-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgenerate_table_vector_vhd.cc
77 lines (73 loc) · 2.98 KB
/
generate_table_vector_vhd.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
Generate table_vector.vhd from table_vector.txt
Copyright 2019 Ahmet Inan <inan@aicodix.de>
*/
#include <fstream>
#include "ldpc_vector.hh"
int main()
{
int offsets[VECTOR_LOCATIONS_MAX];
int shifts[VECTOR_LOCATIONS_MAX];
int counts[VECTOR_PARITIES_MAX];
int parities = 0;
std::ifstream table_txt("table_vector.txt");
for (int loc = 0; table_txt >> counts[parities]; ++parities) {
for (int num = 0; num < counts[parities]; ++num, ++loc) {
table_txt >> offsets[loc];
table_txt.ignore(1, ':');
table_txt >> shifts[loc];
}
}
std::ofstream table_vhd("table_vector.vhd");
table_vhd << "-- code table generated from table_vector.txt by generate_table_vector_vhd.cc" << std::endl;
table_vhd << "--" << std::endl;
table_vhd << "-- Copyright 2019 Ahmet Inan <inan@aicodix.de>" << std::endl;
table_vhd << std::endl;
table_vhd << "use work.ldpc_scalar.all;" << std::endl;
table_vhd << "use work.ldpc_vector.all;" << std::endl;
table_vhd << std::endl;
table_vhd << "package table_vector is" << std::endl;
table_vhd << " function init_vector_parities return vector_parities;" << std::endl;
table_vhd << " function init_vector_counts return vector_counts;" << std::endl;
table_vhd << " function init_vector_offsets return vector_offsets;" << std::endl;
table_vhd << " function init_vector_shifts return vector_shifts;" << std::endl;
table_vhd << "end package;" << std::endl;
table_vhd << std::endl;
table_vhd << "package body table_vector is" << std::endl;
table_vhd << " function init_vector_parities return vector_parities is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return " << parities << ";" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << std::endl;
table_vhd << " function init_vector_counts return vector_counts is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return (" << std::endl;
for (int pty = 0; pty < parities; ++pty)
table_vhd << counts[pty] << "," << std::endl;
table_vhd << " others => count_scalar'low);" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << std::endl;
table_vhd << " function init_vector_offsets return vector_offsets is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return (" << std::endl;
for (int pty = 0, loc = 0; pty < parities; ++pty) {
for (int num = 0; num < counts[pty]; ++num, ++loc)
table_vhd << offsets[loc] << ",";
table_vhd << std::endl;
}
table_vhd << " others => 0);" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << std::endl;
table_vhd << " function init_vector_shifts return vector_shifts is" << std::endl;
table_vhd << " begin" << std::endl;
table_vhd << " return (" << std::endl;
for (int pty = 0, loc = 0; pty < parities; ++pty) {
for (int num = 0; num < counts[pty]; ++num, ++loc)
table_vhd << shifts[loc] << ",";
table_vhd << std::endl;
}
table_vhd << " others => 0);" << std::endl;
table_vhd << " end function;" << std::endl;
table_vhd << "end package body;" << std::endl;
return 0;
}