2 * strnlen - calculate the length of a string with limit.
4 * Copyright (c) 2020-2022, Arm Limited.
5 * SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
7 #if (defined (__OPTIMIZE_SIZE__) || defined (PREFER_SIZE_OVER_SPEED))
8 /* See strlen-stub.c */
13 * ARMv8-a, AArch64, Advanced SIMD.
37 Process the string in 16-byte aligned chunks. Compute a 64-bit mask with
38 four bits per byte using the shrn instruction. A count trailing zeros then
39 identifies the first zero byte. */
46 ld1 {vdata.16b}, [src]
47 cmeq vhas_chr.16b, vdata.16b, 0
49 shrn vend.8b, vhas_chr.8h, 4 /* 128->64 */
52 cbz synd, L(start_loop)
58 csel result, cntin, result, ls
68 subs cntrem, cntin, tmp
71 /* Make sure that it won't overread by a 16-byte chunk */
72 tbz cntrem, 4, L(loop32_2)
77 cmeq vhas_chr.16b, vdata.16b, 0
78 umaxp vend.16b, vhas_chr.16b, vhas_chr.16b /* 128->64 */
83 subs cntrem, cntrem, 32
84 cmeq vhas_chr.16b, vdata.16b, 0
86 umaxp vend.16b, vhas_chr.16b, vhas_chr.16b /* 128->64 */
92 shrn vend.8b, vhas_chr.8h, 4 /* 128->64 */
93 sub result, src, srcin
99 add result, result, synd, lsr 2
101 csel result, cntin, result, ls