Skip to content

Commit 5a91830

Browse files
committed
ArithCircuit refinement
1 parent 7bdc981 commit 5a91830

1 file changed

Lines changed: 15 additions & 24 deletions

File tree

paper.tex

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,13 @@ \subsection{Symbolic Bit Representations}\label{subsec:bitexpr}
434434
\[
435435
\begin{array}{r@{\;}c@{\;}l@{\qquad}l}
436436
\multicolumn{4}{l}{%
437-
b \in Var \qquad
437+
b \in \texttt{Var} \qquad
438438
\circledast \in \{\wedge,\vee,\oplus\}}\\[2pt]
439-
\BitExpr \ni c &::=& b_n \mid 0 \mid 1 \mid \neg c \mid c \circledast c &
439+
\BitExpr \ni c &::=& b \mid 0 \mid 1 \mid \neg c \mid c \circledast c &
440440
\end{array}
441441
\]
442442
To evaluate a \BitExpr, we need to assign values to all the variables in the \BitExpr.
443-
These are supplied by a bit environment $(\sigma : Var \to \mathbb B)$,
443+
These are supplied by a bit environment $(\sigma : \texttt{Var} \to \mathbb B)$,
444444
which maps each bit variable to its Boolean value.
445445
The evaluation function $\csem{\cdot} : \BitExpr \to \mathbb B$ evaluates a \BitExpr under a bit environment $\sigma$,
446446
producing a concrete boolean value. It is defined by recursion.
@@ -573,39 +573,30 @@ \subsection{Bit Heap Data Structure}\label{subsec:bitheap}
573573

574574
\subsection{From Word-Level Arithmetic to Bit Heaps}\label{subsec:to_bitheap}
575575
So far, we have defined the bit heap data structure and its operations, and proved that they preserve the semantics of bit heap evaluation.
576-
To synthesize efficient and provably correct circuits for word-level arithmetic, we require a verified translation from arithmetic to a bit heap.
576+
To use the bit heap to synthesize efficient and provably correct circuits for word-level arithmetic, we require a verified translation from arithmetic to a bit heap.
577577
We represent such arithmetic expressions as \Arith, a minimal symbolic
578578
representation of word-level arithmetic.
579579
We will define a function $\mathsf{toBitHeap}$ that converts an \Arith expression into a bit heap.
580580
This conversion then allows us to apply compression techniques that reduce the delay of the circuit (\autoref{subsec:compression}).
581581
First, we define the syntax and semantics of \Arith,
582582
and then we prove that the semantics of the resulting bit heap are equal to the semantics of the original \Arith expression.
583583

584-
An \Arith is a word-level expression, which can be a variable,
585-
a variadic addition of \Arith expressions,
586-
or a multiplication of two \Arith expressions.
587-
This allows us to represent nested arithmetic expressions, such as multiply-accumulate.
588-
An \Arith variable $\mathsf{var}(i)$ represents the $i$-th input word.
589-
We also support zero-extension and sign-extension of the variables, that allows us to fit narrow operands into a wider datapath,
590-
as this is commonly needed in multiplication to preserve the full precision of the result:
584+
\Arith is a word-level representation supporting variables,
585+
variadic addition and two-input multiplication.
586+
This allows us to represent nested arithmetic expressions, like $a\times b + c$.
587+
We also support zero/sign-extension of variables, as this lets our multiplication preserve the full precision of the result.
591588
\begin{align*}
592-
&i \in \mathbb{N} \qquad v, w \in \mathbb{N}^{+}\\
589+
&b \in \texttt{Var}_{\texttt{Arith}} \qquad v, w \in \mathbb{N}^{+}\\
593590
&\mathtt{ArithCircuit}_w \ni a ::= \\
594-
&\quad \mid \mathsf{var}(i) \mid \mathsf{zext}(i, b) \mid \mathsf{sext}(i, b) \mid \mathsf{add}[a_0,\dots,a_{n-1}] \mid \mathsf{mul}[a, a]
591+
&\quad \mid b \mid \mathsf{zext}(i, b) \mid \mathsf{sext}(i, b) \mid \mathsf{add}[a_0,\dots,a_{n-1}] \mid \mathsf{mul}[a_0, a_1]
595592
\end{align*}
596593

597-
The \Arith variables are assigned a value by a variable environment $\rho : \mathbb{N} \to \mathtt{BitVec}\ w$, mapping each variable to a $w$-bit word,
598-
where $\mathtt{BitVec}\ w$ is Lean's type of bitvectors of width $w$.
594+
The \Arith variables are assigned a value by a variable environment $\rho : \texttt{Var}_{\texttt{Arith}} \to \mathtt{BitVec}\ w$, mapping each variable to Lean's built-in bitvector type of width $w$.
595+
\sam{We should make it clear that everything gets assigned to $w$-bits?}
599596
A variable evaluates to the word the environment assigns it.
600-
A zero-extended variable $\mathsf{zext}(i,b)$ evaluates by truncating that word to its lowest $b$ bits and zero-extending the result back to the width of the \Arith expression.
601-
A sign-extended variable $\mathsf{sext}(i,b)$, where $0 < b \leq w$, truncates in the same way, but extends the result back to width $w$ by replicating the sign bit, i.e. bit $b-1$ of the word.
602-
The addition and multiplication operations in \Arith are interpreted as the corresponding word-level operations:
603-
\begin{align*}
604-
&\bvsem{\mathsf{var}(i)} = \rho\, i \qquad \bvsem{\mathsf{zext}(i,b)} = \mathsf{zext}_{w}\big((\rho\,i)_{[0,b)}\big)\\
605-
&\bvsem{\mathsf{sext}(i,b)} = \mathsf{sext}_{w}\big((\rho\,i)_{[0,b)}\big)\\
606-
&\bvsem{\mathsf{add}[a_0,\dots,a_{n-1}]} = \textstyle\sum_{t<n} \bvsem{a_t}\\
607-
&\bvsem{a_0 \times a_1} = \bvsem{a_0} \cdot \bvsem{a_1}
608-
\end{align*}
597+
A zero-extended variable $\mathsf{zext}(b,w')$, where $w'\leq w$, evaluates by truncating that word to its lowest $w'$-bits and zero-extending the result back to the width of the \Arith expression.
598+
A sign-extended variable $\mathsf{sext}(b,w')$, where $w' \leq w$, truncates in the same way, but extends the result back to width $w$ by replicating the sign bit, i.e. bit $b-1$ of the word.
599+
The addition and multiplication operations in \Arith are interpreted following standard bitvector arithmetic.
609600

610601
\paragraph{Bit Heap Construction from Arithmetic Expressions}
611602

0 commit comments

Comments
 (0)