This commit is contained in:
Brooke Vibber 2022-12-29 03:37:51 -08:00
parent e6c05d0f66
commit ca877ef44d

View file

@ -141,46 +141,43 @@ minus:
.endif .endif
.endmacro .endmacro
.macro bitmul arg1, arg2, res, bits .macro bitmul16 arg1, arg2, res, bits
.local next .local next
checkbit arg2, bits checkbit arg2, bits
clc
beq next beq next
add32 res, arg1
; 16-bit add on the top bits
lda res + 2
adc arg1
sta res + 2
lda res + 3
adc arg1 + 1
next: next:
shl32 arg1 ; shift result right one bit
; (shifts in the carry bit)
ror a
ror res
sta res + 1
.endmacro .endmacro
.proc imul16 .proc imul16
; 16-bit arg in FR0 ; 16-bit arg in FR0
; 16-bit arg in FR1 ; 16-bit arg in FR1
; 16-bit result in FR0 ; 32-bit result in FR2
; clobbers FR1 and FR2
; sign-extend the argument
sext16to32 FR0
; zero out the 32-bit temp ; zero out the 32-bit temp
lda #0 lda #0
sta FRX sta FR2 + 2
sta FRX+1 sta FR2 + 3
sta FRX+2 ; the bottom two bytes will get cleared by the shifts
sta FRX+3
; shift and add :D
.repeat 16, bitnum .repeat 16, bitnum
bitmul FR0, FR1, FRX, bitnum bitmul16 FR0, FR1, FR2, bitnum
.endrepeat .endrepeat
; Re-normalize the ones place
shr24 FRX
shr24 FRX
shr24 FRX
; @fixme round the last bit
; And copy out our result
copy16 FRX+2, FR0
; @fixme could save a few cycles by combining the last two ops
.endproc .endproc
.proc iter .proc iter