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

Commit

Permalink
Merge pull request #1 from chryse-hdl/bb-wider
Browse files Browse the repository at this point in the history
Support a wider range of elements in blackboxes.
  • Loading branch information
kivikakk authored May 18, 2024
2 parents 9c11343 + b972840 commit 8f80147
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ permissions:
contents: read

jobs:
build:
unit-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,21 @@ class BlackBoxGenerator(private val wr: Writer) {
((name, dat)) <-
io.elements.toSeq.reverseIterator
} {
if (elIx > 0) wr.write("\n")
val dir =
dat
.getClass()
.getMethod("specifiedDirection")
classOf[Data]
.getMethod("specifiedDirection") // chisel private :<
.invoke(dat)
.asInstanceOf[SpecifiedDirection]

if (dat.isInstanceOf[Vec[_]]) {
val vec = dat.asInstanceOf[Vec[_]]
for { i <- 0 until vec.length } {
emitWire(s"${name}_$i", dat, dir, elIx)
dat match {
case vec: Vec[_] =>
for { (vecEl, vecElIx) <- vec.getElements.zipWithIndex } {
emitWire(s"${name}_$vecElIx", vecEl, dir, vecEl.getWidth, elIx)
elIx += 1
}
case _ =>
emitWire(name, dat, dir, dat.getWidth, elIx)
elIx += 1
}
} else {
emitWire(name, dat, dir, elIx)
elIx += 1
}

}
throw UnwindException
}
Expand All @@ -57,14 +53,21 @@ class BlackBoxGenerator(private val wr: Writer) {
name: String,
dat: Data,
dir: SpecifiedDirection,
width: Int,
elIx: Integer,
): Unit = {
if (elIx > 0) wr.write("\n")
if (dir == SpecifiedDirection.Input && dat.isInstanceOf[Clock]) {
wr.write(" attribute \\cxxrtl_edge \"p\"\n")
} else if (dir == SpecifiedDirection.Output) {
// XXX: We're assuming this is a synchronous output, but who says it is?
wr.write(" attribute \\cxxrtl_sync 1\n")
}
wr.write(s" wire ${dir.toString().toLowerCase()} ${elIx + 1} \\$name\n")
wr.write(s" wire ${dir.toString().toLowerCase()} ${elIx + 1}")
if (width != 1) {
wr.write(s" width $width")
}
wr.write(s" \\$name\n")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,34 @@ class BlackBoxGeneratorSpec extends AnyFlatSpec with Matchers {
|attribute \blackbox 1
|module \VecOfBoolBB
| wire input 1 \d_in_0
|
| wire input 2 \d_in_1
|
| wire input 3 \d_in_2
|
| attribute \cxxrtl_sync 1
| wire output 4 \d_out_0
|
| attribute \cxxrtl_sync 1
| wire output 5 \d_out_1
|end
""".stripMargin)
}

it should "expand wider elements correctly" in {
val sw = new StringWriter
BlackBoxGenerator(sw, classOf[WiderElementsBB])
sw.toString() should be("""attribute \cxxrtl_blackbox 1
|attribute \blackbox 1
|module \WiderElementsBB
| wire input 1 width 64 \d_in
|
| attribute \cxxrtl_sync 1
| wire output 2 width 8 \d_out_0
|
| attribute \cxxrtl_sync 1
| wire output 3 width 8 \d_out_1
|end
""".stripMargin)
}
}
Expand All @@ -60,3 +80,10 @@ private class VecOfBoolBB extends BlackBox {
val d_out = Output(Vec(2, Bool()))
})
}

private class WiderElementsBB extends BlackBox {
val io = IO(new Bundle {
val d_in = Input(UInt(64.W))
val d_out = Output(Vec(2, SInt(8.W)))
})
}

0 comments on commit 8f80147

Please sign in to comment.