[RTLLM-p010] Arithmetic/Multiplier/multi_pipie_4bit
4 位元無號流水線乘法器
題目說明
請設計一個名為 multi_pipe_4bit 的 Verilog 模組,實作一個 4-bit unsigned pipeline multiplier(4 位元無號流水線乘法器)。
此乘法器使用多級 pipeline register 儲存中間運算結果,將乘法運算拆解成多個階段完成,以提升硬體運算效率。
輸入為兩個 4 位元無號數:
mul_amul_b
輸出為:
mul_out
其寬度為 8 位元,可表示最大乘積結果。
模組介面
| 埠 | 方向 | 位元寬度 | 描述 |
|---|---|---|---|
clk |
input | 1 | Clock 訊號 |
rst_n |
input | 1 | Active-low Reset 訊號 |
mul_a |
input | 4 | 被乘數 |
mul_b |
input | 4 | 乘數 |
mul_out |
output | 8 | 乘法結果 |
Parameter
| 名稱 | 預設值 | 描述 |
|---|---|---|
size |
4 | 輸入資料位元寬度 |
設計要求
- 模組名稱:
multi_pipe_4bit
- 必須使用 pipeline register 儲存中間結果。
- 不可直接使用:
*
完成乘法。
實作流程
1. 輸入資料延伸
將 mul_a 擴展成 2*size 位元。
高位補 0:
例如:
mul_a = 4'b1010
延伸:
00001010
2. Partial Product 產生
根據 mul_b 每一個 bit 產生部分乘積。
若:
mul_b[i] == 1
則:
partial_product = mul_a << i
否則:
partial_product = 0
3. Pipeline 加法
使用 register 儲存每一級加法結果。
每個 pipeline stage 都會保存前一階段計算結果。
4. 最終輸出
經過 pipeline 後:
mul_out = mul_a × mul_b
輸出結果。
程式模板
module multi_pipe_4bit #(
parameter size = 4
)(
input clk,
input rst_n,
input [size-1:0] mul_a,
input [size-1:0] mul_b,
output reg [2*size-1:0] mul_out
);
// 在此填入你的程式
endmodule
評論