Skip to content

Commit

Permalink
evm WIP(14)
Browse files Browse the repository at this point in the history
  • Loading branch information
valdok committed Jul 13, 2023
1 parent 7452817 commit b6f713a
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 7 deletions.
51 changes: 46 additions & 5 deletions bvm/evm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ void EvmProcessor::InitVars()
macro(0x03, sub, 3) \
macro(0x04, div, 5) \
macro(0x05, sdiv, 5) \
macro(0x06, mod, 5) \
macro(0x07, smod, 5) \
macro(0x0a, exp, 10) \
macro(0x10, lt, 3) \
macro(0x11, gt, 3) \
Expand Down Expand Up @@ -485,8 +487,6 @@ OnOpcodeBinary(div)
return;

auto x = b;
Test(x != Zero);

b.SetDiv(a, x);
}

Expand All @@ -496,13 +496,11 @@ OnOpcodeBinary(sdiv)
if (b == Zero)
return;

auto x = b;
Test(x != Zero);

bool bNeg = IsNeg(a);
if (bNeg)
a.Negate();

auto x = b;
if (IsNeg(x))
{
bNeg = !bNeg;
Expand All @@ -514,6 +512,49 @@ OnOpcodeBinary(sdiv)
b.Negate();
}

OnOpcodeBinary(mod)
{
// b = a % b;
if (b == Zero)
return;

Word mul, div;
div.SetDiv(a, b, mul);

b = a;

mul.Negate();
b += mul;
}

OnOpcodeBinary(smod)
{
if (b == Zero)
return;

bool bNeg = IsNeg(a);
if (bNeg)
a.Negate();

if (IsNeg(b))
{
b.Negate();
bNeg = !bNeg;
}

Word mul, div;
div.SetDiv(a, b, mul);

b = a;

if (bNeg)
b.Negate();
else
mul.Negate();

b += mul;
}

OnOpcodeBinary(exp)
{
// b = a ^ b
Expand Down
Loading

0 comments on commit b6f713a

Please sign in to comment.