yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 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, write to the Free |
| 19 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
| 20 | 02111-1307 USA. */ |
| 21 | |
| 22 | /* Normally, this uses ((xword - 0x01010101) & 0x80808080) test |
| 23 | to find out if any byte in xword could be zero. This is fast, but |
| 24 | also gives false alarm for any byte in range 0x81-0xff. It does |
| 25 | not matter for correctness, as if this test tells us there could |
| 26 | be some zero byte, we check it byte by byte, but if bytes with |
| 27 | high bits set are common in the strings, then this will give poor |
| 28 | performance. You can #define EIGHTBIT_NOT_RARE and the algorithm |
| 29 | will use one tick slower, but more precise test |
| 30 | ((xword - 0x01010101) & (~xword) & 0x80808080), |
| 31 | which does not give any false alarms (but if some bits are set, |
| 32 | one cannot assume from it which bytes are zero and which are not). |
| 33 | It is yet to be measured, what is the correct default for glibc |
| 34 | in these days for an average user. |
| 35 | */ |
| 36 | |
| 37 | .text |
| 38 | .align 4 |
| 39 | 10: ldub [%o0], %o4 |
| 40 | add %o0, 1, %o0 |
| 41 | ldub [%o1], %o5 |
| 42 | cmp %o4, 0 |
| 43 | add %o1, 1, %o1 |
| 44 | be 2f |
| 45 | subcc %o4, %o5, %o4 |
| 46 | bne 2f |
| 47 | andcc %o0, 3, %g0 |
| 48 | be 4f |
| 49 | or %g1, %lo(0x80808080), %o3 |
| 50 | ldub [%o0], %o4 |
| 51 | add %o0, 1, %o0 |
| 52 | ldub [%o1], %o5 |
| 53 | cmp %o4, 0 |
| 54 | add %o1, 1, %o1 |
| 55 | be 2f |
| 56 | subcc %o4, %o5, %o4 |
| 57 | bne 2f |
| 58 | andcc %o0, 3, %g0 |
| 59 | be 5f |
| 60 | sethi %hi(0x01010101), %g1 |
| 61 | ldub [%o0], %o4 |
| 62 | add %o0, 1, %o0 |
| 63 | ldub [%o1], %o5 |
| 64 | cmp %o4, 0 |
| 65 | add %o1, 1, %o1 |
| 66 | be 2f |
| 67 | subcc %o4, %o5, %o4 |
| 68 | bne 2f |
| 69 | andcc %o1, 3, %g2 |
| 70 | bne 12f |
| 71 | or %g1, %lo(0x01010101), %o2 |
| 72 | b 1f |
| 73 | ld [%o0], %o4 |
| 74 | 2: retl |
| 75 | mov %o4, %o0 |
| 76 | |
| 77 | ENTRY(strcmp) |
| 78 | andcc %o0, 3, %g0 |
| 79 | bne 10b |
| 80 | sethi %hi(0x80808080), %g1 |
| 81 | or %g1, %lo(0x80808080), %o3 |
| 82 | 4: sethi %hi(0x01010101), %g1 |
| 83 | 5: andcc %o1, 3, %g2 |
| 84 | bne 12f |
| 85 | or %g1, %lo(0x01010101), %o2 |
| 86 | |
| 87 | 0: ld [%o0], %o4 |
| 88 | 1: ld [%o1], %o5 |
| 89 | sub %o4, %o2, %g1 |
| 90 | add %o0, 4, %o0 |
| 91 | cmp %o4, %o5 |
| 92 | #ifdef EIGHTBIT_NOT_RARE |
| 93 | andn %g1, %o4, %g1 |
| 94 | #endif |
| 95 | bne 11f |
| 96 | andcc %g1, %o3, %g0 |
| 97 | be 0b |
| 98 | add %o1, 4, %o1 |
| 99 | |
| 100 | srl %o4, 24, %g4 |
| 101 | andcc %g4, 0xff, %g0 |
| 102 | be 2f |
| 103 | srl %o4, 16, %g4 |
| 104 | andcc %g4, 0xff, %g0 |
| 105 | be 2f |
| 106 | srl %o4, 8, %g4 |
| 107 | andcc %g4, 0xff, %g0 |
| 108 | be 2f |
| 109 | andcc %o4, 0xff, %g0 |
| 110 | bne,a 1b |
| 111 | ld [%o0], %o4 |
| 112 | 2: retl |
| 113 | clr %o0 |
| 114 | |
| 115 | 11: srl %o4, 24, %g4 |
| 116 | srl %o5, 24, %g5 |
| 117 | andcc %g4, 0xff, %g0 |
| 118 | be 3f |
| 119 | subcc %g4, %g5, %g4 |
| 120 | bne 3f |
| 121 | srl %o5, 16, %g5 |
| 122 | srl %o4, 16, %g4 |
| 123 | andcc %g4, 0xff, %g0 |
| 124 | be 3f |
| 125 | subcc %g4, %g5, %g4 |
| 126 | bne 3f |
| 127 | srl %o5, 8, %g5 |
| 128 | srl %o4, 8, %g4 |
| 129 | andcc %g4, 0xff, %g0 |
| 130 | be 3f |
| 131 | subcc %g4, %g5, %g4 |
| 132 | bne 3f |
| 133 | subcc %o4, %o5, %o4 |
| 134 | retl |
| 135 | mov %o4, %o0 |
| 136 | 3: retl |
| 137 | mov %g4, %o0 |
| 138 | |
| 139 | 12: save %sp, -64, %sp |
| 140 | ld [%i0], %i4 |
| 141 | sll %g2, 3, %g3 |
| 142 | andn %i1, 3, %i1 |
| 143 | mov 32, %l1 |
| 144 | ld [%i1], %l2 |
| 145 | mov -1, %g6 |
| 146 | add %i1, 4, %i1 |
| 147 | sub %l1, %g3, %l1 |
| 148 | sll %g6, %g3, %g6 |
| 149 | |
| 150 | 1: sll %l2, %g3, %g5 |
| 151 | and %i4, %g6, %l3 |
| 152 | sub %i4, %i2, %g1 |
| 153 | #ifdef EIGHTBIT_NOT_RARE |
| 154 | andn %g1, %i4, %g1 |
| 155 | #endif |
| 156 | andcc %g1, %i3, %g1 |
| 157 | bne 3f |
| 158 | cmp %g5, %l3 |
| 159 | bne 2f |
| 160 | add %i0, 4, %i0 |
| 161 | ld [%i1], %l2 |
| 162 | add %i1, 4, %i1 |
| 163 | srl %l2, %l1, %l4 |
| 164 | or %l4, %g5, %l4 |
| 165 | cmp %l4, %i4 |
| 166 | be,a 1b |
| 167 | ld [%i0], %i4 |
| 168 | restore %l4, %g0, %o3 |
| 169 | retl |
| 170 | sub %o4, %o3, %o0 |
| 171 | |
| 172 | 2: sll %l2, %g3, %i2 |
| 173 | srl %i4, %g3, %i3 |
| 174 | srl %i2, %g3, %i2 |
| 175 | restore |
| 176 | retl |
| 177 | sub %o3, %o2, %o0 |
| 178 | |
| 179 | 3: srl %i4, 24, %g4 |
| 180 | srl %g5, 24, %l6 |
| 181 | andcc %g4, 0xff, %g0 |
| 182 | be 4f |
| 183 | subcc %g4, %l6, %g4 |
| 184 | bne 4f |
| 185 | cmp %g2, 3 |
| 186 | be 6f |
| 187 | srl %i4, 16, %g4 |
| 188 | srl %g5, 16, %l6 |
| 189 | andcc %g4, 0xff, %g0 |
| 190 | be 4f |
| 191 | subcc %g4, %l6, %g4 |
| 192 | bne 4f |
| 193 | cmp %g2, 2 |
| 194 | be 5f |
| 195 | srl %i4, 8, %g4 |
| 196 | srl %g5, 8, %l6 |
| 197 | andcc %g4, 0xff, %g0 |
| 198 | be 4f |
| 199 | subcc %g4, %l6, %g4 |
| 200 | bne 4f |
| 201 | add %i0, 4, %i0 |
| 202 | ld [%i1], %l2 |
| 203 | add %i1, 4, %i1 |
| 204 | srl %l2, 24, %g5 |
| 205 | andcc %i4, 0xff, %g4 |
| 206 | be 4f |
| 207 | subcc %g4, %g5, %g4 |
| 208 | be,a 1b |
| 209 | ld [%i0], %i4 |
| 210 | 4: jmpl %i7 + 8, %g0 |
| 211 | restore %g4, %g0, %o0 |
| 212 | |
| 213 | 5: ld [%i1], %l2 |
| 214 | add %i1, 4, %i1 |
| 215 | add %i0, 4, %i0 |
| 216 | srl %l2, 24, %l6 |
| 217 | andcc %g4, 0xff, %g4 |
| 218 | be 4b |
| 219 | subcc %g4, %l6, %g4 |
| 220 | bne 4b |
| 221 | srl %l2, 16, %l6 |
| 222 | andcc %i4, 0xff, %g4 |
| 223 | and %l6, 0xff, %l6 |
| 224 | be 4b |
| 225 | subcc %g4, %l6, %g4 |
| 226 | be,a 1b |
| 227 | ld [%i0], %i4 |
| 228 | jmpl %i7 + 8, %g0 |
| 229 | restore %g4, %g0, %o0 |
| 230 | |
| 231 | 6: ld [%i1], %l2 |
| 232 | add %i1, 4, %i1 |
| 233 | add %i0, 4, %i0 |
| 234 | srl %l2, 24, %l6 |
| 235 | andcc %g4, 0xff, %g4 |
| 236 | be 4b |
| 237 | subcc %g4, %l6, %g4 |
| 238 | bne 4b |
| 239 | srl %l2, 16, %l6 |
| 240 | srl %i4, 8, %g4 |
| 241 | and %l6, 0xff, %l6 |
| 242 | andcc %g4, 0xff, %g4 |
| 243 | be 4b |
| 244 | subcc %g4, %l6, %g4 |
| 245 | bne 4b |
| 246 | srl %l2, 8, %l6 |
| 247 | andcc %i4, 0xff, %g4 |
| 248 | and %l6, 0xff, %l6 |
| 249 | be 4b |
| 250 | subcc %g4, %l6, %g4 |
| 251 | be,a 1b |
| 252 | ld [%i0], %i4 |
| 253 | jmpl %i7 + 8, %g0 |
| 254 | restore %g4, %g0, %o0 |
| 255 | END(strcmp) |
| 256 | libc_hidden_def(strcmp) |