/* *Generatesarandomcodewordandstoresitinc.Generatesrandomerrorsand *erasures,andstorestherandomwordwitherrorsinr.Erasurepositionsare *storedinderrlocs,whileerrlocshasoneofthreevaluesineveryposition: * *0ifthereisnoerrorinthisposition; *1ifthereisasymbolerrorinthisposition; *2ifthereisanerasurewithoutsymbolcorruption. * *Returnsthenumberofcorruptedsymbols.
*/ staticint get_rcw_we(struct rs_control *rs, struct wspace *ws, int len, int errs, int eras)
{ int nroots = rs->codec->nroots; int *derrlocs = ws->derrlocs; int *errlocs = ws->errlocs; int dlen = len - nroots; int nn = rs->codec->nn;
uint16_t *c = ws->c;
uint16_t *r = ws->r; int errval; int errloc; int i;
/* Load c with random data and encode */ for (i = 0; i < dlen; i++)
c[i] = get_random_u32() & nn;
/* Make copyand add errors and erasures */
memcpy(r, c, len * sizeof(*r));
memset(errlocs, 0, len * sizeof(*errlocs));
memset(derrlocs, 0, nroots * sizeof(*derrlocs));
/* Generating random errors */ for (i = 0; i < errs; i++) { do { /* Error value must be nonzero */
errval = get_random_u32() & nn;
} while (errval == 0);
do { /* Must not choose the same location twice */
errloc = get_random_u32_below(len);
} while (errlocs[errloc] != 0);
errlocs[errloc] = 1;
r[errloc] ^= errval;
}
/* Generating random erasures */ for (i = 0; i < eras; i++) { do { /* Must not choose the same location twice */
errloc = get_random_u32_below(len);
} while (errlocs[errloc] != 0);
derrlocs[i] = errloc;
if (ewsc && get_random_u32_below(2)) { /* Erasure with the symbol intact */
errlocs[errloc] = 2;
} else { /* Erasure with corrupted symbol */ do { /* Error value must be nonzero */
errval = get_random_u32() & nn;
} while (errval == 0);
/* Convert to index form */ for (i = 0; i < nroots; i++)
syn[i] = rs->index_of[syn[i]];
}
/* Test up to error correction capacity */ staticvoid test_uc(struct rs_control *rs, int len, int errs, int eras, int trials, struct estat *stat, struct wspace *ws, int method)
{ int dlen = len - rs->codec->nroots; int *derrlocs = ws->derrlocs; int *errlocs = ws->errlocs;
uint16_t *corr = ws->corr;
uint16_t *c = ws->c;
uint16_t *r = ws->r;
uint16_t *s = ws->s; int derrs, nerrs; int i, j;
cutoff = nroots <= len - errs ? nroots : len - errs; for (; eras <= cutoff; eras++)
test_bc(rs, len, errs, eras, trials, &stat, ws);
}
if (v >= V_CSUMMARY) {
pr_info(" decoder gives up: %d / %d\n",
stat.rfail, stat.nwords);
pr_info(" decoder returns success: %d / %d\n",
stat.rsuccess, stat.nwords);
pr_info(" not a codeword: %d / %d\n",
stat.noncw, stat.rsuccess);
}
if (stat.noncw && v >= V_PROGRESS)
pr_warn(" FAIL: %d silent failures!\n", stat.noncw);
return stat.noncw;
}
staticint run_exercise(struct etab *e)
{ int nn = (1 << e->symsize) - 1; int kk = nn - e->nroots; struct rs_control *rsc; int retval = -ENOMEM; int max_pad = kk - 1; int prev_pad = -1; struct wspace *ws; int i;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.