在可移植 VHDL 中使用特定于供应商的原语

Using vendor specific primitives in portable VHDL

我的项目是用可移植的 VHDL 编写的(主要是用 GHDL 开发的),但我想在可用时利用供应商特定的原语(例如乘法器)。

例如在 C/C++ 中,您可以使用 #ifdef 有条件地 select 不同的代码片段,具体取决于 CPU 体系结构或编译器供应商。

是否有任何类似的东西可以在 VHDL 中使用,例如区分 Xilinx 或 Altera/Intel 目标?

您可以使用 generate 语句和特定于供应商的实体 + 体系结构。 PoC-Library makes heavily use of this technique to create vendor independent IP cores.

例如看一下 PoC 的 On-Chip-Memory (ocram) 抽象层:PoC.mem.ocram.tdp

gAltera: if not SIMULATION and (VENDOR = VENDOR_ALTERA) generate
    component ocram_tdp_altera
        generic (
            A_BITS      : positive;
            D_BITS      : positive;
            FILENAME    : string        := ""
        );
        port (
            clk1 : in   std_logic;
            clk2 : in   std_logic;
            ce1 : in    std_logic;
            ce2 : in    std_logic;
            we1 : in    std_logic;
            we2 : in    std_logic;
            a1   : in   unsigned(A_BITS-1 downto 0);
            a2   : in   unsigned(A_BITS-1 downto 0);
            d1   : in   std_logic_vector(D_BITS-1 downto 0);
            d2   : in   std_logic_vector(D_BITS-1 downto 0);
            q1   : out std_logic_vector(D_BITS-1 downto 0);
            q2   : out std_logic_vector(D_BITS-1 downto 0)
        );
    end component;
begin
    -- Direct instantiation of altsyncram (including component
    -- declaration above) is not sufficient for ModelSim.
    -- That requires also usage of altera_mf library.

    ram_altera: ocram_tdp_altera
        generic map (
            A_BITS      => A_BITS,
            D_BITS      => D_BITS,
            FILENAME    => FILENAME
        )
        port map (
            clk1    => clk1,
            clk2    => clk2,
            ce1     => ce1,
            ce2     => ce2,
            we1     => we1,
            we2     => we2,
            a1      => a1,
            a2      => a2,
            d1      => d1,
            d2      => d2,
            q1      => q1,
            q2      => q2
        );
end generate gAltera;

在这里,它为 Altera 器件实例化了一个特殊的实体。对于其他设备(Xilinx、Lattice),使用通用 VHDL 实现。此外,一个特殊的模型用于模拟,因为供应商原语不模拟 FPGA 设备文档(例如内存指南)中记录的实际行为。