mirror of https://github.com/PCSX2/pcsx2.git
[Soft-Float] - Fixes MAC-OS compile error + moves the bitUtils methods to their respectives place.
I don't like the SIMD way of doing it, it can be slower and less practical to use (expensive casting).
This commit is contained in:
parent
745e4746fc
commit
5b94f53efc
|
@ -28,6 +28,25 @@ static inline int _BitScanReverse(unsigned long* const Index, const unsigned lon
|
|||
|
||||
namespace Common
|
||||
{
|
||||
static constexpr s8 msb[256] = {
|
||||
-1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
|
||||
|
||||
static constexpr s32 debruijn32[64] = {
|
||||
32, 8, 17, -1, -1, 14, -1, -1, -1, 20, -1, -1, -1, 28, -1, 18,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 26, 25, 24,
|
||||
4, 11, 23, 31, 3, 7, 10, 16, 22, 30, -1, -1, 2, 6, 13, 9,
|
||||
-1, 15, -1, 21, -1, 29, 19, -1, -1, -1, -1, -1, 1, 27, 5, 12};
|
||||
|
||||
static constexpr s32 normalizeAmounts[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24};
|
||||
|
||||
template <typename T>
|
||||
static constexpr __fi bool IsAligned(T value, unsigned int alignment)
|
||||
{
|
||||
|
@ -84,6 +103,32 @@ namespace Common
|
|||
// Perform our count leading zero.
|
||||
return std::countl_zero(static_cast<u32>(n));
|
||||
}
|
||||
|
||||
__fi static s32 clz(s32 x)
|
||||
{
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
|
||||
return debruijn32[(u32)x * 0x8c0b2891u >> 26];
|
||||
}
|
||||
|
||||
__fi static s32 BitScanReverse8(s32 b)
|
||||
{
|
||||
return msb[b];
|
||||
}
|
||||
|
||||
__fi static s32 GetMostSignificantBitPosition(u32 value)
|
||||
{
|
||||
for (s32 i = 31; i >= 0; i--)
|
||||
{
|
||||
if (((value >> i) & 1) != 0)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
} // namespace Common
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <bit>
|
||||
#include "common/Pcsx2Defs.h"
|
||||
#include "common/BitUtils.h"
|
||||
#include "PS2Float.h"
|
||||
#include "Common.h"
|
||||
|
||||
|
@ -381,7 +383,7 @@ std::string PS2Float::ToString()
|
|||
}
|
||||
else
|
||||
{
|
||||
oss << "Ps2Float(" << res << ")";
|
||||
oss << "PS2Float(" << res << ")";
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
|
@ -414,11 +416,11 @@ PS2Float PS2Float::DoAdd(PS2Float other)
|
|||
// Remove from exponent the PS2 Multiplier value.
|
||||
s32 rawExp = selfExponent - roundingMultiplier;
|
||||
|
||||
s32 amount = normalizeAmounts[clz(absMan)];
|
||||
s32 amount = Common::normalizeAmounts[Common::clz(absMan)];
|
||||
rawExp -= amount;
|
||||
absMan <<= amount;
|
||||
|
||||
s32 msbIndex = BitScanReverse8(absMan >> 23);
|
||||
s32 msbIndex = Common::BitScanReverse8(absMan >> 23);
|
||||
rawExp += msbIndex;
|
||||
absMan >>= msbIndex;
|
||||
|
||||
|
@ -490,7 +492,7 @@ PS2Float PS2Float::DoDiv(PS2Float other)
|
|||
|
||||
if (resMantissa > 0)
|
||||
{
|
||||
s32 leadingBitPosition = PS2Float::GetMostSignificantBitPosition(resMantissa);
|
||||
s32 leadingBitPosition = Common::GetMostSignificantBitPosition(resMantissa);
|
||||
|
||||
while (leadingBitPosition != IMPLICIT_LEADING_BIT_POS)
|
||||
{
|
||||
|
@ -759,29 +761,3 @@ bool PS2Float::DetermineSubtractionOperationSign(PS2Float a, PS2Float b)
|
|||
|
||||
return a.CompareOperand(b) >= 0 ? a.Sign() : !b.Sign();
|
||||
}
|
||||
|
||||
s32 PS2Float::clz(s32 x)
|
||||
{
|
||||
x |= x >> 1;
|
||||
x |= x >> 2;
|
||||
x |= x >> 4;
|
||||
x |= x >> 8;
|
||||
x |= x >> 16;
|
||||
|
||||
return debruijn32[(u32)x * 0x8c0b2891u >> 26];
|
||||
}
|
||||
|
||||
s32 PS2Float::BitScanReverse8(s32 b)
|
||||
{
|
||||
return msb[b];
|
||||
}
|
||||
|
||||
s32 PS2Float::GetMostSignificantBitPosition(u32 value)
|
||||
{
|
||||
for (s32 i = 31; i >= 0; i--)
|
||||
{
|
||||
if (((value >> i) & 1) != 0)
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -37,28 +37,6 @@ public:
|
|||
static constexpr u32 MIN_ONE = 0xBF800000;
|
||||
static constexpr int IMPLICIT_LEADING_BIT_POS = 23;
|
||||
|
||||
static constexpr s8 msb[256] = {
|
||||
-1, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
||||
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
||||
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
|
||||
};
|
||||
|
||||
static constexpr s32 debruijn32[64] = {
|
||||
32, 8, 17, -1, -1, 14, -1, -1, -1, 20, -1, -1, -1, 28, -1, 18,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 26, 25, 24,
|
||||
4, 11, 23, 31, 3, 7, 10, 16, 22, 30, -1, -1, 2, 6, 13, 9,
|
||||
-1, 15, -1, 21, -1, 29, 19, -1, -1, -1, -1, -1, 1, 27, 5, 12
|
||||
};
|
||||
|
||||
static constexpr s32 normalizeAmounts[] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8, 8, 8, 16, 16, 16, 16, 16, 16, 16, 16, 24, 24, 24, 24, 24, 24, 24
|
||||
};
|
||||
|
||||
u32 raw;
|
||||
|
||||
constexpr u32 Mantissa() const { return raw & 0x7FFFFF; }
|
||||
|
@ -134,10 +112,4 @@ private:
|
|||
static bool DetermineAdditionOperationSign(PS2Float a, PS2Float b);
|
||||
|
||||
static bool DetermineSubtractionOperationSign(PS2Float a, PS2Float b);
|
||||
|
||||
static s32 GetMostSignificantBitPosition(u32 value);
|
||||
|
||||
static s32 BitScanReverse8(s32 b);
|
||||
|
||||
static s32 clz(s32 x);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue