Vector bitcast support (AArch64 & Interpreter) (#4820)
* Vector bitcast support (AArch64 & Interpreter) Implemented support for `bitcast` on vector values for AArch64 and the interpreter. Also corrected the verifier to ensure that the size, in bits, of the input and output types match for a `bitcast`, per the docs. Copyright (c) 2022 Arm Limited * `I128` same-type bitcast support Copyright (c) 2022 Arm Limited * Directly return input for 64-bit GPR<=>GPR bitcast Copyright (c) 2022 Arm Limited
This commit is contained in:
26
cranelift/filetests/filetests/runtests/bitcast-ref64.clif
Normal file
26
cranelift/filetests/filetests/runtests/bitcast-ref64.clif
Normal file
@@ -0,0 +1,26 @@
|
||||
test run
|
||||
target aarch64
|
||||
; the interpreter, x86_64, and s390x do not support bitcasting to/from
|
||||
; references
|
||||
|
||||
function %bitcast_ir64(i64) -> b1 {
|
||||
block0(v0: i64):
|
||||
v1 = bitcast.r64 v0
|
||||
v2 = is_null v1
|
||||
return v2
|
||||
}
|
||||
; run: %bitcast_ir64(0) == true
|
||||
; run: %bitcast_ir64(18446744073709551615) == false
|
||||
; run: %bitcast_ir64(-1) == false
|
||||
; run: %bitcast_ir64(127) == false
|
||||
|
||||
function %bitcast_ri64(i64) -> i64 {
|
||||
block0(v0: i64):
|
||||
v1 = bitcast.r64 v0
|
||||
v2 = bitcast.i64 v1
|
||||
return v2
|
||||
}
|
||||
; run: %bitcast_ri64(0) == 0
|
||||
; run: %bitcast_ri64(18446744073709551615) == 18446744073709551615
|
||||
; run: %bitcast_ri64(-1) == -1
|
||||
; run: %bitcast_ri64(127) == 127
|
||||
@@ -0,0 +1,69 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
; x86_64 and s390x do not support bitcasting to the same type as the input.
|
||||
|
||||
function %bitcast_i8(i8) -> i8 {
|
||||
block0(v0: i8):
|
||||
v1 = bitcast.i8 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_i8(0) == 0
|
||||
; run: %bitcast_i8(42) == 42
|
||||
; run: %bitcast_i8(255) == 255
|
||||
|
||||
function %bitcast_i16(i16) -> i16 {
|
||||
block0(v0: i16):
|
||||
v1 = bitcast.i16 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_i16(0) == 0
|
||||
; run: %bitcast_i16(42) == 42
|
||||
; run: %bitcast_i16(65535) == 65535
|
||||
|
||||
function %bitcast_i32(i32) -> i32 {
|
||||
block0(v0: i32):
|
||||
v1 = bitcast.i32 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_i32(0) == 0
|
||||
; run: %bitcast_i32(42) == 42
|
||||
; run: %bitcast_i32(4294967295) == 4294967295
|
||||
|
||||
function %bitcast_i64(i64) -> i64 {
|
||||
block0(v0: i64):
|
||||
v1 = bitcast.i64 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_i64(0) == 0
|
||||
; run: %bitcast_i64(42) == 42
|
||||
; run: %bitcast_i64(18446744073709551615) == 18446744073709551615
|
||||
|
||||
function %bitcast_i128(i128) -> i128 {
|
||||
block0(v0: i128):
|
||||
v1 = bitcast.i128 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_i128(0) == 0
|
||||
; run: %bitcast_i128(42) == 42
|
||||
; run: %bitcast_i128(200000000000000000000) == 200000000000000000000
|
||||
|
||||
function %bitcast_f32(f32) -> f32 {
|
||||
block0(v0: f32):
|
||||
v1 = bitcast.f32 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_f32(0x0.0) == 0x0.0
|
||||
; run: %bitcast_f32(0x1.0) == 0x1.0
|
||||
; run: %bitcast_f32(-0x1.0) == -0x1.0
|
||||
; run: %bitcast_f32(NaN) == NaN
|
||||
|
||||
function %bitcast_f64(f64) -> f64 {
|
||||
block0(v0: f64):
|
||||
v1 = bitcast.f64 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_f64(0x0.0) == 0x0.0
|
||||
; run: %bitcast_f64(0x1.0) == 0x1.0
|
||||
; run: %bitcast_f64(-0x1.0) == -0x1.0
|
||||
; run: %bitcast_f64(NaN) == NaN
|
||||
45
cranelift/filetests/filetests/runtests/bitcast.clif
Normal file
45
cranelift/filetests/filetests/runtests/bitcast.clif
Normal file
@@ -0,0 +1,45 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
target x86_64
|
||||
target s390x
|
||||
|
||||
function %bitcast_if32(i32) -> f32 {
|
||||
block0(v0: i32):
|
||||
v1 = bitcast.f32 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_if32(0) == 0x0.0
|
||||
; run: %bitcast_if32(4294967295) == -NaN:0x3fffff
|
||||
; run: %bitcast_if32(-1) == -NaN:0x3fffff
|
||||
; run: %bitcast_if32(127) == 0x0.0000fep-126
|
||||
|
||||
function %bitcast_fi32(f32) -> i32 {
|
||||
block0(v0: f32):
|
||||
v1 = bitcast.i32 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_fi32(0x0.0) == 0
|
||||
; run: %bitcast_fi32(-NaN:0x3fffff) == 4294967295
|
||||
; run: %bitcast_fi32(-NaN:0x3fffff) == -1
|
||||
; run: %bitcast_fi32(0x0.0000fep-126) == 127
|
||||
|
||||
function %bitcast_if64(i64) -> f64 {
|
||||
block0(v0: i64):
|
||||
v1 = bitcast.f64 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_if64(0) == 0x0.0
|
||||
; run: %bitcast_if64(18446744073709551615) == -NaN:0x7ffffffffffff
|
||||
; run: %bitcast_if64(-1) == -NaN:0x7ffffffffffff
|
||||
; run: %bitcast_if64(127) == 0x0.000000000007fp-1022
|
||||
|
||||
function %bitcast_fi64(f64) -> i64 {
|
||||
block0(v0: f64):
|
||||
v1 = bitcast.i64 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_fi64(0x0.0) == 0
|
||||
; run: %bitcast_fi64(-NaN:0x7ffffffffffff) == 18446744073709551615
|
||||
; run: %bitcast_fi64(-NaN:0x7ffffffffffff) == -1
|
||||
; run: %bitcast_fi64(0x0.000000000007fp-1022) == 127
|
||||
121
cranelift/filetests/filetests/runtests/copy.clif
Normal file
121
cranelift/filetests/filetests/runtests/copy.clif
Normal file
@@ -0,0 +1,121 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
target s390x
|
||||
; x86_64 regards this as an unused opcode.
|
||||
|
||||
function %copy_i8(i8) -> i8 {
|
||||
block0(v0: i8):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i8(0) == 0
|
||||
; run: %copy_i8(255) == 255
|
||||
; run: %copy_i8(-1) == -1
|
||||
; run: %copy_i8(127) == 127
|
||||
|
||||
function %copy_i16(i16) -> i16 {
|
||||
block0(v0: i16):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i16(0) == 0
|
||||
; run: %copy_i16(65535) == 65535
|
||||
; run: %copy_i16(-1) == -1
|
||||
; run: %copy_i16(127) == 127
|
||||
|
||||
function %copy_i32(i32) -> i32 {
|
||||
block0(v0: i32):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i32(0) == 0
|
||||
; run: %copy_i32(4294967295) == 4294967295
|
||||
; run: %copy_i32(-1) == -1
|
||||
; run: %copy_i32(127) == 127
|
||||
|
||||
function %copy_i64(i64) -> i64 {
|
||||
block0(v0: i64):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i64(0) == 0
|
||||
; run: %copy_i64(18446744073709551615) == 18446744073709551615
|
||||
; run: %copy_i64(-1) == -1
|
||||
; run: %copy_i64(127) == 127
|
||||
|
||||
function %copy_b1(b1) -> b1 {
|
||||
block0(v0: b1):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_b1(false) == false
|
||||
; run: %copy_b1(true) == true
|
||||
|
||||
function %copy_b8(b8) -> b8 {
|
||||
block0(v0: b8):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_b8(false) == false
|
||||
; run: %copy_b8(true) == true
|
||||
|
||||
function %copy_b16(b16) -> b16 {
|
||||
block0(v0: b16):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_b16(false) == false
|
||||
; run: %copy_b16(true) == true
|
||||
|
||||
function %copy_b32(b32) -> b32 {
|
||||
block0(v0: b32):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_b32(false) == false
|
||||
; run: %copy_b32(true) == true
|
||||
|
||||
function %copy_b64(b64) -> b64 {
|
||||
block0(v0: b64):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_b64(false) == false
|
||||
; run: %copy_b64(true) == true
|
||||
|
||||
function %copy_f32(f32) -> f32 {
|
||||
block0(v0: f32):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_f32(0x1.0) == 0x1.0
|
||||
; run: %copy_f32(0x1.0p10) == 0x1.0p10
|
||||
|
||||
; run: %copy_f32(0x0.0) == 0x0.0
|
||||
; run: %copy_f32(-0x0.0) == -0x0.0
|
||||
; run: %copy_f32(+Inf) == +Inf
|
||||
; run: %copy_f32(-Inf) == -Inf
|
||||
; run: %copy_f32(0x1.000002p-23) == 0x1.000002p-23
|
||||
; run: %copy_f32(0x1.fffffep127) == 0x1.fffffep127
|
||||
; run: %copy_f32(0x1.000000p-126) == 0x1.000000p-126
|
||||
; run: %copy_f32(0x0.800002p-126) == 0x0.800002p-126
|
||||
; run: %copy_f32(-0x0.800000p-126) == -0x0.800000p-126
|
||||
|
||||
function %copy_f64(f64) -> f64 {
|
||||
block0(v0: f64):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_f64(0x2.0) == 0x2.0
|
||||
; run: %copy_f64(0x1.0p11) == 0x1.0p11
|
||||
|
||||
; run: %copy_f64(0x0.0) == 0x0.0
|
||||
; run: %copy_f64(-0x0.0) == -0x0.0
|
||||
; run: %copy_f64(+Inf) == +Inf
|
||||
; run: %copy_f64(-Inf) == -Inf
|
||||
; run: %copy_f64(0x1.0000000000002p-52) == 0x1.0000000000002p-52
|
||||
; run: %copy_f64(0x1.fffffffffffffp1023) == 0x1.fffffffffffffp1023
|
||||
; run: %copy_f64(0x1.0000000000000p-1022) == 0x1.0000000000000p-1022
|
||||
; run: %copy_f64(0x0.8000000000002p-1022) == 0x0.8000000000002p-1022
|
||||
; run: %copy_f64(-0x0.8000000000000p-1022) == -0x0.8000000000000p-1022
|
||||
50
cranelift/filetests/filetests/runtests/simd-bitcast.clif
Normal file
50
cranelift/filetests/filetests/runtests/simd-bitcast.clif
Normal file
@@ -0,0 +1,50 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
; x86_64 and s390x do not support vector bitcasts.
|
||||
|
||||
function %bitcast_if32x2(i32x2) -> f32x2 {
|
||||
block0(v0: i32x2):
|
||||
v1 = bitcast.f32x2 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_if32x2([0 4294967295]) == [0x0.0 -NaN:0x3fffff]
|
||||
; run: %bitcast_if32x2([-1 127]) == [-NaN:0x3fffff 0x0.0000fep-126]
|
||||
|
||||
function %bitcast_fi32x2(f32x2) -> i32x2 {
|
||||
block0(v0: f32x2):
|
||||
v1 = bitcast.i32x2 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_fi32x2([0x0.0 -NaN:0x3fffff]) == [0 4294967295]
|
||||
; run: %bitcast_fi32x2([-NaN:0x3fffff 0x0.0000fep-126]) == [-1 127]
|
||||
|
||||
function %bitcast_if32x4(i32x4) -> f32x4 {
|
||||
block0(v0: i32x4):
|
||||
v1 = bitcast.f32x4 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_if32x4([0 4294967295 -1 127]) == [0x0.0 -NaN:0x3fffff -NaN:0x3fffff 0x0.0000fep-126]
|
||||
|
||||
function %bitcast_fi32x4(f32x4) -> i32x4 {
|
||||
block0(v0: f32x4):
|
||||
v1 = bitcast.i32x4 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_fi32x4([0x0.0 -NaN:0x3fffff -NaN:0x3fffff 0x0.0000fep-126]) == [0 4294967295 -1 127]
|
||||
|
||||
function %bitcast_if64x2(i64x2) -> f64x2 {
|
||||
block0(v0: i64x2):
|
||||
v1 = bitcast.f64x2 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_if64x2([0 18446744073709551615]) == [0x0.0 -NaN:0x7ffffffffffff]
|
||||
; run: %bitcast_if64x2([-1 127]) == [-NaN:0x7ffffffffffff 0x0.000000000007fp-1022]
|
||||
|
||||
function %bitcast_fi64x2(f64x2) -> i64x2 {
|
||||
block0(v0: f64x2):
|
||||
v1 = bitcast.i64x2 v0
|
||||
return v1
|
||||
}
|
||||
; run: %bitcast_fi64x2([0x0.0 -NaN:0x7ffffffffffff]) == [0 18446744073709551615]
|
||||
; run: %bitcast_fi64x2([-NaN:0x7ffffffffffff 0x0.000000000007fp-1022]) == [-1 127]
|
||||
40
cranelift/filetests/filetests/runtests/simd-copy-64bit.clif
Normal file
40
cranelift/filetests/filetests/runtests/simd-copy-64bit.clif
Normal file
@@ -0,0 +1,40 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
; x86_64 regards this as an unused opcode.
|
||||
; s390x does not support 64-bit vectors.
|
||||
|
||||
function %copy_i8x8(i8x8) -> i8x8 {
|
||||
block0(v0: i8x8):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i8x8([0 0 255 255 -1 -1 127 128]) == [0 0 255 255 -1 -1 127 128]
|
||||
|
||||
function %copy_i16x4(i16x4) -> i16x4 {
|
||||
block0(v0: i16x4):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i16x4([0 65535 -1 127]) == [0 65535 -1 127]
|
||||
|
||||
function %copy_i32x2(i32x2) -> i32x2 {
|
||||
block0(v0: i32x2):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i32x2([0 4294967295]) == [0 4294967295]
|
||||
; run: %copy_i32x2([-1 127]) == [-1 127]
|
||||
|
||||
function %copy_f32x2(f32x2) -> f32x2 {
|
||||
block0(v0: f32x2):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_f32x2([0x1.0 0x1.0p10]) == [0x1.0 0x1.0p10]
|
||||
|
||||
; run: %copy_f32x2([0x0.0 -0x0.0]) == [0x0.0 -0x0.0]
|
||||
; run: %copy_f32x2([+Inf -Inf]) == [+Inf -Inf]
|
||||
; run: %copy_f32x2([0x1.000002p-23 0x1.fffffep127]) == [0x1.000002p-23 0x1.fffffep127]
|
||||
; run: %copy_f32x2([0x1.000000p-126 0x0.800002p-126]) == [0x1.000000p-126 0x0.800002p-126]
|
||||
; run: %copy_f32x2([-0x0.800000p-126 -0x0.800000p-126]) == [-0x0.800000p-126 -0x0.800000p-126]
|
||||
57
cranelift/filetests/filetests/runtests/simd-copy.clif
Normal file
57
cranelift/filetests/filetests/runtests/simd-copy.clif
Normal file
@@ -0,0 +1,57 @@
|
||||
test interpret
|
||||
test run
|
||||
target aarch64
|
||||
target s390x
|
||||
; x86_64 regards this as an unused opcode.
|
||||
|
||||
function %copy_i8x16(i8x16) -> i8x16 {
|
||||
block0(v0: i8x16):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i8x16([0 0 255 255 -1 -1 127 128 0 0 255 255 -1 -1 127 128]) == [0 0 255 255 -1 -1 127 128 0 0 255 255 -1 -1 127 128]
|
||||
|
||||
function %copy_i16x8(i16x8) -> i16x8 {
|
||||
block0(v0: i16x8):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i16x8([0 65535 -1 127 0 65535 -1 128]) == [0 65535 -1 127 0 65535 -1 128]
|
||||
|
||||
function %copy_i32x4(i32x4) -> i32x4 {
|
||||
block0(v0: i32x4):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i32x4([0 4294967295 -1 127]) == [0 4294967295 -1 127]
|
||||
|
||||
function %copy_i64x2(i64x2) -> i64x2 {
|
||||
block0(v0: i64x2):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_i64x2([0 18446744073709551615]) == [0 18446744073709551615]
|
||||
; run: %copy_i64x2([-1 127]) == [-1 127]
|
||||
|
||||
function %copy_f32x4(f32x4) -> f32x4 {
|
||||
block0(v0: f32x4):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_f32x4([0x1.0 0x1.0p10 0x0.0 -0x0.0]) == [0x1.0 0x1.0p10 0x0.0 -0x0.0]
|
||||
|
||||
; run: %copy_f32x4([+Inf -Inf 0x1.000002p-23 0x1.fffffep127]) == [+Inf -Inf 0x1.000002p-23 0x1.fffffep127]
|
||||
; run: %copy_f32x4([0x1.000000p-126 0x0.800002p-126 -0x0.800000p-126 -0x0.800000p-126]) == [0x1.000000p-126 0x0.800002p-126 -0x0.800000p-126 -0x0.800000p-126]
|
||||
|
||||
function %copy_f64x2(f64x2) -> f64x2 {
|
||||
block0(v0: f64x2):
|
||||
v1 = copy v0
|
||||
return v1
|
||||
}
|
||||
; run: %copy_f64x2([0x2.0 0x1.0p11]) == [0x2.0 0x1.0p11]
|
||||
|
||||
; run: %copy_f64x2([0x0.0 -0x0.0]) == [0x0.0 -0x0.0]
|
||||
; run: %copy_f64x2([+Inf -Inf]) == [+Inf -Inf]
|
||||
; run: %copy_f64x2([0x1.0000000000002p-52 0x1.fffffffffffffp1023]) == [0x1.0000000000002p-52 0x1.fffffffffffffp1023]
|
||||
; run: %copy_f64x2([0x1.0000000000000p-1022 0x0.8000000000002p-1022]) == [0x1.0000000000000p-1022 0x0.8000000000002p-1022]
|
||||
; run: %copy_f64x2([-0x0.8000000000000p-1022 -0x0.8000000000000p-1022]) == [-0x0.8000000000000p-1022 -0x0.8000000000000p-1022]
|
||||
@@ -1,23 +1,23 @@
|
||||
test verifier
|
||||
|
||||
; bitcast between two types of equal size if ok
|
||||
; bitcast between two types of equal size is ok
|
||||
function %valid_bitcast1(i32) -> f32 { ; Ok
|
||||
block0(v0: i32):
|
||||
v1 = bitcast.f32 v0
|
||||
return v1
|
||||
}
|
||||
|
||||
; bitcast to a type larger than the operand is ok
|
||||
function %valid_bitcast2(i32) -> i64 { ; Ok
|
||||
; bitcast to a type larger than the operand is not ok
|
||||
function %valid_bitcast2(i32) -> i64 {
|
||||
block0(v0: i32):
|
||||
v1 = bitcast.i64 v0
|
||||
v1 = bitcast.i64 v0 ; error: The bitcast argument v0 has a lane type of 32 bits, which doesn't match an expected type of 64 bits
|
||||
return v1
|
||||
}
|
||||
|
||||
; bitcast to a smaller type is not ok
|
||||
function %bad_bitcast(i64) -> i32 {
|
||||
block0(v0: i64):
|
||||
v1 = bitcast.i32 v0 ; error: The bitcast argument v0 doesn't fit in a type of 32 bits
|
||||
v1 = bitcast.i32 v0 ; error: The bitcast argument v0 has a lane type of 64 bits, which doesn't match an expected type of 32 bits
|
||||
return v1
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user