summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2022-12-18 18:26:32 -0600
committerDamien George <damien@micropython.org>2024-02-05 14:04:15 +1100
commit23342eff906a99fc0a006916d350c86426fd9204 (patch)
tree1a9c76bc851ff6f9b22a9923d2d3e054720963e5
parentac8e7f7b67ea13e7e9f816d3cfd4ddae4782db8d (diff)
downloadmicropython-23342eff906a99fc0a006916d350c86426fd9204.tar.gz
micropython-23342eff906a99fc0a006916d350c86426fd9204.zip
windows/Makefile: Fix float exact int formatting on 32-bit mingw.
When compiler optimizations are enabled on the mingw version of gcc, we are getting failing tests because of rounding issues, for example: print(float("1e24")) would print 9.999999999999999e+23 instead of 1e+24 It turns out special compiler options are needed to get GCC to use the SSE instruction set instead of the 387 coprocessor (which uses 80-bit precision internall). Signed-off-by: David Lechner <david@pybricks.com>
-rw-r--r--ports/windows/Makefile9
1 files changed, 9 insertions, 0 deletions
diff --git a/ports/windows/Makefile b/ports/windows/Makefile
index 94bd3f99f9..bb635167da 100644
--- a/ports/windows/Makefile
+++ b/ports/windows/Makefile
@@ -86,6 +86,15 @@ ifneq ($(FROZEN_MANIFEST),)
CFLAGS += -DMPZ_DIG_SIZE=16
endif
+ifeq ($(shell $(CC) -dumpmachine),i686-w64-mingw32)
+# GCC disables the SSE instruction set by default on i366 targets and we have
+# to specify all three of these options to enable it.
+# https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html (see -mfpmath=unit section)
+# Enabling the SSE instruction set is necessary to get correct rounding of floating points.
+# https://lemire.me/blog/2020/06/26/gcc-not-nearest
+CFLAGS += -msse -mfpmath=sse -march=pentium4
+endif
+
CXXFLAGS += $(filter-out -std=gnu99,$(CFLAGS))
include $(TOP)/py/mkrules.mk