Commit 8eaf90b8 authored by balazs.kilvady's avatar balazs.kilvady Committed by Commit bot

MIPS: Refine 'MIPS: Fix FPU min, max, mina, maxa in simulator.'

BUG=

Review URL: https://codereview.chromium.org/1691763002

Cr-Commit-Position: refs/heads/master@{#33913}
parent b44bea94
......@@ -794,6 +794,7 @@ enum CheckForInexactConversion {
kDontCheckForInexactConversion
};
enum class MaxMinKind : int { kMin = 0, kMax = 1 };
// -----------------------------------------------------------------------------
// Hints.
......
......@@ -2348,8 +2348,10 @@ void Simulator::SignalException(Exception e) {
static_cast<int>(e));
}
// Min/Max template functions for Double and Single arguments.
template <typename T>
T FPAbs(T a);
static T FPAbs(T a);
template <>
double FPAbs<double>(double a) {
......@@ -2362,7 +2364,7 @@ float FPAbs<float>(float a) {
}
template <typename T>
bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) {
static bool FPUProcessNaNsAndZeros(T a, T b, MaxMinKind kind, T& result) {
if (std::isnan(a) && std::isnan(b)) {
result = a;
} else if (std::isnan(a)) {
......@@ -2371,9 +2373,9 @@ bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) {
result = a;
} else if (b == a) {
// Handle -0.0 == 0.0 case.
// std::signbit() returns int 0 or 1 so substracting IsMin::kMax negates the
// result.
result = std::signbit(b) - static_cast<int>(min) ? b : a;
// std::signbit() returns int 0 or 1 so substracting MaxMinKind::kMax
// negates the result.
result = std::signbit(b) - static_cast<int>(kind) ? b : a;
} else {
return false;
}
......@@ -2381,9 +2383,9 @@ bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) {
}
template <typename T>
T Simulator::FPUMin(T a, T b) {
static T FPUMin(T a, T b) {
T result;
if (FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) {
if (FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
return result;
} else {
return b < a ? b : a;
......@@ -2391,9 +2393,9 @@ T Simulator::FPUMin(T a, T b) {
}
template <typename T>
T Simulator::FPUMax(T a, T b) {
static T FPUMax(T a, T b) {
T result;
if (FPUProcessNaNsAndZeros(a, b, IsMin::kMax, result)) {
if (FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMax, result)) {
return result;
} else {
return b > a ? b : a;
......@@ -2401,9 +2403,9 @@ T Simulator::FPUMax(T a, T b) {
}
template <typename T>
T Simulator::FPUMinA(T a, T b) {
static T FPUMinA(T a, T b) {
T result;
if (!FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) {
if (!FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
if (FPAbs(a) < FPAbs(b)) {
result = a;
} else if (FPAbs(b) < FPAbs(a)) {
......@@ -2416,9 +2418,9 @@ T Simulator::FPUMinA(T a, T b) {
}
template <typename T>
T Simulator::FPUMaxA(T a, T b) {
static T FPUMaxA(T a, T b) {
T result;
if (!FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) {
if (!FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
if (FPAbs(a) > FPAbs(b)) {
result = a;
} else if (FPAbs(b) > FPAbs(a)) {
......
......@@ -300,24 +300,6 @@ class Simulator {
inline int32_t SetDoubleHIW(double* addr);
inline int32_t SetDoubleLOW(double* addr);
// Min/Max template functions for Double and Single arguments.
enum class IsMin : int { kMin = 0, kMax = 1 };
template <typename T>
bool FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result);
template <typename T>
T FPUMin(T a, T b);
template <typename T>
T FPUMax(T a, T b);
template <typename T>
T FPUMinA(T a, T b);
template <typename T>
T FPUMaxA(T a, T b);
// Executing is handled based on the instruction type.
void DecodeTypeRegister(Instruction* instr);
......
......@@ -819,6 +819,7 @@ enum CheckForInexactConversion {
kDontCheckForInexactConversion
};
enum class MaxMinKind : int { kMin = 0, kMax = 1 };
// -----------------------------------------------------------------------------
// Hints.
......
......@@ -2333,8 +2333,10 @@ void Simulator::SignalException(Exception e) {
static_cast<int>(e));
}
// Min/Max template functions for Double and Single arguments.
template <typename T>
T FPAbs(T a);
static T FPAbs(T a);
template <>
double FPAbs<double>(double a) {
......@@ -2347,7 +2349,7 @@ float FPAbs<float>(float a) {
}
template <typename T>
bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) {
static bool FPUProcessNaNsAndZeros(T a, T b, MaxMinKind kind, T& result) {
if (std::isnan(a) && std::isnan(b)) {
result = a;
} else if (std::isnan(a)) {
......@@ -2356,9 +2358,9 @@ bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) {
result = a;
} else if (b == a) {
// Handle -0.0 == 0.0 case.
// std::signbit() returns int 0 or 1 so substracting IsMin::kMax negates the
// result.
result = std::signbit(b) - static_cast<int>(min) ? b : a;
// std::signbit() returns int 0 or 1 so substracting MaxMinKind::kMax
// negates the result.
result = std::signbit(b) - static_cast<int>(kind) ? b : a;
} else {
return false;
}
......@@ -2366,9 +2368,9 @@ bool Simulator::FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result) {
}
template <typename T>
T Simulator::FPUMin(T a, T b) {
static T FPUMin(T a, T b) {
T result;
if (FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) {
if (FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
return result;
} else {
return b < a ? b : a;
......@@ -2376,9 +2378,9 @@ T Simulator::FPUMin(T a, T b) {
}
template <typename T>
T Simulator::FPUMax(T a, T b) {
static T FPUMax(T a, T b) {
T result;
if (FPUProcessNaNsAndZeros(a, b, IsMin::kMax, result)) {
if (FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMax, result)) {
return result;
} else {
return b > a ? b : a;
......@@ -2386,9 +2388,9 @@ T Simulator::FPUMax(T a, T b) {
}
template <typename T>
T Simulator::FPUMinA(T a, T b) {
static T FPUMinA(T a, T b) {
T result;
if (!FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) {
if (!FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
if (FPAbs(a) < FPAbs(b)) {
result = a;
} else if (FPAbs(b) < FPAbs(a)) {
......@@ -2401,9 +2403,9 @@ T Simulator::FPUMinA(T a, T b) {
}
template <typename T>
T Simulator::FPUMaxA(T a, T b) {
static T FPUMaxA(T a, T b) {
T result;
if (!FPUProcessNaNsAndZeros(a, b, IsMin::kMin, result)) {
if (!FPUProcessNaNsAndZeros(a, b, MaxMinKind::kMin, result)) {
if (FPAbs(a) > FPAbs(b)) {
result = a;
} else if (FPAbs(b) > FPAbs(a)) {
......
......@@ -315,24 +315,6 @@ class Simulator {
inline int32_t SetDoubleHIW(double* addr);
inline int32_t SetDoubleLOW(double* addr);
// Min/Max template functions for Double and Single arguments.
enum class IsMin : int { kMin = 0, kMax = 1 };
template <typename T>
bool FPUProcessNaNsAndZeros(T a, T b, IsMin min, T& result);
template <typename T>
T FPUMin(T a, T b);
template <typename T>
T FPUMax(T a, T b);
template <typename T>
T FPUMinA(T a, T b);
template <typename T>
T FPUMaxA(T a, T b);
// functions called from DecodeTypeRegister.
void DecodeTypeRegisterCOP1();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment