Esempio n. 1
0
int main(int argc, char **argv)
{
  int w, j, i, size, iterations;
  gf_t      gf;
  double timer, elapsed, dnum, num;
  uint8_t *ra, *rb, *mult4, *mult8;
  uint16_t *ra16, *rb16, *log16, *alog16;
  time_t t0;
  
  if (argc != 5) usage(NULL);
  if (sscanf(argv[1], "%d", &w) == 0) usage("Bad w\n");
  if (w != 4 && w != 8 && w != 16) usage("Bad w\n");
  if (sscanf(argv[2], "%ld", &t0) == 0) usage("Bad seed\n");
  if (sscanf(argv[3], "%d", &size) == 0) usage("Bad #elts\n");
  if (sscanf(argv[4], "%d", &iterations) == 0) usage("Bad iterations\n");
  if (t0 == -1) t0 = time(0);
  MOA_Seed(t0);

  num = size;

  gf_init_easy(&gf, w);
  
  printf("Seed: %ld\n", t0);

  if (w == 4 || w == 8) {
    ra = (uint8_t *) malloc(size);
    rb = (uint8_t *) malloc(size);

    if (ra == NULL || rb == NULL) { perror("malloc"); exit(1); }
  } else if (w == 16) {
    ra16 = (uint16_t *) malloc(size*2);
    rb16 = (uint16_t *) malloc(size*2);

    if (ra16 == NULL || rb16 == NULL) { perror("malloc"); exit(1); }
  }

  if (w == 4) {
    mult4 = gf_w4_get_mult_table(&gf);
    if (mult4 == NULL) {
      printf("Couldn't get inline multiplication table.\n");
      exit(1);
    }
    elapsed = 0;
    dnum = 0;
    for (i = 0; i < iterations; i++) {
      for (j = 0; j < size; j++) {
        ra[j] = MOA_Random_W(w, 1);
        rb[j] = MOA_Random_W(w, 1);
      }
      timer_start(&timer);
      for (j = 0; j < size; j++) {
        ra[j] = GF_W4_INLINE_MULTDIV(mult4, ra[j], rb[j]);
      }
      dnum += num;
      elapsed += timer_split(&timer);
    }
    printf("Inline mult:   %10.6lf s   Mops: %10.3lf    %10.3lf Mega-ops/s\n",
           elapsed, dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);

  }
  if (w == 8) {
    mult8 = gf_w8_get_mult_table(&gf);
    if (mult8 == NULL) {
      printf("Couldn't get inline multiplication table.\n");
      exit(1);
    }
    elapsed = 0;
    dnum = 0;
    for (i = 0; i < iterations; i++) {
      for (j = 0; j < size; j++) {
        ra[j] = MOA_Random_W(w, 1);
        rb[j] = MOA_Random_W(w, 1);
      }
      timer_start(&timer);
      for (j = 0; j < size; j++) {
        ra[j] = GF_W8_INLINE_MULTDIV(mult8, ra[j], rb[j]);
      }
      dnum += num;
      elapsed += timer_split(&timer);
    }
    printf("Inline mult:   %10.6lf s   Mops: %10.3lf    %10.3lf Mega-ops/s\n",
           elapsed, dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);
  }
  if (w == 16) {
    log16 = gf_w16_get_log_table(&gf);
    alog16 = gf_w16_get_mult_alog_table(&gf);
    if (log16 == NULL) {
      printf("Couldn't get inline multiplication table.\n");
      exit(1);
    }
    elapsed = 0;
    dnum = 0;
    for (i = 0; i < iterations; i++) {
      for (j = 0; j < size; j++) {
        ra16[j] = MOA_Random_W(w, 1);
        rb16[j] = MOA_Random_W(w, 1);
      }
      timer_start(&timer);
      for (j = 0; j < size; j++) {
        ra16[j] = GF_W16_INLINE_MULT(log16, alog16, ra16[j], rb16[j]);
      }
      dnum += num;
      elapsed += timer_split(&timer);
    }
    printf("Inline mult:   %10.6lf s   Mops: %10.3lf    %10.3lf Mega-ops/s\n",
           elapsed, dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);
  }
}
Esempio n. 2
0
int main(int argc, char **argv)
{
  int w, it, i, size, iterations, xor;
  char tests[100];
  char test;
  char *single_tests = "MDI";
  char *region_tests = "G012";
  char *tstrings[256];
  void *tmethods[256];
  gf_t      gf;
  double timer, elapsed, ds, di, dnum;
  int num;
  time_t t0;
  uint8_t *ra, *rb;
  gf_general_t a;

  
  if (argc < 6) usage(NULL);
  
  if (sscanf(argv[1], "%d", &w) == 0){
    usage("Bad w[-pp]\n");
  }

  
  if (sscanf(argv[3], "%ld", &t0) == 0) usage("Bad seed\n");
  if (sscanf(argv[4], "%d", &size) == 0) usage("Bad size\n");
  if (sscanf(argv[5], "%d", &iterations) == 0) usage("Bad iterations\n");
  if (t0 == -1) t0 = time(0);
  MOA_Seed(t0);

  ds = size;
  di = iterations;

  if ((w > 32 && w != 64 && w != 128) || w < 0) usage("Bad w");
  if ((size * 8) % w != 0) usage ("Bad size -- must be a multiple of w*8\n");
  
  if (!create_gf_from_argv(&gf, w, argc, argv, 6)) usage(BM);

  strcpy(tests, "");
  for (i = 0; argv[2][i] != '\0'; i++) {
    switch(argv[2][i]) {
      case 'A': strcat(tests, single_tests); 
                strcat(tests, region_tests); 
                break;
      case 'S': strcat(tests, single_tests); break;
      case 'R': strcat(tests, region_tests); break;
      case 'G': strcat(tests, "G"); break;
      case '0': strcat(tests, "0"); break;
      case '1': strcat(tests, "1"); break;
      case '2': strcat(tests, "2"); break;
      case 'M': strcat(tests, "M"); break;
      case 'D': strcat(tests, "D"); break;
      case 'I': strcat(tests, "I"); break;
      default: usage("Bad tests");
    }
  }

  tstrings['M'] = "Multiply";
  tstrings['D'] = "Divide";
  tstrings['I'] = "Inverse";
  tstrings['G'] = "Region-Random";
  tstrings['0'] = "Region-By-Zero";
  tstrings['1'] = "Region-By-One";
  tstrings['2'] = "Region-By-Two";

  tmethods['M'] = (void *) gf.multiply.w32;
  tmethods['D'] = (void *) gf.divide.w32;
  tmethods['I'] = (void *) gf.inverse.w32;
  tmethods['G'] = (void *) gf.multiply_region.w32;
  tmethods['0'] = (void *) gf.multiply_region.w32;
  tmethods['1'] = (void *) gf.multiply_region.w32;
  tmethods['2'] = (void *) gf.multiply_region.w32;

  printf("Seed: %ld\n", t0);

  ra = (uint8_t *) malloc(size);
  rb = (uint8_t *) malloc(size);

  if (ra == NULL || rb == NULL) { perror("malloc"); exit(1); }

  for (i = 0; i < 3; i++) {
    test = single_tests[i];
    if (strchr(tests, test) != NULL) {
      if (tmethods[(int)test] == NULL) {
        printf("No %s method.\n", tstrings[(int)test]);
      } else {
        elapsed = 0;
        dnum = 0;
        for (it = 0; it < iterations; it++) {
          gf_general_set_up_single_timing_test(w, ra, rb, size);
          timer_start(&timer);
          num = gf_general_do_single_timing_test(&gf, ra, rb, size, test);
          dnum += num;
          elapsed += timer_split(&timer);
        }
        printf("%14s:           %10.6lf s   Mops: %10.3lf    %10.3lf Mega-ops/s\n", 
               tstrings[(int)test], elapsed, 
               dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);
      }
    }
  }

  for (i = 0; i < 4; i++) {
    test = region_tests[i];
    if (strchr(tests, test) != NULL) {
      if (tmethods[(int)test] == NULL) {
        printf("No %s method.\n", tstrings[(int)test]);
      } else {
        if (test == '0') gf_general_set_zero(&a, w);
        if (test == '1') gf_general_set_one(&a, w);
        if (test == '2') gf_general_set_two(&a, w);

        for (xor = 0; xor < 2; xor++) {
          elapsed = 0;
          for (it = 0; it < iterations; it++) {
            if (test == 'G') gf_general_set_random(&a, w, 1);
            gf_general_set_up_single_timing_test(8, ra, rb, size);
            timer_start(&timer);
            gf_general_do_region_multiply(&gf, &a, ra, rb, size, xor);
            elapsed += timer_split(&timer);
          }
          printf("%14s: XOR: %d    %10.6lf s     MB: %10.3lf    %10.3lf MB/s\n", 
               tstrings[(int)test], xor, elapsed, 
               ds*di/1024.0/1024.0, ds*di/1024.0/1024.0/elapsed);
        }
      }
    }
  }
  return 0;
}