Commit ebe38f86 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Optimize short code decoder performance.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent 12bb5090
......@@ -24,7 +24,7 @@
using std::vector;
#if 0
/* codetables.de */
/* codetables.de / magma online calculator BKLC (GF(2), N, K) */
static vector<vector<int>> block_48_16_16 = {
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1 },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0 },
......@@ -148,7 +148,7 @@ short_decode_blk (const vector<int>& coded_bits)
vector<int> out_bits;
for (size_t c = 0; c < (1 << gen_in_count); c++)
{
vector<int> w;
bool match = true;
for (size_t j = 0; j < gen_out_count; j++)
{
int x = 0;
......@@ -159,9 +159,13 @@ short_decode_blk (const vector<int>& coded_bits)
x ^= gen_matrix[bit][j];
}
}
w.push_back (x);
if (coded_bits[j] != x)
{
match = false;
break;
}
}
if (w == coded_bits)
if (match)
{
for (size_t bit = 0; bit < gen_in_count; bit++)
{
......
......@@ -114,14 +114,14 @@ main (int argc, char **argv)
}
if (argc == 2 && string (argv[1]) == "perf")
{
vector<int> in_bits;
while (in_bits.size() != K)
in_bits.push_back (rand() & 1);
const double start_t = gettime();
const size_t runs = 20;
const size_t runs = 100;
for (size_t i = 0; i < runs; i++)
{
vector<int> in_bits;
while (in_bits.size() != K)
in_bits.push_back (rand() & 1);
vector<int> out_bits = short_decode_blk (short_encode_blk (in_bits));
assert (out_bits == in_bits);
}
......@@ -155,6 +155,11 @@ main (int argc, char **argv)
if (weight[i])
printf ("W %3zd %6d %20s\n", i, weight[i], number_format (factorial (N) / (factorial (i) * factorial (N - i)) / weight[i]).c_str());
}
/* decoding test */
for (auto it : table)
{
assert (short_decode_blk (it.first) == it.second);
}
const size_t runs = 50LL * 1000 * 1000 * 1000;
size_t match = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment