verilog流水線設計


大綱

1,什么是流水線

2,什么時候用流水線

3,它的優缺點

4,使用流水線設計的實例

流水線實際上是將組合邏輯系統分割,然后在間隙插入寄存器,暫存中間數據。其思想就是要將大的操作分成盡量小的操作,每一步小的操作用的時間就越小,也就提高了頻率,各小操作可以並行執行,所以提高了數據的吞吐率(操作的處理速度)。

2當對時序不滿足,系統要工作的頻率高時,也就是需要大的數據吞吐率的時候,具體會遇到的典型的情況如下:

(1)功能模塊之間需要乒乓交換數據時,代價是增加了 memory 的數量,但是和獲得的巨大性能提升相比,可以忽略不計。

(2) I/O 瓶頸,比如某個運算需要輸入 8 個數據,而 memroy 只能同時提供 2 個數據,如果通過適當划分運算步驟,使用流水線反而會減少面積。

(3)片內 sram 的讀操作,因為 sram 的讀操作本身就是兩極流水線,除非下一步操作依賴讀結果,否則使用流水線是自然而然的事情。

(4)組合邏輯太長,比如(a+b)*c,那么在加法和乘法之間插入寄存器是比較穩妥的做法。

優點:

缺點:

4使用流水設計的實例

以一個8位全加器為實例,如下:

1)非流水線實現方式

module adder_8bits(din_1, clk, cin, dout, din_2, cout);
    input [7:0] din_1;
    input clk;
    input cin;
    output [7:0] dout;
    input [7:0] din_2;
    output cout;
     
     reg [7:0] dout;
     reg       cout;
     
     always @(posedge clk) begin
        {cout,dout} <= din_1 + din_2 + cin;
     end

endmodule2)2級流水線實現方式:

module adder_4bits_2steps(cin_a, cin_b, cin, clk, cout, sum);
    input [7:0] cin_a;
    input [7:0] cin_b;
    input cin;
    input clk;
    output cout;
    output [7:0] sum;
     
     reg cout;
     reg cout_temp;
     reg [7:0] sum;
     reg [3:0] sum_temp;
     
     always @(posedge clk) begin
        {cout_temp,sum_temp} = cin_a[3:0] + cin_b[3:0] + cin;
     end
     
     always @(posedge clk) begin
        {cout,sum} = {{1'b0,cin_a[7:4]} + {1'b0,cin_b[7:4]} + cout_temp, sum_temp};
     end
endmodule
注意:這里在always塊內只能用阻塞賦值方式,否則會出現邏輯上的錯誤!

(3)4級流水線實現方式:

module adder_8bits_4steps(cin_a, cin_b, c_in, clk, c_out, sum_out);
    input [7:0] cin_a;
    input [7:0] cin_b;
    input c_in;
    input clk;
    output c_out;
    output [7:0] sum_out;
     
     reg c_out;
     reg c_out_t1, c_out_t2, c_out_t3;
     
     reg [7:0] sum_out;
     reg [1:0] sum_out_t1;
     reg [3:0] sum_out_t2;
     reg [5:0] sum_out_t3;
     
     always @(posedge clk) begin
        {c_out_t1, sum_out_t1} = {1'b0, cin_a[1:0]} + {1'b0, cin_b[1:0]} + c_in;
     end
     
     always @(posedge clk) begin
        {c_out_t2, sum_out_t2} = {{1'b0, cin_a[3:2]} + {1'b0, cin_b[3:2]} + c_out_t1, sum_out_t1};
     end
     
     always @(posedge clk) begin
        {c_out_t3, sum_out_t3} = {{1'b0, cin_a[5:4]} + {1'b0, cin_b[5:4]} + c_out_t2, sum_out_t2};
     end
     
     always @(posedge clk) begin
        {c_out, sum_out} = {{1'b0, cin_a[7:6]} + {1'b0, cin_b[7:6]} + c_out_t3, sum_out_t3};
     end
endmodule

對應的資源占用以及仿真波形如下:

emmm,后來才發現這只是功能仿真,看不出來組合邏輯器件的延時效果的~

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM