Patchwork [i386] : Cleanup ix86_output_operand

login
register
mail settings
Submitter Uros Bizjak
Date May 21, 2012, 7:30 p.m.
Message ID <CAFULd4a476-ySLv2zObs5EZ7ZiuTBGvagDC92Bv2mXErqBHu0g@mail.gmail.com>
Download mbox | patch
Permalink /patch/160436/
State New
Headers show

Comments

Uros Bizjak - May 21, 2012, 7:30 p.m.
Hello!

A cleanup to make ix86_output_operand more maintainable:

- merge condition code handling where appropriate
- change a couple of operands of put_condition_code to bool
- fix a couple of error reporting strings (COMPARISON_P does not check
for constant)
- move operand size checking cases together,
- move condition code handling together

No functional changes.

2012-05-21  Uros Bizjak  <ubizjak@gmail.com>

	* config/i386/i386.c (put_condition_code): Change "reverse" and "fp"
	arguments to bool.
	(ix86_print_operand) <case 'O'>: Look at mode size of the operand.
	Do not print '.' here.  Output operand lossage error for unhandled
	sizes.  Move.
	<case '*'>: Move.
	<case '&'>: Ditto.
	<case 'Y'>: Ditto.
	<case 'z'>: Hardcode "code" argument into error strings.
	<case 'Z'>: Ditto.
	<case 'D'>: Merge AVX and non-AVX codes.
	<case 'C', case 'c', case 'F', case 'f'>: Merge.  Fix error string.
	Update call to put_condition_code.

Tested on x86_64-pc-linux-gnu {,-m32}, also with
HAVE_AS_IX86_CMOV_SUN_SYNTAX (until bootstrap breaks due to invalid
generated asm).

Committed to mainline SVN.

Uros.

Patch

Index: i386.c
===================================================================
--- i386.c	(revision 187726)
+++ i386.c	(working copy)
@@ -13610,8 +13610,8 @@  ix86_find_base_term (rtx x)
 }
 
 static void
-put_condition_code (enum rtx_code code, enum machine_mode mode, int reverse,
-		    int fp, FILE *file)
+put_condition_code (enum rtx_code code, enum machine_mode mode, bool reverse,
+		    bool fp, FILE *file)
 {
   const char *suffix;
 
@@ -13932,8 +13932,8 @@  get_some_local_dynamic_name (void)
    C -- print opcode suffix for set/cmov insn.
    c -- like C, but print reversed condition
    F,f -- likewise, but for floating-point.
-   O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, expand to "w.", "l." or "q.",
-        otherwise nothing
+   O -- if HAVE_AS_IX86_CMOV_SUN_SYNTAX, print the opcode suffix for
+	the size of the current operand, otherwise nothing.
    R -- print the prefix for register names.
    z -- print the opcode suffix for the size of the current operand.
    Z -- likewise, with special suffixes for x87 instructions.
@@ -13974,22 +13974,6 @@  ix86_print_operand (FILE *file, rtx x, int code)
     {
       switch (code)
 	{
-	case '*':
-	  if (ASSEMBLER_DIALECT == ASM_ATT)
-	    putc ('*', file);
-	  return;
-
-	case '&':
-	  {
-	    const char *name = get_some_local_dynamic_name ();
-	    if (name == NULL)
-	      output_operand_lossage ("'%%&' used without any "
-				      "local dynamic TLS references");
-	    else
-	      assemble_name (file, name);
-	    return;
-	  }
-
 	case 'A':
 	  switch (ASSEMBLER_DIALECT)
 	    {
@@ -14054,6 +14038,33 @@  ix86_print_operand (FILE *file, rtx x, int code)
 	    putc ('t', file);
 	  return;
 
+	case 'O':
+#ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
+	  if (ASSEMBLER_DIALECT != ASM_ATT)
+	    return;
+
+	  switch (GET_MODE_SIZE (GET_MODE (x)))
+	    {
+	    case 2:
+	      putc ('w', file);
+	      break;
+  
+	    case 4:
+	      putc ('l', file);
+	      break;
+
+	    case 8:
+	      putc ('q', file);
+	      break;
+
+	    default:
+	      output_operand_lossage
+		("invalid operand size for operand code 'O'");
+	      return;
+	    }
+#endif
+	  return;
+
 	case 'z':
 	  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_INT)
 	    {
@@ -14081,14 +14092,14 @@  ix86_print_operand (FILE *file, rtx x, int code)
 
 		default:
 		  output_operand_lossage
-		    ("invalid operand size for operand code '%c'", code);
+		    ("invalid operand size for operand code 'z'");
 		  return;
 		}
 	    }
 
 	  if (GET_MODE_CLASS (GET_MODE (x)) == MODE_FLOAT)
 	    warning
-	      (0, "non-integer operand used with operand code '%c'", code);
+	      (0, "non-integer operand used with operand code 'z'");
 	  /* FALLTHRU */
 
 	case 'Z':
@@ -14151,12 +14162,12 @@  ix86_print_operand (FILE *file, rtx x, int code)
 	  else
 	    {
 	      output_operand_lossage
-		("invalid operand type used with operand code '%c'", code);
+		("invalid operand type used with operand code 'Z'");
 	      return;
 	    }
 
 	  output_operand_lossage
-	    ("invalid operand size for operand code '%c'", code);
+	    ("invalid operand size for operand code 'Z'");
 	  return;
 
 	case 'd':
@@ -14181,179 +14192,160 @@  ix86_print_operand (FILE *file, rtx x, int code)
 	    }
 	  return;
 
+	case 'Y':
+	  switch (GET_CODE (x))
+	    {
+	    case NE:
+	      fputs ("neq", file);
+	      break;
+	    case EQ:
+	      fputs ("eq", file);
+	      break;
+	    case GE:
+	    case GEU:
+	      fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
+	      break;
+	    case GT:
+	    case GTU:
+	      fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
+	      break;
+	    case LE:
+	    case LEU:
+	      fputs ("le", file);
+	      break;
+	    case LT:
+	    case LTU:
+	      fputs ("lt", file);
+	      break;
+	    case UNORDERED:
+	      fputs ("unord", file);
+	      break;
+	    case ORDERED:
+	      fputs ("ord", file);
+	      break;
+	    case UNEQ:
+	      fputs ("ueq", file);
+	      break;
+	    case UNGE:
+	      fputs ("nlt", file);
+	      break;
+	    case UNGT:
+	      fputs ("nle", file);
+	      break;
+	    case UNLE:
+	      fputs ("ule", file);
+	      break;
+	    case UNLT:
+	      fputs ("ult", file);
+	      break;
+	    case LTGT:
+	      fputs ("une", file);
+	      break;
+	    default:
+	      output_operand_lossage ("operand is not a condition code, "
+				      "invalid operand code 'Y'");
+	      return;
+	    }
+	  return;
+
 	case 'D':
 	  /* Little bit of braindamage here.  The SSE compare instructions
 	     does use completely different names for the comparisons that the
 	     fp conditional moves.  */
-	  if (TARGET_AVX)
+	  switch (GET_CODE (x))
 	    {
-	      switch (GET_CODE (x))
+	    case UNEQ:
+	      if (TARGET_AVX)
 		{
-		case EQ:
-		  fputs ("eq", file);
-		  break;
-		case UNEQ:
 		  fputs ("eq_us", file);
 		  break;
-		case LT:
-		  fputs ("lt", file);
-		  break;
-		case UNLT:
+		}
+	    case EQ:
+	      fputs ("eq", file);
+	      break;
+	    case UNLT:
+	      if (TARGET_AVX)
+		{
 		  fputs ("nge", file);
 		  break;
-		case LE:
-		  fputs ("le", file);
-		  break;
-		case UNLE:
+		}
+	    case LT:
+	      fputs ("lt", file);
+	      break;
+	    case UNLE:
+	      if (TARGET_AVX)
+		{
 		  fputs ("ngt", file);
 		  break;
-		case UNORDERED:
-		  fputs ("unord", file);
-		  break;
-		case NE:
-		  fputs ("neq", file);
-		  break;
-		case LTGT:
+		}
+	    case LE:
+	      fputs ("le", file);
+	      break;
+	    case UNORDERED:
+	      fputs ("unord", file);
+	      break;
+	    case LTGT:
+	      if (TARGET_AVX)
+		{
 		  fputs ("neq_oq", file);
 		  break;
-		case GE:
+		}
+	    case NE:
+	      fputs ("neq", file);
+	      break;
+	    case GE:
+	      if (TARGET_AVX)
+		{
 		  fputs ("ge", file);
 		  break;
-		case UNGE:
-		  fputs ("nlt", file);
-		  break;
-		case GT:
-		  fputs ("gt", file);
-		  break;
-		case UNGT:
-		  fputs ("nle", file);
-		  break;
-		case ORDERED:
-		  fputs ("ord", file);
-		  break;
-		default:
-		  output_operand_lossage ("operand is not a condition code, "
-					  "invalid operand code 'D'");
-		  return;
 		}
-	    }
-	  else
-	    {
-	      switch (GET_CODE (x))
+	    case UNGE:
+	      fputs ("nlt", file);
+	      break;
+	    case GT:
+	      if (TARGET_AVX)
 		{
-		case EQ:
-		case UNEQ:
-		  fputs ("eq", file);
+		  fputs ("gt", file);
 		  break;
-		case LT:
-		case UNLT:
-		  fputs ("lt", file);
-		  break;
-		case LE:
-		case UNLE:
-		  fputs ("le", file);
-		  break;
-		case UNORDERED:
-		  fputs ("unord", file);
-		  break;
-		case NE:
-		case LTGT:
-		  fputs ("neq", file);
-		  break;
-		case UNGE:
-		case GE:
-		  fputs ("nlt", file);
-		  break;
-		case UNGT:
-		case GT:
-		  fputs ("nle", file);
-		  break;
-		case ORDERED:
-		  fputs ("ord", file);
-		  break;
-		default:
-		  output_operand_lossage ("operand is not a condition code, "
-					  "invalid operand code 'D'");
-		  return;
 		}
-	    }
-	  return;
-	case 'O':
-#ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
-	  if (ASSEMBLER_DIALECT == ASM_ATT)
-	    {
-	      switch (GET_MODE (x))
-		{
-		case HImode: putc ('w', file); break;
-		case SImode:
-		case SFmode: putc ('l', file); break;
-		case DImode:
-		case DFmode: putc ('q', file); break;
-		default: gcc_unreachable ();
-		}
-	      putc ('.', file);
-	    }
-#endif
-	  return;
-	case 'C':
-	  if (!COMPARISON_P (x))
-	    {
-	      output_operand_lossage ("operand is neither a constant nor a "
-				      "condition code, invalid operand code "
-				      "'C'");
+	    case UNGT:
+	      fputs ("nle", file);
+	      break;
+	    case ORDERED:
+	      fputs ("ord", file);
+	      break;
+	    default:
+	      output_operand_lossage ("operand is not a condition code, "
+				      "invalid operand code 'D'");
 	      return;
 	    }
-	  put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 0, file);
 	  return;
