[PATCH 3/4] RISC-V: strcmp [speed optimized]: optimize null detect logic for targets with Zb* extension support
puranikvinit <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
Introduces conditional use of the orc.b instruction from the Zbb extension for null byte detection, falling back to the original logic for non-Zbb targets. This reduces cycles in the hot path for supported architectures. Signed-off-by: puranikvinit <[email protected]> Reviewed-by: Christian Herber <[email protected]> --- newlib/libc/machine/riscv/strcmp.S | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/newlib/libc/machine/riscv/strcmp.S b/newlib/libc/machine/riscv/strcmp.S index 405f2f655..42c870c10 100644 --- a/newlib/libc/machine/riscv/strcmp.S +++ b/newlib/libc/machine/riscv/strcmp.S @@ -48,10 +48,14 @@ strcmp: REG_L a2, \i*SZREG(a0) REG_L a3, \i*SZREG(a1) - and a4, a2, a5 - or t1, a2, a5 - add a4, a4, a5 - or a4, a4, t1 + #if __riscv_zbb + orc.b a4, a2 + #else + and a4, a2, a5 + or t1, a2, a5 + add a4, a4, a5 + or a4, a4, t1 + #endif bne a4, t2, .Lnull\i .if \i+1-\n -- 2.34.1