prepair to split FpGenerator

dev
MITSUNARI Shigeo 10 years ago
parent 78dc38ce48
commit 2c238e390f
  1. 3
      include/mcl/fp.hpp
  2. 26
      include/mcl/fp_base.hpp
  3. 9
      src/fp.cpp

@ -89,6 +89,7 @@ public:
op_.sub = subG;
op_.mul = mulG;
const Unit *p = op_.p;
initOpByLLVM(op_, p, bitLen);
#ifdef USE_MONT_FP
if (bitLen <= 128) { fp::MontFp<tag, 128>::init(op_, p); }
#if CYBOZU_OS_BIT == 32
@ -107,8 +108,6 @@ public:
else if (bitLen <= 576) { static fp::MontFp<tag, 576> f; f.init(op_, p); }
#endif
else { static fp::MontFp<tag, maxBitN> f; f.init(op_, p); }
#else
initOpByLLVM(op_, p, bitLen);
#endif
op_.bitLen = bitLen;
op_.sq.set(op_.mp);

@ -25,6 +25,10 @@
#include <cybozu/inttype.hpp>
#ifdef USE_MONT_FP
#include <mcl/fp_generator.hpp>
#else
namespace mcl {
struct FpGenerator;
}
#endif
namespace mcl { namespace fp {
@ -139,6 +143,9 @@ struct TagDefault;
#define MCL_FP_BLOCK_MAX_BIT_N 521
#endif
FpGenerator *createFpGenerator();
void destroyFpGenerator(FpGenerator*);
struct Op {
static const size_t UnitByteN = sizeof(Unit);
static const size_t maxUnitN = (MCL_FP_BLOCK_MAX_BIT_N + UnitByteN * 8 - 1) / (UnitByteN * 8);
@ -167,14 +174,20 @@ struct Op {
void4op subG;
void3op mulPreG;
void3op modG;
FpGenerator *fg;
Op()
: p(), N(0), bitLen(0)
, isZero(0), clear(0), copy(0)
, neg(0), inv(0), add(0), sub(0), mul(0)
, toMont(0), fromMont(0)
, negG(0), invG(0), addG(0), subG(0), mulPreG(0), modG(0)
, fg(createFpGenerator())
{
}
~Op()
{
destroyFpGenerator(fg);
}
};
@ -220,9 +233,9 @@ struct MontFp {
{
return local::isZeroArray(x, N);
}
static inline void invC(Unit *y, const Unit *x)
static inline void invC(Unit *y, const Unit *x, const Op& op)
{
const int2op preInv = Xbyak::CastTo<int2op>(fg_.preInv_);
const int2op preInv = Xbyak::CastTo<int2op>(op.fg->preInv_);
Unit r[N];
int k = preInv(r, x);
/*
@ -230,11 +243,7 @@ struct MontFp {
R = 2^(N * 64)
get r2^(-k)R^2 = r 2^(N * 64 * 2 - k)
*/
mul_(y, r, invTbl_[k]);
}
static inline void squareC(Unit *y, const Unit *x)
{
mul_(y, x, x);
op.mul(y, r, invTbl_[k]);
}
static inline void toMont(Unit *y, const Unit *x)
{
@ -262,7 +271,7 @@ struct MontFp {
op.isZero = &isZero;
op.clear = &clear;
op.neg = Xbyak::CastTo<void2op>(fg_.neg_);
op.inv = &invC;
op.invG = &invC;
// {
// void2op square = Xbyak::CastTo<void2op>(fg_.sqr_);
// if (square) op.square = square;
@ -277,6 +286,7 @@ struct MontFp {
op.fromMont = &fromMont;
initInvTbl(invTbl_);
op.fg = &fg_;
}
};
template<class tag, size_t bitN> mpz_class MontFp<tag, bitN>::mp_;

@ -1,6 +1,15 @@
#include <mcl/fp_base.hpp>
namespace mcl { namespace fp {
FpGenerator *createFpGenerator()
{
return 0;
}
void destroyFpGenerator(FpGenerator*)
{
}
//void setOp(mcl::fp::Op& op, const Unit* p, size_t pBitLen)
void setOp(mcl::fp::Op&, const Unit*, size_t)
{

Loading…
Cancel
Save