wk_sbs_hdl/hw/rtl/two_mult_unsgn_pp_trunc.vhd

86 lines
2.9 KiB
VHDL

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity two_mult_unsgn_pp_trunc is
generic (
BWa : natural := 16; -- Bit width of Multiplier
BWb : natural := 16;
K : natural := 15); -- Vertical truncation
port (
da : in std_logic_vector(BWa-1 downto 0);
db : in std_logic_vector(BWb-1 downto 0);
dc : in std_logic_vector(BWa-1 downto 0);
dd : in std_logic_vector(BWb-1 downto 0);
dout : out std_logic_vector(BWa+BWb downto 0));
end two_mult_unsgn_pp_trunc;
architecture str of two_mult_unsgn_pp_trunc is
type stlv_array is array (0 to 2*BWa-1) of std_logic_vector(BWa+BWb-2 downto 0);
signal pp : stlv_array;
--signal pp_res : std_logic_vector(BWa+BWb downto 0);
begin -- str
ppGen1 : process (da, db)
variable ppt : stlv_array;
begin
ppt := (others => (others => '0'));
-- partial products da(i)db(j) EX:
-- da(0)db(3) da(0)db(2) da(0)db(1) da(0)db(0)
-- da(1)db(3) da(1)db(2) da(1)db(1) da(1)db(0)
-- da(2)db(3) da(2)db(2) da(2)db(1) da(2)db(0)
-- da(3)db(3) da(3)db(2) da(3)db(1) da(3)db(0)
for i in 0 to BWa-1 loop
for j in 0 to BWb-1 loop
if (i+j > K-1) then
ppt(i)(i+j) := da(i) and db(j);
end if;
end loop;
end loop;
PP(0 to BWa-1) <= ppt(0 to BWa-1);
end process ppGen1;
ppGen2 : process (dc, dd)
variable ppt : stlv_array;
begin
ppt := (others => (others => '0'));
-- partial products dc(i)dd(j) EX:
-- dc(0)dd(3) dc(0)dd(2) dc(0)dd(1) dc(0)dd(0)
-- dc(1)dd(3) dc(1)dd(2) dc(1)dd(1) dc(1)dd(0)
-- dc(2)dd(3) dc(2)dd(2) dc(2)dd(1) dc(2)dd(0)
-- dc(3)dd(3) dc(3)dd(2) dc(3)dd(1) dc(3)dd(0)
for i in 0 to BWa-1 loop
for j in 0 to BWb-1 loop
if (i+j > K-1) then
ppt(i)(i+j) := dc(i) and dd(j);
end if;
end loop;
end loop;
PP(BWa to 2*BWa-1) <= ppt(0 to BWa-1);
end process ppGen2;
CSA_tree : process (pp)
variable pp_add : std_logic_vector(BWa+BWb downto 0);
begin -- process CSA_tree
for i in 0 to 2*BWa-1 loop
if i = 0 then
pp_add := "00" & pp(0)(BWa+BWb-2 downto 0);
else
pp_add := std_logic_vector(unsigned(pp(i)(BWa+BWb-2 downto 0)) + unsigned(pp_add));
end if;
end loop; -- i
--pp_res <= pp_add;
dout <= pp_add;
end process CSA_tree;
-- dout <= pp_res;
--dout(BWa+BWb downto 16) <= pp_res(BWa+BWb-1 downto 16);
--dout(15 downto 0) <= (others => '0');
end str;