aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2016-11-21 14:42:54 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2016-11-21 14:42:54 +0800
commite8f51a130400d57bd4e8c5105603667fde9d29d9 (patch)
treeed8ad535ef4d54bbe3987f99499e3ca325a5f91b
parent4bc7bb18bb2b4476ba2982b82ae640611ac34b8b (diff)
downloaddexon-mcl-e8f51a130400d57bd4e8c5105603667fde9d29d9.tar.gz
dexon-mcl-e8f51a130400d57bd4e8c5105603667fde9d29d9.tar.zst
dexon-mcl-e8f51a130400d57bd4e8c5105603667fde9d29d9.zip
shortcut of mulUnit
-rw-r--r--include/mcl/fp.hpp17
-rw-r--r--include/mcl/fp_tower.hpp10
-rw-r--r--test/fp_tower_test.cpp3
3 files changed, 23 insertions, 7 deletions
diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp
index 068774f..41fc8e6 100644
--- a/include/mcl/fp.hpp
+++ b/include/mcl/fp.hpp
@@ -335,7 +335,22 @@ public:
static inline void addPre(FpT& z, const FpT& x, const FpT& y) { op_.fp_addPre(z.v_, x.v_, y.v_); }
static inline void subPre(FpT& z, const FpT& x, const FpT& y) { op_.fp_subPre(z.v_, x.v_, y.v_); }
static inline void mul(FpT& z, const FpT& x, const FpT& y) { op_.fp_mul(z.v_, x.v_, y.v_, op_.p); }
- static inline void mulUnit(FpT& z, const FpT& x, const Unit y) { op_.fp_mulUnit(z.v_, x.v_, y, op_.p); }
+ static inline void mulUnit(FpT& z, const FpT& x, const Unit y)
+ {
+ switch (y) {
+ case 0: z.clear(); return;
+ case 1: z = x; return;
+ case 2: add(z, x, x); return;
+ case 3: { FpT t; add(t, x, x); add(z, t, x); return; }
+ case 4: add(z, x, x); add(z, z, z); return;
+ case 5: { FpT t; add(t, x, x); add(t, t, t); add(z, t, x); return; }
+ case 6: { FpT t; add(t, x, x); add(t, t, x); add(z, t, t); return; }
+ case 7: { FpT t; add(t, x, x); add(t, t, t); add(t, t, t); sub(z, t, x); return; }
+ case 8: add(z, x, x); add(z, z, z); add(z, z, z); return;
+ case 9: { FpT t; add(t, x, x); add(t, t, t); add(t, t, t); add(z, t, x); return; }
+ }
+ op_.fp_mulUnit(z.v_, x.v_, y, op_.p);
+ }
static inline void inv(FpT& y, const FpT& x) { op_.fp_invOp(y.v_, x.v_, op_); }
static inline void neg(FpT& y, const FpT& x) { op_.fp_neg(y.v_, x.v_, op_.p); }
static inline void sqr(FpT& y, const FpT& x) { op_.fp_sqr(y.v_, x.v_, op_.p); }
diff --git a/include/mcl/fp_tower.hpp b/include/mcl/fp_tower.hpp
index f045f48..2edf072 100644
--- a/include/mcl/fp_tower.hpp
+++ b/include/mcl/fp_tower.hpp
@@ -61,7 +61,7 @@ template<class Fp>
class Fp2T : public fp::Operator<Fp2T<Fp> > {
typedef fp::Unit Unit;
typedef FpDblT<Fp> FpDbl;
- static Fp xi_a_;
+ static uint32_t xi_a_;
public:
typedef typename Fp::BaseFp BaseFp;
Fp a, b;
@@ -161,7 +161,7 @@ public:
Fp::add(y, aa, bb);
}
- static const Fp& getXi_a() { return xi_a_; }
+ static uint32_t getXi_a() { return xi_a_; }
static void init(uint32_t xi_a)
{
// assert(Fp::maxSize <= 256);
@@ -329,9 +329,9 @@ private:
const Fp& a = px[0];
const Fp& b = px[1];
Fp t;
- Fp::mul(t, a, xi_a_);
+ Fp::mulUnit(t, a, xi_a_);
t -= b;
- Fp::mul(py[1], b, xi_a_);
+ Fp::mulUnit(py[1], b, xi_a_);
py[1] += a;
py[0] = t;
}
@@ -418,7 +418,7 @@ struct Fp2T<Fp>::Dbl {
}
};
-template<class Fp> Fp Fp2T<Fp>::xi_a_;
+template<class Fp> uint32_t Fp2T<Fp>::xi_a_;
/*
Fp6T = Fp2[v] / (v^3 - xi)
diff --git a/test/fp_tower_test.cpp b/test/fp_tower_test.cpp
index 4b5ed2d..3e93a3a 100644
--- a/test/fp_tower_test.cpp
+++ b/test/fp_tower_test.cpp
@@ -62,7 +62,8 @@ void testFp2()
*/
z = Fp2(1, -2);
Fp2::mul_xi(z, z);
- CYBOZU_TEST_EQUAL(z, Fp2(Fp2::getXi_a() + 2, Fp2::getXi_a() * (-2) + 1));
+ Fp a = Fp2::getXi_a();
+ CYBOZU_TEST_EQUAL(z, Fp2(a + 2, a * (-2) + 1));
z = x * x;
Fp2::sqr(y, x);
CYBOZU_TEST_EQUAL(z, y);