OpenCores
URL https://opencores.org/ocsvn/hwlu/hwlu/trunk

Subversion Repositories hwlu

[/] [hwlu/] [trunk/] [sw/] [gen_priority_encoder.c] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 kavi
/************************************************************/
2
/* Filename   : gen_priority_encoder.c                      */
3
/* Description: Generates priority_encoder module.          */
4
/* Author     : Nikolaos Kavvadias, <nkavv@physics.auth.gr> */
5
/* Date       : Friday, 09/04/2004                          */
6
/* Revision   : 09/02/2010: Created common.[c|h].           */
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_priority_encoder(FILE *outfile);
19
 
20
 
21
FILE *file_priority_encoder; /* VHDL source for the priority_encoder module of the
22
                              * hw_looping unit (priority_encoder.vhd) */
23
char priority_encoder_file_name[32];
24
int nlp;
25
time_t t;
26
 
27
 
28
int main(int argc, char **argv)
29
{
30
  int i;
31
  int gen_priority_encoder_file;
32
  char nlp_s[3];
33
 
34
  gen_priority_encoder_file = 0;
35
 
36
  if( argc < 3 )
37
  {
38
    printf("Usage: gen_priority_encoder <num loops> <output base>\n");
39
    printf("where:\n");
40
    printf("num loops   = give number of supported loops\n");
41
    printf("output base = output file base name. The generated files will be named:\n");
42
    printf("              \"<output base>.vhd\" for the module\n");
43
    //
44
    printf("\n");
45
    //
46
    return -1;
47
  }
48
 
49
  // Acquire number of supported loops
50
  strcpy(nlp_s,argv[1]);
51
  nlp = atoi(nlp_s);
52
 
53
  // Filenames for the requested VHDL source files
54
  sprintf(priority_encoder_file_name,"%s_loops%s%s", argv[2], nlp_s, ".vhd");
55
  gen_priority_encoder_file = 1;
56
 
57
 
58
  // DEBUG OUTPUT      
59
  #ifdef PRINT_DEBUG
60
    printf("\n");
61
    //
62
    printf("nlp = %d\n",nlp);
63
    printf("priority_encoder_file_name = %s\n", priority_encoder_file_name);
64
    //
65
  #endif        
66
 
67
 
68
  /******************************************************/
69
  /* Generate VHDL source for the priority_encoder unit */
70
  /******************************************************/
71
  if (gen_priority_encoder_file == 1)
72
  {
73
    file_priority_encoder = fopen(priority_encoder_file_name,"w");
74
    write_file_priority_encoder(file_priority_encoder);
75
    fclose(file_priority_encoder);
76
  }
77
 
78
  return 0;
79
 
80
}
81
 
82
 
83
void write_file_priority_encoder(
84
                      FILE *outfile     // Name for the output file -- e.g. mbloop_merger.vhd 
85
                     )
