添加use ieee.std_logic_unsigned.all;就像打开潘多拉的盒子
Synopsys 库。经过如下所示的深入研究,结论是
在这种情况下,std_logic_unsigned 包使值 '0' 和 'L' 相等
通过一张桌子。
当“=”运算符被重新定义为:
function "="(L: STD_LOGIC_VECTOR; R: STD_LOGIC_VECTOR) return BOOLEAN is
begin
return UNSIGNED(L) = UNSIGNED(R);
end;
然而这只是开始,因为 std_logic_unsigned 包括
use IEEE.std_logic_arith.all;,它定义了类型:
type UNSIGNED is array (NATURAL range <>) of STD_LOGIC;
“=”中UNSIGNED的比较从而导致调用std_logic_arith函数:
function "="(L: UNSIGNED; R: UNSIGNED) return BOOLEAN is
-- synopsys subpgm_id 341
constant length: INTEGER := max(L'length, R'length);
begin
return bitwise_eql( STD_ULOGIC_VECTOR( CONV_UNSIGNED(L, length) ),
STD_ULOGIC_VECTOR( CONV_UNSIGNED(R, length) ) );
end;
在这个函数中,CONV_UNSIGNED 很有趣:
function CONV_UNSIGNED(ARG: UNSIGNED; SIZE: INTEGER) return UNSIGNED is
constant msb: INTEGER := min(ARG'length, SIZE) - 1;
subtype rtype is UNSIGNED (SIZE-1 downto 0);
variable new_bounds: UNSIGNED (ARG'length-1 downto 0);
variable result: rtype;
-- synopsys built_in SYN_ZERO_EXTEND
-- synopsys subpgm_id 372
begin
-- synopsys synthesis_off
new_bounds := MAKE_BINARY(ARG);
if (new_bounds(0) = 'X') then
result := rtype'(others => 'X');
return result;
end if;
result := rtype'(others => '0');
result(msb downto 0) := new_bounds(msb downto 0);
return result;
-- synopsys synthesis_on
end;
现在我们已经接近了,因为上面的调用:
function MAKE_BINARY(A : UNSIGNED) return UNSIGNED is
-- synopsys built_in SYN_FEED_THRU
variable one_bit : STD_ULOGIC;
variable result : UNSIGNED (A'range);
begin
-- synopsys synthesis_off
for i in A'range loop
if (IS_X(A(i))) then
assert false
report "There is an 'U'|'X'|'W'|'Z'|'-' in an arithmetic operand, the result will be 'X'(es)."
severity warning;
result := (others => 'X');
return result;
end if;
result(i) := tbl_BINARY(A(i));
end loop;
return result;
-- synopsys synthesis_on
end;
在这里我们有'L'等于'0'的原因,因为tbl_BINARY
是一个常量,定义为:
type tbl_type is array (STD_ULOGIC) of STD_ULOGIC;
constant tbl_BINARY : tbl_type :=
('X', 'X', '0', '1', 'X', 'X', '0', '1', 'X');
要理解这种映射,与
STD_ULOGIC 中的值:
std_ulogic: ( 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', '-');
tbl_BINARY: ( 'X', 'X', '0', '1', 'X', 'X', '0', '1', 'X');
这表明通过 tbl_BINARY 转换后则等效组
是 ('U', 'X', 'Z', 'W', '-'), ('0', 'L') 和 ('1', 'H')。
最后的评论是,即使通过 std_logic_unsigned 包驻留
在一个名为“ieee”的库中,该包不是像 VHDL 这样的 IEEE 标准,而是一个
新思软件包。该软件包和其他相关的 Synopsys 软件包具有
已经存在了一段时间并被广泛使用。
但是,您可以考虑改用 IEEE 标准包 numeric_std。