public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/14582] New: float to unsigned int conversion fills only 16 of 32 bits
@ 2004-03-15 16:10 sebastian dot tusk at gmx dot net
  2004-03-15 17:10 ` [Bug c/14582] " sebastian dot tusk at gmx dot net
  2004-04-07  3:06 ` [Bug target/14582] [asm=intel] " pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 3+ messages in thread
From: sebastian dot tusk at gmx dot net @ 2004-03-15 16:10 UTC (permalink / raw)
  To: gcc-bugs

***  gcc -v returns
Reading specs from /usr/lib/gcc-lib/i486-linux/3.3.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,pascal,objc,ada,treelang --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.3 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-debug --enable-java-gc=boehm
--enable-java-awt=xlib --enable-objc-gc i486-linux
Thread model: posix
gcc version 3.3.3 (Debian)

  ***  system type (/proc/version)
Linux version 2.4.21-4-k7 (herbert@gondolin) (gcc version 3.3.1 20030626 (Debian
prerelease)) #1 Sun Aug 3 02:34:06 EST 2003

  ***  command line to build sample application
gcc -masm=intel -fno-exceptions test.c

  ***  test.c source file
#include <stdio.h>

int main( int argc, char** argv )
{
        float f = 100.0f;
        unsigned long l = 0x12345678;
        l = (unsigned int)f;
        printf( "l = 0x64 ---- l = 0x%X\n", l );
        return 0;
}

  ***  
The code should output something like "l = 0x64 ---- l = 0x64" but in fact it
returns "l = 0x64 ---- l = 0x40140064". You may notice that the low 16 bits are
correct.

It seems that the problem is the conversion of a fpu register into a integer in
memory. The temporary assembler (.s) file gcc produces "fistp   QWORD PTR
[%ebp-24]" to do the job. But in the binary lands something that looks like
"fistp   WORD PTR [%ebp-24]" (objdump says "fistp 0xffffffe8(%ebp)"). That would
explain the correct 16 bit. There rest is then simply garbage.

Interestingly converting a float into a signed int works as expected. The
temporary assembler file uses "fistp   DWORD PTR [%ebp-8]" and objdump says
"fistpl 0xfffffff8(%ebp)" for the binary.

-- 
           Summary: float to unsigned int conversion fills only 16 of 32
                    bits
           Product: gcc
           Version: 3.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sebastian dot tusk at gmx dot net
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: 3.3.3
  GCC host triplet: 3.3.3
GCC target triplet: 3.3.3


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14582


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

* [Bug c/14582] float to unsigned int conversion fills only 16 of 32 bits
  2004-03-15 16:10 [Bug c/14582] New: float to unsigned int conversion fills only 16 of 32 bits sebastian dot tusk at gmx dot net
@ 2004-03-15 17:10 ` sebastian dot tusk at gmx dot net
  2004-04-07  3:06 ` [Bug target/14582] [asm=intel] " pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: sebastian dot tusk at gmx dot net @ 2004-03-15 17:10 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From sebastian dot tusk at gmx dot net  2004-03-15 17:10 -------
I realized that omitting the "-masm=intel" flag solves the problem. The compiler
is still not 100 percent correct as it produces "fistpll -24(%ebp)" where
"fistpl -24(%ebp)" should be sufficient. But besides writing 4 bytes more than
necessary no harm is done.

That fistpll seems to be the same problem as that QWORD suffix in the intel
style assembler. The difference is that fistpll lands correctly in the binary in
contrast to the intel version where "fistp WORD PTR []" appears in the binary.
So in fact there could be two problems.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14582


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

* [Bug target/14582] [asm=intel] float to unsigned int conversion fills only 16 of 32 bits
  2004-03-15 16:10 [Bug c/14582] New: float to unsigned int conversion fills only 16 of 32 bits sebastian dot tusk at gmx dot net
  2004-03-15 17:10 ` [Bug c/14582] " sebastian dot tusk at gmx dot net
@ 2004-04-07  3:06 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-04-07  3:06 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-04-07 03:06 -------
Confirmed.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|c                           |target
     Ever Confirmed|                            |1
  GCC build triplet|3.3.3                       |
   GCC host triplet|3.3.3                       |
 GCC target triplet|3.3.3                       |i686-pc-linux-gnu
           Keywords|                            |wrong-code
      Known to fail|                            |3.5.0
   Last reconfirmed|0000-00-00 00:00:00         |2004-04-07 03:06:04
               date|                            |
            Summary|float to unsigned int       |[asm=intel] float to
                   |conversion fills only 16 of |unsigned int conversion
                   |32 bits                     |fills only 16 of 32 bits


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14582


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

end of thread, other threads:[~2004-04-07  3:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-15 16:10 [Bug c/14582] New: float to unsigned int conversion fills only 16 of 32 bits sebastian dot tusk at gmx dot net
2004-03-15 17:10 ` [Bug c/14582] " sebastian dot tusk at gmx dot net
2004-04-07  3:06 ` [Bug target/14582] [asm=intel] " pinskia at gcc dot gnu dot 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).