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

📄 sim-bpred.c

📁 RISC处理器仿真分析程序。可以用于研究通用RISC处理器的指令和架构设计。在linux下编译
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * sim-bpred.c - sample branch predictor simulator implementation * * This file is a part of the SimpleScalar tool suite written by * Todd M. Austin as a part of the Multiscalar Research Project. *   * The tool suite is currently maintained by Doug Burger and Todd M. Austin. *  * Copyright (C) 1994, 1995, 1996, 1997 by Todd M. Austin * * This source file is distributed "as is" in the hope that it will be * useful.  The tool set comes with no warranty, and no author or * distributor accepts any responsibility for the consequences of its * use.  *  * Everyone is granted permission to copy, modify and redistribute * this tool set under the following conditions: *  *    This source code is distributed for non-commercial use only.  *    Please contact the maintainer for restrictions applying to  *    commercial use. * *    Permission is granted to anyone to make or distribute copies *    of this source code, either as received or modified, in any *    medium, provided that all copyright notices, permission and *    nonwarranty notices are preserved, and that the distributor *    grants the recipient permission for further redistribution as *    permitted by this document. * *    Permission is granted to distribute this file in compiled *    or executable form under the same conditions that apply for *    source code, provided that either: * *    A. it is accompanied by the corresponding machine-readable *       source code, *    B. it is accompanied by a written offer, with no time limit, *       to give anyone a machine-readable copy of the corresponding *       source code in return for reimbursement of the cost of *       distribution.  This written offer must permit verbatim *       duplication by anyone, or *    C. it is distributed by someone who received only the *       executable form, and is accompanied by a copy of the *       written offer of source code that they received concurrently. * * In other words, you are welcome to use, share and improve this * source file.  You are forbidden to forbid anyone else to use, share * and improve what you give them. * * INTERNET: dburger@cs.wisc.edu * US Mail:  1210 W. Dayton Street, Madison, WI 53706 * * $Id$ * * $Log$ * */#include <stdio.h>#include <stdlib.h>#include <math.h>#include "misc.h"#include "ss.h"#include "regs.h"#include "memory.h"#include "loader.h"#include "syscall.h"#include "dlite.h"#include "options.h"#include "stats.h"#include "bpred.h"#include "sim.h"/* * This file implements a branch predictor analyzer. *//* branch predictor type {nottaken|taken|perfect|bimod|2lev} */static char *pred_type;/* bimodal predictor config (<table_size>) */static int bimod_nelt = 1;static int bimod_config[1] =  { /* bimod tbl size */2048 };/* 2-level predictor config (<l1size> <l2size> <hist_size> <xor>) */static int twolev_nelt = 4;static int twolev_config[4] =  { /* l1size */1, /* l2size */1024, /* hist */8, /* xor */FALSE};/* combining predictor config (<meta_table_size> */static int comb_nelt = 1;static int comb_config[1] =  { /* meta_table_size */1024 };/* return address stack (RAS) size */static int ras_size = 8;/* BTB predictor config (<num_sets> <associativity>) */static int btb_nelt = 2;static int btb_config[2] =  { /* nsets */512, /* assoc */4 };/* branch predictor */static struct bpred *pred;/* track number of insn and refs */static SS_COUNTER_TYPE sim_num_insn = 0;static SS_COUNTER_TYPE sim_num_refs = 0;/* total number of branches executed */static SS_COUNTER_TYPE sim_num_branches = 0;/* register simulator-specific options */voidsim_reg_options(struct opt_odb_t *odb){  opt_reg_header(odb, "sim-bpred: This simulator implements a branch predictor analyzer.\n"		 );  /* branch predictor options */  opt_reg_note(odb,"  Branch predictor configuration examples for 2-level predictor:\n""    Configurations:   N, M, W, X\n""      N   # entries in first level (# of shift register(s))\n""      W   width of shift register(s)\n""      M   # entries in 2nd level (# of counters, or other FSM)\n""      X   (yes-1/no-0) xor history and address for 2nd level index\n""    Sample predictors:\n""      GAg     : 1, W, 2^W, 0\n""      GAp     : 1, W, M (M > 2^W), 0\n""      PAg     : N, W, 2^W, 0\n""      PAp     : N, W, M (M == 2^(N+W)), 0\n""      gshare  : 1, W, 2^W, 1\n""  Predictor `comb' combines a bimodal and a 2-level predictor.\n"               );  opt_reg_string(odb, "-bpred",		 "branch predictor type {nottaken|taken|bimod|2lev|comb}",                 &pred_type, /* default */"bimod",                 /* print */TRUE, /* format */NULL);  opt_reg_int_list(odb, "-bpred:bimod",		   "bimodal predictor config (<table size>)",		   bimod_config, bimod_nelt, &bimod_nelt,		   /* default */bimod_config,		   /* print */TRUE, /* format */NULL, /* !accrue */FALSE);  opt_reg_int_list(odb, "-bpred:2lev",                   "2-level predictor config "		   "(<l1size> <l2size> <hist_size> <xor>)",                   twolev_config, twolev_nelt, &twolev_nelt,		   /* default */twolev_config,                   /* print */TRUE, /* format */NULL, /* !accrue */FALSE);  opt_reg_int_list(odb, "-bpred:comb",		   "combining predictor config (<meta_table_size>)",		   comb_config, comb_nelt, &comb_nelt,		   /* default */comb_config,		   /* print */TRUE, /* format */NULL, /* !accrue */FALSE);  opt_reg_int(odb, "-bpred:ras",              "return address stack size (0 for no return stack)",              &ras_size, /* default */ras_size,              /* print */TRUE, /* format */NULL);  opt_reg_int_list(odb, "-bpred:btb",		   "BTB config (<num_sets> <associativity>)",		   btb_config, btb_nelt, &btb_nelt,		   /* default */btb_config,		   /* print */TRUE, /* format */NULL, /* !accrue */FALSE);}/* check simulator-specific option values */voidsim_check_options(struct opt_odb_t *odb, int argc, char **argv){  if (!mystricmp(pred_type, "taken"))    {      /* static predictor, not taken */      pred = bpred_create(BPredTaken, 0, 0, 0, 0, 0, 0, 0, 0, 0);    }  else if (!mystricmp(pred_type, "nottaken"))    {      /* static predictor, taken */      pred = bpred_create(BPredNotTaken, 0, 0, 0, 0, 0, 0, 0, 0, 0);    }  else if (!mystricmp(pred_type, "bimod"))    {      if (bimod_nelt != 1)	fatal("bad bimod predictor config (<table_size>)");      if (btb_nelt != 2)	fatal("bad btb config (<num_sets> <associativity>)");      /* bimodal predictor, bpred_create() checks BTB_SIZE */      pred = bpred_create(BPred2bit,			  /* bimod table size */bimod_config[0],			  /* 2lev l1 size */0,			  /* 2lev l2 size */0,			  /* meta table size */0,			  /* history reg size */0,			  /* history xor address */0,			  /* btb sets */btb_config[0],			  /* btb assoc */btb_config[1],			  /* ret-addr stack size */ras_size);    }  else if (!mystricmp(pred_type, "2lev"))    {      /* 2-level adaptive predictor, bpred_create() checks args */      if (twolev_nelt != 4)	fatal("bad 2-level pred config (<l1size> <l2size> <hist_size> <xor>)");      if (btb_nelt != 2)	fatal("bad btb config (<num_sets> <associativity>)");      pred = bpred_create(BPred2Level,			  /* bimod table size */0,			  /* 2lev l1 size */twolev_config[0],			  /* 2lev l2 size */twolev_config[1],			  /* meta table size */0,			  /* history reg size */twolev_config[2],			  /* history xor address */twolev_config[3],			  /* btb sets */btb_config[0],			  /* btb assoc */btb_config[1],			  /* ret-addr stack size */ras_size);    }  else if (!mystricmp(pred_type, "comb"))    {      /* combining predictor, bpred_create() checks args */      if (twolev_nelt != 4)	fatal("bad 2-level pred config (<l1size> <l2size> <hist_size> <xor>)");      if (bimod_nelt != 1)	fatal("bad bimod predictor config (<table_size>)");      if (comb_nelt != 1)	fatal("bad combining predictor config (<meta_table_size>)");      if (btb_nelt != 2)	fatal("bad btb config (<num_sets> <associativity>)");      pred = bpred_create(BPredComb,			  /* bimod table size */bimod_config[0],			  /* l1 size */twolev_config[0],			  /* l2 size */twolev_config[1],			  /* meta table size */comb_config[0],			  /* history reg size */twolev_config[2],			  /* history xor address */twolev_config[3],			  /* btb sets */btb_config[0],			  /* btb assoc */btb_config[1],			  /* ret-addr stack size */ras_size);    }  else    fatal("cannot parse predictor type `%s'", pred_type);}/* register simulator-specific statistics */voidsim_reg_stats(struct stat_sdb_t *sdb){  stat_reg_counter(sdb, "sim_num_insn",		   "total number of instructions executed",		   &sim_num_insn, 0, NULL);  stat_reg_counter(sdb, "sim_num_refs",		   "total number of loads and stores executed",		   &sim_num_refs, 0, NULL);  stat_reg_int(sdb, "sim_elapsed_time",	       "total simulation time in seconds",	       (int *)&sim_elapsed_time, 0, NULL);  stat_reg_formula(sdb, "sim_inst_rate",		   "simulation speed (in insts/sec)",		   "sim_num_insn / sim_elapsed_time", NULL);

⌨️ 快捷键说明

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