Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
4.9 KiB

  1. TITLE "Compute Timer Table Index"
  2. ;++
  3. ;
  4. ; Copyright (c) 1993 Microsoft Corporation
  5. ;
  6. ; Module Name:
  7. ;
  8. ; timindex.asm
  9. ;
  10. ; Abstract:
  11. ;
  12. ; This module implements the code necessary to compute the timer table
  13. ; index for a timer.
  14. ;
  15. ; Author:
  16. ;
  17. ; David N. Cutler (davec) 19-May-1993
  18. ;
  19. ; Environment:
  20. ;
  21. ; Any mode.
  22. ;
  23. ; Revision History:
  24. ;
  25. ;--
  26. .386p
  27. .xlist
  28. include ks386.inc
  29. include callconv.inc ; calling convention macros
  30. .list
  31. extrn _KiTimeIncrementReciprocal:dword
  32. extrn _KiTimeIncrementShiftCount:BYTE
  33. _TEXT$00 SEGMENT DWORD PUBLIC 'CODE'
  34. ASSUME DS:FLAT, ES:FLAT, SS:NOTHING, FS:NOTHING, GS:NOTHING
  35. page
  36. subttl "Compute Timer Table Index"
  37. ;++
  38. ;
  39. ; ULONG
  40. ; KiComputeTimerTableIndex (
  41. ; IN LARGE_INTEGER Interval,
  42. ; IN LARGE_INTEGER CurrentTime,
  43. ; IN PKTIMER Timer
  44. ; )
  45. ;
  46. ; Routine Description:
  47. ;
  48. ; This function computes the timer table index for the specified timer
  49. ; object and stores the due time in the timer object.
  50. ;
  51. ; N.B. The interval parameter is guaranteed to be negative since it is
  52. ; expressed as relative time.
  53. ;
  54. ; The formula for due time calculation is:
  55. ;
  56. ; Due Time = Current Time - Interval
  57. ;
  58. ; The formula for the index calculation is:
  59. ;
  60. ; Index = (Due Time / Maximum time) & (Table Size - 1)
  61. ;
  62. ; The time increment division is performed using reciprocal multiplication.
  63. ;
  64. ; Arguments:
  65. ;
  66. ; Interval - Supplies the relative time at which the timer is to
  67. ; expire.
  68. ;
  69. ; CurrentCount - Supplies the current system tick count.
  70. ;
  71. ; Timer - Supplies a pointer to a dispatch object of type timer.
  72. ;
  73. ; Return Value:
  74. ;
  75. ; The time table index is returned as the function value and the due
  76. ; time is stored in the timer object.
  77. ;
  78. ;--
  79. LocalStack equ 20
  80. Interval equ [esp+LocalStack+4]
  81. CurrentTime equ [esp+LocalStack+12]
  82. Timer equ [esp+LocalStack+20]
  83. cPublicProc _KiComputeTimerTableIndex ,5
  84. sub esp, LocalStack
  85. mov [esp+16], ebx
  86. mov ebx,CurrentTime ; get low current time
  87. mov ecx,CurrentTime + 4 ; get high current time
  88. sub ebx,Interval ; subtract low parts
  89. sbb ecx,Interval + 4 ; subtract high parts and borrow
  90. mov eax,Timer ; get address of timer object
  91. mov [eax].TiDueTime.LiLowPart,ebx ; set low part of due time
  92. mov [eax].TiDueTime.LiHighPart,ecx ; set high part of due time
  93. ;
  94. ; Compute low 32-bits of dividend times low 32-bits of divisor.
  95. ;
  96. mov eax,ebx ; copy low 32-bits of dividend
  97. mul [_KiTimeIncrementReciprocal] ; multiply by low 32-bits of divisor
  98. mov [esp+12], edx ; save high order 32-bits of product
  99. ;
  100. ; Compute low 32-bits of dividend times high 32-bits of divisor.
  101. ;
  102. mov eax,ebx ; copy low 32-bits of dividend
  103. mul [_KiTimeIncrementReciprocal+4] ;multiply by high 32-bits of divisor
  104. mov [esp+8], eax ; save full 64-bit product
  105. mov [esp+4], edx ;
  106. ;
  107. ; Compute high 32-bits of dividend times low 32-bits of divisor.
  108. ;
  109. mov eax,ecx ; copy high 32-bits of dividend
  110. mul [_KiTimeIncrementReciprocal] ; multiply by low 32-bits of divisor
  111. mov [esp+0], edx ; save high 32-bits of product
  112. ;
  113. ; Compute carry out of low 64-bits of 128-bit product.
  114. ;
  115. xor ebx,ebx ; clear carry accumlator
  116. add eax,[esp]+8 ; generate carry
  117. adc ebx,0 ; accumlate carry
  118. add eax,[esp]+12 ; generate carry
  119. adc ebx,0 ; accumulate carry
  120. ;
  121. ; Compute high 32-bits of dividend times high 32-bits of divisor.
  122. ;
  123. mov eax,ecx ; copy high 32-bits of dividend
  124. mul [_KiTimeIncrementReciprocal+4] ; multiply by high 32-bits of divisor
  125. ;
  126. ; Compute high 64-bits of 128-bit product.
  127. ;
  128. add eax,ebx ; add carry from low 64-bits
  129. adc edx,0 ; propagate carry
  130. add eax,[esp]+0 ; add and generate carry
  131. adc edx,0 ; propagate carry
  132. add eax,[esp]+4 ; add and generate carry
  133. adc edx,0 ; propagate carry
  134. ;
  135. ; Right shift the result by the specified shift count and mask off extra
  136. ; bits.
  137. ;
  138. mov cl,[_KiTimeIncrementShiftCount] ; get shift count value
  139. shrd eax,edx,cl ; extract appropriate product bits
  140. mov ebx, [esp+16] ; restore register
  141. add esp, LocalStack ; trim stack
  142. and eax,(TIMER_TABLE_SIZE-1); reduce to size of table
  143. stdRET _KicomputeTimerTableIndex
  144. stdENDP _KiComputeTimerTableIndex
  145. _TEXT$00 ends
  146. end