brintos

brintos / llvm-project-archived public Read only

0
0
Text · 782 B · f06e7bf Raw
26 lines · cpp
1//===-- Implementation 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-exception6//7//===----------------------------------------------------------------------===//8 9#include "src/stdlib/memalignment.h"10#include "src/__support/CPP/bit.h"11#include "src/__support/common.h"12#include "src/__support/macros/config.h"13 14namespace LIBC_NAMESPACE_DECL {15 16LLVM_LIBC_FUNCTION(size_t, memalignment, (const void *p)) {17  if (p == nullptr)18    return 0;19 20  uintptr_t addr = reinterpret_cast<uintptr_t>(p);21 22  return size_t(1) << cpp::countr_zero(addr);23}24 25} // namespace LIBC_NAMESPACE_DECL26