From ead99eb002ea98eeb424f134431d50f5005a3ed6 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 10 May 2021 16:38:34 +0900 Subject: [PATCH] avoid cast of Fp::add --- include/mcl/fp.hpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index f41d4f8..f33e905 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -146,8 +146,9 @@ public: ioMode_ = 0; isETHserialization_ = false; #ifdef MCL_XBYAK_DIRECT_CALL - add = fp::func_ptr_cast(op_.fp_addA_); - if (add == 0) add = addC; + if (op_.fp_addA_ == 0) { + op_.fp_addA_ = addA; + } sub = fp::func_ptr_cast(op_.fp_subA_); if (sub == 0) sub = subC; neg = fp::func_ptr_cast(op_.fp_negA_); @@ -518,9 +519,21 @@ public: } setArray(pb, gmp::getUnit(x), gmp::getUnitSize(x)); } + static void add(FpT& z, const FpT& x, const FpT& y) + { +#ifdef MCL_XBYAK_DIRECT_CALL + op_.fp_addA_(z.v_, x.v_, y.v_); +#else + op_.fp_add(z.v_, x.v_, y.v_, op_.p); +#endif + } +#ifdef MCL_XBYAK_DIRECT_CALL + static inline void addA(Unit *z, const Unit *x, const Unit *y) + { + op_.fp_add(z, x, y, op_.p); + } +#endif #ifdef MCL_XBYAK_DIRECT_CALL - static void (*add)(FpT& z, const FpT& x, const FpT& y); - static inline void addC(FpT& z, const FpT& x, const FpT& y) { op_.fp_add(z.v_, x.v_, y.v_, op_.p); } static void (*sub)(FpT& z, const FpT& x, const FpT& y); static inline void subC(FpT& z, const FpT& x, const FpT& y) { op_.fp_sub(z.v_, x.v_, y.v_, op_.p); } static void (*neg)(FpT& y, const FpT& x); @@ -534,7 +547,6 @@ public: static void (*mul9)(FpT& y, const FpT& x); static inline void mul9C(FpT& y, const FpT& x) { mulSmall(y, x, 9); } #else - static inline void add(FpT& z, const FpT& x, const FpT& y) { op_.fp_add(z.v_, x.v_, y.v_, op_.p); } static inline void sub(FpT& z, const FpT& x, const FpT& y) { op_.fp_sub(z.v_, x.v_, y.v_, op_.p); } static inline void neg(FpT& y, const FpT& x) { op_.fp_neg(y.v_, x.v_, op_.p); } static inline void mul(FpT& z, const FpT& x, const FpT& y) { op_.fp_mul(z.v_, x.v_, y.v_, op_.p); } @@ -789,7 +801,6 @@ template FpT FpT template int FpT::ioMode_ = IoAuto; template bool FpT::isETHserialization_ = false; #ifdef MCL_XBYAK_DIRECT_CALL -template void (*FpT::add)(FpT& z, const FpT& x, const FpT& y); template void (*FpT::sub)(FpT& z, const FpT& x, const FpT& y); template void (*FpT::neg)(FpT& y, const FpT& x); template void (*FpT::mul)(FpT& z, const FpT& x, const FpT& y);