在模拟中,这是完美的。这是检查的最佳方式吗? 可合成代码的零。会产生什么资源?
signal vector_slv : std_logic_vector(2048 downto 0);
...
if (vector_slv = (vector_slv'range => '0')) then
-- do something...
考虑到h / w映射(具有最佳资源利用率),是否还有其他最佳方式来实现此解决方案。
我对了解所使用的资源更感兴趣。
答案 0 :(得分:6)
如果范围可用,如示例代码中所示,那么建议 解决方案看起来很好,我希望合成工具能够处理 像这样的结构。
如果范围不可用,则可以将与零进行比较,如:
library ieee;
use ieee.numeric_std.all;
...
if unsigned( {std_logic_vector expression of any length} ) = 0 then
-- do something...
我希望合成工具能够像处理一样处理这个问题
与(vector_slv'range => '0')
。
答案 1 :(得分:5)
没有办法对合成有或多或少的意义。编写最能表达您意图的代码。
如果您要比较所有零的向量,以下应该都会产生相同的结果,或者您应该对该工具提出严重的错误!
signal vector_slv : std_logic_vector(2048 downto 0);
constant zeros : std_logic_vector(vector_slv'range) := (others => '0');
...
if vector_slv = (vector_slv'range => '0') then
-- do something...
if vector_slv = zeros then
-- do something...
if unsigned(vector_slv) = to_unsigned(0, vector_slv'length) then
-- do something...
实际上对于适合整数的较短向量:
if intvar = 0 then
与任何32位向量比较完全相同。
<子>
(顺便说一句,注意if
条件周围不需要括号 - VHDL不是C :)
子>
答案 2 :(得分:1)
就合成而言,是的,这种简单的结构通常可以通过该工具很好地优化。当然,确切的硬件布局取决于您的目标(FPGA,ASIC,......)。
我的建议是查看综合结果(例如Altera FPGA的技术地图查看器)。如果合成破坏它,您可以手动将其转换为零比较的二叉树,同时考虑到您可用的技术原语。然而,这听起来要比听起来要棘手得多,特别是对于FPGA(不仅仅是LUT可以在那里玩),并且对于一个不错的工具来说也不是必需的。
答案 3 :(得分:1)
您可以使用一元运算符,例如:
signal vector_slv: std_logic_vector(2048 downto 0);
...
if and vector_slv then
-- Do something for all 1...
elsif nand vector_slv then
-- Do something for at least one 0...
elsif or vector_slv then
-- Do something for at least one 1...
elsif nor vector_slv then
-- Do something for all 0...
end if;
或者您可以使用std_logic_1164中定义的功能,例如:
function "and" (l : STD_ULOGIC_VECTOR) return STD_ULOGIC;
function "nand" (l : STD_ULOGIC_VECTOR) return STD_ULOGIC;
function "or" (l : STD_ULOGIC_VECTOR) return STD_ULOGIC;
function "nor" (l : STD_ULOGIC_VECTOR) return STD_ULOGIC;
use ieee.std_logic_1164.all;
...
signal vector_slv: std_logic_vector(2048 downto 0);
...
if and(vector_slv) then
-- Do something for all 1...
elsif nand(vector_slv) then
-- Do something for at least one 0...
elsif or(vector_slv) then
-- Do something for at least one 1...
elsif nor(vector_slv) then
-- Do something for all 0...
end if;
答案 4 :(得分:0)
您还可以通过以下操作将谓词和赋值分开:
signal is_zero : boolean;
signal vector_slv : std_logic_vector(2048 downto 0);
...
process(clk)
begin
if rising_edge(clk) then
is_zero <= vector_slv = (vector_slv'range => '0');
if is_zero then
...
end if;
end if;
end process;
这将大大改善您的计时。考虑到谓词“ is_zero”现在是原始比较的延迟版本!