xor_vmx.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. /*
  21. * Sparse (as at v0.5.0) gets very, very confused by this file.
  22. * Make it a bit simpler for it.
  23. */
  24. #if !defined(__CHECKER__)
  25. #include <altivec.h>
  26. #else
  27. #define vec_xor(a, b) a ^ b
  28. #define vector __attribute__((vector_size(16)))
  29. #endif
  30. #include <linux/preempt.h>
  31. #include <linux/export.h>
  32. #include <linux/sched.h>
  33. #include <asm/switch_to.h>
  34. typedef vector signed char unative_t;
  35. #define DEFINE(V) \
  36. unative_t *V = (unative_t *)V##_in; \
  37. unative_t V##_0, V##_1, V##_2, V##_3
  38. #define LOAD(V) \
  39. do { \
  40. V##_0 = V[0]; \
  41. V##_1 = V[1]; \
  42. V##_2 = V[2]; \
  43. V##_3 = V[3]; \
  44. } while (0)
  45. #define STORE(V) \
  46. do { \
  47. V[0] = V##_0; \
  48. V[1] = V##_1; \
  49. V[2] = V##_2; \
  50. V[3] = V##_3; \
  51. } while (0)
  52. #define XOR(V1, V2) \
  53. do { \
  54. V1##_0 = vec_xor(V1##_0, V2##_0); \
  55. V1##_1 = vec_xor(V1##_1, V2##_1); \
  56. V1##_2 = vec_xor(V1##_2, V2##_2); \
  57. V1##_3 = vec_xor(V1##_3, V2##_3); \
  58. } while (0)
  59. void xor_altivec_2(unsigned long bytes, unsigned long *v1_in,
  60. unsigned long *v2_in)
  61. {
  62. DEFINE(v1);
  63. DEFINE(v2);
  64. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  65. preempt_disable();
  66. enable_kernel_altivec();
  67. do {
  68. LOAD(v1);
  69. LOAD(v2);
  70. XOR(v1, v2);
  71. STORE(v1);
  72. v1 += 4;
  73. v2 += 4;
  74. } while (--lines > 0);
  75. disable_kernel_altivec();
  76. preempt_enable();
  77. }
  78. EXPORT_SYMBOL(xor_altivec_2);
  79. void xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
  80. unsigned long *v2_in, unsigned long *v3_in)
  81. {
  82. DEFINE(v1);
  83. DEFINE(v2);
  84. DEFINE(v3);
  85. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  86. preempt_disable();
  87. enable_kernel_altivec();
  88. do {
  89. LOAD(v1);
  90. LOAD(v2);
  91. LOAD(v3);
  92. XOR(v1, v2);
  93. XOR(v1, v3);
  94. STORE(v1);
  95. v1 += 4;
  96. v2 += 4;
  97. v3 += 4;
  98. } while (--lines > 0);
  99. disable_kernel_altivec();
  100. preempt_enable();
  101. }
  102. EXPORT_SYMBOL(xor_altivec_3);
  103. void xor_altivec_4(unsigned long bytes, unsigned long *v1_in,
  104. unsigned long *v2_in, unsigned long *v3_in,
  105. unsigned long *v4_in)
  106. {
  107. DEFINE(v1);
  108. DEFINE(v2);
  109. DEFINE(v3);
  110. DEFINE(v4);
  111. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  112. preempt_disable();
  113. enable_kernel_altivec();
  114. do {
  115. LOAD(v1);
  116. LOAD(v2);
  117. LOAD(v3);
  118. LOAD(v4);
  119. XOR(v1, v2);
  120. XOR(v3, v4);
  121. XOR(v1, v3);
  122. STORE(v1);
  123. v1 += 4;
  124. v2 += 4;
  125. v3 += 4;
  126. v4 += 4;
  127. } while (--lines > 0);
  128. disable_kernel_altivec();
  129. preempt_enable();
  130. }
  131. EXPORT_SYMBOL(xor_altivec_4);
  132. void xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
  133. unsigned long *v2_in, unsigned long *v3_in,
  134. unsigned long *v4_in, unsigned long *v5_in)
  135. {
  136. DEFINE(v1);
  137. DEFINE(v2);
  138. DEFINE(v3);
  139. DEFINE(v4);
  140. DEFINE(v5);
  141. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  142. preempt_disable();
  143. enable_kernel_altivec();
  144. do {
  145. LOAD(v1);
  146. LOAD(v2);
  147. LOAD(v3);
  148. LOAD(v4);
  149. LOAD(v5);
  150. XOR(v1, v2);
  151. XOR(v3, v4);
  152. XOR(v1, v5);
  153. XOR(v1, v3);
  154. STORE(v1);
  155. v1 += 4;
  156. v2 += 4;
  157. v3 += 4;
  158. v4 += 4;
  159. v5 += 4;
  160. } while (--lines > 0);
  161. disable_kernel_altivec();
  162. preempt_enable();
  163. }
  164. EXPORT_SYMBOL(xor_altivec_5);