📄 sim-outorder.c
字号:
/* sim-outorder.c - sample out-of-order issue perf simulator implementation *//* SimpleScalar(TM) Tool Suite * Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC. * All Rights Reserved. * * THIS IS A LEGAL DOCUMENT, BY USING SIMPLESCALAR, * YOU ARE AGREEING TO THESE TERMS AND CONDITIONS. * * No portion of this work may be used by any commercial entity, or for any * commercial purpose, without the prior, written permission of SimpleScalar, * LLC (info@simplescalar.com). Nonprofit and noncommercial use is permitted * as described below. * * 1. SimpleScalar is provided AS IS, with no warranty of any kind, express * or implied. The user of the program accepts full responsibility for the * application of the program and the use of any results. * * 2. Nonprofit and noncommercial use is encouraged. SimpleScalar may be * downloaded, compiled, executed, copied, and modified solely for nonprofit, * educational, noncommercial research, and noncommercial scholarship * purposes provided that this notice in its entirety accompanies all copies. * Copies of the modified software can be delivered to persons who use it * solely for nonprofit, educational, noncommercial research, and * noncommercial scholarship purposes provided that this notice in its * entirety accompanies all copies. * * 3. ALL COMMERCIAL USE, AND ALL USE BY FOR PROFIT ENTITIES, IS EXPRESSLY * PROHIBITED WITHOUT A LICENSE FROM SIMPLESCALAR, LLC (info@simplescalar.com). * * 4. No nonprofit user may place any restrictions on the use of this software, * including as modified by the user, by any other authorized user. * * 5. Noncommercial and nonprofit users may distribute copies of SimpleScalar * in compiled or executable form as set forth in Section 2, provided that * either: (A) it is accompanied by the corresponding machine-readable source * code, or (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. * * 6. SimpleScalar was developed by Todd M. Austin, Ph.D. The tool suite is * currently maintained by SimpleScalar LLC (info@simplescalar.com). US Mail: * 2395 Timbercrest Court, Ann Arbor, MI 48105. * * Copyright (C) 1994-2003 by Todd M. Austin, Ph.D. and SimpleScalar, LLC. */#include <stdio.h>#include <stdlib.h>#include <math.h>#include <assert.h>#include <signal.h>#include "host.h"#include "misc.h"#include "machine.h"#include "regs.h"#include "memory.h"#include "cache.h"#include "loader.h"#include "syscall.h"#include "bpred.h"#include "resource.h"#include "bitmap.h"#include "options.h"#include "eval.h"#include "stats.h"#include "ptrace.h"#include "dlite.h"#include "sim.h"/* * This file implements a very detailed out-of-order issue superscalar * processor with a two-level memory system and speculative execution support. * This simulator is a performance simulator, tracking the latency of all * pipeline operations. *//* simulated registers */static struct regs_t regs;/* simulated memory */static struct mem_t *mem = NULL;/* * simulator options *//* maximum number of inst's to execute */static unsigned int max_insts;/* number of insts skipped before timing starts */static int fastfwd_count;/* pipeline trace range and output filename */static int ptrace_nelt = 0;static char *ptrace_opts[2];/* instruction fetch queue size (in insts) */static int ruu_ifq_size;/* extra branch mis-prediction latency */static int ruu_branch_penalty;/* speed of front-end of machine relative to execution core */static int fetch_speed;/* 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 };/* instruction decode B/W (insts/cycle) */static int ruu_decode_width;/* instruction issue B/W (insts/cycle) */static int ruu_issue_width;/* run pipeline with in-order issue */static int ruu_inorder_issue;/* issue instructions down wrong execution paths */static int ruu_include_spec = TRUE;/* instruction commit B/W (insts/cycle) */static int ruu_commit_width;/* register update unit (RUU) size */static int RUU_size = 8;/* load/store queue (LSQ) size */static int LSQ_size = 4;/* l1 data cache config, i.e., {<config>|none} */static char *cache_dl1_opt;/* l1 data cache hit latency (in cycles) */static int cache_dl1_lat;/* l2 data cache config, i.e., {<config>|none} */static char *cache_dl2_opt;/* l2 data cache hit latency (in cycles) */static int cache_dl2_lat;/* l1 instruction cache config, i.e., {<config>|dl1|dl2|none} */static char *cache_il1_opt;/* l1 instruction cache hit latency (in cycles) */static int cache_il1_lat;/* l2 instruction cache config, i.e., {<config>|dl1|dl2|none} */static char *cache_il2_opt;/* l2 instruction cache hit latency (in cycles) */static int cache_il2_lat;/* flush caches on system calls */static int flush_on_syscalls;/* convert 64-bit inst addresses to 32-bit inst equivalents */static int compress_icache_addrs;/* memory access latency (<first_chunk> <inter_chunk>) */static int mem_nelt = 2;static int mem_lat[2] = { /* lat to first chunk */18, /* lat between remaining chunks */2 };/* memory access bus width (in bytes) */static int mem_bus_width;/* instruction TLB config, i.e., {<config>|none} */static char *itlb_opt;/* data TLB config, i.e., {<config>|none} */static char *dtlb_opt;/* inst/data TLB miss latency (in cycles) */static int tlb_miss_lat;/* total number of integer ALU's available */static int res_ialu;/* total number of integer multiplier/dividers available */static int res_imult;/* total number of memory system ports available (to CPU) */static int res_memport;/* total number of floating point ALU's available */static int res_fpalu;/* total number of floating point multiplier/dividers available */static int res_fpmult;/* text-based stat profiles */#define MAX_PCSTAT_VARS 8static int pcstat_nelt = 0;static char *pcstat_vars[MAX_PCSTAT_VARS];/* convert 64-bit inst text addresses to 32-bit inst equivalents */#ifdef TARGET_PISA#define IACOMPRESS(A) \ (compress_icache_addrs ? ((((A) - ld_text_base) >> 1) + ld_text_base) : (A))#define ISCOMPRESS(SZ) \ (compress_icache_addrs ? ((SZ) >> 1) : (SZ))#else /* !TARGET_PISA */#define IACOMPRESS(A) (A)#define ISCOMPRESS(SZ) (SZ)#endif /* TARGET_PISA *//* operate in backward-compatible bugs mode (for testing only) */static int bugcompat_mode;/* * functional unit resource configuration *//* resource pool indices, NOTE: update these if you change FU_CONFIG */#define FU_IALU_INDEX 0#define FU_IMULT_INDEX 1#define FU_MEMPORT_INDEX 2#define FU_FPALU_INDEX 3#define FU_FPMULT_INDEX 4/* resource pool definition, NOTE: update FU_*_INDEX defs if you change this */struct res_desc fu_config[] = { { "integer-ALU", 4, 0, { { IntALU, 1, 1 } } }, { "integer-MULT/DIV", 1, 0, { { IntMULT, 3, 1 }, { IntDIV, 20, 19 } } }, { "memory-port", 2, 0, { { RdPort, 1, 1 }, { WrPort, 1, 1 } } }, { "FP-adder", 4, 0, { { FloatADD, 2, 1 }, { FloatCMP, 2, 1 }, { FloatCVT, 2, 1 } } }, { "FP-MULT/DIV", 1, 0, { { FloatMULT, 4, 1 }, { FloatDIV, 12, 12 }, { FloatSQRT, 24, 24 } } },};/* * simulator stats *//* SLIP variable */static counter_t sim_slip = 0;/* total number of instructions executed */static counter_t sim_total_insn = 0;/* total number of memory references committed */static counter_t sim_num_refs = 0;/* total number of memory references executed */static counter_t sim_total_refs = 0;/* total number of loads committed */static counter_t sim_num_loads = 0;/* total number of loads executed */static counter_t sim_total_loads = 0;/* total number of branches committed */static counter_t sim_num_branches = 0;/* total number of branches executed */static counter_t sim_total_branches = 0;/* cycle counter */static tick_t sim_cycle = 0;/* occupancy counters */static counter_t IFQ_count; /* cumulative IFQ occupancy */static counter_t IFQ_fcount; /* cumulative IFQ full count */static counter_t RUU_count; /* cumulative RUU occupancy */static counter_t RUU_fcount; /* cumulative RUU full count */static counter_t LSQ_count; /* cumulative LSQ occupancy */static counter_t LSQ_fcount; /* cumulative LSQ full count *//* total non-speculative bogus addresses seen (debug var) */static counter_t sim_invalid_addrs;/* * simulator state variables *//* instruction sequence counter, used to assign unique id's to insts */static unsigned int inst_seq = 0;/* pipetrace instruction sequence counter */static unsigned int ptrace_seq = 0;/* speculation mode, non-zero when mis-speculating, i.e., executing instructions down the wrong path, thus state recovery will eventually have to occur that resets processor register and memory state back to the last precise state */static int spec_mode = FALSE;/* cycles until fetch issue resumes */static unsigned ruu_fetch_issue_delay = 0;/* perfect prediction enabled */static int pred_perfect = FALSE;/* speculative bpred-update enabled */static char *bpred_spec_opt;static enum { spec_ID, spec_WB, spec_CT } bpred_spec_update;/* level 1 instruction cache, entry level instruction cache */static struct cache_t *cache_il1;/* level 1 instruction cache */static struct cache_t *cache_il2;/* level 1 data cache, entry level data cache */static struct cache_t *cache_dl1;/* level 2 data cache */static struct cache_t *cache_dl2;/* instruction TLB */static struct cache_t *itlb;/* data TLB */static struct cache_t *dtlb;/* branch predictor */static struct bpred_t *pred;/* functional unit resource pool */static struct res_pool *fu_pool = NULL;/* text-based stat profiles */static struct stat_stat_t *pcstat_stats[MAX_PCSTAT_VARS];static counter_t pcstat_lastvals[MAX_PCSTAT_VARS];static struct stat_stat_t *pcstat_sdists[MAX_PCSTAT_VARS];/* wedge all stat values into a counter_t */#define STATVAL(STAT) \ ((STAT)->sc == sc_int \ ? (counter_t)*((STAT)->variant.for_int.var) \ : ((STAT)->sc == sc_uint \ ? (counter_t)*((STAT)->variant.for_uint.var) \ : ((STAT)->sc == sc_counter \ ? *((STAT)->variant.for_counter.var) \ : (panic("bad stat class"), 0))))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -