diff options
| author | Adam Izraelevitz | 2016-09-22 13:08:32 -0700 |
|---|---|---|
| committer | Jack Koenig | 2016-09-22 13:08:32 -0700 |
| commit | 24ffde94c89ef67eed4df30ba49ccf48ca46c9a9 (patch) | |
| tree | e00151cd32f8ce326778662e2a1755e76a21990c /src/main | |
| parent | 8b12dcbb76896a19f95dc4da19b3b8c74c1ddda3 (diff) | |
Fixed width inference for add, sub (#312)
Fixes #308
Fixes #193
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/scala/firrtl/PrimOps.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main/scala/firrtl/PrimOps.scala b/src/main/scala/firrtl/PrimOps.scala index 8d677104..cf2cb74e 100644 --- a/src/main/scala/firrtl/PrimOps.scala +++ b/src/main/scala/firrtl/PrimOps.scala @@ -142,15 +142,15 @@ object PrimOps extends LazyLogging { e copy (tpe = (e.op match { case Add => (t1, t2) match { case (_: UIntType, _: UIntType) => UIntType(PLUS(MAX(w1, w2), IntWidth(1))) - case (_: UIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) - case (_: SIntType, _: UIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) + case (_: UIntType, _: SIntType) => SIntType(PLUS(MAX(w1, MINUS(w2, IntWidth(1))), IntWidth(2))) + case (_: SIntType, _: UIntType) => SIntType(PLUS(MAX(w2, MINUS(w1, IntWidth(1))), IntWidth(2))) case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) case _ => UnknownType } case Sub => (t1, t2) match { case (_: UIntType, _: UIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) - case (_: UIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) - case (_: SIntType, _: UIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) + case (_: UIntType, _: SIntType) => SIntType(MAX(PLUS(w2, IntWidth(1)), PLUS(w1, IntWidth(2)))) + case (_: SIntType, _: UIntType) => SIntType(MAX(PLUS(w1, IntWidth(1)), PLUS(w2, IntWidth(2)))) case (_: SIntType, _: SIntType) => SIntType(PLUS(MAX(w1, w2), IntWidth(1))) case _ => UnknownType } |
