2 * Copyright (C) 2012 Intel Corporation
3 * Author: Jim Kukunas <james.t.kukunas@linux.intel.com>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; version 2
13 #include <linux/raid/pq.h>
16 static int raid6_has_avx2(void)
18 return boot_cpu_has(X86_FEATURE_AVX2) &&
19 boot_cpu_has(X86_FEATURE_AVX);
22 static void raid6_2data_recov_avx2(int disks, size_t bytes, int faila,
23 int failb, void **ptrs)
26 const u8 *pbmul; /* P multiplier table for B data */
27 const u8 *qmul; /* Q multiplier table (for both) */
30 p = (u8 *)ptrs[disks-2];
31 q = (u8 *)ptrs[disks-1];
33 /* Compute syndrome with zero for the missing data pages
34 Use the dead data pages as temporary storage for
35 delta p and delta q */
36 dp = (u8 *)ptrs[faila];
37 ptrs[faila] = (void *)raid6_empty_zero_page;
39 dq = (u8 *)ptrs[failb];
40 ptrs[failb] = (void *)raid6_empty_zero_page;
43 raid6_call.gen_syndrome(disks, bytes, ptrs);
45 /* Restore pointer table */
51 /* Now, pick the proper data tables */
52 pbmul = raid6_vgfmul[raid6_gfexi[failb-faila]];
53 qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila] ^
59 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f));
63 asm volatile("vmovdqa %0, %%ymm1" : : "m" (q[0]));
64 asm volatile("vmovdqa %0, %%ymm9" : : "m" (q[32]));
65 asm volatile("vmovdqa %0, %%ymm0" : : "m" (p[0]));
66 asm volatile("vmovdqa %0, %%ymm8" : : "m" (p[32]));
67 asm volatile("vpxor %0, %%ymm1, %%ymm1" : : "m" (dq[0]));
68 asm volatile("vpxor %0, %%ymm9, %%ymm9" : : "m" (dq[32]));
69 asm volatile("vpxor %0, %%ymm0, %%ymm0" : : "m" (dp[0]));
70 asm volatile("vpxor %0, %%ymm8, %%ymm8" : : "m" (dp[32]));
79 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (qmul[0]));
80 asm volatile("vbroadcasti128 %0, %%ymm5" : : "m" (qmul[16]));
82 asm volatile("vpsraw $4, %ymm1, %ymm3");
83 asm volatile("vpsraw $4, %ymm9, %ymm12");
84 asm volatile("vpand %ymm7, %ymm1, %ymm1");
85 asm volatile("vpand %ymm7, %ymm9, %ymm9");
86 asm volatile("vpand %ymm7, %ymm3, %ymm3");
87 asm volatile("vpand %ymm7, %ymm12, %ymm12");
88 asm volatile("vpshufb %ymm9, %ymm4, %ymm14");
89 asm volatile("vpshufb %ymm1, %ymm4, %ymm4");
90 asm volatile("vpshufb %ymm12, %ymm5, %ymm15");
91 asm volatile("vpshufb %ymm3, %ymm5, %ymm5");
92 asm volatile("vpxor %ymm14, %ymm15, %ymm15");
93 asm volatile("vpxor %ymm4, %ymm5, %ymm5");
100 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (pbmul[0]));
101 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (pbmul[16]));
102 asm volatile("vpsraw $4, %ymm0, %ymm2");
103 asm volatile("vpsraw $4, %ymm8, %ymm6");
104 asm volatile("vpand %ymm7, %ymm0, %ymm3");
105 asm volatile("vpand %ymm7, %ymm8, %ymm14");
106 asm volatile("vpand %ymm7, %ymm2, %ymm2");
107 asm volatile("vpand %ymm7, %ymm6, %ymm6");
108 asm volatile("vpshufb %ymm14, %ymm4, %ymm12");
109 asm volatile("vpshufb %ymm3, %ymm4, %ymm4");
110 asm volatile("vpshufb %ymm6, %ymm1, %ymm13");
111 asm volatile("vpshufb %ymm2, %ymm1, %ymm1");
112 asm volatile("vpxor %ymm4, %ymm1, %ymm1");
113 asm volatile("vpxor %ymm12, %ymm13, %ymm13");
119 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
120 asm volatile("vpxor %ymm15, %ymm13, %ymm13");
124 * 13 = db[32] = DQ[32]
126 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
127 asm volatile("vmovdqa %%ymm13,%0" : "=m" (dq[32]));
128 asm volatile("vpxor %ymm1, %ymm0, %ymm0");
129 asm volatile("vpxor %ymm13, %ymm8, %ymm8");
131 asm volatile("vmovdqa %%ymm0, %0" : "=m" (dp[0]));
132 asm volatile("vmovdqa %%ymm8, %0" : "=m" (dp[32]));
140 asm volatile("vmovdqa %0, %%ymm1" : : "m" (*q));
141 asm volatile("vmovdqa %0, %%ymm0" : : "m" (*p));
142 asm volatile("vpxor %0, %%ymm1, %%ymm1" : : "m" (*dq));
143 asm volatile("vpxor %0, %%ymm0, %%ymm0" : : "m" (*dp));
145 /* 1 = dq ^ q; 0 = dp ^ p */
147 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (qmul[0]));
148 asm volatile("vbroadcasti128 %0, %%ymm5" : : "m" (qmul[16]));
154 asm volatile("vpsraw $4, %ymm1, %ymm3");
155 asm volatile("vpand %ymm7, %ymm1, %ymm1");
156 asm volatile("vpand %ymm7, %ymm3, %ymm3");
157 asm volatile("vpshufb %ymm1, %ymm4, %ymm4");
158 asm volatile("vpshufb %ymm3, %ymm5, %ymm5");
159 asm volatile("vpxor %ymm4, %ymm5, %ymm5");
163 asm volatile("vbroadcasti128 %0, %%ymm4" : : "m" (pbmul[0]));
164 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (pbmul[16]));
166 asm volatile("vpsraw $4, %ymm0, %ymm2");
167 asm volatile("vpand %ymm7, %ymm0, %ymm3");
168 asm volatile("vpand %ymm7, %ymm2, %ymm2");
169 asm volatile("vpshufb %ymm3, %ymm4, %ymm4");
170 asm volatile("vpshufb %ymm2, %ymm1, %ymm1");
171 asm volatile("vpxor %ymm4, %ymm1, %ymm1");
174 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
176 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
178 asm volatile("vpxor %ymm1, %ymm0, %ymm0");
179 asm volatile("vmovdqa %%ymm0, %0" : "=m" (dp[0]));
192 static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila,
196 const u8 *qmul; /* Q multiplier table */
199 p = (u8 *)ptrs[disks-2];
200 q = (u8 *)ptrs[disks-1];
202 /* Compute syndrome with zero for the missing data page
203 Use the dead data page as temporary storage for delta q */
204 dq = (u8 *)ptrs[faila];
205 ptrs[faila] = (void *)raid6_empty_zero_page;
208 raid6_call.gen_syndrome(disks, bytes, ptrs);
210 /* Restore pointer table */
214 /* Now, pick the proper data tables */
215 qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila]]];
219 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f));
223 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq[0]));
224 asm volatile("vmovdqa %0, %%ymm8" : : "m" (dq[32]));
225 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q[0]));
226 asm volatile("vpxor %0, %%ymm8, %%ymm8" : : "m" (q[32]));
232 asm volatile("vbroadcasti128 %0, %%ymm0" : : "m" (qmul[0]));
233 asm volatile("vmovapd %ymm0, %ymm13");
234 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (qmul[16]));
235 asm volatile("vmovapd %ymm1, %ymm14");
237 asm volatile("vpsraw $4, %ymm3, %ymm6");
238 asm volatile("vpsraw $4, %ymm8, %ymm12");
239 asm volatile("vpand %ymm7, %ymm3, %ymm3");
240 asm volatile("vpand %ymm7, %ymm8, %ymm8");
241 asm volatile("vpand %ymm7, %ymm6, %ymm6");
242 asm volatile("vpand %ymm7, %ymm12, %ymm12");
243 asm volatile("vpshufb %ymm3, %ymm0, %ymm0");
244 asm volatile("vpshufb %ymm8, %ymm13, %ymm13");
245 asm volatile("vpshufb %ymm6, %ymm1, %ymm1");
246 asm volatile("vpshufb %ymm12, %ymm14, %ymm14");
247 asm volatile("vpxor %ymm0, %ymm1, %ymm1");
248 asm volatile("vpxor %ymm13, %ymm14, %ymm14");
251 * 1 = qmul[q[0] ^ dq[0]]
252 * 14 = qmul[q[32] ^ dq[32]]
254 asm volatile("vmovdqa %0, %%ymm2" : : "m" (p[0]));
255 asm volatile("vmovdqa %0, %%ymm12" : : "m" (p[32]));
256 asm volatile("vpxor %ymm1, %ymm2, %ymm2");
257 asm volatile("vpxor %ymm14, %ymm12, %ymm12");
260 * 2 = p[0] ^ qmul[q[0] ^ dq[0]]
261 * 12 = p[32] ^ qmul[q[32] ^ dq[32]]
264 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
265 asm volatile("vmovdqa %%ymm14, %0" : "=m" (dq[32]));
266 asm volatile("vmovdqa %%ymm2, %0" : "=m" (p[0]));
267 asm volatile("vmovdqa %%ymm12,%0" : "=m" (p[32]));
274 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq[0]));
275 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q[0]));
279 asm volatile("vbroadcasti128 %0, %%ymm0" : : "m" (qmul[0]));
280 asm volatile("vbroadcasti128 %0, %%ymm1" : : "m" (qmul[16]));
282 asm volatile("vpsraw $4, %ymm3, %ymm6");
283 asm volatile("vpand %ymm7, %ymm3, %ymm3");
284 asm volatile("vpand %ymm7, %ymm6, %ymm6");
285 asm volatile("vpshufb %ymm3, %ymm0, %ymm0");
286 asm volatile("vpshufb %ymm6, %ymm1, %ymm1");
287 asm volatile("vpxor %ymm0, %ymm1, %ymm1");
289 /* 1 = qmul[q ^ dq] */
291 asm volatile("vmovdqa %0, %%ymm2" : : "m" (p[0]));
292 asm volatile("vpxor %ymm1, %ymm2, %ymm2");
294 /* 2 = p ^ qmul[q ^ dq] */
296 asm volatile("vmovdqa %%ymm1, %0" : "=m" (dq[0]));
297 asm volatile("vmovdqa %%ymm2, %0" : "=m" (p[0]));
309 const struct raid6_recov_calls raid6_recov_avx2 = {
310 .data2 = raid6_2data_recov_avx2,
311 .datap = raid6_datap_recov_avx2,
312 .valid = raid6_has_avx2,
322 #warning "your version of binutils lacks AVX2 support"