Skip to content

Commit

Permalink
Remove incorrect clock warning on Mem.read (#2721)
Browse files Browse the repository at this point in the history
Mem.read is combinational and thus unaffected by the clock, and so it
does not make sense to issue warnings about the current clock in this
context.
  • Loading branch information
aswaterman authored Sep 1, 2022
1 parent e1e0503 commit 5fdf74f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
16 changes: 11 additions & 5 deletions core/src/main/scala/chisel3/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ sealed abstract class MemBase[T <: Data](val t: T, val length: BigInt)
// ensure memory ports are created with the same clock unless explicitly specified to use a different clock
private val clockInst: Option[Clock] = Builder.currentClock

protected def clockWarning(sourceInfo: Option[SourceInfo]): Unit = {
protected def clockWarning(sourceInfo: Option[SourceInfo], dir: MemPortDirection): Unit = {
// Turn into pretty String if possible, if not, Builder.deprecated will find one via stack trace
val infoStr = sourceInfo.collect { case SourceLine(file, line, col) => s"$file:$line:$col" }
Builder.deprecated(
Expand Down Expand Up @@ -135,7 +135,7 @@ sealed abstract class MemBase[T <: Data](val t: T, val length: BigInt)
compileOptions: CompileOptions
): T = {
if (warn && clockInst.isDefined && clock != clockInst.get) {
clockWarning(Some(sourceInfo))
clockWarning(Some(sourceInfo), dir)
}
makePort(sourceInfo, idx, dir, clock)
}
Expand Down Expand Up @@ -167,7 +167,7 @@ sealed abstract class MemBase[T <: Data](val t: T, val length: BigInt)
implicit compileOptions: CompileOptions
): Unit = {
if (warn && clockInst.isDefined && clock != clockInst.get) {
clockWarning(None)
clockWarning(None, MemPortDirection.WRITE)
}
implicit val sourceInfo = UnlocatableSourceInfo
makePort(UnlocatableSourceInfo, idx, MemPortDirection.WRITE, clock) := data
Expand Down Expand Up @@ -226,7 +226,7 @@ sealed abstract class MemBase[T <: Data](val t: T, val length: BigInt)
): Unit = {
implicit val sourceInfo = UnlocatableSourceInfo
if (warn && clockInst.isDefined && clock != clockInst.get) {
clockWarning(None)
clockWarning(None, MemPortDirection.WRITE)
}
val accessor = makePort(sourceInfo, idx, MemPortDirection.WRITE, clock).asInstanceOf[Vec[Data]]
val dataVec = data.asInstanceOf[Vec[Data]]
Expand Down Expand Up @@ -274,7 +274,13 @@ sealed abstract class MemBase[T <: Data](val t: T, val length: BigInt)
* @note when multiple conflicting writes are performed on a Mem element, the
* result is undefined (unlike Vec, where the last assignment wins)
*/
sealed class Mem[T <: Data] private[chisel3] (t: T, length: BigInt) extends MemBase(t, length)
sealed class Mem[T <: Data] private[chisel3] (t: T, length: BigInt) extends MemBase(t, length) {
override protected def clockWarning(sourceInfo: Option[SourceInfo], dir: MemPortDirection): Unit = {
// Do not issue clock warnings on reads, since they are not clocked
if (dir != MemPortDirection.READ)
super.clockWarning(sourceInfo, dir)
}
}

object SyncReadMem {

Expand Down
8 changes: 0 additions & 8 deletions src/test/scala/chiselTests/MultiClockSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ class MultiClockSpec extends ChiselFlatSpec with Utils {
}

"Differing clocks at memory and read accessor instantiation" should "warn" in {
class modMemReadDifferingClock extends Module {
val myClock = IO(Input(Clock()))
val mem = withClock(myClock) { Mem(4, UInt(8.W)) }
val readVal = mem.read(0.U)
}
val (logMemReadDifferingClock, _) = grabLog(ChiselStage.elaborate(new modMemReadDifferingClock))
logMemReadDifferingClock should include("memory is different")

class modSyncReadMemReadDifferingClock extends Module {
val myClock = IO(Input(Clock()))
val mem = withClock(myClock) { SyncReadMem(4, UInt(8.W)) }
Expand Down

0 comments on commit 5fdf74f

Please sign in to comment.