2 Copyright (c) 2013 Andes Technology Corporation.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
8 Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
11 Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in the
13 documentation and/or other materials provided with the distribution.
15 The name of the company may not be used to endorse or promote
16 products derived from this software without specific prior written
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 DISCLAIMED. IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
23 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 strcmp - compare two strings.
34 int strcmp(const char *s1, const char *s2);
36 This function compares the two strings s1 and s2. It returns an
37 integer less than, equal to, or greater than zero if s1 is found,
38 respectively, to be less than, to match, or be greater than s2.
40 strcmp returns an integer less than, equal to, or greater than
41 zero if s1 (or the first n bytes thereof) is found, respectively,
42 to be less than, to match, or be greater than s2.
47 .type strcmp, @function
49 /* If s1 or s2 are unaligned, then compare bytes. */
54 /* If s1 and s2 are word-aligned, compare them a word at a time. */
57 bne $r5, $r3, .Lbyte_mode /* A difference was detected, so
60 /* It's more efficient to set bit mask outside the word_mode loop. */
61 sethi $r4, hi20(0xFEFEFEFF) /* Set $r4 as -0x01010101. */
62 ori $r4, $r4, lo12(0xFEFEFEFF)
63 sethi $r2, hi20(0x80808080)
64 ori $r2, $r2, lo12(0x80808080)
69 lmw.aim $r5, [$r0], $r5
70 lmw.aim $r3, [$r1], $r3
71 bne $r5, $r3, .Lbyte_mode
74 /* #define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
75 DETECTNULL returns nonzero if (long)X contains a NULL byte. */
76 nor $r3, $r5, $r5 /* r3 = ~(X) */
77 add $r5, $r5, $r4 /* r2 = ((X) - 0x01010101) */
78 and $r5, $r5, $r3 /* r2 = ~(X) & ((X) - 0x01010101) */
79 and $r5, $r5, $r2 /* r2= r2 & 0x80808080 */
80 beqz $r5, .Lword_mode /* No NULL byte, compare next word. */
82 /* To get here, *a1 == *a2, thus if we find a null in *a1,
83 then the strings must be equal, so return zero. */
88 /* Byte-mode compare. */
91 bne $r5, $r3, 1f /* Mismatch, done. */
96 .size strcmp, .-strcmp