1 //===-- RoundingModeUtils.cpp ---------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "RoundingModeUtils.h"
10 #include "src/__support/FPUtil/FEnvImpl.h"
11 #include "src/__support/FPUtil/rounding_mode.h"
15 namespace LIBC_NAMESPACE
{
19 int get_fe_rounding(RoundingMode mode
) {
21 case RoundingMode::Upward
:
23 case RoundingMode::Downward
:
25 case RoundingMode::TowardZero
:
27 case RoundingMode::Nearest
:
30 __builtin_unreachable();
33 ForceRoundingMode::ForceRoundingMode(RoundingMode mode
) {
34 old_rounding_mode
= quick_get_round();
35 rounding_mode
= get_fe_rounding(mode
);
36 if (old_rounding_mode
!= rounding_mode
) {
37 int status
= set_round(rounding_mode
);
38 success
= (status
== 0);
44 ForceRoundingMode::~ForceRoundingMode() {
45 if (old_rounding_mode
!= rounding_mode
)
46 set_round(old_rounding_mode
);
49 } // namespace testing
51 } // namespace LIBC_NAMESPACE