Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev' into apb4
Browse files Browse the repository at this point in the history
  • Loading branch information
jijingg committed Nov 29, 2022
2 parents 00916fc + c622832 commit 72e5914
Show file tree
Hide file tree
Showing 36 changed files with 720 additions and 88 deletions.
1 change: 1 addition & 0 deletions .mill_version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.10.9
8 changes: 4 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import sbt.Keys._
import sbt._
import sbt.Tests._


val scalatestVersion = "3.2.5"
val defaultSettings = Defaults.coreDefaultSettings ++ xerial.sbt.Sonatype.sonatypeSettings ++ Seq(
organization := "com.github.spinalhdl",
version := SpinalVersion.all,
Expand All @@ -26,6 +26,7 @@ val defaultSettings = Defaults.coreDefaultSettings ++ xerial.sbt.Sonatype.sonaty
// concurrentRestrictions := Seq(Tags.limit(Tags.ForkedTestGroup, 4)),

libraryDependencies += "org.scala-lang" % "scala-library" % scalaVersion.value,
libraryDependencies += "org.scalatest" %% "scalatest" % scalatestVersion % "test",

dependencyOverrides += "net.java.dev.jna" % "jna" % "5.5.0",
dependencyOverrides += "net.java.dev.jna" % "jna-platform" % "5.5.0",
Expand Down Expand Up @@ -157,7 +158,7 @@ lazy val lib = (project in file("lib"))
defaultSettingsWithPlugin,
name := "SpinalHDL-lib",
libraryDependencies += "commons-io" % "commons-io" % "2.4",
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.5",
libraryDependencies += "org.scalatest" %% "scalatest" % scalatestVersion,
version := SpinalVersion.lib
)
.dependsOn (sim, core)
Expand All @@ -170,8 +171,7 @@ lazy val tester = (project in file("tester"))
name := "SpinalHDL-tester",
version := SpinalVersion.tester,
Test / baseDirectory := file("./"),

libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.5",
libraryDependencies += "org.scalatest" %% "scalatest" % scalatestVersion,
publishArtifact := false,
publishLocal := {}
)
Expand Down
110 changes: 110 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
// build.sc
import mill._, scalalib._, publish._
import $file.project.Version

trait SpinalModule extends SbtModule { outer =>
def scalaVersion = Version.SpinalVersion.compilers(0)
def scalacOptions = super.scalacOptions() ++ Seq("-unchecked", "-target:jvm-1.8")
def javacOptions = super.javacOptions() ++ Seq("-source", "1.8", "-target", "1.8")

val IvyDeps = Agg(
ivy"org.scala-lang:scala-library:${scalaVersion}",
ivy"net.java.dev.jna:jna:5.5.0",
ivy"net.java.dev.jna:jna-platform:5.5.0",
ivy"org.slf4j:slf4j-api:1.7.25",
ivy"org.scala-lang.modules::scala-xml:1.2.0"
)
}

trait SpinalPublishModule extends PublishModule {
def publishVersion = Version.SpinalVersion.all
def artifactName = "spinalhdl-" + super.artifactName()

def pomSettings = PomSettings(
description = "SpinalHDL",
organization = "com.github.spinalhdl",
url = "https://github.com/SpinalHDL/SpinalHDL",
licenses = Seq(License.`LGPL-3.0-or-later`),
versionControl = VersionControl.github("SpinalHDL", "SpinalHDL"),
developers = Seq(
Developer("Dolu1990", "SpinalHDL", "https://github.com/SpinalHDL")
)
)
}

object idslpayload extends SpinalModule with SpinalPublishModule {
def mainClass = Some("spinal.idslpayload")
override def artifactName = "spinalhdl-idsl-payload"
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scala-lang:scala-reflect:${scalaVersion}")
}

object idslplugin extends SpinalModule with SpinalPublishModule {
def mainClass = Some("spinal.idslplugin")
override def artifactName = "spinalhdl-idsl-plugin"
def moduleDeps = Seq(idslpayload)
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scala-lang:scala-compiler:${scalaVersion}")
def pluginOptions = T { Seq(s"-Xplugin:${assembly().path}") }
}

