[libc-commits] [libc] [libc] implement `memalignment` (PR #132493)

via libc-commits libc-commits at lists.llvm.org
Sat Mar 22 06:55:40 PDT 2025


================
@@ -0,0 +1,15 @@
+#include "src/stdlib/memalignment.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(size_t, memalignment, (const void *p)) {
+  if (p == NULL)
+    return 0;
+
+  uintptr_t addr = reinterpret_cast<uintptr_t>(p);
+
+  return 1 << __builtin_ctzg(addr);
----------------
lntue wrote:

Use `size_t(1) << cpp::countr_zero(addr);` instead?

https://github.com/llvm/llvm-project/blob/main/libc/src/__support/CPP/bit.h#L81

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


More information about the libc-commits mailing list