MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / mi_bbitmap_bsr_inv

Function mi_bbitmap_bsr_inv

system/lib/mimalloc/src/bitmap.c:1574–1599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1572}
1573
1574bool mi_bbitmap_bsr_inv(mi_bbitmap_t* bbitmap, size_t* idx) {
1575 const size_t chunk_count = mi_bbitmap_chunk_count(bbitmap);
1576 const size_t chunkmap_max = _mi_divide_up(chunk_count, MI_BFIELD_BITS);
1577 size_t skip_at_top = chunk_count % MI_BFIELD_BITS;
1578 for (size_t i = chunkmap_max; i > 0; ) {
1579 i--;
1580 mi_bfield_t cmap = mi_atomic_load_relaxed(&bbitmap->chunkmap.bfields[i]);
1581 size_t cmap_idx;
1582 // don't consider top 0 bits; set those to 1 here
1583 if (skip_at_top > 0) {
1584 const size_t mask_top = (~mi_bfield_zero()) << (MI_BFIELD_BITS - skip_at_top);
1585 skip_at_top = 0; // only for the first iteration
1586 cmap |= mask_top;
1587 }
1588 if (mi_bsr(~cmap, &cmap_idx)) {
1589 // highest chunk
1590 const size_t chunk_idx = i*MI_BFIELD_BITS + cmap_idx;
1591 size_t cidx;
1592 if (mi_bchunk_bsr_inv(&bbitmap->chunks[chunk_idx], &cidx)) {
1593 *idx = (chunk_idx * MI_BCHUNK_BITS) + cidx;
1594 return true;
1595 }
1596 }
1597 }
1598 return false;
1599}
1600
1601
1602/* --------------------------------------------------------------------------------

Callers 2

bitmap.hFile · 0.85
mi_arena_used_slicesFunction · 0.85

Calls 4

_mi_divide_upFunction · 0.85
mi_bfield_zeroFunction · 0.85
mi_bsrFunction · 0.85
mi_bchunk_bsr_invFunction · 0.85

Tested by

no test coverage detected