Bitboard Knight Tour

Algorithms & Data

A knight crosses a 64-bit chessboard while three bit-count operations score its reach, find its next move, and locate its active bit.

loading core…

Self-running — verified CRC C074.

Click the screen, then play. (Tab away and it pauses.)

The operations under test

Each board is one 64-bit integer. Knight attacks are shift-and-mask bitboards; popcountll scores reachable squares, ctzll selects the next set bit, and clzll locates it from the opposite edge.

Lowering: LLVM forms ctpop.i64, cttz.i64, and ctlz.i64. This backend expands all three inline rather than calling the helper routines anticipated by the original plan.

Result: host, default, a16, and xy16 all return 0xC074 on MAME and bsnes-jg.

What the board shows

The selected knight is gold, currently reachable squares are cyan, and visited squares settle blue. Those states are the same bitboards folded into the differential CRC.

Bring-up findings

A variable 1ULL << uint8_t exposed an unlegalizable s8-to-s64 extension, and expanding all three count operations inside the pressure-heavy caller exposed undefined imaginary-register uses. The published shape constructs one-hot values with constant shifts and isolates each count operation behind a noinline helper; both findings remain recorded for compiler follow-up.

Compiler stress-test #120, Round 7. Source and full test record live in llvm-mos-65816.