Reconfigurablecomputing: Euclidean Distance Based Sorting

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

RECONFIGURABLECOMPUTING

CS G553

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE PILANI,


HYDERABAD

ASSIGNMENT 1

Euclidean Distance Based Sorting

Submitted By:
Sanchit Kulkarni (2021H1400153H)
Sujaan Dubey (2021H1400159H)
Anshul Gupta (2021H1400260H)
Anirudh Marathe(2021H1400146H)

Submitted To : Prof. Ravi Teja & Dr. Ershad Ahmed


EXCEL (for HLL)

Decimal to Half Precision Conversion-

Half Precision to Decimal Conversion-


FLOWCHART :

Pre-requisites
Keep Input data containing 32 co=ordinates in (x,y) format with range x,y between
(-1,1)

Load input data in string format

To read data
Convert above String format into float using ‘,’ a delimiter.

calculation
Centroid
Computer centroid coordinate by using mean of x-coordinates and y-coordinates.

Euclidean distance calculation


Find difference between input coordinates and centroid coordinates

Using numpy - linear algebra & ‘norm’ function


Computer Euclidean distance using above difference

append with the coordinates


Formatting the above data to
Reshaping above information into one column of 32 rows

Using stack function, appending this dist_to centroid along with input co-ordinates

Save the last column using return index


Sorting

Display the sorted co-ordinates using the above index


Output

Save the file into ‘sorted_coord.txt’


ADDER/SUBTRACTOR

The Addition and subtraction of the two floating point numbers can be performed using
following steps:
1. Both The inputs and outputs need to be represented in IEEE-754 standard format in
half precision.
2. Now, we check the xor of msb’s of both number this involves follwing cases->
 If xor=0, implies either both number positive or both number negative I.e. addition is
involved.
 If xor=1, implies either of the number is negative I.e. involves subtraction.

A’s sign bit B’s sign bit Resultant sign Operation


bit
0 0 0 ADD
0 1 1 SUBTRACT
1 0 1 SUBTRACT
1 1 0 ADD

3. Compare the exponent of the two inputs and calculate the difference (if any). And
check which number is smaller.
 e1>e2 -The smaller input’s mantissa will be shifted right by the difference of
the two input exponents and the other one will be passed as it is.
 e1<e2- The smaller input’s mantissa will be shifted right by the difference of
the two input exponents and the other one will be passed as it is.
 e1=e2- Don't take the difference of exponents and shift the mantissa, just
pass the value of mantissa and exponent.
This way two mantissas are aligned to be added in a standard adder circuit. we
will obtain one mantissa, sign bit and exponent from this step. In the above
example e1=e2 hence no shifting needed.

4. If xor is zero the shifted mantessa of the smaller number and the mantessa of larger number
is added and stored in a 11 bit variable.
 If 11th bit is one the sum is left shifted by 1 and larger number exponent is
increased by 1.
Exponent sum is stored in a 6 bit variable and carry is check to check the
overflow of range .
 If not the sum is the output mantessa and output exponent is that of larger number
5. If msb xor is one, exponents are compared as depicted in point 3, and mantessa of
smaller number is shifted by the difference, output is assigned the msb and
exponent of larger number. The 2’s complement of shifted mantessa is calculated
and added to the larger number’s mantessa and thus output mantessa is calculated.

UTILIZATION:

SCHEMATIC:
WAVEFORM:
BOOTH’S MULTIPLIER –
Booth’s multiplier as the name suggests uses Booth’s Radix – 4 Modified multiplication algorithm to
find the product. The whole purpose of Booth’s algorithm is to reduce the number of partial products
as in any multipliers the carry propagate and sum are the most time-consuming process. In Radix – 4
Booth’s Multiplier the multiplicand is divided into 3-bit overlapping groups and based on their values
the specific partial product is generated through multiplier. Then all the partial products are then
added. But in half precision the procedure changes as we have to take care of not only the sign bit but
also the exponent bits and the mantissa bits. As we have 10-bit mantissa along with 1 hidden bit the
total product comes out as 22-bit product thus we use normalisation to find hidden bit and truncate
10-bits.

SCHEMATIC :

WAVEFORM :

Utilization:
COMPARATOR

Function: This sub-module compares two half precision numbers and outputs a one-bit signal.

Algorithm:
1. Takes 2 input of 16 bits each.
2. Consider Sign bits of both inputs and write 4 cases – if both are negative, or both
positive or positive and negative and vice-versa.
3. Output the result in 1’b1, if A is greater than B else 1’b0.

SCHEMATIC :

WAVEFORM :

UTILIZATION:
SQUARE ROOT

Function: This module multiplies two half precision floating point numbers.

Algorithm:
1. Takes 2 input of 16 bits each.
2. Separate bits into exponent and mantissa.
3. Exponent + Bias is converted to original exponent and is right shifted one bit.
4. Bias is added to the shifted exponent.
5. If true exponent is negative and odd, than in this case significand is shifted to
right rather than left as in all other cases.
6. Compute square root of mantissa using Ross M Fosler Square Root Method by
successively rotating through each bits and setting it as either 0 or 1.
7. We’d calculate significand fir true exponent both for odd and even separately,
based upon corresponding exponent we assign square rooted significand value
to output.
8. Outputs the result in half precision format.

UTILIZATION :

SCHEMATIC:
WAVEFORM :
MEMORY

Memory holds 32 data points as 32-bit words. The 0 to 15 bits contain y-coordinate whereas
16 to 31 bits contain x-coordinate. Then the (x,y) format makes each data point as 8-bit
hexadecimal notation. It makes it easier to store and convert. The memory has clock input
and read enable. The memory also contains a 32-bit data input and 5-bit address and an
output of 32-bit data output.

RTL Schematic :
SIMULATION :

UTILIZARION :
CONTROL UNIT & DATA PATH :
module data_path(clk,ld,dist

);
input clk;
output reg [15:0]dist;
wire start,reset;
wire [15:0]X[1:32];
wire [15:0]Y[1:32];
wire [31:0]dout;
input [31:0]ld;
wire[15:0]ox[1:16];
wire[15:0]ol1x[1:8];
wire[15:0]ol2x[1:4];
wire[15:0]ol3x[1:2];
wire[15:0]sum_x;
reg k;

wire[15:0]oy[1:16];
wire[15:0]ol1y[1:8];
wire[15:0]ol2y[1:4];
wire[15:0]ol3y[1:2];
wire[15:0]sum_y;

wire[15:0] x_cen,y_cen,nx_cen,ny_cen;

wire [15:0]x_dif[1:32];
wire [15:0]x_dis[1:32];
wire [15:0]y_dif[1:32];
wire [15:0]y_dis[1:32];
wire [15:0]dis_sum[1:32];

wire [15:0]distance[1:32];
reg [15:0]distance_mem[1:32];

reg [15:0]mem[1:32];

parameter
[4:0]A0=5'b00000,A1=5'b00001,A2=5'b00010,A3=5'b00011,A4=5'b00100,A5=5'b00
101,A6=5'b00110,A7=5'b00111,A8=5'b01000,A9=5'b01001,A10=5'b01010,A11=5'b0
1011,A12=5'b01100,A13=5'b01101,A14=5'b01110,A15=5'b01111,

A16=5'b10000,A17=5'b10001,A18=5'b10010,A19=5'b10011,A20=5'b10100,A21=5'b1
0101,A22=5'b10110,A23=5'b10111,A24=5'b11000,A25=5'b11001,A26=5'b11010,A27
=5'b11011,A28=5'b11100,A29=5'b11101,A30=5'b11110,A31=5'b11111;

// load all the registers x1,x2..... y1,y2............

//load x
control_unit_fsm v2(clk,reset,start,ld);
memory_32_words M0(dout,A0,clk);
PIPO I1(X[1],Y[1],dout,ld[0],clk); // loads the value form dout to
X,Y corresponding registers
memory_32_words M1(dout,A1,clk);
PIPO I2(X[2],Y[2],dout,ld[1],clk);
memory_32_words M2(dout,A2,clk);
PIPO I3(X[3],Y[3],dout,ld[2],clk);
memory_32_words M3(dout,A3,clk);
PIPO I4(X[4],Y[4],dout,ld[3],clk);
memory_32_words M4(dout,A4,clk);
PIPO I5(X[5],Y[5],dout,ld[4],clk);

memory_32_words M5(dout,A5,clk);
PIPO I6(X[6],Y[6],dout,ld[5],clk);
memory_32_words M6(dout,A6,clk);
PIPO I7(X[7],Y[7],dout,ld[6],clk);
memory_32_words M7(dout,A7,clk);
PIPO I8(X[8],Y[8],dout,ld[7],clk);
memory_32_words M8(dout,A8,clk);
PIPO I9(X[9],Y[9],dout,ld[8],clk);
memory_32_words M9(dout,A9,clk);
PIPO I10(X[10],Y[10],dout,ld[9],clk);

memory_32_words M10(dout,A10,clk);
PIPO I11(X[11],Y[11],dout,ld[10],clk);
memory_32_words M11(dout,A11,clk);
PIPO I12(X[12],Y[12],dout,ld[11],clk);
memory_32_words M12(dout,A12,clk);
PIPO I13(X[13],Y[13],dout,ld[12],clk);
memory_32_words M13(dout,A13,clk);
PIPO I14(X[14],Y[14],dout,ld[13],clk);
memory_32_words M14(dout,A14,clk);
PIPO I15(X[15],Y[15],dout,ld[14],clk);

memory_32_words M15(dout,A15,clk);
PIPO I16(X[16],Y[16],dout,ld[15],clk);
memory_32_words M16(dout,A16,clk);
PIPO I17(X[17],Y[17],dout,ld[16],clk);
memory_32_words M17(dout,A17,clk);
PIPO I18(X[18],Y[18],dout,ld[17],clk);
memory_32_words M18(dout,A18,clk);
PIPO I19(X[19],Y[19],dout,ld[18],clk);
memory_32_words M19(dout,A19,clk);
PIPO I20(X[20],Y[20],dout,ld[19],clk);

memory_32_words M20(dout,A20,clk);
PIPO I21(X[21],Y[21],dout,ld[20],clk);
memory_32_words M21(dout,A21,clk);
PIPO I22(X[22],Y[22],dout,ld[21],clk);
memory_32_words M22(dout,A22,clk);
PIPO I23(X[23],Y[23],dout,ld[22],clk);
memory_32_words M23(dout,A23,clk);
PIPO I24(X[24],Y[24],dout,ld[23],clk);
memory_32_words M24(dout,A24,clk);
PIPO I25(X[25],Y[25],dout,ld[24],clk);

memory_32_words M25(dout,A25,clk);
PIPO I26(X[26],Y[26],dout,ld[25],clk);
memory_32_words M26(dout,A26,clk);
PIPO I27(X[27],Y[27],dout,ld[26],clk);
memory_32_words M27(dout,A27,clk);
PIPO I28(X[28],Y[28],dout,ld[27],clk);
memory_32_words M28(dout,A28,clk);
PIPO I29(X[29],Y[29],dout,ld[28],clk);
memory_32_words M29(dout,A29,clk);
PIPO I30(X[30],Y[30],dout,ld[29],clk);

memory_32_words M30(dout,A30,clk);
PIPO I31(X[31],Y[31],dout,ld[30],clk);
memory_32_words M31(dout,A31,clk);
PIPO I32(X[32],Y[32],dout,ld[31],clk);

/// for centroid calculation all the x are added and same is done with
y
//summation of x

// Level 1 16 adders

hpadder AX1(X[1],X[2],ox[1]);
hpadder AX2(X[3],X[4],ox[2]);

hpadder AX3(X[5],X[6],ox[3]);
hpadder AX4(X[7],X[8],ox[4]);

hpadder AX5(X[9],X[10],ox[5]);
hpadder AX6(X[11],X[12],ox[6]);

hpadder AX7(X[13],X[14],ox[7]);
hpadder AX8(X[15],X[16],ox[8]);

hpadder AX9(X[17],X[18],ox[9]);
hpadder AX10(X[19],X[20],ox[10]);

hpadder AX11(X[21],X[22],ox[11]);
hpadder AX12(X[23],X[24],ox[12]);

hpadder AX13(X[25],X[26],ox[13]);
hpadder AX14(X[27],X[28],ox[14]);

hpadder AX15(X[29],X[30],ox[15]);
hpadder AX16(X[31],X[32],ox[16]);

// next level 1
hpadder AXL11(ox[1],ox[2],ol1x[1]);
hpadder AXL12(ox[3],ox[4],ol1x[2]);

hpadder AXL13(ox[5],ox[6],ol1x[3]);
hpadder AXL14(ox[7],ox[8],ol1x[4]);

hpadder AXL15(ox[9],ox[10],ol1x[5]);
hpadder AXL16(ox[11],ox[12],ol1x[6]);

hpadder AXL17(ox[13],ox[14],ol1x[7]);
hpadder AXL18(ox[15],ox[16],ol1x[8]);

//8times

// level 2
//4times
hpadder AL21(ol1x[1],ol1x[2],ol2x[1]);
hpadder AL22(ol1x[3],ol1x[4],ol2x[2]);
hpadder AL23(ol1x[5],ol1x[6],ol2x[3]);
hpadder AL24(ol1x[7],ol1x[8],ol2x[4]);
//level 3
hpadder AXL31(ol2x[1],ol2x[2],ol3x[1]);
hpadder AXL32(ol2x[3],ol2x[4],ol3x[2]);

//level 4

hpadder AXL4(ol3x[1],ol3x[2],sum_x);

// summation of y

//Level 1 16 adders

hpadder AY1(Y[1],Y[2],oy[1]);
hpadder AY2(Y[3],Y[4],oy[2]);

hpadder AY3(Y[5],Y[6],oy[3]);
hpadder AY4(Y[7],Y[8],oy[4]);

hpadder AY5(Y[9],Y[10],oy[5]);
hpadder AY6(Y[11],Y[12],oy[6]);

hpadder AY7(Y[13],Y[14],oy[7]);
hpadder AY8(Y[15],Y[16],oy[8]);

hpadder AY9(Y[17],Y[18],oy[9]);
hpadder AY10(Y[19],Y[20],oy[10]);

hpadder AY11(Y[21],Y[22],oy[11]);
hpadder AY12(Y[23],Y[24],oy[12]);

hpadder AY13(Y[25],Y[26],oy[13]);
hpadder AY14(Y[27],Y[28],oy[14]);

hpadder AY15(Y[29],Y[30],oy[15]);
hpadder AY16(Y[31],Y[32],oy[16]);

//level 2 8 adders

hpadder AYL11(oy[1],oy[2],ol1y[1]);
hpadder AYL12(oy[3],oy[4],ol1y[2]);

hpadder AYL13(oy[5],oy[6],ol1y[3]);
hpadder AYL14(oy[7],oy[8],ol1y[4]);

hpadder AYL15(oy[9],oy[10],ol1y[5]);
hpadder AYL16(oy[11],oy[12],ol1y[6]);

hpadder AYL17(oy[13],oy[14],ol1y[7]);
hpadder AYL18(oy[15],oy[16],ol1y[8]);

//level 3 4 adders
hpadder AYL21(ol1y[1],ol1y[2],ol2y[1]);
hpadder AYL22(ol1y[3],ol1y[4],ol2y[2]);
hpadder AYL23(ol1y[5],ol1y[6],ol2y[3]);
hpadder AYL24(ol1y[7],ol1y[8],ol2y[4]);

//level 3
hpadder AYL31(ol2y[1],ol2y[2],ol3y[1]);
hpadder AYL32(ol2y[3],ol2y[4],ol3y[2]);

//level 4

hpadder AYL4(ol3y[1],ol3y[2],sum_y);

//centriod is calculated

centroid_cal C1(sum_x,sum_y,x_cen,y_cen);

//eculdian distance calculation

dis_diff D11(x_cen,y_cen,nx_cen,ny_cen);

hpadder dx1(X[1],nx_cen,x_dif[1]);
multiplier_hp16 mx1(x_dif[1],x_dif[1],x_dis[1]);
hpadder dy1(Y[1],ny_cen,y_dif[1]);
multiplier_hp16 my1(y_dif[1],y_dif[1],y_dis[1]);

hpadder xy1(x_dis[1],y_dis[1],dis_sum[1]);
square_root_hp16 dis1(dis_sum[1],distance[1]);

hpadder dx2(X[2],nx_cen,x_dif[2]);
multiplier_hp16 mx2(x_dif[2],x_dif[2],x_dis[2]);
hpadder dy2(Y[2],ny_cen,y_dif[2]);
multiplier_hp16 my2(y_dif[2],y_dif[2],y_dis[2]);
hpadder xy2(x_dis[2],y_dis[2],dis_sum[2]);
square_root_hp16 dis2(dis_sum[2],distance[2]);

hpadder dx3(X[3],nx_cen,x_dif[3]);
multiplier_hp16 mx3(x_dif[3],x_dif[3],x_dis[3]);
hpadder dy3(Y[3],ny_cen,y_dif[3]);
multiplier_hp16 my3(y_dif[3],y_dif[3],y_dis[3]);
hpadder xy3(x_dis[3],y_dis[3],dis_sum[3]);
square_root_hp16 dis3(dis_sum[3],distance[3]);

hpadder dx4(X[4],nx_cen,x_dif[4]);
multiplier_hp16 mx4(x_dif[4],x_dif[4],x_dis[4]);
hpadder dy4(Y[4],ny_cen,y_dif[4]);
multiplier_hp16 my4(y_dif[4],y_dif[4],y_dis[4]);
hpadder xy4(x_dis[4],y_dis[4],dis_sum[4]);
square_root_hp16 dis4(dis_sum[4], distance[4]);

hpadder dx5(X[5],nx_cen,x_dif[5]);
multiplier_hp16 mx5(x_dif[5],x_dif[5],x_dis[5]);
hpadder dy5(Y[5],ny_cen,y_dif[5]);
multiplier_hp16 my5(y_dif[5],y_dif[5],y_dis[5]);
hpadder xy5(x_dis[5],y_dis[5],dis_sum[5]);
square_root_hp16 dis5(dis_sum[5],distance[5]);

hpadder dx6(X[6],nx_cen,x_dif[6]);
multiplier_hp16 mx6(x_dif[6],x_dif[6],x_dis[6]);
hpadder dy6(Y[6],ny_cen,y_dif[6]);
multiplier_hp16 my6(y_dif[6],y_dif[6],y_dis[6]);
hpadder xy6(x_dis[6],y_dis[6],dis_sum[6]);
square_root_hp16 dis6(dis_sum[6],distance[6]);

hpadder dx7(X[7],nx_cen,x_dif[7]);
multiplier_hp16 mx7(x_dif[7],x_dif[7],x_dis[7]);
hpadder dy7(Y[7],ny_cen,y_dif[7]);
multiplier_hp16 my7(y_dif[7],y_dif[7],y_dis[7]);
hpadder xy7(x_dis[7],y_dis[7],dis_sum[7]);
square_root_hp16 dis7(dis_sum[7],distance[7]);

hpadder dx8(X[8],nx_cen,x_dif[8]);
multiplier_hp16 mx8(x_dif[8],x_dif[8],x_dis[8]);
hpadder dy8(Y[8],ny_cen,y_dif[8]);
multiplier_hp16 my8(y_dif[8],y_dif[8],y_dis[8]);
hpadder xy8(x_dis[8],y_dis[8],dis_sum[8]);
square_root_hp16 dis8(dis_sum[8],distance[8]);

hpadder dx9(X[9],nx_cen,x_dif[9]);
multiplier_hp16 mx9(x_dif[9],x_dif[9],x_dis[9]);
hpadder dy9(Y[9],ny_cen,y_dif[9]);
multiplier_hp16 my9(y_dif[9],y_dif[9],y_dis[9]);
hpadder xy9(x_dis[9],y_dis[9],dis_sum[9]);
square_root_hp16 dis9(dis_sum[9],distance[9]);

hpadder dx10(X[10],nx_cen,x_dif[10]);
multiplier_hp16 mx10(x_dif[10],x_dif[10],x_dis[10]);
hpadder dy10(Y[10],ny_cen,y_dif[10]);
multiplier_hp16 my10(y_dif[10],y_dif[10],y_dis[10]);
hpadder xy10(x_dis[10],y_dis[10],dis_sum[10]);
square_root_hp16 dis10(dis_sum[10],distance[10]);

hpadder dx11(X[11],nx_cen,x_dif[11]);
multiplier_hp16 mx11(x_dif[11],x_dif[11],x_dis[11]);
hpadder dy11(Y[11],ny_cen,y_dif[11]);
multiplier_hp16 my11(y_dif[11],y_dif[11],y_dis[11]);
hpadder xy11(x_dis[11],y_dis[11],dis_sum[11]);
square_root_hp16 dis11(dis_sum[11],distance[11]);

hpadder dx12(X[12],nx_cen,x_dif[12]);
multiplier_hp16 mx12(x_dif[12],x_dif[12],x_dis[12]);
hpadder dy12(Y[12],ny_cen,y_dif[12]);
multiplier_hp16 my12(y_dif[12],y_dif[12],y_dis[12]);
hpadder xy12(x_dis[12],y_dis[12],dis_sum[12]);
square_root_hp16 dis12(dis_sum[12],distance[12]);

hpadder dx13(X[13],nx_cen,x_dif[13]);
multiplier_hp16 mx13(x_dif[13],x_dif[13],x_dis[13]);
hpadder dy13(Y[13],ny_cen,y_dif[13]);
multiplier_hp16 my13(y_dif[13],y_dif[13],y_dis[13]);
hpadder xy13(x_dis[13],y_dis[13],dis_sum[13]);
square_root_hp16 dis13(dis_sum[13],distance[13]);

hpadder dx14(X[14],nx_cen,x_dif[14]);
multiplier_hp16 mx14(x_dif[14],x_dif[14],x_dis[14]);
hpadder dy14(Y[14],ny_cen,y_dif[14]);
multiplier_hp16 my14(y_dif[14],y_dif[14],y_dis[14]);
hpadder xy14(x_dis[14],y_dis[14],dis_sum[14]);
square_root_hp16 dis14(dis_sum[14],distance[14]);

hpadder dx15(X[15],nx_cen,x_dif[15]);
multiplier_hp16 mx15(x_dif[15],x_dif[15],x_dis[15]);
hpadder dy15(Y[15],ny_cen,y_dif[15]);
multiplier_hp16 my15(y_dif[15],y_dif[15],y_dis[15]);
hpadder xy15(x_dis[15],y_dis[15],dis_sum[15]);
square_root_hp16 dis15(dis_sum[15],distance[15]);

hpadder dx16(X[16],nx_cen,x_dif[16]);
multiplier_hp16 mx16(x_dif[16],x_dif[16],x_dis[16]);
hpadder dy16(Y[16],ny_cen,y_dif[16]);
multiplier_hp16 my16(y_dif[16],y_dif[16],y_dis[16]);
hpadder xy16(x_dis[16],y_dis[16],dis_sum[16]);
square_root_hp16 dis16(dis_sum[16],distance[16]);

hpadder dx17(X[17],nx_cen,x_dif[17]);
multiplier_hp16 mx17(x_dif[17],x_dif[17],x_dis[17]);
hpadder dy17(Y[17],ny_cen,y_dif[17]);
multiplier_hp16 my17(y_dif[17],y_dif[17],y_dis[17]);
hpadder xy17(x_dis[17],y_dis[17],dis_sum[17]);
square_root_hp16 dis17(dis_sum[17],distance[17]);

hpadder dx18(X[18],nx_cen,x_dif[18]);
multiplier_hp16 mx18(x_dif[18],x_dif[18],x_dis[18]);
hpadder dy18(Y[18],ny_cen,y_dif[18]);
multiplier_hp16 my18(y_dif[18],y_dif[18],y_dis[18]);
hpadder xy18(x_dis[18],y_dis[18],dis_sum[18]);
square_root_hp16 dis18(dis_sum[18],distance[18]);

hpadder dx19(X[19],nx_cen,x_dif[19]);
multiplier_hp16 mx19(x_dif[19],x_dif[19],x_dis[19]);
hpadder dy19(Y[19],ny_cen,y_dif[19]);
multiplier_hp16 my19(y_dif[19],y_dif[19],y_dis[19]);
hpadder xy19(x_dis[19],y_dis[19],dis_sum[19]);
square_root_hp16 dis19(dis_sum[19],distance[19]);

hpadder dx20(X[20],nx_cen,x_dif[20]);
multiplier_hp16 mx20(x_dif[20],x_dif[20],x_dis[20]);
hpadder dy20(Y[20],ny_cen,y_dif[20]);
multiplier_hp16 my20(y_dif[20],y_dif[20],y_dis[20]);
hpadder xy20(x_dis[20],y_dis[20],dis_sum[20]);
square_root_hp16 dis20(dis_sum[20],distance[20]);

hpadder dx21(X[21],nx_cen,x_dif[21]);
multiplier_hp16 mx21(x_dif[21],x_dif[21],x_dis[21]);
hpadder dy21(Y[21],ny_cen,y_dif[21]);
multiplier_hp16 my21(y_dif[21],y_dif[21],y_dis[21]);
hpadder xy21(x_dis[21],y_dis[21],dis_sum[21]);
square_root_hp16 dis21(dis_sum[21],distance[21]);

hpadder dx22(X[22],nx_cen,x_dif[22]);
multiplier_hp16 mx22(x_dif[22],x_dif[22],x_dis[22]);
hpadder dy22(Y[22],ny_cen,y_dif[22]);
multiplier_hp16 my22(y_dif[22],y_dif[22],y_dis[22]);
hpadder xy22(x_dis[22],y_dis[22],dis_sum[22]);
square_root_hp16 dis22(dis_sum[22],distance[22]);

hpadder dx23(X[23],nx_cen,x_dif[23]);
multiplier_hp16 mx23(x_dif[23],x_dif[23],x_dis[23]);
hpadder dy23(Y[23],ny_cen,y_dif[23]);
multiplier_hp16 my23(y_dif[23],y_dif[23],y_dis[23]);
hpadder xy23(x_dis[23],y_dis[23],dis_sum[23]);
square_root_hp16 dis23(dis_sum[23],distance[23]);

hpadder dx24(X[24],nx_cen,x_dif[24]);
multiplier_hp16 mx24(x_dif[24],x_dif[24],x_dis[24]);
hpadder dy24(Y[24],ny_cen,y_dif[24]);
multiplier_hp16 my24(y_dif[24],y_dif[24],y_dis[24]);
hpadder xy24(x_dis[24],y_dis[24],dis_sum[24]);
square_root_hp16 dis24(dis_sum[24],distance[24]);

hpadder dx25(X[25],nx_cen,x_dif[25]);
multiplier_hp16 mx25(x_dif[25],x_dif[25],x_dis[25]);
hpadder dy25(Y[25],ny_cen,y_dif[25]);
multiplier_hp16 my25(y_dif[25],y_dif[25],y_dis[25]);
hpadder xy25(x_dis[25],y_dis[25],dis_sum[25]);
square_root_hp16 dis25(dis_sum[25],distance[25]);

hpadder dx26(X[26],nx_cen,x_dif[26]);
multiplier_hp16 mx26(x_dif[26],x_dif[26],x_dis[26]);
hpadder dy26(Y[26],ny_cen,y_dif[26]);
multiplier_hp16 my26(y_dif[26],y_dif[26],y_dis[26]);
hpadder xy26(x_dis[26],y_dis[26],dis_sum[26]);
square_root_hp16 dis26(dis_sum[26],distance[26]);

hpadder dx27(X[27],nx_cen,x_dif[27]);
multiplier_hp16 mx27(x_dif[27],x_dif[27],x_dis[27]);
hpadder dy27(Y[27],ny_cen,y_dif[27]);
multiplier_hp16 my27(y_dif[27],y_dif[27],y_dis[27]);
hpadder xy27(x_dis[27],y_dis[27],dis_sum[27]);
square_root_hp16 dis27(dis_sum[27],distance[27]);

hpadder dx28(X[28],nx_cen,x_dif[28]);
multiplier_hp16 mx28(x_dif[28],x_dif[28],x_dis[28]);
hpadder dy28(Y[28],ny_cen,y_dif[28]);
multiplier_hp16 my28(y_dif[28],y_dif[28],y_dis[28]);
hpadder xy28(x_dis[28],y_dis[28],dis_sum[28]);
square_root_hp16 dis28(dis_sum[28],distance[28]);

hpadder dx29(X[29],nx_cen,x_dif[29]);
multiplier_hp16 mx29(x_dif[29],x_dif[29],x_dis[29]);
hpadder dy29(Y[29],ny_cen,y_dif[29]);
multiplier_hp16 my29(y_dif[29],y_dif[29],y_dis[29]);
hpadder xy29(x_dis[29],y_dis[29],dis_sum[29]);
square_root_hp16 dis29(dis_sum[29],distance[29]);

hpadder dx30(X[30],nx_cen,x_dif[30]);
multiplier_hp16 mx30(x_dif[30],x_dif[30],x_dis[30]);
hpadder dy30(Y[30],ny_cen,y_dif[30]);
multiplier_hp16 my30(y_dif[30],y_dif[30],y_dis[30]);
hpadder xy30(x_dis[30],y_dis[30],dis_sum[30]);
square_root_hp16 dis30(dis_sum[30],distance[30]);

hpadder dx31(X[31],nx_cen,x_dif[31]);
multiplier_hp16 mx31(x_dif[31],x_dif[31],x_dis[31]);
hpadder dy31(Y[31],ny_cen,y_dif[31]);
multiplier_hp16 my31(y_dif[31],y_dif[31],y_dis[31]);
hpadder xy31(x_dis[31],y_dis[31],dis_sum[31]);
square_root_hp16 dis31(dis_sum[31],distance[31]);

hpadder dx32(X[32],nx_cen,x_dif[32]);
multiplier_hp16 mx32(x_dif[32],x_dif[32],x_dis[32]);
hpadder dy32(Y[32],ny_cen,y_dif[32]);
multiplier_hp16 my32(y_dif[32],y_dif[32],y_dis[32]);
hpadder xy32(x_dis[32],y_dis[32],dis_sum[32]);
square_root_hp16 dis32(dis_sum[32],distance[32]);

always@(*) begin
//$writememh("E:/Lab - Sem 1/Lab - RC/Assignment_1/test.txt",mem);
$writememh("D:/data_RC_out.txt",mem);
end

endmodule

module control_unit_fsm(clk,reset,start,ld);
input clk,reset,start;
reg [5:0] state;
reg stop;
output reg [31:0]ld;
parameter
[5:0]A0=6'b000000,A1=6'b000001,A2=6'b000010,A3=6'b000011,A4=6'b000100,A5=6'b000101,A6=6'b
000110,A7=6'b000111,A8=6'b001000,A9=6'b001001,A10=6'b001010,A11=6'b001011,A12=6'b001100,
A13=6'b001101,A14=6'b001110,A15=6'b001111,
A16=6'b010000,A17=6'b010001,A18=6'b010010,A19=6'b010011,A20=6'b010100,A21=6'b010101,A22=
6'b010110,A23=6'b010111,A24=6'b011000,A25=6'b011001,A26=6'b011010,A27=6'b011011,A28=6'b0
11100,A29=6'b011101,A30=6'b011110,A31=6'b011111,
A32=6'b100000, A33=6'b100001, A34=6'b100010, A35=6'b100011, A36=6'b100100, A37=6'b100101,
A38=6'b100110, A39=6'b100111, A40=6'b101000, A41=6'b101001, A42=6'b101010, A43=6'b101011,
A44=6'b101100, A45=6'b101101, A46=6'b101110, A47=6'b101111, A48=6'b110000, A49=6'b110001,
A50=6'b110010, A51=6'b110011, A52=6'b110100, A53=6'b110101, A54=6'b110110, A55=6'b110111,
A56=6'b111000, A57=6'b111001, A58=6'b111010, A59=6'b111011, A60=6'b111100, A61=6'b111101,
A62=6'b111110, A63=6'b111111;

always@(posedge clk)
begin
stop<=1'b1;
case(state)

A0: if(start&&stop) state<=A1;


A1: state<= A2;
A2: state<=A3;
A3: state<=A4;
A4: state<=A5;
A5: state<= A6;
A6: state<=A7;
A7: state<=A8;
A8: state<=A9;
A9: state<= A10;
A10: state<=A11;
A11: state<=A12;
A12: state<=A13;
A13: state<=A14;
A14: state<=A15;
A15: state<= A16;
A16: state<=A17;
A17: state<=A18;
A18: state<=A19;
A19: state<= A20;
A20: state<=A21;
A21: state<=A22;
A22: state<=A23;
A23: state<= A24;
A24: state<=A25;
A25: state<=A26;
A26: state<=A27;
A27: state<= A28;
A28: state<=A29;
A29: state<=A30;
A30: state<=A31;
A31: state<=A32;
A32: state<=A33;
/*A32: state<=A33;
A33: state<= A34;
A34: state<=A35;
A35: state<=A36;
A36: state<=A37;
*/
default: state<=A0;
endcase
end

always@(state)
begin

case(state)
A0:ld=32'b0000_0000_0000_0000_0000_0000_0000_0000;

A1:begin
ld=32'b0000_0000_0000_0000_0000_0000_0000_0001;
end

A2: begin
ld=32'b0000_0000_0000_0000_0000_0000_0000_0010;
end

A3: begin
ld=32'b0000_0000_0000_0000_0000_0000_0000_0100;
end

A4: begin
ld=32'b0000_0000_0000_0000_0000_0000_0000_1000;
end

A5: begin
ld=32'b0000_0000_0000_0000_0000_0000_0001_0000;
end

A6: begin
ld=32'b0000_0000_0000_0000_0000_0000_0010_0000;
end

A7: begin
ld=32'b0000_0000_0000_0000_0000_0000_0100_0000;
end

A8: begin
ld=32'b0000_0000_0000_0000_0000_0000_1000_0000;
end

A9: begin
ld=32'b0000_0000_0000_0000_0000_0001_0000_0000;
end

A10: begin
ld=32'b0000_0000_0000_0000_0000_0010_0000_0000;
end

A11: begin
ld=32'b0000_0000_0000_0000_0000_0100_0000_0000;
end

A12: begin
ld=32'b0000_0000_0000_0000_0000_1000_0000_0000;
end

A13: begin
ld=32'b0000_0000_0000_0000_0001_0000_0000_0000;
end

A14: begin
ld=32'b0000_0000_0000_0000_0010_0000_0000_0000;
end

A15: begin
ld=32'b0000_0000_0000_0000_0100_0000_0000_0000;
end

A16: begin
ld=32'b0000_0000_0000_0000_1000_0000_0000_0000;
end

A17: begin
ld=32'b0000_0000_0000_0001_0000_0000_0000_0000;
end

A18: begin
ld=32'b0000_0000_0000_0010_0000_0000_0000_0000;
end

A19: begin
ld=32'b0000_0000_0000_0100_0000_0000_0000_0000;
end

A20: begin
ld=32'b0000_0000_0000_1000_0000_0000_0000_0000;
end

A21: begin
ld=32'b0000_0000_0001_0000_0000_0000_0000_0000;
end

A22: begin
ld=32'b0000_0000_0010_0000_0000_0000_0000_0000;
end

A23: begin
ld=32'b0000_0000_0100_0000_0000_0000_0000_0000;
end

A24: begin
ld=32'b0000_0000_1000_0000_0000_0000_0000_0000;
end

A25: begin
ld=32'b0000_0001_0000_0000_0000_0000_0000_0000;
end

A26: begin
ld=32'b0000_0010_0000_0000_0000_0000_0000_0000;
end

A27: begin
ld=32'b0000_0100_0000_0000_0000_0000_0000_0000;
end

A28: begin
ld=32'b0000_1000_0000_0000_0000_0000_0000_0000;
end

A29: begin
ld=32'b0001_0000_0000_0000_0000_0000_0000_0000;
end

A30: begin
ld=32'b0010_0000_0000_0000_0000_0000_0000_0000;
end

A31: begin
ld=32'b0100_0000_0000_0000_0000_0000_0000_0000;
end
A32: begin
ld=32'b1000_0000_0000_0000_0000_0000_0000_0000;
end
A33: begin
stop=1'b0;
end

endcase
end

endmodule
CONTROL SCHEMATIC :

DATAPATH+CONTROL BLOCK :
Final waveform with all the intermediate results :
DISCUSSION

S. No. Module Behavioural Synthesizable


Simulation
1. adder_hp16 yes yes
2. multiplier_hp16 yes yes
3. comparator_hp16 yes yes
4. Square_root_hp16 yes yes
5. sorting(top module) yes yes

You might also like