2017-04-12 63 views
0

有3個Uint 8位數字。我想總結這些數字。如何用鑿子描述它?如何添加3個號碼?

S = A + B + C // s是10位數字

如果只有這樣,才能形容它爲以下,有什麼好處比較傳統的HDL?

S0 = A + B // S0爲9位numebr S1 = S0 + C // S1是10位數字

我已經嘗試在鑿,結果是不是我所期望的。

val in0 = Input(UInt(8.W)) 
val in1 = Input(UInt(8.W)) 
val p_out = Output(UInt(10.W)) 

io.p_out := io.in0 + io.in0 - io.in1 

生成的RTL:

input [7:0] io_in0, 
input [7:0] io_in1, 
output [9:0] io_p_out 

wire [8:0] _T_18; 
wire [7:0] _T_19; 
wire [8:0] _T_20; 
wire [8:0] _T_21; 
wire [7:0] _T_22; 

assign io_p_out = {{2'd0}, _T_22}; 
assign _T_18 = io_in0 + io_in0; 
assign _T_19 = _T_18[7:0]; // ?? 
assign _T_20 = _T_19 - io_in1; 
assign _T_21 = $unsigned(_T_20); // ?? 
assign _T_22 = _T_21[7:0]; // ?? 

回答

3

爲了保持你應該使用擴大運營商+ &和進 - &。

io.p_out := io.in0 +& io.in0 -& io.in1 

https://chisel.eecs.berkeley.edu/doc/chisel-cheatsheet3.pdf

+0

明白了!謝謝! – BBKing

+0

備忘單顯示:位,UInt,SInt演員表:重新演繹演員表,除以下項: UInt→SInt零延伸至SInt。如何做「8位UInt - > 9位Sint」?或者我該怎麼做「9位Sint = 8位Uint - 8位Uint」? – BBKing

+2

在一個UInt中調用'.zext()'會將它變成一個寬度爲+1的MSI中的零。所以如果你有兩個8位的UI,每個調用'.zext()',減去你將得到一個9位的SInt結果。 – jkoenig