From 24ffde94c89ef67eed4df30ba49ccf48ca46c9a9 Mon Sep 17 00:00:00 2001 From: Adam Izraelevitz Date: Thu, 22 Sep 2016 13:08:32 -0700 Subject: Fixed width inference for add, sub (#312) Fixes #308 Fixes #193 --- src/main/scala/firrtl/PrimOps.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/main') 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 } -- cgit v1.2.3