move low gmp function to log_gmp.hpp

dev
MITSUNARI Shigeo 9 years ago
parent fa88a3b8b8
commit 1804eb044c
  1. 43
      src/fp.cpp
  2. 49
      src/low_gmp.hpp

@ -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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t bitSize>
struct OpeFunc {
static const size_t N = (bitSize + UnitBitSize - 1) / UnitBitSize;

@ -0,0 +1,49 @@
#pragma once
#include <mcl/op.hpp>
namespace mcl { namespace fp {
template<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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<size_t N>
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
Loading…
Cancel
Save