diff options
-rw-r--r-- | CHANGELOG.txt | 9 | ||||
-rw-r--r-- | test.c | 93 | ||||
-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 |
8 files changed, 154 insertions, 50 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 7c5712d..41a8921 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,12 @@ +# 19.0 + +* Return the one-after-the-emd address from cp; +* (amd64) Fix wrong registers being used in cp and the function not working at all; +* Add compatibility version constant; +* Add compile-time string functions for C++; +* Check type in compile-time functions; +* Add more type checking constants for C++; + # 18.1 * Enable debug symbols; @@ -68,7 +68,7 @@ int main(void) { } // mem { - zap_i8 const src[0x3Fu] = { + zap_i8 const src[0x36u] = { 0x02u,0x03u,0x05u,0x07u,0x0Bu,0x0Du,0x11u,0x13u, 0x17u,0x1Du,0x1Fu,0x25u,0x29u,0x2Bu,0x2Fu,0x35u, 0x3Bu,0x3Du,0x43u,0x47u,0x49u,0x4Fu,0x53u,0x59u, @@ -78,42 +78,61 @@ int main(void) { 0xE3u,0xE5u,0xE9u,0xEFu,0xF1u,0xFBu, }; zap_i8 dest[sizeof (src)]; - zap_cp(dest,src,sizeof (src)); - test(dest[0x00u],src[0x00u],==) - test(dest[0x01u],src[0x01u],==) - test(dest[0x02u],src[0x02u],==) - test(dest[0x03u],src[0x03u],==) - test(dest[0x04u],src[0x04u],==) - test(dest[0x05u],src[0x05u],==) - test(dest[0x06u],src[0x06u],==) - test(dest[0x07u],src[0x07u],==) - test(dest[0x08u],src[0x08u],==) - test(dest[0x09u],src[0x09u],==) - test(dest[0x0Au],src[0x0Au],==) - test(dest[0x0Bu],src[0x0Bu],==) - test(dest[0x0Cu],src[0x0Cu],==) - test(dest[0x0Du],src[0x0Du],==) - test(dest[0x0Eu],src[0x0Eu],==) - test(dest[0x0Fu],src[0x0Fu],==) - test(dest[0x10u],src[0x10u],==) - test(dest[0x11u],src[0x11u],==) - test(dest[0x12u],src[0x12u],==) - test(dest[0x13u],src[0x13u],==) - test(dest[0x14u],src[0x14u],==) - test(dest[0x15u],src[0x15u],==) - test(dest[0x16u],src[0x16u],==) - test(dest[0x17u],src[0x17u],==) - test(dest[0x18u],src[0x18u],==) - test(dest[0x19u],src[0x19u],==) - test(dest[0x1Au],src[0x1Au],==) - test(dest[0x1Bu],src[0x1Bu],==) - test(dest[0x1Cu],src[0x1Cu],==) - test(dest[0x1Du],src[0x1Du],==) - test(dest[0x1Eu],src[0x1Eu],==) - test(dest[0x1Fu],src[0x1Fu],==) - test(dest[0x20u],src[0x20u],==) - test(dest[0x21u],src[0x21u],==) - test(dest[0x22u],src[0x22u],==) + test(zap_cp(dest,src,sizeof (src)),dest + sizeof(src),==) + test(dest[0x00u],0x02u,==) + test(dest[0x01u],0x03u,==) + test(dest[0x02u],0x05u,==) + test(dest[0x03u],0x07u,==) + test(dest[0x04u],0x0Bu,==) + test(dest[0x05u],0x0Du,==) + test(dest[0x06u],0x11u,==) + test(dest[0x07u],0x13u,==) + test(dest[0x08u],0x17u,==) + test(dest[0x09u],0x1Du,==) + test(dest[0x0Au],0x1Fu,==) + test(dest[0x0Bu],0x25u,==) + test(dest[0x0Cu],0x29u,==) + test(dest[0x0Du],0x2Bu,==) + test(dest[0x0Eu],0x2Fu,==) + test(dest[0x0Fu],0x35u,==) + test(dest[0x10u],0x3Bu,==) + test(dest[0x11u],0x3Du,==) + test(dest[0x12u],0x43u,==) + test(dest[0x13u],0x47u,==) + test(dest[0x14u],0x49u,==) + test(dest[0x15u],0x4Fu,==) + test(dest[0x16u],0x53u,==) + test(dest[0x17u],0x59u,==) + test(dest[0x18u],0x61u,==) + test(dest[0x19u],0x65u,==) + test(dest[0x1Au],0x67u,==) + test(dest[0x1Bu],0x6Bu,==) + test(dest[0x1Cu],0x6Du,==) + test(dest[0x1Du],0x71u,==) + test(dest[0x1Eu],0x7Fu,==) + test(dest[0x1Fu],0x83u,==) + test(dest[0x20u],0x89u,==) + test(dest[0x21u],0x8Bu,==) + test(dest[0x22u],0x95u,==) + test(dest[0x23u],0x97u,==) + test(dest[0x24u],0x9Du,==) + test(dest[0x25u],0xA3u,==) + test(dest[0x26u],0xA7u,==) + test(dest[0x27u],0xADu,==) + test(dest[0x28u],0xB3u,==) + test(dest[0x29u],0xB5u,==) + test(dest[0x2Au],0xBFu,==) + test(dest[0x2Bu],0xC1u,==) + test(dest[0x2Cu],0xC5u,==) + test(dest[0x2Du],0xC7u,==) + test(dest[0x2Eu],0xD3u,==) + test(dest[0x2Fu],0xDFu,==) + test(dest[0x30u],0xE3u,==) + test(dest[0x31u],0xE5u,==) + test(dest[0x32u],0xE9u,==) + test(dest[0x33u],0xEFu,==) + test(dest[0x34u],0xF1u,==) + test(dest[0x35u],0xFBu,==) } { zap_i04 val = 0x0u; 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; } |