2 ; Smart alignment macros
6 %imacro alignmode 1-2.nolist
8 %define __ALIGN_JMP_THRESHOLD__ 16
10 %define __ALIGN_16BIT_1B__ 0x90
11 %define __ALIGN_16BIT_GROUP__ 1
13 %define __ALIGN_32BIT_1B__ 0x90
14 %define __ALIGN_32BIT_GROUP__ 1
16 %define __ALIGN_64BIT_1B__ 0x90
17 %define __ALIGN_64BIT_GROUP__ 1
19 %define __ALIGN_JMP_THRESHOLD__ 8
21 %define __ALIGN_16BIT_1B__ 0x90
22 %define __ALIGN_16BIT_2B__ 0x89,0xf6
23 %define __ALIGN_16BIT_3B__ 0x8d,0x74,0x00
24 %define __ALIGN_16BIT_4B__ 0x8d,0xb4,0x00,0x00
25 %define __ALIGN_16BIT_5B__ 0x8d,0xb4,0x00,0x00,0x90
26 %define __ALIGN_16BIT_6B__ 0x8d,0xb4,0x00,0x00,0x89,0xff
27 %define __ALIGN_16BIT_7B__ 0x8d,0xb4,0x00,0x00,0x8d,0x7d,0x00
28 %define __ALIGN_16BIT_8B__ 0x8d,0xb4,0x00,0x00,0x8d,0xbd,0x00,0x00
29 %define __ALIGN_16BIT_GROUP__ 8
31 %define __ALIGN_32BIT_1B__ 0x90
32 %define __ALIGN_32BIT_2B__ 0x89,0xf6
33 %define __ALIGN_32BIT_3B__ 0x8d,0x76,0x00
34 %define __ALIGN_32BIT_4B__ 0x8d,0x74,0x26,0x00
35 %define __ALIGN_32BIT_5B__ 0x90,0x8d,0x74,0x26,0x00
36 %define __ALIGN_32BIT_6B__ 0x8d,0xb6,0x00,0x00,0x00,0x00
37 %define __ALIGN_32BIT_7B__ 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00
38 %define __ALIGN_32BIT_GROUP__ 7
40 %define __ALIGN_64BIT_1B__ 0x90
41 %define __ALIGN_64BIT_2B__ 0x66,0x90
42 %define __ALIGN_64BIT_3B__ 0x66,0x66,0x90
43 %define __ALIGN_64BIT_4B__ 0x66,0x66,0x66,0x90
44 %define __ALIGN_64BIT_GROUP__ 4
46 %define __ALIGN_JMP_THRESHOLD__ 16
48 %define __ALIGN_16BIT_1B__ 0x90
49 %define __ALIGN_16BIT_2B__ 0x66,0x90
50 %define __ALIGN_16BIT_3B__ 0x66,0x66,0x90
51 %define __ALIGN_16BIT_4B__ 0x66,0x66,0x66,0x90
52 %define __ALIGN_16BIT_GROUP__ 4
54 %define __ALIGN_32BIT_1B__ 0x90
55 %define __ALIGN_32BIT_2B__ 0x66,0x90
56 %define __ALIGN_32BIT_3B__ 0x66,0x66,0x90
57 %define __ALIGN_32BIT_4B__ 0x66,0x66,0x66,0x90
58 %define __ALIGN_32BIT_GROUP__ 4
60 %define __ALIGN_64BIT_1B__ 0x90
61 %define __ALIGN_64BIT_2B__ 0x66,0x90
62 %define __ALIGN_64BIT_3B__ 0x66,0x66,0x90
63 %define __ALIGN_64BIT_4B__ 0x66,0x66,0x66,0x90
64 %define __ALIGN_64BIT_GROUP__ 4
66 %define __ALIGN_JMP_THRESHOLD__ 16
68 %define __ALIGN_16BIT_1B__ 0x90
69 %define __ALIGN_16BIT_2B__ 0x66,0x90
70 %define __ALIGN_16BIT_3B__ 0x66,0x66,0x90
71 %define __ALIGN_16BIT_4B__ 0x66,0x66,0x66,0x90
72 %define __ALIGN_64BIT_GROUP__ 4
74 %define __ALIGN_32BIT_1B__ 0x90
75 %define __ALIGN_32BIT_2B__ 0x8b,0xc0
76 %define __ALIGN_32BIT_3B__ 0x8d,0x04,0x20
77 %define __ALIGN_32BIT_4B__ 0x8d,0x44,0x20,0x00
78 %define __ALIGN_32BIT_5B__ 0x8d,0x44,0x20,0x00,0x90
79 %define __ALIGN_32BIT_6B__ 0x8d,0x80,0x00,0x00,0x00,0x00
80 %define __ALIGN_32BIT_7B__ 0x8d,0x04,0x05,0x00,0x00,0x00,0x00
81 %define __ALIGN_32BIT_GROUP__ 7
83 %define __ALIGN_64BIT_1B__ 0x90
84 %define __ALIGN_64BIT_2B__ 0x66,0x90
85 %define __ALIGN_64BIT_3B__ 0x66,0x66,0x90
86 %define __ALIGN_64BIT_4B__ 0x66,0x66,0x66,0x90
87 %define __ALIGN_64BIT_GROUP__ 4
89 %define __ALIGN_JMP_THRESHOLD__ 16
91 %define __ALIGN_16BIT_1B__ 0x90
92 %define __ALIGN_16BIT_2B__ 0x66,0x90
93 %define __ALIGN_16BIT_3B__ 0x0f,0x1f,0x00
94 %define __ALIGN_16BIT_4B__ 0x0f,0x1f,0x40,0x00
95 %define __ALIGN_16BIT_GROUP__ 4
97 %define __ALIGN_32BIT_1B__ 0x90
98 %define __ALIGN_32BIT_2B__ 0x66,0x90
99 %define __ALIGN_32BIT_3B__ 0x0f,0x1f,0x00
100 %define __ALIGN_32BIT_4B__ 0x0f,0x1f,0x40,0x00
101 %define __ALIGN_32BIT_5B__ 0x0f,0x1f,0x44,0x00,0x00
102 %define __ALIGN_32BIT_6B__ 0x66,0x0f,0x1f,0x44,0x00,0x00
103 %define __ALIGN_32BIT_7B__ 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
104 %define __ALIGN_32BIT_8B__ 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
105 %define __ALIGN_32BIT_GROUP__ 8
107 %define __ALIGN_64BIT_1B__ 0x90
108 %define __ALIGN_64BIT_2B__ 0x66,0x90
109 %define __ALIGN_64BIT_3B__ 0x0f,0x1f,0x00
110 %define __ALIGN_64BIT_4B__ 0x0f,0x1f,0x40,0x00
111 %define __ALIGN_64BIT_5B__ 0x0f,0x1f,0x44,0x00,0x00
112 %define __ALIGN_64BIT_6B__ 0x66,0x0f,0x1f,0x44,0x00,0x00
113 %define __ALIGN_64BIT_7B__ 0x0f,0x1f,0x80,0x00,0x00,0x00,0x00
114 %define __ALIGN_64BIT_8B__ 0x0f,0x1f,0x84,0x00,0x00,0x00,0x00,0x00
115 %define __ALIGN_64BIT_GROUP__ 8
117 %error unknown alignment mode: %1
120 %xdefine __ALIGN_JMP_THRESHOLD__ %2
122 %xdefine __ALIGNMODE__ %1,__ALIGN_JMP_THRESHOLD__
125 %unimacro align 1-2+.nolist
126 %imacro align 1-2+.nolist
128 times (((%1) - (($-$$) % (%1))) % (%1)) %2
131 %assign %$pad (((%1) - (($-$$) % (%1))) % (%1))
132 %if %$pad > __ALIGN_JMP_THRESHOLD__
134 ; We can't re-use %$pad here as $ will have changed!
135 times (((%1) - (($-$$) % (%1))) % (%1)) nop
138 times (%$pad / __ALIGN_%[__BITS__]BIT_GROUP__) \
139 db __ALIGN_%[__BITS__]BIT_%[__ALIGN_%[__BITS__]BIT_GROUP__]B__
140 %assign %$pad %$pad % __ALIGN_%[__BITS__]BIT_GROUP__
142 db __ALIGN_%[__BITS__]BIT_%[%$pad]B__