static inline bool isConstantColor_ (const ImageBuf &src, float *color, ROI roi, int nthreads) { // Iterate using the native typing (for speed). std::vector<T> constval (roi.nchannels()); ImageBuf::ConstIterator<T,T> s (src, roi); for (int c = roi.chbegin; c < roi.chend; ++c) constval[c] = s[c]; // Loop over all pixels ... for ( ; ! s.done(); ++s) { for (int c = roi.chbegin; c < roi.chend; ++c) if (constval[c] != s[c]) return false; } if (color) { ImageBuf::ConstIterator<T,float> s (src, roi); for (int c = 0; c < roi.chbegin; ++c) color[c] = 0.0f; for (int c = roi.chbegin; c < roi.chend; ++c) color[c] = s[c]; for (int c = roi.chend; c < src.nchannels(); ++c) color[c] = 0.0f; } return true; }
//Input: A string x (representing a constant integer) //Output: A normalized expression with x as sum NC* createConstant( char *constant ) { NC *sum; sum = (NC*) malloc (sizeof(NC)); sum->list = NULL; sum->type = 'S'; sum->inc = constval(constant); sum->link = NULL; //The next statement adds the constant to corresponding var_list //Although it is seemingly unnecessary, it is done to remain compliant //with previous code if(!(flagVar_List)) indexof_varlist(constant, &V0); else indexof_varlist(constant, &V1); return sum; }
void backpatchlabel(char *labelname) { struct BackPatch *bp, *nbp, *pbp, *zbp; int off, vv, vvv, reg, in; unsigned int ui; struct Value *vp = getvaluepos(&llabels, labelname); vvv = getvalueint(vp); bp = bplist; while(bp) { if(!strcmp(bp->label, labelname)) { switch(bp->type) { case BP_ADR: in = getint(&odata, bp->where); reg = getint(&odata, bp->where + 4); vv = vvv + bp->value;; ui = (vv - bp->where)-8; if((vv - bp->where)-8 < 0) { in |= 2<<21; /* sub */ ui = (unsigned int) (- (int) ui); } else in |= 4<<21; /* add */ placeint(&odata, in | constval(&ui) | (15<<16), bp->where); placeint(&odata, in | constval(&ui) | (reg<<16), bp->where + 4); placeint(&odata, in | constval(&ui) | (reg<<16), bp->where + 8); break; case BP_BRANCH: off = bp->value & 0x00ffffff; bp->value &= 0xff000000; vv = vvv + off; if((vv - bp->where)&3) error("Offset must be aligned"); placeint(&odata, bp->value | ((((vv - bp->where)-8)>>2) & 0x00ffffff), bp->where); break; case BP_DTRANS: off = bp->value & 0xfff; in = bp->value & 0xfffff000; vv = vvv + off; vv = (vv - bp->where)-8; if((vv < -4095) || (vv > 4095)) error("Offset out of range"); if(vv < 0) vv = -vv; else in |= 1<<23; placeint(&odata, in | (vv&0xfff), bp->where); break; case BP_FPDTRANS: off = bp->value & 0xff; in = bp->value & 0xffffff00; vv = vvv + off; vv = (vv - bp->where)-8; if((vv < -0x3fc) || (vv > 0x3fc)) error("Offset out of range"); if(vv & 3) error("Offset not aligned"); if(vv < 0) vv = -vv; else in |= 1<<23; placeint(&odata, in | ((vv >> 2) & 0xff), bp->where); break; case BP_DFNL: addinttoarea(&olinkis, bp->where - curfuncstart); addinttoarea(&olinkis, addonestrtoarea(curfuncname)); addinttoarea(&olinkis, bp->value + vvv - curfuncstart); numlinkis++; break; default: fatal("Internal error: Unknown backpatch type"); } freemem(bp->label); zbp = bp; nbp = bp->next; pbp = bp->prev; freemem(bp); if(zbp == bplist) bplist = nbp; if(pbp) pbp->next = nbp; if(nbp) nbp->prev = pbp; bp = nbp; } else bp = bp->next; }
//Input: A name (type: string) and all characteristics of an FSMD //Output: An FSMD with proper states and transitions void createFSMD( char* FSMDname, STMT_LIST *stmts ) { FSMD *M; TRANSITION_ST *trans; STMT *oneStmt; int i, j, k; int current_state, temp, numtrans; if(!(flagVar_List)) { M0 = (FSMD*) malloc (sizeof(FSMD)); M = M0; } else { M1 = (FSMD*) malloc (sizeof(FSMD)); M = M1; } strcpy(M->name, FSMDname); current_state = 0; for(i = 0; i < stmts->numStatements; i++) { oneStmt = stmts->statements[i]; temp = create_state( oneStmt->stateName, M, current_state ); numtrans = constval(oneStmt->numTransitions); M->states[temp].numtrans = numtrans; //value propagation code start M->states[temp].VAPFLAG = FALSE; M->states[temp].propVector.cond = NULL; for(j=0; j < SYMTABSIZE; j++) { M->states[temp].propVector.value[j] = NULL; //array start M->states[temp].propVector.subVector[j].countValues = 0; for(k = 0; k < MAX_ARRAY_VALUES; k++) { M->states[temp].propVector.subVector[j].arrayValue[k] = NULL; } //array end } //value propagation code end if( numtrans == 0 ) { M->states[temp].node_type = 1; // state with no outward transition. This is the last state of the fsmd. // it has a dummy transition from itself to the start state of the fmsd, // with condition = '-' and action = '-'. } else M->states[temp].node_type = 2; if( current_state == 0 ) { // This is the start state of the FSMD M->states[temp].node_type = 0; } if( temp == current_state ) { current_state++; strcpy(M->states[temp].state_id, oneStmt->stateName); } M->states[temp].translist = NULL; for(k = 0; k < numtrans; k++) { // This loop will read the transtions of each state trans = (TRANSITION_ST *) malloc (sizeof(TRANSITION_ST)); trans->next = M->states[temp].translist; M->states[temp].translist = trans; trans->condition = oneStmt->substmts->substmt[k]->condition; generateAssignments(oneStmt->substmts->substmt[k]->assignments, trans); trans->outtrans = create_state(oneStmt->substmts->substmt[k]->stateName, M, current_state); if(trans->outtrans == current_state) { current_state++; M->states[trans->outtrans].translist = NULL; M->states[trans->outtrans].numtrans = 0; M->states[trans->outtrans].node_type = 1; strcpy(M->states[trans->outtrans].state_id, oneStmt->substmts->substmt[k]->stateName); } } } M->numstates = current_state; }