diff options
| author | Andrew Waterman | 2015-08-02 21:38:57 -0700 |
|---|---|---|
| committer | Andrew Waterman | 2015-08-02 21:38:57 -0700 |
| commit | f1c63223307c60cb2400ae2f665ba490478894f7 (patch) | |
| tree | ede4233c3950ac4b91211e7443ee45face487b41 /src | |
| parent | efccec04b26b9660b28176446831d992aee1c245 (diff) | |
Move comparison operators to UInt/SInt
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/scala/Chisel/Core.scala | 44 | ||||
| -rw-r--r-- | src/main/scala/Chisel/utils.scala | 2 |
2 files changed, 21 insertions, 25 deletions
diff --git a/src/main/scala/Chisel/Core.scala b/src/main/scala/Chisel/Core.scala index 72760f96..40bfda0e 100644 --- a/src/main/scala/Chisel/Core.scala +++ b/src/main/scala/Chisel/Core.scala @@ -499,7 +499,7 @@ trait VecLike[T <: Data] extends collection.IndexedSeq[T] { def forall(p: T => Bool): Bool = (this map p).fold(Bool(true))(_&&_) def exists(p: T => Bool): Bool = (this map p).fold(Bool(false))(_||_) - def contains(x: T) (implicit evidence: T <:< Bits): Bool = this.exists(_ === x) + def contains(x: T) (implicit evidence: T <:< UInt): Bool = this.exists(_ === x) def count(p: T => Bool): UInt = PopCount((this map p).toSeq) private def indexWhereHelper(p: T => Bool) = this map p zip (0 until length).map(i => UInt(i)) @@ -607,40 +607,37 @@ sealed abstract class Bits(dirArg: Direction, width: Int, lit: Option[LitArg]) e final def apply(x: Int, y: Int): UInt = apply(BigInt(x), BigInt(y)) - protected[Chisel] def unop(op: PrimOp, width: Int): this.type = { + private[Chisel] def unop(op: PrimOp, width: Int): this.type = { val d = cloneTypeWidth(width) pushCommand(DefPrim(d, d.toType, op, Seq(this.ref), NoLits)) d } - protected[Chisel] def binop(op: PrimOp, other: BigInt, width: Int): this.type = { + private[Chisel] def binop(op: PrimOp, other: BigInt, width: Int): this.type = { val d = cloneTypeWidth(width) pushCommand(DefPrim(d, d.toType, op, Seq(this.ref), Seq(other))) d } - protected[Chisel] def binop(op: PrimOp, other: Bits, width: Int): this.type = { + private[Chisel] def binop(op: PrimOp, other: Bits, width: Int): this.type = { val d = cloneTypeWidth(width) pushCommand(DefPrim(d, d.toType, op, Seq(this.ref, other.ref), NoLits)) d } - protected[Chisel] def compop(op: PrimOp, other: Bits): Bool = { + private[Chisel] def compop(op: PrimOp, other: Bits): Bool = { val d = new Bool(NO_DIR) pushCommand(DefPrim(d, d.toType, op, Seq(this.ref, other.ref), NoLits)) d } - protected[Chisel] def unimp(op: String) = + private[Chisel] def unimp(op: String) = throwException(s"Operator ${op} unsupported for class ${getClass}") + private[Chisel] def redop(op: PrimOp): Bool = { + val d = new Bool(NO_DIR) + pushCommand(DefPrim(d, d.toType, op, Seq(this.ref), NoLits)) + d + } def unary_~ : this.type = unop(BitNotOp, sumWidth(0)) def pad (other: BigInt): this.type = binop(PadOp, other, other.toInt) - def < (other: Bits): Bool = compop(LessOp, other) - def > (other: Bits): Bool = compop(GreaterOp, other) - def === (other: Bits): Bool = compop(EqualOp, other) - def != (other: Bits): Bool = compop(NotEqualOp, other) - def <= (other: Bits): Bool = compop(LessEqOp, other) - def >= (other: Bits): Bool = compop(GreaterEqOp, other) - def unary_! : Bool = this === Bits(0) - def << (other: BigInt): Bits def << (other: Int): Bits def << (other: UInt): Bits @@ -648,16 +645,6 @@ sealed abstract class Bits(dirArg: Direction, width: Int, lit: Option[LitArg]) e def >> (other: Int): Bits def >> (other: UInt): Bits - private def bits_redop(op: PrimOp): Bool = { - val d = new Bool(NO_DIR) - pushCommand(DefPrim(d, d.toType, op, Seq(this.ref), NoLits)) - d - } - - def orR = this != Bits(0) - def andR = ~this === Bits(0) - def xorR = bits_redop(XorReduceOp) - def toBools: Vec[Bool] = Vec.tabulate(this.getWidth)(i => this(i)) def asSInt(): SInt @@ -718,10 +705,17 @@ sealed class UInt(dir: Direction, width: Int, lit: Option[ULit] = None) extends def ^ (other: UInt): UInt = binop(BitXorOp, other, maxWidth(other, 0)) def ## (other: UInt): UInt = Cat(this, other) + def orR = this != UInt(0) + def andR = ~this === UInt(0) + def xorR = redop(XorReduceOp) + def < (other: UInt): Bool = compop(LessOp, other) def > (other: UInt): Bool = compop(GreaterOp, other) def <= (other: UInt): Bool = compop(LessEqOp, other) def >= (other: UInt): Bool = compop(GreaterEqOp, other) + def != (other: UInt): Bool = compop(NotEqualOp, other) + def === (other: UInt): Bool = compop(EqualOp, other) + def unary_! : Bool = this === Bits(0) def << (other: BigInt): UInt = binop(ShiftLeftOp, other, sumWidth(other.toInt)) def << (other: Int): UInt = this << BigInt(other) @@ -810,6 +804,8 @@ sealed class SInt(dir: Direction, width: Int, lit: Option[SLit] = None) extends def > (other: SInt): Bool = compop(GreaterOp, other) def <= (other: SInt): Bool = compop(LessEqOp, other) def >= (other: SInt): Bool = compop(GreaterEqOp, other) + def != (other: SInt): Bool = compop(NotEqualOp, other) + def === (other: SInt): Bool = compop(EqualOp, other) def abs(): UInt = Mux(this < SInt(0), (-this).toUInt, this.toUInt) def << (other: BigInt): SInt = binop(ShiftLeftOp, other, sumWidth(other.toInt)) diff --git a/src/main/scala/Chisel/utils.scala b/src/main/scala/Chisel/utils.scala index 90c59e9d..1e024b11 100644 --- a/src/main/scala/Chisel/utils.scala +++ b/src/main/scala/Chisel/utils.scala @@ -138,7 +138,7 @@ object is { def apply(v: Iterable[Bits])(block: => Unit): Unit = { val keys = switchKeys if (keys.isEmpty) ChiselError.error("The 'is' keyword may not be used outside of a switch.") - else if (!v.isEmpty) when (v.map(_ === keys.top).reduce(_||_)) { block } + else if (!v.isEmpty) when (v.map(_.toBits === keys.top.toBits).reduce(_||_)) { block } } } |
