资源简介
icarnegie ssd6 exercise5 答案

代码片段和文件信息
// #pragma warning(disable: 4244)
/* Cache simulator:
Simulates 4-way set-associative cache using LRU for replacement policy
Cache parameters configured at compile time */
#include “cache.h“
#include “defs.h“
#include “math.h“
/* cache parameters */
#define CACHE_SIZE 16384 /* 16KB cache */
#define SET_ASSOCIATIVITY 1 /* 4-way set associative */
#define BLOCK_SIZE 32 /* 32-byte lines */
/* By default configured for 16KB cache with 32B block size */
static int block_bits = 5;
static int set_bits = 9; //log(CACHE_SIZE/SET_ASSOCIATIVITY/BLOCK_SIZE);
#define MAX_SET_COUNT (1 << 10)
//#define BLOCK_SIZE (1<<(block_bits))
#define SET_COUNT (1<<(set_bits))
#define SET_MASK (SET_COUNT-1)
/* Get cache index from address */
#define GET_INDEX(addr) (SET_MASK & ( (unsigned) (addr) >> block_bits))
/* Get cache tag from address */
#define GET_TAG(addr) ((unsigned) (addr) >> (block_bits + set_bits))
static unsigned tags[MAX_SET_COUNT][SET_ASSOCIATIVITY];
static int read_misses = 0;
static int reads = 0;
static int write_misses = 0;
static int writes = 0;
void set_cache_measurement_enabled(int enabled) {
return;
}
/* Reset cache statistics without clearing cache */
void clear_cache_statistics()
{
read_misses = 0;
reads = 0;
write_misses = 0;
writes = 0;
}
/* Create empty cache with #sets = 2^s_bits block size = 2^b_bits */
void reset_cache(void)
{
clear_cache_statistics();
reset_cache2(set_bits block_bits);
}
void reset_cache2(int s_bits int b_bits)
{
int i j;
set_bits = s_bits;
block_bits = b_bits;
for (i = 0; i < SET_COUNT; i++) {
for( j=0; j tags[i][j] = -1;
}
}
clear_cache_statistics();
}
int get_read_count()
{
return reads;
}
int get_write_count()
{
return writes;
}
int get_read_miss_count()
{
return read_misses;
}
int get_write_miss_count()
{
return write_misses;
}
double get_read_miss_rate()
{
return (double) read_misses / (double) reads;
}
double get_write_miss_rate()
{
return (double) write_misses / (double) writes;
}
double get_miss_rate()
{
return (double) (read_misses + write_misses) / (double) (reads+ writes);
}
static void cache_read(int *addr)
{
int i j;
// unsigned long addr = addr_p;
unsigned tindex = GET_INDEX(addr);
unsigned tag = GET_TAG(addr);
reads++;
for(i=0; i if(tags[tindex][i] == tag) {
for( j=i ; j>0 ; j-- ) {
tags[tindex][j] = tags[tindex][j-1];
}
tags[tindex][0] = tag;
return;
}
}
read_misses++;
for(j=SET_ASSOCIATIVITY-1; j>0; j--) {
tags[tindex][j] = tags[tindex][j-1];
}
tags[tindex][0] = tag;
return;
}
static void cache_write(int *addr)
{
int i j;
unsigned tindex = GET_INDEX(addr);
unsigned tag = GET_TAG(addr);
writes++;
for(i=0; i if(tags[tindex][i] == tag) {
for( j=i ; j>0 ; j-- ) {
ta
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2012-01-27 21:00 exercise5_handout\
文件 3822 2005-08-16 16:27 exercise5_handout\cache.c
文件 754 2002-08-06 11:16 exercise5_handout\cache.h
文件 4042 2008-04-26 01:19 exercise5_handout\cache.vcproj
文件 5077 2011-12-30 15:44 exercise5_handout\cache.vcxproj
文件 1422 2011-12-30 15:44 exercise5_handout\cache.vcxproj.filters
文件 143 2011-12-30 15:44 exercise5_handout\cache.vcxproj.user
目录 0 2012-01-27 21:00 exercise5_handout\Debug\
文件 51200 2011-12-30 18:54 exercise5_handout\Debug\cache.exe
文件 381 2011-12-30 18:54 exercise5_handout\Debug\cache.exe.intermediate.manifest
文件 345116 2011-12-30 18:54 exercise5_handout\Debug\cache.ilk
文件 85 2011-12-30 18:54 exercise5_handout\Debug\cache.lastbuildstate
文件 1957 2011-12-30 18:54 exercise5_handout\Debug\cache.log
文件 14886 2011-12-30 18:46 exercise5_handout\Debug\cache.obj
文件 388096 2011-12-30 18:54 exercise5_handout\Debug\cache.pdb
文件 2390 2011-12-30 18:54 exercise5_handout\Debug\cl.command.1.tlog
文件 6568 2011-12-30 18:54 exercise5_handout\Debug\CL.read.1.tlog
文件 2348 2011-12-30 18:54 exercise5_handout\Debug\CL.write.1.tlog
文件 38150 2011-12-30 18:46 exercise5_handout\Debug\driver.obj
文件 1606 2011-12-30 18:54 exercise5_handout\Debug\li
文件 3242 2011-12-30 18:54 exercise5_handout\Debug\li
文件 1136 2011-12-30 18:54 exercise5_handout\Debug\li
文件 390 2011-12-30 18:54 exercise5_handout\Debug\mt.command.1.tlog
文件 780 2011-12-30 18:54 exercise5_handout\Debug\mt.read.1.tlog
文件 320 2011-12-30 18:54 exercise5_handout\Debug\mt.write.1.tlog
文件 5045 2011-12-30 18:47 exercise5_handout\Debug\rotate.obj
文件 5717 2011-12-30 18:54 exercise5_handout\Debug\smooth.obj
文件 52224 2011-12-30 18:54 exercise5_handout\Debug\vc100.idb
文件 61440 2011-12-30 18:54 exercise5_handout\Debug\vc100.pdb
文件 886 2002-08-10 21:49 exercise5_handout\defs.h
文件 18039 2002-08-11 01:40 exercise5_handout\driver.c
............此处省略2个文件信息
相关资源
- 数据库系统基础教程答案第三版机械
- 《数字信号处理第三版》课后习题答
- 数据结构年终考题范围和答案 耿国华
- 大学物理答案 同济大学 高等教育出版
- 信息论与编码(仇佩亮编著 高等教育
- 《复变函数》习题答案(第四版)
- 中科院 编译原理 习题及解答
- 西安电子科技大学 并行计算 霍红卫
- 浙江工业大学2005-2006学年单片机习题
- 信息系统分析与设计试卷及答案
- SSD4 exercise8答案
- 杨素行第三版模电答案
- 复变函数参考答案(西安交通大学版
- 复旦大学出版社 李贤平 《概率论基础
- 数值分析答案(第五版)李庆扬
- 数据结构殷人昆版的课后答案
- 郁道银 工程光学 习题答案
- 操作系统教程课后答案华中科技大学
- 用友ERP考试系统练习题库及答案
- 《原子物理学》高教 杨福家 完整版课
- 真正!!!概率论与数理统计浙江大
- 计算机操作系统课后_汤小丹_第四版
- 计算机操作系统(第四版)汤小丹课
- 南京大学考研845真题答案-2018
- Convex Optimization 习题答案
- 数据结构考研试题历届试卷(附答案
- 计算机网络自顶向下方法答案(第六
- 数学分析教材,复旦,陈传璋、金福
- 操作系统教程课后习题答案
- 编译原理龙书答案
评论
共有 条评论