OSDN Git Service

* rtlanal.c (dead_or_set_regno_p): Ignore REG_DEAD notes after
[pf3gnuchains/gcc-fork.git] / gcc / config / m32r / m32r.md
1 ;; Machine description of the Mitsubishi M32R cpu for GNU C compiler
2 ;; Copyright (C) 1996, 1997 Free Software Foundation, Inc.
3
4 ;; This file is part of GNU CC.
5
6 ;; GNU CC is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation; either version 2, or (at your option)
9 ;; any later version.
10
11 ;; GNU CC is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;; GNU General Public License for more details.
15
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with GNU CC; see the file COPYING.  If not, write to
18 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
19 ;; Boston, MA 02111-1307, USA.
20
21 ;; See file "rtl.def" for documentation on define_insn, match_*, et. al.
22
23 ;; unspec usage
24 ;; 0 - blockage
25 ;; 1 - flush_icache
26 ;; 2 - load_sda_base
27 \f
28 ;; Insn type.  Used to default other attribute values.
29 ;; move4 = 4 byte move
30 (define_attr "type"
31   "move,move4,load,store,unary,binary,compare,shift,mul,div,uncond_branch,branch,call,multi,misc"
32   (const_string "misc"))
33
34 ;; Length in bytes.
35 (define_attr "length" ""
36   (cond [(eq_attr "type" "move,unary,shift,mul,div")
37          (const_int 2)
38
39          (eq_attr "type" "binary")
40          (if_then_else (match_operand 2 "register_operand" "")
41                        (const_int 2) (const_int 4))
42
43          (eq_attr "type" "compare")
44          (if_then_else (match_operand 1 "register_operand" "")
45                        (const_int 2) (const_int 4))
46
47          (eq_attr "type" "load")
48          (if_then_else (match_operand 1 "memreg_operand" "")
49                        (const_int 2) (const_int 4))
50
51          (eq_attr "type" "store")
52          (if_then_else (match_operand 0 "memreg_operand" "")
53                        (const_int 2) (const_int 4))
54
55          (eq_attr "type" "multi")
56          (const_int 8)
57
58          (eq_attr "type" "uncond_branch,branch,call")
59          (const_int 4)]
60
61          (const_int 4)))
62
63 ;; The length here is the length of a single asm.  Unfortunately it might be
64 ;; 2 or 4 so we must allow for 4.  That's ok though.
65 (define_asm_attributes
66   [(set_attr "length" "4")
67    (set_attr "type" "multi")])
68 \f
69 ;; Function units of the M32R
70 ;; Units that take one cycle do not need to be specified.
71
72 ;; (define_function_unit {name} {num-units} {n-users} {test}
73 ;;                       {ready-delay} {issue-delay} [{conflict-list}])
74
75 ;; References to loaded registers should wait a cycle.
76 ;; Memory with load-delay of 1 (i.e. 2 cycle load).
77 (define_function_unit "memory" 1 1 (eq_attr "type" "load") 2 0)
78
79 ;; Hack to get GCC to better pack the instructions.
80 ;; We pretend there is a separate long function unit that conflicts with
81 ;; both the left and right 16 bit insn slots.
82
83 (define_function_unit "left" 1 1
84   (eq_attr "length" "2")
85   1 0
86   [(not (eq_attr "length" "2"))])
87
88 (define_function_unit "right" 1 1
89   (eq_attr "length" "1")
90   1 0
91   [(not (eq_attr "length" "2"))])
92
93 (define_function_unit "long" 1 1
94   (not (eq_attr "length" "2"))
95   1 0
96   [(eq_attr "length" "2")])
97 \f
98 ;; Expand prologue as RTL
99 ;; ??? Unfinished.
100
101 ;(define_expand "prologue"
102 ;  [(const_int 1)]
103 ;  ""
104 ;  "
105 ;{
106 ;}")
107 \f
108 ;; Move instructions.
109 ;;
110 ;; For QI and HI moves, the register must contain the full properly
111 ;; sign-extended value.  nonzero_bits assumes this [otherwise
112 ;; SHORT_IMMEDIATES_SIGN_EXTEND must be used, but the comment for it
113 ;; says it's a kludge and the .md files should be fixed instead].
114
115 (define_expand "movqi"
116   [(set (match_operand:QI 0 "general_operand" "")
117         (match_operand:QI 1 "general_operand" ""))]
118   ""
119   "
120 {
121   /* Everything except mem = const or mem = mem can be done easily.
122      Objects in the small data area are handled too.  */
123
124   if (GET_CODE (operands[0]) == MEM)
125     operands[1] = force_reg (QImode, operands[1]);
126 }")
127
128 (define_insn "*movqi_insn"
129   [(set (match_operand:QI 0 "move_dest_operand" "=r,r,r,r,m")
130         (match_operand:QI 1 "move_src_operand" "r,I,JQR,m,r"))]
131   "register_operand (operands[0], QImode) || register_operand (operands[1], QImode)"
132   "@
133    mv %0,%1
134    ldi %0,%#%1
135    ldi %0,%#%1
136    ldub %0,%1
137    stb %1,%0"
138   [(set_attr "type" "move,move,move4,load,store")])
139
140 (define_expand "movhi"
141   [(set (match_operand:HI 0 "general_operand" "")
142         (match_operand:HI 1 "general_operand" ""))]
143   ""
144   "
145 {
146   /* Everything except mem = const or mem = mem can be done easily.  */
147
148   if (GET_CODE (operands[0]) == MEM)
149     operands[1] = force_reg (HImode, operands[1]);
150 }")
151
152 (define_insn "*movhi_insn"
153   [(set (match_operand:HI 0 "move_dest_operand" "=r,r,r,r,r,m")
154         (match_operand:HI 1 "move_src_operand" "r,I,JQR,K,m,r"))]
155   "register_operand (operands[0], HImode) || register_operand (operands[1], HImode)"
156   "@
157    mv %0,%1
158    ldi %0,%#%1
159    ldi %0,%#%1
160    ld24 %0,%#%1
161    lduh %0,%1
162    sth %1,%0"
163   [(set_attr "type" "move,move,move4,move4,load,store")])
164
165 (define_expand "movsi"
166   [(set (match_operand:SI 0 "general_operand" "")
167         (match_operand:SI 1 "general_operand" ""))]
168   ""
169   "
170 {
171   /* Everything except mem = const or mem = mem can be done easily.  */
172
173   if (GET_CODE (operands[0]) == MEM)
174     operands[1] = force_reg (SImode, operands[1]);
175
176   /* Small Data Area reference?  */
177   if (small_data_operand (operands[1], SImode))
178     {
179       emit_insn (gen_movsi_sda (operands[0], operands[1]));
180       DONE;
181     }
182
183   /* If medium or large code model, symbols have to be loaded with
184      seth/add3.  */
185   if (addr32_operand (operands[1], SImode))
186     {
187       emit_insn (gen_movsi_addr32 (operands[0], operands[1]));
188       DONE;
189     }
190 }")
191
192 (define_insn "*movsi_insn"
193   [(set (match_operand:SI 0 "move_dest_operand" "=r,r,r,r,r,r,r,m")
194 ;; ??? Do we need a const_double constraint here for large unsigned values?
195         (match_operand:SI 1 "move_src_operand" "r,I,J,MQ,L,N,m,r"))]
196   "register_operand (operands[0], SImode) || register_operand (operands[1], SImode)"
197   "@
198    mv %0,%1
199    ldi %0,%#%1 ; %X1
200    ldi %0,%#%1 ; %X1
201    ld24 %0,%#%1 ; %X1
202    seth %0,%#%T1
203    seth %0,%#%T1\;or3 %0,%0,%#%B1
204    ld %0,%1
205    st %1,%0"
206   [(set_attr "type" "move,move,move4,move4,move4,multi,load,store")])
207
208 ; Try to use a four byte / two byte pair for constants not loadable with
209 ; ldi, ld24, seth.
210
211 (define_split
212  [(set (match_operand:SI 0 "register_operand" "")
213        (match_operand:SI 1 "two_insn_const_operand" ""))]
214   ""
215   [(set (match_dup 0) (match_dup 2))
216    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 3)))]
217   "
218 {
219   unsigned HOST_WIDE_INT val = INTVAL (operands[1]);
220   unsigned HOST_WIDE_INT tmp;
221   int shift;
222
223   /* In all cases we will emit two instructions.  However we try to
224      use 2 byte instructions wherever possible.  We can assume the
225      constant isn't loadable with any of ldi, ld24, or seth.  */
226
227   /* See if we can load a 24 bit unsigned value and invert it.  */
228   if (UINT24_P (~ val))
229     {
230       emit_insn (gen_movsi (operands[0], GEN_INT (~ val)));
231       emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
232       DONE;
233     }
234
235   /* See if we can load a 24 bit unsigned value and shift it into place.
236      0x01fffffe is just beyond ld24's range.  */
237   for (shift = 1, tmp = 0x01fffffe;
238        shift < 8;
239        ++shift, tmp <<= 1)
240     {
241       if ((val & ~tmp) == 0)
242         {
243           emit_insn (gen_movsi (operands[0], GEN_INT (val >> shift)));
244           emit_insn (gen_ashlsi3 (operands[0], operands[0], GEN_INT (shift)));
245           DONE;
246         }
247     }
248
249   /* Can't use any two byte insn, fall back to seth/or3.  */
250   operands[2] = GEN_INT ((val) & 0xffff0000);
251   operands[3] = GEN_INT ((val) & 0xffff);
252 }")
253
254 ;; Small data area support.
255 ;; The address of _SDA_BASE_ is loaded into a register and all objects in
256 ;; the small data area are indexed off that.  This is done for each reference
257 ;; but cse will clean things up for us.  We let the compiler choose the
258 ;; register to use so we needn't allocate (and maybe even fix) a special
259 ;; register to use.  Since the load and store insns have a 16 bit offset the
260 ;; total size of the data area can be 64K.  However, if the data area lives
261 ;; above 16M (24 bits), _SDA_BASE_ will have to be loaded with seth/add3 which
262 ;; would then yield 3 instructions to reference an object [though there would
263 ;; be no net loss if two or more objects were referenced].  The 3 insns can be
264 ;; reduced back to 2 if the size of the small data area were reduced to 32K
265 ;; [then seth + ld/st would work for any object in the area].  Doing this
266 ;; would require special handling of _SDA_BASE_ (its value would be
267 ;; (.sdata + 32K) & 0xffff0000) and reloc computations would be different
268 ;; [I think].  What to do about this is deferred until later and for now we
269 ;; require .sdata to be in the first 16M.
270
271 (define_expand "movsi_sda"
272   [(set (match_dup 2)
273         (unspec [(const_int 0)] 2))
274    (set (match_operand:SI 0 "register_operand" "")
275         (lo_sum:SI (match_dup 2)
276                    (match_operand:SI 1 "small_data_operand" "")))]
277   ""
278   "
279 {
280   if (reload_in_progress || reload_completed)
281     operands[2] = operands[0];
282   else
283     operands[2] = gen_reg_rtx (SImode);
284 }")
285
286 (define_insn "*load_sda_base"
287   [(set (match_operand:SI 0 "register_operand" "=r")
288         (unspec [(const_int 0)] 2))]
289   ""
290   "ld24 %0,#_SDA_BASE_"
291   [(set_attr "type" "move4")])
292
293 ;; 32 bit address support.
294
295 (define_expand "movsi_addr32"
296   [(set (match_dup 2)
297         ; addr32_operand isn't used because it's too restrictive,
298         ; seth_add3_operand is more general and thus safer.
299         (high:SI (match_operand:SI 1 "seth_add3_operand" "")))
300    (set (match_operand:SI 0 "register_operand" "")
301         (lo_sum:SI (match_dup 2) (match_dup 1)))]
302   ""
303   "
304 {
305   if (reload_in_progress || reload_completed)
306     operands[2] = operands[0];
307   else
308     operands[2] = gen_reg_rtx (SImode);
309 }")
310
311 (define_insn "set_hi_si"
312   [(set (match_operand:SI 0 "register_operand" "=r")
313         (high:SI (match_operand 1 "symbolic_operand" "")))]
314   ""
315   "seth %0,%#shigh(%1)"
316   [(set_attr "type" "move4")])
317
318 (define_insn "lo_sum_si"
319   [(set (match_operand:SI 0 "register_operand" "=r")
320         (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
321                    (match_operand:SI 2 "immediate_operand" "in")))]
322   ""
323   "add3 %0,%1,%#%B2"
324   [(set_attr "length" "4")])
325
326 (define_expand "movdi"
327   [(set (match_operand:DI 0 "general_operand" "")
328         (match_operand:DI 1 "general_operand" ""))]
329   ""
330   "
331 {
332   /* Everything except mem = const or mem = mem can be done easily.  */
333
334   if (GET_CODE (operands[0]) == MEM)
335     operands[1] = force_reg (DImode, operands[1]);
336
337   if (CONSTANT_P (operands[1])
338       && ! easy_di_const (operands[1]))
339     {
340       rtx mem = force_const_mem (DImode, operands[1]);
341       rtx reg = ((reload_in_progress || reload_completed)
342                  ? copy_to_suggested_reg (XEXP (mem, 0),
343                                           gen_rtx (REG, Pmode, REGNO (operands[0])),
344                                           Pmode)
345                  : force_reg (Pmode, XEXP (mem, 0)));
346       operands[1] = change_address (mem, DImode, reg);
347     }
348 }")
349
350 (define_insn "*movdi_insn"
351   [(set (match_operand:DI 0 "move_dest_operand" "=r,r,r,m")
352         (match_operand:DI 1 "move_double_src_operand" "r,nG,m,r"))]
353   "register_operand (operands[0], DImode) || register_operand (operands[1], DImode)"
354   "*
355 {
356   switch (which_alternative)
357     {
358     case 0 :
359       /* We normally copy the low-numbered register first.  However, if
360          the first register operand 0 is the same as the second register of
361          operand 1, we must copy in the opposite order.  */
362       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
363         return \"mv %R0,%R1\;mv %0,%1\";
364       else
365         return \"mv %0,%1\;mv %R0,%R1\";
366     case 1 :
367       return \"#\";
368     case 2 :
369       /* If the low-address word is used in the address, we must load it
370          last.  Otherwise, load it first.  Note that we cannot have
371          auto-increment in that case since the address register is known to be
372          dead.  */
373       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
374                              operands [1], 0))
375         {
376           return \"ld %R0,%R1\;ld %0,%1\";
377         }
378       else
379         {
380           /* Try to use auto-inc addressing if we can.  */
381           if (GET_CODE (XEXP (operands[1], 0)) == REG
382               && dead_or_set_p (insn, XEXP (operands[1], 0)))
383             {
384               operands[1] = XEXP (operands[1], 0);
385               return \"ld %0,@%1+\;ld %R0,@%1\";
386             }
387           return \"ld %0,%1\;ld %R0,%R1\";
388         }
389     case 3 :
390       /* Try to use auto-inc addressing if we can.  */
391       if (GET_CODE (XEXP (operands[0], 0)) == REG
392           && dead_or_set_p (insn, XEXP (operands[0], 0)))
393         {
394           operands[0] = XEXP (operands[0], 0);
395           return \"st %1,@%0\;st %R1,@+%0\";
396         }
397       return \"st %1,%0\;st %R1,%R0\";
398     }
399 }"
400   [(set_attr "type" "multi,multi,multi,multi")
401    (set_attr "length" "4,4,6,6")])
402
403 (define_split
404   [(set (match_operand:DI 0 "register_operand" "")
405         (match_operand:DI 1 "const_double_operand" ""))]
406   "reload_completed"
407   [(set (match_dup 2) (match_dup 4))
408    (set (match_dup 3) (match_dup 5))]
409   "
410 {
411   operands[2] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN == 0);
412   operands[3] = gen_rtx (SUBREG, SImode, operands[0], WORDS_BIG_ENDIAN != 0);
413   split_double (operands[1], operands + 4, operands + 5);
414 }")
415 \f
416 ;; Floating point move insns.
417
418 (define_expand "movsf"
419   [(set (match_operand:SF 0 "general_operand" "")
420         (match_operand:SF 1 "general_operand" ""))]
421   ""
422   "
423 {
424   /* Everything except mem = const or mem = mem can be done easily.  */
425
426   if (GET_CODE (operands[0]) == MEM)
427     operands[1] = force_reg (SFmode, operands[1]);
428 }")
429
430 (define_insn "*movsf_insn"
431   [(set (match_operand:SF 0 "move_dest_operand" "=r,r,r,m")
432         (match_operand:SF 1 "move_src_operand" "r,F,m,r"))]
433   "register_operand (operands[0], SFmode) || register_operand (operands[1], SFmode)"
434   "*
435 {
436   switch (which_alternative)
437     {
438     case 0 :
439       return \"mv %0,%1\";
440     case 1 :
441       {
442         REAL_VALUE_TYPE r;
443         long l;
444         REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
445         REAL_VALUE_TO_TARGET_SINGLE (r, l);
446         operands[1] = GEN_INT (l);
447         if (l == 0)
448           return \"ldi %0,%#0\";
449         if ((l & 0xffff) == 0)
450           return \"seth %0,%#%T1\";
451         else
452           return \"seth %0,%#%T1\;or3 %0,%0,%#%B1\";
453       }
454     case 2 :
455       return \"ld %0,%1\";
456     case 3 :
457       return \"st %1,%0\";
458     }
459 }"
460   ;; ??? Length of alternative 1 is either 2, 4 or 8.
461   [(set_attr "type" "move,multi,load,store")])
462
463 (define_expand "movdf"
464   [(set (match_operand:DF 0 "general_operand" "")
465         (match_operand:DF 1 "general_operand" ""))]
466   ""
467   "
468 {
469   /* Everything except mem = const or mem = mem can be done easily.  */
470
471   if (GET_CODE (operands[0]) == MEM)
472     operands[1] = force_reg (DFmode, operands[1]);
473
474   if (GET_CODE (operands[1]) == CONST_DOUBLE
475       && ! easy_df_const (operands[1]))
476     {
477       rtx mem = force_const_mem (DFmode, operands[1]);
478       rtx reg = ((reload_in_progress || reload_completed)
479                  ? copy_to_suggested_reg (XEXP (mem, 0),
480                                           gen_rtx (REG, Pmode, REGNO (operands[0])),
481                                           Pmode)
482                  : force_reg (Pmode, XEXP (mem, 0)));
483       operands[1] = change_address (mem, DFmode, reg);
484     }
485 }")
486
487 (define_insn "*movdf_insn"
488   [(set (match_operand:DF 0 "move_dest_operand" "=r,r,r,m")
489         (match_operand:DF 1 "move_double_src_operand" "r,H,m,r"))]
490   "register_operand (operands[0], DFmode) || register_operand (operands[1], DFmode)"
491   "*
492 {
493   switch (which_alternative)
494     {
495     case 0 :
496       /* We normally copy the low-numbered register first.  However, if
497          the first register operand 0 is the same as the second register of
498          operand 1, we must copy in the opposite order.  */
499       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
500         return \"mv %R0,%R1\;mv %0,%1\";
501       else
502         return \"mv %0,%1\;mv %R0,%R1\";
503     case 1 :
504       {
505         REAL_VALUE_TYPE r;
506         long l[2];
507         REAL_VALUE_FROM_CONST_DOUBLE (r, operands[1]);
508         REAL_VALUE_TO_TARGET_DOUBLE (r, l);
509         operands[1] = GEN_INT (l[0]);
510         if (l[0] == 0 && l[1] == 0)
511           return \"ldi %0,%#0\;ldi %R0,%#0\";
512         else if (l[1] != 0)
513           abort ();
514         else if ((l[0] & 0xffff) == 0)
515           return \"seth %0,%#%T1\;ldi %R0,%#0\";
516         else
517           abort ();
518       }
519     case 2 :
520       /* If the low-address word is used in the address, we must load it
521          last.  Otherwise, load it first.  Note that we cannot have
522          auto-increment in that case since the address register is known to be
523          dead.  */
524       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
525                              operands [1], 0))
526         {
527           return \"ld %R0,%R1\;ld %0,%1\";
528         }
529       else
530         {
531           /* Try to use auto-inc addressing if we can.  */
532           if (GET_CODE (XEXP (operands[1], 0)) == REG
533               && dead_or_set_p (insn, XEXP (operands[1], 0)))
534             {
535               operands[1] = XEXP (operands[1], 0);
536               return \"ld %0,@%1+\;ld %R0,@%1\";
537             }
538           return \"ld %0,%1\;ld %R0,%R1\";
539         }
540     case 3 :
541       /* Try to use auto-inc addressing if we can.  */
542       if (GET_CODE (XEXP (operands[0], 0)) == REG
543           && dead_or_set_p (insn, XEXP (operands[0], 0)))
544         {
545           operands[0] = XEXP (operands[0], 0);
546           return \"st %1,@%0\;st %R1,@+%0\";
547         }
548       return \"st %1,%0\;st %R1,%R0\";
549     }
550 }"
551   [(set_attr "type" "multi,multi,multi,multi")
552    (set_attr "length" "4,6,6,6")])
553 \f
554 ;; Zero extension instructions.
555
556 (define_insn "zero_extendqihi2"
557   [(set (match_operand:HI 0 "register_operand" "=r,r")
558         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
559   ""
560   "@
561    and3 %0,%1,%#255
562    ldub %0,%1"
563   [(set_attr "type" "unary,load")
564    (set_attr "length" "4,*")])
565
566 (define_insn "zero_extendqisi2"
567   [(set (match_operand:SI 0 "register_operand" "=r,r")
568         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,m")))]
569   ""
570   "@
571    and3 %0,%1,%#255
572    ldub %0,%1"
573   [(set_attr "type" "unary,load")
574    (set_attr "length" "4,*")])
575
576 (define_insn "zero_extendhisi2"
577   [(set (match_operand:SI 0 "register_operand" "=r,r")
578         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,m")))]
579   ""
580   "@
581    and3 %0,%1,%#65535
582    lduh %0,%1"
583   [(set_attr "type" "unary,load")
584    (set_attr "length" "4,*")])
585 \f
586 ;; Sign extension instructions.
587 ;; ??? See v850.md.
588
589 ;; These patterns originally accepted general_operands, however, slightly
590 ;; better code is generated by only accepting register_operands, and then
591 ;; letting combine generate the lds[hb] insns.
592 ;; [This comment copied from sparc.md, I think.]
593
594 (define_expand "extendqihi2"
595   [(set (match_operand:HI 0 "register_operand" "")
596         (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
597   ""
598   "
599 {
600   rtx temp = gen_reg_rtx (SImode);
601   rtx shift_24 = gen_rtx (CONST_INT, VOIDmode, 24);
602   int op1_subword = 0;
603   int op0_subword = 0;
604
605   if (GET_CODE (operand1) == SUBREG)
606     {
607       op1_subword = SUBREG_WORD (operand1);
608       operand1 = XEXP (operand1, 0);
609     }
610   if (GET_CODE (operand0) == SUBREG)
611     {
612       op0_subword = SUBREG_WORD (operand0);
613       operand0 = XEXP (operand0, 0);
614     }
615   emit_insn (gen_ashlsi3 (temp, gen_rtx (SUBREG, SImode, operand1,
616                                          op1_subword),
617                           shift_24));
618   if (GET_MODE (operand0) != SImode)
619     operand0 = gen_rtx (SUBREG, SImode, operand0, op0_subword);
620   emit_insn (gen_ashrsi3 (operand0, temp, shift_24));
621   DONE;
622 }")
623
624 (define_insn "*sign_extendqihi2_insn"
625   [(set (match_operand:HI 0 "register_operand" "=r")
626         (sign_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
627   ""
628   "ldb %0,%1"
629   [(set_attr "type" "load")])
630
631 (define_expand "extendqisi2"
632   [(set (match_operand:SI 0 "register_operand" "")
633         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
634   ""
635   "
636 {
637   rtx temp = gen_reg_rtx (SImode);
638   rtx shift_24 = gen_rtx (CONST_INT, VOIDmode, 24);
639   int op1_subword = 0;
640
641   if (GET_CODE (operand1) == SUBREG)
642     {
643       op1_subword = SUBREG_WORD (operand1);
644       operand1 = XEXP (operand1, 0);
645     }
646
647   emit_insn (gen_ashlsi3 (temp, gen_rtx (SUBREG, SImode, operand1,
648                                          op1_subword),
649                           shift_24));
650   emit_insn (gen_ashrsi3 (operand0, temp, shift_24));
651   DONE;
652 }")
653
654 (define_insn "*sign_extendqisi2_insn"
655   [(set (match_operand:SI 0 "register_operand" "=r")
656         (sign_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
657   ""
658   "ldb %0,%1"
659   [(set_attr "type" "load")])
660
661 (define_expand "extendhisi2"
662   [(set (match_operand:SI 0 "register_operand" "")
663         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
664   ""
665   "
666 {
667   rtx temp = gen_reg_rtx (SImode);
668   rtx shift_16 = gen_rtx (CONST_INT, VOIDmode, 16);
669   int op1_subword = 0;
670
671   if (GET_CODE (operand1) == SUBREG)
672     {
673       op1_subword = SUBREG_WORD (operand1);
674       operand1 = XEXP (operand1, 0);
675     }
676
677   emit_insn (gen_ashlsi3 (temp, gen_rtx (SUBREG, SImode, operand1,
678                                          op1_subword),
679                           shift_16));
680   emit_insn (gen_ashrsi3 (operand0, temp, shift_16));
681   DONE;
682 }")
683
684 (define_insn "*sign_extendhisi2_insn"
685   [(set (match_operand:SI 0 "register_operand" "=r")
686         (sign_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
687   ""
688   "ldh %0,%1"
689   [(set_attr "type" "load")])
690 \f
691 ;; Arithmetic instructions.
692
693 ; ??? Adding an alternative to split add3 of small constants into two
694 ; insns yields better instruction packing but slower code.  Adds of small
695 ; values is done a lot.
696
697 (define_insn "addsi3"
698   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
699         (plus:SI (match_operand:SI 1 "register_operand" "%0,0,r")
700                  (match_operand:SI 2 "nonmemory_operand" "r,I,J")))]
701   ""
702   "@
703    add %0,%2
704    addi %0,%#%2
705    add3 %0,%1,%#%2"
706   [(set_attr "type" "binary")
707    (set_attr "length" "2,2,4")])
708
709 ;(define_split
710 ;  [(set (match_operand:SI 0 "register_operand" "")
711 ;       (plus:SI (match_operand:SI 1 "register_operand" "")
712 ;                (match_operand:SI 2 "int8_operand" "")))]
713 ;  "reload_completed
714 ;   && REGNO (operands[0]) != REGNO (operands[1])
715 ;   && INT8_P (INTVAL (operands[2]))
716 ;   && INTVAL (operands[2]) != 0"
717 ;  [(set (match_dup 0) (match_dup 1))
718 ;   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
719 ;  "")
720
721 (define_insn "adddi3"
722   [(set (match_operand:DI 0 "register_operand" "=r")
723         (plus:DI (match_operand:DI 1 "register_operand" "%0")
724                  (match_operand:DI 2 "register_operand" "r")))
725    (clobber (reg:CC 17))]
726   ""
727   "*
728 {
729   /* ??? The cmp clears the condition bit.  Can we speed up somehow?  */
730   return \"cmp %L0,%L0\;addx %L0,%L2\;addx %H0,%H2\";
731 }"
732   [(set_attr "type" "binary")
733    (set_attr "length" "6")])
734
735 (define_insn "subsi3"
736   [(set (match_operand:SI 0 "register_operand" "=r")
737         (minus:SI (match_operand:SI 1 "register_operand" "0")
738                   (match_operand:SI 2 "register_operand" "r")))]
739   ""
740   "sub %0,%2"
741   [(set_attr "type" "binary")])
742
743 (define_insn "subdi3"
744   [(set (match_operand:DI 0 "register_operand" "=r")
745         (minus:DI (match_operand:DI 1 "register_operand" "0")
746                   (match_operand:DI 2 "register_operand" "r")))
747    (clobber (reg:CC 17))]
748   ""
749   "*
750 {
751   /* ??? The cmp clears the condition bit.  Can we speed up somehow?  */
752   return \"cmp %L0,%L0\;subx %L0,%L2\;subx %H0,%H2\";
753 }"
754   [(set_attr "type" "binary")
755    (set_attr "length" "6")])
756 \f
757 ; Multiply/Divide instructions.
758
759 (define_insn "mulhisi3"
760   [(set (match_operand:SI 0 "register_operand" "=r")
761         (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "r"))
762                  (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
763   ""
764   "mullo %1,%2\;mvfacmi %0"
765   [(set_attr "type" "mul")
766    (set_attr "length" "4")])
767
768 (define_insn "mulsi3"
769   [(set (match_operand:SI 0 "register_operand" "=r")
770         (mult:SI (match_operand:SI 1 "register_operand" "%0")
771                  (match_operand:SI 2 "register_operand" "r")))]
772   ""
773   "mul %0,%2"
774   [(set_attr "type" "mul")])
775
776 (define_insn "divsi3"
777   [(set (match_operand:SI 0 "register_operand" "=r")
778         (div:SI (match_operand:SI 1 "register_operand" "0")
779                 (match_operand:SI 2 "register_operand" "r")))]
780   ""
781   "div %0,%2"
782   [(set_attr "type" "div")])
783
784 (define_insn "udivsi3"
785   [(set (match_operand:SI 0 "register_operand" "=r")
786         (udiv:SI (match_operand:SI 1 "register_operand" "0")
787                  (match_operand:SI 2 "register_operand" "r")))]
788   ""
789   "divu %0,%2"
790   [(set_attr "type" "div")])
791
792 (define_insn "modsi3"
793   [(set (match_operand:SI 0 "register_operand" "=r")
794         (mod:SI (match_operand:SI 1 "register_operand" "0")
795                 (match_operand:SI 2 "register_operand" "r")))]
796   ""
797   "rem %0,%2"
798   [(set_attr "type" "div")])
799
800 (define_insn "umodsi3"
801   [(set (match_operand:SI 0 "register_operand" "=r")
802         (umod:SI (match_operand:SI 1 "register_operand" "0")
803                  (match_operand:SI 2 "register_operand" "r")))]
804   ""
805   "remu %0,%2"
806   [(set_attr "type" "div")])
807 \f
808 ;; Boolean instructions.
809 ;;
810 ;; We don't define the DImode versions as expand_binop does a good enough job.
811 ;; And if it doesn't it should be fixed.
812
813 (define_insn "andsi3"
814   [(set (match_operand:SI 0 "register_operand" "=r,r")
815         (and:SI (match_operand:SI 1 "register_operand" "%0,r")
816                 (match_operand:SI 2 "nonmemory_operand" "r,K")))]
817   ""
818   "@
819    and %0,%2
820    and3 %0,%1,%#%2 ; %X2"
821   [(set_attr "type" "binary")])
822
823 (define_insn "iorsi3"
824   [(set (match_operand:SI 0 "register_operand" "=r,r")
825         (ior:SI (match_operand:SI 1 "register_operand" "%0,r")
826                 (match_operand:SI 2 "nonmemory_operand" "r,K")))]
827   ""
828   "@
829    or %0,%2
830    or3 %0,%1,%#%2 ; %X2"
831   [(set_attr "type" "binary")])
832
833 (define_insn "xorsi3"
834   [(set (match_operand:SI 0 "register_operand" "=r,r")
835         (xor:SI (match_operand:SI 1 "register_operand" "%0,r")
836                 (match_operand:SI 2 "nonmemory_operand" "r,K")))]
837   ""
838   "@
839    xor %0,%2
840    xor3 %0,%1,%#%2 ; %X2"
841   [(set_attr "type" "binary")])
842
843 (define_insn "negsi2"
844   [(set (match_operand:SI 0 "register_operand" "=r")
845         (neg:SI (match_operand:SI 1 "register_operand" "r")))]
846   ""
847   "neg %0,%1"
848   [(set_attr "type" "unary")])
849
850 (define_insn "one_cmplsi2"
851   [(set (match_operand:SI 0 "register_operand" "=r")
852         (not:SI (match_operand:SI 1 "register_operand" "r")))]
853   ""
854   "not %0,%1"
855   [(set_attr "type" "unary")])
856 \f
857 ;; Shift instructions.
858
859 (define_insn "ashlsi3"
860   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
861         (ashift:SI (match_operand:SI 1 "register_operand" "0,0,r")
862                    (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
863   ""
864   "@
865    sll %0,%2
866    slli %0,%#%2
867    sll3 %0,%1,%#%2"
868   [(set_attr "type" "shift")
869    (set_attr "length" "2,2,4")])
870
871 (define_insn "ashrsi3"
872   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
873         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
874                      (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
875   ""
876   "@
877    sra %0,%2
878    srai %0,%#%2
879    sra3 %0,%1,%#%2"
880   [(set_attr "type" "shift")
881    (set_attr "length" "2,2,4")])
882
883 (define_insn "lshrsi3"
884   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
885         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
886                      (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
887   ""
888   "@
889    srl %0,%2
890    srli %0,%#%2
891    srl3 %0,%1,%#%2"
892   [(set_attr "type" "shift")
893    (set_attr "length" "2,2,4")])
894 \f
895 ;; Compare instructions.
896 ;; This controls RTL generation and register allocation.
897
898 ;; We generate RTL for comparisons and branches by having the cmpxx 
899 ;; patterns store away the operands.  Then the bcc patterns
900 ;; emit RTL for both the compare and the branch.
901 ;;
902 ;; On the m32r it is more efficient to use the bxxz instructions and
903 ;; thus merge the compare and branch into one instruction, so they are
904 ;; preferred.
905
906 (define_expand "cmpsi"
907   [(set (reg:CC 17)
908         (compare:CC (match_operand:SI 0 "register_operand" "")
909                     (match_operand:SI 1 "nonmemory_operand" "")))]
910   ""
911   "
912 {
913   m32r_compare_op0 = operands[0];
914   m32r_compare_op1 = operands[1];
915   DONE;
916 }")
917
918 ;; The cmp_xxx_insn patterns set the condition bit to the result of the
919 ;; comparison.  There isn't a "compare equal" instruction so cmp_eqsi_insn
920 ;; is quite inefficient.  However, it is rarely used.
921
922 (define_insn "cmp_eqsi_insn"
923   [(set (reg:CC 17)
924         (eq:CC (match_operand:SI 0 "register_operand" "r,r")
925                (match_operand:SI 1 "reg_or_cmp_int16_operand" "r,P")))
926    (clobber (match_scratch:SI 2 "=&r,&r"))]
927   "TARGET_OLD_COMPARE"
928   "@
929    mv %2,%0\;sub %2,%1\;cmpui %2,#1
930    add3 %2,%0,%#%N1\;cmpui %2,#1"
931   [(set_attr "type" "compare,compare")
932    (set_attr "length" "8,8")])
933
934 (define_insn "cmp_ltsi_insn"
935   [(set (reg:CC 17)
936         (lt:CC (match_operand:SI 0 "register_operand" "r,r")
937                (match_operand:SI 1 "reg_or_int16_operand" "r,J")))]
938   ""
939   "@
940    cmp %0,%1
941    cmpi %0,%#%1"
942   [(set_attr "type" "compare")])
943
944 (define_insn "cmp_ltusi_insn"
945   [(set (reg:CC 17)
946         (ltu:CC (match_operand:SI 0 "register_operand" "r,r")
947                 (match_operand:SI 1 "reg_or_uint16_operand" "r,K")))]
948   ""
949   "@
950    cmpu %0,%1
951    cmpui %0,%#%1"
952   [(set_attr "type" "compare")])
953
954 ;; reg == small constant comparisons are best handled by putting the result
955 ;; of the comparison in a tmp reg and then using beqz/bnez.
956 ;; ??? The result register doesn't contain 0/STORE_FLAG_VALUE,
957 ;; it contains 0/non-zero.
958
959 (define_insn "cmp_ne_small_const_insn"
960   [(set (match_operand:SI 0 "register_operand" "=r")
961         (ne:SI (match_operand:SI 1 "register_operand" "r")
962                (match_operand:SI 2 "cmp_int16_operand" "P")))]
963   ""
964   "add3 %0,%1,%#%N2"
965   [(set_attr "type" "compare")
966    (set_attr "length" "4")])
967 \f
968 ;; These control RTL generation for conditional jump insns.
969
970 (define_expand "beq"
971   [(set (pc)
972         (if_then_else (match_dup 1)
973                       (label_ref (match_operand 0 "" ""))
974                       (pc)))]
975   ""
976   "
977 {
978   operands[1] = gen_compare (EQ, m32r_compare_op0, m32r_compare_op1);
979 }")
980
981 (define_expand "bne"
982   [(set (pc)
983         (if_then_else (match_dup 1)
984                       (label_ref (match_operand 0 "" ""))
985                       (pc)))]
986   ""
987   "
988 {
989   operands[1] = gen_compare (NE, m32r_compare_op0, m32r_compare_op1);
990 }")
991
992 (define_expand "bgt"
993   [(set (pc)
994         (if_then_else (match_dup 1)
995                       (label_ref (match_operand 0 "" ""))
996                       (pc)))]
997   ""
998   "
999 {
1000   operands[1] = gen_compare (GT, m32r_compare_op0, m32r_compare_op1);
1001 }")
1002
1003 (define_expand "ble"
1004   [(set (pc)
1005         (if_then_else (match_dup 1)
1006                       (label_ref (match_operand 0 "" ""))
1007                       (pc)))]
1008   ""
1009   "
1010 {
1011   operands[1] = gen_compare (LE, m32r_compare_op0, m32r_compare_op1);
1012 }")
1013
1014 (define_expand "bge"
1015   [(set (pc)
1016         (if_then_else (match_dup 1)
1017                       (label_ref (match_operand 0 "" ""))
1018                       (pc)))]
1019   ""
1020   "
1021 {
1022   operands[1] = gen_compare (GE, m32r_compare_op0, m32r_compare_op1);
1023 }")
1024
1025 (define_expand "blt"
1026   [(set (pc)
1027         (if_then_else (match_dup 1)
1028                       (label_ref (match_operand 0 "" ""))
1029                       (pc)))]
1030   ""
1031   "
1032 {
1033   operands[1] = gen_compare (LT, m32r_compare_op0, m32r_compare_op1);
1034 }")
1035
1036 (define_expand "bgtu"
1037   [(set (pc)
1038         (if_then_else (match_dup 1)
1039                       (label_ref (match_operand 0 "" ""))
1040                       (pc)))]
1041   ""
1042   "
1043 {
1044   operands[1] = gen_compare (GTU, m32r_compare_op0, m32r_compare_op1);
1045 }")
1046
1047 (define_expand "bleu"
1048   [(set (pc)
1049         (if_then_else (match_dup 1)
1050                       (label_ref (match_operand 0 "" ""))
1051                       (pc)))]
1052   ""
1053   "
1054 {
1055   operands[1] = gen_compare (LEU, m32r_compare_op0, m32r_compare_op1);
1056 }")
1057
1058 (define_expand "bgeu"
1059   [(set (pc)
1060         (if_then_else (match_dup 1)
1061                       (label_ref (match_operand 0 "" ""))
1062                       (pc)))]
1063   ""
1064   "
1065 {
1066   operands[1] = gen_compare (GEU, m32r_compare_op0, m32r_compare_op1);
1067 }")
1068
1069 (define_expand "bltu"
1070   [(set (pc)
1071         (if_then_else (match_dup 1)
1072                       (label_ref (match_operand 0 "" ""))
1073                       (pc)))]
1074   ""
1075   "
1076 {
1077   operands[1] = gen_compare (LTU, m32r_compare_op0, m32r_compare_op1);
1078 }")
1079
1080 ;; Now match both normal and inverted jump.
1081
1082 (define_insn "*branch_insn"
1083   [(set (pc)
1084         (if_then_else (match_operator 1 "eqne_comparison_operator"
1085                                       [(reg 17) (const_int 0)])
1086                       (label_ref (match_operand 0 "" ""))
1087                       (pc)))]
1088   ""
1089   "*
1090 {
1091   if (GET_CODE (operands[1]) == NE)
1092     return \"bc %l0\";
1093   else
1094     return \"bnc %l0\";
1095 }"
1096   [(set_attr "type" "branch")
1097    ; We use 400/800 instead of 512,1024 to account for inaccurate insn
1098    ; lengths and insn alignments that are complex to track.
1099    ; It's not important that we be hyper-precise here.  It may be more
1100    ; important blah blah blah when the chip supports parallel execution
1101    ; blah blah blah but until then blah blah blah this is simple and
1102    ; suffices.
1103    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1104                                                  (const_int 400))
1105                                            (const_int 800))
1106                                       (const_int 2)
1107                                       (const_int 4)))])
1108
1109 (define_insn "*rev_branch_insn"
1110   [(set (pc)
1111         (if_then_else (match_operator 1 "eqne_comparison_operator"
1112                                       [(reg 17) (const_int 0)])
1113                       (pc)
1114                       (label_ref (match_operand 0 "" ""))))]
1115   ;"REVERSIBLE_CC_MODE (GET_MODE (XEXP (operands[1], 0)))"
1116   ""
1117   "*
1118 {
1119   if (GET_CODE (operands[1]) == EQ)
1120     return \"bc %l0\";
1121   else
1122     return \"bnc %l0\";
1123 }"
1124   [(set_attr "type" "branch")
1125    ; We use 400/800 instead of 512,1024 to account for inaccurate insn
1126    ; lengths and insn alignments that are complex to track.
1127    ; It's not important that we be hyper-precise here.  It may be more
1128    ; important blah blah blah when the chip supports parallel execution
1129    ; blah blah blah but until then blah blah blah this is simple and
1130    ; suffices.
1131    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1132                                                  (const_int 400))
1133                                            (const_int 800))
1134                                       (const_int 2)
1135                                       (const_int 4)))])
1136
1137 ; reg/reg compare and branch insns
1138
1139 (define_insn "*reg_branch_insn"
1140   [(set (pc)
1141         (if_then_else (match_operator 1 "eqne_comparison_operator"
1142                                       [(match_operand:SI 2 "register_operand" "r")
1143                                        (match_operand:SI 3 "register_operand" "r")])
1144                       (label_ref (match_operand 0 "" ""))
1145                       (pc)))]
1146   ""
1147   "*
1148 {
1149   /* Is branch target reachable with beq/bne?  */
1150   if (get_attr_length (insn) == 4)
1151     {
1152       if (GET_CODE (operands[1]) == EQ)
1153         return \"beq %2,%3,%l0\";
1154       else
1155         return \"bne %2,%3,%l0\";
1156     }
1157   else
1158     {
1159       if (GET_CODE (operands[1]) == EQ)
1160         return \"bne %2,%3,1f\;bra %l0\;1:\";
1161       else
1162         return \"beq %2,%3,1f\;bra %l0\;1:\";
1163     }
1164 }"
1165   [(set_attr "type" "branch")
1166   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1167   ; which is complex to track and inaccurate length specs.
1168    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1169                                                  (const_int 25000))
1170                                            (const_int 50000))
1171                                       (const_int 4)
1172                                       (const_int 8)))])
1173
1174 (define_insn "*rev_reg_branch_insn"
1175   [(set (pc)
1176         (if_then_else (match_operator 1 "eqne_comparison_operator"
1177                                       [(match_operand:SI 2 "register_operand" "r")
1178                                        (match_operand:SI 3 "register_operand" "r")])
1179                       (pc)
1180                       (label_ref (match_operand 0 "" ""))))]
1181   ""
1182   "*
1183 {
1184   /* Is branch target reachable with beq/bne?  */
1185   if (get_attr_length (insn) == 4)
1186     {
1187       if (GET_CODE (operands[1]) == NE)
1188         return \"beq %2,%3,%l0\";
1189       else
1190         return \"bne %2,%3,%l0\";
1191     }
1192   else
1193     {
1194       if (GET_CODE (operands[1]) == NE)
1195         return \"bne %2,%3,1f\;bra %l0\;1:\";
1196       else
1197         return \"beq %2,%3,1f\;bra %l0\;1:\";
1198     }
1199 }"
1200   [(set_attr "type" "branch")
1201   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1202   ; which is complex to track and inaccurate length specs.
1203    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1204                                                  (const_int 25000))
1205                                            (const_int 50000))
1206                                       (const_int 4)
1207                                       (const_int 8)))])
1208
1209 ; reg/zero compare and branch insns
1210
1211 (define_insn "*zero_branch_insn"
1212   [(set (pc)
1213         (if_then_else (match_operator 1 "signed_comparison_operator"
1214                                       [(match_operand:SI 2 "register_operand" "r")
1215                                        (const_int 0)])
1216                       (label_ref (match_operand 0 "" ""))
1217                       (pc)))]
1218   ""
1219   "*
1220 {
1221   char *br,*invbr;
1222   char asmtext[40];
1223
1224   switch (GET_CODE (operands[1]))
1225     {
1226       case EQ : br = \"eq\"; invbr = \"ne\"; break;
1227       case NE : br = \"ne\"; invbr = \"eq\"; break;
1228       case LE : br = \"le\"; invbr = \"gt\"; break;
1229       case GT : br = \"gt\"; invbr = \"le\"; break;
1230       case LT : br = \"lt\"; invbr = \"ge\"; break;
1231       case GE : br = \"ge\"; invbr = \"lt\"; break;
1232     }
1233
1234   /* Is branch target reachable with bxxz?  */
1235   if (get_attr_length (insn) == 4)
1236     {
1237       sprintf (asmtext, \"b%sz %%2,%%l0\", br);
1238       output_asm_insn (asmtext, operands);
1239     }
1240   else
1241     {
1242       sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", invbr);
1243       output_asm_insn (asmtext, operands);
1244     }
1245   return \"\";
1246 }"
1247   [(set_attr "type" "branch")
1248   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1249   ; which is complex to track and inaccurate length specs.
1250    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1251                                                  (const_int 25000))
1252                                            (const_int 50000))
1253                                       (const_int 4)
1254                                       (const_int 8)))])
1255
1256 (define_insn "*rev_zero_branch_insn"
1257   [(set (pc)
1258         (if_then_else (match_operator 1 "eqne_comparison_operator"
1259                                       [(match_operand:SI 2 "register_operand" "r")
1260                                        (const_int 0)])
1261                       (pc)
1262                       (label_ref (match_operand 0 "" ""))))]
1263   ""
1264   "*
1265 {
1266   char *br,*invbr;
1267   char asmtext[40];
1268
1269   switch (GET_CODE (operands[1]))
1270     {
1271       case EQ : br = \"eq\"; invbr = \"ne\"; break;
1272       case NE : br = \"ne\"; invbr = \"eq\"; break;
1273       case LE : br = \"le\"; invbr = \"gt\"; break;
1274       case GT : br = \"gt\"; invbr = \"le\"; break;
1275       case LT : br = \"lt\"; invbr = \"ge\"; break;
1276       case GE : br = \"ge\"; invbr = \"lt\"; break;
1277     }
1278
1279   /* Is branch target reachable with bxxz?  */
1280   if (get_attr_length (insn) == 4)
1281     {
1282       sprintf (asmtext, \"b%sz %%2,%%l0\", invbr);
1283       output_asm_insn (asmtext, operands);
1284     }
1285   else
1286     {
1287       sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", br);
1288       output_asm_insn (asmtext, operands);
1289     }
1290   return \"\";
1291 }"
1292   [(set_attr "type" "branch")
1293   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1294   ; which is complex to track and inaccurate length specs.
1295    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1296                                                  (const_int 25000))
1297                                            (const_int 50000))
1298                                       (const_int 4)
1299                                       (const_int 8)))])
1300 \f
1301 ;; Unconditional and other jump instructions.
1302
1303 (define_insn "jump"
1304   [(set (pc) (label_ref (match_operand 0 "" "")))]
1305   ""
1306   "bra %l0"
1307   [(set_attr "type" "uncond_branch")
1308    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1309                                                  (const_int 400))
1310                                            (const_int 800))
1311                                       (const_int 2)
1312                                       (const_int 4)))])
1313
1314 (define_insn "indirect_jump"
1315   [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
1316   ""
1317   "jmp %a0"
1318   [(set_attr "type" "uncond_branch")
1319    (set_attr "length" "2")])
1320  
1321 (define_insn "tablejump"
1322   [(set (pc) (match_operand:SI 0 "address_operand" "p"))
1323    (use (label_ref (match_operand 1 "" "")))]
1324   ""
1325   "jmp %a0"
1326   [(set_attr "type" "uncond_branch")
1327    (set_attr "length" "2")])
1328
1329 (define_expand "call"
1330   ;; operands[1] is stack_size_rtx
1331   ;; operands[2] is next_arg_register
1332   [(parallel [(call (match_operand:SI 0 "call_operand" "")
1333                     (match_operand 1 "" ""))
1334              (clobber (reg:SI 14))])]
1335   ""
1336   "")
1337
1338 (define_insn "*call_via_reg"
1339   [(call (mem:SI (match_operand:SI 0 "register_operand" "r"))
1340          (match_operand 1 "" ""))
1341    (clobber (reg:SI 14))]
1342   ""
1343   "jl %0"
1344   [(set_attr "type" "call")
1345    (set_attr "length" "2")])
1346
1347 (define_insn "*call_via_label"
1348   [(call (mem:SI (match_operand:SI 0 "call_address_operand" ""))
1349          (match_operand 1 "" ""))
1350    (clobber (reg:SI 14))]
1351   ""
1352   "*
1353 {
1354   int call26_p = call26_operand (operands[0], FUNCTION_MODE);
1355
1356   if (! call26_p)
1357     {
1358       /* We may not be able to reach with a `bl' insn so punt and leave it to
1359          the linker.
1360          We do this here, rather than doing a force_reg in the define_expand
1361          so these insns won't be separated, say by scheduling, thus simplifying
1362          the linker.  */
1363       return \"seth r14,%T0\;add3 r14,r14,%B0\;jl r14\";
1364     }
1365   else
1366     return \"bl %0\";
1367 }"
1368   [(set_attr "type" "call")
1369    (set (attr "length")
1370         (if_then_else (eq (symbol_ref "call26_operand (operands[0], FUNCTION_MODE)")
1371                           (const_int 0))
1372                       (const_int 12) ; 10 + 2 for nop filler
1373                       ; The return address must be on a 4 byte boundary so
1374                       ; there's no point in using a value of 2 here.  A 2 byte
1375                       ; insn may go in the left slot but we currently can't
1376                       ; use such knowledge.
1377                       (const_int 4)))])
1378
1379 (define_expand "call_value"
1380   ;; operand 2 is stack_size_rtx
1381   ;; operand 3 is next_arg_register
1382   [(parallel [(set (match_operand 0 "register_operand" "=r")
1383                    (call (match_operand:SI 1 "call_operand" "")
1384                          (match_operand 2 "" "")))
1385              (clobber (reg:SI 14))])]
1386   ""
1387   "")
1388
1389 (define_insn "*call_value_via_reg"
1390   [(set (match_operand 0 "register_operand" "=r")
1391         (call (mem:SI (match_operand:SI 1 "register_operand" "r"))
1392               (match_operand 2 "" "")))
1393    (clobber (reg:SI 14))]
1394   ""
1395   "jl %1"
1396   [(set_attr "type" "call")
1397    (set_attr "length" "2")])
1398
1399 (define_insn "*call_value_via_label"
1400   [(set (match_operand 0 "register_operand" "=r")
1401         (call (mem:SI (match_operand:SI 1 "call_address_operand" ""))
1402               (match_operand 2 "" "")))
1403    (clobber (reg:SI 14))]
1404   ""
1405   "*
1406 {
1407   int call26_p = call26_operand (operands[1], FUNCTION_MODE);
1408
1409   if (! call26_p)
1410     {
1411       /* We may not be able to reach with a `bl' insn so punt and leave it to
1412          the linker.
1413          We do this here, rather than doing a force_reg in the define_expand
1414          so these insns won't be separated, say by scheduling, thus simplifying
1415          the linker.  */
1416       return \"seth r14,%T1\;add3 r14,r14,%B1\;jl r14\";
1417     }
1418   else
1419     return \"bl %1\";
1420 }"
1421   [(set_attr "type" "call")
1422    (set (attr "length")
1423         (if_then_else (eq (symbol_ref "call26_operand (operands[1], FUNCTION_MODE)")
1424                           (const_int 0))
1425                       (const_int 12) ; 10 + 2 for nop filler
1426                       ; The return address must be on a 4 byte boundary so
1427                       ; there's no point in using a value of 2 here.  A 2 byte
1428                       ; insn may go in the left slot but we currently can't
1429                       ; use such knowledge.
1430                       (const_int 4)))])
1431 \f
1432 (define_insn "nop"
1433   [(const_int 0)]
1434   ""
1435   "nop"
1436   [(set_attr "type" "misc")
1437    (set_attr "length" "2")])
1438
1439 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
1440 ;; all of memory.  This blocks insns from being moved across this point.
1441
1442 (define_insn "blockage"
1443   [(unspec_volatile [(const_int 0)] 0)]
1444   ""
1445   "")
1446
1447 ;; Special pattern to flush the icache.
1448
1449 (define_insn "flush_icache"
1450   [(unspec_volatile [(match_operand 0 "memory_operand" "m")] 0)]
1451   ""
1452   "* return \"nop ; flush-icache\";"
1453   [(set_attr "type" "misc")])
1454 \f
1455 ;; Split up troublesome insns for better scheduling.
1456 \f
1457 ;; Peepholes go at the end.
1458
1459 ;; ??? Setting the type attribute may not be useful, but for completeness
1460 ;; we do it.
1461
1462 (define_peephole
1463   [(set (mem:SI (plus:SI (match_operand:SI 0 "register_operand" "r")
1464                          (const_int 4)))
1465         (match_operand:SI 1 "register_operand" "r"))]
1466   "dead_or_set_p (insn, operands[0])"
1467   "st %1,@+%0"
1468   [(set_attr "type" "store")
1469    (set_attr "length" "2")])