Leaked source code of windows server 2003
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.

103 lines
4.7 KiB

  1. ;---------------------------Module-Header------------------------------;
  2. ; Module Name: unroll.inc
  3. ;
  4. ; Equates and macros for loop unrolling.
  5. ;
  6. ; Copyright (c) 1992 Microsoft Corporation
  7. ;-----------------------------------------------------------------------;
  8. ; Module including this must define LOOP_UNROLL_SHIFT. the log2 of the number
  9. ; of times you want loops in this module unrolled. For example,
  10. ; LOOP_UNROLL_SHIFT of 3 yields 2**3 = 8 times unrolling. This is the only
  11. ; thing you need to change to control unrolling.
  12. ; # of times to unroll the loop, calculated as 2**n, where n is the
  13. ; user-specified log2 of # of times to unroll the loop.
  14. LOOP_UNROLL_COUNT equ (1 shl LOOP_UNROLL_SHIFT)
  15. ;-----------------------------------------------------------------------;
  16. ; Macro to generate an unrolled loop of UNROLL_COUNT instances of BASE_MACRO,
  17. ; passing the base macro the info needed to construct a label of the form
  18. ; BASE_LABELxxx, where xxx is UNROLL_COUNT the first time, and counts down by
  19. ; one each time thereafter.
  20. UNROLL_LOOP macro BASE_MACRO,BASE_LABEL,UNROLL_COUNT
  21. INDEX=UNROLL_COUNT
  22. rept UNROLL_COUNT ;-------------------------;
  23. &BASE_MACRO &BASE_LABEL,%INDEX
  24. INDEX=INDEX-1
  25. endm ;-----------------------------------;
  26. endm ;-----------------------------------;
  27. ;-----------------------------------------------------------------------;
  28. ; Macro to generate a dword memory variable that points to the label
  29. ; specified by concatenating the label and the index.
  30. DEFINE_DD macro BASE_LABEL,INDEX ;------------------;
  31. dd &BASE_LABEL&INDEX
  32. endm ;-----------------------------------;
  33. ;-----------------------------------------------------------------------;
  34. ; Macro to generate a table of vectors into an unrolled loop, for entering
  35. ; to handle all possible fractional loops.
  36. UNROLL_LOOP_ENTRY_TABLE macro TABLE,BASE_LABEL,UNROLL_COUNT
  37. align 4
  38. TABLE label dword
  39. DEFINE_DD BASE_LABEL,%&UNROLL_COUNT
  40. INDEX=1
  41. rept UNROLL_COUNT-1
  42. DEFINE_DD BASE_LABEL,%INDEX
  43. INDEX=INDEX+1
  44. endm ;-----------------------------------;
  45. endm ;-----------------------------------;
  46. ;-----------------------------------------------------------------------;
  47. ; Given a loop count, a vector table, and unrolling parameters, this generates
  48. ; COUNT_DEST = # of times to execute unrolled loop, VEC_DEST = entry point into
  49. ; unrolled loop to perform whatever fractional loop is needed. Assumes dests
  50. ; are registers.
  51. SET_UP_UNROLL_VARS macro COUNT_DEST,VEC_DEST,COUNT_SOURCE,VEC_TABLE,UNROLL_SHIFT
  52. mov &VEC_DEST&,&COUNT_SOURCE& ;copy count to vector dest to
  53. ; work with it
  54. ifdifi <&COUNT_SOURCE&>,<&COUNT_DEST&>
  55. mov &COUNT_DEST&,&COUNT_SOURCE& ;copy to count dest too, if not
  56. endif ; same as count source
  57. add &COUNT_DEST&,(1 shl LOOP_UNROLL_SHIFT)-1 ;round count up
  58. and &VEC_DEST&,(1 shl LOOP_UNROLL_SHIFT)-1
  59. ;fractional part of unrolled loop
  60. shr &COUNT_DEST&,UNROLL_SHIFT ;# of repetitions of unrolled loop
  61. mov &VEC_DEST&,&VEC_TABLE&[&VEC_DEST&*4]
  62. ;place to jump into the unrolled
  63. ; loop so as to handle the
  64. ; fractional part first
  65. endm ;-----------------------------------;
  66. ;-----------------------------------------------------------------------;
  67. ; Given a loop count, a vector table, and unrolling parameters, this generates
  68. ; COUNT_DEST = # of times to execute unrolled loop, VEC_DEST = entry point into
  69. ; unrolled loop to perform whatever fractional loop is needed. Assumes dests
  70. ; are registers.
  71. SET_UP_UNROLL_AND_BRANCH macro COUNT_REG,VEC_REG,VEC_TABLE,UNROLL_SHIFT
  72. mov &VEC_REG&,&COUNT_REG& ;copy count to vector dest to
  73. ; work with it
  74. add &COUNT_reg&,(1 shl LOOP_UNROLL_SHIFT)-1 ;round count up
  75. and &VEC_REG&,(1 shl LOOP_UNROLL_SHIFT)-1
  76. ;fractional part of unrolled loop
  77. shr &COUNT_REG&,UNROLL_SHIFT ;# of repetitions of unrolled loop
  78. jmp dword ptr &VEC_TABLE&[&VEC_REG&*4]
  79. ;jump into the unrolled loop so as
  80. ; to handle the fractional part
  81. ; first
  82. endm ;-----------------------------------;
  83. ;-----------------------------------------------------------------------;
  84.