mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 11:25:00 +00:00
Bug 1415454 - Replace log2 lookup table with FloorLog2. r=njn
FloorLog2 expands to, essentially, a compiler builtin/intrinsic, that, in turn, expands to a single machine instruction on tier 1 and other platforms. On platforms where that's not the case, we can expect the compiler to generate fast code anyways. So overall, this is all better than manually using a log2 lookup table. Also replace a manual power-of-two check with mozilla::IsPowerOfTwo, which does the same test. --HG-- extra : rebase_source : e8164c254723c74ef83e798073327ec6afa6f1fb
This commit is contained in:
parent
3a2a081a07
commit
e68ddaa1c2
@ -2359,33 +2359,8 @@ arena_run_reg_dalloc(arena_run_t* run, arena_bin_t* bin, void* ptr, size_t size)
|
||||
// actual division here can reduce allocator throughput by over 20%!
|
||||
diff =
|
||||
(unsigned)((uintptr_t)ptr - (uintptr_t)run - bin->mRunFirstRegionOffset);
|
||||
if ((size & (size - 1)) == 0) {
|
||||
// log2_table allows fast division of a power of two in the
|
||||
// [1..128] range.
|
||||
//
|
||||
// (x / divisor) becomes (x >> log2_table[divisor - 1]).
|
||||
// clang-format off
|
||||
static const unsigned char log2_table[] = {
|
||||
0, 1, 0, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
if (size <= 128) {
|
||||
regind = (diff >> log2_table[size - 1]);
|
||||
} else if (size <= 32768) {
|
||||
regind = diff >> (8 + log2_table[(size >> 8) - 1]);
|
||||
} else {
|
||||
// The run size is too large for us to use the lookup
|
||||
// table. Use real division.
|
||||
regind = diff / size;
|
||||
}
|
||||
if (mozilla::IsPowerOfTwo(size)) {
|
||||
regind = diff >> FloorLog2(size);
|
||||
} else if (size <= ((sizeof(size_invs) / sizeof(unsigned)) * kQuantum) + 2) {
|
||||
regind = size_invs[(size / kQuantum) - 3] * diff;
|
||||
regind >>= SIZE_INV_SHIFT;
|
||||
|
Loading…
Reference in New Issue
Block a user