2 * Copyright (c) 2011 Apple, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
28 // int strcmp(const char *s1, const char *s2);
30 // Returns zero if the two NUL-terminated strings s1 and s2 are equal.
31 // Otherwise, returns the difference between the first two
32 // characters that do not match, interpreted as unsigned integers.
34 #define ESTABLISH_FRAME \
45 // Load a character from each string and advance the pointers. If the loaded
46 // characters are unequal or NUL, return their difference.
52 // If the address of the next character from s1 does not have word alignment,
53 // continue with the character-by-character comparison. Otherwise, fall
54 // through into the word-by-word comparison path.
58 // We have not encountered a NUL or a mismatch, and s1 has word alignment.
59 // Establish a frame, since we're going to need additional registers anyway.
63 // Word align s2, and place the remainder in r8. Compute the right- and
64 // left-shifts to extract each word that we will compare to the other source
65 // from the aligned words that we load:
67 // aligned s2 to be loaded on next iteration
70 // +---+---+---+---+ +---+---+---+---+
71 // | 0 | 1 | 2 | 3 | | 4 | 5 | 6 | 7 |
72 // +---+---+---+---+ +---+---+---+---+
73 // ^-----------------^
74 // to be compared on next iteration
80 // Load the first aligned word of s2. OR 0x01 into any bytes that preceed the
81 // "true s2", to prevent our check for NUL from generating a false positive.
82 // Then check for NUL, and jump to the byte-by-byte comparison loop after
83 // unwinding the pointers if we enounter one.
85 orr r6, r6, lr, lsr r5
90 bne L_unwindLoopPreload
94 // Load the next aligned word of s2 and check if it contains any NUL bytes.
95 // Load the next aligned word of s1, and extract the corresponding bytes from
96 // the two words of s2 loaded in this and the previous iteration of the loop.
97 // Compare these two words.
98 // If no NUL or mismatched words have been encountered, continue the loop.
100 #if defined _ARM_ARCH_6
110 orr r3, r4, r6, lsl r5
113 beq L_wordCompareLoop
115 // Either we have encountered a NUL, or we have found a mismatch between s1
116 // and s2. Unwind the pointers and use a byte-by-byte comparison loop.
120 sub r1, r1, r5, lsr #3
124 // Load a character from each string and advance the pointers. If the loaded
125 // characters are unequal or NUL, return their difference.
130 beq L_byteCompareLoop
133 // Return the difference between the last two characters loaded.