void VBlankIntrWait () { R(0) = 1; R(1) = 1; IntrWait(); }
TMat4 trans(const TMat4 &m) { #define M(x,y) m[x][y] #define R(x,y) result[x][y] TMat4 result; R(0,0) = M(0,0); R(0,1) = M(1,0); R(0,2) = M(2,0); R(0,3) = M(3,0); R(1,0) = M(0,1); R(1,1) = M(1,1); R(1,2) = M(2,1); R(1,3) = M(3,1); R(2,0) = M(0,2); R(2,1) = M(1,2); R(2,2) = M(2,2); R(2,3) = M(3,2); R(3,0) = M(0,3); R(3,1) = M(1,3); R(3,2) = M(2,3); R(3,3) = M(3,3); return(result); #undef M #undef R }
static INLINE void xor_salsa8(uint32_t B[16], const uint32_t Bx[16]) { uint32_t x00,x01,x02,x03,x04,x05,x06,x07,x08,x09,x10,x11,x12,x13,x14,x15; int8_t i; x00 = (B[0] ^= Bx[0]); x01 = (B[1] ^= Bx[1]); x02 = (B[2] ^= Bx[2]); x03 = (B[3] ^= Bx[3]); x04 = (B[4] ^= Bx[4]); x05 = (B[5] ^= Bx[5]); x06 = (B[6] ^= Bx[6]); x07 = (B[7] ^= Bx[7]); x08 = (B[8] ^= Bx[8]); x09 = (B[9] ^= Bx[9]); x10 = (B[10] ^= Bx[10]); x11 = (B[11] ^= Bx[11]); x12 = (B[12] ^= Bx[12]); x13 = (B[13] ^= Bx[13]); x14 = (B[14] ^= Bx[14]); x15 = (B[15] ^= Bx[15]); for (i = 0; i < 8; i += 2) { #define R(a, b) (((a) << (b)) | ((a) >> (32 - (b)))) /* Operate on columns. */ x04 ^= R(x00+x12, 7); x09 ^= R(x05+x01, 7); x14 ^= R(x10+x06, 7); x03 ^= R(x15+x11, 7); x08 ^= R(x04+x00, 9); x13 ^= R(x09+x05, 9); x02 ^= R(x14+x10, 9); x07 ^= R(x03+x15, 9); x12 ^= R(x08+x04,13); x01 ^= R(x13+x09,13); x06 ^= R(x02+x14,13); x11 ^= R(x07+x03,13); x00 ^= R(x12+x08,18); x05 ^= R(x01+x13,18); x10 ^= R(x06+x02,18); x15 ^= R(x11+x07,18); /* Operate on rows. */ x01 ^= R(x00+x03, 7); x06 ^= R(x05+x04, 7); x11 ^= R(x10+x09, 7); x12 ^= R(x15+x14, 7); x02 ^= R(x01+x00, 9); x07 ^= R(x06+x05, 9); x08 ^= R(x11+x10, 9); x13 ^= R(x12+x15, 9); x03 ^= R(x02+x01,13); x04 ^= R(x07+x06,13); x09 ^= R(x08+x11,13); x14 ^= R(x13+x12,13); x00 ^= R(x03+x02,18); x05 ^= R(x04+x07,18); x10 ^= R(x09+x08,18); x15 ^= R(x14+x13,18); #undef R } B[0] += x00; B[1] += x01; B[2] += x02; B[3] += x03; B[4] += x04; B[5] += x05; B[6] += x06; B[7] += x07; B[8] += x08; B[9] += x09; B[10] += x10; B[11] += x11; B[12] += x12; B[13] += x13; B[14] += x14; B[15] += x15; }
void ElastoViscoplasticModel<EvalT, Traits>:: computeState(typename Traits::EvalData workset, std::map<std::string, Teuchos::RCP<PHX::MDField<ScalarT> > > dep_fields, std::map<std::string, Teuchos::RCP<PHX::MDField<ScalarT> > > eval_fields) { std::string cauchy_string = (*field_name_map_)["Cauchy_Stress"]; std::string Fp_string = (*field_name_map_)["Fp"]; std::string eqps_string = (*field_name_map_)["eqps"]; std::string eps_ss_string = (*field_name_map_)["eps_ss"]; std::string kappa_string = (*field_name_map_)["isotropic_hardening"]; std::string source_string = (*field_name_map_)["Mechanical_Source"]; std::string F_string = (*field_name_map_)["F"]; std::string J_string = (*field_name_map_)["J"]; // extract dependent MDFields PHX::MDField<ScalarT> def_grad_field = *dep_fields[F_string]; PHX::MDField<ScalarT> J = *dep_fields[J_string]; PHX::MDField<ScalarT> poissons_ratio = *dep_fields["Poissons Ratio"]; PHX::MDField<ScalarT> elastic_modulus = *dep_fields["Elastic Modulus"]; PHX::MDField<ScalarT> yield_strength = *dep_fields["Yield Strength"]; PHX::MDField<ScalarT> hardening_modulus = *dep_fields["Hardening Modulus"]; PHX::MDField<ScalarT> recovery_modulus = *dep_fields["Recovery Modulus"]; PHX::MDField<ScalarT> flow_exp = *dep_fields["Flow Rule Exponent"]; PHX::MDField<ScalarT> flow_coeff = *dep_fields["Flow Rule Coefficient"]; PHX::MDField<ScalarT> delta_time = *dep_fields["Delta Time"]; // extract evaluated MDFields PHX::MDField<ScalarT> stress_field = *eval_fields[cauchy_string]; PHX::MDField<ScalarT> Fp_field = *eval_fields[Fp_string]; PHX::MDField<ScalarT> eqps_field = *eval_fields[eqps_string]; PHX::MDField<ScalarT> eps_ss_field = *eval_fields[eps_ss_string]; PHX::MDField<ScalarT> kappa_field = *eval_fields[kappa_string]; PHX::MDField<ScalarT> source_field; if (have_temperature_) { source_field = *eval_fields[source_string]; } // get State Variables Albany::MDArray Fp_field_old = (*workset.stateArrayPtr)[Fp_string + "_old"]; Albany::MDArray eqps_field_old = (*workset.stateArrayPtr)[eqps_string + "_old"]; Albany::MDArray eps_ss_field_old = (*workset.stateArrayPtr)[eps_ss_string + "_old"]; Albany::MDArray kappa_field_old = (*workset.stateArrayPtr)[kappa_string + "_old"]; // define constants RealType sq23(std::sqrt(2. / 3.)); RealType sq32(std::sqrt(3. / 2.)); // pre-define some tensors that will be re-used below Intrepid::Tensor<ScalarT> F(num_dims_), be(num_dims_); Intrepid::Tensor<ScalarT> s(num_dims_), sigma(num_dims_); Intrepid::Tensor<ScalarT> N(num_dims_), A(num_dims_); Intrepid::Tensor<ScalarT> expA(num_dims_), Fpnew(num_dims_); Intrepid::Tensor<ScalarT> I(Intrepid::eye<ScalarT>(num_dims_)); Intrepid::Tensor<ScalarT> Fpn(num_dims_), Cpinv(num_dims_), Fpinv(num_dims_); for (std::size_t cell(0); cell < workset.numCells; ++cell) { for (std::size_t pt(0); pt < num_pts_; ++pt) { ScalarT bulk = elastic_modulus(cell, pt) / (3. * (1. - 2. * poissons_ratio(cell, pt))); ScalarT mu = elastic_modulus(cell, pt) / (2. * (1. + poissons_ratio(cell, pt))); ScalarT Y = yield_strength(cell, pt); ScalarT Jm23 = std::pow(J(cell, pt), -2. / 3.); // assign local state variables // //ScalarT kappa = kappa_field(cell,pt); ScalarT kappa_old = kappa_field_old(cell,pt); ScalarT eps_ss = eps_ss_field(cell,pt); ScalarT eps_ss_old = eps_ss_field_old(cell,pt); ScalarT eqps_old = eqps_field_old(cell,pt); // fill local tensors // F.fill(&def_grad_field(cell, pt, 0, 0)); for (std::size_t i(0); i < num_dims_; ++i) { for (std::size_t j(0); j < num_dims_; ++j) { Fpn(i, j) = ScalarT(Fp_field_old(cell, pt, i, j)); } } // compute trial state // compute the Kirchhoff stress in the current configuration // Cpinv = Intrepid::inverse(Fpn) * Intrepid::transpose(Intrepid::inverse(Fpn)); be = Jm23 * F * Cpinv * Intrepid::transpose(F); s = mu * Intrepid::dev(be); ScalarT smag = Intrepid::norm(s); ScalarT mubar = Intrepid::trace(be) * mu / (num_dims_); // check yield condition // ScalarT Phi = sq32 * smag - ( Y + kappa_old ); std::cout << "======== Phi: " << Phi << std::endl; std::cout << "======== eps: " << std::numeric_limits<RealType>::epsilon() << std::endl; if (Phi > std::numeric_limits<RealType>::epsilon()) { // return mapping algorithm // bool converged = false; int iter = 0; RealType max_norm = std::numeric_limits<RealType>::min(); // hardening and recovery parameters // ScalarT H = hardening_modulus(cell, pt); ScalarT Rd = recovery_modulus(cell, pt); // flow rule temperature dependent parameters // ScalarT f = flow_coeff(cell,pt); ScalarT n = flow_exp(cell,pt); // This solver deals with Sacado type info // LocalNonlinearSolver<EvalT, Traits> solver; // create some vectors to store solver data // std::vector<ScalarT> R(2); std::vector<ScalarT> dRdX(4); std::vector<ScalarT> X(2); // initial guess X[0] = 0.0; X[1] = eps_ss_old; // create a copy of be as a Fad Intrepid::Tensor<Fad> beF(num_dims_); for (std::size_t i = 0; i < num_dims_; ++i) { for (std::size_t j = 0; j < num_dims_; ++j) { beF(i, j) = be(i, j); } } Fad two_mubarF = 2.0 * Intrepid::trace(beF) * mu / (num_dims_); //Fad sq32F = std::sqrt(3.0/2.0); // FIXME this seems to be necessary to get PhiF to compile below // need to look into this more, it appears to be a conflict // between the Intrepid::norm and FadType operations // Fad smagF = smag; while (!converged) { // set up data types // std::vector<Fad> XFad(2); std::vector<Fad> RFad(2); std::vector<ScalarT> Xval(2); for (std::size_t i = 0; i < 2; ++i) { Xval[i] = Sacado::ScalarValue<ScalarT>::eval(X[i]); XFad[i] = Fad(2, i, Xval[i]); } // get solution vars // Fad dgamF = XFad[0]; Fad eps_ssF = XFad[1]; // compute yield function // Fad eqps_rateF = 0.0; if (delta_time(0) > 0) eqps_rateF = sq23 * dgamF / delta_time(0); Fad rate_termF = 1.0 + std::asinh( std::pow(eqps_rateF / f, n)); Fad kappaF = two_mubarF * eps_ssF; Fad PhiF = sq32 * (smagF - two_mubarF * dgamF) - ( Y + kappaF ) * rate_termF; // compute the hardening residual // Fad eps_resF = eps_ssF - eps_ss_old - (H - Rd*eps_ssF) * dgamF; // for convenience put the residuals into a container // RFad[0] = PhiF; RFad[1] = eps_resF; // extract the values of the residuals // for (int i = 0; i < 2; ++i) R[i] = RFad[i].val(); // extract the sensitivities of the residuals // for (int i = 0; i < 2; ++i) for (int j = 0; j < 2; ++j) dRdX[i + 2 * j] = RFad[i].dx(j); // this call invokes the solver and updates the solution in X // solver.solve(dRdX, X, R); // compute the norm of the residual // RealType R0 = Sacado::ScalarValue<ScalarT>::eval(R[0]); RealType R1 = Sacado::ScalarValue<ScalarT>::eval(R[1]); RealType norm_res = std::sqrt(R0*R0 + R1*R1); max_norm = std::max(norm_res, max_norm); // check against too many inerations // TEUCHOS_TEST_FOR_EXCEPTION(iter == 30, std::runtime_error, std::endl << "Error in ElastoViscoplastic return mapping\n" << "iter count = " << iter << "\n" << std::endl); // check for a sufficiently small residual // std::cout << "======== norm_res : " << norm_res << std::endl; if ( (norm_res/max_norm < 1.e-12) || (norm_res < 1.e-12) ) converged = true; // increment the iteratio counter // iter++; } solver.computeFadInfo(dRdX, X, R); ScalarT dgam = X[0]; ScalarT eps_ss = X[1]; ScalarT kappa = 2.0 * mubar * eps_ss; std::cout << "======== dgam : " << dgam << std::endl; std::cout << "======== e_ss : " << eps_ss << std::endl; std::cout << "======== kapp : " << kappa << std::endl; // plastic direction N = (1 / smag) * s; // update s s -= 2 * mubar * dgam * N; // update state variables eps_ss_field(cell, pt) = eps_ss; eqps_field(cell,pt) = eqps_old + sq23 * dgam; kappa_field(cell,pt) = kappa; // mechanical source // FIXME this is not correct, just a placeholder // if (have_temperature_ && delta_time(0) > 0) { source_field(cell, pt) = (sq23 * dgam / delta_time(0)) * (Y + kappa) / (density_ * heat_capacity_); } // exponential map to get Fpnew // A = dgam * N; expA = Intrepid::exp(A); Fpnew = expA * Fpn; for (std::size_t i(0); i < num_dims_; ++i) { for (std::size_t j(0); j < num_dims_; ++j) { Fp_field(cell, pt, i, j) = Fpnew(i, j); } } } else { // we are not yielding, variables do not evolve // eps_ss_field(cell, pt) = eps_ss_old; eqps_field(cell,pt) = eqps_old; kappa_field(cell,pt) = kappa_old; if (have_temperature_) source_field(cell, pt) = 0.0; for (std::size_t i(0); i < num_dims_; ++i) { for (std::size_t j(0); j < num_dims_; ++j) { Fp_field(cell, pt, i, j) = Fpn(i, j); } } } // compute pressure ScalarT p = 0.5 * bulk * (J(cell, pt) - 1. / (J(cell, pt))); // compute stress sigma = p * I + s / J(cell, pt); for (std::size_t i(0); i < num_dims_; ++i) { for (std::size_t j(0); j < num_dims_; ++j) { stress_field(cell, pt, i, j) = sigma(i, j); } } } } if (have_temperature_) { for (std::size_t cell(0); cell < workset.numCells; ++cell) { for (std::size_t pt(0); pt < num_pts_; ++pt) { F.fill(&def_grad_field(cell,pt,0,0)); ScalarT J = Intrepid::det(F); sigma.fill(&stress_field(cell,pt,0,0)); sigma -= 3.0 * expansion_coeff_ * (1.0 + 1.0 / (J*J)) * (temperature_(cell,pt) - ref_temperature_) * I; for (std::size_t i = 0; i < num_dims_; ++i) { for (std::size_t j = 0; j < num_dims_; ++j) { stress_field(cell, pt, i, j) = sigma(i, j); } } } } } }
static void salsa208_word_specification(uint32_t inout[16]) { int i; uint32_t x[16]; memcpy(x, inout, sizeof(x)); for (i = 8; i > 0; i -= 2) { x[4] ^= R(x[0] + x[12], 7); x[8] ^= R(x[4] + x[0], 9); x[12] ^= R(x[8] + x[4], 13); x[0] ^= R(x[12] + x[8], 18); x[9] ^= R(x[5] + x[1], 7); x[13] ^= R(x[9] + x[5], 9); x[1] ^= R(x[13] + x[9], 13); x[5] ^= R(x[1] + x[13], 18); x[14] ^= R(x[10] + x[6], 7); x[2] ^= R(x[14] + x[10], 9); x[6] ^= R(x[2] + x[14], 13); x[10] ^= R(x[6] + x[2], 18); x[3] ^= R(x[15] + x[11], 7); x[7] ^= R(x[3] + x[15], 9); x[11] ^= R(x[7] + x[3], 13); x[15] ^= R(x[11] + x[7], 18); x[1] ^= R(x[0] + x[3], 7); x[2] ^= R(x[1] + x[0], 9); x[3] ^= R(x[2] + x[1], 13); x[0] ^= R(x[3] + x[2], 18); x[6] ^= R(x[5] + x[4], 7); x[7] ^= R(x[6] + x[5], 9); x[4] ^= R(x[7] + x[6], 13); x[5] ^= R(x[4] + x[7], 18); x[11] ^= R(x[10] + x[9], 7); x[8] ^= R(x[11] + x[10], 9); x[9] ^= R(x[8] + x[11], 13); x[10] ^= R(x[9] + x[8], 18); x[12] ^= R(x[15] + x[14], 7); x[13] ^= R(x[12] + x[15], 9); x[14] ^= R(x[13] + x[12], 13); x[15] ^= R(x[14] + x[13], 18); } for (i = 0; i < 16; ++i) inout[i] += x[i]; OPENSSL_cleanse(x, sizeof(x)); }
static void print_character (STREAM stream, D instance, BOOL escape_p, int print_depth) { ignore(print_depth); if (escape_p) { format(stream, "'%c'", R(instance)) } else {
function(R (*fn)(Args...)) : m_funpointer(new detail::free_function<R(Args...)>(fn)){}
inline void LUnb( DistMatrix<R>& A ) { #ifndef RELEASE PushCallStack("bidiag::LUnb"); if( A.Height() > A.Width() ) throw std::logic_error("A must be at least as wide as it is tall"); #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<R> ATL(g), ATR(g), A00(g), a01(g), A02(g), alpha21T(g), a1R(g), ABL(g), ABR(g), a10(g), alpha11(g), a12(g), a21B(g), A2R(g), A20(g), a21(g), A22(g); // Temporary matrices DistMatrix<R,MC, STAR> a21_MC_STAR(g); DistMatrix<R,STAR,MR > a1R_STAR_MR(g); DistMatrix<R,MR, STAR> x12Trans_MR_STAR(g); DistMatrix<R,MC, STAR> w21_MC_STAR(g); PushBlocksizeStack( 1 ); PartitionDownDiagonal ( A, ATL, ATR, ABL, ABR, 0 ); while( ATL.Width() < A.Width() ) { RepartitionDownDiagonal ( ATL, /**/ ATR, A00, /**/ a01, A02, /*************/ /**********************/ /**/ a10, /**/ alpha11, a12, ABL, /**/ ABR, A20, /**/ a21, A22 ); View1x2( a1R, alpha11, a12 ); View1x2( A2R, a21, A22 ); a21_MC_STAR.AlignWith( A22 ); a1R_STAR_MR.AlignWith( A2R ); x12Trans_MR_STAR.AlignWith( A22 ); w21_MC_STAR.AlignWith( A2R ); Zeros( a12.Width(), 1, x12Trans_MR_STAR ); Zeros( a21.Height(), 1, w21_MC_STAR ); const bool thisIsMyRow = ( g.Row() == alpha11.ColAlignment() ); const bool thisIsMyCol = ( g.Col() == alpha11.RowAlignment() ); const bool nextIsMyRow = ( g.Row() == a21.ColAlignment() ); //--------------------------------------------------------------------// // Find tauP, u, and epsilonP such that // I - tauP | 1 | | 1, v^T | | alpha11 | = | epsilonP | // | v | | a12^T | = | 0 | const R tauP = Reflector( alpha11, a12 ); R epsilonP=0; if( thisIsMyCol && thisIsMyRow ) epsilonP = alpha11.GetLocal(0,0); // Set a1R^T = | 1 | and form w21 := A2R a1R^T = A2R | 1 | // | v | | v | alpha11.Set(0,0,R(1)); a1R_STAR_MR = a1R; LocalGemv( NORMAL, R(1), A2R, a1R_STAR_MR, R(0), w21_MC_STAR ); w21_MC_STAR.SumOverRow(); // A2R := A2R - tauP w21 a1R // = A2R - tauP A2R a1R^T a1R // = A2R (I - tauP a1R^T a1R) LocalGer( -tauP, w21_MC_STAR, a1R_STAR_MR, A2R ); // Put epsilonP back instead of the temporary value, 1 if( thisIsMyCol && thisIsMyRow ) alpha11.SetLocal(0,0,epsilonP); if( A22.Height() != 0 ) { // Expose the subvector we seek to zero, a21B PartitionDown ( a21, alpha21T, a21B ); // Find tauQ, u, and epsilonQ such that // I - tauQ | 1 | | 1, u^T | | alpha21T | = | epsilonQ | // | u | | a21B | = | 0 | const R tauQ = Reflector( alpha21T, a21B ); R epsilonQ=0; if( nextIsMyRow && thisIsMyCol ) epsilonQ = alpha21T.GetLocal(0,0); // Set a21 = | 1 | and form x12^T = (a21^T A22)^T = A22^T a21 // | u | alpha21T.Set(0,0,R(1)); a21_MC_STAR = a21; LocalGemv ( TRANSPOSE, R(1), A22, a21_MC_STAR, R(0), x12Trans_MR_STAR ); x12Trans_MR_STAR.SumOverCol(); // A22 := A22 - tauQ a21 x12 // = A22 - tauQ a21 a21^T A22 // = (I - tauQ a21 a21^T) A22 LocalGer( -tauQ, a21_MC_STAR, x12Trans_MR_STAR, A22 ); // Put epsilonQ back instead of the temporary value, 1 if( nextIsMyRow && thisIsMyCol ) alpha21T.SetLocal(0,0,epsilonQ); } //--------------------------------------------------------------------// a1R_STAR_MR.FreeAlignments(); a21_MC_STAR.FreeAlignments(); x12Trans_MR_STAR.FreeAlignments(); w21_MC_STAR.FreeAlignments(); SlidePartitionDownDiagonal ( ATL, /**/ ATR, A00, a01, /**/ A02, /**/ a10, alpha11, /**/ a12, /*************/ /**********************/ ABL, /**/ ABR, A20, a21, /**/ A22 ); } PopBlocksizeStack(); #ifndef RELEASE PopCallStack(); #endif }
void BlackoilCo2PVT::generateBlackOilTables(double temperature) { std::cout << "\n Generating pvt tables for the eclipse black oil formulation\n using the oil component as brine and the gas component as co_2." << std::endl; if (std::fabs(temperature-400.) > 100.0) { std::cout << "T=" << temperature << " is outside the allowed range [300,500] Kelvin" << std::endl; exit(-1); } temperature_ = temperature; CompVec z; z[Water] = 0.0; z[Oil] = 1.0; z[Gas] = 1.0e6; std::ofstream black("blackoil_pvt"); black.precision(8); black << std::fixed << std::showpoint; const double pMin=150.e5; const double pMax=400.e5; const unsigned int np=11; std::vector<double> pValue(np+1,0.0); std::vector<double> rs(np+1,0.0); pValue[0] = 101330.0; rs[0] = 0.0; // Buble points z[Gas] = 1.0e4; for (unsigned int i=0; i<np; ++i) { pValue[i+1] = pMin + i*(pMax-pMin)/(np-1); rs[i+1] = R(pValue[i+1], z, Liquid); } const unsigned int np_fill_in = 10; const double dr = (rs[1] - rs[0])/(np_fill_in+1); const double dp = (pValue[1] - pValue[0])/(np_fill_in+1); rs.insert(rs.begin()+1,np_fill_in,0.0); pValue.insert(pValue.begin()+1,np_fill_in,0.0); for (unsigned int i=1; i<=np_fill_in; ++i) { rs[i] = rs[i-1] + dr; pValue[i] = pValue[i-1] + dp; } // Brine with dissolved co_2 ("live oil") black << "PVTO\n"; black << "-- Rs Pbub Bo Vo\n"; black << "-- sm3/sm3 barsa rm3/sm3 cP\n"; // Undersaturated for (unsigned int i=0; i<np+np_fill_in; ++i) { z[Gas] = rs[i]; black << std::setw(14) << rs[i]; for (unsigned int j=i; j<np+1+np_fill_in; ++j) { if (j<=np_fill_in) { if (j==i) black << std::setw(14) << pValue[j]*1.e-5 << std::setw(14) << 1.0-j*0.001 << std::setw(14) << 1.06499; continue; } if (j>i) black << std::endl << std::setw(14) << ' '; black << std::setw(14) << pValue[j]*1.e-5 << std::setw(14) << B(pValue[j], z, Liquid) << std::setw(14) << getViscosity(pValue[j], z, Liquid)*1.e3; } black << " /" << std::endl; } black << "/ " << std::endl; // We provide tables for co_2 both with and without dissolved water: // Co_2 neglecting dissolved water ("dry gas") black << "\nPVDG\n"; black << "-- Pg Bg Vg\n"; black << "-- barsa rm3/sm3 cP\n"; for (unsigned int i=0; i<np; ++i) { z[Oil] = 0.0; z[Gas] = 1.0; black << std::setw(14) << pValue[i+np_fill_in+1]*1.e-5 << std::setw(14) << B(pValue[i+np_fill_in+1], z, Vapour) << std::setw(14) << getViscosity(pValue[i+np_fill_in+1], z, Vapour)*1.e3 << std::endl; } black << "/ " << std::endl; // Co_2 with dissolved water ("wet gas") black << "\nPVTG\n"; black << "-- Pg Rv Bg Vg\n"; black << "-- barsa sm3/sm3 rm3/sm3 cP\n"; for (unsigned int i=0; i<np; ++i) { z[Oil] = 1000.0; z[Gas] = 1.0; black << std::setw(14) << pValue[i+np_fill_in+1]*1.e-5 << std::setw(14) << R(pValue[i+np_fill_in+1], z, Vapour) << std::setw(14) << B(pValue[i+np_fill_in+1], z, Vapour) << std::setw(14) << getViscosity(pValue[i+np_fill_in+1], z, Vapour)*1.e3 << std::endl; z[Oil] = 0.0; black << std::setw(14) << ' ' << std::setw(14) << R(pValue[i+np_fill_in+1], z, Vapour) << std::setw(14) << B(pValue[i+np_fill_in+1], z, Vapour) << std::setw(14) << getViscosity(pValue[i+np_fill_in+1], z, Vapour)*1.e3 << " /" << std::endl; } black << "/ " << std::endl; black << std::endl; std::cout << " Pvt tables for temperature=" << temperature << " Kelvin is written to file blackoil_pvt. " << std::endl; std::cout << " NOTE that the file contains tables for both PVDG (dry gas) and PVTG (wet gas)." << std::endl; }
int main() { int i ; /* Flush Cache*/ A(0x90A4001C); W(0x00000001); /* Data memory addressing mode (0: not interleaved 1: interleaved) */ A(0x90A80008); W(0x00000000); /* Data memory access priority (0: Core>BIU>CFU 1: BIU>Core>CFU) */ A(0x90A8000C); W(0x00000000); /* Base Address */ A(0x90A80004); W(0x90A00000); /* DBGISR */ A(0x90A0001C); W(0x10000000); /* EXCISR */ A(0x90A00020); W(0x10000000); /* FIQISR */ A(0x90A00024); W(0x10000000); /* IRQISR */ A(0x90A00028); W(0x10000000); /* Start address to PSCU */ A(0x90A00000); W(0x10000000); /* Start Address to ICache */ A(0x90A40008); W(0x10000000); /* Initial program size to ICache */ A(0x90A4000C); W(0x00000B6C); /* Size x 1024bits */ /* Miss program size to ICache */ A(0x90A40018); W(0x00000003); /* Size x 1024bits */ /* Configure ICache size*/ A(0x90A40000); W(0x00000000); /* Configure ICache to cahce/scratch pad mode*/ A(0x90A40004); W(0x00000000); /* Start ICache initialization*/ A(0x90A40010); W(0x00000000); /* Start the program operation */ A(0x90A00004); W(0x00000001); /* Control vector (two address vector followed by one read/write vector) */ /* WAIT = {Bit[11]} */ /* HPROT = {Bit[10:9], Bit[6:5]} */ /* HLOCK = {Bit[4]} */ /* HsizeGen = {Bit[3:2]} */ A(0xC0000000); for (i = 0; i <= 500; i++) R(0x00000000,All_Mask); /* Parameter 0 */ A(0x24000000); W(0x00000000); A(0x24000004); W(0x00000000); A(0x24000008); W(0x00000000); A(0x2400000C); W(0x00000000); A(0x24000010); W(0x00000000); A(0x24000014); W(0x00000000); A(0x24000018); W(0x00000000); A(0x2400001C); W(0x00000000); A(0x24000020); W(0x00000000); /* Parameter 1 */ A(0x24000030); W(0x00000000); A(0x24000034); W(0x00000000); A(0x24000038); W(0x00000000); A(0x2400003C); W(0x00000000); A(0x24000040); W(0x00000000); A(0x24000044); W(0x00000000); /* Parameter 2 */ A(0x24000050); W(0x00000000); A(0x24000054); W(0x00000000); A(0x24000058); W(0x00000000); A(0x2400005C); W(0x00000000); A(0x24000060); W(0x00000000); A(0x24000064); W(0x00000000); /* Parameter 3 */ A(0x24000070); W(0x00000000); A(0x24000074); W(0x00000000); A(0x24000078); W(0x00000000); A(0x2400007C); W(0x00000000); A(0x24000080); W(0x00000000); A(0x24000084); W(0x00000000); A(0x24000088); W(0x00000000); A(0x2400008C); W(0x00000000); A(0x24000090); W(0x00000000); A(0x24000094); W(0x00000000); A(0x24000098); W(0x00000000); A(0x2400009C); W(0x00000000); /* Result check */ /* Parameter 0 */ A(0x24000000); R(0x0A090807,0xFFFFFFFF); A(0x24000004); R(0x0F0E0C0B,0xFFFFFFFF); A(0x24000008); R(0x13121110,0xFFFFFFFF); A(0x2400000C); R(0x18171615,0xFFFFFFFF); A(0x24000010); R(0x1D1C1A19,0xFFFFFFFF); A(0x24000014); R(0x21201F1E,0xFFFFFFFF); A(0x24000018); R(0x26252423,0xFFFFFFFF); A(0x2400001C); R(0x2B2A2827,0xFFFFFFFF); A(0x24000020); R(0x002E2D2C,0x00FFFFFF); /* Parameter 1 */ A(0x24000030); R(0x33323130,0xFFFFFFFF); A(0x24000034); R(0x38363534,0xFFFFFFFF); A(0x24000038); R(0x3C3B3A39,0xFFFFFFFF); A(0x2400003C); R(0x41403E3D,0xFFFFFFFF); A(0x24000040); R(0x45444342,0xFFFFFFFF); A(0x24000044); R(0x00000046,0x000000FF); /* Parameter 2 */ A(0x24000050); R(0x5A595857,0xFFFFFFFF); A(0x24000054); R(0x605D5C5B,0xFFFFFFFF); A(0x24000058); R(0x64636261,0xFFFFFFFF); A(0x2400005C); R(0x6A696665,0xFFFFFFFF); A(0x24000060); R(0x6E6D6C6B,0xFFFFFFFF); A(0x24000064); R(0x0000006F,0x000000FF); /* Parameter 3 */ A(0x24000070); R(0x77767574,0xFFFFFFFF); A(0x24000074); R(0x7B7A7978,0xFFFFFFFF); A(0x24000078); R(0x827E7D7C,0xFFFFFFFF); A(0x2400007C); R(0x86858483,0xFFFFFFFF); A(0x24000080); R(0x8A898887,0xFFFFFFFF); A(0x24000084); R(0x91908C8B,0xFFFFFFFF); A(0x24000088); R(0x95949392,0xFFFFFFFF); A(0x2400008C); R(0x99989796,0xFFFFFFFF); A(0x24000090); R(0xA09F9E9A,0xFFFFFFFF); A(0x24000094); R(0xA4A3A2A1,0xFFFFFFFF); A(0x24000098); R(0xA8A7A6A5,0xFFFFFFFF); A(0x2400009C); R(0x0000ADAC,0x0000FFFF); E(); return 0; }
int main() { int i ; /* Flush Cache*/ A(0x90A4001C); W(0x00000001); /* Data memory addressing mode (0: not interleaved 1: interleaved) */ A(0x90A80008); W(0x00000000); /* Data memory access priority (0: Core>BIU>CFU 1: BIU>Core>CFU) */ A(0x90A8000C); W(0x00000000); /* Base Address */ A(0x90A80004); W(0x90A00000); /* DBGISR */ A(0x90A0001C); W(0x10000000); /* EXCISR */ A(0x90A00020); W(0x10000000); /* FIQISR */ A(0x90A00024); W(0x10000000); /* IRQISR */ A(0x90A00028); W(0x10000000); /* Start address to PSCU */ A(0x90A00000); W(0x10000000); /* Start Address to ICache */ A(0x90A40008); W(0x10000000); /* Initial program size to ICache */ A(0x90A4000C); W(0x00000B6C); /* Size x 1024bits */ /* Miss program size to ICache */ A(0x90A40018); W(0x00000003); /* Size x 1024bits */ /* Configure ICache size*/ A(0x90A40000); W(0x00000000); /* Configure ICache to cahce/scratch pad mode*/ A(0x90A40004); W(0x00000000); /* Start ICache initialization*/ A(0x90A40010); W(0x00000000); /* Start the program operation */ A(0x90A00004); W(0x00000001); /* Control vector (two address vector followed by one read/write vector) */ /* WAIT = {Bit[11]} */ /* HPROT = {Bit[10:9], Bit[6:5]} */ /* HLOCK = {Bit[4]} */ /* HsizeGen = {Bit[3:2]} */ A(0xC0000000); for (i = 0; i <= 2000; i++) R(0x00000000,All_Mask); A(0x24000000); W(0x00000000); A(0x24000004); W(0x00000000); A(0x24000008); W(0x00000000); A(0x2400000C); W(0x00000000); A(0x24000010); W(0x00000000); A(0x24000014); W(0x00000000); A(0x24000018); W(0x00000000); A(0x2400001C); W(0x00000000); A(0x24000020); W(0x00000000); A(0x24000024); W(0x00000000); A(0x24000028); W(0x00000000); A(0x2400002C); W(0x00000000); /* Parameter 1 */ A(0x24000030); W(0x00000000); A(0x24000034); W(0x00000000); A(0x24000038); W(0x00000000); A(0x2400003C); W(0x00000000); A(0x24000040); W(0x00000000); A(0x24000044); W(0x00000000); A(0x24000048); W(0x00000000); A(0x2400004C); W(0x00000000); A(0x24000050); W(0x00000000); A(0x24000054); W(0x00000000); A(0x24000058); W(0x00000000); A(0x2400005C); W(0x00000000); A(0x24000060); W(0x00000000); A(0x24000064); W(0x00000000); A(0x24000068); W(0x00000000); A(0x2400006C); W(0x00000000); /* Parameter 3 */ A(0x24000150); W(0x00000000); A(0x24000154); W(0x00000000); A(0x24000158); W(0x00000000); A(0x2400015C); W(0x00000000); A(0x24000160); W(0x00000000); A(0x24000164); W(0x00000000); A(0x24000168); W(0x00000000); A(0x2400016C); W(0x00000000); /* Result check */ /* Parameter 0 */ A(0x24000000); R(0x03020100,0xFFFFFF00); A(0x24000004); R(0x00000504,0x0000FFFF); A(0x24000008); R(0x07060000,0xFFFF0000); A(0x2400000C); R(0x000A0908,0x00FFFFFF); A(0x24000010); R(0x12000000,0xFF000000); A(0x24000014); R(0x16151413,0xFFFFFFFF); A(0x24000018); R(0x00000000,0x00000000); A(0x2400001C); R(0x1A191817,0xFFFFFFFF); A(0x24000020); R(0x0000001B,0x000000FF); A(0x24000024); R(0x25242300,0xFFFFFF00); A(0x24000028); R(0x00000026,0x000000FF); A(0x2400002C); R(0x00000000,0x00000000); /* Parameter 1 */ A(0x24000030); R(0x03020100,0xFFFFFFFF); A(0x24000034); R(0x00000004,0x000000FF); A(0x24000038); R(0x07060500,0xFFFFFF00); A(0x2400003C); R(0x00000908,0x0000FFFF); A(0x24000040); R(0x12110000,0xFFFF0000); A(0x24000044); R(0x00151413,0x00FFFFFF); A(0x24000048); R(0x16000000,0xFF000000); A(0x2400004C); R(0x1a191817,0xFFFFFFFF); A(0x24000050); R(0x00000000,0x00000000); A(0x24000054); R(0x25242322,0xFFFFFFFF); A(0x24000058); R(0x00000000,0x00000000); A(0x2400005C); R(0x00000000,0x00000000); A(0x24000060); R(0x00000000,0x00000000); A(0x24000064); R(0x00000000,0x00000000); A(0x24000068); R(0x00000000,0x00000000); A(0x2400006C); R(0x00000000,0x00000000); /* Parameter 3 */ A(0x24000150); R(0x1A020100,0xFFFFFFFF); A(0x24000154); R(0x0000001B,0x000000FF); A(0x24000158); R(0x35341C00,0xFFFFFF00); A(0x2400015C); R(0x00004E36,0x0000FFFF); A(0x24000160); R(0x504F0000,0xFFFF0000); A(0x24000164); R(0x006A6968,0x00FFFFFF); A(0x24000168); R(0x82000000,0xFF000000); A(0x2400016C); R(0x00008483,0x0000FFFF); E(); return 0; }
int main() { int i ; /* Flush Cache*/ A(0x90A4001C); W(0x00000001); /* Data memory addressing mode (0: not interleaved 1: interleaved) */ A(0x90A80008); W(0x00000000); /* Data memory access priority (0: Core>BIU>CFU 1: BIU>Core>CFU) */ A(0x90A8000C); W(0x00000000); /* Base Address */ A(0x90A80004); W(0x90A00000); /* DBGISR */ A(0x90A0001C); W(0x10000000); /* EXCISR */ A(0x90A00020); W(0x10000000); /* FIQISR */ A(0x90A00024); W(0x10000000); /* IRQISR */ A(0x90A00028); W(0x10000000); /* Start address to PSCU */ A(0x90A00000); W(0x10000000); /* Start Address to ICache */ A(0x90A40008); W(0x10000000); /* Initial program size to ICache */ A(0x90A4000C); W(0x00000B6C); /* Size x 1024bits */ /* Miss program size to ICache */ A(0x90A40018); W(0x00000003); /* Size x 1024bits */ /* Configure ICache size*/ A(0x90A40000); W(0x00000000); /* Configure ICache to cahce/scratch pad mode*/ A(0x90A40004); W(0x00000000); /* Start ICache initialization*/ A(0x90A40010); W(0x00000000); /* Start the program operation */ A(0x90A00004); W(0x00000001); /* Control vector (two address vector followed by one read/write vector) */ /* WAIT = {Bit[11]} */ /* HPROT = {Bit[10:9], Bit[6:5]} */ /* HLOCK = {Bit[4]} */ /* HsizeGen = {Bit[3:2]} */ A(0xC0000000); for (i = 0; i <= 2000; i++) R(0x00000000,All_Mask); A(0x25000000); W(0x00000000); A(0x25000004); W(0x00000000); A(0x25000008); W(0x00000000); A(0x2500000C); W(0x00000000); A(0x25000010); W(0x00000000); A(0x25000014); W(0x00000000); A(0x25000018); W(0x00000000); A(0x2500001C); W(0x00000000); A(0x25000020); W(0x00000000); A(0x25000024); W(0x00000000); A(0x25000028); W(0x00000000); A(0x2500002C); W(0x00000000); A(0x25000030); W(0x00000000); A(0x25000034); W(0x00000000); A(0x25000038); W(0x00000000); A(0x2500003C); W(0x00000000); A(0x25000040); W(0x00000000); A(0x25000044); W(0x00000000); A(0x25000048); W(0x00000000); A(0x2500004C); W(0x00000000); A(0x25000050); W(0x00000000); A(0x25000054); W(0x00000000); A(0x25000058); W(0x00000000); A(0x2500005C); W(0x00000000); A(0x25000000); R(0x03020100,0xFFFFFF00); A(0x25000004); R(0x07060504,0xFFFFFFFF); A(0x25000008); R(0x0B0A0908,0xFFFFFFFF); A(0x2500000C); R(0x0F0E0D0C,0xFFFFFFFF); A(0x25000010); R(0x13120000,0xFFFF0000); A(0x25000014); R(0x17161514,0xFFFFFFFF); A(0x25000018); R(0x1B1A1918,0xFFFFFFFF); A(0x2500001C); R(0x1F1E1D1C,0xFFFFFFFF); A(0x25000020); R(0x23000020,0xFF0000FF); A(0x25000024); R(0x27262524,0xFFFFFFFF); A(0x25000028); R(0x2B2A2928,0xFFFFFFFF); A(0x2500002C); R(0x2F2E2D2C,0xFFFFFFFF); A(0x25000030); R(0x00003130,0x0000FFFF); A(0x25000034); R(0x37363534,0xFFFFFFFF); A(0x25000038); R(0x3B3A3938,0xFFFFFFFF); A(0x2500003C); R(0x3F3E3D3C,0xFFFFFFFF); A(0x25000040); R(0x00424140,0x00FFFFFF); A(0x25000044); R(0x47464500,0xFFFFFF00); A(0x25000048); R(0x4B4A4948,0xFFFFFFFF); A(0x2500004C); R(0x4F4E4D4C,0xFFFFFFFF); A(0x25000050); R(0x53525150,0xFFFFFFFF); A(0x25000054); R(0x57560000,0xFFFF0000); A(0x25000058); R(0x5B5A5958,0xFFFFFFFF); A(0x2500005C); R(0x5F5E5D5C,0xFFFFFFFF); E(); return 0; }
int main() { int N = random(); #define P(n,args) p(#n #args, __builtin_##n args) #define Q(n,args) q(#n #args, __builtin_##n args) #define R(n,args) r(#n #args, __builtin_##n args) #define V(n,args) p(#n #args, (__builtin_##n args, 0)) P(types_compatible_p, (int, float)); P(choose_expr, (0, 10, 20)); P(constant_p, (sizeof(10))); P(expect, (N == 12, 0)); V(prefetch, (&N)); V(prefetch, (&N, 1)); V(prefetch, (&N, 1, 0)); // Numeric Constants Q(huge_val, ()); Q(huge_valf, ()); Q(huge_vall, ()); Q(inf, ()); Q(inff, ()); Q(infl, ()); P(fpclassify, (0, 1, 2, 3, 4, 1.0)); P(fpclassify, (0, 1, 2, 3, 4, 1.0f)); P(fpclassify, (0, 1, 2, 3, 4, 1.0l)); Q(nan, ("")); Q(nanf, ("")); Q(nanl, ("")); Q(nans, ("")); Q(nan, ("10")); Q(nanf, ("10")); Q(nanl, ("10")); Q(nans, ("10")); P(isgreater, (1., 2.)); P(isgreaterequal, (1., 2.)); P(isless, (1., 2.)); P(islessequal, (1., 2.)); P(islessgreater, (1., 2.)); P(isunordered, (1., 2.)); P(isinf, (1.)); P(isinf_sign, (1.)); P(isnan, (1.)); // Bitwise & Numeric Functions P(abs, (N)); P(clz, (N)); P(clzl, (N)); P(clzll, (N)); P(ctz, (N)); P(ctzl, (N)); P(ctzll, (N)); P(ffs, (N)); P(ffsl, (N)); P(ffsll, (N)); P(parity, (N)); P(parityl, (N)); P(parityll, (N)); P(popcount, (N)); P(popcountl, (N)); P(popcountll, (N)); Q(powi, (1.2f, N)); Q(powif, (1.2f, N)); Q(powil, (1.2f, N)); // Lib functions int a, b, n = random(); // Avoid optimizing out. char s0[10], s1[] = "Hello"; V(strcat, (s0, s1)); V(strcmp, (s0, s1)); V(strncat, (s0, s1, n)); V(strchr, (s0, s1[0])); V(strrchr, (s0, s1[0])); V(strcpy, (s0, s1)); V(strncpy, (s0, s1, n)); // Object size checking V(__memset_chk, (s0, 0, sizeof s0, n)); V(__memcpy_chk, (s0, s1, sizeof s0, n)); V(__memmove_chk, (s0, s1, sizeof s0, n)); V(__mempcpy_chk, (s0, s1, sizeof s0, n)); V(__strncpy_chk, (s0, s1, sizeof s0, n)); V(__strcpy_chk, (s0, s1, n)); s0[0] = 0; V(__strcat_chk, (s0, s1, n)); P(object_size, (s0, 0)); P(object_size, (s0, 1)); P(object_size, (s0, 2)); P(object_size, (s0, 3)); // Whatever P(bswap16, (N)); P(bswap32, (N)); P(bswap64, (N)); // CHECK: @llvm.bitreverse.i8 // CHECK: @llvm.bitreverse.i16 // CHECK: @llvm.bitreverse.i32 // CHECK: @llvm.bitreverse.i64 P(bitreverse8, (N)); P(bitreverse16, (N)); P(bitreverse32, (N)); P(bitreverse64, (N)); // FIXME // V(clear_cache, (&N, &N+1)); V(trap, ()); R(extract_return_addr, (&N)); P(signbit, (1.0)); return 0; }
void Sqrt () { R(0) = (uint16_t)sqrt((float)R(0)); }
ENDP() PROCEDURE(_ReadI) lword e; link(0); scanf("%li", &e); rF.l = e; unlink(); ENDP() PROCEDURE(_WriteR) real e; /* este tipo se debe añadir a la máquina virtual */ link(0); e=R(fp+(2*sizeof(lword))); printf("%f", e); unlink(); ENDP() PROCEDURE(_ReadR) real e; link(0); scanf("%f", &e); rF.r = e; unlink(); ENDP() PROCEDURE(_WriteL) lword l;
double BlackoilCo2PVT::dRdp(double press, const CompVec& surfvol, PhaseIndex phase) const { const double dp = 100.; return (R(press+dp,surfvol,phase)-R(press,surfvol,phase))/dp; }
format(stream, "%ld", R(instance)); break; case 'X': format(stream, "%lx", R(instance)); break; case 'O': format(stream, "%lo", R(instance)); break; default: format(stream, "%ld", R(instance)); break; } } static void print_character (STREAM stream, D instance, BOOL escape_p, int print_depth) { ignore(print_depth); if (escape_p) { format(stream, "'%c'", R(instance)) } else { format(stream, "%c", R(instance)); } } static void print_float (STREAM stream, D instance, BOOL escape_p, int print_depth) { ignore(escape_p); ignore(print_depth); if (dylan_single_float_p(instance)) { format(stream, "%f", dylan_single_float_data(instance)) } else if (dylan_double_float_p(instance)) { format(stream, "%.15f", dylan_double_float_data(instance)); } else { put_string("{unknown float type}", stream); } } static void print_string (STREAM stream, D instance, BOOL escape_p, int print_depth) {
std::unique_ptr<const bfly::PotentialField<R,d,q>> transform ( const bfly::Context<R,d,q>& context, const Plan<d>& plan, const Amplitude<R,d>& amplitude, const Phase<R,d>& phase, const Box<R,d>& sBox, const Box<R,d>& tBox, const vector<Source<R,d>>& mySources ) { #ifdef TIMING bfly::ResetTimers(); bfly::timer.Start(); #endif typedef complex<R> C; const size_t q_to_d = Pow<q,d>::val; // Extract our communicator and its size MPI_Comm comm = plan.GetComm(); int rank, numProcesses; MPI_Comm_rank( comm, &rank ); MPI_Comm_size( comm, &numProcesses ); // Get the problem-specific parameters const size_t N = plan.GetN(); const size_t log2N = Log2( N ); const array<size_t,d>& myInitialSBoxCoords = plan.GetMyInitialSourceBoxCoords(); const array<size_t,d>& log2InitialSBoxesPerDim = plan.GetLog2InitialSourceBoxesPerDim(); array<size_t,d> mySBoxCoords = myInitialSBoxCoords; array<size_t,d> log2SBoxesPerDim = log2InitialSBoxesPerDim; Box<R,d> mySBox; for( size_t j=0; j<d; ++j ) { mySBox.widths[j] = sBox.widths[j] / (1u<<log2SBoxesPerDim[j]); mySBox.offsets[j] = sBox.offsets[j] + mySBox.widths[j]*mySBoxCoords[j]; } array<size_t,d> myTBoxCoords, log2TBoxesPerDim; myTBoxCoords.fill(0); log2TBoxesPerDim.fill(0); Box<R,d> myTBox; myTBox = tBox; const size_t bootstrap = plan.GetBootstrapSkip(); // Compute the number of source and target boxes that our process is // responsible for initializing weights in size_t log2WeightGridSize = 0; size_t log2LocalSBoxes = 0; size_t log2LocalTBoxes = 0; array<size_t,d> log2LocalSBoxesPerDim, log2LocalTBoxesPerDim; log2LocalTBoxesPerDim.fill(0); for( size_t j=0; j<d; ++j ) { if( log2N-log2SBoxesPerDim[j] >= bootstrap ) log2LocalSBoxesPerDim[j]= (log2N-log2SBoxesPerDim[j]) - bootstrap; else log2LocalSBoxesPerDim[j] = 0; log2LocalTBoxesPerDim[j] = bootstrap; log2LocalSBoxes += log2LocalSBoxesPerDim[j]; log2LocalTBoxes += log2LocalTBoxesPerDim[j]; log2WeightGridSize += log2N-log2SBoxesPerDim[j]; } // Initialize the weights using Lagrangian interpolation on the // smooth component of the kernel. WeightGridList<R,d,q> weightGridList( 1u<<log2WeightGridSize ); #ifdef TIMING bfly::initializeWeightsTimer.Start(); #endif bfly::InitializeWeights ( context, plan, phase, sBox, tBox, mySBox, log2LocalSBoxes, log2LocalSBoxesPerDim, mySources, weightGridList ); #ifdef TIMING bfly::initializeWeightsTimer.Stop(); #endif // Now cut the target domain if necessary for( size_t j=0; j<d; ++j ) { if( log2LocalSBoxesPerDim[j] == 0 ) { log2LocalTBoxesPerDim[j] -= bootstrap - (log2N-log2SBoxesPerDim[j]); log2LocalTBoxes -= bootstrap - (log2N-log2SBoxesPerDim[j]); } } // Start the main recursion loop if( bootstrap == log2N/2 ) { #ifdef TIMING bfly::M2LTimer.Start(); #endif bfly::M2L ( context, plan, amplitude, phase, sBox, tBox, mySBox, myTBox, log2LocalSBoxes, log2LocalTBoxes, log2LocalSBoxesPerDim, log2LocalTBoxesPerDim, weightGridList ); #ifdef TIMING bfly::M2LTimer.Stop(); #endif } for( size_t level=bootstrap+1; level<=log2N; ++level ) { // Compute the width of the nodes at this level array<R,d> wA, wB; for( size_t j=0; j<d; ++j ) { wA[j] = tBox.widths[j] / (1<<level); wB[j] = sBox.widths[j] / (1<<(log2N-level)); } if( log2LocalSBoxes >= d ) { // Refine target domain and coursen the source domain for( size_t j=0; j<d; ++j ) { --log2LocalSBoxesPerDim[j]; ++log2LocalTBoxesPerDim[j]; } log2LocalSBoxes -= d; log2LocalTBoxes += d; // Loop over boxes in target domain. ConstrainedHTreeWalker<d> AWalker( log2LocalTBoxesPerDim ); WeightGridList<R,d,q> oldWeightGridList( weightGridList ); for( size_t tIndex=0; tIndex<(1u<<log2LocalTBoxes); ++tIndex, AWalker.Walk() ) { const array<size_t,d> A = AWalker.State(); // Compute coordinates and center of this target box array<R,d> x0A; for( size_t j=0; j<d; ++j ) x0A[j] = myTBox.offsets[j] + (A[j]+R(1)/R(2))*wA[j]; // Loop over the B boxes in source domain ConstrainedHTreeWalker<d> BWalker( log2LocalSBoxesPerDim ); for( size_t sIndex=0; sIndex<(1u<<log2LocalSBoxes); ++sIndex, BWalker.Walk() ) { const array<size_t,d> B = BWalker.State(); // Compute coordinates and center of this source box array<R,d> p0B; for( size_t j=0; j<d; ++j ) p0B[j] = mySBox.offsets[j] + (B[j]+R(1)/R(2))*wB[j]; // We are storing the interaction pairs source-major const size_t iIndex = sIndex + (tIndex<<log2LocalSBoxes); // Grab the interaction offset for the parent of target box // i interacting with the children of source box k const size_t parentIOffset = ((tIndex>>d)<<(log2LocalSBoxes+d)) + (sIndex<<d); if( level <= log2N/2 ) { #ifdef TIMING bfly::M2MTimer.Start(); #endif bfly::M2M ( context, plan, phase, level, x0A, p0B, wB, parentIOffset, oldWeightGridList, weightGridList[iIndex] ); #ifdef TIMING bfly::M2MTimer.Stop(); #endif } else { array<R,d> x0Ap; array<size_t,d> globalA; size_t ARelativeToAp = 0; for( size_t j=0; j<d; ++j ) { globalA[j] = A[j]+ (myTBoxCoords[j]<<log2LocalTBoxesPerDim[j]); x0Ap[j] = tBox.offsets[j] + (globalA[j]|1)*wA[j]; ARelativeToAp |= (globalA[j]&1)<<j; } #ifdef TIMING bfly::L2LTimer.Start(); #endif bfly::L2L ( context, plan, phase, level, ARelativeToAp, x0A, x0Ap, p0B, wA, wB, parentIOffset, oldWeightGridList, weightGridList[iIndex] ); #ifdef TIMING bfly::L2LTimer.Stop(); #endif } } } } else { const size_t log2NumMerging = d-log2LocalSBoxes; log2LocalSBoxes = 0; for( size_t j=0; j<d; ++j ) log2LocalSBoxesPerDim[j] = 0; // Fully refine target domain and coarsen source domain. // We partition the target domain after the SumScatter. const vector<size_t>& sDimsToMerge = plan.GetSourceDimsToMerge( level ); for( size_t i=0; i<log2NumMerging; ++i ) { const size_t j = sDimsToMerge[i]; if( mySBoxCoords[j] & 1 ) mySBox.offsets[j] -= mySBox.widths[j]; mySBoxCoords[j] /= 2; mySBox.widths[j] *= 2; } for( size_t j=0; j<d; ++j ) { ++log2LocalTBoxesPerDim[j]; ++log2LocalTBoxes; } // Compute the coordinates and center of this source box array<R,d> p0B; for( size_t j=0; j<d; ++j ) p0B[j] = mySBox.offsets[j] + wB[j]/R(2); // Form the partial weights by looping over the boxes in the // target domain. ConstrainedHTreeWalker<d> AWalker( log2LocalTBoxesPerDim ); WeightGridList<R,d,q> partialWeightGridList( 1<<log2LocalTBoxes ); for( size_t tIndex=0; tIndex<(1u<<log2LocalTBoxes); ++tIndex, AWalker.Walk() ) { const array<size_t,d> A = AWalker.State(); // Compute coordinates and center of this target box array<R,d> x0A; for( size_t j=0; j<d; ++j ) x0A[j] = myTBox.offsets[j] + (A[j]+R(1)/R(2))*wA[j]; // Compute the interaction offset of A's parent interacting // with the remaining local source boxes const size_t parentIOffset = ((tIndex>>d)<<(d-log2NumMerging)); if( level <= log2N/2 ) { #ifdef TIMING bfly::M2MTimer.Start(); #endif bfly::M2M ( context, plan, phase, level, x0A, p0B, wB, parentIOffset, weightGridList, partialWeightGridList[tIndex] ); #ifdef TIMING bfly::M2MTimer.Stop(); #endif } else { array<R,d> x0Ap; array<size_t,d> globalA; size_t ARelativeToAp = 0; for( size_t j=0; j<d; ++j ) { globalA[j] = A[j] + (myTBoxCoords[j]<<log2LocalTBoxesPerDim[j]); x0Ap[j] = tBox.offsets[j] + (globalA[j]|1)*wA[j]; ARelativeToAp |= (globalA[j]&1)<<j; } #ifdef TIMING bfly::L2LTimer.Start(); #endif bfly::L2L ( context, plan, phase, level, ARelativeToAp, x0A, x0Ap, p0B, wA, wB, parentIOffset, weightGridList, partialWeightGridList[tIndex] ); #ifdef TIMING bfly::L2LTimer.Stop(); #endif } } // Scatter the summation of the weights #ifdef TIMING bfly::sumScatterTimer.Start(); #endif const size_t recvSize = 2*weightGridList.Length()*q_to_d; // Currently two types of planned communication are supported, as // they are the only required types for transforming and inverting // the transform: // 1) partitions of dimensions 0 -> c // 2) partitions of dimensions c -> d-1 // Both 1 and 2 include partitioning 0 -> d-1, but, in general, // the second category never requires packing. const size_t log2SubclusterSize = plan.GetLog2SubclusterSize(level); if( log2SubclusterSize == 0 ) { MPI_Comm clusterComm = plan.GetClusterComm( level ); SumScatter ( partialWeightGridList.Buffer(), weightGridList.Buffer(), recvSize, clusterComm ); } else { const size_t log2NumSubclusters = log2NumMerging-log2SubclusterSize; const size_t numSubclusters = 1u<<log2NumSubclusters; const size_t subclusterSize = 1u<<log2SubclusterSize; const size_t numChunksPerProcess = subclusterSize; const size_t chunkSize = recvSize / numChunksPerProcess; const R* partialBuffer = partialWeightGridList.Buffer(); vector<R> sendBuffer( recvSize<<log2NumMerging ); for( size_t sc=0; sc<numSubclusters; ++sc ) { R* subclusterSendBuffer = &sendBuffer[sc*subclusterSize*recvSize]; const R* subclusterPartialBuffer = &partialBuffer[sc*subclusterSize*recvSize]; for( size_t p=0; p<subclusterSize; ++p ) { R* processSend = &subclusterSendBuffer[p*recvSize]; for( size_t c=0; c<numChunksPerProcess; ++c ) { memcpy ( &processSend[c*chunkSize], &subclusterPartialBuffer [(p+c*subclusterSize)*chunkSize], chunkSize*sizeof(R) ); } } } MPI_Comm clusterComm = plan.GetClusterComm( level ); SumScatter ( &sendBuffer[0], weightGridList.Buffer(), recvSize, clusterComm ); } #ifdef TIMING bfly::sumScatterTimer.Stop(); #endif const vector<size_t>& tDimsToCut = plan.GetTargetDimsToCut( level ); const vector<bool>& rightSideOfCut=plan.GetRightSideOfCut( level ); for( size_t i=0; i<log2NumMerging; ++i ) { const size_t j = tDimsToCut[i]; myTBox.widths[j] /= 2; myTBoxCoords[j] *= 2; if( rightSideOfCut[i] ) { myTBoxCoords[j] |= 1; myTBox.offsets[j] += myTBox.widths[j]; } --log2LocalTBoxesPerDim[j]; --log2LocalTBoxes; } } if( level==log2N/2 ) { #ifdef TIMING bfly::M2LTimer.Start(); #endif bfly::M2L ( context, plan, amplitude, phase, sBox, tBox, mySBox, myTBox, log2LocalSBoxes, log2LocalTBoxes, log2LocalSBoxesPerDim, log2LocalTBoxesPerDim, weightGridList ); #ifdef TIMING bfly::M2LTimer.Stop(); #endif } }
function(T ob, R(T::*fn)(Args...) ) : m_funpointer(new detail::function_object<T,R(Args...)> (ob,fn)){}
int FHGraphSegmentDepth( const ImgBgr& img, const ImgGray& depth, float sigma, float c, int min_size, ImgInt *out_labels, ImgBgr *out_pseudocolors) { int width = img.Width(); int height = img.Height(); int x, y; ImgFloat R(width, height),G(width, height),B(width, height); iExtractRGBColorSpace(img, &B, &G, &R); ImgFloat smooth_R(width, height), smooth_G(width, height), smooth_B(width, height); ImgFloat D(width, height), smooth_D(width, height); out_labels->Reset(width, height); out_pseudocolors->Reset(width, height); Convert(depth,&D); iSmooth(B, sigma, &smooth_B); iSmooth(G, sigma, &smooth_G); iSmooth(R, sigma, &smooth_R); iSmooth(D, sigma, &smooth_D); std::vector<Edge> edges; int num_edges; iBuildDepthGraph(smooth_R, smooth_G, smooth_B, smooth_D, &edges, &num_edges); Universe u(width*height); iSegment_graph(width*height, num_edges, edges, c, &u); int i; for (i = 0; i < num_edges; i++) { int a = u.find(edges[i].a); int b = u.find(edges[i].b); if ((a != b) && ((u.size(a) < min_size) || (u.size(b) < min_size))) { u.join(a, b); } } int num_ccs = u.num_sets(); std::vector<Bgr> colors; for (i = 0; i < width*height; i++) { Bgr color; random_rgb(&color); colors.push_back(color); } for (y = 0; y < height; y++) { for ( x = 0; x < width; x++) { int comp = u.find(y * width + x); (*out_labels)(x, y) = comp; (*out_pseudocolors)(x, y) = colors[comp]; } } return num_ccs; }
int main() { int i ; /* Flush Cache*/ A(0x90A4001C); W(0x00000001); /* Data memory addressing mode (0: not interleaved 1: interleaved) */ A(0x90A80008); W(0x00000000); /* Data memory access priority (0: Core>BIU>CFU 1: BIU>Core>CFU) */ A(0x90A8000C); W(0x00000000); /* Base Address */ A(0x90A80004); W(0x90A00000); /* DBGISR */ A(0x90A0001C); W(0x10000000); /* EXCISR */ A(0x90A00020); W(0x10000000); /* FIQISR */ A(0x90A00024); W(0x10000000); /* IRQISR */ A(0x90A00028); W(0x10000000); /* Start address to PSCU */ A(0x90A00000); W(0x10000000); /* Start Address to ICache */ A(0x90A40008); W(0x10000000); /* Initial program size to ICache */ A(0x90A4000C); W(0x00000B6C); /* Size x 1024bits */ /* Miss program size to ICache */ A(0x90A40018); W(0x00000003); /* Size x 1024bits */ /* Configure ICache size*/ A(0x90A40000); W(0x00000000); /* Configure ICache to cahce/scratch pad mode*/ A(0x90A40004); W(0x00000000); /* Start ICache initialization*/ A(0x90A40010); W(0x00000000); /* Start the program operation */ A(0x90A00004); W(0x00000001); /* Control vector (two address vector followed by one read/write vector) */ /* WAIT = {Bit[11]} */ /* HPROT = {Bit[10:9], Bit[6:5]} */ /* HLOCK = {Bit[4]} */ /* HsizeGen = {Bit[3:2]} */ A(0xC0000000); for (i = 0; i <= 1000; i++) R(0x00000000,All_Mask); /* Result check */ /* Parameter 1 */ A(0x25000000); R(0x03020100); A(0x25000004); R(0x07060504); A(0x25000008); R(0x00000008); A(0x25000010); R(0x000A0900); A(0x25000018); R(0x00141312); /* Parameter 2 */ A(0x25000020); R(0x1B1A1918); A(0x25000024); R(0x0023221C); E(); return 0; }
inline void HermitianTridiagU( DistMatrix<R>& A ) { #ifndef RELEASE PushCallStack("internal::HermitianTridiagU"); if( A.Height() != A.Width() ) throw std::logic_error( "A must be square." ); #endif const Grid& g = A.Grid(); // Matrix views DistMatrix<R> ATL(g), ATR(g), A00(g), A01(g), A02(g), ABL(g), ABR(g), A10(g), A11(g), A12(g), A20(g), A21(g), A22(g); // Temporary distributions DistMatrix<R> WPan(g); DistMatrix<R,STAR,STAR> A11_STAR_STAR(g); DistMatrix<R,MC, STAR> APan_MC_STAR(g), A01_MC_STAR(g), A11_MC_STAR(g); DistMatrix<R,MR, STAR> APan_MR_STAR(g), A01_MR_STAR(g), A11_MR_STAR(g); DistMatrix<R,MC, STAR> WPan_MC_STAR(g), W01_MC_STAR(g), W11_MC_STAR(g); DistMatrix<R,MR, STAR> WPan_MR_STAR(g), W01_MR_STAR(g), W11_MR_STAR(g); PartitionUpDiagonal ( A, ATL, ATR, ABL, ABR, 0 ); while( ABR.Height() < A.Height() ) { RepartitionUpDiagonal ( ATL, /**/ ATR, A00, A01, /**/ A02, /**/ A10, A11, /**/ A12, /*************/ /******************/ ABL, /**/ ABR, A20, A21, /**/ A22 ); if( A00.Height() > 0 ) { WPan.AlignWith( A01 ); APan_MC_STAR.AlignWith( A00 ); WPan_MC_STAR.AlignWith( A00 ); APan_MR_STAR.AlignWith( A00 ); WPan_MR_STAR.AlignWith( A00 ); //----------------------------------------------------------------// WPan.ResizeTo( ATL.Height(), A11.Width() ); APan_MC_STAR.ResizeTo( ATL.Height(), A11.Width() ); WPan_MC_STAR.ResizeTo( ATL.Height(), A11.Width() ); APan_MR_STAR.ResizeTo( ATL.Height(), A11.Width() ); WPan_MR_STAR.ResizeTo( ATL.Height(), A11.Width() ); HermitianPanelTridiagU ( ATL, WPan, APan_MC_STAR, APan_MR_STAR, WPan_MC_STAR, WPan_MR_STAR ); PartitionUp ( APan_MC_STAR, A01_MC_STAR, A11_MC_STAR, A11.Height() ); PartitionUp ( APan_MR_STAR, A01_MR_STAR, A11_MR_STAR, A11.Height() ); PartitionUp ( WPan_MC_STAR, W01_MC_STAR, W11_MC_STAR, A11.Height() ); PartitionUp ( WPan_MR_STAR, W01_MR_STAR, W11_MR_STAR, A11.Height() ); LocalTrr2k ( UPPER, TRANSPOSE, TRANSPOSE, R(-1), A01_MC_STAR, W01_MR_STAR, W01_MC_STAR, A01_MR_STAR, R(1), A00 ); //----------------------------------------------------------------// WPan_MR_STAR.FreeAlignments(); APan_MR_STAR.FreeAlignments(); WPan_MC_STAR.FreeAlignments(); APan_MC_STAR.FreeAlignments(); WPan.FreeAlignments(); } else { A11_STAR_STAR = A11; HermitianTridiag( UPPER, A11_STAR_STAR.LocalMatrix() ); A11 = A11_STAR_STAR; } SlidePartitionUpDiagonal ( ATL, /**/ ATR, A00, /**/ A01, A02, /*************/ /******************/ /**/ A10, /**/ A11, A12, ABL, /**/ ABR, A20, /**/ A21, A22 ); } #ifndef RELEASE PopCallStack(); #endif }
static void add_instrumentation(void) { static u8 line[MAX_AS_LINE]; FILE* inf; FILE* outf; s32 outfd; u32 ins_lines = 0; u8 instr_ok = 0, skip_csect = 0, skip_next_label = 0; #ifdef __APPLE__ u8* colon_pos; #endif /* __APPLE__ */ if (input_file) { inf = fopen(input_file, "r"); if (!inf) PFATAL("Unable to read '%s'", input_file); } else inf = stdin; outfd = open(modified_file, O_WRONLY | O_EXCL | O_CREAT, 0600); if (outfd < 0) PFATAL("Unable to write to '%s'", modified_file); outf = fdopen(outfd, "w"); if (!outf) PFATAL("fdopen() failed"); while (fgets(line, MAX_AS_LINE, inf)) { fputs(line, outf); if (pass_thru) continue; /* We only want to instrument the .text section. So, let's keep track of that in processed files. */ if (line[0] == '\t' && line[1] == '.') { /* OpenBSD puts jump tables directly inline with the code, which is a bit annoying. They use a specific format of p2align directives around them, so we use that as a signal. */ if (!clang_mode && instr_ok && !strncmp(line + 2, "p2align ", 8) && isdigit(line[10]) && line[11] == '\n') skip_next_label = 1; if (!strncmp(line + 2, "text\n", 5) || !strncmp(line + 2, "section\t.text", 13) || !strncmp(line + 2, "section\t__TEXT,__text", 21) || !strncmp(line + 2, "section __TEXT,__text", 21)) { instr_ok = 1; continue; } if (!strncmp(line + 2, "section\t", 8) || !strncmp(line + 2, "section ", 8) || !strncmp(line + 2, "bss\n", 4) || !strncmp(line + 2, "data\n", 5)) { instr_ok = 0; continue; } } if (strstr(line, ".code")) { if (strstr(line, ".code32")) skip_csect = use_64bit; if (strstr(line, ".code64")) skip_csect = !use_64bit; } /* If we're in the right mood for instrumenting, check for function names or conditional labels. This is a bit messy, but in essence, we want to catch: ^main: - function entry point (always instrumented) ^.L0: - GCC branch label ^.LBB0_0: - clang branch label (but only in clang mode) ^\tjnz foo - conditional branches ...but not: ^# BB#0: - clang comments ^ # BB#0: - ditto ^.Ltmp0: - clang non-branch labels ^.LC0 - GCC non-branch labels ^\tjmp foo - non-conditional jumps Additionally, for clang on MacOS X follows a different convention with no leading dots on labels, hence the weird maze of #ifdefs later on. */ if (skip_csect || !instr_ok || line[0] == '#' || line[0] == ' ') continue; /* Conditional branch instruction (jnz, etc). */ if (line[0] == '\t') { if (line[1] == 'j' && line[2] != 'm' && R(100) < inst_ratio) { fprintf(outf, use_64bit ? trampoline_fmt_64 : trampoline_fmt_32, R(MAP_SIZE)); ins_lines++; } continue; } /* Label of some sort. */ #ifdef __APPLE__ /* Apple: L<whatever><digit>: */ if ((colon_pos = strstr(line, ":"))) { if (line[0] == 'L' && isdigit(*(colon_pos - 1))) { #else /* Everybody else: .L<whatever>: */ if (strstr(line, ":")) { if (line[0] == '.') { #endif /* __APPPLE__ */ /* .L0: or LBB0_0: style jump destination */ #ifdef __APPLE__ /* Apple: L<num> / LBB<num> */ if ((isdigit(line[1]) || (clang_mode && !strncmp(line, "LBB", 3))) && R(100) < inst_ratio) { #else /* Apple: .L<num> / .LBB<num> */ if ((isdigit(line[2]) || (clang_mode && !strncmp(line + 1, "LBB", 3))) && R(100) < inst_ratio) { #endif /* __APPLE__ */ if (!skip_next_label) { fprintf(outf, use_64bit ? trampoline_fmt_64 : trampoline_fmt_32, R(MAP_SIZE)); ins_lines++; } else skip_next_label = 0; } } else { /* Function label (always instrumented) */ fprintf(outf, use_64bit ? trampoline_fmt_64 : trampoline_fmt_32, R(MAP_SIZE)); ins_lines++; } } } if (ins_lines) fputs(use_64bit ? main_payload_64 : main_payload_32, outf); if (input_file) fclose(inf); fclose(outf); if (!be_quiet) { if (!ins_lines) WARNF("No instrumentation targets found."); else OKF("Instrumented %u locations (%s-bit, %s mode, ratio %u%%).", ins_lines, use_64bit ? "64" : "32", getenv("AFL_HARDEN") ? "hardened" : "non-hardened", inst_ratio); } } /* Main entry point */ int main(int argc, char** argv) { s32 pid; u32 rand_seed; int status; u8* inst_ratio_str = getenv("AFL_INST_RATIO"); struct timeval tv; struct timezone tz; clang_mode = !!getenv("__AFL_CLANG_MODE"); if (isatty(2) && !getenv("AFL_QUIET")) { SAYF(cCYA "afl-as " cBRI VERSION cRST " (" __DATE__ " " __TIME__ ") by <*****@*****.**>\n"); } else be_quiet = 1; if (argc < 2) { SAYF("\n" "This is a helper application for afl-fuzz. It is a wrapper around GNU 'as',\n" "executed by the toolchain whenever using afl-gcc or afl-clang. You probably\n" "don't want to run this program directly.\n\n" "Rarely, when dealing with extremely complex projects, it may be advisable to\n" "set AFL_INST_RATIO to a value less than 100 in order to reduce the odds of\n" "instrumenting every discovered branch.\n\n"); exit(1); } gettimeofday(&tv, &tz); rand_seed = tv.tv_sec ^ tv.tv_usec ^ getpid(); srandom(rand_seed); edit_params(argc, argv); if (inst_ratio_str) { if (sscanf(inst_ratio_str, "%u", &inst_ratio) != 1 || inst_ratio > 100) FATAL("Bad value of AFL_INST_RATIO (must be between 0 and 100)"); } if (getenv("__AFL_AS_BEENHERE")) FATAL("Endless loop when calling 'as' (remove '.' from your PATH)"); setenv("__AFL_AS_BEENHERE", "1", 1); /* When compiling with ASAN, we don't have a particularly elegant way to skip ASAN-specific branches. But we can probabilistically compensate for that... */ if (getenv("AFL_USE_ASAN")) inst_ratio /= 3; add_instrumentation(); if (!(pid = fork())) { execvp(as_params[0], (char**)as_params); FATAL("Oops, failed to execute '%s' - check your PATH", as_params[0]); } if (pid < 0) PFATAL("fork() failed"); if (waitpid(pid, &status, 0) <= 0) PFATAL("waitpid() failed"); if (!getenv("AFL_KEEP_ASSEMBLY")) unlink(modified_file); exit(WEXITSTATUS(status)); }
vep_do_include(struct vep_state *vep, enum dowhat what) { const char *p, *q, *h; ssize_t l; Debug("DO_INCLUDE(%d)\n", what); if (what == DO_ATTR) { Debug("ATTR (%s) (%s)\n", vep->match_hit->match, VSB_data(vep->attr_vsb)); if (vep->include_src != NULL) { vep_error(vep, "ESI 1.0 <esi:include> " "has multiple src= attributes"); vep->state = VEP_TAGERROR; VSB_destroy(&vep->attr_vsb); VSB_destroy(&vep->include_src); return; } vep->include_src = vep->attr_vsb; vep->attr_vsb = NULL; return; } assert(what == DO_TAG); if (!vep->emptytag) vep_warn(vep, "ESI 1.0 <esi:include> lacks final '/'"); if (vep->include_src == NULL) { vep_error(vep, "ESI 1.0 <esi:include> lacks src attr"); return; } /* * Strictly speaking, we ought to spit out any piled up skip before * emitting the VEC for the include, but objectively that makes no * difference and robs us of a chance to collapse another skip into * this on so we don't do that. * However, we cannot tolerate any verbatim stuff piling up. * The mark_skip() before calling dostuff should have taken * care of that. Make sure. */ assert(vep->o_wait == 0 || vep->last_mark == SKIP); /* XXX: what if it contains NUL bytes ?? */ p = VSB_data(vep->include_src); l = VSB_len(vep->include_src); h = 0; if (l > 7 && !memcmp(p, "http://", 7)) { h = p + 7; p = strchr(h, '/'); AN(p); Debug("HOST <%.*s> PATH <%s>\n", (int)(p-h),h, p); VSB_printf(vep->vsb, "%c", VEC_INCL); VSB_printf(vep->vsb, "Host: %.*s%c", (int)(p-h), h, 0); } else if (l > 8 && !memcmp(p, "https://", 8)) { if (!FEATURE(FEATURE_ESI_IGNORE_HTTPS)) { vep_warn(vep, "ESI 1.0 <esi:include> with https:// ignored"); vep->state = VEP_TAGERROR; AZ(vep->attr_vsb); VSB_destroy(&vep->include_src); return; } vep_warn(vep, "ESI 1.0 <esi:include> https:// treated as http://"); h = p + 8; p = strchr(h, '/'); AN(p); VSB_printf(vep->vsb, "%c", VEC_INCL); VSB_printf(vep->vsb, "Host: %.*s%c", (int)(p-h), h, 0); } else if (*p == '/') { VSB_printf(vep->vsb, "%c", VEC_INCL); VSB_printf(vep->vsb, "%c", 0); } else { VSB_printf(vep->vsb, "%c", VEC_INCL); VSB_printf(vep->vsb, "%c", 0); /* Look for the last / before a '?' */ h = NULL; for (q = vep->url; *q && *q != '?'; q++) if (*q == '/') h = q; if (h == NULL) h = q + 1; Debug("INCL:: [%.*s]/[%s]\n", (int)(h - vep->url), vep->url, p); VSB_printf(vep->vsb, "%.*s/", (int)(h - vep->url), vep->url); } l -= (p - VSB_data(vep->include_src)); for (q = p; *q != '\0'; ) { if (*q == '&') { #define R(w,f,r) \ if (q + w <= p + l && !memcmp(q, f, w)) { \ VSB_printf(vep->vsb, "%c", r); \ q += w; \ continue; \ } R(6, "'", '\''); R(6, """, '"'); R(4, "<", '<'); R(4, ">", '>'); R(5, "&", '&'); } VSB_printf(vep->vsb, "%c", *q++); } #undef R VSB_printf(vep->vsb, "%c", 0); VSB_destroy(&vep->include_src); }
TMat4 TMat4::operator * (const TMat4 &m) const { #define N(x,y) row[x][y] #define M(x,y) m[x][y] #define R(x,y) result[x][y] TMat4 result; R(0,0) = N(0,0) * M(0,0) + N(0,1) * M(1,0) + N(0,2) * M(2,0) + N(0,3) * M(3,0); R(0,1) = N(0,0) * M(0,1) + N(0,1) * M(1,1) + N(0,2) * M(2,1) + N(0,3) * M(3,1); R(0,2) = N(0,0) * M(0,2) + N(0,1) * M(1,2) + N(0,2) * M(2,2) + N(0,3) * M(3,2); R(0,3) = N(0,0) * M(0,3) + N(0,1) * M(1,3) + N(0,2) * M(2,3) + N(0,3) * M(3,3); R(1,0) = N(1,0) * M(0,0) + N(1,1) * M(1,0) + N(1,2) * M(2,0) + N(1,3) * M(3,0); R(1,1) = N(1,0) * M(0,1) + N(1,1) * M(1,1) + N(1,2) * M(2,1) + N(1,3) * M(3,1); R(1,2) = N(1,0) * M(0,2) + N(1,1) * M(1,2) + N(1,2) * M(2,2) + N(1,3) * M(3,2); R(1,3) = N(1,0) * M(0,3) + N(1,1) * M(1,3) + N(1,2) * M(2,3) + N(1,3) * M(3,3); R(2,0) = N(2,0) * M(0,0) + N(2,1) * M(1,0) + N(2,2) * M(2,0) + N(2,3) * M(3,0); R(2,1) = N(2,0) * M(0,1) + N(2,1) * M(1,1) + N(2,2) * M(2,1) + N(2,3) * M(3,1); R(2,2) = N(2,0) * M(0,2) + N(2,1) * M(1,2) + N(2,2) * M(2,2) + N(2,3) * M(3,2); R(2,3) = N(2,0) * M(0,3) + N(2,1) * M(1,3) + N(2,2) * M(2,3) + N(2,3) * M(3,3); R(3,0) = N(3,0) * M(0,0) + N(3,1) * M(1,0) + N(3,2) * M(2,0) + N(3,3) * M(3,0); R(3,1) = N(3,0) * M(0,1) + N(3,1) * M(1,1) + N(3,2) * M(2,1) + N(3,3) * M(3,1); R(3,2) = N(3,0) * M(0,2) + N(3,1) * M(1,2) + N(3,2) * M(2,2) + N(3,3) * M(3,2); R(3,3) = N(3,0) * M(0,3) + N(3,1) * M(1,3) + N(3,2) * M(2,3) + N(3,3) * M(3,3); return(result); #undef N #undef M #undef R }
/** * salsa20_8(B): * Apply the salsa20/8 core to the provided block. */ static void salsa20_8(uint8_t B[64]) { uint32_t B32[16]; uint32_t x[16]; size_t i; /* Convert little-endian values in. */ for (i = 0; i < 16; i++) B32[i] = scrypt_le32dec(&B[i * 4]); /* Compute x = doubleround^4(B32). */ for (i = 0; i < 16; i++) x[i] = B32[i]; for (i = 0; i < 8; i += 2) { #define R(a,b) (((a) << (b)) | ((a) >> (32 - (b)))) /* Operate on columns. */ x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9); x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18); x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9); x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18); x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9); x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18); x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9); x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18); /* Operate on rows. */ x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9); x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18); x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9); x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18); x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9); x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18); x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9); x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18); #undef R } /* Compute B32 = B32 + x. */ for (i = 0; i < 16; i++) B32[i] += x[i]; /* Convert little-endian values out. */ for (i = 0; i < 16; i++) scrypt_le32enc(&B[4 * i], B32[i]); }
I4("vram", &vramblock), I4("hi ", &hiofs), I4("pal ", &palofs), I4("oam ", &oamofs), I4("wav ", &wavofs), /* NOSAVE is a special code to prevent the rest of the table * from being saved, used to support old stuff for backwards * compatibility... */ NOSAVE, /* the following are obsolete as of 0x104 */ I4("hram", &hramofs), R(P1), R(SB), R(SC), R(DIV), R(TIMA), R(TMA), R(TAC), R(IE), R(IF), R(LCDC), R(STAT), R(LY), R(LYC), R(SCX), R(SCY), R(WX), R(WY), R(BGP), R(OBP0), R(OBP1), R(DMA), R(VBK), R(SVBK), R(KEY1), R(BCPS), R(BCPD), R(OCPS), R(OCPD), R(NR10), R(NR11), R(NR12), R(NR13), R(NR14), R(NR21), R(NR22), R(NR23), R(NR24), R(NR30), R(NR31), R(NR32), R(NR33), R(NR34), R(NR41), R(NR42), R(NR43), R(NR44), R(NR50), R(NR51), R(NR52),
R container_cast(C&& from) { return R(begin(from), end(from)); }
static void add_screen(xcb_randr_get_screen_info_reply_t *reply) { const gchar *title = "Display"; GtkWidget *item = gtk_menu_item_new_with_label(title); GtkMenuShell *menu = GTK_MENU_SHELL(app_menu); struct screen_info *info = g_malloc(sizeof *info); xcb_randr_rotation_t rotation = normalize_rotation(reply->rotation); xcb_randr_rotation_t rotations = reply->rotations; info->label_menu_item = item; info->rotation_menu_group = NULL; info->rotation = rotation; info->config_timestamp = reply->config_timestamp; info->root = reply->root; info->sizeID = reply->sizeID; info->rate = reply->rate; screens_info = g_slist_append(screens_info, info); gtk_widget_set_sensitive(item, FALSE); gtk_menu_shell_append(menu, item); #define R(rot, title) \ if (rotations & XCB_RANDR_ROTATION_##rot) \ add_screen_rotation(info, XCB_RANDR_ROTATION_##rot, title, \ XCB_RANDR_ROTATION_##rot & rotation) R(ROTATE_0, "Landscape"); R(ROTATE_90, "Portrait"); R(ROTATE_180, "Landscape Flipped"); R(ROTATE_270, "Portrait Flipped"); if (rotations & xcb_rotations_mask && rotations & xcb_reflections_mask) gtk_menu_shell_append(menu, gtk_separator_menu_item_new()); R(REFLECT_X, "Reflected X"); R(REFLECT_Y, "Reflected Y"); #undef R gtk_menu_shell_append(menu, gtk_separator_menu_item_new()); gtk_widget_show_all(app_menu); /* Get screen resources */ xcb_randr_get_screen_resources_current_cookie_t resources_cookie; xcb_randr_get_screen_resources_current_reply_t *resources_reply; xcb_generic_error_t *err = NULL; resources_cookie = xcb_randr_get_screen_resources_current(conn, info->root); resources_reply = xcb_randr_get_screen_resources_current_reply(conn, resources_cookie, &err); if (err) { g_warning("Get Screen Resources returned error %u\n", err->error_code); return; } /* Get screen outputs */ xcb_randr_output_t *outputs; guint i; gchar *output_name; outputs = xcb_randr_get_screen_resources_current_outputs(resources_reply); for (i = 0; i < resources_reply->num_outputs; i++) { xcb_randr_get_output_info_reply_t *output_info_reply; xcb_randr_get_output_info_cookie_t output_info_cookie = xcb_randr_get_output_info_unchecked(conn, outputs[i], resources_reply->config_timestamp); output_info_reply = xcb_randr_get_output_info_reply(conn, output_info_cookie, NULL); /* Show only if connected */ switch (output_info_reply->connection) { case XCB_RANDR_CONNECTION_DISCONNECTED: case XCB_RANDR_CONNECTION_UNKNOWN: continue; case XCB_RANDR_CONNECTION_CONNECTED: break; } output_name = get_output_name(output_info_reply); /* Put output names on the menu */ gtk_menu_item_set_label(GTK_MENU_ITEM(item), output_name); g_free(output_name); /* TODO: concatenate multiple names or pick them intelligently */ } }
void Bios130h () { debug("IRQ end"); // ldmfd r13!,r0-r3,r12,r14 uint32_t add = R(13) & 0xFFFFFFFC; R( 0) = MEM.Read32(add ); R( 1) = MEM.Read32(add += 4); R( 2) = MEM.Read32(add += 4); R( 3) = MEM.Read32(add += 4); R(12) = MEM.Read32(add += 4); R(14) = MEM.Read32(add + 4); R(13) += 6*4; // subs r15,r14,4h R(15) = R(14); if (CPU.Spsr().b.thumb) R(15) -= 2; CPU.SwitchModeBack(); // XXX FIXME, usefull ? test on breath of fire ! /*if (FLAG_T) R(15) &= 0xFFFFFFFE; else R(15) &= 0xFFFFFFFC;*/ }