URL
https://opencores.org/ocsvn/hwlu/hwlu/trunk
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 4 to Rev 5
- ↔ Reverse comparison
-
Rev 4 → Rev 5
trunk/doc/hwlu_spec.pdf
Property changes :
Deleted: svn:mime-type
## -1 +0,0 ##
-application/octet-stream
\ No newline at end of property
Index: trunk/sw/gen_hw_looping.c
===================================================================
--- trunk/sw/gen_hw_looping.c (revision 4)
+++ trunk/sw/gen_hw_looping.c (nonexistent)
@@ -1,331 +0,0 @@
-/* Filename: gen_hw_looping.c */
-/* Description: Generates top-level module for the hw_looping unit */
-/* Author: Nikos Kavvadias,
*/
-/* Date: Friday, 09/04/2004 */
-
-#include
-#include
-#include
-
-#define PRINT_DEBUG
-
-
-// FUNCTION PROTOTYPES
-void write_file_hw_looping(FILE *outfile);
-
-FILE *file_hw_looping; /* VHDL source for the top-level module of the
- * hw_looping unit (hw_looping.vhd) */
-
-char hw_looping_file_name[32];
-int nlp;
-time_t t;
-
-
-int main(int argc, char **argv)
-{
- int i;
- int gen_hw_looping_file;
- char nlp_s[3];
-
- gen_hw_looping_file = 0;
-
- if( argc < 3 )
- {
- printf("Usage: gen_hw_looping
hwlu/trunk/doc/hwlu_spec.pdf
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: hwlu/trunk/sw/gen_hw_looping.c
===================================================================
--- hwlu/trunk/sw/gen_hw_looping.c (nonexistent)
+++ hwlu/trunk/sw/gen_hw_looping.c (revision 5)
@@ -0,0 +1,331 @@
+/* Filename: gen_hw_looping.c */
+/* Description: Generates top-level module for the hw_looping unit */
+/* Author: Nikos Kavvadias,
*/
+/* Date: Friday, 09/04/2004 */
+
+#include
+#include
+#include
+
+#define PRINT_DEBUG
+
+
+// FUNCTION PROTOTYPES
+void write_file_hw_looping(FILE *outfile);
+
+FILE *file_hw_looping; /* VHDL source for the top-level module of the
+ * hw_looping unit (hw_looping.vhd) */
+
+char hw_looping_file_name[32];
+int nlp;
+time_t t;
+
+
+int main(int argc, char **argv)
+{
+ int i;
+ int gen_hw_looping_file;
+ char nlp_s[3];
+
+ gen_hw_looping_file = 0;
+
+ if( argc < 3 )
+ {
+ printf("Usage: gen_hw_looping \n");
+ printf("where:\n");
+ printf("num loops = give number of supported loops\n");
+ printf("output base = output file base name. The generated files will be named:\n");
+ printf(" \"_top.vhd\" for the top-level module\n");
+ //
+ printf("\n");
+ //
+ return -1;
+ }
+
+ // Acquire number of supported loops
+ strcpy(nlp_s,argv[1]);
+ nlp = atoi(nlp_s);
+
+ // Generate hw_looping_file_name
+ // (indicating the number of loops supported)
+
+ // Filenames for the requested VHDL source files
+ //strcpy(hw_looping_file_name,argv[2]);
+ //strcat(hw_looping_file_name,nlp_s);
+ //strcat(hw_looping_file_name,"_top.vhd");
+ sprintf(hw_looping_file_name,"%s_loops%s%s", argv[2], nlp_s, "_top.vhd");
+ gen_hw_looping_file = 1;
+
+ // DEBUG OUTPUT
+ #ifdef PRINT_DEBUG
+ printf("\n");
+ //
+ printf("nlp = %d\n",nlp);
+ printf("hw_looping_file_name = %s\n", hw_looping_file_name);
+ //
+ #endif
+
+
+ /*************************************************************/
+ /* Generate VHDL source for the top-level unit of hw_looping */
+ /*************************************************************/
+ if (gen_hw_looping_file == 1)
+ {
+ file_hw_looping = fopen(hw_looping_file_name,"w");
+ write_file_hw_looping(file_hw_looping);
+ fclose(file_hw_looping);
+ }
+
+ return 0;
+
+}
+
+
+void write_file_hw_looping(
+ FILE *outfile // Name for the output file
+ )
+{
+ unsigned i;
+
+ // Get current time
+ time(&t);
+
+ /* Generate interface for the VHDL file */
+ fprintf(outfile,"----==============================================================----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Filename: %s ----\n", hw_looping_file_name);
+ fprintf(outfile,"---- Module description: Top-level file for the hw_looping unit. ----\n");
+ fprintf(outfile,"---- Also implements input and output ----\n");
+ fprintf(outfile,"---- wrapping operations. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Author: Nikolaos Kavvadias ----\n");
+ fprintf(outfile,"---- nkavv@skiathos.physics.auth.gr ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Part of the hwlu OPENCORES project generated automatically ----\n");
+ fprintf(outfile,"---- with the use of the \"gen_hw_looping\" tool ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- To Do: ----\n");
+ fprintf(outfile,"---- Considered stable for the time being ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Author: Nikolaos Kavvadias ----\n");
+ fprintf(outfile,"---- nkavv@skiathos.physics.auth.gr ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"----==============================================================----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Copyright (C) 2004 Nikolaos Kavvadias ----\n");
+ fprintf(outfile,"---- nick-kavi.8m.com ----\n");
+ fprintf(outfile,"---- nkavv@skiathos.physics.auth.gr ----\n");
+ fprintf(outfile,"---- nick_ka_vi@hotmail.com ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- This source file may be used and distributed without ----\n");
+ fprintf(outfile,"---- restriction provided that this copyright statement is not ----\n");
+ fprintf(outfile,"---- removed from the file and that any derivative work contains ----\n");
+ fprintf(outfile,"---- the original copyright notice and the associated disclaimer. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- This source file is free software; you can redistribute it ----\n");
+ fprintf(outfile,"---- and/or modify it under the terms of the GNU Lesser General ----\n");
+ fprintf(outfile,"---- Public License as published by the Free Software Foundation; ----\n");
+ fprintf(outfile,"---- either version 2.1 of the License, or (at your option) any ----\n");
+ fprintf(outfile,"---- later version. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- This source is distributed in the hope that it will be ----\n");
+ fprintf(outfile,"---- useful, but WITHOUT ANY WARRANTY; without even the implied ----\n");
+ fprintf(outfile,"---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----\n");
+ fprintf(outfile,"---- PURPOSE. See the GNU Lesser General Public License for more ----\n");
+ fprintf(outfile,"---- details. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- You should have received a copy of the GNU Lesser General ----\n");
+ fprintf(outfile,"---- Public License along with this source; if not, download it ----\n");
+ fprintf(outfile,"---- from ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"----==============================================================----\n");
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"-- CVS Revision History\n");
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"\n");
+
+ /* Code generation for library inclusions */
+ fprintf(outfile,"library IEEE;\n");
+ fprintf(outfile,"use IEEE.std_logic_1164.all;\n");
+ fprintf(outfile,"\n");
+
+ /* Generate entity declaration */
+ fprintf(outfile,"entity hw_looping is\n");
+ fprintf(outfile,"\tgeneric (\n");
+ fprintf(outfile,"\t\tDW : integer := 8;\n");
+ fprintf(outfile,"\t\tNLP : integer := %d\n", nlp);
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"\tport (\n");
+ fprintf(outfile, "\t\tclk : in std_logic;\n");
+ fprintf(outfile, "\t\treset : in std_logic;\n");
+ fprintf(outfile, "\t\ttask_loop%d_end : in std_logic;\n", nlp);
+ //
+ for (i=1; i<=nlp; i++)
+ fprintf(outfile,"\t\tloop%d_count : in std_logic_vector(DW-1 downto 0);\n", i);
+ //
+ for (i=1; i<=nlp; i++)
+ {
+ fprintf(outfile,"\t\tindex%d : out std_logic_vector(DW-1 downto 0);\n", i);
+ }
+ //
+ fprintf(outfile, "\t\tloops_end : out std_logic\n");
+ //
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"end hw_looping;\n");
+ fprintf(outfile,"\n");
+
+ /* Generate architecture declaration */
+ fprintf(outfile,"architecture structural of hw_looping is\n");
+
+ /* Add component declarations here if needed */
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"-- Component declarations\n");
+ fprintf(outfile,"component cmpeq\n");
+ fprintf(outfile,"\tgeneric (\n");
+ fprintf(outfile,"\t\tDW : integer := 8\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"\tport (\n");
+ fprintf(outfile,"\t\ta : in std_logic_vector(DW-1 downto 0);\n");
+ fprintf(outfile,"\t\tb : in std_logic_vector(DW-1 downto 0);\n");
+ fprintf(outfile,"\t\treset : in std_logic;\n");
+ fprintf(outfile,"\t\ta_eq_b : out std_logic\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"end component;\n");
+ //
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"component index_inc\n");
+ fprintf(outfile,"\tgeneric (\n");
+ fprintf(outfile,"\t\tDW : integer := 8\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"\tport (\n");
+ fprintf(outfile,"\t\tclk : in std_logic;\n");
+ fprintf(outfile,"\t\treset : in std_logic;\n");
+ fprintf(outfile,"\t\tinc_en : in std_logic;\n");
+ fprintf(outfile,"\t\tindex_plus_one : out std_logic_vector(DW-1 downto 0);\n");
+ fprintf(outfile,"\t\tindex_out : out std_logic_vector(DW-1 downto 0)\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"end component;\n");
+ //
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"component priority_encoder\n");
+ fprintf(outfile,"\tgeneric (\n");
+ fprintf(outfile,"\t\tNLP : integer := 5\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"\tport (\n");
+ fprintf(outfile,"\t\tflag : in std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"\t\ttask_loop%d_end : in std_logic;\n", nlp);
+ fprintf(outfile,"\t\tincl : out std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"\t\treset_vct : out std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"\t\tloops_end : out std_logic\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"end component;\n");
+
+ /* Add signal declarations here if needed */
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"-- Signal declarations\n");
+ // flag
+ fprintf(outfile,"signal flag : std_logic_vector(NLP-1 downto 0);\n");
+ // incl
+ fprintf(outfile,"signal incl : std_logic_vector(NLP-1 downto 0);\n");
+ // temp_loop_count
+ fprintf(outfile,"signal temp_loop_count : std_logic_vector(NLP*DW-1 downto 0);\n");
+ // temp_index
+ fprintf(outfile,"signal temp_index : std_logic_vector(NLP*DW-1 downto 0);\n");
+ // temp_index_plus_one
+ fprintf(outfile,"signal temp_index_plus_one : std_logic_vector(NLP*DW-1 downto 0);\n");
+ // temp_vct_penc
+ fprintf(outfile,"signal reset_vct_penc : std_logic_vector(NLP-1 downto 0);\n");
+ // temp_index
+ fprintf(outfile,"signal reset_vct_ix : std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"--\n");
+
+ /* Continue with the rest of the architecture declaration */
+ fprintf(outfile,"begin\n");
+ fprintf(outfile,"\n");
+
+ /***************************************/
+ /* GENERATE INPUT WRAPPING ASSIGNMENTS */
+ /***************************************/
+
+ /* Iterate through all loops */
+ for (i=1; i<=nlp; i++)
+ {
+ /* Generate assignment code */
+ fprintf(outfile,"\ttemp_loop_count( ((NLP-%d)*DW-1) downto ((NLP-%d)*DW) ) <= loop%d_count;\n",
+ i-1, i, i);
+ }
+ fprintf(outfile,"\n");
+
+ /***************************************/
+ /* GENERATE INTERNAL HW_LOOPING MODULE */
+ /***************************************/
+
+ // Generate cmpeq modules
+ fprintf(outfile,"\tGEN_COMPARATORS: for i in 0 to NLP-1 generate\n");
+ fprintf(outfile,"\t\tU_cmp : cmpeq\n");
+ fprintf(outfile,"\t\t\tgeneric map (\n");
+ fprintf(outfile,"\t\t\t\tDW => DW\n");
+ fprintf(outfile,"\t\t\t)\n");
+ fprintf(outfile,"\t\t\tport map (\n");
+ fprintf(outfile,"\t\t\t\ta => temp_index_plus_one( ((i+1)*DW-1) downto (i*DW) ),\n");
+ fprintf(outfile,"\t\t\t\tb => temp_loop_count( ((i+1)*DW-1) downto (i*DW) ),\n");
+ fprintf(outfile,"\t\t\t\treset => reset,\n");
+ fprintf(outfile,"\t\t\t\ta_eq_b => flag(i)\n");
+ fprintf(outfile,"\t\t\t);\n");
+ fprintf(outfile,"\tend generate GEN_COMPARATORS;\n");
+ fprintf(outfile,"\n");
+
+ // Generate priority encoder
+ fprintf(outfile,"\tU_priority_enc : priority_encoder\n");
+ fprintf(outfile,"\t\tgeneric map (\n");
+ fprintf(outfile,"\t\t\tNLP => NLP\n");
+ fprintf(outfile,"\t\t)\n");
+ fprintf(outfile,"\t\tport map (\n");
+ fprintf(outfile,"\t\t\tflag => flag,\n");
+ fprintf(outfile,"\t\t\ttask_loop5_end => task_loop5_end,\n");
+ fprintf(outfile,"\t\t\tincl => incl,\n");
+ fprintf(outfile,"\t\t\treset_vct => reset_vct_penc,\n");
+ fprintf(outfile,"\t\t\tloops_end => loops_end\n");
+ fprintf(outfile,"\t\t);\n");
+ fprintf(outfile,"\n");
+
+ // Generate reset_vct_ix
+ fprintf(outfile,"\tGEN_RESET_SEL: for i in 0 to NLP-1 generate\n");
+ fprintf(outfile,"\t\treset_vct_ix(i) <= reset_vct_penc(i) or reset;\n");
+ fprintf(outfile,"\tend generate GEN_RESET_SEL;\n");
+ fprintf(outfile,"\n");
+
+ // Generate index_inc modules
+ fprintf(outfile,"\tGEN_INC_IX: for i in 0 to NLP-1 generate\n");
+ fprintf(outfile,"\t\tU_inc_ix1 : index_inc\n");
+ fprintf(outfile,"\t\t\tgeneric map (\n");
+ fprintf(outfile,"\t\t\t\tDW => DW\n");
+ fprintf(outfile,"\t\t\t)\n");
+ fprintf(outfile,"\t\t\tport map (\n");
+ fprintf(outfile,"\t\t\t\tclk => clk,\n");
+ fprintf(outfile,"\t\t\t\treset => reset_vct_ix(i),\n");
+ fprintf(outfile,"\t\t\t\tinc_en => incl(i),\n");
+ fprintf(outfile,"\t\t\t\tindex_plus_one => temp_index_plus_one( ((i+1)*DW-1) downto (i*DW) ),\n");
+ fprintf(outfile,"\t\t\t\tindex_out => temp_index( ((i+1)*DW-1) downto (i*DW) )\n");
+ fprintf(outfile,"\t\t\t);\n");
+ fprintf(outfile,"\tend generate GEN_INC_IX;\n");
+ fprintf(outfile,"\n");
+
+ /****************************************/
+ /* GENERATE OUTPUT WRAPPING ASSIGNMENTS */
+ /****************************************/
+
+ /* Iterate through all loops */
+ for (i=1; i<=nlp; i++)
+ {
+ /* Generate assignment code */
+ fprintf(outfile,"\tindex%d <= temp_index( ((NLP-%d)*DW-1) downto ((NLP-%d)*DW) );\n", i, i-1, i);
+ }
+ fprintf(outfile,"\n");
+
+ //
+ fprintf(outfile,"end structural;\n");
+
+}
+
\ No newline at end of file
Index: hwlu/trunk/sw/gen_priority_encoder.c
===================================================================
--- hwlu/trunk/sw/gen_priority_encoder.c (nonexistent)
+++ hwlu/trunk/sw/gen_priority_encoder.c (revision 5)
@@ -0,0 +1,424 @@
+/* Filename: gen_priority_encoder.c */
+/* Description: Generates priority_encoder module */
+/* Author: Nikos Kavvadias, */
+/* Date: Friday, 09/04/2004 */
+
+#include
+#include
+#include
+
+#define PRINT_DEBUG
+
+
+// FUNCTION PROTOTYPES
+void write_file_priority_encoder(FILE *outfile);
+unsigned dectobin(unsigned bin_data, int num_bits);
+unsigned ipow(unsigned x, unsigned y);
+unsigned log2(unsigned operand);
+void print_binary_value(FILE *outfile, int i);
+void print_binary_value_fbone(FILE *outfile, int i);
+
+
+FILE *file_priority_encoder; /* VHDL source for the priority_encoder module of the
+ * hw_looping unit (priority_encoder.vhd) */
+
+char priority_encoder_file_name[32];
+int nlp;
+time_t t;
+
+
+int main(int argc, char **argv)
+{
+ int i;
+ int gen_priority_encoder_file;
+ char nlp_s[3];
+
+ gen_priority_encoder_file = 0;
+
+ if( argc < 3 )
+ {
+ printf("Usage: gen_priority_encoder \n");
+ printf("where:\n");
+ printf("num loops = give number of supported loops\n");
+ printf("output base = output file base name. The generated files will be named:\n");
+ printf(" \".vhd\" for the module\n");
+ //
+ printf("\n");
+ //
+ return -1;
+ }
+
+ // Acquire number of supported loops
+ strcpy(nlp_s,argv[1]);
+ nlp = atoi(nlp_s);
+
+ // Filenames for the requested VHDL source files
+ sprintf(priority_encoder_file_name,"%s_loops%s%s", argv[2], nlp_s, ".vhd");
+ gen_priority_encoder_file = 1;
+
+
+ // DEBUG OUTPUT
+ #ifdef PRINT_DEBUG
+ printf("\n");
+ //
+ printf("nlp = %d\n",nlp);
+ printf("priority_encoder_file_name = %s\n", priority_encoder_file_name);
+ //
+ #endif
+
+
+ /******************************************************/
+ /* Generate VHDL source for the priority_encoder unit */
+ /******************************************************/
+ if (gen_priority_encoder_file == 1)
+ {
+ file_priority_encoder = fopen(priority_encoder_file_name,"w");
+ write_file_priority_encoder(file_priority_encoder);
+ fclose(file_priority_encoder);
+ }
+
+ return 0;
+
+}
+
+
+void write_file_priority_encoder(
+ FILE *outfile // Name for the output file -- e.g. mbloop_merger.vhd
+ )
+{
+ int i;
+
+ // Get current time
+ time(&t);
+
+ /* Generate interface for the VHDL file */
+ fprintf(outfile,"----==============================================================----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Filename: %s ----\n", priority_encoder_file_name);
+ fprintf(outfile,"---- Module description: Priority encoder unit. Obtains ----\n");
+ fprintf(outfile,"---- increment and reset decisions for the loop indices. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Author: Nikolaos Kavvadias ----\n");
+ fprintf(outfile,"---- nkavv@skiathos.physics.auth.gr ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Part of the hwlu OPENCORES project generated automatically ----\n");
+ fprintf(outfile,"---- with the use of the \"gen_priority_encoder\" tool ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- To Do: ----\n");
+ fprintf(outfile,"---- Considered stable for the time being ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Author: Nikolaos Kavvadias ----\n");
+ fprintf(outfile,"---- nkavv@skiathos.physics.auth.gr ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"----==============================================================----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- Copyright (C) 2004 Nikolaos Kavvadias ----\n");
+ fprintf(outfile,"---- nick-kavi.8m.com ----\n");
+ fprintf(outfile,"---- nkavv@skiathos.physics.auth.gr ----\n");
+ fprintf(outfile,"---- nick_ka_vi@hotmail.com ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- This source file may be used and distributed without ----\n");
+ fprintf(outfile,"---- restriction provided that this copyright statement is not ----\n");
+ fprintf(outfile,"---- removed from the file and that any derivative work contains ----\n");
+ fprintf(outfile,"---- the original copyright notice and the associated disclaimer. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- This source file is free software; you can redistribute it ----\n");
+ fprintf(outfile,"---- and/or modify it under the terms of the GNU Lesser General ----\n");
+ fprintf(outfile,"---- Public License as published by the Free Software Foundation; ----\n");
+ fprintf(outfile,"---- either version 2.1 of the License, or (at your option) any ----\n");
+ fprintf(outfile,"---- later version. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- This source is distributed in the hope that it will be ----\n");
+ fprintf(outfile,"---- useful, but WITHOUT ANY WARRANTY; without even the implied ----\n");
+ fprintf(outfile,"---- warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ----\n");
+ fprintf(outfile,"---- PURPOSE. See the GNU Lesser General Public License for more ----\n");
+ fprintf(outfile,"---- details. ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"---- You should have received a copy of the GNU Lesser General ----\n");
+ fprintf(outfile,"---- Public License along with this source; if not, download it ----\n");
+ fprintf(outfile,"---- from ----\n");
+ fprintf(outfile,"---- ----\n");
+ fprintf(outfile,"----==============================================================----\n");
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"-- CVS Revision History\n");
+ fprintf(outfile,"--\n");
+ fprintf(outfile,"\n");
+
+ /* Code generation for library inclusions */
+ fprintf(outfile,"library IEEE;\n");
+ fprintf(outfile,"use IEEE.std_logic_1164.all;\n");
+ fprintf(outfile,"use IEEE.std_logic_unsigned.all;\n");
+ fprintf(outfile,"\n");
+
+ /* Generate entity declaration */
+ fprintf(outfile,"entity priority_encoder is\n");
+ fprintf(outfile,"\tgeneric (\n");
+ fprintf(outfile,"\t\tNLP : integer := %d\n", nlp);
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"\tport (\n");
+ fprintf(outfile,"\t\tflag : in std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"\t\ttask_loop%d_end : in std_logic;\n", nlp);
+ fprintf(outfile,"\t\tincl : out std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"\t\treset_vct : out std_logic_vector(NLP-1 downto 0);\n");
+ fprintf(outfile,"\t\tloops_end : out std_logic\n");
+ fprintf(outfile,"\t);\n");
+ fprintf(outfile,"end priority_encoder;\n");
+ fprintf(outfile,"\n");
+
+ /* Generate architecture declaration */
+ fprintf(outfile,"architecture rtl of priority_encoder is\n");
+
+ /* Add component declarations here if needed */
+
+ /* Add signal declarations here if needed */
+
+ /* Continue with the rest of the architecture declaration */
+ fprintf(outfile,"begin\n");
+ fprintf(outfile,"\n");
+
+ fprintf(outfile,"\t-- Fully-nested loop structure with %d loops\n", nlp);
+ fprintf(outfile,"\t-- From outer to inner: ");
+ //
+ i = nlp-1;
+ fprintf(outfile,"%d", nlp-1);
+ //
+ if (nlp>=2)
+ {
+ for (i=nlp-2; i>=0; i--)
+ fprintf(outfile,"-> %d",i);
+ }
+ //
+ fprintf(outfile,"\n");
+
+ // Loop counter
+ i = nlp-1;
+
+ /********************/
+ /* GENERATE process */
+ /********************/
+
+ fprintf(outfile,"\tprocess (flag, task_loop5_end)\n");
+ fprintf(outfile,"\tbegin\n");
+ fprintf(outfile,"\t\t--\n");
+ fprintf(outfile,"\t\t-- if loop%d is terminating:\n", i);
+ fprintf(outfile,"\t\t-- reset loops %d-%d to initial index\n", i, 0);
+ //
+ fprintf(outfile,"\t\tif (flag(%d downto 0) = \"", i);
+ print_binary_value_fbone( outfile, ipow(2,i+1)-1 );
+ fprintf(outfile,"\") then\n");
+ //
+ fprintf(outfile,"\t\t\tincl <= \"");
+ print_binary_value( outfile, 0 );
+ fprintf(outfile,"\";\n");
+ //
+ fprintf(outfile,"\t\t\treset_vct <= \"");
+ print_binary_value( outfile, ipow(2,i+1)-1 );
+ fprintf(outfile,"\";\n");
+ //
+ fprintf(outfile,"\t\t\tloops_end <= '1';\n");
+
+ // Loop on all "elsif" cases: i=2 -> i=nlp
+ for (i=nlp-2; i>=0; i--)
+ {
+ fprintf(outfile,"\t\t-- else if loop%d is terminating:\n", i);
+ fprintf(outfile,"\t\t-- 1. increment loop%d index\n", i+1);
+ fprintf(outfile,"\t\t-- 2. reset loop%d to initial index\n", i);
+ //
+ fprintf(outfile,"\t\telsif (flag(%d downto 0) = \"", i);
+ print_binary_value_fbone( outfile, ipow(2,i+1)-1 );
+ fprintf(outfile,"\") then\n");
+ //
+ fprintf(outfile,"\t\t\tincl <= \"");
+ print_binary_value( outfile, ipow(2,i+1) );
+ fprintf(outfile,"\";\n");
+ //
+ fprintf(outfile,"\t\t\treset_vct <= \"");
+ print_binary_value( outfile, ipow(2,i+1)-1 );
+ fprintf(outfile,"\";\n");
+ //
+ fprintf(outfile,"\t\t\tloops_end <= '0';\n");
+ }
+
+ // Else increment inner loop
+ fprintf(outfile,"\t\t-- else increment loop%d index\n", i);
+ fprintf(outfile,"\t\telse\n");
+ //
+ fprintf(outfile,"\t\t\treset_vct <= \"");
+ print_binary_value( outfile, 0 );
+ fprintf(outfile,"\";\n");
+ //
+ fprintf(outfile,"\t\t\tloops_end <= '0';\n");
+ //
+ fprintf(outfile,"\t\t\tif (task_loop%d_end = '1') then\n", nlp);
+ fprintf(outfile,"\t\t\t\tincl <= \"");
+ print_binary_value( outfile, ipow(2,i+1) );
+ fprintf(outfile,"\";\n");
+ fprintf(outfile,"\t\t\telse\n");
+ fprintf(outfile,"\t\t\t\tincl <= \"");
+ print_binary_value( outfile, 0 );
+ fprintf(outfile,"\";\n");
+ fprintf(outfile,"\t\t\tend if;\n");
+ //
+ fprintf(outfile,"\t\tend if;\n");
+ fprintf(outfile,"\tend process;\n");
+ fprintf(outfile,"\n");
+ //
+ fprintf(outfile,"end rtl;\n");
+
+}
+
+
+unsigned dectobin(unsigned bin_data, int num_bits)
+{
+ int count;
+ unsigned MASK;
+ unsigned result;
+ unsigned result_arr[100];
+
+ count = num_bits;
+ MASK = 1<<(count-1);
+
+ result = 0;
+
+ for (count=num_bits-1; count>-1; count--)
+ {
+ result_arr[count] = (( bin_data & MASK ) ? 1 : 0 );
+ bin_data <<= 1;
+ }
+
+ for (count=num_bits-1; count>-1; count--)
+ result = ipow(10,count)*result_arr[count] + result;
+
+ return result;
+}
+
+
+unsigned ipow(unsigned x, unsigned y)
+{
+ unsigned i;
+ unsigned result;
+
+ result = 1;
+
+ for (i=1; i<=y; i++)
+ result = result*x;
+
+ return result;
+}
+
+
+/* log2 function for integers: unsigned log2(unsigned operand) */
+unsigned log2(unsigned operand)
+{
+ unsigned temp;
+ unsigned log_val;
+
+ temp = operand-1;
+ //temp = operand;
+ log_val = 0;
+
+ while (temp > 0)
+ {
+ temp = temp/2;
+ log_val = log_val + 1;
+ }
+
+ return log_val;
+}
+
+void print_binary_value(FILE *outfile, int i)
+{
+ // Print integer value
+ switch (nlp)
+ {
+ case 1:
+ fprintf(outfile,"%d",dectobin( i, nlp ));
+ break;
+ case 2:
+ fprintf(outfile,"%02d",dectobin( i, nlp ));
+ break;
+ case 3:
+ fprintf(outfile,"%03d",dectobin( i, nlp ));
+ break;
+ case 4:
+ fprintf(outfile,"%04d",dectobin( i, nlp ));
+ break;
+ case 5:
+ fprintf(outfile,"%05d",dectobin( i, nlp ));
+ break;
+ case 6:
+ fprintf(outfile,"%06d",dectobin( i, nlp ));
+ break;
+ case 7:
+ fprintf(outfile,"%07d",dectobin( i, nlp ));
+ break;
+ case 8:
+ fprintf(outfile,"%08d",dectobin( i, nlp ));
+ break;
+ case 9:
+ fprintf(outfile,"%09d",dectobin( i, nlp ));
+ break;
+ case 10:
+ fprintf(outfile,"%10d",dectobin( i, nlp ));
+ break;
+ case 11:
+ fprintf(outfile,"%11d",dectobin( i, nlp ));
+ break;
+ case 12:
+ fprintf(outfile,"%12d",dectobin( i, nlp ));
+ break;
+ case 13:
+ fprintf(outfile,"%13d",dectobin( i, nlp ));
+ break;
+ case 14:
+ fprintf(outfile,"%14d",dectobin( i, nlp ));
+ break;
+ case 15:
+ fprintf(outfile,"%15d",dectobin( i, nlp ));
+ break;
+ case 16:
+ fprintf(outfile,"%16d",dectobin( i, nlp ));
+ break;
+ default:
+ break;
+ }
+}
+
+// Print binary value -- First bit is "one".
+void print_binary_value_fbone(FILE *outfile, int i)
+{
+ // Print integer value
+ switch ( log2(i) )
+ {
+ // i = 1
+ case 0:
+ fprintf(outfile,"%d",dectobin( i, i ));
+ break;
+ // i = 2:3
+ case 1:
+ fprintf(outfile,"%d",dectobin( i, log2(i) ));
+ break;
+ // i = 4:7
+ case 2:
+ fprintf(outfile,"%02d",dectobin( i, log2(i) ));
+ break;
+ // i = 8:15
+ case 3:
+ fprintf(outfile,"%03d",dectobin( i, log2(i) ));
+ break;
+ // i = 16:31
+ case 4:
+ fprintf(outfile,"%04d",dectobin( i, log2(i) ));
+ break;
+ // i = 32:63
+ case 5:
+ fprintf(outfile,"%05d",dectobin( i, log2(i) ));
+ break;
+ default:
+ break;
+ }
+}
+
+
+
\ No newline at end of file
Index: hwlu/trunk
===================================================================
--- hwlu/trunk (nonexistent)
+++ hwlu/trunk (revision 5)
hwlu/trunk
Property changes :
Added: svn:mergeinfo
## -0,0 +0,0 ##
Index: hwlu/web_uploads
===================================================================
--- hwlu/web_uploads (nonexistent)
+++ hwlu/web_uploads (revision 5)
hwlu/web_uploads
Property changes :
Added: svn:mergeinfo
## -0,0 +0,0 ##
Index: hwlu/branches
===================================================================
--- hwlu/branches (nonexistent)
+++ hwlu/branches (revision 5)
hwlu/branches
Property changes :
Added: svn:mergeinfo
## -0,0 +0,0 ##
Index: hwlu/tags
===================================================================
--- hwlu/tags (nonexistent)
+++ hwlu/tags (revision 5)
hwlu/tags
Property changes :
Added: svn:mergeinfo
## -0,0 +0,0 ##
© copyright 1999-2024
OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.