1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <linux/linkage.h>
5 #include <asm/alternative-macros.h>
8 /* int strlen(const char *s) */
11 ALTERNATIVE("nop", "j strlen_zbb", 0, RISCV_ISA_EXT_ZBB, CONFIG_RISCV_ISA_ZBB)
18 * a0 - String to measure
34 * Variant of strlen using the ZBB extension if available
36 #ifdef CONFIG_RISCV_ISA_ZBB
39 #ifdef CONFIG_CPU_BIG_ENDIAN
55 * a0 - String to measure
61 /* Number of irrelevant bytes in the first word. */
71 /* Get the first word. */
75 * Shift away the partial data we loaded to remove the irrelevant bytes
76 * preceding the string with the effect of adding NUL bytes at the
77 * end of the string's first word.
81 /* Convert non-NUL into 0xff and NUL into 0x00. */
84 /* Convert non-NUL into 0x00 and NUL into 0xff. */
88 * Search for the first set bit (corresponding to a NUL byte in the
94 * The first chunk is special: compare against the number
95 * of valid bytes in this chunk.
100 /* Prepare for the word comparison loop. */
105 * Our critical loop is 4 instructions and processes data in
106 * 4 byte or 8 byte chunks.
119 /* Get number of processed bytes. */
122 /* Add number of characters in the first word. */
125 /* Add number of characters in the last word. */
133 SYM_FUNC_ALIAS(__pi_strlen, strlen)
134 EXPORT_SYMBOL(strlen)