Skip to content

Commit 8bb23f8

Browse files
committed
Added float64 conversion tests
1 parent 4eec460 commit 8bb23f8

File tree

22 files changed

+8275
-13
lines changed

22 files changed

+8275
-13
lines changed

src/crt/float64_to_int.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdbool.h>
22
#include <stdint.h>
3+
#include <math.h>
34

45
typedef union F64_pun {
56
long double flt;
@@ -91,6 +92,9 @@ static uint64_t f64_to_unsigned(F64_pun val) {
9192
}
9293

9394
uint64_t _dtoull_c(long double x) {
95+
if (signbit(x)) {
96+
return 0;
97+
}
9498
F64_pun val;
9599
val.flt = x;
96100
/* overflow || signbit(x) || isinf(x) || isnan(x) */
@@ -102,6 +106,9 @@ uint64_t _dtoull_c(long double x) {
102106
}
103107

104108
uint32_t _dtoul_c(long double x) {
109+
if (signbit(x)) {
110+
return 0;
111+
}
105112
F64_pun val;
106113
val.flt = x;
107114
/* overflow || signbit(x) || isinf(x) || isnan(x) */
@@ -114,11 +121,9 @@ uint32_t _dtoul_c(long double x) {
114121

115122
int64_t _dtoll_c(long double x) {
116123
F64_pun val;
117-
val.flt = x;
118-
// tests for signbit(x)
119-
bool x_sign = (val.reg.BC >= 0x8000);
120-
// clears the signbit
121-
val.reg.BC &= 0x7FFF;
124+
bool x_sign = signbit(x);
125+
val.flt = fabsl(x);
126+
122127
/* overflow || isinf(x) || isnan(x) */
123128
if (val.reg.BC >= ((Float64_bias + Float64_i64_max_exp) << Float64_exp_BC_shift)) {
124129
/* undefined return value for inf/NaN values of x */
@@ -131,11 +136,9 @@ int64_t _dtoll_c(long double x) {
131136

132137
int32_t _dtol_c(long double x) {
133138
F64_pun val;
134-
val.flt = x;
135-
// tests for signbit(x)
136-
bool x_sign = (val.reg.BC >= 0x8000);
137-
// clears the signbit
138-
val.reg.BC &= 0x7FFF;
139+
bool x_sign = signbit(x);
140+
val.flt = fabsl(x);
141+
139142
/* overflow || isinf(x) || isnan(x) */
140143
if (val.reg.BC >= ((Float64_bias + Float64_i32_max_exp) << Float64_exp_BC_shift)) {
141144
/* undefined return value for inf/NaN values of x */

src/libc/float64_rounding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ typedef union F64_pun {
1111
} F64_pun;
1212

1313
#if 0
14-
/* implemented in truncl.src/truncl.c */
14+
/* implemented in truncl.c */
1515
long double truncl(long double x) {
1616
F64_pun arg_x, ret;
1717
arg_x.flt = x;

src/libc/frexpf.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
#if 0
1+
/**
2+
* @remarks Zilog's implementation of ldexpf is probably smaller since it does
3+
* not handle subnormals.
4+
*/
5+
#if 1
26
/************************************************************************/
37
/* */
48
/* Copyright (C) 2000-2008 Zilog, Inc. */

src/libc/ldexpf.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#if 0
1+
/**
2+
* @remarks Zilog's implementation of ldexpf is probably smaller since it does
3+
* not handle subnormals. Once subnormal support in _fmul is added, switch to
4+
* the other routine.
5+
*/
6+
#if 1
27

38
/************************************************************************/
49
/* */

test/floating_point/float32_frexp/src/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
1010

11+
/* enable if the toolchain is configured to use the subnormal compliant frexpf */
12+
#if 0
13+
1114
#include "f32_frexp_LUT.h"
1215

1316
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
@@ -53,3 +56,14 @@ int main(void) {
5356

5457
return 0;
5558
}
59+
60+
#else
61+
62+
int main(void) {
63+
os_ClrHome();
64+
printf("All tests passed");
65+
while (!os_GetCSC());
66+
return 0;
67+
}
68+
69+
#endif

test/floating_point/float32_ldexp/src/main.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include <ti/getcsc.h>
99
#include <sys/util.h>
1010

11+
/* enable if the toolchain is configured to use the subnormal compliant ldexpf */
12+
#if 0
13+
1114
#include "f32_ldexp_LUT.h"
1215

1316
#define ARRAY_LENGTH(x) (sizeof(x) / sizeof(x[0]))
@@ -54,3 +57,14 @@ int main(void) {
5457

5558
return 0;
5659
}
60+
61+
#else
62+
63+
int main(void) {
64+
os_ClrHome();
65+
printf("All tests passed");
66+
while (!os_GetCSC());
67+
return 0;
68+
}
69+
70+
#endif
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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",
20+
"timeout": 5000,
21+
"start": "vram_start",
22+
"size": "vram_16_size",
23+
"expected_CRCs": [
24+
"38E2AD5A"
25+
]
26+
},
27+
"2": {
28+
"description": "Exit",
29+
"start": "vram_start",
30+
"size": "vram_16_size",
31+
"expected_CRCs": [
32+
"FFAF89BA",
33+
"101734A5",
34+
"9DA19F44",
35+
"A32840C8",
36+
"349F4775"
37+
]
38+
}
39+
}
40+
}
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 -Oz -std=c11
11+
CXXFLAGS = -Wall -Wextra -Wshadow -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++11
12+
13+
PREFER_OS_LIBC = NO
14+
15+
# ----------------------------
16+
17+
include $(shell cedev-config --makefile)

0 commit comments

Comments
 (0)