Пример #1
0
void *pnvmalloc(size_t size, struct rqst_struct *rqst) {

    int flgPersist = 0;
	struct timeval start, end;
	long total_time; 	

	if(!rqst) {
		perror("failed pnvmalloc \n");
		return NULL;
	}

#ifdef USE_NVMALLOC

    gettimeofday(&start, NULL);	

	addr = (char *)pnv_malloc(size, rqst);

    gettimeofday(&end, NULL);

#ifdef DEBUG
	total_time =  simulation_time( start, end );

	fprintf(stderr, "pnv_malloc time %ld \n", total_time);
#endif

//#endif

#else

	addr = (char *)malloc(size);

#ifdef USE_STATS
	
	gettimeofday(&start, NULL);	

	addr = (char *)malloc(size);

	 gettimeofday(&end, NULL);

	total_time =  simulation_time( start, end );

	fprintf(stderr, "malloc time %ld \n", total_time);

#endif

#endif


#ifdef USE_STATS
    if(!addr){
        fprintf(stderr,"NVmalloc allocation failed \n");
        return NULL;
    }else{
		hash_insert((unsigned long)addr, size);
    }
#endif
    return addr;
}
int sc_main( int argc, char* argv[])
{
   
   // create constants
   const double TIME_RESOLUTION = 1.0;
   const double TOTAL_SIMULATION_TIME = 500.0;
   const double CLOCK_PERIOD = 2.0;

   // set time parameters
   sc_set_time_resolution( TIME_RESOLUTION , SC_NS );
   sc_time simulation_time(TOTAL_SIMULATION_TIME,SC_NS);
   sc_time clock_time(CLOCK_PERIOD,SC_NS);

   // generate clock 
   sc_clock clock("clock",clock_time);

   // create connecting signals from stimulus-->dut
   sc_signal< XY_DATA_TYPE > x_stim,y_stim;
   sc_signal< XY_DATA_TYPE> x_out,y_out;
   sc_signal< Z_DATA_TYPE > z_stim;
   sc_signal< Z_DATA_TYPE > z_out;
   sc_signal< Z_DATA_TYPE > theta_stim;
   sc_signal< RESET_TYPE> reset_stim;

   // create stimulus signal object
   Stimulus stim("stimulus", TOTAL_SIMULATION_TIME);
   stim.reset(reset_stim);
   stim.clock(clock);
   stim.x_in(x_out);
   stim.y_in(y_out);
   stim.z_in(z_out);
   stim.x_out(x_stim);
   stim.y_out(y_stim);
   stim.z_out(z_stim);

   // create cordic_stage object ( DUT )
   CordicStage< XY_DATA_TYPE, Z_DATA_TYPE, RESET_TYPE> cs("cordic_stage", stim.SHIFT);
   cs.xin(x_stim);
   cs.yin(y_stim);
   cs.zin(z_stim);
   cs.reset(reset_stim);
   cs.xout(x_out);
   cs.yout(y_out);
   cs.zout(z_out);
   cs.clock(clock);

   // begin simulation
   sc_start( simulation_time );

   return 0;
}