Compile a list of FAUST signals into a vector C++ class. More...
#include <compile_sched.hh>
Inherits VectorCompiler.
Public Member Functions | |
SchedulerCompiler (const string &name, const string &super, int numInputs, int numOutputs) | |
SchedulerCompiler (Klass *k) | |
virtual void | compileMultiSignal (Tree L) |
Protected Member Functions | |
virtual void | vectorLoop (const string &tname, const string &dlname, const string &cexp) |
Generate the code for a (short) delay line. | |
virtual void | dlineLoop (const string &tname, const string &dlname, int delay, const string &cexp) |
Generate the code for a (short) delay line. |
Compile a list of FAUST signals into a vector C++ class.
Definition at line 37 of file compile_sched.hh.
SchedulerCompiler::SchedulerCompiler | ( | const string & | name, | |
const string & | super, | |||
int | numInputs, | |||
int | numOutputs | |||
) | [inline] |
Definition at line 42 of file compile_sched.hh.
00043 : VectorCompiler(name,super,numInputs,numOutputs) 00044 {}
SchedulerCompiler::SchedulerCompiler | ( | Klass * | k | ) | [inline] |
Definition at line 46 of file compile_sched.hh.
00046 : VectorCompiler(k) 00047 {}
void SchedulerCompiler::compileMultiSignal | ( | Tree | L | ) | [virtual] |
Reimplemented from VectorCompiler.
Definition at line 30 of file compile_sched.cpp.
References Klass::addExecCode(), Klass::addSharedDecl(), Klass::addZone3(), Klass::buildTasksList(), Klass::closeLoop(), VectorCompiler::CS(), Compiler::fClass, Compiler::fDescription, Compiler::fUIRoot, Compiler::generateMacroInterfaceTree(), Compiler::generateUserInterfaceTree(), hd(), Klass::inputs(), isList(), Klass::openLoop(), Klass::outputs(), ScalarCompiler::prepare(), Compiler::prepareUserInterfaceTree(), subst(), T(), tl(), Description::ui(), xcast(), and xfloat().
00031 { 00032 //contextor recursivness(0); 00033 L = prepare(L); // optimize, share and annotate expression 00034 00035 for (int i = 0; i < fClass->inputs(); i++) { 00036 fClass->addZone3(subst("$1* input$0 = &input[$0][fIndex];", T(i), xfloat())); 00037 } 00038 for (int i = 0; i < fClass->outputs(); i++) { 00039 fClass->addZone3(subst("$1* output$0 = &output[$0][fIndex];", T(i), xfloat())); 00040 } 00041 00042 fClass->addSharedDecl("fullcount"); 00043 fClass->addSharedDecl("input"); 00044 fClass->addSharedDecl("output"); 00045 00046 for (int i = 0; isList(L); L = tl(L), i++) { 00047 Tree sig = hd(L); 00048 fClass->openLoop("count"); 00049 fClass->addExecCode(subst("output$0[i] = $2$1;", T(i), CS(sig), xcast())); 00050 fClass->closeLoop(); 00051 } 00052 00053 // Build tasks list 00054 fClass->buildTasksList(); 00055 00056 generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot)); 00057 generateMacroInterfaceTree("", prepareUserInterfaceTree(fUIRoot)); 00058 if (fDescription) { 00059 fDescription->ui(prepareUserInterfaceTree(fUIRoot)); 00060 } 00061 }
void SchedulerCompiler::dlineLoop | ( | const string & | tname, | |
const string & | dlname, | |||
int | delay, | |||
const string & | cexp | |||
) | [protected, virtual] |
Generate the code for a (short) delay line.
k | the c++ class where the delay line will be placed. | |
l | the loop where the code will be placed. | |
tname | the name of the C++ type (float or int) | |
dlname | the name of the delay line (vector) to be used. | |
delay | the maximum delay | |
cexp | the content of the signal as a C++ expression |
Reimplemented from VectorCompiler.
Definition at line 95 of file compile_sched.cpp.
References Klass::addDeclCode(), Klass::addExecCode(), Klass::addFirstPrivateDecl(), Klass::addInitCode(), Klass::addPostCode(), Klass::addPreCode(), Klass::addSharedDecl(), Klass::addZone2(), Compiler::fClass, gMaxCopyDelay, gVecSize, ScalarCompiler::pow2limit(), subst(), and T().
00096 { 00097 if (delay < gMaxCopyDelay) { 00098 00099 // Implementation of a copy based delayline 00100 00101 // create names for temporary and permanent storage 00102 string buf = subst("$0_tmp", dlname); 00103 string pmem= subst("$0_perm", dlname); 00104 00105 // constraints delay size to be multiple of 4 00106 delay = (delay+3)&-4; 00107 00108 // allocate permanent storage for delayed samples 00109 string dsize = T(delay); 00110 fClass->addDeclCode(subst("$0 \t$1[$2];", tname, pmem, dsize)); 00111 00112 // init permanent memory 00113 fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i]=0;", pmem, dsize)); 00114 00115 // compute method 00116 00117 // -- declare a buffer and a "shifted" vector 00118 fClass->addSharedDecl(buf); 00119 00120 // -- variables moved as class fields... 00121 fClass->addDeclCode(subst("$0 \t$1[$2+$3];", tname, buf, T(gVecSize), dsize)); 00122 00123 fClass->addFirstPrivateDecl(dlname); 00124 fClass->addZone2(subst("$0* \t$1 = &$2[$3];", tname, dlname, buf, dsize)); 00125 00126 // -- copy the stored samples to the delay line 00127 fClass->addPreCode(subst("for (int i=0; i<$2; i++) $0[i]=$1[i];", buf, pmem, dsize)); 00128 00129 // -- compute the new samples 00130 fClass->addExecCode(subst("$0[i] = $1;", dlname, cexp)); 00131 00132 // -- copy back to stored samples 00133 fClass->addPostCode(subst("for (int i=0; i<$2; i++) $0[i]=$1[count+i];", pmem, buf, dsize)); 00134 00135 } else { 00136 00137 // Implementation of a ring-buffer delayline 00138 00139 // the size should be large enough and aligned on a power of two 00140 delay = pow2limit(delay + gVecSize); 00141 string dsize = T(delay); 00142 string mask = T(delay-1); 00143 00144 // create names for temporary and permanent storage 00145 string idx = subst("$0_idx", dlname); 00146 string idx_save = subst("$0_idx_save", dlname); 00147 00148 // allocate permanent storage for delayed samples 00149 fClass->addDeclCode(subst("$0 \t$1[$2];", tname, dlname, dsize)); 00150 fClass->addDeclCode(subst("int \t$0;", idx)); 00151 fClass->addDeclCode(subst("int \t$0;", idx_save)); 00152 00153 // init permanent memory 00154 fClass->addInitCode(subst("for (int i=0; i<$1; i++) $0[i]=0;", dlname, dsize)); 00155 fClass->addInitCode(subst("$0 = 0;", idx)); 00156 fClass->addInitCode(subst("$0 = 0;", idx_save)); 00157 00158 // -- update index 00159 fClass->addPreCode(subst("$0 = ($0+$1)&$2;", idx, idx_save, mask)); 00160 00161 // -- compute the new samples 00162 fClass->addExecCode(subst("$0[($2+i)&$3] = $1;", dlname, cexp, idx, mask)); 00163 00164 // -- save index 00165 fClass->addPostCode(subst("$0 = count;", idx_save)); 00166 } 00167 }
void SchedulerCompiler::vectorLoop | ( | const string & | tname, | |
const string & | vecname, | |||
const string & | cexp | |||
) | [protected, virtual] |
Generate the code for a (short) delay line.
k | the c++ class where the delay line will be placed. | |
l | the loop where the code will be placed. | |
tname | the name of the C++ type (float or int) | |
dlname | the name of the delay line (vector) to be used. | |
delay | the maximum delay | |
cexp | the content of the signal as a C++ expression |
Reimplemented from VectorCompiler.
Definition at line 73 of file compile_sched.cpp.
References Klass::addDeclCode(), Klass::addExecCode(), Klass::addSharedDecl(), Compiler::fClass, gVecSize, subst(), and T().
00074 { 00075 // -- declare the vector 00076 fClass->addSharedDecl(vecname); 00077 00078 // -- variables moved as class fields... 00079 fClass->addDeclCode(subst("$0 \t$1[$2];", tname, vecname, T(gVecSize))); 00080 00081 // -- compute the new samples 00082 fClass->addExecCode(subst("$0[i] = $1;", vecname, cexp)); 00083 }