xor_vmx.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 "xor_vmx.h"
  31. typedef vector signed char unative_t;
  32. #define DEFINE(V) \
  33. unative_t *V = (unative_t *)V##_in; \
  34. unative_t V##_0, V##_1, V##_2, V##_3
  35. #define LOAD(V) \
  36. do { \
  37. V##_0 = V[0]; \
  38. V##_1 = V[1]; \
  39. V##_2 = V[2]; \
  40. V##_3 = V[3]; \
  41. } while (0)
  42. #define STORE(V) \
  43. do { \
  44. V[0] = V##_0; \
  45. V[1] = V##_1; \
  46. V[2] = V##_2; \
  47. V[3] = V##_3; \
  48. } while (0)
  49. #define XOR(V1, V2) \
  50. do { \
  51. V1##_0 = vec_xor(V1##_0, V2##_0); \
  52. V1##_1 = vec_xor(V1##_1, V2##_1); \
  53. V1##_2 = vec_xor(V1##_2, V2##_2); \
  54. V1##_3 = vec_xor(V1##_3, V2##_3); \
  55. } while (0)
  56. void __xor_altivec_2(unsigned long bytes, unsigned long *v1_in,
  57. unsigned long *v2_in)
  58. {
  59. DEFINE(v1);
  60. DEFINE(v2);
  61. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  62. do {
  63. LOAD(v1);
  64. LOAD(v2);
  65. XOR(v1, v2);
  66. STORE(v1);
  67. v1 += 4;
  68. v2 += 4;
  69. } while (--lines > 0);
  70. }
  71. void __xor_altivec_3(unsigned long bytes, unsigned long *v1_in,
  72. unsigned long *v2_in, unsigned long *v3_in)
  73. {
  74. DEFINE(v1);
  75. DEFINE(v2);
  76. DEFINE(v3);
  77. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  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. }
  90. void __xor_altivec_4(unsigned long bytes, unsigned long *v1_in,
  91. unsigned long *v2_in, unsigned long *v3_in,
  92. unsigned long *v4_in)
  93. {
  94. DEFINE(v1);
  95. DEFINE(v2);
  96. DEFINE(v3);
  97. DEFINE(v4);
  98. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  99. do {
  100. LOAD(v1);
  101. LOAD(v2);
  102. LOAD(v3);
  103. LOAD(v4);
  104. XOR(v1, v2);
  105. XOR(v3, v4);
  106. XOR(v1, v3);
  107. STORE(v1);
  108. v1 += 4;
  109. v2 += 4;
  110. v3 += 4;
  111. v4 += 4;
  112. } while (--lines > 0);
  113. }
  114. void __xor_altivec_5(unsigned long bytes, unsigned long *v1_in,
  115. unsigned long *v2_in, unsigned long *v3_in,
  116. unsigned long *v4_in, unsigned long *v5_in)
  117. {
  118. DEFINE(v1);
  119. DEFINE(v2);
  120. DEFINE(v3);
  121. DEFINE(v4);
  122. DEFINE(v5);
  123. unsigned long lines = bytes / (sizeof(unative_t)) / 4;
  124. do {
  125. LOAD(v1);
  126. LOAD(v2);
  127. LOAD(v3);
  128. LOAD(v4);
  129. LOAD(v5);
  130. XOR(v1, v2);
  131. XOR(v3, v4);
  132. XOR(v1, v5);
  133. XOR(v1, v3);
  134. STORE(v1);
  135. v1 += 4;
  136. v2 += 4;
  137. v3 += 4;
  138. v4 += 4;
  139. v5 += 4;
  140. } while (--lines > 0);
  141. }