[PATCH] net/crc: cleanup code in net_crc_sse.c implementation
Shreesh Adiga
16567adigashreesh at gmail.com
Fri Jun 12 04:51:35 CEST 2026
Special handling for len between 16 and 31 is not required as the
implementation correctly handles them in the main path. Given that these
cases were annotated with unlikely branch hint, it should be simpler to
have these handled in the main path itself.
We can remove the partial_bytes label as there is no jump target to it,
and replace folding code in that block with already existing inline
function to simplify and have better code reuse.
Signed-off-by: Shreesh Adiga <16567adigashreesh at gmail.com>
---
lib/net/net_crc_sse.c | 53 ++++++++++++++-----------------------------
1 file changed, 17 insertions(+), 36 deletions(-)
diff --git a/lib/net/net_crc_sse.c b/lib/net/net_crc_sse.c
index dfef8ecc59..e30f8544fc 100644
--- a/lib/net/net_crc_sse.c
+++ b/lib/net/net_crc_sse.c
@@ -182,39 +182,24 @@ crc32_eth_calc_pclmulqdq(
goto single_fold_loop;
}
- if (unlikely(data_len < 32)) {
- if (unlikely(data_len == 16)) {
- /* 16 bytes */
- fold = _mm_loadu_si128((const __m128i *)data);
- fold = _mm_xor_si128(fold, temp);
- goto reduction_128_64;
- }
+ if (unlikely(data_len < 16)) {
+ /* 0 to 15 bytes */
+ alignas(16) uint8_t buffer[16];
- if (unlikely(data_len < 16)) {
- /* 0 to 15 bytes */
- alignas(16) uint8_t buffer[16];
-
- memset(buffer, 0, sizeof(buffer));
- memcpy(buffer, data, data_len);
-
- fold = _mm_load_si128((const __m128i *)buffer);
- fold = _mm_xor_si128(fold, temp);
- if (unlikely(data_len < 4)) {
- fold = xmm_shift_left(fold, 8 - data_len);
- goto barret_reduction;
- }
- fold = xmm_shift_left(fold, 16 - data_len);
- goto reduction_128_64;
- }
- /* 17 to 31 bytes */
- fold = _mm_loadu_si128((const __m128i *)data);
+ memset(buffer, 0, sizeof(buffer));
+ memcpy(buffer, data, data_len);
+
+ fold = _mm_load_si128((const __m128i *)buffer);
fold = _mm_xor_si128(fold, temp);
- n = 16;
- k = params->rk3_rk4;
- goto partial_bytes;
+ if (unlikely(data_len < 4)) {
+ fold = xmm_shift_left(fold, 8 - data_len);
+ goto barret_reduction;
+ }
+ fold = xmm_shift_left(fold, 16 - data_len);
+ goto reduction_128_64;
}
- /** At least 32 bytes in the buffer */
+ /** At least 16 bytes in the buffer */
/** Apply CRC initial value */
fold = _mm_loadu_si128((const __m128i *)data);
fold = _mm_xor_si128(fold, temp);
@@ -229,7 +214,7 @@ crc32_eth_calc_pclmulqdq(
fold = crcr32_folding_round(temp, k, fold);
}
-partial_bytes:
+ /** Partial bytes - process last <16 bytes */
if (likely(n < data_len)) {
__m128i last16, a, b;
@@ -244,12 +229,8 @@ crc32_eth_calc_pclmulqdq(
b = _mm_shuffle_epi8(fold, temp);
b = _mm_blendv_epi8(b, last16, temp);
- /* k = rk1 & rk2 */
- temp = _mm_clmulepi64_si128(a, k, 0x01);
- fold = _mm_clmulepi64_si128(a, k, 0x10);
-
- fold = _mm_xor_si128(fold, temp);
- fold = _mm_xor_si128(fold, b);
+ /* k = rk3 & rk4 */
+ fold = crcr32_folding_round(b, k, a);
}
/** Reduction 128 -> 32 Assumes: fold holds 128bit folded data */
--
2.53.0
More information about the dev
mailing list