Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "CacheSim.h"
- #define true 1
- #defien false 0
- /* Posa aqui les teves estructures de dades globals
- * per mantenir la informacio necesaria de la cache
- * */
- const int cacheSize = 128;
- const int bytes = 5;
- const int lines = 7;
- const int tag = 20;
- int cache[cacheSize];
- int valid[cacheSize];
- /* La rutina init_cache es cridada pel programa principal per
- * inicialitzar la cache.
- * La cache es inicialitzada al començar cada un dels tests.
- * */
- void init_cache ()
- {
- /* Escriu aqui el teu codi */
- malloc(cache,0,sizeof cache);
- malloc(valid,0,sizeof valid);
- }
- /* La rutina reference es cridada per cada referencia a simular */
- void reference (unsigned int address, unsigned int LE)
- {
- unsigned int byte;
- unsigned int linea_mp;
- unsigned int linea_mc;
- unsigned int tag;
- unsigned int miss;
- unsigned int lec_mp;
- unsigned int mida_lec_mp;
- unsigned int esc_mp;
- unsigned int mida_esc_mp;
- unsigned int replacement;
- unsigned int tag_out;
- /* Escriu aqui el teu codi */
- byte = address&((1<<bytes)-1);
- linea_mp = address>>bytes;
- linea_mc = (address&((1<<(bytes+lines))-1))>>bytes;
- tag = address>>(bytes+lines);
- if (LE == 1) //lectura
- {
- if (!v[tag] || cache[tag] != tag)
- {
- miss = true;
- lec_mp = true;
- mida_lec_mp = 4; //lectura int
- esc_mp = false;
- mida_esc_mp = 0;
- if (v[tag])
- tag_out = cache[tag];
- else
- tag_out = 0;
- v[tag] = true;
- cache[tag] = tag;
- replacement = tag;
- }
- else
- {
- miss = false;
- lec_mp = false;
- mida_lec_mp = 0; //lectura int
- esc_mp = false;
- mida_esc_mp = 0;
- tag_out = 0;
- replacement = 0;
- }
- }
- else //esriptura
- {
- if (!v[tag] || cache[tag] != tag)
- miss = true;
- miss = false;
- lec_mp = false;
- mida_lec_mp = 0;
- esc_mp = true;
- mida_esc_mp = 4; //escriptura int
- tag_out = 0;
- replacement = 0;
- }
- /* La funcio test_and_print escriu el resultat de la teva simulacio
- * per pantalla (si s'escau) i comproba si hi ha algun error
- * per la referencia actual
- * */
- test_and_print (address, LE, byte, linea_mp, linea_mc, tag,
- miss, lec_mp, mida_lec_mp, esc_mp, mida_esc_mp,
- replacement, tag_out);
- }
- /* La rutina final es cridada al final de la simulacio */
- void final ()
- {
- /* Escriu aqui el teu codi */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement