Browse Source

Remove delayed init from bundle to allow inner class bundle declaration

cleaning of mandelbrot
tags/v0.5.7
Dolu 4 years ago
parent
commit
107a0dda3c
10 changed files with 67 additions and 63 deletions
  1. +1
    -1
      core/src/main/scala/spinal/core/BaseType.scala
  2. +1
    -1
      core/src/main/scala/spinal/core/Bundle.scala
  3. +1
    -10
      core/src/main/scala/spinal/core/Data.scala
  4. +8
    -35
      core/src/main/scala/spinal/core/MultiData.scala
  5. +2
    -1
      core/src/main/scala/spinal/core/Trait.scala
  6. +7
    -8
      demo/src/main/scala/spinal/demo/mandelbrot/FrameTaskSolver.scala
  7. +9
    -0
      lib/src/main/scala/spinal/lib/graphic/Rgb.scala
  8. +1
    -6
      lib/src/main/scala/spinal/lib/graphic/vga/Vga.scala
  9. +3
    -1
      lib/src/main/scala/spinal/lib/graphic/vga/VgaCtrl.scala
  10. +34
    -0
      storage/souvenirsouvenir.txt

+ 1
- 1
core/src/main/scala/spinal/core/BaseType.scala View File

@@ -153,7 +153,7 @@ abstract class BaseType extends Node with Data with Nameable {
// override def :=(bits: this.type): Unit = assignFrom(bits)


override def getZero: this.type

def assignFromImpl(that: AnyRef, conservative: Boolean): Unit = {
that match {

+ 1
- 1
core/src/main/scala/spinal/core/Bundle.scala View File

@@ -81,7 +81,7 @@ class Bundle extends MultiData with Nameable with OverridedEqualsHashCode {
Misc.reflect(this, (name, obj) => {
obj match {
case data: Data => {
if (data.parentData == this) { //To avoid bundle argument
if (this.isOlderThan(data)) { //To avoid bundle argument
elementsCache += Tuple2(name, data)
}
}

+ 1
- 10
core/src/main/scala/spinal/core/Data.scala View File

@@ -155,16 +155,7 @@ trait Data extends ContextUser with Nameable with Assignable with AttributeReady
}


val parentData = globalData.dataStack.head()

def getZero: this.type = {
val ret = clone()
ret.flatten.foreach(t => {
t := t.getZero
})

ret
}
def getZero: this.type

def flatten: Seq[BaseType]


+ 8
- 35
core/src/main/scala/spinal/core/MultiData.scala View File

@@ -23,42 +23,8 @@ import scala.collection.mutable.ArrayBuffer
object MultiData {
// var tab = 0
}
abstract class MultiData extends Data with DelayedInit {
globalData.dataStack.push(this)
//println(" " * MultiData.tab + "push")
// MultiData.tab += 1
override def delayedInit(body: => Unit) = {
body


def getLastBodyClass(clazz: Class[_]): Class[_] = {
val endPoint = "delayedEndpoint$" + clazz.getName.replace(".", "$") + "$1"
for (m <- clazz.getDeclaredMethods) {
// if(m.getName.startsWith("delayedEndpoint$"))
if (m.getName == endPoint)
return clazz
}
return getLastBodyClass(clazz.getSuperclass)
}
if ((body _).getClass.getDeclaringClass == getLastBodyClass(this.getClass)) {
//println(" " * MultiData.tab + "-")
//if (globalData.dataStack.head() == this) {
if (globalData.dataStack.head() != this) {
SpinalError(
"""
|*** One of your bundle as a empty body.
|*** It's not allowed for the moment (in scala 2.12 it will be)
|*** Please, put a dummy field like "val dummy = 0" into the empty bundle """.stripMargin + globalData.dataStack.head().getScalaLocationString)
}
abstract class MultiData extends Data {

globalData.dataStack.pop(this)
//MultiData.tab -= 1
//println(" " * MultiData.tab + "pop")
//}
//else
// println("????")
}
}


def elements: ArrayBuffer[(String, Data)]
@@ -176,4 +142,11 @@ abstract class MultiData extends Data with DelayedInit {
task(e, other)
})
}
override def getZero: this.type = {
val ret = clone()
ret.elements.foreach(e => {
e._2 := e._2.getZero
})
ret
}
}

+ 2
- 1
core/src/main/scala/spinal/core/Trait.scala View File

@@ -85,6 +85,8 @@ trait ContextUser extends GlobalDataUser {
var component = Component.current(globalData)
var whenScope = globalData.whenStack.head()
var instanceCounter = globalData.getInstanceCounter

def isOlderThan(that : ContextUser) : Boolean = this.instanceCounter < that.instanceCounter
}

trait GlobalDataUser {
@@ -354,7 +356,6 @@ class GlobalData {
val componentStack = new SafeStack[Component]
val switchStack = new SafeStack[SwitchStack]
val whenStack = new SafeStack[when]
val dataStack = new SafeStack[Data]

var scalaLocatedEnable = false
var instanceCounter = 0

+ 7
- 8
demo/src/main/scala/spinal/demo/mandelbrot/FrameTaskSolver.scala View File

@@ -84,7 +84,7 @@ class PixelTaskSolver(p: MandelbrotCoreParameters) extends Component {
}

//It's the context definition used by each stage of the pipeline, Each task are translated to context ("thread")
abstract class ContextBase(p: MandelbrotCoreParameters) extends Bundle {
class Context extends Bundle {
val task = PixelTask(p)
val lastPixel = Bool
val done = Bool
@@ -92,16 +92,15 @@ class PixelTaskSolver(p: MandelbrotCoreParameters) extends Component {
val iteration = UInt(p.iterationWidth bit)
val z = SFix2D(p.fix)
}
case class Context(p: MandelbrotCoreParameters) extends ContextBase(p)
//Extended context with x*x y*y x*y result
case class Stage2Context(p: MandelbrotCoreParameters) extends ContextBase(p) {
class Stage2Context extends Context {
val zXzX = p.fix
val zYzY = p.fix
val zXzY = p.fix
}



def fixMul(a: SFix, b: SFix): SFix = {
Delay(a * b, 3)
}
@@ -110,7 +109,7 @@ class PixelTaskSolver(p: MandelbrotCoreParameters) extends Component {
val insertTaskOrder = Counter(16,io.pixelTask.fire)

//Task to insert into the pipeline
val taskToInsert : Handshake[Context] = io.pixelTask.translateInto(Handshake(Context(p)))((to,from) => {
val taskToInsert : Handshake[Context] = io.pixelTask.translateInto(Handshake(new Context))((to,from) => {
to.task := from.fragment
to.lastPixel := from.last
to.done := False
@@ -118,7 +117,7 @@ class PixelTaskSolver(p: MandelbrotCoreParameters) extends Component {
to.iteration := 0
to.z := from.fragment.mandelbrotPosition
})
val loopBack = RegFlow(new Context(p)) //Loop back from end of pipeline
val loopBack = RegFlow(new Context) //Loop back from end of pipeline
val stage0 = HandshakeFlowArbiter(taskToInsert,loopBack) //First stage


@@ -130,7 +129,7 @@ class PixelTaskSolver(p: MandelbrotCoreParameters) extends Component {


//Stage2 get multiplication result of x*x y*y and x*y
val stage2 = RegFlow(new Stage2Context(p))
val stage2 = RegFlow(new Stage2Context)
stage2 assignSomeByName Delay(stage1,3)

stage2.data.zXzX := fixMul(stage1.data.z.x, stage1.data.z.x)
@@ -143,7 +142,7 @@ class PixelTaskSolver(p: MandelbrotCoreParameters) extends Component {
//Stage3 calculate next position of the iteration (zX,zY)
// Increment the iteration count if was not done
// calculate if the "Thread" has rush a end condition (iteration > N, x*x+y*y + 4)
val stage3 = RegFlow(new Context(p))
val stage3 = RegFlow(new Context)
stage3 assignAllByName stage2

stage3.data.z.x := stage2.data.zXzX - stage2.data.zYzY + stage2.data.task.mandelbrotPosition.x

+ 9
- 0
lib/src/main/scala/spinal/lib/graphic/Rgb.scala View File

@@ -0,0 +1,9 @@
package spinal.lib.graphic

import spinal.core._

case class Rgb(rWidth : Int,gWidth : Int,bWidth : Int) extends Bundle{
val r = UInt(rWidth bit)
val g = UInt(gWidth bit)
val b = UInt(bWidth bit)
}

+ 1
- 6
lib/src/main/scala/spinal/lib/graphic/vga/Vga.scala View File

@@ -2,7 +2,7 @@ package spinal.lib.graphic.vga

import spinal.core._
import spinal.lib._
import spinal.lib.graphic.Rgb


case class Vga (rgbType : Rgb) extends Bundle with IMasterSlave{
@@ -16,8 +16,3 @@ case class Vga (rgbType : Rgb) extends Bundle with IMasterSlave{
}


case class Rgb(rWidth : Int,gWidth : Int,bWidth : Int) extends Bundle{
val r = UInt(rWidth bit)
val g = UInt(gWidth bit)
val b = UInt(bWidth bit)
}

+ 3
- 1
lib/src/main/scala/spinal/lib/graphic/vga/VgaCtrl.scala View File

@@ -2,6 +2,7 @@ package spinal.lib.graphic.vga

import spinal.core._
import spinal.lib._
import spinal.lib.graphic.Rgb

case class VgaTimingsHV(timingsWidth : Int) extends Bundle{
val colorStart = UInt(timingsWidth bit)
@@ -53,12 +54,13 @@ class VgaCtrl(rgbType : Rgb,timingsWidth : Int = 12) extends Component{
val h = HVArea(io.timings.h,True)
val v = HVArea(io.timings.v,h.syncEnd)
val colorEn = h.colorEn && v.colorEn
io.colorLink.ready := colorEn

io.frameStart := v.syncEnd

io.vga.hSync := h.sync
io.vga.vSync := v.sync
io.vga.color := (io.colorLink & colorEn).toFlow.data
io.vga.color := Mux(colorEn,io.colorLink.data,rgbType.getZero)
}



+ 34
- 0
storage/souvenirsouvenir.txt View File

@@ -0,0 +1,34 @@
//println(" " * MultiData.tab + "push")
// MultiData.tab += 1
// override def delayedInit(body: => Unit) = {
// body
//
//
// def getLastBodyClass(clazz: Class[_]): Class[_] = {
// val endPoint = "delayedEndpoint$" + clazz.getName.replace(".", "$") + "$1"
// for (m <- clazz.getDeclaredMethods) {
// // if(m.getName.startsWith("delayedEndpoint$"))
// if (m.getName == endPoint)
// return clazz
// }
// return getLastBodyClass(clazz.getSuperclass)
// }
// if ((body _).getClass.getDeclaringClass == getLastBodyClass(this.getClass)) {
// //println(" " * MultiData.tab + "-")
// //if (globalData.dataStack.head() == this) {
// if (globalData.dataStack.head() != this) {
// SpinalError(
// """
// |*** One of your bundle as a empty body.
// |*** It's not allowed for the moment (in scala 2.12 it will be)
// |*** Please, put a dummy field like "val dummy = 0" into the empty bundle """.stripMargin + globalData.dataStack.head().getScalaLocationString)
// }
//
// globalData.dataStack.pop(this)
// //MultiData.tab -= 1
// //println(" " * MultiData.tab + "pop")
// //}
// //else
// // println("????")
// }
// }

Loading…
Cancel
Save