This commit is contained in:
Brooke Vibber 2023-01-04 20:12:34 -08:00
parent fa599be775
commit 58519381bf

View file

@ -30,16 +30,18 @@ FRX = $ec
.endmacro .endmacro
; inner loop for imul16 ; inner loop for imul16
; 24 to 44 cycles ; bitnum < 8: 25 or 30 cycles
; bitnum >= 8: 39 or 44 cycles
.macro bitmul16 arg1, arg2, result, bitnum .macro bitmul16 arg1, arg2, result, bitnum
.local one
.local zero .local zero
.local one
.local next
; does 16-bit adds ; does 16-bit adds
; arg1 must be 0 or positive ; arg1 must be 0 or positive
; arg2 must be 0 or positive ; arg2 must be 0 or positive
clc ; 2 cyc ; 7 cycles up to the branch
; check if arg1 has 0 or 1 bit in this place ; check if arg1 has 0 or 1 bit in this place
; 5 cycles either way ; 5 cycles either way
@ -50,24 +52,10 @@ FRX = $ec
lda arg1 + 1 ; 3 cyc lda arg1 + 1 ; 3 cyc
and #(1 << (bitnum - 8)) ; 2 cyc and #(1 << (bitnum - 8)) ; 2 cyc
.endif .endif
beq zero ; 2 cyc bne one ; 2 cyc
one: zero: ; 18 cyc / 23 cyc
; 16-bit add on the top bits lsr result + 3 ; 5 cyc
lda result + 2 ; 3 cyc
adc arg2 ; 3 cyc
sta result + 2 ; 3 cyc
lda result + 3 ; 3 cyc
adc arg2 + 1 ; 3 cyc
ror a ; 2 cyc - get a jump on the shift
sta result + 3 ; 3 cyc
jmp oneb ; 3 cyc
; Shift the 32-bit result down by one bit,
; saving the previous carry.
zero:
ror result + 3 ; 5 cyc
oneb:
ror result + 2 ; 5 cyc ror result + 2 ; 5 cyc
ror result + 1 ; 5 cyc ror result + 1 ; 5 cyc
.if bitnum >= 8 .if bitnum >= 8
@ -75,6 +63,25 @@ oneb:
; when it's all uninitialized data ; when it's all uninitialized data
ror result ; 5 cyc ror result ; 5 cyc
.endif .endif
jmp next ; 3 cyc
one: ; 32 cyc / 37 cyc
; 16-bit add on the top bits
clc ; 2 cyc
lda result + 2 ; 3 cyc
adc arg2 ; 3 cyc
sta result + 2 ; 3 cyc
lda result + 3 ; 3 cyc
adc arg2 + 1 ; 3 cyc
ror a ; 2 cyc - get a jump on the shift
sta result + 3 ; 3 cyc
ror result + 2 ; 5 cyc
ror result + 1 ; 5 cyc
.if bitnum >= 8
ror result ; 5 cyc
.endif
next:
.endmacro .endmacro
; 5 to 25 cycles ; 5 to 25 cycles
@ -157,7 +164,7 @@ loop:
.proc start .proc start
loop: looplong:
; FR0 = 5 ; FR0 = 5
; FR1 = -3 ; FR1 = -3
lda #5 lda #5
@ -172,5 +179,6 @@ loop:
jsr imul16 jsr imul16
; should have 32-bit -15 in FR2 ; should have 32-bit -15 in FR2
loop:
jmp loop jmp loop
.endproc .endproc