From f876e4afa28fa14446bdd3f09284935265f913be Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 16 Jul 2018 13:48:13 +0100 Subject: [PATCH] fp: Implement FPProcessNaN --- src/CMakeLists.txt | 2 ++ src/common/fp/process_nan.cpp | 40 +++++++++++++++++++++++++++++++++++ src/common/fp/process_nan.h | 20 ++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 src/common/fp/process_nan.cpp create mode 100644 src/common/fp/process_nan.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1abb1cc..b7b88d6c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,6 +24,8 @@ add_library(dynarmic common/fp/op/FPToFixed.h common/fp/process_exception.cpp common/fp/process_exception.h + common/fp/process_nan.cpp + common/fp/process_nan.h common/fp/rounding_mode.h common/fp/unpacked.cpp common/fp/unpacked.h diff --git a/src/common/fp/process_nan.cpp b/src/common/fp/process_nan.cpp new file mode 100644 index 00000000..cd4f7f25 --- /dev/null +++ b/src/common/fp/process_nan.cpp @@ -0,0 +1,40 @@ +/* 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. + */ + +#include "common/assert.h" +#include "common/bit_util.h" +#include "common/fp/fpsr.h" +#include "common/fp/info.h" +#include "common/fp/process_exception.h" +#include "common/fp/process_nan.h" +#include "frontend/A64/FPCR.h" + +namespace Dynarmic::FP { + +template +FPT FPProcessNaN(FPType type, FPT op, FPCR fpcr, FPSR& fpsr) { + ASSERT(type == FPType::QNaN || type == FPType::SNaN); + + constexpr size_t topfrac = FPInfo::explicit_mantissa_width - 1; + + FPT result = op; + + if (type == FPType::SNaN) { + result = Common::ModifyBit(op, true); + FPProcessException(FPExc::InvalidOp, fpcr, fpsr); + } + + if (fpcr.DN()) { + result = FPInfo::DefaultNaN(); + } + + return result; +} + +template u32 FPProcessNaN(FPType type, u32 op, FPCR fpcr, FPSR& fpsr); +template u64 FPProcessNaN(FPType type, u64 op, FPCR fpcr, FPSR& fpsr); + +} // namespace Dynarmic::FP diff --git a/src/common/fp/process_nan.h b/src/common/fp/process_nan.h new file mode 100644 index 00000000..50f7cf68 --- /dev/null +++ b/src/common/fp/process_nan.h @@ -0,0 +1,20 @@ +/* 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/fp/fpsr.h" +#include "common/fp/unpacked.h" +#include "frontend/A64/FPCR.h" + +namespace Dynarmic::FP { + +using FPCR = A64::FPCR; + +template +FPT FPProcessNaN(FPType type, FPT op, FPCR fpcr, FPSR& fpsr); + +} // namespace Dynarmic::FP