Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

36 Zeilen
1015B

  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 writeEnable = Input(Bool())
  12. val dataOut = Output(UInt(32.W))
  13. }
  14. )
  15. // Creates a vector of zero-initialized registers
  16. val rows = VecInit(List.fill(rowsDim)(Module(new Vector(colsDim)).io))
  17. for(ii <- 0 until rowsDim){
  18. // It doesn't matter what we use to drive idx and dataIn, as long as
  19. // writeEnable is low, so we always use the input values.
  20. rows(ii).idx := io.colIdx
  21. rows(ii).dataIn := io.dataIn
  22. // Enable writing when the current row is selected
  23. rows(ii).writeEnable := io.writeEnable && (io.rowIdx === ii.U)
  24. }
  25. io.dataOut := rows(io.rowIdx).dataOut
  26. }