summaryrefslogtreecommitdiff
path: root/zap/source/amd64/mem
diff options
context:
space:
mode:
Diffstat (limited to 'zap/source/amd64/mem')
-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
5 files changed, 28 insertions, 8 deletions
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: