summaryrefslogtreecommitdiff
path: root/Source/Core/Common/Src/MathUtil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Source/Core/Common/Src/MathUtil.cpp')
-rw-r--r--Source/Core/Common/Src/MathUtil.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/Source/Core/Common/Src/MathUtil.cpp b/Source/Core/Common/Src/MathUtil.cpp
index e2dbaa0640..88e929ec41 100644
--- a/Source/Core/Common/Src/MathUtil.cpp
+++ b/Source/Core/Common/Src/MathUtil.cpp
@@ -22,9 +22,64 @@
#include <cmath>
+namespace {
+
static u32 saved_sse_state = _mm_getcsr();
static const u32 default_sse_state = _mm_getcsr();
+}
+
+namespace MathUtil
+{
+
+int ClassifyFP(double dvalue)
+{
+ // TODO: Optimize the below to be as fast as possible.
+ IntDouble value;
+ value.d = dvalue;
+ // 5 bits (C, <, >, =, ?)
+ // easy cases first
+ if (value.i == 0) {
+ // positive zero
+ return 0x2;
+ } else if (value.i == 0x8000000000000000ULL) {
+ // negative zero
+ return 0x12;
+ } else if (value.i == 0x7FF0000000000000ULL) {
+ // positive inf
+ return 0x5;
+ } else if (value.i == 0xFFF0000000000000ULL) {
+ // negative inf
+ return 0x9;
+ } else {
+ // OK let's dissect this thing.
+ int sign = value.i >> 63;
+ int exp = (int)((value.i >> 52) & 0x7FF);
+ if (exp >= 1 && exp <= 2046) {
+ // Nice normalized number.
+ if (sign) {
+ return 0x8; // negative
+ } else {
+ return 0x4; // positive
+ }
+ }
+ u64 mantissa = value.i & 0x000FFFFFFFFFFFFFULL;
+ if (exp == 0 && mantissa) {
+ // Denormalized number.
+ if (sign) {
+ return 0x18;
+ } else {
+ return 0x14;
+ }
+ } else if (exp == 0x7FF && mantissa /* && mantissa_top*/) {
+ return 0x11; // Quiet NAN
+ }
+ }
+
+ return 0x4;
+}
+
+} // namespace
void LoadDefaultSSEState()
{
@@ -145,3 +200,4 @@ void Matrix44::Multiply(const Matrix44 &a, const Matrix44 &b, Matrix44 &result)
{
MatrixMul(4, a.data, b.data, result.data);
}
+