[libc-commits] [libc] [libc] Fix the GPU build for the hashing support (PR #73799)
Joseph Huber via libc-commits
libc-commits at lists.llvm.org
Wed Nov 29 06:44:25 PST 2023
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/73799
Summary:
For reasons unknown to me, this function is undefined only on the GPU
build if you use `uintptr_t` but not `uint64_t` directly. This patch
makes an ifdef to use this directly for the GPU build to fix the bots.
>From f7138df81e9839a7cbba303adbb1e2bcaaad3c08 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Wed, 29 Nov 2023 08:40:48 -0600
Subject: [PATCH] [libc] Fix the GPU build for the hashing support
Summary:
For reasons unknown to me, this function is undefined only on the GPU
build if you use `uintptr_t` but not `uint64_t` directly. This patch
makes an ifdef to use this directly for the GPU build to fix the bots.
---
libc/src/__support/HashTable/CMakeLists.txt | 1 +
.../HashTable/generic/bitmask_impl.inc | 23 +++++++++++++------
2 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/libc/src/__support/HashTable/CMakeLists.txt b/libc/src/__support/HashTable/CMakeLists.txt
index 22e91d4f8708c54..e9b4aa31290a137 100644
--- a/libc/src/__support/HashTable/CMakeLists.txt
+++ b/libc/src/__support/HashTable/CMakeLists.txt
@@ -5,6 +5,7 @@ add_header_library(
FLAGS
PREFER_GENERIC
DEPENDS
+ libc.src.__support.common
libc.src.__support.bit
libc.src.__support.macros.properties.cpu_features
)
diff --git a/libc/src/__support/HashTable/generic/bitmask_impl.inc b/libc/src/__support/HashTable/generic/bitmask_impl.inc
index 13e08382adf6221..8c6188133a4e922 100644
--- a/libc/src/__support/HashTable/generic/bitmask_impl.inc
+++ b/libc/src/__support/HashTable/generic/bitmask_impl.inc
@@ -7,37 +7,46 @@
//===----------------------------------------------------------------------===//
#include "src/__support/endian.h"
+#include "src/__support/common.h"
namespace LIBC_NAMESPACE {
namespace internal {
+
+// FIXME: The GPU build cannot use 'uintptr_t' directly.
+#ifdef LIBC_TARGET_ARCH_IS_GPU
+ using bitmask_t = uint64_t;
+#else
+ using bitmask_t = uintptr_t;
+#endif
+
// Helper function to spread a byte across the whole word.
// Accumutively, the procedure looks like:
// byte = 0x00000000000000ff
// byte | (byte << 8) = 0x000000000000ffff
// byte | (byte << 16) = 0x00000000ffffffff
// byte | (byte << 32) = 0xffffffffffffffff
-LIBC_INLINE constexpr uintptr_t repeat_byte(uintptr_t byte) {
+LIBC_INLINE constexpr bitmask_t repeat_byte(bitmask_t byte) {
size_t shift_amount = 8;
- while (shift_amount < sizeof(uintptr_t) * 8) {
+ while (shift_amount < sizeof(bitmask_t) * 8) {
byte |= byte << shift_amount;
shift_amount <<= 1;
}
return byte;
}
-using BitMask = BitMaskAdaptor<uintptr_t, repeat_byte(0x80), 0x8ull>;
+using BitMask = BitMaskAdaptor<bitmask_t, repeat_byte(0x80), 0x8ull>;
using IteratableBitMask = IteratableBitMaskAdaptor<BitMask>;
struct Group {
- uintptr_t data;
+ bitmask_t data;
// Load a group of control words from an arbitary address.
LIBC_INLINE static Group load(const void *__restrict addr) {
union {
- uintptr_t value;
- char bytes[sizeof(uintptr_t)];
+ bitmask_t value;
+ char bytes[sizeof(bitmask_t)];
} data;
- for (size_t i = 0; i < sizeof(uintptr_t); ++i)
+ for (size_t i = 0; i < sizeof(bitmask_t); ++i)
data.bytes[i] = static_cast<const char *>(addr)[i];
return {data.value};
}
More information about the libc-commits
mailing list