From 1a6eef60e3aa265e0a5b70c632046883d3470a5d Mon Sep 17 00:00:00 2001 From: Yoichi Hirai Date: Tue, 13 Sep 2016 19:34:33 +0200 Subject: [PATCH] Use inline assembly suggested by @chriseth https://github.com/ethereum/solidity/pull/1091#discussion_r78606129 --- libsolidity/codegen/ExpressionCompiler.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/libsolidity/codegen/ExpressionCompiler.cpp b/libsolidity/codegen/ExpressionCompiler.cpp index abc82772aff9..bc5bb0887363 100644 --- a/libsolidity/codegen/ExpressionCompiler.cpp +++ b/libsolidity/codegen/ExpressionCompiler.cpp @@ -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()); }