Post

Compressing Wikipedia with XOR, Popcount and SDOT

Compressing Wikipedia with XOR, Popcount and SDOT

A gigabyte of Wikipedia, as bits

Introduction

Some people think “Comnpression is Intelligence”, but Marcus Hutter put his money where his mouth is, and offers €5,000 for every percent you can squeeze down the first gigabyte of an English Wikipedia dump smaller than the current record. The people who have won a chunk of the prize money usually run descendants of cmix, and hundreds of hand-built context models, a small neural network mixing them, gigabytes of RAM, and days of CPU time to compress one file.

The premise of the Hutter Prize is that compressing text well requires understanding it. A model that knows English, and Wikipedia, and how articles are put together, can guess the next byte better, and every better guess is a smaller file.

No, I didn’t win anything.

I definitely gave is a shot, and though I didn’t win on the compression ratio (the intelligence), I still built something I pretty cool: a 7 MB network made of XORs, popcounts and INT8 dot products that compresses Wikipedia text about as well as cmix, while running 38 times faster and using a thousandth of the memory, while neatly fitting in the L2 cache of a single M4 core.

In the last post, an M4 CPU learned to tell children’s stories with a language model built from the the ISA instructions set: FCMGE compares to make bits, EXT/BSL/EOR logic to transform them, CNT and SDOT to turn them back into numbers. The obvious next step was poking at one of the oldest questions in machine learning: how well can you predict the next byte?

This whole project is tailored to the Apple M4 Pro CPU, but could be tuned to any CPU instruction set and L2 cache size. That said, here as the specifics for the M4:

  • enwik9 (the first gigabyte of an English Wikipedia dump) goes down to 155,874,783 bytes, and comes back out byte-for-byte identical. With the zipped decompressor and its embedded 7 MB model, that’s 161,855,306 bytes, 1.295 bits per byte, which would sit about 56th on Matt Mahoney’s Large Text Compression Benchmark, a few places behind PPMonstr.
  • On held-out Wikipedia text, on the same Mac, it compresses within 0.1 % of cmix v21, one of the strongest compressors ever written, while running 38× faster on one core and using 14 MB of memory instead of 18.6 GB.

TL;DR: a 7 MB integer/Boolean network that never leaves the L2 cache compresses Wikipedia about as well as cmix on a megabyte, beats paq8px, and does a gigabyte in 75 minutes on four M4 Pro cores instead of a week.

You can find the code, the 7 MB model and the benchmark harness here: https://github.com/dnhkng/ISA-NET


Prediction is compression

An arithmetic (range) coder can encode a symbol with probability $p$ in almost exactly $-\log_2 p$ bits. If a model assigns probability $p(x_i \mid x_{<i})$ to each byte, the compressed size of a file is

\[\text{bits} \approx \sum_i -\log_2 p(x_i \mid x_{<i})\]

which is just the model’s cross-entropy on the file (which is why we train for this particular loss with LLMs). Bits per byte (bpb), the metric from the TinyStories post, is the compression ratio: 8 bpb is no compression, 2 bpb is a 4:1 ratio, 1.25 bpb is 6.4:1.

Great! We can get the probabilities of the next word, but catch is that the decoder has to run the same model and get the exact same probabilities, bit for bit, or via the magic of ‘almost-autoregressive-generation’, the rest of the file turns to garbage. One flipped rounding decision in byte 400,000,000, and the remaining 600 MB of Wikipedia is a hallucinated description of a non-existent world.


From words to bytes

The TinyStories model used a 2,048-token BPE vocabulary and a 256-token context, because we want to learn kids stories using a small set of words. For compression, instead of a huge dictionary like that used in an LLM, I switched to raw bytes: no tokeniser logic, and all 256 symbols gets a probability at every step. The model that came out of the search is called Jolt:

ComponentJolt
Inputraw bytes, 256 symbols
Context1,536 bytes
Blocks4
Residual width256
Attention8 heads; in alternate blocks 7 of them see only a 32-byte window and 1 stays global; clipped-linear normaliser, no exp
Attention projectionsINT8 SDOT, prepacked tickets; output projection keeps half its blocks
Boolean FFN2,048 bits, 3 rounds of learned 3-input logic, EOR+CNT+SDOT decode
Hashed n-gram tablesorders 3, 4 and 6, two hash heads each, 64-channel INT8 rows
Readout64-bit Boolean vocabulary code + rank-64 numerical correction
Deployed model image7,052,160 bytes

The architecture is the same family as the story model, with numerical residuals and attention geometry around a wide Boolean feed-forward program. The big new ingredient is the hashed n-gram tables.

Hashed n-gram tables

When you drop a tokenizer, the resultant byte-level models have a problem: a single byte carries very little information, so the network has to spend its first layers just assembling characters into word fragments. By using an n-gram table, the previous 3, 4 and 6 bytes are hashed (a multiply-XOR hash, two hash heads per order) into tables of learned 64-channel INT8 rows, which are summed into the input embedding. On the CPU this is a handful of integer multiplies and three cache-resident row loads per byte: about the cheapest “memory” a network can have. The learnt tables are most of the 7 MB model, and this was a tuned budget that maximised the capabilities of the model while fitting in a 16 MB L2.

