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.
8 * Lists supported methods (incomplete w.r.t. GROUP and COMPOSITE)
16 #include "gf_complete.h"
17 #include "gf_method.h"
21 static char *BMULTS[BNMULTS] = { "CARRY_FREE", "GROUP48",
22 "TABLE", "LOG", "SPLIT4", "SPLIT8", "SPLIT88", "COMPOSITE" };
24 static char *MULTS[NMULTS] = { "SHIFT", "CARRY_FREE", "CARRY_FREE_GK", "GROUP44", "GROUP48", "BYTWO_p", "BYTWO_b",
25 "TABLE", "LOG", "LOG_ZERO", "LOG_ZERO_EXT", "SPLIT2",
26 "SPLIT4", "SPLIT8", "SPLIT16", "SPLIT88", "COMPOSITE" };
28 /* Make sure CAUCHY is last */
31 static char *REGIONS[NREGIONS] = { "DOUBLE", "QUAD", "LAZY", "SIMD", "NOSIMD",
35 static char *BREGIONS[BNREGIONS] = { "DOUBLE", "QUAD", "ALTMAP", "CAUCHY" };
38 static char *divides[NDIVS] = { "MATRIX", "EUCLID" };
42 fprintf(stderr, "usage: gf_methods w -BADC -LXUMDRB\n");
43 fprintf(stderr, "\n");
44 fprintf(stderr, " w can be 1-32, 64, 128\n");
45 fprintf(stderr, "\n");
46 fprintf(stderr, " -B lists basic methods that are useful\n");
47 fprintf(stderr, " -A does a nearly exhaustive listing\n");
48 fprintf(stderr, " -D adds EUCLID and MATRIX division\n");
49 fprintf(stderr, " -C adds CAUCHY when possible\n");
50 fprintf(stderr, " Combinations are fine.\n");
51 fprintf(stderr, "\n");
52 fprintf(stderr, " -L Simply lists methods\n");
53 fprintf(stderr, " -X List methods and functions selected (compile with DEBUG_FUNCTIONS)\n");
54 fprintf(stderr, " -U Produces calls to gf_unit\n");
55 fprintf(stderr, " -M Produces calls to time_tool.sh for single multiplications\n");
56 fprintf(stderr, " -D Produces calls to time_tool.sh for single divisions\n");
57 fprintf(stderr, " -R Produces calls to time_tool.sh for region multiplications\n");
58 fprintf(stderr, " -B Produces calls to time_tool.sh for the fastest region multiplications\n");
59 fprintf(stderr, " Cannot combine L, U, T.\n");
61 fprintf(stderr, "\n");
62 fprintf(stderr, "%s\n", s);
67 void print_methods(gf_t *gf)
69 #ifdef DEBUG_FUNCTIONS
70 gf_internal_t *h = (gf_internal_t*) gf->scratch;
72 printf("multiply = %s\n", h->multiply);
73 printf("divide = %s\n", h->divide);
74 printf("inverse = %s\n", h->inverse);
75 printf("multiply_region = %s\n", h->multiply_region);
76 printf("extract_word = %s\n", h->extract_word);
80 int main(int argc, char *argv[])
82 int m, r, d, w, i, sa, j, k, reset, ok;
91 char *gf_argv[50], *x;
96 if (argc != 4) usage(NULL);
98 ok = (w >= 1 && w <= 32);
100 if (w == 128) ok = 1;
101 if (!ok) usage("Bad w");
103 if (argv[2][0] != '-' || argv[3][0] != '-' || strlen(argv[2]) == 1 || strlen(argv[3]) != 2) {
106 for (i = 1; argv[2][i] != '\0'; i++) {
108 case 'B': exhaustive = 0; break;
109 case 'A': exhaustive = 1; break;
110 case 'D': divide = 1; break;
111 case 'C': cauchy = 1; break;
112 default: usage("Bad -BADC");
116 if (strchr("LXUMDRB", argv[3][1]) == NULL) { usage("Bad -LXUMDRB"); }
117 listing = argv[3][1];
119 if (listing == 'U') {
120 w_str = "../test/gf_unit %d A -1";
121 } else if (listing == 'L' || listing == 'X') {
124 w_str = strdup("sh time_tool.sh X %d");
125 x = strchr(w_str, 'X');
130 if (create_gf_from_argv(&gf, w, 1, gf_argv, 0) > 0) {
134 } else if (_gf_errno == GF_E_DEFAULT) {
135 fprintf(stderr, "Unlabeled failed method: w=%d: -\n", 2);
139 nregions = (exhaustive) ? NREGIONS : BNREGIONS;
140 if (!cauchy) nregions--;
141 regions = (exhaustive) ? REGIONS : BREGIONS;
142 mults = (exhaustive) ? MULTS : BMULTS;
143 nmults = (exhaustive) ? NMULTS : BNMULTS;
146 for (m = 0; m < nmults; m++) {
148 gf_argv[sa++] = "-m";
149 if (strcmp(mults[m], "GROUP44") == 0) {
150 gf_argv[sa++] = "GROUP";
153 } else if (strcmp(mults[m], "GROUP48") == 0) {
154 gf_argv[sa++] = "GROUP";
157 } else if (strcmp(mults[m], "SPLIT2") == 0) {
158 gf_argv[sa++] = "SPLIT";
159 sprintf(ls, "%d", w);
162 } else if (strcmp(mults[m], "SPLIT4") == 0) {
163 gf_argv[sa++] = "SPLIT";
164 sprintf(ls, "%d", w);
167 } else if (strcmp(mults[m], "SPLIT8") == 0) {
168 gf_argv[sa++] = "SPLIT";
169 sprintf(ls, "%d", w);
172 } else if (strcmp(mults[m], "SPLIT16") == 0) {
173 gf_argv[sa++] = "SPLIT";
174 sprintf(ls, "%d", w);
176 gf_argv[sa++] = "16";
177 } else if (strcmp(mults[m], "SPLIT88") == 0) {
178 gf_argv[sa++] = "SPLIT";
181 } else if (strcmp(mults[m], "COMPOSITE") == 0) {
182 gf_argv[sa++] = "COMPOSITE";
186 gf_argv[sa++] = mults[m];
191 for (r = 0; r < (1 << nregions); r++) {
193 for (k = 0; k < nregions; k++) {
195 gf_argv[sa++] = "-r";
196 gf_argv[sa++] = regions[k];
201 /* printf("Hmmmm. %s", gf_argv[0]);
202 for (j = 0; j < sa; j++) printf(" %s", gf_argv[j]);
205 if (create_gf_from_argv(&gf, w, sa, gf_argv, 0) > 0) {
207 for (j = 0; j < sa; j++) printf(" %s", gf_argv[j]);
212 } else if (_gf_errno == GF_E_DEFAULT) {
213 fprintf(stderr, "Unlabeled failed method: w=%d:", w);
214 for (j = 0; j < sa; j++) fprintf(stderr, " %s", gf_argv[j]);
215 fprintf(stderr, "\n");
220 for (d = 0; d < NDIVS; d++) {
221 gf_argv[sa++] = "-d";
222 gf_argv[sa++] = divides[d];
223 /* printf("w=%d:", w);
224 for (j = 0; j < sa; j++) printf(" %s", gf_argv[j]);
227 if (create_gf_from_argv(&gf, w, sa, gf_argv, 0) > 0) {
229 for (j = 0; j < sa; j++) printf(" %s", gf_argv[j]);
234 } else if (_gf_errno == GF_E_DEFAULT) {
235 fprintf(stderr, "Unlabeled failed method: w=%d:", w);
236 for (j = 0; j < sa; j++) fprintf(stderr, " %s", gf_argv[j]);
237 fprintf(stderr, "\n");