1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ; Copyright(c) 2011-2016 Intel Corporation All rights reserved.
4 ; Redistribution and use in source and binary forms, with or without
5 ; modification, are permitted provided that the following conditions
7 ; * Redistributions of source code must retain the above copyright
8 ; notice, this list of conditions and the following disclaimer.
9 ; * Redistributions in binary form must reproduce the above copyright
10 ; notice, this list of conditions and the following disclaimer in
11 ; the documentation and/or other materials provided with the
13 ; * Neither the name of Intel Corporation nor the names of its
14 ; contributors may be used to endorse or promote products derived
15 ; from this software without specific prior written permission.
17 ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 ; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 ; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 ; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 ; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 ; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 ; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 ; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 ; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 ; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
30 %include "options.asm"
37 ;; sttni2 is faster, but it can't be debugged
38 ;; so following code is based on "mine5"
40 ;; compares 8 bytes at a time, using xor
41 ;; assumes the input buffer has size at least 8
42 ;; compare_r src1, src2, result, result_max, tmp
47 %define %%result_max %4
49 %define %%tmp16 %5w ; tmp as a 16-bit register
52 cmp %%result, %%result_max
56 mov %%tmp, [%%src1 + %%result]
57 xor %%tmp, [%%src2 + %%result]
61 mov %%tmp, [%%src1 + %%result]
62 xor %%tmp, [%%src2 + %%result]
65 cmp %%result, %%result_max
70 cmp %%result, %%result_max
73 ; compare last two bytes
74 mov %%tmp, [%%src1 + %%result]
75 xor %%tmp, [%%src2 + %%result]
81 cmp %%result, %%result_max
84 lea %%result, [%%result_max - 8]
86 mov %%tmp, [%%src1 + %%result]
87 xor %%tmp, [%%src2 + %%result]
99 ;; compares 16 bytes at a time, using pcmpeqb/pmovmskb
100 ;; assumes the input buffer has size at least 8
101 ;; compare_x src1, src2, result, result_max, tmp, xtmp1, xtmp2
105 %define %%result %3 ; Accumulator for match_length
106 %define %%result_max %4
108 %define %%tmp16 %5w ; tmp as a 16-bit register
109 %define %%tmp32 %5d ; tmp as a 32-bit register
114 cmp %%result, %%result_max
118 MOVDQU %%xtmp, [%%src1 + %%result]
119 MOVDQU %%xtmp2, [%%src2 + %%result]
120 PCMPEQB %%xtmp, %%xtmp, %%xtmp2
121 PMOVMSKB %%tmp32, %%xtmp
123 jnz %%miscompare_vect
126 MOVDQU %%xtmp, [%%src1 + %%result]
127 MOVDQU %%xtmp2, [%%src2 + %%result]
128 PCMPEQB %%xtmp, %%xtmp, %%xtmp2
129 PMOVMSKB %%tmp32, %%xtmp
131 jnz %%miscompare_vect
134 cmp %%result, %%result_max
139 cmp %%result, %%result_max
142 MOVDQU %%xtmp, [%%src1 + %%result]
143 MOVDQU %%xtmp2, [%%src2 + %%result]
144 PCMPEQB %%xtmp, %%xtmp, %%xtmp2
145 PMOVMSKB %%tmp32, %%xtmp
147 jnz %%miscompare_vect
152 cmp %%result, %%result_max
155 ; compare last two bytes
156 mov %%tmp, [%%src1 + %%result]
157 xor %%tmp, [%%src2 + %%result]
163 cmp %%result, %%result_max
166 lea %%result, [%%result_max - 8]
168 mov %%tmp, [%%src1 + %%result]
169 xor %%tmp, [%%src2 + %%result]
186 ;; compares 32 bytes at a time, using pcmpeqb/pmovmskb
187 ;; assumes the input buffer has size at least 8
188 ;; compare_y src1, src2, result, result_max, tmp, xtmp1, xtmp2
192 %define %%result %3 ; Accumulator for match_length
193 %define %%result_max %4
195 %define %%tmp16 %5w ; tmp as a 16-bit register
196 %define %%tmp32 %5d ; tmp as a 32-bit register
201 cmp %%result, %%result_max
205 vmovdqu %%ytmp, [%%src1 + %%result]
206 vmovdqu %%ytmp2, [%%src2 + %%result]
207 vpcmpeqb %%ytmp, %%ytmp, %%ytmp2
208 vpmovmskb %%tmp, %%ytmp
209 xor %%tmp32, 0xFFFFFFFF
210 jnz %%miscompare_vect
213 vmovdqu %%ytmp, [%%src1 + %%result]
214 vmovdqu %%ytmp2, [%%src2 + %%result]
215 vpcmpeqb %%ytmp, %%ytmp, %%ytmp2
216 vpmovmskb %%tmp, %%ytmp
217 xor %%tmp32, 0xFFFFFFFF
218 jnz %%miscompare_vect
221 cmp %%result, %%result_max
226 cmp %%result, %%result_max
229 vmovdqu %%ytmp, [%%src1 + %%result]
230 vmovdqu %%ytmp2, [%%src2 + %%result]
231 vpcmpeqb %%ytmp, %%ytmp, %%ytmp2
232 vpmovmskb %%tmp, %%ytmp
233 xor %%tmp32, 0xFFFFFFFF
234 jnz %%miscompare_vect
239 cmp %%result, %%result_max
242 vmovdqu %%ytmp %+ x, [%%src1 + %%result]
243 vmovdqu %%ytmp2 %+ x, [%%src2 + %%result]
244 vpcmpeqb %%ytmp %+ x, %%ytmp %+ x, %%ytmp2 %+ x
245 vpmovmskb %%tmp, %%ytmp %+ x
247 jnz %%miscompare_vect
252 cmp %%result, %%result_max
255 mov %%tmp, [%%src1 + %%result]
256 xor %%tmp, [%%src2 + %%result]
262 cmp %%result, %%result_max
265 lea %%result, [%%result_max - 8]
267 ; compare last two bytes
268 mov %%tmp, [%%src1 + %%result]
269 xor %%tmp, [%%src2 + %%result]
286 ;; compares 64 bytes at a time
287 ;; compare_z src1, src2, result, result_max, tmp, ktmp, ztmp1, ztmp2
288 ;; Clobbers result_max
292 %define %%result %3 ; Accumulator for match_length
293 %define %%result_max %4
294 %define %%tmp %5 ; tmp as a 16-bit register
299 sub %%result_max, 128
300 cmp %%result, %%result_max
304 vmovdqu8 %%ztmp, [%%src1 + %%result]
305 vmovdqu8 %%ztmp2, [%%src2 + %%result]
306 vpcmpb %%ktmp, %%ztmp, %%ztmp2, NEQ
307 ktestq %%ktmp, %%ktmp
311 vmovdqu8 %%ztmp, [%%src1 + %%result]
312 vmovdqu8 %%ztmp2, [%%src2 + %%result]
313 vpcmpb %%ktmp, %%ztmp, %%ztmp2, NEQ
314 ktestq %%ktmp, %%ktmp
318 cmp %%result, %%result_max
323 cmp %%result, %%result_max
326 vmovdqu8 %%ztmp, [%%src1 + %%result]
327 vmovdqu8 %%ztmp2, [%%src2 + %%result]
328 vpcmpb %%ktmp, %%ztmp, %%ztmp2, NEQ
329 ktestq %%ktmp, %%ktmp
335 sub %%result_max, %%result
339 bzhi %%tmp, %%tmp, %%result_max
342 vmovdqu8 %%ztmp {%%ktmp}{z}, [%%src1 + %%result]
343 vmovdqu8 %%ztmp2 {%%ktmp}{z}, [%%src2 + %%result]
344 vpcmpb %%ktmp, %%ztmp, %%ztmp2, NEQ
345 ktestq %%ktmp, %%ktmp
347 add %%result, %%result_max
361 %define %%result_max %4
369 cmp %%result_max, 250
370 cmovg %%result_max, %%tmp
372 %if (COMPARE_TYPE == 1)
373 compare_r %%src1, %%src2, %%result, %%result_max, %%tmp
374 %elif (COMPARE_TYPE == 2)
375 compare_x %%src1, %%src2, %%result, %%result_max, %%tmp, %%xtmp0, %%xtmp1
376 %elif (COMPARE_TYPE == 3)
377 compare_y %%src1, %%src2, %%result, %%result_max, %%tmp, %%ytmp0, %%ytmp1
379 %error Unknown Compare type COMPARE_TYPE
384 ; Assumes the buffer has at least 8 bytes
385 ; Accumulates match length onto result
386 %macro compare_large 7
390 %define %%result_max %4
397 %if (COMPARE_TYPE == 1)
398 compare_r %%src1, %%src2, %%result, %%result_max, %%tmp
399 %elif (COMPARE_TYPE == 2)
400 compare_x %%src1, %%src2, %%result, %%result_max, %%tmp, %%xtmp0, %%xtmp1
401 %elif (COMPARE_TYPE == 3)
402 compare_y %%src1, %%src2, %%result, %%result_max, %%tmp, %%ytmp0, %%ytmp1
404 %error Unknown Compare type COMPARE_TYPE
409 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
410 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
412 ;; compare size, src1, src2, result, tmp
419 %define %%tmp8 %5b ; tmp as a 8-bit register
421 xor %%result, %%result
425 mov %%tmp, [%%src1 + %%result]
426 xor %%tmp, [%%src2 + %%result]
432 ;; if we fall through from above, we have found no mismatches,
433 ;; %%size+7 is the number of bytes left to look at, and %%result is the
434 ;; number of bytes that have matched
438 mov %%tmp8, [%%src1 + %%result]
439 cmp %%tmp8, [%%src2 + %%result]