]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/powerpc/powerpc32/405/memcmp.S
b5314a0c53b55c793714c3191900d264c24874d2
[thirdparty/glibc.git] / sysdeps / powerpc / powerpc32 / 405 / memcmp.S
1 /* Optimized memcmp implementation for PowerPC476.
2 Copyright (C) 2010-2019 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 <http://www.gnu.org/licenses/>. */
18
19 #include <sysdep.h>
20
21 /* memcmp
22
23 r3:source1 address, return equality
24 r4:source2 address
25 r5:byte count
26
27 Check 2 words from src1 and src2. If unequal jump to end and
28 return src1 > src2 or src1 < src2.
29 If count = zero check bytes before zero counter and then jump to end and
30 return src1 > src2, src1 < src2 or src1 = src2.
31 If src1 = src2 and no null, repeat. */
32
33 EALIGN (memcmp, 5, 0)
34 srwi. r6,r5,5
35 beq L(preword2_count_loop)
36 mtctr r6
37 clrlwi r5,r5,27
38
39 L(word8_compare_loop):
40 lwz r10,0(r3)
41 lwz r6,4(r3)
42 lwz r8,0(r4)
43 lwz r9,4(r4)
44 cmplw cr5,r8,r10
45 cmplw cr1,r9,r6
46 bne cr5,L(st2)
47 bne cr1,L(st1)
48 lwz r10,8(r3)
49 lwz r6,12(r3)
50 lwz r8,8(r4)
51 lwz r9,12(r4)
52 cmplw cr5,r8,r10
53 cmplw cr1,r9,r6
54 bne cr5,L(st2)
55 bne cr1,L(st1)
56 lwz r10,16(r3)
57 lwz r6,20(r3)
58 lwz r8,16(r4)
59 lwz r9,20(r4)
60 cmplw cr5,r8,r10
61 cmplw cr1,r9,r6
62 bne cr5,L(st2)
63 bne cr1,L(st1)
64 lwz r10,24(r3)
65 lwz r6,28(r3)
66 addi r3,r3,0x20
67 lwz r8,24(r4)
68 lwz r9,28(r4)
69 addi r4,r4,0x20
70 cmplw cr5,r8,r10
71 cmplw cr1,r9,r6
72 bne cr5,L(st2)
73 bne cr1,L(st1)
74 bdnz L(word8_compare_loop)
75
76 L(preword2_count_loop):
77 srwi. r6,r5,3
78 beq L(prebyte_count_loop)
79 mtctr r6
80 clrlwi r5,r5,29
81
82 L(word2_count_loop):
83 lwz r10,0(r3)
84 lwz r6,4(r3)
85 addi r3,r3,0x08
86 lwz r8,0(r4)
87 lwz r9,4(r4)
88 addi r4,r4,0x08
89 cmplw cr5,r8,r10
90 cmplw cr1,r9,r6
91 bne cr5,L(st2)
92 bne cr1,L(st1)
93 bdnz L(word2_count_loop)
94
95 L(prebyte_count_loop):
96 addi r5,r5,1
97 mtctr r5
98 bdz L(end_memcmp)
99
100 L(byte_count_loop):
101 lbz r6,0(r3)
102 addi r3,r3,0x01
103 lbz r8,0(r4)
104 addi r4,r4,0x01
105 cmplw cr5,r8,r6
106 bne cr5,L(st2)
107 bdnz L(byte_count_loop)
108
109 L(end_memcmp):
110 addi r3,r0,0
111 blr
112
113 L(l_r):
114 addi r3,r0,1
115 blr
116
117 L(st1):
118 blt cr1,L(l_r)
119 addi r3,r0,-1
120 blr
121
122 L(st2):
123 blt cr5,L(l_r)
124 addi r3,r0,-1
125 blr
126 END (memcmp)
127 libc_hidden_builtin_def (memcmp)
128 weak_alias (memcmp,bcmp)