remove local::

dev
MITSUNARI Shigeo 10 years ago
parent 629b6ac609
commit d55a10e311
  1. 8
      include/mcl/fp.hpp
  2. 4
      include/mcl/fp_base.hpp
  3. 18
      src/fp.cpp
  4. 10
      test/base_test.cpp

@ -144,7 +144,7 @@ public:
mpz_class x; mpz_class x;
inFromStr(x, &isMinus, str, base); inFromStr(x, &isMinus, str, base);
if (x >= op_.mp) throw cybozu::Exception("fp:FpT:fromStr:large str") << str << op_.mp; if (x >= op_.mp) throw cybozu::Exception("fp:FpT:fromStr:large str") << str << op_.mp;
fp::local::toArray(v_, op_.N, x.get_mpz_t()); fp::toArray(v_, op_.N, x.get_mpz_t());
if (isMinus) { if (isMinus) {
neg(*this, *this); neg(*this, *this);
} }
@ -305,7 +305,7 @@ public:
} }
bool isValid() const bool isValid() const
{ {
return fp::local::compareArray(v_, op_.p, op_.N) < 0; return fp::compareArray(v_, op_.p, op_.N) < 0;
} }
void fromBitVec(const cybozu::BitVector& bv) void fromBitVec(const cybozu::BitVector& bv)
{ {
@ -314,7 +314,7 @@ public:
} }
static inline size_t getModBitLen() { return op_.bitLen; } static inline size_t getModBitLen() { return op_.bitLen; }
static inline size_t getBitVecSize() { return op_.bitLen; } static inline size_t getBitVecSize() { return op_.bitLen; }
bool operator==(const FpT& rhs) const { return fp::local::isEqualArray(v_, rhs.v_, op_.N); } bool operator==(const FpT& rhs) const { return fp::isEqualArray(v_, rhs.v_, op_.N); }
bool operator!=(const FpT& rhs) const { return !operator==(rhs); } bool operator!=(const FpT& rhs) const { return !operator==(rhs); }
inline friend FpT operator+(const FpT& x, const FpT& y) { FpT z; add(z, x, y); return z; } inline friend FpT operator+(const FpT& x, const FpT& y) { FpT z; add(z, x, y); return z; }
inline friend FpT operator-(const FpT& x, const FpT& y) { FpT z; sub(z, x, y); return z; } inline friend FpT operator-(const FpT& x, const FpT& y) { FpT z; sub(z, x, y); return z; }
@ -358,7 +358,7 @@ public:
fp::Block xb, yb; fp::Block xb, yb;
x.getBlock(xb); x.getBlock(xb);
y.getBlock(yb); y.getBlock(yb);
return fp::local::compareArray(xb.p, yb.p, xb.n); return fp::compareArray(xb.p, yb.p, xb.n);
} }
/* /*
wrapper function for generic p wrapper function for generic p

@ -139,8 +139,6 @@ T getMontgomeryCoeff(T pLow)
return ret; return ret;
} }
namespace local {
inline int compareArray(const Unit* x, const Unit* y, size_t n) inline int compareArray(const Unit* x, const Unit* y, size_t n)
{ {
for (size_t i = n - 1; i != size_t(-1); i--) { for (size_t i = n - 1; i != size_t(-1); i--) {
@ -186,6 +184,4 @@ inline void toArray(Unit *y, size_t yn, const mpz_srcptr x)
clearArray(y, xn, yn); clearArray(y, xn, yn);
} }
} // mcl::fp::local
} } // mcl::fp } } // mcl::fp

@ -46,11 +46,11 @@ struct OpeFunc {
} }
static inline void clearC(Unit *x) static inline void clearC(Unit *x)
{ {
local::clearArray(x, 0, N); clearArray(x, 0, N);
} }
static inline void copyC(Unit *y, const Unit *x) static inline void copyC(Unit *y, const Unit *x)
{ {
local::copyArray(y, x, N); copyArray(y, x, N);
} }
static inline void addC(Unit *z, const Unit *x, const Unit *y, const Unit *p) static inline void addC(Unit *z, const Unit *x, const Unit *y, const Unit *p)
{ {
@ -64,7 +64,7 @@ struct OpeFunc {
if (mpz_cmp(mz, mp) >= 0) { if (mpz_cmp(mz, mp) >= 0) {
mpz_sub(mz, mz, mp); mpz_sub(mz, mz, mp);
} }
local::toArray(z, N, mz); toArray(z, N, mz);
} }
static inline void subC(Unit *z, const Unit *x, const Unit *y, const Unit *p) static inline void subC(Unit *z, const Unit *x, const Unit *y, const Unit *p)
{ {
@ -79,7 +79,7 @@ struct OpeFunc {
set_mpz_t(mp, p); set_mpz_t(mp, p);
mpz_add(mz, mz, mp); mpz_add(mz, mz, mp);
} }
local::toArray(z, N, mz); toArray(z, N, mz);
} }
static inline void mulPreC(Unit *z, const Unit *x, const Unit *y) static inline void mulPreC(Unit *z, const Unit *x, const Unit *y)
{ {
@ -88,7 +88,7 @@ struct OpeFunc {
set_mpz_t(mx, x); set_mpz_t(mx, x);
set_mpz_t(my, y); set_mpz_t(my, y);
mpz_mul(mz, mx, my); mpz_mul(mz, mx, my);
local::toArray(z, N * 2, mz); toArray(z, N * 2, mz);
} }
// x[N * 2] -> y[N] // x[N * 2] -> y[N]
static inline void modC(Unit *y, const Unit *x, const Unit *p) static inline void modC(Unit *y, const Unit *x, const Unit *p)
@ -98,7 +98,7 @@ struct OpeFunc {
set_mpz_t(my, y); set_mpz_t(my, y);
set_mpz_t(mp, p); set_mpz_t(mp, p);
mpz_mod(my, mx, mp); mpz_mod(my, mx, mp);
local::clearArray(y, my->_mp_size, N); clearArray(y, my->_mp_size, N);
} }
static inline void invOp(Unit *y, const Unit *x, const Op& op) static inline void invOp(Unit *y, const Unit *x, const Op& op)
{ {
@ -107,11 +107,11 @@ struct OpeFunc {
set_mpz_t(mx, x); set_mpz_t(mx, x);
set_mpz_t(mp, op.p); set_mpz_t(mp, op.p);
mpz_invert(my.get_mpz_t(), mx, mp); mpz_invert(my.get_mpz_t(), mx, mp);
local::toArray(y, N, my.get_mpz_t()); toArray(y, N, my.get_mpz_t());
} }
static inline bool isZeroC(const Unit *x) static inline bool isZeroC(const Unit *x)
{ {
return local::isZeroArray(x, N); return isZeroArray(x, N);
} }
static inline void negC(Unit *y, const Unit *x, const Unit *p) static inline void negC(Unit *y, const Unit *x, const Unit *p)
{ {
@ -159,7 +159,7 @@ inline void invOpForMont(Unit *y, const Unit *x, const Op& op)
} }
static void fromRawGmp(Unit *y, size_t n, const mpz_class& x) static void fromRawGmp(Unit *y, size_t n, const mpz_class& x)
{ {
local::toArray(y, n, x.get_mpz_t()); toArray(y, n, x.get_mpz_t());
} }
static void initInvTbl(Op& op, size_t N) static void initInvTbl(Op& op, size_t N)
{ {

@ -29,7 +29,7 @@ void setMpz(mpz_class& mx, const Unit *x, size_t n)
} }
void getMpz(Unit *x, size_t n, const mpz_class& mx) void getMpz(Unit *x, size_t n, const mpz_class& mx)
{ {
mcl::fp::local::toArray(x, n, mx.get_mpz_t()); mcl::fp::toArray(x, n, mx.get_mpz_t());
} }
struct Montgomery { struct Montgomery {
@ -105,7 +105,7 @@ void put(const char *msg, const Unit *x, size_t n)
} }
void verifyEqual(const Unit *x, const Unit *y, size_t n, const char *file, int line) void verifyEqual(const Unit *x, const Unit *y, size_t n, const char *file, int line)
{ {
bool ok = mcl::fp::local::isEqualArray(x, y, n); bool ok = mcl::fp::isEqualArray(x, y, n);
CYBOZU_TEST_ASSERT(ok); CYBOZU_TEST_ASSERT(ok);
if (ok) return; if (ok) return;
printf("%s:%d\n", file, line); printf("%s:%d\n", file, line);
@ -161,7 +161,7 @@ void mulPreC(Unit *z, const Unit *x, const Unit *y, size_t n)
set_mpz_t(mx, x, n); set_mpz_t(mx, x, n);
set_mpz_t(my, y, n); set_mpz_t(my, y, n);
mpz_mul(mz, mx, my); mpz_mul(mz, mx, my);
mcl::fp::local::toArray(z, n * 2, mz); mcl::fp::toArray(z, n * 2, mz);
#else #else
mpz_class mx, my; mpz_class mx, my;
setMpz(mx, x, n); setMpz(mx, x, n);
@ -178,7 +178,7 @@ void modC(Unit *y, const Unit *x, const Unit *p, size_t n)
set_mpz_t(my, y, n); set_mpz_t(my, y, n);
set_mpz_t(mp, p, n); set_mpz_t(mp, p, n);
mpz_mod(my, mx, mp); mpz_mod(my, mx, mp);
mcl::fp::local::clearArray(y, my->_mp_size, n); mcl::fp::clearArray(y, my->_mp_size, n);
} }
void mul(Unit *z, const Unit *x, const Unit *y, const Unit *p, size_t n) void mul(Unit *z, const Unit *x, const Unit *y, const Unit *p, size_t n)
@ -191,7 +191,7 @@ void mul(Unit *z, const Unit *x, const Unit *y, const Unit *p, size_t n)
set_mpz_t(mp, p, n); set_mpz_t(mp, p, n);
mpz_mul(mz, mx, my); mpz_mul(mz, mx, my);
mpz_mod(mz, mz, mp); mpz_mod(mz, mz, mp);
mcl::fp::local::toArray(z, n, mz); mcl::fp::toArray(z, n, mz);
} }
typedef mcl::fp::void3op void3op; typedef mcl::fp::void3op void3op;

Loading…
Cancel
Save