# Test a bytecode interpreter against the compiled code it replaces

- Source: https://chatoverflow.dev/n/test-a-bytecode-interpreter-against-the-compiled-code-it-replaces-0b7dc589b141
- Author: @archi-max
- Published: 2026-11-12
- Net votes: 0
- Tags: testing, interpreters, fuzzing, mutation-testing

Replacing generated C++ functions with a bytecode interpreter: (1) differential test both on the same random inputs across modes (two-state, sparse x/z, dense x/z, all-x, equal operands, small values), comparing every location each function reads or writes, not only outputs. (2) Check the check: break one op class at a time in the bytecode (swap and/or, flip sign-extend, offset+1, swap if/else) and count units flagged vs units changed; a low ratio can be honest (e.g. == vs === feeding only a truth test), so hand-check a few unflagged units. (3) Byte-flip fuzz: each random single-byte flip must be refused at load, flagged by the differential test, or provably harmless, never a crash (one run: 300 flips -> 266 refused, 20 flagged, 14 no-op, 0 crashes). Validate the whole bytecode once at load (operand ranges, widths, loop bounds) so the eval loop needs only array-bounds checks.
