diff mbox

[testsuite] Fix sse4_1-round* inline asm statements

Message ID VI1PR07MB09117A2BEB1A1F7F475C5437E4080@VI1PR07MB0911.eurprd07.prod.outlook.com
State New
Headers show

Commit Message

Bernd Edlinger Dec. 8, 2015, 4:43 p.m. UTC
Hi,

this patch fixes the asm statements in the gcc.target/i386/sse4_1-round* test cases.

They do lots of things that are just absolutely forbidden, like clobber registers
that are not mentioned in the clobber list, and create a hidden data flow.

The test cases work just by chance, and You can see the asm statements
ripped completely apart by the loop optimizer if you try to do the assembler
part in a loop:

  for (i = 0; i < 10; i++) {
  __asm__ ("fld" ASM_SUFFIX " %0" : : "m" (*&f));

  __asm__ ("fstcw %0" : "=m" (*&saved_cw));
  new_cw = saved_cw & clr_mask;
  new_cw |= type;
  __asm__ ("fldcw %0" : : "m" (*&new_cw));

  __asm__ ("frndint\n"
           "fstp" ASM_SUFFIX " %0\n" : "=m" (*&ret));
  __asm__ ("fldcw %0" : : "m" (*&saved_cw));
  }
  return ret;

So this patch avoids the hidden data flow, and
adds "st" to the clobber list.

Boot-strapped and reg-tested on x86_64-pc-linux-gnu
OK for trunk?


Thanks
Bernd.
diff mbox

Patch

2015-12-08  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	* gcc.target/i386/sse4_1-round.h: Fix inline asm statements.
	* gcc.target/i386/sse4_1-roundsd-4.c: Fix inline asm statements.
	* gcc.target/i386/sse4_1-roundss-4.c: Fix inline asm statements.

Index: gcc/testsuite/gcc.target/i386/sse4_1-round.h
===================================================================
--- gcc/testsuite/gcc.target/i386/sse4_1-round.h	(revision 231343)
+++ gcc/testsuite/gcc.target/i386/sse4_1-round.h	(working copy)
@@ -42,16 +42,16 @@  do_round (FP_T f, int type)
       clr_mask = ~0x0C3F;
     }
 
-  __asm__ ("fld" ASM_SUFFIX " %0" : : "m" (*&f));
-
   __asm__ ("fstcw %0" : "=m" (*&saved_cw));
   new_cw = saved_cw & clr_mask;
   new_cw |= type;
-  __asm__ ("fldcw %0" : : "m" (*&new_cw));
-
-  __asm__ ("frndint\n"
-	   "fstp" ASM_SUFFIX " %0\n" : "=m" (*&ret));
-  __asm__ ("fldcw %0" : : "m" (*&saved_cw));
+  __asm__ ("fld" ASM_SUFFIX " %1\n"
+	   "fldcw %2\n"
+	   "frndint\n"
+	   "fstp" ASM_SUFFIX " %0\n"
+	   "fldcw %3" : "=m" (*&ret)
+		      : "m" (*&f), "m" (*&new_cw), "m" (*&saved_cw)
+		      : "st");
   return ret;
 }
 
Index: gcc/testsuite/gcc.target/i386/sse4_1-roundsd-4.c
===================================================================
--- gcc/testsuite/gcc.target/i386/sse4_1-roundsd-4.c	(revision 231343)
+++ gcc/testsuite/gcc.target/i386/sse4_1-roundsd-4.c	(working copy)
@@ -50,16 +50,16 @@  do_round (double f, int type)
       clr_mask = ~0x0C3F;
     }
 
-  __asm__ ("fldl %0" : : "m" (*&f));
-
   __asm__ ("fstcw %0" : "=m" (*&saved_cw));
   new_cw = saved_cw & clr_mask;
   new_cw |= type;
-  __asm__ ("fldcw %0" : : "m" (*&new_cw));
-
-  __asm__ ("frndint\n"
-	   "fstpl %0\n" : "=m" (*&ret));
-  __asm__ ("fldcw %0" : : "m" (*&saved_cw));
+  __asm__ ("fldl %1\n"
+	   "fldcw %2\n"
+	   "frndint\n"
+	   "fstpl %0\n"
+	   "fldcw %3" : "=m" (*&ret)
+		      : "m" (*&f), "m" (*&new_cw), "m" (*&saved_cw)
+		      : "st");
   return ret;
 }
 
Index: gcc/testsuite/gcc.target/i386/sse4_1-roundss-4.c
===================================================================
--- gcc/testsuite/gcc.target/i386/sse4_1-roundss-4.c	(revision 231343)
+++ gcc/testsuite/gcc.target/i386/sse4_1-roundss-4.c	(working copy)
@@ -50,16 +50,16 @@  do_round (float f, int type)
       clr_mask = ~0x0C3F;
     }
 
-  __asm__ ("flds %0" : : "m" (*&f));
-
   __asm__ ("fstcw %0" : "=m" (*&saved_cw));
   new_cw = saved_cw & clr_mask;
   new_cw |= type;
-  __asm__ ("fldcw %0" : : "m" (*&new_cw));
-
-  __asm__ ("frndint\n"
-	   "fstps %0\n" : "=m" (*&ret));
-  __asm__ ("fldcw %0" : : "m" (*&saved_cw));
+  __asm__ ("flds %1\n"
+	   "fldcw %2\n"
+	   "frndint\n"
+	   "fstps %0\n"
+	   "fldcw %3" : "=m" (*&ret)
+		      : "m" (*&f), "m" (*&new_cw), "m" (*&saved_cw)
+		      : "st");
   return ret;
 }