← Back to all posts
Tools

llm.asm Beats llama.cpp CPU Decode by Up to 36% Running Qwen3 in Pure Assembly

November 27, 2026 · 00:11 UTC · Tools
On this page 8 sections
llm.asm Beats llama.cpp CPU Decode by Up to 36% Running Qwen3 in Pure Assembly

TL;DR

llm.asm is a one-developer project that runs an entire LLM stack in 17,252 lines of hand-written x86-64 NASM: a 14,712-byte static Linux binary that serves Qwen3-0.6B, a 24,252-byte bootable OS whose only job is chatting with that model, and a from-scratch Mini-GPT trainer with a live Braille TUI. There is no C, no libc, and no runtime dependency anywhere in it, and the license is MIT. In the author's head-to-head on an AMD EPYC 7642, the assembly engine decodes the same Q8_0 weights 18 to 36 percent faster than llama.cpp across 1 to 40 threads and still emits the same 64 greedy tokens as PyTorch. The bare-metal half reached the Hacker News front page as "Bare Metal Qwen" on November 25, where it holds 227 points.


At a glance
An LLM stack with nothing underneath
17,252
lines of hand-written nasm across three projects
+36%
peak decode win vs llama.cpp q8_0, at 4 threads
14,712 B
static ELF that runs qwen3-0.6b, zero dependencies
24,252 B
bootable LLM OS, boots in 74-94 ms
64/64
greedy tokens matching pytorch fp32
134.9
tok/s at 16 kvm vCPUs on the bare-metal OS

Three artifacts over one shared core

The repo splits into three phases on top of a shared assembly core of math, matmul, tokenizer, and transformer routines: 3,857 lines that all three binaries include. Phase one, asm-llm, is a static ELF that implements the full Qwen3 architecture, with 16 query heads and 8 KV heads at head_dim 128, per-head QK-Norm before RoPE, a SwiGLU MLP, tied embeddings, and a multi-turn KV-cache chat REPL supporting /clear and /think. The BPE tokenizer is also assembly: a 524,288-slot Fibonacci-hashed merge table that matches the HuggingFace tokenizer token for token.

Weights arrive through a one-time Python export into a custom .asmbin format, 613.66 MiB for Q8_0 against 1.40 GiB of BF16 safetensors, with every row 64-byte aligned so the engine can mmap() it zero-copy. Python is never needed at runtime.

Phase two is the part HN found. The same four core files compile with a -DBARE_METAL flag that swaps Linux syscalls for physical memory, APIC spin barriers, and VGA, PS/2, and serial drivers, producing a kernel that boots straight into a chat REPL with no Linux underneath it. One commenter called it a brain in a jar, which undersells the jar: this one starts answering in under a tenth of a second.

Phase three trains a 2.68M-parameter Mini-GPT from scratch: a register-blocked 6x16 AVX2+FMA SGEMM, the full analytical backward pass, decoupled AdamW, and an 80x24 Braille TUI that draws the loss curve in Unicode dots. On TinyShakespeare it walks val loss from 4.19 to 1.51 in about four minutes, at 27,662 train tokens per second.

How the OS boots
Multiboot to chat REPL in under a tenth of a second
Boot
Multiboot 1 loads the kernel
weights ride along as a boot module
Long mode
Paging on, 64-bit, AVX2/FMA/F16C
cpuID-checked, IDT installed
SMP
ACPI MADT, AP trampoline
INIT-SIPI-SIPI spin barriers
Chat
VGA, PS/2 and COM1 REPL
multi-turn KV cache, /clear /think /bench
Measured boot: 74-94 ms. Throughput: 134.9 tok/s at 16 KVM vCPUs on EPYC, 55.4 tok/s live on a Proxmox VE VM with a 0 GB disk. Source: llm.asm README.

The benchmark

Every number in the head-to-head comes from the author's runs on one machine: an AMD EPYC 7642 with 47 cores online, both engines loading the same Qwen3-0.6B Q8_0 weights, 34 prompt tokens and 64 generated tokens, three-run averages, with llama.cpp driven through llama-bench -ngl 0.

Decode tok/s, Qwen3-0.6B Q8_0
The assembly engine leads at every thread count
llama.cpp, llama-bench -ngl 0llm.asm fast_q8=1
1 thread
llm.asm
20.70 +24.5%
llama.cpp
16.63
4 threads
llm.asm
69.24 +35.6%
llama.cpp
51.08
8 threads
llm.asm
103.64 +28.3%
llama.cpp
80.79
16 threads
llm.asm
121.86 +18.3%
llama.cpp
103.03
64-token greedy decode, 3-run means on an AMD EPYC 7642 (47 cores online). The gap peaks at 4 threads and narrows as thread count rises. Source: llm.asm README, author-run.

The fast path is integer arithmetic. FAST_Q8=1, the default, quantizes activations to Q8_0 once per matmul and runs INT8xINT8 through AVX2. The exact-path build, which keeps FP32 activations, manages 7.18 tok/s at one thread against llama.cpp's 16.63, so the entire win lives inside the integer kernel.

