当前位置: 首页>>代码示例>>C++>>正文


C++ CACHE_HASH函数代码示例

本文整理汇总了C++中CACHE_HASH函数的典型用法代码示例。如果您正苦于以下问题:C++ CACHE_HASH函数的具体用法?C++ CACHE_HASH怎么用?C++ CACHE_HASH使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CACHE_HASH函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: unlink_htab_ent

/* unlink BLK from the hash table bucket chain in SET */
static void
unlink_htab_ent(struct cache_t *cp,		/* cache to update */
		struct cache_set_t *set,	/* set containing bkt chain */
		struct cache_blk_t *blk)	/* block to unlink */
{
  struct cache_blk_t *prev, *ent;
  int index = CACHE_HASH(cp, blk->tag);

  /* locate the block in the hash table bucket chain */
  for (prev=NULL,ent=set->hash[index];
       ent;
       prev=ent,ent=ent->hash_next)
    {
      if (ent == blk)
	break;
    }
  assert(ent);

  /* unlink the block from the hash table bucket chain */
  if (!prev)
    {
      /* head of hash bucket list */
      set->hash[index] = ent->hash_next;
    }
  else
    {
      /* middle or end of hash bucket list */
      prev->hash_next = ent->hash_next;
    }
  ent->hash_next = NULL;
}
开发者ID:jnaneshm,项目名称:614_hw4,代码行数:32,代码来源:cache.c

示例2: cache_invalidate_symbol

static inline void
cache_invalidate_symbol (repv symbol)
{
    unsigned int hash = CACHE_HASH (symbol);
    if (ref_cache[hash].s != 0 && ref_cache[hash].n->symbol == symbol)
	ref_cache[hash].s = 0;
}
开发者ID:OpenInkpot-archive,项目名称:iplinux-librep,代码行数:7,代码来源:structures.c

示例3: enter_cache

static inline void
enter_cache (rep_struct *s, rep_struct_node *binding)
{
    unsigned int hash = CACHE_HASH (binding->symbol);
    int i, oldest_i, oldest_age = INT_MAX;
    for (i = 0; i < CACHE_ASSOC; i++)
    {
	if (ref_cache[hash][i].s == 0)
	{
	    oldest_i = i;
	    break;
	}
	else if (ref_cache[hash][i].age < oldest_age)
	{
	    oldest_i = i;
	    oldest_age = ref_cache[hash][i].age;
	}
    }
    assert (oldest_i < CACHE_ASSOC);
#ifdef DEBUG
    if (ref_cache[hash][oldest_i].s != 0)
    {
	if (ref_cache[hash][oldest_i].n->symbol == binding->symbol)
	    ref_cache_conflicts++;
	else
	    ref_cache_collisions++;
    }
#endif
    ref_cache[hash][oldest_i].s = s;
    ref_cache[hash][oldest_i].n = binding;
    ref_cache[hash][oldest_i].age = ++ref_age;
}
开发者ID:OpenInkpot-archive,项目名称:iplinux-librep,代码行数:32,代码来源:structures.c

示例4: cache_flush_addr

/* flush the block containing ADDR from the cache CP, returns the latency of
   the block flush operation */
