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:
Moe Charm (CI)
2025-12-03 12:11:27 +09:00
parent 2f09f3cba8
commit c2716f5c01
18 changed files with 183 additions and 33 deletions

View File

@ -72,7 +72,7 @@ void* bench_fast_alloc(size_t size) {
// Reason: P3 optimization skips header writes by default (class_map mode)
// But BenchFast REQUIRES headers for free routing (0xa0-0xa7 magic)
// Contract: BenchFast always writes headers, regardless of P3 optimization
#ifdef HAKMEM_TINY_HEADER_CLASSIDX
#if HAKMEM_TINY_HEADER_CLASSIDX
*(uint8_t*)base = (uint8_t)(0xa0 | (class_idx & 0x0f)); // Direct header write
return (void*)((char*)base + 1); // Return USER pointer
#else
@ -88,7 +88,7 @@ void* bench_fast_alloc(size_t size) {
void bench_fast_free(void* ptr) {
if (__builtin_expect(!ptr, 0)) return;
#ifdef HAKMEM_TINY_HEADER_CLASSIDX
#if HAKMEM_TINY_HEADER_CLASSIDX
// 1. Read class_idx from header (1 instruction, 2-3 cycles)
int class_idx = tiny_region_id_read_header(ptr);
if (__builtin_expect(class_idx < 0 || class_idx >= TINY_NUM_CLASSES, 0)) {
@ -156,7 +156,7 @@ int bench_fast_init(void) {
for (int i = 0; i < (int)capacity; i++) {
// Use normal allocator (hak_alloc_at) - recursion safe here
size_t size = g_tiny_class_sizes[cls];
#ifdef HAKMEM_TINY_HEADER_CLASSIDX
#if HAKMEM_TINY_HEADER_CLASSIDX
// Adjust for header: if class size is N, we need N-1 bytes of user data
size = size - 1;
#endif
@ -170,7 +170,7 @@ int bench_fast_init(void) {
return total;
}
#ifdef HAKMEM_TINY_HEADER_CLASSIDX
#if HAKMEM_TINY_HEADER_CLASSIDX
// Convert USER → BASE pointer
void* base = (void*)((char*)ptr - 1);