You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

sbgemm_tcopy_16_power10.c 6.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include <stdio.h>
  39. #include <altivec.h>
  40. #include "common.h"
  41. typedef IFLOAT vec_bf16 __attribute__ ((vector_size (16)));
  42. int CNAME(BLASLONG m, BLASLONG n, IFLOAT *a, BLASLONG lda, IFLOAT *b){
  43. BLASLONG i, j;
  44. IFLOAT *aoffset;
  45. IFLOAT *aoffset1, *aoffset2;
  46. IFLOAT *boffset;
  47. vec_bf16 vtemp01, vtemp02, vtemp03, vtemp04;
  48. IFLOAT ctemp01, ctemp02, ctemp03, ctemp04;
  49. IFLOAT ctemp05, ctemp06, ctemp07, ctemp08;
  50. aoffset = a;
  51. boffset = b;
  52. #if 0
  53. fprintf(stderr, "m = %d n = %d\n", m, n);
  54. #endif
  55. j = (n >> 4);
  56. if (j > 0){
  57. do{
  58. aoffset1 = aoffset;
  59. aoffset2 = aoffset + lda;
  60. aoffset += 16;
  61. i = (m >> 1);
  62. if (i > 0){
  63. do{
  64. vtemp01 = *(vec_bf16 *)(aoffset1);
  65. vtemp02 = *(vec_bf16 *)(aoffset1+8);
  66. vtemp03 = *(vec_bf16 *)(aoffset2);
  67. vtemp04 = *(vec_bf16 *)(aoffset2+8);
  68. *(vec_bf16 *)(boffset + 0) = vec_mergeh(vtemp01, vtemp03);
  69. *(vec_bf16 *)(boffset + 8) = vec_mergel(vtemp01, vtemp03);
  70. *(vec_bf16 *)(boffset + 16) = vec_mergeh(vtemp02, vtemp04);
  71. *(vec_bf16 *)(boffset + 24) = vec_mergel(vtemp02, vtemp04);
  72. aoffset1 += 2 * lda;
  73. aoffset2 += 2 * lda;
  74. boffset += 32;
  75. i --;
  76. }while(i > 0);
  77. }
  78. if (m & 1){
  79. vtemp01 = *(vec_bf16 *)(aoffset1);
  80. vtemp02 = *(vec_bf16 *)(aoffset1+8);
  81. *(vec_bf16 *)(boffset + 0) = vtemp01;
  82. *(vec_bf16 *)(boffset + 8) = vtemp02;
  83. boffset += 16;
  84. }
  85. j--;
  86. }while(j > 0);
  87. } /* end of if(j > 0) */
  88. if (n & 8){
  89. aoffset1 = aoffset;
  90. aoffset2 = aoffset + lda;
  91. aoffset += 8;
  92. i = (m >> 1);
  93. if (i > 0){
  94. do{
  95. vtemp01 = *(vec_bf16 *)(aoffset1);
  96. vtemp03 = *(vec_bf16 *)(aoffset2);
  97. *(vec_bf16 *)(boffset + 0) = vec_mergeh(vtemp01, vtemp03);
  98. *(vec_bf16 *)(boffset + 8) = vec_mergel(vtemp01, vtemp03);
  99. aoffset1 += 2 * lda;
  100. aoffset2 += 2 * lda;
  101. boffset += 16;
  102. i --;
  103. }while(i > 0);
  104. }
  105. if (m & 1){
  106. vtemp01 = *(vec_bf16 *)(aoffset1);
  107. *(vec_bf16 *)(boffset + 0) = vtemp01;
  108. boffset += 8;
  109. }
  110. }
  111. if (n & 4){
  112. aoffset1 = aoffset;
  113. aoffset2 = aoffset + lda;
  114. aoffset += 4;
  115. i = (m >> 1);
  116. if (i > 0){
  117. do{
  118. ctemp01 = *(aoffset1 + 0);
  119. ctemp02 = *(aoffset1 + 1);
  120. ctemp03 = *(aoffset1 + 2);
  121. ctemp04 = *(aoffset1 + 3);
  122. ctemp05 = *(aoffset2 + 0);
  123. ctemp06 = *(aoffset2 + 1);
  124. ctemp07 = *(aoffset2 + 2);
  125. ctemp08 = *(aoffset2 + 3);
  126. *(boffset + 0) = ctemp01;
  127. *(boffset + 1) = ctemp05;
  128. *(boffset + 2) = ctemp02;
  129. *(boffset + 3) = ctemp06;
  130. *(boffset + 4) = ctemp03;
  131. *(boffset + 5) = ctemp07;
  132. *(boffset + 6) = ctemp04;
  133. *(boffset + 7) = ctemp08;
  134. aoffset1 += 2 * lda;
  135. aoffset2 += 2 * lda;
  136. boffset += 8;
  137. i --;
  138. }while(i > 0);
  139. }
  140. if (m & 1){
  141. ctemp01 = *(aoffset1 + 0);
  142. ctemp02 = *(aoffset1 + 1);
  143. ctemp03 = *(aoffset1 + 2);
  144. ctemp04 = *(aoffset1 + 3);
  145. *(boffset + 0) = ctemp01;
  146. *(boffset + 1) = ctemp02;
  147. *(boffset + 2) = ctemp03;
  148. *(boffset + 3) = ctemp04;
  149. boffset += 4;
  150. }
  151. }
  152. if (n & 2){
  153. aoffset1 = aoffset;
  154. aoffset2 = aoffset + lda;
  155. aoffset += 2;
  156. i = (m >> 1);
  157. if (i > 0){
  158. do{
  159. ctemp01 = *(aoffset1 + 0);
  160. ctemp02 = *(aoffset1 + 1);
  161. ctemp03 = *(aoffset2 + 0);
  162. ctemp04 = *(aoffset2 + 1);
  163. *(boffset + 0) = ctemp01;
  164. *(boffset + 1) = ctemp02;
  165. *(boffset + 2) = ctemp03;
  166. *(boffset + 3) = ctemp04;
  167. aoffset1 += 2 * lda;
  168. aoffset2 += 2 * lda;
  169. boffset += 4;
  170. i --;
  171. }while(i > 0);
  172. }
  173. if (m & 1){
  174. ctemp01 = *(aoffset1 + 0);
  175. ctemp02 = *(aoffset1 + 1);
  176. *(boffset + 0) = ctemp01;
  177. *(boffset + 1) = ctemp02;
  178. boffset += 2;
  179. }
  180. }
  181. if (n & 1){
  182. aoffset1 = aoffset;
  183. aoffset2 = aoffset + lda;
  184. i = (m >> 1);
  185. if (i > 0){
  186. do{
  187. ctemp01 = *(aoffset1 + 0);
  188. ctemp02 = *(aoffset2 + 0);
  189. *(boffset + 0) = ctemp01;
  190. *(boffset + 1) = ctemp02;
  191. aoffset1 += 2 * lda;
  192. aoffset2 += 2 * lda;
  193. boffset += 2;
  194. i --;
  195. }while(i > 0);
  196. }
  197. if (m & 1){
  198. ctemp01 = *(aoffset1 + 0);
  199. *(boffset + 0) = ctemp01;
  200. // boffset += 1;
  201. }
  202. }
  203. return 0;
  204. }