BENCH.C 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. // Benchmarking tool
  2. #define word char
  3. #include "LIB/MATH.C"
  4. #include "LIB/STDLIB.C"
  5. #include "LIB/SYS.C"
  6. #define N 256 // Decimals of pi to compute.
  7. #define LEN 854 // (10*N) / 3 + 1
  8. #define TMPMEM_LOCATION 0x440000
  9. word frameCount = 0;
  10. //word a[LEN];
  11. word *a = (char*) TMPMEM_LOCATION;
  12. void spigotPiBench()
  13. {
  14. frameCount = 0;
  15. while (frameCount == 0); // wait until next frame to start
  16. frameCount = 0;
  17. word j = 0;
  18. word predigit = 0;
  19. word nines = 0;
  20. word x = 0;
  21. word q = 0;
  22. word k = 0;
  23. word len = 0;
  24. word i = 0;
  25. word y = 0;
  26. for(j=N; j; )
  27. {
  28. q = 0;
  29. k = LEN+LEN-1;
  30. for(i=LEN; i; --i)
  31. {
  32. if (j == N)
  33. {
  34. x = 20 + q*i;
  35. }
  36. else
  37. {
  38. x = (10*a[i-1]) + q*i;
  39. }
  40. q = MATH_div(x, k);
  41. a[i-1] = (x-q*k);
  42. k -= 2;
  43. }
  44. k = MATH_mod(x, 10);
  45. if (k==9)
  46. {
  47. ++nines;
  48. }
  49. else
  50. {
  51. if (j)
  52. {
  53. --j;
  54. y = predigit+MATH_div(x,10);
  55. BDOS_PrintDecConsole(y);
  56. }
  57. for(; nines; --nines)
  58. {
  59. if (j)
  60. {
  61. --j;
  62. if (x >= 10)
  63. {
  64. BDOS_PrintcConsole('0');
  65. }
  66. else
  67. {
  68. BDOS_PrintcConsole('9');
  69. }
  70. }
  71. }
  72. predigit = k;
  73. }
  74. }
  75. BDOS_PrintConsole("\nPiBench256 took ");
  76. BDOS_PrintDecConsole(frameCount);
  77. BDOS_PrintConsole(" frames\n");
  78. }
  79. // LoopBench: a simple increase and loop bench for a set amount of time.
  80. // reads framecount from memory in the loop.
  81. // no pipeline clears within the loop.
  82. int loopBench()
  83. {
  84. word retval = 0;
  85. asm(
  86. "push r1\npush r2\npush r3\npush r4\n"
  87. "addr2reg frameCount r2\n"
  88. "write 0 r2 r0 ; reset frameCount\n"
  89. "load 0 r4 ; score\n"
  90. "Label_ASM_Loop:\n"
  91. "read 0 r2 r3 ; read frameCount\n"
  92. "slt r3 300 r3 ; TESTDURATION here in frames\n"
  93. "beq r3 r0 3 ; check if done \n"
  94. "add r4 1 r4 ; increase score and loop\n"
  95. "jump Label_ASM_Loop\n"
  96. "jump Label_ASM_Done\n"
  97. "Label_ASM_Done:\n"
  98. "or r4 r0 r2 ; set return value\n"
  99. "write -4 r14 r2 ; write to stack to return\n"
  100. "pop r4\npop r3\npop r2\npop r1\n"
  101. );
  102. return retval;
  103. }
  104. // CountMillionBench: how many frames it takes to do a C for loop to a million
  105. int countMillionBench()
  106. {
  107. frameCount = 0;
  108. while (frameCount == 0); // wait until next frame to start
  109. frameCount = 0;
  110. int i;
  111. for (i = 0; i < 1000000; i++);
  112. return frameCount;
  113. }
  114. int main()
  115. {
  116. BDOS_PrintlnConsole("---------------FPGCbench---------------\n");
  117. BDOS_PrintConsole("LoopBench: ");
  118. frameCount = 0;
  119. while (frameCount == 0); // wait until next frame to start
  120. BDOS_PrintDecConsole(loopBench());
  121. BDOS_PrintcConsole('\n');
  122. BDOS_PrintConsole("CountMillionBench: ");
  123. BDOS_PrintDecConsole(countMillionBench());
  124. BDOS_PrintConsole(" frames\n");
  125. BDOS_PrintConsole("PiBench256:\n");
  126. spigotPiBench();
  127. return 'q';
  128. }
  129. void interrupt()
  130. {
  131. // handle all interrupts
  132. word i = getIntID();
  133. switch(i)
  134. {
  135. case INTID_TIMER1:
  136. timer1Value = 1; // notify ending of timer1
  137. break;
  138. case INTID_TIMER2:
  139. break;
  140. case INTID_UART0:
  141. break;
  142. case INTID_GPU:
  143. frameCount++;
  144. break;
  145. case INTID_TIMER3:
  146. break;
  147. case INTID_PS2:
  148. break;
  149. case INTID_UART1:
  150. break;
  151. case INTID_UART2:
  152. break;
  153. }
  154. }