//---------------------------------------------------------------------------
	void simplify(int code_length)
	{
#ifdef SIMPLIFY
		bool *marked = new bool[code_length];
		for (int i = 0; i < code_length; marked[i++] = false);
		mark(code_length - 1, marked);

		// how many are skipped until a given instruction
		int *skipped = new int[code_length];
		if (!marked[0])
			skipped[0] = 1;
		else
			skipped[0] = 0;
		for (int i = 1; i < code_length; i++)
			if (!marked[i])
				skipped[i] = skipped[i - 1] + 1;
			else
				skipped[i] = skipped[i - 1];

		if (simplified_prg)
			delete[] simplified_prg;
		simplified_prg = new t_code3[code_length];

		num_utilized_instructions = 0;
		for (int i = 0; i < code_length; i++)
			if (marked[i]) {
				simplified_prg[num_utilized_instructions] = prg[i];
				if (prg[i].op < 0) {// operator
					simplified_prg[num_utilized_instructions].adr1 -= skipped[prg[i].adr1];
					simplified_prg[num_utilized_instructions].adr2 -= skipped[prg[i].adr2];
				}
				num_utilized_instructions++;
			}

		delete[] skipped;
		delete[] marked;
#else
		if (simplified_prg)
			delete[] simplified_prg;
		simplified_prg = new t_code3[code_length];
		num_utilized_instructions = code_length;
		for (int i = 0; i < code_length; i++)
			simplified_prg[i] = prg[i];
#endif
	}
Пример #2
0
/* Make sure we get the calculation in RFC 1624 section 4 correct. */
static void
test_rfc1624(void)
{
    /* "...an IP packet header in which a 16-bit field m = 0x5555..." */
    uint8_t data[32] = {
        0xfe, 0x8f, 0xc1, 0x14, 0x4b, 0x6f, 0x70, 0x2a,
        0x80, 0x29, 0x78, 0xc0, 0x58, 0x81, 0x77, 0xaa,
        0x66, 0x64, 0xfc, 0x96, 0x63, 0x97, 0x64, 0xee,
        0x12, 0x53, 0x1d, 0xa9, 0x2d, 0xa9, 0x55, 0x55
    };

    /* "...the one's complement sum of all other header octets is 0xCD7A." */
    assert(ntohs(csum(data, sizeof data - 2)) == 0xffff - 0xcd7a);

    /* "...the header checksum would be:

          HC = ~(0xCD7A + 0x5555)
             = ~0x22D0
             =  0xDD2F"
    */
    assert(ntohs(csum(data, sizeof data)) == 0xdd2f);

    /* "a 16-bit field m = 0x5555 changes to m' = 0x3285..." */
    data[30] = 0x32;
    data[31] = 0x85;

    /* "The new checksum via recomputation is:

          HC' = ~(0xCD7A + 0x3285)
              = ~0xFFFF
              =  0x0000"
    */
    assert(ntohs(csum(data, sizeof data)) == 0x0000);

    /* "Applying [Eqn. 3] to the example above, we get the correct result:

          HC' = ~(C + (-m) + m')
              = ~(0x22D0 + ~0x5555 + 0x3285)
              = ~0xFFFF
              =  0x0000" */
    assert(recalc_csum16(htons(0xdd2f), htons(0x5555), htons(0x3285))
           == htons(0x0000));

    mark('#');
}
Пример #3
0
int main()
{int i;
//for(i=0;i<=1000;i++){
//printf("%d ",a[i]);
//}
   //printf("%d")
   int cnt=0;
   for(i=2;i<=sqrt(n-1);i++)
	{ if (a[i]==0)
		mark(i);
	}   
  for(i=2;i<=n-1;i++){
if (a[i]==0){cnt++;
}}
printf("%d",cnt);


}
Пример #4
0
Файл: gc.c Проект: bhuztez/lisp0
void
gc(struct lisp0_state*state){
  mark(state->env);
  mark(state->x);
  mark(state->y);
  mark(state->z);

  term_t *sp = state->sp, *bp = state->bp;
  for(;bp;++sp){
    for(;sp<bp;++sp)
      mark(*sp);
    bp = (term_t*)*sp++;
  }

  for(struct list_builder *builder=state->builder;builder;builder=builder->next)
    for(struct list*list=(struct list*)(builder->result);list;list=(struct list*)list->tail)
      mark(list->head);

  struct gc_header **gch=&(state->gc_stack);

  for(struct gc_header*current=state->gc_stack;current;){
    if(MARK(current)){
      gch = &(current->next);
      MARK(current)=0;
      switch(PTAG(current)){
      case PTAG_LIST:
      case PTAG_LAMBDA:
      case PTAG_MACRO:
        mark(CAR(current));
        mark(CDR(current));
        break;
      default:
        ;
      };
      current = current -> next;
    }else{
      *gch = current->next;
      mem_free(&(state->pool),current);
      current = *gch;
    }
  }
}
Пример #5
0
  // Support for intptr_t Atomic::cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value)
  //
  // Arguments:
  //
  //     exchange_value - GR_I0
  //     dest           - GR_I1
  //     compare_value  - GR_I2
  //
  // Results:
  //
  //     GR_RET - the value previously stored in dest
  //
  address generate_atomic_cmpxchg_ptr() {
    StubCodeMark mark(this, "StubRoutines", "atomic_cmpxchg_ptr");

    const Register exchange_value = GR_I0;
    const Register dest           = GR_I1;
    const Register compare_value  = GR_I2;

    address start = __ emit_fd();

    __ mf();

    __ mov(AR_CCV, compare_value);
    __ cmpxchg8(GR_RET, dest, exchange_value, Assembler::acquire);

    __ ret();

    return start;
  }
Пример #6
0
// Send a Mitsubishi message
//
// Args:
//   data:   Contents of the message to be sent.
//   nbits:  Nr. of bits of data to be sent. Typically MITSUBISHI_BITS.
//   repeat: Nr. of additional times the message is to be sent.
//
// Status: ALPHA / untested.
//
// Notes:
//   This protocol appears to have no header.
// Ref:
//   https://github.com/marcosamarinho/IRremoteESP8266/blob/master/ir_Mitsubishi.cpp
//   GlobalCache's Control Tower's Mitsubishi TV data.
void IRsend::sendMitsubishi(uint64_t data, uint16_t nbits, uint16_t repeat) {
  enableIROut(33);  // Set IR carrier frequency
  IRtimer usecTimer = IRtimer();

  for (uint16_t i = 0; i <= repeat; i++) {
    usecTimer.reset();
    // No header

    // Data
    sendData(MITSUBISHI_BIT_MARK, MITSUBISHI_ONE_SPACE,
             MITSUBISHI_BIT_MARK, MITSUBISHI_ZERO_SPACE,
             data, nbits, true);
    // Footer
    mark(MITSUBISHI_BIT_MARK);
    space(std::max(MITSUBISHI_MIN_COMMAND_LENGTH - usecTimer.elapsed(),
                   MITSUBISHI_MIN_GAP));
  }
}
Пример #7
0
bool BoardGenerator::guess(int round, int guessNumber){
    int localGuessCount = 0;
    int position = findPositionWithFewestPossibilities();
    {for (int i=0; i<NUM_POSS; i++){
            int valIndex = randomPossibilityArray[i];
            int valPos = getPossibilityIndex(valIndex,position);
            if (possibilities[valPos] == 0){
                if (localGuessCount == guessNumber){
                    int value = valIndex+1;
                    if (recordHistory) addHistoryItem(new LogItem(round, LogItem::GUESS, value, position));
                    mark(position, round, value);
                    return true;
                }
                localGuessCount++;
            }
        }}
    return false;
}
Пример #8
0
void ICACHE_FLASH_ATTR ir_remote_send_raw(uint16_t buf[], uint16_t len, uint16_t freq_hz)
{
	set_carrier_frequence(SONY_FREQUENCY);

	uint16_t i;
	for (i = 0; i < len; i++)
	{
		if (i & 1)
		{
			space(buf[i]);
		}
		else
		{
			mark(buf[i]);
		}
	}
	space(0);
}
Пример #9
0
/* obsluha zmacknuti klavesy */
void ArchiveViewer::keyPressEvent(QKeyEvent *e){
    if(e->key() == Qt::Key_Insert)
        mark(!marked);
    else if(e->key() == Qt::Key_Shift){
        std::string msg("Selecting items is not allowed in archives");
        MyDialog::MsgBox(msg);
    }else if(e->key() == Qt::Key_Backspace){
        emit(chlayout());
        setFocus();
    }else if(e->key() == Qt::Key_Return){
        currentItem()->setExpanded(!currentItem()->isExpanded());
    }else if(e->key() == Qt::Key_F1)
        emit(chlayout());
    else if(e->key() == Qt::Key_F11)
        emit(refresh());
    else // zpracuj normalne
        QTreeWidget::keyPressEvent(e);
}
Пример #10
0
void ICacheStubGenerator::generate_icache_flush(
  ICache::flush_icache_stub_t* flush_icache_stub
) {
  StubCodeMark mark(this, "ICache", "flush_icache_stub");
  address start = __ pc();

  Label L;
  __ bind(L);
  __ flush( O0, G0 );
  __ deccc( O1 );
  __ br(Assembler::positive, false, Assembler::pn, L);
  __ delayed()->inc( O0, 8 );
  __ retl(false);
  __ delayed()->mov( O2, O0 ); // handshake with caller to make sure it happened!

  // Must be set here so StubCodeMark destructor can call the flush stub.
  *flush_icache_stub = (ICache::flush_icache_stub_t)start;
};
Пример #11
0
void CalcIncoherentScattering(const long long int iter_num,
                              const double energy_MeV,
                              SharedCompoundPtr target)
{

    // Gen X axis
    int graduation=50;
    double radStep=180.0/(double)graduation;

    std::vector<double> rad;
    double sum=0.0;
    for(int i=0; i<graduation; i++) {
        rad.push_back(sum);
        sum+=radStep;
    }

    // Gen Y axis
    UniformRandomGenerator0to1 random(12345);
    std::vector<double> hist(graduation, 0);
    for(long long int i=0; i<iter_num; i++) {
        RunLight(i,iter_num);
        PointVector_t ray(1.0, 1.0, 1.0);
        SharedPhotonPtr photon = Photon::CreatePhoton(energy_MeV, ray);
        while(photon->IncoherentScattering(target, random) == MC_REJECTED) {}
        for(int j=0; j<graduation; j++) {
            if(photon->GetIncline_rad() < (double)(j *radStep)*M_PI/180.0 ) {
                hist[j]++;
                break;
            }
        }
    }
    double sumhist =std::accumulate(hist.begin(), hist.end(), 0.0);
    for(int i=0; i<hist.size(); i++) {
        hist[i] /=sumhist;
    }

    // Plot
    std::cout << "\r" << "     ";
    std::string mark("*");
    std::string xlabel("degree");
    std::string ylabel("probability");
    Plotter plotter(graduation, 18, xlabel, ylabel);
    plotter.Plot(rad, hist, mark);
}
Пример #12
0
void ExprCopy::visit(const ExprVector& e) {
	for (int i=0; i<e.nb_args; i++)
		visit(e.arg(i));

	if (fold) {
		int i=0;
		for (; i<e.nb_args; i++) {
			if (!dynamic_cast<const ExprConstant*>(&ARG(i))) break;
		}
		if (i==e.nb_args) {
			if (e.dim.is_vector()) {
				IntervalVector v(e.dim.vec_size());
				for (i=0; i<e.nb_args; i++) {
					v[i]=((const ExprConstant&) ARG(i)).get_value();
				}
				clone.insert(e, &ExprConstant::new_vector(v,e.row_vector()));
			} else if (e.dim.type()==Dim::MATRIX) {
				IntervalMatrix m(e.dim.dim2,e.dim.dim3);
				for (i=0; i<e.nb_args; i++) {
					m.set_row(i,((const ExprConstant&) ARG(i)).get_vector_value());
				}
				clone.insert(e, &ExprConstant::new_matrix(m));
			} else {
				assert(e.dim.type()==Dim::MATRIX_ARRAY);
				IntervalMatrixArray ma(e.dim.dim1,e.dim.dim2,e.dim.dim3);
				for (i=0; i<e.nb_args; i++) {
					ma[i]=((const ExprConstant&) ARG(i)).get_matrix_value();
				}
				clone.insert(e, &ExprConstant::new_matrix_array(ma));
			}
			return;
		}
	}

	Array<const ExprNode> args2(e.nb_args);
	for (int i=0; i<e.nb_args; i++) {
		args2.set_ref(i,ARG(i));
		// don't remove this node even if it is a constant because
		// it is an element of this vector.
		mark(e.arg(i));
	}

	clone.insert(e, &ExprVector::new_(args2,e.row_vector()));
}
Пример #13
0
void mark(CELLP cp, int n) {
	char c = cp->id;
	//既に処理済みの物は対象外
	if(c & USED) {
		return;
	}
	//nilもノータッチ
	if(cp == (CELLP)nil) {
		return;
	}

	// 以下は、atom、cell、numの新世代の2つの領域と旧世代領域、sysatom領域について同じ処理
	switch(c) {
		case _ATOM: 
			//if(prompt == (ATOMP)cp) { printf("[M prompt's id=%x] --> ", (int)(((ATOMP)cp)->id)); }
			cp->id |= USED;
			//if(prompt == (ATOMP)cp) { printf("[M prompt's id=%x]\n", (int)(((ATOMP)cp)->id)); }
			mark(((ATOMP)cp)->value, n);
			mark(((ATOMP)cp)->plist, n);
			mark(((ATOMP)cp)->forwarding, n);
//			if(!((((ATOMP)cp)->ftype) & NONMRK)) {
			if(((ATOMP)cp)->ftype == _EXPR){
				mark(((ATOMP)cp)->fptr, n);
			}
			break;
		case _CELL: 
			cp->id |= USED;
			mark(cp->forwarding, n);
			mark(cp->car, n);
			mark(cp->cdr, n);
			break;
		case _FIX:
		case _FLT:
			if(n) {
				cp->id |= USED;
				if(((NUMP)cp)->forwarding) mark(((NUMP)cp)->forwarding, n);
			}
			break;
	}
	return;
}
Пример #14
0
/* -----------------------------------------------------------------------------
 * Handeling Commands 
 * ---------------------------------------------------------------------------*/
char * handleCommand(char * request) {
  fprintf(stderr, "Recv from Socket: %s", request);

  char *tokens[5]; char *token; int i = 0;
  while ((token = nextToken(&request))) {
    tokens[i] = token;
    i++;
  }

  char * response = "Some arbitrary response back to the socket\0";

  if (!strcmp(tokens[0], "dimensions"))
    dimensions(tokens[1], tokens[2]);


  if (!strcmp(tokens[0], "absorb"))
    absorb(tokens[1], tokens[2]);
  if (!strcmp(tokens[0], "containerize"))
    containerize();
  else if (!strcmp(tokens[0], "focus"))
    focus(tokens[1], tokens[2]);
  else if (!strcmp(tokens[0], "get"))
    response = get(tokens[1]);
  else if(!strcmp(tokens[0], "jump"))
    jump(tokens[1]);
  else if (!strcmp(tokens[0], "kill"))
    kill();
  else if (!strcmp(tokens[0], "layout"))
    layout(tokens[1]);
  else if (!strcmp(tokens[0], "mark"))
    mark(tokens[1]);
  else if (!strcmp(tokens[0], "set"))
    set(tokens[1], tokens[2]);
  else if (!strcmp(tokens[0], "shift"))
    shift(tokens[1], atoi(tokens[2]));
  else if (!strcmp(tokens[0], "swap"))
    swap(tokens[1], tokens[2]);
  else if (!strcmp(tokens[0], "zoom"))
    zoom(atoi(tokens[1]));

  XFlush(display);
  return response;
}
Пример #15
0
size32_t aesEncryptWithRSAEncryptedKey(MemoryBuffer &out, size32_t inSz, const void *inBytes, const CLoadedKey &publicKey)
{
    // create random AES key and IV
    char randomAesKey[aesMaxKeySize];
    char randomIV[aesBlockSize];
    fillRandomData(aesMaxKeySize, randomAesKey);
    fillRandomData(aesBlockSize, randomIV);

    size32_t startSz = out.length();
    DelayedSizeMarker mark(out);
    publicKeyEncrypt(out, aesMaxKeySize, randomAesKey, publicKey);
    mark.write();
    out.append(aesBlockSize, randomIV);

    DelayedSizeMarker aesSz(out);
    aesEncrypt(out, inSz, inBytes, aesMaxKeySize, randomAesKey, randomIV);
    aesSz.write();
    return out.length()-startSz;
}
void AdaptiveRegularRefiner_MultiGrid::
perform_refinement()
{
//	todo: copy refinement marks from closure elements to their parents
	vector<GridObject*> parents;
	Selector::status_t refMark = RM_REFINE | RM_ANISOTROPIC;
	get_parents_of_marked_closure_elements<Vertex>(parents, refMark);
	get_parents_of_marked_closure_elements<Edge>(parents, refMark);
	get_parents_of_marked_closure_elements<Face>(parents, refMark);
	get_parents_of_marked_closure_elements<Volume>(parents, refMark);

	remove_closure_elements();

//	mark parents of formerly marked closure elements for refinement
	mark(parents.begin(), parents.end(), RM_REFINE);

	HangingNodeRefiner_MultiGrid::perform_refinement();
	create_closure_elements();
}
Пример #17
0
 vector<int> spiralOrder(vector<vector<int> > &matrix) {
     vector<int> vec; if (matrix.empty()) return vec;
     int m = matrix.size(), n = matrix[0].size();
     vector<vector<int> > mark(m, vector<int>(n, 0));
     // right, down, left, up
     const int dir[][2] = {{0, +1}, {+1, 0}, {0, -1}, {-1, 0}};
     int r = 0, c = 0;
     int x = 0;
     for (int i = 0; i < m*n; ++i) {
         int val = matrix[r][c]; vec.push_back(val); mark[r][c] = 1;
         int r2 = r + dir[x][0], c2 = c + dir[x][1];
         if (inbound(r2, c2, m, n) && !mark[r2][c2]) { r = r2; c = c2; }
         else {
             x = x+1; if (x >= 4) x = 0;
             r += dir[x][0]; c += dir[x][1];
         }
     }
     return vec;
 }
