From d1acb7979a72f3ccf818c177c5e1af619e4b1150 Mon Sep 17 00:00:00 2001 From: Matthew Parkinson Date: Tue, 6 Apr 2021 12:17:36 +0100 Subject: [PATCH] Improve codegen for start of object. By doubling the mod_mult array, we cause the division part of the calculation to completely overflow, and thus remove one instruction from fast path. --- src/mem/sizeclasstable.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mem/sizeclasstable.h b/src/mem/sizeclasstable.h index 390bce7..e170943 100644 --- a/src/mem/sizeclasstable.h +++ b/src/mem/sizeclasstable.h @@ -65,6 +65,10 @@ namespace snmalloc (bits::one_at_bit(bits::BITS - 1) / size[sizeclass]); if (!bits::is_pow2(size[sizeclass])) mod_mult[sizeclass]++; + // Shift multiplier, so that the result of division completely + // overflows, and thus the top SUPERSLAB_BITS will be zero if the mod is + // zero. + mod_mult[sizeclass] *= 2; if (sizeclass < NUM_SMALL_CLASSES) { @@ -214,8 +218,8 @@ namespace snmalloc // square of the offset to be representable. static_assert( SUPERSLAB_BITS <= 24, "The following code assumes max of 24 bits"); - static constexpr size_t MASK = (bits::one_at_bit(bits::BITS - 1) - 1) ^ - (bits::one_at_bit(bits::BITS - 1 - SUPERSLAB_BITS) - 1); + static constexpr size_t MASK = + ~(bits::one_at_bit(bits::BITS - 1 - SUPERSLAB_BITS) - 1); return ((offset * sizeclass_metadata.mod_mult[sc]) & MASK) == 0; }