G
globalsk
Hello,
I'm trying to understand this fragment of code in Simplescalar's
cache.h code (I've search and look over dozens sites, including
simplescalar.com and there's no help about the coding):
/* cache access macros */
#define CACHE_TAG(cp, addr) ((addr) >> (cp)->tag_shift)
#define CACHE_SET(cp, addr) (((addr) >> (cp)->set_shift) &
(cp)->set_mask)
#define CACHE_BLK(cp, addr) ((addr) & (cp)->blk_mask)
#define CACHE_TAGSET(cp, addr) ((addr) & (cp)->tagset_mask)
I know is about shifting and moving bits around, but don't know how and
specially why is done in this way and for what.
cp is an structure for a cache
addr is a typedef qword_t (64 bits)
md_addr_t blk_mask; idem, typedef qword_t
int set_shift;
md_addr_t set_mask; /* use *after* shift */
int tag_shift;
md_addr_t tag_mask; /* use *after* shift */
md_addr_t tagset_mask; /* used for fast hit detection */
Maybe this is little information, but maybe someone with the knowledge
about caches and this type of coding can help out. Please if someone
can give a helping hand about this and links where they explain in more
detail simplescalar's code will be very appreciated.
Please forgive my syntax mistakes, english is not my mother tongue.
I'm trying to understand this fragment of code in Simplescalar's
cache.h code (I've search and look over dozens sites, including
simplescalar.com and there's no help about the coding):
/* cache access macros */
#define CACHE_TAG(cp, addr) ((addr) >> (cp)->tag_shift)
#define CACHE_SET(cp, addr) (((addr) >> (cp)->set_shift) &
(cp)->set_mask)
#define CACHE_BLK(cp, addr) ((addr) & (cp)->blk_mask)
#define CACHE_TAGSET(cp, addr) ((addr) & (cp)->tagset_mask)
I know is about shifting and moving bits around, but don't know how and
specially why is done in this way and for what.
cp is an structure for a cache
addr is a typedef qword_t (64 bits)
md_addr_t blk_mask; idem, typedef qword_t
int set_shift;
md_addr_t set_mask; /* use *after* shift */
int tag_shift;
md_addr_t tag_mask; /* use *after* shift */
md_addr_t tagset_mask; /* used for fast hit detection */
Maybe this is little information, but maybe someone with the knowledge
about caches and this type of coding can help out. Please if someone
can give a helping hand about this and links where they explain in more
detail simplescalar's code will be very appreciated.
Please forgive my syntax mistakes, english is not my mother tongue.