<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> <title>FAUST compiler: delayline.cpp Source File</title> <link href="tabs.css" rel="stylesheet" type="text/css"/> <link href="doxygen.css" rel="stylesheet" type="text/css"/> </head> <body> <!-- Generated by Doxygen 1.6.3 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <h1>delayline.cpp</h1><a href="delayline_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="preprocessor">#include "<a class="code" href="delayline_8hh.html">delayline.hh</a>"</span> <a name="l00002"></a>00002 <span class="preprocessor">#include "<a class="code" href="Text_8hh.html">Text.hh</a>"</span> <a name="l00003"></a>00003 <a name="l00004"></a>00004 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="compile__vect_8cpp.html#a6913f43c820ecbf6076c31d40598b7ee">gVecSize</a>; <a name="l00005"></a>00005 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="doc__compile_8cpp.html#a278e0cda879c0108aff047853ab0214c">gMaxCopyDelay</a>; <a name="l00006"></a>00006 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="compile__scal_8cpp.html#aed8da6f8f23ca426bf3ea6564e0bd6f2">gSchedulerSwitch</a>; <a name="l00007"></a>00007 <a name="l00008"></a>00008 <a name="l00009"></a><a class="code" href="delayline_8cpp.html#ad4e732d2d6dffb33a5667ab5f13661dd">00009</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="delayline_8cpp.html#ad4e732d2d6dffb33a5667ab5f13661dd">pow2limit</a>(<span class="keywordtype">int</span> x) <a name="l00010"></a>00010 { <a name="l00011"></a>00011 <span class="keywordtype">int</span> n = 2; <a name="l00012"></a>00012 <span class="keywordflow">while</span> (n < x) { n = 2*n; } <a name="l00013"></a>00013 <span class="keywordflow">return</span> n; <a name="l00014"></a>00014 } <a name="l00015"></a>00015 <a name="l00025"></a><a class="code" href="delayline_8hh.html#a85a77a7e8c1cda1145768eaea5c3e398">00025</a> <span class="keywordtype">void</span> <a class="code" href="delayline_8cpp.html#a4105777e2d8b59892f42b9a157002e9e" title="Generate the code for a (short) delay line.">vectorLoop</a> (<a class="code" href="classKlass.html">Klass</a>* k, <span class="keyword">const</span> <span class="keywordtype">string</span>& tname, <span class="keyword">const</span> <span class="keywordtype">string</span>& vecname, <span class="keyword">const</span> <span class="keywordtype">string</span>& cexp) <a name="l00026"></a>00026 { <a name="l00027"></a>00027 <span class="comment">// -- declare the vector</span> <a name="l00028"></a>00028 k-><a class="code" href="classKlass.html#a9cbf32b697f222569fa953a740c0eb4c">addSharedDecl</a>(vecname); <a name="l00029"></a>00029 <a name="l00030"></a>00030 <span class="comment">// -- variables moved as class fields...</span> <a name="l00031"></a>00031 <span class="keywordflow">if</span> (<a class="code" href="compile__scal_8cpp.html#aed8da6f8f23ca426bf3ea6564e0bd6f2">gSchedulerSwitch</a>) { <a name="l00032"></a>00032 k-><a class="code" href="classKlass.html#acb05aee5dfd9fbc3f14215292bb2c18e">addDeclCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 \t$1[$2];"</span>, tname, vecname, <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(<a class="code" href="compile__vect_8cpp.html#a6913f43c820ecbf6076c31d40598b7ee">gVecSize</a>))); <a name="l00033"></a>00033 } <span class="keywordflow">else</span> { <a name="l00034"></a>00034 k-><a class="code" href="classKlass.html#a0e346099132df472ff00fc44c4a02a9a">addZone1</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 \t$1[$2];"</span>, tname, vecname, <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(<a class="code" href="compile__vect_8cpp.html#a6913f43c820ecbf6076c31d40598b7ee">gVecSize</a>))); <a name="l00035"></a>00035 } <a name="l00036"></a>00036 <a name="l00037"></a>00037 <span class="comment">// -- compute the new samples</span> <a name="l00038"></a>00038 k-><a class="code" href="classKlass.html#afb18d2c8b90b89695d866dfa4d4ff52e">addExecCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0[i] = $1;"</span>, vecname, cexp)); <a name="l00039"></a>00039 } <a name="l00040"></a>00040 <a name="l00041"></a>00041 <a name="l00051"></a><a class="code" href="delayline_8hh.html#aeeff01069783bf9c6ec3f18fda583a42">00051</a> <span class="keywordtype">void</span> <a class="code" href="delayline_8cpp.html#aeeff01069783bf9c6ec3f18fda583a42" title="Generate the code for a (short) delay line.">dlineLoop</a> (<a class="code" href="classKlass.html">Klass</a>* k, <span class="keyword">const</span> <span class="keywordtype">string</span>& tname, <span class="keyword">const</span> <span class="keywordtype">string</span>& dlname, <span class="keywordtype">int</span> delay, <span class="keyword">const</span> <span class="keywordtype">string</span>& cexp) <a name="l00052"></a>00052 { <a name="l00053"></a>00053 <span class="keywordflow">if</span> (delay < <a class="code" href="doc__compile_8cpp.html#a278e0cda879c0108aff047853ab0214c">gMaxCopyDelay</a>) { <a name="l00054"></a>00054 <a name="l00055"></a>00055 <span class="comment">// Implementation of a copy based delayline</span> <a name="l00056"></a>00056 <a name="l00057"></a>00057 <span class="comment">// create names for temporary and permanent storage </span> <a name="l00058"></a>00058 <span class="keywordtype">string</span> buf = <a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0_tmp"</span>, dlname); <a name="l00059"></a>00059 <span class="keywordtype">string</span> pmem= <a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0_perm"</span>, dlname); <a name="l00060"></a>00060 <a name="l00061"></a>00061 <span class="comment">// constraints delay size to be multiple of 4</span> <a name="l00062"></a>00062 delay = (delay+3)&-4; <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="comment">// allocate permanent storage for delayed samples</span> <a name="l00065"></a>00065 <span class="keywordtype">string</span> dsize = <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(delay); <a name="l00066"></a>00066 k-><a class="code" href="classKlass.html#acb05aee5dfd9fbc3f14215292bb2c18e">addDeclCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 \t$1[$2];"</span>, tname, pmem, dsize)); <a name="l00067"></a>00067 <a name="l00068"></a>00068 <span class="comment">// init permanent memory</span> <a name="l00069"></a>00069 k-><a class="code" href="classKlass.html#a0a95cda1c8e5e601dd67b80573105af3">addInitCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"for (int i=0; i<$1; i++) $0[i]=0;"</span>, pmem, dsize)); <a name="l00070"></a>00070 <a name="l00071"></a>00071 <span class="comment">// compute method</span> <a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="comment">// -- declare a buffer and a "shifted" vector</span> <a name="l00074"></a>00074 k-><a class="code" href="classKlass.html#a9cbf32b697f222569fa953a740c0eb4c">addSharedDecl</a>(buf); <a name="l00075"></a>00075 <a name="l00076"></a>00076 <span class="comment">// -- variables moved as class fields...</span> <a name="l00077"></a>00077 <span class="keywordflow">if</span> (<a class="code" href="compile__scal_8cpp.html#aed8da6f8f23ca426bf3ea6564e0bd6f2">gSchedulerSwitch</a>) { <a name="l00078"></a>00078 k-><a class="code" href="classKlass.html#acb05aee5dfd9fbc3f14215292bb2c18e">addDeclCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 \t$1[$2+$3];"</span>, tname, buf, <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(<a class="code" href="compile__vect_8cpp.html#a6913f43c820ecbf6076c31d40598b7ee">gVecSize</a>), dsize)); <a name="l00079"></a>00079 } <span class="keywordflow">else</span> { <a name="l00080"></a>00080 k-><a class="code" href="classKlass.html#a0e346099132df472ff00fc44c4a02a9a">addZone1</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 \t$1[$2+$3];"</span>, tname, buf, <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(<a class="code" href="compile__vect_8cpp.html#a6913f43c820ecbf6076c31d40598b7ee">gVecSize</a>), dsize)); <a name="l00081"></a>00081 } <a name="l00082"></a>00082 <a name="l00083"></a>00083 k-><a class="code" href="classKlass.html#a85cbd66d7268d87442a19b4371a15272">addFirstPrivateDecl</a>(dlname); <a name="l00084"></a>00084 k-><a class="code" href="classKlass.html#a28f906237d7648909e66f593ac19ec82">addZone2</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0* \t$1 = &$2[$3];"</span>, tname, dlname, buf, dsize)); <a name="l00085"></a>00085 <a name="l00086"></a>00086 <span class="comment">// -- copy the stored samples to the delay line</span> <a name="l00087"></a>00087 k-><a class="code" href="classKlass.html#ac882bd15af33eef0ec0d90a7c61e88cb">addPreCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"for (int i=0; i<$2; i++) $0[i]=$1[i];"</span>, buf, pmem, dsize)); <a name="l00088"></a>00088 <a name="l00089"></a>00089 <span class="comment">// -- compute the new samples</span> <a name="l00090"></a>00090 k-><a class="code" href="classKlass.html#afb18d2c8b90b89695d866dfa4d4ff52e">addExecCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0[i] = $1;"</span>, dlname, cexp)); <a name="l00091"></a>00091 <a name="l00092"></a>00092 <span class="comment">// -- copy back to stored samples</span> <a name="l00093"></a>00093 k-><a class="code" href="classKlass.html#a9e4aa8af46e099cdfc0cb2775239620f">addPostCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"for (int i=0; i<$2; i++) $0[i]=$1[count+i];"</span>, pmem, buf, dsize)); <a name="l00094"></a>00094 <a name="l00095"></a>00095 } <span class="keywordflow">else</span> { <a name="l00096"></a>00096 <a name="l00097"></a>00097 <span class="comment">// Implementation of a ring-buffer delayline</span> <a name="l00098"></a>00098 <a name="l00099"></a>00099 <span class="comment">// the size should be large enough and aligned on a power of two</span> <a name="l00100"></a>00100 delay = <a class="code" href="delayline_8cpp.html#ad4e732d2d6dffb33a5667ab5f13661dd">pow2limit</a>(delay + <a class="code" href="compile__vect_8cpp.html#a6913f43c820ecbf6076c31d40598b7ee">gVecSize</a>); <a name="l00101"></a>00101 <span class="keywordtype">string</span> dsize = <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(delay); <a name="l00102"></a>00102 <span class="keywordtype">string</span> mask = <a class="code" href="Text_8cpp.html#a16bacb907294be37af81cdf9aff4449a">T</a>(delay-1); <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="comment">// create names for temporary and permanent storage </span> <a name="l00105"></a>00105 <span class="keywordtype">string</span> idx = <a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0_idx"</span>, dlname); <a name="l00106"></a>00106 <span class="keywordtype">string</span> idx_save = <a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0_idx_save"</span>, dlname); <a name="l00107"></a>00107 <a name="l00108"></a>00108 <span class="comment">// allocate permanent storage for delayed samples</span> <a name="l00109"></a>00109 k-><a class="code" href="classKlass.html#acb05aee5dfd9fbc3f14215292bb2c18e">addDeclCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 \t$1[$2];"</span>, tname, dlname, dsize)); <a name="l00110"></a>00110 k-><a class="code" href="classKlass.html#acb05aee5dfd9fbc3f14215292bb2c18e">addDeclCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"int \t$0;"</span>, idx)); <a name="l00111"></a>00111 k-><a class="code" href="classKlass.html#acb05aee5dfd9fbc3f14215292bb2c18e">addDeclCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"int \t$0;"</span>, idx_save)); <a name="l00112"></a>00112 <a name="l00113"></a>00113 <span class="comment">// init permanent memory</span> <a name="l00114"></a>00114 k-><a class="code" href="classKlass.html#a0a95cda1c8e5e601dd67b80573105af3">addInitCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"for (int i=0; i<$1; i++) $0[i]=0;"</span>, dlname, dsize)); <a name="l00115"></a>00115 k-><a class="code" href="classKlass.html#a0a95cda1c8e5e601dd67b80573105af3">addInitCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 = 0;"</span>, idx)); <a name="l00116"></a>00116 k-><a class="code" href="classKlass.html#a0a95cda1c8e5e601dd67b80573105af3">addInitCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 = 0;"</span>, idx_save)); <a name="l00117"></a>00117 <a name="l00118"></a>00118 <span class="comment">// -- update index</span> <a name="l00119"></a>00119 k-><a class="code" href="classKlass.html#ac882bd15af33eef0ec0d90a7c61e88cb">addPreCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 = ($0+$1)&$2;"</span>, idx, idx_save, mask)); <a name="l00120"></a>00120 <a name="l00121"></a>00121 <span class="comment">// -- compute the new samples</span> <a name="l00122"></a>00122 k-><a class="code" href="classKlass.html#afb18d2c8b90b89695d866dfa4d4ff52e">addExecCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0[($2+i)&$3] = $1;"</span>, dlname, cexp, idx, mask)); <a name="l00123"></a>00123 <a name="l00124"></a>00124 <span class="comment">// -- save index</span> <a name="l00125"></a>00125 k-><a class="code" href="classKlass.html#a9e4aa8af46e099cdfc0cb2775239620f">addPostCode</a>(<a class="code" href="Text_8cpp.html#af50e951c134c2c98c4c75d687f8fca7a">subst</a>(<span class="stringliteral">"$0 = count;"</span>, idx_save)); <a name="l00126"></a>00126 } <a name="l00127"></a>00127 } </pre></div></div> <hr class="footer"/><address style="text-align: right;"><small>Generated on Wed Apr 28 23:59:58 2010 for FAUST compiler by <a href="http://www.doxygen.org/index.html"> <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.6.3 </small></address> </body> </html>