x86/Solaris: correct support for Sun form of CMOV<size>.S

Message ID 75f2d7fc-eddd-4c90-8c2e-313ae283a8ce@suse.com
State New
Headers
Series x86/Solaris: correct support for Sun form of CMOV<size>.S |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Jan Beulich Jan. 21, 2025, 11:13 a.m. UTC
  PR gas/32579

The deprecated .s (swapped operand encoding) functionality got in the
way of properly recognizing this specific form. Move the Solaris-
specific code ahead of that.
  

Comments

Rainer Orth Jan. 21, 2025, 4:10 p.m. UTC | #1
Hi Jan,

> PR gas/32579
>
> The deprecated .s (swapped operand encoding) functionality got in the
> way of properly recognizing this specific form. Move the Solaris-
> specific code ahead of that.

thanks for the quick patch.  I've successfully bootstrapped gcc trunk
with it on i386-pc-solaris2.11.  There's one regression in the gcc
testsuite, though:

FAIL: gcc.target/i386/cmov12.c scan-assembler-times cmovg 3

where gcc.log reports

gcc.target/i386/cmov12.c: cmovg found 0 times

No wonder given

--- cmov12.s.bu243	2025-01-21 16:55:27.038829605 +0100
+++ cmov12.s.bu24390	2025-01-21 16:55:44.565051230 +0100
@@ -41,9 +41,9 @@
 	leal	1(%rdx), %ebp
 	movl	(%r11), %esi
 	cmpl	%eax, %esi
-	cmovg	%ebp, %edx
-	cmovg	%r11, %rcx
-	cmovg	%esi, %eax
+	cmovl.g	%ebp, %edx
+	cmovq.g	%r11, %rcx
+	cmovl.g	%esi, %eax

The same failure occurs with /bin/as.  The testcase simply has to be
adjusted for both syntaxes.

Thanks.
	Rainer
  

Patch

--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -7758,6 +7758,32 @@  parse_insn (const char *line, char *mnem
 
   if (!current_templates.start)
     {
+#ifdef TE_SOLARIS
+      /* Sun specifies an alternative form for CMOVcc: Size suffix (if any)
+	 first, then a dot, then the condition code mnemonic.  */
+      if ((mnemonic + 4 == dot_p && !memcmp (mnemonic, "cmov", 4))
+	  /* While doc doesn't say so, gcc assumes it: Same for FCMOVcc,
+	     except that there's no size suffix to care about.  */
+	  || (mnemonic + 5 == dot_p && !memcmp (mnemonic, "fcmov", 5)))
+	{
+	  /* Simply strip the dot.  */
+	  memmove (dot_p, dot_p + 1, mnem_p - dot_p);
+	  dot_p = mnem_p - 1;
+	}
+      else if (!intel_syntax
+	       && mnemonic + 5 == dot_p
+	       && !memcmp (mnemonic, "cmov", 4)
+	       && strchr ("lqw", TOLOWER (dot_p[-1])))
+	{
+	  /* Strip the dot, while moving the suffix.  */
+	  char suffix = dot_p[-1];
+
+	  memmove (dot_p - 1, dot_p + 1, mnem_p - dot_p);
+	  mnem_p[-2] = suffix;
+	  dot_p = mnem_p - 1;
+	}
+      else
+#endif
       /* Deprecated functionality (new code should use pseudo-prefixes instead):
 	 Check if we should swap operand or force 32bit displacement in
 	 encoding.  */
@@ -7788,33 +7814,6 @@  parse_insn (const char *line, char *mnem
 	  else if (pp.disp_encoding != disp_encoding_32bit)
 	    as_warn (_("ignoring `.d32' suffix due to earlier `{disp<N>}'"));
 	}
-#ifdef TE_SOLARIS
-      /* Sun specifies an alternative form for CMOVcc: Size suffix (if any)
-	 first, then a dot, then the condition code mnemonic.  */
-      else if ((mnemonic + 4 == dot_p
-		&& !memcmp (mnemonic, "cmov", 4))
-	       /* While doc doesn't say so, gcc assumes it: Same for FCMOVcc,
-		  except that there's no size suffix to care about.  */
-	       || (mnemonic + 5 == dot_p
-		   && !memcmp (mnemonic, "fcmov", 5)))
-	{
-	  /* Simply strip the dot.  */
-	  memmove (dot_p, dot_p + 1, mnem_p - dot_p);
-	  dot_p = mnem_p - 1;
-	}
-      else if (!intel_syntax
-	       && mnemonic + 5 == dot_p
-	       && !memcmp (mnemonic, "cmov", 4)
-	       && strchr ("lqw", TOLOWER (dot_p[-1])))
-	{
-	  /* Strip the dot, while moving the suffix.  */
-	  char suffix = dot_p[-1];
-
-	  memmove (dot_p - 1, dot_p + 1, mnem_p - dot_p);
-	  mnem_p[-2] = suffix;
-	  dot_p = mnem_p - 1;
-	}
-#endif
       else
 	goto check_suffix;
       mnem_p = dot_p;
--- a/gas/testsuite/gas/i386/solaris/cmov.d
+++ b/gas/testsuite/gas/i386/solaris/cmov.d
@@ -22,6 +22,10 @@  Disassembly of section .text:
 [ 	]*[a-f0-9]+:	48 0f 44 08          	cmove  \(%rax\),%rcx
 [ 	]*[a-f0-9]+:	48 0f 44 08          	cmove  \(%rax\),%rcx
 [ 	]*[a-f0-9]+:	48 0f 44 08          	cmove  \(%rax\),%rcx
+[ 	]*[a-f0-9]+:	0f 48 c8             	cmovs  %eax,%ecx
+[ 	]*[a-f0-9]+:	66 0f 48 c8          	cmovs  %ax,%cx
+[ 	]*[a-f0-9]+:	0f 48 c8             	cmovs  %eax,%ecx
+[ 	]*[a-f0-9]+:	48 0f 48 c8          	cmovs  %rax,%rcx
 [ 	]*[a-f0-9]+:	da d9                	fcmovu %st\(1\),%st
 [ 	]*[a-f0-9]+:	da d9                	fcmovu %st\(1\),%st
 #pass
--- a/gas/testsuite/gas/i386/solaris/cmov.s
+++ b/gas/testsuite/gas/i386/solaris/cmov.s
@@ -20,5 +20,10 @@  cmov:
 	cmoveq		(%rax), %rcx
 	cmovq.e		(%rax), %rcx
 
+	cmov.s		%eax, %ecx
+	cmovw.s		%ax, %cx
+	cmovl.s		%eax, %ecx
+	cmovq.s		%rax, %rcx
+
 	fcmovu		%st(1), %st
 	fcmov.u		%st(1), %st