]> git.ipfire.org Git - thirdparty/gcc.git/blobdiff - libgfortran/generated/matmul_c8.c
Update copyright years.
[thirdparty/gcc.git] / libgfortran / generated / matmul_c8.c
index 7a73f67193866a32f0dcf2728369f93253a36365..e2b36ff549069b8532165c2d25700006a86bd182 100644 (file)
@@ -1,5 +1,5 @@
 /* Implementation of the MATMUL intrinsic
-   Copyright (C) 2002-2018 Free Software Foundation, Inc.
+   Copyright (C) 2002-2021 Free Software Foundation, Inc.
    Contributed by Paul Brook <paul@nowt.org>
 
 This file is part of the GNU Fortran runtime library (libgfortran).
@@ -144,8 +144,8 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -153,8 +153,8 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else
@@ -162,17 +162,15 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 1:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
 
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 2:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 2 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
     }
@@ -213,7 +211,9 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
   if (count != GFC_DESCRIPTOR_EXTENT(b,0))
     {
       if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
-       runtime_error ("dimension of array B incorrect in MATMUL intrinsic");
+       runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
+                      "in dimension 1: is %ld, should be %ld",
+                      (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
     }
 
   if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -258,7 +258,18 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
       if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
        {
          assert (gemm != NULL);
-         gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m,
+         const char *transa, *transb;
+         if (try_blas & 2)
+           transa = "C";
+         else
+           transa = axstride == 1 ? "N" : "T";
+
+         if (try_blas & 4)
+           transb = "C";
+         else
+           transb = bxstride == 1 ? "N" : "T";
+
+         gemm (transa, transb , &m,
                &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
                &ldc, 1, 1);
          return;
@@ -317,8 +328,13 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
        return;
 
       /* Adjust size of t1 to what is needed.  */
-      index_type t1_dim;
-      t1_dim = (a_dim1 - (ycount > 1)) * 256 + b_dim1;
+      index_type t1_dim, a_sz;
+      if (aystride == 1)
+        a_sz = rystride;
+      else
+        a_sz = a_dim1;
+
+      t1_dim = a_sz * 256 + b_dim1;
       if (t1_dim > 65536)
        t1_dim = 65536;
 
@@ -574,20 +590,6 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
            }
        }
     }
-  else if (axstride < aystride)
-    {
-      for (y = 0; y < ycount; y++)
-       for (x = 0; x < xcount; x++)
-         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
-
-      for (y = 0; y < ycount; y++)
-       for (n = 0; n < count; n++)
-         for (x = 0; x < xcount; x++)
-           /* dest[x,y] += a[x,n] * b[n,y] */
-           dest[x*rxstride + y*rystride] +=
-                                       abase[x*axstride + n*aystride] *
-                                       bbase[n*bxstride + y*bystride];
-    }
   else if (GFC_DESCRIPTOR_RANK (a) == 1)
     {
       const GFC_COMPLEX_8 *restrict bbase_y;
@@ -602,6 +604,20 @@ matmul_c8_avx (gfc_array_c8 * const restrict retarray,
          dest[y*rxstride] = s;
        }
     }
+  else if (axstride < aystride)
+    {
+      for (y = 0; y < ycount; y++)
+       for (x = 0; x < xcount; x++)
+         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
+
+      for (y = 0; y < ycount; y++)
+       for (n = 0; n < count; n++)
+         for (x = 0; x < xcount; x++)
+           /* dest[x,y] += a[x,n] * b[n,y] */
+           dest[x*rxstride + y*rystride] +=
+                                       abase[x*axstride + n*aystride] *
+                                       bbase[n*bxstride + y*bystride];
+    }
   else
     {
       const GFC_COMPLEX_8 *restrict abase_x;
@@ -696,8 +712,8 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -705,8 +721,8 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else
@@ -714,17 +730,15 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 1:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
 
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 2:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 2 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
     }
