Path: blob/main/lib/libc/aarch64/string/strcspn.S
103835 views
/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (c) 2024 Getz Mikalsen <[email protected]>4*/56#include <machine/asm.h>78.weak strcspn9.set strcspn, __strcspn10.text1112ENTRY(__strcspn)13stp x29, x30, [sp, #-16]!14mov x29, sp15mov x15, #1 // preload register with 1 for stores1617/* check for special cases */18ldrb w4, [x1] // first character in the set19cbz w4, .Lstrlen2021movi v0.16b, #02223ldrb w5, [x1, #1] // second character in the set24cbz w5, .Lstrchr2526sub sp, sp, #256 // allocate 256 bytes on the stack2728/* no special case matches -- prepare lookup table */29mov w3, #2030.p2align 4310: add x9, sp, x3, lsl #332stp xzr, xzr, [x9]33stp xzr, xzr, [x9, #16]34subs w3, w3, #435b.cs 0b3637/* utilize SIMD stores to speed up zeroing the table */38stp q0, q0, [sp, #6*32]39stp q0, q0, [sp, #7*32]4041add x1, x1, #242strb w15, [sp, x4] // register first chars in the set43strb w15, [sp, x5]4445mov x4, x0 // stash a copy of src4647/* process remaining chars in set */48.p2align 4490: ldrb w5, [x1]50strb w15, [sp, x5]51cbz w5, 1f // end of set?5253ldrb w5, [x1, #1]54strb w15, [sp, x5]55cbz w5, 1f5657add x1, x1, #258b 0b5960/* find match */61.p2align 4621: ldrb w8, [x0]63ldrb w9, [sp, x8]64cbnz w9, 2f6566ldrb w8, [x0, #1]67ldrb w9, [sp, x8]68cbnz w9, 3f6970ldrb w8, [x0, #2]71ldrb w9, [sp, x8]72cbnz w9, 4f7374ldrb w8, [x0, #3]75ldrb w9, [sp, x8]76add x0, x0, #477cbz w9, 1b7879sub x0, x0, #3 // fix up return value804: sub x4, x4, #1813: add x0, x0, #1822: sub x0, x0, x483mov sp, x2984ldp x29, x30, [sp], #16 // restore sp and lr85ret8687/* set is empty, degrades to strlen */88.p2align 489.Lstrlen:90mov sp, x2991ldp x29, x30, [sp], #16 // restore sp and lr92b strlen9394/* just one character in set, degrades to strchrnul */95.p2align 496.Lstrchr:97stp x0, x1, [sp, #-16]!98mov x1, x499100bl strchrnul101102ldp x18, x17, [sp], #16 // restore stashed src103sub x0, x0, x18104105ldp x29, x30, [sp], #16 // Restore sp and lr106ret107108END(__strcspn)109110111