[compiler-rt] f7de708 - scudo: Simplify getClassIdBySize() logic. NFCI.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 4 09:32:34 PST 2020
Author: Peter Collingbourne
Date: 2020-02-04T09:32:27-08:00
New Revision: f7de7084f4a2c346b3db87c26fa519db0781a09a
URL: https://github.com/llvm/llvm-project/commit/f7de7084f4a2c346b3db87c26fa519db0781a09a
DIFF: https://github.com/llvm/llvm-project/commit/f7de7084f4a2c346b3db87c26fa519db0781a09a.diff
LOG: scudo: Simplify getClassIdBySize() logic. NFCI.
By subtracting 1 from Size at the beginning we can simplify the
subsequent calculations. This also saves 4 instructions on aarch64
and 9 instructions on x86_64, but seems to be perf neutral.
Differential Revision: https://reviews.llvm.org/D73936
Added:
Modified:
compiler-rt/lib/scudo/standalone/size_class_map.h
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/size_class_map.h b/compiler-rt/lib/scudo/standalone/size_class_map.h
index f16fed73833f..3849feaf38dd 100644
--- a/compiler-rt/lib/scudo/standalone/size_class_map.h
+++ b/compiler-rt/lib/scudo/standalone/size_class_map.h
@@ -66,11 +66,11 @@ class SizeClassMap {
DCHECK_LE(Size, MaxSize);
if (Size <= MidSize)
return (Size + MinSize - 1) >> MinSizeLog;
+ Size -= 1;
const uptr L = getMostSignificantSetBitIndex(Size);
- const uptr HBits = (Size >> (L - S)) & M;
- const uptr LBits = Size & ((1UL << (L - S)) - 1);
- const uptr L1 = L - MidSizeLog;
- return MidClass + (L1 << S) + HBits + (LBits > 0);
+ const uptr LBits = (Size >> (L - S)) - (1 << S);
+ const uptr HBits = (L - MidSizeLog) << S;
+ return MidClass + 1 + HBits + LBits;
}
static u32 getMaxCachedHint(uptr Size) {
More information about the llvm-commits
mailing list