From: Eric Biggers <ebiggers@kernel.org>
To: Zhihang Shao <zhihang.shao.iscas@gmail.com>
Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-riscv@lists.infradead.org, ardb@kernel.org
Subject: Re: [PATCH v3] riscv: Optimize crct10dif with zbc extension
Date: Wed, 5 Feb 2025 08:30:12 -0800 [thread overview]
Message-ID: <20250205163012.GB1474@sol.localdomain> (raw)
In-Reply-To: <20250205065815.91132-1-zhihang.shao.iscas@gmail.com>
On Wed, Feb 05, 2025 at 02:58:15PM +0800, Zhihang Shao wrote:
> The current CRC-T10DIF algorithm on RISC-V platform is based on
> table-lookup optimization.
> Given the previous work on optimizing crc32 calculations with zbc
> extension, it is believed that this will be equally effective for
> accelerating crc-t10dif.
>
> Therefore this patch offers an implementation of crc-t10dif using zbc
> extension. This can detect whether the current runtime environment
> supports zbc feature and, if so, uses it to accelerate crc-t10dif
> calculations.
>
> This patch is updated due to the patchset of updating kernel's
> CRC-T10DIF library in 6.14, which is finished by Eric Biggers.
> Also, I used crc_kunit.c to test the performance of crc-t10dif optimized
> by crc extension.
>
> Signed-off-by: Zhihang Shao <zhihang.shao.iscas@gmail.com>
> ---
> arch/riscv/Kconfig | 1 +
> arch/riscv/lib/Makefile | 1 +
> arch/riscv/lib/crc-t10dif-riscv.c | 132 ++++++++++++++++++++++++++++++
> 3 files changed, 134 insertions(+)
> create mode 100644 arch/riscv/lib/crc-t10dif-riscv.c
Acked-by: Eric Biggers <ebiggers@kernel.org>
Tested-by: Eric Biggers <ebiggers@kernel.org>
This can go through the riscv tree.
Some minor comments below.
> +static inline u64 crct10dif_prep(u16 crc, unsigned long const *ptr)
> +{
> + return ((u64)crc << 48) ^ (__force u64)__cpu_to_be64(*ptr);
> +}
> +
> +#elif __riscv_xlen == 32
> +#define STEP_ORDER 2
> +#define CRCT10DIF_POLY_QT_BE 0xf65a57f8
> +
> +static inline u32 crct10dif_prep(u16 crc, unsigned long const *ptr)
> +{
> + return ((u32)crc << 16) ^ (__force u32)__cpu_to_be32(*ptr);
> +}
Maybe use 'const __be64 *' and 'const __be32 *' for the pointer, and use
be64_to_cpu() and be32_to_cpu(). Then the __force cast won't be needed.
> +static inline u16 crct10dif_zbc(unsigned long s)
> +{
> + u16 crc;
> +
> + asm volatile (".option push\n"
> + ".option arch,+zbc\n"
> + "clmulh %0, %1, %2\n"
> + "xor %0, %0, %1\n"
> + "clmul %0, %0, %3\n"
> + ".option pop\n"
> + : "=&r" (crc)
> + : "r"(s),
> + "r"(CRCT10DIF_POLY_QT_BE),
> + "r"(CRCT10DIF_POLY)
> + :);
> +
> + return crc;
> +}
A comment mentioning that this is using Barrett reduction would be helpful.
BTW, this is fine for an initial implementation, but eventually we'll probably
want to make it fold multiple words at a time to take advantage of
instruction-level parallelism, like the x86 PCLMULQDQ code does. We also might
be able to share code among all the CRC variants like what I'm doing for x86.
> +#define STEP (1 << STEP_ORDER)
> +#define OFFSET_MASK (STEP - 1)
You can just remove the above #defines and use 'sizeof(unsigned long)' directly.
You can even use the % and / operators since the compiler optimizes them.
arch/x86/lib/crc32-glue.c does this.
> + p = (unsigned char const *)p_ul;
Please use 'const u8 *'.
Thanks!
- Eric
next prev parent reply other threads:[~2025-02-05 16:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-05 6:58 [PATCH v3] riscv: Optimize crct10dif with zbc extension Zhihang Shao
2025-02-05 16:30 ` Eric Biggers [this message]
2025-02-06 20:19 ` Eric Biggers
2025-02-10 20:35 ` Eric Biggers
2025-02-12 8:08 ` Zhihang Shao
2025-02-12 19:52 ` Eric Biggers
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=20250205163012.GB1474@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=ardb@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=zhihang.shao.iscas@gmail.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