diff options
Diffstat (limited to 'zap')
38 files changed, 623 insertions, 1351 deletions
diff --git a/zap/GNUmakefile b/zap/GNUmakefile index 940e993..7567c76 100644 --- a/zap/GNUmakefile +++ b/zap/GNUmakefile @@ -1,78 +1,79 @@ -# 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>. -ifneq "$(arch)" "amd64" -$(error invalid architecture) +ifeq "$(arch)" "" +arch := $(shell ../getarch.sh) +ifeq "$(arch)" "unknown" +$(error Unable to detect architecture!) +endif +$(info Detected architecture $(arch) !) endif -# TOOLS - -#CC = clang -#CC = gcc - -# TOOL FLAGS - -ASFLAGS := \ - -g \ - -march=native - -CFLAGS := \ - -Ofast \ - -Wall \ - -Wextra \ - -Wpedantic \ - -fPIC \ - -ffreestanding \ - -gdwarf-2 \ - -march=native \ - -std=c90 - -CPPFLAGS := \ - -Iinclude \ - -Iinclude-private \ - -# ARTEFACTS - -OBJS = \ - source/$(arch)/mem/memcnt.o \ - source/$(arch)/mem/memcp.o \ - source/$(arch)/mem/memeq.o \ - source/$(arch)/mem/memfill.o \ - source/$(arch)/mem/memfnd.o \ - source/$(arch)/mem/memfor.o \ - source/$(arch)/mem/memgen.o \ - source/$(arch)/mem/streq.o \ - source/$(arch)/mem/strfill.o \ - source/$(arch)/mem/strfnd.o \ - source/$(arch)/mem/strcp.o \ - source/$(arch)/mem/strlen.o \ - source/$(arch)/mem/utf20len.o \ - source/$(arch)/mem/utf8dec.o \ - source/$(arch)/mem/utf8declen.o \ - source/$(arch)/mem/utf8enc.o \ - source/$(arch)/mem/utf8enclen.o \ - source/$(arch)/mem/win1252dec.o \ - source/$(arch)/mem/win1252enc.o \ - source/$(arch)/mth/abs.o - -LIB = libzap.a - -# OPTIONS - -# TARGETS +OBJ_BS_TRAP := source/any/bs/trap.o +OBJ_MATH_ABS := source/any/math/abs.o +OBJ_MATH_DIV0 := source/any/math/div0.o +OBJ_MATH_DIVMOD := source/any/math/divmod.o +OBJ_MEM_CP := source/any/mem/cp.o +OBJ_MEM_EQ := source/any/mem/eq.o +OBJ_MEM_FILL := source/any/mem/fill.o +OBJ_MEM_SRCH := source/any/mem/srch.o +OBJ_MEM_UTF8DEC := source/any/mem/utf8dec.o +OBJ_MEM_UTF8DECLEN := source/any/mem/utf8declen.o +OBJ_MEM_UTF8ENC := source/any/mem/utf8enc.o +OBJ_MEM_UTF8ENCLEN := source/any/mem/utf8enclen.o +OBJ_MEM_WIN1252DEC := source/any/mem/win1252dec.o +OBJ_MEM_WIN1252ENC := source/any/mem/win1252enc.o + +OBJS := \ + $(OBJ_BS_TRAP) \ + $(OBJ_MATH_ABS) \ + $(OBJ_MATH_DIV0) \ + $(OBJ_MATH_DIVMOD) \ + $(OBJ_MEM_CP) \ + $(OBJ_MEM_EQ) \ + $(OBJ_MEM_FILL) \ + $(OBJ_MEM_SRCH) \ + $(OBJ_MEM_UTF8DEC) \ + $(OBJ_MEM_UTF8DECLEN) \ + $(OBJ_MEM_UTF8ENC) \ + $(OBJ_MEM_UTF8ENCLEN) \ + $(OBJ_MEM_WIN1252DEC) \ + $(OBJ_MEM_WIN1252ENC) + +LIB := libzap.a + +HDRS := \ + include/zap/bs.h \ + include/zap/math.h \ + include/zap/mem.h + +CFLAGS := \ + -Iinclude \ + -Oz \ + -Wall \ + -Wextra \ + -Wpadded \ + -Wpedantic \ + -ffreestanding \ + -fno-strict-aliasing \ + -fshort-enums \ + -nostdlib \ + -pipe \ + -std=c99 + +ifeq "$(signaldiv0)" "true" +$(info signaldiv0 has been enabled! Remember to link with csys!) +CFLAGS := \ + $(CFLAGS) \ + -Dzap_priv_signaldiv0 +endif -.PHONY: clean install purge +.PHONY: clean purge $(LIB): $(OBJS) $(AR) r $(@) $(^) -install: $(LIB) - mkdir -pm755 "$(HDRDIR)/zap" - mkdir -pm755 "$(LIBDIR)" - install -m644 "include/zap/"*".h" "$(HDRDIR)/zap" - install -m755 "$(LIB)" "$(LIBDIR)" - clean: $(RM) $(OBJS) diff --git a/zap/include-private/zap/priv.h b/zap/include-private/zap/priv.h deleted file mode 100644 index 0aeafaa..0000000 --- a/zap/include-private/zap/priv.h +++ /dev/null @@ -1,12 +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_priv) -#define zap_priv_hdr_priv - -#include <zap/bs.h> - -#endif 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 diff --git a/zap/source/amd64/mem/memcnt.S b/zap/source/amd64/mem/memcnt.S deleted file mode 100644 index 5323301..0000000 --- a/zap/source/amd64/mem/memcnt.S +++ /dev/null @@ -1,75 +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/. - -.globl zap_memcnt - -zap_memcnt: -# Address of the current element: -#define addr %rbx -# Address of the element after the last input element: -#define afterbuf %r12 -# Size of each input element: -#define sz %r13 -# Address of the function: -#define fn %r14 -# Count: -#define cnt %r15 - - # Push the callee-saved registers: - pushq addr - pushq afterbuf - pushq sz - pushq fn - pushq cnt - - # Move registers into place: - movq %rdi,addr - movq %rsi,sz - movq %rdx,afterbuf - movq %rcx,fn - - # Get the one-past-the-end address: - imulq sz,afterbuf # afterbuf *= sz - addq addr,afterbuf # afterbuf += addr - - movq $0x0,cnt # cnt = 0x0 - - # Iterate through the array: -.loop: - - # Check if we have reached the one-past-the-end address: - cmpq addr,afterbuf # if (addr == afterbuf) - je .done # goto done - - # Call the provided function: - movq addr,%rdi - call *fn # fn(addr) - - # Check the return value of the function: - testb %al,%al # if (fn(addr) == zap_false) - jz .skip # goto skip - - incq cnt # ++cnt - - # Skip the incrementation: -.skip: - - # Continue to the next element: - addq sz,addr # addr += sz - jmp .loop # goto loop - - # Finish: -.done: - - # Move count into return register: - movq cnt,%rax - - # Restore the callee-saved registers: - popq cnt - popq fn - popq sz - popq afterbuf - popq addr - - ret # return cnt diff --git a/zap/source/amd64/mem/memcp.S b/zap/source/amd64/mem/memcp.S deleted file mode 100644 index ac310ae..0000000 --- a/zap/source/amd64/mem/memcp.S +++ /dev/null @@ -1,99 +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/. - -.globl zap_memcp - -zap_memcp: -# Address of the current input element: -#define iaddr %rdi -# Number of remaining bytes: -#define rem %rsi -# Address of the current output element: -#define oaddr %rdx -# Current element: -#define val1 %cl -#define val8 %rcx -#define val01 %xmm0 -#define val02 %ymm0 - -#if defined(__AVX__) - # AVX support 256-bit moves. - - # Copy 32 bytes: -.big02cp: - - # Check if there are at least 32 bytes remaining: - cmpq $0x20,rem # if (rem < 20) - jl .big01cp # goto big01cp // If not, skip to the 10 byte copying. - - # Copy: - vmovups (iaddr),val02 # val02 = *iaddr - vmovups val02,(oaddr) # *oaddr = val02 - - # Continue: - addq $0x20,iaddr # iaddr += 0x20 - addq $0x20,oaddr # oaddr += 0x20 - subq $0x20,rem # rem -= 0x20 - jmp .big02cp # goto big02cp - -#endif - - # AMD64 requires SSE(2), so we don't have to test it. - - # Copy 16 bytes: -.big01cp: - - # Check if there are at least 16 bytes remaining: - cmpq $0x10,rem # if (rem < 10) - jl .wrdcp # goto wrdcp - - # Copy: - movdqu (iaddr),val01 # val01 = *iaddr - movdqu val01,(oaddr) # *oaddr = val01 - - # Continue: - addq $0x10,iaddr # iaddr += 0x10 - addq $0x10,oaddr # oaddr += 0x10 - subq $0x10,rem # rem -= 0x10 - jmp .big01cp # goto big01cp - - # Copy one word (8 bytes): -.wrdcp: - - # Check if there are at least 8 bytes remaining: - cmpq $0x8,rem # if (rem < 8) - jl .bytecp # goto bytecp - - # Copy: - movq (iaddr),val8 # val8 = *iaddr - movq val8,(oaddr) # *oaddr = val8 - - # Continue: - addq $0x8,iaddr # iaddr += 0x8 - addq $0x8,oaddr # oaddr += 0x8 - subq $0x8,rem # rem -= 0x8 - jmp .wrdcp # goto wrdcp - - # Copy one byte: -.bytecp: - - # Check if we have any bytes remaining: - testq rem,rem # if (rem == 0x0) - jz .done # goto done - - # Copy: - movb (iaddr),val1 # val1 = *iaddr - movb val1,(oaddr) # *oaddr = val1 - - # Continue: - incq iaddr # ++iaddr - incq oaddr # ++oaddr - decq rem # --rem - jmp .bytecp # goto bytecp - - # Return: -.done: - - ret # return -
\ No newline at end of file diff --git a/zap/source/amd64/mem/memeq.S b/zap/source/amd64/mem/memeq.S deleted file mode 100644 index b30a884..0000000 --- a/zap/source/amd64/mem/memeq.S +++ /dev/null @@ -1,74 +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/. - -.globl zap_memeq - -zap_memeq: -# Left pointer: -#define laddr %rdi -# Number of remaining elements: -#define rem %rsi -# Right pointer: -#define raddr %rdx -# Current left element: -#define lval8 %rax -#define lval1 %al -# Current right element: -#define rval8 %rcx -#define rval1 %cl - - # Compare words: -.wrdcmp: - - # Check if there's at least one word left: - cmpq $0x8,rem # if (rem == 8) - jl .bytecmp # goto bytecmp - - # Copy the values into registers: - movq (laddr),lval8 # lval8 = *laddr - movq (raddr),rval8 # rval8 = *raddr - - # Check if the words are equal: - cmpq lval8,rval8 # if (lval8 != rval8) - jne .neq # goto neq - - # Mark eight more bytes as equal: - addq $0x8,laddr # laddr += 0x8 - addq $0x8,raddr # raddr += 0x8 - subq $0x8,rem # rem -= 0x8 - - # Continue to the next word: - jmp .wrdcmp # goto wrdcmp - - # Compare bytes: -.bytecmp: - - # Check if there are any bytes left: - testq rem,rem # if (rem == 0x0) - jz .eq # goto eq // If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal. - - # Copy the values into registers: - movb (laddr),lval1 # lval1 = *laddr - movb (raddr),rval1 # rval1 = *raddr - - cmpb lval1,rval1 # if (lval1 != rval1) - jne .neq # goto neq - - # Mark another byte as equal: - incq laddr # ++laddr - incq raddr # ++raddr - decq rem # --rem - - # Continue to the next byte: - jmp .bytecmp # goto bytecmp - - # The memory sequences have compared equal: -.eq: - movb $0xFF,%al - ret # return FF - - # The memory sequences have compared NOT equal: -.neq: - movb $0x0,%al - ret # return 0 diff --git a/zap/source/amd64/mem/memfill.S b/zap/source/amd64/mem/memfill.S deleted file mode 100644 index c38eec8..0000000 --- a/zap/source/amd64/mem/memfill.S +++ /dev/null @@ -1,34 +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/. - -.globl zap_memfill - -zap_memfill: -# Address of the current element: -#define addr %rdi -# Address of the element after the last element: -#define afterbuf %rsi -# Byte value: -#define val %dl - - addq addr,afterbuf # afterbuf += addr // afterbuf contains the number of bytes - - # Iterate over buffer: -.loop: - - # Check if we have reached the final element: - cmpq addr,afterbuf # if (addr == afterbuf) - je .done # goto done - - # Set the value of the current element: - movb val,(addr) # *addr = val - - # Continue to next element: - incq addr # ++addr - jmp .loop # goto loop - - # Finish: -.done: - - ret # return diff --git a/zap/source/amd64/mem/memfnd.S b/zap/source/amd64/mem/memfnd.S deleted file mode 100644 index e1f8c30..0000000 --- a/zap/source/amd64/mem/memfnd.S +++ /dev/null @@ -1,50 +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/. - -.globl zap_memfnd - -zap_memfnd: -# Address of the current element: -#define addr %rax -# Address of the first element: -#define start %rdi -# Address of the element after the last element: -#define afterbuf %rsi -# Byte value: -#define cmp %dl -# Current byte: -#define val %cl - - movq start,addr # addr = start - - addq start,afterbuf # afterbuf += start - - # Iterate over the array: -.loop: - - # Check if we have reached the end of the array: - cmpq addr,afterbuf # if (addr == afterbuf) - je .nfnd # goto nfnd - - # Check if we have found the byte value: - movb (addr),val # val = *addr - cmpb val,cmp # if (val == cmp) - je .fnd # goto fnd - - # Continue to the next byte: - incq addr # ++addr - jmp .loop # goto loop - - # Found: -.fnd: - - # Get the offset of the byte: - subq start,addr # addr -= start - ret # return addr - - # Not found: -.nfnd: - - movq $0xFFFFFFFFFFFFFFFF,addr # addr = 0xFFFFFFFFFFFFFFFF - ret # return addr diff --git a/zap/source/amd64/mem/memfor.S b/zap/source/amd64/mem/memfor.S deleted file mode 100644 index e9cfe6b..0000000 --- a/zap/source/amd64/mem/memfor.S +++ /dev/null @@ -1,59 +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/. - -.globl zap_memfor - -zap_memfor: -# Address of the current element: -#define addr %rbx -# Address of the element after the last input element: -#define afterbuf %r12 -# Size of each input element: -#define sz %r13 -# Address of the function: -#define fn %r14 - - # We're gonna use callee-saved registers for storing values so they don't get overwritten with each function call. - - # Push the callee-saved registers: - pushq addr - pushq afterbuf - pushq sz - pushq fn - - # Move registers into place: - movq %rdi,addr - movq %rsi,sz - movq %rdx,afterbuf - movq %rcx,fn - - # Get the one-past-the-end address: - imulq sz,afterbuf # afterbuf *= sz // Calculate the array size in bytes (sz * num). We're using signed multiply because the equivalent using the unsigned instruction would use more instructions. - addq addr,afterbuf # afterbuf += addr - - # Iterate through the array: -.loop: - - # Check if we have reached the one-past-the-end address: - cmpq addr,afterbuf # if (addr == afterbuf) - je .done # goto done - - # Call the provided function: - movq addr,%rdi # // Provide the current address to the function. - call *fn # fn(addr) // We don't need to save any registers for this as we only use callee-saved registers. - - # Continue to the next element: - addq sz,addr # addr += sz - jmp .loop # goto loop - - # Finish: -.done: - - # Restore the callee-saved registers: - popq fn - popq sz - popq afterbuf - popq addr - - ret # return diff --git a/zap/source/amd64/mem/memgen.c b/zap/source/amd64/mem/memgen.c deleted file mode 100644 index 5410bb3..0000000 --- a/zap/source/amd64/mem/memgen.c +++ /dev/null @@ -1,14 +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/. -*/ - -#include <zap/priv.h> - -void zap_memgen(void * const _ptr,zap_sz const _sz,zap_sz const _num,void (* const _fn)(zap_sz,void *)) { - unsigned char * ptr = _ptr; - unsigned char * const afterbuf = ptr + _sz * _num; - for (;ptr != afterbuf;ptr += _sz) {_fn((ptr - (unsigned char *)_ptr) / _sz,ptr);} -} - diff --git a/zap/source/amd64/mem/strcp.S b/zap/source/amd64/mem/strcp.S deleted file mode 100644 index 820ed96..0000000 --- a/zap/source/amd64/mem/strcp.S +++ /dev/null @@ -1,43 +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/. - -.globl zap_strcp - -zap_strcp: -# Address of the current input character: -#define iaddr %rax -# Address of the first input character: -#define start %rdi -# Address of the current output character: -#define oaddr %rsi -# Current character: -#define chr %dl - - movq start,iaddr - - # Iterate over the strings: -.loop: - - # Copy character: - movb (iaddr),chr # chr = *iaddr - movb chr,(oaddr) # *oaddr = chr - - # Check if we have reached the null-terminator: - testb chr,chr # if (chr == 0x0) - jz .done # goto done - - # Continue to the next character: - - incq iaddr # ++iaddr - incq oaddr # ++oaddr - jmp .loop # goto loop - - # Finish: -.done: - - # Get the length of the (input) string: - subq start,iaddr # iaddr -= start - decq iaddr # --iaddr // We do not count the null-terminator in the string length. - - ret # return iaddr diff --git a/zap/source/amd64/mem/streq.S b/zap/source/amd64/mem/streq.S deleted file mode 100644 index e054531..0000000 --- a/zap/source/amd64/mem/streq.S +++ /dev/null @@ -1,47 +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/. - -.globl zap_streq - -zap_streq: -# Address of the current left character: -#define laddr %rdi -# Address of the current right character: -#define raddr %rsi -# Current left character: -#define lchr %al -# Current right character: -#define rchr %dl - - # Iterate over the strings: -.loop: - - # Copy the characters into registers: - movb (laddr),lchr # lchr = *laddr - movb (raddr),rchr # rchr = *raddr - - # Check if the characters are equal: - cmpb lchr,rchr # if (lchr != rchr) - jne .neq # goto neq // If not, the strings also aren't equal. - - # Check if we have reached the null-terminator: - testb lchr,lchr # if (lchr == 0x0) - jz .eq # goto eq // If so, all previous characters have compared equal, and the strings are equal. - - # Continue to the next characters: - incq laddr # ++laddr - incq raddr # ++raddr - jmp .loop # goto loop - - # The strings have compared equal: -.eq: - - movb $0xFF,%al - ret # return FF - - # The strings have compared unequal: -.neq: - - movb $0x0,%al - ret # return 0 diff --git a/zap/source/amd64/mem/strfill.S b/zap/source/amd64/mem/strfill.S deleted file mode 100644 index f570a35..0000000 --- a/zap/source/amd64/mem/strfill.S +++ /dev/null @@ -1,37 +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/. - -.globl zap_strfill - -zap_strfill: -# Address of the current character: -#define addr %rax -# Address of the first character of the string: -#define start %rdi -# Fill character: -#define chr %sil - - movq start,addr - - # Iterate over string: -.loop: - - # Check if we have reached the null-terminator: - cmpb $0x0,(addr) # if (*addr == 0x0) - je .done # goto done - - # Set the value of the current element: - movb chr,(addr) # *addr = chr - - # Continue to next character: - incq addr # ++addr - jmp .loop # goto loop - - # Finish: -.done: - - # Get the length of the string: - subq start,addr # addr -= start - - ret # return addr diff --git a/zap/source/amd64/mem/strfnd.S b/zap/source/amd64/mem/strfnd.S deleted file mode 100644 index f2f94fa..0000000 --- a/zap/source/amd64/mem/strfnd.S +++ /dev/null @@ -1,48 +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/. - -.globl zap_strfnd - -zap_strfnd: -# Address of the first character: -#define start %rdi -# Character to be found: -#define cmp %sil -# Address of the current character: -#define addr %rax -# Current character: -#define chr %dl - - movq start,addr # addr = start - - # Iterate over the string: -.loop: - - # Copy the character into a register: - movb (addr),chr # chr = *addr - - # Check if we have found the character: - cmpb chr,cmp # if (chr == cmp) - je .fnd # goto fnd - - # Check if we have found the null-terminator: - testb chr,chr # if (chr == 0x0) - jz .nfnd # goto nfnd - - # Continue to the next character: - incq addr # ++addr - jmp .loop # goto loop - - # Found: -.fnd: - - # Get the offset of the character: - subq start,addr # addr -= start - ret # return addr - - # Not found: -.nfnd: - - movq $0xFFFFFFFFFFFFFFFF,addr # addr = 0xFFFFFFFFFFFFFFFF - ret # return addr diff --git a/zap/source/amd64/mem/strlen.S b/zap/source/amd64/mem/strlen.S deleted file mode 100644 index a3f68b1..0000000 --- a/zap/source/amd64/mem/strlen.S +++ /dev/null @@ -1,37 +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/. - -.globl zap_strlen - -zap_strlen: -# Address of the current character: -#define addr %rax -# Address of the first character: -#define start %rdi -# Current character: -#define chr %dl - - movq start,addr - - # Iterate over the string: -.loop: - - # Move the character into a register: - movb (addr),chr # chr = *addr - - # Check if we have reached the null-terminator: - testb chr,chr # if (chr == 0x0) - jz .done # goto done - - # Continue to the next character: - incq addr # ++addr - jmp .loop # goto loop - - # Done: -.done: - - # Get the length: - subq start,addr # addr -= start - - ret # return addr diff --git a/zap/source/amd64/mem/utf20len.S b/zap/source/amd64/mem/utf20len.S deleted file mode 100644 index 03f8254..0000000 --- a/zap/source/amd64/mem/utf20len.S +++ /dev/null @@ -1,38 +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/. - -.globl zap_utf20len - -zap_utf20len: -# Address of the current character: -#define addr %rax -# Address of the first character: -#define start %rdi -# Current character: -#define chr %edx - - movq start,addr - - # Iterate over the string: -.loop: - - # Move the character into a register: - movl (addr),chr # chr = *addr - - # Check if we have reached the null-terminator: - testl chr,chr # if (chr == 0x0) - jz .done # goto done - - # Continue to the next character: - addq $0x4,addr # addr += 0x4 - jmp .loop # goto loop - - # Done: -.done: - - # Get the length: - subq start,addr # addr -= start - shrq $0x2,addr # addr /= 0x4 // Divide by four to get the number of doublewords rather than bytes. - - ret # return addr diff --git a/zap/source/amd64/mem/utf8dec.c b/zap/source/amd64/mem/utf8dec.c deleted file mode 100644 index 62f3f61..0000000 --- a/zap/source/amd64/mem/utf8dec.c +++ /dev/null @@ -1,51 +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/. -*/ - -#include <zap/priv.h> - -#include <zap/mem.h> - -void zap_utf8dec(zap_chr8 const * const _in,zap_chr20 * const _out) { - zap_chr8 const * in = _in; - zap_chr20 * out = _out; - for (;;++out) { - zap_chr8 const oct = *in; - if (oct >= 0xF0u) { /* Four octets. */ - zap_chr20 chr = ((zap_chr20)oct ^ 0xF0u) << 0x12u; - ++in; - chr += ((zap_chr20)*in ^ 0x80u) << 0xCu; - ++in; - chr += ((zap_chr20)*in ^ 0x80u) << 0x6u; - ++in; - chr += (zap_chr20)*in ^ 0x80u; - ++in; - *out = chr; - continue; - } - if (oct >= 0xE0u) { /* Three octets. */ - zap_chr20 chr = ((zap_chr20)oct ^ 0xE0u) << 0xCu; - ++in; - chr += ((zap_chr20)*in ^ 0x80u) << 0x6u; - ++in; - chr += (zap_chr20)*in ^ 0x80u; - ++in; - *out = chr; - continue; - } - if (oct >= 0xC0u) { /* Two octets. */ - zap_chr20 chr = ((zap_chr20)oct ^ 0xC0u) << 0x6u; - ++in; - chr += (zap_chr20)*in ^ 0x80u; - ++in; - *out = chr; - continue; - } - /* One octet. */ - *out = oct; - ++in; - if (oct == 0x0u) {break;} - } -} diff --git a/zap/source/amd64/mem/utf8declen.c b/zap/source/amd64/mem/utf8declen.c deleted file mode 100644 index 85062b9..0000000 --- a/zap/source/amd64/mem/utf8declen.c +++ /dev/null @@ -1,35 +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/. -*/ - -#include <zap/priv.h> - -#include <zap/mem.h> - -#include <stddef.h> - -zap_sz zap_utf8declen(zap_chr8 const * const _in) { - zap_sz len = 0x0u; - zap_chr8 const * in; - for (in = _in;;++len) { - zap_chr8 const oct = *in; - if (oct == 0x0u) {break;} - if (oct >= 0xF0u) { - in += 0x4u; - continue; - } - if (oct >= 0xE0u) { - in += 0x3u; - continue; - } - if (oct >= 0xC0u) { - in += 0x2u; - continue; - } - ++in; - continue; - } - return len; -} diff --git a/zap/source/amd64/mem/utf8enc.S b/zap/source/amd64/mem/utf8enc.S deleted file mode 100644 index 357bdaa..0000000 --- a/zap/source/amd64/mem/utf8enc.S +++ /dev/null @@ -1,139 +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/. - -.globl zap_utf8enc - -zap_utf8enc: - # rdi: Current input codepoint. - # rsi: Current output octet. - # rax: Current codepoint. - # rdx: Temporary. - - # Iterate over the input: -.loop: - - movl (%rdi),%eax - - cmpl $0xFFFF,%eax - jg .oct4 - - cmpl $0x7FF,%eax - jg .oct3 - - cmpl $0x7F,%eax - jg .oct2 # Otherwise, only one octet is needed. - - # One octet: -.oct1: - - # Octet #0: - movb %al,(%rsi) # No conversion needed: - - incq %rsi - - # Test if we have reached the null-terminator: - testb %al,%al - jz .done - - jmp .cnt - - # Two octets: -.oct2: - - /* Octet #0: */ - movl %eax,%edx - shrl $0x6,%edx - orb $0xC0,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #1: - movl %eax,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - jmp .cnt - - # Three octets: -.oct3: - - # Octet #0: - movl %eax,%edx - shrl $0xC,%edx - orb $0xE0,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #1: - movl %eax,%edx - shrl $0x6,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #2: - movl %eax,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - jmp .cnt - - # Four octets: -.oct4: - - # Octet #0: - movl %eax,%edx - shrl $0x12,%edx - orb $0xF0,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #1: - movl %eax,%edx - shrl $0xC,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #2: - movl %eax,%edx - shrl $0x6,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Octet #3: - movl %eax,%edx - andb $0x3F,%dl - orb $0x80,%dl - movb %dl,(%rsi) - - incq %rsi - - # Continue to the next codepoint: -.cnt: - - addq $0x4,%rdi - jmp .loop - - # Done: -.done: - - ret -
\ No newline at end of file diff --git a/zap/source/amd64/mem/utf8enclen.S b/zap/source/amd64/mem/utf8enclen.S deleted file mode 100644 index 2e3b09f..0000000 --- a/zap/source/amd64/mem/utf8enclen.S +++ /dev/null @@ -1,67 +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/. - -.globl zap_utf8enclen - -zap_utf8enclen: - # rdi: Address of the current character. - # rax: Length of the string. - # rsi: Current character. - - movq $0x0,%rax - - # Iterate over the input: -.loop: - - movl (%rdi),%esi - - # Test if we have reached the null-terminator: - testl %esi,%esi - jz .done - - cmpl $0xFFFF,%esi - jg .oct4 - - cmpl $0x7FF,%esi - jg .oct3 - - cmpl $0x7F,%esi - jg .oct2 - - # One octet: -.oct1: - - incq %rax - - jmp .cnt - - # Two octets: -.oct2: - - addq $0x2,%rax - - jmp .cnt - - # Three octets: -.oct3: - - addq $0x3,%rax - - jmp .cnt - - # Four octets: -.oct4: - - addq $0x4,%rax - - # Continue to the next codepoint: -.cnt: - - addq $0x4,%rdi - jmp .loop - - # Done: -.done: - - ret diff --git a/zap/source/amd64/mth/abs.S b/zap/source/amd64/mth/abs.S deleted file mode 100644 index 4c9ed01..0000000 --- a/zap/source/amd64/mth/abs.S +++ /dev/null @@ -1,70 +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/. - -.globl zap_abs_c -.globl zap_abs_i -.globl zap_abs_l -.globl zap_abs_ll -.globl zap_abs_s -.globl zap_abs_sc - -zap_abs_i: -# The input value: -#define val %edi -# Inverted value of the input: -#define inv %eax - movl val,inv # inv = val - negl inv # inv = -inv // Invert the copy of the input value. This also tests the sign of the value. - # . if (inv > 0x0) - cmovsl val,inv # val = inv // If it was positive, just return the unmodified input. - ret # return val // Otherwise, return the inverted value. - -#undef val -#undef inv - -zap_abs_l: -zap_abs_ll: -# The input value: -#define val %rdi -# Inverted value of the input: -#define inv %rax - movq val,inv # inv = val - negq inv # inv = -inv - # . if (inv > 0x0) - cmovsq val,inv # val = inv - ret # return val - -#undef val -#undef inv - -zap_abs_s: -# The input value: -#define val %di -# Inverted value of the input: -#define inv %ax - movw val,inv # inv = val - negw inv # inv = -inv - # . if (inv > 0x0) - cmovsw val,inv # val = inv - ret # return val - -#undef val -#undef inv - -zap_abs_c: -zap_abs_sc: -# The input value: -#define val %dil -#define val2 %di -# Inverted value of the input: -#define inv %al -#define inv2 %ax - movb val,inv # inv = val - negb inv # inv = -inv - # . if (inv > 0x0) - cmovsw val2,inv2 # val = inv - ret # return val - -#undef val -#undef inv diff --git a/zap/source/any/bs/trap.c b/zap/source/any/bs/trap.c new file mode 100644 index 0000000..9428d44 --- /dev/null +++ b/zap/source/any/bs/trap.c @@ -0,0 +1,16 @@ +/* + 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>. +*/ + +#include <zap/bs.h> + +void zap_priv_trap(void) { +#if defined(__has_builtin) +#if __has_builtin(__builtin_trap) + __builtin_trap(); +#endif +#endif + for (;;) {} +} diff --git a/zap/source/any/math/abs.c b/zap/source/any/math/abs.c new file mode 100644 index 0000000..d12b6a6 --- /dev/null +++ b/zap/source/any/math/abs.c @@ -0,0 +1,20 @@ +/* + 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>. +*/ + +#include <zap/math.h> + +#define zap_priv_abs(_wdth) \ +zap_i##_wdth zap_abs##_wdth(zap_i##_wdth##s const _val) { \ + if (_val > 0x0) { \ + return (zap_i##_wdth)_val; \ + } \ + return (zap_i##_wdth)(0x0 - _val); \ +} + +zap_priv_abs(8) +zap_priv_abs(01) +zap_priv_abs(02) +zap_priv_abs(04) diff --git a/zap/source/any/math/div0.c b/zap/source/any/math/div0.c new file mode 100644 index 0000000..87fcfa0 --- /dev/null +++ b/zap/source/any/math/div0.c @@ -0,0 +1,22 @@ +/* + 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>. +*/ + +#include <zap/math.h> + +#include <csys.h> + +#if csys_os_linux +#include <asm/unistd.h> +#endif + +zap_i04 zap_priv_div0(void) { +#if defined(zap_priv_signaldiv0) +#if csys_os_linux + csys_syscall(__NR_kill,csys_syscall(__NR_getpid),0x8u); +#endif +#endif + return (zap_i04)-0x1; +} diff --git a/zap/source/any/math/divmod.c b/zap/source/any/math/divmod.c new file mode 100644 index 0000000..4214651 --- /dev/null +++ b/zap/source/any/math/divmod.c @@ -0,0 +1,24 @@ +/* + 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>. +*/ + +#include <zap/math.h> + +#define zap_priv_divmod(_wdth) \ +zap_quotrem##_wdth zap_divmod##_wdth(zap_i##_wdth const _num,zap_i##_wdth const _den) { \ +zap_quotrem##_wdth quotrem; \ + if (__builtin_expect(_den == 0x0,0x0)) { \ + quotrem.quot = zap_priv_div0(); \ + quotrem.rem = quotrem.quot; \ + return quotrem; \ + } \ + for (quotrem = (zap_quotrem##_wdth){.quot = 0x0u,.rem = _num};quotrem.rem >= _den;++quotrem.quot,quotrem.rem -= _den) {} \ + return quotrem; \ +} + +zap_priv_divmod(8) +zap_priv_divmod(01) +zap_priv_divmod(02) +zap_priv_divmod(04) diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c new file mode 100644 index 0000000..9bfd895 --- /dev/null +++ b/zap/source/any/mem/cp.c @@ -0,0 +1,16 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +void zap_cp(void * const zap_priv_restr _dest,void const * const zap_priv_restr _src,zap_sz const _num) { + zap_byte * dest; + zap_byte const * src; + zap_byte * const stop = (zap_byte *)_dest + _num; + for (dest = _dest,src = _src;dest != stop;++dest,++src) { + *dest = *src; + } +} diff --git a/zap/source/any/mem/eq.c b/zap/source/any/mem/eq.c new file mode 100644 index 0000000..0229fb6 --- /dev/null +++ b/zap/source/any/mem/eq.c @@ -0,0 +1,19 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +zap_bool zap_eq(void const * const _lbuf,void const * const _rbuf,zap_sz const _num) { + zap_byte const * lbuf; + zap_byte const * rbuf; + zap_byte * const stop = (zap_byte *)_lbuf + _num; + for (lbuf = _lbuf,rbuf = _rbuf;lbuf != stop;++lbuf,++rbuf) { + if (*lbuf != *rbuf) { + return zap_false; + } + } + return zap_true; +} diff --git a/zap/source/any/mem/fill.c b/zap/source/any/mem/fill.c new file mode 100644 index 0000000..11f5b59 --- /dev/null +++ b/zap/source/any/mem/fill.c @@ -0,0 +1,15 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +void zap_fill(void * const _dest,zap_byte const _val,zap_sz const _num) { + zap_byte * dest; + zap_byte * const stop = (zap_byte *)_dest + _num; + for (dest = _dest;dest != stop;++dest) { + *dest = _val; + } +} diff --git a/zap/source/any/mem/srch.c b/zap/source/any/mem/srch.c new file mode 100644 index 0000000..494e2d8 --- /dev/null +++ b/zap/source/any/mem/srch.c @@ -0,0 +1,18 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +void * zap_srch(void const * const _buf,zap_byte const _val,zap_sz const _num) { + zap_byte const * buf; + zap_byte * const stop = (zap_byte *)_buf + _num; + for (buf = _buf;buf != stop;++buf) { + if (*buf == _val) { + return (void *)buf; + } + } + return zap_nullptr; +} diff --git a/zap/source/any/mem/utf8dec.c b/zap/source/any/mem/utf8dec.c new file mode 100644 index 0000000..f9a0eac --- /dev/null +++ b/zap/source/any/mem/utf8dec.c @@ -0,0 +1,51 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +void zap_utf8dec(zap_chr02 * const _dest,zap_chr8 const * const _src) { + zap_chr02 * dest; + zap_chr8 const * src; + for (dest = _dest,src = _src;;++dest) { + zap_chr8 const oct = *src; + if (oct == 0x0u) { + break; + } + if (oct >= 0xF0u) { /* Four octets. */ + zap_chr02 chr = ((zap_chr02)oct ^ 0xF0u) << 0x12u; + ++src; + chr += ((zap_chr02)*src ^ 0x80u) << 0xCu; + ++src; + chr += ((zap_chr02)*src ^ 0x80u) << 0x6u; + ++src; + chr += (zap_chr02)*src ^ 0x80u; + ++src; + *dest = chr; + continue; + } + if (oct >= 0xE0u) { /* Three octets. */ + zap_chr02 chr = ((zap_chr02)oct ^ 0xE0u) << 0xCu; + ++src; + chr += ((zap_chr02)*src ^ 0x80u) << 0x6u; + ++src; + chr += (zap_chr02)*src ^ 0x80u; + ++src; + *dest = chr; + continue; + } + if (oct >= 0xC0u) { /* Two octets. */ + zap_chr02 chr = ((zap_chr02)oct ^ 0xC0u) << 0x6u; + ++src; + chr += (zap_chr02)*src ^ 0x80u; + ++src; + *dest = chr; + continue; + } + /* One octet. */ + *dest = oct; + ++src; + } +} diff --git a/zap/source/any/mem/utf8declen.c b/zap/source/any/mem/utf8declen.c new file mode 100644 index 0000000..81fd274 --- /dev/null +++ b/zap/source/any/mem/utf8declen.c @@ -0,0 +1,32 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +zap_sz zap_utf8declen(zap_chr8 const * const _buf) { + zap_sz len = 0x0u; + zap_chr8 const * pos; + for (pos = _buf;;++len) { + zap_chr8 const oct = *pos; + if (oct == 0x0u) { + break; + } + if (oct >= 0xF0u) { + pos += 0x4u; + continue; + } + if (oct >= 0xE0u) { + pos += 0x3u; + continue; + } + if (oct >= 0xC0u) { + pos += 0x2u; + continue; + } + ++pos; + } + return len; +} diff --git a/zap/source/any/mem/utf8enc.c b/zap/source/any/mem/utf8enc.c new file mode 100644 index 0000000..04febb2 --- /dev/null +++ b/zap/source/any/mem/utf8enc.c @@ -0,0 +1,48 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +void zap_utf8enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { + zap_chr8 * dest; + zap_chr02 const * src; + for (dest = _dest,src = _src;;++src) { + zap_chr02 const chr = *src; + if (chr > 0xFFFFu) { /* Four octets. */ + *dest = 0xF0u + (chr >> 0x12u); + ++dest; + *dest = 0x80u + (chr >> 0xCu & 0x3Fu); + ++dest; + *dest = 0x80u + (chr >> 0x6u & 0x3Fu); + ++dest; + *dest = 0x80u + (chr & 0x3Fu); + ++dest; + continue; + } + if (chr >= 0x7FFu) { /* Three octets. */ + *dest = 0xE0u + (zap_chr8)(chr >> 0xCu); + ++dest; + *dest = 0x80u + (zap_chr8)(chr >> 0x6u & 0x3Fu); + ++dest; + *dest = 0x80u + (zap_chr8)(chr & 0x3Fu); + ++dest; + continue; + } + if (chr >= 0x7Fu) { /* Two octets. */ + *dest = 0xC0u + (zap_chr8)(chr >> 0x6u); + ++dest; + *dest = 0x80u + (zap_chr8)(chr & 0x3Fu); + ++dest; + continue; + } + /* One octet. */ + *dest = chr; + ++dest; + if (chr == 0x0u) { + break; + } + } +} diff --git a/zap/source/any/mem/utf8enclen.c b/zap/source/any/mem/utf8enclen.c new file mode 100644 index 0000000..67d938d --- /dev/null +++ b/zap/source/any/mem/utf8enclen.c @@ -0,0 +1,32 @@ +/* + 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>. +*/ + +#include <zap/mem.h> + +zap_sz zap_utf8enclen(zap_chr02 const * const _buf) { + zap_sz len = 0x0u; + zap_chr02 const * pos; + for (pos = _buf;;++pos) { + zap_chr02 const chr = *pos; + if (chr == 0x0u) { + break; + } + if (chr >= 0x10000u) { + len += 0x4u; + continue; + } + if (chr >= 0x800u) { + len += 0x3u; + continue; + } + if (chr >= 0x80u) { + len += 0x2u; + continue; + } + ++len; + } + return len; +} diff --git a/zap/source/amd64/mem/win1252dec.c b/zap/source/any/mem/win1252dec.c index 2a5e897..b808c9b 100644 --- a/zap/source/amd64/mem/win1252dec.c +++ b/zap/source/any/mem/win1252dec.c @@ -1,111 +1,111 @@ /* - 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>. */ -#include <zap/priv.h> - #include <zap/mem.h> -void zap_win1252dec(zap_chr8 const * const _in,zap_chr20 * const _out) { - zap_chr8 const * in = _in; - zap_chr20 * out = _out; - for (;;++in,++out) { - zap_chr8 const chr = *in; +void zap_win1252dec(zap_chr02 * const _dest,zap_chr8 const * const _src) { + zap_chr02 * dest; + zap_chr8 const * src; + for (dest = _dest,src = _src;;++src,++dest) { + zap_chr8 const chr = *src; + if (chr == 0x0u) { + break; + } switch (chr) { default: - *out = *in; + *dest = *src; break; case 0x81: /* Bad characters. */ case 0x8D: case 0x8F: case 0x90: case 0x9D: - *out = 0xFFFDu; /* REPLACEMENT CHARACTER */ + *dest = 0xFFFDu; /* REPLACEMENT CHARACTER */ break; case 0x80: - *out = 0x20ACu; + *dest = 0x20ACu; break; case 0x82: - *out = 0x201Au; + *dest = 0x201Au; break; case 0x83: - *out = 0x192u; + *dest = 0x192u; break; case 0x84: - *out = 0x201Eu; + *dest = 0x201Eu; break; case 0x85: - *out = 0x2026u; + *dest = 0x2026u; break; case 0x86: - *out = 0x2020u; + *dest = 0x2020u; break; case 0x87: - *out = 0x2021u; + *dest = 0x2021u; break; case 0x88: - *out = 0x2C6u; + *dest = 0x2C6u; break; case 0x89: - *out = 0x2030u; + *dest = 0x2030u; break; case 0x8A: - *out = 0x160u; + *dest = 0x160u; break; case 0x8B: - *out = 0x2039u; + *dest = 0x2039u; break; case 0x8C: - *out = 0x152u; + *dest = 0x152u; break; case 0x8E: - *out = 0x17Du; + *dest = 0x17Du; break; case 0x91: - *out = 0x2018u; + *dest = 0x2018u; break; case 0x92: - *out = 0x2019u; + *dest = 0x2019u; break; case 0x93: - *out = 0x201Cu; + *dest = 0x201Cu; break; case 0x94: - *out = 0x201Du; + *dest = 0x201Du; break; case 0x95: - *out = 0x2022u; + *dest = 0x2022u; break; case 0x96: - *out = 0x2013u; + *dest = 0x2013u; break; case 0x97: - *out = 0x2014u; + *dest = 0x2014u; break; case 0x98: - *out = 0x2DCu; + *dest = 0x2DCu; break; case 0x99: - *out = 0x2122u; + *dest = 0x2122u; break; case 0x9A: - *out = 0x161u; + *dest = 0x161u; break; case 0x9B: - *out = 0x203Au; + *dest = 0x203Au; break; case 0x9C: - *out = 0x153u; + *dest = 0x153u; break; case 0x9E: - *out = 0x17Eu; + *dest = 0x17Eu; break; case 0x9F: - *out = 0x178u; + *dest = 0x178u; break; } - if (chr == 0x0u) {break;} } } diff --git a/zap/source/amd64/mem/win1252enc.c b/zap/source/any/mem/win1252enc.c index cd313cd..f773540 100644 --- a/zap/source/amd64/mem/win1252enc.c +++ b/zap/source/any/mem/win1252enc.c @@ -1,113 +1,113 @@ /* - 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>. */ -#include <zap/priv.h> - #include <zap/mem.h> -void zap_win1252enc(zap_chr20 const * const _in,zap_chr8 * const _out) { - zap_chr20 const * in = _in; - zap_chr8 * out = _out; - for (;;++in,++out) { - zap_chr20 const chr = *in; - zap_chr8 const bad = 0x3Fu; +void zap_win1252enc(zap_chr8 * const _dest,zap_chr02 const * const _src) { + zap_chr8 * dest; + zap_chr02 const * src; + for (dest = _dest,src = _src;;++src,++dest) { + zap_chr02 const chr = *src; + if (chr == 0x0u) { + break; + } + zap_chr8 const bad = 0x3Fu; switch (chr) { default: if (chr > 0xFFu) { - *out = bad; + *dest = bad; break; } if (chr >= 0x80u && chr <= 0x9Fu) { - *out = bad; + *dest = bad; break; } - *out = *in; + *dest = *src; break; case 0x20ACu: - *out = 0x80u; + *dest = 0x80u; break; case 0x201Au: - *out = 0x82u; + *dest = 0x82u; break; case 0x192u: - *out = 0x83u; + *dest = 0x83u; break; case 0x201Eu: - *out = 0x84u; + *dest = 0x84u; break; case 0x2026u: - *out = 0x85u; + *dest = 0x85u; break; case 0x2020u: - *out = 0x86u; + *dest = 0x86u; break; case 0x2021u: - *out = 0x87u; + *dest = 0x87u; break; case 0x2C6u: - *out = 0x88u; + *dest = 0x88u; break; case 0x2030u: - *out = 0x89u; + *dest = 0x89u; break; case 0x160u: - *out = 0x8Au; + *dest = 0x8Au; break; case 0x2039u: - *out = 0x8Bu; + *dest = 0x8Bu; break; case 0x152u: - *out = 0x8Cu; + *dest = 0x8Cu; break; case 0x17Du: - *out = 0x8Eu; + *dest = 0x8Eu; break; case 0x2018u: - *out = 0x91u; + *dest = 0x91u; break; case 0x2019u: - *out = 0x92u; + *dest = 0x92u; break; case 0x201Cu: - *out = 0x93u; + *dest = 0x93u; break; case 0x201Du: - *out = 0x94u; + *dest = 0x94u; break; case 0x2022u: - *out = 0x95u; + *dest = 0x95u; break; case 0x2013u: - *out = 0x96u; + *dest = 0x96u; break; case 0x2014u: - *out = 0x97u; + *dest = 0x97u; break; case 0x2DCu: - *out = 0x98u; + *dest = 0x98u; break; case 0x2122u: - *out = 0x99u; + *dest = 0x99u; break; case 0x161u: - *out = 0x9Au; + *dest = 0x9Au; break; case 0x203Au: - *out = 0x9Bu; + *dest = 0x9Bu; break; case 0x153u: - *out = 0x9Cu; + *dest = 0x9Cu; break; case 0x17Eu: - *out = 0x9Eu; + *dest = 0x9Eu; break; case 0x178u: - *out = 0x9Fu; + *dest = 0x9Fu; break; } - if (chr == 0x0u) {break;} } } |