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.

cgemm3m_kernel_8x4_haswell.c 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. /* %0 = "+r"(a_pointer), %1 = "+r"(b_pointer), %2 = "+r"(c_pointer), %3 = "+r"(ldc_in_bytes), %4 for k_count, %5 for c_store */
  2. /* r12 = k << 4(const), r13 = k(const), r14 = b_head_pos(const), r15 = tmp */
  3. #include "common.h"
  4. #include <stdint.h>
  5. //recommended settings: GEMM_P = 320, GEMM_Q = 320.
  6. /* m = 8 *//* ymm0 for alpha, ymm1-ymm3 for temporary use, ymm4-ymm15 for accumulators */
  7. #define KERNEL_k1m8n1 \
  8. "vmovups (%0),%%ymm1; addq $32,%0;"\
  9. "vbroadcastss (%1),%%ymm2; vfmadd231ps %%ymm1,%%ymm2,%%ymm4;"\
  10. "addq $4,%1;"
  11. #define KERNEL_h_k1m8n2 \
  12. "vmovsldup (%0),%%ymm1; vmovshdup (%0),%%ymm2; addq $32,%0;"\
  13. "vbroadcastsd (%1),%%ymm3; vfmadd231ps %%ymm1,%%ymm3,%%ymm4; vfmadd231ps %%ymm2,%%ymm3,%%ymm5;"
  14. #define KERNEL_k1m8n2 KERNEL_h_k1m8n2 "addq $8,%1;"
  15. #define KERNEL_h_k1m8n4 \
  16. KERNEL_h_k1m8n2 "vbroadcastsd 8(%1),%%ymm3; vfmadd231ps %%ymm1,%%ymm3,%%ymm6; vfmadd231ps %%ymm2,%%ymm3,%%ymm7;"
  17. #define KERNEL_k1m8n4 KERNEL_h_k1m8n4 "addq $16,%1;"
  18. #define unit_kernel_k1m8n4(c1,c2,c3,c4,...) \
  19. "vbroadcastsd ("#__VA_ARGS__"),%%ymm3; vfmadd231ps %%ymm1,%%ymm3,"#c1"; vfmadd231ps %%ymm2,%%ymm3,"#c2";"\
  20. "vbroadcastsd 8("#__VA_ARGS__"),%%ymm3; vfmadd231ps %%ymm1,%%ymm3,"#c3"; vfmadd231ps %%ymm2,%%ymm3,"#c4";"
  21. #define KERNEL_h_k1m8n8 KERNEL_h_k1m8n4 unit_kernel_k1m8n4(%%ymm8,%%ymm9,%%ymm10,%%ymm11,%1,%%r12,1)
  22. #define KERNEL_k1m8n8 KERNEL_h_k1m8n8 "addq $16,%1;"
  23. #define KERNEL_h_k1m8n12 KERNEL_h_k1m8n8 unit_kernel_k1m8n4(%%ymm12,%%ymm13,%%ymm14,%%ymm15,%1,%%r12,2)
  24. #define KERNEL_k1m8n12 KERNEL_h_k1m8n12 "addq $16,%1;"
  25. #define INIT_m8n1 "vpxor %%ymm4,%%ymm4,%%ymm4;"
  26. #define INIT_m8n2 INIT_m8n1 "vpxor %%ymm5,%%ymm5,%%ymm5;"
  27. #define INIT_m8n4 INIT_m8n2 "vpxor %%ymm6,%%ymm6,%%ymm6;vpxor %%ymm7,%%ymm7,%%ymm7;"
  28. #define unit_init_m8n4(c1,c2,c3,c4) \
  29. "vpxor "#c1","#c1","#c1";vpxor "#c2","#c2","#c2";vpxor "#c3","#c3","#c3";vpxor "#c4","#c4","#c4";"
  30. #define INIT_m8n8 INIT_m8n4 unit_init_m8n4(%%ymm8,%%ymm9,%%ymm10,%%ymm11)
  31. #define INIT_m8n12 INIT_m8n8 unit_init_m8n4(%%ymm12,%%ymm13,%%ymm14,%%ymm15)
  32. #define SAVE_m8n1 \
  33. "vunpcklps %%ymm4,%%ymm4,%%ymm2; vunpckhps %%ymm4,%%ymm4,%%ymm3;"\
  34. "vperm2f128 $2,%%ymm2,%%ymm3,%%ymm1; vperm2f128 $19,%%ymm2,%%ymm3,%%ymm2;"\
  35. "vfmadd213ps (%2),%%ymm0,%%ymm1; vfmadd213ps 32(%2),%%ymm0,%%ymm2; vmovups %%ymm1,(%2); vmovups %%ymm2,32(%2);"
  36. #define unit_save_m8n2(c1,c2) \
  37. "vunpcklpd "#c2","#c1",%%ymm2; vunpckhpd "#c2","#c1",%%ymm3;"\
  38. "vperm2f128 $2,%%ymm2,%%ymm3,"#c1"; vperm2f128 $19,%%ymm2,%%ymm3,"#c2";"\
  39. "vmovsldup "#c1",%%ymm2; vmovsldup "#c2",%%ymm3;"\
  40. "vfmadd213ps (%5),%%ymm0,%%ymm2; vfmadd213ps 32(%5),%%ymm0,%%ymm3; vmovups %%ymm2,(%5); vmovups %%ymm3,32(%5);"\
  41. "vmovshdup "#c1",%%ymm2; vmovshdup "#c2",%%ymm3;"\
  42. "vfmadd213ps (%5,%3,1),%%ymm0,%%ymm2; vfmadd213ps 32(%5,%3,1),%%ymm0,%%ymm3; vmovups %%ymm2,(%5,%3,1); vmovups %%ymm3,32(%5,%3,1);"\
  43. "leaq (%5,%3,2),%5;"
  44. #define SAVE_m8n2 "movq %2,%5;" unit_save_m8n2(%%ymm4,%%ymm5)
  45. #define SAVE_m8n4 SAVE_m8n2 unit_save_m8n2(%%ymm6,%%ymm7)
  46. #define SAVE_m8n8 SAVE_m8n4 unit_save_m8n2(%%ymm8,%%ymm9) unit_save_m8n2(%%ymm10,%%ymm11)
  47. #define SAVE_m8n12 SAVE_m8n8 unit_save_m8n2(%%ymm12,%%ymm13) unit_save_m8n2(%%ymm14,%%ymm15)
  48. #define COMPUTE_m8(ndim) \
  49. INIT_m8n##ndim\
  50. "movq %%r13,%4; movq %%r14,%1; movq %2,%5; xorq %%r15,%%r15;"\
  51. "cmpq $24,%4; jb "#ndim"882f;"\
  52. #ndim"881:\n\t"\
  53. "cmpq $126,%%r15; movq $126,%%r15; cmoveq %3,%%r15;"\
  54. "prefetcht0 64(%1); prefetcht0 64(%1,%%r12,1); prefetcht0 64(%1,%%r12,2);"\
  55. "prefetcht0 512(%0);" KERNEL_k1m8n##ndim KERNEL_k1m8n##ndim\
  56. "prefetcht0 512(%0);" KERNEL_k1m8n##ndim KERNEL_k1m8n##ndim\
  57. "prefetcht1 (%5); leaq -63(%5,%%r15,1),%5;"\
  58. "prefetcht0 64(%1); prefetcht0 64(%1,%%r12,1); prefetcht0 64(%1,%%r12,2);"\
  59. "prefetcht0 512(%0);" KERNEL_k1m8n##ndim KERNEL_k1m8n##ndim\
  60. "prefetcht0 512(%0);" KERNEL_k1m8n##ndim KERNEL_k1m8n##ndim\
  61. "prefetcht1 (%8); addq $16,%8;"\
  62. "subq $8,%4; cmpq $24,%4; jnb "#ndim"881b;"\
  63. "movq %2,%5;"\
  64. #ndim"882:\n\t"\
  65. "testq %4,%4; jz "#ndim"883f;"\
  66. "prefetcht0 (%5); prefetcht0 63(%5); addq %3,%5;"\
  67. KERNEL_k1m8n##ndim\
  68. "decq %4; jmp "#ndim"882b;"\
  69. #ndim"883:\n\t"\
  70. "prefetcht0 (%%r14); prefetcht0 64(%%r14);"\
  71. SAVE_m8n##ndim "addq $64,%2;"
  72. /* m = 4 *//* xmm0 for alpha, xmm1-xmm3 for temporary use, xmm4-xmm15 for accumulators */
  73. #define KERNEL_k1m4n1 \
  74. "vmovups (%0),%%xmm1; addq $16,%0;"\
  75. "vbroadcastss (%1),%%xmm2; vfmadd231ps %%xmm1,%%xmm2,%%xmm4;"\
  76. "addq $4,%1;"
  77. #define KERNEL_h_k1m4n2 \
  78. "vmovsldup (%0),%%xmm1; vmovshdup (%0),%%xmm2; addq $16,%0;"\
  79. "vmovddup (%1),%%xmm3; vfmadd231ps %%xmm1,%%xmm3,%%xmm4; vfmadd231ps %%xmm2,%%xmm3,%%xmm5;"
  80. #define KERNEL_k1m4n2 KERNEL_h_k1m4n2 "addq $8,%1;"
  81. #define KERNEL_h_k1m4n4 \
  82. KERNEL_h_k1m4n2 "vmovddup 8(%1),%%xmm3; vfmadd231ps %%xmm1,%%xmm3,%%xmm6; vfmadd231ps %%xmm2,%%xmm3,%%xmm7;"
  83. #define KERNEL_k1m4n4 KERNEL_h_k1m4n4 "addq $16,%1;"
  84. #define unit_kernel_k1m4n4(c1,c2,c3,c4,...) \
  85. "vmovddup ("#__VA_ARGS__"),%%xmm3; vfmadd231ps %%xmm1,%%xmm3,"#c1"; vfmadd231ps %%xmm2,%%xmm3,"#c2";"\
  86. "vmovddup 8("#__VA_ARGS__"),%%xmm3; vfmadd231ps %%xmm1,%%xmm3,"#c3"; vfmadd231ps %%xmm2,%%xmm3,"#c4";"
  87. #define KERNEL_h_k1m4n8 KERNEL_h_k1m4n4 unit_kernel_k1m4n4(%%xmm8,%%xmm9,%%xmm10,%%xmm11,%1,%%r12,1)
  88. #define KERNEL_k1m4n8 KERNEL_h_k1m4n8 "addq $16,%1;"
  89. #define KERNEL_h_k1m4n12 KERNEL_h_k1m4n8 unit_kernel_k1m4n4(%%xmm12,%%xmm13,%%xmm14,%%xmm15,%1,%%r12,2)
  90. #define KERNEL_k1m4n12 KERNEL_h_k1m4n12 "addq $16,%1;"
  91. #define INIT_m4n1 "vpxor %%xmm4,%%xmm4,%%xmm4;"
  92. #define INIT_m4n2 INIT_m4n1 "vpxor %%xmm5,%%xmm5,%%xmm5;"
  93. #define INIT_m4n4 INIT_m4n2 "vpxor %%xmm6,%%xmm6,%%xmm6;vpxor %%xmm7,%%xmm7,%%xmm7;"
  94. #define unit_init_m4n4(c1,c2,c3,c4) \
  95. "vpxor "#c1","#c1","#c1";vpxor "#c2","#c2","#c2";vpxor "#c3","#c3","#c3";vpxor "#c4","#c4","#c4";"
  96. #define INIT_m4n8 INIT_m4n4 unit_init_m4n4(%%xmm8,%%xmm9,%%xmm10,%%xmm11)
  97. #define INIT_m4n12 INIT_m4n8 unit_init_m4n4(%%xmm12,%%xmm13,%%xmm14,%%xmm15)
  98. #define SAVE_m4n1 \
  99. "vunpcklps %%xmm4,%%xmm4,%%xmm2; vunpckhps %%xmm4,%%xmm4,%%xmm3;"\
  100. "vfmadd213ps (%2),%%xmm0,%%xmm2; vfmadd213ps 16(%2),%%xmm0,%%xmm3; vmovups %%xmm2,(%2); vmovups %%xmm3,16(%2);"
  101. #define unit_save_m4n2(c1,c2) \
  102. "vunpcklpd "#c2","#c1",%%xmm2; vunpckhpd "#c2","#c1","#c2"; vmovapd %%xmm2,"#c1";"\
  103. "vmovsldup "#c1",%%xmm2; vmovsldup "#c2",%%xmm3;"\
  104. "vfmadd213ps (%5),%%xmm0,%%xmm2; vfmadd213ps 16(%5),%%xmm0,%%xmm3; vmovups %%xmm2,(%5); vmovups %%xmm3,16(%5);"\
  105. "vmovshdup "#c1",%%xmm2; vmovshdup "#c2",%%xmm3;"\
  106. "vfmadd213ps (%5,%3,1),%%xmm0,%%xmm2; vfmadd213ps 16(%5,%3,1),%%xmm0,%%xmm3; vmovups %%xmm2,(%5,%3,1); vmovups %%xmm3,16(%5,%3,1);"\
  107. "leaq (%5,%3,2),%5;"
  108. #define SAVE_m4n2 "movq %2,%5;" unit_save_m4n2(%%xmm4,%%xmm5)
  109. #define SAVE_m4n4 SAVE_m4n2 unit_save_m4n2(%%xmm6,%%xmm7)
  110. #define SAVE_m4n8 SAVE_m4n4 unit_save_m4n2(%%xmm8,%%xmm9) unit_save_m4n2(%%xmm10,%%xmm11)
  111. #define SAVE_m4n12 SAVE_m4n8 unit_save_m4n2(%%xmm12,%%xmm13) unit_save_m4n2(%%xmm14,%%xmm15)
  112. #define COMPUTE_m4(ndim) \
  113. INIT_m4n##ndim\
  114. "movq %%r13,%4; movq %%r14,%1;"\
  115. #ndim"442:\n\t"\
  116. "testq %4,%4; jz "#ndim"443f;"\
  117. KERNEL_k1m4n##ndim\
  118. "decq %4; jmp "#ndim"442b;"\
  119. #ndim"443:\n\t"\
  120. SAVE_m4n##ndim "addq $32,%2;"
  121. /* m = 2 *//* xmm0 for alpha, xmm1-xmm3 and xmm10 for temporary use, xmm4-xmm9 for accumulators */
  122. #define INIT_m2n1 "vpxor %%xmm4,%%xmm4,%%xmm4;"
  123. #define KERNEL_k1m2n1 \
  124. "vmovsd (%0),%%xmm1; addq $8,%0;"\
  125. "vbroadcastss (%1),%%xmm2; vfmadd231ps %%xmm1,%%xmm2,%%xmm4;"\
  126. "addq $4,%1;"
  127. #define SAVE_m2n1 \
  128. "vunpcklps %%xmm4,%%xmm4,%%xmm1; vfmadd213ps (%2),%%xmm0,%%xmm1; vmovups %%xmm1,(%2);"
  129. #define INIT_m2n2 INIT_m2n1 "vpxor %%xmm5,%%xmm5,%%xmm5;"
  130. #define KERNEL_k1m2n2 \
  131. "vmovsd (%0),%%xmm1; addq $8,%0;"\
  132. "vbroadcastss (%1),%%xmm2; vfmadd231ps %%xmm1,%%xmm2,%%xmm4;"\
  133. "vbroadcastss 4(%1),%%xmm3; vfmadd231ps %%xmm1,%%xmm3,%%xmm5;"\
  134. "addq $8,%1;"
  135. #define SAVE_m2n2 SAVE_m2n1 \
  136. "vunpcklps %%xmm5,%%xmm5,%%xmm1; vfmadd213ps (%2,%3,1),%%xmm0,%%xmm1; vmovups %%xmm1,(%2,%3,1);"
  137. #define INIT_m2n4 INIT_m2n2
  138. #define INIT_m2n8 INIT_m2n4 "vpxor %%xmm6,%%xmm6,%%xmm6; vpxor %%xmm7,%%xmm7,%%xmm7;"
  139. #define INIT_m2n12 INIT_m2n8 "vpxor %%xmm8,%%xmm8,%%xmm8; vpxor %%xmm9,%%xmm9,%%xmm9;"
  140. #define KERNEL_k1m2n4 \
  141. "vmovups (%1),%%xmm3; addq $16,%1;"\
  142. "vbroadcastss (%0),%%xmm1; vfmadd231ps %%xmm3,%%xmm1,%%xmm4;"\
  143. "vbroadcastss 4(%0),%%xmm2; vfmadd231ps %%xmm3,%%xmm2,%%xmm5;"\
  144. "addq $8,%0;"
  145. #define KERNEL_k1m2n8 \
  146. "vmovups (%1),%%xmm3; vmovups (%1,%%r12,1),%%xmm2; addq $16,%1;"\
  147. "vbroadcastss (%0),%%xmm1; vfmadd231ps %%xmm3,%%xmm1,%%xmm4; vfmadd231ps %%xmm2,%%xmm1,%%xmm6;"\
  148. "vbroadcastss 4(%0),%%xmm1; vfmadd231ps %%xmm3,%%xmm1,%%xmm5; vfmadd231ps %%xmm2,%%xmm1,%%xmm7;"\
  149. "addq $8,%0;"
  150. #define KERNEL_k1m2n12 \
  151. "vmovups (%1),%%xmm3; vmovups (%1,%%r12,1),%%xmm2; vmovups (%1,%%r12,2),%%xmm1; addq $16,%1;"\
  152. "vbroadcastss (%0),%%xmm10; vfmadd231ps %%xmm3,%%xmm10,%%xmm4; vfmadd231ps %%xmm2,%%xmm10,%%xmm6; vfmadd231ps %%xmm1,%%xmm10,%%xmm8;"\
  153. "vbroadcastss 4(%0),%%xmm10; vfmadd231ps %%xmm3,%%xmm10,%%xmm5; vfmadd231ps %%xmm2,%%xmm10,%%xmm7; vfmadd231ps %%xmm1,%%xmm10,%%xmm9;"\
  154. "addq $8,%0;"
  155. #define unit_save_m2n4(c1,c2) \
  156. "vunpcklpd "#c2","#c1",%%xmm1; vunpckhpd "#c2","#c1",%%xmm2;"\
  157. "vmovsldup %%xmm1,%%xmm3; vfmadd213ps (%5),%%xmm0,%%xmm3; vmovups %%xmm3,(%5);"\
  158. "vmovshdup %%xmm1,%%xmm3; vfmadd213ps (%5,%3,1),%%xmm0,%%xmm3; vmovups %%xmm3,(%5,%3,1);"\
  159. "leaq (%5,%3,2),%5;"\
  160. "vmovsldup %%xmm2,%%xmm3; vfmadd213ps (%5),%%xmm0,%%xmm3; vmovups %%xmm3,(%5);"\
  161. "vmovshdup %%xmm2,%%xmm3; vfmadd213ps (%5,%3,1),%%xmm0,%%xmm3; vmovups %%xmm3,(%5,%3,1);"\
  162. "leaq (%5,%3,2),%5;"
  163. #define SAVE_m2n4 "movq %2,%5;" unit_save_m2n4(%%xmm4,%%xmm5)
  164. #define SAVE_m2n8 SAVE_m2n4 unit_save_m2n4(%%xmm6,%%xmm7)
  165. #define SAVE_m2n12 SAVE_m2n8 unit_save_m2n4(%%xmm8,%%xmm9)
  166. #define COMPUTE_m2(ndim) \
  167. INIT_m2n##ndim\
  168. "movq %%r13,%4; movq %%r14,%1;"\
  169. #ndim"222:\n\t"\
  170. "testq %4,%4; jz "#ndim"223f;"\
  171. KERNEL_k1m2n##ndim\
  172. "decq %4; jmp "#ndim"222b;"\
  173. #ndim"223:\n\t"\
  174. SAVE_m2n##ndim "addq $16,%2;"
  175. /* m = 1 *//* xmm0 for alpha, xmm1-xmm3 and xmm10 for temporary use, xmm4-xmm6 for accumulators */
  176. #define INIT_m1n1 "vpxor %%xmm4,%%xmm4,%%xmm4;"
  177. #define KERNEL_k1m1n1 \
  178. "vmovss (%1),%%xmm3; addq $4,%1;"\
  179. "vmovss (%0),%%xmm1; vfmadd231ss %%xmm3,%%xmm1,%%xmm4;"\
  180. "addq $4,%0;"
  181. #define SAVE_m1n1 \
  182. "vunpcklps %%xmm4,%%xmm4,%%xmm4; vmovsd (%2),%%xmm1; vfmadd213ps %%xmm1,%%xmm0,%%xmm4; vmovsd %%xmm4,(%2);"
  183. #define INIT_m1n2 INIT_m1n1
  184. #define KERNEL_k1m1n2 \
  185. "vmovsd (%1),%%xmm3; addq $8,%1;"\
  186. "vbroadcastss (%0),%%xmm1; vfmadd231ps %%xmm3,%%xmm1,%%xmm4;"\
  187. "addq $4,%0;"
  188. #define SAVE_m1n2 \
  189. "vunpcklps %%xmm4,%%xmm4,%%xmm4; vmovsd (%2),%%xmm3; vmovhpd (%2,%3,1),%%xmm3,%%xmm3; vfmadd213ps %%xmm3,%%xmm0,%%xmm4;"\
  190. "vmovsd %%xmm4,(%2); vmovhpd %%xmm4,(%2,%3,1);"
  191. #define INIT_m1n4 INIT_m1n2
  192. #define INIT_m1n8 INIT_m1n4 "vpxor %%xmm5,%%xmm5,%%xmm5;"
  193. #define INIT_m1n12 INIT_m1n8 "vpxor %%xmm6,%%xmm6,%%xmm6;"
  194. #define KERNEL_k1m1n4 \
  195. "vmovups (%1),%%xmm3; addq $16,%1;"\
  196. "vbroadcastss (%0),%%xmm1; vfmadd231ps %%xmm3,%%xmm1,%%xmm4;"\
  197. "addq $4,%0;"
  198. #define KERNEL_k1m1n8 \
  199. "vmovups (%1),%%xmm3; vmovups (%1,%%r12,1),%%xmm2; addq $16,%1;"\
  200. "vbroadcastss (%0),%%xmm1; vfmadd231ps %%xmm3,%%xmm1,%%xmm4; vfmadd231ps %%xmm2,%%xmm1,%%xmm5;"\
  201. "addq $4,%0;"
  202. #define KERNEL_k1m1n12 \
  203. "vmovups (%1),%%xmm3; vmovups (%1,%%r12,1),%%xmm2; vmovups (%1,%%r12,2),%%xmm1; addq $16,%1;"\
  204. "vbroadcastss (%0),%%xmm10; vfmadd231ps %%xmm3,%%xmm10,%%xmm4; vfmadd231ps %%xmm2,%%xmm10,%%xmm5; vfmadd231ps %%xmm1,%%xmm10,%%xmm6;"\
  205. "addq $4,%0;"
  206. #define unit_save_m1n4(c1) \
  207. "vunpcklps "#c1","#c1",%%xmm1; vunpckhps "#c1","#c1",%%xmm2;"\
  208. "vmovsd (%5),%%xmm3; vmovhpd (%5,%3,1),%%xmm3,%%xmm3; vfmadd213ps %%xmm3,%%xmm0,%%xmm1;"\
  209. "vmovsd %%xmm1,(%5); vmovhpd %%xmm1,(%5,%3,1); leaq (%5,%3,2),%5;"\
  210. "vmovsd (%5),%%xmm3; vmovhpd (%5,%3,1),%%xmm3,%%xmm3; vfmadd213ps %%xmm3,%%xmm0,%%xmm2;"\
  211. "vmovsd %%xmm2,(%5); vmovhpd %%xmm2,(%5,%3,1); leaq (%5,%3,2),%5;"
  212. #define SAVE_m1n4 "movq %2,%5;" unit_save_m1n4(%%xmm4)
  213. #define SAVE_m1n8 SAVE_m1n4 unit_save_m1n4(%%xmm5)
  214. #define SAVE_m1n12 SAVE_m1n8 unit_save_m1n4(%%xmm6)
  215. #define COMPUTE_m1(ndim) \
  216. INIT_m1n##ndim\
  217. "movq %%r13,%4; movq %%r14,%1;"\
  218. #ndim"112:\n\t"\
  219. "testq %4,%4; jz "#ndim"113f;"\
  220. KERNEL_k1m1n##ndim\
  221. "decq %4; jmp "#ndim"112b;"\
  222. #ndim"113:\n\t"\
  223. SAVE_m1n##ndim "addq $8,%2;"
  224. /* %0 = "+r"(a_pointer), %1 = "+r"(b_pointer), %2 = "+r"(c_pointer), %3 = "+r"(ldc_in_bytes), %4 = "+r"(K), %5 = "+r"(ctemp) */
  225. /* %6 = "+r"(&alpha), %7 = "+r"(M), %8 = "+r"(next_b) */
  226. /* r11 = m(const), r12 = k << 4(const), r13 = k(const), r14 = b_head_pos(const),r15 = tmp */
  227. #define COMPUTE(ndim) {\
  228. next_b = b_pointer + ndim * K;\
  229. __asm__ __volatile__(\
  230. "vbroadcastsd (%6),%%ymm0;"\
  231. "movq %4,%%r13; movq %4,%%r12; salq $4,%%r12; movq %1,%%r14; movq %7,%%r11;"\
  232. "cmpq $8,%7;jb 33101"#ndim"f;"\
  233. "33109"#ndim":\n\t"\
  234. COMPUTE_m8(ndim)\
  235. "subq $8,%7;cmpq $8,%7;jnb 33109"#ndim"b;"\
  236. "33101"#ndim":\n\t"\
  237. "cmpq $4,%7;jb 33103"#ndim"f;"\
  238. COMPUTE_m4(ndim)\
  239. "subq $4,%7;"\
  240. "33103"#ndim":\n\t"\
  241. "cmpq $2,%7;jb 33104"#ndim"f;"\
  242. COMPUTE_m2(ndim)\
  243. "subq $2,%7;"\
  244. "33104"#ndim":\n\t"\
  245. "testq %7,%7;jz 33105"#ndim"f;"\
  246. COMPUTE_m1(ndim)\
  247. "33105"#ndim":\n\t"\
  248. "movq %%r13,%4; movq %%r14,%1; movq %%r11,%7;"\
  249. :"+r"(a_pointer),"+r"(b_pointer),"+r"(c_pointer),"+r"(ldc_in_bytes),"+r"(K),"+r"(ctemp),"+r"(const_val),"+r"(M),"+r"(next_b)\
  250. ::"r11","r12","r13","r14","r15",\
  251. "xmm0","xmm1","xmm2","xmm3","xmm4","xmm5","xmm6","xmm7","xmm8","xmm9","xmm10","xmm11","xmm12","xmm13","xmm14","xmm15","cc","memory");\
  252. a_pointer -= M * K; b_pointer += ndim * K; c_pointer += 2*(LDC * ndim - M);\
  253. }
  254. int __attribute__ ((noinline))
  255. CNAME(BLASLONG m, BLASLONG n, BLASLONG k, float alphar, float alphai, float * __restrict__ A, float * __restrict__ B, float * __restrict__ C, BLASLONG LDC)
  256. {
  257. if(m==0||n==0||k==0) return 0;
  258. int64_t ldc_in_bytes = (int64_t)LDC * sizeof(float) * 2;
  259. float constval[2]; constval[0] = alphar; constval[1] = alphai;
  260. float *const_val=constval;
  261. int64_t M = (int64_t)m, K = (int64_t)k;
  262. BLASLONG n_count = n;
  263. float *a_pointer = A,*b_pointer = B,*c_pointer = C,*ctemp = C,*next_b = B;
  264. for(;n_count>11;n_count-=12) COMPUTE(12)
  265. for(;n_count>7;n_count-=8) COMPUTE(8)
  266. for(;n_count>3;n_count-=4) COMPUTE(4)
  267. for(;n_count>1;n_count-=2) COMPUTE(2)
  268. if(n_count>0) COMPUTE(1)
  269. return 0;
  270. }