缩位运算符,即"reduction operator"。对于VHDL来说,很少有人知道其缩位运算符是什么。首先缩位运算的意思是把一个vector合并成一位,例如缩位与运算符:对于一个std_logic_vector
名为example
的变量,完成examlle[0] and example[1] and ... and example[22]
这样的运算的运算符。
-
对于VHDL-2008,直接用
and
就可以完成:and(example)
; -
用组合逻辑自己写一个函数,按位或/与即可。
function and_reduct(slv : in std_logic_vector) return std_logic is variable res_v : std_logic := '1'; -- Null slv vector will also return '1' begin for i in slv'range loop res_v := res_v and slv(i); end loop; return res_v; end function; You can then use the function both inside and outside functions with: signal arg : std_logic_vector(7 downto 0); signal res : std_logic; ... res <= and_reduct(arg);
-
or_reduce
和and_reduce
也可以完成上面的内容。要主要包含头文件std_logic_misc
。