Question

The Intel Instruction set reference claims (emphasis mine):

Converts the signed-integer source operand into double extended-precision floating- point format and pushes the value onto the FPU register stack. The source operand can be a word, doubleword, or quadword integer. It is loaded without rounding errors. The sign of the source operand is preserved. This instruction’s operation is the same in non-64-bit modes and 64-bit mode.

Here you can see my test case:

% cat stackoverflow.c       
float uint2float(unsigned int a) {
    return a;
}
% gcc -c stackoverflow.c    
% objdump -d stackoverflow.o

stackoverflow.o:     file format elf32-i386


Disassembly of section .text:

00000000 <uint2float>:
   0:   55                      push   %ebp
   1:   89 e5                   mov    %esp,%ebp
   3:   83 ec 08                sub    $0x8,%esp
   6:   8b 45 08                mov    0x8(%ebp),%eax
   9:   ba 00 00 00 00          mov    $0x0,%edx
   e:   89 45 f8                mov    %eax,-0x8(%ebp)
  11:   89 55 fc                mov    %edx,-0x4(%ebp)
  14:   df 6d f8                fildll -0x8(%ebp)
  17:   c9                      leave  
  18:   c3                      ret    
% gcc --version
gcc-4.6.real (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Was it helpful?

Solution

Ahah! The "ll" suffix will use the 64-bit input variant of the instruction! GCC initializes the upper 32-bit to 0 and therefore it does not matter if the input is signed or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top