如下代码,累加运算非常占资源,请教如何优化
// Data_acc.v
module Data_acc(Gd,Data_ch,Sin_index,Mul,Reset_n);
input Gd,Reset_n;
input [5:0] Sin_index;
input [27:0] Mul;
output [17:0] Data_ch;
reg [17:0] Data_ch;
reg [22:0] ACC;
reg [22:0] ACC_tem;
always@(posedge Gd or negedge Reset_n)
if(!Reset_n)
begin
ACC <=0;
ACC_tem <=0;
Data_ch <=0;
end
else
begin
if(Sin_index == 0)
begin
if(ACC_tem > ACC)
begin
Data_ch <= ( ACC_tem - ACC ) >>4'd5;
end
else
begin
Data_ch <= ( ACC- ACC_tem ) >>4'd5;
end
ACC <= {5'd0,Mul[27:10]};
end
else if( (Sin_index < 6'd32) && (Sin_index > 6'd0) )
ACC <= ACC + {5'd0,Mul[27:10]};
else if(Sin_index == 6'd32)
begin
ACC_tem <= ACC;
ACC <= {5'd0,Mul[27:10]};
end
else if( (Sin_index <= 6'd63) && (Sin_index > 6'd32))
ACC <= ACC + {5'd0,Mul[27:10]};
else
begin
ACC <= 0;
end
end
endmodule
|