Better reciprocal division and modulus.
The previous reciprocal division branch on the prime that the sizeclass
was constructed from. All sizeclasses can be represented as
2^n * {1,3,5,7}
This lead to a very small table, but some work to calculate the
appropriate shifts and multiplications to implement reciprocal division.
This commit uses a completely uniform representation for every
sizeclass using a lookup table. Due to the precise ranges that we query
the modulus and rounding on, we can do this much more efficiently.
The func-release-rounding exhaustively tests all the queries we are
interested in.
This commit is contained in:
committed by
Matthew Parkinson
parent
486ef10c21
commit
8824622136
@@ -243,8 +243,11 @@ void test_external_pointer()
|
||||
void* p2 = pointer_offset(p1, offset);
|
||||
void* p3 = alloc->external_pointer(p2);
|
||||
void* p4 = alloc->external_pointer<End>(p2);
|
||||
UNUSED(p3);
|
||||
UNUSED(p4);
|
||||
if (p1 != p3)
|
||||
{
|
||||
std::cout << "size: " << size << " offset: " << offset << " p1: " << p1
|
||||
<< " p3: " << p3 << std::endl;
|
||||
}
|
||||
SNMALLOC_CHECK(p1 == p3);
|
||||
SNMALLOC_CHECK((size_t)p4 == (size_t)p1 + size - 1);
|
||||
}
|
||||
|
||||
@@ -18,18 +18,28 @@ int main(int argc, char** argv)
|
||||
for (size_t size_class = 0; size_class < NUM_SIZECLASSES; size_class++)
|
||||
{
|
||||
size_t rsize = sizeclass_to_size((uint8_t)size_class);
|
||||
for (size_t offset = 0; offset < SUPERSLAB_SIZE; offset++)
|
||||
size_t max_offset =
|
||||
size_class < NUM_SMALL_CLASSES ? SLAB_SIZE : SUPERSLAB_SIZE;
|
||||
for (size_t offset = 0; offset < max_offset; offset++)
|
||||
{
|
||||
size_t rounded = (offset / rsize) * rsize;
|
||||
bool mod_0 = (offset % rsize) == 0;
|
||||
|
||||
size_t opt_rounded = round_by_sizeclass(rsize, offset);
|
||||
size_t opt_rounded = round_by_sizeclass(size_class, offset);
|
||||
if (rounded != opt_rounded)
|
||||
{
|
||||
std::cout << "rsize " << rsize << " offset " << offset << " opt "
|
||||
<< opt_rounded << std::endl;
|
||||
abort();
|
||||
}
|
||||
|
||||
bool opt_mod_0 = is_multiple_of_sizeclass(rsize, offset);
|
||||
bool opt_mod_0 = is_multiple_of_sizeclass(size_class, offset);
|
||||
if (opt_mod_0 != mod_0)
|
||||
{
|
||||
std::cout << "rsize " << rsize << " offset " << offset << " opt_mod "
|
||||
<< opt_mod_0 << std::endl;
|
||||
abort();
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user