Skip to content

Commit 69836e2

Browse files
committed
Added tests for utod/itod
1 parent d4015b4 commit 69836e2

File tree

4 files changed

+51
-94
lines changed

4 files changed

+51
-94
lines changed

src/crt/ltod.c

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/crt/ltod.src

Lines changed: 9 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,21 @@
22

33
section .text
44

5-
if 0
6-
; public __utod, __itod
7-
8-
; __utod:
9-
; ; u24_ret_f64
10-
; ld e, 0
11-
__ultod:
12-
; u32_ret_f64
13-
ld d, a
14-
.ultod_skip:
15-
push iy, de, hl
16-
call __ultod_c
17-
pop af, af, iy
18-
ret
19-
20-
; __itod:
21-
; ; i24_ret_f64
22-
; ld d, a
23-
; push hl
24-
; add hl, hl
25-
; sbc a, a
26-
; ld e, a
27-
; pop hl
28-
; jr __ltod.ltod_skip
29-
30-
__ltod:
31-
; i32_ret_f64
32-
ld d, a
33-
bit 7, e
34-
.ltod_skip:
35-
jr z, __ultod.ultod_skip ; positive argument
36-
; return -_ultod_c(labs(x))
37-
call __lneg
38-
push iy, de, hl
39-
call __ultod_c
40-
set 7, b ; negative result
41-
pop af, af, iy
42-
ret
43-
44-
extern __ultod_c
45-
46-
end if
47-
485
public __itod
6+
; (long double)int
497
__itod:
508
push hl
51-
add hl, hl
9+
add hl, hl ; extract signbit
5210
pop hl
5311
push af
5412
ld e, 0
55-
call c, __ineg
13+
call c, __ineg ; abs(UHL)
5614
jr __ltod.hijack
5715

5816
section .text
5917

6018
public __utod
19+
; (long double)unsigned int
6120
__utod:
6221
ld e, 0
6322

@@ -66,19 +25,21 @@ __utod:
6625
section .text
6726

6827
public __ultod
28+
; (long double)unsigned long
6929
__ultod:
7030
or a, a
71-
push af
31+
push af
7232
jr __ltod.hijack
7333

7434
section .text
7535

7636
public __ltod
37+
; (long double)long
7738
__ltod:
7839
rlc e
7940
push af
8041
rrc e
81-
call c, __lneg
42+
call c, __lneg ; abs(E:UHL)
8243

8344
require __ltod.hijack
8445

@@ -159,6 +120,7 @@ end if
159120
pop af
160121
ret
161122

123+
extern __ineg
162124
extern __lneg
163125
extern __lctlz
164126
extern __lshl
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public _CRT_utod, _CRT_itod
6+
7+
_CRT_utod:
8+
ld hl, 3
9+
add hl, sp
10+
ld hl, (hl)
11+
jp __utod
12+
13+
_CRT_itod:
14+
ld hl, 3
15+
add hl, sp
16+
ld hl, (hl)
17+
jp __itod
18+
19+
extern __utod
20+
extern __itod

test/floating_point/float64_from_integer/src/main.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ void print_failed(uint64_t input, uint64_t guess, uint64_t truth) {
2525
);
2626
}
2727

28+
29+
long double CRT_utod(unsigned int);
30+
long double CRT_itod(signed int);
31+
2832
size_t run_test(const char** failed_func) {
2933
typedef struct { uint32_t u32; uint64_t u64; } input_t;
3034
typedef struct { F64_pun fu32; F64_pun fi32; F64_pun fu64; F64_pun fi64; } output_t;
@@ -50,6 +54,24 @@ size_t run_test(const char** failed_func) {
5054
return i;
5155
}
5256

57+
if ((uint32_t)input[i].u32 <= UINT24_MAX) {
58+
result.flt = CRT_utod((uint24_t)input[i].u32);
59+
if (result.bin != output[i].fu32.bin) {
60+
print_failed((uint64_t)input[i].u32, result.bin, output[i].fu32.bin);
61+
*failed_func = "utod";
62+
return i;
63+
}
64+
}
65+
66+
if ((int32_t)input[i].u32 >= INT24_MIN && (int32_t)input[i].u32 <= INT24_MAX) {
67+
result.flt = CRT_itod((int24_t)input[i].u32);
68+
if (result.bin != output[i].fi32.bin) {
69+
print_failed((uint64_t)input[i].u32, result.bin, output[i].fi32.bin);
70+
*failed_func = "itod";
71+
return i;
72+
}
73+
}
74+
5375
result.flt = (long double)((uint64_t)input[i].u64);
5476
if (result.bin != output[i].fu64.bin) {
5577
print_failed((uint64_t)input[i].u64, result.bin, output[i].fu64.bin);

0 commit comments

Comments
 (0)