#ifndef __CAKE_BPF_COMPAT_H
#define __CAKE_BPF_COMPAT_H
#if defined(__clang__) && __clang_major__ >= 21
#define cake_relaxed_load_u32(ptr) __atomic_load_n(ptr, __ATOMIC_RELAXED)
#define cake_relaxed_store_u32(ptr, v) __atomic_store_n(ptr, v, __ATOMIC_RELAXED)
#else
static __always_inline u32 cake_relaxed_load_u32(const volatile u32 *ptr) {
u32 val;
asm volatile(
"%0 = *(u32 *)(%1 + 0)"
: "=r"(val)
: "r"(ptr), "m"(*ptr)
);
return val;
}
static __always_inline void cake_relaxed_store_u32(volatile u32 *ptr, u32 val) {
asm volatile(
"*(u32 *)(%1 + 0) = %2"
: "=m"(*ptr)
: "r"(ptr), "r"(val)
);
}
#endif
#endif