On 32 bit x86, clang seems to miss loading input parameters based
on asm constraints for inline assembly that uses the x87 floating
registers, unless the snippet has got the volatile keyword.

Signed-off-by: Martin Storsjö <mar...@martin.st>
---
 mingw-w64-crt/math/fabs.c        |  2 +-
 mingw-w64-crt/math/fabsf.c       |  2 +-
 mingw-w64-crt/math/fabsl.c       |  2 +-
 mingw-w64-crt/math/modf.c        |  4 ++--
 mingw-w64-crt/math/modff.c       |  4 ++--
 mingw-w64-crt/math/modfl.c       |  4 ++--
 mingw-w64-crt/math/sqrt.def.h    | 10 +++++-----
 mingw-w64-crt/math/x86/acosf.c   |  3 ++-
 mingw-w64-crt/math/x86/acosl.c   |  3 ++-
 mingw-w64-crt/math/x86/asinf.c   |  3 ++-
 mingw-w64-crt/math/x86/asinl.c   |  3 ++-
 mingw-w64-crt/math/x86/atan2.c   |  2 +-
 mingw-w64-crt/math/x86/atan2f.c  |  2 +-
 mingw-w64-crt/math/x86/atan2l.c  |  2 +-
 mingw-w64-crt/math/x86/atanf.c   |  3 ++-
 mingw-w64-crt/math/x86/atanl.c   |  3 ++-
 mingw-w64-crt/math/x86/exp.def.h |  3 ++-
 mingw-w64-crt/math/x86/fmod.c    |  3 ++-
 mingw-w64-crt/math/x86/fmodf.c   |  3 ++-
 mingw-w64-crt/math/x86/fmodl.c   |  3 ++-
 mingw-w64-crt/math/x86/logb.c    |  3 ++-
 mingw-w64-crt/math/x86/logbf.c   |  3 ++-
 mingw-w64-crt/math/x86/logbl.c   |  3 ++-
 mingw-w64-crt/math/x86/pow.def.h |  6 +++---
 24 files changed, 46 insertions(+), 33 deletions(-)

diff --git a/mingw-w64-crt/math/fabs.c b/mingw-w64-crt/math/fabs.c
index 2011378..a663711 100644
--- a/mingw-w64-crt/math/fabs.c
+++ b/mingw-w64-crt/math/fabs.c
@@ -14,7 +14,7 @@ fabs (double x)
 #elif defined(__i386__) || defined(_X86_)
   double res = 0.0;
 
-  asm ("fabs;" : "=t" (res) : "0" (x));
+  asm volatile ("fabs;" : "=t" (res) : "0" (x));
   return res;
 #endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__arm__) || 
defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_) */
 }
diff --git a/mingw-w64-crt/math/fabsf.c b/mingw-w64-crt/math/fabsf.c
index e8520d5..e7e9d8f 100644
--- a/mingw-w64-crt/math/fabsf.c
+++ b/mingw-w64-crt/math/fabsf.c
@@ -12,7 +12,7 @@ fabsf (float x)
   return __builtin_fabsf (x);
 #elif defined(__i386__) || defined(_X86_)
   float res = 0.0F;
-  asm ("fabs;" : "=t" (res) : "0" (x));
+  asm volatile ("fabs;" : "=t" (res) : "0" (x));
   return res;
 #endif /* defined(__x86_64__) || defined(_AMD64_) || defined(__arm__) || 
defined(_ARM_) || defined(__aarch64__) || defined(_ARM64_) */
 }
