2 * Copyright (c) 2014, James S. Plank and Kevin Greenan
5 * Jerasure - A C/C++ Library for a Variety of Reed-Solomon and RAID-6 Erasure
8 * Revision 2.0: Galois Field backend now links to GF-Complete
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
14 * - Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * - Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
22 * - Neither the name of the University of Tennessee nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
32 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
33 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
36 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 /* Jerasure's authors:
42 Revision 2.x - 2014: James S. Plank and Kevin M. Greenan.
43 Revision 1.2 - 2008: James S. Plank, Scott Simmerman and Catherine D. Schuman.
44 Revision 1.0 - 2007: James S. Plank.
55 #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
57 static void usage(char *s)
59 fprintf(stderr, "usage: reed_sol_04 w seed - Shows reed_sol_galois_wXX_region_multby_2\n");
60 fprintf(stderr, " \n");
61 fprintf(stderr, " w must be 8, 16 or 32. Sets up an array of 4 random words in\n");
62 fprintf(stderr, " GF(2^w) and multiplies them by two. \n");
63 fprintf(stderr, " \n");
64 fprintf(stderr, "This demonstrates: reed_sol_galois_w08_region_multby_2()\n");
65 fprintf(stderr, " reed_sol_galois_w16_region_multby_2()\n");
66 fprintf(stderr, " reed_sol_galois_w32_region_multby_2()\n");
67 if (s != NULL) fprintf(stderr, "%s\n", s);
71 int main(int argc, char **argv)
74 unsigned short *xs, *ys;
75 unsigned int *xi, *yi;
81 if (argc != 3) usage(NULL);
82 if (sscanf(argv[1], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w");
83 if (sscanf(argv[2], "%d", &seed) == 0) usage("Bad seed");
85 printf("<HTML><TITLE>reed_sol_04 %d %d</title>\n", w, seed);
86 printf("<h3>reed_sol_04 %d %d</h3>\n", w, seed);
91 copy = talloc(int, 4);
92 y = (unsigned char *) a32;
93 for (i = 0; i < 4*sizeof(int); i++) y[i] = MOA_Random_W(8, 1);
94 memcpy(copy, a32, sizeof(int)*4);
97 x = (unsigned char *) copy;
98 y = (unsigned char *) a32;
99 reed_sol_galois_w08_region_multby_2((char *) a32, sizeof(int)*4);
100 for (i = 0; i < 4*sizeof(int)/sizeof(char); i++) {
101 printf("Char %2d: %3u *2 = %3u\n", i, x[i], y[i]);
103 } else if (w == 16) {
104 xs = (unsigned short *) copy;
105 ys = (unsigned short *) a32;
106 reed_sol_galois_w16_region_multby_2((char *) a32, sizeof(int)*4);
107 for (i = 0; i < 4*sizeof(int)/sizeof(short); i++) {
108 printf("Short %2d: %5u *2 = %5u\n", i, xs[i], ys[i]);
110 } else if (w == 32) {
111 xi = (unsigned int *) copy;
112 yi = (unsigned int *) a32;
113 reed_sol_galois_w16_region_multby_2((char *) a32, sizeof(int)*4);
114 for (i = 0; i < 4*sizeof(int)/sizeof(int); i++) {
115 printf("Int %2d: %10u *2 = %10u\n", i, xi[i], yi[i]);