Browse Source

Move EXP implementation from Ext to Arith256

cl-refactor
Paweł Bylica 10 years ago
parent
commit
49b82cdbac
  1. 14
      libevmjit/Arith256.cpp
  2. 2
      libevmjit/Arith256.h
  3. 2
      libevmjit/Compiler.cpp
  4. 26
      libevmjit/Ext.cpp
  5. 1
      libevmjit/Ext.h

14
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<s256>() % arg2.convert_to<s256>()).convert_to<u256>());
}
EXPORT void arith_exp(i256* _arg1, i256* _arg2, i256* o_result)
{
bigint left = llvm2eth(*_arg1);
bigint right = llvm2eth(*_arg2);
auto ret = static_cast<u256>(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);

2
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;

2
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;
}

26
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<u256>(boost::multiprecision::powm(left, right, bigint(2) << 256));
*o_ret = eth2llvm(ret);
}
}
}
}

1
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);

Loading…
Cancel
Save