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

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

@ -1,6 +1,15 @@
#include <mcl/fp_base.hpp> #include <mcl/fp_base.hpp>
namespace mcl { namespace fp { 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& op, const Unit* p, size_t pBitLen)
void setOp(mcl::fp::Op&, const Unit*, size_t) void setOp(mcl::fp::Op&, const Unit*, size_t)
{ {

Loading…
Cancel
Save