Skip to content

Commit

Permalink
dpcls: fix build on compilers without AVX512-VPOPCNT
Browse files Browse the repository at this point in the history
This commit adds extra checks around the AVX-512 vpopcnt instruction
enabling, ensuring that in the function where the ISA is enabled the
compiler has also indicated its support for the ISA. This is achieved
by checking the __AVX512VPOPCNTDQ__ define, which the compiler sets if
it is capable of handling the vpopcnt instruction.

If the compiler is not capable of handling vpopcnt, we fall back to
the emulated vpopcnt implementation.

Reported-by: Ian Stokes <[email protected]>
Fixes: 1e31489 ("dpcls-avx512: Enable avx512 vector popcount instruction.")
Signed-off-by: Harry van Haaren <[email protected]>
Signed-off-by: Ian Stokes <[email protected]>
  • Loading branch information
harry-van-haaren authored and istokes committed Aug 10, 2021
1 parent ccb6cc2 commit c15c3df
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/dpif-netdev-lookup-avx512-gather.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,6 @@

VLOG_DEFINE_THIS_MODULE(dpif_lookup_avx512_gather);


/* Wrapper function required to enable ISA. */
static inline __m512i
__attribute__((__target__("avx512vpopcntdq")))
_mm512_popcnt_epi64_wrapper(__m512i v_in)
{
return _mm512_popcnt_epi64(v_in);
}

static inline __m512i
_mm512_popcnt_epi64_manual(__m512i v_in)
{
Expand All @@ -85,6 +76,23 @@ _mm512_popcnt_epi64_manual(__m512i v_in)
return _mm512_sad_epu8(v_u8_pop, _mm512_setzero_si512());
}

/* Wrapper function required to enable ISA. First enable the ISA via the
* attribute target for this function, then check if the compiler actually
* #defines the ISA itself. If the ISA is not #define-ed by the compiler it
* indicates the compiler is too old or is not capable of compiling the
* requested ISA level, so fallback to the integer manual implementation.
*/
static inline __m512i
__attribute__((__target__("avx512vpopcntdq")))
_mm512_popcnt_epi64_wrapper(__m512i v_in)
{
#ifdef __AVX512VPOPCNTDQ__
return _mm512_popcnt_epi64(v_in);
#else
return _mm512_popcnt_epi64_manual(v_in);
#endif
}

static inline uint64_t
netdev_rule_matches_key(const struct dpcls_rule *rule,
const uint32_t mf_bits_total,
Expand Down

0 comments on commit c15c3df

Please sign in to comment.