1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <linux/linkage.h>
5 #include <asm/alternative-macros.h>
8 /* int strncmp(const char *cs, const char *ct, size_t count) */
9 SYM_FUNC_START(strncmp)
11 ALTERNATIVE("nop", "j strncmp_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
15 * a0 - comparison result, value like strncmp
20 * a2 - number of characters to compare
40 * strncmp only needs to return (< 0, 0, > 0) values
41 * not necessarily -1, 0, +1
47 * Variant of strncmp using the ZBB extension if available
49 #ifdef CONFIG_RISCV_ISA_ZBB
57 * a0 - comparison result, like strncmp
62 * a2 - number of characters to compare
65 * t0, t1, t2, t3, t4, t5, t6
74 /* Adjust limit for fast-path. */
77 /* Main loop for aligned string. */
92 * Words don't match, and no null byte in the first
93 * word. Get bytes in big-endian order and compare.
95 #ifndef CONFIG_CPU_BIG_ENDIAN
100 /* Synthesize (t0 >= t1) ? 1 : -1 in a branchless sequence. */
109 * If words don't match, fall back to simple loop.
113 /* Otherwise, strings are equal. */
117 /* Simple loop for misaligned strings. */
138 SYM_FUNC_END(strncmp)
139 SYM_FUNC_ALIAS(__pi_strncmp, strncmp)
140 EXPORT_SYMBOL(strncmp)