Skip to content

Commit dea4f32

Browse files
authored
[libc] Use is aligned builtin instead of ptrtoint (#146402)
Summary: This avoids a ptrtoint by just using the clang builtin. This is clang specific but only clang can compile GPU code anyway so I do not bother with a fallback.
1 parent 5fe63ae commit dea4f32

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libc/src/__support/GPU/allocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ void deallocate(void *ptr) {
541541
return;
542542

543543
// All non-slab allocations will be aligned on a 2MiB boundary.
544-
if ((reinterpret_cast<uintptr_t>(ptr) & SLAB_ALIGNMENT) == 0)
544+
if (__builtin_is_aligned(ptr, SLAB_ALIGNMENT + 1))
545545
return impl::rpc_free(ptr);
546546

547547
// The original slab pointer is the 2MiB boundary using the given pointer.
@@ -556,7 +556,7 @@ void *reallocate(void *ptr, uint64_t size) {
556556
return gpu::allocate(size);
557557

558558
// Non-slab allocations are considered foreign pointers so we fail.
559-
if ((reinterpret_cast<uintptr_t>(ptr) & SLAB_ALIGNMENT) == 0)
559+
if (__builtin_is_aligned(ptr, SLAB_ALIGNMENT + 1))
560560
return nullptr;
561561

562562
// The original slab pointer is the 2MiB boundary using the given pointer.

0 commit comments

Comments
 (0)