Files
hakmem/core/box/tiny_c7_hotpath_box.h

64 lines
2.1 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// C7 専用の実験的ホットパス。HAKMEM_TINY_C7_HOT=1 でのみ有効化し、
// デフォルト(未設定/0のときは従来経路に完全フォールバックする。
// 本番デフォルトで ON にしない前提の A/B 用スイッチ。
#pragma once
#include "../hakmem_build_flags.h"
#include "c7_hotpath_env_box.h"
#include "tiny_c7_uc_hit_box.h"
#include "tiny_c7_warm_spill_box.h"
#include "tiny_c7_stats_sample_box.h"
#include "tiny_front_hot_box.h"
#include "tiny_front_cold_box.h"
#include "front_gate_box.h"
#include "tls_sll_box.h"
#include "ptr_conversion_box.h"
// C7 alloc ホットパス。
// 順序:
// 1) TLS/SFC (front_gate_try_pop) を先に覗く
// 2) Unified Cache のヒット専用パス tiny_uc_pop_c7_hit_only()
// 3) それでもダメなら通常の cold refillrefill/統計は cold 側に任せる)
static inline void* tiny_c7_alloc_hot(size_t size) {
(void)size; // size は class_idx=7 前提なので未使用
void* user = NULL;
// 1) SFC/TLS SLL 直叩き(ユーザーポインタが返る)
if (front_gate_try_pop(/*class_idx=*/7, &user)) {
return user;
}
// 2) Unified Cache ヒット
user = tiny_uc_pop_c7_hit_only();
if (__builtin_expect(user != NULL, 1)) {
return user;
}
// 3) Cold refill へフォールバック
return tiny_cold_refill_and_alloc(7);
}
// C7 free ホットパス。BASE を受け取り TLS→UC の順に試す。
static inline int tiny_c7_free_hot(void* base) {
// 1) TLS SLL へ直接 pushBASE のまま渡す)
extern int g_tls_sll_enable;
if (__builtin_expect(g_tls_sll_enable, 1)) {
if (tls_sll_push(7, HAK_BASE_FROM_RAW(base), UINT32_MAX)) {
return 1;
}
}
// 2) Unified Cache へ pushヒット専用の軽量版
if (tiny_uc_push_c7_hot(base)) {
return 1;
}
// 3) Warm spill将来用のフック
if (tiny_c7_warm_spill_one(base)) {
return 1;
}
// 4) 最後に cold free パスへフォールバック
return tiny_cold_drain_and_free(7, base);
}