"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
--- /dev/null
+/* { 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" } } */