library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity booths is
GENERIC(k : POSITIVE := 7); --input number word length less one
Port ( a,b : in STD_LOGIC_VECTOR (k downto 0);
mul : out STD_LOGIC_VECTOR (2*k+1 downto 0));
end booths;
architecture Behavioral of booths is
begin
process(a,b)
variable m: std_logic_vector (2*k+1 downto 0);
variable s: std_logic;
begin
m:="00000000"&b;
s:='0';
for i in 0 to k loop
if(m(0)='0' and s='1') then
m(k downto k-3):= m(k downto k-3)+a;
s:=m(0);
m(k-1 downto 0):=m(k downto 1);
elsif(m(0)='1' and s='0') then
m(k downto k-3):= m(k downto k-3)-a;
s:=m(0);
m(k-1 downto 0):=m(k downto 1);
else
s:=m(0);
m(k-1 downto 0):=m(k downto 1);
end if;
end loop;
mul<=m;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Testbench_di_Booth is
end Testbench_di_Booth;
architecture behavior of Testbench_di_Booth is
component booths
GENERIC(k : POSITIVE := 7); --input number word length less one
Port( a,b : in STD_LOGIC_VECTOR (k downto 0);
mul : out STD_LOGIC_VECTOR (2*k+1 downto 0));
end component;
--Inputs
signal A : STD_LOGIC_VECTOR (7 downto 0):= "00000011";
signal B : STD_LOGIC_VECTOR (7 downto 0):= "00000100";
--Outputs
signal MUL : STD_LOGIC_VECTOR(15 downto 0);
begin
--Instantiate the UnitUnder Test (UUT)
uut: booths PORT MAP
(a => A,
b => B,
mul => MUL);
--Stimulus process
stim_proc: process
begin
--insert stimulus here
A<="00000011"; B<="00000100"; wait for 500 fs;
A<="00000110"; B<="00000111"; wait for 500 fs;
A<="00001011"; B<="00000100"; wait for 500 fs;
wait;
end process;
end;
X= 01001111 (79) Y=010100110 P=0000000000000000 (0)
C=10: P=P-X=(0)-(79)=-79 ; Lshift X ; Rshift Y
X= 010011110 (158) Y= 01010011 P=1111111110110001 (-79)
C=11: Lshift X ; Rshift Y
X= 0100111100 (316) Y= 0101001 P=1111111110110001 (-79)
C=01: P=P+X=(-79)+(316)=237 ; Lshift X ; Rshift Y
X= 01001111000 (632) Y= 010100 P=0000000011101101 (237)
C=00: Lshift X ; Rshift Y
X= 010011110000 (1264) Y= 01010 P=0000000011101101 (237)
C=10: P=P-X=(237)-(1264)=-1027 ; Lshift X ; Rshift Y
X= 0100111100000 (2528) Y= 0101 P=1111101111111101 (-1027)
C=01: P=P+X=(-1027)+(2528)=1501 ; Lshift X ; Rshift Y
X= 01001111000000 (5056) Y= 010 P=0000010111011101 (1501)
C=10: P=P-X=(1501)-(5056)=-3555 ; Lshift X ; Rshift Y
X= 010011110000000 (10112) Y= 01 P=1111001000011101 (-3555)
C=01: P=P+X=(-3555)+(10112)=6557 ; Lshift X ; Rshift Y
il risultato finale è = 6557
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Booth4 is
port(A, B: in std_logic_vector(3 downto 0);
O: out std_logic_vector(7 downto 0));
end Booth4;
architecture boothMult4Arch of Booth4 is
begin
process(A, B)
variable num: std_logic_vector(8 downto 0);
variable Y, Z: unsigned(3 downto 0);
variable i:integer;
begin
num := "000000000";
Y := unsigned(B);
num(4 downto 1) := A;
for i in 0 to 3 loop
if(num(1) = '1' and num(0) = '0') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z - Y);
elsif(num(1) = '0' and num(0) = '1') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z + Y);
end if;
num(7 downto 0) := num(8 downto 1);
end loop;
O(7 downto 0) <= num(8 downto 1);
end process;
end boothMult4Arch;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity Booth4 is
port(A, B: in std_logic_vector(3 downto 0);
O: out std_logic_vector(7 downto 0));
end Booth4;
architecture boothMult4Arch of Booth4 is
begin
process(A, B)
variable num: std_logic_vector(8 downto 0);
variable Y, Z: unsigned(3 downto 0);
variable i:integer;
begin
num := "000000000";
Y := unsigned(B);
num(4 downto 1) := A;
for i in 0 to 3 loop
if(num(1) = '1' and num(0) = '0') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z - Y);
elsif(num(1) = '0' and num(0) = '1') then
Z := unsigned(num(8 downto 5));
num(8 downto 5) := std_logic_vector(Z + Y);
end if;
num(7 downto 0) := num(8 downto 1);
end loop;
O(7 downto 0) <= num(8 downto 1);
end process;
end boothMult4Arch;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Testbench_di_Booth is
end Testbench_di_Booth;
architecture behavior of Testbench_di_Booth is
component Booth4
Port(A, B: in std_logic_vector(3 downto 0);
O: out std_logic_vector(7 downto 0));
end component;
--Inputs
signal a : STD_LOGIC_VECTOR (3 downto 0):= "0011";
signal b : STD_LOGIC_VECTOR (3 downto 0):= "0100";
--Outputs
signal o : STD_LOGIC_VECTOR(7 downto 0);
begin
--Instantiate the UnitUnder Test (UUT)
uut: Booth4 PORT MAP
(A => a,
B => b,
O => o);
--Stimulus process
stim_proc: process
begin
--hold reset state for100ms.
wait for 1 ps;
--insert stimulus here
a<="0011"; b<="0100"; wait for 500 fs;
a<="0110"; b<="0111"; wait for 500 fs;
a<="1011"; b<="0100"; wait for 500 fs;
wait;
end process;
end;
-------------------------------------
-- Define data width
--
-------------------------------------
package mypackage is
constant NBITS :natural := 7;
constant MBITS :natural := 9;
end mypackage;
---------------------------------------------------------
-- Booth-1 multiplier
--
----------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
use work.mypackage.all;
entity booth_1 is
port (
X: in STD_LOGIC_VECTOR (NBITS-1 downto 0);
Y: in STD_LOGIC_VECTOR (MBITS-1 downto 0);
P: out STD_LOGIC_VECTOR (NBITS+MBITS-1 downto 0)
);
end booth_1;
architecture simple_arch of booth_1 is
component booth_1_cell
Port ( P : in std_logic_vector(MBITS-1 downto 0);
Y : in std_logic_vector(MBITS-1 downto 0);
x_i : in std_logic_vector(1 downto 0);
S : out std_logic_vector(MBITS downto 0)
);
end component;
type conections is array (0 to NBITS) of STD_LOGIC_VECTOR (MBITS downto 0);
Signal wires: conections;
Signal eX: STD_LOGIC_VECTOR (NBITS downto 0);
begin
eX(NBITS downto 1) <= X; eX(0) <= '0';
wires(0) <= (others => '0');
iterac: for I in 0 to NBITS-1 generate
mult: booth_1_cell port map (P => wires(i)(MBITS downto 1),
Y => Y, x_i => eX(i+1 downto i), S => wires(i+1) );
p(i) <= wires(i+1)(0);
end generate;
p(MBITS+NBITS-1 downto NBITS) <= wires(NBITS)(MBITS downto 1);
end simple_arch;
--
-- booth-1 cell: basic cell for booth 1 multiplier
--
----------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use work.mypackage.all;
entity booth_1_cell is
Port ( P : in std_logic_vector(MBITS-1 downto 0);
Y : in std_logic_vector(MBITS-1 downto 0);
x_i : in std_logic_vector(1 downto 0);
S : out std_logic_vector(MBITS downto 0)
);
end booth_1_cell;
architecture Behavioral of booth_1_cell is
signal sS : std_logic_vector(MBITS-1 downto 0);
begin
the_mux: process(x_i,P, Y)
begin
case x_i is
when "00" => S <= (P(MBITS-1) & P);
when "01" => S <= (P(MBITS-1) & P) + (Y(MBITS-1) & Y);
when "10" => S <= (P(MBITS-1) & P) - (Y(MBITS-1) & Y);
when "11" => S <= (P(MBITS-1) & P);
when others => NULL;
end case;
end process;
end Behavioral;
-- VHDL Test Bench for booth-1 multiplier
--
-- Notes:
----------------------------------------------------------------------
LIBRARY IEEE;
USE IEEE.std_logic_1164.all;
USE IEEE.std_logic_arith.all;
USE IEEE.std_logic_signed.all;
USE work.mypackage.all;
ENTITY test_exhaustive IS
END test_exhaustive;
ARCHITECTURE behavioural OF test_exhaustive IS
COMPONENT booth_1
PORT(
X : IN std_logic_vector(NBITS-1 downto 0);
Y : IN std_logic_vector(MBITS-1 downto 0);
P : OUT std_logic_vector(MBITS+NBITS-1 downto 0)
);
END COMPONENT;
--Inputs
SIGNAL x : std_logic_vector(NBITS-1 downto 0);
SIGNAL y : std_logic_vector(MBITS-1 downto 0);
--Outputs
SIGNAL p : std_logic_vector(MBITS+NBITS-1 downto 0);
BEGIN
--Instantiate the UnitUnder Test (UUT)
uut: booth_1 PORT MAP(X => x, Y => y, P => p);
--Stimulus process
stim_proc: process
begin
--hold reset state for100ms.
wait for 1 ns;
--insert stimulus here
x<="0000011"; y<="000000100"; wait for 50 ns;
x<="0000110"; y<="000000111"; wait for 50 ns;
x<="0001011"; y<="000000100"; wait for 50 ns;
wait;
end process;
END;
Users browsing this forum: No registered users and 1 guest