webcentive


Assembly vs C for AI: an ODROID-HC1 Experiment

By @tonycasanova, North Carolina, with Grok

Main results: three locked-clock runs. Governor performance (A15 at 2.0 GHz, A7 at 1.4 GHz), Grafana/Prometheus stopped, 60-second cool-down between runs. Run IDs 20261202-214055, 214214, and 214334 (2 December 2026, starting 9:40 p.m. Eastern). Built with gcc 9.4.0, kernel 5.4.275. Each cell below is the mean of the three run medians (each median is 21 timed calls) and the sample coefficient of variation (CV%, n−1). Speedup is mean(naive) / mean(variant). All variants verified; INT8 results were exact.
Companion page: llama.cpp tuning on this ODROID-HC1 (performance governor, monitors, Q4_0 vs Q8_0).

Why matvec dominates LLM inference

Generating one token with a language model multiplies a big weight matrix by a single vector, layer after layer. With one vector there is little reuse of each weight, so the work is a stream of multiply-adds over data that mostly has to come from RAM. Speed is therefore set by how many multiply-adds the CPU can issue (SIMD width, quantization) and by memory bandwidth. This is the same reason the llm.asm project spends its effort on an INT8 AVX2 kernel; see the Phase 2 README, whose own benchmark table credits the INT8 kernel for most of its lead over llama.cpp, with a smaller extra gain from the bare-metal environment.

The seven variants

  1. float32, naive C at -O0: the baseline, in its own object file.
  2. float32, same C at -O3 -ffast-math: lets GCC auto-vectorize with NEON.
  3. float32 NEON intrinsics (vmlaq_f32), four accumulators.
  4. float32 hand-written ARMv7 NEON assembly, unrolled, with pld prefetch.
  5. INT8 C reference at -O3 (exact integer result).
  6. INT8 NEON intrinsics (vmull_s8 / vpadalq_s16).
  7. INT8 hand-written NEON assembly.

Every variant is verified against a reference before it is timed; a mismatch stops the run.

Hypothesis

That was the prediction. The measured three-run results are below.

Method and hardware

Board: ODROID-HC1, Samsung Exynos 5422 (4× Cortex-A15 on CPUs 4–7, 4× Cortex-A7 on CPUs 0–3), 32-bit ARMv7 hard-float, NEON/VFPv4, 2 GB RAM, Ubuntu 20.04, kernel 5.4.275, gcc 9.4.0. Flags: -mcpu=cortex-a15 -mfpu=neon-vfpv4 -mfloat-abi=hard. Shapes (rows × cols): 1024×1024, 2048×2048, and 4864×896. One thread, taskset -c 4-7 then core 0. Each run: 3 warmup calls and 21 timed calls, median kept; clock_gettime(CLOCK_MONOTONIC); 64-byte aligned buffers; fixed seed. The three runs reported here used the performance governor with the clocks held at their maxima, a 60-second pause between runs, and Grafana/Prometheus stopped. Temperature was not recorded. A first run under the ondemand governor is noted separately and is not mixed into these means.

Run 1 on the A15 was a warm-up outlier: float32 assembly at 1024×1024 took 1,959,210 ns versus about 1.04–1.08 million in runs 2 and 3, and -O3 C took 1,690,252 ns versus about 1.32 million. Several other A15 cells in run 1 were also slow. The tables use all three runs, so those CVs are large (up to 38%). Dropping run 1 brings most of those A15 CVs down below 3%. The A7 numbers were stable in all three runs (CV 0.18–2.93%).

Results (performance governor, three-run mean)

Times are the mean, over three runs, of each run’s median nanoseconds per matrix-vector multiply. CV% is the sample standard deviation of those three medians, divided by the mean. GFLOP/s (GOP/s for INT8) counts two operations per element. GB/s is bytes of W, x and y per call, divided by the mean time. Speedup is versus variant 1 on the same core and shape, using the means. CV values of 5% or more are marked in bold.

Cortex-A15, taskset -c 4-7, one thread, 2.0 GHz

