Skip to content

Commit

Permalink
Remove extra bit from SRAMInterface address width (#3830)
Browse files Browse the repository at this point in the history
(cherry picked from commit 4f1f4a7)

# Conflicts:
#	src/test/scala/chiselTests/util/SRAMSpec.scala
  • Loading branch information
debs-sifive authored and mergify[bot] committed Feb 20, 2024
1 parent c0111af commit fb6e4b0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/chisel3/util/SRAM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class SRAMInterface[T <: Data](
s"SRAMInterface_${SRAM.portedness(numReadPorts, numWritePorts, numReadwritePorts)}${if (masked) "_masked"
else ""}}_${tpe.typeName}"

val addrWidth = log2Up(memSize + 1)
val addrWidth = log2Up(memSize)

val readPorts: Vec[MemoryReadPort[T]] = Vec(numReadPorts, new MemoryReadPort(tpe, addrWidth))
val writePorts: Vec[MemoryWritePort[T]] = Vec(numWritePorts, new MemoryWritePort(tpe, addrWidth, masked))
Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/chiselTests/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ class SRAMSpec extends ChiselFunSpec {
val chirrtl = ChiselStage.emitCHIRRTL(new TestModule(1, 1), args = Array("--full-stacktrace"))

chirrtl should include(
"writePorts : { flip address : UInt<6>, flip enable : UInt<1>, flip data : UInt<8>[3], flip mask : UInt<1>[3]}[1]"
"writePorts : { flip address : UInt<5>, flip enable : UInt<1>, flip data : UInt<8>[3], flip mask : UInt<1>[3]}[1]"
)
chirrtl should include(
"readwritePorts : { flip address : UInt<6>, flip enable : UInt<1>, flip isWrite : UInt<1>, readData : UInt<8>[3], flip writeData : UInt<8>[3], flip mask : UInt<1>[3]}[1]"
"readwritePorts : { flip address : UInt<5>, flip enable : UInt<1>, flip isWrite : UInt<1>, readData : UInt<8>[3], flip writeData : UInt<8>[3], flip mask : UInt<1>[3]}[1]"
)

for (i <- 0 until 3) {
Expand Down Expand Up @@ -576,13 +576,13 @@ class SRAMSpec extends ChiselFunSpec {
val wrIndexSuffix = if (i == 0) "" else s"_$i"

chirrtl should include(
s"read mport mem_out_readPorts_${i}_data_MPORT = mem_mem[_mem_out_readPorts_${i}_data_T], readClocks[${i}]"
s"read mport mem_out_readPorts_${i}_data_MPORT = mem_mem[_mem_out_readPorts_${i}_data_WIRE], readClocks[${i}]"
)
chirrtl should include(
s"write mport mem_MPORT${wrIndexSuffix} = mem_mem[_mem_T${wrIndexSuffix}], writeClocks[${i}]"
s"write mport mem_MPORT${wrIndexSuffix} = mem_mem[mem.writePorts[${i}].address], writeClocks[${i}]"
)
chirrtl should include(
s"rdwr mport mem_out_readwritePorts_${i}_readData_MPORT = mem_mem[_mem_out_readwritePorts_${i}_readData_T], readwriteClocks[${i}]"
s"rdwr mport mem_out_readwritePorts_${i}_readData_MPORT = mem_mem[_mem_out_readwritePorts_${i}_readData_WIRE], readwriteClocks[${i}]"
)
}
}
Expand Down
45 changes: 45 additions & 0 deletions src/test/scala/chiselTests/util/SRAMSpec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: Apache-2.0

package chiselTests.util

import chisel3._
import chisel3.util.SRAM
import chisel3.experimental.{annotate, ChiselAnnotation}
import chiselTests.ChiselFlatSpec
import _root_.circt.stage.ChiselStage.emitCHIRRTL
import firrtl.annotations.{Annotation, ReferenceTarget, SingleTargetAnnotation}

class SRAMSpec extends ChiselFlatSpec {
case class DummyAnno(target: ReferenceTarget) extends SingleTargetAnnotation[ReferenceTarget] {
override def duplicate(n: ReferenceTarget) = this.copy(target = n)
}
behavior.of("SRAMInterface")

it should "Provide target information about its instantiating SRAM" in {

class Top extends Module {
val sram = SRAM(
size = 32,
tpe = UInt(8.W),
numReadPorts = 0,
numWritePorts = 0,
numReadwritePorts = 1
)
require(sram.underlying.nonEmpty)
annotate(new ChiselAnnotation {
override def toFirrtl: Annotation = DummyAnno(sram.underlying.get.toTarget)
})
}
val (chirrtlCircuit, annos) = getFirrtlAndAnnos(new Top)
val chirrtl = chirrtlCircuit.serialize
chirrtl should include("module Top :")
chirrtl should include("smem sram_mem : UInt<8> [32]")
chirrtl should include(
"wire sram : { readPorts : { flip address : UInt<5>, flip enable : UInt<1>, data : UInt<8>}[0], writePorts : { flip address : UInt<5>, flip enable : UInt<1>, flip data : UInt<8>}[0], readwritePorts : { flip address : UInt<5>, flip enable : UInt<1>, flip isWrite : UInt<1>, readData : UInt<8>, flip writeData : UInt<8>}[1]}"
)

val dummyAnno = annos.collectFirst { case DummyAnno(t) => (t.toString) }
dummyAnno should be(Some("~Top|Top>sram_mem"))
}

}

0 comments on commit fb6e4b0

Please sign in to comment.