-	case 'F':
-	  if (!COMPARISON_P (x))
-	    {
-	      output_operand_lossage ("operand is neither a constant nor a "
-				      "condition code, invalid operand code "
-				      "'F'");
-	      return;
-	    }
-#ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
-	  if (ASSEMBLER_DIALECT == ASM_ATT)
-	    putc ('.', file);
-#endif
-	  put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 0, 1, file);
-	  return;
 
-	  /* Like above, but reverse condition */
+	case 'C':
 	case 'c':
-	  /* Check to see if argument to %c is really a constant
-	     and not a condition code which needs to be reversed.  */
-	  if (!COMPARISON_P (x))
-	    {
-	      output_operand_lossage ("operand is neither a constant nor a "
-				      "condition code, invalid operand "
-				      "code 'c'");
-	      return;
-	    }
-	  put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 0, file);
-	  return;
+	case 'F':
 	case 'f':
 	  if (!COMPARISON_P (x))
 	    {
-	      output_operand_lossage ("operand is neither a constant nor a "
-				      "condition code, invalid operand "
-				      "code 'f'");
+	      output_operand_lossage ("operand is not a condition code, "
+				      "invalid operand code '%c'", code);
 	      return;
 	    }
 #ifdef HAVE_AS_IX86_CMOV_SUN_SYNTAX
 	  if (ASSEMBLER_DIALECT == ASM_ATT)
 	    putc ('.', file);
 #endif
