u128: StickyLogicalShiftRight requires special-casing for amount == 64

In this case (128 - amount) == 64, and this invokes undefined behaviour
This commit is contained in:
MerryMage
2018-07-23 20:21:33 +01:00
parent 49c7edf7c6
commit 76b07d6646
2 changed files with 29 additions and 0 deletions

View File

@@ -112,6 +112,16 @@ u128 StickyLogicalShiftRight(u128 operand, int amount) {
return result;
}
if (amount == 64) {
u128 result;
result.lower = operand.upper;
// Sticky bit
if (operand.lower != 0) {
result.lower |= 1;
}
return result;
}
if (amount < 128) {
u128 result;
result.lower = operand.upper >> (amount - 64);