VHDL:是否可以用记录定义通用类型?

发布于 2024-11-15 10:12:46 字数 771 浏览 2 评论 0原文

我正在尝试定义一个复杂类型(即由实部和虚部组成的类型),并试图找到一种使其通用的方法。

This my current static code:

  type complex_vector is record
    Re : signed(15 downto 0);
    Im : signed(15 downto 0);
  end record;

现在我想知道是否有一种方法可以使其通用,换句话说:

  type complex_vector (Generic: Integer := WIDTH) is record
    Re : signed(WIDTH downto 0);
    Im : signed(WIDTH downto 0);
  end record;

我尝试在谷歌上搜索解决方案并浏览我的书籍,但我找不到任何解决方案。真的没有吗?如果没有记录,就可以写出这样的东西:

type blaaa is array (NATURAL range <>) of STD_LOGIC;

感谢您的任何输入

编辑:

或者我可以做类似以下的事情吗?

type complex_primitives is (re, im);
type complex_vector is array (re to im) of signed(natural range <>);

但编译器抱怨..

I am trying to define a complex type (i.e, a type that consists of both a real and imaginary part) and am trying to find out a way to make it generic.

This my current static code:

  type complex_vector is record
    Re : signed(15 downto 0);
    Im : signed(15 downto 0);
  end record;

Now I wonder whether there is a way to make this generic, in in other word something like:

  type complex_vector (Generic: Integer := WIDTH) is record
    Re : signed(WIDTH downto 0);
    Im : signed(WIDTH downto 0);
  end record;

I tried to google for a solution as well as going through my books, but I cannot find any solution. Is there really none? Without records it is possible to wright something like this:

type blaaa is array (NATURAL range <>) of STD_LOGIC;

Thanks for any input

EDIT:

Or could I do something like the following?

type complex_primitives is (re, im);
type complex_vector is array (re to im) of signed(natural range <>);

The compiler complains though..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤还要旧人安 2024-11-22 10:12:46

以下是 VHDL-2008 中的合法语法:

type complex is record
  re : signed ;  -- Note that this is unconstrained
  im : signed ;
end record ;

signal my_complex_signal : complex (re(7 downto 0), im(7 downto 0)) ;

重要说明 此示例使用具有无约束数组的记录。目前对 VHDL-2008 的支持还很不稳定。一些工具支持许多 VHDL-2008 功能,但许多工具尚未完全支持所有新功能。

要了解 VHDL-2008 和新功能,请参阅此演示文稿,这是一个很好的总结关于这个问题。

The following is legal syntax in VHDL-2008:

type complex is record
  re : signed ;  -- Note that this is unconstrained
  im : signed ;
end record ;

signal my_complex_signal : complex (re(7 downto 0), im(7 downto 0)) ;

IMPORTANT NOTE This example makes use of records with unconstrained arrays. Support for VHDL-2008 at this point is hit-and-miss. Some tools support many of VHDL-2008 features, but many do not yet fully support all new features.

To read about VHDL-2008 and the new features, see this presentation which is a good summary on the subject.

戴着白色围巾的女孩 2024-11-22 10:12:46

在支持 VHDL-2008 之前(不要屏住呼吸!),有一个次优的忽悠...

在多个同名的包中创建您想要的不同大小的记录,然后选择在定义宽度的包中进行编译你想使用。

-- complex_vector_16.vhd
package types is
  type complex_vector is record
    Re : signed(15 downto 0);
    Im : signed(15 downto 0);
  end record;
end;

-- complex_vector_32.vhd
package types is
  type complex_vector is record
    Re : signed(31 downto 0);
    Im : signed(31 downto 0);
  end record;
end;


library complex.types
use complex.types.complex_vector;

这种方法的严重限制是您在设计中只能支持单一形式的complex_vector,但从好的方面来说您不必担心工具支持!

向工具链中的每个供应商提出有关您的用例的支持/增强请求将很有用。被窃听的越多,VHDL-2008 就会越早得到支持。

Until VHDL-2008 is supported (don't hold your breath!) there are is a sub-optimal fudge...

Create the different sized records you want in multiple packages of the same name and then optionally compile in the package defining the width you want to use.

-- complex_vector_16.vhd
package types is
  type complex_vector is record
    Re : signed(15 downto 0);
    Im : signed(15 downto 0);
  end record;
end;

-- complex_vector_32.vhd
package types is
  type complex_vector is record
    Re : signed(31 downto 0);
    Im : signed(31 downto 0);
  end record;
end;


library complex.types
use complex.types.complex_vector;

The severe limitation of this method is that you can only support a single form of complex_vector in the design, but on the plus side you don't have to worry about tool support!

It would be useful to raise a support/enhancement request with every vendor in your toolchain regarding your use case. The more they get bugged the sooner VHDL-2008 will be supported.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文