simd.nx
buildroot/runtime/simd.nx
about
simd.nx -- SIMD vector types + intrinsics (spec + soft-fallback).
Target: 8-16x speedup on every numeric routine NishiLang ships
(sha256, chacha20, base64, CRCs, etc.) via target-native
vector instructions (AVX-512, RVV, NEON).
Two-phase approach:
Phase A (this file): define the SIMD type API + soft-fallback
implementation. Every SIMD op is a regular i64 function
that manipulates an "8x i64" packed buffer one lane at a
time. No speedup yet, but callers can write SIMD-shaped
code today.
Phase B (riscv.nx backend work, pending): pattern-match these
functions during codegen and replace with single vector
instructions. Same source code compiles to 8-16x
faster machine code.
Why this order: API commitment FIRST means library authors
can start writing SIMD-shaped routines now. The speedup
lands later without breaking any caller.
Invariants:
V1 Vec64 is 8x i64 = 64 bytes = one AVX-512 register / two
AVX2 regs / one RVV VLEN-512 register / four NEON regs.
V2 Ops are pure functions of operand lanes -- no side
effects, no aliasing concerns.
V3 Memory ops (load/store) take aligned pointers; caller
ensures 64-byte alignment for max throughput.
dependencies 1 imports · 0 importers
imports: syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| 37 | struct Vec64 { |
consts
| 42 | const VEC64_BYTES: i64 = 64 |
functions
| 46 | func vec64_zero() -> *Vec64 { |
| 55 | func vec64_splat(x: i64) -> *Vec64 { |
| 64 | func vec64_load(p: *i64) -> *Vec64 {
calls 1: vec64_zero |
| 72 | func vec64_store(v: *Vec64, p: *i64) -> i64 { |
| 81 | func vec64_add(a: *Vec64, b: *Vec64) -> *Vec64 { |
| 95 | func vec64_sub(a: *Vec64, b: *Vec64) -> *Vec64 {
calls 1: vec64_zero |
| 109 | func vec64_mul(a: *Vec64, b: *Vec64) -> *Vec64 {
calls 1: vec64_zero |
| 124 | func vec64_and(a: *Vec64, b: *Vec64) -> *Vec64 {
calls 1: vec64_zero |
| 137 | func vec64_or(a: *Vec64, b: *Vec64) -> *Vec64 {
calls 1: vec64_zero |
| 150 | func vec64_xor(a: *Vec64, b: *Vec64) -> *Vec64 { |
| 164 | func vec64_shl(v: *Vec64, n: i64) -> *Vec64 {
calls 1: vec64_zero |
| 181 | func vec64_hsum(v: *Vec64) -> i64 {
called by 1: main |
| 186 | func main() -> i64 { |