summaryrefslogtreecommitdiff
path: root/rgo/src
diff options
context:
space:
mode:
Diffstat (limited to 'rgo/src')
-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
14 files changed, 124 insertions, 48 deletions
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();
}