This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH, AArch64] Make MOVK output operand 2 in hex
- From: "Ian Bolton" <ian dot bolton at arm dot com>
- To: <gcc-patches at gcc dot gnu dot org>
- Date: Wed, 20 Mar 2013 17:21:38 -0000
- Subject: [PATCH, AArch64] Make MOVK output operand 2 in hex
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.
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 } } */