There are 3 Uint 8 bits numbers. I want to sum up these numbers. How to describe it in chisel?
s = a + b + c // s is 10 bits number
If the only way to describe it as following, what's the benefits compare to traditional HDL?
s0 = a + b // s0 is 9 bits numebr s1 = s0 + c // s1 is 10 bits number
I already try it in chisel, the result is not what I expect.
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
The generated 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]; // ??
In order to keep the carry you should use the expanding operators +& and -&.
io.p_out := io.in0 +& io.in0 -& io.in1