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 85740606A32F for ; Tue, 1 Dec 2026 15:18:06 +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=BRojGyBa Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id F2BF1406BC; Tue, 1 Dec 2026 16:16:56 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.16]) by mails.dpdk.org (Postfix) with ESMTPS id 4C8654067A 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=XcDe1v2bbWfIcbk+2jEI14KtQTxreqygj/hSqTAnThE=; b=BRojGyBazsGJ80F+j5lLBMARBn2b2p/qrZM0ZNWIF94j4ZTZoFHsTmXf jjYdfwSf168MgadlYmO7BYUPj9BADsNTAAf/fdlDWfzRcWhC2lDo7s8hM xSHfg0O+eQiD9krNc9y9facQ2a6FblaakVH5rAIVjJ1HuT+XJdY83o86D cBbln5e5JQbx2S1QZ+VqKevmZWUCj/57+FIdtig75JOMy5h3ClLYzX3xK rCdA7fFqVqtSaiNJ7nB/x5r97QKY4IwWVEgAulVCrFfx8eW283iXlpfiT WSS/QlihQTBxp4BPrye0dKGa6LnDK+73Rc+PUyeonVEeu4hSJ35/wUXP/ Q==; X-CSE-ConnectionGUID: fHqC3SQ2QSatVf5T58n7NQ== X-CSE-MsgGUID: CQstjN6vQYaBjb1QPf+bTQ== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5023503" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5023503" 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: DPp+ygYhSVuIrEg6b6JOzw== X-CSE-MsgGUID: 70EvymzXSRazChOqj3mQPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13749423" Received: from silpixa00401385.ir.intel.com ([10.20.224.226]) by fmviesa001.fm.intel.com with ESMTP; 01 Dec 2026 07:16:50 -0800 From: Bruce Richardson To: dev@dpdk.org Cc: Bruce Richardson Subject: [PATCH 10/11] hash: remove extra store-load when performing RSS Date: Tue, 1 Dec 2026 15:16:22 +0000 Message-ID: <20261201151623.2240031-11-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 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 --- 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 #include #include @@ -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