// Evaluate the summed contribution of all gabor impulses within the // cell whose corner is c_i. x_c_i is vector from x (the point // we are trying to evaluate noise at) and c_i. Dual2<float> gabor_cell (GaborParams &gp, const Vec3 &c_i, const Dual2<Vec3> &x_c_i, int seed = 0) { fast_rng rng (gp.periodic ? Vec3(wrap(c_i,gp.period)) : c_i, seed); int n_impulses = rng.poisson (gp.lambda * gp.radius3); Dual2<float> sum = 0; for (int i = 0; i < n_impulses; i++) { // OLD code: Vec3 x_i_c (rng(), rng(), rng()); // Turned out that C++ spec says order of args are unspecified. // gcc appeared to do right-to-left, so to make sure our noise // function is locked down (and works identically for clang, // which evaluates left-to-right), we ask for the rng() calls // one at a time and match the way it looked before. float z_rng = rng(), y_rng = rng(), x_rng = rng(); Vec3 x_i_c (x_rng, y_rng, z_rng); Dual2<Vec3> x_k_i = gp.radius * (x_c_i - x_i_c); float phi_i; Vec3 omega_i; gabor_sample (gp, c_i, rng, omega_i, phi_i); if (x_k_i.val().length2() < gp.radius2) { if (! gp.do_filter) { // N.B. if determinant(gp.filter) is too small, we will // run into numerical problems. But the filtering isn't // needed in that case anyway, so just don't filter. // This seems to only come up when the filter region is // tiny. sum += gabor_kernel (gp.weight, omega_i, phi_i, gp.a, x_k_i); // 3D } else { // Transform the impulse's anisotropy into tangent space Vec3 omega_i_t; multMatrix (gp.local, omega_i, omega_i_t); // Slice to get a 2D kernel Dual2<float> d_i = -dot(gp.N, x_k_i); Dual2<float> w_i_t_s; Vec2 omega_i_t_s; Dual2<float> phi_i_t_s; slice_gabor_kernel_3d (d_i, gp.weight, gp.a, omega_i_t, phi_i, w_i_t_s, omega_i_t_s, phi_i_t_s); // Filter the 2D kernel Dual2<float> w_i_t_s_f; float a_i_t_s_f; Vec2 omega_i_t_s_f; Dual2<float> phi_i_t_s_f; filter_gabor_kernel_2d (gp.filter, w_i_t_s, gp.a, omega_i_t_s, phi_i_t_s, w_i_t_s_f, a_i_t_s_f, omega_i_t_s_f, phi_i_t_s_f); // Now evaluate the 2D filtered kernel Dual2<Vec3> xkit; multMatrix (gp.local, x_k_i, xkit); Dual2<Vec2> x_k_i_t = make_Vec2 (comp(xkit,0), comp(xkit,1)); Dual2<float> gk = gabor_kernel (w_i_t_s_f, omega_i_t_s_f, phi_i_t_s_f, a_i_t_s_f, x_k_i_t); // 2D if (! isfinite(gk.val())) { // Numeric failure of the filtered version. Fall // back on the unfiltered. gk = gabor_kernel (gp.weight, omega_i, phi_i, gp.a, x_k_i); // 3D } sum += gk; } } } return sum; }
inline constexpr const T& min(const T& a, const T& b, Compare comp) { return comp(b, a) ? b : a; }
inline SPROUT_CONSTEXPR T const& min(T const& a, T const& b, Compare comp) { return comp(b, a) ? b : a; }
void TR::ARM64SystemLinkage::createPrologue(TR::Instruction *cursor) { createPrologue(cursor, comp()->getJittedMethodSymbol()->getParameterList()); }
void dipi0(int plt=0, int cut=2, int run=1, int opt=4){ printf("plt=%d cut=%d run=%d opt=%d\n",plt,cut,run,opt); OPT=opt; RUN=run; openCanvas(); if(plt==1 || plt==0) bbc(1); if(plt==2 || plt==0) bbc(2); if(plt==3 || plt==0) bbc(3); if(plt==4 || plt==0) {plot("bbce",11,cut,c1); plot("bbce",13,cut,c2); plot("bbce",12,cut,c3);} if(plt==5 || plt==0) {plot("m0",11,cut,c1); plot("m0",13,cut,c2); plot("m0",12,cut,c3);} if(plt==6 || plt==0) {plot("m1",11,cut,c1); plot("m1",13,cut,c2); plot("m1",12,cut,c3);} if(plt==7 || plt==0) {plot("m2",11,cut,c1); plot("m2",13,cut,c2); plot("m2",12,cut,c3);} if(plt==8 || plt==0) {plot("z1",11,cut,c1); plot("z1",13,cut,c2); plot("z1",12,cut,c3);} if(plt==9 || plt==0) {plot("z2",11,cut,c1); plot("z2",13,cut,c2); plot("z2",12,cut,c3);} if(plt==10|| plt==0) {plot("phi0",11,cut,c1); plot("phi0",13,cut,c2);plot("phi0",12,cut,c3);} if(plt==11|| plt==0) {plot("phi1",11,cut,c1); plot("phi1",13,cut,c2);plot("phi1",12,cut,c3);} if(plt==12|| plt==0) {plot("phi2",11,cut,c1); plot("phi2",13,cut,c2);plot("phi2",12,cut,c3);} if(plt==13|| plt==0) {plot("eta1",11,cut,c1); plot("eta1",13,cut,c2);plot("eta1",12,cut,c3);} if(plt==14|| plt==0) {plot("eta2",11,cut,c1); plot("eta2",13,cut,c2);plot("eta2",12,cut,c3);} if(plt==15|| plt==0) {plot("dphi",11,cut,c1); plot("dphi",13,cut,c2);plot("dphi",12,cut,c3);} if(plt==16|| plt==0) {plot("phi1dphi",11,cut,c1); plot("phi1dphi",13,cut,c2);plot("phi1dphi",12,cut,c3);} if(plt==17|| plt==0) {plot("mix",11,cut,c1); plot("mix",13,cut,c2);plot("mix",12,cut,c3);} if(plt==20 || plt==0){plot("mall",11,cut,c1); plot("mall",13,cut,c2); plot("mall",12,cut,c3);} if(plt==21 || plt==0){plot("z12",11,cut,c1); plot("z12",13,cut,c2); plot("z12",12,cut,c3);} if(plt==30|| plt==0){comp(11,4,2,c1); comp(13,4,2,c2); comp(12,4,2,c3);} if(plt==31|| plt==0){comp(20,2,1,c1);} if(plt==40 || plt==0) {plot("norm",11,cut,c1,2); plot("norm",13,cut,c2,2); plot("norm",12,cut,c3,2);} if(plt==41 || plt==0) { plot("norm",11,cut,c1,1,-1,-1,0.00,4); plot("norm",13,cut,c2,1,-1,-1,0.00,4); plot("norm",12,cut,c3,1,-1,-1,0.00,4); } if(plt==42 || plt==0) { plot("corr",11,cut,c1,1,-1,-1,0.00,4); plot("corr",13,cut,c2,1,-1,-1,0.00,4); plot("corr",12,cut,c3,1,-1,-1,0.00,4); } if(plt==50) mix(run,cut,3,1); if(plt==51) mix(11,12,4,2); if(plt==52) mix(12,16,2,0); if(plt==53) mix(11,2,3,1); if(plt==54) mix(12,16,3,1); if(plt==55) mix(13,16,3,1); if(plt==56) mix(13,2,2,2); if(plt==100 || plt==0){ plot("norm",11,2,c1,1,2,0,0.1); plot("norm",12,2,c2,1,2,0,0.1); plot("norm",12,3,c2,1,2,0,0.1); plot("norm",12,4,c2,1,2,0,0.1); plot("norm",12,5,c2,1,2,0,0.1); plot("norm",12,15,c2,1,2,0,0.1); plot("norm",12,16,c2,1,2,0,0.1); } if(plt==101 || plt==0){ plot("norm",11,2,c1,1,3,1,0.012); plot("norm",11,3,c1,1,3,1,0.012); plot("norm",11,4,c1,1,3,1,0.012); plot("norm",11,5,c1,1,3,1,0.012); plot("norm",11,15,c1,1,3,1,0.012); plot("norm",12,2,c2,1,3,1,0.012); plot("norm",12,3,c2,1,3,1,0.012); plot("norm",12,4,c2,1,3,1,0.012); plot("norm",12,5,c2,1,3,1,0.012); plot("norm",12,15,c2,1,3,1,0.012); plot("norm",12,16,c2,1,3,1,0.012); plot("norm",13,2,c2,1,3,1,0.012); plot("norm",13,3,c2,1,3,1,0.012); plot("norm",13,4,c2,1,3,1,0.012); plot("norm",13,5,c2,1,3,1,0.012); plot("norm",13,15,c2,1,3,1,0.012); plot("norm",13,16,c2,1,3,1,0.012); } if(plt==102 || plt==0){ plot("norm",11,2,c1,1,4,2,0.002); plot("norm",12,2,c2,1,4,2,0.002); plot("norm",12,3,c2,1,4,2,0.002); plot("norm",12,4,c2,1,4,2,0.002); plot("norm",12,5,c2,1,4,2,0.002); plot("norm",12,15,c2,1,4,2,0.002); plot("norm",12,16,c2,1,4,2,0.002); } if(plt==103 || plt==0){ plot("norm",11,2,c1,1,5,3,0.0005); plot("norm",12,2,c2,1,5,3,0.0005); plot("norm",12,3,c2,1,5,3,0.0005); plot("norm",12,4,c2,1,5,3,0.0005); plot("norm",12,5,c2,1,5,3,0.0005); plot("norm",12,15,c2,1,5,3,0.0005); plot("norm",12,16,c2,1,5,3,0.0005); } if(plt==110 || plt==0){ plot("norm",11,2,c1,1,3,1,0.012); plot("norm",11,6,c2,1,3,1,0.012); plot("norm",12,2,c1,1,3,1,0.012); plot("norm",12,6,c2,1,3,1,0.012); plot("norm",15,2,c1,1,3,1,0.012); plot("norm",15,6,c2,1,3,1,0.012); plot("norm",11,2,c1,1,4,2,0.002); plot("norm",11,6,c2,1,4,2,0.002); plot("norm",12,2,c1,1,4,2,0.002); plot("norm",12,6,c2,1,4,2,0.002); plot("norm",15,2,c1,1,4,2,0.002); plot("norm",15,6,c2,1,4,2,0.002); } if(plt==111 || plt==0){ plot("norm",11,12,c1,1,3,1,0.012); plot("norm",11,13,c2,1,3,1,0.012); plot("norm",15,12,c1,1,3,1,0.012); plot("norm",15,13,c2,1,3,1,0.012); plot("norm",12,12,c1,1,3,1,0.012); plot("norm",12,13,c2,1,3,1,0.012); plot("norm",11,12,c1,1,4,2,0.002); plot("norm",11,13,c2,1,4,2,0.002); plot("norm",15,12,c1,1,4,2,0.002); plot("norm",15,13,c2,1,4,2,0.002); plot("norm",12,12,c1,1,4,2,0.002); plot("norm",12,13,c2,1,4,2,0.002); } if(plt==112 || plt==0){ plot("norm",11,9,c1,1,3,1,0.012); plot("norm",11,10,c2,1,3,1,0.012); plot("norm",11,11,c2,1,3,1,0.012); plot("norm",12,9,c1,1,3,1,0.012); plot("norm",12,10,c2,1,3,1,0.012); plot("norm",12,11,c2,1,3,1,0.012); } if(plt==200){ bbc(); for(int c=0; c<NCUT; c++){ plot("mall",11,c,c1); plot("mall",12,c,c2); plot("z12", 11,c,c1); plot("z12", 12,c,c2); plot("norm",11,c,c1); plot("norm",12,c,c2); } } }
// Counts nodes that involved in PRE that are not stores or checks. // These nodes require temps. // bool TR_LocalAnalysisInfo::countSupportedNodes(TR::Node *node, TR::Node *parent, bool &containsCallInStoreLhs) { if (_visitCount == node->getVisitCount()) { return false; } node->setVisitCount(_visitCount); node->setContainsCall(false); if (isCallLike(node)) { node->setContainsCall(true); // would return here } bool flag = false; TR::ILOpCode &opCode = node->getOpCode(); int n = node->getNumChildren(); int32_t i; for (i = 0; i < n; i++) { TR::Node *child = node->getChild(i); bool childHasCallsInStoreLhs = false; if (countSupportedNodes(child, node, childHasCallsInStoreLhs)) flag = true; if (childHasCallsInStoreLhs) containsCallInStoreLhs = true; if (child->containsCall()) { if (node->getOpCode().isStoreIndirect() && (i == 0)) containsCallInStoreLhs = true; node->setContainsCall(true); } } if (TR_LocalAnalysis::isSupportedNode(node, _compilation, parent)) { int oldExpressionOnRhs = hasOldExpressionOnRhs(node, false, containsCallInStoreLhs); if (oldExpressionOnRhs == -1) { if (trace()) { traceMsg(comp(), "\nExpression #%d is : \n",_numNodes); _compilation->getDebug()->print(_compilation->getOutFile(), node, 6, true); } flag = true; node->setLocalIndex(_numNodes); _numNodes++; } else node->setLocalIndex(oldExpressionOnRhs); } else node->setLocalIndex(-1); return flag; }
bool SplitGraphOp::splitNode(Node * const node, std::vector<NodeUnrecPtr> &split) { // PORTME return false; #if 0 //split it only if it is a non special geometry leaf if (!isLeaf(node) || isInExcludeList(node) || !node->getCore()->getType().isDerivedFrom(Geometry::getClassType())) return false; Geometry *geo = dynamic_cast<Geometry *>(node->getCore()); if ( geo->getPositions() == NULL || geo->getPositions()->size() == 0 || geo->getLengths() == NULL || geo->getLengths()->size() == 0 || geo->getTypes() == NULL || geo->getTypes()->size() == 0 ) return false; //get all center points std::vector<Pnt3f> centers; int ind; PrimitiveIterator it(geo); while (!it.isAtEnd()) { switch(it.getType()) { case GL_POINTS: case GL_LINES: case GL_LINE_STRIP: case GL_LINE_LOOP: case GL_TRIANGLE_FAN: case GL_TRIANGLE_STRIP: case GL_QUAD_STRIP: case GL_POLYGON: { Pnt3f center(0,0,0); for (UInt32 i=0; i<it.getLength(); i++) center+=(Vec3f)it.getPosition(i); center/=Real32(it.getLength()); centers.push_back(center); } break; case GL_TRIANGLES: ind=0; while(it.getLength()-ind>=3) { Pnt3f center(0,0,0); for (UInt32 i=0; i<3; i++, ind++) center+=(Vec3f)it.getPosition(ind); center/=3; centers.push_back(center); } break; case GL_QUADS: ind=0; while(it.getLength()-ind>=4) { Pnt3f center(0,0,0); for (UInt32 i=0; i<4; i++, ind++) center+=(Vec3f)it.getPosition(ind); center/=4; centers.push_back(center); } break; default: SWARNING << "SplitGraphOp::splitLeave: encountered " << "unknown primitive type " << it.getType() << ", ignoring!" << std::endl; break; } ++it; } std::vector<int> order; for (UInt32 i=0; i<centers.size(); i++) order.push_back(i); Pnt3fComparator comp(centers); std::sort(order.begin(), order.end(), comp); //now we need (centers.size()/_max_polygons) amount of new geometries int ngeos=int(ceil((double)centers.size()/(double)_max_polygons)); if (ngeos<=1) return false; Geometry **geos = new Geometry *[ngeos]; GeoPTypes **types = new GeoPTypes *[ngeos]; GeoPLengths **lens = new GeoPLengths *[ngeos]; GeoPositions **pnts = new GeoPositions *[ngeos]; GeoNormals **normals = new GeoNormals *[ngeos]; GeoColors **colors = new GeoColors *[ngeos]; GeoColors **scolors = new GeoColors *[ngeos]; GeoTexCoords **tex = new GeoTexCoords *[ngeos]; GeoTexCoords **tex1 = new GeoTexCoords *[ngeos]; GeoTexCoords **tex2 = new GeoTexCoords *[ngeos]; GeoTexCoords **tex3 = new GeoTexCoords *[ngeos]; GeoIndices **indices = new GeoIndices *[ngeos]; int **pni = new int*[ngeos]; int **nni = new int*[ngeos]; int **cni = new int*[ngeos]; int **sni = new int*[ngeos]; int **tni = new int*[ngeos]; int **t1ni = new int*[ngeos]; int **t2ni = new int*[ngeos]; int **t3ni = new int*[ngeos]; for (Int32 i=0; i<ngeos; i++) { geos[i] = Geometry::create(); geos[i]->setMaterial(geo->getMaterial()); if(geo->getMFIndexMapping() != NULL) geos[i]->getMFIndexMapping()->setValues(*(geo->getMFIndexMapping())); types[i] = dynamic_cast<GeoPTypes *>(geo->getTypes()->getType().createFieldContainer()); lens[i] = dynamic_cast<GeoPLengths *>(geo->getLengths()->getType().createFieldContainer()); if (geo->getIndices()!=NULL) { indices[i] = dynamic_cast<GeoIndices *>(geo->getIndices()->getType().createFieldContainer()); } else indices[i] = NULL; setupAttr( GeoPositions * , pnts , pni , getPositions ); setupAttr( GeoNormals * , normals , nni , getNormals ); setupAttr( GeoColors * , colors , cni , getColors ); setupAttr( GeoColors * , scolors , sni , getSecondaryColors ); setupAttr( GeoTexCoords * , tex , tni , getTexCoords ); setupAttr( GeoTexCoords * , tex1 , t1ni , getTexCoords1 ); setupAttr( GeoTexCoords * , tex2 , t2ni , getTexCoords2 ); setupAttr( GeoTexCoords * , tex3 , t3ni , getTexCoords3 ); } ind=0; it.setToBegin(); while (!it.isAtEnd()) { switch(it.getType()) { case GL_POINTS: case GL_LINES: case GL_LINE_STRIP: case GL_LINE_LOOP: case GL_TRIANGLE_FAN: case GL_TRIANGLE_STRIP: case GL_QUAD_STRIP: case GL_POLYGON: { int geoIndex=order[ind]/_max_polygons; types[geoIndex]->push_back(it.getType()); lens[geoIndex]->push_back(it.getLength()); addPoints( 0 , it.getLength() ); ++ind; } break; case GL_TRIANGLES: { UInt32 i=0; while(it.getLength()-i>=3) { i+=3; ++ind; } } break; case GL_QUADS: { UInt32 i=0; while(it.getLength()-i>=4) { i+=4; ++ind; } } break; default: SWARNING << "SplitGraphOp::splitLeave: encountered " << "unknown primitive type " << it.getType() << ", ignoring!" << std::endl; break; } ++it; } ind=0; it.setToBegin(); while (!it.isAtEnd()) { switch(it.getType()) { case GL_POINTS: case GL_LINES: case GL_LINE_STRIP: case GL_LINE_LOOP: case GL_TRIANGLE_FAN: case GL_TRIANGLE_STRIP: case GL_QUAD_STRIP: case GL_POLYGON: { ++ind; } break; case GL_TRIANGLES: { UInt32 i=0; int geoIndex; while(it.getLength()-i>=3) { geoIndex = order[ind]/_max_polygons; if (types[geoIndex]->size()>0 && types[geoIndex]->getValue(types[geoIndex]->size()-1) == GL_TRIANGLES) { int lind; if ((lind=lens[geoIndex]->size()-1)>=0) lens[geoIndex]->setValue(lens[geoIndex]->getValue(lind)+3, lind); else lens[geoIndex]->push_back(3); } else { types[geoIndex]->push_back(GL_TRIANGLES); lens[geoIndex]->push_back(3); } addPoints( i ,3 ); i+=3; ++ind; } } break; case GL_QUADS: { UInt32 i=0; while(it.getLength()-i>=4) { i+=4; ++ind; } } break; default: SWARNING << "SplitGraphOp::splitLeave: encountered " << "unknown primitive type " << it.getType() << ", ignoring!" << std::endl; break; } ++it; } ind=0; it.setToBegin(); while (!it.isAtEnd()) { switch(it.getType()) { case GL_POINTS: case GL_LINES: case GL_LINE_STRIP: case GL_LINE_LOOP: case GL_TRIANGLE_FAN: case GL_TRIANGLE_STRIP: case GL_QUAD_STRIP: case GL_POLYGON: { ++ind; } break; case GL_TRIANGLES: { UInt32 i=0; while(it.getLength()-i>=3) { i+=3; ++ind; } } break; case GL_QUADS: { UInt32 i=0; int geoIndex; while(it.getLength()-i>=4) { geoIndex = order[ind]/_max_polygons; if (types[geoIndex]->size()>0 && types[geoIndex]->getValue(types[geoIndex]->size()-1) == GL_QUADS) { int lind; if ((lind=lens[geoIndex]->size()-1)>=0) lens[geoIndex]->setValue(lens[geoIndex]->getValue(lind)+4, lind); else lens[geoIndex]->push_back(4); } else { types[geoIndex]->push_back(GL_QUADS); lens[geoIndex]->push_back(4); } addPoints( i , 4 ); i+=4; ++ind; } } break; default: SWARNING << "SplitGraphOp::splitLeave: encountered " << "unknown primitive type " << it.getType() << ", ignoring!" << std::endl; break; } ++it; } for (Int32 i=0; i<ngeos; i++) { geos[i]->setTypes(types[i]); geos[i]->setLengths(lens[i]); geos[i]->setPositions(pnts[i]); // Now close the open FCs if (indices[i]!=NULL) { geos[i]->setIndices(indices[i]); } if (normals[i]!=NULL) { geos[i]->setNormals(normals[i]); } if (colors[i]!=NULL) { geos[i]->setColors(colors[i]); } if (scolors[i]!=NULL) { geos[i]->setSecondaryColors(scolors[i]); } if (tex[i]!=NULL) { geos[i]->setTexCoords(tex[i]); } if (tex1[i]!=NULL) { geos[i]->setTexCoords1(tex1[i]); } if (tex2[i]!=NULL) { geos[i]->setTexCoords2(tex2[i]); } if (tex3[i]!=NULL) { geos[i]->setTexCoords3(tex3[i]); } if (node->getParent()!=NULL) { Node *n=Node::create(); n->setCore(geos[i]); split.push_back(n); } } for (Int32 i=0; i<ngeos; i++) { if (pni[i]) delete [] pni[i]; if (nni[i]) delete [] nni[i]; if (cni[i]) delete [] cni[i]; if (sni[i]) delete [] sni[i]; if (tni[i]) delete [] tni[i]; if (t1ni[i]) delete [] t1ni[i]; if (t2ni[i]) delete [] t2ni[i]; if (t3ni[i]) delete [] t3ni[i]; } delete [] pni; delete [] nni; delete [] cni; delete [] sni; delete [] tni; delete [] t1ni; delete [] t2ni; delete [] t3ni; return true; #endif }
int main() { //CAVITY FLOW auto dt = 0.0005; auto t = clock(); // GRID // Block2* grid = new Block2({0, 0, 0}, {1.0, 2.0, 0}, 10, 20); Block2* grid = new Block2({0, 0, 0}, {1.0, 1.0, 0}, 10, 10); // grid->adaptCriteria(); // CONST variables; sv->specific volume double sv1 = 0.1; double mu1 = 0.067; double g = 0; //-1; double sv2 = 1; double mu2 = 0.00067; double sigma = 1; // FIELD variables; grid->addVar({"p", "vor", "I"}); // initial and bc values; say this is rho*u then divide it by rho auto u = grid->getVar("u"); u->set(0.0); u->setBC("west", "val", 0); u->setBC("east", "val", 0); u->setBC("south", "val", 0); u->setBC("north", "val", 0); auto v = grid->getVar("v"); v->set(0.0); v->setBC("west", "val", 0); v->setBC("east", "val", 0); v->setBC("south", "val", 0); v->setBC("north", "val", 0); auto p = grid->getVar("p"); p->setBC("south", "val", 0); p->setBC("north", "val", 0); p->setBC("west", "val", 0); p->setBC("east", "val", 0); p->set(0.0); grid->levelHighBound[0] = 3; grid->levelHighBound[1] = 3; grid->levelHighBound[2] = 0; auto I = grid->getVar("I"); I->set(0.0); double pi = 4.0*atan(1); for (auto j = 0; j < 4; ++j) { for (auto i = 0; i < grid->listCell.size(); ++i) { auto x = grid->listCell[i]->getCoord(); // - Vec3(0.5, 0.5); double r = 0.125 - (x - Vec3(0.5, 0.5)).abs(); I->set(i, 1.0/(1.0 + exp(-2.0*80*(r)))); r = 0.125 - (x - Vec3(0.5, 0.625)).abs(); // I->set(i, max(0.0, min(1.0, I->get(i) + 1.0/(1.0 + exp(-2.0*80*(r)))))); } grid->solBasedAdapt2(grid->getError(I)); grid->adapt(); } auto gI = grid->valGrad(I); auto gp = grid->valGrad(p); // grid->addVec("st"); // auto stx = grid->getVar("stx"); // auto sty = grid->getVar("sty"); grid->writeVTK("rise"); // exit(1); auto vor = grid->getVar("vor"); // solver behavior u->solver = "Gauss"; u->itmax = 200; u->tol = 1e-4; v->solver = "Gauss"; v->itmax = 200; v->tol = 1e-4; p->itmax = 2000; p->tol = 1e-5; I->solver = "Gauss"; I->itmax = 100; I->tol = 1e-6; VecX<double> rho; VecX<double> mu; dt=0.0001; // Time control grid->setDt(dt); double time= 0; double endTime = 10.0; int filecnt = 0; int it = 0, writeInt = 1; auto adaptInt = 10; ofstream myfile; while (time < endTime) { cout << setiosflags(ios::scientific) << setprecision(2); cout << "------------- Processing TIME = "<< time << " ------------------"<<endl; auto vel = grid->getVel(); auto diverge = grid->valDiv(vel); cout << "+ div=("<<diverge.min()<<":" << diverge.max()<<") "; cout << " u=(" << vel.comp(0).min()<<":"<<vel.comp(0).max()<<")"; cout << " v=(" << vel.comp(1).min()<<":"<<vel.comp(1).max()<<")"<< endl; // cout << grid->valDiv(vel) << endl; // Interface move grid->lockBC(I); I->solve (grid->ddt(1.0) +grid->divRK2E(vel, 1.0) ); grid->unlockBC(); gI = grid->valGrad(I); // for (auto i = 0; i < gI.comp(0).size(); ++i) { // double mag = 1.0/gI.abs(); // gI[i][0] *= mag; // gI[i][1] *= mag; // gI[i][2] *= mag; // } // auto gK = grid->valDiv(gI); // double mingk = 100; double maxgk = -100; // for (auto i = 0; i < gK.size(); ++i) { // if (gK[i] > maxgk) maxgk = gK[i]; // if (gK[i] < mingk) mingk = gK[i]; // } // cout << " curv=(" << mingk<<":"<<maxgk<<")"<< endl; // cout << " nx=(" << gI.comp(0).min()<<":"<<gI.comp(0).max()<<")"<< endl; // cout << " ny=(" << gI.comp(1).min()<<":"<<gI.comp(1).max()<<")"<< endl; // for (auto i = 0; i < grid->listCell.size(); ++i) { // gI[i][0] *= gK[i]; // gI[i][1] *= gK[i]; //sigma*(sv1 + I->get(i) * (sv2 - sv1)); // } vor->set(grid->valGrad(v).comp(0) - grid->valGrad(u).comp(1)); auto gu = grid->valGrad(u); auto gv = grid->valGrad(v); // rho*d(u)/dt + rho*u*d(u)/dx = -dp/dx + mu*d2u/dx2 + rho*g + sigma*nx; // u : rhou & v : rhov for (auto i = 0; i < grid->listCell.size(); ++i) { rho[i] = 1.0/(sv1 + I->get(i) * (sv2 - sv1)); vel[i][0] *= rho[i]; vel[i][1] *= rho[i]; } mu = mu1 + I->data * (mu2 - mu1); grid->lockBC(u); u->solve( grid->ddt(rho) + grid->div(vel, 1, {0.5}) - grid->laplace(mu, {0.5}) - grid->source(0, sigma*gI.comp(0)) //*(sv1 + I->data *(sv2 - sv1))) // gradX is not defined; ); grid->unlockBC(); grid->lockBC(v); v->solve( grid->ddt(rho) + grid->div(vel, 1, {0.5}) - grid->laplace(mu, {0.5}) - grid->source(0, sigma*gI.comp(1) - rho*g) //*(sv1 + I->data *(sv2 - sv1))) ); grid->unlockBC(); // grid->solBasedAdapt(vor->data); // grid->solBasedAdapt(gp); if ((it == 1) || (it % adaptInt) == 0) { //grid->solBasedAdapt(gu, 1.0); // grid->solBasedAdapt(grid->valGrad(vor), 0.4); grid->solBasedAdapt2(grid->getError(I)); grid->solBasedAdapt(vor->data, 0.9); // for (auto i = 0; i < grid->listCell.size(); ++i) // for (auto j = 0; j< 3; ++j) // grid->listCell[i]->checkNgbrLevel(j); grid->adapt(); } // if (periodic) grid->adapt(); auto velstar = grid->getVel(); auto vsdiv = grid->valDiv(velstar); cout << "+ div=("<<vsdiv.min()<<":" << vsdiv.max()<<") "<<endl; //cout << grid->valDiv(velstar) << endl; //cin.ignore().get(); // d(rhou)/dt = -dp/dx // div(rhou(n+1))/dt-div(u(n))/dt = -d2p/dx2 // dt/den*d2p/dx2 = grid->lockBC(p); p->solve(grid->laplace(dt*(sv1 + I->data *(sv2 - sv1))) - grid->source(0, grid->valDiv(velstar)) ); grid->unlockBC(); gp = grid->valGrad(p); for (auto i = 0; i < grid->listCell.size(); ++i) { gp[i][0] *= dt*(sv1 + I->get(i) *(sv2 - sv1) ); gp[i][1] *= dt*(sv1 + I->get(i) *(sv2 - sv1) ); } //cout << gp <<endl; u->set(velstar.comp(0)-gp.comp(0)); // v->set(velstar.comp(1)-gp.comp(1)); // //grid->correctVel(velstar, dt/rho1); grid->setDt(dt); time += dt; //grid->solBasedAdapt(vor->data); // grid->solBasedAdapt(gv); //grid->refine2(); if (( it++ % writeInt) == 0) { //grid->writeFace("face"+std::to_string(filecnt)+".vtk"); std::string flname="rise"+std::to_string(filecnt++)+".vtk"; myfile.open(flname); myfile << grid << endl; myfile.close(); } cout << "---------------------------------------------------"<<endl; //cin.ignore().get(); } delete(grid); return 0; }
typename graph_traits<Graph>::vertex_descriptor sloan_start_end_vertices(Graph& G, typename graph_traits<Graph>::vertex_descriptor &s, ColorMap color, DegreeMap degree) { typedef typename property_traits<DegreeMap>::value_type Degree; typedef typename graph_traits<Graph>::vertex_descriptor Vertex; typedef typename std::vector< typename graph_traits<Graph>::vertices_size_type>::iterator vec_iter; typedef typename graph_traits<Graph>::vertices_size_type size_type; typedef typename property_map<Graph, vertex_index_t>::const_type VertexID; s = *(vertices(G).first); Vertex e = s; Vertex i; unsigned my_degree = get(degree, s ); unsigned dummy, h_i, h_s, w_i, w_e; bool new_start = true; unsigned maximum_degree = 0; //Creating a std-vector for storing the distance from the start vertex in dist std::vector<typename graph_traits<Graph>::vertices_size_type> dist(num_vertices(G), 0); //Wrap a property_map_iterator around the std::iterator boost::iterator_property_map<vec_iter, VertexID, size_type, size_type&> dist_pmap(dist.begin(), get(vertex_index, G)); //Creating a property_map for the indices of a vertex typename property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, G); //Creating a priority queue typedef indirect_cmp<DegreeMap, std::greater<Degree> > Compare; Compare comp(degree); std::priority_queue<Vertex, std::vector<Vertex>, Compare> degree_queue(comp); //step 1 //Scan for the vertex with the smallest degree and the maximum degree typename graph_traits<Graph>::vertex_iterator ui, ui_end; for (tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) { dummy = get(degree, *ui); if(dummy < my_degree) { my_degree = dummy; s = *ui; } if(dummy > maximum_degree) { maximum_degree = dummy; } } //end 1 do{ new_start = false; //Setting the loop repetition status to false //step 2 //initialize the the disance std-vector with 0 for(typename std::vector<typename graph_traits<Graph>::vertices_size_type>::iterator iter = dist.begin(); iter != dist.end(); ++iter) *iter = 0; //generating the RLS (rooted level structure) breadth_first_search (G, s, visitor ( make_bfs_visitor(record_distances(dist_pmap, on_tree_edge() ) ) ) ); //end 2 //step 3 //calculating the depth of the RLS h_s = RLS_depth(dist); //step 4 //pushing one node of each degree in an ascending manner into degree_queue std::vector<bool> shrink_trace(maximum_degree, false); for (tie(ui, ui_end) = vertices(G); ui != ui_end; ++ui) { dummy = get(degree, *ui); if( (dist[index_map[*ui]] == h_s ) && ( !shrink_trace[ dummy ] ) ) { degree_queue.push(*ui); shrink_trace[ dummy ] = true; } } //end 3 & 4 // step 5 // Initializing w w_e = (std::numeric_limits<unsigned>::max)(); //end 5 //step 6 //Testing for termination while( !degree_queue.empty() ) { i = degree_queue.top(); //getting the node with the lowest degree from the degree queue degree_queue.pop(); //ereasing the node with the lowest degree from the degree queue //generating a RLS for(typename std::vector<typename graph_traits<Graph>::vertices_size_type>::iterator iter = dist.begin(); iter != dist.end(); ++iter) *iter = 0; breadth_first_search (G, i, boost::visitor ( make_bfs_visitor(record_distances(dist_pmap, on_tree_edge() ) ) ) ); //Calculating depth and width of the rooted level h_i = RLS_depth(dist); w_i = RLS_max_width(dist, h_i); //Testing for termination if( (h_i > h_s) && (w_i < w_e) ) { h_s = h_i; s = i; while(!degree_queue.empty()) degree_queue.pop(); new_start = true; } else if(w_i < w_e) { w_e = w_i; e = i; } } //end 6 }while(new_start); return e; }
noit_skiplist_node *noit_skiplist_insert_compare(noit_skiplist *sl, const void *data, noit_skiplist_comparator_t comp) { noit_skiplist_node *m, *p, *tmp, *ret = NULL, **stack; int nh=1, ch, stacki; if(!sl->top) { sl->height = 1; sl->top = sl->bottom = calloc(1, sizeof(noit_skiplist_node)); sl->top->sl = sl; } if(sl->preheight) { while(nh < sl->preheight && get_b_rand()) nh++; } else { while(nh <= sl->height && get_b_rand()) nh++; } /* Now we have the new height at which we wish to insert our new node */ /* Let us make sure that our tree is a least that tall (grow if necessary)*/ for(;sl->height<nh;sl->height++) { sl->top->up = (noit_skiplist_node *)calloc(1, sizeof(noit_skiplist_node)); sl->top->up->down = sl->top; sl->top = sl->top->up; sl->top->sl = sl; } ch = sl->height; /* Find the node (or node after which we would insert) */ /* Keep a stack to pop back through for insertion */ m = sl->top; stack = (noit_skiplist_node **)alloca(sizeof(noit_skiplist_node *)*(nh)); stacki=0; while(m) { int compared=-1; if(m->next) compared=comp(data, m->next->data); if(compared == 0) { return 0; } if(compared<0) { if(ch<=nh) { /* push on stack */ stack[stacki++] = m; } m = m->down; ch--; } else { m = m->next; } } /* Pop the stack and insert nodes */ p = NULL; for(;stacki>0;stacki--) { m = stack[stacki-1]; tmp = calloc(1, sizeof(*tmp)); tmp->next = m->next; if(m->next) m->next->prev=tmp; tmp->prev = m; tmp->down = p; if(p) p->up=tmp; tmp->data = (void *)data; tmp->sl = sl; m->next = tmp; /* This sets ret to the bottom-most node we are inserting */ if(!p) ret=tmp; p = tmp; } if(sl->index != NULL) { /* this is a external insertion, we must insert into each index as well */ noit_skiplist_node *p, *ni, *li; assert(ret); li=ret; for(p = noit_skiplist_getlist(sl->index); p; noit_skiplist_next(sl->index, &p)) { ni = noit_skiplist_insert((noit_skiplist *)p->data, ret->data); assert(ni); li->nextindex = ni; ni->previndex = li; li = ni; } } sl->size++; return ret; }
void dsplysale() { system("cls"); p("\n\tDAILY SALES"); comp(); getch(); system("cls"); start(); }
bool operator()( typename call_traits<Value>::param_type x, typename call_traits<Value>::param_type y)const { return comp(key(x),key(y)); }
inline bool operator()(const node_type& x, const node_type& y) const { return comp(x.value(), y.value()); }
void user() //user function definition { do { cout<<endl; if(p=='2') { textcolor(RED); clreol(); cout<<" PLAYER 1's MOVE"<<endl; } cout<<endl; cout<<" ENTER THE COORDINATES WHERE YOU WANT TO PUT YOUR X "<<endl; cout<<" x="; cin>>x; if(x==-1) menu(); cout<<endl; cout<<" y="; cin>>y; if((x<0)||(x>2)||(y<0)||(y>2)) //check for valid coordinates { cout<<endl; textcolor(BLUE); clreol(); cout<<" *.ENTER THE CORRECT COORDINATES!!!!"<<endl<<endl; } }while((x<0)||(x>2)||(y<0)||(y>2)); if(tic[x][y]==' ') //check for vacant space at entered coordinates { tic[x][y]='X'; cout<<endl<<endl; ++sum; textbackground(GREEN); textcolor(WHITE); clrscr(); display(); //calling function display } else { textcolor(BLUE); clreol(); cout<<"\t\tTHIS POSITION IS ALREADY FILLED."<<endl; textcolor(BLUE); clreol(); cout<<"\t\tCHOOSE SOME OTHER COORDINATES"<<endl; user(); //user function call } d=check(); //check function call if(d==0) { if(sum==9) draw(); else if(p=='1') comp(); //comp function call else player2(); } else { cout<<endl; player1win(); } getch(); menu(); }
int main(int argc, const char * argv[]) { setbuf (stdout, NULL); #if TARGET_OS_MAC { thread_extended_policy_data_t theFixedPolicy; theFixedPolicy.timeshare = false; // set to true for a non-fixed thread thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_EXTENDED_POLICY, (thread_policy_t)&theFixedPolicy, THREAD_EXTENDED_POLICY_COUNT); // We keep a reference to the spawning thread's priority around (initialized in the constructor), // and set the importance of the child thread relative to the spawning thread's priority. thread_precedence_policy_data_t thePrecedencePolicy; thePrecedencePolicy.importance = 63 - 36; thread_policy_set(pthread_mach_thread_np(pthread_self()), THREAD_PRECEDENCE_POLICY, (thread_policy_t)&thePrecedencePolicy, THREAD_PRECEDENCE_POLICY_COUNT); } #endif // These are the variables that are set up from the input parsing char* srcFilePath = NULL; char* destFilePath = NULL; char* auPresetFile = NULL; bool shortMemoryProfile = false; OSType manu, subType, type = 0; int userSetFrames = -1; for (int i = 1; i < argc; ++i) { if (strcmp (argv[i], "-au") == 0) { if ( (i + 3) < argc ) { StrToOSType (argv[i + 1], type); StrToOSType (argv[i + 2], subType); StrToOSType (argv[i + 3], manu); i += 3; } else { printf ("Which Audio Unit:\n%s", usageStr); exit(1); } } else if (strcmp (argv[i], "-i") == 0) { srcFilePath = const_cast<char*>(argv[++i]); } else if (strcmp (argv[i], "-o") == 0) { destFilePath = const_cast<char*>(argv[++i]); } else if (strcmp (argv[i], "-p") == 0) { auPresetFile = const_cast<char*>(argv[++i]); } else if (strcmp (argv[i], "-m") == 0) { shortMemoryProfile = true; } else if (strcmp (argv[i], "-f") == 0) { sscanf(argv[++i], "%d", &userSetFrames); } else { printf ("%s\n", usageStr); exit(1); } } if (!type || !srcFilePath) { printf ("%s\n", usageStr); exit(1); } if (!destFilePath) { if (!shortMemoryProfile) { printf ("%s\n", usageStr); exit(1); } } // delete pre-existing output file if (!shortMemoryProfile) { FSRef destFSRef; if (FSPathMakeRef((UInt8 *)destFilePath, &destFSRef, NULL) == noErr) { // output file exists - delete it if (FSDeleteObject(&destFSRef)) { printf ("Cannot Delete Output File\n"); exit(1); } } } CAComponentDescription desc(type, subType, manu); CFPropertyListRef presetDict = ReadPresetFromPresetFile(auPresetFile); // the num of frames to use when processing the file with the Render call UInt32 maxFramesToUse = shortMemoryProfile ? 512 : 32768; // not set from command line if (userSetFrames > 0) { maxFramesToUse = userSetFrames; } // in some settings (for instance a delay with 100% feedback) tail time is essentially infinite // so you should safeguard the final OL render stage (post process) which is aimed at pulling the tail through // if you want to bypass this completely, just set this to zero. Float64 maxTailTimeSecs = 10.; #pragma mark - #pragma mark __ The driving code #pragma mark - try { CAComponent comp(desc); // CAAUProcessor's constructor throws... so make sure the component is valid if (comp.IsValid() == false) { printf ("Can't Find Component\n"); desc.Print(); exit(1); } CAAUProcessor processor(comp); processor.AU().Print(); CAAudioFile srcFile; CAAudioFile destFile; srcFile.Open(srcFilePath); CAStreamBasicDescription procFormat (srcFile.GetFileDataFormat()); procFormat.SetCanonical (srcFile.GetFileDataFormat().NumberChannels(), false); printf ("Processing Format:\n\t"); procFormat.Print(); if (!shortMemoryProfile) { FSRef parentDir; CFStringRef filename; PosixPathToParentFSRefAndName(destFilePath, parentDir, filename); destFile.CreateNew (parentDir, filename, 'AIFF', srcFile.GetFileDataFormat()); destFile.SetClientFormat (procFormat); } srcFile.SetClientFormat (procFormat); AUOutputBL outputList(procFormat); ReadBuffer* readBuf = NULL; #if !CAAF_USE_EXTAUDIOFILE UInt64 numInputSamples = srcFile.GetNumberPackets(); #else UInt64 numInputSamples = srcFile.GetNumberFrames(); #endif if (shortMemoryProfile) { readBuf = new ReadBuffer; readBuf->readData = new AUOutputBL(procFormat); readBuf->readFrames = 0; UInt32 numFrames = UInt32(procFormat.mSampleRate / 2); readBuf->readData->Allocate (numFrames); // half a second of audio data readBuf->readData->Prepare(); // half a second of audio data // read 1/2 second of audio into this read buffer srcFile.Read (numFrames, readBuf->readData->ABL()); sInputCallback.inputProc = MemoryInputCallback; sInputCallback.inputProcRefCon = readBuf; numInputSamples = numFrames; } else { if (desc.IsFConv()) { maxFramesToUse = userSetFrames == -1 ? 512 : maxFramesToUse; // some format converter's can call you several times in small granularities // so you can't use a large buffer to render or you won't return all of the input data // this also lessens the final difference between what you should get and what you do // converter units *really* should have a version that are offline AU's to // handle this for you. sInputCallback.inputProc = FConvInputCallback; } else sInputCallback.inputProc = InputCallback; sInputCallback.inputProcRefCon = &srcFile; } OSStatus result; require_noerr (result = processor.EstablishInputCallback (sInputCallback), home); require_noerr (result = processor.SetMaxFramesPerRender (maxFramesToUse), home); processor.SetMaxTailTime (maxTailTimeSecs); require_noerr (result = processor.Initialize (procFormat, numInputSamples), home); if (presetDict) { require_noerr (result = processor.SetAUPreset (presetDict), home); CFRelease (presetDict); } // this does ALL of the preflighting.. could be specialise for an OfflineAU type // to do this piecemeal and do a progress bar by using the OfflineAUPreflight method require_noerr (result = processor.Preflight (), home); bool isDone; isDone = false; bool needsPostProcessing; bool isSilence; UInt32 numFrames; numFrames = processor.MaxFramesPerRender(); #if CA_AU_PROFILE_TIME sReadTime = 0; sRenderTime = 0; #endif PRINT_MARKS(); // this is the render loop while (!isDone) { #if CA_AU_PROFILE_TIME UInt64 now = CAHostTimeBase::GetTheCurrentTime(); #endif outputList.Prepare(); // have to do this every time... require_noerr (result = processor.Render (outputList.ABL(), numFrames, isSilence, &isDone, &needsPostProcessing), home); #if CA_AU_PROFILE_TIME sRenderTime += (CAHostTimeBase::GetTheCurrentTime() - now); #endif if (!shortMemoryProfile) PRINT_PROGRESS(processor.GetOLPercentComplete()); else PRINT_PROGRESS(((processor.SampleTime() / numInputSamples) * 100.)); if (numFrames && !shortMemoryProfile) destFile.Write (numFrames, outputList.ABL()); } // this is the postprocessing if needed if (!shortMemoryProfile && needsPostProcessing) { isDone = false; numFrames = processor.MaxFramesPerRender(); while (!isDone) { outputList.Prepare(); // have to do this every time... #if CA_AU_PROFILE_TIME UInt64 now = CAHostTimeBase::GetTheCurrentTime(); #endif require_noerr (result = processor.PostProcess (outputList.ABL(), numFrames, isSilence, isDone), home); #if CA_AU_PROFILE_TIME sRenderTime += (CAHostTimeBase::GetTheCurrentTime() - now); #endif PRINT_PROGRESS(processor.GetOLPercentComplete()); if (numFrames && !shortMemoryProfile) destFile.Write (numFrames, outputList.ABL()); } } printf ("\n"); home: if (result) { printf ("Exit with bad result:%ld\n", result); exit(result); } if (readBuf) { delete readBuf->readData; delete readBuf; } #if CA_AU_PROFILE_TIME if (!shortMemoryProfile) { // this flushes any remaing data to be written to the disk. // the source file is closed in its destructor of course destFile.Close(); // open the file again, to get stats about it for profiling destFile.Open(destFilePath); } SInt64 numWritten; if (shortMemoryProfile) numWritten = 0; else { #if !CAAF_USE_EXTAUDIOFILE numWritten = destFile.GetNumberPackets(); #else numWritten = destFile.GetNumberFrames(); #endif } printf ("Read File Time:%.2f secs for %lld packets (%.1f secs), wrote %lld packets\n", (CAHostTimeBase::ConvertToNanos (sReadTime) / 1.0e9), numInputSamples, (numInputSamples / procFormat.mSampleRate), numWritten); if (!shortMemoryProfile) { #if !CAAF_USE_EXTAUDIOFILE UInt64 numOutputSamples = destFile.GetNumberPackets(); #else UInt64 numOutputSamples = destFile.GetNumberFrames(); #endif if (numOutputSamples == numInputSamples) { printf ("\tWrote the same number of packets as read\n"); } else { bool expectationMet = !desc.IsOffline(); // we don't have any expectations for offline AU's if (processor.LatencySampleCount() || processor.TailSampleCount()) { if (numOutputSamples - numInputSamples == processor.TailSampleCount()) expectationMet = true; if (expectationMet) printf ("Correctly wrote \'Read Size + Tail\'. "); printf ("AU reports (samples): %ld latency, %ld tail\n", processor.LatencySampleCount(), processor.TailSampleCount()); } if (expectationMet == false) { if (numOutputSamples > numInputSamples) { printf ("\tWrote %lld packets (%.2f secs) more than read\n", (numOutputSamples - numInputSamples), ((numOutputSamples - numInputSamples) / procFormat.mSampleRate)); } else { printf ("\tRead %lld packets (%.2f secs) more than wrote\n", (numInputSamples - numOutputSamples), ((numInputSamples - numOutputSamples) / procFormat.mSampleRate)); } } } } Float64 renderTimeSecs = CAHostTimeBase::ConvertToNanos (sRenderTime - sReadTime) / 1.0e9; printf ("Total Render Time:%.2f secs, using render slice size of %ld frames\n", renderTimeSecs, maxFramesToUse); Float64 cpuUsage; if (shortMemoryProfile) cpuUsage = (renderTimeSecs / 0.5) * 100.; else cpuUsage = (renderTimeSecs / (numInputSamples / procFormat.mSampleRate)) * 100.; printf ("CPU Usage for Render Time:%.2f%%\n", cpuUsage); CFStringRef str = comp.GetCompName(); UInt32 compNameLen = CFStringGetLength (str); CFStringRef presetName = NULL; if (auPresetFile) { CFPropertyListRef dict; if (processor.AU().GetAUPreset (dict) == noErr) { presetName = (CFStringRef)CFDictionaryGetValue((CFDictionaryRef)dict, CFSTR("name")); CFRelease (dict); } } UInt32 presetLen = presetName ? CFStringGetLength(presetName) : 0; char* cstr = (char*)malloc (compNameLen + presetLen + 2 + 1); CFStringGetCString (str, cstr, (CFStringGetLength (str) + 1), kCFStringEncodingASCII); if (presetName) { cstr[compNameLen] = ':'; cstr[compNameLen+1] = ':'; CFStringGetCString (presetName, cstr + compNameLen + 2, (CFStringGetLength (presetName) + 1), kCFStringEncodingASCII); } PerfResult("AudioUnitProcess", EndianU32_NtoB(comp.Desc().componentSubType), cstr, cpuUsage, "%realtime"); free (cstr); #endif } catch (CAXException &e) { char buf[256]; printf("Error: %s (%s)\n", e.mOperation, e.FormatError(buf)); exit(1); } catch (...) { printf("An unknown error occurred\n"); exit(1); } return 0; }
OutputIterator sloan_ordering(Graph& g, typename graph_traits<Graph>::vertex_descriptor s, typename graph_traits<Graph>::vertex_descriptor e, OutputIterator permutation, ColorMap color, DegreeMap degree, PriorityMap priority, Weight W1, Weight W2) { //typedef typename property_traits<DegreeMap>::value_type Degree; typedef typename property_traits<PriorityMap>::value_type Degree; typedef typename property_traits<ColorMap>::value_type ColorValue; typedef color_traits<ColorValue> Color; typedef typename graph_traits<Graph>::vertex_descriptor Vertex; typedef typename std::vector<typename graph_traits<Graph>::vertices_size_type>::iterator vec_iter; typedef typename graph_traits<Graph>::vertices_size_type size_type; typedef typename property_map<Graph, vertex_index_t>::const_type VertexID; //Creating a std-vector for storing the distance from the end vertex in it typename std::vector<typename graph_traits<Graph>::vertices_size_type> dist(num_vertices(g), 0); //Wrap a property_map_iterator around the std::iterator boost::iterator_property_map<vec_iter, VertexID, size_type, size_type&> dist_pmap(dist.begin(), get(vertex_index, g)); breadth_first_search (g, e, visitor ( make_bfs_visitor(record_distances(dist_pmap, on_tree_edge() ) ) ) ); //Creating a property_map for the indices of a vertex typename property_map<Graph, vertex_index_t>::type index_map = get(vertex_index, g); //Sets the color and priority to their initial status unsigned cdeg; typename graph_traits<Graph>::vertex_iterator ui, ui_end; for (tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) { put(color, *ui, Color::white()); cdeg=get(degree, *ui)+1; put(priority, *ui, W1*dist[index_map[*ui]]-W2*cdeg ); } //Priority list typedef indirect_cmp<PriorityMap, std::greater<Degree> > Compare; Compare comp(priority); std::list<Vertex> priority_list; //Some more declarations typename graph_traits<Graph>::out_edge_iterator ei, ei_end, ei2, ei2_end; Vertex u, v, w; put(color, s, Color::green()); //Sets the color of the starting vertex to gray priority_list.push_front(s); //Puts s into the priority_list while ( !priority_list.empty() ) { priority_list.sort(comp); //Orders the elements in the priority list in an ascending manner u = priority_list.front(); //Accesses the last element in the priority list priority_list.pop_front(); //Removes the last element in the priority list if(get(color, u) == Color::green() ) { //for-loop over all out-edges of vertex u for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { v = target(*ei, g); put( priority, v, get(priority, v) + W2 ); //updates the priority if (get(color, v) == Color::white() ) //test if the vertex is inactive { put(color, v, Color::green() ); //giving the vertex a preactive status priority_list.push_front(v); //writing the vertex in the priority_queue } } } //Here starts step 8 *permutation++ = u; //Puts u to the first position in the permutation-vector put(color, u, Color::black() ); //Gives u an inactive status //for loop over all the adjacent vertices of u for (tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) { v = target(*ei, g); if (get(color, v) == Color::green() ) { //tests if the vertex is inactive put(color, v, Color::red() ); //giving the vertex an active status put(priority, v, get(priority, v)+W2); //updates the priority //for loop over alll adjacent vertices of v for (tie(ei2, ei2_end) = out_edges(v, g); ei2 != ei2_end; ++ei2) { w = target(*ei2, g); if(get(color, w) != Color::black() ) { //tests if vertex is postactive put(priority, w, get(priority, w)+W2); //updates the priority if(get(color, w) == Color::white() ){ put(color, w, Color::green() ); // gives the vertex a preactive status priority_list.push_front(w); // puts the vertex into the priority queue } //end if } //end if } //end for } //end if } //end for } //end while return permutation; }
TR_LocalAnalysisInfo::TR_LocalAnalysisInfo(TR::Compilation *c, bool t) : _compilation(c), _trace(t), _trMemory(c->trMemory()) { _numNodes = -1; #if 0 // somehow stops PRE from happening // We are going to increment visit count for every tree so can reach max // for big methods quickly. Perhaps can improve containsCall() in the future. comp()->resetVisitCounts(0); #endif if (comp()->getVisitCount() > HIGH_VISIT_COUNT) { _compilation->resetVisitCounts(1); dumpOptDetails(comp(), "\nResetting visit counts for this method before LocalAnalysisInfo\n"); } TR::CFG *cfg = comp()->getFlowGraph(); _numBlocks = cfg->getNextNodeNumber(); TR_ASSERT(_numBlocks > 0, "Local analysis, node numbers not assigned"); // Allocate information on the stack. It is the responsibility of the user // of this class to determine the life of the information by using jitStackMark // and jitStackRelease. // //_blocksInfo = (TR::Block **) trMemory()->allocateStackMemory(_numBlocks*sizeof(TR::Block *)); //memset(_blocksInfo, 0, _numBlocks*sizeof(TR::Block *)); TR::TreeTop *currentTree = comp()->getStartTree(); // Only do this if not done before; typically this would be done in the // first call to this method through LocalTransparency and would NOT // need to be re-done by LocalAnticipatability. // if (_numNodes < 0) { _optimizer = comp()->getOptimizer(); int32_t numBuckets; int32_t numNodes = comp()->getNodeCount(); if (numNodes < 10) numBuckets = 1; else if (numNodes < 100) numBuckets = 7; else if (numNodes < 500) numBuckets = 31; else if (numNodes < 3000) numBuckets = 127; else if (numNodes < 6000) numBuckets = 511; else numBuckets = 1023; // Allocate hash table for matching expressions // HashTable hashTable(numBuckets, comp()); _hashTable = &hashTable; // Null checks are handled differently as the criterion for // commoning a null check is different than that used for // other nodes; for a null check, the null check reference is // important (and not the actual indirect access itself) // _numNullChecks = 0; while (currentTree) { if (currentTree->getNode()->getOpCodeValue() == TR::NULLCHK) //////if (currentTree->getNode()->getOpCode().isNullCheck()) _numNullChecks++; currentTree = currentTree->getNextTreeTop(); } if (_numNullChecks == 0) _nullCheckNodesAsArray = NULL; else { _nullCheckNodesAsArray = (TR::Node**)trMemory()->allocateStackMemory(_numNullChecks*sizeof(TR::Node*)); memset(_nullCheckNodesAsArray, 0, _numNullChecks*sizeof(TR::Node*)); } currentTree = comp()->getStartTree(); int32_t symRefCount = comp()->getSymRefCount(); _checkSymbolReferences = new (trStackMemory()) TR_BitVector(symRefCount, trMemory(), stackAlloc); _numNodes = 1; _numNullChecks = 0; // This loop counts all the nodes that are going to take part in PRE. // This is a computation intensive loop as we check if the node that // is syntactically equivalent to a given node has been seen before // and if so we use the local index of the original node (that // is syntactically equivalent to the given node). Could be improved // in complexity with value numbering at some stage. // _visitCount = comp()->incVisitCount(); while (currentTree) { TR::Node *firstNodeInTree = currentTree->getNode(); TR::ILOpCode *opCode = &firstNodeInTree->getOpCode(); if (((firstNodeInTree->getOpCodeValue() == TR::treetop) || (comp()->useAnchors() && firstNodeInTree->getOpCode().isAnchor())) && (firstNodeInTree->getFirstChild()->getOpCode().isStore())) { firstNodeInTree->setLocalIndex(-1); if (comp()->useAnchors() && firstNodeInTree->getOpCode().isAnchor()) firstNodeInTree->getSecondChild()->setLocalIndex(-1); firstNodeInTree = firstNodeInTree->getFirstChild(); opCode = &firstNodeInTree->getOpCode(); } // This call finds nodes with opcodes that are supported by PRE // in this subtree; this accounts for all opcodes other than stores/checks // which are handled later on below // bool firstNodeInTreeHasCallsInStoreLhs = false; countSupportedNodes(firstNodeInTree, NULL, firstNodeInTreeHasCallsInStoreLhs); if ((opCode->isStore() && !firstNodeInTree->getSymbolReference()->getSymbol()->isAutoOrParm()) || opCode->isCheck()) { int32_t oldExpressionOnRhs = hasOldExpressionOnRhs(firstNodeInTree); // // Return value 0 denotes that the node contains some sub-expression // that cannot participate in PRE; e.g. a call or a new // // Return value -1 denotes that the node can participate in PRE // but did not match with any existing expression seen so far // // Any other return value (should be positive always) denotes that // the node can participate in PRE and has been matched with a seen // expression having local index == return value // if (oldExpressionOnRhs == -1) { if (trace()) { traceMsg(comp(), "\nExpression #%d is : \n", _numNodes); comp()->getDebug()->print(comp()->getOutFile(), firstNodeInTree, 6, true); } firstNodeInTree->setLocalIndex(_numNodes++); } else firstNodeInTree->setLocalIndex(oldExpressionOnRhs); if (opCode->isCheck() && (firstNodeInTree->getFirstChild()->getOpCode().isStore() && !firstNodeInTree->getFirstChild()->getSymbolReference()->getSymbol()->isAutoOrParm())) { int oldExpressionOnRhs = hasOldExpressionOnRhs(firstNodeInTree->getFirstChild()); if (oldExpressionOnRhs == -1) { if (trace()) { traceMsg(comp(), "\nExpression #%d is : \n", _numNodes); comp()->getDebug()->print(comp()->getOutFile(), firstNodeInTree->getFirstChild(), 6, true); } firstNodeInTree->getFirstChild()->setLocalIndex(_numNodes++); } else firstNodeInTree->getFirstChild()->setLocalIndex(oldExpressionOnRhs); } } else firstNodeInTree->setLocalIndex(-1); currentTree = currentTree->getNextTreeTop(); } } _supportedNodesAsArray = (TR::Node**)trMemory()->allocateStackMemory(_numNodes*sizeof(TR::Node*)); memset(_supportedNodesAsArray, 0, _numNodes*sizeof(TR::Node*)); _checkExpressions = new (trStackMemory()) TR_BitVector(_numNodes, trMemory(), stackAlloc); //_checkExpressions.init(_numNodes, trMemory(), stackAlloc); // This loop goes through the trees and collects the nodes // that would take part in PRE. Each node has its local index set to // the bit position that it occupies in the bit vector analyses. // currentTree = comp()->getStartTree(); _visitCount = comp()->incVisitCount(); while (currentTree) { TR::Node *firstNodeInTree = currentTree->getNode(); TR::ILOpCode *opCode = &firstNodeInTree->getOpCode(); if (((firstNodeInTree->getOpCodeValue() == TR::treetop) || (comp()->useAnchors() && firstNodeInTree->getOpCode().isAnchor())) && (firstNodeInTree->getFirstChild()->getOpCode().isStore())) { firstNodeInTree = firstNodeInTree->getFirstChild(); opCode = &firstNodeInTree->getOpCode(); } collectSupportedNodes(firstNodeInTree, NULL); if ((opCode->isStore() && !firstNodeInTree->getSymbolReference()->getSymbol()->isAutoOrParm()) || opCode->isCheck()) { if (opCode->isCheck()) { _checkSymbolReferences->set(firstNodeInTree->getSymbolReference()->getReferenceNumber()); _checkExpressions->set(firstNodeInTree->getLocalIndex()); } if (!_supportedNodesAsArray[firstNodeInTree->getLocalIndex()]) _supportedNodesAsArray[firstNodeInTree->getLocalIndex()] = firstNodeInTree; if (opCode->isCheck() && firstNodeInTree->getFirstChild()->getOpCode().isStore() && !firstNodeInTree->getFirstChild()->getSymbolReference()->getSymbol()->isAutoOrParm() && !_supportedNodesAsArray[firstNodeInTree->getFirstChild()->getLocalIndex()]) _supportedNodesAsArray[firstNodeInTree->getFirstChild()->getLocalIndex()] = firstNodeInTree->getFirstChild(); } currentTree = currentTree->getNextTreeTop(); } //initialize(toBlock(cfg->getStart())); }
Complexity Complexity::operator / (Complexity& t){ Complexity res(*this); t.set(t.getF(), -t.getS()); Complexity comp(t); res*t;//TODO }
TR::Register *TR::AMD64SystemLinkage::buildDirectDispatch( TR::Node *callNode, bool spillFPRegs) { TR::SymbolReference *methodSymRef = callNode->getSymbolReference(); TR::MethodSymbol *methodSymbol = methodSymRef->getSymbol()->castToMethodSymbol(); TR::Register *returnReg; // Allocate adequate register dependencies. // // pre = number of argument registers // post = number of volatile + return register // uint32_t pre = getProperties().getNumIntegerArgumentRegisters() + getProperties().getNumFloatArgumentRegisters(); uint32_t post = getProperties().getNumVolatileRegisters() + (callNode->getDataType() == TR::NoType ? 0 : 1); #if defined (PYTHON) && 0 // Treat all preserved GP regs as volatile until register map support available. // post += getProperties().getNumberOfPreservedGPRegisters(); #endif TR::RegisterDependencyConditions *preDeps = generateRegisterDependencyConditions(pre, 0, cg()); TR::RegisterDependencyConditions *postDeps = generateRegisterDependencyConditions(0, post, cg()); // Evaluate outgoing arguments on the system stack and build pre-conditions. // int32_t memoryArgSize = buildArgs(callNode, preDeps); // Build post-conditions. // returnReg = buildVolatileAndReturnDependencies(callNode, postDeps); postDeps->stopAddingPostConditions(); // Find the second scratch register in the post dependency list. // TR::Register *scratchReg = NULL; TR::RealRegister::RegNum scratchRegIndex = getProperties().getIntegerScratchRegister(1); for (int32_t i=0; i<post; i++) { if (postDeps->getPostConditions()->getRegisterDependency(i)->getRealRegister() == scratchRegIndex) { scratchReg = postDeps->getPostConditions()->getRegisterDependency(i)->getRegister(); break; } } #if defined(PYTHON) && 0 // For Python, store the instruction that contains the GC map at this site into // the frame object. // TR::SymbolReference *frameObjectSymRef = comp()->getSymRefTab()->findOrCreateAutoSymbol(comp()->getMethodSymbol(), 0, TR::Address, true, false, true); TR::Register *frameObjectRegister = cg()->allocateRegister(); generateRegMemInstruction( L8RegMem, callNode, frameObjectRegister, generateX86MemoryReference(frameObjectSymRef, cg()), cg()); TR::RealRegister *espReal = cg()->machine()->getRealRegister(TR::RealRegister::esp); TR::Register *gcMapPCRegister = cg()->allocateRegister(); generateRegMemInstruction( LEA8RegMem, callNode, gcMapPCRegister, generateX86MemoryReference(espReal, -8, cg()), cg()); // Use "volatile" registers across the call. Once proper register map support // is implemented, r14 and r15 will no longer be volatile and a different pair // should be chosen. // TR::RegisterDependencyConditions *gcMapDeps = generateRegisterDependencyConditions(0, 2, cg()); gcMapDeps->addPostCondition(frameObjectRegister, TR::RealRegister::r14, cg()); gcMapDeps->addPostCondition(gcMapPCRegister, TR::RealRegister::r15, cg()); gcMapDeps->stopAddingPostConditions(); generateMemRegInstruction( S8MemReg, callNode, generateX86MemoryReference(frameObjectRegister, fe()->getPythonGCMapPCOffsetInFrame(), cg()), gcMapPCRegister, gcMapDeps, cg()); cg()->stopUsingRegister(frameObjectRegister); cg()->stopUsingRegister(gcMapPCRegister); #endif TR::Instruction *instr; if (methodSymbol->getMethodAddress()) { TR_ASSERT(scratchReg, "could not find second scratch register"); auto LoadRegisterInstruction = generateRegImm64SymInstruction( MOV8RegImm64, callNode, scratchReg, (uintptr_t)methodSymbol->getMethodAddress(), methodSymRef, cg()); if (comp()->getOption(TR_EmitRelocatableELFFile)) { LoadRegisterInstruction->setReloKind(TR_NativeMethodAbsolute); } instr = generateRegInstruction(CALLReg, callNode, scratchReg, preDeps, cg()); } else { instr = generateImmSymInstruction(CALLImm4, callNode, (uintptrj_t)methodSymbol->getMethodAddress(), methodSymRef, preDeps, cg()); } cg()->resetIsLeafMethod(); instr->setNeedsGCMap(getProperties().getPreservedRegisterMapForGC()); cg()->stopUsingRegister(scratchReg); TR::LabelSymbol *postDepLabel = generateLabelSymbol(cg()); generateLabelInstruction(LABEL, callNode, postDepLabel, postDeps, cg()); return returnReg; }
comp initfunc(double x, double y) { return comp(exp(-(x*x + y*y)), 0); }
inline ttl_constexpr const T &min(const T &a, const T &b, Compare comp) { return comp(a, b) ? a: b; }
comp referencefunc(double x, double y) { const double r2 = x*x + y*y; const double z = 4*(r2-1)*exp(-r2); return comp(z, 0); }
void TR::ARM64SystemLinkage::createPrologue(TR::Instruction *cursor, List<TR::ParameterSymbol> &parmList) { TR::CodeGenerator *codeGen = cg(); TR::Machine *machine = codeGen->machine(); TR::ResolvedMethodSymbol *bodySymbol = comp()->getJittedMethodSymbol(); const TR::ARM64LinkageProperties& properties = getProperties(); TR::RealRegister *sp = machine->getRealRegister(properties.getStackPointerRegister()); TR::Node *firstNode = comp()->getStartTree()->getNode(); // allocate stack space uint32_t frameSize = (uint32_t)codeGen->getFrameSizeInBytes(); if (constantIsUnsignedImm12(frameSize)) { cursor = generateTrg1Src1ImmInstruction(codeGen, TR::InstOpCode::subimmx, firstNode, sp, sp, frameSize, cursor); } else { TR_ASSERT(false, "Not implemented yet."); } // save link register (x30) TR::MemoryReference *stackSlot = new (trHeapMemory()) TR::MemoryReference(sp, bodySymbol->getLocalMappingCursor(), codeGen); cursor = generateMemSrc1Instruction(cg(), TR::InstOpCode::strimmx, firstNode, stackSlot, machine->getRealRegister(TR::RealRegister::x30), cursor); // spill argument registers int32_t nextIntArgReg = 0; int32_t nextFltArgReg = 0; ListIterator<TR::ParameterSymbol> parameterIterator(&parmList); for (TR::ParameterSymbol *parameter = parameterIterator.getFirst(); parameter != NULL && (nextIntArgReg < getProperties().getNumIntArgRegs() || nextFltArgReg < getProperties().getNumFloatArgRegs()); parameter = parameterIterator.getNext()) { TR::MemoryReference *stackSlot = new (trHeapMemory()) TR::MemoryReference(sp, parameter->getParameterOffset(), codeGen); TR::InstOpCode::Mnemonic op; switch (parameter->getDataType()) { case TR::Int8: case TR::Int16: case TR::Int32: case TR::Int64: case TR::Address: if (nextIntArgReg < getProperties().getNumIntArgRegs()) { op = (parameter->getSize() == 8) ? TR::InstOpCode::strimmx : TR::InstOpCode::strimmw; cursor = generateMemSrc1Instruction(cg(), op, firstNode, stackSlot, machine->getRealRegister((TR::RealRegister::RegNum)(TR::RealRegister::x0 + nextIntArgReg)), cursor); nextIntArgReg++; } else { nextIntArgReg = getProperties().getNumIntArgRegs() + 1; } break; case TR::Float: case TR::Double: if (nextFltArgReg < getProperties().getNumFloatArgRegs()) { op = (parameter->getSize() == 8) ? TR::InstOpCode::vstrimmd : TR::InstOpCode::vstrimms; cursor = generateMemSrc1Instruction(cg(), op, firstNode, stackSlot, machine->getRealRegister((TR::RealRegister::RegNum)(TR::RealRegister::v0 + nextFltArgReg)), cursor); nextFltArgReg++; } else { nextFltArgReg = getProperties().getNumFloatArgRegs() + 1; } break; case TR::Aggregate: TR_ASSERT(false, "Function parameters of aggregate types are not currently supported on AArch64."); break; default: TR_ASSERT(false, "Unknown parameter type."); } } // save callee-saved registers uint32_t offset = bodySymbol->getLocalMappingCursor() + 8; // +8 for LR for (int r = TR::RealRegister::x19; r <= TR::RealRegister::x28; r++) { TR::RealRegister *rr = machine->getRealRegister((TR::RealRegister::RegNum)r); if (rr->getHasBeenAssignedInMethod()) { TR::MemoryReference *stackSlot = new (trHeapMemory()) TR::MemoryReference(sp, offset, codeGen); cursor = generateMemSrc1Instruction(cg(), TR::InstOpCode::strimmx, firstNode, stackSlot, rr, cursor); offset += 8; } } for (int r = TR::RealRegister::v8; r <= TR::RealRegister::v15; r++) { TR::RealRegister *rr = machine->getRealRegister((TR::RealRegister::RegNum)r); if (rr->getHasBeenAssignedInMethod()) { TR::MemoryReference *stackSlot = new (trHeapMemory()) TR::MemoryReference(sp, offset, codeGen); cursor = generateMemSrc1Instruction(cg(), TR::InstOpCode::vstrimmd, firstNode, stackSlot, rr, cursor); offset += 8; } } }
int32_t TR::DeadTreesElimination::perform() { process(comp()->getStartTree(), NULL); return 1; }
static void sunpos(int inYY, int inMM, int inDD, double UTCOFFSET, int inHOUR, int inMIN, int inSEC, double eastlongitude, double latitude, double *L, double *DEC) { int Y; double ZJ, D, T, M, epsilon, lambda, alpha, HA, UTHM; ZJ = ZJtable[inMM]; if (inMM <= 2 && isleap(inYY)) ZJ -= 1.0; UTHM = inHOUR + inMIN / FMINSPERHOUR + inSEC / FSECSPERHOUR - UTCOFFSET; Y = inYY - 1900; /* 1 */ D = floor(365.25 * Y) + ZJ + inDD + UTHM / FHOURSPERDAY; /* 3 */ T = D / 36525.0; /* 4 */ *L = 279.697 + 36000.769 * T; /* 5 */ fixup(L); M = 358.476 + 35999.050 * T; /* 6 */ fixup(&M); epsilon = 23.452 - 0.013 * T; /* 7 */ fixup(&epsilon); lambda = *L + (1.919 - 0.005 * T) * SIN(M) + 0.020 * SIN(2 * M);/* 8 */ fixup(&lambda); alpha = ATAN(TAN(lambda) * COS(epsilon)); /* 9 */ /* Alpha should be in the same quadrant as lamba */ { int lssign = sin(D2R(lambda)) < 0 ? -1 : 1; int lcsign = cos(D2R(lambda)) < 0 ? -1 : 1; while (((sin(D2R(alpha)) < 0) ? -1 : 1) != lssign || ((cos(D2R(alpha)) < 0) ? -1 : 1) != lcsign) alpha += 90.0; } fixup(&alpha); *DEC = ASIN(SIN(lambda) * SIN(epsilon)); /* 10 */ fixup(DEC); fixup(&eastlongitude); HA = *L - alpha + 180 + 15 * UTHM + eastlongitude; /* 12 */ fixup(&HA); fixup(&latitude); #ifdef NOTDEF printf("%02d/%02d %02d:%02d:%02d l:%g d:%g h:%g\n", inMM, inDD, inHOUR, inMIN, inSEC, latitude, *DEC, HA); #endif return; /* * The following calculations are not used, so to save time * they are not calculated. */ #ifdef NOTDEF *ALT = ASIN(SIN(latitude) * SIN(*DEC) + COS(latitude) * COS(*DEC) * COS(HA)); /* 13 */ fixup(ALT); *AZ = ATAN(SIN(HA) / (COS(HA) * SIN(latitude) - TAN(*DEC) * COS(latitude))); /* 14 */ if (*ALT > 180) *ALT -= 360; if (*ALT < -180) *ALT += 360; printf("a:%g a:%g\n", *ALT, *AZ); #endif #ifdef NOTDEF printf("Y:\t\t\t %d\t\t %d\t\t %d\n", Y, expY, Y - expY); comp("ZJ", ZJ, expZJ); comp("UTHM", UTHM, expUTHM); comp("D", D, expD); comp("T", T, expT); comp("L", L, fixup(&expL)); comp("M", M, fixup(&expM)); comp("epsilon", epsilon, fixup(&expepsilon)); comp("lambda", lambda, fixup(&explambda)); comp("alpha", alpha, fixup(&expalpha)); comp("DEC", DEC, fixup(&expDEC)); comp("eastlongitude", eastlongitude, fixup(&expeastlongitude)); comp("latitude", latitude, fixup(&explatitude)); comp("HA", HA, fixup(&expHA)); comp("ALT", ALT, fixup(&expALT)); comp("AZ", AZ, fixup(&expAZ)); #endif }
void TR::DeadTreesElimination::prePerformOnBlocks() { _cannotBeEliminated = false; _delayedRegStores = false; _targetTrees.deleteAll(); // Walk through all the blocks to remove trivial dead trees of the form // treetop // => node // The problem with these trees is in the scenario where the earlier use // of 'node' is also dead. However, our analysis won't find that because // the reference count is > 1. vcount_t visitCount = comp()->incOrResetVisitCount(); for (TR::TreeTop *tt = comp()->getStartTree(); tt != 0; tt = tt->getNextTreeTop()) { bool removed = false; TR::Node *node = tt->getNode(); if (node->getOpCodeValue() == TR::treetop && node->getFirstChild()->getVisitCount() == visitCount && performTransformation(comp(), "%sRemove trivial dead tree: %p\n", optDetailString(), node)) { TR::TransformUtil::removeTree(comp(), tt); removed = true; } else { if (node->getOpCode().isCheck() && node->getFirstChild()->getOpCode().isCall() && node->getFirstChild()->getReferenceCount() == 1 && node->getFirstChild()->getSymbolReference()->getSymbol()->isResolvedMethod() && node->getFirstChild()->getSymbolReference()->getSymbol()->castToResolvedMethodSymbol()->isSideEffectFree() && performTransformation(comp(), "%sRemove dead check of side-effect free call: %p\n", optDetailString(), node)) { TR::TransformUtil::removeTree(comp(), tt); removed = true; } } if (removed && tt->getNextTreeTop()->getNode()->getOpCodeValue() == TR::Goto && tt->getPrevTreeTop()->getNode()->getOpCodeValue() == TR::BBStart && !tt->getPrevTreeTop()->getNode()->getBlock()->isExtensionOfPreviousBlock()) { requestOpt(OMR::redundantGotoElimination, tt->getEnclosingBlock()); } if (node->getVisitCount() >= visitCount) continue; TR::TransformUtil::recursivelySetNodeVisitCount(tt->getNode(), visitCount); } // If the last use of an iRegLoad has been removed, then remove the node from // the BBStart and remove the corresponding dependency node from each of the block's // predecessors. // while (1) { bool glRegDepRemoved = false; for (TR::Block * b = comp()->getStartBlock(); b; b = b->getNextBlock()) { TR::TreeTop * startTT = b->getEntry(); TR::Node * startNode = startTT->getNode(); if (startNode->getNumChildren() > 0 && !debug("disableEliminationOfGlRegDeps")) { TR::Node * glRegDeps = startNode->getFirstChild(); TR_ASSERT(glRegDeps->getOpCodeValue() == TR::GlRegDeps, "expected TR::GlRegDeps"); for (int32_t i = glRegDeps->getNumChildren() - 1; i >= 0; --i) { TR::Node * dep = glRegDeps->getChild(i); if (dep->getReferenceCount() == 1 && (!dep->getOpCode().isFloatingPoint() || cg()->getSupportsJavaFloatSemantics()) && performTransformation(comp(), "%sRemove GlRegDep : %p\n", optDetailString(), glRegDeps->getChild(i))) { glRegDeps->removeChild(i); glRegDepRemoved = true; TR_GlobalRegisterNumber registerNum = dep->getGlobalRegisterNumber(); for (auto e = b->getPredecessors().begin(); e != b->getPredecessors().end(); ++e) { TR::Block * pred = toBlock((*e)->getFrom()); if (pred == comp()->getFlowGraph()->getStart()) continue; TR::Node * parent = pred->getLastRealTreeTop()->getNode(); if ( parent->getOpCode().isJumpWithMultipleTargets() && parent->getOpCode().hasBranchChildren()) { for (int32_t j = parent->getCaseIndexUpperBound() - 1; j > 0; --j) { TR::Node * caseNode = parent->getChild(j); TR_ASSERT(caseNode->getOpCode().isCase() || caseNode->getOpCodeValue() == TR::branch, "having problems navigating a switch"); if (caseNode->getBranchDestination() == startTT && caseNode->getNumChildren() > 0 && 0) // can't do this now that all glRegDeps are hung off the default branch removeGlRegDep(caseNode, registerNum, pred, this); } } else if (!parent->getOpCode().isReturn() && parent->getOpCodeValue() != TR::igoto && !( parent->getOpCode().isJumpWithMultipleTargets() && parent->getOpCode().hasBranchChildren()) && !(parent->getOpCodeValue()==TR::treetop && parent->getFirstChild()->getOpCode().isCall() && parent->getFirstChild()->getOpCode().isIndirect())) { if (pred->getNextBlock() == b) parent = pred->getExit()->getNode(); removeGlRegDep(parent, registerNum, pred, this); } } } } if (glRegDeps->getNumChildren() == 0) startNode->removeChild(0); } } if (!glRegDepRemoved) break; } }
inline constexpr const T& max(const T& a, const T& b, Compare comp) { return comp(a, b) ? b : a; }
int32_t TR::DeadTreesElimination::process(TR::TreeTop *startTree, TR::TreeTop *endTree) { TR::StackMemoryRegion stackRegion(*comp()->trMemory()); LongestPathMap longestPaths(std::less<TR::Node*>(), stackRegion); typedef TR::typed_allocator<CRAnchor, TR::Region&> CRAnchorAlloc; typedef TR::forward_list<CRAnchor, CRAnchorAlloc> CRAnchorList; CRAnchorList anchors(stackRegion); vcount_t visitCount = comp()->incOrResetVisitCount(); TR::TreeTop *treeTop; for (treeTop = startTree; (treeTop != endTree); treeTop = treeTop->getNextTreeTop()) treeTop->getNode()->initializeFutureUseCounts(visitCount); TR::Block *block = NULL; bool delayedRegStoresBeforeThisPass = _delayedRegStores; // Update visitCount as they are used in this optimization and need to be visitCount = comp()->incOrResetVisitCount(); for (TR::TreeTopIterator iter(startTree, comp()); iter != endTree; ++iter) { TR::Node *node = iter.currentTree()->getNode(); if (node->getOpCodeValue() == TR::BBStart) { block = node->getBlock(); if (!block->isExtensionOfPreviousBlock()) longestPaths.clear(); } int vcountLimit = MAX_VCOUNT - 3; if (comp()->getVisitCount() > vcountLimit) { dumpOptDetails(comp(), "%sVisit count %d exceeds limit %d; stopping\n", optDetailString(), comp()->getVisitCount(), vcountLimit); return 0; } // correct at all intermediate stages // if ((node->getOpCodeValue() != TR::treetop) && (!node->getOpCode().isAnchor() || (node->getFirstChild()->getReferenceCount() != 1)) && (!node->getOpCode().isStoreReg() || (node->getFirstChild()->getReferenceCount() != 1)) && (delayedRegStoresBeforeThisPass || (iter.currentTree() == block->getLastRealTreeTop()) || !node->getOpCode().isStoreReg() || (node->getVisitCount() == visitCount))) { if (node->getOpCode().isAnchor() && node->getFirstChild()->getOpCode().isLoadIndirect()) anchors.push_front(CRAnchor(iter.currentTree(), block)); TR::TransformUtil::recursivelySetNodeVisitCount(node, visitCount); continue; } if (node->getOpCode().isStoreReg()) _delayedRegStores = true; TR::Node *child = node->getFirstChild(); if (child->getOpCodeValue() == TR::PassThrough) { TR::Node *newChild = child->getFirstChild(); node->setAndIncChild(0, newChild); newChild->incFutureUseCount(); if (child->getReferenceCount() <= 1) optimizer()->prepareForNodeRemoval(child); child->recursivelyDecReferenceCount(); recursivelyDecFutureUseCount(child); child = newChild; } bool treeTopCanBeEliminated = false; // If the treetop child has been seen before then it must be anchored // somewhere above already; so we don't need the treetop to be anchoring // this node (as the computation is already done at the first reference to // the node). // if (visitCount == child->getVisitCount()) { treeTopCanBeEliminated = true; } else { TR::ILOpCode &childOpCode = child->getOpCode(); TR::ILOpCodes opCodeValue = childOpCode.getOpCodeValue(); bool seenConditionalBranch = false; bool callWithNoSideEffects = child->getOpCode().isCall() && child->getSymbolReference()->getSymbol()->isResolvedMethod() && child->getSymbolReference()->getSymbol()->castToResolvedMethodSymbol()->isSideEffectFree(); if (callWithNoSideEffects) { treeTopCanBeEliminated = true; } else if (!((childOpCode.isCall() && !callWithNoSideEffects) || childOpCode.isStore() || ((opCodeValue == TR::New || opCodeValue == TR::anewarray || opCodeValue == TR::newarray) && child->getReferenceCount() > 1) || opCodeValue == TR::multianewarray || opCodeValue == TR::MergeNew || opCodeValue == TR::checkcast || opCodeValue == TR::Prefetch || opCodeValue == TR::iu2l || ((childOpCode.isDiv() || childOpCode.isRem()) && child->getNumChildren() == 3))) { // Perform the rather complex check to see whether its safe // to disconnect the child node from the treetop // bool safeToReplaceNode = false; if (child->getReferenceCount() == 1) { safeToReplaceNode = true; #ifdef J9_PROJECT_SPECIFIC if (child->getOpCode().isPackedExponentiation()) { // pdexp has a possible message side effect in truncating or no significant digits left cases safeToReplaceNode = false; } #endif if (opCodeValue == TR::loadaddr) treeTopCanBeEliminated = true; } else if (!_cannotBeEliminated) { safeToReplaceNode = isSafeToReplaceNode( child, iter.currentTree(), &seenConditionalBranch, visitCount, comp(), &_targetTrees, _cannotBeEliminated, longestPaths); } if (safeToReplaceNode) { if (childOpCode.hasSymbolReference()) { TR::SymbolReference *symRef = child->getSymbolReference(); if (symRef->getSymbol()->isAuto() || symRef->getSymbol()->isParm()) treeTopCanBeEliminated = true; else { if (childOpCode.isLoad() || (opCodeValue == TR::loadaddr) || (opCodeValue == TR::instanceof) || (((opCodeValue == TR::New) || (opCodeValue == TR::anewarray || opCodeValue == TR::newarray)) && ///child->getFirstChild()->isNonNegative())) child->markedAllocationCanBeRemoved())) // opCodeValue == TR::multianewarray || // opCodeValue == TR::MergeNew) treeTopCanBeEliminated = true; } } else treeTopCanBeEliminated = true; } } // Fix for the case when a float to non-float conversion node swings // down past a branch on IA32; this would cause a FP value to be commoned // across a branch where there was none originally; this causes pblms // as a value is left on the stack. // if (treeTopCanBeEliminated && seenConditionalBranch) { if (!cg()->getSupportsJavaFloatSemantics()) { if (child->getOpCode().isConversion() || child->getOpCode().isBooleanCompare()) { if (child->getFirstChild()->getOpCode().isFloatingPoint() && !child->getOpCode().isFloatingPoint()) treeTopCanBeEliminated = false; } } } if (treeTopCanBeEliminated) { TR::NodeChecklist visited(comp()); bool containsFloatingPoint = false; for (int32_t i = 0; i < child->getNumChildren(); ++i) { // Anchor nodes with reference count > 1 // bool highGlobalIndex = false; if (fixUpTree(child->getChild(i), iter.currentTree(), visited, highGlobalIndex, self(), visitCount)) containsFloatingPoint = true; if (highGlobalIndex) { dumpOptDetails(comp(), "%sGlobal index limit exceeded; stopping\n", optDetailString()); return 0; } } if (seenConditionalBranch && containsFloatingPoint) { if (!cg()->getSupportsJavaFloatSemantics()) treeTopCanBeEliminated = false; } } } // Update visitCount as they are used in this optimization and need to be // correct at all intermediate stages // if (!treeTopCanBeEliminated) TR::TransformUtil::recursivelySetNodeVisitCount(node, visitCount); if (treeTopCanBeEliminated) { TR::TreeTop *prevTree = iter.currentTree()->getPrevTreeTop(); TR::TreeTop *nextTree = iter.currentTree()->getNextTreeTop(); if (!node->getOpCode().isStoreReg() || (node->getFirstChild()->getReferenceCount() == 1)) { // Actually going to remove the treetop now // if (performTransformation(comp(), "%sRemove tree : [" POINTER_PRINTF_FORMAT "] ([" POINTER_PRINTF_FORMAT "] = %s)\n", optDetailString(), node, node->getFirstChild(), node->getFirstChild()->getOpCode().getName())) { prevTree->join(nextTree); optimizer()->prepareForNodeRemoval(node); ///child->recursivelyDecReferenceCount(); node->recursivelyDecReferenceCount(); recursivelyDecFutureUseCount(child); iter.jumpTo(prevTree); if (child->getReferenceCount() == 1) requestOpt(OMR::treeSimplification, true, block); if (nextTree->getNode()->getOpCodeValue() == TR::Goto && prevTree->getNode()->getOpCodeValue() == TR::BBStart && !prevTree->getNode()->getBlock()->isExtensionOfPreviousBlock()) { requestOpt( OMR::redundantGotoElimination, prevTree->getNode()->getBlock()); } } } else { if (performTransformation(comp(), "%sMove tree : [" POINTER_PRINTF_FORMAT "]([" POINTER_PRINTF_FORMAT "] = %s) to end of block\n", optDetailString(), node, node->getFirstChild(), node->getFirstChild()->getOpCode().getName())) { prevTree->join(nextTree); node->setVisitCount(visitCount); TR::TreeTop *lastTree = findLastTreetop(block, prevTree); TR::TreeTop *prevLastTree = lastTree->getPrevTreeTop(); TR::TreeTop *cursorTreeTop = nextTree; while (cursorTreeTop != lastTree) { if (cursorTreeTop->getNode()->getOpCode().isStoreReg() && (cursorTreeTop->getNode()->getGlobalRegisterNumber() == iter.currentTree()->getNode()->getGlobalRegisterNumber())) { lastTree = cursorTreeTop; prevLastTree = lastTree->getPrevTreeTop(); break; } cursorTreeTop = cursorTreeTop->getNextTreeTop(); } if (lastTree->getNode()->getOpCodeValue() == TR::BBStart) { prevLastTree = lastTree; lastTree = block->getExit(); } TR::Node *lastNode = lastTree->getNode(); TR::Node *prevLastNode = prevLastTree->getNode(); if (lastNode->getOpCode().isIf() && !lastNode->getOpCode().isCompBranchOnly() && prevLastNode->getOpCode().isStoreReg() && ((prevLastNode->getFirstChild() == lastNode->getFirstChild()) || (prevLastNode->getFirstChild() == lastNode->getSecondChild()))) { lastTree = prevLastTree; prevLastTree = lastTree->getPrevTreeTop(); } prevLastTree->join(iter.currentTree()); iter.currentTree()->join(lastTree); iter.jumpTo(prevTree); requestOpt(OMR::treeSimplification, true, block); } } } } for (auto it = anchors.begin(); it != anchors.end(); ++it) { TR::Node *anchor = it->tree->getNode(); TR::Node *load = anchor->getChild(0); if (load->getReferenceCount() > 1) continue; // We can eliminate the indirect load immediately, but for the moment the // subtree providing the base object has to be anchored. TR::Node *heapBase = anchor->getChild(1); TR::Node::recreate(anchor, TR::treetop); anchor->setAndIncChild(0, load->getChild(0)); anchor->setChild(1, NULL); anchor->setNumChildren(1); if (!heapBase->getOpCode().isLoadConst()) { it->tree->insertAfter( TR::TreeTop::create( comp(), TR::Node::create(heapBase, TR::treetop, 1, heapBase))); } load->recursivelyDecReferenceCount(); heapBase->recursivelyDecReferenceCount(); // A later pass of dead trees can likely move (or even remove) the base // object expression. requestOpt(OMR::deadTreesElimination, true, it->block); } return 1; // actual cost }
void removeNodeFromList(TR::Node *node, List<TR::Node> *nodes, List< List<TR::Node> > *parents, bool checkSymRefs, List<TR::Node> *loadsAlreadyVisited = NULL, List<TR::Node> *loadsAlreadyVisitedThatCannotBeRematerialized = NULL) { TR::SparseBitVector EMPTY_SET(comp()->allocator()); removeNodeFromList(node, nodes, parents, checkSymRefs, loadsAlreadyVisited, loadsAlreadyVisitedThatCannotBeRematerialized, EMPTY_SET); }
Item ComparingAggregator<oper, result>::evaluateSingleton(const DynamicContext::Ptr &context) const { const Item::Iterator::Ptr it(m_operands.first()->evaluateSequence(context)); Item largest; while(true) { Item next(it->next()); if(!next) { return largest; } AtomicComparator::Ptr comp(comparator()); if(!comp) { ItemType::Ptr t1(next.type()); Q_ASSERT(t1); if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(t1)) { next = cast(next, context); t1 = BuiltinTypes::xsDouble; } if(!largest) { largest = next; continue; } Q_ASSERT(largest); comp = fetchComparator(largest.type(), t1, context); Q_ASSERT(comp); } else if(!largest) { largest = next; continue; } if(comp->compare(next, operatorID(), largest) == result) { largest = applyNumericPromotion(largest, next, next); continue; } const ItemType::Ptr t(next.type()); if(BuiltinTypes::xsDouble->xdtTypeMatches(t) && next.as<Numeric>()->isNaN()) { return CommonValues::DoubleNaN; } else if(BuiltinTypes::xsFloat->xdtTypeMatches(t) && next.as<Numeric>()->isNaN()) { if(BuiltinTypes::xsDouble->xdtTypeMatches(largest.type())) return CommonValues::DoubleNaN; /* If we have a xs:double somewhere, we must promote the NaN value to xs:double, * and we really should raise error on invalid value. */ largest = it->next(); while(largest) { const ItemType::Ptr tf(largest.type()); if(BuiltinTypes::xsDouble->xdtTypeMatches(tf)) return CommonValues::DoubleNaN; else if(BuiltinTypes::xsUntypedAtomic->xdtTypeMatches(tf)) { /* Attempt a convert, which will raise an error if it doesn't work out. */ cast(largest, context); return CommonValues::DoubleNaN; } else if(!BuiltinTypes::numeric->xdtTypeMatches(tf)) { fetchComparator(BuiltinTypes::xsFloat, tf, context); } else largest = it->next(); }; return CommonValues::FloatNaN; } else largest = applyNumericPromotion(largest, next, largest); } }