Line data Source code
1 : // SPDX-License-Identifier: GPL-2.0-or-later
2 : // Copyright (C) 2013 Andrea Mazzoleni
3 :
4 : #include "internal.h"
5 :
6 : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
7 : static const struct gfzconst16 {
8 : uint8_t poly[16];
9 : uint8_t half[16];
10 : uint8_t low7[16];
11 : } gfzconst16 __aligned(64) =
12 : {
13 : {
14 : 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d,
15 : 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d, 0x1d
16 : },
17 : {
18 : 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e,
19 : 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e, 0x8e
20 : },
21 : {
22 : 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
23 : 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f
24 : }
25 : };
26 : #endif
27 :
28 : #if defined(CONFIG_X86) && defined(CONFIG_SSE2)
29 : /*
30 : * GENz (triple parity with powers of 2^-1) SSE2 implementation
31 : */
32 16 : void raid_genz_sse2(int nd, size_t size, void **vv)
33 : {
34 16 : uint8_t **v = (uint8_t**)vv;
35 : uint8_t *p;
36 : uint8_t *q;
37 : uint8_t *r;
38 : int d, l;
39 : size_t i;
40 :
41 16 : l = nd - 1;
42 16 : p = v[nd];
43 16 : q = v[nd + 1];
44 16 : r = v[nd + 2];
45 :
46 : raid_sse_begin();
47 :
48 16 : asm volatile ("movdqa %0,%%xmm7" : : "m" (gfzconst16.poly[0]));
49 16 : asm volatile ("movdqa %0,%%xmm3" : : "m" (gfzconst16.half[0]));
50 16 : asm volatile ("movdqa %0,%%xmm6" : : "m" (gfzconst16.low7[0]));
51 :
52 245792 : for (i = 0; i < size; i += 16) {
53 245776 : asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
54 245776 : asm volatile ("movdqa %xmm0,%xmm1");
55 245776 : asm volatile ("movdqa %xmm0,%xmm2");
56 1966592 : for (d = l - 1; d >= 0; --d) {
57 1720816 : asm volatile ("pxor %xmm4,%xmm4");
58 1720816 : asm volatile ("pcmpgtb %xmm1,%xmm4");
59 1720816 : asm volatile ("paddb %xmm1,%xmm1");
60 1720816 : asm volatile ("pand %xmm7,%xmm4");
61 1720816 : asm volatile ("pxor %xmm4,%xmm1");
62 :
63 1720816 : asm volatile ("movdqa %xmm2,%xmm4");
64 1720816 : asm volatile ("pxor %xmm5,%xmm5");
65 1720816 : asm volatile ("psllw $7,%xmm4");
66 1720816 : asm volatile ("psrlw $1,%xmm2");
67 1720816 : asm volatile ("pcmpgtb %xmm4,%xmm5");
68 1720816 : asm volatile ("pand %xmm6,%xmm2");
69 1720816 : asm volatile ("pand %xmm3,%xmm5");
70 1720816 : asm volatile ("pxor %xmm5,%xmm2");
71 :
72 1720816 : asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
73 1720816 : asm volatile ("pxor %xmm4,%xmm0");
74 1720816 : asm volatile ("pxor %xmm4,%xmm1");
75 1720816 : asm volatile ("pxor %xmm4,%xmm2");
76 : }
77 245776 : asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
78 245776 : asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
79 245776 : asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
80 : }
81 :
82 : raid_sse_end();
83 16 : }
84 : #endif
85 :
86 : #if defined(CONFIG_X86_64) && defined(CONFIG_SSE2)
87 : /*
88 : * GENz (triple parity with powers of 2^-1) SSE2 implementation
89 : *
90 : * Note that it uses 16 registers, meaning that x64 is required.
91 : */
92 34577 : void raid_genz_sse2ext(int nd, size_t size, void **vv)
93 : {
94 34577 : uint8_t **v = (uint8_t**)vv;
95 : uint8_t *p;
96 : uint8_t *q;
97 : uint8_t *r;
98 : int d, l;
99 : size_t i;
100 :
101 34577 : l = nd - 1;
102 34577 : p = v[nd];
103 34577 : q = v[nd + 1];
104 34577 : r = v[nd + 2];
105 :
106 : raid_sse_begin();
107 :
108 34577 : asm volatile ("movdqa %0,%%xmm7" : : "m" (gfzconst16.poly[0]));
109 34577 : asm volatile ("movdqa %0,%%xmm3" : : "m" (gfzconst16.half[0]));
110 34577 : asm volatile ("movdqa %0,%%xmm11" : : "m" (gfzconst16.low7[0]));
111 :
112 1263417 : for (i = 0; i < size; i += 32) {
113 1228840 : asm volatile ("movdqa %0,%%xmm0" : : "m" (v[l][i]));
114 1228840 : asm volatile ("movdqa %0,%%xmm8" : : "m" (v[l][i + 16]));
115 1228840 : asm volatile ("movdqa %xmm0,%xmm1");
116 1228840 : asm volatile ("movdqa %xmm8,%xmm9");
117 1228840 : asm volatile ("movdqa %xmm0,%xmm2");
118 1228840 : asm volatile ("movdqa %xmm8,%xmm10");
119 7619008 : for (d = l - 1; d >= 0; --d) {
120 6390168 : asm volatile ("movdqa %xmm2,%xmm6");
121 6390168 : asm volatile ("movdqa %xmm10,%xmm14");
122 6390168 : asm volatile ("pxor %xmm4,%xmm4");
123 6390168 : asm volatile ("pxor %xmm12,%xmm12");
124 6390168 : asm volatile ("pxor %xmm5,%xmm5");
125 6390168 : asm volatile ("pxor %xmm13,%xmm13");
126 6390168 : asm volatile ("psllw $7,%xmm6");
127 6390168 : asm volatile ("psllw $7,%xmm14");
128 6390168 : asm volatile ("psrlw $1,%xmm2");
129 6390168 : asm volatile ("psrlw $1,%xmm10");
130 6390168 : asm volatile ("pcmpgtb %xmm1,%xmm4");
131 6390168 : asm volatile ("pcmpgtb %xmm9,%xmm12");
132 6390168 : asm volatile ("pcmpgtb %xmm6,%xmm5");
133 6390168 : asm volatile ("pcmpgtb %xmm14,%xmm13");
134 6390168 : asm volatile ("paddb %xmm1,%xmm1");
135 6390168 : asm volatile ("paddb %xmm9,%xmm9");
136 6390168 : asm volatile ("pand %xmm11,%xmm2");
137 6390168 : asm volatile ("pand %xmm11,%xmm10");
138 6390168 : asm volatile ("pand %xmm7,%xmm4");
139 6390168 : asm volatile ("pand %xmm7,%xmm12");
140 6390168 : asm volatile ("pand %xmm3,%xmm5");
141 6390168 : asm volatile ("pand %xmm3,%xmm13");
142 6390168 : asm volatile ("pxor %xmm4,%xmm1");
143 6390168 : asm volatile ("pxor %xmm12,%xmm9");
144 6390168 : asm volatile ("pxor %xmm5,%xmm2");
145 6390168 : asm volatile ("pxor %xmm13,%xmm10");
146 :
147 6390168 : asm volatile ("movdqa %0,%%xmm4" : : "m" (v[d][i]));
148 6390168 : asm volatile ("movdqa %0,%%xmm12" : : "m" (v[d][i + 16]));
149 6390168 : asm volatile ("pxor %xmm4,%xmm0");
150 6390168 : asm volatile ("pxor %xmm4,%xmm1");
151 6390168 : asm volatile ("pxor %xmm4,%xmm2");
152 6390168 : asm volatile ("pxor %xmm12,%xmm8");
153 6390168 : asm volatile ("pxor %xmm12,%xmm9");
154 6390168 : asm volatile ("pxor %xmm12,%xmm10");
155 : }
156 1228840 : asm volatile ("movntdq %%xmm0,%0" : "=m" (p[i]));
157 1228840 : asm volatile ("movntdq %%xmm8,%0" : "=m" (p[i + 16]));
158 1228840 : asm volatile ("movntdq %%xmm1,%0" : "=m" (q[i]));
159 1228840 : asm volatile ("movntdq %%xmm9,%0" : "=m" (q[i + 16]));
160 1228840 : asm volatile ("movntdq %%xmm2,%0" : "=m" (r[i]));
161 1228840 : asm volatile ("movntdq %%xmm10,%0" : "=m" (r[i + 16]));
162 : }
163 :
164 : raid_sse_end();
165 34577 : }
166 : #endif
167 :
168 : #if defined(CONFIG_X86_64) && defined(CONFIG_AVX2)
169 : /*
170 : * GENz (triple parity with powers of 2^-1) AVX2 implementation
171 : *
172 : * Note that it uses 16 registers, meaning that x64 is required.
173 : */
174 1461 : void raid_genz_avx2ext(int nd, size_t size, void **vv)
175 : {
176 1461 : uint8_t **v = (uint8_t**)vv;
177 : uint8_t *p;
178 : uint8_t *q;
179 : uint8_t *r;
180 : int d, l;
181 : size_t i;
182 :
183 1461 : l = nd - 1;
184 1461 : p = v[nd];
185 1461 : q = v[nd + 1];
186 1461 : r = v[nd + 2];
187 :
188 : raid_avx_begin();
189 :
190 1461 : asm volatile ("vbroadcasti128 %0,%%ymm7" : : "m" (gfzconst16.poly[0]));
191 1461 : asm volatile ("vbroadcasti128 %0,%%ymm3" : : "m" (gfzconst16.half[0]));
192 1461 : asm volatile ("vbroadcasti128 %0,%%ymm11" : : "m" (gfzconst16.low7[0]));
193 1461 : asm volatile ("vpxor %ymm15,%ymm15,%ymm15");
194 :
195 23673 : for (i = 0; i < size; i += 64) {
196 22212 : asm volatile ("vmovdqa %0,%%ymm0" : : "m" (v[l][i]));
197 22212 : asm volatile ("vmovdqa %0,%%ymm8" : : "m" (v[l][i + 32]));
198 22212 : asm volatile ("vmovdqa %ymm0,%ymm1");
199 22212 : asm volatile ("vmovdqa %ymm8,%ymm9");
200 22212 : asm volatile ("vmovdqa %ymm0,%ymm2");
201 22212 : asm volatile ("vmovdqa %ymm8,%ymm10");
202 201088 : for (d = l - 1; d >= 0; --d) {
203 178876 : asm volatile ("vpsllw $7,%ymm2,%ymm6");
204 178876 : asm volatile ("vpsllw $7,%ymm10,%ymm14");
205 178876 : asm volatile ("vpsrlw $1,%ymm2,%ymm2");
206 178876 : asm volatile ("vpsrlw $1,%ymm10,%ymm10");
207 178876 : asm volatile ("vpcmpgtb %ymm1,%ymm15,%ymm4");
208 178876 : asm volatile ("vpcmpgtb %ymm9,%ymm15,%ymm12");
209 178876 : asm volatile ("vpcmpgtb %ymm6,%ymm15,%ymm5");
210 178876 : asm volatile ("vpcmpgtb %ymm14,%ymm15,%ymm13");
211 178876 : asm volatile ("vpaddb %ymm1,%ymm1,%ymm1");
212 178876 : asm volatile ("vpaddb %ymm9,%ymm9,%ymm9");
213 178876 : asm volatile ("vpand %ymm11,%ymm2,%ymm2");
214 178876 : asm volatile ("vpand %ymm11,%ymm10,%ymm10");
215 178876 : asm volatile ("vpand %ymm7,%ymm4,%ymm4");
216 178876 : asm volatile ("vpand %ymm7,%ymm12,%ymm12");
217 178876 : asm volatile ("vpand %ymm3,%ymm5,%ymm5");
218 178876 : asm volatile ("vpand %ymm3,%ymm13,%ymm13");
219 178876 : asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
220 178876 : asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
221 178876 : asm volatile ("vpxor %ymm5,%ymm2,%ymm2");
222 178876 : asm volatile ("vpxor %ymm13,%ymm10,%ymm10");
223 :
224 178876 : asm volatile ("vmovdqa %0,%%ymm4" : : "m" (v[d][i]));
225 178876 : asm volatile ("vmovdqa %0,%%ymm12" : : "m" (v[d][i + 32]));
226 178876 : asm volatile ("vpxor %ymm4,%ymm0,%ymm0");
227 178876 : asm volatile ("vpxor %ymm4,%ymm1,%ymm1");
228 178876 : asm volatile ("vpxor %ymm4,%ymm2,%ymm2");
229 178876 : asm volatile ("vpxor %ymm12,%ymm8,%ymm8");
230 178876 : asm volatile ("vpxor %ymm12,%ymm9,%ymm9");
231 178876 : asm volatile ("vpxor %ymm12,%ymm10,%ymm10");
232 : }
233 22212 : asm volatile ("vmovntdq %%ymm0,%0" : "=m" (p[i]));
234 22212 : asm volatile ("vmovntdq %%ymm8,%0" : "=m" (p[i + 32]));
235 22212 : asm volatile ("vmovntdq %%ymm1,%0" : "=m" (q[i]));
236 22212 : asm volatile ("vmovntdq %%ymm9,%0" : "=m" (q[i + 32]));
237 22212 : asm volatile ("vmovntdq %%ymm2,%0" : "=m" (r[i]));
238 22212 : asm volatile ("vmovntdq %%ymm10,%0" : "=m" (r[i + 32]));
239 : }
240 :
241 : raid_avx_end();
242 1461 : }
243 : #endif
244 :
|