From 1804eb044cce1c00651286b99d68aafdc8ec6bb3 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Tue, 21 Jun 2016 10:31:49 +0900 Subject: [PATCH] move low gmp function to log_gmp.hpp --- src/fp.cpp | 43 +------------------------------------------ src/low_gmp.hpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 src/low_gmp.hpp diff --git a/src/fp.cpp b/src/fp.cpp index 040f491..6f167da 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -5,6 +5,7 @@ #include "fp_generator.hpp" #endif #include "fp_proto.hpp" +#include "low_gmp.hpp" #ifdef _MSC_VER #pragma warning(disable : 4127) @@ -108,48 +109,6 @@ Mode StrToMode(const std::string& s) } -template -Unit low_add(Unit *z, const Unit *x, const Unit *y) -{ - return mpn_add_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); -} -template -Unit low_sub(Unit *z, const Unit *x, const Unit *y) -{ - return mpn_sub_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); -} -// Z[N * 2] -template -void low_mul(Unit *z, const Unit *x, const Unit *y) -{ - return mpn_mul_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); -} -template -void low_sqr(Unit *y, const Unit *x) -{ - return mpn_sqr((mp_limb_t*)y, (const mp_limb_t*)x, N); -} -// Z[N + 1] -template -void low_mul_Unit(Unit *z, const Unit *x, Unit y) -{ - z[N] = mpn_mul_1((mp_limb_t*)z, (const mp_limb_t*)x, N, y); -} -// y[N] <- X[N + 1] mod p[N] -template -void low_N1_mod(Unit *y, const Unit *x, const Unit *p) -{ - mp_limb_t q[2]; // not used - mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N + 1, (const mp_limb_t*)p, N); -} -// y[N] <- X[N * 2] mod p[N] -template -void low_mod(Unit *y, const Unit *x, const Unit *p) -{ - mp_limb_t q[N + 1]; // not used - mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N * 2, (const mp_limb_t*)p, N); -} - template struct OpeFunc { static const size_t N = (bitSize + UnitBitSize - 1) / UnitBitSize; diff --git a/src/low_gmp.hpp b/src/low_gmp.hpp new file mode 100644 index 0000000..e14697b --- /dev/null +++ b/src/low_gmp.hpp @@ -0,0 +1,49 @@ +#pragma once +#include + +namespace mcl { namespace fp { + +template +Unit low_add(Unit *z, const Unit *x, const Unit *y) +{ + return mpn_add_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); +} +template +Unit low_sub(Unit *z, const Unit *x, const Unit *y) +{ + return mpn_sub_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); +} +// Z[N * 2] +template +void low_mul(Unit *z, const Unit *x, const Unit *y) +{ + return mpn_mul_n((mp_limb_t*)z, (const mp_limb_t*)x, (const mp_limb_t*)y, N); +} +template +void low_sqr(Unit *y, const Unit *x) +{ + return mpn_sqr((mp_limb_t*)y, (const mp_limb_t*)x, N); +} +// Z[N + 1] +template +void low_mul_Unit(Unit *z, const Unit *x, Unit y) +{ + z[N] = mpn_mul_1((mp_limb_t*)z, (const mp_limb_t*)x, N, y); +} +// y[N] <- X[N + 1] mod p[N] +template +void low_N1_mod(Unit *y, const Unit *x, const Unit *p) +{ + mp_limb_t q[2]; // not used + mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N + 1, (const mp_limb_t*)p, N); +} +// y[N] <- X[N * 2] mod p[N] +template +void low_mod(Unit *y, const Unit *x, const Unit *p) +{ + mp_limb_t q[N + 1]; // not used + mpn_tdiv_qr(q, (mp_limb_t*)y, 0, (const mp_limb_t*)x, N * 2, (const mp_limb_t*)p, N); +} + +} } // mcl::fp +