chipsalliance / chipsalliance/chisel

Shift operators should return same type

Open
#2,540 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Scala
Stars
4.8k
Forks
658
Avg merge
18h 59m
Merged PRs (30d)
14

Description

**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:

```scala
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:

```scala
(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:

```scala
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.

Contributor guide

Open the contributing guide

Research direction

Start by locating the shift-left and shift-right operator definitions and the type-related tests for UInt, SInt, and Bits. Verify the current result types against the examples in the issue, then update the behavior so shifting UInt and SInt preserves the operand type and confirm the tests cover both signed and unsigned cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
scala
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.