Skip to content

arcv: CRC32 for RV32 using clmulr - #311

Open
exur00 wants to merge 2 commits into
arc-2026.09from
loeka/crc
Open

arcv: CRC32 for RV32 using clmulr#311
exur00 wants to merge 2 commits into
arc-2026.09from
loeka/crc

Conversation

@exur00

@exur00 exur00 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

As shown in the code snippet in the RISC-V bitmanip spec v0.93 in section 2.8. It is not present in the ratified spec, but the clmulr definition has not changed between them.

This significantly improves performance for rv32 processors that have the zbc extension.

__builtin_rev_crc32_data32 (crc, data, poly) on rv32_zbc now generates:
li a4,-150925312
xor a0,a0,a1
addi a4,a4,1601
li a5,-306675712
clmul a0,a0,a4
addi a5,a5,800
clmulr a0,a0,a5

which is more compact and faster than the previous approach which generates more than 300 lines of assembly and table data.

@exur00
exur00 requested a review from luismgsilva August 4, 2026 08:57
@exur00 exur00 self-assigned this Aug 4, 2026
@exur00

exur00 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

https://lkml.org/lkml/2024/6/21/204 the linux kernel also has this in assembly

performance goes from +- 17 cycles/byte to +- 1 cycle per byte for RHX100

@exur00
exur00 force-pushed the loeka/crc branch 4 times, most recently from dbc47a5 to 8644a1a Compare August 4, 2026 09:26
@exur00

exur00 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

I think the same could work for crc64 on rv64, but I am not a crc expert, and I can't immediately find a source about it. So I'll leave it for this, don't want to make any mistakes in checksums.

@exur00
exur00 changed the base branch from arc-2026.09-dev to arc-2026.09 August 4, 2026 14:41
@exur00

exur00 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

let's wait to merge this for the first jenkins run on the gcc16 arc-2026.09

As shown in the code snippet in the RISC-V bitmanip spec v0.93
in section 2.8. It is not present in the ratified spec, but the clmulr
definition has not changed between them.

This significantly improves performance for rv32 processors that have
the zbc extension.

__builtin_rev_crc32_data32 (crc, data, poly) on rv32_zbc now generates:
	li	a4,-150925312
	xor	a0,a0,a1
	addi	a4,a4,1601
	li	a5,-306675712
	clmul	a0,a0,a4
	addi	a5,a5,800
	clmulr	a0,a0,a5

which is more compact and faster than the previous approach which
generates more than 300 lines of assembly and table data.

Signed-off-by: Loeka Rogge <loeka.rogge@globalfoundries.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants