Pārlūkot izejas kodu

Merge branch 'master' into Oliver_FPA

# Conflicts:
#	src/FPA_module_test.sv
Oliver Jaison 4 gadi atpakaļ
vecāks
revīzija
7a13726de3
1 mainītis faili ar 50 papildinājumiem un 76 dzēšanām
  1. 50 76
      src/FPA_module_test.sv

+ 50 - 76
src/FPA_module_test.sv

@@ -1,6 +1,5 @@
-module floating_add #(parameter N=16, M=4)(input_1, input_2, sum, diff, clk, reset);
+module floating_add #(parameter N=16, M=4)(input_1, input_2, sum, diff);
 	input logic [N-1:0] input_1, input_2;
-	input logic clk, reset;
 	output logic [N-1:0] sum;
 	output logic [M:0] diff;
 
@@ -9,145 +8,120 @@ module floating_add #(parameter N=16, M=4)(input_1, input_2, sum, diff, clk, res
 	logic [M:0] abs;
 	logic [N-3-M:0] res;
 	
-	logic [N-1:0] D0 [7:0];
-	logic [N-1:0] Q0 [7:0];
-	logic [N-1:0] Q1 [7:0];
-	logic [N-1:0] Q2 [7:0];
-	
 	// sign_x = x[N-1]
 	// exponent_x = x[N-2:N-2-M]
 	// mantissa_x = x[N-3-M:0]
 	
-	//First pipeline stage
-	always_comb
-		begin
-			D0[0] = input_1;
-			D0[1] = input_2;
-			D0[2] = 0; // sum
-			D0[3] = 0; // diff
-			D0[4] = 0; // flag_a
-			D0[5] = 0; // flag_b
-			D0[6] = 0; // abs
-			D0[7] = 0; // res
-		end
-	pipe pipe0(.clk(clk), .reset(reset), .D(D0), .Q(Q0));
-	
-	
 	always_comb
 		begin
-			if (Q0[0][N-2:N-2-M] > Q0[1][N-2:N-2-M]) // If input 1 has the bigger exponent 
+			if (input_1[N-2:N-2-M] > input_2[N-2:N-2-M]) // If input 1 has the bigger exponent 
 				begin
 					// Flags input a as larger and calculates the absolute difference
-					Q0[4] = 1;
-					Q0[5] = 0;
-					Q0[6] = Q0[0][N-2:N-2-M] - Q0[1][N-2:N-2-M];
+					flag_a = 1;
+					flag_b = 0;
+					abs = input_1[N-2:N-2-M] - input_2[N-2:N-2-M];
 					// ASsigning overall sign of the output
-					Q0[2][N-1] = Q0[0][N-1];
+					sum[N-1] = input_1[N-1];
 					// Sets output to have the same exponent
-					Q0[2][N-2:N-2-M] = Q0[0][N-2:N-2-M];
+					sum[N-2:N-2-M] = input_1[N-2:N-2-M];
 				end
-			else if (Q0[1][N-2:N-2-M] > Q0[0][N-2:N-2-M]) // If input 2 has the bigger exponent
+			else if (input_2[N-2:N-2-M] > input_1[N-2:N-2-M]) // If input 2 has the bigger exponent
 				begin
 					// Similarly flags input b as larger and calculates the absolute difference
-					Q0[4] = 0;
-					Q0[5] = 1;
-					Q0[6] = Q0[1][N-2:N-2-M] - Q0[0][N-2:N-2-M];
+					flag_a = 0;
+					flag_b = 1;
+					abs = input_2[N-2:N-2-M] - input_1[N-2:N-2-M];
 					// ASsigning overall sign of the output
-					Q0[2][N-1] = Q0[1][N-1];
+					sum[N-1] = input_2[N-1];
 					// Sets ouput to have the same exponent
-					Q0[2][N-2:N-2-M] = Q0[1][N-2:N-2-M];
+					sum[N-2:N-2-M] = input_2[N-2:N-2-M];
 				end
 			else 
 				begin
 					// THe condition that both inputs have the same exponent
-					Q0[4] = 1;
-					Q0[5] = 1;
-					Q0[6] = 0;
+					flag_a = 1;
+					flag_b = 1;
+					abs = 0;
 					// ASsigning overall sign of the output based on size of the mantissa
-					if (Q0[0][N-3-M:0] >= Q0[1][N-3-M:0]) Q0[2][N-1] = Q0[0][N-1];
-					else Q0[2][N-1] = Q0[1][N-1];
-					Q0[2][N-2:N-2-M] = Q0[0][N-2:N-2-M];
+					if (input_1[N-3-M:0] >= input_2[N-3-M:0]) sum[N-1] = input_1[N-1];
+					else sum[N-1] = input_2[N-1];
+					sum[N-2:N-2-M] = input_1[N-2:N-2-M];
 				end
-			Q0[3] = Q0[6];
+			diff = abs;
 		end
-		
+
 		//Second pipeline stage 1
-		pipe pipe0(.clk(clk), .reset(reset), .D(Q0), .Q(Q1));
-		
+		pipe pipe1(.clk(clk), .reset(reset), .D(Q0), .Q(Q1));
+
 	always_comb
 		begin
 			// Condition for overflow is that it sets the output to the larger input
-			if (Q1[6] > N-2-M) // Because size of mantissa is 10 bits and shifting by 10 would give 0
+			if (abs > 9) // Because size of mantissa is 10 bits and shifting by 10 would give 0
 				begin
-					if (Q1[4] & ~Q1[5]) Q1[2] = Q1[0]; // input 1 is larger and is translated to output
-					else if (~Q1[4] & Q1[5]) Q1[2] = Q1[1]; // input 2 is larger and is translated to output
+					if (flag_a & ~flag_b) sum = input_1; // input 1 is larger and is translated to output
+					else if (~flag_a & flag_b) sum = input_2; // input 2 is larger and is translated to output
 					else // exponents are the same
 						begin
-							if (Q1[6][N-3-M:0] >= Q1[1][N-3-M:0]) Q1[2] = Q1[0];// input 1 has the bigger mantissa
-							else Q1[2] = Q1[1]; // input 2 has the bigger mantissa
+							if (input_1[N-3-M:0] >= input_2[N-3-M:0]) sum = input_1;// input 1 has the bigger mantissa
+							else sum = input_2; // input 2 has the bigger mantissa
 						end
 				end
 			else
 				begin
 					// Shifts the smaller input's mantissa to the right based on abs
-					if (Q1[4] & ~Q1[5])// If input 1 has the larger exponent
+					if (flag_a & ~flag_b)// If input 1 has the larger exponent
 						begin
 							// If the signs of both inputs are the same you add, otherwise you subtract
-							if (Q1[0][N-1] == Q1[1][N-1])
+							if (input_1[N-1] == input_2[N-1])
 								begin
-									Q1[7] = Q1[0][N-3-M:0] + (Q1[1][N-3-M:0] >> Q1[6]-1); // Sum the mantissa
-									Q1[2][N-3-M:0] = Q1[7];
+									res = input_1[N-3-M:0] + (input_2[N-3-M:0] >> abs-1); // Sum the mantissa
+									sum[N-3-M:0] = res;
 								end
 							else
 								begin
-									Q1[7] = Q1[0][N-3-M:0] - (Q1[1][N-3-M:0] >> Q1[6]-1); // Subtract the mantissas
+									res = input_1[N-3-M:0] - (input_2[N-3-M:0] >> abs-1); // Subtract the mantissas
 									sum[N-3-M:0] = res;
 								end
 						end
-					else if (~Q1[4] & Q1[5])
+					else if (~flag_a & flag_b)
 						begin
 							// If the signs of both inputs are the same you add, otherwise you subtract
-							if (Q1[0][N-1] == Q1[1][N-1])
+							if (input_1[N-1] == input_2[N-1])
 								begin
-									Q1[7] = (Q1[0][N-3-M:0] >> Q1[6]-1) + Q1[1][N-3-M:0]; // Sum the mantissa
-									Q1[2][N-3-M:0] = Q1[7];
+									res = (input_1[N-3-M:0] >> abs-1) + input_2[N-3-M:0]; // Sum the mantissa
+									sum[N-3-M:0] = res;
 								end
 							else
 								begin
-									Q1[7] = Q1[1][N-3-M:0] - (Q1[0][N-3-M:0] >> Q1[6]-1); // Subtract the mantissas
-									Q1[2][N-3-M:0] = Q1[7];
+									res = input_2[N-3-M:0] - (input_1[N-3-M:0] >> abs-1); // Subtract the mantissas
+									sum[N-3-M:0] = res;
 								end
 						end
 					else
 						begin 
-							if (Q1[0][N-1] == Q1[1][N-1]) // If exponents and signs equal
+							if (input_1[N-1] == input_2[N-1]) // If exponents and signs equal
 								begin
-									Q1[7] = Q1[0][N-3-M:0] + Q1[1][N-3-M:0]; // Sum the mantissa
-									Q1[2][N-3-M:0] = Q1[7];
+									res = input_1[N-3-M:0] + input_2[N-3-M:0]; // Sum the mantissa
+									sum[N-3-M:0] = res;
 								end
 							else // In this case it will be a subtraction
 								begin
-									if (Q1[0][N-3-M:0] > Q1[1][N-3-M:0]) // Which has the larger mantissa 
+									if (input_1[N-3-M:0] > input_2[N-3-M:0]) // Which has the larger mantissa 
 										begin
-											Q1[7] = Q1[0][N-3-M:0] - Q1[1][N-3-M:0]; // Subtract the mantissa
-											Q1[2][N-3-M:0] = Q1[7];
+											res = input_1[N-3-M:0] - input_2[N-3-M:0]; // Subtract the mantissa
+											sum[N-3-M:0] = res;
 										end
-									else if (Q1[0][N-3-M:0] < Q1[1][N-3-M:0])
+									else if (input_1[N-3-M:0] < input_2[N-3-M:0])
 										begin
-											Q1[7] = Q1[1][N-3-M:0] - Q1[0][N-3-M:0]; // Subtract the mantissa
-											Q1[2][N-3-M:0] = Q1[7];
+											res = input_2[N-3-M:0] - input_1[N-3-M:0]; // Subtract the mantissa
+											sum[N-3-M:0] = res;
 										end
-									else Q1[7] = 0; // Both the exponent and the mantissa are equal so subtraction leads to 0
-									Q1[2][N-3-M:0] = Q1[7];
+									else res = 0; // Both the exponent and the mantissa are equal so subtraction leads to 0
+									sum[N-3-M:0] = res;
 								end
 						end
 				end
 		end
-		
-		// Final pipeline stage 
-		pipe pipe2(.clk(clk), .reset(reset), .D(Q1), .Q(Q2));
-		assign sum = Q2[2];
-		assign diff = Q2[3];
 endmodule : floating_add