diff --git a/libc/include/llvm-libc-macros/fenv-macros.h b/libc/include/llvm-libc-macros/fenv-macros.h --- a/libc/include/llvm-libc-macros/fenv-macros.h +++ b/libc/include/llvm-libc-macros/fenv-macros.h @@ -17,10 +17,10 @@ #define FE_ALL_EXCEPT \ (FE_DIVBYZERO | FE_INEXACT | FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) -#define FE_DOWNWARD 1 -#define FE_TONEAREST 2 -#define FE_TOWARDZERO 4 -#define FE_UPWARD 8 +#define FE_DOWNWARD 0x400 +#define FE_TONEAREST 0 +#define FE_TOWARDZERO 0xC00 +#define FE_UPWARD 0x800 #define FE_DFL_ENV ((fenv_t *)-1) diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt --- a/libc/test/UnitTest/CMakeLists.txt +++ b/libc/test/UnitTest/CMakeLists.txt @@ -110,6 +110,7 @@ libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.fpbits_str libc.src.__support.FPUtil.fenv_impl + libc.src.__support.FPUtil.rounding_mode ) add_unittest_framework_library( diff --git a/libc/test/UnitTest/RoundingModeUtils.cpp b/libc/test/UnitTest/RoundingModeUtils.cpp --- a/libc/test/UnitTest/RoundingModeUtils.cpp +++ b/libc/test/UnitTest/RoundingModeUtils.cpp @@ -7,6 +7,8 @@ //===----------------------------------------------------------------------===// #include "RoundingModeUtils.h" +#include "src/__support/FPUtil/FEnvImpl.h" +#include "src/__support/FPUtil/rounding_mode.h" #include @@ -34,15 +36,15 @@ } ForceRoundingMode::ForceRoundingMode(RoundingMode mode) { - old_rounding_mode = fegetround(); + old_rounding_mode = quick_get_round(); rounding_mode = get_fe_rounding(mode); if (old_rounding_mode != rounding_mode) - fesetround(rounding_mode); + set_round(rounding_mode); } ForceRoundingMode::~ForceRoundingMode() { if (old_rounding_mode != rounding_mode) - fesetround(old_rounding_mode); + set_round(old_rounding_mode); } } // namespace testing diff --git a/libc/test/src/CMakeLists.txt b/libc/test/src/CMakeLists.txt --- a/libc/test/src/CMakeLists.txt +++ b/libc/test/src/CMakeLists.txt @@ -1,7 +1,7 @@ function(add_fp_unittest name) cmake_parse_arguments( "MATH_UNITTEST" - "NEED_MPFR;HERMETIC_TEST_ONLY" # Optional arguments + "NEED_MPFR;UNIT_TEST_ONLY;HERMETIC_TEST_ONLY" # Optional arguments "" # Single value arguments "LINK_LIBRARIES" # Multi-value arguments ${ARGN} @@ -16,6 +16,8 @@ if(MATH_UNITTEST_HERMETIC_TEST_ONLY) set(test_type HERMETIC_TEST_ONLY) + elseif(MATH_UNITTEST_UNIT_TEST_ONLY) + set(test_type UNIT_TEST_ONLY) endif() if(MATH_UNITTEST_NEED_MPFR) if(MATH_UNITTEST_HERMETIC_TEST_ONLY) @@ -26,7 +28,7 @@ endif() list(APPEND MATH_UNITTEST_LINK_LIBRARIES LibcFPTestHelpers) - add_libc_unittest( + add_libc_test( ${name} ${test_type} LINK_LIBRARIES "${MATH_UNITTEST_LINK_LIBRARIES}" diff --git a/libc/test/src/__support/FPUtil/CMakeLists.txt b/libc/test/src/__support/FPUtil/CMakeLists.txt --- a/libc/test/src/__support/FPUtil/CMakeLists.txt +++ b/libc/test/src/__support/FPUtil/CMakeLists.txt @@ -1,17 +1,15 @@ add_custom_target(libc-fputil-tests) -if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) - add_fp_unittest( - dyadic_float_test - NEED_MPFR - SUITE - libc-fputil-tests - SRCS - dyadic_float_test.cpp - DEPENDS - libc.src.__support.FPUtil.dyadic_float - ) -endif() +add_fp_unittest( + dyadic_float_test + NEED_MPFR + SUITE + libc-fputil-tests + SRCS + dyadic_float_test.cpp + DEPENDS + libc.src.__support.FPUtil.dyadic_float +) add_libc_test( fpbits_test @@ -24,14 +22,12 @@ libc.src.__support.FPUtil.fpbits_str ) -if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) - add_fp_unittest( - rounding_mode_test - SUITE - libc-fputil-tests - SRCS - rounding_mode_test.cpp - DEPENDS - libc.src.__support.FPUtil.rounding_mode - ) -endif() +add_fp_unittest( + rounding_mode_test + SUITE + libc-fputil-tests + SRCS + rounding_mode_test.cpp + DEPENDS + libc.src.__support.FPUtil.rounding_mode +) diff --git a/libc/test/src/fenv/CMakeLists.txt b/libc/test/src/fenv/CMakeLists.txt --- a/libc/test/src/fenv/CMakeLists.txt +++ b/libc/test/src/fenv/CMakeLists.txt @@ -94,6 +94,7 @@ # and MacOS. add_fp_unittest( enabled_exceptions_test + UNIT_TEST_ONLY SUITE libc_fenv_unittests SRCS @@ -110,6 +111,7 @@ add_fp_unittest( feholdexcept_test + UNIT_TEST_ONLY SUITE libc_fenv_unittests SRCS diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel @@ -46,6 +46,7 @@ "//libc:__support_cpp_type_traits", "//libc:__support_fputil_fp_bits", "//libc:__support_fputil_fpbits_str", + "//libc:__support_fputil_rounding_mode", "//libc:__support_macros_properties_architectures", "//libc:__support_stringutil", "//libc:__support_uint128", @@ -76,6 +77,7 @@ "//libc:__support_fputil_fenv_impl", "//libc:__support_fputil_fp_bits", "//libc:__support_fputil_fpbits_str", + "//libc:__support_fputil_rounding_mode", "//libc:libc_root", ], )