File: gf_example_6.c

package info (click to toggle)
gf-complete 1.0.2%2B2017.04.10.git.ea75cdf-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 1,272 kB
  • sloc: ansic: 16,714; sh: 573; makefile: 110
file content (84 lines) | stat: -rw-r--r-- 2,024 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * GF-Complete: A Comprehensive Open Source Library for Galois Field Arithmetic
 * James S. Plank, Ethan L. Miller, Kevin M. Greenan,
 * Benjamin A. Arnold, John A. Burnum, Adam W. Disney, Allen C. McBride.
 *
 * gf_example_6.c
 *
 * Demonstrating altmap and extract_word
 */

#include <stdio.h>
#include <getopt.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include "gf_complete.h"
#include "gf_rand.h"

void usage(char *s)
{
  fprintf(stderr, "usage: gf_example_6\n");
  exit(1);
}

int main(int argc, char **argv)
{
  uint32_t *a, *b;
  int i, j;
  gf_t gf, gf_16;

  if (gf_init_hard(&gf_16, 16, GF_MULT_LOG_TABLE, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
                   0, 0, 0, NULL, NULL) == 0) {
    fprintf(stderr, "gf_init_hard (6) failed\n");
    exit(1);
  }

  if (gf_init_hard(&gf, 32, GF_MULT_COMPOSITE, GF_REGION_ALTMAP, GF_DIVIDE_DEFAULT, 
                   0, 2, 0, &gf_16, NULL) == 0) {
    fprintf(stderr, "gf_init_hard (32) failed\n");
    exit(1);
  }

  a = (uint32_t *) malloc(200);
  b = (uint32_t *) malloc(200);

  a += 3;
  b += 3;

  MOA_Seed(0);

  for (i = 0; i < 30; i++) a[i] = MOA_Random_W(32, 1);

  gf.multiply_region.w32(&gf, a, b, 0x12345678, 30*4, 0);

  printf("a: 0x%lx    b: 0x%lx\n", (unsigned long) a, (unsigned long) b);

  for (i = 0; i < 30; i += 10) {
    printf("\n");
    printf("  ");
    for (j = 0; j < 10; j++) printf(" %8d", i+j);
    printf("\n");

    printf("a:");
    for (j = 0; j < 10; j++) printf(" %08x", a[i+j]);
    printf("\n");

    printf("b:");
    for (j = 0; j < 10; j++) printf(" %08x", b[i+j]);
    printf("\n");
    printf("\n");
  }

  for (i = 0; i < 15; i ++) {
    printf("Word %2d: 0x%08x * 0x12345678 = 0x%08x    ", i,
           gf.extract_word.w32(&gf, a, 30*4, i),
           gf.extract_word.w32(&gf, b, 30*4, i));
    printf("Word %2d: 0x%08x * 0x12345678 = 0x%08x\n", i+15,
           gf.extract_word.w32(&gf, a, 30*4, i+15),
           gf.extract_word.w32(&gf, b, 30*4, i+15));
  }
  return 0;
}