]> de.git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
Another flag bites the dust. This time: -ffinite-math-only.
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 Feb 2020 03:47:48 +0000 (03:47 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sat, 22 Feb 2020 03:47:48 +0000 (03:47 +0000)
Since GCC 5, with this flag set, NaN compares equal to zero in some cases but
not others. Causes e.g. "attempted division by zero" error spam from this QC
code:

float x = nan("");
if (x == 0) {
  return 0;
}
return 1.0 / x;

Yes, those NaNs should not be happening in the first place, but suddenly
passing some but not all equality checks to zero seems rather dangerous.

Reference: issue #2412 (not a fix for it; the QC code has a problem too but
this change helps track it down properly).

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12522 d7cf8633-e32d-0410-b094-e92efae38249

makefile
makefile.inc

index d7f3e6d273cb176e06572ca7850fc9cd748e1fe8..17c677692b22342b1325adb29963e8a9e811315a 100644 (file)
--- a/makefile
+++ b/makefile
@@ -200,7 +200,7 @@ ifeq ($(WIN32RELEASE), 1)
 #      TARGET=i686-pc-mingw32
 #      CC=$(TARGET)-g++
 #      WINDRES=$(TARGET)-windres
 #      TARGET=i686-pc-mingw32
 #      CC=$(TARGET)-g++
 #      WINDRES=$(TARGET)-windres
-       CPUOPTIMIZATIONS=-march=pentium3 -mfpmath=sse -fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math
+       CPUOPTIMIZATIONS=-march=pentium3 -mfpmath=sse -fno-math-errno -fno-rounding-math -fno-signaling-nans -fno-trapping-math
 #       CPUOPTIMIZATIONS+=-DUSE_WSPIAPI_H -DSUPPORTIPV6
        LDFLAGS_WINCOMMON=-Wl,--large-address-aware
 else
 #       CPUOPTIMIZATIONS+=-DUSE_WSPIAPI_H -DSUPPORTIPV6
        LDFLAGS_WINCOMMON=-Wl,--large-address-aware
 else
index de68b70988fdf3f6ee0817db95dae3015762f8ec..39976e83981bf178da4fa5bc345c36d0e3897098 100644 (file)
@@ -20,10 +20,11 @@ CC?=gcc
 # No specific CPU (386 compatible)
 #CPUOPTIMIZATIONS?=
 # Experimental
 # No specific CPU (386 compatible)
 #CPUOPTIMIZATIONS?=
 # Experimental
-#CPUOPTIMIZATIONS?=-fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fassociative-math -freciprocal-math -fno-signed-zeros -fno-trapping-math
+#CPUOPTIMIZATIONS?=-fno-math-errno -fno-rounding-math -fno-signaling-nans -fassociative-math -freciprocal-math -fno-signed-zeros -fno-trapping-math
 # Normal
 # Normal
-CPUOPTIMIZATIONS?=-fno-math-errno -ffinite-math-only -fno-rounding-math -fno-signaling-nans -fno-trapping-math
+CPUOPTIMIZATIONS?=-fno-math-errno -fno-rounding-math -fno-signaling-nans -fno-trapping-math
 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
+# Also, since gcc 5, -ffinite-math-only makes NaN and zero compare equal inside engine code but not inside QC, which causes error spam for seemingly valid QC code like if (x != 0) return 1 / x;
 
 SDL_CONFIG?=sdl2-config
 SDLCONFIG_UNIXCFLAGS?=`$(SDL_CONFIG) --cflags`
 
 SDL_CONFIG?=sdl2-config
 SDLCONFIG_UNIXCFLAGS?=`$(SDL_CONFIG) --cflags`
@@ -186,11 +187,12 @@ endif # ifeq ($(DP_SSE),1)
 
 OPTIM_DEBUG=$(CPUOPTIMIZATIONS)
 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -ffast-math -funroll-loops $(CPUOPTIMIZATIONS)
 
 OPTIM_DEBUG=$(CPUOPTIMIZATIONS)
 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -ffast-math -funroll-loops $(CPUOPTIMIZATIONS)
-#OPTIM_RELEASE=-O2 -fno-strict-aliasing -fno-math-errno -fno-trapping-math -ffinite-math-only -fno-signaling-nans -fcx-limited-range -funroll-loops $(CPUOPTIMIZATIONS)
+#OPTIM_RELEASE=-O2 -fno-strict-aliasing -fno-math-errno -fno-trapping-math -fno-signaling-nans -fcx-limited-range -funroll-loops $(CPUOPTIMIZATIONS)
 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -funroll-loops $(CPUOPTIMIZATIONS)
 #OPTIM_RELEASE=-O2 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
 OPTIM_RELEASE=-O3 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
 #OPTIM_RELEASE=-O2 -fno-strict-aliasing -funroll-loops $(CPUOPTIMIZATIONS)
 #OPTIM_RELEASE=-O2 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
 OPTIM_RELEASE=-O3 -fno-strict-aliasing $(CPUOPTIMIZATIONS)
 # NOTE: *never* *ever* use the -ffast-math or -funsafe-math-optimizations flag
+# Also, since gcc 5, -ffinite-math-only makes NaN and zero compare equal inside engine code but not inside QC, which causes error spam for seemingly valid QC code like if (x != 0) return 1 / x;
 
 DO_CC=$(CC) $(CFLAGS) -c $< -o $@
 
 
 DO_CC=$(CC) $(CFLAGS) -c $< -o $@