A15 · 1024 × 1024 (W f32 4.2 MB, W i8 1.0 MB)
VariantMean nsCV%GFLOP/s or GOP/sGB/sSpeedup vs 1
1 f32 C -O0 (naive)8,714,1100.070.2410.4821.00×
2 f32 C -O3 autovec1,444,46114.741.4522.9096.03×
3 f32 NEON intrinsics1,106,4748.411.8953.7987.88×
4 f32 NEON assembly1,359,43238.241.5433.0916.41×
5 i8 C -O3 autovec519,6406.874.0362.02816.77×
6 i8 NEON intrinsics196,1392.8210.6925.37244.43×
7 i8 NEON assembly198,0703.8910.5885.32044.00×
A15 · 2048 × 2048 (W f32 16.8 MB, W i8 4.2 MB)
VariantMean nsCV%GFLOP/s or GOP/sGB/sSpeedup vs 1
1 f32 C -O0 (naive)34,925,2060.590.2400.4811.00×
2 f32 C -O3 autovec6,164,98114.521.3612.7245.67×
3 f32 NEON intrinsics5,001,34117.241.6773.3586.98×
4 f32 NEON assembly5,035,63218.011.6663.3356.94×
5 i8 C -O3 autovec2,240,0312.063.7451.87715.59×
6 i8 NEON intrinsics1,369,34913.756.1263.07025.50×
7 i8 NEON assembly1,212,91912.876.9163.46628.79×
A15 · 4864 × 896 (W f32 17.4 MB, W i8 4.4 MB)
VariantMean nsCV%GFLOP/s or GOP/sGB/sSpeedup vs 1
1 f32 C -O0 (naive)36,175,8750.310.2410.4831.00×
2 f32 C -O3 autovec6,453,17615.891.3512.7055.61×
3 f32 NEON intrinsics4,859,2854.021.7943.5927.44×
4 f32 NEON assembly4,836,8273.451.8023.6097.48×
5 i8 C -O3 autovec2,292,5031.893.8021.91015.78×
6 i8 NEON intrinsics1,353,6973.546.4393.23426.72×
7 i8 NEON assembly1,228,9883.967.0923.56329.44×

Speedup vs naive C (-O0), three-run mean — Cortex-A15

Bar length is linear in speedup versus the -O0 baseline, using the three-run mean times (max 44.43×). Float variants are the darker bars; INT8 the lighter ones. A15 CVs on several cells are high because run 1 was a warm-up outlier; those bars are means, not tight estimates.

1024 × 1024

1 f32 C -O0 (naive)1.00×
2 f32 C -O3 autovec6.03×
3 f32 NEON intrinsics7.88×
4 f32 NEON assembly6.41×
5 i8 C -O3 autovec16.77×
6 i8 NEON intrinsics44.43×
7 i8 NEON assembly44.00×

2048 × 2048

1 f32 C -O0 (naive)1.00×
2 f32 C -O3 autovec5.67×
3 f32 NEON intrinsics6.98×
4 f32 NEON assembly6.94×
5 i8 C -O3 autovec15.59×
6 i8 NEON intrinsics25.50×
7 i8 NEON assembly28.79×

4864 × 896

1 f32 C -O0 (naive)1.00×
2 f32 C -O3 autovec5.61×
3 f32 NEON intrinsics7.44×
4 f32 NEON assembly7.48×
5 i8 C -O3 autovec15.78×
6 i8 NEON intrinsics26.72×
7 i8 NEON assembly29.44×

Cortex-A7, taskset -c 0, one thread, 1.4 GHz

