Guest User

Untitled

a guest
Dec 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. struct Set{
  2. //int order; //NOTE: We may not need this.
  3. long unsigned setIndex;
  4. struct Line *cacheLine;
  5. };
  6.  
  7. struct Line{
  8. int valid;
  9. long unsigned tag;
  10. };
  11.  
  12. if(strcmp(assoc, "direct") == 0 ){
  13.  
  14.  
  15. numOfLines = 1;
  16. numOfSets = cacheSize/(blockSize*numOfLines);
  17. int k = log2n(numOfSets);
  18. int offset = log2n(blockSize);
  19. struct Set *cache = (struct Set *) malloc(sizeof(struct Set)*numOfSets);
  20.  
  21. while(readLine() != EXIT_FAILURE){
  22.  
  23. int hit = 0;
  24. int preHit = 0;
  25. blockIdentifier = address>>offset;
  26. tempSetIndex = ((blockIdentifier) & ((1<<k)-1));
  27. tempTag = address>> k;
  28. tempTag = tempTag >> offset;
  29. for(i = 0; (hit == 0) && (i < numOfSets-1); i++){
  30.  
  31. if((cache[i].setIndex == tempSetIndex) && (cache[i].cacheLine->tag == tempTag)){
  32. hit = 1;
  33. numHits++;
  34.  
  35. if(operation == 'W'){
  36. numWrites++;
  37. }
  38.  
  39. }
  40. }
  41.  
  42. if(hit == 0){
  43.  
  44. cache[fifo].setIndex = tempSetIndex;
  45. cache[fifo].cacheLine->tag = tempTag;
  46. cache[fifo].cacheLine->valid = 1;
  47. hit = 1;
  48.  
  49. if(fifo == numOfSets-2){
  50. fifo = 0;
  51. }
  52.  
  53. else{
  54. fifo++;
  55. }
  56.  
  57. if(operation == 'R'){
  58. numMisses++;
  59. numReads++;
  60. }
  61.  
  62. if(operation == 'W'){
  63. numMisses++;
  64. numReads++;
  65. numWrites++;
  66. }
Add Comment
Please, Sign In to add comment