rename square to sqr

dev
MITSUNARI Shigeo 9 years ago
parent 4667fde466
commit 2d9cd14d41
  1. 54
      include/mcl/ec.hpp
  2. 6
      include/mcl/fp.hpp
  3. 6
      include/mcl/gmp_util.hpp
  4. 8
      include/mcl/util.hpp
  5. 2
      sample/bench.cpp
  6. 4
      test/ec_test.cpp
  7. 2
      test/fp_test.cpp
  8. 4
      test/mont_fp_test.cpp

@ -145,12 +145,12 @@ public:
static inline void dblNoVerifyInfJacobi(EcT& R, const EcT& P)
{
Fp S, M, t, y2;
Fp::square(y2, P.y);
Fp::sqr(y2, P.y);
Fp::mul(S, P.x, y2);
const bool isPzOne = P.z.isOne();
S += S;
S += S;
Fp::square(M, P.x);
Fp::sqr(M, P.x);
switch (specialA_) {
case zero:
Fp::add(t, M, M);
@ -160,8 +160,8 @@ public:
if (isPzOne) {
M -= P.z;
} else {
Fp::square(t, P.z);
Fp::square(t, t);
Fp::sqr(t, P.z);
Fp::sqr(t, t);
M -= t;
}
Fp::add(t, M, M);
@ -172,8 +172,8 @@ public:
if (isPzOne) {
t = a_;
} else {
Fp::square(t, P.z);
Fp::square(t, t);
Fp::sqr(t, P.z);
Fp::sqr(t, t);
t *= a_;
}
t += M;
@ -181,7 +181,7 @@ public:
M += t;
break;
}
Fp::square(R.x, M);
Fp::sqr(R.x, M);
R.x -= S;
R.x -= S;
if (isPzOne) {
@ -190,7 +190,7 @@ public:
Fp::mul(R.z, P.y, P.z);
}
R.z += R.z;
Fp::square(y2, y2);
Fp::sqr(y2, y2);
y2 += y2;
y2 += y2;
y2 += y2;
@ -204,16 +204,16 @@ public:
Fp w, t, h;
switch (specialA_) {
case zero:
Fp::square(w, P.x);
Fp::sqr(w, P.x);
Fp::add(t, w, w);
w += t;
break;
case minus3:
Fp::square(w, P.x);
Fp::sqr(w, P.x);
if (isPzOne) {
w -= P.z;
} else {
Fp::square(t, P.z);
Fp::sqr(t, P.z);
w -= t;
}
Fp::add(t, w, w);
@ -224,10 +224,10 @@ public:
if (isPzOne) {
w = a_;
} else {
Fp::square(w, P.z);
Fp::sqr(w, P.z);
w *= a_;
}
Fp::square(t, P.x);
Fp::sqr(t, P.x);
w += t;
w += t;
w += t; // w = a z^2 + 3x^2
@ -242,16 +242,16 @@ public:
t *= P.y; // xys
t += t;
t += t; // 4(xys) ; 4B
Fp::square(h, w);
Fp::sqr(h, w);
h -= t;
h -= t; // w^2 - 8B
Fp::mul(R.x, h, R.z);
t -= h; // h is free
t *= w;
Fp::square(w, P.y);
Fp::sqr(w, P.y);
R.x += R.x;
R.z += R.z;
Fp::square(h, R.z);
Fp::sqr(h, R.z);
w *= h;
R.z *= h;
Fp::sub(R.y, t, w);
@ -262,13 +262,13 @@ public:
{
#ifdef MCL_EC_USE_AFFINE
Fp t, s;
Fp::square(t, P.x);
Fp::sqr(t, P.x);
Fp::add(s, t, t);
t += s;
t += a_;
Fp::add(s, P.y, P.y);
t /= s;
Fp::square(s, t);
Fp::sqr(s, t);
s -= P.x;
Fp x3;
Fp::sub(x3, s, P.x);
@ -301,7 +301,7 @@ public:
{
const bool isQzOne = Q.z.isOne();
Fp r, U1, S1, H, H3;
Fp::square(r, P.z);
Fp::sqr(r, P.z);
if (isQzOne) {
U1 = P.x;
Fp::mul(H, Q.x, r);
@ -309,7 +309,7 @@ public:
r *= P.z;
S1 = P.y;
} else {
Fp::square(S1, Q.z);
Fp::sqr(S1, Q.z);
Fp::mul(U1, P.x, S1);
Fp::mul(H, Q.x, r);
H -= U1;
@ -333,8 +333,8 @@ public:
Fp::mul(R.z, P.z, Q.z);
R.z *= H;
}
Fp::square(H3, H); // H^2
Fp::square(R.y, r); // r^2
Fp::sqr(H3, H); // H^2
Fp::sqr(R.y, r); // r^2
U1 *= H3; // U1 H^2
H3 *= H; // H^3
R.y -= U1;
@ -368,8 +368,8 @@ public:
return;
}
Fp::sub(R.y, A, PyQz);
Fp::square(A, R.y);
Fp::square(vv, v);
Fp::sqr(A, R.y);
Fp::sqr(vv, v);
r *= vv;
vv *= v;
if (isQzOne) {
@ -413,7 +413,7 @@ public:
Fp::div(t, s, t);
R.inf_ = false;
Fp x3;
Fp::square(x3, t);
Fp::sqr(x3, t);
x3 -= P.x;
x3 -= Q.x;
Fp::sub(s, P.x, x3);
@ -576,11 +576,11 @@ public:
static inline void getYfromX(Fp& y, const Fp& x, bool isYodd)
{
Fp t;
Fp::square(t, x);
Fp::sqr(t, x);
t += a_;
t *= x;
t += b_;
Fp::squareRoot(y, t);
Fp::sqrRoot(y, t);
if (Fp::isOdd(y) ^ isYodd) {
Fp::neg(y, y);
}

@ -133,7 +133,7 @@ public:
x.getBlock(b);
return (b.p[0] & 1) == 1;
}
static inline bool squareRoot(FpT& y, const FpT& x)
static inline bool sqrRoot(FpT& y, const FpT& x)
{
mpz_class mx, my;
x.getMpz(mx);
@ -279,7 +279,7 @@ public:
static inline void mul(FpT& z, const FpT& x, const FpT& y) { op_.mul(z.v_, x.v_, y.v_); }
static inline void inv(FpT& y, const FpT& x) { op_.invOp(y.v_, x.v_, op_); }
static inline void neg(FpT& y, const FpT& x) { op_.neg(y.v_, x.v_); }
static inline void square(FpT& y, const FpT& x) { op_.sqr(y.v_, x.v_); }
static inline void sqr(FpT& y, const FpT& x) { op_.sqr(y.v_, x.v_); }
static inline void div(FpT& z, const FpT& x, const FpT& y)
{
FpT rev;
@ -295,7 +295,7 @@ public:
px = &tmp;
}
z = 1;
fp::powerGeneric(z, *px, y, yn, FpT::mul, FpT::square);
fp::powerGeneric(z, *px, y, yn, FpT::mul, FpT::sqr);
if (isNegative) {
FpT::inv(z, z);
}

@ -121,7 +121,7 @@ struct Gmp {
{
mpz_mul(z.get_mpz_t(), x.get_mpz_t(), y.get_mpz_t());
}
static inline void square(mpz_class& z, const mpz_class& x)
static inline void sqr(mpz_class& z, const mpz_class& x)
{
mpz_mul(z.get_mpz_t(), x.get_mpz_t(), x.get_mpz_t());
}
@ -194,9 +194,9 @@ struct Gmp {
mul(z, x, y);
mod(z, z, m);
}
static inline void squareMod(mpz_class& z, const mpz_class& x, const mpz_class& m)
static inline void sqrMod(mpz_class& z, const mpz_class& x, const mpz_class& m)
{
square(z, x);
sqr(z, x);
mod(z, z, m);
}
// z = x^y (y >= 0)

@ -168,7 +168,7 @@ void getRandVal(T *out, RG& rg, const T *in, size_t bitSize)
@note &out != x and out = the unit element of G
*/
template<class G, class T>
void powerGeneric(G& out, const G& x, const T *y, size_t n, void mul(G&, const G&, const G&) , void square(G&, const G&)){
void powerGeneric(G& out, const G& x, const T *y, size_t n, void mul(G&, const G&, const G&) , void sqr(G&, const G&)){
#if 0
assert(&out != &x);
while (n > 0) {
@ -189,7 +189,7 @@ void powerGeneric(G& out, const G& x, const T *y, size_t n, void mul(G&, const G
m = (int)sizeof(T) * 8;
}
for (int j = m - 1; j >= 0; j--) {
square(out, out);
sqr(out, out);
if (v & (T(1) << j)) {
mul(out, out, x);
}
@ -237,8 +237,8 @@ void powerGeneric(G& out, const G& x, const T *y, size_t n, void mul(G&, const G
for (int i = (int)n - 1; i >= 0; i--) {
T v = y[i];
for (int j = m - 2; j >= 0; j -= 2) {
square(out, out);
square(out, out);
sqr(out, out);
sqr(out, out);
T idx = (v >> j) & 3;
if (idx > 0) {
mul(out, out, tbl[idx - 1]);

@ -31,7 +31,7 @@ void benchFpSub(const char *pStr, const char *xStr, const char *yStr, mcl::fp::M
CYBOZU_BENCH_T(addT, Fp::add, x, x, x);
CYBOZU_BENCH_T(subT, Fp::sub, x, x, y);
CYBOZU_BENCH_T(mulT, Fp::mul, x, x, x);
CYBOZU_BENCH_T(sqrT, Fp::square, x, x);
CYBOZU_BENCH_T(sqrT, Fp::sqr, x, x);
CYBOZU_BENCH_T(invT, x += y;Fp::inv, x, x); // avoid same jmp
printf("%10s bit % 3d add %8.2f sub %8.2f mul %8.2f sqr %8.2f inv %8.2f\n", s, (int)Fp::getBitSize(), addT, subT, mulT, sqrT, invT);
}

@ -164,7 +164,7 @@ struct Test {
R -= P;
}
}
void squareRoot() const
void sqrRoot() const
{
Fp x(para.gx);
Fp y(para.gy);
@ -279,7 +279,7 @@ mul 499.00usec
mul();
neg_mul();
mul_fp();
squareRoot();
sqrRoot();
str();
}
private:

@ -232,7 +232,7 @@ CYBOZU_TEST_AUTO(ope)
z = x * y;
CYBOZU_TEST_EQUAL(z, tbl[i].mul);
Fp::square(z, x);
Fp::sqr(z, x);
CYBOZU_TEST_EQUAL(z, tbl[i].sqr);
z = x / y;

@ -449,7 +449,7 @@ struct Test {
CYBOZU_TEST_EQUAL(z, castTo<Fp>(tbl[i].sub));
z = x * y;
CYBOZU_TEST_EQUAL(z, castTo<Fp>(tbl[i].mul));
Fp::square(z, x);
Fp::sqr(z, x);
CYBOZU_TEST_EQUAL(z, castTo<Fp>(tbl[i].sqr));
z = x / y;
@ -518,7 +518,7 @@ struct Test {
CYBOZU_BENCH("add", operator+, x, x);
CYBOZU_BENCH("sub", operator-, x, y);
CYBOZU_BENCH("mul", operator*, x, x);
CYBOZU_BENCH("sqr", Fp::square, x, x);
CYBOZU_BENCH("sqr", Fp::sqr, x, x);
CYBOZU_BENCH("div", y += x; operator/, x, y);
}
};

Loading…
Cancel
Save