Files
wasmtime/cranelift/filetests/filetests/isa/aarch64/bswap.clif
11evan 4ca9e82bd1 cranelift: Add Bswap instruction (#1092) (#5147)
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
2022-10-31 19:30:00 +00:00

35 lines
411 B
Plaintext

test compile precise-output
set unwind_info=false
target aarch64
function %f0(i64) -> i64 {
block0(v0: i64):
v1 = bswap v0
return v1
}
; block0:
; rev64 x0, x0
; ret
function %f1(i32) -> i32 {
block0(v0: i32):
v1 = bswap v0
return v1
}
; block0:
; rev32 w0, w0
; ret
function %f2(i16) -> i16 {
block0(v0: i16):
v1 = bswap v0
return v1
}
; block0:
; rev16 w0, w0
; ret