module NV_NVDLA_SDP_HLS_X_int_alu (
   alu_data_in //|< i
  ,alu_in_pvld //|< i
  ,alu_op_pvld //|< i
  ,alu_out_prdy //|< i
  ,cfg_alu_algo //|< i
  ,cfg_alu_bypass //|< i
  ,cfg_alu_op //|< i
  ,cfg_alu_shift_value //|< i
  ,cfg_alu_src //|< i
  ,chn_alu_op //|< i
  ,nvdla_core_clk //|< i
  ,nvdla_core_rstn //|< i
  ,alu_data_out //|> o
  ,alu_in_prdy //|> o
  ,alu_op_prdy //|> o
  ,alu_out_pvld //|> o
  );
input [31:0] alu_data_in;
input alu_in_pvld;
input alu_op_pvld;
input alu_out_prdy;
input [1:0] cfg_alu_algo;
input cfg_alu_bypass;
input [15:0] cfg_alu_op;
input [5:0] cfg_alu_shift_value;
input cfg_alu_src;
input [15:0] chn_alu_op;
input nvdla_core_clk;
input nvdla_core_rstn;
output [32:0] alu_data_out;
output alu_in_prdy;
output alu_op_prdy;
output alu_out_pvld;
wire [32:0] alu_sum;
reg [32:0] alu_dout;
wire mon_sum_c;
wire [32:0] alu_data_ext;
wire [32:0] alu_data_final;
wire [31:0] alu_data_reg;
wire [31:0] alu_data_sync;
wire alu_final_prdy;
wire alu_final_pvld;
wire alu_in_srdy;
wire [15:0] alu_op_in;
wire [31:0] alu_op_shift;
wire [15:0] alu_op_sync;
wire alu_shift_prdy;
wire alu_shift_pvld;
wire alu_sync_prdy;
wire alu_sync_pvld;
wire [32:0] operand_ext;
wire [31:0] operand_shift;
NV_NVDLA_SDP_HLS_sync2data #(.DATA1_WIDTH(16 ),.DATA2_WIDTH(32 )) x_alu_sync2data (
   .chn1_en (cfg_alu_src & !cfg_alu_bypass) //|< ?
  ,.chn2_en (!cfg_alu_bypass) //|< i
  ,.chn1_in_pvld (alu_op_pvld) //|< i
  ,.chn1_in_prdy (alu_op_prdy) //|> o
  ,.chn2_in_pvld (alu_in_pvld) //|< i
  ,.chn2_in_prdy (alu_in_srdy) //|> w
  ,.chn_out_pvld (alu_sync_pvld) //|> w
  ,.chn_out_prdy (alu_sync_prdy) //|< w
  ,.data1_in (chn_alu_op[15:0]) //|< i
  ,.data2_in (alu_data_in[31:0]) //|< i
  ,.data1_out (alu_op_sync[15:0]) //|> w
  ,.data2_out (alu_data_sync[31:0]) //|> w
  );
assign alu_op_in[15:0] = cfg_alu_src ? alu_op_sync[15:0] : cfg_alu_op[15:0];
NV_NVDLA_HLS_shiftleftsu #(.IN_WIDTH(16 ),.OUT_WIDTH(32 ),.SHIFT_WIDTH(6)) x_alu_shiftleft_su (
   .data_in (alu_op_in[15:0]) //|< w
  ,.shift_num (cfg_alu_shift_value[5:0]) //|< i
  ,.data_out (alu_op_shift[31:0]) //|> w
  );
//signed
//unsiged
NV_NVDLA_SDP_HLS_X_INT_ALU_pipe_p1 pipe_p1 (
   .nvdla_core_clk (nvdla_core_clk) //|< i
  ,.nvdla_core_rstn (nvdla_core_rstn) //|< i
  ,.alu_data_sync (alu_data_sync[31:0]) //|< w
  ,.alu_op_shift (alu_op_shift[31:0]) //|< w
  ,.alu_shift_prdy (alu_shift_prdy) //|< w
  ,.alu_sync_pvld (alu_sync_pvld) //|< w
  ,.alu_data_reg (alu_data_reg[31:0]) //|> w
  ,.alu_shift_pvld (alu_shift_pvld) //|> w
  ,.alu_sync_prdy (alu_sync_prdy) //|> w
  ,.operand_shift (operand_shift[31:0]) //|> w
  );
assign operand_ext[32:0] = {{1{operand_shift[31]}}, operand_shift[31:0]};
assign alu_data_ext[32:0] = {{1{alu_data_reg[31]}}, alu_data_reg[31:0]};
assign {mon_sum_c,alu_sum[32:0]} = $signed(alu_data_ext) + $signed(operand_ext);
always @(
  cfg_alu_algo
  or alu_data_ext
  or operand_ext
  or alu_sum
  ) begin
 if (cfg_alu_algo[1:0]== 0 )
     alu_dout[32:0] = ($signed(alu_data_ext) > $signed(operand_ext)) ? alu_data_ext : operand_ext;
 else if (cfg_alu_algo[1:0]== 1 )
     alu_dout[32:0] = ($signed(alu_data_ext) < $signed(operand_ext)) ? alu_data_ext : operand_ext;
 else
     alu_dout[32:0] = alu_sum[32:0];
end
NV_NVDLA_SDP_HLS_X_INT_ALU_pipe_p2 pipe_p2 (
   .nvdla_core_clk (nvdla_core_clk) //|< i
  ,.nvdla_core_rstn (nvdla_core_rstn) //|< i
  ,.alu_dout (alu_dout[32:0]) //|< r
  ,.alu_final_prdy (alu_final_prdy) //|< w
  ,.alu_shift_pvld (alu_shift_pvld) //|< w
  ,.alu_data_final (alu_data_final[32:0]) //|> w
  ,.alu_final_pvld (alu_final_pvld) //|> w
  ,.alu_shift_prdy (alu_shift_prdy) //|> w
  );
assign alu_in_prdy = cfg_alu_bypass ? alu_out_prdy : alu_in_srdy;
assign alu_final_prdy = cfg_alu_bypass ? 1'b1 : alu_out_prdy;
assign alu_out_pvld = cfg_alu_bypass ? alu_in_pvld : alu_final_pvld;
assign alu_data_out[32:0] = cfg_alu_bypass ? {{1{alu_data_in[31]}}, alu_data_in[31:0]} : alu_data_final[32:0];
endmodule // NV_NVDLA_SDP_HLS_X_int_alu