Add saturating subtraction with a SIMD encoding

This includes the new instructions `ssub_sat` and `usub_sat` and only encodes the i8x16 and i16x8 types; these are what is needed for implementing the SIMD spec (see https://github.com/WebAssembly/simd/blob/master/proposals/simd/SIMD.md#saturating-integer-subtraction).
This commit is contained in:
Andrew Brown
2019-09-18 16:28:13 -07:00
parent 21144068d4
commit 90c49a2f7c
5 changed files with 102 additions and 4 deletions

View File

@@ -190,3 +190,31 @@ ebb0:
return v4
}
; run
function %sub_sat_i8x16() -> b1 {
ebb0:
[-, %xmm2] v0 = vconst.i8x16 [128 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0] ; 120 == 0x80 == -128
[-, %xmm3] v1 = vconst.i8x16 [1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1]
[-, %xmm2] v2 = ssub_sat v0, v1 ; bin: 66 0f e8 d3
v3 = extractlane v2, 0
v4 = icmp_imm eq v3, 0x80 ; still -128, TODO it's unclear why I can't use -128 here
; now re-use 0x80 as an unsigned 128
[-, %xmm2] v5 = usub_sat v0, v2 ; bin: 66 0f d8 d2
v6 = extractlane v5, 0
v7 = icmp_imm eq v6, 0
v8 = band v4, v7
return v8
}
; run
function %sub_sat_i16x8() {
ebb0:
[-, %xmm3] v0 = vconst.i16x8 [0 0 0 0 0 0 0 0]
[-, %xmm5] v1 = vconst.i16x8 [1 1 1 1 1 1 1 1]
[-, %xmm3] v2 = ssub_sat v0, v1 ; bin: 66 0f e9 dd
[-, %xmm3] v3 = usub_sat v0, v1 ; bin: 66 0f d9 dd
return
}