v2.1 R6 - May 2026
B Compiler (hcbcomp)
Z80 Peephole Optimizations - Bug Fixes
- Pattern 15 (
z80_match_inc_local_full): fixed to match complete 21-instruction sequence (was 19)- Added missing final instructions:
pop deandex de, hlfromgen_pop_sec()andgen_exchange() - Eliminates leftover
pop de; ex de, hlafter optimizedinc word [ix+N]
- Added missing final instructions:
- Pattern 16 (
z80_match_dec_local_full): fixed to match complete 23-instruction sequence (was 21)- Added missing final instructions:
pop deandex de, hlfromgen_pop_sec()andgen_exchange() - Eliminates leftover
pop de; ex de, hlafter optimizeddec word [ix+N]
- Added missing final instructions:
- Dispatcher updated:
wcountchecks changed from 19/21 to 21/23 ingen_peep_replace()
Example - Before Fix
inc word [ix-2]
pop de ; ← leftover (useless)
ex de, hl ; ← leftover (useless)
push ix ; ← next codeExample - After Fix
inc word [ix-2]
push ix ; ← next code (no leftovers)Assembler (hcasm)
Z80 IM Instruction Fix
- Bug fix in
emit_im(): corrected token validation condition- Changed
argv[0]->token != TOK_VALUEtoargv[0]->token == TOK_VALUE - Instructions
IM 0,IM 1,IM 2now assemble correctly
- Changed
- Test impact:
asm/z80/all_opcodesnow passes (was failing due to IM instruction error)
Validation & Testing
- 43/43 tests passing (was 42/43)
- Zero regressions - all B language and assembler tests pass across all platforms
v2.1 R5 - May 2026
B Compiler (hcbcomp)
Z80 Peephole Optimizations - Local Variable Increment/Decrement
- Pattern 15 (
z80_match_inc_local_full): replaces 19-instruction increment sequence withinc word [ix+N]- Pattern:
push ix; pop hl; ld de,OFF; add hl,de; push hl; ld a,[hl]; inc hl; ld h,[hl]; ld l,a; push hl; push hl; ld hl,1; pop de; add hl,de; pop de; ex de,hl; ld [hl],e; inc hl; ld [hl],d - Replacement:
inc word [ix+OFF] - Optimization: 19 → 1 instructions (95% reduction)
- Pattern:
- Pattern 16 (
z80_match_dec_local_full): replaces 21-instruction decrement sequence withdec word [ix+N]- Pattern:
push ix; pop hl; ld de,OFF; add hl,de; push hl; ld a,[hl]; inc hl; ld h,[hl]; ld l,a; push hl; push hl; ld hl,1; pop de; ex de,hl; or a; sbc hl,de; pop de; ex de,hl; ld [hl],e; inc hl; ld [hl],d - Replacement:
dec word [ix+OFF] - Optimization: 21 → 1 instructions (95% reduction)
- Pattern:
- Window size increased:
PEEP_WINDOWfrom 12 to 25 to support larger pattern matching
Example Optimization
; Before (a++)
push ix
pop hl
ld de, -2
add hl, de
push hl
ld a, [hl]
inc hl
ld h, [hl]
ld l, a
push hl
push hl
ld hl, 1
pop de
add hl, de
pop de
ex de, hl
ld [hl], e
inc hl
ld [hl], d
; After
inc word [ix-2]
Validation & Testing
- 42/42 tests passing across all platforms (Z80, 8080, 8085, 8086, 8086exe)
- Zero regressions - all official B language tests continue passing
Performance Impact
| Platform | Optimization | Before | After | Savings |
|---|---|---|---|---|
| Z80 | inc word [ix+N] |
19 instr | 1 instr | 95% fewer instructions |
| Z80 | dec word [ix+N] |
21 instr | 1 instr | 95% fewer instructions |
Overall impact: Significant code size reduction and speedup for programs using ++ and -- operators on local variables