Skip to content

Commit

Permalink
Optimise SAR to not use from/toTwos conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jul 23, 2018
1 parent e7f1f14 commit fb8faac
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,16 @@ module.exports = {
if (!runState._common.gteHardfork('constantinople')) {
trap(ERROR.INVALID_OPCODE)
}
const isSigned = b.testn(255)
if (a.gten(256)) {
if (b.fromTwos(256).ltn(0)) {
return new BN(-1).toTwos(256)
if (isSigned) {
return new BN(utils.MAX_INTEGER)
} else {
return new BN(0)
}
}
const c = b.shrn(a.toNumber())
if (b.testn(255)) {
if (isSigned) {
const shiftedOutWidth = 255 - a.toNumber()
const mask = utils.MAX_INTEGER.shrn(shiftedOutWidth).shln(shiftedOutWidth)
return c.ior(mask)
Expand Down

0 comments on commit fb8faac

Please sign in to comment.