Skip to content

Commit

Permalink
SIMD Basic: refactor get low/high half elements for ModMul
Browse files Browse the repository at this point in the history
  • Loading branch information
lamphamsy committed Oct 30, 2018
1 parent 7cde4de commit 160a031
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/simd_basic.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ inline VecType CardMinusOne<uint32_t>(uint32_t q)
return (q == F3) ? F3_MINUS_ONE_U32 : F4_MINUS_ONE_U32;
}

template <typename T>
inline VecType GetLowHalf(VecType x, T q)
{
return (q == F3) ? BLEND8(ZERO, x, MASK8_LO) : BLEND16(ZERO, x, 0x55);
}

template <typename T>
inline VecType GetHighHalf(VecType x, T q)
{
return (q == F3) ? BLEND8(ZERO, SHIFTR(x, 1), MASK8_LO)
: BLEND16(ZERO, SHIFTR(x, 2), 0x55);
}

/* ================= Basic Operations ================= */

/**
Expand Down Expand Up @@ -123,10 +136,8 @@ template <typename T>
inline VecType ModMul(VecType x, VecType y, T q)
{
const VecType res = Mul<T>(x, y);
const VecType lo =
(q == F3) ? BLEND8(ZERO, res, MASK8_LO) : BLEND16(ZERO, res, 0x55);
const VecType hi = (q == F3) ? BLEND8(ZERO, SHIFTR(res, 1), MASK8_LO)
: BLEND16(ZERO, SHIFTR(res, 2), 0x55);
const VecType lo = GetLowHalf(res, q);
const VecType hi = GetHighHalf(res, q);
return ModSub(lo, hi, q);
}

Expand Down

0 comments on commit 160a031

Please sign in to comment.