Commit 8512198b

8512198bc794Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified

Description

Mark sp_raise_cls noreturn+cold; add hot-cold hint macros

sp_raise_cls always longjmps to the nearest handler or exit(1)s -- it never returns to its caller. Annotating it noreturn+cold lets the C compiler drop the dead return-path code at the hundreds of inline call sites (divide-by-zero, index, frozen, type checks) and pull the raise machinery off the hot path's i-cache footprint.

Add SP_LIKELY/SP_UNLIKELY/SP_COLD/SP_NOINLINE/SP_NORETURN to sp_types.h (no-ops outside GCC/clang) as the shared spelling for these hints -- a static stand-in for what PGO derives from a profile. sp_types.h is included before the first sp_raise_cls declaration, so the attribute is visible at every call site.

optcarrot checksum 59662 unchanged.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
8512198bc794
Parent
34d320b057a8

lib/sp_runtime.hmodifiedView file

@@ -97,7 +97,7 @@
9797 `a / 0`, `a % 0`, `a.divmod(0)`, `a.ceildiv(0)`, and `a.pow(e, 0)` all
9898 raise ZeroDivisionError instead of triggering C undefined behaviour
9999 (SIGFPE on x86) or silently returning 0. */
100-void sp_raise_cls(const char *cls, const char *msg);
100+SP_NORETURN SP_COLD void sp_raise_cls(const char *cls, const char *msg);
101101
102102 static inline mrb_int sp_idiv(mrb_int a, mrb_int b) {
103103 if (b == 0) sp_raise_cls("ZeroDivisionError", "divided by 0");
@@ -241,7 +241,7 @@
241241
242242 /* Forward decls for helpers used across this header (and by the
243243 string->number parsers that now live in libspinel_rt.a). */
244-void sp_raise_cls(const char *cls, const char *msg);
244+SP_NORETURN SP_COLD void sp_raise_cls(const char *cls, const char *msg);
245245 const char *sp_sprintf(const char *fmt, ...);
246246
247247 /* String -> number parsers now live in libspinel_rt.a (lib/sp_core.c). */
@@ -3632,7 +3632,7 @@
36323632 #endif
36333633 }
36343634
3635-void sp_raise_cls(const char *cls, const char *msg) {
3635+SP_NORETURN SP_COLD void sp_raise_cls(const char *cls, const char *msg) {
36363636 #if SP_BT_AVAILABLE
36373637 if (sp_bt_enabled) sp_bt_n = backtrace(sp_bt_buf, 256);
36383638 #endif