unsigned int				/* latency of flush operation */
cache_flush_addr(struct cache_t *cp,	/* cache instance to flush */
		 md_addr_t addr,	/* address of block to flush */
		 tick_t now)		/* time of cache flush */
{
  fprintf( stderr, "flush address\n" );
  md_addr_t tag = CACHE_TAG(cp, addr);
  md_addr_t set = CACHE_SET(cp, addr);
  struct cache_blk_t *blk;
  int lat = cp->hit_latency; /* min latency to probe cache */

  if (cp->hsize)
    {
      /* higly-associativity cache, access through the per-set hash tables */
      int hindex = CACHE_HASH(cp, tag);

      for (blk=cp->sets[set].hash[hindex];
	   blk;
	   blk=blk->hash_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    break;
	}
    }
  else
    {
      /* low-associativity cache, linear search the way list */
      for (blk=cp->sets[set].way_head;
	   blk;
	   blk=blk->way_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    break;
	}
    }

  if (blk)
    {
      cp->invalidations++;
      blk->status &= ~CACHE_BLK_VALID;

      /* blow away the last block to hit */
      cp->last_tagset = 0;
      cp->last_blk = NULL;

      if (blk->status & CACHE_BLK_DIRTY)
	{
	  /* write back the invalidated block */
          cp->writebacks++;
	  lat += cp->blk_access_fn(Write,
				   CACHE_MK_BADDR(cp, blk->tag, set),
				   cp->bsize, blk, now+lat);
	}
      /* move this block to tail of the way (LRU) list */
      update_way_list(&cp->sets[set], blk, Tail);
    }

  /* return latency of the operation */
  return lat;
}
开发者ID:jsarabia1247,项目名称:waylevelcache,代码行数:62,代码来源:cache.c

示例5: cache_probe

/* return non-zero if block containing address ADDR is contained in cache
 CP, this interface is used primarily for debugging and asserting cache
 invariants */
int /* non-zero if access would hit */
cache_probe(struct cache_t *cp, /* cache instance to probe */
md_addr_t addr) /* address of block to probe */
{
	md_addr_t tag = CACHE_TAG(cp, addr);
	md_addr_t set = CACHE_SET(cp, addr);
	struct cache_blk_t *blk;

	/* permissions are checked on cache misses */

	if (cp->hsize) {
		/* higly-associativity cache, access through the per-set hash tables */
		int hindex = CACHE_HASH(cp, tag);

		for (blk = cp->sets[set].hash[hindex]; blk; blk = blk->hash_next) {
			if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
				return TRUE;
		}
	} else {
		/* low-associativity cache, linear search the way list */
		for (blk = cp->sets[set].way_head; blk; blk = blk->way_next) {
			if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
				return TRUE;
		}
	}

	/* cache block not found */
	return FALSE;
}
开发者ID:Evangileon,项目名称:SimpleScalar-Tournament,代码行数:32,代码来源:cache.c

示例6: property_cache_ref

repv
property_cache_ref (repv id, repv prop)
{
    unsigned int h, i;

    if (cache_vec == rep_NULL)
	return rep_NULL;

    h = CACHE_HASH (id, prop) * CACHE_ASSOC;

    DB (("prop ref: 0x%x,%s (%d) -> ", id, rep_STR (rep_SYM (prop)->name), h));

    for (i = h; i < h + CACHE_ASSOC; i++)
    {
	if (cache_ids[i] == id && cache_props[i] == prop)
	{
	    cache_hits++;
	    DB (("hit\n"));
	    cache_ages[i] = ++cache_clock;
	    return cache_values[i];
	}
    }

    DB (("miss\n"));
    cache_misses++;
    return rep_NULL;
}
开发者ID:baohaojun,项目名称:sawfish,代码行数:27,代码来源:property-cache.c

示例7: property_cache_invalidate

void
property_cache_invalidate (repv id, repv prop)
{
    unsigned int h, i;

    if (cache_vec == rep_NULL)
	return;

    h = CACHE_HASH (id, prop) * CACHE_ASSOC;

    for (i = h; i < h + CACHE_ASSOC; i++)
    {
	if (cache_ids[i] == id && cache_props[i] == prop)
	{
	    if (cache_updates[i] == 0)
	    {
		cache_ids[i] = 0;
		cache_props[i] = Qnil;
		cache_values[i] = Qnil;
	    }
	    else
		cache_updates[i]--;
	}
    }
}
开发者ID:baohaojun,项目名称:sawfish,代码行数:25,代码来源:property-cache.c

示例8: link_htab_ent

/* insert BLK onto the head of the hash table bucket chain in SET */
static void link_htab_ent(struct cache_t *cp, /* cache to update */
struct cache_set_t *set, /* set containing bkt chain */
struct cache_blk_t *blk) /* block to insert */
{
	int index = CACHE_HASH(cp, blk->tag);