object sim extends SpinalModule with SpinalPublishModule {
def mainClass = Some("spinal.sim")
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"commons-io:commons-io:2.4",
ivy"net.openhft:affinity:3.21ea1.1",
ivy"org.slf4j:slf4j-simple:1.7.25",
ivy"com.github.oshi:oshi-core:5.2.0"
)
def publishVersion = Version.SpinalVersion.sim
}

object lib extends SpinalModule with SpinalPublishModule {
def mainClass = Some("spinal.lib")
def moduleDeps = Seq(core, sim)
def scalacOptions = super.scalacOptions() ++ idslplugin.pluginOptions()
def ivyDeps = super.ivyDeps() ++ Agg(ivy"commons-io:commons-io:2.4", ivy"org.scalatest::scalatest:3.2.5")
def publishVersion = Version.SpinalVersion.lib
}

import sys.process._
def gitHash(dir: os.Path) = (try {
s"git -C ${dir.toString} rev-parse HEAD".!!
} catch {
case e: java.io.IOException => "???"
}).linesIterator.next()

object core extends SpinalModule with SpinalPublishModule {
def mainClass = Some("spinal.core")
def moduleDeps = Seq(idslplugin, sim)

def scalacOptions = super.scalacOptions() ++ idslplugin.pluginOptions()
def ivyDeps = super.ivyDeps() ++ Agg(
ivy"org.scala-lang:scala-reflect:${scalaVersion}",
ivy"com.github.scopt::scopt:3.7.1",
ivy"com.lihaoyi::sourcecode:0.2.7"
)

override def generatedSources = T {
val dest = T.dest / "Info.scala"
val code =
s"""package spinal.core
|object Info {
| val version = "%s"
| val name = "%s"
| val gitHash = "%s"
|}
|""".stripMargin.format(Version.SpinalVersion.core, mainClass, gitHash(T.dest))
os.write(dest, code, createFolders = true)
Seq(PathRef(T.dest))
}
}

object tester extends SpinalModule {
def mainClass = Some("spinal.tester")
def moduleDeps = Seq(core, sim, lib)
def scalacOptions = super.scalacOptions() ++ idslplugin.pluginOptions()
def ivyDeps = super.ivyDeps() ++ Agg(ivy"org.scalatest::scalatest:3.2.5")

object test extends Tests with TestModule.ScalaTest {
def ivyDeps = Agg(ivy"org.scalatest::scalatest::3.2.5")
}
}
13 changes: 8 additions & 5 deletions core/src/main/scala/spinal/core/Bool.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ import spinal.core.internals.Operator.Formal
import spinal.core.internals._
import spinal.idslplugin.Location

/**
* Bool factory used for instance by the IODirection to create a in/out Bool()
*/
/** Bool factory used for instance by the IODirection to create a in/out Bool() */
trait BoolFactory {
@deprecated("Use `Bool()` (with braces) instead")
def Bool: Bool = Bool()

/** Create a new Bool */
// def Bool(): Bool = new Bool
}
def Bool(u: Unit = ()): Bool = new Bool

/** Create a new Bool with a value */
def Bool(value: Boolean): Bool = BoolLiteral(value, Bool().setAsTypeNode())
}

