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:
@@ -480,6 +480,7 @@ pub(crate) fn define(
|
||||
let sqrt = shared.by_name("sqrt");
|
||||
let sshr = shared.by_name("sshr");
|
||||
let sshr_imm = shared.by_name("sshr_imm");
|
||||
let ssub_sat = shared.by_name("ssub_sat");
|
||||
let stack_addr = shared.by_name("stack_addr");
|
||||
let store = shared.by_name("store");
|
||||
let store_complex = shared.by_name("store_complex");
|
||||
@@ -501,6 +502,7 @@ pub(crate) fn define(
|
||||
let uload8_complex = shared.by_name("uload8_complex");
|
||||
let ushr = shared.by_name("ushr");
|
||||
let ushr_imm = shared.by_name("ushr_imm");
|
||||
let usub_sat = shared.by_name("usub_sat");
|
||||
let vconst = shared.by_name("vconst");
|
||||
let x86_bsf = x86.by_name("x86_bsf");
|
||||
let x86_bsr = x86.by_name("x86_bsr");
|
||||
@@ -1965,6 +1967,24 @@ pub(crate) fn define(
|
||||
e.enc_32_64(isub, rec_fa.opcodes(*opcodes));
|
||||
}
|
||||
|
||||
// SIMD integer saturating subtraction
|
||||
e.enc_32_64(
|
||||
ssub_sat.bind_vector_from_lane(I8, sse_vector_size),
|
||||
rec_fa.opcodes(&PSUBSB),
|
||||
);
|
||||
e.enc_32_64(
|
||||
ssub_sat.bind_vector_from_lane(I16, sse_vector_size),
|
||||
rec_fa.opcodes(&PSUBSW),
|
||||
);
|
||||
e.enc_32_64(
|
||||
usub_sat.bind_vector_from_lane(I8, sse_vector_size),
|
||||
rec_fa.opcodes(&PSUBUSB),
|
||||
);
|
||||
e.enc_32_64(
|
||||
usub_sat.bind_vector_from_lane(I16, sse_vector_size),
|
||||
rec_fa.opcodes(&PSUBUSW),
|
||||
);
|
||||
|
||||
// SIMD integer multiplication: the x86 ISA does not have instructions for multiplying I8x16
|
||||
// and I64x2 and these are (at the time of writing) not necessary for WASM SIMD.
|
||||
for (ty, opcodes, isap) in &[
|
||||
|
||||
@@ -326,6 +326,22 @@ pub static PSUBD: [u8; 3] = [0x66, 0x0f, 0xfa];
|
||||
/// Subtract packed quadword integers in xmm2/m128 from xmm1 (SSE2).
|
||||
pub static PSUBQ: [u8; 3] = [0x66, 0x0f, 0xfb];
|
||||
|
||||
/// Subtract packed signed byte integers in xmm2/m128 from packed signed byte integers in xmm1
|
||||
/// and saturate results (SSE2).
|
||||
pub static PSUBSB: [u8; 3] = [0x66, 0x0f, 0xe8];
|
||||
|
||||
/// Subtract packed signed word integers in xmm2/m128 from packed signed word integers in xmm1
|
||||
/// and saturate results (SSE2).
|
||||
pub static PSUBSW: [u8; 3] = [0x66, 0x0f, 0xe9];
|
||||
|
||||
/// Subtract packed unsigned byte integers in xmm2/m128 from packed unsigned byte integers in xmm1
|
||||
/// and saturate results (SSE2).
|
||||
pub static PSUBUSB: [u8; 3] = [0x66, 0x0f, 0xd8];
|
||||
|
||||
/// Subtract packed unsigned word integers in xmm2/m128 from packed unsigned word integers in xmm1
|
||||
/// and saturate results (SSE2).
|
||||
pub static PSUBUSW: [u8; 3] = [0x66, 0x0f, 0xd9];
|
||||
|
||||
/// Push r{16,32,64}.
|
||||
pub static PUSH_REG: [u8; 1] = [0x50];
|
||||
|
||||
|
||||
@@ -1736,6 +1736,36 @@ pub(crate) fn define(
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
Inst::new(
|
||||
"usub_sat",
|
||||
r#"
|
||||
Subtract with unsigned saturation.
|
||||
|
||||
This is similar to `isub` but the operands are interpreted as unsigned integers and their
|
||||
difference, instead of wrapping, will be saturated to the lowest unsigned integer for
|
||||
the controlling type (e.g. `0x00` for i8).
|
||||
"#,
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
Inst::new(
|
||||
"ssub_sat",
|
||||
r#"
|
||||
Subtract with signed saturation.
|
||||
|
||||
This is similar to `isub` but the operands are interpreted as signed integers and their
|
||||
difference, instead of wrapping, will be saturated to the lowest or highest
|
||||
signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8).
|
||||
"#,
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
ig.push(
|
||||
Inst::new(
|
||||
"ineg",
|
||||
|
||||
Reference in New Issue
Block a user