Пример #1
0
int main(int argc, char *argv[])
{
    srand(time(NULL));

    if (argc > 2) {
        logfile = fopen(argv[2], "w");
    }

    {
        printf("===== L1_1 64KB / 8B Direct =====\n");
        Memory ram(100);
        Cache L1("L1", 64 * 1024, 8, 1, 1, ram);
        CPU cpu(L1);
        cpu.exec(argv[1]);
        cpu.summary();
    }
    {
        printf("===== L1_2 32KB / 32B / 4 ways LRU =====\n");
        Memory ram(100);
        Cache L1("L1", 32 * 1024, 32, 4, 1, ram, true);
        CPU cpu(L1);
        cpu.exec(argv[1]);
        cpu.summary();
    }
    {
        printf("===== L1_3 8KB / 64B / Full Random =====\n");
        Memory ram(100);
        Cache L1("L1", 8 * 1024, 64, (8 * 1024 / 64), 1, ram);
        CPU cpu(L1);
        cpu.exec(argv[1]);
        cpu.summary();
    }
    {
        printf("===== L1 + L2 =====\n");
        n_instr = 0;
        Memory ram(100);
        Cache L2("L2", 2 * 1024 * 1024, 128, 8, 10, ram, true);
        Cache L1("L1", 32 * 1024, 32, 4, 1, L2, true);
        CPU cpu(L1);
        cpu.exec(argv[1]);
        cpu.summary();
    }
    {
        printf("===== L1 + Victim + L2 =====\n");
        n_instr = 0;
        Memory ram(100);
        Cache L2("L2", 2 * 1024 * 1024, 128, 8, 10, ram);
        VictimCache victim("Victim", 1 * 1024, 32, L2, true);
        Cache L1("L1", 32 * 1024, 32, 4, 1, victim);
        CPU cpu(L1);
        cpu.exec(argv[1]);
        cpu.summary();
    }

    if (logfile != stdin) {
        fclose(logfile);
    }
    return 0;
}
//Refer to apps_sfdl_gen/ram_hybrid_micro_cons.h for constants to use when generating input.
void ram_hybrid_microVerifierInpGenHw::create_input(mpq_t* input_q, int num_inputs)
{
#if IS_REDUCER == 0
    //Default implementation is provided by compiler
    compiler_implementation.create_input(input_q, num_inputs);
#endif

    // setup the Merkle root when the hybrid choose Merkle-tree based
    // solution
    if (num_inputs > 1) {
        ConfigurableBlockStore bs;
        RAMImpl ram(&bs);
        HashType* hash = ram.getRootHash();

        int i = 0;
        for (HashType::HashVec::const_iterator itr = hash->GetFieldElts().begin();
                itr != hash->GetFieldElts().end(); ++itr) {
            mpz_set(mpq_numref(input_q[i]), (*itr).get_mpz_t());
            mpq_canonicalize(input_q[i]);
            i++;
        }
    }

    // set the address for RAM operation to be 0
    mpq_set_ui(input_q[num_inputs-1], 0, 1);

    // states that should be persisted and may not be generated everytime should be created here.
    if (generate_states) {
    }
}
Пример #3
0
int main(int argc, char **argv) {
  long l=argc > 1 ? strtol(argv[1],NULL,0) : 10000;
  prog_t progke[]={{0,HALT,0,0},{2,ADD,1,3},{3,SUB,1,2},{1,CJUMP,2,4},{0,HALT,0,0}};
  int mem[]={0,1,l,0};
  ram(progke,mem,1);
/*  printf("%i\n",mem[3]); */
  return 0;
}
void plCreatableListHelper::Read( hsStream* s, hsResMgr* mgr )
{
    IClearItems();

    s->LogSubStreamStart("CreatableListHelper");

    s->LogReadLE( &fFlags, "Flags" );

    fFlags &= ~kWritten;

    uint32_t bufSz;
    s->LogReadLE( &bufSz, "BufSz" );
    std::string buf;
    buf.resize( bufSz );

    if ( fFlags&kCompressed )
    {
        uint32_t zBufSz;
        s->LogReadLE( &zBufSz, "Compressed BufSz" );
        std::string zBuf;
        zBuf.resize( zBufSz );
        s->LogSubStreamPushDesc("Compressed Data");
        s->Read( zBufSz, (void*)zBuf.data() );
        plZlibCompress compressor;
        uint32_t tmp;
        hsBool ans = compressor.Uncompress( (uint8_t*)buf.data(), &tmp, (uint8_t*)zBuf.data(), zBufSz );
        hsAssert( ans!=0, "plCreatableListHelper: Failed to uncompress buffer." );
        hsAssert( tmp==bufSz, "compression size mismatch" );
        fFlags&=~kCompressed;
        hsLogEntry( plNetApp::StaticDebugMsg( "plCreatableListHelper: uncompressed from %lu to %lu", zBufSz, bufSz ) );
    }
    else
    {
        s->LogSubStreamPushDesc("Uncompressed Data");
        s->Read( bufSz, (void*)buf.data() );
    }

    hsReadOnlyStream ram( bufSz, (void*)buf.data() );

    uint16_t nItems;
    ram.ReadLE( &nItems );
    for ( int i=0; i<nItems; i++ )
    {
        uint16_t id;
        uint16_t classIdx;
        ram.ReadLE( &id );
        ram.ReadLE( &classIdx );
        plCreatable * object = plFactory::Create( classIdx );
        hsAssert( object,"plCreatableListHelper: Failed to create plCreatable object (invalid class index?)" );
        if ( object )
        {
            fManagedItems.push_back( object );
            object->Read( &ram, mgr );
            fItems[id] = object;
        }
    }
}
 // Serilize Constructor
 MessageResourcesQueryACK()
     : Message( PROTOCOL_VERSION , 112 , 0 )
 {
     cpu( "not clear" );
     cpufrequency( "not clear" );
     ram( "not clear" );
     gpu( "not clear" );
     video_ram( "not clear" );
 }
