Skip to content

Commit

Permalink
Use inline assembly suggested by @chriseth
Browse files Browse the repository at this point in the history
  • Loading branch information
pirapira committed Sep 13, 2016
1 parent a518a35 commit 1a6eef6
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1340,14 +1340,13 @@ void ExpressionCompiler::appendArithmeticOperatorCode(Token::Value _operator, Ty
// Test for (minInt) / (-1)
if (c_isSigned && _operator == Token::Div)
{
m_context << Instruction::DUP1 // x
<< u256(2) << u256(255) << Instruction::EXP // 2 ** 255
<< Instruction::EQ;
// stack: (x == minInt), x, y
m_context << Instruction::DUP3 << Instruction::NOT // ~y
<< Instruction::ISZERO;
// stack: (y == (-1)), (x == minInt), x, y
m_context << Instruction::AND;
m_context.appendInlineAssembly(R"(
and(
eq(x, exp(2, 255)), // x == 2**256 (min int)
iszero(not(y)) // y == -1
)
)",
{"y", "x"});
m_context.appendConditionalJumpTo(m_context.errorTag());
}

Expand Down

0 comments on commit 1a6eef6

Please sign in to comment.