diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2016-12-25 13:44:05 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2016-12-25 13:44:05 +0800 |
commit | 0caef365788e3256b95cfa97b7e0b1ff6424b850 (patch) | |
tree | 946096763c73eefa30cb4399fa6e1f610f738d61 | |
parent | cbb384b55e2ea7d025f590be76ebd97ca6462dc7 (diff) | |
download | tangerine-mcl-0caef365788e3256b95cfa97b7e0b1ff6424b850.tar.gz tangerine-mcl-0caef365788e3256b95cfa97b7e0b1ff6424b850.tar.zst tangerine-mcl-0caef365788e3256b95cfa97b7e0b1ff6424b850.zip |
use SubIfPossible for N > 1
-rw-r--r-- | src/low_func.hpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/low_func.hpp b/src/low_func.hpp index c806513..c3c7450 100644 --- a/src/low_func.hpp +++ b/src/low_func.hpp @@ -358,6 +358,25 @@ struct Dbl_Mod { template<size_t N, class Tag> const void3u Dbl_Mod<N, Tag>::f = Dbl_Mod<N, Tag>::func; +template<size_t N, class Tag> +struct SubIfPossible { + static inline void f(Unit *z, const Unit *p) + { + Unit tmp[N - 1]; + if (SubPre<N - 1, Tag>::f(tmp, z, p) == 0) { + copyC<N - 1>(z, tmp); + z[N - 1] = 0; + } + } +}; +template<class Tag> +struct SubIfPossible<1, Tag> { + static inline void f(Unit *, const Unit *) + { + } +}; + + // z[N] <- (x[N] + y[N]) % p[N] template<size_t N, bool isFullBit, class Tag = Gtag> struct Add { @@ -381,10 +400,8 @@ struct Add { SubPre<N, Tag>::f(z, z, p); return; } - Unit tmp[N]; - if (SubPre<N, Tag>::f(tmp, z, p) == 0) { - copyC<N>(z, tmp); - } + /* the top of z and p are same */ + SubIfPossible<N, Tag>::f(z, p); } } static const void4u f; |