Skip to content

Commit 20619c1

Browse files
committed
fixed fmodf
1 parent fe08939 commit 20619c1

5 files changed

Lines changed: 155 additions & 8 deletions

File tree

src/libc/fmodf.src

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@
1515

1616
_fmod:
1717
_fmodf:
18+
pop iy
19+
pop bc ; X-lo
1820
pop de
19-
pop bc
20-
ex (sp), hl
21-
ld a, l
22-
call __fprem
23-
push bc
24-
ex (sp), hl
21+
ld a, e ; X-hi
22+
pop hl ; Y-lo
23+
pop de ; Y-hi
24+
push de
25+
push hl
2526
push de
26-
ld e, a
27-
ret
27+
push bc
28+
call __fprem
29+
jp (iy)
2830

2931
.extern __fprem
3032

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+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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 -ffreestanding -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c17
11+
CXXFLAGS = -Wall -Wextra -Wshadow -ffreestanding -Wfloat-conversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion -Oz -std=c++17
12+
13+
HAS_MATH_ERRNO = YES
14+
PREFER_OS_LIBC = NO
15+
PREFER_OS_CRT = NO
16+
17+
# ----------------------------
18+
19+
include $(shell cedev-config --makefile)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.assume adl=1
2+
3+
.section .text
4+
5+
.global _frem_libcall
6+
.type _frem_libcall, @function
7+
8+
_frem_libcall:
9+
ld iy, 0
10+
add iy, sp
11+
ld bc, (iy + 3)
12+
ld a, (iy + 6)
13+
ld hl, (iy + 9)
14+
ld e, (iy + 12)
15+
call __frem
16+
push bc
17+
pop hl
18+
ld e, a
19+
ret
20+
21+
.extern __frem
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include <stdbool.h>
2+
#include <stddef.h>
3+
#include <stdint.h>
4+
#include <stdio.h>
5+
#include <math.h>
6+
#include <assert.h>
7+
#include <ti/screen.h>
8+
#include <ti/getcsc.h>
9+
#include <sys/util.h>
10+
#include <ti/sprintf.h>
11+
12+
#define C(expr) if (!(expr)) { return __LINE__; }
13+
14+
float frem_libcall(float, float);
15+
16+
size_t run_test(void) {
17+
float f32_pos_pi = (float)M_PI;
18+
float f32_neg_pi = (float)-M_PI;
19+
float f32_pos_one = 1.0f;
20+
float f32_neg_one = -1.0f;
21+
22+
float trunc_part;
23+
24+
/* fmodf test */
25+
C((fmodf(f32_pos_pi, f32_pos_one) == modff(f32_pos_pi, &trunc_part)));
26+
C((trunc_part == 3.0f));
27+
C((fmodf(f32_neg_pi, f32_pos_one) == modff(f32_neg_pi, &trunc_part)));
28+
C((trunc_part == -3.0f));
29+
C((fmodf(f32_pos_pi, f32_neg_one) == modff(f32_pos_pi, &trunc_part)));
30+
C((trunc_part == 3.0f));
31+
C((fmodf(f32_neg_pi, f32_neg_one) == modff(f32_neg_pi, &trunc_part)));
32+
C((trunc_part == -3.0f));
33+
34+
/* frem test */
35+
C((frem_libcall(f32_pos_pi, f32_pos_one) == modff(f32_pos_pi, &trunc_part)));
36+
C((trunc_part == 3.0f));
37+
C((frem_libcall(f32_neg_pi, f32_pos_one) == modff(f32_neg_pi, &trunc_part)));
38+
C((trunc_part == -3.0f));
39+
C((frem_libcall(f32_pos_pi, f32_neg_one) == modff(f32_pos_pi, &trunc_part)));
40+
C((trunc_part == 3.0f));
41+
C((frem_libcall(f32_neg_pi, f32_neg_one) == modff(f32_neg_pi, &trunc_part)));
42+
C((trunc_part == -3.0f));
43+
44+
/* passed all */
45+
return SIZE_MAX;
46+
}
47+
48+
int main(void) {
49+
os_ClrHome();
50+
size_t fail_index = run_test();
51+
if (fail_index == SIZE_MAX) {
52+
puts("All tests passed");
53+
} else {
54+
char buf[sizeof("Failed test: 16777215")];
55+
boot_sprintf(buf, "Failed test: %u", fail_index);
56+
puts(buf);
57+
}
58+
59+
while (!os_GetCSC());
60+
61+
return 0;
62+
}

0 commit comments

Comments
 (0)