File tree Expand file tree Collapse file tree 2 files changed +123
-142
lines changed Expand file tree Collapse file tree 2 files changed +123
-142
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 22
33 section .text
44
5- public __ultod, __ltod
5+ if 0
66; public __utod, __itod
77
88; __utod:
@@ -41,4 +41,125 @@ __ltod:
4141 pop af, af, iy
4242 ret
4343
44- extern __ultod_c, __lneg
44+ extern __ultod_c
45+
46+ end if
47+
48+ public __itod
49+ __itod:
50+ push hl
51+ add hl, hl
52+ pop hl
53+ push af
54+ ld e, 0
55+ call c, __ineg
56+ jr __ltod.hijack
57+
58+ section .text
59+
60+ public __utod
61+ __utod:
62+ ld e, 0
63+
64+ require __ultod
65+
66+ section .text
67+
68+ public __ultod
69+ __ultod:
70+ or a, a
71+ push af
72+ jr __ltod.hijack
73+
74+ section .text
75+
76+ public __ltod
77+ __ltod:
78+ rlc e
79+ push af
80+ rrc e
81+ call c, __lneg
82+
83+ require __ltod.hijack
84+
85+ section .text
86+
87+ private __ltod.hijack
88+ __ltod.hijack:
89+ call __lctlz
90+ cp a, 32
91+ jr z, .zero
92+ ; clears the MSB since the float will be normalized
93+ ; x <<= clz_result + 1; /* shift by 32 is UB */
94+ if 0
95+ ; calculate the exponent
96+ push hl
97+ ; 1023 + 31 = 1054 = 0x41E
98+ inc.s bc
99+ or a, a
100+ ld b, a ; <<= 8
101+ ld hl, $041E00
102+ ld c, l ; ld c, 0
103+ sbc hl, bc
104+ ld l, e ; (expon16 << (16 + 24)) | (mant48)
105+ ex de, hl
106+ pop hl
107+
108+ ld b, a
109+ inc b
110+ ld a, e
111+ .loop32: ; shift by 32 is not UB here!
112+ add hl, hl
113+ rla
114+ djnz .loop32
115+ ld e, a
116+ else
117+ ; calculate the exponent
118+ push hl
119+ ; 1023 + 31 = 1054 = 0x41E
120+ inc.s bc
121+ or a, a
122+ ld b, a ; <<= 8
123+ ld hl, $041E00
124+ ld c, l ; ld c, 0
125+ sbc hl, bc
126+ ld l, e ; (expon16 << (16 + 24)) | (mant48)
127+ ex de, hl
128+
129+ pop bc
130+ ld l, a
131+ ld a, e
132+ call __lshl
133+ push bc
134+ pop hl
135+ ; shift by 32 is UB
136+ add hl, hl
137+ rla
138+ ld e, a
139+ end if
140+
141+ ; UDE:D has expon, E:UHL has mant
142+ ; Float64_mant_bits - uint48_bits = 4
143+ ld c, 16 + 4
144+ push bc
145+ call __llshl
146+ pop af ; reset SP
147+ .finish:
148+ pop af
149+ ret nc ; positive
150+ set 7, b
151+ ret ; negative
152+
153+ .zero:
154+ sbc hl, hl
155+ ex de, hl
156+ sbc hl, hl
157+ ld b, e
158+ ld c, e
159+ pop af
160+ ret
161+
162+ extern __lneg
163+ extern __lctlz
164+ extern __lshl
165+ extern __llshl
You can’t perform that action at this time.
0 commit comments