如下代码,累加运算非常占资源,请教如何优化
// 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
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
不过还是有可优化的空间的。
优化前布线结果后的资源:FF 64 , LUT 103
优化后布线结果后的资源:FF 42 , LUT 70
我可以说优化了30%吗?:lol
附上代码。大家交流
module Data_acc_opt(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 [23:0] ACC;
always@(posedge Gd or negedge Reset_n)
if(!Reset_n)
begin
ACC <=0;
end
else
begin
if(Sin_index == 0)
begin
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'd63) && (Sin_index >= 6'd32))
ACC <= ACC - {5'd0,Mul[27:10]};
else
begin
ACC <= 0;
end
end
always@(posedge Gd or negedge Reset_n)
if(!Reset_n)
begin
Data_ch <=0;
end
else
begin
if(Sin_index == 0)
begin
if(ACC[23] == 1'b1)
begin
Data_ch <= (~ACC+ 1) >>4'd5;
end
else
begin
Data_ch <= ACC >>4'd5;
end
end
end
endmodule
顺便结贴送分哦
多谢:D
一周热门 更多>