Pristine Ack-5.5
[Ack-5.5.git] / mach / i86 / ncg / table
1 /*
2  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3  * See the copyright notice in the ACK home directory, in the file "Copyright".
4  */
5
6 rscid = "$Id: table,v 1.61 1995/07/21 12:05:07 ceriel Exp $"
7
8 /*
9  * Back end tables for Intel 8086, 80286
10  *
11  * Author : Ed Keizer
12  *
13  * Adapted to ncg format by BMT Mosseveld, EM v Mulligen, M de Rooy, E tulp,
14  * and R Vendelmans (practical work course compiler construction).
15  *
16  * New format table much corrected: Ceriel Jacobs
17  * Added register variables: Ceriel Jacobs
18  * Adapted to use floating point library: Ceriel Jacobs
19  *
20  * wordsize = 2 bytes, pointersize = 2 bytes.
21  *
22  * Register bp is used as LB, sp is used for SP.
23  * Some global variables are used:
24  * - .reghp     : the heap pointer
25  * - .ignmask   : trap ignore mask
26  * - .trppc     : address of user defined trap handler
27  *
28  */
29
30 SL = 4
31 SSL = "4"
32
33 EM_WSIZE = 2
34 EM_PSIZE = 2
35 EM_BSIZE = 4
36
37 SIZEFACTOR = 5/1
38
39 #define EXACT exact
40 #define REGVARS
41
42 /*****************************************************************/
43 PROPERTIES
44 /*****************************************************************/
45
46 REG1
47 ACC1
48 AREG
49 SHIFT_CREG
50 REG
51 GENREG
52 ACC
53 BREG
54 BXREG
55 ADDREG
56 CXREG
57 DXREG
58 IREG
59 #ifdef REGVARS
60 RADDREG
61 #endif
62
63 /*****************************************************************/
64 REGISTERS
65 /*****************************************************************/
66
67 al                                  : REG1 , ACC1 .
68 ah,bl,bh,ch,dl,dh                   : REG1 .
69 cl                                  : REG1 , SHIFT_CREG .
70 ax = al + ah                        : REG , GENREG , ACC .
71 bx = bl + bh                        : REG , GENREG , BXREG , ADDREG , AREG .
72 cx = cl + ch                        : REG , GENREG , CXREG , SHIFT_CREG.
73 dx = dl + dh                        : REG , GENREG , DXREG .
74 #ifndef REGVARS
75 si                                  : REG , IREG , AREG , ADDREG .
76 di                                  : REG , IREG , AREG , ADDREG .
77 #else
78 si                                  : AREG , RADDREG , IREG regvar(reg_any) .
79 di                                  : AREG , RADDREG , IREG regvar(reg_any) .
80 #endif
81 bp                                  : AREG .
82 sp                                  : BREG .
83
84 /*****************************************************************/
85 TOKENS
86 /*****************************************************************/
87
88 ANYCON          = { INT val; }      2 cost(2,2) val .
89 CONSTR          = { ADDR off; }     2 cost(2,2) off .
90 ADDR_EXTERN     = { ADDR off; }     2 cost(2,2) off .
91 EXTERN1         = { ADDR off; }     2 cost(2,12) "(" off ")" .
92 EXTERN2         = { ADDR off; }     2 cost(2,12) "(" off ")" .
93 ADDR_LOCAL      = { INT ind; }      2 cost(1,9) ind "(bp)" .
94 LOCAL          = { INT ind; INT size; } 2 cost(1,15) ind "(bp)" .
95 LOCAL1          = { INT ind; INT size; } 2 cost(1,15) ind "(bp)" .
96
97 Rreg_off         = { AREG reg; ADDR off;} 2 cost(1,9) off "(" reg ")" .
98 Rbpreg_off       = { AREG reg; INT ind;} 2 cost(1,11) ind "(bp)" "(" reg ")" .
99 Xreg_off         = { AREG reg; ADDR off;} 2 cost(1,9) off "(" reg ")" .
100
101 ind_reg2        = { AREG reg;} 2 cost(0,11) "(" reg ")" .
102 ind_regoff2     = { AREG reg; ADDR off;} 2 cost(1,15) off "(" reg ")" .
103 ind_bpregoff2   = { AREG reg; INT ind;} 2 cost(1,18) ind "(bp)" "(" reg ")" .
104
105 ind_reg1        = { AREG reg;} 2 cost(0,11) "(" reg ")" .
106 ind_regoff1     = { AREG reg; ADDR off;} 2 cost(1,15) off "(" reg ")" .
107 ind_bpregoff1   = { AREG reg; INT ind;} 2 cost(1,18) ind "(bp)" "(" reg ")" .
108 label           = { ADDR off;} 2 off .
109
110 /*****************************************************************/
111 SETS
112 /*****************************************************************/
113
114 /* Mode refering to a word in memory */
115 memory2         = EXTERN2 + ind_reg2 + ind_regoff2 + ind_bpregoff2 +
116                   LOCAL .
117
118
119 memory1         = EXTERN1 + ind_reg1 + ind_regoff1 + ind_bpregoff1 +
120                   LOCAL1 .
121
122 const           = ANYCON + ADDR_EXTERN + CONSTR .
123 register        = REG + AREG
124 #ifdef REGVARS
125                   + IREG
126 #endif
127                         .
128 addreg          = ADDREG
129 #ifdef REGVARS
130                   + RADDREG
131 #endif
132                         .
133 anyreg          = register + BREG .
134 rm              = anyreg + memory2 .
135 rmnoacc         = IREG + BXREG + CXREG + memory2 .
136 rmorconst       = const + rm .
137 regorconst      = const + anyreg .
138 #ifdef REGVARS
139 /* Needed because there is a shortage of ADDREG-registers.
140    This is the main penalty for having register variables.
141 */
142 regorconstnoaddr = const + IREG + ACC + CXREG + DXREG .
143 #else
144 regorconstnoaddr = regorconst .
145 #endif
146 dest            = register + memory2 .
147
148 rm1             = REG1 + memory1 .
149 rmorconst1      = const + rm1 .
150 regorconst12    = REG1 + GENREG + const .
151 dest1           = REG1 + memory1 .
152 rm12            = rm1 + memory2 .
153
154 /* Modes used to indicate tokens to be removed from the fakestack */
155 reg_indexed     = ind_reg2 + ind_regoff2 + ind_reg1 + ind_regoff1 .
156 lb_indexed      = ind_bpregoff2 + ind_bpregoff1 .
157 indexed         = reg_indexed + lb_indexed .
158 externals       = EXTERN2 + EXTERN1 .
159 locals          = LOCAL + LOCAL1 .
160 all_locals      = locals + lb_indexed .
161 indirects       = externals + reg_indexed .
162 referals        = indirects + locals .
163
164 /* Miscellaneous */
165 reg_off         = Xreg_off + Rreg_off .
166 bpreg_off       = Rbpreg_off .
167 halfindir       = reg_off + bpreg_off + ADDR_LOCAL .
168 some_off        = halfindir + ADDR_EXTERN + addreg .
169 a_word          = rmorconst + rm1 + halfindir .
170 no_reg_off      = rmorconst + rm1 + ADDR_LOCAL .
171  
172 /*****************************************************************/
173 INSTRUCTIONS
174 /*****************************************************************/
175
176 cost(1,3)
177 adc rm:rw:cc, regorconst:ro.
178 adc anyreg:rw:cc, rmorconst:ro.
179 #ifdef REGVARS
180 add LOCAL:rw:cc, rmorconst:ro.  /* only for register variables; UNSAFE !!! */
181 #endif
182 add anyreg:rw:cc, rmorconst:ro.
183 add rm:rw:cc, regorconst:ro.
184 #ifdef REGVARS
185 axx "syntax error" LOCAL:rw:cc, rmorconst:ro.   /* only for register variables; UNSAFE !!! */
186 #endif
187 axx "syntax error" anyreg:rw:cc, rmorconst:ro.
188 axx "syntax error" rm:rw:cc, regorconst:ro.
189 #ifdef REGVARS
190 and LOCAL:rw:cc, rmorconst:ro.  /* only for register variables; UNSAFE !!! */
191 #endif
192 and rm:rw:cc, regorconst:ro.
193 and anyreg:rw:cc, rmorconst:ro.
194 cbw kills ah cost(1,2).
195 cmp rm:ro, regorconst:ro kills :cc.
196 cmp anyreg:ro, rmorconst:ro kills :cc.
197 cmpb rm1:ro, REG1+const:ro kills :cc.
198 cmpb REG1:ro, rm1:ro kills :cc.
199 cwd kills dx cost(1,5).
200 dec rm:rw:cc cost(1,2).
201 div rm:ro kills:cc ax dx cost(1,150).
202 idiv rm:ro kills:cc ax dx cost(1,170).
203 inc rm:rw:cc cost(1,2).
204 ja label cost(1,4).
205 jae label cost(1,4).
206 jb label cost(1,4).
207 jbe label cost(1,4).
208 jcxz label cost(1,5).
209 je label cost(1,4).
210 jg label cost(1,4).
211 jge label cost(1,4).
212 jl label cost(1,4).
213 jle label cost(1,4).
214 jne label cost(1,4).
215 jmp label cost(1,7).
216 joehoe "call" label+rm cost(1,8).
217 jxx "syntax error" label.
218 lea anyreg:wo, halfindir:ro cost(1,2).
219 lea LOCAL:wo, halfindir:ro cost(1,2).   /* only for register variables, UNSAFE!!! */
220 loop label kills cx cost(1,5).
221 #ifdef REGVARS
222 mov LOCAL:wo, memory2:ro cost(1,2).     /* only for register variables, UNSAFE!!! */
223 #endif
224 mov a_word:wo, regorconst:ro cost(1,2).
225 mov anyreg:wo, rmorconst:ro cost(1,2).
226 movb rm1:wo, regorconst12:ro cost(1,2).
227 movb REG1:wo, rm1:ro cost(1,2).
228 mul rmorconst:ro kills :cc ax dx cost(1,124).
229 neg rmorconst:rw:cc.
230 nop .
231 not rmorconst:rw.
232 ORB "orb" REG1:ro, REG1:ro:cc.          /* use ORB for tests */
233 OR "or" anyreg:ro, anyreg:ro:cc.        /* Use OR for tests */
234 #ifdef REGVARS
235 or LOCAL:rw:cc, rmorconst:ro.   /* only for register variables; UNSAFE !!! */
236 #endif
237 or rm:rw:cc, regorconst:ro.
238 or anyreg:rw:cc, rmorconst:ro.
239 pop rmorconst:wo cost(1,8).
240 push rmorconst:ro cost(1,10).
241 rcl rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
242 rcr rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
243 ret cost(1,8).
244 rol rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
245 ror rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
246 sal rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
247 sar rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
248 sbb rm:rw:cc, regorconst:ro.
249 sbb anyreg:rw:cc, rmorconst:ro.
250 shl rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
251 shr rm:rw, ANYCON+SHIFT_CREG:ro kills:cc.
252 sxx rm:rw:cc, ANYCON+SHIFT_CREG:ro.
253 #ifdef REGVARS
254 sub LOCAL:rw:cc, rmorconst:ro.  /* only for register variables; UNSAFE !!! */
255 #endif
256 sub rm:rw:cc, regorconst:ro.
257 sub anyreg:rw:cc, rmorconst+halfindir:ro.
258 check "test" rm:ro, regorconst:ro kills :cc.
259 check "test" anyreg:ro, rmorconst:ro kills :cc.
260 testb "testb" rm12:ro, regorconst:ro kills :cc.
261 testb "testb" REG1:ro, rmorconst:ro kills :cc.
262 testb "testb" ACC1:ro, const:ro kills :cc.
263 uxx "syntax error"  rm:rw:cc cost(1,2).
264 xchg rm:rw, anyreg:rw.
265 xchg anyreg:rw, rm:rw.
266 xor rm:rw:cc, regorconst:ro.
267 xor anyreg:rw:cc, rmorconst:ro.
268 xorb rm1:rw:cc, regorconst12:ro.
269 xorb anyreg:rw:cc, rm1:ro.
270 killreg "! kill" anyreg:wo cost(0,0).
271 killcc "! kill cc" kills:cc cost(0,0).
272
273 data ".sect .data".
274 word ".data2" const:ro.
275 text ".sect .text".
276
277
278 /*****************************************************************/
279 MOVES
280 /*****************************************************************/
281
282 #ifdef REGVARS
283 from memory2 to LOCAL           /* unsafe !!! */
284 gen mov %2,%1
285
286 from halfindir to LOCAL         /* unsafe !!! */
287 gen lea %2,%1
288 #endif
289
290 from rm to register
291 gen mov %2,%1
292
293 from anyreg to dest
294 gen mov %2,%1
295
296 from halfindir to register+AREG
297 gen lea %2,%1
298
299 from rm1 to REG1
300 gen movb %2,%1
301
302 from GENREG to rm1
303 gen movb %2,%1.1
304
305 from ANYCON %val==0 to register
306 gen xor %2,%2
307
308 from ANYCON %val==0 to REG1
309 gen xorb %2,%2
310
311 from const to dest
312 gen mov %2,%1
313
314 from const+REG1 to rm1
315 gen movb %2,%1
316
317
318 /*****************************************************************/
319 TESTS
320 /*****************************************************************/
321
322 to test anyreg
323 gen OR %1,%1
324
325 to test memory2
326 gen cmp %1, {ANYCON,0}
327
328 to test REG1
329 gen ORB %1,%1
330
331 to test memory1
332 gen cmpb %1, {ANYCON,0}
333
334
335 /*****************************************************************/
336 STACKINGRULES
337 /*****************************************************************/
338
339 from anyreg to STACK
340   gen push %1
341
342 from memory2 to STACK
343   gen push %1
344
345 from const to STACK
346   uses REG
347   gen move %1,%a
348       push %a
349
350 from const to STACK
351   gen data.
352       1:
353       word %1
354       text.
355       push {EXTERN2,"1b"}
356
357 from rm1 to STACK
358   uses GENREG
359   gen move {ANYCON,0},%a
360       move %1,%a.1
361       push %a
362
363 from rm1 to STACK
364   gen push ax
365       push bx
366       move %1,al
367       xorb ah,ah
368       mov bx,sp
369       xchg {ind_regoff2,bx,2},ax
370       pop bx
371
372 from Xreg_off to STACK
373   gen add %1.reg,{CONSTR,%1.off}
374       push %1.reg
375
376 from ADDR_LOCAL %ind==0 to STACK
377   gen 
378         push bp
379
380 from halfindir to STACK
381   uses REG
382   gen move %1,%a
383       push %a
384
385 from halfindir to STACK
386   gen push ax
387       push bx
388       lea ax,%1
389       mov bx,sp
390       xchg {ind_regoff2,bx,2},ax
391       pop bx
392
393
394 /*****************************************************************/
395 COERCIONS
396 /*****************************************************************/
397
398 /***************************
399  * From source to register *
400  ***************************/
401
402 from rmorconst
403   uses reusing %1,REG=%1                yields %a
404
405 from Xreg_off
406   gen add %1.reg,{CONSTR,%1.off}        yields %1.reg
407
408 from halfindir
409   uses reusing %1,ADDREG
410   gen move %1,%a                        yields %a
411
412 from halfindir
413   uses reusing %1,REG
414   gen move %1,%a                        yields %a
415
416 /************************
417  * From source to token *
418  ************************/
419
420 from ANYCON                             yields {ADDR_EXTERN,%1.val}
421
422 /****************
423  * From source1 *
424  ****************/
425
426 from rm1
427   uses reusing %1,REG1=%1               yields %a
428
429 from rm1
430   uses reusing %1,GENREG
431   gen move %1,%a.1
432       xorb %a.2,%a.2                    yields %a
433
434 from ACC1
435   uses reusing %1,ACC
436   gen xorb %a.2,%a.2                    yields %a
437
438 /************************
439  * From STACK coercions *
440  ************************/
441
442 from STACK
443   uses REG
444   gen pop %a                            yields %a
445
446
447 /*****************************************************************/
448 PATTERNS
449 /*****************************************************************/
450
451 /******************************************************************
452  *  Group 1 : Load Instructions                                   *
453  ******************************************************************/
454
455 pat loc                                 yields {ANYCON,$1}
456
457 pat ldc loww($1)==0 && highw($1)==0
458 uses REG = {ANYCON, 0}                  yields %a %a
459
460 pat ldc                                 yields {ANYCON,highw($1)}
461                                                {ANYCON,loww($1)}
462
463 pat lol                                 yields {LOCAL,$1,2}
464
465 pat stl lol $1==$2
466 #ifdef REGVARS
467         && inreg($1) <= 0
468 #endif
469                                                 leaving dup 2 stl $1
470
471 pat stl lol lof $1==$2
472 #ifdef REGVARS
473         && inreg($1) <= 0
474 #endif
475 with AREG                               yields %1 %1
476                                                 leaving stl $1 lof $3
477
478 pat stl lol loi $1==$2
479 #ifdef REGVARS
480         && inreg($1) <= 0
481 #endif
482 with AREG                               yields %1 %1
483                                                 leaving stl $1 loi $3
484
485 pat sdl ldl $1==$2                              leaving dup 4 sdl $1
486
487 #ifdef REGVARS
488 pat lol dup stl $2==2 && inreg($1) <= 0 && inreg($3) > 0
489 kills regvar($3)
490 gen     move {LOCAL,$1,2}, {LOCAL,$3,2}
491                                         yields {LOCAL,$3,2}
492 #endif
493
494 pat loe                                 yields {EXTERN2,$1}
495
496 pat ste loe $1==$2                              leaving dup 2 ste $1
497
498 pat ste loe lof $1==$2
499 with AREG                               yields %1 %1
500                                                 leaving ste $1 lof $3
501
502 pat ste loe loi $1==$2
503 with AREG                               yields %1 %1
504                                                 leaving ste $1 loi $3
505
506 pat sde lde $1==$2                              leaving dup 4 sde $1
507
508 #ifdef REGVARS
509 pat loe dup stl $2==2 && inreg($3) > 0
510 kills regvar($3)
511 gen     move {EXTERN2,$1}, {LOCAL,$3,2}
512                                         yields {LOCAL,$3,2}
513 #endif
514
515 #ifdef REGVARS
516 pat lil inreg($1) > 0                   yields {ind_reg2, regvar($1)}
517 #endif
518 pat lil 
519   uses ADDREG={LOCAL,$1,2}              yields {ind_reg2,%a}
520
521 pat lil dup stl $2==2                           leaving lil $1 stl $3 lol $3
522
523 pat sil lil $1==$2                              leaving dup 2 sil $1
524
525 pat lof 
526   with exact reg_off            yields {ind_regoff2,%1.reg,%1.off+$1}
527   with exact bpreg_off          yields {ind_bpregoff2,%1.reg,%1.ind+$1}
528   with exact ADDR_EXTERN        yields {EXTERN2,%1.off+$1}
529   with exact ADDR_LOCAL         yields {LOCAL,%1.ind + $1,2}
530   with addreg                   yields {ind_regoff2,%1,$1}
531
532 pat lal                                 yields {ADDR_LOCAL,$1}
533
534 pat lae                                 yields {ADDR_EXTERN,$1}
535
536 pat lpb                                         leaving adp SL
537
538 pat lxl $1==0                           yields {ADDR_LOCAL,0}
539
540 pat lxl $1==1                           yields {LOCAL,SL,2}
541
542 pat lxl $1==2                           
543   uses ADDREG={LOCAL,SL,2}              yields {ind_regoff2,%a,SSL}
544
545 pat lxl $1>2                            
546   uses ADDREG={LOCAL,SL,2},
547        CXREG={ANYCON,$1-1}
548   gen 1:
549       mov %a,{ind_regoff2,%a,4}
550       loop {label,1b}                   yields %a
551
552 pat lxa $1==0                           yields {ADDR_LOCAL,SL}
553
554 pat lxa $1==1                           
555   uses ADDREG={LOCAL,SL,2}              yields {Xreg_off,%a,SSL}
556
557 pat lxa $1==2
558   uses ADDREG={LOCAL,SL,2}
559   gen move {ind_regoff2,%a,SSL},%a      yields {Xreg_off,%a,SSL}
560
561 pat lxa $1>2    
562   uses ADDREG={LOCAL,SL,2},
563        CXREG={ANYCON,$1-1}
564   gen 1:
565       mov %a,{ind_regoff2,%a,4}
566       loop {label,1b}                   yields {Xreg_off,%a,SSL}
567
568 pat dch                                         leaving loi 2
569
570 pat loi $1==2                   
571   with addreg                   yields {ind_reg2,%1}
572   with exact reg_off            yields {ind_regoff2,%1.reg,%1.off}
573   with exact bpreg_off          yields {ind_bpregoff2,%1.reg,%1.ind}
574   with exact ADDR_EXTERN        yields {EXTERN2,%1.off}
575   with exact ADDR_LOCAL         yields {LOCAL,%1.ind,2}
576
577 pat loi $1==1
578   with addreg                   yields {ind_reg1,%1}
579   with exact reg_off            yields {ind_regoff1,%1.reg,%1.off}
580   with exact bpreg_off          yields {ind_bpregoff1,%1.reg,%1.ind}
581   with exact ADDR_EXTERN        yields {EXTERN1,%1.off}
582   with exact ADDR_LOCAL         yields {LOCAL1,%1.ind,1}
583
584 pat loi $1==4
585   with addreg                   yields {ind_regoff2,%1,2}
586                                        {ind_reg2,%1}
587   with exact reg_off            yields {ind_regoff2,%1.reg,%1.off+2}
588                                        {ind_regoff2,%1.reg,%1.off}
589   with exact bpreg_off          yields {ind_bpregoff2,%1.reg,%1.ind+2}
590                                        {ind_bpregoff2,%1.reg,%1.ind}
591   with exact ADDR_LOCAL         yields {LOCAL,%1.ind+2,2}
592                                        {LOCAL,%1.ind,2}
593   with exact ADDR_EXTERN        yields {EXTERN2,%1.off + 2}
594                                        {EXTERN2,%1.off}
595
596 pat loi $1>4
597   with BXREG
598   kills ALL
599   gen mov cx,{ANYCON,$1}
600       joehoe {label,".loi"}
601
602 pat los $1==2
603   with CXREG BXREG
604   kills ALL
605   gen joehoe {label,".los"}
606
607 pat ldl                                 yields {LOCAL,$1+2,2}
608                                                {LOCAL,$1,2}
609
610 pat lde                                 yields {EXTERN2,$1 + 2}
611                                                {EXTERN2,$1}
612
613 pat ldf 
614   with exact reg_off                    yields {ind_regoff2,%1.reg,
615                                                 %1.off + 2 + $1}
616                                                {ind_regoff2,%1.reg,
617                                                 %1.off + $1}
618   with addreg                           yields {ind_regoff2,%1,$1+2}
619                                                {ind_regoff2,%1,$1}
620   with exact bpreg_off  yields {ind_bpregoff2,%1.reg,%1.ind+2+$1}
621                                {ind_bpregoff2,%1.reg,%1.ind+$1}
622   with exact ADDR_EXTERN        yields {EXTERN2,%1.off+2+$1}
623                                        {EXTERN2,%1.off+$1}
624   with exact ADDR_LOCAL         yields {LOCAL,%1.ind + $1 + 2,2}
625                                        {LOCAL,%1.ind + $1,2}
626
627 pat lpi                         yields {ADDR_EXTERN,$1}
628
629 /* this code sequence is generated by the C-compiler to tackle
630    char parameters, on the 8086 it reduces to nil */
631
632 pat lol lal sti $1==$2 && $3<=2
633
634 /*******************************************************************
635  *  Group 2 : Store Instructions                                   *
636  *******************************************************************/
637
638 #ifdef REGVARS
639 pat stl inreg($1)==reg_any
640   with rmorconst
641   kills regvar($1)
642   gen move %1, {LOCAL,$1,2}
643   with halfindir
644   kills regvar($1)
645   gen move %1, {LOCAL,$1,2}
646   with exact STACK
647   kills regvar($1)
648   gen pop {LOCAL, $1, 2}
649 #endif
650 pat stl
651   with regorconst
652   kills indexed,locals %ind+%size > $1 && %ind < $1+2
653   gen move %1,{LOCAL,$1,2}
654   with exact STACK
655   kills indexed,locals %ind+%size > $1 && %ind < $1+2
656   gen pop {LOCAL,$1,2}
657
658 pat ste
659   with regorconst
660   kills indirects
661   gen move %1,{EXTERN2,$1}
662   with exact STACK
663   kills indirects
664   gen pop {EXTERN2,$1}
665
666 #ifdef REGVARS
667 pat sil inreg($1)==reg_any
668   with regorconst
669   kills referals
670   gen move %1,{ind_reg2,regvar($1)}
671   with exact STACK
672   kills referals
673   gen pop {ind_reg2,regvar($1)}
674 #endif
675 pat sil
676   with regorconstnoaddr
677   kills referals
678   uses ADDREG={LOCAL,$1,2}
679   gen move %1,{ind_reg2,%a}
680       killreg %a
681   with exact STACK
682   kills referals
683   uses ADDREG={LOCAL,$1,2}
684   gen pop {ind_reg2,%a}
685       killreg %a
686
687 pat stf
688   with addreg regorconst
689   kills referals
690   gen move %2,{ind_regoff2,%1,$1}
691   with exact addreg STACK
692   kills referals
693   gen pop {ind_regoff2, %1,$1}
694   with reg_off regorconst
695   kills referals
696   gen move %2,{ind_regoff2,%1.reg,%1.off+$1}
697   with exact reg_off STACK
698   kills referals
699   gen pop {ind_regoff2,%1.reg,$1+%1.off}
700   with exact bpreg_off STACK
701   kills all_locals, indexed
702   gen pop {ind_bpregoff2,%1.reg,$1+%1.ind}
703   with ADDR_LOCAL regorconst
704   kills indexed,locals %ind+%size > %1.ind+$1 && %ind < %1.ind+$1+2
705   gen move %2,{LOCAL,%1.ind+$1,2}
706   with exact ADDR_LOCAL STACK
707   kills indexed,locals %ind+%size > %1.ind+$1 && %ind < %1.ind+$1+2
708   gen pop {LOCAL,%1.ind+$1,2}
709   with bpreg_off regorconst
710   kills all_locals,indexed
711   gen move %2,{ind_bpregoff2,%1.reg,%1.ind+$1}
712   with ADDR_EXTERN regorconst
713   kills indirects
714   gen move %2,{EXTERN2,%1.off+$1}
715   with exact ADDR_EXTERN STACK
716   kills indirects
717   gen pop {EXTERN2,%1.off+$1}
718
719 pat sti $1==2
720   with addreg regorconst
721   kills referals
722   gen move %2,{ind_reg2,%1}
723   with exact addreg STACK
724   kills referals
725   gen pop {ind_reg2,%1}
726   with reg_off regorconst
727   kills referals
728   gen move %2,{ind_regoff2,%1.reg,%1.off}
729   with exact reg_off STACK
730   kills referals
731   gen pop {ind_regoff2,%1.reg,%1.off}
732   with bpreg_off regorconst
733   kills all_locals,indexed
734   gen move %2,{ind_bpregoff2,%1.reg,%1.ind}
735   with exact bpreg_off STACK
736   kills all_locals,indexed
737   gen pop {ind_bpregoff2,%1.reg,%1.ind}
738   with ADDR_EXTERN regorconst
739   kills indirects
740   gen move %2,{EXTERN2,%1.off}
741   with exact ADDR_EXTERN STACK
742   kills indirects
743   gen pop {EXTERN2,%1.off}
744   with ADDR_LOCAL regorconst
745   kills indexed,locals %ind+%size > %1.ind && %ind < %1.ind+2
746   gen move %2,{LOCAL,%1.ind,2}
747   with exact ADDR_LOCAL STACK
748   kills indexed,locals %ind+%size > %1.ind && %ind < %1.ind+2
749   gen pop {LOCAL,%1.ind,2}
750
751 pat sti $1==1
752   with addreg regorconst12
753   kills referals
754   gen move %2,{ind_reg1,%1}
755   with reg_off regorconst12
756   kills referals
757   gen move %2,{ind_regoff1,%1.reg,%1.off}
758   with bpreg_off regorconst12
759   kills all_locals,indexed
760   gen move %2,{ind_bpregoff1,%1.reg,%1.ind}
761   with ADDR_EXTERN regorconst12
762   kills indirects
763   gen move %2,{EXTERN1,%1.off}
764   with ADDR_LOCAL regorconst12
765   kills indexed,locals %ind+%size > %1.ind && %ind <= %1.ind
766   gen move %2,{LOCAL1,%1.ind,1}
767
768 pat sti $1==4                           leaving sdf 0
769
770 pat sti $1>4
771   with BXREG
772   kills ALL
773   gen mov cx,{ANYCON,$1}
774       joehoe {label, ".sti"}
775
776 /* this sort of construction gives problems in the codegenerator
777    because of the potential very large lookahead                 
778
779   with addreg 
780   kills ALL
781   gen pop (%1)
782       add %1,{ANYCON,2}                 yields %1       leaving sti $1-2
783
784 */
785
786 pat sts $1==2
787   with CXREG BXREG
788   kills ALL
789   gen joehoe {label,".sts"}
790
791 pat sdl
792   with regorconst regorconst    yields %2 %1
793                                         leaving stl $1 stl $1+2
794   with exact STACK                      leaving stl $1 stl $1+2
795
796 pat sde
797   with regorconst regorconst    yields %2 %1
798                                         leaving ste $1 ste $1+2
799   with exact STACK                      leaving ste $1 ste $1+2
800
801 pat sdf         
802   with addreg regorconst regorconst
803   kills referals
804   gen move %2,{ind_regoff2,%1,$1}
805       move %3,{ind_regoff2,%1,$1+2}
806   with exact addreg STACK
807   kills referals
808   gen pop {ind_regoff2,%1,$1}
809       pop {ind_regoff2,%1,$1+2}
810   with exact halfindir STACK
811   kills referals
812   uses reusing %1,ADDREG=%1
813   gen pop {ind_regoff2,%a,$1}
814       pop {ind_regoff2,%a,$1+2}
815   with exact memory2 STACK
816   kills referals
817   uses reusing %1,ADDREG=%1
818   gen pop {ind_regoff2,%a,$1}
819       pop {ind_regoff2,%a,$1+2}
820   with reg_off regorconst regorconst
821   kills referals
822   gen move %2,{ind_regoff2,%1.reg,%1.off+$1}
823       move %3,{ind_regoff2,%1.reg,%1.off+$1+2}
824   with exact reg_off STACK
825   kills referals
826   gen pop {ind_regoff2,%1.reg,$1+%1.off}
827       pop {ind_regoff2,%1.reg,$1+2+%1.off}
828   with exact bpreg_off STACK
829   kills all_locals,indexed
830   gen pop {ind_bpregoff2, %1.reg,$1+%1.ind}
831       pop {ind_bpregoff2, %1.reg,$1+2+%1.ind}
832   with ADDR_LOCAL regorconst regorconst
833   kills indexed,locals %ind+%size > %1.ind+$1 && %ind < %1.ind+$1+4
834   gen   move %2,{LOCAL,%1.ind+$1,2}
835         move %3,{LOCAL,%1.ind+$1+2,2}
836   with exact ADDR_LOCAL STACK
837   kills indexed,locals %ind+%size > %1.ind+$1 && %ind < %1.ind+$1+4
838   gen   pop {LOCAL,%1.ind+$1,2}
839         pop {LOCAL,%1.ind+$1+2,2}
840   with ADDR_EXTERN regorconst regorconst
841   kills indirects
842   gen   move %2,{EXTERN2,%1.off+$1}
843         move %3,{EXTERN2,%1.off+$1+2}
844   with exact ADDR_EXTERN STACK
845   kills indirects
846   gen   pop {EXTERN2,%1.off+$1}
847         pop {EXTERN2,%1.off+$1+2}
848   with bpreg_off regorconst regorconst
849   kills all_locals,indexed
850   gen move %2,{ind_bpregoff2,%1.reg,%1.ind+$1}
851       move %3,{ind_bpregoff2,%1.reg,%1.ind+$1+2}
852
853
854 /****************************************************************
855  *  Group 3 : Integer Arithmetic.                               *
856  *                                                              *
857  *  Implemented (sometimes with the use of subroutines) :       *
858  *  all 2 and 4 byte arithmetic.                                *
859  ****************************************************************/
860
861 pat adi $1==2
862 #ifdef REGVARS
863 with exact ANYCON IREG
864                                 yields {Rreg_off,%2,%1.val}
865 with exact IREG ANYCON
866                                 yields {Rreg_off,%1,%2.val}
867 #endif
868 with REG rmorconst
869   gen add %1,%2                 yields %1
870 with rmorconst REG
871   gen add %2,%1                 yields %2
872 with EXACT rmorconst const
873   uses reusing %1,REG=%1
874   gen add %a,%2                 yields %a
875
876 pat adi $1==4
877 with EXACT REG REG rmorconst rmorconst
878   gen add %1,%3
879       adc %2,%4                 yields %2 %1
880 with rmorconst rmorconst REG REG
881   gen add %3,%1
882       adc %4,%2                 yields %4 %3
883
884 pat adi !defined($1)
885 with CXREG ACC
886   kills ALL
887   gen joehoe {label,".adi"}     yields ax
888
889 pat sbi $1==2
890
891 with rmorconst REG
892   gen sub %2,%1                 yields %2
893 with EXACT REG rmorconst
894   gen sub %1,%2
895       neg %1                    yields %1
896
897 pat sbi $1==4
898 with rmorconst rmorconst REG REG
899   gen sub %3,%1
900       sbb %4,%2                 yields %4 %3
901
902 pat sbi !defined($1)
903 with CXREG ACC
904   kills ALL
905   gen joehoe {label,".sbi"}     yields ax
906
907 pat mli $1==2
908 with ACC rm
909   uses reusing %2,DXREG
910   gen mul %2                    yields %1
911                         /* mul and imul have same low order result
912                            but mul is faster
913                         */
914
915 with rmnoacc rmorconst
916   uses reusing %2,DXREG,ACC=%2
917   gen mul %1                    yields %b
918
919 pat mli $1==4
920 with ACC DXREG
921   kills ALL
922   gen joehoe {label,".mli4"}    yields dx ax
923
924 /* 
925 pat mli !defined($1)
926 with ACC
927   kills ALL
928   gen joehoe {label,".mli"}
929 */
930
931 pat dvi $1==2
932 with rmnoacc rmorconst
933   uses reusing %2,DXREG,ACC=%2
934   gen cwd.
935       idiv %1                   yields ax
936
937 pat dvi $1==4
938 kills ALL
939   gen joehoe {label,".dvi4"}    yields dx ax
940
941 /*
942 pat dvi !defined($1)
943 with ACC
944   kills ALL
945   gen joehoe {label,".dvi"}
946 */
947
948 pat rmi $1==2
949 with rmnoacc rmorconst
950   uses reusing %2, ACC=%2, DXREG
951   gen cwd.
952       idiv %1                   yields dx
953
954 pat rmi $1==4
955 kills ALL
956   gen joehoe {label,".rmi4"}    yields dx ax
957
958 /*
959 pat rmi !defined($1)
960 with ACC
961   kills ALL
962   gen joehoe {label,".rmi"}
963 */
964
965 pat ngi $1==2
966 with REG
967   gen neg %1                    yields %1
968
969 pat ngi $1==4
970 with REG REG
971   gen neg %2
972       neg %1
973       sbb %2,{ANYCON,0}         yields %2 %1
974
975 /*
976 pat ngi !defined($1)
977 with ACC
978   kills ALL
979   gen joehoe {label,".ngi"}
980 */
981
982 pat loc sli $1==1 && $2==2
983 with REG
984   gen sal %1,{ANYCON,1}         yields %1
985
986 pat loc sli $1==1 && $2==4
987 with REG REG
988   gen sal %1,{ANYCON,1}
989       rcl %2,{ANYCON,1}         yields %2 %1
990
991 pat loc sli $1==2 && $2==4
992 with REG REG
993   gen sal %1,{ANYCON,1}
994       rcl %2,{ANYCON,1}
995       sal %1,{ANYCON,1}
996       rcl %2,{ANYCON,1}         yields %2 %1
997
998 pat loc sli $1==3 && $2==4
999 with REG REG
1000   gen sal %1,{ANYCON,1}
1001       rcl %2,{ANYCON,1}
1002       sal %1,{ANYCON,1}
1003       rcl %2,{ANYCON,1}
1004       sal %1,{ANYCON,1}
1005       rcl %2,{ANYCON,1}         yields %2 %1
1006
1007 pat loc sli $1==16 && $2==4
1008 with rmorconst rmorconst        yields %1 {ANYCON,0}
1009
1010 pat sli $1==2
1011 with SHIFT_CREG REG
1012   gen sal %2,cl                 yields %2
1013
1014 pat sli $1==4
1015 with CXREG REG REG
1016   gen jcxz {label,1f}
1017       2:
1018       sal %2,{ANYCON,1}
1019       rcl %3,{ANYCON,1}
1020       loop {label,2b}
1021       1:
1022                                 yields %3 %2
1023
1024 /*
1025 pat sli !defined($1)
1026 with ACC
1027   kills ALL
1028   gen joehoe {label,".sli"}
1029 */
1030
1031 pat loc sri $1==1 && $2==2
1032 with REG
1033   gen sar %1,{ANYCON,1}         yields %1
1034
1035 pat loc sri $1==1 && $2==4
1036 with REG REG
1037   gen sar %2,{ANYCON,1}
1038       rcr %1,{ANYCON,1}         yields %2 %1
1039
1040 pat loc sri $1==2 && $2==4
1041 with REG REG
1042   gen sar %2,{ANYCON,1}
1043       rcr %1,{ANYCON,1}
1044       sar %2,{ANYCON,1}
1045       rcr %1,{ANYCON,1}         yields %2 %1
1046
1047 pat loc sri $1==3 && $2==4
1048 with REG REG
1049   gen sar %2,{ANYCON,1}
1050       rcr %1,{ANYCON,1}
1051       sar %2,{ANYCON,1}
1052       rcr %1,{ANYCON,1}
1053       sar %2,{ANYCON,1}
1054       rcr %1,{ANYCON,1}         yields %2 %1
1055
1056 pat sri $1==2
1057 with SHIFT_CREG REG
1058   gen sar %2,cl                 yields %2
1059
1060 pat sri $1==4
1061 with CXREG REG REG
1062   gen jcxz {label,1f}
1063       2:
1064       sar %3,{ANYCON,1}
1065       rcr %2,{ANYCON,1}
1066       loop {label,2b}
1067       1:
1068                                 yields %3 %2
1069
1070 /*
1071 pat sri !defined($1)
1072 with ACC
1073   kills ALL
1074   gen joehoe {label,".sri"}
1075 */
1076
1077 /*******************************************************************
1078  *  Group 4: Unsigned Arithmetic                                   *
1079  *******************************************************************/
1080
1081 pat adu                                 leaving adi $1
1082 pat loc lol adu stl $1==1 && $3==2 && $2==$4    leaving inl $2
1083 pat loc loe adu ste $1==1 && $3==2 && $2==$4    leaving ine $2
1084 pat loc lol adu $1==1 && $3==2          leaving lol $2 inc
1085 pat loc loe adu $1==1 && $3==2          leaving loe $2 inc
1086 pat loc lil adu $1==1 && $3==2          leaving lil $2 inc
1087 pat loc lol adu stl $1==0-1 && $3==2 && $2==$4  leaving del $2
1088 pat loc loe adu ste $1==0-1 && $3==2 && $2==$4  leaving dee $2
1089 pat loc lol adu $1==0-1 && $3==2                leaving lol $2 dec
1090 pat loc loe adu $1==0-1 && $3==2                leaving loe $2 dec
1091 pat loc lil adu $1==0-1 && $3==2                leaving lil $2 dec
1092 pat sbu                                 leaving sbi $1
1093 pat lol loc sbu stl $1==$4 && $2==1 && $3==2    leaving del $1
1094 pat loe loc sbu ste $1==$4 && $2==1 && $3==2    leaving dee $1
1095 pat lol loc sbu $2==1 && $3==2          leaving lol $1 dec
1096 pat loe loc sbu $2==1 && $3==2          leaving loe $1 dec
1097 pat lil loc sbu $2==1 && $3==2          leaving lil $1 dec
1098 pat lol loc sbu stl $1==$4 && $2==0-1 && $3==2  leaving inl $1
1099 pat loe loc sbu ste $1==$4 && $2==0-1 && $3==2  leaving ine $1
1100 pat lol loc sbu $2==0-1 && $3==2                leaving lol $1 inc
1101 pat loe loc sbu $2==0-1 && $3==2                leaving loe $1 inc
1102 pat lil loc sbu $2==0-1 && $3==2                leaving lil $1 inc
1103 pat mlu                                 leaving mli $1
1104
1105 pat loe loc loe adu ste $1==$3 && $1==$5 && $4==2
1106 uses REG = {EXTERN2, $1}
1107                                 yields %a leaving loc $2 loe $3 adu 2 ste $3
1108
1109 pat lol loc lol adu stl $1==$3 && $1==$5 && $4==2
1110 uses REG = {LOCAL, $1, 2}
1111                                 yields %a leaving loc $2 lol $3 adu 2 stl $3
1112
1113 pat loe loc loe adi ste $1==$3 && $1==$5 && $4==2
1114 uses REG = {EXTERN2, $1}
1115                                 yields %a leaving loc $2 loe $3 adi 2 ste $3
1116
1117 pat lol loc lol adi stl $1==$3 && $1==$5 && $4==2
1118 uses REG = {LOCAL, $1, 2}
1119                                 yields %a leaving loc $2 lol $3 adi 2 stl $3
1120
1121 pat dvu $1==2
1122 with rmnoacc rmorconst
1123 uses reusing %2, ACC=%2,  DXREG={ANYCON,0}
1124 gen div %1                      yields ax
1125
1126 pat dvu $1==4
1127 kills ALL
1128 gen joehoe {label,".dvu4"}      yields dx ax
1129
1130 /*
1131 pat dvu !defined($1)
1132 with ACC STACK
1133 kills ALL
1134 gen joehoe {label,".dvu"}
1135 */
1136
1137 pat rmu $1==2
1138 with rmnoacc rmorconst
1139 uses reusing %2, ACC=%2, DXREG={ANYCON,0}
1140 gen div %1                      yields dx
1141
1142 pat rmu $1==4
1143 kills ALL
1144 gen joehoe {label,".rmu4"}      yields dx ax
1145
1146 /*
1147 pat rmu !defined($1)
1148 with ACC STACK
1149 kills ALL
1150 gen joehoe {label,".rmu"}
1151 */
1152
1153 pat slu                                 leaving sli $1
1154 pat loc slu                             leaving loc $1 sli $2
1155
1156 pat loc sru $1==1 && $2==2
1157 with REG
1158 gen shr %1,{ANYCON, 1}                  yields %1
1159
1160 pat loc sru $1==16 && $2==4
1161 with rmorconst rmorconst                yields {ANYCON,0} %2
1162
1163 pat sru $1==2
1164 with SHIFT_CREG REG
1165 gen shr %2,cl                   yields %2
1166
1167 pat sru $1==4
1168 with CXREG REG REG
1169 gen jcxz {label,1f}
1170     2:
1171     shr %3,{ANYCON, 1}
1172     rcr %2,{ANYCON, 1}
1173     loop {label,2b}
1174     1:                          yields %3 %2
1175
1176 /*
1177 pat sru !defined($1)
1178 with ACC STACK
1179 kills ALL
1180 gen joehoe {label,".sru"}
1181 */
1182
1183 /*******************************************************************
1184  *  Group 5: Floating Point Instructions                           *
1185  *******************************************************************/
1186
1187 pat adf $1==4           leaving cal ".adf4" asp 4
1188 pat adf $1==8           leaving cal ".adf8" asp 8
1189 pat sbf $1==4           leaving cal ".sbf4" asp 4
1190 pat sbf $1==8           leaving cal ".sbf8" asp 8
1191 pat mlf $1==4           leaving cal ".mlf4" asp 4
1192 pat mlf $1==8           leaving cal ".mlf8" asp 8
1193 pat dvf $1==4           leaving cal ".dvf4" asp 4
1194 pat dvf $1==8           leaving cal ".dvf8" asp 8
1195 pat ngf $1==4           leaving cal ".ngf4"
1196 pat ngf $1==8           leaving cal ".ngf8"
1197 pat fif $1==4           leaving lor 1 cal ".fif4" asp 2
1198 pat fif $1==8           leaving lor 1 cal ".fif8" asp 2
1199 pat fef $1==4           leaving lor 1 adp 0-2 cal ".fef4"
1200 pat fef $1==8           leaving lor 1 adp 0-2 cal ".fef8"
1201
1202 /******************************************************************
1203  *  Group 6: Pointer Arithmetic                                   *
1204  ******************************************************************/
1205
1206 pat adp $1==1
1207 with exact Xreg_off     yields {Xreg_off,%1.reg,%1.off+$1}
1208 with exact Rreg_off     yields {Rreg_off,%1.reg,%1.off+$1}
1209 with exact ADDR_EXTERN  yields {ADDR_EXTERN,%1.off+$1}
1210 with exact ADDR_LOCAL   yields {ADDR_LOCAL,%1.ind+$1}
1211 with exact Rbpreg_off   yields {Rbpreg_off,%1.reg,%1.ind+$1}
1212 with REG
1213   gen inc %1            yields %1
1214 with ADDREG
1215   gen killreg %1
1216                         yields {Xreg_off, %1, $1}
1217 with exact RADDREG      yields {Rreg_off, %1, $1}
1218
1219 pat adp $1==0-1
1220 with exact Xreg_off     yields {Xreg_off,%1.reg,%1.off+$1}
1221 with exact Rreg_off     yields {Rreg_off,%1.reg,%1.off+$1}
1222 with exact ADDR_EXTERN  yields {ADDR_EXTERN,%1.off+$1}
1223 with exact ADDR_LOCAL   yields {ADDR_LOCAL,%1.ind+$1}
1224 with exact Rbpreg_off   yields {Rbpreg_off,%1.reg,%1.ind+$1}
1225 with REG
1226   gen dec %1            yields %1
1227 with ADDREG
1228   gen killreg %1
1229                         yields {Xreg_off, %1, $1}
1230 with exact RADDREG      yields {Rreg_off, %1, $1}
1231
1232 pat adp
1233 with exact Xreg_off     yields {Xreg_off,%1.reg,%1.off+$1}
1234 with exact Rreg_off     yields {Rreg_off,%1.reg,%1.off+$1}
1235 with exact ADDR_EXTERN  yields {ADDR_EXTERN,%1.off+$1}
1236 with exact ADDR_LOCAL   yields {ADDR_LOCAL,%1.ind+$1}
1237 with exact Rbpreg_off   yields {Rbpreg_off,%1.reg,%1.ind+$1}
1238 with ADDREG
1239   gen killreg %1
1240                         yields {Xreg_off,%1,$1}
1241 with exact RADDREG      yields {Rreg_off, %1, $1}
1242 with REG
1243   gen add %1,{ANYCON,$1}        yields %1
1244
1245 pat ads stl $1==2                       leaving adi 2 stl $2
1246 pat ads ste $1==2                       leaving adi 2 ste $2
1247 pat ads sil $1==2                       leaving adi 2 sil $2
1248 pat ads lol stf $1==2                   leaving adi 2 lol $2 stf $3
1249 pat ads loe stf $1==2                   leaving adi 2 loe $2 stf $3
1250
1251 pat ads $1==2
1252 with exact ANYCON Rreg_off
1253                         yields {Rreg_off,%2.reg,%2.off+%1.val}
1254 with exact ANYCON Xreg_off
1255                         yields {Xreg_off,%2.reg,%2.off+%1.val}
1256 with exact ADDR_EXTERN Rreg_off
1257                         yields {Rreg_off,%2.reg,%2.off+%1.off}
1258 with exact ADDR_EXTERN Xreg_off
1259                         yields {Xreg_off,%2.reg,%2.off+%1.off}
1260 with rmorconst Xreg_off
1261   gen add %2.reg,%1     yields %2
1262 with exact ANYCON Rbpreg_off
1263                         yields {Rbpreg_off,%2.reg,%2.ind+%1.val}
1264 with Xreg_off rmorconst
1265   gen add %1.reg,%2     yields %1
1266 with exact Xreg_off ANYCON
1267                         yields {Xreg_off,%1.reg,%1.off+%2.val}
1268 with exact Rreg_off ANYCON
1269                         yields {Rreg_off,%1.reg,%1.off+%2.val}
1270 with exact Xreg_off ADDR_EXTERN
1271                         yields {Xreg_off,%1.reg,%1.off+%2.off}
1272 with exact Rreg_off ADDR_EXTERN
1273                         yields {Rreg_off,%1.reg,%1.off+%2.off}
1274 with exact Xreg_off reg_off
1275   gen add %1.reg,%2.reg
1276                         yields {Xreg_off,%1.reg,%1.off+%2.off}
1277 with exact IREG ADDR_LOCAL
1278                         yields {Rbpreg_off, %1, %2.ind}
1279 with exact IREG ADDR_EXTERN
1280                         yields {Rreg_off, %1, %2.off}
1281 with exact ADDR_EXTERN IREG
1282                         yields {Rreg_off,%2,%1.off}
1283 with exact ADDR_LOCAL IREG
1284                         yields {Rbpreg_off,%2,%1.ind}
1285
1286 with exact rmorconst ADDR_EXTERN
1287   uses reusing %1,ADDREG=%1
1288                         yields {Xreg_off,%a,%2.off}
1289 with exact ADDR_EXTERN rmorconst
1290   uses reusing %2,ADDREG=%2
1291                         yields {Xreg_off,%a,%1.off}
1292 with rmorconst ADDREG
1293   gen add %2,%1         yields %2
1294 with ADDREG rmorconst
1295   gen add %1,%2         yields %1
1296
1297 pat sbs $1==2
1298 with exact ANYCON Xreg_off
1299                         yields {Xreg_off,%2.reg,%2.off+"-"+%1.val}
1300 with exact ANYCON Rreg_off
1301                         yields {Rreg_off,%2.reg,%2.off+"-"+%1.val}
1302 with exact ANYCON ADDR_LOCAL
1303                         yields {ADDR_LOCAL,%2.ind-%1.val}
1304 with rm Xreg_off
1305   gen sub %2.reg,%1     yields {Xreg_off,%2.reg,%2.off}
1306
1307 /* Should not occur
1308 with exact reg_off ANYCON
1309                         yields {reg_off,%1.reg,%1.off-%2.val}
1310 with ANYCON ADDR_EXTERN
1311                         yields {ADDR_EXTERN,%2.off+%1.val}
1312 with exact ANYCON ADDR_LOCAL
1313                         yields {ADDR_LOCAL,%1.val+%2.ind}
1314 */
1315
1316 with rm REG
1317   gen sub %2,%1         yields %2
1318 with const ACC
1319   gen sub %2,%1         yields %2
1320
1321 /*******************************************************************
1322  *  Group 7 : Increment/Decrement Zero                             *
1323  *******************************************************************/
1324
1325 pat inc
1326 with REG
1327 gen inc %1                      yields %1
1328
1329 #ifdef REGVARS
1330 pat inl inreg($1)==reg_any
1331   kills regvar($1)
1332   gen inc {LOCAL,$1,2}
1333 #endif
1334
1335 pat inl 
1336 kills indexed,locals %ind+%size > $1 && %ind < $1+2
1337 gen inc {LOCAL, $1, 2}
1338
1339 pat ine
1340 kills indirects
1341 gen inc {EXTERN2, $1}
1342
1343 pat dec
1344 with REG
1345 gen dec %1                      yields %1
1346
1347 #ifdef REGVARS
1348 pat del inreg($1)==reg_any
1349   kills regvar($1)
1350   gen dec {LOCAL,$1,2}
1351 #endif
1352
1353 pat del 
1354 kills indexed,locals %ind+%size > $1 && %ind < $1+2
1355 gen dec {LOCAL, $1, 2}
1356
1357 pat dee
1358 kills indirects
1359 gen dec {EXTERN2, $1}
1360
1361 pat zrl                         yields {ANYCON, 0}      leaving stl $1
1362
1363 pat zre                         yields {ANYCON, 0}      leaving ste $1
1364
1365 pat zrf                 leaving zer $1
1366
1367 pat zer $1==2                   yields {ANYCON, 0}      
1368 pat zer $1==4                   yields {ANYCON, 0} {ANYCON, 0}  
1369 pat zer $1==6                   yields {ANYCON, 0} {ANYCON, 0} 
1370                                        {ANYCON, 0}      
1371 pat zer $1==8                   yields {ANYCON, 0} {ANYCON, 0} 
1372                                        {ANYCON, 0} {ANYCON, 0}  
1373
1374 pat zer defined($1)
1375 with STACK
1376 gen move {ANYCON, $1/2}, cx
1377     move {ANYCON, 0}, bx
1378     1:
1379     push bx
1380     loop {label,1b}
1381
1382 pat zer !defined($1)
1383 with CXREG STACK
1384 gen move {ANYCON, 0}, bx
1385     sar cx,{ANYCON, 1}
1386     1:
1387     push bx
1388     loop {label,1b}
1389
1390 #ifdef REGVARS
1391 proc lolrxxxstl example lol adi stl
1392 with rmorconst
1393   kills regvar($1)
1394   gen axx* {LOCAL, $1, 2}, %1
1395
1396 proc lilrxxxsil example lil adi sil
1397 with regorconst
1398 kills referals
1399 gen axx* {ind_reg2, regvar($1)}, %1
1400
1401 pat lol adi stl $1==$3 && $2==2 && inreg($1)==reg_any   call lolrxxxstl("add")
1402 pat lol adu stl $1==$3 && $2==2 && inreg($1)==reg_any   call lolrxxxstl("add")
1403 pat lol ads stl $1==$3 && $2==2 && inreg($1)==reg_any   call lolrxxxstl("add")
1404 pat lol and stl $1==$3 && $2==2 && inreg($1)==reg_any   call lolrxxxstl("and")
1405 pat lol ior stl $1==$3 && $2==2 && inreg($1)==reg_any   call lolrxxxstl("or")
1406 pat lol xor stl $1==$3 && $2==2 && inreg($1)==reg_any   call lolrxxxstl("xor")
1407
1408 pat lil adi sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilrxxxsil("add")
1409 pat lil adu sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilrxxxsil("add")
1410 pat lil ads sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilrxxxsil("add")
1411 pat lil and sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilrxxxsil("and")
1412 pat lil ior sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilrxxxsil("or")
1413 pat lil xor sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilrxxxsil("xor")
1414 #endif
1415
1416 proc lolxxxstl example lol adi stl
1417 with regorconst
1418 kills indexed,locals %ind+%size > $1 && %ind < $1+2
1419 gen axx* {LOCAL, $1, 2}, %1
1420
1421 pat lol adi stl $1==$3 && $2==2         call lolxxxstl("add")
1422 pat lol adu stl $1==$3 && $2==2         call lolxxxstl("add")
1423 pat lol ads stl $1==$3 && $2==2         call lolxxxstl("add")
1424 pat lol and stl $1==$3 && $2==2         call lolxxxstl("and")
1425 pat lol ior stl $1==$3 && $2==2         call lolxxxstl("or")
1426 pat lol xor stl $1==$3 && $2==2         call lolxxxstl("xor")
1427
1428 proc lilxxxsil example lil adi sil
1429 with regorconst
1430 kills referals
1431 uses ADDREG={LOCAL, $1, 2}
1432 gen axx* {ind_reg2, %a}, %1
1433     killreg %a
1434
1435 pat lil adi sil $1==$3 && $2==2         call lilxxxsil("add")
1436 pat lil adu sil $1==$3 && $2==2         call lilxxxsil("add")
1437 pat lil ads sil $1==$3 && $2==2         call lilxxxsil("add")
1438 pat lil and sil $1==$3 && $2==2         call lilxxxsil("and")
1439 pat lil ior sil $1==$3 && $2==2         call lilxxxsil("or")
1440 pat lil xor sil $1==$3 && $2==2         call lilxxxsil("xor")
1441
1442 #ifdef REGVARS
1443 proc lilruxxsil example lil ngi sil
1444 kills referals
1445 gen uxx* {ind_reg2, regvar($1)}
1446
1447 pat lil ngi sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilruxxsil("neg")
1448 pat lil com sil $1==$3 && $2==2 && inreg($1)==reg_any   call lilruxxsil("not")
1449 pat lil dec sil $1==$3 && inreg($1)==reg_any            call lilruxxsil("dec")
1450 pat lil inc sil $1==$3 && inreg($1)==reg_any            call lilruxxsil("inc")
1451 #endif
1452
1453 proc liluxxsil example lil ngi sil
1454 kills referals
1455 uses ADDREG={LOCAL, $1, 2}
1456 gen uxx* {ind_reg2, %a}
1457     killreg %a
1458
1459 pat lil ngi sil $1==$3 && $2==2         call liluxxsil("neg")
1460 pat lil com sil $1==$3 && $2==2         call liluxxsil("not")
1461 pat lil dec sil $1==$3                  call liluxxsil("dec")
1462 pat lil inc sil $1==$3                  call liluxxsil("inc")
1463
1464 proc loexxxste example loe adi ste
1465 with regorconst
1466 kills indirects
1467 gen axx* {EXTERN2, $1}, %1
1468
1469 pat loe adi ste $1==$3 && $2==2         call loexxxste("add")
1470 pat loe adu ste $1==$3 && $2==2         call loexxxste("add")
1471 pat loe ads ste $1==$3 && $2==2         call loexxxste("add")
1472 pat loe and ste $1==$3 && $2==2         call loexxxste("and")
1473 pat loe ior ste $1==$3 && $2==2         call loexxxste("or")
1474 pat loe xor ste $1==$3 && $2==2         call loexxxste("xor")
1475
1476 proc ldlxxxsdl example ldl adi sdl
1477 with regorconst regorconst
1478   kills indexed,locals %ind+%size > $1 && %ind < $1+4
1479   gen axx[1] {LOCAL,$1,2},%1
1480       axx[2] {LOCAL,$1+2,2},%2
1481
1482 pat ldl adi sdl $1==$3 && $2==4         call ldlxxxsdl("add", "adc")
1483 pat ldl adu sdl $1==$3 && $2==4         call ldlxxxsdl("add", "adc")
1484 pat ldl and sdl $1==$3 && $2==4         call ldlxxxsdl("and", "and")
1485 pat ldl ior sdl $1==$3 && $2==4         call ldlxxxsdl("or", "or")
1486 pat ldl xor sdl $1==$3 && $2==4         call ldlxxxsdl("xor", "xor")
1487
1488 proc ldlcxxsdl example ldl ldc sbi sdl
1489   kills indexed,locals %ind+%size > $1 && %ind < $1+4
1490   gen axx[1] {LOCAL,$1,2},{ANYCON,loww($2)}
1491       axx[2] {LOCAL,$1+2,2},{ANYCON,highw($2)}
1492
1493 pat ldl ldc sbi sdl $1==$4 && $3==4     call ldlcxxsdl("sub", "sbb")
1494 pat ldl ldc sbu sdl $1==$4 && $3==4     call ldlcxxsdl("sub", "sbb")
1495
1496 proc ldexxxsde example lde adi sde
1497 with regorconst regorconst
1498   kills indirects
1499   gen axx[1] {EXTERN2,$1},%1
1500       axx[2] {EXTERN2,$1+2},%2
1501
1502 pat lde adi sde $1==$3 && $2==4         call ldexxxsde("add", "adc")
1503 pat lde adu sde $1==$3 && $2==4         call ldexxxsde("add", "adc")
1504 pat lde and sde $1==$3 && $2==4         call ldexxxsde("and", "and")
1505 pat lde ior sde $1==$3 && $2==4         call ldexxxsde("or", "or")
1506 pat lde xor sde $1==$3 && $2==4         call ldexxxsde("xor", "xor")
1507
1508 #ifdef REGVARS
1509 proc lofrxxxsof example lol lof adi lol stf
1510 with regorconst
1511 kills referals
1512 gen axx* {ind_regoff2, regvar($1), $2}, %1
1513
1514 pat lol lof adi lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1515                                         call lofrxxxsof("add")
1516 pat lol lof adu lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1517                                         call lofrxxxsof("add")
1518 pat lol lof ads lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1519                                         call lofrxxxsof("add")
1520 pat lol lof and lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1521                                         call lofrxxxsof("and")
1522 pat lol lof ior lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1523                                         call lofrxxxsof("or")
1524 pat lol lof xor lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1525                                         call lofrxxxsof("xor")
1526
1527 proc ldfrxxxsdf example lol ldf adi lol sdf
1528 with regorconst regorconst
1529 kills referals
1530 gen axx[1] {ind_regoff2, regvar($1), $2}, %1
1531     axx[2] {ind_regoff2, regvar($1), $2+2}, %2
1532
1533 pat lol ldf adi lol sdf $1==$4 && $2==$5 && $3==4 && inreg($1)==reg_any
1534                                         call ldfrxxxsdf("add", "adc")
1535 pat lol ldf adu lol sdf $1==$4 && $2==$5 && $3==4 && inreg($1)==reg_any
1536                                         call ldfrxxxsdf("add", "adc")
1537 pat lol ldf and lol sdf $1==$4 && $2==$5 && $3==4 && inreg($1)==reg_any
1538                                         call ldfrxxxsdf("and", "and")
1539 pat lol ldf ior lol sdf $1==$4 && $2==$5 && $3==4 && inreg($1)==reg_any
1540                                         call ldfrxxxsdf("or", "or")
1541 pat lol ldf xor lol sdf $1==$4 && $2==$5 && $3==4 && inreg($1)==reg_any
1542                                         call ldfrxxxsdf("xor", "xor")
1543
1544 proc ldirxxxsdi example lol loi adi lol sti
1545 with regorconst regorconst
1546 kills referals
1547 gen axx[1] {ind_reg2, regvar($1)}, %1
1548     axx[2] {ind_regoff2, regvar($1), 2}, %2
1549
1550 pat lol loi adi lol sti $1==$4 && $2==4 && $5==4 && $3==4 && inreg($1)==reg_any
1551                                         call ldirxxxsdi("add", "adc")
1552 pat lol loi adu lol sti $1==$4 && $2==4 && $5==4 && $3==4 && inreg($1)==reg_any
1553                                         call ldirxxxsdi("add", "adc")
1554 pat lol loi and lol sti $1==$4 && $2==4 && $5==4 && $3==4 && inreg($1)==reg_any
1555                                         call ldirxxxsdi("and", "and")
1556 pat lol loi ior lol sti $1==$4 && $2==4 && $5==4 && $3==4 && inreg($1)==reg_any
1557                                         call ldirxxxsdi("or", "or")
1558 pat lol loi xor lol sti $1==$4 && $2==4 && $5==4 && $3==4 && inreg($1)==reg_any
1559                                         call ldirxxxsdi("xor", "xor")
1560
1561 proc lofruxxsof example lol lof inc lol stf
1562 kills referals
1563 gen uxx* {ind_regoff2, regvar($1), $2}
1564
1565 pat lol lof inc lol stf $1==$4 && $2==$5 && inreg($1)==reg_any
1566                                         call lofruxxsof("inc")
1567 pat lol lof dec lol stf $1==$4 && $2==$5 && inreg($1)==reg_any
1568                                         call lofruxxsof("dec")
1569 pat lol lof ngi lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1570                                         call lofruxxsof("neg")
1571 pat lol lof com lol stf $1==$4 && $2==$5 && $3==2 && inreg($1)==reg_any
1572                                         call lofruxxsof("not")
1573 #endif
1574
1575 proc lofuxxsof example lol lof inc lol stf
1576 kills referals
1577 uses ADDREG={LOCAL,$1,2}
1578 gen uxx* {ind_regoff2, %a, $2}
1579     killreg %a
1580
1581 pat lol lof ngi lol stf $1==$4 && $2==$5 && $3==2       call lofuxxsof("neg")
1582 pat lol lof com lol stf $1==$4 && $2==$5 && $3==2       call lofuxxsof("not")
1583 pat lol lof dec lol stf $1==$4 && $2==$5                call lofuxxsof("dec")
1584 pat lol lof inc lol stf $1==$4 && $2==$5                call lofuxxsof("inc")
1585
1586 proc lofxxxsof example lol lof adi lol stf
1587 with regorconstnoaddr
1588 kills referals
1589 uses ADDREG={LOCAL,$1,2}
1590 gen axx* {ind_regoff2, %a, $2}, %1
1591     killreg %a
1592
1593 pat lol lof adi lol stf $1==$4 && $2==$5 && $3==2       call lofxxxsof("add")
1594 pat lol lof adu lol stf $1==$4 && $2==$5 && $3==2       call lofxxxsof("add")
1595 pat lol lof ads lol stf $1==$4 && $2==$5 && $3==2       call lofxxxsof("add")
1596 pat lol lof and lol stf $1==$4 && $2==$5 && $3==2       call lofxxxsof("and")
1597 pat lol lof ior lol stf $1==$4 && $2==$5 && $3==2       call lofxxxsof("or")
1598 pat lol lof xor lol stf $1==$4 && $2==$5 && $3==2       call lofxxxsof("xor")
1599
1600 proc ldfxxxsdf example lol ldf adi lol sdf
1601 with regorconstnoaddr regorconstnoaddr
1602 kills referals
1603 uses ADDREG={LOCAL,$1,2}
1604 gen axx[1] {ind_regoff2, %a, $2}, %1
1605     axx[2] {ind_regoff2, %a, $2+2}, %2
1606     killreg %a
1607
1608 pat lol ldf adi lol sdf $1==$4 && $2==$5 && $3==4       call ldfxxxsdf("add", "adc")
1609 pat lol ldf adu lol sdf $1==$4 && $2==$5 && $3==4       call ldfxxxsdf("add", "adc")
1610 pat lol ldf and lol sdf $1==$4 && $2==$5 && $3==4       call ldfxxxsdf("and", "and")
1611 pat lol ldf ior lol sdf $1==$4 && $2==$5 && $3==4       call ldfxxxsdf("or", "or")
1612 pat lol ldf xor lol sdf $1==$4 && $2==$5 && $3==4       call ldfxxxsdf("xor", "xor")
1613
1614 proc ldixxxsdi example lol loi adi lol sti
1615 with regorconstnoaddr regorconstnoaddr
1616 kills referals
1617 uses ADDREG={LOCAL,$1,2}
1618 gen axx[1] {ind_reg2, %a}, %1
1619     axx[2] {ind_regoff2, %a, 2}, %2
1620     killreg %a
1621
1622 pat lol loi adi lol sti $1==$4 && $2==4 && $5==4 && $3==4
1623                                         call ldixxxsdi("add", "adc")
1624 pat lol loi adu lol sti $1==$4 && $2==4 && $5==4 && $3==4
1625                                         call ldixxxsdi("add", "adc")
1626 pat lol loi and lol sti $1==$4 && $2==4 && $5==4 && $3==4
1627                                         call ldixxxsdi("and", "and")
1628 pat lol loi ior lol sti $1==$4 && $2==4 && $5==4 && $3==4
1629                                         call ldixxxsdi("or", "or")
1630 pat lol loi xor lol sti $1==$4 && $2==4 && $5==4 && $3==4
1631                                         call ldixxxsdi("xor", "xor")
1632
1633 proc lefuxxsef example loe lof inc loe stf
1634 kills referals
1635 uses ADDREG={EXTERN2,$1}
1636 gen uxx* {ind_regoff2, %a, $2}
1637     killreg %a
1638
1639 pat loe lof ngi loe stf $1==$4 && $2==$5 && $3==2       call lefuxxsef("neg")
1640 pat loe lof com loe stf $1==$4 && $2==$5 && $3==2       call lefuxxsef("not")
1641 pat loe lof dec loe stf $1==$4 && $2==$5                call lefuxxsef("dec")
1642 pat loe lof inc loe stf $1==$4 && $2==$5                call lefuxxsef("inc")
1643
1644 proc lefxxxsef example loe lof adi loe stf
1645 with regorconstnoaddr
1646 kills referals
1647 uses ADDREG={EXTERN2,$1}
1648 gen axx* {ind_regoff2, %a, $2}, %1
1649     killreg %a
1650
1651 pat loe lof adi loe stf $1==$4 && $2==$5 && $3==2       call lefxxxsef("add")
1652 pat loe lof adu loe stf $1==$4 && $2==$5 && $3==2       call lefxxxsef("add")
1653 pat loe lof ads loe stf $1==$4 && $2==$5 && $3==2       call lefxxxsef("add")
1654 pat loe lof and loe stf $1==$4 && $2==$5 && $3==2       call lefxxxsef("and")
1655 pat loe lof ior loe stf $1==$4 && $2==$5 && $3==2       call lefxxxsef("or")
1656 pat loe lof xor loe stf $1==$4 && $2==$5 && $3==2       call lefxxxsef("xor")
1657
1658 proc leiuxxsei example loe loi inc loe sti
1659 kills referals
1660 uses ADDREG={EXTERN2,$1}
1661 gen uxx* {ind_reg2, %a}
1662     killreg %a
1663
1664 pat loe loi ngi loe sti $1==$4 && $2==2 && $5==2 && $3==2
1665                                                         call leiuxxsei("neg")
1666 pat loe loi com loe sti $1==$4 && $2==2 && $5==2 && $3==2
1667                                                         call leiuxxsei("not")
1668 pat loe loi dec loe sti $1==$4 && $2==2 && $5==2        call leiuxxsei("dec")
1669 pat loe loi inc loe sti $1==$4 && $2==2 && $5==2        call leiuxxsei("inc")
1670
1671 proc leixxxsei example loe loi adi loe sti
1672 with regorconstnoaddr
1673 kills referals
1674 uses ADDREG={EXTERN2,$1}
1675 gen axx* {ind_reg2, %a}, %1
1676     killreg %a
1677
1678 pat loe loi adi loe sti $1==$4 && $2==$5 && $2==2 && $3==2      call leixxxsei("add")
1679 pat loe loi adu loe sti $1==$4 && $2==$5 && $2==2 && $3==2      call leixxxsei("add")
1680 pat loe loi ads loe sti $1==$4 && $2==$5 && $2==2 && $3==2      call leixxxsei("add")
1681 pat loe loi and loe sti $1==$4 && $2==$5 && $2==2 && $3==2      call leixxxsei("and")
1682 pat loe loi ior loe sti $1==$4 && $2==$5 && $2==2 && $3==2      call leixxxsei("or")
1683 pat loe loi xor loe sti $1==$4 && $2==$5 && $2==2 && $3==2      call leixxxsei("xor")
1684
1685 #ifdef REGVARS
1686 proc lolcrxxstl example lol loc sbi stl
1687   kills regvar($1)
1688   gen axx* {LOCAL,$1,2},{ANYCON,$2}
1689
1690 pat lol loc sbi stl $1==$4 && $3==2 && inreg($1)==reg_any
1691                                                 call lolcrxxstl("sub")
1692 pat lol loc sbu stl $1==$4 && $3==2 && inreg($1)==reg_any
1693                                                 call lolcrxxstl("sub")
1694 pat lol loc sli stl $1==$4 && $3==2 && $2==1 && inreg($1)==reg_any
1695                                                 call lolcrxxstl("sal")
1696 pat lol loc slu stl $1==$4 && $3==2 && $2==1 && inreg($1)==reg_any
1697                                                 call lolcrxxstl("sal")
1698 pat lol loc sri stl $1==$4 && $3==2 && $2==1 && inreg($1)==reg_any
1699                                                 call lolcrxxstl("sar")
1700 pat lol loc sru stl $1==$4 && $3==2 && $2==1 && inreg($1)==reg_any
1701                                                 call lolcrxxstl("shr")
1702
1703 proc lolr2shstl example lol loc sli stl
1704   kills regvar($1)
1705   gen axx* {LOCAL,$1,2},{ANYCON,1}
1706       axx* {LOCAL,$1,2},{ANYCON,1}
1707
1708 pat lol loc sli stl $1==$4 && $3==2 && $2==2 && inreg($1)==reg_any
1709                                                 call lolr2shstl("sal")
1710 pat lol loc slu stl $1==$4 && $3==2 && $2==2 && inreg($1)==reg_any
1711                                                 call lolr2shstl("sal")
1712 pat lol loc sri stl $1==$4 && $3==2 && $2==2 && inreg($1)==reg_any
1713                                                 call lolr2shstl("sar")
1714 pat lol loc sru stl $1==$4 && $3==2 && $2==2 && inreg($1)==reg_any
1715                                                 call lolr2shstl("shr")
1716
1717 proc lolrcshstl example lol loc sli stl
1718   kills regvar($1)
1719   uses CXREG = {ANYCON,$2}
1720   gen sxx* {LOCAL,$1,2},cl
1721
1722 pat lol loc sli stl $1==$4 && $3==2 && inreg($1)==reg_any
1723                                                 call lolrcshstl("sal")
1724 pat lol loc slu stl $1==$4 && $3==2 && inreg($1)==reg_any
1725                                                 call lolrcshstl("sal")
1726 pat lol loc sri stl $1==$4 && $3==2 && inreg($1)==reg_any
1727                                                 call lolrcshstl("sar")
1728 pat lol loc sru stl $1==$4 && $3==2 && inreg($1)==reg_any
1729                                                 call lolrcshstl("shr")
1730
1731 #endif
1732
1733 proc lolcxxstl example lol loc sbi stl
1734   kills indexed,locals %ind+%size > $1 && %ind < $1+2
1735   gen axx* {LOCAL,$1,2},{ANYCON,$2}
1736
1737 pat lol loc sbi stl $1==$4 && $3==2             call lolcxxstl("sub")
1738 pat lol loc sbu stl $1==$4 && $3==2             call lolcxxstl("sub")
1739 pat lol loc sli stl $1==$4 && $3==2 && $2==1    call lolcxxstl("sal")
1740 pat lol loc slu stl $1==$4 && $3==2 && $2==1    call lolcxxstl("sal")
1741 pat lol loc sri stl $1==$4 && $3==2 && $2==1    call lolcxxstl("sar")
1742 pat lol loc sru stl $1==$4 && $3==2 && $2==1    call lolcxxstl("shr")
1743
1744 proc lolcshstl example lol loc sli stl
1745   kills indexed,locals %ind+%size > $1 && %ind < $1+2
1746   uses CXREG = {ANYCON,$2}
1747   gen sxx* {LOCAL,$1,2},cl
1748
1749 pat lol loc sli stl $1==$4 && $3==2     call lolcshstl("sal")
1750 pat lol loc slu stl $1==$4 && $3==2     call lolcshstl("sal")
1751 pat lol loc sri stl $1==$4 && $3==2     call lolcshstl("sar")
1752 pat lol loc sru stl $1==$4 && $3==2     call lolcshstl("shr")
1753
1754
1755 proc loecxxste example loe loc sbi ste
1756   kills indirects
1757   gen axx* {EXTERN2,$1},{ANYCON,$2}
1758
1759 pat loe loc sbi ste $1==$4 && $3==2             call loecxxste("sub")
1760 pat loe loc sbu ste $1==$4 && $3==2             call loecxxste("sub")
1761 pat loe loc adu ste $1==$4 && $3==2             call loecxxste("add")
1762 pat loe loc adi ste $1==$4 && $3==2             call loecxxste("add")
1763 pat loe loc sli ste $1==$4 && $3==2 && $2==1    call loecxxste("sal")
1764 pat loe loc slu ste $1==$4 && $3==2 && $2==1    call loecxxste("sal")
1765 pat loe loc sri ste $1==$4 && $3==2 && $2==1    call loecxxste("sar")
1766 pat loe loc sru ste $1==$4 && $3==2 && $2==1    call loecxxste("shr")
1767
1768 proc loecshste example loe loc sli ste
1769   kills indirects
1770   uses CXREG = {ANYCON,$2}
1771   gen sxx* {EXTERN2,$1},cl
1772
1773 pat loe loc sli ste $1==$4 && $3==2     call loecshste("sal")
1774 pat loe loc slu ste $1==$4 && $3==2     call loecshste("sal")
1775 pat loe loc sri ste $1==$4 && $3==2     call loecshste("sar")
1776 pat loe loc sru ste $1==$4 && $3==2     call loecshste("shr")
1777
1778 #ifdef REGVARS
1779 pat lol ngi stl $1==$3 && $2==2 && inreg($1)==reg_any
1780 kills regvar($1)
1781 gen neg {LOCAL, $1, 2}
1782 #endif
1783
1784 pat lol ngi stl $1==$3 && $2==2
1785 kills indexed,locals %ind+%size > $1 && %ind < $1+2
1786 gen neg {LOCAL, $1, 2}
1787
1788 pat ldl ngi sdl $1==$3 && $2==4
1789 kills indexed,locals %ind+%size > $1 && %ind < $1+4
1790 gen neg {LOCAL, $1+2, 2}
1791     neg {LOCAL, $1, 2}
1792     sbb {LOCAL, $1+2, 2}, {ANYCON, 0}
1793  
1794 pat lol dup adp stl loi stl $1==$4 && $2==2 && $5<=2
1795                                         leaving lol $1 loi $5 stl $6 lol $4 adp $3 stl $4
1796
1797 #ifdef REGVARS
1798 pat lol dup adp stl loi $1==$4 && $2==2 && $5==1 && inreg($1) > 0
1799 uses REG1 = {ind_reg1, regvar($1)}
1800                                 yields %a
1801                                         leaving lol $4 adp $3 stl $4
1802
1803 pat lol dup adp stl loi $1==$4 && $2==2 && $5==2 && inreg($1) > 0
1804 uses REG = {ind_reg2, regvar($1)}
1805                                 yields %a
1806                                         leaving lol $4 adp $3 stl $4
1807 pat adp stl inreg($2) > 0               leaving stl $2 lol $2 adp $1 stl $2
1808 #endif
1809
1810 pat lol dup adp stl $1==$4 && $2==2
1811 uses ADDREG={LOCAL,$1,2}        yields %a
1812                                         leaving lol $4 adp $3 stl $4
1813
1814 pat lol inl $1==$2
1815 uses REG={LOCAL,$1,2}           yields %a
1816                                         leaving inl $1
1817
1818 pat lol del $1==$2
1819 uses REG={LOCAL,$1,2}           yields %a
1820                                         leaving del $1
1821
1822 pat lol adp stl $1==$3 && $2==1         leaving inl $1
1823 pat lol adp stl $1==$3 && $2==0-1       leaving del $1
1824 pat lol adp stl $1==$3                  leaving loc $2 lol $1 adi 2 stl $3
1825
1826 #ifdef REGVARS
1827 pat lol com stl $1==$3 && $2==2 && inreg($1)==reg_any
1828 kills regvar($1)
1829 gen not {LOCAL,$1,2}
1830 #endif
1831
1832 pat lol com stl $1==$3 && $2==2
1833 kills indexed,locals %ind+%size > $1 && %ind < $1+2
1834 gen not {LOCAL, $1, 2}
1835
1836 pat lil adp dup sil lof $1==$4 && $3==2 && $5==(0-$2)
1837                                         leaving lil $4 dup 2 adp $2 sil $4 loi 2
1838
1839 #ifdef REGVARS
1840 pat lil dup adp sil $1==$4 && $2==2 && inreg($1)==reg_any
1841 uses ADDREG={ind_reg2, regvar($1)}
1842                                 yields %a
1843                                         leaving lil $4 adp $3 sil $4
1844
1845 pat lil adp dup sil $1==$4 && $3==2 && inreg($1)==reg_any
1846                                         leaving lil $4 adp $2 sil $4 lil $4
1847
1848 pat lil dup inc sil $1==$4 && $2==2 && inreg($1)==reg_any
1849 uses REG={ind_reg2, regvar($1)}
1850                                 yields %a
1851                                         leaving lil $4 inc sil $4
1852
1853 pat lil dup dec sil $1==$4 && $2==2 && inreg($1)==reg_any
1854 uses REG={ind_reg2, regvar($1)}
1855                                 yields %a
1856                                         leaving lil $4 dec sil $4
1857 #endif
1858
1859 pat lil adp sil $1==$3 && $2==1         leaving lil $1 inc sil $1
1860
1861 pat lil adp sil $1==$3 && $2==0-1       leaving lil $1 dec sil $1
1862
1863 pat lil adp sil $1==$3                  leaving loc $2 lil $1 adi 2 sil $3
1864
1865 pat lol lof adp lol stf $1==$4 && $2==$5 && $3==1
1866         leaving lol $1 lof $2 inc lol $4 stf $5
1867 pat lol lof adp lol stf $1==$4 && $2==$5 && $3==(0-1)
1868         leaving lol $1 lof $2 dec lol $4 stf $5
1869 pat lol lof adp lol stf $1==$4 && $2==$5        
1870         leaving loc $3 lol $1 lof $2 adi 2 lol $4 stf $5
1871
1872 #ifdef REGVARS
1873 pat lol lof lol lof adp lol stf 
1874         $1==$3 && $1==$6 && $2==$4 && $2==$7 && inreg($1)==reg_any
1875 uses ADDREG={ind_regoff2, regvar($1), $2}
1876                                 yields %a
1877                                         leaving lol $1 lof $2 adp $5 lol $6 stf $7
1878
1879 pat lol lof lol lof inc lol stf
1880         $1==$3 && $1==$6 && $2==$4 && $2==$7 && inreg($1)==reg_any
1881 uses REG={ind_regoff2, regvar($1), $2}
1882                                 yields %a
1883                                         leaving lol $1 lof $2 inc lol $6 stf $7
1884
1885 pat lol lof lol lof dec lol stf
1886         $1==$3 && $1==$6 && $2==$4 && $2==$7 && inreg($1)==reg_any
1887 uses REG={ind_regoff2, regvar($1), $2}
1888                                 yields %a
1889                                         leaving lol $1 lof $2 dec lol $6 stf $7
1890
1891 pat lol lof dup adp lol stf 
1892         $1==$5 && $2==$6 && $3==2 && inreg($1)==reg_any
1893 uses ADDREG={ind_regoff2, regvar($1), $2}
1894                                 yields %a
1895                                         leaving lol $1 lof $2 adp $4 lol $1 stf $2
1896
1897 pat lol lof dup inc lol stf 
1898         $1==$5 && $2==$6 && $3==2 && inreg($1)==reg_any
1899 uses REG={ind_regoff2, regvar($1), $2}
1900                                 yields %a
1901                                         leaving lol $1 lof $2 inc lol $1 stf $2
1902
1903 pat lol lof dup dec lol stf 
1904         $1==$5 && $2==$6 && $3==2 && inreg($1)==reg_any
1905 uses REG={ind_regoff2, regvar($1), $2}
1906                                 yields %a
1907                                         leaving lol $1 lof $2 dec lol $1 stf $2
1908
1909 #endif
1910
1911 pat lol lof dup adp lol stf
1912         $1==$5 && $2==$6 && $3==2 && $4==1
1913 kills referals
1914 uses ADDREG={LOCAL,$1,2}, REG
1915 gen move {ind_regoff2, %a, $2},%b
1916     inc {ind_regoff2, %a, $2}
1917                                 yields %b
1918
1919 pat loe lof dup adp loe stf
1920         $1==$5 && $2==$6 && $3==2 && $4==1
1921 kills referals
1922 uses ADDREG={EXTERN2,$1}, REG
1923 gen move {ind_regoff2, %a, $2},%b
1924     inc {ind_regoff2, %a, $2}
1925                                 yields %b
1926
1927 pat loe loi dup adp loe sti
1928         $1==$5 && $2==$6 && $3==2 && $2==2 && $4==1
1929 kills referals
1930 uses ADDREG={EXTERN2,$1}, REG
1931 gen move {ind_reg2, %a},%b
1932     inc {ind_reg2, %a}
1933                                 yields %b
1934
1935 pat lol lof dup adp lol stf
1936         $1==$5 && $2==$6 && $3==2 && $4==(0-1)
1937 kills referals
1938 uses ADDREG={LOCAL,$1,2}, REG
1939 gen move {ind_regoff2, %a, $2},%b
1940     dec {ind_regoff2, %a, $2}
1941                                 yields %b
1942
1943 pat loe lof dup adp loe stf
1944         $1==$5 && $2==$6 && $3==2 && $4==(0-1)
1945 kills referals
1946 uses ADDREG={EXTERN2,$1}, REG
1947 gen move {ind_regoff2, %a, $2},%b
1948     dec {ind_regoff2, %a, $2}
1949                                 yields %b
1950
1951 pat loe loi dup adp loe sti
1952         $1==$5 && $2==$6 && $3==2 && $2==2 && $4==(0-1)
1953 kills referals
1954 uses ADDREG={EXTERN2,$1}, REG
1955 gen move {ind_reg2, %a},%b
1956     dec {ind_reg2, %a}
1957                                 yields %b
1958
1959 pat lol lof dup adp lol stf
1960         $1==$5 && $2==$6 && $3==2
1961 kills referals
1962 uses ADDREG={LOCAL,$1,2}, REG
1963 gen move {ind_regoff2, %a, $2},%b
1964     add {ind_regoff2, %a, $2}, {ANYCON, $4}
1965                                 yields %b
1966
1967 pat loe lof dup adp loe stf
1968         $1==$5 && $2==$6 && $3==2
1969 kills referals
1970 uses ADDREG={EXTERN2,$1}, REG
1971 gen move {ind_regoff2, %a, $2},%b
1972     add {ind_regoff2, %a, $2}, {ANYCON, $4}
1973                                 yields %b
1974
1975 pat loe loi dup adp loe sti
1976         $1==$5 && $2==$6 && $3==2 && $2==2
1977 kills referals
1978 uses ADDREG={EXTERN2,$1}, REG
1979 gen move {ind_reg2, %a},%b
1980     add {ind_reg2, %a}, {ANYCON, $4}
1981                                 yields %b
1982
1983 pat loe ngi ste $1==$3 && $2==2
1984 kills indirects
1985 gen neg {EXTERN2, $1}
1986
1987 pat lde ngi sde $1==$3 && $2==4
1988 kills indirects
1989 gen neg {EXTERN2, $1+2}
1990     neg {EXTERN2, $1}
1991     sbb {EXTERN2, $1+2}, {ANYCON, 0}
1992
1993 pat loe dup adp ste $1==$4 && $2==2
1994 uses ADDREG={EXTERN2,$1}        yields %a
1995                                         leaving loe $1 adp $3 ste $1
1996
1997 pat loe ine $1==$2
1998 uses REG={EXTERN2,$1}   yields %a       leaving ine $1
1999
2000 pat loe dee $1==$2
2001 uses REG={EXTERN2,$1}   yields %a       leaving dee $1
2002
2003 pat loe adp ste $1==$3 && $2==1         leaving ine $1
2004
2005 pat loe adp ste $1==$3 && $2==0-1       leaving dee $1
2006
2007 pat loe adp ste $1==$3                  leaving loc $2 loe $1 adi 2 ste $3
2008
2009 pat loe com ste $1==$3 && $2==2
2010 kills indirects
2011 gen not {EXTERN2, $1}
2012
2013 pat loe lof adp loe stf $1==$4 && $2==$5 && $3==1
2014         leaving loe $1 lof $2 inc loe $1 stf $2
2015 pat loe lof adp loe stf $1==$4 && $2==$5 && $3==0-1
2016         leaving loe $1 lof $2 dec loe $1 stf $2
2017 pat loe lof adp loe stf $1==$4 && $2==$5
2018         leaving loc $3 loe $1 lof $2 adi 2 loe $1 stf $2
2019
2020 pat loe loi adp loe sti $1==$4 && $2==$5 && $3==1 && $2==2
2021         leaving loe $1 loi $2 inc loe $1 sti $2
2022 pat loe loi adp loe sti $1==$4 && $2==$5 && $3==0-1 && $2==2
2023         leaving loe $1 loi $2 dec loe $1 sti $2
2024 pat loe loi adp loe sti $1==$4 && $2==$5 && $2==2
2025         leaving loc $3 loe $1 loi $2 adi 2 loe $1 sti $2
2026
2027 /*******************************************************************
2028  *  Group 8: Convert Instructions                                  *
2029  *******************************************************************/
2030
2031 pat cii
2032 with CXREG DXREG ACC
2033 kills ALL
2034 gen joehoe {label,".cii"}               yields %3
2035
2036 pat ciu                                 leaving cuu
2037 pat cui                                 leaving cuu
2038
2039 pat cuu
2040 with CXREG DXREG ACC
2041 kills ALL
2042 gen joehoe {label,".cuu"}               yields %3
2043
2044 pat loc loc cii zeq $1==1 && $2==2
2045 with GENREG STACK
2046 gen test %1.1
2047     je {label, $4}
2048
2049 pat loc loc cii zne $1==1 && $2==2
2050 with GENREG STACK
2051 gen test %1.1
2052     jne {label, $4}
2053
2054 pat loc loc cii loc and zeq $4<256 && $4>=0 && $5==2 && $1==1 && $2==2
2055                 leaving loc $4 and $5 zeq $6
2056 pat loc loc cii loc and zne $4<256 && $4>=0 && $5==2 && $1==1 && $2==2
2057                 leaving loc $4 and $5 zne $6
2058
2059 pat loc loc cii $1==1 && $2==2
2060 with ACC
2061 gen cbw.                        yields ax
2062 with exact rmorconst1 ACC
2063 uses REG
2064 gen move %2,%a
2065     move %1,%2.1
2066     cbw.                        yields %a ax
2067 with exact rmorconst1
2068 uses reusing %1, ACC1=%1
2069 gen cbw.                        yields ax
2070
2071 pat loc loc cii $1==1 && $2==4
2072 with ACC
2073 uses DXREG
2074 gen cbw.        
2075     cwd.                        yields dx ax
2076 with exact rmorconst1
2077 uses reusing %1, ACC1=%1, DXREG
2078 gen cbw.        
2079     cwd.                        yields dx ax
2080
2081 pat loc loc cii $1==2 && $2==4
2082 with ACC
2083 uses DXREG
2084 gen  cwd.                       yields dx ax
2085
2086 pat loc loc cii $1==4 && $2==2
2087 with a_word a_word              yields %1
2088
2089 pat loc loc ciu                         leaving loc $1 loc $2 cuu
2090 pat loc loc cui                         leaving loc $1 loc $2 cuu
2091
2092 pat loc loc cuu $1==$2
2093
2094 pat loc loc cuu $1==2 && $2==4
2095 with a_word                     yields {ANYCON,0} %1
2096
2097 pat loc loc cuu $1==4 && $2==2
2098 with a_word a_word              yields %1
2099
2100 pat loc loc cif $1==2 && $2==4          leaving loc $1 cal ".cif4"
2101 pat loc loc cif $1==4 && $2==4          leaving loc $1 cal ".cif4" asp 2
2102
2103 pat loc loc cif $1==2 && $2==8
2104 with REG
2105 kills ALL
2106   gen push %1
2107       push %1
2108       push %1                           leaving loc $1 cal ".cif8"
2109
2110 pat loc loc cif $1==4 && $2==8
2111 with REG REG
2112 kills ALL
2113   gen push %1
2114       push %2
2115       push %1                           leaving loc $1 cal ".cif8"
2116
2117 pat loc loc cuf $1==2 && $2==4          leaving loc $1 cal ".cuf4"
2118 pat loc loc cuf $1==4 && $2==4          leaving loc $1 cal ".cuf4" asp 2
2119
2120 pat loc loc cuf $1==2 && $2==8
2121 with REG
2122 kills ALL
2123   gen push %1
2124       push %1
2125       push %1                           leaving loc $1 cal ".cuf8"
2126
2127 pat loc loc cuf $1==4 && $2==8
2128 with REG REG
2129 kills ALL
2130   gen push %1
2131       push %2
2132       push %1                           leaving loc $1 cal ".cuf8"
2133
2134 pat loc loc cfi $1==4 && $2==2  leaving loc $1 loc $2 cal ".cfi" asp 8 lfr 2
2135 pat loc loc cfi $2==4           leaving loc $1 loc $2 cal ".cfi" asp $1
2136 pat loc loc cfi $1==8 && $2==2  leaving loc $1 loc $2 cal ".cfi" asp 12 lfr 2
2137 pat loc loc cfu $1==4 && $2==2  leaving loc $1 loc $2 cal ".cfu" asp 8 lfr 2
2138 pat loc loc cfu $2==4           leaving loc $1 loc $2 cal ".cfu" asp $1
2139 pat loc loc cfu $1==8 && $2==2  leaving loc $1 loc $2 cal ".cfu" asp 12 lfr 2
2140 pat loc loc cff $1==8 && $2==4  leaving cal ".cff4" asp 4
2141 pat loc loc cff $1==4 && $2==8
2142 with REG REG
2143 kills ALL
2144 uses REG={ANYCON,0}
2145   gen push %a
2146       push %a
2147       push %2
2148       push %1                   leaving cal ".cff8"
2149
2150 /********************************************************************
2151  *  Group 9 : Logical Instructions                                  *
2152  ********************************************************************/
2153
2154 pat and $1==2
2155 with REG rmorconst
2156   gen and %1,%2                         yields %1
2157 with rmorconst REG
2158   gen and %2,%1                         yields %2
2159
2160 pat loc and $1==65535 && $2==2
2161
2162 pat loc and $1==255 && $2==2
2163 with GENREG                             yields %1.1
2164
2165 pat loc and $1==0 && $2==2              leaving asp 2 loc 0
2166
2167 pat and $1==4
2168 with EXACT REG REG rmorconst rmorconst
2169   gen and %1,%3
2170       and %2,%4                         yields %2 %1
2171 with rmorconst rmorconst REG REG
2172   gen and %3,%1
2173       and %4,%2                         yields %4 %3
2174
2175 pat ldc and highw($1)==(0-1) && $2==4   leaving loc loww($1) and 2
2176
2177 pat ldc and loww($1)==0 && $2==4        leaving asp 2 loc highw($1) and 2 loc 0
2178
2179 pat ldc and loww($1)==65535 && $2==4
2180 with rmorconst REG
2181   gen and %2,{ANYCON, highw($1)}        yields %2 %1
2182
2183 pat ldc and highw($1)==0 && $2==4
2184 with REG rmorconst
2185   gen and %1,{ANYCON, loww($1)}         yields {ANYCON,0} %1
2186
2187 pat and defined($1)
2188 kills ALL
2189   gen mov cx,{ANYCON,$1}
2190       joehoe {label, ".and"}
2191
2192 pat and !defined($1)
2193 with CXREG
2194 kills ALL
2195   gen joehoe {label, ".and"}
2196
2197 pat ior $1==2
2198 with REG rmorconst
2199   gen or %1,%2                          yields %1
2200 with rmorconst REG
2201   gen or %2,%1                          yields %2
2202
2203 pat loc ior $1==0 && $2==2
2204
2205 pat loc ior $1==65535 && $2==2          leaving asp 2 loc $1
2206
2207 pat ior $1==4
2208 with EXACT REG REG rmorconst rmorconst
2209   gen or %1,%3
2210       or %2,%4                          yields %2 %1
2211 with rmorconst rmorconst REG REG
2212   gen or %3,%1
2213       or %4,%2                          yields %4 %3
2214
2215 pat ldc ior highw($1)==(0-1) && $2==4
2216 with REG rmorconst
2217   gen or %1,{ANYCON, loww($1)}          yields {ANYCON,0-1} %1
2218
2219 pat ldc ior highw($1)==0 && $2==4       leaving loc loww($1) ior 2
2220
2221 pat ldc ior loww($1)==65535 && $2==4    leaving asp 2 loc highw($1) ior 2 loc 0-1
2222
2223 pat ldc ior loww($1)==0 && $2==4
2224 with rmorconst REG
2225   gen or %2,{ANYCON, highw($1)}         yields %2 %1
2226
2227 pat ior defined($1)
2228 kills ALL
2229   gen mov cx,{ANYCON,$1}
2230       joehoe {label, ".ior"}
2231
2232 pat ior !defined($1)
2233 with CXREG
2234 kills ALL
2235   gen joehoe {label, ".ior"}
2236
2237 pat xor $1==2
2238 with REG rmorconst
2239   gen xor %1,%2                         yields %1
2240 with rmorconst REG
2241   gen xor %2,%1                         yields %2
2242
2243 pat xor $1==4
2244 with EXACT REG REG rmorconst rmorconst
2245   gen xor %1,%3
2246       xor %2,%4                         yields %2 %1
2247 with rmorconst rmorconst REG REG
2248   gen xor %3,%1
2249       xor %4,%2                         yields %4 %3
2250
2251 pat xor defined($1)
2252 kills ALL
2253   gen mov cx,{ANYCON,$1}
2254       joehoe {label, ".xor"}
2255
2256 pat xor !defined($1)
2257 with CXREG
2258 kills ALL
2259   gen joehoe {label, ".xor"}
2260
2261 pat com $1==2
2262 with REG
2263   gen not %1                            yields %1
2264
2265 pat com $1==4
2266 with REG REG
2267   gen not %2
2268       not %1                            yields %2 %1
2269
2270 pat com defined($1)
2271 kills ALL
2272   gen mov cx,{ANYCON,$1}
2273       joehoe {label, ".com"}
2274
2275 pat com !defined($1)
2276 with CXREG
2277 kills ALL
2278   gen joehoe {label, ".com"}
2279
2280 pat loc rol $1==1 && $2==2
2281 with REG
2282   gen rol %1,{ANYCON,1}                 yields %1
2283
2284 pat rol $1==2
2285 with SHIFT_CREG REG
2286   gen rol %2,cl                         yields %2
2287
2288 pat rol $1==4
2289 with CXREG REG REG
2290   gen jcxz {label, 1f}
2291       2: sal %2,{ANYCON,1}
2292       rcl %3,{ANYCON,1}
2293       adc %2,{ANYCON,0}
2294       loop {label, 2b}
2295       1:
2296
2297 pat loc ror $1==1 && $2==2
2298 with REG
2299   gen ror %1,{ANYCON,1}                 yields %1
2300
2301 pat ror $1==2
2302 with SHIFT_CREG REG
2303   gen ror %2,cl                         yields %2
2304
2305 pat ror $1==4
2306 with CXREG REG REG
2307   gen jcxz {label, 1f}
2308       neg cx
2309       add cx,{ANYCON,32}
2310       2: sal %2,{ANYCON,1}
2311       rcl %3,{ANYCON,1}
2312       adc %2,{ANYCON,0}
2313       loop {label, 2b}
2314       1:
2315
2316 /*******************************************************************
2317  *  Group 10 : Set Instructions                                    *
2318  *******************************************************************/
2319
2320 pat inn $1==2
2321 with SHIFT_CREG REG
2322 gen shr %2,cl
2323     and %2,{ANYCON, 1}                  yields %2
2324
2325 pat loc inn $1==1 && $2==2
2326 with REG
2327 gen shr %1,{ANYCON, 1}
2328     and %1,{ANYCON, 1}                  yields %1
2329
2330 pat loc inn $1==0 && $2==2
2331 with REG
2332 gen and %1,{ANYCON, 1}                  yields %1
2333
2334 pat inn defined($1)
2335 with ACC 
2336 kills ALL
2337 gen mov cx,{ANYCON, $1}
2338     joehoe {label,".inn"}               yields ax
2339
2340 pat inn !defined($1)
2341 with CXREG ACC
2342 kills ALL
2343 gen joehoe {label,".inn"}               yields ax
2344
2345 pat loc inn zeq $2==2
2346 with rm STACK
2347 gen check %1,{ANYCON,1<<$1}
2348     je {label,$3}
2349
2350 pat loc inn zne $2==2
2351 with rm STACK
2352 gen check %1,{ANYCON,1<<$1}
2353     jne {label,$3}
2354
2355 pat set $1==2
2356 with SHIFT_CREG
2357 uses REG={ANYCON, 1}
2358 gen shl %a,cl                   yields %a
2359
2360 pat set defined($1)
2361 with ACC
2362 kills ALL
2363 gen mov cx,{ANYCON, $1}
2364     joehoe {label,".set"}
2365
2366 pat set !defined($1)
2367 with CXREG ACC
2368 kills ALL
2369 gen joehoe {label,".set"}
2370
2371 /********************************************************************
2372  *  Group 11 : Array Instructions                                   *
2373  ********************************************************************/
2374
2375 pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)==0
2376                                                 leaving ads 2
2377
2378 pat lae aar $2==2 && rom($1,3)==1 && rom($1,1)!=0
2379                                         leaving adp 0-rom($1,1) ads 2
2380
2381 pat lae aar $2==2 && rom($1,3)==2 && rom($1,1)==0
2382   with ADDREG
2383   gen sal %1,{ANYCON,1}                 yields %1       leaving ads 2
2384
2385 pat lae aar $2==2 && rom($1,3)==2 && rom($1,1)!=0
2386   with ADDREG
2387   gen sal %1,{ANYCON,1}     yields %1   leaving adp 0-2*rom($1,1) ads 2
2388
2389 pat lae aar $2==2 && rom($1,3)==4 && rom($1,1)==0
2390   with ADDREG
2391   gen sal %1,{ANYCON,1}
2392       sal %1,{ANYCON,1}                 yields %1       leaving ads 2
2393
2394 pat lae aar $2==2 && rom($1,3)==4 && rom($1,1)!=0
2395   with ADDREG
2396   gen sal %1,{ANYCON,1}
2397       sal %1,{ANYCON,1}  yields %1      leaving adp 0-4*rom($1,1) ads 2
2398
2399 pat lae aar $2==2 && rom($1,1)==0
2400   with ACC
2401   uses DXREG,REG={ANYCON,rom($1,3)}
2402   gen mul %b                    yields %1       leaving ads 2
2403
2404 pat lae aar $2==2 && defined(rom($1,1))
2405   with ACC
2406   uses DXREG,REG={ANYCON,rom($1,3)}
2407   gen mul %b            yields %1
2408                                 leaving adp 0-rom($1,1)*rom($1,3) ads 2
2409  
2410 pat loc sli ads sti $1==1 && $2==2 && $3==2
2411 with exact rmorconst ADDR_EXTERN
2412   uses reusing %1,ADDREG=%1
2413   gen sal %a,{ANYCON,1}         yields {Xreg_off,%a,%2.off}
2414                                                 leaving sti $4
2415 with ADDREG rmorconst
2416   gen sal %1,{ANYCON,1}
2417   add %1,%2                     yields %1       leaving sti $4
2418 with REG ADDREG
2419   gen sal %1,{ANYCON,1}
2420       add %2,%1                 yields %2       leaving sti $4
2421
2422 pat loc sli ads $1==1 && $2==2 && $3==2
2423 with exact rmorconst ADDR_EXTERN
2424   uses reusing %1,ADDREG=%1
2425   gen sal %a,{ANYCON,1}         yields {Xreg_off,%a,%2.off}
2426 with ADDREG rmorconst
2427   gen sal %1,{ANYCON,1}
2428   add %1,%2                     yields %1
2429 with REG ADDREG
2430   gen sal %1,{ANYCON,1}
2431       add %2,%1                 yields %2
2432 with REG rmorconst
2433   gen sal %1,{ANYCON,1}
2434   add %1,%2                     yields %1
2435
2436 pat loc sli ads sti $1==2 && $2==2 && $3==2
2437 with exact rmorconst ADDR_EXTERN
2438   uses reusing %1,ADDREG=%1
2439   gen sal %a,{ANYCON,1}
2440       sal %a,{ANYCON,1}         yields {Xreg_off,%a,%2.off}
2441                                                 leaving sti $4
2442 with ADDREG rmorconst
2443   gen sal %1,{ANYCON,1}
2444       sal %1,{ANYCON,1}
2445       add %1,%2                 yields %1       leaving sti $4
2446 with REG ADDREG
2447   gen sal %1,{ANYCON,1}
2448       sal %1,{ANYCON,1}
2449       add %2,%1                 yields %2       leaving sti $4
2450
2451 pat loc sli ads $1==2 && $2==2 && $3==2
2452 with exact rmorconst ADDR_EXTERN
2453   uses reusing %1,ADDREG=%1
2454   gen sal %a,{ANYCON,1}
2455       sal %a,{ANYCON,1}         yields {Xreg_off,%a,%2.off}
2456 with ADDREG rmorconst
2457   gen sal %1,{ANYCON,1}
2458       sal %1,{ANYCON,1}
2459       add %1,%2                 yields %1
2460 with REG ADDREG
2461   gen sal %1,{ANYCON,1}
2462       sal %1,{ANYCON,1}
2463       add %2,%1                 yields %2
2464 with REG rmorconst
2465   gen sal %1,{ANYCON,1}
2466       sal %1,{ANYCON,1}
2467       add %1,%2                 yields %1
2468
2469 pat loc sli ads sti $2==2 && $3==2
2470 with exact rmorconst ADDR_EXTERN
2471 uses reusing %1,ADDREG=%1,CXREG={ANYCON,$1}
2472   gen sal %a,cl                 yields {Xreg_off,%a,%2.off}
2473                                                 leaving sti $4
2474 with ADDREG rmorconst
2475 uses CXREG={ANYCON,$1}
2476   gen sal %1,cl
2477       add %1,%2                 yields %1       leaving sti $4
2478 with REG ADDREG
2479 uses CXREG={ANYCON,$1}
2480   gen sal %1,cl
2481       add %2,%1                 yields %2       leaving sti $4
2482
2483 pat loc sli ads $2==2 && $3==2
2484 with exact rmorconst ADDR_EXTERN
2485 uses reusing %1,ADDREG=%1,CXREG={ANYCON,$1}
2486   gen sal %a,cl                 yields {Xreg_off,%a,%2.off}
2487 with ADDREG rmorconst
2488 uses CXREG={ANYCON,$1}
2489   gen sal %1,cl
2490       add %1,%2                 yields %1
2491 with REG ADDREG
2492 uses CXREG={ANYCON,$1}
2493   gen sal %1,cl
2494       add %2,%1                 yields %2
2495 with REG rmorconst
2496 uses CXREG={ANYCON,$1}
2497   gen sal %1,cl
2498       add %1,%2                 yields %1
2499
2500 pat aar $1==2
2501   with AREG ACC
2502   uses DXREG
2503   gen sub %2,{ind_reg2,%1}
2504       mul {ind_regoff2,%1,4}    yields %2       leaving ads 2
2505   with reg_off ACC
2506   uses DXREG
2507   gen sub %2,{ind_regoff2, %1.reg, %1.off}
2508       mul {ind_regoff2, %1.reg, 4+%1.off}
2509                                 yields %2       leaving ads 2
2510   with bpreg_off ACC
2511   uses DXREG
2512   gen sub %2,{ind_bpregoff2, %1.reg, %1.ind}
2513       mul {ind_bpregoff2, %1.reg, 4+%1.ind}
2514                                 yields %2       leaving ads 2
2515   with ADDR_LOCAL ACC
2516   uses DXREG
2517   gen sub %2,{LOCAL,%1.ind,2}
2518       mul {LOCAL, 4+%1.ind,2}   yields %2       leaving ads 2
2519   with ADDR_EXTERN ACC
2520   uses DXREG
2521   gen sub %2,{EXTERN2,%1.off}
2522       mul {EXTERN2,4+%1.off}    yields %2       leaving ads 2
2523
2524 pat lae lar defined(rom($1,3))  leaving lae $1 aar $2 loi rom($1,3)
2525
2526 pat lae sar defined(rom($1,3))  leaving lae $1 aar $2 sti rom($1,3)
2527
2528 pat aar !defined($1)
2529   kills ALL
2530   gen joehoe {label,".iaar"}    yields bx
2531
2532 pat sar $1==2
2533   with BXREG ACC
2534   kills ALL
2535   gen joehoe {label,".sar2"}
2536
2537 pat sar !defined($1)
2538   kills ALL
2539   gen joehoe {label,".isar"}
2540
2541 pat lar $1==2 
2542   with BXREG ACC
2543   kills ALL
2544   gen joehoe {label,".lar2"}
2545
2546 pat lar !defined($1)
2547   kills ALL
2548   gen joehoe {label,".ilar"}
2549
2550 /*******************************************************************
2551  *  Group 12 : Compare Instructions                                *
2552  *******************************************************************/
2553
2554 pat cmi $1==2
2555 with EXACT register rmorconst
2556   uses REG={ANYCON,0}
2557   gen cmp %1,%2
2558       je {label,2f}
2559       jl {label,1f}
2560       inc %a
2561       jmp {label,2f}
2562       1:
2563       dec %a
2564       2:                        yields %a
2565 with rmorconst register
2566   uses REG={ANYCON,0}
2567   gen cmp %2,%1
2568       je {label,2f}
2569       jg {label,1f}
2570       inc %a
2571       jmp {label,2f}
2572       1:
2573       dec %a
2574       2:                        yields %a
2575
2576 pat cmi $1==4
2577 kills ALL
2578   gen joehoe {label,".cmi4"}    yields ax
2579
2580 pat cmu $1==2                            leaving cmp
2581
2582 pat cmu $1==4
2583 kills ALL
2584   gen joehoe {label,".cmu4"}    yields ax
2585
2586 pat cms $1==2
2587 with EXACT REG rmorconst
2588   gen sub %1,%2                 yields %1
2589 with rmorconst REG
2590   gen sub %2,%1                 yields %2
2591
2592 pat cms $1==4
2593 with rmorconst rmorconst REG REG
2594   gen sub %3,%1
2595       sbb %4,%2
2596       or %4,%3                  yields %4
2597 with EXACT REG REG rmorconst rmorconst
2598   gen sub %1,%3
2599       sbb %2,%4
2600       or %2,%1                  yields %2
2601
2602 pat cms defined($1)
2603 kills ALL
2604   gen mov cx,{ANYCON,$1}
2605       joehoe {label,".cms"}     yields cx
2606
2607 pat cms !defined($1)
2608 with CXREG
2609 kills ALL
2610   gen joehoe {label,".cms"}     yields cx
2611
2612 pat cmf $1==4
2613 kills ALL
2614   gen joehoe {label,".cmf4"}    leaving asp 8 lfr 2
2615
2616 pat cmf $1==8
2617 kills ALL
2618   gen joehoe {label,".cmf8"}    leaving asp 16 lfr 2
2619
2620 pat cmp
2621 with EXACT register rmorconst
2622 uses REG = {ANYCON,0}
2623   gen cmp %1,%2
2624       je  {label,2f}
2625       jb  {label,1f}
2626       inc %a
2627       jmp {label,2f}
2628       1: dec %a
2629       2:                            yields %a
2630 with rmorconst register
2631 uses REG = {ANYCON,0}
2632   gen cmp %2,%1
2633       je  {label,2f}
2634       ja  {label,1f}
2635       inc %a
2636       jmp {label,2f}
2637       1: dec %a
2638       2:                            yields %a
2639
2640 proc txx
2641 with rm
2642 uses REG = {ANYCON,0}
2643   gen test %1
2644       jxx* {label,1f}
2645       inc %a
2646       1:                            yields %a
2647
2648 pat tlt call txx("jns")
2649 pat teq call txx("jne")
2650 pat tne call txx("je")
2651 pat tge call txx("js")
2652
2653 /* For the next two patterns there is no I8086 test instruction (one that
2654    ignores the OF flag. Therefore, condition codes are killed and the test
2655    is done again.
2656 */
2657 pat tgt
2658 with rm
2659 uses REG = {ANYCON, 0}
2660   gen killcc.
2661       test %1
2662       jle {label, 1f}
2663       inc %a
2664       1:                            yields %a
2665
2666 pat tle
2667 with rm
2668 uses REG = {ANYCON, 0}
2669   gen killcc.
2670       test %1
2671       jg {label, 1f}
2672       inc %a
2673       1:                            yields %a
2674
2675 proc txxior
2676 with rm REG
2677   gen test %1
2678       jxx* {label,1f}
2679       or  %2,{ANYCON,1}
2680       1:                            yields %2
2681
2682 pat tlt ior $2==2 call txxior("jns")
2683 pat tge ior $2==2 call txxior("js")
2684 pat teq ior $2==2 call txxior("jne")
2685 pat tne ior $2==2 call txxior("je")
2686
2687 /* For the next two patterns there is no I8086 test instruction (one that
2688    ignores the OF flag. Therefore, condition codes are killed and the test
2689    is done again.
2690 */
2691 pat tle ior $2==2
2692 with rm REG
2693   gen killcc.
2694       test %1
2695       jg {label,1f}
2696       or  %2,{ANYCON,1}
2697       1:                            yields %2
2698
2699 pat tgt ior $2==2
2700 with rm REG
2701   gen killcc.
2702       test %1
2703       jle {label,1f}
2704       or  %2,{ANYCON,1}
2705       1:                            yields %2
2706
2707 proc cmixxior
2708 with regorconst rm REG
2709   gen cmp %2,%1
2710       jxx* {label,1f}
2711       or  %3,{ANYCON,1}
2712       1:                            yields %3
2713
2714 pat cmi tlt ior $1==2 && $3==2 call cmixxior("jge")
2715 pat cmi tle ior $1==2 && $3==2 call cmixxior("jg")
2716 pat cmi teq ior $1==2 && $3==2 call cmixxior("jne")
2717 pat cmi tne ior $1==2 && $3==2 call cmixxior("je")
2718 pat cmi tge ior $1==2 && $3==2 call cmixxior("jl")
2719 pat cmi tgt ior $1==2 && $3==2 call cmixxior("jle")
2720
2721 proc cmxtxx
2722 with regorconst rm
2723 uses REG = {ANYCON,0}
2724   gen cmp %2,%1
2725       jxx[1] {label,1f}
2726       inc %a
2727       1:                            yields %a
2728 with rm regorconst
2729 uses REG = {ANYCON,0}
2730   gen cmp %1,%2
2731       jxx[2] {label,1f}
2732       inc %a
2733       1:                            yields %a
2734
2735 pat cmi tlt $1==2     call cmxtxx("jge","jle")
2736 pat cmi tle $1==2     call cmxtxx("jg","jl")
2737 pat cmi teq $1==2     call cmxtxx("jne","jne")
2738 pat cmi tne $1==2     call cmxtxx("je","je")
2739 pat cmi tge $1==2     call cmxtxx("jl","jg")
2740 pat cmi tgt $1==2     call cmxtxx("jle","jge")
2741 pat cmp tlt           call cmxtxx("jae","jbe")
2742 pat cmp tle           call cmxtxx("ja","jb")
2743 pat cmp teq           call cmxtxx("jne","jne")
2744 pat cmp tne           call cmxtxx("je","je")
2745 pat cmp tge           call cmxtxx("jb","ja")
2746 pat cmp tgt           call cmxtxx("jbe","jae")
2747 pat cms teq $1==2     call cmxtxx("jne","jne")
2748 pat cms tne $1==2     call cmxtxx("je","je")
2749
2750 proc cmxzxx example cmp zlt
2751 with regorconst rm STACK
2752   gen cmp %2,%1
2753       jxx[1] {label,$2}
2754 with rm regorconst STACK
2755   gen cmp %1,%2
2756       jxx[2] {label,$2}
2757
2758 pat cmp zlt         call cmxzxx("jb","ja")
2759 pat cmp zle         call cmxzxx("jbe","jae")
2760 pat cmp zeq         call cmxzxx("je","je")
2761 pat cmp zne         call cmxzxx("jne","jne")
2762 pat cmp zge         call cmxzxx("jae","jbe")
2763 pat cmp zgt         call cmxzxx("ja","jb")
2764 pat cms zeq $1==2   call cmxzxx("je","je")
2765 pat cms zne $1==2   call cmxzxx("jne","jne")
2766
2767 proc cmx4zxx example cmi zlt
2768 with regorconst regorconst rm rm STACK
2769   gen cmp %4,%2
2770       jxx[1] {label,$2}
2771       jne {label,1f}
2772       cmp %3,%1
2773       jxx[2] {label,$2}
2774       1:
2775 with rm rm regorconst regorconst STACK
2776   gen cmp %2,%4
2777       jxx[3] {label,$2}
2778       jne {label,1f}
2779       cmp %1,%3
2780       jxx[4] {label,$2}
2781       1:
2782
2783 pat cmi zlt $1==4       call cmx4zxx("jl", "jb", "jg", "ja")
2784 pat cmi zle $1==4       call cmx4zxx("jl", "jbe", "jg", "jae")
2785 pat cmi zgt $1==4       call cmx4zxx("jg", "ja", "jl", "jb")
2786 pat cmi zge $1==4       call cmx4zxx("jg", "jae", "jl", "jbe")
2787
2788 pat cmu zlt $1==4       call cmx4zxx("jb", "jb", "ja", "ja")
2789 pat cmu zle $1==4       call cmx4zxx("jb", "jbe", "ja", "jae")
2790 pat cmu zgt $1==4       call cmx4zxx("ja", "ja", "jb", "jb")
2791 pat cmu zge $1==4       call cmx4zxx("ja", "jae", "jb", "jbe")
2792
2793 pat ldc cmi zlt highw($1)==0 && loww($1)==0 && $2==4
2794 with rmorconst rmorconst        yields %2       leaving zlt $3
2795
2796 pat ldc cmi tlt highw($1)==0 && loww($1)==0 && $2==4
2797 with rmorconst rmorconst        yields %2       leaving tlt
2798
2799 pat ldc cmi zge highw($1)==0 && loww($1)==0 && $2==4
2800 with rmorconst rmorconst        yields %2       leaving zge $3
2801
2802 pat ldc cmi tge highw($1)==0 && loww($1)==0 && $2==4
2803 with rmorconst rmorconst        yields %2       leaving tge $3
2804
2805 pat ldc cmi tle highw($1)==0 && loww($1)==0 && $2==4
2806 with rmorconst rmorconst
2807 uses REG = {ANYCON, 0}
2808   gen cmp %a,%2
2809       jg {label,2f}
2810       jl {label,1f}
2811       cmp %a,%1
2812       jne {label,1f}
2813       2:
2814       inc %a
2815       1:                        yields %a
2816
2817 pat ldc cmi tgt highw($1)==0 && loww($1)==0 && $2==4
2818 with rmorconst rmorconst
2819 uses REG = {ANYCON, 0}
2820   gen cmp %a,%2
2821       jl {label,2f}
2822       jg {label,1f}
2823       cmp %a,%1
2824       je {label,1f}
2825       2:
2826       inc %a
2827       1:                        yields %a
2828
2829 pat loc ldc cms zeq $3==4 && $1==0 && loww($2)==0 && highw($2)==0
2830 with REG STACK
2831   gen test %1
2832       je {label,$4}
2833
2834 pat loc ldc cms zne $3==4 && $1==0 && loww($2)==0 && highw($2)==0
2835 with REG STACK
2836   gen test %1
2837       jne {label,$4}
2838
2839 pat loc ldc cms teq $3==4 && $1==0 && loww($2)==0 && highw($2)==0
2840 with REG
2841 uses REG = {ANYCON, 0}
2842   gen test %1
2843       jne {label,1f}
2844       inc %a
2845       1:                        yields %a
2846
2847 pat loc ldc cms tne $3==4 && $1==0 && loww($2)==0 && highw($2)==0
2848 with REG
2849   gen test %1
2850       je {label,1f}
2851       mov %1,{ANYCON,1}
2852       1:                        yields %1
2853
2854 pat ldc cms zeq $2==4 && loww($1)==0 && highw($1)==0
2855 with rmorconst REG STACK
2856   gen or %2,%1
2857       je {label,$3}
2858 with REG rmorconst STACK
2859   gen or %1,%2
2860       je {label,$3}
2861
2862 pat ldc cms zne $2==4 && loww($1)==0 && highw($1)==0
2863 with rmorconst REG STACK
2864   gen or %2,%1
2865       jne {label,$3}
2866 with REG rmorconst STACK
2867   gen or %1,%2
2868       jne {label,$3}
2869
2870 pat ldc cms teq $2==4 && loww($1)==0 && highw($1)==0
2871 with rmorconst REG
2872 uses REG = {ANYCON, 0}
2873   gen or %2,%1
2874       jne {label,1f}
2875       inc %a
2876       1:                        yields %a
2877 with REG rmorconst
2878 uses REG = {ANYCON, 0}
2879   gen or %1,%2
2880       jne {label,1f}
2881       inc %a
2882       1:                        yields %a
2883
2884 pat ldc cms tne $2==4 && loww($1)==0 && highw($1)==0
2885 with rmorconst REG
2886   gen or %2,%1
2887       je {label,1f}
2888       mov %2,{ANYCON,1}
2889       1:                        yields %2
2890 with REG rmorconst
2891   gen or %1,%2
2892       je {label,1f}
2893       mov %1,{ANYCON,1}
2894       1:                        yields %1
2895
2896 pat ldc cms zeq $2==4 && loww($1)==65535 && highw($1)==(0-1)
2897 with rmorconst REG STACK
2898   gen and %2,%1
2899       cmp %2,{ANYCON,0-1}
2900       je {label,$3}
2901 with REG rmorconst STACK
2902   gen and %1,%2
2903       cmp %1,{ANYCON,0-1}
2904       je {label,$3}
2905
2906 pat ldc cms zne $2==4 && loww($1)==65535 && highw($1)==(0-1)
2907 with rmorconst REG STACK
2908   gen and %2,%1
2909       cmp %2,{ANYCON,0-1}
2910       jne {label,$3}
2911 with REG rmorconst STACK
2912   gen and %1,%2
2913       cmp %1,{ANYCON,0-1}
2914       jne {label,$3}
2915
2916 pat cms zne $1==4
2917 with regorconst regorconst rm rm STACK
2918   gen cmp %3,%1
2919       jne {label,$2}
2920       cmp %4,%2
2921       jne {label,$2}
2922 with rm rm regorconst regorconst STACK
2923   gen cmp %1,%3
2924       jne {label,$2}
2925       cmp %2,%4
2926       jne {label,$2}
2927
2928 pat cms zeq $1==4
2929 with regorconst regorconst rm rm STACK
2930   gen cmp %3,%1
2931       jne {label, 1f}
2932       cmp %4,%2
2933       je {label,$2}
2934       1:
2935 with rm rm regorconst regorconst STACK
2936   gen cmp %1,%3
2937       jne {label,1f}
2938       cmp %2,%4
2939       je {label,$2}
2940       1:
2941
2942 proc andzxx example and zeq
2943 with regorconst rm STACK
2944   gen check %2,%1
2945       jxx* {label,$2}
2946 with exact rm regorconst
2947   kills ALL
2948   gen check %1,%2
2949       jxx* {label,$2}
2950
2951 pat and zeq $1==2 call andzxx("je")
2952 pat and zne $1==2 call andzxx("jne")
2953
2954 proc locandzxx example loc and zeq
2955 with rm12 STACK
2956   gen testb %1,{ANYCON,$1}
2957       jxx* {label,$3}
2958 with GENREG STACK
2959   gen testb %1.1,{ANYCON,$1}
2960       jxx* {label,$3}
2961 with exact IREG
2962   kills ALL
2963   gen check %1,{ANYCON,$1}
2964       jxx* {label,$3}
2965
2966 pat loc and zeq $1<256 && $1>=0 && $2==2 call locandzxx("je")
2967 pat loc and zne $1<256 && $1>=0 && $2==2 call locandzxx("jne")
2968
2969 proc locbxx example loc beq
2970 with rm1 STACK
2971   gen cmpb %1,{ANYCON,$1}
2972       jxx* {label,$2}
2973 with rm STACK
2974   gen cmp %1,{ANYCON,$1}
2975       jxx* {label,$2}
2976
2977 pat loc beq $1<256 && $1>=0 call locbxx("je")
2978 pat loc bne $1<256 && $1>=0 call locbxx("jne")
2979
2980 proc loccmuzxx example loc cmu zeq
2981 with rm1 STACK
2982   gen cmpb %1,{ANYCON,$1}
2983       jxx* {label,$3}
2984 with rm STACK
2985   gen cmp %1,{ANYCON,$1}
2986       jxx* {label,$3}
2987
2988 pat loc cmu zeq $1<256 && $1>=0 && $2==2 call loccmuzxx("je")
2989 pat loc cmu zne $1<256 && $1>=0 && $2==2 call loccmuzxx("jne")
2990
2991 /*******************************************************************
2992  *  Group 13 : Branch Instructions                                 *
2993  *******************************************************************/
2994
2995 pat lab topeltsize($1)==2 && !fallthrough($1)
2996   with STACK
2997   kills ALL
2998   gen labeldef $1                 yields ax
2999
3000 pat lab topeltsize($1)==2 && fallthrough($1)
3001   with ACC STACK
3002   kills ALL
3003   gen labeldef $1                 yields ax
3004
3005 pat lab topeltsize($1)!=2
3006   with STACK
3007   kills ALL
3008   gen labeldef $1
3009
3010 pat bra topeltsize($1)==2
3011   with ACC STACK
3012   gen jmp {label,$1}
3013
3014 pat bra topeltsize($1)!=2
3015   with STACK
3016   gen jmp {label,$1}
3017
3018 proc bxx example blt
3019 with regorconst rm STACK
3020   gen cmp %2,%1
3021       jxx[1] {label,$1}
3022 with rm regorconst STACK
3023   gen cmp %1,%2
3024       jxx[2] {label,$1}
3025
3026 pat blt         call bxx("jl","jg")
3027 pat ble         call bxx("jle","jge")
3028 pat bge         call bxx("jge","jle")
3029 pat bgt         call bxx("jg","jl")
3030
3031 proc bex example beq
3032 with regorconst rm STACK
3033   gen cmp %2,%1
3034       jxx[1] {label,$1}
3035 with rm regorconst STACK
3036   gen cmp %1,%2
3037       jxx[2] {label,$1}
3038 with exact rm1 REG1
3039   kills ALL
3040   gen cmpb %1,%2
3041       jxx[2] {label,$1}
3042 with exact REG1 rm1
3043   kills ALL
3044   gen cmpb %2,%1
3045       jxx[1] {label,$1}
3046
3047 pat beq         call bex("je","je")
3048 pat bne         call bex("jne","jne")
3049
3050 proc zxx example zlt
3051 with rm STACK
3052   gen test %1
3053       jxx* {label,$1}
3054
3055 pat zlt         call zxx("js")
3056 pat zge         call zxx("jns")
3057
3058 /* For the next two patterns there is no I8086 test instruction (one that
3059    ignores the OF flag. Therefore, condition codes are killed and the test
3060    is done again.
3061 */
3062 pat zle
3063 with rm STACK
3064   gen killcc.
3065       test %1
3066       jle {label,$1}
3067
3068 pat zgt
3069 with rm STACK
3070   gen killcc.
3071       test %1
3072       jg {label,$1}
3073
3074 pat zne
3075 with rm+rm1 STACK
3076   gen test %1
3077       jne {label,$1}
3078
3079 pat zeq
3080 with rm+rm1 STACK
3081   gen test %1
3082       je {label,$1}
3083
3084
3085 /*******************************************************************
3086  *  Group 14 : Procedure-call Instructions                         *
3087  *******************************************************************/
3088
3089 pat cal
3090   kills ALL
3091   gen joehoe {label,$1}
3092
3093 pat cai
3094   with rm
3095   kills ALL
3096   gen joehoe %1
3097
3098 #ifdef REGVARS
3099 pat lfr adi stl $1==2 && $2==2 && inreg($3) > 0
3100   kills ALL
3101   gen pop {LOCAL,$3,2}
3102       add {LOCAL,$3,2}, ax
3103 #endif
3104
3105 pat lfr $1==2                   yields ax
3106
3107 pat lfr $1==4                   yields dx ax
3108
3109 pat lfr $1==6
3110 kills ALL
3111   gen joehoe {label, ".lfr6"}
3112
3113 pat lfr $1==8
3114 kills ALL
3115   gen joehoe {label, ".lfr8"}
3116
3117 pat ret $1==0
3118   kills ALL
3119   gen
3120 #ifdef REGVARS
3121         return
3122 #else
3123       mov sp,bp
3124       pop bp
3125       ret.
3126 #endif
3127
3128 pat ret $1==2
3129   with ACC
3130   kills ALL
3131   gen
3132 #ifdef REGVARS
3133         return
3134 #else
3135       mov sp,bp
3136       pop bp
3137       ret.
3138 #endif
3139
3140 pat ret $1==4
3141   with ACC DXREG
3142   kills ALL
3143   gen
3144 #ifdef REGVARS
3145         return
3146 #else
3147       mov sp,bp
3148       pop bp
3149       ret.
3150 #endif
3151
3152 pat ret $1==6
3153   with STACK
3154   gen joehoe {label, ".ret6"}
3155 #ifdef REGVARS
3156         return
3157 #else
3158       mov sp,bp
3159       pop bp
3160       ret.
3161 #endif
3162
3163 pat ret $1==8
3164   with STACK
3165   gen joehoe {label, ".ret8"}
3166 #ifdef REGVARS
3167         return
3168 #else
3169       mov sp,bp
3170       pop bp
3171       ret.
3172 #endif
3173
3174 /********************************************************************
3175  *  Group 15 : Miscellaneous Instructions                           *
3176  ********************************************************************/
3177
3178 pat asp $1==2
3179 with exact a_word
3180 with STACK
3181   uses BXREG /* GENREG may contain lfr area */
3182   gen pop %a
3183
3184 pat asp $1==4
3185 with exact a_word a_word
3186 with STACK
3187   uses BXREG /* GENREG may contain lfr area */
3188   gen pop %a
3189       pop %a
3190
3191 pat asp $1==0-2
3192 with STACK                                      yields bp
3193
3194 pat asp
3195 with STACK
3196   gen add sp,{ANYCON,$1}
3197
3198 pat ass $1==2
3199 with rmorconst STACK
3200   gen add sp,%1
3201
3202 pat ass !defined($1)
3203 with rm rmorconst STACK
3204   gen cmp %1,{ANYCON,2}
3205       jne {label, ".unknown"}
3206       add sp,%2
3207
3208 pat blm $1==0                                   leaving asp 4
3209
3210 pat blm $1>0
3211 kills ALL
3212   gen mov cx,{ANYCON,$1/2}
3213       joehoe {label, ".blm"}
3214
3215 pat bls $1==2
3216 with CXREG
3217 kills ALL
3218   gen sar cx,{ANYCON,1}
3219       joehoe {label, ".blm"}
3220
3221 pat bls !defined($1)
3222 with rm-CXREG CXREG
3223 kills ALL
3224   gen cmp %1,{ANYCON,2}
3225       jne {label, ".unknown"}
3226       sar cx,{ANYCON,1}
3227       joehoe {label, ".blm"}
3228
3229 pat lae csa $2==2
3230 with ACC
3231 kills ALL
3232 uses BXREG = { ADDR_EXTERN, $1}
3233   gen jmp {label, ".csa2"}
3234
3235 pat csa $1==2
3236 with BXREG ACC
3237 kills ALL
3238   gen jmp {label, ".csa2"}
3239
3240 pat csa $1==4
3241 with BXREG ACC DXREG
3242 kills ALL
3243   gen jmp {label, ".csa4"}
3244
3245 pat lae csb $2==2
3246 with ACC
3247 kills ALL
3248 uses BXREG = { ADDR_EXTERN, $1}
3249   gen jmp {label, ".csb2"}
3250
3251 pat csb $1==2
3252 with BXREG ACC
3253 kills ALL
3254   gen jmp {label, ".csb2"}
3255
3256 pat csb $1==4
3257 with BXREG ACC DXREG
3258 kills ALL
3259   gen jmp {label, ".csb4"}
3260
3261 pat dup $1==2
3262 with anyreg                             yields %1 %1
3263 with ACC1                               yields %1 %1
3264
3265 pat dup $1==4
3266 with regorconst regorconst              yields %2 %1 %2 %1
3267
3268 pat dup
3269 kills ALL
3270   gen mov cx,{ANYCON,$1}
3271       joehoe {label, ".dup"}
3272
3273 pat dus $1==2
3274 with CXREG
3275 kills ALL
3276   gen joehoe {label, ".dup"}
3277
3278 pat dus !defined($1)
3279 with rm-CXREG CXREG
3280 kills ALL
3281   gen cmp %1,{ANYCON,2}
3282       jne {label, ".unknown"}
3283       joehoe {label, ".dup"}
3284
3285 pat exg $1==2
3286 with a_word a_word                      yields %1 %2
3287
3288 pat exg $1==4
3289 with a_word a_word a_word a_word        yields %2 %1 %4 %3
3290
3291 pat exg defined($1)
3292 kills ALL
3293   gen mov cx,{ANYCON,$1}
3294       joehoe {label, ".exg"}
3295
3296 pat exg
3297 with CXREG
3298   kills ALL
3299   gen joehoe {label, ".exg"}
3300
3301 pat gto
3302 kills ALL
3303   gen mov bx,{ADDR_EXTERN,$1}
3304       jmp {label, ".gto"}
3305
3306 pat fil
3307   gen mov {EXTERN2,"hol0+4"},{ADDR_EXTERN,$1}
3308
3309 pat lim
3310   uses REG
3311   gen mov %a,{EXTERN2,".ignmask"}                       yields %a
3312
3313 pat lin
3314   gen mov {EXTERN2,"hol0"},{ANYCON,$1}
3315
3316 pat lni
3317   gen inc {EXTERN2,"hol0"}
3318
3319 pat lor $1==0                           yields bp
3320
3321 pat lor $1==1
3322 with STACK
3323   uses REG
3324   gen mov %a,sp                         yields %a
3325
3326 pat lor $1==2
3327   uses REG
3328   gen mov %a,{EXTERN2,".reghp"}         yields %a
3329
3330 pat mon
3331 with ACC
3332 kills ALL
3333   gen joehoe {label, ".mon"}
3334
3335 pat nop
3336 kills ALL
3337 #if DEBUG
3338   gen joehoe {label, ".nop"}
3339 #endif
3340
3341 pat rck $1==2
3342 with BXREG ACC
3343 kills ALL
3344   gen joehoe {label, ".rck"}                            yields ax
3345
3346 pat rck !defined($1)
3347 with rm-BXREG-ACC BXREG ACC
3348 kills ALL
3349   gen cmp %1,{ANYCON,2}
3350       jne {label, ".unknown"}
3351       joehoe {label, ".rck"}                            yields ax
3352
3353 pat rtt                                         leaving ret 0
3354
3355 pat sig
3356 with REG
3357   gen xchg {EXTERN2,".trppc"},%1                        yields %1
3358
3359 pat sim
3360 with regorconst
3361   gen mov {EXTERN2,".ignmask"},%1
3362
3363 pat str $1==0
3364 with rmorconst
3365   gen mov bp,%1
3366
3367 pat str $1==1
3368 with rmorconst STACK
3369   gen mov sp,%1
3370
3371 pat str $1==2
3372 kills ALL
3373   gen joehoe {label, ".strhp"}
3374
3375 pat trp
3376 with ACC
3377 kills ALL
3378   gen joehoe {label, ".Xtrp"}