MITSUNARI Shigeo 9 years ago
parent 6b1d7523da
commit dcf1602828
  1. 12
      include/mcl/fp_generator.hpp
  2. 2
      src/fp.cpp
  3. 3
      test/fp_generator_test.cpp

@ -195,7 +195,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
@param p [in] pointer to prime @param p [in] pointer to prime
@param pn [in] length of 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; if (pn < 2) throw cybozu::Exception("mcl:FpGenerator:small pn") << pn;
p_ = p; p_ = p;
@ -244,7 +244,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
{ {
StackFrame sf(this, 3); StackFrame sf(this, 3);
if (isAdd) { 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 { } else {
gen_raw_sub(sf.p[0], sf.p[1], sf.p[2], rax); gen_raw_sub(sf.p[0], sf.p[1], sf.p[2], rax);
} }
@ -254,12 +254,12 @@ struct FpGenerator : Xbyak::CodeGenerator {
/* /*
pz[] = px[] + py[] 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]); mov(t, ptr [px]);
add(t, ptr [py]); add(t, ptr [py]);
mov(ptr [pz], t); mov(ptr [pz], t);
for (int i = 1; i < pn_; i++) { for (int i = 1; i < n; i++) {
mov(t, ptr [px + i * 8]); mov(t, ptr [px + i * 8]);
adc(t, ptr [py + i * 8]); adc(t, ptr [py + i * 8]);
mov(ptr [pz + i * 8], t); 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; const Xbyak::CodeGenerator::LabelType jmpMode = pn_ < 5 ? T_AUTO : T_NEAR;
inLocalLabel(); inLocalLabel();
gen_raw_add(pz, px, py, rax); gen_raw_add(pz, px, py, rax, pn_);
mov(px, (size_t)p_); // destroy px mov(px, (size_t)p_); // destroy px
if (isFullBit_) { if (isFullBit_) {
jc(".over", jmpMode); jc(".over", jmpMode);
@ -518,7 +518,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
gen_raw_sub(pz, px, py, rax); gen_raw_sub(pz, px, py, rax);
jnc(".exit", jmpMode); jnc(".exit", jmpMode);
mov(px, (size_t)p_); mov(px, (size_t)p_);
gen_raw_add(pz, pz, px, rax); gen_raw_add(pz, pz, px, rax, pn_);
L(".exit"); L(".exit");
outLocalLabel(); outLocalLabel();
} }

@ -363,7 +363,7 @@ static void initForMont(Op& op, const Unit *p, Mode mode)
#ifdef MCL_USE_XBYAK #ifdef MCL_USE_XBYAK
FpGenerator *fg = op.fg; FpGenerator *fg = op.fg;
if (fg == 0) return; if (fg == 0) return;
fg->init(p, (int)N); fg->init(op, p, (int)N);
op.fp_neg = Xbyak::CastTo<void2u>(fg->neg_); op.fp_neg = Xbyak::CastTo<void2u>(fg->neg_);
op.fp_add = Xbyak::CastTo<void3u>(fg->add_); op.fp_add = Xbyak::CastTo<void3u>(fg->add_);

@ -189,7 +189,8 @@ void test(const char *pStr)
const int pn = mcl::fp::getNonZeroArraySize(p, MAX_N); const int pn = mcl::fp::getNonZeroArraySize(p, MAX_N);
printf("pn=%d\n", pn); printf("pn=%d\n", pn);
mcl::fp::FpGenerator fg; mcl::fp::FpGenerator fg;
fg.init(p, pn); mcl::fp::Op op;
fg.init(op, p, pn);
testAddSub(fg, pn); testAddSub(fg, pn);
testNeg(fg, pn); testNeg(fg, pn);
testMulI(fg, pn); testMulI(fg, pn);

Loading…
Cancel
Save