Training

Jolt was trained on the first 900,000,000 bytes of enwik9 (on my GH200 workstation), using the straight-through/multilinear Boolean training from the last post. The final checkpoint saw about 3.2 billion bytes, roughly three and a half passes over the training split, and reached 1.310 bpb on the validation split (bytes 900M-950M). Bytes 950M-1000M were held back as a test split.


The compression codec

A model all on its lonesome not a compressor, so Jolt’s native binary wraps the network in four more pieces:

flowchart LR
    B["previous bytes"] --> M["Jolt network<br/>256 probabilities"]
    B --> MM["match model<br/>64 KiB history"]
    M --> MIX["mix"]
    MM --> MIX
    MIX --> U["Bayesian mix<br/>with uniform"]
    U --> Q["16-bit integer<br/>frequencies"]
    Q --> RC["32-bit range coder"]
    RC --> S["compressed stream"]
  • A match model. We can take advantage of common repeats in Wikipedia, such as templates, infobox fields, and citation boilerplate. We use a small matching model to hash the last six bytes into a 65,536-entry table of positions in a 64 KiB history. It verifies the candidate, and predicts that the next byte continues the match with a confidence that depends on how long the match has run. Its prediction is linearly mixed into the network’s.
  • A safety net. The mixed distribution is mixed once more with the uniform distribution, with the weight updated as an exact Bayesian posterior. On text the network wins and the uniform weight vanishes; on data the model has never seen anything like (binary, a different language) the coder can never do much worse than 8 bits per byte.
  • Integer frequencies. The probabilities are quantised to a 16-bit frequency table in which every symbol gets at least one count, so no byte is ever impossible, and the Bayesian update runs on those integer frequencies, not on the floating-point probabilities, so encoder and decoder agree exactly.
  • A range coder. A classic 32-bit, LZMA-style range coder turns the frequencies into bits.

Determinism

The network uses -ffast-math, FP16 arithmetic and hand-written NEON assembly, so its outputs depend on the exact instruction sequence. Just to be sure I don’t mix thing up during deployment, the stream header carries a fingerprint of the exported weights and of the arithmetic build, and a mismatched decoder refuses to start rather than producing garbage. Every result in this post was round-tripped and compared byte-for-byte, or by SHA-256.

Four cores is 4x Faster!

A single core decodes about 61 kB/s. For the full gigabyte, the file is split into four lanes, each with its own model state, KV cache, match model and range coder, running on four performance cores. The lanes share one read-only copy of the weights. That costs a little compression (each lane starts cold) and gets almost exactly 4× the speed.


The full gigabyte

MeasureValue
Inputenwik9, 1,000,000,000 bytes
Compressed stream155,874,783 bytes (1.2470 bpb)
Decompressor (zip -9, model included)5,980,523 bytes
Total, LTCB-style161,855,306 bytes (1.2948 bpb)
Compress / decompress4,501 s / 4,522 s (about 75 minutes each, four M4 cores, 220 kB/s)
Peak memory2.5 GB compress / 2.1 GB decompress, mostly whole-file buffers
Round tripexact (SHA-256 match)

LTCB placement

On the LTCB table that lands between nanozip (161.7 MB) and kanzi’s TPAQX mode (162.1 MB), about 56th of roughly 240 entries. Every LZ-family compressor is far behind: 18 % smaller than xz with a 1 GiB dictionary, 25 % smaller than zstd -22. PPMonstr, Dmitry Shkarin’s heavyweight PPM, is 4.8 MB smaller in total.


Fight Time!

Most of the benchmarks I found were published in different years on different machines, so hard to compare. So I ran everything again on the same Apple M4 Pro (24 GB, macOS, on mains power, nothing else running), on the same files:

  • dev: enwik9 bytes 909,000,000-910,000,000 (1 MB) and 909,000,000-913,000,000 (4 MB), from Jolt’s validation split
  • test: unseen bytes 959,000,000-960,000,000 (1 MB), from Jolt’s test split

The contenders:

  • cmix v21, Byron Knoll’s context-mixing compressor (with its English dictionary, and without), rank 22 on LTCB
  • paq8px v217, at -11L (-12L wants more than the Mac’s 24 GB)
  • PPMd (7-Zip), xz -9e, zstd -22, bzip2 -9 as the classical baselines

Every tool ran single-threaded; encode and decode were timed separately; every round trip was verified by SHA-256.

Speed against size

The 1 MB dev slice, in numbers:

CompressorbpbCompress kB/sDecompress kB/sPeak memory
cmix v21 + dictionary1.35591.61.818.6 GB
ISA-NET Jolt1.357260.760.614 MB
cmix v21, no dictionary1.50331.61.518.4 GB
paq8px v217 -11L1.50513.93.98.8 GB
PPMd (7-Zip, order 16)2.017215,00013,60021 MB
bzip2 -92.240320,20039,8007 MB
xz -9e2.27586,00050,60075 MB
zstd -22 –long=302.35946,70073,80022 MB

On this megabyte Jolt is just 161 bytes larger than cmix, 0.1 %, and 38× faster to compress, 34× faster to decompress (yes, I spent waaaaay too long trying to beat cmix and failing). It beats paq8px by 10 % at 15× the speed. The classical compressors are hundreds of times faster still, and 49 to 74 % larger (so, in the machine learning sense they are dumber).

Moving the frontier

A cleaner way to see this is the Pareto frontier: the set of compressors for which nothing else is both faster and smaller. Before Jolt, the frontier on this file ran cmix → paq8px → PPMd → bzip2, and between paq8px at 4 kB/s and PPMd at 15,000 kB/s there was nothing: if you wanted anything faster than paq8px, you had to accept a 2.0 bpb file.

Pareto frontier

Jolt knocks paq8px off the frontier, both for compression and decompression, and fills that hole. At 61 kB/s it produces files 33 % smaller than anything that was at least as fast before (PPMd), and the frontier bulges outwards by the whole shaded area.

And check out memory usage:

Memory

cmix allocates about 18.6 GB up front for its hundreds of models and its LSTM. Jolt’s entire working set is 14 MB, half of which is the model itself. That’s a factor of more than a thousand, and it’s the reason Jolt is fast: nothing it touches per byte ever leaves the performance cluster’s L2.

In fairness to cmix, a 24 GB Mac is not its natural habitat. macOS spent a good part of each cmix run compressing cmix’s own memory to make it fit, which is a little ironic for a compression benchmark, and it swapped a bit during one run. Give it 32 GB and it would be somewhat faster. Even if I credit it all of that time back, Jolt is still more than 20× faster.


the Catch

bpb by file

On 4 MB the picture changes: cmix drops to 1.274 bpb while Jolt stays at 1.352, a 6 % gap. paq8px closes most of its gap too.

This is the fundamental difference between the two designs. cmix and paq8px are online learners. They start knowing almost nothing (cmix’s dictionary aside) and adapt to the file as they read it: every byte updates thousands of context statistics and the LSTM’s weights. The longer the file, the better they get. Jolt is a frozen model: everything it knows was learned in pretraining, and it doesn’t improve with length.

Which is better depends entirely on what you’re compressing. For a megabyte of Wikipedia-like text, pretraining wins on speed by a mile and ties on size. For a gigabyte, online learning wins on size, but it’s damn slow.

Time to compress enwik9

Running cmix or paq8px over a gigabyte on this Mac would take days, so those bars are extrapolated from the measured 4 MB throughput (and they’re optimistic as context mixers tend to slow down as their tables fill). The xz, PPMd and Jolt four-core bars are measured.

Jolt, on four M4 Pro cores, does the whole gigabyte in about 75 minutes each way. On one core it would be about four and a half hours.


The Scorecard

 ISA-NET Joltcmix v21
1 MB held-out Wikipedia1.357 bpb1.356 bpb
4 MB held-out Wikipedia1.352 bpb1.274 bpb
Compress speed, one core60.7 kB/s1.6 kB/s
Peak memory14 MB18.6 GB
Learns while compressingnoyes
enwik9, total with decompressor161.9 MB108.2 MB
Time for enwik975 minutes (4 cores)about a week (1 core, extrapolated)
Fits in L2yeslol

Conclusion

So, what did the XORs win? Definitely not the Hutter Prize. But I’m happy with a 7 MB model made of compares, XORs, popcounts and INT8 dot products, which never leaves one core’s L2, compresses unseen Wikipedia text as well as cmix on a megabyte, at 38 times the speed and a thousandth of the memory. And hopefully I also got a nice blog article out of it too. Not bad for hacking instructions that were designed for video codecs and cryptography.


References and reproducibility

The codec, the Jolt model, the training code and the benchmark harness (with the raw results behind every chart) are here: https://github.com/dnhkng/ISA-NET

Benchmark protocol: single core unless marked, encode and decode timed separately, median of 3-5 runs for fast tools and Jolt, 1 run for cmix and paq8px, peak memory from /usr/bin/time -l, every round trip verified by SHA-256. Machine: Apple M4 Pro, 24 GB, macOS 27.2, Apple clang 21.

Citing This Work

1
2
3
4
5
6
7
@article{ng2026isanetcompression,
  title   = {Compressing Wikipedia with XOR, Popcount and SDOT},
  author  = {Ng, David Noel},
  year    = {2026},
  month   = {November},
  url     = {https://dnhkng.github.io/posts/isa-net-compression/}
}

Enjoyed this deep-dive?

Get my next piece on AI hardware, biophysics, or random optimisation hacks delivered straight to your inbox.

This post is licensed under CC BY 4.0 by the author.