Пример #18
0
/**
 * Scans the specified Object +obj+ for references to other Objects, and
 * marks those Objects as reachable. Understands how to read the inside of
 * an Object and find all references located within. For each reference
 * found, it marks the object pointed to as live (which may trigger
 * movement of the object in a copying garbage collector), but does not
 * recursively scan into the referenced object (since such recursion could
 * be arbitrarily deep, depending on the object graph, and this could cause
 * the stack to blow up).
 * /param obj The Object to be scanned for references to other Objects.
 */
void GarbageCollector::scan_object(Object* obj) {
    Object* slot;

#ifdef ENABLE_OBJECT_WATCH
    if(watched_p(obj)) {
        std::cout << "detected " << obj << " during scan_object.\n";
    }
#endif

    // Check and update an inflated header
    if(obj->inflated_header_p()) {
        obj->inflated_header()->reset_object(obj);
    }

    slot = saw_object(obj->klass());
    if(slot) obj->klass(object_memory_, force_as<Class>(slot));

    if(obj->ivars()->reference_p()) {
        slot = saw_object(obj->ivars());
        if(slot) obj->ivars(object_memory_, slot);
    }

    // Handle Tuple directly, because it's so common
    if(Tuple* tup = try_as<Tuple>(obj)) {
        int size = tup->num_fields();

        for(int i = 0; i < size; i++) {
            slot = tup->field[i];
            if(slot->reference_p()) {
                slot = saw_object(slot);
                if(slot) {
                    tup->field[i] = slot;
                    object_memory_->write_barrier(tup, slot);
                }
            }
        }
    } else {
        TypeInfo* ti = object_memory_->type_info[obj->type_id()];

        ObjectMark mark(this);
        ti->mark(obj, mark);
    }
}
Пример #19
0
void cover_goals_extt::operator()()
{
  _iterations=_number_covered=0;

  decision_proceduret::resultt dec_result;

  // We use incremental solving, so need to freeze some variables
  // to prevent them from being eliminated.
  freeze_goal_variables();

  do
  {
    // We want (at least) one of the remaining goals, please!
    _iterations++;

    constraint();

    dec_result=solver();

    switch(dec_result)
    {
    case decision_proceduret::D_UNSATISFIABLE: // DONE
      break;

    case decision_proceduret::D_SATISFIABLE:
      // mark the goals we got
      mark();

      // notify
      assignment();

      if(!all_properties)
        return; // exit on first failure if requested
      break;

    default:
      error() << "decision procedure has failed" << eom;
      return;
    }
  }
  while(dec_result==decision_proceduret::D_SATISFIABLE &&
        number_covered()<size());
}
Пример #20
0
vector<hvec> trace(hvec stpoint)
/* Traces a contour. The start point, because of the way the iteration works,
 * is the leftmost point of the bottom line, so it starts going right.
 */
{hvec dir(1), left(1,1), right(0,-1);
 vector<hvec> contour;
 while (isedge(stpoint) && !ismarked(stpoint))
   {contour.push_back(stpoint);
    mark(stpoint);
    if (isedge(stpoint+dir))
       ;
    else if (isedge(stpoint+dir*left))
       dir*=left;
    else
       dir*=right;
    stpoint+=dir;
    }
 return contour;
 }
