I’m learning the circt project, I started with calyx dialect code and after a series of passes the code looks like this.After thinking about it for a long time, I still can’t understand the design idea of fsm dialect.I don’t know how to understand the fsm dialect, which I think is similar to Moore’s state machine, but different from Moore.
The following code can be used as a reference, I have the following questions.
- Why is there a return value in the state machine? What is the purpose of this return value?
fsm.return %arg1
, although it is used in calyx.wires, I still can’t figure out what it does. - What is the use of
%save_done.in, %save_done.out
?
I have read the material here.But I still didn’t understand it very well.
If anyone can help me, I would be grateful.Thank you!
module {
fsm.machine @control(%arg0: i1, %arg1: i1) -> (i1, i1) attributes {calyx.fsm_group_done_inputs = {save = 0 : i64}, calyx.fsm_group_go_outputs = {save = 0 : i64}, calyx.fsm_top_level_done = 1 : i64, calyx.fsm_top_level_go = 1 : i64, compiledGroups = [@save], initialState = "fsm_entry"} {
%true = hw.constant true
%false = hw.constant false
fsm.state @fsm_entry output {
fsm.output %false, %false : i1, i1
} transitions {
fsm.transition @seq_0_save guard {
fsm.return %arg1
}
}
fsm.state @fsm_exit output {
fsm.output %false, %true : i1, i1
} transitions {
}
fsm.state @seq_0_save output {
fsm.output %true, %false : i1, i1
} transitions {
fsm.transition @fsm_exit guard {
fsm.return %arg0
}
}
}
calyx.component @identity(%in: i32, %go: i1 {go}, %clk: i1 {clk}, %reset: i1 {reset}) -> (%out: i32, %done: i1 {done}) {
%save_done.in, %save_done.out = calyx.std_wire @save_done : i1, i1
%0:2 = fsm.hw_instance "controller" @control(%save_done.out, %go), clock %clk, reset %reset : (i1, i1) -> (i1, i1)
%r.in, %r.write_en, %r.clk, %r.reset, %r.out, %r.done = calyx.register @r : i32, i1, i1, i1, i32, i1
%true = hw.constant true
%true_0 = hw.constant true
calyx.wires {
calyx.assign %out = %r.out : i32
calyx.assign %done = %0#1 : i1
calyx.assign %save_done.in = %r.done : i1
calyx.assign %r.in = %0#0 ? %in : i32
calyx.assign %r.write_en = %0#0 ? %true : i1
}
calyx.control {
}
}
}