Skip to content

SIMD Types

SIMD (Single Instruction, Multiple Data) types are 128-bit vector primitives that operate on multiple values in a single instruction. On x86-64 the backend lowers them to SSE/SSE2/SSE3/SSE4.1/FMA3 instructions; on ARM64 (Apple Silicon, Android, AArch64 servers) the same operations lower to NEON. The IL is platform-agnostic — every SIMD operation has equivalents on both backends, so the same source runs unchanged across architectures.

Types

All SIMD types are 128-bit (16-byte), stack-allocated with 16-byte alignment:

TypeLanesElement
float32x4432-bit float
float64x2264-bit float
int8x1616signed 8-bit int
int16x88signed 16-bit int
int32x44signed 32-bit int
int64x22signed 64-bit int
uint8x1616unsigned 8-bit int
uint16x88unsigned 16-bit int
uint32x44unsigned 32-bit int
uint64x22unsigned 64-bit int

SIMD types are global primitives — no using directive is needed to use them.

Construction

Broadcast (scalar to all lanes)

float32x4 v = float32x4(1.0); // [1.0, 1.0, 1.0, 1.0]
int32x4 w = int32x4(42); // [42, 42, 42, 42]
float64x2 d = float64x2(3.14); // [3.14, 3.14]

Per-element

float32x4 v = float32x4(1.0, 2.0, 3.0, 4.0);
float64x2 d = float64x2(1.0, 2.0);
int32x4 w = int32x4(10, 20, 30, 40);
int64x2 q = int64x2(100, 200);

Operators

All SIMD types support element-wise arithmetic:

float32x4 a = float32x4(1.0, 2.0, 3.0, 4.0);
float32x4 b = float32x4(10.0, 20.0, 30.0, 40.0);
float32x4 c = a + b; // [11.0, 22.0, 33.0, 44.0]
float32x4 d = a - b; // [-9.0, -18.0, -27.0, -36.0]
float32x4 e = a * b; // [10.0, 40.0, 90.0, 160.0]
float32x4 f = a / b; // division (float types only)
float32x4 neg = -a; // unary negation

Bitwise operations

int32x4 a = int32x4(0xFF, 0xF0, 0x0F, 0xFF);
int32x4 b = int32x4(0x0F, 0x0F, 0x0F, 0x0F);
int32x4 c = a & b; // AND
int32x4 d = a | b; // OR
int32x4 e = a ^ b; // XOR

Comparisons

Comparisons return a lane mask (all bits set for true, zero for false):

float32x4 mask = a == b;
float32x4 mask = a < b;

SIMD Namespace Functions

The SIMD namespace (under Core) provides utility functions. Access them with using Core;:

using Core;
float32x4 a = float32x4(4.0, 9.0, 16.0, 25.0);
float32x4 b = SIMD.Sqrt(a); // [2.0, 3.0, 4.0, 5.0]

Unary

FunctionDescriptionTypes
SIMD.Sqrt(a)Square rootfloat only
SIMD.Abs(a)Absolute valueall
SIMD.Not(a)Bitwise complementall
SIMD.Reciprocal(a)Approximate 1/afloat32 only
SIMD.ReciprocalSqrt(a)Approximate 1/sqrt(a)float32 only

Binary

FunctionDescriptionTypes
SIMD.Min(a, b)Element-wise minimumall
SIMD.Max(a, b)Element-wise maximumall
SIMD.AndNot(a, b)~a & ball
SIMD.DotProduct(a, b)Dot productfloat only

Ternary

FunctionDescriptionTypes
SIMD.FMA(a, b, c)Fused multiply-add: a*b+cfloat only
SIMD.FMS(a, b, c)Fused multiply-subtract: a*b-cfloat only
SIMD.Clamp(a, min, max)Element-wise clampall

Horizontal Operations

FunctionDescription
SIMD.HAdd(a, b)Horizontal add
SIMD.HSub(a, b)Horizontal subtract
SIMD.ReduceAdd(a)Sum all lanes, broadcast result
SIMD.ReduceMin(a)Min of all lanes, broadcast result
SIMD.ReduceMax(a)Max of all lanes, broadcast result

Rounding (float only, SSE4.1)

FunctionDescription
SIMD.Floor(a)Round toward -infinity
SIMD.Ceil(a)Round toward +infinity
SIMD.Round(a)Round to nearest even
SIMD.Trunc(a)Round toward zero

Shifts

FunctionDescription
SIMD.ShiftLeft(a, count)Shift left
SIMD.ShiftRight(a, count)Arithmetic shift right (signed)
SIMD.ShiftRightLogical(a, count)Logical shift right (unsigned)

Conversions

FunctionDescription
SIMD.ConvertToFloat(a)int32x4 → float32x4
SIMD.ConvertToInt(a)float32x4 → int32x4 (truncate)

Example

using Core;
float32x4 positions = float32x4(1.0, 2.0, 3.0, 4.0);
float32x4 velocities = float32x4(0.1, 0.2, 0.3, 0.4);
float32x4 dt = float32x4(0.016);
// Update: pos = pos + vel * dt
positions = SIMD.FMA(velocities, dt, positions);
// Clamp to bounds
float32x4 lo = float32x4(0.0);
float32x4 hi = float32x4(10.0);
positions = SIMD.Clamp(positions, lo, hi);