From 557027577adf4cdf5dda1c9e10bd57e943697da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 19 Jan 2015 15:20:50 +0100 Subject: [PATCH] Implementation of EXP with gmp --- evmjit/libevmjit/Arith256.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/evmjit/libevmjit/Arith256.cpp b/evmjit/libevmjit/Arith256.cpp index 621f11650..65179db8c 100644 --- a/evmjit/libevmjit/Arith256.cpp +++ b/evmjit/libevmjit/Arith256.cpp @@ -260,10 +260,17 @@ extern "C" 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); + *o_result = {}; + + static mp_limb_t mod_limbs[nLimbs + 1] = {}; + mod_limbs[nLimbs] = 1; + static const mpz_t mod{nLimbs + 1, nLimbs + 1, &mod_limbs[0]}; + + mpz_t x{nLimbs, countLimbs(_arg1), reinterpret_cast(_arg1)}; + mpz_t y{nLimbs, countLimbs(_arg2), reinterpret_cast(_arg2)}; + mpz_t z{nLimbs, 0, reinterpret_cast(o_result)}; + + mpz_powm(z, x, y, mod); } EXPORT void arith_mulmod(i256* _arg1, i256* _arg2, i256* _arg3, i256* o_result)