From 570396efd88d6334c24f611b00eaffeb18b9040c Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 13 Mar 2021 18:30:07 +0900 Subject: [PATCH] use textbook mul for N = 8 --- src/gen.cpp | 3 ++- test/llvm_test.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gen.cpp b/src/gen.cpp index e2f4015..029a673 100644 --- a/src/gen.cpp +++ b/src/gen.cpp @@ -715,11 +715,12 @@ struct Code : public mcl::Generator { Operand z = mul(x, y); storeN(z, pz); ret(Void); - } else if (N >= 8 && (N % 2) == 0) { + } else if (N > 8 && (N % 2) == 0) { /* W = 1 << half (aW + b)(cW + d) = acW^2 + (ad + bc)W + bd ad + bc = (a + b)(c + d) - ac - bd + @note Karatsuba is slower for N = 8 */ const int H = N / 2; const int half = bit / 2; diff --git a/test/llvm_test.cpp b/test/llvm_test.cpp index 18bf757..ab0d821 100644 --- a/test/llvm_test.cpp +++ b/test/llvm_test.cpp @@ -70,7 +70,7 @@ void bench(Unit *x, Unit *y, const Unit *p) { printf("N=%zd\n", N); Unit xx[N * 2], yy[N * 2]; - const int C = 1000; + const int C = 10000; CYBOZU_BENCH_C("mulPre", C, mulPre, xx, x, y); CYBOZU_BENCH_C("sqrPre", C, sqrPre, yy, x); CYBOZU_BENCH_C("mod ", C, mod, yy, xx, p);