Skip to content

Commit

Permalink
[libc] optimize strnlen and add strlen
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoconlechuga committed Nov 21, 2024
1 parent 67cb588 commit 2c64cab
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/libc/os.src
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ _strcmp := 0000C8h
_strcpy := 0000CCh
public _strcspn
_strcspn := 0000D0h
public _strlen
_strlen := 0000D4h
public _strncat
_strncat := 0000D8h
public _strncmp
Expand Down
26 changes: 26 additions & 0 deletions src/libc/strlen.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
assume adl=1

section .text
public _strlen

if PREFER_OS_LIBC

_strlen := $0000D4

else

_strlen:
pop de
ex (sp),hl
push de
push hl
pop de
xor a,a
ld bc,0
cpir
scf
sbc hl,de
ret

end if

30 changes: 8 additions & 22 deletions src/libc/strnlen.src
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,13 @@
section .text
public _strnlen
_strnlen:
call __frameset0
ld de,(ix+6)
ld bc,(ix+9)
or a,a
sbc hl,hl
jr StartFor
ForLoop:
inc hl
inc de
StartFor:
push hl
or a,a
sbc hl,bc
pop hl,de,bc
push bc,de,hl
push de
pop hl
jr nc,ReachedMax
ld a,(de)
or a,a
jr nz,ForLoop
ReachedMax:
ld sp,ix
pop ix
xor a,a
inc bc
cpir
scf
sbc hl,de
ret

extern __frameset0

0 comments on commit 2c64cab

Please sign in to comment.