Skip to content

Commit f5c00f1

Browse files
ZERICO2005mateoconlechuga
authored andcommitted
Removed 3 bytes from ltod. non-zero faster by 1F, zero slower by 1F
1 parent a311c29 commit f5c00f1

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/crt/ltod.src

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,24 @@ __ltod:
4848
private __ltod.hijack
4949
__ltod.hijack:
5050
call __lctlz
51-
cp a, 32
51+
inc.s bc ; clear UBC
52+
ld b, a ; <<= 8
53+
xor a, $20 ; turns 32 into zero and clears carry flag
5254
jr z, .zero
5355
; clears the MSB since the float will be normalized
5456
; x <<= clz_result + 1; /* shift by 32 is UB */
5557
if 0
5658
; calculate the exponent
5759
push hl
5860
; 1023 + 31 = 1054 = 0x41E
59-
inc.s bc
60-
or a, a
61-
ld b, a ; <<= 8
6261
ld hl, $041E00
6362
ld c, l ; ld c, 0
6463
sbc hl, bc
6564
ld l, e ; (expon16 << (16 + 24)) | (mant48)
6665
ex de, hl
6766
pop hl
6867

69-
ld b, a
68+
; ld b, a
7069
inc b
7170
ld a, e
7271
.loop32: ; shift by 32 is not UB here!
@@ -78,17 +77,14 @@ else
7877
; calculate the exponent
7978
push hl
8079
; 1023 + 31 = 1054 = 0x41E
81-
inc.s bc
82-
or a, a
83-
ld b, a ; <<= 8
8480
ld hl, $041E00
8581
ld c, l ; ld c, 0
8682
sbc hl, bc
8783
ld l, e ; (expon16 << (16 + 24)) | (mant48)
8884
ex de, hl
8985

86+
ld l, b
9087
pop bc
91-
ld l, a
9288
ld a, e
9389
call __lshl
9490
push bc
@@ -112,7 +108,7 @@ end if
112108
ret ; negative
113109

114110
.zero:
115-
sbc hl, hl
111+
; E:UHL and A are zero
116112
ex de, hl
117113
sbc hl, hl
118114
ld b, e

0 commit comments

Comments
 (0)