1 |
13 |
kavi |
/********************************************************************/
|
2 |
|
|
/* Filename : gen_ixgen.c */
|
3 |
|
|
/* Description: Generates the compact index generator (ixgen) unit. */
|
4 |
|
|
/* Author : Nikolaos Kavvadias, <nkavv@physics.auth.gr> */
|
5 |
|
|
/* Date : Sunday, 14/02/2010 */
|
6 |
|
|
/* Revision : */
|
7 |
|
|
/********************************************************************/
|
8 |
|
|
|
9 |
|
|
#include <stdio.h>
|
10 |
|
|
#include <stdlib.h>
|
11 |
|
|
#include <time.h>
|
12 |
|
|
#include "common.h"
|
13 |
|
|
|
14 |
|
|
#define PRINT_DEBUG
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
// FUNCTION PROTOTYPES
|
18 |
|
|
void write_file_ixgen(FILE *outfile);
|
19 |
|
|
|
20 |
|
|
FILE *file_ixgen; /* VHDL source for the top-level module of the
|
21 |
|
|
* ixgen<num>_pf unit (ixgen<num>_pf.vhd) */
|
22 |
|
|
|
23 |
|
|
char ixgen_file_name[32];
|
24 |
|
|
int enable_nlp=0;
|
25 |
|
|
int nlp=1;
|
26 |
|
|
time_t t;
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
int main(int argc, char **argv)
|
30 |
|
|
{
|
31 |
|
|
int i;
|
32 |
|
|
int gen_ixgen_file;
|
33 |
|
|
|
34 |
|
|
gen_ixgen_file = 0;
|
35 |
|
|
|
36 |
|
|
// Read input arguments
|
37 |
|
|
if (argc < 3)
|
38 |
|
|
{
|
39 |
|
|
printf("Usage: gen_ixgen -nlp <num loops> <output base>\n");
|
40 |
|
|
printf("where:\n");
|
41 |
|
|
printf("-nlp <num> = give number of supported loops (default = 1).\n");
|
42 |
|
|
printf("<output base> = output file base name. The generated files will be named:\n");
|
43 |
|
|
printf(" \"<output base><nlp>_pf.vhd\".\n");
|
44 |
|
|
printf("\n");
|
45 |
|
|
exit(1);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
for (i = 1; i < argc; i++)
|
49 |
|
|
{
|
50 |
|
|
if (strcmp("-nlp",argv[i]) == 0)
|
51 |
|
|
{
|
52 |
|
|
enable_nlp = 1;
|
53 |
|
|
if ((i+1) < argc)
|
54 |
|
|
{
|
55 |
|
|
i++;
|
56 |
|
|
nlp = atoi(argv[i]);
|
57 |
|
|
}
|
58 |
|
|
}
|
59 |
|
|
else //if (strcmp("-o",argv[i]) == 0)
|
60 |
|
|
{
|
61 |
|
|
if (i < argc)
|
62 |
|
|
{
|
63 |
|
|
sprintf(ixgen_file_name,"%s%d%s", argv[i], nlp, "_pf.vhd");
|
64 |
|
|
gen_ixgen_file = 1;
|
65 |
|
|
}
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
// DEBUG OUTPUT
|
70 |
|
|
#ifdef PRINT_DEBUG
|
71 |
|
|
printf("\n");
|
72 |
|
|
//
|
73 |
|
|
printf("nlp = %d\n",nlp);
|
74 |
|
|
printf("ixgen_file_name = %s\n", ixgen_file_name);
|
75 |
|
|
//
|
76 |
|
|
#endif
|
77 |
|
|
|
78 |
|
|
/********************************************/
|
79 |
|
|
/* Generate VHDL source for the ixgen unit. */
|
80 |
|
|
/********************************************/
|
81 |
|
|
if (gen_ixgen_file == 1)
|
82 |
|
|
{
|
83 |
|
|
file_ixgen = fopen(ixgen_file_name, "w");
|
84 |
|
|
write_file_ixgen(file_ixgen);
|
85 |
|
|
fclose(file_ixgen);
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
return 0;
|
89 |
|
|
}
|
90 |
|
|
|
91 |
|
|
void write_file_ixgen(FILE *outfile)
|
92 |
|
|
{
|
93 |
|
|
unsigned int i, j;
|
94 |
|
|
|
95 |
|
|
// Get current time
|
96 |
|
|
time(&t);
|
97 |
|
|
|
98 |
|
|
/* Generate interface for the VHDL file */
|
99 |
|
|
fprintf(outfile, "----==============================================================----\n");
|
100 |
|
|
fprintf(outfile, "---- ----\n");
|
101 |
|
|
fprintf(outfile, "---- Filename: %s ----\n", ixgen_file_name);
|
102 |
|
|
fprintf(outfile, "---- Description: Top-level file for the ixgen unit. ----\n");
|
103 |
|
|
fprintf(outfile, "---- Also implements I/O wrapping operations. ----\n");
|
104 |
|
|
fprintf(outfile, "---- ----\n");
|
105 |
|
|
fprintf(outfile, "---- Author: Nikolaos Kavvadias ----\n");
|
106 |
|
|
fprintf(outfile, "---- nkavv@physics.auth.gr ----\n");
|
107 |
|
|
fprintf(outfile, "---- ----\n");
|
108 |
|
|
fprintf(outfile, "---- ----\n");
|
109 |
|
|
fprintf(outfile, "---- Part of the hwlu OPENCORES project generated automatically ----\n");
|
110 |
|
|
fprintf(outfile, "---- with the use of the \"gen_ixgen\" tool. ----\n");
|
111 |
|
|
fprintf(outfile, "---- ----\n");
|
112 |
|
|
fprintf(outfile, "---- To Do: ----\n");
|
113 |
|
|
fprintf(outfile, "---- Considered stable for the time being ----\n");
|
114 |
|
|
print_vhdl_header_common(outfile);
|
115 |
|
|
|
116 |
|
|
/* Code generation for library inclusions */
|
117 |
|
|
fprintf(outfile, "library IEEE;\n");
|
118 |
|
|
fprintf(outfile, "use IEEE.std_logic_1164.all;\n");
|
119 |
|
|
fprintf(outfile, "use IEEE.std_logic_unsigned.all;\n");
|
120 |
|
|
fprintf(outfile, "\n");
|
121 |
|
|
|
122 |
|
|
/* Generate entity declaration */
|
123 |
|
|
fprintf(outfile, "entity ixgen%d_pf is\n", nlp);
|
124 |
|
|
fprintf(outfile, "\tgeneric (\n");
|
125 |
|
|
fprintf(outfile, "\t\tNLP : integer := %d;\n", nlp);
|
126 |
|
|
fprintf(outfile, "\t\tDW : integer := 8\n");
|
127 |
|
|
fprintf(outfile, "\t);\n");
|
128 |
|
|
fprintf(outfile, "\tport (\n");
|
129 |
|
|
fprintf(outfile, "\t\tclk : in std_logic;\n");
|
130 |
|
|
fprintf(outfile, "\t\treset : in std_logic;\n");
|
131 |
|
|
fprintf(outfile, "\t\tinnerloop_end : in std_logic;\n");
|
132 |
|
|
fprintf(outfile, "\t\tloop_count : in std_logic_vector(NLP*DW-1 downto 0);\n");
|
133 |
|
|
fprintf(outfile, "\t\tindex : out std_logic_vector(NLP*DW-1 downto 0);\n");
|
134 |
|
|
//
|
135 |
|
|
fprintf(outfile, "\t\tloops_end : out std_logic\n");
|
136 |
|
|
//
|
137 |
|
|
fprintf(outfile, "\t);\n");
|
138 |
|
|
fprintf(outfile, "end ixgen%d_pf;\n", nlp);
|
139 |
|
|
fprintf(outfile, "\n");
|
140 |
|
|
|
141 |
|
|
/* Generate architecture declaration */
|
142 |
|
|
fprintf(outfile,"architecture rtl of ixgen%d_pf is\n", nlp);
|
143 |
|
|
|
144 |
|
|
/* Add signal declarations here if needed */
|
145 |
|
|
fprintf(outfile, "--\n");
|
146 |
|
|
fprintf(outfile, "-- Signal declarations\n");
|
147 |
|
|
fprintf(outfile, "signal temp_index : std_logic_vector(NLP*DW-1 downto 0);\n");
|
148 |
|
|
for (i = 1; i <= nlp; i++)
|
149 |
|
|
{
|
150 |
|
|
fprintf(outfile, "alias temp_index%d : std_logic_vector(DW-1 downto 0) is temp_index(%d*DW-1 downto %d*DW);\n",
|
151 |
|
|
i, i, i-1);
|
152 |
|
|
}
|
153 |
|
|
for (i = 1; i <= nlp; i++)
|
154 |
|
|
{
|
155 |
|
|
fprintf(outfile, "alias loop%d_count : std_logic_vector(DW-1 downto 0) is loop_count(%d*DW-1 downto %d*DW);\n",
|
156 |
|
|
i, i, i-1);
|
157 |
|
|
}
|
158 |
|
|
fprintf(outfile,"--\n");
|
159 |
|
|
|
160 |
|
|
/* Continue with the rest of the architecture declaration. */
|
161 |
|
|
fprintf(outfile, "begin\n");
|
162 |
|
|
fprintf(outfile, "\n");
|
163 |
|
|
|
164 |
|
|
/* Generate main process. */
|
165 |
|
|
fprintf(outfile,"\tprocess (clk, reset, innerloop_end, temp_index, loop_count)\n");
|
166 |
|
|
fprintf(outfile,"\tbegin\n");
|
167 |
|
|
fprintf(outfile,"\t\tif (reset = '1') then\n");
|
168 |
|
|
for (i = 1; i <= nlp; i++)
|
169 |
|
|
{
|
170 |
|
|
fprintf(outfile,"\t\t\ttemp_index%d <= (others => '0');\n", i);
|
171 |
|
|
}
|
172 |
|
|
fprintf(outfile, "\t\t\tloops_end <= '0';\n");
|
173 |
|
|
fprintf(outfile, "\t\telsif (clk'EVENT and clk = '1') then\n");
|
174 |
|
|
fprintf(outfile, "\t\t\tif (innerloop_end = '1') then\n");
|
175 |
|
|
for (i = nlp; i >= 1; i--)
|
176 |
|
|
{
|
177 |
|
|
if (i == nlp)
|
178 |
|
|
{
|
179 |
|
|
fprintf(outfile, "\t\t\t\tif (temp_index%d < loop%d_count) then\n", i, i);
|
180 |
|
|
}
|
181 |
|
|
else
|
182 |
|
|
{
|
183 |
|
|
fprintf(outfile, "\t\t\t\telsif (temp_index%d < loop%d_count) then\n", i, i);
|
184 |
|
|
}
|
185 |
|
|
for (j = nlp; j > i; j--)
|
186 |
|
|
{
|
187 |
|
|
fprintf(outfile, "\t\t\t\t\ttemp_index%d <= (others => '0');\n", j);
|
188 |
|
|
}
|
189 |
|
|
fprintf(outfile, "\t\t\t\t\ttemp_index%d <= temp_index%d + '1';\n", j);
|
190 |
|
|
}
|
191 |
|
|
fprintf(outfile, "\t\t\t\telse\n");
|
192 |
|
|
for (i = 1; i <= nlp; i++)
|
193 |
|
|
{
|
194 |
|
|
fprintf(outfile, "\t\t\t\t\ttemp_index%d <= (others => '0');\n", i);
|
195 |
|
|
}
|
196 |
|
|
fprintf(outfile, "\t\t\t\tend if;\n");
|
197 |
|
|
fprintf(outfile, "\t\t\tend if;\n");
|
198 |
|
|
fprintf(outfile, "\t\tend if;\n");
|
199 |
|
|
fprintf(outfile, "\tend process;\n");
|
200 |
|
|
fprintf(outfile, "\n");
|
201 |
|
|
|
202 |
|
|
/***************************************/
|
203 |
|
|
/* GENERATE OUTPUT WRAPPING ASSIGNMENTS */
|
204 |
|
|
/***************************************/
|
205 |
|
|
|
206 |
|
|
fprintf(outfile, "\tindex <= temp_index;\n");
|
207 |
|
|
|
208 |
|
|
fprintf(outfile, "\n");
|
209 |
|
|
fprintf(outfile, "end rtl;\n");
|
210 |
|
|
}
|