Skip to content

Commit 29db8e3

Browse files
committed
Implemented the rest of C23 <stdbit.h> and fixed <ez80_builtin.h>
1 parent 21e2bdc commit 29db8e3

File tree

9 files changed

+1853
-193
lines changed

9 files changed

+1853
-193
lines changed

examples/standalone_examples/math_test/src/main.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include <stdio.h>
1212
#include <string.h>
1313

14-
1514
#ifdef _EZ80
1615

1716
# include <debug.h>
1817
# include <ti/screen.h>
1918
# include <ti/getcsc.h>
19+
# include <ez80_builtin.h>
2020

2121
# if INTERACTIVE
2222
# define x_printf printf
@@ -77,6 +77,7 @@ static int24_t __builtin_bitreverse24(int24_t x)
7777

7878
#endif
7979

80+
#ifndef _EZ80
8081
static int48_t __builtin_bitreverse48(int48_t x)
8182
{
8283
// return __builtin_bitreverse64(x) >> 16;
@@ -91,6 +92,20 @@ static int __builtin_popcounti48(uint48_t x)
9192
{
9293
return __builtin_popcountll(x & ((1LL << 48) - 1));
9394
}
95+
#else
96+
static int48_t __builtin_bitreverse48(int48_t x)
97+
{
98+
return __ez80_bitreverse48(x);
99+
}
100+
static uint48_t __builtin_bswap48(uint48_t x)
101+
{
102+
return __ez80_bswap48(x);
103+
}
104+
static int __builtin_popcounti48(uint48_t x)
105+
{
106+
return __ez80_popcounti48(x);
107+
}
108+
#endif
94109
static int24_t iabs(int24_t x)
95110
{
96111
return x < 0 ? (int24_t)-x : x;

src/libc/ez80_builtin.src

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,6 @@ ___ez80_bswap48:
298298
push de, hl, bc
299299
jp __i48bswap
300300

301-
;-------------------------------------------------------------------------------
302-
303-
section .text
304-
305-
public ___ez80_bitreverse24
306-
___ez80_bitreverse24:
307-
pop bc
308-
ex (sp), hl
309-
push bc
310-
jp __ibitrev
311-
312301
;-------------------------------------------------------------------------------
313302

314303
section .text
@@ -447,7 +436,6 @@ ___ez80_rotateright48:
447436
extern __spopcnt
448437
extern __i48popcnt
449438

450-
extern __ibitrev
451439
extern __i48bitrev
452440

453441
extern __i48bswap

src/libc/include/ez80_builtin.h

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,149 @@
88
extern "C" {
99
#endif
1010

11+
#if __has_builtin(__builtin_clzc)
12+
#define __ez80_clzc __builtin_clzc
13+
#else
1114
unsigned char __ez80_clzc(unsigned char) __NOEXCEPT_CONST;
15+
#endif
16+
17+
#if __has_builtin(__builtin_clzi48)
18+
#define __ez80_clzi48 __builtin_clzi48
19+
#else
1220
unsigned char __ez80_clzi48(unsigned __int48) __NOEXCEPT_CONST;
21+
#endif
1322

23+
#if __has_builtin(__builtin_ctzc)
24+
#define __ez80_ctzc __builtin_ctzc
25+
#else
1426
unsigned char __ez80_ctzc(unsigned char) __NOEXCEPT_CONST;
27+
#endif
28+
29+
#if __has_builtin(__builtin_ctzi48)
30+
#define __ez80_ctzi48 __builtin_ctzi48
31+
#else
1532
unsigned char __ez80_ctzi48(unsigned __int48) __NOEXCEPT_CONST;
33+
#endif
1634

35+
#if __has_builtin(__builtin_ffsc)
36+
#define __ez80_ffsc __builtin_ffsc
37+
#else
1738
unsigned char __ez80_ffsc(unsigned char) __NOEXCEPT_CONST;
39+
#endif
40+
41+
#if __has_builtin(__builtin_ffss)
42+
#define __ez80_ffss __builtin_ffss
43+
#else
1844
unsigned char __ez80_ffss(unsigned short) __NOEXCEPT_CONST;
45+
#endif
46+
47+
#if __has_builtin(__builtin_ffsi48)
48+
#define __ez80_ffsi48 __builtin_ffsi48
49+
#else
1950
unsigned char __ez80_ffsi48(unsigned __int48) __NOEXCEPT_CONST;
51+
#endif
2052

53+
#if __has_builtin(__builtin_clrsbc)
54+
#define __ez80_clrsbc __builtin_clrsbc
55+
#else
2156
unsigned char __ez80_clrsbc(unsigned char) __NOEXCEPT_CONST;
57+
#endif
58+
59+
#if __has_builtin(__builtin_clrsbs)
60+
#define __ez80_clrsbs __builtin_clrsbs
61+
#else
2262
unsigned char __ez80_clrsbs(unsigned short) __NOEXCEPT_CONST;
63+
#endif
64+
65+
#if __has_builtin(__builtin_clrsbi48)
66+
#define __ez80_clrsbi48 __builtin_clrsbi48
67+
#else
2368
unsigned char __ez80_clrsbi48(unsigned __int48) __NOEXCEPT_CONST;
69+
#endif
2470

71+
#if __has_builtin(__builtin_parityc)
72+
#define __ez80_parityc __builtin_parityc
73+
#else
2574
bool __ez80_parityc(unsigned char) __NOEXCEPT_CONST;
75+
#endif
76+
77+
#if __has_builtin(__builtin_paritys)
78+
#define __ez80_paritys __builtin_paritys
79+
#else
2680
bool __ez80_paritys(unsigned short) __NOEXCEPT_CONST;
81+
#endif
82+
83+
#if __has_builtin(__builtin_parityi48)
84+
#define __ez80_parityi48 __builtin_parityi48
85+
#else
2786
bool __ez80_parityi48(unsigned __int48) __NOEXCEPT_CONST;
87+
#endif
2888

89+
#if __has_builtin(__builtin_popcountc)
90+
#define __ez80_popcountc __builtin_popcountc
91+
#else
2992
unsigned char __ez80_popcountc(unsigned char) __NOEXCEPT_CONST;
93+
#endif
94+
95+
#if __has_builtin(__builtin_popcounts)
96+
#define __ez80_popcounts __builtin_popcounts
97+
#else
3098
unsigned char __ez80_popcounts(unsigned short) __NOEXCEPT_CONST;
99+
#endif
100+
101+
#if __has_builtin(__builtin_popcounti48)
102+
#define __ez80_popcounti48 __builtin_popcounti48
103+
#else
31104
unsigned char __ez80_popcounti48(unsigned __int48) __NOEXCEPT_CONST;
105+
#endif
32106

107+
#if __has_builtin(__builtin_bswap24)
108+
#define __ez80_bswap24 __builtin_bswap24
109+
#else
33110
unsigned int __ez80_bswap24(unsigned int) __NOEXCEPT_CONST;
111+
#endif
112+
113+
#if __has_builtin(__builtin_bswap48)
114+
#define __ez80_bswap48 __builtin_bswap48
115+
#else
34116
unsigned __int48 __ez80_bswap48(unsigned __int48) __NOEXCEPT_CONST;
117+
#endif
35118

119+
#if __has_builtin(__builtin_bitreverse24)
120+
#define __ez80_bitreverse24 __builtin_bitreverse24
121+
#else
36122
unsigned int __ez80_bitreverse24(unsigned int) __NOEXCEPT_CONST;
123+
#endif
124+
125+
#if __has_builtin(__builtin_bitreverse48)
126+
#define __ez80_bitreverse48 __builtin_bitreverse48
127+
#else
37128
unsigned __int48 __ez80_bitreverse48(unsigned __int48) __NOEXCEPT_CONST;
129+
#endif
38130

131+
#if __has_builtin(__builtin_rotateleft24)
132+
#define __ez80_rotateleft24 __builtin_rotateleft24
133+
#else
39134
unsigned int __ez80_rotateleft24(unsigned int, unsigned char) __NOEXCEPT_CONST;
135+
#endif
136+
137+
#if __has_builtin(__builtin_rotateleft48)
138+
#define __ez80_rotateleft48 __builtin_rotateleft48
139+
#else
40140
unsigned __int48 __ez80_rotateleft48(unsigned __int48, unsigned char) __NOEXCEPT_CONST;
141+
#endif
41142

143+
#if __has_builtin(__builtin_rotateright24)
144+
#define __ez80_rotateright24 __builtin_rotateright24
145+
#else
42146
unsigned int __ez80_rotateright24(unsigned int, unsigned char) __NOEXCEPT_CONST;
147+
#endif
148+
149+
#if __has_builtin(__builtin_rotateright48)
150+
#define __ez80_rotateright48 __builtin_rotateright48
151+
#else
43152
unsigned __int48 __ez80_rotateright48(unsigned __int48, unsigned char) __NOEXCEPT_CONST;
153+
#endif
44154

45155
#ifdef __cplusplus
46156
}

0 commit comments

Comments
 (0)