































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
































Module:3 Implementation of Arithmetic system 5 hours Arithmetic Circuits: High Speed Adders, Carry look-ahead adder, Carry save adders, Conditional Sum adders, Sequential and Parallel Multipliers
Arithmetic circuits are fundamental components in digital systems, especially in processors, where speed is crucial. High-speed adders are designed to reduce the delay caused by carry propagation in simple ripple carry adders.
Carry Look-Ahead Adder CLA Carry Save Adder CSA Conditional Sum Adder CSumA
The CLA adder improves speed by generating carry signals in advance, based on the inputs. The carry for each bit is calculated using generate G and propagate P functions:
Generate : \ G[i] A[i] \cdot B[i] ) Propagate : \ P[i] A[i] \oplus B[i] )
The carry for each bit can then be determined using these formulas:
\ C[i+1] G[i] \text{ or } (P[i] \cdot C[i]) ]
This approach reduces the time complexity to \ O\log n) ).
module CLA_Adder #(parameter WIDTH = 4) ( input [WIDTH-1:0] A, B, input Cin, output [WIDTH-1:0] Sum, output Cout ); wire [WIDTH-1:0] G, P, C;
assign G = A & B; // Generate assign P = A ^ B; // Propagate
assign C[0] = Cin; genvar i; generate for (i = 1; i < WIDTH; i = i + 1) begin : gen_carry assign C[i] = G[i-1] | (P[i-1] & C[i-1]); end endgenerate
assign Cout = G[WIDTH-1] | (P[WIDTH-1] & C[WIDTH-1]); assign Sum = P ^ C; endmodule
module tb_CLA_Adder; reg [3:0] A, B; reg Cin; wire [3:0] Sum; wire Cout;
CLA_Adder #(4) uut ( .A(A), .B(B), .Cin(Cin), .Sum(Sum), .Cout(Cout)
assign TempSum = A ^ B ^ Cin; assign Carry = (A & B) | (B & Cin) | (Cin & A);
assign Cout = Carry[WIDTH-1]; assign Sum = TempSum; endmodule
module tb_CSA_Adder; reg [3:0] A, B, Cin; wire [3:0] Sum; wire Cout;
CSA_Adder #(4) uut ( .A(A), .B(B), .Cin(Cin), .Sum(Sum), .Cout(Cout) );
initial begin $monitor("A = %b, B = %b, Cin = %b -> Sum = %b, Cout = %b", A, B, Cin, Sum, Cout); A = 4'b0101; B = 4'b0011; Cin = 4'b0001; #10 A = 4'b1111; B = 4'b1111; Cin = 4'b1111; #10 A = 4'b0000; B = 4'b0000; Cin = 4'b0000; #10 $finish; end endmodule
Verification Ensure the Sum and Cout match the expected outputs. Usage Commonly used in parallel multiplication where multiple partial products are summed.
4. Conditional Sum Adder (CSumA)
The Conditional Sum Adder works by computing two sums in parallel: one assuming the carry-in is 0 and the other assuming it is 1. The correct result is then selected based on the actual carry-in.
module Conditional_Sum_Adder #(parameter WIDTH = 4) ( input [WIDTH-1:0] A, B, input Cin, output [WIDTH-1:0] Sum, output Cout ); wire [WIDTH-1:0] Sum0, Sum1; wire Cout0, Cout1;
// Sum assuming Cin = 0 assign {Cout0, Sum0} = A + B;
// Sum assuming Cin = 1 assign {Cout1, Sum1} = A + B + 1;
// Conditional select assign Sum = Cin? Sum1 : Sum0; assign Cout = Cin? Cout1 : Cout0; endmodule
module tb_Conditional_Sum_Adder; reg [3:0] A, B; reg Cin; wire [3:0] Sum;
Propagate \ P[i] ) Carry propagated from the previous stage through \ A[i] ) and \ B[i] ).
The carry signals are calculated as: \ C[i+1] G[i] P[i] \cdot C[i] ]
Where \ G[i] A[i] \cdot B[i] ) and \ P[i] A[i] \oplus B[i] ).
module CLA_Adder_4bit(A, B, Cin, Sum, Cout); input [3:0] A, B; input Cin; output [3:0] Sum; output Cout;
wire [3:0] G, P, C;
assign G = A & B; // Generate assign P = A ^ B; // Propagate
assign C[0] = Cin; assign C[1] = G[0] | (P[0] & C[0]); assign C[2] = G[1] | (P[1] & C[1]); assign C[3] = G[2] | (P[2] & C[2]); assign Cout = G[3] | (P[3] & C[3]);
assign Sum = P ^ C[3:0];
endmodule
module CLA_Adder_4bit_Behavioral(A, B, Cin, Sum, Cout); input [3:0] A, B;
input Cin; output reg [3:0] Sum; output reg Cout;
reg [3:0] G, P, C;
always @(A or B or Cin) begin G = A & B; // Generate P = A ^ B; // Propagate C[0] = Cin;
C[1] = G[0] | (P[0] & C[0]); C[2] = G[1] | (P[1] & C[1]); C[3] = G[2] | (P[2] & C[2]); Cout = G[3] | (P[3] & C[3]);
Sum = P ^ C[3:0]; end
endmodule
module CLA_Adder_4bit_Structural(A, B, Cin, Sum, Cout); input [3:0] A, B; input Cin; output [3:0] Sum; output Cout;
wire [3:0] G, P, C;
// Generate and Propagate and(G[0], A[0], B[0]); and(G[1], A[1], B[1]); and(G[2], A[2], B[2]);
#10; // Wait for 10 time units $display("A=%b, B=%b, Cin=%b : Sum=%b, Cout=%b", A, B, Cin, Sum, Cout); // Continue with more test cases as needed end endmodule
For manual verification, consider a simple case where \ A 4'b1100 ), \ B 4'b1010 ), and \ Cin 0 ):
Calculate the generate and propagate terms: \ G A \cdot B 4'b1000 ) \ P A \oplus B 4'b0110 ) Calculate the carry: \ C 1 G 0 | P 0 \cdot Cin) 0 ) \ C 2 G 1 | P 1 \cdot C 1 1 ) \ C 3 G 2 | P 2 \cdot C 2 0 ) \ C 4 G 3 | P 3 \cdot C 3 1 ) Calculate the sum: \ Sum P \oplus C 4'b0110 )
So the output should be \ Sum 4'b0110 ), \ Cout 1 ).
The CSA is used in multi-operand addition, where it saves partial carries instead of propagating them immediately. This allows multiple additions to occur simultaneously without waiting for carries to propagate.
module CSA(A, B, Cin, Sum, Cout); input [3:0] A, B, Cin; output [3:0] Sum, Cout;
assign Sum = A ^ B ^ Cin; assign Cout = (A & B) | (B & Cin) | (Cin & A);
endmodule
module CSA_tb; reg [3:0] A, B, Cin; wire [3:0] Sum, Cout;
CSA uut (A, B, Cin, Sum, Cout);
initial begin // Apply inputs and observe outputs A = 4'b1100; B = 4'b1010; Cin = 4'b0111; #10; $display("A=%b, B=%b, Cin=%b : Sum=%b, Cout=%b", A, B, Cin, Sum, Cout); end endmodule
Given \ A 4'b1100 ), \ B 4'b1010 ), \ Cin 4'b0111 ):
Sum = \ A \oplus B \oplus Cin 4'b0001 ) Cout = ( A \cdot B B \cdot Cin) + (Cin \cdot A 4'b1110 )
Thus, the output should be \ Sum 4'b0001 ), \ Cout 4'b1110 ).
module CSumA_tb; reg [3:0] A, B; reg Cin; wire [3:0] Sum; wire Cout;
CSumA uut (A, B, Cin, Sum, Cout);
initial begin // Apply inputs and observe outputs A = 4'b1100; B = 4'b1010; Cin = 0; #10; $display("A=%b, B=%b, Cin=%b : Sum=%b, Cout=%b", A, B, Cin, Sum, Cout);
Cin = 1; #10; $display("A=%b, B=%b, Cin=%b : Sum=%b, Cout=%b", A, B, Cin, Sum, Cout); end endmodule
With \ A 4'b1100 ), \ B 4'b1010 ), \ Cin 0 ):
If \ Cin 0 ), \ Sum_0 A \oplus B 4'b0110 ), \ Cout_0 1 ) If \ Cin 1 ), \ Sum_1 A \oplus B \oplus 1 4'b0111 ), \ Cout_1 1 )
Selecting based on \ Cin ), output should match the expected values.
The above Verilog models and manual verification steps should help you understand and implement high-speed adders. After implementing and running
the testbenches in a simulation tool, you can confirm that the outputs match the expected results.
Given the inputs: A = 4'b B = 4'b Cin = 0
Step 1: Calculate the generate and propagate terms: G = A ⋅ B = 4'b P = A ⊕ B = 4'b
Step 2: Calculate the carry: C[1] = G[0] ∣ (P[0] ⋅ Cin) = 0 C[2] = G[1] ∣ (P[1] ⋅ C[1]) = 1 C[3] = G[2] ∣ (P[2] ⋅ C[2]) = 0 C[4] = G[3] ∣ (P[3] ⋅ C[3]) = 1
Step 3: Calculate the sum: Sum = P ⊕ C = 4'b
Expected output: Sum = 4'b Cout = 1
Given the inputs: A = 4'b B = 4'b Cin = 4'b
Sum = 4'b Cout = 1
To understand how different adders work, we'll start by manually solving the logic for basic components like the half adder, full adder, ripple carry adder, and then move on to the more complex high-speed adders: Carry Look-Ahead Adder CLA, Carry Save Adder CSA, and Conditional Sum Adder CSumA. I'll break down each of these in detail, showing the logic operations step-by-step.
Logic Explanation:
A half adder adds two single-bit binary numbers, producing a sum and a carry.
Sum S The result of the XOR operation between the two inputs. Carry Cout) The result of the AND operation between the two inputs.
Equations:
\ S A \oplus B ) \ Cout A \cdot B )
Example Calculation:
Given: A = 1, B = 1
Step 1: Calculate Sum: S = A ⊕ B = 1 ⊕ 1 = 0
Step 2: Calculate Carry: Cout = A ⋅ B = 1 ⋅ 1 = 1
Expected Output: Sum = 0, Carry = 1
Logic Explanation:
A full adder adds three single-bit binary numbers (two inputs and a carry-in), producing a sum and a carry-out.
Sum S The result of the XOR operation between the inputs and the carry-in. Carry Cout) The result of the OR operation between the AND results of the input pairs.
Equations:
\ S A \oplus B \oplus Cin ) \ Cout = A \cdot B \oplus B \cdot Cin) \oplus Cin \cdot A )
Example Calculation:
Given: A = 1, B = 1, Cin = 0
Step 1: Calculate Sum: S = A ⊕ B ⊕ Cin = 1 ⊕ 1 ⊕ 0 = 0
Step 2: Calculate Carry: Cout = (A ⋅ B) ⊕ (B ⋅ Cin) ⊕ (Cin ⋅ A) = (1 ⋅ 1) ⊕ (1 ⋅ 0) ⊕ (0 ⋅ 1) = 1
Expected Output: Sum = 0, Carry = 1
Logic Explanation:
A ripple carry adder is a simple multi-bit adder that chains full adders together. The carry-out from each full adder becomes the carry-in for the next.
4-bit Example:
The CLA adder improves speed by generating carry signals in advance using the generate G and propagate P functions.
Equations:
\ G[i] A[i] \cdot B[i] ) \ P[i] A[i] \oplus B[i] ) \ C[i+1] G[i] P[i] \cdot C[i] )
Example Calculation:
Given: A = 1100, B = 1010, Cin = 0
Step 1: Calculate Generate (G) and Propagate (P): G = A ⋅ B = 1000 P = A ⊕ B = 0110
Step 2: Calculate Carry: C[1] = G[0] ∣ (P[0] ⋅ Cin) = 0 C[2] = G[1] ∣ (P[1] ⋅ C[1]) = 1 C[3] = G[2] ∣ (P[2] ⋅ C[2]) = 0 C[4] = G[3] ∣ (P[3] ⋅ C[3]) = 1
Step 3: Calculate the sum: Sum = P ⊕ C = 0110
Expected Output: Sum = 0110, Cout = 1
Logic Explanation:
The CSA is used in multi-operand addition, where it saves partial carries instead of propagating them immediately, allowing multiple additions to occur simultaneously.
Equations:
\ Sum A \oplus B \oplus Cin ) \ Cout = A \cdot B B \cdot Cin) + (Cin \cdot A )
Example Calculation:
Given: A = 1100, B = 1010, Cin = 0111
Step 1: Calculate Sum: Sum = A ⊕ B ⊕ Cin = 0001
Step 2: Calculate Carry: Cout = (A ⋅ B) ∣ (B ⋅ Cin) ∣ (Cin ⋅ A) = 1110
Expected Output: Sum = 0001, Cout = 1110
Logic Explanation:
In a Conditional Sum Adder, the sum is calculated conditionally for both possible carry-in values 0 and 1. The correct result is selected based on the actual carry- in.
Example Calculation:
Given: A = 1100, B = 1010, Cin = 0
Step 1: If Cin = 0: Sum_0 = A ⊕ B = 0110 Cout_0 = (A ⋅ B) = 1
Step 2: If Cin = 1: