Skip to content

Commit 05d3938

Browse files
committed
SIMD Basic: refactor get low/high half elements for ModMul
1 parent d35c4d3 commit 05d3938

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/simd_basic.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ inline VecType CardMinusOne<uint32_t>(uint32_t q)
6262
return (q == F3) ? F3_MINUS_ONE_U32 : F4_MINUS_ONE_U32;
6363
}
6464

65+
template <typename T>
66+
inline VecType GetLowHalf(VecType x, T q)
67+
{
68+
return (q == F3) ? BLEND8(ZERO, x, MASK8_LO) : BLEND16(ZERO, x, 0x55);
69+
}
70+
71+
template <typename T>
72+
inline VecType GetHighHalf(VecType x, T q)
73+
{
74+
return (q == F3) ? BLEND8(ZERO, SHIFTR(x, 1), MASK8_LO)
75+
: BLEND16(ZERO, SHIFTR(x, 2), 0x55);
76+
}
77+
6578
/* ================= Basic Operations ================= */
6679

6780
/**
@@ -123,10 +136,8 @@ template <typename T>
123136
inline VecType ModMul(VecType x, VecType y, T q)
124137
{
125138
const VecType res = Mul<T>(x, y);
126-
const VecType lo =
127-
(q == F3) ? BLEND8(ZERO, res, MASK8_LO) : BLEND16(ZERO, res, 0x55);
128-
const VecType hi = (q == F3) ? BLEND8(ZERO, SHIFTR(res, 1), MASK8_LO)
129-
: BLEND16(ZERO, SHIFTR(res, 2), 0x55);
139+
const VecType lo = GetLowHalf(res, q);
140+
const VecType hi = GetHighHalf(res, q);
130141
return ModSub(lo, hi, q);
131142
}
132143

0 commit comments

Comments
 (0)