package Ex0

import chisel3._
import chisel3.util.Counter

class DotProd(val elements: Int) extends Module {

  val io = IO(
    new Bundle {
      val dataInA     = Input(UInt(32.W))
      val dataInB     = Input(UInt(32.W))

      val dataOut     = Output(UInt(32.W))
      val outputValid = Output(Bool())
    }
  )


  val counter = Counter(elements)
  val accumulator = RegInit(0.U(32.W))

  val result = accumulator + io.dataInA * io.dataInB

  accumulator := Mux(counter.inc(), 0.U, result)
  io.dataOut := result
  io.outputValid := counter.inc()
}
