summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt13
-rw-r--r--rgo/Makefile4
-rw-r--r--rgo/include/rgo.h24
-rw-r--r--rgo/src/fndbyte.S44
-rw-r--r--rgo/src/fndchr.S8
-rw-r--r--rgo/src/memcpy.S14
-rw-r--r--rgo/src/memdup.c6
-rw-r--r--rgo/src/memeq.S60
-rw-r--r--rgo/src/memfill.S8
-rw-r--r--rgo/src/strcpy.S39
-rw-r--r--rgo/src/strdup.c6
-rw-r--r--rgo/src/streq.S45
-rw-r--r--rgo/src/strfill.c6
-rw-r--r--rgo/src/strlen.S6
-rw-r--r--test.c86
15 files changed, 311 insertions, 58 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index b123b2a..face77e 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,16 @@
+| 1
+
+- Fix indentation in license notices;
+- Fix incorrect declaration for rgo_strcpy, rgo_streq;
+- Implement fndbyte,memeq,strcpy,streq;
+- Add new tests;
+- Fix bug in memcpy: Should jump if zero, not if equal;
+- Remove declaration for rgo_memcmp;
+- Add macro rgo_ver, defined to the current version number;
+- Add assembly declaration for rgo_fndchr, rgo_fndbyte;
+- Fix some incorrect comments;
+- Use movups instead of movdqu in memcpy;
+
| 0
- Initial.
diff --git a/rgo/Makefile b/rgo/Makefile
index 4a4e29e..76282be 100644
--- a/rgo/Makefile
+++ b/rgo/Makefile
@@ -1,7 +1,11 @@
SRCS_ASM = \
+ src/fndbyte.S \
src/fndchr.S \
src/memcpy.S \
+ src/memeq.S \
src/memfill.S \
+ src/streq.S \
+ src/strcpy.S \
src/strlen.S
SRCS_C = \
src/memdup.c \
diff --git a/rgo/include/rgo.h b/rgo/include/rgo.h
index 1d76281..38c4672 100644
--- a/rgo/include/rgo.h
+++ b/rgo/include/rgo.h
@@ -3,18 +3,23 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
-#if !defined(rgo_hdr)
-#define rgo_hdr
+#if !defined(rgo_ver)
+#if defined(__ASSEMBLER__)
+#define rgo_ver $0x1
+#else
+#define rgo_ver (0x1)
+#endif
#if defined(__ASSEMBLER__)
-.extern rgo_memcmp
+.extern rgo_fndbyte
+.extern rgo_fndchr
.extern rgo_memcpy
.extern rgo_memeq
.extern rgo_memfill
@@ -33,15 +38,14 @@
#endif
rgo_priv_externc __attribute__((alloc_size(0x2),hot,malloc,nothrow)) void * __rgo_memdup(void const * __restrict__ ptr, size_t num);
-rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_fndchr( char const * __restrict__ str, char chr);
rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_fndbyte( void const * __restrict__ ptr, size_t num,uint8_t byte);
-rgo_priv_externc __attribute__((hot,nothrow)) int8_t rgo_memcmp( void const * __restrict__ lptr,size_t num,void const * __restrict__ rptr);
+rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_fndchr( char const * __restrict__ str, char chr);
rgo_priv_externc __attribute__((hot,nothrow)) void rgo_memcpy( void const * __restrict__ in, size_t num,void * __restrict__ out);
rgo_priv_externc __attribute__((hot,nothrow)) uint8_t rgo_memeq( void const * __restrict__ lptr,size_t num,void const * __restrict__ rptr);
rgo_priv_externc __attribute__((hot,nothrow)) void rgo_memfill( void const * __restrict__ ptr, size_t num,uint8_t val);
-rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_strcpy( char const * __restrict__ str);
+rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_strcpy( char const * __restrict__ lstr,char const * __restrict__ rstr);
rgo_priv_externc __attribute__((hot,malloc,nothrow)) char * rgo_strdup( char const * __restrict__ str);
-rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_streq( char const * __restrict__ lstr,char const * __restrict__ rstr);
+rgo_priv_externc __attribute__((hot,nothrow)) uint8_t rgo_streq( char const * __restrict__ lstr,char const * __restrict__ rstr);
rgo_priv_externc __attribute__((hot,nothrow)) void rgo_strfill( char const * __restrict__ lstr,char chr);
rgo_priv_externc __attribute__((hot,nothrow)) size_t rgo_strlen( char const * __restrict__ str);
diff --git a/rgo/src/fndbyte.S b/rgo/src/fndbyte.S
new file mode 100644
index 0000000..2e0ed8b
--- /dev/null
+++ b/rgo/src/fndbyte.S
@@ -0,0 +1,44 @@
+/*
+ Copyright 2022 Gabriel Jensen
+
+ This file is part of rgo.
+
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <rgo.h>
+
+.global rgo_fndbyte
+
+rgo_fndbyte:
+#if defined(__x86_64__)
+ /*
+ rdi: void const * ptr
+ rsi: size_t num
+ dl: uint8_t byte
+ */
+ /* rax: Address of the current element. */
+ movq %rdi,%rax
+ /* rcx: Address of the element after the last element. */
+ movq %rdi,%rcx
+ addq %rsi,%rcx
+ /* r8b: Current element. */
+.loop:
+ cmpq %rax,%rcx
+ je .nfnd /* We have went through the entire array without finding the byte. */
+ movb (%rax),%r8b
+ cmpb %r8b,%dl
+ je .fnd /* We have found the byte. */
+ incq %rax
+ jmp .loop
+.fnd:
+ subq %rdi,%rax
+ ret
+.nfnd:
+ movq $0xFFFFFFFFFFFFFFFF,%rax
+ ret
+#endif
diff --git a/rgo/src/fndchr.S b/rgo/src/fndchr.S
index 97c3768..cacea5e 100644
--- a/rgo/src/fndchr.S
+++ b/rgo/src/fndchr.S
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
@@ -28,7 +28,7 @@ rgo_fndchr:
cmpb %dl,%sil
je .done /* Exit loop if we have found the character. */
testb %dl,%dl
- je .err /* We encounted the null-terminator but not the specified character. */
+ je .err /* We encountered the null-terminator but not the specified character. */
incq %rax
jmp .loop
.done:
diff --git a/rgo/src/memcpy.S b/rgo/src/memcpy.S
index d20e9d6..51d82f9 100644
--- a/rgo/src/memcpy.S
+++ b/rgo/src/memcpy.S
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
@@ -29,11 +29,11 @@ rgo_memcpy:
movq %rsi,%r9
/* r10: Temporary. */
/* xmm0: Temporary. */
-.big128cpy: /* SSE2 is a part of AMD64. */
+.big128cpy:
cmpq $0x10,%r9
jl .wrdcpy
- movdqu (%rcx),%xmm0
- movdqu %xmm0,(%r8)
+ movups (%rcx),%xmm0
+ movups %xmm0,(%r8)
addq $0x10,%rcx
addq $0x10,%r8
subq $0x10,%r9
@@ -49,7 +49,7 @@ rgo_memcpy:
jmp .wrdcpy
.bytecpy:
testq %r9,%r9
- je .done
+ jz .done
movb (%rcx),%r10b
movb %r10b,(%r8)
incq %rcx
diff --git a/rgo/src/memdup.c b/rgo/src/memdup.c
index 0d166f0..97eefd6 100644
--- a/rgo/src/memdup.c
+++ b/rgo/src/memdup.c
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
diff --git a/rgo/src/memeq.S b/rgo/src/memeq.S
new file mode 100644
index 0000000..c3a9a63
--- /dev/null
+++ b/rgo/src/memeq.S
@@ -0,0 +1,60 @@
+/*
+ Copyright 2022 Gabriel Jensen
+
+ This file is part of rgo.
+
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <rgo.h>
+
+.global rgo_memeq
+
+rgo_memeq:
+#if defined(__x86_64__)
+ /*
+ rdi: void const * lptr
+ rsi: size_t num
+ rdx: void const * rptr
+ */
+ /* rcx: Address of the current left element. */
+ movq %rdi,%rcx
+ /* r8: Address of the current right element. */
+ movq %rdx,%r8
+ /* r9: Number of remaining elements. */
+ movq %rsi,%r9
+ /* r10: Temporary. */
+ /* r11: Temporary. */
+.wrdeq:
+ cmpq $0x8,%r9
+ jl .byteeq
+ movq (%rcx),%r10
+ movq (%r8),%r11
+ cmpq %r10,%r11
+ jz .neq
+ addq $0x8,%rcx
+ addq $0x8,%r8
+ subq $0x8,%r9
+ jmp .wrdeq
+.byteeq:
+ testq %r9,%r9
+ jz .eq /* If we have reached the final element, all previous elements have compared equal, and the memory sequences are equal. */
+ movb (%rcx),%r10b
+ movb (%r8),%r11b
+ cmpb %r10b,%r11b
+ jne .neq
+ incq %rcx
+ incq %r8
+ decq %r9
+ jmp .byteeq
+.eq:
+ mov $0x1,%rax
+ ret
+.neq:
+ mov $0x0,%rax
+ ret
+#endif
diff --git a/rgo/src/memfill.S b/rgo/src/memfill.S
index 3c4fb1f..d131c48 100644
--- a/rgo/src/memfill.S
+++ b/rgo/src/memfill.S
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
@@ -24,7 +24,7 @@ rgo_memfill:
/* We don't need to preserve any of the registers we use according to the ABI. */
/* rcx: Address of the current element. */
movq %rdi,%rcx
- /* r8: Address of the last element. */
+ /* rcx: Address of the element after the last element. */
movq %rdi,%r8
addq %rsi,%r8
.loop:
diff --git a/rgo/src/strcpy.S b/rgo/src/strcpy.S
new file mode 100644
index 0000000..f2fbc36
--- /dev/null
+++ b/rgo/src/strcpy.S
@@ -0,0 +1,39 @@
+/*
+ Copyright 2022 Gabriel Jensen
+
+ This file is part of rgo.
+
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <rgo.h>
+
+.global rgo_strcpy
+
+rgo_strcpy:
+#if defined(__x86_64__)
+ /*
+ rdi: char const * lstr
+ rsi: char const * rstr
+ */
+ /* rax: Address of the current input character. */
+ movq %rdi,%rax
+ /* rdx: Address of the current output character. */
+ movq %rsi,%rdx
+ /* cl: Current character. */
+.loop:
+ movb (%rax),%cl
+ movb %cl,(%rdx)
+ testb %cl,%cl
+ jz .done
+ incq %rax
+ incq %rdx
+ jmp .loop
+.done:
+ subq %rdi,%rax
+ ret
+#endif
diff --git a/rgo/src/strdup.c b/rgo/src/strdup.c
index f10ef84..8608187 100644
--- a/rgo/src/strdup.c
+++ b/rgo/src/strdup.c
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
diff --git a/rgo/src/streq.S b/rgo/src/streq.S
new file mode 100644
index 0000000..f530d54
--- /dev/null
+++ b/rgo/src/streq.S
@@ -0,0 +1,45 @@
+/*
+ Copyright 2022 Gabriel Jensen
+
+ This file is part of rgo.
+
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include <rgo.h>
+
+.global rgo_streq
+
+rgo_streq:
+#if defined(__x86_64__)
+ /*
+ rdi: char const * lstr
+ rsi: char const * rstr
+ */
+ /* rdx: Address of the current input character. */
+ movq %rdi,%rdx
+ /* rcx: Address of the current output character. */
+ movq %rsi,%rcx
+ /* r8b: Current input character. */
+ /* r9b: Current output character. */
+.loop:
+ movb (%rdx),%r8b
+ movb (%rcx),%r9b
+ cmpb %r8b,%r9b
+ jne .neq
+ testb %r8b,%r8b /* Check if we have reached the null-terminator. */
+ jz .eq
+ incq %rdx
+ incq %rcx
+ jmp .loop
+.eq:
+ mov $0x1,%rax
+ ret
+.neq:
+ mov $0x0,%rax
+ ret
+#endif
diff --git a/rgo/src/strfill.c b/rgo/src/strfill.c
index 4d73c11..6fb3d4f 100644
--- a/rgo/src/strfill.c
+++ b/rgo/src/strfill.c
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
diff --git a/rgo/src/strlen.S b/rgo/src/strlen.S
index ff6ed70..7508be9 100644
--- a/rgo/src/strlen.S
+++ b/rgo/src/strlen.S
@@ -3,11 +3,11 @@
This file is part of rgo.
- rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ rgo is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
- rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ rgo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
- You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
+ You should have received a copy of the GNU Lesser General Public License along with rgo. If not, see <https://www.gnu.org/licenses/>.
*/
#include <rgo.h>
diff --git a/test.c b/test.c
index 6119eed..8a3126e 100644
--- a/test.c
+++ b/test.c
@@ -8,20 +8,7 @@
#include <stdio.h>
int main(void) {
- {
- char const * restrict str = "Oh my science!";
- size_t pos = rgo_fndchr(str,' ');
- fprintf(stderr,"pos: %zX\n",pos);
- assert(pos == (size_t)0x2);
- str += pos + (size_t)0x1;
- pos = rgo_fndchr(str,' ');
- fprintf(stderr,"pos: %zX\n",pos);
- assert(pos == (size_t)0x2);
- str += pos + (size_t)0x1;
- pos = rgo_fndchr(str,' ');
- fprintf(stderr,"pos: %zX\n",pos);
- assert(pos == (size_t)-0x1);
- }
+ fprintf(stderr,"\n");
{
#undef arrsz
#define arrsz ((size_t)0x7)
@@ -65,15 +52,19 @@ int main(void) {
fprintf(stderr,"arr1[4]: %" PRIX64 "\n",arr1[(size_t)0x4]);
fprintf(stderr,"arr1[5]: %" PRIX64 "\n",arr1[(size_t)0x5]);
fprintf(stderr,"arr1[6]: %" PRIX64 "\n",arr1[(size_t)0x6]);
- assert(arr1[(size_t)0x0] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr1[(size_t)0x1] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr1[(size_t)0x2] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr1[(size_t)0x3] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr1[(size_t)0x4] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr1[(size_t)0x5] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr1[(size_t)0x6] == UINT64_C(0x7F7F7F7F7F7F7F7F));
+ assert(arr1[(size_t)0x0] == arr0[(size_t)0x0]);
+ assert(arr1[(size_t)0x1] == arr0[(size_t)0x1]);
+ assert(arr1[(size_t)0x2] == arr0[(size_t)0x2]);
+ assert(arr1[(size_t)0x3] == arr0[(size_t)0x3]);
+ assert(arr1[(size_t)0x4] == arr0[(size_t)0x4]);
+ assert(arr1[(size_t)0x5] == arr0[(size_t)0x5]);
+ assert(arr1[(size_t)0x6] == arr0[(size_t)0x6]);
+ uint8_t const cmp = rgo_memeq(arr1,arrsz,arr0);
+ fprintf(stderr,"cmp: %u\n",cmp);
+ assert(cmp);
#undef arrsz
}
+ fprintf(stderr,"\n");
{
char const * str0 = "Hello there! General Kenobi?";
fprintf(stderr,"str0: \"%s\"\n",str0);
@@ -81,5 +72,58 @@ int main(void) {
fprintf(stderr,"strsz: %zX\n",strsz);
assert(strsz == (size_t)0x1C);
}
+ fprintf(stderr,"\n");
+ {
+ char const * restrict str = "Oh my science!";
+ size_t const len = rgo_strlen(str);
+ size_t pos0 = rgo_fndchr(str,' ');
+ size_t pos1 = rgo_fndbyte(str,len,(uint8_t)' ');
+ fprintf(stderr,"pos0: %zX\n",pos0);
+ fprintf(stderr,"pos1: %zX\n",pos1);
+ assert(pos0 == (size_t)0x2);
+ assert(pos1 == pos0);
+ str += pos0 + (size_t)0x1;
+ pos0 = rgo_fndchr(str,' ');
+ pos1 = rgo_fndbyte(str,len,(uint8_t)' ');
+ fprintf(stderr,"pos0: zX\n",pos0);
+ fprintf(stderr,"pos1: %zX\n",pos1);
+ assert(pos0 == (size_t)0x2);
+ assert(pos1 == pos0);
+ str += pos0 + (size_t)0x1;
+ pos0 = rgo_fndchr(str,' ');
+ pos1 = rgo_fndbyte(str,len,(uint8_t)' ');
+ fprintf(stderr,"pos0: %zX\n",pos0);
+ fprintf(stderr,"pos1: %zX\n",pos1);
+ assert(pos0 == (size_t)-0x1);
+ assert(pos1 == pos0);
+ }
+ fprintf(stderr,"\n");
+ {
+ char const str0[] = "What's up, my guy?";
+ fprintf(stderr,"str0: \"%s\"\n",str0);
+ char const str1[] = "What's up, my guy?";
+ fprintf(stderr,"str1: \"%s\"\n",str1);
+ char const str2[] = "I don't know you!";
+ fprintf(stderr,"str2: \"%s\"\n",str2);
+ uint8_t const cmp0 = rgo_streq(str0,str1);
+ uint8_t const cmp1 = rgo_streq(str0,str2);
+ uint8_t const cmp2 = rgo_streq(str1,str2);
+ fprintf(stderr,"cmp0: %u\n",cmp0);
+ fprintf(stderr,"cmp1: %u\n",cmp1);
+ fprintf(stderr,"cmp2: %u\n",cmp2);
+ assert(cmp0);
+ assert(!cmp1);
+ assert(!cmp2);
+ }
+ fprintf(stderr,"\n");
+ {
+ char const str0[] = "What in the world?";
+ fprintf(stderr,"str0: \"%s\"\n",str0);
+ char const str1[sizeof (str0)];
+ assert(rgo_strcpy(str0,str1) == (size_t)0x12);
+ fprintf(stderr,"str1: \"%s\"\n",str1);
+ assert(rgo_streq(str0,str1));
+ }
+ fprintf(stderr,"\n");
printf("All tests have passed!\n");
}