-	  put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)), 1, 1, file);
+	  put_condition_code (GET_CODE (x), GET_MODE (XEXP (x, 0)),
+			      code == 'c' || code == 'f',
+			      code == 'F' || code == 'f',
+			      file);
 	  return;
 
 	case 'H':
 	  if (!offsettable_memref_p (x))
 	    {
 	      output_operand_lossage ("operand is not an offsettable memory "
-				      "reference, invalid operand "
-				      "code 'H'");
+				      "reference, invalid operand code 'H'");
 	      return;
 	    }
 	  /* It doesn't actually matter what mode we use here, as we're
@@ -14379,6 +14371,22 @@  ix86_print_operand (FILE *file, rtx x, int code)
 	  /* We do not want to print value of the operand.  */
 	  return;
 
+	case '*':
+	  if (ASSEMBLER_DIALECT == ASM_ATT)
+	    putc ('*', file);
+	  return;
+
+	case '&':
+	  {
+	    const char *name = get_some_local_dynamic_name ();
+	    if (name == NULL)
+	      output_operand_lossage ("'%%&' used without any "
+				      "local dynamic TLS references");
+	    else
+	      assemble_name (file, name);
+	    return;
+	  }
+
 	case '+':
 	  {
 	    rtx x;
@@ -14416,62 +14424,6 @@  ix86_print_operand (FILE *file, rtx x, int code)
 	    return;
 	  }
 
-	case 'Y':
-	  switch (GET_CODE (x))
-	    {
-	    case NE:
-	      fputs ("neq", file);
-	      break;
-	    case EQ:
-	      fputs ("eq", file);
-	      break;
-	    case GE:
-	    case GEU:
-	      fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "ge" : "unlt", file);
-	      break;
-	    case GT:
-	    case GTU:
-	      fputs (INTEGRAL_MODE_P (GET_MODE (x)) ? "gt" : "unle", file);
-	      break;
-	    case LE:
-	    case LEU:
-	      fputs ("le", file);
-	      break;
-	    case LT:
-	    case LTU:
-	      fputs ("lt", file);
-	      break;
-	    case UNORDERED:
-	      fputs ("unord", file);
-	      break;
-	    case ORDERED:
-	      fputs ("ord", file);
-	      break;
-	    case UNEQ:
-	      fputs ("ueq", file);
-	      break;
-	    case UNGE:
-	      fputs ("nlt", file);
-	      break;
-	    case UNGT:
-	      fputs ("nle", file);
-	      break;
-	    case UNLE:
-	      fputs ("ule", file);
-	      break;
-	    case UNLT:
-	      fputs ("ult", file);
-	      break;
-	    case LTGT:
-	      fputs ("une", file);
-	      break;
-	    default:
-	      output_operand_lossage ("operand is not a condition code, "
-				      "invalid operand code 'Y'");
-	      return;
-	    }
-	  return;
-
 	case ';':
 #ifndef HAVE_AS_IX86_REP_LOCK_PREFIX
 	  putc (';', file);