1/* Optimized strcmp implementation for PowerPC476.
2 Copyright (C) 2010-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/* strcmp
22
23 Register Use
24 r0:temp return equality
25 r3:source1 address, return equality
26 r4:source2 address
27
28 Implementation description
29 Check 2 words from src1 and src2. If unequal jump to end and
30 return src1 > src2 or src1 < src2.
31 If null check bytes before null and then jump to end and
32 return src1 > src2, src1 < src2 or src1 = src2.
33 If src1 = src2 and no null, repeat. */
34
35EALIGN (strcmp,5,0)
36 neg r7,r3
37 clrlwi r7,r7,20
38 neg r8,r4
39 clrlwi r8,r8,20
40 srwi. r7,r7,5
41 beq L(byte_loop)
42 srwi. r8,r8,5
43 beq L(byte_loop)
44 cmplw r7,r8
45 mtctr r7
46 ble L(big_loop)
47 mtctr r8
48
49L(big_loop):
50 lwz r5,0(r3)
51 lwz r6,4(r3)
52 lwz r8,0(r4)
53 lwz r9,4(r4)
54 dlmzb. r12,r5,r6
55 bne L(end_check)
56 cmplw r5,r8
57 bne L(st1)
58 cmplw r6,r9
59 bne L(st1)
60 lwz r5,8(r3)
61 lwz r6,12(r3)
62 lwz r8,8(r4)
63 lwz r9,12(r4)
64 dlmzb. r12,r5,r6
65 bne L(end_check)
66 cmplw r5,r8
67 bne L(st1)
68 cmplw r6,r9
69 bne L(st1)
70 lwz r5,16(r3)
71 lwz r6,20(r3)
72 lwz r8,16(r4)
73 lwz r9,20(r4)
74 dlmzb. r12,r5,r6
75 bne L(end_check)
76 cmplw r5,r8
77 bne L(st1)
78 cmplw r6,r9
79 bne L(st1)
80 lwz r5,24(r3)
81 lwz r6,28(r3)
82 addi r3,r3,0x20
83 lwz r8,24(r4)
84 lwz r9,28(r4)
85 addi r4,r4,0x20
86 dlmzb. r12,r5,r6
87 bne L(end_check)
88 cmplw r5,r8
89 bne L(st1)
90 cmplw r6,r9
91 bne L(st1)
92 bdnz L(big_loop)
93 b L(byte_loop)
94
95L(end_check):
96 subfic r12,r12,4
97 blt L(end_check2)
98 rlwinm r12,r12,3,0,31
99 srw r5,r5,r12
100 srw r8,r8,r12
101 cmplw r5,r8
102 bne L(st1)
103 b L(end_strcmp)
104
105L(end_check2):
106 addi r12,r12,4
107 cmplw r5,r8
108 rlwinm r12,r12,3,0,31
109 bne L(st1)
110 srw r6,r6,r12
111 srw r9,r9,r12
112 cmplw r6,r9
113 bne L(st1)
114
115L(end_strcmp):
116 addi r3,r0,0
117 blr
118
119L(st1):
120 mfcr r3
121 blr
122
123L(byte_loop):
124 lbz r5,0(r3)
125 addi r3,r3,1
126 lbz r6,0(r4)
127 addi r4,r4,1
128 cmplw r5,r6
129 bne L(st1)
130 cmpwi r5,0
131 beq L(end_strcmp)
132 b L(byte_loop)
133END (strcmp)
134libc_hidden_builtin_def (strcmp)
135

source code of glibc/sysdeps/powerpc/powerpc32/405/strcmp.S