diff --git a/include/mcl/fp_generator.hpp b/include/mcl/fp_generator.hpp index a499ca2..04457b3 100644 --- a/include/mcl/fp_generator.hpp +++ b/include/mcl/fp_generator.hpp @@ -195,7 +195,7 @@ struct FpGenerator : Xbyak::CodeGenerator { @param p [in] pointer to prime @param pn [in] length of prime */ - void init(const uint64_t *p, int pn) + void init(Op& /*op*/, const uint64_t *p, int pn) { if (pn < 2) throw cybozu::Exception("mcl:FpGenerator:small pn") << pn; p_ = p; @@ -244,7 +244,7 @@ struct FpGenerator : Xbyak::CodeGenerator { { StackFrame sf(this, 3); if (isAdd) { - gen_raw_add(sf.p[0], sf.p[1], sf.p[2], rax); + gen_raw_add(sf.p[0], sf.p[1], sf.p[2], rax, pn_); } else { gen_raw_sub(sf.p[0], sf.p[1], sf.p[2], rax); } @@ -254,12 +254,12 @@ struct FpGenerator : Xbyak::CodeGenerator { /* pz[] = px[] + py[] */ - void gen_raw_add(const RegExp& pz, const RegExp& px, const RegExp& py, const Reg64& t) + void gen_raw_add(const RegExp& pz, const RegExp& px, const RegExp& py, const Reg64& t, int n) { mov(t, ptr [px]); add(t, ptr [py]); mov(ptr [pz], t); - for (int i = 1; i < pn_; i++) { + for (int i = 1; i < n; i++) { mov(t, ptr [px + i * 8]); adc(t, ptr [py + i * 8]); mov(ptr [pz + i * 8], t); @@ -474,7 +474,7 @@ struct FpGenerator : Xbyak::CodeGenerator { const Xbyak::CodeGenerator::LabelType jmpMode = pn_ < 5 ? T_AUTO : T_NEAR; inLocalLabel(); - gen_raw_add(pz, px, py, rax); + gen_raw_add(pz, px, py, rax, pn_); mov(px, (size_t)p_); // destroy px if (isFullBit_) { jc(".over", jmpMode); @@ -518,7 +518,7 @@ struct FpGenerator : Xbyak::CodeGenerator { gen_raw_sub(pz, px, py, rax); jnc(".exit", jmpMode); mov(px, (size_t)p_); - gen_raw_add(pz, pz, px, rax); + gen_raw_add(pz, pz, px, rax, pn_); L(".exit"); outLocalLabel(); } diff --git a/src/fp.cpp b/src/fp.cpp index 2c7450e..49e8e36 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -363,7 +363,7 @@ static void initForMont(Op& op, const Unit *p, Mode mode) #ifdef MCL_USE_XBYAK FpGenerator *fg = op.fg; if (fg == 0) return; - fg->init(p, (int)N); + fg->init(op, p, (int)N); op.fp_neg = Xbyak::CastTo(fg->neg_); op.fp_add = Xbyak::CastTo(fg->add_); diff --git a/test/fp_generator_test.cpp b/test/fp_generator_test.cpp index 3209fa3..5930727 100644 --- a/test/fp_generator_test.cpp +++ b/test/fp_generator_test.cpp @@ -189,7 +189,8 @@ void test(const char *pStr) const int pn = mcl::fp::getNonZeroArraySize(p, MAX_N); printf("pn=%d\n", pn); mcl::fp::FpGenerator fg; - fg.init(p, pn); + mcl::fp::Op op; + fg.init(op, p, pn); testAddSub(fg, pn); testNeg(fg, pn); testMulI(fg, pn);