fix for c++03

update-fork
MITSUNARI Shigeo 5 years ago
parent 2f1b4c9a56
commit 9f09970f70
  1. 4
      include/mcl/ec.hpp
  2. 2
      test/bls12_test.cpp
  3. 2
      test/bn384_test.cpp
  4. 2
      test/bn512_test.cpp
  5. 2
      test/bn_test.cpp
  6. 55
      test/common_test.hpp

@ -1196,7 +1196,7 @@ public:
@note &z != xVec[i] @note &z != xVec[i]
*/ */
private: private:
template<size_t N = 32, class tag, size_t maxBitSize, template<class _tag, size_t _maxBitSize>class FpT> template<size_t N, class tag, size_t maxBitSize, template<class _tag, size_t _maxBitSize>class FpT>
static inline size_t addMulVecN(EcT& z, const EcT *xVec, const FpT<tag, maxBitSize> *yVec, size_t n) static inline size_t addMulVecN(EcT& z, const EcT *xVec, const FpT<tag, maxBitSize> *yVec, size_t n)
{ {
if (n > N) n = N; if (n > N) n = N;
@ -1236,7 +1236,7 @@ public:
r.clear(); r.clear();
while (n > 0) { while (n > 0) {
EcT t; EcT t;
size_t done = addMulVecN(t, xVec, yVec, n); size_t done = addMulVecN<32>(t, xVec, yVec, n);
r += t; r += t;
xVec += done; xVec += done;
yVec += done; yVec += done;

@ -384,7 +384,7 @@ CYBOZU_TEST_AUTO(naive)
testPairing(P, Q, ts.e); testPairing(P, Q, ts.e);
testPrecomputed(P, Q); testPrecomputed(P, Q);
testMillerLoop2(P, Q); testMillerLoop2(P, Q);
testCommon(); testCommon(P, Q);
testBench(P, Q); testBench(P, Q);
} }
int count = (int)clk.getCount(); int count = (int)clk.getCount();

@ -40,7 +40,7 @@ void testCurve(const mcl::CurveParam& cp)
pairing(e2, aP, bQ); pairing(e2, aP, bQ);
GT::pow(e1, e1, a * b); GT::pow(e1, e1, a * b);
CYBOZU_TEST_EQUAL(e1, e2); CYBOZU_TEST_EQUAL(e1, e2);
testCommon(); testCommon(P, Q);
testBench(P, Q); testBench(P, Q);
testSquareRoot(); testSquareRoot();
testLagrange(); testLagrange();

@ -34,7 +34,7 @@ void testCurve(const mcl::CurveParam& cp)
pairing(e2, aP, bQ); pairing(e2, aP, bQ);
GT::pow(e1, e1, a * b); GT::pow(e1, e1, a * b);
CYBOZU_TEST_EQUAL(e1, e2); CYBOZU_TEST_EQUAL(e1, e2);
testCommon(); testCommon(P, Q);
testBench(P, Q); testBench(P, Q);
testSquareRoot(); testSquareRoot();
testLagrange(); testLagrange();

@ -402,7 +402,7 @@ CYBOZU_TEST_AUTO(naive)
testPrecomputed(P, Q); testPrecomputed(P, Q);
testMillerLoop2(P, Q); testMillerLoop2(P, Q);
testMillerLoopVec(); testMillerLoopVec();
testCommon(); testCommon(P, Q);
testBench(P, Q); testBench(P, Q);
benchAddDblG1(); benchAddDblG1();
benchAddDblG2(); benchAddDblG2();

@ -1,27 +1,44 @@
void testMulVec() template<class G, class F>
void naiveMulVec(G& out, const G *xVec, const F *yVec, size_t n)
{ {
using namespace mcl::bn; G r, t;
const size_t n = 3; r.clear();
G1 xVec[n];
Fr yVec[n];
G1 ok;
ok.clear();
char c = 'a';
for (size_t i = 0; i < n; i++) { for (size_t i = 0; i < n; i++) {
hashAndMapToG1(xVec[i], &c, 1); G::mul(t, xVec[i], yVec[i]);
r += t;
}
out = r;
}
template<class G>
void testMulVec(const G& P)
{
using namespace mcl::bn;
const int N = 33;
G xVec[N];
mcl::bn::Fr yVec[N];
for (size_t i = 0; i < N; i++) {
G::mul(xVec[i], P, i + 3);
yVec[i].setByCSPRNG(); yVec[i].setByCSPRNG();
G1 t;
G1::mul(t, xVec[i], yVec[i]);
ok += t;
} }
G1 z; const size_t nTbl[] = { 1, 2, 3, 5, 30, 31, 32, 33 };
G1::mulVec(z, xVec, yVec, n); const int C = 400;
CYBOZU_TEST_EQUAL(z, ok); for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(nTbl); i++) {
CYBOZU_BENCH_C("mulVec(new)", 1000, G1::mulVec, z, xVec, yVec, n); const size_t n = nTbl[i];
CYBOZU_BENCH_C("mulVec(old)", 1000, G1::mulVec, z, xVec, yVec, n, true); G Q1, Q2;
CYBOZU_TEST_ASSERT(n <= N);
naiveMulVec(Q1, xVec, yVec, n);
G::mulVec(Q2, xVec, yVec, n);
CYBOZU_TEST_EQUAL(Q1, Q2);
printf("n=%zd\n", n);
CYBOZU_BENCH_C("naive ", C, naiveMulVec, Q1, xVec, yVec, n);
CYBOZU_BENCH_C("mulVec", C, G::mulVec, Q1, xVec, yVec, n);
}
} }
void testCommon() template<class G1, class G2>
void testCommon(const G1& P, const G2&)
{ {
testMulVec(); testMulVec(P);
} }

Loading…
Cancel
Save