1
0
mirror of https://github.com/cc65/cc65.git synced 2025-02-28 20:29:46 +00:00

Minor math optimizations

This commit is contained in:
IrgendwerA8 2019-02-28 17:30:34 +01:00 committed by Oliver Schmidt
parent 0ea78be056
commit cc6559c3f6
4 changed files with 16 additions and 10 deletions

View File

@ -78,7 +78,7 @@ L0: asl ptr1
; Do a subtraction. we do not have enough space to store the intermediate ; Do a subtraction. we do not have enough space to store the intermediate
; result, so we may have to do the subtraction twice. ; result, so we may have to do the subtraction twice.
pha tax
cmp ptr3 cmp ptr3
lda ptr2+1 lda ptr2+1
sbc ptr3+1 sbc ptr3+1
@ -91,9 +91,9 @@ L0: asl ptr1
; Overflow, do the subtraction again, this time store the result ; Overflow, do the subtraction again, this time store the result
sta tmp4 ; We have the high byte already sta tmp4 ; We have the high byte already
pla txa
sbc ptr3 ; byte 0 sbc ptr3 ; byte 0
pha tax
lda ptr2+1 lda ptr2+1
sbc ptr3+1 sbc ptr3+1
sta ptr2+1 ; byte 1 sta ptr2+1 ; byte 1
@ -102,7 +102,7 @@ L0: asl ptr1
sta tmp3 ; byte 2 sta tmp3 ; byte 2
inc ptr1 ; Set result bit inc ptr1 ; Set result bit
L1: pla L1: txa
dey dey
bne L0 bne L0
sta ptr2 sta ptr2

View File

@ -34,19 +34,19 @@ L0: asl ptr1
rol a rol a
rol sreg+1 rol sreg+1
pha tax
cmp ptr3 cmp ptr3
lda sreg+1 lda sreg+1
sbc ptr3+1 sbc ptr3+1
bcc L1 bcc L1
sta sreg+1 sta sreg+1
pla txa
sbc ptr3 sbc ptr3
pha tax
inc ptr1 inc ptr1
L1: pla L1: txa
dey dey
bne L0 bne L0
sta sreg sta sreg

View File

@ -42,11 +42,11 @@ umul16x16r16m:
clc clc
adc ptr3 adc ptr3
pha tax
lda ptr3+1 lda ptr3+1
adc sreg+1 adc sreg+1
sta sreg+1 sta sreg+1
pla txa
@L1: ror sreg+1 @L1: ror sreg+1
ror a ror a

View File

@ -9,6 +9,7 @@
.include "zeropage.inc" .include "zeropage.inc"
.macpack cpu
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
; 8x16 => 24 unsigned multiplication routine. Because the overhead for a ; 8x16 => 24 unsigned multiplication routine. Because the overhead for a
@ -30,9 +31,14 @@ umul8x16r16:
umul8x16r24m: umul8x16r24m:
umul8x16r16m: umul8x16r16m:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz ptr1+1
stz sreg
.else
ldx #0 ldx #0
stx ptr1+1 stx ptr1+1
stx sreg stx sreg
.endif
ldy #8 ; Number of bits ldy #8 ; Number of bits
ldx ptr3 ; Get into register for speed ldx ptr3 ; Get into register for speed