Use more compact loops.
This commit is contained in:
committed by
greg-king5
parent
99c0815cdb
commit
f59cb9af06
@@ -13,11 +13,11 @@ _memcmp:
|
||||
; Calculate (-count-1) and store it into ptr3. This is some overhead here but
|
||||
; saves time in the compare loop
|
||||
|
||||
eor #$FF
|
||||
sta ptr3
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr3+1
|
||||
inx
|
||||
stx ptr3+1
|
||||
tax
|
||||
inx
|
||||
stx ptr3 ; Save count with each byte incremented separately
|
||||
|
||||
; Get the pointer parameters
|
||||
|
||||
@@ -33,7 +33,7 @@ _memcmp:
|
||||
|
||||
; Head of compare loop: Test for the end condition
|
||||
|
||||
Loop: inx ; Bump low byte of (-count-1)
|
||||
Loop: dex ; Bump low byte of (-count-1)
|
||||
beq BumpHiCnt ; Jump on overflow
|
||||
|
||||
; Do the compare
|
||||
@@ -53,7 +53,7 @@ Comp: lda (ptr1),y
|
||||
; Entry on low counter byte overflow
|
||||
|
||||
BumpHiCnt:
|
||||
inc ptr3+1 ; Bump high byte of (-count-1)
|
||||
dec ptr3+1 ; Bump high byte of (-count-1)
|
||||
bne Comp ; Jump if not done
|
||||
jmp return0 ; Count is zero, areas are identical
|
||||
|
||||
@@ -67,4 +67,3 @@ NotEqual:
|
||||
Greater:
|
||||
ldx #$01 ; Make result positive
|
||||
rts
|
||||
|
||||
|
||||
@@ -5,17 +5,17 @@
|
||||
; char* strncat (char* dest, const char* src, size_t n);
|
||||
;
|
||||
|
||||
.export _strncat
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
||||
.macpack cpu
|
||||
.export _strncat
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
||||
.macpack cpu
|
||||
|
||||
_strncat:
|
||||
eor #$FF ; one's complement to count upwards
|
||||
sta tmp1
|
||||
txa
|
||||
eor #$FF
|
||||
sta tmp2
|
||||
inx
|
||||
stx tmp2
|
||||
tax
|
||||
inx
|
||||
stx tmp1 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get src
|
||||
|
||||
@@ -49,9 +49,9 @@ L2: sty ptr2
|
||||
L3: ldy #0
|
||||
ldx tmp1 ; low counter byte
|
||||
|
||||
L4: inx
|
||||
L4: dex
|
||||
bne L5
|
||||
inc tmp2
|
||||
dec tmp2
|
||||
beq L6 ; jump if done
|
||||
L5: lda (ptr1),y
|
||||
sta (ptr2),y
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
.proc _strncpy
|
||||
|
||||
eor #$FF
|
||||
sta tmp1
|
||||
txa
|
||||
eor #$FF
|
||||
sta tmp2 ; Store -size - 1
|
||||
inx
|
||||
stx tmp2
|
||||
tax
|
||||
inx
|
||||
stx tmp1 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get src
|
||||
jsr popax ; get dest
|
||||
@@ -26,9 +26,9 @@
|
||||
|
||||
ldx tmp1 ; Load low byte of ones complement of size
|
||||
ldy #$00
|
||||
L1: inx
|
||||
L1: dex
|
||||
bne L2
|
||||
inc tmp2
|
||||
dec tmp2
|
||||
beq L9
|
||||
|
||||
L2: lda (ptr1),y ; Copy one character
|
||||
@@ -42,7 +42,7 @@ L2: lda (ptr1),y ; Copy one character
|
||||
|
||||
; Fill the remaining bytes.
|
||||
|
||||
L3: inx ; Counter low byte
|
||||
L3: dex ; Counter low byte
|
||||
beq L6 ; Branch on overflow
|
||||
L4: sta (ptr2),y ; Clear one byte
|
||||
L5: iny ; Bump pointer
|
||||
@@ -52,7 +52,7 @@ L5: iny ; Bump pointer
|
||||
|
||||
; Bump the counter high byte
|
||||
|
||||
L6: inc tmp2
|
||||
L6: dec tmp2
|
||||
bne L4
|
||||
|
||||
; Done, return dest
|
||||
|
||||
@@ -15,17 +15,11 @@
|
||||
_strnicmp:
|
||||
_strncasecmp:
|
||||
|
||||
; Convert the given counter value in a/x from a downward counter into an
|
||||
; upward counter, so we can increment the counter in the loop below instead
|
||||
; of decrementing it. This adds some overhead now, but is cheaper than
|
||||
; executing a more complex test in each iteration of the loop. We do also
|
||||
; correct the value by one, so we can do the test on top of the loop.
|
||||
|
||||
eor #$FF
|
||||
sta ptr3
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr3+1
|
||||
inx
|
||||
stx ptr3+1
|
||||
tax
|
||||
inx
|
||||
stx ptr3 ; save count with each byte incremented separately
|
||||
|
||||
; Get the remaining arguments
|
||||
|
||||
@@ -40,7 +34,7 @@ _strncasecmp:
|
||||
|
||||
; Start of compare loop. Check the counter.
|
||||
|
||||
Loop: inc ptr3
|
||||
Loop: dec ptr3
|
||||
beq IncHi ; increment high byte
|
||||
|
||||
; Compare a byte from the strings
|
||||
@@ -79,7 +73,7 @@ L2: ldx tmp1
|
||||
|
||||
; Increment hi byte
|
||||
|
||||
IncHi: inc ptr3+1
|
||||
IncHi: dec ptr3+1
|
||||
bne Comp ; jump if counter not zero
|
||||
|
||||
; Exit code if strings are equal. a/x not set
|
||||
|
||||
Reference in New Issue
Block a user