	/* insert block onto the head of the bucket chain */
	blk->hash_next = set->hash[index];
	set->hash[index] = blk;
}
开发者ID:Evangileon,项目名称:SimpleScalar-Tournament,代码行数:11,代码来源:cache.c

示例9: property_cache_set

void
property_cache_set (repv id, repv prop, repv value, int invals)
{
    unsigned int h, i, oldest, oldest_age;

    if (cache_vec == rep_NULL)
    {
	cache_vec = Fmake_vector (rep_MAKE_INT (CACHE_SIZE * 3), Qnil);
	rep_mark_static (&cache_vec);

	cache_ids = rep_VECT (cache_vec)->array;
	cache_props = cache_ids + CACHE_SIZE;
	cache_values = cache_props + CACHE_SIZE;
    }

    h = CACHE_HASH (id, prop) * CACHE_ASSOC;

    oldest_age = UINT_MAX;
    oldest = -1;

    for (i = h; i < h + CACHE_ASSOC; i++)
    {
	if (cache_ids[i] == id && cache_props[i] == prop)
	{
	    cache_values[i] = value;
	    cache_updates[i] += invals;
	    return;
	}

	if (cache_ages[i] <= oldest_age)
	{
	    oldest_age = cache_ages[i];
	    oldest = i;
	}
    }

    assert (oldest != -1);

    if (cache_ids[oldest] != 0)
	DB (("prop eject: 0x%x (%d)\n", cache_ids[oldest], oldest));

    cache_ids[oldest] = id;
    cache_props[oldest] = prop;
    cache_values[oldest] = value;
    cache_ages[oldest] = ++cache_clock;
    cache_updates[oldest] = invals;

    DB (("set: 0x%x,%s (%d)\n", id, rep_STR (rep_SYM (prop)->name), oldest));
}
开发者ID:baohaojun,项目名称:sawfish,代码行数:49,代码来源:property-cache.c

示例10: lookup_cache

static inline rep_struct_node *
lookup_cache (rep_struct *s, repv var)
{
    unsigned int hash = CACHE_HASH (var);
    if (ref_cache[hash].s == s && ref_cache[hash].n->symbol == var)
    {
#ifdef DEBUG
	ref_cache_hits++;
#endif
	return ref_cache[hash].n;
    }
    else
    {
#ifdef DEBUG
	ref_cache_misses++;
#endif
	return 0;
    }
}
开发者ID:OpenInkpot-archive,项目名称:iplinux-librep,代码行数:19,代码来源:structures.c

示例11: allocated

/* access a cache, perform a CMD operation on cache CP at address ADDR,
   places NBYTES of data at *P, returns latency of operation if initiated
   at NOW, places pointer to block user data in *UDATA, *P is untouched if
   cache blocks are not allocated (!CP->BALLOC), UDATA should be NULL if no
   user data is attached to blocks */
unsigned int				/* latency of access in cycles */
cache_access(struct cache_t *cp,	/* cache to access */
	     enum mem_cmd cmd,		/* access type, Read or Write */
	     md_addr_t addr,		/* address of access */
	     void *vp,			/* ptr to buffer for input/output */
	     int nbytes,		/* number of bytes to access */
	     tick_t now,		/* time of access */
	     byte_t **udata,		/* for return of user data ptr */
	     md_addr_t *repl_addr,	/* for address of replaced block */
	     int prefetch)		/* 1 if the access is a prefetch, 0 if it is not */
{
  byte_t *p = vp;
  md_addr_t tag = CACHE_TAG(cp, addr);
  md_addr_t set = CACHE_SET(cp, addr);
  md_addr_t bofs = CACHE_BLK(cp, addr);
  struct cache_blk_t *blk, *repl;
  int lat = 0;

  /* default replacement address */
  if (repl_addr)
    *repl_addr = 0;

  /* check alignments */
  if ((nbytes & (nbytes-1)) != 0 || (addr & (nbytes-1)) != 0)
    fatal("cache: access error: bad size or alignment, addr 0x%08x", addr);

  /* access must fit in cache block */
  /* FIXME:
     ((addr + (nbytes - 1)) > ((addr & ~cp->blk_mask) + (cp->bsize - 1))) */
  if ((addr + nbytes) > ((addr & ~cp->blk_mask) + cp->bsize))
    fatal("cache: access error: access spans block, addr 0x%08x", addr);

  /* permissions are checked on cache misses */

  /* check for a fast hit: access to same block */
  if (CACHE_TAGSET(cp, addr) == cp->last_tagset)
    {
      /* hit in the same block */
      blk = cp->last_blk;
      goto cache_fast_hit;
    }
    
  if (cp->hsize)
    {
      /* higly-associativity cache, access through the per-set hash tables */
      int hindex = CACHE_HASH(cp, tag);

      for (blk=cp->sets[set].hash[hindex];
	   blk;
	   blk=blk->hash_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    goto cache_hit;
	}
    }
  else
    {
      /* low-associativity cache, linear search the way list */
      for (blk=cp->sets[set].way_head;
	   blk;
	   blk=blk->way_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    goto cache_hit;
	}
    }

  /* cache block not found */

  /* **MISS** */
  if (prefetch == 0 ) {

     cp->misses++;

     if (cmd == Read) {	
	cp->read_misses++;
     }
  }

  /* ECE552 Assignment 4 - BEGIN CODE */
  if (strcmp(cp->name, "dl1") == 0) {
    for(std::list<evicted_tag>::iterator it = evicted_blks[set].begin(); it != evicted_blks[set].end(); ++it)
    {
       if(it->tag == tag && it->prefetched) {
         //move element to the front of the list
         if(it != evicted_blks[set].begin()) {
           std::list<evicted_tag>::iterator tmp = it; 
           evicted_blks[set].splice(evicted_blks[set].begin(), evicted_blks[set], tmp, ++it);
         }
         cp->prefetch_misses++;
         break;
       }
    }
  }
  /* ECE552 Assignment 4 - END CODE */
//.........这里部分代码省略.........
开发者ID:swlpark,项目名称:ece552,代码行数:101,代码来源:cache.cpp

示例12: allocated

/* access a cache, perform a CMD operation on cache CP at address ADDR,
   places NBYTES of data at *P, returns latency of operation if initiated
   at NOW, places pointer to block user data in *UDATA, *P is untouched if
   cache blocks are not allocated (!CP->BALLOC), UDATA should be NULL if no
   user data is attached to blocks */
unsigned int				/* latency of access in cycles */
cache_access(struct cache_t *cp,	/* cache to access */
	     enum mem_cmd cmd,		/* access type, Read or Write */
	     md_addr_t addr,		/* address of access */
	     void *vp,			/* ptr to buffer for input/output */
	     int nbytes,		/* number of bytes to access */
	     tick_t now,		/* time of access */
	     byte_t **udata,		/* for return of user data ptr */
	     md_addr_t *repl_addr)	/* for address of replaced block */
{
  byte_t *p = vp;
  md_addr_t tag = CACHE_TAG(cp, addr);
  md_addr_t set = CACHE_SET(cp, addr);
  md_addr_t bofs = CACHE_BLK(cp, addr);
  struct cache_blk_t *blk, *repl;
  int lat = 0;

  if(cp->isL2){
    if(set > 512){
      fprintf(stderr, "Houston we have a problem, set = %d\n", set);
      scanf("%d", &lat);
    }
  }

  int pointerLat = 0;

  /* default replacement address */
  if (repl_addr)
    *repl_addr = 0;

  /* check alignments */
  if ((nbytes & (nbytes-1)) != 0 || (addr & (nbytes-1)) != 0)
    fatal("cache: access error: bad size or alignment, addr 0x%08x", addr);

  /* access must fit in cache block */
  /* FIXME:
     ((addr + (nbytes - 1)) > ((addr & ~cp->blk_mask) + (cp->bsize - 1))) */
  if ((addr + nbytes) > ((addr & ~cp->blk_mask) + cp->bsize))
    fatal("cache: access error: access spans block, addr 0x%08x", addr);

  /* permissions are checked on cache misses */

  /* check for a fast hit: access to same block */
  if (CACHE_TAGSET(cp, addr) == cp->last_tagset)
    {
      /* hit in the same block */
      blk = cp->last_blk;
      goto cache_fast_hit;
    }



  /*FP-JS Loc will store the last line traversed through the list
  I want to keep set so I know where the head of the list is for replacement
  */
  unsigned int loc = set; 
  /*FP-BC Modified cache hit checker for new cache structure*/
  if(cp->isL2)
  {
       /*FP-BC continue through each linked set with data*/
       while(cp->sets[loc].usageCtr)
       {

      //if(cp->isL2)
      //fprintf(stderr, "ptr = %d, loc = %d", cp->sets[loc].fwdPtr, loc);
          if (cp->hsize)
          {
              /* higly-associativity cache, access through the per-set hash tables */
              int hindex = CACHE_HASH(cp, tag);

              for (blk=cp->sets[loc].hash[hindex]; blk; blk=blk->hash_next)
              {
                  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID)){
                    //fprintf(stderr, "Hit!");
                    goto cache_hit;
                  }
              }
          }

          else
          {
              /* low-associativity cache, linear search the way list */
              for (blk=cp->sets[loc].way_head; blk; blk=blk->way_next)
              {
                  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID)){
                       //                 fprintf(stderr, "Hit!");
                    goto cache_hit;
                  }
              }
          }

          /*FP-BC If the current set has a pointer to another set,
            follow it and check again for a hit*/
          if(cp->sets[loc].fwdPtr){
            loc = cp->sets[loc].fwdPtr;
//.........这里部分代码省略.........
开发者ID:jsarabia1247,项目名称:waylevelcache,代码行数:101,代码来源:cache.c

示例13: fetch_cache_blk

/* ECE552 Assignment 4 - BEGIN CODE */
void fetch_cache_blk (struct cache_t *cp, md_addr_t addr) {
  md_addr_t tag = CACHE_TAG(cp, addr);
  md_addr_t set = CACHE_SET(cp, addr);
  md_addr_t bofs = CACHE_BLK(cp, addr);

  int lat = 0;
  struct cache_blk_t *blk, *repl;

  //check if the block already exists in cache
  if (cp->hsize) {
      /* higly-associativity cache, access through the per-set hash tables */
      int hindex = CACHE_HASH(cp, tag);

      for (blk=cp->sets[set].hash[hindex]; blk; blk=blk->hash_next){
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    return;
      }
  } else {
      /* low-associativity cache, linear search the way list */
      for (blk=cp->sets[set].way_head; blk; blk=blk->way_next) {
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    return;
      }
  }
  switch (cp->policy) {
  case LRU:
  case FIFO:
    repl = cp->sets[set].way_tail;
    update_way_list(&cp->sets[set], repl, Head);
    break;
  case Random:
    {
      int bindex = myrand() & (cp->assoc - 1);
      repl = CACHE_BINDEX(cp, cp->sets[set].blks, bindex);
    }
    break;
  default:
    panic("bogus replacement policy");
  }

  /* remove this block from the hash bucket chain, if hash exists */
  if (cp->hsize)
    unlink_htab_ent(cp, &cp->sets[set], repl);

  /* evicted cache_blk */
  if (evicted_blks[set].size() < cp->assoc) {
     evicted_blks[set].push_front({true, repl->tag});
  } else {
     evicted_blks[set].pop_back();
     evicted_blks[set].push_front({true, repl->tag});
  }

  /* write back replaced block data */
  if (repl->status & CACHE_BLK_VALID) {
      cp->replacements++;
      if (repl->status & CACHE_BLK_DIRTY)
      {
        /* write back the cache block */
        cp->writebacks++;
        lat += cp->blk_access_fn(Write,
      			   CACHE_MK_BADDR(cp, repl->tag, set),
      			   cp->bsize, repl, 0, 0);
      }
  }
  /* update block tags */
  repl->tag = tag;
  repl->status = CACHE_BLK_VALID;	/* dirty bit set on update */
  repl->prefetched = 1;
  repl->prefetch_used = 0;

  /* read data block */
  cp->prefetch_cnt += 1;
  lat += cp->blk_access_fn(Read, CACHE_BADDR(cp, addr), cp->bsize,
			   repl, NULL, 0);

  /* update block status */
  repl->ready = NULL;

  /* link this entry back into the hash table */
  if (cp->hsize)
     link_htab_ent(cp, &cp->sets[set], repl);

}
开发者ID:swlpark,项目名称:ece552,代码行数:84,代码来源:cache.cpp

示例14: allocated

/* access a cache, perform a CMD operation on cache CP at address ADDR,
   places NBYTES of data at *P, returns latency of operation if initiated
   at NOW, places pointer to block user data in *UDATA, *P is untouched if
   cache blocks are not allocated (!CP->BALLOC), UDATA should be NULL if no
   user data is attached to blocks */
unsigned int				/* latency of access in cycles */
cache_access(struct cache_t *cp,	/* cache to access */
	     enum mem_cmd cmd,		/* access type, Read or Write */
	     md_addr_t addr,		/* address of access */
	     void *vp,			/* ptr to buffer for input/output */
	     int nbytes,		/* number of bytes to access */
	     tick_t now,		/* time of access */
	     byte_t **udata,		/* for return of user data ptr */
	     md_addr_t *repl_addr)	/* for address of replaced block */
{
  byte_t *p = vp;
  md_addr_t tag = CACHE_TAG(cp, addr);
  md_addr_t set = CACHE_SET(cp, addr);
  md_addr_t bofs = CACHE_BLK(cp, addr);

  struct cache_blk_t *blk, *repl;
  struct pdp_fifo_node *fnode, *tnode;
  int lat = 0;

  /* default replacement address */
  if (repl_addr)
    *repl_addr = 0;

  /* check alignments */
  if ((nbytes & (nbytes-1)) != 0 || (addr & (nbytes-1)) != 0)
    fatal("cache: access error: bad size or alignment, addr 0x%08x", addr);

  /* access must fit in cache block */
  /* FIXME:
     ((addr + (nbytes - 1)) > ((addr & ~cp->blk_mask) + (cp->bsize - 1))) */
  if ((addr + nbytes) > ((addr & ~cp->blk_mask) + cp->bsize))
    fatal("cache: access error: access spans block, addr 0x%08x", addr);

  /* permissions are checked on cache misses */

  /* PDP distance decrement on set access */
  if(cp->policy == PDP){
    for (blk=cp->sets[set].way_head;
      blk;
      blk=blk->way_next)
    {
      if (blk->rpd > 0) blk->rpd--;
    }
    /* PDP counter update */
    cp->PDP_Nt++;
    if((cp->PDP_Nt % 50000) == 0) compute_pd(cp);
  }

  /* check for a fast hit: access to same block */
  if (CACHE_TAGSET(cp, addr) == cp->last_tagset)
    {
      /* hit in the same block */
      blk = cp->last_blk;
      goto cache_fast_hit;
    }
    
  if (cp->hsize)
    {
      /* higly-associativity cache, access through the per-set hash tables */
      int hindex = CACHE_HASH(cp, tag);

      for (blk=cp->sets[set].hash[hindex];
	   blk;
	   blk=blk->hash_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    goto cache_hit;
	}
    }
  else
    {
      /* low-associativity cache, linear search the way list */
      for (blk=cp->sets[set].way_head;
	   blk;
	   blk=blk->way_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    goto cache_hit;
	}
    }

  /* cache block not found */

  /* **MISS** */
  cp->misses++;

  /* select the appropriate block to replace, and re-link this entry to
     the appropriate place in the way list */
  switch (cp->policy) {
  case LRU:
  case FIFO:
    repl = cp->sets[set].way_tail;
    update_way_list(&cp->sets[set], repl, Head);
    break;
  case Random:
//.........这里部分代码省略.........
开发者ID:kuthulas,项目名称:PDP,代码行数:101,代码来源:cache.c

示例15: allocated

/* access a cache, perform a CMD operation on cache CP at address ADDR,
   places NBYTES of data at *P, returns latency of operation if initiated
   at NOW, places pointer to block user data in *UDATA, *P is untouched if
   cache blocks are not allocated (!CP->BALLOC), UDATA should be NULL if no
   user data is attached to blocks */
unsigned int				/* latency of access in cycles */
cache_access(struct cache_t *cp,	/* cache to access */
	     enum mem_cmd cmd,		/* access type, Read or Write */
	     md_addr_t addr,		/* address of access */
	     void *vp,			/* ptr to buffer for input/output */
	     int nbytes,		/* number of bytes to access */
	     tick_t now,		/* time of access */
	     byte_t **udata,		/* for return of user data ptr */
	     md_addr_t *repl_addr)	/* for address of replaced block */
{
  byte_t *p = vp;
  md_addr_t tag = CACHE_TAG(cp, addr);
  md_addr_t set = CACHE_SET(cp, addr);
  md_addr_t bofs = CACHE_BLK(cp, addr);
  struct cache_blk_t *blk, *repl;
  int lat = 0;

  /* default replacement address */
  if (repl_addr)
    *repl_addr = 0;

  /* check alignments */
  if ((nbytes & (nbytes-1)) != 0 || (addr & (nbytes-1)) != 0)
    fatal("cache: access error: bad size or alignment, addr 0x%08x", addr);

  /* access must fit in cache block */
  /* FIXME:
     ((addr + (nbytes - 1)) > ((addr & ~cp->blk_mask) + (cp->bsize - 1))) */
  if ((addr + nbytes) > ((addr & ~cp->blk_mask) + cp->bsize))
    fatal("cache: access error: access spans block, addr 0x%08x", addr);

  /* permissions are checked on cache misses */

  /* check for a fast hit: access to same block */
  if (CACHE_TAGSET(cp, addr) == cp->last_tagset)
    {
      /* hit in the same block */
      blk = cp->last_blk;
      goto cache_fast_hit;
    }
    
  if (cp->hsize)
    {
      /* higly-associativity cache, access through the per-set hash tables */
      int hindex = CACHE_HASH(cp, tag);

      for (blk=cp->sets[set].hash[hindex];
	   blk;
	   blk=blk->hash_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    goto cache_hit;
	}
    }
  else
    {
      /* low-associativity cache, linear search the way list */
      for (blk=cp->sets[set].way_head;
	   blk;
	   blk=blk->way_next)
	{
	  if (blk->tag == tag && (blk->status & CACHE_BLK_VALID))
	    goto cache_hit;
	}
    }

  /* cache block not found */

  /* **MISS** */
  cp->misses++;

  /* select the appropriate block to replace, and re-link this entry to
     the appropriate place in the way list */
  switch (cp->policy) {
  case LRU:
  case FIFO:
    repl = cp->sets[set].way_tail;
    update_way_list(&cp->sets[set], repl, Head);
    break;
	case DIP:
		repl = cp->sets[set].way_tail;
		enum list_loc_t where;		/* insert location */
		if ( cp->sets[set].DIP_set_type == LRU_set ) {
			where = Head;
			// update PSEL to bias BIP
			int max_PSEL = 1 << cp->width_PSEL - 1;
			if ( cp->PSEL < max_PSEL ) {
				cp->PSEL ++;
			}
		}
		else if ( cp->sets[set].DIP_set_type == BIP_set ) {
			if ( cp->BIPCTR == 0 ) {
				// use LRU policy, MRU insertion
				where = Head;
			}
//.........这里部分代码省略.........
开发者ID:tharun-b,项目名称:sim-outorder_DIP-cache,代码行数:101,代码来源:cache.c


注:本文中的CACHE_HASH函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。