perf.asm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. ;/***********************************************\
  2. ;??? perf.asm
  3. ;\***********************************************/
  4. .586
  5. .MODEL flat, SYSCALL, os_dos
  6. .CODE
  7. IDEAL
  8. NAME tsc
  9. MASM
  10. PUBLIC DUCK_sti_
  11. PUBLIC _DUCK_sti
  12. PUBLIC DUCK_cli_
  13. PUBLIC _DUCK_cli
  14. PUBLIC rdtsc_Start_
  15. PUBLIC _rdtsc_Start
  16. PUBLIC rdtsc_End_
  17. PUBLIC _rdtsc_End
  18. PUBLIC addTSC_
  19. PUBLIC _addTSC
  20. ; typedef struct tsc_cnt {
  21. ; unsigned long low;
  22. ; unsigned long high;
  23. ; } *TSC_HANDLE, TSC;
  24. DUCK_sti_:
  25. _DUCK_sti:
  26. sti
  27. ret
  28. DUCK_cli_:
  29. _DUCK_cli:
  30. cli
  31. ret
  32. ;------------------------------------------------
  33. ; void rdtsc_Start(low, high)
  34. ;
  35. rdtsc_StartParams STRUC
  36. dd 3 dup (?) ;3 pushed regs
  37. dd ? ;return address
  38. low dd ?
  39. high dd ?
  40. rdtsc_StartParams ENDS
  41. ;------------------------------------------------
  42. rdtsc_Start_:
  43. _rdtsc_Start:
  44. push ebx
  45. push ecx
  46. push edx
  47. nop
  48. mov ebx,[esp].low ;pointer to low
  49. mov ecx,[esp].high ;pointer to high
  50. ; RDTSC
  51. db 0fh, 31h
  52. mov [ebx],eax ;return values
  53. mov [ecx],edx
  54. nop
  55. pop edx
  56. pop ecx
  57. pop ebx
  58. ret
  59. ;------------------------------------------------
  60. ; void rdtsc_End(unsigned long *)
  61. ;
  62. rdtsc_EndParams STRUC
  63. dd 6 dup (?) ;6 pushed regs
  64. dd ? ;return address
  65. elow dd ?
  66. ehigh dd ?
  67. rdtsc_EndParams ENDS
  68. ;------------------------------------------------
  69. rdtsc_End_:
  70. _rdtsc_End:
  71. push esi
  72. push edi
  73. push ebp
  74. push ebx
  75. push ecx
  76. push edx
  77. mov edi,[esp].elow ;pointer to low var
  78. mov esi,[esp].ehigh ;pointer to high var
  79. ; RDTSC
  80. db 0fh, 31h
  81. mov ebx,[edi] ;get start values
  82. mov ecx,[esi]
  83. sub eax,ebx
  84. sbb edx,ecx
  85. mov [edi],eax ;return values
  86. mov [esi],edx
  87. pop edx
  88. pop ecx
  89. pop ebx
  90. pop ebp
  91. pop edi
  92. pop esi
  93. ret
  94. ;------------------------------------------------
  95. ; adds time stamped counts and passes back average
  96. ;------------------------------------------------
  97. ; void addTSC(unsigned long *, unsigned long, unsigned long *);
  98. ;
  99. addTSCParams STRUC
  100. dd 6 dup (?) ;6 pushed regs
  101. dd ? ;return address
  102. dkTimes dd ?
  103. dkCount dd ?
  104. rv dd ?
  105. addTSCParams ENDS
  106. addTSC_:
  107. _addTSC:
  108. push esi
  109. push edi
  110. push ebp
  111. push ebx
  112. push ecx
  113. push edx
  114. xor ebp,ebp ;used for adc
  115. mov eax,[esp].dkTimes ;pointer to array of TSC's
  116. mov edi,[esp].dkCount ;array count
  117. mov esi,[esp].rv ;pointer to result
  118. xor edx,edx
  119. mov ebx,[eax] ;get first TSC
  120. mov ecx,[eax+4] ;get next TSC
  121. add eax,8
  122. adc edx,ebp
  123. add ebx,ecx
  124. add_loop:
  125. dec edi
  126. jz averageVal
  127. mov ecx,[eax]
  128. add eax,4
  129. adc edx,ebp
  130. add ebx,ecx
  131. jmp add_loop
  132. averageVal:
  133. mov eax,ebx
  134. mov ebx,[esp].dkCount ;array count
  135. div ebx ;div edx:eax by ebx (eax=quo, edx=rem)
  136. mov [esi],eax ;get average of counts
  137. the_exit:
  138. pop edx
  139. pop ecx
  140. pop ebx
  141. pop ebp
  142. pop edi
  143. pop esi
  144. ret
  145. ;************************************************
  146. END