summaryrefslogtreecommitdiff
path: root/zap
diff options
context:
space:
mode:
Diffstat (limited to 'zap')
-rw-r--r--zap/GNUmakefile7
-rw-r--r--zap/include/zap/bs.h2
-rw-r--r--zap/include/zap/mem.h11
-rw-r--r--zap/source/amd64/mem/memcat.c2
-rw-r--r--zap/source/amd64/mem/memcnt.c22
-rw-r--r--zap/source/amd64/mem/memfnd.S (renamed from zap/source/amd64/mem/fndbyte.S)4
-rw-r--r--zap/source/amd64/mem/memfor.S (renamed from zap/source/amd64/mem/foreach.S)4
-rw-r--r--zap/source/amd64/mem/strfnd.S (renamed from zap/source/amd64/mem/fndchr.S)4
8 files changed, 39 insertions, 17 deletions
diff --git a/zap/GNUmakefile b/zap/GNUmakefile
index e0de7c4..18f94eb 100644
--- a/zap/GNUmakefile
+++ b/zap/GNUmakefile
@@ -35,17 +35,18 @@ CPPFLAGS := \
# ARTEFACTS
OBJS = \
- source/$(arch)/mem/fndbyte.o \
- source/$(arch)/mem/fndchr.o \
- source/$(arch)/mem/foreach.o \
source/$(arch)/mem/memcat.o \
+ 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/strcat.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 \
diff --git a/zap/include/zap/bs.h b/zap/include/zap/bs.h
index 1204690..7e14502 100644
--- a/zap/include/zap/bs.h
+++ b/zap/include/zap/bs.h
@@ -30,7 +30,7 @@ typedef signed char zap_cmp;
typedef unsigned long zap_sz;
-#define zap_ver ((unsigned long)+0x12u)
+#define zap_ver ((unsigned long)+0x13u)
#if defined(__cplusplus)
}
diff --git a/zap/include/zap/mem.h b/zap/include/zap/mem.h
index d69c45f..8bcaa0b 100644
--- a/zap/include/zap/mem.h
+++ b/zap/include/zap/mem.h
@@ -13,18 +13,19 @@
extern "C" {
#endif
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_fndbyte( void const * ptr, zap_sz num, unsigned char byte);
-__attribute__ ((hot,nothrow,warn_unused_result)) zap_sz zap_fndchr( char const * str, char chr);
-__attribute__ ((hot)) void zap_foreach( void * ptr, zap_sz sz, zap_sz num, void (* fn)(void *));
-__attribute__ ((hot,nothrow)) void zap_memcat( void const * lptr, zap_sz llen,void const * rptr, zap_sz rlen, void * buf);
+__attribute__ ((hot,nothrow)) void zap_memcat( void const * lptr, zap_sz llen,void const * rptr, zap_sz rlen, void * buf);
+__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)) void 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)) void zap_memfill( void * ptr, zap_sz num, unsigned char val);
-__attribute__ ((hot)) void zap_memgen( void * ptr, zap_sz sz, zap_sz num, void (* fn)(zap_sz,void *));
+__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)) void zap_strcat( char const * lstr, char const * rstr,char * buf);
__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);
diff --git a/zap/source/amd64/mem/memcat.c b/zap/source/amd64/mem/memcat.c
index f3e9a9b..2b50ba7 100644
--- a/zap/source/amd64/mem/memcat.c
+++ b/zap/source/amd64/mem/memcat.c
@@ -8,8 +8,6 @@
#include <zap/mem.h>
-#include <stddef.h>
-
void zap_memcat(void const * const _lptr,zap_sz const _llen,void const * const _rptr,zap_sz const _rlen,void * const _buf) {
zap_memcp(_lptr,_llen,_buf);
zap_memcp(_rptr,_rlen,(unsigned char *)_buf + _llen);
diff --git a/zap/source/amd64/mem/memcnt.c b/zap/source/amd64/mem/memcnt.c
new file mode 100644
index 0000000..c22abca
--- /dev/null
+++ b/zap/source/amd64/mem/memcnt.c
@@ -0,0 +1,22 @@
+/*
+ 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>
+
+zap_sz zap_memcnt(void const * const _ptr,zap_sz const _sz,zap_sz const _num,zap_bool (* const _fn)(void const *)) {
+ unsigned char const * addr = _ptr;
+ zap_sz const numbyte = _num * _sz;
+ unsigned char const * const afterbuf = addr + numbyte;
+ zap_sz num = 0x0u;
+ for (;addr != afterbuf;addr += _sz) {
+ if (_fn(addr)) {
+ ++num;
+ }
+ }
+ return num;
+}
diff --git a/zap/source/amd64/mem/fndbyte.S b/zap/source/amd64/mem/memfnd.S
index af2ee84..0b5a47e 100644
--- a/zap/source/amd64/mem/fndbyte.S
+++ b/zap/source/amd64/mem/memfnd.S
@@ -2,9 +2,9 @@
# 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_fndbyte
+.globl zap_memfnd
-zap_fndbyte:
+zap_memfnd:
# Address of the current element:
#define addr %rax
# Address of the first element:
diff --git a/zap/source/amd64/mem/foreach.S b/zap/source/amd64/mem/memfor.S
index 6766933..be705b9 100644
--- a/zap/source/amd64/mem/foreach.S
+++ b/zap/source/amd64/mem/memfor.S
@@ -2,9 +2,9 @@
# 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_foreach
+.globl zap_memfor
-zap_foreach:
+zap_memfor:
# Address of the current element:
#define addr %rbx
# Address of the element after the last input element:
diff --git a/zap/source/amd64/mem/fndchr.S b/zap/source/amd64/mem/strfnd.S
index 67e0ea1..d9c99f3 100644
--- a/zap/source/amd64/mem/fndchr.S
+++ b/zap/source/amd64/mem/strfnd.S
@@ -2,9 +2,9 @@
# 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_fndchr
+.globl zap_strfnd
-zap_fndchr:
+zap_strfnd:
# Address of the first character:
#define start %rdi
# Character to be found: