From 6f7ba778266b611434ce79ffc599a49ddd30f1fb Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sat, 4 Jun 2016 20:45:10 +0900 Subject: [PATCH] rewrite fpDbl_subPC --- src/fp.cpp | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/fp.cpp b/src/fp.cpp index 2f70b85..5c360c7 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -130,6 +130,16 @@ struct OpeFunc { */ static inline void fpDbl_addPC(Unit *z, const Unit *x, const Unit *y, const Unit *p) { +#if 0 + if (mpn_add_n(z, x, y, N * 2)) { + mpn_sub_n(z + N, z + N, p, N); + return; + } + Unit tmp[N]; + if (mpn_sub_n(tmp, z + N, p, N) == 0) { + memcpy(z, tmp, sizeof(tmp)); + } +#else Unit ret[N * 2 + 2]; // not N + 1 Unit pDbl[N * 2]; mpz_t mz, mx, my, mp; @@ -142,22 +152,13 @@ struct OpeFunc { mpz_sub(mz, mz, mp); } gmp::getArray(z, N * 2, mz); +#endif } static inline void fpDbl_subPC(Unit *z, const Unit *x, const Unit *y, const Unit *p) { - Unit ret[N * 2 + 1]; - mpz_t mz, mx, my; - set_zero(mz, ret, N * 2 + 1); - set_mpz_t(mx, x, N * 2); - set_mpz_t(my, y, N * 2); - mpz_sub(mz, mx, my); - if (mpz_sgn(mz) < 0) { - Unit pDbl[N * 2]; - mpz_t mp; - set_pDbl(mp, pDbl, p); - mpz_add(mz, mz, mp); + if (mpn_sub_n(z, x, y, N * 2)) { + mpn_add_n(z + N, z + N, p, N); } - gmp::getArray(z, N * 2, mz); } // z[N] <- x[N] + y[N] without carry static inline void fp_addNCC(Unit *z, const Unit *x, const Unit *y)