[英]How is this syntax explained in chisel?
I am learning chisel and rocket-chip.我正在学习凿子和火箭芯片。 I recently found an unreadable syntax in the rocket / RocketCore.scala file.
我最近在 Rocket/RocketCore.scala 文件中发现了一个不可读的语法。
val perfEvents = new EventSets(Seq(
new EventSet((mask, hits) => Mux(mask(0), wb_xcpt, wb_valid && pipelineIDToWB((mask & hits).orR)), Seq(
("exception", () => false.B),
("load", () => id_ctrl.mem && id_ctrl.mem_cmd === M_XRD && !id_ctrl.fp),
("store", () => id_ctrl.mem && id_ctrl.mem_cmd === M_XWR && !id_ctrl.fp),
("amo", () => Bool(usingAtomics) && id_ctrl.mem && (isAMO(id_ctrl.mem_cmd) || id_ctrl.mem_cmd.isOneOf(M_XLR, M_XSC))),
("system", () => id_ctrl.csr =/= CSR.N),
("arith", () => id_ctrl.wxd && !(id_ctrl.jal || id_ctrl.jalr || id_ctrl.mem || id_ctrl.fp || id_ctrl.mul || id_ctrl.div || id_ctrl.csr =/= CSR.N)),
("branch", () => id_ctrl.branch),
("jal", () => id_ctrl.jal),
("jalr", () => id_ctrl.jalr))
++ (if (!usingMulDiv) Seq() else Seq(
("mul", () => if (pipelinedMul) id_ctrl.mul else id_ctrl.div && (id_ctrl.alu_fn & ALU.FN_DIV) =/= ALU.FN_DIV),
("div", () => if (pipelinedMul) id_ctrl.div else id_ctrl.div && (id_ctrl.alu_fn & ALU.FN_DIV) === ALU.FN_DIV)))
++ (if (!usingFPU) Seq() else Seq(
("fp load", () => id_ctrl.fp && io.fpu.dec.ldst && io.fpu.dec.wen),
("fp store", () => id_ctrl.fp && io.fpu.dec.ldst && !io.fpu.dec.wen),
("fp add", () => id_ctrl.fp && io.fpu.dec.fma && io.fpu.dec.swap23),
("fp mul", () => id_ctrl.fp && io.fpu.dec.fma && !io.fpu.dec.swap23 && !io.fpu.dec.ren3),
("fp mul-add", () => id_ctrl.fp && io.fpu.dec.fma && io.fpu.dec.ren3),
("fp div/sqrt", () => id_ctrl.fp && (io.fpu.dec.div || io.fpu.dec.sqrt)),
("fp other", () => id_ctrl.fp && !(io.fpu.dec.ldst || io.fpu.dec.fma || io.fpu.dec.div || io.fpu.dec.sqrt))))),
new EventSet((mask, hits) => (mask & hits).orR, Seq(
("load-use interlock", () => id_ex_hazard && ex_ctrl.mem || id_mem_hazard && mem_ctrl.mem || id_wb_hazard && wb_ctrl.mem),
("long-latency interlock", () => id_sboard_hazard),
("csr interlock", () => id_ex_hazard && ex_ctrl.csr =/= CSR.N || id_mem_hazard && mem_ctrl.csr =/= CSR.N || id_wb_hazard && wb_ctrl.csr =/= CSR.N),
("I$ blocked", () => icache_blocked),
("D$ blocked", () => id_ctrl.mem && dcache_blocked),
("branch misprediction", () => take_pc_mem && mem_direction_misprediction),
("control-flow target misprediction", () => take_pc_mem && mem_misprediction && mem_cfi && !mem_direction_misprediction && !icache_blocked),
("flush", () => wb_reg_flush_pipe),
("replay", () => replay_wb))
++ (if (!usingMulDiv) Seq() else Seq(
("mul/div interlock", () => id_ex_hazard && (ex_ctrl.mul || ex_ctrl.div) || id_mem_hazard && (mem_ctrl.mul || mem_ctrl.div) || id_wb_hazard && wb_ctrl.div)))
++ (if (!usingFPU) Seq() else Seq(
("fp interlock", () => id_ex_hazard && ex_ctrl.fp || id_mem_hazard && mem_ctrl.fp || id_wb_hazard && wb_ctrl.fp || id_ctrl.fp && id_stall_fpu)))),
new EventSet((mask, hits) => (mask & hits).orR, Seq(
("I$ miss", () => io.imem.perf.acquire),
("D$ miss", () => io.dmem.perf.acquire),
("D$ release", () => io.dmem.perf.release),
("ITLB miss", () => io.imem.perf.tlbMiss),
("DTLB miss", () => io.dmem.perf.tlbMiss),
("L2 TLB miss", () => io.ptw.perf.l2miss)))))
When using class EventSet, I did not find the definition of mask and hits.使用类EventSet的时候,没有找到mask和hits的定义。
That is a pretty intimidating piece of code.这是一段相当令人生畏的代码。 Breaking it down
打破它
perfEvents
is assigned to be an instance of EventSets
perfEvents
被分配为EventSets
一个实例EventSets
requires a single parameter EventSets
需要一个参数
class EventSets(val eventSets: Seq[EventSet])
Seq
of EventSet
begin created.EventSet
的Seq
开始创建。EventSet
requires two parameters EventSet
需要两个参数
class EventSet(gate: (UInt, UInt) => Bool, events: Seq[(String, () => Bool)])
UInts
that returns a Bool
Bool
的两个UInts
的函数Seq
of 2 tuples of String
and a function with no parameters that returns a Bool
String
元组组成的Seq
和一个没有参数的函数,它返回一个Bool
(String, () => Bool())
needs to be different depending on configuration parameters like usingMulDiv
(String, () => Bool())
的顺序需要根据usingMulDiv
等配置参数而有所不同
++ (if (..
a couple of times.++ (if (..
几次。if
conditionally add different subsequences of tuples to the EventSet
parameter it is constucting.if
有条件地将元组的不同子序列添加到它正在构造的EventSet
参数。 I hope that helps.我希望这有帮助。 This is a whole lot of stuff that is probably going to be either ugly and short or clearer and really long and verbose.
这是一大堆东西,它们可能要么丑陋、简短,要么更清晰、又长又冗长。 It may help a little to run this through a formatter.
通过格式化程序运行它可能会有所帮助。 Here's a bit of that.
这里有一点。
val perfEvents = new EventSets(
Seq(
new EventSet(
(mask, hits) => Mux(wb_xcpt, mask(0), wb_valid && pipelineIDToWB((mask & hits).orR)),
Seq(
("exception", () => false.B),
("load", () => id_ctrl.mem && id_ctrl.mem_cmd === M_XRD && !id_ctrl.fp),
("store", () => id_ctrl.mem && id_ctrl.mem_cmd === M_XWR && !id_ctrl.fp),
("amo",
() =>
Bool(usingAtomics) && id_ctrl.mem && (isAMO(id_ctrl.mem_cmd) || id_ctrl.mem_cmd.isOneOf(M_XLR, M_XSC))),
("system", () => id_ctrl.csr =/= CSR.N),
("arith",
() =>
id_ctrl.wxd && !(id_ctrl.jal || id_ctrl.jalr || id_ctrl.mem || id_ctrl.fp || id_ctrl.mul || id_ctrl.div || id_ctrl.csr =/= CSR.N)),
("branch", () => id_ctrl.branch),
("jal", () => id_ctrl.jal),
("jalr", () => id_ctrl.jalr)
)
++ (if (!usingMulDiv) Seq()
else
Seq(
mask
and hits
are just arguments of the lambda passed to the EventSet
constructor, the (mask, hits) => ...
part is their definition (or declaration, if you prefer). mask
和hits
只是传递给EventSet
构造函数的 lambda 参数, (mask, hits) => ...
部分是它们的定义(或声明,如果您愿意)。 If you look at EventSet
source you can see the lambda is called gate
and used only in this method:如果您查看
EventSet
源代码,您可以看到 lambda 被称为gate
并且仅在此方法中使用:
def check(mask: UInt) = gate(mask, hits)
So mask
will be the argument of check
and hits
come from所以
mask
将是check
的参数, hits
来自
def hits = events.map(_._2()).asUInt
In this case, for the first EventSet
you'll get something like在这种情况下,对于第一个
EventSet
您将得到类似
Seq(
false.B,
id_ctrl.mem && id_ctrl.mem_cmd === M_XRD && !id_ctrl.fp,
...
).asUInt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.