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

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