Skip to content

Commit 2c64cab

Browse files
[libc] optimize strnlen and add strlen
1 parent 67cb588 commit 2c64cab

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/libc/os.src

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ _strcmp := 0000C8h
2424
_strcpy := 0000CCh
2525
public _strcspn
2626
_strcspn := 0000D0h
27-
public _strlen
28-
_strlen := 0000D4h
2927
public _strncat
3028
_strncat := 0000D8h
3129
public _strncmp

src/libc/strlen.src

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
assume adl=1
2+
3+
section .text
4+
public _strlen
5+
6+
if PREFER_OS_LIBC
7+
8+
_strlen := $0000D4
9+
10+
else
11+
12+
_strlen:
13+
pop de
14+
ex (sp),hl
15+
push de
16+
push hl
17+
pop de
18+
xor a,a
19+
ld bc,0
20+
cpir
21+
scf
22+
sbc hl,de
23+
ret
24+
25+
end if
26+

src/libc/strnlen.src

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,13 @@
33
section .text
44
public _strnlen
55
_strnlen:
6-
call __frameset0
7-
ld de,(ix+6)
8-
ld bc,(ix+9)
9-
or a,a
10-
sbc hl,hl
11-
jr StartFor
12-
ForLoop:
13-
inc hl
14-
inc de
15-
StartFor:
16-
push hl
17-
or a,a
18-
sbc hl,bc
6+
pop hl,de,bc
7+
push bc,de,hl
8+
push de
199
pop hl
20-
jr nc,ReachedMax
21-
ld a,(de)
22-
or a,a
23-
jr nz,ForLoop
24-
ReachedMax:
25-
ld sp,ix
26-
pop ix
10+
xor a,a
11+
inc bc
12+
cpir
13+
scf
14+
sbc hl,de
2715
ret
28-
29-
extern __frameset0

0 commit comments

Comments
 (0)