Пример #21
0
int main(int argc, char* argv[])
{
	int max_len = -1;
	long max_ind = -1;
	std::vector<bool> mark(num+1,true);
	for ( long i = 1 ; i <= num ; ++ i)
	{ 
		if(!mark[i])
			continue;
		int len = chainLength(i,mark);
		if(len > max_len)
		{
			max_len = len;
			max_ind = i;
		}
	}
	std::cout<<max_len<<' '<<max_ind<<std::endl;
	// std::cout<<divSummation(divs)<<std::endl;
}   
Пример #22
0
int main()
{ 
	int i,j,ct;
	while( scanf("%d %d",&m,&n) ) {
		if( m == 0 || n == 0 ) break;
		for(i=0;i<m;i++)
			scanf("%s", oil[i] );
		ct = 0;
		for(i=0;i<m;i++)
			for(j=0;j<n;j++)
				if( oil[i][j]=='@') {
					ct++;
					mark(i,j);
				}
		printf("%d\n",ct);
	}

	return 0;
}
Пример #23
0
    void rungc(void) {
      if (_alloced_mem > _gc_threshold) {
#ifdef MINIZINC_GC_STATS
        std::cerr << "GC\n\talloced " << (_alloced_mem/1024) << "\n\tfree " << (_free_mem/1024) << "\n\tdiff "
                  << ((_alloced_mem-_free_mem)/1024)
                  << "\n\tthreshold " << (_gc_threshold/1024)
                  << "\n";
#endif
        mark();
        sweep();
        _gc_threshold = static_cast<size_t>(_alloced_mem * 1.5);
#ifdef MINIZINC_GC_STATS
        std::cerr << "done\n\talloced " << (_alloced_mem/1024) << "\n\tfree " << (_free_mem/1024) << "\n\tdiff "
                  << ((_alloced_mem-_free_mem)/1024)
                  << "\n\tthreshold " << (_gc_threshold/1024)
                  << "\n";
#endif
      }
    }
