diff options
Diffstat (limited to 'zap')
-rw-r--r-- | zap/include/zap/bs.h | 52 | ||||
-rw-r--r-- | zap/include/zap/mem.h | 4 | ||||
-rw-r--r-- | zap/include/zap/str.h | 24 | ||||
-rw-r--r-- | zap/source/amd64/mem/cp.s | 17 | ||||
-rw-r--r-- | zap/source/any/mem/cp.c | 3 | ||||
-rw-r--r-- | zap/source/any/str/strlen.c | 2 |
6 files changed, 89 insertions, 13 deletions
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h index 78d09f9..3a1a1dd 100644 --- a/zap/include/zap/bs.h +++ b/zap/include/zap/bs.h @@ -96,7 +96,8 @@ zap_priv_cdecl -#define zap_ver ((unsigned long)+0x18u) +#define zap_ver ((unsigned long)+0x19u) +#define zap_compatver ((unsigned long)+0x19u) // Programs expecting this version will still compile with the current version. #define zap_nopos zap_maxvalsz @@ -313,6 +314,55 @@ namespace zap { } namespace zap { + template<typename typ> constexpr auto ischrtyp = + ::zap::typeq<typ,char> + || ::zap::typeq<typ,char16_t> + || ::zap::typeq<typ,char32_t> +#if __cpp_char8_t + || ::zap::typeq<typ,char8_t> +#endif + || ::zap::typeq<typ,unsigned char> + || ::zap::typeq<typ,wchar_t>; + + template<typename typ> constexpr auto isflttyp = + ::zap::typeq<typ,double> + || ::zap::typeq<typ,float> + || ::zap::typeq<typ,long double> +#if __STDCPP_BFLOAT16_T__ + || ::zap::typeq<typ,decltype (0x0.0p0bf16)> +#endif +#if __STDCPP_FLOAT128_T__ + || ::zap::typeq<typ,decltype (0x0.0p0f16)> +#endif +#if __STDCPP_FLOAT16_T__ + || ::zap::typeq<typ,decltype (0x0.0p0f32)> +#endif +#if __STDCPP_FLOAT32_T__ + || ::zap::typeq<typ,decltype (0x0.0p0f64)> +#endif +#if __STDCPP_FLOAT64_T__ + || ::zap::typeq<typ,decltype (0x0.0p0f128)> +#endif + ; + + template<typename typ> constexpr auto isinttyp = + ::zap::typeq<typ,int> + || ::zap::typeq<typ,long> + || ::zap::typeq<typ,long long> + || ::zap::typeq<typ,short> + || ::zap::typeq<typ,signed char> + || ::zap::typeq<typ,unsigned char> + || ::zap::typeq<typ,unsigned int> + || ::zap::typeq<typ,unsigned long> + || ::zap::typeq<typ,unsigned long long> + || ::zap::typeq<typ,unsigned short>; + + template<typename typ> constexpr auto isarithtyp = + ::zap::isflttyp<typ> + || ::zap::isinttyp<typ>; +} + +namespace zap { using i8 = ::zap_i8; using i01 = ::zap_i01; using i02 = ::zap_i02; diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h index 36f06b9..751a601 100644 --- a/zap/include/zap/mem.h +++ b/zap/include/zap/mem.h @@ -11,10 +11,10 @@ zap_priv_cdecl -zap_priv_nothrw void zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num); +zap_priv_nothrw void * zap_cp( void * zap_priv_restr dest,void const * zap_priv_restr src, zap_sz num); zap_priv_nothrw zap_i8 zap_eq( void const * lbuf,void const * rbuf,zap_sz num); zap_priv_nothrw void zap_fill(void * dest,unsigned char val, zap_sz num); -zap_priv_nothrw void * zap_srch(void const * buf, unsigned char val, zap_sz num); +zap_priv_nothrw void * zap_srch(void const * buf, unsigned char val, zap_sz num); zap_priv_cdeclend diff --git a/zap/include/zap/str.h b/zap/include/zap/str.h index 42519dc..c594ce4 100644 --- a/zap/include/zap/str.h +++ b/zap/include/zap/str.h @@ -46,4 +46,28 @@ zap_i8 zap_fmtlenus( unsigned short val,zap_i8 bs); zap_priv_cdeclend +#if __cplusplus + +namespace zap { + template<typename typ> constexpr auto streq(typ const * lstr,typ const * rstr) noexcept -> bool { + static_assert(::zap::ischrtyp<typ>,"Input type must be a character type."); + for (;;++lstr,++rstr) { + typ const lchr = *lstr; + typ const rchr = *rstr; + if (lchr != rchr) return false; + if (lchr == typ {0x0}) break; + } + return true; + } + + template<typename typ> constexpr auto strlen(typ const * str) noexcept -> ::zap::sz { + static_assert(::zap::ischrtyp<typ>,"Input type must be a character type."); + typ const * const start = str; + while (*str++ != typ {0x0}); + return static_cast<::zap::sz>(str - start) - 0x1u; + } +} + +#endif + #endif diff --git a/zap/source/amd64/mem/cp.s b/zap/source/amd64/mem/cp.s index 2860acf..3c9f2e1 100644 --- a/zap/source/amd64/mem/cp.s +++ b/zap/source/amd64/mem/cp.s @@ -19,8 +19,8 @@ zap_cp: vmovdqu ymm0,[rsi] # val02 = *(unsigned int256_t *)src; vmovdqu [rdi],ymm0 # *(unsigned int256_t *)dest = val02; - add rsi,0x20 # dest += 0x20u; - add rdi,0x20 # src += 0x20u; + add rdi,0x20 # dest += 0x20u; + add rsi,0x20 # src += 0x20u; sub rdx,0x20 # num -= 0x20u; jmp short .big02cp # goto big02cp; @@ -31,8 +31,8 @@ zap_cp: movdqu xmm0,[rsi] # val01 = *(unsigned int128_t *)src; movdqu [rdi],xmm0 # *(unsigned int128_t *)dest = val01; - add rsi,0x10 # dest += 0x10u; - add rdi,0x10 # src += 0x10u; + add rdi,0x10 # dest += 0x10u; + add rsi,0x10 # src += 0x10u; sub rdx,0x10 # num -= 0x10u; jmp short .big01cp # goto big01cp; @@ -43,8 +43,8 @@ zap_cp: mov rcx,[rsi] # val8 = *(zap_i04 *)src; mov [rdi],rcx # *(zap_i04 *)dest = val8; - add rdi,0x8 # dest += 0x8u; - add rsi,0x8 # src += 0x8u; + add rsi,0x8 # dest += 0x8u; + add rdi,0x8 # src += 0x8u; sub rdx,0x8 # num -= 0x8u; jmp short .wrdcp # goto wrdcp @@ -53,7 +53,7 @@ zap_cp: jz short .done # goto done mov cl,[rsi] # val1 = *(zap_i8 *)src; - mov [rsi],cl # *(zap_i8 *)dest = val1; + mov [rdi],cl # *(zap_i8 *)dest = val1; inc rdi # ++dest; inc rsi # ++src; @@ -61,4 +61,5 @@ zap_cp: jmp short .bytecp # goto bytecp; .done: - ret # return + mov rax,rdi + ret # return dest; diff --git a/zap/source/any/mem/cp.c b/zap/source/any/mem/cp.c index 9752721..12c6bfd 100644 --- a/zap/source/any/mem/cp.c +++ b/zap/source/any/mem/cp.c @@ -6,9 +6,10 @@ #include <zap/mem.h> -void zap_cp(void * const zap_priv_restr voiddest,void const * const zap_priv_restr voidsrc,zap_sz const num) { +void * zap_cp(void * const zap_priv_restr voiddest,void const * const zap_priv_restr voidsrc,zap_sz const num) { unsigned char * dest = voiddest; unsigned char const * src = voidsrc; unsigned char * const stop = dest + num; while (dest != stop) *dest++ = *src++; + return dest; } diff --git a/zap/source/any/str/strlen.c b/zap/source/any/str/strlen.c index e6e9019..e763701 100644 --- a/zap/source/any/str/strlen.c +++ b/zap/source/any/str/strlen.c @@ -8,6 +8,6 @@ zap_sz zap_strlen(char const * str) { char const * const start = str; - while (*str++); + while (*str++ != '\x0'); return (zap_sz)(str - start) - 0x1u; } |