1/* Determine the length of a string.
2 For SPARC v7.
3 Copyright (C) 1996-2024 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
19
20#include <sysdep.h>
21
22 .text
23 .align 4
24
25ENTRY(strlen)
26 mov %o0, %o1
27 andn %o0, 0x3, %o0
28
29 ld [%o0], %o5
30 and %o1, 0x3, %g1
31 mov -1, %g5
32
33 sethi %hi(0x01010101), %o2
34 sll %g1, 3, %g1
35
36 or %o2, %lo(0x01010101), %o2
37 srl %g5, %g1, %g2
38
39 orn %o5, %g2, %o5
40 sll %o2, 7, %o3
4110: add %o0, 4, %o0
42
43 andn %o3, %o5, %g1
44 sub %o5, %o2, %g2
45
46 andcc %g1, %g2, %g0
47 be,a 10b
48 ld [%o0], %o5
49
50 srl %o5, 24, %g1
51
52 andcc %g1, 0xff, %g0
53 be 90f
54 sub %o0, 4, %o0
55
56 srl %o5, 16, %g2
57
58 andcc %g2, 0xff, %g0
59 be 90f
60 add %o0, 1, %o0
61
62 srl %o5, 8, %g1
63
64 andcc %g1, 0xff, %g0
65 be 90f
66 add %o0, 1, %o0
67
68 add %o0, 1, %o0
69
7090: retl
71 sub %o0, %o1, %o0
72END(strlen)
73libc_hidden_builtin_def (strlen)
74

source code of glibc/sysdeps/sparc/sparc32/strlen.S