# asmbench: assembly vs C for AI (ODROID-HC1)

A small benchmark kit by [@tonycasanova](https://x.com/tonycasanova) (North Carolina), with [Grok](https://grok.com).
It times a matrix-vector multiply (the core operation of LLM token generation) in seven ways on
the ODROID-HC1 (Exynos 5422, ARMv7 hard-float, NEON/VFPv4):

| # | variant |
|---|---------|
| 1 | float32 naive C, built at `-O0` (separate object) |
| 2 | float32 same C at `-O3 -ffast-math` (auto-vectorized) |
| 3 | float32 NEON intrinsics (`vmlaq_f32`) |
| 4 | float32 hand-written NEON assembly (`matvec_neon.S`) |
| 5 | INT8 C reference at `-O3` |
| 6 | INT8 NEON intrinsics (`vmull_s8` / `vpadalq_s16`) |
| 7 | INT8 hand-written NEON assembly |

Shapes (rows x cols): 1024x1024, 2048x2048 and 4864x896 (Qwen-0.5B-like FFN). Every variant is
checked against a reference (float: max abs error vs a double-precision reference; INT8: exact
integer match) and the program exits with status 2 and prints `FAIL` on any mismatch.
It reports median ns per call, ns per multiply-accumulate, GFLOP/s (GOP/s for INT8), effective
GB/s (bytes of W, x and y per call / time) and speedup vs variant 1. Method: `clock_gettime(CLOCK_MONOTONIC)`,
3 warmup calls, 21 timed calls (median), 64-byte aligned buffers, fixed RNG seed.

## Build and run (on the ODROID, Ubuntu 20.04, gcc 9)

    sudo apt install build-essential     # if gcc/make are missing
    unzip asmbench.zip && cd asmbench
    make
    ./run.sh            # or: ./run.sh 41   for 41 runs per variant

`run.sh` prints system info, pins one thread with `taskset -c 4-7` (A15) and then on `taskset -c 0`
(A7), and writes `results-<date>.csv` and `results-<date>.txt`. It does not change your CPU
governor; it suggests `performance`. Stop llama.cpp and other heavy jobs first.

Cross-compile check on an x86 box: `make CC=arm-linux-gnueabihf-gcc STATIC=1` and
`QEMU_CPU=cortex-a15 qemu-arm ./bench -n 1 -w 0` (verifies correctness only; QEMU timings mean nothing).

## Notes

- Float variants sum in different orders, so they differ from each other in the last bits;
  the check uses a small tolerance. INT8 results are exact.
- Variant 2 needs `-ffast-math` or GCC will not vectorize a float reduction. Stated openly in the Makefile.
- Memory-bound shapes (4864x896 float is 17 MB) mostly measure DRAM bandwidth, which is the point.

## Sending results back

Send the `results-*.txt` and `results-*.csv` files to [@tonycasanova on X](https://x.com/tonycasanova)
(or paste the `.txt`). Include anything unusual (governor, throttling, other jobs running).
