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