diff --git a/bose_chaudhuri_hocquenghem_decoder.hh b/bose_chaudhuri_hocquenghem_decoder.hh index 2217a04..176a2be 100644 --- a/bose_chaudhuri_hocquenghem_decoder.hh +++ b/bose_chaudhuri_hocquenghem_decoder.hh @@ -34,31 +34,37 @@ private: } } public: - int compute_syndromes(uint8_t *code, ValueType *syndromes) + int compute_syndromes(uint8_t *data, uint8_t *parity, ValueType *syndromes) { // $syndromes_i = code(pe^{FCR+i})$ - ValueType coeff(get_be_bit(code, 0)); + ValueType coeff(get_be_bit(data, 0)); for (int i = 0; i < NR; ++i) syndromes[i] = coeff; - update_syndromes(code, syndromes, 1, N); + update_syndromes(data, syndromes, 1, K); + update_syndromes(parity, syndromes, 0, NP); int nonzero = 0; for (int i = 0; i < NR; ++i) nonzero += !!syndromes[i]; return nonzero; } - int compute_syndromes(uint8_t *code, value_type *syndromes) + int compute_syndromes(uint8_t *data, uint8_t *parity, value_type *syndromes) { - return compute_syndromes(code, reinterpret_cast(syndromes)); + return compute_syndromes(data, parity, reinterpret_cast(syndromes)); } - int operator()(uint8_t *code, value_type *erasures = 0, int erasures_count = 0) + int operator()(uint8_t *data, uint8_t *parity, value_type *erasures = 0, int erasures_count = 0) { assert(0 <= erasures_count && erasures_count <= NR); if (0) { - for (int i = 0; i < erasures_count; ++i) - set_be_bit(code, erasures[i], 0); + for (int i = 0; i < erasures_count; ++i) { + int idx = (int)erasures[i]; + if (idx < K) + set_be_bit(data, idx, 0); + else + set_be_bit(parity, idx-K, 0); + } } ValueType syndromes[NR]; - if (!compute_syndromes(code, syndromes)) + if (!compute_syndromes(data, parity, syndromes)) return 0; IndexType locations[NR]; ValueType magnitudes[NR]; @@ -68,8 +74,14 @@ public: for (int i = 0; i < count; ++i) if (1 < (int)magnitudes[i]) return -1; - for (int i = 0; i < count; ++i) - xor_be_bit(code, (int)locations[i], (bool)magnitudes[i]); + for (int i = 0; i < count; ++i) { + int idx = (int)locations[i]; + bool err = (bool)magnitudes[i]; + if (idx < K) + xor_be_bit(data, idx, err); + else + xor_be_bit(parity, idx-K, err); + } int corrections_count = 0; for (int i = 0; i < count; ++i) corrections_count += !!magnitudes[i]; @@ -99,27 +111,33 @@ private: } } public: - int compute_syndromes(ValueType *code, ValueType *syndromes) + int compute_syndromes(ValueType *data, ValueType *parity, ValueType *syndromes) { // $syndromes_i = code(pe^{FCR+i})$ - ValueType coeff(code[0]); + ValueType coeff(data[0]); for (int i = 0; i < NR; ++i) syndromes[i] = coeff; - update_syndromes(code, syndromes, 1, N); + update_syndromes(data, syndromes, 1, K); + update_syndromes(parity, syndromes, 0, NP); int nonzero = 0; for (int i = 0; i < NR; ++i) nonzero += !!syndromes[i]; return nonzero; } - int operator()(ValueType *code, IndexType *erasures = 0, int erasures_count = 0) + int operator()(ValueType *data, ValueType *parity, IndexType *erasures = 0, int erasures_count = 0) { assert(0 <= erasures_count && erasures_count <= NR); if (0) { - for (int i = 0; i < erasures_count; ++i) - code[(int)erasures[i]] = ValueType(0); + for (int i = 0; i < erasures_count; ++i) { + int idx = (int)erasures[i]; + if (idx < K) + data[idx] = ValueType(0); + else + parity[idx-K] = ValueType(0); + } } ValueType syndromes[NR]; - if (!compute_syndromes(code, syndromes)) + if (!compute_syndromes(data, parity, syndromes)) return 0; IndexType locations[NR]; ValueType magnitudes[NR]; @@ -129,8 +147,13 @@ public: for (int i = 0; i < count; ++i) if (1 < (int)magnitudes[i]) return -1; - for (int i = 0; i < count; ++i) - code[(int)locations[i]] += magnitudes[i]; + for (int i = 0; i < count; ++i) { + int idx = (int)locations[i]; + if (idx < K) + data[idx] += magnitudes[i]; + else + parity[idx-K] += magnitudes[i]; + } int corrections_count = 0; for (int i = 0; i < count; ++i) corrections_count += !!magnitudes[i]; diff --git a/bose_chaudhuri_hocquenghem_encoder.hh b/bose_chaudhuri_hocquenghem_encoder.hh index 4318d69..0b24830 100644 --- a/bose_chaudhuri_hocquenghem_encoder.hh +++ b/bose_chaudhuri_hocquenghem_encoder.hh @@ -17,7 +17,7 @@ class BoseChaudhuriHocquenghemEncoder { public: static const int N = LEN, K = MSG, NP = N - K; - static const int G = ((NP+1+K%8)+7)/8; + static const int G = ((NP+1)+7)/8; private: uint8_t generator[G]; static constexpr uint8_t slb1(uint8_t *buf, int pos) @@ -55,36 +55,24 @@ public: std::cerr << " " << get_be_bit(generator, NP-i); std::cerr << std::endl; } - if (K%8 == 1) { - set_be_bit(generator, 0, 0); - } else if (K%8) { - int shift = K%8-1; - set_be_bit(generator, 0, 0); - for (int i = NP; i >= 0; --i) - set_be_bit(generator, i+shift, get_be_bit(generator, i)); - } else { - for (int i = 0; i <= NP; ++i) - set_be_bit(generator, i, get_be_bit(generator, i+1)); - } + for (int i = 0; i < NP; ++i) + set_be_bit(generator, i, get_be_bit(generator, i+1)); + set_be_bit(generator, NP, 0); } - void operator()(uint8_t *code) + void operator()(uint8_t *data, uint8_t *parity) { // $code = data * x^{NP} + (data * x^{NP}) \mod{generator}$ - static const uint8_t mask = (1<<(8-K%8))-1; - code[K/8] &= ~mask; - for (int l = K/8+1; l < N/8; ++l) - code[l] = 0; + for (int l = 0; l < NP/8; ++l) + parity[l] = 0; for (int i = 0; i < K; ++i) { - if (get_be_bit(code, i) != get_be_bit(code, K)) { - code[K/8] = generator[0] ^ ((~mask&code[K/8])|(mask&slb1(code, K/8))); - for (int l = 1; l < NP/8; ++l) - code[l+K/8] = generator[l] ^ slb1(code, l+K/8); - code[(N-1)/8] = generator[NP/8] ^ (code[(N-1)/8]<<1); + if (get_be_bit(data, i) != get_be_bit(parity, 0)) { + for (int l = 0; l < (NP-1)/8; ++l) + parity[l] = generator[l] ^ slb1(parity, l); + parity[(NP-1)/8] = generator[(NP-1)/8] ^ (parity[(NP-1)/8]<<1); } else { - code[K/8] = (~mask&code[K/8]) | (mask&slb1(code, K/8)); - for (int l = K/8+1; l < (N-1)/8; ++l) - code[l] = slb1(code, l); - code[(N-1)/8] <<= 1; + for (int l = 0; l < (NP-1)/8; ++l) + parity[l] = slb1(parity, l); + parity[(NP-1)/8] <<= 1; } } } @@ -137,20 +125,20 @@ public: std::cerr << std::endl; } } - void operator()(ValueType *code) + void operator()(ValueType *data, ValueType *parity) { // $code = data * x^{NP} + (data * x^{NP}) \mod{generator}$ for (int i = 0; i < NP; ++i) - code[K+i] = ValueType(0); + parity[i] = ValueType(0); for (int i = 0; i < K; ++i) { - if (code[i] != code[K]) { + if (data[i] != parity[0]) { for (int j = 1; j < NP; ++j) - code[K+j-1] = generator[NP-j] + code[K+j]; - code[N-1] = generator[0]; + parity[j-1] = generator[NP-j] + parity[j]; + parity[NP-1] = generator[0]; } else { for (int j = 1; j < NP; ++j) - code[K+j-1] = code[K+j]; - code[N-1] = ValueType(0); + parity[j-1] = parity[j]; + parity[NP-1] = ValueType(0); } } } diff --git a/reed_solomon_decoder.hh b/reed_solomon_decoder.hh index 2175c35..00d715f 100644 --- a/reed_solomon_decoder.hh +++ b/reed_solomon_decoder.hh @@ -33,47 +33,58 @@ private: } } public: - int compute_syndromes(ValueType *code, ValueType *syndromes) + int compute_syndromes(ValueType *data, ValueType *parity, ValueType *syndromes) { // $syndromes_i = code(pe^{FCR+i})$ - ValueType coeff(code[0]); + ValueType coeff(data[0]); for (int i = 0; i < NR; ++i) syndromes[i] = coeff; - update_syndromes(code, syndromes, 1, N); + update_syndromes(data, syndromes, 1, K); + update_syndromes(parity, syndromes, 0, NP); int nonzero = 0; for (int i = 0; i < NR; ++i) nonzero += !!syndromes[i]; return nonzero; } - int operator()(ValueType *code, IndexType *erasures = 0, int erasures_count = 0) + int operator()(ValueType *data, ValueType *parity, IndexType *erasures = 0, int erasures_count = 0) { assert(0 <= erasures_count && erasures_count <= NR); if (0) { - for (int i = 0; i < erasures_count; ++i) - code[(int)erasures[i]] = ValueType(0); + for (int i = 0; i < erasures_count; ++i) { + int idx = (int)erasures[i]; + if (idx < K) + data[idx] = ValueType(0); + else + parity[idx-K] = ValueType(0); + } } ValueType syndromes[NR]; - if (!compute_syndromes(code, syndromes)) + if (!compute_syndromes(data, parity, syndromes)) return 0; IndexType locations[NR]; ValueType magnitudes[NR]; int count = algorithm(syndromes, locations, magnitudes, erasures, erasures_count); if (count <= 0) return count; - for (int i = 0; i < count; ++i) - code[(int)locations[i]] += magnitudes[i]; + for (int i = 0; i < count; ++i) { + int idx = (int)locations[i]; + if (idx < K) + data[idx] += magnitudes[i]; + else + parity[idx-K] += magnitudes[i]; + } int corrections_count = 0; for (int i = 0; i < count; ++i) corrections_count += !!magnitudes[i]; return corrections_count; } - int operator()(value_type *code, value_type *erasures = 0, int erasures_count = 0) + int operator()(value_type *data, value_type *parity, value_type *erasures = 0, int erasures_count = 0) { - return (*this)(reinterpret_cast(code), reinterpret_cast(erasures), erasures_count); + return (*this)(reinterpret_cast(data), reinterpret_cast(parity), reinterpret_cast(erasures), erasures_count); } - int compute_syndromes(value_type *code, value_type *syndromes) + int compute_syndromes(value_type *data, value_type *parity, value_type *syndromes) { - return compute_syndromes(reinterpret_cast(code), reinterpret_cast(syndromes)); + return compute_syndromes(reinterpret_cast(data), reinterpret_cast(parity), reinterpret_cast(syndromes)); } }; diff --git a/reed_solomon_encoder.hh b/reed_solomon_encoder.hh index dee285a..dc20c8c 100644 --- a/reed_solomon_encoder.hh +++ b/reed_solomon_encoder.hh @@ -48,28 +48,28 @@ public: for (int i = 0; i <= NR; ++i) generator[i] = index(tmp[i]); } - void operator()(ValueType *code) + void operator()(ValueType *data, ValueType *parity) { // $code = data * x^{NR} + (data * x^{NR}) \mod{generator}$ for (int i = 0; i < NR; ++i) - code[K+i] = ValueType(0); + parity[i] = ValueType(0); for (int i = 0; i < K; ++i) { - ValueType feedback = code[i] + code[K]; + ValueType feedback = data[i] + parity[0]; if (feedback) { IndexType fb = index(feedback); for (int j = 1; j < NR; ++j) - code[K+j-1] = fma(fb, generator[NR-j], code[K+j]); - code[N-1] = value(generator[0] * fb); + parity[j-1] = fma(fb, generator[NR-j], parity[j]); + parity[NP-1] = value(generator[0] * fb); } else { for (int j = 1; j < NR; ++j) - code[K+j-1] = code[K+j]; - code[N-1] = ValueType(0); + parity[j-1] = parity[j]; + parity[NP-1] = ValueType(0); } } } - void operator()(value_type *code) + void operator()(value_type *data, value_type *parity) { - (*this)(reinterpret_cast(code)); + (*this)(reinterpret_cast(data), reinterpret_cast(parity)); } }; diff --git a/tests/bch_decoder_test.cc b/tests/bch_decoder_test.cc index 0f85880..69e9af0 100644 --- a/tests/bch_decoder_test.cc +++ b/tests/bch_decoder_test.cc @@ -19,18 +19,25 @@ int main() // NASA INTRO BCH(15, 5) T=3 typedef CODE::GaloisField<4, 0b10011, uint8_t> GF; typedef CODE::BoseChaudhuriHocquenghemDecoder<6, 1, 5, GF> BCH; - const int L = (BCH::N + 7) / 8; + const int D = (BCH::K + 7) / 8; + const int P = (BCH::NP + 7) / 8; + const int L = D + P; GF instance; BCH decode; - uint8_t target[L] = { 0b11001000, 0b11110100 }; + uint8_t target[L] = { 0b11001000, 0b00011110, 0b10000000 }; uint8_t code[L]; for (int i = 0; i < L; ++i) code[i] = target[i]; std::uniform_int_distribution distribution(0, BCH::N-1); auto noise = std::bind(distribution, generator); - for (int i = 0; i < 3; ++i) - CODE::xor_be_bit(code, noise(), 1); - decode(code); + for (int i = 0; i < 3; ++i) { + int n = noise(); + if (n < BCH::K) + CODE::xor_be_bit(code, n, 1); + else + CODE::xor_be_bit(code+D, n-BCH::K, 1); + } + decode(code, code + D); for (int i = 0; i < L; ++i) assert(code[i] == target[i]); } @@ -38,7 +45,9 @@ int main() // DVB-S2 FULL BCH(65535, 65343) T=12 typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF; typedef CODE::BoseChaudhuriHocquenghemDecoder<24, 1, 65343, GF> BCH; - const int L = (BCH::N + 7) / 8; + const int D = (BCH::K + 7) / 8; + const int P = (BCH::NP + 7) / 8; + const int L = D + P; GF *instance = new GF(); BCH *decode = new BCH(); uint8_t *target = new uint8_t[L]; @@ -48,15 +57,20 @@ int main() CODE::set_be_bit(target, i, (s^=s>>7)&1); bool parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 }; for (int i = 0; i < BCH::NP; ++i) - CODE::set_be_bit(target, BCH::K+i, parity[i]); + CODE::set_be_bit(target + D, i, parity[i]); uint8_t *code = new uint8_t[L]; for (int i = 0; i < L; ++i) code[i] = target[i]; std::uniform_int_distribution distribution(0, BCH::N-1); auto noise = std::bind(distribution, generator); - for (int i = 0; i < 12; ++i) - CODE::xor_be_bit(code, noise(), 1); - (*decode)(code); + for (int i = 0; i < 12; ++i) { + int n = noise(); + if (n < BCH::K) + CODE::xor_be_bit(code, n, 1); + else + CODE::xor_be_bit(code+D, n-BCH::K, 1); + } + (*decode)(code, code + D); for (int i = 0; i < L; ++i) assert(code[i] == target[i]); delete[] target; @@ -64,7 +78,7 @@ int main() delete decode; delete instance; } - if (0) { + if (1) { // NASA INTRO BCH(15, 5) T=3 typedef CODE::GaloisField<4, 0b10011, uint8_t> GF; typedef CODE::BoseChaudhuriHocquenghemDecoderReference<6, 1, 5, GF> BCH; @@ -78,11 +92,11 @@ int main() auto noise = std::bind(distribution, generator); for (int i = 0; i < 3; ++i) code[noise()] ^= 1; - decode(reinterpret_cast(code)); + decode(reinterpret_cast(code), reinterpret_cast(code) + BCH::K); for (int i = 0; i < BCH::N; ++i) assert(code[i] == target[i]); } - if (0) { + if (1) { // DVB-S2 FULL BCH(65535, 65343) T=12 typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF; typedef CODE::BoseChaudhuriHocquenghemDecoderReference<24, 1, 65343, GF> BCH; @@ -101,7 +115,7 @@ int main() auto noise = std::bind(distribution, generator); for (int i = 0; i < 12; ++i) code[noise()] ^= 1; - (*decode)(reinterpret_cast(code)); + (*decode)(reinterpret_cast(code), reinterpret_cast(code) + BCH::K); for (int i = 0; i < BCH::N; ++i) assert(code[i] == target[i]); delete[] target; diff --git a/tests/bch_encoder_test.cc b/tests/bch_encoder_test.cc index b0d23ea..fd6f8fa 100644 --- a/tests/bch_encoder_test.cc +++ b/tests/bch_encoder_test.cc @@ -15,18 +15,22 @@ int main() if (1) { // NASA INTRO BCH(15, 5) T=3 typedef CODE::BoseChaudhuriHocquenghemEncoder<15, 5> BCH; - const int L = (BCH::N + 7) / 8; + const int D = (BCH::K + 7) / 8; + const int P = (BCH::NP + 7) / 8; + const int L = D + P; BCH encode({0b10011, 0b11111, 0b00111}); uint8_t code[L] = { 0b11001000 }; - uint8_t target[L] = { 0b11001000, 0b11110100 }; - encode(code); + uint8_t target[L] = { 0b11001000, 0b00011110, 0b10000000 }; + encode(code, code + D); for (int i = 0; i < L; ++i) assert(code[i] == target[i]); } if (1) { // DVB-S2 FULL BCH(65535, 65343) T=12 typedef CODE::BoseChaudhuriHocquenghemEncoder<65535, 65343> BCH; - const int L = (BCH::N + 7) / 8; + const int D = (BCH::K + 7) / 8; + const int P = (BCH::NP + 7) / 8; + const int L = D + P; BCH *encode = new BCH({0b10000000000101101, 0b10000000101110011, 0b10000111110111101, 0b10101101001010101, 0b10001111100101111, 0b11111011110110101, 0b11010111101100101, 0b10111001101100111, 0b10000111010100001, 0b10111010110100111, 0b10011101000101101, 0b10001101011100011}); uint8_t *target = new uint8_t[L]; for (int i = 0; i < L; ++i) @@ -38,15 +42,15 @@ int main() code[i] = target[i]; bool parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 }; for (int i = 0; i < BCH::NP; ++i) - CODE::set_be_bit(target, BCH::K+i, parity[i]); - (*encode)(code); + CODE::set_be_bit(target + D, i, parity[i]); + (*encode)(code, code + D); for (int i = 0; i < L; ++i) assert(code[i] == target[i]); delete[] target; delete[] code; delete encode; } - if (0) { + if (1) { // NASA INTRO BCH(15, 5) T=3 typedef CODE::GaloisField<4, 0b10011, uint8_t> GF; typedef CODE::BoseChaudhuriHocquenghemEncoderReference<6, 1, 5, GF> BCH; @@ -54,11 +58,11 @@ int main() BCH encode({0b10011, 0b11111, 0b00111}); BCH::value_type code[BCH::N] = { 1, 1, 0, 0, 1 }; BCH::value_type target[BCH::N] = { 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0 }; - encode(reinterpret_cast(code)); + encode(reinterpret_cast(code), reinterpret_cast(code) + BCH::K); for (int i = 0; i < BCH::N; ++i) assert(code[i] == target[i]); } - if (0) { + if (1) { // DVB-S2 FULL BCH(65535, 65343) T=12 typedef CODE::GaloisField<16, 0b10000000000101101, uint16_t> GF; typedef CODE::BoseChaudhuriHocquenghemEncoderReference<24, 1, 65343, GF> BCH; @@ -71,7 +75,7 @@ int main() BCH::value_type parity[BCH::NP] = { 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0 }; for (int i = 0; i < BCH::NP; ++i) target[BCH::K+i] = parity[i]; - (*encode)(reinterpret_cast(code)); + (*encode)(reinterpret_cast(code), reinterpret_cast(code) + BCH::K); for (int i = 0; i < BCH::N; ++i) assert(code[i] == target[i]); delete[] target; diff --git a/tests/rs_decoder_test.cc b/tests/rs_decoder_test.cc index c492df0..f492603 100644 --- a/tests/rs_decoder_test.cc +++ b/tests/rs_decoder_test.cc @@ -28,7 +28,7 @@ int main() auto val = std::bind(std::uniform_int_distribution(0, RS::N), generator); for (int i = 0; i < 2; ++i) code[pos()] = val(); - decode(code); + decode(code, code + RS::K); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); } @@ -51,7 +51,7 @@ int main() auto val = std::bind(std::uniform_int_distribution(0, RS::N), generator); for (int i = 0; i < 8; ++i) code[pos()] = val(); - decode(code); + decode(code, code + RS::K); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); } @@ -74,7 +74,7 @@ int main() auto val = std::bind(std::uniform_int_distribution(0, RS::N), generator); for (int i = 0; i < 32; ++i) code[pos()] = val(); - (*decode)(code); + (*decode)(code, code + RS::K); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); delete[] target; diff --git a/tests/rs_encoder_test.cc b/tests/rs_encoder_test.cc index 80a0e25..16f3bd5 100644 --- a/tests/rs_encoder_test.cc +++ b/tests/rs_encoder_test.cc @@ -19,7 +19,7 @@ int main() RS encode; RS::value_type code[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 }; RS::value_type target[RS::N] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 3, 3, 12, 12 }; - encode(code); + encode(code, code + RS::K); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); } @@ -35,7 +35,7 @@ int main() RS::value_type parity[RS::NP] = { 1, 126, 147, 48, 155, 224, 3, 157, 29, 226, 40, 114, 61, 30, 244, 75 }; for (int i = 0; i < RS::NP; ++i) target[RS::K+i] = parity[i]; - encode(code); + encode(code, code + RS::K); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); } @@ -52,7 +52,7 @@ int main() RS::value_type parity[RS::NP] = { 25271, 26303, 22052, 31318, 31233, 6076, 40148, 29468, 47507, 32655, 12404, 13265, 23901, 38403, 50967, 50433, 40818, 226, 62296, 23636, 56393, 12952, 11476, 44416, 518, 50014, 10037, 57582, 33421, 42654, 54025, 7157, 4826, 52148, 17167, 23294, 6427, 40953, 11168, 35305, 18209, 1868, 39971, 54928, 27566, 1424, 4846, 25347, 34710, 42190, 56452, 21859, 49805, 28028, 41657, 25756, 22014, 24479, 28758, 17438, 12976, 61743, 46735, 1557 }; for (int i = 0; i < RS::NP; ++i) target[RS::K+i] = parity[i]; - (*encode)(code); + (*encode)(code, code + RS::K); for (int i = 0; i < RS::N; ++i) assert(code[i] == target[i]); delete[] target;