s390x: Add support for all remaining atomic operations (#3746)
This adds support for all atomic operations that were unimplemented so far in the s390x back end: - atomic_rmw operations xchg, nand, smin, smax, umin, umax - $I8 and $I16 versions of atomic_rmw and atomic_cas - little endian versions of atomic_rmw and atomic_cas All of these have to be implemented by a compare-and-swap loop; and for the $I8 and $I16 versions the actual atomic instruction needs to operate on the surrounding aligned 32-bit word. Since we cannot emit new control flow during ISLE instruction selection, these compare-and-swap loops are emitted as a single meta-instruction to be expanded at emit time. However, since there is a large number of different versions of the loop required to implement all the above operations, I've implemented a facility to allow specifying the loop bodies from within ISLE after all, by creating a vector of MInst structures that will be emitted as part of the meta-instruction. There are still restrictions, in particular instructions that are part of the loop body may not modify any virtual register. But even so, this approach looks preferable to doing everything in emit.rs. A few instructions needed in those compare-and-swap loop bodies were added as well, in particular the RxSBG family of instructions as well as the LOAD REVERSED in-register byte-swap instructions. This patch also adds filetest runtests to verify the semantics of all operations, in particular the subword and little-endian variants (those are currently only executed on s390x).
This commit is contained in:
43
cranelift/filetests/filetests/runtests/atomic-cas.clif
Normal file
43
cranelift/filetests/filetests/runtests/atomic-cas.clif
Normal file
@@ -0,0 +1,43 @@
|
||||
test run
|
||||
target aarch64
|
||||
target aarch64 has_lse
|
||||
target x86_64
|
||||
target s390x
|
||||
|
||||
; We can't test that these instructions are right regarding atomicity, but we can
|
||||
; test if they perform their operation correctly
|
||||
|
||||
function %atomic_cas_i64(i64, i64, i64) -> i64 {
|
||||
ss0 = explicit_slot 8
|
||||
|
||||
block0(v0: i64, v1: i64, v2: i64):
|
||||
stack_store.i64 v0, ss0
|
||||
|
||||
v3 = stack_addr.i64 ss0
|
||||
v4 = atomic_cas.i64 v3, v1, v2
|
||||
|
||||
v5 = stack_load.i64 ss0
|
||||
return v5
|
||||
}
|
||||
; run: %atomic_cas_i64(0, 0, 2) == 2
|
||||
; run: %atomic_cas_i64(1, 0, 2) == 1
|
||||
; run: %atomic_cas_i64(0, 1, 2) == 0
|
||||
; run: %atomic_cas_i64(0, 0, 0xC0FFEEEE_DECAFFFF) == 0xC0FFEEEE_DECAFFFF
|
||||
|
||||
function %atomic_cas_i32(i32, i32, i32) -> i32 {
|
||||
ss0 = explicit_slot 4
|
||||
|
||||
block0(v0: i32, v1: i32, v2: i32):
|
||||
stack_store.i32 v0, ss0
|
||||
|
||||
v3 = stack_addr.i32 ss0
|
||||
v4 = atomic_cas.i32 v3, v1, v2
|
||||
|
||||
v5 = stack_load.i32 ss0
|
||||
return v5
|
||||
}
|
||||
; run: %atomic_cas_i32(0, 0, 2) == 2
|
||||
; run: %atomic_cas_i32(1, 0, 2) == 1
|
||||
; run: %atomic_cas_i32(0, 1, 2) == 0
|
||||
; run: %atomic_cas_i32(0, 0, 0xC0FFEEEE) == 0xC0FFEEEE
|
||||
|
||||
Reference in New Issue
Block a user