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/demorec.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/demorec.c') diff --git a/src/demorec.c b/src/demorec.c index 6070bee..7a2c798 100644 --- a/src/demorec.c +++ b/src/demorec.c @@ -124,17 +124,26 @@ DEF_CCMD_COMPAT_HOOK(record) { int gdlen = os_strlen(gameinfo_gamedir); if (gdlen + 1 + argdirlen < PATH_MAX) { // if not, too bad os_char dir[PATH_MAX], *q = dir; - memcpy(q, gameinfo_gamedir, gdlen * sizeof(*gameinfo_gamedir)); + mem_copy(q, gameinfo_gamedir, gdlen * sizeof(*gameinfo_gamedir)); q += gdlen; *q++ = OS_LIT('/'); - // ascii->wtf16 (probably turns into memcpy() on linux) +#ifdef _WIN32 + // ascii->wtf16 for (const char *p = arg; p - arg < argdirlen; ++p, ++q) { *q = (uchar)*p; } +#else + // we're -ffreestanding, so don't rely on the compiler turning + // the above into a memcpy() call automatically. + mem_copy(q, arg, argdirlen); + q += argdirlen; +#endif *q = OS_LIT('\0'); // this is pretty ugly. the error cases would be way tidier if // we could use open(O_DIRECTORY), but that's not a thing on // windows, of course. + // TODO(opt): actually, yes it is, as a more low-level NT thing. + // revisit, if/when we can be bothered. (not exactly crucial) struct os_stat s; static const char *const errpfx = "ERROR: can't record demo: "; if (os_stat(dir, &s) == -1) { -- cgit v1.2.3-54-g00ecf