2 * Copyright (C) 2013, 2022 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 #ifdef __LITTLE_ENDIAN__
14 #else /* BIG ENDIAN */
21 #if defined(__ARC700__) || defined(__ARCHS__)
25 brls r2,r12,.Lbytewise
30 /* In ARCv2 a branch can't be the last instruction in a zero overhead
32 * So we move the branch to the start of the loop, duplicate it
33 * after the end, and set up r12 so that the branch isn't taken
60 #ifdef __LITTLE_ENDIAN__
62 ; one more load latency cycle
99 #else /* BIG ENDIAN */
125 brne r3,r12,.Lbyte_odd
131 brne r4,r5,.Lbyte_even
136 brne r3,r12,.Lbyte_odd
138 brne r3,r12,.Lbyte_odd
142 brne r4,r5,.Lbyte_even
155 #elif (__ARC64_ARCH32__)
156 ;; Based on Synopsys code from newlib's arc64/memcmp.S
158 bls.d @.L_compare_1_bytes
159 mov r3, r0 ; "r0" will be used as return value
161 lsr r12, r2, 4 ; counter for 16-byte chunks
162 xor r13, r13, r13 ; the mask showing inequal registers
174 xor.ne r13, r13, 0b0001
176 xor.ne r13, r13, 0b0010
178 xor.ne r13, r13, 0b0100
180 xor.ne r13, r13, 0b1000
181 brne r13, 0, @.L_unequal_find
182 dbnz r12, @.L_compare_16_bytes
184 ;; Adjusting the pointers because of the extra loads in the end
187 bmsk_s r2, r2, 3 ; any remaining bytes to compare
202 ;; At this point, we want to find the _first_ comparison that marked the
203 ;; inequality of "lhs" and "rhs"
210 b.d @.L_diff_byte_in_regs
215 b.d @.L_diff_byte_in_regs
220 b.d @.L_diff_byte_in_regs
228 ;; If we're here, that means the two operands are not equal.
229 .L_diff_byte_in_regs:
241 #error "Unsupported ARC CPU type"
245 libc_hidden_def(memcmp)
247 #ifdef __UCLIBC_SUSV3_LEGACY__
248 strong_alias(memcmp,bcmp)