Пример #24
0
// Buffer contains times for mark/space pairs
//
void EngduinoIRClass::sendRaw(unsigned int *buf, int len)
{
    bool sending_temp = sending;

    while (rcvstate == STATE_READING)		// Wait until we're not receiving
        ;
    sending = true;

    for (int i = 0; i < len; i++) {
        if ((i & 1) == 0)
            mark(buf[i]);
        else
            space(buf[i]);
    }

    space(0); // Just in case the list isn't an even length

    sending = sending_temp;
}
Пример #25
0
  address generate_icache_flush() {
    assert( (intptr_t)stubCode % ((sizeof (jint)) * 2) == 0,  "must be doubleword aligned");
    StubCodeMark mark(this, "ICache", "flush_icache_stub");
#   define __ _masm->
    address start = __ pc();

    Label L;
    __ bind(L);
    __ flush( O0, G0 );
    __ deccc( O1 );
    __ br(Assembler::positive, false, Assembler::pn, L);
    __ delayed()->inc( O0, 8 );
    __ retl();
    __ delayed()->mov( O2, O0 ); // handshake with caller to make sure it happened!
#   undef __
  
    stubCode_start = start;
    return start;
  };
Пример #26
0
void
inheritance::visit (t_target_definition &n)
{
  if (done (n))
    return;
  mark (n);

  // this target doesn't inherit anything
  if (!n.derive ())
    return;

  std::string const &name = id (n.derive ()->as<t_inheritance> ().base ());

  // find referenced template
  generic_node_ptr base = lookup (name);

  if (!base)
    {
      errors.add<semantic_error> (n.derive (), "no such template: " + C::quoted (name));
      return;
    }

  // visit inherited templates, first
  base->accept (*this);

  // now copy all information from the base definition
  t_target_definition &b = base->as<t_target_definition> ();

  if (b.cond ())
    {
      assert (!n.cond ());
      n.cond (b.cond ()->clone ());
    }
  if (b.dest ())
    {
      assert (!n.dest ());
      n.dest (b.dest ()->clone ());
    }
  t_target_members &body = n.body ()->as<t_target_members> ();
  foreach (node_ptr const &p, b.body ()->as<t_target_members> ().list)
    body.add (p->clone ());
}
  // void getPsrInfo(VM_Version::CpuidInfo* cpuid_info);
  address generate_getPsrInfo() {
    StubCodeMark mark(this, "VM_Version", "getPsrInfo_stub");
#   define __ _masm->

    address start = __ pc();

    // rbx is callee-save on both unix and windows
    // rcx and rdx are first and second argument registers on windows

    __ pushq(rbx);
    __ movq(r8, rarg0);

    __ xorl(rax, rax);
    __ cpuid();
    __ leaq(r9, Address(r8, in_bytes(VM_Version::std_cpuid0_offset())));
    __ movl(Address(r9, 0),  rax);
    __ movl(Address(r9, 4),  rbx);
    __ movl(Address(r9, 8),  rcx);
    __ movl(Address(r9, 12), rdx);

    __ movl(rax, 1);
    __ cpuid();
    __ leaq(r9, Address(r8, in_bytes(VM_Version::std_cpuid1_offset())));
    __ movl(Address(r9, 0),  rax);
    __ movl(Address(r9, 4),  rbx);
    __ movl(Address(r9, 8),  rcx);
    __ movl(Address(r9, 12), rdx);

    __ movl(rax, 0x80000001);
    __ cpuid();
    __ leaq(r9, Address(r8, in_bytes(VM_Version::ext_cpuid1_offset())));
    __ movl(Address(r9, 0),  rax);
    __ movl(Address(r9, 4),  rbx);
    __ movl(Address(r9, 8),  rcx);
    __ movl(Address(r9, 12), rdx);

    __ popq(rbx);

    __ ret(0);

    return start;
  }