86
{
87
  int i;
88
 
89
  // Get current time
90
  time(&t);
91
 
92
  /* Generate interface for the VHDL file */
93
  fprintf(outfile,"----==============================================================----\n");
94
  fprintf(outfile,"----                                                              ----\n");
95
  fprintf(outfile,"---- Filename: %s                                   ----\n", priority_encoder_file_name);
96
  fprintf(outfile,"---- Module description: Priority encoder unit. Obtains           ----\n");
97
  fprintf(outfile,"----        increment and reset decisions for the loop indices.   ----\n");
98
  fprintf(outfile,"----                                                              ----\n");
99
  fprintf(outfile,"---- Author: Nikolaos Kavvadias                                   ----\n");
100
  fprintf(outfile,"----         nkavv@physics.auth.gr                                ----\n");
101
  fprintf(outfile,"----                                                              ----\n");
102
  fprintf(outfile,"----                                                              ----\n");
103
  fprintf(outfile,"---- Part of the hwlu OPENCORES project generated automatically   ----\n");
104
  fprintf(outfile,"---- with the use of the \"gen_priority_encoder\" tool              ----\n");
105
  fprintf(outfile,"----                                                              ----\n");
106
  fprintf(outfile,"---- To Do:                                                       ----\n");
107
  fprintf(outfile,"----         Considered stable for the time being                 ----\n");
108
  print_vhdl_header_common(outfile);
109
 
110
  /* Code generation for library inclusions */
111
  fprintf(outfile,"library IEEE;\n");
112
  fprintf(outfile,"use IEEE.std_logic_1164.all;\n");
113
  fprintf(outfile,"use IEEE.std_logic_unsigned.all;\n");
114
  fprintf(outfile,"\n");
115
 
116
  /* Generate entity declaration */
117
  fprintf(outfile,"entity priority_encoder is\n");
118
  fprintf(outfile,"\tgeneric (\n");
119
  fprintf(outfile,"\t\tNLP : integer := %d\n", nlp);
120
  fprintf(outfile,"\t);\n");
121
  fprintf(outfile,"\tport (\n");
122
  fprintf(outfile,"\t\tflag           : in std_logic_vector(NLP-1 downto 0);\n");
123
  fprintf(outfile,"\t\ttask_loop%d_end : in std_logic;\n", nlp);
124
  fprintf(outfile,"\t\tincl           : out std_logic_vector(NLP-1 downto 0);\n");
125
  fprintf(outfile,"\t\treset_vct      : out std_logic_vector(NLP-1 downto 0);\n");
126
  fprintf(outfile,"\t\tloops_end      : out std_logic\n");
127
  fprintf(outfile,"\t);\n");
128
  fprintf(outfile,"end priority_encoder;\n");
129
  fprintf(outfile,"\n");
130
 
131
  /* Generate architecture declaration */
132
  fprintf(outfile,"architecture rtl of priority_encoder is\n");
133
 
134
  /* Add component declarations here if needed */
135
 
136
  /* Add signal declarations here if needed */
137
 
138
  /* Continue with the rest of the architecture declaration */
139
  fprintf(outfile,"begin\n");
140
  fprintf(outfile,"\n");
141
 
142
  fprintf(outfile,"\t-- Fully-nested loop structure with %d loops\n", nlp);
143
  fprintf(outfile,"\t-- From outer to inner: ");
144
  //                                               
145
  i = nlp-1;
146
  fprintf(outfile,"%d", nlp-1);
147
  //
148
  if (nlp>=2)
149
  {
150
    for (i=nlp-2; i>=0; i--)
151
      fprintf(outfile,"-> %d",i);
152
  }
153
  //
154
  fprintf(outfile,"\n");
155
 
156
  // Loop counter
157
  i = nlp-1;
158
 
159
  /********************/
160
  /* GENERATE process */
161
  /********************/
162
 
163
  fprintf(outfile,"\tprocess (flag, task_loop%d_end)\n", nlp);
164
  fprintf(outfile,"\tbegin\n");
165
  fprintf(outfile,"\t\t--\n");
166
  fprintf(outfile,"\t\t-- if loop%d is terminating:\n", i);
167
  fprintf(outfile,"\t\t-- reset loops %d-%d to initial index\n", i, 0);
168
  //
169
  fprintf(outfile,"\t\tif (flag(%d downto 0) = \"", i);
170
  print_binary_value_fbone( outfile, ipow(2,i+1)-1 );
171
  fprintf(outfile,"\") then\n");
172
  //
173
  fprintf(outfile,"\t\t\tincl <= \"");
174
  print_binary_value( outfile, 0, nlp );
175
  fprintf(outfile,"\";\n");
176
  //                 
177
  fprintf(outfile,"\t\t\treset_vct <= \"");
178
  print_binary_value( outfile, ipow(2,i+1)-1, nlp );
179
  fprintf(outfile,"\";\n");
180
  //                 
181
  fprintf(outfile,"\t\t\tloops_end <= '1';\n");
182
 
183
  // Loop on all "elsif" cases: i=2 -> i=nlp                 
184
  for (i=nlp-2; i>=0; i--)
185
  {
186
    fprintf(outfile,"\t\t-- else if loop%d is terminating:\n", i);
187
    fprintf(outfile,"\t\t-- 1. increment loop%d index\n", i+1);
188
    fprintf(outfile,"\t\t-- 2. reset loop%d to initial index\n", i);
189
    //    
190
    fprintf(outfile,"\t\telsif (flag(%d downto 0) = \"", i);
191
    print_binary_value_fbone( outfile, ipow(2,i+1)-1 );
192
    fprintf(outfile,"\") then\n");
193
    //
194
    fprintf(outfile,"\t\t\tincl <= \"");
195
    print_binary_value( outfile, ipow(2,i+1), nlp );
196
    fprintf(outfile,"\";\n");
197
    //
198
    fprintf(outfile,"\t\t\treset_vct <= \"");
199
    print_binary_value( outfile, ipow(2,i+1)-1, nlp );
200
    fprintf(outfile,"\";\n");
201
    //
202
    fprintf(outfile,"\t\t\tloops_end <= '0';\n");
203
  }
204
 
205
  // Else increment inner loop                 
206
  fprintf(outfile,"\t\t-- else increment loop%d index\n", i);
207
  fprintf(outfile,"\t\telse\n");
208
  //                          
209
  fprintf(outfile,"\t\t\treset_vct <= \"");
210
  print_binary_value( outfile, 0, nlp );
211
  fprintf(outfile,"\";\n");
212
  // 
213
  fprintf(outfile,"\t\t\tloops_end <= '0';\n");
214
  //
215
  fprintf(outfile,"\t\t\tif (task_loop%d_end = '1') then\n", nlp);
216
  fprintf(outfile,"\t\t\t\tincl <= \"");
217
  print_binary_value( outfile, ipow(2,i+1), nlp );
218
  fprintf(outfile,"\";\n");
219
  fprintf(outfile,"\t\t\telse\n");
220
  fprintf(outfile,"\t\t\t\tincl <= \"");
221
  print_binary_value( outfile, 0, nlp );
222
  fprintf(outfile,"\";\n");
223
  fprintf(outfile,"\t\t\tend if;\n");
224
  //                    
225
  fprintf(outfile,"\t\tend if;\n");
226
  fprintf(outfile,"\tend process;\n");
227
  fprintf(outfile,"\n");
228
  //
229
  fprintf(outfile,"end rtl;\n");
230
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.