rename functions

dev
MITSUNARI Shigeo 10 years ago
parent b7a445b4f1
commit 7ed8bfa947
  1. 39
      include/mcl/fp.hpp
  2. 12
      include/mcl/fp_base.hpp
  3. 62
      src/fp.cpp

@ -81,15 +81,14 @@ public:
if (bitLen > maxBitN) throw cybozu::Exception("mcl:FpT:setModulo:too large bitLen") << bitLen << maxBitN;
const size_t n = Gmp::getRaw(op_.p, maxUnitN, op_.mp);
if (n == 0) throw cybozu::Exception("mcl:FpT:setModulo:bad mstr") << mstr;
// mcl::fp::setOp(op_, p, bitLen);
// default
op_.neg = negG;
op_.add = addG;
op_.sub = subG;
op_.mul = mulG;
op_.neg = negW;
op_.add = addW;
op_.sub = subW;
op_.mul = mulW;
const Unit *p = op_.p;
op_.bitLen = bitLen;
initOpByLLVM(op_, p, bitLen);
fp::setOp(op_, p, bitLen);
#ifdef USE_MONT_FP
fp::initForMont(op_, p);
#endif
@ -384,33 +383,27 @@ public:
wrapper function for generic p
add(z, x, y)
case 1: op_.add(z.v_, x.v_, y.v_) written by Xbyak with fixed p
case 2: addG(z.v_, x.v_, y.v_)
op_.addG(z, x, y, p) written by GMP/LLVM with generic p
case 2: addW(z.v_, x.v_, y.v_)
op_.addP(z, x, y, p) written by GMP/LLVM with generic p
*/
static inline void addG(Unit *z, const Unit *x, const Unit *y)
static inline void addW(Unit *z, const Unit *x, const Unit *y)
{
op_.addG(z, x, y, op_.p);
op_.addP(z, x, y, op_.p);
}
static inline void subG(Unit *z, const Unit *x, const Unit *y)
static inline void subW(Unit *z, const Unit *x, const Unit *y)
{
op_.subG(z, x, y, op_.p);
op_.subP(z, x, y, op_.p);
}
static inline void mulG(Unit *z, const Unit *x, const Unit *y)
static inline void mulW(Unit *z, const Unit *x, const Unit *y)
{
Unit xy[maxUnitN * 2];
op_.mulPreG(xy, x, y);
op_.modG(z, xy, op_.p);
op_.mulPreP(xy, x, y);
op_.modP(z, xy, op_.p);
}
static inline void negG(Unit *y, const Unit *x)
static inline void negW(Unit *y, const Unit *x)
{
op_.negG(y, x, op_.p);
op_.negP(y, x, op_.p);
}
#if 0
static inline void inv(Unit *y, const Unit *x)
{
op_.invOp(y, x, op_);
}
#endif
private:
static inline void inFromStr(mpz_class& x, bool *isMinus, const std::string& str, int base)
{

@ -176,19 +176,19 @@ struct Op {
bool useMont;
int2op preInv;
// require p
void3op negG;
void3op negP;
void2opOp invOp;
void4op addG;
void4op subG;
void3op mulPreG;
void3op modG;
void4op addP;
void4op subP;
void3op mulPreP;
void3op modP;
FpGenerator *fg;
Op()
: p(), N(0), bitLen(0)
, isZero(0), clear(0), copy(0)
, neg(0), add(0), sub(0), mul(0)
, useMont(false), preInv(0)
, negG(0), invOp(0), addG(0), subG(0), mulPreG(0), modG(0)
, negP(0), invOp(0), addP(0), subP(0), mulPreP(0), modP(0)
, fg(createFpGenerator())
{
}

@ -22,50 +22,6 @@ void destroyFpGenerator(FpGenerator*)
{
}
#endif
//void setOp(mcl::fp::Op& op, const Unit* p, size_t pBitLen)
void setOp(mcl::fp::Op&, const Unit*, size_t)
{
#if 0
#ifdef USE_MONT_FP
if (pBitLen <= 128) { op = fp::MontFp<tag, 128>::init(p); }
#if CYBOZU_OS_BIT == 32
else if (pBitLen <= 160) { static fp::MontFp<tag, 160> f; op = f.init(p); }
#endif
else if (pBitLen <= 192) { static fp::MontFp<tag, 192> f; op = f.init(p); }
#if CYBOZU_OS_BIT == 32
else if (pBitLen <= 224) { static fp::MontFp<tag, 224> f; op = f.init(p); }
#endif
else if (pBitLen <= 256) { static fp::MontFp<tag, 256> f; op = f.init(p); }
else if (pBitLen <= 384) { static fp::MontFp<tag, 384> f; op = f.init(p); }
else if (pBitLen <= 448) { static fp::MontFp<tag, 448> f; op = f.init(p); }
#if CYBOZU_OS_BIT == 32
else if (pBitLen <= 544) { static fp::MontFp<tag, 544> f; op = f.init(p); }
#else
else if (pBitLen <= 576) { static fp::MontFp<tag, 576> f; op = f.init(p); }
#endif
else { static fp::MontFp<tag, maxBitN> f; op = f.init(p); }
#else
if (pBitLen <= 128) { op = fp::FixedFp<tag, 128>::init(p); }
#if CYBOZU_OS_BIT == 32
else if (pBitLen <= 160) { static fp::FixedFp<tag, 160> f; op = f.init(p); }
#endif
else if (pBitLen <= 192) { static fp::FixedFp<tag, 192> f; op = f.init(p); }
#if CYBOZU_OS_BIT == 32
else if (pBitLen <= 224) { static fp::FixedFp<tag, 224> f; op = f.init(p); }
#endif
else if (pBitLen <= 256) { static fp::FixedFp<tag, 256> f; op = f.init(p); }
else if (pBitLen <= 384) { static fp::FixedFp<tag, 384> f; op = f.init(p); }
else if (pBitLen <= 448) { static fp::FixedFp<tag, 448> f; op = f.init(p); }
#if CYBOZU_OS_BIT == 32
else if (pBitLen <= 544) { static fp::FixedFp<tag, 544> f; op = f.init(p); }
#else
else if (pBitLen <= 576) { static fp::FixedFp<tag, 576> f; op = f.init(p); }
#endif
else { static fp::FixedFp<tag, maxBitN> f; op = f.init(p); }
#endif
assert(op.N <= maxUnitN);
#endif
}
template<size_t bitN>
struct OpeFunc {
@ -168,9 +124,9 @@ struct OpeFunc {
#ifdef MCL_USE_LLVM
#define SET_OP_LLVM(n) \
op.addG = mcl_fp_add ## n ##S; \
op.subG = mcl_fp_sub ## n ##S; \
op.mulPreG = mcl_fp_mulPre ## n;
op.addP = mcl_fp_add ## n ##S; \
op.subP = mcl_fp_sub ## n ##S; \
op.mulPreP = mcl_fp_mulPre ## n;
#else
#define SET_OP_LLVM(n)
#endif
@ -180,15 +136,15 @@ struct OpeFunc {
op.isZero = OpeFunc<n>::isZeroC; \
op.clear = OpeFunc<n>::clearC; \
op.copy = OpeFunc<n>::copyC; \
op.negG = OpeFunc<n>::negC; \
op.negP = OpeFunc<n>::negC; \
op.invOp = OpeFunc<n>::invOp; \
op.addG = OpeFunc<n>::addC; \
op.subG = OpeFunc<n>::subC; \
op.mulPreG = OpeFunc<n>::mulPreC; \
op.modG = OpeFunc<n>::modC; \
op.addP = OpeFunc<n>::addC; \
op.subP = OpeFunc<n>::subC; \
op.mulPreP = OpeFunc<n>::mulPreC; \
op.modP = OpeFunc<n>::modC; \
SET_OP_LLVM(n)
void initOpByLLVM(Op& op, const Unit* /*p*/, size_t bitLen)
void setOp(mcl::fp::Op& op, const Unit* /*p*/, size_t bitLen)
{
assert(sizeof(mp_limb_t) == sizeof(Unit));
const size_t UnitBitN = sizeof(Unit) * 8;

Loading…
Cancel
Save