* added compilers lcc and bcc (linux86)
[mascara-docs.git] / compilers / linux86-0.16.17 / copt / rules.386
blob955d4b64f58f95519757ac29ce73214c81a99448
1 # Rules to optimize BCC assembler output for 386
3 # Many of these rules are very broken, ho hum.
5 # Rules for loading a long constant
7 xor     ax,ax
8 xor     %[bx|si|di]1,%[bx|si|di]1
10 xor     eax,eax
12 xor     eax,eax
13 mov     %[ebx|ecx|edx]1,eax
15 xor     %1,%1
17 xor     ax,ax
18 mov     %[bx|si|di]*,%[*|#]0%1
20 mov     eax,%0%1<<16
22 mov     ax,%[*|#]0%1
23 xor     %[bx|si|di]2,%[bx|si|di]2
25 mov     eax,%0%1 & $0000FFFF
27 mov     ax,%0[%1]
28 xor     %[bx|si|di]2,%[bx|si|di]2
30 movzx   eax,word ptr %0[%1]
32 mov     ax,%[si|di]1
33 xor     bx,bx
35 movzx   eax,%1
37 %[movzx|movsx]5 eax,%1
38 mov     %[ebx|ecx|edx]2,eax
40 %5      %2,%1
42 %[movzx|movsx]5 %[ebx|ecx|edx]1,%2
43 mov     eax,%[#|*]0%3
44 %[add|and|xor|or]4      eax,%[ebx|ecx|edx]1
46 %5      eax,%2
47 %4      eax,%0%3
49 mov     ax,%0[%1]
50 cwde
52 movsx   eax,word ptr %0[%1]
54 mov     ax,%[si|di]1
55 cwde
57 movsx   eax,%1
59 mov     ax,%[#|*]3%1
60 mov     %[bx|si|di]*,%[#|*]4%2
62 mov     eax,%4%2<<16 + %1
65 # Rules for pushing variables and constants onto the stack
67 push    %![dword ptr]%1[%[bx|si|di|bp]3]
68 push    %![dword ptr]%(%1-2)[%[bx|si|di|bp]3]
70 push    dword ptr %(%1-2)[%3]
72 push    [%1+2]
73 push    [%1]
75 push    dword ptr [%1]
77 push    %[bx|si|di]*
78 push    ax
80 push    eax
82 mov     eax,%[#|*]0%1
83 push    eax
85 push    dword %0%1
87 mov     %1,%[eax|ebx|ecx|edx]2
88 push    dword ptr %1
90 mov     %1,%2
91 push    %2
94 # Rules for loading long variables
96 mov     ax,[%1]
97 mov     %[bx|si|di]*,[%1+2]
99 mov     eax,[%1]
101 mov     ax,%1[%[bx|si|di|bp]3]
102 mov     %[bx|si|di]*,%(%1+2)[%[bx|si|di|bp]3]
104 mov     eax,%1[%3]
106 mov     ax,#%1[bx]
107 mov     %[bx|si|di]*,#%1+2[bx]
109 mov     eax,#%1[bx]
111 mov     [%1],ax
112 mov     [%1+2],%[bx|si|di]*
114 mov     [%1],eax
116 mov     [%1+%3],ax
117 mov     [%1+%(%3+2)],%[bx|si|di]*
119 mov     [%1+%3],eax
121 mov     %1[%[si|di|bp]3],ax
122 mov     %(%1+2)[%[si|di|bp]3],%[bx|si|di]*
124 mov     %1[%3],eax
126 mov     #%1[bx],ax
127 mov     #%1+2[bx],%[bx|si|di]*
129 mov     #%1[bx],eax
131 mov     eax,%[#|*]0%1
132 mov     %![dword ptr]%3[%2],eax
134 mov     dword ptr %3[%2],%0%1
136 xor     ax,ax
137 xor     %[bx|si|di]3,%[bx|si|di]3
138 mov     %1[%[bx|bp]4],ax
139 mov     %(%1+2)[%[bx|bp]4],%[bx|si|di]3
141 mov     dword ptr %1[%4],#0
143 mov     ax,%1
144 mov     %[bx|si|di]5,%2
145 mov     %3[%[bx|bp]6],ax
146 mov     %(%3+2)[%[bx|bp]6],%[bx|si|di]5
148 mov     eax,dword ptr %1
149 mov     dword ptr %3[%6],eax
152 # Long return values are in EAX, so we can skip dx
154 mov     dx,bx
155 add     sp,*%1
157 add     sp,*%1
160 # Rules for manipulating long values
162 call    %1
163 mov     bx,dx
165 call    %1
167 call    l%[tstu|tst]*l
169 test    eax,eax
171 call    l%[comu|com]*l
173 not     eax
175 mov     eax,eax
180 mov     %2,%[eax|ebx|ecx|edx]1
181 mov     %[eax|ebx|ecx|edx]1,%2
183 mov     %2,%1
186 mov     bx,dx
188 cwde
190 mov     %[ebx|ecx|edx]0,%1
191 mov     eax,%2
192 %3      eax,%[ebc|ecx|edx]0
194 mov     eax,%2
195 %3      eax,%1
197 %[movzx|movsx|mov]0     %[eax|ebx|ecx|edx]2,%4
198 %[add|and|xor|sub|or]1  %[eax|ebx|ecx|edx]2,%6
199 mov     %6,%[eax|ebx|ecx|edx]2
201 %0      %2,%4
202 %1      %6,%2
204 mov     eax,%[#|*]0%1
205 cmp     eax,%2
206 %[jbe |jae |jne |jge |jle ]3    %4
208 cmp     dword ptr %2,%0%1
209 %=[jbe |jae |jne |jge |jle ][jae |jbe |jne |jle |jge ]3 %4
211 mov     eax,%[#|*]0%1
212 cmp     eax,%2
213 %[jb  |ja  |je  |jg  |jl  ]3    %4
215 cmp     dword ptr %2,%0%1
216 %=[jb  |ja  |je  |jg  |jl  ][ja  |jb  |je  |jl  |jg  ]3 %4
218 mov     eax,%1[%3]
219 cmp     eax,dword %[#|*]0%2
221 cmp     dword ptr %1[%3],%0%2
224 # Rules for calling the bcc library routines.
226 push    %1
227 push    %2
228 mov     eax,%3[bp]
229 %4      eax,%(%3-4)[bp]
230 add     sp,*8
232 mov     edx,%2
233 mov     eax,%1
234 %4      eax,edx
236 push    %1
237 mov     eax,%2
238 push    eax
239 mov     eax,%3[bp]
240 %4      eax,%(%3-4)[bp]
241 add     sp,*8
243 mov     edx,%2
244 mov     eax,%1
245 %4      eax,edx
247 push    %1
248 xor     eax,eax
249 push    eax
250 mov     eax,%2[bp]
251 %3      eax,%(%2-4)[bp]
252 add     sp,*8
254 mov     eax,%1
255 %3      eax,#0
257 push    %1
258 mov     eax,%2
259 %3      eax,%4[bp]
260 add     sp,*4
262 mov     edx,%1
263 mov     eax,%2
264 %3      eax,edx
266 push    %1
267 mov     eax,%2
268 %3      eax,%4[bp]
269 mov     %2,eax
270 add     sp,*4
272 mov     edx,%1
273 %3      %2,edx
276 push    %1
277 push    %2
278 mov     eax,%3[bp]
279 %4      eax,%(%3-4)[bp]
280 lea     sp,%(%3+4)[bp]
282 mov     edx,%2
283 mov     eax,%1
284 %4      eax,edx
286 push    %1
287 mov     eax,%2
288 push    eax
289 mov     eax,%3[bp]
290 %4      eax,%(%3-4)[bp]
291 lea     sp,%(%3+4)[bp]
293 mov     edx,%2
294 mov     eax,%1
295 %4      eax,edx
297 push    %1
298 xor     eax,eax
299 push    eax
300 mov     eax,%2[bp]
301 %3      eax,%(%2-4)[bp]
302 lea     sp,%(%2+4)[bp]
304 mov     eax,%1
305 %3      eax,#0
307 push    %1
308 mov     eax,%2
309 %3      eax,%4[bp]
310 lea     sp,%(%4+4)[bp]
312 mov     edx,%1
313 mov     eax,%2
314 %3      eax,edx
317 # Rules for calling the basic bcc library routines.
319 mov     di,#%2
320 call    l%3%[ul|l]*
322 %3      eax,[%2]
324 mov     di,*%2
325 call    lsll
327 lsl     eax,*%2
329 lea     di,%2
330 call    l%3%[ul|l]*
332 %3      eax,%2
334 mov     di,%[si|di]1
335 call    l%3%[ul|l]*
337 %3      eax,[%1]
339 mov     di,%[ax|bx|cx|dx]1
340 call    l%3%[ul|l]*
342 mov     di,%[ax|bx|cx|dx]1
343 %3      eax,[di]
346 # Rules for pushing short values
348 mov     %[ax|bx|cx|dx|si|di]2,%0[%1]
349 push    %[ax|bx|cx|dx|si|di]2
351 push    word ptr %0[%1]
353 mov     %[ax|bx|cx|dx|si|di]2,%[#|*]0%1
354 push    %[ax|bx|cx|dx|si|di]2
356 push    %0%1
359 # Shifting rules
361 %[shl|shr]2     %1,*1
362 %[shl|shr]2     %1,*1
364 %2      %1,*2
366 mov     cl,*%1
367 %[shl|shr]2     %3,cl
369 %2      %3,*%1
371 mov     dx,ax
372 shl     ax,*%1
373 add     ax,dx
374 shl     ax,*%2
376 mov     dx,ax
377 imul    ax,*%(1<%1+1<%2)
379 mov     dx,ax
380 imul    ax,*%1
381 add     ax,dx
383 mov     dx,ax
384 imul    ax,*%(%1+1)
386 mov     dx,ax
387 imul    ax,*%1
388 shl     ax,*%2
390 mov     dx,ax
391 imul    ax,*%(%1<%2)
393 mov     ax,%![#|*]%4
394 mov     dx,ax
395 imul    ax,*%1
396 %[add|and|xor|sub|or]2  ax,%![dx]%3
398 imul    ax,%4,*%1
399 %2      ax,%3
401 mov     ax,%![#|*]%4
402 mov     dx,ax
403 imul    ax,*%1
404 push    ax
406 imul    ax,%4,*%1
407 push    ax
409 imul    ax,%2,%[#|*]0%1
410 add     ax,%3
411 mov     bx,ax
413 imul    bx,%2,%0%1
414 add     bx,%3
417 # Different rules
419 %1      dword ptr %[eax|ebx|ecx|edx]3,*%2
421 %1      %3,*%2
423 %1      dword ptr %[eax|ebx|ecx|edx]3,#%2
425 %1      %3,#%2
427 eor     %1,%2
429 xor     %1,%2
431 com     %1
433 not     %1
435 xor     bx,bx
437 and     eax,#$0000FFFF