基于LUT4组件的LUT5组件的结构描述

时间:2017-03-25 21:52:46

标签: vhdl

请告诉我如何在LUT4组件的基础上正确描述LUT5的结构组件,问题恰恰在于端口的正确映射。

 //alien contacting the torpedo
if contact.bodyA.categoryBitMask == ColliderType.object.rawValue && contact.bodyB.categoryBitMask == ColliderType.torp.rawValue{
   //then do the following
   }
 //alien contacting the ship
if contact.bodyA.categoryBitMask == ColliderType.object.rawValue && contact.bodyB.categoryBitMask == ColliderType.ship.rawValue{
       //then do the following
       }

1 个答案:

答案 0 :(得分:1)

您可以使用两个四输入查找表来表示一个五输入查找表,其中一个选择器根据第五位选择输出:

library ieee;
use ieee.std_logic_1164.all;

entity lut5 is
    generic (
        LUTVAL: std_logic_vector (0 to 31)
    );
    port (
      a, b, c, d, e:    in  std_logic;
      z :               out std_logic
    );
end entity  lut5;

architecture behaviour of lut5 is
    component mux2 is
        port (
            a:  in  std_logic;
            b:  in  std_logic;
            s:  in  std_logic;
            y:  out std_logic
        );
    end component;
    component lut4 is
        generic (
            LUTVAL:  std_logic_vector (0 to 15)
        );
        port (
          a, b, c, d:   in  std_logic;
          z:            out std_logic
         );
    end component;
    signal z0, z1:      std_logic;
begin
LUT4_0:
    lut4
        generic map (
            LUTVAL => LUTVAL(0 to 15)
        )
        port map (
            a => a,
            b => b,
            c => c,
            d => d,
            z => z0
        );
LUT4_1:
    lut4
        generic map (
            LUTVAL => LUTVAL(16 to 31)
        )
        port map (
            a => a,
            b => b,
            c => c,
            d => d,
            z => z1
        );   
MUX_2_1:
    mux2
        port map (
            a => z0,
            b => z1,
            s => e,
            y => z
        );
end architecture;

泛型是一种从设计模型的顶层提供查找表内容的方法。

添加一个小测试平台:

library ieee;
use ieee.std_logic_1164.all;

entity lut5_tb is
end entity;

architecture foo of lut5_tb is
    signal a, b, c, d, e:   std_logic := '0';
    signal z:               std_logic;
    constant LUTVAL:        std_logic_vector (0 to 31) := x"A2201000";
    signal index:           natural;
begin
DUT:
    entity work.lut5
    generic map (
        LUTVAL => LUTVAL
    )
    port map (
        a => a,
        b => b,
        c => c,
        d => d,
        e => e,
        z => z
    );
STIMULI:
    process
        use ieee.numeric_std.all;
    begin
        for i in LUTVAL'RANGE loop
            (e, d, c, b, a) <= to_unsigned(i,5);
            index <= i;
            wait for 10 ns;
        end loop;
        wait;
    end process;
end architecture;

我们可以看到它作为五输入查找表执行:

lut5_tb.png

您可以使用添加的索引信号计算z输出中的位数,并找到输出重建32位LUTVAL(x&#34; A2201000&#34;)。

这里缺少了点点滴滴:

library ieee;
use ieee.std_logic_1164.all;

entity mux2 is
    port (
        a:  in  std_logic;
        b:  in  std_logic;
        s:  in  std_logic;
        y:  out std_logic
    );
end entity;

architecture foo of mux2 is
begin
    y <= a when s = '0' else
         b;
end architecture;

library ieee;
use ieee.std_logic_1164.all;

entity lut4 is
    generic (
        LUTVAL:  std_logic_vector (0 to 15)
    );
    port (
      a, b, c, d:   in  std_logic;
      z:            out std_logic
     );
end entity;

architecture foo of lut4 is
    constant lut:   std_logic_vector := LUTVAL;
    use ieee.numeric_std.all;
begin
LOOKUP:
    z <= lut(to_integer(unsigned'(d,c,b,a)));
end architecture;