A7 · 1024 × 1024 (W f32 4.2 MB, W i8 1.0 MB)
VariantMean nsCV%GFLOP/s or GOP/sGB/sSpeedup vs 1
1 f32 C -O0 (naive)41,558,6061.860.0500.1011.00×
2 f32 C -O3 autovec10,669,0300.520.1970.3943.90×
3 f32 NEON intrinsics4,450,3822.260.4710.9449.34×
4 f32 NEON assembly4,422,3952.580.4740.9509.40×
5 i8 C -O3 autovec2,786,8371.140.7530.37814.91×
6 i8 NEON intrinsics1,224,6830.951.7120.86033.93×
7 i8 NEON assembly1,177,6821.261.7810.89535.29×
A7 · 2048 × 2048 (W f32 16.8 MB, W i8 4.2 MB)
VariantMean nsCV%GFLOP/s or GOP/sGB/sSpeedup vs 1
1 f32 C -O0 (naive)166,404,0821.470.0500.1011.00×
2 f32 C -O3 autovec42,862,4020.380.1960.3923.88×
3 f32 NEON intrinsics18,433,4880.660.4550.9119.03×
4 f32 NEON assembly18,287,9870.530.4590.9189.10×
5 i8 C -O3 autovec12,632,0482.660.6640.33313.17×
6 i8 NEON intrinsics5,301,2591.321.5820.79331.39×
7 i8 NEON assembly5,209,0922.931.6100.80731.94×
A7 · 4864 × 896 (W f32 17.4 MB, W i8 4.4 MB)
VariantMean nsCV%GFLOP/s or GOP/sGB/sSpeedup vs 1
1 f32 C -O0 (naive)173,280,0591.520.0500.1011.00×
2 f32 C -O3 autovec44,290,5450.330.1970.3943.91×
3 f32 NEON intrinsics18,970,7952.120.4590.9209.13×
4 f32 NEON assembly18,826,8921.880.4630.9279.20×
5 i8 C -O3 autovec13,335,6610.320.6540.32812.99×
6 i8 NEON intrinsics5,534,1760.181.5750.79131.31×
7 i8 NEON assembly5,530,1760.611.5760.79231.33×

Speedup vs naive C (-O0), three-run mean — Cortex-A7

Bar length is linear in speedup versus the -O0 baseline, using the three-run mean times (max 44.43×). Float variants are the darker bars; INT8 the lighter ones. A15 CVs on several cells are high because run 1 was a warm-up outlier; those bars are means, not tight estimates.

1024 × 1024

1 f32 C -O0 (naive)1.00×
2 f32 C -O3 autovec3.90×
3 f32 NEON intrinsics9.34×
4 f32 NEON assembly9.40×
5 i8 C -O3 autovec14.91×
6 i8 NEON intrinsics33.93×
7 i8 NEON assembly35.29×

2048 × 2048

1 f32 C -O0 (naive)1.00×
2 f32 C -O3 autovec3.88×
3 f32 NEON intrinsics9.03×
4 f32 NEON assembly9.10×
5 i8 C -O3 autovec13.17×
6 i8 NEON intrinsics31.39×
7 i8 NEON assembly31.94×

4864 × 896

1 f32 C -O0 (naive)1.00×
2 f32 C -O3 autovec3.91×
3 f32 NEON intrinsics9.13×
4 f32 NEON assembly9.20×
5 i8 C -O3 autovec12.99×
6 i8 NEON intrinsics31.31×
7 i8 NEON assembly31.33×

Do assembly gains hold up?

For each run, the assembly-versus-intrinsics delta is (time of the intrinsics kernel / time of the assembly kernel − 1), as a percent. Positive means assembly was faster. A result is flagged as holding up only if all three runs have the same sign and the mean delta is larger than about twice the combined CVs of the two kernels, taken as 2 × hypot(CVintrinsics, CVassembly). That is a conservative test on only three runs.

Assembly vs NEON intrinsics (positive = assembly faster)
CoreShapeKindR1R2R3MeanRange2×hypot(CV)Holds up?
A151024 × 1024f32-38.16%-0.35%-0.71%-13.07%-38.16% to -0.35%78.31%No
A151024 × 1024i8-2.80%-1.06%+1.05%-0.94%-2.80% to +1.05%9.61%No
A152048 × 2048f32-1.42%-0.12%-0.25%-0.60%-1.42% to -0.12%49.86%No
A152048 × 2048i8+14.00%+13.04%+11.42%+12.82%+11.42% to +14.00%37.66%No
A154864 × 896f32+1.12%+0.03%+0.21%+0.45%+0.03% to +1.12%10.60%No
A154864 × 896i8+9.46%+11.53%+9.50%+10.16%+9.46% to +11.53%10.63%No
A71024 × 1024f32+0.22%+0.72%+0.97%+0.64%+0.22% to +0.97%6.87%No
A71024 × 1024i8+4.36%+3.90%+3.72%+3.99%+3.72% to +4.36%3.16%Yes
A72048 × 2048f32+0.76%+0.63%+0.99%+0.80%+0.63% to +0.99%1.70%No
A72048 × 2048i8+2.62%+2.93%-0.15%+1.80%-0.15% to +2.93%6.42%No
A74864 × 896f32+1.40%+0.38%+0.50%+0.76%+0.38% to +1.40%5.67%No
A74864 × 896i8+0.50%-0.42%+0.14%+0.07%-0.42% to +0.50%1.27%No

