#include #include #if UINTPTR_MAX == UINT32_MAX # define UINTPTR_C(p) UINT32_C(p) #elif UINTPTR_MAX == UINT64_MAX # define UINTPTR_C(p) UINT64_C(p) #else # error uintptr_t size not handled. #endif #define PAD_BITS (sizeof(void*) >> 1) #define BIT_BITS 3 #define BYTE_BITS 14 #define PAD_MASK ((UINTPTR_C(1) << PAD_BITS) - 1) #define BIT_MASK UINTPTR_C(0x00000007) #define BYTE_MASK UINTPTR_C(0x00003FFF) #define PAD_OFFSET 0 #define BIT_OFFSET (PAD_OFFSET + PAD_BITS) #define BYTE_OFFSET (BIT_OFFSET + BIT_BITS) #define SLOT_OFFSET (BYTE_OFFSET + BYTE_BITS) void check_new(void* p) { register uintptr_t i = (uintptr_t)p; uintptr_t slot = ( i >> SLOT_OFFSET ); uintptr_t byte = ( i >> BYTE_OFFSET ) & BYTE_MASK; uintptr_t bit = ( i >> BIT_OFFSET ) & BIT_MASK; uintptr_t pad = ( i >> PAD_OFFSET ) & PAD_MASK; printf("address: %016p " "slot: %016p " "byte: %4x " "bit: %4x " "nop: %x\n", p, (void*)slot, (unsigned)byte, (unsigned)bit, (unsigned)pad ); } int main(int argc, char *argv[]) { void* p; for ( p = (void*)UINTPTR_C(123456); p < (void*)(UINTPTR_C(1) << 34); p += (UINTPTR_C(1) << 29) ) check_new(p); return 0; } #### #if sizeof(uintptr_t) == 4 # define UINTPTR_C(p) UINT32_C(p) #elif sizeof(uintptr_t) == 8 # define UINTPTR_C(p) UINT64_C(p) #else # error uintptr_t size not handled. #endif #if sizeof(uintptr_t) == sizeof(unsigned) # define UINTPTRxf "x" #if sizeof(uintptr_t) == sizeof(unsigned long) # define UINTPTRxf "lx" #if sizeof(uintptr_t) == sizeof(unsigned long long) # define UINTPTRxf "Lx" #else # error uintptr_t size not handled. #endif