2.5 KiB
§255 — THE EMPTY CASE, PART 2: FOUR TREE SHAPES IT BUYS (P31 S58b)
§222 records that "a leading EMPTY case buys the median split" and §193-G gives the ≥3-node floor.
Four more shapes, each byte-proven, each reachable only by adding a case K: break; that emits nothing:
1. EMPTY case 2: TO ROOT THE TREE ON ==1. With cases {0,1} only, gcc-2.7.2 roots the decision
tree on ==0 and lays case 0's body first. Adding case 2: break; gives three case values, so gcc
roots on ==1 and folds v>=2 || v==0 into two default edges — beqz on the slti result to the
tail, bnez $v1 to the tail. func_80180B90 (ov_SC07_000; the banked twin func_801AE220 carries the
same empty case, which was the tell). func_801824E4 (ov_SC02_031) is the same lever stated from the
balance_case_nodes side (stmt.c:5361's i > 2 gate).
2. EMPTY case 0: SO CASE 1 BECOMES THE TREE'S LOW LEAF. With {1,2} + default, a bare
if(v==1)…else if(v==2)… emits bne/li/bne and no slti; the empty case 0: puts case 1
left of the slti split (func_8017F3B0, ov_SC02_017; func_80181AB8, ov_SC03_107 — where §199-G
predicted the residual signature exactly).
3. BOTH case 0: break; AND default: break; FOR A {1,2} FALL-THROUGH TARGET. func_80180D3C
(ov_SC03_029): default: break; alone changed nothing (near-45); adding the empty case 0: as well
made three case nodes and emit_case_nodes produced the median split byte-for-byte.
4. AN EMPTY MEDIAN CASE AS THE TREE ROOT, EMITTING AN EPILOGUE-TARGETING beq. func_80180A44
(ov_SC06_006): the first beq (v1 == 0x200) targets the epilogue — case 0x200 is empty, and
0x200 is the median of {0x000…0x400}, so gcc's comparison tree roots there and emits the slti
guard in that beq's delay slot. Writing the cases in ascending order with an explicit empty
0x200 reproduces the tree exactly.
AND CASE-BODY PLACEMENT. gcc-2.7.2 emits balanced-tree case bodies in DFS order (root body
first), so the physical order of arms in the .s does not name their case values — map them from
the beq/slti chain, not from emission order (func_801855CC, ov_SC03_001; func_8017E614,
ov_SC05_017, where the middle case is tested first and its body sits last-but-one; func_80186238,
ov_SC06_032, where a 0.86-similar twin mislabelled which arm owned which label). Where cases are dense
and the source arm order matters, §222's "source arm order IS emission order" still holds
(func_80183A1C: case 1 must precede case 0).