Re: [V2] riscv: Implement Zbb based strlen and prefer it over the RVV based strlen implementation when Zbb is available
"Andreas K. Huettel" <[email protected]>
| Newsgroups | gmane.comp.lib.glibc.alpha |
|---|---|
| Organization | Gentoo Linux |
| Message-ID | <[email protected]> |
Am Samstag, 4. Juli 2026, 15:34:26 Japanische Normalzeit schrieb Jeffrey Law: > So this is the V2 patch of a Zbb strlen implementation. As was > previously noted, this is 2-4X faster than the current RVV > implementation on the K3 and meaningfully faster on the K1 as well (I > don't remember that data offhand other than Zbb was the best choice > there too). After the release please. > > The most important difference between this and the first patch is > there's no longer a Zbb specific directory. Per the discussion from > last month there aren't any plans to make any Implies relationships and > such. > > The ifunc resolver has been improved ever-so-slightly to avoid an extra > round trip through the hwprobe interface. We can get the state of Zbb > and RVV with a single round trip. A few comment typos spotted by an > LLM have been fixed as well. > > > With dropping the Zbb subdirectory, the bits left in the multiarch > directory have all the hidden symbol, alias and related stuff. I'm not > at all familiar with what needs to be done in this case. So I'd > appreciate a close look at that code. > > I've built and tested glibc on the K3 with this patch. It shows no > regressions relative to the baseline build. I've also verified the > performance data is not meaningfully changed. > > Obviously hoping we can get this included in the upcoming release... > > > -- > So we've had Zbb variants for strlen, strcmp and a few other routines > sitting here in our local repositories for a long time. The original > implementations were done by the VRULL team, then adjusted for minor > bugs caught by the glibc testsuite and later wired into the hwprobe > mechanism. > > Much like the RVV implementations that have been dropping into the tree, > I want to focus on one routine at a time to make sure we're happy with > the result, then move onto the next one. In this particular patch I'm > focused on strlen. > > The implementation is largely derived from the bitmanip examples, just > cleaned up so that it ought to work for both rv32/rv64 and either big or > little endian (little endian is untested, I believe VRULL tested rv32 at > some point). > > Neither the Zbb nor the RVV implementation seems at all sensitive to > data alignment concerns on the K3. So we can safely ignore that input > axis and focus on how many cycles it takes to handle a string of a > particular length. > > I asked the LLM model to take the performance data, convert it to cycles > per byte, then get the average cycles per byte over a range of lengths > new buckets starting a power of 2 boundaries. > > Bucket ZBB CPB Vector CBP Winner > 1-1 4.227 17.312 ZBB is ~4.1x faster > 2-3 1.714 7.232 ZBB is ~4.2x faster > 4-7 0.870 3.287 ZBB is ~3.8x faster > 8-15 0.563 1.950 ZBB is ~3.5x faster > 16-31 0.446 0.954 ZBB is ~2.1x faster > 32-63 0.299 0.477 ZBB is ~1.6x faster > 64-127 0.190 0.414 ZBB is ~2.2x faster > > And so-on with the cycles-per-byte dropping for both, but ZBB > consistently running ~2.1x faster than RVV up to a length of 8k. > > > We can see the Zbb is just better all around. There wasn't a single > case where RVV won. It's pretty obvious that the vector version has a > higher fixed overhead, but I really expected vector to overcome that > overhead as the strings got longer. As it stands the data says quite > clearly that we should be using Zbb on the K3 design and likely the K1 > design (currently being tested). > > Given the K1/K3 designs are what folks can get their hands on, I'd > recommend we make Zbb preferred over RVV. We'll likely have to adjust > that as newer designs come into the market, but the decision should be > data driven. I'm going to run this on our Veyron V2 design and Peter is > going to run on the Ascalon design, but neither of those are generally > available and probably shouldn't drive decisions, those are mostly for > informational purposes and to give a sense of whether or not higher > targeted designs are likely to benefit from the RVV variant when those > higher performance designs hit the market. > > > You could also legitimately ask what GCC should be doing here. Right now > GCC will inline the strlen call, generating RVV code that is nearly > identical to what's in glibc. So it's probably not a win for GCC to > inline an RVV strlen, though inlining does at least avoid the function > call overhead and allow for secondary optimization affects since there's > no call. > > This has been built and regression tested on the c920 and K3, the K1 is > still running. The c920 is interesting because it has neither RVV nor > Zbb, so confirming I didn't do anything dumb in the resolver was useful. > -- > > OK for the trunk? > > jeff -- PD Dr. Andreas K. Hüttel [email protected] Gentoo Linux developer (council, comrel, toolchain, base-system, perl, libreoffice) https://wiki.gentoo.org/wiki/User:Dilfridge
signature.asc
(application/pgp-signature, 870 B)
-----BEGIN PGP SIGNATURE----- iQJPBAABCAA5FiEE/Rnm0xsZLuTcY+rT3CsWIV7VQSoFAmpLpN8bFIAAAAAABAAO bWFudTIsMi41KzEuMTIsMiwyAAoJENwrFiFe1UEq3W8P/ipdHd/AcE0keSMq5Pdq tOE7/BgtSWKzCOKBc8fzV3IKQh0Az8FuKTCP+gji+I2RzH1JB/Y6YhNEXIwJRS0m syIFto6DAAJMVqgq45XibyoNTprmV70cKGQHxz6Du7YGlOE0DvJqWMv4S1Ym+5fW ShBEqFnkCbBYfHTTblSQaPB7Jin9jm5/29pte2NwMrSH7QP0sbGFU31sXwt177Gf cC4bwXMymIGKTYJ7V9KqRorPRhGw4ZZ3XfENVDkS/HmACLLIq3e0dtBcz2acquXu /H5qukl2FX3tX7b1msP+KHgsouPhSBrDuBdXBiEQJeXer/IL6PlZU8HjZXPIcxJD fJRWpzUa8j7ZjPkuJSwjXNtg6Lpj14HwkeyYi8wWjcuIBF/pO9xVXsRhf3nqjJZv LXEHaqYjfp3a1QPzpmNG/mYv0yP7YwC1Gc2yzm+ATpC6y6A8x5fBl+X3qiGyxuTk 7qNM26fDLl/xzUcrQTINRyWOt12+8rK2BqzMTvrlMJoH4EQK30JDw1CYq0B2IGPh VlLQXDriof004vC+YZo4xthknJ9g9jolqxnBm/2Fl2nsXIc07oVYQlSafb2/ddVl cf81KuyIBUZXmJs3DSzuF8z/V79s6Bt0FcpI6YKZD3agXfjP/xEAmoDMTrbtN4Uy TaGQYduUf2K8Zdlf0nhWc8cw =gORQ -----END PGP SIGNATURE-----