Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/scala/Backend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ abstract class Backend extends FileSystemUtilities{
case reg: Reg if reg.name == "" =>
reg setName "R" + reg.component.nextIndex

case node: Node if !node.isTypeNode && node.name == "" =>
case node: Node if !node.isTypeNode && node.name == "" && node.component != null =>
node.name = "T" + node.component.nextIndex
case _ =>
} }
Expand Down
5 changes: 4 additions & 1 deletion src/main/scala/Bundle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ class Bundle(val view: Seq[String] = null) extends Aggregate {
if( types.length == 0 && !isStatic(modifiers) && isInterface
&& !(name contains '$')
&& !(Bundle.keywords contains name)
&& (view == null || (view contains name)) ) {
&& (view == null || (view contains name))
&& checkPort(m, name)) {
val obj = m invoke this
if(!(seen contains obj)) {
obj match {
Expand All @@ -93,6 +94,8 @@ class Bundle(val view: Seq[String] = null) extends Aggregate {
elts
}

protected def checkPort(obj : Any, name : String) : Boolean = true

lazy val elements = calcElements(view)

def fromMap(elemmap: Map[String, Data]): this.type = {
Expand Down
53 changes: 50 additions & 3 deletions src/main/scala/Complex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,27 @@ object Complex {
def apply[T<:Data with Num[T]](real: T, imag: T) = new Complex(real, imag)
}

class Complex[T<:Data with Num[T]](val real: T, val imag: T) extends Bundle {
object conjugate {
def apply[T<: Data with Num[T]](x : T) : T = x match {
case x : Complex[_] => x.conj.asInstanceOf[T]
case _ => x
}
}

class Complex[T<:Data with Num[T]](val real: T, val imag: T) extends Bundle with Num[Complex[T]] {
override def clone() = {
new Complex(real.clone, imag.clone).asInstanceOf[this.type]
}

override protected def checkPort(obj : Any, name : String) : Boolean = name match {
case "real" => true
case "imag" => true
case "abs2" => false
case "conj" => false
case "unary_-" => false
case _ => true
}

def * (r: Complex[T]): Complex[T] =
{
val a = real; val b = imag; val c = r.real; val d = r.imag;
Expand All @@ -60,12 +76,43 @@ class Complex[T<:Data with Num[T]](val real: T, val imag: T) extends Bundle {
}
}

def / (r: Complex[T]): Complex[T] = ???

def conj : Complex[T] =
{
new Complex(real, -imag)
}
def / (r: Complex[T]): Complex[T] =
{
this * r.conj / r.abs2
}
def * (r: T): Complex[T] =
{
new Complex(real*r, imag*r)
}
def % (r : Complex[T]): Complex[T] =
{
// this is bad, but what can we do?
new Complex(real % r.real, imag % r.imag)
}
def < (b : Complex[T]) : Bool =
{
this.abs2 < b.abs2
}
def <= (b : Complex[T]) : Bool =
{
this.abs2 <= b.abs2
}
def > (b : Complex[T]) : Bool =
{
this.abs2 > b.abs2
}
def >= (b : Complex[T]) : Bool =
{
this.abs2 >= b.abs2
}
def abs2 : T =
{
real * real + imag * imag
}
def / (r: T): Complex[T] =
{
new Complex(real/r, imag/r)
Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/Cpp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class CppBackend extends Backend {
} else if (o.op == "~") {
block((0 until words(o)).map(i => emitWordRef(o, i) + " = ~" + emitWordRef(o.inputs(0), i))) + trunc(o)
} else if (o.op == "f-")
" " + emitLoWordRef(o) + " = fromFloat(-(toFloat(" + emitLoWordRef(o.inputs(0)) + "));\n"
" " + emitLoWordRef(o) + " = fromFloat(-(toFloat(" + emitLoWordRef(o.inputs(0)) + ")));\n"
else if (o.op == "fsin")
" " + emitLoWordRef(o) + " = fromFloat(sin(toFloat(" + emitLoWordRef(o.inputs(0)) + ")));\n"
else if (o.op == "fcos")
Expand Down Expand Up @@ -474,6 +474,8 @@ class CppBackend extends Backend {
" " + emitLoWordRef(o) + " = toFloat(" + emitLoWordRef(o.inputs(0)) + ") != toFloat(" + emitLoWordRef(o.inputs(1)) + ");\n"
} else if (o.op == "f>") {
" " + emitLoWordRef(o) + " = toFloat(" + emitLoWordRef(o.inputs(0)) + ") > toFloat(" + emitLoWordRef(o.inputs(1)) + ");\n"
} else if (o.op == "f<") {
" " + emitLoWordRef(o) + " = toFloat(" + emitLoWordRef(o.inputs(0)) + ") < toFloat(" + emitLoWordRef(o.inputs(1)) + ");\n"
} else if (o.op == "f<=") {
" " + emitLoWordRef(o) + " = toFloat(" + emitLoWordRef(o.inputs(0)) + ") <= toFloat(" + emitLoWordRef(o.inputs(1)) + ");\n"
} else if (o.op == "f>=") {
Expand Down