diff options
Diffstat (limited to 'zap')
-rw-r--r-- | zap/include-priv/zap/priv.h | 2 | ||||
-rw-r--r-- | zap/include/zap/base.h | 11 | ||||
-rw-r--r-- | zap/src/fndbyte.c | 4 | ||||
-rw-r--r-- | zap/src/fndchr.c | 4 | ||||
-rw-r--r-- | zap/src/foreach.c | 16 | ||||
-rw-r--r-- | zap/src/memcpy.c | 12 | ||||
-rw-r--r-- | zap/src/memeq.c | 2 | ||||
-rw-r--r-- | zap/src/memfill.c | 4 | ||||
-rw-r--r-- | zap/src/strcpy.c | 2 | ||||
-rw-r--r-- | zap/src/streq.c | 2 | ||||
-rw-r--r-- | zap/src/strlen.c | 2 |
11 files changed, 40 insertions, 21 deletions
diff --git a/zap/include-priv/zap/priv.h b/zap/include-priv/zap/priv.h index b051589..24718bb 100644 --- a/zap/include-priv/zap/priv.h +++ b/zap/include-priv/zap/priv.h @@ -12,7 +12,7 @@ #include <stddef.h> #include <stdint.h> -#if (defined(sus_cmpl_gnu) || defined(sus_cmpl_llvm)) && defined(sus_os_unix) && !defined(zap_priv_noasm) && (defined(sus_arch_amd64) || defined(sus_arch_ia32)) +#if (defined(sus_comp_gnu) || defined(sus_comp_llvm)) && defined(sus_os_unix) && !defined(zap_priv_noasm) && (defined(sus_arch_amd64) || defined(sus_arch_ia32)) #define zap_priv_fastimpl #endif diff --git a/zap/include/zap/base.h b/zap/include/zap/base.h index f909a45..979a01b 100644 --- a/zap/include/zap/base.h +++ b/zap/include/zap/base.h @@ -12,12 +12,13 @@ #if !defined(zap_hdr_base) #define zap_hdr_base -#define zap_ver ((uint_Least64_t)0xCu) +#define zap_ver ((uint_Least64_t)0xBu) #if defined(sus_lang_asm) .extern zap_fndbyte .extern zap_fndchr +.extern zap_foreach .extern zap_memcmp .extern zap_memcpy .extern zap_memeq @@ -36,13 +37,15 @@ extern "C" { extern bool const zap_fastimpl; -sus_attr_alloc sus_attr_allocsz(0x2) sus_attr_hot sus_attr_nothrw sus_attr_useret void * zap_memdup( void const * ptr, size_t num); -sus_attr_hot sus_attr_nothrw sus_attr_useret size_t zap_fndbyte( void const * ptr, size_t num, uint_least8_t byte); +/* Memory sequence functions: */ +sus_attr_hot sus_attr_nothrw sus_attr_useret size_t zap_fndbyte( void const * ptr, size_t num, unsigned char byte); sus_attr_hot sus_attr_nothrw sus_attr_useret size_t zap_fndchr( char const * str, char chr); +sus_attr_hot sus_attr_nothrw void zap_foreach( void * ptr, size_t sz, size_t num, void (* fn)(void *)); sus_attr_hot sus_attr_nothrw sus_attr_useret int_least8_t zap_memcmp( void const * lstr,size_t num, void const * rstr); sus_attr_hot sus_attr_nothrw void zap_memcpy( void const * in, size_t num, void * out); +sus_attr_alloc sus_attr_allocsz(0x2) sus_attr_hot sus_attr_nothrw sus_attr_useret void * zap_memdup( void const * ptr, size_t num); sus_attr_hot sus_attr_nothrw sus_attr_useret bool zap_memeq( void const * lptr,size_t num, void const * rptr); -sus_attr_hot sus_attr_nothrw void zap_memfill( void * ptr, size_t num, uint_least8_t val); +sus_attr_hot sus_attr_nothrw void zap_memfill( void * ptr, size_t num, unsigned char val); sus_attr_hot sus_attr_nothrw sus_attr_useret int_least8_t zap_strcmp( char const * lstr,char const * rstr); sus_attr_hot sus_attr_nothrw sus_attr_useret size_t zap_strcpy( char const * in, char * out); sus_attr_alloc sus_attr_hot sus_attr_nothrw sus_attr_useret char * zap_strdup( char const * str); diff --git a/zap/src/fndbyte.c b/zap/src/fndbyte.c index 917aeff..3283eec 100644 --- a/zap/src/fndbyte.c +++ b/zap/src/fndbyte.c @@ -11,7 +11,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_fndbyte\n" + ".globl zap_fndbyte\n" "zap_fndbyte:\n" /* @@ -72,6 +72,6 @@ size_t zap_fndbyte(void const * const _ptr,size_t const _num,uint_least8_t const uint_least8_t const * ptr = (uint_least8_t const *)_ptr; uint_least8_t const * const afterbuf = ptr + _num; for (;ptr != afterbuf;++ptr) {sus_unlikely (*ptr == _byte) {return ptr - (uint_least8_t const *)_ptr;}} - return -0x1u; + return SIZE_MAX; } #endif diff --git a/zap/src/fndchr.c b/zap/src/fndchr.c index 6af1b73..5cf78f8 100644 --- a/zap/src/fndchr.c +++ b/zap/src/fndchr.c @@ -11,7 +11,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_fndchr\n" + ".globl zap_fndchr\n" "zap_fndchr:\n" /* @@ -64,7 +64,7 @@ size_t zap_fndchr(char const * const _str,char const _chr) { for (;;++pos) { char const chr = *pos; sus_unlikely (chr == _chr) {return (size_t)(pos - _str);} - sus_unlikely (chr == '\x0') {return -0x1u;} + sus_unlikely (chr == '\x0') {return SIZE_MAX;} } sus_unreach(); } diff --git a/zap/src/foreach.c b/zap/src/foreach.c new file mode 100644 index 0000000..54911e9 --- /dev/null +++ b/zap/src/foreach.c @@ -0,0 +1,16 @@ +/* + 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 <stddef.h> + +void zap_foreach(void * const _ptr,size_t const _sz,size_t const _num,void (* const _fn)(void *)) { + unsigned char * ptr = _ptr; + size_t const numbyte = _sz * _num; + void * const afterbuf = ptr + numbyte; + for (;ptr != afterbuf;ptr += _sz) {_fn(ptr);} +} diff --git a/zap/src/memcpy.c b/zap/src/memcpy.c index 1b40832..8fa98ae 100644 --- a/zap/src/memcpy.c +++ b/zap/src/memcpy.c @@ -11,14 +11,14 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_memcpy\n" + ".globl zap_memcpy\n" "zap_memcpy:\n" - /* - void const * in - size_t num - void * out - */ + /* + void const * in + size_t num + void * out + */ #if defined(sus_arch_amd64) /* rdi: Address of the current input element. */ /* rsi: Number of remaining elements. */ diff --git a/zap/src/memeq.c b/zap/src/memeq.c index f9717ad..75ecc12 100644 --- a/zap/src/memeq.c +++ b/zap/src/memeq.c @@ -12,7 +12,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_memeq\n" + ".globl zap_memeq\n" "zap_memeq:\n" /* diff --git a/zap/src/memfill.c b/zap/src/memfill.c index 70982c4..c9a9797 100644 --- a/zap/src/memfill.c +++ b/zap/src/memfill.c @@ -11,7 +11,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_memfill\n" + ".globl zap_memfill\n" "zap_memfill:\n" /* @@ -24,7 +24,7 @@ __asm__ ( /* rsi: Address of the element after the last element. */ "addq %rdi,%rsi\n" ".loop:\n" - "cmpq %rsi,%rdi\n" + "cmpq %rdi,%rsi\n" "je .done\n" /* Exit loop if we have reached the final element. */ "movb %dl,(%rdi)\n" "incq %rdi\n" diff --git a/zap/src/strcpy.c b/zap/src/strcpy.c index 3dc3e0f..943cb2c 100644 --- a/zap/src/strcpy.c +++ b/zap/src/strcpy.c @@ -10,7 +10,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_strcpy\n" + ".globl zap_strcpy\n" "zap_strcpy:\n" /* diff --git a/zap/src/streq.c b/zap/src/streq.c index 6425ef7..9221cec 100644 --- a/zap/src/streq.c +++ b/zap/src/streq.c @@ -11,7 +11,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_streq\n" + ".globl zap_streq\n" "zap_streq:\n" /* diff --git a/zap/src/strlen.c b/zap/src/strlen.c index c1e8959..eab12e6 100644 --- a/zap/src/strlen.c +++ b/zap/src/strlen.c @@ -10,7 +10,7 @@ #if defined(zap_priv_fastimpl) __asm__ ( - ".global zap_strlen\n" + ".globl zap_strlen\n" "zap_strlen:\n" /* |