1 /* Optimized strcmp implementation for PowerPC.
2 Copyright (C) 1997, 1999, 2000 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 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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24 /* See strlen.s for comments on how the end-of-string testing works. */
26 /* int [r3] strcmp (const char *s1 [r3], const char *s2 [r4]) */
28 EALIGN (BP_SYM (strcmp), 4, 0)
32 #define rSTR1 r3 /* first string arg */
33 #define rSTR2 r4 /* second string arg */
34 #if __BOUNDED_POINTERS__
38 #define rWORD1 r5 /* current word in s1 */
39 #define rWORD2 r6 /* current word in s2 */
40 #define rFEFE r7 /* constant 0xfefefeff (-0x01010101) */
41 #define r7F7F r8 /* constant 0x7f7f7f7f */
42 #define rNEG r9 /* ~(word in s1 | 0x7f7f7f7f) */
43 #define rBITDIF r10 /* bits that differ in s1 & s2 words */
45 CHECK_BOUNDS_LOW (rSTR1, rTMP, rHIGH1)
46 CHECK_BOUNDS_LOW (rSTR2, rTMP, rHIGH2)
49 clrlwi. rTMP, rTMP, 30
56 addi rFEFE, rFEFE, -0x101
57 addi r7F7F, r7F7F, 0x7f7f
60 L(g0): lwzu rWORD1, 4(rSTR1)
63 L(g1): add rTMP, rFEFE, rWORD1
64 nor rNEG, r7F7F, rWORD1
66 cmpw cr1, rWORD1, rWORD2
69 /* OK. We've hit the end of the string. We need to be careful that
70 we don't compare two strings as different because of gunk beyond
71 the end of the strings... */
72 and rTMP, r7F7F, rWORD1
75 xor. rBITDIF, rWORD1, rWORD2
78 cntlzw rBITDIF, rBITDIF
81 cmpw cr1, rNEG, rBITDIF
82 sub rRTN, rWORD1, rWORD2
86 /* GKM FIXME: check high bounds. */
91 xor. rBITDIF, rWORD1, rWORD2
92 sub rRTN, rWORD1, rWORD2
96 /* GKM FIXME: check high bounds. */
100 /* Oh well. In this case, we just do a byte-by-byte comparison. */
107 L(u0): lbzu rWORD1, 1(rSTR1)
109 lbzu rWORD2, 1(rSTR2)
110 L(u1): cmpwi cr1, rWORD1, 0
114 lbzu rWORD1, 1(rSTR1)
115 lbzu rWORD2, 1(rSTR2)
119 L(u3): sub rRTN, rWORD1, rWORD2
120 /* GKM FIXME: check high bounds. */
122 L(u4): lbz rWORD1, -1(rSTR1)
123 sub rRTN, rWORD1, rWORD2
124 /* GKM FIXME: check high bounds. */
126 END (BP_SYM (strcmp))