[s390x, abi_impl] Add i128 support (#4598)

This adds full i128 support to the s390x target, including new filetests
and enabling the existing i128 runtest on s390x.

The ABI requires that i128 is passed and returned via implicit pointer,
but the front end still generates direct i128 types in call.  This means
we have to implement ABI support to implicitly convert i128 types to
pointers when passing arguments.

To do so, we add a new variant ABIArg::ImplicitArg.  This acts like
StructArg, except that the value type is the actual target type,
not a pointer type.  The required conversions have to be inserted
in the prologue and at function call sites.

Note that when dereferencing the implicit pointer in the prologue,
we may require a temp register: the pointer may be passed on the
stack so it needs to be loaded first, but the value register may
be in the wrong class for pointer values.  In this case, we use
the "stack limit" register, which should be available at this
point in the prologue.

For return values, we use a mechanism similar to the one used for
supporting multiple return values in the Wasmtime ABI.  The only
difference is that the hidden pointer to the return buffer must
be the *first*, not last, argument in this case.

(This implements the second half of issue #4565.)
This commit is contained in:
Ulrich Weigand
2022-08-04 22:41:26 +02:00
committed by GitHub
parent dc8362ceec
commit b17b1eb25d
46 changed files with 2424 additions and 166 deletions

View File

@@ -2,6 +2,7 @@ test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %add_i128(i128, i128) -> i128 {

View File

@@ -1,5 +1,6 @@
test run
target aarch64
target s390x
function %band_not_i128(i128, i128) -> i128 {
block0(v0: i128, v1: i128):

View File

@@ -1,6 +1,7 @@
test interpret
test run
target aarch64
target s390x
function %bextend_b1_b128(b1) -> b128 {
block0(v0: b1):

View File

@@ -2,6 +2,7 @@ test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %bint_b1_i128_true() -> i128 {

View File

@@ -1,6 +1,7 @@
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %ctz_i128(i128) -> i128 {

View File

@@ -1,6 +1,7 @@
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %bnot_i128(i128) -> i128 {

View File

@@ -1,6 +1,7 @@
test interpret
test run
target aarch64
target s390x
function %bmask_b128_i128(b128) -> i128 {
block0(v0: b128):

View File

@@ -1,5 +1,6 @@
test run
target aarch64
target s390x
function %bor_not_i128(i128, i128) -> i128 {
block0(v0: i128, v1: i128):

View File

@@ -1,6 +1,7 @@
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64

View File

@@ -0,0 +1,61 @@
test run
target aarch64
; TODO: Merge this with the main i128-bricmp file when s390x supports overflows.
; See: https://github.com/bytecodealliance/wasmtime/issues/3060
function %i128_bricmp_of(i128, i128) -> b1 {
block0(v0: i128,v1: i128):
br_icmp.i128 of v0, v1, block2
jump block1
block1:
v2 = bconst.b1 false
return v2
block2:
v3 = bconst.b1 true
return v3
}
; run: %i128_bricmp_of(0, 0) == false
; run: %i128_bricmp_of(0, 1) == false
; run: %i128_bricmp_of(0, -1) == false
; run: %i128_bricmp_of(-1, -1) == false
; run: %i128_bricmp_of(0x80000000_00000000_00000000_00000000, 0) == false
; run: %i128_bricmp_of(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %i128_bricmp_of(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %i128_bricmp_of(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == false
; run: %i128_bricmp_of(0x80000000_00000000_00000000_00000000, 1) == true
; run: %i128_bricmp_of(1, 0x80000000_00000000_00000000_00000000) == true
; run: %i128_bricmp_of(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == true
; run: %i128_bricmp_of(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %i128_bricmp_of(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %i128_bricmp_of(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == false
function %i128_bricmp_nof(i128, i128) -> b1 {
block0(v0: i128,v1: i128):
br_icmp.i128 nof v0, v1, block2
jump block1
block1:
v2 = bconst.b1 false
return v2
block2:
v3 = bconst.b1 true
return v3
}
; run: %i128_bricmp_nof(0, 0) == true
; run: %i128_bricmp_nof(0, 1) == true
; run: %i128_bricmp_nof(0, -1) == true
; run: %i128_bricmp_nof(-1, -1) == true
; run: %i128_bricmp_nof(0x80000000_00000000_00000000_00000000, 0) == true
; run: %i128_bricmp_nof(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == true
; run: %i128_bricmp_nof(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %i128_bricmp_nof(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == true
; run: %i128_bricmp_nof(0x80000000_00000000_00000000_00000000, 1) == false
; run: %i128_bricmp_nof(1, 0x80000000_00000000_00000000_00000000) == false
; run: %i128_bricmp_nof(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == false
; run: %i128_bricmp_nof(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %i128_bricmp_nof(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == true
; run: %i128_bricmp_nof(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == true

View File

@@ -1,5 +1,6 @@
test run
target aarch64
target s390x
function %i128_bricmp_eq(i128, i128) -> b1 {
block0(v0: i128, v1: i128):
@@ -245,45 +246,3 @@ block2:
v3 = bconst.b1 true
return v3
}
; run: %i128_bricmp_of(0, 0) == false
; run: %i128_bricmp_of(0, 1) == false
; run: %i128_bricmp_of(0, -1) == false
; run: %i128_bricmp_of(-1, -1) == false
; run: %i128_bricmp_of(0x80000000_00000000_00000000_00000000, 0) == false
; run: %i128_bricmp_of(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == false
; run: %i128_bricmp_of(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %i128_bricmp_of(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == false
; run: %i128_bricmp_of(0x80000000_00000000_00000000_00000000, 1) == true
; run: %i128_bricmp_of(1, 0x80000000_00000000_00000000_00000000) == true
; run: %i128_bricmp_of(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == true
; run: %i128_bricmp_of(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %i128_bricmp_of(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == false
; run: %i128_bricmp_of(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == false
function %i128_bricmp_nof(i128, i128) -> b1 {
block0(v0: i128,v1: i128):
br_icmp.i128 nof v0, v1, block2
jump block1
block1:
v2 = bconst.b1 false
return v2
block2:
v3 = bconst.b1 true
return v3
}
; run: %i128_bricmp_nof(0, 0) == true
; run: %i128_bricmp_nof(0, 1) == true
; run: %i128_bricmp_nof(0, -1) == true
; run: %i128_bricmp_nof(-1, -1) == true
; run: %i128_bricmp_nof(0x80000000_00000000_00000000_00000000, 0) == true
; run: %i128_bricmp_nof(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0) == true
; run: %i128_bricmp_nof(1, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == true
; run: %i128_bricmp_nof(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 1) == true
; run: %i128_bricmp_nof(0x80000000_00000000_00000000_00000000, 1) == false
; run: %i128_bricmp_nof(1, 0x80000000_00000000_00000000_00000000) == false
; run: %i128_bricmp_nof(0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x80000000_00000000_00000000_00000000) == false
; run: %i128_bricmp_nof(0x80000000_00000000_00000000_00000000, 0x7FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF) == false
; run: %i128_bricmp_nof(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000000) == true
; run: %i128_bricmp_nof(0x4FFFFFFF_FFFFFFFF_FFFFFFFF_FFFFFFFF, 0x30000000_00000000_00000000_00000001) == true

View File

@@ -1,5 +1,6 @@
test run
target aarch64
target s390x
function %bxor_not_i128(i128, i128) -> i128 {
block0(v0: i128, v1: i128):

View File

@@ -1,5 +1,6 @@
test run
target aarch64
target s390x
function %cls_i128(i128) -> i128 {
block0(v0: i128):

View File

@@ -1,6 +1,7 @@
test interpret
test run
target aarch64
target s390x
target x86_64
function %iconcat_isplit(i64, i64) -> i64, i64 {

View File

@@ -2,7 +2,7 @@ test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
; target s390x TODO: Not yet implemented on s390x
target s390x
target x86_64
function %i128_const_0() -> i128 {

View File

@@ -2,6 +2,7 @@ test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %i128_uextend_i64(i64) -> i128 {

View File

@@ -2,6 +2,7 @@ test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %icmp_eq_i128(i128, i128) -> b1 {

View File

@@ -2,6 +2,7 @@ test interpret
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %ireduce_128_64(i128) -> i64 {

View File

@@ -2,6 +2,7 @@ test run
set enable_llvm_abi_extensions=true
target x86_64
target aarch64
target s390x
function %i128_stack_store_load(i128) -> b1 {
ss0 = explicit_slot 16

View File

@@ -1,6 +1,7 @@
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %rotl(i128, i8) -> i128 {

View File

@@ -1,6 +1,7 @@
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64
function %i128_select(b1, i128, i128) -> i128 {

View File

@@ -1,5 +1,6 @@
test run
target aarch64
target s390x
; TODO: Merge this with the main i128-shifts file when x86_64 passes these.

View File

@@ -1,6 +1,7 @@
test run
set enable_llvm_abi_extensions=true
target aarch64
target s390x
target x86_64