VHDL缩位与/缩位或运算

缩位运算符,即"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_reduceand_reduce也可以完成上面的内容。要主要包含头文件std_logic_misc

参考文献
  1. https://electronics.stackexchange.com/questions/85922/vhdl-or-ing-bits-of-a-vector-together
  2. https://stackoverflow.com/questions/20296276/and-all-elements-of-an-n-bit-array-in-vhdl
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值