这是一个本人学习 csapp 的 learning 库
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
879 B

  1. //
  2. // Created by GentleCold on 2022/11/7.
  3. //
  4. #ifndef CSAPPLEARNING_MOUNTAIN_H
  5. #define CSAPPLEARNING_MOUNTAIN_H
  6. #include <stdio.h>
  7. #define MAXELEMS 10000
  8. long data[MAXELEMS];
  9. int read(int elems, int stride) {
  10. long i, sx2 = stride * 2, sx3 = stride * 3, sx4 = stride * 4;
  11. long acc0 = 0, acc1 = 0, acc2 = 0, acc3 = 0;
  12. long length = elems;
  13. long limit = length - sx4;
  14. for (i = 0; i < limit; i += sx4) {
  15. acc0 += data[i];
  16. acc1 += data[i + stride];
  17. acc2 += data[i + sx2];
  18. acc3 += data[i + sx3];
  19. }
  20. for (; i < length; i += stride) {
  21. acc0 += data[i];
  22. }
  23. return ((acc0 + acc1) + (acc2 + acc3));
  24. }
  25. double run(int size, int stride, double Mhz) {
  26. double cycles;
  27. int elems = size / sizeof(double);
  28. read(elems, stride);
  29. cycles = fcyc2();
  30. }
  31. int mountain() {
  32. }
  33. #endif //CSAPPLEARNING_MOUNTAIN_H