add sqrt but not enable

dev
MITSUNARI Shigeo 9 years ago
parent 9aa0ac8f0e
commit aa930b78c1
  1. 10
      include/mcl/fp.hpp
  2. 6
      include/mcl/op.hpp
  3. 19
      src/fp.cpp

@ -75,6 +75,7 @@ public:
assert(sizeof(mp_limb_t) == sizeof(Unit));
// set default wrapper function
op_.neg = negW;
op_.sqr = sqrW;
op_.add = addW;
op_.sub = subW;
op_.mul = mulW;
@ -277,7 +278,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) { mul(y, x, x); }
static inline void square(FpT& y, const FpT& x) { op_.mul(y.v_, x.v_, x.v_); }
static inline void div(FpT& z, const FpT& x, const FpT& y)
{
FpT rev;
@ -430,6 +431,13 @@ public:
op_.mulPreP(xy, x, y);
op_.modP(z, xy, op_.p);
}
static inline void sqrW(Unit *y, const Unit *x)
{
// Unit xx[maxSize * 2];
// op_.sqrPreP(xx, x);
// op_.modP(y, xx, op_.p);
mulW(y, x, x);
}
static inline void negW(Unit *y, const Unit *x)
{
op_.negP(y, x, op_.p);

@ -75,6 +75,7 @@ struct Op {
void2u copy;
// not require p(function having p)
void2u neg;
void2u sqr;
void3u add;
void3u sub;
void3u mul;
@ -86,6 +87,7 @@ struct Op {
void (*mont)(Unit *z, const Unit *x, const Unit *y, const Unit *p, Unit rp);
// require p
void3u negP;
void2u sqrPreP;
void2uOp invOp;
void4u addP;
void4u subP;
@ -95,10 +97,10 @@ struct Op {
Op()
: N(0), bitSize(0)
, isZero(0), clear(0), copy(0)
, neg(0), add(0), sub(0), mul(0)
, neg(0), sqr(0), add(0), sub(0), mul(0)
, useMont(false), preInv(0)
, rp(0), mont(0)
, negP(0), invOp(0), addP(0), subP(0), mulPreP(0), modP(0)
, negP(0), sqrPreP(0), invOp(0), addP(0), subP(0), mulPreP(0), modP(0)
, fg(createFpGenerator())
{
}

@ -131,6 +131,15 @@ struct OpeFunc {
mpz_mul(mz, mx, my);
Gmp::getArray(z, N * 2, mz);
}
static inline void sqrPreC(Unit *y, const Unit *x)
{
// mpz_t mx, my;
// set_zero(my, y, N * 2);
// set_mpz_t(mx, x);
// mpz_mul(my, mx, mx);
// Gmp::getArray(y, N * 2, my);
mulPreC(y, x, x);
}
// x[N * 2] -> y[N]
static inline void modC(Unit *y, const Unit *x, const Unit *p)
{
@ -172,6 +181,10 @@ struct OpeFunc {
}
subC(y, p, x, p);
}
static inline void sqrC(Unit *y, const Unit *x, const Unit *p)
{
sqrC(y, p, x, p);
}
};
#ifdef MCL_USE_LLVM
@ -200,8 +213,9 @@ struct OpeFunc {
addP = OpeFunc<n>::addC; \
subP = OpeFunc<n>::subC; \
mulPreP = OpeFunc<n>::mulPreC; \
sqrPreP = OpeFunc<n>::sqrPreC; \
modP = OpeFunc<n>::modC; \
SET_OP_LLVM(n)
SET_OP_LLVM(n)
#ifdef MCL_USE_XBYAK
inline void invOpForMont(Unit *y, const Unit *x, const Op& op)
@ -256,6 +270,9 @@ static void initForMont(Op& op, const Unit *p, Mode mode)
op.add = Xbyak::CastTo<void3u>(fg->add_);
op.sub = Xbyak::CastTo<void3u>(fg->sub_);
op.mul = Xbyak::CastTo<void3u>(fg->mul_);
// if (fg->sqr_) {
// op.sqr = Xbyak::CastTo<void2u>(fg->sqr_);
// }
op.preInv = Xbyak::CastTo<int2u>(op.fg->preInv_);
op.invOp = &invOpForMont;

Loading…
Cancel
Save