diff options
author | Siva Chandra Reddy <sivachandra@google.com> | 2023-04-18 00:35:28 +0000 |
---|---|---|
committer | Siva Chandra Reddy <sivachandra@google.com> | 2023-04-18 18:37:30 +0000 |
commit | 447d59e071227897207a3cf76e43746e5ce0ab10 (patch) | |
tree | b3e928d3082d34c1e70ffeeca10876f29855a564 /libc/utils | |
parent | 310ee08d5d45d9388333842a79bf4cef761afddf (diff) | |
download | llvm-447d59e071227897207a3cf76e43746e5ce0ab10.tar.gz |
[libc][NFC] Move RoundingModeUtils to LibcFPTestHelpers.
Reviewed By: lntue
Differential Revision: https://reviews.llvm.org/D148602
Diffstat (limited to 'libc/utils')
-rw-r--r-- | libc/utils/CMakeLists.txt | 1 | ||||
-rw-r--r-- | libc/utils/MPFRWrapper/CMakeLists.txt | 3 | ||||
-rw-r--r-- | libc/utils/MPFRWrapper/MPFRUtils.h | 6 | ||||
-rw-r--r-- | libc/utils/testutils/CMakeLists.txt | 4 | ||||
-rw-r--r-- | libc/utils/testutils/RoundingModeUtils.cpp | 48 | ||||
-rw-r--r-- | libc/utils/testutils/RoundingModeUtils.h | 34 |
6 files changed, 4 insertions, 92 deletions
diff --git a/libc/utils/CMakeLists.txt b/libc/utils/CMakeLists.txt index 685b3a61ea4f..9754dcf3854a 100644 --- a/libc/utils/CMakeLists.txt +++ b/libc/utils/CMakeLists.txt @@ -1,6 +1,5 @@ if(LLVM_INCLUDE_TESTS) add_subdirectory(MPFRWrapper) - add_subdirectory(testutils) endif() if(LIBC_TARGET_ARCHITECTURE_IS_GPU) add_subdirectory(gpu) diff --git a/libc/utils/MPFRWrapper/CMakeLists.txt b/libc/utils/MPFRWrapper/CMakeLists.txt index 482c3742aa60..6447d06b7bb5 100644 --- a/libc/utils/MPFRWrapper/CMakeLists.txt +++ b/libc/utils/MPFRWrapper/CMakeLists.txt @@ -13,13 +13,12 @@ if(LIBC_TESTS_CAN_USE_MPFR) libc.src.__support.FPUtil.fp_bits libc.src.__support.FPUtil.platform_defs LibcUnitTest - libc_test_utils ) if(EXISTS ${LLVM_LIBC_MPFR_INSTALL_PATH}) target_include_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/include) target_link_directories(libcMPFRWrapper PUBLIC ${LLVM_LIBC_MPFR_INSTALL_PATH}/lib) endif() - target_link_libraries(libcMPFRWrapper LibcFPTestHelpers LibcUnitTest mpfr gmp libc_test_utils) + target_link_libraries(libcMPFRWrapper LibcFPTestHelpers LibcUnitTest mpfr gmp) elseif(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU) message(WARNING "Math tests using MPFR will be skipped.") endif() diff --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h index 450b31ae8c5c..cbc453169a3b 100644 --- a/libc/utils/MPFRWrapper/MPFRUtils.h +++ b/libc/utils/MPFRWrapper/MPFRUtils.h @@ -10,8 +10,8 @@ #define LLVM_LIBC_UTILS_TESTUTILS_MPFRUTILS_H #include "src/__support/CPP/type_traits.h" +#include "test/UnitTest/RoundingModeUtils.h" #include "test/UnitTest/Test.h" -#include "utils/testutils/RoundingModeUtils.h" #include <stdint.h> @@ -86,8 +86,8 @@ enum class Operation : int { EndTernaryOperationsSingleOutput, }; -using __llvm_libc::testutils::ForceRoundingMode; -using __llvm_libc::testutils::RoundingMode; +using __llvm_libc::fputil::testing::ForceRoundingMode; +using __llvm_libc::fputil::testing::RoundingMode; template <typename T> struct BinaryInput { static_assert( diff --git a/libc/utils/testutils/CMakeLists.txt b/libc/utils/testutils/CMakeLists.txt deleted file mode 100644 index 8f5a10c9c9da..000000000000 --- a/libc/utils/testutils/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_library( - libc_test_utils - RoundingModeUtils.cpp -) diff --git a/libc/utils/testutils/RoundingModeUtils.cpp b/libc/utils/testutils/RoundingModeUtils.cpp deleted file mode 100644 index aff338097197..000000000000 --- a/libc/utils/testutils/RoundingModeUtils.cpp +++ /dev/null @@ -1,48 +0,0 @@ -//===-- RoundingModeUtils.cpp ---------------------------------------------===// -// -// 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 "RoundingModeUtils.h" - -#include <fenv.h> - -namespace __llvm_libc { -namespace testutils { - -int get_fe_rounding(RoundingMode mode) { - switch (mode) { - case RoundingMode::Upward: - return FE_UPWARD; - break; - case RoundingMode::Downward: - return FE_DOWNWARD; - break; - case RoundingMode::TowardZero: - return FE_TOWARDZERO; - break; - case RoundingMode::Nearest: - return FE_TONEAREST; - break; - default: - __builtin_unreachable(); - } -} - -ForceRoundingMode::ForceRoundingMode(RoundingMode mode) { - old_rounding_mode = fegetround(); - rounding_mode = get_fe_rounding(mode); - if (old_rounding_mode != rounding_mode) - fesetround(rounding_mode); -} - -ForceRoundingMode::~ForceRoundingMode() { - if (old_rounding_mode != rounding_mode) - fesetround(old_rounding_mode); -} - -} // namespace testutils -} // namespace __llvm_libc diff --git a/libc/utils/testutils/RoundingModeUtils.h b/libc/utils/testutils/RoundingModeUtils.h deleted file mode 100644 index 49c81ec4a8ce..000000000000 --- a/libc/utils/testutils/RoundingModeUtils.h +++ /dev/null @@ -1,34 +0,0 @@ -//===-- RoundingModeUtils.h -------------------------------------*- 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_UTILS_TESTUTILS_ROUNDINGMODEUTILS_H -#define LLVM_LIBC_UTILS_TESTUTILS_ROUNDINGMODEUTILS_H - -#include <stdint.h> - -namespace __llvm_libc { -namespace testutils { - -enum class RoundingMode : uint8_t { Upward, Downward, TowardZero, Nearest }; - -struct ForceRoundingMode { - ForceRoundingMode(RoundingMode); - ~ForceRoundingMode(); - - int old_rounding_mode; - int rounding_mode; -}; - -template <RoundingMode R> struct ForceRoundingModeTest : ForceRoundingMode { - ForceRoundingModeTest() : ForceRoundingMode(R) {} -}; - -} // namespace testutils -} // namespace __llvm_libc - -#endif // LLVM_LIBC_UTILS_TESTUTILS_ROUNDINGMODEUTILS_H |