Skip to content

Pr/finish c23 stdbit #587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion examples/standalone_examples/math_test/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
#include <stdio.h>
#include <string.h>


#ifdef _EZ80

# include <debug.h>
# include <ti/screen.h>
# include <ti/getcsc.h>
# include <ez80_builtin.h>

# if INTERACTIVE
# define x_printf printf
Expand Down Expand Up @@ -77,6 +77,7 @@ static int24_t __builtin_bitreverse24(int24_t x)

#endif

#ifndef _EZ80
static int48_t __builtin_bitreverse48(int48_t x)
{
// return __builtin_bitreverse64(x) >> 16;
Expand All @@ -91,6 +92,20 @@ static int __builtin_popcounti48(uint48_t x)
{
return __builtin_popcountll(x & ((1LL << 48) - 1));
}
#else
static int48_t __builtin_bitreverse48(int48_t x)
{
return __ez80_bitreverse48(x);
}
static uint48_t __builtin_bswap48(uint48_t x)
{
return __ez80_bswap48(x);
}
static int __builtin_popcounti48(uint48_t x)
{
return __ez80_popcounti48(x);
}
#endif
static int24_t iabs(int24_t x)
{
return x < 0 ? (int24_t)-x : x;
Expand Down
12 changes: 0 additions & 12 deletions src/libc/ez80_builtin.src
Original file line number Diff line number Diff line change
Expand Up @@ -298,17 +298,6 @@ ___ez80_bswap48:
push de, hl, bc
jp __i48bswap

;-------------------------------------------------------------------------------

section .text

public ___ez80_bitreverse24
___ez80_bitreverse24:
pop bc
ex (sp), hl
push bc
jp __ibitrev

;-------------------------------------------------------------------------------

section .text
Expand Down Expand Up @@ -447,7 +436,6 @@ ___ez80_rotateright48:
extern __spopcnt
extern __i48popcnt

extern __ibitrev
extern __i48bitrev

extern __i48bswap
110 changes: 110 additions & 0 deletions src/libc/include/ez80_builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,149 @@
extern "C" {
#endif

#if __has_builtin(__builtin_clzc)
#define __ez80_clzc __builtin_clzc
#else
unsigned char __ez80_clzc(unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_clzi48)
#define __ez80_clzi48 __builtin_clzi48
#else
unsigned char __ez80_clzi48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_ctzc)
#define __ez80_ctzc __builtin_ctzc
#else
unsigned char __ez80_ctzc(unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_ctzi48)
#define __ez80_ctzi48 __builtin_ctzi48
#else
unsigned char __ez80_ctzi48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_ffsc)
#define __ez80_ffsc __builtin_ffsc
#else
unsigned char __ez80_ffsc(unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_ffss)
#define __ez80_ffss __builtin_ffss
#else
unsigned char __ez80_ffss(unsigned short) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_ffsi48)
#define __ez80_ffsi48 __builtin_ffsi48
#else
unsigned char __ez80_ffsi48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_clrsbc)
#define __ez80_clrsbc __builtin_clrsbc
#else
unsigned char __ez80_clrsbc(unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_clrsbs)
#define __ez80_clrsbs __builtin_clrsbs
#else
unsigned char __ez80_clrsbs(unsigned short) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_clrsbi48)
#define __ez80_clrsbi48 __builtin_clrsbi48
#else
unsigned char __ez80_clrsbi48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_parityc)
#define __ez80_parityc __builtin_parityc
#else
bool __ez80_parityc(unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_paritys)
#define __ez80_paritys __builtin_paritys
#else
bool __ez80_paritys(unsigned short) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_parityi48)
#define __ez80_parityi48 __builtin_parityi48
#else
bool __ez80_parityi48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_popcountc)
#define __ez80_popcountc __builtin_popcountc
#else
unsigned char __ez80_popcountc(unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_popcounts)
#define __ez80_popcounts __builtin_popcounts
#else
unsigned char __ez80_popcounts(unsigned short) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_popcounti48)
#define __ez80_popcounti48 __builtin_popcounti48
#else
unsigned char __ez80_popcounti48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_bswap24)
#define __ez80_bswap24 __builtin_bswap24
#else
unsigned int __ez80_bswap24(unsigned int) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_bswap48)
#define __ez80_bswap48 __builtin_bswap48
#else
unsigned __int48 __ez80_bswap48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_bitreverse24)
#define __ez80_bitreverse24 __builtin_bitreverse24
#else
unsigned int __ez80_bitreverse24(unsigned int) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_bitreverse48)
#define __ez80_bitreverse48 __builtin_bitreverse48
#else
unsigned __int48 __ez80_bitreverse48(unsigned __int48) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_rotateleft24)
#define __ez80_rotateleft24 __builtin_rotateleft24
#else
unsigned int __ez80_rotateleft24(unsigned int, unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_rotateleft48)
#define __ez80_rotateleft48 __builtin_rotateleft48
#else
unsigned __int48 __ez80_rotateleft48(unsigned __int48, unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_rotateright24)
#define __ez80_rotateright24 __builtin_rotateright24
#else
unsigned int __ez80_rotateright24(unsigned int, unsigned char) __NOEXCEPT_CONST;
#endif

#if __has_builtin(__builtin_rotateright48)
#define __ez80_rotateright48 __builtin_rotateright48
#else
unsigned __int48 __ez80_rotateright48(unsigned __int48, unsigned char) __NOEXCEPT_CONST;
#endif

#ifdef __cplusplus
}
Expand Down
Loading
Loading