diff options
| author | 2025-12-27 03:05:05 +0000 | |
|---|---|---|
| committer | 2026-02-16 19:11:24 +0000 | |
| commit | 8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45 (patch) | |
| tree | 63a8ea6f645b997fd7943a58a002e66244fa49ac /src/sst.c | |
| parent | e7943fb834cbcaec585ed68e67b5f17ceda504f7 (diff) | |
| download | sst-8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45.tar.gz sst-8d4b47298b6c9eeb9a3f79a5b80d894f80ed4a45.zip | |
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.
Diffstat (limited to 'src/sst.c')
| -rw-r--r-- | src/sst.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -180,7 +180,7 @@ DEF_CCMD_HERE(sst_autoload_enable, "Register SST to load on game startup", 0) { } } } -c: memcpy(r, p + slash + 1, rellen); +c: mem_copy(r, p + slash + 1, rellen); #endif int len = os_strlen(gameinfo_gamedir); if (len + ssizeof("/addons/" VDFBASENAME ".vdf") > countof(path)) { @@ -200,9 +200,11 @@ c: memcpy(r, p + slash + 1, rellen); if_cold (f == -1) { errmsg_errorsys("couldn't open %" fS, path); return; } #ifdef _WIN32 char buf[19 + PATH_MAX]; - memcpy(buf, "Plugin { file \"", 15); + // XXX: with actual calls to memcpy gone, we need this builtin to produce 4 + // 4-byte movs from this string; can we expose this in a less hideous way? + __builtin_memcpy_inline(buf, "Plugin { file \"", 15); for (int i = 0; i < rellen; ++i) buf[i + 15] = relpath[i]; - memcpy(buf + 15 + rellen, "\" }\n", 4); + __builtin_memcpy_inline(buf + 15 + rellen, "\" }\n", 4); if_cold (os_write(f, buf, rellen + 19) == -1) { // blegh #else struct iovec iov[3] = { |
