Skip to content

Commit

Permalink
Shift Optimization (hyperledger#3039)
Browse files Browse the repository at this point in the history
Reduce shift calculations to shifts that may have an actual result.

Signed-off-by: Danno Ferrin <danno.ferrin@gmail.com>
  • Loading branch information
shemnon authored Nov 11, 2021
1 parent 00b81b6 commit 4170524
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Operation.OperationResult executeFixedCostOperation(
} else {
final int shiftAmountInt = shiftAmount.toInt();

if (shiftAmountInt >= 256) {
if (shiftAmountInt >= 256 || shiftAmountInt < 0) {
frame.pushStackItem(negativeNumber ? ALL_BITS : UInt256.ZERO);
} else {
// first perform standard shift right.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Operation.OperationResult executeFixedCostOperation(
final int shiftAmountInt = shiftAmount.toInt();
final Bytes value = leftPad(frame.popStackItem());

if (shiftAmountInt >= 256) {
if (shiftAmountInt >= 256 || shiftAmountInt < 0) {
frame.pushStackItem(UInt256.ZERO);
} else {
frame.pushStackItem(value.shiftLeft(shiftAmountInt));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Operation.OperationResult executeFixedCostOperation(
final int shiftAmountInt = shiftAmount.toInt();
final Bytes value = leftPad(frame.popStackItem());

if (shiftAmountInt >= 256) {
if (shiftAmountInt >= 256 || shiftAmountInt < 0) {
frame.pushStackItem(UInt256.ZERO);
} else {
frame.pushStackItem(value.shiftRight(shiftAmountInt));
Expand Down

0 comments on commit 4170524

Please sign in to comment.