matmulavx128_c17.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186
  1. /* Implementation of the MATMUL intrinsic
  2. Copyright (C) 2002-2022 Free Software Foundation, Inc.
  3. Contributed by Thomas Koenig <tkoenig@gcc.gnu.org>.
  4. This file is part of the GNU Fortran runtime library (libgfortran).
  5. Libgfortran is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. Libgfortran is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. Under Section 7 of GPL version 3, you are granted additional
  14. permissions described in the GCC Runtime Library Exception, version
  15. 3.1, as published by the Free Software Foundation.
  16. You should have received a copy of the GNU General Public License and
  17. a copy of the GCC Runtime Library Exception along with this program;
  18. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. <http://www.gnu.org/licenses/>. */
  20. #include "libgfortran.h"
  21. #include <string.h>
  22. #include <assert.h>
  23. /* These are the specific versions of matmul with -mprefer-avx128. */
  24. #if defined (HAVE_GFC_COMPLEX_17)
  25. /* Prototype for the BLAS ?gemm subroutine, a pointer to which can be
  26. passed to us by the front-end, in which case we call it for large
  27. matrices. */
  28. typedef void (*blas_call)(const char *, const char *, const int *, const int *,
  29. const int *, const GFC_COMPLEX_17 *, const GFC_COMPLEX_17 *,
  30. const int *, const GFC_COMPLEX_17 *, const int *,
  31. const GFC_COMPLEX_17 *, GFC_COMPLEX_17 *, const int *,
  32. int, int);
  33. #if defined(HAVE_AVX) && defined(HAVE_FMA3) && defined(HAVE_AVX128)
  34. void
  35. matmul_c17_avx128_fma3 (gfc_array_c17 * const restrict retarray,
  36. gfc_array_c17 * const restrict a, gfc_array_c17 * const restrict b, int try_blas,
  37. int blas_limit, blas_call gemm) __attribute__((__target__("avx,fma")));
  38. internal_proto(matmul_c17_avx128_fma3);
  39. void
  40. matmul_c17_avx128_fma3 (gfc_array_c17 * const restrict retarray,
  41. gfc_array_c17 * const restrict a, gfc_array_c17 * const restrict b, int try_blas,
  42. int blas_limit, blas_call gemm)
  43. {
  44. const GFC_COMPLEX_17 * restrict abase;
  45. const GFC_COMPLEX_17 * restrict bbase;
  46. GFC_COMPLEX_17 * restrict dest;
  47. index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
  48. index_type x, y, n, count, xcount, ycount;
  49. assert (GFC_DESCRIPTOR_RANK (a) == 2
  50. || GFC_DESCRIPTOR_RANK (b) == 2);
  51. /* C[xcount,ycount] = A[xcount, count] * B[count,ycount]
  52. Either A or B (but not both) can be rank 1:
  53. o One-dimensional argument A is implicitly treated as a row matrix
  54. dimensioned [1,count], so xcount=1.
  55. o One-dimensional argument B is implicitly treated as a column matrix
  56. dimensioned [count, 1], so ycount=1.
  57. */
  58. if (retarray->base_addr == NULL)
  59. {
  60. if (GFC_DESCRIPTOR_RANK (a) == 1)
  61. {
  62. GFC_DIMENSION_SET(retarray->dim[0], 0,
  63. GFC_DESCRIPTOR_EXTENT(b,1) - 1, 1);
  64. }
  65. else if (GFC_DESCRIPTOR_RANK (b) == 1)
  66. {
  67. GFC_DIMENSION_SET(retarray->dim[0], 0,
  68. GFC_DESCRIPTOR_EXTENT(a,0) - 1, 1);
  69. }
  70. else
  71. {
  72. GFC_DIMENSION_SET(retarray->dim[0], 0,
  73. GFC_DESCRIPTOR_EXTENT(a,0) - 1, 1);
  74. GFC_DIMENSION_SET(retarray->dim[1], 0,
  75. GFC_DESCRIPTOR_EXTENT(b,1) - 1,
  76. GFC_DESCRIPTOR_EXTENT(retarray,0));
  77. }
  78. retarray->base_addr
  79. = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_COMPLEX_17));
  80. retarray->offset = 0;
  81. }
  82. else if (unlikely (compile_options.bounds_check))
  83. {
  84. index_type ret_extent, arg_extent;
  85. if (GFC_DESCRIPTOR_RANK (a) == 1)
  86. {
  87. arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
  88. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
  89. if (arg_extent != ret_extent)
  90. runtime_error ("Array bound mismatch for dimension 1 of "
  91. "array (%ld/%ld) ",
  92. (long int) ret_extent, (long int) arg_extent);
  93. }
  94. else if (GFC_DESCRIPTOR_RANK (b) == 1)
  95. {
  96. arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
  97. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
  98. if (arg_extent != ret_extent)
  99. runtime_error ("Array bound mismatch for dimension 1 of "
  100. "array (%ld/%ld) ",
  101. (long int) ret_extent, (long int) arg_extent);
  102. }
  103. else
  104. {
  105. arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
  106. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
  107. if (arg_extent != ret_extent)
  108. runtime_error ("Array bound mismatch for dimension 1 of "
  109. "array (%ld/%ld) ",
  110. (long int) ret_extent, (long int) arg_extent);
  111. arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
  112. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
  113. if (arg_extent != ret_extent)
  114. runtime_error ("Array bound mismatch for dimension 2 of "
  115. "array (%ld/%ld) ",
  116. (long int) ret_extent, (long int) arg_extent);
  117. }
  118. }
  119. if (GFC_DESCRIPTOR_RANK (retarray) == 1)
  120. {
  121. /* One-dimensional result may be addressed in the code below
  122. either as a row or a column matrix. We want both cases to
  123. work. */
  124. rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
  125. }
  126. else
  127. {
  128. rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
  129. rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
  130. }
  131. if (GFC_DESCRIPTOR_RANK (a) == 1)
  132. {
  133. /* Treat it as a a row matrix A[1,count]. */
  134. axstride = GFC_DESCRIPTOR_STRIDE(a,0);
  135. aystride = 1;
  136. xcount = 1;
  137. count = GFC_DESCRIPTOR_EXTENT(a,0);
  138. }
  139. else
  140. {
  141. axstride = GFC_DESCRIPTOR_STRIDE(a,0);
  142. aystride = GFC_DESCRIPTOR_STRIDE(a,1);
  143. count = GFC_DESCRIPTOR_EXTENT(a,1);
  144. xcount = GFC_DESCRIPTOR_EXTENT(a,0);
  145. }
  146. if (count != GFC_DESCRIPTOR_EXTENT(b,0))
  147. {
  148. if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
  149. runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
  150. "in dimension 1: is %ld, should be %ld",
  151. (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
  152. }
  153. if (GFC_DESCRIPTOR_RANK (b) == 1)
  154. {
  155. /* Treat it as a column matrix B[count,1] */
  156. bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
  157. /* bystride should never be used for 1-dimensional b.
  158. The value is only used for calculation of the
  159. memory by the buffer. */
  160. bystride = 256;
  161. ycount = 1;
  162. }
  163. else
  164. {
  165. bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
  166. bystride = GFC_DESCRIPTOR_STRIDE(b,1);
  167. ycount = GFC_DESCRIPTOR_EXTENT(b,1);
  168. }
  169. abase = a->base_addr;
  170. bbase = b->base_addr;
  171. dest = retarray->base_addr;
  172. /* Now that everything is set up, we perform the multiplication
  173. itself. */
  174. #define POW3(x) (((float) (x)) * ((float) (x)) * ((float) (x)))
  175. #define min(a,b) ((a) <= (b) ? (a) : (b))
  176. #define max(a,b) ((a) >= (b) ? (a) : (b))
  177. if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
  178. && (bxstride == 1 || bystride == 1)
  179. && (((float) xcount) * ((float) ycount) * ((float) count)
  180. > POW3(blas_limit)))
  181. {
  182. const int m = xcount, n = ycount, k = count, ldc = rystride;
  183. const GFC_COMPLEX_17 one = 1, zero = 0;
  184. const int lda = (axstride == 1) ? aystride : axstride,
  185. ldb = (bxstride == 1) ? bystride : bxstride;
  186. if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
  187. {
  188. assert (gemm != NULL);
  189. const char *transa, *transb;
  190. if (try_blas & 2)
  191. transa = "C";
  192. else
  193. transa = axstride == 1 ? "N" : "T";
  194. if (try_blas & 4)
  195. transb = "C";
  196. else
  197. transb = bxstride == 1 ? "N" : "T";
  198. gemm (transa, transb , &m,
  199. &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
  200. &ldc, 1, 1);
  201. return;
  202. }
  203. }
  204. if (rxstride == 1 && axstride == 1 && bxstride == 1
  205. && GFC_DESCRIPTOR_RANK (b) != 1)
  206. {
  207. /* This block of code implements a tuned matmul, derived from
  208. Superscalar GEMM-based level 3 BLAS, Beta version 0.1
  209. Bo Kagstrom and Per Ling
  210. Department of Computing Science
  211. Umea University
  212. S-901 87 Umea, Sweden
  213. from netlib.org, translated to C, and modified for matmul.m4. */
  214. const GFC_COMPLEX_17 *a, *b;
  215. GFC_COMPLEX_17 *c;
  216. const index_type m = xcount, n = ycount, k = count;
  217. /* System generated locals */
  218. index_type a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset,
  219. i1, i2, i3, i4, i5, i6;
  220. /* Local variables */
  221. GFC_COMPLEX_17 f11, f12, f21, f22, f31, f32, f41, f42,
  222. f13, f14, f23, f24, f33, f34, f43, f44;
  223. index_type i, j, l, ii, jj, ll;
  224. index_type isec, jsec, lsec, uisec, ujsec, ulsec;
  225. GFC_COMPLEX_17 *t1;
  226. a = abase;
  227. b = bbase;
  228. c = retarray->base_addr;
  229. /* Parameter adjustments */
  230. c_dim1 = rystride;
  231. c_offset = 1 + c_dim1;
  232. c -= c_offset;
  233. a_dim1 = aystride;
  234. a_offset = 1 + a_dim1;
  235. a -= a_offset;
  236. b_dim1 = bystride;
  237. b_offset = 1 + b_dim1;
  238. b -= b_offset;
  239. /* Empty c first. */
  240. for (j=1; j<=n; j++)
  241. for (i=1; i<=m; i++)
  242. c[i + j * c_dim1] = (GFC_COMPLEX_17)0;
  243. /* Early exit if possible */
  244. if (m == 0 || n == 0 || k == 0)
  245. return;
  246. /* Adjust size of t1 to what is needed. */
  247. index_type t1_dim, a_sz;
  248. if (aystride == 1)
  249. a_sz = rystride;
  250. else
  251. a_sz = a_dim1;
  252. t1_dim = a_sz * 256 + b_dim1;
  253. if (t1_dim > 65536)
  254. t1_dim = 65536;
  255. t1 = malloc (t1_dim * sizeof(GFC_COMPLEX_17));
  256. /* Start turning the crank. */
  257. i1 = n;
  258. for (jj = 1; jj <= i1; jj += 512)
  259. {
  260. /* Computing MIN */
  261. i2 = 512;
  262. i3 = n - jj + 1;
  263. jsec = min(i2,i3);
  264. ujsec = jsec - jsec % 4;
  265. i2 = k;
  266. for (ll = 1; ll <= i2; ll += 256)
  267. {
  268. /* Computing MIN */
  269. i3 = 256;
  270. i4 = k - ll + 1;
  271. lsec = min(i3,i4);
  272. ulsec = lsec - lsec % 2;
  273. i3 = m;
  274. for (ii = 1; ii <= i3; ii += 256)
  275. {
  276. /* Computing MIN */
  277. i4 = 256;
  278. i5 = m - ii + 1;
  279. isec = min(i4,i5);
  280. uisec = isec - isec % 2;
  281. i4 = ll + ulsec - 1;
  282. for (l = ll; l <= i4; l += 2)
  283. {
  284. i5 = ii + uisec - 1;
  285. for (i = ii; i <= i5; i += 2)
  286. {
  287. t1[l - ll + 1 + ((i - ii + 1) << 8) - 257] =
  288. a[i + l * a_dim1];
  289. t1[l - ll + 2 + ((i - ii + 1) << 8) - 257] =
  290. a[i + (l + 1) * a_dim1];
  291. t1[l - ll + 1 + ((i - ii + 2) << 8) - 257] =
  292. a[i + 1 + l * a_dim1];
  293. t1[l - ll + 2 + ((i - ii + 2) << 8) - 257] =
  294. a[i + 1 + (l + 1) * a_dim1];
  295. }
  296. if (uisec < isec)
  297. {
  298. t1[l - ll + 1 + (isec << 8) - 257] =
  299. a[ii + isec - 1 + l * a_dim1];
  300. t1[l - ll + 2 + (isec << 8) - 257] =
  301. a[ii + isec - 1 + (l + 1) * a_dim1];
  302. }
  303. }
  304. if (ulsec < lsec)
  305. {
  306. i4 = ii + isec - 1;
  307. for (i = ii; i<= i4; ++i)
  308. {
  309. t1[lsec + ((i - ii + 1) << 8) - 257] =
  310. a[i + (ll + lsec - 1) * a_dim1];
  311. }
  312. }
  313. uisec = isec - isec % 4;
  314. i4 = jj + ujsec - 1;
  315. for (j = jj; j <= i4; j += 4)
  316. {
  317. i5 = ii + uisec - 1;
  318. for (i = ii; i <= i5; i += 4)
  319. {
  320. f11 = c[i + j * c_dim1];
  321. f21 = c[i + 1 + j * c_dim1];
  322. f12 = c[i + (j + 1) * c_dim1];
  323. f22 = c[i + 1 + (j + 1) * c_dim1];
  324. f13 = c[i + (j + 2) * c_dim1];
  325. f23 = c[i + 1 + (j + 2) * c_dim1];
  326. f14 = c[i + (j + 3) * c_dim1];
  327. f24 = c[i + 1 + (j + 3) * c_dim1];
  328. f31 = c[i + 2 + j * c_dim1];
  329. f41 = c[i + 3 + j * c_dim1];
  330. f32 = c[i + 2 + (j + 1) * c_dim1];
  331. f42 = c[i + 3 + (j + 1) * c_dim1];
  332. f33 = c[i + 2 + (j + 2) * c_dim1];
  333. f43 = c[i + 3 + (j + 2) * c_dim1];
  334. f34 = c[i + 2 + (j + 3) * c_dim1];
  335. f44 = c[i + 3 + (j + 3) * c_dim1];
  336. i6 = ll + lsec - 1;
  337. for (l = ll; l <= i6; ++l)
  338. {
  339. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  340. * b[l + j * b_dim1];
  341. f21 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  342. * b[l + j * b_dim1];
  343. f12 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  344. * b[l + (j + 1) * b_dim1];
  345. f22 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  346. * b[l + (j + 1) * b_dim1];
  347. f13 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  348. * b[l + (j + 2) * b_dim1];
  349. f23 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  350. * b[l + (j + 2) * b_dim1];
  351. f14 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  352. * b[l + (j + 3) * b_dim1];
  353. f24 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  354. * b[l + (j + 3) * b_dim1];
  355. f31 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  356. * b[l + j * b_dim1];
  357. f41 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  358. * b[l + j * b_dim1];
  359. f32 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  360. * b[l + (j + 1) * b_dim1];
  361. f42 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  362. * b[l + (j + 1) * b_dim1];
  363. f33 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  364. * b[l + (j + 2) * b_dim1];
  365. f43 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  366. * b[l + (j + 2) * b_dim1];
  367. f34 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  368. * b[l + (j + 3) * b_dim1];
  369. f44 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  370. * b[l + (j + 3) * b_dim1];
  371. }
  372. c[i + j * c_dim1] = f11;
  373. c[i + 1 + j * c_dim1] = f21;
  374. c[i + (j + 1) * c_dim1] = f12;
  375. c[i + 1 + (j + 1) * c_dim1] = f22;
  376. c[i + (j + 2) * c_dim1] = f13;
  377. c[i + 1 + (j + 2) * c_dim1] = f23;
  378. c[i + (j + 3) * c_dim1] = f14;
  379. c[i + 1 + (j + 3) * c_dim1] = f24;
  380. c[i + 2 + j * c_dim1] = f31;
  381. c[i + 3 + j * c_dim1] = f41;
  382. c[i + 2 + (j + 1) * c_dim1] = f32;
  383. c[i + 3 + (j + 1) * c_dim1] = f42;
  384. c[i + 2 + (j + 2) * c_dim1] = f33;
  385. c[i + 3 + (j + 2) * c_dim1] = f43;
  386. c[i + 2 + (j + 3) * c_dim1] = f34;
  387. c[i + 3 + (j + 3) * c_dim1] = f44;
  388. }
  389. if (uisec < isec)
  390. {
  391. i5 = ii + isec - 1;
  392. for (i = ii + uisec; i <= i5; ++i)
  393. {
  394. f11 = c[i + j * c_dim1];
  395. f12 = c[i + (j + 1) * c_dim1];
  396. f13 = c[i + (j + 2) * c_dim1];
  397. f14 = c[i + (j + 3) * c_dim1];
  398. i6 = ll + lsec - 1;
  399. for (l = ll; l <= i6; ++l)
  400. {
  401. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  402. 257] * b[l + j * b_dim1];
  403. f12 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  404. 257] * b[l + (j + 1) * b_dim1];
  405. f13 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  406. 257] * b[l + (j + 2) * b_dim1];
  407. f14 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  408. 257] * b[l + (j + 3) * b_dim1];
  409. }
  410. c[i + j * c_dim1] = f11;
  411. c[i + (j + 1) * c_dim1] = f12;
  412. c[i + (j + 2) * c_dim1] = f13;
  413. c[i + (j + 3) * c_dim1] = f14;
  414. }
  415. }
  416. }
  417. if (ujsec < jsec)
  418. {
  419. i4 = jj + jsec - 1;
  420. for (j = jj + ujsec; j <= i4; ++j)
  421. {
  422. i5 = ii + uisec - 1;
  423. for (i = ii; i <= i5; i += 4)
  424. {
  425. f11 = c[i + j * c_dim1];
  426. f21 = c[i + 1 + j * c_dim1];
  427. f31 = c[i + 2 + j * c_dim1];
  428. f41 = c[i + 3 + j * c_dim1];
  429. i6 = ll + lsec - 1;
  430. for (l = ll; l <= i6; ++l)
  431. {
  432. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  433. 257] * b[l + j * b_dim1];
  434. f21 += t1[l - ll + 1 + ((i - ii + 2) << 8) -
  435. 257] * b[l + j * b_dim1];
  436. f31 += t1[l - ll + 1 + ((i - ii + 3) << 8) -
  437. 257] * b[l + j * b_dim1];
  438. f41 += t1[l - ll + 1 + ((i - ii + 4) << 8) -
  439. 257] * b[l + j * b_dim1];
  440. }
  441. c[i + j * c_dim1] = f11;
  442. c[i + 1 + j * c_dim1] = f21;
  443. c[i + 2 + j * c_dim1] = f31;
  444. c[i + 3 + j * c_dim1] = f41;
  445. }
  446. i5 = ii + isec - 1;
  447. for (i = ii + uisec; i <= i5; ++i)
  448. {
  449. f11 = c[i + j * c_dim1];
  450. i6 = ll + lsec - 1;
  451. for (l = ll; l <= i6; ++l)
  452. {
  453. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  454. 257] * b[l + j * b_dim1];
  455. }
  456. c[i + j * c_dim1] = f11;
  457. }
  458. }
  459. }
  460. }
  461. }
  462. }
  463. free(t1);
  464. return;
  465. }
  466. else if (rxstride == 1 && aystride == 1 && bxstride == 1)
  467. {
  468. if (GFC_DESCRIPTOR_RANK (a) != 1)
  469. {
  470. const GFC_COMPLEX_17 *restrict abase_x;
  471. const GFC_COMPLEX_17 *restrict bbase_y;
  472. GFC_COMPLEX_17 *restrict dest_y;
  473. GFC_COMPLEX_17 s;
  474. for (y = 0; y < ycount; y++)
  475. {
  476. bbase_y = &bbase[y*bystride];
  477. dest_y = &dest[y*rystride];
  478. for (x = 0; x < xcount; x++)
  479. {
  480. abase_x = &abase[x*axstride];
  481. s = (GFC_COMPLEX_17) 0;
  482. for (n = 0; n < count; n++)
  483. s += abase_x[n] * bbase_y[n];
  484. dest_y[x] = s;
  485. }
  486. }
  487. }
  488. else
  489. {
  490. const GFC_COMPLEX_17 *restrict bbase_y;
  491. GFC_COMPLEX_17 s;
  492. for (y = 0; y < ycount; y++)
  493. {
  494. bbase_y = &bbase[y*bystride];
  495. s = (GFC_COMPLEX_17) 0;
  496. for (n = 0; n < count; n++)
  497. s += abase[n*axstride] * bbase_y[n];
  498. dest[y*rystride] = s;
  499. }
  500. }
  501. }
  502. else if (GFC_DESCRIPTOR_RANK (a) == 1)
  503. {
  504. const GFC_COMPLEX_17 *restrict bbase_y;
  505. GFC_COMPLEX_17 s;
  506. for (y = 0; y < ycount; y++)
  507. {
  508. bbase_y = &bbase[y*bystride];
  509. s = (GFC_COMPLEX_17) 0;
  510. for (n = 0; n < count; n++)
  511. s += abase[n*axstride] * bbase_y[n*bxstride];
  512. dest[y*rxstride] = s;
  513. }
  514. }
  515. else if (axstride < aystride)
  516. {
  517. for (y = 0; y < ycount; y++)
  518. for (x = 0; x < xcount; x++)
  519. dest[x*rxstride + y*rystride] = (GFC_COMPLEX_17)0;
  520. for (y = 0; y < ycount; y++)
  521. for (n = 0; n < count; n++)
  522. for (x = 0; x < xcount; x++)
  523. /* dest[x,y] += a[x,n] * b[n,y] */
  524. dest[x*rxstride + y*rystride] +=
  525. abase[x*axstride + n*aystride] *
  526. bbase[n*bxstride + y*bystride];
  527. }
  528. else
  529. {
  530. const GFC_COMPLEX_17 *restrict abase_x;
  531. const GFC_COMPLEX_17 *restrict bbase_y;
  532. GFC_COMPLEX_17 *restrict dest_y;
  533. GFC_COMPLEX_17 s;
  534. for (y = 0; y < ycount; y++)
  535. {
  536. bbase_y = &bbase[y*bystride];
  537. dest_y = &dest[y*rystride];
  538. for (x = 0; x < xcount; x++)
  539. {
  540. abase_x = &abase[x*axstride];
  541. s = (GFC_COMPLEX_17) 0;
  542. for (n = 0; n < count; n++)
  543. s += abase_x[n*aystride] * bbase_y[n*bxstride];
  544. dest_y[x*rxstride] = s;
  545. }
  546. }
  547. }
  548. }
  549. #undef POW3
  550. #undef min
  551. #undef max
  552. #endif
  553. #if defined(HAVE_AVX) && defined(HAVE_FMA4) && defined(HAVE_AVX128)
  554. void
  555. matmul_c17_avx128_fma4 (gfc_array_c17 * const restrict retarray,
  556. gfc_array_c17 * const restrict a, gfc_array_c17 * const restrict b, int try_blas,
  557. int blas_limit, blas_call gemm) __attribute__((__target__("avx,fma4")));
  558. internal_proto(matmul_c17_avx128_fma4);
  559. void
  560. matmul_c17_avx128_fma4 (gfc_array_c17 * const restrict retarray,
  561. gfc_array_c17 * const restrict a, gfc_array_c17 * const restrict b, int try_blas,
  562. int blas_limit, blas_call gemm)
  563. {
  564. const GFC_COMPLEX_17 * restrict abase;
  565. const GFC_COMPLEX_17 * restrict bbase;
  566. GFC_COMPLEX_17 * restrict dest;
  567. index_type rxstride, rystride, axstride, aystride, bxstride, bystride;
  568. index_type x, y, n, count, xcount, ycount;
  569. assert (GFC_DESCRIPTOR_RANK (a) == 2
  570. || GFC_DESCRIPTOR_RANK (b) == 2);
  571. /* C[xcount,ycount] = A[xcount, count] * B[count,ycount]
  572. Either A or B (but not both) can be rank 1:
  573. o One-dimensional argument A is implicitly treated as a row matrix
  574. dimensioned [1,count], so xcount=1.
  575. o One-dimensional argument B is implicitly treated as a column matrix
  576. dimensioned [count, 1], so ycount=1.
  577. */
  578. if (retarray->base_addr == NULL)
  579. {
  580. if (GFC_DESCRIPTOR_RANK (a) == 1)
  581. {
  582. GFC_DIMENSION_SET(retarray->dim[0], 0,
  583. GFC_DESCRIPTOR_EXTENT(b,1) - 1, 1);
  584. }
  585. else if (GFC_DESCRIPTOR_RANK (b) == 1)
  586. {
  587. GFC_DIMENSION_SET(retarray->dim[0], 0,
  588. GFC_DESCRIPTOR_EXTENT(a,0) - 1, 1);
  589. }
  590. else
  591. {
  592. GFC_DIMENSION_SET(retarray->dim[0], 0,
  593. GFC_DESCRIPTOR_EXTENT(a,0) - 1, 1);
  594. GFC_DIMENSION_SET(retarray->dim[1], 0,
  595. GFC_DESCRIPTOR_EXTENT(b,1) - 1,
  596. GFC_DESCRIPTOR_EXTENT(retarray,0));
  597. }
  598. retarray->base_addr
  599. = xmallocarray (size0 ((array_t *) retarray), sizeof (GFC_COMPLEX_17));
  600. retarray->offset = 0;
  601. }
  602. else if (unlikely (compile_options.bounds_check))
  603. {
  604. index_type ret_extent, arg_extent;
  605. if (GFC_DESCRIPTOR_RANK (a) == 1)
  606. {
  607. arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
  608. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
  609. if (arg_extent != ret_extent)
  610. runtime_error ("Array bound mismatch for dimension 1 of "
  611. "array (%ld/%ld) ",
  612. (long int) ret_extent, (long int) arg_extent);
  613. }
  614. else if (GFC_DESCRIPTOR_RANK (b) == 1)
  615. {
  616. arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
  617. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
  618. if (arg_extent != ret_extent)
  619. runtime_error ("Array bound mismatch for dimension 1 of "
  620. "array (%ld/%ld) ",
  621. (long int) ret_extent, (long int) arg_extent);
  622. }
  623. else
  624. {
  625. arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
  626. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
  627. if (arg_extent != ret_extent)
  628. runtime_error ("Array bound mismatch for dimension 1 of "
  629. "array (%ld/%ld) ",
  630. (long int) ret_extent, (long int) arg_extent);
  631. arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
  632. ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
  633. if (arg_extent != ret_extent)
  634. runtime_error ("Array bound mismatch for dimension 2 of "
  635. "array (%ld/%ld) ",
  636. (long int) ret_extent, (long int) arg_extent);
  637. }
  638. }
  639. if (GFC_DESCRIPTOR_RANK (retarray) == 1)
  640. {
  641. /* One-dimensional result may be addressed in the code below
  642. either as a row or a column matrix. We want both cases to
  643. work. */
  644. rxstride = rystride = GFC_DESCRIPTOR_STRIDE(retarray,0);
  645. }
  646. else
  647. {
  648. rxstride = GFC_DESCRIPTOR_STRIDE(retarray,0);
  649. rystride = GFC_DESCRIPTOR_STRIDE(retarray,1);
  650. }
  651. if (GFC_DESCRIPTOR_RANK (a) == 1)
  652. {
  653. /* Treat it as a a row matrix A[1,count]. */
  654. axstride = GFC_DESCRIPTOR_STRIDE(a,0);
  655. aystride = 1;
  656. xcount = 1;
  657. count = GFC_DESCRIPTOR_EXTENT(a,0);
  658. }
  659. else
  660. {
  661. axstride = GFC_DESCRIPTOR_STRIDE(a,0);
  662. aystride = GFC_DESCRIPTOR_STRIDE(a,1);
  663. count = GFC_DESCRIPTOR_EXTENT(a,1);
  664. xcount = GFC_DESCRIPTOR_EXTENT(a,0);
  665. }
  666. if (count != GFC_DESCRIPTOR_EXTENT(b,0))
  667. {
  668. if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
  669. runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
  670. "in dimension 1: is %ld, should be %ld",
  671. (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
  672. }
  673. if (GFC_DESCRIPTOR_RANK (b) == 1)
  674. {
  675. /* Treat it as a column matrix B[count,1] */
  676. bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
  677. /* bystride should never be used for 1-dimensional b.
  678. The value is only used for calculation of the
  679. memory by the buffer. */
  680. bystride = 256;
  681. ycount = 1;
  682. }
  683. else
  684. {
  685. bxstride = GFC_DESCRIPTOR_STRIDE(b,0);
  686. bystride = GFC_DESCRIPTOR_STRIDE(b,1);
  687. ycount = GFC_DESCRIPTOR_EXTENT(b,1);
  688. }
  689. abase = a->base_addr;
  690. bbase = b->base_addr;
  691. dest = retarray->base_addr;
  692. /* Now that everything is set up, we perform the multiplication
  693. itself. */
  694. #define POW3(x) (((float) (x)) * ((float) (x)) * ((float) (x)))
  695. #define min(a,b) ((a) <= (b) ? (a) : (b))
  696. #define max(a,b) ((a) >= (b) ? (a) : (b))
  697. if (try_blas && rxstride == 1 && (axstride == 1 || aystride == 1)
  698. && (bxstride == 1 || bystride == 1)
  699. && (((float) xcount) * ((float) ycount) * ((float) count)
  700. > POW3(blas_limit)))
  701. {
  702. const int m = xcount, n = ycount, k = count, ldc = rystride;
  703. const GFC_COMPLEX_17 one = 1, zero = 0;
  704. const int lda = (axstride == 1) ? aystride : axstride,
  705. ldb = (bxstride == 1) ? bystride : bxstride;
  706. if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
  707. {
  708. assert (gemm != NULL);
  709. const char *transa, *transb;
  710. if (try_blas & 2)
  711. transa = "C";
  712. else
  713. transa = axstride == 1 ? "N" : "T";
  714. if (try_blas & 4)
  715. transb = "C";
  716. else
  717. transb = bxstride == 1 ? "N" : "T";
  718. gemm (transa, transb , &m,
  719. &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
  720. &ldc, 1, 1);
  721. return;
  722. }
  723. }
  724. if (rxstride == 1 && axstride == 1 && bxstride == 1
  725. && GFC_DESCRIPTOR_RANK (b) != 1)
  726. {
  727. /* This block of code implements a tuned matmul, derived from
  728. Superscalar GEMM-based level 3 BLAS, Beta version 0.1
  729. Bo Kagstrom and Per Ling
  730. Department of Computing Science
  731. Umea University
  732. S-901 87 Umea, Sweden
  733. from netlib.org, translated to C, and modified for matmul.m4. */
  734. const GFC_COMPLEX_17 *a, *b;
  735. GFC_COMPLEX_17 *c;
  736. const index_type m = xcount, n = ycount, k = count;
  737. /* System generated locals */
  738. index_type a_dim1, a_offset, b_dim1, b_offset, c_dim1, c_offset,
  739. i1, i2, i3, i4, i5, i6;
  740. /* Local variables */
  741. GFC_COMPLEX_17 f11, f12, f21, f22, f31, f32, f41, f42,
  742. f13, f14, f23, f24, f33, f34, f43, f44;
  743. index_type i, j, l, ii, jj, ll;
  744. index_type isec, jsec, lsec, uisec, ujsec, ulsec;
  745. GFC_COMPLEX_17 *t1;
  746. a = abase;
  747. b = bbase;
  748. c = retarray->base_addr;
  749. /* Parameter adjustments */
  750. c_dim1 = rystride;
  751. c_offset = 1 + c_dim1;
  752. c -= c_offset;
  753. a_dim1 = aystride;
  754. a_offset = 1 + a_dim1;
  755. a -= a_offset;
  756. b_dim1 = bystride;
  757. b_offset = 1 + b_dim1;
  758. b -= b_offset;
  759. /* Empty c first. */
  760. for (j=1; j<=n; j++)
  761. for (i=1; i<=m; i++)
  762. c[i + j * c_dim1] = (GFC_COMPLEX_17)0;
  763. /* Early exit if possible */
  764. if (m == 0 || n == 0 || k == 0)
  765. return;
  766. /* Adjust size of t1 to what is needed. */
  767. index_type t1_dim, a_sz;
  768. if (aystride == 1)
  769. a_sz = rystride;
  770. else
  771. a_sz = a_dim1;
  772. t1_dim = a_sz * 256 + b_dim1;
  773. if (t1_dim > 65536)
  774. t1_dim = 65536;
  775. t1 = malloc (t1_dim * sizeof(GFC_COMPLEX_17));
  776. /* Start turning the crank. */
  777. i1 = n;
  778. for (jj = 1; jj <= i1; jj += 512)
  779. {
  780. /* Computing MIN */
  781. i2 = 512;
  782. i3 = n - jj + 1;
  783. jsec = min(i2,i3);
  784. ujsec = jsec - jsec % 4;
  785. i2 = k;
  786. for (ll = 1; ll <= i2; ll += 256)
  787. {
  788. /* Computing MIN */
  789. i3 = 256;
  790. i4 = k - ll + 1;
  791. lsec = min(i3,i4);
  792. ulsec = lsec - lsec % 2;
  793. i3 = m;
  794. for (ii = 1; ii <= i3; ii += 256)
  795. {
  796. /* Computing MIN */
  797. i4 = 256;
  798. i5 = m - ii + 1;
  799. isec = min(i4,i5);
  800. uisec = isec - isec % 2;
  801. i4 = ll + ulsec - 1;
  802. for (l = ll; l <= i4; l += 2)
  803. {
  804. i5 = ii + uisec - 1;
  805. for (i = ii; i <= i5; i += 2)
  806. {
  807. t1[l - ll + 1 + ((i - ii + 1) << 8) - 257] =
  808. a[i + l * a_dim1];
  809. t1[l - ll + 2 + ((i - ii + 1) << 8) - 257] =
  810. a[i + (l + 1) * a_dim1];
  811. t1[l - ll + 1 + ((i - ii + 2) << 8) - 257] =
  812. a[i + 1 + l * a_dim1];
  813. t1[l - ll + 2 + ((i - ii + 2) << 8) - 257] =
  814. a[i + 1 + (l + 1) * a_dim1];
  815. }
  816. if (uisec < isec)
  817. {
  818. t1[l - ll + 1 + (isec << 8) - 257] =
  819. a[ii + isec - 1 + l * a_dim1];
  820. t1[l - ll + 2 + (isec << 8) - 257] =
  821. a[ii + isec - 1 + (l + 1) * a_dim1];
  822. }
  823. }
  824. if (ulsec < lsec)
  825. {
  826. i4 = ii + isec - 1;
  827. for (i = ii; i<= i4; ++i)
  828. {
  829. t1[lsec + ((i - ii + 1) << 8) - 257] =
  830. a[i + (ll + lsec - 1) * a_dim1];
  831. }
  832. }
  833. uisec = isec - isec % 4;
  834. i4 = jj + ujsec - 1;
  835. for (j = jj; j <= i4; j += 4)
  836. {
  837. i5 = ii + uisec - 1;
  838. for (i = ii; i <= i5; i += 4)
  839. {
  840. f11 = c[i + j * c_dim1];
  841. f21 = c[i + 1 + j * c_dim1];
  842. f12 = c[i + (j + 1) * c_dim1];
  843. f22 = c[i + 1 + (j + 1) * c_dim1];
  844. f13 = c[i + (j + 2) * c_dim1];
  845. f23 = c[i + 1 + (j + 2) * c_dim1];
  846. f14 = c[i + (j + 3) * c_dim1];
  847. f24 = c[i + 1 + (j + 3) * c_dim1];
  848. f31 = c[i + 2 + j * c_dim1];
  849. f41 = c[i + 3 + j * c_dim1];
  850. f32 = c[i + 2 + (j + 1) * c_dim1];
  851. f42 = c[i + 3 + (j + 1) * c_dim1];
  852. f33 = c[i + 2 + (j + 2) * c_dim1];
  853. f43 = c[i + 3 + (j + 2) * c_dim1];
  854. f34 = c[i + 2 + (j + 3) * c_dim1];
  855. f44 = c[i + 3 + (j + 3) * c_dim1];
  856. i6 = ll + lsec - 1;
  857. for (l = ll; l <= i6; ++l)
  858. {
  859. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  860. * b[l + j * b_dim1];
  861. f21 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  862. * b[l + j * b_dim1];
  863. f12 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  864. * b[l + (j + 1) * b_dim1];
  865. f22 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  866. * b[l + (j + 1) * b_dim1];
  867. f13 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  868. * b[l + (j + 2) * b_dim1];
  869. f23 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  870. * b[l + (j + 2) * b_dim1];
  871. f14 += t1[l - ll + 1 + ((i - ii + 1) << 8) - 257]
  872. * b[l + (j + 3) * b_dim1];
  873. f24 += t1[l - ll + 1 + ((i - ii + 2) << 8) - 257]
  874. * b[l + (j + 3) * b_dim1];
  875. f31 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  876. * b[l + j * b_dim1];
  877. f41 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  878. * b[l + j * b_dim1];
  879. f32 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  880. * b[l + (j + 1) * b_dim1];
  881. f42 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  882. * b[l + (j + 1) * b_dim1];
  883. f33 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  884. * b[l + (j + 2) * b_dim1];
  885. f43 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  886. * b[l + (j + 2) * b_dim1];
  887. f34 += t1[l - ll + 1 + ((i - ii + 3) << 8) - 257]
  888. * b[l + (j + 3) * b_dim1];
  889. f44 += t1[l - ll + 1 + ((i - ii + 4) << 8) - 257]
  890. * b[l + (j + 3) * b_dim1];
  891. }
  892. c[i + j * c_dim1] = f11;
  893. c[i + 1 + j * c_dim1] = f21;
  894. c[i + (j + 1) * c_dim1] = f12;
  895. c[i + 1 + (j + 1) * c_dim1] = f22;
  896. c[i + (j + 2) * c_dim1] = f13;
  897. c[i + 1 + (j + 2) * c_dim1] = f23;
  898. c[i + (j + 3) * c_dim1] = f14;
  899. c[i + 1 + (j + 3) * c_dim1] = f24;
  900. c[i + 2 + j * c_dim1] = f31;
  901. c[i + 3 + j * c_dim1] = f41;
  902. c[i + 2 + (j + 1) * c_dim1] = f32;
  903. c[i + 3 + (j + 1) * c_dim1] = f42;
  904. c[i + 2 + (j + 2) * c_dim1] = f33;
  905. c[i + 3 + (j + 2) * c_dim1] = f43;
  906. c[i + 2 + (j + 3) * c_dim1] = f34;
  907. c[i + 3 + (j + 3) * c_dim1] = f44;
  908. }
  909. if (uisec < isec)
  910. {
  911. i5 = ii + isec - 1;
  912. for (i = ii + uisec; i <= i5; ++i)
  913. {
  914. f11 = c[i + j * c_dim1];
  915. f12 = c[i + (j + 1) * c_dim1];
  916. f13 = c[i + (j + 2) * c_dim1];
  917. f14 = c[i + (j + 3) * c_dim1];
  918. i6 = ll + lsec - 1;
  919. for (l = ll; l <= i6; ++l)
  920. {
  921. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  922. 257] * b[l + j * b_dim1];
  923. f12 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  924. 257] * b[l + (j + 1) * b_dim1];
  925. f13 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  926. 257] * b[l + (j + 2) * b_dim1];
  927. f14 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  928. 257] * b[l + (j + 3) * b_dim1];
  929. }
  930. c[i + j * c_dim1] = f11;
  931. c[i + (j + 1) * c_dim1] = f12;
  932. c[i + (j + 2) * c_dim1] = f13;
  933. c[i + (j + 3) * c_dim1] = f14;
  934. }
  935. }
  936. }
  937. if (ujsec < jsec)
  938. {
  939. i4 = jj + jsec - 1;
  940. for (j = jj + ujsec; j <= i4; ++j)
  941. {
  942. i5 = ii + uisec - 1;
  943. for (i = ii; i <= i5; i += 4)
  944. {
  945. f11 = c[i + j * c_dim1];
  946. f21 = c[i + 1 + j * c_dim1];
  947. f31 = c[i + 2 + j * c_dim1];
  948. f41 = c[i + 3 + j * c_dim1];
  949. i6 = ll + lsec - 1;
  950. for (l = ll; l <= i6; ++l)
  951. {
  952. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  953. 257] * b[l + j * b_dim1];
  954. f21 += t1[l - ll + 1 + ((i - ii + 2) << 8) -
  955. 257] * b[l + j * b_dim1];
  956. f31 += t1[l - ll + 1 + ((i - ii + 3) << 8) -
  957. 257] * b[l + j * b_dim1];
  958. f41 += t1[l - ll + 1 + ((i - ii + 4) << 8) -
  959. 257] * b[l + j * b_dim1];
  960. }
  961. c[i + j * c_dim1] = f11;
  962. c[i + 1 + j * c_dim1] = f21;
  963. c[i + 2 + j * c_dim1] = f31;
  964. c[i + 3 + j * c_dim1] = f41;
  965. }
  966. i5 = ii + isec - 1;
  967. for (i = ii + uisec; i <= i5; ++i)
  968. {
  969. f11 = c[i + j * c_dim1];
  970. i6 = ll + lsec - 1;
  971. for (l = ll; l <= i6; ++l)
  972. {
  973. f11 += t1[l - ll + 1 + ((i - ii + 1) << 8) -
  974. 257] * b[l + j * b_dim1];
  975. }
  976. c[i + j * c_dim1] = f11;
  977. }
  978. }
  979. }
  980. }
  981. }
  982. }
  983. free(t1);
  984. return;
  985. }
  986. else if (rxstride == 1 && aystride == 1 && bxstride == 1)
  987. {
  988. if (GFC_DESCRIPTOR_RANK (a) != 1)
  989. {
  990. const GFC_COMPLEX_17 *restrict abase_x;
  991. const GFC_COMPLEX_17 *restrict bbase_y;
  992. GFC_COMPLEX_17 *restrict dest_y;
  993. GFC_COMPLEX_17 s;
  994. for (y = 0; y < ycount; y++)
  995. {
  996. bbase_y = &bbase[y*bystride];
  997. dest_y = &dest[y*rystride];
  998. for (x = 0; x < xcount; x++)
  999. {
  1000. abase_x = &abase[x*axstride];
  1001. s = (GFC_COMPLEX_17) 0;
  1002. for (n = 0; n < count; n++)
  1003. s += abase_x[n] * bbase_y[n];
  1004. dest_y[x] = s;
  1005. }
  1006. }
  1007. }
  1008. else
  1009. {
  1010. const GFC_COMPLEX_17 *restrict bbase_y;
  1011. GFC_COMPLEX_17 s;
  1012. for (y = 0; y < ycount; y++)
  1013. {
  1014. bbase_y = &bbase[y*bystride];
  1015. s = (GFC_COMPLEX_17) 0;
  1016. for (n = 0; n < count; n++)
  1017. s += abase[n*axstride] * bbase_y[n];
  1018. dest[y*rystride] = s;
  1019. }
  1020. }
  1021. }
  1022. else if (GFC_DESCRIPTOR_RANK (a) == 1)
  1023. {
  1024. const GFC_COMPLEX_17 *restrict bbase_y;
  1025. GFC_COMPLEX_17 s;
  1026. for (y = 0; y < ycount; y++)
  1027. {
  1028. bbase_y = &bbase[y*bystride];
  1029. s = (GFC_COMPLEX_17) 0;
  1030. for (n = 0; n < count; n++)
  1031. s += abase[n*axstride] * bbase_y[n*bxstride];
  1032. dest[y*rxstride] = s;
  1033. }
  1034. }
  1035. else if (axstride < aystride)
  1036. {
  1037. for (y = 0; y < ycount; y++)
  1038. for (x = 0; x < xcount; x++)
  1039. dest[x*rxstride + y*rystride] = (GFC_COMPLEX_17)0;
  1040. for (y = 0; y < ycount; y++)
  1041. for (n = 0; n < count; n++)
  1042. for (x = 0; x < xcount; x++)
  1043. /* dest[x,y] += a[x,n] * b[n,y] */
  1044. dest[x*rxstride + y*rystride] +=
  1045. abase[x*axstride + n*aystride] *
  1046. bbase[n*bxstride + y*bystride];
  1047. }
  1048. else
  1049. {
  1050. const GFC_COMPLEX_17 *restrict abase_x;
  1051. const GFC_COMPLEX_17 *restrict bbase_y;
  1052. GFC_COMPLEX_17 *restrict dest_y;
  1053. GFC_COMPLEX_17 s;
  1054. for (y = 0; y < ycount; y++)
  1055. {
  1056. bbase_y = &bbase[y*bystride];
  1057. dest_y = &dest[y*rystride];
  1058. for (x = 0; x < xcount; x++)
  1059. {
  1060. abase_x = &abase[x*axstride];
  1061. s = (GFC_COMPLEX_17) 0;
  1062. for (n = 0; n < count; n++)
  1063. s += abase_x[n*aystride] * bbase_y[n*bxstride];
  1064. dest_y[x*rxstride] = s;
  1065. }
  1066. }
  1067. }
  1068. }
  1069. #undef POW3
  1070. #undef min
  1071. #undef max
  1072. #endif
  1073. #endif