--2 bit multiplication
function mult2( a : std_logic_vector(1 downto 0) ; b : std_logic_vector(1 downto 0) ) return std_logic_vector is
variable a1,b1 : std_logic_vector(1 downto 0):=(others => '0');
variable c1 : std_logic_vector(3 downto 0):=(others => '0');
begin
a1 := a;
b1 := b;
c1(0) := a1(0) and b1(0);
c1(1) := (a1(1) and b1(0)) xor (a1(0) and b1(1));
c1(2) := ((a1(1) and b1(0)) and (a1(0) and b1(1))) xor (a1(1) and b1(1));
c1(3) := ((a1(1) and b1(0)) and (a1(0) and b1(1))) and (a1(1) and b1(1));
return c1;
end mult2;
--4 bit multiplication
function mult4( a : std_logic_vector(3 downto 0) ; b : std_logic_vector(3 downto 0) ) return std_logic_vector is
variable a1,b1 : std_logic_vector(3 downto 0):=(others => '0');
variable c1,c2,c3,c4,c5 : std_logic_vector(7 downto 0):=(others => '0');
begin
a1 := a;
b1 := b;
c2(7 downto 4) := mult2(a1(3 downto 2),b1(3 downto 2));
c3(3 downto 0) := mult2(a1(1 downto 0),b1(1 downto 0));
c4(5 downto 2) := mult2(a1(3 downto 2),b1(1 downto 0));
c5(5 downto 2) := mult2(a1(1 downto 0),b1(3 downto 2));
c1 := c2+c3+c4+c5;
return c1;
end mult4;