chipsalliance / chipsalliance/chisel
Propose Binary operator for Bool and Bits.
- Dominant language
- Scala
- Stars
- 4.8k
- Forks
- 658
- Avg merge
- 18h 59m
- Merged PRs (30d)
- 14
Description
**Type of issue**: feature request
**Impact**: API addition (no impact on existing code)
**Development Phase**: proposal
**Other information**
**What is the expected behavior?**
The current bitwise operators between Bool and Bits, like &|^, are applied to the last bit. It is useful to add Bits width operations:
```
def <&> (b: Bool, u: Bits): Bits = Fill(u.getWidth, b) & u
def <|> (b: Bool, u: Bits): Bits = Fill(u.getWidth, b) | u
def <^> (b: Bool, u: Bits): Bits = Fill(u.getWidth, b) ^ u
```
**What is the use case for changing the behavior?**
1. It is common to expand the Bool bit and then do the operation.
2. It is convenient because they are special (partial) Mux:
```
def <&> (b: Bool, u: Bits): Bits = Mux(b, u, 0.U)
def <|> (b: Bool, u: Bits): Bits = Mux(b, u, Fill(u.getWidth 1.U))
def <^> (b: Bool, u: Bits): Bits = Mux(b, ~u, u)
```
for example OrAndTree Mux:
`(sel1 <&> dat1) & (sel2 <&> dat2) & (sel3 <&> dat3)`
It's small convenient syntax sugar for consideration.
Contributor guide
Assessment
This issue has not been assessed yet.