Skip to content

Commit deea28e

Browse files
committed
optimized TICE calloc
1 parent 377c65c commit deea28e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

src/libc/calloc.src

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,23 @@ _calloc:
2323
pop bc ; BC = size
2424
; test for NULL
2525
add hl, bc
26-
; or a, a ; .assumes that ptr + size does not overflow
26+
; or a, a ; assumes that ptr + size does not overflow
2727
sbc hl, bc
2828
ret z ; return NULL
2929
; inlined bzero
30-
push hl
31-
ex de, hl ; DE = dest
32-
; test if the size is zero
33-
scf
34-
sbc hl, hl
35-
add hl, bc
36-
jr nc, .L.finish
37-
; large region of all zeros on the Ti84CE
38-
ld hl, $E40000 ; HL = src
39-
ldir
40-
.L.finish:
41-
pop hl ; return value
30+
31+
dec bc
32+
add hl, bc ; move to the end of dst
33+
; non-zero + (size - 1) sets carry if size is zero
34+
jr c, .L.zero_size
35+
inc bc
36+
ex de, hl ; DE = dst
37+
; uses the all zeros address range $E40000-$EFFFFF on the Ti84CE
38+
ld hl, $EFFFFF ; HL = src
39+
lddr
40+
ex de, hl
41+
.L.zero_size:
42+
inc hl
4243
ret
4344

4445
.else

0 commit comments

Comments
 (0)