1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-12-25 04:58:05 +11:00

zasm: little drive-by optimization

Use IX directly for argspec rows instead of going through DE. It saves a bit
of processing. The code was this way because I initially didn't use IX at all,
so as code evolved, that DE translation stayed as an artifact.
This commit is contained in:
Virgil Dupras 2019-12-13 10:23:11 -05:00
parent 0d7693a163
commit e691dab070
3 changed files with 45 additions and 54 deletions

View File

@ -417,26 +417,6 @@ matchArg:
dec hl
ret
; Compare primary row at (DE) with ID in A. Sets Z flag if there's a match.
matchPrimaryRow:
push hl
push ix
push de \ pop ix
cp (ix)
jr nz, .end
; name matches, let's see the rest
ld hl, INS_CURARG1
ld a, (ix+1)
call matchArg
jr nz, .end
ld hl, INS_CURARG2
ld a, (ix+2)
call matchArg
.end:
pop ix
pop hl
ret
; *** Special opcodes ***
; The special upcode handling routines below all have the same signature.
; Instruction row is at IX and we're expected to perform the same task as
@ -574,16 +554,13 @@ handleRST:
ld c, 0
ret
; Compute the upcode for argspec row at (DE) and arguments in curArg{1,2} and
; Compute the upcode for argspec row at (IX) and arguments in curArg{1,2} and
; writes the resulting upcode to IO.
; A is zero, with Z set, on success. A is non-zero, with Z unset, on error.
spitUpcode:
push ix
push de
push hl
push bc
; First, let's go in IX mode. It's easier to deal with offsets here.
push de \ pop ix
; before we begin, are we in a 'l' argspec? Is it flagged for IX/IY
; acceptance? If yes, a 'x' or 'y' instruction? Check this on both
@ -823,7 +800,6 @@ spitUpcode:
pop bc
pop hl
pop de
pop ix
ret
.checkCB:
ld a, (INS_UPCODE)
@ -876,7 +852,7 @@ parseInstruction:
push bc
push hl
push de
; A is reused in matchPrimaryRow but that register is way too changing.
; A is reused in .matchPrimaryRow but that register is way too changing.
; Let's keep a copy in a more cosy register.
ld c, a
xor a
@ -899,24 +875,24 @@ parseInstruction:
; To speed up things a little, we use a poor man's indexing. Full
; bisecting would involve too much complexity.
ld a, c ; recall A param
ld de, instrTBl
ld ix, instrTBl
cp I_EX
jr c, .loop
ld de, instrTBlEX
ld ix, instrTBlEX
cp I_LD
jr c, .loop
ld de, instrTBlLD
ld ix, instrTBlLD
cp I_RET
jr c, .loop
ld de, instrTBlRET
ld ix, instrTBlRET
.loop:
ld a, c ; recall A param
call matchPrimaryRow
call .matchPrimaryRow
jr z, .match
ld a, INSTR_TBL_ROWSIZE
call addDE
ld a, (de)
cp 0xff
ld de, INSTR_TBL_ROWSIZE
add ix, de
ld a, 0xff
cp (ix)
jr nz, .loop
; No signature match
ld a, ERR_BAD_ARG
@ -936,6 +912,19 @@ parseInstruction:
pop bc
ret
; Compare primary row at (IX) with ID in A. Sets Z flag if there's a match.
.matchPrimaryRow:
cp (ix)
ret nz
; name matches, let's see the rest
ld hl, INS_CURARG1
ld a, (ix+1)
call matchArg
ret nz
ld hl, INS_CURARG2
ld a, (ix+2)
jp matchArg
; In instruction metadata below, argument types arge indicated with a single
; char mnemonic that is called "argspec". This is the table of correspondence.

View File

@ -1,4 +1,6 @@
#!/bin/sh -e
#!/usr/bin/env bash
set -e
# TODO: find POSIX substitute to that PIPESTATUS thing
BASE=../../..
TOOLS=../..

View File

@ -46,15 +46,15 @@ runTests:
halt
testSpitUpcode:
ld ix, .t1
ld iy, .t1
call .test
ld ix, .t2
ld iy, .t2
call .test
ld ix, .t3
ld iy, .t3
call .test
ld ix, .t4
ld iy, .t4
call .test
ld ix, .t5
ld iy, .t5
call .test
ret
@ -66,36 +66,36 @@ testSpitUpcode:
ld (SPITBOWL+1), a
ld (SPITBOWL+2), a
ld (SPITBOWL+3), a
push ix \ pop de
call intoDE
ld a, (ix+2)
push iy \ pop ix
call intoIX
ld a, (iy+2)
ld (INS_CURARG1), a
ld a, (ix+3)
ld a, (iy+3)
ld (INS_CURARG1+1), a
ld a, (ix+4)
ld a, (iy+4)
ld (INS_CURARG1+2), a
ld a, (ix+5)
ld a, (iy+5)
ld (INS_CURARG2), a
ld a, (ix+6)
ld a, (iy+6)
ld (INS_CURARG2+1), a
ld a, (ix+7)
ld a, (iy+7)
ld (INS_CURARG2+2), a
call spitUpcode
jp nz, fail
ld a, (SPITCNT)
cp (ix+8)
cp (iy+8)
jp nz, fail
ld a, (SPITBOWL)
cp (ix+9)
cp (iy+9)
jp nz, fail
ld a, (SPITBOWL+1)
cp (ix+10)
cp (iy+10)
jp nz, fail
ld a, (SPITBOWL+2)
cp (ix+11)
cp (iy+11)
jp nz, fail
ld a, (SPITBOWL+3)
cp (ix+12)
cp (iy+12)
jp nz, fail
jp nexttest