Under that rule, only one comparison holds up: A7 INT8 at 1024×1024, where assembly is 4.0% faster than intrinsics (range 3.7% to 4.4%). No float32 assembly advantage holds up; the per-run differences are typically under 1.5% once the run-1 A15 1024×1024 outlier (assembly 38% slower in that one run) is read as a warm-up, not as a kernel effect.

Two A15 INT8 cases are consistent in sign and size — +11.4% to +14.0% (mean +12.8%) at 2048×2048, and +9.5% to +11.5% (mean +10.2%) at 4864×896 — but they do not pass the test on all three runs, because run 1 inflates the CVs of the absolute times (the two kernels slowed together). If run 1 is dropped, both would pass a 2×CV test. They are noted here as suggestive, not as confirmed under the pre-set rule.

Findings and conclusion

INT8 SIMD is still the large effect. Against naive float32 C at -O0, the INT8 NEON kernels (variants 6 and 7) are 25–44× faster on the A15 and 31–35× faster on the A7, using three-run means. The 1024×1024 INT8 case remains the outlier (about 44× on the A15): that weight matrix is 1.0 MB and the effective bandwidth is 5.3–5.4 GB/s, versus about 3.1–3.6 GB/s on the 4 MB+ INT8 shapes, which look more memory-bound.

NEON already beats auto-vectorized C, before anyone writes assembly. Float32 NEON intrinsics are 1.23–1.33× the -O3 autovec kernel on the A15, and 2.33–2.40× on the A7, from the three-run means of variants 3 and 2.

Conclusion. On this board, with the clocks locked, the 25–44× gains come from SIMD, INT8, and cache or memory bandwidth — not from writing the kernel in assembly rather than C intrinsics. Hand-written assembly beat well-written NEON intrinsics in only one comparison that clears a simple three-run consistency test (about 4% on the A7, INT8, 1024×1024). That is consistent with llm.asm, whose published gains over llama.cpp come mainly from its INT8 kernel, not from deleting the operating system or from assembly as such.

First run (ondemand)

An earlier single run, 20261202-213433, used the ondemand governor (the script saw 1.0 GHz at start; maxima 2.0 / 1.4 GHz). Those figures are not included in the means above and should not be compared directly with the locked-clock numbers. Qualitatively they already showed the same story: INT8 NEON was the large win (18–49× vs naive), and assembly versus intrinsics was mixed. That run also did not record temperature, and it was only one 21-repetition pass, so run-to-run variation was unknown until the three performance runs.

Caveats

Tie-in to llm.asm

The llm.asm project (MIT) writes Qwen3-0.6B inference and a bootable x86-64 OS in assembly. Its published EPYC 7642 table shows an exact FP32-activation assembly path slower than llama.cpp Q8_0, and an INT8 path faster, which is why this experiment tests float and INT8 separately. The project is x86-64 (AVX2/FMA/F16C) and cannot run on this 32-bit ARM board; this kit asked the same question with ARM NEON and, after three locked-clock runs, got the same qualitative answer. Related reading: issue #29 (independent reproduction), the @IntCyberDigest post, the Qwen3-0.6B model card and the official GGUF repository.

Data

Computed three-run summary (means, sample SD, CV%, speedups and assembly-versus-intrinsics deltas): results/summary-3runs.csv.

Raw board output, one pair per run (each run’s median of 21 timed calls). The first run used the ondemand governor; the next three used performance with a 60-second cool-down:

The four raw run files are copied onto the server alongside this page; if a link 404s, the file has not been placed in results/ yet.

How to reproduce

The benchmark kit is in kit/. Download kit/asmbench.zip, or browse the sources: bench.c, kernels.h, naive_o0.c, kernels_c.c, kernels_neon.c, matvec_neon.S, Makefile, run.sh, and README.md.

unzip asmbench.zip && cd asmbench
make
# optional, for locked clocks (the script does not change the governor):
echo performance | sudo tee /sys/devices/system/cpu/cpu4/cpufreq/scaling_governor
echo performance | sudo tee /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
for i in 1 2 3; do ./run.sh; sleep 60; done

Stop llama.cpp and other heavy jobs first. Each call writes results-<date>.csv and .txt.