From 7ed8bfa9477bf99babec5a7a0f05065e56b1300c Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Fri, 5 Jun 2015 15:01:09 +0900 Subject: [PATCH] rename functions --- include/mcl/fp.hpp | 39 +++++++++++--------------- include/mcl/fp_base.hpp | 12 ++++---- src/fp.cpp | 62 ++++++----------------------------------- 3 files changed, 31 insertions(+), 82 deletions(-) diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index 83a7dcd..65c9b2b 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -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) { diff --git a/include/mcl/fp_base.hpp b/include/mcl/fp_base.hpp index c1c883e..9bdec3b 100644 --- a/include/mcl/fp_base.hpp +++ b/include/mcl/fp_base.hpp @@ -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()) { } diff --git a/src/fp.cpp b/src/fp.cpp index 68a1dc6..9676752 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -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::init(p); } -#if CYBOZU_OS_BIT == 32 - else if (pBitLen <= 160) { static fp::MontFp f; op = f.init(p); } -#endif - else if (pBitLen <= 192) { static fp::MontFp f; op = f.init(p); } -#if CYBOZU_OS_BIT == 32 - else if (pBitLen <= 224) { static fp::MontFp f; op = f.init(p); } -#endif - else if (pBitLen <= 256) { static fp::MontFp f; op = f.init(p); } - else if (pBitLen <= 384) { static fp::MontFp f; op = f.init(p); } - else if (pBitLen <= 448) { static fp::MontFp f; op = f.init(p); } -#if CYBOZU_OS_BIT == 32 - else if (pBitLen <= 544) { static fp::MontFp f; op = f.init(p); } -#else - else if (pBitLen <= 576) { static fp::MontFp f; op = f.init(p); } -#endif - else { static fp::MontFp f; op = f.init(p); } -#else - if (pBitLen <= 128) { op = fp::FixedFp::init(p); } -#if CYBOZU_OS_BIT == 32 - else if (pBitLen <= 160) { static fp::FixedFp f; op = f.init(p); } -#endif - else if (pBitLen <= 192) { static fp::FixedFp f; op = f.init(p); } -#if CYBOZU_OS_BIT == 32 - else if (pBitLen <= 224) { static fp::FixedFp f; op = f.init(p); } -#endif - else if (pBitLen <= 256) { static fp::FixedFp f; op = f.init(p); } - else if (pBitLen <= 384) { static fp::FixedFp f; op = f.init(p); } - else if (pBitLen <= 448) { static fp::FixedFp f; op = f.init(p); } -#if CYBOZU_OS_BIT == 32 - else if (pBitLen <= 544) { static fp::FixedFp f; op = f.init(p); } -#else - else if (pBitLen <= 576) { static fp::FixedFp f; op = f.init(p); } -#endif - else { static fp::FixedFp f; op = f.init(p); } -#endif - assert(op.N <= maxUnitN); -#endif -} template 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::isZeroC; \ op.clear = OpeFunc::clearC; \ op.copy = OpeFunc::copyC; \ - op.negG = OpeFunc::negC; \ + op.negP = OpeFunc::negC; \ op.invOp = OpeFunc::invOp; \ - op.addG = OpeFunc::addC; \ - op.subG = OpeFunc::subC; \ - op.mulPreG = OpeFunc::mulPreC; \ - op.modG = OpeFunc::modC; \ + op.addP = OpeFunc::addC; \ + op.subP = OpeFunc::subC; \ + op.mulPreP = OpeFunc::mulPreC; \ + op.modP = OpeFunc::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;