Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

fix macro anno error #34

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions macros/src/main/scala/CostMetric.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ object DefaultMetric extends CostMetric with CostMetricCompanion {
val memMask = mem.src.ports map (_.maskGran) find (_.isDefined) map (_.get)
val libMask = lib.src.ports map (_.maskGran) find (_.isDefined) map (_.get)
val memWidth = (memMask, libMask) match {
case (Some(1), Some(1)) | (None, _) => mem.src.width
case (Some(p), _) => p // assume that the memory consists of smaller chunks
case (None, _) => mem.src.width
case (Some(p), Some(q)) if p % q == 0 => mem.src.width
case (Some(p), _) => (mem.src.width / p) * lib.src.width // assume that the memory consists of smaller chunks
}
return Some(
(((mem.src.depth - 1) / lib.src.depth) + 1) *
Expand Down
26 changes: 22 additions & 4 deletions macros/src/main/scala/MacroCompiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,9 @@ class MacroCompilerPass(mems: Option[Seq[Macro]],
val name = s"mem_${i}_${j}"
// Create the instance.
stmts += WDefInstance(NoInfo, name, lib.src.name, lib.tpe)
stmts ++= lib.sortedPorts flatMap (_.ports collect {
case Port(_, pname, Input, _) => IsInvalid(NoInfo, WSubField(WRef(name), pname))
})
// Connect extra ports of the lib.
stmts ++= lib.extraPorts map { case (portName, portValue) =>
Connect(NoInfo, WSubField(WRef(name), portName), portValue)
Expand Down Expand Up @@ -418,7 +421,7 @@ class MacroCompilerPass(mems: Option[Seq[Macro]],
// zero out the upper bits.
zero
} else {
if (i >= memPort.src.width.get) {
if ((low + i) >= memPort.src.width.get) {
// If our bit is larger than the whole width of the mem, just zero out the upper bits.
zero
} else {
Expand Down Expand Up @@ -467,13 +470,21 @@ class MacroCompilerPass(mems: Option[Seq[Macro]],
/* Palmer: It's safe to ignore read enables, but we pass them through
* to the vendor memory if there's a port on there that
* implements the read enables. */
/* Donggyu: this is broken as read enables should be piped
(memPort.src.readEnable, libPort.src.readEnable) match {
case (_, None) =>
case (Some(PolarizedPort(mem, _)), Some(PolarizedPort(lib, lib_polarity))) =>
stmts += connectPorts(andAddrMatch(WRef(mem)), lib, lib_polarity)
case (None, Some(PolarizedPort(lib, lib_polarity))) =>
stmts += connectPorts(andAddrMatch(not(memWriteEnable)), lib, lib_polarity)
}
*/
// Donggyu: thus, just connect 1 to read enables for now
libPort.src.readEnable match {
case None =>
case Some(PolarizedPort(lib, lib_polarity)) =>
stmts += connectPorts(one, lib, lib_polarity)
}

/* Palmer: This is actually the memory compiler: it figures out how to
* implement the outer memory's collection of ports using what
Expand Down Expand Up @@ -509,6 +520,14 @@ class MacroCompilerPass(mems: Option[Seq[Macro]],
case (None, None, None) =>
// No write ports to match up (this may be a read-only port).
// This isn't necessarily an error condition.
case (None, None, Some(PolarizedPort(en, en_polarity))) =>
// Correctly connect read-only port's chip enable
stmts += (memPort.src.readEnable match {
case None =>
connectPorts(addrMatch, en, en_polarity)
case Some(PolarizedPort(mem, _)) =>
connectPorts(andAddrMatch(WRef(mem)), en, en_polarity)
})
}
}
// Cat macro outputs for selection
Expand Down Expand Up @@ -707,7 +726,7 @@ object MacroCompiler extends App {
// Note: the last macro in the input list is (seemingly arbitrarily)
// determined as the firrtl "top-level module".
val circuit = Circuit(NoInfo, macros, macros.last.name)
val annotations = AnnotationMap(
val annotations =
Seq(MacroCompilerAnnotation(
circuit.main,
MacroCompilerAnnotation.Params(
Expand All @@ -717,8 +736,7 @@ object MacroCompiler extends App {
params.contains(UseCompiler)
)
))
)
val state = CircuitState(circuit, HighForm, Some(annotations))
val state = CircuitState(circuit, HighForm, annotations)

// Run the compiler.
val result = new MacroCompiler().compileAndEmit(state)
Expand Down
38 changes: 19 additions & 19 deletions macros/src/main/scala/SynFlops.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class SynFlopsPass(synflops: Boolean, libs: Seq[Macro]) extends firrtl.passes.Pa
lib.src.depth,
1, // writeLatency
1, // readLatency. This is possible because of VerilogMemDelays
lib.readers.indices map (i => s"R_$i"),
lib.writers.indices map (i => s"W_$i"),
lib.readwriters.indices map (i => s"RW_$i")
lib.readers.indices map (i => s"R$i"),
lib.writers.indices map (i => s"W$i"),
lib.readwriters.indices map (i => s"RW$i")
)

val readConnects = lib.readers.zipWithIndex flatMap { case (r, i) =>
Expand All @@ -48,16 +48,16 @@ class SynFlopsPass(synflops: Boolean, libs: Seq[Macro]) extends firrtl.passes.Pa
case (None, Some(re_port)) => portToExpression(re_port)
case (None, None) => one
}
val data = memPortField(mem, s"R_$i", "data")
val data = memPortField(mem, s"R$i", "data")
val read = (dataType: @unchecked) match {
case VectorType(tpe, size) => cat(((0 until size) map (k =>
WSubIndex(data, k, tpe, UNKNOWNGENDER))).reverse)
case _: UIntType => data
}
Seq(
Connect(NoInfo, memPortField(mem, s"R_$i", "clk"), clock),
Connect(NoInfo, memPortField(mem, s"R_$i", "addr"), address),
Connect(NoInfo, memPortField(mem, s"R_$i", "en"), enable),
Connect(NoInfo, memPortField(mem, s"R$i", "clk"), clock),
Connect(NoInfo, memPortField(mem, s"R$i", "addr"), address),
Connect(NoInfo, memPortField(mem, s"R$i", "en"), enable),
Connect(NoInfo, WRef(r.src.output.get.name), read)
)
}
Expand All @@ -73,13 +73,13 @@ class SynFlopsPass(synflops: Boolean, libs: Seq[Macro]) extends firrtl.passes.Pa
case (None, Some(we)) => portToExpression(we)
case (None, None) => zero // is it possible?
}
val mask = memPortField(mem, s"W_$i", "mask")
val data = memPortField(mem, s"W_$i", "data")
val mask = memPortField(mem, s"W$i", "mask")
val data = memPortField(mem, s"W$i", "data")
val write = portToExpression(w.src.input.get)
Seq(
Connect(NoInfo, memPortField(mem, s"W_$i", "clk"), clock),
Connect(NoInfo, memPortField(mem, s"W_$i", "addr"), address),
Connect(NoInfo, memPortField(mem, s"W_$i", "en"), enable)
Connect(NoInfo, memPortField(mem, s"W$i", "clk"), clock),
Connect(NoInfo, memPortField(mem, s"W$i", "addr"), address),
Connect(NoInfo, memPortField(mem, s"W$i", "en"), enable)
) ++ (dataType match {
case VectorType(tpe, size) =>
val width = bitWidth(tpe).toInt
Expand Down Expand Up @@ -108,20 +108,20 @@ class SynFlopsPass(synflops: Boolean, libs: Seq[Macro]) extends firrtl.passes.Pa
case (None, Some(re)) => or(portToExpression(re), wmode)
case (None, None) => one
}
val wmask = memPortField(mem, s"RW_$i", "wmask")
val wdata = memPortField(mem, s"RW_$i", "wdata")
val rdata = memPortField(mem, s"RW_$i", "rdata")
val wmask = memPortField(mem, s"RW$i", "wmask")
val wdata = memPortField(mem, s"RW$i", "wdata")
val rdata = memPortField(mem, s"RW$i", "rdata")
val write = portToExpression(rw.src.input.get)
val read = (dataType: @unchecked) match {
case VectorType(tpe, size) => cat(((0 until size) map (k =>
WSubIndex(rdata, k, tpe, UNKNOWNGENDER))).reverse)
case _: UIntType => rdata
}
Seq(
Connect(NoInfo, memPortField(mem, s"RW_$i", "clk"), clock),
Connect(NoInfo, memPortField(mem, s"RW_$i", "addr"), address),
Connect(NoInfo, memPortField(mem, s"RW_$i", "en"), enable),
Connect(NoInfo, memPortField(mem, s"RW_$i", "wmode"), wmode),
Connect(NoInfo, memPortField(mem, s"RW$i", "clk"), clock),
Connect(NoInfo, memPortField(mem, s"RW$i", "addr"), address),
Connect(NoInfo, memPortField(mem, s"RW$i", "en"), enable),
Connect(NoInfo, memPortField(mem, s"RW$i", "wmode"), wmode),
Connect(NoInfo, WRef(rw.src.output.get.name), read)
) ++ (dataType match {
case VectorType(tpe, size) =>
Expand Down