]>
Commit | Line | Data |
---|---|---|
f91f0fd5 TL |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ; Copyright(c) 2011-2020 Intel Corporation All rights reserved. | |
3 | ; | |
4 | ; Redistribution and use in source and binary forms, with or without | |
5 | ; modification, are permitted provided that the following conditions | |
6 | ; are met: | |
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 | |
12 | ; distribution. | |
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. | |
16 | ; | |
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 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
29 | ||
30 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
31 | ; Function API: | |
32 | ; UINT32 crc32_gzip_refl_by8_02( | |
33 | ; UINT32 init_crc, //initial CRC value, 32 bits | |
34 | ; const unsigned char *buf, //buffer pointer to calculate CRC on | |
35 | ; UINT64 len //buffer length in bytes (64-bit data) | |
36 | ; ); | |
37 | ; | |
38 | ; Authors: | |
39 | ; Erdinc Ozturk | |
40 | ; Vinodh Gopal | |
41 | ; James Guilford | |
42 | ; | |
43 | ; Reference paper titled "Fast CRC Computation for Generic Polynomials Using PCLMULQDQ Instruction" | |
44 | ; URL: http://download.intel.com/design/intarch/papers/323102.pdf | |
45 | ; | |
46 | ; | |
47 | ; sample yasm command line: | |
48 | ; yasm -f x64 -f elf64 -X gnu -g dwarf2 crc32_gzip_refl_by8 | |
49 | ; | |
50 | ; As explained here: | |
51 | ; http://docs.oracle.com/javase/7/docs/api/java/util/zip/package-summary.html | |
52 | ; CRC-32 checksum is described in RFC 1952 | |
53 | ; Implementing RFC 1952 CRC: | |
54 | ; http://www.ietf.org/rfc/rfc1952.txt | |
55 | ||
56 | %include "reg_sizes.asm" | |
57 | ||
58 | %define fetch_dist 1024 | |
59 | ||
60 | [bits 64] | |
61 | default rel | |
62 | ||
63 | section .text | |
64 | ||
65 | ||
66 | %ifidn __OUTPUT_FORMAT__, win64 | |
67 | %xdefine arg1 rcx | |
68 | %xdefine arg2 rdx | |
69 | %xdefine arg3 r8 | |
70 | ||
71 | %xdefine arg1_low32 ecx | |
72 | %else | |
73 | %xdefine arg1 rdi | |
74 | %xdefine arg2 rsi | |
75 | %xdefine arg3 rdx | |
76 | ||
77 | %xdefine arg1_low32 edi | |
78 | %endif | |
79 | ||
80 | %define TMP 16*0 | |
81 | %ifidn __OUTPUT_FORMAT__, win64 | |
82 | %define XMM_SAVE 16*2 | |
83 | %define VARIABLE_OFFSET 16*10+8 | |
84 | %else | |
85 | %define VARIABLE_OFFSET 16*2+8 | |
86 | %endif | |
87 | ||
88 | align 16 | |
89 | global crc32_gzip_refl_by8_02:ISAL_SYM_TYPE_FUNCTION | |
90 | crc32_gzip_refl_by8_02: | |
91 | not arg1_low32 | |
92 | sub rsp, VARIABLE_OFFSET | |
93 | ||
94 | %ifidn __OUTPUT_FORMAT__, win64 | |
95 | ; push the xmm registers into the stack to maintain | |
96 | vmovdqa [rsp + XMM_SAVE + 16*0], xmm6 | |
97 | vmovdqa [rsp + XMM_SAVE + 16*1], xmm7 | |
98 | vmovdqa [rsp + XMM_SAVE + 16*2], xmm8 | |
99 | vmovdqa [rsp + XMM_SAVE + 16*3], xmm9 | |
100 | vmovdqa [rsp + XMM_SAVE + 16*4], xmm10 | |
101 | vmovdqa [rsp + XMM_SAVE + 16*5], xmm11 | |
102 | vmovdqa [rsp + XMM_SAVE + 16*6], xmm12 | |
103 | vmovdqa [rsp + XMM_SAVE + 16*7], xmm13 | |
104 | %endif | |
105 | ||
106 | ; check if smaller than 256B | |
107 | cmp arg3, 256 | |
108 | jl .less_than_256 | |
109 | ||
110 | ; load the initial crc value | |
111 | vmovd xmm10, arg1_low32 ; initial crc | |
112 | ||
113 | ; receive the initial 64B data, xor the initial crc value | |
114 | vmovdqu xmm0, [arg2+16*0] | |
115 | vmovdqu xmm1, [arg2+16*1] | |
116 | vmovdqu xmm2, [arg2+16*2] | |
117 | vmovdqu xmm3, [arg2+16*3] | |
118 | vmovdqu xmm4, [arg2+16*4] | |
119 | vmovdqu xmm5, [arg2+16*5] | |
120 | vmovdqu xmm6, [arg2+16*6] | |
121 | vmovdqu xmm7, [arg2+16*7] | |
122 | ||
123 | ; XOR the initial_crc value | |
124 | vpxor xmm0, xmm10 | |
125 | vmovdqa xmm10, [rk3] ;xmm10 has rk3 and rk4 | |
126 | ;imm value of pclmulqdq instruction will determine which constant to use | |
127 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
128 | ; we subtract 256 instead of 128 to save one instruction from the loop | |
129 | sub arg3, 256 | |
130 | ||
131 | ; at this section of the code, there is 128*x+y (0<=y<128) bytes of buffer. The fold_128_B_loop | |
132 | ; loop will fold 128B at a time until we have 128+y Bytes of buffer | |
133 | ||
134 | ; fold 128B at a time. This section of the code folds 8 xmm registers in parallel | |
135 | .fold_128_B_loop: | |
136 | add arg2, 128 | |
137 | prefetchnta [arg2+fetch_dist+0] | |
138 | vmovdqu xmm9, [arg2+16*0] | |
139 | vmovdqu xmm12, [arg2+16*1] | |
140 | vpclmulqdq xmm8, xmm0, xmm10, 0x10 | |
141 | vpclmulqdq xmm0, xmm0, xmm10 , 0x1 | |
142 | vpclmulqdq xmm13, xmm1, xmm10, 0x10 | |
143 | vpclmulqdq xmm1, xmm1, xmm10 , 0x1 | |
144 | vpxor xmm0, xmm9 | |
145 | vxorps xmm0, xmm8 | |
146 | vpxor xmm1, xmm12 | |
147 | vxorps xmm1, xmm13 | |
148 | ||
149 | prefetchnta [arg2+fetch_dist+32] | |
150 | vmovdqu xmm9, [arg2+16*2] | |
151 | vmovdqu xmm12, [arg2+16*3] | |
152 | vpclmulqdq xmm8, xmm2, xmm10, 0x10 | |
153 | vpclmulqdq xmm2, xmm2, xmm10 , 0x1 | |
154 | vpclmulqdq xmm13, xmm3, xmm10, 0x10 | |
155 | vpclmulqdq xmm3, xmm3, xmm10 , 0x1 | |
156 | vpxor xmm2, xmm9 | |
157 | vxorps xmm2, xmm8 | |
158 | vpxor xmm3, xmm12 | |
159 | vxorps xmm3, xmm13 | |
160 | ||
161 | prefetchnta [arg2+fetch_dist+64] | |
162 | vmovdqu xmm9, [arg2+16*4] | |
163 | vmovdqu xmm12, [arg2+16*5] | |
164 | vpclmulqdq xmm8, xmm4, xmm10, 0x10 | |
165 | vpclmulqdq xmm4, xmm4, xmm10 , 0x1 | |
166 | vpclmulqdq xmm13, xmm5, xmm10, 0x10 | |
167 | vpclmulqdq xmm5, xmm5, xmm10 , 0x1 | |
168 | vpxor xmm4, xmm9 | |
169 | vxorps xmm4, xmm8 | |
170 | vpxor xmm5, xmm12 | |
171 | vxorps xmm5, xmm13 | |
172 | ||
173 | prefetchnta [arg2+fetch_dist+96] | |
174 | vmovdqu xmm9, [arg2+16*6] | |
175 | vmovdqu xmm12, [arg2+16*7] | |
176 | vpclmulqdq xmm8, xmm6, xmm10, 0x10 | |
177 | vpclmulqdq xmm6, xmm6, xmm10 , 0x1 | |
178 | vpclmulqdq xmm13, xmm7, xmm10, 0x10 | |
179 | vpclmulqdq xmm7, xmm7, xmm10 , 0x1 | |
180 | vpxor xmm6, xmm9 | |
181 | vxorps xmm6, xmm8 | |
182 | vpxor xmm7, xmm12 | |
183 | vxorps xmm7, xmm13 | |
184 | ||
185 | sub arg3, 128 | |
186 | jge .fold_128_B_loop | |
187 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
188 | ||
189 | add arg2, 128 | |
190 | ; at this point, the buffer pointer is pointing at the last y Bytes of the buffer, where 0 <= y < 128 | |
191 | ; the 128B of folded data is in 8 of the xmm registers: xmm0, xmm1, xmm2, xmm3, xmm4, xmm5, xmm6, xmm7 | |
192 | ||
193 | ; fold the 8 xmm registers to 1 xmm register with different constants | |
194 | vmovdqa xmm10, [rk9] | |
195 | vpclmulqdq xmm8, xmm0, xmm10, 0x1 | |
196 | vpclmulqdq xmm0, xmm0, xmm10, 0x10 | |
197 | vpxor xmm7, xmm8 | |
198 | vxorps xmm7, xmm0 | |
199 | ||
200 | vmovdqa xmm10, [rk11] | |
201 | vpclmulqdq xmm8, xmm1, xmm10, 0x1 | |
202 | vpclmulqdq xmm1, xmm1, xmm10, 0x10 | |
203 | vpxor xmm7, xmm8 | |
204 | vxorps xmm7, xmm1 | |
205 | ||
206 | vmovdqa xmm10, [rk13] | |
207 | vpclmulqdq xmm8, xmm2, xmm10, 0x1 | |
208 | vpclmulqdq xmm2, xmm2, xmm10, 0x10 | |
209 | vpxor xmm7, xmm8 | |
210 | vpxor xmm7, xmm2 | |
211 | ||
212 | vmovdqa xmm10, [rk15] | |
213 | vpclmulqdq xmm8, xmm3, xmm10, 0x1 | |
214 | vpclmulqdq xmm3, xmm3, xmm10, 0x10 | |
215 | vpxor xmm7, xmm8 | |
216 | vxorps xmm7, xmm3 | |
217 | ||
218 | vmovdqa xmm10, [rk17] | |
219 | vpclmulqdq xmm8, xmm4, xmm10, 0x1 | |
220 | vpclmulqdq xmm4, xmm4, xmm10, 0x10 | |
221 | vpxor xmm7, xmm8 | |
222 | vpxor xmm7, xmm4 | |
223 | ||
224 | vmovdqa xmm10, [rk19] | |
225 | vpclmulqdq xmm8, xmm5, xmm10, 0x1 | |
226 | vpclmulqdq xmm5, xmm5, xmm10, 0x10 | |
227 | vpxor xmm7, xmm8 | |
228 | vxorps xmm7, xmm5 | |
229 | ||
230 | vmovdqa xmm10, [rk1] | |
231 | vpclmulqdq xmm8, xmm6, xmm10, 0x1 | |
232 | vpclmulqdq xmm6, xmm6, xmm10, 0x10 | |
233 | vpxor xmm7, xmm8 | |
234 | vpxor xmm7, xmm6 | |
235 | ||
236 | ||
237 | ; instead of 128, we add 128-16 to the loop counter to save 1 instruction from the loop | |
238 | ; instead of a cmp instruction, we use the negative flag with the jl instruction | |
239 | add arg3, 128-16 | |
240 | jl .final_reduction_for_128 | |
241 | ||
242 | ; now we have 16+y bytes left to reduce. 16 Bytes is in register xmm7 and the rest is in memory | |
243 | ; we can fold 16 bytes at a time if y>=16 | |
244 | ; continue folding 16B at a time | |
245 | ||
246 | .16B_reduction_loop: | |
247 | vpclmulqdq xmm8, xmm7, xmm10, 0x1 | |
248 | vpclmulqdq xmm7, xmm7, xmm10, 0x10 | |
249 | vpxor xmm7, xmm8 | |
250 | vmovdqu xmm0, [arg2] | |
251 | vpxor xmm7, xmm0 | |
252 | add arg2, 16 | |
253 | sub arg3, 16 | |
254 | ; instead of a cmp instruction, we utilize the flags with the jge instruction | |
255 | ; equivalent of: cmp arg3, 16-16 | |
256 | ; check if there is any more 16B in the buffer to be able to fold | |
257 | jge .16B_reduction_loop | |
258 | ||
259 | ;now we have 16+z bytes left to reduce, where 0<= z < 16. | |
260 | ;first, we reduce the data in the xmm7 register | |
261 | ||
262 | ||
263 | .final_reduction_for_128: | |
264 | add arg3, 16 | |
265 | je .128_done | |
266 | ||
267 | ; here we are getting data that is less than 16 bytes. | |
268 | ; since we know that there was data before the pointer, we can offset | |
269 | ; the input pointer before the actual point, to receive exactly 16 bytes. | |
270 | ; after that the registers need to be adjusted. | |
271 | .get_last_two_xmms: | |
272 | ||
273 | vmovdqa xmm2, xmm7 | |
274 | vmovdqu xmm1, [arg2 - 16 + arg3] | |
275 | ||
276 | ; get rid of the extra data that was loaded before | |
277 | ; load the shift constant | |
278 | lea rax, [pshufb_shf_table] | |
279 | add rax, arg3 | |
280 | vmovdqu xmm0, [rax] | |
281 | ||
282 | vpshufb xmm7, xmm0 | |
283 | vpxor xmm0, [mask3] | |
284 | vpshufb xmm2, xmm0 | |
285 | ||
286 | vpblendvb xmm2, xmm2, xmm1, xmm0 | |
287 | ;;;;;;;;;; | |
288 | vpclmulqdq xmm8, xmm7, xmm10, 0x1 | |
289 | vpclmulqdq xmm7, xmm7, xmm10, 0x10 | |
290 | vpxor xmm7, xmm8 | |
291 | vpxor xmm7, xmm2 | |
292 | ||
293 | .128_done: | |
294 | ; compute crc of a 128-bit value | |
295 | vmovdqa xmm10, [rk5] | |
296 | vmovdqa xmm0, xmm7 | |
297 | ||
298 | ;64b fold | |
299 | vpclmulqdq xmm7, xmm10, 0 | |
300 | vpsrldq xmm0, 8 | |
301 | vpxor xmm7, xmm0 | |
302 | ||
303 | ;32b fold | |
304 | vmovdqa xmm0, xmm7 | |
305 | vpslldq xmm7, 4 | |
306 | vpclmulqdq xmm7, xmm10, 0x10 | |
307 | vpxor xmm7, xmm0 | |
308 | ||
309 | ||
310 | ;barrett reduction | |
311 | .barrett: | |
312 | vpand xmm7, [mask2] | |
313 | vmovdqa xmm1, xmm7 | |
314 | vmovdqa xmm2, xmm7 | |
315 | vmovdqa xmm10, [rk7] | |
316 | ||
317 | vpclmulqdq xmm7, xmm10, 0 | |
318 | vpxor xmm7, xmm2 | |
319 | vpand xmm7, [mask] | |
320 | vmovdqa xmm2, xmm7 | |
321 | vpclmulqdq xmm7, xmm10, 0x10 | |
322 | vpxor xmm7, xmm2 | |
323 | vpxor xmm7, xmm1 | |
324 | vpextrd eax, xmm7, 2 | |
325 | ||
326 | .cleanup: | |
327 | not eax | |
328 | ||
329 | ||
330 | %ifidn __OUTPUT_FORMAT__, win64 | |
331 | vmovdqa xmm6, [rsp + XMM_SAVE + 16*0] | |
332 | vmovdqa xmm7, [rsp + XMM_SAVE + 16*1] | |
333 | vmovdqa xmm8, [rsp + XMM_SAVE + 16*2] | |
334 | vmovdqa xmm9, [rsp + XMM_SAVE + 16*3] | |
335 | vmovdqa xmm10, [rsp + XMM_SAVE + 16*4] | |
336 | vmovdqa xmm11, [rsp + XMM_SAVE + 16*5] | |
337 | vmovdqa xmm12, [rsp + XMM_SAVE + 16*6] | |
338 | vmovdqa xmm13, [rsp + XMM_SAVE + 16*7] | |
339 | %endif | |
340 | add rsp, VARIABLE_OFFSET | |
341 | ret | |
342 | ||
343 | ||
344 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
345 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
346 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
347 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
348 | ||
349 | align 16 | |
350 | .less_than_256: | |
351 | ||
352 | ; check if there is enough buffer to be able to fold 16B at a time | |
353 | cmp arg3, 32 | |
354 | jl .less_than_32 | |
355 | ||
356 | ; if there is, load the constants | |
357 | vmovdqa xmm10, [rk1] ; rk1 and rk2 in xmm10 | |
358 | ||
359 | vmovd xmm0, arg1_low32 ; get the initial crc value | |
360 | vmovdqu xmm7, [arg2] ; load the plaintext | |
361 | vpxor xmm7, xmm0 | |
362 | ||
363 | ; update the buffer pointer | |
364 | add arg2, 16 | |
365 | ||
366 | ; update the counter. subtract 32 instead of 16 to save one instruction from the loop | |
367 | sub arg3, 32 | |
368 | ||
369 | jmp .16B_reduction_loop | |
370 | ||
371 | ||
372 | align 16 | |
373 | .less_than_32: | |
374 | ; mov initial crc to the return value. this is necessary for zero-length buffers. | |
375 | mov eax, arg1_low32 | |
376 | test arg3, arg3 | |
377 | je .cleanup | |
378 | ||
379 | vmovd xmm0, arg1_low32 ; get the initial crc value | |
380 | ||
381 | cmp arg3, 16 | |
382 | je .exact_16_left | |
383 | jl .less_than_16_left | |
384 | ||
385 | vmovdqu xmm7, [arg2] ; load the plaintext | |
386 | vpxor xmm7, xmm0 ; xor the initial crc value | |
387 | add arg2, 16 | |
388 | sub arg3, 16 | |
389 | vmovdqa xmm10, [rk1] ; rk1 and rk2 in xmm10 | |
390 | jmp .get_last_two_xmms | |
391 | ||
392 | align 16 | |
393 | .less_than_16_left: | |
394 | ; use stack space to load data less than 16 bytes, zero-out the 16B in memory first. | |
395 | ||
396 | vpxor xmm1, xmm1 | |
397 | mov r11, rsp | |
398 | vmovdqa [r11], xmm1 | |
399 | ||
400 | cmp arg3, 4 | |
401 | jl .only_less_than_4 | |
402 | ||
403 | ; backup the counter value | |
404 | mov r9, arg3 | |
405 | cmp arg3, 8 | |
406 | jl .less_than_8_left | |
407 | ||
408 | ; load 8 Bytes | |
409 | mov rax, [arg2] | |
410 | mov [r11], rax | |
411 | add r11, 8 | |
412 | sub arg3, 8 | |
413 | add arg2, 8 | |
414 | .less_than_8_left: | |
415 | ||
416 | cmp arg3, 4 | |
417 | jl .less_than_4_left | |
418 | ||
419 | ; load 4 Bytes | |
420 | mov eax, [arg2] | |
421 | mov [r11], eax | |
422 | add r11, 4 | |
423 | sub arg3, 4 | |
424 | add arg2, 4 | |
425 | .less_than_4_left: | |
426 | ||
427 | cmp arg3, 2 | |
428 | jl .less_than_2_left | |
429 | ||
430 | ; load 2 Bytes | |
431 | mov ax, [arg2] | |
432 | mov [r11], ax | |
433 | add r11, 2 | |
434 | sub arg3, 2 | |
435 | add arg2, 2 | |
436 | .less_than_2_left: | |
437 | cmp arg3, 1 | |
438 | jl .zero_left | |
439 | ||
440 | ; load 1 Byte | |
441 | mov al, [arg2] | |
442 | mov [r11], al | |
443 | ||
444 | .zero_left: | |
445 | vmovdqa xmm7, [rsp] | |
446 | vpxor xmm7, xmm0 ; xor the initial crc value | |
447 | ||
448 | lea rax,[pshufb_shf_table] | |
449 | vmovdqu xmm0, [rax + r9] | |
450 | vpshufb xmm7,xmm0 | |
451 | jmp .128_done | |
452 | ||
453 | align 16 | |
454 | .exact_16_left: | |
455 | vmovdqu xmm7, [arg2] | |
456 | vpxor xmm7, xmm0 ; xor the initial crc value | |
457 | jmp .128_done | |
458 | ||
459 | .only_less_than_4: | |
460 | cmp arg3, 3 | |
461 | jl .only_less_than_3 | |
462 | ||
463 | ; load 3 Bytes | |
464 | mov al, [arg2] | |
465 | mov [r11], al | |
466 | ||
467 | mov al, [arg2+1] | |
468 | mov [r11+1], al | |
469 | ||
470 | mov al, [arg2+2] | |
471 | mov [r11+2], al | |
472 | ||
473 | vmovdqa xmm7, [rsp] | |
474 | vpxor xmm7, xmm0 ; xor the initial crc value | |
475 | ||
476 | vpslldq xmm7, 5 | |
477 | jmp .barrett | |
478 | ||
479 | .only_less_than_3: | |
480 | cmp arg3, 2 | |
481 | jl .only_less_than_2 | |
482 | ||
483 | ; load 2 Bytes | |
484 | mov al, [arg2] | |
485 | mov [r11], al | |
486 | ||
487 | mov al, [arg2+1] | |
488 | mov [r11+1], al | |
489 | ||
490 | vmovdqa xmm7, [rsp] | |
491 | vpxor xmm7, xmm0 ; xor the initial crc value | |
492 | ||
493 | vpslldq xmm7, 6 | |
494 | jmp .barrett | |
495 | ||
496 | .only_less_than_2: | |
497 | ; load 1 Byte | |
498 | mov al, [arg2] | |
499 | mov [r11], al | |
500 | ||
501 | vmovdqa xmm7, [rsp] | |
502 | vpxor xmm7, xmm0 ; xor the initial crc value | |
503 | ||
504 | vpslldq xmm7, 7 | |
505 | jmp .barrett | |
506 | ||
507 | section .data | |
508 | ||
509 | ; precomputed constants | |
510 | align 16 | |
511 | rk1: dq 0x00000000ccaa009e | |
512 | rk2: dq 0x00000001751997d0 | |
513 | rk3: dq 0x000000014a7fe880 | |
514 | rk4: dq 0x00000001e88ef372 | |
515 | rk5: dq 0x00000000ccaa009e | |
516 | rk6: dq 0x0000000163cd6124 | |
517 | rk7: dq 0x00000001f7011640 | |
518 | rk8: dq 0x00000001db710640 | |
519 | rk9: dq 0x00000001d7cfc6ac | |
520 | rk10: dq 0x00000001ea89367e | |
521 | rk11: dq 0x000000018cb44e58 | |
522 | rk12: dq 0x00000000df068dc2 | |
523 | rk13: dq 0x00000000ae0b5394 | |
524 | rk14: dq 0x00000001c7569e54 | |
525 | rk15: dq 0x00000001c6e41596 | |
526 | rk16: dq 0x0000000154442bd4 | |
527 | rk17: dq 0x0000000174359406 | |
528 | rk18: dq 0x000000003db1ecdc | |
529 | rk19: dq 0x000000015a546366 | |
530 | rk20: dq 0x00000000f1da05aa | |
531 | ||
532 | mask: dq 0xFFFFFFFFFFFFFFFF, 0x0000000000000000 | |
533 | mask2: dq 0xFFFFFFFF00000000, 0xFFFFFFFFFFFFFFFF | |
534 | mask3: dq 0x8080808080808080, 0x8080808080808080 | |
535 | ||
536 | pshufb_shf_table: | |
537 | ; use these values for shift constants for the pshufb instruction | |
538 | ; different alignments result in values as shown: | |
539 | ; dq 0x8887868584838281, 0x008f8e8d8c8b8a89 ; shl 15 (16-1) / shr1 | |
540 | ; dq 0x8988878685848382, 0x01008f8e8d8c8b8a ; shl 14 (16-3) / shr2 | |
541 | ; dq 0x8a89888786858483, 0x0201008f8e8d8c8b ; shl 13 (16-4) / shr3 | |
542 | ; dq 0x8b8a898887868584, 0x030201008f8e8d8c ; shl 12 (16-4) / shr4 | |
543 | ; dq 0x8c8b8a8988878685, 0x04030201008f8e8d ; shl 11 (16-5) / shr5 | |
544 | ; dq 0x8d8c8b8a89888786, 0x0504030201008f8e ; shl 10 (16-6) / shr6 | |
545 | ; dq 0x8e8d8c8b8a898887, 0x060504030201008f ; shl 9 (16-7) / shr7 | |
546 | ; dq 0x8f8e8d8c8b8a8988, 0x0706050403020100 ; shl 8 (16-8) / shr8 | |
547 | ; dq 0x008f8e8d8c8b8a89, 0x0807060504030201 ; shl 7 (16-9) / shr9 | |
548 | ; dq 0x01008f8e8d8c8b8a, 0x0908070605040302 ; shl 6 (16-10) / shr10 | |
549 | ; dq 0x0201008f8e8d8c8b, 0x0a09080706050403 ; shl 5 (16-11) / shr11 | |
550 | ; dq 0x030201008f8e8d8c, 0x0b0a090807060504 ; shl 4 (16-12) / shr12 | |
551 | ; dq 0x04030201008f8e8d, 0x0c0b0a0908070605 ; shl 3 (16-13) / shr13 | |
552 | ; dq 0x0504030201008f8e, 0x0d0c0b0a09080706 ; shl 2 (16-14) / shr14 | |
553 | ; dq 0x060504030201008f, 0x0e0d0c0b0a090807 ; shl 1 (16-15) / shr15 | |
554 | dq 0x8786858483828100, 0x8f8e8d8c8b8a8988 | |
555 | dq 0x0706050403020100, 0x000e0d0c0b0a0908 |