rename isNIST_P192 to primeMode

dev
MITSUNARI Shigeo 9 years ago
parent 2bdbeda2be
commit 67077bace9
  1. 11
      include/mcl/op.hpp
  2. 11
      src/fp.cpp
  3. 8
      src/fp_generator.hpp

@ -51,6 +51,11 @@ enum Mode {
FP_XBYAK
};
enum PrimeMode {
PM_GENERIC = 0,
PM_NICT_P192
};
static inline const char *ModeToStr(Mode mode)
{
switch (mode) {
@ -99,7 +104,7 @@ struct Op {
bool isFullBit; // true if bitSize % uniSize == 0
bool isMont; // true if use Montgomery
bool isNIST_P192; // true if p is NIST_P192
PrimeMode primeMode;
bool isFastMod; // true if modulo is fast
/*
same fp_add, fp_sub if isFullBit
@ -160,9 +165,9 @@ struct Op {
, fp_mulIPre(0)
, fpN1_modP(0)
, fp_mulI(0)
, isFullBit(true)
, isFullBit(false)
, isMont(false)
, isNIST_P192(false)
, primeMode(PM_GENERIC)
, isFastMod(false)
, fp_addNC(0), fp_subNC(0)
, fp_preInv(0)

@ -410,10 +410,13 @@ void Op::init(const std::string& mstr, int base, size_t maxBitSize, Mode mode)
isFullBit = (bitSize % UnitBitSize) == 0;
const size_t roundBit = (bitSize + UnitBitSize - 1) & ~(UnitBitSize - 1);
primeMode = PM_GENERIC;
#if defined(MCL_USE_LLVM) || defined(MCL_USE_XBYAK)
isNIST_P192 = (mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK)
&& mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff");
if (isNIST_P192) {
if ((mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK)
&& mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff")) {
primeMode = PM_NICT_P192;
}
if (primeMode == PM_NICT_P192) {
isMont = false;
isFastMod = true;
}
@ -444,7 +447,7 @@ void Op::init(const std::string& mstr, int base, size_t maxBitSize, Mode mode)
throw cybozu::Exception("Op::init:not:support") << mstr;
}
#ifdef MCL_USE_LLVM
if (isNIST_P192) {
if (primeMode == PM_NICT_P192) {
fp_mul = &mcl_fp_mul_NIST_P192;
fp_sqr = &mcl_fp_sqr_NIST_P192;
fpDbl_mod = &mcl_fpDbl_mod_NIST_P192;

@ -227,7 +227,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
align(16);
shr1_ = getCurr<void2op>();
gen_shr1();
if (!op.isNIST_P192 && op.N <= 4) { // support general op.N but not fast for op.N > 4
if (op.primeMode != PM_NICT_P192 && op.N <= 4) { // support general op.N but not fast for op.N > 4
align(16);
op.fp_preInv = getCurr<int2u>();
gen_preInv();
@ -600,7 +600,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
}
void gen_mul()
{
if (op_->isNIST_P192) {
if (op_->primeMode == PM_NICT_P192) {
StackFrame sf(this, 3, 10 | UseRDX, 8 * 6);
mulPre3(rsp, sf.p[1], sf.p[2], sf.t);
fpDbl_mod_NIST_P192(sf.p[0], rsp, sf.t);
@ -888,7 +888,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
}
void gen_fpDbl_mod(const mcl::fp::Op& op)
{
if (op.isNIST_P192) {
if (op.primeMode == PM_NICT_P192) {
StackFrame sf(this, 2, 6 | UseRDX);
fpDbl_mod_NIST_P192(sf.p[0], sf.p[1], sf.t);
return;
@ -909,7 +909,7 @@ struct FpGenerator : Xbyak::CodeGenerator {
}
void gen_sqr()
{
if (op_->isNIST_P192) {
if (op_->primeMode == PM_NICT_P192) {
StackFrame sf(this, 2, 10 | UseRDX | UseRCX, 8 * 6);
sqrPre3(rsp, sf.p[1], sf.t);
fpDbl_mod_NIST_P192(sf.p[0], rsp, sf.t);

Loading…
Cancel
Save