aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-11-11 22:24:54 +0000
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-11-11 23:15:15 +0000
commite281c39d24793ea5793b0eabdd684c5e12ea77fe (patch)
tree1f1debed802fcc1764d33b05d21d7935bead3d19
parentde8db70103b5ba472fa6e3992e4c7ebb6dcae153 (diff)
downloadsst-e281c39d24793ea5793b0eabdd684c5e12ea77fe.tar.gz
sst-e281c39d24793ea5793b0eabdd684c5e12ea77fe.zip
Add a mem_copy_fixed and mem_set_fixed to mem.h
Probably self-explanatory. I was finding more use cases for the __builtin_memcpy_inline thing but boy is that ugly.
-rw-r--r--src/mem.h22
-rw-r--r--src/speedrun.c3
-rw-r--r--src/sst.c6
3 files changed, 25 insertions, 6 deletions
diff --git a/src/mem.h b/src/mem.h
index ae33092..553d390 100644
--- a/src/mem.h
+++ b/src/mem.h
@@ -223,6 +223,28 @@ static forceinline int mem_cmp(const void *restrict x, const void *restrict y,
#endif
}
+/*
+ * Copies a small fixed-size chunk of memory using some appropriate
+ * compiler-chosen arrangement of move instructions, without calling any
+ * functions. Length must be a compile-time constant.
+ */
+#ifdef __clang__
+#define mem_copy_fixed __builtin_memcpy_inline
+#else
+#define mem_copy_fixed mem_copy // meh
+#endif
+
+/*
+ * Sets a small fixed-size chunk of memory using some appropriate
+ * compiler-chosen arrangement of instructions, without calling any
+ * functions. Length and value must be compile-time constants.
+ */
+#ifdef __clang__
+#define mem_set_fixed __builtin_memcpy_inline
+#else
+#define mem_set_fixed mem_set // meh
+#endif
+
#endif
// vi: sw=4 ts=4 noet tw=80 cc=80
diff --git a/src/speedrun.c b/src/speedrun.c
index a0849dd..87942e2 100644
--- a/src/speedrun.c
+++ b/src/speedrun.c
@@ -186,8 +186,7 @@ DEF_CCMD_HERE(sst_speedrun_start, "Start recording demos for a speedrun", 0) {
else {
nameend = pathsz + namelen;
}
- __builtin_memcpy_inline(path + nameend, OS_LIT(".dem"),
- sizeof(OS_LIT(".dem")));
+ mem_copy_fixed(path + nameend, OS_LIT(".dem"), sizeof(OS_LIT(".dem")));
// check for an existing demo file with this name: if we started
// recording, then stopped, then started again in quick succession, we
// could have one. in this scenario, append a 2-digit counter to the end
diff --git a/src/sst.c b/src/sst.c
index ab78b9c..4cdad5d 100644
--- a/src/sst.c
+++ b/src/sst.c
@@ -197,11 +197,9 @@ c: mem_copy(r, p + slash + 1, rellen);
if_cold (f == -1) { errmsg_errorsys("couldn't open %" fS, path); return; }
#ifdef _WIN32
char buf[19 + PATH_MAX];
- // 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);
+ mem_copy_fixed(buf, "Plugin { file \"", 15);
for (int i = 0; i < rellen; ++i) buf[i + 15] = relpath[i];
- __builtin_memcpy_inline(buf + 15 + rellen, "\" }\n", 4);
+ mem_copy_fixed(buf + 15 + rellen, "\" }\n", 4);
if_cold (os_write(f, buf, rellen + 19) == -1) { // blegh
#else
struct iovec iov[3] = {