⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sim-bpred.c

📁 RISC处理器仿真分析程序。可以用于研究通用RISC处理器的指令和架构设计。在linux下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
  stat_reg_counter(sdb, "sim_num_branches",                   "total number of branches executed",                   &sim_num_branches, /* initial value */0, /* format */NULL);  stat_reg_formula(sdb, "sim_IPB",                   "instruction per branch",                   "sim_num_insn / sim_num_branches", /* format */NULL);  /* register predictor stats */  if (pred)    bpred_reg_stats(pred, sdb);}/* initialize the simulator */voidsim_init(void){  SS_INST_TYPE inst;  sim_num_insn = 0;  sim_num_refs = 0;  regs_PC = ld_prog_entry;  /* decode all instructions */  {    SS_ADDR_TYPE addr;    if (OP_MAX > 255)      fatal("cannot perform fast decoding, too many opcodes");    debug("sim: decoding text segment...");    for (addr=ld_text_base;	 addr < (ld_text_base+ld_text_size);	 addr += SS_INST_SIZE)      {	inst = __UNCHK_MEM_ACCESS(SS_INST_TYPE, addr);	inst.a = SWAP_WORD(inst.a);	inst.b = SWAP_WORD(inst.b);	inst.a = (inst.a & ~0xff) | (unsigned int)SS_OP_ENUM(SS_OPCODE(inst));	__UNCHK_MEM_ACCESS(SS_INST_TYPE, addr) = inst;      }  }  /* initialize the DLite debugger */  dlite_init(dlite_reg_obj, dlite_mem_obj, dlite_mstate_obj);}/* print simulator-specific configuration information */voidsim_aux_config(FILE *stream)		/* output stream */{  /* nothing currently */}/* dump simulator-specific auxiliary simulator statistics */voidsim_aux_stats(FILE *stream)		/* output stream */{  /* nada */}/* un-initialize simulator-specific state */voidsim_uninit(void){  /* nada */}/* * configure the execution engine *//* * precise architected register accessors *//* next program counter */#define SET_NPC(EXPR)		(next_PC = (EXPR))/* target program counter */#undef  SET_TPC#define SET_TPC(EXPR)		(target_PC = (EXPR))/* current program counter */#define CPC			(regs_PC)/* general purpose registers */#define GPR(N)			(regs_R[N])#define SET_GPR(N,EXPR)		(regs_R[N] = (EXPR))/* floating point registers, L->word, F->single-prec, D->double-prec */#define FPR_L(N)		(regs_F.l[(N)])#define SET_FPR_L(N,EXPR)	(regs_F.l[(N)] = (EXPR))#define FPR_F(N)		(regs_F.f[(N)])#define SET_FPR_F(N,EXPR)	(regs_F.f[(N)] = (EXPR))#define FPR_D(N)		(regs_F.d[(N) >> 1])#define SET_FPR_D(N,EXPR)	(regs_F.d[(N) >> 1] = (EXPR))/* miscellaneous register accessors */#define SET_HI(EXPR)		(regs_HI = (EXPR))#define HI			(regs_HI)#define SET_LO(EXPR)		(regs_LO = (EXPR))#define LO			(regs_LO)#define FCC			(regs_FCC)#define SET_FCC(EXPR)		(regs_FCC = (EXPR))/* precise architected memory state help functions */#define __READ_WORD(DST_T, SRC_T, SRC)					\  ((unsigned int)((DST_T)(SRC_T)MEM_READ_WORD(addr = (SRC))))#define __READ_HALF(DST_T, SRC_T, SRC)					\  ((unsigned int)((DST_T)(SRC_T)MEM_READ_HALF(addr = (SRC))))#define __READ_BYTE(DST_T, SRC_T, SRC)					\  ((unsigned int)((DST_T)(SRC_T)MEM_READ_BYTE(addr = (SRC))))/* precise architected memory state accessor macros */#define READ_WORD(SRC)							\  __READ_WORD(unsigned int, unsigned int, (SRC))#define READ_UNSIGNED_HALF(SRC)						\  __READ_HALF(unsigned int, unsigned short, (SRC))#define READ_SIGNED_HALF(SRC)						\  __READ_HALF(signed int, signed short, (SRC))#define READ_UNSIGNED_BYTE(SRC)						\  __READ_BYTE(unsigned int, unsigned char, (SRC))#define READ_SIGNED_BYTE(SRC)						\  __READ_BYTE(signed int, signed char, (SRC))#define WRITE_WORD(SRC, DST)						\  (MEM_WRITE_WORD(addr = (DST), (unsigned int)(SRC)))#define WRITE_HALF(SRC, DST)						\  (MEM_WRITE_HALF(addr = (DST), (unsigned short)(unsigned int)(SRC)))#define WRITE_BYTE(SRC, DST)						\  (MEM_WRITE_BYTE(addr = (DST), (unsigned char)(unsigned int)(SRC)))/* system call handler macro */#define SYSCALL(INST)		(ss_syscall(mem_access, INST))/* instantiate the helper functions in the '.def' file */#define DEFINST(OP,MSK,NAME,OPFORM,RES,CLASS,O1,O2,I1,I2,I3,EXPR)#define DEFLINK(OP,MSK,NAME,MASK,SHIFT)#define CONNECT(OP)#define IMPL#include "ss.def"#undef DEFINST#undef DEFLINK#undef CONNECT#undef IMPL/* start simulation, program loaded, processor precise state initialized */voidsim_main(void){  SS_INST_TYPE inst;  register SS_ADDR_TYPE next_PC, target_PC;  register SS_ADDR_TYPE addr;  enum ss_opcode op;  register int is_write;  int stack_idx;  fprintf(stderr, "sim: ** starting functional simulation **\n");  /* set up initial default next PC */  next_PC = regs_PC + SS_INST_SIZE;  /* check for DLite debugger entry condition */  if (dlite_check_break(regs_PC, /* no access */0, /* addr */0, 0, 0))    dlite_main(regs_PC - SS_INST_SIZE, regs_PC, sim_num_insn);  while (TRUE)    {      /* maintain $r0 semantics */      regs_R[0] = 0;      /* keep an instruction count */      sim_num_insn++;      /* get the next instruction to execute */      inst = __UNCHK_MEM_ACCESS(SS_INST_TYPE, regs_PC);      /* set default reference address and access mode */      addr = 0; is_write = FALSE;      /* decode the instruction */      op = SS_OPCODE(inst);      switch (op)	{#define DEFINST(OP,MSK,NAME,OPFORM,RES,FLAGS,O1,O2,I1,I2,I3,EXPR)	\	case OP:                                                        \          EXPR;                                                         \          break;#define DEFLINK(OP,MSK,NAME,MASK,SHIFT)                                 \        case OP:                                                        \          panic("attempted to execute a linking opcode");#define CONNECT(OP)#include "ss.def"#undef DEFINST#undef DEFLINK#undef CONNECT	default:	  panic("bogus opcode");      }      if (SS_OP_FLAGS(op) & F_MEM)	{	  sim_num_refs++;	  if (SS_OP_FLAGS(op) & F_STORE)	    is_write = TRUE;	}      if (SS_OP_FLAGS(op) & F_CTRL)	{	  SS_ADDR_TYPE pred_PC;	  struct bpred_update update_rec;	  sim_num_branches++;	  if (pred)	    {	      /* get the next predicted fetch address */	      pred_PC = bpred_lookup(pred,				     /* branch addr */regs_PC,				     /* target */target_PC,				     /* opcode */op,				     /* jump through R31? */(RS) == 31,				     /* stash an update ptr */&update_rec,				     /* stash return stack ptr */&stack_idx);	      /* valid address returned from branch predictor? */	      if (!pred_PC)		{		  /* no predicted taken target, attempt not taken target */		  pred_PC = regs_PC + sizeof(SS_INST_TYPE);		}	      bpred_update(pred,			   /* branch addr */regs_PC,			   /* resolved branch target */next_PC,			   /* taken? */next_PC != (regs_PC +						   sizeof(SS_INST_TYPE)),			   /* pred taken? */pred_PC != (regs_PC +							sizeof(SS_INST_TYPE)),			   /* correct pred? */pred_PC == next_PC,			   /* opcode */op,			   /* jump through R31? */(RS) == 31,			   /* predictor update pointer */&update_rec);	    }	}      /* check for DLite debugger entry condition */      if (dlite_check_break(next_PC,			    is_write ? ACCESS_WRITE : ACCESS_READ,			    addr, sim_num_insn, sim_num_insn))	dlite_main(regs_PC, next_PC, sim_num_insn);      /* go to the next instruction */      regs_PC = next_PC;      next_PC += SS_INST_SIZE;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -