Implement Phase 2: Headerless Allocator Support (Partial)
- Feature: Added HAKMEM_TINY_HEADERLESS toggle (A/B testing) - Feature: Implemented Headerless layout logic (Offset=0) - Refactor: Centralized layout definitions in tiny_layout_box.h - Refactor: Abstracted pointer arithmetic in free path via ptr_conversion_box.h - Verification: sh8bench passes in Headerless mode (No TLS_SLL_HDR_RESET) - Known Issue: Regression in Phase 1 mode due to blind pointer conversion logic
This commit is contained in:
@ -17,11 +17,32 @@
|
||||
#include <stddef.h>
|
||||
#include "../hakmem_tiny_config.h" // For g_tiny_class_sizes and TINY_NUM_CLASSES
|
||||
|
||||
// A/B Toggle: Headerless mode
|
||||
// ENV: HAKMEM_TINY_HEADERLESS=1 to enable
|
||||
// Default: 0 (Phase 1 compatible)
|
||||
#ifndef HAKMEM_TINY_HEADERLESS
|
||||
#define HAKMEM_TINY_HEADERLESS 0
|
||||
#endif
|
||||
|
||||
// Define all class-specific layout parameters
|
||||
// Current: Defined in g_tiny_class_sizes[8] in hakmem_tiny.c
|
||||
// This file makes them accessible via a unified Box API
|
||||
|
||||
// Header size is 1 byte when enabled
|
||||
// Header size
|
||||
static inline size_t tiny_header_size(int class_idx) {
|
||||
#if HAKMEM_TINY_HEADERLESS
|
||||
(void)class_idx;
|
||||
return 0;
|
||||
#else
|
||||
// Phase 1: 1 byte header if enabled
|
||||
// C0 (8B): offset 0 (8B stride too small for header + 8B pointer - would overflow)
|
||||
// C7 (2048B): offset 0 (overwrites header in freelist - largest class can tolerate)
|
||||
// C1-C6: offset 1 (header preserved - user data is not disturbed)
|
||||
return (0x7Eu >> class_idx) & 1u;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Legacy macro for backward compatibility (Phase 1)
|
||||
#define TINY_HEADER_SIZE 1
|
||||
|
||||
// Validation macros
|
||||
@ -38,7 +59,10 @@ static inline size_t tiny_class_stride(int class_idx) {
|
||||
// Calculate user pointer offset from base pointer
|
||||
// This logic centralizes the "User = Base + 1" vs "User = Base + 0" decision
|
||||
static inline size_t tiny_user_offset(int class_idx) {
|
||||
#if HAKMEM_TINY_HEADER_CLASSIDX
|
||||
#if HAKMEM_TINY_HEADERLESS
|
||||
(void)class_idx;
|
||||
return 0; // Headerless: user = base
|
||||
#elif HAKMEM_TINY_HEADER_CLASSIDX
|
||||
// C0 (8B): offset 0 (8B stride too small for header + 8B pointer - would overflow)
|
||||
// C7 (2048B): offset 0 (overwrites header in freelist - largest class can tolerate)
|
||||
// C1-C6: offset 1 (header preserved - user data is not disturbed)
|
||||
|
||||
Reference in New Issue
Block a user