static NODE * builtin_stdarg_start(const struct bitable *bt, NODE *a) { NODE *p, *q; int sz; /* must first deal with argument size; use int size */ p = a->n_right; if (p->n_type < INT) { sz = (int)(SZINT/tsize(p->n_type, p->n_df, p->n_ap)); } else sz = 1; /* do the real job */ p = buildtree(ADDROF, p, NIL); /* address of last arg */ #ifdef BACKAUTO p = optim(buildtree(PLUS, p, bcon(sz))); /* add one to it (next arg) */ #else p = optim(buildtree(MINUS, p, bcon(sz))); /* add one to it (next arg) */ #endif q = block(NAME, NIL, NIL, PTR+VOID, 0, 0); /* create cast node */ q = buildtree(CAST, q, p); /* cast to void * (for assignment) */ p = q->n_right; nfree(q->n_left); nfree(q); p = buildtree(ASSIGN, a->n_left, p); /* assign to ap */ nfree(a); return p; }
//update the scanline optimization cost when the direction is horizontal //x1 is current column and x2 is previous column void StereoFlow::scanlineOptimizationH(const float* costs, float* soCosts, int x1, int x2) { for(int y = 0; y < height; ++y) { optim(costs, soCosts, x1, x2 ,y, y); } }
/* * va_start(ap, last) implementation. * * f is the NAME node for this builtin function. * a is the argument list containing: * CM * ap last * * It turns out that this is easy on MIPS. Just write the * argument registers to the stack in va_arg_start() and * use the traditional method of walking the stackframe. */ NODE * mips_builtin_stdarg_start(NODE *f, NODE *a, TWORD t) { NODE *p, *q; int sz = 1; /* check num args and type */ if (a == NULL || a->n_op != CM || a->n_left->n_op == CM || !ISPTR(a->n_left->n_type)) goto bad; /* must first deal with argument size; use int size */ p = a->n_right; if (p->n_type < INT) { /* round up to word */ sz = SZINT / tsize(p->n_type, p->n_df, p->n_ap); } p = buildtree(ADDROF, p, NIL); /* address of last arg */ p = optim(buildtree(PLUS, p, bcon(sz))); q = block(NAME, NIL, NIL, PTR+VOID, 0, 0); q = buildtree(CAST, q, p); p = q->n_right; nfree(q->n_left); nfree(q); p = buildtree(ASSIGN, a->n_left, p); tfree(f); nfree(a); return p; bad: uerror("bad argument to __builtin_stdarg_start"); return bcon(0); }
/// update the scanline optimization cost when the direction is horizontal /// x1 is current column and x2 is previous column void scanlineOptimizationH(const float* costs, float* soCosts, int x1, int x2, const PARAMETERS& params) { for(int y=0; y<params.h; ++y){ optim(costs, soCosts, x1, x2, y, y, params); } }
/// update the scanline optimization cost when the direction is vertical /// y1 is current line and y2 is previous line void scanlineOptimizationV(const float* costs, float* soCosts, int y1, int y2, const PARAMETERS& params) { for(int x=0; x<params.w; ++x){ optim(costs, soCosts, x, x, y1, y2, params); } }
//update the scanline optimization cost when the direction is vertical //y1 is current line and y2 is previous line void StereoFlow::scanlineOptimizationV(const float* costs, float* soCosts, int y1, int y2) { for(int x = 0; x < width; ++x) { // double t = (double)getTickCount(); /*if(x == 500) { cout << "DEBUG" << endl; }*/ optim(costs, soCosts, x, x, y1, y2); //0.07s // printf("times = %.2f s\n", (double)(getTickCount() - t)/getTickFrequency()); } }
void ComplexInliner::process(BooleanDAG& dag){ // cout<<" funmap has size " << functionMap.size() << endl; somethingChanged = true; { DagOptim optim(dag); optim.process(dag); } computeSpecialInputs(); expectedNFuns = 2; timerclass everything("everything"); everything.start(); int inlin = 0; while(somethingChanged && dag.size() < 510000 && inlin < inlineAmnt){ somethingChanged = false; if(inlin!=0){ cout<<inlin<<": inside the loop dag.size()=="<<dag.size()<<endl; } immInline(dag); //if(inlin==0){( dag.print(cout) );} ++inlin; } everything.stop(); if(inlin>1){ cout<<" final dag.size()=="<<dag.size()<<endl; cout<<"inlin = "<<inlin<<endl; everything.print(); unifyTime.print(); clonetime.print(); optAll.print(); optimTime.print(); } /* for(map<string, pair<int, int> >::iterator it = sizes.begin(); it != sizes.end(); ++it){ cout<<it->first<<" : "<< (it->second.second / it->second.first)<<" "<<it->second.second<<" "<<it->second.first<<endl; } */ // dag.print(cout); { DagFunctionToAssertion makeAssert(dag, functionMap); makeAssert.process(dag); } if(inlin>1){ cout<<" After everything: dag.size()=="<<dag.size()<<endl; } }
/* * fortran function arguments */ static NODE * fortarg(NODE *p) { if( p->n_op == CM ){ p->n_left = fortarg( p->n_left ); p->n_right = fortarg( p->n_right ); return(p); } while( ISPTR(p->n_type) ){ p = buildtree( UMUL, p, NIL ); } return( optim(p) ); }
void myp2tree(NODE *p) { struct symtab *sp; NODE *l, *r; int o = p->n_op; switch (o) { case NAME: /* reading from a name must be done with a subroutine */ if (p->n_type != CHAR && p->n_type != UCHAR) break; l = buildtree(ADDROF, ccopy(p), NIL); r = block(NAME, NIL, NIL, INT, 0, 0); r->n_sp = lookup(addname("__nova_rbyte"), SNORMAL); if (r->n_sp->sclass == SNULL) { r->n_sp->sclass = EXTERN; r->n_sp->stype = INCREF(p->n_type)+(FTN-PTR); } r->n_type = r->n_sp->stype; r = clocal(r); r = optim(buildtree(CALL, r, l)); *p = *r; nfree(r); break; case FCON: sp = tmpalloc(sizeof(struct symtab)); sp->sclass = STATIC; sp->sap = 0; sp->slevel = 1; /* fake numeric label */ sp->soffset = getlab(); sp->sflags = 0; sp->stype = p->n_type; sp->squal = (CON >> TSHIFT); defloc(sp); ninval(0, tsize(sp->stype, sp->sdf, sp->sap), p); p->n_op = NAME; p->n_lval = 0; p->n_sp = sp; } }
Result* OptimizationInterface::loadResult(QFileInfo saveFile,const QDomElement & domOMCase, ProjectBase * projectBase) { if(domOMCase.isNull() || domOMCase.tagName()!="OMCase" ) return NULL; Project* project = dynamic_cast<Project*>(projectBase); if(!project) return NULL; // read problem bool ok; QDomElement domOMProblem = domOMCase.firstChildElement("OMProblem"); QDomElement domProblem = domOMProblem.firstChildElement(Optimization::className()); Optimization optim(domProblem,project,ok); if(!ok) { InfoSender::instance()->send( Info(ListInfo::RESULTFILECORRUPTED,saveFile.filePath())); return NULL; } // create result QDomElement domOMResult = domOMCase.firstChildElement("OMResult"); QDomElement domResult = domOMResult.firstChildElement(OptimResult::className()); Result* result = new OptimResult(project,domResult,optim,saveFile.absoluteDir(),ok); if(!result) { InfoSender::instance()->send( Info(ListInfo::RESULTFILECORRUPTED,saveFile.filePath())); return NULL; } // attribute problem to result if(result) { // attribute file path to result result->setEntireSavePath(saveFile.filePath()); } return result; }
/* * local optimizations, most of which are probably * machine independent */ NODE * optim(NODE *p) { int o, ty; NODE *sp, *q; OFFSZ sz; int i; if (odebug) return(p); ty = coptype(p->n_op); if( ty == LTYPE ) return(p); if( ty == BITYPE ) p->n_right = optim(p->n_right); p->n_left = optim(p->n_left); /* collect constants */ again: o = p->n_op; switch(o){ case SCONV: if (concast(p->n_left, p->n_type)) { q = p->n_left; nfree(p); p = q; break; } /* FALLTHROUGH */ case PCONV: if (p->n_type != VOID) p = clocal(p); break; case FORTCALL: p->n_right = fortarg( p->n_right ); break; case ADDROF: if (LO(p) == TEMP) break; if( LO(p) != NAME ) cerror( "& error" ); if( !andable(p->n_left) && !statinit) break; LO(p) = ICON; setuleft: /* paint over the type of the left hand side with the type of the top */ p->n_left->n_type = p->n_type; p->n_left->n_df = p->n_df; p->n_left->n_ap = p->n_ap; q = p->n_left; nfree(p); p = q; break; case NOT: case UMINUS: case COMPL: if (LCON(p) && conval(p->n_left, o, p->n_left)) p = nfree(p); break; case UMUL: /* Do not discard ADDROF TEMP's */ if (LO(p) == ADDROF && LO(p->n_left) != TEMP) { q = p->n_left->n_left; nfree(p->n_left); nfree(p); p = q; break; } if( LO(p) != ICON ) break; LO(p) = NAME; goto setuleft; case RS: if (LCON(p) && RCON(p) && conval(p->n_left, o, p->n_right)) goto zapright; sz = tsize(p->n_type, p->n_df, p->n_ap); if (LO(p) == RS && RCON(p->n_left) && RCON(p) && (RV(p) + RV(p->n_left)) < sz) { /* two right-shift by constants */ RV(p) += RV(p->n_left); p->n_left = zapleft(p->n_left); } #if 0 else if (LO(p) == LS && RCON(p->n_left) && RCON(p)) { RV(p) -= RV(p->n_left); if (RV(p) < 0) o = p->n_op = LS, RV(p) = -RV(p); p->n_left = zapleft(p->n_left); } #endif if (RO(p) == ICON) { if (RV(p) < 0) { RV(p) = -RV(p); p->n_op = LS; goto again; } #ifdef notyet /* must check for side effects, --a >> 32; */ if (RV(p) >= tsize(p->n_type, p->n_df, p->n_sue) && ISUNSIGNED(p->n_type)) { /* ignore signed shifts */ /* too many shifts */ tfree(p->n_left); nfree(p->n_right); p->n_op = ICON; p->n_lval = 0; p->n_sp = NULL; } else #endif /* avoid larger shifts than type size */ if (RV(p) >= sz) { RV(p) = RV(p) % sz; werror("shift larger than type"); } if (RV(p) == 0) p = zapleft(p); } break; case LS: if (LCON(p) && RCON(p) && conval(p->n_left, o, p->n_right)) goto zapright; sz = tsize(p->n_type, p->n_df, p->n_ap); if (LO(p) == LS && RCON(p->n_left) && RCON(p)) { /* two left-shift by constants */ RV(p) += RV(p->n_left); p->n_left = zapleft(p->n_left); } #if 0 else if (LO(p) == RS && RCON(p->n_left) && RCON(p)) { RV(p) -= RV(p->n_left); p->n_left = zapleft(p->n_left); } #endif if (RO(p) == ICON) { if (RV(p) < 0) { RV(p) = -RV(p); p->n_op = RS; goto again; } #ifdef notyet /* must check for side effects */ if (RV(p) >= tsize(p->n_type, p->n_df, p->n_sue)) { /* too many shifts */ tfree(p->n_left); nfree(p->n_right); p->n_op = ICON; p->n_lval = 0; p->n_sp = NULL; } else #endif /* avoid larger shifts than type size */ if (RV(p) >= sz) { RV(p) = RV(p) % sz; werror("shift larger than type"); } if (RV(p) == 0) p = zapleft(p); } break; case MINUS: if (LCON(p) && RCON(p) && p->n_left->n_sp == p->n_right->n_sp) { /* link-time constants, but both are the same */ /* solve it now by forgetting the symbols */ p->n_left->n_sp = p->n_right->n_sp = NULL; } if( !nncon(p->n_right) ) break; RV(p) = -RV(p); o = p->n_op = PLUS; case MUL: /* * Check for u=(x-y)+z; where all vars are pointers to * the same struct. This has two advantages: * 1: avoid a mul+div * 2: even if not allowed, people may get surprised if this * calculation do not give correct result if using * unaligned structs. */ if (p->n_type == INTPTR && RCON(p) && LO(p) == DIV && RCON(p->n_left) && RV(p) == RV(p->n_left) && LO(p->n_left) == MINUS) { q = p->n_left->n_left; if (q->n_left->n_type == PTR+STRTY && q->n_right->n_type == PTR+STRTY && strmemb(q->n_left->n_ap) == strmemb(q->n_right->n_ap)) { p = zapleft(p); p = zapleft(p); } } /* FALLTHROUGH */ case PLUS: case AND: case OR: case ER: /* commutative ops; for now, just collect constants */ /* someday, do it right */ if( nncon(p->n_left) || ( LCON(p) && !RCON(p) ) ) SWAP( p->n_left, p->n_right ); /* make ops tower to the left, not the right */ if( RO(p) == o ){ NODE *t1, *t2, *t3; t1 = p->n_left; sp = p->n_right; t2 = sp->n_left; t3 = sp->n_right; /* now, put together again */ p->n_left = sp; sp->n_left = t1; sp->n_right = t2; sp->n_type = p->n_type; p->n_right = t3; } if(o == PLUS && LO(p) == MINUS && RCON(p) && RCON(p->n_left) && conval(p->n_right, MINUS, p->n_left->n_right)){ zapleft: q = p->n_left->n_left; nfree(p->n_left->n_right); nfree(p->n_left); p->n_left = q; } if( RCON(p) && LO(p)==o && RCON(p->n_left) && conval( p->n_right, o, p->n_left->n_right ) ){ goto zapleft; } else if( LCON(p) && RCON(p) && conval( p->n_left, o, p->n_right ) ){ zapright: nfree(p->n_right); q = makety(p->n_left, p->n_type, p->n_qual, p->n_df, p->n_ap); nfree(p); p = clocal(q); break; } /* change muls to shifts */ if( o == MUL && nncon(p->n_right) && (i=ispow2(RV(p)))>=0){ if( i == 0 ) { /* multiplication by 1 */ goto zapright; } o = p->n_op = LS; p->n_right->n_type = INT; p->n_right->n_df = NULL; RV(p) = i; } /* change +'s of negative consts back to - */ if( o==PLUS && nncon(p->n_right) && RV(p)<0 ){ RV(p) = -RV(p); o = p->n_op = MINUS; } /* remove ops with RHS 0 */ if ((o == PLUS || o == MINUS || o == OR || o == ER) && nncon(p->n_right) && RV(p) == 0) { goto zapright; } break; case DIV: if( nncon( p->n_right ) && p->n_right->n_lval == 1 ) goto zapright; if (LCON(p) && RCON(p) && conval(p->n_left, DIV, p->n_right)) goto zapright; if (RCON(p) && ISUNSIGNED(p->n_type) && (i=ispow2(RV(p))) > 0) { p->n_op = RS; RV(p) = i; q = p->n_right; if(tsize(q->n_type, q->n_df, q->n_ap) > SZINT) p->n_right = makety(q, INT, 0, 0, 0); break; } break; case MOD: if (RCON(p) && ISUNSIGNED(p->n_type) && ispow2(RV(p)) > 0) { p->n_op = AND; RV(p) = RV(p) -1; break; } break; case EQ: case NE: case LT: case LE: case GT: case GE: case ULT: case ULE: case UGT: case UGE: if( !LCON(p) ) break; /* exchange operands */ sp = p->n_left; p->n_left = p->n_right; p->n_right = sp; p->n_op = revrel[p->n_op - EQ ]; break; #ifdef notyet case ASSIGN: /* Simple test to avoid two branches */ if (RO(p) != NE) break; q = p->n_right; if (RCON(q) && RV(q) == 0 && LO(q) == AND && RCON(q->n_left) && (i = ispow2(RV(q->n_left))) && q->n_left->n_type == INT) { q->n_op = RS; RV(q) = i; } break; #endif } return(p); }
void HAZRD3(void){ int smode; if(H->mode==0 && H->only1!=1) O->N = H->N-1; else O->N = H->N; DCEOBJ(&O->typf); O->itrcnt = 0; H->nfncts = 0; O->gradtl = -ONE; O->stptol = -ONE; O->maxstp = -ONE; O->fdigit = -1; O->prtcod = 2; setoptim(); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); STPNOTE(); if(!(H->angrad || H->anhess)) RESTOR(H->x0,O->N,H->nm1dx,C->theta); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); nrow = ceil((H->N+ONE)/7); if(prnt==1) { OPTHDR(); theta_x(); OPTPRTX(); } while(O->itrcnt<O->itrlmt && O->iret==0 && C->errorno==0 && O->trmcod==0) { optim(); if(C->errorno) { OPTNOTE(); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); } if(prnt==1) { theta_x(); OPTPRTX(); } } if(!(H->angrad || H->anhess)) { RESTOR(H->xplus,O->N,H->nm1dx,C->theta); if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); } O->iret++; smode = H->mode; H->mode = 2; constp(); H->mode = smode; if(C->errorno==1) HAZ3TRM(9900); else if(C->errorno==2) HAZ3TRM(9910); OPTNOTE(); switch(O->iret) { case 2: HAZ3TRM(9110); break; case 3: hzfxpc("Initial estimate appears to be a critical",41,9); hzfxpc(" point. It is possible, however, that it",41,0); hzfxpc(" is a maximizer or a saddle point.",34,0); hzfskp(1); RETRY_T(); break; case 4: hzfxpc("The scaled distance between the last two",40,9); hzfxpc(" estimates of the parameters is less than ",42,0); hzfxpf(O->stptol,16,99,0); hzfskp(1); hzfxpc("The current set of parameter estimates",38,9); hzfxpc(" may be a minimizer. It is also possible",41,0); hzfxpc(" that the optimization code",27,0); hzfskp(1); hzfxpc("is making slow progress and is not near",39,9); hzfxpc(" a minimum.",11,0); hzfskp(1); RETRY_T(); break; case 5: hzfxpc("The last step attempted failed to find a",40,9); hzfxpc(" point better than the last estimate. ",38,0); hzfxpc(" Either the current estimates",29,0); hzfskp(1); hzfxpc("are a minimizer and no more accuracy is",39,9); hzfxpc(" possible or insufficient accuracy is",37,0); hzfxpc(" possible in the gradient calculations",38,0); hzfskp(1); hzfxpc("due to machine precision.",25,9); hzfskp(1); RETRY_T(); break; case 6: hzfxpc("Maximum iterations of ",22,9); hzfxpi(O->itrlmt,5,0); hzfxpc("reached no convergence.",23,-1); hzfskp(1); break; case 7: hzfxpc("Five consecutive steps of length, ",34,9); hzfxpf(O->maxstp,22,99,0); hzfxpc(" have been taken. Either the objective",39,0); hzfxpc(" function is unbounded below or has a",37,0); hzfxpc(" finite asymptote in some direction.",36,0); hzfskp(1); hzfxpc("It is also possible that the value used",39,9); hzfxpc(" is too small.",14,0); hzfskp(1); RETRY_T(); break; case 8: if(H->retry!=0) HAZ3TRM(9136); hzfxpc("Problem is so ill-conditioned that a",36,9); hzfxpc(" reasonable direction of search cannot",38,0); hzfxpc(" be calculated",14,0); hzfskp(1); hzfxpc("given the current limit for the condition",41,9); hzfxpc(" code.",6,0); hzfskp(1); RETRY_T(); } hzfpag(2); }
//TODO dynamically maintain all array sizes int main(int argc, char** argv) { int fr_no=5, s=0; char rep_policy[20] = "FIFO"; char logpath[1024] = "input.txt"; for (s=1; s<argc; s++) { if (strcmp(argv[s], "-f")==0) { fr_no = atoi(argv[++s]); } else if (strcmp(argv[s], "-r")==0) { strcpy(rep_policy, argv[++s]); } else if (strcmp(argv[s], "-i")==0) { strcpy(logpath, argv[++s]); } else if (strcmp(argv[s], "-h")==0) { printf("help mode"); serverOptions(); } else { printf("\n\nNo Options Passed, ...\n"); } } int i, j=0,nf=0; if(fr_no>0){ nf=fr_no; } else{ printf("Enter proper frame value\n"); exit(0); } unsigned int input[16] ={0,1,2,3,0,1,2,3,0,1,2,3,4,5,6,7};//{1,2,3,4,1,2,5,1,2,3,4,5}; count_page=0; //{ 1, 2, 3, 1, 1, 2, 4, 1, 3, 2, 1, 3 };// //TODO load the array size from file inputs //Reading from file FILE *f; char res[1024]; f = fopen(logpath,"r"); if (f == NULL) {perror ("Error opening file..Exiting...\n");exit(0);} else { fgets(res,1024,f); //puts(res); char* str=NULL; char delim[] = " "; str=strtok(res,delim); while(str!=NULL) { input[i]=atoi(str); i++; count_page++; str = strtok(NULL," "); } } printf("%d %s %s\n", fr_no, rep_policy, logpath); if (strcmp(rep_policy,"LRU-REF8")==0) { printf("Executing LRU-Ref8\n"); pr1=lruRefBit(input, nf); pr2 = optim(input, nf); compare(rep_policy); return 0; } /*else if(==2){ optim(input,nf); return 0; }*/ else if (strcmp(rep_policy,"LRU-STACK")==0) { printf("Executing LRU-STACK\n"); pr1= lruStack(input, nf); pr2 = optim(input, nf); compare(rep_policy); return 0; } else if (strcmp(rep_policy,"LFU")==0) { printf("Executing LFU\n"); pr1=lfu(input, nf); pr2 = optim(input, nf); compare(rep_policy); return 0; } else if (strcmp(rep_policy,"LRU-CLOCK")==0) { pr1 = lruref8bit(input,nf); pr2 = optim(input, nf); compare(rep_policy); } else { pr1 = fifo(input, nf); pr2 = optim(input, nf); compare(rep_policy); return 0; } }
char * netmap(char name[], char from[]) { char nbuf[BUFSIZ], ret[BUFSIZ]; register char *cp, *oname; if (debug) fprintf(stderr, "netmap(name '%s', from '%s')\n", name, from); if (strlen(from) == 0) return(name); /* "from" is empty - can't do anything */ if (strcmp(from, name) == 0) return(name); /* "from" and "name" are the same, do nothing */ /* * If the name contains an "@" or a "%", remove it and the host * following it if that host is "known". */ if (any('@', name) || any('%', name)) return(arpafix(name, from)); /* * If the sender contains a "@" or a "%", make "name" into an * address on that host, on the presumption that it should * really have read "name@from" when we received the message * rather than just "name". */ if (any('@', from) || any('%', from)) return(unuucp(makeremote(name, from))); if (value("onehop") && (cp = strchr(name, '!')) && cp > name) { /* * "onehop" is set, meaning all machines are one UUCP * hop away (fat chance, in this day and age), and "name" * is a UUCP path rather than just a name. Leave it alone. */ nstrcpy(nbuf, sizeof (nbuf), name); } else { from = tackon(host, from); *strrchr(from, '!') = 0; name = tackon(lasthost(from), name); while (((cp = lasthost(from)) != 0) && ishost(cp, name)) { oname = name; name = strchr(name, '!') + 1; if (cp == from) { from[strlen(from)] = '!'; if (value("mustbang") && !strchr(name, '!')) name = oname; return(unuucp(name)); } *--cp = 0; } from[strlen(from)] = '!'; from = strchr(from, '!') + 1; snprintf(nbuf, sizeof (nbuf), "%s!%s", from, name); } if (debug) fprintf(stderr, "before optim, nbuf '%s'\n", name); #ifdef OPTIM if ((cp = value("conv"))==NOSTR || strcmp(cp, "optimize") != 0) nstrcpy(ret, sizeof (ret), nbuf); else optim(nbuf, ret); #else nstrcpy(ret, sizeof (ret), nbuf); #endif /* OPTIM */ if (debug) fprintf(stderr, "after optim, nbuf '%s', ret '%s'\n", nbuf, ret); cp = ret; if (debug) fprintf(stderr, "wind up with '%s'\n", name); if (!icequal(name, cp)) return(unuucp((char *) savestr(cp))); return(unuucp(name)); }