2merge^2
MITSUNARI Shigeo 4 years ago
parent 8f195134f7
commit 3be037a853
  1. 42
      include/mcl/fp_tower.hpp
  2. 12
      test/common_test.hpp

@ -695,27 +695,6 @@ struct Fp2DblT {
FpDbl::neg(y.a, x.a); FpDbl::neg(y.a, x.a);
FpDbl::neg(y.b, x.b); FpDbl::neg(y.b, x.b);
} }
static void mul_xi_1A(Unit *py, const Unit *px)
{
Fp2Dbl& y = castD(py);
const Fp2Dbl& x = castD(px);
FpDbl t;
FpDbl::add(t, x.a, x.b);
FpDbl::sub(y.a, x.a, x.b);
y.b = t;
}
static void mul_xi_genericA(Unit *py, const Unit *px)
{
const uint32_t xi_a = Fp2::get_xi_a();
Fp2Dbl& y = castD(py);
const Fp2Dbl& x = castD(px);
FpDbl t;
FpDbl::mulUnit(t, x.a, xi_a);
FpDbl::sub(t, t, x.b);
FpDbl::mulUnit(y.b, x.b, xi_a);
FpDbl::add(y.b, y.b, x.a);
y.a = t;
}
static void mulPre(Fp2DblT& z, const Fp2& x, const Fp2& y) static void mulPre(Fp2DblT& z, const Fp2& x, const Fp2& y)
{ {
Fp::getOp().fp2Dbl_mulPreA_(z.a.v_, x.getUnit(), y.getUnit()); Fp::getOp().fp2Dbl_mulPreA_(z.a.v_, x.getUnit(), y.getUnit());
@ -804,6 +783,27 @@ private:
Fp::sub(t1, x.a, x.b); // a - b Fp::sub(t1, x.a, x.b); // a - b
FpDbl::mulPre(y.a, t1, t2); // (a + b)(a - b) FpDbl::mulPre(y.a, t1, t2); // (a + b)(a - b)
} }
static void mul_xi_1A(Unit *py, const Unit *px)
{
Fp2Dbl& y = castD(py);
const Fp2Dbl& x = castD(px);
FpDbl t;
FpDbl::add(t, x.a, x.b);
FpDbl::sub(y.a, x.a, x.b);
y.b = t;
}
static void mul_xi_genericA(Unit *py, const Unit *px)
{
const uint32_t xi_a = Fp2::get_xi_a();
Fp2Dbl& y = castD(py);
const Fp2Dbl& x = castD(px);
FpDbl t;
FpDbl::mulUnit(t, x.a, xi_a);
FpDbl::sub(t, t, x.b);
FpDbl::mulUnit(y.b, x.b, xi_a);
FpDbl::add(y.b, y.b, x.a);
y.a = t;
}
}; };
template<class Fp> Fp2T<Fp> Fp2T<Fp>::g[Fp2T<Fp>::gN]; template<class Fp> Fp2T<Fp> Fp2T<Fp>::g[Fp2T<Fp>::gN];

@ -163,10 +163,11 @@ void testABCD()
void testFp2Dbl_mul_xi1() void testFp2Dbl_mul_xi1()
{ {
if (Fp2::get_xi_a() != 1) return; const uint32_t xi_a = Fp2::get_xi_a();
if (xi_a != 1) return;
puts("testFp2Dbl_mul_xi1"); puts("testFp2Dbl_mul_xi1");
cybozu::XorShift rg; cybozu::XorShift rg;
for (int i = 0; i < 100; i++) { for (int i = 0; i < 10; i++) {
Fp a1, a2; Fp a1, a2;
a1.setByCSPRNG(rg); a1.setByCSPRNG(rg);
a2.setByCSPRNG(rg); a2.setByCSPRNG(rg);
@ -176,7 +177,12 @@ void testFp2Dbl_mul_xi1()
a2.setByCSPRNG(rg); a2.setByCSPRNG(rg);
FpDbl::mulPre(x.b, a1, a2); FpDbl::mulPre(x.b, a1, a2);
Fp2Dbl ok; Fp2Dbl ok;
Fp2Dbl::mul_xi_1C(ok, x); {
FpDbl::mulUnit(ok.a, x.a, xi_a);
ok.a -= x.b;
FpDbl::mulUnit(ok.b, x.b, xi_a);
ok.b += x.a;
}
Fp2Dbl::mul_xi(x, x); Fp2Dbl::mul_xi(x, x);
CYBOZU_TEST_EQUAL_ARRAY(ok.a.getUnit(), x.a.getUnit(), ok.a.getUnitSize()); CYBOZU_TEST_EQUAL_ARRAY(ok.a.getUnit(), x.a.getUnit(), ok.a.getUnitSize());
CYBOZU_TEST_EQUAL_ARRAY(ok.b.getUnit(), x.b.getUnit(), ok.b.getUnitSize()); CYBOZU_TEST_EQUAL_ARRAY(ok.b.getUnit(), x.b.getUnit(), ok.b.getUnitSize());

Loading…
Cancel
Save