public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4566] bpf: add define_insn for bswap
@ 2022-12-08 18:50 David Faust
0 siblings, 0 replies; only message in thread
From: David Faust @ 2022-12-08 18:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:5ddfe794405a514824382e96b1047d3195af23cc
commit r13-4566-g5ddfe794405a514824382e96b1047d3195af23cc
Author: David Faust <david.faust@oracle.com>
Date: Thu Dec 8 10:08:22 2022 -0800
bpf: add define_insn for bswap
The eBPF architecture provides 'end[be,le]' instructions for endianness
swapping. Add a define_insn for bswap<mode>2 to use them instaed of
falling back on a libcall.
gcc/
* config/bpf/bpf.md (bswap<mode>2): New define_insn.
gcc/testsuite/
* gcc.target/bpf/bswap-1.c: New test.
Diff:
---
gcc/config/bpf/bpf.md | 17 +++++++++++++++++
gcc/testsuite/gcc.target/bpf/bswap-1.c | 23 +++++++++++++++++++++++
2 files changed, 40 insertions(+)
diff --git a/gcc/config/bpf/bpf.md b/gcc/config/bpf/bpf.md
index a28021aef26..22a133f1c79 100644
--- a/gcc/config/bpf/bpf.md
+++ b/gcc/config/bpf/bpf.md
@@ -341,6 +341,23 @@
"rsh<msuffix>\t%0,%2"
[(set_attr "type" "<mtype>")])
+;;;; Endianness conversion
+
+(define_mode_iterator BSM [HI SI DI])
+(define_mode_attr endmode [(HI "16") (SI "32") (DI "64")])
+
+(define_insn "bswap<BSM:mode>2"
+ [(set (match_operand:BSM 0 "register_operand" "=r")
+ (bswap:BSM (match_operand:BSM 1 "register_operand" " r")))]
+ ""
+{
+ if (TARGET_BIG_ENDIAN)
+ return "endle\t%0, <endmode>";
+ else
+ return "endbe\t%0, <endmode>";
+}
+ [(set_attr "type" "end")])
+
;;;; Conditional branches
;; The eBPF jump instructions use 64-bit arithmetic when evaluating
diff --git a/gcc/testsuite/gcc.target/bpf/bswap-1.c b/gcc/testsuite/gcc.target/bpf/bswap-1.c
new file mode 100644
index 00000000000..4748143ada5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/bpf/bswap-1.c
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+/* { dg-options "-mlittle-endian" } */
+
+unsigned short in16 = 0x1234U;
+unsigned int in32 = 0x12345678U;
+unsigned long in64 = 0x123456789abcdef0ULL;
+
+unsigned short out16 = 0;
+unsigned int out32 = 0;
+unsigned long out64 = 0;
+
+int foo (void)
+{
+ out16 = __builtin_bswap16 (in16);
+ out32 = __builtin_bswap32 (in32);
+ out64 = __builtin_bswap64 (in64);
+
+ return 0;
+}
+
+/* { dg-final { scan-assembler "endbe\t%r., 16" } } */
+/* { dg-final { scan-assembler "endbe\t%r., 32" } } */
+/* { dg-final { scan-assembler "endbe\t%r., 64" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-12-08 18:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-08 18:50 [gcc r13-4566] bpf: add define_insn for bswap David Faust
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).