summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjackbackrack2015-07-02 16:37:43 -0700
committerjackbackrack2015-07-02 16:37:43 -0700
commite125a232e6ffcd36f20a2baf73460186ea71f5c0 (patch)
tree9587ed256dfd2e852fe79af2e3bb5e3a7aefceff /src
parent155babe6f0ae394e6ce590a9ffe0f6ada163a06b (diff)
more support for testing FPs
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/FP.scala10
-rw-r--r--src/main/scala/Tester.scala8
2 files changed, 14 insertions, 4 deletions
diff --git a/src/main/scala/FP.scala b/src/main/scala/FP.scala
index 5ad50a92..3c16ce4c 100644
--- a/src/main/scala/FP.scala
+++ b/src/main/scala/FP.scala
@@ -40,7 +40,7 @@ object Flo {
def apply(x: Float): Flo = floLit(x)
def apply(x: Double): Flo = Flo(x.toFloat)
def floLit(value: Float): Flo = {
- val b = new Flo(NO_DIR)
+ val b = new Flo(NO_DIR, Some(value))
pushCommand(DefFlo(b.defd.cid, value))
b
}
@@ -78,8 +78,9 @@ object FloPrimOp {
}
import FloPrimOp._
-class Flo(dir: Direction = NO_DIR) extends Element(dir, 32) with Num[Flo] {
+class Flo(dir: Direction = NO_DIR, val value:Option[Float] = None) extends Element(dir, 32) with Num[Flo] {
type T = Flo;
+ override def floLitValue: Float = value.get
def cloneTypeWidth(width: Int): this.type = cloneType
override def fromBits(n: Bits): this.type = {
val d = cloneType
@@ -150,7 +151,7 @@ object Dbl {
def apply(x: Float): Dbl = Dbl(x.toDouble);
def apply(x: Double): Dbl = dblLit(x)
def dblLit(value: Double): Dbl = {
- val b = new Dbl(NO_DIR)
+ val b = new Dbl(NO_DIR, Some(value))
pushCommand(DefDbl(b.defd.cid, value))
b
}
@@ -188,12 +189,13 @@ object DblPrimOp {
}
import DblPrimOp._
-class Dbl(dir: Direction = null) extends Element(dir, 64) with Num[Dbl] {
+class Dbl(dir: Direction, val value: Option[Double] = None) extends Element(dir, 64) with Num[Dbl] {
// setIsSigned
// override def setIsTypeNode = {inputs(0).setIsSigned; super.setIsTypeNode}
type T = Dbl;
+ override def dblLitValue: Double = value.get
def cloneTypeWidth(width: Int): this.type = cloneType
override def fromBits(n: Bits): this.type = {
val d = cloneType
diff --git a/src/main/scala/Tester.scala b/src/main/scala/Tester.scala
index 91efc146..68fad15d 100644
--- a/src/main/scala/Tester.scala
+++ b/src/main/scala/Tester.scala
@@ -324,6 +324,14 @@ class ManualTester[+T <: Module]
def expect (data: Bits, expected: Long): Boolean = {
expect(data, BigInt(expected))
}
+ def expect (data: Flo, expected: Double): Boolean = {
+ val got = peek(data)
+ expect(got == expected, "EXPECT " + data.debugName + " <- " + got + " == " + expected)
+ }
+ def expect (data: Dbl, expected: Double): Boolean = {
+ val got = peek(data)
+ expect(got == expected, "EXPECT " + data.debugName + " <- " + got + " == " + expected)
+ }
/* Compare the floating point value of a node with an expected floating point value.
* We will tolerate differences in the bottom bit.