TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 229 subscribers
Post #24651 22
My C++ compiler just wrote its own fan-fiction (inference at compile-time)

Not really, but at least it generated its own main characters.

I've been obsessed with pushing language models into places they don't belong. Last summer it was a 1KB bigram model for the NES written in 6502 assembly. This week, I decided that even 1983 hardware was too much runtime for me.

So I built a bigram language model that runs entirely during the C++ compilation phase.

Technically it's a Markov chain implemented via constexpr and template metaprogramming. The model's weights are hardcoded in an array. A fun part was implementing the random number generator: since compilers are (mostly) deterministic (rightfully so), I hashed __TIME__ and __DATE__ using an FNV-1a algorithm to seed a constexpr Xorshift32 RNG.

When you run the binary, the CPU does zero math. It just prints a string that was hallucinated by the compiler, different at each compile.

    // this line does all the work while you're getting coffee
static constexpr NameGenerator<15> result(seed, T);

int main() {
// just printing a constant baked into the data segment
std::cout << [result.name](http://result.name) << std::endl;
}


Aside from the fun of it, I hope it proves a point that the bottleneck isn't always our hardware. We have wiggle room to redefine when execution should happen, and bake deterministic inference directly into the binary.

Code is here: https://github.com/erodola/bigram-metacpp

https://redd.it/1q830rk
@r_cpp
GitHub GitHub - erodola/bigram-nes: Tiny AI model embedded in NES ROMs to generate character names in-game. Tiny AI model embedded in NES ROMs to generate character names in-game. - erodola/bigram-nes
More from @r_cpp
  1. Oct 8, 2026Profiles for simplicity and guarantees - Bjarne Stroustrup - CppCon 2026 https://youtu.be/…
  2. Oct 8, 2026How to Fix autoconf-style Configuration Probing https://build2.org/blog/fix-autoconf.xhtml…
  3. Oct 8, 2026owl – a header-only C++23 HTTP framework where route patterns and handler extractors are c…
  4. Oct 8, 2026Removed by Reddit Removed by Reddit on account of violating the [content policy. ] https:/…
  5. Oct 8, 2026Is there a way to search across all P and N papers throughout standardization history? It…
  6. Oct 8, 2026CppCast Episode 412 : Safety and Interoperability with Rust and C++ https://cppcast.com/sa…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →