aboutsummaryrefslogtreecommitdiff
path: root/src/langext.h
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-08-03 16:09:42 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-08-03 16:09:42 +0100
commit69f34b359c0ec0d4517050fe274883421c4c119b (patch)
tree44bf4ce549129ddf83371d3c6abbe8e2bf6a7869 /src/langext.h
parentb11cf48853bc4eccde60bc82180025f0797fa823 (diff)
downloadsst-69f34b359c0ec0d4517050fe274883421c4c119b.tar.gz
sst-69f34b359c0ec0d4517050fe274883421c4c119b.zip
Tidy up some extensions and remove some ifdefs
Since this codebase is already extremely nonportable, I've decided to relax the obsessive ifdef-else-error usage around all the extensions. From now on, if there's no alternative to using an extension, we can just use that extension. If it's possible to do something in a relatively portable way, we can still try to do that in order to make the code somewhat reusable, in contexts where that makes sense. I also decided to use langext.h for naked functions and tail calls. If that's used in another codebase build with a different compiler, those just won't work, but that's fine. The benefit is really just that there's less ceremony in places where those are used, because it's likely there'll be a few more such places in the future, and it gets annoying reading all the double-underscore stuff all over the place. I still kind of want to do something about all the _WIN32 ifdefs too, but I've realised that doing so will lead to almost nothing actually being built on Linux. Then again, none of it currently runs on Linux so I guess that's a moot point. Will worry about it later, anyway.
Diffstat (limited to 'src/langext.h')
-rw-r--r--src/langext.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/langext.h b/src/langext.h
index d2d9a23..0624b71 100644
--- a/src/langext.h
+++ b/src/langext.h
@@ -17,6 +17,7 @@
#define unreachable __builtin_unreachable()
#define assume(x) ((void)(!!(x) || (unreachable, 0)))
#define cold __attribute((__cold__, __noinline__))
+#define asm_only __attribute((__naked__)) // N.B.: may not actually work in GCC?
#else
#define if_hot(x) if (x)
#define if_cold(x) if (x)
@@ -25,11 +26,13 @@
#define unreachable __assume(0)
#define assume(x) ((void)(__assume(x), 0))
#define cold __declspec(noinline)
+#define asm_only __declspec(naked)
#else
static inline _Noreturn void _invoke_ub() {}
#define unreachable (_invoke_ub())
#define assume(x) ((void)(!!(x) || (_invoke_ub(), 0)))
#define cold
+//#define asm_only // Can't use this without Clang/GCC/MSVC. Too bad.
#endif
#endif
@@ -63,6 +66,17 @@ static inline _Noreturn void _invoke_ub() {}
#endif
#endif
+#ifdef __clang__
+#define tailcall \
+ /* Clang forces us to use void return and THEN warns about it ._. */ \
+ _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wpedantic\"") \
+ __attribute((musttail)) return \
+ _Pragma("clang diagnostic pop")
+#else
+//#define tailcall // Can't use this without Clang.
+#endif
+
#endif
// vi: sw=4 ts=4 noet tw=80 cc=80