aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-12-24 16:58:47 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-12-24 16:58:47 +0800
commit1838f97b1e7beb748145c11098295ed155680ffb (patch)
treec79dc70149d6d442a87bd750b4d99f5afda076db
parent41fe8b7a952f8c39b875bd69320d8904f08aaf95 (diff)
downloaddexon-mcl-1838f97b1e7beb748145c11098295ed155680ffb.tar.gz
dexon-mcl-1838f97b1e7beb748145c11098295ed155680ffb.tar.zst
dexon-mcl-1838f97b1e7beb748145c11098295ed155680ffb.zip
add mcl_fp_addNF
-rw-r--r--src/fp.cpp3
-rw-r--r--src/gen.cpp54
-rw-r--r--src/low_func_llvm.hpp1
-rw-r--r--src/proto.hpp1
4 files changed, 38 insertions, 21 deletions
diff --git a/src/fp.cpp b/src/fp.cpp
index a0a5804..e7cc175 100644
--- a/src/fp.cpp
+++ b/src/fp.cpp
@@ -183,10 +183,11 @@ void setOp2(Op& op)
{
op.fp_shr1 = Shr1<N, Tag>::f;
op.fp_neg = Neg<N, Tag>::f;
- op.fp_add = Add<N, Tag>::f;
if (op.isFullBit) {
+ op.fp_add = Add<N, Tag>::f;
op.fp_sub = Sub<N, Tag>::f;
} else {
+ op.fp_add = AddNF<N, Tag>::f;
op.fp_sub = SubNF<N, Tag>::f;
}
if (op.isMont) {
diff --git a/src/gen.cpp b/src/gen.cpp
index cc7d958..627c2d2 100644
--- a/src/gen.cpp
+++ b/src/gen.cpp
@@ -410,36 +410,49 @@ struct Code : public mcl::Generator {
ret(Void);
endFunc();
}
- void gen_mcl_fp_add()
+ void gen_mcl_fp_add(bool isFullBit = true)
{
resetGlobalIdx();
Operand pz(IntPtr, unit);
Operand px(IntPtr, unit);
Operand py(IntPtr, unit);
Operand pp(IntPtr, unit);
- std::string name = "mcl_fp_add" + cybozu::itoa(N) + "L";
+ std::string name = "mcl_fp_add";
+ if (!isFullBit) {
+ name += "NF";
+ }
+ name += cybozu::itoa(N) + "L";
mcl_fp_addM[N] = Function(name, Void, pz, px, py, pp);
verifyAndSetPrivate(mcl_fp_addM[N]);
beginFunc(mcl_fp_addM[N]);
Operand x = loadN(px, N);
Operand y = loadN(py, N);
- Operand p = loadN(pp, N);
- x = zext(x, bit + unit);
- y = zext(y, bit + unit);
- p = zext(p, bit + unit);
- Operand t0 = add(x, y);
- Operand t1 = trunc(t0, bit);
- storeN(t1, pz);
- Operand vc = sub(t0, p);
- Operand c = lshr(vc, bit);
- c = trunc(c, 1);
- Label carry("carry");
- Label nocarry("nocarry");
- br(c, carry, nocarry);
- putLabel(nocarry);
- storeN(trunc(vc, bit), pz);
- ret(Void);
- putLabel(carry);
+ if (isFullBit) {
+ x = zext(x, bit + unit);
+ y = zext(y, bit + unit);
+ Operand t0 = add(x, y);
+ Operand t1 = trunc(t0, bit);
+ storeN(t1, pz);
+ Operand p = loadN(pp, N);
+ p = zext(p, bit + unit);
+ Operand vc = sub(t0, p);
+ Operand c = lshr(vc, bit);
+ c = trunc(c, 1);
+ Label carry("carry");
+ Label nocarry("nocarry");
+ br(c, carry, nocarry);
+ putLabel(nocarry);
+ storeN(trunc(vc, bit), pz);
+ ret(Void);
+ putLabel(carry);
+ } else {
+ x = add(x, y);
+ Operand p = loadN(pp, N);
+ y = sub(x, p);
+ Operand c = trunc(lshr(y, bit - 1), 1);
+ x = select(c, x, y);
+ storeN(x, pz);
+ }
ret(Void);
endFunc();
}
@@ -814,7 +827,8 @@ struct Code : public mcl::Generator {
}
void gen_addsub()
{
- gen_mcl_fp_add();
+ gen_mcl_fp_add(true);
+ gen_mcl_fp_add(false);
gen_mcl_fp_sub(true);
gen_mcl_fp_sub(false);
gen_mcl_fpDbl_add();
diff --git a/src/low_func_llvm.hpp b/src/low_func_llvm.hpp
index d81a956..2871201 100644
--- a/src/low_func_llvm.hpp
+++ b/src/low_func_llvm.hpp
@@ -32,6 +32,7 @@ template<>const void2u Shr1<n, Ltag>::f = &mcl_fp_shr1_ ## n ## L; \
MCL_DEF_MUL(n) \
template<>const void2uI MulUnitPre<n, Ltag>::f = &mcl_fp_mulUnitPre ## n ## L; \
template<>const void4u Add<n, Ltag>::f = &mcl_fp_add ## n ## L; \
+template<>const void4u AddNF<n, Ltag>::f = &mcl_fp_addNF ## n ## L; \
template<>const void4u Sub<n, Ltag>::f = &mcl_fp_sub ## n ## L; \
template<>const void4u SubNF<n, Ltag>::f = &mcl_fp_subNF ## n ## L; \
template<>const void4u Mont<n, Ltag>::f = &mcl_fp_mont ## n ## L; \
diff --git a/src/proto.hpp b/src/proto.hpp
index dda02c7..46dac04 100644
--- a/src/proto.hpp
+++ b/src/proto.hpp
@@ -10,6 +10,7 @@
#define MCL_FP_DEF_FUNC_SUB(n, suf) \
void mcl_fp_add ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
+void mcl_fp_addNF ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_sub ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_subNF ## n ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* x, const mcl::fp::Unit* y, const mcl::fp::Unit* p); \
void mcl_fp_shr1_ ## n ## suf(mcl::fp::Unit*y, const mcl::fp::Unit* x); \