Beispiel #1
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num, nret;
    int64_t *A, *B;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    if (num > SZ) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    A = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));

    srandom (99);

    for (i=0; i<SZ; i++) {
        A[2*i] = random () & 0xffff;
        A[2*i+1] = A[2*i] + 100000;
	}

    map_allocate (1);

    // call the MAP routine
    subr (A, B, num, &nret, &tm, mapnum);

    printf ("combined DMA and compute time: %lld clocks\n", tm);

    for (i=0; i<nret; i++)
        fprintf (res_map, "%lld\n", B[i]);

    for (i=0; i<num; i++)
	if (A[i] > 30000)
            fprintf (res_cpu, "%lld\n", A[i]*17);

    map_free (1);

    exit(0);
    }
Beispiel #2
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num;
    int64_t *A0, *A1, *B;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if ((num < 1) || (num > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
	exit (1);
	}

    A0 = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
    A1 = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));

    srandom (99);

    for (i=0; i<num; i++) {
        A0[i] = random ();
        A1[i] = random ();
	}

    map_allocate (1);

    subr (A0, A1, B, num, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<num; i++) {
        fprintf (res_map, "%lld\n", B[i]);
        fprintf (res_cpu, "%lld\n", A0[i]+A1[i]);
	}

    map_free (1);

    exit(0);
    }
Beispiel #3
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num;
    double *D_src, res, acc;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map.flt", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map.flt'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu.flt", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu.flt'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if ((num < 1) || (num > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
	exit (1);
	}

    D_src = (double*) malloc (num * sizeof (double));

    srandom (99);

    acc = 0.0;

    for (i=0; i<num; i++) {
        D_src[i] = (double)random() / random();
	acc += D_src[i];
	}

    fprintf (res_cpu, "%lf\n", acc);

    map_allocate (1);

    subr (D_src, &res, num, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    fprintf (res_map, "%lf\n", res);

    map_free (1);

    exit(0);
    }
Beispiel #4
0
struct lispobj *apply(struct lispobj *proc, struct lispobj *args)
{    
    if(proc != NULL && OBJ_TYPE(proc) == CONS) {
        struct lispobj *ret;
        
        if(NEW_SYMBOL("SUBR") == CAR(proc)) {
            /* Apply primitive function. */
            struct lispobj *body, *(*subr)(struct lispobj *);

            body = CADR(proc);
            subr = (struct lispobj *) NUMBER_VALUE(body);
            //subr = (struct lispobj *) body;

            ret = heap_grab(subr(args));
        } else if(NEW_SYMBOL("PROC") == CAR(proc)) {
            /* Apply user defined procedure. */
            struct lispobj *body, *params, *penv;

            body = CADDR(proc);
            params = CADR(proc);
            penv = CADDDR(proc);
            
            if(length(params) == length(args)) {
                struct lispobj *env;

                if(params == NULL || params == NEW_SYMBOL("NIL")) {
                    env = penv;

                    ret = eval_progn(body, env);
                } else {
                    env = heap_grab(NEW_CONS(env_frame_make(params, args), penv));

                    ret = eval_progn(body, env);
                    heap_release(env);
                }
            } else {
                char error[64]; 
                snprintf(error,
                         64,
                         "Has recieved wrong number of parameters: %d.\n",
                         length(args));
                ret = heap_grab(NEW_ERROR(error));
            }
        } else {
            goto error;
        }

        return ret;
    }
    
    error:
    return heap_grab(NEW_ERROR("Unknown procedure.\n"));
}
Beispiel #5
0
int
main()
{
  subr (1);
  end (1);

  subr (2);
  end (2);

  subr (3);
  end (3);

  subr (4);
  end (4);

  subr (5);
  subr2 (5);
  end (5);

  subr (6);
  subr2 (6);
  end (6);

  return 0;
}
Beispiel #6
0
main()
{
  int k;

  creat(tempfile, 0777);
  printf("Test  4 ");
  fflush(stdout);		/* have to flush for child's benefit */

  for (k = 0; k < 20; k++) {
	subr();
  }
  printf("ok\n");
  unlink(tempfile);
}
Beispiel #7
0
int main()
{
  int k;

  printf("Test  4 ");
  fflush(stdout);		/* have to flush for child's benefit */

  system("rm -rf DIR_04; mkdir DIR_04");
  chdir("DIR_04");

  creat(tempfile, 0777);
  for (k = 0; k < 20; k++) {
	subr();
  }
  unlink(tempfile);
  quit();
  return(-1);			/* impossible */
}
Beispiel #8
0
// Gets start and end points in dictionary for a certain wordlength
// Gets a pointer to a new dictionary with only the specified wordlength
// Creates new int64_t* array containing ciphertext for subroutine
// Decrypts using map, which returns the decryption key
// Prints the key and the plaintext
// Frees all malloc'd resources created in block
int64_t* executeSubroutine(char** words, char* ciphertextchars, int ciphertextlength, int wordlength, int keylength, int64_t* tm, int mapnum){
    int start=0, end=0, wordcount=0, i=0;
    
    // Get a new short dictionary
    int64_t** wordlengthOnly = getShortDictionary(words, wordlength);
    
    int64_t* foundkey = Cache_Aligned_Allocate(keylength * sizeof(int64_t));

    start = getStart(words, wordlength);
    end = getEnd(words, wordlength);
    wordcount = end - start + 1;   
    int64_t* ciphertext = malloc(sizeof(int64_t) * (ciphertextlength+1)); // Extra for null char
    for(i = 0; i < ciphertextlength; i++){
        ciphertext[i] = (int64_t)ciphertextchars[i];
    }

    // Decrypt on MAP
    subr (&wordlengthOnly[0][0], ciphertext, ciphertextlength, foundkey, wordcount, wordlength, keylength, &tm, mapnum);
 
    char *key = malloc(sizeof(char) * (keylength+1));
    key[keylength] = '\0';

    printf("MAP subroutine found key '");
    for(i = 0; i < keylength; i++){
        printf("%c", (char)(foundkey[i]) );
        key[i] = (char)foundkey[i];
    } 
    printf("' and plaintext %s \n", decrypt( ciphertextchars, ciphertextlength, key, keylength ));
 
    printf ("MAP completed in %lld clocks.\n", tm);

    free(foundkey);
    freeShortDictionary(wordlengthOnly, wordcount);
    free(ciphertext);
    free(key);
    return tm;
}
Beispiel #9
0
int main (int argc, char *argv[]) {
    int64_t time;

    if (argc < 2) {
        fprintf (stderr, "need image file source as arg\n");
	exit (1);
	}

    map_allocate (1);

    read_image (argv[1]);

    subr (A, B, SN, SM, SZ/8, &time, 0);

    printf ("%lld clocks\n", time);

    dump_image (B, "res_map.pgm");

    map_free (1);

    cpu_compute ("res_cpu.pgm");

    exit (0);
    }
