Page MenuHomeFreeBSD

libc: scalar strlen() in RISC-V assembly
AcceptedPublic

Authored by strajabot on Jun 22 2024, 5:04 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Feb 3, 1:36 AM
Unknown Object (File)
Mon, Jan 20, 6:24 PM
Unknown Object (File)
Wed, Jan 8, 2:15 PM
Unknown Object (File)
Nov 25 2024, 6:52 PM
Unknown Object (File)
Nov 23 2024, 3:59 PM
Unknown Object (File)
Nov 21 2024, 4:27 AM
Unknown Object (File)
Nov 21 2024, 4:26 AM
Unknown Object (File)
Nov 21 2024, 1:28 AM
Subscribers

Details

Reviewers
fuz
emaste
mhorne
Summary

Includes a scalar implementation of strlen() for the RISC-V
architecture and changes to the corresponding manpage.

Performance was benchamarked using before and after:
https://github.com/clausecker/strperf

os: FreeBSD
arch: riscv
        │ strlen_baseline │             strlen_scalar              │
        │     sec/op      │   sec/op     vs base                   │
Short        541.2µ ± 17%   401.6µ ± 0%  -25.78% (p=0.000 n=21+20)
Mid          249.6µ ±  3%   191.9µ ± 0%  -23.13% (p=0.000 n=21+20)
Long         124.6µ ±  0%   110.7µ ± 0%  -11.13% (p=0.000 n=21+20)
geomean      256.3µ         204.3µ       -20.26%

        │ strlen_baseline │              strlen_scalar               │
        │       B/s       │      B/s       vs base                   │
Short       220.3Mi ± 14%    296.8Mi ± 0%  +34.74% (p=0.000 n=21+20)
Mid         477.6Mi ±  3%    621.3Mi ± 0%  +30.09% (p=0.000 n=21+20)
Long        956.9Mi ±  0%   1076.7Mi ± 0%  +12.52% (p=0.000 n=21+20)
geomean     465.2Mi          583.4Mi       +25.40%
Test Plan

Passes the tests in the test suite

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 58351
Build 55239: arc lint + arc unit

Event Timeline

LGTM with indicated possibilities of improvement.

It might be possible to improve performance further by unrolling the main loop once or by processing 16 bytes per iteration.

lib/libc/riscv/string/strlen.S
25

Instead of loading -1 here, you could simply reuse the mask in t0. It doesn't matter what you or in, as long as it's not zeros.

mhorne requested changes to this revision.Jun 25 2024, 2:29 PM
mhorne added a subscriber: mhorne.

The new .S file needs a license.

I trust @fuz and the test suite to provide proper review of the assembly; more than I can.

What hardware was the benchmarking performed on? This is worth noting in the commit description.

lib/libc/riscv/string/Makefile.inc
2–5
This revision now requires changes to proceed.Jun 25 2024, 2:29 PM
lib/libc/riscv/string/strlen.S
5–8

One more thing: we generally prefer C-style comments in assembly sources (/* comment */).

Add license, remove unnecessary li, reformat comments

This revision is now accepted and ready to land.Jun 26 2024, 3:54 PM

We will bulk commit these following an exp-run of the ports tree to give these changes some more field testing.