2 ; Copyright (c) 2013 - 2016, Linaro Limited
4 ; SPDX-License-Identifier: BSD-2-Clause-Patent
7 ; Parameters and result.
23 EXPORT InternalMemCompareMem
25 AREA CompareMem, CODE, READONLY
34 add limit_wd, limit, #3
36 lsr limit_wd, limit_wd, #2
38 ; Start of performance-critical section -- one 32B cache line.
43 subs limit_wd, limit_wd, #1
44 eor diff, data1, data2 ; Non-zero if differences found.
47 ; End of performance-critical section -- one 32B cache line.
49 ; Not reached the limit, must have found a diff.
51 cbnz limit_wd, Lnot_limit
53 // Limit % 4 == 0 => all bytes significant.
57 lsl limit, limit, #3 // Bits -> bytes.
60 bic data1, data1, mask
61 bic data2, data2, mask
70 ; The MS-non-zero bit of DIFF marks either the first bit
71 ; that is different, or the end of the significant data.
72 ; Shifting left now will bring the critical information into the
78 ; But we need to zero-extend (char is unsigned) the value and then
79 ; perform a signed 32-bit subtraction.
81 sub result, data1, data2, lsr #28
85 ; Sources are mutually aligned, but are not currently at an
86 ; alignment boundary. Round down the addresses and then mask off
87 ; the bytes that precede the start point.
90 add limit, limit, tmp1 ; Adjust the limit for the extra.
91 lsl tmp1, tmp1, #2 ; Bytes beyond alignment -> bits.
93 neg tmp1, tmp1 ; Bits to alignment -32.
97 ; Little-endian. Early bytes are at LSB.
98 lsr tmp2, tmp2, tmp1 ; Shift (tmp1 & 31).
99 add limit_wd, limit, #3
100 orr data1, data1, tmp2
101 orr data2, data2, tmp2
102 lsr limit_wd, limit_wd, #2
108 // Perhaps we can do better than this.
109 ldrb data1, [src1], #1
110 ldrb data2, [src2], #1
111 subs limit, limit, #1
115 sub result, data1, data2