Complete Phase 1.2: Centralize layout definitions in tiny_layout_box.h
Changes: - Updated ptr_conversion_box.h: Use TINY_HEADER_SIZE instead of hardcoded -1 - Updated tiny_front_hot_box.h: Use tiny_user_offset() for BASE->USER conversion - Updated tiny_front_cold_box.h: Use tiny_user_offset() for BASE->USER conversion - Added tiny_layout_box.h includes to both front box headers Box theory: Layout parameters now isolated in dedicated Box component. All offset arithmetic centralized - no scattered +1/-1 arithmetic. Verified: Build succeeds (make clean && make shared -j8) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@ -99,8 +99,11 @@ static inline void* ptr_user_to_base_blind(void* user_ptr) {
|
||||
// Headerless: base = user
|
||||
return user_ptr;
|
||||
#else
|
||||
// Phase 1: All classes have 1 byte header -> base = user - 1
|
||||
return (void*)((uint8_t*)user_ptr - 1);
|
||||
// Phase 1: All classes 0-6 have 1 byte header, class 7 is headerless
|
||||
// For blind conversion (no class info), assume standard header offset
|
||||
// This works because class is determined AFTER base pointer calculation
|
||||
size_t offset = TINY_HEADER_SIZE; // From tiny_layout_box.h
|
||||
return (void*)((uint8_t*)user_ptr - offset);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include "../hakmem_tiny_config.h"
|
||||
#include "../tiny_region_id.h"
|
||||
#include "../front/tiny_unified_cache.h" // For TinyUnifiedCache, unified_cache_refill
|
||||
#include "tiny_layout_box.h" // For tiny_user_offset()
|
||||
|
||||
// ============================================================================
|
||||
// Box 3: Tiny Cold Refill + Alloc
|
||||
@ -76,7 +77,9 @@ static inline void* tiny_cold_refill_and_alloc(int class_idx) {
|
||||
// NOTE: Header already written by unified_cache_refill()
|
||||
// (Removed redundant tiny_region_id_write_header() - P2 fix)
|
||||
#if HAKMEM_TINY_HEADER_CLASSIDX
|
||||
return (void*)((char*)base + 1); // USER pointer
|
||||
// Use centralized layout API for offset calculation
|
||||
size_t user_offset = tiny_user_offset(class_idx);
|
||||
return (void*)((char*)base + user_offset); // USER pointer
|
||||
#else
|
||||
return base;
|
||||
#endif
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "../hakmem_tiny_config.h"
|
||||
#include "../tiny_region_id.h"
|
||||
#include "../front/tiny_unified_cache.h" // For TinyUnifiedCache
|
||||
#include "tiny_layout_box.h" // For tiny_user_offset()
|
||||
|
||||
// ============================================================================
|
||||
// Branch Prediction Macros (Pointer Safety - Prediction Hints)
|
||||
@ -128,7 +129,9 @@ static inline void* tiny_hot_alloc_fast(int class_idx) {
|
||||
// Write header + return USER pointer (no branch)
|
||||
#if HAKMEM_TINY_HEADER_CLASSIDX
|
||||
tiny_region_id_write_header(base, class_idx); // 1-byte header at BASE
|
||||
return (void*)((char*)base + 1); // Return USER pointer (BASE+1)
|
||||
// Use centralized layout API for offset calculation
|
||||
size_t user_offset = tiny_user_offset(class_idx);
|
||||
return (void*)((char*)base + user_offset); // Return USER pointer
|
||||
#else
|
||||
return base; // No-header mode: return BASE directly
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user