--- cg_sim.c-save 2006-08-28 06:38:38.000000000 -0700 +++ cg_sim.c 2006-11-06 23:04:57.000000000 -0800 @@ -42,29 +42,33 @@ Int size; /* bytes */ Int assoc; Int line_size; /* bytes */ - Int sets; Int sets_min_1; Int assoc_bits; Int line_size_bits; Int tag_shift; - Char desc_line[128]; UWord* tags; -} cache_t2; + Char desc_line[128]; +} cache_t2 +#ifdef __GNUC__ +__attribute__ ((aligned (8 * sizeof (Int)))) +#endif +; /* By this point, the size/assoc/line_size has been checked. */ static void cachesim_initcache(cache_t config, cache_t2* c) { Int i; + Int sets; c->size = config.size; c->assoc = config.assoc; c->line_size = config.line_size; - c->sets = (c->size / c->line_size) / c->assoc; - c->sets_min_1 = c->sets - 1; + sets = (c->size / c->line_size) / c->assoc; + c->sets_min_1 = sets - 1; c->assoc_bits = VG_(log2)(c->assoc); c->line_size_bits = VG_(log2)(c->line_size); - c->tag_shift = c->line_size_bits + VG_(log2)(c->sets); + c->tag_shift = c->line_size_bits + VG_(log2)(sets); if (c->assoc == 1) { VG_(sprintf)(c->desc_line, "%d B, %d B, direct-mapped", @@ -74,9 +78,9 @@ c->size, c->line_size, c->assoc); } - c->tags = VG_(malloc)(sizeof(UWord) * c->sets * c->assoc); + c->tags = VG_(malloc)(sizeof(UWord) * sets * c->assoc); - for (i = 0; i < c->sets * c->assoc; i++) + for (i = 0; i < sets * c->assoc; i++) c->tags[i] = 0; } @@ -86,7 +90,7 @@ UInt set, way, i; /* Note initialisation and update of 'i'. */ - for (i = 0, set = 0; set < c->sets; set++) { + for (i = 0, set = 0; set <= c->sets_min_1; set++) { for (way = 0; way < c->assoc; way++, i++) { VG_(printf)("%16lx ", c->tags[i]); } @@ -154,8 +158,7 @@ return; \ \ /* Second case: word straddles two lines. */ \ - /* Nb: this is a fast way of doing ((set1+1) % L.sets) */ \ - } else if (((set1 + 1) & (L.sets-1)) == set2) { \ + } else if (((set1 + 1) & (L.sets_min_1)) == set2) { \ set = &(L.tags[set1 << L.assoc_bits]); \ if (tag == set[0]) { \ goto block2; \ @@ -176,6 +179,8 @@ is_miss = True; \ block2: \ set = &(L.tags[set2 << L.assoc_bits]); \ + if (set2 == 0) \ + ++tag; \ if (tag == set[0]) { \ goto miss_treatment; \ } \