Пример #6
0
		void execute( const call &, int arg_addr8)
		{
			push( program_counter);
			set_pc( arg_addr8 | ((address_t( ram( sx_ram::STATUS)) & 0x00e0) << 4));

			if (stack.size() > sx_stack_size)
			{
				throw stack_overflow_exception( stack.back());
			}
		}
Пример #7
0
		void do_rtcc()
		{
			if (!(++cycle_counter & rtcc_prescale_mask))
			{
				if (++ram( sx_ram::RTCC) == 0 && enable_rtcc_interrupt)
				{
					do_interrupt();
				}
			}
		}
Пример #8
0
		void do_interrupt()
		{
			if (!in_interrupt)
			{
				in_interrupt = true;
				interrupt_state.pc = program_counter;
				interrupt_state.w = w;
				interrupt_state.fsr = ram( sx_ram::FSR);
				interrupt_state.status = ram( sx_ram::STATUS);
				ram( sx_ram::STATUS) &= 0x1f; // clear page bits.
				set_pc(0);
				set_nop_delay( 2);
			}
			else
			{
				if (throw_on_rtcc_overflow)
				{
					throw rtcc_overflow_exception(get_pc());
				}
			}
		}
Пример #9
0
void RingoAAM::parse(const char *mode) {
   if (strcasecmp(mode, "CLEAR") == 0){
      _reaction.clearAAM();
      return;
   }
   ReactionAutomapper ram(_reaction);
   if (strcasecmp(mode, "DISCARD") == 0){
      ram.automap(ReactionAutomapper::AAM_REGEN_DISCARD);
   } else if (strcasecmp(mode, "ALTER") == 0){
      ram.automap(ReactionAutomapper::AAM_REGEN_ALTER);
   } else if (strcasecmp(mode, "KEEP") == 0){
      ram.automap(ReactionAutomapper::AAM_REGEN_KEEP);
   }
   else
      throw Error("unknown mode: %s", mode);
}
Пример #10
0
void RingoIndex::prepare (Scanner &rxnfile, Output &output, OsLock *lock_for_exclusive_access)
{
   QS_DEF(Reaction, reaction);
      
   ReactionAutoLoader rrd(rxnfile);
   _context->setLoaderSettings(rrd);
   rrd.loadReaction(reaction);

   // Skip all SGroups
   for (int mol_idx = reaction.begin(); mol_idx != reaction.end(); mol_idx = reaction.next(mol_idx)) 
      reaction.getBaseMolecule(mol_idx).clearSGroups();

   Reaction::checkForConsistency(reaction);

   ReactionAutomapper ram(reaction);
   ram.correctReactingCenters(true);

   reaction.aromatize(AromaticityOptions::BASIC);

   _hash = RingoExact::calculateHash(reaction);
   {
      ArrayOutput out(_hash_str);
      out.printf("%02X", _hash);
      _hash_str.push(0);
   }

   if (!skip_calculate_fp)
   {
      ReactionFingerprintBuilder builder(reaction, _context->fp_parameters);

      builder.process();
      _fp.copy(builder.get(), _context->fp_parameters.fingerprintSizeExtOrdSim() * 2);
   }

   ArrayOutput output_crf(_crf);
   {
      // CrfSaver modifies _context->cmf_dict and 
      // requires exclusive access for this
      OsLockerNullable locker(lock_for_exclusive_access);
      CrfSaver saver(_context->cmf_dict, output_crf);
      saver.saveReaction(reaction);
   }

   output.writeArray(_crf);
}
Пример #11
0
Файл: ai.c Проект: aichao/sst
static void movebaddy(int comx, int comy, int loccom, int ienm) {
	int motion, mdist, nsteps, mx, my, nextx, nexty, lookx, looky, ll;
	int irun = 0;
	int krawlx, krawly;
	int success;
	int attempts;
	/* This should probably be just comhere + ishere */
	int nbaddys = skill > 3 ?
				  (int)((comhere*2 + ishere*2+klhere*1.23+irhere*1.5)/2.0):
				  (comhere + ishere);
	double dist1, forces;

	dist1 = kdist[loccom];
	mdist = dist1 + 0.5; /* Nearest integer distance */

	/* If SC, check with spy to see if should hi-tail it */
	if (ienm==IHS &&
		(kpower[loccom] <= 500.0 || (condit==IHDOCKED && damage[DPHOTON]==0))) {
		irun = 1;
		motion = -10;
	}
	else {
		/* decide whether to advance, retreat, or hold position */
/* Algorithm:
   * Enterprise has "force" based on condition of phaser and photon torpedoes.
     If both are operating full strength, force is 1000. If both are damaged,
	 force is -1000. Having shields down subtracts an additional 1000.

   * Enemy has forces equal to the energy of the attacker plus
     100*(K+R) + 500*(C+S) - 400 for novice through good levels OR
	 346*K + 400*R + 500*(C+S) - 400 for expert and emeritus.

	 Attacker Initial energy levels (nominal):
	          Klingon   Romulan   Commander   Super-Commander
	 Novice    400        700        1200        
	 Fair      425        750        1250
	 Good      450        800        1300        1750
	 Expert    475        850        1350        1875
	 Emeritus  500        900        1400        2000
     VARIANCE   75        200         200         200

	 Enemy vessels only move prior to their attack. In Novice - Good games
	 only commanders move. In Expert games, all enemy vessels move if there
	 is a commander present. In Emeritus games all enemy vessels move.

  *  If Enterprise is not docked, an agressive action is taken if enemy
     forces are 1000 greater than Enterprise.

	 Agressive action on average cuts the distance between the ship and
	 the enemy to 1/4 the original.

  *  At lower energy advantage, movement units are proportional to the
     advantage with a 650 advantage being to hold ground, 800 to move forward
	 1, 950 for two, 150 for back 4, etc. Variance of 100.

	 If docked, is reduced by roughly 1.75*skill, generally forcing a
	 retreat, especially at high skill levels.

  *  Motion is limited to skill level, except for SC hi-tailing it out.
  */

		forces = kpower[loccom]+100.0*nenhere+400*(nbaddys-1);
		if (shldup==0) forces += 1000; /* Good for enemy if shield is down! */
		if (damage[DPHASER] == 0.0 || damage[DPHOTON] == 0.0) {
			if (damage[DPHASER] != 0) /* phasers damaged */
				forces += 300.0;
			else
				forces -= 0.2*(energy - 2500.0);
			if (damage[DPHOTON] != 0) /* photon torpedoes damaged */
				forces += 300.0;
			else
				forces -= 50.0*torps;
		}
		else {
			/* phasers and photon tubes both out! */
			forces += 1000.0;
		}
		motion = 0;
		if (forces <= 1000.0 && condit != IHDOCKED) /* Typical situation */
			motion = ((forces+200.0*Rand())/150.0) - 5.0;
		else {
			if (forces > 1000.0) /* Very strong -- move in for kill */
				motion = (1.0-square(Rand()))*dist1 + 1.0;
			if (condit==IHDOCKED) /* protected by base -- back off ! */
				motion -= skill*(2.0-square(Rand()));
		}
#ifdef DEBUG
		if (idebug) {
			proutn("MOTION = ");
			cramf(motion, 1, 2);
            proutn("  FORCES = ");
			cramf(forces, 1, 2);
			skip(1);
		}
#endif
		/* don't move if no motion */
		if (motion==0) return;
		/* Limit motion according to skill */
		if (abs(motion) > skill) motion = (motion < 0) ? -skill : skill;
	}
	/* calcuate preferred number of steps */
	nsteps = motion < 0 ? -motion : motion;
	if (motion > 0 && nsteps > mdist) nsteps = mdist; /* don't overshoot */
	if (nsteps > 10) nsteps = 10; /* This shouldn't be necessary */
	if (nsteps < 1) nsteps = 1; /* This shouldn't be necessary */
#ifdef DEBUG
	if (idebug) {
		proutn("NSTEPS = ");
		crami(nsteps, 1);
		skip(1);
	}
#endif
	/* Compute preferred values of delta X and Y */
	mx = sectx - comx;
	my = secty - comy;
	if (2.0 * abs(mx) < abs(my)) mx = 0;
	if (2.0 * abs(my) < abs(sectx-comx)) my = 0;
	if (mx != 0) mx = mx*motion < 0 ? -1 : 1;
	if (my != 0) my = my*motion < 0 ? -1 : 1;
	nextx = comx;
	nexty = comy;
	quad[comx][comy] = IHDOT;
	/* main move loop */
	for (ll = 1; ll <= nsteps; ll++) {
#ifdef DEBUG
		if (idebug) {
			crami(ll,2);
			skip(1);
		}
#endif
		/* Check if preferred position available */
		lookx = nextx + mx;
		looky = nexty + my;
		krawlx = mx < 0 ? 1 : -1;
		krawly = my < 0 ? 1 : -1;
		success = 0;
		attempts = 0; /* Settle mysterious hang problem */
		while (attempts++ < 20 && !success) {
			if (lookx < 1 || lookx > 10) {
				if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
					return;
				if (krawlx == mx || my == 0) break;
				lookx = nextx + krawlx;
				krawlx = -krawlx;
			}
			else if (looky < 1 || looky > 10) {
				if (motion < 0 && tryexit(lookx, looky, ienm, loccom, irun))
					return;
				if (krawly == my || mx == 0) break;
				looky = nexty + krawly;
				krawly = -krawly;
			}
			else if (quad[lookx][looky] != IHDOT) {
				/* See if we should ram ship */
				if (quad[lookx][looky] == ship &&
					(ienm == IHC || ienm == IHS)) {
					ram(1, ienm, comx, comy);
					return;
				}
				if (krawlx != mx && my != 0) {
					lookx = nextx + krawlx;
					krawlx = -krawlx;
				}
				else if (krawly != my && mx != 0) {
					looky = nexty + krawly;
					krawly = -krawly;
				}
				else break; /* we have failed */
			}
			else success = 1;
		}
		if (success) {
			nextx = lookx;
			nexty = looky;
#ifdef DEBUG
			if (idebug) {
				cramlc(0, nextx, nexty);
				skip(1);
			}
#endif
		}
		else break; /* done early */
	}
	/* Put commander in place within same quadrant */
	quad[nextx][nexty] = ienm;
	if (nextx != comx || nexty != comy) {
		/* it moved */
		kx[loccom] = nextx;
		ky[loccom] = nexty;
		kdist[loccom] = kavgd[loccom] =
					sqrt(square(sectx-nextx)+square(secty-nexty));
		if (damage[DSRSENS] == 0 || condit == IHDOCKED) {
			proutn("***");
			cramen(ienm);
			if (kdist[loccom] < dist1) proutn(" advances to");
			else proutn(" retreats to");
			cramlc(2, nextx, nexty);
			skip(1);
		}
	}
}
Пример #12
0
double
move(int ramflag, int course, double p_time, double speed)
{
	double			angle;
	double			x, y, dx, dy;
	int		ix, iy;
	double			bigger;
	int			n;
	int		i;
	double			dist;
	double			sectsize;
	double			xn;
	double			evtime;

	ix = iy = 0;
#ifdef xTRACE
	if (Trace)
		printf("move: ramflag %d course %d time %.2f speed %.2f\n",
			ramflag, course, p_time, speed);
#endif
	sectsize = NSECTS;
	/* initialize delta factors for move */
	angle = course * 0.0174532925;
	if (damaged(SINS))
		angle += Param.navigcrud[1] * (franf() - 0.5);
	else
		if (Ship.sinsbad)
			angle += Param.navigcrud[0] * (franf() - 0.5);
	dx = -cos(angle);
	dy = sin(angle);
	bigger = fabs(dx);
	dist = fabs(dy);
	if (dist > bigger)
		bigger = dist;
	dx /= bigger;
	dy /= bigger;

	/* check for long range tractor beams */
	/****  TEMPORARY CODE == DEBUGGING  ****/
	evtime = Now.eventptr[E_LRTB]->date - Now.date;
#ifdef xTRACE
	if (Trace)
		printf("E.ep = %p, ->evcode = %d, ->date = %.2f, evtime = %.2f\n",
			(void *)Now.eventptr[E_LRTB],
			Now.eventptr[E_LRTB]->evcode,
			Now.eventptr[E_LRTB]->date, evtime);
#endif
	if (p_time > evtime && Etc.nkling < 3) {
		/* then we got a LRTB */
		evtime += 0.005;
		p_time = evtime;
	} else
		evtime = -1.0e50;
	dist = p_time * speed;

	/* move within quadrant */
	Sect[Ship.sectx][Ship.secty] = EMPTY;
	x = Ship.sectx + 0.5;
	y = Ship.secty + 0.5;
	xn = NSECTS * dist * bigger;
	n = xn + 0.5;
#ifdef xTRACE
	if (Trace)
		printf("dx = %.2f, dy = %.2f, xn = %.2f, n = %d\n", dx, dy, xn, n);
#endif
	Move.free = 0;

	for (i = 0; i < n; i++) {
		ix = (x += dx);
		iy = (y += dy);
#ifdef xTRACE
		if (Trace)
			printf("ix = %d, x = %.2f, iy = %d, y = %.2f\n", ix, x, iy, y);
#endif
		if (x < 0.0 || y < 0.0 || x >= sectsize || y >= sectsize) {
			/* enter new quadrant */
			dx = Ship.quadx * NSECTS + Ship.sectx + dx * xn;
			dy = Ship.quady * NSECTS + Ship.secty + dy * xn;
			if (dx < 0.0)
				ix = -1;
			else
				ix = dx + 0.5;
			if (dy < 0.0)
				iy = -1;
			else
				iy = dy + 0.5;
#ifdef xTRACE
			if (Trace)
				printf("New quad: ix = %d, iy = %d\n", ix, iy);
#endif
			Ship.sectx = x;
			Ship.secty = y;
			compkldist(0);
			Move.newquad = 2;
			attack(0);
			checkcond();
			Ship.quadx = ix / NSECTS;
			Ship.quady = iy / NSECTS;
			Ship.sectx = ix % NSECTS;
			Ship.secty = iy % NSECTS;
			if (ix < 0 || Ship.quadx >= NQUADS || iy < 0 ||
			    Ship.quady >= NQUADS) {
				if (!damaged(COMPUTER)) {
					dumpme(0);
				} else
					lose(L_NEGENB);
			}
			initquad(0);
			n = 0;
			break;
		}
		if (Sect[ix][iy] != EMPTY) {
			/* we just hit something */
			if (!damaged(COMPUTER) && ramflag <= 0) {
				ix = x - dx;
				iy = y - dy;
				printf("Computer reports navigation error; %s stopped at %d,%d\n",
					Ship.shipname, ix, iy);
				Ship.energy -= Param.stopengy * speed;
				break;
			}
			/* test for a black hole */
			if (Sect[ix][iy] == HOLE) {
				/* get dumped elsewhere in the galaxy */
				dumpme(1);
				initquad(0);
				n = 0;
				break;
			}
			ram(ix, iy);
			break;
		}
	}
	if (n > 0) {
		dx = Ship.sectx - ix;
		dy = Ship.secty - iy;
		dist = sqrt(dx * dx + dy * dy) / NSECTS;
		p_time = dist / speed;
		if (evtime > p_time)
			p_time = evtime;		/* spring the LRTB trap */
		Ship.sectx = ix;
		Ship.secty = iy;
	}
	Sect[Ship.sectx][Ship.secty] = Ship.ship;
	compkldist(0);
	return (p_time);
}
Пример #13
0
		void execute( const jmp &, int addr9_)
		{
			set_pc( addr9_ | ((address_t( ram( sx_ram::STATUS)) & 0x00e0) << 4));
			set_nop_delay( 2);
		}