L
Laurent Pinchart
Guest
Hi everybody,
I have some experience with VHDL as a language, but not much with bigger
systems design and optimization.
I need to implement address decoding for read/write operations on registers.
I would like to know which of those two methods gives better results and
should be prefered (of course, ff there is a better method that I haven't
thought about, feel free to mention it .
I would choose the first method, as the case can easily be mapped to
hardware, but I might be wrong.
Laurent Pinchart
-- CODE --
signal reg1: std_logic_vector(...);
signal reg2: std_logic_vector(...);
....
signal regn: std_logic_vector(...);
-- METHOD 1 --
process (clk, rst)
begin
if (rst = '1') then
reg1 <= REG1_INIT_VAL;
reg2 <= REG2_INIT_VAL;
...
regn <= REGn_INIT_VAL;
elsif (clk'Event and clk = '1') then
if (wr_en = '1') then
case addr is
when "0000" => reg1 <= data;
when "0001" => reg2 <= data;
...
when "1111" => regn <= data;
end case;
end if;
end if;
end process;
-- METHOD 2 --
signal reg1_sel : std_logic;
signal reg2_sel : std_logic;
....
signal regn_sel : std_logic;
reg1_sel <= '1' when wr_en and addr = "0000" else
'0';
reg2_sel <= '1' when wr_en and addr = "0001" else
'0';
....
regn_sel <= '1' when wr_en and addr = "1111" else
'0';
process (clk, rst)
begin
if (rst = '1') then
reg1 <= REG1_INIT_VAL;
elsif (clk'Event and clk = '1') then
if (reg1_sel = '1') then
reg1 <= data;
end if;
end if;
end process;
....
process (clk, rst)
begin
if (rst = '1') then
regn <= REGn_INIT_VAL;
elsif (clk'Event and clk = '1') then
if (regn_sel = '1') then
regn <= data;
end if;
end if;
end process;
I have some experience with VHDL as a language, but not much with bigger
systems design and optimization.
I need to implement address decoding for read/write operations on registers.
I would like to know which of those two methods gives better results and
should be prefered (of course, ff there is a better method that I haven't
thought about, feel free to mention it .
I would choose the first method, as the case can easily be mapped to
hardware, but I might be wrong.
Laurent Pinchart
-- CODE --
signal reg1: std_logic_vector(...);
signal reg2: std_logic_vector(...);
....
signal regn: std_logic_vector(...);
-- METHOD 1 --
process (clk, rst)
begin
if (rst = '1') then
reg1 <= REG1_INIT_VAL;
reg2 <= REG2_INIT_VAL;
...
regn <= REGn_INIT_VAL;
elsif (clk'Event and clk = '1') then
if (wr_en = '1') then
case addr is
when "0000" => reg1 <= data;
when "0001" => reg2 <= data;
...
when "1111" => regn <= data;
end case;
end if;
end if;
end process;
-- METHOD 2 --
signal reg1_sel : std_logic;
signal reg2_sel : std_logic;
....
signal regn_sel : std_logic;
reg1_sel <= '1' when wr_en and addr = "0000" else
'0';
reg2_sel <= '1' when wr_en and addr = "0001" else
'0';
....
regn_sel <= '1' when wr_en and addr = "1111" else
'0';
process (clk, rst)
begin
if (rst = '1') then
reg1 <= REG1_INIT_VAL;
elsif (clk'Event and clk = '1') then
if (reg1_sel = '1') then
reg1 <= data;
end if;
end if;
end process;
....
process (clk, rst)
begin
if (rst = '1') then
regn <= REGn_INIT_VAL;
elsif (clk'Event and clk = '1') then
if (regn_sel = '1') then
regn <= data;
end if;
end if;
end process;