Patchwork [AArch64] Implement bswaphi2 with rev16

login
register
mail settings
Submitter Ian Bolton
Date Nov. 16, 2012, 6:52 p.m.
Message ID <000201cdc42b$89b5e710$9d21b530$@bolton@arm.com>
Download mbox | patch
Permalink /patch/199714/
State New
Headers show

Comments

Ian Bolton - Nov. 16, 2012, 6:52 p.m.
This patch implements the standard pattern bswaphi2 for AArch64.

Regression tests all pass.

OK for trunk and backport to arm/aarch64-4.7-branch?

Cheers,
Ian



2012-11-16  Ian Bolton  <ian.bolton@arm.com>

	* gcc/config/aarch64/aarch64.md (bswaphi2): New pattern.
	* gcc/testsuite/gcc.target/aarch64/builtin-bswap-1.c: New test.
	* gcc/testsuite/gcc.target/aarch64/builtin-bswap-2.c: New test.


-----------------
Marcus Shawcroft - Nov. 19, 2012, 6:40 p.m.
On 16 Nov 2012, at 18:52, Ian Bolton <ian.bolton@arm.com> wrote:

> This patch implements the standard pattern bswaphi2 for AArch64.
> 
> Regression tests all pass.
> 
> OK for trunk and backport to arm/aarch64-4.7-branch?

OK

/Marcus

Patch

diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md
index e6086a9..22c7103 100644
--- a/gcc/config/aarch64/aarch64.md
+++ b/gcc/config/aarch64/aarch64.md
@@ -2340,6 +2340,15 @@ 
    (set_attr "mode" "<MODE>")]
 )
 
+(define_insn "bswaphi2"
+  [(set (match_operand:HI 0 "register_operand" "=r")
+        (bswap:HI (match_operand:HI 1 "register_operand" "r")))]
+  ""
+  "rev16\\t%w0, %w1"
+  [(set_attr "v8type" "rev")
+   (set_attr "mode" "HI")]
+)
+
 ;; -------------------------------------------------------------------
 ;; Floating-point intrinsics
 ;; -------------------------------------------------------------------
diff --git a/gcc/testsuite/gcc.target/aarch64/builtin-bswap-1.c
b/gcc/testsuite/gcc.target/aarch64/builtin-bswap-1.c
new file mode 100644
index 0000000..a6706e6
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/builtin-bswap-1.c
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* { dg-final { scan-assembler-times "rev16\\t" 2 } }  */
+
+/* rev16 */
+short
+swaps16 (short x)
+{
+  return __builtin_bswap16 (x);
+}
+
+/* rev16 */
+unsigned short
+swapu16 (unsigned short x)
+{
+  return __builtin_bswap16 (x);
+}
diff --git a/gcc/testsuite/gcc.target/aarch64/builtin-bswap-2.c
b/gcc/testsuite/gcc.target/aarch64/builtin-bswap-2.c
new file mode 100644
index 0000000..6018b48
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/builtin-bswap-2.c
@@ -0,0 +1,18 @@ 
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+/* { dg-final { scan-assembler-times "rev16\\t" 2 } }  */
+
+/* rev16 */
+unsigned short
+swapu16_1 (unsigned short x)
+{
+  return (x << 8) | (x >> 8);
+}
+
+/* rev16 */
+unsigned short
+swapu16_2 (unsigned short x)
+{
+  return (x >> 8) | (x << 8);
+}