Skip to content

// TABLES · WHAT'S UNDERNEATH //

The fastest function is the one you already ran

You cache an expensive result. You precompute a gradient, a hash, a ramp, and call it an optimisation. On the 68000 in your Amiga — with no sine instruction and a multiply that can cost seventy cycles — the demoscene took that one idea, compute it once, read it forever, and built an entire art form on it.

Maths is dear; memory is cheap

The 68000 can multiply, but slowly — a single MULU can run as long as seventy cycles. Sine and cosine it can’t do at all; you’d need a polynomial and a fistful of multiplies per angle. In a demo redrawing the whole screen every frame, that bill is unpayable. So you don’t compute sine — you compute it once, into a table, and from then on you just look:

68000 · A SINE TABLEone read
        lea    sintab,a0
      move.b (a0,d0.w),d1    ; d1 = sin(angle) — one indexed read

sintab: dc.b   0,3,6,9,12,...  ; 256 values, precomputed
A whole transcendental function, collapsed to one addressed read. The angle is a byte, so 255 + 1 wraps to 0 for free — the same power-of-two trick.

This is memoisation with the lid off

Trading space for time is the entire move. A table costs 256 bytes and turns an unaffordable calculation into a constant-time fetch — the exact bargain behind every cache, every memoised function, every precomputed gamma ramp or gradient LUT you’ve ever shipped. The demoscene just did it without apology, and stacked plasma, rotozoomers and the eternal wobbling “sinus scroller” on top.

There’s a second, quieter win: a table read costs the same every single time. No branches, no worst case, no surprises. In a routine that has to finish before the next frame arrives, flat and predictable is fast — often more valuable than a lower average with a nasty tail.

Reach for a lookup table today and you’re standing exactly where a 1988 demo coder stood: maths is expensive, memory is cheap, and the fastest function call is the one you already made. The Amiga just made the trade impossible to ignore.

>Every great programmer started with one instruction.