sse1.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright 2002 H. Peter Anvin - All Rights Reserved
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  8. * Boston MA 02111-1307, USA; either version 2 of the License, or
  9. * (at your option) any later version; incorporated herein by reference.
  10. *
  11. * ----------------------------------------------------------------------- */
  12. /*
  13. * raid6/sse1.c
  14. *
  15. * SSE-1/MMXEXT implementation of RAID-6 syndrome functions
  16. *
  17. * This is really an MMX implementation, but it requires SSE-1 or
  18. * AMD MMXEXT for prefetch support and a few other features. The
  19. * support for nontemporal memory accesses is enough to make this
  20. * worthwhile as a separate implementation.
  21. */
  22. #ifdef CONFIG_X86_32
  23. #include <linux/raid/pq.h>
  24. #include "x86.h"
  25. /* Defined in raid6/mmx.c */
  26. extern const struct raid6_mmx_constants {
  27. u64 x1d;
  28. } raid6_mmx_constants;
  29. static int raid6_have_sse1_or_mmxext(void)
  30. {
  31. /* Not really boot_cpu but "all_cpus" */
  32. return boot_cpu_has(X86_FEATURE_MMX) &&
  33. (boot_cpu_has(X86_FEATURE_XMM) ||
  34. boot_cpu_has(X86_FEATURE_MMXEXT));
  35. }
  36. /*
  37. * Plain SSE1 implementation
  38. */
  39. static void raid6_sse11_gen_syndrome(int disks, size_t bytes, void **ptrs)
  40. {
  41. u8 **dptr = (u8 **)ptrs;
  42. u8 *p, *q;
  43. int d, z, z0;
  44. z0 = disks - 3; /* Highest data disk */
  45. p = dptr[z0+1]; /* XOR parity */
  46. q = dptr[z0+2]; /* RS syndrome */
  47. kernel_fpu_begin();
  48. asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
  49. asm volatile("pxor %mm5,%mm5"); /* Zero temp */
  50. for ( d = 0 ; d < bytes ; d += 8 ) {
  51. asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
  52. asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
  53. asm volatile("prefetchnta %0" : : "m" (dptr[z0-1][d]));
  54. asm volatile("movq %mm2,%mm4"); /* Q[0] */
  55. asm volatile("movq %0,%%mm6" : : "m" (dptr[z0-1][d]));
  56. for ( z = z0-2 ; z >= 0 ; z-- ) {
  57. asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
  58. asm volatile("pcmpgtb %mm4,%mm5");
  59. asm volatile("paddb %mm4,%mm4");
  60. asm volatile("pand %mm0,%mm5");
  61. asm volatile("pxor %mm5,%mm4");
  62. asm volatile("pxor %mm5,%mm5");
  63. asm volatile("pxor %mm6,%mm2");
  64. asm volatile("pxor %mm6,%mm4");
  65. asm volatile("movq %0,%%mm6" : : "m" (dptr[z][d]));
  66. }
  67. asm volatile("pcmpgtb %mm4,%mm5");
  68. asm volatile("paddb %mm4,%mm4");
  69. asm volatile("pand %mm0,%mm5");
  70. asm volatile("pxor %mm5,%mm4");
  71. asm volatile("pxor %mm5,%mm5");
  72. asm volatile("pxor %mm6,%mm2");
  73. asm volatile("pxor %mm6,%mm4");
  74. asm volatile("movntq %%mm2,%0" : "=m" (p[d]));
  75. asm volatile("movntq %%mm4,%0" : "=m" (q[d]));
  76. }
  77. asm volatile("sfence" : : : "memory");
  78. kernel_fpu_end();
  79. }
  80. const struct raid6_calls raid6_sse1x1 = {
  81. raid6_sse11_gen_syndrome,
  82. NULL, /* XOR not yet implemented */
  83. raid6_have_sse1_or_mmxext,
  84. "sse1x1",
  85. 1 /* Has cache hints */
  86. };
  87. /*
  88. * Unrolled-by-2 SSE1 implementation
  89. */
  90. static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs)
  91. {
  92. u8 **dptr = (u8 **)ptrs;
  93. u8 *p, *q;
  94. int d, z, z0;
  95. z0 = disks - 3; /* Highest data disk */
  96. p = dptr[z0+1]; /* XOR parity */
  97. q = dptr[z0+2]; /* RS syndrome */
  98. kernel_fpu_begin();
  99. asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
  100. asm volatile("pxor %mm5,%mm5"); /* Zero temp */
  101. asm volatile("pxor %mm7,%mm7"); /* Zero temp */
  102. /* We uniformly assume a single prefetch covers at least 16 bytes */
  103. for ( d = 0 ; d < bytes ; d += 16 ) {
  104. asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
  105. asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
  106. asm volatile("movq %0,%%mm3" : : "m" (dptr[z0][d+8])); /* P[1] */
  107. asm volatile("movq %mm2,%mm4"); /* Q[0] */
  108. asm volatile("movq %mm3,%mm6"); /* Q[1] */
  109. for ( z = z0-1 ; z >= 0 ; z-- ) {
  110. asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
  111. asm volatile("pcmpgtb %mm4,%mm5");
  112. asm volatile("pcmpgtb %mm6,%mm7");
  113. asm volatile("paddb %mm4,%mm4");
  114. asm volatile("paddb %mm6,%mm6");
  115. asm volatile("pand %mm0,%mm5");
  116. asm volatile("pand %mm0,%mm7");
  117. asm volatile("pxor %mm5,%mm4");
  118. asm volatile("pxor %mm7,%mm6");
  119. asm volatile("movq %0,%%mm5" : : "m" (dptr[z][d]));
  120. asm volatile("movq %0,%%mm7" : : "m" (dptr[z][d+8]));
  121. asm volatile("pxor %mm5,%mm2");
  122. asm volatile("pxor %mm7,%mm3");
  123. asm volatile("pxor %mm5,%mm4");
  124. asm volatile("pxor %mm7,%mm6");
  125. asm volatile("pxor %mm5,%mm5");
  126. asm volatile("pxor %mm7,%mm7");
  127. }
  128. asm volatile("movntq %%mm2,%0" : "=m" (p[d]));
  129. asm volatile("movntq %%mm3,%0" : "=m" (p[d+8]));
  130. asm volatile("movntq %%mm4,%0" : "=m" (q[d]));
  131. asm volatile("movntq %%mm6,%0" : "=m" (q[d+8]));
  132. }
  133. asm volatile("sfence" : :: "memory");
  134. kernel_fpu_end();
  135. }
  136. const struct raid6_calls raid6_sse1x2 = {
  137. raid6_sse12_gen_syndrome,
  138. NULL, /* XOR not yet implemented */
  139. raid6_have_sse1_or_mmxext,
  140. "sse1x2",
  141. 1 /* Has cache hints */
  142. };
  143. #endif