ucb-bar / chisel2-deprecated

chisel.eecs.berkeley.edu
388 stars 90 forks source link

Make Printf Cycle Accurate #675

Closed da-steve101 closed 8 years ago

da-steve101 commented 8 years ago

As discussed in #671, I think printf should be cycle accurate. Consider the following two examples of printf usage:

class MyMod extends Module {
  val io = new Bundle {
    val enable = Bool(INPUT)
    val a = UInt(INPUT, 4)
    val b = UInt(INPUT, 4)
    val c = UInt(OUTPUT, 4)
  }
  io.c := UInt(0, 4)
  when( io.enable ) {
    printf("MyMod add enabled\n")
    io.c := io.a + io.b
  }
}
class MyMod( flag : Boolean ) extends Module {
  val io = new Bundle {
    val a = UInt(INPUT, 4)
    val b = UInt(INPUT, 4)
    val c = UInt(OUTPUT, 4)
  }
  if ( flag ) {
    val myReg = RegNext( io.a + io.b )
    io.c := myReg
    printf("myReg = %d\n", myReg)
  } else {
    io.c := io.a - io.b
  }
}

In the first case, if trying to implement a conditional printf, you would have to duplicate the logic in the tester. In the second case myReg isn't visible outside the if statement and hence cannot be peeked.

donggyukim commented 8 years ago

Try it with #682. Let me know it's still broken. We should make tester sleep if prints do not pop up immediately, which is not desirable at all.

da-steve101 commented 8 years ago

Seems to be working :) thanks