View Full Version : How to use SoftFloat library in GCC?
Atak_Snajpera
9th March 2016, 18:49
I would like to compile some old benchmark called flops.c (https://github.com/AMDmi3/flops/blob/master/flops.c) with floating point emulation.
I've found this Barkeley SoftFloat
http://www.jhauser.us/arithmetic/SoftFloat.html
Unfortunately there is no noob friendly guide how to set up everything step by step therefore I'm asking for help here.
LoRd_MuldeR
9th March 2016, 19:31
First of all, why do you need floating point emulation at all?
Any CPU from the past two decades does floating point in hardware. Even 1980's PCs came with the notorious "floating point co-processor" unit.
Also you would probably have to re-write the whole benchmark code to make it use the SoftFloat library instead of "native" floating point operations. And it will be much slower, of course.
Anyway, they have an API specification that, at a first glance, looks exactly like what you need:
http://www.jhauser.us/arithmetic/SoftFloat-3a/doc/SoftFloat.html
Groucho2004
9th March 2016, 19:34
When you have MingW and gcc set up, open a bash console and compile it with "gcc flops.c -o flops.exe -Wall -Wextra -pedantic". I used the switches from the flops makefile.
LoRd_MuldeR
9th March 2016, 19:40
When you have MingW and gcc set up, open a bash console and compile it with "gcc flops.c -o flops.exe -Wall -Wextra -pedantic". I used the switches from the flops makefile.
This compiles flops.c using "native" floating point capabilities of the CPU. It does not magically make it use SoftFloat library ;)
To use SoftFloat library, he will have to replace any variable of double or float with the "custom" types defined in SoftFloat library (float32_t, float64_t, etc). Furthermore, any operation (addition, multiplication, etc. pp.) performed on any floating-point variable has to be replaced with the corresponding library calls (e.g. z = f64_add(y,x) instead of z = x + y). As said before, this means he will have to re-write pretty much all of the benchmark code...
Atak_Snajpera
9th March 2016, 19:57
First of all, why do you need floating point emulation at all?
Any CPU from the past two decades does floating point in hardware. Even 1980's PCs came with the notorious "floating point co-processor" unit.
Also you would probably have to re-write the whole benchmark code to make it use the SoftFloat library instead of "native" floating point operations. And it will be much slower, of course.
Anyway, they have an API specification that, at a first glance, looks exactly like what you need:
http://www.jhauser.us/arithmetic/SoftFloat-3a/doc/SoftFloat.html
In order to see how efficient is ALU. I have already 3 versions of this benchmark compiled.
Flops_x87.exe
Flops_SSE2.exe
Flops_AVX.exe
Now I want to test ALU with FPU emulation enabled.
So far my gui for flops.c looks like this
http://i.cubeupload.com/A88gmZ.png
I managed to force GCC to use soft-floats with this
http://stackoverflow.com/questions/1018638/using-software-floating-point-on-x86-linux
svn co svn://gcc.gnu.org/svn/gcc/trunk/libgcc/ libgcc
cd libgcc/soft-fp/
gcc -c -O2 -msoft-float -m32 -I../config/i386/ -I.. *.c
ar -crv libsoft-fp.a *.o
gcc -g -m32 -msoft-float flops.c -lsoft-fp -L.
Now I'm curious if Berkeley SoftFloat is faster.
LoRd_MuldeR
9th March 2016, 19:59
Now I'm curious if Berkeley SoftFloat is faster.
Well, then the way to go seems obvious:
https://forum.doom9.org/showpost.php?p=1760123&postcount=4
Atak_Snajpera
9th March 2016, 21:11
Well I assumed that It could automagically do that like GCC with those switches -msoft-float -lsoft-fp
LoRd_MuldeR
9th March 2016, 21:26
Well I assumed that It could automagically do that like GCC with those switches -msoft-float -lsoft-fp
With switch "-lsoft-fp" your are linking in "libsoft-fp.a". Not more, not less!
This will be required to use SoftFloat library, yes. But, most important, you will need to change the code to actually call into SoftFloat library instead of using the "standard" floating-point types an operation.
Just linking your program to the library certainly does not "magically" change the program code in the required way ;)
Also, the "-msoft-float" switch enables GCC's own software floating-point implementation, which is used for platforms without proper FP support. Not related to Berkeley SoftFloat library, as far as I can tell:
Software floating point in GCC currently uses config/fp-bit.c, with some special case support code in mklibgcc.in, plus target-specific assembly implementations for some targets. In addition, libgcc2.c contains generic implementations of conversions of floating point to and from signed and unsigned DImode (or TImode on 64-bit targets), and of conversions from floating point to unsigned SImode, used on all targets unless they expand such conversions inline or use system library functions via set_conv_libfunc.
fp-bit.c is a rather inefficient implementation of software floating point. Some years ago Torbjorn Granlund posted an alternative implementation, ieeelib; see http://gcc.gnu.org/ml/gcc/2005-11/msg01373.html for discussion and references.
GNU libc has a third implementation, soft-fp. (Variants of this are also used for Linux kernel math emulation on some targets.) soft-fp is used in glibc on PowerPC --without-fp to provide the same soft-float functions as in libgcc. It is also used on Alpha, SPARC and PowerPC to provide some ABI-specified floating-point functions (which in turn may get used by GCC); on PowerPC these are IEEE quad functions, not IBM long double ones.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.