Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove incorrect clock warning on Mem.read #2721

Merged
merged 2 commits into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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