mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2025-12-29 18:54:47 +01:00
u128: Add StickyLogicalShiftRight
This commit is contained in:
parent
b0afd53ea7
commit
1fe8f51c54
2 changed files with 43 additions and 0 deletions
|
|
@ -92,4 +92,43 @@ u128 operator>>(u128 operand, int amount) {
|
|||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue