chisel icon indicating copy to clipboard operation
chisel copied to clipboard

Shift operators should return same type

Open nullobject opened this issue 3 years ago • 0 comments

Type of issue: feature request

Impact: API modification

Development Phase: request

What is the use case for changing the behavior?

When using the shift left/right operator on a UInt or SInt, the API current returns a value of type Bits.

For example:

1.U << 1 // value of type Bits
1.S << 1 // value of type Bits

This requires explicitly converting back to a UInt using the asUInt method:

(1.U << 1).asUInt // value of type UInt

But logically, when an integer is shifted the result is still just another integer. Why should its type change?

What we really want is:

1.U << 1 // value of type UInt
1.S << 1 // value of type SInt

I would be happy to submit this change in a PR, if you would be willing to accept it.

nullobject avatar May 20 '22 06:05 nullobject