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
`a / 0`, `a % 0`, `a.divmod(0)`, `a.ceildiv(0)`, and `a.pow(e, 0)` all raise ZeroDivisionError instead of triggering C undefined behaviour (SIGFPE on x86) or silently returning 0. */void sp_raise_cls(const char *cls, const char *msg);SP_NORETURN SP_COLD void sp_raise_cls(const char *cls, const char *msg);static inline mrb_int sp_idiv(mrb_int a, mrb_int b) { if (b == 0) sp_raise_cls("ZeroDivisionError", "divided by 0");/* Forward decls for helpers used across this header (and by the string->number parsers that now live in libspinel_rt.a). */void sp_raise_cls(const char *cls, const char *msg);SP_NORETURN SP_COLD void sp_raise_cls(const char *cls, const char *msg);const char *sp_sprintf(const char *fmt, ...);/* String -> number parsers now live in libspinel_rt.a (lib/sp_core.c). */#endif}void sp_raise_cls(const char *cls, const char *msg) {SP_NORETURN SP_COLD void sp_raise_cls(const char *cls, const char *msg) {#if SP_BT_AVAILABLE if (sp_bt_enabled) sp_bt_n = backtrace(sp_bt_buf, 256);#endiflib/sp_types.hmodifiedView file
Loading diff…