Пример #28
0
/* Make sure we get the calculation in RFC 1624 section 4 correct. */
static void
test_rfc1624(void)
{
    /* "...an IP packet header in which a 16-bit field m = 0x5555..." */
    uint8_t data[32] =
        "\xfe\x8f\xc1\x14\x4b\x6f\x70\x2a\x80\x29\x78\xc0\x58\x81\x77\xaa"
        "\x66\x64\xfc\x96\x63\x97\x64\xee\x12\x53\x1d\xa9\x2d\xa9\x55\x55";

    /* "...the one's complement sum of all other header octets is 0xCD7A." */
    assert(ntohs(csum(data, sizeof data - 2)) == 0xffff - 0xcd7a);

    /* "...the header checksum would be:

          HC = ~(0xCD7A + 0x5555)
             = ~0x22D0
             =  0xDD2F"
    */
    assert(ntohs(csum(data, sizeof data)) == 0xdd2f);

    /* "a 16-bit field m = 0x5555 changes to m' = 0x3285..." */
    data[30] = 0x32;
    data[31] = 0x85;

    /* "The new checksum via recomputation is:

          HC' = ~(0xCD7A + 0x3285)
              = ~0xFFFF
              =  0x0000"
    */
    assert(ntohs(csum(data, sizeof data)) == 0x0000);

    /* "Applying [Eqn. 3] to the example above, we get the correct result:

          HC' = ~(C + (-m) + m')
              = ~(0x22D0 + ~0x5555 + 0x3285)
              = ~0xFFFF
              =  0x0000" */
    assert(recalc_csum16(htons(0xdd2f), htons(0x5555), htons(0x3285))
           == htons(0x0000));

    mark('#');
}
Пример #29
0
  //------------------------------------------------------------------------------------------------------------------------
  // Return point for a Java call if there's an exception thrown in Java code.
  // The exception is caught and transformed into a pending exception stored in
  // JavaThread that can be tested from within the VM.
  //
  address generate_catch_exception() {
    StubCodeMark mark(this, "StubRoutines", "catch_exception");

    address start = __ pc();

    // verify that thread corresponds
//  __ verify_thread();

    // set pending exception
//  __ verify_oop(GR8_exception, "generate_catch_exception");

    const Register pending_exception_addr   = GR2_SCRATCH;
    const Register exception_file_addr      = GR3_SCRATCH;
    const Register exception_line_addr      = GR31_SCRATCH;
    const Register exception_file           = GR30_SCRATCH;
    const Register exception_line           = GR29_SCRATCH;
    const Register call_stub_return_address = GR28_SCRATCH;

    const BranchRegister call_stub_return_address_br = BR6_SCRATCH;

    __ add(pending_exception_addr, thread_(pending_exception));
    __ mova(exception_file, (address)__FILE__);
    __ add(exception_file_addr, thread_(exception_file));
    __ mova(exception_line, (address)__LINE__);

    __ st8(pending_exception_addr, GR8_exception);
    __ st8(exception_file_addr, exception_file);
    __ add(exception_line_addr, thread_(exception_line));

    __ st8(exception_line_addr, exception_line);

    // complete return to VM
    assert(StubRoutines::_call_stub_return_address != NULL, "must have been generated before");

    __ mova(call_stub_return_address, StubRoutines::_call_stub_return_address);
    __ mov(call_stub_return_address_br, call_stub_return_address);
    __ br(call_stub_return_address_br);

    __ flush_bundle();

    return start;
  }
Пример #30
0
  /**
   * Scans the specified Object +obj+ for references to other Objects, and
   * marks those Objects as reachable. Understands how to read the inside of
   * an Object and find all references located within. For each reference
   * found, it marks the object pointed to as live (which may trigger
   * movement of the object in a copying garbage collector), but does not
   * recursively scan into the referenced object (since such recursion could
   * be arbitrarily deep, depending on the object graph, and this could cause
   * the stack to blow up).
   * /param obj The Object to be scanned for references to other Objects.
   */
  void GarbageCollector::scan_object(Object* obj) {
#ifdef ENABLE_OBJECT_WATCH
    if(watched_p(obj)) {
      std::cout << "detected " << obj << " during scan_object.\n";
    }
#endif
    // We set scanned here before we finish scanning the object.
    // This is done so we don't have a race condition while we're
    // scanning the object and another thread updates a field during
    // the phase where the object is partially scanned.
    scanned_object(obj);

    if(Object* klass = saw_object(obj->klass())) {
      obj->klass(object_memory_, force_as<Class>(klass));
    }

    if(obj->ivars()->reference_p()) {
      if(Object* ivars = saw_object(obj->ivars())) {
        obj->ivars(object_memory_, ivars);
      }
    }

    // Handle Tuple directly, because it's so common
    if(Tuple* tup = try_as<Tuple>(obj)) {
      native_int size = tup->num_fields();

      for(native_int i = 0; i < size; i++) {
        Object* slot = tup->field[i];
        if(slot->reference_p()) {
          if(Object* moved = saw_object(slot)) {
            tup->field[i] = moved;
            object_memory_->write_barrier(tup, moved);
          }
        }
      }
    } else {
      TypeInfo* ti = object_memory_->type_info[obj->type_id()];

      ObjectMark mark(this);
      ti->mark(obj, mark);
    }
  }