From 49b82cdbac09c3c2058e0b4326645e5da37f7133 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Wed, 3 Dec 2014 15:02:50 +0100 Subject: [PATCH] Move EXP implementation from Ext to Arith256 --- libevmjit/Arith256.cpp | 14 ++++++++++++++ libevmjit/Arith256.h | 2 ++ libevmjit/Compiler.cpp | 2 +- libevmjit/Ext.cpp | 26 -------------------------- libevmjit/Ext.h | 1 - 5 files changed, 17 insertions(+), 28 deletions(-) diff --git a/libevmjit/Arith256.cpp b/libevmjit/Arith256.cpp index aa76ec0ef..95d11e3f3 100644 --- a/libevmjit/Arith256.cpp +++ b/libevmjit/Arith256.cpp @@ -31,6 +31,7 @@ Arith256::Arith256(llvm::IRBuilder<>& _builder) : m_mod = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_mod", getModule()); m_sdiv = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_sdiv", getModule()); m_smod = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_smod", getModule()); + m_exp = Function::Create(FunctionType::get(Type::Void, arg2Types, false), Linkage::ExternalLinkage, "arith_exp", getModule()); m_addmod = Function::Create(FunctionType::get(Type::Void, arg3Types, false), Linkage::ExternalLinkage, "arith_addmod", getModule()); m_mulmod = Function::Create(FunctionType::get(Type::Void, arg3Types, false), Linkage::ExternalLinkage, "arith_mulmod", getModule()); } @@ -80,6 +81,11 @@ llvm::Value* Arith256::smod(llvm::Value* _arg1, llvm::Value* _arg2) return binaryOp(m_smod, _arg1, _arg2); } +llvm::Value* Arith256::exp(llvm::Value* _arg1, llvm::Value* _arg2) +{ + return binaryOp(m_exp, _arg1, _arg2); +} + llvm::Value* Arith256::addmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3) { return ternaryOp(m_addmod, _arg1, _arg2, _arg3); @@ -137,6 +143,14 @@ extern "C" *o_result = eth2llvm(arg2 == 0 ? arg2 : (arg1.convert_to() % arg2.convert_to()).convert_to()); } + EXPORT void arith_exp(i256* _arg1, i256* _arg2, i256* o_result) + { + bigint left = llvm2eth(*_arg1); + bigint right = llvm2eth(*_arg2); + auto ret = static_cast(boost::multiprecision::powm(left, right, bigint(2) << 256)); + *o_result = eth2llvm(ret); + } + EXPORT void arith_mulmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result) { auto arg1 = llvm2eth(*_arg1); diff --git a/libevmjit/Arith256.h b/libevmjit/Arith256.h index 2268d5076..57bc061de 100644 --- a/libevmjit/Arith256.h +++ b/libevmjit/Arith256.h @@ -20,6 +20,7 @@ public: llvm::Value* mod(llvm::Value* _arg1, llvm::Value* _arg2); llvm::Value* sdiv(llvm::Value* _arg1, llvm::Value* _arg2); llvm::Value* smod(llvm::Value* _arg1, llvm::Value* _arg2); + llvm::Value* exp(llvm::Value* _arg1, llvm::Value* _arg2); llvm::Value* mulmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3); llvm::Value* addmod(llvm::Value* _arg1, llvm::Value* _arg2, llvm::Value* _arg3); @@ -32,6 +33,7 @@ private: llvm::Function* m_mod; llvm::Function* m_sdiv; llvm::Function* m_smod; + llvm::Function* m_exp; llvm::Function* m_mulmod; llvm::Function* m_addmod; diff --git a/libevmjit/Compiler.cpp b/libevmjit/Compiler.cpp index 41098510b..1ccd7f74e 100644 --- a/libevmjit/Compiler.cpp +++ b/libevmjit/Compiler.cpp @@ -331,7 +331,7 @@ void Compiler::compileBasicBlock(BasicBlock& _basicBlock, bytes const& _bytecode { auto left = stack.pop(); auto right = stack.pop(); - auto ret = _ext.exp(left, right); + auto ret = _arith.exp(left, right); stack.push(ret); break; } diff --git a/libevmjit/Ext.cpp b/libevmjit/Ext.cpp index 9d7bd8d44..ef7bba69c 100644 --- a/libevmjit/Ext.cpp +++ b/libevmjit/Ext.cpp @@ -135,15 +135,6 @@ llvm::Value* Ext::sha3(llvm::Value* _inOff, llvm::Value* _inSize) return hash; } -llvm::Value* Ext::exp(llvm::Value* _left, llvm::Value* _right) -{ - // TODO: Move ext to Arith256 - m_builder.CreateStore(_left, m_args[0]); - m_builder.CreateStore(_right, m_arg2); - createCall(m_exp, getRuntimeManager().getRuntimePtr(), m_args[0], m_arg2, m_args[1]); - return m_builder.CreateLoad(m_args[1]); -} - llvm::Value* Ext::codeAt(llvm::Value* _addr) { auto addr = Endianness::toBE(m_builder, _addr); @@ -175,22 +166,5 @@ void Ext::log(llvm::Value* _memIdx, llvm::Value* _numBytes, size_t _numTopics, s } } - - -extern "C" -{ - using namespace dev::eth::jit; - - //FIXME: Move to arithmentics - void ext_exp(i256* _left, i256* _right, i256* o_ret) - { - bigint left = llvm2eth(*_left); - bigint right = llvm2eth(*_right); - auto ret = static_cast(boost::multiprecision::powm(left, right, bigint(2) << 256)); - *o_ret = eth2llvm(ret); - } -} - } } - diff --git a/libevmjit/Ext.h b/libevmjit/Ext.h index ad4649177..62bdbf61e 100644 --- a/libevmjit/Ext.h +++ b/libevmjit/Ext.h @@ -26,7 +26,6 @@ public: llvm::Value* call(llvm::Value*& _gas, llvm::Value* _receiveAddress, llvm::Value* _value, llvm::Value* _inOff, llvm::Value* _inSize, llvm::Value* _outOff, llvm::Value* _outSize, llvm::Value* _codeAddress); llvm::Value* sha3(llvm::Value* _inOff, llvm::Value* _inSize); - llvm::Value* exp(llvm::Value* _left, llvm::Value* _right); llvm::Value* codeAt(llvm::Value* _addr); llvm::Value* codesizeAt(llvm::Value* _addr);