Update.
[glibc.git] / sysdeps / powerpc / strcmp.S
blob9f4d13441991e31ba718bb0f135bf90eb1a40198
1 /* Optimized strcmp implementation for PowerPC.
2    Copyright (C) 1997 Free Software Foundation, Inc.
3    This file is part of the GNU C Library.
5    The GNU C Library is free software; you can redistribute it and/or
6    modify it under the terms of the GNU Library General Public License as
7    published by the Free Software Foundation; either version 2 of the
8    License, or (at your option) any later version.
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    Library General Public License for more details.
15    You should have received a copy of the GNU Library General Public
16    License along with the GNU C Library; see the file COPYING.LIB.  If not,
17    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18    Boston, MA 02111-1307, USA.  */
20 #include <sysdep.h>
22 /* See strlen.s for comments on how the end-of-string testing works.  */
24 EALIGN(strcmp,4,0)
25 /* int [r3] strcmp (const char *p1 [r3], const char *p2 [r4])  */
27 /* General register assignments:
28    r0:  temporary
29    r3:  pointer to previous word in s1
30    r4:  pointer to previous word in s2
31    r5:  current word from s1
32    r6:  current word from s2
33    r7:  0xfefefeff
34    r8:  0x7f7f7f7f
35    r9:  ~(word in s1 | 0x7f7f7f7f)  */
37 /* Register assignments in the prologue:
38    r10: low 2 bits of p2-p1
39    r11: mask to orc with r5/r6  */
41         or    %r0,%r4,%r3
42         clrlwi. %r0,%r0,30
43         lis   %r7,0xfeff
44         bne   L(unaligned)
46         lwz   %r5,0(%r3)
47         lwz   %r6,0(%r4)
48         lis   %r8,0x7f7f
49         addi  %r7,%r7,-0x101
50         addi  %r8,%r8,0x7f7f
51         b     1f
53 0:      lwzu  %r5,4(%r3)
54         bne   %cr1,L(different)
55         lwzu  %r6,4(%r4)
56 1:      add   %r0,%r7,%r5
57         nor   %r9,%r8,%r5
58         and.  %r0,%r0,%r9
59         cmpw  %cr1,%r5,%r6
60         beq+  0b
61 L(endstring):
62 /* OK. We've hit the end of the string. We need to be careful that
63    we don't compare two strings as different because of gunk beyond
64    the end of the strings...  */
65         and   %r0,%r8,%r5
66         beq   %cr1,L(equal)
67         add   %r0,%r0,%r8
68         xor.  %r10,%r5,%r6
69         andc  %r9,%r9,%r0
70         blt-  L(highbit)
71         cntlzw %r10,%r10
72         cntlzw %r9,%r9
73         addi  %r9,%r9,7
74         cmpw  %cr1,%r9,%r10
75         sub   %r3,%r5,%r6
76         bgelr+ %cr1
77 L(equal):
78         li    %r3,0
79         blr
81 L(different):
82         lwz   %r5,-4(%r3)
83         xor.  %r10,%r5,%r6
84         sub   %r3,%r5,%r6
85         bgelr+
86 L(highbit):
87         mr    %r3,%r6
88         blr
91 /* Oh well.  In this case, we just do a byte-by-byte comparison.  */
92         .align 4
93 L(unaligned):
94         lbz   %r5,0(%r3)
95         lbz   %r6,0(%r4)
96         b     1f
98 0:      lbzu  %r5,1(%r3)
99         bne-  4f
100         lbzu  %r6,1(%r4)
101 1:      cmpwi %cr1,%r5,0
102         beq-  %cr1,3f
103         cmpw  %r5,%r6
104         bne-  3f
105         lbzu  %r5,1(%r3)
106         lbzu  %r6,1(%r4)
107         cmpwi %cr1,%r5,0
108         cmpw  %r5,%r6
109         bne+  %cr1,0b
110 3:      sub   %r3,%r5,%r6
111         blr
112 4:      lbz   %r5,-1(%r3)
113         sub   %r3,%r5,%r6
114         blr
115 END(strcmp)