Files
clang-p2996/libc/test/UnitTest/RoundingModeUtils.cpp
Joseph Huber 9e6946c252 [libc] Revert rounding mode changes for hermetic tests
We got rid of the rounding mode here so that the hermetic tests wouldn't
depend on the system fenv.h. But this seemed to cause some bots to
break. Getting rid of this change for now, it should be fine for the CPU
builds.

Differential Revision: https://reviews.llvm.org/D149767
2023-05-03 11:51:42 -05:00

51 lines
1.2 KiB
C++

//===-- 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 fputil {
namespace testing {
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 testing
} // namespace fputil
} // namespace __llvm_libc