前言
使用DSP的方法一般有兩種:讓綜合器自己推斷、例化DSP原語。
有的時候為了偷懶或者有的計數器之類的需要跑高速,則可以讓計數器也使用DSP實現。
語法:(*use_dsp=“yes”*)
流程
1.編寫代碼測試,一個乘法器加一個cnt計數器,直接在模塊頭使用語法規則。
`timescale 1ns/1ps (*use_dsp = "yes"*)module mul_test ( input i_clk , input [17:0] i_mul_a , input [17:0] i_mul_b , output [35:0] o_mul_result, output [15:0] o_cnt ); reg [15:0] r_cnt = 'd0; always @(posedge i_clk) begin r_cnt <= r_cnt + 'd1; end assign o_cnt = r_cnt; reg [17:0] r_mul_a_delay_0 = 18'd0; reg [17:0] r_mul_a_delay_1 = 18'd0; reg [17:0] r_mul_b_delay_0 = 18'd0; reg [17:0] r_mul_b_delay_1 = 18'd0; reg [35:0] r_mul_result_0 = 36'd0; reg [35:0] r_mul_result_1 = 36'd0; reg [35:0] r_mul_result_2 = 36'd0; reg [35:0] r_mul_result_3 = 36'd0; always @(posedge i_clk) begin r_mul_a_delay_0 <= i_mul_a; r_mul_a_delay_1 <= r_mul_a_delay_0; r_mul_b_delay_0 <= i_mul_b; r_mul_b_delay_1 <= r_mul_b_delay_0; end always @(posedge i_clk) begin r_mul_result_0 <= r_mul_a_delay_1 * r_mul_b_delay_1; end always @(posedge i_clk) begin r_mul_result_1 <= r_mul_result_0; r_mul_result_2 <= r_mul_result_1; r_mul_result_3 <= r_mul_result_2; end assign o_mul_result = r_mul_result_3; endmodule // end the mul_test model
2.綜合適配看看結果:可以看到使用了2個DSP塊。
如果只是乘法使用DSP實現的話,在結果寄存器添加語法規則即可。
(*use_dsp = "yes"*)reg [35:0] r_mul_result_0 = 36'd0;
以上。