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.bol...@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. ----------------- 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); +}