mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2026-03-25 20:28:43 +00:00
fp: Change FPUnpacked to a normalized representation
Having a known position for the highest set bit makes writing algorithms easier
This commit is contained in:
@@ -24,7 +24,10 @@ enum class FPType {
|
||||
SNaN,
|
||||
};
|
||||
|
||||
/// value = (sign ? -1 : +1) * mantissa * 2^exponent
|
||||
constexpr size_t normalized_point_position = 62;
|
||||
|
||||
/// value = (sign ? -1 : +1) * mantissa/(2^62) * 2^exponent
|
||||
/// 63rd bit of mantissa is always set (unless value is zero)
|
||||
struct FPUnpacked {
|
||||
bool sign;
|
||||
int exponent;
|
||||
@@ -35,6 +38,19 @@ inline bool operator==(const FPUnpacked& a, const FPUnpacked& b) {
|
||||
return std::tie(a.sign, a.exponent, a.mantissa) == std::tie(b.sign, b.exponent, b.mantissa);
|
||||
}
|
||||
|
||||
/// return value = (sign ? -1 : +1) * value * 2^exponent
|
||||
constexpr FPUnpacked ToNormalized(bool sign, int exponent, u64 value) {
|
||||
if (value == 0) {
|
||||
return {sign, 0, 0};
|
||||
}
|
||||
|
||||
const int highest_bit = Common::HighestSetBit(value);
|
||||
const int offset = static_cast<int>(normalized_point_position) - highest_bit;
|
||||
value <<= offset;
|
||||
exponent -= offset - normalized_point_position;
|
||||
return {sign, exponent, value};
|
||||
}
|
||||
|
||||
template<typename FPT>
|
||||
std::tuple<FPType, bool, FPUnpacked> FPUnpack(FPT op, FPCR fpcr, FPSR& fpsr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user