gpt4 book ai didi

encryption - if 中的 VHDL 条件必须是静态的,并且 if 语句中的组件实例化

转载 作者:行者123 更新时间:2023-12-04 21:56:10 25 4
gpt4 key购买 nike

我正在实现一个由 8 轮组成的分组密码(SQUARE)(见下文)。密码必须允许两种操作模式:加密和解密(在代码中表示为 mode = 0mode = 1)。

entity SQUARE is
Port ( mode : in STD_LOGIC;
squarein : in STD_LOGIC_VECTOR (127 downto 0);
key : in STD_LOGIC_VECTOR (127 downto 0);
squareout : out STD_LOGIC_VECTOR (127 downto 0)
);
end SQUARE;

enc : if (mode = '0') generate -- do encryption
s0 : preround port map(squarein, key, con0, key1, rin1);
s1 : round port map(rin1, key1, con1, key2, rin2);
s2 : round port map(rin2, key2, con2, key3, rin3);
s3 : round port map(rin3, key3, con3, key4, rin4);
s4 : round port map(rin4, key4, con4, key5, rin5);
s5 : round port map(rin5, key5, con5, key6, rin6);
s6 : round port map(rin6, key6, con6, key7, rin7);
s7 : round port map(rin7, key7, con7, key8, rin8);
s8 : lastround port map(rin8, key8, squareout);
end generate;

dec : if (mode = '1') generate -- do decryption
i8 : invround port map(squarein, key8, con7, invkey7, invrin7);
i7 : invround port map(invrin7, invkey7, con6, invkey6, invrin6);
i6 : invround port map(invrin6, invkey6, con5, invkey5, invrin5);
i5 : invround port map(invrin5, invkey5, con4, invkey4, invrin4);
i4 : invround port map(invrin4, invkey4, con3, invkey3, invrin3);
i3 : invround port map(invrin3, invkey3, con2, invkey2, invrin2);
i2 : invround port map(invrin2, invkey2, con1, invkey1, invrin1);
i1 : invround port map(invrin1, invkey1, con0, invkey0, invrin0);
i0 : invpreround port map(invrin0, invkey0, squareout);
end generate;

问题:编译成功但有警告(IF GENERATE 中的条件必须是静态的)。我怎么能避免这个警告?也许以其他方式重写代码..

最佳答案

正如 Paebbels 所说,generate不能动态使用。它需要在编译/合成时保持不变。您可以做的是改用泛型(使用 VHDL-2008 if-else 生成构造):

entity SQUARE is
generic(mode : std_logic);
Port ( squarein : in STD_LOGIC_VECTOR (127 downto 0);
key : in STD_LOGIC_VECTOR (127 downto 0);
squareout : out STD_LOGIC_VECTOR (127 downto 0)
);
end entity;

architecture structural or SQUARE is
begin
enc : if (mode = '0') generate -- do encryption
s0 : entity work.preround port map(squarein, key, con0, key1, rin1);
[...]
else generate
-- decrypt
i8 : entity work.invround port map(squarein, key8, con7, invkey7, invrin7);
[...]
end generate;
end architecture;

如果要动态更改操作模式,则需要生成所有组件,并使用多路复用器选择输出:
entity SQUARE is
Port ( mode : in std_logic;
squarein : in STD_LOGIC_VECTOR (127 downto 0);
key : in STD_LOGIC_VECTOR (127 downto 0);
squareout : out STD_LOGIC_VECTOR (127 downto 0)
);
end entity;

architecture structural or SQUARE is
begin
-- encrypt components
s0 : entity work.preround port map(squarein, key, con0, key1, rin1);
[...]
s8 : entity work.lastround port map(rin8, key8, squareout_enc);
-- decrypt components
i8 : entity work.invround port map(squarein, key8, con7, invkey7, invrin7);
[...]
i0 : entity work.invpreround port map(invrin0, invkey0, squareout_dec);
-- connect outputs
squareout <= squareout_enc when mode='0' else squareout_dec;
end architecture;

关于encryption - if 中的 VHDL 条件必须是静态的,并且 if 语句中的组件实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48060264/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com