MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_bin

Function mi_bin

3rd/mimalloc-2.0.9/src/page-queue.c:56–93  ·  view source on GitHub ↗

Return the bin for a given field size. Returns MI_BIN_HUGE if the size is too large. We use `wsize` for the size in "machine word sizes", i.e. byte size == `wsize*sizeof(void*)`.

Source from the content-addressed store, hash-verified

54// We use `wsize` for the size in "machine word sizes",
55// i.e. byte size == `wsize*sizeof(void*)`.
56static inline uint8_t mi_bin(size_t size) {
57 size_t wsize = _mi_wsize_from_size(size);
58 uint8_t bin;
59 if (wsize <= 1) {
60 bin = 1;
61 }
62 #if defined(MI_ALIGN4W)
63 else if (wsize <= 4) {
64 bin = (uint8_t)((wsize+1)&~1); // round to double word sizes
65 }
66 #elif defined(MI_ALIGN2W)
67 else if (wsize <= 8) {
68 bin = (uint8_t)((wsize+1)&~1); // round to double word sizes
69 }
70 #else
71 else if (wsize <= 8) {
72 bin = (uint8_t)wsize;
73 }
74 #endif
75 else if (wsize > MI_MEDIUM_OBJ_WSIZE_MAX) {
76 bin = MI_BIN_HUGE;
77 }
78 else {
79 #if defined(MI_ALIGN4W)
80 if (wsize <= 16) { wsize = (wsize+3)&~3; } // round to 4x word sizes
81 #endif
82 wsize--;
83 // find the highest bit
84 uint8_t b = (uint8_t)mi_bsr(wsize); // note: wsize != 0
85 // and use the top 3 bits to determine the bin (~12.5% worst internal fragmentation).
86 // - adjust with 3 because we use do not round the first 8 sizes
87 // which each get an exact bin
88 bin = ((b << 2) + (uint8_t)((wsize >> (b - 2)) & 0x03)) - 3;
89 mi_assert_internal(bin < MI_BIN_HUGE);
90 }
91 mi_assert_internal(bin > 0 && bin <= MI_BIN_HUGE);
92 return bin;
93}
94
95
96

Callers 6

_mi_binFunction · 0.85
mi_good_sizeFunction · 0.85
mi_page_queue_ofFunction · 0.85
mi_heap_page_queue_ofFunction · 0.85
mi_large_huge_page_allocFunction · 0.85

Calls 2

mi_bsrFunction · 0.85
_mi_wsize_from_sizeFunction · 0.50

Tested by

no test coverage detected