FpDBl::add does not pass test

dev
MITSUNARI Shigeo 9 years ago
parent 07372ca3af
commit 26f31a71aa
  1. 8
      include/mcl/fp.hpp
  2. 25
      src/fp.cpp
  3. 3
      test/fp_tower_test.cpp

@ -192,10 +192,18 @@ public:
return *this; return *this;
} }
static inline bool useMont() { return op_.useMont; } static inline bool useMont() { return op_.useMont; }
/*
convert normal value to Montgomery value
do nothing is !useMont()
*/
void toMont() void toMont()
{ {
if (useMont()) op_.toMont(v_, v_); if (useMont()) op_.toMont(v_, v_);
} }
/*
convert Montgomery value to normal value
do nothing is !useMont()
*/
void fromMont() void fromMont()
{ {
if (useMont()) op_.fromMont(v_, v_); if (useMont()) op_.fromMont(v_, v_);

@ -138,6 +138,7 @@ struct OpeFunc {
*/ */
static inline void fpDbl_addPC(Unit *z, const Unit *x, const Unit *y, const Unit *p) static inline void fpDbl_addPC(Unit *z, const Unit *x, const Unit *y, const Unit *p)
{ {
puts("BBB");
Unit ret[N * 2 + 2]; // not N + 1 Unit ret[N * 2 + 2]; // not N + 1
Unit pDbl[N * 2]; Unit pDbl[N * 2];
mpz_t mz, mx, my, mp; mpz_t mz, mx, my, mp;
@ -264,16 +265,20 @@ struct OpeFunc {
} \ } \
mont = mcl_fp_mont ## n; \ mont = mcl_fp_mont ## n; \
} }
#define SET_OP_DBL_LLVM(n2) \ #define SET_OP_DBL_LLVM(n, n2) \
if (mode == FP_LLVM || mode == FP_LLVM_MONT) { \ if (mode == FP_LLVM || mode == FP_LLVM_MONT) { \
if (!fullBit && n2 <= 512) { \ if (n <= 256) { \
fpDbl_addNC = mcl_fp_addNC ## n2; \ fpDbl_addP = mcl_fpDbl_add ## n; \
fpDbl_subNC = mcl_fp_subNC ## n2; \ fpDbl_subP = mcl_fpDbl_sub ## n; \
if (!fullBit) { \
fpDbl_addNC = mcl_fp_addNC ## n2; \
fpDbl_subNC = mcl_fp_subNC ## n2; \
} \
} \ } \
} }
#else #else
#define SET_OP_LLVM(n) #define SET_OP_LLVM(n)
#define SET_OP_DBL_LLVM(n2) #define SET_OP_DBL_LLVM(n, n2)
#endif #endif
#define SET_OP(n) \ #define SET_OP(n) \
@ -389,9 +394,9 @@ void Op::init(const std::string& mstr, int base, size_t maxBitSize, Mode mode)
case 32: case 32:
case 64: case 64:
case 96: case 96:
case 128: SET_OP(128); SET_OP_DBL_LLVM(256); break; case 128: SET_OP(128); SET_OP_DBL_LLVM(128, 256); break;
case 192: SET_OP(192); SET_OP_DBL_LLVM(384); break; case 192: SET_OP(192); SET_OP_DBL_LLVM(192, 384); break;
case 256: SET_OP(256); SET_OP_DBL_LLVM(512); break; case 256: SET_OP(256); SET_OP_DBL_LLVM(256, 512); break;
case 320: SET_OP(320); break; case 320: SET_OP(320); break;
case 384: SET_OP(384); break; case 384: SET_OP(384); break;
case 448: SET_OP(448); break; case 448: SET_OP(448); break;
@ -399,8 +404,8 @@ void Op::init(const std::string& mstr, int base, size_t maxBitSize, Mode mode)
#if CYBOZU_OS_BIT == 64 #if CYBOZU_OS_BIT == 64
case 576: SET_OP(576); break; case 576: SET_OP(576); break;
#else #else
case 160: SET_OP(160); SET_OP_DBL_LLVM(320); break; case 160: SET_OP(160); SET_OP_DBL_LLVM(160, 320); break;
case 224: SET_OP(224); SET_OP_DBL_LLVM(448); break; case 224: SET_OP(224); SET_OP_DBL_LLVM(224, 448); break;
case 288: SET_OP(288); break; case 288: SET_OP(288); break;
case 352: SET_OP(352); break; case 352: SET_OP(352); break;
case 416: SET_OP(416); break; case 416: SET_OP(416); break;

@ -105,7 +105,8 @@ void testFpDbl()
void test(const char *p) void test(const char *p)
{ {
printf("prime=%s\n", p); printf("prime=%s\n", p);
Fp::setModulo(p); // Fp::setModulo(p);
Fp::setModulo(p, 0, mcl::fp::FP_LLVM); // QQQ
testFp2(); testFp2();
if (Fp::getBitSize() <= 256) { if (Fp::getBitSize() <= 256) {
testFpDbl(); testFpDbl();

Loading…
Cancel
Save