Prefill runs the other way. llama.cpp batches prompt processing with GEMM, 56 to 1,113 tok/s in these runs, while llm.asm walks the prompt token by token with GEMV, 26.7 to 160.8 tok/s. Hand it a long document and the 14 KB binary is the slow one, by roughly 2x to 7x.

Where the speed comes from

Decoding a token means dragging all 613.66 MiB of weights past the CPU. Once the arithmetic is vectorized, the remaining job is freight: the faster engine is the one whose next row of weights is already on the truck when the cores ask for it.

The fast path
What the INT8 kernel is made of
int8 x int8 vpmaddubswfp16 block scales via f16cmonotonic next-row prefetchhead-major contiguous kv cacheparallel gqa attentionclone + futex thread pool
All hand-written NASM in the shared core, reused by the Linux binary and the bare-metal OS. Source: llm.asm README.

Two properties are worth stealing outright. Output is bit-exact from 1 to 40 threads, which turns regression testing into a byte comparison. And the bare-metal build picks up another 10 percent from 2 MiB huge-page identity mapping, one of the perks of being your own operating system.

Correctness receipts

Each phase ships with a verification harness. The fast path matches PyTorch FP32 Qwen3-0.6B with 0.9997 logits cosine and identical greedy tokens; the exact path matches the Python Q8_0 reference with cosine 1.000000000 and a max difference of 1.53e-5. The trainer was checked tensor by tensor against PyTorch CPU: all 21 parameter tensors, worst absolute difference 3.35e-8, plus a 10-step AdamW trajectory within 4.77e-7 loss of the reference.

Verification
Checked against PyTorch at every layer
64/64
greedy tokens match pytorch fp32, fast path
1.0000000
gradient cosine, all 21 tensors, to ten digits
3.35e-8
worst absolute gradient diff vs pytorch cpu
1-40T
bit-exact output across every thread count

The receipts matter because the HN thread arrived skeptical, with reason: one commenter pointed out that a lot of "beats llama.cpp" claims quietly prune experts or quantize harder than the baseline. Here both engines ran the same Q8_0 quant and the output tokens match the reference implementations. The timing figures are still one author's runs on one CPU, and nobody outside the repo has replicated them.

Why you would bother

llama.cpp runs hundreds of models, dozens of quantizations, CPUs and GPUs alike. llm.asm runs one model, one quant, one instruction set, and collects 18 to 36 percent for the focus. If your product serves exactly one model on fixed hardware, some of that margin is currently sitting in your inference bill.

  • It is readable end to end. 17,252 lines covers tokenizer, transformer, matmul kernels, a backward pass, a thread pool, and an OS; as an executable anatomy course on inference, it beats a semester of slides.
  • A 24 KB OS with no syscalls, no package updates, and no disk makes a small attack surface for an appliance that does one thing, booting to first token in under a tenth of a second from RAM.
  • Trying it costs a compatible CPU and two packages. Anything with AVX2, FMA, and F16C works, which means Intel Haswell (2013) onward; install nasm and binutils, then make all.

Caveats

  • The benchmark is the author's own, on one CPU, with the llama.cpp build and version not pinned in the published table. Treat the percentages as promising until replicated.
  • Decode only. Prefill is roughly 2x to 7x slower than llama.cpp's batched GEMM, and the FP32-activation build loses at low thread counts.
  • One model, one quant, CPU only. The KV cache defaults to 2048 tokens, and there is no server, no batching, and no GPU path.
  • Qwen3-0.6B is a small model. Nobody is putting it in front of customers; the engineering is the story.

Key Takeaways

  • llm.asm is 17,252 lines of pure x86-64 NASM under MIT: a Qwen3-0.6B inference binary (14,712 bytes), a bootable LLM OS (24,252 bytes, 74-94 ms boot), and a Mini-GPT trainer (32,944 bytes).
  • On the author's EPYC 7642 runs, the fast path decodes Q8_0 18-36% faster than llama.cpp across 1-40 threads: 20.70 vs 16.63 tok/s at one thread, 121.86 vs 103.03 at 16.
  • The speed comes from INT8 AVX2 kernels, FP16 block scales, next-row prefetch, and a contiguous head-major KV cache; decode is bandwidth-bound, so memory layout decides the result.
  • Output is bit-exact across 1-40 threads, and correctness is verified against PyTorch: identical greedy tokens on inference, gradients within 3.35e-8 on all 21 trainer tensors.
  • Prefill is 2x-7x slower than llama.cpp, the FP32-activation build loses at one thread, and the timings are unreplicated author runs.
  • Anyone with an AVX2+FMA+F16C CPU (Haswell 2013 onward) can build it with nasm and binutils and run make all.

Sources: alesha-pro/llm.asm on GitHub, Phase 1 inference README with the full benchmark table, Phase 2 bare-metal OS, Hacker News discussion, Nov 25, 2026, AlphaSignal coverage

AIllm.asmQwen3llama.cppx86-64 AssemblyCPU InferenceOpen SourceBare Metal
CONSOLE
$