Merge branch 'aarch64/psci/drivers' into aarch64/for-next/core
[linux/fpc-iii.git] / lib / raid6 / recov_avx2.c
blob53fe3d7bdfb3b4de498c19001c2e8d49352e22c3
1 /*
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
8 * of the License.
9 */
11 #ifdef CONFIG_AS_AVX2
13 #include <linux/raid/pq.h>
14 #include "x86.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)
25 u8 *p, *q, *dp, *dq;
26 const u8 *pbmul; /* P multiplier table for B data */
27 const u8 *qmul; /* Q multiplier table (for both) */
28 const u8 x0f = 0x0f;
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;
38 ptrs[disks-2] = dp;
39 dq = (u8 *)ptrs[failb];
40 ptrs[failb] = (void *)raid6_empty_zero_page;
41 ptrs[disks-1] = dq;
43 raid6_call.gen_syndrome(disks, bytes, ptrs);
45 /* Restore pointer table */
46 ptrs[faila] = dp;
47 ptrs[failb] = dq;
48 ptrs[disks-2] = p;
49 ptrs[disks-1] = q;
51 /* Now, pick the proper data tables */
52 pbmul = raid6_vgfmul[raid6_gfexi[failb-faila]];
53 qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila] ^
54 raid6_gfexp[failb]]];
56 kernel_fpu_begin();
58 /* ymm0 = x0f[16] */
59 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f));
61 while (bytes) {
62 #ifdef CONFIG_X86_64
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]));
73 * 1 = dq[0] ^ q[0]
74 * 9 = dq[32] ^ q[32]
75 * 0 = dp[0] ^ p[0]
76 * 8 = dp[32] ^ p[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");
96 * 5 = qx[0]
97 * 15 = qx[32]
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");
116 * 1 = pbmul[px[0]]
117 * 13 = pbmul[px[32]]
119 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
120 asm volatile("vpxor %ymm15, %ymm13, %ymm13");
123 * 1 = db = DQ
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]));
134 bytes -= 64;
135 p += 64;
136 q += 64;
137 dp += 64;
138 dq += 64;
139 #else
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]));
151 * 1 = dq ^ q
152 * 3 = dq ^ p >> 4
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");
161 /* 5 = qx */
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");
173 /* 1 = pbmul[px] */
174 asm volatile("vpxor %ymm5, %ymm1, %ymm1");
175 /* 1 = db = DQ */
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]));
181 bytes -= 32;
182 p += 32;
183 q += 32;
184 dp += 32;
185 dq += 32;
186 #endif
189 kernel_fpu_end();
192 static void raid6_datap_recov_avx2(int disks, size_t bytes, int faila,
193 void **ptrs)
195 u8 *p, *q, *dq;
196 const u8 *qmul; /* Q multiplier table */
197 const u8 x0f = 0x0f;
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;
206 ptrs[disks-1] = dq;
208 raid6_call.gen_syndrome(disks, bytes, ptrs);
210 /* Restore pointer table */
211 ptrs[faila] = dq;
212 ptrs[disks-1] = q;
214 /* Now, pick the proper data tables */
215 qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila]]];
217 kernel_fpu_begin();
219 asm volatile("vpbroadcastb %0, %%ymm7" : : "m" (x0f));
221 while (bytes) {
222 #ifdef CONFIG_X86_64
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]));
229 * 3 = q[0] ^ dq[0]
230 * 8 = q[32] ^ dq[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]));
269 bytes -= 64;
270 p += 64;
271 q += 64;
272 dq += 64;
273 #else
274 asm volatile("vmovdqa %0, %%ymm3" : : "m" (dq[0]));
275 asm volatile("vpxor %0, %%ymm3, %%ymm3" : : "m" (q[0]));
277 /* 3 = q ^ dq */
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]));
299 bytes -= 32;
300 p += 32;
301 q += 32;
302 dq += 32;
303 #endif
306 kernel_fpu_end();
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,
313 #ifdef CONFIG_X86_64
314 .name = "avx2x2",
315 #else
316 .name = "avx2x1",
317 #endif
318 .priority = 2,
321 #else
322 #warning "your version of binutils lacks AVX2 support"
323 #endif