00001 #include "delayline.hh"
00002 #include "Text.hh"
00003
00004 extern int gVecSize;
00005 extern int gMaxCopyDelay;
00006 extern int gSchedulerSwitch;
00007
00008
00009 static int pow2limit(int x)
00010 {
00011 int n = 2;
00012 while (n < x) { n = 2*n; }
00013 return n;
00014 }
00015
00025 void vectorLoop (Klass* k, const string& tname, const string& vecname, const string& cexp)
00026 {
00027
00028 k->addSharedDecl(vecname);
00029
00030
00031 if (gSchedulerSwitch) {
00032 k->addDeclCode(subst("$0 \t$1[$2];", tname, vecname, T(gVecSize)));
00033 } else {
00034 k->addZone1(subst("$0 \t$1[$2];", tname, vecname, T(gVecSize)));
00035 }
00036
00037
00038 k->addExecCode(subst("$0[i] = $1;", vecname, cexp));
00039 }
00040
00041
00051 void dlineLoop (Klass* k, const string& tname, const string& dlname, int delay, const string& cexp)
00052 {
00053 if (delay < gMaxCopyDelay) {
00054
00055
00056
00057
00058 string buf = subst("$0_tmp", dlname);
00059 string pmem= subst("$0_perm", dlname);
00060
00061
00062 delay = (delay+3)&-4;
00063
00064
00065 string dsize = T(delay);
00066 k->addDeclCode(subst("$0 \t$1[$2];", tname, pmem, dsize));
00067
00068
00069 k->addInitCode(subst("for (int i=0; i<$1; i++) $0[i]=0;", pmem, dsize));
00070
00071
00072
00073
00074 k->addSharedDecl(buf);
00075
00076
00077 if (gSchedulerSwitch) {
00078 k->addDeclCode(subst("$0 \t$1[$2+$3];", tname, buf, T(gVecSize), dsize));
00079 } else {
00080 k->addZone1(subst("$0 \t$1[$2+$3];", tname, buf, T(gVecSize), dsize));
00081 }
00082
00083 k->addFirstPrivateDecl(dlname);
00084 k->addZone2(subst("$0* \t$1 = &$2[$3];", tname, dlname, buf, dsize));
00085
00086
00087 k->addPreCode(subst("for (int i=0; i<$2; i++) $0[i]=$1[i];", buf, pmem, dsize));
00088
00089
00090 k->addExecCode(subst("$0[i] = $1;", dlname, cexp));
00091
00092
00093 k->addPostCode(subst("for (int i=0; i<$2; i++) $0[i]=$1[count+i];", pmem, buf, dsize));
00094
00095 } else {
00096
00097
00098
00099
00100 delay = pow2limit(delay + gVecSize);
00101 string dsize = T(delay);
00102 string mask = T(delay-1);
00103
00104
00105 string idx = subst("$0_idx", dlname);
00106 string idx_save = subst("$0_idx_save", dlname);
00107
00108
00109 k->addDeclCode(subst("$0 \t$1[$2];", tname, dlname, dsize));
00110 k->addDeclCode(subst("int \t$0;", idx));
00111 k->addDeclCode(subst("int \t$0;", idx_save));
00112
00113
00114 k->addInitCode(subst("for (int i=0; i<$1; i++) $0[i]=0;", dlname, dsize));
00115 k->addInitCode(subst("$0 = 0;", idx));
00116 k->addInitCode(subst("$0 = 0;", idx_save));
00117
00118
00119 k->addPreCode(subst("$0 = ($0+$1)&$2;", idx, idx_save, mask));
00120
00121
00122 k->addExecCode(subst("$0[($2+i)&$3] = $1;", dlname, cexp, idx, mask));
00123
00124
00125 k->addPostCode(subst("$0 = count;", idx_save));
00126 }
00127 }