mmx.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. #ifdef CONFIG_X86_32
  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. NULL, /* XOR not yet implemented */
  68. raid6_have_mmx,
  69. "mmxx1",
  70. 0
  71. };
  72. /*
  73. * Unrolled-by-2 MMX implementation
  74. */
  75. static void raid6_mmx2_gen_syndrome(int disks, size_t bytes, void **ptrs)
  76. {
  77. u8 **dptr = (u8 **)ptrs;
  78. u8 *p, *q;
  79. int d, z, z0;
  80. z0 = disks - 3; /* Highest data disk */
  81. p = dptr[z0+1]; /* XOR parity */
  82. q = dptr[z0+2]; /* RS syndrome */
  83. kernel_fpu_begin();
  84. asm volatile("movq %0,%%mm0" : : "m" (raid6_mmx_constants.x1d));
  85. asm volatile("pxor %mm5,%mm5"); /* Zero temp */
  86. asm volatile("pxor %mm7,%mm7"); /* Zero temp */
  87. for ( d = 0 ; d < bytes ; d += 16 ) {
  88. asm volatile("movq %0,%%mm2" : : "m" (dptr[z0][d])); /* P[0] */
  89. asm volatile("movq %0,%%mm3" : : "m" (dptr[z0][d+8]));
  90. asm volatile("movq %mm2,%mm4"); /* Q[0] */
  91. asm volatile("movq %mm3,%mm6"); /* Q[1] */
  92. for ( z = z0-1 ; z >= 0 ; z-- ) {
  93. asm volatile("pcmpgtb %mm4,%mm5");
  94. asm volatile("pcmpgtb %mm6,%mm7");
  95. asm volatile("paddb %mm4,%mm4");
  96. asm volatile("paddb %mm6,%mm6");
  97. asm volatile("pand %mm0,%mm5");
  98. asm volatile("pand %mm0,%mm7");
  99. asm volatile("pxor %mm5,%mm4");
  100. asm volatile("pxor %mm7,%mm6");
  101. asm volatile("movq %0,%%mm5" : : "m" (dptr[z][d]));
  102. asm volatile("movq %0,%%mm7" : : "m" (dptr[z][d+8]));
  103. asm volatile("pxor %mm5,%mm2");
  104. asm volatile("pxor %mm7,%mm3");
  105. asm volatile("pxor %mm5,%mm4");
  106. asm volatile("pxor %mm7,%mm6");
  107. asm volatile("pxor %mm5,%mm5");
  108. asm volatile("pxor %mm7,%mm7");
  109. }
  110. asm volatile("movq %%mm2,%0" : "=m" (p[d]));
  111. asm volatile("movq %%mm3,%0" : "=m" (p[d+8]));
  112. asm volatile("movq %%mm4,%0" : "=m" (q[d]));
  113. asm volatile("movq %%mm6,%0" : "=m" (q[d+8]));
  114. }
  115. kernel_fpu_end();
  116. }
  117. const struct raid6_calls raid6_mmxx2 = {
  118. raid6_mmx2_gen_syndrome,
  119. NULL, /* XOR not yet implemented */
  120. raid6_have_mmx,
  121. "mmxx2",
  122. 0
  123. };
  124. #endif