1

I've constructed what I believe to be the simplest possible use of the extFloat80_t type provided by the SoftFloat library (http://www.jhauser.us/arithmetic/SoftFloat.html) and can't see what I'm doing wrong -- all values for i32 that I've tried result in output "0".

#include "softfloat.h"
#include "stdio.h"
int main( int argc, char** argv )
{
    int32_t i32 = 1000;
    extFloat80_t f80 = i32_to_extF80(i32);
    int32_t i80 = extF80_to_i32_r_minMag( f80, false );
    printf( "%d\n", i80 );
    return 0;
}

Built via

gcc -I source/include/ test.c -DSOFTFLOAT_FAST_INT64 build/Linux-x86_64-GCC/softfloat.a -DSOFTFLOAT_ROUND_ODD -DINLINE_LEVEL=5 -DSOFTFLOAT_FAST_DIV32TO16   -DSOFTFLOAT_FAST_DIV64TO32
gmabey
  • 15
  • 1
  • 6

1 Answers1

0

I have reproduced your result on Ubuntu/x86_64 (version 16.04). (You have not specified exact details of your target. Please provide such critical data in future questions.)

I have fixed it by adding

#define LITTLEENDIAN 1

to the main program definitions. After this, all values are restored properly.

I guess this is related to x86_64 SysV ABI that used in Linux - it allows splitting a structure passed by value into a few registers (instead of passing by pointer), and misdefining of endianness leads into improper splitting. Without the needed definition, order of signExp and signif in extFloat80_t is reversed.

Netch
  • 4,171
  • 1
  • 19
  • 31