File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include <math.h>
2+ #include <stdbool.h>
3+ #include <stdint.h>
4+
5+ typedef union {
6+ struct {
7+ uint8_t carry : 1 ;
8+ uint8_t : 5 ;
9+ uint8_t zero : 1 ;
10+ uint8_t sign : 1 ;
11+ };
12+ uint8_t bin ;
13+ } Flags ;
14+
15+ typedef union {
16+ long double flt ;
17+ uint64_t bin ;
18+ } F64_pun ;
19+
20+ typedef struct {
21+ long double x ;
22+ uint8_t x_padding ;
23+ unsigned int const return_address ;
24+ long double y ;
25+ uint8_t y_padding ;
26+ } f64_cmp_arg ;
27+
28+ uint8_t _dcmpo_c (f64_cmp_arg const * __restrict const arg ) {
29+ F64_pun x , y ;
30+ x .flt = arg -> x ;
31+ y .flt = arg -> y ;
32+ Flags flags ;
33+ if (_isnanl (x .flt ) || _isnanl (y .flt )) {
34+ flags .zero = 0 ;
35+ flags .carry = 0 ;
36+ flags .sign = 1 ;
37+ return flags .bin ;
38+ }
39+ bool x_sign = _signbitl (x .flt );
40+ bool y_sign = _signbitl (y .flt );
41+ if (x_sign != y_sign ) {
42+ if (_iszerol (x .flt ) && _iszerol (y .flt )) {
43+ flags .zero = 1 ;
44+ flags .carry = 0 ;
45+ flags .sign = 0 ;
46+ return flags .bin ;
47+ }
48+ flags .zero = 0 ;
49+ flags .carry = x_sign ? 1 : 0 ;
50+ flags .sign = x_sign ? 1 : 0 ;
51+ return flags .bin ;
52+ }
53+ if (x .bin == y .bin ) {
54+ flags .zero = 1 ;
55+ flags .carry = 0 ;
56+ flags .sign = 0 ;
57+ return flags .bin ;
58+ }
59+ bool cmp_less = ((x .bin < y .bin ) != x_sign );
60+ flags .zero = 0 ;
61+ flags .carry = cmp_less ? 1 : 0 ;
62+ flags .sign = cmp_less ? 1 : 0 ;
63+ return flags .bin ;
64+ }
Original file line number Diff line number Diff line change 1+ .assume adl=1
2+
3+ .section .text.__dcmpo
4+
5+ .global __dcmpo
6+ .type __dcmpo, @function
7+
8+ __dcmpo:
9+ push bc
10+ push de
11+ push hl
12+ or a, a
13+ sbc hl, hl
14+ add hl, sp
15+ push iy
16+ push af
17+ push hl ; f64_cmp_arg*
18+ call __dcmpo_c
19+ ld l, a
20+ pop af
21+ pop af
22+ pop iy
23+
24+ ; Set the comparison flags
25+ ld h, a
26+ ex (sp), hl
27+ pop af
28+
29+ pop de
30+ pop bc
31+ ret
32+
33+ .section .text.__dcmpu
34+
35+ .global __dcmpu
36+ .type __dcmpu, @function
37+
38+ __dcmpu:
39+ push bc
40+ push de
41+ push hl
42+ or a, a
43+ sbc hl, hl
44+ add hl, sp
45+ push iy
46+ push af
47+ push hl ; f64_cmp_arg*
48+ call __dcmpo_c
49+ ld l, a
50+ pop af
51+ pop af
52+ pop iy
53+
54+ ; Set the comparison flags
55+ ld h, a
56+ ex (sp), hl
57+ pop af
58+
59+ pop de
60+ pop bc
61+ ret c ; If BC:UDE:UHL < (SP64): C = 1, Z = 0
62+ scf
63+ ret p ; If BC:UDE:UHL >= (SP64): C = 1, Z = (euhl == aubc)
64+ cp a, a ; If unordered: C = 0, Z = 1
65+ ret
66+
67+ ; uint8_t _dcmpo_c(f64_cmp_arg const *__restrict const arg)
68+ .extern __dcmpo_c
Original file line number Diff line number Diff line change 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|4000" ,
12+ " hashWait|1" ,
13+ " key|enter" ,
14+ " delay|400" ,
15+ " hashWait|2"
16+ ],
17+ "hashes" : {
18+ "1" : {
19+ "description" : " All tests passed or GDB1 error" ,
20+ "timeout" : 6000 ,
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+ }
Original file line number Diff line number Diff line change 1+ # ----------------------------
2+ # Makefile Options
3+ # ----------------------------
4+
5+ NAME = DEMO
6+ ICON = icon.png
7+ DESCRIPTION = "CE C Toolchain Demo"
8+ COMPRESSED = NO
9+
10+ COMMON_FLAGS = -Wall -Wextra -Wshadow -Wformat=2 -Wconversion -Wimplicit-float-conversion -Wimplicit-int-float-conversion
11+ COMMON_FLAGS += -Oz -ffreestanding
12+
13+ CFLAGS = ${COMMON_FLAGS} -std=c17
14+ CXXFLAGS = ${COMMON_FLAGS} -std=c++20
15+
16+ PREFER_OS_LIBC = NO
17+ PREFER_OS_CRT = NO
18+
19+ # ----------------------------
20+
21+ include $(shell cedev-config --makefile)
Original file line number Diff line number Diff line change 1+ .assume adl= 1
2+
3+ . section .text
4+
5+ . global _crt_fcmpo
6+ .type _crt_fcmpo , @function
7+ _crt_fcmpo:
8+ ld iy , 0
9+ add iy , sp
10+ ld hl , (iy + 3 )
11+ ld e , (iy + 6 )
12+ ld bc , (iy + 9 )
13+ ld a , (iy + 12 )
14+ call __fpcmpo
15+ push af
16+ pop hl
17+ ld a , l
18+ ret
19+ . extern __fpcmpo
20+
21+ . global _crt_fcmpu
22+ .type _crt_fcmpu , @function
23+ _crt_fcmpu:
24+ ld iy , 0
25+ add iy , sp
26+ ld hl , (iy + 3 )
27+ ld e , (iy + 6 )
28+ ld bc , (iy + 9 )
29+ ld a , (iy + 12 )
30+ call __fpcmpu
31+ push af
32+ pop hl
33+ ld a , l
34+ ret
35+ . extern __fpcmpu
36+
37+ . global _crt_dcmpo
38+ .type _crt_dcmpo , @function
39+ _crt_dcmpo:
40+ ld iy , 0
41+ add iy , sp
42+ ld hl , (iy + 18 )
43+ push hl
44+ ld hl , (iy + 15 )
45+ push hl
46+ ld hl , (iy + 12 )
47+ push hl
48+ ld bc , (iy + 9 )
49+ ld de , (iy + 6 )
50+ ld hl , (iy + 3 )
51+ call __dcmpo
52+ push af
53+ pop hl
54+ ld a , l
55+ ld sp , iy
56+ ret
57+ . extern __dcmpo
58+
59+ . global _crt_dcmpu
60+ .type _crt_dcmpu , @function
61+ _crt_dcmpu:
62+ ld iy , 0
63+ add iy , sp
64+ ld hl , (iy + 18 )
65+ push hl
66+ ld hl , (iy + 15 )
67+ push hl
68+ ld hl , (iy + 12 )
69+ push hl
70+ ld bc , (iy + 9 )
71+ ld de , (iy + 6 )
72+ ld hl , (iy + 3 )
73+ call __dcmpu
74+ push af
75+ pop hl
76+ ld a , l
77+ ld sp , iy
78+ ret
79+ . extern __dcmpu
You can’t perform that action at this time.
0 commit comments