Phase 7-Step8: Replace SFC/HEAP_V2/ULTRA_SLIM runtime checks with config macros
**Goal**: Complete dead code elimination infrastructure for all runtime checks **Changes**: 1. core/box/tiny_front_config_box.h: - Rename sfc_cascade_enabled() → tiny_sfc_enabled() (avoid name collision) - Update TINY_FRONT_SFC_ENABLED macro to use tiny_sfc_enabled() 2. core/tiny_alloc_fast.inc.h (5 locations): - Line 274: tiny_heap_v2_alloc_by_class() - use TINY_FRONT_HEAP_V2_ENABLED - Line 431: SFC TLS cache init - use TINY_FRONT_SFC_ENABLED - Line 678: SFC cascade check - use TINY_FRONT_SFC_ENABLED - Line 740: Ultra SLIM debug check - use TINY_FRONT_ULTRA_SLIM_ENABLED 3. core/hakmem_tiny_free.inc (1 location): - Line 233: Heap V2 free path - use TINY_FRONT_HEAP_V2_ENABLED **Performance**: 79.5M ops/s (maintained, -0.4M vs Step 7, within noise) - Normal mode: Neutral (runtime checks preserved) - PGO mode: Ready for dead code elimination **Total Runtime Checks Replaced (Phase 7)**: - ✅ TINY_FRONT_FASTCACHE_ENABLED: 3 locations (Step 4-6) - ✅ TINY_FRONT_TLS_SLL_ENABLED: 7 locations (Step 7) - ✅ TINY_FRONT_SFC_ENABLED: 2 locations (Step 8) - ✅ TINY_FRONT_HEAP_V2_ENABLED: 2 locations (Step 8) - ✅ TINY_FRONT_ULTRA_SLIM_ENABLED: 1 location (Step 8) **Total**: 15 runtime checks → config macros **PGO Mode Expected Benefit**: - Eliminate 15 runtime checks across hot paths - Reduce branch mispredictions - Smaller code size (dead code removed by compiler) - Better instruction cache locality **Design Complete**: Config Box as single entry point for all Tiny Front policy - Unified macro interface for all feature toggles - Include order independent (static inline wrappers) - Dual-mode support (PGO compile-time vs normal runtime) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -270,7 +270,8 @@ static inline void* tiny_heap_v2_alloc_by_class(int class_idx) {
|
||||
// FIX: Ensure TLS is initialized before first magazine access
|
||||
tiny_heap_v2_ensure_init();
|
||||
if (class_idx < 0 || class_idx > 3) return NULL;
|
||||
if (!tiny_heap_v2_enabled()) return NULL;
|
||||
// Phase 7-Step8: Use config macro for dead code elimination in PGO mode
|
||||
if (!TINY_FRONT_HEAP_V2_ENABLED) return NULL;
|
||||
if (!tiny_heap_v2_class_enabled(class_idx)) return NULL;
|
||||
|
||||
TinyHeapV2Mag* mag = &g_tiny_heap_v2_mag[class_idx];
|
||||
@ -424,11 +425,11 @@ static inline void* tiny_alloc_fast_pop(int class_idx) {
|
||||
}
|
||||
|
||||
// Box 5-NEW: Layer 0 - Try SFC first (if enabled)
|
||||
// Cache g_sfc_enabled in TLS to avoid global load on every allocation
|
||||
// Phase 7-Step8: Use config macro for dead code elimination in PGO mode
|
||||
static __thread int sfc_check_done = 0;
|
||||
static __thread int sfc_is_enabled = 0;
|
||||
if (__builtin_expect(!sfc_check_done, 0)) {
|
||||
sfc_is_enabled = g_sfc_enabled;
|
||||
sfc_is_enabled = TINY_FRONT_SFC_ENABLED;
|
||||
sfc_check_done = 1;
|
||||
}
|
||||
|
||||
@ -674,7 +675,8 @@ static inline int tiny_alloc_fast_refill(int class_idx) {
|
||||
}
|
||||
|
||||
// Only cascade if explicitly enabled AND we have refilled blocks in SLL
|
||||
if (sfc_cascade_enabled && g_sfc_enabled && refilled > 0) {
|
||||
// Phase 7-Step8: Use config macro for dead code elimination in PGO mode
|
||||
if (sfc_cascade_enabled && TINY_FRONT_SFC_ENABLED && refilled > 0) {
|
||||
// Transfer half of refilled blocks to SFC (keep half in SLL for future)
|
||||
int sfc_target = refilled / 2;
|
||||
if (sfc_target > 0) {
|
||||
@ -734,7 +736,8 @@ static inline void* tiny_alloc_fast(size_t size) {
|
||||
#if !HAKMEM_BUILD_RELEASE
|
||||
static __thread int debug_checked = 0;
|
||||
if (!debug_checked) {
|
||||
int enabled = ultra_slim_mode_enabled();
|
||||
// Phase 7-Step8: Use config macro for dead code elimination in PGO mode
|
||||
int enabled = TINY_FRONT_ULTRA_SLIM_ENABLED;
|
||||
if (enabled) {
|
||||
fprintf(stderr, "[TINY_ALLOC_FAST] Ultra SLIM gate: ENABLED (will use 4-layer path)\n");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user