fix crash on x64-CPU without AVX

pull/2/head
MITSUNARI Shigeo 6 years ago
parent f1f607d5e5
commit 6ef8f3db38
  1. 4
      readme.md
  2. 4
      src/fp.cpp
  3. 5
      src/fp_generator.hpp

@ -403,6 +403,10 @@ This library contains some part of the followings software licensed by BSD-3-Cla
* [_Skew Frobenius Map and Efficient Scalar Multiplication for Pairing–Based Cryptography_](https://www.researchgate.net/publication/221282560_Skew_Frobenius_Map_and_Efficient_Scalar_Multiplication_for_Pairing-Based_Cryptography),
Y. Sakemi, Y. Nogami, K. Okeya, Y. Morikawa, CANS 2008.
# History
* 2019/Jan/31 fix crash on x64-CPU without AVX
# Author
光成滋生 MITSUNARI Shigeo(herumi@nifty.com)

@ -318,9 +318,9 @@ static bool initForMont(Op& op, const Unit *p, Mode mode)
if (mode != FP_XBYAK) return true;
#ifdef MCL_USE_XBYAK
if (op.fg == 0) op.fg = Op::createFpGenerator();
op.fg->init(op);
bool useXbyak = op.fg->init(op);
if (op.isMont && N <= 4) {
if (useXbyak && op.isMont && N <= 4) {
op.fp_invOp = &invOpForMontC;
initInvTbl(op);
}

@ -307,19 +307,20 @@ struct FpGenerator : Xbyak::CodeGenerator {
useMulx_ = cpu_.has(Xbyak::util::Cpu::tBMI2);
useAdx_ = cpu_.has(Xbyak::util::Cpu::tADX);
}
void init(Op& op)
bool init(Op& op)
{
if (!cpu_.has(Xbyak::util::Cpu::tAVX)) return false;
reset(); // reset jit code for reuse
setProtectModeRW(); // read/write memory
init_inner(op);
// printf("code size=%d\n", (int)getSize());
setProtectModeRE(); // set read/exec memory
return true;
}
private:
void init_inner(Op& op)
{
op_ = &op;
if (!cpu_.has(Xbyak::util::Cpu::tAVX)) return;
L(pL_);
p_ = reinterpret_cast<const uint64_t*>(getCurr());
for (size_t i = 0; i < op.N; i++) {

Loading…
Cancel
Save