mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-08-29 16:18:09 -04:00
Add an assembly implementation of strrchr() for RISC-V. This implementation minimizes instruction count and avoids unnecessary memory access to the stack. The performance benefits are most visible on small workloads (1-16 bytes) where the architectural savings in function overhead outweigh the execution time of the scan loop. Benchmark results (QEMU TCG, rv64): Length | Original (MB/s) | Optimized (MB/s) | Improvement -------|-----------------|------------------|------------ 1 B | 20 | 21 | +5.0% 7 B | 111 | 120 | +8.1% 16 B | 189 | 199 | +5.3% 512 B | 361 | 382 | +5.8% 4096 B | 388 | 391 | +0.8% Signed-off-by: Feng Jiang <jiangfeng@kylinos.cn> Tested-by: Joel Stanley <joel@jms.id.au> Link: https://patch.msgid.link/20260130025018.172925-9-jiangfeng@kylinos.cn Signed-off-by: Paul Walmsley <pjw@kernel.org>
38 lines
624 B
ArmAsm
38 lines
624 B
ArmAsm
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
/*
|
|
* Copyright (C) 2025 Feng Jiang <jiangfeng@kylinos.cn>
|
|
*/
|
|
|
|
#include <linux/linkage.h>
|
|
#include <asm/asm.h>
|
|
|
|
/* char *strrchr(const char *s, int c) */
|
|
SYM_FUNC_START(strrchr)
|
|
/*
|
|
* Parameters
|
|
* a0 - The string to be searched
|
|
* a1 - The character to seaerch for
|
|
*
|
|
* Returns
|
|
* a0 - Address of last occurrence of 'c' or 0
|
|
*
|
|
* Clobbers
|
|
* t0, t1
|
|
*/
|
|
andi a1, a1, 0xff
|
|
mv t1, a0
|
|
li a0, 0
|
|
1:
|
|
lbu t0, 0(t1)
|
|
bne t0, a1, 2f
|
|
mv a0, t1
|
|
2:
|
|
addi t1, t1, 1
|
|
bnez t0, 1b
|
|
ret
|
|
SYM_FUNC_END(strrchr)
|
|
|
|
SYM_FUNC_ALIAS_WEAK(__pi_strrchr, strrchr)
|
|
EXPORT_SYMBOL(strrchr)
|