From 6b3bc5e534d2c1d3b4f8bdfae782beec6597c22d Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Thu, 27 Sep 2018 10:33:47 +0200 Subject: [PATCH] added update_syndromes() helper --- bose_chaudhuri_hocquenghem_decoder.hh | 40 +++++++++++++++++---------- reed_solomon_decoder.hh | 20 +++++++++----- 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/bose_chaudhuri_hocquenghem_decoder.hh b/bose_chaudhuri_hocquenghem_decoder.hh index fedb0a1..2217a04 100644 --- a/bose_chaudhuri_hocquenghem_decoder.hh +++ b/bose_chaudhuri_hocquenghem_decoder.hh @@ -20,21 +20,27 @@ public: typedef typename GF::ValueType ValueType; typedef typename GF::IndexType IndexType; static const int N = GF::N, K = MSG, NP = N - K; +private: ReedSolomonErrorCorrection algorithm; - int compute_syndromes(uint8_t *code, ValueType *syndromes) + void update_syndromes(uint8_t *poly, ValueType *syndromes, int begin, int end) { - // $syndromes_i = code(pe^{FCR+i})$ - ValueType coeff(get_be_bit(code, 0)); - for (int i = 0; i < NR; ++i) - syndromes[i] = coeff; - for (int j = 1; j < N; ++j) { - ValueType coeff(get_be_bit(code, j)); + for (int j = begin; j < end; ++j) { + ValueType coeff(get_be_bit(poly, j)); IndexType root(FCR), pe(1); for (int i = 0; i < NR; ++i) { syndromes[i] = fma(root, syndromes[i], coeff); root *= pe; } } + } +public: + int compute_syndromes(uint8_t *code, ValueType *syndromes) + { + // $syndromes_i = code(pe^{FCR+i})$ + ValueType coeff(get_be_bit(code, 0)); + for (int i = 0; i < NR; ++i) + syndromes[i] = coeff; + update_syndromes(code, syndromes, 1, N); int nonzero = 0; for (int i = 0; i < NR; ++i) nonzero += !!syndromes[i]; @@ -79,21 +85,27 @@ public: typedef typename GF::ValueType ValueType; typedef typename GF::IndexType IndexType; static const int N = GF::N, K = MSG, NP = N - K; +private: ReedSolomonErrorCorrection algorithm; - int compute_syndromes(ValueType *code, ValueType *syndromes) + void update_syndromes(ValueType *poly, ValueType *syndromes, int begin, int end) { - // $syndromes_i = code(pe^{FCR+i})$ - ValueType coeff(code[0]); - for (int i = 0; i < NR; ++i) - syndromes[i] = coeff; - for (int j = 1; j < N; ++j) { - ValueType coeff(code[j]); + for (int j = begin; j < end; ++j) { + ValueType coeff(poly[j]); IndexType root(FCR), pe(1); for (int i = 0; i < NR; ++i) { syndromes[i] = fma(root, syndromes[i], coeff); root *= pe; } } + } +public: + int compute_syndromes(ValueType *code, ValueType *syndromes) + { + // $syndromes_i = code(pe^{FCR+i})$ + ValueType coeff(code[0]); + for (int i = 0; i < NR; ++i) + syndromes[i] = coeff; + update_syndromes(code, syndromes, 1, N); int nonzero = 0; for (int i = 0; i < NR; ++i) nonzero += !!syndromes[i]; diff --git a/reed_solomon_decoder.hh b/reed_solomon_decoder.hh index 2334880..2175c35 100644 --- a/reed_solomon_decoder.hh +++ b/reed_solomon_decoder.hh @@ -19,21 +19,27 @@ public: typedef typename GF::ValueType ValueType; typedef typename GF::IndexType IndexType; static const int N = GF::N, K = N - NR, NP = NR; +private: ReedSolomonErrorCorrection algorithm; - int compute_syndromes(ValueType *code, ValueType *syndromes) + void update_syndromes(ValueType *poly, ValueType *syndromes, int begin, int end) { - // $syndromes_i = code(pe^{FCR+i})$ - ValueType coeff(code[0]); - for (int i = 0; i < NR; ++i) - syndromes[i] = coeff; - for (int j = 1; j < N; ++j) { - ValueType coeff(code[j]); + for (int j = begin; j < end; ++j) { + ValueType coeff(poly[j]); IndexType root(FCR), pe(1); for (int i = 0; i < NR; ++i) { syndromes[i] = fma(root, syndromes[i], coeff); root *= pe; } } + } +public: + int compute_syndromes(ValueType *code, ValueType *syndromes) + { + // $syndromes_i = code(pe^{FCR+i})$ + ValueType coeff(code[0]); + for (int i = 0; i < NR; ++i) + syndromes[i] = coeff; + update_syndromes(code, syndromes, 1, N); int nonzero = 0; for (int i = 0; i < NR; ++i) nonzero += !!syndromes[i];