|
|
|
@ -145,152 +145,62 @@ struct OpeFunc { |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
#define SET_OP_LLVM(n) \ |
|
|
|
|
op.addG = mcl_fp_add ## n ##S; \
|
|
|
|
|
op.subG = mcl_fp_sub ## n ##S; \
|
|
|
|
|
op.mulPreG = mcl_fp_mulPre ## n; |
|
|
|
|
#else |
|
|
|
|
#define SET_OP_LLVM(n) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#define SET_OP(n) \ |
|
|
|
|
op.N = n / UnitBitN; \
|
|
|
|
|
op.isZero = OpeFunc<n>::isZeroC; \
|
|
|
|
|
op.clear = OpeFunc<n>::clearC; \
|
|
|
|
|
op.copy = OpeFunc<n>::copyC; \
|
|
|
|
|
op.negG = OpeFunc<n>::negC; \
|
|
|
|
|
op.invG = OpeFunc<n>::invC; \
|
|
|
|
|
op.addG = OpeFunc<n>::addC; \
|
|
|
|
|
op.subG = OpeFunc<n>::subC; \
|
|
|
|
|
op.mulPreG = OpeFunc<n>::mulPreC; \
|
|
|
|
|
op.modG = OpeFunc<n>::modC; \
|
|
|
|
|
SET_OP_LLVM(n) |
|
|
|
|
|
|
|
|
|
void initOpByLLVM(Op& op, const Unit* /*p*/, size_t bitLen) |
|
|
|
|
{ |
|
|
|
|
assert(sizeof(mp_limb_t) == sizeof(Unit)); |
|
|
|
|
const size_t UnitBitN = sizeof(Unit) * 8; |
|
|
|
|
|
|
|
|
|
if (bitLen <= 128) { |
|
|
|
|
op.N = 128 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<128>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<128>::clearC; |
|
|
|
|
op.copy = OpeFunc<128>::copyC; |
|
|
|
|
op.negG = OpeFunc<128>::negC; |
|
|
|
|
op.invG = OpeFunc<128>::invC; |
|
|
|
|
op.addG = OpeFunc<128>::addC; |
|
|
|
|
op.subG = OpeFunc<128>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<128>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<128>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add128S; |
|
|
|
|
op.subG = mcl_fp_sub128S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre128; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(128) |
|
|
|
|
} else |
|
|
|
|
#if CYBOZU_OS_BIT == 32 |
|
|
|
|
if (bitLen <= 160) { |
|
|
|
|
op.N = 160 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<160>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<160>::clearC; |
|
|
|
|
op.copy = OpeFunc<160>::copyC; |
|
|
|
|
op.negG = OpeFunc<160>::negC; |
|
|
|
|
op.invG = OpeFunc<160>::invC; |
|
|
|
|
op.addG = OpeFunc<160>::addC; |
|
|
|
|
op.subG = OpeFunc<160>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<160>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<160>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add160S; |
|
|
|
|
op.subG = mcl_fp_sub160S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre160; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(160) |
|
|
|
|
} else |
|
|
|
|
#endif |
|
|
|
|
if (bitLen <= 192) { |
|
|
|
|
op.N = 192 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<192>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<192>::clearC; |
|
|
|
|
op.copy = OpeFunc<192>::copyC; |
|
|
|
|
op.negG = OpeFunc<192>::negC; |
|
|
|
|
op.invG = OpeFunc<192>::invC; |
|
|
|
|
op.addG = OpeFunc<192>::addC; |
|
|
|
|
op.subG = OpeFunc<192>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<192>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<192>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add192S; |
|
|
|
|
op.subG = mcl_fp_sub192S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre192; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(192) |
|
|
|
|
} else |
|
|
|
|
#if CYBOZU_OS_BIT == 32 |
|
|
|
|
if (bitLen <= 224) { |
|
|
|
|
op.N = 224 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<224>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<224>::clearC; |
|
|
|
|
op.copy = OpeFunc<224>::copyC; |
|
|
|
|
op.negG = OpeFunc<224>::negC; |
|
|
|
|
op.invG = OpeFunc<224>::invC; |
|
|
|
|
op.addG = OpeFunc<224>::addC; |
|
|
|
|
op.subG = OpeFunc<224>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<224>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<224>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add224S; |
|
|
|
|
op.subG = mcl_fp_sub224S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre224; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(224) |
|
|
|
|
} else |
|
|
|
|
#endif |
|
|
|
|
if (bitLen <= 256) { |
|
|
|
|
op.N = 256 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<256>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<256>::clearC; |
|
|
|
|
op.copy = OpeFunc<256>::copyC; |
|
|
|
|
op.negG = OpeFunc<256>::negC; |
|
|
|
|
op.invG = OpeFunc<256>::invC; |
|
|
|
|
op.addG = OpeFunc<256>::addC; |
|
|
|
|
op.subG = OpeFunc<256>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<256>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<256>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add256S; |
|
|
|
|
op.subG = mcl_fp_sub256S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre256; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(256) |
|
|
|
|
} else |
|
|
|
|
if (bitLen <= 384) { |
|
|
|
|
op.N = 384 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<384>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<384>::clearC; |
|
|
|
|
op.copy = OpeFunc<384>::copyC; |
|
|
|
|
op.negG = OpeFunc<384>::negC; |
|
|
|
|
op.invG = OpeFunc<384>::invC; |
|
|
|
|
op.addG = OpeFunc<384>::addC; |
|
|
|
|
op.subG = OpeFunc<384>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<384>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<384>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add384S; |
|
|
|
|
op.subG = mcl_fp_sub384S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre384; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(384) |
|
|
|
|
} else |
|
|
|
|
#if CYBOZU_OS_BIT == 64 |
|
|
|
|
if (bitLen <= 576) { |
|
|
|
|
op.N = 576 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<576>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<576>::clearC; |
|
|
|
|
op.copy = OpeFunc<576>::copyC; |
|
|
|
|
op.negG = OpeFunc<576>::negC; |
|
|
|
|
op.invG = OpeFunc<576>::invC; |
|
|
|
|
op.addG = OpeFunc<576>::addC; |
|
|
|
|
op.subG = OpeFunc<576>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<576>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<576>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add576S; |
|
|
|
|
op.subG = mcl_fp_sub576S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre576; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(576) |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
if (bitLen <= 544) { |
|
|
|
|
op.N = 544 / UnitBitN; |
|
|
|
|
op.isZero = OpeFunc<544>::isZeroC; |
|
|
|
|
op.clear = OpeFunc<544>::clearC; |
|
|
|
|
op.copy = OpeFunc<544>::copyC; |
|
|
|
|
op.negG = OpeFunc<544>::negC; |
|
|
|
|
op.invG = OpeFunc<544>::invC; |
|
|
|
|
op.addG = OpeFunc<544>::addC; |
|
|
|
|
op.subG = OpeFunc<544>::subC; |
|
|
|
|
op.mulPreG = OpeFunc<544>::mulPreC; |
|
|
|
|
op.modG = OpeFunc<544>::modC; |
|
|
|
|
#ifdef MCL_USE_LLVM |
|
|
|
|
op.addG = mcl_fp_add544S; |
|
|
|
|
op.subG = mcl_fp_sub544S; |
|
|
|
|
op.mulPreG = mcl_fp_mulPre544; |
|
|
|
|
#endif |
|
|
|
|
SET_OP(544) |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|