2 Copyright (c) 2015-2024, Synopsys, Inc. All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are met:
7 1) Redistributions of source code must retain the above copyright notice,
8 this list of conditions and the following disclaimer.
10 2) Redistributions in binary form must reproduce the above copyright notice,
11 this list of conditions and the following disclaimer in the documentation
12 and/or other materials provided with the distribution.
14 3) Neither the name of the Synopsys, Inc., nor the names of its contributors
15 may be used to endorse or promote products derived from this software
16 without specific prior written permission.
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 POSSIBILITY OF SUCH DAMAGE.
31 /* This implementation is optimized for performance. For code size a generic
32 implementation of this function from newlib/libc/string/strcmp.c will be
34 #if !defined (__OPTIMIZE_SIZE__) && !defined (PREFER_SIZE_OVER_SPEED) \
35 && !defined (__ARC_RF16__)
39 /* This is optimized primarily for the ARC700.
40 It would be possible to speed up the loops by one cycle / word
41 respective one cycle / byte by forcing double source 1 alignment, unrolling
42 by a factor of two, and speculatively loading the second word / byte of
43 source 1; however, that would increase the overhead for loop setup / finish,
44 and strcmp might often terminate early. */
50 brne_l r2,0,.Lcharloop
62 #ifdef __LITTLE_ENDIAN__
63 xor r0,r2,r3 ; mask for difference
65 bic_s r0,r0,r1 ; mask for least significant difference bit
67 xor r0,r5,r1 ; mask for least significant difference byte
70 #endif /* LITTLE ENDIAN */
77 #ifdef __LITTLE_ENDIAN__
79 xor r0,r2,r3 ; mask for difference
80 or r0,r0,r4 ; or in zero indicator
82 bic_s r0,r0,r1 ; mask for least significant difference bit
84 xor r0,r5,r1 ; mask for least significant difference byte
91 #else /* BIG ENDIAN */
92 /* The zero-detection above can mis-detect 0x01 bytes as zeroes
93 because of carry-propagateion from a lower significant zero byte.
94 We can compensate for this by checking that bit0 is zero.
95 This compensation is not necessary in the step where we
96 get a low estimate for r2, because in any affected bytes
97 we already have 0x00 or 0x01, which will remain unchanged
98 when bit 7 is cleared. */
101 #ifdef __ARC_BARREL_SHIFTER__
104 bic_s r2,r2,r0 ; get low estimate for r2 and get ...
105 bic_s r0,r0,r1 ; <this is the adjusted mask for zeros>
106 or_s r3,r3,r0 ; ... high estimate r3 so that r2 > r3 will ...
107 cmp_s r3,r2 ; ... be independent of trailing garbage
108 or_s r2,r2,r0 ; likewise for r3 > r2
110 rlc r0,0 ; r0 := r2 > r3 ? 1 : 0
114 #else /* __ARC_BARREL_SHIFTER__ */
115 /* Fall through to .Lcharloop. */
118 #endif /* __ARC_BARREL_SHIFTER__ */
127 breq r2,r3,.Lcharloop
132 #endif /* !__ARCHS__ */
134 #endif /* !__OPTIMIZE_SIZE__ && !PREFER_SIZE_OVER_SPEED */