I am studying Tom Forsyth Linear-Speed Vertex Cache Optimization, and I do not understand how it calculates ACMR. From what I read, I already know that ACMR = the number of misses in the cache / the number of triangles, but I do not understand what type of cache is used (i.e. FIFO or LRU?).
I wrote a test program that calculates and prints the ACMR of a given 3d model using the FIFO cache, can you tell me if this code is ok? or should I use LRU cache instead?
#define FIFO_CACHE_SIZE 32
struct fifo_cache {
long entries[FIFO_CACHE_SIZE];
};
static void init_cache(struct fifo_cache *cache)
{
int i = 0;
for (i = 0;i < FIFO_CACHE_SIZE;i++)
cache->entries[i] = -1;
}
static int check_entry(const struct fifo_cache *cache, u16 entry)
{
int i = 0;
for (i = 0;i < FIFO_CACHE_SIZE;i++) {
if (cache->entries[i] == (long)entry)
return 1;
}
return 0;
}
static void add_entry(struct fifo_cache *cache, u16 entry)
{
long aux = 0;
long aux2 = 0;
int i = 0;
aux = cache->entries[0];
cache->entries[0] = (long)entry;
for (i = 1;i < FIFO_CACHE_SIZE;i++) {
aux2 = cache->entries[i];
cache->entries[i] = aux;
aux = aux2;
}
}
float calculate_acmr(const u16 *indices, size_t count)
{
struct fifo_cache cache = {0};
long total = 0;
long i = 0;
init_cache(&cache);
for (i = 0;i < count;i++) {
if (!check_entry(&cache, indices[i])) {
add_entry(&cache, indices[i]);
total++;
}
}
return ((float)total / (count / 3));
}
source
share