mmx.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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/mmx.c
  14. *
  15. * MMX implementation of RAID-6 syndrome functions
  16. */
  17. #if defined(__i386__) && !defined(__arch_um__)
  18. #include <linux/raid/pq.h>
  19. #include "x86.h"
  20. /* Shared with raid6/sse1.c */
  21. const struct raid6_mmx_constants {
  22. u64 x1d;
  23. } raid6_mmx_constants = {
  24. 0x1d1d1d1d1d1d1d1dULL,
  25. };
  26. static int raid6_have_mmx(void)
  27. {
  28. /* Not really "boot_cpu" but "all_cpus" */
  29. return boot_cpu_has(X86_FEATURE_MMX);
  30. }
  31. /*
  32. * Plain MMX implementation
  33. */
  34. static void raid6_mmx1_gen_syndrome(int disks, size_t bytes, void **ptrs)
  35. {
  36. u8 **dptr = (u8 **)ptrs;
  37. u8 *p, *q;
  38. int d, z, z0;
  39. z0 = disks - 3; /* Highest data disk */
  40. p = dptr[z0+1]; /* XOR parity */
  41. q = dptr[z0+2]; /* RS syndrome */
  42. kernel_fpu_begin();
  43. asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
  44. asm volatile("pxor %mm5,%mm5"); /* Zero temp */
  45. for ( d = 0 ; d < bytes ; d += 8 ) {
  46. asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
  47. asm volatile("movq %mm2,%mm4"); /* Q[0] */
  48. for ( z = z0-1 ; z >= 0 ; z-- ) {
  49. asm volatile("movq %0,%%mm6" : : "m" (dptr[z][d]));
  50. asm volatile("pcmpgtb %mm4,%mm5");
  51. asm volatile("paddb %mm4,%mm4");
  52. asm volatile("pand %mm0,%mm5");
  53. asm volatile("pxor %mm5,%mm4");
  54. asm volatile("pxor %mm5,%mm5");
  55. asm volatile("pxor %mm6,%mm2");
  56. asm volatile("pxor %mm6,%mm4");
  57. }
  58. asm volatile("movq %%mm2,%0" : "=m" (p[d]));
  59. asm volatile("pxor %mm2,%mm2");
  60. asm volatile("movq %%mm4,%0" : "=m" (q[d]));
  61. asm volatile("pxor %mm4,%mm4");
  62. }
  63. kernel_fpu_end();
  64. }
  65. const struct raid6_calls raid6_mmxx1 = {
  66. raid6_mmx1_gen_syndrome,
  67. raid6_have_mmx,
  68. "mmxx1",
  69. 0
  70. };
  71. /*
  72. * Unrolled-by-2 MMX implementation
  73. */
  74. static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs)
  75. {
  76. u8 **dptr = (u8 **)ptrs;
  77. u8 *p, *q;
  78. int d, z, z0;
  79. z0 = disks - 3; /* Highest data disk */
  80. p = dptr[z0+1]; /* XOR parity */
  81. q = dptr[z0+2]; /* RS syndrome */
  82. kernel_fpu_begin();
  83. asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
  84. asm volatile("pxor %mm5,%mm5"); /* Zero temp */
  85. asm volatile("pxor %mm7,%mm7"); /* Zero temp */
  86. for ( d = 0 ; d < bytes ; d += 16 ) {
  87. asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
  88. asm volatile("movq %0,%%mm3" : : "m" (dptr[z0][d+8]));
  89. asm volatile("movq %mm2,%mm4"); /* Q[0] */
  90. asm volatile("movq %mm3,%mm6"); /* Q[1] */
  91. for ( z = z0-1 ; z >= 0 ; z-- ) {
  92. asm volatile("pcmpgtb %mm4,%mm5");
  93. asm volatile("pcmpgtb %mm6,%mm7");
  94. asm volatile("paddb %mm4,%mm4");
  95. asm volatile("paddb %mm6,%mm6");
  96. asm volatile("pand %mm0,%mm5");
  97. asm volatile("pand %mm0,%mm7");
  98. asm volatile("pxor %mm5,%mm4");
  99. asm volatile("pxor %mm7,%mm6");
  100. asm volatile("movq %0,%%mm5" : : "m" (dptr[z][d]));
  101. asm volatile("movq %0,%%mm7" : : "m" (dptr[z][d+8]));
  102. asm volatile("pxor %mm5,%mm2");
  103. asm volatile("pxor %mm7,%mm3");
  104. asm volatile("pxor %mm5,%mm4");
  105. asm volatile("pxor %mm7,%mm6");
  106. asm volatile("pxor %mm5,%mm5");
  107. asm volatile("pxor %mm7,%mm7");
  108. }
  109. asm volatile("movq %%mm2,%0" : "=m" (p[d]));
  110. asm volatile("movq %%mm3,%0" : "=m" (p[d+8]));
  111. asm volatile("movq %%mm4,%0" : "=m" (q[d]));
  112. asm volatile("movq %%mm6,%0" : "=m" (q[d+8]));
  113. }
  114. kernel_fpu_end();
  115. }
  116. const struct raid6_calls raid6_mmxx2 = {
  117. raid6_mmx2_gen_syndrome,
  118. raid6_have_mmx,
  119. "mmxx2",
  120. 0
  121. };
  122. #endif