1/*
2 * Compute the CRC32 using a parallelized folding approach with the PCLMULQDQ
3 * instruction.
4 *
5 * A white paper describing this algorithm can be found at:
6 * http://www.intel.com/content/dam/www/public/us/en/documents/white-papers/fast-crc-computation-generic-polynomials-pclmulqdq-paper.pdf
7 *
8 * Copyright (C) 2013 Intel Corporation. All rights reserved.
9 * Authors:
10 * Wajdi Feghali <wajdi.k.feghali@intel.com>
11 * Jim Guilford <james.guilford@intel.com>
12 * Vinodh Gopal <vinodh.gopal@intel.com>
13 * Erdinc Ozturk <erdinc.ozturk@intel.com>
14 * Jim Kukunas <james.t.kukunas@linux.intel.com>
15 *
16 * For conditions of distribution and use, see copyright notice in zlib.h
17 */
18
19#ifdef X86_PCLMULQDQ_CRC
20
21#include "../../zbuild.h"
22#include <inttypes.h>
23#include <immintrin.h>
24#include <wmmintrin.h>
25
26#include "crc_folding.h"
27
28ZLIB_INTERNAL void crc_fold_init(deflate_state *const s) {
29 /* CRC_SAVE */
30 _mm_storeu_si128((__m128i *)s->crc0 + 0, _mm_cvtsi32_si128(0x9db42487));
31 _mm_storeu_si128((__m128i *)s->crc0 + 1, _mm_setzero_si128());
32 _mm_storeu_si128((__m128i *)s->crc0 + 2, _mm_setzero_si128());
33 _mm_storeu_si128((__m128i *)s->crc0 + 3, _mm_setzero_si128());
34
35 s->strm->adler = 0;
36}
37
38static void fold_1(__m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2, __m128i *xmm_crc3) {
39 const __m128i xmm_fold4 = _mm_set_epi32( 0x00000001, 0x54442bd4,
40 0x00000001, 0xc6e41596);
41 __m128i x_tmp3;
42 __m128 ps_crc0, ps_crc3, ps_res;
43
44 x_tmp3 = *xmm_crc3;
45
46 *xmm_crc3 = *xmm_crc0;
47 *xmm_crc0 = _mm_clmulepi64_si128(*xmm_crc0, xmm_fold4, 0x01);
48 *xmm_crc3 = _mm_clmulepi64_si128(*xmm_crc3, xmm_fold4, 0x10);
49 ps_crc0 = _mm_castsi128_ps(*xmm_crc0);
50 ps_crc3 = _mm_castsi128_ps(*xmm_crc3);
51 ps_res = _mm_xor_ps(ps_crc0, ps_crc3);
52
53 *xmm_crc0 = *xmm_crc1;
54 *xmm_crc1 = *xmm_crc2;
55 *xmm_crc2 = x_tmp3;
56 *xmm_crc3 = _mm_castps_si128(ps_res);
57}
58
59static void fold_2(__m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2, __m128i *xmm_crc3) {
60 const __m128i xmm_fold4 = _mm_set_epi32( 0x00000001, 0x54442bd4,
61 0x00000001, 0xc6e41596);
62 __m128i x_tmp3, x_tmp2;
63 __m128 ps_crc0, ps_crc1, ps_crc2, ps_crc3, ps_res31, ps_res20;
64
65 x_tmp3 = *xmm_crc3;
66 x_tmp2 = *xmm_crc2;
67
68 *xmm_crc3 = *xmm_crc1;
69 *xmm_crc1 = _mm_clmulepi64_si128(*xmm_crc1, xmm_fold4, 0x01);
70 *xmm_crc3 = _mm_clmulepi64_si128(*xmm_crc3, xmm_fold4, 0x10);
71 ps_crc3 = _mm_castsi128_ps(*xmm_crc3);
72 ps_crc1 = _mm_castsi128_ps(*xmm_crc1);
73 ps_res31 = _mm_xor_ps(ps_crc3, ps_crc1);
74
75 *xmm_crc2 = *xmm_crc0;
76 *xmm_crc0 = _mm_clmulepi64_si128(*xmm_crc0, xmm_fold4, 0x01);
77 *xmm_crc2 = _mm_clmulepi64_si128(*xmm_crc2, xmm_fold4, 0x10);
78 ps_crc0 = _mm_castsi128_ps(*xmm_crc0);
79 ps_crc2 = _mm_castsi128_ps(*xmm_crc2);
80 ps_res20 = _mm_xor_ps(ps_crc0, ps_crc2);
81
82 *xmm_crc0 = x_tmp2;
83 *xmm_crc1 = x_tmp3;
84 *xmm_crc2 = _mm_castps_si128(ps_res20);
85 *xmm_crc3 = _mm_castps_si128(ps_res31);
86}
87
88static void fold_3(__m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2, __m128i *xmm_crc3) {
89 const __m128i xmm_fold4 = _mm_set_epi32( 0x00000001, 0x54442bd4,
90 0x00000001, 0xc6e41596);
91 __m128i x_tmp3;
92 __m128 ps_crc0, ps_crc1, ps_crc2, ps_crc3, ps_res32, ps_res21, ps_res10;
93
94 x_tmp3 = *xmm_crc3;
95
96 *xmm_crc3 = *xmm_crc2;
97 *xmm_crc2 = _mm_clmulepi64_si128(*xmm_crc2, xmm_fold4, 0x01);
98 *xmm_crc3 = _mm_clmulepi64_si128(*xmm_crc3, xmm_fold4, 0x10);
99 ps_crc2 = _mm_castsi128_ps(*xmm_crc2);
100 ps_crc3 = _mm_castsi128_ps(*xmm_crc3);
101 ps_res32 = _mm_xor_ps(ps_crc2, ps_crc3);
102
103 *xmm_crc2 = *xmm_crc1;
104 *xmm_crc1 = _mm_clmulepi64_si128(*xmm_crc1, xmm_fold4, 0x01);
105 *xmm_crc2 = _mm_clmulepi64_si128(*xmm_crc2, xmm_fold4, 0x10);
106 ps_crc1 = _mm_castsi128_ps(*xmm_crc1);
107 ps_crc2 = _mm_castsi128_ps(*xmm_crc2);
108 ps_res21 = _mm_xor_ps(ps_crc1, ps_crc2);
109
110 *xmm_crc1 = *xmm_crc0;
111 *xmm_crc0 = _mm_clmulepi64_si128(*xmm_crc0, xmm_fold4, 0x01);
112 *xmm_crc1 = _mm_clmulepi64_si128(*xmm_crc1, xmm_fold4, 0x10);
113 ps_crc0 = _mm_castsi128_ps(*xmm_crc0);
114 ps_crc1 = _mm_castsi128_ps(*xmm_crc1);
115 ps_res10 = _mm_xor_ps(ps_crc0, ps_crc1);
116
117 *xmm_crc0 = x_tmp3;
118 *xmm_crc1 = _mm_castps_si128(ps_res10);
119 *xmm_crc2 = _mm_castps_si128(ps_res21);
120 *xmm_crc3 = _mm_castps_si128(ps_res32);
121}
122
123static void fold_4(__m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2, __m128i *xmm_crc3) {
124 const __m128i xmm_fold4 = _mm_set_epi32( 0x00000001, 0x54442bd4,
125 0x00000001, 0xc6e41596);
126 __m128i x_tmp0, x_tmp1, x_tmp2, x_tmp3;
127 __m128 ps_crc0, ps_crc1, ps_crc2, ps_crc3;
128 __m128 ps_t0, ps_t1, ps_t2, ps_t3;
129 __m128 ps_res0, ps_res1, ps_res2, ps_res3;
130
131 x_tmp0 = *xmm_crc0;
132 x_tmp1 = *xmm_crc1;
133 x_tmp2 = *xmm_crc2;
134 x_tmp3 = *xmm_crc3;
135
136 *xmm_crc0 = _mm_clmulepi64_si128(*xmm_crc0, xmm_fold4, 0x01);
137 x_tmp0 = _mm_clmulepi64_si128(x_tmp0, xmm_fold4, 0x10);
138 ps_crc0 = _mm_castsi128_ps(*xmm_crc0);
139 ps_t0 = _mm_castsi128_ps(x_tmp0);
140 ps_res0 = _mm_xor_ps(ps_crc0, ps_t0);
141
142 *xmm_crc1 = _mm_clmulepi64_si128(*xmm_crc1, xmm_fold4, 0x01);
143 x_tmp1 = _mm_clmulepi64_si128(x_tmp1, xmm_fold4, 0x10);
144 ps_crc1 = _mm_castsi128_ps(*xmm_crc1);
145 ps_t1 = _mm_castsi128_ps(x_tmp1);
146 ps_res1 = _mm_xor_ps(ps_crc1, ps_t1);
147
148 *xmm_crc2 = _mm_clmulepi64_si128(*xmm_crc2, xmm_fold4, 0x01);
149 x_tmp2 = _mm_clmulepi64_si128(x_tmp2, xmm_fold4, 0x10);
150 ps_crc2 = _mm_castsi128_ps(*xmm_crc2);
151 ps_t2 = _mm_castsi128_ps(x_tmp2);
152 ps_res2 = _mm_xor_ps(ps_crc2, ps_t2);
153
154 *xmm_crc3 = _mm_clmulepi64_si128(*xmm_crc3, xmm_fold4, 0x01);
155 x_tmp3 = _mm_clmulepi64_si128(x_tmp3, xmm_fold4, 0x10);
156 ps_crc3 = _mm_castsi128_ps(*xmm_crc3);
157 ps_t3 = _mm_castsi128_ps(x_tmp3);
158 ps_res3 = _mm_xor_ps(ps_crc3, ps_t3);
159
160 *xmm_crc0 = _mm_castps_si128(ps_res0);
161 *xmm_crc1 = _mm_castps_si128(ps_res1);
162 *xmm_crc2 = _mm_castps_si128(ps_res2);
163 *xmm_crc3 = _mm_castps_si128(ps_res3);
164}
165
166static const unsigned ALIGNED_(32) pshufb_shf_table[60] = {
167 0x84838281, 0x88878685, 0x8c8b8a89, 0x008f8e8d, /* shl 15 (16 - 1)/shr1 */
168 0x85848382, 0x89888786, 0x8d8c8b8a, 0x01008f8e, /* shl 14 (16 - 3)/shr2 */
169 0x86858483, 0x8a898887, 0x8e8d8c8b, 0x0201008f, /* shl 13 (16 - 4)/shr3 */
170 0x87868584, 0x8b8a8988, 0x8f8e8d8c, 0x03020100, /* shl 12 (16 - 4)/shr4 */
171 0x88878685, 0x8c8b8a89, 0x008f8e8d, 0x04030201, /* shl 11 (16 - 5)/shr5 */
172 0x89888786, 0x8d8c8b8a, 0x01008f8e, 0x05040302, /* shl 10 (16 - 6)/shr6 */
173 0x8a898887, 0x8e8d8c8b, 0x0201008f, 0x06050403, /* shl 9 (16 - 7)/shr7 */
174 0x8b8a8988, 0x8f8e8d8c, 0x03020100, 0x07060504, /* shl 8 (16 - 8)/shr8 */
175 0x8c8b8a89, 0x008f8e8d, 0x04030201, 0x08070605, /* shl 7 (16 - 9)/shr9 */
176 0x8d8c8b8a, 0x01008f8e, 0x05040302, 0x09080706, /* shl 6 (16 -10)/shr10*/
177 0x8e8d8c8b, 0x0201008f, 0x06050403, 0x0a090807, /* shl 5 (16 -11)/shr11*/
178 0x8f8e8d8c, 0x03020100, 0x07060504, 0x0b0a0908, /* shl 4 (16 -12)/shr12*/
179 0x008f8e8d, 0x04030201, 0x08070605, 0x0c0b0a09, /* shl 3 (16 -13)/shr13*/
180 0x01008f8e, 0x05040302, 0x09080706, 0x0d0c0b0a, /* shl 2 (16 -14)/shr14*/
181 0x0201008f, 0x06050403, 0x0a090807, 0x0e0d0c0b /* shl 1 (16 -15)/shr15*/
182};
183
184static void partial_fold(const size_t len, __m128i *xmm_crc0, __m128i *xmm_crc1, __m128i *xmm_crc2,
185 __m128i *xmm_crc3, __m128i *xmm_crc_part) {
186
187 const __m128i xmm_fold4 = _mm_set_epi32( 0x00000001, 0x54442bd4,
188 0x00000001, 0xc6e41596);
189 const __m128i xmm_mask3 = _mm_set1_epi32(0x80808080);
190
191 __m128i xmm_shl, xmm_shr, xmm_tmp1, xmm_tmp2, xmm_tmp3;
192 __m128i xmm_a0_0, xmm_a0_1;
193 __m128 ps_crc3, psa0_0, psa0_1, ps_res;
194
195 xmm_shl = _mm_load_si128((__m128i *)pshufb_shf_table + (len - 1));
196 xmm_shr = xmm_shl;
197 xmm_shr = _mm_xor_si128(xmm_shr, xmm_mask3);
198
199 xmm_a0_0 = _mm_shuffle_epi8(*xmm_crc0, xmm_shl);
200
201 *xmm_crc0 = _mm_shuffle_epi8(*xmm_crc0, xmm_shr);
202 xmm_tmp1 = _mm_shuffle_epi8(*xmm_crc1, xmm_shl);
203 *xmm_crc0 = _mm_or_si128(*xmm_crc0, xmm_tmp1);
204
205 *xmm_crc1 = _mm_shuffle_epi8(*xmm_crc1, xmm_shr);
206 xmm_tmp2 = _mm_shuffle_epi8(*xmm_crc2, xmm_shl);
207 *xmm_crc1 = _mm_or_si128(*xmm_crc1, xmm_tmp2);
208
209 *xmm_crc2 = _mm_shuffle_epi8(*xmm_crc2, xmm_shr);
210 xmm_tmp3 = _mm_shuffle_epi8(*xmm_crc3, xmm_shl);
211 *xmm_crc2 = _mm_or_si128(*xmm_crc2, xmm_tmp3);
212
213 *xmm_crc3 = _mm_shuffle_epi8(*xmm_crc3, xmm_shr);
214 *xmm_crc_part = _mm_shuffle_epi8(*xmm_crc_part, xmm_shl);
215 *xmm_crc3 = _mm_or_si128(*xmm_crc3, *xmm_crc_part);
216
217 xmm_a0_1 = _mm_clmulepi64_si128(xmm_a0_0, xmm_fold4, 0x10);
218 xmm_a0_0 = _mm_clmulepi64_si128(xmm_a0_0, xmm_fold4, 0x01);
219
220 ps_crc3 = _mm_castsi128_ps(*xmm_crc3);
221 psa0_0 = _mm_castsi128_ps(xmm_a0_0);
222 psa0_1 = _mm_castsi128_ps(xmm_a0_1);
223
224 ps_res = _mm_xor_ps(ps_crc3, psa0_0);
225 ps_res = _mm_xor_ps(ps_res, psa0_1);
226
227 *xmm_crc3 = _mm_castps_si128(ps_res);
228}
229
230ZLIB_INTERNAL void crc_fold_copy(deflate_state *const s, unsigned char *dst, const unsigned char *src, long len) {
231 unsigned long algn_diff;
232 __m128i xmm_t0, xmm_t1, xmm_t2, xmm_t3;
233 char ALIGNED_(16) partial_buf[16] = { 0 };
234
235 /* CRC_LOAD */
236 __m128i xmm_crc0 = _mm_loadu_si128((__m128i *)s->crc0 + 0);
237 __m128i xmm_crc1 = _mm_loadu_si128((__m128i *)s->crc0 + 1);
238 __m128i xmm_crc2 = _mm_loadu_si128((__m128i *)s->crc0 + 2);
239 __m128i xmm_crc3 = _mm_loadu_si128((__m128i *)s->crc0 + 3);
240 __m128i xmm_crc_part;
241
242 if (len < 16) {
243 if (len == 0)
244 return;
245
246 memcpy(partial_buf, src, len);
247 xmm_crc_part = _mm_loadu_si128((const __m128i *)partial_buf);
248 memcpy(dst, partial_buf, len);
249 goto partial;
250 }
251
252 algn_diff = ((uintptr_t)0 - (uintptr_t)src) & 0xF;
253 if (algn_diff) {
254 xmm_crc_part = _mm_loadu_si128((__m128i *)src);
255 _mm_storeu_si128((__m128i *)dst, xmm_crc_part);
256
257 dst += algn_diff;
258 src += algn_diff;
259 len -= algn_diff;
260
261 partial_fold(algn_diff, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3, &xmm_crc_part);
262 } else {
263 xmm_crc_part = _mm_setzero_si128();
264 }
265
266 while ((len -= 64) >= 0) {
267 /* CRC_LOAD */
268 xmm_t0 = _mm_load_si128((__m128i *)src);
269 xmm_t1 = _mm_load_si128((__m128i *)src + 1);
270 xmm_t2 = _mm_load_si128((__m128i *)src + 2);
271 xmm_t3 = _mm_load_si128((__m128i *)src + 3);
272
273 fold_4(&xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3);
274
275 /* CRC_SAVE */
276 _mm_storeu_si128((__m128i *)dst, xmm_t0);
277 _mm_storeu_si128((__m128i *)dst + 1, xmm_t1);
278 _mm_storeu_si128((__m128i *)dst + 2, xmm_t2);
279 _mm_storeu_si128((__m128i *)dst + 3, xmm_t3);
280
281 xmm_crc0 = _mm_xor_si128(xmm_crc0, xmm_t0);
282 xmm_crc1 = _mm_xor_si128(xmm_crc1, xmm_t1);
283 xmm_crc2 = _mm_xor_si128(xmm_crc2, xmm_t2);
284 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_t3);
285
286 src += 64;
287 dst += 64;
288 }
289
290 /*
291 * len = num bytes left - 64
292 */
293 if (len + 16 >= 0) {
294 len += 16;
295
296 xmm_t0 = _mm_load_si128((__m128i *)src);
297 xmm_t1 = _mm_load_si128((__m128i *)src + 1);
298 xmm_t2 = _mm_load_si128((__m128i *)src + 2);
299
300 fold_3(&xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3);
301
302 _mm_storeu_si128((__m128i *)dst, xmm_t0);
303 _mm_storeu_si128((__m128i *)dst + 1, xmm_t1);
304 _mm_storeu_si128((__m128i *)dst + 2, xmm_t2);
305
306 xmm_crc1 = _mm_xor_si128(xmm_crc1, xmm_t0);
307 xmm_crc2 = _mm_xor_si128(xmm_crc2, xmm_t1);
308 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_t2);
309
310 if (len == 0)
311 goto done;
312
313 dst += 48;
314 memcpy(&xmm_crc_part, (__m128i *)src + 3, len);
315 } else if (len + 32 >= 0) {
316 len += 32;
317
318 xmm_t0 = _mm_load_si128((__m128i *)src);
319 xmm_t1 = _mm_load_si128((__m128i *)src + 1);
320
321 fold_2(&xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3);
322
323 _mm_storeu_si128((__m128i *)dst, xmm_t0);
324 _mm_storeu_si128((__m128i *)dst + 1, xmm_t1);
325
326 xmm_crc2 = _mm_xor_si128(xmm_crc2, xmm_t0);
327 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_t1);
328
329 if (len == 0)
330 goto done;
331
332 dst += 32;
333 memcpy(&xmm_crc_part, (__m128i *)src + 2, len);
334 } else if (len + 48 >= 0) {
335 len += 48;
336
337 xmm_t0 = _mm_load_si128((__m128i *)src);
338
339 fold_1(&xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3);
340
341 _mm_storeu_si128((__m128i *)dst, xmm_t0);
342
343 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_t0);
344
345 if (len == 0)
346 goto done;
347
348 dst += 16;
349 memcpy(&xmm_crc_part, (__m128i *)src + 1, len);
350 } else {
351 len += 64;
352 if (len == 0)
353 goto done;
354 memcpy(&xmm_crc_part, src, len);
355 }
356
357 _mm_storeu_si128((__m128i *)partial_buf, xmm_crc_part);
358 memcpy(dst, partial_buf, len);
359
360partial:
361 partial_fold(len, &xmm_crc0, &xmm_crc1, &xmm_crc2, &xmm_crc3, &xmm_crc_part);
362done:
363 /* CRC_SAVE */
364 _mm_storeu_si128((__m128i *)s->crc0 + 0, xmm_crc0);
365 _mm_storeu_si128((__m128i *)s->crc0 + 1, xmm_crc1);
366 _mm_storeu_si128((__m128i *)s->crc0 + 2, xmm_crc2);
367 _mm_storeu_si128((__m128i *)s->crc0 + 3, xmm_crc3);
368 _mm_storeu_si128((__m128i *)s->crc0 + 4, xmm_crc_part);
369}
370
371static const unsigned ALIGNED_(16) crc_k[] = {
372 0xccaa009e, 0x00000000, /* rk1 */
373 0x751997d0, 0x00000001, /* rk2 */
374 0xccaa009e, 0x00000000, /* rk5 */
375 0x63cd6124, 0x00000001, /* rk6 */
376 0xf7011640, 0x00000001, /* rk7 */
377 0xdb710640, 0x00000001 /* rk8 */
378};
379
380static const unsigned ALIGNED_(16) crc_mask[4] = {
381 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000
382};
383
384static const unsigned ALIGNED_(16) crc_mask2[4] = {
385 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF
386};
387
388uint32_t ZLIB_INTERNAL crc_fold_512to32(deflate_state *const s) {
389 const __m128i xmm_mask = _mm_load_si128((__m128i *)crc_mask);
390 const __m128i xmm_mask2 = _mm_load_si128((__m128i *)crc_mask2);
391
392 uint32_t crc;
393 __m128i x_tmp0, x_tmp1, x_tmp2, crc_fold;
394
395 /* CRC_LOAD */
396 __m128i xmm_crc0 = _mm_loadu_si128((__m128i *)s->crc0 + 0);
397 __m128i xmm_crc1 = _mm_loadu_si128((__m128i *)s->crc0 + 1);
398 __m128i xmm_crc2 = _mm_loadu_si128((__m128i *)s->crc0 + 2);
399 __m128i xmm_crc3 = _mm_loadu_si128((__m128i *)s->crc0 + 3);
400
401 /*
402 * k1
403 */
404 crc_fold = _mm_load_si128((__m128i *)crc_k);
405
406 x_tmp0 = _mm_clmulepi64_si128(xmm_crc0, crc_fold, 0x10);
407 xmm_crc0 = _mm_clmulepi64_si128(xmm_crc0, crc_fold, 0x01);
408 xmm_crc1 = _mm_xor_si128(xmm_crc1, x_tmp0);
409 xmm_crc1 = _mm_xor_si128(xmm_crc1, xmm_crc0);
410
411 x_tmp1 = _mm_clmulepi64_si128(xmm_crc1, crc_fold, 0x10);
412 xmm_crc1 = _mm_clmulepi64_si128(xmm_crc1, crc_fold, 0x01);
413 xmm_crc2 = _mm_xor_si128(xmm_crc2, x_tmp1);
414 xmm_crc2 = _mm_xor_si128(xmm_crc2, xmm_crc1);
415
416 x_tmp2 = _mm_clmulepi64_si128(xmm_crc2, crc_fold, 0x10);
417 xmm_crc2 = _mm_clmulepi64_si128(xmm_crc2, crc_fold, 0x01);
418 xmm_crc3 = _mm_xor_si128(xmm_crc3, x_tmp2);
419 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_crc2);
420
421 /*
422 * k5
423 */
424 crc_fold = _mm_load_si128((__m128i *)crc_k + 1);
425
426 xmm_crc0 = xmm_crc3;
427 xmm_crc3 = _mm_clmulepi64_si128(xmm_crc3, crc_fold, 0);
428 xmm_crc0 = _mm_srli_si128(xmm_crc0, 8);
429 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_crc0);
430
431 xmm_crc0 = xmm_crc3;
432 xmm_crc3 = _mm_slli_si128(xmm_crc3, 4);
433 xmm_crc3 = _mm_clmulepi64_si128(xmm_crc3, crc_fold, 0x10);
434 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_crc0);
435 xmm_crc3 = _mm_and_si128(xmm_crc3, xmm_mask2);
436
437 /*
438 * k7
439 */
440 xmm_crc1 = xmm_crc3;
441 xmm_crc2 = xmm_crc3;
442 crc_fold = _mm_load_si128((__m128i *)crc_k + 2);
443
444 xmm_crc3 = _mm_clmulepi64_si128(xmm_crc3, crc_fold, 0);
445 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_crc2);
446 xmm_crc3 = _mm_and_si128(xmm_crc3, xmm_mask);
447
448 xmm_crc2 = xmm_crc3;
449 xmm_crc3 = _mm_clmulepi64_si128(xmm_crc3, crc_fold, 0x10);
450 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_crc2);
451 xmm_crc3 = _mm_xor_si128(xmm_crc3, xmm_crc1);
452
453 crc = _mm_extract_epi32(xmm_crc3, 2);
454 return ~crc;
455}
456
457#endif
458
459