Skip to content

Commit 94cb05d

Browse files
rlyerlymeta-codesync[bot]
authored andcommitted
Avoid pointer->integer->pointer roundtrip in AllocationClass
Summary: Linter was complaining because it pessimizes optimizations. Just do pointer arithmetic on a uint8_t*. Reviewed By: stuclar Differential Revision: D99208064 fbshipit-source-id: 3ce7e73016319dfe17b9ab1985d2ad2dbbf67359
1 parent 50ef107 commit 94cb05d

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

cachelib/allocator/memory/AllocationClass.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,21 @@ class AllocationClass {
183183

184184
// Prefetch the first kForEachAllocPrefetchOffset items in the slab.
185185
// Note that the prefetch is for read with no temporal locality.
186-
void* prefetchOffsetPtr = reinterpret_cast<void*>(slab);
186+
auto* prefetchPtr = reinterpret_cast<uint8_t*>(slab);
187187
for (unsigned int i = 0; i < kForEachAllocPrefetchOffset; i++) {
188-
prefetchOffsetPtr = reinterpret_cast<void*>(
189-
reinterpret_cast<uintptr_t>(prefetchOffsetPtr) + allocationSize_);
190-
__builtin_prefetch(prefetchOffsetPtr, 0, 0);
188+
prefetchPtr += allocationSize_;
189+
__builtin_prefetch(prefetchPtr, 0, 0);
191190
}
192-
void* ptr = reinterpret_cast<void*>(slab);
191+
uint8_t* ptr = reinterpret_cast<uint8_t*>(slab);
193192
unsigned int allocsPerSlab = getAllocsPerSlab();
194193
for (unsigned int i = 0; i < allocsPerSlab; ++i) {
195-
prefetchOffsetPtr = reinterpret_cast<void*>(
196-
reinterpret_cast<uintptr_t>(prefetchOffsetPtr) + allocationSize_);
194+
prefetchPtr += allocationSize_;
197195
// Prefetch ahead the kForEachAllocPrefetchOffset item.
198-
__builtin_prefetch(prefetchOffsetPtr, 0, 0);
196+
__builtin_prefetch(prefetchPtr, 0, 0);
199197
if (!callback(ptr, allocInfo.value())) {
200198
return SlabIterationStatus::kAbortIteration;
201199
}
202-
ptr = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(ptr) +
203-
allocationSize_);
200+
ptr += allocationSize_;
204201
}
205202
return SlabIterationStatus::kFinishedCurrentSlabAndContinue;
206203
}

0 commit comments

Comments
 (0)