You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1KB

  1. package Ex0
  2. import chisel3._
  3. // This import statement makes the scala vector invisible, reducing confusion
  4. import scala.collection.immutable.{ Vector => _ }
  5. class Matrix(val rowsDim: Int, val colsDim: Int) extends Module {
  6. val io = IO(
  7. new Bundle {
  8. val colIdx = Input(UInt(32.W))
  9. val rowIdx = Input(UInt(32.W))
  10. val dataIn = Input(UInt(32.W))
  11. val readEnable = Input(Bool())
  12. val dataOut = Output(UInt(32.W))
  13. }
  14. )
  15. /**
  16. * Your code here
  17. */
  18. // Creates a vector of zero-initialized registers
  19. val rows = Vec.fill(rowsDim)(Module(new Vector(colsDim)).io)
  20. // placeholders
  21. io.dataOut := 0.U
  22. for(ii <- 0 until rowsDim){
  23. rows(ii).dataIn := 0.U
  24. rows(ii).readEnable := false.B
  25. rows(ii).idx := 0.U
  26. }
  27. /**
  28. * LF
  29. */
  30. for(ii <- 0 until rowsDim){
  31. rows(ii).dataIn := io.dataIn
  32. rows(ii).idx := io.colIdx
  33. when(ii.U === io.rowIdx){
  34. rows(ii).readEnable := io.readEnable
  35. }.otherwise{
  36. rows(ii).readEnable := false.B
  37. }
  38. }
  39. io.dataOut := rows(io.rowIdx).dataOut
  40. }