@@ -765,7 +779,9 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
   if (count != GFC_DESCRIPTOR_EXTENT(b,0))
     {
       if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
-       runtime_error ("dimension of array B incorrect in MATMUL intrinsic");
+       runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
+                      "in dimension 1: is %ld, should be %ld",
+                      (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
     }
 
   if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -810,7 +826,18 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
       if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
        {
          assert (gemm != NULL);
-         gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m,
+         const char *transa, *transb;
+         if (try_blas & 2)
+           transa = "C";
+         else
+           transa = axstride == 1 ? "N" : "T";
+
+         if (try_blas & 4)
+           transb = "C";
+         else
+           transb = bxstride == 1 ? "N" : "T";
+
+         gemm (transa, transb , &m,
                &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
                &ldc, 1, 1);
          return;
@@ -869,8 +896,13 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
        return;
 
       /* Adjust size of t1 to what is needed.  */
-      index_type t1_dim;
-      t1_dim = (a_dim1 - (ycount > 1)) * 256 + b_dim1;
+      index_type t1_dim, a_sz;
+      if (aystride == 1)
+        a_sz = rystride;
+      else
+        a_sz = a_dim1;
+
+      t1_dim = a_sz * 256 + b_dim1;
       if (t1_dim > 65536)
        t1_dim = 65536;
 
@@ -1126,20 +1158,6 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
            }
        }
     }
-  else if (axstride < aystride)
-    {
-      for (y = 0; y < ycount; y++)
-       for (x = 0; x < xcount; x++)
-         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
-
-      for (y = 0; y < ycount; y++)
-       for (n = 0; n < count; n++)
-         for (x = 0; x < xcount; x++)
-           /* dest[x,y] += a[x,n] * b[n,y] */
-           dest[x*rxstride + y*rystride] +=
-                                       abase[x*axstride + n*aystride] *
-                                       bbase[n*bxstride + y*bystride];
-    }
   else if (GFC_DESCRIPTOR_RANK (a) == 1)
     {
       const GFC_COMPLEX_8 *restrict bbase_y;
@@ -1154,6 +1172,20 @@ matmul_c8_avx2 (gfc_array_c8 * const restrict retarray,
          dest[y*rxstride] = s;
        }
     }
+  else if (axstride < aystride)
+    {
+      for (y = 0; y < ycount; y++)
+       for (x = 0; x < xcount; x++)
+         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
+
+      for (y = 0; y < ycount; y++)
+       for (n = 0; n < count; n++)
+         for (x = 0; x < xcount; x++)
+           /* dest[x,y] += a[x,n] * b[n,y] */
+           dest[x*rxstride + y*rystride] +=
+                                       abase[x*axstride + n*aystride] *
+                                       bbase[n*bxstride + y*bystride];
+    }
   else
     {
       const GFC_COMPLEX_8 *restrict abase_x;
@@ -1248,8 +1280,8 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -1257,8 +1289,8 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else
@@ -1266,17 +1298,15 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 1:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
 
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 2:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 2 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
     }
@@ -1317,7 +1347,9 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
   if (count != GFC_DESCRIPTOR_EXTENT(b,0))
     {
       if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
-       runtime_error ("dimension of array B incorrect in MATMUL intrinsic");
+       runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
+                      "in dimension 1: is %ld, should be %ld",
+                      (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
     }
 
   if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -1362,7 +1394,18 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
       if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
        {
          assert (gemm != NULL);
-         gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m,
+         const char *transa, *transb;
+         if (try_blas & 2)
+           transa = "C";
+         else
+           transa = axstride == 1 ? "N" : "T";
+
+         if (try_blas & 4)
+           transb = "C";
+         else
+           transb = bxstride == 1 ? "N" : "T";
+
+         gemm (transa, transb , &m,
                &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
                &ldc, 1, 1);
          return;
@@ -1421,8 +1464,13 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
        return;
 
       /* Adjust size of t1 to what is needed.  */
-      index_type t1_dim;
-      t1_dim = (a_dim1 - (ycount > 1)) * 256 + b_dim1;
+      index_type t1_dim, a_sz;
+      if (aystride == 1)
+        a_sz = rystride;
+      else
+        a_sz = a_dim1;
+
+      t1_dim = a_sz * 256 + b_dim1;
       if (t1_dim > 65536)
        t1_dim = 65536;
 
@@ -1678,20 +1726,6 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
            }
        }
     }
