nice
This commit is contained in:
parent
ca877ef44d
commit
b307f98760
1 changed files with 29 additions and 24 deletions
53
mandel.s
53
mandel.s
|
@ -131,45 +131,48 @@ minus:
|
||||||
shr 4, arg
|
shr 4, arg
|
||||||
.endmacro
|
.endmacro
|
||||||
|
|
||||||
.macro checkbit arg, bits
|
.macro bitmul16 arg1, arg2, result, bitnum
|
||||||
.if bits < 8
|
|
||||||
lda arg
|
|
||||||
and #(1 << bits)
|
|
||||||
.else
|
|
||||||
lda arg + 1
|
|
||||||
and #(1 << (bits - 8))
|
|
||||||
.endif
|
|
||||||
.endmacro
|
|
||||||
|
|
||||||
.macro bitmul16 arg1, arg2, res, bits
|
|
||||||
.local next
|
.local next
|
||||||
|
|
||||||
checkbit arg2, bits
|
|
||||||
clc
|
clc
|
||||||
|
|
||||||
|
; check if arg1 has 0 or 1 bit in this place
|
||||||
|
.if bitnum < 8
|
||||||
|
lda arg1
|
||||||
|
and #(1 << bitnum)
|
||||||
|
.else
|
||||||
|
lda arg1 + 1
|
||||||
|
and #(1 << (bitnum - 8))
|
||||||
|
.endif
|
||||||
beq next
|
beq next
|
||||||
|
|
||||||
; 16-bit add on the top bits
|
; 16-bit add on the top bits
|
||||||
lda res + 2
|
lda result + 2
|
||||||
adc arg1
|
adc arg2
|
||||||
sta res + 2
|
sta result + 2
|
||||||
lda res + 3
|
lda result + 3
|
||||||
adc arg1 + 1
|
adc arg2 + 1
|
||||||
|
sta result + 3
|
||||||
|
|
||||||
next:
|
next:
|
||||||
; shift result right one bit
|
; Shift the 32-bit result down by one bit,
|
||||||
; (shifts in the carry bit)
|
; saving the previous carry.
|
||||||
ror a
|
ror result + 3
|
||||||
ror res
|
ror result + 2
|
||||||
sta res + 1
|
ror result + 1
|
||||||
|
.if bitnum >= 8
|
||||||
|
; we can save 5 cycles * 8 bits = 40 cycles total by skipping this byte
|
||||||
|
; when it's all uninitialized data
|
||||||
|
ror result
|
||||||
|
.endif
|
||||||
.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
|
||||||
; 32-bit result in FR2
|
; 32-bit result in FR2
|
||||||
; clobbers FR1 and FR2
|
|
||||||
|
|
||||||
; zero out the 32-bit temp
|
; zero out the 32-bit temp's top 16 bits
|
||||||
lda #0
|
lda #0
|
||||||
sta FR2 + 2
|
sta FR2 + 2
|
||||||
sta FR2 + 3
|
sta FR2 + 3
|
||||||
|
@ -178,6 +181,8 @@ next:
|
||||||
.repeat 16, bitnum
|
.repeat 16, bitnum
|
||||||
bitmul16 FR0, FR1, FR2, bitnum
|
bitmul16 FR0, FR1, FR2, bitnum
|
||||||
.endrepeat
|
.endrepeat
|
||||||
|
|
||||||
|
rts
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
.proc iter
|
.proc iter
|
||||||
|
|
Loading…
Reference in a new issue