3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 only,
7 * as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License version 2 for more details (a copy is included
13 * in the LICENSE file that accompanied this code).
15 * You should have received a copy of the GNU General Public License
16 * version 2 along with this program; If not, see http://www.gnu.org/licenses
18 * Please visit http://www.xyratex.com/contact if you need additional
19 * information or have any questions.
25 * Copyright 2012 Xyratex Technology Limited
27 * Using hardware provided PCLMULQDQ instruction to accelerate the CRC32
29 * CRC32 polynomial:0x04c11db7(BE)/0xEDB88320(LE)
30 * PCLMULQDQ is a new instruction in Intel SSE4.2, the reference can be found
32 * http://www.intel.com/products/processor/manuals/
33 * Intel(R) 64 and IA-32 Architectures Software Developer's Manual
34 * Volume 2B: Instruction Set Reference, N-Z
36 * Authors: Gregory Prestas <Gregory_Prestas@us.xyratex.com>
37 * Alexander Boyko <Alexander_Boyko@xyratex.com>
40 #include <linux/linkage.h>
46 * [x4*128+32 mod P(x) << 32)]' << 1 = 0x154442bd4
47 * #define CONSTANT_R1 0x154442bd4LL
49 * [(x4*128-32 mod P(x) << 32)]' << 1 = 0x1c6e41596
50 * #define CONSTANT_R2 0x1c6e41596LL
53 .octa 0x00000001c6e415960000000154442bd4
55 * [(x128+32 mod P(x) << 32)]' << 1 = 0x1751997d0
56 * #define CONSTANT_R3 0x1751997d0LL
58 * [(x128-32 mod P(x) << 32)]' << 1 = 0x0ccaa009e
59 * #define CONSTANT_R4 0x0ccaa009eLL
62 .octa 0x00000000ccaa009e00000001751997d0
64 * [(x64 mod P(x) << 32)]' << 1 = 0x163cd6124
65 * #define CONSTANT_R5 0x163cd6124LL
68 .octa 0x00000000000000000000000163cd6124
70 .octa 0x000000000000000000000000FFFFFFFF
72 * #define CRCPOLY_TRUE_LE_FULL 0x1DB710641LL
74 * Barrett Reduction constant (u64`) = u` = (x**64 / P(x))` = 0x1F7011641LL
75 * #define CONSTANT_RU 0x1F7011641LL
78 .octa 0x00000001F701164100000001DB710641
80 #define CONSTANT %xmm0
97 * BUF - buffer (16 bytes aligned)
98 * LEN - sizeof buffer (16 bytes aligned), LEN should be grater than 63
101 * uint crc32_pclmul_le_16(unsigned char const *buffer,
102 * size_t len, uint crc32)
105 ENTRY(crc32_pclmul_le_16) /* buffer and buffer size are 16 bytes aligned */
107 movdqa 0x10(BUF), %xmm2
108 movdqa 0x20(BUF), %xmm3
109 movdqa 0x30(BUF), %xmm4
115 /* This is for position independent code(-fPIC) support for 32bit */
124 movdqa .Lconstant_R2R1(%rip), CONSTANT
126 movdqa .Lconstant_R2R1 - delta(%ecx), CONSTANT
129 loop_64:/* 64 bytes Full cache line folding */
130 prefetchnta 0x40(BUF)
137 PCLMULQDQ 00, CONSTANT, %xmm1
138 PCLMULQDQ 00, CONSTANT, %xmm2
139 PCLMULQDQ 00, CONSTANT, %xmm3
141 PCLMULQDQ 00, CONSTANT, %xmm4
143 PCLMULQDQ 0x11, CONSTANT, %xmm5
144 PCLMULQDQ 0x11, CONSTANT, %xmm6
145 PCLMULQDQ 0x11, CONSTANT, %xmm7
147 PCLMULQDQ 0x11, CONSTANT, %xmm8
155 /* xmm8 unsupported for x32 */
157 PCLMULQDQ 00, CONSTANT, %xmm4
158 PCLMULQDQ 0x11, CONSTANT, %xmm5
163 pxor 0x10(BUF), %xmm2
164 pxor 0x20(BUF), %xmm3
165 pxor 0x30(BUF), %xmm4
171 less_64:/* Folding cache line into 128bit */
173 movdqa .Lconstant_R4R3(%rip), CONSTANT
175 movdqa .Lconstant_R4R3 - delta(%ecx), CONSTANT
180 PCLMULQDQ 0x00, CONSTANT, %xmm1
181 PCLMULQDQ 0x11, CONSTANT, %xmm5
186 PCLMULQDQ 0x00, CONSTANT, %xmm1
187 PCLMULQDQ 0x11, CONSTANT, %xmm5
192 PCLMULQDQ 0x00, CONSTANT, %xmm1
193 PCLMULQDQ 0x11, CONSTANT, %xmm5
199 loop_16:/* Folding rest buffer into 128bit */
201 PCLMULQDQ 0x00, CONSTANT, %xmm1
202 PCLMULQDQ 0x11, CONSTANT, %xmm5
211 /* perform the last 64 bit fold, also adds 32 zeroes
212 * to the input stream */
213 PCLMULQDQ 0x01, %xmm1, CONSTANT /* R4 * xmm1.low */
217 /* final 32-bit fold */
220 movdqa .Lconstant_R5(%rip), CONSTANT
221 movdqa .Lconstant_mask32(%rip), %xmm3
223 movdqa .Lconstant_R5 - delta(%ecx), CONSTANT
224 movdqa .Lconstant_mask32 - delta(%ecx), %xmm3
228 PCLMULQDQ 0x00, CONSTANT, %xmm1
231 /* Finish up with the bit-reversed barrett reduction 64 ==> 32 bits */
233 movdqa .Lconstant_RUpoly(%rip), CONSTANT
235 movdqa .Lconstant_RUpoly - delta(%ecx), CONSTANT
239 PCLMULQDQ 0x10, CONSTANT, %xmm1
241 PCLMULQDQ 0x00, CONSTANT, %xmm1
243 PEXTRD 0x01, %xmm1, %eax
246 ENDPROC(crc32_pclmul_le_16)