OSDN Git Service

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