Skip to content

Commit f4ed77d

Browse files
committed
eliminate wasteful branch
Signed-off-by: Luis Pinto <luis.pinto@consensys.net>
1 parent 5187470 commit f4ed77d

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

evm/src/main/java/org/hyperledger/besu/evm/UInt256.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -682,15 +682,13 @@ public UInt256 shr(final UInt256 shift) {
682682
*/
683683
// TODO: check perf - wiring shiftRight callers with this one
684684
private UInt256 sar0(final int shift, final long fill) {
685-
long w3 = fill, w2 = fill, w1 = fill, w0 = fill;
686-
if (shift != 256) {
687-
w3 = u3;
688-
w2 = u2;
689-
w1 = u1;
690-
w0 = u0;
691-
}
692-
693-
if (shift != 0 && shift != 256) {
685+
long w3 = u3, w2 = u2, w1 = u1, w0 = u0;
686+
if (shift == 256) {
687+
w3 = fill;
688+
w2 = fill;
689+
w1 = fill;
690+
w0 = fill;
691+
} else if (shift != 0) {
694692
// Number of whole 64-bit words to shift (shift / 64)
695693
final int wordShift = shift >>> 6;
696694
// Remaining intra-word bit shift (shift % 64)
@@ -756,15 +754,13 @@ public UInt256 shl(final UInt256 shift) {
756754
*/
757755
// TODO: check perf - wiring shiftLeft callers with this one
758756
private UInt256 shl0(final int shift) {
759-
long w3 = 0, w2 = 0, w1 = 0, w0 = 0;
760-
if (shift != 256) {
761-
w3 = u3;
762-
w2 = u2;
763-
w1 = u1;
764-
w0 = u0;
765-
}
766-
767-
if (shift != 0 && shift != 256) {
757+
long w3 = u3, w2 = u2, w1 = u1, w0 = u0;
758+
if (shift == 256) {
759+
w3 = 0;
760+
w2 = 0;
761+
w1 = 0;
762+
w0 = 0;
763+
} else if (shift != 0) {
768764
// Number of whole 64-bit words to shift (shift / 64)
769765
final int wordShift = shift >>> 6;
770766
// Remaining intra-word bit shift (shift % 64)

0 commit comments

Comments
 (0)