250 lines
6.7 KiB
TeX
250 lines
6.7 KiB
TeX
\subsection{Métaprogrammation template}
|
|
|
|
%{{{
|
|
\begin{frame}{Métaprogrammation}
|
|
%{{{ frame "
|
|
\begin{block}{Définition de métaprogramme}
|
|
programme dont les données traitées sont des programmes
|
|
\end{block}
|
|
|
|
En C++ :
|
|
\begin{itemize}
|
|
\item notamment basé sur les templates
|
|
\item exécution du métaprogramme durant la compilation
|
|
\item génération d'un programme C++
|
|
\end{itemize}
|
|
|
|
\fig{mp/metaprogram}
|
|
%}}}
|
|
\end{frame}
|
|
%}}}
|
|
|
|
%{{{
|
|
\begin{frame}{Métaprogrammation template}
|
|
\framesubtitle{Généricité}
|
|
|
|
%{{{ frame "
|
|
\begin{block}{Résultats d'un template}
|
|
\begin{itemize}
|
|
\item structure / classe / union
|
|
\item fonction
|
|
\item variable
|
|
\end{itemize}
|
|
\end{block}
|
|
|
|
\lstvisible<2->{mp/tmptype}
|
|
|
|
\visible<3->{
|
|
\begin{columns}
|
|
\begin{column}{.33\paperwidth}
|
|
\lst{mp/tmptype_int_5}
|
|
\end{column}
|
|
\begin{column}{.33\paperwidth}
|
|
\lst{mp/tmptype_float_3}
|
|
\end{column}
|
|
\begin{column}{.33\paperwidth}
|
|
\lst{mp/tmptype_Foo_256}
|
|
\end{column}
|
|
\end{columns}
|
|
|
|
|
|
\tikz[remember picture,overlay]\draw[->,>=stealth]
|
|
(mp tmptype) -- node[midway,left]{\cppinline{Array<int, 5>}} (mp tmptype int 5);
|
|
\tikz[remember picture,overlay]\draw[->,>=stealth]
|
|
(mp tmptype) -- node[midway]{\cppinline{Array<float, 3>}} (mp tmptype float 3);
|
|
\tikz[remember picture,overlay]\draw[->,>=stealth]
|
|
(mp tmptype) -- node[midway,right]{\cppinline{Array<Foo, 256>}} (mp tmptype Foo 256);
|
|
}
|
|
%}}}
|
|
\end{frame}
|
|
%}}}
|
|
|
|
%{{{
|
|
\begin{frame}{Puissance avec exposant connu}
|
|
%{{{ frame "
|
|
\vspace*{-3ex}
|
|
\begin{columns}
|
|
\begin{column}{.25\paperwidth}\end{column}
|
|
\begin{column}{.5\paperwidth}
|
|
\only<-9>{\center Fonction puissance\vspace{-2ex}}
|
|
\lstonly<-9>{mp/pow.rt}
|
|
\only<10-12>{\setminted{highlightcolor=yellow!80!black!30,highlightlines={1-4}}}
|
|
\only<13>{\setminted{highlightcolor=yellow!80!black!30,highlightlines={6-9}}}
|
|
\only<9->{\center Métafonction puissance\vspace{-2ex}}
|
|
\lstonly<9->{mp/pow.ct}
|
|
\end{column}
|
|
\begin{column}{.25\paperwidth}\end{column}
|
|
\end{columns}
|
|
\vspace{-2ex}
|
|
\begin{columns}[t]
|
|
\begin{column}{.066\paperwidth}\end{column}
|
|
\begin{column}{.4\paperwidth}
|
|
\only<2-8,10->{\center Exemple d'appel\vspace{-2ex}}
|
|
\only<-8>{\lstvisible<2-8>{mp/pow.rt.call}}
|
|
\only<8>{
|
|
\vspace{2ex}
|
|
\begin{itemize}
|
|
\item $n$ multiplications
|
|
\item $n$ soustractions
|
|
\item structures de contrôle
|
|
\end{itemize}
|
|
}
|
|
\lstvisible<10->{mp/pow.ct.call}
|
|
\end{column}
|
|
\begin{column}{.066\paperwidth}\end{column}
|
|
\begin{column}{.4\paperwidth}
|
|
\visible<3-8,15->{\center Assembleur produit\vspace{-2ex}}
|
|
\only<-8>{\lstvisible<3-8>{mp/pow.rt.asm}}
|
|
\lstonly<15>{mp/pow.ct.asm}
|
|
\only<15->{\vspace{7pt}}
|
|
\end{column}
|
|
\begin{column}{.066\paperwidth}\end{column}
|
|
\end{columns}
|
|
|
|
\only<10-14>{\center C++ généré\\\vspace{-1pt}}
|
|
\only<10>{\small\center\texttt{\hlbox{yellow!80!black!30}{pow<24>(x)}}}
|
|
\only<11>{\small\center\texttt{x*\hlbox{yellow!80!black!30}{pow<23>(x)}}}
|
|
\only<12>{\small\center\texttt{x*x*\hlbox{yellow!80!black!30}{pow<22>(x)}}}
|
|
\only<13>{\small\center\texttt{x*\dots*x*\hlbox{yellow!80!black!30}{pow<0>(x)}}}
|
|
\only<14>{%
|
|
\small\center\texttt{\phantom{p}\tikzmark{powx0}x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x\tikzmark{powxn}*1\phantom{p}}%
|
|
\tikz[remember picture,overlay]{%
|
|
\draw[decorate,decoration={brace,amplitude=4pt,raise=2pt,mirror}]
|
|
(pic cs:powx0) -- node[below=4pt]{\num{24} occurrences de \texttt{x}} (pic cs:powxn);
|
|
}%
|
|
}
|
|
\only<10-14>{\vspace{11pt}}
|
|
|
|
\only<15>{\vspace{-3ex}\center $\implies$ exponentiation rapide par le compilateur}
|
|
|
|
\tikz[remember picture,overlay,->,>=stealth,rounded corners,thick]{%
|
|
\only<4>{
|
|
\draw[<-] ([shift={(-.1em,.5ex)}]pic cs:powimul) -- +(-10mm,0) node[left]{\texttt{r *= x}};
|
|
}
|
|
\only<5>{
|
|
\draw[<-] ([shift={(-.1em,.5ex)}]pic cs:powsub) -- +(-10mm,0) node[left]{\texttt{n-{}-}};
|
|
}
|
|
\only<6>{
|
|
\draw ([shift={(-.1em,.5ex)}]pic cs:powjend) -- ++(-12mm,0)
|
|
|- node[pos=.25,left]{si \textcolor[rgb]{.53,0,0}{\texttt{esi}} $\leqslant 0$} ([shift={(-.1em,.5ex)}]pic cs:powlend);
|
|
\draw ([shift={(-.1em,.5ex)}]pic cs:powjloop) -- ++(-8mm,0) |- ([shift={(-.1em,.5ex)}]pic cs:powlloop);
|
|
}
|
|
\only<7>{
|
|
\draw ([shift={(-.1em,.5ex)}]pic cs:powjloop) -- ++(-8mm,0)
|
|
|- node[pos=.25,left]{tant que \textcolor[rgb]{.53,0,0}{\texttt{eax}} $>0$} ([shift={(-.1em,.5ex)}]pic cs:powlloop);
|
|
}
|
|
}%
|
|
%}}}
|
|
\end{frame}
|
|
%}}}
|
|
|
|
%{{{
|
|
\begin{frame}{Patrons d'expression}
|
|
%{{{ frame "
|
|
\framesubtitle{Concept}
|
|
|
|
\begin{itemize}
|
|
\item traitement d'arbre syntaxiques abstraits
|
|
\item acquisition avec un langage embarqué
|
|
\end{itemize}
|
|
|
|
\begin{columns}<only@-5>
|
|
\begin{column}{.32\paperwidth}
|
|
\vspace{1mm}
|
|
\lstvisible<2->{mp/edsl_basic}
|
|
\lstvisible<4->{mp/et_basic}
|
|
\end{column}
|
|
\begin{column}{.56\paperwidth}
|
|
\figonly<3-4>{mp/et_basic}
|
|
\only<5>{\vspace{1mm}}
|
|
\lstonly<5>{mp/opmul}
|
|
\lstonly<5>{mp/opadd}
|
|
\end{column}
|
|
\end{columns}
|
|
|
|
\only<6->{\vspace{15.75mm}}% fix v pos
|
|
\begin{exampleblock}<only@6->{Applications}
|
|
\begin{itemize}
|
|
\item Eigen : optimisation de calculs matriciels
|
|
\item Adept : optimisation de dérivées de fonctions
|
|
\item Parallélisation assistée/automatique
|
|
\end{itemize}
|
|
\end{exampleblock}
|
|
%}}}
|
|
\end{frame}
|
|
%}}}
|
|
|
|
%{{{
|
|
\begin{frame}{Patrons d'expression}
|
|
%{{{ frame "
|
|
\framesubtitle{Exemple d'optimisation}
|
|
|
|
\only<-3>{\vspace{-2ex}}
|
|
|
|
\begin{columns}<only@-3>
|
|
\begin{column}{.4\paperwidth}
|
|
\lst{mp/edsl_linexpr}
|
|
\lstvisible<2->{mp/et}
|
|
\end{column}
|
|
\begin{column}{.55\paperwidth}
|
|
% \vspace{-39mm}
|
|
\visible<3>{
|
|
\center Motif \og affine \fg\vspace{-1ex}
|
|
\lst{mp/et_pattern_lin}
|
|
|
|
\center Motif \og constante \texttimes{} affine \fg\vspace{-1ex}
|
|
\lst{mp/et_pattern_mulcstlin}
|
|
|
|
\center Motif \og affine $-$ affine \fg\vspace{-1ex}
|
|
\lst{mp/et_pattern_sublinlin}
|
|
}
|
|
\end{column}
|
|
\end{columns}
|
|
|
|
\begin{columns}<only@4>
|
|
\begin{column}{.3995\paperwidth}
|
|
\lst{mp/edsl_linexpr}
|
|
\end{column}
|
|
\end{columns}
|
|
\begin{columns}<only@5>
|
|
\begin{column}{.3275\paperwidth}
|
|
\lst{mp/edsl_linexpr_opti0}
|
|
\end{column}
|
|
\end{columns}
|
|
\begin{columns}<only@6-7>
|
|
\begin{column}{.17\paperwidth}
|
|
\lst{mp/edsl_linexpr_opti}
|
|
\end{column}
|
|
\end{columns}
|
|
\begin{overprint}
|
|
\onslide+<4>
|
|
\fig{mp/et_linexpr}
|
|
\onslide+<5>
|
|
\fig{mp/et_linexpr_opti0}
|
|
\onslide+<6->
|
|
\fig{mp/et_linexpr_opti1}
|
|
\only<7>{
|
|
\begin{itemize}
|
|
\item code effectif produit
|
|
\item analyse durant la compilation
|
|
\end{itemize}
|
|
}
|
|
\end{overprint}
|
|
%}}}
|
|
\end{frame}
|
|
%}}}
|
|
|
|
%{{{
|
|
\begin{frame}{Atouts de la métaprogrammation template}
|
|
%{{{ frame "
|
|
\begin{itemize}
|
|
\item Analyse et génération de code durant la compilation
|
|
\vspace{1ex}
|
|
\item Possibilité de le faire sans surcoût
|
|
\vspace{1ex}
|
|
\item C++ standard
|
|
\end{itemize}
|
|
%}}}
|
|
\end{frame}
|
|
%}}}
|