From 8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 27 Dec 2025 03:05:05 +0000 Subject: Do away with memcpy/memset/memcmp Now everything is either explicitly a rep thing, or explicitly some other small run of reasonably efficient instructions. No library calls or function call overhead of any kind. Code size remains nice and small. Ban a few other bad libc functions while we're at it. More can be added later if we decide that's a useful idea. This will require some discipline and workarounds to cope with Clang's tendency to shove mem* calls in places you don't want them even when you tell it not to. Well, c'est la vie. I'm a little nervous that the __builtin_memmove() usage in shuntvars() could still one day emit actual library calls. It appears we're not importing memmove() from anywhere at the moment, though. So I guess it's good enough for now. Also I had to get rid of alloca() in con_.c but that was kind of bad anyway, so that's fine. --- src/os.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'src/os.c') diff --git a/src/os.c b/src/os.c index 5fb84bc..2bc0e45 100644 --- a/src/os.c +++ b/src/os.c @@ -32,6 +32,22 @@ #include "intdefs.h" #include "langext.h" +#include "os.h" + +// HACK: host tools link in os.c as well. if cross-compiling, we can't use our +// inline asm mem_copy implementation. just use memcpy if not on 32-bit x86. +// the host tools will have the C runtime available, unlike SST itself +#if defined(__i386__) || defined(_M_IX86) +#include "mem.h" +#endif + +void os_spancopy(os_char *restrict dest, const os_char *restrict src, int n) { +#if defined(__i386__) || defined(_M_IX86) + mem_copy(dest, src, n * sizeof(os_char)); +#else + memcpy(dest, src, n * sizeof(os_char)); +#endif +} #ifdef _WIN32 @@ -196,7 +212,7 @@ int os_dlfile(void *lib, char *buf, int sz) { struct link_map *lm = lib; int ssz = strlen(lm->l_name) + 1; if_cold (ssz > sz) { errno = ENAMETOOLONG; return -1; } - memcpy(buf, lm->l_name, ssz); + mem_copy(buf, lm->l_name, ssz); return ssz; } #endif -- cgit v1.2.3-54-g00ecf