vhdl - VHDL 中的通用移位算法

标签 vhdl fpga circuit hdl

我正在设计通用移位算术运算符。 除了以下面介绍的方式使用 32 位多路复用器(解码器)之外,还有更好的方法来实现它吗?

ENTITY isra IS 
PORT (
  clk:    in std_logic;
  rst:    in std_logic;
  di:     in std_logic_vector (31 downto 0);
  sel:    in std_logic_vector (31  downto 0);
  res:    out std_logic_vector (31 downto 0) := (others => '0')
);
END isra;


PROCESS
  BEGIN
    WAIT UNTIL clk'EVENT AND clk = '1';
    IF rst = '1' THEN
      res <= (others => '0');
    ELSE
    CASE sel IS
        when X"00000001"  => res <= to_stdlogicvector(to_bitvector(a) sra 1);
        when X"00000002"  => res <= to_stdlogicvector(to_bitvector(a) sra 2);
        ...
        when X"0000001F"  => res <= to_stdlogicvector(to_bitvector(a) sra 31);
        when others => res <= (others => '0');
    END CASE;
END IF;
END PROCESS;

最佳答案

您可以在没有任何循环或 case 语句的情况下使用 SRA 函数:

res <= to_stdlogicvector(to_bitvector(di) sra to_integer(sel));

请注意,您需要使 sel 成为无符号的,而不是 std_logic_vector:

sel: in unsigned (31  downto 0);

如果您不想这样,您仍然可以将 sel 转换为无符号的。您还需要我们 numeric_bit:

use ieee.numeric_bit.all;

关于vhdl - VHDL 中的通用移位算法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4174473/

相关文章:

ide - 专业的VHDL IDE?

compiler-construction - FPGA 设计是否应该整合到计算机科学类(class)中?

vhdl - 如何计算 FPGA spartan 板上的按键数

用于计算逻辑电路输出的 Matlab 程序

VHDL:将输出切片映射到信号

algorithm - 生成 nCk 个从 0 到 n-1 的数字组合

arduino - 如何读取多个模拟传感器

architecture - 需要帮助弄清楚 FPGA 的 CLB 是如何构建的(在此图上)

comparison - 有人有关于 VHDL 与 Verilog 使用的定量数据吗?

hardware - FPGA 的配置数量限制?