You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In our RTL code, we frequently qualify an arbitrary Data type with a Bool.
In Chisel we have to write Mux(enable, value, 0.U) // if value is an UInt
or Mux(enable, value, 0.U.asTypeOf(value)) // if value is an arbitrary Data type
For conciseness, we like to write enable && value or value && enable. WIth proper signal names, this is intuitive.
Today, Chisel defines the logical && operator only on a pair of Bools.
This pull request adds support for this operator, if one side of the expression is a Bool and the other is subtype of Data. For completeness, we also implement || for OR and ^^ for XOR. The function is intuitive: the Bool is extended to the full width of the other operand, then the logical function is applied on every bit. The result of the expression has the same type as the non-Bool operand.
In existing Chisel projects like ours, designers may have added logical operators to their Data classes, to already allow the short-hand notation. This pull request makes this unnecessary.
Release Notes
Enhance logical operators &&, ||, ^^ to have a Bool on one side of the epxression and wider Data on the other.
The feature looks good. You'll need to get this working with Scala 3 by moving the impls into scala/ and intf overrides in scala-2/BitsIntf.scala and scala-3/BitsIntf.scala
We already support bitwise versions of these operators, &, | and ^ on UInt and Bool is a subtype of UInt that behave the same as your proposed && but quite differently for |/|| and ^/^^1.
I think these are interesting functions but we should give them names instead since they are inconsistent with the existing symbolic methods.
Footnotes
All Chisel operators on UInt or SInt sign extend (0 for UInt) the narrower argument. ↩
Discussed in Chisel dev today. We don't define operators on Data the same way we do on UInt, SInt, and Bool, so we resolved to call it AndEach as a special case of Mux (it is after all a half-mux). I guess we could even call it Mux.andEach.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FeatureNew feature, will be included in release notes
4 participants
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
In our RTL code, we frequently qualify an arbitrary Data type with a Bool.
In Chisel we have to write
Mux(enable, value, 0.U) // if value is an UIntor
Mux(enable, value, 0.U.asTypeOf(value)) // if value is an arbitrary Data typeFor conciseness, we like to write
enable && valueorvalue && enable. WIth proper signal names, this is intuitive.Today, Chisel defines the logical
&&operator only on a pair of Bools.This pull request adds support for this operator, if one side of the expression is a Bool and the other is subtype of Data. For completeness, we also implement
||for OR and^^for XOR. The function is intuitive: the Bool is extended to the full width of the other operand, then the logical function is applied on every bit. The result of the expression has the same type as the non-Bool operand.In existing Chisel projects like ours, designers may have added logical operators to their Data classes, to already allow the short-hand notation. This pull request makes this unnecessary.
Release Notes
Enhance logical operators &&, ||, ^^ to have a Bool on one side of the epxression and wider Data on the other.