diff options
| author | Andrew Waterman | 2015-08-03 17:10:11 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-08-03 17:10:11 -0700 |
| commit | bf72a6a7fd747a267d4264ac2d532bb02407f7c6 (patch) | |
| tree | 7e373fbf0edb0d5e1c287a1590ecf9ec42f2af54 /src/main/scala/Chisel/Core.scala | |
| parent | cb92cc4f8b46bdcbd159f0aeb9b0e556ee55f959 (diff) | |
Fix << width bug
Diffstat (limited to 'src/main/scala/Chisel/Core.scala')
| -rw-r--r-- | src/main/scala/Chisel/Core.scala | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala index 3f6c197d..d9d7cf38 100644 --- a/src/main/scala/Chisel/Core.scala +++ b/src/main/scala/Chisel/Core.scala @@ -305,8 +305,8 @@ abstract class Data(dirArg: Direction) extends Id { def sumWidth(amt: Int): Int = if (knownWidth) (getWidth + amt).toInt else -1 def sumWidth(other: Data, amt: Int): Int = if (knownWidth && other.knownWidth) (getWidth + other.getWidth + amt).toInt else -1 - def sumPow2Width(other: Data): Int = - if (knownWidth && other.knownWidth) (getWidth + (1 << other.getWidth)).toInt else -1 + def lshWidth(other: Data): Int = + if (knownWidth && other.knownWidth) (0 max (getWidth + (1 << other.getWidth) - 1)).toInt else -1 def rshWidth(amt: Int): Int = if (knownWidth) (0 max (getWidth - amt)) else -1 def flatten: IndexedSeq[Bits] @@ -720,7 +720,7 @@ sealed class UInt(dir: Direction, width: Int, lit: Option[ULit] = None) extends def << (other: BigInt): UInt = binop(ShiftLeftOp, other, sumWidth(other.toInt)) def << (other: Int): UInt = this << BigInt(other) - def << (other: UInt): UInt = binop(DynamicShiftLeftOp, other, sumPow2Width(other)) + def << (other: UInt): UInt = binop(DynamicShiftLeftOp, other, lshWidth(other)) def >> (other: BigInt): UInt = binop(ShiftRightOp, other, rshWidth(other.toInt)) def >> (other: Int): UInt = this >> BigInt(other) def >> (other: UInt): UInt = binop(DynamicShiftRightOp, other, sumWidth(0)) @@ -811,7 +811,7 @@ sealed class SInt(dir: Direction, width: Int, lit: Option[SLit] = None) extends def << (other: BigInt): SInt = binop(ShiftLeftOp, other, sumWidth(other.toInt)) def << (other: Int): SInt = this << BigInt(other) - def << (other: UInt): SInt = binop(DynamicShiftLeftOp, other, sumPow2Width(other)) + def << (other: UInt): SInt = binop(DynamicShiftLeftOp, other, lshWidth(other)) def >> (other: BigInt): SInt = binop(ShiftRightOp, other, rshWidth(other.toInt)) def >> (other: Int): SInt = this >> BigInt(other) def >> (other: UInt): SInt = binop(DynamicShiftRightOp, other, sumWidth(0)) |
