Skip to content

Commit

Permalink
Zicond: implement czero.eqz, czero.nez
Browse files Browse the repository at this point in the history
  • Loading branch information
rewired-gh committed Apr 23, 2023
1 parent 0815dba commit f3e3ee8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/main/scala/rocket/ALU.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ALUFN {
def FN_SR = 5.U
def FN_OR = 6.U
def FN_AND = 7.U
def FN_CZEQZ = 8.U
def FN_CZNEZ = 9.U
def FN_SUB = 10.U
def FN_SRA = 11.U
def FN_SLT = 12.U
Expand Down Expand Up @@ -160,10 +162,19 @@ class ALU(implicit p: Parameters) extends AbstractALU(new ALUFN)(p) {
val shout = Mux(io.fn === aluFn.FN_SR || io.fn === aluFn.FN_SRA, shout_r, 0.U) |
Mux(io.fn === aluFn.FN_SL, shout_l, 0.U)

// CZEQZ, CZNEZ
val cond_out = Option.when(coreParams.useConditionalZero)(
Mux(io.fn === aluFn.FN_CZEQZ && io.in2 =/= 0.U, io.in1, 0.U) |
Mux(io.fn === aluFn.FN_CZNEZ && io.in2 === 0.U, io.in1, 0.U)
)

// AND, OR, XOR
val logic = Mux(io.fn === aluFn.FN_XOR || io.fn === aluFn.FN_OR, in1_xor_in2, 0.U) |
Mux(io.fn === aluFn.FN_OR || io.fn === aluFn.FN_AND, io.in1 & io.in2, 0.U)
val shift_logic = (aluFn.isCmp(io.fn) && slt) | logic | shout
val shift_logic = cond_out match {
case Some(co) => (aluFn.isCmp (io.fn) && slt) | logic | shout | co
case _ => (aluFn.isCmp (io.fn) && slt) | logic | shout
}
val out = Mux(io.fn === aluFn.FN_ADD || io.fn === aluFn.FN_SUB, io.adder_out, shift_logic)

io.out := out
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/rocket/IDecode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ class IDecode(aluFn: ALUFN = ALUFN())(implicit val p: Parameters) extends Decode
SLL-> List(Y,N,N,N,N,N,Y,Y,N,N,N,N,A2_RS2, A1_RS1, IMM_X, DW_XPR,aluFn.FN_SL, N,M_X, N,N,N,N,N,N,Y,CSR.N,N,N,N,N),
SRL-> List(Y,N,N,N,N,N,Y,Y,N,N,N,N,A2_RS2, A1_RS1, IMM_X, DW_XPR,aluFn.FN_SR, N,M_X, N,N,N,N,N,N,Y,CSR.N,N,N,N,N),
SRA-> List(Y,N,N,N,N,N,Y,Y,N,N,N,N,A2_RS2, A1_RS1, IMM_X, DW_XPR,aluFn.FN_SRA, N,M_X, N,N,N,N,N,N,Y,CSR.N,N,N,N,N),
CZERO_EQZ-> List(Y,N,N,N,N,N,Y,Y,N,N,N,N,A2_RS2, A1_RS1, IMM_X, DW_XPR,aluFn.FN_CZEQZ, N,M_X, N,N,N,N,N,N,Y,CSR.N,N,N,N,N),
CZERO_NEZ-> List(Y,N,N,N,N,N,Y,Y,N,N,N,N,A2_RS2, A1_RS1, IMM_X, DW_XPR,aluFn.FN_CZNEZ, N,M_X, N,N,N,N,N,N,Y,CSR.N,N,N,N,N),

FENCE-> List(Y,N,N,N,N,N,N,N,N,N,N,N,A2_X, A1_X, IMM_X, DW_X, aluFn.FN_X, N,M_X, N,N,N,N,N,N,N,CSR.N,N,Y,N,N),

Expand Down
1 change: 1 addition & 0 deletions src/main/scala/rocket/RocketCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ case class RocketCoreParams(
useBitManipCrypto: Boolean = false,
useCryptoNIST: Boolean = false,
useCryptoSM: Boolean = false,
useConditionalZero: Boolean = false,
nLocalInterrupts: Int = 0,
useNMI: Boolean = false,
nBreakpoints: Int = 1,
Expand Down
1 change: 1 addition & 0 deletions src/main/scala/tile/Core.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ trait CoreParams {
val useCryptoNIST: Boolean
val useCryptoSM: Boolean
val useRVE: Boolean
val useConditionalZero: Boolean
val mulDiv: Option[MulDivParams]
val fpu: Option[FPUParams]
val fetchWidth: Int
Expand Down

0 comments on commit f3e3ee8

Please sign in to comment.