1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46#include <linux/linkage.h>
47#include <asm/nospec-branch.h>
48
49
50
51.macro LABEL prefix n
52\prefix\n\():
53.endm
54
55.macro JMPTBL_ENTRY i
56.quad crc_\i
57.endm
58
59.macro JNC_LESS_THAN j
60 jnc less_than_\j
61.endm
62
63
64
65
66
67#define SMALL_SIZE 200
68
69.if (SMALL_SIZE > 255)
70.error "SMALL_ SIZE must be < 256"
71.endif
72
73
74
75.text
76SYM_FUNC_START(crc_pcl)
77#define bufp rdi
78#define bufp_dw %edi
79#define bufp_w %di
80#define bufp_b %dil
81#define bufptmp %rcx
82#define block_0 %rcx
83#define block_1 %rdx
84#define block_2 %r11
85#define len %rsi
86#define len_dw %esi
87#define len_w %si
88#define len_b %sil
89#define crc_init_arg %rdx
90#define tmp %rbx
91#define crc_init %r8
92#define crc_init_dw %r8d
93#define crc1 %r9
94#define crc2 %r10
95
96 pushq %rbx
97 pushq %rdi
98 pushq %rsi
99
100
101 mov crc_init_arg, crc_init
102
103
104
105
106
107 mov %bufp, bufptmp
108 neg %bufp
109 and $7, %bufp
110
111 je proc_block
112
113
114
115 cmp $8, len
116 jae do_align
117
118
119 shl $32-3+1, len_dw
120 jmp less_than_8_post_shl1
121
122do_align:
123
124 movq (bufptmp), tmp
125 add %bufp, bufptmp
126
127 sub %bufp, len
128align_loop:
129 crc32b %bl, crc_init_dw
130 shr $8, tmp
131 dec %bufp
132 jne align_loop
133
134proc_block:
135
136
137
138
139
140
141 movq len, tmp
142
143 cmpq $128*24, len
144 jae full_block
145
146continue_block:
147 cmpq $SMALL_SIZE, len
148 jb small
149
150
151 movq $2731, %rax
152 mul len_dw
153 shrq $16, %rax
154
155
156
157
158
159
160
161
162
163 lea (bufptmp, %rax, 8), block_0
164 lea (block_0, %rax, 8), block_1
165 lea (block_1, %rax, 8), block_2
166
167 xor crc1, crc1
168 xor crc2, crc2
169
170
171 mov jump_table(,%rax,8), %bufp
172 JMP_NOSPEC bufp
173
174
175
176
177full_block:
178 movl $128,%eax
179 lea 128*8*2(block_0), block_1
180 lea 128*8*3(block_0), block_2
181 add $128*8*1, block_0
182
183 xor crc1,crc1
184 xor crc2,crc2
185
186
187
188
189
190
191
192crc_array:
193 i=128
194.rept 128-1
195.altmacro
196LABEL crc_ %i
197.noaltmacro
198 crc32q -i*8(block_0), crc_init
199 crc32q -i*8(block_1), crc1
200 crc32q -i*8(block_2), crc2
201 i=(i-1)
202.endr
203
204.altmacro
205LABEL crc_ %i
206.noaltmacro
207 crc32q -i*8(block_0), crc_init
208 crc32q -i*8(block_1), crc1
209
210
211 mov block_2, block_0
212
213
214
215
216
217 lea (K_table-8)(%rip), %bufp
218 shlq $3, %rax
219 pmovzxdq (%bufp,%rax), %xmm0
220 leal (%eax,%eax,2), %eax
221 subq %rax, tmp
222
223 movq crc_init, %xmm1
224 pclmulqdq $0x00, %xmm0, %xmm1
225
226 movq crc1, %xmm2
227 pclmulqdq $0x10, %xmm0, %xmm2
228
229 pxor %xmm2,%xmm1
230 movq %xmm1, %rax
231 xor -i*8(block_2), %rax
232 mov crc2, crc_init
233 crc32 %rax, crc_init
234
235
236
237
238
239LABEL crc_ 0
240 mov tmp, len
241 cmp $128*24, tmp
242 jae full_block
243 cmp $24, tmp
244 jae continue_block
245
246less_than_24:
247 shl $32-4, len_dw
248
249 jnc less_than_16
250 crc32q (bufptmp), crc_init
251 crc32q 8(bufptmp), crc_init
252 jz do_return
253 add $16, bufptmp
254
255
256
257 shl $2, len_dw
258 jmp less_than_8_post_shl1
259
260
261
262
263small:
264 shl $32-8, len_dw
265 j=256
266.rept 5
267.altmacro
268LABEL less_than_ %j
269
270 j=(j/2)
271 shl $1, len_dw
272 JNC_LESS_THAN %j
273.noaltmacro
274 i=0
275.rept (j/8)
276 crc32q i(bufptmp), crc_init
277 i=i+8
278.endr
279 jz do_return
280 add $j, bufptmp
281.endr
282
283less_than_8:
284
285 shl $1, len_dw
286less_than_8_post_shl1:
287 jnc less_than_4
288 crc32l (bufptmp), crc_init_dw
289 jz do_return
290 add $4, bufptmp
291less_than_4:
292
293 shl $1, len_dw
294 jnc less_than_2
295 crc32w (bufptmp), crc_init_dw
296 jz do_return
297 add $2, bufptmp
298less_than_2:
299
300 shl $1, len_dw
301 jnc less_than_1
302 crc32b (bufptmp), crc_init_dw
303less_than_1:
304do_return:
305 movq crc_init, %rax
306 popq %rsi
307 popq %rdi
308 popq %rbx
309 ret
310SYM_FUNC_END(crc_pcl)
311
312.section .rodata, "a", @progbits
313
314
315
316.align 4
317jump_table:
318 i=0
319.rept 129
320.altmacro
321JMPTBL_ENTRY %i
322.noaltmacro
323 i=i+1
324.endr
325
326
327
328
329
330
331.align 8
332K_table:
333 .long 0x493c7d27, 0x00000001
334 .long 0xba4fc28e, 0x493c7d27
335 .long 0xddc0152b, 0xf20c0dfe
336 .long 0x9e4addf8, 0xba4fc28e
337 .long 0x39d3b296, 0x3da6d0cb
338 .long 0x0715ce53, 0xddc0152b
339 .long 0x47db8317, 0x1c291d04
340 .long 0x0d3b6092, 0x9e4addf8
341 .long 0xc96cfdc0, 0x740eef02
342 .long 0x878a92a7, 0x39d3b296
343 .long 0xdaece73e, 0x083a6eec
344 .long 0xab7aff2a, 0x0715ce53
345 .long 0x2162d385, 0xc49f4f67
346 .long 0x83348832, 0x47db8317
347 .long 0x299847d5, 0x2ad91c30
348 .long 0xb9e02b86, 0x0d3b6092
349 .long 0x18b33a4e, 0x6992cea2
350 .long 0xb6dd949b, 0xc96cfdc0
351 .long 0x78d9ccb7, 0x7e908048
352 .long 0xbac2fd7b, 0x878a92a7
353 .long 0xa60ce07b, 0x1b3d8f29
354 .long 0xce7f39f4, 0xdaece73e
355 .long 0x61d82e56, 0xf1d0f55e
356 .long 0xd270f1a2, 0xab7aff2a
357 .long 0xc619809d, 0xa87ab8a8
358 .long 0x2b3cac5d, 0x2162d385
359 .long 0x65863b64, 0x8462d800
360 .long 0x1b03397f, 0x83348832
361 .long 0xebb883bd, 0x71d111a8
362 .long 0xb3e32c28, 0x299847d5
363 .long 0x064f7f26, 0xffd852c6
364 .long 0xdd7e3b0c, 0xb9e02b86
365 .long 0xf285651c, 0xdcb17aa4
366 .long 0x10746f3c, 0x18b33a4e
367 .long 0xc7a68855, 0xf37c5aee
368 .long 0x271d9844, 0xb6dd949b
369 .long 0x8e766a0c, 0x6051d5a2
370 .long 0x93a5f730, 0x78d9ccb7
371 .long 0x6cb08e5c, 0x18b0d4ff
372 .long 0x6b749fb2, 0xbac2fd7b
373 .long 0x1393e203, 0x21f3d99c
374 .long 0xcec3662e, 0xa60ce07b
375 .long 0x96c515bb, 0x8f158014
376 .long 0xe6fc4e6a, 0xce7f39f4
377 .long 0x8227bb8a, 0xa00457f7
378 .long 0xb0cd4768, 0x61d82e56
379 .long 0x39c7ff35, 0x8d6d2c43
380 .long 0xd7a4825c, 0xd270f1a2
381 .long 0x0ab3844b, 0x00ac29cf
382 .long 0x0167d312, 0xc619809d
383 .long 0xf6076544, 0xe9adf796
384 .long 0x26f6a60a, 0x2b3cac5d
385 .long 0xa741c1bf, 0x96638b34
386 .long 0x98d8d9cb, 0x65863b64
387 .long 0x49c3cc9c, 0xe0e9f351
388 .long 0x68bce87a, 0x1b03397f
389 .long 0x57a3d037, 0x9af01f2d
390 .long 0x6956fc3b, 0xebb883bd
391 .long 0x42d98888, 0x2cff42cf
392 .long 0x3771e98f, 0xb3e32c28
393 .long 0xb42ae3d9, 0x88f25a3a
394 .long 0x2178513a, 0x064f7f26
395 .long 0xe0ac139e, 0x4e36f0b0
396 .long 0x170076fa, 0xdd7e3b0c
397 .long 0x444dd413, 0xbd6f81f8
398 .long 0x6f345e45, 0xf285651c
399 .long 0x41d17b64, 0x91c9bd4b
400 .long 0xff0dba97, 0x10746f3c
401 .long 0xa2b73df1, 0x885f087b
402 .long 0xf872e54c, 0xc7a68855
403 .long 0x1e41e9fc, 0x4c144932
404 .long 0x86d8e4d2, 0x271d9844
405 .long 0x651bd98b, 0x52148f02
406 .long 0x5bb8f1bc, 0x8e766a0c
407 .long 0xa90fd27a, 0xa3c6f37a
408 .long 0xb3af077a, 0x93a5f730
409 .long 0x4984d782, 0xd7c0557f
410 .long 0xca6ef3ac, 0x6cb08e5c
411 .long 0x234e0b26, 0x63ded06a
412 .long 0xdd66cbbb, 0x6b749fb2
413 .long 0x4597456a, 0x4d56973c
414 .long 0xe9e28eb4, 0x1393e203
415 .long 0x7b3ff57a, 0x9669c9df
416 .long 0xc9c8b782, 0xcec3662e
417 .long 0x3f70cc6f, 0xe417f38a
418 .long 0x93e106a4, 0x96c515bb
419 .long 0x62ec6c6d, 0x4b9e0f71
420 .long 0xd813b325, 0xe6fc4e6a
421 .long 0x0df04680, 0xd104b8fc
422 .long 0x2342001e, 0x8227bb8a
423 .long 0x0a2a8d7e, 0x5b397730
424 .long 0x6d9a4957, 0xb0cd4768
425 .long 0xe8b6368b, 0xe78eb416
426 .long 0xd2c3ed1a, 0x39c7ff35
427 .long 0x995a5724, 0x61ff0e01
428 .long 0x9ef68d35, 0xd7a4825c
429 .long 0x0c139b31, 0x8d96551c
430 .long 0xf2271e60, 0x0ab3844b
431 .long 0x0b0bf8ca, 0x0bf80dd2
432 .long 0x2664fd8b, 0x0167d312
433 .long 0xed64812d, 0x8821abed
434 .long 0x02ee03b2, 0xf6076544
435 .long 0x8604ae0f, 0x6a45d2b2
436 .long 0x363bd6b3, 0x26f6a60a
437 .long 0x135c83fd, 0xd8d26619
438 .long 0x5fabe670, 0xa741c1bf
439 .long 0x35ec3279, 0xde87806c
440 .long 0x00bcf5f6, 0x98d8d9cb
441 .long 0x8ae00689, 0x14338754
442 .long 0x17f27698, 0x49c3cc9c
443 .long 0x58ca5f00, 0x5bd2011f
444 .long 0xaa7c7ad5, 0x68bce87a
445 .long 0xb5cfca28, 0xdd07448e
446 .long 0xded288f8, 0x57a3d037
447 .long 0x59f229bc, 0xdde8f5b9
448 .long 0x6d390dec, 0x6956fc3b
449 .long 0x37170390, 0xa3e3e02c
450 .long 0x6353c1cc, 0x42d98888
451 .long 0xc4584f5c, 0xd73c7bea
452 .long 0xf48642e9, 0x3771e98f
453 .long 0x531377e2, 0x80ff0093
454 .long 0xdd35bc8d, 0xb42ae3d9
455 .long 0xb25b29f2, 0x8fe4c34d
456 .long 0x9a5ede41, 0x2178513a
457 .long 0xa563905d, 0xdf99fc11
458 .long 0x45cddf4e, 0xe0ac139e
459 .long 0xacfa3103, 0x6c23e841
460 .long 0xa51b6135, 0x170076fa
461