Beispiel #10
0
main()
{
  subr (1);
  end (1);

  subr (2);
  end (2);

  subr (3);
  end (3);

  subr (4);
  end (4);

  subr (5);
  subr2 (5);
  end (5);

  subr (6);
  subr2 (6);
  end (6);
}
Beispiel #11
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i,j,ix, msize;
    double *D_src, *D_sum, res, acc;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need msizeber of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &msize) < 1) {
	fprintf (stderr, "need msizeber of elements as arg\n");
	exit (1);
	}

    if ((msize < 1) || (msize > 724)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", 724);
	exit (1);
	}

    D_src = (double*) malloc (msize*msize * sizeof (double));
    D_sum = (double*) malloc (msize * sizeof (double));

    srandom (99);


    for (j=0; j<msize; j++) {
       acc = 0.0;
       for (i=j; i<msize; i++) {
           ix = i + j*msize;
           D_src[ix] = (double)random() / random();
	       acc += D_src[ix];
	       }
       fprintf (res_cpu, "%lf\n", acc);
    }
     


    map_allocate (1);

    subr (D_src, D_sum, msize, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<msize; i++) fprintf (res_map, "%lf\n", D_sum[i]);

    map_free (1);

    exit(0);
    }
Beispiel #12
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i,n, maxlen,nvec;
    int64_t *A, *B, *Out;
    int32_t *Counts;
    int64_t tm,i64;
    int cnt,cnta,cntb,j;
    int total_nsampA, ijA;
    int total_nsampB, ijB;
    int total_nsamp;
    int nspin;
    int nout;
    int mapnum = 0;
    int64_t temp;
    int iput;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    nspin = 1;

    if (argc < 2) {
	fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS);
	exit (1);
	}

    if (sscanf (argv[1], "%d", &nvec) < 1) {
	fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS);
	exit (1);
	}

    if (nvec > MAXVECS) {
	fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS);
	exit (1);
	}

    if (argc < 3) {
	fprintf (stderr, "need max vector length (up to %d) as arg\n", MAXVEC_LEN);
	exit (1);
	}

    if (sscanf (argv[2], "%d", &maxlen) < 1) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN);
	exit (1);
	}

    if (maxlen > MAXVEC_LEN) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN);
	exit (1);
	}

    if (argc > 3) {
       if (sscanf (argv[3], "%d", &nspin) < 1) {
      	fprintf (stderr, "need clocks to spin before Buffer A starts in MAP) as arg\n");
	   exit (1);
       }
    }

    Counts = (int32_t*) malloc (nvec * sizeof (int64_t));

 printf ("Number vectors                     %4i\n",nvec);
 printf ("Maximum vector length              %4i\n",maxlen);
 printf ("Number of clocks to delay Buffer A %4i\n",nspin);
    
    srandom (973);

    total_nsampA = 0;
    total_nsampB = 0;
    for (i=0; i<nvec; i++) {
        cnta = random () % maxlen;
        cntb = random () % maxlen;
        if (cnta==0) cnta = 1;
        if (cntb==0) cntb = 1;
        Counts[2*i]   = cnta;
        Counts[2*i+1] = cntb;
        
  printf ("Line %2i Buffer A Samples %4i Buffer B Samples %4i\n",i,Counts[2*i],Counts[2*i+1]);
        total_nsampA = total_nsampA + cnta;
        total_nsampB = total_nsampB + cntb;
	}

    A      = (int64_t*) malloc (total_nsampA * sizeof (int64_t));
    B      = (int64_t*) malloc (total_nsampB * sizeof (int64_t));


    total_nsamp = total_nsampA + total_nsampB;
 printf ("total sampA %i\n",total_nsampA);
 printf ("total sampB %i\n",total_nsampB);
 printf ("total samp %i\n",total_nsamp);
    Out    = (int64_t*) malloc (total_nsamp * sizeof (int64_t));

    ijA = 0;
    ijB = 0;
    for (i=0;i<nvec;i++) {
      cnt = Counts[2*i];
      n = i+1;

      for (j=0;j<cnt;j++) {
//         i64 = random () % maxlen;
         i64 = j;
         A[ijA] = i64;
         ijA++;

         fprintf (res_cpu, "%10lld\n", i64 + n*10000);
      }

      cnt = Counts[2*i+1];
      n = i+1000+1;

      for (j=0;j<cnt;j++) {
//         i64 = random () % maxlen;
         i64 = j;
         B[ijB] = i64;
         ijB++;

         fprintf (res_cpu, "%10lld\n", i64 + n*1000000);
      }
    }

    map_allocate (1);

    // call the MAP routine
    subr (A, B, Out,  Counts, nvec, nspin, &nout, &tm, mapnum);

    printf ("compute on MAP: %10lld clocks\n", tm);

    for (i=0; i<nout; i++) {
        fprintf (res_map, "%10lld\n", Out[i]);
	}

    map_free (1);

    exit(0);
    }
Beispiel #13
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, maxlen,nvec;
    int64_t *A, *B, *C, *D;
    int16_t *Counts;
    int64_t tm,i64;
    int total_nsamp,ij,cnt,j,jj;
    int mapnum = 0;
    int64_t temp;
    int Indx[MAXVECS];
    int tcnt,hash_indx;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS);
	exit (1);
	}

    if (sscanf (argv[1], "%d", &nvec) < 1) {
	fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS);
	exit (1);
	}

    if (nvec > MAXVECS) {
	fprintf (stderr, "need number of vectors (up to %d) as arg\n", MAXVECS);
	exit (1);
	}

    if (argc < 3) {
	fprintf (stderr, "need max vector length (up to %d) as arg\n", MAXVEC_LEN);
	exit (1);
	}

    if (sscanf (argv[2], "%d", &maxlen) < 1) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN);
	exit (1);
	}

    if (maxlen > MAXVEC_LEN) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", MAXVEC_LEN);
	exit (1);
	}

    Counts = (int16_t*) malloc (4*nvec * sizeof (int16_t));

 if (maxlen%4 != 0) maxlen = 4*((maxlen+3)/4);

 printf ("Number vectors        %4i\n",nvec);
 printf ("Maximum vector length %4i\n",maxlen);
    
    srandom (99);

    total_nsamp = 0;
    for (i=0; i<nvec; i++) {
        tcnt      = random () % maxlen;
        hash_indx = random () % 16384;
        tcnt      = ((tcnt+3)/4)*4;
        if (tcnt==0) tcnt = 4;

        Counts[4*i]   = tcnt;
        Counts[4*i+1] = hash_indx;
        Counts[4*i+2] = i;
  printf ("Line %2i Samples %4i Hash_Indx %i\n",i,tcnt,hash_indx);

        total_nsamp = total_nsamp + tcnt;
	}
 printf ("total_samp %i %x\n",total_nsamp,total_nsamp);

    A      = (int64_t*) malloc (total_nsamp * sizeof (int64_t));
    B      = (int64_t*) malloc (total_nsamp * sizeof (int64_t));
    C      = (int64_t*) malloc (total_nsamp * sizeof (int64_t));
    D      = (int64_t*) malloc (total_nsamp * sizeof (int64_t));

    ij = 0;
    for (i=0;i<nvec;i++) {
      cnt = Counts[4*i];
      Indx[i] = ij;

      for (j=0;j<cnt;j++) {
         //i64 = random () % maxlen;
         //A[ij] = i64;
         A[ij] = j + i*0x1000;
         C[ij] = j + i*0x100000 + i*0x1000;
         ij++;
 
      }
    }

    jj = 0;
    for (i=nvec-1;i>=0;i--) {
      cnt = Counts[4*i];
      ij = Indx[i];

 printf ("cpu ij %i cnt %i\n",ij,cnt);

      for (j=0;j<cnt;j++) {
         i64 = C[ij+j];
         D[jj] = i64;
         fprintf (res_cpu, "%016llx\n", i64);
         jj++;
      }
    }

    map_allocate (1);

    // call the MAP routine

printf ("b4 map call\n");
    subr (A, B, Counts, nvec, total_nsamp, maxlen, &tm, mapnum);

    printf ("compute on MAP: %10lld clocks\n", tm);


    for (i=0; i<total_nsamp; i++) {
    printf ("cpu %016llx  map %016llx\n", D[i],B[i]);
        fprintf (res_map, "%016llx\n", B[i]);
	}

    map_free (1);

    exit(0);
    }
Beispiel #14
0
void KatePluginSymbolViewerView::parseFortranSymbols(void)
{
 if (!mainWindow()->activeView())
   return;

 QString currline;
 QString subrStr("subroutine ");
 QString funcStr("function ");
 QString modStr("module ");

 QString stripped="";
 int i;
 int fnd,block=0,blockend=0,paro=0,parc=0;
 bool mainprog;

 QTreeWidgetItem *node = NULL;
 QTreeWidgetItem *subrNode = NULL, *funcNode = NULL, *modNode = NULL;
 QTreeWidgetItem *lastSubrNode = NULL, *lastFuncNode = NULL, *lastModNode = NULL;

 QPixmap func( ( const char** ) class_xpm );
 QPixmap subr( ( const char** ) macro_xpm );
 QPixmap mod( ( const char** ) struct_xpm );

 //It is necessary to change names
 m_macro->setText(i18n("Show Subroutines"));
 m_struct->setText(i18n("Show Modules"));
 m_func->setText(i18n("Show Functions"));

 if(m_plugin->treeOn)
  {
   funcNode = new QTreeWidgetItem(m_symbols, QStringList(i18n("Functions") ) );
   subrNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Subroutines") ) );
   modNode = new QTreeWidgetItem(m_symbols, QStringList( i18n("Modules") ) );
   funcNode->setIcon(0, QIcon(func));
   modNode->setIcon(0, QIcon(mod));
   subrNode->setIcon(0, QIcon(subr));

   if (m_plugin->expandedOn)
      {
       m_symbols->expandItem(funcNode);
       m_symbols->expandItem(subrNode);
       m_symbols->expandItem(modNode);
      }

   lastSubrNode = subrNode;
   lastFuncNode = funcNode;
   lastModNode = modNode;
   m_symbols->setRootIsDecorated(1);
  }
 else
   m_symbols->setRootIsDecorated(0);

 KTextEditor::Document *kDoc = mainWindow()->activeView()->document();

 for (i = 0; i < kDoc->lines(); i++)
   {
    currline = kDoc->line(i);
    currline = currline.trimmed();
    //currline = currline.simplified(); is this really needed ?
    //Fortran is case insensitive
    currline = currline.toLower();
    bool comment = false;
    //kdDebug(13000)<<currline<<endl;
    if(currline == "") continue;
    if(currline.at(0) == '!' || currline.at(0) == 'c') comment = true;
    //block=0;

    mainprog=false;

    if(!comment)
      {
       //Subroutines
       if(currline.startsWith(subrStr) || currline.startsWith("program "))
         {
          block=1;
          stripped="";
         }
       //Modules
        else if(currline.startsWith(modStr))
         {
          block=2;
          stripped="";
         }
       //Functions
        else if(((( currline.startsWith("real") || 
                    currline.startsWith("double") || 
                    currline.startsWith("integer") || 
                    currline.startsWith("character")) || 
                    currline.startsWith("logical") || 
                    currline.startsWith("pure") ||
                    currline.startsWith("elemental") ||
                    currline.startsWith("recursive") ||
                    currline.startsWith("type")) &&   
                    currline.indexOf(funcStr) > 0) || 
                    currline.startsWith(funcStr)                    
                )
         {
          block=3;
          stripped="";
         }

       //Subroutines
       if(block==1)
         {
          if(currline.startsWith("program "))
               mainprog=true;
          if (macro_on == true) // not really a macro, but a subroutines
            {
             stripped += currline.right(currline.length());
             stripped = stripped.simplified();
             stripped.remove('*');
             stripped.remove('+');
             stripped.remove('$');
             if(blockend==0)
               {
                fnd = stripped.indexOf(' ');
                stripped = currline.right(currline.length()-fnd-1);
               }
             stripped.remove(' ');
             fnd = stripped.indexOf('!');
             if(fnd>0)
               {
                stripped = stripped.left(fnd);
               }
             paro+=currline.count(')', Qt::CaseSensitive);
             parc+=currline.count('(', Qt::CaseSensitive);

             if((paro==parc || mainprog) && stripped.endsWith('&', Qt::CaseInsensitive)==false)
               {
                stripped.remove('&');
                if(mainprog && stripped.indexOf('(')<0 && stripped.indexOf(')')<0)
                    stripped.prepend("Main: ");
                if(stripped.indexOf('=')==-1)
                  {
                   if (m_plugin->treeOn)
                     {
                      node = new QTreeWidgetItem(subrNode, lastSubrNode);
                      lastSubrNode = node;
                     }
                   else
                      node = new QTreeWidgetItem(m_symbols);
                   node->setText(0, stripped);
                   node->setIcon(0, QIcon(subr));
                   node->setText(1, QString::number( i, 10));
                  }
                stripped="";
                block=0;
                blockend=0;
                paro=0;
                parc=0;
               }
             else
               {
                blockend=1;
               }
            }
        }

       //Modules
       else if(block==2)
        {
         if (struct_on == true) // not really a struct, but a module
           {
            stripped = currline.right(currline.length());
            stripped = stripped.simplified();
            fnd = stripped.indexOf(' ');
            stripped = currline.right(currline.length()-fnd-1);
            fnd = stripped.indexOf('!');
            if(fnd>0)
              {
               stripped = stripped.left(fnd);
              }
            if(stripped.indexOf('=')==-1)
              {
               if (m_plugin->treeOn)
                 {
                  node = new QTreeWidgetItem(modNode, lastModNode);
                  lastModNode = node;
                 }
               else
                  node = new QTreeWidgetItem(m_symbols);
               node->setText(0, stripped);
               node->setIcon(0, QIcon(mod));
               node->setText(1, QString::number( i, 10));
              }
            stripped = "";
           }
          block=0;
          blockend=0;
        }

      //Functions
      else if(block==3)
        {
         if (func_on == true)
           {
            stripped += currline.right(currline.length());
            stripped = stripped.trimmed();
            stripped.remove( "function" );
            stripped.remove('*');
            stripped.remove('+');
            stripped.remove('$');
            stripped = stripped.simplified();
            fnd = stripped.indexOf('!');
            if(fnd>0)
              {
               stripped = stripped.left(fnd);
              }
            stripped = stripped.trimmed();
            paro+=currline.count(')', Qt::CaseSensitive);
            parc+=currline.count('(', Qt::CaseSensitive);

            if(paro==parc && stripped.endsWith('&')==false)
              {
               stripped.remove('&');
              if (m_plugin->treeOn)
                {
                 node = new QTreeWidgetItem(funcNode, lastFuncNode);
                 lastFuncNode = node;
                }
              else
                 node = new QTreeWidgetItem(m_symbols);
              node->setText(0, stripped);
              node->setIcon(0, QIcon(func));
              node->setText(1, QString::number( i, 10));
              stripped = "";
              block=0;
              paro=0;
              parc=0;
             }
           blockend=0;
          }
        }
      }
    } //for i loop
}
Beispiel #15
0
int
main ()
{
  subr (1);
  end ();
}
Beispiel #16
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num0, num1;
    int64_t *A, *B, *C, *D, *Out1, *Out2;
    int64_t tm;
    int mapnum = 0;

 int64_t i64;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 3) {
	fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ);
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num0) < 1) {
	fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ);
	exit (1);
	}

    if (sscanf (argv[2], "%d", &num1) < 1) {
	fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ);
	exit (1);
	}

    if ((num0 > SZ) || (num1 > SZ)) {
	fprintf (stderr, "need two elements counts (each up to %d) as args\n", SZ);
	exit (1);
	}

    A    = (int64_t*) malloc (num0 * sizeof (int64_t));
    B    = (int64_t*) malloc (num0 * sizeof (int64_t));
    C    = (int64_t*) malloc (num1 * sizeof (int64_t));
    D    = (int64_t*) malloc (num1 * sizeof (int64_t));
    Out1 = (int64_t*) malloc (num0 * sizeof (int64_t));
    Out2 = (int64_t*) malloc (num1 * sizeof (int64_t));

    srandom (99);

    for (i=0; i<num0; i++) {
        A[i] = random ();
        B[i] = random ();
	}

    for (i=0; i<num1; i++) {
        C[i] = random ();
        D[i] = random ();
	}

    map_allocate (1);

    // call the MAP routine
    subr (A, B, C, D, Out1, Out2, num0, num1, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<num0; i++) {
        fprintf (res_map, "%lld\n", Out1[i]);
        fprintf (res_cpu, "%lld\n", A[i]+B[i]);
	}

    for (i=0; i<num1; i++) {
        fprintf (res_map, "%lld\n", Out2[i]);
        fprintf (res_cpu, "%lld\n", C[i]*D[i]);
	}

    map_free (1);

    exit(0);
    }
