1 /* Compare two strings for differences.
3 Copyright (C) 1996-2023 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
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.
43 sethi %hi(0x80808080), %g1
55 or %g1, %lo(0x80808080), %o3
66 sethi %hi(0x01010101), %g1
77 or %g1, %lo(0x01010101), %o2
83 13: or %g1, %lo(0x80808080), %o3
84 4: sethi %hi(0x01010101), %g1
87 or %g1, %lo(0x01010101), %o2
94 #ifdef EIGHTBIT_NOT_RARE
141 12: save %sp, -64, %sp
155 #ifdef EIGHTBIT_NOT_RARE
170 restore %l4, %g0, %o3
213 restore %g4, %g0, %o0
231 restore %g4, %g0, %o0
256 restore %g4, %g0, %o0
258 libc_hidden_builtin_def (strcmp)