Modules

SIMD

moduleSource
macOSLinuxWindows

#import "Extensions/SIMD";

Portable fixed-width vectors. A jaic extension, not official Jai: other Jai compilers have no such module, and it may change between jaic releases. See docs/extensions/simd.md.

ExampleOpen in playground ↗
SIMD :: #import "Extensions/SIMD";
using SIMD;

text := "hello, wide world!";

// Where is the first space in these 16 bytes?
chunk := load(u8x16, text.data);
spaces := eq(chunk, #char " ");
if any(spaces) print("at %\n", first_true(spaces));
Show moreShow less

A Vector(T, N) is N lanes of T, at most 64 bytes. Every operation works lane by lane, and its result is the same on every target: the interpreter, x86-64, arm64 and wasm. Compiled with optimization, the operations become the target's vector instructions. Integer arithmetic wraps. Comparisons give a Mask, which selects lanes, reduces to a bool, or becomes a bit per lane.