]> git.proxmox.com Git - ceph.git/blob - ceph/src/erasure-code/jerasure/gf-complete/examples/gf_example_3.c
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / erasure-code / jerasure / gf-complete / examples / gf_example_3.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_3.c
7 *
8 * Identical to example_2 except it works in GF(2^64)
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_3\n");
24 exit(1);
25 }
26
27 int main(int argc, char **argv)
28 {
29 uint64_t a, b, c;
30 uint64_t *r1, *r2;
31 int i;
32 gf_t gf;
33
34 if (argc != 1) usage(NULL);
35
36 /* Get two random numbers in a and b */
37
38 MOA_Seed(time(0));
39 a = MOA_Random_64();
40 b = MOA_Random_64();
41
42 /* Create the proper instance of the gf_t object using defaults: */
43
44 gf_init_easy(&gf, 64);
45
46 /* And multiply a and b using the galois field: */
47
48 c = gf.multiply.w64(&gf, a, b);
49 printf("%llx * %llx = %llx\n", (long long unsigned int) a, (long long unsigned int) b, (long long unsigned int) c);
50
51 /* Divide the product by a and b */
52
53 printf("%llx / %llx = %llx\n", (long long unsigned int) c, (long long unsigned int) a, (long long unsigned int) gf.divide.w64(&gf, c, a));
54 printf("%llx / %llx = %llx\n", (long long unsigned int) c, (long long unsigned int) b, (long long unsigned int) gf.divide.w64(&gf, c, b));
55
56 r1 = (uint64_t *) malloc(32);
57 r2 = (uint64_t *) malloc(32);
58
59 r1[0] = b;
60
61 for (i = 1; i < 4; i++) r1[i] = MOA_Random_64();
62
63 gf.multiply_region.w64(&gf, r1, r2, a, 32, 0);
64
65 printf("\nmultiply_region by %llx\n\n", (long long unsigned int) a);
66 printf("R1 (the source): ");
67 for (i = 0; i < 4; i++) printf(" %016llx", (long long unsigned int) r1[i]);
68
69 printf("\nR2 (the product): ");
70 for (i = 0; i < 4; i++) printf(" %016llx", (long long unsigned int) r2[i]);
71 printf("\n");
72
73 exit(0);
74 }