icon-cookie
The website uses cookies to optimize your user experience. Using this website grants us the permission to collect certain information essential to the provision of our services to you, but you may change the cookie settings within your browser any time you wish. Learn more
I agree
blank_error__heading
blank_error__body
Text direction?

chisel-tutorial/SingleEvenFilter.scala at release · ucb-bar/chisel-tutorial · GitHub

Permalink

Join GitHub today

GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.

Sign up
Branch: release
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
45 lines (38 sloc) 1.08 KB
// See LICENSE.txt for license details.
package solutions
import chisel3._
import chisel3.util._
// Problem:
//
// Create a composition (chain) of two filters:
//
// SingleFilter - indicates that input is single decimal digit
// (i.e. is less or equal to 9)
//
// EvenFilter - indicates that input is even number
//
abstract class Filter[T <: Data](dtype: T) extends Module {
val io = IO(new Bundle {
val in = Input(Valid(dtype))
val out = Output(Valid(dtype))
})
}
class PredicateFilter[T <: Data](dtype: T, f: T => Bool) extends Filter(dtype) {
io.out.valid := io.in.valid && f(io.in.bits)
io.out.bits := io.in.bits
}
object SingleFilter {
def apply[T <: UInt](dtype: T) =
Module(new PredicateFilter(dtype, (x: T) => x <= 9.U))
}
object EvenFilter {
def apply[T <: UInt](dtype: T) =
Module(new PredicateFilter(dtype, (x: T) => x(0).toBool))
}
class SingleEvenFilter[T <: UInt](dtype: T) extends Filter(dtype) {
val single = SingleFilter(dtype)
val even = EvenFilter(dtype)
single.io.in := io.in
even.io.in := single.io.out
io.out := even.io.out
}
Measure
Measure
Related Notes
Get a free MyMarkup account to save this article and view it later on any device.
Create account

End User License Agreement

Summary | 0 Annotations