Skip to content

igzip/riscv64: Optimize deflate performance with vectorized assembly implementation of compare258 - #431

Closed
zl523856 wants to merge 1 commit into
intel:masterfrom
zte-riscv:optimize-deflate2
Closed

zl523856 wants to merge 1 commit into
intel:masterfrom
zte-riscv:optimize-deflate2

Conversation

@zl523856

Copy link
Copy Markdown
Contributor

The hot functions in the three parts—icf_body, deflate_body, and update_histogram—are centered around compare258. By implementing a reusable vectorized assembly version of compare258 (i.e., compare258_rvv) using RISC-V vector extensions, while keeping the original C control flow in the outer layers, we can improve deflate performance.

This optimization has been validated with igzip_perf on the Spacemit(R) X100 platform:

igzip_perf -f 0 -y 0 -b 1024 silesia.tar (6% performance improvement)
new:isal_stateful_deflate-> runtime = 4342565 usecs, bandwidth 423 MB in 4.3426 sec = 97.62 MB/s
old:isal_stateful_deflate-> runtime = 4616307 usecs, bandwidth 423 MB in 4.6163 sec = 91.83 MB/s

igzip_perf -f 0 -y 1 -b 1024 silesia.tar (9% performance improvement)
new:isal_stateful_deflate-> runtime = 3975344 usecs, bandwidth 423 MB in 3.9753 sec = 106.64 MB/s
old:isal_stateful_deflate-> runtime = 4322878 usecs, bandwidth 423 MB in 4.3229 sec = 98.06 MB/s

igzip_perf -f 1 -y 0 -b 1024 silesia.tar (10% performance improvement)
new:isal_stateful_deflate-> runtime = 4233799 usecs, bandwidth 423 MB in 4.2338 sec = 100.13 MB/s
old:isal_stateful_deflate-> runtime = 4656209 usecs, bandwidth 423 MB in 4.6562 sec = 91.04 MB/s

igzip_perf -f 1 -y 1 -b 1024 silesia.tar (6% performance improvement)
new:isal_stateful_deflate-> runtime = 5723116 usecs, bandwidth 211 MB in 5.7231 sec = 37.04 MB/s
old:isal_stateful_deflate-> runtime = 6045445 usecs, bandwidth 211 MB in 6.0454 sec = 35.06 MB/s

All tests successful:
PASS: igzip/igzip_rand_test

@zl523856

Copy link
Copy Markdown
Contributor Author

I have pulled the zte-riscv:optimize-deflate2 branch locally and run ./tools/test_checks.sh on a Spacemit(R) X100. The test passed successfully. Could the maintainer please trigger the CI again? Thanks! @pablodelara
test_checks.log

@sunyuechi

Copy link
Copy Markdown
Contributor

Tested on a BPI-F3 (K1) and the CI failure reproduces reliably. This looks like a misaligned access issue.

@zl523856

Copy link
Copy Markdown
Contributor Author

Tested on a BPI-F3 (K1) and the CI failure reproduces reliably. This looks like a misaligned access issue.

Thank you for the guidance. I've successfully reproduced the error and am currently working on a fix.

@sunyuechi

Copy link
Copy Markdown
Contributor

I think we'd better fix the root cause rather than work around it. The problem is the vlse64 in igzip/riscv64/igzip_deflate_hash_rvv.S; it may be solvable by switching to vle8 or similar.

More importantly, these hash computations often end up slower than the scalar code. Did you benchmark igzip/riscv64/igzip_deflate_hash_rvv.S on its own? If it's slower, maybe it's better to
just drop the vectorization of it altogether.

@zl523856

zl523856 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

I think we'd better fix the root cause rather than work around it. The problem is the vlse64 in igzip/riscv64/igzip_deflate_hash_rvv.S; it may be solvable by switching to vle8 or similar.

More importantly, these hash computations often end up slower than the scalar code. Did you benchmark igzip/riscv64/igzip_deflate_hash_rvv.S on its own? If it's slower, maybe it's better to just drop the vectorization of it altogether.

I haven't tested it individually yet. I'll run some additional verification and fix the unaligned access issue in igzip_deflate_hash_rvv.S on the K1 environment.

@zl523856

Copy link
Copy Markdown
Contributor Author

The igzip_deflate_hash_riscv64.S has been updated to a scalar implementation. Could the reviewer please re-trigger the CI and review? Thank you! @pablodelara @sunyuechi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the _rvv.c files need to be guarded with #if HAVE_RVV, otherwise the
build will fail when V is not supported.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several of the newly added files are missing a copyright header, would you
like to add those as well?

Comment thread igzip/riscv64/igzip_deflate_body_rvv.c Outdated
#include "unaligned.h"

extern uint32_t
compare258_rvv(const uint8_t *str1, const uint8_t *str2, uint32_t max_length);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extern declarations in these rvv files could be dropped and add
into huffman_riscv64.h, which would be easier to maintain.

lbu t6, 2(a3); slli t6, t6, 16; or t2, t2, t6
lbu t6, 3(a3); slli t6, t6, 24; or t2, t2, t6

.loop_start:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The labels in this file could use the .L prefix, like the other .S files do.

@zl523856
zl523856 force-pushed the optimize-deflate2 branch 2 times, most recently from afbb956 to c20fd90 Compare October 9, 2026 06:47
@zl523856

zl523856 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

The review comments have been addressed. Could the reviewer please re-trigger the CI and review? Thank you! @pablodelara @sunyuechi

@pablodelara

Copy link
Copy Markdown
Contributor

