Patchwork [AArch64] Make MOVK output operand 2 in hex

login
register
mail settings
Submitter Ian Bolton
Date March 20, 2013, 5:21 p.m.
Message ID <000001ce258f$61932f70$24b98e50$@bolton@arm.com>
Download mbox | patch
Permalink /patch/229437/
State New
Headers show

Comments

Ian Bolton - March 20, 2013, 5:21 p.m.
MOVK should not be generated with a negative immediate, which
the assembler rightfully rejects.

This patch makes MOVK output its 2nd operand in hex instead.

Tested on bare-metal and linux.

OK for trunk?

Cheers,
Ian


2013-03-20  Ian Bolton  <ian.bolton@arm.com>

gcc/
	* config/aarch64/aarch64.c (aarch64_print_operand): New
	format specifier for printing a constant in hex.
	* config/aarch64/aarch64.md (insv_imm<mode>): Use the X
	format specifier for printing second operand.

testsuite/
	* gcc.target/aarch64/movk.c: New test.
Marcus Shawcroft - March 28, 2013, 2:59 p.m.
On 20/03/13 17:21, Ian Bolton wrote:
> MOVK should not be generated with a negative immediate, which
> the assembler rightfully rejects.
>
> This patch makes MOVK output its 2nd operand in hex instead.
>
> Tested on bare-metal and linux.
>
> OK for trunk?
>
> Cheers,
> Ian
>
>
> 2013-03-20  Ian Bolton  <ian.bolton@arm.com>
>
> gcc/
> 	* config/aarch64/aarch64.c (aarch64_print_operand): New
> 	format specifier for printing a constant in hex.
> 	* config/aarch64/aarch64.md (insv_imm<mode>): Use the X
> 	format specifier for printing second operand.
>
> testsuite/
> 	* gcc.target/aarch64/movk.c: New test.
>

OK

/Marcus

Patch

diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1404a70..5e51630 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -3365,6 +3365,16 @@  aarch64_print_operand (FILE *f, rtx x, char code)
 			       REGNO (x) - V0_REGNUM + (code - 'S'));
       break;
 
+    case 'X':
+      /* Print integer constant in hex.  */
+      if (GET_CODE (x) != CONST_INT)
+	{
+	  output_operand_lossage ("invalid operand for '%%%c'", code);
+	  return;
+	}
+      asm_fprintf (f, "0x%x", UINTVAL (x));
+      break;
+
     case 'w':
     case 'x':
       /* Print a general register name or the zero register (32-bit or
diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index 40e66db..9c89413 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -850,8 +850,8 @@ 
 	(match_operand:GPI 2 "const_int_operand" "n"))]
   "INTVAL (operands[1]) < GET_MODE_BITSIZE (<MODE>mode)
    && INTVAL (operands[1]) % 16 == 0
-   && INTVAL (operands[2]) <= 0xffff"
-  "movk\\t%<w>0, %2, lsl %1"
+   && UINTVAL (operands[2]) <= 0xffff"
+  "movk\\t%<w>0, %X2, lsl %1"
   [(set_attr "v8type" "movk")
    (set_attr "mode" "<MODE>")]
 )
diff --git a/gcc/testsuite/gcc.target/aarch64/movk.c b/gcc/testsuite/gcc.target/aarch64/movk.c
new file mode 100644
index 0000000..e4b2209
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/movk.c
@@ -0,0 +1,31 @@ 
+/* { dg-do run } */
+/* { dg-options "-O2 --save-temps -fno-inline" } */
+
+extern void abort (void);
+
+long long int
+dummy_number_generator ()
+{
+  /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0xefff, lsl 16" } } */
+  /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0xc4cc, lsl 32" } } */
+  /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0xfffe, lsl 48" } } */
+  return -346565474575675;
+}
+
+int
+main (void)
+{
+
+  long long int num = dummy_number_generator ();
+  if (num > 0)
+    abort ();
+
+  /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0x4667, lsl 16" } } */
+  /* { dg-final { scan-assembler "movk\tx\[0-9\]+, 0x7a3d, lsl 32" } } */
+  if (num / 69313094915135 != -5)
+    abort ();
+
+  return 0;
+}
+
+/* { dg-final { cleanup-saved-temps } } */