make use of my new small utility library

This commit is contained in:
2026-03-25 15:50:47 +01:00
parent 0d1aa938e3
commit d9a620bc1f
20 changed files with 194 additions and 506 deletions
@@ -1,7 +1,7 @@
#include <cfenv>
#include <cmath>
#include <Core.hpp>
#include <utils/FloatingPoint.hpp>
#include <ircolib/floats.hpp>
namespace n64 {
template <>
@@ -503,7 +503,7 @@ void Cop1::ceills(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundCeil(fs));
CHECK_FPE_CONST(s64, fd, ircolib::roundCeil(fs));
FGR_D<s64>(regs.cop0.status, instr.fd()) = fd;
}
@@ -514,7 +514,7 @@ void Cop1::ceilld(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundCeil(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundCeil(fs))
FGR_D<s64>(regs.cop0.status, instr.fd()) = fd;
}
@@ -525,7 +525,7 @@ void Cop1::ceilws(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundCeil(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundCeil(fs))
FGR_D<s32>(regs.cop0.status, instr.fd()) = fd;
}
@@ -536,7 +536,7 @@ void Cop1::ceilwd(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundCeil(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundCeil(fs))
FGR_D<s32>(regs.cop0.status, instr.fd()) = fd;
}
@@ -666,7 +666,7 @@ void Cop1::cvtwd(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundCurrent(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundCurrent(fs))
FGR_D<s32>(regs.cop0.status, instr.fd()) = fd;
}
@@ -677,7 +677,7 @@ void Cop1::cvtws(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundCurrent(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundCurrent(fs))
FGR_D<s32>(regs.cop0.status, instr.fd()) = fd;
}
@@ -688,7 +688,7 @@ void Cop1::cvtls(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundCurrent(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundCurrent(fs))
FGR_D<s64>(regs.cop0.status, instr.fd()) = fd;
}
@@ -728,7 +728,7 @@ void Cop1::cvtld(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundCurrent(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundCurrent(fs))
FGR_D<s64>(regs.cop0.status, instr.fd()) = fd;
}
@@ -1128,7 +1128,7 @@ void Cop1::roundls(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundNearest(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundNearest(fs))
if (fd != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1143,7 +1143,7 @@ void Cop1::roundld(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundNearest(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundNearest(fs))
if (fd != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1158,7 +1158,7 @@ void Cop1::roundws(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundNearest(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundNearest(fs))
if (fd != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1173,7 +1173,7 @@ void Cop1::roundwd(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundNearest(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundNearest(fs))
if (fd != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1188,7 +1188,7 @@ void Cop1::floorls(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundFloor(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundFloor(fs))
FGR_D<s64>(regs.cop0.status, instr.fd()) = fd;
}
@@ -1199,7 +1199,7 @@ void Cop1::floorld(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundFloor(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundFloor(fs))
FGR_D<s64>(regs.cop0.status, instr.fd()) = fd;
}
@@ -1210,7 +1210,7 @@ void Cop1::floorws(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundFloor(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundFloor(fs))
FGR_D<s32>(regs.cop0.status, instr.fd()) = fd;
}
@@ -1221,7 +1221,7 @@ void Cop1::floorwd(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundFloor(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundFloor(fs))
FGR_D<s32>(regs.cop0.status, instr.fd()) = fd;
}
@@ -1232,7 +1232,7 @@ void Cop1::truncws(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundTrunc(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundTrunc(fs))
if (static_cast<float>(fd) != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1247,7 +1247,7 @@ void Cop1::truncwd(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s32>(fs))
return;
CHECK_FPE_CONV_CONST(s32, fd, Util::roundTrunc(fs))
CHECK_FPE_CONV_CONST(s32, fd, ircolib::roundTrunc(fs))
if (static_cast<double>(fd) != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1262,7 +1262,7 @@ void Cop1::truncls(const Instruction instr) {
const auto fs = FGR_S<float>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundTrunc(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundTrunc(fs))
if (static_cast<float>(fd) != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;
@@ -1277,7 +1277,7 @@ void Cop1::truncld(const Instruction instr) {
const auto fs = FGR_S<double>(regs.cop0.status, instr.fs());
if (!CheckCVTArg<s64>(fs))
return;
CHECK_FPE_CONST(s64, fd, Util::roundTrunc(fs))
CHECK_FPE_CONST(s64, fd, ircolib::roundTrunc(fs))
if (static_cast<double>(fd) != fs && SetCauseInexact()) {
regs.cop0.FireException(ExceptionCode::FloatingPointError, 0, regs.oldPC);
return;