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 * Times inline single multiplication when w = 4, 8 or 16
18 #include "gf_complete.h"
22 timer_start (double *t)
26 gettimeofday (&tv, NULL);
27 *t = (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
31 timer_split (const double *t)
36 gettimeofday (&tv, NULL);
37 cur_t = (double)tv.tv_sec + (double)tv.tv_usec * 1e-6;
43 fprintf(stderr, "Timing test failed.\n");
44 fprintf(stderr, "%s\n", s);
50 fprintf(stderr, "usage: gf_inline_time w seed #elts iterations - does timing of single multiplies\n");
51 fprintf(stderr, "\n");
52 fprintf(stderr, "Legal w are: 4, 8 or 16\n");
53 fprintf(stderr, "\n");
54 fprintf(stderr, "Use -1 for time(0) as a seed.\n");
55 fprintf(stderr, "\n");
56 if (s != NULL) fprintf(stderr, "%s\n", s);
60 int main(int argc, char **argv)
62 int w, j, i, size, iterations;
64 double timer, elapsed, dnum, num;
65 uint8_t *ra = NULL, *rb = NULL, *mult4, *mult8;
66 uint16_t *ra16 = NULL, *rb16 = NULL, *log16, *alog16;
69 if (argc != 5) usage(NULL);
70 if (sscanf(argv[1], "%d", &w) == 0) usage("Bad w\n");
71 if (w != 4 && w != 8 && w != 16) usage("Bad w\n");
72 if (sscanf(argv[2], "%ld", &t0) == 0) usage("Bad seed\n");
73 if (sscanf(argv[3], "%d", &size) == 0) usage("Bad #elts\n");
74 if (sscanf(argv[4], "%d", &iterations) == 0) usage("Bad iterations\n");
75 if (t0 == -1) t0 = time(0);
82 printf("Seed: %ld\n", t0);
84 if (w == 4 || w == 8) {
85 ra = (uint8_t *) malloc(size);
86 rb = (uint8_t *) malloc(size);
88 if (ra == NULL || rb == NULL) { perror("malloc"); exit(1); }
90 ra16 = (uint16_t *) malloc(size*2);
91 rb16 = (uint16_t *) malloc(size*2);
93 if (ra16 == NULL || rb16 == NULL) { perror("malloc"); exit(1); }
97 mult4 = gf_w4_get_mult_table(&gf);
99 printf("Couldn't get inline multiplication table.\n");
104 for (i = 0; i < iterations; i++) {
105 for (j = 0; j < size; j++) {
106 ra[j] = MOA_Random_W(w, 1);
107 rb[j] = MOA_Random_W(w, 1);
110 for (j = 0; j < size; j++) {
111 ra[j] = GF_W4_INLINE_MULTDIV(mult4, ra[j], rb[j]);
114 elapsed += timer_split(&timer);
116 printf("Inline mult: %10.6lf s Mops: %10.3lf %10.3lf Mega-ops/s\n",
117 elapsed, dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);
120 mult8 = gf_w8_get_mult_table(&gf);
122 printf("Couldn't get inline multiplication table.\n");
127 for (i = 0; i < iterations; i++) {
128 for (j = 0; j < size; j++) {
129 ra[j] = MOA_Random_W(w, 1);
130 rb[j] = MOA_Random_W(w, 1);
133 for (j = 0; j < size; j++) {
134 ra[j] = GF_W8_INLINE_MULTDIV(mult8, ra[j], rb[j]);
137 elapsed += timer_split(&timer);
139 printf("Inline mult: %10.6lf s Mops: %10.3lf %10.3lf Mega-ops/s\n",
140 elapsed, dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);
141 } else if (w == 16) {
142 log16 = gf_w16_get_log_table(&gf);
143 alog16 = gf_w16_get_mult_alog_table(&gf);
145 printf("Couldn't get inline multiplication table.\n");
150 for (i = 0; i < iterations; i++) {
151 for (j = 0; j < size; j++) {
152 ra16[j] = MOA_Random_W(w, 1);
153 rb16[j] = MOA_Random_W(w, 1);
156 for (j = 0; j < size; j++) {
157 ra16[j] = GF_W16_INLINE_MULT(log16, alog16, ra16[j], rb16[j]);
160 elapsed += timer_split(&timer);
162 printf("Inline mult: %10.6lf s Mops: %10.3lf %10.3lf Mega-ops/s\n",
163 elapsed, dnum/1024.0/1024.0, dnum/1024.0/1024.0/elapsed);