1 /* Optimized strcmp implementation for PowerPC64.
2 Copyright (C) 2003 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] strncmp (const char *s1 [r3], const char *s2 [r4], size_t size [r5]) */
28 EALIGN (BP_SYM(strncmp), 4, 0)
33 #define rSTR1 r3 /* first string arg */
34 #define rSTR2 r4 /* second string arg */
35 #define rN r5 /* max string length */
36 /* Note: The Bounded pointer support in this code is broken. This code
37 was inherited from PPC32 and and that support was never completed.
38 Current PPC gcc does not support -fbounds-check or -fbounded-pointers. */
39 #define rWORD1 r6 /* current word in s1 */
40 #define rWORD2 r7 /* current word in s2 */
41 #define rFEFE r8 /* constant 0xfefefefefefefeff (-0x0101010101010101) */
42 #define r7F7F r9 /* constant 0x7f7f7f7f7f7f7f7f */
43 #define rNEG r10 /* ~(word in s1 | 0x7f7f7f7f7f7f7f7f) */
44 #define rBITDIF r11 /* bits that differ in s1 & s2 words */
50 clrldi. rTMP, rTMP, 61
53 /* We are doubleword alligned so set up for two loops. first a double word
54 loop, then fall into the byte loop if any residual. */
57 addi rFEFE, rFEFE, -0x101
58 addi r7F7F, r7F7F, 0x7f7f
61 mtctr rTMP /* Power4 wants mtctr 1st in dispatch group. */
65 insrdi r7F7F, r7F7F, 32, 0
66 add rFEFE, rFEFE, rTMP
71 bne- cr1, L(different)
73 L(g1): add rTMP, rFEFE, rWORD1
74 nor rNEG, r7F7F, rWORD1
77 cmpd cr1, rWORD1, rWORD2
80 /* OK. We've hit the end of the string. We need to be careful that
81 we don't compare two strings as different because of gunk beyond
82 the end of the strings... */
85 and rTMP, r7F7F, rWORD1
88 xor. rBITDIF, rWORD1, rWORD2
92 cntlzd rBITDIF, rBITDIF
95 cmpd cr1, rNEG, rBITDIF
96 sub rRTN, rWORD1, rWORD2
106 ldu rWORD1, -8(rSTR1)
107 xor. rBITDIF, rWORD1, rWORD2
108 sub rRTN, rWORD1, rWORD2
114 srdi rWORD2, rWORD2, 56
115 srdi rWORD1, rWORD1, 56
116 sub rRTN, rWORD1, rWORD2
120 /* Oh well. In this case, we just do a byte-by-byte comparison. */
123 and. rTMP, rTMP, rNEG
124 cmpd cr1, rWORD1, rWORD2
127 bne- cr1, L(different)
130 mtctr rN /* Power4 wants mtctr 1st in dispatch group */
140 lbzu rWORD2, 1(rSTR2)
146 lbzu rWORD1, 1(rSTR1)
148 lbzu rWORD2, 1(rSTR2)
153 lbzu rWORD1, 1(rSTR1)
156 L(u2): lbzu rWORD1, -1(rSTR1)
157 L(u3): sub rRTN, rWORD1, rWORD2
159 END (BP_SYM (strncmp))
160 libc_hidden_builtin_def (strncmp)