|
|
@ -93,6 +93,7 @@ Ext::Ext(llvm::IRBuilder<>& _builder, llvm::Module* module) |
|
|
|
m_call = Function::Create(FunctionType::get(m_builder.getVoidTy(), args, false), Linkage::ExternalLinkage, "ext_call", module); |
|
|
|
m_bswap = Intrinsic::getDeclaration(module, Intrinsic::bswap, i256Ty); |
|
|
|
m_sha3 = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_sha3", module); |
|
|
|
m_exp = Function::Create(TypeBuilder<void(i<256>*, i<256>*, i<256>*), true>::get(ctx), Linkage::ExternalLinkage, "ext_exp", module); |
|
|
|
|
|
|
|
|
|
|
|
m_builder.CreateCall(m_init, m_data); |
|
|
@ -196,6 +197,15 @@ llvm::Value* Ext::sha3(llvm::Value* _inOff, llvm::Value* _inSize) |
|
|
|
return hash; |
|
|
|
} |
|
|
|
|
|
|
|
llvm::Value* Ext::exp(llvm::Value* _left, llvm::Value* _right) |
|
|
|
{ |
|
|
|
m_builder.CreateStore(_left, m_args[0]); |
|
|
|
m_builder.CreateStore(_right, m_arg2); |
|
|
|
llvm::Value* args[] = {m_args[0], m_arg2, m_args[1]}; |
|
|
|
m_builder.CreateCall(m_exp, args); |
|
|
|
return m_builder.CreateLoad(m_args[1]); |
|
|
|
} |
|
|
|
|
|
|
|
extern "C" |
|
|
|
{ |
|
|
|
|
|
|
@ -308,6 +318,14 @@ EXPORT void ext_sha3(i256* _inOff, i256* _inSize, i256* _ret) |
|
|
|
*_ret = *reinterpret_cast<i256*>(&hash); |
|
|
|
} |
|
|
|
|
|
|
|
EXPORT void ext_exp(i256* _left, i256* _right, i256* _ret) |
|
|
|
{ |
|
|
|
dev::bigint left = llvm2eth(*_left); |
|
|
|
dev::bigint right = llvm2eth(*_right); |
|
|
|
auto ret = static_cast<u256>(boost::multiprecision::powm(left, right, dev::bigint(2) << 256)); |
|
|
|
*_ret = eth2llvm(ret); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|