Correctness of Guard Synthesis #106
rachitnigam
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Compilation of high-level Filament programs need to turn all invocation into guarded assignments that forward the source values into the instance's ports as specified by the schedule.
In short, it must turn this high-level program:
into:
The core problem during lowering is synthesizing
guard
expressions for each invocation. Here, we'll show that for a well-typed high-level Filament program, we can always generate correct guards.Restrictions: We only address compilation of programs without
max
expressions and adhering to restrictions from #27 which disallows relating events using ordering constraints.Ports on Pipelined FSMs
Generating FSMs: We assume that for each event
G
for the current component, there is an FSM calledGf
that is triggered by the interface port forG
:The FSMs for each event can be thought of as a series of shift registers of length$i^{th}$ register has a token in it. The interval type for a port is:
n
. The portGf._i
is active when thewhere
d
is the delay for the port that triggers the FSM.First, we look at the active part of the specification:$i$ cycles after a token enters the FSM.
@exact[G+i, G+i+1]
. This means that the guard has a non-zero valueThe availability of the guard is more complex:
[G+i-d, G+i+d]
. It states that the guard is guaranteed to have a known value in the given duration. Next, it says that the guard does not observe a new token ford
cycles after it gets a token ord
cycles before it observes a new token.The intuition for this is that if an FSM is triggered at most once every$0$ .
d
cycles, each token is separated byd
cycles in both the past and the future. The first token is a special case but we assume that resetting the circuit instantiates everything toConstraints on Low-level Assignments
In the high-level program
We have the restriction that$[G+m_s, G+n_s]$ and $[G+m_d, G+n_d]$ for $[G+m_s, G+n_s] \supseteq [G+m_d, G+n_d]$ .
a.out
is available for at least as long asm0.left
requires. Thus, if we have the availabilitiesa.out
andm0.left
respectively, we haveWhen generating the assignment:
We need to synthesize a guard that is available for$[G+m_s, G+n_s]$ and active for $[G+m_d, G+n_d]$ , i.e. it has a non-zero value in the interval that the destination requires and long enough to guard the source port.
Lemma: The delay for the event$G$ is greater than or equal to $n_s - m_s$ .
Proof. Since
a.out
is an output from some instance related to invocationa
, we know thatG
must obey the delay constraints (as specified in #20). Specifically, the delay must be longer than the length of the interval of any input or output port. Similar reasoning applies to any input port of the component that can be used in this position.We also know that$n_s - m_s \geq n_d - m_d$ due to the subset relationship between the source and destination port.
Synthesizability of Guards
Here is the rule we use to generate guards: If the requirement of a destination port is$[G+m_d, G+n_d]$ , generate the expression:
So, if we have the interval$[G+3, G+5]$ , we'll generate the expression:
To show that this is correct, we need to show that:
We have (1) by construction since we use the destination to construct the guard expression.
For (2), we have$n_s - m_s \leq d$ and $m_s \leq m_d$ , thus we have:
This shows that the guard is active at least until the end of the interval for the source port.
Next, we can use similar reasoning to show that the guard is active at least before the start of the source port:
Thus, we have that the guard is available for at least as long as the source port and active as long as the destination requires.
Implementation
The implementation in the compiler currently does not have a way to talk about terms like
G+i-d
since negation of events is not supported. If we want the lowered programs to type check, we need some way of doing this. If not, we can skip implementing this and rely on the pen-and-paper proof.Beta Was this translation helpful? Give feedback.
All reactions