sse1.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #if defined(__i386__) && !defined(__arch_um__)
  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. raid6_have_sse1_or_mmxext,
  83. "sse1x1",
  84. 1 /* Has cache hints */
  85. };
  86. /*
  87. * Unrolled-by-2 SSE1 implementation
  88. */
  89. static void raid6_sse12_gen_syndrome(int disks, size_t bytes, void **ptrs)
  90. {
  91. u8 **dptr = (u8 **)ptrs;
  92. u8 *p, *q;
  93. int d, z, z0;
  94. z0 = disks - 3; /* Highest data disk */
  95. p = dptr[z0+1]; /* XOR parity */
  96. q = dptr[z0+2]; /* RS syndrome */
  97. kernel_fpu_begin();
  98. asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
  99. asm volatile("pxor %mm5,%mm5"); /* Zero temp */
  100. asm volatile("pxor %mm7,%mm7"); /* Zero temp */
  101. /* We uniformly assume a single prefetch covers at least 16 bytes */
  102. for ( d = 0 ; d < bytes ; d += 16 ) {
  103. asm volatile("prefetchnta %0" : : "m" (dptr[z0][d]));
  104. asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
  105. asm volatile("movq %0,%%mm3" : : "m" (dptr[z0][d+8])); /* P[1] */
  106. asm volatile("movq %mm2,%mm4"); /* Q[0] */
  107. asm volatile("movq %mm3,%mm6"); /* Q[1] */
  108. for ( z = z0-1 ; z >= 0 ; z-- ) {
  109. asm volatile("prefetchnta %0" : : "m" (dptr[z][d]));
  110. asm volatile("pcmpgtb %mm4,%mm5");
  111. asm volatile("pcmpgtb %mm6,%mm7");
  112. asm volatile("paddb %mm4,%mm4");
  113. asm volatile("paddb %mm6,%mm6");
  114. asm volatile("pand %mm0,%mm5");
  115. asm volatile("pand %mm0,%mm7");
  116. asm volatile("pxor %mm5,%mm4");
  117. asm volatile("pxor %mm7,%mm6");
  118. asm volatile("movq %0,%%mm5" : : "m" (dptr[z][d]));
  119. asm volatile("movq %0,%%mm7" : : "m" (dptr[z][d+8]));
  120. asm volatile("pxor %mm5,%mm2");
  121. asm volatile("pxor %mm7,%mm3");
  122. asm volatile("pxor %mm5,%mm4");
  123. asm volatile("pxor %mm7,%mm6");
  124. asm volatile("pxor %mm5,%mm5");
  125. asm volatile("pxor %mm7,%mm7");
  126. }
  127. asm volatile("movntq %%mm2,%0" : "=m" (p[d]));
  128. asm volatile("movntq %%mm3,%0" : "=m" (p[d+8]));
  129. asm volatile("movntq %%mm4,%0" : "=m" (q[d]));
  130. asm volatile("movntq %%mm6,%0" : "=m" (q[d+8]));
  131. }
  132. asm volatile("sfence" : :: "memory");
  133. kernel_fpu_end();
  134. }
  135. const struct raid6_calls raid6_sse1x2 = {
  136. raid6_sse12_gen_syndrome,
  137. raid6_have_sse1_or_mmxext,
  138. "sse1x2",
  139. 1 /* Has cache hints */
  140. };
  141. #endif