File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ #include "src/stdlib/memalignment.h"
2+ #include "src/__support/macros/config.h"
3+
4+ namespace LIBC_NAMESPACE_DECL {
5+
6+ LLVM_LIBC_FUNCTION (size_t , memalignment , (const void * p )) {
7+ if (p == NULL ) {
8+ return 0 ;
9+ }
10+
11+ uintptr_t addr = (uintptr_t )p ;
12+
13+ // Find the rightmost set bit, which represents the maximum alignment
14+ // The alignment is a power of two, so we need to find the largest
15+ // power of two that divides the address
16+ return addr & (~addr + 1 );
17+ }
18+
19+ } // namespace LIBC_NAMESPACE_DECL
Original file line number Diff line number Diff line change 1+ // ===-- Implementation header for memalignment --------------------------*- C++ -*-===//
2+ //
3+ // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+ // See https://llvm.org/LICENSE.txt for license information.
5+ // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+ //
7+ // ===----------------------------------------------------------------------===//
8+
9+ #ifndef LLVM_LIBC_SRC_STDLIB_MEM_ALIGNMENT_H
10+ #define LLVM_LIBC_SRC_STDLIB_MEM_ALIGNMENT_H
11+
12+ #include " src/__support/macros/config.h"
13+ #include < stddef.h>
14+
15+ namespace LIBC_NAMESPACE_DECL {
16+
17+ size_t memalignment (const void * p);
18+
19+ } // namespace LIBC_NAMESPACE_DECL
20+
21+ #endif // LLVM_LIBC_SRC_STDLIB_LDIV_H
22+
You can’t perform that action at this time.
0 commit comments