aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/firrtl/ir
diff options
context:
space:
mode:
authorAlbert Chen2020-07-23 11:14:35 -0700
committerGitHub2020-07-23 18:14:35 +0000
commit1927dc6574b9eee315c8f24441df390f2ce793c7 (patch)
tree8f942d8d4c7c46c59db476a4329d119d0ac77c79 /src/main/scala/firrtl/ir
parentea558ad79ed0e65df73b5a01ceea690e5b0479ca (diff)
mask bits when propagating bitwise ops (#1745)
* ConstProp: test bitwise op of signed literals * ConstProp: use bit mask for FoldOr/FoldXor * handle and also * add UIntLiteral.masked helper Co-authored-by: Jack Koenig <koenig@sifive.com>
Diffstat (limited to 'src/main/scala/firrtl/ir')
-rw-r--r--src/main/scala/firrtl/ir/IR.scala9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/main/scala/firrtl/ir/IR.scala b/src/main/scala/firrtl/ir/IR.scala
index 275cbe51..023f53fd 100644
--- a/src/main/scala/firrtl/ir/IR.scala
+++ b/src/main/scala/firrtl/ir/IR.scala
@@ -297,6 +297,15 @@ case class UIntLiteral(value: BigInt, width: Width) extends Literal {
object UIntLiteral {
def minWidth(value: BigInt): Width = IntWidth(math.max(value.bitLength, 1))
def apply(value: BigInt): UIntLiteral = new UIntLiteral(value, minWidth(value))
+
+ /** Utility to construct UIntLiterals masked by the width
+ *
+ * This supports truncating negative values as well as values that are too wide for the width
+ */
+ def masked(value: BigInt, width: IntWidth): UIntLiteral = {
+ val mask = (BigInt(1) << width.width.toInt) - 1
+ UIntLiteral(value & mask, width)
+ }
}
case class SIntLiteral(value: BigInt, width: Width) extends Literal {
def tpe = SIntType(width)