I am new to Scala and I have been trying to understand the RISC-V architecture. I came across this piece of code, which I have been staring at for hours, unable to understand.
val csignals =
ListLookup(io.dat.inst,
List(N, BR_N , OP1_X , OP2_X , ALU_X , WB_X , REN_0, MEN_0, M_X , MT_X, CSR.N),
Array( /* val | BR | op1 | op2 | ALU | wb | rf | mem | mem | mask | csr */
/* inst | type | sel | sel | fcn | sel | wen | en | wr | type | cmd */
LW -> List(Y, BR_N , OP1_RS1, OP2_IMI , ALU_ADD , WB_MEM, REN_1, MEN_1, M_XRD, MT_W, CSR.N),
LB -> List(Y, BR_N , OP1_RS1, OP2_IMI , ALU_ADD , WB_MEM, REN_1, MEN_1, M_XRD, MT_B, CSR.N),
LBU -> List(Y, BR_N , OP1_RS1, OP2_IMI , ALU_ADD , WB_MEM, REN_1, MEN_1, M_XRD, MT_BU, CSR.N),...
The ListLookUp is roughly equivalent to a switch()
statement in software programming, or a casez
statement in Verilog RTL.
The first argument (io.dat.inst
) is the signal to match against.
The second argument is the default value if no match occurs.
The third argument is an Array of "key"->"value" tuples. The io.dat.inst
is matched against the keys to find a match and the csignals
is set to the value
part if a match is found.
So csignals is of a type List()
.