Skip to content

Commit 5548122

Browse files
committed
feat: add custom inst decode for the alu
1 parent ba1f7f6 commit 5548122

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

rtl/tc_l2/src/main/scala/core/exec/ACU.scala

+17-12
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,32 @@ class AGU extends Module {
1111
val src1 = Input(UInt(ConstVal.AddrLen.W))
1212
val src2 = Input(UInt(ConstVal.AddrLen.W))
1313
val valid = Output(Bool())
14+
val busy = Output(Bool())
1415
val res = Output(UInt(ConstVal.AddrLen.W))
1516
})
1617

1718
// cordic or gcd
1819
// https://zhuanlan.zhihu.com/p/304477416
1920
// https://zhuanlan.zhihu.com/p/365058686
20-
protected val vala = RegInit(0.U(64.W))
21-
protected val valb = RegInit(0.U(64.W))
22-
protected val gcdVis = io.isa.GCD
21+
protected val val1Reg = RegInit(0.U(64.W))
22+
protected val val2Reg = RegInit(0.U(64.W))
23+
protected val busyReg = RegInit(false.B)
24+
protected val gcdVis = io.isa.GCD
2325

24-
when(gcdVis && io.valid) {
25-
vala := io.src1
26-
valb := io.src2
27-
}.otherwise {
28-
when(vala > valb) {
29-
vala := vala - valb
26+
when(gcdVis && !busyReg) {
27+
val1Reg := io.src1
28+
val2Reg := io.src2
29+
busyReg := true.B
30+
}.elsewhen(busyReg) {
31+
when(val1Reg > val2Reg) {
32+
val1Reg := val1Reg - val2Reg
3033
}.otherwise {
31-
valb := valb - vala
34+
val2Reg := val2Reg - val1Reg
3235
}
3336
}
3437

35-
io.valid := valb === 0.U(64.W)
36-
io.res := vala
38+
when(val2Reg === 0.U(64.W)) { busyReg := false.B }
39+
io.valid := (val2Reg === 0.U(64.W) && busyReg)
40+
io.busy := busyReg
41+
io.res := val1Reg
3742
}

rtl/tc_l2/src/main/scala/core/id/ISADecoder.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,11 @@ class ISADecoder extends Module {
102102
protected val env = io.isa.ECALL || io.isa.EBREAK
103103
protected val csr = io.isa.CSRRW || io.isa.CSRRS || io.isa.CSRRC || io.isa.CSRRWI || io.isa.CSRRSI || io.isa.CSRRCI
104104
protected val priv = io.isa.MRET || io.isa.SRET || io.isa.WFI || io.isa.SFENCE_VMA
105+
protected val custom = io.isa.GCD
105106

106107
protected val immExten = Module(new ImmExten)
107108
immExten.io.inst := io.inst
108109
io.imm := immExten.io.imm
109110
io.csr := csr
110-
io.wen := arith || logc || shift || comp || link || load || csr
111+
io.wen := arith || logc || shift || comp || link || load || csr || custom
111112
}

0 commit comments

Comments
 (0)