-
Notifications
You must be signed in to change notification settings - Fork 76
Reintroduce FixedPoint support #706
base: 5.x
Are you sure you want to change the base?
Conversation
With lots of inspiration from the firrtl build.sbt.
This reverts commit d8a44b2. We only revert FixedPoint support, not Interval. We also do not revert changes in chiseltest.iotesters, since that codebase was ported into dsptools.
Thanks for working on this. I will do a detailed review later. Currently the major thing you will have to fix is that I do not want to add the fixed point library as a submodule. Instead, As an alternative to depending on a published version of the fixed point library, we could also investigate what it would take to change |
Thanks for the quick reply! I agree that I will ask whether the |
It seems very feasible to move A few remarks:
This last one fails with:
If I remove the intercept:
I'm not entirely sure, but would think the problem is with: val expectStackDepth = trace.getStackTrace.indexWhere(ste =>
ste.getClassName.startsWith(
"chiseltest.package$"
) && (ste.getMethodName == "expect" || ste.getMethodName == "expectPartial")
) We need somehow to pass |
I think we will be able to make that more public, such that you can use it without copying.
Could you see if there is an easy way to make this list that it is checking against extensible? Or maybe even just confirm that adding your package to the check makes everything else work. Then we could try together to allow an external package to add itself. |
I created another branch of
As you mentioned, I can also make this last check extensible for other package names. However, I was wondering if that is really necessary. What does this check avoid? If there is a method called |
On another note, in a project of mine, we created some extensions to This looks roughly like this: object ChiselTestUtilities {
trait Pokeable[A <: Data, B] {
def poke(data: A, value: B): Unit
}
trait Expectable[A <: Data, B] {
def expect(data: A, value: B): Unit
}
trait ExpectableEpsilon[A <: Data, B] {
def expect(data: A, value: B, epsilon: Double): Unit
}
// Implicit class for extension method syntax
implicit class PeekPokeableOps[A <: Data](data: A) {
def poke[B](value: B)(implicit p: Pokeable[A, B]) = p.poke(data, value)
def expect[B](value: B)(implicit p: Expectable[A, B]) = p.expect(data, value)
def expect[B](value: B, epsilon: Double)(implicit p: ExpectableEpsilon[A, B]) = p.expect(data, value, epsilon)
}
// Poking a Vec[A] with Iterable[B] needs evidence of a Pokeable[A, B]
// Here we redefine all native chiselTest pokes as Pokeable instances
implicit val pokeUIntWithUInt: Pokeable[UInt, UInt] =
(data: UInt, value: UInt) => chiseltest.testableUInt(data).poke(value)
implicit val pokeUIntWithInt: Pokeable[UInt, Int] =
(data: UInt, value: Int) => chiseltest.testableUInt(data).poke(value)
implicit val pokeUIntWithLong: Pokeable[UInt, Long] =
(data: UInt, value: Long) => chiseltest.testableUInt(data).poke(value)
implicit val pokeUIntWithBigInt: Pokeable[UInt, BigInt] =
(data: UInt, value: BigInt) => chiseltest.testableUInt(data).poke(value)
// We can also define new Pokeable instances that are not native in chiseltest
implicit val pokeDspComplexWithComplex: Pokeable[DspComplex[FixedPoint], Complex] =
(data: DspComplex[FixedPoint], value: Complex) => { data.real.poke(value.real); data.imag.poke(value.imag) }
// Now we can have a generic method for poking a `Vec[Data]` with a `Iterable[B]`
implicit def pokeVecWithIterable[A <: Data, B, C[B] <: Iterable[B]](implicit p: Pokeable[A, B]): Pokeable[Vec[A], C[B]] (data: Vec[A], value: C[B]) => {
require(data.length == value.size, s"Cannot poke vec of length=${data.length} with iterable of length=${value.size})")
data.lazyZip(value).foreach(p.poke)
}
}
If you have any interest for me to include something like this in If functionality like this would be included, then supporting peek/poke for |
Why do you think so? Wouldn't it get the user Maybe you could add a test to demonstrate that it works. |
Yeah, I think this would be pretty cool. Happy to review the PR. |
Some of those methods seem to be only package private. Have you considered putting your new code under a |
@mvanbeirendonck Do you want to make a PR with the changes that we discussed above? Any way I can help? |
Yes! I need to find some time to give it a try, hopefully next week. I will first create a draft issue with the proposed changes, and from there identify where extra help could be useful. |
#624 removed FixedPoint support because this feature was removed from Chisel5.
There is some effort to reintroduce FixedPoint support in Chisel (chipsalliance/chisel#3161) through a custom library (https://github.com/ucb-bar/fixedpoint).
This pull request reintroduces FixedPoint support in Chiseltest5 using that fixedpoint library.
The main change in this PR are:
fixedpoint
as a git submodulefixedpoint
as a subprojectgit revert d8a44b2
For this last one,
git revert d8a44b2
, I only reintroduced changes related toFixedPoint
, notInterval
.I have also not included any old
FixedPoint
support that was present in the legacyPeekPokeTester
. The reason for this is that usingFixedPoint
withPeekPokeTester
was already integrated by @konda-x1 and @milovanovic intodsptools
(https://github.com/ucb-bar/dsptools/blob/master/src/main/scala/dsptools/misc/PeekPokeDspExtensions.scala).This is my first pull request for a Scala project, so let me know if there is anything you'd like me to improve :-)