bool HandlerBroker::connect(MyThread * TID, const wxString& sDevName,const std::string& strDevInit, DEVID *id){ DevDesc * pNewDev; DevDesc* pDevLocker = getDev(sDevName); if (!pDevLocker) return false; std::string strUniqueDev = std::string(sDevName.utf8_str())+ pDevLocker->makeUniqueDev(strDevInit); { wxMutexLocker ml1(mtxDevHandlesTreeEdit); std::map<std::string, CountedDevHandle*>::iterator itDevH = mapDevHandlesInUse.find(strUniqueDev); if(itDevH != mapDevHandlesInUse.end()){ pNewDev = itDevH->second->dev; }else{ pNewDev = pDevLocker->clone(); if (!(pNewDev->connect(strDevInit)))return false; wxMutexLocker ml2(mtxBusLockTreeEdit); std::string strBusLock= pNewDev->makeBusLock(strDevInit); pNewDev->itBusLocker = mapBusLockers.find(strBusLock); if(pNewDev->itBusLocker == mapBusLockers.end()) pNewDev->itBusLocker = mapBusLockers.insert(std::make_pair(strBusLock, new mtxCont)).first; ++(*(pNewDev->itBusLocker->second)); itDevH = mapDevHandlesInUse.insert( std::make_pair( strUniqueDev, new CountedDevHandle(pNewDev)) ).first; itDevH->second->dev->itDevH = itDevH; } ++(*(itDevH->second)); } wxMutexLocker ml0(mtxDevTreeEdit); std::map<MyThread *, ThrDevs*>::iterator it=mapThreadDevsInUse.find(TID); if (it == mapThreadDevsInUse.end()) it = mapThreadDevsInUse.insert(std::pair<MyThread * , ThrDevs*>(TID, new ThrDevs(TID)) ).first; *id = it->second->insert(pNewDev); return true; };
Wire::~Wire(void) { int32 ret = 0; // DEBUG UOSUTIL_DOUT(("~Wire(): entered")); if (_p1 && _p2) { MutexLocker ml1(_p1); MutexLocker ml2(_p2); ret = _p1->disconnect(_p2->getBlock(), _p2); if (ret == FAILURE) { // DEBUG UOSUTIL_DOUT(("~Wire(): disconnect failure on %s\n", _p1->getAbsoluteName())); } ret = _p2->disconnect(_p1->getBlock(), _p1); if (ret == FAILURE) { // DEBUG UOSUTIL_DOUT(("~Wire(): disconnect failure on %s\n", _p2->getAbsoluteName())); } /* * Pin2 is an input pin for sure, so the buffer pool is shared among * wires. If there are no more peers connected to pin2, it means * that no more wires share buffer pool and this is the last wire. * So delete the bp2 buffer pool. */ if (!_p2->getPeersCount()) { delete _bp2; _p2->_ibp = NULL; _p2->_bpSet = false; } /* * In case of bidirectional wire, Pin1 behaves like Pin2. So * check for type and do the same us below. */ if (_type == BIDIRECTIONAL) { // DEBUG UOSUTIL_DOUT(("~Wire(): doing cleanup for bidirectional wire\n")); UOSUTIL_DOUT(("~Wire(): p1 = %s, p2 = %s\n", _p1->getAbsoluteName(), _p2->getAbsoluteName())); if (!_p1->getPeersCount()) { delete _bp1; _p1->_ibp = NULL; _p1->_bpSet = false; } } } // DEBUG UOSUTIL_DOUT(("~Wire(): ok")); }
int32 Wire::_allocate(void) { uint32 max_buf_size = 0, p1_bsz = 0, p2_bsz = 0; int32 max_buf_count = 0, p1_bco = 0, p2_bco = 0; int32 ret = 0; char tmp[4096]; // get right buffers info if (_p1->getStatus() == Pin::CONNECTED) { p1_bsz = _p1->_real_bufsz; p1_bco = _p1->_real_bufcount; } else { p1_bsz = _p1->_pref_bufsz; p1_bco = _p1->_pref_bufcount; } if (_p2->getStatus() == Pin::CONNECTED) { p2_bsz = _p2->_real_bufsz; p2_bco = _p2->_real_bufcount; } else { p2_bsz = _p2->_pref_bufsz; p2_bco = _p2->_pref_bufcount; } // select right buffers size and count max_buf_size = p1_bsz > p2_bsz ? p1_bsz : p2_bsz; max_buf_count = p1_bco > p2_bco ? p1_bco : p2_bco; // DEBUG UOSUTIL_DOUT(("Wire::_allocate(): BSZ = %u, BCO = %d\n", max_buf_size, max_buf_count)); // lock pins MutexLocker ml1(_p1); MutexLocker ml2(_p2); // check which pin needs a buffer pool if (!_p1->_bpSet) { // check if this wire is bidirectional if (_type == BIDIRECTIONAL) { // build buffer pool name snprintf(tmp, sizeof(tmp), "BP1[%s,%s]", _p1->getAbsoluteName(), _p2->getAbsoluteName()); // create buffer pool object _bp1 = new BufferPool(); if (!_bp1) return FAILURE; // allocate buffer pool for Pin 1 ret = _bp1->init(tmp, max_buf_size, max_buf_count); if (ret == FAILURE) { delete _bp1; return FAILURE; } // DEBUG UOSUTIL_DOUT(("Wire::_allocate(): allocating bp for pin %s\n", _p1->getAbsoluteName())); // associate bp1 to pin 1 _p1->_ibp = _bp1; } else { // set input buffer pool for pin 1 to NULL _p1->_ibp = NULL; } // signal that buffer pool has been set _p1->_bpSet = true; } else { // use pin 1's buffer pool _bp1 = _p1->_ibp; _multipoint_on_bp1 = true; // DEBUG UOSUTIL_DOUT(("Wire::_allocate(): it is multipoint\n")); UOSUTIL_DOUT(("Wire::_allocate(): using buffer pool of pin %s (%s)\n", _p1->getAbsoluteName(), _bp1 ? "and is ok" : "and is null")); } /* * Notice that data flow from pin1 to pin2. Buffer pool * is associated to the input pin so I need to create * a buffer pool only for pin2. */ if (!_p2->_bpSet) { // build buffer pool name snprintf(tmp, sizeof(tmp), "BP2[%s,%s]", _p1->getAbsoluteName(), _p2->getAbsoluteName()); // create buffer pool object _bp2 = new BufferPool(); if (!_bp2) return FAILURE; // allocate buffer pool for Pin 2 ret = _bp2->init(tmp, max_buf_size, max_buf_count); if (ret == FAILURE) { delete _bp2; return FAILURE; } // associate bp2 to pin 2 _p2->_ibp = _bp2; // signal that buffer pool has been set _p2->_bpSet = true; // DEBUG UOSUTIL_DOUT(("Wire::_allocate(): allocating bp for pin %s\n", _p2->getAbsoluteName())); } else { // use pin 2's buffer pool _bp2 = _p2->_ibp; _multipoint_on_bp2 = true; // DEBUG UOSUTIL_DOUT(("Wire::_allocate(): - it is multipoint\n")); UOSUTIL_DOUT(("Wire::_allocate(): using buffer pool of pin %s (%s)\n", _p2->getAbsoluteName(), _bp2 ? "and is ok" : "and is null")); } // set real parameters for pins _p1->_real_bufsz = max_buf_size; _p1->_real_bufcount = max_buf_count; _p2->_real_bufsz = max_buf_size; _p2->_real_bufcount = max_buf_count; // ok return SUCCESS; }
int main(void) { float *a = malloc(sizeof(float)*NUM + SSE_ALIGN); /* make sure that pointers are aligned to multiplies of 16 bytes */ a = (float *) align(a, SSE_ALIGN); /* write values to a and b */ for (int i = 0; i < NUM; i++) { a[i] = i; } /* invoke the function written in the vector language */ ml0(NUM, a); /* read values from c */ printf("Result for vector a after ml0:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml1(NUM, a); printf("Result for vector a after ml1:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml2(NUM, a); printf("Result for vector a after ml2:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml3(NUM, a); printf("Result for vector a after ml3:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml4(NUM, a); printf("Result for vector a after ml4:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml5(NUM, a); printf("Result for vector a after ml5:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml6(NUM, a); printf("Result for vector a after ml6:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml7(NUM, a); printf("Result for vector a after ml7:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); ml8(NUM, a); printf("Result for vector a after ml8:\n"); for (int i = 0; i < NUM; i++) { printf("%f ", a[i]); } printf("\n"); return 0; }
// resolve two clauses, if possible. int resolveClauses(Array<BinaryTree_AVL<Clause> > &clausesArray, Clause &cl1, Clause &cl2, int &clausesAdded, unsigned int currentDepth) { // check if any of the clauses are empty statistics[ResolutionsAttempted] += 1; totalstatistics[TotalResolutionsAttempted] += 1; if (cl1.isEmpty() || cl2.isEmpty()) { return(VALID); } // check if clauses can be resolved if (!cl1.getSOS() && !cl2.getSOS()) { // one clause must be in the set-of-support return(NOMATCH); } if ((cl1.getType() == Clause::Negative && cl2.getType() == Clause::Negative) || (cl1.getType() == Clause::Positive && cl2.getType() == Clause::Positive)) { // two positive clauses or two negative clauses // can not be resolved. return(NOMATCH); } // attempt to resolve two clauses. use A-ordering resolution, // try to resolve maximal literals. // Literal maxlit1; if (cl1.getMaximalLiteral(maxlit1) != OK) { ERROR("getMaximalLiteral failed.", errno); return(NOTOK); } Literal maxlit2; if (cl2.getMaximalLiteral(maxlit2) != OK) { ERROR("getMaximalLiteral failed.", errno); return(NOTOK); } if ((cl1.getTotalMembers() > maxliterals) || (cl2.getTotalMembers() > maxliterals)) { statistics[MaximumLiteralsClausesRejected] += 1; totalstatistics[TotalMaximumLiteralsClausesRejected] += 1; return(NOMATCH); } if (maxlit1.unify_ne(~maxlit2)) { return(NOMATCH); } // factor clauses Substitutions subs; if (factor(maxlit1, cl1, subs) == NOTOK) { ERROR("factor failed.", errno); return(NOTOK); } if (factor(maxlit2, cl2, subs) == NOTOK) { ERROR("factor failed.", errno); return(NOTOK); } // attempt to unify the clauses subs.clear(); int status = unify(maxlit1, ~maxlit2, subs); switch (status) { case OK: if (verbose) { cout << endl; Literal ml1(maxlit1); cout << "max literal 1 (before subs): " << ml1 << endl; subs.applyTo(ml1); cout << "max literal 1 (after subs): " << ml1 << endl; Literal ml2(maxlit2); cout << "max literal 2 (before subs): " << ml2 << endl; subs.applyTo(ml2); cout << "max literal 2 (after subs): " << ml2 << endl; MustBeTrue(equal(ml1, ~ml2)); } break; case NOMATCH: return(NOMATCH); default: ERROR("unify failed.", errno); return(status); } // can resolve, remove literals from clauses Clause newcl1(cl1); if (newcl1.remove(maxlit1) != OK) { ERROR("remove failed.", errno); return(NOTOK); } if (subs.applyTo(newcl1) != OK) { ERROR("applyTo failed.", errno); return(NOTOK); } Clause newcl2(cl2); if (newcl2.remove(maxlit2) != OK) { ERROR("remove failed.", errno); return(NOTOK); } if (subs.applyTo(newcl2) != OK) { ERROR("applyTo failed.", errno); return(NOTOK); } // store new clause and update flag Clause newcl = newcl1+newcl2; if (newcl.renameVariables() != OK) { ERROR("renameVariables failed.", errno); return(NOTOK); } newcl.setDepth(currentDepth+1); newcl.setNumber(nextClause++); if (clausesArray[currentDepth+1].insert(newcl) != OK) { ERROR("insert failed.", errno); return(NOTOK); } clausesAdded = 1; // indicate the clauses that were resolved statistics[ClausesGenerated] += 1; totalstatistics[TotalClausesGenerated] += 1; dumpnewclause(cl1, cl2, newcl); // check if we found an empty clause if (newcl.isEmpty()) { return(VALID); } else { return(OK); } }