forked from gcc-mirror/gcc
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
or1k: we only support ordered compares
Tighten the conditions to support ordered fpu compares only. This fixes github issue #1
- Loading branch information
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stffrdhrn
Stafford, the update makes possible to build NewLIB itself with options
-mhard-float -mdouble-float
. However it looks like it brings an issue intoprintf()
internals when printing a floating point value.Example
sinf_out.c
:Being compiled with
or1k-elf-gcc -pipe -O2 -mboard=atlys sinf_out.c -lm -o sinf_out.elf
it's output isIf I build it with previous version of tool-chain (without the modification and NewLIB was build without
-mhard-float -mdouble-float
options) it’s output is normal:Not sure could it be related to unordered fp- comparison or not.
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for testing this. This is interesting, the extra
>
and/
characters seem strange. Is this running on FPGA or simulator? Just from the nature it looks like some sort of timing/corruption issue.I tried to compile newlib myself right now and I got the below error. Its interesting that the compiler error is in the dtoa code (double to ascii) which is used for your printf test.
Note, I might be getting this failure due to my recent change to fix issue #4 .
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, I got the failure with compiling newlib with
CFLAGS_FOR_TARGET=-O2 -mhard-float -mdouble-float
. When removing-O2
I don't get the failure.I will need to fix it anyway.
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, when running in
sim
(or1k-elf-run
) I don't see the issue.BUT Running in icarus I can reproduce the issue:
fusesoc run --target marocchino_tb --tool icarus mor1kx-generic --elf-load ./printfp --option_orfpx64a32_abi GCC9
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stffrdhrn
I run it on FPGA. Simulation typically produces too long output for analysis. Even so the example, I believe, could be reduced down to
it would be useful to have a reference for debug. Is it possible to use
sim
to generate, say, sequence of PC of completed instruction and written back values?Perhaps, we additionally should check GCC behavior when it processed expression which involves operands o different types, for example
"an integer" <add> "a double"
. I've remembered that at 1-st time I compiled Whetstone it operated incorrectly. To fix it I had to edit Whetstone sources by adding explicit type conversions into such expressions. Have GCC got an option to force types coercion before computing an expression with mixed type of operands?975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be done in sim. see:
or1k-elf-run --trace-insn ./printfp
I uploaded my output: https://gist.github.com/06c6e0dc0736b363c8bf2efea0981794
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done by default. I don't know of any option to force it to so.
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. As I've never build
sim
I've got a question. Could I buildsim
it while buildingbinutils
or I have to build it after completion GCC stage 2 (along with building gdb)?975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is part of binutils and has no dependencies on gcc. You should already be building and installing it if you are building binutils.
Does or1k-elf-run exist in your path?
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note another option, and probably better is to use or1ksim as it produces insn traces that match the or1k verilog monitor.
Did anyone as orfp32a64 to or1ksim?
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or1k-elf-run is definitely not present in my path because I build binutils traditionally with
--disable-sim
configuring option. :)I doubt if or1ksim supports orfpx64a32.
Well, I'll rebuild binutils with
sim
soon.975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stffrdhrn
I've found the problem.
C/C++ double to integer conversion assumes truncation (rounding toward zero). But
lf.ftoi.s(d)
performes conversion in according withrounding mode
bits of FPCSR, And these bits are"nearest-even ronding mode"
by default.I added code with change rounding mode to
"toward zero"
at the beginning of main() of the example and Whetstone. And printf() become printing floating point values correctly.Not sure how the issue should be fixed correctly in hardware. As a temporary workaround I’m going to add parameter like OPTION_FTOI_ROUNDING = “IEEE”/”CPP”, where “CPP” is supposed to be default and it should force
"toward zero"
forlf.ftoi.s(d)
instruction regardless ofrounding mode
bits of FPCSR.975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great find. This is another thing we should clarify in the spec. But why is this something we didn't see before? Did we never build libc with fpu before?
975f33d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previously I build NewLIB (and never uClibc) with FPU for GCC5-based tool-chain only. I suppose that GCC5 just doesn't involve
lf.ftoi.s(d)
but calls appropriate subroutine instead.