/********************************************************************************************************************** * Function : getDigit * * Inputs : > const int *integer. Receives a reference to a integer. * * > unsigned short position. Receives the position of the digit to be extracted * * Outputs : N/A * * Return : The digit character representation for the integer value. * * Description : Returns the enum digit representaion of an integer in the specified position. * * * **********************************************************************************************************************/ enum digit getDigit(const int *integer, unsigned short position) { unsigned short digit = (unsigned short)(absInt(integer)/tenToPW(&position)%10); switch(digit) { case 0: return zero; case 1: return one; case 2: return two; case 3: return three; case 4: return four; case 5: return five; case 6: return six; case 7: return seven; case 8: return eight; case 9: return nine; default: return zero; } }
/*--------------------------------------------------------------------------*/ types::Function::ReturnValue sci_abs(types::typed_list &in, int _iRetCount, types::typed_list &out) { if (in.size() != 1) { Scierror(77, _("%s: Wrong number of input argument(s): %d expected.\n"), "abs", 1); return types::Function::Error; } if (_iRetCount > 1) { Scierror(78, _("%s: Wrong number of output argument(s): %d expected.\n"), "abs", 1); return types::Function::Error; } switch (in[0]->getType()) { case types::InternalType::ScilabDouble: { api_scilab::Double* pDblIn = api_scilab::getAsDouble(in[0]); api_scilab::Double* pDblOut = new api_scilab::Double(pDblIn->getDims(), pDblIn->getDimsArray()); double* pdblInR = pDblIn->get(); double* pdblInI = pDblIn->getImg(); double* pdblOut = pDblOut->get(); int size = pDblIn->getSize(); if (pDblIn->isComplex()) { for (int i = 0; i < size; i++) { if (ISNAN(pdblInR[i])) { pdblOut[i] = pdblInR[i]; } else if (ISNAN(pdblInI[i])) { pdblOut[i] = pdblInI[i]; } else { pdblOut[i] = dabsz(pdblInR[i], pdblInI[i]); } } } else { for (int i = 0; i < size; i++) { if (ISNAN(pdblInR[i])) { pdblOut[i] = pdblInR[i]; } else { pdblOut[i] = std::fabs(pdblInR[i]); } } } out.push_back(api_scilab::getReturnVariable(pDblOut)); delete pDblOut; delete pDblIn; break; } case types::InternalType::ScilabPolynom: { types::Polynom* pPolyIn = in[0]->getAs<types::Polynom>(); types::Polynom* pPolyOut = new types::Polynom(pPolyIn->getVariableName(), pPolyIn->getDims(), pPolyIn->getDimsArray()); double* data = NULL; if (pPolyIn->isComplex()) { for (int i = 0; i < pPolyIn->getSize(); i++) { int rank = pPolyIn->get(i)->getRank(); types::SinglePoly* pSP = new types::SinglePoly(&data, rank); for (int j = 0; j < rank + 1; j++) { data[j] = dabsz(pPolyIn->get(i)->get()[j], pPolyIn->get(i)->getImg()[j]); } pPolyOut->set(i, pSP); delete pSP; pSP = NULL; } } else { for (int i = 0; i < pPolyIn->getSize(); i++) { int rank = pPolyIn->get(i)->getRank(); types::SinglePoly* pSP = new types::SinglePoly(&data, rank); for (int j = 0; j < rank + 1; j++) { data[j] = dabss(pPolyIn->get(i)->get()[j]); } pPolyOut->set(i, pSP); delete pSP; pSP = NULL; } } out.push_back(pPolyOut); break; } case types::InternalType::ScilabInt8: { out.push_back(absInt(in[0]->getAs<types::Int8>())); break; } case types::InternalType::ScilabInt16: { out.push_back(absInt(in[0]->getAs<types::Int16>())); break; } case types::InternalType::ScilabInt32: { out.push_back(absInt(in[0]->getAs<types::Int32>())); break; } case types::InternalType::ScilabInt64: { out.push_back(absInt(in[0]->getAs<types::Int64>())); break; } case types::InternalType::ScilabUInt8: case types::InternalType::ScilabUInt16: case types::InternalType::ScilabUInt32: case types::InternalType::ScilabUInt64: { out.push_back(in[0]); break; } default: { std::wstring wstFuncName = L"%" + in[0]->getShortTypeStr() + L"_abs"; return Overload::call(wstFuncName, in, _iRetCount, out); } } return types::Function::OK; }
/********************************************************************************************************************** * Function : getNumDigitsa * * Inputs : const int *integer. Receives a reference to the integer to which the number of decimal digits is to * * be obtained. * * Outputs : N/A * * Return : Unsigned short that represents the desired number of digits. * * Description : Divide the argument-referenced integer by 10 to the power of counter, as far as the results is * * greater than one, while counting in counter how many times the said division is made * * * **********************************************************************************************************************/ unsigned short getNumDigits(const int *integer) { unsigned short count; unsigned absValue = absInt(integer); for(count = 1; absValue/tenToPW(&count) > 0u; count++); return count; }
/* analyze data reference with regular access pattern */ int analyze_regular_access(dat_inst_t *d_inst, inf_node_t *ib) { int dbg = 0; int i,j,min, tmp; int lpId, addr, flag; insn_t *insn; expr_p exp; reg_t tmpReg; ts_p ts; loop_t *lp; int lpIter[5]; worklist_p tsList, tsNode, addrSet; initReg(&tmpReg); exp = &(d_inst->addrExpr); //check if it is really regular access (no unknown parameter) for (i=0; i<exp->varNum; i++) { if (exp->value[i].t==VALUE_PARA || exp->value[i].t==VALUE_UNDEF){ analyze_unpred_access(d_inst,ib);return;} } //Sort BIV loopID in ascending order for (i=0; i<exp->varNum; i++) { min = i; for (j=i+1; j<exp->varNum; j++) { if (exp->value[j].val <= exp->value[min].val) min = j; #if 0 if (exp->coef[i] = 0 - exp->coef[j]) { exp->value[i].val = max(exp->value[i].val,exp->value[j].val); exp->coef[i] = absInt(exp->coef[i]); exp->coef[j] = 0; exp->value[j].val = 999; } #endif } if (i==min) continue;//exp->value[i] is already min if (exp->value[min].val == exp->value[i].val) { //min & i are two biv of the same loop --> merge exp->coef[i] += exp->coef[min]; exp->value[min].val = 999;exp->coef[min] =0; } else {//swap min & i cpyReg(&tmpReg, exp->value[i]); cpyReg(&(exp->value[i]), exp->value[min]); cpyReg(&(exp->value[min]), tmpReg); tmp = exp->coef[i]; exp->coef[i]=exp->coef[min]; exp->coef[min]=tmp; } } //Clear up merged register while (exp->varNum>0) { i = exp->varNum-1; if (exp->value[i].val == 999) exp->varNum--; else break; } /*To deal with j = i*/ if (dbg) {fprintf(dbgAddr,"\nSorted expr: ");printExpr(dbgAddr,exp);} //create the temporal scope for memory blocks of d_inst tsList = NULL; tsNode = NULL; lp = loops[exp->value[0].val];//inner most loop i = 0; while (lp!=NULL) { if (0) fprintf(dbgAddr,"\n In loop L%d, lbound %d",lp->id,lp->bound-1); ts = (ts_p) malloc(sizeof(ts_s)); if (lp->id == exp->value[i].val) { ts->loop_id = lp->id; ts->lw = 0; ts->up = 0; ts->flag = 0;i++; } else { ts->loop_id = lp->id; ts->lw = 0; ts->up = lp->bound; ts->flag = 0; } addAfterNode(ts, &tsNode, &tsList); //addToWorkList( &(orgTS),memTS); lp = lp->parent; } if (dbg) {fprintf(dbgAddr,"\nTemporal scope: ");printTSset(dbgAddr,tsList);} //enumerating possible memory blocks addrSet = NULL; lastNode = NULL; enumTSset = &tsList; enumAddrSet = &addrSet; flag = 0; for (i=0; i<num_tcfg_loops; i++) iterValue[i]=-1; minAddr = exp->k; maxAddr = 0; enum_regular_address(d_inst, exp, flag, 0, tsList, exp->k); d_inst->addr_set = addrSet; if (dbg) { fprintf(dbgAddr,"\nGenerated range: [%x, %x], %d elems", minAddr, maxAddr, GET_MEM(maxAddr-minAddr)); //printSAddrSet(dbgAddr,d_inst->addr_set,1); } }