Browse the docs

silk.simd.i32x4.

Operations on simd<i32, 4>: four signed 32-bit integer lanes in one 128-bit vector.

When to use#

Use this module to work on four i32 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<4>, and silk.simd.mask4 to test that mask.

Details#

The operators +, -, *, /, %, &, |, ^ and ~ apply lane by lane and trap exactly where the i32 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#

silk
import silk.simd.mask4
import silk.simd.i32x4

pub fn main() -> i32 {
  let mut values: [i32; 4] = i32x4.toArray(i32x4.splat(0))
  values[3] = -3
  let hits = i32x4.lanesEqual(i32x4.fromArray(values), i32x4.splat(-3))
  if !mask4.any(hits) || mask4.firstSet(hits) != 3 {
    return 1
  }
  return 0
}

Import as i32x4 with import silk.simd.i32x4 as i32x4.

Public declarations: 50.

LANES#

silk
pub const LANES: usize

The number of lanes in a vector.

splat#

silk
pub fn splat(lane: i32) -> simd<i32, 4>

Returns a vector with every lane set to lane.

fromArray#

silk
pub fn fromArray(lanes: [i32; 4]) -> simd<i32, 4>

Returns a vector whose lane i is lanes[i].

toArray#

silk
pub fn toArray(vector: simd<i32, 4>) -> [i32; 4]

Returns the lanes of vector as an array, in lane order.

extract#

silk
pub fn extract(vector: simd<i32, 4>, index: usize) -> i32

Returns lane index of vector. Traps when index is LANES or more.

insert#

silk
pub fn insert(vector: simd<i32, 4>, index: usize, lane: i32) -> simd<i32, 4>

Returns vector with lane index replaced by lane. Traps when index is LANES or more.

load#

silk
pub fn load(lanes: &[i32], offset: usize) -> simd<i32, 4>

Reads LANES lanes of lanes starting at offset.

Gotchas#

Traps unless offset + LANES is at most lanes.length. The slice needs no alignment beyond i32.

store#

silk
pub fn store(lanes: &mut [i32], offset: usize, vector: simd<i32, 4>) -> ()

Writes the lanes of vector into lanes starting at offset.

Gotchas#

Traps unless offset + LANES is at most lanes.length.

loadUnchecked#

silk
pub unsafe fn loadUnchecked(pointer: [*]const i32) -> simd<i32, 4>

Reads LANES lanes starting at pointer, with no bounds check.

Gotchas#

The caller proves that pointer addresses LANES live lanes aligned to i32.

storeUnchecked#

silk
pub unsafe fn storeUnchecked(pointer: [*]mut i32, vector: simd<i32, 4>) -> ()

Writes the lanes of vector starting at pointer, with no bounds check.

Gotchas#

The caller proves that pointer addresses LANES writable lanes aligned to i32.

lanesEqual#

silk
pub fn lanesEqual(left: simd<i32, 4>, right: simd<i32, 4>) -> mask<4>

Returns a mask with lane i set where lane i of left is equal to lane i of right.

lanesNotEqual#

silk
pub fn lanesNotEqual(left: simd<i32, 4>, right: simd<i32, 4>) -> mask<4>

Returns a mask with lane i set where lane i of left is not equal to lane i of right.

lanesLess#

silk
pub fn lanesLess(left: simd<i32, 4>, right: simd<i32, 4>) -> mask<4>

Returns a mask with lane i set where lane i of left is less than lane i of right.

lanesLessOrEqual#

silk
pub fn lanesLessOrEqual(left: simd<i32, 4>, right: simd<i32, 4>) -> mask<4>

Returns a mask with lane i set where lane i of left is less than or equal to lane i of right.

lanesGreater#

silk
pub fn lanesGreater(left: simd<i32, 4>, right: simd<i32, 4>) -> mask<4>

Returns a mask with lane i set where lane i of left is greater than lane i of right.

lanesGreaterOrEqual#

silk
pub fn lanesGreaterOrEqual(left: simd<i32, 4>, right: simd<i32, 4>) -> mask<4>

Returns a mask with lane i set where lane i of left is greater than or equal to lane i of right.

select#

silk
pub fn select(mask: mask<4>, chosen: simd<i32, 4>, other: simd<i32, 4>) -> simd<i32, 4>

Returns lane i of chosen where lane i of mask is set, and lane i of other elsewhere.

minimum#

