Skip to content

Implemented ldexpf in assembly (subnormal input/output returns zero) #602

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 2 commits into from
May 15, 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
30 changes: 15 additions & 15 deletions src/libc/frexpf.src
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ else
_frexp:
_frexpf:
ld iy, 0
lea de, iy - 127 ; bias ; $FFFF81
add iy, sp
ld hl, (iy + 3)
add hl, hl
Expand All @@ -29,40 +30,39 @@ _frexpf:
rr b
sbc hl, hl
ld l, a
ld de, -127 ; bias
; ld de, -127 ; bias
add hl, de
.ret_zero:
ex de, hl
.ret_subnormal:
res 7, (iy + 5)
.ret_zero:
.ret_self:
ld de, (iy + 9) ; int *expon
ex de, hl
ld hl, (iy + 9) ; int *expon
ld (hl), de
ld hl, (iy + 3) ; mantissa
ld e, b ; exponent
ret

.inf_nan:
ld hl, $7FFFFF ; INT_MAX
ld de, $7FFFFF ; INT_MAX
jr .ret_self

.maybe_subnormal:
add hl, bc
or a, a
sbc hl, bc
jr z, .ret_zero
ld e, d ; ld de, -1
add hl, de
inc hl ; restore HL
jr nc, .ret_zero
; input: HL output: A
call __ictlz
ld c, a
call __ishl
ld (iy + 3), hl
scf
sbc hl, hl
sub a, 131 ; (127 + 3) + 1? idk where this magic number comes from
cpl
add a, 131 ; 127 + 3 + 1? idk where this magic number comes from
ld l, a
ld a, b ; exponent
xor a, $3F
ld e, a ; DE was -1 from before
; copy exponent of 0.5f
ld a, b
xor a, $3F
ld b, a
jr .ret_subnormal

Expand Down
211 changes: 0 additions & 211 deletions src/libc/ldexpf.c

This file was deleted.

Loading
Loading