xor_vmx.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. *
  16. * Copyright (C) IBM Corporation, 2012
  17. *
  18. * Author: Anton Blanchard <anton@au.ibm.com>
  19. */
  20. #include <altivec.h>
  21. #include <linux/preempt.h>
  22. #include <linux/export.h>
  23. #include <linux/sched.h>
  24. #include <asm/switch_to.h>
  25. typedef vector signed char unative_t;
  26. #define DEFINE(V) \
  27. unative_t *V = (unative_t *)V##_in; \
  28. unative_t V##_0, V##_1, V##_2, V##_3
  29. #define LOAD(V) \
  30. do { \
  31. V##_0 = V[0]; \
  32. V##_1 = V[1]; \
  33. V##_2 = V[2]; \
  34. V##_3 = V[3]; \
  35. } while (0)
  36. #define STORE(V) \
  37. do { \
  38. V[0] = V##_0; \
  39. V[1] = V##_1; \
  40. V[2] = V##_2; \
  41. V[3] = V##_3; \
  42. } while (0)
  43. #define XOR(V1, V2) \
  44. do { \
  45. V1##_0 = vec_xor(V1##_0, V2##_0); \
  46. V1##_1 = vec_xor(V1##_1, V2##_1); \
  47. V1##_2 = vec_xor(V1##_2, V2##_2); \
  48. V1##_3 = vec_xor(V1##_3, V2##_3); \
  49. } while (0)
  50. void xor_altivec_2(unsigned long bytes, unsigned long *v1_in,
  51. unsigned long *v2_in)
  52. {
  53. DEFINE(v1);
  54. DEFINE(v2);
  55. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  56. preempt_disable();
  57. enable_kernel_altivec();
  58. do {
  59. LOAD(v1);
  60. LOAD(v2);
  61. XOR(v1, v2);
  62. STORE(v1);
  63. v1 += 4;
  64. v2 += 4;
  65. } while (--lines > 0);
  66. preempt_enable();
  67. }
  68. EXPORT_SYMBOL(xor_altivec_2);
  69. void xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
  70. unsigned long *v2_in, unsigned long *v3_in)
  71. {
  72. DEFINE(v1);
  73. DEFINE(v2);
  74. DEFINE(v3);
  75. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  76. preempt_disable();
  77. enable_kernel_altivec();
  78. do {
  79. LOAD(v1);
  80. LOAD(v2);
  81. LOAD(v3);
  82. XOR(v1, v2);
  83. XOR(v1, v3);
  84. STORE(v1);
  85. v1 += 4;
  86. v2 += 4;
  87. v3 += 4;
  88. } while (--lines > 0);
  89. preempt_enable();
  90. }
  91. EXPORT_SYMBOL(xor_altivec_3);
  92. void xor_altivec_4(unsigned long bytes, unsigned long *v1_in,
  93. unsigned long *v2_in, unsigned long *v3_in,
  94. unsigned long *v4_in)
  95. {
  96. DEFINE(v1);
  97. DEFINE(v2);
  98. DEFINE(v3);
  99. DEFINE(v4);
  100. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  101. preempt_disable();
  102. enable_kernel_altivec();
  103. do {
  104. LOAD(v1);
  105. LOAD(v2);
  106. LOAD(v3);
  107. LOAD(v4);
  108. XOR(v1, v2);
  109. XOR(v3, v4);
  110. XOR(v1, v3);
  111. STORE(v1);
  112. v1 += 4;
  113. v2 += 4;
  114. v3 += 4;
  115. v4 += 4;
  116. } while (--lines > 0);
  117. preempt_enable();
  118. }
  119. EXPORT_SYMBOL(xor_altivec_4);
  120. void xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
  121. unsigned long *v2_in, unsigned long *v3_in,
  122. unsigned long *v4_in, unsigned long *v5_in)
  123. {
  124. DEFINE(v1);
  125. DEFINE(v2);
  126. DEFINE(v3);
  127. DEFINE(v4);
  128. DEFINE(v5);
  129. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  130. preempt_disable();
  131. enable_kernel_altivec();
  132. do {
  133. LOAD(v1);
  134. LOAD(v2);
  135. LOAD(v3);
  136. LOAD(v4);
  137. LOAD(v5);
  138. XOR(v1, v2);
  139. XOR(v3, v4);
  140. XOR(v1, v5);
  141. XOR(v1, v3);
  142. STORE(v1);
  143. v1 += 4;
  144. v2 += 4;
  145. v3 += 4;
  146. v4 += 4;
  147. v5 += 4;
  148. } while (--lines > 0);
  149. preempt_enable();
  150. }
  151. EXPORT_SYMBOL(xor_altivec_5);