-  else if (axstride < aystride)
-    {
-      for (y = 0; y < ycount; y++)
-       for (x = 0; x < xcount; x++)
-         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
-
-      for (y = 0; y < ycount; y++)
-       for (n = 0; n < count; n++)
-         for (x = 0; x < xcount; x++)
-           /* dest[x,y] += a[x,n] * b[n,y] */
-           dest[x*rxstride + y*rystride] +=
-                                       abase[x*axstride + n*aystride] *
-                                       bbase[n*bxstride + y*bystride];
-    }
   else if (GFC_DESCRIPTOR_RANK (a) == 1)
     {
       const GFC_COMPLEX_8 *restrict bbase_y;
@@ -1706,6 +1740,20 @@ matmul_c8_avx512f (gfc_array_c8 * const restrict retarray,
          dest[y*rxstride] = s;
        }
     }
+  else if (axstride < aystride)
+    {
+      for (y = 0; y < ycount; y++)
+       for (x = 0; x < xcount; x++)
+         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
+
+      for (y = 0; y < ycount; y++)
+       for (n = 0; n < count; n++)
+         for (x = 0; x < xcount; x++)
+           /* dest[x,y] += a[x,n] * b[n,y] */
+           dest[x*rxstride + y*rystride] +=
+                                       abase[x*axstride + n*aystride] *
+                                       bbase[n*bxstride + y*bystride];
+    }
   else
     {
       const GFC_COMPLEX_8 *restrict abase_x;
@@ -1814,8 +1862,8 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -1823,8 +1871,8 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else
@@ -1832,17 +1880,15 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 1:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
 
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 2:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 2 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
     }
@@ -1883,7 +1929,9 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
   if (count != GFC_DESCRIPTOR_EXTENT(b,0))
     {
       if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
-       runtime_error ("dimension of array B incorrect in MATMUL intrinsic");
+       runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
+                      "in dimension 1: is %ld, should be %ld",
+                      (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
     }
 
   if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -1928,7 +1976,18 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
       if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
        {
          assert (gemm != NULL);
-         gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m,
+         const char *transa, *transb;
+         if (try_blas & 2)
+           transa = "C";
+         else
+           transa = axstride == 1 ? "N" : "T";
+
+         if (try_blas & 4)
+           transb = "C";
+         else
+           transb = bxstride == 1 ? "N" : "T";
+
+         gemm (transa, transb , &m,
                &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
                &ldc, 1, 1);
          return;
@@ -1987,8 +2046,13 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
        return;
 
       /* Adjust size of t1 to what is needed.  */
-      index_type t1_dim;
-      t1_dim = (a_dim1 - (ycount > 1)) * 256 + b_dim1;
+      index_type t1_dim, a_sz;
+      if (aystride == 1)
+        a_sz = rystride;
+      else
+        a_sz = a_dim1;
+
+      t1_dim = a_sz * 256 + b_dim1;
       if (t1_dim > 65536)
        t1_dim = 65536;
 
@@ -2244,20 +2308,6 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
            }
        }
     }
-  else if (axstride < aystride)
-    {
-      for (y = 0; y < ycount; y++)
-       for (x = 0; x < xcount; x++)
-         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
-
-      for (y = 0; y < ycount; y++)
-       for (n = 0; n < count; n++)
-         for (x = 0; x < xcount; x++)
-           /* dest[x,y] += a[x,n] * b[n,y] */
-           dest[x*rxstride + y*rystride] +=
-                                       abase[x*axstride + n*aystride] *
-                                       bbase[n*bxstride + y*bystride];
-    }
   else if (GFC_DESCRIPTOR_RANK (a) == 1)
     {
       const GFC_COMPLEX_8 *restrict bbase_y;
@@ -2272,6 +2322,20 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
          dest[y*rxstride] = s;
        }
     }
+  else if (axstride < aystride)
+    {
+      for (y = 0; y < ycount; y++)
+       for (x = 0; x < xcount; x++)
+         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
+
+      for (y = 0; y < ycount; y++)
+       for (n = 0; n < count; n++)
+         for (x = 0; x < xcount; x++)
+           /* dest[x,y] += a[x,n] * b[n,y] */
+           dest[x*rxstride + y*rystride] +=
+                                       abase[x*axstride + n*aystride] *
+                                       bbase[n*bxstride + y*bystride];
+    }
   else
     {
       const GFC_COMPLEX_8 *restrict abase_x;
@@ -2303,7 +2367,6 @@ matmul_c8_vanilla (gfc_array_c8 * const restrict retarray,
 
 /* Currently, this is i386 only.  Adjust for other architectures.  */
 
-#include <config/i386/cpuinfo.h>
 void matmul_c8 (gfc_array_c8 * const restrict retarray, 
        gfc_array_c8 * const restrict a, gfc_array_c8 * const restrict b, int try_blas,
        int blas_limit, blas_call gemm)
@@ -2320,11 +2383,11 @@ void matmul_c8 (gfc_array_c8 * const restrict retarray,
   if (matmul_fn == NULL)
     {
       matmul_fn = matmul_c8_vanilla;
-      if (__cpu_model.__cpu_vendor == VENDOR_INTEL)
+      if (__builtin_cpu_is ("intel"))
        {
           /* Run down the available processors in order of preference.  */
 #ifdef HAVE_AVX512F
-         if (__cpu_model.__cpu_features[0] & (1 << FEATURE_AVX512F))
+         if (__builtin_cpu_supports ("avx512f"))
            {
              matmul_fn = matmul_c8_avx512f;
              goto store;
@@ -2333,8 +2396,8 @@ void matmul_c8 (gfc_array_c8 * const restrict retarray,
 #endif  /* HAVE_AVX512F */
 
 #ifdef HAVE_AVX2
-         if ((__cpu_model.__cpu_features[0] & (1 << FEATURE_AVX2))
-            && (__cpu_model.__cpu_features[0] & (1 << FEATURE_FMA)))
+         if (__builtin_cpu_supports ("avx2")
+             && __builtin_cpu_supports ("fma"))
            {
              matmul_fn = matmul_c8_avx2;
              goto store;
@@ -2343,26 +2406,26 @@ void matmul_c8 (gfc_array_c8 * const restrict retarray,
 #endif
 
 #ifdef HAVE_AVX
-         if (__cpu_model.__cpu_features[0] & (1 << FEATURE_AVX))
+         if (__builtin_cpu_supports ("avx"))
            {
               matmul_fn = matmul_c8_avx;
              goto store;
            }
 #endif  /* HAVE_AVX */
         }
-    else if (__cpu_model.__cpu_vendor == VENDOR_AMD)
+    else if (__builtin_cpu_is ("amd"))
       {
 #if defined(HAVE_AVX) && defined(HAVE_FMA3) && defined(HAVE_AVX128)
-        if ((__cpu_model.__cpu_features[0] & (1 << FEATURE_AVX))
-           && (__cpu_model.__cpu_features[0] & (1 << FEATURE_FMA)))
+       if (__builtin_cpu_supports ("avx")
+           && __builtin_cpu_supports ("fma"))
          {
             matmul_fn = matmul_c8_avx128_fma3;
            goto store;
          }
 #endif
 #if defined(HAVE_AVX) && defined(HAVE_FMA4) && defined(HAVE_AVX128)
-        if ((__cpu_model.__cpu_features[0] & (1 << FEATURE_AVX))
-            && (__cpu_model.__cpu_features[0] & (1 << FEATURE_FMA4)))
+       if (__builtin_cpu_supports ("avx")
+           && __builtin_cpu_supports ("fma4"))
          {
             matmul_fn = matmul_c8_avx128_fma4;
            goto store;
@@ -2440,8 +2503,8 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -2449,8 +2512,8 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic: is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
       else
@@ -2458,17 +2521,15 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
          arg_extent = GFC_DESCRIPTOR_EXTENT(a,0);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,0);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 1:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 1 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
 
          arg_extent = GFC_DESCRIPTOR_EXTENT(b,1);
          ret_extent = GFC_DESCRIPTOR_EXTENT(retarray,1);
          if (arg_extent != ret_extent)
-           runtime_error ("Incorrect extent in return array in"
-                          " MATMUL intrinsic for dimension 2:"
-                          " is %ld, should be %ld",
+           runtime_error ("Array bound mismatch for dimension 2 of "
+                          "array (%ld/%ld) ",
                           (long int) ret_extent, (long int) arg_extent);
        }
     }
@@ -2509,7 +2570,9 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
   if (count != GFC_DESCRIPTOR_EXTENT(b,0))
     {
       if (count > 0 || GFC_DESCRIPTOR_EXTENT(b,0) > 0)
-       runtime_error ("dimension of array B incorrect in MATMUL intrinsic");
+       runtime_error ("Incorrect extent in argument B in MATMUL intrinsic "
+                      "in dimension 1: is %ld, should be %ld",
+                      (long int) GFC_DESCRIPTOR_EXTENT(b,0), (long int) count);
     }
 
   if (GFC_DESCRIPTOR_RANK (b) == 1)
@@ -2554,7 +2617,18 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
       if (lda > 0 && ldb > 0 && ldc > 0 && m > 1 && n > 1 && k > 1)
        {
          assert (gemm != NULL);
-         gemm (axstride == 1 ? "N" : "T", bxstride == 1 ? "N" : "T", &m,
+         const char *transa, *transb;
+         if (try_blas & 2)
+           transa = "C";
+         else
+           transa = axstride == 1 ? "N" : "T";
+
+         if (try_blas & 4)
+           transb = "C";
+         else
+           transb = bxstride == 1 ? "N" : "T";
+
+         gemm (transa, transb , &m,
                &n, &k, &one, abase, &lda, bbase, &ldb, &zero, dest,
                &ldc, 1, 1);
          return;
@@ -2613,8 +2687,13 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
        return;
 
       /* Adjust size of t1 to what is needed.  */
-      index_type t1_dim;
-      t1_dim = (a_dim1 - (ycount > 1)) * 256 + b_dim1;
+      index_type t1_dim, a_sz;
+      if (aystride == 1)
+        a_sz = rystride;
+      else
+        a_sz = a_dim1;
+
+      t1_dim = a_sz * 256 + b_dim1;
       if (t1_dim > 65536)
        t1_dim = 65536;
 
@@ -2870,20 +2949,6 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
            }
        }
     }
-  else if (axstride < aystride)
-    {
-      for (y = 0; y < ycount; y++)
-       for (x = 0; x < xcount; x++)
-         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
-
-      for (y = 0; y < ycount; y++)
-       for (n = 0; n < count; n++)
-         for (x = 0; x < xcount; x++)
-           /* dest[x,y] += a[x,n] * b[n,y] */
-           dest[x*rxstride + y*rystride] +=
-                                       abase[x*axstride + n*aystride] *
-                                       bbase[n*bxstride + y*bystride];
-    }
   else if (GFC_DESCRIPTOR_RANK (a) == 1)
     {
       const GFC_COMPLEX_8 *restrict bbase_y;
@@ -2898,6 +2963,20 @@ matmul_c8 (gfc_array_c8 * const restrict retarray,
          dest[y*rxstride] = s;
        }
     }
+  else if (axstride < aystride)
+    {
+      for (y = 0; y < ycount; y++)
+       for (x = 0; x < xcount; x++)
+         dest[x*rxstride + y*rystride] = (GFC_COMPLEX_8)0;
+
+      for (y = 0; y < ycount; y++)
+       for (n = 0; n < count; n++)
+         for (x = 0; x < xcount; x++)
+           /* dest[x,y] += a[x,n] * b[n,y] */
+           dest[x*rxstride + y*rystride] +=
+                                       abase[x*axstride + n*aystride] *
+                                       bbase[n*bxstride + y*bystride];
+    }
   else
     {
       const GFC_COMPLEX_8 *restrict abase_x;