DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH 10/11] hash: remove extra store-load when performing RSS
Date: Tue,  1 Dec 2026 15:16:22 +0000	[thread overview]
Message-ID: <20261201151623.2240031-11-bruce.richardson@intel.com> (raw)
In-Reply-To: <20261201151623.2240031-1-bruce.richardson@intel.com>

Because of the need to handle cases where the L4 is not contiguous with
the L3 addresses, we have to build up a tuple locally before calling the
hash calculation. This building the tuple, even using AVX-512, still
leads to an extra store of that tuple before loading it back inside the
calculation loop. We can eliminate this unnecessary store and load back
by making a simplified copy of the core calculation function that only
handles tuples of up to 64-bytes in size and that takes those as input
via an already populated AVX-512 register.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/hash/thash_gfni_avx512.c | 94 ++++++++++++++++++++++++++++++------
 1 file changed, 79 insertions(+), 15 deletions(-)

diff --git a/lib/hash/thash_gfni_avx512.c b/lib/hash/thash_gfni_avx512.c
index e738812807..8c8384919a 100644
--- a/lib/hash/thash_gfni_avx512.c
+++ b/lib/hash/thash_gfni_avx512.c
@@ -2,7 +2,6 @@
  * Copyright(c) 2026 Intel Corporation
  */
 
-#include <stdalign.h>
 #include <string.h>
 
 #include <rte_thash_x86_gfni.h>
@@ -13,56 +12,121 @@
 #error "GFNI and required AVX512 extensions must be enabled to build this file"
 #endif
 
