/* * ??? This function really categorizes the lblock "line"... ??? * Annotates the "line" with ALWAYSMISS/ALWAYSHIT/FIRSTMISS/FIRSTHIT * In the case of FIRSTMISS, also annotate with the loop-header of the most inner loop. */ void CATBuilder::worst(LBlock *line , ContextTree *node , LBlockSet *idset, int dec){ int number = idset->count(); BasicBlock *bb = line->bb(); LBlock *cacheline; BitSet *in = new BitSet(number); in = IN(bb); //int count = 0; bool nonconflitdetected = false; bool continu = false; unsigned long tagcachline,tagline; //test if it's the lbloc which find in the same memory block /* * If the IN(line) = {LB} and cacheblock(line)==cacheblock(LB), then * nonconflict (Always Hit) */ if (in->count() == 1){ for (int i=0;i < number;i++){ if (in->contains(i)){ cacheline = idset->lblock(i); tagcachline = ((unsigned long)cacheline->address()) >> dec; unsigned long tagline = ((unsigned long)line->address()) >> dec; if (tagcachline == tagline ) nonconflitdetected = true; } } }
BitSet* ChainedFilter::bits( IndexReader* reader, int logic ) { BitSet* bts = NULL; Filter** filter = filters; // see discussion at top of file if( *filter ) { BitSet* tmp = (*filter)->bits( reader ); if ( (*filter)->shouldDeleteBitSet(tmp) ) //if we are supposed to delete this BitSet, then bts = tmp; //we can safely call it our own else if ( tmp == NULL ){ int32_t len = reader->maxDoc(); bts = _CLNEW BitSet( len ); //bitset returned null, which means match _all_ for (int32_t i=0;i<len;i++ ) bts->set(i); }else{ bts = tmp->clone(); //else it is probably cached, so we need to copy it before using it. } filter++; } else bts = _CLNEW BitSet( reader->maxDoc() ); while( *filter ) { doChain( bts, reader, logic, *filter ); filter++; } return bts; }
void PVCopy::initCopy( PVStructure ©PVStructure, BitSet &bitSet, bool lockRecord) { bitSet.clear(); bitSet.set(0); updateCopyFromBitSet(copyPVStructure,bitSet,lockRecord); }
BitSet ATNConfigSet::getAlts() { BitSet alts; for (ATNConfig config : configs) { alts.set(config.alt); } return alts; }
double processInternalChild(Symbol parentSymbol,int parentID,int child, NthOrdSubstMatrix &noPt) { AlignmentSeq &track=A.getIthTrack(parentID); AlignmentSeq &childTrack=A.getIthTrack(child); int contextBegin=column-order; if(contextBegin<0) contextBegin=0; int contextLen=column-contextBegin; Sequence context; track.getSeq().getSubsequence(contextBegin,contextLen,context);//ACO //A.getIthTrack(root->getID()).getSeq().getSubsequence(contextBegin,contextLen,context);//TRCO int pos=MultSeqAlignment::rightmostGapPos(context,gapSymbols); if(pos>=0) { throw "this should not happen (FitchFelsenstein)::processInternalChild"; Sequence temp; context.getSubsequence(pos+1,contextLen-pos-1,temp); context=temp; } SubstitutionMatrix &Pt=*noPt.lookup(context,0,-1); Array2D<double>::RowIn2DArray<double> row=L[child]; Symbol childSym=childTrack.getSeq()[column]; double ll; if(gapSymbols.isMember(childSym)){ V.setAllTo(NEGATIVE_INFINITY); for(Symbol a=0 ; a<numAlpha ; ++a) { if(!gapSymbols.isMember(a)) { V[(int)a]=safeAdd(row[a],Pt(parentSymbol,a)); } } ll=sumLogProbs(V); } else { ll=safeAdd(row[childSym],Pt(parentSymbol,childSym)); } return ll; }
/* * Restricted propagation procedure. Used when a direction is solved, but no new q-intersection is found. * Same as propagate, except that upper bounds are not recorded (because we did not find a curr_qinter to work with). */ void propagate_no_ub(const Array<IntervalVector>& boxes, IntStack ***dirboxes, int dimension, bool left, IntervalVector& hull_qinter, vector<BitSet *>& nogoods) { unsigned int n = hull_qinter.size(); unsigned int p = boxes.size(); IntervalVector b(n); /* Create the new nogood */ BitSet *newNogood = new BitSet(0,p-1,BitSet::empt); /* We iterate through the boxes to propagate bounds */ /* This does not seem to be optimal ; maybe we should study directly the directions' lists ? */ for (int i=0; i<p; i++) { b = boxes[i]; /* Check if the box can be added to the new nogood */ if ((left && (b[dimension].lb() < hull_qinter[dimension].lb())) || (!left && (b[dimension].ub() > hull_qinter[dimension].ub()))) { newNogood->add(i); } /* Check if the box is strictly outside our current q-inter hull */ if ((left && (b[dimension].ub() < hull_qinter[dimension].lb())) || (!left && (b[dimension].lb() > hull_qinter[dimension].ub()))) { for (int k=dimension+1; k<n; k++) { if (dirboxes[k][0]->contain(i)) dirboxes[k][0]->remove(i); if (dirboxes[k][1]->contain(i)) dirboxes[k][1]->remove(i); } continue; } } nogoods.push_back(newNogood); }
BitSet BitSet::operator+(const BitSet& that) { BitSet result(*this); for (int i = 0; i < that.length(); ++i) { result.add(that.get(i)); } return result; }
// populates el (assumed to be pre-allocated adequately by caller) // with list of members in bitset bs. static SB_INLINE void bitset_get_list_here(BitSet& bs, uint32_t *el) { int j = 0; BitSet::iterator i; for(i = bs.begin(); i != bs.end(); i++) { el[j] = *i; j++; } }
static SB_INLINE void bitset_iter(BitSet& bs, int (*app)(uint32_t e, void* stuff1), void* stuff2) { BitSet::iterator i; for(i = bs.begin(); i != bs.end(); i++) { if((app(*i, stuff2)) != 0) { break; } } }
BitSet * BitSet::New(unsigned int max) { BitSet *result = new BitSet(max); if (!result->init()) return NULL; return result; }
int main(int argc, char *argv[]) { int x = 63; BitSet a; a.insertIntoSet(x); a.deleteFromSet(x); cout << a.isInBitSet(x); return 0; }
void BitVector<dim>::unslice(BitSet<dim> t,size_t new_size) { BitSet<dim> result; for (typename BitSet<dim>::iterator it=t.begin(); it(); d_data>>=1,++it) result.set(*it,d_data[0]); d_data=result; d_size=new_size; }
BitSet BitSet::operator!() { BitSet bs; for (int i = 0; i < this->bitLength; ++i) { bool bit = (*this)[i]; bs.add(!bit); } return bs; }
Delta delta( const BitSet& bit, const Scalar& default_value ) { Delta u( bit.size(), 1 ); for( uint i = 0; i < bit.size(); ++i ) { if( bit[i]) { u.insert( i, 0 ) = default_value; } } return u; }
NFAFrag NFA::cloneFrag(const NFAFrag& frag) { list<NFAState*> workList; BitSet visited; workList.push_back(frag.start); visited.set(frag.start->stateId); map<NFAState*,NFAState*> old2new; typedef map<NFAState*,NFAState*>::iterator Old2NewIter; while(!workList.empty()) { NFAState* cur_state=workList.front();workList.pop_front(); for(map<int,NFAState*>::iterator it=cur_state->cedges.begin();it!=cur_state->cedges.end();++it) { NFAState* nextstate=0; Old2NewIter findit; if((findit=old2new.find(it->second))==old2new.end()) { old2new[it->second]=nextstate=newState(); } else nextstate=findit->second; cur_state->cedges[it->first]=nextstate; if(!visited[nextstate->stateId]) workList.push_back(nextstate); } for(NFAStateArrIter it=cur_state->eedges.begin();it!=cur_state->eedges.end();++it) { NFAState* nextstate=0; Old2NewIter findit; if((findit=old2new.find(*it))==old2new.end()) { old2new[*it]=nextstate=newState(); } else nextstate=findit->second; patch(cur_state,nextstate); if(!visited[nextstate->stateId]) workList.push_back(nextstate); } } NFAFrag ret(old2new[frag.start],old2new[frag.out]); return ret; }
BitSet BitSet::operator<<(const int shift) { BitSet result; for (int i = 0; i < shift; ++i) { result.add(false); } for (int i = 0; i < this->length(); ++i) { result.add((*this)[i]); } return result; }
BitSet BitSet::operator&=(const BitSet& that) { int maxLength = std::max(this->length(), that.length()); for (int i = 0; i < maxLength; ++i) { if (i >= this->length() || i >= that.length()) { this->put(false, i); } else { this->put((*this)[i] && that[i], i); } } return *this; }
void ChunkManager::dataChecked(const BitSet & ok_chunks) { // go over all chunks at check each of them for (Uint32 i = 0;i < chunks.count();i++) { Chunk* c = chunks[i]; if (ok_chunks.get(i) && !bitset.get(i)) { // We think we do not hae a chunk, but we do have it bitset.set(i,true); todo.set(i,false); // the chunk must be on disk c->setStatus(Chunk::ON_DISK); tor.updateFilePercentage(i,bitset); } else if (!ok_chunks.get(i) && bitset.get(i)) { Out(SYS_DIO|LOG_IMPORTANT) << "Previously OK chunk " << i << " is corrupt !!!!!" << endl; // We think we have a chunk, but we don't bitset.set(i,false); todo.set(i,!only_seed_chunks.get(i) && !excluded_chunks.get(i)); if (c->getStatus() == Chunk::ON_DISK) { c->setStatus(Chunk::NOT_DOWNLOADED); tor.updateFilePercentage(i,bitset); } else if (c->getStatus() == Chunk::MMAPPED || c->getStatus() == Chunk::BUFFERED) { resetChunk(i); } else { tor.updateFilePercentage(i,bitset); } } } recalc_chunks_left = true; try { saveIndexFile(); } catch (bt::Error & err) { Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : " << err.toString() << endl; } catch (...) { Out(SYS_DIO|LOG_DEBUG) << "Failed to save index file : unkown exception" << endl; } chunksLeft(); corrupted_count = 0; }
BitSet BitSet::operator&(const BitSet& that) { BitSet bs; int maxLength = std::max(this->length(), that.length()); for (int i = 0; i < maxLength; ++i) { if (i >= this->length() || i >= that.length()) { bs.add(false); } else { bs.add((*this)[i] && that[i]); } } return bs; }
BitSet BitSet::operator|=(const BitSet& that) { int maxLength = std::max(this->length(), that.length()); for (int i = 0; i < maxLength; ++i) { if (i < this->length() && i >= that.length()) { this->put((*this)[i], i); } else if (i >= this->length() && i < that.length()) { this->put(that[i], i); } else { this->put((*this)[i] || that[i], i); } } return *this; }
static void calculateReachableNodesInLoop(LoopNode* loop, Node* node, Node* stopNode, BitSet& flags) { int id = node->getId(); if (!loop->inLoop(node) || node == stopNode || flags.getBit(id)) { return; } flags.setBit(id, true); const Edges& edges = node->getOutEdges(); for (Edges::const_iterator ite = edges.begin(), ende = edges.end(); ite!=ende; ++ite) { Edge* e = *ite; Node* nextNode = e->getTargetNode(); if (nextNode != loop->getHeader()) { calculateReachableNodesInLoop(loop, nextNode, stopNode, flags); } } }
/* * Bound propagation and nogood recording. Assumes that dimensions are processed in the ascending order and left side first. */ void propagate(const Array<IntervalVector>& boxes, IntStack ***dirboxes, int dimension, bool left, IntervalVector& curr_qinter, vector<BitSet *>& nogoods) { unsigned int n = curr_qinter.size(); unsigned int p = boxes.size(); IntervalVector b(n); /* Create the new nogood */ BitSet *newNogood = new BitSet(0,p-1,BitSet::empt); /* We iterate through the boxes to propagate bounds */ /* This does not seem to be optimal ; maybe we should study directly the directions' lists ? */ for (int i=0; i<p; i++) { b = boxes[i]; /* Check if the box can be added to the new nogood */ if ((left && (b[dimension].lb() < curr_qinter[dimension].lb())) || (!left && (b[dimension].ub() > curr_qinter[dimension].ub()))) { newNogood->add(i); } /* First check : the q-inter is a valid upper bound for the opposite direction */ if (left && (b[dimension].ub() <= curr_qinter[dimension].ub())) { if (dirboxes[dimension][1]->contain(i)) dirboxes[dimension][1]->remove(i); } /* Second check : check if the box is strictly outside our current q-inter hull */ if ((left && (b[dimension].ub() < curr_qinter[dimension].lb())) || (!left && (b[dimension].lb() > curr_qinter[dimension].ub()))) { for (int k=dimension+1; k<n; k++) { if (dirboxes[k][0]->contain(i)) dirboxes[k][0]->remove(i); if (dirboxes[k][1]->contain(i)) dirboxes[k][1]->remove(i); } continue; } /* Third check : the q-intersection provides a valid upper bound for the orthogonal dimensions. */ for (int j=dimension+1; j<n; j++) { if (b[j].lb() >= curr_qinter[j].lb()) { if (dirboxes[j][0]->contain(i)) dirboxes[j][0]->remove(i); } if (b[j].ub() <= curr_qinter[j].ub()) { if (dirboxes[j][1]->contain(i)) dirboxes[j][1]->remove(i); } } } nogoods.push_back(newNogood); }
void delta( const BitSet& bit, Delta& u, const Scalar& default_value ) { Delta d( bit.size(), 1 ); #pragma omp parallel for for( int i = 0; i < int(bit.size()); ++i ) { if( bit[i]) { #pragma omp critical { d.insert( i, 0 ) = default_value; } } } #pragma omp barrier std::swap( u, d ); }
bool BitSet::operator == (const BitSet & bs) { if (this->getNumBits() != bs.getNumBits()) return false; return memcmp(data,bs.data,num_bytes) == 0; }
/** * helper - add the users of the Defs of a given * instruction to the passed worklist. * * This encapsulates several nontrivial pieces of logic: * 1. Skip use instructions that haven't been reached yet. * 2. Skip over dead arms of constant conditionals. * 3. Jump the call-site gap between block delims. * (goto -> label, cond -> arm) * 4. When reaching a block the first time, mark all its instructions reached * *and* enque them, because they could have been previously skipped. */ void SCCP::addInstrUsers(Instr* instr) { for (AllUsesRange u(instr); !u.empty(); u.popFront()) { Instr* use_instr = user(u.front()); if (mark.get(use_instr->id)) ssawork.add(use_instr); } }
//Record IR list into 'irset'. void CfsMgr::recordStmt(IR * ir_list, BitSet & irset) { while (ir_list != NULL) { irset.bunion(IR_id(ir_list)); ir_list = ir_list->get_next(); } }
VectorIterator<Entity*> EntityList::filterByControllers(const BitSet &controllerIds) { return filter( [=] (Entity *e) -> bool { return controllerIds.intersects( e->getEntityType()->getControllers().getBitSet() ); }); }
/** * Test if the first basic block postdominates the second one. * @param bb1 Dominator BB. * @param bb2 Dominated BB. * @return True if bb1 postdominates bb2. */ bool PostDominance::postDominates(BasicBlock *bb1, BasicBlock *bb2) { ASSERTP(bb1, "null BB 1"); ASSERTP(bb2, "null BB 2"); ASSERTP(bb1->cfg() == bb2->cfg(), "both BB are not owned by the same CFG"); int index = bb1->number(); ASSERTP(index >= 0, "no index for BB 1"); BitSet *set = REVERSE_POSTDOM(bb2); ASSERTP(set, "no index for BB 2"); ASSERTP(bb1 == bb2 || !REVERSE_POSTDOM(bb1)->contains(bb2->number()) || !REVERSE_POSTDOM(bb2)->contains(bb1->number()), "CFG with disconnected nodes"); return set->contains(index); }
void Grammar::findFirst1Sets() { findEpsilonSymbols(); const int n = getProductionCount(); bool stable; do { stable = true; for(int p = 0; p < n; p++) { const Production &prod = m_productions[p]; const int length = prod.getLength(); GrammarSymbol &ls = getSymbol(prod.m_leftSide); for(int k = 0; k < length; k++) { const int sk = prod.m_rightSide[k]; if(isTerminal(sk)) { if(!ls.m_first1.contains(sk)) { ls.m_first1.add(sk); // _tprintf(_T("first1(%s) : "), ls.m_name.cstr()); dump(ls.m_first1); printf(_T(")\n"); stable = false; } break; } else { // nonterminal const GrammarSymbol &nt = getSymbol(sk); const BitSet diff(nt.m_first1 - ls.m_first1); if(!diff.isEmpty()) { ls.m_first1 += nt.m_first1; // printf(_T(")first1(%s) : ", ls.m_name.cstr()); dump(ls.m_first1); printf(_T(")\n"); stable = false; } if(!nt.m_deriveEpsilon) { break; } } } } /* gotoxy(0, 0); for(long s = getTerminalCount(); s < getSymbolCount(); s++) { GrammarSymbol &nonTerm = getSymbol(s); _tprintf(_T("first(%-10s):"), nonTerm.m_name.cstr()); dump(nonTerm.m_first1); _tprintf(_T("\n")); } pause(); */ } while(!stable); }
FncKhunTucker::FncKhunTucker(const NormalizedSystem& sys, Function& _df, Function** _dg, const IntervalVector& current_box, const BitSet& active) : Fnc(1,1), nb_mult(0), // **tmp** n(sys.nb_var), sys(sys), df(_df), dg(active.size()), active(active), eq(BitSet::empty(sys.f_ctrs.image_dim())), ineq(BitSet::empty(sys.f_ctrs.image_dim())), bound_left(BitSet::empty(sys.nb_var)), bound_right(BitSet::empty(sys.nb_var)) { int l=1; // lambda0 if (_dg==NULL && !active.empty()) { ibex_error("[FncKhunTucker] an unconstrained system cannot have active constraints"); } unsigned int i=0; // index of a constraint in the active set for (BitSet::const_iterator c=active.begin(); c!=active.end(); ++c, ++i) { dg.set_ref(i,*_dg[c]); if (sys.ops[c]==EQ) eq.add(i); else ineq.add(i); //cout << " constraint n°" << c << " active\n"; } l+=active.size(); for (int j=0; j<sys.box.size(); j++) { if (current_box[j].lb() <= sys.box[j].lb()) { bound_left.add(j); //cout << " left bound n°" << j << " active\n"; l++; } if (current_box[j].ub() >= sys.box[j].ub()) { bound_right.add(j); //cout << " right bound n°" << j << " active\n"; l++; } } (int&) nb_mult = l; (int&) _nb_var = n + l; assert(_nb_var == sys.nb_var + eq.size() + ineq.size() + bound_left.size() + bound_right.size() + 1); (Dim&) _image_dim = Dim(_nb_var, 1); }