diff --git a/mingw-w64-crt/math/fabsl.c b/mingw-w64-crt/math/fabsl.c
index 20b8b22..1df48cf 100644
--- a/mingw-w64-crt/math/fabsl.c
+++ b/mingw-w64-crt/math/fabsl.c
@@ -10,7 +10,7 @@ fabsl (long double x)
 {
 #if defined(__x86_64__) || defined(_AMD64_) || defined(__i386__) || 
defined(_X86_)
   long double res = 0.0L;
-  asm ("fabs;" : "=t" (res) : "0" (x));
+  asm volatile ("fabs;" : "=t" (res) : "0" (x));
   return res;
 #elif defined(__arm__) || defined(_ARM_) || defined(__aarch64__) || 
defined(_ARM64_)
   return __builtin_fabsl (x);
diff --git a/mingw-w64-crt/math/modf.c b/mingw-w64-crt/math/modf.c
index f8ba64e..d262309 100644
--- a/mingw-w64-crt/math/modf.c
+++ b/mingw-w64-crt/math/modf.c
@@ -13,7 +13,7 @@ modf (double value, double* iptr)
   double int_part = 0.0;
   /* truncate */
 #if defined(_AMD64_) || defined(__x86_64__)
-  asm ("subq $8, %%rsp\n"
+  asm volatile ("subq $8, %%rsp\n"
     "fnstcw 4(%%rsp)\n"
     "movzwl 4(%%rsp), %%eax\n"
     "orb $12, %%ah\n"
@@ -23,7 +23,7 @@ modf (double value, double* iptr)
     "fldcw 4(%%rsp)\n"
     "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
-  asm ("push %%eax\n\tsubl $8, %%esp\n"
+  asm volatile ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"
     "movzwl 4(%%esp), %%eax\n"
     "orb $12, %%ah\n"
diff --git a/mingw-w64-crt/math/modff.c b/mingw-w64-crt/math/modff.c
index 2c4de3e..dcf19cf 100644
--- a/mingw-w64-crt/math/modff.c
+++ b/mingw-w64-crt/math/modff.c
@@ -14,7 +14,7 @@ modff (float value, float* iptr)
   /* truncate */ 
   /* truncate */
 #if defined(_AMD64_) || defined(__x86_64__)
-  asm ("subq $8, %%rsp\n"
+  asm volatile ("subq $8, %%rsp\n"
     "fnstcw 4(%%rsp)\n"
     "movzwl 4(%%rsp), %%eax\n"
     "orb $12, %%ah\n"
@@ -24,7 +24,7 @@ modff (float value, float* iptr)
     "fldcw 4(%%rsp)\n"
     "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
-  asm ("push %%eax\n\tsubl $8, %%esp\n"
+  asm volatile ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"
     "movzwl 4(%%esp), %%eax\n"
     "orb $12, %%ah\n"
diff --git a/mingw-w64-crt/math/modfl.c b/mingw-w64-crt/math/modfl.c
index ef1ab16..33593e6 100644
--- a/mingw-w64-crt/math/modfl.c
+++ b/mingw-w64-crt/math/modfl.c
@@ -13,7 +13,7 @@ modfl (long double value, long double* iptr)
   long double int_part = 0.0L;
   /* truncate */
 #if defined(_AMD64_) || defined(__x86_64__)
-  asm ("subq $8, %%rsp\n"
+  asm volatile ("subq $8, %%rsp\n"
     "fnstcw 4(%%rsp)\n"
     "movzwl 4(%%rsp), %%eax\n"
     "orb $12, %%ah\n"
@@ -23,7 +23,7 @@ modfl (long double value, long double* iptr)
     "fldcw 4(%%rsp)\n"
     "addq $8, %%rsp\n" : "=t" (int_part) : "0" (value) : "eax"); /* round */
 #elif defined(_X86_) || defined(__i386__)
-  asm ("push %%eax\n\tsubl $8, %%esp\n"
+  asm volatile ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"
     "movzwl 4(%%esp), %%eax\n"
     "orb $12, %%ah\n"
diff --git a/mingw-w64-crt/math/sqrt.def.h b/mingw-w64-crt/math/sqrt.def.h
index 041bc82..ed1e663 100644
--- a/mingw-w64-crt/math/sqrt.def.h
+++ b/mingw-w64-crt/math/sqrt.def.h
@@ -73,18 +73,18 @@ __FLT_ABI (sqrt) (__FLT_TYPE x)
    return __FLT_CST (1.0);
 #if defined(__arm__) || defined(_ARM_)
 #if _NEW_COMPLEX_FLOAT
-  asm ("fsqrts %[dst], %[src];\n" : [dst] "=t" (res) : [src] "t" (x));
+  asm volatile ("fsqrts %[dst], %[src];\n" : [dst] "=t" (res) : [src] "t" (x));
 #else
-  asm ("fsqrtd %[dst], %[src];\n" : [dst] "=w" (res) : [src] "w" (x));
+  asm volatile ("fsqrtd %[dst], %[src];\n" : [dst] "=w" (res) : [src] "w" (x));
 #endif
 #elif defined(__aarch64__) || defined(_ARM64_)
 #if _NEW_COMPLEX_FLOAT
-  asm ("fsqrt %s[dst], %s[src]\n" : [dst] "=w" (res) : [src] "w" (x));
+  asm volatile ("fsqrt %s[dst], %s[src]\n" : [dst] "=w" (res) : [src] "w" (x));
 #else
-  asm ("fsqrt %d[dst], %d[src]\n" : [dst] "=w" (res) : [src] "w" (x));
+  asm volatile ("fsqrt %d[dst], %d[src]\n" : [dst] "=w" (res) : [src] "w" (x));
 #endif
 #elif defined(_X86_) || defined(__i386__) || defined(_AMD64_) || 
defined(__x86_64__)
-  asm ("fsqrt" : "=t" (res) : "0" (x));
+  asm volatile ("fsqrt" : "=t" (res) : "0" (x));
 #else
 #error Not supported on your platform yet
 #endif
diff --git a/mingw-w64-crt/math/x86/acosf.c b/mingw-w64-crt/math/x86/acosf.c
index 5c0027a..4246be0 100644
--- a/mingw-w64-crt/math/x86/acosf.c
+++ b/mingw-w64-crt/math/x86/acosf.c
@@ -16,7 +16,8 @@ acosf (float x)
   float res = 0.0F;
 
   /* acosl = atanl (sqrtl(1 - x^2) / x) */
-  asm (        "fld    %%st\n\t"
+  asm volatile (
+       "fld    %%st\n\t"
        "fmul   %%st(0)\n\t"            /* x^2 */
        "fld1\n\t"
        "fsubp\n\t"                     /* 1 - x^2 */
diff --git a/mingw-w64-crt/math/x86/acosl.c b/mingw-w64-crt/math/x86/acosl.c
index 511b5de..553d06f 100644
--- a/mingw-w64-crt/math/x86/acosl.c
+++ b/mingw-w64-crt/math/x86/acosl.c
@@ -10,7 +10,8 @@ long double acosl (long double x)
   long double res = 0.0L;
 
   /* acosl = atanl (sqrtl(1 - x^2) / x) */
-  asm (        "fld    %%st\n\t"
+  asm volatile (
+       "fld    %%st\n\t"
        "fmul   %%st(0)\n\t"            /* x^2 */
        "fld1\n\t"
        "fsubp\n\t"                     /* 1 - x^2 */
diff --git a/mingw-w64-crt/math/x86/asinf.c b/mingw-w64-crt/math/x86/asinf.c
index 045a798..f0be4be 100644
--- a/mingw-w64-crt/math/x86/asinf.c
+++ b/mingw-w64-crt/math/x86/asinf.c
@@ -16,7 +16,8 @@ float asinf (float x)
 {
   float res = 0.0F;
 
-  asm (        "fld    %%st\n\t"
+  asm volatile (
+       "fld    %%st\n\t"
        "fmul   %%st(0)\n\t"                    /* x^2 */
        "fld1\n\t"
        "fsubp\n\t"                             /* 1 - x^2 */
diff --git a/mingw-w64-crt/math/x86/asinl.c b/mingw-w64-crt/math/x86/asinl.c
index a4d8746..35df3b5 100644
--- a/mingw-w64-crt/math/x86/asinl.c
+++ b/mingw-w64-crt/math/x86/asinl.c
@@ -16,7 +16,8 @@ long double asinl (long double x)
 {
   long double res = 0.0L;
 
-  asm (        "fld    %%st\n\t"
+  asm volatile (
+       "fld    %%st\n\t"
        "fmul   %%st(0)\n\t"                    /* x^2 */
        "fld1\n\t"
        "fsubp\n\t"                             /* 1 - x^2 */
diff --git a/mingw-w64-crt/math/x86/atan2.c b/mingw-w64-crt/math/x86/atan2.c
index 986954b..1d8a099 100644
--- a/mingw-w64-crt/math/x86/atan2.c
+++ b/mingw-w64-crt/math/x86/atan2.c
@@ -10,6 +10,6 @@ double
 atan2 (double y, double x)
 {
   double res = 0.0;
-  asm ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
+  asm volatile ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
   return res;
 }
diff --git a/mingw-w64-crt/math/x86/atan2f.c b/mingw-w64-crt/math/x86/atan2f.c
index 0d54e06..915c3e4 100644
--- a/mingw-w64-crt/math/x86/atan2f.c
+++ b/mingw-w64-crt/math/x86/atan2f.c
@@ -15,6 +15,6 @@ float
 atan2f (float y, float x)
 {
   float res = 0.0F;
-  asm ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
+  asm volatile ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
   return res;
 }
diff --git a/mingw-w64-crt/math/x86/atan2l.c b/mingw-w64-crt/math/x86/atan2l.c
index a32b097..a4300cb 100644
--- a/mingw-w64-crt/math/x86/atan2l.c
+++ b/mingw-w64-crt/math/x86/atan2l.c
@@ -9,6 +9,6 @@ long double
 atan2l (long double y, long double x)
 {
   long double res = 0.0L;
-  asm ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
+  asm volatile ("fpatan" : "=t" (res) : "u" (y), "0" (x) : "st(1)");
   return res;
 }
diff --git a/mingw-w64-crt/math/x86/atanf.c b/mingw-w64-crt/math/x86/atanf.c
index 85fadd8..f11bfc6 100644
--- a/mingw-w64-crt/math/x86/atanf.c
+++ b/mingw-w64-crt/math/x86/atanf.c
@@ -16,7 +16,8 @@ atanf (float x)
 {
   float res = 0.0F;
 
-  asm ("fld1\n\t"
+  asm volatile (
+       "fld1\n\t"
        "fpatan" : "=t" (res) : "0" (x));
   return res;
 }
diff --git a/mingw-w64-crt/math/x86/atanl.c b/mingw-w64-crt/math/x86/atanl.c
index b85d053..d289ef0 100644
--- a/mingw-w64-crt/math/x86/atanl.c
+++ b/mingw-w64-crt/math/x86/atanl.c
@@ -10,7 +10,8 @@ atanl (long double x)
 {
   long double res = 0.0L;
 
-  asm ("fld1\n\t"
+  asm volatile (
+       "fld1\n\t"
        "fpatan"
        : "=t" (res) : "0" (x));
   return res;
diff --git a/mingw-w64-crt/math/x86/exp.def.h b/mingw-w64-crt/math/x86/exp.def.h
index 6f1ab8e..33a176a 100644
--- a/mingw-w64-crt/math/x86/exp.def.h
+++ b/mingw-w64-crt/math/x86/exp.def.h
@@ -52,7 +52,8 @@ static long double
 __expl_internal (long double x)
 {
   long double res = 0.0L;
-  asm ("fldl2e\n\t"             /* 1  log2(e)         */
+  asm volatile (
+       "fldl2e\n\t"             /* 1  log2(e)         */
        "fmul %%st(1),%%st\n\t"  /* 1  x log2(e)       */
 
 #ifdef __x86_64__
diff --git a/mingw-w64-crt/math/x86/fmod.c b/mingw-w64-crt/math/x86/fmod.c
index 29787e2..5764db0 100644
--- a/mingw-w64-crt/math/x86/fmod.c
+++ b/mingw-w64-crt/math/x86/fmod.c
@@ -10,7 +10,8 @@ fmod (double x, double y)
 {
   double res = 0.0;
 
-  asm ("1:\tfprem\n\t"
+  asm volatile (
+       "1:\tfprem\n\t"
        "fstsw   %%ax\n\t"
        "sahf\n\t"
        "jp      1b\n\t"
diff --git a/mingw-w64-crt/math/x86/fmodf.c b/mingw-w64-crt/math/x86/fmodf.c
index e68fec2..45106ad 100644
--- a/mingw-w64-crt/math/x86/fmodf.c
+++ b/mingw-w64-crt/math/x86/fmodf.c
@@ -18,7 +18,8 @@ fmodf (float x, float y)
 {
   float res = 0.0F;
 
-  asm ("1:\tfprem\n\t"
+  asm volatile (
+       "1:\tfprem\n\t"
        "fstsw   %%ax\n\t"
        "sahf\n\t"
        "jp      1b\n\t"
diff --git a/mingw-w64-crt/math/x86/fmodl.c b/mingw-w64-crt/math/x86/fmodl.c
index 6224db1..462b6fa 100644
--- a/mingw-w64-crt/math/x86/fmodl.c
+++ b/mingw-w64-crt/math/x86/fmodl.c
@@ -10,7 +10,8 @@ fmodl (long double x, long double y)
 {
   long double res = 0.0L;
 
-  asm ("1:\tfprem\n\t"
+  asm volatile (
+       "1:\tfprem\n\t"
        "fstsw   %%ax\n\t"
        "sahf\n\t"
        "jp      1b\n\t"
diff --git a/mingw-w64-crt/math/x86/logb.c b/mingw-w64-crt/math/x86/logb.c
index 5760d26..0c0475d 100644
--- a/mingw-w64-crt/math/x86/logb.c
+++ b/mingw-w64-crt/math/x86/logb.c
@@ -30,7 +30,8 @@ logb (double x)
   return (double) (hx - 1023);
 #else
   double res = 0.0;
-  asm ("fxtract\n\t"
+  asm volatile (
+       "fxtract\n\t"
        "fstp   %%st" : "=t" (res) : "0" (x));
   return res;
 #endif
diff --git a/mingw-w64-crt/math/x86/logbf.c b/mingw-w64-crt/math/x86/logbf.c
index 5a0429e..158b29b 100644
--- a/mingw-w64-crt/math/x86/logbf.c
+++ b/mingw-w64-crt/math/x86/logbf.c
@@ -29,7 +29,8 @@ logbf (float x)
     return (float) (v - 127);
 #else
   float res = 0.0F;
-  asm ("fxtract\n\t"
+  asm volatile (
+       "fxtract\n\t"
        "fstp   %%st" : "=t" (res) : "0" (x));
   return res;
 #endif
diff --git a/mingw-w64-crt/math/x86/logbl.c b/mingw-w64-crt/math/x86/logbl.c
index 310c445..5e533c0 100644
--- a/mingw-w64-crt/math/x86/logbl.c
+++ b/mingw-w64-crt/math/x86/logbl.c
@@ -16,7 +16,8 @@ logbl (long double x)
 {
   long double res = 0.0L;
 
-  asm ("fxtract\n\t"
+  asm volatile (
+       "fxtract\n\t"
        "fstp   %%st" : "=t" (res) : "0" (x));
   return res;
 }
diff --git a/mingw-w64-crt/math/x86/pow.def.h b/mingw-w64-crt/math/x86/pow.def.h
index 5ef6211..375b02b 100644
--- a/mingw-w64-crt/math/x86/pow.def.h
+++ b/mingw-w64-crt/math/x86/pow.def.h
@@ -82,7 +82,7 @@ internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr)
   /* truncate */ 
   /* truncate */
 #ifdef __x86_64__
-  asm ("pushq %%rax\n\tsubq $8, %%rsp\n"
+  asm volatile ("pushq %%rax\n\tsubq $8, %%rsp\n"
     "fnstcw 4(%%rsp)\n"
     "movzwl 4(%%rsp), %%eax\n"
     "orb $12, %%ah\n"
@@ -92,7 +92,7 @@ internal_modf (__FLT_TYPE value, __FLT_TYPE *iptr)
     "fldcw 4(%%rsp)\n"
     "addq $8, %%rsp\npopq %%rax" : "=t" (int_part) : "0" (value)); /* round */
 #else
-  asm ("push %%eax\n\tsubl $8, %%esp\n"
+  asm volatile ("push %%eax\n\tsubl $8, %%esp\n"
     "fnstcw 4(%%esp)\n"
     "movzwl 4(%%esp), %%eax\n"
     "orb $12, %%ah\n"
@@ -200,7 +200,7 @@ __FLT_ABI(pow) (__FLT_TYPE x, __FLT_TYPE y)
        }
       if (y == __FLT_CST(0.5))
        {
-         asm ("fsqrt" : "=t" (rslt) : "0" (x));
+         asm volatile ("fsqrt" : "=t" (rslt) : "0" (x));
          return rslt;
        }
     }
-- 
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