silk
pub fn minimum(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the smaller lane of each pair.

maximum#

silk
pub fn maximum(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the larger lane of each pair.

shuffle#

silk
pub fn shuffle(left: simd<i32, 4>, right: simd<i32, 4>, static indices: [usize; 4]) -> simd<i32, 4>

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#

silk
pub fn reduceAdd(vector: simd<i32, 4>) -> i32

Returns the sum of every lane. Traps when the exact sum does not fit i32.

reduceMinimum#

silk
pub fn reduceMinimum(vector: simd<i32, 4>) -> i32

Returns the smallest lane.

reduceMaximum#

silk
pub fn reduceMaximum(vector: simd<i32, 4>) -> i32

Returns the largest lane.

wrappingAdd#

silk
pub fn wrappingAdd(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the sum of each pair of lanes modulo 2^32.

wrappingSubtract#

silk
pub fn wrappingSubtract(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the difference of each pair of lanes modulo 2^32.

wrappingMultiply#

silk
pub fn wrappingMultiply(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the product of each pair of lanes modulo 2^32.

saturatingAdd#

silk
pub fn saturatingAdd(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the sum of each pair of lanes, clamped to the range of i32.

saturatingSubtract#

silk
pub fn saturatingSubtract(left: simd<i32, 4>, right: simd<i32, 4>) -> simd<i32, 4>

Returns the difference of each pair of lanes, clamped to the range of i32.

shiftLeft#

silk
pub fn shiftLeft(vector: simd<i32, 4>, counts: simd<i32, 4>) -> simd<i32, 4>

Shifts lane i of vector left by lane i of counts.

Gotchas#

Traps when any count is not in the range 0 to 31.

shiftRight#

silk
pub fn shiftRight(vector: simd<i32, 4>, counts: simd<i32, 4>) -> simd<i32, 4>

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 31.

rotateLeft#

silk
pub fn rotateLeft(vector: simd<i32, 4>, counts: simd<i32, 4>) -> simd<i32, 4>

Rotates lane i of vector left by lane i of counts modulo 32.

rotateRight#

silk
pub fn rotateRight(vector: simd<i32, 4>, counts: simd<i32, 4>) -> simd<i32, 4>

Rotates lane i of vector right by lane i of counts modulo 32.

reduceWrappingAdd#

silk
pub fn reduceWrappingAdd(vector: simd<i32, 4>) -> i32

Returns the sum of every lane modulo 2^32.

reduceBitAnd#

silk
pub fn reduceBitAnd(vector: simd<i32, 4>) -> i32

Returns the bitwise and of every lane.

reduceBitOr#

silk
pub fn reduceBitOr(vector: simd<i32, 4>) -> i32

Returns the bitwise or of every lane.

reduceBitXor#

silk
pub fn reduceBitXor(vector: simd<i32, 4>) -> i32

Returns the bitwise exclusive or of every lane.

toU32x4#

silk
pub fn toU32x4(vector: simd<i32, 4>) -> simd<u32, 4>

Converts each lane to u32 as the scalar conversion does. Traps when any lane does not fit u32.

toF32x4#

silk
pub fn toF32x4(vector: simd<i32, 4>) -> simd<f32, 4>

Converts each lane to f32 as the scalar conversion does.

toU64x4#

silk
pub fn toU64x4(vector: simd<i32, 4>) -> simd<u64, 4>

Converts each lane to u64 as the scalar conversion does. Traps when any lane does not fit u64.

toI64x4#

silk
pub fn toI64x4(vector: simd<i32, 4>) -> simd<i64, 4>

Converts each lane to i64 as the scalar conversion does. Traps when any lane does not fit i64.

toF64x4#

silk
pub fn toF64x4(vector: simd<i32, 4>) -> simd<f64, 4>

Converts each lane to f64 as the scalar conversion does.

bitcastToU8x16#

silk
pub fn bitcastToU8x16(vector: simd<i32, 4>) -> simd<u8, 16>

Returns the bits of vector as a simd<u8, 16>, in memory order.

bitcastToI8x16#

silk
pub fn bitcastToI8x16(vector: simd<i32, 4>) -> simd<i8, 16>

Returns the bits of vector as a simd<i8, 16>, in memory order.

bitcastToU16x8#

silk
pub fn bitcastToU16x8(vector: simd<i32, 4>) -> simd<u16, 8>

Returns the bits of vector as a simd<u16, 8>, in memory order.

bitcastToI16x8#

silk
pub fn bitcastToI16x8(vector: simd<i32, 4>) -> simd<i16, 8>

Returns the bits of vector as a simd<i16, 8>, in memory order.

bitcastToU32x4#

silk
pub fn bitcastToU32x4(vector: simd<i32, 4>) -> simd<u32, 4>

Returns the bits of vector as a simd<u32, 4>, in memory order.

bitcastToU64x2#

silk
pub fn bitcastToU64x2(vector: simd<i32, 4>) -> simd<u64, 2>

Returns the bits of vector as a simd<u64, 2>, in memory order.

bitcastToI64x2#

silk
pub fn bitcastToI64x2(vector: simd<i32, 4>) -> simd<i64, 2>

Returns the bits of vector as a simd<i64, 2>, in memory order.

bitcastToF32x4#

silk
pub fn bitcastToF32x4(vector: simd<i32, 4>) -> simd<f32, 4>

Returns the bits of vector as a simd<f32, 4>, in memory order.

bitcastToF64x2#

silk
pub fn bitcastToF64x2(vector: simd<i32, 4>) -> 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.

View the source of this page