From d875c08ebfee6ef1f5c0c3efe1ad47cf6fc024a5 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Tue, 26 Jun 2018 15:10:44 +0100 Subject: [PATCH] fp: Extract common RoundingMode enum --- src/CMakeLists.txt | 1 + src/backend_x64/a32_emit_x64.cpp | 2 +- src/backend_x64/a64_emit_x64.cpp | 2 +- src/common/fp/rounding_mode.h | 30 ++++++++++++++++++++++++++++++ src/frontend/A32/FPSCR.h | 12 +++--------- src/frontend/A64/FPCR.h | 12 +++--------- 6 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 src/common/fp/rounding_mode.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 118f8799..df52f329 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -17,6 +17,7 @@ add_library(dynarmic common/crc32.cpp common/crc32.h common/fp_util.h + common/fp/rounding_mode.h common/intrusive_list.h common/iterator_util.h common/llvm_disassemble.cpp diff --git a/src/backend_x64/a32_emit_x64.cpp b/src/backend_x64/a32_emit_x64.cpp index 80ca023c..0fc0e290 100644 --- a/src/backend_x64/a32_emit_x64.cpp +++ b/src/backend_x64/a32_emit_x64.cpp @@ -59,7 +59,7 @@ A32::LocationDescriptor A32EmitContext::Location() const { } bool A32EmitContext::FPSCR_RoundTowardsZero() const { - return Location().FPSCR().RMode() != A32::FPSCR::RoundingMode::TowardsZero; + return Location().FPSCR().RMode() != FP::RoundingMode::TowardsZero; } bool A32EmitContext::FPSCR_FTZ() const { diff --git a/src/backend_x64/a64_emit_x64.cpp b/src/backend_x64/a64_emit_x64.cpp index 54c4163c..e5f8f22f 100644 --- a/src/backend_x64/a64_emit_x64.cpp +++ b/src/backend_x64/a64_emit_x64.cpp @@ -41,7 +41,7 @@ A64::LocationDescriptor A64EmitContext::Location() const { } bool A64EmitContext::FPSCR_RoundTowardsZero() const { - return Location().FPCR().RMode() != A64::FPCR::RoundingMode::TowardsZero; + return Location().FPCR().RMode() != FP::RoundingMode::TowardsZero; } bool A64EmitContext::FPSCR_FTZ() const { diff --git a/src/common/fp/rounding_mode.h b/src/common/fp/rounding_mode.h new file mode 100644 index 00000000..01ca790b --- /dev/null +++ b/src/common/fp/rounding_mode.h @@ -0,0 +1,30 @@ +/* This file is part of the dynarmic project. + * Copyright (c) 2018 MerryMage + * This software may be used and distributed according to the terms of the GNU + * General Public License version 2 or any later version. + */ + +#pragma once + +#include "common/common_types.h" + +namespace Dynarmic::FP { + +/// Ordering of first four values is important as they correspond to bits in FPCR. +enum class RoundingMode { + /// Round to nearest floating point. If there is a tie, round to nearest even digit in required position. + ToNearest_TieEven, + /// Round up towards positive infinity. + TowardsPlusInfinity, + /// Round downwards towards negative infinity. + TowardsMinusInfinity, + /// Truncate towards zero. + TowardsZero, + /// Round to nearest floating point. If there is a tie, round away from zero. + ToNearest_TieAwayFromZero, + /// Von Neumann rounding (as modified by Brent). Also known as sticky rounding. + /// Set the least significant bit to 1 if the result is not exact. + ToOdd, +}; + +} // namespace Dynarmic::FP diff --git a/src/frontend/A32/FPSCR.h b/src/frontend/A32/FPSCR.h index 51eb40f7..1cafbddb 100644 --- a/src/frontend/A32/FPSCR.h +++ b/src/frontend/A32/FPSCR.h @@ -10,6 +10,7 @@ #include "common/bit_util.h" #include "common/common_types.h" +#include "common/fp/rounding_mode.h" namespace Dynarmic::A32 { @@ -19,13 +20,6 @@ namespace Dynarmic::A32 { class FPSCR final { public: - enum class RoundingMode { - ToNearest, - TowardsPlusInfinity, - TowardsMinusInfinity, - TowardsZero - }; - FPSCR() = default; FPSCR(const FPSCR&) = default; FPSCR(FPSCR&&) = default; @@ -79,8 +73,8 @@ public: } /// Rounding mode control field. - RoundingMode RMode() const { - return static_cast(Common::Bits<22, 23>(value)); + FP::RoundingMode RMode() const { + return static_cast(Common::Bits<22, 23>(value)); } /// Indicates the stride of a vector. diff --git a/src/frontend/A64/FPCR.h b/src/frontend/A64/FPCR.h index 5c1c524f..9e82733e 100644 --- a/src/frontend/A64/FPCR.h +++ b/src/frontend/A64/FPCR.h @@ -10,6 +10,7 @@ #include "common/bit_util.h" #include "common/common_types.h" +#include "common/fp/rounding_mode.h" namespace Dynarmic::A64 { @@ -19,13 +20,6 @@ namespace Dynarmic::A64 { class FPCR final { public: - enum class RoundingMode { - ToNearest, - TowardsPlusInfinity, - TowardsMinusInfinity, - TowardsZero - }; - FPCR() = default; FPCR(const FPCR&) = default; FPCR(FPCR&&) = default; @@ -54,8 +48,8 @@ public: } /// Rounding mode control field. - RoundingMode RMode() const { - return static_cast(Common::Bits<22, 23>(value)); + FP::RoundingMode RMode() const { + return static_cast(Common::Bits<22, 23>(value)); } /// Input denormal exception trap enable flag.