Cygnet: a Forth interpreter in pure LLVM IR runs Qwen3 inference 9.76x faster than C
solidavocadorock · reddit · 2026-11-30
Inspired by Alexey Fateev's llm.asm (hand-written x86-64 assembly running AI on bare metal, Ring -1 hypervisors and eBPF LSM hooks), the author built Cygnet: a from-scratch Forth interpreter/compiler written in pure LLVM IR (.ll), with five AI phases implemented as compact portable Forth (.fs) programs.
Key design points:
- All control flow (layer loops, KV-cache indexing, decision gates, training steps, fault triage) lives in Forth; Thinking Forth factorization shrank 4 programs from 14,981B to 5,989B (-60%)
- The Forth VM is written directly in pure LLVM IR: interpreter state pinned in SSA registers, 16KB string dictionary replaced by a 1KB O(1) FNV-1a hash table, compile-time inlining and LIT-fusion
- Hot vector primitives hand-written as LLVM IR SIMD: ARM64 NEON sdot.4s + addp.4s reductions, x86-64 AVX2 vpmaddwd/vphaddd, 4-row Q80 FMA, fused SGEMM+SiLU; the same Forth script runs on both ARM64 and x86-64
Benchmarks on Ryzen 9 7950X (QEMU/KVM, Ring 0): Phase 01 Qwen3 Q80 inference hits 33,236 tok/s vs 3,406 tok/s for reference C -O2 (9.76x) with 16/16 exact tokens; Phase 02 is a 16,664B bare-metal Ring 0 Forth OS booting in 45ms; Phase 03 trains a from-scratch Mini-GPT on TinyShakespeare at 206,941 tok/s (loss 4.17→2.08); Phase 04's kernel-patch policy passes 122/122 held-out scenarios (vs 119/122 for GRPO MiniCPM5-2B) at 139.2ns per decision.
More from Infra
- 17 new AI chips landing by 2027, 14 of them from non-Nvidia vendors — AccBalanced · 2026-11-30
- Hot Aisle founder battles renewed credit card fraud attacks on his compute platform — AccBalanced · 2026-11-30
- Polymarket's GPU markets look bearish, but thin liquidity means few wallets move prices — AccBalanced · 2026-11-30
- SGLang PR adds hot-reload so kernel-writing AI agents iterate without server restarts — AccBalanced · 2026-11-30
- HiPerfCC-KVCache boosts confidential LLM serving throughput 1.74x in SGLang — AccBalanced · 2026-11-30
- Why Anthropic's tokenizer shrinks to 16k vocab while rivals use 100k-256k — teortaxesTex · 2026-11-30