public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: crt: Add "volatile" to all inline assembly snippets under math
Date: Sun, 30 Aug 2020 12:30:25 +0000 (GMT)	[thread overview]
Message-ID: <20200830123025.2F5BD3836C73@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=023ddc41283b3508d32eb00bb45a7408cc196ffa

commit 023ddc41283b3508d32eb00bb45a7408cc196ffa
Author: Martin Storsjö <martin@martin.st>
Date:   Sun Aug 30 14:12:48 2020 +0200

    Cygwin: crt: Add "volatile" to all inline assembly snippets under math
    
    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ö <martin@martin.st>

Diff:
---
 winsup/cygwin/math/acosl.c    | 3 ++-
 winsup/cygwin/math/asinl.c    | 3 ++-
 winsup/cygwin/math/atan2l.c   | 2 +-
 winsup/cygwin/math/atanl.c    | 3 ++-
 winsup/cygwin/math/exp.def.h  | 3 ++-
 winsup/cygwin/math/fabsl.c    | 2 +-
 winsup/cygwin/math/fmodl.c    | 3 ++-
 winsup/cygwin/math/logbl.c    | 3 ++-
 winsup/cygwin/math/modfl.c    | 4 ++--
 winsup/cygwin/math/pow.def.h  | 6 +++---
 winsup/cygwin/math/sqrt.def.h | 4 ++--
 11 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/winsup/cygwin/math/acosl.c b/winsup/cygwin/math/acosl.c
index 511b5def2..553d06f75 100644
--- a/winsup/cygwin/math/acosl.c
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/asinl.c b/winsup/cygwin/math/asinl.c
index a4d8746be..35df3b5dd 100644
--- a/winsup/cygwin/math/asinl.c
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/atan2l.c b/winsup/cygwin/math/atan2l.c
index a32b097fb..a4300cbf4 100644
--- a/winsup/cygwin/math/atan2l.c
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/atanl.c b/winsup/cygwin/math/atanl.c
index b85d05350..d289ef08c 100644
--- a/winsup/cygwin/math/atanl.c
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/exp.def.h b/winsup/cygwin/math/exp.def.h
index d4d4c04cf..3066b745d 100644
--- a/winsup/cygwin/math/exp.def.h
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/fabsl.c b/winsup/cygwin/math/fabsl.c
index 2dfdfaa45..f3864ea13 100644
--- a/winsup/cygwin/math/fabsl.c
+++ b/winsup/cygwin/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_)
   return __builtin_fabsl (x);
diff --git a/winsup/cygwin/math/fmodl.c b/winsup/cygwin/math/fmodl.c
index 6224db13b..462b6fa79 100644
--- a/winsup/cygwin/math/fmodl.c
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/logbl.c b/winsup/cygwin/math/logbl.c
index 310c4457b..5e533c07c 100644
--- a/winsup/cygwin/math/logbl.c
+++ b/winsup/cygwin/math/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/winsup/cygwin/math/modfl.c b/winsup/cygwin/math/modfl.c
index ef1ab16ce..33593e6de 100644
--- a/winsup/cygwin/math/modfl.c
+++ b/winsup/cygwin/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/winsup/cygwin/math/pow.def.h b/winsup/cygwin/math/pow.def.h
index c22064b58..2ea825720 100644
--- a/winsup/cygwin/math/pow.def.h
+++ b/winsup/cygwin/math/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"
@@ -204,7 +204,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;
 	}
     }
diff --git a/winsup/cygwin/math/sqrt.def.h b/winsup/cygwin/math/sqrt.def.h
index 863c0286c..cf8b5cbe6 100644
--- a/winsup/cygwin/math/sqrt.def.h
+++ b/winsup/cygwin/math/sqrt.def.h
@@ -50,7 +50,7 @@
  * asm ("fsqrts %[dst], %[src];\n" : [dst] "=w" (res) : [src] "w" (x));
  */
 __FLT_TYPE __fsqrt_internal( __FLT_TYPE x );
-asm(".def __fsqrt_internal; .scl 2; .type 32; .endef\n"
+asm volatile(".def __fsqrt_internal; .scl 2; .type 32; .endef\n"
     "\t.text\n"
     "\t.align 4\n"
     "\t.globl __fsqrt_internal\n"
@@ -85,7 +85,7 @@ __FLT_ABI (sqrt) (__FLT_TYPE x)
 #if defined(__arm__) || defined(_ARM_)
   __fsqrt_internal(x);
 #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


                 reply	other threads:[~2020-08-30 12:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200830123025.2F5BD3836C73@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).