+static inline uint32_t
+thash_gfni_avx512_hash(const uint64_t *mtrx, __m512i tuple_bytes, int len)
+{
+	__m512i permute_idx = _mm512_set_epi32(0x07060504, 0x07060504,
+		0x06050403, 0x06050403,
+		0x05040302, 0x05040302,
+		0x04030201, 0x04030201,
+		0x03020100, 0x03020100,
+		0x020100FF, 0x020100FF,
+		0x0100FFFE, 0x0100FFFE,
+		0x00FFFEFD, 0x00FFFEFD);
+	const __m512i rewind_idx = _mm512_set_epi32(0, 0, 0, 0,
+		0, 0, 0, 0,
+		0, 0, 0x0000003B, 0x0000003B,
+		0x00003B3A, 0x00003B3A,
+		0x003B3A39, 0x003B3A39);
+	const __m512i shift_8 = _mm512_set1_epi8(8);
+	__m512i xor_acc = _mm512_setzero_si512();
+	__m512i perm_bytes = _mm512_setzero_si512();
+	__mmask64 permute_mask = RTE_THASH_FIRST_ITER_MSK;
+	const int full_len = (len + 3) / 8;
+	uint32_t val, val_zero;
+
+	for (int i = 0; i < full_len; i++, mtrx += 8) {
+		perm_bytes = _mm512_mask_permutexvar_epi8(perm_bytes,
+			permute_mask, permute_idx, tuple_bytes);
+		const __m512i matrixes = _mm512_maskz_loadu_epi64(UINT8_MAX, mtrx);
+		const __m512i vals = _mm512_gf2p8affine_epi64_epi8(perm_bytes, matrixes, 0);
+
+		xor_acc = _mm512_xor_si512(xor_acc, vals);
+		permute_idx = _mm512_add_epi8(permute_idx, shift_8);
+		permute_mask = RTE_THASH_PERM_MSK;
+	}
+
+	const int rest_len = (len + 3) % 8;
+	if (rest_len != 0) {
+		const __mmask8 mtrx_mask = (1U << rest_len) - 1;
+		const __m512i matrixes = _mm512_maskz_loadu_epi64(mtrx_mask, mtrx);
+
+		if (full_len == 8)
+			perm_bytes = _mm512_maskz_permutexvar_epi8(RTE_THASH_REWIND_MSK,
+				rewind_idx, perm_bytes);
+		else
+			perm_bytes = _mm512_mask_permutexvar_epi8(perm_bytes,
+				permute_mask, permute_idx, tuple_bytes);
+
+		const __m512i vals = _mm512_gf2p8affine_epi64_epi8(perm_bytes, matrixes, 0);
+		xor_acc = _mm512_xor_si512(xor_acc, vals);
+	}
+
+	__rte_thash_xor_reduce(xor_acc, &val, &val_zero);
+	return val;
+}
+
 uint32_t
 thash_gfni_avx512_8B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
 {
-	return rte_thash_gfni(ctx->data.matrices, tuple, 8);
+	uint64_t value;
+
+	memcpy(&value, tuple, sizeof(value));
+	const __m512i tuple_bytes = _mm512_maskz_set1_epi64(1, value);
+
+	return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 8);
 }
 
 uint32_t
 thash_gfni_avx512_12B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
 {
-	return rte_thash_gfni(ctx->data.matrices, tuple, 12);
+	const __m512i tuple_bytes = _mm512_maskz_loadu_epi8(UINT64_C(0xfff), tuple);
+
+	return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 12);
 }
 
 uint32_t
 thash_gfni_avx512_32B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
 {
-	return rte_thash_gfni(ctx->data.matrices, tuple, 32);
+	const __m512i tuple_bytes = _mm512_zextsi256_si512(
+		_mm256_loadu_si256((const __m256i *)tuple));
+
+	return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 32);
 }
 
 uint32_t
 thash_gfni_avx512_36B(const struct rte_thash_rss_ctx *ctx, const uint8_t *tuple)
 {
-	return rte_thash_gfni(ctx->data.matrices, tuple, 36);
+	const __m512i tuple_bytes = _mm512_maskz_loadu_epi8(UINT64_C(0xfffffffff), tuple);
+
+	return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 36);
 }
 
 uint32_t
 thash_gfni_avx512_12B_split(const struct rte_thash_rss_ctx *ctx,
 	const uint8_t *addresses, const uint8_t *ports)
 {
-	alignas(64) uint8_t tuple[64];
 	uint32_t ports_value;
+	uint64_t address_value;
 
 	memcpy(&ports_value, ports, sizeof(ports_value));
-	__m512i value = _mm512_maskz_loadu_epi8(UINT64_C(0xff), addresses);
-	value = _mm512_mask_set1_epi32(value, UINT16_C(1) << 2, ports_value);
-	_mm512_store_si512(tuple, value);
+	memcpy(&address_value, addresses, sizeof(address_value));
+	__m512i tuple_bytes = _mm512_maskz_set1_epi64(1, address_value);
+	tuple_bytes = _mm512_mask_set1_epi32(tuple_bytes, UINT16_C(1) << 2, ports_value);
 
-	return rte_thash_gfni(ctx->data.matrices, tuple, 12);
+	return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 12);
 }
 
 uint32_t
 thash_gfni_avx512_36B_split(const struct rte_thash_rss_ctx *ctx,
 	const uint8_t *addresses, const uint8_t *ports)
 {
-	alignas(64) uint8_t tuple[64];
 	uint32_t ports_value;
 
 	memcpy(&ports_value, ports, sizeof(ports_value));
-	__m512i value = _mm512_maskz_loadu_epi8(UINT64_C(0xffffffff), addresses);
-	value = _mm512_mask_set1_epi32(value, UINT16_C(1) << 8, ports_value);
-	_mm512_store_si512(tuple, value);
+	__m512i tuple_bytes = _mm512_zextsi256_si512(
+		_mm256_loadu_si256((const __m256i *)addresses));
+	tuple_bytes = _mm512_mask_set1_epi32(tuple_bytes, UINT16_C(1) << 8, ports_value);
 
-	return rte_thash_gfni(ctx->data.matrices, tuple, 36);
+	return thash_gfni_avx512_hash(ctx->data.matrices, tuple_bytes, 36);
 }
-- 
2.55.0


  parent reply	other threads:[~2026-12-01 15:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 15:16 [PATCH 00/11] Add optimized path selection for thash Bruce Richardson
2026-12-01 15:16 ` [PATCH 01/11] hash: improve build-time instruction set checks " Bruce Richardson
2026-12-01 15:16 ` [PATCH 02/11] test/thash_perf: test gfni thash when platform supports Bruce Richardson
2026-12-01 15:16 ` [PATCH 03/11] hash: create library internal header file for thash Bruce Richardson
2026-12-01 15:16 ` [PATCH 04/11] hash: add functions for GFNI RSS hash calculations Bruce Richardson
2026-12-01 15:16 ` [PATCH 05/11] hash: add fixed-size scalar " Bruce Richardson
2026-12-01 15:16 ` [PATCH 06/11] hash: add thash context struct for runtime path selection Bruce Richardson
2026-12-01 15:16 ` [PATCH 07/11] hash: implement IPv4 and IPv6 RSS hashing in SW Bruce Richardson
2026-12-01 15:16 ` [PATCH 08/11] hash: add explicit handling for RSS with split L3/L4 data Bruce Richardson
2026-12-01 15:16 ` [PATCH 09/11] test/thash: add perf tests for new RSS functions Bruce Richardson
2026-12-01 15:16 ` Bruce Richardson [this message]
2026-12-01 15:16 ` [PATCH 11/11] hash: add AVX2 RSS hash functions Bruce Richardson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201151623.2240031-11-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox