From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35C85606A330 for ; Tue, 1 Dec 2026 15:18:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=HKFTwIkn Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2960D40A73; Tue, 1 Dec 2026 16:16:58 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by mails.dpdk.org (Postfix) with ESMTPS id A22A540678 for ; Tue, 1 Dec 2026 16:16:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796138213; x=1827674213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QfKN+vv1zNtlNXBfkj38au1H8jUoMNxDmslGu7QADvk=; b=HKFTwIknAZWZsgzWywv/FiLIujYKfZ/SyVXUKfkb4azvlNmobVJhZfRN So2ew88N4NSzPxdlgBiEpOt3O07dX/n9bhhnptgz4RhcPzGOP2IJ/6uUp dU/C7N6yWFX8yUm24ZxrwURaTWkYv0tjMw2eod35YUoMv7ZhDUzJ/tTYz yEhWa96FYvr3g01V70Ljy4b86DdXRURL98TstTXJKpjzrE+vdKrgLcAos VWU2S3ZS556oq73gWzLsVsgeo8OHercJX+NYCku+t+Oy8YbmCVLYIhGb9 iYKzq5mKmIIeuN3Udr8Quun53uqfNxWwfTpB7muH3jOBsAtQe9gQIQG6d A==; X-CSE-ConnectionGUID: 7DTVgn+iQoytV3NQMaW2WQ== X-CSE-MsgGUID: oytNjGbxSi+TPXAnwSTW+Q== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5023504" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5023504" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by fmvoesa110.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 07:16:52 -0800 X-CSE-ConnectionGUID: dHwrX6gxRo2bNf9hJLh9eQ== X-CSE-MsgGUID: ojqllwdkSsaCRYhdGWZLFg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13749429" Received: from silpixa00401385.ir.intel.com ([10.20.224.226]) by fmviesa001.fm.intel.com with ESMTP; 01 Dec 2026 07:16:51 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Subject: [PATCH 11/11] hash: add AVX2 RSS hash functions Date: Tue, 1 Dec 2026 15:16:23 +0000 Message-ID: <20261201151623.2240031-12-bruce.richardson@intel.com> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20261201151623.2240031-1-bruce.richardson@intel.com> References: <20261201151623.2240031-1-bruce.richardson@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Archive: List-Post: List-Help: List-Subscribe: , X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 Add copies of the RSS L3/L4 hash functions using AVX2+GFNI, rather than requiring AVX-512. The AVX2 implementation body is LLM created, and then tuned with manual intervention. It is port of the AVX-512 code, rather than a newly hand-crafted implementation. Signed-off-by: Bruce Richardson --- app/test/test_thash.c | 6 +- app/test/test_thash_perf.c | 120 +++++++++++++++----------- lib/hash/meson.build | 9 ++ lib/hash/rte_thash.c | 12 +++ lib/hash/thash_gfni_avx2.c | 170 +++++++++++++++++++++++++++++++++++++ lib/hash/thash_private.h | 23 +++++ lib/hash/thash_rss.c | 19 +++++ lib/meson.build | 3 +- 8 files changed, 309 insertions(+), 53 deletions(-) create mode 100644 lib/hash/thash_gfni_avx2.c diff --git a/app/test/test_thash.c b/app/test/test_thash.c index 148213be4b..0d8fe136e5 100644 --- a/app/test/test_thash.c +++ b/app/test/test_thash.c @@ -503,7 +503,11 @@ static int test_rss_packet_hashes(void) { const uint16_t original_bitwidth = rte_vect_get_max_simd_bitwidth(); - const uint16_t bitwidths[] = { RTE_VECT_SIMD_DISABLED, RTE_VECT_SIMD_512 }; + const uint16_t bitwidths[] = { + RTE_VECT_SIMD_DISABLED, + RTE_VECT_SIMD_256, + RTE_VECT_SIMD_512, + }; bool bitwidth_changed = false; int ret = TEST_SUCCESS; diff --git a/app/test/test_thash_perf.c b/app/test/test_thash_perf.c index 44bda932c7..e3568ab8bb 100644 --- a/app/test/test_thash_perf.c +++ b/app/test/test_thash_perf.c @@ -194,35 +194,27 @@ run_thash_test(unsigned int tuple_len) (double)(tsc_diff) / (double)(ITERATIONS * BATCH_SZ), len); } -/* - * The GFNI implementation is only used when 512-bit SIMD is permitted, which - * is not the default on x86, so opt in to it where the CPU can support it. - */ -static void -enable_gfni_simd_bitwidth(void) +static bool +cpu_has_avx2_gfni(void) { #ifdef RTE_ARCH_X86 - const uint16_t cur = rte_vect_get_max_simd_bitwidth(); - - if (cur >= RTE_VECT_SIMD_512) - return; - - if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) || - !rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI) || - !rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512DQ) || - !rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL)) - return; - - const int ret = rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_512); - if (ret != 0) { - printf("WARNING: CPU supports GFNI, but max SIMD bitwidth is pinned at %u, " - "so GFNI is not benchmarked\n", - cur); - return; - } + return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 && + rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) > 0; +#else + return false; +#endif +} - printf("WARNING: CPU supports GFNI, raising max SIMD bitwidth from %u to %u to benchmark it\n", - cur, RTE_VECT_SIMD_512); +static bool +cpu_has_avx512_gfni(void) +{ +#ifdef RTE_ARCH_X86 + return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 && + rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VBMI) > 0 && + rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512DQ) > 0 && + rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512VL) > 0; +#else + return false; #endif } @@ -230,38 +222,64 @@ static int test_thash_perf(void) { const uint16_t original_bitwidth = rte_vect_get_max_simd_bitwidth(); - const bool scalar_selected = - rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_DISABLED) == 0; - struct rte_thash_rss_ctx *scalar = rte_thash_rss_ctx_create(default_rss_key, - sizeof(default_rss_key), 0); - struct rte_thash_rss_ctx *simd = NULL; - int ret; - - if (scalar_selected) - rte_vect_set_max_simd_bitwidth(original_bitwidth); - if (scalar == NULL) - return -1; - - enable_gfni_simd_bitwidth(); - if (scalar_selected && rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_512) { - simd = rte_thash_rss_ctx_create(default_rss_key, sizeof(default_rss_key), 0); - if (simd == NULL) { - rte_thash_rss_ctx_free(scalar); - return -1; - } - } + struct rte_thash_rss_ctx *contexts[3] = { NULL }; + const char *labels[3] = { + "SIMD disabled", "256-bit SIMD limit", "512-bit SIMD limit" + }; + const bool has_avx2_gfni = cpu_has_avx2_gfni(); + const bool has_avx512_gfni = cpu_has_avx512_gfni(); + const uint16_t max_bitwidth = has_avx512_gfni ? RTE_VECT_SIMD_512 : + has_avx2_gfni ? RTE_VECT_SIMD_256 : RTE_VECT_SIMD_DISABLED; + const int bitwidth_set_ret = rte_vect_set_max_simd_bitwidth(max_bitwidth); + int ret = -1; + + if (bitwidth_set_ret == 0 && max_bitwidth > original_bitwidth) + printf("WARNING: CPU supports GFNI, raising max SIMD bitwidth from %u to %u\n", + original_bitwidth, max_bitwidth); run_thash_test(IPV4_2_TUPLE_LEN); run_thash_test(IPV4_4_TUPLE_LEN); run_thash_test(IPV6_2_TUPLE_LEN); run_thash_test(IPV6_4_TUPLE_LEN); - ret = run_rss_packet_perf(scalar, scalar_selected ? "scalar" : "configured SIMD"); - if (ret == 0 && simd != NULL) - ret = run_rss_packet_perf(simd, "512-bit limit"); - rte_thash_rss_ctx_free(scalar); - rte_thash_rss_ctx_free(simd); + /* we need to set the max SIMD bitwidth in order to create different contexts for testing */ + if (bitwidth_set_ret != 0) { + printf("Skipping RSS packet hash perf test: max SIMD bitwidth is forced/locked\n"); + return TEST_SKIPPED; + } + + if (has_avx512_gfni) { + contexts[2] = rte_thash_rss_ctx_create(default_rss_key, + sizeof(default_rss_key), 0); + if (contexts[2] == NULL) + goto out; + } + if (has_avx2_gfni) { + if (rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_256) != 0) + goto out; + contexts[1] = rte_thash_rss_ctx_create(default_rss_key, + sizeof(default_rss_key), 0); + if (contexts[1] == NULL) + goto out; + } + if (rte_vect_set_max_simd_bitwidth(RTE_VECT_SIMD_DISABLED) != 0) + goto out; + contexts[0] = rte_thash_rss_ctx_create(default_rss_key, + sizeof(default_rss_key), 0); + if (contexts[0] == NULL) + goto out; + rte_vect_set_max_simd_bitwidth(original_bitwidth); + + ret = 0; + for (unsigned int i = 0; i < RTE_DIM(contexts) && ret == 0; i++) { + if (contexts[i] != NULL) + ret = run_rss_packet_perf(contexts[i], labels[i]); + } +out: + rte_vect_set_max_simd_bitwidth(original_bitwidth); + for (unsigned int i = 0; i < RTE_DIM(contexts); i++) + rte_thash_rss_ctx_free(contexts[i]); return ret; } diff --git a/lib/hash/meson.build b/lib/hash/meson.build index 72fb7efd8d..71aca563a6 100644 --- a/lib/hash/meson.build +++ b/lib/hash/meson.build @@ -32,6 +32,15 @@ deps += ['net'] deps += ['ring'] deps += ['rcu'] +if dpdk_conf.has('RTE_ARCH_X86') + thash_gfni_avx2_cflags = ['-mgfni'] + if cc.has_multi_arguments(thash_gfni_avx2_cflags) + sources_avx2 += files('thash_gfni_avx2.c') + cflags_avx2 += thash_gfni_avx2_cflags + cflags += '-DCC_THASH_GFNI_AVX2_SUPPORT' + endif +endif + if dpdk_conf.has('RTE_ARCH_X86') and cc_has_avx512 thash_gfni_cflags = ['-mgfni', '-mavx512vbmi'] if cc.has_multi_arguments(thash_gfni_cflags) diff --git a/lib/hash/rte_thash.c b/lib/hash/rte_thash.c index f544cc0d69..5322ceb368 100644 --- a/lib/hash/rte_thash.c +++ b/lib/hash/rte_thash.c @@ -86,6 +86,18 @@ thash_gfni_avx512_usable(void) #endif } +bool +thash_gfni_avx2_usable(void) +{ +#ifdef RTE_ARCH_X86 + return rte_cpu_get_flag_enabled(RTE_CPUFLAG_GFNI) > 0 && + rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX2) > 0 && + rte_vect_get_max_simd_bitwidth() >= RTE_VECT_SIMD_256; +#else + return false; +#endif +} + RTE_EXPORT_SYMBOL(rte_thash_gfni_supported) int rte_thash_gfni_supported(void) diff --git a/lib/hash/thash_gfni_avx2.c b/lib/hash/thash_gfni_avx2.c new file mode 100644 index 0000000000..23a788c24b --- /dev/null +++ b/lib/hash/thash_gfni_avx2.c @@ -0,0 +1,170 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2026 Intel Corporation + */ + +#include + +#include + +#include "thash_private.h" + +#if !defined(__AVX2__) || !defined(__GFNI__) +#error "AVX2 and GFNI must be enabled to build this file" +#endif + +/* + * Matrix k is applied to tuple bytes k - 3 .. k in the low dword of qword k % 4; + * the high dword never reaches the 32-bit result, so it is left zero. + */ +#define WIN_IDX(start, valid, i) \ + ((start) + (i) >= 0 && (start) + (i) < (valid) ? (start) + (i) : -1) +#define WIN_MASK(start, valid) _mm256_setr_epi8( \ + WIN_IDX(start, valid, 0), WIN_IDX(start, valid, 1), \ + WIN_IDX(start, valid, 2), WIN_IDX(start, valid, 3), -1, -1, -1, -1, \ + WIN_IDX(start, valid, 1), WIN_IDX(start, valid, 2), \ + WIN_IDX(start, valid, 3), WIN_IDX(start, valid, 4), -1, -1, -1, -1, \ + WIN_IDX(start, valid, 2), WIN_IDX(start, valid, 3), \ + WIN_IDX(start, valid, 4), WIN_IDX(start, valid, 5), -1, -1, -1, -1, \ + WIN_IDX(start, valid, 3), WIN_IDX(start, valid, 4), \ + WIN_IDX(start, valid, 5), WIN_IDX(start, valid, 6), -1, -1, -1, -1) + +static inline __m256i +thash_gfni_avx2_group(__m256i xor_acc, __m256i src, __m256i mask, const uint64_t *mtrx) +{ + const __m256i matrixes = _mm256_loadu_si256((const __m256i *)mtrx); + const __m256i tuple_bytes = _mm256_shuffle_epi8(src, mask); + + return _mm256_xor_si256(xor_acc, + _mm256_gf2p8affine_epi64_epi8(tuple_bytes, matrixes, 0)); +} + +static inline uint32_t +thash_gfni_avx2_reduce(__m256i xor_acc) +{ + __m128i reduced = _mm_xor_si128(_mm256_castsi256_si128(xor_acc), + _mm256_extracti128_si256(xor_acc, 1)); + + reduced = _mm_xor_si128(reduced, _mm_srli_si128(reduced, 8)); + return (uint32_t)_mm_cvtsi128_si32(reduced); +} + +/* Each 128-bit lane holds 8 bytes from first followed by 4 bytes from second. */ +static inline __m256i +thash_gfni_avx2_load_8_4(const uint8_t *first, const uint8_t *second) +{ + uint32_t second_value; + + memcpy(&second_value, second, sizeof(second_value)); + return _mm256_blend_epi32( + _mm256_broadcastq_epi64(_mm_loadl_epi64((const __m128i *)first)), + _mm256_set1_epi32((int)second_value), 0x44); +} + +static inline __m256i +thash_gfni_avx2_load_16(const uint8_t *src) +{ + return _mm256_broadcastsi128_si256(_mm_loadu_si128((const __m128i *)src)); +} + +static inline uint32_t +thash_gfni_avx2_hash_12(const uint64_t *mtrx, const uint8_t *addresses, const uint8_t *ports) +{ + const __m256i src = thash_gfni_avx2_load_8_4(addresses, ports); + __m256i xor_acc = _mm256_setzero_si256(); + + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(-3, 12), &mtrx[0]); + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(1, 12), &mtrx[4]); + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(5, 12), &mtrx[8]); + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(9, 12), &mtrx[12]); + + return thash_gfni_avx2_reduce(xor_acc); +} + +/* Matrices 0-27, covering tuple bytes 0-27 from the 32 address bytes. */ +static inline __m256i +thash_gfni_avx2_hash_32_head(const uint64_t *mtrx, const uint8_t *addresses, __m256i *src_16) +{ + const __m256i src_0 = thash_gfni_avx2_load_16(addresses); + const __m256i src_8 = thash_gfni_avx2_load_16(&addresses[8]); + __m256i xor_acc = _mm256_setzero_si256(); + + *src_16 = thash_gfni_avx2_load_16(&addresses[16]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(-3, 16), &mtrx[0]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(1, 16), &mtrx[4]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(5, 16), &mtrx[8]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_0, WIN_MASK(9, 16), &mtrx[12]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_8, WIN_MASK(5, 16), &mtrx[16]); + xor_acc = thash_gfni_avx2_group(xor_acc, *src_16, WIN_MASK(1, 16), &mtrx[20]); + return thash_gfni_avx2_group(xor_acc, *src_16, WIN_MASK(5, 16), &mtrx[24]); +} + +uint32_t +thash_gfni_avx2_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple) +{ + const uint64_t *mtrx = ctx->data.matrices; + const __m256i src = _mm256_broadcastq_epi64(_mm_loadl_epi64((const __m128i *)tuple)); + __m256i xor_acc = _mm256_setzero_si256(); + + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(-3, 8), &mtrx[0]); + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(1, 8), &mtrx[4]); + xor_acc = thash_gfni_avx2_group(xor_acc, src, WIN_MASK(5, 8), &mtrx[8]); + + return thash_gfni_avx2_reduce(xor_acc); +} + +uint32_t +thash_gfni_avx2_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple) +{ + return thash_gfni_avx2_hash_12(ctx->data.matrices, tuple, &tuple[8]); +} + +uint32_t +thash_gfni_avx2_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple) +{ + const uint64_t *mtrx = ctx->data.matrices; + __m256i src_16; + __m256i xor_acc = thash_gfni_avx2_hash_32_head(mtrx, tuple, &src_16); + + xor_acc = thash_gfni_avx2_group(xor_acc, src_16, WIN_MASK(9, 16), &mtrx[28]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_16, WIN_MASK(13, 16), &mtrx[32]); + + return thash_gfni_avx2_reduce(xor_acc); +} + +uint32_t +thash_gfni_avx2_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple) +{ + const uint64_t *mtrx = ctx->data.matrices; + const __m256i src_20 = thash_gfni_avx2_load_16(&tuple[20]); + __m256i src_16; + __m256i xor_acc = thash_gfni_avx2_hash_32_head(mtrx, tuple, &src_16); + + xor_acc = thash_gfni_avx2_group(xor_acc, src_20, WIN_MASK(5, 16), &mtrx[28]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_20, WIN_MASK(9, 16), &mtrx[32]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_20, WIN_MASK(13, 16), &mtrx[36]); + + return thash_gfni_avx2_reduce(xor_acc); +} + +uint32_t +thash_gfni_avx2_12B_split(const struct rte_thash_rss_ctx *ctx, + const uint8_t *addresses, const uint8_t *ports) +{ + return thash_gfni_avx2_hash_12(ctx->data.matrices, addresses, ports); +} + +uint32_t +thash_gfni_avx2_36B_split(const struct rte_thash_rss_ctx *ctx, + const uint8_t *addresses, const uint8_t *ports) +{ + const uint64_t *mtrx = ctx->data.matrices; + const __m256i src_24 = thash_gfni_avx2_load_8_4(&addresses[24], ports); + __m256i src_16; + __m256i xor_acc = thash_gfni_avx2_hash_32_head(mtrx, addresses, &src_16); + + xor_acc = thash_gfni_avx2_group(xor_acc, src_24, WIN_MASK(1, 12), &mtrx[28]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_24, WIN_MASK(5, 12), &mtrx[32]); + xor_acc = thash_gfni_avx2_group(xor_acc, src_24, WIN_MASK(9, 12), &mtrx[36]); + + return thash_gfni_avx2_reduce(xor_acc); +} diff --git a/lib/hash/thash_private.h b/lib/hash/thash_private.h index a7a1b0148f..322a65a2e1 100644 --- a/lib/hash/thash_private.h +++ b/lib/hash/thash_private.h @@ -59,6 +59,26 @@ uint32_t thash_gfni_avx512_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses, const uint8_t *ports); +uint32_t +thash_gfni_avx2_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple); + +uint32_t +thash_gfni_avx2_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple); + +uint32_t +thash_gfni_avx2_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple); + +uint32_t +thash_gfni_avx2_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple); + +uint32_t +thash_gfni_avx2_12B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses, + const uint8_t *ports); + +uint32_t +thash_gfni_avx2_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addresses, + const uint8_t *ports); + uint32_t thash_scalar_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple); @@ -82,4 +102,7 @@ thash_scalar_36B_split(const struct rte_thash_rss_ctx *ctx, const uint8_t *addre bool thash_gfni_avx512_usable(void); +bool +thash_gfni_avx2_usable(void); + #endif /* THASH_PRIVATE_H */ diff --git a/lib/hash/thash_rss.c b/lib/hash/thash_rss.c index 95fecd6d92..c0c76b2467 100644 --- a/lib/hash/thash_rss.c +++ b/lib/hash/thash_rss.c @@ -84,6 +84,17 @@ static const struct thash_rss_ops scalar_ops = { .hash_36_split = thash_scalar_36B_split, }; +#ifdef CC_THASH_GFNI_AVX2_SUPPORT +static const struct thash_rss_ops gfni_avx2_ops = { + .hash_8 = thash_gfni_avx2_8B, + .hash_12 = thash_gfni_avx2_12B, + .hash_32 = thash_gfni_avx2_32B, + .hash_36 = thash_gfni_avx2_36B, + .hash_12_split = thash_gfni_avx2_12B_split, + .hash_36_split = thash_gfni_avx2_36B_split, +}; +#endif + #ifdef CC_THASH_GFNI_AVX512_SUPPORT static const struct thash_rss_ops gfni_avx512_ops = { .hash_8 = thash_gfni_avx512_8B, @@ -118,6 +129,14 @@ rte_thash_rss_ctx_create(const uint8_t *key, uint32_t key_len, uint64_t flags) } #endif +#ifdef CC_THASH_GFNI_AVX2_SUPPORT + if (thash_gfni_avx2_usable()) { + ctx->ops = &gfni_avx2_ops; + rte_thash_complete_matrix(ctx->data.matrices, key, THASH_RSS_KEY_LEN); + return ctx; + } +#endif + ctx->ops = &scalar_ops; memcpy(ctx->data.key, key, THASH_RSS_KEY_LEN); rte_convert_rss_key(ctx->data.key, ctx->data.key, THASH_RSS_KEY_LEN); diff --git a/lib/meson.build b/lib/meson.build index 458951054c..84594af8a3 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -120,6 +120,7 @@ foreach l:libraries sources = [] sources_avx2 = [] sources_avx512 = [] + cflags_avx2 = [] # extra cflags for the avx2 code, e.g. extra avx2 feature flags cflags_avx512 = [] # extra cflags for the avx512 code, e.g. extra avx512 feature flags headers = [] indirect_headers = [] # public headers not directly included by apps @@ -249,7 +250,7 @@ foreach l:libraries sources_avx2, dependencies: static_deps, include_directories: includes, - c_args: [cflags, cc_avx2_flags]) + c_args: [cflags, cflags_avx2, cc_avx2_flags]) objs += avx2_lib.extract_objects(sources_avx2) endif if sources_avx512.length() > 0 and cc_has_avx512 -- 2.55.0