public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/61563] New: better 387 code for float x == (int)x
@ 2014-06-19 15:47 jay.foad at gmail dot com
  2014-06-19 16:22 ` [Bug target/61563] " joseph at codesourcery dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: jay.foad at gmail dot com @ 2014-06-19 15:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61563

            Bug ID: 61563
           Summary: better 387 code for float x == (int)x
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jay.foad at gmail dot com

I get this with GCC 4.10.0 20140619 (experimental):

$ gcc -mno-sse -O3 -S -o - -x c - <<<"int f(float x) { return x == (int)x; }"
...
f:
    fnstcw    -2(%rsp)
    movzwl    -2(%rsp), %eax
    flds    8(%rsp)
    movl    $0, %edx
    orb    $12, %ah
    movw    %ax, -4(%rsp)
    xorl    %eax, %eax
    fldcw    -4(%rsp)
    fistl    -12(%rsp)
    fldcw    -2(%rsp)
    fildl    -12(%rsp)
    fucomip    %st(1), %st
    fstp    %st(0)
    setnp    %al
    cmovne    %edx, %eax
    ret

All the fnstcw and fldcw stuff is unnecessary, because when we convert x to
int, it doesn't matter what rounding mode we use; all that matters is whether
it is already an exact int value or not.

I think the x == (int)x pattern is fairly common, and it would be nice if GCC
generated better 387 code for it.


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

end of thread, other threads:[~2021-08-02 20:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-06-19 15:47 [Bug target/61563] New: better 387 code for float x == (int)x jay.foad at gmail dot com
2014-06-19 16:22 ` [Bug target/61563] " joseph at codesourcery dot com
2014-06-19 20:16 ` jay.foad at gmail dot com
2014-06-21  8:45 ` ubizjak at gmail dot com
2021-08-02 20:08 ` pinskia at gcc dot gnu.org

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).