RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Raya · Compiler

Plain Raya integer loops, faster than C

Write ordinary integer loops over typed lists (dot products, polynomial products, matrix products, FIR filters, 2-D convolutions) and Raya's compiler runs them faster than gcc and clang at -O3 -march=native, with the same results bit for bit, on AWS Graviton3 and Graviton4, Intel Sapphire Rapids and Ice Lake, and AMD EPYC Zen 4.

Date
1 December 2026
Author
Samario Torres, Riptide
Software
Raya main (AOT); C with gcc 13.3 and clang 18.1 at -O3 -march=native
Hardware
AWS Graviton3, Graviton4, Xeon Sapphire Rapids and Ice Lake, EPYC Zen 4

1 December 2026. Samario Torres, Riptide.

What you can do

Write the loop the way the maths reads, over Uint8List, Int16List, Int32List or Int64List, and compile it with raya compile exe. These run faster than the same loops in C compiled by gcc 13 or clang 18 at -O3 -march=native, on every one of the five server CPUs we measured (one exception, for the compiler's own code: a 16 × 16 product into an Int64List on EPYC Zen 4, 0.87× clang), and give exactly the same results:

  • Byte dot products: s += a[i] * b[i].
  • Polynomial products of byte counts: c[i + j] += a[i] * b[j].
  • Matrix products of byte matrices, in row form (c[i * n + j] += a[i * n + k] * b[k * n + j]) or dot form (s += a[i * n + k] * bt[j * n + k]; c[i * n + j] = s).
  • FIR filters with int8 or int16 taps over byte samples: y[i] += h[k] * x[i + k].
  • 2-D convolutions of byte images with int16 kernels, four loops deep.

How much faster, as the faster C compiler's time over Raya's (more than 1× is a win for Raya):

LoopGraviton3Graviton4Sapphire RapidsIce LakeEPYC Zen 4
Byte dot product, 4K pairs11.3×8.95×5.89×4.43×3.33×
Byte dot product, 64K pairs12.0×9.22×6.29×4.07×4.63×
Byte dot product, 1M pairs9.58×7.76×4.26×2.33×3.99×
Polynomial product 64 × 64 → Int64List2.03×2.50×2.93×1.62×2.58×
Polynomial product 64 × 64 → Int32List1.27×1.63×2.71×1.66×2.48×
Polynomial product 256 × 256 → Int32List3.87×4.30×5.29×2.98×3.49×
Polynomial product 256 × 256 → Int64List8.06×7.80×9.87×6.25×6.21×
Polynomial product 1024 × 1024 → Int32List5.75×5.55×8.69×4.63×5.03×
Polynomial product 1024 × 1024 → Int64List12.2×10.5×17.6×8.79×9.32×
Polynomial product 4096 × 4096 → Int32List6.38×5.76×11.0×5.26×5.83×
Polynomial product 4096 × 4096 → Int64List13.8×11.0×21.4×10.3×12.5×
Byte matrix product 64 × 64, dot form3.57×3.81×8.14×6.28×4.90×
Byte matrix product 64 × 64, row form4.08×5.31×4.13×2.86×6.89×
Byte matrix product 256 × 256, dot form4.38×5.51×26.0×11.9×5.75×
Byte matrix product 256 × 256, row form7.54×7.52×15.7×7.55×6.58×
Byte matrix product 512 × 512, dot form5.17×5.77×42.5×13.5×5.81×
Byte matrix product 512 × 512, row form8.21×9.31×25.1×7.97×6.12×
FIR filter, 16 taps, 64K samples2.84×2.97×4.26×3.10×2.71×
FIR filter, 16 taps, 1M samples3.31×3.82×5.94×5.20×3.13×
3 × 3 convolution, 256 × 256 bytes1.46×1.56×2.05×1.67×1.38×
3 × 3 convolution, 1024 × 1024 bytes1.82×2.09×3.78×2.96×1.82×

Geometric mean over the 21 loops, per CPU: Graviton3 4.9×, Graviton4 5.0×, Sapphire Rapids 7.9×, Ice Lake 4.5×, EPYC Zen 4 4.4×.

This table and the per-CPU tables below measure the kernel path: the compiler finds the nest and calls a tuned runtime kernel. For byte dot products and polynomial products the compiler now writes the vector code itself, which is faster again for small and medium nests; see Vector code the compiler writes itself.

Setup: none. It is on in every AOT build (raya compile exe app.ray).

How it gets there

For matrix products, FIR filters and 2-D convolutions, the win comes from the compiler recognising the loop nest and choosing a kernel tuned for the CPU it runs on. For byte dot products and polynomial products, the compiler now writes the vector code itself, in place, with no kernel call (next section). Outside these shapes the compiler's general code is not yet better than gcc's or clang's: with recognition off, Raya's own vectoriser beats C only on byte dot products (12 of 105 measurements).

  1. The compiler finds the nest. Raya's AOT front end looks for rectangular loop nests up to four deep whose bounds don't change inside the nest and whose every index is linear in the loop counters (i * n + k, (y + dy) * w + dx + x). The body must be one multiply-add into a list (dst[..] += x[..] * y[..]) or a sum that is then stored or returned. final locals holding an index or one factor may sit between the loops, and so may if (factor == 0) continue;.
  2. It puts one call in front of the nest. The call gets the lists, the bounds and every index as a base plus one coefficient per loop. The loops stay in the program, unchanged, behind it.
  3. The runtime picks the kernel at start-up. It reads the CPU's features once and names a family: AVX-512 VNNI (VPDPBUSD, VPDPWSSD) on Ice Lake and Zen 4, plus AMX-INT8 tiles (TDPBUUD) for matrix products on Sapphire Rapids; NEON UDOT, USDOT and UMMLA on Graviton4; and on Graviton3 the same, with 256-bit SVE for the longer correlations and dot products. Each kernel blocks its loops for that machine: how many outputs stay in registers, how the operands are packed, where the vector width changes.
  4. The call does the whole nest, or nothing. If the shape is one it has a kernel for, it checks every index the nest would touch and that the destination's memory overlaps neither source, then runs the kernel and the loops are skipped. Otherwise it writes nothing and the loops run as written.

For one-loop element-wise work (c[i] = a[i] + b[i], masks, shifts, sums) the compiler's own integer vectoriser does the job; see SIMD.

Exactness

The results are the loops' results, bit for bit, on every CPU.

  • Reordering is exact. Raya's int wraps modulo 2⁶⁴, and a 32-bit list stores the low 32 bits, so adding the same products in another order gives the same bits.
  • Partial sums never overflow where it matters. The kernels add in 32-bit lanes. That is exact for destinations of 32 bits or fewer. For 64-bit destinations the work is cut into chunks small enough that no 32-bit partial sum can leave its range (65,536 byte-by-byte products, 256 for int16 taps), and each chunk is added in 64 bits.
  • Signed and unsigned bytes. x86's VPDPBUSD multiplies unsigned bytes by signed bytes. For unsigned × unsigned one side is moved to signed (b − 128) and 128 times the other side's sum is added back. int16 taps on Arm are split into a low byte (unsigned, UDOT) and a high byte (signed, USDOT).
  • Errors and partial writes stay the same. The call writes nothing unless every index is in range, so an out-of-range index or a destination that shares memory with a source gives the same RangeError, after the same writes, as before.

The test raya_nest_kernels_test.ray compares every shape with the same loops compiled without the pass: random data and each type's edge values, every length and start in a range, odd sizes, narrow, 32-bit and 64-bit destinations, reversed loops and offsets, out-of-range bounds and a destination sharing memory with a source. It runs once for each kernel family the CPU has, once with the widest kernels at every size, once with the kernels off and once with the vectoriser off, and checks that the kernels ran. benchmarks/RayaIntVec/kernels/nest_kernels_test.cc checks the kernels alone against the scalar nest, for every family, on each CPU.

Results per CPU

These are the kernel-path measurements (benchmarks/RayaIntVec/results/2026-12-01-nest/). Time per call, one thread, best of five blocks of at least 60 ms. Every implementation is checked against a scalar reference before it is timed. C is benchmarks/RayaIntVec/c/intvec_bench.c, the same loops written plainly, compiled on each machine with gcc 13.3 and with clang 18.1 at -O3 -march=native. "Hand intrinsics" are the same operations written by hand with Raya's raya:simd intrinsics (their x86 fallback is scalar, which is why they are slow there). "Raya without the kernels" is the same build with --no-raya-nest-kernels: the integer vectoriser alone. AWS us-west-2, 2-vCPU instances.

AWS Graviton3 (Neoverse V1)

LoopRayagcc 13clang 18Raya vs the faster CHand intrinsicsRaya without the kernelsKernel
Byte dot product, 4K pairs137 ns1.56 µs1.59 µs11.3× faster770 ns224 nsNEON UDOT
Byte dot product, 64K pairs2.11 µs25.3 µs25.3 µs12.0× faster12.6 µs3.63 µsNEON UDOT
Byte dot product, 1M pairs42.3 µs405 µs405 µs9.58× faster201 µs61 µsSVE UDOT
Polynomial product 64 × 64 → Int64List397 ns806 ns852 ns2.03× faster1.45 µs1.33 µsNEON UDOT
Polynomial product 64 × 64 → Int32List390 ns497 ns593 ns1.27× faster1.45 µs754 nsNEON UDOT
Polynomial product 256 × 256 → Int32List1.51 µs5.86 µs6.86 µs3.87× faster6.94 µs9.73 µsNEON UDOT
Polynomial product 256 × 256 → Int64List1.55 µs12.5 µs13.4 µs8.06× faster6.94 µs19.1 µsNEON UDOT
Polynomial product 1024 × 1024 → Int32List16.1 µs92.3 µs113 µs5.75× faster64.1 µs147 µsNEON UDOT
Polynomial product 1024 × 1024 → Int64List16.3 µs199 µs223 µs12.2× faster64.1 µs300 µsNEON UDOT
Polynomial product 4096 × 4096 → Int32List231 µs1.47 ms1.82 ms6.38× faster877 µs2.34 msSVE UDOT
Polynomial product 4096 × 4096 → Int64List232 µs3.2 ms3.58 ms13.8× faster877 µs4.8 msSVE UDOT
Byte matrix product 64 × 64, dot form2.78 µs9.91 µs29 µs3.57× faster24.2 µs35.4 µsUMMLA
Byte matrix product 64 × 64, row form3.2 µs13.1 µs14 µs4.08× faster24.2 µs40.4 µsUMMLA
Byte matrix product 256 × 256, dot form110 µs484 µs1.52 ms4.38× faster760 µs1.34 msUMMLA
Byte matrix product 256 × 256, row form120 µs907 µs934 µs7.54× faster760 µs1.61 msUMMLA
Byte matrix product 512 × 512, dot form792 µs4.09 ms11.8 ms5.17× faster5.71 ms9.74 msUMMLA
Byte matrix product 512 × 512, row form884 µs7.26 ms7.5 ms8.21× faster5.71 ms11.9 msUMMLA
FIR filter, 16 taps, 64K samples44 µs125 µs161 µs2.84× faster–169 µsSVE UDOT + USDOT
FIR filter, 16 taps, 1M samples754 µs2.49 ms2.8 ms3.31× faster–3.19 msSVE UDOT + USDOT
3 × 3 convolution, 256 × 256 bytes53 µs77.4 µs86.5 µs1.46× faster–147 µsSVE UDOT + USDOT
3 × 3 convolution, 1024 × 1024 bytes813 µs1.48 ms1.65 ms1.82× faster–1.92 msSVE UDOT + USDOT

AWS Graviton4 (Neoverse V2)

LoopRayagcc 13clang 18Raya vs the faster CHand intrinsicsRaya without the kernelsKernel
Byte dot product, 4K pairs122 ns1.44 µs1.09 µs8.95× faster700 ns218 nsNEON UDOT
Byte dot product, 64K pairs1.91 µs23.4 µs17.6 µs9.22× faster11.6 µs3.31 µsNEON UDOT
Byte dot product, 1M pairs38.4 µs376 µs298 µs7.76× faster186 µs68.4 µsNEON UDOT
Polynomial product 64 × 64 → Int64List298 ns745 ns869 ns2.50× faster1.25 µs1.15 µsNEON UDOT
Polynomial product 64 × 64 → Int32List286 ns465 ns473 ns1.63× faster1.25 µs653 nsNEON UDOT
Polynomial product 256 × 256 → Int32List1.44 µs6.21 µs7.05 µs4.30× faster6.25 µs10.1 µsNEON UDOT
Polynomial product 256 × 256 → Int64List1.49 µs11.6 µs13.8 µs7.80× faster6.25 µs15.9 µsNEON UDOT
Polynomial product 1024 × 1024 → Int32List17.5 µs97 µs115 µs5.55× faster60 µs153 µsNEON UDOT
Polynomial product 1024 × 1024 → Int64List17.6 µs185 µs223 µs10.5× faster60 µs247 µsNEON UDOT
Polynomial product 4096 × 4096 → Int32List269 µs1.55 ms1.82 ms5.76× faster822 µs2.46 msNEON UDOT
Polynomial product 4096 × 4096 → Int64List272 µs2.98 ms3.55 ms11.0× faster822 µs3.94 msNEON UDOT
Byte matrix product 64 × 64, dot form2.4 µs9.15 µs23.7 µs3.81× faster17.7 µs27.5 µsUMMLA
Byte matrix product 64 × 64, row form2.71 µs14.4 µs15.3 µs5.31× faster17.7 µs25.1 µsUMMLA
Byte matrix product 256 × 256, dot form95.7 µs528 µs1.4 ms5.51× faster638 µs1.08 msUMMLA
Byte matrix product 256 × 256, row form106 µs800 µs1.04 ms7.52× faster638 µs1.4 msUMMLA
Byte matrix product 512 × 512, dot form722 µs4.17 ms11.7 ms5.77× faster4.96 ms7.88 msUMMLA
Byte matrix product 512 × 512, row form773 µs7.2 ms7.84 ms9.31× faster4.96 ms12.3 msUMMLA
FIR filter, 16 taps, 64K samples41.6 µs139 µs124 µs2.97× faster–180 µsNEON UDOT + USDOT
FIR filter, 16 taps, 1M samples739 µs2.82 ms3.04 ms3.82× faster–3.59 msNEON UDOT + USDOT
3 × 3 convolution, 256 × 256 bytes49.8 µs85.4 µs77.7 µs1.56× faster–123 µsNEON UDOT + USDOT
3 × 3 convolution, 1024 × 1024 bytes798 µs1.67 ms1.81 ms2.09× faster–2.22 msNEON UDOT + USDOT

Intel Xeon Sapphire Rapids

LoopRayagcc 13clang 18Raya vs the faster CHand intrinsicsRaya without the kernelsKernel
Byte dot product, 4K pairs97.2 ns862 ns572 ns5.89× faster8.02 µs386 nsVPDPBUSD
Byte dot product, 64K pairs1.45 µs13.7 µs9.14 µs6.29× faster130 µs5.78 µsVPDPBUSD
Byte dot product, 1M pairs34.5 µs222 µs147 µs4.26× faster2.11 ms94.5 µsVPDPBUSD
Polynomial product 64 × 64 → Int64List250 ns860 ns732 ns2.93× faster10.4 µs1.37 µsVPDPBUSD
Polynomial product 64 × 64 → Int32List231 ns669 ns626 ns2.71× faster10.4 µs765 nsVPDPBUSD
Polynomial product 256 × 256 → Int32List762 ns6.41 µs4.03 µs5.29× faster128 µs9.71 µsVPDPBUSD
Polynomial product 256 × 256 → Int64List825 ns13.4 µs8.15 µs9.87× faster128 µs19 µsVPDPBUSD
Polynomial product 1024 × 1024 → Int32List6.91 µs102 µs60 µs8.69× faster1.93 ms148 µsVPDPBUSD
Polynomial product 1024 × 1024 → Int64List7.11 µs211 µs125 µs17.6× faster1.93 ms292 µsVPDPBUSD
Polynomial product 4096 × 4096 → Int32List94.6 µs1.61 ms1.04 ms11.0× faster28 ms2.37 msVPDPBUSD
Polynomial product 4096 × 4096 → Int64List96.9 µs3.4 ms2.07 ms21.4× faster28 ms4.67 msVPDPBUSD
Byte matrix product 64 × 64, dot form2.12 µs28.6 µs17.2 µs8.14× faster482 µs42.7 µsAMX TDPBUUD
Byte matrix product 64 × 64, row form2.38 µs13.8 µs9.83 µs4.13× faster482 µs31 µsAMX TDPBUUD
Byte matrix product 256 × 256, dot form35.2 µs1.78 ms917 µs26.0× faster30.5 ms1.92 msAMX TDPBUUD
Byte matrix product 256 × 256, row form42.2 µs875 µs664 µs15.7× faster30.5 ms1.63 msAMX TDPBUUD
Byte matrix product 512 × 512, dot form166 µs14.1 ms7.05 ms42.5× faster245 ms14.4 msAMX TDPBUUD
Byte matrix product 512 × 512, row form196 µs6.74 ms4.94 ms25.1× faster245 ms11.6 msAMX TDPBUUD
FIR filter, 16 taps, 64K samples22.5 µs106 µs95.8 µs4.26× faster–165 µsVPDPWSSD
FIR filter, 16 taps, 1M samples482 µs2.86 ms2.93 ms5.94× faster–3.01 msVPDPWSSD
3 × 3 convolution, 256 × 256 bytes31 µs69.7 µs63.4 µs2.05× faster–125 µsVPDPWSSD
3 × 3 convolution, 1024 × 1024 bytes445 µs1.68 ms1.71 ms3.78× faster–1.9 msVPDPWSSD

Intel Xeon Ice Lake

LoopRayagcc 13clang 18Raya vs the faster CHand intrinsicsRaya without the kernelsKernel
Byte dot product, 4K pairs135 ns887 ns596 ns4.43× faster12 µs476 nsVPDPBUSD
Byte dot product, 64K pairs2.32 µs14.2 µs9.47 µs4.07× faster194 µs7.38 µsVPDPBUSD
Byte dot product, 1M pairs65.5 µs228 µs152 µs2.33× faster3.1 ms135 µsVPDPBUSD
Polynomial product 64 × 64 → Int64List348 ns885 ns564 ns1.62× faster15.8 µs1.71 µsVPDPBUSD
Polynomial product 64 × 64 → Int32List333 ns583 ns553 ns1.66× faster15.8 µs1.01 µsVPDPBUSD
Polynomial product 256 × 256 → Int32List1.17 µs6.59 µs3.49 µs2.98× faster199 µs12.7 µsVPDPBUSD
Polynomial product 256 × 256 → Int64List1.25 µs13.7 µs7.8 µs6.25× faster199 µs23.7 µsVPDPBUSD
Polynomial product 1024 × 1024 → Int32List13.8 µs104 µs63.9 µs4.63× faster3.03 ms192 µsVPDPBUSD
Polynomial product 1024 × 1024 → Int64List14.2 µs218 µs124 µs8.79× faster3.03 ms381 µsVPDPBUSD
Polynomial product 4096 × 4096 → Int32List192 µs1.67 ms1.01 ms5.26× faster43.7 ms3.06 msVPDPBUSD
Polynomial product 4096 × 4096 → Int64List194 µs3.49 ms1.99 ms10.3× faster43.7 ms6.22 msVPDPBUSD
Byte matrix product 64 × 64, dot form3.38 µs29.6 µs21.2 µs6.28× faster744 µs56.2 µsVPDPBUSD
Byte matrix product 64 × 64, row form3.83 µs14.5 µs11 µs2.86× faster744 µs38.8 µsVPDPBUSD
Byte matrix product 256 × 256, dot form89.6 µs1.83 ms1.07 ms11.9× faster46.9 ms2.46 msVPDPBUSD
Byte matrix product 256 × 256, row form101 µs965 µs763 µs7.55× faster46.9 ms2 msVPDPBUSD
Byte matrix product 512 × 512, dot form616 µs14.6 ms8.32 ms13.5× faster375 ms18.3 msVPDPBUSD
Byte matrix product 512 × 512, row form661 µs7.24 ms5.26 ms7.97× faster375 ms14.2 msVPDPBUSD
FIR filter, 16 taps, 64K samples29.5 µs118 µs91.5 µs3.10× faster–213 µsVPDPWSSD
FIR filter, 16 taps, 1M samples574 µs3.01 ms2.98 ms5.20× faster–3.61 msVPDPWSSD
3 × 3 convolution, 256 × 256 bytes41.9 µs86.2 µs69.8 µs1.67× faster–157 µsVPDPWSSD
3 × 3 convolution, 1024 × 1024 bytes589 µs1.79 ms1.74 ms2.96× faster–2.23 msVPDPWSSD

AMD EPYC Zen 4

LoopRayagcc 13clang 18Raya vs the faster CHand intrinsicsRaya without the kernelsKernel
Byte dot product, 4K pairs108 ns433 ns361 ns3.33× faster8.43 µs406 nsVPDPBUSD
Byte dot product, 64K pairs1.24 µs6.86 µs5.74 µs4.63× faster134 µs6.18 µsVPDPBUSD
Byte dot product, 1M pairs22.9 µs110 µs91.4 µs3.99× faster2.12 ms99.1 µsVPDPBUSD
Polynomial product 64 × 64 → Int64List283 ns877 ns731 ns2.58× faster10.9 µs1.45 µsVPDPBUSD
Polynomial product 64 × 64 → Int32List255 ns643 ns633 ns2.48× faster10.9 µs804 nsVPDPBUSD
Polynomial product 256 × 256 → Int32List934 ns3.71 µs3.26 µs3.49× faster140 µs10.2 µsVPDPBUSD
Polynomial product 256 × 256 → Int64List1e+03 ns7.44 µs6.21 µs6.21× faster140 µs19.9 µsVPDPBUSD
Polynomial product 1024 × 1024 → Int32List9.89 µs52.8 µs49.8 µs5.03× faster2.11 ms155 µsVPDPBUSD
Polynomial product 1024 × 1024 → Int64List10.3 µs120 µs96.1 µs9.32× faster2.11 ms308 µsVPDPBUSD
Polynomial product 4096 × 4096 → Int32List136 µs873 µs795 µs5.83× faster31.2 ms2.45 msVPDPBUSD
Polynomial product 4096 × 4096 → Int64List137 µs2.03 ms1.72 ms12.5× faster31.2 ms4.98 msVPDPBUSD
Byte matrix product 64 × 64, dot form2.72 µs18.8 µs13.3 µs4.90× faster503 µs45.5 µsVPDPBUSD
Byte matrix product 64 × 64, row form3 µs20.9 µs20.7 µs6.89× faster503 µs31.3 µsVPDPBUSD
Byte matrix product 256 × 256, dot form91.4 µs980 µs526 µs5.75× faster32.9 ms2.01 msVPDPBUSD
Byte matrix product 256 × 256, row form96 µs663 µs632 µs6.58× faster32.9 ms1.7 msVPDPBUSD
Byte matrix product 512 × 512, dot form655 µs7.55 ms3.81 ms5.81× faster257 ms14.9 msVPDPBUSD
Byte matrix product 512 × 512, row form675 µs4.34 ms4.13 ms6.12× faster257 ms12.1 msVPDPBUSD
FIR filter, 16 taps, 64K samples23.2 µs72.5 µs62.8 µs2.71× faster–165 µsVPDPWSSD
FIR filter, 16 taps, 1M samples375 µs1.24 ms1.18 ms3.13× faster–2.67 msVPDPWSSD
3 × 3 convolution, 256 × 256 bytes31.1 µs58.1 µs42.9 µs1.38× faster–133 µsVPDPWSSD
3 × 3 convolution, 1024 × 1024 bytes360 µs729 µs654 µs1.82× faster–1.71 msVPDPWSSD

Vector code the compiler writes itself

For two of the shapes, the compiler now writes the vector code itself, in place, with no call into the runtime:

  • byte dot products, s += a[i] * b[i], with a and b both Uint8List or both Int8List;
  • polynomial products of byte lists, c[i + j] += a[i] * b[j], into an Int32List, Uint32List, Int64List or Uint64List.

How. The front end puts a marker call in front of the kernel call it already makes for these nests, and the compiler replaces the marker with one IL instruction that emits the whole nest as straight vector loops. The code path is picked when the program runs, from the CPU's features, so one executable runs on any CPU of its architecture:

  • Arm: NEON UDOT/SDOT. Polynomial products run as correlations over sliding 4-byte windows of the data. On Graviton3, dot products of 16K to 2M bytes use 256-bit SVE UDOT/SDOT, where it measured faster than NEON (and slower below and above that range).
  • x86: AVX-512 VNNI VPDPBUSD, with one side moved to the other signedness (an XOR with 0x80) and 128 times the other side's sum added back. CPUs with AVX2 but no AVX-512 VNNI get an AVX2 dot product; their polynomial products still go to the kernel call.

Exactness. Products are added in 32-bit lanes, and range analysis over the element types bounds every lane before it can overflow: a byte product is at most 65,025 (unsigned) or 16,384 in magnitude (signed). Dot products move their 32-bit lanes into 64-bit sums at least every 16,384 steps; polynomial products take at most 256 terms per pass (256 × 65,025 < 2³¹) before adding to the destination. When the CPU has no usable path, a list isn't what the code expects, an index is out of range, or the destination overlaps a source, the code writes nothing; then the kernel call and, after it, the loops run exactly as before. raya_nest_codegen_test.ray checks both shapes against the plain loops (random and edge values, every length up to 700 and long ones across every block boundary, views, out-of-range bounds, overlapping destinations) for each code path and with the kernels off, on all five CPUs.

What it gains. The kernel call costs a few tens of nanoseconds (argument checks, a native transition, a handle per list), which is most of the time for small nests. In place, dot products of up to 4K bytes run 1.7 to 5.8 times faster than through the kernel, and polynomial products of up to 64 terms 1.4 to 3.5 times faster. Large nests are level with the kernel (within about 2%, at most 2.3% slower) or faster (up to 1.7 times on Graviton4).

Where it loses. 256 × 256 polynomial products on Ice Lake are 5 to 7% slower than the kernel call. A 16 × 16 product into an Int64List on EPYC Zen 4 is 0.87× clang, the one loop and CPU where C is faster: fixed costs dominate a nest of 256 products. A few large cases are 1–2.3% behind the kernel.

The compiler's own code against the faster of gcc and clang (more than 1× is a win for Raya):

LoopGraviton3Graviton4Sapphire RapidsIce LakeEPYC Zen 4
Byte dot product, 256 pairs5.22×5.36×3.26×2.63×2.18×
Byte dot product, 1K pairs12.2×9.80×7.47×6.25×4.88×
Byte dot product, 4K pairs17.9×13.4×9.35×7.84×6.60×
Byte dot product, 64K pairs13.1×9.50×6.31×4.39×4.79×
Byte dot product, 1M pairs10.6×7.88×4.29×2.46×4.01×
Polynomial product 16 × 16 → Int32List1.51×1.59×1.08×1.15×1.15×
Polynomial product 16 × 16 → Int64List1.04×1.13×1.56×1.13×0.87×
Polynomial product 64 × 64 → Int32List3.27×3.77×5.05×2.44×3.88×
Polynomial product 64 × 64 → Int64List4.85×5.58×5.05×2.30×4.01×
Polynomial product 256 × 256 → Int32List5.33×7.19×6.38×2.76×3.71×
Polynomial product 256 × 256 → Int64List11.1×12.9×11.8×5.87×6.79×
Polynomial product 1024 × 1024 → Int32List6.15×8.09×9.42×4.96×5.58×
Polynomial product 1024 × 1024 → Int64List13.1×15.3×18.9×9.48×10.3×
Polynomial product 4096 × 4096 → Int32List6.36×8.35×11.8×5.63×6.36×
Polynomial product 4096 × 4096 → Int64List13.6×15.7×22.0×10.6×13.2×

Geometric mean over the 15 loops, per CPU: Graviton3 6.5×, Graviton4 6.8×, Sapphire Rapids 6.3×, Ice Lake 3.8×, EPYC Zen 4 4.2×.

Time per call, one thread, best of five blocks of at least 60 ms, each implementation checked against a scalar reference first. "Kernel call" is the same program with --no-raya-nest-codegen. C as above. Measurements in benchmarks/RayaIntVec/results/2026-12-01-codegen/.

AWS Graviton3 (Neoverse V1), compiler's own code

LoopCompiler's own codeKernel callgcc 13clang 18vs the faster Cvs the kernel call
Byte dot product, 256 pairs14.4 ns75.7 ns75 ns99.9 ns5.22×5.26×
Byte dot product, 1K pairs30.4 ns92.4 ns372 ns401 ns12.2×3.04×
Byte dot product, 4K pairs87 ns163 ns1.56 µs1.59 µs17.9×1.87×
Byte dot product, 64K pairs1.94 µs2.12 µs25.3 µs25.3 µs13.1×1.10×
Byte dot product, 1M pairs38.3 µs41.8 µs405 µs405 µs10.6×1.09×
Polynomial product 16 × 16 → Int32List75 ns266 ns113 ns119 ns1.51×3.54×
Polynomial product 16 × 16 → Int64List78.6 ns260 ns82 ns82.6 ns1.04×3.30×
Polynomial product 64 × 64 → Int32List152 ns369 ns497 ns592 ns3.27×2.43×
Polynomial product 64 × 64 → Int64List166 ns369 ns805 ns856 ns4.85×2.23×
Polynomial product 256 × 256 → Int32List1.1 µs1.51 µs5.85 µs6.86 µs5.33×1.38×
Polynomial product 256 × 256 → Int64List1.13 µs1.55 µs12.5 µs13.4 µs11.1×1.37×
Polynomial product 1024 × 1024 → Int32List15 µs16.1 µs92.3 µs114 µs6.15×1.07×
Polynomial product 1024 × 1024 → Int64List15.3 µs16.3 µs200 µs223 µs13.1×1.07×
Polynomial product 4096 × 4096 → Int32List231 µs230 µs1.47 ms1.81 ms6.36×1.00×
Polynomial product 4096 × 4096 → Int64List235 µs232 µs3.2 ms3.57 ms13.6×0.99× (slower)

AWS Graviton4 (Neoverse V2), compiler's own code

LoopCompiler's own codeKernel callgcc 13clang 18vs the faster Cvs the kernel call
Byte dot product, 256 pairs11.5 ns62.5 ns61.7 ns62 ns5.36×5.44×
Byte dot product, 1K pairs27.4 ns78.8 ns337 ns268 ns9.80×2.88×
Byte dot product, 4K pairs81.8 ns149 ns1.44 µs1.09 µs13.4×1.82×
Byte dot product, 64K pairs1.86 µs1.92 µs23.5 µs17.6 µs9.50×1.04×
Byte dot product, 1M pairs39.1 µs38.2 µs376 µs308 µs7.88×0.98× (slower)
Polynomial product 16 × 16 → Int32List62 ns183 ns98.5 ns104 ns1.59×2.95×
Polynomial product 16 × 16 → Int64List64.8 ns190 ns73.5 ns91.2 ns1.13×2.94×
Polynomial product 64 × 64 → Int32List124 ns291 ns466 ns484 ns3.77×2.35×
Polynomial product 64 × 64 → Int64List134 ns303 ns746 ns870 ns5.58×2.26×
Polynomial product 256 × 256 → Int32List864 ns1.45 µs6.21 µs7.05 µs7.19×1.68×
Polynomial product 256 × 256 → Int64List898 ns1.5 µs11.6 µs13.8 µs12.9×1.67×
Polynomial product 1024 × 1024 → Int32List12 µs17 µs97 µs115 µs8.09×1.42×
Polynomial product 1024 × 1024 → Int64List12.3 µs17.9 µs188 µs223 µs15.3×1.46×
Polynomial product 4096 × 4096 → Int32List186 µs258 µs1.55 ms1.82 ms8.35×1.39×
Polynomial product 4096 × 4096 → Int64List190 µs260 µs2.98 ms3.55 ms15.7×1.37×

Intel Xeon Sapphire Rapids, compiler's own code

LoopCompiler's own codeKernel callgcc 13clang 18vs the faster Cvs the kernel call
Byte dot product, 256 pairs11.3 ns58.4 ns55.3 ns36.9 ns3.26×5.16×
Byte dot product, 1K pairs19.8 ns68.3 ns222 ns148 ns7.47×3.45×
Byte dot product, 4K pairs62.5 ns106 ns879 ns584 ns9.35×1.70×
Byte dot product, 64K pairs1.48 µs1.53 µs14.1 µs9.36 µs6.31×1.03×
Byte dot product, 1M pairs35.6 µs34.9 µs230 µs153 µs4.29×0.98× (slower)
Polynomial product 16 × 16 → Int32List83.5 ns175 ns115 ns90.5 ns1.08×2.09×
Polynomial product 16 × 16 → Int64List84.8 ns176 ns133 ns133 ns1.56×2.08×
Polynomial product 64 × 64 → Int32List130 ns238 ns696 ns654 ns5.05×1.84×
Polynomial product 64 × 64 → Int64List152 ns254 ns882 ns769 ns5.05×1.67×
Polynomial product 256 × 256 → Int32List672 ns773 ns6.57 µs4.29 µs6.38×1.15×
Polynomial product 256 × 256 → Int64List718 ns850 ns13.6 µs8.5 µs11.8×1.18×
Polynomial product 1024 × 1024 → Int32List6.76 µs7.09 µs103 µs63.7 µs9.42×1.05×
Polynomial product 1024 × 1024 → Int64List7.06 µs7.36 µs216 µs134 µs18.9×1.04×
Polynomial product 4096 × 4096 → Int32List92 µs97 µs1.65 ms1.08 ms11.8×1.05×
Polynomial product 4096 × 4096 → Int64List98.2 µs99 µs3.44 ms2.17 ms22.0×1.01×

Intel Xeon Ice Lake, compiler's own code

LoopCompiler's own codeKernel callgcc 13clang 18vs the faster Cvs the kernel call
Byte dot product, 256 pairs14.2 ns79.4 ns55.7 ns37.2 ns2.63×5.60×
Byte dot product, 1K pairs23.7 ns87.3 ns222 ns148 ns6.25×3.69×
Byte dot product, 4K pairs76 ns138 ns887 ns596 ns7.84×1.82×
Byte dot product, 64K pairs2.16 µs2.31 µs14.2 µs9.47 µs4.39×1.07×
Byte dot product, 1M pairs62 µs63.9 µs228 µs152 µs2.46×1.03×
Polynomial product 16 × 16 → Int32List103 ns244 ns119 ns174 ns1.15×2.37×
Polynomial product 16 × 16 → Int64List116 ns244 ns135 ns131 ns1.13×2.11×
Polynomial product 64 × 64 → Int32List226 ns342 ns583 ns553 ns2.44×1.51×
Polynomial product 64 × 64 → Int64List246 ns350 ns886 ns565 ns2.30×1.43×
Polynomial product 256 × 256 → Int32List1.27 µs1.18 µs6.59 µs3.49 µs2.76×0.93× (slower)
Polynomial product 256 × 256 → Int64List1.33 µs1.26 µs13.7 µs7.82 µs5.87×0.95× (slower)
Polynomial product 1024 × 1024 → Int32List13.1 µs13.8 µs105 µs64.9 µs4.96×1.06×
Polynomial product 1024 × 1024 → Int64List13.6 µs14.2 µs224 µs129 µs9.48×1.04×
Polynomial product 4096 × 4096 → Int32List183 µs192 µs1.68 ms1.03 ms5.63×1.05×
Polynomial product 4096 × 4096 → Int64List190 µs194 µs3.49 ms2.03 ms10.6×1.02×

AMD EPYC Zen 4, compiler's own code

LoopCompiler's own codeKernel callgcc 13clang 18vs the faster Cvs the kernel call
Byte dot product, 256 pairs10.5 ns60.8 ns28.3 ns22.9 ns2.18×5.79×
Byte dot product, 1K pairs18.4 ns76.4 ns109 ns89.7 ns4.88×4.16×
Byte dot product, 4K pairs54.9 ns120 ns433 ns363 ns6.60×2.18×
Byte dot product, 64K pairs1.18 µs1.27 µs6.86 µs5.67 µs4.79×1.08×
Byte dot product, 1M pairs22.8 µs22.9 µs110 µs91.5 µs4.01×1.00×
Polynomial product 16 × 16 → Int32List89.4 ns182 ns145 ns102 ns1.15×2.04×
Polynomial product 16 × 16 → Int64List97 ns188 ns107 ns84.1 ns0.87× (slower)1.94×
Polynomial product 64 × 64 → Int32List159 ns258 ns641 ns617 ns3.88×1.62×
Polynomial product 64 × 64 → Int64List179 ns282 ns874 ns717 ns4.01×1.58×
Polynomial product 256 × 256 → Int32List883 ns954 ns3.7 µs3.28 µs3.71×1.08×
Polynomial product 256 × 256 → Int64List916 ns1 µs7.44 µs6.21 µs6.79×1.09×
Polynomial product 1024 × 1024 → Int32List8.87 µs10 µs52.7 µs49.6 µs5.58×1.13×
Polynomial product 1024 × 1024 → Int64List9.23 µs10.3 µs126 µs95.3 µs10.3×1.12×
Polynomial product 4096 × 4096 → Int32List125 µs136 µs856 µs795 µs6.36×1.09×
Polynomial product 4096 × 4096 → Int64List130 µs137 µs2.03 ms1.72 ms13.2×1.06×

Where it doesn't apply

  • Other shapes run as written. A nest with an if other than the zero-factor continue, a bound that changes inside the nest, an index that isn't linear (a[i * i], a[idx[i]]), or two products in one body is left to the vectoriser and the scalar loop.
  • Element types. The data side must be bytes (Uint8List); taps may be Uint8List, Int8List or Int16List; matrix products are byte by byte; dot products are byte by byte (Int8List too: on Arm through the kernels, and on both Arm and x86 through the compiler's own code). Wider operands, such as Int64List counts, use the vectoriser.
  • CPUs. Kernels need AVX-512 with VNNI on x86 and the dot-product instructions on Arm (Graviton2 and later, Apple M1 and later). Matrix products and signed taps on Arm also need I8MM (Graviton3 and later). Byte dot products also run on x86 CPUs with AVX2 only, through the compiler's own AVX2 code. On other CPUs the call returns at once and the loops run as written.
  • Small work. For matrix products, FIR filters and 2-D convolutions, the call and its checks cost a few tens of nanoseconds, so a nest of a few hundred multiply-adds gains little. Dot and polynomial products no longer pay that cost.
  • Ahead-of-time only. The pass runs in AOT builds (raya compile exe, aot-snapshot), not in the JIT.

Reproduce

Everything is in the repository, under benchmarks/RayaIntVec/:

raya compile exe benchmarks/RayaIntVec/raya/intvec_bench.ray -o intvec_bench
./intvec_bench poly 4096 now
gcc -O3 -march=native -o intvec_bench_c benchmarks/RayaIntVec/c/intvec_bench.c && ./intvec_bench_c poly 4096 gcc
clang -O3 -march=native -o intvec_bench_c benchmarks/RayaIntVec/c/intvec_bench.c && ./intvec_bench_c poly 4096 clang

Cases: dot, poly, maxel, fir, conv2d, each with a size. Each prints one JSON line per implementation. The kernels alone, without the VM: clang++ -O2 -std=c++17 -I runtime runtime/vm/raya_nest_kernels.cc benchmarks/RayaIntVec/kernels/nest_kernels_test.cc -o nest_test, then ./nest_test test (exactness, every family this CPU has) or ./nest_test bench. The measurements on this page are in benchmarks/RayaIntVec/results/2026-12-01-nest/.

Details

Flags. --no-raya-nest-kernels (a VM flag) makes every call return false, so the loops run as written. -Draya.nest_kernels=false at compile time leaves the program without the calls. @pragma('raya:no-nest-kernel') on a function or method keeps the pass out of it. --trace-raya-nest prints, for each call, the kernel that ran or why the loops ran instead. --raya-nest-isa=N caps the kernel family (0 none; Arm 1 dot product, 2 I8MM, 3 SVE; x86 11 AVX-512 VNNI, 12 AMX) and --raya-nest-widest uses the widest kernel at every size; both are for tests. For the compiler's own code: --no-raya-nest-codegen (a VM flag) sends dot and polynomial nests to the kernels again; --raya-nest-codegen-isa=<mask> limits its code paths (tests: Arm 1 NEON, 2 SVE; x86 256 AVX2, 512 AVX-512 VNNI); --no-raya-nest-codegen-compile (gen_snapshot) and -Draya.nest_codegen=false (gen_kernel) leave the code out.

Shapes the runtime has kernels for. After loops of one iteration are dropped and loops are flipped so that unit steps are +1: a matrix product, dst[i, j] (+)= Σk A[i, k] · B[k, j] with any strides, written to a row-major or column-major destination; a 1-D or 2-D correlation, dst[oy, ox] += Σ w[ty, tx] · x[oy, ty, ox + tx] with the taps forward or reversed and any row strides; and a full 1-D convolution, dst[p + q] += a[p] · b[q], which the runtime turns into a correlation with the taps reversed and the data zero-padded in scratch memory, skipping the taps that only meet padding.

Also in this change. fillRange on the VM's integer typed lists now runs in native code (it was a loop that dispatched every store), so the zeroing before an accumulating nest costs what memset costs.

Next. The same approach, one shape at a time, each tested against the scalar loops the same way:

  1. Matrix products (row form and dot form) in the compiler's own code: Arm UMMLA/SMMLA register blocks, x86 VPDPBUSD register blocks, then AMX-INT8 tiles on Sapphire Rapids.
  2. FIR filters and 2-D convolutions with int8 and int16 taps (USDOT, VPDPWSSD), and the AVX2 polynomial product.
  3. General integer loops: 256-bit and 512-bit lanes for the compiler's integer vectoriser (today 128-bit), so element-wise work and reductions that are not one of these shapes get the full vector width too.