8-By-8 Bit Multiply Accumulator Jean Jewry Ramos
8-By-8 Bit Multiply Accumulator Jean Jewry Ramos
ID : 5037220
1
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
Table of Contents
1 INTRODUCTION………………………………………………………………………4
2 GENERAL REQUIREMENTS……………………………………………………….. 5
3 DESIGN SPECIFICATIONS…………………………………………………………. 6
3.1 CONTROLLER DESIGN…………………………………………………………………………………... 6
3.1.1 Design……………………….……………………………………………………………..………...7
3.1.2 Simulation and Timing…….……………………………………………………………………….8
3.2 MULTIPLIER BLOCK DESIGN.…….…………….………………………………………………………..8
3.2.1 Design………………………………………………………………………………………………...8
3.2.2 Simulation and Timing……………………….…………………………………………………….9
3.3 INPUT REGISTER BLOCK DESIGN.……………………………………….……………………………...10
3.4 ADD ACCUMULATOR BLOCK DESIGN………………..…………………...……………………………10
3.4.1 Design………………………………………………………………………………………………..10
3.4.2 Simulation and Timing…………………………………………………………………….………11
3.5 ADDER DESIGN.…………………………………………………………………….…………………….12
3.5.1 Design…………………………………………………………………………………….………….12
3.5.2 Simulation and Timing……………………………………………………………………..……...13
3.6 MULTIPLIER ACCUMULATOR DESIGN.………….…. …………………………………………………13
3.6.1 Design…………………………………………………………………………………….………….13
3.6.2 Test Bench…………………………………………………………………………………………..13
3.6.3 Simulation and Timing……………………………………………………………………………..14
4 CONCLUSION…………………………………………………………………………15
2
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
List of Figures
3
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
1 INTRODUCTION
This project describes a design methodology of an 8-by-8 unsigned multiplier accumulator. At the highest
abstraction level, the project starts with the conception of functional blocks to accommodate multiplication,
addition and accumulation of data as a general requirement. Based upon design specifications, a detailed
Design Block Diagram is constructed; at this level, the block diagram contains major blocks, connections
between blocks and signal flow direction.
Principles of design strategies such as hierarchy, regularity, modularity and locality coupled with
constraints of area, speed and power dissipation are considered. These considerations further determine
detail implementations of each functional block. Each functional block would be designed, tested and
simulated.
The design would be modeled and coded in VHDL and simulated for proper functionality and timing. The
simulation results, design diagrams and VHDL codes would be included.
4
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
2 GENERAL REQUIREMENTS
The requirement is to design a Multiplier-Accumulator circuit. 10 pairs of operands have to be multiplied
and added.
The MAC receives operands Ai and Bi, each an 8 bit unsigned binary number. The output results C, is the
summation of these results. Each pair of operand A & B are loaded in parallel in the RA & RB registers
the beginning of each multiplication cycle. Each multiplication cycle starts with a BEGIN signal and ends
with an END signal. The result of each multiplication is added to the previously accumulated data in the
RC register. The start of each multiply-accumulate cycle is indicated with a START signal.
5
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
3 DESIGN SPECIFICATIONS
The MAC would be designed for high speed and good regularity. To improve speed operation with good
regularity, a Carry Select Adder would be used in all addition processes. An 8-by-8-bit Shift/Add
multiplier designed by Giovanni D’Aliesio would be used with a slight modification of addition operation
to improve speed. The process of addition and accumulation are integrated into an add-accumulate unit.
A detailed block diagram is shown in Figure 3-1.
The LOAD_cmd output signal commands Register A and Register B to load operands. The begin output
signal commands the multiplier to begin multiplication operation. The ADD_cmd output signal commands
the add-accumulator unit to add and accumulate result of multiplication. The FINISH_cmd output signal is
used for a test purpose only telling stimuli of testbench to send a next pair of operands. It also indicates that
each multiply-accumulate cycle is done.
6
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
3.1.1 Design
A finite state machine (FSM) of the controller is shown in Figure 3-2. An active START signal transitions
the state from IDLE state to INITIALIZATION state; at initialization state, a RESET command is generated
to reset all the functional units and the registers. After one clock cycle, the FSM goes to LOAD state
whereby it commands the input registers to load a pair of operands. Then the FSM goes to RUN state to
start multiplication process. After one clock cycle, the FSM goes to TEST state, and it waits for the
multiplier unit to complete its multiplication process.
Once complete, the FSM receives an active END_MULT signal from the multiplier unit, and it transitions
to ADD state. At the ADD state, the controller commands the add-accumulator unit to add and accumulate
result of multiplication. It also decrements an counter which keeps track the number of pair of operands
being cycled; there are 10 pair of operands to be cycled. If the number of pair of operands is not equal to
10, then the FSM goes to LOAD state to load the next pair of operands, else it goes to IDLE state waiting
for the next 10 pairs of operands.
7
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
Once the operands loaded into the multiplier, the controller commands the multiplier to begin
multiplication process by activating BEGIN_MULT_cmd signal. When the multiplier unit completes its
tasks, it generates a multiplication complete (END_MULT) signal to the controller. The simulation
indicates that when the controller receives the END_MULT signal, the controller commands the add-
accumulator unit to add and accumulate the multiplication result. The simulation also shows that the state
changes back to IDLE state when a reset signal is applied to the controller.
The Multiplier block is an 8-by-8-bit Shift/Add multiplier designed by Giovanni D’Aliesio with a
modification in the addition unit to improve speed. It is composed of a controller, a multiplicand unit, an
adder unit and a multiplier_result unit. The multiplier starts multiplication process when a START signal is
received. It generates a STOP signal when the multiplication process completes and data is ready at output
register (RC).
3.2.1 Design
The Shift/Add multiplier performs multiplication process using shift and add methods. A value of the
multiplicand is added and accumulated based upon the value of multiplier LSB bit. Multiplier is shifted
one bit to the right at each clock cycle, and its LSB value is tested. If the LSB value is 0, then it performs a
shift operation. If the LSB value is 0, then multiplicand is added to the accumulator and is shifted by one
bit to the right.
The multiplicand block is composed of 8 D flip-flop blocks, and it is loaded when the LOAD_cmd signal is
received from the controller. The multiplier/result block stores the accumulated output of the adder and the
8
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
multiplier. It consists of a 17-bit shift register and a multiplexer to perform shift-right operation. The
addition section is replaced with an 8-bit Carry Select Adder to improve speed. The previous adder was a
Carry Propagate Adder. The 8-bit CPA has 8-delay unit of full-adder (FA), but the 8-bit CSA has only 5-
delay unit of full adder (FA). That is an improvement of 37.5% in speed.
9
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
The input registers (register A and register B) are composed of 8 D flip-flop blocks. They load a pair of
operands into the input of multiplier when a LOAD_cmd signal is received from the controller. Figure 3-6
shows the design block diagram of one of the register.
The add-accumulate block performs additions and accumulations processes. It accepts multiplication result
from the multiplier adds the result and accumulates them. It consists of an inverter, two 20-bit registers,
and a 20-bit Carry Select Adder.
3.4.1 Design
The important aspect of the add-accumulate block is its ability to hold the accumulated value. Figure 3-7
shows that the operand fed to the input of the add-accumulator is a 16-bit value, and the output of the add-
accumulate is a 20-bit value.
The storing register is 20 bits wide to hold the maximum accumulated value. The maximum accumulated
value is determined by the number of pair of the operands and the width of the operands. On this project,
the add-accumulator receives 10 pairs of operands and (after multiplication process) each of them generates
a 16-bit wide value. The binary representation of 10 is 1010, so it is a 4-bit value. Since we are adding the
operand ten times, it means that we are basically multiplying the operand by ten. So we are multiplying a
16-bit value and a 4-bit value; the result would be 16+4 = 20 bits of storing register.
To accept a 16-bit value and convert it into a 20-bit value, the inputs of the upper 4 bits of the register are
connected to zeros.
To avoid a race problem between addition and accumulation processes, the two registers are triggered at
different clock edge. This ensures the addition process is completed before the result is being transferred to
the accumulation unit and fed back to input of the adder. An inverter is used for this technique.
10
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
The timing diagram for the Add_Accumulator simulation is shown in Figure 3-8. For this simulation, the
input operand (operand_in) is fed with a value of 2 when it receives a command to add (add_cmd). The
simulation shows that the add_accumulator accepts the value, adds it with previous value and store the new
value at RC. The accumulator (RC) gets the new value on the negative edge of the clock because on the
rising edge of the clock, the addition process takes place.
11
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
3.5.1 Design
A carry-select adder has some 4-bit Ripple Carry Adders (Figure 3-9) and some multiplexers. A carry-
select adder can be divided into section of 4 bits (linear expansion), or it can be apportioned non-linearly to
maximize speed. For this project, a linear expansion carry-select adder is selected for better regularity.
Figure 3-10 displays the block diagram of a 20-Bit Carry-Select adder implemented for this project.
A regular 20-bit Carry Ripple Adder would have a delay of 20 ϑFull-Adder, a 20-bit carry-select adder
would require only 6ϑ Full-Adder. That is an improvement of 70% in speed with a penalty in the size of
area.
12
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
3.6.1 Design
A complete Multiplier Accumulator consists of components described in the previous sections.
The associated VHDL source code is included in Appendix A: VHDL Source Code.
3.6.2 Testbench
Testbench provides inputs to the design unit and monitors any outputs. Figure 3-12 shows a structure of a
testbench and its design under test (D.U.T). All Testbench source code is included in Appendix B.
13
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
14
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
4 CONCLUSION
A complete design of an 8-by-8 unsigned Multiplier Accumulator was presented. The project aimed to
design a high speed MAC with good regularity; this was achieved by using Carry Select Adders on all
addition process. An Add/Shift Multiplier is selected because it generates a signal when it completes its
multiplication process; this feature is one of the design requirements. A complete design analysis of the
add/shift multiplier can be found on a paper written by Giovanni D’Aliesio. A 20-Bit Add Accumulator
was selected to handle maximum accumulated value for ten pairs of 8-bit operands.
All components were modeled with VHDL at structural level and RTL level. The VHDL source codes
were written and simulated on various UNIX-based and windows-based CAD tools such as ModelSim EE
5.4d and Synopsys VHDL System Simulator. More projects could be done to explore and extend the
power of MAC by accepting floating-point numbers, optimizing the control unit and increasing speed by
using Booth-Wallace Tree multiplier.
15
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
CONTROLLER BLOCK
-----------------------------------------------------------------------
-- --------------
-- Purpose : CONTROLLER MAC
-- --------------
-- This file describes a VHDL behavioral model of a controller mac.
-- Controller_mac is a finite state machine that has the following
-- states:
-- IDLE > samples the START signal
-- INIT > commands all registers to be reset
-- LOAD > commands input registers to load operands
-- RUN > executes multiplication operation
-- TEST > checks for end of multiplication process
-- ADD > executes addition accumulation operation
--
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity CONTROLLER_MAC is
port( reset : in std_logic;
clk : in std_logic;
START : in std_logic;
END_MULT : in std_logic;
FINISH_cmd : out std_logic;
RESET_cmd : out std_logic;
LOAD_MULT_cmd : out std_logic;
BEGIN_MULT_cmd: out std_logic;
ADD_cmd : out std_logic
);
end;
begin
-----------------------------------------------------------------------
-- On the following process, when the reset signal activated, the
-- FSM goes to IDLE state and operand pair counter is set to 9. On
-- each leading edge clock transition, state's status is
16
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
-- investigated.
-----------------------------------------------------------------------
process(clk,reset)
begin
if reset = '0' then
state <= IDLE;
temp_count <= "1001";
17
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
else
state <= ADD;
end if;
end case;
end if;
end process;
end RTL;
MULTIPLIER BLOCK
-----------------------------------------------------------------------
-- -------------------------
-- Purpose : EDGE TRIGGER D FLIP-FLOP
-- -------------------------
-- This file describes a VHDL structural model of a D Flip-Flop.
-- This component is part of an 8-bit register.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity DFF is
18
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
port (
reset : in std_logic;
clk : in std_logic;
D : in std_logic;
Q : out std_logic
);
end DFF;
process (clk,reset)
begin
if reset = '0' then
Q <= '0'; -- clear register
elsif (clk'event and clk='1') then
Q <= D; -- load Register
end if;
end process;
end BEHAV;
-----------------------------------------------------------------------
-- --------------
-- Purpose : 8-BIT REGISTER
-- --------------
-- This file describes a VHDL structural model of an 8-bit register
-- This component is part of multiplier block.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity REGISTER8 is
port (
reset : in std_logic;
A_in_reg : in std_logic_vector (7 downto 0);
LOAD_cmd : in std_logic;
RA : out std_logic_vector (7 downto 0)
);
end REGISTER8;
19
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
component DFF
port (
reset : in std_logic;
clk : in std_logic;
D : in std_logic;
Q : out std_logic
);
end component;
begin
end STRUCT;
-----------------------------------------------------------------------
-- -------------------------
-- Purpose : 4-BIT RIPPLE CARRY ADDER
-- -------------------------
-- This file describes a VHDL structural model of a 4-bit Ripple
-- Carry Adder. This component is part of 4-bit Carry Select Adder.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity ripple_carry4 is
port (
e, f : in std_logic_vector(3 downto 0);
carry_in : in std_logic;
S : out std_logic_vector(3 downto 0);
carry_out: out std_logic
);
end ripple_carry4;
20
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
end ARC_ripple_carry4;
-----------------------------------------------------------------------
-- -------------------------
-- Purpose : 4-BIT CARRY SELECT ADDER
-- -------------------------
-- This file describes a VHDL structural model of the 4-bit Carry
-- Select Adder. This component is part of 8-bit Carry Select Adder
-- and 20-bit Carry Select Adder.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity carry_select4 is
port (
c, d : in std_logic_vector(3 downto 0);
C_input : in std_logic;
Result : out std_logic_vector(3 downto 0);
C_output : out std_logic
);
end carry_select4;
component ripple_carry4
port (
e, f : in std_logic_vector(3 downto 0);
21
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
carry_in : in std_logic;
S : out std_logic_vector(3 downto 0);
carry_out: out std_logic
);
end component;
begin
zero<='0';
one<= '1';
end ARC_carry_select4;
-----------------------------------------------------------------------
-- -------------------------
-- Purpose : 8-BIT CARRY SELECT ADDER
-- -------------------------
-- This file describes a VHDL structural model of the 8-bit Carry
-- Select Adder. This component is part of the multiplier block.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity carry_select8 is
port (
A, B : in std_logic_vector(7 downto 0);
C_in : in std_logic;
22
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
component carry_select4
port (
c, d : in std_logic_vector(3 downto 0);
C_input : in std_logic;
Result : out std_logic_vector(3 downto 0);
C_output : out std_logic
);
end component;
begin
end ARC_carry_select8;
-----------------------------------------------------------------------
-- ----------
-- Purpose : CONTROLLER
-- ----------
-- This file describes a VHDL structural model of a controller.
-- This component is part of the 8-by-8-multiplier block.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
23
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entity CONTROLLER is
port (
reset : in std_logic;
clk : in std_logic;
START : in std_logic;
LSB : in std_logic;
ADD_cmd : out std_logic;
SHIFT_cmd : out std_logic;
LOAD_cmd : out std_logic;
STOP : out std_logic
);
end CONTROLLER;
begin
process(clk, reset)
begin
if reset='0' then
state <= IDLE;
temp_count <= "000";
case state is
when IDLE =>
if START = '1' then
state<=INIT;
else
state<=IDLE;
end if;
when INIT =>
state <= TEST;
24
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
else
temp_count <= temp_count + 1;
state <= TEST;
end if;
end case;
end if;
end process;
end RTL;
-----------------------------------------------------------------------
-- ------------
-- Purpose : MULTIPLICAND
-- ------------
-- This file describes a VHDL structural model of Multiplicand
-- Block.
-- This component is part of the 8-by-8-multiplier block.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity MULTIPLICAND is
port (
reset : in std_logic;
A_in : in std_logic_vector (7 downto 0);
LOAD_cmd : in std_logic;
RA : out std_logic_vector (7 downto 0)
);
end MULTIPLICAND;
component DFF
port (
reset : in std_logic;
clk : in std_logic;
D : in std_logic;
25
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
Q : out std_logic
);
end component;
begin
end STRUCT;
-----------------------------------------------------------------------
-- -----------------
-- Purpose : MULTIPLIER_RESULT
-- -----------------
-- This file describes a VHDL structural model of the
-- Multiplier_Result block. This component is part of the 8-by-8-
-- multiplier block.
-- This block performs shifting operation of the multiplication
-- process.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity MULTIPLIER_RESULT is
port (
reset : in std_logic;
clk : in std_logic;
B_in : in std_logic_vector (7 downto 0);
LOAD_cmd : in std_logic;
SHIFT_cmd : in std_logic;
ADD_cmd : in std_logic;
Add_out : in std_logic_vector (7 downto 0);
C_out : in std_logic;
RC_MULT : out std_logic_vector (15 downto 0);
LSB : out std_logic;
RB : out std_logic_vector (7 downto 0)
);
end MULTIPLIER_RESULT;
26
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
begin
else
-- No Add Simply shift 1 bit
temp_register <= '0' & temp_register (16 downto
1);
end if;
end if;
end if;
end process;
RB <= temp_register(15 downto 8);
LSB <= temp_register(0);
RC_MULT <= temp_register(15 downto 0);
end RTL;
27
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity REGISTER8 is
port (
reset : in std_logic;
A_in_reg : in std_logic_vector (7 downto 0);
LOAD_cmd : in std_logic;
RA : out std_logic_vector (7 downto 0)
);
end REGISTER8;
component DFF
port (
reset : in std_logic;
clk : in std_logic;
D : in std_logic;
Q : out std_logic
);
end component;
begin
end STRUCT;
28
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
ADD-ACCUMULATE BLOCK
-----------------------------------------------------------------------
-- ---------------
-- Purpose : 20-BIT REGISTER
-- ---------------
-- This file describes a VHDL structural model of a 20-bit Register.
-- It has asynchronous reset input signal, and it loads data from
-- A_in to RA when a LOAD_cmd signal is triggered.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity REGISTER20 is
port (
reset : in std_logic;
A_in : in std_logic_vector (19 downto 0);
LOAD_cmd : in std_logic;
RA : out std_logic_vector (19 downto 0)
);
end REGISTER20;
component DFF
port (
reset : in std_logic;
clk : in std_logic;
D : in std_logic;
Q : out std_logic
);
end component;
begin
end STRUCT;
29
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
end CFG_REGISTER20;
-----------------------------------------------------------------------
-- -------------------------
-- Purpose : 20-BIT CARRY SELECT ADDER
-- -------------------------
-- This file describes a VHDL structural model of a 20-bit Carry
-- Select Adder.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity carry_select20 is
port (
A, B : in std_logic_vector(19 downto 0);
C_in : in std_logic;
SUM : out std_logic_vector(19 downto 0);
C_out : out std_logic
);
end carry_select20;
component carry_select4
port (
c, d : in std_logic_vector(3 downto 0);
C_input : in std_logic;
Result : out std_logic_vector(3 downto 0);
C_output : out std_logic
);
end component;
begin
30
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
end ARC_carry_select20;
-----------------------------------------------------------------------
-- --------------------
-- Purpose : MULTIPLY ACCUMULATOR
-- --------------------
-- This file describes a VHDL structural model of a MAC.
-- This particular MAC consists of 2 8-Bit Input Registers, an 8-by-
-- 8 Add/Shift Multiplier, a MAC controller and a 20 Bit Add-
-- Accumulator.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity MAC is
port (
OPA_in : in std_logic_vector (7 downto 0);
OPB_in : in std_logic_vector (7 downto 0);
clk : in std_logic;
reset : in std_logic;
START : in std_logic;
FINISH_cmd : out std_logic;
RC : out std_logic_vector(19 downto 0);
C_out : out std_logic;
STOP : out std_logic
);
end MAC;
use work.all;
31
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
component REGISTER8
port (
reset : in std_logic;
A_in_reg : in std_logic_vector (7 downto 0);
LOAD_cmd : in std_logic;
RA : out std_logic_vector (7 downto 0)
);
end component;
component MULTIPLIER
port (
A_in : in std_logic_vector (7 downto 0);
B_in : in std_logic_vector (7 downto 0);
clk : in std_logic;
reset : in std_logic;
START : in std_logic;
RC_MULT : out std_logic_vector(15 downto 0);
STOP : out std_logic
);
end component;
component ADD_ACCUMULATOR
port (
OPERAND_in : in std_logic_vector (15 downto 0);
reset : in std_logic;
ADD_cmd: in std_logic;
C_out : out std_logic;
RC : out std_logic_vector (19 downto 0)
);
end component;
component CONTROLLER_MAC
port (
reset : in std_logic;
clk : in std_logic;
START : in std_logic;
END_MULT : in std_logic;
32
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
);
end component;
begin
inst_register8_A: REGISTER8
port map (
reset => Rreset,
A_in_reg => ROPA_in,
LOAD_cmd => RLOAD_cmd,
RA => RA_in
);
inst_register8_B: REGISTER8
port map (
reset => Rreset,
A_in_reg => ROPB_in,
LOAD_cmd => RLOAD_cmd,
RA => RB_in
);
inst_MULTIPLIER: MULTIPLIER
port map (
A_in => RA_in,
B_in => RB_in,
clk => clk,
reset => Rreset,
START => RSTART_BEG,
RC_MULT => ROPERAND_in,
STOP => RSTOP_END
);
inst_ADD_ACCUMULATOR: ADD_ACCUMULATOR
port map (
OPERAND_in => ROPERAND_in,
reset => Rreset,
ADD_cmd => RADD_cmd,
C_out => RC_out,
RC => RRC
);
inst_CONTROLLER_MAC: CONTROLLER_MAC
port map (
33
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
);
end RTL;
-----------------------------------------------------------------------
-- ------------------------
-- Purpose : TESTBENCH CARRY_SELECT20
-- ------------------------
-- This file describes a VHDL model of a testbench for the 20-bit
-- carry select adder. A sample array is fed into DUT, and the
-- results of simulation would be compared with this sample array.
-- An error message would be generated if they do not match.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity funct_test is
end funct_test;
34
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
);
component carry_select20
port (
A, B : in std_logic_vector(19 downto 0);
C_in : in std_logic;
SUM : out std_logic_vector(19 downto 0);
C_out : out std_logic
);
end component;
begin
design: carry_select20 port map(A,B,C_in,SUM,C_out);
process
begin
for i in test_data'range loop
A <= test_data(i).A;
B <= test_data(i).B;
C_in <= test_data(i).C_in;
wait for 10 ns;
assert SUM = test_data(i).SUM
report "output SUM is wrong!"
severity error;
assert C_out = test_data(i).C_out
report "output C_out is wrong!"
severity error;
end loop;
wait;
end process;
end test_bench;
-----------------------------------------------------------------------
-- -------------------------
-- Purpose : TESTBENCH ADD_ACCUMULATOR
-- -------------------------
-- This file describes a VHDL model of a testbench for the add-
35
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity FUNC_TEST_ADD_ACC is
end FUNC_TEST_ADD_ACC;
end record;
);
component ADD_ACCUMULATOR
port (
OPERAND_in : in std_logic_vector (15 downto 0);
reset : in std_logic;
ADD_cmd: in std_logic;
C_out : out std_logic;
RC : out std_logic_vector (19 downto 0)
);
36
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
end component;
begin
design: ADD_ACCUMULATOR port map(OPERAND_in, reset, ADD_cmd,
C_out, RC);
process
begin
for i in test_data'range loop
OPERAND_in <= test_data(i).OPERAND_in;
reset <= test_data(i).reset;
ADD_cmd <= test_data(i).ADD_cmd;
wait for 10 ns;
assert C_out = test_data(i).C_out
report "output STOP is wrong!"
severity error;
assert RC = test_data(i).RC
report "output RC is wrong!"
severity error;
end loop;
wait;
end process;
end test_bench;
-----------------------------------------------------------------------
-- --------------------
-- Purpose : TESTBENCH MULTIPLIER
-- --------------------
-- This file describes a VHDL model of a testbench for the
-- multiplier unit.
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
37
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
use std.textio.all;
use ieee.std_logic_textio.all;
entity TESTBENCH is
end TESTBENCH;
component MULTIPLIER
port (
A_in : in std_logic_vector (7 downto 0);
B_in : in std_logic_vector (7 downto 0);
clk : in std_logic;
reset : in std_logic;
START : in std_logic;
RC_MULT : out std_logic_vector(15 downto 0);
STOP : out std_logic
);
end component;
begin
38
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
begin
for i in 1 to 20 loop
end loop;
wait;
end BEHAVIORAL;
-----------------------------------------------------------------------
39
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
-- --------------
-- Purpose : TESTBENCH MAC1
-- --------------
-- This file describes a VHDL model of a testbench for the
-- MAC unit. This testbench verifies that the MAC could handle
-- the maximum accumulated value; The maximum value is 255 x 255 x
-- 10 = 650250 or 9EC0A (HEX)
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity FUNC_TEST_MAC1 is
end FUNC_TEST_MAC1;
component MAC
port (
OPA_in : in std_logic_vector (7 downto 0);
OPB_in : in std_logic_vector (7 downto 0);
clk : in std_logic;
reset : in std_logic;
START : in std_logic;
FINISH_cmd : out std_logic;
RC : out std_logic_vector(19 downto 0);
C_out : out std_logic;
STOP : out std_logic
);
end component;
begin
--instantiate DUT
inst_DUT: MAC
port map(
OPA_in => OPA_in_TB,
40
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
begin
write(L, string'("A B RESULT")); -- include heading in
file
writeline(logFile,L);
A_temp := 255;
B_temp := 255;
for i in 1 to 10 loop
OPA_in_TB <= STD_LOGIC_VECTOR(to_unsigned(A_temp,8));
OPB_in_TB <= STD_LOGIC_VECTOR(to_unsigned(B_temp,8));
41
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
hwrite(L, OPB_in_TB);
write(L, string'(" "));
hwrite(L, RC_TB);
writeline(logFile,L);
end loop;
wait;
end process STIMULUS_START;
end test_bench;
-----------------------------------------------------------------------
-- --------------
-- Purpose : TESTBENCH MAC2
-- --------------
-- This file describes a VHDL model of a testbench for the
-- MAC unit. This testbench feeds the input registers with a pair
-- of ascending-descending operands.
-- The results are stored in a text file called "bus_log_
-- ascending_descending.txt".
-----------------------------------------------------------------------
-----------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
use std.textio.all;
use ieee.std_logic_textio.all;
entity FUNC_TEST_MAC2 is
end FUNC_TEST_MAC2;
component MAC
port (
OPA_in : in std_logic_vector (7 downto 0);
OPB_in : in std_logic_vector (7 downto 0);
clk : in std_logic;
reset : in std_logic;
START : in std_logic;
FINISH_cmd : out std_logic;
RC : out std_logic_vector(19 downto 0);
C_out : out std_logic;
STOP : out std_logic
42
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
);
end component;
begin
--instantiate DUT
inst_DUT: MAC
port map(
OPA_in => OPA_in_TB,
OPB_in => OPB_in_TB,
clk => clk_TB,
reset => reset_TB,
START => START_TB,
FINISH_cmd => FINISH_cmd_TB,
RC => RC_TB,
C_out => C_out_TB,
STOP => STOP_TB
);
-- Generating CLK STIMULUS
STIMULUS_CLK: process
variable j: integer;
begin
for i in 0 to 10000 loop
clk_TB <= '0';
wait for 10 ns;
clk_TB <= '1';
wait for 10 ns;
end loop;
wait;
end process STIMULUS_CLK;
begin
write(L, string'("A B RESULT")); -- include heading in
file
writeline(logFile,L);
A_temp := 0;
43
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
B_temp := 255;
end loop;
wait;
end process STIMULUS_START;
end test_bench;
44
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
45
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos
5
8-by-8 Bit Multiply Accumulator
Jean Jewry Ramos