Compiling ESTEREL circuits into finite states machines

Compiling ESTEREL circuits
into finite states machines
BRES Yannis
Stage de DEA d’Informatique 1998/1999
Esterel constructive semantics
Gives, for each statement p , provided an initial environment E :
A new environment E’
A completion code k (terminated, paused or trap exit level)
A derivative statement p’, to be executed on next step
p
E’ , k
E
p’
Circuit compilation
Thus, each statement p of the language can be compiled into a circuit :
E are wires indicating present signals
E’ are wires indicating emitted signals
k indicates which completing code wire will be on
p’ is a another circuit activated by k wire
p
E’ , k
E
p’
Generated circuits
Directed graphs :
logical gates (and, or, not, …)
registers (memory elements)
wires
Example of circuit
abort
sustain O
when I
K0
0
!O
I
0
K1
1
Circuits vs. automata
Circuits are roughly linear while automata are exponential
 No automata for big circuits
Up to medium-sized circuits :
Automata are faster (run-time minimal)
Control flow computed at compile-time
 Only input/test dependent stuff remain at run-time
Ex : Motorola measures maximal application speed
Current compilation chain
Esterel source
intermediate code
.strl
.strl
.strl
strlic
strlic
strlic
.ic
.ic
.ic
iclc
linked code
.lc
lcsc
circuit code
.sc
scssc
sorted circuit code
sccausal
.ssc
sscoc
automaton code
.oc
Future compilation chain
Esterel source
intermediate code
.strl
.strl
.strl
strlic
strlic
strlic
.ic
.ic
.ic
iclc
linked code
.lc
lcsc
circuit code
.sc
scssc
sorted circuit code
sccausal
scoc
.ssc
sscoc
automaton code
.oc
SSCOC automaton generation
Circuit is seen like a set of boolean equations
To be evaluated, equations must be sorted (.ssc)
Sorting fails on several kind of cyclic circuits !
Code unmaintained...
SCOC automaton compilation
Algorithm follows electrical current
new informations (hot)
propagated informations (cold)
K0
0
!O
I
0
K1
1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
K0
0
!O
I
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
K0
0
!O
I
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
K0
0
0
!O
I
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
K0
0
!O
I
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
I
K0
0
!O
0
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
I
K0
0
!O
0
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
I
K0
0
!O
0
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
I
K0
0
!O
0
0
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
I
K0
0
!O
0
0
1
1
1
K1
SCOC automaton compilation
Building initial state
Propagating registers
new informations (hot)
propagated informations (cold)
0
0
0
I
K0
0
!O
0
0
1
1
1
K1
SCOC automaton compilation
Initial state built
new informations (hot)
propagated informations (cold)
!O
0
0
0
I
K0
0
!O
0
0
1
1
1
K1
SCOC automaton compilation
Initial state built
Building state 1
new informations (hot)
propagated informations (cold)
!O
0
0
0
I
K0
0
!O
0
0
1
1
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
K0
0
!O
?I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
K0
!O
?I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
?I
K0
!O
0
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
?I
K0
!O
0
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
?I
K0
0
!O
0
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
?I
K0
0
!O
0
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
?I
K0
0
!O
0
0
0
1
0
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
new informations (hot)
propagated informations (cold)
!O
1
0
1
?I
K0
0
!O
0
0
0
1
0
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Final state reached
new informations (hot)
propagated informations (cold)
!O
1
0
1
K0
0
?I
?I
!O
0
0
0
1
0
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
K0
0
?I
!O
#I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
?I
!O
#I
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
?I
#I
!O
1
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
?I
#I
!O
1
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
1
?I
#I
!O
1
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
1
?I
#I
!O
1
0
0
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
1
?I
#I
!O
1
0
0
1
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
new informations (hot)
propagated informations (cold)
!O
1
0
0
K0
1
?I
#I
!O
1
0
0
1
1
K1
SCOC automaton compilation
Initial state built
Building state 1
Loading registers values
Propagating registers
Forking on input signal I
Building branch where I is present
Building branch where I is absent
State 1 reached again
new informations (hot)
propagated informations (cold)
!O
1
#I.!O
0
0
K0
1
?I
#I
!O
1
0
0
1
1
K1
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Circuit saving and restoring
To avoid saving the whole circuit at each step of automata building :
Restoration data are stored in a stack of stacks
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Signal relations processing
Stored in a directed graph
: present  present
Example :
32
21
1#4#5
: absent  absent
: present  absent
absent  present
1
4
2
5
3
Smart circuit evaluation
Circuit evaluation algorithm stops as soon as all required nets are stabilized :
Registers (determine next state)
K0/K1 (determine whether automaton has terminated)
Output signals
Action nets (side-effects operating on values)
Input partitionning
Depending on current state, parts of the circuit are disabled
After registers propagation :
Inputs reachable from required nets will be processed first
Other inputs will probably not be processed at all
Input sorting
Example : bus arbiter
Set of cells requesting the access to a data bus
Cells have rotating priorities
Cell #1
Cell #3
Cell #5
bus
Cell #2
Cell #4
Input sorting
Inputs are sorted upon the number of reachable registers
This turns transitions from full trees (2n-sized) to combs (n-sized):
1
?Req1
!Ack1
#Req1
?Req2
!Ack2
#Req2
?Req3
#Req3
!Ack3
2
?Req2
!Ack2
#Req2
?Req3
!Ack3
#Req3
?Req1
#Req1
!Ack1
3
?Req3
!Ack3
#Req3
?Req1
!Ack1
#Req1
?Req2
#Req2
!Ack2
DAG sharing
Goals :
Saving memory
Emphazing semantic aspects
present A
emit A'
end present
||
?A . !A'
?A . !A'
#A
#B
?B . !B'
?B . !B'
?B . !B'
present B
emit B'
end present
#A
#B
#B
Performance comparison