The LLVM optimizer replaces a call to pow(2, x) back into a call to
exp2(x), which ends up in an infinite loop/recursion here. To avoid
the issue, one could either build exp2.c (or easier to accomplish, all
of libmingwex.a) using -fno-builtin or -ffreestanding, or produce the
exp2() function wrappers using assembly instead, to force a function
call to the real pow/powf functions.
---
 mingw-w64-crt/Makefile.am                     |  6 +++---
 mingw-w64-crt/math/arm64/exp2.S               | 19 +++++++++++++++++++
 mingw-w64-crt/math/arm64/exp2.c               | 26 --------------------------
 mingw-w64-crt/math/arm64/{ceill.S => exp2f.S} | 13 +++++++------
 4 files changed, 29 insertions(+), 35 deletions(-)
 create mode 100644 mingw-w64-crt/math/arm64/exp2.S
 delete mode 100644 mingw-w64-crt/math/arm64/exp2.c
 copy mingw-w64-crt/math/arm64/{ceill.S => exp2f.S} (61%)

diff --git a/mingw-w64-crt/Makefile.am b/mingw-w64-crt/Makefile.am
index ce208b6..3771f98 100644
--- a/mingw-w64-crt/Makefile.am
+++ b/mingw-w64-crt/Makefile.am
@@ -355,9 +355,9 @@ endif
 # these only go into the ARM64 version:
 src_libmingwexarm64=\
   math/arm64/_chgsignl.S    math/arm64/ceil.S         math/arm64/ceilf.S       
 math/arm64/ceill.S        math/arm64/copysignl.c    \
-  math/arm64/exp2.c         math/arm64/floor.S        math/arm64/floorf.S      
 math/arm64/floorl.S       math/arm64/log2.c         \
-  math/arm64/nearbyint.S    math/arm64/nearbyintf.S   math/arm64/nearbyintl.S  
 math/arm64/scalbn.c       math/arm64/sincos.c       \
-  math/arm64/trunc.S        math/arm64/truncf.S
+  math/arm64/exp2.S         math/arm64/exp2f.S        math/arm64/floor.S       
 math/arm64/floorf.S       math/arm64/floorl.S       \
+  math/arm64/log2.c         math/arm64/nearbyint.S    math/arm64/nearbyintf.S  
 math/arm64/nearbyintl.S   math/arm64/scalbn.c       \
+  math/arm64/sincos.c       math/arm64/trunc.S        math/arm64/truncf.S
 
 
 # These intrinsics are target independent:
diff --git a/mingw-w64-crt/math/arm64/exp2.S b/mingw-w64-crt/math/arm64/exp2.S
new file mode 100644
index 0000000..b1f7a07
--- /dev/null
+++ b/mingw-w64-crt/math/arm64/exp2.S
@@ -0,0 +1,19 @@
+/**
+ * This file has no copyright assigned and is placed in the Public Domain.
+ * This file is part of the mingw-w64 runtime package.
+ * No warranty is given; refer to the file DISCLAIMER.PD within this package.
+ */
+#include <_mingw_mac.h>
+
+       .file   "exp2.S"
+       .text
+       .align 2
+       .globl __MINGW_USYMBOL(exp2)
+       .globl __MINGW_USYMBOL(exp2l)
+       .def    __MINGW_USYMBOL(exp2);  .scl    2;      .type   32;     .endef
+       .def    __MINGW_USYMBOL(exp2l); .scl    2;      .type   32;     .endef
+__MINGW_USYMBOL(exp2):
+__MINGW_USYMBOL(exp2l):
+       fmov d1, d0
+       fmov d0, #2.0
+       b pow
diff --git a/mingw-w64-crt/math/arm64/exp2.c b/mingw-w64-crt/math/arm64/exp2.c
deleted file mode 100644
index eb9ddf5..0000000
--- a/mingw-w64-crt/math/arm64/exp2.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/**
- * This file has no copyright assigned and is placed in the Public Domain.
- * This file is part of the mingw-w64 runtime package.
- * No warranty is given; refer to the file DISCLAIMER.PD within this package.
- */
-
-#include <math.h>
-
-double exp2(double x)
-{
-    return pow(2, x);
-}
-
-float exp2f(float x)
-{
-    return powf(2, x);
-}
-
-long double exp2l(long double x)
-{
-#if defined(__aarch64__) || defined(_ARM64_)
-    return exp2(x);
-#else
-#error Not supported on your platform yet
-#endif
-}
diff --git a/mingw-w64-crt/math/arm64/ceill.S b/mingw-w64-crt/math/arm64/exp2f.S
similarity index 61%
copy from mingw-w64-crt/math/arm64/ceill.S
copy to mingw-w64-crt/math/arm64/exp2f.S
index 99385a3..c00f003 100644
--- a/mingw-w64-crt/math/arm64/ceill.S
+++ b/mingw-w64-crt/math/arm64/exp2f.S
@@ -5,11 +5,12 @@
  */
 #include <_mingw_mac.h>
 
-       .file   "ceill.S"
+       .file   "exp2f.S"
        .text
        .align 2
-       .globl __MINGW_USYMBOL(ceill)
-       .def    __MINGW_USYMBOL(ceill); .scl    2;      .type   32;     .endef
-__MINGW_USYMBOL(ceill):
-       frintp  d0, d0
-       ret
+       .globl __MINGW_USYMBOL(exp2f)
+       .def    __MINGW_USYMBOL(exp2f); .scl    2;      .type   32;     .endef
+__MINGW_USYMBOL(exp2f):
+       fmov s1, s0
+       fmov s0, #2.0
+       b powf
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to