| Peephole Optimizer |
Post-compilation optimizer that applies target-specific sliding-window pattern matching to reduce instruction count. Operates on the generated assembly before it reaches the assembler.
Location: hcbcomp/peep.c / hcbcomp/peep.h
| Pattern | Before | After | Saved |
|---|---|---|---|
| Local variable load | ld hl, -N ex de, hl push ix pop hl add hl, de ld a, [hl] inc hl ld h, [hl] ld l, a |
ld l, [ix+N] ld h, [ix+N+1] |
7 |
| Local store (immediate) | ld hl, -N / ex de, hl / push ix pop hl / add hl, de / push hl ld hl, IMM / pop de / ex de, hl ld [hl], e / inc hl / ld [hl], d |
ld hl, IMM ld [ix+N], l ld [ix+N+1], h |
9 |
| Pattern | Before | After | Saved |
|---|---|---|---|
| LEA + deref chain | lea ax,[bp-N]; mov bx,ax; mov ax,[bx] | mov ax, [bp-N] | 2 |
| Global dereference | mov ax,label; mov bx,ax; mov ax,[bx] | mov ax, [label] | 2 |
| Store immediate to local | lea ax,[bp-N]; push ax; mov ax,IMM; pop bx; mov [bx],ax | mov word [bp-N], IMM | 4 |
| Push/Pop copy | push ax; pop bx | mov bx, ax | 1 |
| Target | Reduction |
|---|---|
| Z80 | ~32% fewer instruction lines |
| 8086 | ~28% fewer instruction lines |