Page MenuHomeFreeBSD

libc: scalar strnlen() in RISC-V assembly
Needs ReviewPublic

Authored by strajabot on Aug 5 2024, 2:29 PM.
Tags
None
Referenced Files
Unknown Object (File)
Nov 28 2024, 8:15 AM
Unknown Object (File)
Nov 19 2024, 12:49 PM
Unknown Object (File)
Sep 30 2024, 4:54 PM
Unknown Object (File)
Sep 19 2024, 12:05 PM
Unknown Object (File)
Sep 18 2024, 11:12 AM
Unknown Object (File)
Sep 8 2024, 12:06 AM
Unknown Object (File)
Sep 7 2024, 4:37 PM
Unknown Object (File)
Sep 2 2024, 2:41 PM
Subscribers

Details

Reviewers
fuz
emaste
Summary

Optimized implementation of strnlen() in RISC-V assembly

Performance was measured using strperf on a HiFive Unmatched (SiFive HF105-001) board.

os: FreeBSD
arch: riscv
        │ strnlen_baseline │           strnlen_scalar            │
        │      sec/op      │   sec/op     vs base                │
Short          787.0µ ± 0%   430.9µ ± 1%  -45.24% (p=0.000 n=20)
Mid            621.6µ ± 0%   195.1µ ± 1%  -68.61% (p=0.000 n=20)
Long           569.4µ ± 1%   100.6µ ± 0%  -82.34% (p=0.000 n=20)
geomean        653.1µ        203.7µ       -68.81%

        │ strnlen_baseline │            strnlen_scalar            │
        │      MiB/s       │    MiB/s     vs base                 │
Short           158.8 ± 0%    290.1 ± 1%   +82.62% (p=0.000 n=20)
Mid             201.1 ± 0%    640.6 ± 1%  +218.59% (p=0.000 n=20)
Long            219.5 ± 1%   1242.9 ± 0%  +466.19% (p=0.000 n=20)
geomean         191.4         613.5       +220.57%
Test Plan

The test suite currently has no test for strnlen. I've tested the function with all different alignments and maxlen up to 128...

All tests that pass before, pass after adding the changes.

Diff Detail

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

Event Timeline

Check if you can add a unit test for strnlen. You should be able to adapt the existing memchr unit test for this purpose.

Code looks reasonable.