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