Skip to content

Commit

Permalink
Bool: add implication operator |->
Browse files Browse the repository at this point in the history
  • Loading branch information
ekiwi-sifive committed Jun 25, 2020
1 parent a1edc8f commit c843c06
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/chisel3/Bits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,16 @@ sealed class Bool() extends UInt(1.W) with Reset {
/** @group SourceInfoTransformMacro */
def do_asAsyncReset(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): AsyncReset =
pushOp(DefPrim(sourceInfo, AsyncReset(), AsAsyncResetOp, ref))

/** Implication operator
*
* @param that a boolean signal
* @return [[!this || that]]
*/
def |-> (that: Bool): Bool = macro SourceInfoTransform.thatArg

/** @group SourceInfoTransformMacro */
def do_|-> (that: Bool)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = (!this) | that
}

package experimental {
Expand Down
21 changes: 21 additions & 0 deletions src/test/scala/chiselTests/BoolSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// See LICENSE for license details.

package chiselTests

import chisel3._
import chisel3.testers.BasicTester


class BoolSpec extends ChiselFlatSpec with Utils {

"implication" should "work in RTL" in {
assertTesterPasses {
new BasicTester {
chisel3.assert((false.B |-> false.B) === true.B, "0 -> 0 = 1")
chisel3.assert((false.B |-> true.B) === true.B, "0 -> 1 = 1")
chisel3.assert((true.B |-> false.B) === false.B, "1 -> 0 = 0")
chisel3.assert((true.B |-> true.B) === true.B, "1 -> 1 = 1")
}
}
}
}

0 comments on commit c843c06

Please sign in to comment.