summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2013-05-16 07:11:16 +0000
committerKostya Serebryany <kcc@google.com>2013-05-16 07:11:16 +0000
commita551aaa944647e9d5ecbfa3888ea4b56944a7f8a (patch)
treec520acf85a1a0db2b2b12541978884dc3627e5c8 /compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
parent267b446324762b773e0a72f5b4a47e1c43458651 (diff)
downloadbcm5719-llvm-a551aaa944647e9d5ecbfa3888ea4b56944a7f8a.tar.gz
bcm5719-llvm-a551aaa944647e9d5ecbfa3888ea4b56944a7f8a.zip
[sanitizer] fix the GetBlockBegin overflow bug while preserving the performance optimization (use 32-bit division when possible). Improve the benchmarks that checks for performance of GetBlockBegin/GetMetaData
llvm-svn: 181989
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/sanitizer_allocator.h')
-rw-r--r--compiler-rt/lib/sanitizer_common/sanitizer_allocator.h9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
index d0716a4a1c8..f17f08eab56 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator.h
@@ -492,11 +492,12 @@ class SizeClassAllocator64 {
}
static uptr GetChunkIdx(uptr chunk, uptr size) {
- u32 offset = chunk % kRegionSize;
+ uptr offset = chunk % kRegionSize;
// Here we divide by a non-constant. This is costly.
- // We require that kRegionSize is at least 2^32 so that offset is 32-bit.
- // We save 2x by using 32-bit div, but may need to use a 256-way switch.
- return offset / (u32)size;
+ // size always fits into 32-bits. If the offset fits too, use 32-bit div.
+ if (offset >> 32)
+ return offset / size;
+ return (u32)offset / (u32)size;
}
NOINLINE Batch* PopulateFreeList(AllocatorStats *stat, AllocatorCache *c,
OpenPOWER on IntegriCloud