00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "compile_vect.hh"
00025 #include "compatibility.hh"
00026
00027 #include "compile.hh"
00028 #include "compile_scal.hh"
00029 #include "sigtype.hh"
00030
00031 #include <stdio.h>
00032 #include <iostream>
00033 #include <sstream>
00034
00035 #include "sigprint.hh"
00036 #include "sigtyperules.hh"
00037 #include "simplify.hh"
00038 #include "privatise.hh"
00039 #include "prim2.hh"
00040
00041
00042 static Klass* signal2klass (const string& name, Tree sig)
00043 {
00044 Type t = getSigType(sig);
00045 if (t->nature() == kInt) {
00046
00047 ScalarCompiler C( new SigIntGenKlass(name) );
00048 C.compileSingleSignal(sig);
00049 return C.getClass();
00050
00051 } else {
00052
00053 ScalarCompiler C( new SigFloatGenKlass(name) );
00054 C.compileSingleSignal(sig);
00055 return C.getClass();
00056
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067 string VectorCompiler::getFreshID ( const char* prefix)
00068 {
00069 char c[64];
00070
00071 if (fIDCounters.find(prefix) == fIDCounters.end()) {
00072 fIDCounters[prefix]=0;
00073 }
00074
00075 int n = fIDCounters[prefix];
00076
00077 fIDCounters[prefix] = n+1;
00078
00079 snprintf(c, 63, "%s%d", prefix, n);
00080
00081 return string(c);
00082 }
00083
00084
00085
00086
00087
00088
00089
00090 Tree VectorCompiler::makeCompileKey(Tree t, int unroll)
00091 {
00092 char name[256];
00093 snprintf(name, 256, "%d COMPILED IN %p : ", unroll, (CTree*)t);
00094 return tree(unique(name));
00095 }
00096
00097
00098
00099
00100
00101
00102 Tree VectorCompiler::prepare(Tree L0)
00103 {
00104 Tree L3 = Compiler::prepare(L0);
00105
00106 sharingAnalysis(L3);
00107
00108 fCompileScalKey[0] = makeCompileKey(L3,0);
00109 fCompileScalKey[1] = makeCompileKey(L3,1);
00110 fCompileScalKey[2] = makeCompileKey(L3,2);
00111 fCompileScalKey[3] = makeCompileKey(L3,3);
00112 fCompileScalarVecKey[0] = makeCompileKey(L3,0);
00113 fCompileScalarVecKey[1] = makeCompileKey(L3,1);
00114 fCompileScalarVecKey[2] = makeCompileKey(L3,2);
00115 fCompileScalarVecKey[3] = makeCompileKey(L3,3);
00116 fCompileVecKey = makeCompileKey(L3,0);
00117
00118 fIDKey = tree(unique("IDKEY"));
00119
00120 return L3;
00121 }
00122
00123
00124
00125
00126
00127 #if 0
00128 void VectorCompiler::compileMultiSignal (Tree L)
00129 {
00130 L = prepare(L);
00131 for (int i = 0; i < fClass->inputs(); i++) {
00132 fClass->addSlowCode(subst("float* input$0 __attribute__ ((aligned(16))); input$0 = input[$0];", T(i)));
00133 }
00134 for (int i = 0; i < fClass->outputs(); i++) {
00135 fClass->addSlowCode(subst("float* output$0 __attribute__ ((aligned(16))); output$0 = output[$0]; vec_float vec_output$0;", T(i)));
00136 }
00137 for (int i = 0; isList(L); L = tl(L), i++) {
00138 Tree sig = hd(L);
00139
00140 Type t = getSigType(sig, NULLENV);
00141
00142 if(t->boolean()==kBool) fClass->addExecCode(subst("vec_output$0 = bool2float($1);", T(i), CS(NULLENV,sig,kVect)));
00143 else if(t->nature()==kInt) fClass->addExecCode(subst("vec_output$0 = int2float($1);", T(i), CS(NULLENV,sig,kVect)));
00144 else fClass->addExecCode(subst("vec_output$0 = $1;", T(i), CS(NULLENV,sig,kVect)));
00145
00146 fClass->addExecCode(subst("store_a_vec(&output$0[i], vec_output$0);",T(i)));
00147 }
00148 generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot));
00149 }
00150 #endif
00151
00152 void VectorCompiler::compileMultiSignal (Tree L)
00153 {
00154 L = prepare(L);
00155 for (int i = 0; i < fClass->inputs(); i++) {
00156 fClass->addSlowCode(subst("float* input$0 __attribute__ ((aligned(16))); input$0 = input[$0];", T(i)));
00157 }
00158 for (int i = 0; i < fClass->outputs(); i++) {
00159 fClass->addSlowCode(subst("float* output$0 __attribute__ ((aligned(16))); output$0 = output[$0];", T(i)));
00160 }
00161 for (int i = 0; isList(L); L = tl(L), i++) {
00162 Tree sig = hd(L);
00163
00164 Type t = getSigType(sig);
00165
00166 if(t->boolean()==kBool) fClass->addExecCode(subst("store_stream(&output$0[i], bool2float($1));", T(i), CS(NULLENV,sig,kVect)));
00167 else if(t->nature()==kInt) fClass->addExecCode(subst("store_stream(&output$0[i], int2float($1));", T(i), CS(NULLENV,sig,kVect)));
00168 else fClass->addExecCode(subst("store_stream(&output$0[i], $1);", T(i), CS(NULLENV,sig,kVect)));
00169 }
00170 generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot));
00171 if (fDescription) {
00172 fDescription->ui(prepareUserInterfaceTree(fUIRoot));
00173 }
00174 }
00175
00176
00177
00178
00179
00180
00181 void VectorCompiler::compileSingleSignal (Tree sig)
00182 {
00183 sig = prepare(sig);
00184
00185 fClass->addSlowCode("float* input _attribute__ ((aligned(16))); input = input[0];");
00186
00187 fClass->addSlowCode("float* output __attribute__ ((aligned(16))); output = output[0]; vec_float vec_output;");
00188
00189
00190 Type t = getSigType(sig);
00191
00192 if(t->boolean()==kBool) fClass->addExecCode(subst("vec_output = bool2float($0);", CS(NULLENV,sig,kVect)));
00193 else if(t->nature()==kInt) fClass->addExecCode(subst("vec_output = int2float($0);", CS(NULLENV,sig,kVect)));
00194 else fClass->addExecCode(subst("vec_output = $0;", CS(NULLENV,sig,kVect)));
00195
00196 fClass->addExecCode("store_a_vec(&output[i], vec_output);");
00197
00198
00199 generateUserInterfaceTree(prepareUserInterfaceTree(fUIRoot));
00200 if (fDescription) {
00201 fDescription->ui(prepareUserInterfaceTree(fUIRoot));
00202 }
00203 }
00204
00205
00206
00207
00216 string VectorCompiler::CS (Tree env, Tree sig, int context)
00217 {
00218
00219
00220
00221
00222
00223 Tree prop;
00224
00225 Type t = getSigType(sig);
00226 int type = t->vectorability();
00227 int varia = t->variability();
00228
00229
00230
00231 if((context==kVect)&&(getProperty(sig,fCompileVecKey,prop))) return tree2str(prop);
00232 else if((context==kScal)&&(getProperty(sig,fCompileScalarVecKey[loop_unroll],prop))) return tree2str(prop);
00233 else if((context==kTrueScal)&&(getProperty(sig,fCompileScalKey[loop_unroll],prop))) return tree2str(prop);
00234
00235 else if((varia==kSamp)&&(context==kScal)&&(getProperty(sig,fCompileVecKey,prop))) {
00236
00237 string temp;
00238 if(shcount(fSharingKeyScal,sig)>1) {
00239
00240 temp = generateCacheCode(env,sig,subst("VEC2SCALVEC0($0)",tree2str(prop)),kScal);
00241 setProperty(sig,fCompileScalarVecKey[0],tree(temp));
00242 setProperty(sig,fCompileScalarVecKey[1],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC1($0)",tree2str(prop)),kScal)));
00243 setProperty(sig,fCompileScalarVecKey[2],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC2($0)",tree2str(prop)),kScal)));
00244 setProperty(sig,fCompileScalarVecKey[3],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC3($0)",tree2str(prop)),kScal)));
00245
00246 } else {
00247
00248 temp = subst("VEC2SCALVEC0($0)",tree2str(prop));
00249 setProperty(sig,fCompileScalarVecKey[0],tree(temp));
00250 setProperty(sig,fCompileScalarVecKey[1],tree(subst("VEC2SCALVEC1($0)",tree2str(prop))));
00251 setProperty(sig,fCompileScalarVecKey[2],tree(subst("VEC2SCALVEC2($0)",tree2str(prop))));
00252 setProperty(sig,fCompileScalarVecKey[3],tree(subst("VEC2SCALVEC3($0)",tree2str(prop))));
00253
00254 }
00255
00256 return temp;
00257
00258 } else if((varia==kSamp)&&(context==kTrueScal)&&(getProperty(sig,fCompileVecKey,prop))) {
00259
00260 string vname = getFreshID("vec_tempScal");
00261
00262
00263 if (t->nature() == kInt) fClass->addExecCode(subst("vec_int $0($1);", vname, tree2str(prop)));
00264 else fClass->addExecCode(subst("vec_float $0($1);", vname, tree2str(prop)));
00265
00266 string temp;
00267 if(shcount(fSharingKeyTrueScal,sig)>1) {
00268
00269 temp = generateCacheCode(env,sig,subst("$0[0]",vname),kTrueScal);
00270 setProperty(sig,fCompileScalKey[0],tree(temp));
00271 setProperty(sig,fCompileScalKey[1],tree(generateCacheCode(env,sig,subst("$0[1]",vname),kTrueScal)));
00272 setProperty(sig,fCompileScalKey[2],tree(generateCacheCode(env,sig,subst("$0[2]",vname),kTrueScal)));
00273 setProperty(sig,fCompileScalKey[3],tree(generateCacheCode(env,sig,subst("$0[3]",vname),kTrueScal)));
00274
00275 } else {
00276
00277 temp = subst("$0[0]",vname);
00278 setProperty(sig,fCompileScalKey[0],tree(temp));
00279 setProperty(sig,fCompileScalKey[1],tree(subst("$0[1]",vname)));
00280 setProperty(sig,fCompileScalKey[2],tree(subst("$0[2]",vname)));
00281 setProperty(sig,fCompileScalKey[3],tree(subst("$0[3]",vname)));
00282
00283 }
00284
00285 return temp;
00286
00287
00288
00289 } else {
00290
00291 string code;
00292 int i;
00293 Tree id,z,x,y,ff,largs,label,le;
00294
00295
00296
00297
00298 if(context==kVect) {
00299
00300
00301 if(varia==kSamp) {
00302
00303 code = generateVec(env,sig);
00304
00305
00306 if(shcount(fSharingKeyVec,sig)>1) code = generateCacheCode(env,sig,code,kVect);
00307 else if((shcount(fSharingKeyScal,sig)>=1)&&(!getProperty(sig,fCompileScalarVecKey[loop_unroll],prop))) code = generateCacheCode(env,sig,code,kVect);
00308
00309
00310
00311 } else {
00312
00313 code = generateCacheCode(env,sig,CS(env,sig,kTrueScal),kVect);
00314 setProperty(sig,fCompileVecKey,tree(code));
00315 setProperty(sig,fCompileScalarVecKey[0],tree(code));
00316 setProperty(sig,fCompileScalarVecKey[1],tree(code));
00317 setProperty(sig,fCompileScalarVecKey[2],tree(code));
00318 setProperty(sig,fCompileScalarVecKey[3],tree(code));
00319
00320 }
00321
00322 setProperty(sig,fCompileVecKey,tree(code));
00323
00324
00325
00326
00327
00328 } else if(context==kScal) {
00329
00330
00331 if(varia==kSamp) {
00332
00333 if(type==kVect) {
00334
00335 if(isSigInput(sig,&i)&&(shcount(fSharingKeyVec,sig)==1)&&(shcount(fSharingKeyScal,sig)==1)) {
00336
00337 code = generateScalarVec(env,sig);
00338
00339 if(shcount(fSharingKeyScal,sig)>1) code = generateCacheCode(env,sig,code,kScal);
00340 setProperty(sig,fCompileScalarVecKey[loop_unroll],tree(code));
00341
00342 } else if(isProj(sig,&i,x)&&isRec(x,label,le)) {
00343
00344 if(heuristiqueRec(env,sig,&code)) {
00345
00346 string temp = generateCacheCode(env,sig,subst("VEC2SCALVEC0($0)",code),kScal);
00347 setProperty(sig,fCompileScalarVecKey[0],tree(temp));
00348 setProperty(sig,fCompileScalarVecKey[1],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC1($0)",code),kScal)));
00349 setProperty(sig,fCompileScalarVecKey[2],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC2($0)",code),kScal)));
00350 setProperty(sig,fCompileScalarVecKey[3],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC3($0)",code),kScal)));
00351 setProperty(sig,fCompileVecKey,tree(subst("$0",code)));
00352
00353 code = temp;
00354
00355 } else {
00356
00357 code = generateScalarVec(env,sig);
00358 setProperty(sig,fCompileScalarVecKey[loop_unroll],tree(code));
00359 }
00360
00361
00362 } else {
00363
00364
00365
00366
00367 string tempVec = CS(env,sig,kVect);
00368 string temp = generateCacheCode(env,sig,subst("VEC2SCALVEC0($0)",tempVec),kScal);
00369 setProperty(sig,fCompileScalarVecKey[0],tree(temp));
00370 setProperty(sig,fCompileScalarVecKey[1],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC1($0)",tempVec),kScal)));
00371 setProperty(sig,fCompileScalarVecKey[2],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC2($0)",tempVec),kScal)));
00372 setProperty(sig,fCompileScalarVecKey[3],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC3($0)",tempVec),kScal)));
00373
00374 code = temp;
00375 }
00376
00377
00378 } else {
00379 code = generateScalarVec(env,sig);
00380
00381 if(shcount(fSharingKeyScal,sig)>1) code = generateCacheCode(env,sig,code,kScal);
00382 setProperty(sig,fCompileScalarVecKey[loop_unroll],tree(code));
00383
00384 }
00385
00386
00387
00388
00389
00390 } else {
00391
00392 code = generateCacheCode(env,sig,CS(env,sig,kTrueScal),kVect);
00393 setProperty(sig,fCompileVecKey,tree(code));
00394 setProperty(sig,fCompileScalarVecKey[0],tree(code));
00395 setProperty(sig,fCompileScalarVecKey[1],tree(code));
00396 setProperty(sig,fCompileScalarVecKey[2],tree(code));
00397 setProperty(sig,fCompileScalarVecKey[3],tree(code));
00398 }
00399
00400
00401
00402
00403
00404
00405
00406
00407 } else if(context==kTrueScal) {
00408
00409
00410 if(varia==kSamp) {
00411
00412 if(type==kVect) {
00413
00414 if(isSigInput(sig,&i)||isSigGen(sig,x)||isSigTable(sig,id,x,y)||isSigWRTbl(sig,id,x,y,z)||isSigRDTbl(sig,x,y)||isSigFFun(sig,ff,largs)) {
00415
00416 code = generateScal(env,sig);
00417
00418 } else if(isProj(sig,&i,x)&&isRec(x,label,le)) {
00419
00420 code = CS(env,sig,kVect);
00421
00422 string vname = getFreshID("vec_tempScal");
00423
00424
00425 if (t->nature() == kInt) fClass->addExecCode(subst("vec_int $0($1);", vname, code));
00426 else fClass->addExecCode(subst("vec_float $0($1);", vname, code));
00427
00428 setProperty(sig,fCompileScalKey[0],tree(subst("$0[0]",vname)));
00429 setProperty(sig,fCompileScalKey[1],tree(subst("$0[1]",vname)));
00430 setProperty(sig,fCompileScalKey[2],tree(subst("$0[2]",vname)));
00431 setProperty(sig,fCompileScalKey[3],tree(subst("$0[3]",vname)));
00432
00433 code = subst("$0[0]",vname);
00434
00435 } else {
00436
00437 string temp = CS(env,sig,kVect);
00438
00439 string vname = getFreshID("vec_tempScal");
00440
00441
00442 if (t->nature() == kInt) fClass->addExecCode(subst("vec_int $0($1);", vname, temp));
00443 else fClass->addExecCode(subst("vec_float $0($1);", vname, temp));
00444
00445 setProperty(sig,fCompileScalKey[0],tree(subst("$0[0]",vname)));
00446 setProperty(sig,fCompileScalKey[1],tree(subst("$0[1]",vname)));
00447 setProperty(sig,fCompileScalKey[2],tree(subst("$0[2]",vname)));
00448 setProperty(sig,fCompileScalKey[3],tree(subst("$0[3]",vname)));
00449
00450 code = subst("$0[0]",vname);
00451
00452 }
00453
00454
00455 } else {
00456
00457 if(isSigInput(sig,&i)||isSigGen(sig,x)||isSigTable(sig,id,x,y)||isSigWRTbl(sig,id,x,y,z)||isSigRDTbl(sig,x,y)||isSigFFun(sig,ff,largs)) {
00458
00459 code = generateScal(env,sig);
00460
00461 } else {
00462
00463 code = subst("VEC2SCAL0($0)",CS(env,sig,kScal));
00464
00465 }
00466 }
00467
00468 if(shcount(fSharingKeyTrueScal,sig)>1) code = generateCacheCode(env,sig,code,kTrueScal);
00469
00470
00471 if((!isSigGen(sig,x))&&(!isSigTable(sig,id,x,y))) setProperty(sig,fCompileScalKey[loop_unroll],tree(code));
00472 else {
00473 setProperty(sig,fCompileScalKey[0],tree(code));
00474 setProperty(sig,fCompileScalKey[1],tree(code));
00475 setProperty(sig,fCompileScalKey[2],tree(code));
00476 setProperty(sig,fCompileScalKey[3],tree(code));
00477 }
00478
00479
00480 } else {
00481
00482 code = generateScal(env,sig);
00483
00484 if(shcount(fSharingKeyTrueScal,sig)>1) code = generateCacheCode(env,sig,code,kTrueScal);
00485
00486 setProperty(sig,fCompileScalKey[0],tree(code));
00487 setProperty(sig,fCompileScalKey[1],tree(code));
00488 setProperty(sig,fCompileScalKey[2],tree(code));
00489 setProperty(sig,fCompileScalKey[3],tree(code));
00490
00491 }
00492 }
00493
00494
00495 return code;
00496 }
00497
00498 }
00499
00500
00501
00502
00503
00504
00505
00506
00507 string VectorCompiler::generateVec(Tree env,Tree sig)
00508 {
00509 int i;
00510 float r;
00511 Tree c,x,y,ff,largs,label,le,type,name,file;
00512
00513 if(isSigInt(sig,&i)) return generateCacheCode(env,sig,T(i),kVect);
00514 else if(isSigReal(sig,&r)) return generateCacheCode(env,sig,T(r),kVect);
00515 else if(isSigInput(sig,&i)) return generateInput(env,sig,T(i),kVect);
00516 else if(isSigFConst(sig,type,name,file) ) { addIncludeFile(tree2str(file)); return generateCacheCode(env,sig,tree2str(name),kVect); }
00517 else if(isSigBinOp(sig,&i,x,y)) return generateBinOp(env,sig,i,x,y,kVect);
00518 else if(isSigDelay1(sig,x)) return generateDelay1(env,sig,x,kVect);
00519 else if(isSigSelect2(sig,c,x,y)) return generateSelect2(env,sig,c,x,y,kVect);
00520 else if(isSigIntCast(sig,x)) return generateIntCast(env,sig,x,kVect);
00521 else if(isSigFloatCast(sig,x)) return generateFloatCast(env,sig,x,kVect);
00522 else if(isProj(sig,&i,x)&&isRec(x,label,le)) {
00523
00524 string code;
00525 if(heuristiqueRec(env,sig,&code)) {
00526
00527 setProperty(sig,fCompileScalarVecKey[0],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC0($0)",code),kScal)));
00528 setProperty(sig,fCompileScalarVecKey[1],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC1($0)",code),kScal)));
00529 setProperty(sig,fCompileScalarVecKey[2],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC2($0)",code),kScal)));
00530 setProperty(sig,fCompileScalarVecKey[3],tree(generateCacheCode(env,sig,subst("VEC2SCALVEC3($0)",code),kScal)));
00531
00532 return code;
00533
00534 } else {
00535
00536 string ID;
00537
00538 loop_unroll = 0; ID = CS(env,x,kScal); rec_var_map[ID] = 0;
00539 string Scal0 = generateRecProj(env,sig,ID,i); setProperty(sig,fCompileScalarVecKey[0],tree(Scal0));
00540 loop_unroll = 1; ID = CS(env,x,kScal); rec_var_map[ID] = 1;
00541 string Scal1 = generateRecProj(env,sig,ID,i); setProperty(sig,fCompileScalarVecKey[1],tree(Scal1));
00542 loop_unroll = 2; ID = CS(env,x,kScal); rec_var_map[ID] = 2;
00543 string Scal2 = generateRecProj(env,sig,ID,i); setProperty(sig,fCompileScalarVecKey[2],tree(Scal2));
00544 loop_unroll = 3; ID = CS(env,x,kScal); rec_var_map[ID] = 3;
00545 string Scal3 = generateRecProj(env,sig,ID,i); setProperty(sig,fCompileScalarVecKey[3],tree(Scal3));
00546 loop_unroll = 0;
00547
00548 return subst("SCAL2VEC($0,$1,$2,$3)",Scal0,Scal1,Scal2,Scal3);
00549 }
00550
00551
00552 } else if(isSigFFun(sig,ff,largs)) {
00553
00554
00555 loop_unroll = 0; string Scal0 = CS(env,sig,kTrueScal);
00556 loop_unroll = 1; string Scal1 = CS(env,sig,kTrueScal);
00557 loop_unroll = 2; string Scal2 = CS(env,sig,kTrueScal);
00558 loop_unroll = 3; string Scal3 = CS(env,sig,kTrueScal);
00559 loop_unroll = 0;
00560
00561 return subst("SCAL2VEC($0,$1,$2,$3)",Scal0,Scal1,Scal2,Scal3);
00562
00563
00564 } else if(isSigRDTbl(sig,x,y)) {
00565
00566
00567 loop_unroll = 0; string Scal0 = generateCacheCode(env,sig,subst("load_scal(&$0)",CS(env,sig,kTrueScal)),kScal); setProperty(sig,fCompileScalarVecKey[0],tree(Scal0));
00568 loop_unroll = 1; string Scal1 = generateCacheCode(env,sig,subst("load_scal(&$0)",CS(env,sig,kTrueScal)),kScal); setProperty(sig,fCompileScalarVecKey[1],tree(Scal1));
00569 loop_unroll = 2; string Scal2 = generateCacheCode(env,sig,subst("load_scal(&$0)",CS(env,sig,kTrueScal)),kScal); setProperty(sig,fCompileScalarVecKey[2],tree(Scal2));
00570 loop_unroll = 3; string Scal3 = generateCacheCode(env,sig,subst("load_scal(&$0)",CS(env,sig,kTrueScal)),kScal); setProperty(sig,fCompileScalarVecKey[3],tree(Scal3));
00571 loop_unroll = 0;
00572
00573 return subst("SCAL2VEC($0,$1,$2,$3)",Scal0,Scal1,Scal2,Scal3);
00574
00575
00576 }
00577
00578
00579 return "Error generateVec";
00580 }
00581
00582
00583 string VectorCompiler::generateScalarVec(Tree env,Tree sig)
00584 {
00585 int i;
00586 Tree c,x,y,label,le,ff,largs;
00587
00588 if(isSigInput(sig,&i)) return generateInput(env,sig,T(i),kScal);
00589 else if(isSigBinOp(sig,&i,x,y)) return generateBinOp(env,sig,i,x,y,kScal);
00590 else if(isSigDelay1(sig,x)) return generateDelay1(env,sig,x,kScal);
00591 else if(isSigSelect2(sig,c,x,y)) return generateSelect2(env,sig,c,x,y,kScal);
00592 else if(isSigIntCast(sig,x)) return generateIntCast(env,sig,x,kScal);
00593 else if(isSigFloatCast(sig,x)) return generateFloatCast(env,sig,x,kScal);
00594 else if(isRef(sig,label)) return generateRecRef(env,sig,label);
00595 else if(isRec(sig,label,le)) return generateRecGroup(env,sig,label,le);
00596 else if(isProj(sig,&i,x)&&isRef(x,label)) {
00597
00598 string ID = CS(env,x,kScal);
00599 if(loop_unroll==0) rec_var_map[ID]=3;
00600 else rec_var_map[ID]=loop_unroll-1;
00601 return generateRecProj(env,sig,ID,i);
00602
00603
00604 } else if(isProj(sig,&i,x)&&isRec(x,label,le)) {
00605
00606 string ID = CS(env,x,kScal);
00607 rec_var_map[ID] = loop_unroll;
00608 return generateRecProj(env,sig,ID,i);
00609
00610
00611 } else if(isSigFFun(sig,ff,largs)) {
00612
00613 string Scal = generateCacheCode(env,sig,CS(env,sig,kTrueScal),kTrueScal);
00614 return subst("load_scal(&$0)", Scal);
00615
00616 } else if(isSigRDTbl(sig,x,y)) return subst("load_scal(&$0)",CS(env,sig,kTrueScal));
00617
00618
00619 return "Error generateScalarVec";
00620 }
00621
00622
00623 string VectorCompiler::generateScal(Tree env,Tree sig)
00624 {
00625 int i;
00626 float r;
00627 Tree ff,largs,id,label,c,x,y,z,type,name,file;
00628
00629 if(isSigInt(sig,&i)) return T(i);
00630 else if(isSigReal(sig,&r)) return T(r);
00631 else if(isSigFConst(sig,type,name,file) ) { addIncludeFile(tree2str(file)); return tree2str(name); }
00632 else if(isSigVSlider(sig,label,c,x,y,z)) return generateVSlider(env,sig,label,c,x,y,z);
00633 else if(isSigHSlider(sig,label,c,x,y,z)) return generateHSlider(env,sig,label,c,x,y,z);
00634 else if(isSigButton(sig,label)) return generateButton(env,sig,label);
00635 else if(isSigCheckbox(sig,label)) return generateCheckbox(env,sig,label);
00636 else if(isSigNumEntry(sig,label,c,x,y,z)) return generateNumEntry(env,sig,label,c,x,y,z);
00637 else if(isSigInput(sig,&i)) return generateInput(env,sig,T(i),kTrueScal);
00638 else if(isSigBinOp(sig,&i,x,y)) return generateBinOp(env,sig,i,x,y,kTrueScal);
00639 else if(isSigDelay1(sig,x)) return generateDelay1(env,sig,x,kTrueScal);
00640 else if(isSigSelect2(sig,c,x,y)) return generateSelect2(env,sig,c,x,y,kTrueScal);
00641 else if(isSigIntCast(sig,x)) return generateIntCast(env,sig,x,kTrueScal);
00642 else if(isSigFloatCast(sig,x)) return generateFloatCast(env,sig,x,kTrueScal);
00643 else if(isSigFFun(sig,ff,largs)) return generateFFun(env,sig,ff,largs);
00644 else if(isSigGen(sig,x)) return generateSigGen(env,sig,x);
00645 else if(isSigTable(sig,id,x,y)) return generateTable(env,sig,x,y);
00646 else if(isSigWRTbl(sig,id,x,y,z)) return generateWRTbl(env,sig,x,y,z);
00647 else if(isSigRDTbl(sig,x,y)) return generateRDTbl(env,sig,x,y);
00648
00649
00650 return "Error generateScal";
00651 }
00652
00653
00654
00655
00656
00657
00658 string VectorCompiler::generateCacheCode(Tree env, Tree sig, const string& exp, int context)
00659 {
00660 string ctype,vname;
00661 int i; float r;
00662 Tree x,y,z,label,le,id;
00663
00664 Type t = getSigType(sig);
00665
00666 if((!isSigGen(sig,x))&&(!isSigTable(sig,id,x,y))&&(!isSigWRTbl(sig,id,x,y,z))&&(!isSigDelay1(sig,x))) {
00667
00668 switch(t->variability())
00669 {
00670
00671 case kKonst :
00672
00673 vname = getFreshID("vec_data");
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709
00710 if((context==kVect)||(context==kScal)) {
00711
00712 if(t->nature() == kInt) fClass->addSlowCode(subst("const vec_int $0 = set_vec($1);", vname, exp));
00713 else fClass->addSlowCode(subst("const vec_float $0 = set_vec($1);", vname, exp));
00714
00715 } else {
00716
00717
00718
00719 if((!isSigInt(sig,&i))&&(!isSigReal(sig,&r))) {
00720
00721 vname = getFreshID("temp");
00722 if (t->nature() == kInt) {
00723 fClass->addDeclCode(subst("int \t$0;", vname));
00724 fClass->addInitCode(subst("$0 = $1;", vname, exp));
00725 } else {
00726 fClass->addDeclCode(subst("float \t$0;", vname));
00727 fClass->addInitCode(subst("$0 = $1;", vname, exp));
00728 }
00729
00730 } else vname = exp;
00731
00732 }
00733
00734 break;
00735
00736
00737 case kBlock :
00738
00739 if((context==kVect)||(context==kScal)) {
00740
00741 vname = getFreshID("vec_block");
00742 if (t->nature() == kInt) fClass->addSlowCode(subst("vec_int $0 = set_vec($1);", vname, exp));
00743 else fClass->addSlowCode(subst("vec_float $0 = set_vec($1);", vname, exp));
00744
00745 } else {
00746
00747 vname = getFreshID("block");
00748 if (t->nature() == kInt) fClass->addSlowCode(subst("int $0 = $1;", vname, exp));
00749 else fClass->addSlowCode(subst("float $0 = $1;", vname, exp));
00750
00751 }
00752
00753 break;
00754
00755
00756
00757
00758 case kSamp :
00759
00760 if(context==kVect) {
00761
00762 vname = getFreshID("vec_temp");
00763 if (t->nature() == kInt) fClass->addExecCode(subst("vec_int $0 = $1;", vname, exp));
00764 else fClass->addExecCode(subst("vec_float $0 = $1;", vname, exp));
00765
00766 } else if(context==kScal) {
00767
00768 if( isProj(sig,&i,x) || isRec(sig,label,le) || isRef(sig,label) ) {
00769
00770 vname = exp;
00771
00772 } else {
00773
00774 vname = getFreshID("vec_temp");
00775
00776 if (t->nature() == kInt) fClass->addExecCode(subst("vec_int $0 = $1;", vname, exp));
00777 else fClass->addExecCode(subst("vec_float $0 = $1;", vname, exp));
00778
00779 }
00780
00781 } else {
00782
00783 vname = getFreshID("temp");
00784
00785 if (t->nature() == kInt) fClass->addExecCode(subst("int $0 = $1;", vname, exp));
00786 else fClass->addExecCode(subst("float $0 = $1;", vname, exp));
00787
00788
00789 }
00790
00791 break;
00792
00793
00794
00795 default:
00796 fprintf(stderr,"Error in generateCacheCode: variability of signal undefined: %s\n",exp.c_str());
00797 return exp;
00798 }
00799
00800
00801 } else vname = exp;
00802
00803 return vname;
00804 }
00805
00806
00807
00808
00809
00810
00811 string VectorCompiler::generateInput (Tree env, Tree sig, const string& idx, int context)
00812 {
00813 string temp;
00814
00815 if(context==kVect) {
00816 if((shcount(fSharingKeyVec,sig)>1)||(shcount(fSharingKeyScal,sig)>=1)||(shcount(fSharingKeyTrueScal,sig)>=1)) temp = subst("load_a_vec(&input$0[i])",idx);
00817 else temp = subst("*(vec_float*)&input$0[i]",idx);
00818 } else if(context==kScal) temp = subst("load_scal(&input$0[i+$1])",idx,T(loop_unroll));
00819 else temp = subst("input$0[i+$1]",idx,T(loop_unroll));
00820
00821 return temp;
00822 }
00823
00824
00825
00826 string VectorCompiler::generateOutput(Tree env, Tree sig, const string& idx, Tree x, int context)
00827 {
00828 string dst,arg;
00829
00830 if(context==kVect) {
00831 dst = subst("vec_output$0", idx);
00832 arg = generateVec(env,x);
00833 } else {
00834 dst = subst("output$0[i+$1]", idx, T(loop_unroll));
00835 arg = generateScalarVec(env,x);
00836 }
00837
00838 if(context==kVect) fClass->addExecCode(subst("$0 = $1;", dst, arg));
00839 else fClass->addExecCode(subst("store_scal(&$0,$1);", dst, arg));
00840 return dst;
00841 }
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859 bool VectorCompiler::DynamicCasting(Tree env, int nature_sig, int nature_arg1, int nature_arg2, Tree arg1, Tree arg2, string* cast_arg1, string* cast_arg2)
00860 {
00861 int i;
00862
00863 if(nature_arg1==kBool) {
00864
00865 if(nature_arg2==kBool) {
00866
00867
00868 if(nature_sig==kBool) {
00869
00870
00871 *cast_arg1 = CS(env,arg1,kVect);
00872 *cast_arg2 = CS(env,arg2,kVect);
00873
00874 } else if(nature_sig==kInt) {
00875
00876
00877 *cast_arg1 = subst("bool2int($0)",CS(env,arg1,kVect));
00878 *cast_arg2 = subst("bool2int($0)",CS(env,arg2,kVect));
00879
00880 } else if(nature_sig==kReal) {
00881
00882
00883 *cast_arg1 = subst("bool2float($0)",CS(env,arg1,kVect));
00884 *cast_arg2 = subst("bool2float($0)",CS(env,arg2,kVect));
00885
00886 } else return false;
00887
00888
00889 } else if(nature_arg2==kInt) {
00890
00891
00892 *cast_arg1 = subst("bool2int($0)",CS(env,arg1,kVect));
00893 *cast_arg2 = CS(env,arg2,kVect);
00894
00895 } else if(nature_arg2==kReal) {
00896
00897
00898 *cast_arg1 = subst("bool2float($0)",CS(env,arg1,kVect));
00899 *cast_arg2 = CS(env,arg2,kVect);
00900
00901 } else return false;
00902
00903
00904
00905 } else if(nature_arg1==kInt) {
00906
00907 if(nature_arg2==kBool) {
00908
00909
00910 *cast_arg1 = CS(env,arg1,kVect);
00911 *cast_arg2 = subst("bool2int($0)",CS(env,arg2,kVect));
00912
00913 } else if(nature_arg2==kInt) {
00914
00915
00916 *cast_arg1 = CS(env,arg1,kVect);
00917 *cast_arg2 = CS(env,arg2,kVect);
00918
00919 } else if(nature_arg2==kReal) {
00920
00921
00922 if(isSigInt(arg1,&i)) {
00923 string vname = getFreshID("vec_data");
00924 fClass->addDeclCode(subst("vec_float \t$0;", vname));
00925 fClass->addInitCode(subst("$0 = set_vec($1);", vname, T(float(i))));
00926 *cast_arg1 = vname;
00927 } else *cast_arg1 = subst("int2float($0)",CS(env,arg1,kVect));
00928 *cast_arg2 = CS(env,arg2,kVect);
00929
00930 } else return false;
00931
00932
00933
00934 } else if(nature_arg1==kReal) {
00935
00936 if(nature_arg2==kBool) {
00937
00938
00939 *cast_arg1 = CS(env,arg1,kVect);
00940 *cast_arg2 = subst("bool2float($0)",CS(env,arg2,kVect));
00941
00942 } else if(nature_arg2==kInt) {
00943
00944
00945 *cast_arg1 = CS(env,arg1,kVect);
00946 if(isSigInt(arg2,&i)) {
00947 string vname = getFreshID("vec_data");
00948 fClass->addDeclCode(subst("vec_float \t$0;", vname));
00949 fClass->addInitCode(subst("$0 = set_vec($1);", vname, T(float(i))));
00950 *cast_arg2 = vname;
00951 } else *cast_arg2 = subst("int2float($0)",CS(env,arg2,kVect));
00952
00953 } else if(nature_arg2==kReal) {
00954
00955
00956 *cast_arg1 = CS(env,arg1,kVect);
00957 *cast_arg2 = CS(env,arg2,kVect);
00958
00959 } else return false;
00960
00961 } else return false;
00962
00963 return true;
00964 }
00965
00966
00967
00968 bool VectorCompiler::TrinaryOperationAccVec(Tree env,Tree arg1,Tree arg2,string* result)
00969 {
00970 int i; float r;
00971 Tree w,x,y,z;
00972 string tri_op,tri_arg1,tri_arg2,tri_arg3;
00973
00974 Type targ1 = getSigType(arg1);
00975 Type targ2 = getSigType(arg2);
00976
00977 if(isSigBinOp(arg1, &i, x, y)&&(i==2)&&(shcount(fSharingKeyVec,arg1)==1)&&(shcount(fSharingKeyScal,arg1)==0)&&(shcount(fSharingKeyTrueScal,arg1)==0)&&(targ1->variability()==kSamp)) {
00978
00979
00980
00981
00982
00983 if(isSigBinOp(x,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
00984
00985
00986
00987 tri_op = string("divadd_vec");
00988
00989 tri_arg1 = CS(env,y,kVect);
00990 tri_arg2 = CS(env,z,kVect);
00991 tri_arg3 = CS(env,arg2,kVect);
00992
00993
00994
00995
00996
00997
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 } else if(isSigBinOp(y,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01033
01034 tri_op = string("divadd_vec");
01035
01036 tri_arg1 = CS(env,x,kVect);
01037 tri_arg2 = CS(env,z,kVect);
01038 tri_arg3 = CS(env,arg2,kVect);
01039
01040
01041 } else {
01042
01043 tri_op = string("madd_vec");
01044
01045 tri_arg1 = CS(env,x,kVect);
01046 tri_arg2 = CS(env,y,kVect);
01047 tri_arg3 = CS(env,arg2,kVect);
01048
01049 }
01050
01051 } else if(isSigBinOp(arg2, &i, x, y)&&(i==2)&&(shcount(fSharingKeyVec,arg2)==1)&&(shcount(fSharingKeyScal,arg2)==0)&&(shcount(fSharingKeyTrueScal,arg2)==0)&&(targ2->variability()==kSamp)) {
01052
01053 if(isSigBinOp(x,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01054
01055 tri_op = string("divadd_vec");
01056
01057 tri_arg1 = CS(env,y,kVect);
01058 tri_arg2 = CS(env,z,kVect);
01059 tri_arg3 = CS(env,arg1,kVect);
01060
01061 } else if(isSigBinOp(y,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01062
01063 tri_op = string("divadd_vec");
01064
01065 tri_arg1 = CS(env,x,kVect);
01066 tri_arg2 = CS(env,z,kVect);
01067 tri_arg3 = CS(env,arg1,kVect);
01068
01069 } else {
01070
01071 tri_op = string("madd_vec");
01072
01073 tri_arg1 = CS(env,x,kVect);
01074 tri_arg2 = CS(env,y,kVect);
01075 tri_arg3 = CS(env,arg1,kVect);
01076 }
01077
01078 } else return false;
01079
01080
01081 *result = subst("$0($1,$2,$3)",tri_op,tri_arg1,tri_arg2,tri_arg3);
01082
01083 return true;
01084 }
01085
01086 bool VectorCompiler::TrinaryOperationAccScal(Tree env,Tree arg1,Tree arg2,string* result)
01087 {
01088 int i; float r;
01089 Tree w,x,y,z;
01090 string tri_op,tri_arg1,tri_arg2,tri_arg3;
01091
01092 Type targ1 = getSigType(arg1);
01093 Type targ2 = getSigType(arg2);
01094
01095
01096
01097 if(isSigBinOp(arg1, &i, x, y)&&(i==2)&&(shcount(fSharingKeyVec,arg1)==0)&&(shcount(fSharingKeyScal,arg1)==1)&&(shcount(fSharingKeyTrueScal,arg1)==1)&&(targ1->variability()==kSamp)) {
01098
01099
01100
01101
01102
01103 if(targ1->vectorability()==kScal) {
01104
01105
01106 if(isSigBinOp(x,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01107
01108
01109
01110 tri_op = string("divadd_scal");
01111
01112 tri_arg1 = CS(env,y,kScal);
01113 tri_arg2 = CS(env,z,kScal);
01114 tri_arg3 = CS(env,arg2,kScal);
01115
01116
01117 } else if(isSigBinOp(y,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01118
01119 tri_op = string("divadd_scal");
01120
01121 tri_arg1 = CS(env,x,kScal);
01122 tri_arg2 = CS(env,z,kScal);
01123 tri_arg3 = CS(env,arg2,kScal);
01124
01125
01126 } else {
01127
01128 tri_op = string("madd_scal");
01129
01130 tri_arg1 = CS(env,x,kScal);
01131 tri_arg2 = CS(env,y,kScal);
01132 tri_arg3 = CS(env,arg2,kScal);
01133
01134 }
01135
01136 } else return false;
01137
01138
01139 } else if(isSigBinOp(arg2, &i, x, y)&&(i==2)&&(shcount(fSharingKeyVec,arg2)==0)&&(shcount(fSharingKeyScal,arg2)==1)&&(shcount(fSharingKeyTrueScal,arg2)==1)&&(targ2->variability()==kSamp)) {
01140
01141 if(targ2->vectorability()==kScal) {
01142
01143 if(isSigBinOp(x,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01144
01145 tri_op = string("divadd_scal");
01146
01147 tri_arg1 = CS(env,y,kScal);
01148 tri_arg2 = CS(env,z,kScal);
01149 tri_arg3 = CS(env,arg1,kScal);
01150
01151 } else if(isSigBinOp(y,&i,w,z)&&(i==3)&&((isSigReal(w,&r)&&(r==1.0))||(isSigInt(w,&i)&&(i==1)))) {
01152
01153 tri_op = string("divadd_scal");
01154
01155 tri_arg1 = CS(env,x,kScal);
01156 tri_arg2 = CS(env,z,kScal);
01157 tri_arg3 = CS(env,arg1,kScal);
01158
01159 } else {
01160
01161 tri_op = string("madd_scal");
01162
01163 tri_arg1 = CS(env,x,kScal);
01164 tri_arg2 = CS(env,y,kScal);
01165 tri_arg3 = CS(env,arg1,kScal);
01166 }
01167
01168 } else return false;
01169
01170 } else return false;
01171
01172
01173 *result = subst("$0($1,$2,$3)",tri_op,tri_arg1,tri_arg2,tri_arg3);
01174
01175 return true;
01176 }
01177
01178
01179
01180
01181
01182 string VectorCompiler::generateBinOp (Tree env,Tree sig, int opcode, Tree arg1, Tree arg2, int context)
01183 {
01184 Type t = getSigType(sig);
01185 Type targ1 = getSigType(arg1);
01186 Type targ2 = getSigType(arg2);
01187
01188 if(t->variability()<kSamp) {
01189
01190 return subst("($0 $1 $2)", CS(env,arg1,kTrueScal), gBinOpTable[opcode]->fName, CS(env,arg2,kTrueScal));
01191
01192 } else if(context==kVect) {
01193
01194 string tri_op;
01195
01196 if((opcode==0)&&TrinaryOperationAccVec(env,arg1,arg2,&tri_op)) {
01197
01198 return tri_op;
01199
01200
01201 } else {
01202
01203
01204
01205
01206
01207
01208 return subst("$0($1,$2)", gBinOpTable[opcode]->fNameVec, CS(env,arg1,kVect), CS(env,arg2,kVect));
01209
01210 }
01211
01212
01213
01214
01215 } else if(context==kScal) {
01216
01217 string tri_op;
01218
01219 if((opcode==0)&&TrinaryOperationAccScal(env,arg1,arg2,&tri_op)) {
01220
01221 return tri_op;
01222
01223
01224 } else {
01225
01226 return subst("$0($1,$2)", gBinOpTable[opcode]->fNameScal, CS(env,arg1,kScal), CS(env,arg2,kScal));
01227
01228 }
01229
01230 } else
01231
01232 return "Error in generateBinOp";
01233 }
01234
01235
01236
01237
01238
01239
01240
01241 string VectorCompiler::generateDelay1 (Tree env, Tree sig, Tree arg, int context)
01242 {
01243 string vname,tname,ctype,zero;
01244
01245 Type t = getSigType(sig);
01246 Type targ = getSigType(arg);
01247
01248
01249
01250
01251 if(t->nature()==kInt) {
01252 if(loop_unroll==0) {
01253 vname = getFreshID("vec_imem");
01254 tname = getFreshID("vec_ipre");
01255 ctype = "vec_int";
01256 zero = "set_vec(0)";
01257 } else {
01258 Tree prop; getProperty(sig,fCompileScalarVecKey[0],prop);
01259 tname = tree2str(prop);
01260 vname = subst("vec_imem$0", tname.substr(8,tname.size()+1));
01261 }
01262 } else {
01263 if(loop_unroll==0) {
01264 vname = getFreshID("vec_fmem");
01265 tname = getFreshID("vec_fpre");
01266 ctype = "vec_float";
01267 zero = "set_vec(0.0f)";
01268 } else {
01269 Tree prop; getProperty(sig,fCompileScalarVecKey[0],prop);
01270 tname = tree2str(prop);
01271 vname = subst("vec_fmem$0", tname.substr(8,tname.size()+1));
01272 }
01273 }
01274
01275
01276
01277
01278 if(context==kVect) {
01279
01280 int sharingVec = shcount(fSharingKeyVec, sig);
01281 int sharingScal = shcount(fSharingKeyScal, sig) ;
01282 int sharingTrueScal = shcount(fSharingKeyTrueScal, sig);
01283 string arg_vec = CS(env,arg,kVect);
01284
01285 if(loop_unroll==0) {
01286
01287 fClass->addDeclCode(subst("$0 \t$1;", ctype, vname));
01288 fClass->addInitCode(subst("$0 = $1;", vname, zero));
01289
01290 Tree x; int i;
01291 if((sharingVec>1)||(sharingScal>=1)||(sharingTrueScal>=1)||isSigDelay1(sig,x)||isProj(sig,&i,x)) {
01292 fClass->addExecCode(subst("$0 $1 = mem1_vec($2,$3);", ctype, tname, arg_vec, vname));
01293 fClass->addExecCode(subst("$0 = $1;", vname, arg_vec));
01294 } else {
01295 string name_temp,type_temp;
01296
01297 if (t->nature() == kInt) {
01298 name_temp = getFreshID("vec_idata");
01299 type_temp = "vec_int";
01300 } else {
01301 name_temp = getFreshID("vec_fdata");
01302 type_temp = "vec_float";
01303 }
01304
01305 fClass->addExecCode(subst("$0 $1 = $2;",type_temp,name_temp,arg_vec));
01306 fClass->addExecCode(subst("$0 $1 = mem1_vec($2,$3);", ctype, tname, name_temp, vname));
01307 fClass->addExecCode(subst("$0 = $1;", vname, name_temp));
01308 }
01309
01310 } else {
01311
01312 fprintf(stderr,"ERROR GENERATE DELAY: VECTOR CONTEXT LOOP_UNROLL!=0\n");
01313
01314 }
01315
01316 } else {
01317
01318 string arg_scal = CS(env,arg,kScal);
01319
01320 if(loop_unroll==0) {
01321 fClass->addDeclCode(subst("$0 \t$1;", ctype, vname));
01322 fClass->addInitCode(subst("$0 = $1;", vname, zero));
01323
01324
01325 fClass->addExecCode(subst("$0 $1 = $2;", ctype, tname, vname));
01326
01327
01328 } else fClass->addExecCode(subst("$0 = $1;", tname, vname));
01329
01330
01331 fClass->addExecCode(subst("$0 = $1;", vname, arg_scal));
01332
01333 }
01334
01335 return tname;
01336 }
01337
01338
01339
01340
01341
01342
01343 string VectorCompiler::generateSelect2(Tree env, Tree sig, Tree selector, Tree s1, Tree s2, int context)
01344 {
01345 string ctype,temp0,temp1,selidx;
01346
01347 Type t = getSigType(sig);
01348 Type ts1 = getSigType(s1);
01349 Type ts2 = getSigType(s2);
01350 Type tsel = getSigType(selector);
01351
01352
01353 if(t->nature() == kInt) ctype = "int";
01354 else ctype = "float";
01355
01356 if(context==kVect) {
01357 if(loop_unroll==0) {
01358
01359 temp0 = getFreshID("tmpSelvec0");
01360 temp1 = getFreshID("tmpSelvec1");
01361 selidx = getFreshID("idxSelvec");
01362
01363 if(t->nature()==ts1->nature()) fClass->addExecCode(subst("vec_$0 $1 = $2;",ctype,temp0,CS(env,s1,kVect)));
01364 else fClass->addExecCode(subst("vec_$0 $1 = int2float($2);",ctype,temp0,CS(env,s1,kVect)));
01365
01366 if(t->nature()==ts2->nature()) fClass->addExecCode(subst("vec_$0 $1 = $2;",ctype,temp1,CS(env,s2,kVect)));
01367 else fClass->addExecCode(subst("vec_$0 $1 = int2float($2);",ctype,temp1,CS(env,s2,kVect)));
01368
01369 if((tsel->boolean()==kBool)&&(tsel->variability()==kSamp )) {
01370
01371 if((t->nature()==kInt)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_int $0 = $1;",selidx,CS(env,selector,kVect)));
01372 else if((t->nature()==kReal)&&(tsel->nature()==kReal)) fClass->addExecCode(subst("vec_float $0 = $1;",selidx,CS(env,selector,kVect)));
01373 else if((t->nature()==kReal)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_float $0 = boolint2boolfloat($1);",selidx,CS(env,selector,kVect)));
01374 else fClass->addExecCode(subst("vec_int $0 = boolfloat2boolint($1);",selidx,CS(env,selector,kVect)));
01375
01376 } else {
01377
01378 if((t->nature()==kInt)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_int $0 = gt_vec($1, set_vec(0) );",selidx,CS(env,selector,kVect)));
01379 else if((t->nature()==kReal)&&(tsel->nature()==kReal)) fClass->addExecCode(subst("vec_float $0 = gt_vec($1, set_vec(0) );",selidx,CS(env,selector,kVect)));
01380 else if((t->nature()==kReal)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_float $0 = gt_vec(int2float($1), set_vec(0.0f) );",selidx,CS(env,selector,kVect)));
01381 else fClass->addExecCode(subst("vec_int $0 = gt_vec(float2int($1), set_vec(0) );",selidx,CS(env,selector,kVect)));
01382 }
01383
01384 return subst("select_vec($0,$1,$2)",selidx,temp0,temp1);
01385
01386
01387 } else return "Error Select2: vectorability kVect but loop_unrool!=0";
01388
01389 } else if(context==kScal) {
01390
01391 temp0 = subst("tmpSel0$0",T(loop_unroll)); temp0 = getFreshID(temp0.c_str());
01392 temp1 = subst("tmpSel1$0",T(loop_unroll)); temp1 = getFreshID(temp1.c_str());
01393 selidx = subst("idxSel$0",T(loop_unroll)); selidx = getFreshID(selidx.c_str());
01394
01395
01396
01397 if(t->nature()==ts1->nature()) fClass->addExecCode(subst("vec_$0 $1 = $2;",ctype,temp0,CS(env,s1,kScal)));
01398 else fClass->addExecCode(subst("vec_$0 $1 = int2float($2);",ctype,temp0,CS(env,s1,kScal)));
01399
01400
01401
01402 if(t->nature()==ts2->nature()) fClass->addExecCode(subst("vec_$0 $1 = $2;",ctype,temp1,CS(env,s2,kScal)));
01403 else fClass->addExecCode(subst("vec_$0 $1 = int2float($2);",ctype,temp1,CS(env,s2,kScal)));
01404
01405 if((tsel->boolean()==kBool)&&(tsel->variability()==kSamp)) {
01406
01407 if((t->nature()==kInt)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_int $0 = $1;",selidx,CS(env,selector,kScal)));
01408 else if((t->nature()==kReal)&&(tsel->nature()==kReal)) fClass->addExecCode(subst("vec_float $0 = $1;",selidx,CS(env,selector,kScal)));
01409 else if((t->nature()==kReal)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_float $0 = boolint2boolfloat($1);",selidx,CS(env,selector,kScal)));
01410 else fClass->addExecCode(subst("vec_int $0 = boolfloat2boolint($1);",selidx,CS(env,selector,kScal)));
01411
01412 } else {
01413
01414 if((t->nature()==kInt)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_int $0 = gt_scal($1, set_vec(0));",selidx,CS(env,selector,kScal)));
01415 else if((t->nature()==kReal)&&(tsel->nature()==kReal)) fClass->addExecCode(subst("vec_float $0 = gt_scal($1,set_vec(0.0f));",selidx,CS(env,selector,kScal)));
01416 else if((t->nature()==kReal)&&(tsel->nature()==kInt)) fClass->addExecCode(subst("vec_float $0 = gt_scal(int2float($1),set_vec(0.0f));",selidx,CS(env,selector,kScal)));
01417 else fClass->addExecCode(subst("vec_int $0 = gt_scal(float2int($1), set_vec(0));",selidx,CS(env,selector,kScal)));
01418 }
01419
01420
01421 return subst("select_scal($0,$1,$2)",selidx,temp0,temp1);
01422
01423
01424 } else {
01425
01426 return "Error: Select2 for true Scal not implemented yet";
01427 }
01428
01429 return "Error generateSelect2";
01430
01431
01432 }
01433
01434
01435
01436
01437
01438 string VectorCompiler::generateFFun (Tree env, Tree sig, Tree ff, Tree largs)
01439 {
01440 addIncludeFile(ffincfile(ff));
01441 addLibrary(fflibfile(ff));
01442
01443 switch (ffarity(ff))
01444 {
01445 case 0 : return subst("$0()", ffname(ff));
01446 case 1 : return subst("$0($1)", ffname(ff), CS(env,nth(largs,0),kTrueScal));
01447 case 2 : return subst("$0($1, $2)", ffname(ff), CS(env,nth(largs,0),kTrueScal), CS(env,nth(largs,1),kTrueScal));
01448 case 3 : return subst("$0($1, $2, $3)", ffname(ff), CS(env,nth(largs,0),kTrueScal), CS(env,nth(largs,1),kTrueScal), CS(env,nth(largs,2),kTrueScal));
01449 default :
01450 exit(1);
01451 }
01452 return "Arity Error in FFun";
01453 }
01454
01455
01456
01457
01458
01459
01460
01461 string VectorCompiler::generateIntCast (Tree env, Tree sig, Tree x, int context)
01462 {
01463 Type t = getSigType(sig);
01464
01465 if(t->variability()<kSamp) return subst("int($0)",CS(env,x,kTrueScal));
01466 else if(context==kVect) return subst("float2int($0)", CS(env,x,kVect));
01467 else return subst("float2int($0)", CS(env,x,kScal));
01468 }
01469
01470 string VectorCompiler::generateFloatCast (Tree env, Tree sig, Tree x, int context)
01471 {
01472 Type t = getSigType(sig);
01473
01474 if(t->variability()<kSamp) return subst("float($0)",CS(env,x,kTrueScal));
01475 else if(context==kVect) return subst("int2float($0)", CS(env,x,kVect));
01476 else return subst("int2float($0)", CS(env,x,kScal));
01477 }
01478
01479
01480
01481
01482
01483
01484 string VectorCompiler::generateButton (Tree env, Tree sig, Tree path)
01485 {
01486 static string varname;
01487
01488 if(!loop_unroll) {
01489
01490 Tree prop;
01491 if(getProperty(sig,fCompileScalKey[0],prop)) varname = tree2str(prop);
01492 else {
01493 varname = getFreshID("fbutton");
01494 fClass->addDeclCode(subst("float \t$0;", varname));
01495 fClass->addInitCode(subst("$0 = 0.0f;", varname));
01496 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
01497 }
01498
01499 return varname;
01500 }
01501
01502 return "Error in generateButton";
01503 }
01504
01505 string VectorCompiler::generateCheckbox (Tree env, Tree sig, Tree path)
01506 {
01507 static string varname;
01508
01509 if(!loop_unroll) {
01510
01511 Tree prop;
01512 if(getProperty(sig,fCompileScalKey[0],prop)) varname = tree2str(prop);
01513 else {
01514 varname = getFreshID("fcheckbox");
01515 fClass->addDeclCode(subst("float \t$0;", varname));
01516 fClass->addInitCode(subst("$0 = 0.0f;", varname));
01517 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
01518 }
01519
01520 return varname;
01521 }
01522
01523 return "Error in generateCheckbox";
01524 }
01525
01526 string VectorCompiler::generateVSlider (Tree env, Tree sig, Tree path, Tree cur, Tree min, Tree max, Tree step)
01527 {
01528 static string varname;
01529
01530 if(loop_unroll==0) {
01531
01532 Tree prop;
01533 if(getProperty(sig,fCompileScalKey[0],prop)) varname = tree2str(prop);
01534 else {
01535 varname = getFreshID("fslider");
01536 fClass->addDeclCode(subst("float \t$0;", varname));
01537 fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur))));
01538 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
01539 }
01540
01541 return varname;
01542 }
01543
01544 return "Error in generateVSlider";
01545 }
01546
01547 string VectorCompiler::generateHSlider (Tree env, Tree sig, Tree path, Tree cur, Tree min, Tree max, Tree step)
01548 {
01549 static string varname;
01550
01551 if(loop_unroll==0) {
01552
01553 Tree prop;
01554 if(getProperty(sig,fCompileScalKey[0],prop)) varname = tree2str(prop);
01555 else {
01556 varname = getFreshID("fslider");
01557 fClass->addDeclCode(subst("float \t$0;", varname));
01558 fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur))));
01559 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
01560 }
01561
01562 return varname;
01563 }
01564
01565 return "Error in generateHSlider";
01566 }
01567
01568
01569 string VectorCompiler::generateNumEntry (Tree env, Tree sig, Tree path, Tree cur, Tree min, Tree max, Tree step)
01570 {
01571 static string varname;
01572
01573 if(loop_unroll==0) {
01574
01575 Tree prop;
01576 if(getProperty(sig,fCompileScalKey[0],prop)) varname = tree2str(prop);
01577 else {
01578 varname = getFreshID("fentry");
01579 fClass->addDeclCode(subst("float \t$0;", varname));
01580 fClass->addInitCode(subst("$0 = $1;", varname, T(tree2float(cur))));
01581 addUIWidget(reverse(tl(path)), uiWidget(hd(path), tree(varname), sig));
01582 }
01583
01584 return varname;
01585 }
01586
01587 return "Error in generateNumEntry";
01588 }
01589
01590
01591
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601 string VectorCompiler::generateSigGen(Tree env, Tree sig, Tree content)
01602 {
01603 string klassname = getFreshID("SIG");
01604 string signame = getFreshID("sig");
01605
01606 if(!loop_unroll) {
01607 fClass->addSubKlass(signal2klass(klassname, content));
01608 fClass->addInitCode(subst("$0 $1;", klassname, signame));
01609 }
01610
01611 return signame;
01612 }
01613
01614
01615
01616
01617
01618 string VectorCompiler::generateTable (Tree env, Tree sig, Tree tsize, Tree content)
01619 {
01620 string generator(CS(env,content,kTrueScal));
01621 string ctype;
01622 int size;
01623 static string vname;
01624
01625 if (!isSigInt(tsize, &size)) {
01626
01627 exit(1);
01628 }
01629
01630
01631
01632 Type t = getSigType(sig);
01633
01634 if (t->nature() == kInt) { vname = getFreshID("itbl"); ctype = "int"; }
01635 else { vname = getFreshID("ftbl"); ctype = "float"; }
01636
01637
01638
01639 fClass->addDeclCode(subst("$0 \t$1[$2] __attribute__ ((aligned(16)));", ctype, vname, T(size)));
01640
01641
01642 fClass->addInitCode(subst("$0.init(samplingFreq);", generator));
01643
01644
01645 fClass->addInitCode(subst("$0.fill($1,$2);", generator, T(size), vname));
01646
01647
01648
01649
01650 return vname;
01651 }
01652
01653
01654
01655
01656
01657 string VectorCompiler::generateWRTbl (Tree env, Tree sig, Tree tbl, Tree idx, Tree data )
01658 {
01659 string tblName = CS(env,tbl,kTrueScal);
01660
01661 fClass->addExecCode(subst("store_scal(&$0[$1],$2);", tblName, CS(env,idx,kTrueScal), CS(env,data,kScal)));
01662 return tblName;
01663 }
01664
01665
01666
01667
01668
01669 string VectorCompiler::generateRDTbl (Tree env, Tree sig, Tree tbl, Tree idx )
01670 {
01671 return subst("$1[$0]", CS(env,idx,kTrueScal), CS(env,tbl,kTrueScal));
01672 }
01673
01674
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687
01688 bool VectorCompiler::heuristiqueRec(Tree env, Tree sig, string* result)
01689 {
01690 int i,j,n,m;
01691 Tree prop,ProjRec,ProjRef,label,le,LeftAnd,RightAnd,LeftPlus,RightPlus;
01692
01693
01694
01695
01697
01698 if(getProperty(sig,fCompileVecKey,prop)) { *result = tree2str(prop); return true; }
01699 else if ( !isProj(sig, &i, ProjRec) ) { return false; }
01700 else if ( !isRec(ProjRec, label, le) ) { return false; }
01701 else if ( len(le)!=1 ) { return false; }
01702 else if ( !(isSigBinOp(nth(le,0), &i, LeftAnd, RightAnd)&&(shcount(fSharingKeyScal, nth(le,0))==1)&&(shcount(fSharingKeyVec, nth(le,0))==0)&&(shcount(fSharingKeyTrueScal, nth(le,0))==1) ) ) { return false; }
01703 else if ( i!=13 ) { return false; }
01704 else if ( isSigInt(LeftAnd,&n) ) {
01705
01706 if( isSigBinOp(RightAnd,&i,LeftPlus,RightPlus) && (i==0) && (shcount(fSharingKeyVec,RightAnd)==0) &&(shcount(fSharingKeyScal,RightAnd)==1)&&(shcount(fSharingKeyTrueScal,RightAnd)==1) ) {
01707
01708 if ( isSigInt(LeftPlus,&m) ) {
01709
01710 if( isProj(RightPlus,&j,ProjRef) && isRef(ProjRef,label) && (j==0) ) {
01711
01712 int sh = shcount(fSharingKeyVec,LeftPlus);
01713 if(sh>1) setProperty(LeftPlus,fSharingKeyVec,tree(sh-1));
01714
01715 } else { return false; }
01716
01717 } else if ( isSigInt(RightPlus,&m) ) {
01718
01719 if( isProj(LeftPlus,&j,ProjRef) && isRef(ProjRef,label) && (j==0) ) {
01720
01721 int sh = shcount(fSharingKeyVec,RightPlus);
01722 if(sh>1) setProperty(RightPlus,fSharingKeyVec,tree(sh-1));
01723
01724 } else { return false; }
01725
01726 } else { return false; }
01727
01728 } else { return false; }
01729
01730 } else if ( isSigInt(RightAnd,&n) ) {
01731
01732 if( isSigBinOp(LeftAnd,&i,LeftPlus,RightPlus) && (i==0) && (shcount(fSharingKeyVec,LeftAnd)==0) &&(shcount(fSharingKeyScal,LeftAnd)==1)&&(shcount(fSharingKeyTrueScal,LeftAnd)==1)) {
01733
01734 if ( isSigInt(LeftPlus,&m) ) {
01735
01736 if( isProj(RightPlus,&j,ProjRef) && isRef(ProjRef,label) && (j==0) ) {
01737
01738 int sh = shcount(fSharingKeyVec,LeftPlus);
01739 if(sh>1) setProperty(LeftPlus,fSharingKeyVec,tree(sh-1));
01740
01741 } else { return false; }
01742
01743 } else if ( isSigInt(RightPlus,&m) ) {
01744
01745 if( isProj(LeftPlus,&j,ProjRef) && isRef(ProjRef,label) && (j==0) ) {
01746
01747 int sh = shcount(fSharingKeyVec,RightPlus);
01748 if(sh>1) setProperty(RightPlus,fSharingKeyVec,tree(sh-1));
01749
01750 } else { return false; }
01751
01752 } else { return false; }
01753
01754 } else { return false; }
01755
01756 } else { return false; }
01757
01758
01759
01760
01761
01762 string ID = getFreshID("vec_R");
01763 fClass->addDeclCode(subst("vec_int \t$0;",ID));
01764 int init3 = 0;
01765 int init2 = n;
01766 int init1 = n-m;
01767 int init0 = n-2*m;
01768 fClass->addInitCode(subst("$0 = set_vec($1,$2,$3,$4);" , ID,T(init0),T(init1),T(init2),T(init3)));
01769
01770
01771 string Inc = getFreshID("vec_data");
01772 fClass->addDeclCode(subst("vec_int \t$0;",Inc));
01773 int IntInc = 4*m;
01774 fClass->addInitCode(subst("$0 = set_vec($1);", Inc, T(IntInc)));
01775
01776
01777 string And;
01778 if(n==IntInc) {
01779 And = Inc;
01780 if(isSigInt(LeftAnd,&n)) {
01781 setProperty(LeftAnd,fCompileVecKey,tree(And));
01782 setProperty(LeftAnd,fCompileScalarVecKey[0],tree(And));
01783 setProperty(LeftAnd,fCompileScalarVecKey[1],tree(And));
01784 setProperty(LeftAnd,fCompileScalarVecKey[2],tree(And));
01785 setProperty(LeftAnd,fCompileScalarVecKey[3],tree(And));
01786 } else {
01787 setProperty(RightAnd,fCompileVecKey,tree(And));
01788 setProperty(RightAnd,fCompileScalarVecKey[0],tree(And));
01789 setProperty(RightAnd,fCompileScalarVecKey[1],tree(And));
01790 setProperty(RightAnd,fCompileScalarVecKey[2],tree(And));
01791 setProperty(RightAnd,fCompileScalarVecKey[3],tree(And));
01792 }
01793 } else {
01794 if(isSigInt(LeftAnd,&n)&&getProperty(LeftAnd,fCompileVecKey,prop)) And = tree2str(prop);
01795 else if(getProperty(RightAnd,fCompileVecKey,prop)) And = tree2str(prop);
01796 else {
01797 And = getFreshID("vec_data");
01798 fClass->addDeclCode(subst("vec_int \t$0;",And));
01799 fClass->addInitCode(subst("$0 = set_vec($1);", And, T(n)));
01800 if(isSigInt(LeftAnd,&n)) {
01801 setProperty(LeftAnd,fCompileVecKey,tree(And));
01802 setProperty(LeftAnd,fCompileScalarVecKey[0],tree(And));
01803 setProperty(LeftAnd,fCompileScalarVecKey[1],tree(And));
01804 setProperty(LeftAnd,fCompileScalarVecKey[2],tree(And));
01805 setProperty(LeftAnd,fCompileScalarVecKey[3],tree(And));
01806 } else {
01807 setProperty(RightAnd,fCompileVecKey,tree(And));
01808 setProperty(RightAnd,fCompileScalarVecKey[0],tree(And));
01809 setProperty(RightAnd,fCompileScalarVecKey[1],tree(And));
01810 setProperty(RightAnd,fCompileScalarVecKey[2],tree(And));
01811 setProperty(RightAnd,fCompileScalarVecKey[3],tree(And));
01812 }
01813 }
01814 }
01815
01816 fClass->addExecCode(subst("$0 = and_vec(add_vec($0,$1),$2);", ID, Inc, And));
01817
01818 *result = subst("$0",ID);
01819
01820 return true;
01821 }
01822
01823
01824
01825
01826
01827
01828
01829 static string makeRecVarPermName_vect(const string& groupID, int i)
01830 {
01831 return subst("$0_$1", groupID, T(i));
01832 }
01833
01834
01835 static string makeRecVarTempName_vect(const string& groupID, int i)
01836 {
01837 return subst("$0temp$1", groupID, T(i));
01838 }
01839
01840
01841
01842
01843
01844
01845
01846
01847
01848 Tree RECNAMEPROP = tree(symbol("sigRecNameProp"));
01849
01850
01851
01852
01853
01854
01855
01856 string VectorCompiler::generateRecGroup (Tree env, Tree sig, Tree label, Tree le)
01857 {
01858 Type t = getSigType(sig);
01859
01860 Tree tEnv2 = addEnv(label,t,env);
01861
01862 int n = len(le);
01863
01864
01865 string ID; Tree tID;
01866 if(getProperty(sig,fIDKey,tID)) ID = tree2str(tID);
01867 else {
01868 ID = getFreshID("vec_R");
01869 setProperty(sig,fIDKey,tree(ID));
01870 }
01871
01872 setProperty(label, RECNAMEPROP, tree(ID.c_str()));
01873
01874
01875 if(n==1) {
01876
01877 Tree e = nth(le, 0);
01878 Type te = getSigType(e);
01879
01880
01881
01882
01883 string vperm = subst("$0_$1", makeRecVarPermName_vect(ID, 0),T(loop_unroll));
01884
01885
01886 if(loop_unroll==3) {
01887
01888 if(te->nature()==kInt) {
01889 fClass->addDeclCode(subst("vec_int \t$0;",vperm));
01890 fClass->addInitCode(subst("$0 = set_vec(0);", vperm));
01891 } else {
01892 fClass->addDeclCode(subst("vec_float \t$0;", vperm));
01893 fClass->addInitCode(subst("$0 = set_vec(0.0f);", vperm));
01894 }
01895
01896
01897 fClass->addExecCode(subst("\t$0 = $1;", vperm, CS(tEnv2,e,kScal)));
01898
01899 } else {
01900
01901
01902
01903 if(te->nature()==kInt) fClass->addExecCode(subst("vec_int $0 = $1;", vperm, CS(tEnv2,e,kScal)));
01904 else fClass->addExecCode(subst("vec_float $0 = $1;", vperm, CS(tEnv2,e,kScal)));
01905
01906 }
01907
01908
01909
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923
01924
01925
01926 } else {
01927
01928 for (int i=0; i<n; i++) {
01929 Tree e = nth(le, i);
01930 Type te = getSigType(e);
01931
01932
01933
01934 string vperm = subst("$0_$1",makeRecVarPermName_vect(ID, i),T(loop_unroll));
01935 string vtemp = subst("$0_$1",makeRecVarTempName_vect(ID, i),T(loop_unroll));
01936
01937
01938
01939 if(loop_unroll==3) {
01940
01941 if(te->nature()==kInt) {
01942 fClass->addDeclCode(subst("vec_int \t$0;", vperm));
01943 fClass->addInitCode(subst("$0 = set_vec(0);", vperm));
01944 } else {
01945 fClass->addDeclCode(subst("vec_float \t$0;", vperm));
01946 fClass->addInitCode(subst("$0 = set_vec(0.0f);", vperm));
01947 }
01948 }
01949
01950
01951 fClass->addExecCode(subst("vec_$0 $1 = $2;", cType(te), vtemp, CS(tEnv2,e,kScal)));
01952
01953
01954
01955
01956
01957
01958
01959
01960
01961
01962
01963
01964
01965
01966
01967
01968
01969
01970 }
01971
01972 for (int i=0; i<n; i++) {
01973
01974 Tree e = nth(le, 0);
01975 Type te = getSigType(e);
01976
01977
01978 if(loop_unroll==3) fClass->addExecCode(subst("\t$0_$1 = $2_$1;", makeRecVarPermName_vect(ID, i), T(loop_unroll), makeRecVarTempName_vect(ID, i)));
01979 else {
01980
01981
01982
01983 if(te->nature()==kInt) fClass->addExecCode(subst("vec_int $0_$1 = $2_$1;", makeRecVarPermName_vect(ID, i), T(loop_unroll), makeRecVarTempName_vect(ID, i)));
01984 else fClass->addExecCode(subst("vec_float $0_$1 = $2_$1;", makeRecVarPermName_vect(ID, i), T(loop_unroll), makeRecVarTempName_vect(ID, i)));
01985 }
01986
01987
01988
01989 }
01990
01991 }
01992
01993
01994 return ID;
01995 }
01996
01997
01998
01999 string VectorCompiler::generateRecProj (Tree env, Tree sig, const string& ID, int i)
02000 {
02001 return subst("$0_$1",makeRecVarPermName_vect(ID, i),T(rec_var_map[ID]));
02002
02003 }
02004
02005
02006
02007 string VectorCompiler::generateRecRef (Tree env, Tree sig, Tree label)
02008 {
02009 Tree t;
02010
02011 if (getProperty(label, RECNAMEPROP, t)) {
02012 return name(t->node().getSym());
02013 } else {
02014
02015 exit(1);
02016 }
02017 return "error in Compiler::generateRecRef";
02018 }
02019