add base and size to OS memid

This commit is contained in:
daanx 2024-12-02 19:31:36 -08:00
parent 5e95ebc7a0
commit fe5a314114
9 changed files with 104 additions and 40 deletions

View file

@ -237,6 +237,30 @@ static inline uint32_t mi_ctz32(uint32_t x) {
#define MI_HAS_FAST_BITSCAN 1
#endif
static inline size_t mi_popcount(size_t x) {
#if mi_has_builtin_size(popcount)
return mi_builtin_size(popcount)(x);
#elif defined(_MSC_VER) && (MI_ARCH_X64 || MI_ARCH_X86 || MI_ARCH_ARM64 || MI_ARCH_ARM32)
#if MI_SIZE_BITS==32
return __popcnt(x);
#else
return __popcnt64(x);
#endif
#elif MI_ARCH_X64 && defined(__BMI1__)
return (size_t)_mm_popcnt_u64(x);
#else
#define MI_HAS_FAST_POPCOUNT 0
error define generic popcount
#endif
}
#ifndef MI_HAS_FAST_POPCOUNT
#define MI_HAS_FAST_POPCOUNT 1
#endif
/* --------------------------------------------------------------------------------
find trailing/leading zero (bit scan forward/reverse)
-------------------------------------------------------------------------------- */

View file

@ -844,8 +844,10 @@ static inline mi_memid_t _mi_memid_none(void) {
return _mi_memid_create(MI_MEM_NONE);
}
static inline mi_memid_t _mi_memid_create_os(bool committed, bool is_zero, bool is_large) {
static inline mi_memid_t _mi_memid_create_os(void* base, size_t size, bool committed, bool is_zero, bool is_large) {
mi_memid_t memid = _mi_memid_create(MI_MEM_OS);
memid.mem.os.base = base;
memid.mem.os.size = size;
memid.initially_committed = committed;
memid.initially_zero = is_zero;
memid.is_pinned = is_large;

View file

@ -171,6 +171,7 @@ static inline bool mi_memkind_is_os(mi_memkind_t memkind) {
typedef struct mi_memid_os_info {
void* base; // actual base address of the block (used for offset aligned allocations)
size_t alignment; // alignment at allocation
size_t size; // allocated full size
} mi_memid_os_info_t;
typedef struct mi_memid_arena_info {