[libc-commits] [libc] [libc] Efficiently implement `aligned_alloc` for AMDGPU (PR #146585)

Matt Arsenault via libc-commits libc-commits at lists.llvm.org
Wed Jul 2 06:41:07 PDT 2025


================
@@ -0,0 +1,29 @@
+#include "test/IntegrationTest/test.h"
+
+#include "src/__support/GPU/utils.h"
+#include "src/stdlib/aligned_alloc.h" // Adjust path if needed
+#include "src/stdlib/free.h"
+
+using namespace LIBC_NAMESPACE;
+
+TEST_MAIN(int, char **, char **) {
+  // aligned_alloc with valid alignment and size
+  void *ptr = LIBC_NAMESPACE::aligned_alloc(32, 16);
+  EXPECT_NE(ptr, nullptr);
+  EXPECT_EQ(reinterpret_cast<uintptr_t>(ptr) & (32 - 1), 0U);
----------------
arsenm wrote:

Could use the builtins here too, I guess 

https://github.com/llvm/llvm-project/pull/146585


More information about the libc-commits mailing list