1/* Compare two strings for differences. 2 For SPARC v7. 3 Copyright (C) 1996, 97, 99, 2003 Free Software Foundation, Inc. 4 This file is part of the GNU C Library. 5 Contributed by Jakub Jelinek <jj@ultra.linux.cz>. 6 7 The GNU C Library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 The GNU C Library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with the GNU C Library; if not, see 19 <http://www.gnu.org/licenses/>. */ 20 21 /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test 22 to find out if any byte in xword could be zero. This is fast, but 23 also gives false alarm for any byte in range 0x81-0xff. It does 24 not matter for correctness, as if this test tells us there could 25 be some zero byte, we check it byte by byte, but if bytes with 26 high bits set are common in the strings, then this will give poor 27 performance. You can #define EIGHTBIT_NOT_RARE and the algorithm 28 will use one tick slower, but more precise test 29 ((xword - 0x01010101) & (~xword) & 0x80808080), 30 which does not give any false alarms (but if some bits are set, 31 one cannot assume from it which bytes are zero and which are not). 32 It is yet to be measured, what is the correct default for glibc 33 in these days for an average user. 34 */ 35 36 .text 37 .align 4 3810: ldub [%o0], %o4 39 add %o0, 1, %o0 40 ldub [%o1], %o5 41 cmp %o4, 0 42 add %o1, 1, %o1 43 be 2f 44 subcc %o4, %o5, %o4 45 bne 2f 46 andcc %o0, 3, %g0 47 be 4f 48 or %g1, %lo(0x80808080), %o3 49 ldub [%o0], %o4 50 add %o0, 1, %o0 51 ldub [%o1], %o5 52 cmp %o4, 0 53 add %o1, 1, %o1 54 be 2f 55 subcc %o4, %o5, %o4 56 bne 2f 57 andcc %o0, 3, %g0 58 be 5f 59 sethi %hi(0x01010101), %g1 60 ldub [%o0], %o4 61 add %o0, 1, %o0 62 ldub [%o1], %o5 63 cmp %o4, 0 64 add %o1, 1, %o1 65 be 2f 66 subcc %o4, %o5, %o4 67 bne 2f 68 andcc %o1, 3, %g2 69 bne 12f 70 or %g1, %lo(0x01010101), %o2 71 b 1f 72 ld [%o0], %o4 732: retl 74 mov %o4, %o0 75 76ENTRY(strcmp) 77 andcc %o0, 3, %g0 78 bne 10b 79 sethi %hi(0x80808080), %g1 80 or %g1, %lo(0x80808080), %o3 814: sethi %hi(0x01010101), %g1 825: andcc %o1, 3, %g2 83 bne 12f 84 or %g1, %lo(0x01010101), %o2 85 860: ld [%o0], %o4 871: ld [%o1], %o5 88 sub %o4, %o2, %g1 89 add %o0, 4, %o0 90 cmp %o4, %o5 91#ifdef EIGHTBIT_NOT_RARE 92 andn %g1, %o4, %g1 93#endif 94 bne 11f 95 andcc %g1, %o3, %g0 96 be 0b 97 add %o1, 4, %o1 98 99 srl %o4, 24, %g4 100 andcc %g4, 0xff, %g0 101 be 2f 102 srl %o4, 16, %g4 103 andcc %g4, 0xff, %g0 104 be 2f 105 srl %o4, 8, %g4 106 andcc %g4, 0xff, %g0 107 be 2f 108 andcc %o4, 0xff, %g0 109 bne,a 1b 110 ld [%o0], %o4 1112: retl 112 clr %o0 113 11411: srl %o4, 24, %g4 115 srl %o5, 24, %g5 116 andcc %g4, 0xff, %g0 117 be 3f 118 subcc %g4, %g5, %g4 119 bne 3f 120 srl %o5, 16, %g5 121 srl %o4, 16, %g4 122 andcc %g4, 0xff, %g0 123 be 3f 124 subcc %g4, %g5, %g4 125 bne 3f 126 srl %o5, 8, %g5 127 srl %o4, 8, %g4 128 andcc %g4, 0xff, %g0 129 be 3f 130 subcc %g4, %g5, %g4 131 bne 3f 132 subcc %o4, %o5, %o4 133 retl 134 mov %o4, %o0 1353: retl 136 mov %g4, %o0 137 13812: save %sp, -64, %sp 139 ld [%i0], %i4 140 sll %g2, 3, %g3 141 andn %i1, 3, %i1 142 mov 32, %l1 143 ld [%i1], %l2 144 mov -1, %g6 145 add %i1, 4, %i1 146 sub %l1, %g3, %l1 147 sll %g6, %g3, %g6 148 1491: sll %l2, %g3, %g5 150 and %i4, %g6, %l3 151 sub %i4, %i2, %g1 152#ifdef EIGHTBIT_NOT_RARE 153 andn %g1, %i4, %g1 154#endif 155 andcc %g1, %i3, %g1 156 bne 3f 157 cmp %g5, %l3 158 bne 2f 159 add %i0, 4, %i0 160 ld [%i1], %l2 161 add %i1, 4, %i1 162 srl %l2, %l1, %l4 163 or %l4, %g5, %l4 164 cmp %l4, %i4 165 be,a 1b 166 ld [%i0], %i4 167 restore %l4, %g0, %o3 168 retl 169 sub %o4, %o3, %o0 170 1712: sll %l2, %g3, %i2 172 srl %i4, %g3, %i3 173 srl %i2, %g3, %i2 174 restore 175 retl 176 sub %o3, %o2, %o0 177 1783: srl %i4, 24, %g4 179 srl %g5, 24, %l6 180 andcc %g4, 0xff, %g0 181 be 4f 182 subcc %g4, %l6, %g4 183 bne 4f 184 cmp %g2, 3 185 be 6f 186 srl %i4, 16, %g4 187 srl %g5, 16, %l6 188 andcc %g4, 0xff, %g0 189 be 4f 190 subcc %g4, %l6, %g4 191 bne 4f 192 cmp %g2, 2 193 be 5f 194 srl %i4, 8, %g4 195 srl %g5, 8, %l6 196 andcc %g4, 0xff, %g0 197 be 4f 198 subcc %g4, %l6, %g4 199 bne 4f 200 add %i0, 4, %i0 201 ld [%i1], %l2 202 add %i1, 4, %i1 203 srl %l2, 24, %g5 204 andcc %i4, 0xff, %g4 205 be 4f 206 subcc %g4, %g5, %g4 207 be,a 1b 208 ld [%i0], %i4 2094: jmpl %i7 + 8, %g0 210 restore %g4, %g0, %o0 211 2125: ld [%i1], %l2 213 add %i1, 4, %i1 214 add %i0, 4, %i0 215 srl %l2, 24, %l6 216 andcc %g4, 0xff, %g4 217 be 4b 218 subcc %g4, %l6, %g4 219 bne 4b 220 srl %l2, 16, %l6 221 andcc %i4, 0xff, %g4 222 and %l6, 0xff, %l6 223 be 4b 224 subcc %g4, %l6, %g4 225 be,a 1b 226 ld [%i0], %i4 227 jmpl %i7 + 8, %g0 228 restore %g4, %g0, %o0 229 2306: ld [%i1], %l2 231 add %i1, 4, %i1 232 add %i0, 4, %i0 233 srl %l2, 24, %l6 234 andcc %g4, 0xff, %g4 235 be 4b 236 subcc %g4, %l6, %g4 237 bne 4b 238 srl %l2, 16, %l6 239 srl %i4, 8, %g4 240 and %l6, 0xff, %l6 241 andcc %g4, 0xff, %g4 242 be 4b 243 subcc %g4, %l6, %g4 244 bne 4b 245 srl %l2, 8, %l6 246 andcc %i4, 0xff, %g4 247 and %l6, 0xff, %l6 248 be 4b 249 subcc %g4, %l6, %g4 250 be,a 1b 251 ld [%i0], %i4 252 jmpl %i7 + 8, %g0 253 restore %g4, %g0, %o0 254END(strcmp) 255libc_hidden_def(strcmp) 256