Beispiel #17
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num;
    int64_t *A, *B, *C;
    int64_t tm0, tm1, tm2;
    int mapnum = 0;
    int snapmem = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if ((num < 1) || (num > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through "
                 "%d\n", MAX_OBM_SIZE);
	exit (1);
	}

    if (argc ==  3) {
      sscanf (argv[2], "%d", &snapmem);
      printf ("snapmem %i\n",snapmem);
   }
        

       A = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
       B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
       C = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));

    memset (A, 0, num * sizeof (int64_t));
    memset (B, 0, num * sizeof (int64_t));
    memset (C, 0, num * sizeof (int64_t));

    srandom (99);

    for (i=0; i<num; i++) {
        A[i] = random ();
        B[i] = random ();
	}

    map_allocate (1);

    subr (A, B, C, num, &tm0, &tm1, &tm2, mapnum);

    printf ("DMA to MAP: %8lld clocks\n", tm0);
    printf ("compute:    %8lld clocks\n", tm1);
    printf ("DMA to CPU: %8lld clocks\n", tm2);

    for (i=0; i<num; i++) {
	int64_t v;

        fprintf (res_map, "%lld\n", C[i]);

        v = A[i] + B[i];
        if (A[i] > B[i])
            v = v + 42;
        fprintf (res_cpu, "%lld\n", v*3);
	}

    map_free (1);

    exit(0);
    }
