在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1385|回复: 0

[其它] PIPE LINED MATRIX MULTIPLICATION

[复制链接]
发表于 2014-2-5 21:36:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
Code : in Vhdllibrary IEEE;use IEEE.std_logic_1164.all;use IEEE.std_logic_arith.all;entity mult is        port (  Clk : in STD_LOGIC;              Start : in STD_LOGIC;               Done : out STD_LOGIC;               Dout : out INTEGER);end mult;architecture sequential of mult is        signal        Count0, Count1         : UNSIGNED (8 downto 0):="000000000";        signal        Count2, Count3         : UNSIGNED (8 downto 0):="000000000";        signal        A, B, P, Sum        : INTEGER;begin   process(Clk)        type STATE_VALUE is (S0, S1, S2, S3, S4, S5, S6, S7, S8);        type RF is array (0 to 7, 0 to 7) of INTEGER;        variable         i0, j0, k0, k2         : INTEGER;        variable         i3, j3, k3          : INTEGER;        variable         State                 : STATE_VALUE := S0;        ----------------------------------------        -- some random numbers for the A matrix        ----------------------------------------        variable A_Matrix         : RF := (                 (1, 1, 2, 3, 4, 5, 6, 7),                (8, 9, 0, 1, 2, 3, 4, 5),                (6, 7, 8, 9, 1, 3, 4, 5),                (4, 1, 2, 3, 4, 5, 6, 7),                (8, 9, 0, 1, 2, 3, 4, 5),                (6, 7, 8, 9, 1, 3, 4, 5),                (7, 1, 2, 3, 4, 5, 6, 7),                (8, 9, 0, 1, 2, 3, 4, 5));        ----------------------------------------        -- some random numbers for the B matrix        ----------------------------------------        variable B_Matrix       : RF := (                (6, 7, 8, 9, 1, 3, 4, 9),                (0, 1, 2, 3, 4, 5, 6, 7),                (8, 9, 0, 1, 2, 3, 4, 8),                (0, 1, 2, 3, 4, 5, 6, 7),                (6, 7, 8, 9, 1, 3, 4, 5),                (8, 9, 0, 1, 2, 3, 4, 5),                (8, 9, 0, 1, 2, 3, 4, 5),                (0, 1, 2, 3, 4, 5, 6, 7));        variable C_Matrix      : RF;        begin        if (Clk'event and Clk = '1') then                i0 := CONV_INTEGER( Count0( 8 downto 6 ) );                j0 := CONV_INTEGER( Count0( 5 downto 3 ) );                k0 := CONV_INTEGER( Count0( 2 downto 0 ) );                k2 := CONV_INTEGER( Count2( 2 downto 0 ) );                i3 := CONV_INTEGER( Count3( 8 downto 6 ) );                j3 := CONV_INTEGER( Count3( 5 downto 3 ) );                k3 := CONV_INTEGER( Count3( 2 downto 0 ) );                case State is                ------------------------------------------                --        State S0 (wait for start signal)                ------------------------------------------                when S0 =>                        Done <= '0';                        Count0 <= "000000000";                        if( Start = '1' ) then                                State := S1;                        else                                State := S0;                        end if;                -------------------------------------------                --        State S1 (filling up of pipeline)                -------------------------------------------                when S1 =>                        A <= A_Matrix(i0, k0);                          B <= B_Matrix(k0, j0);                        Count1 <= Count0;                        Count0 <= Count0 + 1;                        State := S2;                ---------------------------------------                --        State S2 (more of filling up)                ---------------------------------------                when S2 =>                        A <= A_Matrix(i0, k0);                          B <= B_Matrix(k0, j0);                        P <= A * B;                        Count2 <= Count1;                        Count1 <= Count0;                        Count0 <= Count0 + 1;                        State := S3;                -------------------------------------------                --        State S3 (even more of filling up)                -------------------------------------------                when S3 =>                        A <= A_Matrix(i0, k0);                          B <= B_Matrix(k0, j0);                        P <= A * B;                                                if (k2 = 0) then                                Sum <= P;                        else                                Sum <= Sum + P;                        end if;                        Count3 <= Count2;                        Count2 <= Count1;                        Count1 <= Count0;                        Count0 <= Count0 + 1;                        State := S4;                -------------------------------------------------                --        State S4 (pipeline full, complete work)                -------------------------------------------------                when S4 =>                        A <= A_Matrix(i0, k0);                          B <= B_Matrix(k0, j0);                        P <= A * B;                        if (k2 = 0) then                                Sum <= P;                        else                                Sum <= Sum + P;                        end if;                        if (k3 = 7) then                                C_Matrix(i3, j3) := Sum;                        end if;                        Count3 <= Count2;                        Count2 <= Count1;                        Count1 <= Count0;                        ----------------------------------                        -- check if all initiations done                        ----------------------------------                        if (Count0 = 511) then                                State := S5;                        else                                State := S4;                                Count0 <= Count0 + 1;                        end if;                ------------------------------------------------                --        State S5 (start flushing the pipeline)                ------------------------------------------------                when S5 =>                        P <= A * B;                        if (k2 = 0) then                                Sum <= P;                        else                                Sum <= Sum + P;                        end if;                        if (k3 = 7) then                                C_Matrix(i3, j3) := Sum;                        end if;                        Count3 <= Count2;                        Count2 <= Count1;                        State := S6;                -------------------------------------                --        State S6 (more of flushing)                -------------------------------------                when S6 =>                        if (k2 = 0) then                                Sum <= P;                        else                                Sum <= Sum + P;                        end if;                        if (k3 = 7) then                                C_Matrix(i3, j3) := Sum;                        end if;                        Count3 <= Count2;                        State := S7;                -------------------------------------------                --        State S7 (completion of flushing)                -------------------------------------------                when S7 =>                        if (k3 = 7) then                                C_Matrix(i3, j3) := Sum;                        end if;                        State := S8;                        Count0 <= "000000000";                                Done <= '1';                ------------------------------------                --        State S8 (output the data)                ------------------------------------                when S8 =>                        if( Count0 = 63 ) then                                Count0 <= "000000000";                                State := S0;                        else                                Count0 <= Count0 + 1;                                State := S8;                        end if;                        Dout <=  C_Matrix( j0, k0 );                end case;        end if;   end process;end sequential;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条

×

小黑屋| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-5-1 05:17 , Processed in 0.023838 second(s), 8 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表