OSDN Git Service

Merge in gcc2-ss-010999
[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
73
74 \f
75 ;; ::::::::::::::::::::
76 ;; ::
77 ;; :: Function Units
78 ;; ::
79 ;; ::::::::::::::::::::
80
81 ;; On most RISC machines, there are instructions whose results are not
82 ;; available for a specific number of cycles.  Common cases are instructions
83 ;; that load data from memory.  On many machines, a pipeline stall will result
84 ;; if the data is referenced too soon after the load instruction.
85
86 ;; In addition, many newer microprocessors have multiple function units,
87 ;; usually one for integer and one for floating point, and often will incur
88 ;; pipeline stalls when a result that is needed is not yet ready.
89
90 ;; The descriptions in this section allow the specification of how much time
91 ;; must elapse between the execution of an instruction and the time when its
92 ;; result is used.  It also allows specification of when the execution of an
93 ;; instruction will delay execution of similar instructions due to function
94 ;; unit conflicts.
95
96 ;; For the purposes of the specifications in this section, a machine is divided
97 ;; into "function units", each of which execute a specific class of
98 ;; instructions in first-in-first-out order.  Function units that accept one
99 ;; instruction each cycle and allow a result to be used in the succeeding
100 ;; instruction (usually via forwarding) need not be specified.  Classic RISC
101 ;; microprocessors will normally have a single function unit, which we can call
102 ;; `memory'.  The newer "superscalar" processors will often have function units
103 ;; for floating point operations, usually at least a floating point adder and
104 ;; multiplier.
105
106 ;; Each usage of a function units by a class of insns is specified with a
107 ;; `define_function_unit' expression, which looks like this:
108
109 ;; (define_function_unit NAME MULTIPLICITY SIMULTANEITY TEST READY-DELAY
110 ;;   ISSUE-DELAY [CONFLICT-LIST])
111
112 ;; NAME is a string giving the name of the function unit.
113
114 ;; MULTIPLICITY is an integer specifying the number of identical units in the
115 ;; processor.  If more than one unit is specified, they will be scheduled
116 ;; independently.  Only truly independent units should be counted; a pipelined
117 ;; unit should be specified as a single unit.  (The only common example of a
118 ;; machine that has multiple function units for a single instruction class that
119 ;; are truly independent and not pipelined are the two multiply and two
120 ;; increment units of the CDC 6600.)
121
122 ;; SIMULTANEITY specifies the maximum number of insns that can be executing in
123 ;; each instance of the function unit simultaneously or zero if the unit is
124 ;; pipelined and has no limit.
125
126 ;; All `define_function_unit' definitions referring to function unit NAME must
127 ;; have the same name and values for MULTIPLICITY and SIMULTANEITY.
128
129 ;; TEST is an attribute test that selects the insns we are describing in this
130 ;; definition.  Note that an insn may use more than one function unit and a
131 ;; function unit may be specified in more than one `define_function_unit'.
132
133 ;; READY-DELAY is an integer that specifies the number of cycles after which
134 ;; the result of the instruction can be used without introducing any stalls.
135
136 ;; ISSUE-DELAY is an integer that specifies the number of cycles after the
137 ;; instruction matching the TEST expression begins using this unit until a
138 ;; subsequent instruction can begin.  A cost of N indicates an N-1 cycle delay.
139 ;; A subsequent instruction may also be delayed if an earlier instruction has a
140 ;; longer READY-DELAY value.  This blocking effect is computed using the
141 ;; SIMULTANEITY, READY-DELAY, ISSUE-DELAY, and CONFLICT-LIST terms.  For a
142 ;; normal non-pipelined function unit, SIMULTANEITY is one, the unit is taken
143 ;; to block for the READY-DELAY cycles of the executing insn, and smaller
144 ;; values of ISSUE-DELAY are ignored.
145
146 ;; CONFLICT-LIST is an optional list giving detailed conflict costs for this
147 ;; unit.  If specified, it is a list of condition test expressions to be
148 ;; applied to insns chosen to execute in NAME following the particular insn
149 ;; matching TEST that is already executing in NAME.  For each insn in the list,
150 ;; ISSUE-DELAY specifies the conflict cost; for insns not in the list, the cost
151 ;; is zero.  If not specified, CONFLICT-LIST defaults to all instructions that
152 ;; use the function unit.
153
154 ;; Typical uses of this vector are where a floating point function unit can
155 ;; pipeline either single- or double-precision operations, but not both, or
156 ;; where a memory unit can pipeline loads, but not stores, etc.
157
158 ;; As an example, consider a classic RISC machine where the result of a load
159 ;; instruction is not available for two cycles (a single "delay" instruction is
160 ;; required) and where only one load instruction can be executed
161 ;; simultaneously.  This would be specified as:
162
163 ;; (define_function_unit "memory" 1 1 (eq_attr "type" "load") 2 0)
164
165 ;; For the case of a floating point function unit that can pipeline
166 ;; either single or double precision, but not both, the following could be
167 ;; specified:
168 ;;
169 ;; (define_function_unit "fp" 1 0
170 ;;   (eq_attr "type" "sp_fp") 4 4
171 ;;   [(eq_attr "type" "dp_fp")])
172 ;;
173 ;; (define_function_unit "fp" 1 0
174 ;;   (eq_attr "type" "dp_fp") 4 4
175 ;;   [(eq_attr "type" "sp_fp")])
176
177 ;; Note: The scheduler attempts to avoid function unit conflicts and uses all
178 ;; the specifications in the `define_function_unit' expression.  It has
179 ;; recently come to our attention that these specifications may not allow
180 ;; modeling of some of the newer "superscalar" processors that have insns using
181 ;; multiple pipelined units.  These insns will cause a potential conflict for
182 ;; the second unit used during their execution and there is no way of
183 ;; representing that conflict.  We welcome any examples of how function unit
184 ;; conflicts work in such processors and suggestions for their representation.
185
186 ;; Function units of the M32R
187 ;; Units that take one cycle do not need to be specified.
188
189 ;; (define_function_unit {name} {multiplicity} {simulataneity} {test}
190 ;;                       {ready-delay} {issue-delay} [{conflict-list}])
191
192 ;; Hack to get GCC to better pack the instructions.
193 ;; We pretend there is a separate long function unit that conflicts with
194 ;; both the left and right 16 bit insn slots.
195
196 (define_function_unit "short" 2 2
197   (and (eq_attr "m32r" "yes")
198        (and (eq_attr "insn_size" "short")
199             (eq_attr "type" "!load2")))
200   1 0
201   [(eq_attr "insn_size" "long")])
202
203 (define_function_unit "short" 2 2       ;; load delay of 1 clock for mem execution + 1 clock for WB
204   (and (eq_attr "m32r" "yes")
205        (eq_attr "type" "load2"))
206   3 0
207   [(eq_attr "insn_size" "long")])
208
209 (define_function_unit "long" 1 1
210   (and (eq_attr "m32r" "yes")
211        (and (eq_attr "insn_size" "long")
212             (eq_attr "type" "!load4,load8")))
213   1 0
214   [(eq_attr "insn_size" "short")])
215
216 (define_function_unit "long" 1 1        ;; load delay of 1 clock for mem execution + 1 clock for WB
217   (and (eq_attr "m32r" "yes")
218        (and (eq_attr "insn_size" "long")
219             (eq_attr "type" "load4,load8")))
220   3 0
221   [(eq_attr "insn_size" "short")])
222
223
224 \f
225 ;; Instruction grouping
226
227 \f
228 ;; Expand prologue as RTL
229 (define_expand "prologue"
230   [(const_int 1)]
231   ""
232   "
233 {
234   m32r_expand_prologue ();
235   DONE;
236 }")
237
238 \f
239 ;; Move instructions.
240 ;;
241 ;; For QI and HI moves, the register must contain the full properly
242 ;; sign-extended value.  nonzero_bits assumes this [otherwise
243 ;; SHORT_IMMEDIATES_SIGN_EXTEND must be used, but the comment for it
244 ;; says it's a kludge and the .md files should be fixed instead].
245
246 (define_expand "movqi"
247   [(set (match_operand:QI 0 "general_operand" "")
248         (match_operand:QI 1 "general_operand" ""))]
249   ""
250   "
251 {
252   /* Everything except mem = const or mem = mem can be done easily.
253      Objects in the small data area are handled too.  */
254
255   if (GET_CODE (operands[0]) == MEM)
256     operands[1] = force_reg (QImode, operands[1]);
257 }")
258
259 (define_insn "*movqi_insn"
260   [(set (match_operand:QI 0 "move_dest_operand" "=r,r,r,r,r,T,m")
261         (match_operand:QI 1 "move_src_operand" "r,I,JQR,T,m,r,r"))]
262   "register_operand (operands[0], QImode) || register_operand (operands[1], QImode)"
263   "@
264    mv %0,%1
265    ldi %0,%#%1
266    ldi %0,%#%1
267    ldub %0,%1
268    ldub %0,%1
269    stb %1,%0
270    stb %1,%0"
271   [(set_attr "type" "int2,int2,int4,load2,load4,store2,store4")
272    (set_attr "length" "2,2,4,2,4,2,4")])
273
274 (define_expand "movhi"
275   [(set (match_operand:HI 0 "general_operand" "")
276         (match_operand:HI 1 "general_operand" ""))]
277   ""
278   "
279 {
280   /* Everything except mem = const or mem = mem can be done easily.  */
281
282   if (GET_CODE (operands[0]) == MEM)
283     operands[1] = force_reg (HImode, operands[1]);
284 }")
285
286 (define_insn "*movhi_insn"
287   [(set (match_operand:HI 0 "move_dest_operand" "=r,r,r,r,r,r,T,m")
288         (match_operand:HI 1 "move_src_operand" "r,I,JQR,K,T,m,r,r"))]
289   "register_operand (operands[0], HImode) || register_operand (operands[1], HImode)"
290   "@
291    mv %0,%1
292    ldi %0,%#%1
293    ldi %0,%#%1
294    ld24 %0,%#%1
295    lduh %0,%1
296    lduh %0,%1
297    sth %1,%0
298    sth %1,%0"
299   [(set_attr "type" "int2,int2,int4,int4,load2,load4,store2,store4")
300    (set_attr "length" "2,2,4,4,2,4,2,4")])
301
302 (define_expand "movsi_push"
303   [(set (mem:SI (pre_dec:SI (match_operand:SI 0 "register_operand" "")))
304         (match_operand:SI 1 "register_operand" ""))]
305   ""
306   "")
307
308 (define_expand "movsi_pop"
309   [(set (match_operand:SI 0 "register_operand" "")
310         (mem:SI (post_inc:SI (match_operand:SI 1 "register_operand" ""))))]
311   ""
312   "")
313
314 (define_expand "movsi"
315   [(set (match_operand:SI 0 "general_operand" "")
316         (match_operand:SI 1 "general_operand" ""))]
317   ""
318   "
319 {
320   /* Everything except mem = const or mem = mem can be done easily.  */
321
322   if (GET_CODE (operands[0]) == MEM)
323     operands[1] = force_reg (SImode, operands[1]);
324
325   /* Small Data Area reference?  */
326   if (small_data_operand (operands[1], SImode))
327     {
328       emit_insn (gen_movsi_sda (operands[0], operands[1]));
329       DONE;
330     }
331
332   /* If medium or large code model, symbols have to be loaded with
333      seth/add3.  */
334   if (addr32_operand (operands[1], SImode))
335     {
336       emit_insn (gen_movsi_addr32 (operands[0], operands[1]));
337       DONE;
338     }
339 }")
340
341 ;; ??? Do we need a const_double constraint here for large unsigned values?
342 (define_insn "*movsi_insn"
343   [(set (match_operand:SI 0 "move_dest_operand" "=r,r,r,r,r,r,r,r,r,T,U,m")
344         (match_operand:SI 1 "move_src_operand" "r,I,J,MQ,L,n,T,U,m,r,r,r"))]
345   "register_operand (operands[0], SImode) || register_operand (operands[1], SImode)"
346   "*
347 {
348   if (GET_CODE (operands[0]) == REG || GET_CODE (operands[1]) == SUBREG)
349     {
350       switch (GET_CODE (operands[1]))
351         {
352           HOST_WIDE_INT value;
353
354           default:
355             break;
356
357           case REG:
358           case SUBREG:
359             return \"mv %0,%1\";
360
361           case MEM:
362             return \"ld %0,%1\";
363
364           case CONST_INT:
365             value = INTVAL (operands[1]);
366             if (INT16_P (value))
367               return \"ldi %0,%#%1\\t; %X1\";
368
369             if (UINT24_P (value))
370               return \"ld24 %0,%#%1\\t; %X1\";
371
372             if (UPPER16_P (value))
373               return \"seth %0,%#%T1\\t; %X1\";
374
375             return \"#\";
376
377           case CONST:
378           case SYMBOL_REF:
379           case LABEL_REF:
380             if (TARGET_ADDR24)
381               return \"ld24 %0,%#%1\";
382
383             return \"#\";
384         }
385     }
386
387   else if (GET_CODE (operands[0]) == MEM
388            && (GET_CODE (operands[1]) == REG || GET_CODE (operands[1]) == SUBREG))
389     return \"st %1,%0\";
390
391   fatal_insn (\"bad movsi insn\", insn);
392 }"
393   [(set_attr "type" "int2,int2,int4,int4,int4,multi,load2,load2,load4,store2,store2,store4")
394    (set_attr "length" "2,2,4,4,4,8,2,2,4,2,2,4")])
395
396 ; Try to use a four byte / two byte pair for constants not loadable with
397 ; ldi, ld24, seth.
398
399 (define_split
400  [(set (match_operand:SI 0 "register_operand" "")
401        (match_operand:SI 1 "two_insn_const_operand" ""))]
402   ""
403   [(set (match_dup 0) (match_dup 2))
404    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 3)))]
405   "
406 {
407   unsigned HOST_WIDE_INT val = INTVAL (operands[1]);
408   unsigned HOST_WIDE_INT tmp;
409   int shift;
410
411   /* In all cases we will emit two instructions.  However we try to
412      use 2 byte instructions wherever possible.  We can assume the
413      constant isn't loadable with any of ldi, ld24, or seth.  */
414
415   /* See if we can load a 24 bit unsigned value and invert it.  */
416   if (UINT24_P (~ val))
417     {
418       emit_insn (gen_movsi (operands[0], GEN_INT (~ val)));
419       emit_insn (gen_one_cmplsi2 (operands[0], operands[0]));
420       DONE;
421     }
422
423   /* See if we can load a 24 bit unsigned value and shift it into place.
424      0x01fffffe is just beyond ld24's range.  */
425   for (shift = 1, tmp = 0x01fffffe;
426        shift < 8;
427        ++shift, tmp <<= 1)
428     {
429       if ((val & ~tmp) == 0)
430         {
431           emit_insn (gen_movsi (operands[0], GEN_INT (val >> shift)));
432           emit_insn (gen_ashlsi3 (operands[0], operands[0], GEN_INT (shift)));
433           DONE;
434         }
435     }
436
437   /* Can't use any two byte insn, fall back to seth/or3.  Use ~0xffff instead
438      of 0xffff0000, since the later fails on a 64-bit host.  */
439   operands[2] = GEN_INT ((val) & ~0xffff);
440   operands[3] = GEN_INT ((val) & 0xffff);
441 }")
442
443 (define_split
444   [(set (match_operand:SI 0 "register_operand" "")
445         (match_operand:SI 1 "seth_add3_operand" "i"))]
446   "TARGET_ADDR32"
447   [(set (match_dup 0)
448         (high:SI (match_dup 1)))
449    (set (match_dup 0)
450         (lo_sum:SI (match_dup 0)
451                    (match_dup 1)))]
452   "")
453
454 ;; Small data area support.
455 ;; The address of _SDA_BASE_ is loaded into a register and all objects in
456 ;; the small data area are indexed off that.  This is done for each reference
457 ;; but cse will clean things up for us.  We let the compiler choose the
458 ;; register to use so we needn't allocate (and maybe even fix) a special
459 ;; register to use.  Since the load and store insns have a 16 bit offset the
460 ;; total size of the data area can be 64K.  However, if the data area lives
461 ;; above 16M (24 bits), _SDA_BASE_ will have to be loaded with seth/add3 which
462 ;; would then yield 3 instructions to reference an object [though there would
463 ;; be no net loss if two or more objects were referenced].  The 3 insns can be
464 ;; reduced back to 2 if the size of the small data area were reduced to 32K
465 ;; [then seth + ld/st would work for any object in the area].  Doing this
466 ;; would require special handling of _SDA_BASE_ (its value would be
467 ;; (.sdata + 32K) & 0xffff0000) and reloc computations would be different
468 ;; [I think].  What to do about this is deferred until later and for now we
469 ;; require .sdata to be in the first 16M.
470
471 (define_expand "movsi_sda"
472   [(set (match_dup 2)
473         (unspec [(const_int 0)] 2))
474    (set (match_operand:SI 0 "register_operand" "")
475         (lo_sum:SI (match_dup 2)
476                    (match_operand:SI 1 "small_data_operand" "")))]
477   ""
478   "
479 {
480   if (reload_in_progress || reload_completed)
481     operands[2] = operands[0];
482   else
483     operands[2] = gen_reg_rtx (SImode);
484 }")
485
486 (define_insn "*load_sda_base"
487   [(set (match_operand:SI 0 "register_operand" "=r")
488         (unspec [(const_int 0)] 2))]
489   ""
490   "ld24 %0,#_SDA_BASE_"
491   [(set_attr "type" "int4")
492    (set_attr "length" "4")])
493
494 ;; 32 bit address support.
495
496 (define_expand "movsi_addr32"
497   [(set (match_dup 2)
498         ; addr32_operand isn't used because it's too restrictive,
499         ; seth_add3_operand is more general and thus safer.
500         (high:SI (match_operand:SI 1 "seth_add3_operand" "")))
501    (set (match_operand:SI 0 "register_operand" "")
502         (lo_sum:SI (match_dup 2) (match_dup 1)))]
503   ""
504   "
505 {
506   if (reload_in_progress || reload_completed)
507     operands[2] = operands[0];
508   else
509     operands[2] = gen_reg_rtx (SImode);
510 }")
511
512 (define_insn "set_hi_si"
513   [(set (match_operand:SI 0 "register_operand" "=r")
514         (high:SI (match_operand 1 "symbolic_operand" "")))]
515   ""
516   "seth %0,%#shigh(%1)"
517   [(set_attr "type" "int4")
518    (set_attr "length" "4")])
519
520 (define_insn "lo_sum_si"
521   [(set (match_operand:SI 0 "register_operand" "=r")
522         (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
523                    (match_operand:SI 2 "immediate_operand" "in")))]
524   ""
525   "add3 %0,%1,%#%B2"
526   [(set_attr "type" "int4")
527    (set_attr "length" "4")])
528
529 (define_expand "movdi"
530   [(set (match_operand:DI 0 "general_operand" "")
531         (match_operand:DI 1 "general_operand" ""))]
532   ""
533   "
534 {
535   /* Everything except mem = const or mem = mem can be done easily.  */
536
537   if (GET_CODE (operands[0]) == MEM)
538     operands[1] = force_reg (DImode, operands[1]);
539 }")
540
541 (define_insn "*movdi_insn"
542   [(set (match_operand:DI 0 "move_dest_operand" "=r,r,r,r,m")
543         (match_operand:DI 1 "move_double_src_operand" "r,nG,F,m,r"))]
544   "register_operand (operands[0], DImode) || register_operand (operands[1], DImode)"
545   "#"
546   [(set_attr "type" "multi,multi,multi,load8,store8")
547    (set_attr "length" "4,4,16,6,6")])
548
549 (define_split
550   [(set (match_operand:DI 0 "move_dest_operand" "")
551         (match_operand:DI 1 "move_double_src_operand" ""))]
552   "reload_completed"
553   [(match_dup 2)]
554   "operands[2] = gen_split_move_double (operands);")
555 \f
556 ;; Floating point move insns.
557
558 (define_expand "movsf"
559   [(set (match_operand:SF 0 "general_operand" "")
560         (match_operand:SF 1 "general_operand" ""))]
561   ""
562   "
563 {
564   /* Everything except mem = const or mem = mem can be done easily.  */
565
566   if (GET_CODE (operands[0]) == MEM)
567     operands[1] = force_reg (SFmode, operands[1]);
568 }")
569
570 (define_insn "*movsf_insn"
571   [(set (match_operand:SF 0 "move_dest_operand" "=r,r,r,r,T,m")
572         (match_operand:SF 1 "move_src_operand" "r,F,T,m,r,r"))]
573   "register_operand (operands[0], SFmode) || register_operand (operands[1], SFmode)"
574   "@
575    mv %0,%1
576    #
577    ld %0,%1
578    ld %0,%1
579    st %1,%0
580    st %1,%0"
581   ;; ??? Length of alternative 1 is either 2, 4 or 8.
582   [(set_attr "type" "int2,multi,load2,load4,store2,store4")
583    (set_attr "length" "2,8,2,4,2,4")])
584
585 (define_split
586   [(set (match_operand:SF 0 "register_operand" "")
587         (match_operand:SF 1 "const_double_operand" ""))]
588   "reload_completed"
589   [(set (match_dup 2) (match_dup 3))]
590   "
591 {
592   operands[2] = operand_subword (operands[0], 0, 0, SFmode);
593   operands[3] = operand_subword (operands[1], 0, 0, SFmode);
594 }")
595
596 (define_expand "movdf"
597   [(set (match_operand:DF 0 "general_operand" "")
598         (match_operand:DF 1 "general_operand" ""))]
599   ""
600   "
601 {
602   /* Everything except mem = const or mem = mem can be done easily.  */
603
604   if (GET_CODE (operands[0]) == MEM)
605     operands[1] = force_reg (DFmode, operands[1]);
606 }")
607
608 (define_insn "*movdf_insn"
609   [(set (match_operand:DF 0 "move_dest_operand" "=r,r,r,m")
610         (match_operand:DF 1 "move_double_src_operand" "r,F,m,r"))]
611   "register_operand (operands[0], DFmode) || register_operand (operands[1], DFmode)"
612   "#"
613   [(set_attr "type" "multi,multi,load8,store8")
614    (set_attr "length" "4,16,6,6")])
615
616 (define_split
617   [(set (match_operand:DF 0 "move_dest_operand" "")
618         (match_operand:DF 1 "move_double_src_operand" ""))]
619   "reload_completed"
620   [(match_dup 2)]
621   "operands[2] = gen_split_move_double (operands);")
622 \f
623 ;; Zero extension instructions.
624
625 (define_insn "zero_extendqihi2"
626   [(set (match_operand:HI 0 "register_operand" "=r,r,r")
627         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "r,T,m")))]
628   ""
629   "@
630    and3 %0,%1,%#255
631    ldub %0,%1
632    ldub %0,%1"
633   [(set_attr "type" "int4,load2,load4")
634    (set_attr "length" "4,2,4")])
635
636 (define_insn "zero_extendqisi2"
637   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
638         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "r,T,m")))]
639   ""
640   "@
641    and3 %0,%1,%#255
642    ldub %0,%1
643    ldub %0,%1"
644   [(set_attr "type" "int4,load2,load4")
645    (set_attr "length" "4,2,4")])
646
647 (define_insn "zero_extendhisi2"
648   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
649         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "r,T,m")))]
650   ""
651   "@
652    and3 %0,%1,%#65535
653    lduh %0,%1
654    lduh %0,%1"
655   [(set_attr "type" "int4,load2,load4")
656    (set_attr "length" "4,2,4")])
657 \f
658 ;; Sign extension instructions.
659 ;; ??? See v850.md.
660
661 ;; These patterns originally accepted general_operands, however, slightly
662 ;; better code is generated by only accepting register_operands, and then
663 ;; letting combine generate the lds[hb] insns.
664 ;; [This comment copied from sparc.md, I think.]
665
666 (define_expand "extendqihi2"
667   [(set (match_operand:HI 0 "register_operand" "")
668         (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
669   ""
670   "
671 {
672   rtx temp = gen_reg_rtx (SImode);
673   rtx shift_24 = GEN_INT (24);
674   int op1_subword = 0;
675   int op0_subword = 0;
676
677   if (GET_CODE (operand1) == SUBREG)
678     {
679       op1_subword = SUBREG_WORD (operand1);
680       operand1 = XEXP (operand1, 0);
681     }
682   if (GET_CODE (operand0) == SUBREG)
683     {
684       op0_subword = SUBREG_WORD (operand0);
685       operand0 = XEXP (operand0, 0);
686     }
687   emit_insn (gen_ashlsi3 (temp, gen_rtx_SUBREG (SImode, operand1,
688                                                 op1_subword),
689                           shift_24));
690   if (GET_MODE (operand0) != SImode)
691     operand0 = gen_rtx_SUBREG (SImode, operand0, op0_subword);
692   emit_insn (gen_ashrsi3 (operand0, temp, shift_24));
693   DONE;
694 }")
695
696 (define_insn "*sign_extendqihi2_insn"
697   [(set (match_operand:HI 0 "register_operand" "=r,r")
698         (sign_extend:HI (match_operand:QI 1 "memory_operand" "T,m")))]
699   ""
700   "ldb %0,%1"
701   [(set_attr "type" "load2,load4")
702    (set_attr "length" "2,4")])
703
704 (define_expand "extendqisi2"
705   [(set (match_operand:SI 0 "register_operand" "")
706         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
707   ""
708   "
709 {
710   rtx temp = gen_reg_rtx (SImode);
711   rtx shift_24 = GEN_INT (24);
712   int op1_subword = 0;
713
714   if (GET_CODE (operand1) == SUBREG)
715     {
716       op1_subword = SUBREG_WORD (operand1);
717       operand1 = XEXP (operand1, 0);
718     }
719
720   emit_insn (gen_ashlsi3 (temp, gen_rtx_SUBREG (SImode, operand1, op1_subword),
721                           shift_24));
722   emit_insn (gen_ashrsi3 (operand0, temp, shift_24));
723   DONE;
724 }")
725
726 (define_insn "*sign_extendqisi2_insn"
727   [(set (match_operand:SI 0 "register_operand" "=r,r")
728         (sign_extend:SI (match_operand:QI 1 "memory_operand" "T,m")))]
729   ""
730   "ldb %0,%1"
731   [(set_attr "type" "load2,load4")
732    (set_attr "length" "2,4")])
733
734 (define_expand "extendhisi2"
735   [(set (match_operand:SI 0 "register_operand" "")
736         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
737   ""
738   "
739 {
740   rtx temp = gen_reg_rtx (SImode);
741   rtx shift_16 = GEN_INT (16);
742   int op1_subword = 0;
743
744   if (GET_CODE (operand1) == SUBREG)
745     {
746       op1_subword = SUBREG_WORD (operand1);
747       operand1 = XEXP (operand1, 0);
748     }
749
750   emit_insn (gen_ashlsi3 (temp, gen_rtx_SUBREG (SImode, operand1, op1_subword),
751                           shift_16));
752   emit_insn (gen_ashrsi3 (operand0, temp, shift_16));
753   DONE;
754 }")
755
756 (define_insn "*sign_extendhisi2_insn"
757   [(set (match_operand:SI 0 "register_operand" "=r,r")
758         (sign_extend:SI (match_operand:HI 1 "memory_operand" "T,m")))]
759   ""
760   "ldh %0,%1"
761   [(set_attr "type" "load2,load4")
762    (set_attr "length" "2,4")])
763 \f
764 ;; Arithmetic instructions.
765
766 ; ??? Adding an alternative to split add3 of small constants into two
767 ; insns yields better instruction packing but slower code.  Adds of small
768 ; values is done a lot.
769
770 (define_insn "addsi3"
771   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
772         (plus:SI (match_operand:SI 1 "register_operand" "%0,0,r")
773                  (match_operand:SI 2 "nonmemory_operand" "r,I,J")))]
774   ""
775   "@
776    add %0,%2
777    addi %0,%#%2
778    add3 %0,%1,%#%2"
779   [(set_attr "type" "int2,int2,int4")
780    (set_attr "length" "2,2,4")])
781
782 ;(define_split
783 ;  [(set (match_operand:SI 0 "register_operand" "")
784 ;       (plus:SI (match_operand:SI 1 "register_operand" "")
785 ;                (match_operand:SI 2 "int8_operand" "")))]
786 ;  "reload_completed
787 ;   && REGNO (operands[0]) != REGNO (operands[1])
788 ;   && INT8_P (INTVAL (operands[2]))
789 ;   && INTVAL (operands[2]) != 0"
790 ;  [(set (match_dup 0) (match_dup 1))
791 ;   (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
792 ;  "")
793
794 (define_insn "adddi3"
795   [(set (match_operand:DI 0 "register_operand" "=r")
796         (plus:DI (match_operand:DI 1 "register_operand" "%0")
797                  (match_operand:DI 2 "register_operand" "r")))
798    (clobber (reg:SI 17))]
799   ""
800   "#"
801   [(set_attr "type" "multi")
802    (set_attr "length" "6")])
803
804 ;; ??? The cmp clears the condition bit.  Can we speed up somehow?
805 (define_split
806   [(set (match_operand:DI 0 "register_operand" "")
807         (plus:DI (match_operand:DI 1 "register_operand" "")
808                  (match_operand:DI 2 "register_operand" "")))
809    (clobber (match_operand 3 "" ""))]
810   "reload_completed"
811   [(parallel [(set (match_dup 3)
812                    (const_int 0))
813               (use (match_dup 4))])
814    (parallel [(set (match_dup 4)
815                    (plus:SI (match_dup 4)
816                             (plus:SI (match_dup 5)
817                                      (match_dup 3))))
818               (set (match_dup 3)
819                    (unspec [(const_int 0)] 3))])
820    (parallel [(set (match_dup 6)
821                    (plus:SI (match_dup 6)
822                             (plus:SI (match_dup 7)
823                                      (match_dup 3))))
824               (set (match_dup 3)
825                    (unspec [(const_int 0)] 3))])]
826   "
827 {
828   operands[4] = operand_subword (operands[0], (WORDS_BIG_ENDIAN != 0), 0, DImode);
829   operands[5] = operand_subword (operands[2], (WORDS_BIG_ENDIAN != 0), 0, DImode);
830   operands[6] = operand_subword (operands[0], (WORDS_BIG_ENDIAN == 0), 0, DImode);
831   operands[7] = operand_subword (operands[2], (WORDS_BIG_ENDIAN == 0), 0, DImode);
832 }")
833
834 (define_insn "*clear_c"
835   [(set (reg:SI 17)
836         (const_int 0))
837    (use (match_operand:SI 0 "register_operand" "r"))]
838   ""
839   "cmp %0,%0"
840   [(set_attr "type" "int2")
841    (set_attr "length" "2")])
842
843 (define_insn "*add_carry"
844   [(set (match_operand:SI 0 "register_operand" "=r")
845         (plus:SI (match_operand:SI 1 "register_operand" "%0")
846                  (plus:SI (match_operand:SI 2 "register_operand" "r")
847                           (reg:SI 17))))
848    (set (reg:SI 17)
849         (unspec [(const_int 0)] 3))]
850   ""
851   "addx %0,%2"
852   [(set_attr "type" "int2")
853    (set_attr "length" "2")])
854
855 (define_insn "subsi3"
856   [(set (match_operand:SI 0 "register_operand" "=r")
857         (minus:SI (match_operand:SI 1 "register_operand" "0")
858                   (match_operand:SI 2 "register_operand" "r")))]
859   ""
860   "sub %0,%2"
861   [(set_attr "type" "int2")
862    (set_attr "length" "2")])
863
864 (define_insn "subdi3"
865   [(set (match_operand:DI 0 "register_operand" "=r")
866         (minus:DI (match_operand:DI 1 "register_operand" "0")
867                   (match_operand:DI 2 "register_operand" "r")))
868    (clobber (reg:SI 17))]
869   ""
870   "#"
871   [(set_attr "type" "multi")
872    (set_attr "length" "6")])
873
874 ;; ??? The cmp clears the condition bit.  Can we speed up somehow?
875 (define_split
876   [(set (match_operand:DI 0 "register_operand" "")
877         (minus:DI (match_operand:DI 1 "register_operand" "")
878                   (match_operand:DI 2 "register_operand" "")))
879    (clobber (match_operand 3 "" ""))]
880   "reload_completed"
881   [(parallel [(set (match_dup 3)
882                    (const_int 0))
883               (use (match_dup 4))])
884    (parallel [(set (match_dup 4)
885                    (minus:SI (match_dup 4)
886                              (minus:SI (match_dup 5)
887                                        (match_dup 3))))
888               (set (match_dup 3)
889                    (unspec [(const_int 0)] 3))])
890    (parallel [(set (match_dup 6)
891                    (minus:SI (match_dup 6)
892                              (minus:SI (match_dup 7)
893                                        (match_dup 3))))
894               (set (match_dup 3)
895                    (unspec [(const_int 0)] 3))])]
896   "
897 {
898   operands[4] = operand_subword (operands[0], (WORDS_BIG_ENDIAN != 0), 0, DImode);
899   operands[5] = operand_subword (operands[2], (WORDS_BIG_ENDIAN != 0), 0, DImode);
900   operands[6] = operand_subword (operands[0], (WORDS_BIG_ENDIAN == 0), 0, DImode);
901   operands[7] = operand_subword (operands[2], (WORDS_BIG_ENDIAN == 0), 0, DImode);
902 }")
903
904 (define_insn "*sub_carry"
905   [(set (match_operand:SI 0 "register_operand" "=r")
906         (minus:SI (match_operand:SI 1 "register_operand" "%0")
907                   (minus:SI (match_operand:SI 2 "register_operand" "r")
908                             (reg:SI 17))))
909    (set (reg:SI 17)
910         (unspec [(const_int 0)] 3))]
911   ""
912   "subx %0,%2"
913   [(set_attr "type" "int2")
914    (set_attr "length" "2")])
915 \f
916 ; Multiply/Divide instructions.
917
918 (define_insn "mulhisi3"
919   [(set (match_operand:SI 0 "register_operand" "=r")
920         (mult:SI (sign_extend:SI (match_operand:HI 1 "register_operand" "r"))
921                  (sign_extend:SI (match_operand:HI 2 "register_operand" "r"))))]
922   ""
923   "mullo %1,%2\;mvfacmi %0"
924   [(set_attr "type" "multi")
925    (set_attr "length" "4")])
926
927 (define_insn "mulsi3"
928   [(set (match_operand:SI 0 "register_operand" "=r")
929         (mult:SI (match_operand:SI 1 "register_operand" "%0")
930                  (match_operand:SI 2 "register_operand" "r")))]
931   ""
932   "mul %0,%2"
933   [(set_attr "type" "mul2")
934    (set_attr "length" "2")])
935
936 (define_insn "divsi3"
937   [(set (match_operand:SI 0 "register_operand" "=r")
938         (div:SI (match_operand:SI 1 "register_operand" "0")
939                 (match_operand:SI 2 "register_operand" "r")))]
940   ""
941   "div %0,%2"
942   [(set_attr "type" "div4")
943    (set_attr "length" "4")])
944
945 (define_insn "udivsi3"
946   [(set (match_operand:SI 0 "register_operand" "=r")
947         (udiv:SI (match_operand:SI 1 "register_operand" "0")
948                  (match_operand:SI 2 "register_operand" "r")))]
949   ""
950   "divu %0,%2"
951   [(set_attr "type" "div4")
952    (set_attr "length" "4")])
953
954 (define_insn "modsi3"
955   [(set (match_operand:SI 0 "register_operand" "=r")
956         (mod:SI (match_operand:SI 1 "register_operand" "0")
957                 (match_operand:SI 2 "register_operand" "r")))]
958   ""
959   "rem %0,%2"
960   [(set_attr "type" "div4")
961    (set_attr "length" "4")])
962
963 (define_insn "umodsi3"
964   [(set (match_operand:SI 0 "register_operand" "=r")
965         (umod:SI (match_operand:SI 1 "register_operand" "0")
966                  (match_operand:SI 2 "register_operand" "r")))]
967   ""
968   "remu %0,%2"
969   [(set_attr "type" "div4")
970    (set_attr "length" "4")])
971 \f
972 ;; Boolean instructions.
973 ;;
974 ;; We don't define the DImode versions as expand_binop does a good enough job.
975 ;; And if it doesn't it should be fixed.
976
977 (define_insn "andsi3"
978   [(set (match_operand:SI 0 "register_operand" "=r,r")
979         (and:SI (match_operand:SI 1 "register_operand" "%0,r")
980                 (match_operand:SI 2 "nonmemory_operand" "r,K")))]
981   ""
982   "@
983    and %0,%2
984    and3 %0,%1,%#%2\\t; %X2"
985   [(set_attr "type" "int2,int4")
986    (set_attr "length" "2,4")])
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 "nonmemory_operand" "r,K")))]
992   ""
993   "@
994    or %0,%2
995    or3 %0,%1,%#%2\\t; %X2"
996   [(set_attr "type" "int2,int4")
997    (set_attr "length" "2,4")])
998
999 (define_insn "xorsi3"
1000   [(set (match_operand:SI 0 "register_operand" "=r,r")
1001         (xor:SI (match_operand:SI 1 "register_operand" "%0,r")
1002                 (match_operand:SI 2 "nonmemory_operand" "r,K")))]
1003   ""
1004   "@
1005    xor %0,%2
1006    xor3 %0,%1,%#%2\\t; %X2"
1007   [(set_attr "type" "int2,int4")
1008    (set_attr "length" "2,4")])
1009
1010 (define_insn "negsi2"
1011   [(set (match_operand:SI 0 "register_operand" "=r")
1012         (neg:SI (match_operand:SI 1 "register_operand" "r")))]
1013   ""
1014   "neg %0,%1"
1015   [(set_attr "type" "int2")
1016    (set_attr "length" "2")])
1017
1018 (define_insn "one_cmplsi2"
1019   [(set (match_operand:SI 0 "register_operand" "=r")
1020         (not:SI (match_operand:SI 1 "register_operand" "r")))]
1021   ""
1022   "not %0,%1"
1023   [(set_attr "type" "int2")
1024    (set_attr "length" "2")])
1025 \f
1026 ;; Shift instructions.
1027
1028 (define_insn "ashlsi3"
1029   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1030         (ashift:SI (match_operand:SI 1 "register_operand" "0,0,r")
1031                    (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1032   ""
1033   "@
1034    sll %0,%2
1035    slli %0,%#%2
1036    sll3 %0,%1,%#%2"
1037   [(set_attr "type" "shift2,shift2,shift4")
1038    (set_attr "length" "2,2,4")])
1039
1040 (define_insn "ashrsi3"
1041   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1042         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
1043                      (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1044   ""
1045   "@
1046    sra %0,%2
1047    srai %0,%#%2
1048    sra3 %0,%1,%#%2"
1049   [(set_attr "type" "shift2,shift2,shift4")
1050    (set_attr "length" "2,2,4")])
1051
1052 (define_insn "lshrsi3"
1053   [(set (match_operand:SI 0 "register_operand" "=r,r,r")
1054         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,0,r")
1055                      (match_operand:SI 2 "reg_or_uint16_operand" "r,O,K")))]
1056   ""
1057   "@
1058    srl %0,%2
1059    srli %0,%#%2
1060    srl3 %0,%1,%#%2"
1061   [(set_attr "type" "shift2,shift2,shift4")
1062    (set_attr "length" "2,2,4")])
1063 \f
1064 ;; Compare instructions.
1065 ;; This controls RTL generation and register allocation.
1066
1067 ;; We generate RTL for comparisons and branches by having the cmpxx 
1068 ;; patterns store away the operands.  Then the bcc patterns
1069 ;; emit RTL for both the compare and the branch.
1070 ;;
1071 ;; On the m32r it is more efficient to use the bxxz instructions and
1072 ;; thus merge the compare and branch into one instruction, so they are
1073 ;; preferred.
1074
1075 (define_expand "cmpsi"
1076   [(set (reg:SI 17)
1077         (compare:SI (match_operand:SI 0 "register_operand" "")
1078                     (match_operand:SI 1 "nonmemory_operand" "")))]
1079   ""
1080   "
1081 {
1082   m32r_compare_op0 = operands[0];
1083   m32r_compare_op1 = operands[1];
1084   DONE;
1085 }")
1086
1087
1088 ;; The cmp_xxx_insn patterns set the condition bit to the result of the
1089 ;; comparison.  There isn't a "compare equal" instruction so cmp_eqsi_insn
1090 ;; is quite inefficient.  However, it is rarely used.
1091
1092 (define_insn "cmp_eqsi_insn"
1093   [(set (reg:SI 17)
1094         (eq:SI (match_operand:SI 0 "register_operand" "r,r")
1095                (match_operand:SI 1 "reg_or_cmp_int16_operand" "r,P")))
1096    (clobber (match_scratch:SI 2 "=&r,&r"))]
1097   ""
1098   "*
1099 {
1100   if (which_alternative == 0)
1101     {
1102          return \"mv %2,%0\;sub %2,%1\;cmpui %2,#1\";
1103     }
1104   else
1105     {
1106         if (INTVAL (operands [1]) == 0)
1107           return \"cmpui %0, #1\";
1108         else if (REGNO (operands [2]) == REGNO (operands [0]))
1109           return \"addi %0,%#%N1\;cmpui %2,#1\";
1110         else
1111           return \"add3 %2,%0,%#%N1\;cmpui %2,#1\";
1112     }
1113 }"
1114   [(set_attr "type" "multi,multi")
1115    (set_attr "length" "8,8")])
1116
1117 (define_insn "cmp_ltsi_insn"
1118   [(set (reg:SI 17)
1119         (lt:SI (match_operand:SI 0 "register_operand" "r,r")
1120                (match_operand:SI 1 "reg_or_int16_operand" "r,J")))]
1121   ""
1122   "@
1123    cmp %0,%1
1124    cmpi %0,%#%1"
1125   [(set_attr "type" "int2,int4")
1126    (set_attr "length" "2,4")])
1127
1128 (define_insn "cmp_ltusi_insn"
1129   [(set (reg:SI 17)
1130         (ltu:SI (match_operand:SI 0 "register_operand" "r,r")
1131                 (match_operand:SI 1 "reg_or_uint16_operand" "r,K")))]
1132   ""
1133   "@
1134    cmpu %0,%1
1135    cmpui %0,%#%1"
1136   [(set_attr "type" "int2,int4")
1137    (set_attr "length" "2,4")])
1138
1139 ;; reg == small constant comparisons are best handled by putting the result
1140 ;; of the comparison in a tmp reg and then using beqz/bnez.
1141 ;; ??? The result register doesn't contain 0/STORE_FLAG_VALUE,
1142 ;; it contains 0/non-zero.
1143
1144 (define_insn "cmp_ne_small_const_insn"
1145   [(set (match_operand:SI 0 "register_operand" "=r,r")
1146         (ne:SI (match_operand:SI 1 "register_operand" "0,r")
1147                (match_operand:SI 2 "cmp_int16_operand" "N,P")))]
1148   ""
1149   "@
1150    addi %0,%#%N2
1151    add3 %0,%1,%#%N2"
1152   [(set_attr "type" "int2,int4")
1153    (set_attr "length" "2,4")])
1154 \f
1155 ;; These control RTL generation for conditional jump insns.
1156
1157 (define_expand "beq"
1158   [(set (pc)
1159         (if_then_else (match_dup 1)
1160                       (label_ref (match_operand 0 "" ""))
1161                       (pc)))]
1162   ""
1163   "
1164 {
1165   operands[1] = gen_compare ((int)EQ, m32r_compare_op0, m32r_compare_op1, FALSE);
1166 }")
1167
1168 (define_expand "bne"
1169   [(set (pc)
1170         (if_then_else (match_dup 1)
1171                       (label_ref (match_operand 0 "" ""))
1172                       (pc)))]
1173   ""
1174   "
1175 {
1176   operands[1] = gen_compare ((int)NE, m32r_compare_op0, m32r_compare_op1, FALSE);
1177 }")
1178
1179 (define_expand "bgt"
1180   [(set (pc)
1181         (if_then_else (match_dup 1)
1182                       (label_ref (match_operand 0 "" ""))
1183                       (pc)))]
1184   ""
1185   "
1186 {
1187   operands[1] = gen_compare ((int)GT, m32r_compare_op0, m32r_compare_op1, FALSE);
1188 }")
1189
1190 (define_expand "ble"
1191   [(set (pc)
1192         (if_then_else (match_dup 1)
1193                       (label_ref (match_operand 0 "" ""))
1194                       (pc)))]
1195   ""
1196   "
1197 {
1198   operands[1] = gen_compare ((int)LE, m32r_compare_op0, m32r_compare_op1, FALSE);
1199 }")
1200
1201 (define_expand "bge"
1202   [(set (pc)
1203         (if_then_else (match_dup 1)
1204                       (label_ref (match_operand 0 "" ""))
1205                       (pc)))]
1206   ""
1207   "
1208 {
1209   operands[1] = gen_compare ((int)GE, m32r_compare_op0, m32r_compare_op1, FALSE);
1210 }")
1211
1212 (define_expand "blt"
1213   [(set (pc)
1214         (if_then_else (match_dup 1)
1215                       (label_ref (match_operand 0 "" ""))
1216                       (pc)))]
1217   ""
1218   "
1219 {
1220   operands[1] = gen_compare ((int)LT, m32r_compare_op0, m32r_compare_op1, FALSE);
1221 }")
1222
1223 (define_expand "bgtu"
1224   [(set (pc)
1225         (if_then_else (match_dup 1)
1226                       (label_ref (match_operand 0 "" ""))
1227                       (pc)))]
1228   ""
1229   "
1230 {
1231   operands[1] = gen_compare ((int)GTU, m32r_compare_op0, m32r_compare_op1, FALSE);
1232 }")
1233
1234 (define_expand "bleu"
1235   [(set (pc)
1236         (if_then_else (match_dup 1)
1237                       (label_ref (match_operand 0 "" ""))
1238                       (pc)))]
1239   ""
1240   "
1241 {
1242   operands[1] = gen_compare ((int)LEU, m32r_compare_op0, m32r_compare_op1, FALSE);
1243 }")
1244
1245 (define_expand "bgeu"
1246   [(set (pc)
1247         (if_then_else (match_dup 1)
1248                       (label_ref (match_operand 0 "" ""))
1249                       (pc)))]
1250   ""
1251   "
1252 {
1253   operands[1] = gen_compare ((int)GEU, m32r_compare_op0, m32r_compare_op1, FALSE);
1254 }")
1255
1256 (define_expand "bltu"
1257   [(set (pc)
1258         (if_then_else (match_dup 1)
1259                       (label_ref (match_operand 0 "" ""))
1260                       (pc)))]
1261   ""
1262   "
1263 {
1264   operands[1] = gen_compare ((int)LTU, m32r_compare_op0, m32r_compare_op1, FALSE);
1265 }")
1266
1267 ;; Now match both normal and inverted jump.
1268
1269 (define_insn "*branch_insn"
1270   [(set (pc)
1271         (if_then_else (match_operator 1 "eqne_comparison_operator"
1272                                       [(reg 17) (const_int 0)])
1273                       (label_ref (match_operand 0 "" ""))
1274                       (pc)))]
1275   ""
1276   "*
1277 {
1278   static char instruction[40];
1279   sprintf (instruction, \"%s%s %%l0\",
1280            (GET_CODE (operands[1]) == NE) ? \"bc\" : \"bnc\",
1281            (get_attr_length (insn) == 2) ? \".s\" : \"\");
1282   return instruction;
1283 }"
1284   [(set_attr "type" "branch")
1285    ; We use 400/800 instead of 512,1024 to account for inaccurate insn
1286    ; lengths and insn alignments that are complex to track.
1287    ; It's not important that we be hyper-precise here.  It may be more
1288    ; important blah blah blah when the chip supports parallel execution
1289    ; blah blah blah but until then blah blah blah this is simple and
1290    ; suffices.
1291    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1292                                                  (const_int 400))
1293                                            (const_int 800))
1294                                       (const_int 2)
1295                                       (const_int 4)))])
1296
1297 (define_insn "*rev_branch_insn"
1298   [(set (pc)
1299         (if_then_else (match_operator 1 "eqne_comparison_operator"
1300                                       [(reg 17) (const_int 0)])
1301                       (pc)
1302                       (label_ref (match_operand 0 "" ""))))]
1303   ;"REVERSIBLE_CC_MODE (GET_MODE (XEXP (operands[1], 0)))"
1304   ""
1305   "*
1306 {
1307   static char instruction[40];
1308   sprintf (instruction, \"%s%s %%l0\",
1309            (GET_CODE (operands[1]) == EQ) ? \"bc\" : \"bnc\",
1310            (get_attr_length (insn) == 2) ? \".s\" : \"\");
1311   return instruction;
1312 }"
1313   [(set_attr "type" "branch")
1314    ; We use 400/800 instead of 512,1024 to account for inaccurate insn
1315    ; lengths and insn alignments that are complex to track.
1316    ; It's not important that we be hyper-precise here.  It may be more
1317    ; important blah blah blah when the chip supports parallel execution
1318    ; blah blah blah but until then blah blah blah this is simple and
1319    ; suffices.
1320    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1321                                                  (const_int 400))
1322                                            (const_int 800))
1323                                       (const_int 2)
1324                                       (const_int 4)))])
1325
1326 ; reg/reg compare and branch insns
1327
1328 (define_insn "*reg_branch_insn"
1329   [(set (pc)
1330         (if_then_else (match_operator 1 "eqne_comparison_operator"
1331                                       [(match_operand:SI 2 "register_operand" "r")
1332                                        (match_operand:SI 3 "register_operand" "r")])
1333                       (label_ref (match_operand 0 "" ""))
1334                       (pc)))]
1335   ""
1336   "*
1337 {
1338   /* Is branch target reachable with beq/bne?  */
1339   if (get_attr_length (insn) == 4)
1340     {
1341       if (GET_CODE (operands[1]) == EQ)
1342         return \"beq %2,%3,%l0\";
1343       else
1344         return \"bne %2,%3,%l0\";
1345     }
1346   else
1347     {
1348       if (GET_CODE (operands[1]) == EQ)
1349         return \"bne %2,%3,1f\;bra %l0\;1:\";
1350       else
1351         return \"beq %2,%3,1f\;bra %l0\;1:\";
1352     }
1353 }"
1354   [(set_attr "type" "branch")
1355   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1356   ; which is complex to track and inaccurate length specs.
1357    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1358                                                  (const_int 25000))
1359                                            (const_int 50000))
1360                                       (const_int 4)
1361                                       (const_int 8)))])
1362
1363 (define_insn "*rev_reg_branch_insn"
1364   [(set (pc)
1365         (if_then_else (match_operator 1 "eqne_comparison_operator"
1366                                       [(match_operand:SI 2 "register_operand" "r")
1367                                        (match_operand:SI 3 "register_operand" "r")])
1368                       (pc)
1369                       (label_ref (match_operand 0 "" ""))))]
1370   ""
1371   "*
1372 {
1373   /* Is branch target reachable with beq/bne?  */
1374   if (get_attr_length (insn) == 4)
1375     {
1376       if (GET_CODE (operands[1]) == NE)
1377         return \"beq %2,%3,%l0\";
1378       else
1379         return \"bne %2,%3,%l0\";
1380     }
1381   else
1382     {
1383       if (GET_CODE (operands[1]) == NE)
1384         return \"bne %2,%3,1f\;bra %l0\;1:\";
1385       else
1386         return \"beq %2,%3,1f\;bra %l0\;1:\";
1387     }
1388 }"
1389   [(set_attr "type" "branch")
1390   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1391   ; which is complex to track and inaccurate length specs.
1392    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1393                                                  (const_int 25000))
1394                                            (const_int 50000))
1395                                       (const_int 4)
1396                                       (const_int 8)))])
1397
1398 ; reg/zero compare and branch insns
1399
1400 (define_insn "*zero_branch_insn"
1401   [(set (pc)
1402         (if_then_else (match_operator 1 "signed_comparison_operator"
1403                                       [(match_operand:SI 2 "register_operand" "r")
1404                                        (const_int 0)])
1405                       (label_ref (match_operand 0 "" ""))
1406                       (pc)))]
1407   ""
1408   "*
1409 {
1410   char *br,*invbr;
1411   char asmtext[40];
1412
1413   switch (GET_CODE (operands[1]))
1414     {
1415       case EQ : br = \"eq\"; invbr = \"ne\"; break;
1416       case NE : br = \"ne\"; invbr = \"eq\"; break;
1417       case LE : br = \"le\"; invbr = \"gt\"; break;
1418       case GT : br = \"gt\"; invbr = \"le\"; break;
1419       case LT : br = \"lt\"; invbr = \"ge\"; break;
1420       case GE : br = \"ge\"; invbr = \"lt\"; break;
1421     }
1422
1423   /* Is branch target reachable with bxxz?  */
1424   if (get_attr_length (insn) == 4)
1425     {
1426       sprintf (asmtext, \"b%sz %%2,%%l0\", br);
1427       output_asm_insn (asmtext, operands);
1428     }
1429   else
1430     {
1431       sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", invbr);
1432       output_asm_insn (asmtext, operands);
1433     }
1434   return \"\";
1435 }"
1436   [(set_attr "type" "branch")
1437   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1438   ; which is complex to track and inaccurate length specs.
1439    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1440                                                  (const_int 25000))
1441                                            (const_int 50000))
1442                                       (const_int 4)
1443                                       (const_int 8)))])
1444
1445 (define_insn "*rev_zero_branch_insn"
1446   [(set (pc)
1447         (if_then_else (match_operator 1 "eqne_comparison_operator"
1448                                       [(match_operand:SI 2 "register_operand" "r")
1449                                        (const_int 0)])
1450                       (pc)
1451                       (label_ref (match_operand 0 "" ""))))]
1452   ""
1453   "*
1454 {
1455   char *br,*invbr;
1456   char asmtext[40];
1457
1458   switch (GET_CODE (operands[1]))
1459     {
1460       case EQ : br = \"eq\"; invbr = \"ne\"; break;
1461       case NE : br = \"ne\"; invbr = \"eq\"; break;
1462       case LE : br = \"le\"; invbr = \"gt\"; break;
1463       case GT : br = \"gt\"; invbr = \"le\"; break;
1464       case LT : br = \"lt\"; invbr = \"ge\"; break;
1465       case GE : br = \"ge\"; invbr = \"lt\"; break;
1466     }
1467
1468   /* Is branch target reachable with bxxz?  */
1469   if (get_attr_length (insn) == 4)
1470     {
1471       sprintf (asmtext, \"b%sz %%2,%%l0\", invbr);
1472       output_asm_insn (asmtext, operands);
1473     }
1474   else
1475     {
1476       sprintf (asmtext, \"b%sz %%2,1f\;bra %%l0\;1:\", br);
1477       output_asm_insn (asmtext, operands);
1478     }
1479   return \"\";
1480 }"
1481   [(set_attr "type" "branch")
1482   ; We use 25000/50000 instead of 32768/65536 to account for slot filling
1483   ; which is complex to track and inaccurate length specs.
1484    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1485                                                  (const_int 25000))
1486                                            (const_int 50000))
1487                                       (const_int 4)
1488                                       (const_int 8)))])
1489 \f
1490 ;; Unconditional and other jump instructions.
1491
1492 (define_insn "jump"
1493   [(set (pc) (label_ref (match_operand 0 "" "")))]
1494   ""
1495   "bra %l0"
1496   [(set_attr "type" "uncond_branch")
1497    (set (attr "length") (if_then_else (ltu (plus (minus (match_dup 0) (pc))
1498                                                  (const_int 400))
1499                                            (const_int 800))
1500                                       (const_int 2)
1501                                       (const_int 4)))])
1502
1503 (define_insn "indirect_jump"
1504   [(set (pc) (match_operand:SI 0 "address_operand" "p"))]
1505   ""
1506   "jmp %a0"
1507   [(set_attr "type" "uncond_branch")
1508    (set_attr "length" "2")])
1509  
1510 (define_insn "tablejump"
1511   [(set (pc) (match_operand:SI 0 "address_operand" "p"))
1512    (use (label_ref (match_operand 1 "" "")))]
1513   ""
1514   "jmp %a0"
1515   [(set_attr "type" "uncond_branch")
1516    (set_attr "length" "2")])
1517
1518 (define_expand "call"
1519   ;; operands[1] is stack_size_rtx
1520   ;; operands[2] is next_arg_register
1521   [(parallel [(call (match_operand:SI 0 "call_operand" "")
1522                     (match_operand 1 "" ""))
1523              (clobber (reg:SI 14))])]
1524   ""
1525   "")
1526
1527 (define_insn "*call_via_reg"
1528   [(call (mem:SI (match_operand:SI 0 "register_operand" "r"))
1529          (match_operand 1 "" ""))
1530    (clobber (reg:SI 14))]
1531   ""
1532   "jl %0"
1533   [(set_attr "type" "call")
1534    (set_attr "length" "2")])
1535
1536 (define_insn "*call_via_label"
1537   [(call (mem:SI (match_operand:SI 0 "call_address_operand" ""))
1538          (match_operand 1 "" ""))
1539    (clobber (reg:SI 14))]
1540   ""
1541   "*
1542 {
1543   int call26_p = call26_operand (operands[0], FUNCTION_MODE);
1544
1545   if (! call26_p)
1546     {
1547       /* We may not be able to reach with a `bl' insn so punt and leave it to
1548          the linker.
1549          We do this here, rather than doing a force_reg in the define_expand
1550          so these insns won't be separated, say by scheduling, thus simplifying
1551          the linker.  */
1552       return \"seth r14,%T0\;add3 r14,r14,%B0\;jl r14\";
1553     }
1554   else
1555     return \"bl %0\";
1556 }"
1557   [(set_attr "type" "call")
1558    (set (attr "length")
1559         (if_then_else (eq (symbol_ref "call26_operand (operands[0], FUNCTION_MODE)")
1560                           (const_int 0))
1561                       (const_int 12) ; 10 + 2 for nop filler
1562                       ; The return address must be on a 4 byte boundary so
1563                       ; there's no point in using a value of 2 here.  A 2 byte
1564                       ; insn may go in the left slot but we currently can't
1565                       ; use such knowledge.
1566                       (const_int 4)))])
1567
1568 (define_expand "call_value"
1569   ;; operand 2 is stack_size_rtx
1570   ;; operand 3 is next_arg_register
1571   [(parallel [(set (match_operand 0 "register_operand" "=r")
1572                    (call (match_operand:SI 1 "call_operand" "")
1573                          (match_operand 2 "" "")))
1574              (clobber (reg:SI 14))])]
1575   ""
1576   "")
1577
1578 (define_insn "*call_value_via_reg"
1579   [(set (match_operand 0 "register_operand" "=r")
1580         (call (mem:SI (match_operand:SI 1 "register_operand" "r"))
1581               (match_operand 2 "" "")))
1582    (clobber (reg:SI 14))]
1583   ""
1584   "jl %1"
1585   [(set_attr "type" "call")
1586    (set_attr "length" "2")])
1587
1588 (define_insn "*call_value_via_label"
1589   [(set (match_operand 0 "register_operand" "=r")
1590         (call (mem:SI (match_operand:SI 1 "call_address_operand" ""))
1591               (match_operand 2 "" "")))
1592    (clobber (reg:SI 14))]
1593   ""
1594   "*
1595 {
1596   int call26_p = call26_operand (operands[1], FUNCTION_MODE);
1597
1598   if (! call26_p)
1599     {
1600       /* We may not be able to reach with a `bl' insn so punt and leave it to
1601          the linker.
1602          We do this here, rather than doing a force_reg in the define_expand
1603          so these insns won't be separated, say by scheduling, thus simplifying
1604          the linker.  */
1605       return \"seth r14,%T1\;add3 r14,r14,%B1\;jl r14\";
1606     }
1607   else
1608     return \"bl %1\";
1609 }"
1610   [(set_attr "type" "call")
1611    (set (attr "length")
1612         (if_then_else (eq (symbol_ref "call26_operand (operands[1], FUNCTION_MODE)")
1613                           (const_int 0))
1614                       (const_int 12) ; 10 + 2 for nop filler
1615                       ; The return address must be on a 4 byte boundary so
1616                       ; there's no point in using a value of 2 here.  A 2 byte
1617                       ; insn may go in the left slot but we currently can't
1618                       ; use such knowledge.
1619                       (const_int 4)))])
1620 \f
1621 (define_insn "nop"
1622   [(const_int 0)]
1623   ""
1624   "nop"
1625   [(set_attr "type" "int2")
1626    (set_attr "length" "2")])
1627
1628 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
1629 ;; all of memory.  This blocks insns from being moved across this point.
1630
1631 (define_insn "blockage"
1632   [(unspec_volatile [(const_int 0)] 0)]
1633   ""
1634   "")
1635
1636 ;; Special pattern to flush the icache.
1637
1638 (define_insn "flush_icache"
1639   [(unspec_volatile [(match_operand 0 "memory_operand" "m")] 0)]
1640   ""
1641   "* return \"nop ; flush-icache\";"
1642   [(set_attr "type" "int2")
1643    (set_attr "length" "2")])
1644 \f
1645 ;; Conditional move instructions
1646 ;; Based on those done for the d10v
1647
1648
1649 (define_expand "movsicc"
1650   [
1651    (set (match_operand:SI 0 "register_operand" "r")
1652         (if_then_else:SI (match_operand 1 "" "")
1653                          (match_operand:SI 2 "conditional_move_operand" "O")
1654                          (match_operand:SI 3 "conditional_move_operand" "O")
1655         )
1656    )
1657   ]
1658   ""
1659   "
1660 {
1661   if (! zero_and_one (operands [2], operands [3]))
1662     FAIL;
1663
1664   /* Generate the comparision that will set the carry flag.  */
1665   operands[1] = gen_compare ((int)GET_CODE (operands[1]), m32r_compare_op0,
1666                              m32r_compare_op1, TRUE);
1667
1668   /* See other movsicc pattern below for reason why.  */
1669   emit_insn (gen_blockage());
1670 }")
1671
1672 ;; Generate the conditional instructions based on how the carry flag is examined.
1673 (define_insn "*movsicc_internal"
1674   [(set (match_operand:SI 0 "register_operand" "r")
1675         (if_then_else:SI (match_operand 1 "carry_compare_operand" "")
1676                          (match_operand:SI 2 "conditional_move_operand" "O")
1677                          (match_operand:SI 3 "conditional_move_operand" "O")
1678         )
1679    )]
1680   "zero_and_one (operands [2], operands[3])"
1681   "* return emit_cond_move (operands, insn);"
1682   [(set_attr "type" "multi")
1683    (set_attr "length" "8")
1684   ]
1685 )
1686
1687 (define_insn "movcc_insn"
1688   [(set (match_operand:SI 0 "register_operand" "=r")
1689         (reg:SI 17))]
1690   ""
1691   "mvfc %0, cbr"
1692   [(set_attr "type" "misc")
1693    (set_attr "length" "2")]
1694 )
1695
1696 \f
1697 ;; Split up troublesome insns for better scheduling.
1698 \f
1699 ;; Peepholes go at the end.
1700
1701 ;; ??? Setting the type attribute may not be useful, but for completeness
1702 ;; we do it.
1703
1704 (define_peephole
1705   [(set (mem:SI (plus:SI (match_operand:SI 0 "register_operand" "r")
1706                          (const_int 4)))
1707         (match_operand:SI 1 "register_operand" "r"))]
1708   "0 && dead_or_set_p (insn, operands[0])"
1709   "st %1,@+%0"
1710   [(set_attr "type" "store2")
1711    (set_attr "length" "2")])
1712
1713 ;; This case is triggered by compiling this code:
1714 ;; 
1715 ;; extern void sub(int *);
1716 ;; void main (void)
1717 ;; {
1718 ;;   int i=2,j=3,k;
1719 ;;   while (i < j)  sub(&k);
1720 ;;   i = j / k;
1721 ;;   sub(&i);
1722 ;;   i = j - k;
1723 ;;   sub(&i);
1724 ;; }
1725 ;;
1726 ;; Without the peephole the following assembler is generated for the
1727 ;; divide and subtract expressions:
1728 ;;
1729 ;;         div r5,r4     
1730 ;;         mv r4,r5      
1731 ;;         st r4,@(4,sp) 
1732 ;;         bl sub
1733 ;; 
1734 ;; Simialr code is produced for the subtract expression.  With this
1735 ;; peephole the redundant move is eliminated.
1736 ;;
1737 ;; This optimisation onbly works if PRESERVE_DEATH_INFO_REGNO_P is
1738 ;; defined in m32r.h
1739
1740 (define_peephole
1741   [(set (match_operand:SI 0 "register_operand" "r")
1742         (match_operand:SI 1 "register_operand" "r")
1743    )
1744    (set (mem:SI (plus: SI (match_operand:SI 2 "register_operand" "r")
1745                 (match_operand:SI 3 "immediate_operand" "J")))
1746         (match_dup 0)
1747    )
1748   ]
1749   "0 && dead_or_set_p (insn, operands [0])"
1750   "st %1,@(%3,%2)"
1751   [(set_attr "type" "store4")
1752    (set_attr "length" "4")
1753   ]
1754 )
1755
1756 ;; Block moves, see m32r.c for more details.
1757 ;; Argument 0 is the destination
1758 ;; Argument 1 is the source
1759 ;; Argument 2 is the length
1760 ;; Argument 3 is the alignment
1761
1762 (define_expand "movstrsi"
1763   [(parallel [(set (match_operand:BLK 0 "general_operand" "")
1764                    (match_operand:BLK 1 "general_operand" ""))
1765               (use (match_operand:SI  2 "immediate_operand" ""))
1766               (use (match_operand:SI  3 "immediate_operand" ""))])]
1767   ""
1768   "
1769 {
1770   if (operands[0])              /* avoid unused code messages */
1771     {
1772       m32r_expand_block_move (operands);
1773       DONE;
1774     }
1775 }")
1776
1777 ;; Insn generated by block moves
1778
1779 (define_insn "movstrsi_internal"
1780   [(set (mem:BLK (match_operand:SI 0 "register_operand" "r"))   ;; destination
1781         (mem:BLK (match_operand:SI 1 "register_operand" "r")))  ;; source
1782    (use (match_operand:SI 2 "m32r_block_immediate_operand" "J"));; # bytes to move
1783    (set (match_dup 0) (plus:SI (match_dup 0) (minus:SI (match_dup 2) (const_int 4))))
1784    (set (match_dup 1) (plus:SI (match_dup 1) (match_dup 2)))
1785    (clobber (match_scratch:SI 3 "=&r"))                         ;; temp 1
1786    (clobber (match_scratch:SI 4 "=&r"))]                        ;; temp 2
1787   ""
1788   "* return m32r_output_block_move (insn, operands);"
1789   [(set_attr "type"     "store8")
1790    (set_attr "length"   "72")]) ;; Maximum