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 @@ -7,11 +7,13 @@ if(${LIBC_TARGET_ARCHITECTURE_IS_X86}) set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX2 AVX512F) - set(LIBC_COMPILE_OPTIONS_NATIVE -march=native) + # set(LIBC_COMPILE_OPTIONS_NATIVE -march=native) elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64}) set(LIBC_COMPILE_OPTIONS_NATIVE -mcpu=native) endif() +set(LIBC_COMPILE_OPTIONS_NATIVE -mcpu=cortex-m4 -mabi=aapcs -mthumb) + # Making sure ALL_CPU_FEATURES is sorted. list(SORT ALL_CPU_FEATURES) diff --git a/libc/cmake/modules/LLVMLibCTestRules.cmake b/libc/cmake/modules/LLVMLibCTestRules.cmake --- a/libc/cmake/modules/LLVMLibCTestRules.cmake +++ b/libc/cmake/modules/LLVMLibCTestRules.cmake @@ -151,7 +151,12 @@ if(LIBC_UNITTEST_LINK_OPTIONS) target_link_options( ${fq_target_name} - PRIVATE ${LIBC_UNITTEST_LINK_OPTIONS} + PRIVATE ${LIBC_UNITTEST_LINK_OPTIONS} -mcpu=cortex-m4 -mabi=aapcs -mthumb + ) + else() + target_link_options( + ${fq_target_name} + PRIVATE -mcpu=cortex-m4 -mabi=aapcs -mthumb ) endif() diff --git a/libc/config/linux/arm/entrypoints.txt b/libc/config/linux/arm/entrypoints.txt new file mode 100644 --- /dev/null +++ b/libc/config/linux/arm/entrypoints.txt @@ -0,0 +1,86 @@ +set(TARGET_LIBC_ENTRYPOINTS + # ctype.h entrypoints + libc.src.ctype.isalnum + libc.src.ctype.isalpha + libc.src.ctype.isascii + libc.src.ctype.isblank + libc.src.ctype.iscntrl + libc.src.ctype.isdigit + libc.src.ctype.isgraph + libc.src.ctype.islower + libc.src.ctype.isprint + libc.src.ctype.ispunct + libc.src.ctype.isspace + libc.src.ctype.isupper + libc.src.ctype.isxdigit + libc.src.ctype.toascii + libc.src.ctype.tolower + libc.src.ctype.toupper + + # string.h entrypoints + libc.src.string.bcmp + libc.src.string.bzero + libc.src.string.memccpy + libc.src.string.memchr + libc.src.string.memcmp + libc.src.string.memcpy + libc.src.string.memmove + libc.src.string.mempcpy + libc.src.string.memrchr + libc.src.string.memset + libc.src.string.stpcpy + libc.src.string.stpncpy + libc.src.string.strcat + libc.src.string.strchr + libc.src.string.strcmp + libc.src.string.strcpy + libc.src.string.strcspn + libc.src.string.strlen + libc.src.string.strncat + libc.src.string.strncmp + libc.src.string.strncpy + libc.src.string.strnlen + libc.src.string.strpbrk + libc.src.string.strrchr + libc.src.string.strspn + libc.src.string.strstr + libc.src.string.strtok + libc.src.string.strtok_r + + # inttypes.h entrypoints + libc.src.inttypes.imaxdiv + + # stdlib.h entrypoints + libc.src.stdlib.abs + libc.src.stdlib.bsearch + libc.src.stdlib.div + libc.src.stdlib.labs + libc.src.stdlib.ldiv + libc.src.stdlib.llabs + libc.src.stdlib.lldiv + libc.src.stdlib.qsort +) + +set(TARGET_LIBM_ENTRYPOINTS + # math.h entrypoints + libc.src.math.cosf + libc.src.math.fabs + libc.src.math.fabsf + libc.src.math.fabsl + libc.src.math.fdim + libc.src.math.fdimf + libc.src.math.fdiml + libc.src.math.fmax + libc.src.math.fmaxf + libc.src.math.fmaxl + libc.src.math.fmin + libc.src.math.fminf + libc.src.math.fminl + libc.src.math.sincosf + libc.src.math.sinf +) + +set(TARGET_LLVMLIBC_ENTRYPOINTS + ${TARGET_LIBC_ENTRYPOINTS} + ${TARGET_LIBM_ENTRYPOINTS} +) diff --git a/libc/config/linux/arm/headers.txt b/libc/config/linux/arm/headers.txt new file mode 100644 --- /dev/null +++ b/libc/config/linux/arm/headers.txt @@ -0,0 +1,9 @@ +set(TARGET_PUBLIC_HEADERS + libc.include.ctype + libc.include.errno + libc.include.fenv + libc.include.inttypes + libc.include.math + libc.include.stdlib + libc.include.string +) diff --git a/libc/src/__support/CPP/Limits.h b/libc/src/__support/CPP/Limits.h --- a/libc/src/__support/CPP/Limits.h +++ b/libc/src/__support/CPP/Limits.h @@ -9,6 +9,7 @@ #ifndef LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H #define LLVM_LIBC_SRC_SUPPORT_CPP_LIMITS_H +#include #include namespace __llvm_libc { @@ -52,6 +53,7 @@ static constexpr unsigned long long max() { return ULLONG_MAX; } static constexpr unsigned long long min() { return 0; } }; +#ifdef __SIZEOF_INT128__ template <> class NumericLimits<__uint128_t> { public: static constexpr __uint128_t max() { return ~__uint128_t(0); } @@ -62,6 +64,7 @@ static constexpr __int128_t max() { return ~__uint128_t(0) >> 1; } static constexpr __int128_t min() { return __int128_t(1) << 127; } }; +#endif // int128_t } // namespace cpp } // namespace __llvm_libc diff --git a/libc/src/__support/CPP/TypeTraits.h b/libc/src/__support/CPP/TypeTraits.h --- a/libc/src/__support/CPP/TypeTraits.h +++ b/libc/src/__support/CPP/TypeTraits.h @@ -49,8 +49,11 @@ IsSameV || IsSameV || IsSameV || IsSameV || IsSameV || IsSameV || - IsSameV || IsSameV || - IsSameV<__uint128_t, TypeNoCV> || IsSameV<__int128_t, TypeNoCV>; + IsSameV || IsSameV +#ifdef __SIZEOF_INT128__ + || IsSameV<__uint128_t, TypeNoCV> || IsSameV<__int128_t, TypeNoCV> +#endif // __uint128_t + ; }; template struct IsPointerTypeNoCV : public FalseValue {}; diff --git a/libc/src/__support/FPUtil/FEnvImpl.h b/libc/src/__support/FPUtil/FEnvImpl.h --- a/libc/src/__support/FPUtil/FEnvImpl.h +++ b/libc/src/__support/FPUtil/FEnvImpl.h @@ -35,7 +35,7 @@ static inline int raise_except(int) { return 0; } -static inline int get_round() { return FE_TONEAREST; } +static inline int get_round() { return 0; } static inline int set_round(int) { return 0; } diff --git a/libc/src/__support/FPUtil/PlatformDefs.h b/libc/src/__support/FPUtil/PlatformDefs.h --- a/libc/src/__support/FPUtil/PlatformDefs.h +++ b/libc/src/__support/FPUtil/PlatformDefs.h @@ -16,7 +16,8 @@ #endif // https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms -#if defined(_WIN32) || (defined(__APPLE__) && defined(__aarch64__)) +#if defined(_WIN32) || (defined(__APPLE__) && defined(__aarch64__)) || \ + defined(__arm__) #define LONG_DOUBLE_IS_DOUBLE #endif diff --git a/libc/src/string/memory_utils/utils.h b/libc/src/string/memory_utils/utils.h --- a/libc/src/string/memory_utils/utils.h +++ b/libc/src/string/memory_utils/utils.h @@ -17,6 +17,8 @@ // time. #if defined(LLVM_LIBC_ARCH_AARCH64) || defined(LLVM_LIBC_ARCH_X86) #define LLVM_LIBC_CACHELINE_SIZE 64 +#elif defined(LLVM_LIBC_ARCH_ARM) +#define LLVM_LIBC_CACHELINE_SIZE 32 // This number is just a guess. #else #error "Unsupported platform for memory functions." #endif diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt --- a/libc/test/src/__support/CMakeLists.txt +++ b/libc/test/src/__support/CMakeLists.txt @@ -10,60 +10,65 @@ libc.src.__support.common ) -add_libc_unittest( - high_precision_decimal_test - SUITE - libc_support_unittests - SRCS - high_precision_decimal_test.cpp - DEPENDS - libc.src.__support.high_precision_decimal -) +if(false) -add_libc_unittest( - str_to_float_test - SUITE - libc_support_unittests - SRCS - str_to_float_test.cpp - DEPENDS - libc.src.__support.str_to_float -) + add_libc_unittest( + high_precision_decimal_test + SUITE + libc_support_unittests + SRCS + high_precision_decimal_test.cpp + DEPENDS + libc.src.__support.high_precision_decimal + ) -add_libc_unittest( - arg_list_test - SUITE - libc_support_unittests - SRCS - arg_list_test.cpp - DEPENDS - libc.src.__support.arg_list -) + add_libc_unittest( + str_to_float_test + SUITE + libc_support_unittests + SRCS + str_to_float_test.cpp + DEPENDS + libc.src.__support.str_to_float + ) -add_executable( - libc_str_to_float_comparison_test - str_to_float_comparison_test.cpp -) + add_libc_unittest( + arg_list_test + SUITE + libc_support_unittests + SRCS + arg_list_test.cpp + DEPENDS + libc.src.__support.arg_list + ) -target_link_libraries(libc_str_to_float_comparison_test - PRIVATE - llvmlibc -) + add_executable( + libc_str_to_float_comparison_test + str_to_float_comparison_test.cpp + ) -add_executable( - libc_system_str_to_float_comparison_test - str_to_float_comparison_test.cpp -) + target_link_libraries(libc_str_to_float_comparison_test + PRIVATE + llvmlibc + ) -set(float_test_file ${CMAKE_CURRENT_SOURCE_DIR}/str_to_float_comparison_data.txt) + add_executable( + libc_system_str_to_float_comparison_test + str_to_float_comparison_test.cpp + ) -add_custom_command(TARGET libc_str_to_float_comparison_test - POST_BUILD - COMMAND $ ${float_test_file} - DEPENDS ${float_test_file} - COMMENT "Test the strtof and strtod implementations against precomputed results." - VERBATIM) + set(float_test_file ${CMAKE_CURRENT_SOURCE_DIR}/str_to_float_comparison_data.txt) + + add_custom_command(TARGET libc_str_to_float_comparison_test + POST_BUILD + COMMAND $ ${float_test_file} + DEPENDS ${float_test_file} + COMMENT "Test the strtof and strtod implementations against precomputed results." + VERBATIM) -add_subdirectory(CPP) add_subdirectory(File) + +endif() + +add_subdirectory(CPP) add_subdirectory(OSUtil) diff --git a/libc/test/src/__support/CPP/limits_test.cpp b/libc/test/src/__support/CPP/limits_test.cpp --- a/libc/test/src/__support/CPP/limits_test.cpp +++ b/libc/test/src/__support/CPP/limits_test.cpp @@ -29,6 +29,8 @@ ULLONG_MAX); } +#ifdef __SIZEOF_INT128__ + // This checks that the current environment supports 128 bit integers. TEST(LlvmLibcLimitsTest, Int128Works) { __int128_t max128 = ~__uint128_t(0) >> 1; @@ -47,3 +49,4 @@ __uint128_t(__llvm_libc::cpp::NumericLimits::max())); ASSERT_EQ(__llvm_libc::cpp::NumericLimits<__uint128_t>::max(), umax128); } +#endif // int128_t diff --git a/libc/utils/UnitTest/FPExceptMatcher.cpp b/libc/utils/UnitTest/FPExceptMatcher.cpp --- a/libc/utils/UnitTest/FPExceptMatcher.cpp +++ b/libc/utils/UnitTest/FPExceptMatcher.cpp @@ -17,7 +17,7 @@ namespace fputil { namespace testing { -#if defined(_WIN32) +#if defined(_WIN32) || defined(__arm__) #define sigjmp_buf jmp_buf #define sigsetjmp(buf, save) setjmp(buf) #define siglongjmp(buf, val) longjmp(buf, val) diff --git a/libc/utils/UnitTest/LibcTest.cpp b/libc/utils/UnitTest/LibcTest.cpp --- a/libc/utils/UnitTest/LibcTest.cpp +++ b/libc/utils/UnitTest/LibcTest.cpp @@ -42,6 +42,7 @@ std::string describeValue(std::string Value) { return std::string(Value); } +#ifdef __SIZEOF_INT128__ // When the value is __uint128_t, also show its hexadecimal digits. // Using template to force exact match, prevent ambiguous promotion. std::string describeValue128(__uint128_t Value) { @@ -61,6 +62,7 @@ template <> std::string describeValue<__uint128_t>(__uint128_t Value) { return describeValue128(Value); } +#endif //__uint128_t template void explainDifference(ValType LHS, ValType RHS, const char *LHSStr, @@ -218,10 +220,12 @@ const char *RHSStr, const char *File, unsigned long Line); +#ifdef __SIZEOF_INT128__ template bool test<__int128_t>(RunContext *Ctx, TestCondition Cond, __int128_t LHS, __int128_t RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line); +#endif //__int128_t template bool test(RunContext *Ctx, TestCondition Cond, unsigned char LHS, unsigned char RHS, @@ -253,10 +257,12 @@ const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line); +#ifdef __SIZEOF_INT128__ template bool test<__uint128_t>(RunContext *Ctx, TestCondition Cond, __uint128_t LHS, __uint128_t RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line); +#endif //__uint128_t } // namespace internal diff --git a/libc/utils/testutils/CMakeLists.txt b/libc/utils/testutils/CMakeLists.txt --- a/libc/utils/testutils/CMakeLists.txt +++ b/libc/utils/testutils/CMakeLists.txt @@ -1,8 +1,11 @@ -if(CMAKE_HOST_UNIX) +if(FALSE) set(EFFile ExecuteFunctionUnix.cpp) set(FDReaderFile FDReaderUnix.cpp) endif() +set(EFFile ExecuteFunctionDummy.cpp) + + add_library( libc_test_utils RandUtils.cpp diff --git a/libc/utils/testutils/ExecuteFunctionDummy.cpp b/libc/utils/testutils/ExecuteFunctionDummy.cpp new file mode 100644 --- /dev/null +++ b/libc/utils/testutils/ExecuteFunctionDummy.cpp @@ -0,0 +1,30 @@ +//===-- simple ExecuteFunction implementation -----------------------------===// +// +// 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 +// +//===----------------------------------------------------------------------===// + +#include "ExecuteFunction.h" + +namespace __llvm_libc { +namespace testutils { + +bool ProcessStatus::exited_normally() const { return true; } + +int ProcessStatus::get_exit_code() const { return 0; } + +int ProcessStatus::get_fatal_signal() const { return 0; } + +ProcessStatus invoke_in_subprocess(FunctionCaller *func, unsigned timeout_ms) { + (*func)(); + + int wstatus = 0; + return {wstatus}; +} + +const char *signal_as_string(int signum) { return "SIGNALLING UNSUPPPORTED"; } + +} // namespace testutils +} // namespace __llvm_libc diff --git a/llvm/cmake/config-ix.cmake b/llvm/cmake/config-ix.cmake --- a/llvm/cmake/config-ix.cmake +++ b/llvm/cmake/config-ix.cmake @@ -371,7 +371,7 @@ # Define LLVM_HAS_ATOMICS if gcc or MSVC atomic builtins are supported. -include(CheckAtomic) +# include(CheckAtomic) if( LLVM_ENABLE_PIC ) set(ENABLE_PIC 1)