From: "De Lara Guarch, Pablo" <pablo.de.lara.guarch@intel.com>
To: "Singh, Jasvinder" <jasvinder.singh@intel.com>,
"dev@dpdk.org" <dev@dpdk.org>
Cc: "olivier.matz@6wind.com" <olivier.matz@6wind.com>,
"Doherty, Declan" <declan.doherty@intel.com>
Subject: Re: [dpdk-dev] [PATCH v5 1/2] librte_net: add crc compute APIs
Date: Tue, 28 Mar 2017 18:04:16 +0000 [thread overview]
Message-ID: <E115CCD9D858EF4F90C690B0DCB4D8974770CFBE@IRSMSX108.ger.corp.intel.com> (raw)
In-Reply-To: <1490107540-66614-2-git-send-email-jasvinder.singh@intel.com>
Hi Jasvinder,
> -----Original Message-----
> From: Singh, Jasvinder
> Sent: Tuesday, March 21, 2017 2:46 PM
> To: dev@dpdk.org
> Cc: olivier.matz@6wind.com; Doherty, Declan; De Lara Guarch, Pablo
> Subject: [PATCH v5 1/2] librte_net: add crc compute APIs
>
> APIs for selecting the architecure specific implementation and computing
> the crc (16-bit and 32-bit CRCs) are added. For CRCs calculation, scalar
> as well as x86 intrinsic(sse4.2) versions are implemented.
>
> The scalar version is based on generic Look-Up Table(LUT) algorithm,
> while x86 intrinsic version uses carry-less multiplication for
> fast CRC computation.
>
> Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
> ---
> diff --git a/lib/librte_net/rte_net_crc.c b/lib/librte_net/rte_net_crc.c
> new file mode 100644
> index 0000000..89edd80
> --- /dev/null
> +++ b/lib/librte_net/rte_net_crc.c
...
> +
> +#include <rte_net_crc.h>
> +#include <stddef.h>
> +
> +/** crc tables */
> +static uint32_t crc32_eth_lut[256];
> +static uint32_t crc16_ccitt_lut[256];
Use a macro for 256, that you can use in crc32_eth_init_lut.
> +
> +static uint32_t rte_crc16_ccitt_handler(const uint8_t *data,
> + uint32_t data_len);
Separate "static uint32_t" in another line.
> +/**
> + * Reflect the bits about the middle
> + *
> + * @param x value to be reflected
Should be "val".
> + *
> + * @return reflected value
> + */
> +static uint32_t
> +reflect_32bits(const uint32_t val)
No need for "const" here, as it is not a pointer.
> +{
> + uint32_t i, res = 0;
> +
> + for (i = 0; i < 32; i++)
> + if ((val & (1 << i)) != 0)
> + res |= (uint32_t)(1 << (31 - i));
> +
> + return res;
> +}
> +
> +static void
> +crc32_eth_init_lut(const uint32_t poly,
No need for "const" here.
> + uint32_t *lut)
> +{
> + uint_fast32_t i, j;
> +
> + for (i = 0; i < 256; i++) {
> + uint_fast32_t crc = reflect_32bits(i);
> +
> + for (j = 0; j < 8; j++) {
> + if (crc & 0x80000000L)
> + crc = (crc << 1) ^ poly;
> + else
> + crc <<= 1;
> + }
> + lut[i] = reflect_32bits(crc);
Wrong indentation.
> + }
> +}
> +
> +static inline __attribute__((always_inline)) uint32_t
> +crc32_eth_calc_lut(const uint8_t *data,
> + uint32_t data_len,
> + uint32_t crc,
> + const uint32_t *lut)
> +{
> + while (data_len--)
> + crc = lut[(crc ^ *data++) & 0xffL] ^ (crc >> 8);
> +
> + return crc;
> +}
> +
> +static void
> +rte_net_crc_scalar_init(void)
> +{
> + /** 32-bit crc init */
> + crc32_eth_init_lut(CRC32_ETH_POLYNOMIAL, crc32_eth_lut);
> +
> + /** 16-bit CRC init */
> + crc32_eth_init_lut(CRC16_CCITT_POLYNOMIAL << 16,
> crc16_ccitt_lut);
> +
Remove this blank line.
> +}
> +
> +static inline uint32_t
> +rte_crc16_ccitt_handler(const uint8_t *data, uint32_t data_len)
> +{
> + return (uint16_t)~crc32_eth_calc_lut(data,
> + data_len,
> + 0xffff,
> + crc16_ccitt_lut);
Since you are casting to uint16_t, when you are supposed to cast to uint32_t
(given the return type), I would add a comment explaining why.
> +}
> +
> diff --git a/lib/librte_net/rte_net_crc.h b/lib/librte_net/rte_net_crc.h
> new file mode 100644
> index 0000000..f8c9075
> --- /dev/null
> +++ b/lib/librte_net/rte_net_crc.h
> @@ -0,0 +1,101 @@
...
> +
> +/**
> + * This API set the crc computation algorithm (i.e. scalar version,
> + * x86 64-bit sse4.2 intrinsic version, etc.) and internal data
> + * structure.
> + *
> + * @param alg
Add extra information (CRC algorithm?).
> + * - RTE_NET_CRC_SCALAR
> + * - RTE_NET_CRC_SSE42 (Use 64-bit SSE4.2 intrinsic)
> + */
> +void
> +rte_net_crc_set_alg(enum rte_net_crc_alg alg);
> +
> +/**
> + * CRC compute API
> + *
> + * @param data
> + * Pointer to the packet data for crc computation
> + * @param data_len
> + * Data length for crc computation
> + * @param type
> + * Crc type (enum rte_net_crc_type)
CRC
> + *
> + * @return
> + * crc value
Add two spaces after "@param" and "@return".
> + */
> +uint32_t
> +rte_net_crc_calc(const void *data,
> + uint32_t data_len,
> + enum rte_net_crc_type type);
> +
> +#if defined(RTE_ARCH_X86_64) || defined(RTE_CPU_FALGS_SSE_4_2)
Typo in RTE_CPU_FALGS_SSE_4_2 (I missed the same one in rte_net_crc.c ).
Also, should it be "&&"?
> +#include <rte_net_crc_sse.h>
> +#endif
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +
> +#endif /* _RTE_NET_CRC_H_ */
> diff --git a/lib/librte_net/rte_net_crc_sse.h
> b/lib/librte_net/rte_net_crc_sse.h
> new file mode 100644
> index 0000000..e9af22d
> --- /dev/null
> +++ b/lib/librte_net/rte_net_crc_sse.h
> @@ -0,0 +1,345 @@
...
> + * @brief Performs one folding round
> + *
> + * Logically function operates as follows:
> + * DATA = READ_NEXT_16BYTES();
> + * F1 = LSB8(FOLD)
> + * F2 = MSB8(FOLD)
> + * T1 = CLMUL(F1, RK1)
> + * T2 = CLMUL(F2, RK2)
> + * FOLD = XOR(T1, T2, DATA)
> + *
> + * @param data_block 16 byte data block
> + * @param precomp precomputed rk1 constanst
> + * @param fold running 16 byte folded data
> + *
> + * @return New 16 byte folded data
Move parameter/rturn description in a separate line (same for other functions).
> + */
> +static inline __attribute__((always_inline)) __m128i
> +crcr32_folding_round(const __m128i data_block,
> + const __m128i precomp,
> + const __m128i fold)
No need to use "const" here.
> +{
> + __m128i tmp0 = _mm_clmulepi64_si128(fold, precomp, 0x01);
> + __m128i tmp1 = _mm_clmulepi64_si128(fold, precomp, 0x10);
> +
> + return _mm_xor_si128(tmp1, _mm_xor_si128(data_block, tmp0));
> +}
> +
> +/**
> + * Performs reduction from 128 bits to 64 bits
> + *
> + * @param data128 128 bits data to be reduced
> + * @param precomp rk5 and rk6 precomputed constants
> + *
> + * @return data reduced to 64 bits
> + */
> +
> +static inline __attribute__((always_inline)) __m128i
> +crcr32_reduce_128_to_64(__m128i data128,
> + const __m128i precomp)
No need to use "const" here.
...
> +
> +
> +static inline void
> +rte_net_crc_sse42_init(void)
> +{
> + uint64_t k1, k2, k5, k6;
> + uint64_t p = 0, q = 0;
> +
> + /** Initialize CRC16 data */
> + k1 = 0x189aeLLU;
> + k2 = 0x8e10LLU;
> + k5 = 0x189aeLLU;
> + k6 = 0x114aaLLU;
> + q = 0x11c581910LLU;
> + p = 0x10811LLU;
> +
> + /** Save the params in context structure */
> + crc16_ccitt_pclmulqdq.rk1_rk2 =
> + _mm_setr_epi64(_mm_cvtsi64_m64(k1),
> _mm_cvtsi64_m64(k2));
> + crc16_ccitt_pclmulqdq.rk5_rk6 =
> + _mm_setr_epi64(_mm_cvtsi64_m64(k5),
> _mm_cvtsi64_m64(k6));
> + crc16_ccitt_pclmulqdq.rk7_rk8 =
> + _mm_setr_epi64(_mm_cvtsi64_m64(q),
> _mm_cvtsi64_m64(p));
> +
> + /** Initialize CRC32 data */
> + k1 = 0xccaa009eLLU;
> + k2 = 0x1751997d0LLU;
> + k5 = 0xccaa009eLLU;
> + k6 = 0x163cd6124LLU;
> + q = 0x1f7011640LLU;
> + p = 0x1db710641LLU;
> +
> + /** Save the params in context structure */
> + crc32_eth_pclmulqdq.rk1_rk2 =
> + _mm_setr_epi64(_mm_cvtsi64_m64(k1),
> _mm_cvtsi64_m64(k2));
Add extra tab for better readability.
> + crc32_eth_pclmulqdq.rk5_rk6 =
> + _mm_setr_epi64(_mm_cvtsi64_m64(k5),
> _mm_cvtsi64_m64(k6));
> + crc32_eth_pclmulqdq.rk7_rk8 =
> + _mm_setr_epi64(_mm_cvtsi64_m64(q),
> _mm_cvtsi64_m64(p));
> +
> + _mm_empty();
Maybe we need a comment here.
> +
> +}
> +
> +static inline uint32_t
> +rte_crc16_ccitt_sse42_handler(const uint8_t *data,
> + uint32_t data_len)
> +{
> + return (uint16_t)~crc32_eth_calc_pclmulqdq(data,
> + data_len,
> + 0xffff,
> + &crc16_ccitt_pclmulqdq);
Same comment about the casting here.
> +}
> +
> +static inline uint32_t
> +rte_crc32_eth_sse42_handler(const uint8_t *data,
> + uint32_t data_len)
> +{
> + return ~crc32_eth_calc_pclmulqdq(data,
> + data_len,
> + 0xffffffffUL,
> + &crc32_eth_pclmulqdq);
> +}
> +
> +#ifdef __cplusplus
> +}
> +#endif
> +
> +#endif /* _RTE_NET_CRC_SSE_H_ */
> diff --git a/lib/librte_net/rte_net_version.map
> b/lib/librte_net/rte_net_version.map
> index 3b15e65..c6716ec 100644
> --- a/lib/librte_net/rte_net_version.map
> +++ b/lib/librte_net/rte_net_version.map
> @@ -4,3 +4,11 @@ DPDK_16.11 {
>
> local: *;
> };
> +
> +DPDK_17.05 {
> + global:
> +
> + rte_net_crc_set_alg;
> + rte_net_crc_calc;
This has to be alphabetically sorted.
> +
> +} DPDK_16.11;
> --
> 2.5.5
next prev parent reply other threads:[~2017-03-28 18:04 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-24 20:54 [dpdk-dev] [PATCH 0/2] librte_net: add crc computation support Jasvinder Singh
2017-02-24 20:54 ` [dpdk-dev] [PATCH 1/2] librte_net: add crc init and compute APIs Jasvinder Singh
2017-02-28 12:08 ` [dpdk-dev] [PATCH v2 0/2] librte_net: add crc computation support Jasvinder Singh
2017-02-28 12:08 ` [dpdk-dev] [PATCH v2 1/2] librte_net: add crc init and compute APIs Jasvinder Singh
2017-02-28 12:15 ` Jerin Jacob
2017-03-01 18:46 ` Thomas Monjalon
2017-03-02 13:03 ` Singh, Jasvinder
2017-03-06 15:27 ` Thomas Monjalon
2017-03-08 11:08 ` De Lara Guarch, Pablo
2017-03-15 17:35 ` Thomas Monjalon
2017-03-15 19:03 ` Dumitrescu, Cristian
2017-03-15 20:15 ` Thomas Monjalon
2017-03-15 21:11 ` Dumitrescu, Cristian
2017-03-15 19:09 ` Dumitrescu, Cristian
2017-03-12 21:33 ` [dpdk-dev] [PATCH v3 0/2] librte_net: add crc computation support Jasvinder Singh
2017-03-12 21:33 ` [dpdk-dev] [PATCH v3 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-03-13 3:06 ` Ananyev, Konstantin
2017-03-13 9:05 ` Singh, Jasvinder
2017-03-20 19:29 ` [dpdk-dev] [PATCH v4 0/2] librte_net: add crc computation support Jasvinder Singh
2017-03-20 19:29 ` [dpdk-dev] [PATCH v4 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-03-21 14:45 ` [dpdk-dev] [PATCH v5 0/2] librte_net: add crc computation support Jasvinder Singh
2017-03-21 14:45 ` [dpdk-dev] [PATCH v5 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-03-28 18:04 ` De Lara Guarch, Pablo [this message]
2017-03-28 18:07 ` De Lara Guarch, Pablo
2017-03-28 19:21 ` Singh, Jasvinder
2017-03-29 12:42 ` [dpdk-dev] [PATCH v6 0/2] librte_net: add crc computation support Jasvinder Singh
2017-03-29 12:42 ` [dpdk-dev] [PATCH v6 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-03-29 16:14 ` De Lara Guarch, Pablo
2017-03-29 17:15 ` [dpdk-dev] [PATCH v7 0/2] librte_net: add crc computation support Jasvinder Singh
2017-03-29 17:15 ` [dpdk-dev] [PATCH v7 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-03-30 11:30 ` [dpdk-dev] [PATCH v8 0/2] librte_net: add crc computation support Jasvinder Singh
2017-03-30 11:30 ` [dpdk-dev] [PATCH v8 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-03-30 11:31 ` Ananyev, Konstantin
2017-03-30 12:06 ` Singh, Jasvinder
2017-03-30 14:40 ` Olivier Matz
2017-03-30 15:14 ` Singh, Jasvinder
2017-03-30 16:15 ` [dpdk-dev] [PATCH v9 0/3] librte_net: add crc computation support Jasvinder Singh
2017-03-30 16:15 ` [dpdk-dev] [PATCH v9 1/3] librte_net: add crc compute APIs Jasvinder Singh
2017-04-04 20:00 ` Thomas Monjalon
2017-04-05 14:58 ` [dpdk-dev] [PATCH v10 0/2] librte_net: add crc computation support Jasvinder Singh
2017-04-05 14:58 ` [dpdk-dev] [PATCH v10 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-04-05 17:49 ` Thomas Monjalon
2017-04-05 19:22 ` Singh, Jasvinder
2017-04-05 20:49 ` [dpdk-dev] [PATCH v11 0/2] librte_net: add crc computation support Jasvinder Singh
2017-04-05 20:49 ` [dpdk-dev] [PATCH v11 1/2] librte_net: add crc compute APIs Jasvinder Singh
2017-04-05 20:49 ` [dpdk-dev] [PATCH v11 2/2] test/test: add unit test for CRC computation Jasvinder Singh
2017-04-05 20:59 ` Thomas Monjalon
2017-04-05 21:00 ` [dpdk-dev] [PATCH v11 0/2] librte_net: add crc computation support Thomas Monjalon
2017-04-05 14:58 ` [dpdk-dev] [PATCH v10 2/2] test/test: add unit test for CRC computation Jasvinder Singh
2017-03-30 16:15 ` [dpdk-dev] [PATCH v9 2/3] " Jasvinder Singh
2017-03-30 16:15 ` [dpdk-dev] [PATCH v9 3/3] maintainers: add packet crc section and claim maintainership Jasvinder Singh
2017-04-04 19:55 ` Thomas Monjalon
2017-04-04 20:02 ` [dpdk-dev] [PATCH v9 0/3] librte_net: add crc computation support Thomas Monjalon
2017-04-05 8:34 ` Singh, Jasvinder
2017-04-05 9:01 ` Thomas Monjalon
2017-04-05 9:37 ` Richardson, Bruce
2017-04-05 12:52 ` Singh, Jasvinder
2017-03-30 11:30 ` [dpdk-dev] [PATCH v8 2/2] test/test: add unit test for CRC computation Jasvinder Singh
2017-03-29 17:15 ` [dpdk-dev] [PATCH v7 " Jasvinder Singh
2017-03-29 12:42 ` [dpdk-dev] [PATCH v6 " Jasvinder Singh
2017-03-29 16:12 ` De Lara Guarch, Pablo
2017-03-21 14:45 ` [dpdk-dev] [PATCH v5 " Jasvinder Singh
2017-03-28 19:23 ` De Lara Guarch, Pablo
2017-03-28 19:27 ` Singh, Jasvinder
2017-03-20 19:29 ` [dpdk-dev] [PATCH v4 2/2] app/test: " Jasvinder Singh
2017-03-21 7:14 ` Peng, Yuan
2017-03-12 21:33 ` [dpdk-dev] [PATCH v3 " Jasvinder Singh
2017-02-28 12:08 ` [dpdk-dev] [PATCH v2 " Jasvinder Singh
2017-02-24 20:54 ` [dpdk-dev] [PATCH " Jasvinder Singh
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=E115CCD9D858EF4F90C690B0DCB4D8974770CFBE@IRSMSX108.ger.corp.intel.com \
--to=pablo.de.lara.guarch@intel.com \
--cc=declan.doherty@intel.com \
--cc=dev@dpdk.org \
--cc=jasvinder.singh@intel.com \
--cc=olivier.matz@6wind.com \
/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;
as well as URLs for NNTP newsgroup(s).