]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/gf-complete/examples/gf_example_6.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / erasure-code / jerasure / gf-complete / examples / gf_example_6.c
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_6.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_6\n");
24 exit(1);
25 }
26
27 int main(int argc, char **argv)
28 {
29 uint32_t *a, *b;
30 int i, j;
31 gf_t gf, gf_16;
32
33 if (gf_init_hard(&gf_16, 16, GF_MULT_LOG_TABLE, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT,
34 0, 0, 0, NULL, NULL) == 0) {
35 fprintf(stderr, "gf_init_hard (6) failed\n");
36 exit(1);
37 }
38
39 if (gf_init_hard(&gf, 32, GF_MULT_COMPOSITE, GF_REGION_ALTMAP, GF_DIVIDE_DEFAULT,
40 0, 2, 0, &gf_16, NULL) == 0) {
41 fprintf(stderr, "gf_init_hard (32) failed\n");
42 exit(1);
43 }
44
45 a = (uint32_t *) malloc(200);
46 b = (uint32_t *) malloc(200);
47
48 a += 3;
49 b += 3;
50
51 MOA_Seed(0);
52
53 for (i = 0; i < 30; i++) a[i] = MOA_Random_W(32, 1);
54
55 gf.multiply_region.w32(&gf, a, b, 0x12345678, 30*4, 0);
56
57 printf("a: 0x%lx b: 0x%lx\n", (unsigned long) a, (unsigned long) b);
58
59 for (i = 0; i < 30; i += 10) {
60 printf("\n");
61 printf(" ");
62 for (j = 0; j < 10; j++) printf(" %8d", i+j);
63 printf("\n");
64
65 printf("a:");
66 for (j = 0; j < 10; j++) printf(" %08x", a[i+j]);
67 printf("\n");
68
69 printf("b:");
70 for (j = 0; j < 10; j++) printf(" %08x", b[i+j]);
71 printf("\n");
72 printf("\n");
73 }
74
75 for (i = 0; i < 15; i ++) {
76 printf("Word %2d: 0x%08x * 0x12345678 = 0x%08x ", i,
77 gf.extract_word.w32(&gf, a, 30*4, i),
78 gf.extract_word.w32(&gf, b, 30*4, i));
79 printf("Word %2d: 0x%08x * 0x12345678 = 0x%08x\n", i+15,
80 gf.extract_word.w32(&gf, a, 30*4, i+15),
81 gf.extract_word.w32(&gf, b, 30*4, i+15));
82 }
83 return 0;
84 }