mirror of
https://github.com/intel/isa-l.git
synced 2024-12-12 09:23:50 +01:00
examples: reformat using new code style
Signed-off-by: Marcel Cornu <marcel.d.cornu@intel.com>
This commit is contained in:
parent
300260a4d9
commit
9d99f8215d
@ -49,14 +49,14 @@
|
|||||||
|
|
||||||
int verbose; // Global for tests
|
int verbose; // Global for tests
|
||||||
|
|
||||||
#if defined (_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
# define __builtin_parity(x) (__popcnt64(x) & 1)
|
#define __builtin_parity(x) (__popcnt64(x) & 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (__GNUC__) || defined (__clang__)
|
#if defined(__GNUC__) || defined(__clang__)
|
||||||
# define ATTRIBUTE_TARGET(x) __attribute__((target(x)))
|
#define ATTRIBUTE_TARGET(x) __attribute__((target(x)))
|
||||||
#else
|
#else
|
||||||
# define ATTRIBUTE_TARGET(x)
|
#define ATTRIBUTE_TARGET(x)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct crc64_desc {
|
struct crc64_desc {
|
||||||
@ -66,7 +66,8 @@ struct crc64_desc {
|
|||||||
uint64_t k8;
|
uint64_t k8;
|
||||||
};
|
};
|
||||||
|
|
||||||
void gen_crc64_refl_consts(uint64_t poly, struct crc64_desc *c)
|
void
|
||||||
|
gen_crc64_refl_consts(uint64_t poly, struct crc64_desc *c)
|
||||||
{
|
{
|
||||||
uint64_t quotienth = 0;
|
uint64_t quotienth = 0;
|
||||||
uint64_t div;
|
uint64_t div;
|
||||||
@ -84,7 +85,8 @@ void gen_crc64_refl_consts(uint64_t poly, struct crc64_desc *c)
|
|||||||
c->k8 = poly << 1;
|
c->k8 = poly << 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gen_crc64_norm_consts(uint64_t poly, struct crc64_desc *c)
|
void
|
||||||
|
gen_crc64_norm_consts(uint64_t poly, struct crc64_desc *c)
|
||||||
{
|
{
|
||||||
uint64_t quotientl = 0;
|
uint64_t quotientl = 0;
|
||||||
uint64_t div;
|
uint64_t div;
|
||||||
@ -103,7 +105,8 @@ void gen_crc64_norm_consts(uint64_t poly, struct crc64_desc *c)
|
|||||||
c->k8 = poly;
|
c->k8 = poly;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t calc_xi_mod(int n)
|
uint32_t
|
||||||
|
calc_xi_mod(int n)
|
||||||
{
|
{
|
||||||
uint32_t rem = 0x1ul;
|
uint32_t rem = 0x1ul;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -120,7 +123,8 @@ uint32_t calc_xi_mod(int n)
|
|||||||
return rem;
|
return rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t calc64_refl_xi_mod(int n, struct crc64_desc *c)
|
uint64_t
|
||||||
|
calc64_refl_xi_mod(int n, struct crc64_desc *c)
|
||||||
{
|
{
|
||||||
uint64_t rem = 1ull;
|
uint64_t rem = 1ull;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -137,7 +141,8 @@ uint64_t calc64_refl_xi_mod(int n, struct crc64_desc *c)
|
|||||||
return rem;
|
return rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t calc64_norm_xi_mod(int n, struct crc64_desc *c)
|
uint64_t
|
||||||
|
calc64_norm_xi_mod(int n, struct crc64_desc *c)
|
||||||
{
|
{
|
||||||
uint64_t rem = 1ull;
|
uint64_t rem = 1ull;
|
||||||
int i, j;
|
int i, j;
|
||||||
@ -157,7 +162,8 @@ uint64_t calc64_norm_xi_mod(int n, struct crc64_desc *c)
|
|||||||
// Base function for crc32_iscsi_shiftx() if c++ multi-function versioning
|
// Base function for crc32_iscsi_shiftx() if c++ multi-function versioning
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
static inline uint32_t bit_reverse32(uint32_t x)
|
static inline uint32_t
|
||||||
|
bit_reverse32(uint32_t x)
|
||||||
{
|
{
|
||||||
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
|
x = (((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1));
|
||||||
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
|
x = (((x & 0xcccccccc) >> 2) | ((x & 0x33333333) << 2));
|
||||||
@ -169,7 +175,8 @@ static inline uint32_t bit_reverse32(uint32_t x)
|
|||||||
// Base function for crc32_iscsi_shiftx without clmul optimizations
|
// Base function for crc32_iscsi_shiftx without clmul optimizations
|
||||||
|
|
||||||
ATTRIBUTE_TARGET("default")
|
ATTRIBUTE_TARGET("default")
|
||||||
uint32_t crc32_iscsi_shiftx(uint32_t crc1, uint32_t x)
|
uint32_t
|
||||||
|
crc32_iscsi_shiftx(uint32_t crc1, uint32_t x)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint64_t xrev, q = 0;
|
uint64_t xrev, q = 0;
|
||||||
@ -190,7 +197,8 @@ uint32_t crc32_iscsi_shiftx(uint32_t crc1, uint32_t x)
|
|||||||
#endif // cplusplus
|
#endif // cplusplus
|
||||||
|
|
||||||
ATTRIBUTE_TARGET("pclmul,sse4.2")
|
ATTRIBUTE_TARGET("pclmul,sse4.2")
|
||||||
uint32_t crc32_iscsi_shiftx(uint32_t crc1, uint32_t x)
|
uint32_t
|
||||||
|
crc32_iscsi_shiftx(uint32_t crc1, uint32_t x)
|
||||||
{
|
{
|
||||||
__m128i crc1x, constx;
|
__m128i crc1x, constx;
|
||||||
uint64_t crc64;
|
uint64_t crc64;
|
||||||
@ -204,11 +212,12 @@ uint32_t crc32_iscsi_shiftx(uint32_t crc1, uint32_t x)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ATTRIBUTE_TARGET("pclmul,sse4.2")
|
ATTRIBUTE_TARGET("pclmul,sse4.2")
|
||||||
uint64_t crc64_refl_shiftx(uint64_t crc1, uint64_t x, struct crc64_desc *c)
|
uint64_t
|
||||||
|
crc64_refl_shiftx(uint64_t crc1, uint64_t x, struct crc64_desc *c)
|
||||||
{
|
{
|
||||||
__m128i crc1x, crc2x, crc3x, constx;
|
__m128i crc1x, crc2x, crc3x, constx;
|
||||||
const __m128i rk5 = _mm_loadu_si64(&c->k5);
|
const __m128i rk5 = _mm_loadu_si64(&c->k5);
|
||||||
const __m128i rk7 = _mm_loadu_si128((__m128i *) & c->k7);
|
const __m128i rk7 = _mm_loadu_si128((__m128i *) &c->k7);
|
||||||
|
|
||||||
crc1x = _mm_cvtsi64_si128(crc1);
|
crc1x = _mm_cvtsi64_si128(crc1);
|
||||||
constx = _mm_cvtsi64_si128(x);
|
constx = _mm_cvtsi64_si128(x);
|
||||||
@ -229,11 +238,12 @@ uint64_t crc64_refl_shiftx(uint64_t crc1, uint64_t x, struct crc64_desc *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ATTRIBUTE_TARGET("pclmul,sse4.2")
|
ATTRIBUTE_TARGET("pclmul,sse4.2")
|
||||||
uint64_t crc64_norm_shiftx(uint64_t crc1, uint64_t x, struct crc64_desc *c)
|
uint64_t
|
||||||
|
crc64_norm_shiftx(uint64_t crc1, uint64_t x, struct crc64_desc *c)
|
||||||
{
|
{
|
||||||
__m128i crc1x, crc2x, crc3x, constx;
|
__m128i crc1x, crc2x, crc3x, constx;
|
||||||
const __m128i rk5 = _mm_loadu_si64(&c->k5);
|
const __m128i rk5 = _mm_loadu_si64(&c->k5);
|
||||||
const __m128i rk7 = _mm_loadu_si128((__m128i *) & c->k7);
|
const __m128i rk7 = _mm_loadu_si128((__m128i *) &c->k7);
|
||||||
|
|
||||||
crc1x = _mm_cvtsi64_si128(crc1);
|
crc1x = _mm_cvtsi64_si128(crc1);
|
||||||
constx = _mm_cvtsi64_si128(x);
|
constx = _mm_cvtsi64_si128(x);
|
||||||
@ -252,9 +262,10 @@ uint64_t crc64_norm_shiftx(uint64_t crc1, uint64_t x, struct crc64_desc *c)
|
|||||||
return _mm_extract_epi64(crc1x, 0);
|
return _mm_extract_epi64(crc1x, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t crc32_iscsi_combine_4k(uint32_t * crc_array, int n)
|
uint32_t
|
||||||
|
crc32_iscsi_combine_4k(uint32_t *crc_array, int n)
|
||||||
{
|
{
|
||||||
const uint32_t cn4k = 0x82f89c77; //calc_xi_mod(4*1024);
|
const uint32_t cn4k = 0x82f89c77; // calc_xi_mod(4*1024);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (n < 1)
|
if (n < 1)
|
||||||
@ -270,10 +281,17 @@ uint32_t crc32_iscsi_combine_4k(uint32_t * crc_array, int n)
|
|||||||
|
|
||||||
// Tests
|
// Tests
|
||||||
|
|
||||||
#define printv(...) {if (verbose) printf(__VA_ARGS__); else printf(".");}
|
#define printv(...) \
|
||||||
|
{ \
|
||||||
|
if (verbose) \
|
||||||
|
printf(__VA_ARGS__); \
|
||||||
|
else \
|
||||||
|
printf("."); \
|
||||||
|
}
|
||||||
|
|
||||||
uint64_t test_combine64(uint8_t * inp, size_t len, uint64_t poly, int reflected,
|
uint64_t
|
||||||
uint64_t(*func) (uint64_t, const uint8_t *, uint64_t))
|
test_combine64(uint8_t *inp, size_t len, uint64_t poly, int reflected,
|
||||||
|
uint64_t (*func)(uint64_t, const uint8_t *, uint64_t))
|
||||||
{
|
{
|
||||||
|
|
||||||
uint64_t crc64_init, crc64, crc64a, crc64b;
|
uint64_t crc64_init, crc64, crc64a, crc64b;
|
||||||
@ -341,13 +359,14 @@ uint64_t test_combine64(uint8_t * inp, size_t len, uint64_t poly, int reflected,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#define N (1024)
|
#define N (1024)
|
||||||
#define B (2*N)
|
#define B (2 * N)
|
||||||
#define T (3*N)
|
#define T (3 * N)
|
||||||
#define N4k (4*1024)
|
#define N4k (4 * 1024)
|
||||||
#define NMAX 32
|
#define NMAX 32
|
||||||
#define NMAX_SIZE (NMAX * N4k)
|
#define NMAX_SIZE (NMAX * N4k)
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint32_t crc, crca, crcb, crc1, crc2, crc3, crcn;
|
uint32_t crc, crca, crcb, crc1, crc2, crc3, crcn;
|
||||||
@ -384,8 +403,7 @@ int main(int argc, char *argv[])
|
|||||||
crc1 = crc32_iscsi(&inp[0], 100, crc_init);
|
crc1 = crc32_iscsi(&inp[0], 100, crc_init);
|
||||||
crc2 = crc32_iscsi(&inp[100], 100, 0);
|
crc2 = crc32_iscsi(&inp[100], 100, 0);
|
||||||
crc3 = crc32_iscsi(&inp[200], B - 200, 0);
|
crc3 = crc32_iscsi(&inp[200], B - 200, 0);
|
||||||
crcn = crc3 ^
|
crcn = crc3 ^ crc32_iscsi_shiftx(crc2, calc_xi_mod(B - 200)) ^
|
||||||
crc32_iscsi_shiftx(crc2, calc_xi_mod(B - 200)) ^
|
|
||||||
crc32_iscsi_shiftx(crc1, calc_xi_mod(B - 100));
|
crc32_iscsi_shiftx(crc1, calc_xi_mod(B - 100));
|
||||||
printv("crcB combined3 = 0x%" PRIx32 "\n\n", crcn);
|
printv("crcB combined3 = 0x%" PRIx32 "\n\n", crcn);
|
||||||
err |= crcn ^ crc;
|
err |= crcn ^ crc;
|
||||||
@ -398,16 +416,14 @@ int main(int argc, char *argv[])
|
|||||||
crc1 = crc32_iscsi(&inp[0], N, crc_init);
|
crc1 = crc32_iscsi(&inp[0], N, crc_init);
|
||||||
crc2 = crc32_iscsi(&inp[N], N, 0);
|
crc2 = crc32_iscsi(&inp[N], N, 0);
|
||||||
crc3 = crc32_iscsi(&inp[2 * N], N, 0);
|
crc3 = crc32_iscsi(&inp[2 * N], N, 0);
|
||||||
crcn = crc3 ^
|
crcn = crc3 ^ crc32_iscsi_shiftx(crc2, calc_xi_mod(N)) ^
|
||||||
crc32_iscsi_shiftx(crc2, calc_xi_mod(N)) ^
|
|
||||||
crc32_iscsi_shiftx(crc1, calc_xi_mod(2 * N));
|
crc32_iscsi_shiftx(crc1, calc_xi_mod(2 * N));
|
||||||
printv("crcT combined3 = 0x%" PRIx32 "\n", crcn);
|
printv("crcT combined3 = 0x%" PRIx32 "\n", crcn);
|
||||||
err |= crcn ^ crc;
|
err |= crcn ^ crc;
|
||||||
|
|
||||||
// Combine 3 segments with one const by sequential shift
|
// Combine 3 segments with one const by sequential shift
|
||||||
uint32_t xi_mod_n = calc_xi_mod(N);
|
uint32_t xi_mod_n = calc_xi_mod(N);
|
||||||
crcn = crc3 ^ crc32_iscsi_shiftx(crc32_iscsi_shiftx(crc1, xi_mod_n)
|
crcn = crc3 ^ crc32_iscsi_shiftx(crc32_iscsi_shiftx(crc1, xi_mod_n) ^ crc2, xi_mod_n);
|
||||||
^ crc2, xi_mod_n);
|
|
||||||
printv("crcT comb3 seq = 0x%" PRIx32 "\n\n", crcn);
|
printv("crcT comb3 seq = 0x%" PRIx32 "\n\n", crcn);
|
||||||
err |= crcn ^ crc;
|
err |= crcn ^ crc;
|
||||||
|
|
||||||
|
@ -40,7 +40,8 @@
|
|||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
|
||||||
int usage(void)
|
int
|
||||||
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: ec_piggyback_example [options]\n"
|
"Usage: ec_piggyback_example [options]\n"
|
||||||
@ -57,7 +58,8 @@ int usage(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cauchy-based matrix
|
// Cauchy-based matrix
|
||||||
void gf_gen_full_pb_cauchy_matrix(u8 * a, int m, int k)
|
void
|
||||||
|
gf_gen_full_pb_cauchy_matrix(u8 *a, int m, int k)
|
||||||
{
|
{
|
||||||
int i, j, p = m - k;
|
int i, j, p = m - k;
|
||||||
|
|
||||||
@ -94,7 +96,8 @@ void gf_gen_full_pb_cauchy_matrix(u8 * a, int m, int k)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Vandermonde based matrix - not recommended due to limits when invertable
|
// Vandermonde based matrix - not recommended due to limits when invertable
|
||||||
void gf_gen_full_pb_vand_matrix(u8 * a, int m, int k)
|
void
|
||||||
|
gf_gen_full_pb_vand_matrix(u8 *a, int m, int k)
|
||||||
{
|
{
|
||||||
int i, j, p = m - k;
|
int i, j, p = m - k;
|
||||||
unsigned char q, gen = 1;
|
unsigned char q, gen = 1;
|
||||||
@ -141,7 +144,8 @@ void gf_gen_full_pb_vand_matrix(u8 * a, int m, int k)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_matrix(int m, int k, unsigned char *s, const char *msg)
|
void
|
||||||
|
print_matrix(int m, int k, unsigned char *s, const char *msg)
|
||||||
{
|
{
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
@ -156,7 +160,8 @@ void print_matrix(int m, int k, unsigned char *s, const char *msg)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void print_list(int n, unsigned char *s, const char *msg)
|
void
|
||||||
|
print_list(int n, unsigned char *s, const char *msg)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
if (!verbose)
|
if (!verbose)
|
||||||
@ -168,14 +173,12 @@ void print_list(int n, unsigned char *s, const char *msg)
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gf_gen_decode_matrix(u8 * encode_matrix,
|
static int
|
||||||
u8 * decode_matrix,
|
gf_gen_decode_matrix(u8 *encode_matrix, u8 *decode_matrix, u8 *invert_matrix, u8 *temp_matrix,
|
||||||
u8 * invert_matrix,
|
u8 *decode_index, u8 *frag_err_list, int nerrs, int k, int m);
|
||||||
u8 * temp_matrix,
|
|
||||||
u8 * decode_index,
|
|
||||||
u8 * frag_err_list, int nerrs, int k, int m);
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, m, c, e, ret;
|
int i, j, m, c, e, ret;
|
||||||
int k = 10, p = 4, len = 8 * 1024; // Default params
|
int k = 10, p = 4, len = 8 * 1024; // Default params
|
||||||
@ -246,13 +249,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Check for valid parameters
|
// Check for valid parameters
|
||||||
if (m > (MMAX / 2) || k > (KMAX / 2) || m < 0 || p < 2 || k < 1) {
|
if (m > (MMAX / 2) || k > (KMAX / 2) || m < 0 || p < 2 || k < 1) {
|
||||||
printf(" Input test parameter error m=%d, k=%d, p=%d, erasures=%d\n",
|
printf(" Input test parameter error m=%d, k=%d, p=%d, erasures=%d\n", m, k, p,
|
||||||
m, k, p, nerrs);
|
nerrs);
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
if (nerrs > p) {
|
if (nerrs > p) {
|
||||||
printf(" Number of erasures chosen exceeds power of code erasures=%d p=%d\n",
|
printf(" Number of erasures chosen exceeds power of code erasures=%d p=%d\n", nerrs,
|
||||||
nerrs, p);
|
p);
|
||||||
}
|
}
|
||||||
for (i = 0; i < nerrs; i++) {
|
for (i = 0; i < nerrs; i++) {
|
||||||
if (frag_err_list[i] >= m)
|
if (frag_err_list[i] >= m)
|
||||||
@ -279,8 +282,8 @@ int main(int argc, char *argv[])
|
|||||||
temp_matrix = malloc(m2 * k2);
|
temp_matrix = malloc(m2 * k2);
|
||||||
g_tbls = malloc(k2 * p2 * 32);
|
g_tbls = malloc(k2 * p2 * 32);
|
||||||
|
|
||||||
if (encode_matrix == NULL || decode_matrix == NULL
|
if (encode_matrix == NULL || decode_matrix == NULL || invert_matrix == NULL ||
|
||||||
|| invert_matrix == NULL || temp_matrix == NULL || g_tbls == NULL) {
|
temp_matrix == NULL || g_tbls == NULL) {
|
||||||
printf("Test failure! Error with malloc\n");
|
printf("Test failure! Error with malloc\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -336,8 +339,7 @@ int main(int argc, char *argv[])
|
|||||||
if (benchmark) {
|
if (benchmark) {
|
||||||
struct perf start;
|
struct perf start;
|
||||||
BENCHMARK(&start, BENCHMARK_TIME,
|
BENCHMARK(&start, BENCHMARK_TIME,
|
||||||
ec_encode_data(len / 2, k2, p2, g_tbls, frag_ptrs,
|
ec_encode_data(len / 2, k2, p2, g_tbls, frag_ptrs, parity_ptrs));
|
||||||
parity_ptrs));
|
|
||||||
printf("ec_piggyback_encode_std: ");
|
printf("ec_piggyback_encode_std: ");
|
||||||
perf_print(start, m2 * len / 2);
|
perf_print(start, m2 * len / 2);
|
||||||
}
|
}
|
||||||
@ -362,8 +364,7 @@ int main(int argc, char *argv[])
|
|||||||
memcpy(&encode_matrix_faster[k * i], &encode_matrix[k2 * j], k);
|
memcpy(&encode_matrix_faster[k * i], &encode_matrix[k2 * j], k);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
print_matrix(p, k, &encode_matrix_faster[k * k],
|
print_matrix(p, k, &encode_matrix_faster[k * k], "encode via sparse-opt");
|
||||||
"encode via sparse-opt");
|
|
||||||
print_matrix(p2 / 2, k2, &encode_matrix[(k2 + p2 / 2) * k2],
|
print_matrix(p2 / 2, k2, &encode_matrix[(k2 + p2 / 2) * k2],
|
||||||
"encode via sparse-opt");
|
"encode via sparse-opt");
|
||||||
}
|
}
|
||||||
@ -372,16 +373,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Generate EC parity blocks from sources
|
// Generate EC parity blocks from sources
|
||||||
ec_encode_data(len / 2, k, p, g_tbls_faster, frag_ptrs, parity_ptrs);
|
ec_encode_data(len / 2, k, p, g_tbls_faster, frag_ptrs, parity_ptrs);
|
||||||
ec_encode_data(len / 2, k2, p, &g_tbls[k2 * p * 32], frag_ptrs,
|
ec_encode_data(len / 2, k2, p, &g_tbls[k2 * p * 32], frag_ptrs, &parity_ptrs[p]);
|
||||||
&parity_ptrs[p]);
|
|
||||||
|
|
||||||
if (benchmark) {
|
if (benchmark) {
|
||||||
struct perf start;
|
struct perf start;
|
||||||
BENCHMARK(&start, BENCHMARK_TIME,
|
BENCHMARK(&start, BENCHMARK_TIME,
|
||||||
ec_encode_data(len / 2, k, p, g_tbls_faster, frag_ptrs,
|
ec_encode_data(len / 2, k, p, g_tbls_faster, frag_ptrs,
|
||||||
parity_ptrs);
|
parity_ptrs);
|
||||||
ec_encode_data(len / 2, k2, p, &g_tbls[k2 * p * 32],
|
ec_encode_data(len / 2, k2, p, &g_tbls[k2 * p * 32], frag_ptrs,
|
||||||
frag_ptrs, &parity_ptrs[p]));
|
&parity_ptrs[p]));
|
||||||
printf("ec_piggyback_encode_sparse: ");
|
printf("ec_piggyback_encode_sparse: ");
|
||||||
perf_print(start, m2 * len / 2);
|
perf_print(start, m2 * len / 2);
|
||||||
}
|
}
|
||||||
@ -399,9 +399,8 @@ int main(int argc, char *argv[])
|
|||||||
print_list(nerrs2, frag_err_list, " frag err list");
|
print_list(nerrs2, frag_err_list, " frag err list");
|
||||||
|
|
||||||
// Find a decode matrix to regenerate all erasures from remaining frags
|
// Find a decode matrix to regenerate all erasures from remaining frags
|
||||||
ret = gf_gen_decode_matrix(encode_matrix, decode_matrix,
|
ret = gf_gen_decode_matrix(encode_matrix, decode_matrix, invert_matrix, temp_matrix,
|
||||||
invert_matrix, temp_matrix, decode_index, frag_err_list,
|
decode_index, frag_err_list, nerrs2, k2, m2);
|
||||||
nerrs2, k2, m2);
|
|
||||||
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("Fail on generate decode matrix\n");
|
printf("Fail on generate decode matrix\n");
|
||||||
@ -423,8 +422,7 @@ int main(int argc, char *argv[])
|
|||||||
if (benchmark) {
|
if (benchmark) {
|
||||||
struct perf start;
|
struct perf start;
|
||||||
BENCHMARK(&start, BENCHMARK_TIME,
|
BENCHMARK(&start, BENCHMARK_TIME,
|
||||||
ec_encode_data(len / 2, k2, nerrs2, g_tbls, recover_srcs,
|
ec_encode_data(len / 2, k2, nerrs2, g_tbls, recover_srcs, recover_outp));
|
||||||
recover_outp));
|
|
||||||
printf("ec_piggyback_decode: ");
|
printf("ec_piggyback_decode: ");
|
||||||
perf_print(start, (k2 + nerrs2) * len / 2);
|
perf_print(start, (k2 + nerrs2) * len / 2);
|
||||||
}
|
}
|
||||||
@ -444,11 +442,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Generate decode matrix from encode matrix and erasure list
|
// Generate decode matrix from encode matrix and erasure list
|
||||||
|
|
||||||
static int gf_gen_decode_matrix(u8 * encode_matrix,
|
static int
|
||||||
u8 * decode_matrix,
|
gf_gen_decode_matrix(u8 *encode_matrix, u8 *decode_matrix, u8 *invert_matrix, u8 *temp_matrix,
|
||||||
u8 * invert_matrix,
|
u8 *decode_index, u8 *frag_err_list, int nerrs, int k, int m)
|
||||||
u8 * temp_matrix,
|
|
||||||
u8 * decode_index, u8 * frag_err_list, int nerrs, int k, int m)
|
|
||||||
{
|
{
|
||||||
int i, j, p, r;
|
int i, j, p, r;
|
||||||
int nsrcerrs = 0;
|
int nsrcerrs = 0;
|
||||||
|
@ -38,7 +38,8 @@
|
|||||||
|
|
||||||
typedef unsigned char u8;
|
typedef unsigned char u8;
|
||||||
|
|
||||||
int usage(void)
|
int
|
||||||
|
usage(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: ec_simple_example [options]\n"
|
"Usage: ec_simple_example [options]\n"
|
||||||
@ -51,14 +52,13 @@ int usage(void)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int gf_gen_decode_matrix_simple(u8 * encode_matrix,
|
static int
|
||||||
u8 * decode_matrix,
|
gf_gen_decode_matrix_simple(u8 *encode_matrix, u8 *decode_matrix, u8 *invert_matrix,
|
||||||
u8 * invert_matrix,
|
u8 *temp_matrix, u8 *decode_index, u8 *frag_err_list, int nerrs, int k,
|
||||||
u8 * temp_matrix,
|
int m);
|
||||||
u8 * decode_index,
|
|
||||||
u8 * frag_err_list, int nerrs, int k, int m);
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int i, j, m, c, e, ret;
|
int i, j, m, c, e, ret;
|
||||||
int k = 10, p = 4, len = 8 * 1024; // Default params
|
int k = 10, p = 4, len = 8 * 1024; // Default params
|
||||||
@ -116,13 +116,13 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Check for valid parameters
|
// Check for valid parameters
|
||||||
if (m > MMAX || k > KMAX || m < 0 || p < 1 || k < 1) {
|
if (m > MMAX || k > KMAX || m < 0 || p < 1 || k < 1) {
|
||||||
printf(" Input test parameter error m=%d, k=%d, p=%d, erasures=%d\n",
|
printf(" Input test parameter error m=%d, k=%d, p=%d, erasures=%d\n", m, k, p,
|
||||||
m, k, p, nerrs);
|
nerrs);
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
if (nerrs > p) {
|
if (nerrs > p) {
|
||||||
printf(" Number of erasures chosen exceeds power of code erasures=%d p=%d\n",
|
printf(" Number of erasures chosen exceeds power of code erasures=%d p=%d\n", nerrs,
|
||||||
nerrs, p);
|
p);
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
for (i = 0; i < nerrs; i++) {
|
for (i = 0; i < nerrs; i++) {
|
||||||
@ -141,8 +141,8 @@ int main(int argc, char *argv[])
|
|||||||
temp_matrix = malloc(m * k);
|
temp_matrix = malloc(m * k);
|
||||||
g_tbls = malloc(k * p * 32);
|
g_tbls = malloc(k * p * 32);
|
||||||
|
|
||||||
if (encode_matrix == NULL || decode_matrix == NULL
|
if (encode_matrix == NULL || decode_matrix == NULL || invert_matrix == NULL ||
|
||||||
|| invert_matrix == NULL || temp_matrix == NULL || g_tbls == NULL) {
|
temp_matrix == NULL || g_tbls == NULL) {
|
||||||
printf("Test failure! Error with malloc\n");
|
printf("Test failure! Error with malloc\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -185,9 +185,8 @@ int main(int argc, char *argv[])
|
|||||||
printf(" recover %d fragments\n", nerrs);
|
printf(" recover %d fragments\n", nerrs);
|
||||||
|
|
||||||
// Find a decode matrix to regenerate all erasures from remaining frags
|
// Find a decode matrix to regenerate all erasures from remaining frags
|
||||||
ret = gf_gen_decode_matrix_simple(encode_matrix, decode_matrix,
|
ret = gf_gen_decode_matrix_simple(encode_matrix, decode_matrix, invert_matrix, temp_matrix,
|
||||||
invert_matrix, temp_matrix, decode_index,
|
decode_index, frag_err_list, nerrs, k, m);
|
||||||
frag_err_list, nerrs, k, m);
|
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("Fail on generate decode matrix\n");
|
printf("Fail on generate decode matrix\n");
|
||||||
return -1;
|
return -1;
|
||||||
@ -219,11 +218,9 @@ int main(int argc, char *argv[])
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int gf_gen_decode_matrix_simple(u8 * encode_matrix,
|
static int
|
||||||
u8 * decode_matrix,
|
gf_gen_decode_matrix_simple(u8 *encode_matrix, u8 *decode_matrix, u8 *invert_matrix,
|
||||||
u8 * invert_matrix,
|
u8 *temp_matrix, u8 *decode_index, u8 *frag_err_list, int nerrs, int k,
|
||||||
u8 * temp_matrix,
|
|
||||||
u8 * decode_index, u8 * frag_err_list, int nerrs, int k,
|
|
||||||
int m)
|
int m)
|
||||||
{
|
{
|
||||||
int i, j, p, r;
|
int i, j, p, r;
|
||||||
@ -257,8 +254,7 @@ static int gf_gen_decode_matrix_simple(u8 * encode_matrix,
|
|||||||
for (i = 0; i < nerrs; i++) {
|
for (i = 0; i < nerrs; i++) {
|
||||||
if (frag_err_list[i] < k) // A src err
|
if (frag_err_list[i] < k) // A src err
|
||||||
for (j = 0; j < k; j++)
|
for (j = 0; j < k; j++)
|
||||||
decode_matrix[k * i + j] =
|
decode_matrix[k * i + j] = invert_matrix[k * frag_err_list[i] + j];
|
||||||
invert_matrix[k * frag_err_list[i] + j];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// For non-src (parity) erasures need to multiply encode matrix * invert
|
// For non-src (parity) erasures need to multiply encode matrix * invert
|
||||||
|
Loading…
Reference in New Issue
Block a user