Overview
SIMD helpers for engine code. On Raya for arm64 (macOS, iOS, Android) every operation here compiles to one NEON instruction; on other runtimes, other targets and the web the same Raya code runs and gives the same result.
import 'package:riptide_simd/riptide_simd.ray';
final d = a.dot(b); // FMUL + FADDP + FADDP
final acc2 = a.fma(b, acc); // FMLA: a * b + acc, one rounding
final q = (v * k).clamp(lo, hi).round().toInt32x4Truncated(); // FRINTA + FCVTZS
final m = x.lessThan(y); // Float64x2 compare -> 64-bit lane mask
final r = m.selectF64(x, y); // BSL
final w = Float32x8.load(list, i) * Float32x8.splat(0.5); // two registers, no allocation
What's in it
| API | Raya arm64 | Portable body |
|---|---|---|
Float32x4.fma(b, c), Float64x2.fma(b, c) | FMLA (fused) | computed in double (see below) |
Float32x4.sum, .dot(b) | FADDP ×2 (+ FMUL) | the same pairwise order, (x+y)+(z+w) |
Float64x2.sum, .dot(b) | FADDP (+ FMUL) | x + y |
Float32x4.minLane, .maxLane | FMINV / FMAXV | shuffles + min/max |
floor, ceil, truncate, round (both float types) | FRINTM / FRINTP / FRINTZ / FRINTA | floorToDouble etc. per lane |
Float32x4.toInt32x4Truncated | FCVTZS (saturating, NaN → 0) | the same rule in Raya |
Int32x4.toFloat32x4Value | SCVTF | toDouble per lane |
Int32x4 * Int32x4, .equal, .greaterThan | MUL / CMEQ / CMGT | per lane |
Int32x4.shiftLeft(n), .shiftRightArithmetic(n), .shiftRightLogical(n) | SHL / SSHR / USHR when n is a constant | per lane |
Float64x2.lessThan … .notEqual | FCMGT / FCMGE / FCMEQ | per lane |
Int32x4.selectF64(t, f) | BSL | bitwise, through a scratch buffer |
Float32x4.lowToFloat64x2, .highToFloat64x2 | FCVTL / FCVTL2 | Float64x2.fromFloat32x4 |
Float32x8, Float64x4, Int32x8 | two Q registers (@pragma('raya:value'),) | immutable classes |
Results are bit-identical between Raya and the portable bodies, with two documented exceptions:
- fma: Raya rounds once (true fused multiply-add). The portable
Float32x4.fmacomputesa * b + cin double and rounds to float, which equals the fused result except in rare halfway cases (at most 1 ulp). The portableFloat64x2.fmais unfused (two roundings). - Lane min/max with NaN or 0.0 vs -0.0 are unspecified, exactly as for
Float32x4.min/maxtoday (the VM's runtime and compiled code already disagree there).
How it works
Each member carries @pragma('raya:simd', '<op>'). Raya's compiler replaces a call to a function with that pragma by one IL SimdOp when the signature matches the op; anything else (other runtimes, x64, the web, a tear-off) calls the Raya body. Raya also:
- Lowers the
raya:typed_dataoperations themselves to single instructions on arm64 (shuffles,shuffleMix,select,scale, conversions,signMask;v * c.shuffle(Float32x4.yyyy)becomes one multiply-by-element); - auto-vectorises element-wise
Float32List/Float64Listloops in AOT (for (i = 0; i < n; i++) out[i] = …, includingif/elseon doubles), four elements per iteration, with a scalar tail and bit-identical results.
Int8 lanes. Int32x4.sdot/udot (each lane += the dot product of its 4 bytes; one SDOT/UDOT) and smmla/ummla/usmmla (the accumulator as a 2 x 2 int32 matrix += A·Bᵀ of two 2 x 8 byte matrices; one SMMLA/UMMLA/USMMLA, 32 multiply-adds) treat the vector as 16 bytes, in the order of an Int32x4List view over an Int8List/Uint8List. SDOT/UDOT are on by default; the SMMLA family needs --raya-simd-i8mm at compile time (raya compile exe --extra-gen-snapshot-options=--raya-simd-i8mm), because M1 and A14 lack it. Measured on one M5 Pro core, all-pairs Gram 4,096 x 128: f32 fma 65 GOPS, sdot 156, smmla 279, exact.
So plain scalar typed-data code gets faster on Raya too; reach for riptide_simd for the operations Raya has no syntax for (fma, horizontal sums, rounding, integer conversions) and for 256-bit types.
Classes
SplitOSFloat32x4Ops
extension SplitOSFloat32x4Ops on Float32x4
Float32x4 operations.
Properties
Float64x2 get highToFloat64x2Lanes z and w as a Float64x2 (FCVTL2 on Raya, via a shuffle here).
Methods
Float32x4 fma(Float32x4 b, Float32x4 c)this * b + c per lane. On Raya arm64 it is fused (FMLA, one rounding); the portable body computes in double and rounds twice, which can differ from the fused result by 1 ulp in rare halfway cases.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x4(1.5, -2.25, 3.0, 0.5), b = Float32x4(2.0, 4.0, -1.0, 8.0);
final c = Float32x4(0.25, 0.25, 0.25, 0.25);
final r = a.fma(b, c);
print('a * b + c = ${[r.x, r.y, r.z, r.w]}');
}a * b + c = [3.25, -8.75, -2.75, 4.25]
double sum()(x + y) + (z + w), each addition rounded to float (FADDP twice).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x4(1.5, -2.25, 3.0, 0.5), b = Float32x4(2.0, 4.0, -1.0, 8.0);
print('sum of a = ${a.sum()}');
print('sum of (0.1, 0.2, 0.3, 0.4) in float32 = ${Float32x4(0.1, 0.2, 0.3, 0.4).sum()}');
}sum of a = 2.75 sum of (0.1, 0.2, 0.3, 0.4) in float32 = 1.0
double dot(Float32x4 b)The dot product: (this * b).sum.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x4(1.5, -2.25, 3.0, 0.5), b = Float32x4(2.0, 4.0, -1.0, 8.0);
print('a · b = ${a.dot(b)}');
print('a · a = ${a.dot(a)}');
}a · b = -5.0 a · a = 16.5625
double minLane()The smallest lane (FMINV). NaN and 0.0 vs -0.0 are unspecified, as for Float32x4.min.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x4(1.5, -2.25, 3.0, 0.5), b = Float32x4(2.0, 4.0, -1.0, 8.0);
print('smallest lane of a: ${a.minLane()}');
print('of b: ${b.minLane()}');
}smallest lane of a: -2.25 of b: -1.0
double maxLane()The largest lane (FMAXV). NaN and 0.0 vs -0.0 are unspecified, as for Float32x4.max.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x4(1.5, -2.25, 3.0, 0.5), b = Float32x4(2.0, 4.0, -1.0, 8.0);
print('largest lane of a: ${a.maxLane()}');
print('of b: ${b.maxLane()}');
}largest lane of a: 3.0 of b: 8.0
Float32x4 floor()double.floorToDouble per lane (FRINTM).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x4(-1.5, -0.5, 0.5, 2.5);
final r = v.floor();
print('floor(-1.5, -0.5, 0.5, 2.5) = ${[r.x, r.y, r.z, r.w]}');
}floor(-1.5, -0.5, 0.5, 2.5) = [-2.0, -1.0, 0.0, 2.0]
Float32x4 ceil()double.ceilToDouble per lane (FRINTP).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x4(-1.5, -0.5, 0.5, 2.5);
final r = v.ceil();
print('ceil(-1.5, -0.5, 0.5, 2.5) = ${[r.x, r.y, r.z, r.w]}');
}ceil(-1.5, -0.5, 0.5, 2.5) = [-1.0, -0.0, 1.0, 3.0]
Float32x4 truncate()double.truncateToDouble per lane (FRINTZ).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x4(-1.5, -0.5, 0.5, 2.5);
final r = v.truncate();
print('truncate(-1.5, -0.5, 0.5, 2.5) = ${[r.x, r.y, r.z, r.w]}');
}truncate(-1.5, -0.5, 0.5, 2.5) = [-1.0, -0.0, 0.0, 2.0]
Float32x4 round()double.roundToDouble per lane, halves away from zero (FRINTA).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x4(-1.5, -0.5, 0.5, 2.5);
final r = v.round();
print('round(-1.5, -0.5, 0.5, 2.5) = ${[r.x, r.y, r.z, r.w]}');
}round(-1.5, -0.5, 0.5, 2.5) = [-2.0, -1.0, 1.0, 3.0]
Int32x4 toInt32x4Truncated()Each lane converted to an int32, rounding toward zero; out-of-range lanes saturate and NaN becomes 0 (FCVTZS). Unlike Float32x4 → Int32x4 constructors, this converts values, not bits.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x4(-2.7, 3.9, 1e10, double.nan);
final i = v.toInt32x4Truncated();
print('values: ${[i.x, i.y, i.z, i.w]}');
print('bits instead (fromFloat32x4Bits): ${Int32x4.fromFloat32x4Bits(Float32x4(1.0, 0, 0, 0)).x}');
}values: [-2, 3, 2147483647, 0] bits instead (fromFloat32x4Bits): 1065353216
SplitOSFloat64x2Ops
extension SplitOSFloat64x2Ops on Float64x2
Float64x2 operations.
Methods
Float64x2 fma(Float64x2 b, Float64x2 c)this * b + c per lane. Fused on Raya arm64 (FMLA); the portable body is unfused (two roundings).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.5, -2.0), b = Float64x2(3.0, 0.25);
final r = a.fma(b, Float64x2(1.0, 1.0));
print('a * b + 1 = ${[r.x, r.y]}');
}a * b + 1 = [5.5, 0.5]
double sum()x + y (FADDP).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.5, -2.0), b = Float64x2(3.0, 0.25);
print('sum = ${a.sum()}');
print('0.1 + 0.2 = ${Float64x2(0.1, 0.2).sum()}');
}sum = -0.5 0.1 + 0.2 = 0.30000000000000004
double dot(Float64x2 b)x * b.x + y * b.y, products rounded before the sum.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.5, -2.0), b = Float64x2(3.0, 0.25);
print('a · b = ${a.dot(b)}');
}a · b = 4.0
Float64x2 floor()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float64x2(-2.5, 2.5);
final r = v.floor();
print('floor(-2.5, 2.5) = ${[r.x, r.y]}');
print('floor(0.49, -0.51) = ${[Float64x2(0.49, -0.51).floor().x, Float64x2(0.49, -0.51).floor().y]}');
}floor(-2.5, 2.5) = [-3.0, 2.0] floor(0.49, -0.51) = [0.0, -1.0]
Float64x2 ceil()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float64x2(-2.5, 2.5);
final r = v.ceil();
print('ceil(-2.5, 2.5) = ${[r.x, r.y]}');
print('ceil(0.49, -0.51) = ${[Float64x2(0.49, -0.51).ceil().x, Float64x2(0.49, -0.51).ceil().y]}');
}ceil(-2.5, 2.5) = [-2.0, 3.0] ceil(0.49, -0.51) = [1.0, -0.0]
Float64x2 truncate()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float64x2(-2.5, 2.5);
final r = v.truncate();
print('truncate(-2.5, 2.5) = ${[r.x, r.y]}');
print('truncate(0.49, -0.51) = ${[Float64x2(0.49, -0.51).truncate().x, Float64x2(0.49, -0.51).truncate().y]}');
}truncate(-2.5, 2.5) = [-2.0, 2.0] truncate(0.49, -0.51) = [0.0, -0.0]
Float64x2 round()Halves away from zero.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float64x2(-2.5, 2.5);
final r = v.round();
print('round(-2.5, 2.5) = ${[r.x, r.y]}');
print('round(0.49, -0.51) = ${[Float64x2(0.49, -0.51).round().x, Float64x2(0.49, -0.51).round().y]}');
}round(-2.5, 2.5) = [-3.0, 3.0] round(0.49, -0.51) = [0.0, -1.0]
Int32x4 equal(Float64x2 b)Lane masks: Int32x4 lanes x and y hold lane x's result (all ones when true), z and w lane y's. Use with SplitOSInt32x4Ops.selectF64.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.0, 5.0), b = Float64x2(1.0, 3.0);
final m = a.equal(b);
print('mask lanes: ${[m.x, m.y, m.z, m.w]}');
// Pick a where the test holds, else b.
final r = m.selectF64(a, b);
print('selected: ${[r.x, r.y]}');
}mask lanes: [-1, -1, 0, 0] selected: [1.0, 3.0]
Int32x4 notEqual(Float64x2 b)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.0, 5.0), b = Float64x2(1.0, 3.0);
final m = a.notEqual(b);
print('mask lanes: ${[m.x, m.y, m.z, m.w]}');
// Pick a where the test holds, else b.
final r = m.selectF64(a, b);
print('selected: ${[r.x, r.y]}');
}mask lanes: [0, 0, -1, -1] selected: [1.0, 5.0]
Int32x4 greaterThan(Float64x2 b)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.0, 5.0), b = Float64x2(1.0, 3.0);
final m = a.greaterThan(b);
print('mask lanes: ${[m.x, m.y, m.z, m.w]}');
// Pick a where the test holds, else b.
final r = m.selectF64(a, b);
print('selected: ${[r.x, r.y]}');
}mask lanes: [0, 0, -1, -1] selected: [1.0, 5.0]
Int32x4 greaterThanOrEqual(Float64x2 b)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.0, 5.0), b = Float64x2(1.0, 3.0);
final m = a.greaterThanOrEqual(b);
print('mask lanes: ${[m.x, m.y, m.z, m.w]}');
// Pick a where the test holds, else b.
final r = m.selectF64(a, b);
print('selected: ${[r.x, r.y]}');
}mask lanes: [-1, -1, -1, -1] selected: [1.0, 5.0]
Int32x4 lessThan(Float64x2 b)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.0, 5.0), b = Float64x2(1.0, 3.0);
final m = a.lessThan(b);
print('mask lanes: ${[m.x, m.y, m.z, m.w]}');
// Pick a where the test holds, else b.
final r = m.selectF64(a, b);
print('selected: ${[r.x, r.y]}');
}mask lanes: [0, 0, 0, 0] selected: [1.0, 3.0]
Int32x4 lessThanOrEqual(Float64x2 b)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(1.0, 5.0), b = Float64x2(1.0, 3.0);
final m = a.lessThanOrEqual(b);
print('mask lanes: ${[m.x, m.y, m.z, m.w]}');
// Pick a where the test holds, else b.
final r = m.selectF64(a, b);
print('selected: ${[r.x, r.y]}');
}mask lanes: [-1, -1, 0, 0] selected: [1.0, 3.0]
SplitOSInt32x4Ops
extension SplitOSInt32x4Ops on Int32x4
Int32x4 operations.
Methods
Float32x4 toFloat32x4Value()Each lane converted to a float (SCVTF). Unlike Float32x4.fromInt32x4Bits, this converts values, not bits.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final i = Int32x4(-3, 0, 7, 16777217);
final f = i.toFloat32x4Value();
print('as floats: ${[f.x, f.y, f.z, f.w]}');
print('16777217 rounds to the nearest float32');
}as floats: [-3.0, 0.0, 7.0, 16777216.0] 16777217 rounds to the nearest float32
Int32x4 equal(Int32x4 b)All ones where lanes are equal (CMEQ).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x4(1, 5, -3, 7), b = Int32x4(1, 2, -3, 9);
final m = a.equal(b);
print('equal mask: ${[m.x, m.y, m.z, m.w]}');
}equal mask: [-1, 0, -1, 0]
Int32x4 greaterThan(Int32x4 b)All ones where this lane is greater, signed (CMGT).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x4(1, 5, -3, 7), b = Int32x4(1, 2, -3, 9);
final m = a.greaterThan(b);
print('a > b mask: ${[m.x, m.y, m.z, m.w]}');
}a > b mask: [0, -1, 0, 0]
Int32x4 shiftLeft(int n)Shift left by n (0-31). One SHL when n is a constant.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Int32x4(1, -8, 0x40000000, -1);
final r = v.shiftLeft(2);
print('<< 2: ${[r.x, r.y, r.z, r.w]} (wraps to 32 bits)');
}<< 2: [4, -32, 0, -4] (wraps to 32 bits)
Int32x4 shiftRightArithmetic(int n)Arithmetic shift right by n (0-31). One SSHR when n is a constant.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Int32x4(1, -8, 0x40000000, -1);
final r = v.shiftRightArithmetic(2);
print('>> 2: ${[r.x, r.y, r.z, r.w]} (sign kept)');
}>> 2: [0, -2, 268435456, -1] (sign kept)
Int32x4 shiftRightLogical(int n)Logical shift right by n (0-31). One USHR when n is a constant.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Int32x4(1, -8, 0x40000000, -1);
final r = v.shiftRightLogical(2);
print('>>> 2: ${[r.x, r.y, r.z, r.w]} (zeros shifted in)');
}>>> 2: [0, 1073741822, 268435456, 1073741823] (zeros shifted in)
Int32x4 sdot(Int32x4 a, Int32x4 b)Each lane plus the dot product of its 4 signed bytes in a and b (SDOT). On by default in Raya (--raya-simd-dotprod; every Apple chip from A13 and M1).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
int pack(List<int> b) => (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24;
void main() {
// Each lane holds 4 bytes; the result adds the 4-byte dot product to the accumulator lane.
final a = Int32x4(pack([1, 2, 3, 4]), pack([-1, -1, -1, -1]), pack([100, 0, 0, 0]), pack([127, 127, 127, 127]));
final b = Int32x4(pack([1, 1, 1, 1]), pack([2, 3, 4, 5]), pack([100, 0, 0, 0]), pack([127, 127, 127, 127]));
final r = Int32x4(10, 0, 0, 0).sdot(a, b);
print('signed dot + acc: ${[r.x, r.y, r.z, r.w]}');
}signed dot + acc: [20, -14, 10000, 64516]
Int32x4 udot(Int32x4 a, Int32x4 b)sdot with unsigned bytes (UDOT).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
int pack(List<int> b) => (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24;
void main() {
// Each lane holds 4 bytes; the result adds the 4-byte dot product to the accumulator lane.
final a = Int32x4(pack([1, 2, 3, 4]), pack([-1, -1, -1, -1]), pack([100, 0, 0, 0]), pack([127, 127, 127, 127]));
final b = Int32x4(pack([1, 1, 1, 1]), pack([2, 3, 4, 5]), pack([100, 0, 0, 0]), pack([127, 127, 127, 127]));
final r = Int32x4(10, 0, 0, 0).udot(a, b);
print('unsigned dot + acc: ${[r.x, r.y, r.z, r.w]}');
}unsigned dot + acc: [20, 3570, 10000, 64516]
Int32x4 smmla(Int32x4 a, Int32x4 b)This as a 2 x 2 int32 matrix (x y / z w) plus A·Bᵀ, where a and b are 2 x 8 signed byte matrices (row r = bytes 8r.. 8r + 7): 32 multiply-adds in one SMMLA. Raya replaces it only with --raya-simd-i8mm (A15/M2 and later); otherwise this body runs.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
int pack(List<int> b) => (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24;
void main() {
// a and b are 2 × 8 byte matrices: row r is bytes 8r..8r+7 (lanes 2r and 2r+1).
final a = Int32x4(pack([1, 2, 3, 4]), pack([5, 6, 7, 8]), pack([1, 1, 1, 1]), pack([1, 1, 1, 1]));
final b = Int32x4(pack([1, 0, 0, 0]), pack([0, 0, 0, 1]), pack([-1, -1, -1, -1]), pack([-1, -1, -1, -1]));
final c = Int32x4(0, 0, 0, 0).smmla(a, b);
print('C = A·Bᵀ (signed × signed): [[${c.x}, ${c.y}], [${c.z}, ${c.w}]]');
}C = A·Bᵀ (signed × signed): [[9, -36], [2, -8]]
Int32x4 ummla(Int32x4 a, Int32x4 b)smmla with unsigned bytes (UMMLA).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
int pack(List<int> b) => (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24;
void main() {
// a and b are 2 × 8 byte matrices: row r is bytes 8r..8r+7 (lanes 2r and 2r+1).
final a = Int32x4(pack([1, 2, 3, 4]), pack([5, 6, 7, 8]), pack([1, 1, 1, 1]), pack([1, 1, 1, 1]));
final b = Int32x4(pack([1, 0, 0, 0]), pack([0, 0, 0, 1]), pack([-1, -1, -1, -1]), pack([-1, -1, -1, -1]));
final c = Int32x4(0, 0, 0, 0).ummla(a, b);
print('C = A·Bᵀ (unsigned × unsigned): [[${c.x}, ${c.y}], [${c.z}, ${c.w}]]');
}C = A·Bᵀ (unsigned × unsigned): [[9, 9180], [2, 2040]]
Int32x4 usmmla(Int32x4 a, Int32x4 b)smmla with a unsigned and b signed (USMMLA).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
int pack(List<int> b) => (b[0] & 0xff) | (b[1] & 0xff) << 8 | (b[2] & 0xff) << 16 | (b[3] & 0xff) << 24;
void main() {
// a and b are 2 × 8 byte matrices: row r is bytes 8r..8r+7 (lanes 2r and 2r+1).
final a = Int32x4(pack([1, 2, 3, 4]), pack([5, 6, 7, 8]), pack([1, 1, 1, 1]), pack([1, 1, 1, 1]));
final b = Int32x4(pack([1, 0, 0, 0]), pack([0, 0, 0, 1]), pack([-1, -1, -1, -1]), pack([-1, -1, -1, -1]));
final c = Int32x4(0, 0, 0, 0).usmmla(a, b);
print('C = A·Bᵀ (unsigned × signed): [[${c.x}, ${c.y}], [${c.z}, ${c.w}]]');
}C = A·Bᵀ (unsigned × signed): [[9, -36], [2, -8]]
Float64x2 selectF64(Float64x2 t, Float64x2 f)Bitwise select of two Float64x2 by this mask (BSL): bits of t where the mask is set, of f elsewhere. Masks come from the Float64x2 comparisons in SplitOSFloat64x2Ops.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x2(-1.5, 2.5), zero = Float64x2(0, 0);
// max(a, 0) per lane: a mask from a comparison picks lanes bit by bit.
final r = a.greaterThan(zero).selectF64(a, zero);
print('max(a, 0) = ${[r.x, r.y]}');
}max(a, 0) = [0.0, 2.5]
Operators
Int32x4 operator *(Int32x4 b)Lane-wise multiply, wrapping to 32 bits (MUL).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x4(3, -4, 65536, 2147483647), b = Int32x4(5, 6, 65536, 2);
final r = a * b;
print('a * b = ${[r.x, r.y, r.z, r.w]} (wraps to 32 bits)');
}a * b = [15, -24, 0, -2] (wraps to 32 bits)
Float32x8
final class Float32x8
Constructors
const Float32x8.fromHalves(this.lo, this.hi)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8.fromHalves(Float32x4(1, 2, 3, 4), Float32x4(5, 6, 7, 8));
print('$v');
print('lo.x = ${v.lo.x}, hi.w = ${v.hi.w}');
}Float32x8(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0) lo.x = 1.0, hi.w = 8.0
Float32x8(double l0, double l1, double l2, double l3, double l4, double l5, double l6, double l7)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8(0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4);
print('$v');
print('lane 5: ${v[5]}');
}Float32x8(0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0) lane 5: 3.0
Float32x8.splat(double v)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8.splat(0.1);
print(v.toList());
print('0.1 in float32 is ${v[0]}');
}[0.10000000149011612, 0.10000000149011612, 0.10000000149011612, 0.10000000149011612, 0.10000000149011612, 0.10000000149011612, 0.10000000149011612, 0.10000000149011612] 0.1 in float32 is 0.10000000149011612
Float32x8.zero()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8.zero();
print('$v, sum ${v.sum()}');
}Float32x8(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0), sum 0.0
factory Float32x8.load(Float32x4List list, int index)Lanes 8 * index.. 8 * index + 7 of list (two Float32x4 loads).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final data = Float32x4List.fromList([for (var i = 0; i < 4; i++) Float32x4(4.0 * i, 4.0 * i + 1, 4.0 * i + 2, 4.0 * i + 3)]);
final v = Float32x8.load(data, 1); // lanes 8..15
print('block 1: ${v.toList()}');
}block 1: [8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0]
Properties
final Float32x4 lofinal Float32x4 hiint get hashCodeMethods
void store(Float32x4List list, int index)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final out = Float32x4List(4);
Float32x8.splat(2).store(out, 0);
(Float32x8.splat(2) * Float32x8(1, 2, 3, 4, 5, 6, 7, 8)).store(out, 1);
print([for (final q in out) [q.x, q.y, q.z, q.w]]);
}[[2.0, 2.0, 2.0, 2.0], [2.0, 2.0, 2.0, 2.0], [2.0, 4.0, 6.0, 8.0], [10.0, 12.0, 14.0, 16.0]]
Float32x8 scale(double s)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('a × 0.5 = ${a.scale(0.5).toList()}');
}a × 0.5 = [0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0]
Float32x8 min(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('min(a, b) = ${a.min(b).toList()}');
}min(a, b) = [1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0]
Float32x8 max(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('max(a, b) = ${a.max(b).toList()}');
}max(a, b) = [8.0, 7.0, 6.0, 5.0, 5.0, 6.0, 7.0, 8.0]
Float32x8 abs()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8(-1, 2, -3, 4, -5, 6, -7, 8);
print('|v| = ${v.abs().toList()}');
}|v| = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]
Float32x8 sqrt()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8(0, 1, 2, 4, 9, 16, 0.25, 2.25);
print('√v = ${v.sqrt().toList()}');
}√v = [0.0, 1.0, 1.4142135381698608, 2.0, 3.0, 4.0, 0.5, 1.5]
Float32x8 fma(Float32x8 b, Float32x8 c)this * b + c, fused on Raya arm64 (see SplitOSFloat32x4Ops.fma).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final r = a.fma(b, Float32x8.splat(1));
print('a·b + 1 = ${r.toList()}');
}a·b + 1 = [9.0, 15.0, 19.0, 21.0, 21.0, 19.0, 15.0, 9.0]
double sum()lo.sum + hi.sum, rounded to float.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('sum of a = ${a.sum()}');
}sum of a = 36.0
double dot(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('a · b = ${a.dot(b)}');
print('a · a = ${a.dot(a)}');
}a · b = 120.0 a · a = 204.0
Int32x8 lessThan(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final m = a.lessThan(b);
print('mask: ${m.toList()}');
print('signMask: ${m.signMask.toRadixString(2).padLeft(8, '0')}');
print('picked: ${m.select(a, b).toList()}');
}mask: [-1, -1, -1, -1, 0, 0, 0, 0] signMask: 00001111 picked: [1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0]
Int32x8 lessThanOrEqual(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final m = a.lessThanOrEqual(b);
print('mask: ${m.toList()}');
print('signMask: ${m.signMask.toRadixString(2).padLeft(8, '0')}');
print('picked: ${m.select(a, b).toList()}');
}mask: [-1, -1, -1, -1, 0, 0, 0, 0] signMask: 00001111 picked: [1.0, 2.0, 3.0, 4.0, 4.0, 3.0, 2.0, 1.0]
Int32x8 greaterThan(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final m = a.greaterThan(b);
print('mask: ${m.toList()}');
print('signMask: ${m.signMask.toRadixString(2).padLeft(8, '0')}');
print('picked: ${m.select(a, b).toList()}');
}mask: [0, 0, 0, 0, -1, -1, -1, -1] signMask: 11110000 picked: [8.0, 7.0, 6.0, 5.0, 5.0, 6.0, 7.0, 8.0]
Int32x8 greaterThanOrEqual(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final m = a.greaterThanOrEqual(b);
print('mask: ${m.toList()}');
print('signMask: ${m.signMask.toRadixString(2).padLeft(8, '0')}');
print('picked: ${m.select(a, b).toList()}');
}mask: [0, 0, 0, 0, -1, -1, -1, -1] signMask: 11110000 picked: [8.0, 7.0, 6.0, 5.0, 5.0, 6.0, 7.0, 8.0]
Int32x8 equal(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final m = a.equal(b);
print('mask: ${m.toList()}');
print('signMask: ${m.signMask.toRadixString(2).padLeft(8, '0')}');
print('picked: ${m.select(a, b).toList()}');
}mask: [0, 0, 0, 0, 0, 0, 0, 0] signMask: 00000000 picked: [8.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0]
List<double> toList()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float32x8(1, 2, 3, 4, 5, 6, 7, 8) * Float32x8.splat(0.5);
final l = v.toList();
print('$l (${l.length} lanes)');
}[0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0] (8 lanes)
String toString()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float32x8(1, -2, 3.5, 0, 0, 0, 0, 1e-3));
}Float32x8(1.0, -2.0, 3.5, 0.0, 0.0, 0.0, 0.0, 0.0010000000474974513)
Operators
Float32x8 operator +(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final r = a + b;
print('a + b = ${r.toList()}');
}a + b = [9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0]
Float32x8 operator -(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final r = a - b;
print('a - b = ${r.toList()}');
}a - b = [-7.0, -5.0, -3.0, -1.0, 1.0, 3.0, 5.0, 7.0]
Float32x8 operator *(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final r = a * b;
print('a * b = ${r.toList()}');
}a * b = [8.0, 14.0, 18.0, 20.0, 20.0, 18.0, 14.0, 8.0]
Float32x8 operator /(Float32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
final r = a / b;
print('a / b = ${r.toList()}');
}a / b = [0.125, 0.2857142984867096, 0.5, 0.800000011920929, 1.25, 2.0, 3.5, 8.0]
Float32x8 operator -()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('−a = ${(-a).toList()}');
}−a = [-1.0, -2.0, -3.0, -4.0, -5.0, -6.0, -7.0, -8.0]
double operator [](int i)Lane i (0-7).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float32x8(1, 2, 3, 4, 5, 6, 7, 8), b = Float32x8(8, 7, 6, 5, 4, 3, 2, 1);
print('a[0] = ${a[0]}, a[3] = ${a[3]}, a[4] = ${a[4]}, a[7] = ${a[7]}');
}a[0] = 1.0, a[3] = 4.0, a[4] = 5.0, a[7] = 8.0
bool operator ==(Object other)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float32x8.splat(1) == Float32x8(1, 1, 1, 1, 1, 1, 1, 1));
print(Float32x8.splat(1) == Float32x8.zero());
}true false
Float64x4
final class Float64x4
Constructors
const Float64x4.fromHalves(this.lo, this.hi)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float64x4.fromHalves(Float64x2(1, 2), Float64x2(3, 4));
print('$v');
}Float64x4(1.0, 2.0, 3.0, 4.0)
Float64x4(double l0, double l1, double l2, double l3)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final v = Float64x4(0.1, 0.2, 0.3, 0.4);
print('$v, sum ${v.sum()}');
}Float64x4(0.1, 0.2, 0.3, 0.4), sum 1.0
Float64x4.splat(double v)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float64x4.splat(0.1).toList());
}[0.1, 0.1, 0.1, 0.1]
Float64x4.zero()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float64x4.zero());
}Float64x4(0.0, 0.0, 0.0, 0.0)
factory Float64x4.load(Float64x2List list, int index)Lanes 4 * index.. 4 * index + 3 of list.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final data = Float64x2List.fromList([Float64x2(0, 1), Float64x2(2, 3), Float64x2(4, 5), Float64x2(6, 7)]);
print('block 1: ${Float64x4.load(data, 1).toList()}');
}block 1: [4.0, 5.0, 6.0, 7.0]
factory Float64x4.fromFloat32x4(Float32x4 v)Four floats widened to doubles (FCVTL + FCVTL2 on Raya arm64).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final f = Float32x4(0.1, 0.2, 0.3, 0.4);
final d = Float64x4.fromFloat32x4(f);
print('widened: ${d.toList()}');
print('the float32 value of 0.1 differs from 0.1 by ${(d.toList()[0] - 0.1).abs()}');
}widened: [0.10000000149011612, 0.20000000298023224, 0.30000001192092896, 0.4000000059604645] the float32 value of 0.1 differs from 0.1 by 1.4901161138336505e-9
Properties
final Float64x2 lofinal Float64x2 hiint get hashCodeMethods
void store(Float64x2List list, int index)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final out = Float64x2List(2);
Float64x4(1, 2, 3, 4).scale(10).store(out, 0);
print([for (final p in out) [p.x, p.y]]);
}[[10.0, 20.0], [30.0, 40.0]]
Float64x4 scale(double s)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a × 3 = ${a.scale(3).toList()}');
}a × 3 = [3.0, 6.0, 9.0, 12.0]
Float64x4 min(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('min = ${a.min(b).toList()}');
}min = [0.5, -1.0, 2.0, 4.0]
Float64x4 max(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('max = ${a.max(b).toList()}');
}max = [1.0, 2.0, 3.0, 8.0]
Float64x4 abs()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float64x4(-1.5, 2, -0.0, -8).abs().toList());
}[1.5, 2.0, 0.0, 8.0]
Float64x4 sqrt()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float64x4(2, 4, 9, 0.25).sqrt().toList());
}[1.4142135623730951, 2.0, 3.0, 0.5]
Float64x4 fma(Float64x4 b, Float64x4 c)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a·b + 1 = ${a.fma(b, Float64x4.splat(1)).toList()}');
}a·b + 1 = [1.5, -1.0, 7.0, 33.0]
double sum()(l0 + l2) + (l1 + l3).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('sum = ${a.sum()}');
}sum = 10.0
double dot(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a · b = ${a.dot(b)}');
}a · b = 36.5
Float32x4 toFloat32x4()The four lanes narrowed to floats.
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final f = Float64x4(0.1, 1 / 3, 1e40, -2).toFloat32x4();
print('narrowed: ${[f.x, f.y, f.z, f.w]}');
}narrowed: [0.10000000149011612, 0.3333333432674408, Infinity, -2.0]
List<double> toList()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print(a.toList());
}[1.0, 2.0, 3.0, 4.0]
String toString()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float64x4(1, 0.5, -2, 1e-9));
}Float64x4(1.0, 0.5, -2.0, 1e-9)
Operators
Float64x4 operator +(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a + b = ${(a + b).toList()}');
}a + b = [1.5, 1.0, 5.0, 12.0]
Float64x4 operator -(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a - b = ${(a - b).toList()}');
}a - b = [0.5, 3.0, 1.0, -4.0]
Float64x4 operator *(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a * b = ${(a * b).toList()}');
}a * b = [0.5, -2.0, 6.0, 32.0]
Float64x4 operator /(Float64x4 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('a / b = ${(a / b).toList()}');
}a / b = [2.0, -2.0, 1.5, 0.5]
Float64x4 operator -()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Float64x4(1, 2, 3, 4), b = Float64x4(0.5, -1, 2, 8);
print('−a = ${(-a).toList()}');
}−a = [-1.0, -2.0, -3.0, -4.0]
bool operator ==(Object other)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
print(Float64x4(1, 2, 3, 4) == Float64x4(1, 2, 3, 4));
print(Float64x4(1, 2, 3, 4) == Float64x4(1, 2, 3, 5));
}true false
Int32x8
final class Int32x8
Eight int32 lanes or a Float32x8 comparison mask.
Constructors
const Int32x8.fromHalves(this.lo, this.hi)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
print('$a');
}Int32x8(1, 2, 3, 4, 5, 6, 7, 8)
Properties
final Int32x4 lofinal Int32x4 hiint get hashCodeMethods
Float32x8 select(Float32x8 t, Float32x8 f)Lanes of t where the mask is set, of f elsewhere (BSL per half).
import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final x = Float32x8(-3, 1, -2, 4, 0, -1, 5, -6);
final mask = x.greaterThan(Float32x8.zero());
final relu = mask.select(x, Float32x8.zero());
print('max(x, 0) = ${relu.toList()}');
}max(x, 0) = [0.0, 1.0, 0.0, 4.0, 0.0, 0.0, 5.0, 0.0]
List<int> toList()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
print(a.toList());
}[1, 2, 3, 4, 5, 6, 7, 8]
String toString()import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
print(a * b);
}Int32x8(8, 14, 18, 20, 20, 18, 14, 8)
Operators
Int32x8 operator &(Int32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
final r = a & b;
print('a & b = ${r.toList()}');
}a & b = [0, 2, 2, 4, 4, 2, 2, 0]
Int32x8 operator |(Int32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
final r = a | b;
print('a | b = ${r.toList()}');
}a | b = [9, 7, 7, 5, 5, 7, 7, 9]
Int32x8 operator ^(Int32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
final r = a ^ b;
print('a ^ b = ${r.toList()}');
}a ^ b = [9, 5, 5, 1, 1, 5, 5, 9]
Int32x8 operator +(Int32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
final r = a + b;
print('a + b = ${r.toList()}');
}a + b = [9, 9, 9, 9, 9, 9, 9, 9]
Int32x8 operator -(Int32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
final r = a - b;
print('a - b = ${r.toList()}');
}a - b = [-7, -5, -3, -1, 1, 3, 5, 7]
Int32x8 operator *(Int32x8 o)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
final r = a * b;
print('a * b = ${r.toList()}');
}a * b = [8, 14, 18, 20, 20, 18, 14, 8]
bool operator ==(Object other)import 'package:riptide_simd/riptide_simd.ray';
import 'raya:convert';
import 'raya:typed_data';
void main() {
final a = Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8));
final b = Int32x8.fromHalves(Int32x4(8, 7, 6, 5), Int32x4(4, 3, 2, 1));
print(a == Int32x8.fromHalves(Int32x4(1, 2, 3, 4), Int32x4(5, 6, 7, 8)));
print(a == b);
}true false