silk.simd.i8x16.
Operations on simd<i8, 16>: sixteen signed 8-bit integer lanes in one 128-bit vector.
When to use#
Use this module to work on sixteen i8 values at once. Use load and store
to move lanes between a slice and a vector, a lane comparison such as lanesEqual to make
a mask<16>, and silk.simd.mask16 to test that mask.
Details#
The operators +, -, *, /, %, &, |, ^ and ~ apply lane by lane and trap
exactly where the i8 operator traps. Use wrappingAdd or saturatingAdd when
overflow is expected. == is true only when every lane is equal.
Lane 0 is at the lowest address in memory.
Examples#
Find the first matching lane#
import silk.simd.mask16
import silk.simd.i8x16
pub fn main() -> i32 {
let mut values: [i8; 16] = i8x16.toArray(i8x16.splat(0))
values[15] = -3
let hits = i8x16.lanesEqual(i8x16.fromArray(values), i8x16.splat(-3))
if !mask16.any(hits) || mask16.firstSet(hits) != 15 {
return 1
}
return 0
}Import as i8x16 with import silk.simd.i8x16 as i8x16.
Public declarations: 48.
LANES#
pub const LANES: usizeThe number of lanes in a vector.
splat#
pub fn splat(lane: i8) -> simd<i8, 16>Returns a vector with every lane set to lane.
fromArray#
pub fn fromArray(lanes: [i8; 16]) -> simd<i8, 16>Returns a vector whose lane i is lanes[i].
toArray#
pub fn toArray(vector: simd<i8, 16>) -> [i8; 16]Returns the lanes of vector as an array, in lane order.
extract#
pub fn extract(vector: simd<i8, 16>, index: usize) -> i8Returns lane index of vector. Traps when index is LANES or more.
insert#
pub fn insert(vector: simd<i8, 16>, index: usize, lane: i8) -> simd<i8, 16>Returns vector with lane index replaced by lane. Traps when index is LANES or more.
load#
pub fn load(lanes: &[i8], offset: usize) -> simd<i8, 16>Reads LANES lanes of lanes starting at offset.
Gotchas#
Traps unless offset + LANES is at most lanes.length. The slice needs no alignment beyond
i8.
store#
pub fn store(lanes: &mut [i8], offset: usize, vector: simd<i8, 16>) -> ()Writes the lanes of vector into lanes starting at offset.
Gotchas#
Traps unless offset + LANES is at most lanes.length.
loadUnchecked#
pub unsafe fn loadUnchecked(pointer: [*]const i8) -> simd<i8, 16>Reads LANES lanes starting at pointer, with no bounds check.
Gotchas#
The caller proves that pointer addresses LANES live lanes aligned to i8.
storeUnchecked#
pub unsafe fn storeUnchecked(pointer: [*]mut i8, vector: simd<i8, 16>) -> ()Writes the lanes of vector starting at pointer, with no bounds check.
Gotchas#
The caller proves that pointer addresses LANES writable lanes aligned to i8.
lanesEqual#
pub fn lanesEqual(left: simd<i8, 16>, right: simd<i8, 16>) -> mask<16>Returns a mask with lane i set where lane i of left is equal to lane i of right.
lanesNotEqual#
pub fn lanesNotEqual(left: simd<i8, 16>, right: simd<i8, 16>) -> mask<16>Returns a mask with lane i set where lane i of left is not equal to lane i of right.
lanesLess#
pub fn lanesLess(left: simd<i8, 16>, right: simd<i8, 16>) -> mask<16>Returns a mask with lane i set where lane i of left is less than lane i of right.
lanesLessOrEqual#
pub fn lanesLessOrEqual(left: simd<i8, 16>, right: simd<i8, 16>) -> mask<16>Returns a mask with lane i set where lane i of left is less than or equal to lane i of right.
lanesGreater#
pub fn lanesGreater(left: simd<i8, 16>, right: simd<i8, 16>) -> mask<16>Returns a mask with lane i set where lane i of left is greater than lane i of right.
lanesGreaterOrEqual#
pub fn lanesGreaterOrEqual(left: simd<i8, 16>, right: simd<i8, 16>) -> mask<16>Returns a mask with lane i set where lane i of left is greater than or equal to lane i of right.
select#
pub fn select(mask: mask<16>, chosen: simd<i8, 16>, other: simd<i8, 16>) -> simd<i8, 16>Returns lane i of chosen where lane i of mask is set, and lane i of other elsewhere.
minimum#
pub fn minimum(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the smaller lane of each pair.
maximum#
pub fn maximum(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the larger lane of each pair.
shuffle#
pub fn shuffle(left: simd<i8, 16>, right: simd<i8, 16>, static indices: [usize; 16]) -> simd<i8, 16>Returns a vector whose lane i is lane indices[i] of left followed by right.
Details#
An index below LANES selects from left, and an index from LANES to 2 * LANES - 1
selects from right. The indices are static, so each call is one fixed lane permutation.
reduceAdd#
pub fn reduceAdd(vector: simd<i8, 16>) -> i8Returns the sum of every lane. Traps when the exact sum does not fit i8.
reduceMinimum#
pub fn reduceMinimum(vector: simd<i8, 16>) -> i8Returns the smallest lane.
reduceMaximum#
pub fn reduceMaximum(vector: simd<i8, 16>) -> i8Returns the largest lane.
wrappingAdd#
pub fn wrappingAdd(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the sum of each pair of lanes modulo 2^8.
wrappingSubtract#
pub fn wrappingSubtract(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the difference of each pair of lanes modulo 2^8.
wrappingMultiply#
pub fn wrappingMultiply(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the product of each pair of lanes modulo 2^8.
saturatingAdd#
pub fn saturatingAdd(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the sum of each pair of lanes, clamped to the range of i8.
saturatingSubtract#
pub fn saturatingSubtract(left: simd<i8, 16>, right: simd<i8, 16>) -> simd<i8, 16>Returns the difference of each pair of lanes, clamped to the range of i8.
shiftLeft#
pub fn shiftLeft(vector: simd<i8, 16>, counts: simd<i8, 16>) -> simd<i8, 16>Shifts lane i of vector left by lane i of counts.
Gotchas#
Traps when any count is not in the range 0 to 7.
shiftRight#
pub fn shiftRight(vector: simd<i8, 16>, counts: simd<i8, 16>) -> simd<i8, 16>Shifts lane i of vector right by lane i of counts. The shift copies the sign bit.
Gotchas#
Traps when any count is not in the range 0 to 7.
rotateLeft#
pub fn rotateLeft(vector: simd<i8, 16>, counts: simd<i8, 16>) -> simd<i8, 16>Rotates lane i of vector left by lane i of counts modulo 8.
rotateRight#
pub fn rotateRight(vector: simd<i8, 16>, counts: simd<i8, 16>) -> simd<i8, 16>Rotates lane i of vector right by lane i of counts modulo 8.
reduceWrappingAdd#
pub fn reduceWrappingAdd(vector: simd<i8, 16>) -> i8Returns the sum of every lane modulo 2^8.
reduceBitAnd#
pub fn reduceBitAnd(vector: simd<i8, 16>) -> i8Returns the bitwise and of every lane.
reduceBitOr#
pub fn reduceBitOr(vector: simd<i8, 16>) -> i8Returns the bitwise or of every lane.
reduceBitXor#
pub fn reduceBitXor(vector: simd<i8, 16>) -> i8Returns the bitwise exclusive or of every lane.
toU8x16#
pub fn toU8x16(vector: simd<i8, 16>) -> simd<u8, 16>Converts each lane to u8 as the scalar conversion does. Traps when any lane does not
fit u8.
toU16x16#
pub fn toU16x16(vector: simd<i8, 16>) -> simd<u16, 16>Converts each lane to u16 as the scalar conversion does. Traps when any lane does not
fit u16.
toI16x16#
pub fn toI16x16(vector: simd<i8, 16>) -> simd<i16, 16>Converts each lane to i16 as the scalar conversion does. Traps when any lane does not
fit i16.
bitcastToU8x16#
pub fn bitcastToU8x16(vector: simd<i8, 16>) -> simd<u8, 16>Returns the bits of vector as a simd<u8, 16>, in memory order.
bitcastToU16x8#
pub fn bitcastToU16x8(vector: simd<i8, 16>) -> simd<u16, 8>Returns the bits of vector as a simd<u16, 8>, in memory order.
bitcastToI16x8#
pub fn bitcastToI16x8(vector: simd<i8, 16>) -> simd<i16, 8>Returns the bits of vector as a simd<i16, 8>, in memory order.
bitcastToU32x4#
pub fn bitcastToU32x4(vector: simd<i8, 16>) -> simd<u32, 4>Returns the bits of vector as a simd<u32, 4>, in memory order.
bitcastToI32x4#
pub fn bitcastToI32x4(vector: simd<i8, 16>) -> simd<i32, 4>Returns the bits of vector as a simd<i32, 4>, in memory order.
bitcastToU64x2#
pub fn bitcastToU64x2(vector: simd<i8, 16>) -> simd<u64, 2>Returns the bits of vector as a simd<u64, 2>, in memory order.
bitcastToI64x2#
pub fn bitcastToI64x2(vector: simd<i8, 16>) -> simd<i64, 2>Returns the bits of vector as a simd<i64, 2>, in memory order.
bitcastToF32x4#
pub fn bitcastToF32x4(vector: simd<i8, 16>) -> simd<f32, 4>Returns the bits of vector as a simd<f32, 4>, in memory order.
bitcastToF64x2#
pub fn bitcastToF64x2(vector: simd<i8, 16>) -> simd<f64, 2>Returns the bits of vector as a simd<f64, 2>, in memory order.
Category: SIMD.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2.