MCPcopy Create free account
hub / github.com/aff3ct/aff3ct / Encoder_conv

Method Encoder_conv

src/Module/Encoder/Conv/Encoder_conv.cpp:11–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10template<typename B>
11Encoder_conv<B>::Encoder_conv(const int K, const int N, const std::vector<int>& poly)
12 : Encoder<B>(K, N)
13 , n_ff(0)
14 , n_poly(static_cast<int>(poly.size()))
15 , n_states(0)
16 , poly(poly)
17 , next_state_table()
18 , output_table()
19{
20 const std::string name = "Encoder_conv";
21 this->set_name(name);
22 for (auto& t : this->tasks)
23 t->set_replicability(true);
24
25 if (n_poly < 2)
26 {
27 std::stringstream message;
28 message << "'poly' must have at least 2 elements ('poly.size()' = " << n_poly << ").";
29 throw spu::tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
30 }
31
32 // Determine n_ff from the maximum bit width of the polynomials
33 int max_poly = 0;
34 for (auto g : poly)
35 if (g > max_poly) max_poly = g;
36
37 // n_ff = floor(log2(max_poly)), i.e. the number of memory elements
38 int tmp = max_poly;
39 int bits = 0;
40 while (tmp > 0)
41 {
42 bits++;
43 tmp >>= 1;
44 }
45 // const_cast to set the const member after computation
46 const_cast<int&>(this->n_ff) = bits - 1;
47 const_cast<int&>(this->n_states) = 1 << this->n_ff;
48
49 if (this->n_ff <= 0)
50 {
51 std::stringstream message;
52 message << "'n_ff' has to be greater than 0 ('n_ff' = " << this->n_ff << ").";
53 throw spu::tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
54 }
55
56 if (N != n_poly * (K + this->n_ff))
57 {
58 std::stringstream message;
59 message << "'N' must equal 'n_poly' * ('K' + 'n_ff') ('N' = " << N << ", 'n_poly' = " << n_poly
60 << ", 'K' = " << K << ", 'n_ff' = " << this->n_ff << ").";
61 throw spu::tools::invalid_argument(__FILE__, __LINE__, __func__, message.str());
62 }
63
64 // Set info_bits_pos: positions of the "systematic" bit in interleaved output
65 // For rate 1/n_poly, info bits are at positions [0, n_poly, 2*n_poly, ...]
66 for (auto k = 0; k < this->K; k++)
67 this->info_bits_pos[k] = n_poly * k;
68

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected