Logical circuit design
Inquiry Sitemap Link Tips
Regarding CSA[1]

Outline of CSA

Overflow problem of CSA

Subtraction using CSA

CSA Code

/* **************************** MODULE PREAMBLE ********************************

	Copyright (c) 2012, ArchiTek
	This document constitutes confidential and proprietary information
	of ArchiTek. All rights reserved.
*/

// ***************************** MODULE HEADER *********************************
//
// Module for adding normal type value and CSA type value
//  CSA type value+normal type value=CSA type value
//

module CSA (
	iA,
	iB,

	oY

	);

// ************************ PARAMETER DECLARATIONS *****************************

	parameter		W	= 4;		// Normal type bit width

// *************************** I/O DECLARATIONS ********************************

	// Input
	input	[W*2-1:0]	iA;			// CSA type input value A
                                                        // Bit width is twice normal type
	input	[W-1:0]		iB;			// Normal type input value B

	// Output
	output	[W*2-1:0]	oY;			// CSA type output value
                                                        // Bit width is twice normal type

// ************************** LOCAL DECLARATIONS *******************************

// ****************************** MODULE BODY **********************************
//Actual operation is thru CSAFunc
assign oY		= CSAFunc(iA, iB);

// ************************** FUNCTIONS and TASKS ******************************

function [W*2-1:0] CSAFunc;
	input	[W*2-1:0]	opA;
	input	[W-1:0]		opB;
	reg	[1:0]		result[0:W-1];
	reg	[1:0]		tmp;
	integer			i;

	begin
                // 0 bit addition result is inserted into result
                // No Carry for 0 bit
		result[0]	= {1'd0, opA[0]}
				+ {1'd0, opB[0]};

                // 1 bit and higher addition results are inserted into result
                // For 1 bit and higher previous bit Carry and Value A and B values are added.
		for (i=1; i < W; i=i+1)
			result[i]	= {1'd0, opA[i*2-1]}
					+ {1'd0, opA[i*2]}
					+ {1'd0, opB[i]};

                // result is inserted as CSA type
		for (i=0; i < W; i=i+1) begin
			tmp		= result[i];

			CSAFunc[i*2+1]	= tmp[1];
			CSAFunc[i*2]	= tmp[0];
		end
	end
endfunction

endmodule

// *****************************************************************************


        

CSA Type ⇔ Normal type transform code

//
// Function to transform normal type value to CSA type
//
function [CSA_BIT_W-1:0] bin2csaFunc;
	input	[BIT_W-1:0]	data;
	integer			i;

	begin
		for(i=0 ; i < BIT_W ; i=i+1) begin
			bin2csaFunc[i*2] = data[i];     // Insert value into Value part
			bin2csaFunc[i*2+1] = 1'b0;      // Insert 0 into Carry part
		end
	end

endfunction


//
// function to transform CSA type value into normal type value
//
function [BIT_W-1:0] csa2binFunc;
	input	[CSA_BIT_W-1:0]		data;
	reg	[BIT_W-1:0]		carry;
	reg	[BIT_W-1:0]		value;
	integer			i;

	begin
		for (i=0; i < BIT_W; i=i+1) begin
			carry[i]	= data[i*2+1];     // Extract Carry part
			value[i]	= data[i*2];       // Extract Value part
		end

		// Carry part is shifted 1 bit to the left and added to Value
		csa2binFunc	= {carry[BIT_W-2:0], 1'b0} + value;
	end
endfunction


        

Logical circuit design > Technic > Fast operation    Next page(Pipeline feedback)    TOP of this page ▲

[1]
In fast operation, there are other factors then CSA. Will add these to this chapter later.
[2]
Reference:
・Wikipedia Adder
・Wikipedia Digit up stored adder

[3]
Subtraction using CSA also has the problem of overflow which needs to be considered and taken care.