Beispiel #18
0
int main (int argc, char *argv[]) {
    int i = 0;
    int j = 0;
    int64_t* time;

    if (argc < 2) {
        fprintf (stderr, "need image file source as arg\n");
        exit (1);
    }

    /*** Insert Your Code Here ***/

    read_image( argv[1] );

    int64_t *a;
    A = (int*) Cache_Aligned_Allocate(n_bytes * sizeof(int));
    B = (int*) Cache_Aligned_Allocate(n_bytes * sizeof(int));

    // Move image from 2d array into 1d int array (easier to pass to map)
    int index = 0;
    for(i = 0; i < n_rows; i++){
        for(j = 0; j < n_cols; j++){
            A[index] = image[i][j];
            index++;
        }
    }

    // prints 289722, which is n_cols*n_rows, and all the values of A, which shows it storing correctly
    /*
       int count = 0;
       for(i = 0; i < n_bytes; i++){
       count++;
       printf("%d\n ", A[i]);
       }
       printf("%d\n", count);
       */

    status = map_allocate(nmaps);
    if(status != 0  ){
        fprintf (stderr, "Could not allocate nmaps\n");
        exit(2);
    }


    int mapnum = nmaps - 1;

    printf("Calling map subroutine.\n");
    subr(A, B, n_rows, n_cols, n_bytes, &time, mapnum);
    printf("Completed map subroutine.\n");

    // Producing the wrong output for some reason. Lot of 0's.
    /*
    int count = 0;
    for(i = 0; i < n_bytes; i++){
        count++;
        printf("%d\n ", B[i]);
    }
    printf("%d\n", count);
    */


    // Move from 1d array (B) back to 2d array so it can be printed to file
    index = 0;
    for(i = 0; i < n_rows; i++){
        for(j = 0; j < n_cols; j++){
            image[i][j] = B[index];
            index++;
        }
    }

    map_free(nmaps);

    /*****************************/

    //printf ("%lld clocks\n", &time);
    printf ("%lld clocks\n", time);

    write_image( 0, "output.pgm" );

    exit (0);
}
Beispiel #19
0
SCM
scm_apply_subr (union scm_vm_stack_element *sp, scm_t_ptrdiff nslots)
{
  SCM (*subr)() = SCM_SUBRF (sp[nslots - 1].as_scm);

#define ARG(i) (sp[i].as_scm)
  switch (nslots - 1)
    {
    case 0:
      return subr ();
    case 1:
      return subr (ARG (0));
    case 2:
      return subr (ARG (1), ARG (0));
    case 3:
      return subr (ARG (2), ARG (1), ARG (0));
    case 4:
      return subr (ARG (3), ARG (2), ARG (1), ARG (0));
    case 5:
      return subr (ARG (4), ARG (3), ARG (2), ARG (1), ARG (0));
    case 6:
      return subr (ARG (5), ARG (4), ARG (3), ARG (2), ARG (1),
                   ARG (0));
    case 7:
      return subr (ARG (6), ARG (5), ARG (4), ARG (3), ARG (2),
                   ARG (1), ARG (0));
    case 8:
      return subr (ARG (7), ARG (6), ARG (5), ARG (4), ARG (3),
                   ARG (2), ARG (1), ARG (0));
    case 9:
      return subr (ARG (8), ARG (7), ARG (6), ARG (5), ARG (4),
                   ARG (3), ARG (2), ARG (1), ARG (0));
    case 10:
      return subr (ARG (9), ARG (8), ARG (7), ARG (6), ARG (5),
                   ARG (4), ARG (3), ARG (2), ARG (1), ARG (0));
    default:
      abort ();
    }
#undef ARG
}
Beispiel #20
0
int main (int argc, char *argv[]) {

    FILE *res_map, *res_cpu;
    int64_t *In, *Out;
    int64_t tm;
    int mapnum = 0;
    int i, j, k;
    int nval, Num_Lines, Line_Length;
    gcm_addr_t gcm_in, gcm_out;
    int64_t nbytes;
    int64_t i64;
    int npoint, numvec;
    int offset;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    npoint      = 16;
    numvec      = 16;

    Num_Lines   = npoint*numvec;
    Line_Length = npoint * numvec;


// add dummy line at beginning and end
    nval = (Num_Lines+2) * npoint * numvec;

    In  = malloc (nval * sizeof (int64_t));
    Out = malloc (nval * sizeof (int64_t));

    i = 0;
    for (k=-1; k<Num_Lines+1; k++)  {
    for (j=0; j<Line_Length; j++)  {
        i64 = k*1000 + j;
        In[i] = i64;
        i++;
    }
    }

    if (map_allocate (1)) {
       fprintf (stdout, "Map allocation failed.\n");
       exit (1);
       }

    nbytes = nval * 8;
    gcm_in  = gcm_allocate_by_bank (nbytes, 1);
    gcm_out = gcm_allocate_by_bank (nbytes, 2);

    gcm_cp_to (gcm_in, In, nbytes);

    /* call compute */
    subr (gcm_in, gcm_out, npoint, numvec, Num_Lines, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    gcm_cp_from (gcm_out, Out, nbytes);

    for (k=0; k<Num_Lines; k++)  {
        offset = (k+1)*Line_Length;

    for (j=0; j<Line_Length; j++)  {
        i64 = In[offset + (j%numvec)*npoint+j/numvec];
        fprintf (res_cpu, "%lld\n", i64);
    }
    }

    nval = (Num_Lines) * npoint * numvec;
    for (i=0; i < nval; i++) {
        fprintf (res_map, "%lld\n", Out[i]);
        }

    if (map_free (1)) {
        printf ("Map deallocation failed. \n");
        exit (1);
        }

}
Beispiel #21
0
void
camellia_setup256(const unsigned char *key, uint32_t *subkey)
{
    uint32_t kll,klr,krl,krr;           /* left half of key */
    uint32_t krll,krlr,krrl,krrr;       /* right half of key */
    uint32_t il, ir, t0, t1, w0, w1;    /* temporary variables */
    uint32_t kw4l, kw4r, dw, tl, tr;
    uint32_t subL[34];
    uint32_t subR[34];

    /*
     *  key = (kll || klr || krl || krr || krll || krlr || krrl || krrr)
     *  (|| is concatination)
     */

    kll  = GETU32(key     );
    klr  = GETU32(key +  4);
    krl  = GETU32(key +  8);
    krr  = GETU32(key + 12);
    krll = GETU32(key + 16);
    krlr = GETU32(key + 20);
    krrl = GETU32(key + 24);
    krrr = GETU32(key + 28);

    /* generate KL dependent subkeys */
    subl(0) = kll; subr(0) = klr;
    subl(1) = krl; subr(1) = krr;
    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 45);
    subl(12) = kll; subr(12) = klr;
    subl(13) = krl; subr(13) = krr;
    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
    subl(16) = kll; subr(16) = klr;
    subl(17) = krl; subr(17) = krr;
    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 17);
    subl(22) = kll; subr(22) = klr;
    subl(23) = krl; subr(23) = krr;
    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 34);
    subl(30) = kll; subr(30) = klr;
    subl(31) = krl; subr(31) = krr;

    /* generate KR dependent subkeys */
    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
    subl(4) = krll; subr(4) = krlr;
    subl(5) = krrl; subr(5) = krrr;
    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 15);
    subl(8) = krll; subr(8) = krlr;
    subl(9) = krrl; subr(9) = krrr;
    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
    subl(18) = krll; subr(18) = krlr;
    subl(19) = krrl; subr(19) = krrr;
    CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);
    subl(26) = krll; subr(26) = krlr;
    subl(27) = krrl; subr(27) = krrr;
    CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 34);

    /* generate KA */
    kll = subl(0) ^ krll; klr = subr(0) ^ krlr;
    krl = subl(1) ^ krrl; krr = subr(1) ^ krrr;
    CAMELLIA_F(kll, klr, CAMELLIA_SIGMA1L, CAMELLIA_SIGMA1R,
	       w0, w1, il, ir, t0, t1);
    krl ^= w0; krr ^= w1;
    CAMELLIA_F(krl, krr, CAMELLIA_SIGMA2L, CAMELLIA_SIGMA2R,
	       kll, klr, il, ir, t0, t1);
    kll ^= krll; klr ^= krlr;
    CAMELLIA_F(kll, klr, CAMELLIA_SIGMA3L, CAMELLIA_SIGMA3R,
	       krl, krr, il, ir, t0, t1);
    krl ^= w0 ^ krrl; krr ^= w1 ^ krrr;
    CAMELLIA_F(krl, krr, CAMELLIA_SIGMA4L, CAMELLIA_SIGMA4R,
	       w0, w1, il, ir, t0, t1);
    kll ^= w0; klr ^= w1;

    /* generate KB */
    krll ^= kll; krlr ^= klr;
    krrl ^= krl; krrr ^= krr;
    CAMELLIA_F(krll, krlr, CAMELLIA_SIGMA5L, CAMELLIA_SIGMA5R,
	       w0, w1, il, ir, t0, t1);
    krrl ^= w0; krrr ^= w1;
    CAMELLIA_F(krrl, krrr, CAMELLIA_SIGMA6L, CAMELLIA_SIGMA6R,
	       w0, w1, il, ir, t0, t1);
    krll ^= w0; krlr ^= w1;

    /* generate KA dependent subkeys */
    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 15);
    subl(6) = kll; subr(6) = klr;
    subl(7) = krl; subr(7) = krr;
    CAMELLIA_ROLDQ(kll, klr, krl, krr, w0, w1, 30);
    subl(14) = kll; subr(14) = klr;
    subl(15) = krl; subr(15) = krr;
    subl(24) = klr; subr(24) = krl;
    subl(25) = krr; subr(25) = kll;
    CAMELLIA_ROLDQo32(kll, klr, krl, krr, w0, w1, 49);
    subl(28) = kll; subr(28) = klr;
    subl(29) = krl; subr(29) = krr;

    /* generate KB dependent subkeys */
    subl(2) = krll; subr(2) = krlr;
    subl(3) = krrl; subr(3) = krrr;
    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
    subl(10) = krll; subr(10) = krlr;
    subl(11) = krrl; subr(11) = krrr;
    CAMELLIA_ROLDQ(krll, krlr, krrl, krrr, w0, w1, 30);
    subl(20) = krll; subr(20) = krlr;
    subl(21) = krrl; subr(21) = krrr;
    CAMELLIA_ROLDQo32(krll, krlr, krrl, krrr, w0, w1, 51);
    subl(32) = krll; subr(32) = krlr;
    subl(33) = krrl; subr(33) = krrr;

    /* absorb kw2 to other subkeys */
    subl(3) ^= subl(1); subr(3) ^= subr(1);
    subl(5) ^= subl(1); subr(5) ^= subr(1);
    subl(7) ^= subl(1); subr(7) ^= subr(1);
    subl(1) ^= subr(1) & ~subr(9);
    dw = subl(1) & subl(9), subr(1) ^= CAMELLIA_RL1(dw);
    subl(11) ^= subl(1); subr(11) ^= subr(1);
    subl(13) ^= subl(1); subr(13) ^= subr(1);
    subl(15) ^= subl(1); subr(15) ^= subr(1);
    subl(1) ^= subr(1) & ~subr(17);
    dw = subl(1) & subl(17), subr(1) ^= CAMELLIA_RL1(dw);
    subl(19) ^= subl(1); subr(19) ^= subr(1);
    subl(21) ^= subl(1); subr(21) ^= subr(1);
    subl(23) ^= subl(1); subr(23) ^= subr(1);
    subl(1) ^= subr(1) & ~subr(25);
    dw = subl(1) & subl(25), subr(1) ^= CAMELLIA_RL1(dw);
    subl(27) ^= subl(1); subr(27) ^= subr(1);
    subl(29) ^= subl(1); subr(29) ^= subr(1);
    subl(31) ^= subl(1); subr(31) ^= subr(1);
    subl(32) ^= subl(1); subr(32) ^= subr(1);


    /* absorb kw4 to other subkeys */
    kw4l = subl(33); kw4r = subr(33);
    subl(30) ^= kw4l; subr(30) ^= kw4r;
    subl(28) ^= kw4l; subr(28) ^= kw4r;
    subl(26) ^= kw4l; subr(26) ^= kw4r;
    kw4l ^= kw4r & ~subr(24);
    dw = kw4l & subl(24), kw4r ^= CAMELLIA_RL1(dw);
    subl(22) ^= kw4l; subr(22) ^= kw4r;
    subl(20) ^= kw4l; subr(20) ^= kw4r;
    subl(18) ^= kw4l; subr(18) ^= kw4r;
    kw4l ^= kw4r & ~subr(16);
    dw = kw4l & subl(16), kw4r ^= CAMELLIA_RL1(dw);
    subl(14) ^= kw4l; subr(14) ^= kw4r;
    subl(12) ^= kw4l; subr(12) ^= kw4r;
    subl(10) ^= kw4l; subr(10) ^= kw4r;
    kw4l ^= kw4r & ~subr(8);
    dw = kw4l & subl(8), kw4r ^= CAMELLIA_RL1(dw);
    subl(6) ^= kw4l; subr(6) ^= kw4r;
    subl(4) ^= kw4l; subr(4) ^= kw4r;
    subl(2) ^= kw4l; subr(2) ^= kw4r;
    subl(0) ^= kw4l; subr(0) ^= kw4r;

    /* key XOR is end of F-function */
    SUBL(0) = subl(0) ^ subl(2);
    SUBR(0) = subr(0) ^ subr(2);
    SUBL(2) = subl(3);
    SUBR(2) = subr(3);
    SUBL(3) = subl(2) ^ subl(4);
    SUBR(3) = subr(2) ^ subr(4);
    SUBL(4) = subl(3) ^ subl(5);
    SUBR(4) = subr(3) ^ subr(5);
    SUBL(5) = subl(4) ^ subl(6);
    SUBR(5) = subr(4) ^ subr(6);
    SUBL(6) = subl(5) ^ subl(7);
    SUBR(6) = subr(5) ^ subr(7);
    tl = subl(10) ^ (subr(10) & ~subr(8));
    dw = tl & subl(8), tr = subr(10) ^ CAMELLIA_RL1(dw);
    SUBL(7) = subl(6) ^ tl;
    SUBR(7) = subr(6) ^ tr;
    SUBL(8) = subl(8);
    SUBR(8) = subr(8);
    SUBL(9) = subl(9);
    SUBR(9) = subr(9);
    tl = subl(7) ^ (subr(7) & ~subr(9));
    dw = tl & subl(9), tr = subr(7) ^ CAMELLIA_RL1(dw);
    SUBL(10) = tl ^ subl(11);
    SUBR(10) = tr ^ subr(11);
    SUBL(11) = subl(10) ^ subl(12);
    SUBR(11) = subr(10) ^ subr(12);
    SUBL(12) = subl(11) ^ subl(13);
    SUBR(12) = subr(11) ^ subr(13);
    SUBL(13) = subl(12) ^ subl(14);
    SUBR(13) = subr(12) ^ subr(14);
    SUBL(14) = subl(13) ^ subl(15);
    SUBR(14) = subr(13) ^ subr(15);
    tl = subl(18) ^ (subr(18) & ~subr(16));
    dw = tl & subl(16), tr = subr(18) ^ CAMELLIA_RL1(dw);
    SUBL(15) = subl(14) ^ tl;
    SUBR(15) = subr(14) ^ tr;
    SUBL(16) = subl(16);
    SUBR(16) = subr(16);
    SUBL(17) = subl(17);
    SUBR(17) = subr(17);
    tl = subl(15) ^ (subr(15) & ~subr(17));
    dw = tl & subl(17), tr = subr(15) ^ CAMELLIA_RL1(dw);
    SUBL(18) = tl ^ subl(19);
    SUBR(18) = tr ^ subr(19);
    SUBL(19) = subl(18) ^ subl(20);
    SUBR(19) = subr(18) ^ subr(20);
    SUBL(20) = subl(19) ^ subl(21);
    SUBR(20) = subr(19) ^ subr(21);
    SUBL(21) = subl(20) ^ subl(22);
    SUBR(21) = subr(20) ^ subr(22);
    SUBL(22) = subl(21) ^ subl(23);
    SUBR(22) = subr(21) ^ subr(23);
    tl = subl(26) ^ (subr(26) & ~subr(24));
    dw = tl & subl(24), tr = subr(26) ^ CAMELLIA_RL1(dw);
    SUBL(23) = subl(22) ^ tl;
    SUBR(23) = subr(22) ^ tr;
    SUBL(24) = subl(24);
    SUBR(24) = subr(24);
    SUBL(25) = subl(25);
    SUBR(25) = subr(25);
    tl = subl(23) ^ (subr(23) & ~subr(25));
    dw = tl & subl(25), tr = subr(23) ^ CAMELLIA_RL1(dw);
    SUBL(26) = tl ^ subl(27);
    SUBR(26) = tr ^ subr(27);
    SUBL(27) = subl(26) ^ subl(28);
    SUBR(27) = subr(26) ^ subr(28);
    SUBL(28) = subl(27) ^ subl(29);
    SUBR(28) = subr(27) ^ subr(29);
    SUBL(29) = subl(28) ^ subl(30);
    SUBR(29) = subr(28) ^ subr(30);
    SUBL(30) = subl(29) ^ subl(31);
    SUBR(30) = subr(29) ^ subr(31);
    SUBL(31) = subl(30);
    SUBR(31) = subr(30);
    SUBL(32) = subl(32) ^ subl(31);
    SUBR(32) = subr(32) ^ subr(31);

    /* apply the inverse of the last half of P-function */
    dw = SUBL(2) ^ SUBR(2), dw = CAMELLIA_RL8(dw);
    SUBR(2) = SUBL(2) ^ dw, SUBL(2) = dw;
    dw = SUBL(3) ^ SUBR(3), dw = CAMELLIA_RL8(dw);
    SUBR(3) = SUBL(3) ^ dw, SUBL(3) = dw;
    dw = SUBL(4) ^ SUBR(4), dw = CAMELLIA_RL8(dw);
    SUBR(4) = SUBL(4) ^ dw, SUBL(4) = dw;
    dw = SUBL(5) ^ SUBR(5), dw = CAMELLIA_RL8(dw);
    SUBR(5) = SUBL(5) ^ dw, SUBL(5) = dw;
    dw = SUBL(6) ^ SUBR(6), dw = CAMELLIA_RL8(dw);
    SUBR(6) = SUBL(6) ^ dw, SUBL(6) = dw;
    dw = SUBL(7) ^ SUBR(7), dw = CAMELLIA_RL8(dw);
    SUBR(7) = SUBL(7) ^ dw, SUBL(7) = dw;
    dw = SUBL(10) ^ SUBR(10), dw = CAMELLIA_RL8(dw);
    SUBR(10) = SUBL(10) ^ dw, SUBL(10) = dw;
    dw = SUBL(11) ^ SUBR(11), dw = CAMELLIA_RL8(dw);
    SUBR(11) = SUBL(11) ^ dw, SUBL(11) = dw;
    dw = SUBL(12) ^ SUBR(12), dw = CAMELLIA_RL8(dw);
    SUBR(12) = SUBL(12) ^ dw, SUBL(12) = dw;
    dw = SUBL(13) ^ SUBR(13), dw = CAMELLIA_RL8(dw);
    SUBR(13) = SUBL(13) ^ dw, SUBL(13) = dw;
    dw = SUBL(14) ^ SUBR(14), dw = CAMELLIA_RL8(dw);
    SUBR(14) = SUBL(14) ^ dw, SUBL(14) = dw;
    dw = SUBL(15) ^ SUBR(15), dw = CAMELLIA_RL8(dw);
    SUBR(15) = SUBL(15) ^ dw, SUBL(15) = dw;
    dw = SUBL(18) ^ SUBR(18), dw = CAMELLIA_RL8(dw);
    SUBR(18) = SUBL(18) ^ dw, SUBL(18) = dw;
    dw = SUBL(19) ^ SUBR(19), dw = CAMELLIA_RL8(dw);
    SUBR(19) = SUBL(19) ^ dw, SUBL(19) = dw;
    dw = SUBL(20) ^ SUBR(20), dw = CAMELLIA_RL8(dw);
    SUBR(20) = SUBL(20) ^ dw, SUBL(20) = dw;
    dw = SUBL(21) ^ SUBR(21), dw = CAMELLIA_RL8(dw);
    SUBR(21) = SUBL(21) ^ dw, SUBL(21) = dw;
    dw = SUBL(22) ^ SUBR(22), dw = CAMELLIA_RL8(dw);
    SUBR(22) = SUBL(22) ^ dw, SUBL(22) = dw;
    dw = SUBL(23) ^ SUBR(23), dw = CAMELLIA_RL8(dw);
    SUBR(23) = SUBL(23) ^ dw, SUBL(23) = dw;
    dw = SUBL(26) ^ SUBR(26), dw = CAMELLIA_RL8(dw);
    SUBR(26) = SUBL(26) ^ dw, SUBL(26) = dw;
    dw = SUBL(27) ^ SUBR(27), dw = CAMELLIA_RL8(dw);
    SUBR(27) = SUBL(27) ^ dw, SUBL(27) = dw;
    dw = SUBL(28) ^ SUBR(28), dw = CAMELLIA_RL8(dw);
    SUBR(28) = SUBL(28) ^ dw, SUBL(28) = dw;
    dw = SUBL(29) ^ SUBR(29), dw = CAMELLIA_RL8(dw);
    SUBR(29) = SUBL(29) ^ dw, SUBL(29) = dw;
    dw = SUBL(30) ^ SUBR(30), dw = CAMELLIA_RL8(dw);
    SUBR(30) = SUBL(30) ^ dw, SUBL(30) = dw;
    dw = SUBL(31) ^ SUBR(31), dw = CAMELLIA_RL8(dw);
    SUBR(31) = SUBL(31) ^ dw, SUBL(31) = dw;
}
Beispiel #22
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, idx, num, nvals;
    int64_t *A, *B, *MB;
    int64_t tm, res, accum=0;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements as arg\n");
	exit (1);
	}

    if ((num < 1) || (num > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
	exit (1);
	}

    A = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));
    MB = (int64_t*) Cache_Aligned_Allocate (num * sizeof (int64_t));

    srandom (99);

    idx = 0;
    for (i=0; i<num; i++) {
        A[i] = random () & 0xff;
	if (A[i] < 128)
	    MB[idx++] = A[i];
	}

    for (i=0; i<idx; i++)
        fprintf (res_cpu, "%lld\n", MB[i]);

    map_allocate (1);

    subr (A, B, num, &nvals, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<nvals; i++)
        fprintf (res_map, "%lld\n", B[i]);

    map_free (1);

    exit(0);
    }
Beispiel #23
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, j, D0, D1, num;
    int64_t *A, *B, *MB;
    int64_t tm, res, accum=0;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 3) {
	fprintf (stderr, "need two dimensions as args\n");
	exit (1);
	}

    if (sscanf (argv[1], "%d", &D0) < 1) {
	fprintf (stderr, "need two dimensions as args\n");
	exit (1);
	}

    if (sscanf (argv[2], "%d", &D1) < 1) {
	fprintf (stderr, "need two dimensions as args\n");
	exit (1);
	}

    if ((D0*D1 < 1) || (D0*D1 > MAX_OBM_SIZE)) {
        fprintf (stderr, "number of elements must be in the range 1 through %d\n", MAX_OBM_SIZE);
	exit (1);
	}

    A = (int64_t*) Cache_Aligned_Allocate (D0*D1 * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (D0 * sizeof (int64_t));
    MB = (int64_t*) Cache_Aligned_Allocate (D0 * sizeof (int64_t));

    srandom (99);

    for (i=0; i<D0*D1; i++) {
        A[i] = random ();
	}

    for (i=0; i<D0; i++) {
	MB[i] = 0;
        for (j=0; j<D1; j++)
	    MB[i] += A[i*D1+j];
	}

    map_allocate (1);

    subr (A, B, D0, D1, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<D0; i++) {
        fprintf (res_map, "%lld\n", B[i]);
        fprintf (res_cpu, "%lld\n", MB[i]);
	}

    map_free (1);

    exit(0);
    }
Beispiel #24
0
int main (int argc, char *argv[]) 
{
    FILE 	*res_map, *res_cpu;
    int	 	i,j;

    /* 
     * Text memory routes to Bank A and it is the input to Map Processor
     * 	### Currently limited to 100 words - Bank A
     * Core Dump is the output from MAP processer and it contains the 
     * architecture state in the form of register file data
     *  ### Fixed at 32 words - Bank B
     * Data memory is also the output from MAP processor and it contains
     * the final state of processor's memory 
     *  ### Currently limited to 100 words - Bank D
     */
    int64_t 	*text_memory, *core_dump, *data_memory;
    int64_t 	tm, accum=0;
    int 	mapnum = 0;

    /* Statically initialize PC to the start of text memory */
    int64_t	pc_value = MEM_TEXT_START;

    /* Program File Variable */
    FILE	*program;
    int		instruction_word;
    int         instruction_count;
    int64_t     instructions_executed;

    /* Preliminary Error Checking */
    if (argc < 2) {
	/* Dislay correct usage information */
	printf ("[Error] usage: %s <program_file>\n", argv[0]);
	exit (1);
    }

    /* Open the program file for reading */
    program = fopen (argv[1], "r");

    /* Check for the validity of program file */
    if (program == NULL) {
	printf ("[Error] Can't open program file %s\n", argv[1]);
	exit (1);
    }

    /* Initialize the memories on co-processor */
    text_memory	= (int64_t*) Cache_Aligned_Allocate ((MEM_TEXT_SIZE)  * sizeof (int64_t));
    core_dump	= (int64_t*) Cache_Aligned_Allocate ((MIPS_ARCH_REGS) * sizeof (int64_t));
    data_memory	= (int64_t*) Cache_Aligned_Allocate ((MEM_DATA_SIZE)  * sizeof (int64_t));

    /* Read the program file */
    instruction_count = 0;
    while (fscanf (program, "%x\n", &instruction_word) != EOF) {
	text_memory[instruction_count] = instruction_word;
	instruction_count++;
    }

    /* Close the program file */
    fclose (program);

    printf ("MIPS Simulator\n\n");
    printf ("Read %d words from program file into instruction memory.\n", instruction_count);

    /* Initialize the remaining instructions as zeros */
    for (i = instruction_count; i < (MEM_TEXT_SIZE); i++) {
	text_memory[i] = 0;
    }

    /* Open the files to print data from mips processor */
    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
	}

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
    }

    /* Run the program on simulator */
    simulate(argv[1]);

    /* Dump the simulation result to res_cpu file */
    fprintf (res_cpu, "Program                     : %s\n", argv[1]);
    fprintf (res_cpu, "Clocks                      : 0\n");
    rdump (res_cpu);
    mdump (res_cpu);

    /* Execute the program on MAP processor */
    map_allocate (1);

    subr (text_memory, core_dump, data_memory, &pc_value, &instructions_executed, &tm, mapnum);

    /* Free the map processor */
    map_free (1);
    
    /* Print execution results to output files */
    fprintf (res_map, "Program                     : %s\n", argv[1]);
    fprintf (res_map, "Clocks                      : %lld\n", tm);
    fprintf (res_map, "Instruction Count           : %d\n", (int)instructions_executed);
    fprintf (res_map, "Final PC Value              : 0x%08x\n", (int)pc_value);
    
    rdump_map(res_map, core_dump);
    mdump_map(res_map, data_memory);

    /* Close result files */
    fclose (res_cpu);
    fclose (res_map);

    exit(0);
}
Beispiel #25
0
int main (int argc, char *argv[]) {
    FILE *res_map, *res_cpu;
    int i, num;
    int64_t *A, *B, *C, *D;
    int64_t tm;
    int mapnum = 0;

    if ((res_map = fopen ("res_map", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_map'\n");
        exit (1);
        }

    if ((res_cpu = fopen ("res_cpu", "w")) == NULL) {
        fprintf (stderr, "failed to open file 'res_cpu'\n");
        exit (1);
        }

    if (argc < 2) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    if (sscanf (argv[1], "%d", &num) < 1) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    if (num > SZ) {
	fprintf (stderr, "need number of elements (up to %d) as arg\n", SZ);
	exit (1);
	}

    A = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));
    B = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));
    C = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));
    D = (int64_t*) Cache_Aligned_Allocate (SZ * sizeof (int64_t));

    srandom (99);

    for (i=0; i<SZ; i++) {
        A[i] = random ();
        B[i] = random ();
        C[i] = random ();
	}

    map_allocate (1);

    // call the MAP routine
    subr (A, B, C, D, num, &tm, mapnum);

    printf ("%lld clocks\n", tm);

    for (i=0; i<num; i++) {
	int64_t vx, vy, res;
        fprintf (res_map, "%lld\n", D[i]);

        vx = C[i] * (A[i]>B[i] ? A[i]-B[i] : A[i]+B[i]);
        vy = vx + A[i];
        vy = vy / 42;
        res = vy + C[i];

        fprintf (res_cpu, "%lld\n", res);
	}

    map_free (1);

    exit(0);
    }