aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-10-04 14:02:18 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-10-04 14:02:18 +0800
commitd19646967837d5b3bd3ff3856e1296f85ab4156b (patch)
treebcf5f12d41f04dfe0d6128387722450e1a194b23
parentbade8efc64a69b040f51c44dbc1e0d495100498b (diff)
downloaddexon-mcl-d19646967837d5b3bd3ff3856e1296f85ab4156b.tar.gz
dexon-mcl-d19646967837d5b3bd3ff3856e1296f85ab4156b.tar.zst
dexon-mcl-d19646967837d5b3bd3ff3856e1296f85ab4156b.zip
[bn] a little optimization of addLineWithoutP
-rw-r--r--include/mcl/bn.hpp56
-rw-r--r--test/bn_test.cpp6
2 files changed, 30 insertions, 32 deletions
diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp
index b6ca557..662c8d7 100644
--- a/include/mcl/bn.hpp
+++ b/include/mcl/bn.hpp
@@ -705,37 +705,35 @@ struct BNT {
}
static void addLineWithoutP(Fp6& l, G2& R, const G2& Q)
{
- // 4Kclk x 30
#if 1
- Fp2 theta;
- Fp2::mul(theta, Q.y, R.z);
- Fp2::sub(theta, R.y, theta);
- Fp2::mul(l.b, Q.x, R.z);
- Fp2::sub(l.b, R.x, l.b);
- Fp2 lambda2;
- Fp2::sqr(lambda2, l.b);
Fp2 t1, t2, t3, t4;
- Fp2 t;
- Fp2::mul(t1, R.x, lambda2);
- Fp2::add(t2, t1, t1); // 2 R.x lambda^2
- Fp2::mul(t3, lambda2, l.b); // lambda^3
- Fp2::sqr(t4, theta);
- t4 *= R.z; // t4 = R.z theta^2
- Fp2::add(R.x, t3, t4);
- R.x -= t2;
- R.x *= l.b;
- Fp2::mul(t, R.y, t3);
- Fp2::add(R.y, t1, t2);
- R.y -= t3;
- R.y -= t4;
- R.y *= theta;
- R.y -= t;
- Fp2::mul(R.z, R.z, t3);
- Fp2::mul(l.a, theta, Q.x);
- Fp2::mul(t, l.b, Q.y);
- l.a -= t;
- Fp2::mul_xi(l.a, l.a);
- Fp2::neg(l.c, theta);
+ Fp2Dbl T1, T2;
+ Fp2::mul(t1, R.z, Q.x);
+ Fp2::mul(t2, R.z, Q.y);
+ Fp2::sub(t1, R.x, t1);
+ Fp2::sub(t2, R.y, t2);
+ Fp2::sqr(t3, t1);
+ Fp2::mul(R.x, t3, R.x);
+ Fp2::sqr(t4, t2);
+ t3 *= t1;
+ t4 *= R.z;
+ t4 += t3;
+ t4 -= R.x;
+ t4 -= R.x;
+ R.x -= t4;
+ Fp2Dbl_mulOpt(T1, t2, R.x);
+ Fp2Dbl_mulOpt(T2, t3, R.y);
+ Fp2Dbl::sub(T2, T1, T2);
+ Fp2Dbl::mod(R.y, T2);
+ Fp2::mul(R.x, t1, t4);
+ Fp2::mul(R.z, t3, R.z);
+ Fp2::neg(l.c, t2);
+ Fp2Dbl_mulOpt(T1, t2, Q.x);
+ Fp2Dbl_mulOpt(T2, t1, Q.y);
+ Fp2Dbl::sub(T1, T1, T2);
+ Fp2Dbl::mod(t2, T1);
+ Fp2::mul_xi(l.a, t2);
+ l.b = t1;
#else
Fp2 t1, t2, t3, t4, T1, T2;
Fp2::mul(t1, R.z, Q.x);
diff --git a/test/bn_test.cpp b/test/bn_test.cpp
index 4938662..2d07199 100644
--- a/test/bn_test.cpp
+++ b/test/bn_test.cpp
@@ -360,10 +360,10 @@ CYBOZU_TEST_AUTO(naive)
initPairing(ts.cp, g_mode);
G1 P(ts.g1.a, ts.g1.b);
G2 Q(Fp2(ts.g2.aa, ts.g2.ab), Fp2(ts.g2.ba, ts.g2.bb));
-#if 0
+#ifdef ONLY_BENCH
testPairing(P, Q, ts.e);
-clk.put();
-return;
+ clk.put();
+ return;
#endif
testFp12pow(P, Q);
testIo(P, Q);