OSDN Git Service

Add prototype header file
[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, 1998, 1999 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 ;; 3 - setting carry in addx/subx instructions.
28 \f
29 ;; Insn type.  Used to default other attribute values.
30 (define_attr "type"
31   "int2,int4,load2,load4,load8,store2,store4,store8,shift2,shift4,mul2,div4,uncond_branch,branch,call,multi,misc"
32   (const_string "misc"))
33
34 ;; Length in bytes.
35 (define_attr "length" ""
36   (cond [(eq_attr "type" "int2,load2,store2,shift2,mul2")
37          (const_int 2)
38
39          (eq_attr "type" "int4,load4,store4,shift4,div4")
40          (const_int 4)
41
42          (eq_attr "type" "multi")
43          (const_int 8)
44
45          (eq_attr "type" "uncond_branch,branch,call")
46          (const_int 4)]
47
48          (const_int 4)))
49
50 ;; The length here is the length of a single asm.  Unfortunately it might be
51 ;; 2 or 4 so we must allow for 4.  That's ok though.
52 (define_asm_attributes
53   [(set_attr "length" "4")
54    (set_attr "type" "multi")])
55
56
57 ;; Whether an instruction is 16-bit or 32-bit
58 (define_attr "insn_size" "short,long"
59   (if_then_else (eq_attr "type" "int2,load2,store2,shift2,mul2")
60                 (const_string "short")
61                 (const_string "long")))
62
63 (define_attr "debug" "no,yes"
64   (const (symbol_ref "(TARGET_DEBUG != 0)")))
65
66 (define_attr "opt_size" "no,yes"
67   (const (symbol_ref "(optimize_size != 0)")))
68
69 (define_attr "m32r" "no,yes"
70   (const (symbol_ref "(TARGET_M32R != 0)")))
71
72 \f
73 ;; ::::::::::::::::::::
74 ;; ::
75 ;; :: Function Units
76 ;; ::
77 ;; ::::::::::::::::::::
78
79 ;; On most RISC machines, there are instructions whose results are not
80 ;; available for a specific number of cycles.  Common cases are instructions
81 ;; that load data from memory.  On many machines, a pipeline stall will result
82 ;; if the data is referenced too soon after the load instruction.
83
84 ;; In addition, many newer microprocessors have multiple function units,
85 ;; usually one for integer and one for floating point, and often will incur
86 ;; pipeline stalls when a result that is needed is not yet ready.
87
88 ;; The descriptions in this section allow the specification of how much time
89 ;; must elapse between the execution of an instruction and the time when its
90 ;; result is used.  It also allows specification of when the execution of an
91 ;; instruction will delay execution of similar instructions due to function
92 ;; unit conflicts.
93
94 ;; For the purposes of the specifications in this section, a machine is divided
95 ;; into "function units", each of which execute a specific class of
96 ;; instructions in first-in-first-out order.  Function units that accept one
97 ;; instruction each cycle and allow a result to be used in the succeeding
98 ;; instruction (usually via forwarding) need not be specified.  Classic RISC
99 ;; microprocessors will normally have a single function unit, which we can call
100 ;; `memory'.  The newer "superscalar" processors will often have function units
101 ;; for floating point operations, usually at least a floating point adder and
102 ;; multiplier.
103
104 ;; Each usage of a function units by a class of insns is specified with a
105 ;; `define_function_unit' expression, which looks like this:
106
107 ;; (define_function_unit NAME MULTIPLICITY SIMULTANEITY TEST READY-DELAY
108 ;;   ISSUE-DELAY [CONFLICT-LIST])
109
110 ;; NAME is a string giving the name of the function unit.
111
112 ;; MULTIPLICITY is an integer specifying the number of identical units in the
113 ;; processor.  If more than one unit is specified, they will be scheduled
114 ;; independently.  Only truly independent units should be counted; a pipelined
115 ;; unit should be specified as a single unit.  (The only common example of a
116 ;; machine that has multiple function units for a single instruction class that
117 ;; are truly independent and not pipelined are the two multiply and two
118 ;; increment units of the CDC 6600.)
119
120 ;; SIMULTANEITY specifies the maximum number of insns that can be executing in
121 ;; each instance of the function unit simultaneously or zero if the unit is
122 ;; pipelined and has no limit.
123
124 ;; All `define_function_unit' definitions referring to function unit NAME must
125 ;; have the same name and values for MULTIPLICITY and SIMULTANEITY.
126
127 ;; TEST is an attribute test that selects the insns we are describing in this
128 ;; definition.  Note that an insn may use more than one function unit and a
129 ;; function unit may be specified in more than one `define_function_unit'.
130
131 ;; READY-DELAY is an integer that specifies the number of cycles after which
132 ;; the result of the instruction can be used without introducing any stalls.
133
134 ;; ISSUE-DELAY is an integer that specifies the number of cycles after the
135 ;; instruction matching the TEST expression begins using this unit until a
136 ;; subsequent instruction can begin.  A cost of N indicates an N-1 cycle delay.
137 ;; A subsequent instruction may also be delayed if an earlier instruction has a
138 ;; longer READY-DELAY value.  This blocking effect is computed using the
139 ;; SIMULTANEITY, READY-DELAY, ISSUE-DELAY, and CONFLICT-LIST terms.  For a
140 ;; normal non-pipelined function unit, SIMULTANEITY is one, the unit is taken
141 ;; to block for the READY-DELAY cycles of the executing insn, and smaller
142 ;; values of ISSUE-DELAY are ignored.
143
144 ;; CONFLICT-LIST is an optional list giving detailed conflict costs for this
145 ;; unit.  If specified, it is a list of condition test expressions to be
146 ;; applied to insns chosen to execute in NAME following the particular insn
147 ;; matching TEST that is already executing in NAME.  For each insn in the list,
148 ;; ISSUE-DELAY specifies the conflict cost; for insns not in the list, the cost
149 ;; is zero.  If not specified, CONFLICT-LIST defaults to all instructions that
150 ;; use the function unit.
151
152 ;; Typical uses of this vector are where a floating point function unit can
153 ;; pipeline either single- or double-precision operations, but not both, or
154 ;; where a memory unit can pipeline loads, but not stores, etc.
155
156 ;; As an example, consider a classic RISC machine where the result of a load
157 ;; instruction is not available for two cycles (a single "delay" instruction is
158 ;; required) and where only one load instruction can be executed
159 ;; simultaneously.  This would be specified as:
160
161 ;; (define_function_unit "memory" 1 1 (eq_attr "type" "load") 2 0)
162
163 ;; For the case of a floating point function unit that can pipeline
164 ;; either single or double precision, but not both, the following could be
165 ;; specified:
166 ;;
167 ;; (define_function_unit "fp" 1 0
168 ;;   (eq_attr "type" "sp_fp") 4 4
169 ;;   [(eq_attr "type" "dp_fp")])
170 ;;
171 ;; (define_function_unit "fp" 1 0
172 ;;   (eq_attr "type" "dp_fp") 4 4
173 ;;   [(eq_attr "type" "sp_fp")])
174
175 ;; Note: The scheduler attempts to avoid function unit conflicts and uses all
176 ;; the specifications in the `define_function_unit' expression.  It has
177 ;; recently come to our attention that these specifications may not allow
178 ;; modeling of some of the newer "superscalar" processors that have insns using
179 ;; multiple pipelined units.  These insns will cause a potential conflict for
180 ;; the second unit used during their execution and there is no way of
181 ;; representing that conflict.  We welcome any examples of how function unit
182 ;; conflicts work in such processors and suggestions for their representation.
183
184 ;; Function units of the M32R
185 ;; Units that take one cycle do not need to be specified.
186
187 ;; (define_function_unit {name} {multiplicity} {simulataneity} {test}
188 ;;                       {ready-delay} {issue-delay} [{conflict-list}])
189
190 ;; Hack to get GCC to better pack the instructions.
191 ;; We pretend there is a separate long function unit that conflicts with
192 ;; both the left and right 16 bit insn slots.
193
194 (define_function_unit "short" 2 2
195   (and (eq_attr "m32r" "yes")
196        (and (eq_attr "insn_size" "short")
197             (eq_attr "type" "!load2")))
198   1 0
199   [(eq_attr "insn_size" "long")])
200
201 (define_function_unit "short" 2 2       ;; load delay of 1 clock for mem execution + 1 clock for WB
202   (and (eq_attr "m32r" "yes")
203        (eq_attr "type" "load2"))
204   3 0
205   [(eq_attr "insn_size" "long")])
206
207 (define_function_unit "long" 1 1
208   (and (eq_attr "m32r" "yes")
209        (and (eq_attr "insn_size" "long")
210             (eq_attr "type" "!load4,load8")))
211   1 0
212   [(eq_attr "insn_size" "short")])
213
214 (define_function_unit "long" 1 1        ;; load delay of 1 clock for mem execution + 1 clock for WB
215   (and (eq_attr "m32r" "yes")
216        (and (eq_attr "insn_size" "long")
217             (eq_attr "type" "load4,load8")))
218   3 0
219   [(eq_attr "insn_size" "short")])
220
221 \f
222 ;; Expand prologue as RTL
223 (define_expand "prologue"
224   [(const_int 1)]
225   ""
226   "
227 {
228   m32r_expand_prologue ();
229   DONE;
230 }")
231
232 \f
233 ;; Move instructions.
234 ;;
235 ;; For QI and HI moves, the register must contain the full properly
236 ;; sign-extended value.  nonzero_bits assumes this [otherwise
237 ;; SHORT_IMMEDIATES_SIGN_EXTEND must be used, but the comment for it
238 ;; says it's a kludge and the .md files should be fixed instead].
239
240 (define_expand "movqi"
241   [(set (match_operand:QI 0 "general_operand" "")
242         (match_operand:QI 1 "general_operand" ""))]
243   ""
244   "
245 {
246   /* Everything except mem = const or mem = mem can be done easily.
247      Objects in the small data area are handled too.  */
248
249   if (GET_CODE (operands[0]) == MEM)
250     operands[1] = force_reg (QImode, operands[1]);
251 }")
252
253 (define_insn "*movqi_insn"
254   [(set (match_operand:QI 0 "move_dest_operand" "=r,r,r,r,r,T,m")
255         (match_operand:QI 1 "move_src_operand" "r,I,JQR,T,m,r,r"))]
256   "register_operand (operands[0], QImode) || register_operand (operands[1], QImode)"
257   "@
258    mv %0,%1
259    ldi %0,%#%1
260    ldi %0,%#%1
261    ldub %0,%1
262    ldub %0,%1
263    stb %1,%0
264    stb %1,%0"
265   [(set_attr "type" "int2,int2,int4,load2,load4,store2,store4")
266    (set_attr "length" "2,2,4,2,4,2,4")])
267
268 (define_expand "movhi"
269   [(set (match_operand:HI 0 "general_operand" "")
270         (match_operand:HI 1 "general_operand" ""))]
271   ""
272   "
273 {
274   /* Everything except mem = const or mem = mem can be done easily.  */
275
276   if (GET_CODE (operands[0]) == MEM)
277     operands[1] = force_reg (HImode, operands[1]);
278 }")
279
280 (define_insn "*movhi_insn"
281   [(set (match_operand:HI 0 "move_dest_operand" "=r,r,r,r,r,r,T,m")
282         (match_operand:HI 1 "move_src_operand" "r,I,JQR,K,T,m,r,r"))]
283   "register_operand (operands[0], HImode) || register_operand (operands[1], HImode)"
284   "@
285    mv %0,%1
286    ldi %0,%#%1
287    ldi %0,%#%1
288    ld24 %0,%#%1
289    lduh %0,%1
290    lduh %0,%1
291    sth %1,%0
292    sth %1,%0"
293   [(set_attr "type" "int2,int2,int4,int4,load2,load4,store2,store4")
294    (set_attr "length" "2,2,4,4,2,4,2,4")])
295
296 (define_expand "movsi_push"
297   [(set (mem:SI (pre_dec:SI (match_operand:SI 0 "register_operand" "")))
298         (match_operand:SI 1 "register_operand" ""))]
299   ""
300   "")
301
302 (define_expand "movsi_pop"
303   [(set (match_operand:SI 0 "register_operand" "")
304         (mem:SI (post_inc:SI (match_operand:SI 1 "register_operand" ""))))]
305   ""
306   "")
307
308 (define_expand "movsi"
309   [(set (match_operand:SI 0 "general_operand" "")
310         (match_operand:SI 1 "general_operand" ""))]
311   ""
312   "
313 {
314   /* Everything except mem = const or mem = mem can be done easily.  */
315
316   if (GET_CODE (operands[0]) == MEM)
317     operands[1] = force_reg (SImode, operands[1]);
318
319   /* Small Data Area reference?  */
320   if (small_data_operand (operands[1], SImode))
321     {
322       emit_insn (gen_movsi_sda (operands[0], operands[1]));
323       DONE;
324     }
325
326   /* If medium or large code model, symbols have to be loaded with
327      seth/add3.  */
328   if (addr32_operand (operands[1], SImode))
329     {
330       emit_insn (gen_movsi_addr32 (operands[0], operands[1]));
331       DONE;
332     }
333 }")
334
335 ;; ??? Do we need a const_double constraint here for large unsigned values?
336 (define_insn "*movsi_insn"
337   [(set (match_operand:SI 0 "move_dest_operand" "=r,r,r,r,r,r,r,r,r,T,S,m")
338         (match_operand:SI 1 "move_src_operand" "r,I,J,MQ,L,n,T,U,m,r,r,r"))]
339   "register_operand (operands[0], SImode) || register_operand (operands[1], SImode)"
340   "*
341 {
342   if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == SUBREG)
343     {
344       switch (GET_CODE (operands[1]))
345         {
346           HOST_WIDE_INT value;
347
348           default:
349             break;
350
351           case REG:
352           case SUBREG:
353             return \"mv %0,%1\";
354
355           case MEM:
356             if (GET_CODE (XEXP (operands[1], 0)) == POST_INC
357                 && XEXP (XEXP (operands[1], 0), 0) == stack_pointer_rtx)
358               return \"pop %0\";
359
360             return \"ld %0,%1\";
361
362           case CONST_INT:
363             value = INTVAL (operands[1]);
364             if (INT16_P (value))
365               return \"ldi %0,%#%1\\t; %X1\";
366
367             if (UINT24_P (value))
368               return \"ld24 %0,%#%1\\t; %X1\";
369
370             if (UPPER16_P (value))
371               return \"seth %0,%#%T1\\t; %X1\";
372
373             return \"#\";
374
375           case CONST:
376           case SYMBOL_REF:
377           case LABEL_REF:
378             if (TARGET_ADDR24)
379               return \"ld24 %0,%#%1\";
380
381             return \"#\";
382         }
383     }
384
385   else if (GET_CODE (operands[0]) == MEM
386            && (GET_CODE (operands[1]) == REG || GET_CODE (operands[1]) == SUBREG))
387     {
388       if (GET_CODE (XEXP (operands[0], 0)) == PRE_DEC
389           && XEXP (XEXP (operands[0], 0), 0) == stack_pointer_rtx)
390         return \"push %1\";
391
392       return \"st %1,%0\";
393     }
394
395   abort ();
396 }"
397   [(set_attr "type" "int2,int2,int4,int4,int4,multi,load2,load2,load4,store2,store2,store4")
398    (set_attr "length" "2,2,4,4,4,8,2,2,4,2,2,4")])
399
400 ; Try to use a four byte / two byte pair for constants not loadable with
401 ; ldi, ld24, seth.
402
403 (define_split
404  [(set (match_operand:SI 0 "register_operand" "")
405        (match_operand:SI 1 "two_insn_const_operand" ""))]
406   ""
407   [(set (match_dup 0) (match_dup 2))
408    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 3)))]
409   "
410 {
411   unsigned HOST_WIDE_INT val = INTVAL (operands[1]);
412   unsigned HOST_WIDE_INT tmp;
413   int shift;
414
415   /* In all cases we will emit two instructions.  However we try to
416      use 2 byte instructions wherever possible.  We can assume the
417      constant isn't loadable with any of ldi, ld24, or seth.  */
418
419   /* See if we can load a 24 bit unsigned value and invert it.  */
420   if (UINT24_P (~ val))
421     {
422       emit_insn (gen_movsi (operands[0], GEN_INT (~ val)));
423       emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
424       DONE;
425     }
426
427   /* See if we can load a 24 bit unsigned value and shift it into place.
428      0x01fffffe is just beyond ld24's range.  */
429   for (shift = 1, tmp = 0x01fffffe;
430        shift < 8;
431        ++shift, tmp <<= 1)
432     {
433       if ((val & ~tmp) == 0)
434         {
435           emit_insn (gen_movsi (operands[0], GEN_INT (val >> shift)));
436           emit_insn (gen_ashlsi3 (operands[0], operands[0], GEN_INT (shift)));
437           DONE;
438         }
439     }
440
441   /* Can't use any two byte insn, fall back to seth/or3.  Use ~0xffff instead
442      of 0xffff0000, since the later fails on a 64-bit host.  */
443   operands[2] = GEN_INT ((val) & ~0xffff);
444   operands[3] = GEN_INT ((val) & 0xffff);
445 }")
446
447 (define_split
448   [(set (match_operand:SI 0 "register_operand" "")
449         (match_operand:SI 1 "seth_add3_operand" "i"))]
450   "TARGET_ADDR32"
451   [(set (match_dup 0)
452         (high:SI (match_dup 1)))
453    (set (match_dup 0)
454         (lo_sum:SI (match_dup 0)
455                    (match_dup 1)))]
456   "")
457
458 ;; Small data area support.
459 ;; The address of _SDA_BASE_ is loaded into a register and all objects in
460 ;; the small data area are indexed off that.  This is done for each reference
461 ;; but cse will clean things up for us.  We let the compiler choose the
462 ;; register to use so we needn't allocate (and maybe even fix) a special
463 ;; register to use.  Since the load and store insns have a 16 bit offset the
464 ;; total size of the data area can be 64K.  However, if the data area lives
465 ;; above 16M (24 bits), _SDA_BASE_ will have to be loaded with seth/add3 which
466 ;; would then yield 3 instructions to reference an object [though there would
467 ;; be no net loss if two or more objects were referenced].  The 3 insns can be
468 ;; reduced back to 2 if the size of the small data area were reduced to 32K
469 ;; [then seth + ld/st would work for any object in the area].  Doing this
470 ;; would require special handling of _SDA_BASE_ (its value would be
471 ;; (.sdata + 32K) & 0xffff0000) and reloc computations would be different
472 ;; [I think].  What to do about this is deferred until later and for now we
473 ;; require .sdata to be in the first 16M.
474
475 (define_expand "movsi_sda"
476   [(set (match_dup 2)
477         (unspec [(const_int 0)] 2))
478    (set (match_operand:SI 0 "register_operand" "")
479         (lo_sum:SI (match_dup 2)
480                    (match_operand:SI 1 "small_data_operand" "")))]
481   ""
482   "
483 {
484   if (reload_in_progress || reload_completed)
485     operands[2] = operands[0];
486   else
487     operands[2] = gen_reg_rtx (SImode);
488 }")
489
490 (define_insn "*load_sda_base"
491   [(set (match_operand:SI 0 "register_operand" "=r")
492         (unspec [(const_int 0)] 2))]
493   ""
494   "ld24 %0,#_SDA_BASE_"
495   [(set_attr "type" "int4")
496    (set_attr "length" "4")])
497
498 ;; 32 bit address support.
499
500 (define_expand "movsi_addr32"
501   [(set (match_dup 2)
502         ; addr32_operand isn't used because it's too restrictive,
503         ; seth_add3_operand is more general and thus safer.
504         (high:SI (match_operand:SI 1 "seth_add3_operand" "")))
505    (set (match_operand:SI 0 "register_operand" "")
506         (lo_sum:SI (match_dup 2) (match_dup 1)))]
507   ""
508   "
509 {
510   if (reload_in_progress || reload_completed)
511     operands[2] = operands[0];
512   else
513     operands[2] = gen_reg_rtx (SImode);
514 }")
515
516 (define_insn "set_hi_si"
517   [(set (match_operand:SI 0 "register_operand" "=r")
518         (high:SI (match_operand 1 "symbolic_operand" "")))]
519   ""
520   "seth %0,%#shigh(%1)"
521   [(set_attr "type" "int4")
522    (set_attr "length" "4")])
523
524 (define_insn "lo_sum_si"
525   [(set (match_operand:SI 0 "register_operand" "=r")
526         (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
527                    (match_operand:SI 2 "immediate_operand" "in")))]
528   ""
529   "add3 %0,%1,%#%B2"
530   [(set_attr "type" "int4")
531    (set_attr "length" "4")])
532
533 (define_expand "movdi"
534   [(set (match_operand:DI 0 "general_operand" "")
535         (match_operand:DI 1 "general_operand" ""))]
536   ""
537   "
538 {
539   /* Everything except mem = const or mem = mem can be done easily.  */
540
541   if (GET_CODE (operands[0]) == MEM)
542     operands[1] = force_reg (DImode, operands[1]);
543 }")
544
545 (define_insn "*movdi_insn"
546   [(set (match_operand:DI 0 "move_dest_operand" "=r,r,r,r,m")
547         (match_operand:DI 1 "move_double_src_operand" "r,nG,F,m,r"))]
548   "register_operand (operands[0], DImode) || register_operand (operands[1], DImode)"
549   "#"
550   [(set_attr "type" "multi,multi,multi,load8,store8")
551    (set_attr "length" "4,4,16,6,6")])
552
553 (define_split
554   [(set (match_operand:DI 0 "move_dest_operand" "")
555         (match_operand:DI 1 "move_double_src_operand" ""))]
556   "reload_completed"
557   [(match_dup 2)]
558   "operands[2] = gen_split_move_double (operands);")
559 \f
560 ;; Floating point move insns.
561
562 (define_expand "movsf"
563   [(set (match_operand:SF 0 "general_operand" "")
564         (match_operand:SF 1 "general_operand" ""))]
565   ""
566   "
567 {
568   /* Everything except mem = const or mem = mem can be done easily.  */
569
570   if (GET_CODE (operands[0]) == MEM)
571     operands[1] = force_reg (SFmode, operands[1]);
572 }")
573
574 (define_insn "*movsf_insn"
575   [(set (match_operand:SF 0 "move_dest_operand" "=r,r,r,r,r,T,S,m")
576         (match_operand:SF 1 "move_src_operand" "r,F,U,S,m,r,r,r"))]
577   "register_operand (operands[0], SFmode) || register_operand (operands[1], SFmode)"
578   "@
579    mv %0,%1
580    #
581    ld %0,%1
582    ld %0,%1
583    ld %0,%1
584    st %1,%0
585    st %1,%0
586    st %1,%0"
587   ;; ??? Length of alternative 1 is either 2, 4 or 8.
588   [(set_attr "type" "int2,multi,load2,load2,load4,store2,store2,store4")
589    (set_attr "length" "2,8,2,2,4,2,2,4")])
590
591 (define_split
592   [(set (match_operand:SF 0 "register_operand" "")
593         (match_operand:SF 1 "const_double_operand" ""))]
594   "reload_completed"
595   [(set (match_dup 2) (match_dup 3))]
596   "
597 {
598   operands[2] = operand_subword (operands[0], 0, 0, SFmode);
599   operands[3] = operand_subword (operands[1], 0, 0, SFmode);
600 }")
601
602 (define_expand "movdf"
603   [(set (match_operand:DF 0 "general_operand" "")
604         (match_operand:DF 1 "general_operand" ""))]
605   ""
606   "
607 {
608   /* Everything except mem = const or mem = mem can be done easily.  */
609
610   if (GET_CODE (operands[0]) == MEM)
611     operands[1] = force_reg (DFmode, operands[1]);
612 }")
613
614 (define_insn "*movdf_insn"
615   [(set (match_operand:DF 0 "move_dest_operand" "=r,r,r,m")
616         (match_operand:DF 1 "move_double_src_operand" "r,F,m,r"))]
617   "register_operand (operands[0], DFmode) || register_operand (operands[1], DFmode)"
618   "#"
619   [(set_attr "type" "multi,multi,load8,store8")
620    (set_attr "length" "4,16,6,6")])
621
622 (define_split
623   [(set (match_operand:DF 0 "move_dest_operand" "")
624         (match_operand:DF 1 "move_double_src_operand" ""))]
625   "reload_completed"
626   [(match_dup 2)]
627   "operands[2] = gen_split_move_double (operands);")
628 \f
629 ;; Zero extension instructions.
630
631 (define_insn "zero_extendqihi2"
632   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
633         (zero_extend:HI (match_operand:QI 1 "extend_operand" "r,T,m")))]
634   ""
635   "@
636    and3 %0,%1,%#255
637    ldub %0,%1
638    ldub %0,%1"
639   [(set_attr "type" "int4,load2,load4")
640    (set_attr "length" "4,2,4")])
641
642 (define_insn "zero_extendqisi2"
643   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
644         (zero_extend:SI (match_operand:QI 1 "extend_operand" "r,T,m")))]
645   ""
646   "@
647    and3 %0,%1,%#255
648    ldub %0,%1
649    ldub %0,%1"
650   [(set_attr "type" "int4,load2,load4")
651    (set_attr "length" "4,2,4")])
652
653 (define_insn "zero_extendhisi2"
654   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
655         (zero_extend:SI (match_operand:HI 1 "extend_operand" "r,T,m")))]
656   ""
657   "@
658    and3 %0,%1,%#65535
659    lduh %0,%1
660    lduh %0,%1"
661   [(set_attr "type" "int4,load2,load4")
662    (set_attr "length" "4,2,4")])
663 \f
664 ;; Signed conversions from a smaller integer to a larger integer
665 (define_insn "extendqihi2"
666   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
667         (sign_extend:HI (match_operand:QI 1 "extend_operand" "0,T,m")))]
668   ""
669   "@
670     #
671     ldb %0,%1
672     ldb %0,%1"
673   [(set_attr "type" "multi,load2,load4")
674    (set_attr "length" "2,2,4")])
675
676 (define_split
677   [(set (match_operand:HI 0 "register_operand" "")
678         (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
679   "reload_completed"
680   [(match_dup 2)
681    (match_dup 3)]
682   "
683 {
684   rtx op0   = gen_lowpart (SImode, operands[0]);
685   rtx shift = gen_rtx (CONST_INT, VOIDmode, 24);
686
687   operands[2] = gen_ashlsi3 (op0, op0, shift);
688   operands[3] = gen_ashrsi3 (op0, op0, shift);
689 }")
690
691 (define_insn "extendqisi2"
692   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
693         (sign_extend:SI (match_operand:QI 1 "extend_operand" "0,T,m")))]
694   ""
695   "@
696     #
697     ldb %0,%1
698     ldb %0,%1"
699   [(set_attr "type" "multi,load2,load4")
700    (set_attr "length" "4,2,4")])
701
702 (define_split
703   [(set (match_operand:SI 0 "register_operand" "")
704         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
705   "reload_completed"
706   [(match_dup 2)
707    (match_dup 3)]
708   "
709 {
710   rtx op0   = gen_lowpart (SImode, operands[0]);
711   rtx shift = gen_rtx (CONST_INT, VOIDmode, 24);
712
713   operands[2] = gen_ashlsi3 (op0, op0, shift);
714   operands[3] = gen_ashrsi3 (op0, op0, shift);
715 }")
716
717 (define_insn "extendhisi2"
718   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
719         (sign_extend:SI (match_operand:HI 1 "extend_operand" "0,T,m")))]
720   ""
721   "@
722     #
723     ldh %0,%1
724     ldh %0,%1"
725   [(set_attr "type" "multi,load2,load4")
726    (set_attr "length" "4,2,4")])
727
728 (define_split
729   [(set (match_operand:SI 0 "register_operand" "")
730         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
731   "reload_completed"
732   [(match_dup 2)
733    (match_dup 3)]
734   "
735 {
736   rtx op0   = gen_lowpart (SImode, operands[0]);
737   rtx shift = gen_rtx (CONST_INT, VOIDmode, 16);
738
739   operands[2] = gen_ashlsi3 (op0, op0, shift);
740   operands[3] = gen_ashrsi3 (op0, op0, shift);
741 }")
742 \f
743 ;; Arithmetic instructions.
744
745 ; ??? Adding an alternative to split add3 of small constants into two
746 ; insns yields better instruction packing but slower code.  Adds of small
747 ; values is done a lot.
748
749 (define_insn "addsi3"
750   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
751         (plus:SI (match_operand:SI 1 "register_operand" "%0,0,r")
752                  (match_operand:SI 2 "nonmemory_operand" "r,I,J")))]
753   ""
754   "@
755    add %0,%2
756    addi %0,%#%2
757    add3 %0,%1,%#%2"
758   [(set_attr "type" "int2,int2,int4")
759    (set_attr "length" "2,2,4")])
760
761 ;(define_split
762 ;  [(set (match_operand:SI 0 "register_operand" "")
763 ;       (plus:SI (match_operand:SI 1 "register_operand" "")
764 ;                (match_operand:SI 2 "int8_operand" "")))]
765 ;  "reload_completed
766 ;   && REGNO (operands[0]) != REGNO (operands[1])
767 ;   && INT8_P (INTVAL (operands[2]))
768 ;   && INTVAL (operands[2]) != 0"
769 ;  [(set (match_dup 0) (match_dup 1))
770 ;   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
771 ;  "")
772
773 (define_insn "adddi3"
774   [(set (match_operand:DI 0 "register_operand" "=r")
775         (plus:DI (match_operand:DI 1 "register_operand" "%0")
776                  (match_operand:DI 2 "register_operand" "r")))
777    (clobber (reg:SI 17))]
778   ""
779   "#"
780   [(set_attr "type" "multi")
781    (set_attr "length" "6")])
782
783 ;; ??? The cmp clears the condition bit.  Can we speed up somehow?
784 (define_split
785   [(set (match_operand:DI 0 "register_operand" "")
786         (plus:DI (match_operand:DI 1 "register_operand" "")
787                  (match_operand:DI 2 "register_operand" "")))
788    (clobber (match_operand 3 "" ""))]
789   "reload_completed"
790   [(parallel [(set (match_dup 3)
791                    (const_int 0))
792               (use (match_dup 4))])
793    (parallel [(set (match_dup 4)
794                    (plus:SI (match_dup 4)
795                             (plus:SI (match_dup 5)
796                                      (match_dup 3))))
797               (set (match_dup 3)
798                    (unspec [(const_int 0)] 3))])
799    (parallel [(set (match_dup 6)
800                    (plus:SI (match_dup 6)
801                             (plus:SI (match_dup 7)
802                                      (match_dup 3))))
803               (set (match_dup 3)
804                    (unspec [(const_int 0)] 3))])]
805   "
806 {
807   operands[4] = operand_subword (operands[0], (WORDS_BIG_ENDIAN != 0), 0, DImode);
808   operands[5] = operand_subword (operands[2], (WORDS_BIG_ENDIAN != 0), 0, DImode);
809   operands[6] = operand_subword (operands[0], (WORDS_BIG_ENDIAN == 0), 0, DImode);
810   operands[7] = operand_subword (operands[2], (WORDS_BIG_ENDIAN == 0), 0, DImode);
811 }")
812
813 (define_insn "*clear_c"
814   [(set (reg:SI 17)
815         (const_int 0))
816    (use (match_operand:SI 0 "register_operand" "r"))]
817   ""
818   "cmp %0,%0"
819   [(set_attr "type" "int2")
820    (set_attr "length" "2")])
821
822 (define_insn "*add_carry"
823   [(set (match_operand:SI 0 "register_operand" "=r")
824         (plus:SI (match_operand:SI 1 "register_operand" "%0")
825                  (plus:SI (match_operand:SI 2 "register_operand" "r")
826                           (reg:SI 17))))
827    (set (reg:SI 17)
828         (unspec [(const_int 0)] 3))]
829   ""
830   "addx %0,%2"
831   [(set_attr "type" "int2")
832    (set_attr "length" "2")])
833
834 (define_insn "subsi3"
835   [(set (match_operand:SI 0 "register_operand" "=r")
836         (minus:SI (match_operand:SI 1 "register_operand" "0")
837                   (match_operand:SI 2 "register_operand" "r")))]
838   ""
839   "sub %0,%2"
840   [(set_attr "type" "int2")
841    (set_attr "length" "2")])
842
843 (define_insn "subdi3"
844   [(set (match_operand:DI 0 "register_operand" "=r")
845         (minus:DI (match_operand:DI 1 "register_operand" "0")
846                   (match_operand:DI 2 "register_operand" "r")))
847    (clobber (reg:SI 17))]
848   ""
849   "#"
850   [(set_attr "type" "multi")
851    (set_attr "length" "6")])
852
853 ;; ??? The cmp clears the condition bit.  Can we speed up somehow?
854 (define_split
855   [(set (match_operand:DI 0 "register_operand" "")
856         (minus:DI (match_operand:DI 1 "register_operand" "")
857                   (match_operand:DI 2 "register_operand" "")))
858    (clobber (match_operand 3 "" ""))]
859   "reload_completed"
860   [(parallel [(set (match_dup 3)
861                    (const_int 0))
862               (use (match_dup 4))])
863    (parallel [(set (match_dup 4)
864                    (minus:SI (match_dup 4)
865                              (minus:SI (match_dup 5)
866                                        (match_dup 3))))
867               (set (match_dup 3)
868                    (unspec [(const_int 0)] 3))])
869    (parallel [(set (match_dup 6)
870                    (minus:SI (match_dup 6)
871                              (minus:SI (match_dup 7)
872                                        (match_dup 3))))
873               (set (match_dup 3)
874                    (unspec [(const_int 0)] 3))])]
875   "
876 {
877   operands[4] = operand_subword (operands[0], (WORDS_BIG_ENDIAN != 0), 0, DImode);
878   operands[5] = operand_subword (operands[2], (WORDS_BIG_ENDIAN != 0), 0, DImode);
879   operands[6] = operand_subword (operands[0], (WORDS_BIG_ENDIAN == 0), 0, DImode);
880   operands[7] = operand_subword (operands[2], (WORDS_BIG_ENDIAN == 0), 0, DImode);
881 }")
882
883 (define_insn "*sub_carry"
884   [(set (match_operand:SI 0 "register_operand" "=r")
885         (minus:SI (match_operand:SI 1 "register_operand" "%0")
886                   (minus:SI (match_operand:SI 2 "register_operand" "r")
887                             (reg:SI 17))))
888    (set (reg:SI 17)
889         (unspec [(const_int 0)] 3))]
890   ""
891   "subx %0,%2"
892   [(set_attr "type" "int2")
893    (set_attr "length" "2")])
894 \f
895 ; Multiply/Divide instructions.
896
897 (define_insn "mulhisi3"
898   [(set (match_operand:SI 0 "register_operand" "=r")
899         (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "r"))
900                  (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
901   ""
902   "mullo %1,%2\;mvfacmi %0"
903   [(set_attr "type" "multi")
904    (set_attr "length" "4")])
905
906 (define_insn "mulsi3"
907   [(set (match_operand:SI 0 "register_operand" "=r")
908         (mult:SI (match_operand:SI 1 "register_operand" "%0")
909                  (match_operand:SI 2 "register_operand" "r")))]
910   ""
911   "mul %0,%2"
912   [(set_attr "type" "mul2")
913    (set_attr "length" "2")])
914
915 (define_insn "divsi3"
916   [(set (match_operand:SI 0 "register_operand" "=r")
917         (div:SI (match_operand:SI 1 "register_operand" "0")
918                 (match_operand:SI 2 "register_operand" "r")))]
919   ""
920   "div %0,%2"
921   [(set_attr "type" "div4")
922    (set_attr "length" "4")])
923
924 (define_insn "udivsi3"
925   [(set (match_operand:SI 0 "register_operand" "=r")
926         (udiv:SI (match_operand:SI 1 "register_operand" "0")
927                  (match_operand:SI 2 "register_operand" "r")))]
928   ""
929   "divu %0,%2"
930   [(set_attr "type" "div4")
931    (set_attr "length" "4")])
932
933 (define_insn "modsi3"
934   [(set (match_operand:SI 0 "register_operand" "=r")
935         (mod:SI (match_operand:SI 1 "register_operand" "0")
936                 (match_operand:SI 2 "register_operand" "r")))]
937   ""
938   "rem %0,%2"
939   [(set_attr "type" "div4")
940    (set_attr "length" "4")])
941
942 (define_insn "umodsi3"
943   [(set (match_operand:SI 0 "register_operand" "=r")
944         (umod:SI (match_operand:SI 1 "register_operand" "0")
945                  (match_operand:SI 2 "register_operand" "r")))]
946   ""
947   "remu %0,%2"
948   [(set_attr "type" "div4")
949    (set_attr "length" "4")])
950 \f
951 ;; Boolean instructions.
952 ;;
953 ;; We don't define the DImode versions as expand_binop does a good enough job.
954 ;; And if it doesn't it should be fixed.
955
956 (define_insn "andsi3"
957   [(set (match_operand:SI 0 "register_operand" "=r,r")
958         (and:SI (match_operand:SI 1 "register_operand" "%0,r")
959                 (match_operand:SI 2 "reg_or_uint16_operand" "r,K")))]
960   ""
961   "*
962 {
963   /* If we are worried about space, see if we can break this up into two
964      short instructions, which might eliminate a NOP being inserted.  */
965   if (optimize_size
966       && m32r_not_same_reg (operands[0], operands[1])
967       && GET_CODE (operands[2]) == CONST_INT
968       && INT8_P (INTVAL (operands[2])))
969     return \"#\";
970
971   else if (GET_CODE (operands[2]) == CONST_INT)
972     return \"and3 %0,%1,%#%X2\";
973
974   return \"and %0,%2\";
975 }"
976   [(set_attr "type" "int2,int4")
977    (set_attr "length" "2,4")])
978
979 (define_split
980   [(set (match_operand:SI 0 "register_operand" "")
981         (and:SI (match_operand:SI 1 "register_operand" "")
982                 (match_operand:SI 2 "int8_operand" "")))]
983   "optimize_size && m32r_not_same_reg (operands[0], operands[1])"
984   [(set (match_dup 0) (match_dup 2))
985    (set (match_dup 0) (and:SI (match_dup 1) (match_dup 0)))]
986   "")
987
988 (define_insn "iorsi3"
989   [(set (match_operand:SI 0 "register_operand" "=r,r")
990         (ior:SI (match_operand:SI 1 "register_operand" "%0,r")
991                 (match_operand:SI 2 "reg_or_uint16_operand" "r,K")))]
992   ""
993   "*
994 {
995   /* If we are worried about space, see if we can break this up into two
996      short instructions, which might eliminate a NOP being inserted.  */
997   if (optimize_size
998       && m32r_not_same_reg (operands[0], operands[1])
999       && GET_CODE (operands[2]) == CONST_INT
1000       && INT8_P (INTVAL (operands[2])))
1001     return \"#\";
1002
1003   else if (GET_CODE (operands[2]) == CONST_INT)
1004     return \"or3 %0,%1,%#%X2\";
1005
1006   return \"or %0,%2\";
1007 }"
1008   [(set_attr "type" "int2,int4")
1009    (set_attr "length" "2,4")])
1010
1011 (define_split
1012   [(set (match_operand:SI 0 "register_operand" "")
1013         (ior:SI (match_operand:SI 1 "register_operand" "")
1014                 (match_operand:SI 2 "int8_operand" "")))]
1015   "optimize_size && m32r_not_same_reg (operands[0], operands[1])"
1016   [(set (match_dup 0) (match_dup 2))
1017    (set (match_dup 0) (ior:SI (match_dup 1) (match_dup 0)))]
1018   "")
1019
1020 (define_insn "xorsi3"
1021   [(set (match_operand:SI 0 "register_operand" "=r,r")
1022         (xor:SI (match_operand:SI 1 "register_operand" "%0,r")
1023                 (match_operand:SI 2 "reg_or_uint16_operand" "r,K")))]
1024   ""
1025   "*
1026 {
1027   /* If we are worried about space, see if we can break this up into two
1028      short instructions, which might eliminate a NOP being inserted.  */
1029   if (optimize_size
1030       && m32r_not_same_reg (operands[0], operands[1])
1031       && GET_CODE (operands[2]) == CONST_INT
1032       && INT8_P (INTVAL (operands[2])))
1033     return \"#\";
1034
1035   else if (GET_CODE (operands[2]) == CONST_INT)
1036     return \"xor3 %0,%1,%#%X2\";
1037
1038   return \"xor %0,%2\";
1039 }"
1040   [(set_attr "type" "int2,int4")
1041    (set_attr "length" "2,4")])
1042
1043 (define_split
1044   [(set (match_operand:SI 0 "register_operand" "")
1045         (xor:SI (match_operand:SI 1 "register_operand" "")
1046                 (match_operand:SI 2 "int8_operand" "")))]
1047   "optimize_size && m32r_not_same_reg (operands[0], operands[1])"
1048   [(set (match_dup 0) (match_dup 2))
1049    (set (match_dup 0) (xor:SI (match_dup 1) (match_dup 0)))]
1050   "")
1051
1052 (define_insn "negsi2"
1053   [(set (match_operand:SI 0 "register_operand" "=r")
1054         (neg:SI (match_operand:SI 1 "register_operand" "r")))]
1055   ""
1056   "neg %0,%1"
1057   [(set_attr "type" "int2")
1058    (set_attr "length" "2")])
1059
1060 (define_insn "one_cmplsi2"
1061   [(set (match_operand:SI 0 "register_operand" "=r")
1062         (not:SI (match_operand:SI 1 "register_operand" "r")))]
1063   ""
1064   "not %0,%1"
1065   [(set_attr "type" "int2")
1066    (set_attr "length" "2")])
1067 \f
1068 ;; Shift instructions.
1069
1070 (define_insn "ashlsi3"
1071   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1072         (ashift:SI (match_operand:SI 1 "register_operand" "0,0,r")
1073                    (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1074   ""
1075   "@
1076    sll %0,%2
1077    slli %0,%#%2
1078    sll3 %0,%1,%#%2"
1079   [(set_attr "type" "shift2,shift2,shift4")
1080    (set_attr "length" "2,2,4")])
1081
1082 (define_insn "ashrsi3"
1083   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1084         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
1085                      (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1086   ""
1087   "@
1088    sra %0,%2
1089    srai %0,%#%2
1090    sra3 %0,%1,%#%2"
1091   [(set_attr "type" "shift2,shift2,shift4")
1092    (set_attr "length" "2,2,4")])
1093
1094 (define_insn "lshrsi3"
1095   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1096         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
1097                      (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1098   ""
1099   "@
1100    srl %0,%2
1101    srli %0,%#%2
1102    srl3 %0,%1,%#%2"
1103   [(set_attr "type" "shift2,shift2,shift4")
1104    (set_attr "length" "2,2,4")])
1105 \f
1106 ;; Compare instructions.
1107 ;; This controls RTL generation and register allocation.
1108
1109 ;; We generate RTL for comparisons and branches by having the cmpxx 
1110 ;; patterns store away the operands.  Then the bcc patterns
1111 ;; emit RTL for both the compare and the branch.
1112 ;;
1113 ;; On the m32r it is more efficient to use the bxxz instructions and
1114 ;; thus merge the compare and branch into one instruction, so they are
1115 ;; preferred.
1116
1117 (define_expand "cmpsi"
1118   [(set (reg:SI 17)
1119         (compare:CC (match_operand:SI 0 "register_operand" "")
1120                     (match_operand:SI 1 "reg_or_cmp_int16_operand" "")))]
1121   ""
1122   "
1123 {
1124   m32r_compare_op0 = operands[0];
1125   m32r_compare_op1 = operands[1];
1126   DONE;
1127 }")
1128
1129 ;; The cmp_xxx_insn patterns set the condition bit to the result of the
1130 ;; comparison.  There isn't a "compare equal" instruction so cmp_eqsi_insn
1131 ;; is quite inefficient.  However, it is rarely used.
1132
1133 (define_insn "cmp_eqsi_insn"
1134   [(set (reg:SI 17)
1135         (eq:SI (match_operand:SI 0 "register_operand" "r,r")
1136                (match_operand:SI 1 "reg_or_cmp_int16_operand" "r,P")))
1137    (clobber (match_scratch:SI 2 "=&r,&r"))]
1138   ""
1139   "*
1140 {
1141   if (which_alternative == 0)
1142     {
1143          return \"mv %2,%0\;sub %2,%1\;cmpui %2,#1\";
1144     }
1145   else
1146     {
1147         if (INTVAL (operands [1]) == 0)
1148           return \"cmpui %0, #1\";
1149         else if (REGNO (operands [2]) == REGNO (operands [0]))
1150           return \"addi %0,%#%N1\;cmpui %2,#1\";
1151         else
1152           return \"add3 %2,%0,%#%N1\;cmpui %2,#1\";
1153     }
1154 }"
1155   [(set_attr "type" "multi,multi")
1156    (set_attr "length" "8,8")])
1157
1158 (define_insn "cmp_ltsi_insn"
1159   [(set (reg:SI 17)
1160         (lt:SI (match_operand:SI 0 "register_operand" "r,r")
1161                (match_operand:SI 1 "reg_or_int16_operand" "r,J")))]
1162   ""
1163   "@
1164    cmp %0,%1
1165    cmpi %0,%#%1"
1166   [(set_attr "type" "int2,int4")
1167    (set_attr "length" "2,4")])
1168
1169 (define_insn "cmp_ltusi_insn"
1170   [(set (reg:SI 17)
1171         (ltu:SI (match_operand:SI 0 "register_operand" "r,r")
1172                 (match_operand:SI 1 "reg_or_int16_operand" "r,J")))]
1173   ""
1174   "@
1175    cmpu %0,%1
1176    cmpui %0,%#%1"
1177   [(set_attr "type" "int2,int4")
1178    (set_attr "length" "2,4")])
1179
1180 ;; reg == small constant comparisons are best handled by putting the result
1181 ;; of the comparison in a tmp reg and then using beqz/bnez.
1182 ;; ??? The result register doesn't contain 0/STORE_FLAG_VALUE,
1183 ;; it contains 0/non-zero.
1184
1185 (define_insn "cmp_ne_small_const_insn"
1186   [(set (match_operand:SI 0 "register_operand" "=r,r")
1187         (ne:SI (match_operand:SI 1 "register_operand" "0,r")
1188                (match_operand:SI 2 "cmp_int16_operand" "N,P")))]
1189   ""
1190   "@
1191    addi %0,%#%N2
1192    add3 %0,%1,%#%N2"
1193   [(set_attr "type" "int2,int4")
1194    (set_attr "length" "2,4")])
1195 \f
1196 ;; These control RTL generation for conditional jump insns.
1197
1198 (define_expand "beq"
1199   [(set (pc)
1200         (if_then_else (match_dup 1)
1201                       (label_ref (match_operand 0 "" ""))
1202                       (pc)))]
1203   ""
1204   "
1205 {
1206   operands[1] = gen_compare (EQ, m32r_compare_op0, m32r_compare_op1, FALSE);
1207 }")
1208
1209 (define_expand "bne"
1210   [(set (pc)
1211         (if_then_else (match_dup 1)
1212                       (label_ref (match_operand 0 "" ""))
1213                       (pc)))]
1214   ""
1215   "
1216 {
1217   operands[1] = gen_compare (NE, m32r_compare_op0, m32r_compare_op1, FALSE);
1218 }")
1219
1220 (define_expand "bgt"
1221   [(set (pc)
1222         (if_then_else (match_dup 1)
1223                       (label_ref (match_operand 0 "" ""))
1224                       (pc)))]
1225   ""
1226   "
1227 {
1228   operands[1] = gen_compare (GT, m32r_compare_op0, m32r_compare_op1, FALSE);
1229 }")
1230
1231 (define_expand "ble"
1232   [(set (pc)
1233         (if_then_else (match_dup 1)
1234                       (label_ref (match_operand 0 "" ""))
1235                       (pc)))]
1236   ""
1237   "
1238 {
1239   operands[1] = gen_compare (LE, m32r_compare_op0, m32r_compare_op1, FALSE);
1240 }")
1241
1242 (define_expand "bge"
1243   [(set (pc)
1244         (if_then_else (match_dup 1)
1245                       (label_ref (match_operand 0 "" ""))
1246                       (pc)))]
1247   ""
1248   "
1249 {
1250   operands[1] = gen_compare (GE, m32r_compare_op0, m32r_compare_op1, FALSE);
1251 }")
1252
1253 (define_expand "blt"
1254   [(set (pc)
1255         (if_then_else (match_dup 1)
1256                       (label_ref (match_operand 0 "" ""))
1257                       (pc)))]
1258   ""
1259   "
1260 {
1261   operands[1] = gen_compare (LT, m32r_compare_op0, m32r_compare_op1, FALSE);
1262 }")
1263
1264 (define_expand "bgtu"
1265   [(set (pc)
1266         (if_then_else (match_dup 1)
1267                       (label_ref (match_operand 0 "" ""))
1268                       (pc)))]
1269   ""
1270   "
1271 {
1272   operands[1] = gen_compare (GTU, m32r_compare_op0, m32r_compare_op1, FALSE);
1273 }")
1274
1275 (define_expand "bleu"
1276   [(set (pc)
1277         (if_then_else (match_dup 1)
1278                       (label_ref (match_operand 0 "" ""))
1279                       (pc)))]
1280   ""
1281   "
1282 {
1283   operands[1] = gen_compare (LEU, m32r_compare_op0, m32r_compare_op1, FALSE);
1284 }")
1285
1286 (define_expand "bgeu"
1287   [(set (pc)
1288         (if_then_else (match_dup 1)
1289                       (label_ref (match_operand 0 "" ""))
1290                       (pc)))]
1291   ""
1292   "
1293 {
1294   operands[1] = gen_compare (GEU, m32r_compare_op0, m32r_compare_op1, FALSE);
1295 }")
1296
1297 (define_expand "bltu"
1298   [(set (pc)
1299         (if_then_else (match_dup 1)
1300                       (label_ref (match_operand 0 "" ""))
1301                       (pc)))]
1302   ""
1303   "
1304 {
1305   operands[1] = gen_compare (LTU, m32r_compare_op0, m32r_compare_op1, FALSE);
1306 }")
1307
1308 ;; Now match both normal and inverted jump.
1309
1310 (define_insn "*branch_insn"
1311   [(set (pc)
1312         (if_then_else (match_operator 1 "eqne_comparison_operator"
1313                                       [(reg 17) (const_int 0)])
1314                       (label_ref (match_operand 0 "" ""))
1315                       (pc)))]
1316   ""
1317   "*
1318 {
1319   static char instruction[40];
1320   sprintf (instruction, \"%s%s %%l0\",
1321            (GET_CODE (operands[1]) == NE) ? \"bc\" : \"bnc\",
1322            (get_attr_length (insn) == 2) ? \".s\" : \"\");
1323   return instruction;
1324 }"
1325   [(set_attr "type" "branch")
1326    ; We use 400/800 instead of 512,1024 to account for inaccurate insn
1327    ; lengths and insn alignments that are complex to track.
1328    ; It's not important that we be hyper-precise here.  It may be more
1329    ; important blah blah blah when the chip supports parallel execution
1330    ; blah blah blah but until then blah blah blah this is simple and
1331    ; suffices.
1332    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1333                                                  (const_int 400))
1334                                            (const_int 800))
1335                                       (const_int 2)
1336                                       (const_int 4)))])
1337
1338 (define_insn "*rev_branch_insn"
1339   [(set (pc)
1340         (if_then_else (match_operator 1 "eqne_comparison_operator"
1341                                       [(reg 17) (const_int 0)])
1342                       (pc)
1343                       (label_ref (match_operand 0 "" ""))))]
1344   ;"REVERSIBLE_CC_MODE (GET_MODE (XEXP (operands[1], 0)))"
1345   ""
1346   "*
1347 {
1348   static char instruction[40];
1349   sprintf (instruction, \"%s%s %%l0\",
1350            (GET_CODE (operands[1]) == EQ) ? \"bc\" : \"bnc\",
1351            (get_attr_length (insn) == 2) ? \".s\" : \"\");
1352   return instruction;
1353 }"
1354   [(set_attr "type" "branch")
1355    ; We use 400/800 instead of 512,1024 to account for inaccurate insn
1356    ; lengths and insn alignments that are complex to track.
1357    ; It's not important that we be hyper-precise here.  It may be more
1358    ; important blah blah blah when the chip supports parallel execution
1359    ; blah blah blah but until then blah blah blah this is simple and
1360    ; suffices.
1361    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1362                                                  (const_int 400))
1363                                            (const_int 800))
1364                                       (const_int 2)
1365                                       (const_int 4)))])
1366
1367 ; reg/reg compare and branch insns
1368
1369 (define_insn "*reg_branch_insn"
1370   [(set (pc)
1371         (if_then_else (match_operator 1 "eqne_comparison_operator"
1372                                       [(match_operand:SI 2 "register_operand" "r")
1373                                        (match_operand:SI 3 "register_operand" "r")])
1374                       (label_ref (match_operand 0 "" ""))
1375                       (pc)))]
1376   ""
1377   "*
1378 {
1379   /* Is branch target reachable with beq/bne?  */
1380   if (get_attr_length (insn) == 4)
1381     {
1382       if (GET_CODE (operands[1]) == EQ)
1383         return \"beq %2,%3,%l0\";
1384       else
1385         return \"bne %2,%3,%l0\";
1386     }
1387   else
1388     {
1389       if (GET_CODE (operands[1]) == EQ)
1390         return \"bne %2,%3,1f\;bra %l0\;1:\";
1391       else
1392         return \"beq %2,%3,1f\;bra %l0\;1:\";
1393     }
1394 }"
1395   [(set_attr "type" "branch")
1396   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1397   ; which is complex to track and inaccurate length specs.
1398    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1399                                                  (const_int 25000))
1400                                            (const_int 50000))
1401                                       (const_int 4)
1402                                       (const_int 8)))])
1403
1404 (define_insn "*rev_reg_branch_insn"
1405   [(set (pc)
1406         (if_then_else (match_operator 1 "eqne_comparison_operator"
1407                                       [(match_operand:SI 2 "register_operand" "r")
1408                                        (match_operand:SI 3 "register_operand" "r")])
1409                       (pc)
1410                       (label_ref (match_operand 0 "" ""))))]
1411   ""
1412   "*
1413 {
1414   /* Is branch target reachable with beq/bne?  */
1415   if (get_attr_length (insn) == 4)
1416     {
1417       if (GET_CODE (operands[1]) == NE)
1418         return \"beq %2,%3,%l0\";
1419       else
1420         return \"bne %2,%3,%l0\";
1421     }
1422   else
1423     {
1424       if (GET_CODE (operands[1]) == NE)
1425         return \"bne %2,%3,1f\;bra %l0\;1:\";
1426       else
1427         return \"beq %2,%3,1f\;bra %l0\;1:\";
1428     }
1429 }"
1430   [(set_attr "type" "branch")
1431   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1432   ; which is complex to track and inaccurate length specs.
1433    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1434                                                  (const_int 25000))
1435                                            (const_int 50000))
1436                                       (const_int 4)
1437                                       (const_int 8)))])
1438
1439 ; reg/zero compare and branch insns
1440
1441 (define_insn "*zero_branch_insn"
1442   [(set (pc)
1443         (if_then_else (match_operator 1 "signed_comparison_operator"
1444                                       [(match_operand:SI 2 "register_operand" "r")
1445                                        (const_int 0)])
1446                       (label_ref (match_operand 0 "" ""))
1447                       (pc)))]
1448   ""
1449   "*
1450 {
1451   char *br,*invbr;
1452   char asmtext[40];
1453
1454   switch (GET_CODE (operands[1]))
1455     {
1456       case EQ : br = \"eq\"; invbr = \"ne\"; break;
1457       case NE : br = \"ne\"; invbr = \"eq\"; break;
1458       case LE : br = \"le\"; invbr = \"gt\"; break;
1459       case GT : br = \"gt\"; invbr = \"le\"; break;
1460       case LT : br = \"lt\"; invbr = \"ge\"; break;
1461       case GE : br = \"ge\"; invbr = \"lt\"; break;
1462
1463       default: abort();
1464     }
1465
1466   /* Is branch target reachable with bxxz?  */
1467   if (get_attr_length (insn) == 4)
1468     {
1469       sprintf (asmtext, \"b%sz %%2,%%l0\", br);
1470       output_asm_insn (asmtext, operands);
1471     }
1472   else
1473     {
1474       sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", invbr);
1475       output_asm_insn (asmtext, operands);
1476     }
1477   return \"\";
1478 }"
1479   [(set_attr "type" "branch")
1480   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1481   ; which is complex to track and inaccurate length specs.
1482    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1483                                                  (const_int 25000))
1484                                            (const_int 50000))
1485                                       (const_int 4)
1486                                       (const_int 8)))])
1487
1488 (define_insn "*rev_zero_branch_insn"
1489   [(set (pc)
1490         (if_then_else (match_operator 1 "eqne_comparison_operator"
1491                                       [(match_operand:SI 2 "register_operand" "r")
1492                                        (const_int 0)])
1493                       (pc)
1494                       (label_ref (match_operand 0 "" ""))))]
1495   ""
1496   "*
1497 {
1498   char *br,*invbr;
1499   char asmtext[40];
1500
1501   switch (GET_CODE (operands[1]))
1502     {
1503       case EQ : br = \"eq\"; invbr = \"ne\"; break;
1504       case NE : br = \"ne\"; invbr = \"eq\"; break;
1505       case LE : br = \"le\"; invbr = \"gt\"; break;
1506       case GT : br = \"gt\"; invbr = \"le\"; break;
1507       case LT : br = \"lt\"; invbr = \"ge\"; break;
1508       case GE : br = \"ge\"; invbr = \"lt\"; break;
1509
1510       default: abort();
1511     }
1512
1513   /* Is branch target reachable with bxxz?  */
1514   if (get_attr_length (insn) == 4)
1515     {
1516       sprintf (asmtext, \"b%sz %%2,%%l0\", invbr);
1517       output_asm_insn (asmtext, operands);
1518     }
1519   else
1520     {
1521       sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", br);
1522       output_asm_insn (asmtext, operands);
1523     }
1524   return \"\";
1525 }"
1526   [(set_attr "type" "branch")
1527   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1528   ; which is complex to track and inaccurate length specs.
1529    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1530                                                  (const_int 25000))
1531                                            (const_int 50000))
1532                                       (const_int 4)
1533                                       (const_int 8)))])
1534 \f
1535 ;; S<cc> operations to set a register to 1/0 based on a comparison
1536
1537 (define_expand "seq"
1538   [(match_operand:SI 0 "register_operand" "")]
1539   ""
1540   "
1541 {
1542   rtx op0 = operands[0];
1543   rtx op1 = m32r_compare_op0;
1544   rtx op2 = m32r_compare_op1;
1545   enum machine_mode mode = GET_MODE (op0);
1546
1547   if (mode != SImode)
1548     FAIL;
1549
1550   if (! register_operand (op1, mode))
1551     op1 = force_reg (mode, op1);
1552
1553   if (GET_CODE (op2) == CONST_INT && INTVAL (op2) == 0)
1554     {
1555       emit_insn (gen_seq_zero_insn (op0, op1));
1556       DONE;
1557     }
1558
1559   if (! reg_or_eq_int16_operand (op2, mode))
1560     op2 = force_reg (mode, op2);
1561
1562   emit_insn (gen_seq_insn (op0, op1, op2));
1563   DONE;
1564 }")
1565
1566 (define_insn "seq_zero_insn"
1567   [(set (match_operand:SI 0 "register_operand" "=r")
1568         (eq:SI (match_operand:SI 1 "register_operand" "r")
1569                (const_int 0)))
1570    (clobber (reg:SI 17))]
1571   "TARGET_M32R"
1572   "#"
1573   [(set_attr "type" "multi")
1574    (set_attr "length" "6")])
1575
1576 (define_split
1577   [(set (match_operand:SI 0 "register_operand" "")
1578         (eq:SI (match_operand:SI 1 "register_operand" "")
1579                (const_int 0)))
1580    (clobber (reg:SI 17))]
1581   "TARGET_M32R"
1582   [(match_dup 3)]
1583   "
1584 {
1585   rtx op0 = operands[0];
1586   rtx op1 = operands[1];
1587
1588   start_sequence ();
1589   emit_insn (gen_cmp_ltusi_insn (op1, GEN_INT (1)));
1590   emit_insn (gen_movcc_insn (op0));
1591   operands[3] = gen_sequence ();
1592   end_sequence ();
1593 }")
1594
1595 (define_insn "seq_insn"
1596   [(set (match_operand:SI 0 "register_operand" "=r,r,??r,r")
1597         (eq:SI (match_operand:SI 1 "register_operand" "r,r,r,r")
1598                (match_operand:SI 2 "reg_or_eq_int16_operand" "r,r,r,PK")))
1599    (clobber (reg:SI 17))
1600    (clobber (match_scratch:SI 3 "=1,2,&r,r"))]
1601   "TARGET_M32R"
1602   "#"
1603   [(set_attr "type" "multi")
1604    (set_attr "length" "8,8,10,10")])
1605
1606 (define_split
1607   [(set (match_operand:SI 0 "register_operand" "")
1608         (eq:SI (match_operand:SI 1 "register_operand" "")
1609                (match_operand:SI 2 "reg_or_eq_int16_operand" "")))
1610    (clobber (reg:SI 17))
1611    (clobber (match_scratch:SI 3 ""))]
1612   "TARGET_M32R && reload_completed"
1613   [(match_dup 4)]
1614   "
1615 {
1616   rtx op0 = operands[0];
1617   rtx op1 = operands[1];
1618   rtx op2 = operands[2];
1619   rtx op3 = operands[3];
1620   HOST_WIDE_INT value;
1621
1622   if (GET_CODE (op2) == REG && GET_CODE (op3) == REG
1623       && REGNO (op2) == REGNO (op3))
1624     {
1625       op1 = operands[2];
1626       op2 = operands[1];
1627     }
1628
1629   start_sequence ();
1630   if (GET_CODE (op1) == REG && GET_CODE (op3) == REG
1631       && REGNO (op1) != REGNO (op3))
1632     {
1633       emit_move_insn (op3, op1);
1634       op1 = op3;
1635     }
1636
1637   if (GET_CODE (op2) == CONST_INT && (value = INTVAL (op2)) != 0
1638       && CMP_INT16_P (value))
1639     emit_insn (gen_addsi3 (op3, op1, GEN_INT (-value)));
1640   else
1641     emit_insn (gen_xorsi3 (op3, op1, op2));
1642
1643   emit_insn (gen_cmp_ltusi_insn (op3, GEN_INT (1)));
1644   emit_insn (gen_movcc_insn (op0));
1645   operands[4] = gen_sequence ();
1646   end_sequence ();
1647 }")
1648
1649 (define_expand "sne"
1650   [(match_operand:SI 0 "register_operand" "")]
1651   ""
1652   "
1653 {
1654   rtx op0 = operands[0];
1655   rtx op1 = m32r_compare_op0;
1656   rtx op2 = m32r_compare_op1;
1657   enum machine_mode mode = GET_MODE (op0);
1658
1659   if (mode != SImode)
1660     FAIL;
1661
1662   if (GET_CODE (op2) != CONST_INT
1663       || (INTVAL (op2) != 0 && UINT16_P (INTVAL (op2))))
1664     {
1665       rtx reg;
1666
1667       if (reload_completed || reload_in_progress)
1668         FAIL;
1669
1670       reg = gen_reg_rtx (SImode);
1671       emit_insn (gen_xorsi3 (reg, op1, op2));
1672       op1 = reg;
1673
1674       if (! register_operand (op1, mode))
1675         op1 = force_reg (mode, op1);
1676
1677       emit_insn (gen_sne_zero_insn (op0, op1));
1678       DONE;
1679     }
1680   else
1681     FAIL;
1682 }")
1683
1684 (define_insn "sne_zero_insn"
1685   [(set (match_operand:SI 0 "register_operand" "=r")
1686         (ne:SI (match_operand:SI 1 "register_operand" "r")
1687                (const_int 0)))
1688    (clobber (reg:SI 17))
1689    (clobber (match_scratch:SI 2 "=&r"))]
1690   ""
1691   "#"
1692   [(set_attr "type" "multi")
1693    (set_attr "length" "6")])
1694
1695 (define_split
1696   [(set (match_operand:SI 0 "register_operand" "")
1697         (ne:SI (match_operand:SI 1 "register_operand" "")
1698                (const_int 0)))
1699    (clobber (reg:SI 17))
1700    (clobber (match_scratch:SI 2 ""))]
1701   "reload_completed"
1702   [(set (match_dup 2)
1703         (const_int 0))
1704    (set (reg:SI 17)
1705         (ltu:SI (match_dup 2)
1706                 (match_dup 1)))
1707    (set (match_dup 0)
1708         (reg:SI 17))]
1709   "")
1710         
1711 (define_expand "slt"
1712   [(match_operand:SI 0 "register_operand" "")]
1713   ""
1714   "
1715 {
1716   rtx op0 = operands[0];
1717   rtx op1 = m32r_compare_op0;
1718   rtx op2 = m32r_compare_op1;
1719   enum machine_mode mode = GET_MODE (op0);
1720
1721   if (mode != SImode)
1722     FAIL;
1723
1724   if (! register_operand (op1, mode))
1725     op1 = force_reg (mode, op1);
1726
1727   if (! reg_or_int16_operand (op2, mode))
1728     op2 = force_reg (mode, op2);
1729
1730   emit_insn (gen_slt_insn (op0, op1, op2));
1731   DONE;
1732 }")
1733
1734 (define_insn "slt_insn"
1735   [(set (match_operand:SI 0 "register_operand" "=r,r")
1736         (lt:SI (match_operand:SI 1 "register_operand" "r,r")
1737                (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
1738    (clobber (reg:SI 17))]
1739   ""
1740   "#"
1741   [(set_attr "type" "multi")
1742    (set_attr "length" "4,6")])
1743
1744 (define_split
1745   [(set (match_operand:SI 0 "register_operand" "")
1746         (lt:SI (match_operand:SI 1 "register_operand" "")
1747                (match_operand:SI 2 "reg_or_int16_operand" "")))
1748    (clobber (reg:SI 17))]
1749   ""
1750   [(set (reg:SI 17)
1751         (lt:SI (match_dup 1)
1752                (match_dup 2)))
1753    (set (match_dup 0)
1754         (reg:SI 17))]
1755   "")
1756
1757 (define_expand "sle"
1758   [(match_operand:SI 0 "register_operand" "")]
1759   ""
1760   "
1761 {
1762   rtx op0 = operands[0];
1763   rtx op1 = m32r_compare_op0;
1764   rtx op2 = m32r_compare_op1;
1765   enum machine_mode mode = GET_MODE (op0);
1766
1767   if (mode != SImode)
1768     FAIL;
1769
1770   if (! register_operand (op1, mode))
1771     op1 = force_reg (mode, op1);
1772
1773   if (GET_CODE (op2) == CONST_INT)
1774     {
1775       HOST_WIDE_INT value = INTVAL (op2);
1776       if (value >= 2147483647)
1777         {
1778           emit_move_insn (op0, GEN_INT (1));
1779           DONE;
1780         }
1781
1782       op2 = GEN_INT (value+1);
1783       if (value < -32768 || value >= 32767)
1784         op2 = force_reg (mode, op2);
1785
1786       emit_insn (gen_slt_insn (op0, op1, op2));
1787       DONE;
1788     }
1789
1790   if (! register_operand (op2, mode))
1791     op2 = force_reg (mode, op2);
1792
1793   emit_insn (gen_sle_insn (op0, op1, op2));
1794   DONE;
1795 }")
1796
1797 (define_insn "sle_insn"
1798   [(set (match_operand:SI 0 "register_operand" "=r")
1799         (le:SI (match_operand:SI 1 "register_operand" "r")
1800                (match_operand:SI 2 "register_operand" "r")))
1801    (clobber (reg:SI 17))]
1802   ""
1803   "#"
1804   [(set_attr "type" "multi")
1805    (set_attr "length" "8")])
1806
1807 (define_split
1808   [(set (match_operand:SI 0 "register_operand" "")
1809         (le:SI (match_operand:SI 1 "register_operand" "")
1810                (match_operand:SI 2 "register_operand" "")))
1811    (clobber (reg:SI 17))]
1812   "!optimize_size"
1813   [(set (reg:SI 17)
1814         (lt:SI (match_dup 2)
1815                (match_dup 1)))
1816    (set (match_dup 0)
1817         (reg:SI 17))
1818    (set (match_dup 0)
1819         (xor:SI (match_dup 0)
1820                 (const_int 1)))]
1821   "")
1822
1823 ;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
1824 ;; xor reg,reg,1 which might eliminate a NOP being inserted.
1825 (define_split
1826   [(set (match_operand:SI 0 "register_operand" "")
1827         (le:SI (match_operand:SI 1 "register_operand" "")
1828                (match_operand:SI 2 "register_operand" "")))
1829    (clobber (reg:SI 17))]
1830   "optimize_size"
1831   [(set (reg:SI 17)
1832         (lt:SI (match_dup 2)
1833                (match_dup 1)))
1834    (set (match_dup 0)
1835         (reg:SI 17))
1836    (set (match_dup 0)
1837         (plus:SI (match_dup 0)
1838                  (const_int -1)))
1839    (set (match_dup 0)
1840         (neg:SI (match_dup 0)))]
1841   "")
1842
1843 (define_expand "sgt"
1844   [(match_operand:SI 0 "register_operand" "")]
1845   ""
1846   "
1847 {
1848   rtx op0 = operands[0];
1849   rtx op1 = m32r_compare_op0;
1850   rtx op2 = m32r_compare_op1;
1851   enum machine_mode mode = GET_MODE (op0);
1852
1853   if (mode != SImode)
1854     FAIL;
1855
1856   if (! register_operand (op1, mode))
1857     op1 = force_reg (mode, op1);
1858
1859   if (! register_operand (op2, mode))
1860     op2 = force_reg (mode, op2);
1861
1862   emit_insn (gen_slt_insn (op0, op2, op1));
1863   DONE;
1864 }")
1865
1866 (define_expand "sge"
1867   [(match_operand:SI 0 "register_operand" "")]
1868   ""
1869   "
1870 {
1871   rtx op0 = operands[0];
1872   rtx op1 = m32r_compare_op0;
1873   rtx op2 = m32r_compare_op1;
1874   enum machine_mode mode = GET_MODE (op0);
1875
1876   if (mode != SImode)
1877     FAIL;
1878
1879   if (! register_operand (op1, mode))
1880     op1 = force_reg (mode, op1);
1881
1882   if (! reg_or_int16_operand (op2, mode))
1883     op2 = force_reg (mode, op2);
1884
1885   emit_insn (gen_sge_insn (op0, op1, op2));
1886   DONE;
1887 }")
1888
1889 (define_insn "sge_insn"
1890   [(set (match_operand:SI 0 "register_operand" "=r,r")
1891         (ge:SI (match_operand:SI 1 "register_operand" "r,r")
1892                (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
1893    (clobber (reg:SI 17))]
1894   ""
1895   "#"
1896   [(set_attr "type" "multi")
1897    (set_attr "length" "8,10")])
1898
1899 (define_split
1900   [(set (match_operand:SI 0 "register_operand" "")
1901         (ge:SI (match_operand:SI 1 "register_operand" "")
1902                (match_operand:SI 2 "reg_or_int16_operand" "")))
1903    (clobber (reg:SI 17))]
1904   "!optimize_size"
1905   [(set (reg:SI 17)
1906         (lt:SI (match_dup 1)
1907                (match_dup 2)))
1908    (set (match_dup 0)
1909         (reg:SI 17))
1910    (set (match_dup 0)
1911         (xor:SI (match_dup 0)
1912                 (const_int 1)))]
1913   "")
1914
1915 ;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
1916 ;; xor reg,reg,1 which might eliminate a NOP being inserted.
1917 (define_split
1918   [(set (match_operand:SI 0 "register_operand" "")
1919         (ge:SI (match_operand:SI 1 "register_operand" "")
1920                (match_operand:SI 2 "reg_or_int16_operand" "")))
1921    (clobber (reg:SI 17))]
1922   "optimize_size"
1923   [(set (reg:SI 17)
1924         (lt:SI (match_dup 1)
1925                (match_dup 2)))
1926    (set (match_dup 0)
1927         (reg:SI 17))
1928    (set (match_dup 0)
1929         (plus:SI (match_dup 0)
1930                  (const_int -1)))
1931    (set (match_dup 0)
1932         (neg:SI (match_dup 0)))]
1933   "")
1934
1935 (define_expand "sltu"
1936   [(match_operand:SI 0 "register_operand" "")]
1937   ""
1938   "
1939 {
1940   rtx op0 = operands[0];
1941   rtx op1 = m32r_compare_op0;
1942   rtx op2 = m32r_compare_op1;
1943   enum machine_mode mode = GET_MODE (op0);
1944
1945   if (mode != SImode)
1946     FAIL;
1947
1948   if (! register_operand (op1, mode))
1949     op1 = force_reg (mode, op1);
1950
1951   if (! reg_or_int16_operand (op2, mode))
1952     op2 = force_reg (mode, op2);
1953
1954   emit_insn (gen_sltu_insn (op0, op1, op2));
1955   DONE;
1956 }")
1957
1958 (define_insn "sltu_insn"
1959   [(set (match_operand:SI 0 "register_operand" "=r,r")
1960         (ltu:SI (match_operand:SI 1 "register_operand" "r,r")
1961                 (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
1962    (clobber (reg:SI 17))]
1963   ""
1964   "#"
1965   [(set_attr "type" "multi")
1966    (set_attr "length" "6,8")])
1967
1968 (define_split
1969   [(set (match_operand:SI 0 "register_operand" "")
1970         (ltu:SI (match_operand:SI 1 "register_operand" "")
1971                 (match_operand:SI 2 "reg_or_int16_operand" "")))
1972    (clobber (reg:SI 17))]
1973   ""
1974   [(set (reg:SI 17)
1975         (ltu:SI (match_dup 1)
1976                 (match_dup 2)))
1977    (set (match_dup 0)
1978         (reg:SI 17))]
1979   "")
1980
1981 (define_expand "sleu"
1982   [(match_operand:SI 0 "register_operand" "")]
1983   ""
1984   "
1985 {
1986   rtx op0 = operands[0];
1987   rtx op1 = m32r_compare_op0;
1988   rtx op2 = m32r_compare_op1;
1989   enum machine_mode mode = GET_MODE (op0);
1990
1991   if (mode != SImode)
1992     FAIL;
1993
1994   if (GET_CODE (op2) == CONST_INT)
1995     {
1996       HOST_WIDE_INT value = INTVAL (op2);
1997       if (value >= 2147483647)
1998         {
1999           emit_move_insn (op0, GEN_INT (1));
2000           DONE;
2001         }
2002
2003       op2 = GEN_INT (value+1);
2004       if (value < 0 || value >= 32767)
2005         op2 = force_reg (mode, op2);
2006
2007       emit_insn (gen_sltu_insn (op0, op1, op2));
2008       DONE;
2009     }
2010
2011   if (! register_operand (op2, mode))
2012     op2 = force_reg (mode, op2);
2013
2014   emit_insn (gen_sleu_insn (op0, op1, op2));
2015   DONE;
2016 }")
2017
2018 (define_insn "sleu_insn"
2019   [(set (match_operand:SI 0 "register_operand" "=r")
2020         (leu:SI (match_operand:SI 1 "register_operand" "r")
2021                 (match_operand:SI 2 "register_operand" "r")))
2022    (clobber (reg:SI 17))]
2023   ""
2024   "#"
2025   [(set_attr "type" "multi")
2026    (set_attr "length" "8")])
2027
2028 (define_split
2029   [(set (match_operand:SI 0 "register_operand" "")
2030         (leu:SI (match_operand:SI 1 "register_operand" "")
2031                 (match_operand:SI 2 "register_operand" "")))
2032    (clobber (reg:SI 17))]
2033   "!optimize_size"
2034   [(set (reg:SI 17)
2035         (ltu:SI (match_dup 2)
2036                 (match_dup 1)))
2037    (set (match_dup 0)
2038         (reg:SI 17))
2039    (set (match_dup 0)
2040         (xor:SI (match_dup 0)
2041                 (const_int 1)))]
2042   "")
2043
2044 ;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
2045 ;; xor reg,reg,1 which might eliminate a NOP being inserted.
2046 (define_split
2047   [(set (match_operand:SI 0 "register_operand" "")
2048         (leu:SI (match_operand:SI 1 "register_operand" "")
2049                 (match_operand:SI 2 "register_operand" "")))
2050    (clobber (reg:SI 17))]
2051   "optimize_size"
2052   [(set (reg:SI 17)
2053         (ltu:SI (match_dup 2)
2054                 (match_dup 1)))
2055    (set (match_dup 0)
2056         (reg:SI 17))
2057    (set (match_dup 0)
2058         (plus:SI (match_dup 0)
2059                  (const_int -1)))
2060    (set (match_dup 0)
2061         (neg:SI (match_dup 0)))]
2062   "")
2063
2064 (define_expand "sgtu"
2065   [(match_operand:SI 0 "register_operand" "")]
2066   ""
2067   "
2068 {
2069   rtx op0 = operands[0];
2070   rtx op1 = m32r_compare_op0;
2071   rtx op2 = m32r_compare_op1;
2072   enum machine_mode mode = GET_MODE (op0);
2073
2074   if (mode != SImode)
2075     FAIL;
2076
2077   if (! register_operand (op1, mode))
2078     op1 = force_reg (mode, op1);
2079
2080   if (! register_operand (op2, mode))
2081     op2 = force_reg (mode, op2);
2082
2083   emit_insn (gen_sltu_insn (op0, op2, op1));
2084   DONE;
2085 }")
2086
2087 (define_expand "sgeu"
2088   [(match_operand:SI 0 "register_operand" "")]
2089   ""
2090   "
2091 {
2092   rtx op0 = operands[0];
2093   rtx op1 = m32r_compare_op0;
2094   rtx op2 = m32r_compare_op1;
2095   enum machine_mode mode = GET_MODE (op0);
2096
2097   if (mode != SImode)
2098     FAIL;
2099
2100   if (! register_operand (op1, mode))
2101     op1 = force_reg (mode, op1);
2102
2103   if (! reg_or_int16_operand (op2, mode))
2104     op2 = force_reg (mode, op2);
2105
2106   emit_insn (gen_sgeu_insn (op0, op1, op2));
2107   DONE;
2108 }")
2109
2110 (define_insn "sgeu_insn"
2111   [(set (match_operand:SI 0 "register_operand" "=r,r")
2112         (geu:SI (match_operand:SI 1 "register_operand" "r,r")
2113                 (match_operand:SI 2 "reg_or_int16_operand" "r,J")))
2114    (clobber (reg:SI 17))]
2115   ""
2116   "#"
2117   [(set_attr "type" "multi")
2118    (set_attr "length" "8,10")])
2119
2120 (define_split
2121   [(set (match_operand:SI 0 "register_operand" "")
2122         (geu:SI (match_operand:SI 1 "register_operand" "")
2123                 (match_operand:SI 2 "reg_or_int16_operand" "")))
2124    (clobber (reg:SI 17))]
2125   "!optimize_size"
2126   [(set (reg:SI 17)
2127         (ltu:SI (match_dup 1)
2128                 (match_dup 2)))
2129    (set (match_dup 0)
2130         (reg:SI 17))
2131    (set (match_dup 0)
2132         (xor:SI (match_dup 0)
2133                 (const_int 1)))]
2134   "")
2135
2136 ;; If optimizing for space, use -(reg - 1) to invert the comparison rather than
2137 ;; xor reg,reg,1 which might eliminate a NOP being inserted.
2138 (define_split
2139   [(set (match_operand:SI 0 "register_operand" "")
2140         (geu:SI (match_operand:SI 1 "register_operand" "")
2141                 (match_operand:SI 2 "reg_or_int16_operand" "")))
2142    (clobber (reg:SI 17))]
2143   "optimize_size"
2144   [(set (reg:SI 17)
2145         (ltu:SI (match_dup 1)
2146                 (match_dup 2)))
2147    (set (match_dup 0)
2148         (reg:SI 17))
2149    (set (match_dup 0)
2150         (plus:SI (match_dup 0)
2151                  (const_int -1)))
2152    (set (match_dup 0)
2153         (neg:SI (match_dup 0)))]
2154   "")
2155
2156 (define_insn "movcc_insn"
2157   [(set (match_operand:SI 0 "register_operand" "=r")
2158         (reg:SI 17))]
2159   ""
2160   "mvfc %0, cbr"
2161   [(set_attr "type" "misc")
2162    (set_attr "length" "2")])
2163
2164 \f
2165 ;; Unconditional and other jump instructions.
2166
2167 (define_insn "jump"
2168   [(set (pc) (label_ref (match_operand 0 "" "")))]
2169   ""
2170   "bra %l0"
2171   [(set_attr "type" "uncond_branch")
2172    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
2173                                                  (const_int 400))
2174                                            (const_int 800))
2175                                       (const_int 2)
2176                                       (const_int 4)))])
2177
2178 (define_insn "indirect_jump"
2179   [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
2180   ""
2181   "jmp %a0"
2182   [(set_attr "type" "uncond_branch")
2183    (set_attr "length" "2")])
2184
2185 (define_insn "return"
2186   [(return)]
2187   "direct_return ()"
2188   "jmp lr"
2189   [(set_attr "type" "uncond_branch")
2190    (set_attr "length" "2")])
2191  
2192 (define_insn "tablejump"
2193   [(set (pc) (match_operand:SI 0 "address_operand" "p"))
2194    (use (label_ref (match_operand 1 "" "")))]
2195   ""
2196   "jmp %a0"
2197   [(set_attr "type" "uncond_branch")
2198    (set_attr "length" "2")])
2199
2200 (define_expand "call"
2201   ;; operands[1] is stack_size_rtx
2202   ;; operands[2] is next_arg_register
2203   [(parallel [(call (match_operand:SI 0 "call_operand" "")
2204                     (match_operand 1 "" ""))
2205              (clobber (reg:SI 14))])]
2206   ""
2207   "")
2208
2209 (define_insn "*call_via_reg"
2210   [(call (mem:SI (match_operand:SI 0 "register_operand" "r"))
2211          (match_operand 1 "" ""))
2212    (clobber (reg:SI 14))]
2213   ""
2214   "jl %0"
2215   [(set_attr "type" "call")
2216    (set_attr "length" "2")])
2217
2218 (define_insn "*call_via_label"
2219   [(call (mem:SI (match_operand:SI 0 "call_address_operand" ""))
2220          (match_operand 1 "" ""))
2221    (clobber (reg:SI 14))]
2222   ""
2223   "*
2224 {
2225   int call26_p = call26_operand (operands[0], FUNCTION_MODE);
2226
2227   if (! call26_p)
2228     {
2229       /* We may not be able to reach with a `bl' insn so punt and leave it to
2230          the linker.
2231          We do this here, rather than doing a force_reg in the define_expand
2232          so these insns won't be separated, say by scheduling, thus simplifying
2233          the linker.  */
2234       return \"seth r14,%T0\;add3 r14,r14,%B0\;jl r14\";
2235     }
2236   else
2237     return \"bl %0\";
2238 }"
2239   [(set_attr "type" "call")
2240    (set (attr "length")
2241         (if_then_else (eq (symbol_ref "call26_operand (operands[0], FUNCTION_MODE)")
2242                           (const_int 0))
2243                       (const_int 12) ; 10 + 2 for nop filler
2244                       ; The return address must be on a 4 byte boundary so
2245                       ; there's no point in using a value of 2 here.  A 2 byte
2246                       ; insn may go in the left slot but we currently can't
2247                       ; use such knowledge.
2248                       (const_int 4)))])
2249
2250 (define_expand "call_value"
2251   ;; operand 2 is stack_size_rtx
2252   ;; operand 3 is next_arg_register
2253   [(parallel [(set (match_operand 0 "register_operand" "=r")
2254                    (call (match_operand:SI 1 "call_operand" "")
2255                          (match_operand 2 "" "")))
2256              (clobber (reg:SI 14))])]
2257   ""
2258   "")
2259
2260 (define_insn "*call_value_via_reg"
2261   [(set (match_operand 0 "register_operand" "=r")
2262         (call (mem:SI (match_operand:SI 1 "register_operand" "r"))
2263               (match_operand 2 "" "")))
2264    (clobber (reg:SI 14))]
2265   ""
2266   "jl %1"
2267   [(set_attr "type" "call")
2268    (set_attr "length" "2")])
2269
2270 (define_insn "*call_value_via_label"
2271   [(set (match_operand 0 "register_operand" "=r")
2272         (call (mem:SI (match_operand:SI 1 "call_address_operand" ""))
2273               (match_operand 2 "" "")))
2274    (clobber (reg:SI 14))]
2275   ""
2276   "*
2277 {
2278   int call26_p = call26_operand (operands[1], FUNCTION_MODE);
2279
2280   if (! call26_p)
2281     {
2282       /* We may not be able to reach with a `bl' insn so punt and leave it to
2283          the linker.
2284          We do this here, rather than doing a force_reg in the define_expand
2285          so these insns won't be separated, say by scheduling, thus simplifying
2286          the linker.  */
2287       return \"seth r14,%T1\;add3 r14,r14,%B1\;jl r14\";
2288     }
2289   else
2290     return \"bl %1\";
2291 }"
2292   [(set_attr "type" "call")
2293    (set (attr "length")
2294         (if_then_else (eq (symbol_ref "call26_operand (operands[1], FUNCTION_MODE)")
2295                           (const_int 0))
2296                       (const_int 12) ; 10 + 2 for nop filler
2297                       ; The return address must be on a 4 byte boundary so
2298                       ; there's no point in using a value of 2 here.  A 2 byte
2299                       ; insn may go in the left slot but we currently can't
2300                       ; use such knowledge.
2301                       (const_int 4)))])
2302 \f
2303 (define_insn "nop"
2304   [(const_int 0)]
2305   ""
2306   "nop"
2307   [(set_attr "type" "int2")
2308    (set_attr "length" "2")])
2309
2310 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
2311 ;; all of memory.  This blocks insns from being moved across this point.
2312
2313 (define_insn "blockage"
2314   [(unspec_volatile [(const_int 0)] 0)]
2315   ""
2316   "")
2317
2318 ;; Special pattern to flush the icache.
2319
2320 (define_insn "flush_icache"
2321   [(unspec_volatile [(match_operand 0 "memory_operand" "m")] 0)]
2322   ""
2323   "* return \"nop ; flush-icache\";"
2324   [(set_attr "type" "int2")
2325    (set_attr "length" "2")])
2326 \f
2327 ;; Speed up fabs and provide correct sign handling for -0
2328
2329 (define_insn "absdf2"
2330   [(set (match_operand:DF 0 "register_operand" "=r")
2331         (abs:DF (match_operand:DF 1 "register_operand" "0")))]
2332   ""
2333   "#"
2334   [(set_attr "type" "multi")
2335    (set_attr "length" "4")])
2336
2337 (define_split
2338   [(set (match_operand:DF 0 "register_operand" "")
2339         (abs:DF (match_operand:DF 1 "register_operand" "")))]
2340   "reload_completed"
2341   [(set (match_dup 2)
2342         (ashift:SI (match_dup 2)
2343                    (const_int 1)))
2344    (set (match_dup 2)
2345         (lshiftrt:SI (match_dup 2)
2346                      (const_int 1)))]
2347   "operands[2] = gen_highpart (SImode, operands[0]);")
2348
2349 (define_insn "abssf2"
2350   [(set (match_operand:SF 0 "register_operand" "=r")
2351         (abs:SF (match_operand:SF 1 "register_operand" "0")))]
2352   ""
2353   "#"
2354   [(set_attr "type" "multi")
2355    (set_attr "length" "4")])
2356
2357 (define_split
2358   [(set (match_operand:SF 0 "register_operand" "")
2359         (abs:SF (match_operand:SF 1 "register_operand" "")))]
2360   "reload_completed"
2361   [(set (match_dup 2)
2362         (ashift:SI (match_dup 2)
2363                    (const_int 1)))
2364    (set (match_dup 2)
2365         (lshiftrt:SI (match_dup 2)
2366                      (const_int 1)))]
2367   "operands[2] = gen_highpart (SImode, operands[0]);")
2368 \f
2369 ;; Conditional move instructions
2370 ;; Based on those done for the d10v
2371
2372 (define_expand "movsicc"
2373   [
2374    (set (match_operand:SI 0 "register_operand" "r")
2375         (if_then_else:SI (match_operand 1 "" "")
2376                          (match_operand:SI 2 "conditional_move_operand" "O")
2377                          (match_operand:SI 3 "conditional_move_operand" "O")
2378         )
2379    )
2380   ]
2381   ""
2382   "
2383 {
2384   if (! zero_and_one (operands [2], operands [3]))
2385     FAIL;
2386
2387   /* Generate the comparision that will set the carry flag.  */
2388   operands[1] = gen_compare (GET_CODE (operands[1]), m32r_compare_op0,
2389                              m32r_compare_op1, TRUE);
2390
2391   /* See other movsicc pattern below for reason why.  */
2392   emit_insn (gen_blockage ());
2393 }")
2394
2395 ;; Generate the conditional instructions based on how the carry flag is examined.
2396 (define_insn "*movsicc_internal"
2397   [(set (match_operand:SI 0 "register_operand" "=r")
2398         (if_then_else:SI (match_operand 1 "carry_compare_operand" "")
2399                          (match_operand:SI 2 "conditional_move_operand" "O")
2400                          (match_operand:SI 3 "conditional_move_operand" "O")
2401         )
2402    )]
2403   "zero_and_one (operands [2], operands[3])"
2404   "* return emit_cond_move (operands, insn);"
2405   [(set_attr "type" "multi")
2406    (set_attr "length" "8")
2407   ]
2408 )
2409
2410 \f
2411 ;; Split up troublesome insns for better scheduling.
2412 ;; FIXME: Peepholes go at the end.
2413
2414 ;; ??? Setting the type attribute may not be useful, but for completeness
2415 ;; we do it.
2416
2417 (define_peephole
2418   [(set (mem:SI (plus:SI (match_operand:SI 0 "register_operand" "r")
2419                          (const_int 4)))
2420         (match_operand:SI 1 "register_operand" "r"))]
2421   "0 && dead_or_set_p (insn, operands[0])"
2422   "st %1,@+%0"
2423   [(set_attr "type" "store2")
2424    (set_attr "length" "2")])
2425
2426 ;; This case is triggered by compiling this code:
2427 ;; 
2428 ;; extern void sub(int *);
2429 ;; void main (void)
2430 ;; {
2431 ;;   int i=2,j=3,k;
2432 ;;   while (i < j)  sub(&k);
2433 ;;   i = j / k;
2434 ;;   sub(&i);
2435 ;;   i = j - k;
2436 ;;   sub(&i);
2437 ;; }
2438 ;;
2439 ;; Without the peephole the following assembler is generated for the
2440 ;; divide and subtract expressions:
2441 ;;
2442 ;;         div r5,r4     
2443 ;;         mv r4,r5      
2444 ;;         st r4,@(4,sp) 
2445 ;;         bl sub
2446 ;; 
2447 ;; Simialr code is produced for the subtract expression.  With this
2448 ;; peephole the redundant move is eliminated.
2449 ;;
2450 ;; This optimisation onbly works if PRESERVE_DEATH_INFO_REGNO_P is
2451 ;; defined in m32r.h
2452
2453 (define_peephole
2454   [(set (match_operand:SI 0 "register_operand" "r")
2455         (match_operand:SI 1 "register_operand" "r")
2456    )
2457    (set (mem:SI (plus: SI (match_operand:SI 2 "register_operand" "r")
2458                 (match_operand:SI 3 "immediate_operand" "J")))
2459         (match_dup 0)
2460    )
2461   ]
2462   "0 && dead_or_set_p (insn, operands [0])"
2463   "st %1,@(%3,%2)"
2464   [(set_attr "type" "store4")
2465    (set_attr "length" "4")
2466   ]
2467 )
2468
2469 ;; Block moves, see m32r.c for more details.
2470 ;; Argument 0 is the destination
2471 ;; Argument 1 is the source
2472 ;; Argument 2 is the length
2473 ;; Argument 3 is the alignment
2474
2475 (define_expand "movstrsi"
2476   [(parallel [(set (match_operand:BLK 0 "general_operand" "")
2477                    (match_operand:BLK 1 "general_operand" ""))
2478               (use (match_operand:SI  2 "immediate_operand" ""))
2479               (use (match_operand:SI  3 "immediate_operand" ""))])]
2480   ""
2481   "
2482 {
2483   if (operands[0])              /* avoid unused code messages */
2484     {
2485       m32r_expand_block_move (operands);
2486       DONE;
2487     }
2488 }")
2489
2490 ;; Insn generated by block moves
2491
2492 (define_insn "movstrsi_internal"
2493   [(set (mem:BLK (match_operand:SI 0 "register_operand" "+r"))  ;; destination
2494         (mem:BLK (match_operand:SI 1 "register_operand" "+r"))) ;; source
2495    (use (match_operand:SI 2 "m32r_block_immediate_operand" "J"));; # bytes to move
2496    (set (match_dup 0) (plus:SI (match_dup 0) (minus:SI (match_dup 2) (const_int 4))))
2497    (set (match_dup 1) (plus:SI (match_dup 1) (match_dup 2)))
2498    (clobber (match_scratch:SI 3 "=&r"))                         ;; temp 1
2499    (clobber (match_scratch:SI 4 "=&r"))]                        ;; temp 2
2500   ""
2501   "* return m32r_output_block_move (insn, operands);"
2502   [(set_attr "type"     "store8")
2503    (set_attr "length"   "72")]) ;; Maximum