Floating point problems with the default SConscript file on i686
When I build gpsd (commit ID 4205238f) for i686 using the command scons
I get this output indicating an issue with the floating point operations:
gpsd-3.25.1~dev/gpsd/gpsd -D 5
gpsd:WARN: This system has a 32-bit time_t. This gpsd will fail at 2038-01-19T03:14:07Z.
gpsd:WARN: FLT_EVAL_METHOD is 2, s/b 0
gpsd:WARN: gpsd not started as root, can not drop privileges.
gpsd:ERROR: can't run with neither control socket nor devices
And when I run scons check
it fails one of the regressions
Processing test/daemon/cat-ms352.log
--- test/daemon/cat-ms352.log.chk 2024-05-02 09:45:59.527833168 -0400
+++ /tmp/gpsd-test-78LY5LXJreHCES/test-22634.chk 2024-05-07 10:43:10.890985617 -0400
@@ -58,7 +58,7 @@
$GPGGA,113945.50,3842.86006251,N,11705.43645093,W,2,09,1.3,1864.253,M,-44.296,M,1.4,0000*47
{"class":"SKY","hdop":1.30,"uSat":9}
$GPRMC,113945.50,A,3842.86006251,N,11705.43645093,W,0.082,273.032,231122,999.9000,E,D*1B
-{"class":"TPV","status":2,"mode":3,"time":"2022-11-23T11:39:45.500Z","ept":0.005,"lat":38.714334375,"lon":-117.090607515,"altHAE":1819.9570,"altMSL":1864.2530,"alt":1864.2530,"track":273.0320,"magtrack":912.9320,"magvar":999.9,"speed":0.042,"climb":0.036,"geoidSep":-44.296,"eph":6.175,"dgpsAge":1.4,"dgpsSta":0}
+{"class":"TPV","status":2,"mode":3,"time":"2022-11-23T11:39:45.500Z","ept":0.005,"lat":38.714334375,"lon":-117.090607516,"altHAE":1819.9570,"altMSL":1864.2530,"alt":1864.2530,"track":273.0320,"magtrack":912.9320,"magvar":999.9,"speed":0.042,"climb":0.036,"geoidSep":-44.296,"eph":6.175,"dgpsAge":1.4,"dgpsSta":0}
$GPGGA,113946.00,3842.86004170,N,11705.43647185,W,2,09,1.2,1864.257,M,-44.296,M,1.0,0000*46
{"class":"SKY","hdop":1.20,"uSat":9}
$GPRMC,113946.00,A,3842.86004170,N,11705.43647185,W,0.044,265.149,231122,999.9000,E,D*1B
@@ -126,7 +126,7 @@
$GPGGA,113954.00,3842.85995201,N,11705.43604033,W,2,10,1.2,1865.595,M,-44.296,M,1.0,0000*49
{"class":"SKY","hdop":1.20,"uSat":10}
$GPRMC,113954.00,A,3842.85995201,N,11705.43604033,W,0.019,10.622,231122,999.9000,E,D*26
-{"class":"TPV","status":2,"mode":3,"time":"2022-11-23T11:39:54.000Z","ept":0.005,"lat":38.714332533,"lon":-117.090600672,"altHAE":1821.2990,"altMSL":1865.5950,"alt":1865.5950,"track":10.6220,"magtrack":650.5220,"magvar":999.9,"speed":0.010,"climb":0.306,"geoidSep":-44.296,"eph":5.700,"dgpsAge":1.0,"dgpsSta":0}
+{"class":"TPV","status":2,"mode":3,"time":"2022-11-23T11:39:54.000Z","ept":0.005,"lat":38.714332534,"lon":-117.090600672,"altHAE":1821.2990,"altMSL":1865.5950,"alt":1865.5950,"track":10.6220,"magtrack":650.5220,"magvar":999.9,"speed":0.010,"climb":0.306,"geoidSep":-44.296,"eph":5.700,"dgpsAge":1.0,"dgpsSta":0}
$GPGGA,113954.50,3842.85992064,N,11705.43608578,W,2,10,1.2,1865.671,M,-44.296,M,1.4,0000*41
{"class":"SKY","hdop":1.20,"uSat":10}
$GPRMC,113954.50,A,3842.85992064,N,11705.43608578,W,0.091,240.765,231122,999.9000,E,D*16
Regression test FAILED: 1 errors in 1 tests total (0 not found).
The following test Failed:
================================================================
"test/daemon/cat-ms352.log"
================================================================
All my processors are new enough so I can do what x64 does by default and use the SSE2 FPU
diff --git a/SConscript b/SConscript
index d884843..9f6e142 100644
--- a/SConscript
+++ b/SConscript
@@ -695,6 +695,8 @@ else:
env.Append(CCFLAGS=['-O0'])
else:
env.Append(CCFLAGS=['-O2'])
+ env.Append(CCFLAGS=['-msse2'])
+ env.Append(CCFLAGS=['-mfpmath=sse'])
# Cross-development
Unfortunately that patch won't help everyone, SSE2 was introduced in the Pentium 4, while distros like Debian still support Pentium Pro and other architectures won't want those flags at all. It might be worth adding a special note to the build page https://gpsd.io/building.html rather than changing the build script.
I tried a few other things without success, they all failed the regression. A few compile flags to try to change the precision of the x87 FPU
-mpc32
-mpc64
-mpc80
and using software floating point https://stackoverflow.com/questions/1018638/using-software-floating-point-on-x86-linux