/** * @brief This constructor builds the Quadtree data structure from a list of Nodes and * a list Elements * @param nodes * @param elements * @param size * @param minX * @param maxX * @param minY * @param maxY */ Quadtree::Quadtree(std::vector<Node> nodes, std::vector<Element> elements, int size, float minX, float maxX, float minY, float maxY) { nodeList = nodes; elementList = elements; binSize = size; glLoaded = false; pointCount = 0; VAOId = 0; VBOId = 0; IBOId = 0; outlineShader = 0; camera = 0; // Create the root branch std::cout << "Creating quadtree: " << minX << ", " << maxX << ", " << minY << ", " << maxY << std::endl; root = newBranch(minX, maxX, minY, maxY); if (binSize > 0) { for (unsigned int i=0; i<nodeList.size(); i++) addNode(&nodeList[i], root); for (unsigned int i=0; i<elementList.size(); i++) addElement(&elementList[i], root); } hasElements = true; }
void AggressiveDCEPass::AddBranch(uint32_t labelId, BasicBlock* bp) { std::unique_ptr<Instruction> newBranch( new Instruction(context(), SpvOpBranch, 0, 0, {{spv_operand_type_t::SPV_OPERAND_TYPE_ID, {labelId}}})); context()->AnalyzeDefUse(&*newBranch); context()->set_instr_block(&*newBranch, bp); bp->AddInstruction(std::move(newBranch)); }
void Lightning::Strike() { //While its not hit the ground while(!hitGround) { //If not first branch(to save on the else statment) if(!firstBranch) { //create branch from parent branch glm::vec3 begin = lightningStrike[predessingIndex].getEnd(); newBranch(begin,strikeBranchPercentage, false, 0); } else { //Create a brand new branch. newBranch(startingPoint,strikeBranchPercentage , false, 0); predessingIndex = 0; firstBranch = false; } branchOff(); } //Finish branches until the amount of branches it has gets to 0 while(!finishedBranches) { finishOffBranches(); branchOff(); } //Find the core branch to seperate from branch offs FindCoreBranch(); /*!DEBUG ONLY!*/ //for(int i = 0; i<m_vCoreVerts.size();i++){ // printf("\n CORE BRANCH %i = X:%f, Y:%f, Z%f", i, m_vCoreVerts[i].x, m_vCoreVerts[i].y, m_vCoreVerts[i].z); //} for (int i = 0; i < m_vCoreVerts.size(); i+=2) { if (m_vCoreVerts[i] == m_vBranchedVerts[0]) { branchedStart = m_vCoreVerts.size() - i; break; } } }
void Lightning::branchOff() { //Check for any current branch offs, if so branch off them. for(unsigned int i= 0; i<lightningStrike.size(); i++) { if(lightningStrike[i].getBranchChance() == true) { int randVal = rand() % 2; int branchAmountSize = rand() % 5; if(randVal == 0) { newBranch(lightningStrike[i].getEnd(),strikeBranchPercentage, true,branchAmountSize); }else { newBranch(lightningStrike[i].getBeginning(),strikeBranchPercentage,true,branchAmountSize); } lightningStrike[i].setBranchChance(false); } } }
void Lightning::finishOffBranches() { //finish off the branches as if continously branch off, it can go forever. for(unsigned int i= 0; i<lightningStrike.size(); i++) { if(lightningStrike[i].getAmountOfBranches() == 0){ finishedBranches = true; }else if(lightningStrike[i].getIsBranchOff() == true ) { newBranch(lightningStrike[i].getEnd(),strikeBranchPercentage, true, lightningStrike[i].getAmountOfBranches() - 1); lightningStrike[i].setAmountOfBranches(0); finishedBranches = false; } } }
void BaseTreeView::reload(BaseTreeBranch *btb) { // remember the old status QStringList folderToOpen; btb->addOpenFolder(&folderToOpen); KURL url = btb->rootUrl(); // remove and open again removeBranch(btb); btb = dynamic_cast<BaseTreeBranch *>(newBranch(url)); if (btb) { btb->folderToOpen = folderToOpen; btb->reopenFolder(); btb->updateOpenFolder(); } }
void TreeWrapper::setBranch( const char* branchName, T* dataPtr, int bufferSize, int splitLevel ) { std::string dataName = branchName; dataName += "/"; dataName += TreeTypeNames::typeCode( dataPtr ); branch_desc* bDesc = newBranch( branchName, dataPtr, dataName.c_str() ); bDesc->bufferSize = bufferSize; bDesc->splitLevel = splitLevel; bDesc->branchPtr = 0; return; }
/** * @brief Converts a leaf into a branch * * This function is used to turn a leaf into a branch when the leaf needs to add more nodes * but has reached its maximum capacity. All of the nodes that were in the old leaf are added * to the new branch and the old leaf is permanently deleted. * * @param currLeaf A pointer to the leaf that will be turned into a branch * @return A pointer to the new branch object */ branch* Quadtree::leafToBranch(leaf *currLeaf) { // Create new branch with same bounds as the old leaf branch *currBranch = newBranch(currLeaf->bounds[0], currLeaf->bounds[1], currLeaf->bounds[2], currLeaf->bounds[3]); // Add all of the nodes that were in the old leaf to the new branch for (unsigned int i=0; i<currLeaf->nodes.size(); i++) addNode(currLeaf->nodes[i], currBranch); // Remove the old leaf pointer from the leaf list (just change to 0, removing is inefficient) and delete it for (unsigned int i=0; i<leafList.size(); i++) { if (leafList[i] == currLeaf && leafList[i] != 0) { leafList[i] = 0; delete currLeaf; } } return currBranch; }
/** * @brief This constructor builds the Quadtree data structure from a list of Nodes * @param nodes A list of Node objects to be included in the Quadtree * @param size The maximum number of Node objects allowed in each leaf * @param minX The lower bound x-value * @param maxX The upper bound x-value * @param minY The lower bound y-value * @param maxY The upper bound y-value */ Quadtree::Quadtree(std::vector<Node> nodes, int size, float minX, float maxX, float minY, float maxY) { nodeList = nodes; binSize = size; glLoaded = false; pointCount = 0; VAOId = 0; VBOId = 0; IBOId = 0; outlineShader = 0; camera = 0; // Create the root branch root = newBranch(minX, maxX, minY, maxY); if (binSize > 0) for (unsigned int i=0; i<nodeList.size(); i++) addNode(&nodeList[i], root); hasElements = false; }
void DivergenceAnalysis::_findBranches(branch_set& branches) { Analysis* dfgAnalysis = getAnalysis("DataflowGraphAnalysis"); assert(dfgAnalysis != 0); DataflowGraph &dfg = static_cast<DataflowGraph&>(*dfgAnalysis); /* Create a list of branches that can be divergent, that is, they are not bra.uni and have a predicate */ DataflowGraph::iterator block = dfg.begin(); DataflowGraph::iterator endBlock = dfg.end(); /* Post-dominator tree */ PostdominatorTree *dtree; dtree = (PostdominatorTree*) (getAnalysis("PostDominatorTreeAnalysis")); report(" Finding branches"); for (; block != endBlock; ++block) { ir::PTXInstruction *ptxInstruction = NULL; if (block->instructions().size() > 0) { /* Branch instructions can only be the last instruction of a basic block */ DataflowGraph::Instruction& lastInstruction = *(--block->instructions().end()); if (typeid(ir::PTXInstruction) == typeid(*(lastInstruction.i))) { ptxInstruction = static_cast<ir::PTXInstruction*>(lastInstruction.i); if ((ptxInstruction->opcode == ir::PTXInstruction::Bra)) { report(" examining " << ptxInstruction->toString()); if(ptxInstruction->uni == true) { report(" eliminated, uniform..."); continue; } if(lastInstruction.s.size() == 0) { report(" eliminated, wrong source count (" << lastInstruction.s.size() << ")..."); continue; } assert(lastInstruction.s.size() == 1); DataflowGraph::iterator postDomBlock = dfg.getCFGtoDFGMap()[ dtree->getPostDominator(block->block())]; if (postDomBlock != dfg.end()) { BranchInfo newBranch(&(*block), &(*postDomBlock), lastInstruction, _divergGraph); branches.insert(newBranch); report(" is potentially divergent..."); } else { report(" eliminated, no post-dominator..."); } } } } } }
PeepHoleOpt::Changed PeepHoleOpt::handleInst_Convert_F2I_D2I(Inst* inst) { // // Inline 'int_value = (int)(float_value or double_value)' // Opnd* dst = inst->getOpnd(0); Opnd* src = inst->getOpnd(2); Type* srcType = src->getType(); assert(srcType->isSingle() || srcType->isDouble()); assert(dst->getType()->isInt4()); const bool is_dbl = srcType->isDouble(); // Here, we might have to deal with 3 cases with src (_value): // 1. Unassigned operand - act as if were operating with XMM // 2. Assigned to FPU - convert to FPU operations, to // avoid long FPU->mem->XMM chain // 3. Assigned to XMM - see #1 const bool xmm_way = !(src->hasAssignedPhysicalLocation() && src->isPlacedIn(OpndKind_FPReg)); if (!xmm_way) { //TODO: will add FPU later if measurements show it worths trying return Changed_Nothing; } // // /* movss xmm0, val // presuming the corner cases (NaN, overflow) // normally happen rare, do conversion first, // and check for falls later -- convertNode cvttss2si eax, xmm0 -- ovfTestNode // did overflow happen ? cmp eax, 0x80000000 jne _done // no - go return result -- testAgainstZeroNode // test SRC against zero comiss xmm0, [fp_zero] // isNaN ? jp _nan // yes - go load 0 -- testIfBelowNode // xmm < 0 ? jb _done // yes - go load MIN_INT. EAX already has it - simply return. -- loadMaxIntNode // ok. at this point, XMM is positive and > MAX_INT // must load MAX_INT which is 0x7fffffff. // As EAX has 0x80000000, then simply substract 1 sub eax, 1 jmp _done -- loadZeroNode _nan: xor eax, eax -- nodeNode _done: mov result, eax } */ Opnd* fpZeroOpnd = getZeroConst(srcType); Type* int32type = irManager->getTypeManager().getInt32Type(); Opnd* oneOpnd = irManager->newImmOpnd(int32type, 1); Opnd* intZeroOpnd = getIntZeroConst(); // 0x8..0 here is not the INT_MIN, but comes from the COMISS // opcode description instead. Opnd* minIntOpnd = irManager->newImmOpnd(int32type, 0x80000000); newSubGFG(); Node* entryNode = getSubCfgEntryNode(); Node* convertNode = newBB(); Node* ovfTestNode = newBB(); Node* testAgainstZeroNode = newBB(); Node* testIfBelowNode = newBB(); Node* loadMaxIntNode = newBB(); Node* loadZeroNode = newBB(); Node* doneNode = newBB(); // // presuming the corner cases (NaN, overflow) // normally happen rare, do conversion first, // and check for falls later // connectNodes(entryNode, convertNode); // // convert // setCurrentNode(convertNode) ; Mnemonic mn_cvt = is_dbl ? Mnemonic_CVTTSD2SI : Mnemonic_CVTTSS2SI; /*cvttss2si r32, xmm*/ newInst(mn_cvt, 1, dst, src); connectNodeTo(ovfTestNode); setCurrentNode(NULL); // // check whether overflow happened // setCurrentNode(ovfTestNode); /*cmp r32, MIN_INT*/ newInst(Mnemonic_CMP, dst, minIntOpnd); /*jne _done */ newBranch(Mnemonic_JNE, doneNode, testAgainstZeroNode, 0.9, 0.1); // setCurrentNode(NULL); // test SRC against zero // setCurrentNode(testAgainstZeroNode); Mnemonic mn_cmp = is_dbl ? Mnemonic_UCOMISD : Mnemonic_UCOMISS; /*comiss src, 0. */ newInst(mn_cmp, src, fpZeroOpnd); /*jp _nan:result=0*/ newBranch(Mnemonic_JP, loadZeroNode, testIfBelowNode); setCurrentNode(NULL); // // // setCurrentNode(loadZeroNode); /*mov r32, 0*/ newInst(Mnemonic_MOV, dst, intZeroOpnd); /*jmp _done*/ connectNodeTo(doneNode); setCurrentNode(NULL); // // test if we have a huge negative in SRC // setCurrentNode(testIfBelowNode); /*jb _done:*/ newBranch(Mnemonic_JB, doneNode, loadMaxIntNode); setCurrentNode(NULL); // // // setCurrentNode(loadMaxIntNode); /* sub dst, 1*/ newInst(Mnemonic_SUB, dst, oneOpnd); connectNodeTo(doneNode); setCurrentNode(NULL); // connectNodes(doneNode, getSubCfgReturnNode()); // propagateSubCFG(inst); return Changed_Node; }