[libc] Switch to using the generic `<gpuintrin.h>` implementations (#121810)
[llvm-project.git] / libc / test / UnitTest / RoundingModeUtils.cpp
blob46ac204bcd7591a48c1f809baeaf2ba393d93fa0
1 //===-- RoundingModeUtils.cpp ---------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "RoundingModeUtils.h"
10 #include "src/__support/FPUtil/FEnvImpl.h"
11 #include "src/__support/FPUtil/rounding_mode.h"
13 #include "hdr/fenv_macros.h"
14 #include "src/__support/macros/config.h"
16 namespace LIBC_NAMESPACE_DECL {
17 namespace fputil {
18 namespace testing {
20 int get_fe_rounding(RoundingMode mode) {
21 switch (mode) {
22 case RoundingMode::Upward:
23 return FE_UPWARD;
24 case RoundingMode::Downward:
25 return FE_DOWNWARD;
26 case RoundingMode::TowardZero:
27 return FE_TOWARDZERO;
28 case RoundingMode::Nearest:
29 return FE_TONEAREST;
31 __builtin_unreachable();
34 ForceRoundingMode::ForceRoundingMode(RoundingMode mode) {
35 old_rounding_mode = quick_get_round();
36 rounding_mode = get_fe_rounding(mode);
37 if (old_rounding_mode != rounding_mode) {
38 int status = set_round(rounding_mode);
39 success = (status == 0);
40 } else {
41 success = true;
45 ForceRoundingMode::~ForceRoundingMode() {
46 if (old_rounding_mode != rounding_mode)
47 set_round(old_rounding_mode);
50 } // namespace testing
51 } // namespace fputil
52 } // namespace LIBC_NAMESPACE_DECL