From c9851639f4830e516e48797832ec30fe82a43e28 Mon Sep 17 00:00:00 2001 From: roentgen Date: Tue, 13 Nov 2018 23:24:39 +0900 Subject: [PATCH 1/6] make them thread-safe --- Examples/cauchy_01.c | 10 ++- Examples/cauchy_02.c | 16 ++-- Examples/cauchy_03.c | 18 ++-- Examples/cauchy_04.c | 16 ++-- Examples/decoder.c | 17 ++-- Examples/encoder.c | 25 +++--- Examples/jerasure_01.c | 6 +- Examples/jerasure_02.c | 7 +- Examples/jerasure_03.c | 10 ++- Examples/jerasure_04.c | 7 +- Examples/jerasure_05.c | 13 +-- Examples/jerasure_06.c | 11 +-- Examples/jerasure_07.c | 13 +-- Examples/jerasure_08.c | 13 +-- Examples/liberation_01.c | 5 +- Examples/reed_sol_01.c | 7 +- Examples/reed_sol_02.c | 7 +- Examples/reed_sol_03.c | 7 +- Examples/reed_sol_04.c | 7 +- Examples/reed_sol_test_gf.c | 9 +- Examples/reed_sol_time_gf.c | 9 +- include/cauchy.h | 10 +-- include/galois.h | 38 +++++--- include/jerasure.h | 32 +++---- include/reed_sol.h | 16 ++-- src/cauchy.c | 36 ++++---- src/galois.c | 170 ++++++++++++++++++++---------------- src/jerasure.c | 98 +++++++++++---------- src/reed_sol.c | 55 ++++++------ 29 files changed, 376 insertions(+), 312 deletions(-) diff --git a/Examples/cauchy_01.c b/Examples/cauchy_01.c index 65419a0..1eddd0d 100644 --- a/Examples/cauchy_01.c +++ b/Examples/cauchy_01.c @@ -48,6 +48,7 @@ #include #include #include +#include "galois.h" /* gf2_t */ #include "cauchy.h" #include "jerasure.h" #include "reed_sol.h" @@ -74,6 +75,7 @@ int main(int argc, char **argv) int n; int i, no, w; int *bitmatrix; + static gf2_t g; if (argc != 3) usage(NULL); if (sscanf(argv[1], "0x%x", &n) == 0) { @@ -86,7 +88,7 @@ int main(int argc, char **argv) if (n >= (1 << w)) usage("Bad n/w combination (n not between 0 and 2^w-1)\n"); } - bitmatrix = jerasure_matrix_to_bitmatrix(1, 1, w, &n); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, 1, 1, w, &n); printf("cauchy_01 %u %d\n", w, n); printf("

cauchy_01 %u %d

\n", w, n); printf("
\n");
@@ -100,13 +102,13 @@ int main(int argc, char **argv)
 
   no = 0;
   for (i = 0; i < w*w; i++) no += bitmatrix[i];
-  if (no != cauchy_n_ones(n, w)) { 
+  if (no != cauchy_n_ones(&g, n, w)) { 
     fprintf(stderr, "Jerasure error: # ones in the bitmatrix (%d) doesn't match cauchy_n_ones() (%d).\n",
-       no, cauchy_n_ones(n, w));
+            no, cauchy_n_ones(&g, n, w));
     exit(1);
   }
 
-  printf("# Ones: %d\n", cauchy_n_ones(n, w));
+  printf("# Ones: %d\n", cauchy_n_ones(&g, n, w));
 
   return 0;
 }
diff --git a/Examples/cauchy_02.c b/Examples/cauchy_02.c
index 45c78ab..47e52cc 100644
--- a/Examples/cauchy_02.c
+++ b/Examples/cauchy_02.c
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include "jerasure.h"
+#include "galois.h"
 #include "cauchy.h"
 
 #define talloc(type, num) (type *) malloc(sizeof(type)*(num))
@@ -120,6 +121,7 @@ int main(int argc, char **argv)
   int *erasures, *erased;
   double mstats[3], sstats[3];
   uint32_t seed;
+  static gf2_t g;
   
   if (argc != 5) usage(NULL);
   if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k");
@@ -128,7 +130,7 @@ int main(int argc, char **argv)
   if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed");
   if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big");
 
-  matrix = cauchy_original_coding_matrix(k, m, w);
+  matrix = cauchy_original_coding_matrix(&g, k, m, w);
   if (matrix == NULL) {
     usage("couldn't make coding matrix");
   }
@@ -159,11 +161,11 @@ int main(int argc, char **argv)
   jerasure_print_matrix(matrix, m, k, w);
   printf("
\n"); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); no = 0; for (i = 0; i < k*m; i++) { - no += cauchy_n_ones(matrix[i], w); + no += cauchy_n_ones(&g, matrix[i], w); } printf("The bitmatrix, which has %d one%s:

\n", no, (no == 1) ? "" : "s");
@@ -191,11 +193,11 @@ int main(int argc, char **argv)
     ccopy[i] = talloc(char, sizeof(long)*w);
   }
 
-  jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
+  jerasure_bitmatrix_encode(&g, k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
   jerasure_get_stats(mstats);
 
   schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
-  jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
+  jerasure_schedule_encode(&g, k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
   jerasure_get_stats(sstats);
 
   printf("

Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.
\n", mstats[0]); @@ -234,7 +236,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("


\n"); - jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); + jerasure_bitmatrix_decode(&g, k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(mstats); printf("

Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.
\n", mstats[0]); @@ -250,7 +252,7 @@ int main(int argc, char **argv) bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); } - jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); + jerasure_schedule_decode_lazy(&g, k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); jerasure_get_stats(sstats); printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.
\n", sstats[0]); diff --git a/Examples/cauchy_03.c b/Examples/cauchy_03.c index e246e77..3868423 100644 --- a/Examples/cauchy_03.c +++ b/Examples/cauchy_03.c @@ -50,6 +50,7 @@ #include #include #include "jerasure.h" +#include "galois.h" #include "cauchy.h" #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) @@ -125,6 +126,7 @@ int main(int argc, char **argv) double mstats[3], sstats[3]; uint32_t seed; int *X, *Y; + static gf2_t g; if (argc != 5) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -138,7 +140,7 @@ int main(int argc, char **argv) for (i = 0; i < m; i++) X[i] = i; for (i = 0; i < k; i++) Y[i] = m+i; - matrix = cauchy_xy_coding_matrix(k, m, w, X, Y); + matrix = cauchy_xy_coding_matrix(&g, k, m, w, X, Y); if (matrix == NULL) { usage("couldn't make coding matrix"); } @@ -167,7 +169,7 @@ int main(int argc, char **argv) jerasure_print_matrix(matrix, m, k, w); printf("

\n"); - cauchy_improve_coding_matrix(k, m, w, matrix); + cauchy_improve_coding_matrix(&g, k, m, w, matrix); printf("
\n"); printf("Here is the matrix improved with cauchy_improve_coding_matrix().\n"); @@ -176,11 +178,11 @@ int main(int argc, char **argv) jerasure_print_matrix(matrix, m, k, w); printf("\n"); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); no = 0; for (i = 0; i < k*m; i++) { - no += cauchy_n_ones(matrix[i], w); + no += cauchy_n_ones(&g, matrix[i], w); } printf("The bitmatrix, which has %d one%s:

\n", no, (no == 1) ? "" : "s");
@@ -209,11 +211,11 @@ int main(int argc, char **argv)
     ccopy[i] = talloc(char, sizeof(long)*w);
   }
 
-  jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
+  jerasure_bitmatrix_encode(&g, k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
   jerasure_get_stats(mstats);
 
   schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
-  jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
+  jerasure_schedule_encode(&g, k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
   jerasure_get_stats(sstats);
 
   printf("

Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.
\n", mstats[0]); @@ -252,7 +254,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("


\n"); - jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); + jerasure_bitmatrix_decode(&g, k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(mstats); printf("

Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.
\n", mstats[0]); @@ -268,7 +270,7 @@ int main(int argc, char **argv) bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); } - jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); + jerasure_schedule_decode_lazy(&g, k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); jerasure_get_stats(sstats); printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.
\n", sstats[0]); diff --git a/Examples/cauchy_04.c b/Examples/cauchy_04.c index f61c614..2ff9490 100644 --- a/Examples/cauchy_04.c +++ b/Examples/cauchy_04.c @@ -50,6 +50,7 @@ #include #include #include "jerasure.h" +#include "galois.h" #include "cauchy.h" #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) @@ -121,6 +122,7 @@ int main(int argc, char **argv) int *erasures, *erased; double mstats[3], sstats[3]; uint32_t seed; + static gf2_t g; if (argc != 5) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -129,7 +131,7 @@ int main(int argc, char **argv) if (sscanf(argv[4], "%d", &seed) == 0) usage("Bad seed"); if (w < 30 && (k+m) > (1 << w)) usage("k + m is too big"); - matrix = cauchy_good_general_coding_matrix(k, m, w); + matrix = cauchy_good_general_coding_matrix(&g, k, m, w); if (matrix == NULL) { usage("couldn't make coding matrix"); } @@ -158,11 +160,11 @@ int main(int argc, char **argv) jerasure_print_matrix(matrix, m, k, w); printf("

\n"); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); no = 0; for (i = 0; i < k*m; i++) { - no += cauchy_n_ones(matrix[i], w); + no += cauchy_n_ones(&g, matrix[i], w); } printf("The bitmatrix, which has %d one%s:

\n", no, (no == 1) ? "" : "s");
@@ -191,11 +193,11 @@ int main(int argc, char **argv)
     ccopy[i] = talloc(char, sizeof(long)*w);
   }
 
-  jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
+  jerasure_bitmatrix_encode(&g, k, m, w, bitmatrix, data, coding, w*sizeof(long), sizeof(long));
   jerasure_get_stats(mstats);
 
   schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix);
-  jerasure_schedule_encode(k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
+  jerasure_schedule_encode(&g, k, m, w, schedule, data, ccopy, w*sizeof(long), sizeof(long));
   jerasure_get_stats(sstats);
 
   printf("

Encoding with jerasure_bitmatrix_encode() - Bytes XOR'd: %.0lf.
\n", mstats[0]); @@ -234,7 +236,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("


\n"); - jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); + jerasure_bitmatrix_decode(&g, k, m, w, bitmatrix, 0, erasures, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(mstats); printf("

Decoded with jerasure_bitmatrix_decode - Bytes XOR'd: %.0lf.
\n", mstats[0]); @@ -250,7 +252,7 @@ int main(int argc, char **argv) bzero((erasures[i] < k) ? data[erasures[i]] : coding[erasures[i]-k], sizeof(long)*w); } - jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); + jerasure_schedule_decode_lazy(&g, k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); jerasure_get_stats(sstats); printf("jerasure_schedule_decode_lazy - Bytes XOR'd: %.0lf.
\n", sstats[0]); diff --git a/Examples/decoder.c b/Examples/decoder.c index 229dccc..4b3da39 100644 --- a/Examples/decoder.c +++ b/Examples/decoder.c @@ -123,6 +123,7 @@ int main (int argc, char **argv) { double tsec; double totalsec; + static gf2_t g; signal(SIGQUIT, ctrl_bs_handler); @@ -225,18 +226,18 @@ int main (int argc, char **argv) { case No_Coding: break; case Reed_Sol_Van: - matrix = reed_sol_vandermonde_coding_matrix(k, m, w); + matrix = reed_sol_vandermonde_coding_matrix(&g, k, m, w); break; case Reed_Sol_R6_Op: - matrix = reed_sol_r6_coding_matrix(k, w); + matrix = reed_sol_r6_coding_matrix(&g, k, w); break; case Cauchy_Orig: - matrix = cauchy_original_coding_matrix(k, m, w); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + matrix = cauchy_original_coding_matrix(&g, k, m, w); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); break; case Cauchy_Good: - matrix = cauchy_good_general_coding_matrix(k, m, w); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + matrix = cauchy_good_general_coding_matrix(&g, k, m, w); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); break; case Liberation: bitmatrix = liberation_coding_bitmatrix(k, w); @@ -319,10 +320,10 @@ int main (int argc, char **argv) { /* Choose proper decoding method */ if (tech == Reed_Sol_Van || tech == Reed_Sol_R6_Op) { - i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, blocksize); + i = jerasure_matrix_decode(&g, k, m, w, matrix, 1, erasures, data, coding, blocksize); } else if (tech == Cauchy_Orig || tech == Cauchy_Good || tech == Liberation || tech == Blaum_Roth || tech == Liber8tion) { - i = jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, blocksize, packetsize, 1); + i = jerasure_schedule_decode_lazy(&g, k, m, w, bitmatrix, erasures, data, coding, blocksize, packetsize, 1); } else { fprintf(stderr, "Not a valid coding technique.\n"); diff --git a/Examples/encoder.c b/Examples/encoder.c index 367686e..f0c9d48 100644 --- a/Examples/encoder.c +++ b/Examples/encoder.c @@ -134,6 +134,7 @@ int main (int argc, char **argv) { /* Find buffersize */ int up, down; + static gf2_t g; signal(SIGQUIT, ctrl_bs_handler); @@ -438,18 +439,18 @@ int main (int argc, char **argv) { case No_Coding: break; case Reed_Sol_Van: - matrix = reed_sol_vandermonde_coding_matrix(k, m, w); + matrix = reed_sol_vandermonde_coding_matrix(&g, k, m, w); break; case Reed_Sol_R6_Op: break; case Cauchy_Orig: - matrix = cauchy_original_coding_matrix(k, m, w); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + matrix = cauchy_original_coding_matrix(&g, k, m, w); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); break; case Cauchy_Good: - matrix = cauchy_good_general_coding_matrix(k, m, w); - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + matrix = cauchy_good_general_coding_matrix(&g, k, m, w); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); schedule = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); break; case Liberation: @@ -507,25 +508,25 @@ int main (int argc, char **argv) { case No_Coding: break; case Reed_Sol_Van: - jerasure_matrix_encode(k, m, w, matrix, data, coding, blocksize); + jerasure_matrix_encode(&g, k, m, w, matrix, data, coding, blocksize); break; case Reed_Sol_R6_Op: - reed_sol_r6_encode(k, w, data, coding, blocksize); + reed_sol_r6_encode(&g, k, w, data, coding, blocksize); break; case Cauchy_Orig: - jerasure_schedule_encode(k, m, w, schedule, data, coding, blocksize, packetsize); + jerasure_schedule_encode(&g, k, m, w, schedule, data, coding, blocksize, packetsize); break; case Cauchy_Good: - jerasure_schedule_encode(k, m, w, schedule, data, coding, blocksize, packetsize); + jerasure_schedule_encode(&g, k, m, w, schedule, data, coding, blocksize, packetsize); break; case Liberation: - jerasure_schedule_encode(k, m, w, schedule, data, coding, blocksize, packetsize); + jerasure_schedule_encode(&g, k, m, w, schedule, data, coding, blocksize, packetsize); break; case Blaum_Roth: - jerasure_schedule_encode(k, m, w, schedule, data, coding, blocksize, packetsize); + jerasure_schedule_encode(&g, k, m, w, schedule, data, coding, blocksize, packetsize); break; case Liber8tion: - jerasure_schedule_encode(k, m, w, schedule, data, coding, blocksize, packetsize); + jerasure_schedule_encode(&g, k, m, w, schedule, data, coding, blocksize, packetsize); break; case RDP: case EVENODD: diff --git a/Examples/jerasure_01.c b/Examples/jerasure_01.c index 20df225..ab448c8 100644 --- a/Examples/jerasure_01.c +++ b/Examples/jerasure_01.c @@ -73,11 +73,13 @@ int main(int argc, char **argv) matrix = talloc(int, r*c); n = 1; + gf2_t* g = galois_init_empty(); for (i = 0; i < r*c; i++) { matrix[i] = n; - n = galois_single_multiply(n, 2, w); + n = galois_single_multiply(g, n, 2, w); } - + galois_destroy(g); + printf("jerasure_01"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); printf("\n"); diff --git a/Examples/jerasure_02.c b/Examples/jerasure_02.c index eb952ae..c8df0c7 100644 --- a/Examples/jerasure_02.c +++ b/Examples/jerasure_02.c @@ -71,14 +71,17 @@ int main(int argc, char **argv) if (sscanf(argv[3], "%d", &w) == 0 || w <= 0) usage("Bad w"); matrix = talloc(int, r*c); + gf2_t* g = galois_init_empty(); n = 1; for (i = 0; i < r*c; i++) { matrix[i] = n; - n = galois_single_multiply(n, 2, w); + n = galois_single_multiply(g, n, 2, w); } - bitmatrix = jerasure_matrix_to_bitmatrix(c, r, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(g, c, r, w, matrix); + + galois_destroy(g); printf("jerasure_02"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); diff --git a/Examples/jerasure_03.c b/Examples/jerasure_03.c index 24bd15c..a2f8349 100644 --- a/Examples/jerasure_03.c +++ b/Examples/jerasure_03.c @@ -85,10 +85,12 @@ int main(int argc, char **argv) matrix_copy = talloc(int, k*k); inverse = talloc(int, k*k); + static gf2_t g; + for (i = 0; i < k; i++) { for (j = 0; j < k; j++) { n = i ^ ((1 << w)-1-j); - matrix[i*k+j] = (n == 0) ? 0 : galois_single_divide(1, n, w); + matrix[i*k+j] = (n == 0) ? 0 : galois_single_divide(&g, 1, n, w); } } @@ -103,14 +105,14 @@ int main(int argc, char **argv) printf("The Cauchy Matrix:\n"); jerasure_print_matrix(matrix, k, k, w); memcpy(matrix_copy, matrix, sizeof(int)*k*k); - i = jerasure_invertible_matrix(matrix_copy, k, w); + i = jerasure_invertible_matrix(&g, matrix_copy, k, w); printf("\nInvertible: %s\n", (i == 1) ? "Yes" : "No"); if (i == 1) { printf("\nInverse:\n"); memcpy(matrix_copy, matrix, sizeof(int)*k*k); - i = jerasure_invert_matrix(matrix_copy, inverse, k, w); + i = jerasure_invert_matrix(&g, matrix_copy, inverse, k, w); jerasure_print_matrix(inverse, k, k, w); - identity = jerasure_matrix_multiply(inverse, matrix, k, k, k, k, w); + identity = jerasure_matrix_multiply(&g, inverse, matrix, k, k, k, k, w); printf("\nInverse times matrix (should be identity):\n"); jerasure_print_matrix(identity, k, k, w); } diff --git a/Examples/jerasure_04.c b/Examples/jerasure_04.c index 21410a5..81efc44 100644 --- a/Examples/jerasure_04.c +++ b/Examples/jerasure_04.c @@ -73,6 +73,7 @@ int main(int argc, char **argv) int *bitmatrix_copy; int *inverse; int *identity; + static gf2_t g; if (argc != 3) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -86,10 +87,10 @@ int main(int argc, char **argv) for (i = 0; i < k; i++) { for (j = 0; j < k; j++) { n = i ^ ((1 << w)-1-j); - matrix[i*k+j] = (n == 0) ? 0 : galois_single_divide(1, n, w); + matrix[i*k+j] = (n == 0) ? 0 : galois_single_divide(&g, 1, n, w); } } - bitmatrix = jerasure_matrix_to_bitmatrix(k, k, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, k, w, matrix); printf("<HTML><TITLE>jerasure_04"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); @@ -109,7 +110,7 @@ int main(int argc, char **argv) memcpy(bitmatrix_copy, bitmatrix, sizeof(int)*k*w*k*w); i = jerasure_invert_bitmatrix(bitmatrix_copy, inverse, k*w); jerasure_print_bitmatrix(inverse, k*w, k*w, w); - identity = jerasure_matrix_multiply(inverse, bitmatrix, k*w, k*w, k*w, k*w, 2); + identity = jerasure_matrix_multiply(&g, inverse, bitmatrix, k*w, k*w, k*w, k*w, 2); printf("\nInverse times matrix (should be identity):\n"); jerasure_print_bitmatrix(identity, k*w, k*w, w); } diff --git a/Examples/jerasure_05.c b/Examples/jerasure_05.c index 20b059b..9e42a16 100644 --- a/Examples/jerasure_05.c +++ b/Examples/jerasure_05.c @@ -77,7 +77,7 @@ static void print_data_and_coding(int k, int m, int w, int size, { int i, j, x; int n, sp; - + if(k > m) n = k; else n = m; sp = size * 2 + size/(w/8) + 8; @@ -118,6 +118,7 @@ int main(int argc, char **argv) int *erasures, *erased; int *decoding_matrix, *dm_ids; uint32_t seed; + static gf2_t g; if (argc != 6) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -131,7 +132,7 @@ int main(int argc, char **argv) matrix = talloc(int, m*k); for (i = 0; i < m; i++) { for (j = 0; j < k; j++) { - matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w); + matrix[i*k+j] = galois_single_divide(&g, 1, i ^ (m + j), w); } } @@ -159,7 +160,7 @@ int main(int argc, char **argv) coding[i] = talloc(char, size); } - jerasure_matrix_encode(k, m, w, matrix, data, coding, size); + jerasure_matrix_encode(&g, k, m, w, matrix, data, coding, size); printf("Encoding Complete:\n\n"); print_data_and_coding(k, m, w, size, data, coding); @@ -181,7 +182,7 @@ int main(int argc, char **argv) printf("Erased %d random devices:\n\n", m); print_data_and_coding(k, m, w, size, data, coding); - i = jerasure_matrix_decode(k, m, w, matrix, 0, erasures, data, coding, size); + i = jerasure_matrix_decode(&g, k, m, w, matrix, 0, erasures, data, coding, size); printf("State of the system after decoding:\n\n"); print_data_and_coding(k, m, w, size, data, coding); @@ -192,7 +193,7 @@ int main(int argc, char **argv) for (i = 0; i < m; i++) erased[i] = 1; for (; i < k+m; i++) erased[i] = 0; - jerasure_make_decoding_matrix(k, m, w, matrix, erased, decoding_matrix, dm_ids); + jerasure_make_decoding_matrix(&g, k, m, w, matrix, erased, decoding_matrix, dm_ids); printf("Suppose we erase the first %d devices. Here is the decoding matrix:\n\n", m); jerasure_print_matrix(decoding_matrix, k, k, w); @@ -201,7 +202,7 @@ int main(int argc, char **argv) jerasure_print_matrix(dm_ids, 1, k, w); bzero(data[0], size); - jerasure_matrix_dotprod(k, w, decoding_matrix, dm_ids, 0, data, coding, size); + jerasure_matrix_dotprod(&g, k, w, decoding_matrix, dm_ids, 0, data, coding, size); printf("\nAfter calling jerasure_matrix_dotprod, we calculate the value of device #0 to be:\n\n"); printf("D0 :"); diff --git a/Examples/jerasure_06.c b/Examples/jerasure_06.c index 9af9ca2..755a499 100644 --- a/Examples/jerasure_06.c +++ b/Examples/jerasure_06.c @@ -107,6 +107,7 @@ int main(int argc, char **argv) int *erasures, *erased; int *decoding_matrix, *dm_ids; uint32_t seed; + static gf2_t g; if (argc != 6) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -121,10 +122,10 @@ int main(int argc, char **argv) matrix = talloc(int, m*k); for (i = 0; i < m; i++) { for (j = 0; j < k; j++) { - matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w); + matrix[i*k+j] = galois_single_divide(&g, 1, i ^ (m + j), w); } } - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); printf("<HTML><TITLE>jerasure_06"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); @@ -149,7 +150,7 @@ int main(int argc, char **argv) coding[i] = talloc(char, psize*w); } - jerasure_bitmatrix_encode(k, m, w, bitmatrix, data, coding, w*psize, psize); + jerasure_bitmatrix_encode(&g, k, m, w, bitmatrix, data, coding, w*psize, psize); printf("Encoding Complete - Here is the state of the system\n\n"); printf("<p>\n"); @@ -183,7 +184,7 @@ int main(int argc, char **argv) print_array(coding, m, psize*w, psize, "C"); printf("<hr>\n"); - i = jerasure_bitmatrix_decode(k, m, w, bitmatrix, 0, erasures, data, coding, + i = jerasure_bitmatrix_decode(&g, k, m, w, bitmatrix, 0, erasures, data, coding, w*psize, psize); printf("Here is the state of the system after decoding:\n\n"); @@ -220,7 +221,7 @@ int main(int argc, char **argv) printf("<hr>\n"); for (i = 0; i < x; i++) { - jerasure_bitmatrix_dotprod(k, w, decoding_matrix+i*(k*w*w), dm_ids, i, data, coding, w*psize, psize); + jerasure_bitmatrix_dotprod(&g, k, w, decoding_matrix+i*(k*w*w), dm_ids, i, data, coding, w*psize, psize); } printf("Here is the state of the system after calling <b>jerasure_bitmatrix_dotprod()</b> %d time%s with the decoding matrix:\n\n", x, (x == 1) ? "" : "s"); diff --git a/Examples/jerasure_07.c b/Examples/jerasure_07.c index cc57163..199eef9 100644 --- a/Examples/jerasure_07.c +++ b/Examples/jerasure_07.c @@ -108,6 +108,7 @@ int main(int argc, char **argv) int *erasures, *erased; double stats[3]; uint32_t seed; + static gf2_t g; if (argc != 5) usage("Wrong number of arguments"); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -119,10 +120,10 @@ int main(int argc, char **argv) matrix = talloc(int, m*k); for (i = 0; i < m; i++) { for (j = 0; j < k; j++) { - matrix[i*k+j] = galois_single_divide(1, i ^ (m + j), w); + matrix[i*k+j] = galois_single_divide(&g, 1, i ^ (m + j), w); } } - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); printf("<HTML><TITLE>jerasure_07"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); @@ -151,7 +152,7 @@ int main(int argc, char **argv) coding[i] = talloc(char, sizeof(long)*w); } - jerasure_schedule_encode(k, m, w, dumb, data, coding, w*sizeof(long), sizeof(long)); + jerasure_schedule_encode(&g, k, m, w, dumb, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(stats); printf("Dumb Encoding Complete: - %.0lf XOR'd bytes. State of the system:\n\n", stats[0]); printf("<p>\n"); @@ -160,7 +161,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("<hr>\n"); - jerasure_schedule_encode(k, m, w, smart, data, coding, w*sizeof(long), sizeof(long)); + jerasure_schedule_encode(&g, k, m, w, smart, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(stats); printf("Smart Encoding Complete: - %.0lf XOR'd bytes\n\n", stats[0]); printf("<p>\n"); @@ -189,7 +190,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("<hr>\n"); - jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); + jerasure_schedule_decode_lazy(&g, k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); jerasure_get_stats(stats); printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]); @@ -211,7 +212,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("<hr>\n"); - jerasure_do_scheduled_operations(ptrs, smart, sizeof(long)); + jerasure_do_scheduled_operations(&g, ptrs, smart, sizeof(long)); printf("And using <b>jerasure_do_scheduled_operations()</b>: %.0lf XOR'd bytes\n\n", stats[0]); printf("<p>\n"); print_array(data, k, sizeof(long)*w, sizeof(long), "D"); diff --git a/Examples/jerasure_08.c b/Examples/jerasure_08.c index 0eb5ace..3450661 100644 --- a/Examples/jerasure_08.c +++ b/Examples/jerasure_08.c @@ -111,6 +111,7 @@ int main(int argc, char **argv) int *erasures, *erased; double stats[3]; uint32_t seed; + static gf2_t g; if (argc != 4) usage("Wrong number of arguments"); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -126,9 +127,9 @@ int main(int argc, char **argv) i = 1; for (j = 0; j < k; j++) { matrix[k+j] = i; - i = galois_single_multiply(i, 2, w); + i = galois_single_multiply(&g, i, 2, w); } - bitmatrix = jerasure_matrix_to_bitmatrix(k, m, w, matrix); + bitmatrix = jerasure_matrix_to_bitmatrix(&g, k, m, w, matrix); smart = jerasure_smart_bitmatrix_to_schedule(k, m, w, bitmatrix); cache = jerasure_generate_schedule_cache(k, m, w, bitmatrix, 1); @@ -144,7 +145,7 @@ int main(int argc, char **argv) coding[i] = talloc(char, sizeof(long)*w); } - jerasure_schedule_encode(k, m, w, smart, data, coding, w*sizeof(long), sizeof(long)); + jerasure_schedule_encode(&g, k, m, w, smart, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(stats); printf("<HTML><TITLE>jerasure_08"); @@ -168,7 +169,7 @@ int main(int argc, char **argv) erasures[2] = -1; for (j = 0; j < m; j++) bzero(coding[j], sizeof(long)*w); - jerasure_schedule_decode_cache(k, m, w, cache, erasures, data, coding, w*sizeof(long), sizeof(long)); + jerasure_schedule_decode_cache(&g, k, m, w, cache, erasures, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(stats); printf("Encoding Using the Schedule Cache: - %.0lf XOR'd bytes\n\n", stats[0]); printf("<p>\n"); @@ -196,7 +197,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("<hr>\n"); - jerasure_schedule_decode_cache(k, m, w, cache, erasures, data, coding, w*sizeof(long), sizeof(long)); + jerasure_schedule_decode_cache(&g, k, m, w, cache, erasures, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(stats); printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]); @@ -214,7 +215,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("<hr>\n"); - jerasure_do_parity(k, data, coding[0], sizeof(long)*w); + jerasure_do_parity(&g, k, data, coding[0], sizeof(long)*w); printf("State of the system after using\n"); printf("<b>jerasure_do_parity()</b> to re-encode it:\n\n"); printf("<p>\n"); diff --git a/Examples/liberation_01.c b/Examples/liberation_01.c index d3b4392..2494a57 100644 --- a/Examples/liberation_01.c +++ b/Examples/liberation_01.c @@ -109,6 +109,7 @@ int main(int argc, char **argv) int *erasures, *erased; double stats[3]; uint32_t seed; + static gf2_t g; if (argc != 4) usage("Wrong number of arguments"); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -149,7 +150,7 @@ int main(int argc, char **argv) coding[i] = talloc(char, sizeof(long)*w); } - jerasure_schedule_encode(k, m, w, dumb, data, coding, w*sizeof(long), sizeof(long)); + jerasure_schedule_encode(&g, k, m, w, dumb, data, coding, w*sizeof(long), sizeof(long)); jerasure_get_stats(stats); printf("Smart Encoding Complete: - %.0lf XOR'd bytes. State of the system:\n\n", stats[0]); printf("<p>\n"); @@ -178,7 +179,7 @@ int main(int argc, char **argv) print_array(coding, m, sizeof(long)*w, sizeof(long), "C"); printf("<hr>\n"); - jerasure_schedule_decode_lazy(k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); + jerasure_schedule_decode_lazy(&g, k, m, w, bitmatrix, erasures, data, coding, w*sizeof(long), sizeof(long), 1); jerasure_get_stats(stats); printf("State of the system after decoding: %.0lf XOR'd bytes\n\n", stats[0]); diff --git a/Examples/reed_sol_01.c b/Examples/reed_sol_01.c index da46aeb..cfed7aa 100644 --- a/Examples/reed_sol_01.c +++ b/Examples/reed_sol_01.c @@ -116,6 +116,7 @@ int main(int argc, char **argv) unsigned char uc; int *erasures, *erased; uint32_t seed; + static gf2_t g; if (argc != 5) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -124,7 +125,7 @@ int main(int argc, char **argv) if (sscanf(argv[4], "%u", &seed) == 0) usage("Bad seed"); if (w <= 16 && k + m > (1 << w)) usage("k + m is too big"); - matrix = reed_sol_vandermonde_coding_matrix(k, m, w); + matrix = reed_sol_vandermonde_coding_matrix(&g, k, m, w); printf("<HTML><TITLE>reed_sol_01 %d %d %d %d\n", k, m, w, seed); printf("

reed_sol_01 %d %d %d %d

\n", k, m, w, seed); @@ -153,7 +154,7 @@ int main(int argc, char **argv) ccopy[i] = talloc(char, sizeof(long)); } - jerasure_matrix_encode(k, m, w, matrix, data, coding, sizeof(long)); + jerasure_matrix_encode(&g, k, m, w, matrix, data, coding, sizeof(long)); for (i = 0; i < m; i++) { memcpy(ccopy[i], coding[i], sizeof(long)); @@ -179,7 +180,7 @@ int main(int argc, char **argv) printf("Erased %d random devices:\n\n", m); print_data_and_coding(k, m, w, sizeof(long), data, coding); - i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, sizeof(long)); + i = jerasure_matrix_decode(&g, k, m, w, matrix, 1, erasures, data, coding, sizeof(long)); printf("State of the system after decoding:\n\n"); print_data_and_coding(k, m, w, sizeof(long), data, coding); diff --git a/Examples/reed_sol_02.c b/Examples/reed_sol_02.c index 6beb4f6..bf1bb69 100644 --- a/Examples/reed_sol_02.c +++ b/Examples/reed_sol_02.c @@ -73,6 +73,7 @@ int main(int argc, char **argv) { int k, w, m; int *matrix; + static gf2_t g; if (argc != 4) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -80,7 +81,7 @@ int main(int argc, char **argv) if (sscanf(argv[3], "%d", &w) == 0 || w <= 0 || w > 32) usage("Bad w"); if (w <= 30 && k + m > (1 << w)) usage("k + m is too big"); - matrix = reed_sol_extended_vandermonde_matrix(k+m, k, w); + matrix = reed_sol_extended_vandermonde_matrix(&g, k+m, k, w); printf("reed_sol_02 %d %d %d\n", k, m, w); printf("

reed_sol_02 %d %d %d

\n", k, m, w); @@ -89,12 +90,12 @@ int main(int argc, char **argv) jerasure_print_matrix(matrix, k+m, k, w); printf("\n"); - matrix = reed_sol_big_vandermonde_distribution_matrix(k+m, k, w); + matrix = reed_sol_big_vandermonde_distribution_matrix(&g, k+m, k, w); printf("Vandermonde Generator Matrix (G^T):\n\n"); jerasure_print_matrix(matrix, k+m, k, w); printf("\n"); - matrix = reed_sol_vandermonde_coding_matrix(k, m, w); + matrix = reed_sol_vandermonde_coding_matrix(&g, k, m, w); printf("Vandermonde Coding Matrix:\n\n"); jerasure_print_matrix(matrix, m, k, w); printf("\n"); diff --git a/Examples/reed_sol_03.c b/Examples/reed_sol_03.c index 187cebd..b708b50 100644 --- a/Examples/reed_sol_03.c +++ b/Examples/reed_sol_03.c @@ -116,6 +116,7 @@ int main(int argc, char **argv) char **data, **coding, **dcopy, **ccopy; int *erasures, *erased; uint32_t seed; + static gf2_t g; if (argc != 4) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -125,7 +126,7 @@ int main(int argc, char **argv) if (w <= 16 && k + m > (1 << w)) usage("k + m is too big"); MOA_Seed(seed); - matrix = reed_sol_r6_coding_matrix(k, w); + matrix = reed_sol_r6_coding_matrix(&g, k, w); printf("reed_sol_03 %d %d %d\n", k, w, seed); printf("

reed_sol_03 %d %d %d

\n", k, w, seed); @@ -154,7 +155,7 @@ int main(int argc, char **argv) ccopy[i] = talloc(char, sizeof(long)); } - reed_sol_r6_encode(k, w, data, coding, sizeof(long)); + reed_sol_r6_encode(&g, k, w, data, coding, sizeof(long)); for (i = 0; i < m; i++) { memcpy(ccopy[i], coding[i], sizeof(long)); } @@ -179,7 +180,7 @@ int main(int argc, char **argv) printf("Erased %d random devices:\n\n", m); print_data_and_coding(k, m, w, sizeof(long), data, coding); - i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, sizeof(long)); + i = jerasure_matrix_decode(&g, k, m, w, matrix, 1, erasures, data, coding, sizeof(long)); printf("State of the system after decoding:\n\n"); print_data_and_coding(k, m, w, sizeof(long), data, coding); diff --git a/Examples/reed_sol_04.c b/Examples/reed_sol_04.c index f763fb0..fe6141d 100644 --- a/Examples/reed_sol_04.c +++ b/Examples/reed_sol_04.c @@ -77,6 +77,7 @@ int main(int argc, char **argv) int *a32, *copy; int i; int w; + static gf2_t g; if (argc != 3) usage(NULL); if (sscanf(argv[1], "%d", &w) == 0 || (w != 8 && w != 16 && w != 32)) usage("Bad w"); @@ -96,21 +97,21 @@ int main(int argc, char **argv) if (w == 8) { x = (unsigned char *) copy; y = (unsigned char *) a32; - reed_sol_galois_w08_region_multby_2((char *) a32, sizeof(int)*4); + reed_sol_galois_w08_region_multby_2(&g, (char *) a32, sizeof(int)*4); for (i = 0; i < 4*sizeof(int)/sizeof(char); i++) { printf("Char %2d: %3u *2 = %3u\n", i, x[i], y[i]); } } else if (w == 16) { xs = (unsigned short *) copy; ys = (unsigned short *) a32; - reed_sol_galois_w16_region_multby_2((char *) a32, sizeof(int)*4); + reed_sol_galois_w16_region_multby_2(&g, (char *) a32, sizeof(int)*4); for (i = 0; i < 4*sizeof(int)/sizeof(short); i++) { printf("Short %2d: %5u *2 = %5u\n", i, xs[i], ys[i]); } } else if (w == 32) { xi = (unsigned int *) copy; yi = (unsigned int *) a32; - reed_sol_galois_w16_region_multby_2((char *) a32, sizeof(int)*4); + reed_sol_galois_w16_region_multby_2(&g, (char *) a32, sizeof(int)*4); for (i = 0; i < 4*sizeof(int)/sizeof(int); i++) { printf("Int %2d: %10u *2 = %10u\n", i, xi[i], yi[i]); } diff --git a/Examples/reed_sol_test_gf.c b/Examples/reed_sol_test_gf.c index 9e8856c..a1cb9e1 100644 --- a/Examples/reed_sol_test_gf.c +++ b/Examples/reed_sol_test_gf.c @@ -109,6 +109,7 @@ int main(int argc, char **argv) int *erasures, *erased; gf_t *gf = NULL; uint32_t seed; + static gf2_t g; if (argc < 6) usage("Not enough command line arguments"); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -125,9 +126,9 @@ int main(int argc, char **argv) usage("Invalid arguments given for GF!\n"); } - galois_change_technique(gf, w); + galois_change_technique(&g, gf, w); - matrix = reed_sol_vandermonde_coding_matrix(k, m, w); + matrix = reed_sol_vandermonde_coding_matrix(&g, k, m, w); printf("reed_sol_test_gf"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); @@ -154,7 +155,7 @@ int main(int argc, char **argv) old_values[i] = talloc(char, BUFSIZE); } - jerasure_matrix_encode(k, m, w, matrix, data, coding, BUFSIZE); + jerasure_matrix_encode(&g, k, m, w, matrix, data, coding, BUFSIZE); erasures = talloc(int, (m+1)); erased = talloc(int, (k+m)); @@ -170,7 +171,7 @@ int main(int argc, char **argv) } erasures[i] = -1; - i = jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, BUFSIZE); + i = jerasure_matrix_decode(&g, k, m, w, matrix, 1, erasures, data, coding, BUFSIZE); for (i = 0; i < m; i++) { if (erasures[i] < k) { diff --git a/Examples/reed_sol_time_gf.c b/Examples/reed_sol_time_gf.c index 175de8b..8f3f41a 100644 --- a/Examples/reed_sol_time_gf.c +++ b/Examples/reed_sol_time_gf.c @@ -109,6 +109,7 @@ int main(int argc, char **argv) uint32_t seed; double t = 0, total_time = 0; gf_t *gf = NULL; + static gf2_t g; if (argc < 8) usage(NULL); if (sscanf(argv[1], "%d", &k) == 0 || k <= 0) usage("Bad k"); @@ -127,9 +128,9 @@ int main(int argc, char **argv) usage("Invalid arguments given for GF!\n"); } - galois_change_technique(gf, w); + galois_change_technique(&g, gf, w); - matrix = reed_sol_vandermonde_coding_matrix(k, m, w); + matrix = reed_sol_vandermonde_coding_matrix(&g, k, m, w); printf("<HTML><TITLE>reed_sol_time_gf"); for (i = 1; i < argc; i++) printf(" %s", argv[i]); @@ -158,7 +159,7 @@ int main(int argc, char **argv) for (i = 0; i < iterations; i++) { t = timing_now(); - jerasure_matrix_encode(k, m, w, matrix, data, coding, bufsize); + jerasure_matrix_encode(&g, k, m, w, matrix, data, coding, bufsize); total_time += timing_now() - t; } @@ -180,7 +181,7 @@ int main(int argc, char **argv) for (i = 0; i < iterations; i++) { t = timing_now(); - jerasure_matrix_decode(k, m, w, matrix, 1, erasures, data, coding, bufsize); + jerasure_matrix_decode(&g, k, m, w, matrix, 1, erasures, data, coding, bufsize); total_time += timing_now() - t; } diff --git a/include/cauchy.h b/include/cauchy.h index f8d1ae3..c837b80 100644 --- a/include/cauchy.h +++ b/include/cauchy.h @@ -43,11 +43,11 @@ extern "C" { #endif -extern int *cauchy_original_coding_matrix(int k, int m, int w); -extern int *cauchy_xy_coding_matrix(int k, int m, int w, int *x, int *y); -extern void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix); -extern int *cauchy_good_general_coding_matrix(int k, int m, int w); -extern int cauchy_n_ones(int n, int w); +extern int *cauchy_original_coding_matrix(gf2_t* g, int k, int m, int w); +extern int *cauchy_xy_coding_matrix(gf2_t* g, int k, int m, int w, int *x, int *y); +extern void cauchy_improve_coding_matrix(gf2_t* g, int k, int m, int w, int *matrix); +extern int *cauchy_good_general_coding_matrix(gf2_t* g, int k, int m, int w); +extern int cauchy_n_ones(gf2_t* g, int n, int w); #ifdef __cplusplus } diff --git a/include/galois.h b/include/galois.h index 78e6567..cc42f25 100644 --- a/include/galois.h +++ b/include/galois.h @@ -46,43 +46,55 @@ extern "C" { #endif -extern int galois_init_default_field(int w); -extern int galois_uninit_field(int w); -extern void galois_change_technique(gf_t *gf, int w); +typedef struct gf2_t_ { + gf_t* gf; + gf_t* gfp_array[64]; + int gfp_is_composite[64]; +} gf2_t; -extern int galois_single_multiply(int a, int b, int w); -extern int galois_single_divide(int a, int b, int w); -extern int galois_inverse(int x, int w); +extern gf2_t* galois_init_empty(); +extern void galois_destroy(gf2_t*); +extern int galois_init_default_field(gf2_t*, int w); +extern int galois_uninit_field(gf2_t*, int w); +extern void galois_change_technique(gf2_t *g, gf_t* gf, int w); -void galois_region_xor( char *src, /* Source Region */ +extern int galois_single_multiply(gf2_t*, int a, int b, int w); +extern int galois_single_divide(gf2_t*, int a, int b, int w); +extern int galois_inverse(gf2_t*, int x, int w); + +void galois_region_xor( gf2_t*, + char *src, /* Source Region */ char *dest, /* Dest Region (holds result) */ int nbytes); /* Number of bytes in region */ /* These multiply regions in w=8, w=16 and w=32. They are much faster than calling galois_single_multiply. The regions must be long word aligned. */ -void galois_w08_region_multiply(char *region, /* Region to multiply */ +void galois_w08_region_multiply(gf2_t*, + char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here. Otherwise region is overwritten */ int add); /* If (r2 != NULL && add) the produce is XOR'd with r2 */ -void galois_w16_region_multiply(char *region, /* Region to multiply */ +void galois_w16_region_multiply(gf2_t*, + char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here. Otherwise region is overwritten */ int add); /* If (r2 != NULL && add) the produce is XOR'd with r2 */ -void galois_w32_region_multiply(char *region, /* Region to multiply */ +void galois_w32_region_multiply(gf2_t*, + char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here. Otherwise region is overwritten */ int add); /* If (r2 != NULL && add) the produce is XOR'd with r2 */ -gf_t* galois_init_field(int w, +gf2_t* galois_init_field(int w, int mult_type, int region_type, int divide_type, @@ -90,13 +102,13 @@ gf_t* galois_init_field(int w, int arg1, int arg2); -gf_t* galois_init_composite_field(int w, +gf2_t* galois_init_composite_field(int w, int region_type, int divide_type, int degree, gf_t* base_gf); -gf_t * galois_get_field_ptr(int w); +gf_t * galois_get_field_ptr(gf2_t*, int w); #ifdef __cplusplus } diff --git a/include/jerasure.h b/include/jerasure.h index de874e1..f311458 100644 --- a/include/jerasure.h +++ b/include/jerasure.h @@ -123,7 +123,7 @@ extern "C" { jerasure_generate_schedule_cache. */ -int *jerasure_matrix_to_bitmatrix(int k, int m, int w, int *matrix); +int *jerasure_matrix_to_bitmatrix(gf2_t* g, int k, int m, int w, int *matrix); int **jerasure_dumb_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix); int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix); int ***jerasure_generate_schedule_cache(int k, int m, int w, int *bitmatrix, int smart); @@ -136,15 +136,15 @@ void jerasure_free_schedule_cache(int k, int m, int ***cache); /* Encoding - these are all straightforward. jerasure_matrix_encode only works with w = 8|16|32. */ -void jerasure_do_parity(int k, char **data_ptrs, char *parity_ptr, int size); +void jerasure_do_parity(gf2_t* g, int k, char **data_ptrs, char *parity_ptr, int size); -void jerasure_matrix_encode(int k, int m, int w, int *matrix, +void jerasure_matrix_encode(gf2_t* g, int k, int m, int w, int *matrix, char **data_ptrs, char **coding_ptrs, int size); -void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix, +void jerasure_bitmatrix_encode(gf2_t* g, int k, int m, int w, int *bitmatrix, char **data_ptrs, char **coding_ptrs, int size, int packetsize); -void jerasure_schedule_encode(int k, int m, int w, int **schedule, +void jerasure_schedule_encode(gf2_t* g, int k, int m, int w, int **schedule, char **data_ptrs, char **coding_ptrs, int size, int packetsize); /* ------------------------------------------------------------ */ @@ -183,22 +183,22 @@ void jerasure_schedule_encode(int k, int m, int w, int **schedule, */ -int jerasure_matrix_decode(int k, int m, int w, +int jerasure_matrix_decode(gf2_t* g, int k, int m, int w, int *matrix, int row_k_ones, int *erasures, char **data_ptrs, char **coding_ptrs, int size); -int jerasure_bitmatrix_decode(int k, int m, int w, +int jerasure_bitmatrix_decode(gf2_t* g, int k, int m, int w, int *bitmatrix, int row_k_ones, int *erasures, char **data_ptrs, char **coding_ptrs, int size, int packetsize); -int jerasure_schedule_decode_lazy(int k, int m, int w, int *bitmatrix, int *erasures, +int jerasure_schedule_decode_lazy(gf2_t* g, int k, int m, int w, int *bitmatrix, int *erasures, char **data_ptrs, char **coding_ptrs, int size, int packetsize, int smart); -int jerasure_schedule_decode_cache(int k, int m, int w, int ***scache, int *erasures, +int jerasure_schedule_decode_cache(gf2_t* g, int k, int m, int w, int ***scache, int *erasures, char **data_ptrs, char **coding_ptrs, int size, int packetsize); -int jerasure_make_decoding_matrix(int k, int m, int w, int *matrix, int *erased, +int jerasure_make_decoding_matrix(gf2_t* g, int k, int m, int w, int *matrix, int *erased, int *decoding_matrix, int *dm_ids); int jerasure_make_decoding_bitmatrix(int k, int m, int w, int *matrix, int *erased, @@ -221,15 +221,15 @@ int *jerasure_erasures_to_erased(int k, int m, int *erasures); */ -void jerasure_matrix_dotprod(int k, int w, int *matrix_row, +void jerasure_matrix_dotprod(gf2_t* g, int k, int w, int *matrix_row, int *src_ids, int dest_id, char **data_ptrs, char **coding_ptrs, int size); -void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row, +void jerasure_bitmatrix_dotprod(gf2_t* g, int k, int w, int *bitmatrix_row, int *src_ids, int dest_id, char **data_ptrs, char **coding_ptrs, int size, int packetsize); -void jerasure_do_scheduled_operations(char **ptrs, int **schedule, int packetsize); +void jerasure_do_scheduled_operations(gf2_t* g, char **ptrs, int **schedule, int packetsize); /* ------------------------------------------------------------ */ /* Matrix Inversion ------------------------------------------- */ @@ -255,9 +255,9 @@ void jerasure_do_scheduled_operations(char **ptrs, int **schedule, int packetsiz invertible. (0 or 1). Mat will be destroyed. */ -int jerasure_invert_matrix(int *mat, int *inv, int rows, int w); +int jerasure_invert_matrix(gf2_t* g, int *mat, int *inv, int rows, int w); int jerasure_invert_bitmatrix(int *mat, int *inv, int rows); -int jerasure_invertible_matrix(int *mat, int rows, int w); +int jerasure_invertible_matrix(gf2_t* g, int *mat, int rows, int w); int jerasure_invertible_bitmatrix(int *mat, int rows); /* ------------------------------------------------------------ */ @@ -277,7 +277,7 @@ void jerasure_print_matrix(int *matrix, int rows, int cols, int w); void jerasure_print_bitmatrix(int *matrix, int rows, int cols, int w); -int *jerasure_matrix_multiply(int *m1, int *m2, int r1, int c1, int r2, int c2, int w); +int *jerasure_matrix_multiply(gf2_t* g, int *m1, int *m2, int r1, int c1, int r2, int c2, int w); /* ------------------------------------------------------------ */ /* Stats ------------------------------------------------------ */ diff --git a/include/reed_sol.h b/include/reed_sol.h index 48fc4e6..c47b26f 100644 --- a/include/reed_sol.h +++ b/include/reed_sol.h @@ -43,16 +43,16 @@ extern "C" { #endif -extern int *reed_sol_vandermonde_coding_matrix(int k, int m, int w); -extern int *reed_sol_extended_vandermonde_matrix(int rows, int cols, int w); -extern int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w); +extern int *reed_sol_vandermonde_coding_matrix(gf2_t* g, int k, int m, int w); +extern int *reed_sol_extended_vandermonde_matrix(gf2_t* g, int rows, int cols, int w); +extern int *reed_sol_big_vandermonde_distribution_matrix(gf2_t* g, int rows, int cols, int w); -extern int reed_sol_r6_encode(int k, int w, char **data_ptrs, char **coding_ptrs, int size); -extern int *reed_sol_r6_coding_matrix(int k, int w); +extern int reed_sol_r6_encode(gf2_t* g, int k, int w, char **data_ptrs, char **coding_ptrs, int size); +extern int *reed_sol_r6_coding_matrix(gf2_t* g, int k, int w); -extern void reed_sol_galois_w08_region_multby_2(char *region, int nbytes); -extern void reed_sol_galois_w16_region_multby_2(char *region, int nbytes); -extern void reed_sol_galois_w32_region_multby_2(char *region, int nbytes); +extern void reed_sol_galois_w08_region_multby_2(gf2_t* g, char *region, int nbytes); +extern void reed_sol_galois_w16_region_multby_2(gf2_t* g, char *region, int nbytes); +extern void reed_sol_galois_w32_region_multby_2(gf2_t* g, char *region, int nbytes); #ifdef __cplusplus } diff --git a/src/cauchy.c b/src/cauchy.c index f63dfb7..a5c859f 100644 --- a/src/cauchy.c +++ b/src/cauchy.c @@ -86,7 +86,7 @@ static int *cbest_all[33]; #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) -int cauchy_n_ones(int n, int w) +int cauchy_n_ones(gf2_t* g, int n, int w) { int no; int cno; @@ -98,7 +98,7 @@ int cauchy_n_ones(int n, int w) if (PPs[w] == -1) { nones = 0; - PPs[w] = galois_single_multiply(highbit, 2, w); + PPs[w] = galois_single_multiply(g, highbit, 2, w); for (i = 0; i < w; i++) { if (PPs[w] & (1 << i)) { ONEs[w][nones] = (1 << i); @@ -128,7 +128,7 @@ int cauchy_n_ones(int n, int w) return no; } -int *cauchy_original_coding_matrix(int k, int m, int w) +int *cauchy_original_coding_matrix(gf2_t* g, int k, int m, int w) { int *matrix; int i, j, index; @@ -139,14 +139,14 @@ int *cauchy_original_coding_matrix(int k, int m, int w) index = 0; for (i = 0; i < m; i++) { for (j = 0; j < k; j++) { - matrix[index] = galois_single_divide(1, (i ^ (m+j)), w); + matrix[index] = galois_single_divide(g, 1, (i ^ (m+j)), w); index++; } } return matrix; } -int *cauchy_xy_coding_matrix(int k, int m, int w, int *X, int *Y) +int *cauchy_xy_coding_matrix(gf2_t* g, int k, int m, int w, int *X, int *Y) { int index, i, j; int *matrix; @@ -156,14 +156,14 @@ int *cauchy_xy_coding_matrix(int k, int m, int w, int *X, int *Y) index = 0; for (i = 0; i < m; i++) { for (j = 0; j < k; j++) { - matrix[index] = galois_single_divide(1, (X[i] ^ Y[j]), w); + matrix[index] = galois_single_divide(g, 1, (X[i] ^ Y[j]), w); index++; } } return matrix; } -void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix) +void cauchy_improve_coding_matrix(gf2_t* g, int k, int m, int w, int *matrix) { int index, i, j, x; int tmp; @@ -171,10 +171,10 @@ void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix) for (j = 0; j < k; j++) { if (matrix[j] != 1) { - tmp = galois_single_divide(1, matrix[j], w); + tmp = galois_single_divide(g, 1, matrix[j], w); index = j; for (i = 0; i < m; i++) { - matrix[index] = galois_single_multiply(matrix[index], tmp, w); + matrix[index] = galois_single_multiply(g, matrix[index], tmp, w); index += k; } } @@ -182,14 +182,14 @@ void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix) for (i = 1; i < m; i++) { bno = 0; index = i*k; - for (j = 0; j < k; j++) bno += cauchy_n_ones(matrix[index+j], w); + for (j = 0; j < k; j++) bno += cauchy_n_ones(g, matrix[index+j], w); bno_index = -1; for (j = 0; j < k; j++) { if (matrix[index+j] != 1) { - tmp = galois_single_divide(1, matrix[index+j], w); + tmp = galois_single_divide(g, 1, matrix[index+j], w); tno = 0; for (x = 0; x < k; x++) { - tno += cauchy_n_ones(galois_single_multiply(matrix[index+x], tmp, w), w); + tno += cauchy_n_ones(g, galois_single_multiply(g, matrix[index+x], tmp, w), w); } if (tno < bno) { bno = tno; @@ -198,22 +198,22 @@ void cauchy_improve_coding_matrix(int k, int m, int w, int *matrix) } } if (bno_index != -1) { - tmp = galois_single_divide(1, matrix[index+bno_index], w); + tmp = galois_single_divide(g, 1, matrix[index+bno_index], w); for (j = 0; j < k; j++) { - matrix[index+j] = galois_single_multiply(matrix[index+j], tmp, w); + matrix[index+j] = galois_single_multiply(g, matrix[index+j], tmp, w); } } } } -int *cauchy_good_general_coding_matrix(int k, int m, int w) +int *cauchy_good_general_coding_matrix(gf2_t* g, int k, int m, int w) { int *matrix, i; if (m == 2 && k <= cbest_max_k[w]) { matrix = talloc(int, k*m); if (matrix == NULL) return NULL; - if (!cbest_init) { + if (!cbest_init) { /* not safe for multithreads. need CAS */ cbest_init = 1; cbest_all[0] = cbest_0; cbest_all[1] = cbest_1; cbest_all[2] = cbest_2; cbest_all[3] = cbest_3; cbest_all[4] = cbest_4; cbest_all[5] = cbest_5; cbest_all[6] = cbest_6; cbest_all[7] = cbest_7; cbest_all[8] = cbest_8; @@ -230,9 +230,9 @@ int *cauchy_good_general_coding_matrix(int k, int m, int w) } return matrix; } else { - matrix = cauchy_original_coding_matrix(k, m, w); + matrix = cauchy_original_coding_matrix(g, k, m, w); if (matrix == NULL) return NULL; - cauchy_improve_coding_matrix(k, m, w, matrix); + cauchy_improve_coding_matrix(g, k, m, w, matrix); return matrix; } } diff --git a/src/galois.c b/src/galois.c index cd9faa8..b900b32 100644 --- a/src/galois.c +++ b/src/galois.c @@ -53,19 +53,34 @@ #include "galois.h" #define MAX_GF_INSTANCES 64 -gf_t *gfp_array[MAX_GF_INSTANCES] = { 0 }; -int gfp_is_composite[MAX_GF_INSTANCES] = { 0 }; -gf_t *galois_get_field_ptr(int w) +gf_t *galois_get_field_ptr(gf2_t* g, int w) { - if (gfp_array[w] != NULL) { - return gfp_array[w]; + if (g->gfp_array[w] != NULL) { + return g->gfp_array[w]; } return NULL; } -gf_t* galois_init_field(int w, +gf2_t* galois_init_empty() +{ + gf2_t* ptr = (gf2_t *) malloc(sizeof(gf2_t)); + memset(ptr, sizeof(gf2_t), 0); + return ptr; +} + +void galois_destroy(gf2_t* g) +{ + if (g) { + free(g->gf); + for (int i = 0; i < MAX_GF_INSTANCES; i ++) + free(galois_get_field_ptr(g, i)); + free(g); + } +} + +gf2_t* galois_init_field(int w, int mult_type, int region_type, int divide_type, @@ -75,15 +90,16 @@ gf_t* galois_init_field(int w, { int scratch_size; void *scratch_memory; - gf_t *gfp; + gf2_t *gf2p; if (w <= 0 || w > 32) { fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w); assert(0); } - gfp = (gf_t *) malloc(sizeof(gf_t)); - if (!gfp) { + gf2p = (gf2_t *) malloc(sizeof(gf2_t)); + gf2p->gf = (gf_t *) malloc(sizeof(gf_t)); + if (!gf2p || gf2p->gf) { fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); assert(0); } @@ -100,7 +116,7 @@ gf_t* galois_init_field(int w, assert(0); } - if(!gf_init_hard(gfp, + if(!gf_init_hard(gf2p->gf, w, mult_type, region_type, @@ -115,27 +131,28 @@ gf_t* galois_init_field(int w, assert(0); } - gfp_is_composite[w] = 0; - return gfp; + gf2p->gfp_is_composite[w] = 0; + return gf2p; } -gf_t* galois_init_composite_field(int w, - int region_type, - int divide_type, - int degree, - gf_t* base_gf) +gf2_t* galois_init_composite_field(int w, + int region_type, + int divide_type, + int degree, + gf_t* base_gf) { int scratch_size; void *scratch_memory; - gf_t *gfp; + gf2_t *gf2p; if (w <= 0 || w > 32) { fprintf(stderr, "ERROR -- cannot init composite field for w=%d\n", w); assert(0); } - gfp = (gf_t *) malloc(sizeof(gf_t)); - if (!gfp) { + gf2p = (gf2_t *) malloc(sizeof(gf2_t)); + gf2p->gf = (gf_t *) malloc(sizeof(gf_t)); + if (!gf2p || gf2p->gf) { fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); assert(0); } @@ -152,7 +169,7 @@ gf_t* galois_init_composite_field(int w, assert(0); } - if(!gf_init_hard(gfp, + if(!gf_init_hard(gf2p->gf, w, GF_MULT_COMPOSITE, region_type, @@ -166,42 +183,42 @@ gf_t* galois_init_composite_field(int w, fprintf(stderr, "ERROR -- cannot init default composite field for w=%d\n", w); assert(0); } - gfp_is_composite[w] = 1; - return gfp; + gf2p->gfp_is_composite[w] = 1; + return gf2p; } -int galois_init_default_field(int w) +int galois_init_default_field(gf2_t* g, int w) { - if (gfp_array[w] == NULL) { - gfp_array[w] = (gf_t*)malloc(sizeof(gf_t)); - if(gfp_array[w] == NULL) + if (g->gfp_array[w] == NULL) { + g->gfp_array[w] = (gf_t*)malloc(sizeof(gf_t)); + if(g->gfp_array[w] == NULL) return ENOMEM; - if (!gf_init_easy(gfp_array[w], w)) + if (!gf_init_easy(g->gfp_array[w], w)) return EINVAL; } return 0; } -int galois_uninit_field(int w) +int galois_uninit_field(gf2_t* g, int w) { int ret = 0; - if (gfp_array[w] != NULL) { + if (g->gfp_array[w] != NULL) { int recursive = 1; - ret = gf_free(gfp_array[w], recursive); - free(gfp_array[w]); - gfp_array[w] = NULL; + ret = gf_free(g->gfp_array[w], recursive); + free(g->gfp_array[w]); + g->gfp_array[w] = NULL; } return ret; } -static void galois_init(int w) +static void galois_init(gf2_t* g, int w) { if (w <= 0 || w > 32) { fprintf(stderr, "ERROR -- cannot init default Galois field for w=%d\n", w); assert(0); } - switch (galois_init_default_field(w)) { + switch (galois_init_default_field(g, w)) { case ENOMEM: fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); assert(0); @@ -243,7 +260,7 @@ static int is_valid_gf(gf_t *gf, int w) return 1; } -void galois_change_technique(gf_t *gf, int w) +void galois_change_technique(gf2_t *g, gf_t* gf, int w) { if (w <= 0 || w > 32) { fprintf(stderr, "ERROR -- cannot support Galois field for w=%d\n", w); @@ -255,111 +272,114 @@ void galois_change_technique(gf_t *gf, int w) assert(0); } - if (gfp_array[w] != NULL) { - gf_free(gfp_array[w], gfp_is_composite[w]); + if (g->gfp_array[w] != NULL) { + gf_free(g->gfp_array[w], g->gfp_is_composite[w]); } - gfp_array[w] = gf; + g->gfp_array[w] = g; } -int galois_single_multiply(int x, int y, int w) +int galois_single_multiply(gf2_t* g, int x, int y, int w) { if (x == 0 || y == 0) return 0; - if (gfp_array[w] == NULL) { - galois_init(w); + if (g->gfp_array[w] == NULL) { + galois_init(g, w); } if (w <= 32) { - return gfp_array[w]->multiply.w32(gfp_array[w], x, y); + return g->gfp_array[w]->multiply.w32(g->gfp_array[w], x, y); } else { fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w); return 0; } } -int galois_single_divide(int x, int y, int w) +int galois_single_divide(gf2_t* g, int x, int y, int w) { if (x == 0) return 0; if (y == 0) return -1; - if (gfp_array[w] == NULL) { - galois_init(w); + if (g->gfp_array[w] == NULL) { + galois_init(g, w); } if (w <= 32) { - return gfp_array[w]->divide.w32(gfp_array[w], x, y); + return g->gfp_array[w]->divide.w32(g->gfp_array[w], x, y); } else { fprintf(stderr, "ERROR -- Galois field not implemented for w=%d\n", w); return 0; } } -void galois_w08_region_multiply(char *region, /* Region to multiply */ +void galois_w08_region_multiply(gf2_t* g, + char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here */ int add) { - if (gfp_array[8] == NULL) { - galois_init(8); + if (g->gfp_array[8] == NULL) { + galois_init(g, 8); } - gfp_array[8]->multiply_region.w32(gfp_array[8], region, r2, multby, nbytes, add); + g->gfp_array[8]->multiply_region.w32(g->gfp_array[8], region, r2, multby, nbytes, add); } -void galois_w16_region_multiply(char *region, /* Region to multiply */ +void galois_w16_region_multiply(gf2_t* g, + char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here */ int add) { - if (gfp_array[16] == NULL) { - galois_init(16); + if (g->gfp_array[16] == NULL) { + galois_init(g, 16); } - gfp_array[16]->multiply_region.w32(gfp_array[16], region, r2, multby, nbytes, add); + g->gfp_array[16]->multiply_region.w32(g->gfp_array[16], region, r2, multby, nbytes, add); } -void galois_w32_region_multiply(char *region, /* Region to multiply */ +void galois_w32_region_multiply(gf2_t* g, + char *region, /* Region to multiply */ int multby, /* Number to multiply by */ int nbytes, /* Number of bytes in region */ char *r2, /* If r2 != NULL, products go here */ int add) { - if (gfp_array[32] == NULL) { - galois_init(32); + if (g->gfp_array[32] == NULL) { + galois_init(g, 32); } - gfp_array[32]->multiply_region.w32(gfp_array[32], region, r2, multby, nbytes, add); + g->gfp_array[32]->multiply_region.w32(g->gfp_array[32], region, r2, multby, nbytes, add); } -void galois_w8_region_xor(void *src, void *dest, int nbytes) +void galois_w8_region_xor(gf2_t* g, void *src, void *dest, int nbytes) { - if (gfp_array[8] == NULL) { - galois_init(8); + if (g->gfp_array[8] == NULL) { + galois_init(g, 8); } - gfp_array[8]->multiply_region.w32(gfp_array[32], src, dest, 1, nbytes, 1); + g->gfp_array[8]->multiply_region.w32(g->gfp_array[32], src, dest, 1, nbytes, 1); } -void galois_w16_region_xor(void *src, void *dest, int nbytes) +void galois_w16_region_xor(gf2_t* g, void *src, void *dest, int nbytes) { - if (gfp_array[16] == NULL) { - galois_init(16); + if (g->gfp_array[16] == NULL) { + galois_init(g, 16); } - gfp_array[16]->multiply_region.w32(gfp_array[16], src, dest, 1, nbytes, 1); + g->gfp_array[16]->multiply_region.w32(g->gfp_array[16], src, dest, 1, nbytes, 1); } -void galois_w32_region_xor(void *src, void *dest, int nbytes) +void galois_w32_region_xor(gf2_t* g, void *src, void *dest, int nbytes) { - if (gfp_array[32] == NULL) { - galois_init(32); + if (g->gfp_array[32] == NULL) { + galois_init(g, 32); } - gfp_array[32]->multiply_region.w32(gfp_array[32], src, dest, 1, nbytes, 1); + g->gfp_array[32]->multiply_region.w32(g->gfp_array[32], src, dest, 1, nbytes, 1); } -void galois_region_xor(char *src, char *dest, int nbytes) +void galois_region_xor(gf2_t* g, char *src, char *dest, int nbytes) { if (nbytes >= 16) { - galois_w32_region_xor(src, dest, nbytes); + galois_w32_region_xor(g, src, dest, nbytes); } else { int i = 0; for (i = 0; i < nbytes; i++) { @@ -370,8 +390,8 @@ void galois_region_xor(char *src, char *dest, int nbytes) } } -int galois_inverse(int y, int w) +int galois_inverse(gf2_t* g, int y, int w) { if (y == 0) return -1; - return galois_single_divide(1, y, w); + return galois_single_divide(g, 1, y, w); } diff --git a/src/jerasure.c b/src/jerasure.c index 6874a8a..8ef5b25 100644 --- a/src/jerasure.c +++ b/src/jerasure.c @@ -96,7 +96,7 @@ void jerasure_print_bitmatrix(int *m, int rows, int cols, int w) } } -int jerasure_make_decoding_matrix(int k, int m, int w, int *matrix, int *erased, int *decoding_matrix, int *dm_ids) +int jerasure_make_decoding_matrix(gf2_t* g, int k, int m, int w, int *matrix, int *erased, int *decoding_matrix, int *dm_ids) { int i, j, *tmpmat; @@ -121,7 +121,7 @@ int jerasure_make_decoding_matrix(int k, int m, int w, int *matrix, int *erased, } } - i = jerasure_invert_matrix(tmpmat, decoding_matrix, k, w); + i = jerasure_invert_matrix(g, tmpmat, decoding_matrix, k, w); free(tmpmat); return i; } @@ -165,7 +165,7 @@ int jerasure_make_decoding_bitmatrix(int k, int m, int w, int *matrix, int *eras return i; } -int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int *erasures, +int jerasure_matrix_decode(gf2_t* g, int k, int m, int w, int *matrix, int row_k_ones, int *erasures, char **data_ptrs, char **coding_ptrs, int size) { int i, edd, lastdrive; @@ -221,7 +221,7 @@ int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int return -1; } - if (jerasure_make_decoding_matrix(k, m, w, matrix, erased, decoding_matrix, dm_ids) < 0) { + if (jerasure_make_decoding_matrix(g, k, m, w, matrix, erased, decoding_matrix, dm_ids) < 0) { free(erased); free(dm_ids); free(decoding_matrix); @@ -237,7 +237,7 @@ int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int for (i = 0; edd > 0 && i < lastdrive; i++) { if (erased[i]) { - jerasure_matrix_dotprod(k, w, decoding_matrix+(i*k), dm_ids, i, data_ptrs, coding_ptrs, size); + jerasure_matrix_dotprod(g, k, w, decoding_matrix+(i*k), dm_ids, i, data_ptrs, coding_ptrs, size); edd--; } } @@ -255,7 +255,7 @@ int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int for (i = 0; i < k; i++) { tmpids[i] = (i < lastdrive) ? i : i+1; } - jerasure_matrix_dotprod(k, w, matrix, tmpids, lastdrive, data_ptrs, coding_ptrs, size); + jerasure_matrix_dotprod(g, k, w, matrix, tmpids, lastdrive, data_ptrs, coding_ptrs, size); free(tmpids); } @@ -263,7 +263,7 @@ int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int for (i = 0; i < m; i++) { if (erased[k+i]) { - jerasure_matrix_dotprod(k, w, matrix+(i*k), NULL, i+k, data_ptrs, coding_ptrs, size); + jerasure_matrix_dotprod(g, k, w, matrix+(i*k), NULL, i+k, data_ptrs, coding_ptrs, size); } } @@ -275,7 +275,7 @@ int jerasure_matrix_decode(int k, int m, int w, int *matrix, int row_k_ones, int } -int *jerasure_matrix_to_bitmatrix(int k, int m, int w, int *matrix) +int *jerasure_matrix_to_bitmatrix(gf2_t* g, int k, int m, int w, int *matrix) { int *bitmatrix; int rowelts, rowindex, colindex, elt, i, j, l, x; @@ -296,7 +296,7 @@ int *jerasure_matrix_to_bitmatrix(int k, int m, int w, int *matrix) for (l = 0; l < w; l++) { bitmatrix[colindex+x+l*rowelts] = ((elt & (1 << l)) ? 1 : 0); } - elt = galois_single_multiply(elt, 2, w); + elt = galois_single_multiply(g, elt, 2, w); } colindex += w; } @@ -305,7 +305,7 @@ int *jerasure_matrix_to_bitmatrix(int k, int m, int w, int *matrix) return bitmatrix; } -void jerasure_matrix_encode(int k, int m, int w, int *matrix, +void jerasure_matrix_encode(gf2_t* g, int k, int m, int w, int *matrix, char **data_ptrs, char **coding_ptrs, int size) { int i; @@ -316,11 +316,11 @@ void jerasure_matrix_encode(int k, int m, int w, int *matrix, } for (i = 0; i < m; i++) { - jerasure_matrix_dotprod(k, w, matrix+(i*k), NULL, k+i, data_ptrs, coding_ptrs, size); + jerasure_matrix_dotprod(g, k, w, matrix+(i*k), NULL, k+i, data_ptrs, coding_ptrs, size); } } -void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row, +void jerasure_bitmatrix_dotprod(gf2_t* g, int k, int w, int *bitmatrix_row, int *src_ids, int dest_id, char **data_ptrs, char **coding_ptrs, int size, int packetsize) { @@ -355,7 +355,7 @@ void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row, jerasure_total_memcpy_bytes += packetsize; pstarted = 1; } else { - galois_region_xor(dptr, pptr, packetsize); + galois_region_xor(g, dptr, pptr, packetsize); jerasure_total_xor_bytes += packetsize; } } @@ -366,7 +366,7 @@ void jerasure_bitmatrix_dotprod(int k, int w, int *bitmatrix_row, } } -void jerasure_do_parity(int k, char **data_ptrs, char *parity_ptr, int size) +void jerasure_do_parity(gf2_t* g, int k, char **data_ptrs, char *parity_ptr, int size) { int i; @@ -374,12 +374,12 @@ void jerasure_do_parity(int k, char **data_ptrs, char *parity_ptr, int size) jerasure_total_memcpy_bytes += size; for (i = 1; i < k; i++) { - galois_region_xor(data_ptrs[i], parity_ptr, size); + galois_region_xor(g, data_ptrs[i], parity_ptr, size); jerasure_total_xor_bytes += size; } } -int jerasure_invert_matrix(int *mat, int *inv, int rows, int w) +int jerasure_invert_matrix(gf2_t* g, int *mat, int *inv, int rows, int w) { int cols, i, j, k, x, rs2; int row_start, tmp, inverse; @@ -418,10 +418,10 @@ int jerasure_invert_matrix(int *mat, int *inv, int rows, int w) /* Multiply the row by 1/element i,i */ tmp = mat[row_start+i]; if (tmp != 1) { - inverse = galois_single_divide(1, tmp, w); + inverse = galois_single_divide(g, 1, tmp, w); for (j = 0; j < cols; j++) { - mat[row_start+j] = galois_single_multiply(mat[row_start+j], inverse, w); - inv[row_start+j] = galois_single_multiply(inv[row_start+j], inverse, w); + mat[row_start+j] = galois_single_multiply(g, mat[row_start+j], inverse, w); + inv[row_start+j] = galois_single_multiply(g, inv[row_start+j], inverse, w); } } @@ -440,8 +440,8 @@ int jerasure_invert_matrix(int *mat, int *inv, int rows, int w) tmp = mat[k]; rs2 = cols*j; for (x = 0; x < cols; x++) { - mat[rs2+x] ^= galois_single_multiply(tmp, mat[row_start+x], w); - inv[rs2+x] ^= galois_single_multiply(tmp, inv[row_start+x], w); + mat[rs2+x] ^= galois_single_multiply(g, tmp, mat[row_start+x], w); + inv[rs2+x] ^= galois_single_multiply(g, tmp, inv[row_start+x], w); } } } @@ -458,7 +458,7 @@ int jerasure_invert_matrix(int *mat, int *inv, int rows, int w) tmp = mat[rs2+i]; mat[rs2+i] = 0; for (k = 0; k < cols; k++) { - inv[rs2+k] ^= galois_single_multiply(tmp, inv[row_start+k], w); + inv[rs2+k] ^= galois_single_multiply(g, tmp, inv[row_start+k], w); } } } @@ -466,7 +466,7 @@ int jerasure_invert_matrix(int *mat, int *inv, int rows, int w) return 0; } -int jerasure_invertible_matrix(int *mat, int rows, int w) +int jerasure_invertible_matrix(gf2_t* g, int *mat, int rows, int w) { int cols, i, j, k, x, rs2; int row_start, tmp, inverse; @@ -494,9 +494,9 @@ int jerasure_invertible_matrix(int *mat, int rows, int w) /* Multiply the row by 1/element i,i */ tmp = mat[row_start+i]; if (tmp != 1) { - inverse = galois_single_divide(1, tmp, w); + inverse = galois_single_divide(g, 1, tmp, w); for (j = 0; j < cols; j++) { - mat[row_start+j] = galois_single_multiply(mat[row_start+j], inverse, w); + mat[row_start+j] = galois_single_multiply(g, mat[row_start+j], inverse, w); } } @@ -514,7 +514,7 @@ int jerasure_invertible_matrix(int *mat, int rows, int w) tmp = mat[k]; rs2 = cols*j; for (x = 0; x < cols; x++) { - mat[rs2+x] ^= galois_single_multiply(tmp, mat[row_start+x], w); + mat[rs2+x] ^= galois_single_multiply(g, tmp, mat[row_start+x], w); } } } @@ -580,7 +580,7 @@ void jerasure_free_schedule_cache(int k, int m, int ***cache) free(cache); } -void jerasure_matrix_dotprod(int k, int w, int *matrix_row, +void jerasure_matrix_dotprod(gf2_t* g, int k, int w, int *matrix_row, int *src_ids, int dest_id, char **data_ptrs, char **coding_ptrs, int size) { @@ -613,7 +613,7 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row, jerasure_total_memcpy_bytes += size; init = 1; } else { - galois_region_xor(sptr, dptr, size); + galois_region_xor(g, sptr, dptr, size); jerasure_total_xor_bytes += size; } } @@ -631,9 +631,9 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row, sptr = coding_ptrs[src_ids[i]-k]; } switch (w) { - case 8: galois_w08_region_multiply(sptr, matrix_row[i], size, dptr, init); break; - case 16: galois_w16_region_multiply(sptr, matrix_row[i], size, dptr, init); break; - case 32: galois_w32_region_multiply(sptr, matrix_row[i], size, dptr, init); break; + case 8: galois_w08_region_multiply(g, sptr, matrix_row[i], size, dptr, init); break; + case 16: galois_w16_region_multiply(g, sptr, matrix_row[i], size, dptr, init); break; + case 32: galois_w32_region_multiply(g, sptr, matrix_row[i], size, dptr, init); break; } jerasure_total_gf_bytes += size; init = 1; @@ -642,7 +642,7 @@ void jerasure_matrix_dotprod(int k, int w, int *matrix_row, } -int jerasure_bitmatrix_decode(int k, int m, int w, int *bitmatrix, int row_k_ones, int *erasures, +int jerasure_bitmatrix_decode(gf2_t* g, int k, int m, int w, int *bitmatrix, int row_k_ones, int *erasures, char **data_ptrs, char **coding_ptrs, int size, int packetsize) { int i; @@ -697,7 +697,7 @@ int jerasure_bitmatrix_decode(int k, int m, int w, int *bitmatrix, int row_k_one for (i = 0; edd > 0 && i < lastdrive; i++) { if (erased[i]) { - jerasure_bitmatrix_dotprod(k, w, decoding_matrix+i*k*w*w, dm_ids, i, data_ptrs, coding_ptrs, size, packetsize); + jerasure_bitmatrix_dotprod(g, k, w, decoding_matrix+i*k*w*w, dm_ids, i, data_ptrs, coding_ptrs, size, packetsize); edd--; } } @@ -713,13 +713,13 @@ int jerasure_bitmatrix_decode(int k, int m, int w, int *bitmatrix, int row_k_one for (i = 0; i < k; i++) { tmpids[i] = (i < lastdrive) ? i : i+1; } - jerasure_bitmatrix_dotprod(k, w, bitmatrix, tmpids, lastdrive, data_ptrs, coding_ptrs, size, packetsize); + jerasure_bitmatrix_dotprod(g, k, w, bitmatrix, tmpids, lastdrive, data_ptrs, coding_ptrs, size, packetsize); free(tmpids); } for (i = 0; i < m; i++) { if (erased[k+i]) { - jerasure_bitmatrix_dotprod(k, w, bitmatrix+i*k*w*w, NULL, k+i, data_ptrs, coding_ptrs, size, packetsize); + jerasure_bitmatrix_dotprod(g, k, w, bitmatrix+i*k*w*w, NULL, k+i, data_ptrs, coding_ptrs, size, packetsize); } } @@ -988,7 +988,7 @@ static int **jerasure_generate_decoding_schedule(int k, int m, int w, int *bitma return schedule; } -int jerasure_schedule_decode_lazy(int k, int m, int w, int *bitmatrix, int *erasures, +int jerasure_schedule_decode_lazy(gf2_t* g, int k, int m, int w, int *bitmatrix, int *erasures, char **data_ptrs, char **coding_ptrs, int size, int packetsize, int smart) { @@ -1006,7 +1006,7 @@ int jerasure_schedule_decode_lazy(int k, int m, int w, int *bitmatrix, int *eras } for (tdone = 0; tdone < size; tdone += packetsize*w) { - jerasure_do_scheduled_operations(ptrs, schedule, packetsize); + jerasure_do_scheduled_operations(g, ptrs, schedule, packetsize); for (i = 0; i < k+m; i++) ptrs[i] += (packetsize*w); } @@ -1016,7 +1016,7 @@ int jerasure_schedule_decode_lazy(int k, int m, int w, int *bitmatrix, int *eras return 0; } -int jerasure_schedule_decode_cache(int k, int m, int w, int ***scache, int *erasures, +int jerasure_schedule_decode_cache(gf2_t* g, int k, int m, int w, int ***scache, int *erasures, char **data_ptrs, char **coding_ptrs, int size, int packetsize) { int i, tdone; @@ -1039,7 +1039,7 @@ int jerasure_schedule_decode_cache(int k, int m, int w, int ***scache, int *eras for (tdone = 0; tdone < size; tdone += packetsize*w) { - jerasure_do_scheduled_operations(ptrs, schedule, packetsize); + jerasure_do_scheduled_operations(g, ptrs, schedule, packetsize); for (i = 0; i < k+m; i++) ptrs[i] += (packetsize*w); } @@ -1176,7 +1176,7 @@ int jerasure_invertible_bitmatrix(int *mat, int rows) } -int *jerasure_matrix_multiply(int *m1, int *m2, int r1, int c1, int r2, int c2, int w) +int *jerasure_matrix_multiply(gf2_t* g, int *m1, int *m2, int r1, int c1, int r2, int c2, int w) { int *product, i, j, k; @@ -1186,7 +1186,7 @@ int *jerasure_matrix_multiply(int *m1, int *m2, int r1, int c1, int r2, int c2, for (i = 0; i < r1; i++) { for (j = 0; j < c2; j++) { for (k = 0; k < r2; k++) { - product[i*c2+j] ^= galois_single_multiply(m1[i*c1+k], m2[k*c2+j], w); + product[i*c2+j] ^= galois_single_multiply(g, m1[i*c1+k], m2[k*c2+j], w); } } } @@ -1203,7 +1203,7 @@ void jerasure_get_stats(double *fill_in) jerasure_total_memcpy_bytes = 0; } -void jerasure_do_scheduled_operations(char **ptrs, int **operations, int packetsize) +void jerasure_do_scheduled_operations(gf2_t* g, char **ptrs, int **operations, int packetsize) { char *sptr; char *dptr; @@ -1218,7 +1218,7 @@ void jerasure_do_scheduled_operations(char **ptrs, int **operations, int packets operations[op][2], operations[op][3]); printf("xor(0x%x, 0x%x -> 0x%x, %d)\n", sptr, dptr, dptr, packetsize); */ - galois_region_xor(sptr, dptr, packetsize); + galois_region_xor(g, sptr, dptr, packetsize); jerasure_total_xor_bytes += packetsize; } else { /* printf("memcpy(0x%x <- 0x%x)\n", dptr, sptr); */ @@ -1228,7 +1228,7 @@ void jerasure_do_scheduled_operations(char **ptrs, int **operations, int packets } } -void jerasure_schedule_encode(int k, int m, int w, int **schedule, +void jerasure_schedule_encode(gf2_t* g, int k, int m, int w, int **schedule, char **data_ptrs, char **coding_ptrs, int size, int packetsize) { char **ptr_copy; @@ -1238,7 +1238,7 @@ void jerasure_schedule_encode(int k, int m, int w, int **schedule, for (i = 0; i < k; i++) ptr_copy[i] = data_ptrs[i]; for (i = 0; i < m; i++) ptr_copy[i+k] = coding_ptrs[i]; for (tdone = 0; tdone < size; tdone += packetsize*w) { - jerasure_do_scheduled_operations(ptr_copy, schedule, packetsize); + jerasure_do_scheduled_operations(g, ptr_copy, schedule, packetsize); for (i = 0; i < k+m; i++) ptr_copy[i] += (packetsize*w); } free(ptr_copy); @@ -1450,7 +1450,7 @@ int **jerasure_smart_bitmatrix_to_schedule(int k, int m, int w, int *bitmatrix) return NULL; } -void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix, +void jerasure_bitmatrix_encode(gf2_t* g, int k, int m, int w, int *bitmatrix, char **data_ptrs, char **coding_ptrs, int size, int packetsize) { int i; @@ -1466,7 +1466,7 @@ void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix, } for (i = 0; i < m; i++) { - jerasure_bitmatrix_dotprod(k, w, bitmatrix+i*k*w*w, NULL, k+i, data_ptrs, coding_ptrs, size, packetsize); + jerasure_bitmatrix_dotprod(g, k, w, bitmatrix+i*k*w*w, NULL, k+i, data_ptrs, coding_ptrs, size, packetsize); } } @@ -1476,7 +1476,9 @@ void jerasure_bitmatrix_encode(int k, int m, int w, int *bitmatrix, */ int jerasure_autoconf_test() { - int x = galois_single_multiply(1, 2, 8); + gf2_t* g = galois_init_empty(); + int x = galois_single_multiply(g, 1, 2, 8); + galois_destroy(g); if (x != 2) { return -1; } diff --git a/src/reed_sol.c b/src/reed_sol.c index 72cbff8..8fe4ca6 100644 --- a/src/reed_sol.c +++ b/src/reed_sol.c @@ -56,7 +56,7 @@ #define talloc(type, num) (type *) malloc(sizeof(type)*(num)) -int *reed_sol_r6_coding_matrix(int k, int w) +int *reed_sol_r6_coding_matrix(gf2_t* g, int k, int w) { int *matrix; int i, tmp; @@ -70,18 +70,18 @@ int *reed_sol_r6_coding_matrix(int k, int w) matrix[k] = 1; tmp = 1; for (i = 1; i < k; i++) { - tmp = galois_single_multiply(tmp, 2, w); + tmp = galois_single_multiply(g, tmp, 2, w); matrix[k+i] = tmp; } return matrix; } -int *reed_sol_vandermonde_coding_matrix(int k, int m, int w) +int *reed_sol_vandermonde_coding_matrix(gf2_t* g, int k, int m, int w) { int i, j; int *vdm, *dist; - vdm = reed_sol_big_vandermonde_distribution_matrix(k+m, k, w); + vdm = reed_sol_big_vandermonde_distribution_matrix(g, k+m, k, w); if (vdm == NULL) return NULL; dist = talloc(int, m*k); if (dist == NULL) { @@ -101,10 +101,10 @@ int *reed_sol_vandermonde_coding_matrix(int k, int m, int w) static int prim08 = -1; static gf_t GF08; -void reed_sol_galois_w08_region_multby_2(char *region, int nbytes) +void reed_sol_galois_w08_region_multby_2(gf2_t* g, char *region, int nbytes) { if (prim08 == -1) { - prim08 = galois_single_multiply((1 << 7), 2, 8); + prim08 = galois_single_multiply(g, (1 << 7), 2, 8); if (!gf_init_hard(&GF08, 8, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT, prim08, 0, 0, NULL, NULL)) { fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w08_region_multby_2\n"); @@ -117,10 +117,10 @@ void reed_sol_galois_w08_region_multby_2(char *region, int nbytes) static int prim16 = -1; static gf_t GF16; -void reed_sol_galois_w16_region_multby_2(char *region, int nbytes) +void reed_sol_galois_w16_region_multby_2(gf2_t* g, char *region, int nbytes) { if (prim16 == -1) { - prim16 = galois_single_multiply((1 << 15), 2, 16); + prim16 = galois_single_multiply(g, (1 << 15), 2, 16); if (!gf_init_hard(&GF16, 16, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT, prim16, 0, 0, NULL, NULL)) { fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w16_region_multby_2\n"); @@ -133,10 +133,10 @@ void reed_sol_galois_w16_region_multby_2(char *region, int nbytes) static int prim32 = -1; static gf_t GF32; -void reed_sol_galois_w32_region_multby_2(char *region, int nbytes) +void reed_sol_galois_w32_region_multby_2(gf2_t* g, char *region, int nbytes) { if (prim32 == -1) { - prim32 = galois_single_multiply(((gf_val_32_t)1 << 31), 2, 32); + prim32 = galois_single_multiply(g, ((gf_val_32_t)1 << 31), 2, 32); if (!gf_init_hard(&GF32, 32, GF_MULT_BYTWO_b, GF_REGION_DEFAULT, GF_DIVIDE_DEFAULT, prim32, 0, 0, NULL, NULL)) { fprintf(stderr, "Error: Can't initialize the GF for reed_sol_galois_w32_region_multby_2\n"); @@ -146,7 +146,7 @@ void reed_sol_galois_w32_region_multby_2(char *region, int nbytes) GF32.multiply_region.w32(&GF32, region, region, 2, nbytes, 0); } -int reed_sol_r6_encode(int k, int w, char **data_ptrs, char **coding_ptrs, int size) +int reed_sol_r6_encode(gf2_t* g, int k, int w, char **data_ptrs, char **coding_ptrs, int size) { int i; @@ -154,26 +154,27 @@ int reed_sol_r6_encode(int k, int w, char **data_ptrs, char **coding_ptrs, int s memcpy(coding_ptrs[0], data_ptrs[0], size); - for (i = 1; i < k; i++) galois_region_xor(data_ptrs[i], coding_ptrs[0], size); + for (i = 1; i < k; i++) galois_region_xor(g, data_ptrs[i], coding_ptrs[0], size); /* Next, put the sum of (2^j)*Dj into coding region 1 */ memcpy(coding_ptrs[1], data_ptrs[k-1], size); + /* reed_sol_galois_w**_region_multby_2()s are not safe for multithread even if it has the context(gf2_t) */ for (i = k-2; i >= 0; i--) { switch (w) { - case 8: reed_sol_galois_w08_region_multby_2(coding_ptrs[1], size); break; - case 16: reed_sol_galois_w16_region_multby_2(coding_ptrs[1], size); break; - case 32: reed_sol_galois_w32_region_multby_2(coding_ptrs[1], size); break; + case 8: reed_sol_galois_w08_region_multby_2(g, coding_ptrs[1], size); break; + case 16: reed_sol_galois_w16_region_multby_2(g, coding_ptrs[1], size); break; + case 32: reed_sol_galois_w32_region_multby_2(g, coding_ptrs[1], size); break; default: return 0; } - galois_region_xor(data_ptrs[i], coding_ptrs[1], size); + galois_region_xor(g, data_ptrs[i], coding_ptrs[1], size); } return 1; } -int *reed_sol_extended_vandermonde_matrix(int rows, int cols, int w) +int *reed_sol_extended_vandermonde_matrix(gf2_t* g, int rows, int cols, int w) { int *vdm; int i, j, k; @@ -197,13 +198,13 @@ int *reed_sol_extended_vandermonde_matrix(int rows, int cols, int w) k = 1; for (j = 0; j < cols; j++) { vdm[i*cols+j] = k; - k = galois_single_multiply(k, i, w); + k = galois_single_multiply(g, k, i, w); } } return vdm; } -int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w) +int *reed_sol_big_vandermonde_distribution_matrix(gf2_t* g, int rows, int cols, int w) { int *dist; int i, j, k; @@ -211,7 +212,7 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w) if (cols >= rows) return NULL; - dist = reed_sol_extended_vandermonde_matrix(rows, cols, w); + dist = reed_sol_extended_vandermonde_matrix(g, rows, cols, w); if (dist == NULL) return NULL; sindex = 0; @@ -240,10 +241,10 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w) /* If Element i,i is not equal to 1, multiply the column by 1/i */ if (dist[sindex+i] != 1) { - tmp = galois_single_divide(1, dist[sindex+i], w); + tmp = galois_single_divide(g, 1, dist[sindex+i], w); srindex = i; for (j = 0; j < rows; j++) { - dist[srindex] = galois_single_multiply(tmp, dist[srindex], w); + dist[srindex] = galois_single_multiply(g, tmp, dist[srindex], w); srindex += cols; } } @@ -260,7 +261,7 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w) srindex = j; siindex = i; for (k = 0; k < rows; k++) { - dist[srindex] = dist[srindex] ^ galois_single_multiply(tmp, dist[siindex], w); + dist[srindex] = dist[srindex] ^ galois_single_multiply(g, tmp, dist[siindex], w); srindex += cols; siindex += cols; } @@ -274,10 +275,10 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w) for (j = 0; j < cols; j++) { tmp = dist[sindex]; if (tmp != 1) { - tmp = galois_single_divide(1, tmp, w); + tmp = galois_single_divide(g, 1, tmp, w); srindex = sindex; for (i = cols; i < rows; i++) { - dist[srindex] = galois_single_multiply(tmp, dist[srindex], w); + dist[srindex] = galois_single_multiply(g, tmp, dist[srindex], w); srindex += cols; } } @@ -291,8 +292,8 @@ int *reed_sol_big_vandermonde_distribution_matrix(int rows, int cols, int w) for (i = cols+1; i < rows; i++) { tmp = dist[sindex]; if (tmp != 1) { - tmp = galois_single_divide(1, tmp, w); - for (j = 0; j < cols; j++) dist[sindex+j] = galois_single_multiply(dist[sindex+j], tmp, w); + tmp = galois_single_divide(g, 1, tmp, w); + for (j = 0; j < cols; j++) dist[sindex+j] = galois_single_multiply(g, dist[sindex+j], tmp, w); } sindex += cols; } From 084cbd45c7926c0a45b07bbdfd3391045d9ffde5 Mon Sep 17 00:00:00 2001 From: roentgen <fukasawa666@gmail.com> Date: Fri, 16 Nov 2018 20:19:57 +0900 Subject: [PATCH 2/6] fixed SEGV --- src/galois.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/galois.c b/src/galois.c index b900b32..2b71523 100644 --- a/src/galois.c +++ b/src/galois.c @@ -66,7 +66,7 @@ gf_t *galois_get_field_ptr(gf2_t* g, int w) gf2_t* galois_init_empty() { gf2_t* ptr = (gf2_t *) malloc(sizeof(gf2_t)); - memset(ptr, sizeof(gf2_t), 0); + memset(ptr, 0, sizeof(gf2_t)); return ptr; } From 5cca7df46ba83459fe9c7462d57b06af670838a2 Mon Sep 17 00:00:00 2001 From: yuuya uezato <yuuya_uezato@dwango.co.jp> Date: Mon, 19 Nov 2018 19:25:03 +0900 Subject: [PATCH 3/6] fix a misstake in the galois_change_technique function --- src/galois.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/galois.c b/src/galois.c index 2b71523..1d530ab 100644 --- a/src/galois.c +++ b/src/galois.c @@ -276,7 +276,7 @@ void galois_change_technique(gf2_t *g, gf_t* gf, int w) gf_free(g->gfp_array[w], g->gfp_is_composite[w]); } - g->gfp_array[w] = g; + g->gfp_array[w] = gf; } int galois_single_multiply(gf2_t* g, int x, int y, int w) From a53f2e2ba3b9a3861ef2aec754c670a5f6e0820c Mon Sep 17 00:00:00 2001 From: yuuya uezato <yuuya_uezato@dwango.co.jp> Date: Mon, 19 Nov 2018 19:45:45 +0900 Subject: [PATCH 4/6] bypass the C99 feature, loop initial declarations --- src/galois.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/galois.c b/src/galois.c index 1d530ab..d35751f 100644 --- a/src/galois.c +++ b/src/galois.c @@ -72,12 +72,13 @@ gf2_t* galois_init_empty() void galois_destroy(gf2_t* g) { - if (g) { - free(g->gf); - for (int i = 0; i < MAX_GF_INSTANCES; i ++) - free(galois_get_field_ptr(g, i)); - free(g); - } + if (g) { + free(g->gf); + int i; + for (i = 0; i < MAX_GF_INSTANCES; i++) + free(galois_get_field_ptr(g, i)); + free(g); + } } gf2_t* galois_init_field(int w, From 77c90fd5cc051182c2bc04828a3ed4ac84e45e7c Mon Sep 17 00:00:00 2001 From: yuuya uezato <yuuya_uezato@dwango.co.jp> Date: Fri, 30 Nov 2018 20:02:24 +0900 Subject: [PATCH 5/6] rename libJerasure.* -> libFrugalosJerasure.* --- Examples/Makefile.am | 2 +- src/Makefile.am | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Examples/Makefile.am b/Examples/Makefile.am index defd139..61ba7d5 100644 --- a/Examples/Makefile.am +++ b/Examples/Makefile.am @@ -61,7 +61,7 @@ liberation_01_SOURCES = liberation_01.c decoder_SOURCES = decoder.c encoder_SOURCES = encoder.c -LDADD = ../src/libJerasure.la +LDADD = ../src/libFrugalosJerasure.la decoder_LDADD = $(LDADD) ../src/libtiming.a encoder_LDADD = $(LDADD) ../src/libtiming.a reed_sol_time_gf_LDADD = $(LDADD) ../src/libtiming.a diff --git a/src/Makefile.am b/src/Makefile.am index 070f545..8a7ce22 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,10 +3,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include AM_CFLAGS = $(SIMD_FLAGS) -lib_LTLIBRARIES = libJerasure.la -libJerasure_la_SOURCES = galois.c jerasure.c reed_sol.c cauchy.c liberation.c -libJerasure_la_LDFLAGS = -version-info 2:0:0 -libJerasure_la_LIBADD = -lgf_complete +lib_LTLIBRARIES = libFrugalosJerasure.la +libFrugalosJerasure_la_SOURCES = galois.c jerasure.c reed_sol.c cauchy.c liberation.c +libFrugalosJerasure_la_LDFLAGS = -version-info 2:0:0 +libFrugalosJerasure_la_LIBADD = -lgf_complete include_HEADERS = ../include/jerasure.h # Install additional Jerasure header files in their own directory. From 7e37185929355cbd1b4f06e18c851958577f5b23 Mon Sep 17 00:00:00 2001 From: roentgen <fukasawa666@gmail.com> Date: Tue, 4 Dec 2018 18:43:07 +0900 Subject: [PATCH 6/6] fixed wrong checking of badalloc --- src/galois.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/galois.c b/src/galois.c index d35751f..dd45d4c 100644 --- a/src/galois.c +++ b/src/galois.c @@ -100,7 +100,7 @@ gf2_t* galois_init_field(int w, gf2p = (gf2_t *) malloc(sizeof(gf2_t)); gf2p->gf = (gf_t *) malloc(sizeof(gf_t)); - if (!gf2p || gf2p->gf) { + if (!gf2p || !gf2p->gf) { fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); assert(0); } @@ -153,7 +153,7 @@ gf2_t* galois_init_composite_field(int w, gf2p = (gf2_t *) malloc(sizeof(gf2_t)); gf2p->gf = (gf_t *) malloc(sizeof(gf_t)); - if (!gf2p || gf2p->gf) { + if (!gf2p || !gf2p->gf) { fprintf(stderr, "ERROR -- cannot allocate memory for Galois field w=%d\n", w); assert(0); }