Plain Raya integer loops, faster than C
You write an integer loop the way the maths reads. The Raya compiler recognises the loop nest, checks it is safe, and runs it on the vector and matrix units of the CPU it finds itself on. This paper measures that against gcc and clang on five server CPUs, shows the results are exact, and is plain about where the speed comes from.
Abstract
Integer loops over small numbers are everywhere: pixels, audio samples, quantized model weights, counts in exact algebra. On 1 December 2026 we measured 21 such loops written plainly in Raya against the same loops written plainly in C, compiled with gcc 13.3 and with clang 18.1 at -O3 -march=native, on five AWS server CPUs: Graviton3 (c7g), Graviton4 (c8g), Intel Xeon Sapphire Rapids (c7i), Intel Xeon Ice Lake (c6i) and AMD EPYC Zen 4 (c7a), one thread each.
- Raya is faster than the faster of the two C compilers in all 105 of 105 measurements, by 1.27× (a 64 × 64 polynomial product on Graviton3) to 42.5× (a 512 × 512 byte matrix product on Sapphire Rapids, dot form against the same dot form in C; against C's faster row form, 4.94 ms, it is 29.8×). 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×.
- The results are the same, bit for bit. Every implementation is checked against a scalar reference before it is timed, and a test suite compares every shape with the same loops compiled without the change, including edge values, odd sizes, out-of-range indices and overlapping memory.
- The win comes from recognising the loop nest, not from a better general code generator. With recognition switched off, Raya's own integer vectoriser beats C in 12 of the 105 measurements.
- New in version 1.2: for byte dot products and polynomial products, the compiler now writes the vector code itself, in place, with no call into a runtime kernel. Over 15 loops on the same five CPUs it is faster than the faster C compiler in 74 of 75 measurements (0.87× to 22.0×; geometric mean Graviton3 6.5×, Graviton4 6.8×, Sapphire Rapids 6.3×, Ice Lake 3.8×, EPYC Zen 4 4.2×; the one loss is a 16 × 16 product on EPYC Zen 4), 1.7× to 5.8× faster than the kernel call for dot products of up to 4K bytes, 1.4× to 3.5× for polynomial products of up to 64 terms, and level or faster on large nests (0.93× to 1.68×; slower only for 256 × 256 on Ice Lake).
What this lets you do
- Write the loop the way the maths reads, over
Uint8List,Int16List,Int32ListorInt64List, and compile it withraya compile exe. No intrinsics, no library calls, no flags. - Get the CPU's vector and matrix units without writing for them. The same source uses the dot-product instructions on Arm, AVX-512 VNNI on Intel and AMD, and AMX matrix tiles on Sapphire Rapids, chosen when the program starts.
- Keep exact results. Reordering integer sums gives the same bits, so the fast path and the plain loop agree on every input, and an out-of-range index still raises the same error after the same writes.
The loops it recognises today:
- 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
int8orint16taps over byte samples:y[i] += h[k] * x[i + k]. - 2-D convolutions of byte images with
int16kernels, four loops deep.
Method
This section describes the compiler change at the level of the algorithm. Raya is open source, so the full implementation is in the repository as well.
- Recognise the nest. In ahead-of-time builds, Raya's compiler looks for rectangular loop nests up to four deep whose bounds do not 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.finallocals holding an index or one factor may sit between the loops, and so mayif (factor == 0) continue;. - Describe it. Loops of one iteration are dropped and loops with negative steps are flipped. Each index becomes a base plus one coefficient per loop counter. The nest then matches one of three shapes: a matrix product with any strides; a 1-D or 2-D correlation with the taps forward or reversed; or a full 1-D convolution (a polynomial product), which is turned into a correlation with the taps reversed and the data zero-padded in scratch memory, skipping taps that only meet padding.
- One call in front of the loops. The compiler places a single call before the nest, passing the lists, the bounds and the index descriptions. The loops stay in the program behind it.
- Choose the kernel once per process. At start-up the runtime reads the CPU's features and picks an instruction family: AVX-512 VNNI (
VPDPBUSDfor bytes,VPDPWSSDfor 16-bit pairs) on Ice Lake and Zen 4, plus AMX-INT8 tiles (TDPBUUD) for matrix products on Sapphire Rapids; the Arm dot-product instructions (UDOT,USDOT) and the I8MM matrix instruction (UMMLA) on Graviton; and 256-bit SVE on Graviton3 for long correlations and dot products. Each kernel blocks the work for its machine: how many outputs stay in registers, how operands are packed, where the vector width changes. - All or nothing. At run time the call checks every index the nest would touch and that the destination's memory overlaps neither source. If all checks pass, the kernel computes the whole nest and the loops are skipped; otherwise the call writes nothing and the loops run as written, so errors and partial writes are exactly those of the plain loops.
Why the results are bit for bit the same. Raya's int wraps modulo and a 32-bit list stores the low 32 bits, so adding the same products in a different order gives the same bits. The kernels add byte products in 32-bit lanes, which 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, or 256 for 16-bit taps), and each chunk is added in 64 bits. x86's VPDPBUSD multiplies unsigned by signed bytes, so for unsigned × unsigned data one side is shifted to and 128 times the other side's sum is added back. 16-bit taps on Arm are split into a low byte (unsigned, UDOT) and a high byte (signed, USDOT), and the two results are combined.
Compiler-generated code for dot and polynomial products (version 1.2). For byte dot products (Uint8List × Uint8List or Int8List × Int8List) and polynomial products of byte lists into 32- or 64-bit lists, the kernel call is replaced by code the compiler emits itself:
- A marker, then one instruction. The front end puts a marker call in front of the kernel call it already makes for these nests. The compiler replaces the marker with one intermediate-language instruction that emits the whole nest as straight vector loops, in place.
- The path is chosen at run time. The generated code reads the CPU's features and picks a path, so one executable runs on any CPU of its architecture. On Arm it uses NEON
UDOT/SDOT; on Graviton3, dot products of 16K to 2M bytes use 256-bit SVEUDOT/SDOT, where SVE measured faster than NEON (and slower below and above that range). On x86 it uses AVX-512 VNNIVPDPBUSD, moving one side to the other signedness and adding 128 times the other side's sum back; CPUs with AVX2 but no AVX-512 VNNI get an AVX2 dot product. Polynomial products run as correlations over sliding 4-byte windows of the data, and blocks skip the terms that only meet zero padding. - The overflow bound comes from the element types. Products are added in 32-bit lanes. A byte product is at most 65,025 (unsigned) or 16,384 in magnitude (signed), and one dot-product instruction adds four of them to a lane. Dot products move their lanes into 64-bit sums at least every 16,384 steps; polynomial products take at most 256 terms per pass () before adding to the destination, widened for a 64-bit destination. Integer adds wrap, so any order of the same products gives the same bits.
- Fallback is unchanged. When the CPU has no usable path, a list is not the type the code expects, an index is out of range, or the destination overlaps a source, the generated code writes nothing; the kernel call and, after it, the plain loops then run exactly as before.
Setup
- Machines. AWS EC2, one thread: Graviton3 (Neoverse V1; c7g), Graviton4 (Neoverse V2; c8g), Intel Xeon Platinum 8488C (Sapphire Rapids; c7i), Intel Xeon Platinum 8375C (Ice Lake; c6i) and AMD EPYC 9R14 (Zen 4; c7a).
- Baselines. The same 21 loops written plainly in C, compiled on each machine with gcc 13.3 and with clang 18.1 at
-O3 -march=native. Each row compares Raya with whichever compiler was faster on that row and machine, on the same loop: the row-form and dot-form matrix products are each compared with the same form in C. - Timing. Time per call, best of five blocks of at least 60 ms each.
- Correctness. Every implementation is checked against a scalar reference before it is timed. Separately, the compiler's test suite compares every recognised shape with the same loops compiled without recognition: 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 passed on all five CPUs, for every family of CPU instructions each one has.
Results

