fork download
  1. #include <stdio.h>
  2.  
  3. #define OBTER_ULTIMOS_BITS(x, k) ((x) & ((1 << (k)) - 1))
  4. #define DESCARTAR_ULTIMOS_BITS(x, k) ((x) >> (k))
  5.  
  6. typedef struct CACHE {
  7. unsigned int lineSize;
  8. unsigned int associativity;
  9. unsigned int numLines;
  10. } CACHE;
  11.  
  12. /*unsigned int log2(unsigned int x) {
  13.   unsigned long long int resultado = 0;
  14.   while (x >>= 1) resultado++;
  15.   return resultado;
  16. }*/
  17.  
  18. int main(void) {
  19. unsigned long long int address = 0x123456789ABCDEFLL;
  20. CACHE cacheconfig;
  21. cacheconfig.lineSize = 20;
  22. cacheconfig.numLines = 200;
  23. cacheconfig.associativity = 4;
  24.  
  25. unsigned int a = log2(cacheconfig.numLines / cacheconfig.associativity);
  26. unsigned int b = log2(cacheconfig.lineSize);
  27. long unsigned int Tag = DESCARTAR_ULTIMOS_BITS(OBTER_ULTIMOS_BITS(address, cacheconfig.lineSize), b);
  28. long unsigned int Index = DESCARTAR_ULTIMOS_BITS(OBTER_ULTIMOS_BITS(address, b + a), b);
  29. long unsigned int Dado = OBTER_ULTIMOS_BITS(address, b);
  30.  
  31. printf("%lu,%lu,%lu", Tag, Index, Dado);
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
48350,30,15