diff --git a/include/mcl/fp_tower.hpp b/include/mcl/fp_tower.hpp index d4536a9..a2cf930 100644 --- a/include/mcl/fp_tower.hpp +++ b/include/mcl/fp_tower.hpp @@ -695,27 +695,6 @@ struct Fp2DblT { FpDbl::neg(y.a, x.a); 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) { 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 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 Fp2T Fp2T::g[Fp2T::gN]; diff --git a/test/common_test.hpp b/test/common_test.hpp index 74a745c..5deb9f1 100644 --- a/test/common_test.hpp +++ b/test/common_test.hpp @@ -163,10 +163,11 @@ void testABCD() 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"); cybozu::XorShift rg; - for (int i = 0; i < 100; i++) { + for (int i = 0; i < 10; i++) { Fp a1, a2; a1.setByCSPRNG(rg); a2.setByCSPRNG(rg); @@ -176,7 +177,12 @@ void testFp2Dbl_mul_xi1() a2.setByCSPRNG(rg); FpDbl::mulPre(x.b, a1, a2); 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); 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());