void clear(void) { hs.clear(); }
inline vec mid(const vec&v, int start, int num){ return v.segment(start, std::min(num, (int)(v.size()-start))); }
inline void sort(vec & a){ std::sort(a.data(), a.data()+a.size()); }
void generateIf(){ int pl=tempCode.size(); if(DEBUG)printf("Generuje if w linii %d\n", pl); }
void generateWhile(){ int pl=tempCode.size(); if(DEBUG)printf("Generuej while w linii %d\n", pl); labeler(); }
void generateDivision(){ char temp[50]; int mod=0; //c=0, d=1 addCodeLine("LOAD " + op_temp_b); addCodeLine("STORE " + op_temp_c); //jezeli b=0 to skaczemy //addCodeLine("JZ " + tempCode.size()+66); sprintf(temp, "JZ %d", tempCode.size()+mod+66);addCodeLine(temp); addCodeLine("ZERO"); addCodeLine("STORE " + op_temp_c); addCodeLine("INC"); addCodeLine("STORE " + op_temp_d); //jesli b parzyste -> skacz (czyt. jezeli b+1 nieparzyste -> skacz) // ********** 0 ********* int label[7]; label[0] = tempCode.size(); addCodeLine("LOAD " + op_temp_b); //addCodeLine("INC"); // dopokia b+1 jest nieparzyste (b jest parzyste) sprintf(temp, "JODD %d", tempCode.size()+mod+17);addCodeLine(temp); addCodeLine("LOAD " + op_temp_d); addCodeLine("SHL"); addCodeLine("STORE " + op_temp_d); //jezeli a+1 nieparzyste -> 2 addCodeLine("LOAD " + op_temp_a); addCodeLine("INC"); sprintf(temp, "JODD %d", tempCode.size()+mod+4);addCodeLine(temp); addCodeLine("LOAD " + op_temp_d); addCodeLine("INC"); addCodeLine("STORE " + op_temp_d); // ************ 2 ********** addCodeLine("LOAD " + op_temp_a); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_a); addCodeLine("LOAD " + op_temp_b); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_b); sprintf(temp, "JUMP %d", label[0]);addCodeLine(temp); // **************** 1 label[1]=tempCode.size(); addCodeLine("LOAD " + op_temp_b); addCodeLine("SUB " + op_temp_a); sprintf(temp, "JG %d", tempCode.size()+mod+5);addCodeLine(temp); //3 addCodeLine("LOAD " + op_temp_b); addCodeLine("SHL"); addCodeLine("STORE " + op_temp_b); sprintf(temp, "JUMP %d", label[1]);addCodeLine(temp); //1 // ************* 3 label[3]=tempCode.size(); addCodeLine("LOAD " + op_temp_b); sprintf(temp, "JODD %d", tempCode.size()+mod+16);addCodeLine(temp); //4 addCodeLine("LOAD " + op_temp_c); addCodeLine("SHL"); addCodeLine("STORE " + op_temp_c); addCodeLine("LOAD " + op_temp_b); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_b); addCodeLine("SUB " + op_temp_a); sprintf(temp, "JG %d", tempCode.size()+mod+7);addCodeLine(temp); // -> 5 addCodeLine("LOAD " + op_temp_c); addCodeLine("INC"); addCodeLine("STORE " + op_temp_c); addCodeLine("LOAD " + op_temp_a); addCodeLine("SUB " + op_temp_b); addCodeLine("STORE " + op_temp_a); // ****************** 5 sprintf(temp, "JUMP %d", label[3]);addCodeLine(temp); // ->3 // jezeli d>0 (r>0) to rob; jesli rowna- skacz // ***************** 4 label[4]=tempCode.size(); addCodeLine("LOAD " + op_temp_d); sprintf(temp, "JZ %d", tempCode.size()+mod+14);addCodeLine(temp); // -> 6 addCodeLine("LOAD " + op_temp_a); addCodeLine("SHL"); addCodeLine("STORE " + op_temp_a); addCodeLine("LOAD " + op_temp_d); addCodeLine("INC"); sprintf(temp, "JODD %d", tempCode.size()+mod+4);addCodeLine(temp); // -> 7 addCodeLine("LOAD " + op_temp_a); addCodeLine("INC"); addCodeLine("STORE " + op_temp_a); // ************* 7 addCodeLine("LOAD " + op_temp_d); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_d); sprintf(temp, "JUMP %d", label[4]);addCodeLine(temp); // -> 4 // **************** 6 addCodeLine("LOAD " + op_temp_a); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_a); addCodeLine("STORE " + op_temp_b); //reszta w b addCodeLine("LOAD " + op_temp_c); // przepisac wynik z c do a addCodeLine("STORE " + op_temp_a); }
void labeler(){ if(DEBUG)addCodeLine("---ETYKIETA---"); int line=tempCode.size()-1; labelStack.push_back(line); if(DEBUG)printf("Tymczasowy label w linii %d\n", line); }
static void buildConstraint(vec<Formula>& ps, vec<Int>& Cs, vec<Formula>& carry, vec<int>& base, int digit_no, vec<vec<Formula> >& out_digits, int max_cost) { assert(ps.size() == Cs.size()); if (FEnv::topSize() > max_cost) throw Exception_TooBig(); /** pf("buildConstraint("); for (int i = 0; i < ps.size(); i++) pf("%d*%s ", Cs[i], (*debug_names)[index(ps[i])]); pf("+ %d carry)\n", carry.size()); **/ if (digit_no == base.size()){ // Final digit, build sorter for rest: // -- add carry bits: for (int i = 0; i < carry.size(); i++) ps.push(carry[i]), Cs.push(1); out_digits.push(); buildSorter(ps, Cs, out_digits.last()); }else{ vec<Formula> ps_rem; vec<int> Cs_rem; vec<Formula> ps_div; vec<Int> Cs_div; // Split sum according to base: int B = base[digit_no]; for (int i = 0; i < Cs.size(); i++){ Int div = Cs[i] / Int(B); int rem = toint(Cs[i] % Int(B)); if (div > 0){ ps_div.push(ps[i]); Cs_div.push(div); } if (rem > 0){ ps_rem.push(ps[i]); Cs_rem.push(rem); } } // Add carry bits: for (int i = 0; i < carry.size(); i++) ps_rem.push(carry[i]), Cs_rem.push(1); // Build sorting network: vec<Formula> result; buildSorter(ps_rem, Cs_rem, result); // Get carry bits: carry.clear(); for (int i = B-1; i < result.size(); i += B) carry.push(result[i]); out_digits.push(); for (int i = 0; i < B-1; i++){ Formula out = _0_; for (int j = 0; j < result.size(); j += B){ int n = j+B-1; if (j + i < result.size()) out |= result[j + i] & ((n >= result.size()) ? _1_ : ~result[n]); } out_digits.last().push(out); } buildConstraint(ps_div, Cs_div, carry, base, digit_no+1, out_digits, max_cost); // <<== change to normal loop } }
static void optimizeBase(vec<Int>& seq, int carry_ins, vec<Int>& rhs, int cost, vec<int>& base, int& cost_bestfound, vec<int>& base_bestfound) { if (cost >= cost_bestfound) return; // "Base case" -- don't split further, build sorting network for current sequence: int final_cost = 0; for (int i = 0; i < seq.size(); i++){ if (seq[i] > INT_MAX) goto TooBig; #ifdef ExpensiveBigConstants final_cost += toint(seq[i]); #else int c; for (c = 1; c*c < seq[i]; c++); final_cost += c; #endif if (final_cost < 0) goto TooBig; } if (cost + final_cost < cost_bestfound){ base.copyTo(base_bestfound); cost_bestfound = cost + final_cost; } TooBig:; /**/static int depth = 0; // <<== could count 1:s here for efficiency vec<Int> new_seq; vec<Int> new_rhs; #ifdef PickSmallest int p = -1; for (int i = 0; i < seq.size(); i++) if (seq[i] > 1){ p = seq[i]; break; } if (p != -1){ #else //int upper_lim = (seq.size() == 0) ? 1 : seq.last(); // <<== Check that sqRoot is an 'int' (no truncation of 'Int') //for (int i = 0; i < (int)elemsof(primes) && primes[i] <= upper_lim; i++){ for (int i = 0; i < (int)elemsof(primes); i++){ int p = primes[i]; #endif int rest = carry_ins; // Sum of all the remainders. Int div, rem; /**/for (int n = depth; n != 0; n--) pf(" "); pf("prime=%d carry_ins=%d\n", p, carry_ins); /**/for (int n = depth; n != 0; n--) pf(" "); pf("New seq:"); for (int j = 0; j < seq.size(); j++){ rest += toint(seq[j] % Int(p)); div = seq[j] / Int(p); if (div > 0) //**/pf(" %d", div), new_seq.push(div); } /**/pf("\n"); /**/for (int n = depth; n != 0; n--) pf(" "); pf("rest=%d\n", rest); /**/for (int n = depth; n != 0; n--) pf(" "); pf("New rhs:"); #ifdef AllDigitsImportant bool digit_important = true; #else bool digit_important = false; #endif for (int j = 0; j < rhs.size(); j++){ div = rhs[j] / p; if (new_rhs.size() == 0 || div > new_rhs.last()){ rem = rhs[j] % p; /**/pf(" %d:%d", div, rem), new_rhs.push(div); if (!(rem == 0 && rest < p) && !(rem > rest)) digit_important = true; } /* <<== om 'rhs' slutar på 0:a och 'rest' inte kan overflowa, då behövs inte det sorterande nätverket för 'rest' ("always TRUE") samma sak om 'rhs' sista siffra är strikt större än 'rest' ("never TRUE") */ } /**/pf("\n\n"); base.push(p); /**/depth++; optimizeBase(new_seq, rest/p, new_rhs, cost+(digit_important ? rest : 0), base, cost_bestfound, base_bestfound); /**/depth--; base.pop(); new_seq.clear(); new_rhs.clear(); } } static void optimizeBase(vec<Int>& seq, vec<Int>& rhs, int& cost_bestfound, vec<int>& base_bestfound) { vec<int> base; cost_bestfound = INT_MAX; base_bestfound.clear(); optimizeBase(seq, 0, rhs, 0, base, cost_bestfound, base_bestfound); }
vco() { y0.set_length(2); y0(0) = 0.0; y0(1)= 0.0; acc = 0.0; } ;
bool maymove() const { return timeinair || physstate < PHYS_FLOOR || vel.squaredlen() > 1e-4f || deltapos.squaredlen() > 1e-4f; }
void ggc_register_root_tab (const struct ggc_root_tab* rt) { if (rt) extra_root_vec.safe_push (rt); }
~VSolver(void) { for (int i = 0; i < clauses.size(); i++) delete clauses[i]; }
virtual int len(void) { return hs.size() * sha1::hashsize; }
void addPb(const vec<Formula>& ps, const vec<Int>& Cs_, vec<Formula>& out, int bits) { assert(ps.size() == Cs_.size()); vec<vec<Formula> > pools; vec<Int> Cs(Cs_.size()); Int max_C = -1; for (int i = 0; i < Cs_.size(); i++){ Cs[i] = Cs_[i]; if (Cs[i] > max_C) max_C = Cs[i]; } for (; max_C > 0; max_C >>= 1){ pools.push(); for (int i = 0; i < Cs.size(); i++){ if ((Cs[i] & 1) != 0) pools.last().push(ps[i]); Cs[i] >>= 1; } } vec<Formula> carry; for (int p = 0; p < pools.size(); p++){ vec<Formula>& pool = pools[p]; carry.clear(); if (p == bits){ Formula overflow = _0_; for (; p < pools.size(); p++) for (int i = 0; i < pools[p].size(); i++) overflow |= pools[p][i]; out.push(overflow); }else if (pool.size() == 0) out.push(_0_); else{ int head = 0; while (pool.size()-head >= 3){ pool .push(FAs(pool[head], pool[head+1], pool[head+2])); carry.push(FAc(pool[head], pool[head+1], pool[head+2])); head += 3; } if (pool.size()-head == 2){ pool .push(FAs(pool[head], pool[head+1], _0_)); carry.push(FAc(pool[head], pool[head+1], _0_)); head += 2; } assert(pool.size()-head == 1); out.push(pool[head]); } if (carry.size() > 0){ if (p+1 == pools.size()) pools.push(); for (int i = 0; i < carry.size(); i++) pools[p+1].push(carry[i]); } } #if 0 //DEBUG for (int p = 0; p < pools.size(); p++){ printf("pool %d:", (1 << p)); for (int i = 0; i < pools[p].size(); i++){ printf(" "); dump(pools[p][i]); } printf("\n"); } #endif }
static Formula lexComp(vec<int>& num, vec<vec<Formula> >& digits) { assert(num.size() == digits.size()); return lexComp(num.size(), num, digits); }
void addCodeLine(str line){ tempCode.push_back(line); }
struct lto_out_decl_state * lto_get_out_decl_state (void) { return decl_state_stack.last (); }
void jumper(){ if(DEBUG)printf("TEST JUMPERA"); int line=tempCode.size()-1; jumpStack.push_back(line); if(DEBUG)printf("Tymczasowy jumper w linii %d\n", line); }
void lto_push_out_decl_state (struct lto_out_decl_state *state) { decl_state_stack.safe_push (state); }
int generateArithOp(str op, str a, str b){ generateP_AB(a, b); if(op==S_PLUS){ addCodeLine("ADD " +op_temp_a); }else if(op==S_MINUS){ addCodeLine("LOAD " + op_temp_a); addCodeLine("SUB " + op_temp_b); }else if(op==S_MULT){ char temp[50]; if(DEBUG)addCodeLine("-----------POCZATEK MNOZENIA"); addCodeLine("ZERO"); addCodeLine("STORE " + op_temp_c); int startLineNumber=tempCode.size(); // ETYKIETA START addCodeLine("LOAD " + op_temp_b); sprintf(temp, "JZ %d", tempCode.size()+19); addCodeLine(temp); sprintf(temp, "JODD %d", tempCode.size()+8); addCodeLine(temp); addCodeLine("LOAD " + op_temp_a); addCodeLine("SHL"); addCodeLine("STORE " + op_temp_a); addCodeLine("LOAD " + op_temp_b); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_b); sprintf(temp, "JUMP %d", startLineNumber); addCodeLine(temp); //KONIEC DLA PARZYSTEGO addCodeLine("LOAD " + op_temp_c); addCodeLine("ADD " + op_temp_a); addCodeLine("STORE " + op_temp_c); addCodeLine("LOAD " + op_temp_a); addCodeLine("SHL"); addCodeLine("STORE " + op_temp_a); addCodeLine("LOAD " + op_temp_b); addCodeLine("SHR"); addCodeLine("STORE " + op_temp_b); sprintf(temp, "JUMP %d", startLineNumber); addCodeLine(temp); addCodeLine("LOAD " + op_temp_c); //addCodeLine("DEC"); addCodeLine("STORE " + op_temp_a); // reg_a=a if(DEBUG)addCodeLine("-----------KONIEC MNOZENIA"); }else if(op==S_DIV){ generateDivision(); }else if(op==S_MOD){ generateDivision(); addCodeLine("LOAD " + op_temp_b); addCodeLine("STORE " + op_temp_a); } else{ if(ERR)printf("Nieznany operator %s\n", op.c_str()); } return 0; }
struct lto_out_decl_state * lto_pop_out_decl_state (void) { return decl_state_stack.pop (); }
void fixWhileLabels(){ int label1=labelStack.back(); labelStack.pop_back(); int label2=labelStack.back(); labelStack.pop_back(); labelStack.push_back(label1); labelStack.push_back(label2); if(DEBUG)printf("Zamieniam etykiety %d i %d\n", label1, label2); for(int i=0; i<2; i++){ int jumperLine=jumpStack.back(); if(DEBUG)printf("Skok z %d -> ", jumperLine); str jumper=tempCode.at(jumperLine); if(labelStack.size()==0){ if(DEBUG)printf("NO LABELS LEFT\n"); return; } jumpStack.pop_back(); int labelLine=labelStack.back(); labelStack.pop_back(); char op[10]; char direction[50]; char lab[50]; sscanf(jumper.c_str(), "%s", op); if(DEBUG)printf(" ---> %d\n", labelLine+1); sprintf(lab, "%s %d", op, labelLine+1); str t=lab; tempCode.at(jumperLine)=t; } }
/* Initialize the per SSA_NAME value-handles array. Returns it. */ void threadedge_initialize_values (void) { gcc_assert (!ssa_name_values.exists ()); ssa_name_values.create (num_ssa_names); }
inline vec head(const vec& v, int num){ return v.head(num); }
/* Free the per SSA_NAME value-handle array. */ void threadedge_finalize_values (void) { ssa_name_values.release (); }
inline vec tail(const vec&v, int num){ return v.segment(v.size() - num, num); }
inline void operator=(const char *arg) { on_ = true; *mode_ = false; arg_.push_back(arg); }
inline mat diag(vec & v){ return v.asDiagonal(); }
transmiter() { Parser p(std::string("config.txt")); DPCCH_NBits=p.get_int("DPCCH_NBits"); HS_DPCCH_NBits=p.get_int("HS_DPCCH_NBits"); E_DPCCH_NBits=p.get_int("E_DPCCH_NBits"); E_DPDCH1_NData=p.get_int("E_DPDCH1_NData"); E_DPDCH2_NData=p.get_int("E_DPDCH2_NData"); E_DPDCH3_NData=p.get_int("E_DPDCH3_NData"); E_DPDCH4_NData=p.get_int("E_DPDCH4_NData"); SF=p.get_int("SF"); SF_EDPDCH2=p.get_int("SF_EDPDCH2"); SF_EDPDCH3=p.get_int("SF_EDPDCH3"); DPCCH_SLOT0=p.get_int("DPCCH_SLOT0"); DPCCH_SLOT1=p.get_int("DPCCH_SLOT1"); DPCCH_SLOT2=p.get_int("DPCCH_SLOT2"); DPCCH_SLOT3=p.get_int("DPCCH_SLOT3"); DPCCH_SLOT4=p.get_int("DPCCH_SLOT4"); DPCCH_SLOT5=p.get_int("DPCCH_SLOT5"); DPCCH_SLOT6=p.get_int("DPCCH_SLOT6"); DPCCH_SLOT7=p.get_int("DPCCH_SLOT7"); DPCCH_SLOT8=p.get_int("DPCCH_SLOT8"); DPCCH_SLOT9=p.get_int("DPCCH_SLOT9"); DPCCH_SLOT10=p.get_int("DPCCH_SLOT10"); DPCCH_SLOT11=p.get_int("DPCCH_SLOT11"); DPCCH_SLOT12=p.get_int("DPCCH_SLOT12"); DPCCH_SLOT13=p.get_int("DPCCH_SLOT13"); DPCCH_SLOT14=p.get_int("DPCCH_SLOT14"); betaDPCCH=p.get_int("betaDPCCH"); betaE_DPDCH1=p.get_int("betaE_DPDCH1"); betaE_DPDCH2=p.get_int("betaE_DPDCH2"); betaE_DPDCH3=p.get_int("betaE_DPDCH3"); betaE_DPDCH4=p.get_int("betaE_DPDCH4"); betaE_DPCCH=p.get_int("betaE_DPCCH"); betaE_HS_DPCCH=p.get_int("betaE_HS_DPCCH"); betaDPCCHlin=pow10(betaDPCCH/10.0); betaE_DPDCH1lin=pow10(betaE_DPDCH1/10.0); betaE_DPDCH2lin=pow10(betaE_DPDCH2/10.0); betaE_DPDCH3lin=pow10(betaE_DPDCH3/10.0); betaE_DPDCH4lin=pow10(betaE_DPDCH4/10.0); betaE_DPCCHlin=pow10(betaE_DPCCH/10.0); betaE_HS_DPCCHlin=pow10(betaE_HS_DPCCH/10.0); OVSF=wcdma_spreading_codes (SF); OVSF4=wcdma_spreading_codes(SF_EDPDCH3); OVSF2=wcdma_spreading_codes(SF_EDPDCH2); OVSF256_0.set_length(SF,false); OVSF256_1.set_length(SF,false); OVSF256_33.set_length(SF,false); OVSF256_64.set_length(SF,false); OVSF4_1.set_length(SF_EDPDCH3,false); OVSF4_3.set_length(SF_EDPDCH3,false); OVSF2_1.set_length(SF_EDPDCH2,false); for(int i=0;i<OVSF.cols();i++) { OVSF256_0[i]=OVSF(0,i); OVSF256_1[i]=OVSF(1,i); OVSF256_33[i]=OVSF(33,i); OVSF256_64[i]=OVSF(64,i); } for(int i=0;i<OVSF4.cols();i++) { OVSF4_1[i]=OVSF4(1,i); } for(int i=0;i<OVSF2.cols();i++) { OVSF2_1[i]=OVSF2(1,i); } bvec DPCCH0=dec2bin(DPCCH_SLOT0,true); bvec DPCCH1=dec2bin(DPCCH_SLOT1,true); bvec DPCCH2=dec2bin(DPCCH_SLOT2,true); bvec DPCCH3=dec2bin(DPCCH_SLOT3,true); bvec DPCCH4=dec2bin(DPCCH_SLOT4,true); bvec DPCCH5=dec2bin(DPCCH_SLOT5,true); bvec DPCCH6=dec2bin(DPCCH_SLOT6,true); bvec DPCCH7=dec2bin(DPCCH_SLOT7,true); bvec DPCCH8=dec2bin(DPCCH_SLOT8,true); bvec DPCCH9=dec2bin(DPCCH_SLOT9,true); bvec DPCCH10=dec2bin(DPCCH_SLOT10,true); bvec DPCCH11=dec2bin(DPCCH_SLOT11,true); bvec DPCCH12=dec2bin(DPCCH_SLOT12,true); bvec DPCCH13=dec2bin(DPCCH_SLOT13,true); bvec DPCCH14=dec2bin(DPCCH_SLOT14,true); DPCCH.set_length(DPCCH_NBits,false); bvec conDPCCH0=concat(DPCCH0,DPCCH1,DPCCH2,DPCCH3,DPCCH4); bvec conDPCCH1=concat(DPCCH5,DPCCH6,DPCCH7,DPCCH8,DPCCH9); bvec conDPCCH2=concat(DPCCH10,DPCCH11,DPCCH12,DPCCH13,DPCCH14); DPCCH=concat(conDPCCH0,conDPCCH1,conDPCCH2); gold.generate(); }