/* sudo cpufreq-set -c 0 -g performance mycl karatsuba.cpp -DMCL_USE_LLVM=1 ../lib/libmcl.a && ./a.out */ #include #include #include #include "../src/low_func.hpp" #ifdef MCL_USE_LLVM #include "../src/low_func_llvm.hpp" #endif #include #include typedef mcl::FpT<> Fp; using namespace mcl::fp; void dump(const Unit *x, size_t N) { for (size_t i = 0; i < N; i++) { printf("%016llx ", (long long)x[N - 1 - i]); } printf("\n"); } void gggKara(uint64_t *z, const uint64_t *x, const uint64_t *) { SqrPre<8, Gtag>::f(z, x); } void gggLLVM(uint64_t *z, const uint64_t *x, const uint64_t *y) { MulPre<8, Ltag>::f(z, x, y); } template void benchKaratsuba() { cybozu::XorShift rg; printf("N=%d\n", (int)N); Unit z[N * 2]; rg.read(z, N); CYBOZU_BENCH("g:mulPre ", (MulPreCore::f), z, z, z); CYBOZU_BENCH("g:mulKara", (MulPre::karatsuba), z, z, z); CYBOZU_BENCH("g:sqrPre ", (SqrPreCore::f), z, z); CYBOZU_BENCH("g:sqrKara", (SqrPre::karatsuba), z, z); #ifdef MCL_USE_LLVM CYBOZU_BENCH("l:mulPre ", (MulPreCore::f), z, z, z); CYBOZU_BENCH("l:mulKara", (MulPre::karatsuba), z, z, z); CYBOZU_BENCH("l:sqrPre ", (SqrPreCore::f), z, z); CYBOZU_BENCH("l:sqrKara", (SqrPre::karatsuba), z, z); #endif } CYBOZU_TEST_AUTO(karatsuba) { benchKaratsuba<4>(); benchKaratsuba<6>(); benchKaratsuba<8>(); #if MCL_MAX_BIT_SIZE == 768 benchKaratsuba<10>(); benchKaratsuba<12>(); #endif }