summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.txt16
-rw-r--r--Makefile66
-rw-r--r--rgo/include-priv/rgo-priv.h3
-rw-r--r--rgo/include/rgo.h56
-rw-r--r--rgo/src/fastimpl.c9
-rw-r--r--rgo/src/fndbyte.c17
-rw-r--r--rgo/src/fndchr.c11
-rw-r--r--rgo/src/memcmp.c21
-rw-r--r--rgo/src/memcpy.c13
-rw-r--r--rgo/src/memdup.c8
-rw-r--r--rgo/src/memeq.c18
-rw-r--r--rgo/src/memfill.c13
-rw-r--r--rgo/src/strcmp.c21
-rw-r--r--rgo/src/strcpy.c10
-rw-r--r--rgo/src/strdup.c8
-rw-r--r--rgo/src/streq.c13
-rw-r--r--rgo/src/strfill.c2
-rw-r--r--rgo/src/strlen.c8
-rw-r--r--test.c144
19 files changed, 308 insertions, 149 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index f1f91c3..e5da972 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -1,3 +1,19 @@
+| A
+
+- Installation script: Create installation directories if they don't already exist;
+- Don't use susinfo types;
+- Remove declarations for getbinver;
+- Add memcmp, strcmp;
+- Update makefile;
+- Reimplement fastimpl as a global variable;
+- Change type of fastimpl (uint_least8_t => _Bool);
+- Change the return types of memeq and streq (uint_least8_t => _Bool);
+- Enable compilation warnings;
+- Add type literals (like those from susinfo);
+- Use *int_leastN_t instead of *intN_t;
+- Remove restrict-qualifications;
+- Remove C++ version of memdup;
+
| 9
- Fix readme not reflecting that we now support all platforms;
diff --git a/Makefile b/Makefile
index f1301bf..264dbaa 100644
--- a/Makefile
+++ b/Makefile
@@ -1,41 +1,67 @@
-SRCS = \
- rgo/src/fastimpl.c \
- rgo/src/fndbyte.c \
- rgo/src/fndchr.c \
- rgo/src/memcpy.c \
- rgo/src/memdup.c \
- rgo/src/memeq.c \
- rgo/src/memfill.c \
- rgo/src/strdup.c \
- rgo/src/streq.c \
- rgo/src/strfill.c \
- rgo/src/strcpy.c \
- rgo/src/strlen.c
-
-OBJS := $(SRCS:.c=.o)
-LIB := librgo.a
+# TOOLS
+
+# TOOL FLAGS
CFLAGS = \
-Irgo/include \
-Irgo/include-priv \
-O3 \
-g \
- -march=native
+ -march=native \
+ -std=c99 \
+ -Wall \
+ -Wextra \
+ -Wpedantic
+
+# Uncomment to enable freestanding mode:
+#CFLAGS += \
+ -Drgo_priv_nostdlib \
+ -ffreestanding
# Uncomment to disable assembly algorithms:
#CFLAGS += -Drgo_priv_noasm
+# HEADERS
+
+HDRS = \
+ rgo/include-priv/rgo-priv.h \
+ rgo/include/rgo.h \
+
+# BINARIES
+
+OBJS = \
+ rgo/src/fastimpl.o \
+ rgo/src/fndbyte.o \
+ rgo/src/fndchr.o \
+ rgo/src/memcmp.o \
+ rgo/src/memcpy.o \
+ rgo/src/memdup.o \
+ rgo/src/memeq.o \
+ rgo/src/memfill.o \
+ rgo/src/strcmp.o \
+ rgo/src/strdup.o \
+ rgo/src/streq.o \
+ rgo/src/strfill.o \
+ rgo/src/strcpy.o \
+ rgo/src/strlen.o
+
+LIB = librgo.a
+
+# TARGETS
+
.PHONY: clean install purge
$(LIB): $(OBJS)
ar r $@ $^
install: $(LIB)
- install -Dm644 rgo/include/rgo.h $(HDRDIR)/rgo.h
+ mkdir -pm755 $(HDRDIR)
+ mkdir -pm755 $(LIBDIR)
+ install -Dm644 rgo/include/rgo.h $(HDRDIR)
install -Dm755 $(LIB) $(LIBDIR)/$(LIB)
clean:
rm -fr $(OBJS)
-purge:
- rm -fr $(LIB) $(OBJS)
+purge: clean
+ rm -fr $(LIB)
diff --git a/rgo/include-priv/rgo-priv.h b/rgo/include-priv/rgo-priv.h
index 8b0b65c..2669e92 100644
--- a/rgo/include-priv/rgo-priv.h
+++ b/rgo/include-priv/rgo-priv.h
@@ -8,6 +8,9 @@
#include <rgo.h>
+#include <stddef.h>
+#include <stdint.h>
+
#if defined(__GNUC__) && defined(sus_os_unix) && !defined(rgo_priv_noasm) && (defined(sus_arch_amd64) || defined(sus_arch_ia32))
#define rgo_priv_fastimpl
#endif
diff --git a/rgo/include/rgo.h b/rgo/include/rgo.h
index fe54e75..d05b4dd 100644
--- a/rgo/include/rgo.h
+++ b/rgo/include/rgo.h
@@ -4,51 +4,63 @@
If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
#include <sus.h>
#if !defined(rgo_ver)
-#define rgo_ver sus_typlit_u64(0x9)
+#define rgo_ver rgo_typlit_u64(0xA)
+
+#define rgo_typlit_s10(_lit) ((int_least16_t)( _lit))
+#define rgo_typlit_s20(_lit) ((int_least32_t)( _lit))
+#define rgo_typlit_s40(_lit) ((int_least64_t)( _lit))
+#define rgo_typlit_s8( _lit) ((int_least8_t)( _lit))
+#define rgo_typlit_u10(_lit) ((uint_least16_t)(_lit))
+#define rgo_typlit_u20(_lit) ((uint_least32_t)(_lit))
+#define rgo_typlit_u40(_lit) ((uint_least64_t)(_lit))
+#define rgo_typlit_u8( _lit) ((uint_least8_t)( _lit))
+#define rgo_typlit_usz(_lit) ((size_t)( _lit))
#if defined(sus_lang_asm)
+
.extern rgo_fndbyte
.extern rgo_fndchr
-.extern rgo_getbinver
+.extern rgo_memcmp
.extern rgo_memcpy
.extern rgo_memeq
.extern rgo_memfill
+.extern rgo_strcmp
.extern rgo_strcpy
.extern rgo_streq
.extern rgo_strfill
.extern rgo_strlen
+
#else
#if defined(sus_lang_cxx)
extern "C" {
#endif
-sus_attr_alloc sus_attr_allocsz(0x2) sus_attr_hot sus_attr_nothrw void * __rgo_memdup( void const * sus_restr ptr, sus_typ_usz num);
-sus_attr_cold sus_attr_const sus_attr_nothrw sus_typ_u8 rgo_fastimpl( void);
-sus_attr_hot sus_attr_nothrw sus_typ_usz rgo_fndbyte( void const * sus_restr ptr, sus_typ_usz num,sus_typ_u8 byte);
-sus_attr_hot sus_attr_nothrw sus_typ_usz rgo_fndchr( char const * sus_restr str, char chr);
-sus_attr_cold sus_attr_nothrw sus_typ_u64 rgo_getbinver(void);
-sus_attr_hot sus_attr_nothrw void rgo_memcpy( void const * sus_restr in, sus_typ_usz num,void * sus_restr out);
-sus_attr_hot sus_attr_nothrw sus_typ_u8 rgo_memeq( void const * sus_restr lptr,sus_typ_usz num,void const * sus_restr rptr);
-sus_attr_hot sus_attr_nothrw void rgo_memfill( void * sus_restr ptr, sus_typ_usz num,sus_typ_u8 val);
-sus_attr_hot sus_attr_nothrw sus_typ_usz rgo_strcpy( char const * sus_restr in, char * sus_restr out);
-sus_attr_alloc sus_attr_hot sus_attr_nothrw char * rgo_strdup( char const * sus_restr str);
-sus_attr_hot sus_attr_nothrw sus_typ_u8 rgo_streq( char const * sus_restr lstr,char const * sus_restr rstr);
-sus_attr_hot sus_attr_nothrw void rgo_strfill( char * sus_restr lstr,char chr);
-sus_attr_hot sus_attr_nothrw sus_typ_usz rgo_strlen( char const * sus_restr str);
+extern bool const rgo_fastimpl;
-#if defined(sus_lang_cxx)
-}
-#endif
+sus_attr_alloc sus_attr_allocsz(0x2) sus_attr_hot sus_attr_nothrw void * rgo_memdup( void const * ptr, size_t num);
+sus_attr_hot sus_attr_nothrw size_t rgo_fndbyte( void const * ptr, size_t num, uint_least8_t byte);
+sus_attr_hot sus_attr_nothrw size_t rgo_fndchr( char const * str, char chr);
+sus_attr_hot sus_attr_nothrw int_least8_t rgo_memcmp( void const * lstr,size_t num, void const * rstr);
+sus_attr_hot sus_attr_nothrw void rgo_memcpy( void const * in, size_t num, void * out);
+sus_attr_hot sus_attr_nothrw bool rgo_memeq( void const * lptr,size_t num, void const * rptr);
+sus_attr_hot sus_attr_nothrw void rgo_memfill( void * ptr, size_t num, uint_least8_t val);
+sus_attr_hot sus_attr_nothrw int_least8_t rgo_strcmp( char const * lstr,char const * rstr);
+sus_attr_hot sus_attr_nothrw size_t rgo_strcpy( char const * in, char * out);
+sus_attr_alloc sus_attr_hot sus_attr_nothrw char * rgo_strdup( char const * str);
+sus_attr_hot sus_attr_nothrw bool rgo_streq( char const * lstr,char const * rstr);
+sus_attr_hot sus_attr_nothrw void rgo_strfill( char * lstr,char chr);
+sus_attr_hot sus_attr_nothrw size_t rgo_strlen( char const * str);
-#if defined(sus_lang_cxx)
-template<typename T> sus_attr_alloc sus_attr_allocsz(0x2) sus_attr_hot sus_attr_nothrw T * rgo_memdup(T const * sus_restr const _ptr,::sus_typ_usz const _num) -> T * {return static_cast<T *>(::__rgo_memdup(_ptr,_num));}
-#else
-#define rgo_memdup __rgo_memdup
#endif
+#if defined(sus_lang_cxx)
+}
#endif
#endif
diff --git a/rgo/src/fastimpl.c b/rgo/src/fastimpl.c
index c584119..3d3e67f 100644
--- a/rgo/src/fastimpl.c
+++ b/rgo/src/fastimpl.c
@@ -6,10 +6,11 @@
#include <rgo-priv.h>
-sus_typ_u8 rgo_fastimpl(void) {
+#include <stdbool.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
- return sus_typlit_u8(0x1);
+bool const rgo_fastimpl = true;
#else
- return sus_typlit_u8(0x0);
+bool const rgo_fastimpl = false;
#endif
-}
diff --git a/rgo/src/fndbyte.c b/rgo/src/fndbyte.c
index 29945a0..79b4aaf 100644
--- a/rgo/src/fndbyte.c
+++ b/rgo/src/fndbyte.c
@@ -6,6 +6,9 @@
#include <rgo-priv.h>
+#include <stddef.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_fndbyte\n"
@@ -13,8 +16,8 @@ __asm__ (
"rgo_fndbyte:\n"
/*
void const * ptr
- sus_typ_usz num
- sus_typ_u8 byte
+ size_t num
+ uint_least8_t byte
*/
#if defined(sus_arch_amd64)
/* rax: Address of the current element. */
@@ -65,10 +68,10 @@ __asm__ (
#endif
);
#else
-sus_typ_usz rgo_fndbyte(void const * const sus_restr _ptr,sus_typ_usz const _num,sus_typ_u8 const _byte) {
- sus_typ_u8 const * ptr = (sus_typ_u8 const *)_ptr;
- sus_typ_u8 const * const afterbuf = ptr + _num;
- for (;ptr != afterbuf;++ptr) {sus_unlikely (*ptr == _byte) {return ptr - (sus_typ_u8 const *)_ptr;}}
- return sus_typlit_usz(-0x1);
+size_t rgo_fndbyte(void const * const _ptr,size_t const _num,uint_least8_t const _byte) {
+ 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 rgo_typlit_usz(-0x1);
}
#endif
diff --git a/rgo/src/fndchr.c b/rgo/src/fndchr.c
index 12cd006..74aac4d 100644
--- a/rgo/src/fndchr.c
+++ b/rgo/src/fndchr.c
@@ -6,6 +6,9 @@
#include <rgo-priv.h>
+#include <stddef.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_fndchr\n"
@@ -56,12 +59,12 @@ __asm__ (
#endif
);
#else
-sus_typ_usz rgo_fndchr(char const * const sus_restr _str,char const _chr) {
- char const * sus_restr pos = _str;
+size_t rgo_fndchr(char const * const _str,char const _chr) {
+ char const * pos = _str;
for (;;++pos) {
char const chr = *pos;
- sus_unlikely (chr == _chr) {return (sus_typ_usz)(pos - _str);}
- sus_unlikely (chr == '\x0') {return sus_typlit_usz(-0x1);}
+ sus_unlikely (chr == _chr) {return (size_t)(pos - _str);}
+ sus_unlikely (chr == '\x0') {return rgo_typlit_usz(-0x1);}
}
sus_unreach();
}
diff --git a/rgo/src/memcmp.c b/rgo/src/memcmp.c
new file mode 100644
index 0000000..bb134f4
--- /dev/null
+++ b/rgo/src/memcmp.c
@@ -0,0 +1,21 @@
+/*
+ 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 <rgo-priv.h>
+
+#include <stddef.h>
+
+int_least8_t rgo_memcmp(void const * const _lstr,size_t const _num,void const * const _rstr) {
+ unsigned char const * lpos = (unsigned char const *)_lstr;
+ unsigned char const * rpos = (unsigned char const *)_rstr;
+ unsigned char const * const afterlbuf = lpos + _num;
+ for (;lpos != afterlbuf;++lpos,++rpos) {
+ unsigned char const lbyte = *lpos;
+ unsigned char const rbyte = *rpos;
+ sus_likely (lbyte != rbyte) {return lbyte < rbyte ? (int_least8_t)INT8_MIN : (int_least8_t)INT8_MAX;}
+ }
+ return rgo_typlit_s8(0x0);
+}
diff --git a/rgo/src/memcpy.c b/rgo/src/memcpy.c
index 89adc14..33ca41c 100644
--- a/rgo/src/memcpy.c
+++ b/rgo/src/memcpy.c
@@ -6,6 +6,9 @@
#include <rgo-priv.h>
+#include <stddef.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_memcpy\n"
@@ -13,7 +16,7 @@ __asm__ (
"rgo_memcpy:\n"
/*
void const * in
- sus_typ_usz num
+ size_t num
void * out
*/
#if defined(sus_arch_amd64)
@@ -129,10 +132,10 @@ __asm__ (
#endif
);
#else
-void rgo_memcpy(void const * const sus_restr _in,sus_typ_usz const _num,void * const sus_restr _out) {
- sus_typ_u8 const * in = (sus_typ_u8 const *)_in;
- sus_typ_u8 * sus_restr out = (sus_typ_u8 *)_out;
- sus_typ_u8 const * const afterbuf = in + _num;
+void rgo_memcpy(void const * const _in,size_t const _num,void * const _out) {
+ uint_least8_t const * in = (uint_least8_t const *)_in;
+ uint_least8_t * out = (uint_least8_t *)_out;
+ uint_least8_t const * const afterbuf = in + _num;
for (;in != afterbuf;++in,++out) {*out = *in;}
}
#endif
diff --git a/rgo/src/memdup.c b/rgo/src/memdup.c
index fb247f3..9cdf3cb 100644
--- a/rgo/src/memdup.c
+++ b/rgo/src/memdup.c
@@ -8,9 +8,13 @@
#include <stdlib.h>
-void * __rgo_memdup(void const * const __restrict__ _ptr,sus_typ_usz const _num) {
- void * const __restrict__ dup = malloc(_num);
+void * rgo_memdup(sus_attr_unused void const * const _ptr,sus_attr_unused size_t const _num) {
+#if !defined(rgo_priv_nostdlib)
+ void * const dup = malloc(_num);
if (__builtin_expect (dup == NULL,0x0l)) {return NULL;}
rgo_memcpy(_ptr,_num,dup);
return dup;
+#else
+ return NULL;
+#endif
}
diff --git a/rgo/src/memeq.c b/rgo/src/memeq.c
index 03ae2c2..d2d51a2 100644
--- a/rgo/src/memeq.c
+++ b/rgo/src/memeq.c
@@ -6,6 +6,10 @@
#include <rgo-priv.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_memeq\n"
@@ -13,7 +17,7 @@ __asm__ (
"rgo_memeq:\n"
/*
void const * lptr
- sus_typ_usz num
+ size_t num
void const * rptr
*/
#if defined(sus_arch_amd64)
@@ -96,11 +100,11 @@ __asm__ (
#endif
);
#else
-sus_typ_u8 rgo_memeq(void const * const sus_restr _lptr,sus_typ_usz const _num,void const * const sus_restr _rptr) {
- sus_typ_u8 const * lpos = (sus_typ_u8 const *)_lptr;
- sus_typ_u8 const * sus_restr rpos = (sus_typ_u8 const *)_rptr;
- sus_typ_u8 const * const afterbuf = lpos + _num;
- for (;lpos != afterbuf;++lpos,++rpos) {sus_likely (*lpos != *rpos) {return sus_typlit_u8(0x0);}}
- return sus_typlit_u8(0x1);
+bool rgo_memeq(void const * const _lptr,size_t const _num,void const * const _rptr) {
+ uint_least8_t const * lpos = (uint_least8_t const *)_lptr;
+ uint_least8_t const * rpos = (uint_least8_t const *)_rptr;
+ uint_least8_t const * const afterbuf = lpos + _num;
+ for (;lpos != afterbuf;++lpos,++rpos) {sus_likely (*lpos != *rpos) {return false;}}
+ return true;
}
#endif
diff --git a/rgo/src/memfill.c b/rgo/src/memfill.c
index ec5e1fa..d4c27e0 100644
--- a/rgo/src/memfill.c
+++ b/rgo/src/memfill.c
@@ -6,6 +6,9 @@
#include <rgo-priv.h>
+#include <stddef.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_memfill\n"
@@ -13,8 +16,8 @@ __asm__ (
"rgo_memfill:\n"
/*
void const * ptr
- sus_typ_usz num
- sus_typ_u8 val
+ size_t num
+ uint_least8_t val
*/
#if defined(sus_arch_amd64)
/* rdi: Address of the current element. */
@@ -47,9 +50,9 @@ __asm__ (
#endif
);
#else
-void rgo_memfill(void * const sus_restr _ptr,sus_typ_usz const _num,sus_typ_u8 const _byte) {
- sus_typ_u8 * pos = (sus_typ_u8 *)_ptr;
- sus_typ_u8 * const afterbuf = pos + _num;
+void rgo_memfill(void * const _ptr,size_t const _num,uint_least8_t const _byte) {
+ uint_least8_t * pos = (uint_least8_t *)_ptr;
+ uint_least8_t * const afterbuf = pos + _num;
for (;pos != afterbuf;++pos) {*pos = _byte;}
}
#endif
diff --git a/rgo/src/strcmp.c b/rgo/src/strcmp.c
new file mode 100644
index 0000000..aea821b
--- /dev/null
+++ b/rgo/src/strcmp.c
@@ -0,0 +1,21 @@
+/*
+ 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 <rgo-priv.h>
+
+#include <stdint.h>
+
+int_least8_t rgo_strcmp(char const * const _lstr,char const * const _rstr) {
+ unsigned char const * lpos = (unsigned char const *)_lstr;
+ unsigned char const * rpos = (unsigned char const *)_rstr;
+ for (;;++lpos,++rpos) {
+ unsigned char const lchr = *lpos;
+ unsigned char const rchr = *rpos;
+ sus_likely (lchr != rchr) {return lchr < rchr ? (int_least8_t)INT8_MIN : (int_least8_t)INT8_MAX;}
+ sus_unlikely (lchr == (unsigned char)0x0) {return rgo_typlit_s8(0x0);}
+ }
+ sus_unreach();
+}
diff --git a/rgo/src/strcpy.c b/rgo/src/strcpy.c
index 4e26312..1d27be3 100644
--- a/rgo/src/strcpy.c
+++ b/rgo/src/strcpy.c
@@ -6,6 +6,8 @@
#include <rgo-priv.h>
+#include <stddef.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_strcpy\n"
@@ -54,13 +56,13 @@ __asm__ (
#endif
);
#else
-sus_typ_usz rgo_strcpy(char const * const sus_restr _in,char * const sus_restr _out) {
- char const * sus_restr inpos = _in;
- char * sus_restr outpos = _out;
+size_t rgo_strcpy(char const * const _in,char * const _out) {
+ char const * inpos = _in;
+ char * outpos = _out;
for (;;++inpos,++outpos) {
char const chr = *inpos;
*outpos = chr;
- if (chr == '\x0') {return (sus_typ_usz)(inpos - _in);}
+ if (chr == '\x0') {return (size_t)(inpos - _in);}
}
sus_unreach();
}
diff --git a/rgo/src/strdup.c b/rgo/src/strdup.c
index 7937658..786de55 100644
--- a/rgo/src/strdup.c
+++ b/rgo/src/strdup.c
@@ -8,4 +8,10 @@
#include <stdlib.h>
-char * rgo_strdup(char const * const __restrict__ _str) {return rgo_memdup(_str,rgo_strlen(_str) + (sus_typ_usz)0x1);}
+char * rgo_strdup(sus_attr_unused char const * const _str) {
+#if !defined(rgo_priv_nostdlib)
+ return rgo_memdup(_str,rgo_strlen(_str) + rgo_typlit_usz(0x1));
+#else
+ return NULL;
+#endif
+}
diff --git a/rgo/src/streq.c b/rgo/src/streq.c
index 7cf2f21..feecf15 100644
--- a/rgo/src/streq.c
+++ b/rgo/src/streq.c
@@ -6,6 +6,9 @@
#include <rgo-priv.h>
+#include <stdbool.h>
+#include <stdint.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_streq\n"
@@ -64,14 +67,14 @@ __asm__ (
#endif
);
#else
-sus_typ_u8 rgo_streq(char const * const sus_restr _lstr,char const * const sus_restr _rstr) {
- char const * sus_restr lpos = _lstr;
- char const * sus_restr rpos = _rstr;
+bool rgo_streq(char const * const _lstr,char const * const _rstr) {
+ char const * lpos = _lstr;
+ char const * rpos = _rstr;
for (;;++lpos,++rpos) {
char const lchr = *lpos;
char const rchr = *rpos;
- sus_likely (lchr != rchr) {return sus_typlit_u8(0x0);}
- if (lchr == '\x0') {return sus_typlit_u8(0x1);}
+ sus_likely (lchr != rchr) {return false;}
+ if (lchr == '\x0') {return true;}
}
sus_unreach();
}
diff --git a/rgo/src/strfill.c b/rgo/src/strfill.c
index 5d6270a..6fe3f48 100644
--- a/rgo/src/strfill.c
+++ b/rgo/src/strfill.c
@@ -8,4 +8,4 @@
#include <stdint.h>
-void rgo_strfill(char * const __restrict__ _str,char const _chr) {rgo_memfill(_str,rgo_strlen(_str),(sus_typ_u8)_chr);}
+void rgo_strfill(char * const _str,char const _chr) {rgo_memfill(_str,rgo_strlen(_str),(uint_least8_t)_chr);}
diff --git a/rgo/src/strlen.c b/rgo/src/strlen.c
index 6ddbf8b..b937fb9 100644
--- a/rgo/src/strlen.c
+++ b/rgo/src/strlen.c
@@ -6,6 +6,8 @@
#include <rgo-priv.h>
+#include <stddef.h>
+
#if defined(rgo_priv_fastimpl)
__asm__ (
".global rgo_strlen\n"
@@ -43,11 +45,11 @@ __asm__ (
#endif
);
#else
-sus_typ_usz rgo_strlen(char const * const sus_restr _str) {
- char const * sus_restr pos = _str;
+size_t rgo_strlen(char const * const _str) {
+ char const * pos = _str;
for (;;++pos) {
char const chr = *pos;
- sus_unlikely (chr == '\x0') {return (sus_typ_usz)(pos - _str);}
+ sus_unlikely (chr == '\x0') {return (size_t)(pos - _str);}
}
sus_unreach();
}
diff --git a/test.c b/test.c
index cf43ecf..4e7e146 100644
--- a/test.c
+++ b/test.c
@@ -1,4 +1,4 @@
-/* cc test.c -Irgo/include -L. -lrgo -otest */
+/* cc -Irgo/include -L. -otest test.c -lrgo */
#include <assert.h>
#include <inttypes.h>
@@ -10,59 +10,59 @@
int main(void) {
fprintf(stderr,"rgo test\n");
fprintf(stderr,"arch: %s\n",sus_archstr);
- fprintf(stderr,"fast: %s\n",rgo_fastimpl() ? "yes" : "no");
+ fprintf(stderr,"fast: %s\n",rgo_fastimpl ? "yes" : "no");
fprintf(stderr,"\n");
{
#undef arrsz
-#define arrsz ((size_t)0x8)
+#define arrsz rgo_typlit_usz(0x8)
uint64_t arr0[arrsz] = {0x0};
- rgo_memfill(arr0,arrsz * sizeof (uint64_t),UINT8_C(0x0));
- fprintf(stderr,"arr0[0]: %" PRIX64 "\n",arr0[(size_t)0x0]);
- fprintf(stderr,"arr0[1]: %" PRIX64 "\n",arr0[(size_t)0x1]);
- fprintf(stderr,"arr0[2]: %" PRIX64 "\n",arr0[(size_t)0x2]);
- fprintf(stderr,"arr0[3]: %" PRIX64 "\n",arr0[(size_t)0x3]);
- fprintf(stderr,"arr0[4]: %" PRIX64 "\n",arr0[(size_t)0x4]);
- fprintf(stderr,"arr0[5]: %" PRIX64 "\n",arr0[(size_t)0x5]);
- fprintf(stderr,"arr0[6]: %" PRIX64 "\n",arr0[(size_t)0x6]);
- assert(arr0[(size_t)0x0] == UINT64_C(0x0));
- assert(arr0[(size_t)0x1] == UINT64_C(0x0));
- assert(arr0[(size_t)0x2] == UINT64_C(0x0));
- assert(arr0[(size_t)0x3] == UINT64_C(0x0));
- assert(arr0[(size_t)0x4] == UINT64_C(0x0));
- assert(arr0[(size_t)0x5] == UINT64_C(0x0));
- assert(arr0[(size_t)0x6] == UINT64_C(0x0));
+ rgo_memfill(arr0,arrsz * sizeof (uint64_t),rgo_typlit_u8(0x0));
+ fprintf(stderr,"arr0[0]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x0)]);
+ fprintf(stderr,"arr0[1]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x1)]);
+ fprintf(stderr,"arr0[2]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x2)]);
+ fprintf(stderr,"arr0[3]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x3)]);
+ fprintf(stderr,"arr0[4]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x4)]);
+ fprintf(stderr,"arr0[5]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x5)]);
+ fprintf(stderr,"arr0[6]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x6)]);
+ assert(arr0[rgo_typlit_usz(0x0)] == rgo_typlit_u40(0x0));
+ assert(arr0[rgo_typlit_usz(0x1)] == rgo_typlit_u40(0x0));
+ assert(arr0[rgo_typlit_usz(0x2)] == rgo_typlit_u40(0x0));
+ assert(arr0[rgo_typlit_usz(0x3)] == rgo_typlit_u40(0x0));
+ assert(arr0[rgo_typlit_usz(0x4)] == rgo_typlit_u40(0x0));
+ assert(arr0[rgo_typlit_usz(0x5)] == rgo_typlit_u40(0x0));
+ assert(arr0[rgo_typlit_usz(0x6)] == rgo_typlit_u40(0x0));
rgo_memfill(arr0,arrsz * sizeof (uint64_t),INT8_C(0x7F));
- fprintf(stderr,"arr0[0]: %" PRIX64 "\n",arr0[(size_t)0x0]);
- fprintf(stderr,"arr0[1]: %" PRIX64 "\n",arr0[(size_t)0x1]);
- fprintf(stderr,"arr0[2]: %" PRIX64 "\n",arr0[(size_t)0x2]);
- fprintf(stderr,"arr0[3]: %" PRIX64 "\n",arr0[(size_t)0x3]);
- fprintf(stderr,"arr0[4]: %" PRIX64 "\n",arr0[(size_t)0x4]);
- fprintf(stderr,"arr0[5]: %" PRIX64 "\n",arr0[(size_t)0x5]);
- fprintf(stderr,"arr0[6]: %" PRIX64 "\n",arr0[(size_t)0x6]);
- assert(arr0[(size_t)0x0] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr0[(size_t)0x1] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr0[(size_t)0x2] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr0[(size_t)0x3] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr0[(size_t)0x4] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr0[(size_t)0x5] == UINT64_C(0x7F7F7F7F7F7F7F7F));
- assert(arr0[(size_t)0x6] == UINT64_C(0x7F7F7F7F7F7F7F7F));
+ fprintf(stderr,"arr0[0]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x0)]);
+ fprintf(stderr,"arr0[1]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x1)]);
+ fprintf(stderr,"arr0[2]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x2)]);
+ fprintf(stderr,"arr0[3]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x3)]);
+ fprintf(stderr,"arr0[4]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x4)]);
+ fprintf(stderr,"arr0[5]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x5)]);
+ fprintf(stderr,"arr0[6]: %" PRIX64 "\n",arr0[rgo_typlit_usz(0x6)]);
+ assert(arr0[rgo_typlit_usz(0x0)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
+ assert(arr0[rgo_typlit_usz(0x1)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
+ assert(arr0[rgo_typlit_usz(0x2)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
+ assert(arr0[rgo_typlit_usz(0x3)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
+ assert(arr0[rgo_typlit_usz(0x4)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
+ assert(arr0[rgo_typlit_usz(0x5)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
+ assert(arr0[rgo_typlit_usz(0x6)] == rgo_typlit_u40(0x7F7F7F7F7F7F7F7F));
uint64_t arr1[arrsz] = {0x0};
rgo_memcpy(arr0,arrsz * sizeof (uint64_t),arr1);
- fprintf(stderr,"arr1[0]: %" PRIX64 "\n",arr1[(size_t)0x0]);
- fprintf(stderr,"arr1[1]: %" PRIX64 "\n",arr1[(size_t)0x1]);
- fprintf(stderr,"arr1[2]: %" PRIX64 "\n",arr1[(size_t)0x2]);
- fprintf(stderr,"arr1[3]: %" PRIX64 "\n",arr1[(size_t)0x3]);
- 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] == 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]);
- sus_typ_u8 const eq = rgo_memeq(arr1,arrsz,arr0);
+ fprintf(stderr,"arr1[0]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x0)]);
+ fprintf(stderr,"arr1[1]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x1)]);
+ fprintf(stderr,"arr1[2]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x2)]);
+ fprintf(stderr,"arr1[3]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x3)]);
+ fprintf(stderr,"arr1[4]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x4)]);
+ fprintf(stderr,"arr1[5]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x5)]);
+ fprintf(stderr,"arr1[6]: %" PRIX64 "\n",arr1[rgo_typlit_usz(0x6)]);
+ assert(arr1[rgo_typlit_usz(0x0)] == arr0[rgo_typlit_usz(0x0)]);
+ assert(arr1[rgo_typlit_usz(0x1)] == arr0[rgo_typlit_usz(0x1)]);
+ assert(arr1[rgo_typlit_usz(0x2)] == arr0[rgo_typlit_usz(0x2)]);
+ assert(arr1[rgo_typlit_usz(0x3)] == arr0[rgo_typlit_usz(0x3)]);
+ assert(arr1[rgo_typlit_usz(0x4)] == arr0[rgo_typlit_usz(0x4)]);
+ assert(arr1[rgo_typlit_usz(0x5)] == arr0[rgo_typlit_usz(0x5)]);
+ assert(arr1[rgo_typlit_usz(0x6)] == arr0[rgo_typlit_usz(0x6)]);
+ bool const eq = rgo_memeq(arr1,arrsz,arr0);
fprintf(stderr,"eq: %u\n",eq);
assert(eq);
#undef arrsz
@@ -73,7 +73,7 @@ int main(void) {
fprintf(stderr,"str0: \"%s\"\n",str0);
size_t const strsz = rgo_strlen(str0);
fprintf(stderr,"strsz: %zX\n",strsz);
- assert(strsz == (size_t)0x1C);
+ assert(strsz == rgo_typlit_usz(0x1C));
}
fprintf(stderr,"\n");
{
@@ -82,23 +82,23 @@ int main(void) {
size_t len = rgo_strlen(str);
fprintf(stderr,"len: %zX\n",len);
size_t pos0 = rgo_fndchr(str,' ');
- size_t pos1 = rgo_fndbyte(str,len,(sus_typ_u8)' ');
+ size_t pos1 = rgo_fndbyte(str,len,(uint_least8_t)' ');
fprintf(stderr,"pos0: %zX\n",pos0);
fprintf(stderr,"pos1: %zX\n",pos1);
- assert(pos0 == (size_t)0x2);
+ assert(pos0 == rgo_typlit_usz(0x2));
assert(pos1 == pos0);
- str += pos0 + (size_t)0x1;
+ str += pos0 + rgo_typlit_usz(0x1);
len = rgo_strlen(str);
pos0 = rgo_fndchr(str,' ');
- pos1 = rgo_fndbyte(str,len,(sus_typ_u8)' ');
+ pos1 = rgo_fndbyte(str,len,(uint_least8_t)' ');
fprintf(stderr,"pos0: %zX\n",pos0);
fprintf(stderr,"pos1: %zX\n",pos1);
- assert(pos0 == (size_t)0x2);
+ assert(pos0 == rgo_typlit_usz(0x2));
assert(pos1 == pos0);
- str += pos0 + (size_t)0x1;
+ str += pos0 + rgo_typlit_usz(0x1);
len = rgo_strlen(str);
pos0 = rgo_fndchr(str,' ');
- pos1 = rgo_fndbyte(str,len,(sus_typ_u8)' ');
+ pos1 = rgo_fndbyte(str,len,(uint_least8_t)' ');
fprintf(stderr,"pos0: %zX\n",pos0);
fprintf(stderr,"pos1: %zX\n",pos1);
assert(pos0 == (size_t)-0x1);
@@ -112,9 +112,9 @@ int main(void) {
fprintf(stderr,"str1: \"%s\"\n",str1);
char const str2[] = "I don't know you!";
fprintf(stderr,"str2: \"%s\"\n",str2);
- sus_typ_u8 const cmp0 = rgo_streq(str0,str1);
- sus_typ_u8 const cmp1 = rgo_streq(str0,str2);
- sus_typ_u8 const cmp2 = rgo_streq(str1,str2);
+ bool const cmp0 = rgo_streq(str0,str1);
+ bool const cmp1 = rgo_streq(str0,str2);
+ bool const cmp2 = rgo_streq(str1,str2);
fprintf(stderr,"cmp0: %u\n",cmp0);
fprintf(stderr,"cmp1: %u\n",cmp1);
fprintf(stderr,"cmp2: %u\n",cmp2);
@@ -127,10 +127,36 @@ int main(void) {
char const str0[] = "What in the world are you doing?";
fprintf(stderr,"str0: \"%s\"\n",str0);
char str1[sizeof (str0)];
- assert(rgo_strcpy(str0,str1) == (size_t)0x20);
+ assert(rgo_strcpy(str0,str1) == rgo_typlit_usz(0x20));
fprintf(stderr,"str1: \"%s\"\n",str1);
assert(rgo_streq(str0,str1));
}
fprintf(stderr,"\n");
+ {
+ char const str0[] = "Oej Moej Goejd";
+ char const str1[] = "Er jeg egentlig okay med AWP?";
+ fprintf(stderr,"str0: \"%s\"\n",str0);
+ fprintf(stderr,"str1: \"%s\"\n",str1);
+ int_least8_t const cmp0 = rgo_strcmp(str0,str1);
+ int_least8_t const cmp1 = rgo_strcmp(str0,str0);
+ int_least8_t const cmp2 = rgo_strcmp(str1,str0);
+ size_t const leastsz = sizeof (str0) < sizeof (str1) ? sizeof (str0) : sizeof (str1);
+ int_least8_t const cmp3 = rgo_memcmp(str0,leastsz,str1);
+ int_least8_t const cmp4 = rgo_memcmp(str0,leastsz,str0);
+ int_least8_t const cmp5 = rgo_memcmp(str1,leastsz,str0);
+ fprintf(stderr,"cmp0: %i\n",cmp0);
+ fprintf(stderr,"cmp1: %i\n",cmp1);
+ fprintf(stderr,"cmp2: %i\n",cmp2);
+ fprintf(stderr,"cmp3: %i\n",cmp3);
+ fprintf(stderr,"cmp4: %i\n",cmp4);
+ fprintf(stderr,"cmp5: %i\n",cmp5);
+ assert(cmp0 > rgo_typlit_s8(0x0));
+ assert(cmp1 == rgo_typlit_s8(0x0));
+ assert(cmp2 < rgo_typlit_s8(0x0));
+ assert(cmp3 > rgo_typlit_s8(0x0));
+ assert(cmp4 == rgo_typlit_s8(0x0));
+ assert(cmp5 < rgo_typlit_s8(0x0));
+ }
+ fprintf(stderr,"\n");
printf("All tests have passed!\n");
}