Serial Multiplier Vhdl Code

  1. 4 Bit Multiplier Vhdl Code
  2. Serial Multiplier Vhdl Code For Pc
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
ENTITY NAND_GATE IS
PORT(A,B:IN STD_LOGIC;C:OUT STD_LOGIC);
END NAND_GATE;
ARCHITECTURE NAND_ARCH OF NAND_GATE IS
BEGIN
C<=(NOT(A AND B));
END NAND_ARCH;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY HALF_ADDER IS
PORT(A,B:IN STD_LOGIC;SUM,CARRY:OUT STD_LOGIC);
END HALF_ADDER;
ARCHITECTURE HALF_ADDER_ARCH OF HALF_ADDER IS
SIGNAL X1,X2,X3:STD_LOGIC;
COMPONENT NAND_GATE
PORT(A,B:IN STD_LOGIC;C:OUT STD_LOGIC);
END COMPONENT;
BEGIN
STEP1:NAND_GATE PORT MAP (A,B,X1);
STEP2:NAND_GATE PORT MAP (A,X1,X2);
STEP3:NAND_GATE PORT MAP (B,X1,X3);
STEP4:NAND_GATE PORT MAP (X2,X3,SUM);
CARRY<=((A NAND B)NAND (A NAND B));
END HALF_ADDER_ARCH;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY BITFULLADDER IS
PORT(A,B,CIN:IN STD_LOGIC;SUM,CARRY:OUT STD_LOGIC);
END BITFULLADDER;
ARCHITECTURE BITFULLADDER_ARCH OF BITFULLADDER IS
COMPONENT HALF_ADDER
PORT(A,B:IN STD_LOGIC;SUM,CARRY:OUT STD_LOGIC);
END COMPONENT;
SIGNAL Z1,C1,C2: STD_LOGIC;
BEGIN
STEP5:HALF_ADDER PORT MAP(A,B,Z1,C1);
STEP6:HALF_ADDER PORT MAP(CIN,Z1,SUM,C2);
CARRY<=((C1 NAND C1) NAND (C2 NAND C2));
END BITFULLADDER_ARCH;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.numeric_bit.all;
entity multiplierr is
Port ( x : in STD_LOGIC_VECTOR (03 downto 0);
y : in STD_LOGIC_VECTOR (03 downto 0);
z : out STD_LOGIC_VECTOR (07 downto 0);
carry:out std_logic);
end multiplierr;
architecture Behavioral of multiplierr is
component BITFULLADDER
PORT(A,B,CIN:IN STD_LOGIC;SUM,CARRY:OUT STD_LOGIC);
END component;
signal a,b,c,d,j,k:std_logic_vector(7 downto 0 );
signal c0,c1,c2,c3,c4,c5,c6,c7,c00,c01,c02,c03,c04,c05,c06,c07,c000,c001,c002,c003,c004,c005,c006,c007:std_logic;
begin
process(x,y,a,b,c,d,j,k,c0,c1,c2,c3,c4,c5,c6,c7,c00,c01,c02,c03,c04,c05,c06,c07,c000,c001,c002,c003,c004,c005,c006,c007)
begin
if x(0)='1'
then a<='0000'&y;
else a<='0000'&'0000';
end if;
if x(1)='1'
then b<='000'&y&'0';
else b<='000'&'0000'&'0';
end if;
if x(2)='1'
then c<='00'&y&'00';
else c<='00'&'0000'&'00';
end if;
if x(3)='1'
then d<='0'&y&'000';
else d<='0'&'0000'&'000';
end if;
end process;
j0:BITFULLADDER port map (a(0),b(0),'0',j(0),c0);
j1:BITFULLADDER port map (a(1),b(1),c0,j(1),c1);
j2:BITFULLADDER port map (a(2),b(2),c1,j(2),c2);
j3:BITFULLADDER port map (a(3),b(3),c2,j(3),c3);
j4:BITFULLADDER port map (a(4),b(4),c3,j(4),c4);
j5:BITFULLADDER port map (a(5),b(5),c4,j(5),c5);
j6:BITFULLADDER port map (a(6),b(6),c5,j(6),c6);
j7:BITFULLADDER port map (a(7),b(7),c6,j(7),c7);
k0:BITFULLADDER port map (c(0),d(0),'0',k(0),c00);
k1:BITFULLADDER port map (c(1),d(1),c00,k(1),c01);
k2:BITFULLADDER port map (c(2),d(2),c01,k(2),c02);
k3:BITFULLADDER port map (c(3),d(3),c02,k(3),c03);
k4:BITFULLADDER port map (c(4),d(4),c03,k(4),c04);
k5:BITFULLADDER port map (c(5),d(5),c04,k(5),c05);
k6:BITFULLADDER port map (c(6),d(6),c05,k(6),c06);
k7:BITFULLADDER port map (c(7),d(7),c06,k(7),c07);
z0:BITFULLADDER port map (j(0),k(0),'0',z(0),c000);
z1:BITFULLADDER port map (j(1),k(1),c000,z(1),c001);
z2:BITFULLADDER port map (j(2),k(2),c001,z(2),c002);
z3:BITFULLADDER port map (j(3),k(3),c002,z(3),c003);
z4:BITFULLADDER port map (j(4),k(4),c003,z(4),c004);
z5:BITFULLADDER port map (j(5),k(5),c004,z(5),c005);
z6:BITFULLADDER port map (j(6),k(6),c005,z(6),c006);
z7:BITFULLADDER port map (j(7),k(7),c006,z(7),c007);
carry<= c7 xor c07 xor c007;
end Behavioral;

In the modern FPGA, the multiplication operation is implemented using a dedicated hardware resource. Such dedicated hardware resource generally implements 18×18 multiply and accumulate function that can be used for efficient implementation of complex DSP algorithms such as finite impulse response (FIR) filters, infinite impulse response (IIR) filters, and fast fourier transform (FFT) for filtering and image processing applications etc.

The Multiplier-Accumulator blocks has a built-in multiplier and adder, which minimizes the fabric logic required to implement multiplication, multiply-add, and multiply-accumulate (MACC) functions. Implementation of these arithmetic functions results in efficient resource usage and improved performance for DSP applications. In addition to the basic MACC function, DSP algorithms typically need small amounts of RAM for coefficients and larger RAMs for data storage.

Feb 21, 2018 Design 2x2 binary multiplier in VHDL Using Xilinx ISE Simulator Searches related to Design 2x2 binary multiplier in vhdl 2 bit multiplier vhdl code 2 bit multiplier verilog code 2 bit multiplier. Different VHDL coding styles shall be demonstrated with a simple module that has to calculate the result of the multiplication of two 2-bit numbers. The maximum value of each input is 3, i.e. The maximum output value is 9 which needs 4 bits in a binary code. Therefore, four input ports and four output ports of data type ’bit’ are required.

The main features multiply-accumulate block are mainly:

  • Supports 18 × 18 signed multiplication natively.
  • Supports 17 × 17 unsigned multiplications.
  • Built-in addition, subtraction, and accumulation units to combine multiplication results efficiently.
  • Independent third input C with data width completely registered.
  • Single-bit input, CARRYIN, from fabric routing.

Of course, these features depend on the technology we are using. Above are described the features that are mainly implemented on every modern FPGA such Altera Stratix, Xilinx Virtex, Microsemi Smartfusion and so on. Each of these technologies customize the implementation adding different features depending on the type of FPGA you are using.

You can, of course, instantiate multiply-accumulate macros using the core generator of the vendor as follow:

Generate the VHDL/Verilog code for the component

Instantiate the component in your VHDL/Verilog code.

Another solution to use the multiplier hardware macro is to activate the instantiation writing the proper VHDL/Verilog code that triggers the synthesizer the instantiation of hardware macro.

Here below you can find the template for NxM signed multiplier. If you want to trigger the hardware macro in an efficient way N and M shall be less than the maximum number of bit handled by the hardware multiplier macro. For instance, if the hardware multiplier can work up to 18×18, you can set N and M to be less or equal to 18 bit. Using more than 18 bit the implementation will use more than a multiplier block slowing down the timing performances.

When you multiply two number with N and M bit, the result will be of N+M bit. For instance, if the first multiplicand has 14 bit and the second multiplicand has 13 bit, the result of the multiplication will have 13+14 = 27 bit.

The example below will implement a 13 x 14 bit signed multiplier.

VHDL Code for 13×14 signed multiplier

To understand what are the hardware resources relative to the 13×14 multiplier implementation let’s layout the code on a Cyclone IV FPGA EP4CGX30. This FPGA has 80 multiplier 18×18 that can be used as 160 multiplier 9×9. The synthesizer maps the best hardware macro implementation for your design.

Figure 1 reports the hardware resources available for the different version of Cyclone IV FPGA. The multiplier has been realized using 2 embedded 9×9 multiplier, as reported on Area report of Figure 2. In the timing report, the maximum clock frequency is 286 MHz.

In Figure 3 is reported the Area and Timing report for a 16×16 multiplier. As clear the hardware resource for the multipliers are the same of the 13×14 multiplier since the VHDL code trigger the same multiplier hardware macro 18×18.

Bit

Implementation of pipelined 16×16 multiplier

Taking as reference the previous example, now we are going to implement the pipelined version of the 16×16 multiplier. Let’s refresh the multiplication algorithm: a 16 bit operand can be written as follow:

So, if we want to multiply two 16-bit operands:

The hardware structure for such implementation is reported in Figure 4:

A possible VHDL implementation of Figure 4 is reported below.

VHDL code for a 16×16 multiplier

Figure 5 reports the area and timing report of VHDL code implementation on Altera Cyclone IV used before. In this case, we are using 4 multipliers 9×9 instead of two and both logic and register. The timing report is quite half the previous and the adder and register are implemented using logic. In the previous example reported in Figure 3 the register and logic was zero since the VHDL code of the multiplier was mapped in the hardware multiplier resource present into the FPGA.

Starting from the architecture of Figure 4 the pipeline implementation is straightforward. To implement the pipeline into the multiplier architecture, we need to introduce registers to break the combinatorial path of multiplication and addition and compensate the delay added by these registers.

A possible implementation is given in Figure 6. Here the latency of the multiplier is 6 clock cycles.

Starting from the architecture of the pipelined multiplier of Figure 6 a possible VHDL implementation of a signed pipeline multiplier is:

VHDL code for 16×16 pipeline multiplier

The implementation of the VHDL code of the pipeline multiplier reports the timing characteristic like the implementation of Figure 3 while the area is greater than the implementation of Figure 3.

We can conclude that, for FPGA implementation, if we are using the hardware macro implementation for a multiplier, generally this is the best solution. In ASIC implementation, the pipeline approach can give good result since the same implementation on FPGA report timing performance similar to the optimal implementation of the hardware macro inside the FPGA. In the next section, we will discover a condition where the pipeline multiplier can be used in FPGA too.

Serial Multiplier Vhdl Code

Take advantage of pipeline multiplier

In the previous section, we learned how to pipeline a multiplier. The VHDL of the pipeline multiplier has been evaluated on a Cyclone IV FPGA. As clear from area and timing report there are no significant advantages in writing the pipelined version of a multiplier since we are using the basic multiplier macro primitive. As clear from Figure 3 and Figure 7 the timing is similar while the area is slightly greater than the version without a pipeline. Now we are going to see an example where the pipeline multiplier has better performances than the no pipelined one. Suppose you need a multiplier 35×35. The FPGA we are using supports natively 18×18, so you need to use 2 multiplier 18×18 in order to implement a multiplier 35×35.

The VHDL code for a 34×34 multiplier is:

VHDL code for 34×34 multiplier

Using a Cyclone IV FPGA the area and timing report are in Figure 8

In this case, if we want to pipeline the multiply, we can re-write the multiply as:

Following the same rules of the previous section the hardware architecture of the multiplier will be:

The VHDL code for the 34×34 pipelined multiplier can be written following the architecture of Figure 9:

VHDL code for 34×34 pipeline multiplier

Serial multiplier vhdl code for windows 7

Mapping this VHDL code on the Cyclone IV used in the no-pipeline example the results are:

4 Bit Multiplier Vhdl Code

As clear in this case, the pipeline implementation gives an important speed-up in terms of timing, doubling the performances. Conclusion In this post, we considered the VHDL implementation of a multiplier. If we are using an FPGA we should check if the silicon provides the hardware macro for the multiplier. If case the multiplier are present into FPGA as dedicated silicon, we can use them directly using the “*” operator. We must pay attention to the maximum width in

We must pay attention to the maximum width in bit for the operand, if we use operand with the number of the bit less than or equal to the maximum number provided by the hardware macro the VHDL code will be mapped directly into the hardware multiplier as seen in the previous example. In case we need more bit than the maximum number provided we could have to use a pipeline approach. The examples provided above with the Cyclone IV FPGA, but the same consideration can be extended to the others technologies, show that since the number of bit of the operand is less than or equal to 18, no benefit is present in pipeline implementation as summarized in Figure 11.

In the case of multiplier 35×35 the pipeline implementation has a great impact on performances in terms of speed as summarized. In this case is clear that despite an increment of register due to the pipeline, the timing performances increment is 2X.

If you appreciated this post, please help us to share it to your friend.

If you need to contact us, please write to: surf.vhdl@gmail.com

Serial Multiplier Vhdl Code For Pc

We appreciate any of your comment, please post below: