vhdl - 如何创建大于 2^3-1 的 numeric_std 有符号值?

标签 vhdl

在下面的类型和常量声明中,数组中的最后一个值实际上不会是 2**35-1,因为整数大于 2**31-1 code> 不是标准 VHDL (2002)

library ieee;
use ieee.numeric_std.all;

-- Boilerplate elided...

constant X_SIZE : natural := 40; -- Really, anything greater than 32
type x_array is array(natural range <>) of signed;

constant XS : x_array := (
    to_signed(0, X_SIZE),
    to_signed(1, X_SIZE),
    to_signed(2**35 - 1, X_SIZE) -- Not possible!
);

我无法执行 to_signed(2, X_SIZE)**35 - 1,因为 signed 上未定义求幂。我不愿意输入完整的数组,因为它看起来很笨拙,而且 X_SIZE 将来可能会改变。那么我如何在这里创造我想要的值(value)呢?有没有比逐字输入 40 个 01 更好的方法?

最佳答案

根据值的不同,有几种方法可以实现。

  1. 使用十六进制文字适合任意数字,并且可以节省一点空间:x"1FFFFFFFF"
  2. 聚合赋值提供了一种指定模式的方法(例如,对于任何大小,一个零后跟全一):(X_SIZE-1 downto 35 => '0', other => '1') — 但请注意,如果您尝试将其与其他运算符或函数结合使用,编译器将无法推断所需的向量大小。您需要执行以下操作:(X_SIZE-1 downto 35 => '1', 35 downto 0 => '0')。此时,您可能不会节省太多空间,但根据您正在做的事情,它可能会让您的意图比文字更清晰。
  3. 您还可以构建所需类型的单位,并将其左右移动:shift_left(to_unsigned(1, X_SIZE), 35) - 1

关于vhdl - 如何创建大于 2^3-1 的 numeric_std 有符号值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11219350/

相关文章:

vhdl - 在 ModelSim 中从断点跳转到断点

vhdl - VHDL 中的 Mealy machine 1011 检测器

c - microblaze 和 vhdl 之间如何通信?

vhdl - vsim 在 Windows 上不接受 -modelsimini 参数

error-handling - VHDL类型在仿真期间不匹配

templates - 是否可以在 vhdl 中使用泛型类型?

type-conversion - VHDL 中的类型转换 : real to integer - Is the rounding mode specified?

vhdl - 如何在 VHDL 中合成进程内的循环?

arrays - VHDL 中的多维信号数组

arrays - 数组类型的 VHDL 赋值