52 changes: 52 additions & 0 deletions libc/src/__support/macros/architectures.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//===-- Compile time architecture detection ---------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIBC_SUPPORT_MACROS_ARCHITECTURES_H
#define LLVM_LIBC_SUPPORT_MACROS_ARCHITECTURES_H

#if defined(__AMDGPU__)
#define LIBC_TARGET_IS_AMDGPU
#endif

#if defined(__NVPTX__)
#define LIBC_TARGET_IS_NVPTX
#endif

#if defined(LIBC_TARGET_IS_NVPTX) || defined(LIBC_TARGET_IS_AMDGPU)
#define LIBC_TARGET_IS_GPU
#endif

#if defined(__pnacl__) || defined(__CLR_VER) || defined(LIBC_TARGET_IS_GPU)
#define LIBC_TARGET_IS_VM
#endif

#if (defined(_M_IX86) || defined(__i386__)) && !defined(LIBC_TARGET_IS_VM)
#define LIBC_TARGET_IS_X86_32
#endif

#if (defined(_M_X64) || defined(__x86_64__)) && !defined(LIBC_TARGET_IS_VM)
#define LIBC_TARGET_IS_X86_64
#endif

#if defined(LIBC_TARGET_IS_X86_32) || defined(LIBC_TARGET_IS_X86_64)
#define LIBC_TARGET_IS_X86
#endif

#if (defined(__arm__) || defined(_M_ARM))
#define LIBC_TARGET_IS_ARM
#endif

#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64)
#define LIBC_TARGET_IS_AARCH64
#endif

#if (defined(LIBC_TARGET_IS_AARCH64) || defined(LIBC_TARGET_IS_ARM))
#define LIBC_TARGET_IS_ANY_ARM
#endif

#endif // LLVM_LIBC_SUPPORT_MACROS_ARCHITECTURES_H
12 changes: 6 additions & 6 deletions libc/src/__support/threads/linux/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "src/__support/error_or.h"
#include "src/__support/threads/linux/futex_word.h" // For FutexWordType

#ifdef LLVM_LIBC_ARCH_AARCH64
#ifdef LIBC_TARGET_IS_AARCH64
#include <arm_acle.h>
#endif

Expand Down Expand Up @@ -99,14 +99,14 @@ __attribute__((always_inline)) inline uintptr_t get_start_args_addr() {
// NOTE: For __builtin_frame_address to work reliably across compilers,
// architectures and various optimization levels, the TU including this file
// should be compiled with -fno-omit-frame-pointer.
#ifdef LLVM_LIBC_ARCH_X86_64
#ifdef LIBC_TARGET_IS_X86_64
return reinterpret_cast<uintptr_t>(__builtin_frame_address(0))
// The x86_64 call instruction pushes resume address on to the stack.
// Next, The x86_64 SysV ABI requires that the frame pointer be pushed
// on to the stack. So, we have to step past two 64-bit values to get
// to the start args.
+ sizeof(uintptr_t) * 2;
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
// The frame pointer after cloning the new thread in the Thread::run method
// is set to the stack pointer where start args are stored. So, we fetch
// from there.
Expand Down Expand Up @@ -190,15 +190,15 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
// Also, we want the result of the syscall to be in a register as the child
// thread gets a completely different stack after it is created. The stack
// variables from this function will not be availalbe to the child thread.
#ifdef LLVM_LIBC_ARCH_X86_64
#ifdef LIBC_TARGET_IS_X86_64
long register clone_result asm("rax");
clone_result = __llvm_libc::syscall_impl(
SYS_clone, CLONE_SYSCALL_FLAGS, adjusted_stack,
&attrib->tid, // The address where the child tid is written
&clear_tid->val, // The futex where the child thread status is signalled
tls.tp // The thread pointer value for the new thread.
);
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
long register clone_result asm("x0");
clone_result = __llvm_libc::syscall_impl(
SYS_clone, CLONE_SYSCALL_FLAGS, adjusted_stack,
Expand All @@ -211,7 +211,7 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack,
#endif

if (clone_result == 0) {
#ifdef LLVM_LIBC_ARCH_AARCH64
#ifdef LIBC_TARGET_IS_AARCH64
// We set the frame pointer to be the same as the "sp" so that start args
// can be sniffed out from start_thread.
__arm_wsr64("x29", __arm_rsr64("sp"));
Expand Down
6 changes: 3 additions & 3 deletions libc/src/__support/threads/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#ifndef LLVM_LIBC_SRC_SUPPORT_THREADS_THREAD_H
#define LLVM_LIBC_SRC_SUPPORT_THREADS_THREAD_H

#include "src/__support/CPP/string_view.h"
#include "src/__support/CPP/atomic.h"
#include "src/__support/CPP/optional.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/CPP/stringstream.h"
#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"

#include <stddef.h> // For size_t
#include <stdint.h>
Expand All @@ -36,7 +36,7 @@ union ThreadReturnValue {
constexpr ThreadReturnValue(void *r) : posix_retval(r) {}
};

#if (defined(LLVM_LIBC_ARCH_AARCH64) || defined(LLVM_LIBC_ARCH_X86_64))
#if (defined(LIBC_TARGET_IS_AARCH64) || defined(LIBC_TARGET_IS_X86_64))
constexpr unsigned int STACK_ALIGNMENT = 16;
#endif
// TODO: Provide stack alignment requirements for other architectures.
Expand Down
6 changes: 3 additions & 3 deletions libc/src/setjmp/longjmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
//===----------------------------------------------------------------------===//

#include "src/setjmp/longjmp.h"
#include "src/__support/architectures.h"
#include "src/__support/common.h"
#include "src/__support/macros/architectures.h"

#include <setjmp.h>

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
#ifdef LLVM_LIBC_ARCH_X86_64
#ifdef LIBC_TARGET_IS_X86_64
register __UINT64_TYPE__ rbx __asm__("rbx");
register __UINT64_TYPE__ rbp __asm__("rbp");
register __UINT64_TYPE__ r12 __asm__("r12");
Expand All @@ -38,7 +38,7 @@ LLVM_LIBC_FUNCTION(void, longjmp, (__jmp_buf * buf, int val)) {
LIBC_INLINE_ASM("mov %1, %0\n\t" : "=r"(r15) : "m"(buf->r15) :);
LIBC_INLINE_ASM("mov %1, %0\n\t" : "=r"(rsp) : "m"(buf->rsp) :);
LIBC_INLINE_ASM("jmp *%0\n\t" : : "m"(buf->rip));
#else // LLVM_LIBC_ARCH_X86_64
#else // LIBC_TARGET_IS_X86_64
#error "longjmp implementation not available for the target architecture."
#endif
}
Expand Down
6 changes: 3 additions & 3 deletions libc/src/setjmp/setjmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/architectures.h"
#include "src/__support/common.h"
#include "src/__support/macros/architectures.h"
#include "src/setjmp/setjmp_impl.h"

#include <setjmp.h>

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
#ifdef LLVM_LIBC_ARCH_X86_64
#ifdef LIBC_TARGET_IS_X86_64
register __UINT64_TYPE__ rbx __asm__("rbx");
register __UINT64_TYPE__ r12 __asm__("r12");
register __UINT64_TYPE__ r13 __asm__("r13");
Expand Down Expand Up @@ -50,7 +50,7 @@ LLVM_LIBC_FUNCTION(int, setjmp, (__jmp_buf * buf)) {
buf->rsp = reinterpret_cast<__UINTPTR_TYPE__>(__builtin_frame_address(0)) +
sizeof(__UINTPTR_TYPE__) * 2;
buf->rip = reinterpret_cast<__UINTPTR_TYPE__>(__builtin_return_address(0));
#else // LLVM_LIBC_ARCH_X86_64
#else // LIBC_TARGET_IS_X86_64
#error "setjmp implementation not available for the target architecture."
#endif

Expand Down
22 changes: 11 additions & 11 deletions libc/src/string/memory_utils/bcmp_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BCMP_IMPLEMENTATIONS_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_BCMP_IMPLEMENTATIONS_H

#include "src/__support/architectures.h"
#include "src/__support/common.h"
#include "src/__support/macros/architectures.h"
#include "src/string/memory_utils/op_aarch64.h"
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
Expand All @@ -29,7 +29,7 @@ inline_bcmp_embedded_tiny(CPtr p1, CPtr p2, size_t count) {
return BcmpReturnType::ZERO();
}

#if defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE BcmpReturnType
inline_bcmp_generic_gt16(CPtr p1, CPtr p2, size_t count) {
if (count < 256)
Expand All @@ -39,9 +39,9 @@ inline_bcmp_generic_gt16(CPtr p1, CPtr p2, size_t count) {
align_to_next_boundary<64, Arg::P1>(p1, p2, count);
return generic::Bcmp<64>::loop_and_tail(p1, p2, count);
}
#endif // defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)

#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
[[maybe_unused]] LIBC_INLINE BcmpReturnType
inline_bcmp_x86_sse2_gt16(CPtr p1, CPtr p2, size_t count) {
if (count <= 32)
Expand Down Expand Up @@ -109,9 +109,9 @@ inline_bcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
else
return inline_bcmp_generic_gt16(p1, p2, count);
}
#endif // defined(LLVM_LIBC_ARCH_X86)
#endif // defined(LIBC_TARGET_IS_X86)

#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE BcmpReturnType inline_bcmp_aarch64(CPtr p1,
CPtr p2,
size_t count) {
Expand Down Expand Up @@ -158,16 +158,16 @@ inline_bcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
}
return aarch64::Bcmp<32>::loop_and_tail(p1, p2, count);
}
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

LIBC_INLINE BcmpReturnType inline_bcmp(CPtr p1, CPtr p2, size_t count) {
#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
return inline_bcmp_x86(p1, p2, count);
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
return inline_bcmp_aarch64(p1, p2, count);
#elif defined(LLVM_LIBC_ARCH_ARM)
#elif defined(LIBC_TARGET_IS_ARM)
return inline_bcmp_embedded_tiny(p1, p2, count);
#elif defined(LLVM_LIBC_ARCH_GPU)
#elif defined(LIBC_TARGET_IS_GPU)
return inline_bcmp_embedded_tiny(p1, p2, count);
#else
#error "Unsupported platform"
Expand Down
24 changes: 12 additions & 12 deletions libc/src/string/memory_utils/memcmp_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMCMP_IMPLEMENTATIONS_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMCMP_IMPLEMENTATIONS_H

#include "src/__support/architectures.h"
#include "src/__support/common.h"
#include "src/__support/macros/architectures.h"
#include "src/string/memory_utils/op_aarch64.h"
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
Expand All @@ -29,7 +29,7 @@ inline_memcmp_embedded_tiny(CPtr p1, CPtr p2, size_t count) {
return MemcmpReturnType::ZERO();
}

#if defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
inline_memcmp_generic_gt16(CPtr p1, CPtr p2, size_t count) {
if (unlikely(count >= 384)) {
Expand All @@ -39,9 +39,9 @@ inline_memcmp_generic_gt16(CPtr p1, CPtr p2, size_t count) {
}
return generic::Memcmp<16>::loop_and_tail(p1, p2, count);
}
#endif // defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)

#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
inline_memcmp_x86_sse2_gt16(CPtr p1, CPtr p2, size_t count) {
if (unlikely(count >= 384)) {
Expand Down Expand Up @@ -84,9 +84,9 @@ inline_memcmp_x86_avx512bw_gt16(CPtr p1, CPtr p2, size_t count) {
return x86::avx512bw::Memcmp<64>::loop_and_tail(p1, p2, count);
}

#endif // defined(LLVM_LIBC_ARCH_X86)
#endif // defined(LIBC_TARGET_IS_X86)

#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE MemcmpReturnType
inline_memcmp_aarch64_neon_gt16(CPtr p1, CPtr p2, size_t count) {
if (unlikely(count >= 128)) { // [128, ∞]
Expand All @@ -106,10 +106,10 @@ inline_memcmp_aarch64_neon_gt16(CPtr p1, CPtr p2, size_t count) {
// [64, 127]
return generic::Memcmp<16>::loop_and_tail(p1 + 32, p2 + 32, count - 32);
}
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

LIBC_INLINE MemcmpReturnType inline_memcmp(CPtr p1, CPtr p2, size_t count) {
#if defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)
if (count == 0)
return MemcmpReturnType::ZERO();
if (count == 1)
Expand All @@ -122,7 +122,7 @@ LIBC_INLINE MemcmpReturnType inline_memcmp(CPtr p1, CPtr p2, size_t count) {
return generic::Memcmp<4>::head_tail(p1, p2, count);
if (count <= 16)
return generic::Memcmp<8>::head_tail(p1, p2, count);
#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
if constexpr (x86::kAvx512BW)
return inline_memcmp_x86_avx512bw_gt16(p1, p2, count);
else if constexpr (x86::kAvx2)
Expand All @@ -131,15 +131,15 @@ LIBC_INLINE MemcmpReturnType inline_memcmp(CPtr p1, CPtr p2, size_t count) {
return inline_memcmp_x86_sse2_gt16(p1, p2, count);
else
return inline_memcmp_generic_gt16(p1, p2, count);
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
if constexpr (aarch64::kNeon)
return inline_memcmp_aarch64_neon_gt16(p1, p2, count);
else
return inline_memcmp_generic_gt16(p1, p2, count);
#endif
#elif defined(LLVM_LIBC_ARCH_ARM)
#elif defined(LIBC_TARGET_IS_ARM)
return inline_memcmp_embedded_tiny(p1, p2, count);
#elif defined(LLVM_LIBC_ARCH_GPU)
#elif defined(LIBC_TARGET_IS_GPU)
return inline_memcmp_embedded_tiny(p1, p2, count);
#else
#error "Unsupported platform"
Expand Down
18 changes: 9 additions & 9 deletions libc/src/string/memory_utils/memcpy_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY_IMPLEMENTATIONS_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY_IMPLEMENTATIONS_H

#include "src/__support/architectures.h"
#include "src/__support/common.h"
#include "src/__support/macros/architectures.h"
#include "src/string/memory_utils/op_aarch64.h"
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
Expand All @@ -29,7 +29,7 @@ inline_memcpy_embedded_tiny(Ptr __restrict dst, CPtr __restrict src,
builtin::Memcpy<1>::block(dst + offset, src + offset);
}

#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
[[maybe_unused]] LIBC_INLINE void
inline_memcpy_x86(Ptr __restrict dst, CPtr __restrict src, size_t count) {
if (count == 0)
Expand Down Expand Up @@ -86,9 +86,9 @@ inline_memcpy_x86_maybe_interpose_repmovsb(Ptr __restrict dst,
return inline_memcpy_x86(dst, src, count);
}
}
#endif // defined(LLVM_LIBC_ARCH_X86)
#endif // defined(LIBC_TARGET_IS_X86)

#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
[[maybe_unused]] LIBC_INLINE void
inline_memcpy_aarch64(Ptr __restrict dst, CPtr __restrict src, size_t count) {
if (count == 0)
Expand All @@ -115,18 +115,18 @@ inline_memcpy_aarch64(Ptr __restrict dst, CPtr __restrict src, size_t count) {
align_to_next_boundary<16, Arg::Src>(dst, src, count);
return builtin::Memcpy<64>::loop_and_tail(dst, src, count);
}
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

LIBC_INLINE void inline_memcpy(Ptr __restrict dst, CPtr __restrict src,
size_t count) {
using namespace __llvm_libc::builtin;
#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
return inline_memcpy_x86_maybe_interpose_repmovsb(dst, src, count);
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
return inline_memcpy_aarch64(dst, src, count);
#elif defined(LLVM_LIBC_ARCH_ARM)
#elif defined(LIBC_TARGET_IS_ARM)
return inline_memcpy_embedded_tiny(dst, src, count);
#elif defined(LLVM_LIBC_ARCH_GPU)
#elif defined(LIBC_TARGET_IS_GPU)
return inline_memcpy_embedded_tiny(dst, src, count);
#else
#error "Unsupported platform"
Expand Down
10 changes: 5 additions & 5 deletions libc/src/string/memory_utils/memmove_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ template <size_t MaxSize>
}

LIBC_INLINE void inline_memmove(Ptr dst, CPtr src, size_t count) {
#if defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86) || defined(LIBC_TARGET_IS_AARCH64)
#if defined(LIBC_TARGET_IS_X86)
static constexpr size_t kMaxSize = x86::kAvx512F ? 64
: x86::kAvx ? 32
: x86::kSse2 ? 16
: 8;
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
static constexpr size_t kMaxSize = aarch64::kNeon ? 16 : 8;
#endif
// return inline_memmove_generic<kMaxSize>(dst, src, count);
Expand Down Expand Up @@ -101,9 +101,9 @@ LIBC_INLINE void inline_memmove(Ptr dst, CPtr src, size_t count) {
return generic::Memmove<64, kMaxSize>::loop_and_tail_backward(dst, src,
count);
}
#elif defined(LLVM_LIBC_ARCH_ARM)
#elif defined(LIBC_TARGET_IS_ARM)
return inline_memmove_embedded_tiny(dst, src, count);
#elif defined(LLVM_LIBC_ARCH_GPU)
#elif defined(LIBC_TARGET_IS_GPU)
return inline_memmove_embedded_tiny(dst, src, count);
#else
#error "Unsupported platform"
Expand Down
18 changes: 9 additions & 9 deletions libc/src/string/memory_utils/memset_implementations.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H

#include "src/__support/architectures.h"
#include "src/__support/common.h"
#include "src/__support/macros/architectures.h"
#include "src/string/memory_utils/op_aarch64.h"
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
Expand All @@ -28,7 +28,7 @@ inline_memset_embedded_tiny(Ptr dst, uint8_t value, size_t count) {
generic::Memset<1, 1>::block(dst + offset, value);
}

#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
template <size_t MaxSize>
[[maybe_unused]] LIBC_INLINE static void
inline_memset_x86(Ptr dst, uint8_t value, size_t count) {
Expand All @@ -55,9 +55,9 @@ inline_memset_x86(Ptr dst, uint8_t value, size_t count) {
align_to_next_boundary<32>(dst, count);
return generic::Memset<32, MaxSize>::loop_and_tail(dst, value, count);
}
#endif // defined(LLVM_LIBC_ARCH_X86)
#endif // defined(LIBC_TARGET_IS_X86)

#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
template <size_t MaxSize>
[[maybe_unused]] LIBC_INLINE static void
inline_memset_aarch64(Ptr dst, uint8_t value, size_t count) {
Expand Down Expand Up @@ -93,21 +93,21 @@ inline_memset_aarch64(Ptr dst, uint8_t value, size_t count) {
return generic::Memset<64, MaxSize>::loop_and_tail(dst, value, count);
}
}
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

LIBC_INLINE static void inline_memset(Ptr dst, uint8_t value, size_t count) {
#if defined(LLVM_LIBC_ARCH_X86)
#if defined(LIBC_TARGET_IS_X86)
static constexpr size_t kMaxSize = x86::kAvx512F ? 64
: x86::kAvx ? 32
: x86::kSse2 ? 16
: 8;
return inline_memset_x86<kMaxSize>(dst, value, count);
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
static constexpr size_t kMaxSize = aarch64::kNeon ? 16 : 8;
return inline_memset_aarch64<kMaxSize>(dst, value, count);
#elif defined(LLVM_LIBC_ARCH_ARM)
#elif defined(LIBC_TARGET_IS_ARM)
return inline_memset_embedded_tiny(dst, value, count);
#elif defined(LLVM_LIBC_ARCH_GPU)
#elif defined(LIBC_TARGET_IS_GPU)
return inline_memset_embedded_tiny(dst, value, count);
#else
#error "Unsupported platform"
Expand Down
6 changes: 3 additions & 3 deletions libc/src/string/memory_utils/op_aarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_AARCH64_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_AARCH64_H

#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"

#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)

#include "src/__support/common.h"
#include "src/string/memory_utils/op_generic.h"
Expand Down Expand Up @@ -174,6 +174,6 @@ template <size_t Size> struct Bcmp {

} // namespace __llvm_libc::aarch64

#endif // LLVM_LIBC_ARCH_AARCH64
#endif // LIBC_TARGET_IS_AARCH64

#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_AARCH64_H
2 changes: 1 addition & 1 deletion libc/src/string/memory_utils/op_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ static_assert((UINTPTR_MAX == 4294967295U) ||
(UINTPTR_MAX == 18446744073709551615UL),
"We currently only support 32- or 64-bit platforms");

#if defined(LLVM_LIBC_ARCH_X86_64) || defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_X86_64) || defined(LIBC_TARGET_IS_AARCH64)
#define LLVM_LIBC_HAS_UINT64
#endif

Expand Down
6 changes: 3 additions & 3 deletions libc/src/string/memory_utils/op_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_X86_H
#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_X86_H

#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"

#if defined(LLVM_LIBC_ARCH_X86_64)
#if defined(LIBC_TARGET_IS_X86_64)

#include "src/__support/common.h"
#include "src/string/memory_utils/op_builtin.h"
Expand Down Expand Up @@ -269,6 +269,6 @@ template <size_t Size> using Memcmp = MemcmpImpl<Size, 64, memcmp64, bcmp64>;

} // namespace __llvm_libc::x86

#endif // LLVM_LIBC_ARCH_X86_64
#endif // LIBC_TARGET_IS_X86_64

#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_OP_X86_H
4 changes: 2 additions & 2 deletions libc/src/threads/linux/Futex.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
#ifndef LLVM_LIBC_SRC_THREADS_LINUX_FUTEX_H
#define LLVM_LIBC_SRC_THREADS_LINUX_FUTEX_H

#include "src/__support/architectures.h" // Architecture macros
#include "src/__support/macros/architectures.h" // Architecture macros

namespace __llvm_libc {

#if (defined(LLVM_LIBC_ARCH_AARCH64) || defined(LLVM_LIBC_ARCH_X86_64))
#if (defined(LIBC_TARGET_IS_AARCH64) || defined(LIBC_TARGET_IS_X86_64))
// The futex data has to be exactly 4 bytes long. However, we use a uint type
// here as we do not want to use `uint32_t` type to match the public definitions
// of types which include a field for a futex word. With public definitions, we
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/fenv/enabled_exceptions_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "src/fenv/fetestexcept.h"

#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"
#include "utils/UnitTest/FPExceptMatcher.h"
#include "utils/UnitTest/Test.h"

Expand All @@ -21,7 +21,7 @@
// This test enables an exception and verifies that raising that exception
// triggers SIGFPE.
TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
// Few aarch64 HW implementations do not trap exceptions. We skip this test
// completely on such HW.
//
Expand All @@ -33,7 +33,7 @@ TEST(LlvmLibcExceptionStatusTest, RaiseAndCrash) {
__llvm_libc::fputil::enable_except(FE_DIVBYZERO);
if (__llvm_libc::fputil::get_except() == 0)
return;
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

// TODO: Install a floating point exception handler and verify that the
// the expected exception was raised. One will have to longjmp back from
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/fenv/feenableexcept_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
//===----------------------------------------------------------------------===//

#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"
#include "src/fenv/fedisableexcept.h"
#include "src/fenv/feenableexcept.h"
#include "src/fenv/fegetexcept.h"
Expand All @@ -16,7 +16,7 @@
#include <fenv.h>

TEST(LlvmLibcFEnvTest, EnableTest) {
#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
// Few aarch64 HW implementations do not trap exceptions. We skip this test
// completely on such HW.
//
Expand All @@ -28,7 +28,7 @@ TEST(LlvmLibcFEnvTest, EnableTest) {
__llvm_libc::feenableexcept(FE_DIVBYZERO);
if (__llvm_libc::fegetexcept() == 0)
return;
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
FE_UNDERFLOW};
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/fenv/feholdexcept_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#include "src/fenv/feholdexcept.h"

#include "src/__support/FPUtil/FEnvImpl.h"
#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"
#include "utils/UnitTest/FPExceptMatcher.h"
#include "utils/UnitTest/Test.h"

#include <fenv.h>

TEST(LlvmLibcFEnvTest, RaiseAndCrash) {
#if defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_AARCH64)
// Few aarch64 HW implementations do not trap exceptions. We skip this test
// completely on such HW.
//
Expand All @@ -28,7 +28,7 @@ TEST(LlvmLibcFEnvTest, RaiseAndCrash) {
__llvm_libc::fputil::enable_except(FE_DIVBYZERO);
if (__llvm_libc::fputil::get_except() == 0)
return;
#endif // defined(LLVM_LIBC_ARCH_AARCH64)
#endif // defined(LIBC_TARGET_IS_AARCH64)

int excepts[] = {FE_DIVBYZERO, FE_INVALID, FE_INEXACT, FE_OVERFLOW,
FE_UNDERFLOW};
Expand Down
4 changes: 2 additions & 2 deletions libc/test/src/string/memory_utils/op_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#include <assert.h>

#if defined(LLVM_LIBC_ARCH_X86_64) || defined(LLVM_LIBC_ARCH_AARCH64)
#if defined(LIBC_TARGET_IS_X86_64) || defined(LIBC_TARGET_IS_AARCH64)
#define LLVM_LIBC_HAS_UINT64
#endif

Expand Down Expand Up @@ -200,7 +200,7 @@ using BcmpImplementations = testing::TypeList<
x86::avx512bw::Bcmp<64>, //
x86::avx512bw::Bcmp<128>, //
#endif
#ifdef LLVM_LIBC_ARCH_AARCH64
#ifdef LIBC_TARGET_IS_AARCH64
aarch64::Bcmp<16>, //
aarch64::Bcmp<32>, //
#endif
Expand Down
6 changes: 3 additions & 3 deletions libc/test/src/sys/utsname/uname_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//

#include "src/__support/CPP/string_view.h"
#include "src/__support/architectures.h"
#include "src/__support/macros/architectures.h"
#include "src/sys/utsname/uname.h"
#include "test/ErrnoSetterMatcher.h"
#include "utils/UnitTest/Test.h"
Expand All @@ -18,9 +18,9 @@
TEST(LlvmLibcUnameTest, GetMachineName) {
struct utsname names;
ASSERT_GE(__llvm_libc::uname(&names), 0);
#ifdef LLVM_LIBC_ARCH_X86_64
#ifdef LIBC_TARGET_IS_X86_64
ASSERT_STREQ(names.machine, "x86_64");
#elif defined(LLVM_LIBC_ARCH_AARCH64)
#elif defined(LIBC_TARGET_IS_AARCH64)
ASSERT_STREQ(names.machine, "aarch64");
#endif
}
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ libc_support_library(
libc_support_library(
name = "__support_common",
hdrs = [
"src/__support/architectures.h",
"src/__support/macros/architectures.h",
"src/__support/common.h",
"src/__support/cpu_features.h",
"src/__support/endian.h",
Expand Down