mirror of
https://github.com/cc65/cc65.git
synced 2024-12-22 12:30:41 +00:00
Swap the positive/negative paths to save a branch.
This commit is contained in:
parent
421c3f2b4f
commit
985371433b
@ -32,24 +32,7 @@ imul8x8r16m:
|
||||
ldy #<$0000 ; Clear .XY accumulator
|
||||
ldx #>$0000
|
||||
lda ptr1
|
||||
bmi NegMult
|
||||
bpl @L2 ; Branch always
|
||||
|
||||
@L0: tya ; Add current multiplicand
|
||||
add ptr3
|
||||
tay
|
||||
txa
|
||||
adc ptr3+1
|
||||
tax
|
||||
|
||||
@L1: asl ptr3
|
||||
rol ptr3+1
|
||||
@L2: lsr ptr1 ; Get next bit of Right-Hand Side into carry
|
||||
bcs @L0
|
||||
bnz @L1 ; Loop if more one-bits in multiplier
|
||||
|
||||
tya ; Put result into cc65's accumulator
|
||||
rts
|
||||
bpl PosStart
|
||||
|
||||
; The multiplier is negative.
|
||||
; Therefore, make it positive; and, subtract when multiplying.
|
||||
@ -57,9 +40,10 @@ NegMult:
|
||||
eor #%11111111
|
||||
sta ptr1
|
||||
inc ptr1
|
||||
bnz @L2 ; Branch always
|
||||
bnz NegStart ; Branch always
|
||||
|
||||
@L0: tya ; Subtract current multiplicand
|
||||
NegAdd:
|
||||
tya ; Subtract current multiplicand
|
||||
; sec
|
||||
sbc ptr3
|
||||
tay
|
||||
@ -67,11 +51,34 @@ NegMult:
|
||||
sbc ptr3+1
|
||||
tax
|
||||
|
||||
@L1: asl ptr3
|
||||
NegShift:
|
||||
asl ptr3
|
||||
rol ptr3+1
|
||||
@L2: lsr ptr1 ; Get next bit of Right-Hand Side into carry
|
||||
bcs @L0
|
||||
bnz @L1 ; Loop if more one-bits in multiplier
|
||||
NegStart:
|
||||
lsr ptr1 ; Get next bit of Right-Hand Side into carry
|
||||
bcs NegAdd
|
||||
bnz NegShift ; Loop if more one-bits in multiplier
|
||||
|
||||
tya ; Put result into cc65's accumulator
|
||||
rts
|
||||
|
||||
; The multiplier is positive.
|
||||
|
||||
PosAdd:
|
||||
tya ; Add current multiplicand
|
||||
add ptr3
|
||||
tay
|
||||
txa
|
||||
adc ptr3+1
|
||||
tax
|
||||
|
||||
PosShift:
|
||||
asl ptr3
|
||||
rol ptr3+1
|
||||
PosStart:
|
||||
lsr ptr1 ; Get next bit of Right-Hand Side into carry
|
||||
bcs PosAdd
|
||||
bnz PosShift ; Loop if more one-bits in multiplier
|
||||
|
||||
tya ; Put result into cc65's accumulator
|
||||
rts
|
||||
|
Loading…
Reference in New Issue
Block a user