From f7de7084f4a2c346b3db87c26fa519db0781a09a Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 3 Feb 2020 15:35:35 -0800 Subject: [PATCH] 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 --- compiler-rt/lib/scudo/standalone/size_class_map.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 @@ public: 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) {