/**
* The Bool type corresponds to a boolean value (True or False)
Expand Down
43 changes: 41 additions & 2 deletions core/src/main/scala/spinal/core/FixedPoint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ trait UFixCast {
* Base class for SFix and UFix
*/
abstract class XFix[T <: XFix[T, R], R <: BitVector with Num[R]](val maxExp: Int, val bitCount: Int) extends MultiData with MinMaxDecimalProvider {

require(bitCount >= 0)
require(bitCount >= 0, s"Length of fixed point number must be > 0 (not $bitCount)")

val raw = rawFactory(maxExp, bitCount)

Expand All @@ -185,6 +184,8 @@ abstract class XFix[T <: XFix[T, R], R <: BitVector with Num[R]](val maxExp: Int

def rawFactory(exp: Int, bitCount: Int): R
def fixFactory(exp: Int, bitCount: Int): T
def fixFactory(maxExp: ExpNumber, bitCount: BitCount): T
def fixFactory(maxExp: ExpNumber, resolution: ExpNumber): T

def difLsb(that: T) = (this.maxExp - this.bitCount) - (that.maxExp - that.bitCount)

Expand Down Expand Up @@ -247,6 +248,17 @@ abstract class XFix[T <: XFix[T, R], R <: BitVector with Num[R]](val maxExp: Int
copy.asInstanceOf[this.type]
}

def truncated(maxExp: ExpNumber, bitCount: BitCount): T = {
val t = fixFactory(maxExp, bitCount)
t := this.truncated.asInstanceOf[T]
t
}
def truncated(maxExp: ExpNumber, resolution: ExpNumber): T = {
val t = fixFactory(maxExp, resolution)
t := this.truncated.asInstanceOf[T]
t
}

override private[spinal] def assignFromImpl(that: AnyRef, target: AnyRef, kind: AnyRef): Unit = {
that match {
case that if this.getClass.isAssignableFrom(that.getClass) =>
Expand All @@ -267,6 +279,28 @@ abstract class XFix[T <: XFix[T, R], R <: BitVector with Num[R]](val maxExp: Int
case _ => SpinalError("Undefined assignment")
}
}

override def getMuxType[M <: Data](list: TraversableOnce[M]): HardType[M] = {
val fixed = list.filter(u => !u.hasTag(tagTruncated)).toSeq
assert(fixed.nonEmpty, "Can't generate mux for all-truncated fixed point numbers")
val muxMaxExp = fixed.map {
case x: XFix[T,R] => x.maxExp
}.max
val muxMinExp = fixed.map {
case x: XFix[T,R] => x.minExp
}.min
HardType(fixFactory(muxMaxExp exp, muxMinExp exp).asInstanceOf[M])
}

override def toMuxInput[M <: Data](muxOutput: M): M = {
muxOutput match {
case m: XFix[T,R] if(m.maxExp ==maxExp && m.bitCount == bitCount) => this.asInstanceOf[M]
case _ =>
val ret = cloneOf(muxOutput)
ret.assignFrom(this)
ret
}
}
}

//TODO Fix autoconnect
Expand All @@ -279,6 +313,8 @@ class SFix(maxExp: Int, bitCount: Int) extends XFix[SFix, SInt](maxExp, bitCount
override def rawFactory(maxExp: Int, bitCount: Int): SInt = SInt(bitCount bit)

override def fixFactory(maxExp: Int, bitCount: Int): SFix = SFix(maxExp exp, bitCount bit)
override def fixFactory(maxExp: ExpNumber, bitCount: BitCount): SFix = SFix(maxExp, bitCount)
override def fixFactory(maxExp: ExpNumber, resolution: ExpNumber): SFix = SFix(maxExp, resolution)

override def minExp: Int = maxExp - bitCount + 1

Expand Down Expand Up @@ -425,6 +461,9 @@ class UFix(maxExp: Int, bitCount: Int) extends XFix[UFix, UInt](maxExp, bitCount

override def rawFactory(maxExp: Int, bitCount: Int): UInt = UInt(bitCount bit)
override def fixFactory(maxExp: Int, bitCount: Int): UFix = UFix(maxExp exp, bitCount bit)
override def fixFactory(maxExp: ExpNumber, bitCount: BitCount): UFix = UFix(maxExp, bitCount)
override def fixFactory(maxExp: ExpNumber, resolution: ExpNumber): UFix = UFix(maxExp, resolution)

override def minExp: Int = maxExp - bitCount

def +(that: UFix): UFix = doAddSub(that, sub = false)
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/spinal/core/IODirection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sealed trait IODirection extends BaseTypeFactory {
*
* See [[IODirection]] for other syntaxes.
*/
def Bool(u: Unit = ()): Bool = port(spinal.core.Bool())
override def Bool(u: Unit = ()): Bool = port(super.Bool())

override def Bits(u: Unit = ()): Bits = port(super.Bits())

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/scala/spinal/core/Mem.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ object dontCare extends ReadUnderWritePolicy with DuringWritePolicy{
override def duringWriteString: String = "dontCare"
}

object eitherFirst extends ReadUnderWritePolicy with DuringWritePolicy{
override def readUnderWriteString: String = "eitherFirst"
override def duringWriteString: String = "eitherFirst"
}

object writeFirst extends ReadUnderWritePolicy {
override def readUnderWriteString: String = "writeFirst"
Expand Down
9 changes: 9 additions & 0 deletions core/src/main/scala/spinal/core/Trait.scala
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,15 @@ object Nameable{
val DATAMODEL_WEAK : Byte = 5
val USER_WEAK : Byte = 0
val REMOVABLE : Byte = -5

def getNameWithoutPrefix(prefix : Nameable, from : Nameable): String ={
val stageSlices = prefix.getName.split('_')
val postfixSlices = from.getName.split('_')
var i = 0
val iEnd = stageSlices.length min postfixSlices.length
while(i != iEnd && stageSlices(i) == postfixSlices(i)) i += 1
postfixSlices.drop(i).mkString("_")
}
}


Expand Down
6 changes: 1 addition & 5 deletions core/src/main/scala/spinal/core/core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ package object core extends BaseTypeFactory with BaseTypeCast {
type Module = spinal.core.Component
type dontName = spinal.core.DontName @field

def Bool : Bool = new Bool
def Bool(u: DummyTrait = DummyObject) : Bool = new Bool
def Bool(value: Boolean): Bool = BoolLiteral(value, this.Bool().setAsTypeNode())

/**
* Scala implicit
*/
Expand Down Expand Up @@ -268,7 +264,7 @@ package object core extends BaseTypeFactory with BaseTypeCast {
/**
* True / False definition
*/
def True = Bool(true) //Should be def, not val, else it will create cross hierarchy usage of the same instance
def True = Bool(true)
def False = Bool(false)


Expand Down
30 changes: 4 additions & 26 deletions core/src/main/scala/spinal/core/formal/FormalBootstraps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
package spinal.core.formal

import java.io.{File, PrintWriter}

import org.apache.commons.io.FileUtils
import spinal.core.internals.{PhaseContext, PhaseNetlist}
import spinal.core.{Component, GlobalData, SpinalConfig, SpinalReport, BlackBox}
import spinal.core.sim.SimWorkspace
import spinal.core.{BlackBox, Component, GlobalData, SpinalConfig, SpinalReport}
import spinal.sim._

import scala.collection.mutable
Expand All @@ -41,30 +41,8 @@ trait FormalBackend {
/** Formal verify Workspace
*/
object FormalWorkspace {
private var uniqueId = 0

def allocateUniqueId(): Int = {
this.synchronized {
uniqueId = uniqueId + 1
uniqueId
}
}

val workspaceMap = mutable.HashMap[(String, String), Int]()

def allocateWorkspace(path: String, name: String): String = {
workspaceMap.synchronized {
val value = workspaceMap.getOrElseUpdate((path, name), 0)
workspaceMap((path, name)) = value + 1
if (value == 0) {
return name
} else {
val ret = name + "_" + value
println(s"[Info] Workspace '$name' was reallocated as '$ret' to avoid collision")
return ret
}
}
}
def allocateUniqueId(): Int = SimWorkspace.allocateUniqueId()
def allocateWorkspace(path: String, name: String): String = SimWorkspace.allocateWorkspace(path, name)
}

class SpinalFormalBackendSel
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/scala/spinal/core/sim/SimBootstraps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ abstract class SimCompiled[T <: Component](val report: SpinalReport[T]){
def newSeed(): Int = {
sys.env.get("SPINAL_SIM_SEED") match {
case Some(v) => v.toInt
case None => Random.nextInt(2000000000)
case None => Random.nextInt(Integer.MAX_VALUE)
}
}

Expand Down
Loading

0 comments on commit 72e5914

Please sign in to comment.