1 /* Optimized strcasecmp implementation for PowerPC64.
2 Copyright (C) 2011 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
23 #include <locale-defines.h>
25 /* int [r3] strcasecmp (const char *s1 [r3], const char *s2 [r4] )
27 or if defined USE_IN_EXTENDED_LOCALE_MODEL:
29 int [r3] strcasecmp_l (const char *s1 [r3], const char *s2 [r4],
30 __locale_t loc [r5]) */
33 # define __STRCMP __strcasecmp
34 # define STRCMP strcasecmp
37 ENTRY (BP_SYM (__STRCMP))
40 #define rRTN r3 /* Return value */
41 #define rSTR1 r5 /* 1st string */
42 #define rSTR2 r4 /* 2nd string */
43 #define rLOCARG r5 /* 3rd argument: locale_t */
44 #define rCHAR1 r6 /* Byte readed from 1st string */
45 #define rCHAR2 r7 /* Byte readed from 2nd string */
46 #define rADDR1 r8 /* Address of tolower(rCHAR1) */
47 #define rADDR2 r12 /* Address of tolower(rCHAR2) */
48 #define rLWR1 r8 /* Word tolower(rCHAR1) */
49 #define rLWR2 r12 /* Word tolower(rCHAR2) */
51 #define rLOC r11 /* Default locale address */
54 #ifndef USE_IN_EXTENDED_LOCALE_MODEL
55 ld rTMP, __libc_tsd_LOCALE@got@tprel(r2)
56 add rLOC, rTMP, __libc_tsd_LOCALE@tls
61 ld rLOC, LOCALE_CTYPE_TOLOWER(rLOC)
67 /* Unrolling loop for POWER: loads are done with 'lbz' plus
68 offset and string descriptors are only updated in the end
71 lbz rCHAR1, 0(rSTR1) /* Load char from s1 */
72 lbz rCHAR2, 0(rSTR2) /* Load char from s2 */
74 cmpdi rCHAR1, 0 /* *s1 == '\0' ? */
75 sldi rADDR1, rCHAR1, 2 /* Calculate address for tolower(*s1) */
76 sldi rADDR2, rCHAR2, 2 /* Calculate address for tolower(*s2) */
77 lwzx rLWR1, rLOC, rADDR1 /* Load tolower(*s1) */
78 lwzx rLWR2, rLOC, rADDR2 /* Load tolower(*s2) */
79 cmpw cr1, rLWR1, rLWR2 /* r = tolower(*s1) == tolower(*s2) ? */
80 crorc 4*cr1+eq,eq,4*cr1+eq /* (*s1 != '\0') || (r == 1) */
85 sldi rADDR1, rCHAR1, 2
86 sldi rADDR2, rCHAR2, 2
87 lwzx rLWR1, rLOC, rADDR1
88 lwzx rLWR2, rLOC, rADDR2
89 cmpw cr1, rLWR1, rLWR2
90 crorc 4*cr1+eq,eq,4*cr1+eq
95 sldi rADDR1, rCHAR1, 2
96 sldi rADDR2, rCHAR2, 2
97 lwzx rLWR1, rLOC, rADDR1
98 lwzx rLWR2, rLOC, rADDR2
99 cmpw cr1, rLWR1, rLWR2
100 crorc 4*cr1+eq,eq,4*cr1+eq
105 /* Increment both string descriptors */
108 sldi rADDR1, rCHAR1, 2
109 sldi rADDR2, rCHAR2, 2
110 lwzx rLWR1, rLOC, rADDR1
111 lwzx rLWR2, rLOC, rADDR2
112 cmpw cr1, rLWR1, rLWR2
113 crorc 4*cr1+eq,eq,4*cr1+eq
115 lbz rCHAR1, 0(rSTR1) /* Load char from s1 */
116 lbz rCHAR2, 0(rSTR2) /* Load char from s2 */
119 subf r0, rLWR2, rLWR1
122 END (BP_SYM (__STRCMP))
124 weak_alias (BP_SYM (__STRCMP), BP_SYM (STRCMP))
125 libc_hidden_builtin_def (__STRCMP)