Пример #1
0
int main(int argc, char **argv)
{
  uint32_t a, b, c;
  uint8_t *r1, *r2;
  uint16_t *r16;
  uint32_t *r32;
  int w, i;
  gf_t gf;

  if (argc != 2) usage(NULL);
  w = atoi(argv[1]);
  if (w <= 0 || w > 32) usage("Bad w");

  /* Get two random numbers in a and b */

  MOA_Seed(time(0));
  a = MOA_Random_W(w, 0);
  b = MOA_Random_W(w, 0);

  /* Create the proper instance of the gf_t object using defaults: */

  gf_init_easy(&gf, w);

  /* And multiply a and b using the galois field: */

  c = gf.multiply.w32(&gf, a, b);
  printf("%u * %u = %u\n", a, b, c);

  /* Divide the product by a and b */

  printf("%u / %u = %u\n", c, a, gf.divide.w32(&gf, c, a));
  printf("%u / %u = %u\n", c, b, gf.divide.w32(&gf, c, b));

  /* If w is 4, 8, 16 or 32, do a very small region operation */

  if (w == 4 || w == 8 || w == 16 || w == 32) {
    r1 = (uint8_t *) malloc(16);
    r2 = (uint8_t *) malloc(16);

    if (w == 4 || w == 8) {
      r1[0] = b;
      for (i = 1; i < 16; i++) r1[i] = MOA_Random_W(8, 1);
    } else if (w == 16) {
      r16 = (uint16_t *) r1;
      r16[0] = b;
      for (i = 1; i < 8; i++) r16[i] = MOA_Random_W(16, 1);
    } else {
      r32 = (uint32_t *) r1;
      r32[0] = b;
      for (i = 1; i < 4; i++) r32[i] = MOA_Random_W(32, 1);
    }

    gf.multiply_region.w32(&gf, r1, r2, a, 16, 0);
  
    printf("\nmultiply_region by 0x%x (%u)\n\n", a, a);
    printf("R1 (the source):  ");
    if (w == 4) {
      for (i = 0; i < 16; i++) printf(" %x %x", r1[i] >> 4, r1[i] & 0xf);
    } else if (w == 8) {
Пример #2
0
int galois_init_default_field(int w)
{
  if (gfp_array[w] == NULL) {
    gfp_array[w] = (gf_t*)malloc(sizeof(gf_t));
    if(gfp_array[w] == NULL)
      return ENOMEM;
    if (!gf_init_easy(gfp_array[w], w))
      return EINVAL;
  }
  return 0;
}
Пример #3
0
int main(int argc, char **argv)
{
  uint64_t a, b, c;
  uint64_t *r1, *r2;
  int i;
  gf_t gf;

  if (argc != 1) usage(NULL);

  /* Get two random numbers in a and b */

  MOA_Seed(time(0));
  a = MOA_Random_64();
  b = MOA_Random_64();

  /* Create the proper instance of the gf_t object using defaults: */

  gf_init_easy(&gf, 64);

  /* And multiply a and b using the galois field: */

  c = gf.multiply.w64(&gf, a, b);
  printf("%llx * %llx = %llx\n", (long long unsigned int) a, (long long unsigned int) b, (long long unsigned int) c);

  /* Divide the product by a and b */

  printf("%llx / %llx = %llx\n", (long long unsigned int) c, (long long unsigned int) a, (long long unsigned int) gf.divide.w64(&gf, c, a));
  printf("%llx / %llx = %llx\n", (long long unsigned int) c, (long long unsigned int) b, (long long unsigned int) gf.divide.w64(&gf, c, b));

  r1 = (uint64_t *) malloc(32);
  r2 = (uint64_t *) malloc(32);

  r1[0] = b;

  for (i = 1; i < 4; i++) r1[i] = MOA_Random_64();

  gf.multiply_region.w64(&gf, r1, r2, a, 32, 0);

  printf("\nmultiply_region by %llx\n\n", (long long unsigned int) a);
  printf("R1 (the source):  ");
  for (i = 0; i < 4; i++) printf(" %016llx", (long long unsigned int) r1[i]);

  printf("\nR2 (the product): ");
  for (i = 0; i < 4; i++) printf(" %016llx", (long long unsigned int) r2[i]);
  printf("\n");

  exit(0);
}
Пример #4
0
static void galois_init_default_field(int w)
{
  if (w <= 0 || w > 32) {
    fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
    exit(1);
  }

  if (gfp_array[w] == NULL) {
    gfp_array[w] = (gf_t*)malloc(sizeof(gf_t));
    if (gfp_array[w] == NULL) {
      fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w);
      exit(1);
    }
  }

  if (!gf_init_easy(gfp_array[w], w)) {
    fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w);
    exit(1);
  }
}
Пример #5
0
int main(int argc, char **argv) {
	gf_t *gfield_context = malloc(sizeof(gf_t));
	uint32_t *vmond_row = malloc(NUM_CHECKSUMS*sizeof(uint32_t));
	uint32_t *chksums = calloc(NUM_CHECKSUMS, sizeof(uint32_t));
	uint32_t data = 0x41414141;

	debug4("Initializing gf.\n");
	gf_init_easy(gfield_context, FIELD_SIZE);

	for (int i = 0; i < 32; i++) {
		printarray(chksums, NUM_CHECKSUMS);
		createvmond(gfield_context, vmond_row, NUM_CHECKSUMS, i+1);
		updatechecksum(gfield_context, chksums, vmond_row, NUM_CHECKSUMS, data);
		//stepvmond(gfield_context, vmond_matrix, FIELD_SIZE);
	}
	printarray(chksums, NUM_CHECKSUMS);

	//free(gfield_context);
	argc=0; argv=0;
}
Пример #6
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);
  }
}