0

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];  // ??
BBKing
  • 5
  • 4

1 Answers1

3

In order to keep the carry you should use the expanding operators +& and -&.

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

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

ɹɐʎɯɐʞ
  • 542
  • 5
  • 15
  • The cheat sheet shows: Bits, UInt, SInt Casts: reinterpret cast except for: UInt → SInt Zero-extend to SInt. How to do "8 bits UInt -> 9 bits Sint"? Or How can I do "9 bits Sint = 8 bits Uint - 8 bits Uint"? – BBKing Apr 13 '17 at 06:47
  • 2
    Calling `.zext()` on a UInt will turn it into an SInt of it's width + 1 with a zero in the MSB. So if you have two 8-bit UInts, call `.zext()` on each and subtract you will get a 9-bit SInt result. – Jack Koenig Apr 15 '17 at 00:07