Skip to content

Commit acc64d9

Browse files
committed
fixed ultof and added tests
1 parent 52a64af commit acc64d9

File tree

7 files changed

+1454
-3
lines changed

7 files changed

+1454
-3
lines changed

src/crt/os.src

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,3 @@ __sshru_b := 000254h
4242
__stoi := 000260h
4343
public __stoiu
4444
__stoiu := 000264h
45-
public __ultof
46-
__ultof := 000280h

src/crt/ultof.src

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
assume adl=1
2+
3+
section .text
4+
5+
public __ultof
6+
7+
; round to nearest ties to even
8+
__ultof:
9+
bit 7, a
10+
jp z, __ltof ; common case
11+
; A:UBC > INT32_MAX
12+
res 7, a ; sets the LSB of the exponent
13+
sla c ; C = Round, NZ = Sticky
14+
; A:UBC >>= 8
15+
push af
16+
inc sp
17+
push bc
18+
inc sp
19+
pop bc
20+
inc sp
21+
ld a, $4F ; sets the exponent
22+
ret nc ; round down
23+
inc bc
24+
ret nz ; round up (this will not overflow because bit 23 is 0)
25+
; round to even
26+
res 0, c
27+
ret
28+
29+
extern __ltof

src/include/ti84pceg.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ namespace ti?
22822282
?_fcmp := 0000274h
22832283
?_fdiv := 0000278h
22842284
?_ftol := 000027Ch
2285-
?_ultof := 0000280h
2285+
;?_ultof := 0000280h
22862286
?_ltof := 0000284h
22872287
?_fmul := 0000288h
22882288
?_fneg := 000028Ch
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"transfer_files": [
3+
"bin/DEMO.8xp"
4+
],
5+
"target": {
6+
"name": "DEMO",
7+
"isASM": true
8+
},
9+
"sequence": [
10+
"action|launch",
11+
"delay|1000",
12+
"hashWait|1",
13+
"key|enter",
14+
"delay|300",
15+
"hashWait|2"
16+
],
17+
"hashes": {
18+
"1": {
19+
"description": "All tests passed or GDB1 error",
20+
"timeout": 5000,
21+
"start": "vram_start",
22+
"size": "vram_16_size",
23+
"expected_CRCs": [
24+
"38E2AD5A",
25+
"2C812DC2"
26+
]
27+
},
28+
"2": {
29+
"description": "Exit or GDB1 error",
30+
"start": "vram_start",
31+
"size": "vram_16_size",
32+
"expected_CRCs": [
33+
"FFAF89BA",
34+
"101734A5",
35+
"9DA19F44",
36+
"A32840C8",
37+
"349F4775",
38+
"271A9FBF",
39+
"82FD0B1E"
40+
]
41+
}
42+
}
43+
}

test/floating_point/ultof/makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# ----------------------------
2+
# Makefile Options
3+
# ----------------------------
4+
5+
NAME = DEMO
6+
ICON = icon.png
7+
DESCRIPTION = "CE C Toolchain Demo"
8+
COMPRESSED = NO
9+
10+
CFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -O0
11+
CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -O0
12+
13+
PREFER_OS_LIBC = NO
14+
15+
# ----------------------------
16+
17+
include $(shell cedev-config --makefile)

test/floating_point/ultof/src/main.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include <stdbool.h>
2+
#include <stddef.h>
3+
#include <stdint.h>
4+
#include <stdio.h>
5+
#include <assert.h>
6+
#include <ti/screen.h>
7+
#include <ti/getcsc.h>
8+
#include <sys/util.h>
9+
10+
#include "ultof_lut.h"
11+
12+
typedef union F32_pun {
13+
float flt;
14+
uint32_t bin;
15+
} F32_pun;
16+
17+
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
18+
19+
void print_failed(uint32_t input, uint32_t guess, uint32_t truth) {
20+
printf(
21+
"I: %lu\nU: %08lX -->\nG: %08lX !=\nT: %08lX\n",
22+
input, input, guess, truth
23+
);
24+
}
25+
26+
size_t run_test(void) {
27+
typedef uint32_t input_t;
28+
typedef F32_pun output_t;
29+
30+
const size_t length = ARRAY_LENGTH(ultof_LUT_input);
31+
const input_t *input = (const input_t* )((const void*)ultof_LUT_input );
32+
const output_t *output = (const output_t*)((const void*)ultof_LUT_output);
33+
34+
for (size_t i = 0; i < length; i++) {
35+
F32_pun result;
36+
37+
result.flt = (float)input[i];
38+
if (result.bin != output[i].bin) {
39+
// ignore round to maximum magnitude errors from __ltof
40+
bool ignore_ltof_failure =
41+
(input[i] <= INT32_MAX) &&
42+
(result.bin == output[i].bin + 1);
43+
if (ignore_ltof_failure == false) {
44+
print_failed(input[i], result.bin, output[i].bin);
45+
return i;
46+
}
47+
}
48+
}
49+
50+
/* passed all */
51+
return SIZE_MAX;
52+
}
53+
54+
int main(void) {
55+
os_ClrHome();
56+
size_t fail_index = run_test();
57+
if (fail_index == SIZE_MAX) {
58+
printf("All tests passed");
59+
} else {
60+
printf("Failed test: %zu", fail_index);
61+
}
62+
63+
while (!os_GetCSC());
64+
65+
return 0;
66+
}

0 commit comments

Comments
 (0)