// find the suffix array SA of s[0..n-1] in {1..K}^n // require s[n]=s[n+1]=s[n+2]=0, n>=2 void suffixArray(int* s, int* SA, uint32_t n, uint32_t K) { uint32_t n0=(n+2)/3, n1=(n+1)/3, n2=n/3, n02=n0+n2; int* s12 = new int[n02 + 3]; s12[n02]= s12[n02+1]= s12[n02+2]=0; int* SA12 = new int[n02 + 3]; SA12[n02]=SA12[n02+1]=SA12[n02+2]=0; int* s0 = new int[n0]; int* SA0 = new int[n0]; // generate positions of mod 1 and mod 2 suffixes // the "+(n0-n1)" adds a dummy mod 1 suffix if n%3 == 1 for (uint32_t i=0, j=0; i < n+(n0-n1); i++) if (i%3 != 0) s12[j++] = i; // lsb radix sort the mod 1 and mod 2 triples radixPass(s12 , SA12, s+2, n02, K); radixPass(SA12, s12 , s+1, n02, K); radixPass(s12 , SA12, s , n02, K); // find lexicographic names of triples int name = 0, c0 = -1, c1 = -1, c2 = -1; for (uint32_t i = 0; i < n02; i++) { if (s[SA12[i]] != c0 || s[SA12[i]+1] != c1 || s[SA12[i]+2] != c2) { name++; c0 = s[SA12[i]]; c1 = s[SA12[i]+1]; c2 = s[SA12[i]+2]; } if (SA12[i] % 3 == 1) { s12[SA12[i]/3] = name; } // left half else { s12[SA12[i]/3 + n0] = name; } // right half } // recurse if names are not yet unique if (name < n02) { suffixArray(s12, SA12, n02, name); // store unique names in s12 using the suffix array for (uint32_t i = 0; i < n02; i++) s12[SA12[i]] = i + 1; } else // generate the suffix array of s12 directly for (uint32_t i = 0; i < n02; i++) SA12[s12[i] - 1] = i; // stably sort the mod 0 suffixes from SA12 by their first character for (uint32_t i=0, j=0; i < n02; i++) if (SA12[i] < n0) s0[j++] = 3*SA12[i]; radixPass(s0, SA0, s, n0, K); // merge sorted SA0 suffixes and sorted SA12 suffixes for (uint32_t p=0, t=n0-n1, k=0; k < n; k++) { #define GetI() (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2) int i = GetI(); // pos of current offset 12 suffix int j = SA0[p]; // pos of current offset 0 suffix if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j/3]) : leq(s[i],s[i+1],s12[SA12[t]-n0+1], s[j],s[j+1],s12[j/3+n0])) { // suffix from SA12 is smaller SA[k] = i; t++; if (t == n02) { // done --- only SA0 suffixes left for (k++; p < n0; p++, k++) SA[k] = SA0[p]; } } else { SA[k] = j; p++; if (p == n0) { // done --- only SA12 suffixes left for (k++; t < n02; t++, k++) SA[k] = GetI(); } } } delete [] s12; delete [] SA12; delete [] SA0; delete [] s0; }
void suffixArray(VI &T, VI &SA, int n, int K) { int n0 = (n + 2) / 3, n1 = (n + 1) / 3, n2 = n / 3, n02 = n0 + n2; VI R(n02+3), SA12(n02+3), R0(n0), SA0(n0); for (int i = 0, j = 0; i < n + (n0 - n1); i++) if (i % 3 != 0) R[j++] = i; radixPass(R, SA12, T.begin() + 2, n02, K); radixPass(SA12, R, T.begin() + 1, n02, K); radixPass(R, SA12, T.begin(), n02, K); int name = 0, c0 = -1, c1 = -1, c2 = -1; for (int i = 0; i < n02; i++) { if (T[SA12[i]] != c0 || T[SA12[i] + 1] != c1 || T[SA12[i] + 2] != c2) { name++; c0 = T[SA12[i]]; c1 = T[SA12[i] + 1]; c2 = T[SA12[i] + 2]; } if (SA12[i] % 3 == 1) { R[SA12[i] / 3] = name; } else { R[SA12[i] / 3 + n0] = name; } } if (name < n02) { suffixArray(R, SA12, n02, name); for (int i = 0; i < n02; i++) R[SA12[i]] = i + 1; } else for (int i = 0; i < n02; i++) SA12[R[i] - 1] = i; for (int i = 0, j = 0; i < n02; i++) if (SA12[i] < n0) R0[j++] = 3 * SA12[i]; radixPass(R0, SA0, T.begin(), n0, K); for (int p = 0, t = n0 - n1, k = 0; k < n; k++) { #define GetI() (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2) int i = GetI(); // pos of current offset 12 suffix int j = SA0[p]; // pos of current offset 0 suffix if (SA12[t] < n0 ? // different compares for mod 1 and mod 2 suffixes leq(T[i], R[SA12[t] + n0], T[j], R[j / 3]) : leq(T[i], T[i + 1], R[SA12[t] - n0 + 1], T[j], T[j + 1], R[j / 3 + n0])) { // suffix from SA12 is smaller SA[k] = i; t++; if (t == n02) // done --- only SA0 suffixes left for (k++; p < n0; p++, k++) SA[k] = SA0[p]; } else { // suffix from SA0 is smaller SA[k] = j; p++; if (p == n0) // done --- only SA12 suffixes left for (k++; t < n02; t++, k++) SA[k] = GetI(); } } }
static void increment(pointer& x,pointer bbegin,pointer bbend) { std::less_equal<pointer> leq; x=x->next(); if(leq(bbegin,x)&&leq(x,bbend)) { /* bucket node */ do { ++x; } while(x->next()==x); x=x->next(); } }
static void increment( hashed_index_node_impl*& x, hashed_index_node_impl* bbegin,hashed_index_node_impl* bbend) { std::less_equal<hashed_index_node_impl*> leq; x=x->next(); if(leq(bbegin,x)&&leq(x,bbend)){ /* bucket node */ do{ ++x; }while(x->next()==x); x=x->next(); } }
static void sift_down(struct heap *h, size_t i) { while( L(i) < h->n ) { size_t l = L(i); size_t r = R(i); size_t j = l; if( r < h->n && leq(h, r, l) ) { j = r; } if( leq(h, i, j) ) { break; } swap(h, i, j); i = j; } }
int ChunkView::findWaypoint( const Vector3& inpt, float girth ) const { static Vector3 lastPt( 0.f, 0.f, 0.f ); static uint32 nextToSkip = 0; if (lastPt != inpt) { lastPt = inpt; nextToSkip = 0; } int toSkip = nextToSkip++; Vector2 pt(inpt.x, inpt.z); // do a brute force search for the polygon uint i, j; for (i = 0; i < polygons_.size(); i++) { const PolygonDef & p = polygons_[i]; if (!p.vertices.size()) continue; if (!this->equivGirth( i, girth )) continue; Vector2 av, bv; bv = p.vertices.back().position; for (j = 0; j < p.vertices.size(); j++) { av = bv; bv = p.vertices[j].position; LineEq leq( av, bv ); if (leq.isInFrontOf( pt )) break; } if (j == p.vertices.size() && toSkip--==0) return i; } nextToSkip = 0; return -1; }
static int callback (struct dl_phdr_info *info, size_t size, void *ptr) { static int last_adds = 0, last_subs = 0; intptr_t cmd = (intptr_t) ptr; printf (" size = %Zu\n", size); if (size < (offsetof (struct dl_phdr_info, dlpi_subs) + sizeof (info->dlpi_subs))) { fprintf (stderr, "dl_iterate_phdr failed to pass dlpi_adds/dlpi_subs\n"); exit (5); } printf (" dlpi_adds = %Lu dlpi_subs = %Lu\n", info->dlpi_adds, info->dlpi_subs); switch (cmd) { case SET: break; case ADD: if (leq (info->dlpi_adds, last_adds)) { fprintf (stderr, "dlpi_adds failed to get incremented!\n"); exit (3); } break; case REMOVE: if (leq (info->dlpi_subs, last_subs)) { fprintf (stderr, "dlpi_subs failed to get incremented!\n"); exit (4); } break; } last_adds = info->dlpi_adds; last_subs = info->dlpi_subs; return -1; }
// returns true if there is an intersection with the face, else returns false int testLinePlaneIntersection(GLfloat* la, GLfloat* lb, GLfloat* p0, GLfloat* p1, GLfloat* p2) { // returns true for indices where intersection occurs GLfloat a1=la[0]-lb[0], b1=la[1]-lb[1], c1=la[2]-lb[2]; GLfloat a2=p1[0]-p0[0], b2=p1[1]-p0[1], c2=p1[2]-p0[2]; GLfloat a3=p2[0]-p0[0], b3=p2[1]-p0[1], c3=p2[2]-p0[2]; GLfloat l1=la[0]-p0[0], l2=la[1]-p0[1], l3=la[2]-p0[2]; GLfloat denom=(a1*b2*c3 - a1*b3*c2 - a2*b1*c3 + a2*b3*c1 + a3*b1*c2 - a3*b2*c1); if (fabs(denom)<1e-6) return 0; // if you can't find an intersection because there is no solution, return notFacesSeen=0 ==> you are never blocked GLfloat num1= (a2*b3*l3 - a3*b2*l3 - a2*c3*l2 + a3*c2*l2 + b2*c3*l1 - b3*c2*l1); GLfloat num2=-(a1*b3*l3 - a3*b1*l3 - a1*c3*l2 + a3*c1*l2 + b1*c3*l1 - b3*c1*l1); GLfloat num3= (a1*b2*l3 - a2*b1*l3 - a1*c2*l2 + a2*c1*l2 + b1*c2*l1 - b2*c1*l1); GLfloat t1=num1/denom, t2=num2/denom, t3=num3/denom; return geq(t1,0) & leq(t1,1) & geq(t2,0) & geq(t3,0) & leq(t3,1) & leq(t2,1) & leq(t2+t3,1); }
bool IndexedBestFSStateSet::add(State *state){ // Ensure we're larger than any state in waiting. Pop any states smaller //std::cout<<"Checking waiting"<<std::endl; bool skipVisited = false; for(waitingIter it = _waiting.begin(); it != _waiting.end();){ if(this->less(it.item(), state)){ _waiting.remove(it++); this->_countRemove++; skipVisited = true; } else { if(this->leq(state, it.item())) return false; it++; } } //std::cout<<"Doing visited check"<<std::endl; // Perform visited check if(!skipVisited){ int is = state->stateIndex(*_net); for(visitIter it = _visited.begin(); it != _visited.end();){ int iv = it->first; if(is <= iv){ // Check we are not smaller then existing states if(leq(state, it->second)) return false; } it++; } } //std::cout<<"Doing heuristic distance"<<std::endl; // Calculate priority and add state PQL::DistanceContext context(*this->_net, _distanceStrategy, state->marking(), state->intValuation(), state->boolValuation(), _dm); double d = _query->distance(context); //std::cout<<"Pushing state to waiting"<<std::endl; _waiting.push(d, state); return true; }
void suffix_array(int *s, int *SA, int n, int K, int level = 0) { int n0 = (n+2)/3, n1 = (n+1)/3, n2 = n/3, n02 = n0+n2; int *s12 = pool[level][0], *SA12 = pool[level][1]; int *s0 = pool[level][2], *SA0 = pool[level][3]; s12[n02] = s12[n02+1] = s12[n02+2] = 0; SA12[n02] = SA12[n02+1] = SA12[n02+2] = 0; for (int i = 0, j = 0; i < n+(n0-n1); i++) { if (i % 3 != 0) { s12[j++] = i; } } radix(s12, SA12, s+2, n02, K); radix(SA12, s12, s+1, n02, K); radix(s12, SA12, s+0, n02, K); int name = 0, c0 = -1, c1 = -1, c2 = -1; for (int i = 0; i < n02; i++) { if (s[SA12[i]] != c0 || s[SA12[i]+1] != c1 || s[SA12[i]+2] != c2) { name++; c0 = s[SA12[i]]; c1 = s[SA12[i]+1]; c2 = s[SA12[i]+2]; } if (SA12[i] % 3 == 1) { s12[SA12[i]/3] = name; } else { s12[SA12[i]/3 + n0] = name; } } if (name < n02) { suffix_array(s12, SA12, n02, name, level+1); for (int i = 0; i < n02; i++) { s12[SA12[i]] = i + 1; } } else { for (int i = 0; i < n02; i++) { SA12[s12[i]-1] = i; } } for (int i = 0, j = 0; i < n02; i++) { if (SA12[i] < n0) { s0[j++] = 3*SA12[i]; } } radix(s0, SA0, s, n0, K); for (int p = 0, t = n0-n1, k = 0; k < n; k++) { int i = GetI(); int j = SA0[p]; if (SA12[t] < n0 ? leq(s[i], s12[SA12[t] + n0], s[j], s12[j/3]) : leq(s[i], s[i+1], s12[SA12[t]-n0+1], s[j], s[j+1], s12[j/3+n0])) { SA[k] = i; t++; if (t == n02) { for (k++; p < n0; p++, k++) { SA[k] = SA0[p]; } } } else { SA[k] = j; p++; if (p == n0) { for (k++; t < n02; t++, k++) { SA[k] = GetI(); } } } } }
// find the suffix array SA of T[0..n-1] in {1..K}^n // require T[n] = T[n+1] = T[n+2] = 0, n >= 2 void suffixArray(int* T, int* SA, int n, int K) { int n0 = (n + 2) / 3, n1 = (n + 1) / 3, n2 = n / 3, n02 = n0 + n2; int* R = new int[n02 + 3]; R[n02] = R[n02 + 1] = R[n02 + 2] = 0; int* SA12 = new int[n02 + 3]; SA12[n02] = SA12[n02 + 1] = SA12[n02 + 2] = 0; int* R0 = new int[n0]; int* SA0 = new int[n0]; //******* Step 0: Construct sample ******** // generate positions of mod 1 and mod 2 suffixes // the "+(n0-n1)" adds a dummy mod 1 suffix if n%3 == 1 for (int i = 0, j = 0; i < n + (n0 - n1); i++) if (i%3 != 0) R[j++] = i; //******* Step 1: Sort sample suffixes ******** // lsb radix sort the mod 1 and mod 2 triples radixPass(R, SA12, T + 2, n02, K); radixPass(SA12, R, T + 1, n02, K); radixPass(R, SA12, T, n02, K); // find lexicographic names of triples and // write them to correct places in R int name = 0, c0 = -1, c1 = -1, c2 = -1; for (int i = 0; i < n02; i++) { if (T[SA12[i]] != c0 || T[SA12[i] + 1] != c1 || T[SA12[i] + 2] != c2) { name++; c0 = T[SA12[i]]; c1 = T[SA12[i] + 1]; c2 = T[SA12[i] + 2]; } if (SA12[i] % 3 == 1) { R[SA12[i] / 3] = name; // write to R1 } else { R[SA12[i] / 3 + n0] = name; // write to R2 } } // recurse if names are not yet unique if (name < n02) { suffixArray(R, SA12, n02, name); // store unique names in R using the suffix array for (int i = 0; i < n02; i++) R[SA12[i]] = i + 1; } else // generate the suffix array of R directly for (int i = 0; i < n02; i++) SA12[R[i] - 1] = i; //******* Step 2: Sort nonsample suffixes ******** // stably sort the mod 0 suffixes from SA12 by their first character for (int i = 0, j = 0; i < n02; i++) if (SA12[i] < n0) R0[j++] = 3 * SA12[i]; radixPass(R0, SA0, T, n0, K); //******* Step 3: Merge ******** // merge sorted SA0 suffixes and sorted SA12 suffixes for (int p = 0, t = n0 - n1, k = 0; k < n; k++) { #define GetI() (SA12[t] < n0 ? SA12[t] * 3 + 1 : (SA12[t] - n0) * 3 + 2) int i = GetI(); // pos of current offset 12 suffix int j = SA0[p]; // pos of current offset 0 suffix if (SA12[t] < n0 ? // different compares for mod 1 and mod 2 suffixes leq(T[i], R[SA12[t] + n0], T[j], R[j / 3]) : leq(T[i], T[i+1], R[SA12[t] - n0 + 1], T[j], T[j + 1], R[j / 3 + n0])) { // suffix from SA12 is smaller SA[k] = i; t++; if (t == n02) // done --- only SA0 suffixes left for (k++; p < n0; p++, k++) SA[k] = SA0[p]; } else { // suffix from SA0 is smaller SA[k] = j; p++; if (p == n0) // done --- only SA12 suffixes left for (k++; t < n02; t++, k++) SA[k] = GetI(); } } delete [] R; delete [] SA12; delete [] SA0; delete [] R0; }
// and triples inline bool leq(int a1, int a2, int a3, int b1, int b2, int b3) { return(a1 < b1 || a1 == b1 && leq(a2,a3, b2,b3)); } // and triples
static bool gt(int c, int d) { return ff::not(leq(c, d)); };
static void sift_up(struct heap *h, size_t i) { for(; i && leq(h, i, P(i)); i = P(i) ) { swap(h, i, P(i)); } }
void executeInstruction() { switch(ir.op) { case 1: lit(); break; case 2: opr(); break; case 3: lod(); break; case 4: sto(); break; case 5: cal(); break; case 6: inc(); break; case 7: jmp(); break; case 8: jpc(); break; case 9: sio(); default: break; } void opr() { switch ( ir.m) { //rtn case 0: ret(); break; //neg case 1: neg(); break; //add case 2: add(); break; //sub case 3: sub(); break; //mul case 4: mul(); break; //div case 5: divid(); break; //odd case 6: odd(); break; //mod case 7: mod(); break; //eql case 8: eql(); break; //neq case 9: neq(); break; //lss case 10: lss(); break; //leq case 11: leq(); break; //gtr case 12: gtr(); break; //geq case 13: geq(); break; default: fprintf(output, "OP code input was invalid. "); halt = 1; break; } } }
int main () { unsigned char bytes[256]; int i; /* Table 2. Double-precision floating-point arithmetic. */ deq (__aeabi_dadd (dzero, done), done); deq (__aeabi_dadd (done, done), dtwo); deq (__aeabi_ddiv (dminus_four, dminus_two), dtwo); deq (__aeabi_ddiv (dminus_two, dtwo), dminus_one); deq (__aeabi_dmul (dtwo, dtwo), dfour); deq (__aeabi_dmul (dminus_one, dminus_two), dtwo); deq (__aeabi_dneg (dminus_one), done); deq (__aeabi_dneg (dfour), dminus_four); deq (__aeabi_drsub (done, dzero), dminus_one); deq (__aeabi_drsub (dtwo, dminus_two), dminus_four); deq (__aeabi_dsub (dzero, done), dminus_one); deq (__aeabi_dsub (dminus_two, dtwo), dminus_four); /* Table 3. Double-precision floating-point comparisons. */ ieq (__aeabi_dcmpeq (done, done), 1); ieq (__aeabi_dcmpeq (done, dzero), 0); ieq (__aeabi_dcmpeq (dNaN, dzero), 0); ieq (__aeabi_dcmpeq (dNaN, dNaN), 0); ieq (__aeabi_dcmplt (dzero, done), 1); ieq (__aeabi_dcmplt (done, dzero), 0); ieq (__aeabi_dcmplt (dzero, dzero), 0); ieq (__aeabi_dcmplt (dzero, dNaN), 0); ieq (__aeabi_dcmplt (dNaN, dNaN), 0); ieq (__aeabi_dcmple (dzero, done), 1); ieq (__aeabi_dcmple (done, dzero), 0); ieq (__aeabi_dcmple (dzero, dzero), 1); ieq (__aeabi_dcmple (dzero, dNaN), 0); ieq (__aeabi_dcmple (dNaN, dNaN), 0); ieq (__aeabi_dcmpge (dzero, done), 0); ieq (__aeabi_dcmpge (done, dzero), 1); ieq (__aeabi_dcmpge (dzero, dzero), 1); ieq (__aeabi_dcmpge (dzero, dNaN), 0); ieq (__aeabi_dcmpge (dNaN, dNaN), 0); ieq (__aeabi_dcmpgt (dzero, done), 0); ieq (__aeabi_dcmpgt (done, dzero), 1); ieq (__aeabi_dcmplt (dzero, dzero), 0); ieq (__aeabi_dcmpgt (dzero, dNaN), 0); ieq (__aeabi_dcmpgt (dNaN, dNaN), 0); ieq (__aeabi_dcmpun (done, done), 0); ieq (__aeabi_dcmpun (done, dzero), 0); ieq (__aeabi_dcmpun (dNaN, dzero), 1); ieq (__aeabi_dcmpun (dNaN, dNaN), 1); /* Table 4. Single-precision floating-point arithmetic. */ feq (__aeabi_fadd (fzero, fone), fone); feq (__aeabi_fadd (fone, fone), ftwo); feq (__aeabi_fdiv (fminus_four, fminus_two), ftwo); feq (__aeabi_fdiv (fminus_two, ftwo), fminus_one); feq (__aeabi_fmul (ftwo, ftwo), ffour); feq (__aeabi_fmul (fminus_one, fminus_two), ftwo); feq (__aeabi_fneg (fminus_one), fone); feq (__aeabi_fneg (ffour), fminus_four); feq (__aeabi_frsub (fone, fzero), fminus_one); feq (__aeabi_frsub (ftwo, fminus_two), fminus_four); feq (__aeabi_fsub (fzero, fone), fminus_one); feq (__aeabi_fsub (fminus_two, ftwo), fminus_four); /* Table 5. Single-precision floating-point comparisons. */ ieq (__aeabi_fcmpeq (fone, fone), 1); ieq (__aeabi_fcmpeq (fone, fzero), 0); ieq (__aeabi_fcmpeq (fNaN, fzero), 0); ieq (__aeabi_fcmpeq (fNaN, fNaN), 0); ieq (__aeabi_fcmplt (fzero, fone), 1); ieq (__aeabi_fcmplt (fone, fzero), 0); ieq (__aeabi_fcmplt (fzero, fzero), 0); ieq (__aeabi_fcmplt (fzero, fNaN), 0); ieq (__aeabi_fcmplt (fNaN, fNaN), 0); ieq (__aeabi_fcmple (fzero, fone), 1); ieq (__aeabi_fcmple (fone, fzero), 0); ieq (__aeabi_fcmple (fzero, fzero), 1); ieq (__aeabi_fcmple (fzero, fNaN), 0); ieq (__aeabi_fcmple (fNaN, fNaN), 0); ieq (__aeabi_fcmpge (fzero, fone), 0); ieq (__aeabi_fcmpge (fone, fzero), 1); ieq (__aeabi_fcmpge (fzero, fzero), 1); ieq (__aeabi_fcmpge (fzero, fNaN), 0); ieq (__aeabi_fcmpge (fNaN, fNaN), 0); ieq (__aeabi_fcmpgt (fzero, fone), 0); ieq (__aeabi_fcmpgt (fone, fzero), 1); ieq (__aeabi_fcmplt (fzero, fzero), 0); ieq (__aeabi_fcmpgt (fzero, fNaN), 0); ieq (__aeabi_fcmpgt (fNaN, fNaN), 0); ieq (__aeabi_fcmpun (fone, fone), 0); ieq (__aeabi_fcmpun (fone, fzero), 0); ieq (__aeabi_fcmpun (fNaN, fzero), 1); ieq (__aeabi_fcmpun (fNaN, fNaN), 1); /* Table 6. Floating-point to integer conversions. */ ieq (__aeabi_d2iz (dminus_one), -1); ueq (__aeabi_d2uiz (done), 1); leq (__aeabi_d2lz (dminus_two), -2LL); uleq (__aeabi_d2ulz (dfour), 4LL); ieq (__aeabi_f2iz (fminus_one), -1); ueq (__aeabi_f2uiz (fone), 1); leq (__aeabi_f2lz (fminus_two), -2LL); uleq (__aeabi_f2ulz (ffour), 4LL); /* Table 7. Conversions between floating types. */ feq (__aeabi_d2f (dtwo), ftwo); deq (__aeabi_f2d (fminus_four), dminus_four); /* Table 8. Integer to floating-point conversions. */ deq (__aeabi_i2d (-1), dminus_one); deq (__aeabi_ui2d (2), dtwo); deq (__aeabi_l2d (-1), dminus_one); deq (__aeabi_ul2d (2ULL), dtwo); feq (__aeabi_i2f (-1), fminus_one); feq (__aeabi_ui2f (2), ftwo); feq (__aeabi_l2f (-1), fminus_one); feq (__aeabi_ul2f (2ULL), ftwo); /* Table 9. Long long functions. */ leq (__aeabi_lmul (4LL, -1LL), -4LL); leq (__aeabi_llsl (2LL, 1), 4LL); leq (__aeabi_llsr (-1LL, 63), 1); leq (__aeabi_lasr (-1LL, 63), -1); ieq (__aeabi_lcmp (0LL, 1LL), -1); ieq (__aeabi_lcmp (0LL, 0LL), 0); ieq (__aeabi_lcmp (1LL, 0LL), 1); ieq (__aeabi_ulcmp (0LL, 1LL), -1); ieq (__aeabi_ulcmp (0LL, 0LL), 0); ieq (__aeabi_ulcmp (1LL, 0LL), 1); ieq (__aeabi_idiv (-550, 11), -50); ueq (__aeabi_uidiv (4000000000U, 1000000U), 4000U); for (i = 0; i < 256; i++) bytes[i] = i; #ifdef __ARMEB__ ieq (__aeabi_uread4 (bytes + 1), 0x01020304U); leq (__aeabi_uread8 (bytes + 3), 0x030405060708090aLL); ieq (__aeabi_uwrite4 (0x66778899U, bytes + 5), 0x66778899U); leq (__aeabi_uwrite8 (0x2030405060708090LL, bytes + 15), 0x2030405060708090LL); #else ieq (__aeabi_uread4 (bytes + 1), 0x04030201U); leq (__aeabi_uread8 (bytes + 3), 0x0a09080706050403LL); ieq (__aeabi_uwrite4 (0x99887766U, bytes + 5), 0x99887766U); leq (__aeabi_uwrite8 (0x9080706050403020LL, bytes + 15), 0x9080706050403020LL); #endif for (i = 0; i < 4; i++) ieq (bytes[5 + i], (6 + i) * 0x11); for (i = 0; i < 8; i++) ieq (bytes[15 + i], (2 + i) * 0x10); exit (0); }
inline bool leq(int a1, int a2, int a3, int b1, int b2, int b3) { return (a1 < b1 || (a1 == b1 && leq(a2, a3, b2, b3))); }
relation_t pdbm_relationWithMinDBM(const PDBM pdbm1, cindex_t dim, const mingraph_t pdbm2, raw_t *dbm2) { assert(pdbm1 && pdbm2 && dim && dbm2); raw_t *dbm1 = pdbm_matrix(pdbm1); int32_t cost1 = pdbm_cost(pdbm1); int32_t *rates1 = pdbm_rates(pdbm1); int32_t c, d; /* We know how the cost and the rates are encoded in a mingraph: * see writeToMinDBMWithOffset and readFromMinDBM. */ int32_t cost2 = pdbm2[0]; const int32_t *rates2 = pdbm2 + 2; /* dbm_relationWithMinDBM will in some cases unpack pdbm2 into * dbm2. In order to detect whether this has happened, we set the * first entry of dbm2 to -1. If dbm_relationWithMinDBM did indeed * unpack pdbm2, this entry will have a different value * afterwards. */ dbm2[0] = -1; switch (dbm_relationWithMinDBM(dbm1, dim, pdbm2 + dim + 2, dbm2)) { case base_SUPERSET: /* pdbm2 is smaller. Check whether it is also the most * expensive: This is the case when the difference between * pdbm2 and pdbm1 is always non-negative (the infimum is not * smaller than 0). */ if (dbm2[0] == -1) { dbm_readFromMinDBM(dbm2, pdbm2 + dim + 2); } cost1 = costAtOtherOffset(dbm1, rates1, cost1, dbm2, dim); if (cost1 <= cost2 && (leq(rates1, rates1 + dim, rates2) || infOfDiff(dbm2, dim, cost2, rates2, cost1, rates1) >= 0)) { return base_SUPERSET; } else { return base_DIFFERENT; } case base_SUBSET: /* pdbm2 is bigger. Check whether it is also the cheapest: * This is the case when the difference between pdbm1 and * pdbm2 is always non-negative (the infimum is not smaller * than 0). */ if (dbm2[0] == -1) { dbm_readFromMinDBM(dbm2, pdbm2 + dim + 2); } cost2 = costAtOtherOffset(dbm2, rates2, cost2, dbm1, dim); if (cost2 <= cost1 && (leq(rates2, rates2 + dim, rates1) || infOfDiff(dbm1, dim, cost1, rates1, cost2, rates2) >= 0)) { return base_SUBSET; } else { return base_DIFFERENT; } case base_EQUAL: /* Both have the same size. We need to compare the planes to * see which one is cheaper. */ /* Do sound and cheap comparison first. */ c = cost1 <= cost2 && leq(rates1, rates1 + dim, rates2); d = cost2 <= cost1 && leq(rates2, rates2 + dim, rates1); if (c & d) { return base_EQUAL; } else if (c) { return base_SUPERSET; } else if (d) { return base_SUBSET; } /* The planes are incomparable, so we need to do the * subtraction. Notice that priced zones are not canonical, * so the two zones can in fact be equal even though the rates * are different. Therefore we must also check for the * situation where both infima are zero. * * Notice that dbm1 equals dbm2, hence we do not need to * unpacked dbm2. */ c = infOfDiff(dbm1, dim, cost2, rates2, cost1, rates1); if (c > 0) { /* Early return to avoid unnecessary computation of the * second subtraction. */ return base_SUPERSET; } d = infOfDiff(dbm1, dim, cost1, rates1, cost2, rates2); if (c == 0 && d == 0) { return base_EQUAL; } if (c >= 0) { return base_SUPERSET; } if (d >= 0) { return base_SUBSET; } return base_DIFFERENT; default: return base_DIFFERENT; } }
relation_t pdbm_relation(const PDBM pdbm1, const PDBM pdbm2, cindex_t dim) { assert(pdbm1 && pdbm2 && dim); raw_t *dbm1 = pdbm_matrix(pdbm1); raw_t *dbm2 = pdbm_matrix(pdbm2); int32_t *rates1 = pdbm_rates(pdbm1); int32_t *rates2 = pdbm_rates(pdbm2); int32_t cost1 = pdbm_cost(pdbm1); int32_t cost2 = pdbm_cost(pdbm2); int32_t c, d; switch (dbm_relation(dbm1, dbm2, dim)) { case base_SUPERSET: /* pdbm2 is smaller. Check whether it is also the most * expensive: This is the case when the difference between * pdbm2 and pdbm1 is always non-negative (the infimum is not * smaller than 0). */ cost1 = costAtOtherOffset(dbm1, rates1, cost1, dbm2, dim); if (cost1 <= cost2 && (leq(rates1, rates1 + dim, rates2) || infOfDiff(dbm2, dim, cost2, rates2, cost1, rates1) >= 0)) { return base_SUPERSET; } else { return base_DIFFERENT; } case base_SUBSET: /* pdbm2 is bigger. Check whether it is also the cheapest: * This is the case when the difference between pdbm1 and * pdbm2 is always non-negative (the infimum is not smaller * than 0). */ cost2 = costAtOtherOffset(dbm2, rates2, cost2, dbm1, dim); if (cost2 <= cost1 && (leq(rates2, rates2 + dim, rates1) || infOfDiff(dbm1, dim, cost1, rates1, cost2, rates2) >= 0)) { return base_SUBSET; } else { return base_DIFFERENT; } case base_EQUAL: /* Both have the same size. We need to compare the planes to * see which one is cheaper. */ /* Do sound and cheap comparison first. */ /* This test is not sound when the zone is reduced to a single point */ // c = cost1 <= cost2 && leq(rates1, rates1 + dim, rates2); // d = cost2 <= cost1 && leq(rates2, rates2 + dim, rates1); // // if (c & d) // { // return base_EQUAL; // } // else if (c) // { // return base_SUPERSET; // } // else if (d) // { // return base_SUBSET; // } /* The planes are incomparable, so we need to do the * subtraction. Notice that priced zones are not canonical, * so the two zones can in fact be equal even though the rates * are different. Therefore we must also check for the * situation where both infima are zero. * * Notice that dbm1 equals dbm2, hence we do not need to * unpack dbm2. */ c = infOfDiff(dbm1, dim, cost2, rates2, cost1, rates1); if (c > 0) { /* Early return to avoid unnecessary computation of the * second subtraction. */ return base_SUPERSET; } d = infOfDiff(dbm1, dim, cost1, rates1, cost2, rates2); if (c == 0 && d == 0) { return base_EQUAL; } if (c >= 0) { return base_SUPERSET; } if (d >= 0) { return base_SUBSET; } return base_DIFFERENT; default: return base_DIFFERENT; } }
void opr() { switch ( ir.m) { //rtn case 0: ret(); break; //neg case 1: neg(); break; //add case 2: add(); break; //sub case 3: sub(); break; //mul case 4: mul(); break; //div case 5: divid(); break; //odd case 6: odd(); break; //mod case 7: mod(); break; //eql case 8: eql(); break; //neq case 9: neq(); break; //lss case 10: lss(); break; //leq case 11: leq(); break; //gtr case 12: gtr(); break; //geq case 13: geq(); break; default: fprintf(output, "OP code input was invalid. "); sio3(); } }
CompileOutput *Compiler::Compile(AMXRef amx) { Prepare(amx); Disassembler disasm(amx); Instruction instr; bool error = false; while (!error && disasm.Decode(instr, error)) { if (!Process(instr)) { error = true; break; } switch (instr.opcode().GetId()) { case OP_LOAD_PRI: load_pri(instr.operand()); break; case OP_LOAD_ALT: load_alt(instr.operand()); break; case OP_LOAD_S_PRI: load_s_pri(instr.operand()); break; case OP_LOAD_S_ALT: load_s_alt(instr.operand()); break; case OP_LREF_PRI: lref_pri(instr.operand()); break; case OP_LREF_ALT: lref_alt(instr.operand()); break; case OP_LREF_S_PRI: lref_s_pri(instr.operand()); break; case OP_LREF_S_ALT: lref_s_alt(instr.operand()); break; case OP_LOAD_I: load_i(); break; case OP_LODB_I: lodb_i(instr.operand()); break; case OP_CONST_PRI: const_pri(instr.operand()); break; case OP_CONST_ALT: const_alt(instr.operand()); break; case OP_ADDR_PRI: addr_pri(instr.operand()); break; case OP_ADDR_ALT: addr_alt(instr.operand()); break; case OP_STOR_PRI: stor_pri(instr.operand()); break; case OP_STOR_ALT: stor_alt(instr.operand()); break; case OP_STOR_S_PRI: stor_s_pri(instr.operand()); break; case OP_STOR_S_ALT: stor_s_alt(instr.operand()); break; case OP_SREF_PRI: sref_pri(instr.operand()); break; case OP_SREF_ALT: sref_alt(instr.operand()); break; case OP_SREF_S_PRI: sref_s_pri(instr.operand()); break; case OP_SREF_S_ALT: sref_s_alt(instr.operand()); break; case OP_STOR_I: stor_i(); break; case OP_STRB_I: strb_i(instr.operand()); break; case OP_LIDX: lidx(); break; case OP_LIDX_B: lidx_b(instr.operand()); break; case OP_IDXADDR: idxaddr(); break; case OP_IDXADDR_B: idxaddr_b(instr.operand()); break; case OP_ALIGN_PRI: align_pri(instr.operand()); break; case OP_ALIGN_ALT: align_alt(instr.operand()); break; case OP_LCTRL: lctrl(instr.operand(), instr.address() + instr.size()); break; case OP_SCTRL: sctrl(instr.operand()); break; case OP_MOVE_PRI: move_pri(); break; case OP_MOVE_ALT: move_alt(); break; case OP_XCHG: xchg(); break; case OP_PUSH_PRI: push_pri(); break; case OP_PUSH_ALT: push_alt(); break; case OP_PUSH_C: push_c(instr.operand()); break; case OP_PUSH: push(instr.operand()); break; case OP_PUSH_S: push_s(instr.operand()); break; case OP_POP_PRI: pop_pri(); break; case OP_POP_ALT: pop_alt(); break; case OP_STACK: // value stack(instr.operand()); break; case OP_HEAP: heap(instr.operand()); break; case OP_PROC: proc(); break; case OP_RET: ret(); break; case OP_RETN: retn(); break; case OP_JUMP_PRI: jump_pri(); break; case OP_CALL: case OP_JUMP: case OP_JZER: case OP_JNZ: case OP_JEQ: case OP_JNEQ: case OP_JLESS: case OP_JLEQ: case OP_JGRTR: case OP_JGEQ: case OP_JSLESS: case OP_JSLEQ: case OP_JSGRTR: case OP_JSGEQ: { cell dest = instr.operand() - reinterpret_cast<cell>(amx.code()); switch (instr.opcode().GetId()) { case OP_CALL: call(dest); break; case OP_JUMP: jump(dest); break; case OP_JZER: jzer(dest); break; case OP_JNZ: jnz(dest); break; case OP_JEQ: jeq(dest); break; case OP_JNEQ: jneq(dest); break; case OP_JLESS: jless(dest); break; case OP_JLEQ: jleq(dest); break; case OP_JGRTR: jgrtr(dest); break; case OP_JGEQ: jgeq(dest); break; case OP_JSLESS: jsless(dest); break; case OP_JSLEQ: jsleq(dest); break; case OP_JSGRTR: jsgrtr(dest); break; case OP_JSGEQ: jsgeq(dest); break; } break; } case OP_SHL: shl(); break; case OP_SHR: shr(); break; case OP_SSHR: sshr(); break; case OP_SHL_C_PRI: shl_c_pri(instr.operand()); break; case OP_SHL_C_ALT: shl_c_alt(instr.operand()); break; case OP_SHR_C_PRI: shr_c_pri(instr.operand()); break; case OP_SHR_C_ALT: shr_c_alt(instr.operand()); break; case OP_SMUL: smul(); break; case OP_SDIV: sdiv(); break; case OP_SDIV_ALT: sdiv_alt(); break; case OP_UMUL: umul(); break; case OP_UDIV: udiv(); break; case OP_UDIV_ALT: udiv_alt(); break; case OP_ADD: add(); break; case OP_SUB: sub(); break; case OP_SUB_ALT: sub_alt(); break; case OP_AND: and_(); break; case OP_OR: or_(); break; case OP_XOR: xor_(); break; case OP_NOT: not_(); break; case OP_NEG: neg(); break; case OP_INVERT: invert(); break; case OP_ADD_C: add_c(instr.operand()); break; case OP_SMUL_C: smul_c(instr.operand()); break; case OP_ZERO_PRI: zero_pri(); break; case OP_ZERO_ALT: zero_alt(); break; case OP_ZERO: zero(instr.operand()); break; case OP_ZERO_S: zero_s(instr.operand()); break; case OP_SIGN_PRI: sign_pri(); break; case OP_SIGN_ALT: sign_alt(); break; case OP_EQ: eq(); break; case OP_NEQ: neq(); break; case OP_LESS: less(); break; case OP_LEQ: leq(); break; case OP_GRTR: grtr(); break; case OP_GEQ: geq(); break; case OP_SLESS: sless(); break; case OP_SLEQ: sleq(); break; case OP_SGRTR: sgrtr(); break; case OP_SGEQ: sgeq(); break; case OP_EQ_C_PRI: eq_c_pri(instr.operand()); break; case OP_EQ_C_ALT: eq_c_alt(instr.operand()); break; case OP_INC_PRI: inc_pri(); break; case OP_INC_ALT: inc_alt(); break; case OP_INC: inc(instr.operand()); break; case OP_INC_S: inc_s(instr.operand()); break; case OP_INC_I: inc_i(); break; case OP_DEC_PRI: dec_pri(); break; case OP_DEC_ALT: dec_alt(); break; case OP_DEC: dec(instr.operand()); break; case OP_DEC_S: dec_s(instr.operand()); break; case OP_DEC_I: dec_i(); break; case OP_MOVS: movs(instr.operand()); break; case OP_CMPS: cmps(instr.operand()); break; case OP_FILL: fill(instr.operand()); break; case OP_HALT: halt(instr.operand()); break; case OP_BOUNDS: bounds(instr.operand()); break; case OP_SYSREQ_PRI: sysreq_pri(); break; case OP_SYSREQ_C: { const char *name = amx.GetNativeName(instr.operand()); if (name == 0) { error = true; } else { sysreq_c(instr.operand(), name); } break; } case OP_SYSREQ_D: { const char *name = amx.GetNativeName(amx.FindNative(instr.operand())); if (name == 0) { error = true; } else { sysreq_d(instr.operand(), name); } break; } case OP_SWITCH: switch_(CaseTable(amx, instr.operand())); break; case OP_CASETBL: casetbl(); break; case OP_SWAP_PRI: swap_pri(); break; case OP_SWAP_ALT: swap_alt(); break; case OP_PUSH_ADR: push_adr(instr.operand()); break; case OP_NOP: nop(); break; case OP_BREAK: break_(); break; default: error = true; } } if (error && error_handler_ != 0) { error_handler_->Execute(instr); } return Finish(error); }