Skip to content

Commit

Permalink
sub64 added
Browse files Browse the repository at this point in the history
  • Loading branch information
lunfardo314 committed Feb 7, 2024
1 parent f358ba6 commit d1d544e
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion library.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ func init() {
EmbedShort("sum32_64", 2, evalSum32_64)
EmbedShort("sum64", 2, evalMustSum64)
EmbedShort("sub8", 2, evalMustSub8)
EmbedShort("sub64", 2, evalMustSub64)
{
MustEqual("sub64(u64/121, u64/11)", "u64/110")
MustEqual("sub64(u64/11, u64/0)", "u64/11")
MustError("sub64(u64/121, 11)", "8-bytes size parameters expected")
MustError("sub64(u64/11, u64/121)", "underflow")
}
EmbedShort("mul8_16", 2, evalMul8_16)
EmbedShort("mul16_32", 2, evalMul16_32)
EmbedLong("div64", 2, evalDiv64)
Expand Down Expand Up @@ -884,13 +891,26 @@ func evalMustSum64(par *CallParams) []byte {
func evalMustSub8(par *CallParams) []byte {
a0, a1 := mustArithmArgs(par, 1, "sub8")
if a0[0] < a1[0] {
par.TracePanic("_mustSub8:: %s, %s -> underflow in subtraction", Fmt(a0), Fmt(a1))
par.TracePanic("mustSub8:: %s, %s -> underflow in subtraction", Fmt(a0), Fmt(a1))
}
ret := []byte{a0[0] - a1[0]}
par.Trace("sub8:: %s, %s -> %s", Fmt(a0), Fmt(a1), Fmt(ret))
return ret
}

func evalMustSub64(par *CallParams) []byte {
a0, a1 := mustArithmArgs(par, 8, "sub64")
op0 := binary.BigEndian.Uint64(a0)
op1 := binary.BigEndian.Uint64(a1)
if op0 < op1 {
par.TracePanic("mustSub64:: %s, %s -> underflow in subtraction", Fmt(a0), Fmt(a1))
}
ret := make([]byte, 8)
binary.BigEndian.PutUint64(ret, op0-op1)
par.Trace("sub64:: %s, %s -> %s", Fmt(a0), Fmt(a1), Fmt(ret))
return ret
}

func evalMul8_16(par *CallParams) []byte {
a0, a1 := mustArithmArgs(par, 1, "mul8_16")
var ret [2]byte
Expand Down

0 comments on commit d1d544e

Please sign in to comment.