37 lines
1.0 KiB
C
37 lines
1.0 KiB
C
|
|
#ifndef SS_PT_LOOKUP_BOX_H
|
||
|
|
#define SS_PT_LOOKUP_BOX_H
|
||
|
|
|
||
|
|
#include "ss_pt_types_box.h"
|
||
|
|
#include "ss_pt_env_box.h"
|
||
|
|
|
||
|
|
// O(1) lookup (hot path, lock-free)
|
||
|
|
static inline struct SuperSlab* ss_pt_lookup(void* addr) {
|
||
|
|
uintptr_t p = (uintptr_t)addr;
|
||
|
|
|
||
|
|
// Out-of-range check (>> 48 for LA57 compatibility)
|
||
|
|
if (__builtin_expect(p >> 48, 0)) {
|
||
|
|
if (hak_ss_pt_stats_enabled()) t_ss_pt_stats.pt_out_of_range++;
|
||
|
|
return NULL; // Fallback to hash handled by caller
|
||
|
|
}
|
||
|
|
|
||
|
|
uint32_t l1_idx = SS_PT_L1_INDEX(addr);
|
||
|
|
uint32_t l2_idx = SS_PT_L2_INDEX(addr);
|
||
|
|
|
||
|
|
// L1 load (acquire)
|
||
|
|
SsPtL2* l2 = atomic_load_explicit(&g_ss_pt.l2[l1_idx], memory_order_acquire);
|
||
|
|
if (__builtin_expect(l2 == NULL, 0)) {
|
||
|
|
if (hak_ss_pt_stats_enabled()) t_ss_pt_stats.pt_miss++;
|
||
|
|
return NULL;
|
||
|
|
}
|
||
|
|
|
||
|
|
// L2 load (acquire)
|
||
|
|
struct SuperSlab* ss = atomic_load_explicit(&l2->entries[l2_idx], memory_order_acquire);
|
||
|
|
if (hak_ss_pt_stats_enabled()) {
|
||
|
|
if (ss) t_ss_pt_stats.pt_hit++;
|
||
|
|
else t_ss_pt_stats.pt_miss++;
|
||
|
|
}
|
||
|
|
return ss;
|
||
|
|
}
|
||
|
|
|
||
|
|
#endif
|