code
stringlengths
35
6.69k
score
float64
6.5
11.5
module td_fused_top_hmul_16ns_16ns_16_4_max_dsp_1 #( parameter ID = 20, NUM_STAGE = 4, 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_hmul_2_max_dsp_16 td_fused_top_ap_hmul_2_max_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_hmul_2_max_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 multiply_fp u_mult_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPMult_16 u_FPMult ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPMult_RoundModule ( RoundM, RoundMP, RoundE, RoundEP, Sp, GRS, InputExc, Z, Flags ); // Input Ports input [`MANTISSA:0] RoundM; // Normalized mantissa input [`MANTISSA:0] RoundMP; // Normalized exponent input [`EXPONENT:0] RoundE; // Normalized mantissa + 1 input [`EXPONENT:0] RoundEP; // Normalized exponent + 1 input Sp; // Product sign input GRS; input [4:0] InputExc; // Output Ports output [`DWIDTH-1:0] Z; // Final product output [4:0] Flags; // Internal Signals wire [`EXPONENT:0] FinalE; // Rounded exponent wire [`MANTISSA:0] FinalM; wire [`MANTISSA:0] PreShiftM; assign PreShiftM = GRS ? RoundMP : RoundM; // Round up if R and (G or S) // Post rounding normalization (potential one bit shift> use shifted mantissa if there is overflow) assign FinalM = (PreShiftM[`MANTISSA] ? {1'b0, PreShiftM[`MANTISSA:1]} : PreShiftM[`MANTISSA:0]); assign FinalE = (PreShiftM[`MANTISSA] ? RoundEP : RoundE) ; // Increment exponent if a shift was done assign Z = {Sp, FinalE[`EXPONENT-1:0], FinalM[`MANTISSA-1:0]}; // Putting the pieces together assign Flags = InputExc[4:0]; endmodule
7.570448
module FPMult_NormalizeModule ( NormM, NormE, RoundE, RoundEP, RoundM, RoundMP ); // Input Ports input [`MANTISSA-1:0] NormM; // Normalized mantissa input [`EXPONENT:0] NormE; // Normalized exponent // Output Ports output [`EXPONENT:0] RoundE; output [`EXPONENT:0] RoundEP; output [`MANTISSA:0] RoundM; output [`MANTISSA:0] RoundMP; assign RoundE = NormE - 15; assign RoundEP = NormE - 14; assign RoundM = NormM; assign RoundMP = NormM; endmodule
7.947312
module FPMult_PrepModule ( clk, rst, a, b, Sa, Sb, Ea, Eb, Mp, InputExc ); // Input ports input clk; input rst; 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 // Output ports output Sa; // A's sign output Sb; // B's sign output [`EXPONENT-1:0] Ea; // A's exponent output [`EXPONENT-1:0] Eb; // B's exponent output [2*`MANTISSA+1:0] Mp; // Mantissa product output [4:0] InputExc; // Input numbers are exceptions // Internal signals // If signal is high... wire ANaN; // A is a signalling NaN wire BNaN; // B is a signalling NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`MANTISSA-1:0] Ma; wire [`MANTISSA-1:0] Mb; assign ANaN = &(a[`DWIDTH-2:`MANTISSA]) & |(a[`DWIDTH-2:`MANTISSA]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(b[`DWIDTH-2:`MANTISSA]) & |(b[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(a[`DWIDTH-2:`MANTISSA]) & ~|(a[`DWIDTH-2:`MANTISSA]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(b[`DWIDTH-2:`MANTISSA]) & ~|(b[`DWIDTH-2:`MANTISSA]) ; // All one exponent and all zero mantissa - Infinity // Check for any exceptions and put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign InputExc = {(ANaN | ANaN | BNaN |BNaN), ANaN, ANaN, BNaN,BNaN} ; // Take input numbers apart assign Sa = a[`DWIDTH-1]; // A's sign assign Sb = b[`DWIDTH-1]; // B's sign assign Ea = a[`DWIDTH-2:`MANTISSA]; // Store A's exponent in Ea, unless A is an exception assign Eb = b[`DWIDTH-2:`MANTISSA]; // Store B's exponent in Eb, unless B is an exception // assign Ma = a[`MANTISSA_MSB:`MANTISSA_LSB]; // assign Mb = b[`MANTISSA_MSB:`MANTISSA_LSB]; //assign Mp = ({4'b0001, a[`MANTISSA-1:0]}*{4'b0001, b[`MANTISSA-1:9]}) ; assign Mp = ({1'b1, a[`MANTISSA-1:0]} * {1'b1, b[`MANTISSA-1:0]}); //We multiply part of the mantissa here //Full mantissa of A //Bits MANTISSA_MUL_SPLIT_MSB:MANTISSA_MUL_SPLIT_LSB of B // wire [`ACTUAL_MANTISSA-1:0] inp_A; // wire [`ACTUAL_MANTISSA-1:0] inp_B; // assign inp_A = {1'b1, Ma}; // assign inp_B = {{(`MANTISSA-(`MANTISSA_MUL_SPLIT_MSB-`MANTISSA_MUL_SPLIT_LSB+1)){1'b0}}, 1'b1, Mb[`MANTISSA_MUL_SPLIT_MSB:`MANTISSA_MUL_SPLIT_LSB]}; // DW02_mult #(`ACTUAL_MANTISSA,`ACTUAL_MANTISSA) u_mult(.A(inp_A), .B(inp_B), .TC(1'b0), .PRODUCT(Mp)); endmodule
7.427166
module td_fused_top_hsub_16ns_16ns_16_5_full_dsp_1 #( parameter ID = 37, 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------------------ // Just replace with the hadd, logic is similar enough. //td_fused_top_ap_hsub_3_full_dsp_16 td_fused_top_ap_hsub_3_full_dsp_16_u ( td_fused_top_ap_hadd_3_full_dsp_16 td_fused_top_ap_hsub_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 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
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
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_hmul_16ns_16ns_16_4_max_dsp_1 #( parameter ID = 20, NUM_STAGE = 4, 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_hmul_2_max_dsp_16 td_fused_top_ap_hmul_2_max_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_hmul_2_max_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 multiply_fp u_mult_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPMult_16 u_FPMult ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPMult_RoundModule ( RoundM, RoundMP, RoundE, RoundEP, Sp, GRS, InputExc, Z, Flags ); // Input Ports input [`MANTISSA:0] RoundM; // Normalized mantissa input [`MANTISSA:0] RoundMP; // Normalized exponent input [`EXPONENT:0] RoundE; // Normalized mantissa + 1 input [`EXPONENT:0] RoundEP; // Normalized exponent + 1 input Sp; // Product sign input GRS; input [4:0] InputExc; // Output Ports output [`DWIDTH-1:0] Z; // Final product output [4:0] Flags; // Internal Signals wire [`EXPONENT:0] FinalE; // Rounded exponent wire [`MANTISSA:0] FinalM; wire [`MANTISSA:0] PreShiftM; assign PreShiftM = GRS ? RoundMP : RoundM; // Round up if R and (G or S) // Post rounding normalization (potential one bit shift> use shifted mantissa if there is overflow) assign FinalM = (PreShiftM[`MANTISSA] ? {1'b0, PreShiftM[`MANTISSA:1]} : PreShiftM[`MANTISSA:0]); assign FinalE = (PreShiftM[`MANTISSA] ? RoundEP : RoundE) ; // Increment exponent if a shift was done assign Z = {Sp, FinalE[`EXPONENT-1:0], FinalM[`MANTISSA-1:0]}; // Putting the pieces together assign Flags = InputExc[4:0]; endmodule
7.570448
module FPMult_NormalizeModule ( NormM, NormE, RoundE, RoundEP, RoundM, RoundMP ); // Input Ports input [`MANTISSA-1:0] NormM; // Normalized mantissa input [`EXPONENT:0] NormE; // Normalized exponent // Output Ports output [`EXPONENT:0] RoundE; output [`EXPONENT:0] RoundEP; output [`MANTISSA:0] RoundM; output [`MANTISSA:0] RoundMP; assign RoundE = NormE - 15; assign RoundEP = NormE - 14; assign RoundM = NormM; assign RoundMP = NormM; endmodule
7.947312
module FPMult_PrepModule ( clk, rst, a, b, Sa, Sb, Ea, Eb, Mp, InputExc ); // Input ports input clk; input rst; 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 // Output ports output Sa; // A's sign output Sb; // B's sign output [`EXPONENT-1:0] Ea; // A's exponent output [`EXPONENT-1:0] Eb; // B's exponent output [2*`MANTISSA+1:0] Mp; // Mantissa product output [4:0] InputExc; // Input numbers are exceptions // Internal signals // If signal is high... wire ANaN; // A is a signalling NaN wire BNaN; // B is a signalling NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`MANTISSA-1:0] Ma; wire [`MANTISSA-1:0] Mb; assign ANaN = &(a[`DWIDTH-2:`MANTISSA]) & |(a[`DWIDTH-2:`MANTISSA]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(b[`DWIDTH-2:`MANTISSA]) & |(b[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(a[`DWIDTH-2:`MANTISSA]) & ~|(a[`DWIDTH-2:`MANTISSA]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(b[`DWIDTH-2:`MANTISSA]) & ~|(b[`DWIDTH-2:`MANTISSA]) ; // All one exponent and all zero mantissa - Infinity // Check for any exceptions and put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign InputExc = {(ANaN | ANaN | BNaN |BNaN), ANaN, ANaN, BNaN,BNaN} ; // Take input numbers apart assign Sa = a[`DWIDTH-1]; // A's sign assign Sb = b[`DWIDTH-1]; // B's sign assign Ea = a[`DWIDTH-2:`MANTISSA]; // Store A's exponent in Ea, unless A is an exception assign Eb = b[`DWIDTH-2:`MANTISSA]; // Store B's exponent in Eb, unless B is an exception // assign Ma = a[`MANTISSA_MSB:`MANTISSA_LSB]; // assign Mb = b[`MANTISSA_MSB:`MANTISSA_LSB]; //assign Mp = ({4'b0001, a[`MANTISSA-1:0]}*{4'b0001, b[`MANTISSA-1:9]}) ; assign Mp = ({1'b1, a[`MANTISSA-1:0]} * {1'b1, b[`MANTISSA-1:0]}); //We multiply part of the mantissa here //Full mantissa of A //Bits MANTISSA_MUL_SPLIT_MSB:MANTISSA_MUL_SPLIT_LSB of B // wire [`ACTUAL_MANTISSA-1:0] inp_A; // wire [`ACTUAL_MANTISSA-1:0] inp_B; // assign inp_A = {1'b1, Ma}; // assign inp_B = {{(`MANTISSA-(`MANTISSA_MUL_SPLIT_MSB-`MANTISSA_MUL_SPLIT_LSB+1)){1'b0}}, 1'b1, Mb[`MANTISSA_MUL_SPLIT_MSB:`MANTISSA_MUL_SPLIT_LSB]}; // DW02_mult #(`ACTUAL_MANTISSA,`ACTUAL_MANTISSA) u_mult(.A(inp_A), .B(inp_B), .TC(1'b0), .PRODUCT(Mp)); endmodule
7.427166
module td_fused_top_hsub_16ns_16ns_16_5_full_dsp_1 #( parameter ID = 37, 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------------------ // Just replace with the hadd, logic is similar enough. //td_fused_top_ap_hsub_3_full_dsp_16 td_fused_top_ap_hsub_3_full_dsp_16_u ( td_fused_top_ap_hadd_3_full_dsp_16 td_fused_top_ap_hsub_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
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_hmul_16ns_16ns_16_4_max_dsp_1 #( parameter ID = 20, NUM_STAGE = 4, 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_hmul_2_max_dsp_16 td_fused_top_ap_hmul_2_max_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_hmul_2_max_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 multiply_fp u_mult_fp ( .a (a_reg), .b (b_reg), .out(res) ); `else FPMult_16 u_FPMult ( .clk(), .rst(1'b0), .a(a_reg), .b(b_reg), .result(res), .flags() ); `endif assign m_axis_result_tdata = res_reg; endmodule
6.827284
module FPMult_RoundModule ( RoundM, RoundMP, RoundE, RoundEP, Sp, GRS, InputExc, Z, Flags ); // Input Ports input [`MANTISSA:0] RoundM; // Normalized mantissa input [`MANTISSA:0] RoundMP; // Normalized exponent input [`EXPONENT:0] RoundE; // Normalized mantissa + 1 input [`EXPONENT:0] RoundEP; // Normalized exponent + 1 input Sp; // Product sign input GRS; input [4:0] InputExc; // Output Ports output [`DWIDTH-1:0] Z; // Final product output [4:0] Flags; // Internal Signals wire [`EXPONENT:0] FinalE; // Rounded exponent wire [`MANTISSA:0] FinalM; wire [`MANTISSA:0] PreShiftM; assign PreShiftM = GRS ? RoundMP : RoundM; // Round up if R and (G or S) // Post rounding normalization (potential one bit shift> use shifted mantissa if there is overflow) assign FinalM = (PreShiftM[`MANTISSA] ? {1'b0, PreShiftM[`MANTISSA:1]} : PreShiftM[`MANTISSA:0]); assign FinalE = (PreShiftM[`MANTISSA] ? RoundEP : RoundE) ; // Increment exponent if a shift was done assign Z = {Sp, FinalE[`EXPONENT-1:0], FinalM[`MANTISSA-1:0]}; // Putting the pieces together assign Flags = InputExc[4:0]; endmodule
7.570448
module FPMult_NormalizeModule ( NormM, NormE, RoundE, RoundEP, RoundM, RoundMP ); // Input Ports input [`MANTISSA-1:0] NormM; // Normalized mantissa input [`EXPONENT:0] NormE; // Normalized exponent // Output Ports output [`EXPONENT:0] RoundE; output [`EXPONENT:0] RoundEP; output [`MANTISSA:0] RoundM; output [`MANTISSA:0] RoundMP; assign RoundE = NormE - 15; assign RoundEP = NormE - 14; assign RoundM = NormM; assign RoundMP = NormM; endmodule
7.947312
module FPMult_PrepModule ( clk, rst, a, b, Sa, Sb, Ea, Eb, Mp, InputExc ); // Input ports input clk; input rst; 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 // Output ports output Sa; // A's sign output Sb; // B's sign output [`EXPONENT-1:0] Ea; // A's exponent output [`EXPONENT-1:0] Eb; // B's exponent output [2*`MANTISSA+1:0] Mp; // Mantissa product output [4:0] InputExc; // Input numbers are exceptions // Internal signals // If signal is high... wire ANaN; // A is a signalling NaN wire BNaN; // B is a signalling NaN wire AInf; // A is infinity wire BInf; // B is infinity wire [`MANTISSA-1:0] Ma; wire [`MANTISSA-1:0] Mb; assign ANaN = &(a[`DWIDTH-2:`MANTISSA]) & |(a[`DWIDTH-2:`MANTISSA]) ; // All one exponent and not all zero mantissa - NaN assign BNaN = &(b[`DWIDTH-2:`MANTISSA]) & |(b[`MANTISSA-1:0]); // All one exponent and not all zero mantissa - NaN assign AInf = &(a[`DWIDTH-2:`MANTISSA]) & ~|(a[`DWIDTH-2:`MANTISSA]) ; // All one exponent and all zero mantissa - Infinity assign BInf = &(b[`DWIDTH-2:`MANTISSA]) & ~|(b[`DWIDTH-2:`MANTISSA]) ; // All one exponent and all zero mantissa - Infinity // Check for any exceptions and put all flags into exception vector assign InputExc = {(ANaN | BNaN | AInf | BInf), ANaN, BNaN, AInf, BInf}; //assign InputExc = {(ANaN | ANaN | BNaN |BNaN), ANaN, ANaN, BNaN,BNaN} ; // Take input numbers apart assign Sa = a[`DWIDTH-1]; // A's sign assign Sb = b[`DWIDTH-1]; // B's sign assign Ea = a[`DWIDTH-2:`MANTISSA]; // Store A's exponent in Ea, unless A is an exception assign Eb = b[`DWIDTH-2:`MANTISSA]; // Store B's exponent in Eb, unless B is an exception // assign Ma = a[`MANTISSA_MSB:`MANTISSA_LSB]; // assign Mb = b[`MANTISSA_MSB:`MANTISSA_LSB]; //assign Mp = ({4'b0001, a[`MANTISSA-1:0]}*{4'b0001, b[`MANTISSA-1:9]}) ; assign Mp = ({1'b1, a[`MANTISSA-1:0]} * {1'b1, b[`MANTISSA-1:0]}); //We multiply part of the mantissa here //Full mantissa of A //Bits MANTISSA_MUL_SPLIT_MSB:MANTISSA_MUL_SPLIT_LSB of B // wire [`ACTUAL_MANTISSA-1:0] inp_A; // wire [`ACTUAL_MANTISSA-1:0] inp_B; // assign inp_A = {1'b1, Ma}; // assign inp_B = {{(`MANTISSA-(`MANTISSA_MUL_SPLIT_MSB-`MANTISSA_MUL_SPLIT_LSB+1)){1'b0}}, 1'b1, Mb[`MANTISSA_MUL_SPLIT_MSB:`MANTISSA_MUL_SPLIT_LSB]}; // DW02_mult #(`ACTUAL_MANTISSA,`ACTUAL_MANTISSA) u_mult(.A(inp_A), .B(inp_B), .TC(1'b0), .PRODUCT(Mp)); endmodule
7.427166
module td_fused_top_tdf8_filters_0 ( reset, clk, address0, ce0, q0, address1, ce1, we1, d1 ); parameter DataWidth = 32'd32; parameter AddressRange = 32'd9216; parameter AddressWidth = 32'd14; input reset; input clk; input [AddressWidth - 1:0] address0; input ce0; output [DataWidth - 1:0] q0; input [AddressWidth - 1:0] address1; input ce1; input we1; input [DataWidth - 1:0] d1; td_fused_top_tdf8_filters_0_ram td_fused_top_tdf8_filters_0_ram_U ( .clk(clk), .addr0(address0), .ce0(ce0), .q0(q0), .addr1(address1), .ce1(ce1), .we1(we1), .d1(d1) ); endmodule
6.827284
module td_fused_top_tdf8_filters_0_ram ( addr0, ce0, q0, addr1, ce1, d1, we1, clk ); parameter DWIDTH = 32; parameter AWIDTH = 14; parameter MEM_SIZE = 9216; input [AWIDTH-1:0] addr0; input ce0; output reg [DWIDTH-1:0] q0; input [AWIDTH-1:0] addr1; input ce1; input [DWIDTH-1:0] d1; input we1; input clk; reg [DWIDTH-1:0] ram[MEM_SIZE-1:0]; always @(posedge clk) begin if (ce0) begin q0 <= ram[addr0]; end end always @(posedge clk) begin if (ce1) begin if (we1) ram[addr1] <= d1; end end endmodule
6.827284
module td_fused_top_tdf8_filters_0_ram ( addr0, ce0, q0, addr1, ce1, d1, we1, clk ); parameter DWIDTH = 32; parameter AWIDTH = 14; parameter MEM_SIZE = 9216; input [AWIDTH-1:0] addr0; input ce0; output reg [DWIDTH-1:0] q0; input [AWIDTH-1:0] addr1; input ce1; input [DWIDTH-1:0] d1; input we1; input clk; reg [DWIDTH-1:0] ram[MEM_SIZE-1:0]; always @(posedge clk) begin if (ce0) begin q0 <= ram[addr0]; end end always @(posedge clk) begin if (ce1) begin if (we1) ram[addr1] <= d1; end end endmodule
6.827284
module td_fused_top_tdf8_filters_1 ( reset, clk, address0, ce0, q0 ); parameter DataWidth = 32'd32; parameter AddressRange = 32'd9216; parameter AddressWidth = 32'd14; input reset; input clk; input [AddressWidth - 1:0] address0; input ce0; output [DataWidth - 1:0] q0; td_fused_top_tdf8_filters_1_rom td_fused_top_tdf8_filters_1_rom_U ( .clk(clk), .addr0(address0), .ce0(ce0), .q0(q0) ); endmodule
6.827284
module td_fused_top_tdf8_filters_1_rom ( addr0, ce0, q0, clk ); parameter DWIDTH = 32; parameter AWIDTH = 14; parameter MEM_SIZE = 9216; input [AWIDTH-1:0] addr0; input ce0; output reg [DWIDTH-1:0] q0; input clk; reg [DWIDTH-1:0] ram[MEM_SIZE-1:0]; //initial begin // $readmemh("./td_fused_top_tdf8_filters_1_rom.dat", ram); //end always @(posedge clk) begin if (ce0) begin q0 <= ram[addr0]; end end endmodule
6.827284
module td_fused_top_tdf8_filters_1_rom ( addr0, ce0, q0, clk ); parameter DWIDTH = 32; parameter AWIDTH = 14; parameter MEM_SIZE = 9216; input [AWIDTH-1:0] addr0; input ce0; output reg [DWIDTH-1:0] q0; input clk; reg [DWIDTH-1:0] ram[MEM_SIZE-1:0]; //initial begin // $readmemh("./td_fused_top_tdf8_filters_1_rom.dat", ram); //end always @(posedge clk) begin if (ce0) begin q0 <= ram[addr0]; end end endmodule
6.827284
module td_fused_top_hcmp_16ns_16ns_1_2_no_dsp_1 #( parameter ID = 47, NUM_STAGE = 2, din0_WIDTH = 16, din1_WIDTH = 16, dout_WIDTH = 1 ) ( input wire clk, input wire reset, input wire ce, input wire [din0_WIDTH-1:0] din0, input wire [din1_WIDTH-1:0] din1, input wire [ 4:0] opcode, output wire [dout_WIDTH-1:0] dout ); //------------------------Parameter---------------------- // AutoESL opcode localparam [4:0] AP_OEQ = 5'b00001, AP_OGT = 5'b00010, AP_OGE = 5'b00011, AP_OLT = 5'b00100, AP_OLE = 5'b00101, AP_ONE = 5'b00110, AP_UNO = 5'b01000; // FPV6 opcode localparam [7:0] OP_EQ = 8'b00010100, OP_GT = 8'b00100100, OP_GE = 8'b00110100, OP_LT = 8'b00001100, OP_LE = 8'b00011100, OP_NE = 8'b00101100, OP_UO = 8'b00000100; //------------------------Local signal------------------- wire a_tvalid; wire [ 15:0] a_tdata; wire b_tvalid; wire [ 15:0] b_tdata; wire op_tvalid; reg [ 7:0] op_tdata; wire r_tvalid; wire [ 7:0] r_tdata; reg [din0_WIDTH-1:0] din0_buf1; reg [din1_WIDTH-1:0] din1_buf1; reg [ 4:0] opcode_buf1; reg ce_r; wire [dout_WIDTH-1:0] dout_i; reg [dout_WIDTH-1:0] dout_r; //------------------------Instantiation------------------ td_fused_top_ap_hcmp_0_no_dsp_16 td_fused_top_ap_hcmp_0_no_dsp_16_u ( .s_axis_a_tvalid (a_tvalid), .s_axis_a_tdata (a_tdata), .s_axis_b_tvalid (b_tvalid), .s_axis_b_tdata (b_tdata), .s_axis_operation_tvalid(op_tvalid), .s_axis_operation_tdata (op_tdata), .m_axis_result_tvalid (r_tvalid), .m_axis_result_tdata (r_tdata) ); //------------------------Body--------------------------- assign a_tvalid = 1'b1; assign a_tdata = din0_buf1; assign b_tvalid = 1'b1; assign b_tdata = din1_buf1; assign op_tvalid = 1'b1; assign dout_i = r_tdata[0]; always @(*) begin case (opcode_buf1) AP_OEQ: op_tdata = OP_EQ; AP_OGT: op_tdata = OP_GT; AP_OGE: op_tdata = OP_GE; AP_OLT: op_tdata = OP_LT; AP_OLE: op_tdata = OP_LE; AP_ONE: op_tdata = OP_NE; AP_UNO: op_tdata = OP_UO; default: op_tdata = OP_EQ; endcase end always @(posedge clk) begin if (ce) begin din0_buf1 <= din0; din1_buf1 <= din1; opcode_buf1 <= opcode; 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_hcmp_0_no_dsp_16 ( 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, input wire s_axis_operation_tvalid, input wire [ 7:0] s_axis_operation_tdata, output wire m_axis_result_tvalid, output wire [ 7:0] m_axis_result_tdata ); // TEMP - compare module not yet ready // In the meantime, negate operand B, add them // together, and return the sign bit of the result. wire [15:0] b_negative; wire [15:0] result; assign b_negative = {~s_axis_b_tdata[15], s_axis_b_tdata[14:0]}; `ifdef complex_dsp adder_fp u_add_fp ( .a (s_axis_a_tdata), .b (b_negative), .out(result) ); `else FPAddSub u_FPAddSub_2 ( .clk(), .rst(1'b0), .a(s_axis_a_tdata), .b(b_negative), .operation(1'b0), .result(result), .flags() ); `endif assign m_axis_result_tdata = {7'b0, result[15]}; 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