diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt --- a/libc/CMakeLists.txt +++ b/libc/CMakeLists.txt @@ -19,7 +19,8 @@ set(LIBC_TARGET_OS ${CMAKE_SYSTEM_NAME}) string(TOLOWER ${LIBC_TARGET_OS} LIBC_TARGET_OS) -set(LIBC_TARGET_MACHINE ${CMAKE_SYSTEM_PROCESSOR}) +# Defines LIBC_TARGET_ARCHITECTURE and associated macros. +include(LLVMLibCArchitectures) # Check --print-resource-dir to find the compiler resource dir if this flag # is supported by the compiler. @@ -70,8 +71,8 @@ include(LLVMLibCRules) include(LLVMLibCCheckCpuFeatures) -include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/entrypoints.txt") -include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_MACHINE}/headers.txt") +include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/entrypoints.txt") +include("${LIBC_SOURCE_DIR}/config/${LIBC_TARGET_OS}/${LIBC_TARGET_ARCHITECTURE}/headers.txt") set(TARGET_ENTRYPOINT_NAME_LIST "") foreach(entrypoint IN LISTS TARGET_LLVMLIBC_ENTRYPOINTS) diff --git a/libc/cmake/modules/LLVMLibCArchitectures.cmake b/libc/cmake/modules/LLVMLibCArchitectures.cmake new file mode 100644 --- /dev/null +++ b/libc/cmake/modules/LLVMLibCArchitectures.cmake @@ -0,0 +1,22 @@ +# ------------------------------------------------------------------------------ +# Architecture definitions +# ------------------------------------------------------------------------------ + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips") + set(LIBC_TARGET_ARCHITECTURE_IS_MIPS TRUE) + set(LIBC_TARGET_ARCHITECTURE "mips") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm") + set(LIBC_TARGET_ARCHITECTURE_IS_ARM TRUE) + set(LIBC_TARGET_ARCHITECTURE "arm") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64") + set(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 TRUE) + set(LIBC_TARGET_ARCHITECTURE "aarch64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(AMD64|amd64)|(^i.86$)") + set(LIBC_TARGET_ARCHITECTURE_IS_X86 TRUE) + set(LIBC_TARGET_ARCHITECTURE "x86_64") +elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)") + set(LIBC_TARGET_ARCHITECTURE_IS_POWER TRUE) + set(LIBC_TARGET_ARCHITECTURE "power") +else() + message(FATAL_ERROR "Unsupported processor ${CMAKE_SYSTEM_PROCESSOR}") +endif() diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake --- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake +++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake @@ -2,7 +2,7 @@ # Cpu features definition and flags # ------------------------------------------------------------------------------ -if(${LIBC_TARGET_MACHINE} MATCHES "x86|x86_64") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) set(ALL_CPU_FEATURES SSE SSE2 AVX AVX2 AVX512F) list(SORT ALL_CPU_FEATURES) endif() diff --git a/libc/config/linux/CMakeLists.txt b/libc/config/linux/CMakeLists.txt --- a/libc/config/linux/CMakeLists.txt +++ b/libc/config/linux/CMakeLists.txt @@ -3,9 +3,9 @@ DEF_FILE syscall.h.def GEN_HDR syscall.h PARAMS - inline_syscalls=${LIBC_TARGET_MACHINE}/syscall.h.inc + inline_syscalls=${LIBC_TARGET_ARCHITECTURE}/syscall.h.inc DATA_FILES - ${LIBC_TARGET_MACHINE}/syscall.h.inc + ${LIBC_TARGET_ARCHITECTURE}/syscall.h.inc DEPENDS libc.src.__support.common ) diff --git a/libc/fuzzing/CMakeLists.txt b/libc/fuzzing/CMakeLists.txt --- a/libc/fuzzing/CMakeLists.txt +++ b/libc/fuzzing/CMakeLists.txt @@ -1,6 +1,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=fuzzer") add_custom_target(libc-fuzzer) -add_dependencies(check-libc libc-fuzzer) +# add_dependencies(check-libc libc-fuzzer) add_subdirectory(math) add_subdirectory(string) diff --git a/libc/loader/linux/CMakeLists.txt b/libc/loader/linux/CMakeLists.txt --- a/libc/loader/linux/CMakeLists.txt +++ b/libc/loader/linux/CMakeLists.txt @@ -56,16 +56,16 @@ ) endfunction() -if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE})) - message(STATUS "Skipping loader for target machine ${LIBC_TARGET_MACHINE}") +if(NOT (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE})) + message(STATUS "Skipping loader for target architecture ${LIBC_TARGET_ARCHITECTURE}") return() endif() -add_subdirectory(${LIBC_TARGET_MACHINE}) +add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) add_loader_object( crt1 ALIAS DEPENDS - .${LIBC_TARGET_MACHINE}.crt1 + .${LIBC_TARGET_ARCHITECTURE}.crt1 ) diff --git a/libc/src/math/CMakeLists.txt b/libc/src/math/CMakeLists.txt --- a/libc/src/math/CMakeLists.txt +++ b/libc/src/math/CMakeLists.txt @@ -1,19 +1,19 @@ add_subdirectory(generic) -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE}) - add_subdirectory(${LIBC_TARGET_MACHINE}) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) endif() function(add_math_entrypoint_object name) # We prefer machine specific implementation if available. Hence we check # that first and retrun early if we are able to add an alias target for the # machine specific implementation. - get_fq_target_name("${LIBC_TARGET_MACHINE}.${name}" fq_machine_specific_target_name) + get_fq_target_name("${LIBC_TARGET_ARCHITECTURE}.${name}" fq_machine_specific_target_name) if(TARGET ${fq_machine_specific_target_name}) add_entrypoint_object( ${name} ALIAS DEPENDS - .${LIBC_TARGET_MACHINE}.${name} + .${LIBC_TARGET_ARCHITECTURE}.${name} ) return() endif() diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt --- a/libc/src/string/CMakeLists.txt +++ b/libc/src/string/CMakeLists.txt @@ -211,16 +211,13 @@ # ------------------------------------------------------------------------------ # include the relevant architecture specific implementations -if(${LIBC_TARGET_MACHINE} STREQUAL "x86_64") - set(LIBC_STRING_TARGET_ARCH "x86") - set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/x86/memcpy.cpp) -elseif(${LIBC_TARGET_MACHINE} STREQUAL "aarch64") - set(LIBC_STRING_TARGET_ARCH "aarch64") - set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/aarch64/memcpy.cpp) +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) + set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/${LIBC_TARGET_ARCHITECTURE}/memcpy.cpp) +elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64}) + set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/${LIBC_TARGET_ARCHITECTURE}/memcpy.cpp) #Disable tail merging as it leads to lower performance set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm --tail-merge-threshold=0") else() - set(LIBC_STRING_TARGET_ARCH ${LIBC_TARGET_MACHINE}) set(MEMCPY_SRC ${LIBC_SOURCE_DIR}/src/string/memcpy.cpp) endif() @@ -237,7 +234,7 @@ ) endfunction() -if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_memcpy(memcpy MARCH native) else() add_memcpy(memcpy) @@ -260,7 +257,7 @@ ) endfunction() -if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_memset(memset MARCH native) else() add_memset(memset) @@ -284,7 +281,7 @@ ) endfunction() -if(${LIBC_STRING_TARGET_ARCH} STREQUAL "x86") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_bzero(bzero MARCH native) else() add_bzero(bzero) @@ -294,6 +291,6 @@ # Add all other relevant implementations for the native target. # ------------------------------------------------------------------------------ -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_STRING_TARGET_ARCH}) - include(${LIBC_STRING_TARGET_ARCH}/CMakeLists.txt) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + include(${LIBC_TARGET_ARCHITECTURE}/CMakeLists.txt) endif() diff --git a/libc/src/string/aarch64/CMakeLists.txt b/libc/src/string/aarch64/CMakeLists.txt --- a/libc/src/string/aarch64/CMakeLists.txt +++ b/libc/src/string/aarch64/CMakeLists.txt @@ -1 +1 @@ -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}") diff --git a/libc/src/string/x86/CMakeLists.txt b/libc/src/string/x86/CMakeLists.txt deleted file mode 100644 --- a/libc/src/string/x86/CMakeLists.txt +++ /dev/null @@ -1,14 +0,0 @@ -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_none" REJECT "${ALL_CPU_FEATURES}") -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") -add_memcpy("memcpy_${LIBC_TARGET_MACHINE}_opt_avx512f" REQUIRE "AVX512F") - -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_none" REJECT "${ALL_CPU_FEATURES}") -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") -add_memset("memset_${LIBC_TARGET_MACHINE}_opt_avx512f" REQUIRE "AVX512F") - -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_none" REJECT "${ALL_CPU_FEATURES}") -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") -add_bzero("bzero_${LIBC_TARGET_MACHINE}_opt_avx512f" REQUIRE "AVX512F") diff --git a/libc/src/string/x86_64/CMakeLists.txt b/libc/src/string/x86_64/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/libc/src/string/x86_64/CMakeLists.txt @@ -0,0 +1,14 @@ +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_none" REJECT "${ALL_CPU_FEATURES}") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") +add_memcpy("memcpy_${LIBC_TARGET_ARCHITECTURE}_opt_avx512f" REQUIRE "AVX512F") + +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_none" REJECT "${ALL_CPU_FEATURES}") +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") +add_memset("memset_${LIBC_TARGET_ARCHITECTURE}_opt_avx512f" REQUIRE "AVX512F") + +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_none" REJECT "${ALL_CPU_FEATURES}") +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_sse" REQUIRE "SSE" REJECT "SSE2") +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_avx" REQUIRE "AVX" REJECT "AVX2") +add_bzero("bzero_${LIBC_TARGET_ARCHITECTURE}_opt_avx512f" REQUIRE "AVX512F") diff --git a/libc/src/string/x86/memcpy.cpp b/libc/src/string/x86_64/memcpy.cpp rename from libc/src/string/x86/memcpy.cpp rename to libc/src/string/x86_64/memcpy.cpp diff --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt --- a/libc/src/threads/linux/CMakeLists.txt +++ b/libc/src/threads/linux/CMakeLists.txt @@ -3,9 +3,9 @@ DEF_FILE thread_start_args.h.def GEN_HDR thread_start_args.h PARAMS - thread_start_args=${LIBC_TARGET_MACHINE}/thread_start_args.h.in + thread_start_args=${LIBC_TARGET_ARCHITECTURE}/thread_start_args.h.in DATA_FILES - ${LIBC_TARGET_MACHINE}/thread_start_args.h.in + ${LIBC_TARGET_ARCHITECTURE}/thread_start_args.h.in ) add_entrypoint_object( diff --git a/libc/test/config/linux/CMakeLists.txt b/libc/test/config/linux/CMakeLists.txt --- a/libc/test/config/linux/CMakeLists.txt +++ b/libc/test/config/linux/CMakeLists.txt @@ -1,5 +1,5 @@ add_libc_testsuite(libc_linux_tests) -if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_MACHINE}) - add_subdirectory(${LIBC_TARGET_MACHINE}) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${LIBC_TARGET_ARCHITECTURE}) + add_subdirectory(${LIBC_TARGET_ARCHITECTURE}) endif() diff --git a/libc/test/loader/linux/CMakeLists.txt b/libc/test/loader/linux/CMakeLists.txt --- a/libc/test/loader/linux/CMakeLists.txt +++ b/libc/test/loader/linux/CMakeLists.txt @@ -1,5 +1,5 @@ -if(NOT (EXISTS ${LIBC_SOURCE_DIR}/loader/linux/${LIBC_TARGET_MACHINE})) - message("Skipping loader tests for target machine ${LIBC_TARGET_MACHINE}.") +if(NOT (EXISTS ${LIBC_SOURCE_DIR}/loader/linux/${LIBC_TARGET_ARCHITECTURE})) + message("Skipping loader tests for target architecture ${LIBC_TARGET_ARCHITECTURE}.") return() endif() diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -976,7 +976,7 @@ # from insufficient precision in MPFR calculations leading to # https://hal.archives-ouvertes.fr/hal-01091186/document. We will # renable after fixing the precision issue. -if(${LIBC_TARGET_MACHINE} MATCHES "x86_64") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) add_fp_unittest( sqrtl_test NEED_MPFR diff --git a/libc/test/utils/FPUtil/CMakeLists.txt b/libc/test/utils/FPUtil/CMakeLists.txt --- a/libc/test/utils/FPUtil/CMakeLists.txt +++ b/libc/test/utils/FPUtil/CMakeLists.txt @@ -1,4 +1,4 @@ -if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_MACHINE} MATCHES "i386|x86_64")) +if((${LIBC_TARGET_OS} STREQUAL "linux") AND (${LIBC_TARGET_ARCHITECTURE_IS_X86})) add_libc_unittest( x86_long_double_test SRCS diff --git a/libc/utils/FPUtil/CMakeLists.txt b/libc/utils/FPUtil/CMakeLists.txt --- a/libc/utils/FPUtil/CMakeLists.txt +++ b/libc/utils/FPUtil/CMakeLists.txt @@ -1,11 +1,11 @@ -if(${LIBC_TARGET_MACHINE} MATCHES "^x86.*") +if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) set(LONG_DOUBLE_HDR LongDoubleBitsX86.h) else() set(LONG_DOUBLE_HDR) endif() -if(EXISTS ${LIBC_TARGET_MACHINE}) - set(FENV_IMPL ${LIBC_TARGET_MACHINE}/FEnv.h) +if(EXISTS ${LIBC_TARGET_ARCHITECTURE}) + set(FENV_IMPL ${LIBC_TARGET_ARCHITECTURE}/FEnv.h) else() set(FENV_IMPL DummyFEnv.h) endif()