这是一个本人学习 csapp 的 learning 库
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

83 líneas
2.1 KiB

  1. /*
  2. * cachelab.c - Cache Lab helper functions
  3. */
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <assert.h>
  7. #include "cachelab.h"
  8. #include <time.h>
  9. trans_func_t func_list[MAX_TRANS_FUNCS];
  10. int func_counter = 0;
  11. /*
  12. * printSummary - Summarize the cache simulation statistics. Student cache simulators
  13. * must call this function in order to be properly autograded.
  14. */
  15. void printSummary(int hits, int misses, int evictions)
  16. {
  17. printf("hits:%d misses:%d evictions:%d\n", hits, misses, evictions);
  18. FILE* output_fp = fopen(".csim_results", "w");
  19. assert(output_fp);
  20. fprintf(output_fp, "%d %d %d\n", hits, misses, evictions);
  21. fclose(output_fp);
  22. }
  23. /*
  24. * initMatrix - Initialize the given matrix
  25. */
  26. void initMatrix(int M, int N, int A[N][M], int B[M][N])
  27. {
  28. int i, j;
  29. srand(time(NULL));
  30. for (i = 0; i < N; i++){
  31. for (j = 0; j < M; j++){
  32. // A[i][j] = i+j; /* The matrix created this way is symmetric */
  33. A[i][j]=rand();
  34. B[j][i]=rand();
  35. }
  36. }
  37. }
  38. void randMatrix(int M, int N, int A[N][M]) {
  39. int i, j;
  40. srand(time(NULL));
  41. for (i = 0; i < N; i++){
  42. for (j = 0; j < M; j++){
  43. // A[i][j] = i+j; /* The matrix created this way is symmetric */
  44. A[i][j]=rand();
  45. }
  46. }
  47. }
  48. /*
  49. * correctTrans - baseline transpose function used to evaluate correctness
  50. */
  51. void correctTrans(int M, int N, int A[N][M], int B[M][N])
  52. {
  53. int i, j, tmp;
  54. for (i = 0; i < N; i++){
  55. for (j = 0; j < M; j++){
  56. tmp = A[i][j];
  57. B[j][i] = tmp;
  58. }
  59. }
  60. }
  61. /*
  62. * registerTransFunction - Add the given trans function into your list
  63. * of functions to be tested
  64. */
  65. void registerTransFunction(void (*trans)(int M, int N, int[N][M], int[M][N]),
  66. char* desc)
  67. {
  68. func_list[func_counter].func_ptr = trans;
  69. func_list[func_counter].description = desc;
  70. func_list[func_counter].correct = 0;
  71. func_list[func_counter].num_hits = 0;
  72. func_list[func_counter].num_misses = 0;
  73. func_list[func_counter].num_evictions =0;
  74. func_counter++;
  75. }