Adds Bswap to the Cranelift IR. Implements the Bswap instruction in the x64 and aarch64 codegen backends. Cranelift users can now: ``` builder.ins().bswap(value) ``` to get a native byteswap instruction. * x64: implements the 32- and 64-bit bswap instruction, following the pattern set by similar unary instrutions (Neg and Not) - it only operates on a dst register, but is parameterized with both a src and dst which are expected to be the same register. As x64 bswap instruction is only for 32- or 64-bit registers, the 16-bit swap is implemented as a rotate left by 8. Updated x64 RexFlags type to support emitting for single-operand instructions like bswap * aarch64: Bswap gets emitted as aarch64 rev16, rev32, or rev64 instruction as appropriate. * s390x: Bswap was already supported in backend, just had to add a bit of plumbing * For completeness, added bswap to the interpreter as well. * added filetests and runtests for each ISA * added bswap to fuzzgen, thanks to afonso360 for the code there * 128-bit swaps are not yet implemented, that can be done later
This commit is contained in:
@@ -1023,6 +1023,10 @@
|
||||
(RBit)
|
||||
(Clz)
|
||||
(Cls)
|
||||
;; Byte reverse
|
||||
(Rev16)
|
||||
(Rev32)
|
||||
(Rev64)
|
||||
))
|
||||
|
||||
(type MemLabel extern (enum))
|
||||
@@ -2579,6 +2583,17 @@
|
||||
(decl a64_cls (Type Reg) Reg)
|
||||
(rule (a64_cls ty x) (bit_rr (BitOp.Cls) ty x))
|
||||
|
||||
;; Helpers for generating `rev` instructions
|
||||
|
||||
(decl a64_rev16 (Type Reg) Reg)
|
||||
(rule (a64_rev16 ty x) (bit_rr (BitOp.Rev16) ty x))
|
||||
|
||||
(decl a64_rev32 (Type Reg) Reg)
|
||||
(rule (a64_rev32 ty x) (bit_rr (BitOp.Rev32) ty x))
|
||||
|
||||
(decl a64_rev64 (Type Reg) Reg)
|
||||
(rule (a64_rev64 ty x) (bit_rr (BitOp.Rev64) ty x))
|
||||
|
||||
;; Helpers for generating `eon` instructions.
|
||||
|
||||
(decl eon (Type Reg Reg) Reg)
|
||||
|
||||
Reference in New Issue
Block a user