]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | * GF-Complete: A Comprehensive Open Source Library for Galois Field Arithmetic | |
3 | * James S. Plank, Ethan L. Miller, Kevin M. Greenan, | |
4 | * Benjamin A. Arnold, John A. Burnum, Adam W. Disney, Allen C. McBride. | |
5 | * | |
6 | * gf_example_5.c | |
7 | * | |
8 | * Demonstrating altmap and extract_word | |
9 | */ | |
10 | ||
11 | #include <stdio.h> | |
12 | #include <getopt.h> | |
13 | #include <stdint.h> | |
14 | #include <string.h> | |
15 | #include <stdlib.h> | |
16 | #include <time.h> | |
17 | ||
18 | #include "gf_complete.h" | |
19 | #include "gf_rand.h" | |
20 | ||
21 | void usage(char *s) | |
22 | { | |
23 | fprintf(stderr, "usage: gf_example_5\n"); | |
24 | exit(1); | |
25 | } | |
26 | ||
27 | int main(int argc, char **argv) | |
28 | { | |
29 | uint16_t *a, *b; | |
30 | int i, j; | |
31 | gf_t gf; | |
32 | ||
33 | if (gf_init_hard(&gf, 16, GF_MULT_SPLIT_TABLE, GF_REGION_ALTMAP, GF_DIVIDE_DEFAULT, | |
34 | 0, 16, 4, NULL, NULL) == 0) { | |
35 | fprintf(stderr, "gf_init_hard failed\n"); | |
36 | exit(1); | |
37 | } | |
38 | ||
39 | a = (uint16_t *) malloc(200); | |
40 | b = (uint16_t *) malloc(200); | |
41 | ||
42 | a += 6; | |
43 | b += 6; | |
44 | ||
45 | MOA_Seed(0); | |
46 | ||
47 | for (i = 0; i < 30; i++) a[i] = MOA_Random_W(16, 1); | |
48 | ||
49 | gf.multiply_region.w32(&gf, a, b, 0x1234, 30*2, 0); | |
50 | ||
51 | printf("a: 0x%lx b: 0x%lx\n", (unsigned long) a, (unsigned long) b); | |
52 | ||
53 | for (i = 0; i < 30; i += 10) { | |
54 | printf("\n"); | |
55 | printf(" "); | |
56 | for (j = 0; j < 10; j++) printf(" %4d", i+j); | |
57 | printf("\n"); | |
58 | ||
59 | printf("a:"); | |
60 | for (j = 0; j < 10; j++) printf(" %04x", a[i+j]); | |
61 | printf("\n"); | |
62 | ||
63 | printf("b:"); | |
64 | for (j = 0; j < 10; j++) printf(" %04x", b[i+j]); | |
65 | printf("\n"); | |
66 | printf("\n"); | |
67 | } | |
68 | ||
69 | for (i = 0; i < 15; i ++) { | |
70 | printf("Word %2d: 0x%04x * 0x1234 = 0x%04x ", i, | |
71 | gf.extract_word.w32(&gf, a, 30*2, i), | |
72 | gf.extract_word.w32(&gf, b, 30*2, i)); | |
73 | printf("Word %2d: 0x%04x * 0x1234 = 0x%04x\n", i+15, | |
74 | gf.extract_word.w32(&gf, a, 30*2, i+15), | |
75 | gf.extract_word.w32(&gf, b, 30*2, i+15)); | |
76 | } | |
77 | return 0; | |
78 | } |