Page MenuHomeFreeBSD

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

Authored by strajabot on Thu, Oct 24, 6:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Oct 28, 5:28 PM
Unknown Object (File)
Sun, Oct 27, 4:35 AM
Subscribers

Details

Reviewers
fuz
emaste
Summary

Implements strrchr in RISC-V assembly, leading to the following
improvements (performance measured on SiFive HF105-001)

os: FreeBSD
arch: riscv
        │ strrchr_baseline │             strrchr_scalar             │
        │      sec/op      │   sec/op     vs base                   │
Short          837.2µ ± 1%   574.6µ ± 1%  -31.37% (p=0.000 n=20+21)
Mid            639.7µ ± 0%   269.7µ ± 0%  -57.84% (p=0.000 n=20+21)
Long           589.1µ ± 0%   176.7µ ± 0%  -70.01% (p=0.000 n=20+21)
geomean        680.8µ        301.4µ       -55.73%
 
        │ strrchr_baseline │             strrchr_scalar             │
        │      MiB/s       │   MiB/s     vs base                    │
Short           149.3 ± 1%   217.6 ± 1%   +45.71% (p=0.000 n=20+21)
Mid             195.4 ± 0%   463.6 ± 0%  +137.22% (p=0.000 n=20+21)
Long            212.2 ± 0%   707.4 ± 0%  +233.40% (p=0.000 n=20+21)
geomean         183.6        414.7       +125.88%
Test Plan

Tested using in-tree test suite, and my custom test.

Diff Detail

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

Event Timeline

This looks pretty reasonable.

We have discussed this function a bunch while @strajabot designed the algorithm and came to the conclusion that it's not easy to do better than a linear search on the tail.