wasm: Add convenience aliases with unsigned names (#1174)

Naming right now for wasm simd intrinsics takes the signededness of the
instruction into account, but some operations are the same regardless of
signededness, such as `i32x4_add`. This commit adds aliases for all of
these operations under unsigned names as well (such as `u32x4_add`)
which are just a `pub use` to rename the item as two names. The goal of
this is to assist in reading code (no need to switch back and forth
between `i` and `u`) as well as writing code (no need to always remember
which operations are the same for signed/unsigned but only available
under the signed names).
This commit is contained in:
Alex Crichton 2021-05-27 10:52:15 -05:00 committed by GitHub
parent b3f06eb658
commit 4d6fa80bb3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 108 additions and 4 deletions

View file

@ -304,6 +304,8 @@ pub unsafe fn i16x8_load_extend_u8x8(m: *const u8) -> v128 {
transmute(simd_cast::<_, simd::u16x8>(*(m as *const simd::u8x8)))
}
pub use i16x8_load_extend_u8x8 as u16x8_load_extend_u8x8;
/// Load four 16-bit integers and sign extend each one to a 32-bit lane
#[inline]
#[cfg_attr(test, assert_instr(v128.load16x4_s))]
@ -322,6 +324,8 @@ pub unsafe fn i32x4_load_extend_u16x4(m: *const u16) -> v128 {
transmute(simd_cast::<_, simd::u32x4>(*(m as *const simd::u16x4)))
}
pub use i32x4_load_extend_u16x4 as u32x4_load_extend_u16x4;
/// Load two 32-bit integers and sign extend each one to a 64-bit lane
#[inline]
#[cfg_attr(test, assert_instr(v128.load32x2_s))]
@ -340,6 +344,8 @@ pub unsafe fn i64x2_load_extend_u32x2(m: *const u32) -> v128 {
transmute(simd_cast::<_, simd::u64x2>(*(m as *const simd::u32x2)))
}
pub use i64x2_load_extend_u32x2 as u64x2_load_extend_u32x2;
/// Load a single element and splat to all lanes of a v128 vector.
#[inline]
#[cfg_attr(test, assert_instr(v128.load8_splat))]
@ -798,6 +804,8 @@ pub unsafe fn i8x16_shuffle<
transmute(shuf)
}
pub use i8x16_shuffle as u8x16_shuffle;
/// Same as [`i8x16_shuffle`], except operates as if the inputs were eight
/// 16-bit integers, only taking 8 indices to shuffle.
///
@ -861,6 +869,8 @@ pub unsafe fn i16x8_shuffle<
transmute(shuf)
}
pub use i16x8_shuffle as u16x8_shuffle;
/// Same as [`i8x16_shuffle`], except operates as if the inputs were four
/// 32-bit integers, only taking 4 indices to shuffle.
///
@ -888,6 +898,8 @@ pub unsafe fn i32x4_shuffle<const I0: usize, const I1: usize, const I2: usize, c
transmute(shuf)
}
pub use i32x4_shuffle as u32x4_shuffle;
/// Same as [`i8x16_shuffle`], except operates as if the inputs were two
/// 64-bit integers, only taking 2 indices to shuffle.
///
@ -910,6 +922,8 @@ pub unsafe fn i64x2_shuffle<const I0: usize, const I1: usize>(a: v128, b: v128)
transmute(shuf)
}
pub use i64x2_shuffle as u64x2_shuffle;
/// Extracts a lane from a 128-bit vector interpreted as 16 packed i8 numbers.
///
/// Extracts the scalar value of lane specified in the immediate mode operand
@ -1175,6 +1189,8 @@ pub unsafe fn i8x16_swizzle(a: v128, s: v128) -> v128 {
transmute(llvm_swizzle(transmute(a), transmute(s)))
}
pub use i8x16_swizzle as u8x16_swizzle;
/// Creates a vector with identical lanes.
///
/// Constructs a vector with `x` replicated to all 16 lanes.
@ -1309,6 +1325,9 @@ pub unsafe fn i8x16_ne(a: v128, b: v128) -> v128 {
transmute(simd_ne::<_, simd::i8x16>(a.as_i8x16(), b.as_i8x16()))
}
pub use i8x16_eq as u8x16_eq;
pub use i8x16_ne as u8x16_ne;
/// Compares two 128-bit vectors as if they were two vectors of 16 eight-bit
/// signed integers.
///
@ -1439,6 +1458,9 @@ pub unsafe fn i16x8_ne(a: v128, b: v128) -> v128 {
transmute(simd_ne::<_, simd::i16x8>(a.as_i16x8(), b.as_i16x8()))
}
pub use i16x8_eq as u16x8_eq;
pub use i16x8_ne as u16x8_ne;
/// Compares two 128-bit vectors as if they were two vectors of 8 sixteen-bit
/// signed integers.
///
@ -1569,6 +1591,9 @@ pub unsafe fn i32x4_ne(a: v128, b: v128) -> v128 {
transmute(simd_ne::<_, simd::i32x4>(a.as_i32x4(), b.as_i32x4()))
}
pub use i32x4_eq as u32x4_eq;
pub use i32x4_ne as u32x4_ne;
/// Compares two 128-bit vectors as if they were two vectors of 4 thirty-two-bit
/// signed integers.
///
@ -1699,6 +1724,9 @@ pub unsafe fn i64x2_ne(a: v128, b: v128) -> v128 {
transmute(simd_ne::<_, simd::i64x2>(a.as_i64x2(), b.as_i64x2()))
}
pub use i64x2_eq as u64x2_eq;
pub use i64x2_ne as u64x2_ne;
/// Compares two 128-bit vectors as if they were two vectors of 2 sixty-four-bit
/// signed integers.
///
@ -2011,6 +2039,8 @@ pub unsafe fn i8x16_popcnt(v: v128) -> v128 {
transmute(llvm_popcnt(v.as_i8x16()))
}
pub use i8x16_popcnt as u8x16_popcnt;
/// Returns true if all lanes are nonzero or false if any lane is nonzero.
#[inline]
#[cfg_attr(test, assert_instr(i8x16.all_true))]
@ -2020,6 +2050,8 @@ pub unsafe fn i8x16_all_true(a: v128) -> bool {
llvm_i8x16_all_true(a.as_i8x16()) != 0
}
pub use i8x16_all_true as u8x16_all_true;
/// Extracts the high bit for each lane in `a` and produce a scalar mask with
/// all bits concatenated.
#[inline]
@ -2034,6 +2066,8 @@ pub unsafe fn i8x16_bitmask(a: v128) -> u16 {
llvm_bitmask_i8x16(transmute(a)) as u16
}
pub use i8x16_bitmask as u8x16_bitmask;
/// Converts two input vectors into a smaller lane vector by narrowing each
/// lane.
///
@ -2072,6 +2106,8 @@ pub unsafe fn i8x16_shl(a: v128, amt: u32) -> v128 {
transmute(simd_shl(a.as_i8x16(), simd::i8x16::splat(amt as i8)))
}
pub use i8x16_shl as u8x16_shl;
/// Shifts each lane to the right by the specified number of bits, sign
/// extending.
///
@ -2107,6 +2143,8 @@ pub unsafe fn i8x16_add(a: v128, b: v128) -> v128 {
transmute(simd_add(a.as_i8x16(), b.as_i8x16()))
}
pub use i8x16_add as u8x16_add;
/// Adds two 128-bit vectors as if they were two packed sixteen 8-bit signed
/// integers, saturating on overflow to `i8::MAX`.
#[inline]
@ -2136,6 +2174,8 @@ pub unsafe fn i8x16_sub(a: v128, b: v128) -> v128 {
transmute(simd_sub(a.as_i8x16(), b.as_i8x16()))
}
pub use i8x16_sub as u8x16_sub;
/// Subtracts two 128-bit vectors as if they were two packed sixteen 8-bit
/// signed integers, saturating on overflow to `i8::MIN`.
#[inline]
@ -2233,6 +2273,8 @@ pub unsafe fn i16x8_extadd_pairwise_u8x16(a: v128) -> v128 {
transmute(llvm_i16x8_extadd_pairwise_i8x16_u(a.as_i8x16()))
}
pub use i16x8_extadd_pairwise_u8x16 as u16x8_extadd_pairwise_u8x16;
/// Lane-wise wrapping absolute value.
#[inline]
#[cfg_attr(test, assert_instr(i16x8.abs))]
@ -2275,6 +2317,8 @@ pub unsafe fn i16x8_all_true(a: v128) -> bool {
llvm_i16x8_all_true(a.as_i16x8()) != 0
}
pub use i16x8_all_true as u16x8_all_true;
/// Extracts the high bit for each lane in `a` and produce a scalar mask with
/// all bits concatenated.
#[inline]
@ -2285,6 +2329,8 @@ pub unsafe fn i16x8_bitmask(a: v128) -> u8 {
llvm_bitmask_i16x8(transmute(a)) as u8
}
pub use i16x8_bitmask as u16x8_bitmask;
/// Converts two input vectors into a smaller lane vector by narrowing each
/// lane.
///
@ -2353,6 +2399,8 @@ pub unsafe fn i16x8_extend_low_u8x16(a: v128) -> v128 {
)))
}
pub use i16x8_extend_low_u8x16 as u16x8_extend_low_u8x16;
/// Converts high half of the smaller lane vector to a larger lane
/// vector, zero extended.
#[inline]
@ -2367,6 +2415,8 @@ pub unsafe fn i16x8_extend_high_u8x16(a: v128) -> v128 {
)))
}
pub use i16x8_extend_high_u8x16 as u16x8_extend_high_u8x16;
/// Shifts each lane to the left by the specified number of bits.
///
/// Only the low bits of the shift amount are used if the shift amount is
@ -2379,6 +2429,8 @@ pub unsafe fn i16x8_shl(a: v128, amt: u32) -> v128 {
transmute(simd_shl(a.as_i16x8(), simd::i16x8::splat(amt as i16)))
}
pub use i16x8_shl as u16x8_shl;
/// Shifts each lane to the right by the specified number of bits, sign
/// extending.
///
@ -2414,6 +2466,8 @@ pub unsafe fn i16x8_add(a: v128, b: v128) -> v128 {
transmute(simd_add(a.as_i16x8(), b.as_i16x8()))
}
pub use i16x8_add as u16x8_add;
/// Adds two 128-bit vectors as if they were two packed eight 16-bit signed
/// integers, saturating on overflow to `i16::MAX`.
#[inline]
@ -2443,6 +2497,8 @@ pub unsafe fn i16x8_sub(a: v128, b: v128) -> v128 {
transmute(simd_sub(a.as_i16x8(), b.as_i16x8()))
}
pub use i16x8_sub as u16x8_sub;
/// Subtracts two 128-bit vectors as if they were two packed eight 16-bit
/// signed integers, saturating on overflow to `i16::MIN`.
#[inline]
@ -2473,6 +2529,8 @@ pub unsafe fn i16x8_mul(a: v128, b: v128) -> v128 {
transmute(simd_mul(a.as_i16x8(), b.as_i16x8()))
}
pub use i16x8_mul as u16x8_mul;
/// Compares lane-wise signed integers, and returns the minimum of
/// each pair.
#[inline]
@ -2566,6 +2624,8 @@ pub unsafe fn i16x8_extmul_low_u8x16(a: v128, b: v128) -> v128 {
transmute(llvm_i16x8_extmul_low_i8x16_u(a.as_i8x16(), b.as_i8x16()))
}
pub use i16x8_extmul_low_u8x16 as u16x8_extmul_low_u8x16;
/// Lane-wise integer extended multiplication producing twice wider result than
/// the inputs.
///
@ -2578,6 +2638,8 @@ pub unsafe fn i16x8_extmul_high_u8x16(a: v128, b: v128) -> v128 {
transmute(llvm_i16x8_extmul_high_i8x16_u(a.as_i8x16(), b.as_i8x16()))
}
pub use i16x8_extmul_high_u8x16 as u16x8_extmul_high_u8x16;
/// Lane-wise integer extended pairwise addition producing extended results
/// (twice wider results than the inputs).
#[inline]
@ -2598,6 +2660,8 @@ pub unsafe fn i32x4_extadd_pairwise_u16x8(a: v128) -> v128 {
transmute(llvm_i32x4_extadd_pairwise_i16x8_u(a.as_i16x8()))
}
pub use i32x4_extadd_pairwise_u16x8 as u32x4_extadd_pairwise_u16x8;
/// Lane-wise wrapping absolute value.
#[inline]
#[cfg_attr(test, assert_instr(i32x4.abs))]
@ -2631,6 +2695,8 @@ pub unsafe fn i32x4_all_true(a: v128) -> bool {
llvm_i32x4_all_true(a.as_i32x4()) != 0
}
pub use i32x4_all_true as u32x4_all_true;
/// Extracts the high bit for each lane in `a` and produce a scalar mask with
/// all bits concatenated.
#[inline]
@ -2641,6 +2707,8 @@ pub unsafe fn i32x4_bitmask(a: v128) -> u8 {
llvm_bitmask_i32x4(transmute(a)) as u8
}
pub use i32x4_bitmask as u32x4_bitmask;
/// Converts low half of the smaller lane vector to a larger lane
/// vector, sign extended.
#[inline]
@ -2683,6 +2751,8 @@ pub unsafe fn i32x4_extend_low_u16x8(a: v128) -> v128 {
)))
}
pub use i32x4_extend_low_u16x8 as u32x4_extend_low_u16x8;
/// Converts high half of the smaller lane vector to a larger lane
/// vector, zero extended.
#[inline]
@ -2697,6 +2767,8 @@ pub unsafe fn i32x4_extend_high_u16x8(a: v128) -> v128 {
)))
}
pub use i32x4_extend_high_u16x8 as u32x4_extend_high_u16x8;
/// Shifts each lane to the left by the specified number of bits.
///
/// Only the low bits of the shift amount are used if the shift amount is
@ -2709,6 +2781,8 @@ pub unsafe fn i32x4_shl(a: v128, amt: u32) -> v128 {
transmute(simd_shl(a.as_i32x4(), simd::i32x4::splat(amt as i32)))
}
pub use i32x4_shl as u32x4_shl;
/// Shifts each lane to the right by the specified number of bits, sign
/// extending.
///
@ -2744,6 +2818,8 @@ pub unsafe fn i32x4_add(a: v128, b: v128) -> v128 {
transmute(simd_add(a.as_i32x4(), b.as_i32x4()))
}
pub use i32x4_add as u32x4_add;
/// Subtracts two 128-bit vectors as if they were two packed four 32-bit integers.
#[inline]
#[cfg_attr(test, assert_instr(i32x4.sub))]
@ -2753,6 +2829,8 @@ pub unsafe fn i32x4_sub(a: v128, b: v128) -> v128 {
transmute(simd_sub(a.as_i32x4(), b.as_i32x4()))
}
pub use i32x4_sub as u32x4_sub;
/// Multiplies two 128-bit vectors as if they were two packed four 32-bit
/// signed integers.
#[inline]
@ -2763,6 +2841,8 @@ pub unsafe fn i32x4_mul(a: v128, b: v128) -> v128 {
transmute(simd_mul(a.as_i32x4(), b.as_i32x4()))
}
pub use i32x4_mul as u32x4_mul;
/// Compares lane-wise signed integers, and returns the minimum of
/// each pair.
#[inline]
@ -2857,6 +2937,8 @@ pub unsafe fn i32x4_extmul_low_u16x8(a: v128, b: v128) -> v128 {
transmute(llvm_i32x4_extmul_low_i16x8_u(a.as_i16x8(), b.as_i16x8()))
}
pub use i32x4_extmul_low_u16x8 as u32x4_extmul_low_u16x8;
/// Lane-wise integer extended multiplication producing twice wider result than
/// the inputs.
///
@ -2869,6 +2951,8 @@ pub unsafe fn i32x4_extmul_high_u16x8(a: v128, b: v128) -> v128 {
transmute(llvm_i32x4_extmul_high_i16x8_u(a.as_i16x8(), b.as_i16x8()))
}
pub use i32x4_extmul_high_u16x8 as u32x4_extmul_high_u16x8;
/// Lane-wise wrapping absolute value.
#[inline]
// #[cfg_attr(test, assert_instr(i64x2.abs))] // FIXME llvm
@ -2902,6 +2986,8 @@ pub unsafe fn i64x2_all_true(a: v128) -> bool {
llvm_i64x2_all_true(a.as_i64x2()) != 0
}
pub use i64x2_all_true as u64x2_all_true;
/// Extracts the high bit for each lane in `a` and produce a scalar mask with
/// all bits concatenated.
#[inline]
@ -2912,6 +2998,8 @@ pub unsafe fn i64x2_bitmask(a: v128) -> u8 {
llvm_bitmask_i64x2(transmute(a)) as u8
}
pub use i64x2_bitmask as u64x2_bitmask;
/// Converts low half of the smaller lane vector to a larger lane
/// vector, sign extended.
#[inline]
@ -2954,6 +3042,8 @@ pub unsafe fn i64x2_extend_low_u32x4(a: v128) -> v128 {
)))
}
pub use i64x2_extend_low_u32x4 as u64x2_extend_low_u32x4;
/// Converts high half of the smaller lane vector to a larger lane
/// vector, zero extended.
#[inline]
@ -2968,6 +3058,8 @@ pub unsafe fn i64x2_extend_high_u32x4(a: v128) -> v128 {
)))
}
pub use i64x2_extend_high_u32x4 as u64x2_extend_high_u32x4;
/// Shifts each lane to the left by the specified number of bits.
///
/// Only the low bits of the shift amount are used if the shift amount is
@ -2980,6 +3072,8 @@ pub unsafe fn i64x2_shl(a: v128, amt: u32) -> v128 {
transmute(simd_shl(a.as_i64x2(), simd::i64x2::splat(amt as i64)))
}
pub use i64x2_shl as u64x2_shl;
/// Shifts each lane to the right by the specified number of bits, sign
/// extending.
///
@ -3015,6 +3109,8 @@ pub unsafe fn i64x2_add(a: v128, b: v128) -> v128 {
transmute(simd_add(a.as_i64x2(), b.as_i64x2()))
}
pub use i64x2_add as u64x2_add;
/// Subtracts two 128-bit vectors as if they were two packed two 64-bit integers.
#[inline]
#[cfg_attr(test, assert_instr(i64x2.sub))]
@ -3024,6 +3120,8 @@ pub unsafe fn i64x2_sub(a: v128, b: v128) -> v128 {
transmute(simd_sub(a.as_i64x2(), b.as_i64x2()))
}
pub use i64x2_sub as u64x2_sub;
/// Multiplies two 128-bit vectors as if they were two packed two 64-bit integers.
#[inline]
#[cfg_attr(test, assert_instr(i64x2.mul))]
@ -3033,6 +3131,8 @@ pub unsafe fn i64x2_mul(a: v128, b: v128) -> v128 {
transmute(simd_mul(a.as_i64x2(), b.as_i64x2()))
}
pub use i64x2_mul as u64x2_mul;
/// Lane-wise integer extended multiplication producing twice wider result than
/// the inputs.
///
@ -3069,6 +3169,8 @@ pub unsafe fn i64x2_extmul_low_u32x4(a: v128, b: v128) -> v128 {
transmute(llvm_i64x2_extmul_low_i32x4_u(a.as_i32x4(), b.as_i32x4()))
}
pub use i64x2_extmul_low_u32x4 as u64x2_extmul_low_u32x4;
/// Lane-wise integer extended multiplication producing twice wider result than
/// the inputs.
///
@ -3081,6 +3183,8 @@ pub unsafe fn i64x2_extmul_high_u32x4(a: v128, b: v128) -> v128 {
transmute(llvm_i64x2_extmul_high_i32x4_u(a.as_i32x4(), b.as_i32x4()))
}
pub use i64x2_extmul_high_u32x4 as u64x2_extmul_high_u32x4;
/// Lane-wise rounding to the nearest integral value not smaller than the input.
#[inline]
#[cfg_attr(test, assert_instr(f32x4.ceil))]

