2 * Copyright (C) 2013, 2014-2015, 2017 Synopsys, Inc. (www.synopsys.com)
3 * Copyright (C) 2007 ARC International (UK) LTD
5 * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
11 #if !defined(__ARC700__) && !defined(__ARCHS__)
12 #error "Neither ARC700 nor ARCHS is defined!"
18 /* This is optimized primarily for the ARC700.
19 It would be possible to speed up the loops by one cycle / word
20 respective one cycle / byte by forcing double source 1 alignment, unrolling
21 by a factor of two, and speculatively loading the second word / byte of
22 source 1; however, that would increase the overhead for loop setup / finish,
23 and strcmp might often terminate early. */
39 #ifdef __LITTLE_ENDIAN__
40 xor r0,r2,r3 ; mask for difference
42 bic_s r0,r0,r1 ; mask for least significant difference bit
44 xor r0,r5,r1 ; mask for least significant difference byte
47 #endif /* LITTLE ENDIAN */
54 #ifdef __LITTLE_ENDIAN__
56 xor r0,r2,r3 ; mask for difference
57 or r0,r0,r4 ; or in zero indicator
59 bic_s r0,r0,r1 ; mask for least significant difference bit
61 xor r0,r5,r1 ; mask for least significant difference byte
68 #else /* BIG ENDIAN */
69 /* The zero-detection above can mis-detect 0x01 bytes as zeroes
70 because of carry-propagateion from a lower significant zero byte.
71 We can compensate for this by checking that bit0 is zero.
72 This compensation is not necessary in the step where we
73 get a low estimate for r2, because in any affected bytes
74 we already have 0x00 or 0x01, which will remain unchanged
75 when bit 7 is cleared. */
80 bic_s r2,r2,r0 ; get low estimate for r2 and get ...
81 bic_s r0,r0,r1 ; <this is the adjusted mask for zeros>
82 or_s r3,r3,r0 ; ... high estimate r3 so that r2 > r3 will ...
83 cmp_s r3,r2 ; ... be independent of trailing garbage
84 or_s r2,r2,r0 ; likewise for r3 > r2
86 rlc r0,0 ; r0 := r2 > r3 ? 1 : 0
102 #endif /* __ARC700__ */
107 brne r2, 0, @.Lcharloop
109 ;;; s1 and s2 are word aligned
112 mov_s r12, 0x01010101
117 ;; Detect NULL char in str1
122 brne.d.nt r4, 0, .LfoundNULL
123 ;; Check if the read locations are the same
128 ;; A match is found, spot it out
129 #ifdef __LITTLE_ENDIAN__
142 #ifdef __BIG_ENDIAN__
153 ;; make the return value
165 breq r2, r3, .Lcharloop
171 #endif /* __ARCHS__ */
174 libc_hidden_def(strcmp)
176 #ifndef __UCLIBC_HAS_LOCALE__
177 strong_alias(strcmp,strcoll)
178 libc_hidden_def(strcoll)