a little optimize Fp6::mul

update-fork
MITSUNARI Shigeo 4 years ago
parent 3423988fa0
commit 6b5a64c3ec
  1. 23
      include/mcl/fp_tower.hpp
  2. 32
      test/common_test.hpp

@ -978,6 +978,7 @@ template<class Fp>
struct Fp6DblT {
typedef Fp2T<Fp> Fp2;
typedef Fp6T<Fp> Fp6;
typedef FpDblT<Fp> FpDbl;
typedef Fp2DblT<Fp> Fp2Dbl;
typedef Fp6DblT<Fp> Fp6Dbl;
typedef fp::Unit Unit;
@ -994,6 +995,11 @@ struct Fp6DblT {
Fp2Dbl::sub(z.b, x.b, y.b);
Fp2Dbl::sub(z.c, x.c, y.c);
}
static void sub2(Fp2Dbl& y, const Fp2Dbl& x)
{
FpDbl::sub(y.a, y.a, x.a);
FpDbl::subPre(y.b, y.b, x.b);
}
/*
x = a + bv + cv^2, y = d + ev + fv^2, v^3 = xi
xy = (ad + (bf + ce)xi) + ((ae + bd) + cf xi)v + ((af + cd) + be)v^2
@ -1010,7 +1016,7 @@ struct Fp6DblT {
const Fp2& d = y.a;
const Fp2& e = y.b;
const Fp2& f = y.c;
#if 0
#if 1
Fp2Dbl& ZA = z.a;
Fp2Dbl& ZB = z.b;
Fp2Dbl& ZC = z.c;
@ -1028,15 +1034,12 @@ struct Fp6DblT {
Fp2Dbl::mulPre(BE, b, e);
Fp2Dbl::mulPre(CF, c, f);
Fp2Dbl::mulPre(AD, a, d);
Fp2Dbl::sub(ZA, ZA, BE);
Fp2Dbl::sub(ZA, ZA, CF);
// Fp2Dbl::sub_p_if_possible(ZA, ZA);
Fp2Dbl::sub(ZB, ZB, AD);
Fp2Dbl::sub(ZB, ZB, BE);
// Fp2Dbl::sub_p_if_possible(ZB, ZB);
Fp2Dbl::sub(ZC, ZC, AD);
Fp2Dbl::sub(ZC, ZC, CF);
// Fp2Dbl::sub_p_if_possible(ZC, ZC);
sub2(ZA, BE);
sub2(ZA, CF);
sub2(ZB, AD);
sub2(ZB, BE);
sub2(ZC, AD);
sub2(ZC, CF);
Fp2Dbl::mul_xi(ZA, ZA);
Fp2Dbl::add(ZA, ZA, AD);
Fp2Dbl::mul_xi(CF, CF);

@ -129,14 +129,21 @@ void testMul2()
void testABCDsub(const Fp2& a, const Fp2& b, const Fp2& c, const Fp2& d)
{
Fp2 t1, t2;
Fp2::add(t1, a, b);
Fp2::add(t2, c, d);
Fp2::addPre(t1, a, b);
Fp2::addPre(t2, c, d);
Fp2Dbl T1, AC, BD;
Fp2Dbl::mulPre(T1, t1, t2);
Fp2Dbl::mulPre(AC, a, c);
Fp2Dbl::mulPre(BD, b, d);
#if 0
Fp2Dbl::sub(T1, T1, AC);
Fp2Dbl::sub(T1, T1, BD);
#else
FpDbl::sub(T1.a, T1.a, AC.a);
FpDbl::subPre(T1.b, T1.b, AC.b);
FpDbl::sub(T1.a, T1.a, BD.a);
FpDbl::subPre(T1.b, T1.b, BD.b);
#endif
Fp2Dbl::mod(t1, T1);
CYBOZU_TEST_EQUAL(t1, a * d + b * c);
}
@ -145,13 +152,20 @@ void testABCD()
{
puts("testMisc1");
// (a + b)(c + d) - ac - bd = ad + bc
Fp2 a, b, c, d;
a.a = -1;
a.b = -1;
b = a;
c = a;
d = a;
testABCDsub(a, b, c, d);
Fp2 a[4];
a[0].a = -1;
a[0].b = -1;
a[1] = a[0];
a[2] = a[0];
a[3] = a[0];
testABCDsub(a[0], a[1], a[2], a[3]);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 4; j++) {
a[j].a.setByCSPRNG();
a[j].b.setByCSPRNG();
}
testABCDsub(a[0], a[1], a[2], a[3]);
}
}
void testCommon(const G1& P, const G2& Q)

Loading…
Cancel
Save