Add v4 C7/C6 fast classify and small-segment v4 scaffolding

This commit is contained in:
Moe Charm (CI)
2025-12-10 19:14:38 +09:00
parent 3261025995
commit f2ce7256cd
11 changed files with 221 additions and 17 deletions

View File

@ -5,8 +5,9 @@
// - 挙動はまだ v3/v1 のまま。alloc/free 本体は後続フェーズで実装する。
#pragma once
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include "tiny_geometry_box.h"
@ -46,3 +47,4 @@ small_heap_ctx_v4* small_heap_ctx_v4_get(void);
// Hot path API (C7-only stub; later phases will expand)
void* small_heap_alloc_fast_v4(small_heap_ctx_v4* ctx, int class_idx);
void small_heap_free_fast_v4(small_heap_ctx_v4* ctx, int class_idx, void* ptr);
int smallobject_hotbox_v4_can_own(int class_idx, void* ptr);

View File

@ -47,3 +47,7 @@ static inline int small_heap_v4_c7_enabled(void) {
static inline int small_heap_v4_c6_enabled(void) {
return small_heap_v4_class_enabled(6);
}
static inline int small_heap_v4_c5_enabled(void) {
return small_heap_v4_class_enabled(5);
}

View File

@ -0,0 +1,11 @@
// smallsegment_v4_box.h - Small-object専用 Segment Box の宣言だけを置く足場
// Phase PF2: 挙動はまだ変えず、型と API だけを先行定義する。
#pragma once
typedef struct small_segment_v4 small_segment_v4;
// class_idx ごとに小さな Segment を確保/再利用する想定。
// まだ実装はなく、次フェーズで Superslab/OS との接続を決める。
small_segment_v4* smallsegment_v4_acquire(int class_idx);
void* smallsegment_v4_alloc_page(small_segment_v4* seg, int class_idx);
void smallsegment_v4_release_if_empty(small_segment_v4* seg);

View File

@ -0,0 +1,28 @@
// smallsegment_v4_env_box.h - small-object segment v4 の ENV ゲート
// Phase PF2: ENV を宣言するだけ。実装は次フェーズで追加。
#pragma once
#include <stdlib.h>
static inline int smallsegment_v4_enabled(void) {
static int g = -1;
if (__builtin_expect(g == -1, 0)) {
const char* e = getenv("HAKMEM_SMALL_SEGMENT_V4_ENABLED");
if (e && *e && *e != '0') {
g = 1;
} else {
g = 0;
}
}
return g;
}
static inline const char* smallsegment_v4_size_env(void) {
static int g_init = 0;
static const char* g_val = NULL;
if (__builtin_expect(!g_init, 0)) {
g_val = getenv("HAKMEM_SMALL_SEGMENT_V4_SIZE");
g_init = 1;
}
return g_val;
}

View File

@ -77,6 +77,16 @@ static inline bool tiny_ptr_fast_classify_enabled(void) {
return g != 0;
}
// C7/C6 v4 free 用 fast classify gate (default OFF)
static inline bool tiny_ptr_fast_classify_v4_enabled(void) {
static int g = -1;
if (__builtin_expect(g == -1, 0)) {
const char* e = getenv("HAKMEM_TINY_PTR_FAST_CLASSIFY_V4_ENABLED");
g = (e && *e && *e != '0') ? 1 : 0;
}
return g != 0;
}
// Optional stats gate
static inline bool tiny_front_v3_stats_enabled(void) {
static int g = -1;