Phase TLS-UNIFY-3+: Refactoring - Unified ENV gates for C6 ULTRA
Consolidate C6 ULTRA ENV gate functions: - tiny_c6_ultra_intrusive_env_box.h now contains both: - tiny_c6_ultra_free_enabled() - C6 ULTRA routing (policy gate) - tiny_c6_ultra_intrusive_enabled() - intrusive LIFO mode (TLS optimization) - Simplified ENV gate management with clear separation of concerns Removes code duplication by centralizing environment checks in single header. Performance verified: ENV_OFF=56.4 Mop/s, ENV_ON=57.6 Mop/s (parity maintained) Note: Avoided macro-based segment learning consolidation (C4/C5/C6) as it would hinder compiler optimizations. Current inline approach is optimal. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@ -1,7 +1,8 @@
|
||||
// tiny_c6_ultra_intrusive_env_box.h - Phase TLS-UNIFY-3: C6 Intrusive FL ENV gate
|
||||
// tiny_c6_ultra_intrusive_env_box.h - Phase TLS-UNIFY-3+: C6 ULTRA ENV gates
|
||||
//
|
||||
// ENV: HAKMEM_TINY_C6_ULTRA_INTRUSIVE_FL (default OFF)
|
||||
// Separate from existing HAKMEM_TINY_C6_ULTRA_FREE_ENABLED
|
||||
// Unified ENV gates for C6 ULTRA functionality:
|
||||
// - HAKMEM_TINY_C6_ULTRA_FREE_ENABLED: Route C6 to ULTRA path (global policy)
|
||||
// - HAKMEM_TINY_C6_ULTRA_INTRUSIVE_FL: Use intrusive LIFO instead of array (TLS optimization)
|
||||
//
|
||||
#ifndef HAKMEM_TINY_C6_ULTRA_INTRUSIVE_ENV_BOX_H
|
||||
#define HAKMEM_TINY_C6_ULTRA_INTRUSIVE_ENV_BOX_H
|
||||
@ -9,10 +10,23 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// Cached ENV gate (read once on first call)
|
||||
// C6 ULTRA routing (policy-level gate)
|
||||
// Controls whether C6 allocations are routed to ULTRA path at all
|
||||
static inline bool tiny_c6_ultra_free_enabled(void) {
|
||||
static int g_enabled = -1;
|
||||
if (__builtin_expect(g_enabled == -1, 0)) {
|
||||
const char* e = getenv("HAKMEM_TINY_C6_ULTRA_FREE_ENABLED");
|
||||
g_enabled = (e && *e && *e != '0') ? 1 : 0;
|
||||
}
|
||||
return g_enabled;
|
||||
}
|
||||
|
||||
// C6 intrusive LIFO mode (TLS optimization within ULTRA path)
|
||||
// When enabled: use single-linked LIFO (intrusive) instead of array magazine
|
||||
// Default: OFF (array magazine for compatibility)
|
||||
static inline bool tiny_c6_ultra_intrusive_enabled(void) {
|
||||
static int g_enabled = -1; // -1 = not initialized
|
||||
if (g_enabled < 0) {
|
||||
static int g_enabled = -1;
|
||||
if (__builtin_expect(g_enabled == -1, 0)) {
|
||||
const char* env = getenv("HAKMEM_TINY_C6_ULTRA_INTRUSIVE_FL");
|
||||
g_enabled = (env && env[0] == '1') ? 1 : 0;
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ void tiny_ultra_tls_push(uint8_t class_idx, void* base) {
|
||||
uintptr_t addr = (uintptr_t)base;
|
||||
|
||||
switch (class_idx) {
|
||||
case 4:
|
||||
case 4: {
|
||||
// Learn segment on first C4 free
|
||||
if (unlikely(ctx->c4_seg_base == 0)) {
|
||||
SuperSlab* ss = ss_fast_lookup(base);
|
||||
@ -124,8 +124,9 @@ void tiny_ultra_tls_push(uint8_t class_idx, void* base) {
|
||||
}
|
||||
tiny_ultra_tls_push_slow(class_idx, base);
|
||||
break;
|
||||
}
|
||||
|
||||
case 5:
|
||||
case 5: {
|
||||
// Learn segment on first C5 free
|
||||
if (unlikely(ctx->c5_seg_base == 0)) {
|
||||
SuperSlab* ss = ss_fast_lookup(base);
|
||||
@ -144,8 +145,9 @@ void tiny_ultra_tls_push(uint8_t class_idx, void* base) {
|
||||
}
|
||||
tiny_ultra_tls_push_slow(class_idx, base);
|
||||
break;
|
||||
}
|
||||
|
||||
case 6:
|
||||
case 6: {
|
||||
// Learn segment on first C6 free (common for both modes)
|
||||
if (unlikely(ctx->c6_seg_base == 0)) {
|
||||
SuperSlab* ss = ss_fast_lookup(base);
|
||||
@ -180,6 +182,7 @@ void tiny_ultra_tls_push(uint8_t class_idx, void* base) {
|
||||
}
|
||||
tiny_ultra_tls_push_slow(class_idx, base);
|
||||
break;
|
||||
}
|
||||
|
||||
case 7: {
|
||||
// C7 uses separate TinyC7Ultra box (not unified)
|
||||
|
||||
@ -75,4 +75,5 @@ static inline int tiny_ultra_tls_unified_enabled(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif // HAKMEM_TINY_ULTRA_TLS_BOX_H
|
||||
|
||||
Reference in New Issue
Block a user