Skip to content
Snippets Groups Projects
Verified Commit b803be17 authored by Minyong Li's avatar Minyong Li :speech_balloon:
Browse files

core.{Add,Xor}er{,Test}: impl

These are trivial modules, but add convenience when wiring up
the processor.
parent 1b6286a3
No related branches found
No related tags found
No related merge requests found
package uk.ac.soton.ecs.can.core
import chisel3._
class Adder extends MultiIOModule {
val lhs = IO(Input(Vec(16, UInt(32.W))))
val rhs = IO(Input(Vec(16, UInt(32.W))))
val out = IO(Output(Vec(16, UInt(32.W))))
out := lhs.zip(rhs).map { case (lhs, rhs) => lhs + rhs }
}
package uk.ac.soton.ecs.can.core
import chisel3._
class Xorer extends MultiIOModule {
val lhs = IO(Input(Vec(16, UInt(32.W))))
val rhs = IO(Input(Vec(16, UInt(32.W))))
val out = IO(Output(Vec(16, UInt(32.W))))
out := lhs.zip(rhs).map { case (lhs, rhs) => lhs ^ rhs }
}
package uk.ac.soton.ecs.can.core
import org.scalatest._
import chiseltest._
import chisel3._
import scala.util.Random
import scala.math.abs
class AdderTest extends FlatSpec with ChiselScalatestTester {
private val maxUInt = (Int.MaxValue.toLong << 1) | 1
behavior of "The Adder"
it should "sum the 16 32b unsigned integers" in {
test(new Adder) { c =>
val randomLhs = c.lhs.map(_ => abs(Random.nextInt))
val randomRhs = c.rhs.map(_ => abs(Random.nextInt))
val randomRes = randomLhs.zip(randomRhs).map { case (l, r) =>
(l.toLong + r.toLong) % maxUInt
}
c.lhs.zip(randomLhs).foreach { case (p, r) => p.poke(r.U) }
c.rhs.zip(randomRhs).foreach { case (p, r) => p.poke(r.U) }
c.out.zip(randomRes).foreach { case (p, r) => p.expect(r.U) }
}
}
}
package uk.ac.soton.ecs.can.core
import org.scalatest._
import chiseltest._
import chisel3._
import scala.util.Random
import scala.math.abs
class XorerTest extends FlatSpec with ChiselScalatestTester {
behavior of "The Xorer"
it should "exclusive-or the 16 32b unsigned integers" in {
test(new Xorer) { c =>
val randomLhs = c.lhs.map(_ => abs(Random.nextInt))
val randomRhs = c.rhs.map(_ => abs(Random.nextInt))
val randomRes = randomLhs.zip(randomRhs).map { case (l, r) => l ^ r }
c.lhs.zip(randomLhs).foreach { case (p, r) => p.poke(r.U) }
c.rhs.zip(randomRhs).foreach { case (p, r) => p.poke(r.U) }
c.out.zip(randomRes).foreach { case (p, r) => p.expect(r.U) }
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment