Skip to content

Commit b38f520

Browse files
support sram depth/width lists, as well as explicit list of legal combos
Co-authored-by: Lux <[email protected]> Co-authored-by: -T.K.233- <[email protected]>"
1 parent 592dad6 commit b38f520

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

tools/tapeout/src/main/scala/macrolib/SRAM.scala

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ case class SRAMGroup(
105105
family: String,
106106
vt: Seq[String],
107107
mux: Int,
108-
depth: Range,
109-
width: Range,
108+
depth: Iterable[Int],
109+
width: Iterable[Int],
110+
triples: Option[Seq[(Int, Int, Int)]],
110111
ports: Seq[MacroPort],
111112
extraPorts: Seq[MacroExtraPort] = List()) {
112113
def toJSON: JsObject = {
@@ -116,8 +117,18 @@ case class SRAMGroup(
116117
"name" -> JsArray(name.map(Json.toJson(_))),
117118
"vt" -> JsArray(vt.map(Json.toJson(_))),
118119
"mux" -> Json.toJson(mux),
119-
"depth" -> JsArray(Seq(depth.start, depth.end, depth.step).map { x => Json.toJson(x) }),
120-
"width" -> JsArray(Seq(width.start, width.end, width.step).map { x => Json.toJson(x) }),
120+
"depth" -> (depth match {
121+
case list: List[Int] =>
122+
JsArray(list.map { x => Json.toJson(x) })
123+
case range: Range =>
124+
JsArray(Seq(range.start, range.end, range.step).map { x => Json.toJson(x) })
125+
}),
126+
"width" -> (width match {
127+
case list: List[Int] =>
128+
JsArray(list.map { x => Json.toJson(x) })
129+
case range: Range =>
130+
JsArray(Seq(range.start, range.end, range.step).map { x => Json.toJson(x) })
131+
}),
121132
"ports" -> JsArray(ports.map { _.toJSON })
122133
)
123134
)
@@ -148,17 +159,35 @@ object SRAMGroup {
148159
case Some(x: JsNumber) => x.value.intValue
149160
case _ => return None
150161
}
151-
val depth: Range = json.get("depth") match {
162+
val triples: Option[Seq[(Int, Int, Int)]] = json.get("triples") match {
163+
case Some(x: JsArray) =>
164+
val seq = x.as[List[JsArray]].map(_.as[List[JsNumber]].map(_.value.intValue))
165+
Some(seq.map(y => (y(0), y(1), y(2))).sorted)
166+
case _ => None
167+
}
168+
val depth: Iterable[Int] = json.get("depth list") match {
152169
case Some(x: JsArray) =>
153170
val seq = x.as[List[JsNumber]].map(_.value.intValue)
154-
Range.inclusive(seq(0), seq(1), seq(2))
155-
case _ => return None
171+
seq.sorted
172+
case _ => json.get("depth") match {
173+
case Some(x: JsArray) =>
174+
val seq = x.as[List[JsNumber]].map(_.value.intValue)
175+
Range.inclusive(seq(0), seq(1), seq(2))
176+
case _ =>
177+
if (triples.isDefined) Seq() else return None
178+
}
156179
}
157-
val width: Range = json.get("width") match {
180+
val width: Iterable[Int] = json.get("width list") match {
158181
case Some(x: JsArray) =>
159182
val seq = x.as[List[JsNumber]].map(_.value.intValue)
160-
Range.inclusive(seq(0), seq(1), seq(2))
161-
case _ => return None
183+
seq.sorted
184+
case _ => json.get("width") match {
185+
case Some(x: JsArray) =>
186+
val seq = x.as[List[JsNumber]].map(_.value.intValue)
187+
Range.inclusive(seq(0), seq(1), seq(2))
188+
case _ =>
189+
if (triples.isDefined) Seq() else return None
190+
}
162191
}
163192
val ports: Seq[MacroPort] = json.get("ports") match {
164193
case Some(x: JsArray) =>
@@ -188,7 +217,7 @@ object SRAMGroup {
188217
}
189218
case _ => List()
190219
}
191-
Some(SRAMGroup(name, family, vt, mux, depth, width, ports, extraPorts))
220+
Some(SRAMGroup(name, family, vt, mux, depth, width, triples, ports, extraPorts))
192221
}
193222
}
194223

tools/tapeout/src/main/scala/macros/MacroCompiler.scala

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -623,10 +623,16 @@ class MacroCompilerPass(
623623
groups
624624
.filter(g => g.family == sram.family && groupMatchesMask(g, sram))
625625
.map(g => {
626-
for {
627-
w <- g.width
628-
d <- g.depth if (sram.width % w == 0) && (sram.depth % d == 0)
629-
} yield Seq(new Macro(buildSRAMMacro(g, d, w, g.vt.head)))
626+
g.triples match {
627+
case Some(triples) =>
628+
for {(d, w, _) <- triples}
629+
yield Seq(new Macro(buildSRAMMacro(g, d, w, g.vt.head)))
630+
case None =>
631+
for {
632+
w <- g.width
633+
d <- g.depth if (sram.width % w == 0) && (sram.depth % d == 0)
634+
} yield Seq(new Macro(buildSRAMMacro(g, d, w, g.vt.head)))
635+
}
630636
})
631637
case None => Seq()
632638
}

0 commit comments

Comments
 (0)