riscv: word-at-a-time: improve find_zero()
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v5 Latest posting 2/23 patches 1 replyIn review
- v5 posting 1/23 patches 0 repliesSuperseded
- v43 patches 2 repliesSuperseded
Earlier versions · 3
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v3 | 3 patches | 1 reply | Superseded | |
| v2 | 3 patches | 0 replies | Superseded | |
| v1 | 0 of 3 patches | 0 replies | Superseded |
Changes in v5 from the cover letter
- fix commit msg of patch1
- collect Reviewed-by tag
Patches in v5 posting 2/2 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | riscv: word-at-a-time: improve find_zero() for !RISCV_ISA_ZBB or no Zbbarch/ | +29 | 0 replies | |
| 2/3 | riscv: word-at-a-time: improve find_zero() for RV32arch/ | +1 | 0 replies | |
| 3/3 | riscv: word-at-a-time: improve find_zero() for Zbbarch/ | +15 | 1 reply |
Reviews trailers per patch
2 of 3 patches have a Reviewed-by or Acked-by.
| Patch | Nam Cao | Ze Huang |
|---|---|---|
| 1/3 | R-b | |
| 2/3 | R-b | |
| 3/3 | T-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH RESEND v5 0/3] riscv: word-at-a-time: improve find_zero()
Currently, there are two problems with riscv find_zero():
1. When !RISCV_ISA_ZBB, the generic fls64() bring non-optimal code.
But in word-at-a-time case, we don't have to go with fls64() code path, instead, we can fallback to the generic word-at-a-time implementaion.
What's more, the fls64() brings non-necessary zero bits couting for RV32. In fact, fls() is enough.
2. Similar as 1, the generic fls64() also brings non-optimal code when RISCV_ISA_ZBB=y but HW doesn't support Zbb.
So this series tries to improve find_zero() by falling back to generic word-at-a-time implementaion where necessary. We dramatically reduce the instructions of find_zero() from 33 to 8! Also testing with the micro-benchamrk in patch1 shows that the performance is improved by about 1150%!
After that, we improve find_zero() for Zbb further by applying similar optimization as Linus did in commit f915a3e5b018 ("arm64:
word-at-a-time: improve byte count calculations for LE"), so that we share the similar improvements:
"The difference between the old and the new implementation is that "count_zero()" ends up scheduling better because it is being done on a value that is available earlier (before the final mask).
But more importantly, it can be implemented without the insane semantics of the standard bit finding helpers that have the off-by-one issue and have to special-case the zero mask situation."
On RV64 w/ Zbb, the new "find_zero()" ends up just "ctz" plus the shift right that then ends up being subsumed by the "add to final length". Reduce the total instructions from 7 to 3!
But I have no HW platform which supports Zbb, so I can't get the performance improvement numbers by the last patch, only built and tested the patch on QEMU.
Since v4:
- fix commit msg of patch1
- collect Reviewed-by tag
Since v3:
- fold part of patch2 into patch1 and make the RV32 improvement as patch2.
Since v2:
- fix wrong version(PATCH vs "PATCH v2" in cover letter)
Since v1:
- rebase on the latest rc1
- Use if (IS_ENABLED(CONFIG_RISCV_ISA_ZBB) && IS_ENABLED(CONFIG_TOOLCHAIN_HAS_ZBB) && riscv_has_extension_likely(RISCV_ISA_EXT_ZBB))
Jisheng Zhang (3):
riscv: word-at-a-time: improve find_zero() for !RISCV_ISA_ZBB or no
Zbb
riscv: word-at-a-time: improve find_zero() for RV32
riscv: word-at-a-time: improve find_zero() for Zbb
arch/riscv/include/asm/word-at-a-time.h | 46 +++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-)
Signature · 1 line
2.51.0