NumArray(vector<int> nums) { head = build(nums,0,nums.size()-1,head); }
AORemoteCtrl::AORemoteCtrl() { setIsChrome(TRUE); build(); setFocusRoot(TRUE); }
void SFBerlekamp(vec_ZZ_pX& factors, const ZZ_pX& ff, long verbose) { ZZ_pX f = ff; if (!IsOne(LeadCoeff(f))) LogicError("SFBerlekamp: bad args"); if (deg(f) == 0) { factors.SetLength(0); return; } if (deg(f) == 1) { factors.SetLength(1); factors[0] = f; return; } double t; const ZZ& p = ZZ_p::modulus(); long n = deg(f); ZZ_pXModulus F; build(F, f); ZZ_pX g, h; if (verbose) { cerr << "computing X^p..."; t = GetTime(); } PowerXMod(g, p, F); if (verbose) { cerr << (GetTime()-t) << "\n"; } vec_long D; long r; vec_ZZVec M; if (verbose) { cerr << "building matrix..."; t = GetTime(); } BuildMatrix(M, n, g, F, verbose); if (verbose) { cerr << (GetTime()-t) << "\n"; } if (verbose) { cerr << "diagonalizing..."; t = GetTime(); } NullSpace(r, D, M, verbose); if (verbose) { cerr << (GetTime()-t) << "\n"; } if (verbose) cerr << "number of factors = " << r << "\n"; if (r == 1) { factors.SetLength(1); factors[0] = f; return; } if (verbose) { cerr << "factor extraction..."; t = GetTime(); } vec_ZZ_p roots; RandomBasisElt(g, D, M); MinPolyMod(h, g, F, r); if (deg(h) == r) M.kill(); FindRoots(roots, h); FindFactors(factors, f, g, roots); ZZ_pX g1; vec_ZZ_pX S, S1; long i; while (factors.length() < r) { if (verbose) cerr << "+"; RandomBasisElt(g, D, M); S.kill(); for (i = 0; i < factors.length(); i++) { const ZZ_pX& f = factors[i]; if (deg(f) == 1) { append(S, f); continue; } build(F, f); rem(g1, g, F); if (deg(g1) <= 0) { append(S, f); continue; } MinPolyMod(h, g1, F, min(deg(f), r-factors.length()+1)); FindRoots(roots, h); S1.kill(); FindFactors(S1, f, g1, roots); append(S, S1); } swap(factors, S); } if (verbose) { cerr << (GetTime()-t) << "\n"; } if (verbose) { cerr << "degrees:"; long i; for (i = 0; i < factors.length(); i++) cerr << " " << deg(factors[i]); cerr << "\n"; } }
DocParser::DocParser(const QString &name) : m_doc_file(name), m_dom(0) { build(); }
Entity::Entity(const std::string& name, const std::string& type, Engine* engine) : _name(name), _type(type), _engine(engine), _id(0) { build(); }
MM_BEGIN_NAMESPACE MShape::MShape(const QVector<QPointF>& vertices_) : _isLocked(false) { setVertices(vertices_); build(); }
void init(int n){root=build(1, n);}
static void do_build_assign_ref (tree fndecl) { tree parm = TREE_CHAIN (DECL_ARGUMENTS (fndecl)); tree compound_stmt; compound_stmt = begin_compound_stmt (/*has_no_scope=*/false); parm = convert_from_reference (parm); if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type) && is_empty_class (current_class_type)) /* Don't copy the padding byte; it might not have been allocated if *this is a base subobject. */; else if (TYPE_HAS_TRIVIAL_ASSIGN_REF (current_class_type)) { tree t = build (MODIFY_EXPR, void_type_node, current_class_ref, parm); finish_expr_stmt (t); } else { tree fields; int cvquals = cp_type_quals (TREE_TYPE (parm)); int i; /* Assign to each of the direct base classes. */ for (i = 0; i < CLASSTYPE_N_BASECLASSES (current_class_type); ++i) { tree binfo; tree converted_parm; binfo = BINFO_BASETYPE (TYPE_BINFO (current_class_type), i); /* We must convert PARM directly to the base class explicitly since the base class may be ambiguous. */ converted_parm = build_base_path (PLUS_EXPR, parm, binfo, 1); /* Call the base class assignment operator. */ finish_expr_stmt (build_special_member_call (current_class_ref, ansi_assopname (NOP_EXPR), build_tree_list (NULL_TREE, converted_parm), binfo, LOOKUP_NORMAL | LOOKUP_NONVIRTUAL)); } /* Assign to each of the non-static data members. */ for (fields = TYPE_FIELDS (current_class_type); fields; fields = TREE_CHAIN (fields)) { tree comp = current_class_ref; tree init = parm; tree field = fields; tree expr_type; int quals; if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field)) continue; expr_type = TREE_TYPE (field); if (CP_TYPE_CONST_P (expr_type)) { error ("non-static const member `%#D', can't use default assignment operator", field); continue; } else if (TREE_CODE (expr_type) == REFERENCE_TYPE) { error ("non-static reference member `%#D', can't use default assignment operator", field); continue; } if (DECL_NAME (field)) { if (VFIELD_NAME_P (DECL_NAME (field))) continue; /* True for duplicate members. */ if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) continue; } else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type)) /* Just use the field; anonymous types can't have nontrivial copy ctors or assignment ops. */; else continue; comp = build (COMPONENT_REF, TREE_TYPE (field), comp, field); /* Compute the type of init->field */ quals = cvquals; if (DECL_MUTABLE_P (field)) quals &= ~TYPE_QUAL_CONST; expr_type = cp_build_qualified_type (expr_type, quals); init = build (COMPONENT_REF, expr_type, init, field); if (DECL_NAME (field)) init = build_modify_expr (comp, NOP_EXPR, init); else init = build (MODIFY_EXPR, TREE_TYPE (comp), comp, init); finish_expr_stmt (init); } } finish_return_stmt (current_class_ref); finish_compound_stmt (compound_stmt); }
void PLTFile::rebuild() { build(); refresh(); }
void BinarySwitch::build(unsigned start, bool hardStart, unsigned end) { unsigned size = end - start; RELEASE_ASSERT(size); // This code uses some random numbers to keep things balanced. It's important to keep in mind // that this does not improve average-case throughput under the assumption that all cases fire // with equal probability. It just ensures that there will not be some switch structure that // when combined with some input will always produce pathologically good or pathologically bad // performance. const unsigned leafThreshold = 3; if (size <= leafThreshold) { // It turns out that for exactly three cases or less, it's better to just compare each // case individually. This saves 1/6 of a branch on average, and up to 1/3 of a branch in // extreme cases where the divide-and-conquer bottoms out in a lot of 3-case subswitches. // // This assumes that we care about the cost of hitting some case more than we care about // bottoming out in a default case. I believe that in most places where we use switch // statements, we are more likely to hit one of the cases than we are to fall through to // default. Intuitively, if we wanted to improve the performance of default, we would // reduce the value of leafThreshold to 2 or even to 1. See below for a deeper discussion. bool allConsecutive = false; if ((hardStart || (start && m_cases[start - 1].value == m_cases[start].value - 1)) && start + size < m_cases.size() && m_cases[start + size - 1].value == m_cases[start + size].value - 1) { allConsecutive = true; for (unsigned i = 0; i < size - 1; ++i) { if (m_cases[i].value + 1 != m_cases[i + 1].value) { allConsecutive = false; break; } } } Vector<unsigned, 3> localCaseIndices; for (unsigned i = 0; i < size; ++i) localCaseIndices.append(start + i); std::random_shuffle( localCaseIndices.begin(), localCaseIndices.end(), [this] (unsigned n) { // We use modulo to get a random number in the range we want fully knowing that // this introduces a tiny amount of bias, but we're fine with such tiny bias. return m_weakRandom.getUint32() % n; }); for (unsigned i = 0; i < size - 1; ++i) { m_branches.append(BranchCode(NotEqualToPush, localCaseIndices[i])); m_branches.append(BranchCode(ExecuteCase, localCaseIndices[i])); m_branches.append(BranchCode(Pop)); } if (!allConsecutive) m_branches.append(BranchCode(NotEqualToFallThrough, localCaseIndices.last())); m_branches.append(BranchCode(ExecuteCase, localCaseIndices.last())); return; } // There are two different strategies we could consider here: // // Isolate median and split: pick a median and check if the comparison value is equal to it; // if so, execute the median case. Otherwise check if the value is less than the median, and // recurse left or right based on this. This has two subvariants: we could either first test // equality for the median and then do the less-than, or we could first do the less-than and // then check equality on the not-less-than path. // // Ignore median and split: do a less-than comparison on a value that splits the cases in two // equal-sized halves. Recurse left or right based on the comparison. Do not test for equality // against the median (or anything else); let the recursion handle those equality comparisons // once we bottom out in a list that case 3 cases or less (see above). // // I'll refer to these strategies as Isolate and Ignore. I initially believed that Isolate // would be faster since it leads to less branching for some lucky cases. It turns out that // Isolate is almost a total fail in the average, assuming all cases are equally likely. How // bad Isolate is depends on whether you believe that doing two consecutive branches based on // the same comparison is cheaper than doing the compare/branches separately. This is // difficult to evaluate. For small immediates that aren't blinded, we just care about // avoiding a second compare instruction. For large immediates or when blinding is in play, we // also care about the instructions used to materialize the immediate a second time. Isolate // can help with both costs since it involves first doing a < compare+branch on some value, // followed by a == compare+branch on the same exact value (or vice-versa). Ignore will do a < // compare+branch on some value, and then the == compare+branch on that same value will happen // much later. // // To evaluate these costs, I wrote the recurrence relation for Isolate and Ignore, assuming // that ComparisonCost is the cost of a compare+branch and ChainedComparisonCost is the cost // of a compare+branch on some value that you've just done another compare+branch for. These // recurrence relations compute the total cost incurred if you executed the switch statement // on each matching value. So the average cost of hitting some case can be computed as // Isolate[n]/n or Ignore[n]/n, respectively for the two relations. // // Isolate[1] = ComparisonCost // Isolate[2] = (2 + 1) * ComparisonCost // Isolate[3] = (3 + 2 + 1) * ComparisonCost // Isolate[n_] := With[ // {medianIndex = Floor[n/2] + If[EvenQ[n], RandomInteger[], 1]}, // ComparisonCost + ChainedComparisonCost + // (ComparisonCost * (medianIndex - 1) + Isolate[medianIndex - 1]) + // (2 * ComparisonCost * (n - medianIndex) + Isolate[n - medianIndex])] // // Ignore[1] = ComparisonCost // Ignore[2] = (2 + 1) * ComparisonCost // Ignore[3] = (3 + 2 + 1) * ComparisonCost // Ignore[n_] := With[ // {medianIndex = If[EvenQ[n], n/2, Floor[n/2] + RandomInteger[]]}, // (medianIndex * ComparisonCost + Ignore[medianIndex]) + // ((n - medianIndex) * ComparisonCost + Ignore[n - medianIndex])] // // This does not account for the average cost of hitting the default case. See further below // for a discussion of that. // // It turns out that for ComparisonCost = 1 and ChainedComparisonCost = 1, Ignore is always // better than Isolate. If we assume that ChainedComparisonCost = 0, then Isolate wins for // switch statements that have 20 cases or fewer, though the margin of victory is never large // - it might sometimes save an average of 0.3 ComparisonCost. For larger switch statements, // we see divergence between the two with Ignore winning. This is of course rather // unrealistic since the chained comparison is never free. For ChainedComparisonCost = 0.5, we // see Isolate winning for 10 cases or fewer, by maybe 0.2 ComparisonCost. Again we see // divergence for large switches with Ignore winning, for example if a switch statement has // 100 cases then Ignore saves one branch on average. // // Our current JIT backends don't provide for optimization for chained comparisons, except for // reducing the code for materializing the immediate if the immediates are large or blinding // comes into play. Probably our JIT backends live somewhere north of // ChainedComparisonCost = 0.5. // // This implies that using the Ignore strategy is likely better. If we wanted to incorporate // the Isolate strategy, we'd want to determine the switch size threshold at which the two // cross over and then use Isolate for switches that are smaller than that size. // // The average cost of hitting the default case is similar, but involves a different cost for // the base cases: you have to assume that you will always fail each branch. For the Ignore // strategy we would get this recurrence relation; the same kind of thing happens to the // Isolate strategy: // // Ignore[1] = ComparisonCost // Ignore[2] = (2 + 2) * ComparisonCost // Ignore[3] = (3 + 3 + 3) * ComparisonCost // Ignore[n_] := With[ // {medianIndex = If[EvenQ[n], n/2, Floor[n/2] + RandomInteger[]]}, // (medianIndex * ComparisonCost + Ignore[medianIndex]) + // ((n - medianIndex) * ComparisonCost + Ignore[n - medianIndex])] // // This means that if we cared about the default case more, we would likely reduce // leafThreshold. Reducing it to 2 would reduce the average cost of the default case by 1/3 // in the most extreme cases (num switch cases = 3, 6, 12, 24, ...). But it would also // increase the average cost of taking one of the non-default cases by 1/3. Typically the // difference is 1/6 in either direction. This makes it a very simple trade-off: if we believe // that the default case is more important then we would want leafThreshold to be 2, and the // default case would become 1/6 faster on average. But we believe that most switch statements // are more likely to take one of the cases than the default, so we use leafThreshold = 3 // and get a 1/6 speed-up on average for taking an explicit case. unsigned medianIndex = (start + end) / 2; // We want medianIndex to point to the thing we will do a less-than compare against. We want // this less-than compare to split the current sublist into equal-sized sublists, or // nearly-equal-sized with some randomness if we're in the odd case. With the above // calculation, in the odd case we will have medianIndex pointing at either the element we // want or the element to the left of the one we want. Consider the case of five elements: // // 0 1 2 3 4 // // start will be 0, end will be 5. The average is 2.5, which rounds down to 2. If we do // value < 2, then we will split the list into 2 elements on the left and three on the right. // That's pretty good, but in this odd case we'd like to at random choose 3 instead to ensure // that we don't become unbalanced on the right. This does not improve throughput since one // side will always get shafted, and that side might still be odd, in which case it will also // have two sides and one of them will get shafted - and so on. We just want to avoid // deterministic pathologies. // // In the even case, we will always end up pointing at the element we want: // // 0 1 2 3 // // start will be 0, end will be 4. So, the average is 2, which is what we'd like. if (size & 1) { RELEASE_ASSERT(medianIndex - start + 1 == end - medianIndex); medianIndex += m_weakRandom.getUint32() & 1; } else RELEASE_ASSERT(medianIndex - start == end - medianIndex); RELEASE_ASSERT(medianIndex > start); RELEASE_ASSERT(medianIndex + 1 < end); m_branches.append(BranchCode(LessThanToPush, medianIndex)); build(medianIndex, true, end); m_branches.append(BranchCode(Pop)); build(start, hardStart, medianIndex); }
static void do_build_copy_constructor (tree fndecl) { tree parm = FUNCTION_FIRST_USER_PARM (fndecl); tree t; parm = convert_from_reference (parm); if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type) && is_empty_class (current_class_type)) /* Don't copy the padding byte; it might not have been allocated if *this is a base subobject. */; else if (TYPE_HAS_TRIVIAL_INIT_REF (current_class_type)) { t = build (INIT_EXPR, void_type_node, current_class_ref, parm); finish_expr_stmt (t); } else { tree fields = TYPE_FIELDS (current_class_type); int n_bases = CLASSTYPE_N_BASECLASSES (current_class_type); tree binfos = TYPE_BINFO_BASETYPES (current_class_type); tree member_init_list = NULL_TREE; int cvquals = cp_type_quals (TREE_TYPE (parm)); int i; /* Initialize all the base-classes with the parameter converted to their type so that we get their copy constructor and not another constructor that takes current_class_type. We must deal with the binfo's directly as a direct base might be inaccessible due to ambiguity. */ for (t = CLASSTYPE_VBASECLASSES (current_class_type); t; t = TREE_CHAIN (t)) { tree binfo = TREE_VALUE (t); member_init_list = tree_cons (binfo, build_tree_list (NULL_TREE, build_base_path (PLUS_EXPR, parm, binfo, 1)), member_init_list); } for (i = 0; i < n_bases; ++i) { tree binfo = TREE_VEC_ELT (binfos, i); if (TREE_VIA_VIRTUAL (binfo)) continue; member_init_list = tree_cons (binfo, build_tree_list (NULL_TREE, build_base_path (PLUS_EXPR, parm, binfo, 1)), member_init_list); } for (; fields; fields = TREE_CHAIN (fields)) { tree init = parm; tree field = fields; tree expr_type; if (TREE_CODE (field) != FIELD_DECL) continue; expr_type = TREE_TYPE (field); if (DECL_NAME (field)) { if (VFIELD_NAME_P (DECL_NAME (field))) continue; /* True for duplicate members. */ if (IDENTIFIER_CLASS_VALUE (DECL_NAME (field)) != field) continue; } else if (ANON_AGGR_TYPE_P (expr_type) && TYPE_FIELDS (expr_type)) /* Just use the field; anonymous types can't have nontrivial copy ctors or assignment ops. */; else continue; /* Compute the type of "init->field". If the copy-constructor parameter is, for example, "const S&", and the type of the field is "T", then the type will usually be "const T". (There are no cv-qualified variants of reference types.) */ if (TREE_CODE (expr_type) != REFERENCE_TYPE) { int quals = cvquals; if (DECL_MUTABLE_P (field)) quals &= ~TYPE_QUAL_CONST; expr_type = cp_build_qualified_type (expr_type, quals); } init = build (COMPONENT_REF, expr_type, init, field); init = build_tree_list (NULL_TREE, init); member_init_list = tree_cons (field, init, member_init_list); } finish_mem_initializers (member_init_list); } }
// On idle things, we don't want to do shit in interrupts // don't queue gcodes in this void Panel::on_idle(void *argument) { if (this->start_up) { this->lcd->init(); Version v; string build(v.get_build()); string date(v.get_build_date()); this->lcd->clear(); this->lcd->setCursor(0, 0); this->lcd->printf("Welcome to Smoothie"); this->lcd->setCursor(0, 1); this->lcd->printf("%s", build.substr(0, 20).c_str()); this->lcd->setCursor(0, 2); this->lcd->printf("%s", date.substr(0, 20).c_str()); this->lcd->setCursor(0, 3); this->lcd->printf("Please wait...."); if (this->lcd->hasGraphics()) { this->lcd->bltGlyph(24, 40, ohw_logo_antipixel_width, ohw_logo_antipixel_height, ohw_logo_antipixel_bits); } this->lcd->on_refresh(true); // tell lcd to display now // Default top screen this->top_screen= new MainMenuScreen(); this->custom_screen->set_parent(this->top_screen); this->start_up = false; return; } MainMenuScreen *mms= static_cast<MainMenuScreen*>(this->top_screen); // after being idle for a while switch to Watch screen if (this->current_screen != NULL && this->idle_time > this->current_screen->idle_timeout_secs()*20) { this->idle_time = 0; if (mms->watch_screen != this->current_screen) { this->enter_screen(mms->watch_screen); // TODO do we need to reset any state? } return; } if(current_screen == NULL && this->idle_time > 20*4) { this->enter_screen(mms->watch_screen); return; } if(this->do_encoder) { this->do_encoder= false; encoder_check(0); } if (this->do_buttons) { // we don't want to do SPI in interrupt mode this->do_buttons = false; // read the actual buttons int but = lcd->readButtons(); if (but != 0) { this->idle_time = 0; if(current_screen == NULL) { // we were in startup screen so go to watch screen this->enter_screen(mms->watch_screen); return; } } // fire events if the buttons are active and debounce is satisfied this->up_button.check_signal(but & BUTTON_UP); this->down_button.check_signal(but & BUTTON_DOWN); this->back_button.check_signal(but & BUTTON_LEFT); this->click_button.check_signal(but & BUTTON_SELECT); this->pause_button.check_signal(but & BUTTON_PAUSE); } // If we are in menu mode and the position has changed if ( this->mode == MENU_MODE && this->counter_change() ) { this->menu_update(); } // If we are in control mode if ( this->mode == CONTROL_MODE && this->counter_change() ) { this->control_value_update(); } // If we must refresh if ( this->refresh_flag ) { this->refresh_flag = false; if (this->current_screen != NULL) { this->current_screen->on_refresh(); this->lcd->on_refresh(); } } }
void deltas_sector::operator() ( signal_& vi__io, signal_& hi__io, signal_& ci__io, signal_& si__io, signal_& ph_match__io, signal_& th_match__io, signal_& th_match11__io, signal_& cpat_match__io, signal_& ph_q__io, signal_& th_window__io, signal_& phi__io, signal_& theta__io, signal_& cpattern__io, signal_& delta_ph__io, signal_& delta_th__io, signal_& sign_ph__io, signal_& sign_th__io, signal_& rank__io, signal_& vir__io, signal_& hir__io, signal_& cir__io, signal_& sir__io, signal_& clk__io ) { if (!built) { seg_ch = 2; bw_ph = 8; bw_th = 7; bw_fph = 12; bw_fth = 8; bw_wg = 7; bw_ds = 7; bw_hs = 8; pat_w_st3 = 3; pat_w_st1 = pat_w_st3 + 1; full_pat_w_st3 = (1 << (pat_w_st3+1)) - 1; full_pat_w_st1 = (1 << (pat_w_st1+1)) - 1; padding_w_st1 = full_pat_w_st1 / 2; padding_w_st3 = full_pat_w_st3 / 2; red_pat_w_st3 = pat_w_st3 * 2 + 1; red_pat_w_st1 = pat_w_st1 * 2 + 1; fold = 4; th_ch11 = seg_ch*seg_ch; bw_q = 4; bw_addr = 7; ph_raw_w = (1 << pat_w_st3) * 15; th_raw_w = (1 << bw_th); max_drift = 3; bw_phi = 12; bw_eta = 7; ph_hit_w = 40+4; ph_hit_w20 = ph_hit_w; ph_hit_w10 = 20+4; th_hit_w = 56 + 8; endcap = 1; n_strips = (station <= 1 && cscid <= 2) ? 64 : (station <= 1 && cscid >= 6) ? 64 : 80; n_wg = (station <= 1 && cscid <= 3) ? 48 : (station <= 1 && cscid >= 6) ? 32 : (station == 2 && cscid <= 3) ? 112 : (station >= 3 && cscid <= 3) ? 96 : 64; th_coverage = (station <= 1 && cscid <= 2) ? 45 : (station <= 1 && cscid >= 6) ? 27 : (station <= 1 && cscid >= 3) ? 39 : (station == 2 && cscid <= 2) ? 43 : (station == 2 && cscid >= 3) ? 56 : (station == 3 && cscid <= 2) ? 34 : (station == 3 && cscid >= 3) ? 52 : (station == 4 && cscid <= 2) ? 28 : (station == 4 && cscid >= 3) ? 50 : 0; ph_coverage = (station <= 1 && cscid >= 6) ? 15 : //30 : (station >= 2 && cscid <= 2) ? 40 : 20; th_ch = (station <= 1 && cscid <= 2) ? (seg_ch*seg_ch) : seg_ch; ph_reverse = (endcap == 1 && station >= 3) ? 1 : (endcap == 2 && station < 3) ? 1 : 0; th_mem_sz = (1 << bw_addr); th_corr_mem_sz = (1 << bw_addr); mult_bw = bw_fph + 11; ph_zone_bnd1 = (station <= 1 && cscid <= 2) ? 41 : (station == 2 && cscid <= 2) ? 41 : (station == 2 && cscid > 2) ? 87 : (station == 3 && cscid > 2) ? 49 : (station == 4 && cscid > 2) ? 49 : 127; ph_zone_bnd2 = (station == 3 && cscid > 2) ? 87 : 127; zone_overlap = 2; bwr = 6; bpow = 6; cnr = (1 << bpow); cnrex = ph_raw_w; seg1 = me11 ? th_ch11 : seg_ch; build(); //[zone][pattern_num][station 0-3] vi.attach(vi__io); hi.attach(hi__io); ci.attach(ci__io); si.attach(si__io); ph_match.attach(ph_match__io); th_match.attach(th_match__io); th_match11.attach(th_match11__io); cpat_match.attach(cpat_match__io); // best ranks [zone][num] ph_q.attach(ph_q__io); th_window.attach(th_window__io); clk.attach(clk__io); // precise phi and theta of candidates // [zone][pattern_num] phi.attach(phi__io); theta.attach(theta__io); cpattern.attach(cpattern__io); // ph and th deltas from best stations // [zone][pattern_num], last index: [0] - best pair of stations, [1] - second best pair delta_ph.attach(delta_ph__io); delta_th.attach(delta_th__io); sign_ph.attach(sign_ph__io); sign_th.attach(sign_th__io); // updated ranks [zone][pattern_num] rank.attach(rank__io); //[zone][pattern_num][station 0-3] vir.attach(vir__io); hir.attach(hir__io); cir.attach(cir__io); sir.attach(sir__io); } { for (i = 0; i < 2; i = i+1) // zone loop { for (j = 0; j < 3; j = j+1) // pattern loop { gb.zl11[i].pl[j].da.me11 = 1; gb.zl11[i].pl[j].da ( vi[i][j], hi[i][j], ci[i][j], si[i][j], ph_match[i][j], th_match[i][j], th_match11[i][j], cpat_match[i][j], ph_q[i][j], th_window, phi[i][j], theta[i][j], cpattern[i][j], delta_ph[i][j], delta_th[i][j], sign_ph[i][j], sign_th[i][j], rank[i][j], vir[i][j], hir[i][j], cir[i][j], sir[i][j], clk ); } } for (i = 2; i < 4; i = i+1) // zone loop { for (j = 0; j < 3; j = j+1) // pattern loop { gb.zl[i].pl[j].da.me11 = 0; gb.zl[i].pl[j].da ( vi[i][j], hi[i][j], ci[i][j], si[i][j], ph_match[i][j], th_match[i][j], dummy[i-2][j], cpat_match[i][j], ph_q[i][j], th_window, phi[i][j], theta[i][j], cpattern[i][j], delta_ph[i][j], delta_th[i][j], sign_ph[i][j], sign_th[i][j], rank[i][j], vir[i][j], hir[i][j], cir[i][j], sir[i][j], clk ); } } // block: zl } }
twidget* tbuilder_viewport::build() const { return build(treplacements()); }
Line(Point &p, Point &q) : _p(p), _q(q) { build(); }
twindow* ttitle_screen::build_window(CVideo& video) { return build(video, get_id(TITLE_SCREEN)); }
Triangle(Point left, Point right, Point top) : _l(left), _r(right), _t(top), _left(Line(left, top)), _right(Line(right, top)) { build(); }
void BookmarksToolBar::setRootIndex(const QModelIndex &index) { m_root = index; build(); }
void transportProcessMessage(void) { // Manage signing timeout (void)signerCheckTimer(); // receive message setIndication(INDICATION_RX); uint8_t payloadLength = transportReceive((uint8_t *)&_msg); // get message length and limit size const uint8_t msgLength = min(mGetLength(_msg), (uint8_t)MAX_PAYLOAD); // calculate expected length const uint8_t expectedMessageLength = HEADER_SIZE + (mGetSigned(_msg) ? MAX_PAYLOAD : msgLength); #if defined(MY_RF24_ENABLE_ENCRYPTION) // payload length = a multiple of blocksize length for decrypted messages, i.e. cannot be used for payload length check payloadLength = expectedMessageLength; #endif const uint8_t command = mGetCommand(_msg); const uint8_t type = _msg.type; const uint8_t sender = _msg.sender; const uint8_t last = _msg.last; const uint8_t destination = _msg.destination; TRANSPORT_DEBUG(PSTR("TSF:MSG:READ,%d-%d-%d,s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d:%s\n"), sender, last, destination, _msg.sensor, command, type, mGetPayloadType(_msg), msgLength, mGetSigned(_msg), _msg.getString(_convBuf)); // Reject payloads with incorrect length if (payloadLength != expectedMessageLength) { setIndication(INDICATION_ERR_LENGTH); TRANSPORT_DEBUG(PSTR("!TSF:MSG:LEN,%d!=%d\n"), payloadLength, expectedMessageLength); // invalid payload length return; } // Reject messages with incorrect protocol version if (mGetVersion(_msg) != PROTOCOL_VERSION) { setIndication(INDICATION_ERR_VERSION); TRANSPORT_DEBUG(PSTR("!TSF:MSG:PVER,%d=%d\n"), mGetVersion(_msg), PROTOCOL_VERSION); // protocol version mismatch return; } // Reject messages that do not pass verification if (!signerVerifyMsg(_msg)) { setIndication(INDICATION_ERR_SIGN); TRANSPORT_DEBUG(PSTR("!TSF:MSG:SIGN VERIFY FAIL\n")); return; } // update routing table if msg not from parent #if defined(MY_REPEATER_FEATURE) #if !defined(MY_GATEWAY_FEATURE) if (last != _transportConfig.parentNodeId) { #else // GW doesn't have parent { #endif // Message is from one of the child nodes and not sent from this node. Add it to routing table. if (sender != _transportConfig.nodeId) { transportSetRoute(sender, last); } } #endif // MY_REPEATER_FEATURE // set message received flag _transportSM.msgReceived = true; // Is message addressed to this node? if (destination == _transportConfig.nodeId) { // prevent buffer overflow by limiting max. possible message length (5 bits=31 bytes max) to MAX_PAYLOAD (25 bytes) mSetLength(_msg, min(mGetLength(_msg),(uint8_t)MAX_PAYLOAD)); // null terminate data _msg.data[msgLength] = 0u; // Check if sender requests an ack back. if (mGetRequestAck(_msg)) { TRANSPORT_DEBUG(PSTR("TSF:MSG:ACK REQ\n")); // ACK requested _msgTmp = _msg; // Copy message mSetRequestAck(_msgTmp, false); // Reply without ack flag (otherwise we would end up in an eternal loop) mSetAck(_msgTmp, true); // set ACK flag _msgTmp.sender = _transportConfig.nodeId; _msgTmp.destination = sender; // send ACK, use transportSendRoute since ACK reply is not internal, i.e. if !transportOK do not reply (void)transportSendRoute(_msgTmp); } if(!mGetAck(_msg)) { // only process if not ACK if (command == C_INTERNAL) { // Process signing related internal messages if (signerProcessInternal(_msg)) { return; // Signer processing indicated no further action needed } #if !defined(MY_GATEWAY_FEATURE) if (type == I_ID_RESPONSE) { #if (MY_NODE_ID == AUTO) // only active if node ID dynamic (void)transportAssignNodeID(_msg.getByte()); #endif return; // no further processing required } if (type == I_FIND_PARENT_RESPONSE) { #if !defined(MY_GATEWAY_FEATURE) && !defined(MY_PARENT_NODE_IS_STATIC) if (_transportSM.findingParentNode) { // only process if find parent active // Reply to a I_FIND_PARENT_REQUEST message. Check if the distance is shorter than we already have. uint8_t distance = _msg.getByte(); if (isValidDistance(distance)) { distance++; // Distance to gateway is one more for us w.r.t. parent // update settings if distance shorter or preferred parent found if (((isValidDistance(distance) && distance < _transportConfig.distanceGW) || (!_autoFindParent && sender == (uint8_t)MY_PARENT_NODE_ID)) && !_transportSM.preferredParentFound) { // Found a neighbor closer to GW than previously found if (!_autoFindParent && sender == (uint8_t)MY_PARENT_NODE_ID) { _transportSM.preferredParentFound = true; TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR PREF\n")); // find parent, preferred parent found } _transportConfig.distanceGW = distance; _transportConfig.parentNodeId = sender; TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR OK,ID=%d,D=%d\n"), _transportConfig.parentNodeId, _transportConfig.distanceGW); } } } else { TRANSPORT_DEBUG(PSTR("!TSF:MSG:FPAR INACTIVE\n")); // find parent response received, but inactive } return; #endif } #endif // general if (type == I_PING) { TRANSPORT_DEBUG(PSTR("TSF:MSG:PINGED,ID=%d,HP=%d\n"), sender, _msg.getByte()); // node pinged #if defined(MY_GATEWAY_FEATURE) && (F_CPU>16000000) // delay for fast GW and slow nodes delay(5); #endif (void)transportRouteMessage(build(_msgTmp, sender, NODE_SENSOR_ID, C_INTERNAL, I_PONG).set((uint8_t)1)); return; // no further processing required } if (type == I_PONG) { if (_transportSM.pingActive) { _transportSM.pingActive = false; _transportSM.pingResponse = _msg.getByte(); TRANSPORT_DEBUG(PSTR("TSF:MSG:PONG RECV,HP=%d\n"), _transportSM.pingResponse); // pong received } else { TRANSPORT_DEBUG(PSTR("!TSF:MSG:PONG RECV,INACTIVE\n")); // pong received, but !pingActive } return; // no further processing required } if (_processInternalMessages()) { return; // no further processing required } } else if (command == C_STREAM) { #if defined(MY_OTA_FIRMWARE_FEATURE) if(firmwareOTAUpdateProcess()) { return; // OTA FW update processing indicated no further action needed } #endif } } else { TRANSPORT_DEBUG( PSTR("TSF:MSG:ACK\n")); // received message is ACK, no internal processing, handover to msg callback } #if defined(MY_GATEWAY_FEATURE) // Hand over message to controller (void)gatewayTransportSend(_msg); #endif // Call incoming message callback if available if (receive) { receive(_msg); } } else if (destination == BROADCAST_ADDRESS) { TRANSPORT_DEBUG(PSTR("TSF:MSG:BC\n")); // broadcast msg if (command == C_INTERNAL) { if (isTransportReady()) { // only reply if node is fully operational if (type == I_FIND_PARENT_REQUEST) { #if defined(MY_REPEATER_FEATURE) if (sender != _transportConfig.parentNodeId) { // no circular reference TRANSPORT_DEBUG(PSTR("TSF:MSG:FPAR REQ,ID=%d\n"), sender); // FPAR: find parent request // check if uplink functional - node can only be parent node if link to GW functional // this also prevents circular references in case GW ooo if (transportCheckUplink()) { _transportSM.lastUplinkCheck = hwMillis(); TRANSPORT_DEBUG(PSTR("TSF:MSG:GWL OK\n")); // GW uplink ok // random delay minimizes collisions delay(hwMillis() & 0x3ff); (void)transportRouteMessage(build(_msgTmp, sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE).set(_transportConfig.distanceGW)); } else { TRANSPORT_DEBUG(PSTR("!TSF:MSG:GWL FAIL\n")); // GW uplink fail, do not respond to parent request } } #endif return; // no further processing required, do not forward } } // isTransportReady if (type == I_FIND_PARENT_RESPONSE) { return; // no further processing required, do not forward } #if !defined(MY_GATEWAY_FEATURE) if (type == I_DISCOVER_REQUEST) { if (last == _transportConfig.parentNodeId) { // random wait to minimize collisions delay(hwMillis() & 0x3ff); (void)transportRouteMessage(build(_msgTmp, sender, NODE_SENSOR_ID, C_INTERNAL, I_DISCOVER_RESPONSE).set(_transportConfig.parentNodeId)); // no return here (for fwd if repeater) } } #endif } // controlled BC relay #if defined(MY_REPEATER_FEATURE) // controlled BC repeating: forward only if message received from parent and sender not self to prevent circular fwds if(last == _transportConfig.parentNodeId && sender != _transportConfig.nodeId && isTransportReady()) { TRANSPORT_DEBUG(PSTR("TSF:MSG:FWD BC MSG\n")); // controlled broadcast msg forwarding (void)transportRouteMessage(_msg); } #endif // Callback for BC, only for non-internal messages if (command != C_INTERNAL) { #if !defined(MY_GATEWAY_FEATURE) // only proceed if message received from parent if (last != _transportConfig.parentNodeId) { return; } #endif #if defined(MY_GATEWAY_FEATURE) // Hand over message to controller (void)gatewayTransportSend(_msg); #endif if (receive) { receive(_msg); } } } else { // msg not to us and not BC, relay msg #if defined(MY_REPEATER_FEATURE) if (isTransportReady()) { TRANSPORT_DEBUG(PSTR("TSF:MSG:REL MSG\n")); // relay msg if (command == C_INTERNAL) { if (type == I_PING || type == I_PONG) { uint8_t hopsCnt = _msg.getByte(); if (hopsCnt != MAX_HOPS) { TRANSPORT_DEBUG(PSTR("TSF:MSG:REL PxNG,HP=%d\n"), hopsCnt); hopsCnt++; _msg.set(hopsCnt); } } } // Relay this message to another node (void)transportRouteMessage(_msg); } #else TRANSPORT_DEBUG(PSTR("!TSF:MSG:REL MSG,NREP\n")); // message relaying request, but not a repeater #endif } } void transportInvokeSanityCheck(void) { if (!transportSanityCheck()) { TRANSPORT_DEBUG(PSTR("!TSF:SAN:FAIL\n")); // sanity check fail transportSwitchSM(stFailure); } else { TRANSPORT_DEBUG(PSTR("TSF:SAN:OK\n")); // sanity check ok } } void transportProcessFIFO(void) { if (!_transportSM.transportActive) { // transport not active, no further processing required return; } #if defined(MY_TRANSPORT_SANITY_CHECK) if (hwMillis() - _lastSanityCheck > MY_TRANSPORT_SANITY_CHECK_INTERVAL_MS) { _lastSanityCheck = hwMillis(); transportInvokeSanityCheck(); } #endif uint8_t _processedMessages = MAX_SUBSEQ_MSGS; // process all msgs in FIFO or counter exit while (transportAvailable() && _processedMessages--) { transportProcessMessage(); } #if defined(MY_OTA_FIRMWARE_FEATURE) if (isTransportReady()) { // only process if transport ok firmwareOTAUpdateRequest(); } #endif } bool transportSendWrite(const uint8_t to, MyMessage &message) { message.last = _transportConfig.nodeId; // Update last // sign message if required if (!signerSignMsg(message)) { TRANSPORT_DEBUG(PSTR("!TSF:MSG:SIGN FAIL\n")); setIndication(INDICATION_ERR_SIGN); return false; } // msg length changes if signed const uint8_t totalMsgLength = HEADER_SIZE + ( mGetSigned(message) ? MAX_PAYLOAD : mGetLength( message) ); // send setIndication(INDICATION_TX); bool result = transportSend(to, &message, min((uint8_t)MAX_MESSAGE_LENGTH, totalMsgLength)); // broadcasting (workaround counterfeits) result |= (to == BROADCAST_ADDRESS); TRANSPORT_DEBUG(PSTR("%sTSF:MSG:SEND,%d-%d-%d-%d,s=%d,c=%d,t=%d,pt=%d,l=%d,sg=%d,ft=%d,st=%s:%s\n"), (result ? "" : "!"), message.sender, message.last, to, message.destination, message.sensor, mGetCommand(message), message.type, mGetPayloadType(message), mGetLength(message), mGetSigned(message), _transportSM.failedUplinkTransmissions, (result ? "OK" : "NACK"), message.getString(_convBuf)); return result; }
void work() { int build(),dinic(int,int); while (build()) ans+=dinic(0,20000000); }
static void build_sync(hpx::naming::id_type const &gid, std::string NVCC_FLAGS) { build(gid, NVCC_FLAGS).get(); }
//----------------------------------------------------------------------- FocusedShadowCameraSetup::PointListBody::PointListBody(const ConvexBody& body) { build(body); }
void AsiMS2000::selectCommand(int commandNum) { switch(commandNum) { case 0: accel(); break; case 1: aalign(); break; case 2: afcont(); break; case 3: aflim(); break; case 4: afocus(); break; case 5: afset(); break; case 6: afmove(); break; case 7: ahome(); break; case 8: aij(); break; case 9: array(); break; case 10: azero(); break; case 11: backlash(); break; case 12: bcustom(); break; case 13: benable(); break; case 14: build(); break; case 15: cdate(); break; case 16: cnts(); break; case 17: customa(); break; case 18: customb(); break; case 19: dack(); break; case 20: dump(); break; case 21: ensync(); break; case 22: epolarity(); break; case 23: error(); break; case 24: halt(); break; case 25: here(); break; case 26: home(); break; case 27: info(); break; case 28: joystick(); break; case 29: jsspd(); break; case 30: kadc(); break; case 31: kd(); break; case 32: ki(); break; case 33: kp(); break; case 34: lcd(); break; case 35: led(); break; case 36: lladdr(); break; case 37: load(); break; case 38: lock(); break; case 39: lockrg(); break; case 40: lockset(); break; case 41: maintain(); break; case 42: motctrl(); break; case 43: move(); break; case 44: movrel(); break; case 45: pcros(); break; case 46: pedal(); break; case 47: rbmode(); break; case 48: rdadc(); break; case 49: rdsbyte(); break; case 50: rdstat(); break; case 51: relock(); break; case 52: reset(); break; case 53: rt(); break; case 54: runaway(); break; case 55: saveset(); break; case 56: savepos(); break; case 57: scan(); break; case 58: scanr(); break; case 59: scanv(); break; case 60: secure(); break; case 61: sethome(); break; case 62: setlow(); break; case 63: setup(); break; case 64: si(); break; case 65: speed(); break; case 66: spin(); break; case 67: status(); break; case 68: stopbits(); break; case 69: ttl(); break; case 70: um(); break; case 71: units(); break; case 72: unlock(); break; case 73: vb(); break; case 74: vector(); break; case 75: version(); break; case 76: wait(); break; case 77: where(); break; case 78: who(); break; case 79: wrdac(); break; case 80: zero(); break; case 81: z2b(); break; case 82: zs(); break; case 83: overshoot(); break; } }
MxScalarOp<DIM>::MxScalarOp(MxComplex value, MxGridField<DIM> const * field, bool imag) : Epetra_CrsMatrix(Copy, field->getMap(), 1, true), mValue(value), mField(field) { this->imaginary = imag; build(); }
void UDFGraph::build(const expr* curExpr, std::vector<user_function*>& callChain) { expr_kind_t kind = curExpr->get_expr_kind(); if (kind == fo_expr_kind || kind == function_item_expr_kind) { user_function* udf = NULL; if (kind == fo_expr_kind) { const fo_expr* fo = static_cast<const fo_expr*>(curExpr); if (fo->get_func()->isUdf()) udf = static_cast<user_function*>(fo->get_func()); } else { const function_item_expr* fi = static_cast<const function_item_expr*>(curExpr); // Literal function item expressions might have UDFs, but they should not // get into the UDF graph. if (fi->is_inline()) udf = static_cast<user_function*>(fi->get_function()); } if (udf != NULL) { std::vector<user_function*>::const_iterator cycle; if ((cycle = std::find(callChain.begin(), callChain.end(), udf)) == callChain.end()) { bool found = theNodes.exists(udf); addEdge(callChain.back(), udf); callChain.push_back(udf); // If this is the first time we see the current udf, do a recursive // call on its body expr. if (!found && udf->getBody()) { build(udf->getBody(), callChain); } callChain.pop_back(); } else { // A recursive function call. std::vector<user_function*>::const_iterator ite = cycle; std::vector<user_function*>::const_iterator end = callChain.end(); for (; ite != end; ++ite) { (*ite)->addMutuallyRecursiveUDFs(callChain, cycle); } } } } ExprConstIterator iter(curExpr); while (!iter.done()) { build(iter.get_expr(), callChain); iter.next(); } }
void init(int k) { build(1, 1, k); n = k; }
long IterIrredTest(const ZZ_pX& f) { if (deg(f) <= 0) return 0; if (deg(f) == 1) return 1; ZZ_pXModulus F; build(F, f); ZZ_pX h; PowerXMod(h, ZZ_p::modulus(), F); long CompTableSize = 2*SqrRoot(deg(f)); ZZ_pXNewArgument H; build(H, h, F, CompTableSize); long i, d, limit, limit_sqr; ZZ_pX g, X, t, prod; SetX(X); i = 0; g = h; d = 1; limit = 2; limit_sqr = limit*limit; set(prod); while (2*d <= deg(f)) { sub(t, g, X); MulMod(prod, prod, t, F); i++; if (i == limit_sqr) { GCD(t, f, prod); if (!IsOne(t)) return 0; set(prod); limit++; limit_sqr = limit*limit; i = 0; } d = d + 1; if (2*d <= deg(f)) { CompMod(g, g, H, F); } } if (i > 0) { GCD(t, f, prod); if (!IsOne(t)) return 0; } return 1; }
TreeNode* sortedArrayToBST(vector<int>& nums) { int sz = nums.size(); return build(nums, 0, sz-1); }
void DDF(vec_pair_ZZ_pX_long& factors, const ZZ_pX& ff, const ZZ_pX& hh, long verbose) { ZZ_pX f = ff; ZZ_pX h = hh; if (!IsOne(LeadCoeff(f))) LogicError("DDF: bad args"); factors.SetLength(0); if (deg(f) == 0) return; if (deg(f) == 1) { AddFactor(factors, f, 1, verbose); return; } long CompTableSize = 2*SqrRoot(deg(f)); long GCDTableSize = ZZ_pX_BlockingFactor; ZZ_pXModulus F; build(F, f); ZZ_pXNewArgument H; build(H, h, F, min(CompTableSize, deg(f))); long i, d, limit, old_n; ZZ_pX g, X; vec_ZZ_pX tbl(INIT_SIZE, GCDTableSize); SetX(X); i = 0; g = h; d = 1; limit = GCDTableSize; while (2*d <= deg(f)) { old_n = deg(f); sub(tbl[i], g, X); i++; if (i == limit) { ProcessTable(f, factors, F, i, tbl, d, verbose); i = 0; } d = d + 1; if (2*d <= deg(f)) { // we need to go further if (deg(f) < old_n) { // f has changed build(F, f); rem(h, h, f); rem(g, g, f); build(H, h, F, min(CompTableSize, deg(f))); } CompMod(g, g, H, F); } } ProcessTable(f, factors, F, i, tbl, d-1, verbose); if (!IsOne(f)) AddFactor(factors, f, deg(f), verbose); }
/* Synthesize a CALL_EXPR and a TRY_FINALLY_EXPR, for this chain of _DECLs if appropriate. Arrange to call the __mf_register function now, and the __mf_unregister function later for each. */ static void mx_register_decls (tree decl, tree *stmt_list) { tree finally_stmts = NULL_TREE; tree_stmt_iterator initially_stmts = tsi_start (*stmt_list); while (decl != NULL_TREE) { if (mf_decl_eligible_p (decl) /* Not already processed. */ && ! mf_marked_p (decl) /* Automatic variable. */ && ! DECL_EXTERNAL (decl) && ! TREE_STATIC (decl)) { tree size = NULL_TREE, variable_name; tree unregister_fncall, unregister_fncall_params; tree register_fncall, register_fncall_params; size = convert (size_type_node, TYPE_SIZE_UNIT (TREE_TYPE (decl))); /* (& VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK) */ unregister_fncall_params = tree_cons (NULL_TREE, convert (ptr_type_node, mf_mark (build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (decl)), decl))), tree_cons (NULL_TREE, size, tree_cons (NULL_TREE, /* __MF_TYPE_STACK */ build_int_cst (NULL_TREE, 3), NULL_TREE))); /* __mf_unregister (...) */ unregister_fncall = build_function_call_expr (mf_unregister_fndecl, unregister_fncall_params); /* (& VARIABLE, sizeof (VARIABLE), __MF_TYPE_STACK, "name") */ variable_name = mf_varname_tree (decl); register_fncall_params = tree_cons (NULL_TREE, convert (ptr_type_node, mf_mark (build1 (ADDR_EXPR, build_pointer_type (TREE_TYPE (decl)), decl))), tree_cons (NULL_TREE, size, tree_cons (NULL_TREE, /* __MF_TYPE_STACK */ build_int_cst (NULL_TREE, 3), tree_cons (NULL_TREE, variable_name, NULL_TREE)))); /* __mf_register (...) */ register_fncall = build_function_call_expr (mf_register_fndecl, register_fncall_params); /* Accumulate the two calls. */ /* ??? Set EXPR_LOCATION. */ gimplify_stmt (®ister_fncall); gimplify_stmt (&unregister_fncall); /* Add the __mf_register call at the current appending point. */ if (tsi_end_p (initially_stmts)) warning (0, "mudflap cannot track %qs in stub function", IDENTIFIER_POINTER (DECL_NAME (decl))); else { tsi_link_before (&initially_stmts, register_fncall, TSI_SAME_STMT); /* Accumulate the FINALLY piece. */ append_to_statement_list (unregister_fncall, &finally_stmts); } mf_mark (decl); } decl = TREE_CHAIN (decl); } /* Actually, (initially_stmts!=NULL) <=> (finally_stmts!=NULL) */ if (finally_stmts != NULL_TREE) { tree t = build (TRY_FINALLY_EXPR, void_type_node, *stmt_list, finally_stmts); *stmt_list = NULL; append_to_statement_list (t, stmt_list); } }