博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Lab 4: Cache Geometries
阅读量:4318 次
发布时间:2019-06-06

本文共 2615 字,大约阅读时间需要 8 分钟。

这次的lab特别简单,直接贴代码了

/*Coursera HW/SW InterfaceLab 4 - Mystery CachesMystery Cache Geometries (for you to keep notes):mystery0:    block size =    cache size =    associativity =mystery1:    block size =    cache size =    associativity =mystery2:    block size =    cache size =    associativity =mystery3:    block size =    cache size =    associativity =*/#include 
#include
#include "mystery-cache.h"/* * NOTE: When using access_cache() you do not need to provide a "real" * memory addresses. You can use any convenient integer value as a * memory address, you should not be able to cause a segmentation * fault by providing a memory address out of your programs address * space as the argument to access_cache. *//* Returns the size (in B) of each block in the cache.*/int get_block_size(void) { /* YOUR CODE GOES HERE */ cache_init(16000, 4); flush_cache(); int back = 0x0000ff00; access_cache(back); while(access_cache(back)) { back+= 1; } flush_cache(); int front = 0x0000ff00; access_cache(front); while(access_cache(front)) { front-= 1; } return back-front-1; }/* Returns the size (in B) of the cache.*/int get_cache_size(int size) { /* YOUR CODE GOES HERE */ // printf("%d\n", s); flush_cache(); int start = 0x00FFff00; int i = size / 2; int p; do { i *= 2; p = start; flush_cache(); access_cache(start); while(p < start + i) { p += size; access_cache(p); } if (!access_cache(start)) break; } while(1); return i;}/* Returns the associativity of the cache.*/int get_cache_assoc(int size) { /* YOUR CODE GOES HERE */ return get_cache_size(size) / size; }//// DO NOT CHANGE ANYTHING BELOW THIS POINTint main(void) { int size; int assoc; int block_size; /* The cache needs to be initialized, but the parameters will be ignored by the mystery caches, as they are hard coded. You can test your geometry paramter discovery routines by calling cache_init() w/ your own size and block size values. */ cache_init(0,0); block_size=get_block_size(); size=get_cache_size(block_size); assoc=get_cache_assoc(size); printf("Cache block size: %d bytes\n", block_size); printf("Cache size: %d bytes\n", size); printf("Cache associativity: %d\n", assoc); return EXIT_SUCCESS;}

 get_block_size 中代码的意思是找到下一行的起始点,上一行的终结点,然后两者相减再减1就是block size

get_cache_size 中代码的意思是不断访问一行行cache,一旦访问到某一行时最初那行变为未访问状态,就表明这行block被替换了,说明已经经过了cache size。

get_cache_assoc 与 get_cache_size 相同,不过每次加的都是 cache size,这样每次访问都只会在一组内访问,一旦最初那组出现未访问,就说明被替代了。这样就能得出一组的行数。

 

 

 

2015-09-28

 

转载于:https://www.cnblogs.com/whuyt/p/4843795.html

你可能感兴趣的文章
二分图匹配
查看>>
c++ 模板template
查看>>
CString的成员函数详解
查看>>
Appium Studio 初体验(windows做ios自动化,录制appium脚本)
查看>>
Linux常用命令
查看>>
整体二分&cdq分治 ZOJ 2112 Dynamic Rankings
查看>>
【POJ2976】Dropping tests (01分数规划入门题)
查看>>
通过正则表达式获取url中参数
查看>>
cxx signal信号捕获
查看>>
《Android开发艺术探索》读书笔记——Cha3.2.3改变布局参数实现View的滑动
查看>>
python闭包与装饰器
查看>>
Acegi 源码解释
查看>>
Activity的几种启动跳转方式
查看>>
LCA最近公共祖先Tarjan(离线)
查看>>
牛客练习赛16 E求值
查看>>
matlab rank
查看>>
Asp.net系列--基础篇(三)
查看>>
css基础
查看>>
如何在tomcat中如何部署java EE项目
查看>>
【Python基础教程第2版】——第二讲:列表和元组
查看>>