reduce supporting bitSize

update-fork
MITSUNARI Shigeo 4 years ago
parent 2e39b86af5
commit 414204f508
  1. 40
      src/fp.cpp
  2. 20
      src/gen.cpp
  3. 38
      src/low_func_llvm.hpp
  4. 37
      src/proto.hpp

@ -569,38 +569,16 @@ bool Op::init(const mpz_class& _p, size_t maxBitSize, int _xi_a, Mode mode, size
}
#endif
switch (N) {
case 1: setOp<1>(*this, mode); break;
case 2: setOp<2>(*this, mode); break;
case 3: setOp<3>(*this, mode); break;
case 4: setOp<4>(*this, mode); break; // 256 if 64-bit
#if MCL_MAX_UNIT_SIZE >= 6
case 5: setOp<5>(*this, mode); break;
case 6: setOp<6>(*this, mode); break;
case 192/CYBOZU_OS_BIT: setOp<192/CYBOZU_OS_BIT>(*this, mode); break;
#if CYBOZU_OS_BIT == 32
case 224/CYBOZU_OS_BIT: setOp<224/CYBOZU_OS_BIT>(*this, mode); break;
#endif
#if MCL_MAX_UNIT_SIZE >= 8
case 7: setOp<7>(*this, mode); break;
case 8: setOp<8>(*this, mode); break;
case 256/CYBOZU_OS_BIT: setOp<256/CYBOZU_OS_BIT>(*this, mode); break;
#if MCL_MAX_BIT_SIZE >= 384
case 384/CYBOZU_OS_BIT: setOp<384/CYBOZU_OS_BIT>(*this, mode); break;
#endif
#if MCL_MAX_UNIT_SIZE >= 9
case 9: setOp<9>(*this, mode); break; // 521 if 64-bit
#endif
#if MCL_MAX_UNIT_SIZE >= 10
case 10: setOp<10>(*this, mode); break;
#endif
#if MCL_MAX_UNIT_SIZE >= 12
case 11: setOp<11>(*this, mode); break;
case 12: setOp<12>(*this, mode); break; // 768 if 64-bit
#endif
#if MCL_MAX_UNIT_SIZE >= 14
case 13: setOp<13>(*this, mode); break;
case 14: setOp<14>(*this, mode); break;
#endif
#if MCL_MAX_UNIT_SIZE >= 16
case 15: setOp<15>(*this, mode); break;
case 16: setOp<16>(*this, mode); break; // 1024 if 64-bit
#endif
#if MCL_MAX_UNIT_SIZE >= 17
case 17: setOp<17>(*this, mode); break; // 521 if 32-bit
#if MCL_MAX_BIT_SIZE >= 512
case 512/CYBOZU_OS_BIT: setOp<512/CYBOZU_OS_BIT>(*this, mode); break;
#endif
default:
return false;
@ -618,10 +596,12 @@ bool Op::init(const mpz_class& _p, size_t maxBitSize, int _xi_a, Mode mode, size
fp_sqr = &mcl_fp_sqr_NIST_P192L;
fpDbl_mod = &mcl_fpDbl_mod_NIST_P192L;
}
#if MCL_MAX_BIT_SIZE >= 521
if (primeMode == PM_NIST_P521) {
fpDbl_mod = &mcl_fpDbl_mod_NIST_P521L;
}
#endif
#endif
#if defined(MCL_USE_VINT) && MCL_SIZEOF_UNIT == 8
if (primeMode == PM_SECP256K1) {
fp_mul = &mcl::vint::mcl_fp_mul_SECP256K1;

@ -669,7 +669,7 @@ struct Code : public mcl::Generator {
Operand z(Int, bu);
Operand px(IntPtr, unit);
Operand y(Int, unit);
std::string name = "mulPv" + cybozu::itoa(bit) + "x" + cybozu::itoa(unit);
std::string name = "mulPv" + cybozu::itoa(bit) + "x" + cybozu::itoa(unit) + suf;
mulPvM[bit] = Function(name, z, px, y);
// workaround at https://github.com/herumi/mcl/pull/82
// mulPvM[bit].setPrivate();
@ -1006,6 +1006,23 @@ struct Code : public mcl::Generator {
gen_mulUU();
#else
gen_once();
#if 1
int bitTbl[] = {
192,
224,
256,
384,
512
};
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(bitTbl); i++) {
uint32_t bit = bitTbl[i];
if (unit == 64 && bit == 224) continue;
setBit(bit);
gen_mul();
gen_all();
gen_addsub();
}
#else
uint32_t end = ((maxBitSize + unit - 1) / unit);
for (uint32_t n = 1; n <= end; n++) {
setBit(n * unit);
@ -1013,6 +1030,7 @@ struct Code : public mcl::Generator {
gen_all();
gen_addsub();
}
#endif
if (unit == 64 && maxBitSize == 768) {
for (uint32_t i = maxBitSize + unit * 2; i <= maxBitSize * 2; i += unit * 2) {
setBit(i);

@ -52,41 +52,29 @@ template<>const void4u DblSub<n, tag>::f = &mcl_fpDbl_sub ## n ## suf; \
MCL_DEF_LLVM_FUNC2(n, Ltag, L)
#endif
MCL_DEF_LLVM_FUNC(1)
MCL_DEF_LLVM_FUNC(2)
MCL_DEF_LLVM_FUNC(3)
MCL_DEF_LLVM_FUNC(4)
#if MCL_MAX_UNIT_SIZE >= 6
MCL_DEF_LLVM_FUNC(5)
#if CYBOZU_OS_BIT == 32
MCL_DEF_LLVM_FUNC(6)
#endif
#if MCL_MAX_UNIT_SIZE >= 8
MCL_DEF_LLVM_FUNC(7)
MCL_DEF_LLVM_FUNC(8)
#endif
#if MCL_MAX_UNIT_SIZE >= 9
MCL_DEF_LLVM_FUNC(9)
#endif
#if MCL_MAX_UNIT_SIZE >= 10
MCL_DEF_LLVM_FUNC(10)
#endif
#if MCL_MAX_UNIT_SIZE >= 12
MCL_DEF_LLVM_FUNC(11)
MCL_DEF_LLVM_FUNC(12)
#endif
#if MCL_MAX_UNIT_SIZE >= 14
MCL_DEF_LLVM_FUNC(13)
MCL_DEF_LLVM_FUNC(14)
#endif
#if MCL_MAX_UNIT_SIZE >= 16
MCL_DEF_LLVM_FUNC(15)
#if MCL_SIZEOF_UNIT == 4
MCL_DEF_LLVM_FUNC(16)
#else
#endif
#else // 64
MCL_DEF_LLVM_FUNC(3)
MCL_DEF_LLVM_FUNC(4)
#if MCL_MAX_UNIT_SIZE >= 6
MCL_DEF_LLVM_FUNC(6)
#endif
#if MCL_MAX_UNIT_SIZE >= 17
MCL_DEF_LLVM_FUNC(17)
#if MCL_MAX_UNIT_SIZE >= 8
MCL_DEF_LLVM_FUNC(8)
#endif
#endif
} } // mcl::fp

@ -38,38 +38,29 @@ void mcl_fpDbl_mod_NIST_P521 ## suf(mcl::fp::Unit* z, const mcl::fp::Unit* xy, c
extern "C" {
MCL_FP_DEF_FUNC(1)
MCL_FP_DEF_FUNC(2)
MCL_FP_DEF_FUNC(3)
MCL_FP_DEF_FUNC(4)
#if MCL_MAX_UNIT_SIZE >= 6
MCL_FP_DEF_FUNC(5)
#if CYBOZU_OS_BIT == 32
MCL_FP_DEF_FUNC(6)
#endif
#if MCL_MAX_UNIT_SIZE >= 8
MCL_FP_DEF_FUNC(7)
MCL_FP_DEF_FUNC(8)
#endif
#if MCL_MAX_UNIT_SIZE >= 9
MCL_FP_DEF_FUNC(9)
#endif
#if MCL_MAX_UNIT_SIZE >= 10
MCL_FP_DEF_FUNC(10)
#endif
#if MCL_MAX_UNIT_SIZE >= 12
MCL_FP_DEF_FUNC(11)
MCL_FP_DEF_FUNC(12)
#endif
#if MCL_MAX_UNIT_SIZE >= 14
MCL_FP_DEF_FUNC(13)
MCL_FP_DEF_FUNC(14)
#endif
#if MCL_MAX_UNIT_SIZE >= 16
MCL_FP_DEF_FUNC(15)
MCL_FP_DEF_FUNC(16)
#endif
#if MCL_MAX_UNIT_SIZE >= 17
MCL_FP_DEF_FUNC(17)
#else // 64
MCL_FP_DEF_FUNC(3)
MCL_FP_DEF_FUNC(4)
#if MCL_MAX_UNIT_SIZE >= 6
MCL_FP_DEF_FUNC(6)
#endif
#if MCL_MAX_UNIT_SIZE >= 8
MCL_FP_DEF_FUNC(8)
#endif
#endif
MCL_FP_DEF_FUNC_SPECIAL(L)

Loading…
Cancel
Save