View file

@ -176,17 +176,17 @@ unsafe fn hex_encode_simd128<'a>(mut src: &[u8], dst: &'a mut [u8]) -> Result<&'
let cmpmask2 = u8x16_gt(masked2, nines);
// add '0' or the offset depending on the masks
let masked1 = i8x16_add(masked1, v128_bitselect(ascii_a, ascii_zero, cmpmask1));
let masked2 = i8x16_add(masked2, v128_bitselect(ascii_a, ascii_zero, cmpmask2));
let masked1 = u8x16_add(masked1, v128_bitselect(ascii_a, ascii_zero, cmpmask1));
let masked2 = u8x16_add(masked2, v128_bitselect(ascii_a, ascii_zero, cmpmask2));
// Next we need to shuffle around masked{1,2} to get back to the
// original source text order. The first element (res1) we'll store uses
// all the low bytes from the 2 masks and the second element (res2) uses
// all the upper bytes.
let res1 = i8x16_shuffle::<0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23>(
let res1 = u8x16_shuffle::<0, 16, 1, 17, 2, 18, 3, 19, 4, 20, 5, 21, 6, 22, 7, 23>(
masked2, masked1,
);
let res2 = i8x16_shuffle::<8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31>(
let res2 = u8x16_shuffle::<8, 24, 9, 25, 10, 26, 11, 27, 12, 28, 13, 29, 14, 30, 15, 31>(
masked2, masked1,
);