public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* why does gcc need -fno-trapping-math to generate roundsd instructions?
@ 2014-01-14 14:53 Jay Foad
  2014-01-15 16:13 ` Marc Glisse
  0 siblings, 1 reply; 2+ messages in thread
From: Jay Foad @ 2014-01-14 14:53 UTC (permalink / raw)
  To: gcc-help

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?

Thanks,
Jay.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: why does gcc need -fno-trapping-math to generate roundsd instructions?
  2014-01-14 14:53 why does gcc need -fno-trapping-math to generate roundsd instructions? Jay Foad
@ 2014-01-15 16:13 ` Marc Glisse
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Glisse @ 2014-01-15 16:13 UTC (permalink / raw)
  To: Jay Foad; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-15 16:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-14 14:53 why does gcc need -fno-trapping-math to generate roundsd instructions? Jay Foad
2014-01-15 16:13 ` Marc Glisse

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).