Simd
Simd -- explicit 128-bit SIMD vector values (F32x4, F64x2, I32x4, I64x2, U8x16). Fixed width: identical semantics on every target, interpreted or compiled. See docs/simd-vectorization.md.
Boundary rule: lane get/set traffic in widened Int/Float; integer narrowing wraps mod 2^w two's-complement; f32 narrowing rounds to nearest-even; u8 loads zero-extend (0..255), i32 sign-extends. Integer lane arithmetic wraps. Float lanes are true single/double precision. min/max/hmin/hmax on floats use minNum/maxNum semantics (a NaN operand loses to the other; both NaN is NaN). sum accumulates sequentially (f32x4/f64x2 in double, i32x4/i64x2 in i64).
Lane order: lane 0 is the first make_* argument / lowest-addressed on load.
Mask convention: select/any/all/first_set all read a lane's HIGH BIT (its sign bit), matching hardware blend/movemask. eq/lt/gt still produce canonical all-ones/all-zero lanes, which read the same either way; a hand-rolled non-canonical mask lane follows the high-bit rule. A float mask's all-ones lane is a NaN bit pattern, so extracting it gives NaN; read float masks with any/all/first_set/select (or and_* them with a value vector) rather than by extracting lanes.
Op coverage: F32x4, F64x2, I32x4 and I64x2 have the full set (construct, lanes, load/store, compare, bitwise, mask, arithmetic, min/max, horizontal reductions; floats add div/fma/sqrt, integers add shl/shr). U8x16 has construct, lanes, load/store, compare (unsigned), bitwise and mask ops only.
Arrays: load/store work on NativeArray's flat arrays, one per lane type: F32x4 <-> NativeF32Arr, F64x2 <-> NativeFloatArr, I32x4 <-> NativeI32Arr, I64x2 <-> NativeIntArr, U8x16 <-> NativeU8Arr (see NativeArray.from_list_, NativeArray.make_, Bytes.to_u8_arr).
Inspecting a vector: vectors have no literal form, so the REPL shows them as an opaque value. Use extract_* for one lane, == (impl Eq compares lane values with Int/Float ==), or to_string (impl Show, e.g. "I32x4[1, 2, 3, 4]").
Functions
Per-lane addition, rounded to binary32.
Examples
march> Simd.add_f32x4(Simd.make_f32x4(1.0, 2.0, 3.0, 4.0), Simd.splat_f32x4(0.5)) == Simd.make_f32x4(1.5, 2.5, 3.5, 4.5)
true
march> Simd.extract_f32x4(Simd.add_f32x4(Simd.splat_f32x4(16777216.0), Simd.splat_f32x4(1.0)), 0) == 16777216.0
truePer-lane addition (binary64; no narrowing).
Examples
march> Simd.extract_f64x2(Simd.add_f64x2(Simd.splat_f64x2(16777216.0), Simd.splat_f64x2(1.0)), 0) == 16777217.0
truePer-lane addition, wrapping mod 2^32 (never panics on overflow).
Examples
march> Simd.add_i32x4(Simd.make_i32x4(1, 2, 3, 4), Simd.splat_i32x4(10)) == Simd.make_i32x4(11, 12, 13, 14)
true
march> Simd.extract_i32x4(Simd.add_i32x4(Simd.splat_i32x4(2147483647), Simd.splat_i32x4(1)), 0)
-2147483648Per-lane addition, wrapping mod 2^64.
Examples
march> Simd.add_i64x2(Simd.make_i64x2(1, 2), Simd.make_i64x2(10, -20)) == Simd.make_i64x2(11, -18)
trueTrue if every lane's high (sign) bit is set (interprets [v] as a mask).
Examples
march> Simd.all_f32x4(Simd.make_f32x4(-1.0, -2.0, -0.5, -3.0))
trueTrue if every lane's high (sign) bit is set (interprets [v] as a mask).
Examples
march> Simd.all_f64x2(Simd.make_f64x2(-1.0, 1.0))
falseTrue if every lane's high bit is set, i.e. every lane is negative (interprets [v] as a mask).
Examples
march> Simd.all_i32x4(Simd.make_i32x4(-1, -1, -1, 1))
falseTrue if every lane's high bit is set, i.e. both lanes are negative (interprets [v] as a mask).
Examples
march> Simd.all_i64x2(Simd.make_i64x2(0, -1))
falseTrue if every lane has bit 7 set, i.e. is >= 128 (interprets [v] as a mask).
Examples
march> Simd.all_u8x16(Simd.splat_u8x16(255))
truePer-lane bitwise AND of the lanes' binary32 bit patterns. ANDing a compare mask with a value vector keeps the value where the mask is set and gives 0.0 elsewhere.
Examples
march> Simd.and_f32x4(Simd.eq_f32x4(Simd.make_f32x4(1.0, 2.0, 3.0, 2.0), Simd.splat_f32x4(2.0)), Simd.splat_f32x4(5.0)) == Simd.make_f32x4(0.0, 5.0, 0.0, 5.0)
truePer-lane bitwise AND of the lanes' binary64 bit patterns.
Examples
march> Simd.and_f64x2(Simd.eq_f64x2(Simd.make_f64x2(1.0, 2.0), Simd.splat_f64x2(2.0)), Simd.splat_f64x2(9.5)) == Simd.make_f64x2(0.0, 9.5)
truePer-lane bitwise AND.
Examples
march> Simd.extract_i32x4(Simd.and_i32x4(Simd.splat_i32x4(12), Simd.splat_i32x4(10)), 0)
8Per-lane bitwise AND.
Examples
march> Simd.and_i64x2(Simd.make_i64x2(12, -1), Simd.splat_i64x2(10)) == Simd.make_i64x2(8, 10)
truePer-lane bitwise AND.
Examples
march> Simd.extract_u8x16(Simd.and_u8x16(Simd.splat_u8x16(12), Simd.splat_u8x16(10)), 0)
8True if any lane's high (sign) bit is set (interprets [v] as a mask). On a plain value vector that means "any lane is negative or -0.0".
Examples
march> Simd.any_f32x4(Simd.make_f32x4(1.0, 2.0, 0.5, 3.0))
false
march> Simd.any_f32x4(Simd.make_f32x4(1.0, 2.0, -0.0, 3.0))
trueTrue if any lane's high (sign) bit is set (interprets [v] as a mask).
Examples
march> Simd.any_f64x2(Simd.make_f64x2(-0.0, 1.0))
trueTrue if any lane's high bit is set, i.e. any lane is negative (interprets [v] as a mask).
Examples
march> Simd.any_i32x4(Simd.gt_i32x4(Simd.make_i32x4(1, 5, 2, 9), Simd.splat_i32x4(8)))
true
march> Simd.any_i32x4(Simd.make_i32x4(0, 1, 2, 3))
falseTrue if any lane's high bit is set, i.e. any lane is negative (interprets [v] as a mask).
Examples
march> Simd.any_i64x2(Simd.make_i64x2(0, -1))
trueTrue if any lane has bit 7 set, i.e. is >= 128 (interprets [v] as a mask).
Examples
march> Simd.any_u8x16(Simd.splat_u8x16(127))
false
march> Simd.any_u8x16(Simd.replace_u8x16(Simd.splat_u8x16(0), 9, 128))
truePer-lane division [a] / [b], rounded to binary32. IEEE semantics: dividing by 0.0 gives an infinity (or NaN for 0.0 / 0.0), never a panic.
Examples
march> Simd.extract_f32x4(Simd.div_f32x4(Simd.make_f32x4(1.0, 2.0, 3.0, 5.0), Simd.splat_f32x4(2.0)), 3)
2.5Per-lane division [a] / [b]. IEEE semantics: dividing by 0.0 gives an infinity (or NaN for 0.0 / 0.0), never a panic.
Examples
march> Simd.div_f64x2(Simd.make_f64x2(1.0, 3.0), Simd.splat_f64x2(2.0)) == Simd.make_f64x2(0.5, 1.5)
truePer-lane equality mask: all-ones lane where [a] == [b], zero otherwise. IEEE comparison: NaN is unequal to everything, 0.0 equals -0.0.
Examples
march> Simd.first_set_f32x4(Simd.eq_f32x4(Simd.make_f32x4(1.0, 2.0, 3.0, 2.0), Simd.splat_f32x4(2.0)))
1Per-lane equality mask: all-ones lane where [a] == [b], zero otherwise (IEEE: NaN is unequal to everything).
Examples
march> Simd.all_f64x2(Simd.eq_f64x2(Simd.make_f64x2(1.0, 2.0), Simd.make_f64x2(1.0, 2.0)))
truePer-lane equality mask: -1 (all ones) where [a] == [b], 0 otherwise.
Examples
march> Simd.eq_i32x4(Simd.make_i32x4(1, 2, 3, 4), Simd.make_i32x4(1, 0, 3, 0)) == Simd.make_i32x4(-1, 0, -1, 0)
truePer-lane equality mask: -1 (all ones) where [a] == [b], 0 otherwise.
Examples
march> Simd.eq_i64x2(Simd.make_i64x2(1, 2), Simd.make_i64x2(1, 3)) == Simd.make_i64x2(-1, 0)
truePer-lane equality mask: 255 where [a] == [b], 0 otherwise.
Examples
march> Simd.all_u8x16(Simd.eq_u8x16(Simd.splat_u8x16(7), Simd.make_u8x16(7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8)))
falseLane [i] (0-3), widened to Float exactly. The index is refinement-checked; an out-of-range index panics at run time if it gets past the checker.
Examples
march> (Simd.extract_f32x4(Simd.make_f32x4(1.0, 2.0, 3.0, 4.0), 3)) == 4.0
trueLane [i] (0-1). The index is refinement-checked; an out-of-range index panics at run time if it gets past the checker.
Examples
march> (Simd.extract_f64x2(Simd.make_f64x2(1.5, -2.0), 1)) == -2.0
trueLane [i] (0-3), sign-extended to Int. The index is refinement-checked; an out-of-range index panics at run time if it gets past the checker.
Examples
march> Simd.extract_i32x4(Simd.make_i32x4(10, 20, 30, 40), 2)
30Lane [i] (0-1) as an Int. The index is refinement-checked; an out-of-range index panics at run time if it gets past the checker.
Examples
march> Simd.extract_i64x2(Simd.make_i64x2(5, -6), 1)
-6Lane [i] (0-15) as an Int in 0..255. The index is refinement-checked; an out-of-range index panics at run time if it gets past the checker.
Examples
march> Simd.extract_u8x16(Simd.splat_u8x16(200), 15)
200Index (0-3) of the first lane whose high bit is set (interprets [v] as a mask), or -1 if none.
Examples
march> Simd.first_set_f32x4(Simd.splat_f32x4(1.0))
-1Index (0-1) of the first lane whose high bit is set (interprets [v] as a mask), or -1 if none.
Examples
march> Simd.first_set_f64x2(Simd.splat_f64x2(0.0))
-1Index (0-3) of the first lane whose high bit is set (interprets [v] as a mask), or -1 if none. Combined with a compare, finds the first match.
Examples
march> Simd.first_set_i32x4(Simd.gt_i32x4(Simd.make_i32x4(1, 5, 2, 9), Simd.splat_i32x4(4)))
1
march> Simd.first_set_i32x4(Simd.splat_i32x4(0))
-1Index (0-1) of the first lane whose high bit is set (interprets [v] as a mask), or -1 if none.
Examples
march> Simd.first_set_i64x2(Simd.lt_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(0)))
1Index (0-15) of the first lane with bit 7 set (interprets [v] as a mask), or -1 if none.
Examples
march> Simd.first_set_u8x16(Simd.splat_u8x16(0))
-1Per-lane fused multiply-add [a] * [b] + [c] with a single binary32 rounding (bit-identical to hardware fmaf on both backends).
Examples
march> (Simd.extract_f32x4(Simd.fma_f32x4(Simd.splat_f32x4(2.0), Simd.splat_f32x4(3.0), Simd.splat_f32x4(1.0)), 0)) == 7.0
truePer-lane fused multiply-add [a] * [b] + [c] with a single binary64 rounding.
Examples
march> Simd.fma_f64x2(Simd.splat_f64x2(2.0), Simd.make_f64x2(3.0, 0.5), Simd.splat_f64x2(1.0)) == Simd.make_f64x2(7.0, 2.0)
truePer-lane greater-than mask: all-ones lane where [a] > [b], zero otherwise (false for a NaN lane).
Examples
march> Simd.all_f32x4(Simd.gt_f32x4(Simd.make_f32x4(5.0, 6.0, 7.0, 1.0), Simd.splat_f32x4(4.0)))
falsePer-lane greater-than mask: all-ones lane where [a] > [b], zero otherwise.
Examples
march> Simd.first_set_f64x2(Simd.gt_f64x2(Simd.make_f64x2(1.0, 5.0), Simd.splat_f64x2(2.0)))
1Per-lane signed greater-than mask: -1 where [a] > [b], 0 otherwise.
Examples
march> Simd.gt_i32x4(Simd.make_i32x4(1, 5, -2, 9), Simd.splat_i32x4(4)) == Simd.make_i32x4(0, -1, 0, -1)
truePer-lane signed greater-than mask: -1 where [a] > [b], 0 otherwise.
Examples
march> Simd.gt_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(0)) == Simd.make_i64x2(-1, 0)
truePer-lane UNSIGNED greater-than mask: 255 where [a] > [b], 0 otherwise.
Examples
march> Simd.first_set_u8x16(Simd.gt_u8x16(Simd.make_u8x16(0, 0, 0, 200, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9), Simd.splat_u8x16(100)))
3Horizontal maximum of all lanes (maxNum: a NaN lane is skipped unless every lane is NaN).
Examples
march> Simd.hmax_f32x4(Simd.make_f32x4(1.0, 7.5, -2.0, 3.0))
7.5Horizontal maximum of both lanes (maxNum: a NaN lane is skipped unless both lanes are NaN).
Examples
march> Simd.hmax_f64x2(Simd.make_f64x2(-1.5, -2.5))
-1.5Horizontal signed maximum of all lanes.
Examples
march> Simd.hmax_i32x4(Simd.make_i32x4(3, -2, 7, 0))
7Horizontal signed maximum of both lanes.
Examples
march> Simd.hmax_i64x2(Simd.make_i64x2(4, -9))
4Horizontal minimum of all lanes (minNum: a NaN lane is skipped unless every lane is NaN).
Examples
march> (Simd.hmin_f32x4(Simd.make_f32x4(1.0, 7.5, -2.0, 3.0))) == -2.0
trueHorizontal minimum of both lanes (minNum: a NaN lane is skipped unless both lanes are NaN).
Examples
march> Simd.hmin_f64x2(Simd.make_f64x2(-1.5, -2.5))
-2.5Horizontal signed minimum of all lanes.
Examples
march> Simd.hmin_i32x4(Simd.make_i32x4(3, -2, 7, 0))
-2Horizontal signed minimum of both lanes.
Examples
march> Simd.hmin_i64x2(Simd.make_i64x2(4, -9))
-9Load 4 lanes from the NativeF32Arr [arr], elements [i] to [i] + 3. Panics unless 0 <= [i] and [i] + 4 <= length.
Examples
march> (Simd.extract_f32x4(Simd.load_f32x4(NativeArray.from_list_f32([1.0, 2.0, 3.0, 4.0, 5.0]), 1), 3)) == 5.0
trueLoad 2 lanes from the NativeFloatArr [arr], elements [i] and [i] + 1. Panics unless 0 <= [i] and [i] + 2 <= length.
Examples
march> Simd.load_f64x2(NativeArray.from_list_float([1.0, 2.0, 3.0]), 1) == Simd.make_f64x2(2.0, 3.0)
trueLoad 4 lanes from the NativeI32Arr [arr], elements [i] to [i] + 3. Panics unless 0 <= [i] and [i] + 4 <= length.
Examples
march> Simd.load_i32x4(NativeArray.from_list_i32([1, 2, 3, 4, 5]), 1) == Simd.make_i32x4(2, 3, 4, 5)
trueLoad 2 lanes from the NativeIntArr [arr], elements [i] and [i] + 1. Panics unless 0 <= [i] and [i] + 2 <= length.
Examples
march> Simd.load_i64x2(NativeArray.from_list_int([5, 6, 7]), 1) == Simd.make_i64x2(6, 7)
trueLoad 16 lanes from the NativeU8Arr [arr], elements [i] to [i] + 15. Panics unless 0 <= [i] and [i] + 16 <= length. Bytes.to_u8_arr turns a Bytes value into a NativeU8Arr, which makes byte scanning straightforward:
Examples
march> let chunk = Simd.load_u8x16(Bytes.to_u8_arr(Bytes.from_string("hello, world! ok")), 0)
march> Simd.first_set_u8x16(Simd.eq_u8x16(chunk, Simd.splat_u8x16(44)))
5Per-lane less-than mask: all-ones lane where [a] < [b], zero otherwise (false for a NaN lane).
Examples
march> Simd.first_set_f32x4(Simd.lt_f32x4(Simd.make_f32x4(4.0, 3.0, 1.0, 0.0), Simd.splat_f32x4(2.0)))
2Per-lane less-than mask: all-ones lane where [a] < [b], zero otherwise.
Examples
march> Simd.first_set_f64x2(Simd.lt_f64x2(Simd.make_f64x2(3.0, 1.0), Simd.splat_f64x2(2.0)))
1Per-lane signed less-than mask: -1 where [a] < [b], 0 otherwise.
Examples
march> Simd.lt_i32x4(Simd.make_i32x4(1, 5, -2, 9), Simd.splat_i32x4(4)) == Simd.make_i32x4(-1, 0, -1, 0)
truePer-lane signed less-than mask: -1 where [a] < [b], 0 otherwise.
Examples
march> Simd.lt_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(0)) == Simd.make_i64x2(0, -1)
truePer-lane UNSIGNED less-than mask: 255 where [a] < [b], 0 otherwise.
Examples
march> Simd.extract_u8x16(Simd.lt_u8x16(Simd.splat_u8x16(1), Simd.splat_u8x16(200)), 0)
255Vector with lane 0 = the first argument, ..., lane 3 = the last. Each value is rounded to binary32, so a lane need not read back as the Float passed in.
Examples
march> Simd.extract_f32x4(Simd.make_f32x4(1.0, 2.5, -3.0, 0.25), 1)
2.5
march> Simd.extract_f32x4(Simd.make_f32x4(0.1, 0.0, 0.0, 0.0), 0) == 0.1
falseVector with lane 0 = [v0] and lane 1 = [v1] (exact; no rounding).
Examples
march> Simd.extract_f64x2(Simd.make_f64x2(0.1, 2.0), 0) == 0.1
trueVector with lane 0 = the first argument, ..., lane 3 = the last. Each value is wrapped to 32 bits (two's complement).
Examples
march> Simd.make_i32x4(1, -2, 3, 2147483647) == Simd.make_i32x4(1, -2, 3, 2147483647)
trueVector with lane 0 = [v0] and lane 1 = [v1].
Examples
march> Simd.make_i64x2(5, -6) == Simd.make_i64x2(5, -6)
trueVector with lane 0 = the first argument, ..., lane 15 = the last, each taken mod 256.
Examples
march> Simd.extract_u8x16(Simd.make_u8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), 15)
15
march> Simd.extract_u8x16(Simd.make_u8x16(-1, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 0)
255Per-lane maximum (maxNum: a NaN lane yields the other operand; both NaN yields NaN).
Examples
march> Simd.max_f32x4(Simd.make_f32x4(1.0, 5.0, 2.0, 9.0), Simd.splat_f32x4(3.0)) == Simd.make_f32x4(3.0, 5.0, 3.0, 9.0)
truePer-lane maximum (maxNum: a NaN lane yields the other operand; both NaN yields NaN).
Examples
march> Simd.max_f64x2(Simd.make_f64x2(1.0, 5.0), Simd.splat_f64x2(2.0)) == Simd.make_f64x2(2.0, 5.0)
truePer-lane signed maximum.
Examples
march> Simd.max_i32x4(Simd.make_i32x4(1, 5, -2, 9), Simd.splat_i32x4(3)) == Simd.make_i32x4(3, 5, 3, 9)
truePer-lane signed maximum.
Examples
march> Simd.max_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(1)) == Simd.make_i64x2(4, 1)
truePer-lane minimum (minNum: a NaN lane yields the other operand; both NaN yields NaN).
Examples
march> Simd.min_f32x4(Simd.make_f32x4(1.0, 5.0, 2.0, 9.0), Simd.splat_f32x4(3.0)) == Simd.make_f32x4(1.0, 3.0, 2.0, 3.0)
truePer-lane minimum (minNum: a NaN lane yields the other operand; both NaN yields NaN).
Examples
march> Simd.min_f64x2(Simd.make_f64x2(1.0, 5.0), Simd.splat_f64x2(2.0)) == Simd.make_f64x2(1.0, 2.0)
truePer-lane signed minimum.
Examples
march> Simd.min_i32x4(Simd.make_i32x4(1, 5, -2, 9), Simd.splat_i32x4(3)) == Simd.make_i32x4(1, 3, -2, 3)
truePer-lane signed minimum.
Examples
march> Simd.min_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(1)) == Simd.make_i64x2(1, -9)
truePer-lane multiplication, rounded to binary32.
Examples
march> (Simd.extract_f32x4(Simd.mul_f32x4(Simd.splat_f32x4(1.5), Simd.splat_f32x4(4.0)), 0)) == 6.0
truePer-lane multiplication.
Examples
march> Simd.mul_f64x2(Simd.make_f64x2(1.5, 2.0), Simd.splat_f64x2(4.0)) == Simd.make_f64x2(6.0, 8.0)
truePer-lane multiplication, keeping the low 32 bits of each product (wraps mod 2^32).
Examples
march> Simd.mul_i32x4(Simd.make_i32x4(1, -2, 3, 4), Simd.splat_i32x4(3)) == Simd.make_i32x4(3, -6, 9, 12)
truePer-lane multiplication, keeping the low 64 bits of each product.
Examples
march> Simd.mul_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(3)) == Simd.make_i64x2(12, -27)
truePer-lane bitwise complement of the binary32 bit pattern; inverts a mask.
Examples
march> Simd.all_f32x4(Simd.not_f32x4(Simd.splat_f32x4(0.0)))
truePer-lane bitwise complement of the binary64 bit pattern; inverts a mask.
Examples
march> Simd.any_f64x2(Simd.not_f64x2(Simd.eq_f64x2(Simd.splat_f64x2(1.0), Simd.splat_f64x2(1.0))))
falsePer-lane bitwise complement (-1 - x); inverts a mask.
Examples
march> Simd.not_i32x4(Simd.make_i32x4(0, -1, 5, -6)) == Simd.make_i32x4(-1, 0, -6, 5)
truePer-lane bitwise complement (-1 - x); inverts a mask.
Examples
march> Simd.not_i64x2(Simd.make_i64x2(0, 5)) == Simd.make_i64x2(-1, -6)
truePer-lane bitwise complement within 8 bits (255 - x); inverts a mask.
Examples
march> Simd.extract_u8x16(Simd.not_u8x16(Simd.splat_u8x16(15)), 0)
240Per-lane bitwise OR of the lanes' binary32 bit patterns (ORing in -0.0 sets the sign bit).
Examples
march> (Simd.extract_f32x4(Simd.or_f32x4(Simd.splat_f32x4(2.0), Simd.splat_f32x4(-0.0)), 0)) == -2.0
truePer-lane bitwise OR of the lanes' binary64 bit patterns.
Examples
march> Simd.extract_f64x2(Simd.or_f64x2(Simd.splat_f64x2(1.5), Simd.splat_f64x2(-0.0)), 0)
-1.5Per-lane bitwise OR.
Examples
march> Simd.extract_i32x4(Simd.or_i32x4(Simd.splat_i32x4(12), Simd.splat_i32x4(10)), 0)
14Per-lane bitwise OR.
Examples
march> Simd.or_i64x2(Simd.make_i64x2(12, 0), Simd.splat_i64x2(10)) == Simd.make_i64x2(14, 10)
truePer-lane bitwise OR.
Examples
march> Simd.extract_u8x16(Simd.or_u8x16(Simd.splat_u8x16(12), Simd.splat_u8x16(10)), 0)
14A copy of [v] with lane [i] (0-3) set to [x], rounded to binary32. [v] is unchanged.
Examples
march> Simd.replace_f32x4(Simd.splat_f32x4(0.0), 3, 2.5) == Simd.make_f32x4(0.0, 0.0, 0.0, 2.5)
trueA copy of [v] with lane [i] (0-1) set to [x].
Examples
march> Simd.extract_f64x2(Simd.replace_f64x2(Simd.splat_f64x2(0.0), 1, 2.5), 1)
2.5A copy of [v] with lane [i] (0-3) set to [x], wrapped to 32 bits.
Examples
march> Simd.replace_i32x4(Simd.splat_i32x4(0), 2, 7) == Simd.make_i32x4(0, 0, 7, 0)
trueA copy of [v] with lane [i] (0-1) set to [x].
Examples
march> Simd.replace_i64x2(Simd.splat_i64x2(0), 1, 42) == Simd.make_i64x2(0, 42)
trueA copy of [v] with lane [i] (0-15) set to [x] mod 256.
Examples
march> Simd.extract_u8x16(Simd.replace_u8x16(Simd.splat_u8x16(0), 15, 257), 15)
1Per-lane blend: where [mask]'s lane has its high (sign) bit set take [a]'s lane, else [b]'s lane.
Examples
march> let xs = Simd.make_f32x4(1.0, 5.0, 2.0, 9.0)
march> Simd.select_f32x4(Simd.gt_f32x4(xs, Simd.splat_f32x4(4.0)), Simd.splat_f32x4(4.0), xs) == Simd.make_f32x4(1.0, 4.0, 2.0, 4.0)
truePer-lane blend: where [mask]'s lane has its high (sign) bit set take [a]'s lane, else [b]'s lane.
Examples
march> Simd.select_f64x2(Simd.lt_f64x2(Simd.make_f64x2(1.0, 5.0), Simd.splat_f64x2(2.0)), Simd.splat_f64x2(0.0), Simd.make_f64x2(1.0, 5.0)) == Simd.make_f64x2(0.0, 5.0)
truePer-lane blend: where [mask]'s lane is negative (high bit set) take [a]'s lane, else [b]'s lane.
Examples
march> let xs = Simd.make_i32x4(1, 5, 2, 9)
march> Simd.select_i32x4(Simd.lt_i32x4(xs, Simd.splat_i32x4(4)), Simd.splat_i32x4(0), xs) == Simd.make_i32x4(0, 5, 0, 9)
truePer-lane blend: where [mask]'s lane is negative (high bit set) take [a]'s lane, else [b]'s lane.
Examples
march> Simd.select_i64x2(Simd.make_i64x2(-1, 0), Simd.splat_i64x2(1), Simd.splat_i64x2(2)) == Simd.make_i64x2(1, 2)
truePer-lane blend: where [mask]'s lane has bit 7 set (>= 128) take [a]'s lane, else [b]'s lane.
Examples
march> Simd.extract_u8x16(Simd.select_u8x16(Simd.splat_u8x16(128), Simd.splat_u8x16(1), Simd.splat_u8x16(2)), 0)
1
march> Simd.extract_u8x16(Simd.select_u8x16(Simd.splat_u8x16(127), Simd.splat_u8x16(1), Simd.splat_u8x16(2)), 0)
2Per-lane shift left by [n] mod 32 (the count is masked to its low 5 bits, so a negative or oversized count never panics); bits shifted out of the lane are lost.
Examples
march> Simd.shl_i32x4(Simd.make_i32x4(1, 3, -1, 0), 4) == Simd.make_i32x4(16, 48, -16, 0)
true
march> Simd.extract_i32x4(Simd.shl_i32x4(Simd.splat_i32x4(1), 33), 0)
2Per-lane shift left by [n] mod 64 (the count is masked to its low 6 bits); bits shifted out of the lane are lost.
Examples
march> Simd.shl_i64x2(Simd.make_i64x2(3, -1), 4) == Simd.make_i64x2(48, -16)
true
march> Simd.extract_i64x2(Simd.shl_i64x2(Simd.splat_i64x2(1), 65), 0)
2Per-lane arithmetic (sign-extending) shift right by [n] mod 32 (the count is masked to its low 5 bits).
Examples
march> Simd.shr_i32x4(Simd.make_i32x4(16, -8, -1, 7), 1) == Simd.make_i32x4(8, -4, -1, 3)
truePer-lane arithmetic (sign-extending) shift right by [n] mod 64 (the count is masked to its low 6 bits).
Examples
march> Simd.shr_i64x2(Simd.make_i64x2(-16, 16), 2) == Simd.make_i64x2(-4, 4)
trueAll four lanes set to [v], rounded to binary32 (nearest-even).
Examples
march> Simd.splat_f32x4(1.5) == Simd.make_f32x4(1.5, 1.5, 1.5, 1.5)
true
march> Simd.extract_f32x4(Simd.splat_f32x4(16777217.0), 0) == 16777216.0
trueBoth lanes set to [v].
Examples
march> Simd.splat_f64x2(2.5) == Simd.make_f64x2(2.5, 2.5)
trueAll four lanes set to [v], wrapped to 32 bits (two's complement).
Examples
march> Simd.splat_i32x4(7) == Simd.make_i32x4(7, 7, 7, 7)
trueBoth lanes set to [v].
Examples
march> Simd.splat_i64x2(-3) == Simd.make_i64x2(-3, -3)
trueAll sixteen lanes set to [v] mod 256 (so 300 becomes 44 and -1 becomes 255).
Examples
march> Simd.splat_u8x16(300) == Simd.make_u8x16(44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44)
true
march> Simd.extract_u8x16(Simd.splat_u8x16(-1), 0)
255Per-lane square root, rounded to binary32 (NaN for a negative lane).
Examples
march> (Simd.extract_f32x4(Simd.sqrt_f32x4(Simd.make_f32x4(9.0, 2.0, 4.0, 1.0)), 0)) == 3.0
truePer-lane square root (NaN for a negative lane).
Examples
march> (Simd.extract_f64x2(Simd.sqrt_f64x2(Simd.make_f64x2(16.0, 2.0)), 0)) == 4.0
trueStore [v]'s 4 lanes into the NativeF32Arr [arr] at elements [i] to [i] + 3, returning the updated array. Panics unless 0 <= [i] and [i] + 4 <= length.
Examples
march> NativeArray.to_list_f32(Simd.store_f32x4(NativeArray.make_f32(5, 0.5), 1, Simd.splat_f32x4(1.5)))
[0.5, 1.5, 1.5, 1.5, 1.5]Store [v]'s 2 lanes into the NativeFloatArr [arr] at elements [i] and [i] + 1, returning the updated array. Panics unless 0 <= [i] and [i] + 2 <= length.
Examples
march> NativeArray.to_list_float(Simd.store_f64x2(NativeArray.make_float(3, 0.5), 1, Simd.make_f64x2(1.5, 2.5)))
[0.5, 1.5, 2.5]Store [v]'s 4 lanes into the NativeI32Arr [arr] at elements [i] to [i] + 3, returning the updated array. Panics unless 0 <= [i] and [i] + 4 <= length.
Examples
march> NativeArray.to_list_i32(Simd.store_i32x4(NativeArray.make_i32(6, 0), 2, Simd.make_i32x4(1, 2, 3, 4)))
[0, 0, 1, 2, 3, 4]Store [v]'s 2 lanes into the NativeIntArr [arr] at elements [i] and [i] + 1, returning the updated array. Panics unless 0 <= [i] and [i] + 2 <= length.
Examples
march> NativeArray.to_list_int(Simd.store_i64x2(NativeArray.make_int(3, 0), 1, Simd.make_i64x2(8, 9)))
[0, 8, 9]Store [v]'s 16 lanes into the NativeU8Arr [arr] at elements [i] to [i] + 15, returning the updated array. Panics unless 0 <= [i] and [i] + 16 <= length.
Examples
march> List.take(NativeArray.to_list_u8(Simd.store_u8x16(NativeArray.make_u8(18, 0), 2, Simd.splat_u8x16(255))), 4)
[0, 0, 255, 255]Per-lane subtraction [a] - [b], rounded to binary32.
Examples
march> Simd.extract_f32x4(Simd.sub_f32x4(Simd.splat_f32x4(1.0), Simd.splat_f32x4(0.25)), 0)
0.75Per-lane subtraction [a] - [b].
Examples
march> Simd.sub_f64x2(Simd.make_f64x2(1.5, 2.0), Simd.splat_f64x2(4.0)) == Simd.make_f64x2(-2.5, -2.0)
truePer-lane subtraction [a] - [b], wrapping mod 2^32.
Examples
march> Simd.sub_i32x4(Simd.make_i32x4(10, 0, -5, 3), Simd.splat_i32x4(3)) == Simd.make_i32x4(7, -3, -8, 0)
truePer-lane subtraction [a] - [b], wrapping mod 2^64.
Examples
march> Simd.sub_i64x2(Simd.make_i64x2(4, -9), Simd.splat_i64x2(3)) == Simd.make_i64x2(1, -12)
trueHorizontal sum of all lanes, accumulated sequentially (lane 0 first) in double, so the result is not rounded back to binary32.
Examples
march> Simd.sum_f32x4(Simd.make_f32x4(1.5, 2.0, 3.0, 4.0))
10.5Horizontal sum of both lanes (lane 0 + lane 1).
Examples
march> Simd.sum_f64x2(Simd.make_f64x2(1.5, 2.25))
3.75Horizontal sum of all lanes, accumulated in i64, so the sum of four i32 lanes never wraps.
Examples
march> Simd.sum_i32x4(Simd.make_i32x4(1, 2, 3, 4))
10Horizontal sum of both lanes, wrapping mod 2^64.
Examples
march> Simd.sum_i64x2(Simd.make_i64x2(100, -30))
70Per-lane bitwise XOR of the lanes' binary32 bit patterns (XOR with -0.0 flips the sign bit).
Examples
march> (Simd.extract_f32x4(Simd.xor_f32x4(Simd.splat_f32x4(-2.0), Simd.splat_f32x4(-0.0)), 0)) == 2.0
truePer-lane bitwise XOR of the lanes' binary64 bit patterns (x XOR x is 0.0).
Examples
march> (Simd.extract_f64x2(Simd.xor_f64x2(Simd.splat_f64x2(1.0), Simd.splat_f64x2(1.0)), 0)) == 0.0
truePer-lane bitwise XOR.
Examples
march> Simd.extract_i32x4(Simd.xor_i32x4(Simd.splat_i32x4(12), Simd.splat_i32x4(10)), 0)
6Per-lane bitwise XOR.
Examples
march> Simd.xor_i64x2(Simd.make_i64x2(12, 10), Simd.splat_i64x2(10)) == Simd.make_i64x2(6, 0)
truePer-lane bitwise XOR.
Examples
march> Simd.extract_u8x16(Simd.xor_u8x16(Simd.splat_u8x16(12), Simd.splat_u8x16(10)), 0)
6