Skip to content

Optimize count-leading-zero routines #591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions src/crt/bctlz.src

This file was deleted.

101 changes: 101 additions & 0 deletions src/crt/ctlz.src
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
assume adl=1

section .text
public __bctlz
__bctlz:
cp a, 010h
jr c, .low4
cp a, 040h
jr c, .low6
add a, a
sbc a, a
inc a
ret
.low6:
add a, -020h
sbc a, a
add a, 3
ret
.low4:
cp a, 4
jr c, .low2
add a, -8
sbc a, a
add a, 5
ret
.low2:
add a, -3
cpl
adc a, 6
ret

section .text
public __sctlz
__sctlz:
ld a, h
or a, a
jr nz, __bctlz
ld a, l
require __sctlz.hijack

section .text
private __sctlz.hijack
__sctlz.hijack:
call __bctlz
add a, 8
ret

section .text
public __ictlz
__ictlz:
dec sp
push hl
inc sp
pop af
or a, a
jr nz, __bctlz
or a, h
jr nz, __sctlz.hijack
ld a, l
call __bctlz
add a, 16
ret

section .text
public __lctlz
__lctlz:
ld a, e
or a, a
jr nz, __bctlz
call __ictlz
add a, 8
ret

section .text
public __llctlz
__llctlz:
ld a, b
or a, a
jr nz, __bctlz
or a, c
jr nz, __sctlz.hijack
call __i48ctlz
add a, 16
ret

section .text
public __i48ctlz
__i48ctlz:
ex de, hl
add hl, de
or a, a
sbc hl, de
jr z, .low
call __ictlz
ex de, hl
ret
.low:
ex de, hl
call __ictlz
add a, 24
ret
31 changes: 0 additions & 31 deletions src/crt/i48ctlz.src

This file was deleted.

17 changes: 0 additions & 17 deletions src/crt/ictlz.src

This file was deleted.

20 changes: 0 additions & 20 deletions src/crt/lctlz.src

This file was deleted.

26 changes: 0 additions & 26 deletions src/crt/llctlz.src

This file was deleted.

17 changes: 0 additions & 17 deletions src/crt/sctlz.src

This file was deleted.

Loading
Loading