u128: Add StickyLogicalShiftRight
This commit is contained in:
parent
3b337df076
commit
8e2ff56569
@ -92,4 +92,43 @@ u128 operator>>(u128 operand, int amount) {
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u128 StickyLogicalShiftRight(u128 operand, int amount) {
|
||||||
|
if (amount < 0) {
|
||||||
|
return operand << -amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount == 0) {
|
||||||
|
return operand;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount < 64) {
|
||||||
|
u128 result;
|
||||||
|
result.lower = (operand.lower >> amount) | (operand.upper << (64 - amount));
|
||||||
|
result.upper = (operand.upper >> amount);
|
||||||
|
// Sticky bit
|
||||||
|
if ((operand.lower << (64 - amount)) != 0) {
|
||||||
|
result.lower |= 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (amount < 128) {
|
||||||
|
u128 result;
|
||||||
|
result.lower = operand.upper >> (amount - 64);
|
||||||
|
// Sticky bit
|
||||||
|
if (operand.lower != 0) {
|
||||||
|
result.lower |= 1;
|
||||||
|
}
|
||||||
|
if ((operand.upper << (128 - amount)) != 0) {
|
||||||
|
result.lower |= 1;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operand.lower != 0 || operand.upper != 0) {
|
||||||
|
return u128(1);
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Dynarmic
|
} // namespace Dynarmic
|
||||||
|
@ -91,4 +91,8 @@ inline bool operator!=(u128 a, u128 b) {
|
|||||||
u128 operator<<(u128 operand, int amount);
|
u128 operator<<(u128 operand, int amount);
|
||||||
u128 operator>>(u128 operand, int amount);
|
u128 operator>>(u128 operand, int amount);
|
||||||
|
|
||||||
|
/// LSB is a "sticky-bit".
|
||||||
|
/// If a 1 is shifted off, the LSB would be set.
|
||||||
|
u128 StickyLogicalShiftRight(u128 operand, int amount);
|
||||||
|
|
||||||
} // namespace Dynarmic
|
} // namespace Dynarmic
|
||||||
|
Loading…
x
Reference in New Issue
Block a user