From b54be1c997c137675f5b1ae3dfb0caf6121e87db Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sun, 14 Jun 2020 20:43:45 +0200 Subject: [PATCH] moved constructor generator argument to template parameter --- short_bch_code_decoder.hh | 18 +++++++++--------- short_bch_code_encoder.hh | 10 +++++----- tests/short_bch_code_decoder_test.cc | 6 +++--- tests/short_bch_code_encoder_test.cc | 2 +- tests/short_bch_code_regression_test.cc | 4 ++-- tests/soft_bch_regression_test.cc | 4 ++-- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/short_bch_code_decoder.hh b/short_bch_code_decoder.hh index a833ac6..741860f 100644 --- a/short_bch_code_decoder.hh +++ b/short_bch_code_decoder.hh @@ -8,7 +8,7 @@ Copyright 2020 Ahmet Inan namespace CODE { -template +template class ShortBCHCodeDecoder { static const int P = N - K; @@ -19,11 +19,11 @@ class ShortBCHCodeDecoder static_assert(N < 8 * sizeof(err[0]), "codeword type not wide enough"); static_assert(P < 8 * sizeof(par[0]), "parity type not wide enough"); static_assert(T > 0 && T <= 4, "unsupported radius T"); - static int modgen(int inp, int gen) + static int modgen(int inp) { for (int i = K-1; i >= 0; --i) { int tmp = inp >> (i+P); - inp ^= (tmp & 1) * (gen << i); + inp ^= (tmp & 1) * (G << i); } return inp; } @@ -36,19 +36,19 @@ class ShortBCHCodeDecoder return sum; } public: - ShortBCHCodeDecoder(int generator) + ShortBCHCodeDecoder() { for (int i = 0; i < W; ++i) - par[i] = modgen(i << P, generator); + par[i] = modgen(i << P); err[0] = 0; for (int a = 1<<(N-1); T >= 1 && a; a >>= 1) { - err[modgen(a, generator)] = a; + err[modgen(a)] = a; for (int b = a >> 1; T >= 2 && b; b >>= 1) { - err[modgen(a|b, generator)] = a|b; + err[modgen(a|b)] = a|b; for (int c = b >> 1; T >= 3 && c; c >>= 1) { - err[modgen(a|b|c, generator)] = a|b|c; + err[modgen(a|b|c)] = a|b|c; for (int d = c >> 1; T >= 4 && d; d >>= 1) { - err[modgen(a|b|c|d, generator)] = a|b|c|d; + err[modgen(a|b|c|d)] = a|b|c|d; } } } diff --git a/short_bch_code_encoder.hh b/short_bch_code_encoder.hh index 30bc7c7..32bfcde 100644 --- a/short_bch_code_encoder.hh +++ b/short_bch_code_encoder.hh @@ -8,7 +8,7 @@ Copyright 2020 Ahmet Inan namespace CODE { -template +template class ShortBCHCodeEncoder { static const int P = N - K; @@ -16,19 +16,19 @@ class ShortBCHCodeEncoder short par[W]; static_assert(N < 8 * sizeof(int), "codeword type not wide enough"); static_assert(P < 8 * sizeof(par[0]), "parity type not wide enough"); - static int modgen(int inp, int gen) + static int modgen(int inp) { for (int i = K-1; i >= 0; --i) { int tmp = inp >> (i+P); - inp ^= (tmp & 1) * (gen << i); + inp ^= (tmp & 1) * (G << i); } return inp; } public: - ShortBCHCodeEncoder(int generator) + ShortBCHCodeEncoder() { for (int i = 0; i < W; ++i) - par[i] = modgen(i << P, generator); + par[i] = modgen(i << P); } int operator()(int msg) { diff --git a/tests/short_bch_code_decoder_test.cc b/tests/short_bch_code_decoder_test.cc index 1918590..b0174cb 100644 --- a/tests/short_bch_code_decoder_test.cc +++ b/tests/short_bch_code_decoder_test.cc @@ -17,7 +17,7 @@ int main() if (1) { // Perfect binary Golay code using x^11+x^9+x^7+x^6+x^5+x+1 const int N = 23, K = 12, T = 3, POLY = 0b101011100011; - CODE::ShortBCHCodeDecoder decode(POLY); + CODE::ShortBCHCodeDecoder decode; int target = 0b10101101101111011111001; int damaged = target; typedef std::uniform_int_distribution distribution; @@ -30,7 +30,7 @@ int main() if (1) { // Perfect binary Golay code using x^11+x^10+x^6+x^5+x^4+x^2+1 const int N = 23, K = 12, T = 3, POLY = 0b110001110101; - CODE::ShortBCHCodeDecoder decode(POLY); + CODE::ShortBCHCodeDecoder decode; int target = 0b10101101101100100010101; int damaged = target; typedef std::uniform_int_distribution distribution; @@ -43,7 +43,7 @@ int main() if (1) { // NASA INTRO BCH(15, 5) T=3 const int N = 15, K = 5, T = 3, POLY = 0b10100110111; - CODE::ShortBCHCodeDecoder decode(POLY); + CODE::ShortBCHCodeDecoder decode; int target = 0b110010001111010; int damaged = target; typedef std::uniform_int_distribution distribution; diff --git a/tests/short_bch_code_encoder_test.cc b/tests/short_bch_code_encoder_test.cc index 7a87a9a..9b98d71 100644 --- a/tests/short_bch_code_encoder_test.cc +++ b/tests/short_bch_code_encoder_test.cc @@ -22,7 +22,7 @@ int popcnt(TYPE x) template void bch_test(int message, int target) { - CODE::ShortBCHCodeEncoder encode(POLY); + CODE::ShortBCHCodeEncoder encode; int hist[N+1] = { 0 }; for (int j = 0; j < (1 << K); ++j) for (int i = j + 1; i < (1 << K); ++i) diff --git a/tests/short_bch_code_regression_test.cc b/tests/short_bch_code_regression_test.cc index 8ee5ac7..84c152d 100644 --- a/tests/short_bch_code_regression_test.cc +++ b/tests/short_bch_code_regression_test.cc @@ -14,8 +14,8 @@ Copyright 2020 Ahmet Inan template void bch_test(int trials) { - CODE::ShortBCHCodeEncoder encode(POLY); - CODE::ShortBCHCodeDecoder decode(POLY); + CODE::ShortBCHCodeEncoder encode; + CODE::ShortBCHCodeDecoder decode; std::random_device rd; typedef std::default_random_engine generator; typedef std::uniform_int_distribution distribution; diff --git a/tests/soft_bch_regression_test.cc b/tests/soft_bch_regression_test.cc index 14c291b..f762ce7 100644 --- a/tests/soft_bch_regression_test.cc +++ b/tests/soft_bch_regression_test.cc @@ -54,8 +54,8 @@ int popcnt(TYPE x) int main() { - CODE::ShortBCHCodeEncoder encode(GEN_POLY); - CODE::ShortBCHCodeDecoder decode(GEN_POLY); + CODE::ShortBCHCodeEncoder encode; + CODE::ShortBCHCodeDecoder decode; std::random_device rd; std::default_random_engine generator(rd());