avoid cast of Fp2::sub

2merge^2
MITSUNARI Shigeo 4 years ago
parent bb83774fad
commit a36e6f276b
  1. 21
      include/mcl/fp_tower.hpp

@ -229,16 +229,22 @@ public:
Fp::op_.fp2_addA_(z.a.v_, x.a.v_, y.a.v_); Fp::op_.fp2_addA_(z.a.v_, x.a.v_, y.a.v_);
#else #else
addA(z.a.v_, x.a.v_, y.a.v_); addA(z.a.v_, x.a.v_, y.a.v_);
#endif
}
static void sub(Fp2T& z, const Fp2T& x, const Fp2T& y)
{
#ifdef MCL_XBYAK_DIRECT_CALL
Fp::op_.fp2_subA_(z.a.v_, x.a.v_, y.a.v_);
#else
subA(z.a.v_, x.a.v_, y.a.v_);
#endif #endif
} }
#ifdef MCL_XBYAK_DIRECT_CALL #ifdef MCL_XBYAK_DIRECT_CALL
static void (*sub)(Fp2T& z, const Fp2T& x, const Fp2T& y);
static void (*neg)(Fp2T& y, const Fp2T& x); static void (*neg)(Fp2T& y, const Fp2T& x);
static void (*mul)(Fp2T& z, const Fp2T& x, const Fp2T& y); static void (*mul)(Fp2T& z, const Fp2T& x, const Fp2T& y);
static void (*sqr)(Fp2T& y, const Fp2T& x); static void (*sqr)(Fp2T& y, const Fp2T& x);
static void (*mul2)(Fp2T& y, const Fp2T& x); static void (*mul2)(Fp2T& y, const Fp2T& x);
#else #else
static void sub(Fp2T& z, const Fp2T& x, const Fp2T& y) { subC(z, x, y); }
static void neg(Fp2T& y, const Fp2T& x) { negC(y, x); } static void neg(Fp2T& y, const Fp2T& x) { negC(y, x); }
static void mul(Fp2T& z, const Fp2T& x, const Fp2T& y) { mulC(z, x, y); } static void mul(Fp2T& z, const Fp2T& x, const Fp2T& y) { mulC(z, x, y); }
static void sqr(Fp2T& y, const Fp2T& x) { sqrC(y, x); } static void sqr(Fp2T& y, const Fp2T& x) { sqrC(y, x); }
@ -394,8 +400,9 @@ public:
if (op.fp2_addA_ == 0) { if (op.fp2_addA_ == 0) {
op.fp2_addA_ = addA; op.fp2_addA_ = addA;
} }
sub = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_subA_); if (op.fp2_subA_ == 0) {
if (sub == 0) sub = subC; op.fp2_subA_ = subA;
}
neg = fp::func_ptr_cast<void (*)(Fp2T& y, const Fp2T& x)>(op.fp2_negA_); neg = fp::func_ptr_cast<void (*)(Fp2T& y, const Fp2T& x)>(op.fp2_negA_);
if (neg == 0) neg = negC; if (neg == 0) neg = negC;
mul = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_mulA_); mul = fp::func_ptr_cast<void (*)(Fp2T& z, const Fp2T& x, const Fp2T& y)>(op.fp2_mulA_);
@ -501,8 +508,11 @@ private:
Fp::add(z.a, x.a, y.a); Fp::add(z.a, x.a, y.a);
Fp::add(z.b, x.b, y.b); Fp::add(z.b, x.b, y.b);
} }
static void subC(Fp2T& z, const Fp2T& x, const Fp2T& y) static void subA(Unit *pz, const Unit *px, const Unit *py)
{ {
Fp2T& z = *reinterpret_cast<Fp2T*>(pz);
const Fp2T& x = *reinterpret_cast<const Fp2T*>(px);
const Fp2T& y = *reinterpret_cast<const Fp2T*>(py);
Fp::sub(z.a, x.a, y.a); Fp::sub(z.a, x.a, y.a);
Fp::sub(z.b, x.b, y.b); Fp::sub(z.b, x.b, y.b);
} }
@ -603,7 +613,6 @@ private:
}; };
#ifdef MCL_XBYAK_DIRECT_CALL #ifdef MCL_XBYAK_DIRECT_CALL
template<class Fp_> void (*Fp2T<Fp_>::sub)(Fp2T& z, const Fp2T& x, const Fp2T& y);
template<class Fp_> void (*Fp2T<Fp_>::neg)(Fp2T& y, const Fp2T& x); template<class Fp_> void (*Fp2T<Fp_>::neg)(Fp2T& y, const Fp2T& x);
template<class Fp_> void (*Fp2T<Fp_>::mul)(Fp2T& z, const Fp2T& x, const Fp2T& y); template<class Fp_> void (*Fp2T<Fp_>::mul)(Fp2T& z, const Fp2T& x, const Fp2T& y);
template<class Fp_> void (*Fp2T<Fp_>::sqr)(Fp2T& y, const Fp2T& x); template<class Fp_> void (*Fp2T<Fp_>::sqr)(Fp2T& y, const Fp2T& x);

Loading…
Cancel
Save