From 1a70a051c1ec3a718db3c50bb0338e70afbd7022 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sun, 6 Mar 2016 17:18:34 +0900 Subject: [PATCH] refactor --- include/mcl/fp_generator.hpp | 37 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/include/mcl/fp_generator.hpp b/include/mcl/fp_generator.hpp index cfbed1a..65f89e8 100644 --- a/include/mcl/fp_generator.hpp +++ b/include/mcl/fp_generator.hpp @@ -162,10 +162,7 @@ struct FpGenerator : Xbyak::CodeGenerator { void3u mul_; uint3opI mulI_; void *montRedRaw_; - void2op montRed_; - void2op sqr_; void2op shr1_; - int2op preInv_; FpGenerator() : CodeGenerator(4096 * 8) , p_(0) @@ -175,9 +172,7 @@ struct FpGenerator : Xbyak::CodeGenerator { , mul_(0) , mulI_(0) , montRedRaw_(0) - , montRed_(0) , shr1_(0) - , preInv_(0) { useMulx_ = cpu_.has(Xbyak::util::Cpu::tBMI2); } @@ -223,26 +218,20 @@ struct FpGenerator : Xbyak::CodeGenerator { op.fp_mul = mul_; gen_mul(); align(16); - montRed_ = getCurr(); - if (!gen_montRed()) { - montRed_ = 0; - } - align(16); - sqr_ = getCurr(); + op.fp_sqr = getCurr(); gen_sqr(); align(16); shr1_ = getCurr(); gen_shr1(); - preInv_ = getCurr(); - gen_preInv(); - - op.fp_sqr = Xbyak::CastTo(sqr_); - - if (op.N <= 4) { - if (montRed_) { - op.fp_mod = Xbyak::CastTo(montRed_); - } - op.fp_preInv = Xbyak::CastTo(preInv_); + if (op.N == 3 || op.N == 4) { + align(16); + op.fp_mod = getCurr(); + gen_montRed(); + } + if (op.N <= 4) { // support general op.N but not fast + align(16); + op.fp_preInv = getCurr(); + gen_preInv(); } } void gen_addSubNC(bool isAdd, int n) @@ -791,16 +780,14 @@ struct FpGenerator : Xbyak::CodeGenerator { movq(z, xm0); store_mr(z, Pack(t10, t9, t8, t4)); } - bool gen_montRed() + void gen_montRed() { + assert(pn_ == 3 || pn_ == 4); if (pn_ == 3) { gen_montRed3(); - return true; } else if (pn_ == 4) { gen_montRed4(); - return true; } - return false; } void gen_sqr() {