recov_ssse3.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. /*
  2. * Copyright (C) 2012 Intel Corporation
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; version 2
  7. * of the License.
  8. */
  9. #ifdef CONFIG_AS_SSSE3
  10. #include <linux/raid/pq.h>
  11. #include "x86.h"
  12. static int raid6_has_ssse3(void)
  13. {
  14. return boot_cpu_has(X86_FEATURE_XMM) &&
  15. boot_cpu_has(X86_FEATURE_XMM2) &&
  16. boot_cpu_has(X86_FEATURE_SSSE3);
  17. }
  18. static void raid6_2data_recov_ssse3(int disks, size_t bytes, int faila,
  19. int failb, void **ptrs)
  20. {
  21. u8 *p, *q, *dp, *dq;
  22. const u8 *pbmul; /* P multiplier table for B data */
  23. const u8 *qmul; /* Q multiplier table (for both) */
  24. static const u8 __aligned(16) x0f[16] = {
  25. 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
  26. 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f};
  27. p = (u8 *)ptrs[disks-2];
  28. q = (u8 *)ptrs[disks-1];
  29. /* Compute syndrome with zero for the missing data pages
  30. Use the dead data pages as temporary storage for
  31. delta p and delta q */
  32. dp = (u8 *)ptrs[faila];
  33. ptrs[faila] = (void *)raid6_empty_zero_page;
  34. ptrs[disks-2] = dp;
  35. dq = (u8 *)ptrs[failb];
  36. ptrs[failb] = (void *)raid6_empty_zero_page;
  37. ptrs[disks-1] = dq;
  38. raid6_call.gen_syndrome(disks, bytes, ptrs);
  39. /* Restore pointer table */
  40. ptrs[faila] = dp;
  41. ptrs[failb] = dq;
  42. ptrs[disks-2] = p;
  43. ptrs[disks-1] = q;
  44. /* Now, pick the proper data tables */
  45. pbmul = raid6_vgfmul[raid6_gfexi[failb-faila]];
  46. qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila] ^
  47. raid6_gfexp[failb]]];
  48. kernel_fpu_begin();
  49. asm volatile("movdqa %0,%%xmm7" : : "m" (x0f[0]));
  50. #ifdef CONFIG_X86_64
  51. asm volatile("movdqa %0,%%xmm6" : : "m" (qmul[0]));
  52. asm volatile("movdqa %0,%%xmm14" : : "m" (pbmul[0]));
  53. asm volatile("movdqa %0,%%xmm15" : : "m" (pbmul[16]));
  54. #endif
  55. /* Now do it... */
  56. while (bytes) {
  57. #ifdef CONFIG_X86_64
  58. /* xmm6, xmm14, xmm15 */
  59. asm volatile("movdqa %0,%%xmm1" : : "m" (q[0]));
  60. asm volatile("movdqa %0,%%xmm9" : : "m" (q[16]));
  61. asm volatile("movdqa %0,%%xmm0" : : "m" (p[0]));
  62. asm volatile("movdqa %0,%%xmm8" : : "m" (p[16]));
  63. asm volatile("pxor %0,%%xmm1" : : "m" (dq[0]));
  64. asm volatile("pxor %0,%%xmm9" : : "m" (dq[16]));
  65. asm volatile("pxor %0,%%xmm0" : : "m" (dp[0]));
  66. asm volatile("pxor %0,%%xmm8" : : "m" (dp[16]));
  67. /* xmm0/8 = px */
  68. asm volatile("movdqa %xmm6,%xmm4");
  69. asm volatile("movdqa %0,%%xmm5" : : "m" (qmul[16]));
  70. asm volatile("movdqa %xmm6,%xmm12");
  71. asm volatile("movdqa %xmm5,%xmm13");
  72. asm volatile("movdqa %xmm1,%xmm3");
  73. asm volatile("movdqa %xmm9,%xmm11");
  74. asm volatile("movdqa %xmm0,%xmm2"); /* xmm2/10 = px */
  75. asm volatile("movdqa %xmm8,%xmm10");
  76. asm volatile("psraw $4,%xmm1");
  77. asm volatile("psraw $4,%xmm9");
  78. asm volatile("pand %xmm7,%xmm3");
  79. asm volatile("pand %xmm7,%xmm11");
  80. asm volatile("pand %xmm7,%xmm1");
  81. asm volatile("pand %xmm7,%xmm9");
  82. asm volatile("pshufb %xmm3,%xmm4");
  83. asm volatile("pshufb %xmm11,%xmm12");
  84. asm volatile("pshufb %xmm1,%xmm5");
  85. asm volatile("pshufb %xmm9,%xmm13");
  86. asm volatile("pxor %xmm4,%xmm5");
  87. asm volatile("pxor %xmm12,%xmm13");
  88. /* xmm5/13 = qx */
  89. asm volatile("movdqa %xmm14,%xmm4");
  90. asm volatile("movdqa %xmm15,%xmm1");
  91. asm volatile("movdqa %xmm14,%xmm12");
  92. asm volatile("movdqa %xmm15,%xmm9");
  93. asm volatile("movdqa %xmm2,%xmm3");
  94. asm volatile("movdqa %xmm10,%xmm11");
  95. asm volatile("psraw $4,%xmm2");
  96. asm volatile("psraw $4,%xmm10");
  97. asm volatile("pand %xmm7,%xmm3");
  98. asm volatile("pand %xmm7,%xmm11");
  99. asm volatile("pand %xmm7,%xmm2");
  100. asm volatile("pand %xmm7,%xmm10");
  101. asm volatile("pshufb %xmm3,%xmm4");
  102. asm volatile("pshufb %xmm11,%xmm12");
  103. asm volatile("pshufb %xmm2,%xmm1");
  104. asm volatile("pshufb %xmm10,%xmm9");
  105. asm volatile("pxor %xmm4,%xmm1");
  106. asm volatile("pxor %xmm12,%xmm9");
  107. /* xmm1/9 = pbmul[px] */
  108. asm volatile("pxor %xmm5,%xmm1");
  109. asm volatile("pxor %xmm13,%xmm9");
  110. /* xmm1/9 = db = DQ */
  111. asm volatile("movdqa %%xmm1,%0" : "=m" (dq[0]));
  112. asm volatile("movdqa %%xmm9,%0" : "=m" (dq[16]));
  113. asm volatile("pxor %xmm1,%xmm0");
  114. asm volatile("pxor %xmm9,%xmm8");
  115. asm volatile("movdqa %%xmm0,%0" : "=m" (dp[0]));
  116. asm volatile("movdqa %%xmm8,%0" : "=m" (dp[16]));
  117. bytes -= 32;
  118. p += 32;
  119. q += 32;
  120. dp += 32;
  121. dq += 32;
  122. #else
  123. asm volatile("movdqa %0,%%xmm1" : : "m" (*q));
  124. asm volatile("movdqa %0,%%xmm0" : : "m" (*p));
  125. asm volatile("pxor %0,%%xmm1" : : "m" (*dq));
  126. asm volatile("pxor %0,%%xmm0" : : "m" (*dp));
  127. /* 1 = dq ^ q
  128. * 0 = dp ^ p
  129. */
  130. asm volatile("movdqa %0,%%xmm4" : : "m" (qmul[0]));
  131. asm volatile("movdqa %0,%%xmm5" : : "m" (qmul[16]));
  132. asm volatile("movdqa %xmm1,%xmm3");
  133. asm volatile("psraw $4,%xmm1");
  134. asm volatile("pand %xmm7,%xmm3");
  135. asm volatile("pand %xmm7,%xmm1");
  136. asm volatile("pshufb %xmm3,%xmm4");
  137. asm volatile("pshufb %xmm1,%xmm5");
  138. asm volatile("pxor %xmm4,%xmm5");
  139. asm volatile("movdqa %xmm0,%xmm2"); /* xmm2 = px */
  140. /* xmm5 = qx */
  141. asm volatile("movdqa %0,%%xmm4" : : "m" (pbmul[0]));
  142. asm volatile("movdqa %0,%%xmm1" : : "m" (pbmul[16]));
  143. asm volatile("movdqa %xmm2,%xmm3");
  144. asm volatile("psraw $4,%xmm2");
  145. asm volatile("pand %xmm7,%xmm3");
  146. asm volatile("pand %xmm7,%xmm2");
  147. asm volatile("pshufb %xmm3,%xmm4");
  148. asm volatile("pshufb %xmm2,%xmm1");
  149. asm volatile("pxor %xmm4,%xmm1");
  150. /* xmm1 = pbmul[px] */
  151. asm volatile("pxor %xmm5,%xmm1");
  152. /* xmm1 = db = DQ */
  153. asm volatile("movdqa %%xmm1,%0" : "=m" (*dq));
  154. asm volatile("pxor %xmm1,%xmm0");
  155. asm volatile("movdqa %%xmm0,%0" : "=m" (*dp));
  156. bytes -= 16;
  157. p += 16;
  158. q += 16;
  159. dp += 16;
  160. dq += 16;
  161. #endif
  162. }
  163. kernel_fpu_end();
  164. }
  165. static void raid6_datap_recov_ssse3(int disks, size_t bytes, int faila,
  166. void **ptrs)
  167. {
  168. u8 *p, *q, *dq;
  169. const u8 *qmul; /* Q multiplier table */
  170. static const u8 __aligned(16) x0f[16] = {
  171. 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f,
  172. 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f, 0x0f};
  173. p = (u8 *)ptrs[disks-2];
  174. q = (u8 *)ptrs[disks-1];
  175. /* Compute syndrome with zero for the missing data page
  176. Use the dead data page as temporary storage for delta q */
  177. dq = (u8 *)ptrs[faila];
  178. ptrs[faila] = (void *)raid6_empty_zero_page;
  179. ptrs[disks-1] = dq;
  180. raid6_call.gen_syndrome(disks, bytes, ptrs);
  181. /* Restore pointer table */
  182. ptrs[faila] = dq;
  183. ptrs[disks-1] = q;
  184. /* Now, pick the proper data tables */
  185. qmul = raid6_vgfmul[raid6_gfinv[raid6_gfexp[faila]]];
  186. kernel_fpu_begin();
  187. asm volatile("movdqa %0, %%xmm7" : : "m" (x0f[0]));
  188. while (bytes) {
  189. #ifdef CONFIG_X86_64
  190. asm volatile("movdqa %0, %%xmm3" : : "m" (dq[0]));
  191. asm volatile("movdqa %0, %%xmm4" : : "m" (dq[16]));
  192. asm volatile("pxor %0, %%xmm3" : : "m" (q[0]));
  193. asm volatile("movdqa %0, %%xmm0" : : "m" (qmul[0]));
  194. /* xmm3 = q[0] ^ dq[0] */
  195. asm volatile("pxor %0, %%xmm4" : : "m" (q[16]));
  196. asm volatile("movdqa %0, %%xmm1" : : "m" (qmul[16]));
  197. /* xmm4 = q[16] ^ dq[16] */
  198. asm volatile("movdqa %xmm3, %xmm6");
  199. asm volatile("movdqa %xmm4, %xmm8");
  200. /* xmm4 = xmm8 = q[16] ^ dq[16] */
  201. asm volatile("psraw $4, %xmm3");
  202. asm volatile("pand %xmm7, %xmm6");
  203. asm volatile("pand %xmm7, %xmm3");
  204. asm volatile("pshufb %xmm6, %xmm0");
  205. asm volatile("pshufb %xmm3, %xmm1");
  206. asm volatile("movdqa %0, %%xmm10" : : "m" (qmul[0]));
  207. asm volatile("pxor %xmm0, %xmm1");
  208. asm volatile("movdqa %0, %%xmm11" : : "m" (qmul[16]));
  209. /* xmm1 = qmul[q[0] ^ dq[0]] */
  210. asm volatile("psraw $4, %xmm4");
  211. asm volatile("pand %xmm7, %xmm8");
  212. asm volatile("pand %xmm7, %xmm4");
  213. asm volatile("pshufb %xmm8, %xmm10");
  214. asm volatile("pshufb %xmm4, %xmm11");
  215. asm volatile("movdqa %0, %%xmm2" : : "m" (p[0]));
  216. asm volatile("pxor %xmm10, %xmm11");
  217. asm volatile("movdqa %0, %%xmm12" : : "m" (p[16]));
  218. /* xmm11 = qmul[q[16] ^ dq[16]] */
  219. asm volatile("pxor %xmm1, %xmm2");
  220. /* xmm2 = p[0] ^ qmul[q[0] ^ dq[0]] */
  221. asm volatile("pxor %xmm11, %xmm12");
  222. /* xmm12 = p[16] ^ qmul[q[16] ^ dq[16]] */
  223. asm volatile("movdqa %%xmm1, %0" : "=m" (dq[0]));
  224. asm volatile("movdqa %%xmm11, %0" : "=m" (dq[16]));
  225. asm volatile("movdqa %%xmm2, %0" : "=m" (p[0]));
  226. asm volatile("movdqa %%xmm12, %0" : "=m" (p[16]));
  227. bytes -= 32;
  228. p += 32;
  229. q += 32;
  230. dq += 32;
  231. #else
  232. asm volatile("movdqa %0, %%xmm3" : : "m" (dq[0]));
  233. asm volatile("movdqa %0, %%xmm0" : : "m" (qmul[0]));
  234. asm volatile("pxor %0, %%xmm3" : : "m" (q[0]));
  235. asm volatile("movdqa %0, %%xmm1" : : "m" (qmul[16]));
  236. /* xmm3 = *q ^ *dq */
  237. asm volatile("movdqa %xmm3, %xmm6");
  238. asm volatile("movdqa %0, %%xmm2" : : "m" (p[0]));
  239. asm volatile("psraw $4, %xmm3");
  240. asm volatile("pand %xmm7, %xmm6");
  241. asm volatile("pand %xmm7, %xmm3");
  242. asm volatile("pshufb %xmm6, %xmm0");
  243. asm volatile("pshufb %xmm3, %xmm1");
  244. asm volatile("pxor %xmm0, %xmm1");
  245. /* xmm1 = qmul[*q ^ *dq */
  246. asm volatile("pxor %xmm1, %xmm2");
  247. /* xmm2 = *p ^ qmul[*q ^ *dq] */
  248. asm volatile("movdqa %%xmm1, %0" : "=m" (dq[0]));
  249. asm volatile("movdqa %%xmm2, %0" : "=m" (p[0]));
  250. bytes -= 16;
  251. p += 16;
  252. q += 16;
  253. dq += 16;
  254. #endif
  255. }
  256. kernel_fpu_end();
  257. }
  258. const struct raid6_recov_calls raid6_recov_ssse3 = {
  259. .data2 = raid6_2data_recov_ssse3,
  260. .datap = raid6_datap_recov_ssse3,
  261. .valid = raid6_has_ssse3,
  262. #ifdef CONFIG_X86_64
  263. .name = "ssse3x2",
  264. #else
  265. .name = "ssse3x1",
  266. #endif
  267. .priority = 1,
  268. };
  269. #else
  270. #warning "your version of binutils lacks SSSE3 support"
  271. #endif