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/hexcolour.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/hexcolour.c') diff --git a/src/hexcolour.c b/src/hexcolour.c index f5d2af1..80186aa 100644 --- a/src/hexcolour.c +++ b/src/hexcolour.c @@ -14,9 +14,8 @@ * PERFORMANCE OF THIS SOFTWARE. */ -#include - #include "intdefs.h" +#include "mem.h" void hexcolour_rgb(uchar out[static 4], const char *s) { const char *p = s; @@ -30,7 +29,7 @@ void hexcolour_rgb(uchar out[static 4], const char *s) { else { // screw it, just fall back on white, I guess. // note: this also handles *p == '\0' so we don't overrun the string - memset(out, 255, 4); // should be a single mov + mem_storeu32(out, -1u); // 255, 255, 255, 255 return; } // repetitive unrolled nonsense @@ -41,7 +40,7 @@ void hexcolour_rgb(uchar out[static 4], const char *s) { *q |= 10 + (*p++ | 32) - 'a'; } else { - memset(out, 255, 4); // should be a single mov + mem_storeu32(out, -1u); // 255, 255, 255, 255 return; } } @@ -65,7 +64,7 @@ void hexcolour_rgba(uchar out[static 4], const char *s) { out[3] = 255; return; } - memset(out, 255, 4); + mem_storeu32(out, -1u); // 255, 255, 255, 255 return; } // even more repetitive unrolled nonsense @@ -76,7 +75,7 @@ void hexcolour_rgba(uchar out[static 4], const char *s) { *q |= 10 + (*p++ | 32) - 'a'; } else { - memset(out, 255, 4); + mem_storeu32(out, -1u); // 255, 255, 255, 255 return; } } -- cgit v1.2.3-54-g00ecf