需要在一个时钟周期内(125MHz)完成,我想进行并行比较,没找到例子,自己写了一个,思路就是1和2比,较大的一个和3比,再得到一个和4比,依次类推。时序仿真结果不太稳定,最大值的位置应该在0-9内,但是结果经常出现10-15,不知道错在哪儿。另外有没有更好的办法能推荐一下,谢谢。 library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all;
entity max19_10_comb is port( clock:in std_logic; data0,data1,data2,data3,data4,data5,data6,data7:in std_logic_vector(18 downto 0); data8,data9:in std_logic_vector(18 downto 0); result_value:out std_logic_vector(18 downto 0); result_index:out std_logic_vector(3 downto 0) ); end max19_10_comb;
architecture beha of max19_10_comb is signal index0:std_logic_vector(3 downto 0):="0000"; signal index1:std_logic_vector(3 downto 0):="0001"; signal index2:std_logic_vector(3 downto 0):="0010"; signal index3:std_logic_vector(3 downto 0):="0011"; signal index4:std_logic_vector(3 downto 0):="0100"; signal index5:std_logic_vector(3 downto 0):="0101"; signal index6:std_logic_vector(3 downto 0):="0110"; signal index7:std_logic_vector(3 downto 0):="0111"; signal index8:std_logic_vector(3 downto 0):="1000"; signal index9:std_logic_vector(3 downto 0):="1001"; signal result01,result02,result03,result04,result05,result06,result07:std_logic_vector(18 downto 0); signal result08,result09:std_logic_vector(18 downto 0); signal index01,index02,index03,index04,index05,index06,index07:std_logic_vector(3 downto 0); signal index08,index09:std_logic_vector(3 downto 0);
begin process(data0,data1,data2,data3,data4,data5,data6,data7,data8,data9,result01,result02,result03,result04,result05,result06,result07,result08,result09,index01,index02,index03,index04,index05,index06,index07,index08,index09) begin if data0 > data1 then result01 <= data0; index01 <= index0; else result01 <= data1; index01 <= index1; end if; if result01 > data2 then result02 <= result01; index02 <= index01; else result02 <= data2; index02 <= index2; end if; if result02 > data3 then result03 <= result02; index03 <= index02; else result03 <= data3; index03 <= index3; end if; if result03 > data4 then result04 <= result03; index04 <= index03; else result04 <= data4; index04 <= index4; end if; if result04 > data5 then result05 <= result04; index05 <= index04; else result05 <= data5; index05 <= index5; end if; if result05 > data6 then result06 <= result05; index06 <= index05; else result06 <= data6; index06 <= index6; end if; if result06 > data7 then result07 <= result06; index07 <= index06; else result07 <= data7; index07 <= index7; end if; if result07 > data8 then result08 <= result07; index08 <= index07; else result08 <= data8; index08 <= index8; end if; if result08 > data9 then result09 <= result08; index09 <= index08; else result09 <= data9; index09 <= index9; end if;
end process; process(clock) begin if clock'EVENT and clock = '1' then result_value <= result09; result_index <= index09; end if; end process; end beha;
|
|