Пример #1
0
int KillSpecCases(int n, int *ix, int *iy, int *ia, int *ib, FILENODE **bp)
/*
 * Kills all special cases that are actually handled by general case
 */
{
   FILENODE *gp;
   int i, j;
   gp = FindGen(n, ix, iy, ia, ib, bp);
   if (gp == NULL)
   {
      fprintf(stderr, "NO GENERAL CASE SURVIVED!!  ABORTING!!\n");
      exit(-1);
   }
   for (i=0; i < n; i++)
   {
      if (bp[i] == gp)
      {
         if (ix[i] != 0 || iy[i] != 0 || ia[i] != AlphaX || ib[i] != AlphaX)
            bp[i] = NULL;
      }
   }
/*
 * eliminate entries that are NULL
 */
   for (j=i=0; i < n; i++)
   {
      if (bp[i] != NULL)
      {
         ix[j] = ix[i];
         iy[j] = iy[i];
         ia[j] = ia[i];
         ib[j] = ib[i];
         bp[j] = bp[i];
         j++;
      }
   }
   return(j);
}
Пример #2
0
void GenMainRout(char pre, int n, int *ix, int *iy, int *ia, int *ib,
                 FILENODE **bp)
{
   int i, j, NeedElse=0;
   FILENODE *gp;
   FILE *fpout;
   char *els="else if", *ifs ="if";
   char *spcs="                  ";
   char *spc = spcs+18;
   char ln[64];
   char *dargs="const int, const SCALAR, const TYPE*, const int, const SCALAR, TYPE*, const int";
   char *args="N, alpha, X, incx, beta, Y, incy";

   sprintf(ln, "GEN/ATL_%caxpby.c", pre);
   fpout = fopen(ln, "w");
   assert(fpout);
   fprintf(fpout, "#include \"atlas_misc.h\"\n\n");
   gp = FindGen(n, ix, iy, ia, ib, bp);
   assert(gp);
/*
 * prototype all routines
 */
   for (i=0; i < n; i++)
   {
      fprintf(fpout, "void %s\n   (%s);\n",
              GetNam(pre, ia[i], ib[i], ix[i], iy[i]), dargs);
   }

   fprintf(fpout, "void ATL_%caxpy(const int, const SCALAR, const TYPE*, const int, TYPE*, const int);\n", pre);
   fprintf(fpout, "void ATL_%ccpsc(const int, const SCALAR, const TYPE*, const int, TYPE*, const int);\n", pre);
   fprintf(fpout,
      "void ATL_%cscal(const int, const SCALAR, TYPE*, const int);\n", pre);
   if (pre == 'c' || pre == 'z')
      fprintf(fpout, "void Mjoin(PATLU,axpby)\n   (const int, const TYPE, const TYPE*, const int, const TYPE, TYPE*, const int);\n");

   fprintf(fpout, "\nvoid ATL_%caxpby(const int N, const SCALAR alpha, const TYPE *X, const int incX,\n", pre);
   fprintf(fpout,
      "               const SCALAR beta, TYPE *Y, const int incY)\n{\n");
   fprintf(fpout, "   int incx=incX, incy=incY;\n");
   if (pre == 'c' || pre == 'z')
      fprintf(fpout, "   const TYPE ralpha=(*alpha), ialpha=alpha[1], rbeta=(*beta), ibeta=beta[1];\n");
   fprintf(fpout, "\n   if (N > 0)\n   {\n");
   spc -= 6;
   MangleIncs(fpout, spc, pre);
   GenAlpBetCase(pre, spc, fpout, n, ix, iy, ia, ib);
/*
 * Handle general alpha & beta, specific incs
 */
   fprintf(fpout, "\n");
   for (i=0; i < n-1; i++)
   {
      if (ia[i] != AlphaX || ib[i] != AlphaX) continue;
      if (ix[i] && iy[i])
         fprintf(fpout, "%s%s (incx == %d && incy == %d)\n",
                 spc, ifs, ix[i], iy[i]);
      else if (iy[i]) fprintf(fpout, "%s%s (incy == %d)\n", spc, ifs, iy[i]);
      else if (ix[i]) fprintf(fpout, "%s%s (incx == %d)\n", spc, ifs, ix[i]);
      fprintf(fpout, "%s   %s(%s);\n", spc,
              GetNam(pre, ia[i], ib[i], ix[i], iy[i]), args);
      ifs = els;
      NeedElse = 1;
   }

   if (NeedElse)
   {
      fprintf(fpout, "%selse\n", spc);
      spc -= 3;
   }
   fprintf(fpout, "%s%s(%s);\n", spc,
           GetNam(pre, AlphaX, AlphaX, 0, 0), args);
   fprintf(fpout, "   }\n");
   fprintf(fpout, "}\n");
   fclose(fpout);
}
Пример #3
0
void GenMainRout(char pre, int n, int *ix, int *iy, int *ia, int *ib,
                 FILENODE **bp)
{
   int i, j, NeedElse=0;
   FILENODE *gp;
   FILE *fpout;
   char *els="else if", *ifs ="if";
   char *spcs="                  ";
   char *spc = spcs+18;
   char ln[64];
   char *dargs="const int, const TYPE*, const int";
   char *args="N, X, incx";

   sprintf(ln, "GEN/ATL_%casum.c", pre);
   fpout = fopen(ln, "w");
   assert(fpout);
   fprintf(fpout, "#include \"atlas_misc.h\"\n\n");
   gp = FindGen(n, ix, iy, ia, ib, bp);
   assert(gp);
/*
 * prototype all routines
 */
   for (i=0; i < n; i++)
   {
      fprintf(fpout, "TYPE %s(const int, const TYPE*, const int);\n",
              GetNam(pre, ia[i], ib[i], ix[i], iy[i]));
   }

   if (pre == 'c' || pre == 'z')
      fprintf(fpout,
              "TYPE Mjoin(PATLU,asum)(const int, const TYPE*, const int);\n");

   if (pre == 's' || pre == 'd') fprintf(fpout, "\nTYPE ATL_%casum", pre);
   else if (pre == 'c') fprintf(fpout, "\nTYPE ATL_scasum");
   else fprintf(fpout, "\nTYPE ATL_dzasum");
   fprintf(fpout, "(const int N, const TYPE *X, const int incX)\n{\n");
   fprintf(fpout, "   int incx;\n\n");
   fprintf(fpout, "   if (N > 0)\n   {\n");
   spc -= 6;
   MangleIncs(fpout, spc, pre);
   if (pre == 'c' || pre == 'z')
   {
      fprintf(fpout,
         "%sif (incx==1) return(Mjoin(PATLU,asum)(N<<1, X, 1));\n", spc);
   }
/*
 * Handle specific incX
 */
   for (i=0; i < n-1; i++)
   {
      fprintf(fpout, "%s%s (incx == %d)\n", spc, ifs, ix[i]);
      fprintf(fpout, "%s   return(%s(%s));\n", spc,
              GetNam(pre, ia[i], ib[i], ix[i], iy[i]), args);
      ifs = els;
      NeedElse = 1;
   }

   if (NeedElse)
   {
      fprintf(fpout, "%selse\n", spc);
      spc -= 3;
   }
   fprintf(fpout, "%sreturn(%s(N, X, incx));\n", spc,
           GetNam(pre, AlphaX, AlphaX, 0, 0));
   fprintf(fpout, "   }\n");
   fprintf(fpout, "   return(ATL_rzero);\n");
   fprintf(fpout, "}\n");
   fclose(fpout);
}
Пример #4
0
void GenMainRout(char pre, int n, int *ix, int *iy, int *ia, int *ib,
                 FILENODE **bp)
{
   int i, j, NeedElse=0;
   FILENODE *gp;
   FILE *fpout;
   char *els="else if", *ifs ="if";
   char *spcs="                  ";
   char *spc = spcs+18;
   char ln[64];
   char *dargs="const int, const TYPE*, const int, const TYPE*, const int";
   char *args="N, X, incx, Y, incy";
   char *cargs="N, X, incx, Y, incy, dotc";
   if (pre == 'c' || pre == 'z') args = cargs;

   sprintf(ln, "GEN/ATL_%cdot.c", pre);
   if (CONJ) sprintf(ln, "GEN/ATL_%cdotc.c", pre);
   fpout = fopen(ln, "w");
   assert(fpout);
   fprintf(fpout, "#include \"atlas_misc.h\"\n\n");
   gp = FindGen(n, ix, iy, ia, ib, bp);
   assert(gp);
/*
 * prototype all routines
 */
   for (i=0; i < n; i++)
   {
      if (pre == 'd' || pre == 's')
         fprintf(fpout, "TYPE %s\n   (%s);\n",
                 GetNam(pre, ia[i], ib[i], ix[i], iy[i]), dargs);
      else
         fprintf(fpout, "void %s\n   (%s, TYPE*);\n",
                 GetNam(pre, ia[i], ib[i], ix[i], iy[i]), dargs);
   }


   if (pre == 'c' || pre == 'z')
   {
      if (CONJ)
         fprintf(fpout,
"\nvoid ATL_%cdotc_sub(const int N, const TYPE *X, const int incX,\n", pre);
      else
         fprintf(fpout,
"\nvoid ATL_%cdotu_sub(const int N, const TYPE *X, const int incX,\n", pre);
      fprintf(fpout,
         "                   const TYPE *Y, const int incY, TYPE *dotc)\n{\n");
   }
   else
   {
      fprintf(fpout,
      "\nTYPE ATL_%cdot(const int N, const TYPE *X, const int incX,\n", pre);
      fprintf(fpout, "              const TYPE *Y, const int incY)\n{\n");
   }
   fprintf(fpout, "   int incx=incX, incy=incY;\n\n");
   fprintf(fpout, "   if (N > 0)\n   {\n");
   spc -= 6;
   MangleIncs(fpout, spc, pre);
/*
 * Handle general alpha & beta, specific incs
 */
   fprintf(fpout, "\n");
   for (i=0; i < n-1; i++)
   {
      if (ix[i] && iy[i])
         fprintf(fpout, "%s%s (incx == %d && incy == %d)\n",
                 spc, ifs, ix[i], iy[i]);
      else if (iy[i]) fprintf(fpout, "%s%s (incy == %d)\n", spc, ifs, iy[i]);
      else if (ix[i]) fprintf(fpout, "%s%s (incx == %d)\n", spc, ifs, ix[i]);
      if (pre == 'd' || pre == 's')
         fprintf(fpout, "%s   return(%s(%s));\n", spc,
                 GetNam(pre, ia[i], ib[i], ix[i], iy[i]), args);
      else
         fprintf(fpout, "%s   %s(%s);\n", spc,
                 GetNam(pre, ia[i], ib[i], ix[i], iy[i]), args);
      ifs = els;
      NeedElse = 1;
   }

   if (NeedElse)
   {
      fprintf(fpout, "%selse\n", spc);
      spc -= 3;
   }
   if (pre == 's' || pre == 'd')
      fprintf(fpout, "%sreturn(%s(%s));\n", spc,
              GetNam(pre, AlphaX, AlphaX, 0, 0), args);
   else
   fprintf(fpout, "%s%s(%s);\n", spc,
           GetNam(pre, AlphaX, AlphaX, 0, 0), args);
   fprintf(fpout, "   }\n");
   if (pre == 'd' || pre == 's') fprintf(fpout, "   else return(ATL_rzero);\n");
   else fprintf(fpout, "   else dotc[0] = dotc[1] = ATL_rzero;\n");
   fprintf(fpout, "}\n");
   fclose(fpout);
}