why does gcc need -fno-trapping-math to generate roundsd instructions?
Marc Glisse
marc.glisse@inria.fr
Wed Jan 15 16:13:00 GMT 2014
On Tue, 14 Jan 2014, Jay Foad wrote:
> I'm using GCC 4.8.1 with eglibc 2.17 on an Intel CPU with SSE 4.1.
>
> Given this source:
>
> #include <math.h>
> double f(double x){return floor x;}
>
> gcc -msse4.1 -O -S generates:
>
> f:
> subq $8, %rsp
> call floor
> addq $8, %rsp
> ret
>
> It seems I need to add -fno-trapping-math to get inline code:
>
> f:
> roundsd $1, %xmm0, %xmm0
> ret
>
> But why? If I run the first version under a debugger, the call to
> "floor" eventually resolves to eglibc's __floor_sse41, which just does
> this:
>
> roundsd $0x1,%xmm0,%xmm0
> retq
>
> So what is -ftrapping-math really buying me? Why can't the compiler
> generate roundsd inline in all cases?
First, I think you want to file a PR on bugzilla, or your message will
just be forgotten.
The reason could be related to this note in the glibc manpage:
"SUSv2 and POSIX.1-2001 contain text about overflow (which might set
errno to ERANGE, or raise an FE_OVERFLOW exception). In practice, the
result cannot overflow on any current machine, so this error-handling
stuff is just nonsense."
--
Marc Glisse
More information about the Gcc-help
mailing list