Add x86 SIMD average rounding
This commit is contained in:
@@ -1560,6 +1560,7 @@ fn define_simd(
|
||||
let formats = &shared_defs.formats;
|
||||
|
||||
// Shorthands for instructions.
|
||||
let avg_round = shared.by_name("avg_round");
|
||||
let bitcast = shared.by_name("bitcast");
|
||||
let bor = shared.by_name("bor");
|
||||
let bxor = shared.by_name("bxor");
|
||||
@@ -1926,6 +1927,12 @@ fn define_simd(
|
||||
e.enc_32_64_maybe_isap(imul, rec_fa.opcodes(opcodes), *isap);
|
||||
}
|
||||
|
||||
// SIMD integer average with rounding.
|
||||
for (ty, opcodes) in &[(I8, &PAVGB[..]), (I16, &PAVGW[..])] {
|
||||
let avgr = avg_round.bind(vector(*ty, sse_vector_size));
|
||||
e.enc_32_64(avgr, rec_fa.opcodes(opcodes));
|
||||
}
|
||||
|
||||
// SIMD logical operations
|
||||
let band = shared.by_name("band");
|
||||
let band_not = shared.by_name("band_not");
|
||||
|
||||
@@ -317,6 +317,12 @@ pub static PAND: [u8; 3] = [0x66, 0x0f, 0xdb];
|
||||
/// Bitwise AND NOT of xmm2/m128 and xmm1 (SSE2).
|
||||
pub static PANDN: [u8; 3] = [0x66, 0x0f, 0xdf];
|
||||
|
||||
/// Average packed unsigned byte integers from xmm2/m128 and xmm1 with rounding (SSE2).
|
||||
pub static PAVGB: [u8; 3] = [0x66, 0x0f, 0xE0];
|
||||
|
||||
/// Average packed unsigned word integers from xmm2/m128 and xmm1 with rounding (SSE2).
|
||||
pub static PAVGW: [u8; 3] = [0x66, 0x0f, 0xE3];
|
||||
|
||||
/// Compare packed data for equal (SSE2).
|
||||
pub static PCMPEQB: [u8; 3] = [0x66, 0x0f, 0x74];
|
||||
|
||||
|
||||
@@ -548,6 +548,32 @@ fn define_simd_arithmetic(
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
|
||||
let IxN = &TypeVar::new(
|
||||
"IxN",
|
||||
"A SIMD vector type containing integers",
|
||||
TypeSetBuilder::new()
|
||||
.ints(Interval::All)
|
||||
.simd_lanes(Interval::All)
|
||||
.includes_scalars(false)
|
||||
.build(),
|
||||
);
|
||||
|
||||
let a = &Operand::new("a", IxN);
|
||||
let x = &Operand::new("x", IxN);
|
||||
let y = &Operand::new("y", IxN);
|
||||
|
||||
ig.push(
|
||||
Inst::new(
|
||||
"avg_round",
|
||||
r#"
|
||||
Unsigned average with rounding: `a := (x + y + 1) // 2`
|
||||
"#,
|
||||
&formats.binary,
|
||||
)
|
||||
.operands_in(vec![x, y])
|
||||
.operands_out(vec![a]),
|
||||
);
|
||||
}
|
||||
|
||||
#[allow(clippy::many_single_char_names)]
|
||||
@@ -627,7 +653,6 @@ pub(crate) fn define(
|
||||
.includes_scalars(false)
|
||||
.build(),
|
||||
);
|
||||
|
||||
let Any = &TypeVar::new(
|
||||
"Any",
|
||||
"Any integer, float, boolean, or reference scalar or vector type",
|
||||
|
||||
Reference in New Issue
Block a user