summaryrefslogtreecommitdiff
path: root/zap/include
diff options
context:
space:
mode:
Diffstat (limited to 'zap/include')
-rw-r--r--zap/include/zap/bs.h101
-rw-r--r--zap/include/zap/math.h63
-rw-r--r--zap/include/zap/mem.h50
-rw-r--r--zap/include/zap/mth.h125
4 files changed, 163 insertions, 176 deletions
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h
index 5da18d8..678b892 100644
--- a/zap/include/zap/bs.h
+++ b/zap/include/zap/bs.h
@@ -1,39 +1,104 @@
/*
- Copyright 2022 Gabriel Jensen.
+ Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#if !defined(zap_priv_hdr_bs)
#define zap_priv_hdr_bs
+#include <csys.h>
+
#if defined(__cplusplus)
-extern "C" {
+#define zap_priv_cdecl extern "C" {
+#define zap_priv_cdeclend }
+#else
+#define zap_priv_cdecl
+#define zap_priv_cdeclend
+#endif
+
+#if defined(__GNUC__)
+#define zap_priv_noret __attribute__ ((noreturn))
+#elif __STDC_VERSION__ == 202311 || __cplusplus == 201103
+#define zap_priv_noret [[noreturn]]
+#elif __STDC_VERSION__ == 199901
+#define zap_priv_noret _Noreturn
+#else
+#define zap_priv_noret
+#endif
+
+#if defined(__GNUC__)
+#define zap_priv_nothrw __attribute__ ((nothrow))
+#else
+#define zap_priv_nothrw
+#endif
+
+#if defined(__GNUC__)
+#define zap_priv_restr __restrict
+#elif __STDC_VERSION__ == 199901
+#define zap_priv_restr restrict
+#else
+#define zap_priv_restr
+#endif
+
+#if defined(__GNUC__)
+#define zap_priv_unseq __attribute__ ((const))
+#elif __STDC_VERSION__ == 202311
+#define zap_priv_unseq [[unsequenced]]
+#else
+#define zap_priv_unseq
#endif
-typedef unsigned char zap_bool;
+zap_priv_cdecl
+
+#define zap_ver ((unsigned long)+0x16u)
+
+#define zap_bytesz ((zap_sz)+0x8u)
+
#define zap_false ((zap_bool)+0x0u)
-#define zap_true ((zap_bool)+0xFFu)
+#define zap_true ((zap_bool)-0x1)
-typedef unsigned short zap_chr10;
-typedef unsigned int zap_chr20;
-typedef unsigned char zap_chr8;
+#define zap_nopos ((zap_sz)-0x1)
-typedef signed char zap_cmp;
-#define zap_eq ((zap_cmp)+0x0)
-#define zap_gt ((zap_cmp)+0x7F)
-#define zap_lt ((zap_cmp)-0x80)
+#define zap_nullptr ((void *)0x0u)
-#define zap_nopos ((zap_sz)+0xFFFFFFFFFFFFFFFFu)
+typedef unsigned char zap_i8;
+typedef unsigned short zap_i01;
+typedef unsigned int zap_i02;
+#if \
+ csys_arch_arm \
+ || csys_arch_ia32 \
+ || (csys_os_cur == csys_os_win && csys_arch_amd64)
+typedef unsigned long long zap_i04;
+#else
+typedef unsigned long zap_i04;
+#endif
-#define zap_nullptr (0x0u)
+typedef signed char zap_i8s;
+typedef short zap_i01s;
+typedef int zap_i02s;
+typedef long zap_i04s;
-typedef unsigned long zap_sz;
+typedef zap_i8 zap_chr8;
+typedef zap_i01 zap_chr01;
+typedef zap_i02 zap_chr02;
-#define zap_ver ((unsigned long)+0x15u)
+typedef zap_i8 zap_bool;
-#if defined(__cplusplus)
-}
+#if \
+ csys_arch_arm \
+ || csys_arch_ia32
+typedef zap_i8 zap_byte;
+typedef zap_i02 zap_ptr;
+typedef zap_i02 zap_sz;
+#else
+typedef zap_i8 zap_byte;
+typedef zap_i04 zap_ptr;
+typedef zap_i04 zap_sz;
#endif
+zap_priv_noret void zap_priv_trap(void);
+
+zap_priv_cdeclend
+
#endif
diff --git a/zap/include/zap/math.h b/zap/include/zap/math.h
new file mode 100644
index 0000000..5cacbef
--- /dev/null
+++ b/zap/include/zap/math.h
@@ -0,0 +1,63 @@
+/*
+ Copyright 2022-2023 Gabriel Jensen.
+ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
+*/
+
+#if !defined(zap_priv_hdr_math)
+#define zap_priv_hdr_math
+
+#include <zap/bs.h>
+
+zap_priv_cdecl
+
+typedef struct {
+ zap_i8 quot;
+ zap_i8 rem;
+} zap_quotrem8;
+
+typedef struct {
+ zap_i01 quot;
+ zap_i01 rem;
+} zap_quotrem01;
+
+typedef struct {
+ zap_i02 quot;
+ zap_i02 rem;
+} zap_quotrem02;
+
+typedef struct {
+ zap_i04 quot;
+ zap_i04 rem;
+} zap_quotrem04;
+
+zap_i04 zap_priv_div0(void);
+
+zap_priv_unseq zap_i8 zap_abs8( zap_i8s val);
+zap_priv_unseq zap_i01 zap_abs01(zap_i01s val);
+zap_priv_unseq zap_i02 zap_abs02(zap_i02s val);
+zap_priv_unseq zap_i04 zap_abs04(zap_i04s val);
+
+zap_priv_unseq zap_quotrem8 zap_divmod8( zap_i8 num,zap_i8 den);
+zap_priv_unseq zap_quotrem01 zap_divmod01(zap_i01 num,zap_i01 den);
+zap_priv_unseq zap_quotrem02 zap_divmod02(zap_i02 num,zap_i02 den);
+zap_priv_unseq zap_quotrem04 zap_divmod04(zap_i04 num,zap_i04 den);
+
+zap_priv_unseq zap_i8 zap_exp8( zap_i8 val,zap_i8 n);
+zap_priv_unseq zap_i01 zap_exp01(zap_i01 val,zap_i01 n);
+zap_priv_unseq zap_i02 zap_exp02(zap_i02 val,zap_i02 n);
+zap_priv_unseq zap_i04 zap_exp04(zap_i04 val,zap_i04 n);
+
+zap_priv_unseq zap_i8 zap_log8( zap_i8 val,zap_i8 n);
+zap_priv_unseq zap_i01 zap_log01(zap_i01 val,zap_i01 n);
+zap_priv_unseq zap_i02 zap_log02(zap_i02 val,zap_i02 n);
+zap_priv_unseq zap_i04 zap_log04(zap_i04 val,zap_i04 n);
+
+zap_priv_unseq zap_i8 zap_root8( zap_i8 val,zap_i8 n);
+zap_priv_unseq zap_i01 zap_root01(zap_i01 val,zap_i01 n);
+zap_priv_unseq zap_i02 zap_root02(zap_i02 val,zap_i02 n);
+zap_priv_unseq zap_i04 zap_root04(zap_i04 val,zap_i04 n);
+
+zap_priv_cdeclend
+
+#endif
diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h
index 8646d63..4085a20 100644
--- a/zap/include/zap/mem.h
+++ b/zap/include/zap/mem.h
@@ -1,7 +1,7 @@
/*
- Copyright 2022 Gabriel Jensen.
+ Copyright 2022-2023 Gabriel Jensen.
This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ If a copy of the MPL was not distributed with this file, You can obtain one at <https://mozilla.org/MPL/2.0>.
*/
#if !defined(zap_priv_hdr_mem)
@@ -9,37 +9,21 @@
#include <zap/bs.h>
-#if defined(__cplusplus)
-extern "C" {
-#endif
+zap_priv_cdecl
-typedef struct {
- void * ptr;
- zap_sz sz;
-} zap_mem;
-
-__attribute__ ((hot,warn_unused_result)) zap_sz zap_memcnt( void const * ptr, zap_sz sz, zap_sz num, zap_bool (* fn)(void const *));
-__attribute__ ((hot,nothrow)) zap_sz zap_memcp( void const * in, zap_sz num, void * out);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_bool zap_memeq( void const * lptr, zap_sz num, void const * rptr);
-__attribute__ ((hot,nothrow)) zap_sz zap_memfill( void * ptr, zap_sz num, unsigned char val);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_memfnd( void const * ptr, zap_sz num, unsigned char byte);
-__attribute__ ((hot)) void zap_memfor( void * ptr, zap_sz sz, zap_sz num, void (* fn)(void *));
-__attribute__ ((hot)) void zap_memgen( void * ptr, zap_sz sz, zap_sz num, void (* fn)(zap_sz,void *));
-__attribute__ ((hot,nothrow)) zap_sz zap_strcp( char const * in, char * out);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_bool zap_streq( char const * lstr, char const * rstr);
-__attribute__ ((hot,nothrow)) zap_sz zap_strfill( char * lstr, char chr);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_strfnd( char const * str, char chr);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_strlen( char const * str);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_utf20len( zap_chr20 const * utf20);
-__attribute__ ((hot,nothrow)) void zap_utf8dec( zap_chr8 const * in, zap_chr20 * out);
-__attribute__ ((hot,nothrow)) zap_sz zap_utf8declen(zap_chr8 const * utf8);
-__attribute__ ((hot,nothrow)) void zap_utf8enc( zap_chr20 const * in, zap_chr8 * out);
-__attribute__ ((hot,nothrow)) zap_sz zap_utf8enclen(zap_chr20 const * utf20);
-__attribute__ ((hot,nothrow)) void zap_win1252dec(zap_chr8 const * in, zap_chr20 * out);
-__attribute__ ((hot,nothrow)) void zap_win1252enc(zap_chr20 const * in, zap_chr8 * out);
-
-#if defined(__cplusplus)
-}
-#endif
+void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num);
+zap_bool zap_eq( void const * lbuf,void const * rbuf,zap_sz num);
+void zap_fill(void * dest,zap_byte val, zap_sz num);
+void * zap_srch(void const * buf, zap_byte val, zap_sz num);
+
+zap_sz zap_utf8declen(zap_chr8 const * buf);
+zap_sz zap_utf8enclen(zap_chr02 const * buf);
+
+void zap_utf8dec( zap_chr02 * dest,zap_chr8 const * src);
+void zap_utf8enc( zap_chr8 * dest,zap_chr02 const * src);
+void zap_win1252dec(zap_chr02 * dest,zap_chr8 const * src);
+void zap_win1252enc(zap_chr8 * dest,zap_chr02 const * src);
+
+zap_priv_cdeclend
#endif
diff --git a/zap/include/zap/mth.h b/zap/include/zap/mth.h
deleted file mode 100644
index 00f90c9..0000000
--- a/zap/include/zap/mth.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- Copyright 2022 Gabriel Jensen.
- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
- If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
-*/
-
-#if !defined(zap_priv_hdr_mth)
-#define zap_priv_hdr_mth
-
-#include <zap/bs.h>
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-#define zap_minval_c ((char )-0x80)
-#define zap_minval_i ((int )-0x80000000)
-#define zap_minval_l ((long )-0x8000000000000000)
-#define zap_minval_ll ((long long )-0x8000000000000000)
-#define zap_minval_s ((short )-0x8000)
-#define zap_minval_sc ((signed char )-0x80)
-
-#define zap_maxval_sc ((char )+0x7F)
-#define zap_maxval_c ((int )+0x7FFFFFFF)
-#define zap_maxval_i ((int )+0x7FFFFFFF)
-#define zap_maxval_l ((long )+0x7FFFFFFFFFFFFFFF)
-#define zap_maxval_ll ((long long )+0x7FFFFFFFFFFFFFFF)
-#define zap_maxval_s ((short )+0x7FFF)
-#define zap_maxval_sc ((signed char )+0x7F)
-#define zap_maxval_uc ((unsigned char )+0xFFu)
-#define zap_maxval_ui ((unsigned int )+0xFFFFFFFFu)
-#define zap_maxval_ul ((unsigned long )+0xFFFFFFFFFFFFFFFFu)
-#define zap_maxval_ull ((unsigned long long)+0xFFFFFFFFFFFFFFFFu)
-#define zap_maxval_us ((unsigned short )+0xFFFFu)
-
-typedef struct {char div;char mod;} zap_divmod_c;
-typedef struct {int div;int mod;} zap_divmod_i;
-typedef struct {long div;long mod;} zap_divmod_l;
-typedef struct {long long div;long long mod;} zap_divmod_ll;
-typedef struct {short div;short mod;} zap_divmod_s;
-typedef struct {signed char div;signed char mod;} zap_divmod_sc;
-typedef struct {unsigned char div;unsigned char mod;} zap_divmod_uc;
-typedef struct {unsigned int div;unsigned int mod;} zap_divmod_ui;
-typedef struct {unsigned long div;unsigned long mod;} zap_divmod_ul;
-typedef struct {unsigned long long div;unsigned long long mod;} zap_divmod_ull;
-typedef struct {unsigned short div;unsigned short mod;} zap_divmod_us;
-
-typedef struct {char num;char den;} zap_frac_c;
-typedef struct {int num;int den;} zap_frac_i;
-typedef struct {long num;long den;} zap_frac_l;
-typedef struct {long long num;long long den;} zap_frac_ll;
-typedef struct {short num;short den;} zap_frac_s;
-typedef struct {signed char num;signed char den;} zap_frac_sc;
-typedef struct {unsigned char num;unsigned char den;} zap_frac_uc;
-typedef struct {unsigned int num;unsigned int den;} zap_frac_ui;
-typedef struct {unsigned long num;unsigned long den;} zap_frac_ul;
-typedef struct {unsigned long long num;unsigned long long den;} zap_frac_ull;
-typedef struct {unsigned short num;unsigned short den;} zap_frac_us;
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_abs_c( char val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_abs_i( int val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_abs_l( long val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_abs_ll(long long val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_abs_s( short val);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_abs_sc(signed char val);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_c zap_div_c( char num,char den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_i zap_div_i( int num,int den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_l zap_div_l( long num,long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ll zap_div_ll( long long num,long long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_s zap_div_s( short num,short den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_sc zap_div_sc( signed char num,signed char den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_uc zap_div_uc( unsigned char num,unsigned char den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ui zap_div_ui( unsigned int num,unsigned int den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ul zap_div_ul( unsigned long num,unsigned long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_ull zap_div_ull(unsigned long long num,unsigned long long den);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) zap_divmod_us zap_div_us( unsigned short num,unsigned short den);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_exp_c( char bs,unsigned char exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_exp_i( int bs,unsigned int exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_exp_l( long bs,unsigned long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_exp_ll( long long bs,unsigned long long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_exp_s( short bs,unsigned short exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_exp_sc( signed char bs,unsigned char exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_exp_uc( unsigned char bs,unsigned char exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_exp_ui( unsigned int bs,unsigned int exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_exp_ul( unsigned long bs,unsigned long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_exp_ull(unsigned long long bs,unsigned long long exp);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_exp_us( unsigned short bs,unsigned short exp);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_log_uc( unsigned char bs,unsigned char pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_log_ui( unsigned int bs,unsigned int pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_log_ul( unsigned long bs,unsigned long pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_log_ull(unsigned long long bs,unsigned long long pow);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_log_us( unsigned short bs,unsigned short pow);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_mul_c( char lfac,char rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_mul_i( int lfac,int rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_mul_l( long lfac,long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_mul_ll( long long lfac,long long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_mul_s( short lfac,short rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_mul_sc( signed char lfac,signed char rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_mul_uc( unsigned char lfac,unsigned char rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_mul_ui( unsigned int lfac,unsigned int rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_mul_ul( unsigned long lfac,unsigned long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_mul_ull(unsigned long long lfac,unsigned long long rfac);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_mul_us( unsigned short lfac,unsigned short rfac);
-
-__attribute__ ((const,hot,nothrow,warn_unused_result)) char zap_nrt_c( char deg,char rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) int zap_nrt_i( int deg,int rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long zap_nrt_l( long deg,long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) long long zap_nrt_ll( long long deg,long long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) short zap_nrt_s( short deg,short rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) signed char zap_nrt_sc( signed char deg,signed char rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned char zap_nrt_uc( unsigned char deg,unsigned char rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned int zap_nrt_ui( unsigned int deg,unsigned int rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long zap_nrt_ul( unsigned long deg,unsigned long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned long long zap_nrt_ull(unsigned long long deg,unsigned long long rad);
-__attribute__ ((const,hot,nothrow,warn_unused_result)) unsigned short zap_nrt_us( unsigned short deg,unsigned short rad);
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif