Page MenuHomeFreeBSD

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

Authored by strajabot on Oct 24 2024, 6:31 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 8:55 AM
Unknown Object (File)
Fri, Oct 10, 8:54 AM
Unknown Object (File)
Fri, Oct 10, 8:54 AM
Unknown Object (File)
Fri, Oct 10, 8:54 AM
Unknown Object (File)
Fri, Oct 10, 2:42 AM
Unknown Object (File)
Mon, Oct 6, 3:00 AM
Unknown Object (File)
Fri, Oct 3, 12:31 PM
Unknown Object (File)
Fri, Oct 3, 6:46 AM
Subscribers

Details

Reviewers
fuz
emaste
mhorne
Group Reviewers
riscv
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 Skipped
Unit
Tests Skipped

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.

mhorne added a subscriber: mhorne.
mhorne added inline comments.
lib/libc/riscv/string/strrchr.S
11
15–26

I am nitpicking.

This revision is now accepted and ready to land.Aug 19 2025, 7:00 PM
  • fixup: address comments on strrchr
This revision now requires review to proceed.Mon, Sep 22, 8:48 PM

Addressed the comments on the diff