@@ -20,7 +20,7 @@ object Routes extends Enumeration {
2020 val LEFT, UP, RIGHT, DOWN = Value
2121}
2222
23- class RoutesVec (singleElementWidth: Int ) extends Record {
23+ class RoutesVec (singleElementWidth : Int ) extends Record {
2424 val routes = SeqMap (Routes .values.toSeq.map { bus =>
2525 bus -> UInt (singleElementWidth.W )
2626 }: _* )
@@ -30,20 +30,22 @@ class RoutesVec(singleElementWidth:Int) extends Record {
3030 def asSeq : Seq [UInt ] = routes.map(_._2).toSeq
3131}
3232
33- class BusesVec (singleElementWidth: Int , width: Int , height: Int ) extends Record {
34- val routes = SeqMap (Routes .LEFT -> Vec (height, UInt (singleElementWidth.W )),
33+ class BusesVec (singleElementWidth : Int , width : Int , height : Int )
34+ extends Record {
35+ val routes = SeqMap (
36+ Routes .LEFT -> Vec (height, UInt (singleElementWidth.W )),
3537 Routes .RIGHT -> Vec (height, UInt (singleElementWidth.W )),
3638 Routes .UP -> Vec (width, UInt (singleElementWidth.W )),
37- Routes .DOWN -> Vec (width, UInt (singleElementWidth.W )),
39+ Routes .DOWN -> Vec (width, UInt (singleElementWidth.W ))
3840 )
3941 val elements = routes.map { case (a, b) => a.toString().toLowerCase() -> b }
4042
4143 def asMap : SeqMap [Routes .Value , Vec [UInt ]] = routes
4244 def asSeq : Seq [Vec [UInt ]] = routes.map(_._2).toSeq
4345}
4446
45-
46- class MockArray (width : Int , height : Int , singleElementWidth : Int ) extends Module {
47+ class MockArray ( width : Int , height : Int , singleElementWidth : Int )
48+ extends Module {
4749 val io = IO (new Bundle {
4850 val ins = Input (new BusesVec (singleElementWidth, width, height))
4951 val outs = Output (new BusesVec (singleElementWidth, width, height))
@@ -64,35 +66,50 @@ class MockArray(width:Int, height:Int, singleElementWidth:Int) extends Module {
6466 // Registered routing paths
6567 // left <-> down
6668 // up <-> right
67- (io.outs.asSeq zip io.ins.asSeq.reverse.map(RegNext (_))).foreach{case (a, b) => a := b}
69+ (io.outs.asSeq zip io.ins.asSeq.reverse.map(RegNext (_))).foreach {
70+ case (a, b) => a := b
71+ }
6872
6973 // Combinational logic
7074 io.lsbOuts := io.lsbIns.drop(1 ) ++ Seq (io.outs.asSeq.head(0 )(0 ))
7175 }
7276
7377 val ces = Seq .fill(height)(Seq .fill(width)(Module (new Element ())))
7478
75- ces.foreach{ row =>
79+ ces.foreach { row =>
7680 row.head.io.lsbIns := DontCare
7781 if (row.length > 1 ) {
78- row.sliding(2 , 1 ).foreach{ pair =>
82+ row.sliding(2 , 1 ).foreach { pair =>
7983 pair(1 ).io.lsbIns := pair(0 ).io.lsbOuts
84+ }
8085 }
81- }}
86+ }
8287
8388 io.lsbs := RegNext (VecInit (ces.map(_.last.io.lsbOuts).flatten))
8489
8590 // Connect inputs to edge element buses
86- (ces.map(_.head).map(_.io.ins.asMap(Routes .RIGHT )) zip io.ins.asMap(Routes .RIGHT )).foreach { case (a, b) => a := b }
87- (ces.last.map(_.io.ins.asMap(Routes .DOWN )) zip io.ins.asMap(Routes .DOWN )).foreach { case (a, b) => a := b }
88- (ces.map(_.last).map(_.io.ins.asMap(Routes .LEFT )) zip io.ins.asMap(Routes .LEFT )).foreach { case (a, b) => a := b }
89- (ces.head.map(_.io.ins.asMap(Routes .UP )) zip io.ins.asMap(Routes .UP )).foreach { case (a, b) => a := b }
91+ (ces.map(_.head).map(_.io.ins.asMap(Routes .RIGHT )) zip io.ins.asMap(
92+ Routes .RIGHT
93+ )).foreach { case (a, b) => a := b }
94+ (ces.last.map(_.io.ins.asMap(Routes .DOWN )) zip io.ins.asMap(Routes .DOWN ))
95+ .foreach { case (a, b) => a := b }
96+ (ces.map(_.last).map(_.io.ins.asMap(Routes .LEFT )) zip io.ins.asMap(
97+ Routes .LEFT
98+ )).foreach { case (a, b) => a := b }
99+ (ces.head.map(_.io.ins.asMap(Routes .UP )) zip io.ins.asMap(Routes .UP ))
100+ .foreach { case (a, b) => a := b }
90101
91102 // Connect edge element buses to outputs
92- (ces.map(_.head).map(_.io.outs.asMap(Routes .LEFT )) zip io.outs.asMap(Routes .LEFT )).foreach { case (a, b) => b := a }
93- (ces.last.map(_.io.outs.asMap(Routes .UP )) zip io.outs.asMap(Routes .UP )).foreach { case (a, b) => b := a }
94- (ces.map(_.last).map(_.io.outs.asMap(Routes .RIGHT )) zip io.outs.asMap(Routes .RIGHT )).foreach { case (a, b) => b := a }
95- (ces.head.map(_.io.outs.asMap(Routes .DOWN )) zip io.outs.asMap(Routes .DOWN )).foreach { case (a, b) => b := a }
103+ (ces.map(_.head).map(_.io.outs.asMap(Routes .LEFT )) zip io.outs.asMap(
104+ Routes .LEFT
105+ )).foreach { case (a, b) => b := a }
106+ (ces.last.map(_.io.outs.asMap(Routes .UP )) zip io.outs.asMap(Routes .UP ))
107+ .foreach { case (a, b) => b := a }
108+ (ces.map(_.last).map(_.io.outs.asMap(Routes .RIGHT )) zip io.outs.asMap(
109+ Routes .RIGHT
110+ )).foreach { case (a, b) => b := a }
111+ (ces.head.map(_.io.outs.asMap(Routes .DOWN )) zip io.outs.asMap(Routes .DOWN ))
112+ .foreach { case (a, b) => b := a }
96113
97114 // Connect neighboring left/right element buses
98115 (ces.transpose.flatten zip ces.transpose.drop(1 ).flatten).foreach {
@@ -102,18 +119,21 @@ class MockArray(width:Int, height:Int, singleElementWidth:Int) extends Module {
102119 }
103120
104121 // Connect neighboring up/down element buses
105- (ces.flatten zip ces.drop(1 ).flatten).foreach {
106- case (a, b) =>
107- a.io.ins.asMap(Routes .DOWN ) := b.io.outs.asMap(Routes .DOWN )
108- b.io.ins.asMap(Routes .UP ) := a.io.outs.asMap(Routes .UP )
122+ (ces.flatten zip ces.drop(1 ).flatten).foreach { case (a, b) =>
123+ a.io.ins.asMap(Routes .DOWN ) := b.io.outs.asMap(Routes .DOWN )
124+ b.io.ins.asMap(Routes .UP ) := a.io.outs.asMap(Routes .UP )
109125 }
110126}
111127
112- case class ArrayConfig (width : Int = 8 , height : Int = 8 , dataWidth : Int = 8 , remainingArgs : Seq [String ] = Seq .empty)
128+ case class ArrayConfig (
129+ width : Int = 8 ,
130+ height : Int = 8 ,
131+ dataWidth : Int = 8 ,
132+ remainingArgs : Seq [String ] = Seq .empty
133+ )
113134
114135object GenerateMockArray extends App {
115136
116-
117137 val builder = OParser .builder[ArrayConfig ]
118138 val parser = {
119139 import builder ._
@@ -142,9 +162,15 @@ object GenerateMockArray extends App {
142162
143163 OParser .parse(parser, configArgs, ArrayConfig ()) match {
144164 case Some (c) =>
145-
146- new ChiselStage ()
147- .execute(chiselArgs, Seq (ChiselGeneratorAnnotation (() => new MockArray (c.width, c.height, c.dataWidth))))
165+ new ChiselStage ()
166+ .execute(
167+ chiselArgs,
168+ Seq (
169+ ChiselGeneratorAnnotation (() =>
170+ new MockArray (c.width, c.height, c.dataWidth)
171+ )
172+ )
173+ )
148174
149175 case _ =>
150176 // arguments are invalid
0 commit comments