Skip to content

Commit 1ec73e7

Browse files
fboemerjoserochh
authored andcommitted
Signing on behalf of fboemer
1 parent accf7a5 commit 1ec73e7

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

hexl/ntt/inv-ntt-avx512.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,18 @@ template void InverseTransformFromBitReverseAVX512<NTT::s_default_shift_bits>(
6464
template <int BitShift, bool InputLessThanMod>
6565
inline void InvButterfly(__m512i* X, __m512i* Y, __m512i W, __m512i W_precon,
6666
__m512i neg_modulus, __m512i twice_modulus) {
67+
// Compute T first to allow in-place update of X
6768
__m512i Y_minus_2q = _mm512_sub_epi64(*Y, twice_modulus);
6869
__m512i T = _mm512_sub_epi64(*X, Y_minus_2q);
6970

7071
if (InputLessThanMod) {
7172
// No need for modulus reduction, since inputs are in [0, q)
7273
*X = _mm512_add_epi64(*X, *Y);
7374
} else {
75+
// Algorithm 3 computes (X >= 2q) ? (X - 2q) : X
76+
// We instead compute (X - 2q >= 0) ? (X - 2q) : X
77+
// This allows us to use the faster _mm512_movepi64_mask rather than
78+
// _mm512_cmp_epu64_mask to create the mask.
7479
*X = _mm512_add_epi64(*X, Y_minus_2q);
7580
__mmask8 sign_bits = _mm512_movepi64_mask(*X);
7681
*X = _mm512_mask_add_epi64(*X, sign_bits, *X, twice_modulus);

0 commit comments

Comments
 (0)