Skip to content

Commit

Permalink
added lshift64, rshift64
Browse files Browse the repository at this point in the history
  • Loading branch information
lunfardo314 committed Feb 10, 2024
1 parent 959f17b commit ce393d3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
20 changes: 20 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,26 @@ func evalBitwiseNOT(par *CallParams) []byte {
return ret
}

func evalLShift64(par *CallParams) []byte {
a0, a1 := mustArithmArgs(par, 8, "lshift64")
op0 := binary.BigEndian.Uint64(a0)
op1 := binary.BigEndian.Uint64(a1)
ret := make([]byte, len(a0))
binary.BigEndian.PutUint64(ret, op0<<op1)
par.Trace("lshift64: %s << %s -> %s", Fmt(a0), Fmt(a1), Fmt(ret))
return ret
}

func evalRShift64(par *CallParams) []byte {
a0, a1 := mustArithmArgs(par, 8, "rshift64")
op0 := binary.BigEndian.Uint64(a0)
op1 := binary.BigEndian.Uint64(a1)
ret := make([]byte, len(a0))
binary.BigEndian.PutUint64(ret, op0>>op1)
par.Trace("rshift64: %s >> %s -> %s", Fmt(a0), Fmt(a1), Fmt(ret))
return ret
}

func (lib *Library) evalUnwrapBytecodeArg(par *CallParams) []byte {
a0 := par.Arg(0)
_, prefix, args, err := lib.ParseBytecodeOneLevel(a0)
Expand Down
16 changes: 16 additions & 0 deletions library.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,22 @@ func (lib *Library) init() {
lib.Extend("greaterOrEqualThan", "not(lessThan($0,$1))")
// other

lib.EmbedLong("lshift64", 2, evalLShift64)
{
lib.MustEqual("lshift64(u64/3, u64/2)", "u64/12")
lib.MustTrue("isZero(lshift64(u64/2001, u64/64))")
lib.MustTrue("equal(lshift64(u64/2001, u64/4), mul64(u64/2001, u64/16))")
lib.MustError("lshift64(u64/2001, 4)", "8-bytes size parameters expected")
}

lib.EmbedLong("rshift64", 2, evalRShift64)
{
lib.MustEqual("rshift64(u64/15, u64/2)", "u64/3")
lib.MustTrue("isZero(rshift64(0xffffffffffffffff, u64/64))")
lib.MustTrue("equal(rshift64(u64/2001, u64/3), div64(u64/2001, u64/8))")
lib.MustError("rshift64(u64/2001, 4)", "8-bytes size parameters expected")
}

lib.EmbedLong("validSignatureED25519", 3, evalValidSigED25519)

lib.EmbedLong("blake2b", -1, evalBlake2b)
Expand Down

0 comments on commit ce393d3

Please sign in to comment.