如何将3个数字加在一起?

时间:2017-04-12 09:13:12

标签: chisel

有3个Uint 8位数字。我想总结这些数字。如何用凿子描述它?

s = a + b + c // s是10位数

如果将其描述为以下的唯一方式,与传统HDL相比有什么好处?

s0 = a + b // s0是9位数 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];  // ??

1 个答案:

答案 0 :(得分:3)

为了保持携带,您应该使用扩展操作符+&和 - &。

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

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