| CPU | Geometric mean | Closest | Widest |
|---|---|---|---|
| Graviton3 | 4.9× | 1.27× (polynomial 64 × 64 → Int32List) | 13.8× (polynomial 4096 × 4096 → Int64List) |
| Graviton4 | 5.0× | 1.56× (3 × 3 convolution, 256 × 256) | 11.0× (polynomial 4096 × 4096 → Int64List) |
| Sapphire Rapids | 7.9× | 2.05× (3 × 3 convolution, 256 × 256) | 42.5× (byte matrix 512 × 512, dot form; 29.8× against C's faster row form) |
| Ice Lake | 4.5× | 1.62× (polynomial 64 × 64 → Int64List) | 13.5× (byte matrix 512 × 512, dot form) |
| EPYC Zen 4 | 4.4× | 1.38× (3 × 3 convolution, 256 × 256) | 12.5× (polynomial 4096 × 4096 → Int64List) |
- Dot products gain most on Arm: 9.6–12.0× on Graviton3 and 7.8–9.2× on Graviton4, against 2.3–6.3× on the x86 machines.
- Byte matrix products gain most on Sapphire Rapids, 15.7–42.5× at 256 and 512, where the AMX matrix tiles are used; Ice Lake reaches 11.9–13.5× on the dot form at 256 and 512.
- Polynomial products grow with size, from 1.27–2.93× at 64 terms to 10.3–21.4× at 4,096 terms into a 64-bit destination.
- FIR filters are 2.7–5.9× and 3 × 3 convolutions 1.38–3.78×, among the smallest margins in the table, with the 64 × 64 polynomial products (1.27× on Graviton3, 1.63× on Graviton4, 1.62–1.66× on Ice Lake).
Where the win comes from

Recognising the nest and running a kernel built for the CPU's vector and matrix units (see Method) is how the 105 wins are made; with recognition switched off, the vectoriser alone is slower than C on average on every CPU (0.42× to 0.84×).
The compiler's own code for dot and polynomial products (version 1.2)
The same five machines, 15 loops: byte dot products of 256 to 1M pairs, and polynomial products of 16 to 4,096 terms into Int32List and Int64List. "Kernel call" is the same program with --no-raya-nest-codegen.
| CPU | vs kernel call, dot ≤ 4K bytes | vs kernel call, polynomial ≤ 64 terms | vs kernel call, large nests | vs the faster C (geometric mean) |
|---|---|---|---|---|
| Graviton3 | 1.87–5.26× | 2.23–3.54× | 0.99–1.38× | 1.04–17.9× (6.5×) |
| Graviton4 | 1.82–5.44× | 2.26–2.95× | 0.98–1.68× | 1.13–15.7× (6.8×) |
| Sapphire Rapids | 1.70–5.16× | 1.67–2.09× | 0.98–1.18× | 1.08–22.0× (6.3×) |
| Ice Lake | 1.82–5.60× | 1.43–2.37× | 0.93–1.07× | 1.13–10.6× (3.8×) |
| EPYC Zen 4 | 2.18–5.79× | 1.58–2.04× | 1.00–1.13× | 0.87–13.2× (4.2×) |
- Small nests gain most. 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; the generated code has none of that.
- Large nests are level. Within about 2% of the kernel call (at most 2.3% slower) or faster, up to 1.68× on Graviton4. One case is slower: 256 × 256 polynomial products on Ice Lake, 0.93–0.95× of the kernel call.
- One loss to C. A 16 × 16 polynomial product into an
Int64Liston EPYC Zen 4 is 0.87× clang: fixed costs dominate a nest of 256 products. - Exact. A new test compares both shapes with 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. It passed on all five CPUs.
Limitations and next steps
The limits of these results, each with its cause and, where one is planned, the next step.
- General code generation. Without loop-nest recognition, Raya's integer vectoriser is faster than C in only 12 of 105 measurements. Cause: the vectoriser emits 128-bit vector code on both architectures today. Version 1.2 adds the compiler's own vector code for two shapes (dot and polynomial products); 256- and 512-bit lanes for general integer loops are planned after matrix products and filters.
- Matrix products, FIR filters and 2-D convolutions still go through the kernel call. Cause: the compiler's own code covers dot and polynomial products first; matrix products (Arm
UMMLA/SMMLA, x86VPDPBUSD, then AMX tiles) and then FIR filters and 2-D convolutions are the next phases, not started. - No AVX2 polynomial product yet. On x86 CPUs with AVX2 but no AVX-512 VNNI, polynomial products still use the kernel call. Cause: only the AVX2 dot product has been written so far; the AVX2 polynomial product is in the next phase.
- 256 × 256 polynomial products on Ice Lake are 5–7% slower than the kernel call. Cause: under investigation.
- A 16 × 16 product into an Int64List on EPYC Zen 4 is 0.87× clang. Cause: the generated code's fixed costs dominate a nest of 256 products.
- Only these shapes are recognised. A nest with an
ifother than a zero-factorcontinue, a bound that changes inside the nest, a non-linear index (a[i * i],a[idx[i]]) or two products in one body runs as written. Cause: the recogniser matches a fixed set of shapes by design. - Element types are narrow. The data side must be bytes; taps may be 8- or 16-bit; matrix products are byte by byte. Wider operands, such as
Int64Listcounts, fall back to the vectoriser. Cause: the kernels are written for the CPUs' 8- and 16-bit dot-product instructions. - Small loops gain least. The closest margins are a 64 × 64 polynomial product on Graviton3 (1.27×) and a 256 × 256 3 × 3 convolution on Zen 4 (1.38×). Cause: under investigation. The call and its checks also cost a fixed few tens of nanoseconds, which matters most on small nests; for dot and polynomial products version 1.2 removes that cost (see Results).
- CPU support. Recognised nests need AVX-512 with VNNI on x86 (byte dot products also run on CPUs with AVX2 only, through the compiler's own AVX2 code) and the dot-product instructions on Arm (matrix products and signed taps also need I8MM, Graviton3 and later); elsewhere the loops run as written. AOT builds only, not the JIT. Cause: by design.
- The C side is plain C. The baselines are the same loops compiled by gcc and clang, not hand-written intrinsics or a tuned library. The C dot product sums into
int64_t, matching what Raya'sintmeans; that stops gcc and clang from using the narrow dot-product instructions and likely widens the Graviton dot-product margins. Cause: the comparison measures what each compiler makes of the same ordinary loop.
Reproduction notes
- Software. Raya is open source at github.com/riptide-compute/raya. This work is on the main branch after the 0.4.0 release (no flags needed in AOT builds); it is not yet in a tagged release. The benchmark sources, C baselines and the raw results are in the repository under
benchmarks/RayaIntVec/, with the full per-CPU tables in the repository documentdocs/raya/performance/integer-vectorization.mdand on riptidecompute.com/raya/compiler. - Switches.
--no-raya-nest-kernelsturns recognition off at run time (the "vectoriser alone" bars);--trace-raya-nestprints, for each nest, what ran and why;--no-raya-nest-codegensends dot and polynomial nests back to the kernel call (the "kernel call" column in version 1.2). - Version 1.2 measurements. On Raya main after the change that adds the compiler's own code (public main
fff0e3111ce); raw results underbenchmarks/RayaIntVec/results/2026-12-01-codegen/.
References
- GCC 13: the GNU Compiler Collection, gcc.gnu.org.
- Clang 18 and LLVM, llvm.org.
- Arm Architecture Reference Manual for A-profile architecture (dot-product, I8MM and SVE instructions).
- Intel 64 and IA-32 Architectures Software Developer's Manual (AVX-512 VNNI and AMX).
- AMD64 Architecture Programmer's Manual (AVX-512 on Zen 4).
Date and version
Version 1.3, 1 December 2026. Measurements from 1 December 2026. Updated 1 December 2026: added Method section (1.1); compiler-generated code for dot and polynomial products (1.2). Updated 1 December 2026: limitations section retitled.
Working with Riptide
Riptide works with a small number of teams. Each engagement starts with 4 weeks inside your systems, learning how your models, data and infrastructure work. Only then does Riptide apply its software to them. Contact samario@riptidecompute.com or riptidecompute.com/evaluate.