2025-11-05 12:31:14 +09:00
|
|
|
// hakmem_build_flags.h - Centralized compile-time feature switches
|
|
|
|
|
// Purpose: Define all build-time toggles in one place with safe defaults.
|
|
|
|
|
// Usage: Include from common public headers (e.g., hakmem.h / hakmem_tiny.h).
|
|
|
|
|
|
|
|
|
|
#ifndef HAKMEM_BUILD_FLAGS_H
|
|
|
|
|
#define HAKMEM_BUILD_FLAGS_H
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Release/debug detection
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// HAKMEM_BUILD_RELEASE: 1 in release-like builds, 0 otherwise
|
|
|
|
|
#ifndef HAKMEM_BUILD_RELEASE
|
|
|
|
|
# if defined(NDEBUG)
|
|
|
|
|
# define HAKMEM_BUILD_RELEASE 1
|
|
|
|
|
# else
|
|
|
|
|
# define HAKMEM_BUILD_RELEASE 0
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Instrumentation & counters (compile-time)
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Enable lightweight path/debug counters (compiled out when 0)
|
|
|
|
|
#ifndef HAKMEM_DEBUG_COUNTERS
|
2025-11-07 01:27:04 +09:00
|
|
|
# define HAKMEM_DEBUG_COUNTERS 1
|
2025-11-05 12:31:14 +09:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Enable extended memory profiling (compiled out when 0)
|
|
|
|
|
#ifndef HAKMEM_DEBUG_MEMORY
|
|
|
|
|
# define HAKMEM_DEBUG_MEMORY 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Tiny refill optimization helpers (header-only)
|
|
|
|
|
#ifndef HAKMEM_TINY_REFILL_OPT
|
|
|
|
|
# define HAKMEM_TINY_REFILL_OPT 1
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Batch refill P0 (can be toggled for A/B)
|
|
|
|
|
#ifndef HAKMEM_TINY_P0_BATCH_REFILL
|
2025-11-11 10:00:36 +09:00
|
|
|
# define HAKMEM_TINY_P0_BATCH_REFILL 0
|
2025-11-05 12:31:14 +09:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Box refactor (Phase 6-1.7) — usually injected from build system
|
|
|
|
|
#ifndef HAKMEM_TINY_PHASE6_BOX_REFACTOR
|
|
|
|
|
# define HAKMEM_TINY_PHASE6_BOX_REFACTOR 1
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-08 12:54:52 +09:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Phase 7: Region-ID Direct Lookup (Header-based optimization)
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Phase 7 Task 1: Header-based class_idx for O(1) free
|
|
|
|
|
// Default: OFF (enable after full validation in Task 5)
|
|
|
|
|
// Build: make HEADER_CLASSIDX=1 or make phase7
|
|
|
|
|
#ifndef HAKMEM_TINY_HEADER_CLASSIDX
|
2025-11-11 10:00:36 +09:00
|
|
|
# define HAKMEM_TINY_HEADER_CLASSIDX 1
|
2025-11-08 12:54:52 +09:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Phase 7 Task 2: Aggressive inline TLS cache access
|
|
|
|
|
// Default: OFF (enable after full validation in Task 5)
|
|
|
|
|
// Build: make AGGRESSIVE_INLINE=1 or make phase7
|
|
|
|
|
// Requires: HAKMEM_TINY_HEADER_CLASSIDX=1
|
|
|
|
|
#ifndef HAKMEM_TINY_AGGRESSIVE_INLINE
|
|
|
|
|
# define HAKMEM_TINY_AGGRESSIVE_INLINE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Phase 7 Task 3: Pre-warm TLS cache at init
|
|
|
|
|
// Default: OFF (enable after implementation)
|
|
|
|
|
// Build: make PREWARM_TLS=1 or make phase7
|
|
|
|
|
#ifndef HAKMEM_TINY_PREWARM_TLS
|
|
|
|
|
# define HAKMEM_TINY_PREWARM_TLS 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-09 11:50:18 +09:00
|
|
|
// Runtime verbosity (printf-heavy diagnostics). Keep OFF for benches.
|
|
|
|
|
#ifndef HAKMEM_DEBUG_VERBOSE
|
|
|
|
|
# define HAKMEM_DEBUG_VERBOSE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Tiny/Mid safety checks on free path (mincore header validation).
|
|
|
|
|
// 0 = performance (boundary-only), 1 = strict (mincore for all)
|
|
|
|
|
#ifndef HAKMEM_TINY_SAFE_FREE
|
|
|
|
|
# define HAKMEM_TINY_SAFE_FREE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-08 12:54:52 +09:00
|
|
|
// Phase 7 refill count defaults (tunable via env vars)
|
|
|
|
|
// HAKMEM_TINY_REFILL_COUNT: global default (default: 16)
|
|
|
|
|
// HAKMEM_TINY_REFILL_COUNT_HOT: class 0-3 (default: 16)
|
|
|
|
|
// HAKMEM_TINY_REFILL_COUNT_MID: class 4-7 (default: 16)
|
|
|
|
|
#ifndef HAKMEM_TINY_REFILL_DEFAULT
|
|
|
|
|
# define HAKMEM_TINY_REFILL_DEFAULT 16
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-07 01:27:04 +09:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Tiny front architecture toggles (compile-time defaults)
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// New 3-layer Tiny front (A/B via build flag)
|
|
|
|
|
#ifndef HAKMEM_TINY_USE_NEW_3LAYER
|
|
|
|
|
# define HAKMEM_TINY_USE_NEW_3LAYER 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Minimal/strict front variants (bench/debug only)
|
|
|
|
|
#ifndef HAKMEM_TINY_MINIMAL_FRONT
|
|
|
|
|
# define HAKMEM_TINY_MINIMAL_FRONT 0
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_STRICT_FRONT
|
|
|
|
|
# define HAKMEM_TINY_STRICT_FRONT 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Route fingerprint (compile-time gate; runtime ENV still required)
|
|
|
|
|
#ifndef HAKMEM_ROUTE
|
|
|
|
|
# define HAKMEM_ROUTE 0
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Bench-only knobs (default values; can be overridden via build flags)
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_REFILL
|
|
|
|
|
# define HAKMEM_TINY_BENCH_REFILL 8
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_REFILL8
|
|
|
|
|
# define HAKMEM_TINY_BENCH_REFILL8 HAKMEM_TINY_BENCH_REFILL
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_REFILL16
|
|
|
|
|
# define HAKMEM_TINY_BENCH_REFILL16 HAKMEM_TINY_BENCH_REFILL
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_REFILL32
|
|
|
|
|
# define HAKMEM_TINY_BENCH_REFILL32 HAKMEM_TINY_BENCH_REFILL
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_REFILL64
|
|
|
|
|
# define HAKMEM_TINY_BENCH_REFILL64 HAKMEM_TINY_BENCH_REFILL
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_WARMUP8
|
|
|
|
|
# define HAKMEM_TINY_BENCH_WARMUP8 64
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_WARMUP16
|
|
|
|
|
# define HAKMEM_TINY_BENCH_WARMUP16 96
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_WARMUP32
|
|
|
|
|
# define HAKMEM_TINY_BENCH_WARMUP32 160
|
|
|
|
|
#endif
|
|
|
|
|
#ifndef HAKMEM_TINY_BENCH_WARMUP64
|
|
|
|
|
# define HAKMEM_TINY_BENCH_WARMUP64 192
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-11-05 12:31:14 +09:00
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
// Helper enum (for documentation / logging)
|
|
|
|
|
// ------------------------------------------------------------
|
|
|
|
|
typedef enum {
|
|
|
|
|
HAK_FLAG_BUILD_RELEASE = HAKMEM_BUILD_RELEASE,
|
|
|
|
|
HAK_FLAG_DEBUG_COUNTERS = HAKMEM_DEBUG_COUNTERS,
|
|
|
|
|
HAK_FLAG_DEBUG_MEMORY = HAKMEM_DEBUG_MEMORY,
|
|
|
|
|
HAK_FLAG_REFILL_OPT = HAKMEM_TINY_REFILL_OPT,
|
|
|
|
|
HAK_FLAG_P0_BATCH = HAKMEM_TINY_P0_BATCH_REFILL,
|
|
|
|
|
HAK_FLAG_BOX_REFACTOR = HAKMEM_TINY_PHASE6_BOX_REFACTOR,
|
2025-11-07 01:27:04 +09:00
|
|
|
HAK_FLAG_NEW_3LAYER = HAKMEM_TINY_USE_NEW_3LAYER,
|
2025-11-05 12:31:14 +09:00
|
|
|
} hak_build_flags_t;
|
|
|
|
|
|
|
|
|
|
#endif // HAKMEM_BUILD_FLAGS_H
|