@tkanteck can review this from now on, but @sunyuechi, could you review again?

@sunyuechi

Copy link
Copy Markdown
Contributor

Only the four _rvv.c files under igzip/riscv64 still lack a license header

@tkanteck tkanteck added the riscv label Oct 28, 2026
@zl523856

Copy link
Copy Markdown
Contributor Author

Only the four _rvv.c files under igzip/riscv64 still lack a license header

The newly added rvv.c is derived from existing functions within the library (which currently lack copyright headers). Therefore, I haven't added a copyright notice to this new file either.

@sunyuechi

Copy link
Copy Markdown
Contributor

LGTM

@zl523856

zl523856 commented Nov 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @tkanteck, just a gentle ping — this PR has been open for a while. Would you be able to take a look when you get a chance? Happy to address any changes or add more details if needed. Thanks!

@tkanteck tkanteck added the wip work in progress label Nov 9, 2026
@tkanteck

tkanteck commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Hi @tkanteck, just a gentle ping — this PR has been open for a while. Would you be able to take a look when you get a chance? Happy to address any changes or add more details if needed. Thanks!

Thanks for the ping and apologies for the delay. Let me have a look into it.

@tkanteck tkanteck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few files that have no copyright/license header. Could you address it please?

Comment thread igzip/riscv64/igzip_deflate_body_rvv.c Resolved
@@ -0,0 +1,62 @@
#if HAVE_RVV

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no copyright / license header here

@tkanteck tkanteck removed the wip work in progress label Nov 9, 2026
@zl523856

Copy link
Copy Markdown
Contributor Author

有些文件缺少版权/许可声明。请问您能否处理一下?

The four new rvv.c files are derived from existing functions in igzip/igzip_base.c, igzip/igzip_icf_base.c, and igzip/igzip_icf_body.c. As the original files contain no copyright notice, I omitted a copyright header. Could you please advise whether this is acceptable, or whether I should add "Copyright (c) 2011-2016 Intel Corporation All rights reserved"?

@tkanteck

Copy link
Copy Markdown
Contributor

有些文件缺少版权/许可声明。请问您能否处理一下?

The four new rvv.c files are derived from existing functions in igzip/igzip_base.c, igzip/igzip_icf_base.c, and igzip/igzip_icf_body.c. As the original files contain no copyright notice, I omitted a copyright header. Could you please advise whether this is acceptable, or whether I should add "Copyright (c) 2011-2016 Intel Corporation All rights reserved"?

If existing files are re-used then original headers should be preserved. If additional changes are introduced to the files then extra copyright line can be added, next to the Intel one.

…implementation of compare258

The hot functions in the three parts—icf_body, deflate_body, and update_histogram—are centered around compare258. By implementing a reusable vectorized assembly version of compare258 (i.e., compare258_rvv) using RISC-V vector extensions, while keeping the original C control flow in the outer layers, we can improve deflate performance.

This optimization has been validated with igzip_perf on the Spacemit(R) X100 platform:

igzip_perf -f 0 -y 0 -b 1024 silesia.tar (6% performance improvement)
new:isal_stateful_deflate-> runtime = 4342565 usecs, bandwidth 423 MB in 4.3426 sec = 97.62 MB/s
old:isal_stateful_deflate-> runtime = 4616307 usecs, bandwidth 423 MB in 4.6163 sec = 91.83 MB/s

igzip_perf -f 0 -y 1 -b 1024 silesia.tar (9% performance improvement)
new:isal_stateful_deflate-> runtime = 3975344 usecs, bandwidth 423 MB in 3.9753 sec = 106.64 MB/s
old:isal_stateful_deflate-> runtime = 4322878 usecs, bandwidth 423 MB in 4.3229 sec = 98.06 MB/s

igzip_perf -f 1 -y 0 -b 1024 silesia.tar (10% performance improvement)
new:isal_stateful_deflate-> runtime = 4233799 usecs, bandwidth 423 MB in 4.2338 sec = 100.13 MB/s
old:isal_stateful_deflate-> runtime = 4656209 usecs, bandwidth 423 MB in 4.6562 sec = 91.04 MB/s

igzip_perf -f 1 -y 1 -b 1024 silesia.tar (6% performance improvement)
new:isal_stateful_deflate-> runtime = 5723116 usecs, bandwidth 211 MB in 5.7231 sec = 37.04 MB/s
old:isal_stateful_deflate-> runtime = 6045445 usecs, bandwidth 211 MB in 6.0454 sec = 35.06 MB/s

All tests successful:
PASS: igzip/igzip_rand_test

Signed-off-by: zhoulu <zhou.lu1@zte.com.cn>
@zl523856

Copy link
Copy Markdown
Contributor Author

有些文件缺少版权/许可声明。请问您能否处理一下?

The four new rvv.c files are derived from existing functions in igzip/igzip_base.c, igzip/igzip_icf_base.c, and igzip/igzip_icf_body.c. As the original files contain no copyright notice, I omitted a copyright header. Could you please advise whether this is acceptable, or whether I should add "Copyright (c) 2011-2016 Intel Corporation All rights reserved"?

If existing files are re-used then original headers should be preserved. If additional changes are introduced to the files then extra copyright line can be added, next to the Intel one.

I've made the requested changes. Could you please review again when you get a chance? Thank you!

@tkanteck tkanteck added wip work in progress and removed wip work in progress labels Nov 12, 2026
@tkanteck

Copy link
Copy Markdown
Contributor

Thanks. It's merged now e1838d4

@tkanteck tkanteck closed this Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants