Przeglądaj źródła

debugging fp16_tb

Oliver Jaison 4 lat temu
rodzic
commit
fab843dd47
1 zmienionych plików z 16 dodań i 16 usunięć
  1. 16 16
      src/fpu16/fp_adder.sv

+ 16 - 16
src/fpu16/fp_adder.sv

@@ -7,11 +7,10 @@ module fp_adder #(parameter N=16, M=5)(input_a, input_b, output_z, clk, reset);
 	reg [N-2-M:0] a_m1, b_m1; 
 	
 	reg [M-1:0] a_e, b_e, z_e, z_e1; // exponent
-	reg a_s, b_s, z_s, z_s1; // sign
+	reg a_s, b_s, a_s1, b_s1, z_s, z_s1; // sign
 	
 	reg [1:0] greater; // 01 for a, 10 for b, 11 for both and 00 for neither
 	reg [M:0] abs; // For the absolute difference between exponents
-	reg [N-2-M:0] res; // For the addition result
 	
 	always_ff @(posedge clk)
 	begin
@@ -27,7 +26,9 @@ module fp_adder #(parameter N=16, M=5)(input_a, input_b, output_z, clk, reset);
 			b_s <= input_b[N-1];
 			
 			a_m1 <= a_m;
+			a_s1 <= a_s;
 			b_m1 <= b_m;
+			b_s1 <= b_s;
 			
 			z_e1 <= z_e;
 			z_s1 <= z_s;
@@ -101,37 +102,37 @@ module fp_adder #(parameter N=16, M=5)(input_a, input_b, output_z, clk, reset);
 				if (greater == 2'b01)
 				begin
 					// If the signs are the same then add
-					if (a_s == b_s)
+					if (a_s1 == b_s1)
 					begin
-						res <= a_m1 + (b_m1 >> (abs-1));
+						z_m <= a_m1 + (b_m1 >> (abs-1));
 					end
 					// If they are different then subtract
 					else
 					begin
-						res <= a_m1 - (b_m1 >> (abs-1));
+						z_m <= a_m1 - (b_m1 >> (abs-1));
 					end
 				end
 				// If b has the bigger exponent
 				else if (greater == 2'b10)
 				begin
 				// If the signs are the same then add
-					if (a_s == b_s)
+					if (a_s1 == b_s1)
 					begin
-						res <= b_m1 + (a_m1 >> (abs-1));
+						z_m <= b_m1 + (a_m1 >> (abs-1));
 					end
 					// If they are different then subtract
 					else
 					begin
-						res <= b_m1 - (a_m1 >> (abs-1));
+						z_m <= b_m1 - (a_m1 >> (abs-1));
 					end
 				end
 				// If the exponents are equal
 				else
 				begin
 					// If the signs are the same then add
-					if (a_s == b_s)
+					if (a_s1 == b_s1)
 					begin
-						res <= a_m1 + b_m1;
+						z_m <= a_m1 + b_m1;
 					end
 					// If the signs are different then subtract
 					else
@@ -139,21 +140,19 @@ module fp_adder #(parameter N=16, M=5)(input_a, input_b, output_z, clk, reset);
 						// First checking which has the bigger mantissa
 						if (a_m1 > b_m1)
 						begin
-							res <= a_m1 - b_m1;
+							z_m <= a_m1 - b_m1;
 						end
 						else if (b_m1 > a_m1)
 						begin
-							res <= b_m1 - a_m1;
+							z_m <= b_m1 - a_m1;
 						end
 						// If the mantissa are the same as well then the result should be 0
 						else
 						begin
-							res <= 0;
+							z_m <= 0;
 						end
 					end
 				end
-				// Assigning the mantissa of output the the sum of input mantissa
-				z_m <= res;
 			end
 			output_z[N-1] <= z_s1;
 			output_z[N-2:N-1-M] <= z_e1;
@@ -178,11 +177,12 @@ module fp_adder #(parameter N=16, M=5)(input_a, input_b, output_z, clk, reset);
 			
 			z_s <= 0;
 			z_e <= 0;
+			z_s1 <= 0;
+			z_e1 <= 0;
 			z_m <= 0;
 			
 			greater <= 0;
 			abs <= 0;
-			res <= 0;
 			
 			output_z <= 0;
 		end