From 1637351fd125c9a8236602c2aefdac0b64c7db75 Mon Sep 17 00:00:00 2001 From: Guillaume Chatelet Date: Tue, 7 Feb 2023 10:19:12 +0000 Subject: [PATCH] [libc][NFC] Rename architecture macros and move to macros folder --- libc/config/linux/app.h | 4 +- libc/src/__support/CMakeLists.txt | 2 +- libc/src/__support/FPUtil/FEnvImpl.h | 6 +-- libc/src/__support/FPUtil/FMA.h | 6 +-- libc/src/__support/FPUtil/PlatformDefs.h | 4 +- libc/src/__support/FPUtil/aarch64/FEnvImpl.h | 4 +- libc/src/__support/FPUtil/aarch64/FMA.h | 4 +- .../__support/FPUtil/aarch64/fenv_darwin_impl.h | 4 +- .../src/__support/FPUtil/aarch64/nearest_integer.h | 4 +- libc/src/__support/FPUtil/aarch64/sqrt.h | 4 +- libc/src/__support/FPUtil/multiply_add.h | 2 +- libc/src/__support/FPUtil/nearest_integer.h | 6 +-- libc/src/__support/FPUtil/sqrt.h | 6 +-- libc/src/__support/FPUtil/x86_64/FEnvImpl.h | 4 +- libc/src/__support/FPUtil/x86_64/FMA.h | 4 +- libc/src/__support/FPUtil/x86_64/LongDoubleBits.h | 4 +- .../__support/FPUtil/x86_64/NextAfterLongDouble.h | 4 +- libc/src/__support/FPUtil/x86_64/PolyEval.h | 4 +- libc/src/__support/FPUtil/x86_64/nearest_integer.h | 4 +- libc/src/__support/FPUtil/x86_64/sqrt.h | 4 +- libc/src/__support/OSUtil/linux/syscall.h | 8 ++-- libc/src/__support/architectures.h | 52 ---------------------- libc/src/__support/macros/README.md | 6 +++ libc/src/__support/macros/architectures.h | 52 ++++++++++++++++++++++ libc/src/__support/threads/linux/thread.cpp | 12 ++--- libc/src/__support/threads/thread.h | 6 +-- libc/src/setjmp/longjmp.cpp | 6 +-- libc/src/setjmp/setjmp.cpp | 6 +-- .../src/string/memory_utils/bcmp_implementations.h | 22 ++++----- .../string/memory_utils/memcmp_implementations.h | 24 +++++----- .../string/memory_utils/memcpy_implementations.h | 18 ++++---- .../string/memory_utils/memmove_implementations.h | 10 ++--- .../string/memory_utils/memset_implementations.h | 18 ++++---- libc/src/string/memory_utils/op_aarch64.h | 6 +-- libc/src/string/memory_utils/op_generic.h | 2 +- libc/src/string/memory_utils/op_x86.h | 6 +-- libc/src/threads/linux/Futex.h | 4 +- libc/test/src/fenv/enabled_exceptions_test.cpp | 6 +-- libc/test/src/fenv/feenableexcept_test.cpp | 6 +-- libc/test/src/fenv/feholdexcept_test.cpp | 6 +-- libc/test/src/string/memory_utils/op_tests.cpp | 4 +- libc/test/src/sys/utsname/uname_test.cpp | 6 +-- utils/bazel/llvm-project-overlay/libc/BUILD.bazel | 2 +- 43 files changed, 189 insertions(+), 183 deletions(-) delete mode 100644 libc/src/__support/architectures.h create mode 100644 libc/src/__support/macros/README.md create mode 100644 libc/src/__support/macros/architectures.h diff --git a/libc/config/linux/app.h b/libc/config/linux/app.h index c4cf6df..67a3624 100644 --- a/libc/config/linux/app.h +++ b/libc/config/linux/app.h @@ -9,7 +9,7 @@ #ifndef LLVM_LIBC_CONFIG_LINUX_APP_H #define LLVM_LIBC_CONFIG_LINUX_APP_H -#include "src/__support/architectures.h" +#include "src/__support/macros/architectures.h" #include @@ -35,7 +35,7 @@ struct TLSImage { uintptr_t align; }; -#if defined(LLVM_LIBC_ARCH_X86_64) || defined(LLVM_LIBC_ARCH_AARCH64) +#if defined(LIBC_TARGET_IS_X86_64) || defined(LIBC_TARGET_IS_AARCH64) // At the language level, argc is an int. But we use uint64_t as the x86_64 // ABI specifies it as an 8 byte value. Likewise, in the ARM64 ABI, arguments // are usually passed in registers. x0 is a doubleword register, so this is diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt index daaabca..7d68137 100644 --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -31,7 +31,7 @@ add_header_library( add_header_library( common HDRS - architectures.h + macros/architectures.h common.h cpu_features.h endian.h diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h index 85818a6..6d060b8 100644 --- a/libc/src/__support/FPUtil/FEnvImpl.h +++ b/libc/src/__support/FPUtil/FEnvImpl.h @@ -9,16 +9,16 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_FENVIMPL_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_FENVIMPL_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if defined(LLVM_LIBC_ARCH_AARCH64) +#if defined(LIBC_TARGET_IS_AARCH64) #if defined(__APPLE__) #include "aarch64/fenv_darwin_impl.h" #else #include "aarch64/FEnvImpl.h" #endif -#elif defined(LLVM_LIBC_ARCH_X86) +#elif defined(LIBC_TARGET_IS_X86) #include "x86_64/FEnvImpl.h" #else #include diff --git a/libc/src/__support/FPUtil/FMA.h b/libc/src/__support/FPUtil/FMA.h index 7b0dbe4..68bb952 100644 --- a/libc/src/__support/FPUtil/FMA.h +++ b/libc/src/__support/FPUtil/FMA.h @@ -9,15 +9,15 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_FMA_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_FMA_H -#include "src/__support/architectures.h" #include "src/__support/common.h" #include "src/__support/cpu_features.h" +#include "src/__support/macros/architectures.h" #if defined(LIBC_TARGET_HAS_FMA) -#if defined(LLVM_LIBC_ARCH_X86_64) +#if defined(LIBC_TARGET_IS_X86_64) #include "x86_64/FMA.h" -#elif defined(LLVM_LIBC_ARCH_AARCH64) +#elif defined(LIBC_TARGET_IS_AARCH64) #include "aarch64/FMA.h" #endif diff --git a/libc/src/__support/FPUtil/PlatformDefs.h b/libc/src/__support/FPUtil/PlatformDefs.h index 6f22bc3..3d97b10 100644 --- a/libc/src/__support/FPUtil/PlatformDefs.h +++ b/libc/src/__support/FPUtil/PlatformDefs.h @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_PLATFORM_DEFS_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_PLATFORM_DEFS_H -#include "src/__support/architectures.h" +#include "src/__support/macros/architectures.h" -#if defined(LLVM_LIBC_ARCH_X86) +#if defined(LIBC_TARGET_IS_X86) #define X87_FPU #endif diff --git a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h index c82d1be..03730dd 100644 --- a/libc/src/__support/FPUtil/aarch64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/aarch64/FEnvImpl.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FENVIMPL_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FENVIMPL_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_AARCH64) || defined(__APPLE__) +#if !defined(LIBC_TARGET_IS_AARCH64) || defined(__APPLE__) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/aarch64/FMA.h b/libc/src/__support/FPUtil/aarch64/FMA.h index 1591c9b..0f319a7 100644 --- a/libc/src/__support/FPUtil/aarch64/FMA.h +++ b/libc/src/__support/FPUtil/aarch64/FMA.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FMA_H -#include "src/__support/architectures.h" #include "src/__support/cpu_features.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_AARCH64) +#if !defined(LIBC_TARGET_IS_AARCH64) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h index a916dc5..da7b44d 100644 --- a/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h +++ b/libc/src/__support/FPUtil/aarch64/fenv_darwin_impl.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FENV_DARWIN_IMPL_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_FENV_DARWIN_IMPL_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_AARCH64) || !defined(__APPLE__) +#if !defined(LIBC_TARGET_IS_AARCH64) || !defined(__APPLE__) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/aarch64/nearest_integer.h b/libc/src/__support/FPUtil/aarch64/nearest_integer.h index 1d94e66..351e147 100644 --- a/libc/src/__support/FPUtil/aarch64/nearest_integer.h +++ b/libc/src/__support/FPUtil/aarch64/nearest_integer.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_NEAREST_INTEGER_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_NEAREST_INTEGER_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_AARCH64) +#if !defined(LIBC_TARGET_IS_AARCH64) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/aarch64/sqrt.h b/libc/src/__support/FPUtil/aarch64/sqrt.h index 2a8912e..b6e3f68 100644 --- a/libc/src/__support/FPUtil/aarch64/sqrt.h +++ b/libc/src/__support/FPUtil/aarch64/sqrt.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_SQRT_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_AARCH64_SQRT_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_AARCH64) +#if !defined(LIBC_TARGET_IS_AARCH64) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/multiply_add.h b/libc/src/__support/FPUtil/multiply_add.h index aef102e..f2db759 100644 --- a/libc/src/__support/FPUtil/multiply_add.h +++ b/libc/src/__support/FPUtil/multiply_add.h @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_MULTIPLY_ADD_H -#include "src/__support/architectures.h" #include "src/__support/common.h" #include "src/__support/cpu_features.h" +#include "src/__support/macros/architectures.h" namespace __llvm_libc { namespace fputil { diff --git a/libc/src/__support/FPUtil/nearest_integer.h b/libc/src/__support/FPUtil/nearest_integer.h index bf2bf4b..4ff19ca 100644 --- a/libc/src/__support/FPUtil/nearest_integer.h +++ b/libc/src/__support/FPUtil/nearest_integer.h @@ -9,12 +9,12 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_NEAREST_INTEGER_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_NEAREST_INTEGER_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if (defined(LLVM_LIBC_ARCH_X86_64) && defined(__SSE4_2__)) +#if (defined(LIBC_TARGET_IS_X86_64) && defined(__SSE4_2__)) #include "x86_64/nearest_integer.h" -#elif defined(LLVM_LIBC_ARCH_AARCH64) +#elif defined(LIBC_TARGET_IS_AARCH64) #include "aarch64/nearest_integer.h" #else diff --git a/libc/src/__support/FPUtil/sqrt.h b/libc/src/__support/FPUtil/sqrt.h index 6e02d9c..5c48967 100644 --- a/libc/src/__support/FPUtil/sqrt.h +++ b/libc/src/__support/FPUtil/sqrt.h @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_SQRT_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_SQRT_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 "x86_64/sqrt.h" -#elif defined(LLVM_LIBC_ARCH_AARCH64) +#elif defined(LIBC_TARGET_IS_AARCH64) #include "aarch64/sqrt.h" #else #include "generic/sqrt.h" diff --git a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h index 5c30ee3..d80fa5b 100644 --- a/libc/src/__support/FPUtil/x86_64/FEnvImpl.h +++ b/libc/src/__support/FPUtil/x86_64/FEnvImpl.h @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FENVIMPL_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FENVIMPL_H -#include "src/__support/architectures.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86) +#if !defined(LIBC_TARGET_IS_X86) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/x86_64/FMA.h b/libc/src/__support/FPUtil/x86_64/FMA.h index 43b1443..466f413 100644 --- a/libc/src/__support/FPUtil/x86_64/FMA.h +++ b/libc/src/__support/FPUtil/x86_64/FMA.h @@ -9,11 +9,11 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FMA_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_FMA_H -#include "src/__support/architectures.h" #include "src/__support/common.h" #include "src/__support/cpu_features.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86_64) +#if !defined(LIBC_TARGET_IS_X86_64) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h index 2c49a48..1833091 100644 --- a/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h +++ b/libc/src/__support/FPUtil/x86_64/LongDoubleBits.h @@ -11,10 +11,10 @@ #include "src/__support/CPP/bit.h" #include "src/__support/UInt128.h" -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86) +#if !defined(LIBC_TARGET_IS_X86) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h index 8d3dd30..1b8d95d 100644 --- a/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h +++ b/libc/src/__support/FPUtil/x86_64/NextAfterLongDouble.h @@ -9,9 +9,9 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEXT_AFTER_LONG_DOUBLE_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEXT_AFTER_LONG_DOUBLE_H -#include "src/__support/architectures.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86) +#if !defined(LIBC_TARGET_IS_X86) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/x86_64/PolyEval.h b/libc/src/__support/FPUtil/x86_64/PolyEval.h index d6cd28d..d38af43 100644 --- a/libc/src/__support/FPUtil/x86_64/PolyEval.h +++ b/libc/src/__support/FPUtil/x86_64/PolyEval.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_POLYEVAL_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_POLYEVAL_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86_64) +#if !defined(LIBC_TARGET_IS_X86_64) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/x86_64/nearest_integer.h b/libc/src/__support/FPUtil/x86_64/nearest_integer.h index f9a2a6a..12fe62e 100644 --- a/libc/src/__support/FPUtil/x86_64/nearest_integer.h +++ b/libc/src/__support/FPUtil/x86_64/nearest_integer.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEAREST_INTEGER_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_NEAREST_INTEGER_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86_64) +#if !defined(LIBC_TARGET_IS_X86_64) #error "Invalid include" #endif diff --git a/libc/src/__support/FPUtil/x86_64/sqrt.h b/libc/src/__support/FPUtil/x86_64/sqrt.h index 07009d6..0ee57b0 100644 --- a/libc/src/__support/FPUtil/x86_64/sqrt.h +++ b/libc/src/__support/FPUtil/x86_64/sqrt.h @@ -9,10 +9,10 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H #define LLVM_LIBC_SRC_SUPPORT_FPUTIL_X86_64_SQRT_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#if !defined(LLVM_LIBC_ARCH_X86) +#if !defined(LIBC_TARGET_IS_X86) #error "Invalid include" #endif diff --git a/libc/src/__support/OSUtil/linux/syscall.h b/libc/src/__support/OSUtil/linux/syscall.h index d4defd3..ff9810e 100644 --- a/libc/src/__support/OSUtil/linux/syscall.h +++ b/libc/src/__support/OSUtil/linux/syscall.h @@ -9,14 +9,14 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H #define LLVM_LIBC_SRC_SUPPORT_OSUTIL_LINUX_SYSCALL_H -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" -#ifdef LLVM_LIBC_ARCH_X86_64 +#ifdef LIBC_TARGET_IS_X86_64 #include "x86_64/syscall.h" -#elif defined(LLVM_LIBC_ARCH_AARCH64) +#elif defined(LIBC_TARGET_IS_AARCH64) #include "aarch64/syscall.h" -#elif defined(LLVM_LIBC_ARCH_ARM) +#elif defined(LIBC_TARGET_IS_ARM) #include "arm/syscall.h" #endif diff --git a/libc/src/__support/architectures.h b/libc/src/__support/architectures.h deleted file mode 100644 index af97469..0000000 --- a/libc/src/__support/architectures.h +++ /dev/null @@ -1,52 +0,0 @@ -//===-- 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_ARCHITECTURES_H -#define LLVM_LIBC_SUPPORT_ARCHITECTURES_H - -#if defined(__AMDGPU__) -#define LLVM_LIBC_ARCH_AMDGPU -#endif - -#if defined(__NVPTX__) -#define LLVM_LIBC_ARCH_NVPTX -#endif - -#if defined(LLVM_LIBC_ARCH_NVPTX) || defined(LLVM_LIBC_ARCH_AMDGPU) -#define LLVM_LIBC_ARCH_GPU -#endif - -#if defined(__pnacl__) || defined(__CLR_VER) || defined(LLVM_LIBC_ARCH_GPU) -#define LLVM_LIBC_ARCH_VM -#endif - -#if (defined(_M_IX86) || defined(__i386__)) && !defined(LLVM_LIBC_ARCH_VM) -#define LLVM_LIBC_ARCH_X86_32 -#endif - -#if (defined(_M_X64) || defined(__x86_64__)) && !defined(LLVM_LIBC_ARCH_VM) -#define LLVM_LIBC_ARCH_X86_64 -#endif - -#if defined(LLVM_LIBC_ARCH_X86_32) || defined(LLVM_LIBC_ARCH_X86_64) -#define LLVM_LIBC_ARCH_X86 -#endif - -#if (defined(__arm__) || defined(_M_ARM)) -#define LLVM_LIBC_ARCH_ARM -#endif - -#if defined(__aarch64__) || defined(__arm64__) || defined(_M_ARM64) -#define LLVM_LIBC_ARCH_AARCH64 -#endif - -#if (defined(LLVM_LIBC_ARCH_AARCH64) || defined(LLVM_LIBC_ARCH_ARM)) -#define LLVM_LIBC_ARCH_ANY_ARM -#endif - -#endif // LLVM_LIBC_SUPPORT_ARCHITECTURES_H diff --git a/libc/src/__support/macros/README.md b/libc/src/__support/macros/README.md new file mode 100644 index 0000000..d9a008d --- /dev/null +++ b/libc/src/__support/macros/README.md @@ -0,0 +1,6 @@ +This folder contains freestanding header only files. + +They define macros either properties or attributes. + +Properties are derived from existing preprocessor definitions and present a +uniform presentation of the target for which we build. diff --git a/libc/src/__support/macros/architectures.h b/libc/src/__support/macros/architectures.h new file mode 100644 index 0000000..234ed3e --- /dev/null +++ b/libc/src/__support/macros/architectures.h @@ -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 diff --git a/libc/src/__support/threads/linux/thread.cpp b/libc/src/__support/threads/linux/thread.cpp index 62e24e5..599082a 100644 --- a/libc/src/__support/threads/linux/thread.cpp +++ b/libc/src/__support/threads/linux/thread.cpp @@ -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 #endif @@ -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(__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. @@ -190,7 +190,7 @@ 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, @@ -198,7 +198,7 @@ int Thread::run(ThreadStyle style, ThreadRunner runner, void *arg, void *stack, &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, @@ -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")); diff --git a/libc/src/__support/threads/thread.h b/libc/src/__support/threads/thread.h index 0ac2a06..fe95d8f 100644 --- a/libc/src/__support/threads/thread.h +++ b/libc/src/__support/threads/thread.h @@ -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 // For size_t #include @@ -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. diff --git a/libc/src/setjmp/longjmp.cpp b/libc/src/setjmp/longjmp.cpp index 9d2d783..da323dd 100644 --- a/libc/src/setjmp/longjmp.cpp +++ b/libc/src/setjmp/longjmp.cpp @@ -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 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"); @@ -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 } diff --git a/libc/src/setjmp/setjmp.cpp b/libc/src/setjmp/setjmp.cpp index 11d2d70..9506eda 100644 --- a/libc/src/setjmp/setjmp.cpp +++ b/libc/src/setjmp/setjmp.cpp @@ -6,8 +6,8 @@ // //===----------------------------------------------------------------------===// -#include "src/__support/architectures.h" #include "src/__support/common.h" +#include "src/__support/macros/architectures.h" #include "src/setjmp/setjmp_impl.h" #include @@ -15,7 +15,7 @@ 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"); @@ -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 diff --git a/libc/src/string/memory_utils/bcmp_implementations.h b/libc/src/string/memory_utils/bcmp_implementations.h index 4e31cc9..f3622dd 100644 --- a/libc/src/string/memory_utils/bcmp_implementations.h +++ b/libc/src/string/memory_utils/bcmp_implementations.h @@ -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" @@ -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) @@ -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) @@ -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) { @@ -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" diff --git a/libc/src/string/memory_utils/memcmp_implementations.h b/libc/src/string/memory_utils/memcmp_implementations.h index 1f0f5b9..e9fed02 100644 --- a/libc/src/string/memory_utils/memcmp_implementations.h +++ b/libc/src/string/memory_utils/memcmp_implementations.h @@ -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" @@ -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)) { @@ -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)) { @@ -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, ∞] @@ -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) @@ -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) @@ -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" diff --git a/libc/src/string/memory_utils/memcpy_implementations.h b/libc/src/string/memory_utils/memcpy_implementations.h index 23abdb8..7af309f 100644 --- a/libc/src/string/memory_utils/memcpy_implementations.h +++ b/libc/src/string/memory_utils/memcpy_implementations.h @@ -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" @@ -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) @@ -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) @@ -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" diff --git a/libc/src/string/memory_utils/memmove_implementations.h b/libc/src/string/memory_utils/memmove_implementations.h index 0444aed..d6b7e63 100644 --- a/libc/src/string/memory_utils/memmove_implementations.h +++ b/libc/src/string/memory_utils/memmove_implementations.h @@ -66,13 +66,13 @@ template } 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(dst, src, count); @@ -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" diff --git a/libc/src/string/memory_utils/memset_implementations.h b/libc/src/string/memory_utils/memset_implementations.h index c9d047c..2640bd2 100644 --- a/libc/src/string/memory_utils/memset_implementations.h +++ b/libc/src/string/memory_utils/memset_implementations.h @@ -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" @@ -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 [[maybe_unused]] LIBC_INLINE static void inline_memset_x86(Ptr dst, uint8_t value, size_t count) { @@ -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 [[maybe_unused]] LIBC_INLINE static void inline_memset_aarch64(Ptr dst, uint8_t value, size_t count) { @@ -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(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(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" diff --git a/libc/src/string/memory_utils/op_aarch64.h b/libc/src/string/memory_utils/op_aarch64.h index 3d625c2..ac0d956 100644 --- a/libc/src/string/memory_utils/op_aarch64.h +++ b/libc/src/string/memory_utils/op_aarch64.h @@ -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" @@ -174,6 +174,6 @@ template 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 diff --git a/libc/src/string/memory_utils/op_generic.h b/libc/src/string/memory_utils/op_generic.h index 3d505fb..70d234d 100644 --- a/libc/src/string/memory_utils/op_generic.h +++ b/libc/src/string/memory_utils/op_generic.h @@ -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 diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h index dd96e9c..5310255 100644 --- a/libc/src/string/memory_utils/op_x86.h +++ b/libc/src/string/memory_utils/op_x86.h @@ -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" @@ -269,6 +269,6 @@ template using Memcmp = MemcmpImpl; } // 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 diff --git a/libc/src/threads/linux/Futex.h b/libc/src/threads/linux/Futex.h index fab1b6d..8030092 100644 --- a/libc/src/threads/linux/Futex.h +++ b/libc/src/threads/linux/Futex.h @@ -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 diff --git a/libc/test/src/fenv/enabled_exceptions_test.cpp b/libc/test/src/fenv/enabled_exceptions_test.cpp index 75e3cda..c51a00c 100644 --- a/libc/test/src/fenv/enabled_exceptions_test.cpp +++ b/libc/test/src/fenv/enabled_exceptions_test.cpp @@ -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" @@ -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. // @@ -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 diff --git a/libc/test/src/fenv/feenableexcept_test.cpp b/libc/test/src/fenv/feenableexcept_test.cpp index f1cb8a3..910702f 100644 --- a/libc/test/src/fenv/feenableexcept_test.cpp +++ b/libc/test/src/fenv/feenableexcept_test.cpp @@ -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" @@ -16,7 +16,7 @@ #include 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. // @@ -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}; diff --git a/libc/test/src/fenv/feholdexcept_test.cpp b/libc/test/src/fenv/feholdexcept_test.cpp index 99df0bb..f3c4e12 100644 --- a/libc/test/src/fenv/feholdexcept_test.cpp +++ b/libc/test/src/fenv/feholdexcept_test.cpp @@ -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 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. // @@ -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}; diff --git a/libc/test/src/string/memory_utils/op_tests.cpp b/libc/test/src/string/memory_utils/op_tests.cpp index fdfe9d9..8b54cfe 100644 --- a/libc/test/src/string/memory_utils/op_tests.cpp +++ b/libc/test/src/string/memory_utils/op_tests.cpp @@ -15,7 +15,7 @@ #include -#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 @@ -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 diff --git a/libc/test/src/sys/utsname/uname_test.cpp b/libc/test/src/sys/utsname/uname_test.cpp index 1a1e4a7..ffe63cf 100644 --- a/libc/test/src/sys/utsname/uname_test.cpp +++ b/libc/test/src/sys/utsname/uname_test.cpp @@ -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" @@ -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 } diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel index 9b189df..4e24360 100644 --- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel @@ -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", -- 2.7.4