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 * Parses argv to figure out the mult_type and arguments. Returns the gf.
17 #include "gf_complete.h"
19 #include "gf_method.h"
21 int create_gf_from_argv(gf_t *gf, int w, int argc, char **argv, int starting)
23 int mult_type, divide_type, region_type;
28 mult_type = GF_MULT_DEFAULT;
29 region_type = GF_REGION_DEFAULT;
30 divide_type = GF_DIVIDE_DEFAULT;
36 if (argc > starting) {
37 if (strcmp(argv[starting], "-m") == 0) {
39 if (mult_type != GF_MULT_DEFAULT) {
40 if (base != NULL) gf_free(base, 1);
41 _gf_errno = GF_E_TWOMULT;
44 if (strcmp(argv[starting], "SHIFT") == 0) {
45 mult_type = GF_MULT_SHIFT;
47 } else if (strcmp(argv[starting], "CARRY_FREE") == 0) {
48 mult_type = GF_MULT_CARRY_FREE;
50 } else if (strcmp(argv[starting], "CARRY_FREE_GK") == 0) {
51 mult_type = GF_MULT_CARRY_FREE_GK;
53 } else if (strcmp(argv[starting], "GROUP") == 0) {
54 mult_type = GF_MULT_GROUP;
55 if (argc < starting + 3) {
56 _gf_errno = GF_E_GROUPAR;
59 if (sscanf(argv[starting+1], "%d", &arg1) == 0 ||
60 sscanf(argv[starting+2], "%d", &arg2) == 0) {
61 _gf_errno = GF_E_GROUPNU;
65 } else if (strcmp(argv[starting], "BYTWO_p") == 0) {
66 mult_type = GF_MULT_BYTWO_p;
68 } else if (strcmp(argv[starting], "BYTWO_b") == 0) {
69 mult_type = GF_MULT_BYTWO_b;
71 } else if (strcmp(argv[starting], "TABLE") == 0) {
72 mult_type = GF_MULT_TABLE;
74 } else if (strcmp(argv[starting], "LOG") == 0) {
75 mult_type = GF_MULT_LOG_TABLE;
77 } else if (strcmp(argv[starting], "LOG_ZERO") == 0) {
78 mult_type = GF_MULT_LOG_ZERO;
80 } else if (strcmp(argv[starting], "LOG_ZERO_EXT") == 0) {
81 mult_type = GF_MULT_LOG_ZERO_EXT;
83 } else if (strcmp(argv[starting], "SPLIT") == 0) {
84 mult_type = GF_MULT_SPLIT_TABLE;
85 if (argc < starting + 3) {
86 _gf_errno = GF_E_SPLITAR;
89 if (sscanf(argv[starting+1], "%d", &arg1) == 0 ||
90 sscanf(argv[starting+2], "%d", &arg2) == 0) {
91 _gf_errno = GF_E_SPLITNU;
95 } else if (strcmp(argv[starting], "COMPOSITE") == 0) {
96 mult_type = GF_MULT_COMPOSITE;
97 if (argc < starting + 2) { _gf_errno = GF_E_FEWARGS; return 0; }
98 if (sscanf(argv[starting+1], "%d", &arg1) == 0) {
99 _gf_errno = GF_E_COMP_A2;
103 base = (gf_t *) malloc(sizeof(gf_t));
104 starting = create_gf_from_argv(base, w/arg1, argc, argv, starting);
110 _gf_errno = GF_E_UNKNOWN;
113 } else if (strcmp(argv[starting], "-r") == 0) {
115 if (strcmp(argv[starting], "DOUBLE") == 0) {
116 region_type |= GF_REGION_DOUBLE_TABLE;
118 } else if (strcmp(argv[starting], "QUAD") == 0) {
119 region_type |= GF_REGION_QUAD_TABLE;
121 } else if (strcmp(argv[starting], "LAZY") == 0) {
122 region_type |= GF_REGION_LAZY;
124 } else if (strcmp(argv[starting], "SIMD") == 0) {
125 region_type |= GF_REGION_SIMD;
127 } else if (strcmp(argv[starting], "NOSIMD") == 0) {
128 region_type |= GF_REGION_NOSIMD;
130 } else if (strcmp(argv[starting], "SSE") == 0) {
131 region_type |= GF_REGION_SIMD;
133 } else if (strcmp(argv[starting], "NOSSE") == 0) {
134 region_type |= GF_REGION_NOSIMD;
136 } else if (strcmp(argv[starting], "CAUCHY") == 0) {
137 region_type |= GF_REGION_CAUCHY;
139 } else if (strcmp(argv[starting], "ALTMAP") == 0) {
140 region_type |= GF_REGION_ALTMAP;
143 if (base != NULL) gf_free(base, 1);
144 _gf_errno = GF_E_UNK_REG;
147 } else if (strcmp(argv[starting], "-p") == 0) {
149 if (sscanf(argv[starting], "%llx", (long long unsigned int *)(&prim_poly)) == 0) {
150 if (base != NULL) gf_free(base, 1);
151 _gf_errno = GF_E_POLYSPC;
155 } else if (strcmp(argv[starting], "-d") == 0) {
157 if (divide_type != GF_DIVIDE_DEFAULT) {
158 if (base != NULL) gf_free(base, 1);
159 _gf_errno = GF_E_TWO_DIV;
161 } else if (strcmp(argv[starting], "EUCLID") == 0) {
162 divide_type = GF_DIVIDE_EUCLID;
164 } else if (strcmp(argv[starting], "MATRIX") == 0) {
165 divide_type = GF_DIVIDE_MATRIX;
168 _gf_errno = GF_E_UNK_DIV;
171 } else if (strcmp(argv[starting], "-") == 0) {
173 printf("Scratch size: %d\n", gf_scratch_size(w,
174 mult_type, region_type, divide_type, arg1, arg2));
176 if (gf_init_hard(gf, w, mult_type, region_type, divide_type,
177 prim_poly, arg1, arg2, base, NULL) == 0) {
178 if (base != NULL) gf_free(base, 1);
183 if (base != NULL) gf_free(base, 1);
184 _gf_errno = GF_E_UNKFLAG;
188 if (base != NULL) gf_free(base, 1);
189 _gf_errno = GF_E_FEWARGS;