Example #1
0
void init_structures(memory_c *main_memory) // please modify init_structures function argument  /** NEW-LAB2 */ 
{
  init_op_pool(); 
  init_op_latency();
  init_reg_file();
  /* please initialize other data stucturs */ 
  /* you must complete the function */
  init_latches();
  cache_size = KNOB(KNOB_DCACHE_SIZE)->getValue();
  block_size = KNOB(KNOB_BLOCK_SIZE)->getValue();
  assoc = KNOB(KNOB_DCACHE_WAY)->getValue();
  dcache_latency = KNOB(KNOB_DCACHE_LATENCY)->getValue();
  mshr_size = KNOB(KNOB_MSHR_SIZE)->getValue();
  use_bpred = KNOB(KNOB_USE_BPRED)->getValue();
  type_bpred = (bpred_type) KNOB(KNOB_BPRED_TYPE)->getValue();
  hist_len = KNOB(KNOB_BPRED_HIST_LEN)->getValue();
  vmem_enabled = KNOB(KNOB_ENABLE_VMEM)->getValue();
  tlb_size = KNOB(KNOB_TLB_ENTRIES)->getValue();
  vmem_page_size = KNOB(KNOB_VMEM_PAGE_SIZE)->getValue();
  thread_count = KNOB(KNOB_RUN_THREAD_NUM)->getValue();

  for(int i = 0 ; i < HW_MAX_THREAD ; i++)
	  end_of_stream[i] = false;

  data_cache = (Cache *) malloc(sizeof(Cache));
  cache_init(data_cache,cache_size,block_size,assoc,"dcache");
  main_memory->init_mem();

  if(use_bpred)
	  branchpred = bpred_new(type_bpred,hist_len);
  else
	  branchpred = NULL;

  if(vmem_enabled)
	  dtlb = tlb_new(tlb_size);
  else
	  dtlb = NULL;
}
void simulator_main(int argc, char** argv) 
{
  init_knobs(argc, argv);

  // trace driven simulation 
  read_trace_file();

  /** NEW-LAB2 */ /* just note: passing main memory pointers is hack to mix up c++ objects and c-style code */  /* Not recommended at all */ 
  memory_c *main_memory = new memory_c();  // /** NEW-LAB2 */ 


  init_structures(main_memory);  // please modify run_a_cycle function argument  /** NEW-LAB2 */ 
  
  /*LAB 3*/
  if(KNOB(KNOB_USE_BPRED)->getValue())
  {
	  use_bpred=true;
	  bpred_type type=(bpred_type) KNOB(KNOB_BPRED_TYPE)->getValue();
	  unsigned int bhr_len;
	  if(type == BPRED_TAKEN || type == BPRED_NOTTAKEN || type == BPRED_BIMODAL)
		  bhr_len=0;
	  else if(type == BPRED_GSHARE)
		  bhr_len=KNOB(KNOB_BPRED_HIST_LEN)->getValue();
	  branchpred=bpred_new(type,bhr_len);
  }
  /*LAB 3*/
  if(KNOB(KNOB_ENABLE_VMEM)->getValue())
  {
	  vmem_enabled=true;
	  dtlb = tlb_new(KNOB(KNOB_TLB_ENTRIES)->getValue());
	  vmem_page_size=KNOB(KNOB_VMEM_PAGE_SIZE)->getValue();
  }
  run_a_cycle(main_memory); // please modify run_a_cycle function argument  /** NEW-LAB2 */ 


}