ISA_V1,
ISA_V2,
ISA_V3,
+ ISA_V4
};
enum bpf_asm_dialect
if (bpf_has_jmp32 == -1)
bpf_has_jmp32 = (bpf_isa >= ISA_V3);
+ if (bpf_has_bswap == -1)
+ bpf_has_bswap = (bpf_isa >= ISA_V4);
+
/* Disable -fstack-protector as it is not supported in BPF. */
if (flag_stack_protect)
{
;; Instruction classes.
;; alu 64-bit arithmetic.
;; alu32 32-bit arithmetic.
-;; end endianness conversion instructions.
+;; end endianness conversion or byte swap instructions.
;; ld load instructions.
;; lddx load 64-bit immediate instruction.
;; ldx generic load instructions.
"{rsh<msuffix>\t%0,%2|%w0 >>= %w2}"
[(set_attr "type" "<mtype>")])
-;;;; Endianness conversion
+;;;; Byte swapping
(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")))]
+ (bswap:BSM (match_operand:BSM 1 "register_operand" " 0")))]
""
{
- if (TARGET_BIG_ENDIAN)
- return "{endle\t%0, <endmode>|%0 = le<endmode> %0}";
+ if (bpf_has_bswap)
+ return "{bswap\t%0, <endmode>|%0 = bswap<endmode> %1}";
else
- return "{endbe\t%0, <endmode>|%0 = be<endmode> %0}";
+ {
+ if (TARGET_BIG_ENDIAN)
+ return "{endle\t%0, <endmode>|%0 = le<endmode> %1}";
+ else
+ return "{endbe\t%0, <endmode>|%0 = be<endmode> %1}";
+ }
}
[(set_attr "type" "end")])
Target Var(bpf_has_jmp32) Init(-1)
Enable 32-bit jump instructions.
+mbswap
+Target Var(bpf_has_bswap) Init(-1)
+Enable byte swap instructions.
+
mcpu=
-Target RejectNegative Joined Var(bpf_isa) Enum(bpf_isa) Init(ISA_V3)
+Target RejectNegative Joined Var(bpf_isa) Enum(bpf_isa) Init(ISA_V4)
Enum
Name(bpf_isa) Type(enum bpf_isa_version)
EnumValue
Enum(bpf_isa) String(v3) Value(ISA_V3)
+EnumValue
+Enum(bpf_isa) String(v4) Value(ISA_V4)
+
masm=
Target RejectNegative Joined Var(asm_dialect) Enum(asm_dialect) Init(ASM_NORMAL)
Use given assembler dialect.
@item -malu32
Enable 32-bit ALU instructions. Enabled for CPU v3 and above.
+@opindex mbswap
+@item -mbswap
+Enable byte swap instructions. Enabled for CPU v4 and above.
+
@opindex mcpu
@item -mcpu=@var{version}
This specifies which version of the eBPF ISA to target. Newer versions
-may not be supported by all kernels. The default is @samp{v3}.
+may not be supported by all kernels. The default is @samp{v4}.
Supported values for @var{version} are:
@item 32-bit ALU operations, as in @option{-malu32}
@end itemize
+@item v4
+All features of v3, plus:
+@itemize @minus
+@item Byte swap instructions, as in @option{-mbswap}
+@end itemize
@end table
@opindex mco-re
/* { dg-do compile } */
-/* { dg-options "-mlittle-endian" } */
+/* { dg-options "-mlittle-endian -mcpu=v3" } */
unsigned short in16 = 0x1234U;
unsigned int in32 = 0x12345678U;
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-mlittle-endian -mcpu=v4" } */
+
+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 "bswap\t%r., 16" } } */
+/* { dg-final { scan-assembler "bswap\t%r., 32" } } */
+/* { dg-final { scan-assembler "bswap\t%r., 64" } } */