code
stringlengths
35
6.69k
score
float64
6.5
11.5
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_mux_42_1_1_1 #( parameter ID = 0, NUM_STAGE = 1, din0_WIDTH = 32, din1_WIDTH = 32, din2_WIDTH = 32, din3_WIDTH = 32, din4_WIDTH = 32, dout_WIDTH = 32 ) ( input [0 : 0] din0, input [0 : 0] din1, input [0 : 0] din2, input [0 : 0] din3, input [1 : 0] din4, output [0 : 0] dout ); // puts internal signals wire [1 : 0] sel; // level 1 signals wire [0 : 0] mux_1_0; wire [0 : 0] mux_1_1; // level 2 signals wire [0 : 0] mux_2_0; assign sel = din4; // Generate level 1 logic assign mux_1_0 = (sel[0] == 0) ? din0 : din1; assign mux_1_1 = (sel[0] == 0) ? din2 : din3; // Generate level 2 logic assign mux_2_0 = (sel[1] == 0) ? mux_1_0 : mux_1_1; // output logic assign dout = mux_2_0; endmodule
6.827284
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_mux_42_1_1_1 #( parameter ID = 0, NUM_STAGE = 1, din0_WIDTH = 32, din1_WIDTH = 32, din2_WIDTH = 32, din3_WIDTH = 32, din4_WIDTH = 32, dout_WIDTH = 32 ) ( input [0 : 0] din0, input [0 : 0] din1, input [0 : 0] din2, input [0 : 0] din3, input [1 : 0] din4, output [0 : 0] dout ); // puts internal signals wire [1 : 0] sel; // level 1 signals wire [0 : 0] mux_1_0; wire [0 : 0] mux_1_1; // level 2 signals wire [0 : 0] mux_2_0; assign sel = din4; // Generate level 1 logic assign mux_1_0 = (sel[0] == 0) ? din0 : din1; assign mux_1_1 = (sel[0] == 0) ? din2 : din3; // Generate level 2 logic assign mux_2_0 = (sel[1] == 0) ? mux_1_0 : mux_1_1; // output logic assign dout = mux_2_0; endmodule
6.827284
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_mux_42_1_1_1 #( parameter ID = 0, NUM_STAGE = 1, din0_WIDTH = 32, din1_WIDTH = 32, din2_WIDTH = 32, din3_WIDTH = 32, din4_WIDTH = 32, dout_WIDTH = 32 ) ( input [0 : 0] din0, input [0 : 0] din1, input [0 : 0] din2, input [0 : 0] din3, input [1 : 0] din4, output [0 : 0] dout ); // puts internal signals wire [1 : 0] sel; // level 1 signals wire [0 : 0] mux_1_0; wire [0 : 0] mux_1_1; // level 2 signals wire [0 : 0] mux_2_0; assign sel = din4; // Generate level 1 logic assign mux_1_0 = (sel[0] == 0) ? din0 : din1; assign mux_1_1 = (sel[0] == 0) ? din2 : din3; // Generate level 2 logic assign mux_2_0 = (sel[1] == 0) ? mux_1_0 : mux_1_1; // output logic assign dout = mux_2_0; endmodule
6.827284
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_hadd_16ns_16ns_16_8_full_dsp_1 #( parameter ID = 45, NUM_STAGE = 8, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_6_full_dsp_16 td_fused_top_ap_hadd_6_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_6_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792
module FPAddSub_AlignShift2 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [1:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal Signal reg [ `MANTISSA:0] Lvl3; wire [2*`MANTISSA+1:0] Stage2; integer j; // Loop variable assign Stage2 = {11'b0, MminP}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl3 <= Stage2[`MANTISSA:0]; // Rotate by 1 2'b01: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+1]; end /*Lvl3[`MANTISSA] <= 0; */ end // Rotate by 2 2'b10: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+2]; end /*Lvl3[`MANTISSA:`MANTISSA-1] <= 0;*/ end // Rotate by 3 2'b11: begin for (j = 0; j <= `MANTISSA; j = j + 1) begin Lvl3[j] <= Stage2[j+3]; end /*Lvl3[`MANTISSA:`MANTISSA-2] <= 0;*/ end endcase end // Assign output assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.969233
module FPAddSub_AlignShift1 ( MminP, Shift, Mmin ); // Input ports input [`MANTISSA-1:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [2:0] Shift; // Shift amount // Output ports output [`MANTISSA:0] Mmin; // The smaller mantissa // Internal signals reg [ `MANTISSA:0] Lvl1; reg [ `MANTISSA:0] Lvl2; wire [2*`MANTISSA+1:0] Stage1; integer i; // Loop variable always @(*) begin // Rotate by 16? //Lvl1 <= Shift[2] ? {17'b00000000000000001, MminP[22:16]} : {1'b1, MminP}; Lvl1 <= Shift[2] ? {11'b0000000000} : {1'b1, MminP}; end assign Stage1 = {11'b0, Lvl1}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[1:0]) // Rotate by 0 2'b00: Lvl2 <= Stage1[`MANTISSA:0]; // Rotate by 4 2'b01: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+4]; end /*Lvl2[`MANTISSA:`MANTISSA-3] <= 0;*/ end // Rotate by 8 2'b10: begin for (i = 0; i <= `MANTISSA; i = i + 1) begin Lvl2[i] <= Stage1[i+8]; end /*Lvl2[`MANTISSA:`MANTISSA-7] <= 0;*/ end // Rotate by 12 2'b11: Lvl2[`MANTISSA:0] <= 0; //2'b11: begin for (i=0; i<=`MANTISSA; i=i+1) begin Lvl2[i] <= Stage1[i+12]; end Lvl2[`MANTISSA:`MANTISSA-12] <= 0; end endcase end // Assign output to next shift stage assign Mmin = Lvl2; endmodule
6.969233
module FPAddSub_AlignModule ( A, B, ShiftDet, CExp, MaxAB, Shift, Mmin, Mmax ); // Input ports input [`DWIDTH-2:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-2:0] B; // Input B, a 32-bit floating point number input [9:0] ShiftDet; // Output ports output [`EXPONENT-1:0] CExp; // Common Exponent output MaxAB; // Incidates larger of A and B (0/A, 1/B) output [4:0] Shift; // Number of steps to smaller mantissa shift right output [`MANTISSA-1:0] Mmin; // Smaller mantissa output [`MANTISSA-1:0] Mmax; // Larger mantissa // Internal signals //wire BOF ; // Check for shifting overflow if B is larger //wire AOF ; // Check for shifting overflow if A is larger assign MaxAB = (A[`DWIDTH-2:0] < B[`DWIDTH-2:0]); //assign BOF = ShiftDet[9:5] < 25 ; // Cannot shift more than 25 bits //assign AOF = ShiftDet[4:0] < 25 ; // Cannot shift more than 25 bits // Determine final shift value //assign Shift = MaxAB ? (BOF ? ShiftDet[9:5] : 5'b11001) : (AOF ? ShiftDet[4:0] : 5'b11001) ; assign Shift = MaxAB ? ShiftDet[9:5] : ShiftDet[4:0]; // Take out smaller mantissa and append shift space assign Mmin = MaxAB ? A[`MANTISSA-1:0] : B[`MANTISSA-1:0]; // Take out larger mantissa assign Mmax = MaxAB ? B[`MANTISSA-1:0] : A[`MANTISSA-1:0]; // Common exponent assign CExp = (MaxAB ? B[`MANTISSA+`EXPONENT-1:`MANTISSA] : A[`MANTISSA+`EXPONENT-1:`MANTISSA]); endmodule
6.969233
module FPAddSub_PrealignModule ( A, B, operation, Sa, Sb, ShiftDet, InputExc, Aout, Bout, Opout ); // Input ports input [`DWIDTH-1:0] A; // Input A, a 32-bit floating point number input [`DWIDTH-1:0] B; // Input B, a 32-bit floating point number input operation; // Output ports output Sa; // A's sign output Sb; // B's sign output [9:0] ShiftDet; output [4:0] InputExc; // Input numbers are exceptions output [`DWIDTH-2:0] Aout; output [`DWIDTH-2:0] Bout; output Opout; // Internal signals // If signal is high... wire ANaN; // A is a NaN (Not-a-Number) wire BNaN; // B is a NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`EXPONENT-1:0] DAB; // ExpA - ExpB wire [`EXPONENT-1:0] DBA; // ExpB - ExpA assign ANaN = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(A[`MANTISSA-1:0]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & |(B[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(A[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(A[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(B[`DWIDTH-2:`DWIDTH-1-`EXPONENT]) & ~|(B[`MANTISSA-1:0]) ; // All one exponent and all zero mantissa - Infinity // Put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign DAB = (A[30:23] - B[30:23]) ; //assign DBA = (B[30:23] - A[30:23]) ; assign DAB = (A[`DWIDTH-2:`MANTISSA] + ~(B[`DWIDTH-2:`MANTISSA]) + 1); assign DBA = (B[`DWIDTH-2:`MANTISSA] + ~(A[`DWIDTH-2:`MANTISSA]) + 1); assign Sa = A[`DWIDTH-1]; // A's sign bit assign Sb = B[`DWIDTH-1]; // B's sign bit assign ShiftDet = {DBA[4:0], DAB[4:0]}; // Shift data assign Opout = operation; assign Aout = A[`DWIDTH-2:0]; assign Bout = B[`DWIDTH-2:0]; endmodule
7.069212
module td_fused_top_hadd_16ns_16ns_16_5_full_dsp_1 #( parameter ID = 25, NUM_STAGE = 5, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 16 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, output wire [dout_WIDTH-1:0] dout ); //------------------------Local signal------------------- wire aclk; wire aclken; wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire r_tvalid; wire [ 15:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hadd_3_full_dsp_16 td_fused_top_ap_hadd_3_full_dsp_16_u ( .aclk (aclk), .aclken (aclken), .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .m_axis_result_tvalid(r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign aclk = clk; assign aclken = ce_r; assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign dout_i = r_tdata; always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; end end always @(posedge clk) begin ce_r <= ce; end always @(posedge clk) begin if (ce_r) begin dout_r <= dout_i; end end assign dout = ce_r ? dout_i : dout_r; endmodule
6.827284
module td_fused_top_ap_hadd_3_full_dsp_16 ( input wire aclk, input wire aclken, input wire s_axis_a_tvalid, input wire [15:0] s_axis_a_tdata, input wire s_axis_b_tvalid, input wire [15:0] s_axis_b_tdata, output wire m_axis_result_tvalid, output wire [15:0] m_axis_result_tdata ); reg [15:0] a_reg, b_reg, res, res_reg; always @(posedge aclk) begin if (aclken) begin a_reg <= s_axis_a_tdata; b_reg <= s_axis_b_tdata; res_reg <= res; end end `ifdef complex_dsp adder_fp u_add_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPAddSub u_FPAddSub ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .operation(1'b0), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPAddSub_ExceptionModule ( Z, NegE, R, S, InputExc, EOF, P, Flags ); // Input ports input [`DWIDTH-1:0] Z; // Final product input NegE; // Negative exponent? input R; // Round bit input S; // Sticky bit input [4:0] InputExc; // Exceptions in inputs A and B input EOF; // Output ports output [`DWIDTH-1:0] P; // Final result output [4:0] Flags; // Exception flags // Internal signals wire Overflow; // Overflow flag wire Underflow; // Underflow flag wire DivideByZero; // Divide-by-Zero flag (always 0 in Add/Sub) wire Invalid; // Invalid inputs or result wire Inexact; // Result is inexact because of rounding // Exception flags // Result is too big to be represented assign Overflow = EOF | InputExc[1] | InputExc[0]; // Result is too small to be represented assign Underflow = NegE & (R | S); // Infinite result computed exactly from finite operands assign DivideByZero = &(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~|(Z[`MANTISSA+`EXPONENT-1:`MANTISSA]) & ~InputExc[1] & ~InputExc[0]; // Invalid inputs or operation assign Invalid = |(InputExc[4:2]); // Inexact answer due to rounding, overflow or underflow assign Inexact = (R | S) | Overflow | Underflow; // Put pieces together to form final result assign P = Z; // Collect exception flags assign Flags = {Overflow, Underflow, DivideByZero, Invalid, Inexact}; endmodule
7.326377
module FPAddSub_RoundModule ( ZeroSum, NormE, NormM, R, S, G, Sa, Sb, Ctrl, MaxAB, Z, EOF ); // Input ports input ZeroSum; // Sum is zero input [`EXPONENT:0] NormE; // Normalized exponent input [`MANTISSA-1:0] NormM; // Normalized mantissa input R; // Round bit input S; // Sticky bit input G; input Sa; // A's sign bit input Sb; // B's sign bit input Ctrl; // Control bit (operation) input MaxAB; // Output ports output [`DWIDTH-1:0] Z; // Final result output EOF; // Internal signals wire [ `MANTISSA:0] RoundUpM; // Rounded up sum with room for overflow wire [`MANTISSA-1:0] RoundM; // The final rounded sum wire [ `EXPONENT:0] RoundE; // Rounded exponent (note extra bit due to poential overflow ) wire RoundUp; // Flag indicating that the sum should be rounded up wire FSgn; wire ExpAdd; // May have to add 1 to compensate for overflow wire RoundOF; // Rounding overflow // The cases where we need to round upwards (= adding one) in Round to nearest, tie to even assign RoundUp = (G & ((R | S) | NormM[0])); // Note that in the other cases (rounding down), the sum is already 'rounded' assign RoundUpM = (NormM + 1); // The sum, rounded up by 1 assign RoundM = (RoundUp ? RoundUpM[`MANTISSA-1:0] : NormM); // Compute final mantissa assign RoundOF = RoundUp & RoundUpM[`MANTISSA]; // Check for overflow when rounding up // Calculate post-rounding exponent assign ExpAdd = (RoundOF ? 1'b1 : 1'b0); // Add 1 to exponent to compensate for overflow assign RoundE = ZeroSum ? 5'b00000 : (NormE + ExpAdd); // Final exponent // If zero, need to determine sign according to rounding assign FSgn = (ZeroSum & (Sa ^ Sb)) | (ZeroSum ? (Sa & Sb & ~Ctrl) : ((~MaxAB & Sa) | ((Ctrl ^ Sb) & (MaxAB | Sa)))) ; // Assign final result assign Z = {FSgn, RoundE[`EXPONENT-1:0], RoundM[`MANTISSA-1:0]}; // Indicate exponent overflow assign EOF = RoundE[`EXPONENT]; endmodule
7.753919
module FPAddSub_NormalizeShift2 ( PSSum, CExp, Shift, NormM, NormE, ZeroSum, NegE, R, S, FG ); // Input ports input [`DWIDTH:0] PSSum; // The Pre-Shift-Sum input [`EXPONENT-1:0] CExp; input [4:0] Shift; // Amount to be shifted // Output ports output [`MANTISSA-1:0] NormM; // Normalized mantissa output [`EXPONENT:0] NormE; // Adjusted exponent output ZeroSum; // Zero flag output NegE; // Flag indicating negative exponent output R; // Round bit output S; // Final sticky bit output FG; // Internal signals wire MSBShift; // Flag indicating that a second shift is needed wire [`EXPONENT:0] ExpOF; // MSB set in sum indicates overflow wire [`EXPONENT:0] ExpOK; // MSB not set, no adjustment // Calculate normalized exponent and mantissa, check for all-zero sum assign MSBShift = PSSum[`DWIDTH]; // Check MSB in unnormalized sum assign ZeroSum = ~|PSSum; // Check for all zero sum assign ExpOK = CExp - Shift; // Adjust exponent for new normalized mantissa assign NegE = ExpOK[`EXPONENT]; // Check for exponent overflow assign ExpOF = CExp - Shift + 1'b1; // If MSB set, add one to exponent(x2) assign NormE = MSBShift ? ExpOF : ExpOK; // Check for exponent overflow assign NormM = PSSum[`DWIDTH-1:`EXPONENT+1]; // The new, normalized mantissa // Also need to compute sticky and round bits for the rounding stage assign FG = PSSum[`EXPONENT]; assign R = PSSum[`EXPONENT-1]; assign S = |PSSum[`EXPONENT-2:0]; endmodule
6.905513
module FPAddSub_NormalizeShift1 ( MminP, Shift, Mmin ); // Input ports input [`DWIDTH:0] MminP; // Smaller mantissa after 16|12|8|4 shift input [3:0] Shift; // Shift amount // Output ports output [`DWIDTH:0] Mmin; // The smaller mantissa reg [ `DWIDTH:0] Lvl2; wire [2*`DWIDTH+1:0] Stage1; reg [ `DWIDTH:0] Lvl3; wire [2*`DWIDTH+1:0] Stage2; integer i; // Loop variable assign Stage1 = {MminP, MminP}; always @(*) begin // Rotate {0 | 4 | 8 | 12} bits case (Shift[3:2]) // Rotate by 0 2'b00: //Lvl2 <= Stage1[`DWIDTH:0]; begin Lvl2 = Stage1[`DWIDTH:0]; end // Rotate by 4 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-4]; end Lvl2[3:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-4)] = Stage1[3:0]; Lvl2[`DWIDTH-4-1:0] = Stage1[`DWIDTH-4]; end // Rotate by 8 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-8]; end Lvl2[7:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-8)] = Stage1[3:0]; Lvl2[`DWIDTH-8-1:0] = Stage1[`DWIDTH-8]; end // Rotate by 12 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl2[i-33] <= Stage1[i-12]; end Lvl2[11:0] <= 0; end begin Lvl2[`DWIDTH:(`DWIDTH-12)] = Stage1[3:0]; Lvl2[`DWIDTH-12-1:0] = Stage1[`DWIDTH-12]; end endcase end assign Stage2 = {Lvl2, Lvl2}; always @(*) begin // Rotate {0 | 1 | 2 | 3} bits case (Shift[1:0]) // Rotate by 0 2'b00: //Lvl3 <= Stage2[`DWIDTH:0]; begin Lvl3 = Stage2[`DWIDTH:0]; end // Rotate by 1 2'b01: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-1]; end Lvl3[0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-1)] = Stage2[3:0]; Lvl3[`DWIDTH-1-1:0] = Stage2[`DWIDTH-1]; end // Rotate by 2 2'b10: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-2]; end Lvl3[1:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-2)] = Stage2[3:0]; Lvl3[`DWIDTH-2-1:0] = Stage2[`DWIDTH-2]; end // Rotate by 3 2'b11: //begin for (i=2*`DWIDTH+1; i>=`DWIDTH+1; i=i-1) begin Lvl3[i-`DWIDTH-1] <= Stage2[i-3]; end Lvl3[2:0] <= 0; end begin Lvl3[`DWIDTH:(`DWIDTH-3)] = Stage2[3:0]; Lvl3[`DWIDTH-3-1:0] = Stage2[`DWIDTH-3]; end endcase end // Assign outputs assign Mmin = Lvl3; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_NormalizeModule ( Sum, Mmin, Shift ); // Input ports input [`DWIDTH:0] Sum; // Mantissa sum including hidden 1 and GRS // Output ports output [`DWIDTH:0] Mmin; // Mantissa after 16|0 shift output [4:0] Shift; // Shift amount // Determine normalization shift amount by finding leading nought assign Shift = ( Sum[16] ? 5'b00000 : Sum[15] ? 5'b00001 : Sum[14] ? 5'b00010 : Sum[13] ? 5'b00011 : Sum[12] ? 5'b00100 : Sum[11] ? 5'b00101 : Sum[10] ? 5'b00110 : Sum[9] ? 5'b00111 : Sum[8] ? 5'b01000 : Sum[7] ? 5'b01001 : Sum[6] ? 5'b01010 : Sum[5] ? 5'b01011 : Sum[4] ? 5'b01100 : 5'b01101 // Sum[19] ? 5'b01101 : // Sum[18] ? 5'b01110 : // Sum[17] ? 5'b01111 : // Sum[16] ? 5'b10000 : // Sum[15] ? 5'b10001 : // Sum[14] ? 5'b10010 : // Sum[13] ? 5'b10011 : // Sum[12] ? 5'b10100 : // Sum[11] ? 5'b10101 : // Sum[10] ? 5'b10110 : // Sum[9] ? 5'b10111 : // Sum[8] ? 5'b11000 : // Sum[7] ? 5'b11001 : 5'b11010 ); reg [`DWIDTH:0] Lvl1; always @(*) begin // Rotate by 16? Lvl1 <= Shift[4] ? {Sum[8:0], 8'b00000000} : Sum; end // Assign outputs assign Mmin = Lvl1; // Take out smaller mantissa endmodule
6.905513
module FPAddSub_ExecutionModule ( Mmax, Mmin, Sa, Sb, MaxAB, OpMode, Sum, PSgn, Opr ); // Input ports input [`MANTISSA-1:0] Mmax; // The larger mantissa input [`MANTISSA:0] Mmin; // The smaller mantissa input Sa; // Sign bit of larger number input Sb; // Sign bit of smaller number input MaxAB; // Indicates the larger number (0/A, 1/B) input OpMode; // Operation to be performed (0/Add, 1/Sub) // Output ports output [`DWIDTH:0] Sum; // The result of the operation output PSgn; // The sign for the result output Opr; // The effective (performed) operation assign Opr = (OpMode ^ Sa ^ Sb); // Resolve sign to determine operation // Perform effective operation assign Sum = (OpMode^Sa^Sb) ? ({1'b1, Mmax, 5'b00000} - {Mmin, 5'b00000}) : ({1'b1, Mmax, 5'b00000} + {Mmin, 5'b00000}) ; // Assign result sign assign PSgn = (MaxAB ? Sb : Sa); endmodule
6.632792