Skip to content

Commit

Permalink
Implement SHL and SHR
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Jul 23, 2018
1 parent c174d68 commit 21dda65
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/opFns.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,29 @@ module.exports = {

return new BN(word.shrn((31 - pos.toNumber()) * 8).andln(0xff))
},
SHL: function (a, b, runState) {
if (a.gten(256)) {
return new BN(0)
}
return b.shln(a.toNumber())
},
SHR: function (a, b, runState) {
if (a.gten(256)) {
return new BN(0)
}
return b.shrn(a.toNumber())
},
SAR: function (a, b, runState) {
b = b.fromTwos(256)
if (a.gten(256)) {
if (b.ltn(0)) {
return new BN(-1).toTwos(256)
} else {
return new BN(0)
}
}
// FIXME: implement
},
// 0x20 range - crypto
SHA3: function (offset, length, runState) {
var data = memLoad(runState, offset, length)
Expand Down

0 comments on commit 21dda65

Please sign in to comment.