2 * Copyright (C) 2016 Intel Corporation
4 * Author: Gayatri Kammela <gayatri.kammela@intel.com>
5 * Author: Megha Dey <megha.dey@linux.intel.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; version 2
14 #ifdef CONFIG_AS_AVX512
16 #include <linux/raid/pq.h>
19 static int raid6_has_avx512(void)
21 return boot_cpu_has(X86_FEATURE_AVX2
) &&
22 boot_cpu_has(X86_FEATURE_AVX
) &&
23 boot_cpu_has(X86_FEATURE_AVX512F
) &&
24 boot_cpu_has(X86_FEATURE_AVX512BW
) &&
25 boot_cpu_has(X86_FEATURE_AVX512VL
) &&
26 boot_cpu_has(X86_FEATURE_AVX512DQ
);
29 static void raid6_2data_recov_avx512(int disks
, size_t bytes
, int faila
,
30 int failb
, void **ptrs
)
33 const u8
*pbmul
; /* P multiplier table for B data */
34 const u8
*qmul
; /* Q multiplier table (for both) */
37 p
= (u8
*)ptrs
[disks
-2];
38 q
= (u8
*)ptrs
[disks
-1];
41 * Compute syndrome with zero for the missing data pages
42 * Use the dead data pages as temporary storage for
46 dp
= (u8
*)ptrs
[faila
];
47 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
49 dq
= (u8
*)ptrs
[failb
];
50 ptrs
[failb
] = (void *)raid6_empty_zero_page
;
53 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
55 /* Restore pointer table */
61 /* Now, pick the proper data tables */
62 pbmul
= raid6_vgfmul
[raid6_gfexi
[failb
-faila
]];
63 qmul
= raid6_vgfmul
[raid6_gfinv
[raid6_gfexp
[faila
] ^
69 asm volatile("vpbroadcastb %0, %%zmm7" : : "m" (x0f
));
73 asm volatile("vmovdqa64 %0, %%zmm1\n\t"
74 "vmovdqa64 %1, %%zmm9\n\t"
75 "vmovdqa64 %2, %%zmm0\n\t"
76 "vmovdqa64 %3, %%zmm8\n\t"
77 "vpxorq %4, %%zmm1, %%zmm1\n\t"
78 "vpxorq %5, %%zmm9, %%zmm9\n\t"
79 "vpxorq %6, %%zmm0, %%zmm0\n\t"
80 "vpxorq %7, %%zmm8, %%zmm8"
82 : "m" (q
[0]), "m" (q
[64]), "m" (p
[0]),
83 "m" (p
[64]), "m" (dq
[0]), "m" (dq
[64]),
84 "m" (dp
[0]), "m" (dp
[64]));
93 asm volatile("vbroadcasti64x2 %0, %%zmm4\n\t"
94 "vbroadcasti64x2 %1, %%zmm5"
96 : "m" (qmul
[0]), "m" (qmul
[16]));
98 asm volatile("vpsraw $4, %%zmm1, %%zmm3\n\t"
99 "vpsraw $4, %%zmm9, %%zmm12\n\t"
100 "vpandq %%zmm7, %%zmm1, %%zmm1\n\t"
101 "vpandq %%zmm7, %%zmm9, %%zmm9\n\t"
102 "vpandq %%zmm7, %%zmm3, %%zmm3\n\t"
103 "vpandq %%zmm7, %%zmm12, %%zmm12\n\t"
104 "vpshufb %%zmm9, %%zmm4, %%zmm14\n\t"
105 "vpshufb %%zmm1, %%zmm4, %%zmm4\n\t"
106 "vpshufb %%zmm12, %%zmm5, %%zmm15\n\t"
107 "vpshufb %%zmm3, %%zmm5, %%zmm5\n\t"
108 "vpxorq %%zmm14, %%zmm15, %%zmm15\n\t"
109 "vpxorq %%zmm4, %%zmm5, %%zmm5"
118 asm volatile("vbroadcasti64x2 %0, %%zmm4\n\t"
119 "vbroadcasti64x2 %1, %%zmm1\n\t"
120 "vpsraw $4, %%zmm0, %%zmm2\n\t"
121 "vpsraw $4, %%zmm8, %%zmm6\n\t"
122 "vpandq %%zmm7, %%zmm0, %%zmm3\n\t"
123 "vpandq %%zmm7, %%zmm8, %%zmm14\n\t"
124 "vpandq %%zmm7, %%zmm2, %%zmm2\n\t"
125 "vpandq %%zmm7, %%zmm6, %%zmm6\n\t"
126 "vpshufb %%zmm14, %%zmm4, %%zmm12\n\t"
127 "vpshufb %%zmm3, %%zmm4, %%zmm4\n\t"
128 "vpshufb %%zmm6, %%zmm1, %%zmm13\n\t"
129 "vpshufb %%zmm2, %%zmm1, %%zmm1\n\t"
130 "vpxorq %%zmm4, %%zmm1, %%zmm1\n\t"
131 "vpxorq %%zmm12, %%zmm13, %%zmm13"
133 : "m" (pbmul
[0]), "m" (pbmul
[16]));
139 asm volatile("vpxorq %%zmm5, %%zmm1, %%zmm1\n\t"
140 "vpxorq %%zmm15, %%zmm13, %%zmm13"
146 * 13 = db[64] = DQ[64]
148 asm volatile("vmovdqa64 %%zmm1, %0\n\t"
149 "vmovdqa64 %%zmm13,%1\n\t"
150 "vpxorq %%zmm1, %%zmm0, %%zmm0\n\t"
151 "vpxorq %%zmm13, %%zmm8, %%zmm8"
153 : "m" (dq
[0]), "m" (dq
[64]));
155 asm volatile("vmovdqa64 %%zmm0, %0\n\t"
156 "vmovdqa64 %%zmm8, %1"
158 : "m" (dp
[0]), "m" (dp
[64]));
166 asm volatile("vmovdqa64 %0, %%zmm1\n\t"
167 "vmovdqa64 %1, %%zmm0\n\t"
168 "vpxorq %2, %%zmm1, %%zmm1\n\t"
169 "vpxorq %3, %%zmm0, %%zmm0"
171 : "m" (*q
), "m" (*p
), "m"(*dq
), "m" (*dp
));
173 /* 1 = dq ^ q; 0 = dp ^ p */
175 asm volatile("vbroadcasti64x2 %0, %%zmm4\n\t"
176 "vbroadcasti64x2 %1, %%zmm5"
178 : "m" (qmul
[0]), "m" (qmul
[16]));
184 asm volatile("vpsraw $4, %%zmm1, %%zmm3\n\t"
185 "vpandq %%zmm7, %%zmm1, %%zmm1\n\t"
186 "vpandq %%zmm7, %%zmm3, %%zmm3\n\t"
187 "vpshufb %%zmm1, %%zmm4, %%zmm4\n\t"
188 "vpshufb %%zmm3, %%zmm5, %%zmm5\n\t"
189 "vpxorq %%zmm4, %%zmm5, %%zmm5"
195 asm volatile("vbroadcasti64x2 %0, %%zmm4\n\t"
196 "vbroadcasti64x2 %1, %%zmm1"
198 : "m" (pbmul
[0]), "m" (pbmul
[16]));
200 asm volatile("vpsraw $4, %%zmm0, %%zmm2\n\t"
201 "vpandq %%zmm7, %%zmm0, %%zmm3\n\t"
202 "vpandq %%zmm7, %%zmm2, %%zmm2\n\t"
203 "vpshufb %%zmm3, %%zmm4, %%zmm4\n\t"
204 "vpshufb %%zmm2, %%zmm1, %%zmm1\n\t"
205 "vpxorq %%zmm4, %%zmm1, %%zmm1"
210 asm volatile("vpxorq %%zmm5, %%zmm1, %%zmm1\n\t"
212 "vmovdqa64 %%zmm1, %0\n\t"
216 asm volatile("vpxorq %%zmm1, %%zmm0, %%zmm0\n\t"
217 "vmovdqa64 %%zmm0, %0"
232 static void raid6_datap_recov_avx512(int disks
, size_t bytes
, int faila
,
236 const u8
*qmul
; /* Q multiplier table */
239 p
= (u8
*)ptrs
[disks
-2];
240 q
= (u8
*)ptrs
[disks
-1];
243 * Compute syndrome with zero for the missing data page
244 * Use the dead data page as temporary storage for delta q
247 dq
= (u8
*)ptrs
[faila
];
248 ptrs
[faila
] = (void *)raid6_empty_zero_page
;
251 raid6_call
.gen_syndrome(disks
, bytes
, ptrs
);
253 /* Restore pointer table */
257 /* Now, pick the proper data tables */
258 qmul
= raid6_vgfmul
[raid6_gfinv
[raid6_gfexp
[faila
]]];
262 asm volatile("vpbroadcastb %0, %%zmm7" : : "m" (x0f
));
266 asm volatile("vmovdqa64 %0, %%zmm3\n\t"
267 "vmovdqa64 %1, %%zmm8\n\t"
268 "vpxorq %2, %%zmm3, %%zmm3\n\t"
269 "vpxorq %3, %%zmm8, %%zmm8"
271 : "m" (dq
[0]), "m" (dq
[64]), "m" (q
[0]),
278 asm volatile("vbroadcasti64x2 %0, %%zmm0\n\t"
279 "vmovapd %%zmm0, %%zmm13\n\t"
280 "vbroadcasti64x2 %1, %%zmm1\n\t"
281 "vmovapd %%zmm1, %%zmm14"
283 : "m" (qmul
[0]), "m" (qmul
[16]));
285 asm volatile("vpsraw $4, %%zmm3, %%zmm6\n\t"
286 "vpsraw $4, %%zmm8, %%zmm12\n\t"
287 "vpandq %%zmm7, %%zmm3, %%zmm3\n\t"
288 "vpandq %%zmm7, %%zmm8, %%zmm8\n\t"
289 "vpandq %%zmm7, %%zmm6, %%zmm6\n\t"
290 "vpandq %%zmm7, %%zmm12, %%zmm12\n\t"
291 "vpshufb %%zmm3, %%zmm0, %%zmm0\n\t"
292 "vpshufb %%zmm8, %%zmm13, %%zmm13\n\t"
293 "vpshufb %%zmm6, %%zmm1, %%zmm1\n\t"
294 "vpshufb %%zmm12, %%zmm14, %%zmm14\n\t"
295 "vpxorq %%zmm0, %%zmm1, %%zmm1\n\t"
296 "vpxorq %%zmm13, %%zmm14, %%zmm14"
301 * 1 = qmul[q[0] ^ dq[0]]
302 * 14 = qmul[q[64] ^ dq[64]]
304 asm volatile("vmovdqa64 %0, %%zmm2\n\t"
305 "vmovdqa64 %1, %%zmm12\n\t"
306 "vpxorq %%zmm1, %%zmm2, %%zmm2\n\t"
307 "vpxorq %%zmm14, %%zmm12, %%zmm12"
309 : "m" (p
[0]), "m" (p
[64]));
312 * 2 = p[0] ^ qmul[q[0] ^ dq[0]]
313 * 12 = p[64] ^ qmul[q[64] ^ dq[64]]
316 asm volatile("vmovdqa64 %%zmm1, %0\n\t"
317 "vmovdqa64 %%zmm14, %1\n\t"
318 "vmovdqa64 %%zmm2, %2\n\t"
319 "vmovdqa64 %%zmm12,%3"
321 : "m" (dq
[0]), "m" (dq
[64]), "m" (p
[0]),
329 asm volatile("vmovdqa64 %0, %%zmm3\n\t"
330 "vpxorq %1, %%zmm3, %%zmm3"
332 : "m" (dq
[0]), "m" (q
[0]));
336 asm volatile("vbroadcasti64x2 %0, %%zmm0\n\t"
337 "vbroadcasti64x2 %1, %%zmm1"
339 : "m" (qmul
[0]), "m" (qmul
[16]));
341 asm volatile("vpsraw $4, %%zmm3, %%zmm6\n\t"
342 "vpandq %%zmm7, %%zmm3, %%zmm3\n\t"
343 "vpandq %%zmm7, %%zmm6, %%zmm6\n\t"
344 "vpshufb %%zmm3, %%zmm0, %%zmm0\n\t"
345 "vpshufb %%zmm6, %%zmm1, %%zmm1\n\t"
346 "vpxorq %%zmm0, %%zmm1, %%zmm1"
350 /* 1 = qmul[q ^ dq] */
352 asm volatile("vmovdqa64 %0, %%zmm2\n\t"
353 "vpxorq %%zmm1, %%zmm2, %%zmm2"
357 /* 2 = p ^ qmul[q ^ dq] */
359 asm volatile("vmovdqa64 %%zmm1, %0\n\t"
360 "vmovdqa64 %%zmm2, %1"
362 : "m" (dq
[0]), "m" (p
[0]));
374 const struct raid6_recov_calls raid6_recov_avx512
= {
375 .data2
= raid6_2data_recov_avx512
,
376 .datap
= raid6_datap_recov_avx512
,
377 .valid
= raid6_has_avx512
,
387 #warning "your version of binutils lacks AVX512 support"