3 ms·
Compiling switches into binary (and even sometimes trinary) trees is an old technique that's been around since at least the days of 16-bit DOS... they will usua
by userbinator 10y ago
Compiling switches into binary (and even sometimes trinary) trees is an old technique that's been around since at least the days of 16-bit DOS... they will usually choose between a single-level lookup, double-level lookup, or tree depending on sparsity and options used.
Subtraction and addition implicitly sets the flags, so you can generate very small code with inc/dec (1-byte instructions), like this:
dec ax
jz ax_was_zero
dec ax
jz ax_was_one
...