This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/14582] New: float to unsigned int conversion fills only 16 of 32 bits


***  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]