Bug 1806049 - Explicitly use uint32_t r=glandium

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
This commit is contained in:
Paul Bone 2023-01-10 22:30:05 +00:00
Родитель f9bccca030
Коммит 4ea7329f5a
1 изменённых файлов: 8 добавлений и 5 удалений

Просмотреть файл

@ -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;
@ -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));