Skip to content

Commit

Permalink
Bug 1806049 - Explicitly use uint32_t r=glandium
Browse files Browse the repository at this point in the history
We want to be precise about types used here.  Although in practice unsigned
is the same as uint32_t, it's not guaranteed.  We want to definitely use
32-bit multiplication as it can be faster than 64-bit.

Differential Revision: https://phabricator.services.mozilla.com/D164889
  • Loading branch information
PaulBone committed Jan 10, 2023
1 parent ce032fe commit 6cde1a7
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions memory/build/mozjemalloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -838,9 +838,11 @@ class FastDivisor {
#endif
}

// Note that this always occurs in unsigned regardless of m's type. That
// is, m is zero-extended before the operation.
inline unsigned divide(unsigned num) const {
// Note that this always occurs in uint32_t regardless of m's type. If m is
// a uint16_t it will be zero-extended before the multiplication. We also use
// uint32_t rather than something that could possibly be larger because it is
// most-likely the cheapest multiplication.
inline uint32_t divide(uint32_t num) const {
// Check that m was initialised.
MOZ_ASSERT(m);
return (num * m) >> p;
Expand Down Expand Up @@ -2445,14 +2447,15 @@ inline void* arena_t::ArenaRunRegAlloc(arena_run_t* aRun, arena_bin_t* aBin) {

static inline void arena_run_reg_dalloc(arena_run_t* run, arena_bin_t* bin,
void* ptr, size_t size) {
unsigned diff, regind, elm, bit;
uint32_t diff, regind;
unsigned elm, bit;

MOZ_DIAGNOSTIC_ASSERT(run->mMagic == ARENA_RUN_MAGIC);

// Avoid doing division with a variable divisor if possible. Using
// actual division here can reduce allocator throughput by over 20%!
diff =
(unsigned)((uintptr_t)ptr - (uintptr_t)run - bin->mRunFirstRegionOffset);
(uint32_t)((uintptr_t)ptr - (uintptr_t)run - bin->mRunFirstRegionOffset);

MOZ_ASSERT(diff <=
(static_cast<unsigned>(bin->mRunSizePages) << gPageSize2Pow));
Expand Down

0 comments on commit 6cde1a7

Please sign in to comment.