OSDN Git Service

* config/mips/mips.c (machine_function): Add new fields:
[pf3gnuchains/gcc-fork.git] / gcc / config / mips / mips.md
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;;  1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
5 ;;  Changes by       Michael Meissner, meissner@osf.org
6 ;;  64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 ;;  Brendan Eich, brendan@microunity.com.
8
9 ;; This file is part of GNU CC.
10
11 ;; GNU CC is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU CC is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU CC; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;; ??? Currently does not have define_function_unit support for the R8000.
27 ;; Must include new entries for fmadd in addition to existing entries.
28
29 (define_constants
30   [(UNSPEC_LOAD_DF_LOW           0)
31    (UNSPEC_LOAD_DF_HIGH          1)
32    (UNSPEC_STORE_DF_HIGH         2)
33    (UNSPEC_GET_FNADDR            4)
34    (UNSPEC_BLOCKAGE              6)
35    (UNSPEC_CPRESTORE             8)
36    (UNSPEC_EH_RECEIVER          10)
37    (UNSPEC_EH_RETURN            11)
38    (UNSPEC_CONSTTABLE_QI        12)
39    (UNSPEC_CONSTTABLE_HI        13)
40    (UNSPEC_CONSTTABLE_SI        14)
41    (UNSPEC_CONSTTABLE_DI        15)
42    (UNSPEC_CONSTTABLE_SF        16)
43    (UNSPEC_CONSTTABLE_DF        17)
44    (UNSPEC_ALIGN_2              18)
45    (UNSPEC_ALIGN_4              19)
46    (UNSPEC_ALIGN_8              20)
47    (UNSPEC_HIGH                 22)
48    (UNSPEC_LWL                  23)
49    (UNSPEC_LWR                  24)
50    (UNSPEC_SWL                  25)
51    (UNSPEC_SWR                  26)
52    (UNSPEC_LDL                  27)
53    (UNSPEC_LDR                  28)
54    (UNSPEC_SDL                  29)
55    (UNSPEC_SDR                  30)
56
57    ;; Constants used in relocation unspecs.  RELOC_GOT_PAGE and RELOC_GOT_DISP
58    ;; are really only available for n32 and n64.  However, it is convenient
59    ;; to reuse them for SVR4 PIC, where they represent the local and global
60    ;; forms of R_MIPS_GOT16.
61    (RELOC_GPREL16               100)
62    (RELOC_GOT_HI                101)
63    (RELOC_GOT_LO                102)
64    (RELOC_GOT_PAGE              103)
65    (RELOC_GOT_DISP              104)
66    (RELOC_CALL16                105)
67    (RELOC_CALL_HI               106)
68    (RELOC_CALL_LO               107)
69    (RELOC_LOADGP_HI             108)
70    (RELOC_LOADGP_LO             109)])
71 \f
72
73 ;; ....................
74 ;;
75 ;;      Attributes
76 ;;
77 ;; ....................
78
79 ;; For jal instructions, this attribute is DIRECT when the target address
80 ;; is symbolic and INDIRECT when it is a register.
81 (define_attr "jal" "unset,direct,indirect"
82   (const_string "unset"))
83
84 ;; True for multi-instruction jal macros.  jal is always a macro
85 ;; in SVR4 PIC since it includes an instruction to restore $gp.
86 ;; Direct jals are also macros in NewABI PIC since they load the
87 ;; target address into $25.
88 (define_attr "jal_macro" "no,yes"
89   (cond [(eq_attr "jal" "direct")
90          (symbol_ref "TARGET_ABICALLS != 0")
91          (eq_attr "jal" "indirect")
92          (symbol_ref "(TARGET_ABICALLS && !TARGET_NEWABI) != 0")]
93         (const_string "no")))
94
95 ;; Classification of each insn.
96 ;; branch       conditional branch
97 ;; jump         unconditional jump
98 ;; call         unconditional call
99 ;; load         load instruction(s)
100 ;; store        store instruction(s)
101 ;; prefetch     memory prefetch
102 ;; move         data movement within same register set
103 ;; xfer         transfer to/from coprocessor
104 ;; hilo         transfer of hi/lo registers
105 ;; arith        integer arithmetic instruction
106 ;; darith       double precision integer arithmetic instructions
107 ;; const        load constant
108 ;; imul         integer multiply
109 ;; imadd        integer multiply-add
110 ;; idiv         integer divide
111 ;; icmp         integer compare
112 ;; fadd         floating point add/subtract
113 ;; fmul         floating point multiply
114 ;; fmadd        floating point multiply-add
115 ;; fdiv         floating point divide
116 ;; fabs         floating point absolute value
117 ;; fneg         floating point negation
118 ;; fcmp         floating point compare
119 ;; fcvt         floating point convert
120 ;; fsqrt        floating point square root
121 ;; frsqrt       floating point reciprocal square root
122 ;; multi        multiword sequence (or user asm statements)
123 ;; nop          no operation
124 (define_attr "type"
125   "unknown,branch,jump,call,load,store,prefetch,move,xfer,hilo,const,arith,darith,imul,imadd,idiv,icmp,fadd,fmul,fmadd,fdiv,fabs,fneg,fcmp,fcvt,fsqrt,frsqrt,multi,nop"
126   (cond [(eq_attr "jal" "!unset")
127          (const_string "call")]
128         (const_string "unknown")))
129
130 ;; Main data type used by the insn
131 (define_attr "mode" "unknown,none,QI,HI,SI,DI,SF,DF,FPSW" (const_string "unknown"))
132
133 ;; Is this an extended instruction in mips16 mode?
134 (define_attr "extended_mips16" "no,yes"
135   (const_string "no"))
136
137 ;; Length (in # of bytes).  A conditional branch is allowed only to a
138 ;; location within a signed 18-bit offset of the delay slot.  If that
139 ;; provides too smal a range, we use the `j' instruction.  This
140 ;; instruction takes a 28-bit value, but that value is not an offset.
141 ;; Instead, it's bitwise-ored with the high-order four bits of the
142 ;; instruction in the delay slot, which means it cannot be used to
143 ;; cross a 256MB boundary.  We could fall back back on the jr,
144 ;; instruction which allows full access to the entire address space,
145 ;; but we do not do so at present.
146
147 (define_attr "length" ""
148    (cond [(eq_attr "type" "branch")
149           (cond [(lt (abs (minus (match_dup 1) (plus (pc) (const_int 4))))
150                      (const_int 131072))
151                  (const_int 4)
152                  (ne (symbol_ref "flag_pic && ! TARGET_EMBEDDED_PIC")
153                      (const_int 0))
154                  (const_int 24)
155                  ] (const_int 12))
156           (eq_attr "type" "const")
157           (symbol_ref "mips_const_insns (operands[1]) * 4")
158           (eq_attr "type" "load")
159           (symbol_ref "mips_fetch_insns (operands[1]) * 4")
160           (eq_attr "type" "store")
161           (symbol_ref "mips_fetch_insns (operands[0]) * 4")
162           ;; In the worst case, a call macro will take 8 instructions:
163           ;;
164           ;;     lui $25,%call_hi(FOO)
165           ;;     addu $25,$25,$28
166           ;;     lw $25,%call_lo(FOO)($25)
167           ;;     nop
168           ;;     jalr $25
169           ;;     nop
170           ;;     lw $gp,X($sp)
171           ;;     nop
172           (eq_attr "jal_macro" "yes")
173           (const_int 32)
174           (and (eq_attr "extended_mips16" "yes")
175                (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
176           (const_int 8)
177           (and (eq_attr "type" "idiv")
178                (ne (symbol_ref "TARGET_CHECK_ZERO_DIV") (const_int 0)))
179           (cond [(ne (symbol_ref "TARGET_MIPS16") (const_int 0))
180                  (const_int 12)]
181                 (const_int 16))
182           ] (const_int 4)))
183
184 ;; Attribute describing the processor.  This attribute must match exactly
185 ;; with the processor_type enumeration in mips.h.
186
187 ;; Attribute describing the processor
188 ;; (define_attr "cpu" "default,r3000,r6000,r4000"
189 ;;   (const
190 ;;    (cond [(eq (symbol_ref "mips_cpu") (symbol_ref "PROCESSOR_R3000"))   (const_string "r3000")
191 ;;           (eq (symbol_ref "mips_cpu") (symbol_ref "PROCESSOR_R4000"))   (const_string "r4000")
192 ;;           (eq (symbol_ref "mips_cpu") (symbol_ref "PROCESSOR_R6000"))   (const_string "r6000")]
193 ;;          (const_string "default"))))
194
195 ;; ??? Fix everything that tests this attribute.
196 (define_attr "cpu"
197   "default,4kc,5kc,20kc,m4k,r3000,r3900,r6000,r4000,r4100,r4111,r4120,r4300,r4600,r4650,r5000,r5400,r5500,r8000,sb1,sr71000"
198   (const (symbol_ref "mips_cpu_attr")))
199
200 ;; The type of hardware hazard associated with this instruction.
201 ;; DELAY means that the next instruction cannot read the result
202 ;; of this one.  HILO means that the next two instructions cannot
203 ;; write to HI or LO.
204 (define_attr "hazard" "none,delay,hilo"
205   (cond [(and (eq_attr "type" "load")
206               (ne (symbol_ref "ISA_HAS_LOAD_DELAY") (const_int 0)))
207          (const_string "delay")
208
209          (and (eq_attr "type" "xfer")
210               (ne (symbol_ref "ISA_HAS_XFER_DELAY") (const_int 0)))
211          (const_string "delay")
212
213          (and (eq_attr "type" "fcmp")
214               (ne (symbol_ref "ISA_HAS_FCMP_DELAY") (const_int 0)))
215          (const_string "delay")
216
217          ;; The r4000 multiplication patterns include an mflo instruction.
218          (and (eq_attr "type" "imul")
219               (ne (symbol_ref "TARGET_MIPS4000") (const_int 0)))
220          (const_string "hilo")
221
222          (and (eq_attr "type" "hilo")
223               (and (eq (symbol_ref "ISA_HAS_HILO_INTERLOCKS") (const_int 0))
224                    (match_operand 1 "hilo_operand" "")))
225          (const_string "hilo")]
226         (const_string "none")))
227
228 ;; Is it a single instruction?
229 (define_attr "single_insn" "no,yes"
230   (symbol_ref "get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)"))
231
232 ;; Can the instruction be put into a delay slot?
233 (define_attr "can_delay" "no,yes"
234   (if_then_else (and (eq_attr "type" "!branch,call,jump")
235                      (and (eq_attr "hazard" "none")
236                           (eq_attr "single_insn" "yes")))
237                 (const_string "yes")
238                 (const_string "no")))
239
240 ;; Attribute defining whether or not we can use the branch-likely instructions
241
242 (define_attr "branch_likely" "no,yes"
243   (const
244    (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
245                  (const_string "yes")
246                  (const_string "no"))))
247
248
249 ;; Describe a user's asm statement.
250 (define_asm_attributes
251   [(set_attr "type" "multi")])
252
253 \f
254
255 ;; .........................
256 ;;
257 ;;      Delay slots, can't describe load/fcmp/xfer delay slots here
258 ;;
259 ;; .........................
260
261 (define_delay (and (eq_attr "type" "branch")
262                    (eq (symbol_ref "mips16") (const_int 0)))
263   [(eq_attr "can_delay" "yes")
264    (nil)
265    (and (eq_attr "branch_likely" "yes")
266         (eq_attr "can_delay" "yes"))])
267
268 (define_delay (eq_attr "type" "jump")
269   [(eq_attr "can_delay" "yes")
270    (nil)
271    (nil)])
272
273 (define_delay (and (eq_attr "type" "call")
274                    (eq_attr "jal_macro" "no"))
275   [(eq_attr "can_delay" "yes")
276    (nil)
277    (nil)])
278
279 \f
280
281 ;; .........................
282 ;;
283 ;;      Functional units
284 ;;
285 ;; .........................
286
287 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
288 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
289
290 ;; Make the default case (PROCESSOR_DEFAULT) handle the worst case
291
292 (define_function_unit "memory" 1 0
293   (and (eq_attr "type" "load")
294        (eq_attr "cpu" "!r3000,r3900,r4600,r4650,r4100,r4120,r4300,r5000"))
295   3 0)
296
297 (define_function_unit "memory" 1 0
298   (and (eq_attr "type" "load")
299        (eq_attr "cpu" "r3000,r3900,r4600,r4650,r4100,r4120,r4300,r5000"))
300   2 0)
301
302 (define_function_unit "memory"   1 0 (eq_attr "type" "store") 1 0)
303
304 (define_function_unit "memory"   1 0 (eq_attr "type" "xfer") 2 0)
305
306 (define_function_unit "imuldiv"  1 0
307   (eq_attr "type" "hilo")
308   1 3)
309
310 (define_function_unit "imuldiv"  1 0
311   (and (eq_attr "type" "imul,imadd")
312        (eq_attr "cpu" "!r3000,r3900,r4000,r4600,r4650,r4100,r4120,r4300,r5000"))
313   17 17)
314
315 ;; On them mips16, we want to stronly discourage a mult from appearing
316 ;; after an mflo, since that requires explicit nop instructions.  We
317 ;; do this by pretending that mflo ties up the function unit for long
318 ;; enough that the scheduler will ignore load stalls and the like when
319 ;; selecting instructions to between the two instructions.
320
321 (define_function_unit "imuldiv" 1 0
322   (and (eq_attr "type" "hilo") (ne (symbol_ref "mips16") (const_int 0)))
323   1 5)
324
325 (define_function_unit "imuldiv"  1 0
326   (and (eq_attr "type" "imul,imadd") (eq_attr "cpu" "r3000,r3900"))
327   12 12)
328
329 (define_function_unit "imuldiv"  1 0
330   (and (eq_attr "type" "imul,imadd") (eq_attr "cpu" "r4000,r4600"))
331   10 10)
332
333 (define_function_unit "imuldiv"  1 0
334   (and (eq_attr "type" "imul,imadd") (eq_attr "cpu" "r4650"))
335   4 4)
336
337 (define_function_unit "imuldiv"  1 0
338   (and (eq_attr "type" "imul,imadd")
339        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4100,r4120")))
340   1 1)
341
342 (define_function_unit "imuldiv"  1 0
343   (and (eq_attr "type" "imul,imadd")
344        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4100,r4120")))
345   4 4)
346
347 (define_function_unit "imuldiv"  1 0
348   (and (eq_attr "type" "imul,imadd")
349        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4300,r5000")))
350   5 5)
351
352 (define_function_unit "imuldiv"  1 0
353   (and (eq_attr "type" "imul,imadd")
354        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4300")))
355   8 8)
356
357 (define_function_unit "imuldiv"  1 0
358   (and (eq_attr "type" "imul,imadd")
359        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r5000")))
360   9 9)
361
362 (define_function_unit "imuldiv"  1 0
363   (and (eq_attr "type" "idiv")
364        (eq_attr "cpu" "!r3000,r3900,r4000,r4600,r4650,r4100,r4120,r4300,r5000"))
365   38 38)
366
367 (define_function_unit "imuldiv"  1 0
368   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r3000,r3900"))
369   35 35)
370
371 (define_function_unit "imuldiv"  1 0
372   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r4600"))
373   42 42)
374
375 (define_function_unit "imuldiv"  1 0
376   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r4650"))
377   36 36)
378
379 (define_function_unit "imuldiv"  1 0
380   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r4000"))
381   69 69)
382
383 (define_function_unit "imuldiv" 1 0
384   (and (eq_attr "type" "idiv")
385        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4100,r4120")))
386   35 35)
387
388 (define_function_unit "imuldiv" 1 0
389   (and (eq_attr "type" "idiv")
390        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4100,r4120")))
391   67 67)
392
393 (define_function_unit "imuldiv" 1 0
394   (and (eq_attr "type" "idiv")
395        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4300")))
396   37 37)
397
398 (define_function_unit "imuldiv" 1 0
399   (and (eq_attr "type" "idiv")
400        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4300")))
401   69 69)
402
403 (define_function_unit "imuldiv" 1 0
404   (and (eq_attr "type" "idiv")
405        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r5000")))
406   36 36)
407
408 (define_function_unit "imuldiv" 1 0
409   (and (eq_attr "type" "idiv")
410        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r5000")))
411   68 68)
412
413 ;; The R4300 does *NOT* have a separate Floating Point Unit, instead
414 ;; the FP hardware is part of the normal ALU circuitry.  This means FP
415 ;; instructions affect the pipe-line, and no functional unit
416 ;; parallelism can occur on R4300 processors.  To force GCC into coding
417 ;; for only a single functional unit, we force the R4300 FP
418 ;; instructions to be processed in the "imuldiv" unit.
419
420 (define_function_unit "adder" 1 1
421   (and (eq_attr "type" "fcmp") (eq_attr "cpu" "!r3000,r3900,r6000,r4300,r5000"))
422   3 0)
423
424 (define_function_unit "adder" 1 1
425   (and (eq_attr "type" "fcmp") (eq_attr "cpu" "r3000,r3900,r6000"))
426   2 0)
427
428 (define_function_unit "adder" 1 1
429   (and (eq_attr "type" "fcmp") (eq_attr "cpu" "r5000"))
430   1 0)
431
432 (define_function_unit "adder" 1 1
433   (and (eq_attr "type" "fadd") (eq_attr "cpu" "!r3000,r3900,r6000,r4300"))
434   4 0)
435
436 (define_function_unit "adder" 1 1
437   (and (eq_attr "type" "fadd") (eq_attr "cpu" "r3000,r3900"))
438   2 0)
439
440 (define_function_unit "adder" 1 1
441   (and (eq_attr "type" "fadd") (eq_attr "cpu" "r6000"))
442   3 0)
443
444 (define_function_unit "adder" 1 1
445   (and (eq_attr "type" "fabs,fneg")
446        (eq_attr "cpu" "!r3000,r3900,r4600,r4650,r4300,r5000"))
447   2 0)
448
449 (define_function_unit "adder" 1 1
450   (and (eq_attr "type" "fabs,fneg") (eq_attr "cpu" "r3000,r3900,r4600,r4650,r5000"))
451   1 0)
452
453 (define_function_unit "mult" 1 1
454   (and (eq_attr "type" "fmul")
455        (and (eq_attr "mode" "SF")
456             (eq_attr "cpu" "!r3000,r3900,r6000,r4600,r4650,r4300,r5000")))
457   7 0)
458
459 (define_function_unit "mult" 1 1
460   (and (eq_attr "type" "fmul")
461        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r3000,r3900,r5000")))
462   4 0)
463
464 (define_function_unit "mult" 1 1
465   (and (eq_attr "type" "fmul")
466        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r6000")))
467   5 0)
468
469 (define_function_unit "mult" 1 1
470   (and (eq_attr "type" "fmul")
471        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4600,r4650")))
472   8 0)
473
474 (define_function_unit "mult" 1 1
475   (and (eq_attr "type" "fmul")
476        (and (eq_attr "mode" "DF") (eq_attr "cpu" "!r3000,r3900,r6000,r4300,r5000")))
477   8 0)
478
479 (define_function_unit "mult" 1 1
480   (and (eq_attr "type" "fmul")
481        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r3000,r3900,r5000")))
482   5 0)
483
484 (define_function_unit "mult" 1 1
485   (and (eq_attr "type" "fmul")
486        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r6000")))
487   6 0)
488
489 (define_function_unit "divide" 1 1
490   (and (eq_attr "type" "fdiv")
491        (and (eq_attr "mode" "SF")
492             (eq_attr "cpu" "!r3000,r3900,r6000,r4600,r4650,r4300,r5000")))
493   23 0)
494
495 (define_function_unit "divide" 1 1
496   (and (eq_attr "type" "fdiv")
497        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r3000,r3900")))
498   12 0)
499
500 (define_function_unit "divide" 1 1
501   (and (eq_attr "type" "fdiv")
502        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r6000")))
503   15 0)
504
505 (define_function_unit "divide" 1 1
506   (and (eq_attr "type" "fdiv")
507        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4600,r4650")))
508   32 0)
509
510 (define_function_unit "divide" 1 1
511   (and (eq_attr "type" "fdiv")
512        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r5000")))
513   21 0)
514
515 (define_function_unit "divide" 1 1
516   (and (eq_attr "type" "fdiv")
517        (and (eq_attr "mode" "DF")
518             (eq_attr "cpu" "!r3000,r3900,r6000,r4600,r4650,r4300")))
519   36 0)
520
521 (define_function_unit "divide" 1 1
522   (and (eq_attr "type" "fdiv")
523        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r3000,r3900")))
524   19 0)
525
526 (define_function_unit "divide" 1 1
527   (and (eq_attr "type" "fdiv")
528        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r6000")))
529   16 0)
530
531 (define_function_unit "divide" 1 1
532   (and (eq_attr "type" "fdiv")
533        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4600,r4650")))
534   61 0)
535
536 ;;; ??? Is this number right?
537 (define_function_unit "divide" 1 1
538   (and (eq_attr "type" "fsqrt,frsqrt")
539        (and (eq_attr "mode" "SF") (eq_attr "cpu" "!r4600,r4650,r4300,r5000")))
540   54 0)
541
542 (define_function_unit "divide" 1 1
543   (and (eq_attr "type" "fsqrt,frsqrt")
544        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4600,r4650")))
545   31 0)
546
547 (define_function_unit "divide" 1 1
548   (and (eq_attr "type" "fsqrt,frsqrt")
549        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r5000")))
550   21 0)
551
552 ;;; ??? Is this number right?
553 (define_function_unit "divide" 1 1
554   (and (eq_attr "type" "fsqrt,frsqrt")
555        (and (eq_attr "mode" "DF") (eq_attr "cpu" "!r4600,r4650,r4300,r5000")))
556   112 0)
557
558 (define_function_unit "divide" 1 1
559   (and (eq_attr "type" "fsqrt,frsqrt")
560        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4600,r4650")))
561   60 0)
562
563 (define_function_unit "divide" 1 1
564   (and (eq_attr "type" "fsqrt,frsqrt")
565        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r5000")))
566   36 0)
567
568 ;; R4300 FP instruction classes treated as part of the "imuldiv"
569 ;; functional unit:
570
571 (define_function_unit "imuldiv" 1 0
572   (and (eq_attr "type" "fadd") (eq_attr "cpu" "r4300"))
573   3 3)
574
575 (define_function_unit "imuldiv" 1 0
576   (and (eq_attr "type" "fcmp,fabs,fneg") (eq_attr "cpu" "r4300"))
577   1 1)
578
579 (define_function_unit "imuldiv" 1 0
580   (and (eq_attr "type" "fmul") (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4300")))
581   5 5)
582 (define_function_unit "imuldiv" 1 0
583   (and (eq_attr "type" "fmul") (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4300")))
584   8 8)
585
586 (define_function_unit "imuldiv" 1 0
587   (and (and (eq_attr "type" "fdiv") (eq_attr "type" "fsqrt,frsqrt"))
588        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4300")))
589   29 29)
590 (define_function_unit "imuldiv" 1 0
591   (and (and (eq_attr "type" "fdiv") (eq_attr "type" "fsqrt,frsqrt"))
592        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4300")))
593   58 58)
594 \f
595 ;; The following functional units do not use the cpu type, and use
596 ;; much less memory in genattrtab.c.
597
598 ;; (define_function_unit "memory"   1 0 (eq_attr "type" "load")                                3 0)
599 ;; (define_function_unit "memory"   1 0 (eq_attr "type" "store")                               1 0)
600 ;;
601 ;; (define_function_unit "fp_comp"  1 0 (eq_attr "type" "fcmp")                                2 0)
602 ;;
603 ;; (define_function_unit "transfer" 1 0 (eq_attr "type" "xfer")                                2 0)
604 ;; (define_function_unit "transfer" 1 0 (eq_attr "type" "hilo")                                3 0)
605 ;;
606 ;; (define_function_unit "imuldiv"  1 1 (eq_attr "type" "imul")                               17 0)
607 ;; (define_function_unit "imuldiv"  1 1 (eq_attr "type" "idiv")                               38 0)
608 ;;
609 ;; (define_function_unit "adder"    1 1 (eq_attr "type" "fadd")                                4 0)
610 ;; (define_function_unit "adder"    1 1 (eq_attr "type" "fabs,fneg")                           2 0)
611 ;;
612 ;; (define_function_unit "mult"     1 1 (and (eq_attr "type" "fmul") (eq_attr "mode" "SF"))    7 0)
613 ;; (define_function_unit "mult"     1 1 (and (eq_attr "type" "fmul") (eq_attr "mode" "DF"))    8 0)
614 ;;
615 ;; (define_function_unit "divide"   1 1 (and (eq_attr "type" "fdiv") (eq_attr "mode" "SF"))   23 0)
616 ;; (define_function_unit "divide"   1 1 (and (eq_attr "type" "fdiv") (eq_attr "mode" "DF"))   36 0)
617 ;;
618 ;; (define_function_unit "sqrt"     1 1 (and (eq_attr "type" "fsqrt") (eq_attr "mode" "SF"))  54 0)
619 ;; (define_function_unit "sqrt"     1 1 (and (eq_attr "type" "fsqrt") (eq_attr "mode" "DF")) 112 0)
620 \f
621 ;; Include scheduling descriptions.
622
623 (include "5400.md")
624 (include "5500.md")
625 (include "sr71k.md")
626
627
628 ;;
629 ;;  ....................
630 ;;
631 ;;      CONDITIONAL TRAPS
632 ;;
633 ;;  ....................
634 ;;
635
636 (define_insn "trap"
637   [(trap_if (const_int 1) (const_int 0))]
638   ""
639   "*
640 {
641   if (ISA_HAS_COND_TRAP)
642     return \"teq\\t$0,$0\";
643   /* The IRIX 6 O32 assembler requires the first break operand.  */
644   else if (TARGET_MIPS16 || ! TARGET_GAS)
645     return \"break 0\";
646   else
647     return \"break\";
648 }")
649
650 (define_expand "conditional_trap"
651   [(trap_if (match_operator 0 "cmp_op"
652                             [(match_dup 2) (match_dup 3)])
653             (match_operand 1 "const_int_operand" ""))]
654   "ISA_HAS_COND_TRAP"
655   "
656 {
657   mips_gen_conditional_trap (operands);
658   DONE;
659 }")
660
661 ;; Match a TRAP_IF with 2nd arg of 0.  The div_trap_* insns match a
662 ;; 2nd arg of any CONST_INT, so this insn must appear first.
663 ;; gen_div_trap always generates TRAP_IF with 2nd arg of 6 or 7.
664
665 (define_insn ""
666   [(trap_if (match_operator 0 "trap_cmp_op"
667                             [(match_operand:SI 1 "reg_or_0_operand" "d")
668                              (match_operand:SI 2 "nonmemory_operand" "dI")])
669             (const_int 0))]
670   "ISA_HAS_COND_TRAP"
671   "t%C0\\t%z1,%z2")
672 \f
673 ;;
674 ;;  ....................
675 ;;
676 ;;      ADDITION
677 ;;
678 ;;  ....................
679 ;;
680
681 (define_insn "adddf3"
682   [(set (match_operand:DF 0 "register_operand" "=f")
683         (plus:DF (match_operand:DF 1 "register_operand" "f")
684                  (match_operand:DF 2 "register_operand" "f")))]
685   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
686   "add.d\\t%0,%1,%2"
687   [(set_attr "type"     "fadd")
688    (set_attr "mode"     "DF")])
689
690 (define_insn "addsf3"
691   [(set (match_operand:SF 0 "register_operand" "=f")
692         (plus:SF (match_operand:SF 1 "register_operand" "f")
693                  (match_operand:SF 2 "register_operand" "f")))]
694   "TARGET_HARD_FLOAT"
695   "add.s\\t%0,%1,%2"
696   [(set_attr "type"     "fadd")
697    (set_attr "mode"     "SF")])
698
699 (define_expand "addsi3"
700   [(set (match_operand:SI 0 "register_operand" "")
701         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "")
702                  (match_operand:SI 2 "arith_operand" "")))]
703   ""
704   "
705 {
706   /* The mips16 assembler handles -32768 correctly, and so does gas,
707      but some other MIPS assemblers think that -32768 needs to be
708      loaded into a register before it can be added in.  */
709   if (! TARGET_MIPS16
710       && ! TARGET_GAS
711       && GET_CODE (operands[2]) == CONST_INT
712       && INTVAL (operands[2]) == -32768)
713     operands[2] = force_reg (SImode, operands[2]);
714
715   /* If a large stack adjustment was forced into a register, we may be
716      asked to generate rtx such as:
717
718         (set (reg:SI sp) (plus:SI (reg:SI sp) (reg:SI pseudo)))
719
720      but no such instruction is available in mips16.  Handle it by
721      using a temporary.  */
722   if (TARGET_MIPS16
723       && REGNO (operands[0]) == STACK_POINTER_REGNUM
724       && ((GET_CODE (operands[1]) == REG
725            && REGNO (operands[1]) != STACK_POINTER_REGNUM)
726           || GET_CODE (operands[2]) != CONST_INT))
727     {
728       rtx tmp = gen_reg_rtx (SImode);
729
730       emit_move_insn (tmp, operands[1]);
731       emit_insn (gen_addsi3 (tmp, tmp, operands[2]));
732       emit_move_insn (operands[0], tmp);
733       DONE;
734     }
735 }")
736
737 (define_insn "addsi3_internal"
738   [(set (match_operand:SI 0 "register_operand" "=d,d")
739         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ,dJ")
740                  (match_operand:SI 2 "arith_operand" "d,Q")))]
741   "! TARGET_MIPS16
742    && (TARGET_GAS
743        || GET_CODE (operands[2]) != CONST_INT
744        || INTVAL (operands[2]) != -32768)"
745   "@
746     addu\\t%0,%z1,%2
747     addiu\\t%0,%z1,%2"
748   [(set_attr "type"     "arith")
749    (set_attr "mode"     "SI")])
750
751 ;; For the mips16, we need to recognize stack pointer additions
752 ;; explicitly, since we don't have a constraint for $sp.  These insns
753 ;; will be generated by the save_restore_insns functions.
754
755 (define_insn ""
756   [(set (reg:SI 29)
757         (plus:SI (reg:SI 29)
758                  (match_operand:SI 0 "small_int" "I")))]
759   "TARGET_MIPS16"
760   "addu\\t%$,%$,%0"
761   [(set_attr "type"     "arith")
762    (set_attr "mode"     "SI")
763    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_simm8_8" "")
764                                       (const_int 4)
765                                       (const_int 8)))])
766
767 (define_insn ""
768   [(set (match_operand:SI 0 "register_operand" "=d")
769         (plus:SI (reg:SI 29)
770                  (match_operand:SI 1 "small_int" "I")))]
771   "TARGET_MIPS16"
772   "addu\\t%0,%$,%1"
773   [(set_attr "type"     "arith")
774    (set_attr "mode"     "SI")
775    (set (attr "length") (if_then_else (match_operand:VOID 1 "m16_uimm8_4" "")
776                                       (const_int 4)
777                                       (const_int 8)))])
778
779 (define_insn ""
780   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
781         (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
782                  (match_operand:SI 2 "arith_operand" "Q,O,d")))]
783   "TARGET_MIPS16
784    && (GET_CODE (operands[1]) != REG
785        || REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER
786        || M16_REG_P (REGNO (operands[1]))
787        || REGNO (operands[1]) == ARG_POINTER_REGNUM
788        || REGNO (operands[1]) == FRAME_POINTER_REGNUM
789        || REGNO (operands[1]) == STACK_POINTER_REGNUM)
790    && (GET_CODE (operands[2]) != REG
791        || REGNO (operands[2]) >= FIRST_PSEUDO_REGISTER
792        || M16_REG_P (REGNO (operands[2]))
793        || REGNO (operands[2]) == ARG_POINTER_REGNUM
794        || REGNO (operands[2]) == FRAME_POINTER_REGNUM
795        || REGNO (operands[2]) == STACK_POINTER_REGNUM)"
796   "*
797 {
798   if (REGNO (operands[0]) == REGNO (operands[1]))
799     return \"addu\\t%0,%2\";
800   return \"addu\\t%0,%1,%2\";
801 }"
802   [(set_attr "type"     "arith")
803    (set_attr "mode"     "SI")
804    (set_attr_alternative "length"
805                 [(if_then_else (match_operand:VOID 2 "m16_simm8_1" "")
806                                (const_int 4)
807                                (const_int 8))
808                  (if_then_else (match_operand:VOID 2 "m16_simm4_1" "")
809                                (const_int 4)
810                                (const_int 8))
811                  (const_int 4)])])
812
813
814 ;; On the mips16, we can sometimes split an add of a constant which is
815 ;; a 4 byte instruction into two adds which are both 2 byte
816 ;; instructions.  There are two cases: one where we are adding a
817 ;; constant plus a register to another register, and one where we are
818 ;; simply adding a constant to a register.
819
820 (define_split
821   [(set (match_operand:SI 0 "register_operand" "")
822         (plus:SI (match_dup 0)
823                  (match_operand:SI 1 "const_int_operand" "")))]
824   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
825    && GET_CODE (operands[0]) == REG
826    && M16_REG_P (REGNO (operands[0]))
827    && GET_CODE (operands[1]) == CONST_INT
828    && ((INTVAL (operands[1]) > 0x7f
829         && INTVAL (operands[1]) <= 0x7f + 0x7f)
830        || (INTVAL (operands[1]) < - 0x80
831            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
832   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
833    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
834   "
835 {
836   HOST_WIDE_INT val = INTVAL (operands[1]);
837
838   if (val >= 0)
839     {
840       operands[1] = GEN_INT (0x7f);
841       operands[2] = GEN_INT (val - 0x7f);
842     }
843   else
844     {
845       operands[1] = GEN_INT (- 0x80);
846       operands[2] = GEN_INT (val + 0x80);
847     }
848 }")
849
850 (define_split
851   [(set (match_operand:SI 0 "register_operand" "")
852         (plus:SI (match_operand:SI 1 "register_operand" "")
853                  (match_operand:SI 2 "const_int_operand" "")))]
854   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
855    && GET_CODE (operands[0]) == REG
856    && M16_REG_P (REGNO (operands[0]))
857    && GET_CODE (operands[1]) == REG
858    && M16_REG_P (REGNO (operands[1]))
859    && REGNO (operands[0]) != REGNO (operands[1])
860    && GET_CODE (operands[2]) == CONST_INT
861    && ((INTVAL (operands[2]) > 0x7
862         && INTVAL (operands[2]) <= 0x7 + 0x7f)
863        || (INTVAL (operands[2]) < - 0x8
864            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
865   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
866    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
867   "
868 {
869   HOST_WIDE_INT val = INTVAL (operands[2]);
870
871   if (val >= 0)
872     {
873       operands[2] = GEN_INT (0x7);
874       operands[3] = GEN_INT (val - 0x7);
875     }
876   else
877     {
878       operands[2] = GEN_INT (- 0x8);
879       operands[3] = GEN_INT (val + 0x8);
880     }
881 }")
882
883 (define_expand "adddi3"
884   [(parallel [(set (match_operand:DI 0 "register_operand" "")
885                    (plus:DI (match_operand:DI 1 "register_operand" "")
886                             (match_operand:DI 2 "arith_operand" "")))
887               (clobber (match_dup 3))])]
888   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
889   "
890 {
891   /* The mips16 assembler handles -32768 correctly, and so does gas,
892      but some other MIPS assemblers think that -32768 needs to be
893      loaded into a register before it can be added in.  */
894   if (! TARGET_MIPS16
895       && ! TARGET_GAS
896       && GET_CODE (operands[2]) == CONST_INT
897       && INTVAL (operands[2]) == -32768)
898     operands[2] = force_reg (DImode, operands[2]);
899
900   /* If a large stack adjustment was forced into a register, we may be
901      asked to generate rtx such as:
902
903         (set (reg:DI sp) (plus:DI (reg:DI sp) (reg:DI pseudo)))
904
905      but no such instruction is available in mips16.  Handle it by
906      using a temporary.  */
907   if (TARGET_MIPS16
908       && REGNO (operands[0]) == STACK_POINTER_REGNUM
909       && ((GET_CODE (operands[1]) == REG
910            && REGNO (operands[1]) != STACK_POINTER_REGNUM)
911           || GET_CODE (operands[2]) != CONST_INT))
912     {
913       rtx tmp = gen_reg_rtx (DImode);
914
915       emit_move_insn (tmp, operands[1]);
916       emit_insn (gen_addsi3 (tmp, tmp, operands[2]));
917       emit_move_insn (operands[0], tmp);
918       DONE;
919     }
920
921   if (TARGET_64BIT)
922     {
923       emit_insn (gen_adddi3_internal_3 (operands[0], operands[1],
924                                         operands[2]));
925       DONE;
926     }
927
928   operands[3] = gen_reg_rtx (SImode);
929 }")
930
931 (define_insn "adddi3_internal_1"
932   [(set (match_operand:DI 0 "register_operand" "=d,&d")
933         (plus:DI (match_operand:DI 1 "register_operand" "0,d")
934                  (match_operand:DI 2 "register_operand" "d,d")))
935    (clobber (match_operand:SI 3 "register_operand" "=d,d"))]
936   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
937   "*
938 {
939   return (REGNO (operands[0]) == REGNO (operands[1])
940           && REGNO (operands[0]) == REGNO (operands[2]))
941     ? \"srl\\t%3,%L0,31\;sll\\t%M0,%M0,1\;sll\\t%L0,%L1,1\;addu\\t%M0,%M0,%3\"
942     : \"addu\\t%L0,%L1,%L2\;sltu\\t%3,%L0,%L2\;addu\\t%M0,%M1,%M2\;addu\\t%M0,%M0,%3\";
943 }"
944   [(set_attr "type"     "darith")
945    (set_attr "mode"     "DI")
946    (set_attr "length"   "16")])
947
948 (define_split
949   [(set (match_operand:DI 0 "register_operand" "")
950         (plus:DI (match_operand:DI 1 "register_operand" "")
951                  (match_operand:DI 2 "register_operand" "")))
952    (clobber (match_operand:SI 3 "register_operand" ""))]
953   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
954    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
955    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
956    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
957    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))
958    && (REGNO (operands[0]) != REGNO (operands[1])
959        || REGNO (operands[0]) != REGNO (operands[2]))"
960
961   [(set (subreg:SI (match_dup 0) 0)
962         (plus:SI (subreg:SI (match_dup 1) 0)
963                  (subreg:SI (match_dup 2) 0)))
964
965    (set (match_dup 3)
966         (ltu:SI (subreg:SI (match_dup 0) 0)
967                 (subreg:SI (match_dup 2) 0)))
968
969    (set (subreg:SI (match_dup 0) 4)
970         (plus:SI (subreg:SI (match_dup 1) 4)
971                  (subreg:SI (match_dup 2) 4)))
972
973    (set (subreg:SI (match_dup 0) 4)
974         (plus:SI (subreg:SI (match_dup 0) 4)
975                  (match_dup 3)))]
976   "")
977
978 (define_split
979   [(set (match_operand:DI 0 "register_operand" "")
980         (plus:DI (match_operand:DI 1 "register_operand" "")
981                  (match_operand:DI 2 "register_operand" "")))
982    (clobber (match_operand:SI 3 "register_operand" ""))]
983   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
984    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
985    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
986    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
987    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))
988    && (REGNO (operands[0]) != REGNO (operands[1])
989        || REGNO (operands[0]) != REGNO (operands[2]))"
990
991   [(set (subreg:SI (match_dup 0) 4)
992         (plus:SI (subreg:SI (match_dup 1) 4)
993                  (subreg:SI (match_dup 2) 4)))
994
995    (set (match_dup 3)
996         (ltu:SI (subreg:SI (match_dup 0) 4)
997                 (subreg:SI (match_dup 2) 4)))
998
999    (set (subreg:SI (match_dup 0) 0)
1000         (plus:SI (subreg:SI (match_dup 1) 0)
1001                  (subreg:SI (match_dup 2) 0)))
1002
1003    (set (subreg:SI (match_dup 0) 0)
1004         (plus:SI (subreg:SI (match_dup 0) 0)
1005                  (match_dup 3)))]
1006   "")
1007
1008 (define_insn "adddi3_internal_2"
1009   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1010         (plus:DI (match_operand:DI 1 "register_operand" "%d,%d,%d")
1011                  (match_operand:DI 2 "small_int" "P,J,N")))
1012    (clobber (match_operand:SI 3 "register_operand" "=d,d,d"))]
1013   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1014    && (TARGET_GAS
1015        || GET_CODE (operands[2]) != CONST_INT
1016        || INTVAL (operands[2]) != -32768)"
1017   "@
1018    addu\\t%L0,%L1,%2\;sltu\\t%3,%L0,%2\;addu\\t%M0,%M1,%3
1019    move\\t%L0,%L1\;move\\t%M0,%M1
1020    subu\\t%L0,%L1,%n2\;sltu\\t%3,%L0,%2\;subu\\t%M0,%M1,1\;addu\\t%M0,%M0,%3"
1021   [(set_attr "type"     "darith")
1022    (set_attr "mode"     "DI")
1023    (set_attr "length"   "12,8,16")])
1024
1025 (define_split
1026   [(set (match_operand:DI 0 "register_operand" "")
1027         (plus:DI (match_operand:DI 1 "register_operand" "")
1028                  (match_operand:DI 2 "small_int" "")))
1029    (clobber (match_operand:SI 3 "register_operand" ""))]
1030   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
1031    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1032    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1033    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1034    && INTVAL (operands[2]) > 0"
1035
1036   [(set (subreg:SI (match_dup 0) 0)
1037         (plus:SI (subreg:SI (match_dup 1) 0)
1038                  (match_dup 2)))
1039
1040    (set (match_dup 3)
1041         (ltu:SI (subreg:SI (match_dup 0) 0)
1042                 (match_dup 2)))
1043
1044    (set (subreg:SI (match_dup 0) 4)
1045         (plus:SI (subreg:SI (match_dup 1) 4)
1046                  (match_dup 3)))]
1047   "")
1048
1049 (define_split
1050   [(set (match_operand:DI 0 "register_operand" "")
1051         (plus:DI (match_operand:DI 1 "register_operand" "")
1052                  (match_operand:DI 2 "small_int" "")))
1053    (clobber (match_operand:SI 3 "register_operand" ""))]
1054   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
1055    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1056    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1057    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1058    && INTVAL (operands[2]) > 0"
1059
1060   [(set (subreg:SI (match_dup 0) 4)
1061         (plus:SI (subreg:SI (match_dup 1) 4)
1062                  (match_dup 2)))
1063
1064    (set (match_dup 3)
1065         (ltu:SI (subreg:SI (match_dup 0) 4)
1066                 (match_dup 2)))
1067
1068    (set (subreg:SI (match_dup 0) 0)
1069         (plus:SI (subreg:SI (match_dup 1) 0)
1070                  (match_dup 3)))]
1071   "")
1072
1073 (define_insn "adddi3_internal_3"
1074   [(set (match_operand:DI 0 "register_operand" "=d,d")
1075         (plus:DI (match_operand:DI 1 "reg_or_0_operand" "dJ,dJ")
1076                  (match_operand:DI 2 "arith_operand" "d,Q")))]
1077   "TARGET_64BIT
1078    && !TARGET_MIPS16
1079    && (TARGET_GAS
1080        || GET_CODE (operands[2]) != CONST_INT
1081        || INTVAL (operands[2]) != -32768)"
1082   "@
1083     daddu\\t%0,%z1,%2
1084     daddiu\\t%0,%z1,%2"
1085   [(set_attr "type"     "darith")
1086    (set_attr "mode"     "DI")])
1087
1088 ;; For the mips16, we need to recognize stack pointer additions
1089 ;; explicitly, since we don't have a constraint for $sp.  These insns
1090 ;; will be generated by the save_restore_insns functions.
1091
1092 (define_insn ""
1093   [(set (reg:DI 29)
1094         (plus:DI (reg:DI 29)
1095                  (match_operand:DI 0 "small_int" "I")))]
1096   "TARGET_MIPS16 && TARGET_64BIT"
1097   "daddu\\t%$,%$,%0"
1098   [(set_attr "type"     "arith")
1099    (set_attr "mode"     "DI")
1100    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_simm8_8" "")
1101                                       (const_int 4)
1102                                       (const_int 8)))])
1103
1104 (define_insn ""
1105   [(set (match_operand:DI 0 "register_operand" "=d")
1106         (plus:DI (reg:DI 29)
1107                  (match_operand:DI 1 "small_int" "I")))]
1108   "TARGET_MIPS16 && TARGET_64BIT"
1109   "daddu\\t%0,%$,%1"
1110   [(set_attr "type"     "arith")
1111    (set_attr "mode"     "DI")
1112    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_uimm5_4" "")
1113                                       (const_int 4)
1114                                       (const_int 8)))])
1115
1116 (define_insn ""
1117   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1118         (plus:DI (match_operand:DI 1 "register_operand" "0,d,d")
1119                  (match_operand:DI 2 "arith_operand" "Q,O,d")))]
1120   "TARGET_MIPS16 && TARGET_64BIT
1121    && (GET_CODE (operands[1]) != REG
1122        || REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER
1123        || M16_REG_P (REGNO (operands[1]))
1124        || REGNO (operands[1]) == ARG_POINTER_REGNUM
1125        || REGNO (operands[1]) == FRAME_POINTER_REGNUM
1126        || REGNO (operands[1]) == STACK_POINTER_REGNUM)
1127    && (GET_CODE (operands[2]) != REG
1128        || REGNO (operands[2]) >= FIRST_PSEUDO_REGISTER
1129        || M16_REG_P (REGNO (operands[2]))
1130        || REGNO (operands[2]) == ARG_POINTER_REGNUM
1131        || REGNO (operands[2]) == FRAME_POINTER_REGNUM
1132        || REGNO (operands[2]) == STACK_POINTER_REGNUM)"
1133   "*
1134 {
1135   if (REGNO (operands[0]) == REGNO (operands[1]))
1136     return \"daddu\\t%0,%2\";
1137   return \"daddu\\t%0,%1,%2\";
1138 }"
1139   [(set_attr "type"     "arith")
1140    (set_attr "mode"     "DI")
1141    (set_attr_alternative "length"
1142                 [(if_then_else (match_operand:VOID 2 "m16_simm5_1" "")
1143                                (const_int 4)
1144                                (const_int 8))
1145                  (if_then_else (match_operand:VOID 2 "m16_simm4_1" "")
1146                                (const_int 4)
1147                                (const_int 8))
1148                  (const_int 4)])])
1149
1150
1151 ;; On the mips16, we can sometimes split an add of a constant which is
1152 ;; a 4 byte instruction into two adds which are both 2 byte
1153 ;; instructions.  There are two cases: one where we are adding a
1154 ;; constant plus a register to another register, and one where we are
1155 ;; simply adding a constant to a register.
1156
1157 (define_split
1158   [(set (match_operand:DI 0 "register_operand" "")
1159         (plus:DI (match_dup 0)
1160                  (match_operand:DI 1 "const_int_operand" "")))]
1161   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1162    && GET_CODE (operands[0]) == REG
1163    && M16_REG_P (REGNO (operands[0]))
1164    && GET_CODE (operands[1]) == CONST_INT
1165    && ((INTVAL (operands[1]) > 0xf
1166         && INTVAL (operands[1]) <= 0xf + 0xf)
1167        || (INTVAL (operands[1]) < - 0x10
1168            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1169   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1170    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1171   "
1172 {
1173   HOST_WIDE_INT val = INTVAL (operands[1]);
1174
1175   if (val >= 0)
1176     {
1177       operands[1] = GEN_INT (0xf);
1178       operands[2] = GEN_INT (val - 0xf);
1179     }
1180   else
1181     {
1182       operands[1] = GEN_INT (- 0x10);
1183       operands[2] = GEN_INT (val + 0x10);
1184     }
1185 }")
1186
1187 (define_split
1188   [(set (match_operand:DI 0 "register_operand" "")
1189         (plus:DI (match_operand:DI 1 "register_operand" "")
1190                  (match_operand:DI 2 "const_int_operand" "")))]
1191   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1192    && GET_CODE (operands[0]) == REG
1193    && M16_REG_P (REGNO (operands[0]))
1194    && GET_CODE (operands[1]) == REG
1195    && M16_REG_P (REGNO (operands[1]))
1196    && REGNO (operands[0]) != REGNO (operands[1])
1197    && GET_CODE (operands[2]) == CONST_INT
1198    && ((INTVAL (operands[2]) > 0x7
1199         && INTVAL (operands[2]) <= 0x7 + 0xf)
1200        || (INTVAL (operands[2]) < - 0x8
1201            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1202   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1203    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1204   "
1205 {
1206   HOST_WIDE_INT val = INTVAL (operands[2]);
1207
1208   if (val >= 0)
1209     {
1210       operands[2] = GEN_INT (0x7);
1211       operands[3] = GEN_INT (val - 0x7);
1212     }
1213   else
1214     {
1215       operands[2] = GEN_INT (- 0x8);
1216       operands[3] = GEN_INT (val + 0x8);
1217     }
1218 }")
1219
1220 (define_insn "addsi3_internal_2"
1221   [(set (match_operand:DI 0 "register_operand" "=d,d")
1222         (sign_extend:DI (plus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ,dJ")
1223                                  (match_operand:SI 2 "arith_operand" "d,Q"))))]
1224   "TARGET_64BIT
1225    && !TARGET_MIPS16
1226    && (TARGET_GAS
1227        || GET_CODE (operands[2]) != CONST_INT
1228        || INTVAL (operands[2]) != -32768)"
1229   "@
1230     addu\\t%0,%z1,%2
1231     addiu\\t%0,%z1,%2"
1232   [(set_attr "type"     "arith")
1233    (set_attr "mode"     "SI")])
1234
1235 (define_insn ""
1236   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1237         (sign_extend:DI (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1238                                  (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1239   "TARGET_MIPS16 && TARGET_64BIT"
1240   "*
1241 {
1242   if (REGNO (operands[0]) == REGNO (operands[1]))
1243     return \"addu\\t%0,%2\";
1244   return \"addu\\t%0,%1,%2\";
1245 }"
1246   [(set_attr "type"     "arith")
1247    (set_attr "mode"     "SI")
1248    (set_attr_alternative "length"
1249                 [(if_then_else (match_operand:VOID 2 "m16_simm8_1" "")
1250                                (const_int 4)
1251                                (const_int 8))
1252                  (if_then_else (match_operand:VOID 2 "m16_simm4_1" "")
1253                                (const_int 4)
1254                                (const_int 8))
1255                  (const_int 4)])])
1256
1257 \f
1258 ;;
1259 ;;  ....................
1260 ;;
1261 ;;      SUBTRACTION
1262 ;;
1263 ;;  ....................
1264 ;;
1265
1266 (define_insn "subdf3"
1267   [(set (match_operand:DF 0 "register_operand" "=f")
1268         (minus:DF (match_operand:DF 1 "register_operand" "f")
1269                   (match_operand:DF 2 "register_operand" "f")))]
1270   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
1271   "sub.d\\t%0,%1,%2"
1272   [(set_attr "type"     "fadd")
1273    (set_attr "mode"     "DF")])
1274
1275 (define_insn "subsf3"
1276   [(set (match_operand:SF 0 "register_operand" "=f")
1277         (minus:SF (match_operand:SF 1 "register_operand" "f")
1278                   (match_operand:SF 2 "register_operand" "f")))]
1279   "TARGET_HARD_FLOAT"
1280   "sub.s\\t%0,%1,%2"
1281   [(set_attr "type"     "fadd")
1282    (set_attr "mode"     "SF")])
1283
1284 (define_expand "subsi3"
1285   [(set (match_operand:SI 0 "register_operand" "=d")
1286         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ")
1287                   (match_operand:SI 2 "arith_operand" "dI")))]
1288   ""
1289   "
1290 {
1291   if (GET_CODE (operands[2]) == CONST_INT
1292       && (INTVAL (operands[2]) == -32768
1293           || (TARGET_MIPS16
1294               && INTVAL (operands[2]) == -0x4000)))
1295     operands[2] = force_reg (SImode, operands[2]);
1296 }")
1297
1298 (define_insn "subsi3_internal"
1299   [(set (match_operand:SI 0 "register_operand" "=d")
1300         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ")
1301                   (match_operand:SI 2 "arith_operand" "dI")))]
1302   "!TARGET_MIPS16
1303    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1304   "subu\\t%0,%z1,%2"
1305   [(set_attr "type"     "arith")
1306    (set_attr "mode"     "SI")])
1307
1308 ;; For the mips16, we need to recognize stack pointer subtractions
1309 ;; explicitly, since we don't have a constraint for $sp.  These insns
1310 ;; will be generated by the save_restore_insns functions.
1311
1312 (define_insn ""
1313   [(set (reg:SI 29)
1314         (minus:SI (reg:SI 29)
1315                   (match_operand:SI 0 "small_int" "I")))]
1316   "TARGET_MIPS16
1317    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1318   "addu\\t%$,%$,%n0"
1319   [(set_attr "type"     "arith")
1320    (set_attr "mode"     "SI")
1321    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_nsimm8_8" "")
1322                                       (const_int 4)
1323                                       (const_int 8)))])
1324
1325 (define_insn ""
1326   [(set (match_operand:SI 0 "register_operand" "=d")
1327         (minus:SI (reg:SI 29)
1328                   (match_operand:SI 1 "small_int" "I")))]
1329   "TARGET_MIPS16
1330    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1331   "addu\\t%0,%$,%n1"
1332   [(set_attr "type"     "arith")
1333    (set_attr "mode"     "SI")
1334    (set (attr "length") (if_then_else (match_operand:VOID 1 "m16_nuimm8_4" "")
1335                                       (const_int 4)
1336                                       (const_int 8)))])
1337
1338
1339 (define_insn ""
1340   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
1341         (minus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1342                   (match_operand:SI 2 "arith_operand" "I,O,d")))]
1343   "TARGET_MIPS16
1344    && (GET_CODE (operands[2]) != CONST_INT
1345        || (INTVAL (operands[2]) != -32768 && INTVAL (operands[2]) != -0x4000))"
1346   "*
1347 {
1348   if (REGNO (operands[0]) == REGNO (operands[1]))
1349     return \"subu\\t%0,%2\";
1350   return \"subu\\t%0,%1,%2\";
1351 }"
1352   [(set_attr "type"     "arith")
1353    (set_attr "mode"     "SI")
1354    (set_attr_alternative "length"
1355                 [(if_then_else (match_operand:VOID 2 "m16_nsimm8_1" "")
1356                                (const_int 4)
1357                                (const_int 8))
1358                  (if_then_else (match_operand:VOID 2 "m16_nsimm4_1" "")
1359                                (const_int 4)
1360                                (const_int 8))
1361                  (const_int 4)])])
1362
1363 ;; On the mips16, we can sometimes split a subtract of a constant
1364 ;; which is a 4 byte instruction into two adds which are both 2 byte
1365 ;; instructions.  There are two cases: one where we are setting a
1366 ;; register to a register minus a constant, and one where we are
1367 ;; simply subtracting a constant from a register.
1368
1369 (define_split
1370   [(set (match_operand:SI 0 "register_operand" "")
1371         (minus:SI (match_dup 0)
1372                   (match_operand:SI 1 "const_int_operand" "")))]
1373   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1374    && GET_CODE (operands[0]) == REG
1375    && M16_REG_P (REGNO (operands[0]))
1376    && GET_CODE (operands[1]) == CONST_INT
1377    && ((INTVAL (operands[1]) > 0x80
1378         && INTVAL (operands[1]) <= 0x80 + 0x80)
1379        || (INTVAL (operands[1]) < - 0x7f
1380            && INTVAL (operands[1]) >= - 0x7f - 0x7f))"
1381   [(set (match_dup 0) (minus:SI (match_dup 0) (match_dup 1)))
1382    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1383   "
1384 {
1385   HOST_WIDE_INT val = INTVAL (operands[1]);
1386
1387   if (val >= 0)
1388     {
1389       operands[1] = GEN_INT (0x80);
1390       operands[2] = GEN_INT (val - 0x80);
1391     }
1392   else
1393     {
1394       operands[1] = GEN_INT (- 0x7f);
1395       operands[2] = GEN_INT (val + 0x7f);
1396     }
1397 }")
1398
1399 (define_split
1400   [(set (match_operand:SI 0 "register_operand" "")
1401         (minus:SI (match_operand:SI 1 "register_operand" "")
1402                   (match_operand:SI 2 "const_int_operand" "")))]
1403   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1404    && GET_CODE (operands[0]) == REG
1405    && M16_REG_P (REGNO (operands[0]))
1406    && GET_CODE (operands[1]) == REG
1407    && M16_REG_P (REGNO (operands[1]))
1408    && REGNO (operands[0]) != REGNO (operands[1])
1409    && GET_CODE (operands[2]) == CONST_INT
1410    && ((INTVAL (operands[2]) > 0x8
1411         && INTVAL (operands[2]) <= 0x8 + 0x80)
1412        || (INTVAL (operands[2]) < - 0x7
1413            && INTVAL (operands[2]) >= - 0x7 - 0x7f))"
1414   [(set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))
1415    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 3)))]
1416   "
1417 {
1418   HOST_WIDE_INT val = INTVAL (operands[2]);
1419
1420   if (val >= 0)
1421     {
1422       operands[2] = GEN_INT (0x8);
1423       operands[3] = GEN_INT (val - 0x8);
1424     }
1425   else
1426     {
1427       operands[2] = GEN_INT (- 0x7);
1428       operands[3] = GEN_INT (val + 0x7);
1429     }
1430 }")
1431
1432 (define_expand "subdi3"
1433   [(parallel [(set (match_operand:DI 0 "register_operand" "=d")
1434                    (minus:DI (match_operand:DI 1 "register_operand" "d")
1435                              (match_operand:DI 2 "register_operand" "d")))
1436               (clobber (match_dup 3))])]
1437   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
1438   "
1439 {
1440   if (TARGET_64BIT)
1441     {
1442       emit_insn (gen_subdi3_internal_3 (operands[0], operands[1],
1443                                         operands[2]));
1444       DONE;
1445     }
1446
1447   operands[3] = gen_reg_rtx (SImode);
1448 }")
1449
1450 (define_insn "subdi3_internal"
1451   [(set (match_operand:DI 0 "register_operand" "=d")
1452         (minus:DI (match_operand:DI 1 "register_operand" "d")
1453                   (match_operand:DI 2 "register_operand" "d")))
1454    (clobber (match_operand:SI 3 "register_operand" "=d"))]
1455   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
1456   "sltu\\t%3,%L1,%L2\;subu\\t%L0,%L1,%L2\;subu\\t%M0,%M1,%M2\;subu\\t%M0,%M0,%3"
1457   [(set_attr "type"     "darith")
1458    (set_attr "mode"     "DI")
1459    (set_attr "length"   "16")])
1460
1461 (define_split
1462   [(set (match_operand:DI 0 "register_operand" "")
1463         (minus:DI (match_operand:DI 1 "register_operand" "")
1464                   (match_operand:DI 2 "register_operand" "")))
1465    (clobber (match_operand:SI 3 "register_operand" ""))]
1466   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
1467    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1468    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1469    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1470    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))"
1471
1472   [(set (match_dup 3)
1473         (ltu:SI (subreg:SI (match_dup 1) 0)
1474                 (subreg:SI (match_dup 2) 0)))
1475
1476    (set (subreg:SI (match_dup 0) 0)
1477         (minus:SI (subreg:SI (match_dup 1) 0)
1478                   (subreg:SI (match_dup 2) 0)))
1479
1480    (set (subreg:SI (match_dup 0) 4)
1481         (minus:SI (subreg:SI (match_dup 1) 4)
1482                   (subreg:SI (match_dup 2) 4)))
1483
1484    (set (subreg:SI (match_dup 0) 4)
1485         (minus:SI (subreg:SI (match_dup 0) 4)
1486                   (match_dup 3)))]
1487   "")
1488
1489 (define_split
1490   [(set (match_operand:DI 0 "register_operand" "")
1491         (minus:DI (match_operand:DI 1 "register_operand" "")
1492                   (match_operand:DI 2 "register_operand" "")))
1493    (clobber (match_operand:SI 3 "register_operand" ""))]
1494   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
1495    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1496    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1497    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1498    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))"
1499
1500   [(set (match_dup 3)
1501         (ltu:SI (subreg:SI (match_dup 1) 4)
1502                 (subreg:SI (match_dup 2) 4)))
1503
1504    (set (subreg:SI (match_dup 0) 4)
1505         (minus:SI (subreg:SI (match_dup 1) 4)
1506                   (subreg:SI (match_dup 2) 4)))
1507
1508    (set (subreg:SI (match_dup 0) 0)
1509         (minus:SI (subreg:SI (match_dup 1) 0)
1510                   (subreg:SI (match_dup 2) 0)))
1511
1512    (set (subreg:SI (match_dup 0) 0)
1513         (minus:SI (subreg:SI (match_dup 0) 0)
1514                   (match_dup 3)))]
1515   "")
1516
1517 (define_insn "subdi3_internal_2"
1518   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1519         (minus:DI (match_operand:DI 1 "register_operand" "d,d,d")
1520                   (match_operand:DI 2 "small_int" "P,J,N")))
1521    (clobber (match_operand:SI 3 "register_operand" "=d,d,d"))]
1522   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1523    && INTVAL (operands[2]) != -32768"
1524   "@
1525    sltu\\t%3,%L1,%2\;subu\\t%L0,%L1,%2\;subu\\t%M0,%M1,%3
1526    move\\t%L0,%L1\;move\\t%M0,%M1
1527    sltu\\t%3,%L1,%2\;subu\\t%L0,%L1,%2\;subu\\t%M0,%M1,1\;subu\\t%M0,%M0,%3"
1528   [(set_attr "type"     "darith")
1529    (set_attr "mode"     "DI")
1530    (set_attr "length"   "12,8,16")])
1531
1532 (define_split
1533   [(set (match_operand:DI 0 "register_operand" "")
1534         (minus:DI (match_operand:DI 1 "register_operand" "")
1535                   (match_operand:DI 2 "small_int" "")))
1536    (clobber (match_operand:SI 3 "register_operand" ""))]
1537   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
1538    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1539    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1540    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1541    && INTVAL (operands[2]) > 0"
1542
1543   [(set (match_dup 3)
1544         (ltu:SI (subreg:SI (match_dup 1) 0)
1545                 (match_dup 2)))
1546
1547    (set (subreg:SI (match_dup 0) 0)
1548         (minus:SI (subreg:SI (match_dup 1) 0)
1549                   (match_dup 2)))
1550
1551    (set (subreg:SI (match_dup 0) 4)
1552         (minus:SI (subreg:SI (match_dup 1) 4)
1553                   (match_dup 3)))]
1554   "")
1555
1556 (define_split
1557   [(set (match_operand:DI 0 "register_operand" "")
1558         (minus:DI (match_operand:DI 1 "register_operand" "")
1559                   (match_operand:DI 2 "small_int" "")))
1560    (clobber (match_operand:SI 3 "register_operand" ""))]
1561   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
1562    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1563    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1564    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1565    && INTVAL (operands[2]) > 0"
1566
1567   [(set (match_dup 3)
1568         (ltu:SI (subreg:SI (match_dup 1) 4)
1569                 (match_dup 2)))
1570
1571    (set (subreg:SI (match_dup 0) 4)
1572         (minus:SI (subreg:SI (match_dup 1) 4)
1573                   (match_dup 2)))
1574
1575    (set (subreg:SI (match_dup 0) 0)
1576         (minus:SI (subreg:SI (match_dup 1) 0)
1577                   (match_dup 3)))]
1578   "")
1579
1580 (define_insn "subdi3_internal_3"
1581   [(set (match_operand:DI 0 "register_operand" "=d")
1582         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "dJ")
1583                   (match_operand:DI 2 "arith_operand" "dI")))]
1584   "TARGET_64BIT && !TARGET_MIPS16
1585    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1586   "*
1587 {
1588   return (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
1589     ? \"daddu\\t%0,%z1,%n2\"
1590     : \"dsubu\\t%0,%z1,%2\";
1591 }"
1592   [(set_attr "type"     "darith")
1593    (set_attr "mode"     "DI")])
1594
1595 ;; For the mips16, we need to recognize stack pointer subtractions
1596 ;; explicitly, since we don't have a constraint for $sp.  These insns
1597 ;; will be generated by the save_restore_insns functions.
1598
1599 (define_insn ""
1600   [(set (reg:DI 29)
1601         (minus:DI (reg:DI 29)
1602                   (match_operand:DI 0 "small_int" "I")))]
1603   "TARGET_MIPS16
1604    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1605   "daddu\\t%$,%$,%n0"
1606   [(set_attr "type"     "arith")
1607    (set_attr "mode"     "DI")
1608    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_nsimm8_8" "")
1609                                       (const_int 4)
1610                                       (const_int 8)))])
1611
1612 (define_insn ""
1613   [(set (match_operand:DI 0 "register_operand" "=d")
1614         (minus:DI (reg:DI 29)
1615                   (match_operand:DI 1 "small_int" "I")))]
1616   "TARGET_MIPS16
1617    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1618   "daddu\\t%0,%$,%n1"
1619   [(set_attr "type"     "arith")
1620    (set_attr "mode"     "DI")
1621    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_nuimm5_4" "")
1622                                       (const_int 4)
1623                                       (const_int 8)))])
1624
1625 (define_insn ""
1626   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1627         (minus:DI (match_operand:DI 1 "register_operand" "0,d,d")
1628                   (match_operand:DI 2 "arith_operand" "I,O,d")))]
1629   "TARGET_MIPS16
1630    && (GET_CODE (operands[2]) != CONST_INT
1631        || (INTVAL (operands[2]) != -32768 && INTVAL (operands[2]) != -0x4000))"
1632   "*
1633 {
1634   if (REGNO (operands[0]) == REGNO (operands[1]))
1635     return \"dsubu\\t%0,%2\";
1636   return \"dsubu\\t%0,%1,%2\";
1637 }"
1638   [(set_attr "type"     "arith")
1639    (set_attr "mode"     "DI")
1640    (set_attr_alternative "length"
1641                 [(if_then_else (match_operand:VOID 2 "m16_nsimm5_1" "")
1642                                (const_int 4)
1643                                (const_int 8))
1644                  (if_then_else (match_operand:VOID 2 "m16_nsimm4_1" "")
1645                                (const_int 4)
1646                                (const_int 8))
1647                  (const_int 4)])])
1648
1649 ;; On the mips16, we can sometimes split an add of a constant which is
1650 ;; a 4 byte instruction into two adds which are both 2 byte
1651 ;; instructions.  There are two cases: one where we are adding a
1652 ;; constant plus a register to another register, and one where we are
1653 ;; simply adding a constant to a register.
1654
1655 (define_split
1656   [(set (match_operand:DI 0 "register_operand" "")
1657         (minus:DI (match_dup 0)
1658                   (match_operand:DI 1 "const_int_operand" "")))]
1659   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1660    && GET_CODE (operands[0]) == REG
1661    && M16_REG_P (REGNO (operands[0]))
1662    && GET_CODE (operands[1]) == CONST_INT
1663    && ((INTVAL (operands[1]) > 0x10
1664         && INTVAL (operands[1]) <= 0x10 + 0x10)
1665        || (INTVAL (operands[1]) < - 0xf
1666            && INTVAL (operands[1]) >= - 0xf - 0xf))"
1667   [(set (match_dup 0) (minus:DI (match_dup 0) (match_dup 1)))
1668    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
1669   "
1670 {
1671   HOST_WIDE_INT val = INTVAL (operands[1]);
1672
1673   if (val >= 0)
1674     {
1675       operands[1] = GEN_INT (0xf);
1676       operands[2] = GEN_INT (val - 0xf);
1677     }
1678   else
1679     {
1680       operands[1] = GEN_INT (- 0x10);
1681       operands[2] = GEN_INT (val + 0x10);
1682     }
1683 }")
1684
1685 (define_split
1686   [(set (match_operand:DI 0 "register_operand" "")
1687         (minus:DI (match_operand:DI 1 "register_operand" "")
1688                   (match_operand:DI 2 "const_int_operand" "")))]
1689   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1690    && GET_CODE (operands[0]) == REG
1691    && M16_REG_P (REGNO (operands[0]))
1692    && GET_CODE (operands[1]) == REG
1693    && M16_REG_P (REGNO (operands[1]))
1694    && REGNO (operands[0]) != REGNO (operands[1])
1695    && GET_CODE (operands[2]) == CONST_INT
1696    && ((INTVAL (operands[2]) > 0x8
1697         && INTVAL (operands[2]) <= 0x8 + 0x10)
1698        || (INTVAL (operands[2]) < - 0x7
1699            && INTVAL (operands[2]) >= - 0x7 - 0xf))"
1700   [(set (match_dup 0) (minus:DI (match_dup 1) (match_dup 2)))
1701    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 3)))]
1702   "
1703 {
1704   HOST_WIDE_INT val = INTVAL (operands[2]);
1705
1706   if (val >= 0)
1707     {
1708       operands[2] = GEN_INT (0x8);
1709       operands[3] = GEN_INT (val - 0x8);
1710     }
1711   else
1712     {
1713       operands[2] = GEN_INT (- 0x7);
1714       operands[3] = GEN_INT (val + 0x7);
1715     }
1716 }")
1717
1718 (define_insn "subsi3_internal_2"
1719   [(set (match_operand:DI 0 "register_operand" "=d")
1720         (sign_extend:DI (minus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ")
1721                                   (match_operand:SI 2 "arith_operand" "dI"))))]
1722   "TARGET_64BIT && !TARGET_MIPS16
1723    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1724   "*
1725 {
1726   return (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
1727     ? \"addu\\t%0,%z1,%n2\"
1728     : \"subu\\t%0,%z1,%2\";
1729 }"
1730   [(set_attr "type"     "arith")
1731    (set_attr "mode"     "DI")])
1732
1733 (define_insn ""
1734   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1735         (sign_extend:DI (minus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1736                                   (match_operand:SI 2 "arith_operand" "I,O,d"))))]
1737   "TARGET_64BIT && TARGET_MIPS16
1738    && (GET_CODE (operands[2]) != CONST_INT
1739        || (INTVAL (operands[2]) != -32768 && INTVAL (operands[2]) != -0x4000))"
1740   "*
1741 {
1742   if (REGNO (operands[0]) == REGNO (operands[1]))
1743     return \"subu\\t%0,%2\";
1744   return \"subu\\t%0,%1,%2\";
1745 }"
1746   [(set_attr "type"     "arith")
1747    (set_attr "mode"     "SI")
1748    (set_attr_alternative "length"
1749                 [(if_then_else (match_operand:VOID 2 "m16_nsimm8_1" "")
1750                                (const_int 4)
1751                                (const_int 8))
1752                  (if_then_else (match_operand:VOID 2 "m16_nsimm4_1" "")
1753                                (const_int 4)
1754                                (const_int 8))
1755                  (const_int 4)])])
1756
1757
1758 \f
1759 ;;
1760 ;;  ....................
1761 ;;
1762 ;;      MULTIPLICATION
1763 ;;
1764 ;;  ....................
1765 ;;
1766
1767 ;; Early Vr4300 silicon has a CPU bug where multiplies with certain
1768 ;; operands may corrupt immediately following multiplies. This is a
1769 ;; simple fix to insert NOPs.
1770
1771 (define_expand "muldf3"
1772   [(set (match_operand:DF 0 "register_operand" "=f")
1773         (mult:DF (match_operand:DF 1 "register_operand" "f")
1774                  (match_operand:DF 2 "register_operand" "f")))]
1775   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
1776   "
1777 {
1778   if (!TARGET_MIPS4300)
1779     emit_insn (gen_muldf3_internal (operands[0], operands[1], operands[2]));
1780   else
1781     emit_insn (gen_muldf3_r4300 (operands[0], operands[1], operands[2]));
1782   DONE;
1783 }")
1784
1785 (define_insn "muldf3_internal"
1786   [(set (match_operand:DF 0 "register_operand" "=f")
1787         (mult:DF (match_operand:DF 1 "register_operand" "f")
1788                  (match_operand:DF 2 "register_operand" "f")))]
1789   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_MIPS4300"
1790   "mul.d\\t%0,%1,%2"
1791   [(set_attr "type"     "fmul")
1792    (set_attr "mode"     "DF")])
1793
1794 (define_insn "muldf3_r4300"
1795   [(set (match_operand:DF 0 "register_operand" "=f")
1796         (mult:DF (match_operand:DF 1 "register_operand" "f")
1797                  (match_operand:DF 2 "register_operand" "f")))]
1798   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_MIPS4300"
1799   "*
1800 {
1801   output_asm_insn (\"mul.d\\t%0,%1,%2\", operands);
1802   if (TARGET_4300_MUL_FIX)
1803     output_asm_insn (\"nop\", operands);
1804   return \"\";
1805 }"
1806   [(set_attr "type"     "fmul")
1807    (set_attr "mode"     "DF")
1808    (set_attr "length"   "8")])  ;; mul.d + nop
1809
1810 (define_expand "mulsf3"
1811   [(set (match_operand:SF 0 "register_operand" "=f")
1812         (mult:SF (match_operand:SF 1 "register_operand" "f")
1813                  (match_operand:SF 2 "register_operand" "f")))]
1814   "TARGET_HARD_FLOAT"
1815   "
1816 {
1817   if (!TARGET_MIPS4300)
1818     emit_insn( gen_mulsf3_internal (operands[0], operands[1], operands[2]));
1819   else
1820     emit_insn( gen_mulsf3_r4300 (operands[0], operands[1], operands[2]));
1821   DONE;
1822 }")
1823
1824 (define_insn "mulsf3_internal"
1825   [(set (match_operand:SF 0 "register_operand" "=f")
1826         (mult:SF (match_operand:SF 1 "register_operand" "f")
1827                  (match_operand:SF 2 "register_operand" "f")))]
1828   "TARGET_HARD_FLOAT && !TARGET_MIPS4300"
1829   "mul.s\\t%0,%1,%2"
1830   [(set_attr "type"     "fmul")
1831    (set_attr "mode"     "SF")])
1832
1833 (define_insn "mulsf3_r4300"
1834   [(set (match_operand:SF 0 "register_operand" "=f")
1835         (mult:SF (match_operand:SF 1 "register_operand" "f")
1836                  (match_operand:SF 2 "register_operand" "f")))]
1837   "TARGET_HARD_FLOAT && TARGET_MIPS4300"
1838   "*
1839 {
1840   output_asm_insn (\"mul.s\\t%0,%1,%2\", operands);
1841   if (TARGET_4300_MUL_FIX)
1842     output_asm_insn (\"nop\", operands);
1843   return \"\";
1844 }"
1845   [(set_attr "type"     "fmul")
1846    (set_attr "mode"     "SF")
1847    (set_attr "length"   "8")])  ;; mul.s + nop
1848
1849
1850 ;; ??? The R4000 (only) has a cpu bug.  If a double-word shift executes while
1851 ;; a multiply is in progress, it may give an incorrect result.  Avoid
1852 ;; this by keeping the mflo with the mult on the R4000.
1853
1854 (define_expand "mulsi3"
1855   [(set (match_operand:SI 0 "register_operand" "")
1856         (mult:SI (match_operand:SI 1 "register_operand" "")
1857                  (match_operand:SI 2 "register_operand" "")))]
1858   ""
1859   "
1860 {
1861   if (GENERATE_MULT3_SI || TARGET_MAD)
1862     emit_insn (gen_mulsi3_mult3 (operands[0], operands[1], operands[2]));
1863   else if (!TARGET_MIPS4000 || TARGET_MIPS16)
1864     emit_insn (gen_mulsi3_internal (operands[0], operands[1], operands[2]));
1865   else
1866     emit_insn (gen_mulsi3_r4000 (operands[0], operands[1], operands[2]));
1867   DONE;
1868 }")
1869
1870 (define_insn "mulsi3_mult3"
1871   [(set (match_operand:SI 0 "register_operand" "=d,l")
1872         (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1873                  (match_operand:SI 2 "register_operand" "d,d")))
1874    (clobber (match_scratch:SI 3 "=h,h"))
1875    (clobber (match_scratch:SI 4 "=l,X"))]
1876   "GENERATE_MULT3_SI
1877    || TARGET_MAD"
1878   "*
1879 {
1880   if (which_alternative == 1)
1881     return \"mult\\t%1,%2\";
1882   if (TARGET_MAD
1883       || TARGET_MIPS5400
1884       || TARGET_MIPS5500
1885       || ISA_MIPS32
1886       || ISA_MIPS32R2
1887       || ISA_MIPS64)
1888     return \"mul\\t%0,%1,%2\";
1889   return \"mult\\t%0,%1,%2\";
1890 }"
1891   [(set_attr "type"     "imul")
1892    (set_attr "mode"     "SI")])
1893
1894 ;; If a register gets allocated to LO, and we spill to memory, the reload
1895 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1896 ;; if it can set the GPR directly.
1897 ;;
1898 ;; Operand 0: LO
1899 ;; Operand 1: GPR (1st multiplication operand)
1900 ;; Operand 2: GPR (2nd multiplication operand)
1901 ;; Operand 3: HI
1902 ;; Operand 4: GPR (destination)
1903 (define_peephole2
1904   [(parallel
1905        [(set (match_operand:SI 0 "register_operand" "")
1906              (mult:SI (match_operand:SI 1 "register_operand" "")
1907                       (match_operand:SI 2 "register_operand" "")))
1908         (clobber (match_operand:SI 3 "register_operand" ""))
1909         (clobber (scratch:SI))])
1910    (set (match_operand:SI 4 "register_operand" "")
1911         (match_dup 0))]
1912   "GENERATE_MULT3_SI
1913    && true_regnum (operands[0]) == LO_REGNUM
1914    && GP_REG_P (true_regnum (operands[4]))
1915    && peep2_reg_dead_p (2, operands[0])"
1916   [(parallel
1917        [(set (match_dup 4)
1918              (mult:SI (match_dup 1)
1919                       (match_dup 2)))
1920         (clobber (match_dup 3))
1921         (clobber (match_dup 0))])])
1922
1923 (define_insn "mulsi3_internal"
1924   [(set (match_operand:SI 0 "register_operand" "=l")
1925         (mult:SI (match_operand:SI 1 "register_operand" "d")
1926                  (match_operand:SI 2 "register_operand" "d")))
1927    (clobber (match_scratch:SI 3 "=h"))]
1928   "!TARGET_MIPS4000 || TARGET_MIPS16"
1929   "mult\\t%1,%2"
1930   [(set_attr "type"     "imul")
1931    (set_attr "mode"     "SI")])
1932
1933 (define_insn "mulsi3_r4000"
1934   [(set (match_operand:SI 0 "register_operand" "=d")
1935         (mult:SI (match_operand:SI 1 "register_operand" "d")
1936                  (match_operand:SI 2 "register_operand" "d")))
1937    (clobber (match_scratch:SI 3 "=h"))
1938    (clobber (match_scratch:SI 4 "=l"))]
1939   "TARGET_MIPS4000 && !TARGET_MIPS16"
1940   "mult\t%1,%2\;mflo\t%0"
1941   [(set_attr "type"     "imul")
1942    (set_attr "mode"     "SI")
1943    (set_attr "length"   "8")])
1944
1945 ;; Multiply-accumulate patterns
1946
1947 ;; For processors that can copy the output to a general register:
1948 ;;
1949 ;; The all-d alternative is needed because the combiner will find this
1950 ;; pattern and then register alloc/reload will move registers around to
1951 ;; make them fit, and we don't want to trigger unnecessary loads to LO.
1952 ;;
1953 ;; The last alternative should be made slightly less desirable, but adding
1954 ;; "?" to the constraint is too strong, and causes values to be loaded into
1955 ;; LO even when that's more costly.  For now, using "*d" mostly does the
1956 ;; trick.
1957 (define_insn "*mul_acc_si"
1958   [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1959         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1960                           (match_operand:SI 2 "register_operand" "d,d,d"))
1961                  (match_operand:SI 3 "register_operand" "0,l,*d")))
1962    (clobber (match_scratch:SI 4 "=h,h,h"))
1963    (clobber (match_scratch:SI 5 "=X,3,l"))
1964    (clobber (match_scratch:SI 6 "=X,X,&d"))]
1965   "(TARGET_MIPS3900
1966    || ISA_HAS_MADD_MSUB)
1967    && !TARGET_MIPS16"
1968   "*
1969 {
1970   static const char *const madd[] = { \"madd\\t%1,%2\", \"madd\\t%0,%1,%2\" };
1971   if (which_alternative == 2)
1972     return \"#\";
1973   if (ISA_HAS_MADD_MSUB && which_alternative != 0)
1974     return \"#\";
1975   return madd[which_alternative];
1976 }"
1977   [(set_attr "type"     "imadd,imadd,multi")
1978    (set_attr "mode"     "SI")
1979    (set_attr "length"   "4,4,8")])
1980
1981 ;; Split the above insn if we failed to get LO allocated.
1982 (define_split
1983   [(set (match_operand:SI 0 "register_operand" "")
1984         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
1985                           (match_operand:SI 2 "register_operand" ""))
1986                  (match_operand:SI 3 "register_operand" "")))
1987    (clobber (match_scratch:SI 4 ""))
1988    (clobber (match_scratch:SI 5 ""))
1989    (clobber (match_scratch:SI 6 ""))]
1990   "reload_completed && !TARGET_DEBUG_D_MODE
1991    && GP_REG_P (true_regnum (operands[0]))
1992    && GP_REG_P (true_regnum (operands[3]))"
1993   [(parallel [(set (match_dup 6)
1994                    (mult:SI (match_dup 1) (match_dup 2)))
1995               (clobber (match_dup 4))
1996               (clobber (match_dup 5))])
1997    (set (match_dup 0) (plus:SI (match_dup 6) (match_dup 3)))]
1998   "")
1999
2000 ;; Splitter to copy result of MADD to a general register
2001 (define_split
2002   [(set (match_operand:SI                   0 "register_operand" "")
2003         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
2004                           (match_operand:SI 2 "register_operand" ""))
2005                  (match_operand:SI          3 "register_operand" "")))
2006    (clobber (match_scratch:SI               4 ""))
2007    (clobber (match_scratch:SI               5 ""))
2008    (clobber (match_scratch:SI               6 ""))]
2009   "reload_completed && !TARGET_DEBUG_D_MODE
2010    && GP_REG_P (true_regnum (operands[0]))
2011    && true_regnum (operands[3]) == LO_REGNUM"
2012   [(parallel [(set (match_dup 3)
2013                    (plus:SI (mult:SI (match_dup 1) (match_dup 2))
2014                             (match_dup 3)))
2015               (clobber (match_dup 4))
2016               (clobber (match_dup 5))
2017               (clobber (match_dup 6))])
2018    (set (match_dup 0) (match_dup 3))]
2019   "")
2020
2021 (define_insn "*macc"
2022   [(set (match_operand:SI 0 "register_operand" "=l,d")
2023         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2024                           (match_operand:SI 2 "register_operand" "d,d"))
2025                  (match_operand:SI 3 "register_operand" "0,l")))
2026    (clobber (match_scratch:SI 4 "=h,h"))
2027    (clobber (match_scratch:SI 5 "=X,3"))]
2028   "ISA_HAS_MACC"
2029   "*
2030 {
2031   if (which_alternative == 1)
2032     return \"macc\\t%0,%1,%2\";
2033   else if (TARGET_MIPS5500)
2034     return \"madd\\t%1,%2\";
2035   else
2036     return \"macc\\t%.,%1,%2\";
2037 }"
2038   [(set_attr "type" "imadd")
2039    (set_attr "mode" "SI")])
2040
2041 ;; Pattern generated by define_peephole2 below
2042 (define_insn "*macc2"
2043   [(set (match_operand:SI 0 "register_operand" "=l")
2044         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2045                           (match_operand:SI 2 "register_operand" "d"))
2046                  (match_dup 0)))
2047    (set (match_operand:SI 3 "register_operand" "=d")
2048         (plus:SI (mult:SI (match_dup 1)
2049                           (match_dup 2))
2050                  (match_dup 0)))
2051    (clobber (match_scratch:SI 4 "=h"))]
2052   "ISA_HAS_MACC && reload_completed"
2053   "macc\\t%3,%1,%2"
2054   [(set_attr "type"     "imadd")
2055    (set_attr "mode"     "SI")])
2056
2057 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
2058 ;;
2059 ;; Operand 0: LO
2060 ;; Operand 1: GPR (1st multiplication operand)
2061 ;; Operand 2: GPR (2nd multiplication operand)
2062 ;; Operand 3: HI
2063 ;; Operand 4: GPR (destination)
2064 (define_peephole2
2065   [(parallel
2066        [(set (match_operand:SI 0 "register_operand" "")
2067              (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
2068                                (match_operand:SI 2 "register_operand" ""))
2069                       (match_dup 0)))
2070         (clobber (match_operand:SI 3 "register_operand" ""))
2071         (clobber (scratch:SI))])
2072    (set (match_operand:SI 4 "register_operand" "")
2073         (match_dup 0))]
2074   "ISA_HAS_MACC
2075    && true_regnum (operands[0]) == LO_REGNUM
2076    && GP_REG_P (true_regnum (operands[4]))"
2077   [(parallel [(set (match_dup 0)
2078                    (plus:SI (mult:SI (match_dup 1)
2079                                      (match_dup 2))
2080                             (match_dup 0)))
2081               (set (match_dup 4)
2082                    (plus:SI (mult:SI (match_dup 1)
2083                                      (match_dup 2))
2084                             (match_dup 0)))
2085               (clobber (match_dup 3))])]
2086   "")
2087
2088 ;; When we have a three-address multiplication instruction, it should
2089 ;; be faster to do a separate multiply and add, rather than moving
2090 ;; something into LO in order to use a macc instruction.
2091 ;;
2092 ;; This peephole needs a scratch register to cater for the case when one
2093 ;; of the multiplication operands is the same as the destination.
2094 ;;
2095 ;; Operand 0: GPR (scratch)
2096 ;; Operand 1: LO
2097 ;; Operand 2: GPR (addend)
2098 ;; Operand 3: GPR (destination)
2099 ;; Operand 4: GPR (1st multiplication operand)
2100 ;; Operand 5: GPR (2nd multiplication operand)
2101 ;; Operand 6: HI
2102 (define_peephole2
2103   [(match_scratch:SI 0 "d")
2104    (set (match_operand:SI 1 "register_operand" "")
2105         (match_operand:SI 2 "register_operand" ""))
2106    (match_dup 0)
2107    (parallel
2108        [(set (match_operand:SI 3 "register_operand" "")
2109              (plus:SI (mult:SI (match_operand:SI 4 "register_operand" "")
2110                                (match_operand:SI 5 "register_operand" ""))
2111                       (match_dup 1)))
2112         (clobber (match_operand:SI 6 "register_operand" ""))
2113         (clobber (match_dup 1))])]
2114   "ISA_HAS_MACC && GENERATE_MULT3_SI
2115    && true_regnum (operands[1]) == LO_REGNUM
2116    && peep2_reg_dead_p (2, operands[1])
2117    && GP_REG_P (true_regnum (operands[3]))"
2118   [(parallel [(set (match_dup 0)
2119                    (mult:SI (match_dup 4)
2120                             (match_dup 5)))
2121               (clobber (match_dup 6))
2122               (clobber (match_dup 1))])
2123    (set (match_dup 3)
2124         (plus:SI (match_dup 0)
2125                  (match_dup 2)))]
2126   "")
2127
2128 ;; Same as above, except LO is the initial target of the macc.
2129 ;;
2130 ;; Operand 0: GPR (scratch)
2131 ;; Operand 1: LO
2132 ;; Operand 2: GPR (addend)
2133 ;; Operand 3: GPR (1st multiplication operand)
2134 ;; Operand 4: GPR (2nd multiplication operand)
2135 ;; Operand 5: HI
2136 ;; Operand 6: GPR (destination)
2137 (define_peephole2
2138   [(match_scratch:SI 0 "d")
2139    (set (match_operand:SI 1 "register_operand" "")
2140         (match_operand:SI 2 "register_operand" ""))
2141    (match_dup 0)
2142    (parallel
2143        [(set (match_dup 1)
2144              (plus:SI (mult:SI (match_operand:SI 3 "register_operand" "")
2145                                (match_operand:SI 4 "register_operand" ""))
2146                       (match_dup 1)))
2147         (clobber (match_operand:SI 5 "register_operand" ""))
2148         (clobber (scratch:SI))])
2149    (match_dup 0)
2150    (set (match_operand:SI 6 "register_operand" "")
2151         (match_dup 1))]
2152   "ISA_HAS_MACC && GENERATE_MULT3_SI
2153    && true_regnum (operands[1]) == LO_REGNUM
2154    && peep2_reg_dead_p (3, operands[1])
2155    && GP_REG_P (true_regnum (operands[6]))"
2156   [(parallel [(set (match_dup 0)
2157                    (mult:SI (match_dup 3)
2158                             (match_dup 4)))
2159               (clobber (match_dup 5))
2160               (clobber (match_dup 1))])
2161    (set (match_dup 6)
2162         (plus:SI (match_dup 0)
2163                  (match_dup 2)))]
2164   "")
2165
2166 (define_insn "*mul_sub_si"
2167   [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
2168         (minus:SI (match_operand:SI 1 "register_operand" "0,l,*d")
2169                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
2170                            (match_operand:SI 3 "register_operand" "d,d,d"))))
2171    (clobber (match_scratch:SI 4 "=h,h,h"))
2172    (clobber (match_scratch:SI 5 "=X,1,l"))
2173    (clobber (match_scratch:SI 6 "=X,X,&d"))]
2174   "ISA_HAS_MADD_MSUB"
2175   "*
2176 {
2177   if (which_alternative != 0)
2178     return \"#\";
2179   return \"msub\\t%2,%3\";
2180 }"
2181   [(set_attr "type"     "imadd,multi,multi")
2182    (set_attr "mode"     "SI")
2183    (set_attr "length"   "4,8,8")])
2184
2185 ;; Split the above insn if we failed to get LO allocated.
2186 (define_split
2187   [(set (match_operand:SI 0 "register_operand" "")
2188         (minus:SI (match_operand:SI 1 "register_operand" "")
2189                   (mult:SI (match_operand:SI 2 "register_operand" "")
2190                            (match_operand:SI 3 "register_operand" ""))))
2191    (clobber (match_scratch:SI 4 ""))
2192    (clobber (match_scratch:SI 5 ""))
2193    (clobber (match_scratch:SI 6 ""))]
2194   "reload_completed && !TARGET_DEBUG_D_MODE
2195    && GP_REG_P (true_regnum (operands[0]))
2196    && GP_REG_P (true_regnum (operands[1]))"
2197   [(parallel [(set (match_dup 6)
2198                    (mult:SI (match_dup 2) (match_dup 3)))
2199               (clobber (match_dup 4))
2200               (clobber (match_dup 5))])
2201    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 6)))]
2202   "")
2203
2204 ;; Splitter to copy result of MSUB to a general register
2205 (define_split
2206   [(set (match_operand:SI 0 "register_operand" "")
2207         (minus:SI (match_operand:SI 1 "register_operand" "")
2208                   (mult:SI (match_operand:SI 2 "register_operand" "")
2209                            (match_operand:SI 3 "register_operand" ""))))
2210    (clobber (match_scratch:SI 4 ""))
2211    (clobber (match_scratch:SI 5 ""))
2212    (clobber (match_scratch:SI 6 ""))]
2213   "reload_completed && !TARGET_DEBUG_D_MODE
2214    && GP_REG_P (true_regnum (operands[0]))
2215    && true_regnum (operands[1]) == LO_REGNUM"
2216   [(parallel [(set (match_dup 1)
2217                    (minus:SI (match_dup 1)
2218                              (mult:SI (match_dup 2) (match_dup 3))))
2219               (clobber (match_dup 4))
2220               (clobber (match_dup 5))
2221               (clobber (match_dup 6))])
2222    (set (match_dup 0) (match_dup 1))]
2223   "")
2224
2225 (define_insn "*muls"
2226   [(set (match_operand:SI                  0 "register_operand" "=l,d")
2227         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2228                          (match_operand:SI 2 "register_operand" "d,d"))))
2229    (clobber (match_scratch:SI              3                    "=h,h"))
2230    (clobber (match_scratch:SI              4                    "=X,l"))]
2231   "ISA_HAS_MULS"
2232   "@
2233    muls\\t$0,%1,%2
2234    muls\\t%0,%1,%2"
2235   [(set_attr "type"     "imul")
2236    (set_attr "mode"     "SI")])
2237
2238 (define_insn "*msac"
2239   [(set (match_operand:SI 0 "register_operand" "=l,d")
2240         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
2241                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
2242                            (match_operand:SI 3 "register_operand" "d,d"))))
2243    (clobber (match_scratch:SI 4 "=h,h"))
2244    (clobber (match_scratch:SI 5 "=X,1"))]
2245   "ISA_HAS_MSAC"
2246   "*
2247 {
2248   if (which_alternative == 1)
2249     return \"msac\\t%0,%2,%3\";
2250   else if (TARGET_MIPS5500)
2251     return \"msub\\t%2,%3\";
2252   else
2253     return \"msac\\t$0,%2,%3\";
2254 }"
2255   [(set_attr "type"     "imadd")
2256    (set_attr "mode"     "SI")])
2257
2258 (define_expand "muldi3"
2259   [(set (match_operand:DI 0 "register_operand" "")
2260         (mult:DI (match_operand:DI 1 "register_operand" "")
2261                  (match_operand:DI 2 "register_operand" "")))]
2262   "TARGET_64BIT"
2263
2264   "
2265 {
2266   if (GENERATE_MULT3_DI || TARGET_MIPS4000)
2267     emit_insn (gen_muldi3_internal2 (operands[0], operands[1], operands[2]));
2268   else
2269     emit_insn (gen_muldi3_internal (operands[0], operands[1], operands[2]));
2270   DONE;
2271 }")
2272
2273 (define_insn "muldi3_internal"
2274   [(set (match_operand:DI 0 "register_operand" "=l")
2275         (mult:DI (match_operand:DI 1 "register_operand" "d")
2276                  (match_operand:DI 2 "register_operand" "d")))
2277    (clobber (match_scratch:DI 3 "=h"))]
2278   "TARGET_64BIT && !TARGET_MIPS4000"
2279   "dmult\\t%1,%2"
2280   [(set_attr "type"     "imul")
2281    (set_attr "mode"     "DI")])
2282
2283 (define_insn "muldi3_internal2"
2284   [(set (match_operand:DI 0 "register_operand" "=d")
2285         (mult:DI (match_operand:DI 1 "register_operand" "d")
2286                  (match_operand:DI 2 "register_operand" "d")))
2287    (clobber (match_scratch:DI 3 "=h"))
2288    (clobber (match_scratch:DI 4 "=l"))]
2289   "TARGET_64BIT && (GENERATE_MULT3_DI || TARGET_MIPS4000)"
2290   {
2291     if (GENERATE_MULT3_DI)
2292       return "dmult\t%0,%1,%2";
2293     else
2294       return "dmult\t%1,%2\n\tmflo\t%0";
2295   }
2296   [(set_attr "type"     "imul")
2297    (set_attr "mode"     "DI")
2298    (set (attr "length")
2299         (if_then_else (ne (symbol_ref "GENERATE_MULT3_DI") (const_int 0))
2300                       (const_int 4)
2301                       (const_int 8)))])
2302
2303 ;; ??? We could define a mulditi3 pattern when TARGET_64BIT.
2304
2305 (define_expand "mulsidi3"
2306   [(parallel
2307       [(set (match_operand:DI 0 "register_operand" "")
2308             (mult:DI
2309                (sign_extend:DI (match_operand:SI 1 "register_operand" ""))
2310                (sign_extend:DI (match_operand:SI 2 "register_operand" ""))))
2311        (clobber (scratch:DI))
2312        (clobber (scratch:DI))
2313        (clobber (scratch:DI))])]
2314   ""
2315   {
2316     if (!TARGET_64BIT)
2317       {
2318         emit_insn (gen_mulsidi3_32bit (operands[0], operands[1], operands[2]));
2319         DONE;
2320       }
2321    })
2322
2323 (define_insn "mulsidi3_32bit"
2324   [(set (match_operand:DI 0 "register_operand" "=x")
2325         (mult:DI
2326            (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2327            (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2328   "!TARGET_64BIT"
2329   "mult\\t%1,%2"
2330   [(set_attr "type"     "imul")
2331    (set_attr "mode"     "SI")])
2332
2333 (define_insn_and_split "*mulsidi3_64bit"
2334   [(set (match_operand:DI 0 "register_operand" "=d")
2335         (mult:DI (match_operator:DI 1 "extend_operator"
2336                     [(match_operand:SI 3 "register_operand" "d")])
2337                  (match_operator:DI 2 "extend_operator"
2338                     [(match_operand:SI 4 "register_operand" "d")])))
2339    (clobber (match_scratch:DI 5 "=l"))
2340    (clobber (match_scratch:DI 6 "=h"))
2341    (clobber (match_scratch:DI 7 "=d"))]
2342   "TARGET_64BIT && GET_CODE (operands[1]) == GET_CODE (operands[2])"
2343   "#"
2344   "&& reload_completed"
2345   [(parallel
2346        [(set (match_dup 5)
2347              (sign_extend:DI
2348                 (mult:SI (match_dup 3)
2349                          (match_dup 4))))
2350         (set (match_dup 6)
2351              (ashiftrt:DI
2352                 (mult:DI (match_dup 1)
2353                          (match_dup 2))
2354                 (const_int 32)))])
2355
2356    ;; OP7 <- LO, OP0 <- HI
2357    (set (match_dup 7) (match_dup 5))
2358    (set (match_dup 0) (match_dup 6))
2359
2360    ;; Zero-extend OP7.
2361    (set (match_dup 7)
2362         (ashift:DI (match_dup 7)
2363                    (const_int 32)))
2364    (set (match_dup 7)
2365         (lshiftrt:DI (match_dup 7)
2366                      (const_int 32)))
2367
2368    ;; Shift OP0 into place.
2369    (set (match_dup 0)
2370         (ashift:DI (match_dup 0)
2371                    (const_int 32)))
2372
2373    ;; OR the two halves together
2374    (set (match_dup 0)
2375         (ior:DI (match_dup 0)
2376                 (match_dup 7)))]
2377   ""
2378   [(set_attr "type"     "imul")
2379    (set_attr "mode"     "SI")
2380    (set_attr "length"   "24")])
2381
2382 (define_insn "*mulsidi3_64bit_parts"
2383   [(set (match_operand:DI 0 "register_operand" "=l")
2384         (sign_extend:DI
2385            (mult:SI (match_operand:SI 2 "register_operand" "d")
2386                     (match_operand:SI 3 "register_operand" "d"))))
2387    (set (match_operand:DI 1 "register_operand" "=h")
2388         (ashiftrt:DI
2389            (mult:DI
2390               (match_operator:DI 4 "extend_operator" [(match_dup 2)])
2391               (match_operator:DI 5 "extend_operator" [(match_dup 3)]))
2392            (const_int 32)))]
2393   "TARGET_64BIT && GET_CODE (operands[4]) == GET_CODE (operands[5])"
2394   {
2395     if (GET_CODE (operands[4]) == SIGN_EXTEND)
2396       return "mult\t%2,%3";
2397     else
2398       return "multu\t%2,%3";
2399   }
2400   [(set_attr "type" "imul")
2401    (set_attr "mode" "SI")])
2402
2403 (define_expand "umulsidi3"
2404   [(parallel
2405       [(set (match_operand:DI 0 "register_operand" "")
2406             (mult:DI
2407                (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
2408                (zero_extend:DI (match_operand:SI 2 "register_operand" ""))))
2409        (clobber (scratch:DI))
2410        (clobber (scratch:DI))
2411        (clobber (scratch:DI))])]
2412   ""
2413   {
2414     if (!TARGET_64BIT)
2415       {
2416         emit_insn (gen_umulsidi3_32bit (operands[0], operands[1],
2417                                         operands[2]));
2418         DONE;
2419       }
2420   })
2421
2422 (define_insn "umulsidi3_32bit"
2423   [(set (match_operand:DI 0 "register_operand" "=x")
2424         (mult:DI
2425            (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2426            (zero_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2427   "!TARGET_64BIT"
2428   "multu\\t%1,%2"
2429   [(set_attr "type"     "imul")
2430    (set_attr "mode"     "SI")])
2431
2432 ;; Widening multiply with negation.
2433 (define_insn "*muls_di"
2434   [(set (match_operand:DI 0 "register_operand" "=x")
2435         (neg:DI
2436          (mult:DI
2437           (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2438           (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2439   "!TARGET_64BIT && ISA_HAS_MULS"
2440   "muls\\t$0,%1,%2"
2441   [(set_attr "type"     "imul")
2442    (set_attr "length"   "4")
2443    (set_attr "mode"     "SI")])
2444
2445 (define_insn "*umuls_di"
2446   [(set (match_operand:DI 0 "register_operand" "=x")
2447         (neg:DI
2448          (mult:DI
2449           (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2450           (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2451   "!TARGET_64BIT && ISA_HAS_MULS"
2452   "mulsu\\t$0,%1,%2"
2453   [(set_attr "type"     "imul")
2454    (set_attr "length"   "4")
2455    (set_attr "mode"     "SI")])
2456
2457 (define_insn "*smsac_di"
2458   [(set (match_operand:DI 0 "register_operand" "=x")
2459         (minus:DI
2460            (match_operand:DI 3 "register_operand" "0")
2461            (mult:DI
2462               (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2463               (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2464   "!TARGET_64BIT && ISA_HAS_MSAC"
2465   "*
2466 {
2467   if (TARGET_MIPS5500)
2468     return \"msub\\t%1,%2\";
2469   else
2470     return \"msac\\t$0,%1,%2\";
2471 }"
2472   [(set_attr "type"     "imadd")
2473    (set_attr "length"   "4")
2474    (set_attr "mode"     "SI")])
2475
2476 (define_insn "*umsac_di"
2477   [(set (match_operand:DI 0 "register_operand" "=x")
2478         (minus:DI
2479            (match_operand:DI 3 "register_operand" "0")
2480            (mult:DI
2481               (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2482               (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2483   "!TARGET_64BIT && ISA_HAS_MSAC"
2484   "*
2485 {
2486   if (TARGET_MIPS5500)
2487     return \"msubu\\t%1,%2\";
2488   else
2489     return \"msacu\\t$0,%1,%2\";
2490 }"
2491   [(set_attr "type"     "imadd")
2492    (set_attr "length"   "4")
2493    (set_attr "mode"     "SI")])
2494
2495 ;; _highpart patterns
2496 (define_expand "umulsi3_highpart"
2497   [(set (match_operand:SI 0 "register_operand" "")
2498         (truncate:SI
2499          (lshiftrt:DI
2500           (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" ""))
2501                    (zero_extend:DI (match_operand:SI 2 "register_operand" "")))
2502           (const_int 32))))]
2503   ""
2504   "
2505 {
2506   if (ISA_HAS_MULHI)
2507     emit_insn (gen_umulsi3_highpart_mulhi_internal (operands[0], operands[1],
2508                                                     operands[2]));
2509   else
2510     emit_insn (gen_umulsi3_highpart_internal (operands[0], operands[1],
2511                                               operands[2]));
2512   DONE;
2513 }")
2514
2515 (define_insn "umulsi3_highpart_internal"
2516   [(set (match_operand:SI 0 "register_operand" "=h")
2517         (truncate:SI
2518          (lshiftrt:DI
2519           (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2520                    (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))
2521           (const_int 32))))
2522    (clobber (match_scratch:SI 3 "=l"))]
2523   "!ISA_HAS_MULHI"
2524   "multu\\t%1,%2"
2525   [(set_attr "type"   "imul")
2526    (set_attr "mode"   "SI")
2527    (set_attr "length" "4")])
2528
2529 (define_insn "umulsi3_highpart_mulhi_internal"
2530   [(set (match_operand:SI 0 "register_operand" "=h,d")
2531         (truncate:SI
2532          (lshiftrt:DI
2533           (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2534                    (zero_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
2535           (const_int 32))))
2536    (clobber (match_scratch:SI 3 "=l,l"))
2537    (clobber (match_scratch:SI 4 "=X,h"))]
2538   "ISA_HAS_MULHI"
2539   "@
2540    multu\\t%1,%2
2541    mulhiu\\t%0,%1,%2"
2542   [(set_attr "type"   "imul")
2543    (set_attr "mode"   "SI")
2544    (set_attr "length" "4")])
2545
2546 (define_insn "umulsi3_highpart_neg_mulhi_internal"
2547   [(set (match_operand:SI 0 "register_operand" "=h,d")
2548         (truncate:SI
2549          (lshiftrt:DI
2550           (neg:DI
2551            (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2552                     (zero_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
2553           (const_int 32))))
2554    (clobber (match_scratch:SI 3 "=l,l"))
2555    (clobber (match_scratch:SI 4 "=X,h"))]
2556   "ISA_HAS_MULHI"
2557   "@
2558    mulshiu\\t%.,%1,%2
2559    mulshiu\\t%0,%1,%2"
2560   [(set_attr "type"   "imul")
2561    (set_attr "mode"   "SI")
2562    (set_attr "length" "4")])
2563
2564 (define_expand "smulsi3_highpart"
2565   [(set (match_operand:SI 0 "register_operand" "")
2566         (truncate:SI
2567          (lshiftrt:DI
2568           (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" ""))
2569                    (sign_extend:DI (match_operand:SI 2 "register_operand" "")))
2570          (const_int 32))))]
2571   ""
2572   "
2573 {
2574   if (ISA_HAS_MULHI)
2575     emit_insn (gen_smulsi3_highpart_mulhi_internal (operands[0], operands[1],
2576                                                     operands[2]));
2577   else
2578     emit_insn (gen_smulsi3_highpart_internal (operands[0], operands[1],
2579                                               operands[2]));
2580   DONE;
2581 }")
2582
2583 (define_insn "smulsi3_highpart_internal"
2584   [(set (match_operand:SI 0 "register_operand" "=h")
2585         (truncate:SI
2586          (lshiftrt:DI
2587           (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2588                    (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))
2589           (const_int 32))))
2590    (clobber (match_scratch:SI 3 "=l"))]
2591   "!ISA_HAS_MULHI"
2592   "mult\\t%1,%2"
2593   [(set_attr "type"     "imul")
2594    (set_attr "mode"     "SI")
2595    (set_attr "length"   "4")])
2596
2597 (define_insn "smulsi3_highpart_mulhi_internal"
2598   [(set (match_operand:SI 0 "register_operand" "=h,d")
2599         (truncate:SI
2600          (lshiftrt:DI
2601           (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2602                    (sign_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
2603           (const_int 32))))
2604    (clobber (match_scratch:SI 3 "=l,l"))
2605    (clobber (match_scratch:SI 4 "=X,h"))]
2606   "ISA_HAS_MULHI"
2607   "@
2608    mult\\t%1,%2
2609    mulhi\\t%0,%1,%2"
2610   [(set_attr "type"   "imul")
2611    (set_attr "mode"   "SI")
2612    (set_attr "length" "4")])
2613
2614 (define_insn "smulsi3_highpart_neg_mulhi_internal"
2615   [(set (match_operand:SI 0 "register_operand" "=h,d")
2616         (truncate:SI
2617          (lshiftrt:DI
2618           (neg:DI
2619            (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2620                     (sign_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
2621           (const_int 32))))
2622    (clobber (match_scratch:SI 3 "=l,l"))
2623    (clobber (match_scratch:SI 4 "=X,h"))]
2624   "ISA_HAS_MULHI"
2625   "@
2626    mulshi\\t%.,%1,%2
2627    mulshi\\t%0,%1,%2"
2628   [(set_attr "type"   "imul")
2629    (set_attr "mode"   "SI")])
2630
2631 (define_insn "smuldi3_highpart"
2632   [(set (match_operand:DI 0 "register_operand" "=h")
2633         (truncate:DI
2634          (lshiftrt:TI
2635           (mult:TI
2636            (sign_extend:TI (match_operand:DI 1 "register_operand" "d"))
2637            (sign_extend:TI (match_operand:DI 2 "register_operand" "d")))
2638          (const_int 64))))
2639    (clobber (match_scratch:DI 3 "=l"))]
2640   "TARGET_64BIT"
2641   "dmult\\t%1,%2"
2642   [(set_attr "type"     "imul")
2643    (set_attr "mode"     "DI")])
2644
2645 (define_insn "umuldi3_highpart"
2646   [(set (match_operand:DI 0 "register_operand" "=h")
2647         (truncate:DI
2648          (lshiftrt:TI
2649           (mult:TI
2650            (zero_extend:TI (match_operand:DI 1 "register_operand" "d"))
2651            (zero_extend:TI (match_operand:DI 2 "register_operand" "d")))
2652           (const_int 64))))
2653    (clobber (match_scratch:DI 3 "=l"))]
2654   "TARGET_64BIT"
2655   "dmultu\\t%1,%2"
2656   [(set_attr "type"     "imul")
2657    (set_attr "mode"     "DI")])
2658
2659
2660 ;; The R4650 supports a 32 bit multiply/ 64 bit accumulate
2661 ;; instruction.  The HI/LO registers are used as a 64 bit accumulator.
2662
2663 (define_insn "madsi"
2664   [(set (match_operand:SI 0 "register_operand" "+l")
2665         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2666                           (match_operand:SI 2 "register_operand" "d"))
2667                  (match_dup 0)))
2668    (clobber (match_scratch:SI 3 "=h"))]
2669   "TARGET_MAD"
2670   "mad\\t%1,%2"
2671   [(set_attr "type"     "imadd")
2672    (set_attr "mode"     "SI")])
2673
2674 (define_insn "*umul_acc_di"
2675   [(set (match_operand:DI 0 "register_operand" "=x")
2676         (plus:DI
2677          (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2678                   (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))
2679          (match_operand:DI 3 "register_operand" "0")))]
2680   "(TARGET_MAD || ISA_HAS_MACC)
2681    && !TARGET_64BIT"
2682   "*
2683 {
2684   if (TARGET_MAD)
2685     return \"madu\\t%1,%2\";
2686   else if (TARGET_MIPS5500)
2687     return \"maddu\\t%1,%2\";
2688   else
2689     return \"maccu\\t%.,%1,%2\";
2690 }"
2691   [(set_attr "type"   "imadd")
2692    (set_attr "mode"   "SI")])
2693
2694
2695 (define_insn "*smul_acc_di"
2696   [(set (match_operand:DI 0 "register_operand" "=x")
2697         (plus:DI
2698          (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2699                   (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))
2700          (match_operand:DI 3 "register_operand" "0")))]
2701   "(TARGET_MAD || ISA_HAS_MACC)
2702    && !TARGET_64BIT"
2703   "*
2704 {
2705   if (TARGET_MAD)
2706     return \"mad\\t%1,%2\";
2707   else if (TARGET_MIPS5500)
2708     return \"madd\\t%1,%2\";
2709   else
2710     return \"macc\\t%.,%1,%2\";
2711 }"
2712   [(set_attr "type"   "imadd")
2713    (set_attr "mode"   "SI")])
2714
2715 ;; Floating point multiply accumulate instructions.
2716
2717 (define_insn ""
2718   [(set (match_operand:DF 0 "register_operand" "=f")
2719         (plus:DF (mult:DF (match_operand:DF 1 "register_operand" "f")
2720                           (match_operand:DF 2 "register_operand" "f"))
2721                  (match_operand:DF 3 "register_operand" "f")))]
2722   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2723   "madd.d\\t%0,%3,%1,%2"
2724   [(set_attr "type"     "fmadd")
2725    (set_attr "mode"     "DF")])
2726
2727 (define_insn ""
2728   [(set (match_operand:SF 0 "register_operand" "=f")
2729         (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "f")
2730                           (match_operand:SF 2 "register_operand" "f"))
2731                  (match_operand:SF 3 "register_operand" "f")))]
2732   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2733   "madd.s\\t%0,%3,%1,%2"
2734   [(set_attr "type"     "fmadd")
2735    (set_attr "mode"     "SF")])
2736
2737 (define_insn ""
2738   [(set (match_operand:DF 0 "register_operand" "=f")
2739         (minus:DF (mult:DF (match_operand:DF 1 "register_operand" "f")
2740                            (match_operand:DF 2 "register_operand" "f"))
2741                   (match_operand:DF 3 "register_operand" "f")))]
2742   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2743   "msub.d\\t%0,%3,%1,%2"
2744   [(set_attr "type"     "fmadd")
2745    (set_attr "mode"     "DF")])
2746
2747 (define_insn ""
2748   [(set (match_operand:SF 0 "register_operand" "=f")
2749         (minus:SF (mult:SF (match_operand:SF 1 "register_operand" "f")
2750                            (match_operand:SF 2 "register_operand" "f"))
2751                   (match_operand:SF 3 "register_operand" "f")))]
2752
2753   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2754   "msub.s\\t%0,%3,%1,%2"
2755   [(set_attr "type"     "fmadd")
2756    (set_attr "mode"     "SF")])
2757
2758 (define_insn ""
2759   [(set (match_operand:DF 0 "register_operand" "=f")
2760         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "register_operand" "f")
2761                                   (match_operand:DF 2 "register_operand" "f"))
2762                          (match_operand:DF 3 "register_operand" "f"))))]
2763   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2764   "nmadd.d\\t%0,%3,%1,%2"
2765   [(set_attr "type"     "fmadd")
2766    (set_attr "mode"     "DF")])
2767
2768 (define_insn ""
2769   [(set (match_operand:SF 0 "register_operand" "=f")
2770         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "f")
2771                                   (match_operand:SF 2 "register_operand" "f"))
2772                          (match_operand:SF 3 "register_operand" "f"))))]
2773   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2774   "nmadd.s\\t%0,%3,%1,%2"
2775   [(set_attr "type"     "fmadd")
2776    (set_attr "mode"     "SF")])
2777
2778 (define_insn ""
2779   [(set (match_operand:DF 0 "register_operand" "=f")
2780         (minus:DF (match_operand:DF 1 "register_operand" "f")
2781                   (mult:DF (match_operand:DF 2 "register_operand" "f")
2782                            (match_operand:DF 3 "register_operand" "f"))))]
2783   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2784   "nmsub.d\\t%0,%1,%2,%3"
2785   [(set_attr "type"     "fmadd")
2786    (set_attr "mode"     "DF")])
2787
2788 (define_insn ""
2789   [(set (match_operand:SF 0 "register_operand" "=f")
2790         (minus:SF (match_operand:SF 1 "register_operand" "f")
2791                   (mult:SF (match_operand:SF 2 "register_operand" "f")
2792                            (match_operand:SF 3 "register_operand" "f"))))]
2793   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2794   "nmsub.s\\t%0,%1,%2,%3"
2795   [(set_attr "type"     "fmadd")
2796    (set_attr "mode"     "SF")])
2797 \f
2798 ;;
2799 ;;  ....................
2800 ;;
2801 ;;      DIVISION and REMAINDER
2802 ;;
2803 ;;  ....................
2804 ;;
2805
2806 (define_insn "divdf3"
2807   [(set (match_operand:DF 0 "register_operand" "=f")
2808         (div:DF (match_operand:DF 1 "register_operand" "f")
2809                 (match_operand:DF 2 "register_operand" "f")))]
2810   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2811   "div.d\\t%0,%1,%2"
2812   [(set_attr "type"     "fdiv")
2813    (set_attr "mode"     "DF")])
2814
2815 (define_insn "divsf3"
2816   [(set (match_operand:SF 0 "register_operand" "=f")
2817         (div:SF (match_operand:SF 1 "register_operand" "f")
2818                 (match_operand:SF 2 "register_operand" "f")))]
2819   "TARGET_HARD_FLOAT"
2820   "div.s\\t%0,%1,%2"
2821   [(set_attr "type"     "fdiv")
2822    (set_attr "mode"     "SF")])
2823
2824 (define_insn ""
2825   [(set (match_operand:DF 0 "register_operand" "=f")
2826         (div:DF (match_operand:DF 1 "const_float_1_operand" "")
2827                 (match_operand:DF 2 "register_operand" "f")))]
2828   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && flag_unsafe_math_optimizations"
2829   "recip.d\\t%0,%2"
2830   [(set_attr "type"     "fdiv")
2831    (set_attr "mode"     "DF")])
2832
2833 (define_insn ""
2834   [(set (match_operand:SF 0 "register_operand" "=f")
2835         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
2836                 (match_operand:SF 2 "register_operand" "f")))]
2837   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
2838   "recip.s\\t%0,%2"
2839   [(set_attr "type"     "fdiv")
2840    (set_attr "mode"     "SF")])
2841
2842 (define_insn "divmodsi4"
2843   [(set (match_operand:SI 0 "register_operand" "=l")
2844         (div:SI (match_operand:SI 1 "register_operand" "d")
2845                 (match_operand:SI 2 "register_operand" "d")))
2846    (set (match_operand:SI 3 "register_operand" "=h")
2847         (mod:SI (match_dup 1)
2848                 (match_dup 2)))]
2849   ""
2850   { return mips_output_division ("div\\t$0,%1,%2", operands); }
2851   [(set_attr "type"     "idiv")
2852    (set_attr "mode"     "SI")])
2853
2854 (define_insn "divmoddi4"
2855   [(set (match_operand:DI 0 "register_operand" "=l")
2856         (div:DI (match_operand:DI 1 "register_operand" "d")
2857                 (match_operand:DI 2 "register_operand" "d")))
2858    (set (match_operand:DI 3 "register_operand" "=h")
2859         (mod:DI (match_dup 1)
2860                 (match_dup 2)))]
2861   "TARGET_64BIT"
2862   { return mips_output_division ("ddiv\\t$0,%1,%2", operands); }
2863   [(set_attr "type"     "idiv")
2864    (set_attr "mode"     "DI")])
2865
2866 (define_insn "udivmodsi4"
2867   [(set (match_operand:SI 0 "register_operand" "=l")
2868         (udiv:SI (match_operand:SI 1 "register_operand" "d")
2869                  (match_operand:SI 2 "register_operand" "d")))
2870    (set (match_operand:SI 3 "register_operand" "=h")
2871         (umod:SI (match_dup 1)
2872                  (match_dup 2)))]
2873   ""
2874   { return mips_output_division ("divu\\t$0,%1,%2", operands); }
2875   [(set_attr "type"     "idiv")
2876    (set_attr "mode"     "SI")])
2877
2878 (define_insn "udivmoddi4"
2879   [(set (match_operand:DI 0 "register_operand" "=l")
2880         (udiv:DI (match_operand:DI 1 "register_operand" "d")
2881                  (match_operand:DI 2 "register_operand" "d")))
2882    (set (match_operand:DI 3 "register_operand" "=h")
2883         (umod:DI (match_dup 1)
2884                  (match_dup 2)))]
2885   "TARGET_64BIT"
2886   { return mips_output_division ("ddivu\\t$0,%1,%2", operands); }
2887   [(set_attr "type"     "idiv")
2888    (set_attr "mode"     "DI")])
2889 ;;
2890 ;;  ....................
2891 ;;
2892 ;;      SQUARE ROOT
2893 ;;
2894 ;;  ....................
2895
2896 (define_insn "sqrtdf2"
2897   [(set (match_operand:DF 0 "register_operand" "=f")
2898         (sqrt:DF (match_operand:DF 1 "register_operand" "f")))]
2899   "TARGET_HARD_FLOAT && HAVE_SQRT_P() && TARGET_DOUBLE_FLOAT"
2900   "sqrt.d\\t%0,%1"
2901   [(set_attr "type"     "fsqrt")
2902    (set_attr "mode"     "DF")])
2903
2904 (define_insn "sqrtsf2"
2905   [(set (match_operand:SF 0 "register_operand" "=f")
2906         (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
2907   "TARGET_HARD_FLOAT && HAVE_SQRT_P()"
2908   "sqrt.s\\t%0,%1"
2909   [(set_attr "type"     "fsqrt")
2910    (set_attr "mode"     "SF")])
2911
2912 (define_insn ""
2913   [(set (match_operand:DF 0 "register_operand" "=f")
2914         (div:DF (match_operand:DF 1 "const_float_1_operand" "")
2915                 (sqrt:DF (match_operand:DF 2 "register_operand" "f"))))]
2916   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && flag_unsafe_math_optimizations"
2917   "rsqrt.d\\t%0,%2"
2918   [(set_attr "type"     "frsqrt")
2919    (set_attr "mode"     "DF")])
2920
2921 (define_insn ""
2922   [(set (match_operand:SF 0 "register_operand" "=f")
2923         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
2924                 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
2925   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
2926   "rsqrt.s\\t%0,%2"
2927   [(set_attr "type"     "frsqrt")
2928    (set_attr "mode"     "SF")])
2929
2930 \f
2931 ;;
2932 ;;  ....................
2933 ;;
2934 ;;      ABSOLUTE VALUE
2935 ;;
2936 ;;  ....................
2937
2938 ;; Do not use the integer abs macro instruction, since that signals an
2939 ;; exception on -2147483648 (sigh).
2940
2941 (define_insn "abssi2"
2942   [(set (match_operand:SI 0 "register_operand" "=d")
2943         (abs:SI (match_operand:SI 1 "register_operand" "d")))]
2944   "!TARGET_MIPS16"
2945   "*
2946 {
2947   operands[2] = const0_rtx;
2948
2949   if (REGNO (operands[0]) == REGNO (operands[1]))
2950     {
2951       if (GENERATE_BRANCHLIKELY)
2952         return \"%(bltzl\\t%1,1f\\n\\tsubu\\t%0,%z2,%0\\n%~1:%)\";
2953       else
2954         return \"bgez\\t%1,1f%#\\n\\tsubu\\t%0,%z2,%0\\n%~1:\";
2955     }
2956   else
2957     return \"%(bgez\\t%1,1f\\n\\tmove\\t%0,%1\\n\\tsubu\\t%0,%z2,%0\\n%~1:%)\";
2958 }"
2959   [(set_attr "type"     "multi")
2960    (set_attr "mode"     "SI")
2961    (set_attr "length"   "12")])
2962
2963 (define_insn "absdi2"
2964   [(set (match_operand:DI 0 "register_operand" "=d")
2965         (abs:DI (match_operand:DI 1 "register_operand" "d")))]
2966   "TARGET_64BIT && !TARGET_MIPS16"
2967   "*
2968 {
2969   unsigned int regno1;
2970   operands[2] = const0_rtx;
2971
2972   if (GET_CODE (operands[1]) == REG)
2973     regno1 = REGNO (operands[1]);
2974   else
2975     regno1 = REGNO (XEXP (operands[1], 0));
2976
2977   if (REGNO (operands[0]) == regno1)
2978     return \"%(bltzl\\t%1,1f\\n\\tdsubu\\t%0,%z2,%0\\n%~1:%)\";
2979   else
2980     return \"%(bgez\\t%1,1f\\n\\tmove\\t%0,%1\\n\\tdsubu\\t%0,%z2,%0\\n%~1:%)\";
2981 }"
2982   [(set_attr "type"     "multi")
2983    (set_attr "mode"     "DI")
2984    (set_attr "length"   "12")])
2985
2986 (define_insn "absdf2"
2987   [(set (match_operand:DF 0 "register_operand" "=f")
2988         (abs:DF (match_operand:DF 1 "register_operand" "f")))]
2989   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2990   "abs.d\\t%0,%1"
2991   [(set_attr "type"     "fabs")
2992    (set_attr "mode"     "DF")])
2993
2994 (define_insn "abssf2"
2995   [(set (match_operand:SF 0 "register_operand" "=f")
2996         (abs:SF (match_operand:SF 1 "register_operand" "f")))]
2997   "TARGET_HARD_FLOAT"
2998   "abs.s\\t%0,%1"
2999   [(set_attr "type"     "fabs")
3000    (set_attr "mode"     "SF")])
3001
3002 \f
3003 ;;
3004 ;;  ....................
3005 ;;
3006 ;;      FIND FIRST BIT INSTRUCTION
3007 ;;
3008 ;;  ....................
3009 ;;
3010
3011 (define_insn "ffssi2"
3012   [(set (match_operand:SI 0 "register_operand" "=&d")
3013         (ffs:SI (match_operand:SI 1 "register_operand" "d")))
3014    (clobber (match_scratch:SI 2 "=&d"))
3015    (clobber (match_scratch:SI 3 "=&d"))]
3016   "!TARGET_MIPS16"
3017   "*
3018 {
3019   operands[4] = const0_rtx;
3020
3021   if (optimize && find_reg_note (insn, REG_DEAD, operands[1]))
3022     return \"%(\\
3023 move\\t%0,%z4\\n\\
3024 \\tbeq\\t%1,%z4,2f\\n\\
3025 %~1:\\tand\\t%2,%1,0x0001\\n\\
3026 \\taddu\\t%0,%0,1\\n\\
3027 \\tbeq\\t%2,%z4,1b\\n\\
3028 \\tsrl\\t%1,%1,1\\n\\
3029 %~2:%)\";
3030
3031   return \"%(\\
3032 move\\t%0,%z4\\n\\
3033 \\tmove\\t%3,%1\\n\\
3034 \\tbeq\\t%3,%z4,2f\\n\\
3035 %~1:\\tand\\t%2,%3,0x0001\\n\\
3036 \\taddu\\t%0,%0,1\\n\\
3037 \\tbeq\\t%2,%z4,1b\\n\\
3038 \\tsrl\\t%3,%3,1\\n\\
3039 %~2:%)\";
3040 }"
3041   [(set_attr "type"     "multi")
3042    (set_attr "mode"     "SI")
3043    (set_attr "length"   "28")])
3044
3045 (define_insn "ffsdi2"
3046   [(set (match_operand:DI 0 "register_operand" "=&d")
3047         (ffs:DI (match_operand:DI 1 "register_operand" "d")))
3048    (clobber (match_scratch:DI 2 "=&d"))
3049    (clobber (match_scratch:DI 3 "=&d"))]
3050   "TARGET_64BIT && !TARGET_MIPS16"
3051   "*
3052 {
3053   operands[4] = const0_rtx;
3054
3055   if (optimize && find_reg_note (insn, REG_DEAD, operands[1]))
3056     return \"%(\\
3057 move\\t%0,%z4\\n\\
3058 \\tbeq\\t%1,%z4,2f\\n\\
3059 %~1:\\tand\\t%2,%1,0x0001\\n\\
3060 \\tdaddu\\t%0,%0,1\\n\\
3061 \\tbeq\\t%2,%z4,1b\\n\\
3062 \\tdsrl\\t%1,%1,1\\n\\
3063 %~2:%)\";
3064
3065   return \"%(\\
3066 move\\t%0,%z4\\n\\
3067 \\tmove\\t%3,%1\\n\\
3068 \\tbeq\\t%3,%z4,2f\\n\\
3069 %~1:\\tand\\t%2,%3,0x0001\\n\\
3070 \\tdaddu\\t%0,%0,1\\n\\
3071 \\tbeq\\t%2,%z4,1b\\n\\
3072 \\tdsrl\\t%3,%3,1\\n\\
3073 %~2:%)\";
3074 }"
3075   [(set_attr "type"     "multi")
3076    (set_attr "mode"     "DI")
3077    (set_attr "length"   "28")])
3078
3079 \f
3080
3081 ;;
3082 ;;  ...................
3083 ;;
3084 ;;  Count leading zeroes.
3085 ;;
3086 ;;  ...................
3087 ;;
3088
3089 (define_insn "clzsi2"
3090   [(set (match_operand:SI 0 "register_operand" "=d")
3091         (clz:SI (match_operand:SI 1 "register_operand" "d")))]
3092   "ISA_HAS_CLZ_CLO"
3093   "clz\\t%0,%1"
3094   [(set_attr "type" "arith")
3095    (set_attr "mode" "SI")])
3096
3097 (define_insn "clzdi2"
3098   [(set (match_operand:DI 0 "register_operand" "=d")
3099         (clz:DI (match_operand:DI 1 "register_operand" "d")))]
3100   "ISA_HAS_DCLZ_DCLO"
3101   "dclz\\t%0,%1"
3102   [(set_attr "type" "arith")
3103    (set_attr "mode" "DI")])
3104
3105 ;;
3106 ;;  ....................
3107 ;;
3108 ;;      NEGATION and ONE'S COMPLEMENT
3109 ;;
3110 ;;  ....................
3111
3112 (define_insn "negsi2"
3113   [(set (match_operand:SI 0 "register_operand" "=d")
3114         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3115   ""
3116   "*
3117 {
3118   if (TARGET_MIPS16)
3119     return \"neg\\t%0,%1\";
3120   operands[2] = const0_rtx;
3121   return \"subu\\t%0,%z2,%1\";
3122 }"
3123   [(set_attr "type"     "arith")
3124    (set_attr "mode"     "SI")])
3125
3126 (define_expand "negdi2"
3127   [(parallel [(set (match_operand:DI 0 "register_operand" "=d")
3128                    (neg:DI (match_operand:DI 1 "register_operand" "d")))
3129               (clobber (match_dup 2))])]
3130   "(TARGET_64BIT || !TARGET_DEBUG_G_MODE) && !TARGET_MIPS16"
3131   "
3132 {
3133   if (TARGET_64BIT)
3134     {
3135       emit_insn (gen_negdi2_internal_2 (operands[0], operands[1]));
3136       DONE;
3137     }
3138
3139   operands[2] = gen_reg_rtx (SImode);
3140 }")
3141
3142 (define_insn "negdi2_internal"
3143   [(set (match_operand:DI 0 "register_operand" "=d")
3144         (neg:DI (match_operand:DI 1 "register_operand" "d")))
3145    (clobber (match_operand:SI 2 "register_operand" "=d"))]
3146   "! TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
3147   "*
3148 {
3149   operands[3] = const0_rtx;
3150   return \"subu\\t%L0,%z3,%L1\;subu\\t%M0,%z3,%M1\;sltu\\t%2,%z3,%L0\;subu\\t%M0,%M0,%2\";
3151 }"
3152   [(set_attr "type"     "darith")
3153    (set_attr "mode"     "DI")
3154    (set_attr "length"   "16")])
3155
3156 (define_insn "negdi2_internal_2"
3157   [(set (match_operand:DI 0 "register_operand" "=d")
3158         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3159   "TARGET_64BIT && !TARGET_MIPS16"
3160   "*
3161 {
3162   operands[2] = const0_rtx;
3163   return \"dsubu\\t%0,%z2,%1\";
3164 }"
3165   [(set_attr "type"     "arith")
3166    (set_attr "mode"     "DI")])
3167
3168 (define_insn "negdf2"
3169   [(set (match_operand:DF 0 "register_operand" "=f")
3170         (neg:DF (match_operand:DF 1 "register_operand" "f")))]
3171   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3172   "neg.d\\t%0,%1"
3173   [(set_attr "type"     "fneg")
3174    (set_attr "mode"     "DF")])
3175
3176 (define_insn "negsf2"
3177   [(set (match_operand:SF 0 "register_operand" "=f")
3178         (neg:SF (match_operand:SF 1 "register_operand" "f")))]
3179   "TARGET_HARD_FLOAT"
3180   "neg.s\\t%0,%1"
3181   [(set_attr "type"     "fneg")
3182    (set_attr "mode"     "SF")])
3183
3184 (define_insn "one_cmplsi2"
3185   [(set (match_operand:SI 0 "register_operand" "=d")
3186         (not:SI (match_operand:SI 1 "register_operand" "d")))]
3187   ""
3188   "*
3189 {
3190   if (TARGET_MIPS16)
3191     return \"not\\t%0,%1\";
3192   operands[2] = const0_rtx;
3193   return \"nor\\t%0,%z2,%1\";
3194 }"
3195   [(set_attr "type"     "arith")
3196    (set_attr "mode"     "SI")])
3197
3198 (define_insn "one_cmpldi2"
3199   [(set (match_operand:DI 0 "register_operand" "=d")
3200         (not:DI (match_operand:DI 1 "register_operand" "d")))]
3201   "TARGET_64BIT"
3202   "*
3203 {
3204   if (TARGET_MIPS16)
3205     return \"not\\t%0,%1\";
3206   return \"nor\\t%0,%.,%1\";
3207 }"
3208   [(set_attr "type"     "darith")
3209    (set_attr "mode"     "DI")])
3210 \f
3211 ;;
3212 ;;  ....................
3213 ;;
3214 ;;      LOGICAL
3215 ;;
3216 ;;  ....................
3217 ;;
3218
3219 ;; Many of these instructions uses trivial define_expands, because we
3220 ;; want to use a different set of constraints when TARGET_MIPS16.
3221
3222 (define_expand "andsi3"
3223   [(set (match_operand:SI 0 "register_operand" "=d,d")
3224         (and:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3225                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3226   ""
3227   "
3228 {
3229   if (TARGET_MIPS16)
3230     {
3231       operands[1] = force_reg (SImode, operands[1]);
3232       operands[2] = force_reg (SImode, operands[2]);
3233     }
3234 }")
3235
3236 (define_insn ""
3237   [(set (match_operand:SI 0 "register_operand" "=d,d")
3238         (and:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3239                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3240   "!TARGET_MIPS16"
3241   "@
3242    and\\t%0,%1,%2
3243    andi\\t%0,%1,%x2"
3244   [(set_attr "type"     "arith")
3245    (set_attr "mode"     "SI")])
3246
3247 (define_insn ""
3248   [(set (match_operand:SI 0 "register_operand" "=d")
3249         (and:SI (match_operand:SI 1 "register_operand" "%0")
3250                 (match_operand:SI 2 "register_operand" "d")))]
3251   "TARGET_MIPS16"
3252   "and\\t%0,%2"
3253   [(set_attr "type"     "arith")
3254    (set_attr "mode"     "SI")])
3255
3256 (define_expand "anddi3"
3257   [(set (match_operand:DI 0 "register_operand" "")
3258         (and:DI (match_operand:DI 1 "register_operand" "")
3259                 (match_operand:DI 2 "uns_arith_operand" "")))]
3260   "TARGET_64BIT"
3261   "
3262 {
3263   if (TARGET_MIPS16)
3264     {
3265       operands[1] = force_reg (DImode, operands[1]);
3266       operands[2] = force_reg (DImode, operands[2]);
3267     }
3268 }")
3269
3270 (define_insn ""
3271   [(set (match_operand:DI 0 "register_operand" "=d,d")
3272         (and:DI (match_operand:DI 1 "register_operand" "d,d")
3273                 (match_operand:DI 2 "uns_arith_operand" "d,K")))]
3274   "TARGET_64BIT && !TARGET_MIPS16"
3275   "@
3276    and\\t%0,%1,%2
3277    andi\\t%0,%1,%x2"
3278   [(set_attr "type"     "darith")
3279    (set_attr "mode"     "DI")])
3280
3281 (define_insn ""
3282   [(set (match_operand:DI 0 "register_operand" "=d")
3283         (and:DI (match_operand:DI 1 "register_operand" "0")
3284                 (match_operand:DI 2 "register_operand" "d")))]
3285   "TARGET_64BIT && TARGET_MIPS16"
3286   "and\\t%0,%2"
3287   [(set_attr "type"     "darith")
3288    (set_attr "mode"     "DI")])
3289
3290 (define_expand "iorsi3"
3291   [(set (match_operand:SI 0 "register_operand" "=d,d")
3292         (ior:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3293                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3294   ""
3295   "
3296 {
3297   if (TARGET_MIPS16)
3298     {
3299       operands[1] = force_reg (SImode, operands[1]);
3300       operands[2] = force_reg (SImode, operands[2]);
3301     }
3302 }")
3303
3304 (define_insn ""
3305   [(set (match_operand:SI 0 "register_operand" "=d,d")
3306         (ior:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3307                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3308   "!TARGET_MIPS16"
3309   "@
3310    or\\t%0,%1,%2
3311    ori\\t%0,%1,%x2"
3312   [(set_attr "type"     "arith")
3313    (set_attr "mode"     "SI")])
3314
3315 (define_insn ""
3316   [(set (match_operand:SI 0 "register_operand" "=d")
3317         (ior:SI (match_operand:SI 1 "register_operand" "%0")
3318                 (match_operand:SI 2 "register_operand" "d")))]
3319   "TARGET_MIPS16"
3320   "or\\t%0,%2"
3321   [(set_attr "type"     "arith")
3322    (set_attr "mode"     "SI")])
3323
3324 (define_expand "iordi3"
3325   [(set (match_operand:DI 0 "register_operand" "")
3326         (ior:DI (match_operand:DI 1 "register_operand" "")
3327                 (match_operand:DI 2 "uns_arith_operand" "")))]
3328   "TARGET_64BIT"
3329   "
3330 {
3331   if (TARGET_MIPS16)
3332     {
3333       operands[1] = force_reg (DImode, operands[1]);
3334       operands[2] = force_reg (DImode, operands[2]);
3335     }
3336 }")
3337
3338 (define_insn ""
3339   [(set (match_operand:DI 0 "register_operand" "=d,d")
3340         (ior:DI (match_operand:DI 1 "register_operand" "d,d")
3341                 (match_operand:DI 2 "uns_arith_operand" "d,K")))]
3342   "TARGET_64BIT && !TARGET_MIPS16"
3343   "@
3344    or\t%0,%1,%2
3345    ori\t%0,%1,%x2"
3346   [(set_attr "type"     "darith")
3347    (set_attr "mode"     "DI")])
3348
3349 (define_insn ""
3350   [(set (match_operand:DI 0 "register_operand" "=d")
3351         (ior:DI (match_operand:DI 1 "register_operand" "0")
3352                 (match_operand:DI 2 "register_operand" "d")))]
3353   "TARGET_64BIT && TARGET_MIPS16"
3354   "or\t%0,%2"
3355   [(set_attr "type"     "darith")
3356    (set_attr "mode"     "DI")])
3357
3358 (define_expand "xorsi3"
3359   [(set (match_operand:SI 0 "register_operand" "=d,d")
3360         (xor:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3361                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3362   ""
3363   "")
3364
3365 (define_insn ""
3366   [(set (match_operand:SI 0 "register_operand" "=d,d")
3367         (xor:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3368                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3369   "!TARGET_MIPS16"
3370   "@
3371    xor\\t%0,%1,%2
3372    xori\\t%0,%1,%x2"
3373   [(set_attr "type"     "arith")
3374    (set_attr "mode"     "SI")])
3375
3376 (define_insn ""
3377   [(set (match_operand:SI 0 "register_operand" "=d,t,t")
3378         (xor:SI (match_operand:SI 1 "uns_arith_operand" "%0,d,d")
3379                 (match_operand:SI 2 "uns_arith_operand" "d,K,d")))]
3380   "TARGET_MIPS16"
3381   "@
3382    xor\\t%0,%2
3383    cmpi\\t%1,%2
3384    cmp\\t%1,%2"
3385   [(set_attr "type"     "arith")
3386    (set_attr "mode"     "SI")
3387    (set_attr_alternative "length"
3388                 [(const_int 4)
3389                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
3390                                (const_int 4)
3391                                (const_int 8))
3392                  (const_int 4)])])
3393
3394 (define_expand "xordi3"
3395   [(set (match_operand:DI 0 "register_operand" "")
3396         (xor:DI (match_operand:DI 1 "register_operand" "")
3397                 (match_operand:DI 2 "uns_arith_operand" "")))]
3398   "TARGET_64BIT"
3399   "
3400 {
3401   if (TARGET_MIPS16)
3402     {
3403       operands[1] = force_reg (DImode, operands[1]);
3404       operands[2] = force_reg (DImode, operands[2]);
3405     }
3406 }")
3407
3408 (define_insn ""
3409   [(set (match_operand:DI 0 "register_operand" "=d,d")
3410         (xor:DI (match_operand:DI 1 "register_operand" "d,d")
3411                 (match_operand:DI 2 "uns_arith_operand" "d,K")))]
3412   "TARGET_64BIT && !TARGET_MIPS16"
3413   "@
3414    xor\t%0,%1,%2
3415    xori\t%0,%1,%x2"
3416   [(set_attr "type"     "darith")
3417    (set_attr "mode"     "DI")])
3418
3419 (define_insn ""
3420   [(set (match_operand:DI 0 "register_operand" "=d,t,t")
3421         (xor:DI (match_operand:DI 1 "register_operand" "%0,d,d")
3422                 (match_operand:DI 2 "uns_arith_operand" "d,K,d")))]
3423   "TARGET_64BIT && TARGET_MIPS16"
3424   "@
3425    xor\\t%0,%2
3426    cmpi\\t%1,%2
3427    cmp\\t%1,%2"
3428   [(set_attr "type"     "arith")
3429    (set_attr "mode"     "DI")
3430    (set_attr_alternative "length"
3431                 [(const_int 4)
3432                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
3433                                (const_int 4)
3434                                (const_int 8))
3435                  (const_int 4)])])
3436
3437 (define_insn "*norsi3"
3438   [(set (match_operand:SI 0 "register_operand" "=d")
3439         (and:SI (not:SI (match_operand:SI 1 "register_operand" "d"))
3440                 (not:SI (match_operand:SI 2 "register_operand" "d"))))]
3441   "!TARGET_MIPS16"
3442   "nor\\t%0,%z1,%z2"
3443   [(set_attr "type"     "arith")
3444    (set_attr "mode"     "SI")])
3445
3446 (define_insn "*nordi3"
3447   [(set (match_operand:DI 0 "register_operand" "=d")
3448         (and:DI (not:DI (match_operand:DI 1 "register_operand" "d"))
3449                 (not:DI (match_operand:DI 2 "register_operand" "d"))))]
3450   "TARGET_64BIT && !TARGET_MIPS16"
3451   "nor\\t%0,%z1,%z2"
3452   [(set_attr "type"     "darith")
3453    (set_attr "mode"     "DI")])
3454 \f
3455 ;;
3456 ;;  ....................
3457 ;;
3458 ;;      TRUNCATION
3459 ;;
3460 ;;  ....................
3461
3462
3463
3464 (define_insn "truncdfsf2"
3465   [(set (match_operand:SF 0 "register_operand" "=f")
3466         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3467   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3468   "cvt.s.d\\t%0,%1"
3469   [(set_attr "type"     "fcvt")
3470    (set_attr "mode"     "SF")])
3471
3472 ;; Integer truncation patterns.  Truncating SImode values to smaller
3473 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3474 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3475 ;; need to make sure that the lower 32 bits are properly sign-extended
3476 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3477 ;; smaller than SImode is equivalent to two separate truncations:
3478 ;;
3479 ;;                        A       B
3480 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3481 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3482 ;;
3483 ;; Step A needs a real instruction but step B does not.
3484
3485 (define_insn "truncdisi2"
3486   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
3487         (truncate:SI (match_operand:DI 1 "register_operand" "d,d")))]
3488   "TARGET_64BIT"
3489   "@
3490     sll\t%0,%1,0
3491     sw\t%1,%0"
3492   [(set_attr "type" "darith,store")
3493    (set_attr "mode" "SI")
3494    (set_attr "extended_mips16" "yes,*")])
3495
3496 (define_insn "truncdihi2"
3497   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,m")
3498         (truncate:HI (match_operand:DI 1 "register_operand" "d,d")))]
3499   "TARGET_64BIT"
3500   "@
3501     sll\t%0,%1,0
3502     sh\t%1,%0"
3503   [(set_attr "type" "darith,store")
3504    (set_attr "mode" "SI")
3505    (set_attr "extended_mips16" "yes,*")])
3506
3507 (define_insn "truncdiqi2"
3508   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,m")
3509         (truncate:QI (match_operand:DI 1 "register_operand" "d,d")))]
3510   "TARGET_64BIT"
3511   "@
3512     sll\t%0,%1,0
3513     sb\t%1,%0"
3514   [(set_attr "type" "darith,store")
3515    (set_attr "mode" "SI")
3516    (set_attr "extended_mips16" "yes,*")])
3517
3518 ;; Combiner patterns to optimize shift/truncate combinations.
3519
3520 (define_insn ""
3521   [(set (match_operand:SI 0 "register_operand" "=d")
3522         (truncate:SI (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3523                                   (match_operand:DI 2 "small_int" "I"))))]
3524   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) >= 32"
3525   "dsra\\t%0,%1,%2"
3526   [(set_attr "type" "darith")
3527    (set_attr "mode" "SI")])
3528
3529 (define_insn ""
3530   [(set (match_operand:SI 0 "register_operand" "=d")
3531         (truncate:SI (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3532                                   (const_int 32))))]
3533   "TARGET_64BIT && !TARGET_MIPS16"
3534   "dsra\\t%0,%1,32"
3535   [(set_attr "type" "darith")
3536    (set_attr "mode" "SI")])
3537
3538
3539 ;; Combiner patterns for truncate/sign_extend combinations.  They use
3540 ;; the shift/truncate patterns above.
3541
3542 (define_insn_and_split ""
3543   [(set (match_operand:SI 0 "register_operand" "=d")
3544         (sign_extend:SI
3545             (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
3546   "TARGET_64BIT && !TARGET_MIPS16"
3547   "#"
3548   "&& reload_completed"
3549   [(set (match_dup 2)
3550         (ashift:DI (match_dup 1)
3551                    (const_int 48)))
3552    (set (match_dup 0)
3553         (truncate:SI (ashiftrt:DI (match_dup 2)
3554                                   (const_int 48))))]
3555   { operands[2] = gen_lowpart (DImode, operands[0]); })
3556
3557 (define_insn_and_split ""
3558   [(set (match_operand:SI 0 "register_operand" "=d")
3559         (sign_extend:SI
3560             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3561   "TARGET_64BIT && !TARGET_MIPS16"
3562   "#"
3563   "&& reload_completed"
3564   [(set (match_dup 2)
3565         (ashift:DI (match_dup 1)
3566                    (const_int 56)))
3567    (set (match_dup 0)
3568         (truncate:SI (ashiftrt:DI (match_dup 2)
3569                                   (const_int 56))))]
3570   { operands[2] = gen_lowpart (DImode, operands[0]); })
3571
3572
3573 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3574
3575 (define_insn ""
3576   [(set (match_operand:SI 0 "register_operand" "=d")
3577         (zero_extend:SI (truncate:HI
3578                          (match_operand:DI 1 "register_operand" "d"))))]
3579   "TARGET_64BIT && !TARGET_MIPS16"
3580   "andi\\t%0,%1,0xffff"
3581   [(set_attr "type"     "darith")
3582    (set_attr "mode"     "SI")])
3583
3584 (define_insn ""
3585   [(set (match_operand:SI 0 "register_operand" "=d")
3586         (zero_extend:SI (truncate:QI
3587                          (match_operand:DI 1 "register_operand" "d"))))]
3588   "TARGET_64BIT && !TARGET_MIPS16"
3589   "andi\\t%0,%1,0xff"
3590   [(set_attr "type"     "darith")
3591    (set_attr "mode"     "SI")])
3592
3593 (define_insn ""
3594   [(set (match_operand:HI 0 "register_operand" "=d")
3595         (zero_extend:HI (truncate:QI
3596                          (match_operand:DI 1 "register_operand" "d"))))]
3597   "TARGET_64BIT && !TARGET_MIPS16"
3598   "andi\\t%0,%1,0xff"
3599   [(set_attr "type"     "darith")
3600    (set_attr "mode"     "HI")])
3601
3602 \f
3603 ;;
3604 ;;  ....................
3605 ;;
3606 ;;      ZERO EXTENSION
3607 ;;
3608 ;;  ....................
3609
3610 ;; Extension insns.
3611 ;; Those for integer source operand are ordered widest source type first.
3612
3613 (define_insn_and_split "zero_extendsidi2"
3614   [(set (match_operand:DI 0 "register_operand" "=d")
3615         (zero_extend:DI (match_operand:SI 1 "register_operand" "d")))]
3616   "TARGET_64BIT"
3617   "#"
3618   "&& reload_completed"
3619   [(set (match_dup 0)
3620         (ashift:DI (match_dup 1) (const_int 32)))
3621    (set (match_dup 0)
3622         (lshiftrt:DI (match_dup 0) (const_int 32)))]
3623   "operands[1] = gen_lowpart (DImode, operands[1]);"
3624   [(set_attr "type" "arith")
3625    (set_attr "mode" "DI")])
3626
3627 (define_insn "*zero_extendsidi2_mem"
3628   [(set (match_operand:DI 0 "register_operand" "=d")
3629         (zero_extend:DI (match_operand:SI 1 "memory_operand" "m")))]
3630   "TARGET_64BIT && !TARGET_MIPS16"
3631   "lwu\t%0,%1"
3632   [(set_attr "type"     "load")
3633    (set_attr "mode"     "DI")])
3634
3635 (define_expand "zero_extendhisi2"
3636   [(set (match_operand:SI 0 "register_operand" "")
3637         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3638   ""
3639   "
3640 {
3641   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
3642     {
3643       rtx op = gen_lowpart (SImode, operands[1]);
3644       rtx temp = force_reg (SImode, GEN_INT (0xffff));
3645
3646       emit_insn (gen_andsi3 (operands[0], op, temp));
3647       DONE;
3648     }
3649 }")
3650
3651 (define_insn ""
3652   [(set (match_operand:SI 0 "register_operand" "=d,d")
3653         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "d,m")))]
3654   "!TARGET_MIPS16"
3655   "@
3656    andi\t%0,%1,0xffff
3657    lhu\t%0,%1"
3658   [(set_attr "type"     "arith,load")
3659    (set_attr "mode"     "SI")
3660    (set_attr "length"   "4,*")])
3661
3662 (define_insn ""
3663   [(set (match_operand:SI 0 "register_operand" "=d")
3664         (zero_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
3665   "TARGET_MIPS16"
3666   "lhu\t%0,%1"
3667   [(set_attr "type"     "load")
3668    (set_attr "mode"     "SI")])
3669
3670 (define_expand "zero_extendhidi2"
3671   [(set (match_operand:DI 0 "register_operand" "")
3672         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "")))]
3673   "TARGET_64BIT"
3674   "
3675 {
3676   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
3677     {
3678       rtx op = gen_lowpart (DImode, operands[1]);
3679       rtx temp = force_reg (DImode, GEN_INT (0xffff));
3680
3681       emit_insn (gen_anddi3 (operands[0], op, temp));
3682       DONE;
3683     }
3684 }")
3685
3686 (define_insn ""
3687   [(set (match_operand:DI 0 "register_operand" "=d,d")
3688         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "d,m")))]
3689   "TARGET_64BIT && !TARGET_MIPS16"
3690   "@
3691    andi\t%0,%1,0xffff
3692    lhu\t%0,%1"
3693   [(set_attr "type"     "arith,load")
3694    (set_attr "mode"     "DI")
3695    (set_attr "length"   "4,*")])
3696
3697 (define_insn ""
3698   [(set (match_operand:DI 0 "register_operand" "=d")
3699         (zero_extend:DI (match_operand:HI 1 "memory_operand" "m")))]
3700   "TARGET_64BIT && TARGET_MIPS16"
3701   "lhu\t%0,%1"
3702   [(set_attr "type"     "load")
3703    (set_attr "mode"     "DI")])
3704
3705 (define_expand "zero_extendqihi2"
3706   [(set (match_operand:HI 0 "register_operand" "")
3707         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
3708   ""
3709   "
3710 {
3711   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
3712     {
3713       rtx op0 = gen_lowpart (SImode, operands[0]);
3714       rtx op1 = gen_lowpart (SImode, operands[1]);
3715       rtx temp = force_reg (SImode, GEN_INT (0xff));
3716
3717       emit_insn (gen_andsi3 (op0, op1, temp));
3718       DONE;
3719     }
3720 }")
3721
3722 (define_insn ""
3723   [(set (match_operand:HI 0 "register_operand" "=d,d")
3724         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3725   "!TARGET_MIPS16"
3726   "@
3727    andi\t%0,%1,0x00ff
3728    lbu\t%0,%1"
3729   [(set_attr "type"     "arith,load")
3730    (set_attr "mode"     "HI")
3731    (set_attr "length"   "4,*")])
3732
3733 (define_insn ""
3734   [(set (match_operand:HI 0 "register_operand" "=d")
3735         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3736   "TARGET_MIPS16"
3737   "lbu\t%0,%1"
3738   [(set_attr "type"     "load")
3739    (set_attr "mode"     "HI")])
3740
3741 (define_expand "zero_extendqisi2"
3742   [(set (match_operand:SI 0 "register_operand" "")
3743         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
3744   ""
3745   "
3746 {
3747   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
3748     {
3749       rtx op = gen_lowpart (SImode, operands[1]);
3750       rtx temp = force_reg (SImode, GEN_INT (0xff));
3751
3752       emit_insn (gen_andsi3 (operands[0], op, temp));
3753       DONE;
3754     }
3755 }")
3756
3757 (define_insn ""
3758   [(set (match_operand:SI 0 "register_operand" "=d,d")
3759         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3760   "!TARGET_MIPS16"
3761   "@
3762    andi\t%0,%1,0x00ff
3763    lbu\t%0,%1"
3764   [(set_attr "type"     "arith,load")
3765    (set_attr "mode"     "SI")
3766    (set_attr "length"   "4,*")])
3767
3768 (define_insn ""
3769   [(set (match_operand:SI 0 "register_operand" "=d")
3770         (zero_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
3771   "TARGET_MIPS16"
3772   "lbu\t%0,%1"
3773   [(set_attr "type"     "load")
3774    (set_attr "mode"     "SI")])
3775
3776 (define_expand "zero_extendqidi2"
3777   [(set (match_operand:DI 0 "register_operand" "")
3778         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "")))]
3779   "TARGET_64BIT"
3780   "
3781 {
3782   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
3783     {
3784       rtx op = gen_lowpart (DImode, operands[1]);
3785       rtx temp = force_reg (DImode, GEN_INT (0xff));
3786
3787       emit_insn (gen_anddi3 (operands[0], op, temp));
3788       DONE;
3789     }
3790 }")
3791
3792 (define_insn ""
3793   [(set (match_operand:DI 0 "register_operand" "=d,d")
3794         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3795   "TARGET_64BIT && !TARGET_MIPS16"
3796   "@
3797    andi\t%0,%1,0x00ff
3798    lbu\t%0,%1"
3799   [(set_attr "type"     "arith,load")
3800    (set_attr "mode"     "DI")
3801    (set_attr "length"   "4,*")])
3802
3803 (define_insn ""
3804   [(set (match_operand:DI 0 "register_operand" "=d")
3805         (zero_extend:DI (match_operand:QI 1 "memory_operand" "m")))]
3806   "TARGET_64BIT && TARGET_MIPS16"
3807   "lbu\t%0,%1"
3808   [(set_attr "type"     "load")
3809    (set_attr "mode"     "DI")])
3810 \f
3811 ;;
3812 ;;  ....................
3813 ;;
3814 ;;      SIGN EXTENSION
3815 ;;
3816 ;;  ....................
3817
3818 ;; Extension insns.
3819 ;; Those for integer source operand are ordered widest source type first.
3820
3821 (define_expand "extendsidi2"
3822   [(set (match_operand:DI 0 "register_operand" "")
3823         (sign_extend:DI (match_operand:SI 1 "move_operand" "")))]
3824   "TARGET_64BIT"
3825   "
3826 {
3827  if (symbolic_operand (operands[1], SImode))
3828    {
3829       emit_move_insn (operands[0], convert_memory_address (DImode, operands[1]));
3830       DONE;
3831    }
3832
3833 }")
3834
3835 (define_insn "*extendsidi2"
3836   [(set (match_operand:DI 0 "register_operand" "=d,d")
3837         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,m")))]
3838   "TARGET_64BIT"
3839   "@
3840    sll\t%0,%1,0
3841    lw\t%0,%1"
3842   [(set_attr "type" "arith,load")
3843    (set_attr "mode" "DI")
3844    (set_attr "extended_mips16" "yes,*")])
3845
3846 ;; These patterns originally accepted general_operands, however, slightly
3847 ;; better code is generated by only accepting register_operands, and then
3848 ;; letting combine generate the lh and lb insns.
3849
3850 ;; These expanders originally put values in registers first. We split
3851 ;; all non-mem patterns after reload.
3852
3853 (define_expand "extendhidi2"
3854   [(set (match_operand:DI 0 "register_operand" "")
3855         (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "")))]
3856   "TARGET_64BIT"
3857   "")
3858
3859 (define_insn "*extendhidi2"
3860   [(set (match_operand:DI 0 "register_operand" "=d")
3861         (sign_extend:DI (match_operand:HI 1 "register_operand" "d")))]
3862   "TARGET_64BIT"
3863   "#")
3864
3865 (define_split
3866   [(set (match_operand:DI 0 "register_operand" "")
3867         (sign_extend:DI (match_operand:HI 1 "register_operand" "")))]
3868   "TARGET_64BIT && reload_completed"
3869   [(set (match_dup 0)
3870         (ashift:DI (match_dup 1) (const_int 48)))
3871    (set (match_dup 0)
3872         (ashiftrt:DI (match_dup 0) (const_int 48)))]
3873   "operands[1] = gen_lowpart (DImode, operands[1]);")
3874
3875 (define_insn "*extendhidi2_mem"
3876   [(set (match_operand:DI 0 "register_operand" "=d")
3877         (sign_extend:DI (match_operand:HI 1 "memory_operand" "m")))]
3878   "TARGET_64BIT"
3879   "lh\t%0,%1"
3880   [(set_attr "type"     "load")
3881    (set_attr "mode"     "DI")])
3882
3883 (define_expand "extendhisi2"
3884   [(set (match_operand:SI 0 "register_operand" "")
3885         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
3886   ""
3887   "
3888    if (ISA_HAS_SEB_SEH)
3889      {
3890         emit_insn (gen_extendhisi2_hw (operands[0],
3891                                        force_reg (HImode, operands[1])));
3892         DONE;
3893      }
3894 ")
3895
3896 (define_insn "*extendhisi2"
3897   [(set (match_operand:SI 0 "register_operand" "=d")
3898         (sign_extend:SI (match_operand:HI 1 "register_operand" "d")))]
3899   ""
3900   "#")
3901
3902 (define_split
3903   [(set (match_operand:SI 0 "register_operand" "")
3904         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
3905   "reload_completed"
3906   [(set (match_dup 0)
3907         (ashift:SI (match_dup 1) (const_int 16)))
3908    (set (match_dup 0)
3909         (ashiftrt:SI (match_dup 0) (const_int 16)))]
3910   "operands[1] = gen_lowpart (SImode, operands[1]);")
3911
3912 (define_insn "extendhisi2_mem"
3913   [(set (match_operand:SI 0 "register_operand" "=d")
3914         (sign_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
3915   ""
3916   "lh\t%0,%1"
3917   [(set_attr "type"     "load")
3918    (set_attr "mode"     "SI")])
3919
3920 (define_insn "extendhisi2_hw"
3921   [(set (match_operand:SI 0 "register_operand" "=r")
3922         (sign_extend:SI (match_operand:HI 1 "register_operand" "r")))]
3923   "ISA_HAS_SEB_SEH"
3924   "seh\\t%0,%1"
3925   [(set_attr "type" "arith")
3926    (set_attr "mode" "SI")])
3927
3928 (define_expand "extendqihi2"
3929   [(set (match_operand:HI 0 "register_operand" "")
3930         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
3931   ""
3932   "")
3933
3934 (define_insn "*extendqihi2"
3935   [(set (match_operand:HI 0 "register_operand" "=d")
3936         (sign_extend:HI (match_operand:QI 1 "register_operand" "d")))]
3937   ""
3938   "#")
3939
3940 (define_split
3941   [(set (match_operand:HI 0 "register_operand" "")
3942         (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
3943   "reload_completed"
3944   [(set (match_dup 0)
3945         (ashift:SI (match_dup 1) (const_int 24)))
3946    (set (match_dup 0)
3947         (ashiftrt:SI (match_dup 0) (const_int 24)))]
3948   "operands[0] = gen_lowpart (SImode, operands[0]);
3949    operands[1] = gen_lowpart (SImode, operands[1]);")
3950
3951 (define_insn "*extendqihi2_internal_mem"
3952   [(set (match_operand:HI 0 "register_operand" "=d")
3953         (sign_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3954   ""
3955   "lb\t%0,%1"
3956   [(set_attr "type"     "load")
3957    (set_attr "mode"     "SI")])
3958
3959
3960 (define_expand "extendqisi2"
3961   [(set (match_operand:SI 0 "register_operand" "")
3962         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
3963   ""
3964   "
3965    if (ISA_HAS_SEB_SEH)
3966      {
3967        emit_insn (gen_extendqisi2_hw (operands[0],
3968                                       force_reg (QImode, operands[1])));
3969        DONE;
3970      }
3971 ")
3972
3973 (define_insn "*extendqisi2"
3974   [(set (match_operand:SI 0 "register_operand" "=d")
3975         (sign_extend:SI (match_operand:QI 1 "register_operand" "d")))]
3976   ""
3977   "#")
3978
3979 (define_split
3980   [(set (match_operand:SI 0 "register_operand" "")
3981         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
3982   "reload_completed"
3983   [(set (match_dup 0)
3984         (ashift:SI (match_dup 1) (const_int 24)))
3985    (set (match_dup 0)
3986         (ashiftrt:SI (match_dup 0) (const_int 24)))]
3987   "operands[1] = gen_lowpart (SImode, operands[1]);")
3988
3989 (define_insn "*extendqisi2_mem"
3990   [(set (match_operand:SI 0 "register_operand" "=d")
3991         (sign_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
3992   ""
3993   "lb\t%0,%1"
3994   [(set_attr "type"     "load")
3995    (set_attr "mode"     "SI")])
3996
3997 (define_insn "extendqisi2_hw"
3998   [(set (match_operand:SI 0 "register_operand" "=r")
3999         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
4000   "ISA_HAS_SEB_SEH"
4001   "seb\\t%0,%1"
4002   [(set_attr "type" "arith")
4003    (set_attr "mode" "SI")])
4004
4005 (define_expand "extendqidi2"
4006   [(set (match_operand:DI 0 "register_operand" "")
4007         (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "")))]
4008   "TARGET_64BIT"
4009   "")
4010
4011 (define_insn "*extendqidi2"
4012   [(set (match_operand:DI 0 "register_operand" "=d")
4013         (sign_extend:DI (match_operand:QI 1 "register_operand" "d")))]
4014   "TARGET_64BIT"
4015   "#")
4016
4017 (define_split
4018   [(set (match_operand:DI 0 "register_operand" "")
4019         (sign_extend:DI (match_operand:QI 1 "register_operand" "")))]
4020   "TARGET_64BIT && reload_completed"
4021   [(set (match_dup 0)
4022         (ashift:DI (match_dup 1) (const_int 56)))
4023    (set (match_dup 0)
4024         (ashiftrt:DI (match_dup 0) (const_int 56)))]
4025   "operands[1] = gen_lowpart (DImode, operands[1]);")
4026
4027 (define_insn "*extendqidi2_mem"
4028   [(set (match_operand:DI 0 "register_operand" "=d")
4029         (sign_extend:DI (match_operand:QI 1 "memory_operand" "m")))]
4030   "TARGET_64BIT"
4031   "lb\t%0,%1"
4032   [(set_attr "type"     "load")
4033    (set_attr "mode"     "DI")])
4034
4035 (define_insn "extendsfdf2"
4036   [(set (match_operand:DF 0 "register_operand" "=f")
4037         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
4038   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4039   "cvt.d.s\\t%0,%1"
4040   [(set_attr "type"     "fcvt")
4041    (set_attr "mode"     "DF")])
4042
4043 \f
4044
4045 ;;
4046 ;;  ....................
4047 ;;
4048 ;;      CONVERSIONS
4049 ;;
4050 ;;  ....................
4051
4052 (define_expand "fix_truncdfsi2"
4053   [(set (match_operand:SI 0 "register_operand" "=f")
4054         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
4055   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4056 {
4057   if (!ISA_HAS_TRUNC_W)
4058     {
4059       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
4060       DONE;
4061     }
4062 })
4063
4064 (define_insn "fix_truncdfsi2_insn"
4065   [(set (match_operand:SI 0 "register_operand" "=f")
4066         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
4067   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
4068   "trunc.w.d %0,%1"
4069   [(set_attr "type"     "fcvt")
4070    (set_attr "mode"     "DF")
4071    (set_attr "length"   "4")])
4072
4073 (define_insn "fix_truncdfsi2_macro"
4074   [(set (match_operand:SI 0 "register_operand" "=f")
4075         (fix:SI (match_operand:DF 1 "register_operand" "f")))
4076    (clobber (match_scratch:DF 2 "=d"))]
4077   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
4078   {
4079     if (set_nomacro)
4080       return ".set\tmacro\n\ttrunc.w.d %0,%1,%2\n\t.set\tmacro";
4081     return "trunc.w.d %0,%1,%2";
4082   }
4083   [(set_attr "type"     "fcvt")
4084    (set_attr "mode"     "DF")
4085    (set_attr "length"   "36")])
4086
4087 (define_expand "fix_truncsfsi2"
4088   [(set (match_operand:SI 0 "register_operand" "=f")
4089         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
4090   "TARGET_HARD_FLOAT"
4091 {
4092   if (!ISA_HAS_TRUNC_W)
4093     {
4094       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
4095       DONE;
4096     }
4097 })
4098
4099 (define_insn "fix_truncsfsi2_insn"
4100   [(set (match_operand:SI 0 "register_operand" "=f")
4101         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
4102   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
4103   "trunc.w.s %0,%1"
4104   [(set_attr "type"     "fcvt")
4105    (set_attr "mode"     "DF")
4106    (set_attr "length"   "4")])
4107
4108 (define_insn "fix_truncsfsi2_macro"
4109   [(set (match_operand:SI 0 "register_operand" "=f")
4110         (fix:SI (match_operand:SF 1 "register_operand" "f")))
4111    (clobber (match_scratch:SF 2 "=d"))]
4112   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
4113   {
4114     if (set_nomacro)
4115       return ".set\tmacro\n\ttrunc.w.s %0,%1,%2\n\t.set\tmacro";
4116     return "trunc.w.s %0,%1,%2";
4117   }
4118   [(set_attr "type"     "fcvt")
4119    (set_attr "mode"     "DF")
4120    (set_attr "length"   "36")])
4121
4122 ;;; ??? trunc.l.d is mentioned in the appendix of the 1993 r4000/r4600 manuals
4123 ;;; but not in the chapter that describes the FPU.  It is not mentioned at all
4124 ;;; in the 1991 manuals.  The r4000 at Cygnus does not have this instruction.
4125
4126 ;;; Deleting this means that we now need two libgcc2.a libraries.  One for
4127 ;;; the 32 bit calling convention and one for the 64 bit calling convention.
4128
4129 ;;; If this is disabled, then fixuns_truncdfdi2 must be disabled also.
4130
4131 (define_insn "fix_truncdfdi2"
4132   [(set (match_operand:DI 0 "register_operand" "=f")
4133         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
4134   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4135   "trunc.l.d %0,%1"
4136   [(set_attr "type"     "fcvt")
4137    (set_attr "mode"     "DF")
4138    (set_attr "length"   "4")])
4139
4140
4141 ;;; ??? trunc.l.s is mentioned in the appendix of the 1993 r4000/r4600 manuals
4142 ;;; but not in the chapter that describes the FPU.  It is not mentioned at all
4143 ;;; in the 1991 manuals.  The r4000 at Cygnus does not have this instruction.
4144 (define_insn "fix_truncsfdi2"
4145   [(set (match_operand:DI 0 "register_operand" "=f")
4146         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
4147   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4148   "trunc.l.s %0,%1"
4149   [(set_attr "type"     "fcvt")
4150    (set_attr "mode"     "SF")
4151    (set_attr "length"   "4")])
4152
4153
4154 (define_insn "floatsidf2"
4155   [(set (match_operand:DF 0 "register_operand" "=f")
4156         (float:DF (match_operand:SI 1 "register_operand" "f")))]
4157   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4158   "cvt.d.w\\t%0,%1"
4159   [(set_attr "type"     "fcvt")
4160    (set_attr "mode"     "DF")
4161    (set_attr "length"   "4")])
4162
4163
4164 (define_insn "floatdidf2"
4165   [(set (match_operand:DF 0 "register_operand" "=f")
4166         (float:DF (match_operand:DI 1 "register_operand" "f")))]
4167   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4168   "cvt.d.l\\t%0,%1"
4169   [(set_attr "type"     "fcvt")
4170    (set_attr "mode"     "DF")
4171    (set_attr "length"   "4")])
4172
4173
4174 (define_insn "floatsisf2"
4175   [(set (match_operand:SF 0 "register_operand" "=f")
4176         (float:SF (match_operand:SI 1 "register_operand" "f")))]
4177   "TARGET_HARD_FLOAT"
4178   "cvt.s.w\\t%0,%1"
4179   [(set_attr "type"     "fcvt")
4180    (set_attr "mode"     "SF")
4181    (set_attr "length"   "4")])
4182
4183
4184 (define_insn "floatdisf2"
4185   [(set (match_operand:SF 0 "register_operand" "=f")
4186         (float:SF (match_operand:DI 1 "register_operand" "f")))]
4187   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4188   "cvt.s.l\\t%0,%1"
4189   [(set_attr "type"     "fcvt")
4190    (set_attr "mode"     "SF")
4191    (set_attr "length"   "4")])
4192
4193
4194 (define_expand "fixuns_truncdfsi2"
4195   [(set (match_operand:SI 0 "register_operand" "")
4196         (unsigned_fix:SI (match_operand:DF 1 "register_operand" "")))]
4197   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4198   "
4199 {
4200   rtx reg1 = gen_reg_rtx (DFmode);
4201   rtx reg2 = gen_reg_rtx (DFmode);
4202   rtx reg3 = gen_reg_rtx (SImode);
4203   rtx label1 = gen_label_rtx ();
4204   rtx label2 = gen_label_rtx ();
4205   REAL_VALUE_TYPE offset;
4206
4207   real_2expN (&offset, 31);
4208
4209   if (reg1)                     /* turn off complaints about unreached code */
4210     {
4211       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
4212       do_pending_stack_adjust ();
4213
4214       emit_insn (gen_cmpdf (operands[1], reg1));
4215       emit_jump_insn (gen_bge (label1));
4216
4217       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4218       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4219                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4220       emit_barrier ();
4221
4222       emit_label (label1);
4223       emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4224       emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
4225                                      (BITMASK_HIGH, SImode)));
4226
4227       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4228       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4229
4230       emit_label (label2);
4231
4232       /* allow REG_NOTES to be set on last insn (labels don't have enough
4233          fields, and can't be used for REG_NOTES anyway).  */
4234       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4235       DONE;
4236     }
4237 }")
4238
4239
4240 (define_expand "fixuns_truncdfdi2"
4241   [(set (match_operand:DI 0 "register_operand" "")
4242         (unsigned_fix:DI (match_operand:DF 1 "register_operand" "")))]
4243   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4244   "
4245 {
4246   rtx reg1 = gen_reg_rtx (DFmode);
4247   rtx reg2 = gen_reg_rtx (DFmode);
4248   rtx reg3 = gen_reg_rtx (DImode);
4249   rtx label1 = gen_label_rtx ();
4250   rtx label2 = gen_label_rtx ();
4251   REAL_VALUE_TYPE offset;
4252
4253   real_2expN (&offset, 63);
4254
4255   if (reg1)                     /* turn off complaints about unreached code */
4256     {
4257       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
4258       do_pending_stack_adjust ();
4259
4260       emit_insn (gen_cmpdf (operands[1], reg1));
4261       emit_jump_insn (gen_bge (label1));
4262
4263       emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4264       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4265                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4266       emit_barrier ();
4267
4268       emit_label (label1);
4269       emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4270       emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
4271       emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4272
4273       emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4274       emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4275
4276       emit_label (label2);
4277
4278       /* allow REG_NOTES to be set on last insn (labels don't have enough
4279          fields, and can't be used for REG_NOTES anyway).  */
4280       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4281       DONE;
4282     }
4283 }")
4284
4285
4286 (define_expand "fixuns_truncsfsi2"
4287   [(set (match_operand:SI 0 "register_operand" "")
4288         (unsigned_fix:SI (match_operand:SF 1 "register_operand" "")))]
4289   "TARGET_HARD_FLOAT"
4290   "
4291 {
4292   rtx reg1 = gen_reg_rtx (SFmode);
4293   rtx reg2 = gen_reg_rtx (SFmode);
4294   rtx reg3 = gen_reg_rtx (SImode);
4295   rtx label1 = gen_label_rtx ();
4296   rtx label2 = gen_label_rtx ();
4297   REAL_VALUE_TYPE offset;
4298
4299   real_2expN (&offset, 31);
4300
4301   if (reg1)                     /* turn off complaints about unreached code */
4302     {
4303       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4304       do_pending_stack_adjust ();
4305
4306       emit_insn (gen_cmpsf (operands[1], reg1));
4307       emit_jump_insn (gen_bge (label1));
4308
4309       emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4310       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4311                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4312       emit_barrier ();
4313
4314       emit_label (label1);
4315       emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4316       emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
4317                                      (BITMASK_HIGH, SImode)));
4318
4319       emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4320       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4321
4322       emit_label (label2);
4323
4324       /* allow REG_NOTES to be set on last insn (labels don't have enough
4325          fields, and can't be used for REG_NOTES anyway).  */
4326       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4327       DONE;
4328     }
4329 }")
4330
4331
4332 (define_expand "fixuns_truncsfdi2"
4333   [(set (match_operand:DI 0 "register_operand" "")
4334         (unsigned_fix:DI (match_operand:SF 1 "register_operand" "")))]
4335   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4336   "
4337 {
4338   rtx reg1 = gen_reg_rtx (SFmode);
4339   rtx reg2 = gen_reg_rtx (SFmode);
4340   rtx reg3 = gen_reg_rtx (DImode);
4341   rtx label1 = gen_label_rtx ();
4342   rtx label2 = gen_label_rtx ();
4343   REAL_VALUE_TYPE offset;
4344
4345   real_2expN (&offset, 63);
4346
4347   if (reg1)                     /* turn off complaints about unreached code */
4348     {
4349       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4350       do_pending_stack_adjust ();
4351
4352       emit_insn (gen_cmpsf (operands[1], reg1));
4353       emit_jump_insn (gen_bge (label1));
4354
4355       emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4356       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4357                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4358       emit_barrier ();
4359
4360       emit_label (label1);
4361       emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4362       emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
4363       emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4364
4365       emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4366       emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4367
4368       emit_label (label2);
4369
4370       /* allow REG_NOTES to be set on last insn (labels don't have enough
4371          fields, and can't be used for REG_NOTES anyway).  */
4372       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4373       DONE;
4374     }
4375 }")
4376
4377 \f
4378 ;;
4379 ;;  ....................
4380 ;;
4381 ;;      DATA MOVEMENT
4382 ;;
4383 ;;  ....................
4384
4385 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4386
4387 (define_expand "extv"
4388   [(set (match_operand 0 "register_operand" "")
4389         (sign_extract (match_operand:QI 1 "memory_operand" "")
4390                       (match_operand 2 "immediate_operand" "")
4391                       (match_operand 3 "immediate_operand" "")))]
4392   "!TARGET_MIPS16"
4393   {
4394     if (mips_expand_unaligned_load (operands[0], operands[1],
4395                                     INTVAL (operands[2]),
4396                                     INTVAL (operands[3])))
4397       DONE;
4398     else
4399       FAIL;
4400   })
4401
4402 (define_expand "extzv"
4403   [(set (match_operand 0 "register_operand" "")
4404         (zero_extract (match_operand:QI 1 "memory_operand" "")
4405                       (match_operand 2 "immediate_operand" "")
4406                       (match_operand 3 "immediate_operand" "")))]
4407   "!TARGET_MIPS16"
4408   {
4409     if (mips_expand_unaligned_load (operands[0], operands[1],
4410                                     INTVAL (operands[2]),
4411                                     INTVAL (operands[3])))
4412       DONE;
4413     else
4414       FAIL;
4415   })
4416
4417 (define_expand "insv"
4418   [(set (zero_extract (match_operand:QI 0 "memory_operand" "")
4419                       (match_operand 1 "immediate_operand" "")
4420                       (match_operand 2 "immediate_operand" ""))
4421         (match_operand 3 "reg_or_0_operand" ""))]
4422   "!TARGET_MIPS16"
4423   {
4424     if (mips_expand_unaligned_store (operands[0], operands[3],
4425                                      INTVAL (operands[1]),
4426                                      INTVAL (operands[2])))
4427       DONE;
4428     else
4429       FAIL;
4430   })
4431
4432 ;; Unaligned word moves generated by the bit field patterns.
4433 ;;
4434 ;; As far as the rtl is concerned, both the left-part and right-part
4435 ;; instructions can access the whole field.  However, the real operand
4436 ;; refers to just the first or the last byte (depending on endianness).
4437 ;; We therefore use two memory operands to each instruction, one to
4438 ;; describe the rtl effect and one to use in the assembly output.
4439
4440 (define_insn "mov_lwl"
4441   [(set (match_operand:SI 0 "register_operand" "=d")
4442         (unspec:SI [(match_operand:BLK 1 "general_operand" "m")
4443                     (match_operand:QI 2 "general_operand" "m")]
4444                    UNSPEC_LWL))]
4445   "!TARGET_MIPS16"
4446   "lwl\t%0,%2"
4447   [(set_attr "type" "load")
4448    (set_attr "mode" "SI")
4449    (set_attr "hazard" "none")])
4450
4451 (define_insn "mov_lwr"
4452   [(set (match_operand:SI 0 "register_operand" "=d")
4453         (unspec:SI [(match_operand:BLK 1 "general_operand" "m")
4454                     (match_operand:QI 2 "general_operand" "m")
4455                     (match_operand:SI 3 "register_operand" "0")]
4456                    UNSPEC_LWR))]
4457   "!TARGET_MIPS16"
4458   "lwr\t%0,%2"
4459   [(set_attr "type" "load")
4460    (set_attr "mode" "SI")])
4461
4462
4463 (define_insn "mov_swl"
4464   [(set (match_operand:BLK 0 "memory_operand" "=m")
4465         (unspec:BLK [(match_operand:SI 1 "reg_or_0_operand" "dJ")
4466                      (match_operand:QI 2 "general_operand" "m")]
4467                     UNSPEC_SWL))]
4468   "!TARGET_MIPS16"
4469   "swl\t%z1,%2"
4470   [(set_attr "type" "store")
4471    (set_attr "mode" "SI")])
4472
4473 (define_insn "mov_swr"
4474   [(set (match_operand:BLK 0 "memory_operand" "+m")
4475         (unspec:BLK [(match_operand:SI 1 "reg_or_0_operand" "dJ")
4476                      (match_operand:QI 2 "general_operand" "m")
4477                      (match_dup 0)]
4478                     UNSPEC_SWR))]
4479   "!TARGET_MIPS16"
4480   "swr\t%z1,%2"
4481   [(set_attr "type" "store")
4482    (set_attr "mode" "SI")])
4483
4484
4485 (define_insn "mov_ldl"
4486   [(set (match_operand:DI 0 "register_operand" "=d")
4487         (unspec:DI [(match_operand:BLK 1 "general_operand" "m")
4488                     (match_operand:QI 2 "general_operand" "m")]
4489                    UNSPEC_LDL))]
4490   "TARGET_64BIT && !TARGET_MIPS16"
4491   "ldl\t%0,%2"
4492   [(set_attr "type" "load")
4493    (set_attr "mode" "DI")])
4494
4495 (define_insn "mov_ldr"
4496   [(set (match_operand:DI 0 "register_operand" "=d")
4497         (unspec:DI [(match_operand:BLK 1 "general_operand" "m")
4498                     (match_operand:QI 2 "general_operand" "m")
4499                     (match_operand:DI 3 "register_operand" "0")]
4500                    UNSPEC_LDR))]
4501   "TARGET_64BIT && !TARGET_MIPS16"
4502   "ldr\t%0,%2"
4503   [(set_attr "type" "load")
4504    (set_attr "mode" "DI")])
4505
4506
4507 (define_insn "mov_sdl"
4508   [(set (match_operand:BLK 0 "memory_operand" "=m")
4509         (unspec:BLK [(match_operand:DI 1 "reg_or_0_operand" "dJ")
4510                      (match_operand:QI 2 "general_operand" "m")]
4511                     UNSPEC_SDL))]
4512   "TARGET_64BIT && !TARGET_MIPS16"
4513   "sdl\t%z1,%2"
4514   [(set_attr "type" "store")
4515    (set_attr "mode" "DI")])
4516
4517 (define_insn "mov_sdr"
4518   [(set (match_operand:BLK 0 "memory_operand" "+m")
4519         (unspec:BLK [(match_operand:DI 1 "reg_or_0_operand" "dJ")
4520                      (match_operand:QI 2 "general_operand" "m")
4521                      (match_dup 0)]
4522                     UNSPEC_SDR))]
4523   "TARGET_64BIT && !TARGET_MIPS16"
4524   "sdr\t%z1,%2"
4525   [(set_attr "type" "store")
4526    (set_attr "mode" "DI")])
4527
4528
4529 ;; Instructions for loading a relocation expression using "lui".
4530
4531 (define_insn "luisi"
4532   [(set (match_operand:SI 0 "register_operand" "=r")
4533         (unspec:SI [(match_operand 1 "const_arith_operand" "")] UNSPEC_HIGH))]
4534   ""
4535   "lui\t%0,%1"
4536   [(set_attr "type" "arith")])
4537
4538 (define_insn "luidi"
4539   [(set (match_operand:DI 0 "register_operand" "=r")
4540         (unspec:DI [(match_operand 1 "const_arith_operand" "")] UNSPEC_HIGH))]
4541   "TARGET_64BIT"
4542   "lui\t%0,%1"
4543   [(set_attr "type" "arith")])
4544
4545
4546 ;; Instructions for adding the low 16 bits of an address to a register.
4547 ;; Operand 2 is the address: print_operand works out which relocation
4548 ;; should be applied.
4549
4550 (define_insn "lowsi"
4551   [(set (match_operand:SI 0 "register_operand" "=r")
4552         (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
4553                    (match_operand:SI 2 "immediate_operand" "")))]
4554   "!TARGET_MIPS16"
4555   "addiu\\t%0,%1,%R2"
4556   [(set_attr "type"     "arith")
4557    (set_attr "mode"     "SI")])
4558
4559 (define_insn "lowdi"
4560   [(set (match_operand:DI 0 "register_operand" "=r")
4561         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
4562                    (match_operand:DI 2 "immediate_operand" "")))]
4563   "!TARGET_MIPS16 && TARGET_64BIT"
4564   "daddiu\\t%0,%1,%R2"
4565   [(set_attr "type"     "arith")
4566    (set_attr "mode"     "DI")])
4567
4568 ;; 64-bit integer moves
4569
4570 ;; Unlike most other insns, the move insns can't be split with
4571 ;; different predicates, because register spilling and other parts of
4572 ;; the compiler, have memoized the insn number already.
4573
4574 (define_expand "movdi"
4575   [(set (match_operand:DI 0 "nonimmediate_operand" "")
4576         (match_operand:DI 1 "" ""))]
4577   ""
4578   "
4579 {
4580   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4581     DONE;
4582
4583   /* If we are generating embedded PIC code, and we are referring to a
4584      symbol in the .text section, we must use an offset from the start
4585      of the function.  */
4586   if (TARGET_EMBEDDED_PIC
4587       && (GET_CODE (operands[1]) == LABEL_REF
4588           || (GET_CODE (operands[1]) == SYMBOL_REF
4589               && ! SYMBOL_REF_FLAG (operands[1]))))
4590     {
4591       rtx temp;
4592
4593       temp = embedded_pic_offset (operands[1]);
4594       temp = gen_rtx_PLUS (Pmode, embedded_pic_fnaddr_reg (),
4595                            force_reg (DImode, temp));
4596       emit_move_insn (operands[0], force_reg (DImode, temp));
4597       DONE;
4598     }
4599 }")
4600
4601 ;; For mips16, we need a special case to handle storing $31 into
4602 ;; memory, since we don't have a constraint to match $31.  This
4603 ;; instruction can be generated by save_restore_insns.
4604
4605 (define_insn ""
4606   [(set (match_operand:DI 0 "memory_operand" "=m")
4607         (reg:DI 31))]
4608   "TARGET_MIPS16 && TARGET_64BIT"
4609   "sd\t$31,%0"
4610   [(set_attr "type"     "store")
4611    (set_attr "mode"     "DI")])
4612
4613 (define_insn "movdi_internal"
4614   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*x,*d,*x,*B*C*D,*B*C*D,*d,*m")
4615         (match_operand:DI 1 "general_operand" "d,iF,m,d,J,*x,*d,*d,*m,*B*C*D,*B*C*D"))]
4616   "!TARGET_64BIT && !TARGET_MIPS16
4617    && (register_operand (operands[0], DImode)
4618        || register_operand (operands[1], DImode)
4619        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0)
4620        || operands[1] == CONST0_RTX (DImode))"
4621   { return mips_output_move (operands[0], operands[1]); }
4622   [(set_attr "type"     "move,arith,load,store,hilo,hilo,hilo,xfer,load,xfer,store")
4623    (set_attr "mode"     "DI")
4624    (set_attr "length"   "8,16,*,*,8,8,8,8,*,8,*")])
4625
4626 (define_insn ""
4627   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4628         (match_operand:DI 1 "general_operand" "d,d,y,K,N,m,d,*x"))]
4629   "!TARGET_64BIT && TARGET_MIPS16
4630    && (register_operand (operands[0], DImode)
4631        || register_operand (operands[1], DImode))"
4632   { return mips_output_move (operands[0], operands[1]); }
4633   [(set_attr "type"     "move,move,move,arith,arith,load,store,hilo")
4634    (set_attr "mode"     "DI")
4635    (set_attr "length"   "8,8,8,8,12,*,*,8")])
4636
4637 (define_insn "movdi_internal2"
4638   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*x,*d,*x,*B*C*D,*B*C*D,*d,*m")
4639         (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*J,*x,*d,*d,*m,*B*C*D,*B*C*D"))]
4640   "TARGET_64BIT && !TARGET_MIPS16
4641    && (register_operand (operands[0], DImode)
4642        || register_operand (operands[1], DImode)
4643        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0)
4644        || operands[1] == CONST0_RTX (DImode))"
4645   { return mips_output_move (operands[0], operands[1]); }
4646   [(set_attr "type"     "move,const,const,load,store,move,xfer,load,xfer,store,hilo,hilo,hilo,xfer,load,xfer,store")
4647    (set_attr "mode"     "DI")
4648    (set_attr "length"   "4,*,*,*,*,4,4,*,4,*,4,4,4,8,*,8,*")])
4649
4650 (define_insn "*movdi_internal2_mips16"
4651   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m,*d")
4652         (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,m,d,*x"))]
4653   "TARGET_64BIT && TARGET_MIPS16
4654    && (register_operand (operands[0], DImode)
4655        || register_operand (operands[1], DImode))"
4656   { return mips_output_move (operands[0], operands[1]); }
4657   [(set_attr "type"     "move,move,move,arith,arith,const,load,store,hilo")
4658    (set_attr "mode"     "DI")
4659    (set_attr_alternative "length"
4660                 [(const_int 4)
4661                  (const_int 4)
4662                  (const_int 4)
4663                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1" "")
4664                                (const_int 4)
4665                                (const_int 8))
4666                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1" "")
4667                                (const_int 8)
4668                                (const_int 12))
4669                  (const_string "*")
4670                  (const_string "*")
4671                  (const_string "*")
4672                  (const_int 4)])])
4673
4674
4675 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4676 ;; when the original load is a 4 byte instruction but the add and the
4677 ;; load are 2 2 byte instructions.
4678
4679 (define_split
4680   [(set (match_operand:DI 0 "register_operand" "")
4681         (mem:DI (plus:DI (match_dup 0)
4682                          (match_operand:DI 1 "const_int_operand" ""))))]
4683   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4684    && !TARGET_DEBUG_D_MODE
4685    && GET_CODE (operands[0]) == REG
4686    && M16_REG_P (REGNO (operands[0]))
4687    && GET_CODE (operands[1]) == CONST_INT
4688    && ((INTVAL (operands[1]) < 0
4689         && INTVAL (operands[1]) >= -0x10)
4690        || (INTVAL (operands[1]) >= 32 * 8
4691            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4692        || (INTVAL (operands[1]) >= 0
4693            && INTVAL (operands[1]) < 32 * 8
4694            && (INTVAL (operands[1]) & 7) != 0))"
4695   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4696    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4697   "
4698 {
4699   HOST_WIDE_INT val = INTVAL (operands[1]);
4700
4701   if (val < 0)
4702     operands[2] = GEN_INT (0);
4703   else if (val >= 32 * 8)
4704     {
4705       int off = val & 7;
4706
4707       operands[1] = GEN_INT (0x8 + off);
4708       operands[2] = GEN_INT (val - off - 0x8);
4709     }
4710   else
4711     {
4712       int off = val & 7;
4713
4714       operands[1] = GEN_INT (off);
4715       operands[2] = GEN_INT (val - off);
4716     }
4717 }")
4718
4719 ;; 32-bit Integer moves
4720
4721 ;; Unlike most other insns, the move insns can't be split with
4722 ;; different predicates, because register spilling and other parts of
4723 ;; the compiler, have memoized the insn number already.
4724
4725 (define_expand "movsi"
4726   [(set (match_operand:SI 0 "nonimmediate_operand" "")
4727         (match_operand:SI 1 "" ""))]
4728   ""
4729   "
4730 {
4731   if (mips_legitimize_move (SImode, operands[0], operands[1]))
4732     DONE;
4733
4734   /* If we are generating embedded PIC code, and we are referring to a
4735      symbol in the .text section, we must use an offset from the start
4736      of the function.  */
4737   if (TARGET_EMBEDDED_PIC
4738       && (GET_CODE (operands[1]) == LABEL_REF
4739           || (GET_CODE (operands[1]) == SYMBOL_REF
4740               && ! SYMBOL_REF_FLAG (operands[1]))))
4741     {
4742       rtx temp;
4743
4744       temp = embedded_pic_offset (operands[1]);
4745       temp = gen_rtx_PLUS (Pmode, embedded_pic_fnaddr_reg (),
4746                            force_reg (SImode, temp));
4747       emit_move_insn (operands[0], force_reg (SImode, temp));
4748       DONE;
4749     }
4750 }")
4751
4752 ;; We can only store $ra directly into a small sp offset.  Should the
4753 ;; offset be too wide, non-constant or not sp-based, leave it up to
4754 ;; reload to choose a scratch register.
4755
4756 (define_insn ""
4757   [(set (mem:SI (plus:SI (reg:SI 29)
4758                          (match_operand:SI 0 "small_int" "n")))
4759         (reg:SI 31))]
4760   "TARGET_MIPS16"
4761   "sw\\t$31,%0($sp)"
4762   [(set_attr "type"     "store")
4763    (set_attr "mode"     "SI")
4764    (set_attr_alternative
4765     "length"
4766     [(if_then_else
4767       (lt (symbol_ref "(unsigned HOST_WIDE_INT) INTVAL (operands[0])")
4768           (const_int 1024))
4769       (const_int 4)
4770       (const_int 8))])])
4771
4772 ;; The difference between these two is whether or not ints are allowed
4773 ;; in FP registers (off by default, use -mdebugh to enable).
4774
4775 (define_insn "movsi_internal"
4776   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*d,*z,*x,*d,*x,*B*C*D,*B*C*D,*d,*m")
4777         (match_operand:SI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*z,*d,J,*x,*d,*d,*m,*B*C*D,*B*C*D"))]
4778   "!TARGET_MIPS16
4779    && (register_operand (operands[0], SImode)
4780        || register_operand (operands[1], SImode)
4781        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
4782   { return mips_output_move (operands[0], operands[1]); }
4783   [(set_attr "type"     "move,const,const,load,store,move,xfer,load,xfer,store,xfer,xfer,hilo,hilo,hilo,xfer,load,xfer,store")
4784    (set_attr "mode"     "SI")
4785    (set_attr "length"   "4,*,*,*,*,4,4,*,4,*,4,4,4,4,4,4,*,4,*")])
4786
4787 (define_insn ""
4788   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m,*d")
4789         (match_operand:SI 1 "move_operand" "d,d,y,K,N,U,m,d,*x"))]
4790   "TARGET_MIPS16
4791    && (register_operand (operands[0], SImode)
4792        || register_operand (operands[1], SImode))"
4793   { return mips_output_move (operands[0], operands[1]); }
4794   [(set_attr "type"     "move,move,move,arith,arith,const,load,store,hilo")
4795    (set_attr "mode"     "SI")
4796    (set_attr_alternative "length"
4797                 [(const_int 4)
4798                  (const_int 4)
4799                  (const_int 4)
4800                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1" "")
4801                                (const_int 4)
4802                                (const_int 8))
4803                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1" "")
4804                                (const_int 8)
4805                                (const_int 12))
4806                  (const_string "*")
4807                  (const_string "*")
4808                  (const_string "*")
4809                  (const_int 4)])])
4810
4811 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4812 ;; when the original load is a 4 byte instruction but the add and the
4813 ;; load are 2 2 byte instructions.
4814
4815 (define_split
4816   [(set (match_operand:SI 0 "register_operand" "")
4817         (mem:SI (plus:SI (match_dup 0)
4818                          (match_operand:SI 1 "const_int_operand" ""))))]
4819   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4820    && GET_CODE (operands[0]) == REG
4821    && M16_REG_P (REGNO (operands[0]))
4822    && GET_CODE (operands[1]) == CONST_INT
4823    && ((INTVAL (operands[1]) < 0
4824         && INTVAL (operands[1]) >= -0x80)
4825        || (INTVAL (operands[1]) >= 32 * 4
4826            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4827        || (INTVAL (operands[1]) >= 0
4828            && INTVAL (operands[1]) < 32 * 4
4829            && (INTVAL (operands[1]) & 3) != 0))"
4830   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4831    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4832   "
4833 {
4834   HOST_WIDE_INT val = INTVAL (operands[1]);
4835
4836   if (val < 0)
4837     operands[2] = GEN_INT (0);
4838   else if (val >= 32 * 4)
4839     {
4840       int off = val & 3;
4841
4842       operands[1] = GEN_INT (0x7c + off);
4843       operands[2] = GEN_INT (val - off - 0x7c);
4844     }
4845   else
4846     {
4847       int off = val & 3;
4848
4849       operands[1] = GEN_INT (off);
4850       operands[2] = GEN_INT (val - off);
4851     }
4852 }")
4853
4854 ;; On the mips16, we can split a load of certain constants into a load
4855 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
4856 ;; instructions.
4857
4858 (define_split
4859   [(set (match_operand:SI 0 "register_operand" "")
4860         (match_operand:SI 1 "const_int_operand" ""))]
4861   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4862    && GET_CODE (operands[0]) == REG
4863    && M16_REG_P (REGNO (operands[0]))
4864    && GET_CODE (operands[1]) == CONST_INT
4865    && INTVAL (operands[1]) >= 0x100
4866    && INTVAL (operands[1]) <= 0xff + 0x7f"
4867   [(set (match_dup 0) (match_dup 1))
4868    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4869   "
4870 {
4871   int val = INTVAL (operands[1]);
4872
4873   operands[1] = GEN_INT (0xff);
4874   operands[2] = GEN_INT (val - 0xff);
4875 }")
4876
4877 ;; On the mips16, we can split a load of a negative constant into a
4878 ;; load and a neg.  That's what mips_output_move will generate anyhow.
4879
4880 (define_split
4881   [(set (match_operand:SI 0 "register_operand" "")
4882         (match_operand:SI 1 "const_int_operand" ""))]
4883   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4884    && GET_CODE (operands[0]) == REG
4885    && M16_REG_P (REGNO (operands[0]))
4886    && GET_CODE (operands[1]) == CONST_INT
4887    && INTVAL (operands[1]) < 0
4888    && INTVAL (operands[1]) > - 0x8000"
4889   [(set (match_dup 0) (match_dup 1))
4890    (set (match_dup 0) (neg:SI (match_dup 0)))]
4891   "
4892 {
4893   operands[1] = GEN_INT (- INTVAL (operands[1]));
4894 }")
4895
4896 ;; This insn handles moving CCmode values.  It's really just a
4897 ;; slightly simplified copy of movsi_internal2, with additional cases
4898 ;; to move a condition register to a general register and to move
4899 ;; between the general registers and the floating point registers.
4900
4901 (define_insn "movcc"
4902   [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
4903         (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
4904   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4905   { return mips_output_move (operands[0], operands[1]); }
4906   [(set_attr "type"     "move,move,load,store,xfer,xfer,move,load,store")
4907    (set_attr "mode"     "SI")
4908    (set_attr "length"   "8,4,*,*,4,4,4,*,*")])
4909
4910 ;; Reload condition code registers.  reload_incc and reload_outcc
4911 ;; both handle moves from arbitrary operands into condition code
4912 ;; registers.  reload_incc handles the more common case in which
4913 ;; a source operand is constrained to be in a condition-code
4914 ;; register, but has not been allocated to one.
4915 ;;
4916 ;; Sometimes, such as in movcc, we have a CCmode destination whose
4917 ;; constraints do not include 'z'.  reload_outcc handles the case
4918 ;; when such an operand is allocated to a condition-code register.
4919 ;;
4920 ;; Note that reloads from a condition code register to some
4921 ;; other location can be done using ordinary moves.  Moving
4922 ;; into a GPR takes a single movcc, moving elsewhere takes
4923 ;; two.  We can leave these cases to the generic reload code.
4924 (define_expand "reload_incc"
4925   [(set (match_operand:CC 0 "fcc_register_operand" "=z")
4926         (match_operand:CC 1 "general_operand" ""))
4927    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4928   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4929   "
4930 {
4931   mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
4932   DONE;
4933 }")
4934
4935 (define_expand "reload_outcc"
4936   [(set (match_operand:CC 0 "fcc_register_operand" "=z")
4937         (match_operand:CC 1 "register_operand" ""))
4938    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4939   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4940   "
4941 {
4942   mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
4943   DONE;
4944 }")
4945
4946 ;; MIPS4 supports loading and storing a floating point register from
4947 ;; the sum of two general registers.  We use two versions for each of
4948 ;; these four instructions: one where the two general registers are
4949 ;; SImode, and one where they are DImode.  This is because general
4950 ;; registers will be in SImode when they hold 32 bit values, but,
4951 ;; since the 32 bit values are always sign extended, the [ls][wd]xc1
4952 ;; instructions will still work correctly.
4953
4954 ;; ??? Perhaps it would be better to support these instructions by
4955 ;; modifying GO_IF_LEGITIMATE_ADDRESS and friends.  However, since
4956 ;; these instructions can only be used to load and store floating
4957 ;; point registers, that would probably cause trouble in reload.
4958
4959 (define_insn ""
4960   [(set (match_operand:SF 0 "register_operand" "=f")
4961         (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "d")
4962                          (match_operand:SI 2 "register_operand" "d"))))]
4963   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
4964   "lwxc1\\t%0,%1(%2)"
4965   [(set_attr "type"     "load")
4966    (set_attr "mode"     "SF")
4967    (set_attr "length"   "4")])
4968
4969 (define_insn ""
4970   [(set (match_operand:SF 0 "register_operand" "=f")
4971         (mem:SF (plus:DI (match_operand:DI 1 "register_operand" "d")
4972                          (match_operand:DI 2 "register_operand" "d"))))]
4973   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
4974   "lwxc1\\t%0,%1(%2)"
4975   [(set_attr "type"     "load")
4976    (set_attr "mode"     "SF")
4977    (set_attr "length"   "4")])
4978
4979 (define_insn ""
4980   [(set (match_operand:DF 0 "register_operand" "=f")
4981         (mem:DF (plus:SI (match_operand:SI 1 "register_operand" "d")
4982                          (match_operand:SI 2 "register_operand" "d"))))]
4983   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4984   "ldxc1\\t%0,%1(%2)"
4985   [(set_attr "type"     "load")
4986    (set_attr "mode"     "DF")
4987    (set_attr "length"   "4")])
4988
4989 (define_insn ""
4990   [(set (match_operand:DF 0 "register_operand" "=f")
4991         (mem:DF (plus:DI (match_operand:DI 1 "register_operand" "d")
4992                          (match_operand:DI 2 "register_operand" "d"))))]
4993   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4994   "ldxc1\\t%0,%1(%2)"
4995   [(set_attr "type"     "load")
4996    (set_attr "mode"     "DF")
4997    (set_attr "length"   "4")])
4998
4999 (define_insn ""
5000   [(set (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "d")
5001                          (match_operand:SI 2 "register_operand" "d")))
5002         (match_operand:SF 0 "register_operand" "f"))]
5003   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
5004   "swxc1\\t%0,%1(%2)"
5005   [(set_attr "type"     "store")
5006    (set_attr "mode"     "SF")
5007    (set_attr "length"   "4")])
5008
5009 (define_insn ""
5010   [(set (mem:SF (plus:DI (match_operand:DI 1 "register_operand" "d")
5011                          (match_operand:DI 2 "register_operand" "d")))
5012         (match_operand:SF 0 "register_operand" "f"))]
5013   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
5014   "swxc1\\t%0,%1(%2)"
5015   [(set_attr "type"     "store")
5016    (set_attr "mode"     "SF")
5017    (set_attr "length"   "4")])
5018
5019 (define_insn ""
5020   [(set (mem:DF (plus:SI (match_operand:SI 1 "register_operand" "d")
5021                          (match_operand:SI 2 "register_operand" "d")))
5022         (match_operand:DF 0 "register_operand" "f"))]
5023   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5024   "sdxc1\\t%0,%1(%2)"
5025   [(set_attr "type"     "store")
5026    (set_attr "mode"     "DF")
5027    (set_attr "length"   "4")])
5028
5029 (define_insn ""
5030   [(set (mem:DF (plus:DI (match_operand:DI 1 "register_operand" "d")
5031                          (match_operand:DI 2 "register_operand" "d")))
5032         (match_operand:DF 0 "register_operand" "f"))]
5033   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5034   "sdxc1\\t%0,%1(%2)"
5035   [(set_attr "type"     "store")
5036    (set_attr "mode"     "DF")
5037    (set_attr "length"   "4")])
5038
5039 ;; 16-bit Integer moves
5040
5041 ;; Unlike most other insns, the move insns can't be split with
5042 ;; different predicates, because register spilling and other parts of
5043 ;; the compiler, have memoized the insn number already.
5044 ;; Unsigned loads are used because BYTE_LOADS_ZERO_EXTEND is defined
5045
5046 (define_expand "movhi"
5047   [(set (match_operand:HI 0 "nonimmediate_operand" "")
5048         (match_operand:HI 1 "general_operand" ""))]
5049   ""
5050   "
5051 {
5052   if ((reload_in_progress | reload_completed) == 0
5053       && !register_operand (operands[0], HImode)
5054       && !register_operand (operands[1], HImode)
5055       && (TARGET_MIPS16
5056           || (GET_CODE (operands[1]) != CONST_INT
5057           || INTVAL (operands[1]) != 0)))
5058     {
5059       rtx temp = force_reg (HImode, operands[1]);
5060       emit_move_insn (operands[0], temp);
5061       DONE;
5062     }
5063 }")
5064
5065 ;; The difference between these two is whether or not ints are allowed
5066 ;; in FP registers (off by default, use -mdebugh to enable).
5067
5068 (define_insn "movhi_internal"
5069   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x,*d")
5070         (match_operand:HI 1 "general_operand"       "d,IK,m,dJ,*f,*d,*f,*d,*x"))]
5071   "!TARGET_MIPS16
5072    && (register_operand (operands[0], HImode)
5073        || register_operand (operands[1], HImode)
5074        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
5075   "@
5076     move\t%0,%1
5077     li\t%0,%1
5078     lhu\t%0,%1
5079     sh\t%z1,%0
5080     mfc1\t%0,%1
5081     mtc1\t%1,%0
5082     mov.s\t%0,%1
5083     mt%0\t%1
5084     mf%1\t%0"
5085   [(set_attr "type"     "move,arith,load,store,xfer,xfer,move,hilo,hilo")
5086    (set_attr "mode"     "HI")
5087    (set_attr "length"   "4,4,*,*,4,4,4,4,4")])
5088
5089 (define_insn ""
5090   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5091         (match_operand:HI 1 "general_operand"      "d,d,y,K,N,m,d,*x"))]
5092   "TARGET_MIPS16
5093    && (register_operand (operands[0], HImode)
5094        || register_operand (operands[1], HImode))"
5095   "@
5096     move\t%0,%1
5097     move\t%0,%1
5098     move\t%0,%1
5099     li\t%0,%1
5100     li\t%0,%n1\;neg\t%0
5101     lhu\t%0,%1
5102     sh\t%1,%0
5103     mf%1\t%0"
5104   [(set_attr "type"     "move,move,move,arith,arith,load,store,hilo")
5105    (set_attr "mode"     "HI")
5106    (set_attr_alternative "length"
5107                 [(const_int 4)
5108                  (const_int 4)
5109                  (const_int 4)
5110                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1" "")
5111                                (const_int 4)
5112                                (const_int 8))
5113                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1" "")
5114                                (const_int 8)
5115                                (const_int 12))
5116                  (const_string "*")
5117                  (const_string "*")
5118                  (const_int 4)])])
5119
5120
5121 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
5122 ;; when the original load is a 4 byte instruction but the add and the
5123 ;; load are 2 2 byte instructions.
5124
5125 (define_split
5126   [(set (match_operand:HI 0 "register_operand" "")
5127         (mem:HI (plus:SI (match_dup 0)
5128                          (match_operand:SI 1 "const_int_operand" ""))))]
5129   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5130    && GET_CODE (operands[0]) == REG
5131    && M16_REG_P (REGNO (operands[0]))
5132    && GET_CODE (operands[1]) == CONST_INT
5133    && ((INTVAL (operands[1]) < 0
5134         && INTVAL (operands[1]) >= -0x80)
5135        || (INTVAL (operands[1]) >= 32 * 2
5136            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
5137        || (INTVAL (operands[1]) >= 0
5138            && INTVAL (operands[1]) < 32 * 2
5139            && (INTVAL (operands[1]) & 1) != 0))"
5140   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5141    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
5142   "
5143 {
5144   HOST_WIDE_INT val = INTVAL (operands[1]);
5145
5146   if (val < 0)
5147     operands[2] = GEN_INT (0);
5148   else if (val >= 32 * 2)
5149     {
5150       int off = val & 1;
5151
5152       operands[1] = GEN_INT (0x7e + off);
5153       operands[2] = GEN_INT (val - off - 0x7e);
5154     }
5155   else
5156     {
5157       int off = val & 1;
5158
5159       operands[1] = GEN_INT (off);
5160       operands[2] = GEN_INT (val - off);
5161     }
5162 }")
5163
5164 ;; 8-bit Integer moves
5165
5166 ;; Unlike most other insns, the move insns can't be split with
5167 ;; different predicates, because register spilling and other parts of
5168 ;; the compiler, have memoized the insn number already.
5169 ;; Unsigned loads are used because BYTE_LOADS_ZERO_EXTEND is defined
5170
5171 (define_expand "movqi"
5172   [(set (match_operand:QI 0 "nonimmediate_operand" "")
5173         (match_operand:QI 1 "general_operand" ""))]
5174   ""
5175   "
5176 {
5177   if ((reload_in_progress | reload_completed) == 0
5178       && !register_operand (operands[0], QImode)
5179       && !register_operand (operands[1], QImode)
5180       && (TARGET_MIPS16
5181           || (GET_CODE (operands[1]) != CONST_INT
5182           || INTVAL (operands[1]) != 0)))
5183     {
5184       rtx temp = force_reg (QImode, operands[1]);
5185       emit_move_insn (operands[0], temp);
5186       DONE;
5187     }
5188 }")
5189
5190 ;; The difference between these two is whether or not ints are allowed
5191 ;; in FP registers (off by default, use -mdebugh to enable).
5192
5193 (define_insn "movqi_internal"
5194   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x,*d")
5195         (match_operand:QI 1 "general_operand"       "d,IK,m,dJ,*f,*d,*f,*d,*x"))]
5196   "!TARGET_MIPS16
5197    && (register_operand (operands[0], QImode)
5198        || register_operand (operands[1], QImode)
5199        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
5200   "@
5201     move\t%0,%1
5202     li\t%0,%1
5203     lbu\t%0,%1
5204     sb\t%z1,%0
5205     mfc1\t%0,%1
5206     mtc1\t%1,%0
5207     mov.s\t%0,%1
5208     mt%0\t%1
5209     mf%1\t%0"
5210   [(set_attr "type"     "move,arith,load,store,xfer,xfer,move,hilo,hilo")
5211    (set_attr "mode"     "QI")
5212    (set_attr "length"   "4,4,*,*,4,4,4,4,4")])
5213
5214 (define_insn ""
5215   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5216         (match_operand:QI 1 "general_operand"      "d,d,y,K,N,m,d,*x"))]
5217   "TARGET_MIPS16
5218    && (register_operand (operands[0], QImode)
5219        || register_operand (operands[1], QImode))"
5220   "@
5221     move\t%0,%1
5222     move\t%0,%1
5223     move\t%0,%1
5224     li\t%0,%1
5225     li\t%0,%n1\;neg\t%0
5226     lbu\t%0,%1
5227     sb\t%1,%0
5228     mf%1\t%0"
5229   [(set_attr "type"     "move,move,move,arith,arith,load,store,hilo")
5230    (set_attr "mode"     "QI")
5231    (set_attr "length"   "4,4,4,4,8,*,*,4")])
5232
5233 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
5234 ;; when the original load is a 4 byte instruction but the add and the
5235 ;; load are 2 2 byte instructions.
5236
5237 (define_split
5238   [(set (match_operand:QI 0 "register_operand" "")
5239         (mem:QI (plus:SI (match_dup 0)
5240                          (match_operand:SI 1 "const_int_operand" ""))))]
5241   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5242    && GET_CODE (operands[0]) == REG
5243    && M16_REG_P (REGNO (operands[0]))
5244    && GET_CODE (operands[1]) == CONST_INT
5245    && ((INTVAL (operands[1]) < 0
5246         && INTVAL (operands[1]) >= -0x80)
5247        || (INTVAL (operands[1]) >= 32
5248            && INTVAL (operands[1]) <= 31 + 0x7f))"
5249   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5250    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
5251   "
5252 {
5253   HOST_WIDE_INT val = INTVAL (operands[1]);
5254
5255   if (val < 0)
5256     operands[2] = GEN_INT (0);
5257   else
5258     {
5259       operands[1] = GEN_INT (0x7f);
5260       operands[2] = GEN_INT (val - 0x7f);
5261     }
5262 }")
5263
5264 ;; 32-bit floating point moves
5265
5266 (define_expand "movsf"
5267   [(set (match_operand:SF 0 "nonimmediate_operand" "")
5268         (match_operand:SF 1 "general_operand" ""))]
5269   ""
5270   "
5271 {
5272   if ((reload_in_progress | reload_completed) == 0
5273       && !register_operand (operands[0], SFmode)
5274       && !nonmemory_operand (operands[1], SFmode))
5275     operands[1] = force_reg (SFmode, operands[1]);
5276 }")
5277
5278 (define_insn "movsf_internal1"
5279   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,*f,*d,*d,*d,*m")
5280         (match_operand:SF 1 "general_operand" "f,G,m,fG,*d,*f,*G*d,*m,*d"))]
5281   "TARGET_HARD_FLOAT
5282    && (register_operand (operands[0], SFmode)
5283        || nonmemory_operand (operands[1], SFmode))"
5284   { return mips_output_move (operands[0], operands[1]); }
5285   [(set_attr "type"     "move,xfer,load,store,xfer,xfer,move,load,store")
5286    (set_attr "mode"     "SF")
5287    (set_attr "length"   "4,4,*,*,4,4,4,*,*")])
5288
5289 (define_insn "movsf_internal2"
5290   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
5291         (match_operand:SF 1 "general_operand" "      Gd,m,d"))]
5292   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
5293    && (register_operand (operands[0], SFmode)
5294        || nonmemory_operand (operands[1], SFmode))"
5295   { return mips_output_move (operands[0], operands[1]); }
5296   [(set_attr "type"     "move,load,store")
5297    (set_attr "mode"     "SF")
5298    (set_attr "length"   "4,*,*")])
5299
5300 (define_insn ""
5301   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
5302         (match_operand:SF 1 "nonimmediate_operand" "d,d,y,m,d"))]
5303   "TARGET_MIPS16
5304    && (register_operand (operands[0], SFmode)
5305        || register_operand (operands[1], SFmode))"
5306   { return mips_output_move (operands[0], operands[1]); }
5307   [(set_attr "type"     "move,move,move,load,store")
5308    (set_attr "mode"     "SF")
5309    (set_attr "length"   "4,4,4,*,*")])
5310
5311
5312 ;; 64-bit floating point moves
5313
5314 (define_expand "movdf"
5315   [(set (match_operand:DF 0 "nonimmediate_operand" "")
5316         (match_operand:DF 1 "general_operand" ""))]
5317   ""
5318   "
5319 {
5320   if ((reload_in_progress | reload_completed) == 0
5321       && !register_operand (operands[0], DFmode)
5322       && !nonmemory_operand (operands[1], DFmode))
5323     operands[1] = force_reg (DFmode, operands[1]);
5324 }")
5325
5326 (define_insn "movdf_internal1a"
5327   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,*f,*d,*d,*d,*m")
5328         (match_operand:DF 1 "general_operand" "f,G,m,fG,*d,*f,*d*G,*m,*d"))]
5329   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_64BIT
5330    && (register_operand (operands[0], DFmode)
5331        || nonmemory_operand (operands[1], DFmode))"
5332   { return mips_output_move (operands[0], operands[1]); }
5333   [(set_attr "type"     "move,xfer,load,store,xfer,xfer,move,load,store")
5334    (set_attr "mode"     "DF")
5335    (set_attr "length"   "4,4,*,*,4,4,4,*,*")])
5336
5337 (define_insn "movdf_internal1b"
5338   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,*f,*d,*d,*d,*m")
5339         (match_operand:DF 1 "general_operand" "f,G,m,fG,*d,*f,*d*G,*m,*d"))]
5340   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT
5341    && (register_operand (operands[0], DFmode)
5342        || nonmemory_operand (operands[1], DFmode))"
5343   { return mips_output_move (operands[0], operands[1]); }
5344   [(set_attr "type"     "move,xfer,load,store,xfer,xfer,move,load,store")
5345    (set_attr "mode"     "DF")
5346    (set_attr "length"   "4,8,*,*,8,8,8,*,*")])
5347
5348 (define_insn "movdf_internal2"
5349   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m,d,f,f")
5350         (match_operand:DF 1 "general_operand" "dG,m,dG,f,d,f"))]
5351   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
5352    && (register_operand (operands[0], DFmode)
5353        || nonmemory_operand (operands[1], DFmode))"
5354   { return mips_output_move (operands[0], operands[1]); }
5355   [(set_attr "type"     "move,load,store,xfer,xfer,move")
5356    (set_attr "mode"     "DF")
5357    (set_attr "length"   "8,*,*,4,4,4")])
5358
5359 (define_insn ""
5360   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
5361         (match_operand:DF 1 "nonimmediate_operand" "d,d,y,m,d"))]
5362   "TARGET_MIPS16
5363    && (register_operand (operands[0], DFmode)
5364        || register_operand (operands[1], DFmode))"
5365   { return mips_output_move (operands[0], operands[1]); }
5366   [(set_attr "type"     "move,move,move,load,store")
5367    (set_attr "mode"     "DF")
5368    (set_attr "length"   "8,8,8,*,*")])
5369
5370 (define_split
5371   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5372         (match_operand:DI 1 "general_operand" ""))]
5373   "reload_completed && !TARGET_64BIT
5374    && mips_split_64bit_move_p (operands[0], operands[1])"
5375   [(const_int 0)]
5376   {
5377     mips_split_64bit_move (operands[0], operands[1]);
5378     DONE;
5379   })
5380
5381 (define_split
5382   [(set (match_operand:DF 0 "nonimmediate_operand" "")
5383         (match_operand:DF 1 "general_operand" ""))]
5384   "reload_completed && !TARGET_64BIT
5385    && mips_split_64bit_move_p (operands[0], operands[1])"
5386   [(const_int 0)]
5387   {
5388     mips_split_64bit_move (operands[0], operands[1]);
5389     DONE;
5390   })
5391
5392 ;; Patterns for loading or storing part of a paired floating point
5393 ;; register.  We need them because odd-numbered floating-point registers
5394 ;; are not fully independent: see mips_split_64bit_move.
5395
5396 ;; Load the low word of operand 0 with operand 1.
5397 (define_insn "load_df_low"
5398   [(set (match_operand:DF 0 "register_operand" "=f,f")
5399         (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")]
5400                    UNSPEC_LOAD_DF_LOW))]
5401   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
5402   {
5403     operands[0] = mips_subword (operands[0], 0);
5404     return mips_output_move (operands[0], operands[1]);
5405   }
5406   [(set_attr "type"     "xfer,load")
5407    (set_attr "mode"     "SF")
5408    (set_attr "length"   "4")])
5409
5410 ;; Load the high word of operand 0 from operand 1, preserving the value
5411 ;; in the low word.
5412 (define_insn "load_df_high"
5413   [(set (match_operand:DF 0 "register_operand" "=f,f")
5414         (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")
5415                     (match_operand:DF 2 "register_operand" "0,0")]
5416                    UNSPEC_LOAD_DF_HIGH))]
5417   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
5418   {
5419     operands[0] = mips_subword (operands[0], 1);
5420     return mips_output_move (operands[0], operands[1]);
5421   }
5422   [(set_attr "type"     "xfer,load")
5423    (set_attr "mode"     "SF")
5424    (set_attr "length"   "4")])
5425
5426 ;; Store the high word of operand 1 in operand 0.  The corresponding
5427 ;; low-word move is done in the normal way.
5428 (define_insn "store_df_high"
5429   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
5430         (unspec:SI [(match_operand:DF 1 "register_operand" "f,f")]
5431                    UNSPEC_STORE_DF_HIGH))]
5432   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
5433   {
5434     operands[1] = mips_subword (operands[1], 1);
5435     return mips_output_move (operands[0], operands[1]);
5436   }
5437   [(set_attr "type"     "xfer,store")
5438    (set_attr "mode"     "SF")
5439    (set_attr "length"   "4")])
5440
5441 ;; The use of gp is hidden when not using explicit relocations.
5442 ;; This blockage instruction prevents the gp load from being
5443 ;; scheduled after an implicit use of gp.  It also prevents
5444 ;; the load from being deleted as dead.
5445 (define_insn "loadgp_blockage"
5446   [(unspec_volatile [(reg:DI 28)] UNSPEC_BLOCKAGE)]
5447   ""
5448   ""
5449   [(set_attr "type"     "unknown")
5450    (set_attr "mode"     "none")
5451    (set_attr "length"   "0")])
5452
5453 ;; Emit a .cprestore directive, which expands to a single store instruction.
5454 ;; Note that we continue to use .cprestore for explicit reloc code so that
5455 ;; jals inside inlines asms will work correctly.
5456 (define_insn "cprestore"
5457   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
5458                     UNSPEC_CPRESTORE)]
5459   ""
5460   ".cprestore\t%0"
5461   [(set_attr "type" "store")
5462    (set_attr "length" "4")])
5463 \f
5464 ;; Block moves, see mips.c for more details.
5465 ;; Argument 0 is the destination
5466 ;; Argument 1 is the source
5467 ;; Argument 2 is the length
5468 ;; Argument 3 is the alignment
5469
5470 (define_expand "movstrsi"
5471   [(parallel [(set (match_operand:BLK 0 "general_operand" "")
5472                    (match_operand:BLK 1 "general_operand" ""))
5473               (use (match_operand:SI 2 "" ""))
5474               (use (match_operand:SI 3 "const_int_operand" ""))])]
5475   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5476   {
5477     if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5478       DONE;
5479     else
5480       FAIL;
5481   })
5482 \f
5483 ;;
5484 ;;  ....................
5485 ;;
5486 ;;      SHIFTS
5487 ;;
5488 ;;  ....................
5489
5490 ;; Many of these instructions uses trivial define_expands, because we
5491 ;; want to use a different set of constraints when TARGET_MIPS16.
5492
5493 (define_expand "ashlsi3"
5494   [(set (match_operand:SI 0 "register_operand" "=d")
5495         (ashift:SI (match_operand:SI 1 "register_operand" "d")
5496                    (match_operand:SI 2 "arith_operand" "dI")))]
5497   ""
5498   "
5499 {
5500   /* On the mips16, a shift of more than 8 is a four byte instruction,
5501      so, for a shift between 8 and 16, it is just as fast to do two
5502      shifts of 8 or less.  If there is a lot of shifting going on, we
5503      may win in CSE.  Otherwise combine will put the shifts back
5504      together again.  This can be called by function_arg, so we must
5505      be careful not to allocate a new register if we've reached the
5506      reload pass.  */
5507   if (TARGET_MIPS16
5508       && optimize
5509       && GET_CODE (operands[2]) == CONST_INT
5510       && INTVAL (operands[2]) > 8
5511       && INTVAL (operands[2]) <= 16
5512       && ! reload_in_progress
5513       && ! reload_completed)
5514     {
5515       rtx temp = gen_reg_rtx (SImode);
5516
5517       emit_insn (gen_ashlsi3_internal2 (temp, operands[1], GEN_INT (8)));
5518       emit_insn (gen_ashlsi3_internal2 (operands[0], temp,
5519                                         GEN_INT (INTVAL (operands[2]) - 8)));
5520       DONE;
5521     }
5522 }")
5523
5524 (define_insn "ashlsi3_internal1"
5525   [(set (match_operand:SI 0 "register_operand" "=d")
5526         (ashift:SI (match_operand:SI 1 "register_operand" "d")
5527                    (match_operand:SI 2 "arith_operand" "dI")))]
5528   "!TARGET_MIPS16"
5529   "*
5530 {
5531   if (GET_CODE (operands[2]) == CONST_INT)
5532     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5533
5534   return \"sll\\t%0,%1,%2\";
5535 }"
5536   [(set_attr "type"     "arith")
5537    (set_attr "mode"     "SI")])
5538
5539 (define_insn "ashlsi3_internal1_extend"
5540   [(set (match_operand:DI 0 "register_operand" "=d")
5541        (sign_extend:DI (ashift:SI (match_operand:SI 1 "register_operand" "d")
5542                                   (match_operand:SI 2 "arith_operand" "dI"))))]
5543   "TARGET_64BIT && !TARGET_MIPS16"
5544   "*
5545 {
5546   if (GET_CODE (operands[2]) == CONST_INT)
5547     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5548
5549   return \"sll\\t%0,%1,%2\";
5550 }"
5551   [(set_attr "type"    "arith")
5552    (set_attr "mode"    "DI")])
5553
5554
5555 (define_insn "ashlsi3_internal2"
5556   [(set (match_operand:SI 0 "register_operand" "=d,d")
5557         (ashift:SI (match_operand:SI 1 "register_operand" "0,d")
5558                    (match_operand:SI 2 "arith_operand" "d,I")))]
5559   "TARGET_MIPS16"
5560   "*
5561 {
5562   if (which_alternative == 0)
5563     return \"sll\\t%0,%2\";
5564
5565   if (GET_CODE (operands[2]) == CONST_INT)
5566     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5567
5568   return \"sll\\t%0,%1,%2\";
5569 }"
5570   [(set_attr "type"     "arith")
5571    (set_attr "mode"     "SI")
5572    (set_attr_alternative "length"
5573                 [(const_int 4)
5574                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
5575                                (const_int 4)
5576                                (const_int 8))])])
5577
5578 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5579
5580 (define_split
5581   [(set (match_operand:SI 0 "register_operand" "")
5582         (ashift:SI (match_operand:SI 1 "register_operand" "")
5583                    (match_operand:SI 2 "const_int_operand" "")))]
5584   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5585    && GET_CODE (operands[2]) == CONST_INT
5586    && INTVAL (operands[2]) > 8
5587    && INTVAL (operands[2]) <= 16"
5588   [(set (match_dup 0) (ashift:SI (match_dup 1) (const_int 8)))
5589    (set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))]
5590 "
5591 {
5592   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
5593 }")
5594
5595 (define_expand "ashldi3"
5596   [(parallel [(set (match_operand:DI 0 "register_operand" "")
5597                    (ashift:DI (match_operand:DI 1 "register_operand" "")
5598                               (match_operand:SI 2 "arith_operand" "")))
5599               (clobber (match_dup  3))])]
5600   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
5601   "
5602 {
5603   if (TARGET_64BIT)
5604     {
5605       /* On the mips16, a shift of more than 8 is a four byte
5606          instruction, so, for a shift between 8 and 16, it is just as
5607          fast to do two shifts of 8 or less.  If there is a lot of
5608          shifting going on, we may win in CSE.  Otherwise combine will
5609          put the shifts back together again.  This can be called by
5610          function_arg, so we must be careful not to allocate a new
5611          register if we've reached the reload pass.  */
5612       if (TARGET_MIPS16
5613           && optimize
5614           && GET_CODE (operands[2]) == CONST_INT
5615           && INTVAL (operands[2]) > 8
5616           && INTVAL (operands[2]) <= 16
5617           && ! reload_in_progress
5618           && ! reload_completed)
5619         {
5620           rtx temp = gen_reg_rtx (DImode);
5621
5622           emit_insn (gen_ashldi3_internal4 (temp, operands[1], GEN_INT (8)));
5623           emit_insn (gen_ashldi3_internal4 (operands[0], temp,
5624                                             GEN_INT (INTVAL (operands[2]) - 8)));
5625           DONE;
5626         }
5627
5628       emit_insn (gen_ashldi3_internal4 (operands[0], operands[1],
5629                                         operands[2]));
5630       DONE;
5631     }
5632
5633   operands[3] = gen_reg_rtx (SImode);
5634 }")
5635
5636
5637 (define_insn "ashldi3_internal"
5638   [(set (match_operand:DI 0 "register_operand" "=&d")
5639         (ashift:DI (match_operand:DI 1 "register_operand" "d")
5640                    (match_operand:SI 2 "register_operand" "d")))
5641    (clobber (match_operand:SI 3 "register_operand" "=d"))]
5642   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
5643   "*
5644 {
5645   operands[4] = const0_rtx;
5646
5647   return \"sll\\t%3,%2,26\\n\\
5648 \\tbgez\\t%3,1f%#\\n\\
5649 \\tsll\\t%M0,%L1,%2\\n\\
5650 \\t%(b\\t3f\\n\\
5651 \\tmove\\t%L0,%z4%)\\n\\
5652 \\n\\
5653 %~1:\\n\\
5654 \\t%(beq\\t%3,%z4,2f\\n\\
5655 \\tsll\\t%M0,%M1,%2%)\\n\\
5656 \\n\\
5657 \\tsubu\\t%3,%z4,%2\\n\\
5658 \\tsrl\\t%3,%L1,%3\\n\\
5659 \\tor\\t%M0,%M0,%3\\n\\
5660 %~2:\\n\\
5661 \\tsll\\t%L0,%L1,%2\\n\\
5662 %~3:\";
5663 }"
5664   [(set_attr "type"     "darith")
5665    (set_attr "mode"     "SI")
5666    (set_attr "length"   "48")])
5667
5668
5669 (define_insn "ashldi3_internal2"
5670   [(set (match_operand:DI 0 "register_operand" "=d")
5671         (ashift:DI (match_operand:DI 1 "register_operand" "d")
5672                    (match_operand:SI 2 "small_int" "IJK")))
5673    (clobber (match_operand:SI 3 "register_operand" "=d"))]
5674   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
5675    && (INTVAL (operands[2]) & 32) != 0"
5676   "*
5677 {
5678   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5679   operands[4] = const0_rtx;
5680   return \"sll\\t%M0,%L1,%2\;move\\t%L0,%z4\";
5681 }"
5682   [(set_attr "type"     "darith")
5683    (set_attr "mode"     "DI")
5684    (set_attr "length"   "8")])
5685
5686
5687 (define_split
5688   [(set (match_operand:DI 0 "register_operand" "")
5689         (ashift:DI (match_operand:DI 1 "register_operand" "")
5690                    (match_operand:SI 2 "small_int" "")))
5691    (clobber (match_operand:SI 3 "register_operand" ""))]
5692   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
5693    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
5694    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
5695    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
5696    && (INTVAL (operands[2]) & 32) != 0"
5697
5698   [(set (subreg:SI (match_dup 0) 4) (ashift:SI (subreg:SI (match_dup 1) 0) (match_dup 2)))
5699    (set (subreg:SI (match_dup 0) 0) (const_int 0))]
5700
5701   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
5702
5703
5704 (define_split
5705   [(set (match_operand:DI 0 "register_operand" "")
5706         (ashift:DI (match_operand:DI 1 "register_operand" "")
5707                    (match_operand:SI 2 "small_int" "")))
5708    (clobber (match_operand:SI 3 "register_operand" ""))]
5709   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
5710    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
5711    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
5712    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
5713    && (INTVAL (operands[2]) & 32) != 0"
5714
5715   [(set (subreg:SI (match_dup 0) 0) (ashift:SI (subreg:SI (match_dup 1) 4) (match_dup 2)))
5716    (set (subreg:SI (match_dup 0) 4) (const_int 0))]
5717
5718   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
5719
5720
5721 (define_insn "ashldi3_internal3"
5722   [(set (match_operand:DI 0 "register_operand" "=d")
5723         (ashift:DI (match_operand:DI 1 "register_operand" "d")
5724                    (match_operand:SI 2 "small_int" "IJK")))
5725    (clobber (match_operand:SI 3 "register_operand" "=d"))]
5726   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
5727    && (INTVAL (operands[2]) & 63) < 32
5728    && (INTVAL (operands[2]) & 63) != 0"
5729   "*
5730 {
5731   int amount = INTVAL (operands[2]);
5732
5733   operands[2] = GEN_INT (amount & 31);
5734   operands[4] = const0_rtx;
5735   operands[5] = GEN_INT ((-amount) & 31);
5736
5737   return \"sll\\t%M0,%M1,%2\;srl\\t%3,%L1,%5\;or\\t%M0,%M0,%3\;sll\\t%L0,%L1,%2\";
5738 }"
5739   [(set_attr "type"     "darith")
5740    (set_attr "mode"     "DI")
5741    (set_attr "length"   "16")])
5742
5743
5744 (define_split
5745   [(set (match_operand:DI 0 "register_operand" "")
5746         (ashift:DI (match_operand:DI 1 "register_operand" "")
5747                    (match_operand:SI 2 "small_int" "")))
5748    (clobber (match_operand:SI 3 "register_operand" ""))]
5749   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
5750    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
5751    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
5752    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
5753    && (INTVAL (operands[2]) & 63) < 32
5754    && (INTVAL (operands[2]) & 63) != 0"
5755
5756   [(set (subreg:SI (match_dup 0) 4)
5757         (ashift:SI (subreg:SI (match_dup 1) 4)
5758                    (match_dup 2)))
5759
5760    (set (match_dup 3)
5761         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
5762                      (match_dup 4)))
5763
5764    (set (subreg:SI (match_dup 0) 4)
5765         (ior:SI (subreg:SI (match_dup 0) 4)
5766                 (match_dup 3)))
5767
5768    (set (subreg:SI (match_dup 0) 0)
5769         (ashift:SI (subreg:SI (match_dup 1) 0)
5770                    (match_dup 2)))]
5771   "
5772 {
5773   int amount = INTVAL (operands[2]);
5774   operands[2] = GEN_INT (amount & 31);
5775   operands[4] = GEN_INT ((-amount) & 31);
5776 }")
5777
5778
5779 (define_split
5780   [(set (match_operand:DI 0 "register_operand" "")
5781         (ashift:DI (match_operand:DI 1 "register_operand" "")
5782                    (match_operand:SI 2 "small_int" "")))
5783    (clobber (match_operand:SI 3 "register_operand" ""))]
5784   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
5785    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
5786    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
5787    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
5788    && (INTVAL (operands[2]) & 63) < 32
5789    && (INTVAL (operands[2]) & 63) != 0"
5790
5791   [(set (subreg:SI (match_dup 0) 0)
5792         (ashift:SI (subreg:SI (match_dup 1) 0)
5793                    (match_dup 2)))
5794
5795    (set (match_dup 3)
5796         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
5797                      (match_dup 4)))
5798
5799    (set (subreg:SI (match_dup 0) 0)
5800         (ior:SI (subreg:SI (match_dup 0) 0)
5801                 (match_dup 3)))
5802
5803    (set (subreg:SI (match_dup 0) 4)
5804         (ashift:SI (subreg:SI (match_dup 1) 4)
5805                    (match_dup 2)))]
5806   "
5807 {
5808   int amount = INTVAL (operands[2]);
5809   operands[2] = GEN_INT (amount & 31);
5810   operands[4] = GEN_INT ((-amount) & 31);
5811 }")
5812
5813
5814 (define_insn "ashldi3_internal4"
5815   [(set (match_operand:DI 0 "register_operand" "=d")
5816         (ashift:DI (match_operand:DI 1 "register_operand" "d")
5817                    (match_operand:SI 2 "arith_operand" "dI")))]
5818   "TARGET_64BIT && !TARGET_MIPS16"
5819   "*
5820 {
5821   if (GET_CODE (operands[2]) == CONST_INT)
5822     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5823
5824   return \"dsll\\t%0,%1,%2\";
5825 }"
5826   [(set_attr "type"     "arith")
5827    (set_attr "mode"     "DI")])
5828
5829 (define_insn ""
5830   [(set (match_operand:DI 0 "register_operand" "=d,d")
5831         (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
5832                    (match_operand:SI 2 "arith_operand" "d,I")))]
5833   "TARGET_64BIT && TARGET_MIPS16"
5834   "*
5835 {
5836   if (which_alternative == 0)
5837     return \"dsll\\t%0,%2\";
5838
5839   if (GET_CODE (operands[2]) == CONST_INT)
5840     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5841
5842   return \"dsll\\t%0,%1,%2\";
5843 }"
5844   [(set_attr "type"     "arith")
5845    (set_attr "mode"     "DI")
5846    (set_attr_alternative "length"
5847                 [(const_int 4)
5848                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
5849                                (const_int 4)
5850                                (const_int 8))])])
5851
5852
5853 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5854
5855 (define_split
5856   [(set (match_operand:DI 0 "register_operand" "")
5857         (ashift:DI (match_operand:DI 1 "register_operand" "")
5858                    (match_operand:SI 2 "const_int_operand" "")))]
5859   "TARGET_MIPS16 && TARGET_64BIT && !TARGET_DEBUG_D_MODE
5860    && reload_completed
5861    && GET_CODE (operands[2]) == CONST_INT
5862    && INTVAL (operands[2]) > 8
5863    && INTVAL (operands[2]) <= 16"
5864   [(set (match_dup 0) (ashift:DI (match_dup 1) (const_int 8)))
5865    (set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))]
5866 "
5867 {
5868   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
5869 }")
5870
5871 (define_expand "ashrsi3"
5872   [(set (match_operand:SI 0 "register_operand" "=d")
5873         (ashiftrt:SI (match_operand:SI 1 "register_operand" "d")
5874                      (match_operand:SI 2 "arith_operand" "dI")))]
5875   ""
5876   "
5877 {
5878   /* On the mips16, a shift of more than 8 is a four byte instruction,
5879      so, for a shift between 8 and 16, it is just as fast to do two
5880      shifts of 8 or less.  If there is a lot of shifting going on, we
5881      may win in CSE.  Otherwise combine will put the shifts back
5882      together again.  */
5883   if (TARGET_MIPS16
5884       && optimize
5885       && GET_CODE (operands[2]) == CONST_INT
5886       && INTVAL (operands[2]) > 8
5887       && INTVAL (operands[2]) <= 16)
5888     {
5889       rtx temp = gen_reg_rtx (SImode);
5890
5891       emit_insn (gen_ashrsi3_internal2 (temp, operands[1], GEN_INT (8)));
5892       emit_insn (gen_ashrsi3_internal2 (operands[0], temp,
5893                                         GEN_INT (INTVAL (operands[2]) - 8)));
5894       DONE;
5895     }
5896 }")
5897
5898 (define_insn "ashrsi3_internal1"
5899   [(set (match_operand:SI 0 "register_operand" "=d")
5900         (ashiftrt:SI (match_operand:SI 1 "register_operand" "d")
5901                      (match_operand:SI 2 "arith_operand" "dI")))]
5902   "!TARGET_MIPS16"
5903   "*
5904 {
5905   if (GET_CODE (operands[2]) == CONST_INT)
5906     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5907
5908   return \"sra\\t%0,%1,%2\";
5909 }"
5910   [(set_attr "type"     "arith")
5911    (set_attr "mode"     "SI")])
5912
5913 (define_insn "ashrsi3_internal2"
5914   [(set (match_operand:SI 0 "register_operand" "=d,d")
5915         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,d")
5916                      (match_operand:SI 2 "arith_operand" "d,I")))]
5917   "TARGET_MIPS16"
5918   "*
5919 {
5920   if (which_alternative == 0)
5921     return \"sra\\t%0,%2\";
5922
5923   if (GET_CODE (operands[2]) == CONST_INT)
5924     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5925
5926   return \"sra\\t%0,%1,%2\";
5927 }"
5928   [(set_attr "type"     "arith")
5929    (set_attr "mode"     "SI")
5930    (set_attr_alternative "length"
5931                 [(const_int 4)
5932                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
5933                                (const_int 4)
5934                                (const_int 8))])])
5935
5936
5937 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5938
5939 (define_split
5940   [(set (match_operand:SI 0 "register_operand" "")
5941         (ashiftrt:SI (match_operand:SI 1 "register_operand" "")
5942                      (match_operand:SI 2 "const_int_operand" "")))]
5943   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5944    && GET_CODE (operands[2]) == CONST_INT
5945    && INTVAL (operands[2]) > 8
5946    && INTVAL (operands[2]) <= 16"
5947   [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (const_int 8)))
5948    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
5949 "
5950 {
5951   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
5952 }")
5953
5954 (define_expand "ashrdi3"
5955   [(parallel [(set (match_operand:DI 0 "register_operand" "")
5956                    (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
5957                                 (match_operand:SI 2 "arith_operand" "")))
5958               (clobber (match_dup  3))])]
5959   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
5960   "
5961 {
5962   if (TARGET_64BIT)
5963     {
5964       /* On the mips16, a shift of more than 8 is a four byte
5965          instruction, so, for a shift between 8 and 16, it is just as
5966          fast to do two shifts of 8 or less.  If there is a lot of
5967          shifting going on, we may win in CSE.  Otherwise combine will
5968          put the shifts back together again.  */
5969       if (TARGET_MIPS16
5970           && optimize
5971           && GET_CODE (operands[2]) == CONST_INT
5972           && INTVAL (operands[2]) > 8
5973           && INTVAL (operands[2]) <= 16)
5974         {
5975           rtx temp = gen_reg_rtx (DImode);
5976
5977           emit_insn (gen_ashrdi3_internal4 (temp, operands[1], GEN_INT (8)));
5978           emit_insn (gen_ashrdi3_internal4 (operands[0], temp,
5979                                             GEN_INT (INTVAL (operands[2]) - 8)));
5980           DONE;
5981         }
5982
5983       emit_insn (gen_ashrdi3_internal4 (operands[0], operands[1],
5984                                         operands[2]));
5985       DONE;
5986     }
5987
5988   operands[3] = gen_reg_rtx (SImode);
5989 }")
5990
5991
5992 (define_insn "ashrdi3_internal"
5993   [(set (match_operand:DI 0 "register_operand" "=&d")
5994         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
5995                      (match_operand:SI 2 "register_operand" "d")))
5996    (clobber (match_operand:SI 3 "register_operand" "=d"))]
5997   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
5998   "*
5999 {
6000   operands[4] = const0_rtx;
6001
6002   return \"sll\\t%3,%2,26\\n\\
6003 \\tbgez\\t%3,1f%#\\n\\
6004 \\tsra\\t%L0,%M1,%2\\n\\
6005 \\t%(b\\t3f\\n\\
6006 \\tsra\\t%M0,%M1,31%)\\n\\
6007 \\n\\
6008 %~1:\\n\\
6009 \\t%(beq\\t%3,%z4,2f\\n\\
6010 \\tsrl\\t%L0,%L1,%2%)\\n\\
6011 \\n\\
6012 \\tsubu\\t%3,%z4,%2\\n\\
6013 \\tsll\\t%3,%M1,%3\\n\\
6014 \\tor\\t%L0,%L0,%3\\n\\
6015 %~2:\\n\\
6016 \\tsra\\t%M0,%M1,%2\\n\\
6017 %~3:\";
6018 }"
6019   [(set_attr "type"     "darith")
6020    (set_attr "mode"     "DI")
6021    (set_attr "length"   "48")])
6022
6023
6024 (define_insn "ashrdi3_internal2"
6025   [(set (match_operand:DI 0 "register_operand" "=d")
6026         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
6027                      (match_operand:SI 2 "small_int" "IJK")))
6028    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6029   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && (INTVAL (operands[2]) & 32) != 0"
6030   "*
6031 {
6032   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6033   return \"sra\\t%L0,%M1,%2\;sra\\t%M0,%M1,31\";
6034 }"
6035   [(set_attr "type"     "darith")
6036    (set_attr "mode"     "DI")
6037    (set_attr "length"   "8")])
6038
6039
6040 (define_split
6041   [(set (match_operand:DI 0 "register_operand" "")
6042         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6043                      (match_operand:SI 2 "small_int" "")))
6044    (clobber (match_operand:SI 3 "register_operand" ""))]
6045   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6046    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE
6047    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6048    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6049    && (INTVAL (operands[2]) & 32) != 0"
6050
6051   [(set (subreg:SI (match_dup 0) 0) (ashiftrt:SI (subreg:SI (match_dup 1) 4) (match_dup 2)))
6052    (set (subreg:SI (match_dup 0) 4) (ashiftrt:SI (subreg:SI (match_dup 1) 4) (const_int 31)))]
6053
6054   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6055
6056
6057 (define_split
6058   [(set (match_operand:DI 0 "register_operand" "")
6059         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6060                      (match_operand:SI 2 "small_int" "")))
6061    (clobber (match_operand:SI 3 "register_operand" ""))]
6062   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6063    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE
6064    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6065    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6066    && (INTVAL (operands[2]) & 32) != 0"
6067
6068   [(set (subreg:SI (match_dup 0) 4) (ashiftrt:SI (subreg:SI (match_dup 1) 0) (match_dup 2)))
6069    (set (subreg:SI (match_dup 0) 0) (ashiftrt:SI (subreg:SI (match_dup 1) 0) (const_int 31)))]
6070
6071   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6072
6073
6074 (define_insn "ashrdi3_internal3"
6075   [(set (match_operand:DI 0 "register_operand" "=d")
6076         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
6077                      (match_operand:SI 2 "small_int" "IJK")))
6078    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6079   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6080    && (INTVAL (operands[2]) & 63) < 32
6081    && (INTVAL (operands[2]) & 63) != 0"
6082   "*
6083 {
6084   int amount = INTVAL (operands[2]);
6085
6086   operands[2] = GEN_INT (amount & 31);
6087   operands[4] = GEN_INT ((-amount) & 31);
6088
6089   return \"srl\\t%L0,%L1,%2\;sll\\t%3,%M1,%4\;or\\t%L0,%L0,%3\;sra\\t%M0,%M1,%2\";
6090 }"
6091   [(set_attr "type"     "darith")
6092    (set_attr "mode"     "DI")
6093    (set_attr "length"   "16")])
6094
6095
6096 (define_split
6097   [(set (match_operand:DI 0 "register_operand" "")
6098         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6099                      (match_operand:SI 2 "small_int" "")))
6100    (clobber (match_operand:SI 3 "register_operand" ""))]
6101   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6102    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6103    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6104    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6105    && (INTVAL (operands[2]) & 63) < 32
6106    && (INTVAL (operands[2]) & 63) != 0"
6107
6108   [(set (subreg:SI (match_dup 0) 0)
6109         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
6110                      (match_dup 2)))
6111
6112    (set (match_dup 3)
6113         (ashift:SI (subreg:SI (match_dup 1) 4)
6114                    (match_dup 4)))
6115
6116    (set (subreg:SI (match_dup 0) 0)
6117         (ior:SI (subreg:SI (match_dup 0) 0)
6118                 (match_dup 3)))
6119
6120    (set (subreg:SI (match_dup 0) 4)
6121         (ashiftrt:SI (subreg:SI (match_dup 1) 4)
6122                      (match_dup 2)))]
6123   "
6124 {
6125   int amount = INTVAL (operands[2]);
6126   operands[2] = GEN_INT (amount & 31);
6127   operands[4] = GEN_INT ((-amount) & 31);
6128 }")
6129
6130
6131 (define_split
6132   [(set (match_operand:DI 0 "register_operand" "")
6133         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6134                      (match_operand:SI 2 "small_int" "")))
6135    (clobber (match_operand:SI 3 "register_operand" ""))]
6136   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6137    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6138    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6139    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6140    && (INTVAL (operands[2]) & 63) < 32
6141    && (INTVAL (operands[2]) & 63) != 0"
6142
6143   [(set (subreg:SI (match_dup 0) 4)
6144         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
6145                      (match_dup 2)))
6146
6147    (set (match_dup 3)
6148         (ashift:SI (subreg:SI (match_dup 1) 0)
6149                    (match_dup 4)))
6150
6151    (set (subreg:SI (match_dup 0) 4)
6152         (ior:SI (subreg:SI (match_dup 0) 4)
6153                 (match_dup 3)))
6154
6155    (set (subreg:SI (match_dup 0) 0)
6156         (ashiftrt:SI (subreg:SI (match_dup 1) 0)
6157                      (match_dup 2)))]
6158   "
6159 {
6160   int amount = INTVAL (operands[2]);
6161   operands[2] = GEN_INT (amount & 31);
6162   operands[4] = GEN_INT ((-amount) & 31);
6163 }")
6164
6165
6166 (define_insn "ashrdi3_internal4"
6167   [(set (match_operand:DI 0 "register_operand" "=d")
6168         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
6169                      (match_operand:SI 2 "arith_operand" "dI")))]
6170   "TARGET_64BIT && !TARGET_MIPS16"
6171   "*
6172 {
6173   if (GET_CODE (operands[2]) == CONST_INT)
6174     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
6175
6176   return \"dsra\\t%0,%1,%2\";
6177 }"
6178   [(set_attr "type"     "arith")
6179    (set_attr "mode"     "DI")])
6180
6181 (define_insn ""
6182   [(set (match_operand:DI 0 "register_operand" "=d,d")
6183         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
6184                      (match_operand:SI 2 "arith_operand" "d,I")))]
6185   "TARGET_64BIT && TARGET_MIPS16"
6186   "*
6187 {
6188   if (GET_CODE (operands[2]) == CONST_INT)
6189     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
6190
6191   return \"dsra\\t%0,%2\";
6192 }"
6193   [(set_attr "type"     "arith")
6194    (set_attr "mode"     "DI")
6195    (set_attr_alternative "length"
6196                 [(const_int 4)
6197                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6198                                (const_int 4)
6199                                (const_int 8))])])
6200
6201 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
6202
6203 (define_split
6204   [(set (match_operand:DI 0 "register_operand" "")
6205         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6206                      (match_operand:SI 2 "const_int_operand" "")))]
6207   "TARGET_MIPS16 && TARGET_64BIT && !TARGET_DEBUG_D_MODE
6208    && reload_completed
6209    && GET_CODE (operands[2]) == CONST_INT
6210    && INTVAL (operands[2]) > 8
6211    && INTVAL (operands[2]) <= 16"
6212   [(set (match_dup 0) (ashiftrt:DI (match_dup 1) (const_int 8)))
6213    (set (match_dup 0) (ashiftrt:DI (match_dup 0) (match_dup 2)))]
6214 "
6215 {
6216   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
6217 }")
6218
6219 (define_expand "lshrsi3"
6220   [(set (match_operand:SI 0 "register_operand" "=d")
6221         (lshiftrt:SI (match_operand:SI 1 "register_operand" "d")
6222                      (match_operand:SI 2 "arith_operand" "dI")))]
6223   ""
6224   "
6225 {
6226   /* On the mips16, a shift of more than 8 is a four byte instruction,
6227      so, for a shift between 8 and 16, it is just as fast to do two
6228      shifts of 8 or less.  If there is a lot of shifting going on, we
6229      may win in CSE.  Otherwise combine will put the shifts back
6230      together again.  */
6231   if (TARGET_MIPS16
6232       && optimize
6233       && GET_CODE (operands[2]) == CONST_INT
6234       && INTVAL (operands[2]) > 8
6235       && INTVAL (operands[2]) <= 16)
6236     {
6237       rtx temp = gen_reg_rtx (SImode);
6238
6239       emit_insn (gen_lshrsi3_internal2 (temp, operands[1], GEN_INT (8)));
6240       emit_insn (gen_lshrsi3_internal2 (operands[0], temp,
6241                                         GEN_INT (INTVAL (operands[2]) - 8)));
6242       DONE;
6243     }
6244 }")
6245
6246 (define_insn "lshrsi3_internal1"
6247   [(set (match_operand:SI 0 "register_operand" "=d")
6248         (lshiftrt:SI (match_operand:SI 1 "register_operand" "d")
6249                      (match_operand:SI 2 "arith_operand" "dI")))]
6250   "!TARGET_MIPS16"
6251   "*
6252 {
6253   if (GET_CODE (operands[2]) == CONST_INT)
6254     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6255
6256   return \"srl\\t%0,%1,%2\";
6257 }"
6258   [(set_attr "type"     "arith")
6259    (set_attr "mode"     "SI")])
6260
6261 (define_insn "lshrsi3_internal2"
6262   [(set (match_operand:SI 0 "register_operand" "=d,d")
6263         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,d")
6264                      (match_operand:SI 2 "arith_operand" "d,I")))]
6265   "TARGET_MIPS16"
6266   "*
6267 {
6268   if (which_alternative == 0)
6269     return \"srl\\t%0,%2\";
6270
6271   if (GET_CODE (operands[2]) == CONST_INT)
6272     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6273
6274   return \"srl\\t%0,%1,%2\";
6275 }"
6276   [(set_attr "type"     "arith")
6277    (set_attr "mode"     "SI")
6278    (set_attr_alternative "length"
6279                 [(const_int 4)
6280                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6281                                (const_int 4)
6282                                (const_int 8))])])
6283
6284
6285 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
6286
6287 (define_split
6288   [(set (match_operand:SI 0 "register_operand" "")
6289         (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
6290                      (match_operand:SI 2 "const_int_operand" "")))]
6291   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
6292    && GET_CODE (operands[2]) == CONST_INT
6293    && INTVAL (operands[2]) > 8
6294    && INTVAL (operands[2]) <= 16"
6295   [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (const_int 8)))
6296    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
6297 "
6298 {
6299   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
6300 }")
6301
6302 ;; If we load a byte on the mips16 as a bitfield, the resulting
6303 ;; sequence of instructions is too complicated for combine, because it
6304 ;; involves four instructions: a load, a shift, a constant load into a
6305 ;; register, and an and (the key problem here is that the mips16 does
6306 ;; not have and immediate).  We recognize a shift of a load in order
6307 ;; to make it simple enough for combine to understand.
6308
6309 ;; ??? FIXME: turn into a define_insn_and_split
6310 (define_insn ""
6311   [(set (match_operand:SI 0 "register_operand" "=d")
6312         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
6313                      (match_operand:SI 2 "immediate_operand" "I")))]
6314   "0 && TARGET_MIPS16"
6315   "lw\\t%0,%1\;srl\\t%0,%2"
6316   [(set_attr "type"     "load")
6317    (set_attr "mode"     "SI")
6318    (set_attr_alternative "length"
6319                 [(if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6320                                (const_int 12)
6321                                (const_int 16))])])
6322
6323 (define_split
6324   [(set (match_operand:SI 0 "register_operand" "")
6325         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "")
6326                      (match_operand:SI 2 "immediate_operand" "")))]
6327   "TARGET_MIPS16 && !TARGET_DEBUG_D_MODE"
6328   [(set (match_dup 0) (match_dup 1))
6329    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
6330   "")
6331
6332 (define_expand "lshrdi3"
6333   [(parallel [(set (match_operand:DI 0 "register_operand" "")
6334                    (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
6335                                 (match_operand:SI 2 "arith_operand" "")))
6336               (clobber (match_dup  3))])]
6337   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
6338   "
6339 {
6340   if (TARGET_64BIT)
6341     {
6342       /* On the mips16, a shift of more than 8 is a four byte
6343          instruction, so, for a shift between 8 and 16, it is just as
6344          fast to do two shifts of 8 or less.  If there is a lot of
6345          shifting going on, we may win in CSE.  Otherwise combine will
6346          put the shifts back together again.  */
6347       if (TARGET_MIPS16
6348           && optimize
6349           && GET_CODE (operands[2]) == CONST_INT
6350           && INTVAL (operands[2]) > 8
6351           && INTVAL (operands[2]) <= 16)
6352         {
6353           rtx temp = gen_reg_rtx (DImode);
6354
6355           emit_insn (gen_lshrdi3_internal4 (temp, operands[1], GEN_INT (8)));
6356           emit_insn (gen_lshrdi3_internal4 (operands[0], temp,
6357                                             GEN_INT (INTVAL (operands[2]) - 8)));
6358           DONE;
6359         }
6360
6361       emit_insn (gen_lshrdi3_internal4 (operands[0], operands[1],
6362                                         operands[2]));
6363       DONE;
6364     }
6365
6366   operands[3] = gen_reg_rtx (SImode);
6367 }")
6368
6369
6370 (define_insn "lshrdi3_internal"
6371   [(set (match_operand:DI 0 "register_operand" "=&d")
6372         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
6373                      (match_operand:SI 2 "register_operand" "d")))
6374    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6375   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
6376   "*
6377 {
6378   operands[4] = const0_rtx;
6379
6380   return \"sll\\t%3,%2,26\\n\\
6381 \\tbgez\\t%3,1f%#\\n\\
6382 \\tsrl\\t%L0,%M1,%2\\n\\
6383 \\t%(b\\t3f\\n\\
6384 \\tmove\\t%M0,%z4%)\\n\\
6385 \\n\\
6386 %~1:\\n\\
6387 \\t%(beq\\t%3,%z4,2f\\n\\
6388 \\tsrl\\t%L0,%L1,%2%)\\n\\
6389 \\n\\
6390 \\tsubu\\t%3,%z4,%2\\n\\
6391 \\tsll\\t%3,%M1,%3\\n\\
6392 \\tor\\t%L0,%L0,%3\\n\\
6393 %~2:\\n\\
6394 \\tsrl\\t%M0,%M1,%2\\n\\
6395 %~3:\";
6396 }"
6397   [(set_attr "type"     "darith")
6398    (set_attr "mode"     "DI")
6399    (set_attr "length"   "48")])
6400
6401
6402 (define_insn "lshrdi3_internal2"
6403   [(set (match_operand:DI 0 "register_operand" "=d")
6404         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
6405                      (match_operand:SI 2 "small_int" "IJK")))
6406    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6407   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6408    && (INTVAL (operands[2]) & 32) != 0"
6409   "*
6410 {
6411   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6412   operands[4] = const0_rtx;
6413   return \"srl\\t%L0,%M1,%2\;move\\t%M0,%z4\";
6414 }"
6415   [(set_attr "type"     "darith")
6416    (set_attr "mode"     "DI")
6417    (set_attr "length"   "8")])
6418
6419
6420 (define_split
6421   [(set (match_operand:DI 0 "register_operand" "")
6422         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
6423                      (match_operand:SI 2 "small_int" "")))
6424    (clobber (match_operand:SI 3 "register_operand" ""))]
6425   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6426    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6427    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6428    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6429    && (INTVAL (operands[2]) & 32) != 0"
6430
6431   [(set (subreg:SI (match_dup 0) 0) (lshiftrt:SI (subreg:SI (match_dup 1) 4) (match_dup 2)))
6432    (set (subreg:SI (match_dup 0) 4) (const_int 0))]
6433
6434   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6435
6436
6437 (define_split
6438   [(set (match_operand:DI 0 "register_operand" "")
6439         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
6440                      (match_operand:SI 2 "small_int" "")))
6441    (clobber (match_operand:SI 3 "register_operand" ""))]
6442   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6443    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6444    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6445    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6446    && (INTVAL (operands[2]) & 32) != 0"
6447
6448   [(set (subreg:SI (match_dup 0) 4) (lshiftrt:SI (subreg:SI (match_dup 1) 0) (match_dup 2)))
6449    (set (subreg:SI (match_dup 0) 0) (const_int 0))]
6450
6451   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6452
6453
6454 (define_insn "lshrdi3_internal3"
6455   [(set (match_operand:DI 0 "register_operand" "=d")
6456         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
6457                    (match_operand:SI 2 "small_int" "IJK")))
6458    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6459   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6460    && (INTVAL (operands[2]) & 63) < 32
6461    && (INTVAL (operands[2]) & 63) != 0"
6462   "*
6463 {
6464   int amount = INTVAL (operands[2]);
6465
6466   operands[2] = GEN_INT (amount & 31);
6467   operands[4] = GEN_INT ((-amount) & 31);
6468
6469   return \"srl\\t%L0,%L1,%2\;sll\\t%3,%M1,%4\;or\\t%L0,%L0,%3\;srl\\t%M0,%M1,%2\";
6470 }"
6471   [(set_attr "type"     "darith")
6472    (set_attr "mode"     "DI")
6473    (set_attr "length"   "16")])
6474
6475
6476 (define_split
6477   [(set (match_operand:DI 0 "register_operand" "")
6478         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
6479                      (match_operand:SI 2 "small_int" "")))
6480    (clobber (match_operand:SI 3 "register_operand" ""))]
6481   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6482    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6483    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6484    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6485    && (INTVAL (operands[2]) & 63) < 32
6486    && (INTVAL (operands[2]) & 63) != 0"
6487
6488   [(set (subreg:SI (match_dup 0) 0)
6489         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
6490                      (match_dup 2)))
6491
6492    (set (match_dup 3)
6493         (ashift:SI (subreg:SI (match_dup 1) 4)
6494                    (match_dup 4)))
6495
6496    (set (subreg:SI (match_dup 0) 0)
6497         (ior:SI (subreg:SI (match_dup 0) 0)
6498                 (match_dup 3)))
6499
6500    (set (subreg:SI (match_dup 0) 4)
6501         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
6502                      (match_dup 2)))]
6503   "
6504 {
6505   int amount = INTVAL (operands[2]);
6506   operands[2] = GEN_INT (amount & 31);
6507   operands[4] = GEN_INT ((-amount) & 31);
6508 }")
6509
6510
6511 (define_split
6512   [(set (match_operand:DI 0 "register_operand" "")
6513         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
6514                      (match_operand:SI 2 "small_int" "")))
6515    (clobber (match_operand:SI 3 "register_operand" ""))]
6516   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6517    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6518    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6519    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6520    && (INTVAL (operands[2]) & 63) < 32
6521    && (INTVAL (operands[2]) & 63) != 0"
6522
6523   [(set (subreg:SI (match_dup 0) 4)
6524         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
6525                      (match_dup 2)))
6526
6527    (set (match_dup 3)
6528         (ashift:SI (subreg:SI (match_dup 1) 0)
6529                    (match_dup 4)))
6530
6531    (set (subreg:SI (match_dup 0) 4)
6532         (ior:SI (subreg:SI (match_dup 0) 4)
6533                 (match_dup 3)))
6534
6535    (set (subreg:SI (match_dup 0) 0)
6536         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
6537                      (match_dup 2)))]
6538   "
6539 {
6540   int amount = INTVAL (operands[2]);
6541   operands[2] = GEN_INT (amount & 31);
6542   operands[4] = GEN_INT ((-amount) & 31);
6543 }")
6544
6545
6546 (define_insn "lshrdi3_internal4"
6547   [(set (match_operand:DI 0 "register_operand" "=d")
6548         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
6549                      (match_operand:SI 2 "arith_operand" "dI")))]
6550   "TARGET_64BIT && !TARGET_MIPS16"
6551   "*
6552 {
6553   if (GET_CODE (operands[2]) == CONST_INT)
6554     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
6555
6556   return \"dsrl\\t%0,%1,%2\";
6557 }"
6558   [(set_attr "type"     "arith")
6559    (set_attr "mode"     "DI")])
6560
6561 (define_insn ""
6562   [(set (match_operand:DI 0 "register_operand" "=d,d")
6563         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
6564                      (match_operand:SI 2 "arith_operand" "d,I")))]
6565   "TARGET_64BIT && TARGET_MIPS16"
6566   "*
6567 {
6568   if (GET_CODE (operands[2]) == CONST_INT)
6569     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
6570
6571   return \"dsrl\\t%0,%2\";
6572 }"
6573   [(set_attr "type"     "arith")
6574    (set_attr "mode"     "DI")
6575    (set_attr_alternative "length"
6576                 [(const_int 4)
6577                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6578                                (const_int 4)
6579                                (const_int 8))])])
6580
6581 (define_insn "rotrsi3"
6582   [(set (match_operand:SI              0 "register_operand" "=d")
6583         (rotatert:SI (match_operand:SI 1 "register_operand" "d")
6584                      (match_operand:SI 2 "arith_operand"    "dn")))]
6585   "ISA_HAS_ROTR_SI"
6586   "*
6587 {
6588   if (TARGET_SR71K && GET_CODE (operands[2]) != CONST_INT)
6589     return \"rorv\\t%0,%1,%2\";
6590
6591   if ((GET_CODE (operands[2]) == CONST_INT)
6592       && (INTVAL (operands[2]) < 0 || INTVAL (operands[2]) >= 32))
6593     abort ();
6594
6595   return \"ror\\t%0,%1,%2\";
6596 }"
6597   [(set_attr "type"     "arith")
6598    (set_attr "mode"     "SI")])
6599
6600 (define_insn "rotrdi3"
6601   [(set (match_operand:DI              0 "register_operand" "=d")
6602         (rotatert:DI (match_operand:DI 1 "register_operand" "d")
6603                      (match_operand:DI 2 "arith_operand"    "dn")))]
6604   "ISA_HAS_ROTR_DI"
6605   "*
6606 {
6607    if (TARGET_SR71K)
6608     {
6609       if (GET_CODE (operands[2]) != CONST_INT)
6610         return \"drorv\\t%0,%1,%2\";
6611
6612       if (INTVAL (operands[2]) >= 32 && INTVAL (operands[2]) <= 63)
6613         return \"dror32\\t%0,%1,%2\";
6614     }
6615
6616   if ((GET_CODE (operands[2]) == CONST_INT)
6617       && (INTVAL (operands[2]) < 0 || INTVAL (operands[2]) >= 64))
6618     abort ();
6619
6620   return \"dror\\t%0,%1,%2\";
6621 }"
6622   [(set_attr "type"     "arith")
6623    (set_attr "mode"     "DI")])
6624
6625
6626 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
6627
6628 (define_split
6629   [(set (match_operand:DI 0 "register_operand" "")
6630         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
6631                      (match_operand:SI 2 "const_int_operand" "")))]
6632   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
6633    && GET_CODE (operands[2]) == CONST_INT
6634    && INTVAL (operands[2]) > 8
6635    && INTVAL (operands[2]) <= 16"
6636   [(set (match_dup 0) (lshiftrt:DI (match_dup 1) (const_int 8)))
6637    (set (match_dup 0) (lshiftrt:DI (match_dup 0) (match_dup 2)))]
6638 "
6639 {
6640   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
6641 }")
6642
6643 \f
6644 ;;
6645 ;;  ....................
6646 ;;
6647 ;;      COMPARISONS
6648 ;;
6649 ;;  ....................
6650
6651 ;; Flow here is rather complex:
6652 ;;
6653 ;;  1)  The cmp{si,di,sf,df} routine is called.  It deposits the
6654 ;;      arguments into the branch_cmp array, and the type into
6655 ;;      branch_type.  No RTL is generated.
6656 ;;
6657 ;;  2)  The appropriate branch define_expand is called, which then
6658 ;;      creates the appropriate RTL for the comparison and branch.
6659 ;;      Different CC modes are used, based on what type of branch is
6660 ;;      done, so that we can constrain things appropriately.  There
6661 ;;      are assumptions in the rest of GCC that break if we fold the
6662 ;;      operands into the branchs for integer operations, and use cc0
6663 ;;      for floating point, so we use the fp status register instead.
6664 ;;      If needed, an appropriate temporary is created to hold the
6665 ;;      of the integer compare.
6666
6667 (define_expand "cmpsi"
6668   [(set (cc0)
6669         (compare:CC (match_operand:SI 0 "register_operand" "")
6670                     (match_operand:SI 1 "arith_operand" "")))]
6671   ""
6672   "
6673 {
6674   if (operands[0])              /* avoid unused code message */
6675     {
6676       branch_cmp[0] = operands[0];
6677       branch_cmp[1] = operands[1];
6678       branch_type = CMP_SI;
6679       DONE;
6680     }
6681 }")
6682
6683 (define_expand "tstsi"
6684   [(set (cc0)
6685         (match_operand:SI 0 "register_operand" ""))]
6686   ""
6687   "
6688 {
6689   if (operands[0])              /* avoid unused code message */
6690     {
6691       branch_cmp[0] = operands[0];
6692       branch_cmp[1] = const0_rtx;
6693       branch_type = CMP_SI;
6694       DONE;
6695     }
6696 }")
6697
6698 (define_expand "cmpdi"
6699   [(set (cc0)
6700         (compare:CC (match_operand:DI 0 "register_operand" "")
6701                     (match_operand:DI 1 "arith_operand" "")))]
6702   "TARGET_64BIT"
6703   "
6704 {
6705   if (operands[0])              /* avoid unused code message */
6706     {
6707       branch_cmp[0] = operands[0];
6708       branch_cmp[1] = operands[1];
6709       branch_type = CMP_DI;
6710       DONE;
6711     }
6712 }")
6713
6714 (define_expand "tstdi"
6715   [(set (cc0)
6716         (match_operand:DI 0 "register_operand" ""))]
6717   "TARGET_64BIT"
6718   "
6719 {
6720   if (operands[0])              /* avoid unused code message */
6721     {
6722       branch_cmp[0] = operands[0];
6723       branch_cmp[1] = const0_rtx;
6724       branch_type = CMP_DI;
6725       DONE;
6726     }
6727 }")
6728
6729 (define_expand "cmpdf"
6730   [(set (cc0)
6731         (compare:CC (match_operand:DF 0 "register_operand" "")
6732                     (match_operand:DF 1 "register_operand" "")))]
6733   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
6734   "
6735 {
6736   if (operands[0])              /* avoid unused code message */
6737     {
6738       branch_cmp[0] = operands[0];
6739       branch_cmp[1] = operands[1];
6740       branch_type = CMP_DF;
6741       DONE;
6742     }
6743 }")
6744
6745 (define_expand "cmpsf"
6746   [(set (cc0)
6747         (compare:CC (match_operand:SF 0 "register_operand" "")
6748                     (match_operand:SF 1 "register_operand" "")))]
6749   "TARGET_HARD_FLOAT"
6750   "
6751 {
6752   if (operands[0])              /* avoid unused code message */
6753     {
6754       branch_cmp[0] = operands[0];
6755       branch_cmp[1] = operands[1];
6756       branch_type = CMP_SF;
6757       DONE;
6758     }
6759 }")
6760
6761 \f
6762 ;;
6763 ;;  ....................
6764 ;;
6765 ;;      CONDITIONAL BRANCHES
6766 ;;
6767 ;;  ....................
6768
6769 ;; Conditional branches on floating-point equality tests.
6770
6771 (define_insn "branch_fp"
6772   [(set (pc)
6773         (if_then_else
6774          (match_operator:CC 0 "cmp_op"
6775                             [(match_operand:CC 2 "register_operand" "z")
6776                              (const_int 0)])
6777          (label_ref (match_operand 1 "" ""))
6778          (pc)))]
6779   "TARGET_HARD_FLOAT"
6780   "*
6781 {
6782   return mips_output_conditional_branch (insn,
6783                                          operands,
6784                                          /*two_operands_p=*/0,
6785                                          /*float_p=*/1,
6786                                          /*inverted_p=*/0,
6787                                          get_attr_length (insn));
6788 }"
6789   [(set_attr "type"     "branch")
6790    (set_attr "mode"     "none")])
6791
6792 (define_insn "branch_fp_inverted"
6793   [(set (pc)
6794         (if_then_else
6795          (match_operator:CC 0 "cmp_op"
6796                             [(match_operand:CC 2 "register_operand" "z")
6797                              (const_int 0)])
6798          (pc)
6799          (label_ref (match_operand 1 "" ""))))]
6800   "TARGET_HARD_FLOAT"
6801   "*
6802 {
6803   return mips_output_conditional_branch (insn,
6804                                          operands,
6805                                          /*two_operands_p=*/0,
6806                                          /*float_p=*/1,
6807                                          /*inverted_p=*/1,
6808                                          get_attr_length (insn));
6809 }"
6810   [(set_attr "type"     "branch")
6811    (set_attr "mode"     "none")])
6812
6813 ;; Conditional branches on comparisons with zero.
6814
6815 (define_insn "branch_zero"
6816   [(set (pc)
6817         (if_then_else
6818          (match_operator:SI 0 "cmp_op"
6819                             [(match_operand:SI 2 "register_operand" "d")
6820                              (const_int 0)])
6821         (label_ref (match_operand 1 "" ""))
6822         (pc)))]
6823   "!TARGET_MIPS16"
6824   "*
6825 {
6826   return mips_output_conditional_branch (insn,
6827                                          operands,
6828                                          /*two_operands_p=*/0,
6829                                          /*float_p=*/0,
6830                                          /*inverted_p=*/0,
6831                                          get_attr_length (insn));
6832 }"
6833   [(set_attr "type"     "branch")
6834    (set_attr "mode"     "none")])
6835
6836 (define_insn "branch_zero_inverted"
6837   [(set (pc)
6838         (if_then_else
6839          (match_operator:SI 0 "cmp_op"
6840                             [(match_operand:SI 2 "register_operand" "d")
6841                              (const_int 0)])
6842         (pc)
6843         (label_ref (match_operand 1 "" ""))))]
6844   "!TARGET_MIPS16"
6845   "*
6846 {
6847   return mips_output_conditional_branch (insn,
6848                                          operands,
6849                                          /*two_operands_p=*/0,
6850                                          /*float_p=*/0,
6851                                          /*inverted_p=*/1,
6852                                          get_attr_length (insn));
6853 }"
6854   [(set_attr "type"     "branch")
6855    (set_attr "mode"     "none")])
6856
6857 (define_insn "branch_zero_di"
6858   [(set (pc)
6859         (if_then_else
6860          (match_operator:DI 0 "cmp_op"
6861                             [(match_operand:DI 2 "register_operand" "d")
6862                              (const_int 0)])
6863         (label_ref (match_operand 1 "" ""))
6864         (pc)))]
6865   "!TARGET_MIPS16"
6866   "*
6867 {
6868   return mips_output_conditional_branch (insn,
6869                                          operands,
6870                                          /*two_operands_p=*/0,
6871                                          /*float_p=*/0,
6872                                          /*inverted_p=*/0,
6873                                          get_attr_length (insn));
6874 }"
6875   [(set_attr "type"     "branch")
6876    (set_attr "mode"     "none")])
6877
6878 (define_insn "branch_zero_di_inverted"
6879   [(set (pc)
6880         (if_then_else
6881          (match_operator:DI 0 "cmp_op"
6882                             [(match_operand:DI 2 "register_operand" "d")
6883                              (const_int 0)])
6884         (pc)
6885         (label_ref (match_operand 1 "" ""))))]
6886   "!TARGET_MIPS16"
6887   "*
6888 {
6889   return mips_output_conditional_branch (insn,
6890                                          operands,
6891                                          /*two_operands_p=*/0,
6892                                          /*float_p=*/0,
6893                                          /*inverted_p=*/1,
6894                                          get_attr_length (insn));
6895 }"
6896   [(set_attr "type"     "branch")
6897    (set_attr "mode"     "none")])
6898
6899 ;; Conditional branch on equality comparison.
6900
6901 (define_insn "branch_equality"
6902   [(set (pc)
6903         (if_then_else
6904          (match_operator:SI 0 "equality_op"
6905                             [(match_operand:SI 2 "register_operand" "d")
6906                              (match_operand:SI 3 "register_operand" "d")])
6907          (label_ref (match_operand 1 "" ""))
6908          (pc)))]
6909   "!TARGET_MIPS16"
6910   "*
6911 {
6912   return mips_output_conditional_branch (insn,
6913                                          operands,
6914                                          /*two_operands_p=*/1,
6915                                          /*float_p=*/0,
6916                                          /*inverted_p=*/0,
6917                                          get_attr_length (insn));
6918 }"
6919   [(set_attr "type"     "branch")
6920    (set_attr "mode"     "none")])
6921
6922 (define_insn "branch_equality_di"
6923   [(set (pc)
6924         (if_then_else
6925          (match_operator:DI 0 "equality_op"
6926                             [(match_operand:DI 2 "register_operand" "d")
6927                              (match_operand:DI 3 "register_operand" "d")])
6928         (label_ref (match_operand 1 "" ""))
6929         (pc)))]
6930   "!TARGET_MIPS16"
6931   "*
6932 {
6933   return mips_output_conditional_branch (insn,
6934                                          operands,
6935                                          /*two_operands_p=*/1,
6936                                          /*float_p=*/0,
6937                                          /*inverted_p=*/0,
6938                                          get_attr_length (insn));
6939 }"
6940   [(set_attr "type"     "branch")
6941    (set_attr "mode"     "none")])
6942
6943 (define_insn "branch_equality_inverted"
6944   [(set (pc)
6945         (if_then_else
6946          (match_operator:SI 0 "equality_op"
6947                             [(match_operand:SI 2 "register_operand" "d")
6948                              (match_operand:SI 3 "register_operand" "d")])
6949          (pc)
6950          (label_ref (match_operand 1 "" ""))))]
6951   "!TARGET_MIPS16"
6952   "*
6953 {
6954   return mips_output_conditional_branch (insn,
6955                                          operands,
6956                                          /*two_operands_p=*/1,
6957                                          /*float_p=*/0,
6958                                          /*inverted_p=*/1,
6959                                          get_attr_length (insn));
6960 }"
6961   [(set_attr "type"     "branch")
6962    (set_attr "mode"     "none")])
6963
6964 (define_insn "branch_equality_di_inverted"
6965   [(set (pc)
6966         (if_then_else
6967          (match_operator:DI 0 "equality_op"
6968                             [(match_operand:DI 2 "register_operand" "d")
6969                              (match_operand:DI 3 "register_operand" "d")])
6970         (pc)
6971         (label_ref (match_operand 1 "" ""))))]
6972   "!TARGET_MIPS16"
6973   "*
6974 {
6975   return mips_output_conditional_branch (insn,
6976                                          operands,
6977                                          /*two_operands_p=*/1,
6978                                          /*float_p=*/0,
6979                                          /*inverted_p=*/1,
6980                                          get_attr_length (insn));
6981 }"
6982   [(set_attr "type"     "branch")
6983    (set_attr "mode"     "none")])
6984
6985 ;; MIPS16 branches
6986
6987 (define_insn ""
6988   [(set (pc)
6989         (if_then_else (match_operator:SI 0 "equality_op"
6990                                          [(match_operand:SI 1 "register_operand" "d,t")
6991                                           (const_int 0)])
6992         (match_operand 2 "pc_or_label_operand" "")
6993         (match_operand 3 "pc_or_label_operand" "")))]
6994   "TARGET_MIPS16"
6995   "*
6996 {
6997   if (operands[2] != pc_rtx)
6998     {
6999       if (which_alternative == 0)
7000         return \"b%C0z\\t%1,%2\";
7001       else
7002         return \"bt%C0z\\t%2\";
7003     }
7004   else
7005     {
7006       if (which_alternative == 0)
7007         return \"b%N0z\\t%1,%3\";
7008       else
7009         return \"bt%N0z\\t%3\";
7010     }
7011 }"
7012   [(set_attr "type"     "branch")
7013    (set_attr "mode"     "none")
7014    (set_attr "length"   "8")])
7015
7016 (define_insn ""
7017   [(set (pc)
7018         (if_then_else (match_operator:DI 0 "equality_op"
7019                                          [(match_operand:DI 1 "register_operand" "d,t")
7020                                           (const_int 0)])
7021         (match_operand 2 "pc_or_label_operand" "")
7022         (match_operand 3 "pc_or_label_operand" "")))]
7023   "TARGET_MIPS16"
7024   "*
7025 {
7026   if (operands[2] != pc_rtx)
7027     {
7028       if (which_alternative == 0)
7029         return \"b%C0z\\t%1,%2\";
7030       else
7031         return \"bt%C0z\\t%2\";
7032     }
7033   else
7034     {
7035       if (which_alternative == 0)
7036         return \"b%N0z\\t%1,%3\";
7037       else
7038         return \"bt%N0z\\t%3\";
7039     }
7040 }"
7041   [(set_attr "type"     "branch")
7042    (set_attr "mode"     "none")
7043    (set_attr "length"   "8")])
7044
7045 (define_expand "bunordered"
7046   [(set (pc)
7047         (if_then_else (unordered:CC (cc0)
7048                                     (const_int 0))
7049                       (label_ref (match_operand 0 "" ""))
7050                       (pc)))]
7051   ""
7052   "
7053 {
7054   if (operands[0])              /* avoid unused code warning */
7055     {
7056       gen_conditional_branch (operands, UNORDERED);
7057       DONE;
7058     }
7059 }")
7060
7061 (define_expand "bordered"
7062   [(set (pc)
7063         (if_then_else (ordered:CC (cc0)
7064                                   (const_int 0))
7065                       (label_ref (match_operand 0 "" ""))
7066                       (pc)))]
7067   ""
7068   "
7069 {
7070   if (operands[0])              /* avoid unused code warning */
7071      {
7072         gen_conditional_branch (operands, ORDERED);
7073         DONE;
7074      }
7075 }")
7076
7077 (define_expand "bunlt"
7078   [(set (pc)
7079         (if_then_else (unlt:CC (cc0)
7080                                (const_int 0))
7081                       (label_ref (match_operand 0 "" ""))
7082                       (pc)))]
7083   ""
7084   "
7085 {
7086   if (operands[0])              /* avoid unused code warning */
7087      {
7088         gen_conditional_branch (operands, UNLT);
7089         DONE;
7090      }
7091 }")
7092
7093 (define_expand "bunge"
7094   [(set (pc)
7095         (if_then_else (unge:CC (cc0)
7096                                (const_int 0))
7097                       (label_ref (match_operand 0 "" ""))
7098                       (pc)))]
7099   ""
7100   "
7101 {
7102   gen_conditional_branch (operands, UNGE);
7103   DONE;
7104 }")
7105
7106 (define_expand "buneq"
7107   [(set (pc)
7108         (if_then_else (uneq:CC (cc0)
7109                                (const_int 0))
7110                       (label_ref (match_operand 0 "" ""))
7111                       (pc)))]
7112   ""
7113   "
7114 {
7115   if (operands[0])              /* avoid unused code warning */
7116      {
7117         gen_conditional_branch (operands, UNEQ);
7118         DONE;
7119      }
7120 }")
7121
7122 (define_expand "bltgt"
7123   [(set (pc)
7124         (if_then_else (ltgt:CC (cc0)
7125                                (const_int 0))
7126                       (label_ref (match_operand 0 "" ""))
7127                       (pc)))]
7128   ""
7129   "
7130 {
7131   gen_conditional_branch (operands, LTGT);
7132   DONE;
7133 }")
7134
7135 (define_expand "bunle"
7136   [(set (pc)
7137         (if_then_else (unle:CC (cc0)
7138                                (const_int 0))
7139                       (label_ref (match_operand 0 "" ""))
7140                       (pc)))]
7141   ""
7142   "
7143 {
7144   if (operands[0])              /* avoid unused code warning */
7145      {
7146         gen_conditional_branch (operands, UNLE);
7147         DONE;
7148      }
7149 }")
7150
7151 (define_expand "bungt"
7152   [(set (pc)
7153         (if_then_else (ungt:CC (cc0)
7154                                (const_int 0))
7155                       (label_ref (match_operand 0 "" ""))
7156                       (pc)))]
7157   ""
7158   "
7159 {
7160   gen_conditional_branch (operands, UNGT);
7161   DONE;
7162 }")
7163
7164 (define_expand "beq"
7165   [(set (pc)
7166         (if_then_else (eq:CC (cc0)
7167                              (const_int 0))
7168                       (label_ref (match_operand 0 "" ""))
7169                       (pc)))]
7170   ""
7171   "
7172 {
7173   if (operands[0])              /* avoid unused code warning */
7174     {
7175       gen_conditional_branch (operands, EQ);
7176       DONE;
7177     }
7178 }")
7179
7180 (define_expand "bne"
7181   [(set (pc)
7182         (if_then_else (ne:CC (cc0)
7183                              (const_int 0))
7184                       (label_ref (match_operand 0 "" ""))
7185                       (pc)))]
7186   ""
7187   "
7188 {
7189   if (operands[0])              /* avoid unused code warning */
7190     {
7191       gen_conditional_branch (operands, NE);
7192       DONE;
7193     }
7194 }")
7195
7196 (define_expand "bgt"
7197   [(set (pc)
7198         (if_then_else (gt:CC (cc0)
7199                              (const_int 0))
7200                       (label_ref (match_operand 0 "" ""))
7201                       (pc)))]
7202   ""
7203   "
7204 {
7205   if (operands[0])              /* avoid unused code warning */
7206     {
7207       gen_conditional_branch (operands, GT);
7208       DONE;
7209     }
7210 }")
7211
7212 (define_expand "bge"
7213   [(set (pc)
7214         (if_then_else (ge:CC (cc0)
7215                              (const_int 0))
7216                       (label_ref (match_operand 0 "" ""))
7217                       (pc)))]
7218   ""
7219   "
7220 {
7221   if (operands[0])              /* avoid unused code warning */
7222     {
7223       gen_conditional_branch (operands, GE);
7224       DONE;
7225     }
7226 }")
7227
7228 (define_expand "blt"
7229   [(set (pc)
7230         (if_then_else (lt:CC (cc0)
7231                              (const_int 0))
7232                       (label_ref (match_operand 0 "" ""))
7233                       (pc)))]
7234   ""
7235   "
7236 {
7237   if (operands[0])              /* avoid unused code warning */
7238     {
7239       gen_conditional_branch (operands, LT);
7240       DONE;
7241     }
7242 }")
7243
7244 (define_expand "ble"
7245   [(set (pc)
7246         (if_then_else (le:CC (cc0)
7247                              (const_int 0))
7248                       (label_ref (match_operand 0 "" ""))
7249                       (pc)))]
7250   ""
7251   "
7252 {
7253   if (operands[0])              /* avoid unused code warning */
7254     {
7255       gen_conditional_branch (operands, LE);
7256       DONE;
7257     }
7258 }")
7259
7260 (define_expand "bgtu"
7261   [(set (pc)
7262         (if_then_else (gtu:CC (cc0)
7263                               (const_int 0))
7264                       (label_ref (match_operand 0 "" ""))
7265                       (pc)))]
7266   ""
7267   "
7268 {
7269   if (operands[0])              /* avoid unused code warning */
7270     {
7271       gen_conditional_branch (operands, GTU);
7272       DONE;
7273     }
7274 }")
7275
7276 (define_expand "bgeu"
7277   [(set (pc)
7278         (if_then_else (geu:CC (cc0)
7279                               (const_int 0))
7280                       (label_ref (match_operand 0 "" ""))
7281                       (pc)))]
7282   ""
7283   "
7284 {
7285   if (operands[0])              /* avoid unused code warning */
7286     {
7287       gen_conditional_branch (operands, GEU);
7288       DONE;
7289     }
7290 }")
7291
7292
7293 (define_expand "bltu"
7294   [(set (pc)
7295         (if_then_else (ltu:CC (cc0)
7296                               (const_int 0))
7297                       (label_ref (match_operand 0 "" ""))
7298                       (pc)))]
7299   ""
7300   "
7301 {
7302   if (operands[0])              /* avoid unused code warning */
7303     {
7304       gen_conditional_branch (operands, LTU);
7305       DONE;
7306     }
7307 }")
7308
7309 (define_expand "bleu"
7310   [(set (pc)
7311         (if_then_else (leu:CC (cc0)
7312                               (const_int 0))
7313                       (label_ref (match_operand 0 "" ""))
7314                       (pc)))]
7315   ""
7316   "
7317 {
7318   if (operands[0])              /* avoid unused code warning */
7319     {
7320       gen_conditional_branch (operands, LEU);
7321       DONE;
7322     }
7323 }")
7324
7325 \f
7326 ;;
7327 ;;  ....................
7328 ;;
7329 ;;      SETTING A REGISTER FROM A COMPARISON
7330 ;;
7331 ;;  ....................
7332
7333 (define_expand "seq"
7334   [(set (match_operand:SI 0 "register_operand" "=d")
7335         (eq:SI (match_dup 1)
7336                (match_dup 2)))]
7337   ""
7338   "
7339 {
7340   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7341     FAIL;
7342
7343   /* set up operands from compare.  */
7344   operands[1] = branch_cmp[0];
7345   operands[2] = branch_cmp[1];
7346
7347   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7348     {
7349       gen_int_relational (EQ, operands[0], operands[1], operands[2], (int *)0);
7350       DONE;
7351     }
7352
7353   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
7354     operands[2] = force_reg (SImode, operands[2]);
7355
7356   /* fall through and generate default code */
7357 }")
7358
7359
7360 (define_insn "seq_si_zero"
7361   [(set (match_operand:SI 0 "register_operand" "=d")
7362         (eq:SI (match_operand:SI 1 "register_operand" "d")
7363                (const_int 0)))]
7364   "!TARGET_MIPS16"
7365   "sltu\\t%0,%1,1"
7366   [(set_attr "type"     "arith")
7367    (set_attr "mode"     "SI")])
7368
7369 (define_insn ""
7370   [(set (match_operand:SI 0 "register_operand" "=t")
7371         (eq:SI (match_operand:SI 1 "register_operand" "d")
7372                (const_int 0)))]
7373   "TARGET_MIPS16"
7374   "sltu\\t%1,1"
7375   [(set_attr "type"     "arith")
7376    (set_attr "mode"     "SI")])
7377
7378 (define_insn "seq_di_zero"
7379   [(set (match_operand:DI 0 "register_operand" "=d")
7380         (eq:DI (match_operand:DI 1 "register_operand" "d")
7381                (const_int 0)))]
7382   "TARGET_64BIT && !TARGET_MIPS16"
7383   "sltu\\t%0,%1,1"
7384   [(set_attr "type"     "arith")
7385    (set_attr "mode"     "DI")])
7386
7387 (define_insn ""
7388   [(set (match_operand:DI 0 "register_operand" "=t")
7389         (eq:DI (match_operand:DI 1 "register_operand" "d")
7390                (const_int 0)))]
7391   "TARGET_64BIT && TARGET_MIPS16"
7392   "sltu\\t%1,1"
7393   [(set_attr "type"     "arith")
7394    (set_attr "mode"     "DI")])
7395
7396 (define_insn "seq_si"
7397   [(set (match_operand:SI 0 "register_operand" "=d,d")
7398         (eq:SI (match_operand:SI 1 "register_operand" "%d,d")
7399                (match_operand:SI 2 "uns_arith_operand" "d,K")))]
7400   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7401   "@
7402    xor\\t%0,%1,%2\;sltu\\t%0,%0,1
7403    xori\\t%0,%1,%2\;sltu\\t%0,%0,1"
7404   [(set_attr "type"     "arith")
7405    (set_attr "mode"     "SI")
7406    (set_attr "length"   "8")])
7407
7408 (define_split
7409   [(set (match_operand:SI 0 "register_operand" "")
7410         (eq:SI (match_operand:SI 1 "register_operand" "")
7411                (match_operand:SI 2 "uns_arith_operand" "")))]
7412   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16
7413     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
7414   [(set (match_dup 0)
7415         (xor:SI (match_dup 1)
7416                 (match_dup 2)))
7417    (set (match_dup 0)
7418         (ltu:SI (match_dup 0)
7419                 (const_int 1)))]
7420   "")
7421
7422 (define_insn "seq_di"
7423   [(set (match_operand:DI 0 "register_operand" "=d,d")
7424         (eq:DI (match_operand:DI 1 "register_operand" "%d,d")
7425                (match_operand:DI 2 "uns_arith_operand" "d,K")))]
7426   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7427   "@
7428    xor\\t%0,%1,%2\;sltu\\t%0,%0,1
7429    xori\\t%0,%1,%2\;sltu\\t%0,%0,1"
7430   [(set_attr "type"     "arith")
7431    (set_attr "mode"     "DI")
7432    (set_attr "length"   "8")])
7433
7434 (define_split
7435   [(set (match_operand:DI 0 "register_operand" "")
7436         (eq:DI (match_operand:DI 1 "register_operand" "")
7437                (match_operand:DI 2 "uns_arith_operand" "")))]
7438   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
7439     && !TARGET_MIPS16
7440     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
7441   [(set (match_dup 0)
7442         (xor:DI (match_dup 1)
7443                 (match_dup 2)))
7444    (set (match_dup 0)
7445         (ltu:DI (match_dup 0)
7446                 (const_int 1)))]
7447   "")
7448
7449 ;; On the mips16 the default code is better than using sltu.
7450
7451 (define_expand "sne"
7452   [(set (match_operand:SI 0 "register_operand" "=d")
7453         (ne:SI (match_dup 1)
7454                (match_dup 2)))]
7455   "!TARGET_MIPS16"
7456   "
7457 {
7458   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7459     FAIL;
7460
7461   /* set up operands from compare.  */
7462   operands[1] = branch_cmp[0];
7463   operands[2] = branch_cmp[1];
7464
7465   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE)
7466     {
7467       gen_int_relational (NE, operands[0], operands[1], operands[2], (int *)0);
7468       DONE;
7469     }
7470
7471   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
7472     operands[2] = force_reg (SImode, operands[2]);
7473
7474   /* fall through and generate default code */
7475 }")
7476
7477 (define_insn "sne_si_zero"
7478   [(set (match_operand:SI 0 "register_operand" "=d")
7479         (ne:SI (match_operand:SI 1 "register_operand" "d")
7480                (const_int 0)))]
7481   "!TARGET_MIPS16"
7482   "sltu\\t%0,%.,%1"
7483   [(set_attr "type"     "arith")
7484    (set_attr "mode"     "SI")])
7485
7486 (define_insn "sne_di_zero"
7487   [(set (match_operand:DI 0 "register_operand" "=d")
7488         (ne:DI (match_operand:DI 1 "register_operand" "d")
7489                (const_int 0)))]
7490   "TARGET_64BIT && !TARGET_MIPS16"
7491   "sltu\\t%0,%.,%1"
7492   [(set_attr "type"     "arith")
7493    (set_attr "mode"     "DI")])
7494
7495 (define_insn "sne_si"
7496   [(set (match_operand:SI 0 "register_operand" "=d,d")
7497         (ne:SI (match_operand:SI 1 "register_operand" "%d,d")
7498                (match_operand:SI 2 "uns_arith_operand" "d,K")))]
7499   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7500   "@
7501     xor\\t%0,%1,%2\;sltu\\t%0,%.,%0
7502     xori\\t%0,%1,%x2\;sltu\\t%0,%.,%0"
7503   [(set_attr "type"     "arith")
7504    (set_attr "mode"     "SI")
7505    (set_attr "length"   "8")])
7506
7507 (define_split
7508   [(set (match_operand:SI 0 "register_operand" "")
7509         (ne:SI (match_operand:SI 1 "register_operand" "")
7510                (match_operand:SI 2 "uns_arith_operand" "")))]
7511   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16
7512     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
7513   [(set (match_dup 0)
7514         (xor:SI (match_dup 1)
7515                 (match_dup 2)))
7516    (set (match_dup 0)
7517         (gtu:SI (match_dup 0)
7518                 (const_int 0)))]
7519   "")
7520
7521 (define_insn "sne_di"
7522   [(set (match_operand:DI 0 "register_operand" "=d,d")
7523         (ne:DI (match_operand:DI 1 "register_operand" "%d,d")
7524                (match_operand:DI 2 "uns_arith_operand" "d,K")))]
7525   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7526   "@
7527     xor\\t%0,%1,%2\;sltu\\t%0,%.,%0
7528     xori\\t%0,%1,%x2\;sltu\\t%0,%.,%0"
7529   [(set_attr "type"     "arith")
7530    (set_attr "mode"     "DI")
7531    (set_attr "length"   "8")])
7532
7533 (define_split
7534   [(set (match_operand:DI 0 "register_operand" "")
7535         (ne:DI (match_operand:DI 1 "register_operand" "")
7536                (match_operand:DI 2 "uns_arith_operand" "")))]
7537   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
7538     && !TARGET_MIPS16
7539     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
7540   [(set (match_dup 0)
7541         (xor:DI (match_dup 1)
7542                 (match_dup 2)))
7543    (set (match_dup 0)
7544         (gtu:DI (match_dup 0)
7545                 (const_int 0)))]
7546   "")
7547
7548 (define_expand "sgt"
7549   [(set (match_operand:SI 0 "register_operand" "=d")
7550         (gt:SI (match_dup 1)
7551                (match_dup 2)))]
7552   ""
7553   "
7554 {
7555   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7556     FAIL;
7557
7558   /* set up operands from compare.  */
7559   operands[1] = branch_cmp[0];
7560   operands[2] = branch_cmp[1];
7561
7562   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7563     {
7564       gen_int_relational (GT, operands[0], operands[1], operands[2], (int *)0);
7565       DONE;
7566     }
7567
7568   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
7569     operands[2] = force_reg (SImode, operands[2]);
7570
7571   /* fall through and generate default code */
7572 }")
7573
7574 (define_insn "sgt_si"
7575   [(set (match_operand:SI 0 "register_operand" "=d")
7576         (gt:SI (match_operand:SI 1 "register_operand" "d")
7577                (match_operand:SI 2 "reg_or_0_operand" "dJ")))]
7578   "!TARGET_MIPS16"
7579   "slt\\t%0,%z2,%1"
7580   [(set_attr "type"     "arith")
7581    (set_attr "mode"     "SI")])
7582
7583 (define_insn ""
7584   [(set (match_operand:SI 0 "register_operand" "=t")
7585         (gt:SI (match_operand:SI 1 "register_operand" "d")
7586                (match_operand:SI 2 "register_operand" "d")))]
7587   "TARGET_MIPS16"
7588   "slt\\t%2,%1"
7589   [(set_attr "type"     "arith")
7590    (set_attr "mode"     "SI")])
7591
7592 (define_insn "sgt_di"
7593   [(set (match_operand:DI 0 "register_operand" "=d")
7594         (gt:DI (match_operand:DI 1 "register_operand" "d")
7595                (match_operand:DI 2 "reg_or_0_operand" "dJ")))]
7596   "TARGET_64BIT && !TARGET_MIPS16"
7597   "slt\\t%0,%z2,%1"
7598   [(set_attr "type"     "arith")
7599    (set_attr "mode"     "DI")])
7600
7601 (define_insn ""
7602   [(set (match_operand:DI 0 "register_operand" "=d")
7603         (gt:DI (match_operand:DI 1 "register_operand" "d")
7604                (match_operand:DI 2 "register_operand" "d")))]
7605   "TARGET_64BIT && TARGET_MIPS16"
7606   "slt\\t%2,%1"
7607   [(set_attr "type"     "arith")
7608    (set_attr "mode"     "DI")])
7609
7610 (define_expand "sge"
7611   [(set (match_operand:SI 0 "register_operand" "=d")
7612         (ge:SI (match_dup 1)
7613                (match_dup 2)))]
7614   ""
7615   "
7616 {
7617   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7618     FAIL;
7619
7620   /* set up operands from compare.  */
7621   operands[1] = branch_cmp[0];
7622   operands[2] = branch_cmp[1];
7623
7624   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7625     {
7626       gen_int_relational (GE, operands[0], operands[1], operands[2], (int *)0);
7627       DONE;
7628     }
7629
7630   /* fall through and generate default code */
7631 }")
7632
7633 (define_insn "sge_si"
7634   [(set (match_operand:SI 0 "register_operand" "=d")
7635         (ge:SI (match_operand:SI 1 "register_operand" "d")
7636                (match_operand:SI 2 "arith_operand" "dI")))]
7637   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7638   "slt\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
7639   [(set_attr "type"     "arith")
7640    (set_attr "mode"     "SI")
7641    (set_attr "length"   "8")])
7642
7643 (define_split
7644   [(set (match_operand:SI 0 "register_operand" "")
7645         (ge:SI (match_operand:SI 1 "register_operand" "")
7646                (match_operand:SI 2 "arith_operand" "")))]
7647   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
7648   [(set (match_dup 0)
7649         (lt:SI (match_dup 1)
7650                (match_dup 2)))
7651    (set (match_dup 0)
7652         (xor:SI (match_dup 0)
7653                 (const_int 1)))]
7654   "")
7655
7656 (define_insn "sge_di"
7657   [(set (match_operand:DI 0 "register_operand" "=d")
7658         (ge:DI (match_operand:DI 1 "register_operand" "d")
7659                (match_operand:DI 2 "arith_operand" "dI")))]
7660   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7661   "slt\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
7662   [(set_attr "type"     "arith")
7663    (set_attr "mode"     "DI")
7664    (set_attr "length"   "8")])
7665
7666 (define_split
7667   [(set (match_operand:DI 0 "register_operand" "")
7668         (ge:DI (match_operand:DI 1 "register_operand" "")
7669                (match_operand:DI 2 "arith_operand" "")))]
7670   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
7671    && !TARGET_MIPS16"
7672   [(set (match_dup 0)
7673         (lt:DI (match_dup 1)
7674                (match_dup 2)))
7675    (set (match_dup 0)
7676         (xor:DI (match_dup 0)
7677                 (const_int 1)))]
7678   "")
7679
7680 (define_expand "slt"
7681   [(set (match_operand:SI 0 "register_operand" "=d")
7682         (lt:SI (match_dup 1)
7683                (match_dup 2)))]
7684   ""
7685   "
7686 {
7687   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7688     FAIL;
7689
7690   /* set up operands from compare.  */
7691   operands[1] = branch_cmp[0];
7692   operands[2] = branch_cmp[1];
7693
7694   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7695     {
7696       gen_int_relational (LT, operands[0], operands[1], operands[2], (int *)0);
7697       DONE;
7698     }
7699
7700   /* fall through and generate default code */
7701 }")
7702
7703 (define_insn "slt_si"
7704   [(set (match_operand:SI 0 "register_operand" "=d")
7705         (lt:SI (match_operand:SI 1 "register_operand" "d")
7706                (match_operand:SI 2 "arith_operand" "dI")))]
7707   "!TARGET_MIPS16"
7708   "slt\\t%0,%1,%2"
7709   [(set_attr "type"     "arith")
7710    (set_attr "mode"     "SI")])
7711
7712 (define_insn ""
7713   [(set (match_operand:SI 0 "register_operand" "=t,t")
7714         (lt:SI (match_operand:SI 1 "register_operand" "d,d")
7715                (match_operand:SI 2 "arith_operand" "d,I")))]
7716   "TARGET_MIPS16"
7717   "slt\\t%1,%2"
7718   [(set_attr "type"     "arith")
7719    (set_attr "mode"     "SI")
7720    (set_attr_alternative "length"
7721                 [(const_int 4)
7722                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
7723                                (const_int 4)
7724                                (const_int 8))])])
7725
7726 (define_insn "slt_di"
7727   [(set (match_operand:DI 0 "register_operand" "=d")
7728         (lt:DI (match_operand:DI 1 "register_operand" "d")
7729                (match_operand:DI 2 "arith_operand" "dI")))]
7730   "TARGET_64BIT && !TARGET_MIPS16"
7731   "slt\\t%0,%1,%2"
7732   [(set_attr "type"     "arith")
7733    (set_attr "mode"     "DI")])
7734
7735 (define_insn ""
7736   [(set (match_operand:DI 0 "register_operand" "=t,t")
7737         (lt:DI (match_operand:DI 1 "register_operand" "d,d")
7738                (match_operand:DI 2 "arith_operand" "d,I")))]
7739   "TARGET_64BIT && TARGET_MIPS16"
7740   "slt\\t%1,%2"
7741   [(set_attr "type"     "arith")
7742    (set_attr "mode"     "DI")
7743    (set_attr_alternative "length"
7744                 [(const_int 4)
7745                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
7746                                (const_int 4)
7747                                (const_int 8))])])
7748
7749 (define_expand "sle"
7750   [(set (match_operand:SI 0 "register_operand" "=d")
7751         (le:SI (match_dup 1)
7752                (match_dup 2)))]
7753   ""
7754   "
7755 {
7756   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7757     FAIL;
7758
7759   /* set up operands from compare.  */
7760   operands[1] = branch_cmp[0];
7761   operands[2] = branch_cmp[1];
7762
7763   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7764     {
7765       gen_int_relational (LE, operands[0], operands[1], operands[2], (int *)0);
7766       DONE;
7767     }
7768
7769   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 32767)
7770     operands[2] = force_reg (SImode, operands[2]);
7771
7772   /* fall through and generate default code */
7773 }")
7774
7775 (define_insn "sle_si_const"
7776   [(set (match_operand:SI 0 "register_operand" "=d")
7777         (le:SI (match_operand:SI 1 "register_operand" "d")
7778                (match_operand:SI 2 "small_int" "I")))]
7779   "!TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
7780   "*
7781 {
7782   operands[2] = GEN_INT (INTVAL (operands[2])+1);
7783   return \"slt\\t%0,%1,%2\";
7784 }"
7785   [(set_attr "type"     "arith")
7786    (set_attr "mode"     "SI")])
7787
7788 (define_insn ""
7789   [(set (match_operand:SI 0 "register_operand" "=t")
7790         (le:SI (match_operand:SI 1 "register_operand" "d")
7791                (match_operand:SI 2 "small_int" "I")))]
7792   "TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
7793   "*
7794 {
7795   operands[2] = GEN_INT (INTVAL (operands[2])+1);
7796   return \"slt\\t%1,%2\";
7797 }"
7798   [(set_attr "type"     "arith")
7799    (set_attr "mode"     "SI")
7800    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
7801                                       (const_int 4)
7802                                       (const_int 8)))])
7803
7804 (define_insn "sle_di_const"
7805   [(set (match_operand:DI 0 "register_operand" "=d")
7806         (le:DI (match_operand:DI 1 "register_operand" "d")
7807                (match_operand:DI 2 "small_int" "I")))]
7808   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
7809   "*
7810 {
7811   operands[2] = GEN_INT (INTVAL (operands[2])+1);
7812   return \"slt\\t%0,%1,%2\";
7813 }"
7814   [(set_attr "type"     "arith")
7815    (set_attr "mode"     "DI")])
7816
7817 (define_insn ""
7818   [(set (match_operand:DI 0 "register_operand" "=t")
7819         (le:DI (match_operand:DI 1 "register_operand" "d")
7820                (match_operand:DI 2 "small_int" "I")))]
7821   "TARGET_64BIT && TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
7822   "*
7823 {
7824   operands[2] = GEN_INT (INTVAL (operands[2])+1);
7825   return \"slt\\t%1,%2\";
7826 }"
7827   [(set_attr "type"     "arith")
7828    (set_attr "mode"     "DI")
7829    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
7830                                       (const_int 4)
7831                                       (const_int 8)))])
7832
7833 (define_insn "sle_si_reg"
7834   [(set (match_operand:SI 0 "register_operand" "=d")
7835         (le:SI (match_operand:SI 1 "register_operand" "d")
7836                (match_operand:SI 2 "register_operand" "d")))]
7837   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7838   "slt\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
7839   [(set_attr "type"     "arith")
7840    (set_attr "mode"     "SI")
7841    (set_attr "length"   "8")])
7842
7843 (define_split
7844   [(set (match_operand:SI 0 "register_operand" "")
7845         (le:SI (match_operand:SI 1 "register_operand" "")
7846                (match_operand:SI 2 "register_operand" "")))]
7847   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
7848   [(set (match_dup 0)
7849         (lt:SI (match_dup 2)
7850                (match_dup 1)))
7851    (set (match_dup 0)
7852         (xor:SI (match_dup 0)
7853                 (const_int 1)))]
7854   "")
7855
7856 (define_insn "sle_di_reg"
7857   [(set (match_operand:DI 0 "register_operand" "=d")
7858         (le:DI (match_operand:DI 1 "register_operand" "d")
7859                (match_operand:DI 2 "register_operand" "d")))]
7860   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7861   "slt\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
7862   [(set_attr "type"     "arith")
7863    (set_attr "mode"     "DI")
7864    (set_attr "length"   "8")])
7865
7866 (define_split
7867   [(set (match_operand:DI 0 "register_operand" "")
7868         (le:DI (match_operand:DI 1 "register_operand" "")
7869                (match_operand:DI 2 "register_operand" "")))]
7870   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
7871    && !TARGET_MIPS16"
7872   [(set (match_dup 0)
7873         (lt:DI (match_dup 2)
7874                (match_dup 1)))
7875    (set (match_dup 0)
7876         (xor:DI (match_dup 0)
7877                 (const_int 1)))]
7878   "")
7879
7880 (define_expand "sgtu"
7881   [(set (match_operand:SI 0 "register_operand" "=d")
7882         (gtu:SI (match_dup 1)
7883                 (match_dup 2)))]
7884   ""
7885   "
7886 {
7887   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7888     FAIL;
7889
7890   /* set up operands from compare.  */
7891   operands[1] = branch_cmp[0];
7892   operands[2] = branch_cmp[1];
7893
7894   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7895     {
7896       gen_int_relational (GTU, operands[0], operands[1], operands[2], (int *)0);
7897       DONE;
7898     }
7899
7900   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
7901     operands[2] = force_reg (SImode, operands[2]);
7902
7903   /* fall through and generate default code */
7904 }")
7905
7906 (define_insn "sgtu_si"
7907   [(set (match_operand:SI 0 "register_operand" "=d")
7908         (gtu:SI (match_operand:SI 1 "register_operand" "d")
7909                 (match_operand:SI 2 "reg_or_0_operand" "dJ")))]
7910   "!TARGET_MIPS16"
7911   "sltu\\t%0,%z2,%1"
7912   [(set_attr "type"     "arith")
7913    (set_attr "mode"     "SI")])
7914
7915 (define_insn ""
7916   [(set (match_operand:SI 0 "register_operand" "=t")
7917         (gtu:SI (match_operand:SI 1 "register_operand" "d")
7918                 (match_operand:SI 2 "register_operand" "d")))]
7919   "TARGET_MIPS16"
7920   "sltu\\t%2,%1"
7921   [(set_attr "type"     "arith")
7922    (set_attr "mode"     "SI")])
7923
7924 (define_insn "sgtu_di"
7925   [(set (match_operand:DI 0 "register_operand" "=d")
7926         (gtu:DI (match_operand:DI 1 "register_operand" "d")
7927                 (match_operand:DI 2 "reg_or_0_operand" "dJ")))]
7928   "TARGET_64BIT && !TARGET_MIPS16"
7929   "sltu\\t%0,%z2,%1"
7930   [(set_attr "type"     "arith")
7931    (set_attr "mode"     "DI")])
7932
7933 (define_insn ""
7934   [(set (match_operand:DI 0 "register_operand" "=t")
7935         (gtu:DI (match_operand:DI 1 "register_operand" "d")
7936                 (match_operand:DI 2 "register_operand" "d")))]
7937   "TARGET_64BIT && TARGET_MIPS16"
7938   "sltu\\t%2,%1"
7939   [(set_attr "type"     "arith")
7940    (set_attr "mode"     "DI")])
7941
7942 (define_expand "sgeu"
7943   [(set (match_operand:SI 0 "register_operand" "=d")
7944         (geu:SI (match_dup 1)
7945                 (match_dup 2)))]
7946   ""
7947   "
7948 {
7949   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
7950     FAIL;
7951
7952   /* set up operands from compare.  */
7953   operands[1] = branch_cmp[0];
7954   operands[2] = branch_cmp[1];
7955
7956   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
7957     {
7958       gen_int_relational (GEU, operands[0], operands[1], operands[2], (int *)0);
7959       DONE;
7960     }
7961
7962   /* fall through and generate default code */
7963 }")
7964
7965 (define_insn "sgeu_si"
7966   [(set (match_operand:SI 0 "register_operand" "=d")
7967         (geu:SI (match_operand:SI 1 "register_operand" "d")
7968                 (match_operand:SI 2 "arith_operand" "dI")))]
7969   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7970   "sltu\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
7971   [(set_attr "type"     "arith")
7972    (set_attr "mode"     "SI")
7973    (set_attr "length"   "8")])
7974
7975 (define_split
7976   [(set (match_operand:SI 0 "register_operand" "")
7977         (geu:SI (match_operand:SI 1 "register_operand" "")
7978                 (match_operand:SI 2 "arith_operand" "")))]
7979   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
7980   [(set (match_dup 0)
7981         (ltu:SI (match_dup 1)
7982                 (match_dup 2)))
7983    (set (match_dup 0)
7984         (xor:SI (match_dup 0)
7985                 (const_int 1)))]
7986   "")
7987
7988 (define_insn "sgeu_di"
7989   [(set (match_operand:DI 0 "register_operand" "=d")
7990         (geu:DI (match_operand:DI 1 "register_operand" "d")
7991                 (match_operand:DI 2 "arith_operand" "dI")))]
7992   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
7993   "sltu\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
7994   [(set_attr "type"     "arith")
7995    (set_attr "mode"     "DI")
7996    (set_attr "length"   "8")])
7997
7998 (define_split
7999   [(set (match_operand:DI 0 "register_operand" "")
8000         (geu:DI (match_operand:DI 1 "register_operand" "")
8001                 (match_operand:DI 2 "arith_operand" "")))]
8002   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8003    && !TARGET_MIPS16"
8004   [(set (match_dup 0)
8005         (ltu:DI (match_dup 1)
8006                 (match_dup 2)))
8007    (set (match_dup 0)
8008         (xor:DI (match_dup 0)
8009                 (const_int 1)))]
8010   "")
8011
8012 (define_expand "sltu"
8013   [(set (match_operand:SI 0 "register_operand" "=d")
8014         (ltu:SI (match_dup 1)
8015                 (match_dup 2)))]
8016   ""
8017   "
8018 {
8019   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8020     FAIL;
8021
8022   /* set up operands from compare.  */
8023   operands[1] = branch_cmp[0];
8024   operands[2] = branch_cmp[1];
8025
8026   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8027     {
8028       gen_int_relational (LTU, operands[0], operands[1], operands[2], (int *)0);
8029       DONE;
8030     }
8031
8032   /* fall through and generate default code */
8033 }")
8034
8035 (define_insn "sltu_si"
8036   [(set (match_operand:SI 0 "register_operand" "=d")
8037         (ltu:SI (match_operand:SI 1 "register_operand" "d")
8038                 (match_operand:SI 2 "arith_operand" "dI")))]
8039   "!TARGET_MIPS16"
8040   "sltu\\t%0,%1,%2"
8041   [(set_attr "type"     "arith")
8042    (set_attr "mode"     "SI")])
8043
8044 (define_insn ""
8045   [(set (match_operand:SI 0 "register_operand" "=t,t")
8046         (ltu:SI (match_operand:SI 1 "register_operand" "d,d")
8047                 (match_operand:SI 2 "arith_operand" "d,I")))]
8048   "TARGET_MIPS16"
8049   "sltu\\t%1,%2"
8050   [(set_attr "type"     "arith")
8051    (set_attr "mode"     "SI")
8052    (set_attr_alternative "length"
8053                 [(const_int 4)
8054                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
8055                                (const_int 4)
8056                                (const_int 8))])])
8057
8058 (define_insn "sltu_di"
8059   [(set (match_operand:DI 0 "register_operand" "=d")
8060         (ltu:DI (match_operand:DI 1 "register_operand" "d")
8061                 (match_operand:DI 2 "arith_operand" "dI")))]
8062   "TARGET_64BIT && !TARGET_MIPS16"
8063   "sltu\\t%0,%1,%2"
8064   [(set_attr "type"     "arith")
8065    (set_attr "mode"     "DI")])
8066
8067 (define_insn ""
8068   [(set (match_operand:DI 0 "register_operand" "=t,t")
8069         (ltu:DI (match_operand:DI 1 "register_operand" "d,d")
8070                 (match_operand:DI 2 "arith_operand" "d,I")))]
8071   "TARGET_64BIT && TARGET_MIPS16"
8072   "sltu\\t%1,%2"
8073   [(set_attr "type"     "arith")
8074    (set_attr "mode"     "DI")
8075    (set_attr_alternative "length"
8076                 [(const_int 4)
8077                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
8078                                (const_int 4)
8079                                (const_int 8))])])
8080
8081 (define_expand "sleu"
8082   [(set (match_operand:SI 0 "register_operand" "=d")
8083         (leu:SI (match_dup 1)
8084                 (match_dup 2)))]
8085   ""
8086   "
8087 {
8088   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8089     FAIL;
8090
8091   /* set up operands from compare.  */
8092   operands[1] = branch_cmp[0];
8093   operands[2] = branch_cmp[1];
8094
8095   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8096     {
8097       gen_int_relational (LEU, operands[0], operands[1], operands[2], (int *)0);
8098       DONE;
8099     }
8100
8101   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 32767)
8102     operands[2] = force_reg (SImode, operands[2]);
8103
8104   /* fall through and generate default code */
8105 }")
8106
8107 (define_insn "sleu_si_const"
8108   [(set (match_operand:SI 0 "register_operand" "=d")
8109         (leu:SI (match_operand:SI 1 "register_operand" "d")
8110                 (match_operand:SI 2 "small_int" "I")))]
8111   "!TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8112   "*
8113 {
8114   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
8115   return \"sltu\\t%0,%1,%2\";
8116 }"
8117   [(set_attr "type"     "arith")
8118    (set_attr "mode"     "SI")])
8119
8120 (define_insn ""
8121   [(set (match_operand:SI 0 "register_operand" "=t")
8122         (leu:SI (match_operand:SI 1 "register_operand" "d")
8123                 (match_operand:SI 2 "small_int" "I")))]
8124   "TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8125   "*
8126 {
8127   operands[2] = GEN_INT (INTVAL (operands[2])+1);
8128   return \"sltu\\t%1,%2\";
8129 }"
8130   [(set_attr "type"     "arith")
8131    (set_attr "mode"     "SI")
8132    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
8133                                       (const_int 4)
8134                                       (const_int 8)))])
8135
8136 (define_insn "sleu_di_const"
8137   [(set (match_operand:DI 0 "register_operand" "=d")
8138         (leu:DI (match_operand:DI 1 "register_operand" "d")
8139                 (match_operand:DI 2 "small_int" "I")))]
8140   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8141   "*
8142 {
8143   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
8144   return \"sltu\\t%0,%1,%2\";
8145 }"
8146   [(set_attr "type"     "arith")
8147    (set_attr "mode"     "DI")])
8148
8149 (define_insn ""
8150   [(set (match_operand:DI 0 "register_operand" "=t")
8151         (leu:DI (match_operand:DI 1 "register_operand" "d")
8152                 (match_operand:DI 2 "small_int" "I")))]
8153   "TARGET_64BIT && TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8154   "*
8155 {
8156   operands[2] = GEN_INT (INTVAL (operands[2])+1);
8157   return \"sltu\\t%1,%2\";
8158 }"
8159   [(set_attr "type"     "arith")
8160    (set_attr "mode"     "DI")
8161    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
8162                                       (const_int 4)
8163                                       (const_int 8)))])
8164
8165 (define_insn "sleu_si_reg"
8166   [(set (match_operand:SI 0 "register_operand" "=d")
8167         (leu:SI (match_operand:SI 1 "register_operand" "d")
8168                 (match_operand:SI 2 "register_operand" "d")))]
8169   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8170   "sltu\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
8171   [(set_attr "type"     "arith")
8172    (set_attr "mode"     "SI")
8173    (set_attr "length"   "8")])
8174
8175 (define_split
8176   [(set (match_operand:SI 0 "register_operand" "")
8177         (leu:SI (match_operand:SI 1 "register_operand" "")
8178                 (match_operand:SI 2 "register_operand" "")))]
8179   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
8180   [(set (match_dup 0)
8181         (ltu:SI (match_dup 2)
8182                 (match_dup 1)))
8183    (set (match_dup 0)
8184         (xor:SI (match_dup 0)
8185                 (const_int 1)))]
8186   "")
8187
8188 (define_insn "sleu_di_reg"
8189   [(set (match_operand:DI 0 "register_operand" "=d")
8190         (leu:DI (match_operand:DI 1 "register_operand" "d")
8191                 (match_operand:DI 2 "register_operand" "d")))]
8192   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8193   "sltu\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
8194   [(set_attr "type"     "arith")
8195    (set_attr "mode"     "DI")
8196    (set_attr "length"   "8")])
8197
8198 (define_split
8199   [(set (match_operand:DI 0 "register_operand" "")
8200         (leu:DI (match_operand:DI 1 "register_operand" "")
8201                 (match_operand:DI 2 "register_operand" "")))]
8202   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8203    && !TARGET_MIPS16"
8204   [(set (match_dup 0)
8205         (ltu:DI (match_dup 2)
8206                 (match_dup 1)))
8207    (set (match_dup 0)
8208         (xor:DI (match_dup 0)
8209                 (const_int 1)))]
8210   "")
8211
8212 \f
8213 ;;
8214 ;;  ....................
8215 ;;
8216 ;;      FLOATING POINT COMPARISONS
8217 ;;
8218 ;;  ....................
8219
8220 (define_insn "sunordered_df"
8221   [(set (match_operand:CC 0 "register_operand" "=z")
8222         (unordered:CC (match_operand:DF 1 "register_operand" "f")
8223                       (match_operand:DF 2 "register_operand" "f")))]
8224   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8225   "c.un.d\t%Z0%1,%2"
8226   [(set_attr "type" "fcmp")
8227    (set_attr "mode" "FPSW")])
8228
8229 (define_insn "sunlt_df"
8230   [(set (match_operand:CC 0 "register_operand" "=z")
8231         (unlt:CC (match_operand:DF 1 "register_operand" "f")
8232                  (match_operand:DF 2 "register_operand" "f")))]
8233   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8234   "c.ult.d\t%Z0%1,%2"
8235   [(set_attr "type" "fcmp")
8236    (set_attr "mode" "FPSW")])
8237
8238 (define_insn "suneq_df"
8239   [(set (match_operand:CC 0 "register_operand" "=z")
8240         (uneq:CC (match_operand:DF 1 "register_operand" "f")
8241                  (match_operand:DF 2 "register_operand" "f")))]
8242   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8243   "c.ueq.d\t%Z0%1,%2"
8244   [(set_attr "type" "fcmp")
8245    (set_attr "mode" "FPSW")])
8246
8247 (define_insn "sunle_df"
8248   [(set (match_operand:CC 0 "register_operand" "=z")
8249         (unle:CC (match_operand:DF 1 "register_operand" "f")
8250                  (match_operand:DF 2 "register_operand" "f")))]
8251   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8252   "c.ule.d\t%Z0%1,%2"
8253   [(set_attr "type" "fcmp")
8254    (set_attr "mode" "FPSW")])
8255
8256 (define_insn "seq_df"
8257   [(set (match_operand:CC 0 "register_operand" "=z")
8258         (eq:CC (match_operand:DF 1 "register_operand" "f")
8259                (match_operand:DF 2 "register_operand" "f")))]
8260   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8261   "c.eq.d\t%Z0%1,%2"
8262   [(set_attr "type" "fcmp")
8263    (set_attr "mode" "FPSW")])
8264
8265 (define_insn "slt_df"
8266   [(set (match_operand:CC 0 "register_operand" "=z")
8267         (lt:CC (match_operand:DF 1 "register_operand" "f")
8268                (match_operand:DF 2 "register_operand" "f")))]
8269   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8270   "c.lt.d\t%Z0%1,%2"
8271   [(set_attr "type" "fcmp")
8272    (set_attr "mode" "FPSW")])
8273
8274 (define_insn "sle_df"
8275   [(set (match_operand:CC 0 "register_operand" "=z")
8276         (le:CC (match_operand:DF 1 "register_operand" "f")
8277                (match_operand:DF 2 "register_operand" "f")))]
8278   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8279   "c.le.d\t%Z0%1,%2"
8280   [(set_attr "type" "fcmp")
8281    (set_attr "mode" "FPSW")])
8282
8283 (define_insn "sgt_df"
8284   [(set (match_operand:CC 0 "register_operand" "=z")
8285         (gt:CC (match_operand:DF 1 "register_operand" "f")
8286                (match_operand:DF 2 "register_operand" "f")))]
8287   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8288   "c.lt.d\t%Z0%2,%1"
8289   [(set_attr "type" "fcmp")
8290    (set_attr "mode" "FPSW")])
8291
8292 (define_insn "sge_df"
8293   [(set (match_operand:CC 0 "register_operand" "=z")
8294         (ge:CC (match_operand:DF 1 "register_operand" "f")
8295                (match_operand:DF 2 "register_operand" "f")))]
8296   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
8297   "c.le.d\t%Z0%2,%1"
8298   [(set_attr "type" "fcmp")
8299    (set_attr "mode" "FPSW")])
8300
8301 (define_insn "sunordered_sf"
8302   [(set (match_operand:CC 0 "register_operand" "=z")
8303         (unordered:CC (match_operand:SF 1 "register_operand" "f")
8304                       (match_operand:SF 2 "register_operand" "f")))]
8305   "TARGET_HARD_FLOAT"
8306   "c.un.s\t%Z0%1,%2"
8307   [(set_attr "type" "fcmp")
8308    (set_attr "mode" "FPSW")])
8309
8310 (define_insn "sunlt_sf"
8311   [(set (match_operand:CC 0 "register_operand" "=z")
8312         (unlt:CC (match_operand:SF 1 "register_operand" "f")
8313                  (match_operand:SF 2 "register_operand" "f")))]
8314   "TARGET_HARD_FLOAT"
8315   "c.ult.s\t%Z0%1,%2"
8316   [(set_attr "type" "fcmp")
8317    (set_attr "mode" "FPSW")])
8318
8319 (define_insn "suneq_sf"
8320   [(set (match_operand:CC 0 "register_operand" "=z")
8321         (uneq:CC (match_operand:SF 1 "register_operand" "f")
8322                  (match_operand:SF 2 "register_operand" "f")))]
8323   "TARGET_HARD_FLOAT"
8324   "c.ueq.s\t%Z0%1,%2"
8325   [(set_attr "type" "fcmp")
8326    (set_attr "mode" "FPSW")])
8327
8328 (define_insn "sunle_sf"
8329   [(set (match_operand:CC 0 "register_operand" "=z")
8330         (unle:CC (match_operand:SF 1 "register_operand" "f")
8331                  (match_operand:SF 2 "register_operand" "f")))]
8332   "TARGET_HARD_FLOAT"
8333   "c.ule.s\t%Z0%1,%2"
8334   [(set_attr "type" "fcmp")
8335    (set_attr "mode" "FPSW")])
8336
8337 (define_insn "seq_sf"
8338   [(set (match_operand:CC 0 "register_operand" "=z")
8339         (eq:CC (match_operand:SF 1 "register_operand" "f")
8340                (match_operand:SF 2 "register_operand" "f")))]
8341   "TARGET_HARD_FLOAT"
8342   "c.eq.s\t%Z0%1,%2"
8343   [(set_attr "type" "fcmp")
8344    (set_attr "mode" "FPSW")])
8345
8346 (define_insn "slt_sf"
8347   [(set (match_operand:CC 0 "register_operand" "=z")
8348         (lt:CC (match_operand:SF 1 "register_operand" "f")
8349                (match_operand:SF 2 "register_operand" "f")))]
8350   "TARGET_HARD_FLOAT"
8351   "c.lt.s\t%Z0%1,%2"
8352   [(set_attr "type" "fcmp")
8353    (set_attr "mode" "FPSW")])
8354
8355 (define_insn "sle_sf"
8356   [(set (match_operand:CC 0 "register_operand" "=z")
8357         (le:CC (match_operand:SF 1 "register_operand" "f")
8358                (match_operand:SF 2 "register_operand" "f")))]
8359   "TARGET_HARD_FLOAT"
8360   "c.le.s\t%Z0%1,%2"
8361   [(set_attr "type" "fcmp")
8362    (set_attr "mode" "FPSW")])
8363
8364 (define_insn "sgt_sf"
8365   [(set (match_operand:CC 0 "register_operand" "=z")
8366         (gt:CC (match_operand:SF 1 "register_operand" "f")
8367                (match_operand:SF 2 "register_operand" "f")))]
8368   "TARGET_HARD_FLOAT"
8369   "c.lt.s\t%Z0%2,%1"
8370   [(set_attr "type" "fcmp")
8371    (set_attr "mode" "FPSW")])
8372
8373 (define_insn "sge_sf"
8374   [(set (match_operand:CC 0 "register_operand" "=z")
8375         (ge:CC (match_operand:SF 1 "register_operand" "f")
8376                (match_operand:SF 2 "register_operand" "f")))]
8377   "TARGET_HARD_FLOAT"
8378   "c.le.s\t%Z0%2,%1"
8379   [(set_attr "type" "fcmp")
8380    (set_attr "mode" "FPSW")])
8381
8382 \f
8383 ;;
8384 ;;  ....................
8385 ;;
8386 ;;      UNCONDITIONAL BRANCHES
8387 ;;
8388 ;;  ....................
8389
8390 ;; Unconditional branches.
8391
8392 (define_insn "jump"
8393   [(set (pc)
8394         (label_ref (match_operand 0 "" "")))]
8395   "!TARGET_MIPS16"
8396   "*
8397 {
8398   if (flag_pic && ! TARGET_EMBEDDED_PIC)
8399     {
8400       if (get_attr_length (insn) <= 8)
8401         return \"%*b\\t%l0%/\";
8402       else
8403         {
8404           output_asm_insn (mips_output_load_label (), operands);
8405           return \"%*jr\\t%@%/%]\";
8406         }
8407     }
8408   else
8409     return \"%*j\\t%l0%/\";
8410 }"
8411   [(set_attr "type"     "jump")
8412    (set_attr "mode"     "none")
8413    (set (attr "length")
8414         ;; we can't use `j' when emitting non-embedded PIC, so we emit
8415         ;; branch, if it's in range, or load the address of the branch
8416         ;; target into $at in a PIC-compatible way and then jump to it.
8417         (if_then_else
8418          (ior (eq (symbol_ref "flag_pic && ! TARGET_EMBEDDED_PIC")
8419                   (const_int 0))
8420               (lt (abs (minus (match_dup 0)
8421                               (plus (pc) (const_int 4))))
8422                   (const_int 131072)))
8423          (const_int 4) (const_int 16)))])
8424
8425 ;; We need a different insn for the mips16, because a mips16 branch
8426 ;; does not have a delay slot.
8427
8428 (define_insn ""
8429   [(set (pc)
8430         (label_ref (match_operand 0 "" "")))]
8431   "TARGET_MIPS16"
8432   "b\\t%l0"
8433   [(set_attr "type"     "branch")
8434    (set_attr "mode"     "none")
8435    (set_attr "length"   "8")])
8436
8437 (define_expand "indirect_jump"
8438   [(set (pc) (match_operand 0 "register_operand" "d"))]
8439   ""
8440   "
8441 {
8442   rtx dest;
8443
8444   if (operands[0])              /* eliminate unused code warnings */
8445     {
8446       dest = operands[0];
8447       if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
8448         operands[0] = copy_to_mode_reg (Pmode, dest);
8449
8450       if (!(Pmode == DImode))
8451         emit_jump_insn (gen_indirect_jump_internal1 (operands[0]));
8452       else
8453         emit_jump_insn (gen_indirect_jump_internal2 (operands[0]));
8454
8455       DONE;
8456     }
8457 }")
8458
8459 (define_insn "indirect_jump_internal1"
8460   [(set (pc) (match_operand:SI 0 "register_operand" "d"))]
8461   "!(Pmode == DImode)"
8462   "%*j\t%0%/"
8463   [(set_attr "type"     "jump")
8464    (set_attr "mode"     "none")])
8465
8466 (define_insn "indirect_jump_internal2"
8467   [(set (pc) (match_operand:DI 0 "register_operand" "d"))]
8468   "Pmode == DImode"
8469   "%*j\t%0%/"
8470   [(set_attr "type"     "jump")
8471    (set_attr "mode"     "none")])
8472
8473 (define_expand "tablejump"
8474   [(set (pc)
8475         (match_operand 0 "register_operand" "d"))
8476    (use (label_ref (match_operand 1 "" "")))]
8477   ""
8478   "
8479 {
8480   if (operands[0])              /* eliminate unused code warnings */
8481     {
8482       if (TARGET_MIPS16)
8483         {
8484           if (GET_MODE (operands[0]) != HImode)
8485             abort ();
8486           if (!(Pmode == DImode))
8487             emit_insn (gen_tablejump_mips161 (operands[0], operands[1]));
8488           else
8489             emit_insn (gen_tablejump_mips162 (operands[0], operands[1]));
8490           DONE;
8491         }
8492
8493       if (GET_MODE (operands[0]) != ptr_mode)
8494         abort ();
8495
8496       if (TARGET_GPWORD)
8497         operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
8498                                     pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
8499
8500       if (Pmode == SImode)
8501         emit_jump_insn (gen_tablejump_internal1 (operands[0], operands[1]));
8502       else
8503         emit_jump_insn (gen_tablejump_internal2 (operands[0], operands[1]));
8504       DONE;
8505     }
8506 }")
8507
8508 (define_insn "tablejump_internal1"
8509   [(set (pc)
8510         (match_operand:SI 0 "register_operand" "d"))
8511    (use (label_ref (match_operand 1 "" "")))]
8512   ""
8513   "%*j\t%0%/"
8514   [(set_attr "type"     "jump")
8515    (set_attr "mode"     "none")])
8516
8517 (define_insn "tablejump_internal2"
8518   [(set (pc)
8519         (match_operand:DI 0 "register_operand" "d"))
8520    (use (label_ref (match_operand 1 "" "")))]
8521   "TARGET_64BIT"
8522   "%*j\t%0%/"
8523   [(set_attr "type"     "jump")
8524    (set_attr "mode"     "none")])
8525
8526 (define_expand "tablejump_mips161"
8527   [(set (pc) (plus:SI (sign_extend:SI
8528                        (match_operand:HI 0 "register_operand" "d"))
8529                       (label_ref:SI (match_operand 1 "" ""))))]
8530   "TARGET_MIPS16 && !(Pmode == DImode)"
8531   "
8532 {
8533   if (operands[0])      /* eliminate unused code warnings.  */
8534     {
8535       rtx t1, t2, t3;
8536
8537       t1 = gen_reg_rtx (SImode);
8538       t2 = gen_reg_rtx (SImode);
8539       t3 = gen_reg_rtx (SImode);
8540       emit_insn (gen_extendhisi2 (t1, operands[0]));
8541       emit_move_insn (t2, gen_rtx_LABEL_REF (SImode, operands[1]));
8542       emit_insn (gen_addsi3 (t3, t1, t2));
8543       emit_jump_insn (gen_tablejump_internal1 (t3, operands[1]));
8544       DONE;
8545     }
8546 }")
8547
8548 (define_expand "tablejump_mips162"
8549   [(set (pc) (plus:DI (sign_extend:DI
8550                        (match_operand:HI 0 "register_operand" "d"))
8551                       (label_ref:DI (match_operand 1 "" ""))))]
8552   "TARGET_MIPS16 && Pmode == DImode"
8553   "
8554 {
8555   if (operands[0])      /* eliminate unused code warnings.  */
8556     {
8557       rtx t1, t2, t3;
8558
8559       t1 = gen_reg_rtx (DImode);
8560       t2 = gen_reg_rtx (DImode);
8561       t3 = gen_reg_rtx (DImode);
8562       emit_insn (gen_extendhidi2 (t1, operands[0]));
8563       emit_move_insn (t2, gen_rtx_LABEL_REF (DImode, operands[1]));
8564       emit_insn (gen_adddi3 (t3, t1, t2));
8565       emit_jump_insn (gen_tablejump_internal2 (t3, operands[1]));
8566       DONE;
8567     }
8568 }")
8569
8570 ;; Implement a switch statement when generating embedded PIC code.
8571 ;; Switches are implemented by `tablejump' when not using -membedded-pic.
8572
8573 (define_expand "casesi"
8574   [(set (match_dup 5)
8575         (minus:SI (match_operand:SI 0 "register_operand" "d")
8576                   (match_operand:SI 1 "arith_operand" "dI")))
8577    (set (cc0)
8578         (compare:CC (match_dup 5)
8579                     (match_operand:SI 2 "arith_operand" "")))
8580    (set (pc)
8581         (if_then_else (gtu (cc0)
8582                            (const_int 0))
8583                       (label_ref (match_operand 4 "" ""))
8584                       (pc)))
8585    (parallel
8586     [(set (pc)
8587           (mem:SI (plus:SI (mult:SI (match_dup 5)
8588                                     (const_int 4))
8589                            (label_ref (match_operand 3 "" "")))))
8590      (clobber (match_scratch:SI 6 ""))
8591      (clobber (reg:SI 31))])]
8592   "TARGET_EMBEDDED_PIC"
8593   "
8594 {
8595   if (operands[0])
8596     {
8597       rtx reg = gen_reg_rtx (SImode);
8598
8599       /* If the index is too large, go to the default label.  */
8600       emit_insn (gen_subsi3 (reg, operands[0], operands[1]));
8601       emit_insn (gen_cmpsi (reg, operands[2]));
8602       emit_insn (gen_bgtu (operands[4]));
8603
8604       /* Do the PIC jump.  */
8605       if (Pmode != DImode)
8606         emit_jump_insn (gen_casesi_internal (reg, operands[3],
8607                                              gen_reg_rtx (SImode)));
8608       else
8609         emit_jump_insn (gen_casesi_internal_di (reg, operands[3],
8610                                                 gen_reg_rtx (DImode)));
8611
8612       DONE;
8613     }
8614 }")
8615
8616 ;; An embedded PIC switch statement looks like this:
8617 ;;      bal     $LS1
8618 ;;      sll     $reg,$index,2
8619 ;; $LS1:
8620 ;;      addu    $reg,$reg,$31
8621 ;;      lw      $reg,$L1-$LS1($reg)
8622 ;;      addu    $reg,$reg,$31
8623 ;;      j       $reg
8624 ;; $L1:
8625 ;;      .word   case1-$LS1
8626 ;;      .word   case2-$LS1
8627 ;;      ...
8628
8629 (define_insn "casesi_internal"
8630   [(set (pc)
8631         (mem:SI (plus:SI (mult:SI (match_operand:SI 0 "register_operand" "d")
8632                                   (const_int 4))
8633                          (label_ref (match_operand 1 "" "")))))
8634    (clobber (match_operand:SI 2 "register_operand" "=d"))
8635    (clobber (reg:SI 31))]
8636   "TARGET_EMBEDDED_PIC"
8637   "%(bal\\t%S1\;sll\\t%2,%0,2\\n%~%S1:\;addu\\t%2,%2,$31%)\;\\
8638 lw\\t%2,%1-%S1(%2)\;addu\\t%2,%2,$31\\n\\t%*j\\t%2%/"
8639   [(set_attr "type"     "jump")
8640    (set_attr "mode"     "none")
8641    (set_attr "length"   "24")])
8642
8643 ;; This code assumes that the table index will never be >= 29 bits wide,
8644 ;; which allows the 'sign extend' from SI to DI be a no-op.
8645 (define_insn "casesi_internal_di"
8646   [(set (pc)
8647         (mem:DI (plus:DI (sign_extend:DI
8648                           (mult:SI (match_operand:SI 0 "register_operand" "d")
8649                                   (const_int 8)))
8650                          (label_ref (match_operand 1 "" "")))))
8651    (clobber (match_operand:DI 2 "register_operand" "=d"))
8652    (clobber (reg:DI 31))]
8653   "TARGET_EMBEDDED_PIC"
8654   "%(bal\\t%S1\;sll\\t%2,%0,3\\n%~%S1:\;daddu\\t%2,%2,$31%)\;\\
8655 ld\\t%2,%1-%S1(%2)\;daddu\\t%2,%2,$31\\n\\t%*j\\t%2%/"
8656   [(set_attr "type"     "jump")
8657    (set_attr "mode"     "none")
8658    (set_attr "length"   "24")])
8659
8660 ;; For TARGET_ABICALLS, we save the gp in the jmp_buf as well.
8661 ;; While it is possible to either pull it off the stack (in the
8662 ;; o32 case) or recalculate it given t9 and our target label,
8663 ;; it takes 3 or 4 insns to do so.
8664
8665 (define_expand "builtin_setjmp_setup"
8666   [(use (match_operand 0 "register_operand" ""))]
8667   "TARGET_ABICALLS"
8668   {
8669     rtx addr;
8670
8671     addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
8672     emit_move_insn (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
8673     DONE;
8674   })
8675
8676 ;; Restore the gp that we saved above.  Despite the comment, it seems that
8677 ;; older code did recalculate the gp from $25.  Continue to jump through
8678 ;; $25 for compatibility (we lose nothing by doing so).
8679
8680 (define_expand "builtin_longjmp"
8681   [(use (match_operand 0 "register_operand" "r"))]
8682   "TARGET_ABICALLS"
8683   "
8684 {
8685   /* The elements of the buffer are, in order:  */
8686   int W = GET_MODE_SIZE (Pmode);
8687   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
8688   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
8689   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
8690   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
8691   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
8692   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
8693      The target is bound to be using $28 as the global pointer
8694      but the current function might not be.  */
8695   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
8696
8697   /* This bit is similar to expand_builtin_longjmp except that it
8698      restores $gp as well.  */
8699   emit_move_insn (hard_frame_pointer_rtx, fp);
8700   emit_move_insn (pv, lab);
8701   emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
8702   emit_move_insn (gp, gpv);
8703   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
8704   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
8705   emit_insn (gen_rtx_USE (VOIDmode, gp));
8706   emit_indirect_jump (pv);
8707   DONE;
8708 }")
8709 \f
8710 ;;
8711 ;;  ....................
8712 ;;
8713 ;;      Function prologue/epilogue
8714 ;;
8715 ;;  ....................
8716 ;;
8717
8718 (define_expand "prologue"
8719   [(const_int 1)]
8720   ""
8721   "
8722 {
8723   if (mips_isa >= 0)            /* avoid unused code warnings */
8724     {
8725       mips_expand_prologue ();
8726       DONE;
8727     }
8728 }")
8729
8730 ;; Block any insns from being moved before this point, since the
8731 ;; profiling call to mcount can use various registers that aren't
8732 ;; saved or used to pass arguments.
8733
8734 (define_insn "blockage"
8735   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
8736   ""
8737   ""
8738   [(set_attr "type"     "unknown")
8739    (set_attr "mode"     "none")
8740    (set_attr "length"   "0")])
8741
8742 (define_expand "epilogue"
8743   [(const_int 2)]
8744   ""
8745 {
8746   mips_expand_epilogue (false);
8747   DONE;
8748 })
8749
8750 (define_expand "sibcall_epilogue"
8751   [(const_int 2)]
8752   ""
8753 {
8754   mips_expand_epilogue (true);
8755   DONE;
8756 })
8757
8758 ;; Trivial return.  Make it look like a normal return insn as that
8759 ;; allows jump optimizations to work better .
8760 (define_insn "return"
8761   [(return)]
8762   "mips_can_use_return_insn ()"
8763   "%*j\t$31%/"
8764   [(set_attr "type"     "jump")
8765    (set_attr "mode"     "none")])
8766
8767 ;; Normal return.
8768
8769 (define_insn "return_internal"
8770   [(use (match_operand 0 "pmode_register_operand" ""))
8771    (return)]
8772   ""
8773   "%*j\t%0%/"
8774   [(set_attr "type"     "jump")
8775    (set_attr "mode"     "none")])
8776
8777 ;; When generating embedded PIC code we need to get the address of the
8778 ;; current function.  This specialized instruction does just that.
8779
8780 (define_insn "get_fnaddr"
8781   [(set (match_operand 0 "register_operand" "=d")
8782         (unspec [(match_operand 1 "" "")] UNSPEC_GET_FNADDR))
8783    (clobber (reg:SI 31))]
8784   "TARGET_EMBEDDED_PIC
8785    && GET_CODE (operands[1]) == SYMBOL_REF"
8786   "%($LF%= = . + 8\;bal\\t$LF%=\;nop;la\\t%0,%1-$LF%=%)\;addu\\t%0,%0,$31"
8787   [(set_attr "type"     "call")
8788    (set_attr "mode"     "none")
8789    (set_attr "length"   "20")])
8790
8791 ;; This is used in compiling the unwind routines.
8792 (define_expand "eh_return"
8793   [(use (match_operand 0 "general_operand" ""))]
8794   ""
8795   "
8796 {
8797   enum machine_mode gpr_mode = TARGET_64BIT ? DImode : SImode;
8798
8799   if (GET_MODE (operands[0]) != gpr_mode)
8800     operands[0] = convert_to_mode (gpr_mode, operands[0], 0);
8801   if (TARGET_64BIT)
8802     emit_insn (gen_eh_set_lr_di (operands[0]));
8803   else
8804     emit_insn (gen_eh_set_lr_si (operands[0]));
8805
8806   DONE;
8807 }")
8808
8809 ;; Clobber the return address on the stack.  We can't expand this
8810 ;; until we know where it will be put in the stack frame.
8811
8812 (define_insn "eh_set_lr_si"
8813   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
8814    (clobber (match_scratch:SI 1 "=&d"))]
8815   "! TARGET_64BIT"
8816   "#")
8817
8818 (define_insn "eh_set_lr_di"
8819   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
8820    (clobber (match_scratch:DI 1 "=&d"))]
8821   "TARGET_64BIT"
8822   "#")
8823
8824 (define_split
8825   [(unspec [(match_operand 0 "register_operand" "")] UNSPEC_EH_RETURN)
8826    (clobber (match_scratch 1 ""))]
8827   "reload_completed && !TARGET_DEBUG_D_MODE"
8828   [(const_int 0)]
8829   "
8830 {
8831   mips_set_return_address (operands[0], operands[1]);
8832   DONE;
8833 }")
8834
8835 (define_insn "exception_receiver"
8836   [(set (reg:SI 28)
8837         (unspec_volatile [(const_int 0)] UNSPEC_EH_RECEIVER))]
8838   "TARGET_ABICALLS && (mips_abi == ABI_32 || mips_abi == ABI_O64)"
8839   { return mips_restore_gp (operands); }
8840   [(set_attr "type"   "load")
8841    (set_attr "length" "8")])
8842 \f
8843 ;;
8844 ;;  ....................
8845 ;;
8846 ;;      FUNCTION CALLS
8847 ;;
8848 ;;  ....................
8849
8850 ;; Sibling calls.  All these patterns use direct jumps.
8851
8852 ;; call_insn_operand will only accepts constant addresses if a direct
8853 ;; jump is acceptable.  Since the 'S' constraint is defined in terms of
8854 ;; call_insn_operand, the same is true of the contraints.
8855
8856 ;; When we use an indirect jump, we need a register that will be
8857 ;; preserved by the epilogue.  Since TARGET_ABICALLS forces us to
8858 ;; use $25 for this purpose -- and $25 is never clobbered by the
8859 ;; epilogue -- we might as well use it for !TARGET_ABICALLS as well.
8860
8861 (define_expand "sibcall"
8862   [(parallel [(call (match_operand 0 "" "")
8863                     (match_operand 1 "" ""))
8864               (use (match_operand 2 "" ""))     ;; next_arg_reg
8865               (use (match_operand 3 "" ""))])]  ;; struct_value_size_rtx
8866   "TARGET_SIBCALLS"
8867 {
8868   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
8869   DONE;
8870 })
8871
8872 (define_insn "sibcall_internal"
8873   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
8874          (match_operand 1 "" ""))]
8875   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
8876   "@
8877     %*jr\t%0%/
8878     %*j\t%0%/"
8879   [(set_attr "type" "call")])
8880
8881 (define_expand "sibcall_value"
8882   [(parallel [(set (match_operand 0 "" "")
8883                    (call (match_operand 1 "" "")
8884                          (match_operand 2 "" "")))
8885               (use (match_operand 3 "" ""))])]          ;; next_arg_reg
8886   "TARGET_SIBCALLS"
8887 {
8888   mips_expand_call (operands[0], XEXP (operands[1], 0),
8889                     operands[2], operands[3], true);
8890   DONE;
8891 })
8892
8893 (define_insn "sibcall_value_internal"
8894   [(set (match_operand 0 "register_operand" "=df,df")
8895         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
8896               (match_operand 2 "" "")))]
8897   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
8898   "@
8899     %*jr\t%1%/
8900     %*j\t%1%/"
8901   [(set_attr "type" "call")])
8902
8903 (define_insn "sibcall_value_multiple_internal"
8904   [(set (match_operand 0 "register_operand" "=df,df")
8905         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
8906               (match_operand 2 "" "")))
8907    (set (match_operand 3 "register_operand" "=df,df")
8908         (call (mem:SI (match_dup 1))
8909               (match_dup 2)))]
8910   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
8911   "@
8912     %*jr\t%1%/
8913     %*j\t%1%/"
8914   [(set_attr "type" "call")])
8915
8916 (define_expand "call"
8917   [(parallel [(call (match_operand 0 "" "")
8918                     (match_operand 1 "" ""))
8919               (use (match_operand 2 "" ""))     ;; next_arg_reg
8920               (use (match_operand 3 "" ""))])]  ;; struct_value_size_rtx
8921   ""
8922 {
8923   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
8924   DONE;
8925 })
8926
8927 (define_insn_and_split "call_internal"
8928   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
8929          (match_operand 1 "" ""))
8930    (clobber (reg:SI 31))]
8931   ""
8932   "%*jal\t%0%/"
8933   "reload_completed && TARGET_SPLIT_CALLS"
8934   [(const_int 0)]
8935   {
8936     emit_call_insn (gen_call_split (operands[0], operands[1]));
8937     emit_insn (gen_exception_receiver ());
8938     DONE;
8939   }
8940   [(set_attr "jal" "indirect,direct")
8941    (set_attr "extended_mips16" "no,yes")])
8942
8943 (define_insn "call_split"
8944   [(call (mem:SI (match_operand 0 "call_insn_operand" "c"))
8945          (match_operand 1 "" ""))
8946    (clobber (reg:SI 31))
8947    (const_int 1)]
8948   "TARGET_SPLIT_CALLS"
8949   "%*jalr\t%0%/"
8950   [(set_attr "type" "call")])
8951
8952 (define_expand "call_value"
8953   [(parallel [(set (match_operand 0 "" "")
8954                    (call (match_operand 1 "" "")
8955                          (match_operand 2 "" "")))
8956               (use (match_operand 3 "" ""))])]          ;; next_arg_reg
8957   ""
8958 {
8959   mips_expand_call (operands[0], XEXP (operands[1], 0),
8960                     operands[2], operands[3], false);
8961   DONE;
8962 })
8963
8964 (define_insn_and_split "call_value_internal"
8965   [(set (match_operand 0 "register_operand" "=df,df")
8966         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
8967               (match_operand 2 "" "")))
8968    (clobber (reg:SI 31))]
8969   ""
8970   "%*jal\t%1%/"
8971   "reload_completed && TARGET_SPLIT_CALLS"
8972   [(const_int 0)]
8973   {
8974     emit_call_insn (gen_call_value_split (operands[0], operands[1],
8975                                           operands[2]));
8976     emit_insn (gen_exception_receiver ());
8977     DONE;
8978   }
8979   [(set_attr "jal" "indirect,direct")
8980    (set_attr "extended_mips16" "no,yes")])
8981
8982 (define_insn "call_value_split"
8983   [(set (match_operand 0 "register_operand" "=df")
8984         (call (mem:SI (match_operand 1 "call_insn_operand" "c"))
8985               (match_operand 2 "" "")))
8986    (clobber (reg:SI 31))
8987    (const_int 1)]
8988   "TARGET_SPLIT_CALLS"
8989   "%*jalr\t%1%/"
8990   [(set_attr "type" "call")])
8991
8992 (define_insn_and_split "call_value_multiple_internal"
8993   [(set (match_operand 0 "register_operand" "=df,df")
8994         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
8995               (match_operand 2 "" "")))
8996    (set (match_operand 3 "register_operand" "=df,df")
8997         (call (mem:SI (match_dup 1))
8998               (match_dup 2)))
8999    (clobber (reg:SI 31))]
9000   ""
9001   "%*jal\t%1%/"
9002   "reload_completed && TARGET_SPLIT_CALLS"
9003   [(const_int 0)]
9004   {
9005     emit_call_insn (gen_call_value_multiple_split (operands[0], operands[1],
9006                                                    operands[2], operands[3]));
9007     emit_insn (gen_exception_receiver ());
9008     DONE;
9009   }
9010   [(set_attr "jal" "indirect,direct")
9011    (set_attr "extended_mips16" "no,yes")])
9012
9013 (define_insn "call_value_multiple_split"
9014   [(set (match_operand 0 "register_operand" "=df")
9015         (call (mem:SI (match_operand 1 "call_insn_operand" "c"))
9016               (match_operand 2 "" "")))
9017    (set (match_operand 3 "register_operand" "=df")
9018         (call (mem:SI (match_dup 1))
9019               (match_dup 2)))
9020    (clobber (reg:SI 31))
9021    (const_int 1)]
9022   "TARGET_SPLIT_CALLS"
9023   "%*jalr\t%1%/"
9024   [(set_attr "type" "call")])
9025
9026 ;; Call subroutine returning any type.
9027
9028 (define_expand "untyped_call"
9029   [(parallel [(call (match_operand 0 "" "")
9030                     (const_int 0))
9031               (match_operand 1 "" "")
9032               (match_operand 2 "" "")])]
9033   ""
9034   "
9035 {
9036   int i;
9037
9038   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
9039
9040   for (i = 0; i < XVECLEN (operands[2], 0); i++)
9041     {
9042       rtx set = XVECEXP (operands[2], 0, i);
9043       emit_move_insn (SET_DEST (set), SET_SRC (set));
9044     }
9045
9046   emit_insn (gen_blockage ());
9047   DONE;
9048 }")
9049 \f
9050 ;;
9051 ;;  ....................
9052 ;;
9053 ;;      MISC.
9054 ;;
9055 ;;  ....................
9056 ;;
9057
9058
9059 (define_expand "prefetch"
9060   [(prefetch (match_operand 0 "address_operand" "")
9061              (match_operand 1 "const_int_operand" "")
9062              (match_operand 2 "const_int_operand" ""))]
9063   "ISA_HAS_PREFETCH"
9064 {
9065   if (symbolic_operand (operands[0], GET_MODE (operands[0])))
9066     operands[0] = force_reg (GET_MODE (operands[0]), operands[0]);
9067 })
9068
9069 (define_insn "prefetch_si_address"
9070   [(prefetch (plus:SI (match_operand:SI 0 "register_operand" "r")
9071                       (match_operand:SI 3 "const_int_operand" "i"))
9072              (match_operand:SI 1 "const_int_operand" "n")
9073              (match_operand:SI 2 "const_int_operand" "n"))]
9074   "ISA_HAS_PREFETCH && Pmode == SImode"
9075   "* return mips_emit_prefetch (operands);"
9076   [(set_attr "type" "prefetch")])
9077
9078 (define_insn "prefetch_si"
9079   [(prefetch (match_operand:SI 0 "register_operand" "r")
9080              (match_operand:SI 1 "const_int_operand" "n")
9081              (match_operand:SI 2 "const_int_operand" "n"))]
9082   "ISA_HAS_PREFETCH && Pmode == SImode"
9083   "* return mips_emit_prefetch (operands);"
9084   [(set_attr "type" "prefetch")])
9085
9086 (define_insn "prefetch_di_address"
9087   [(prefetch (plus:DI (match_operand:DI 0 "register_operand" "r")
9088                       (match_operand:DI 3 "const_int_operand" "i"))
9089              (match_operand:DI 1 "const_int_operand" "n")
9090              (match_operand:DI 2 "const_int_operand" "n"))]
9091   "ISA_HAS_PREFETCH && Pmode == DImode"
9092   "* return mips_emit_prefetch (operands);"
9093   [(set_attr "type" "prefetch")])
9094
9095 (define_insn "prefetch_di"
9096   [(prefetch (match_operand:DI 0 "register_operand" "r")
9097              (match_operand:DI 1 "const_int_operand" "n")
9098              (match_operand:DI 2 "const_int_operand" "n"))]
9099   "ISA_HAS_PREFETCH && Pmode == DImode"
9100   "* return mips_emit_prefetch (operands);"
9101   [(set_attr "type" "prefetch")])
9102
9103 (define_insn "nop"
9104   [(const_int 0)]
9105   ""
9106   "%(nop%)"
9107   [(set_attr "type"     "nop")
9108    (set_attr "mode"     "none")])
9109
9110 ;; Like nop, but commented out when outside a .set noreorder block.
9111 (define_insn "hazard_nop"
9112   [(const_int 1)]
9113   ""
9114   {
9115     if (set_noreorder)
9116       return "nop";
9117     else
9118       return "#nop";
9119   }
9120   [(set_attr "type"     "arith")])
9121
9122 ;; The MIPS chip does not seem to require stack probes.
9123 ;;
9124 ;; (define_expand "probe"
9125 ;;   [(set (match_dup 0)
9126 ;;      (match_dup 1))]
9127 ;;   ""
9128 ;;   "
9129 ;; {
9130 ;;   operands[0] = gen_reg_rtx (SImode);
9131 ;;   operands[1] = gen_rtx_MEM (SImode, stack_pointer_rtx);
9132 ;;   MEM_VOLATILE_P (operands[1]) = TRUE;
9133 ;;
9134 ;;   /* fall through and generate default code */
9135 ;; }")
9136 ;;
9137 \f
9138 ;;
9139 ;; MIPS4 Conditional move instructions.
9140
9141 (define_insn ""
9142   [(set (match_operand:SI 0 "register_operand" "=d,d")
9143         (if_then_else:SI
9144          (match_operator 4 "equality_op"
9145                          [(match_operand:SI 1 "register_operand" "d,d")
9146                           (const_int 0)])
9147          (match_operand:SI 2 "reg_or_0_operand" "dJ,0")
9148          (match_operand:SI 3 "reg_or_0_operand" "0,dJ")))]
9149   "ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE"
9150   "@
9151     mov%B4\\t%0,%z2,%1
9152     mov%b4\\t%0,%z3,%1"
9153   [(set_attr "type" "move")
9154    (set_attr "mode" "SI")])
9155
9156 (define_insn ""
9157   [(set (match_operand:SI 0 "register_operand" "=d,d")
9158         (if_then_else:SI
9159          (match_operator 4 "equality_op"
9160                          [(match_operand:DI 1 "register_operand" "d,d")
9161                           (const_int 0)])
9162          (match_operand:SI 2 "reg_or_0_operand" "dJ,0")
9163          (match_operand:SI 3 "reg_or_0_operand" "0,dJ")))]
9164   "ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE"
9165   "@
9166     mov%B4\\t%0,%z2,%1
9167     mov%b4\\t%0,%z3,%1"
9168   [(set_attr "type" "move")
9169    (set_attr "mode" "SI")])
9170
9171 (define_insn ""
9172   [(set (match_operand:SI 0 "register_operand" "=d,d")
9173         (if_then_else:SI
9174          (match_operator 3 "equality_op" [(match_operand:CC 4
9175                                                             "register_operand"
9176                                                             "z,z")
9177                                           (const_int 0)])
9178          (match_operand:SI 1 "reg_or_0_operand" "dJ,0")
9179          (match_operand:SI 2 "reg_or_0_operand" "0,dJ")))]
9180   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
9181   "@
9182     mov%T3\\t%0,%z1,%4
9183     mov%t3\\t%0,%z2,%4"
9184   [(set_attr "type" "move")
9185    (set_attr "mode" "SI")])
9186
9187 (define_insn ""
9188   [(set (match_operand:DI 0 "register_operand" "=d,d")
9189         (if_then_else:DI
9190          (match_operator 4 "equality_op"
9191                          [(match_operand:SI 1 "register_operand" "d,d")
9192                           (const_int 0)])
9193          (match_operand:DI 2 "reg_or_0_operand" "dJ,0")
9194          (match_operand:DI 3 "reg_or_0_operand" "0,dJ")))]
9195   "(ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE) && TARGET_64BIT"
9196   "@
9197     mov%B4\\t%0,%z2,%1
9198     mov%b4\\t%0,%z3,%1"
9199   [(set_attr "type" "move")
9200    (set_attr "mode" "DI")])
9201
9202 (define_insn ""
9203   [(set (match_operand:DI 0 "register_operand" "=d,d")
9204         (if_then_else:DI
9205          (match_operator 4 "equality_op"
9206                          [(match_operand:DI 1 "register_operand" "d,d")
9207                           (const_int 0)])
9208          (match_operand:DI 2 "reg_or_0_operand" "dJ,0")
9209          (match_operand:DI 3 "reg_or_0_operand" "0,dJ")))]
9210   "(ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE) && TARGET_64BIT"
9211   "@
9212     mov%B4\\t%0,%z2,%1
9213     mov%b4\\t%0,%z3,%1"
9214   [(set_attr "type" "move")
9215    (set_attr "mode" "DI")])
9216
9217 (define_insn ""
9218   [(set (match_operand:DI 0 "register_operand" "=d,d")
9219         (if_then_else:DI
9220          (match_operator 3 "equality_op" [(match_operand:CC 4
9221                                                             "register_operand"
9222                                                             "z,z")
9223                                           (const_int 0)])
9224          (match_operand:DI 1 "reg_or_0_operand" "dJ,0")
9225          (match_operand:DI 2 "reg_or_0_operand" "0,dJ")))]
9226   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_64BIT"
9227   "@
9228     mov%T3\\t%0,%z1,%4
9229     mov%t3\\t%0,%z2,%4"
9230   [(set_attr "type" "move")
9231    (set_attr "mode" "DI")])
9232
9233 (define_insn ""
9234   [(set (match_operand:SF 0 "register_operand" "=f,f")
9235         (if_then_else:SF
9236          (match_operator 4 "equality_op"
9237                          [(match_operand:SI 1 "register_operand" "d,d")
9238                           (const_int 0)])
9239          (match_operand:SF 2 "register_operand" "f,0")
9240          (match_operand:SF 3 "register_operand" "0,f")))]
9241   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
9242   "@
9243     mov%B4.s\\t%0,%2,%1
9244     mov%b4.s\\t%0,%3,%1"
9245   [(set_attr "type" "move")
9246    (set_attr "mode" "SF")])
9247
9248 (define_insn ""
9249   [(set (match_operand:SF 0 "register_operand" "=f,f")
9250         (if_then_else:SF
9251          (match_operator 4 "equality_op"
9252                          [(match_operand:DI 1 "register_operand" "d,d")
9253                           (const_int 0)])
9254          (match_operand:SF 2 "register_operand" "f,0")
9255          (match_operand:SF 3 "register_operand" "0,f")))]
9256   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
9257   "@
9258     mov%B4.s\\t%0,%2,%1
9259     mov%b4.s\\t%0,%3,%1"
9260   [(set_attr "type" "move")
9261    (set_attr "mode" "SF")])
9262
9263 (define_insn ""
9264   [(set (match_operand:SF 0 "register_operand" "=f,f")
9265         (if_then_else:SF
9266          (match_operator 3 "equality_op" [(match_operand:CC 4
9267                                                             "register_operand"
9268                                                             "z,z")
9269                                           (const_int 0)])
9270          (match_operand:SF 1 "register_operand" "f,0")
9271          (match_operand:SF 2 "register_operand" "0,f")))]
9272   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
9273   "@
9274     mov%T3.s\\t%0,%1,%4
9275     mov%t3.s\\t%0,%2,%4"
9276   [(set_attr "type" "move")
9277    (set_attr "mode" "SF")])
9278
9279 (define_insn ""
9280   [(set (match_operand:DF 0 "register_operand" "=f,f")
9281         (if_then_else:DF
9282          (match_operator 4 "equality_op"
9283                          [(match_operand:SI 1 "register_operand" "d,d")
9284                           (const_int 0)])
9285          (match_operand:DF 2 "register_operand" "f,0")
9286          (match_operand:DF 3 "register_operand" "0,f")))]
9287   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9288   "@
9289     mov%B4.d\\t%0,%2,%1
9290     mov%b4.d\\t%0,%3,%1"
9291   [(set_attr "type" "move")
9292    (set_attr "mode" "DF")])
9293
9294 (define_insn ""
9295   [(set (match_operand:DF 0 "register_operand" "=f,f")
9296         (if_then_else:DF
9297          (match_operator 4 "equality_op"
9298                          [(match_operand:DI 1 "register_operand" "d,d")
9299                           (const_int 0)])
9300          (match_operand:DF 2 "register_operand" "f,0")
9301          (match_operand:DF 3 "register_operand" "0,f")))]
9302   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9303   "@
9304     mov%B4.d\\t%0,%2,%1
9305     mov%b4.d\\t%0,%3,%1"
9306   [(set_attr "type" "move")
9307    (set_attr "mode" "DF")])
9308
9309 (define_insn ""
9310   [(set (match_operand:DF 0 "register_operand" "=f,f")
9311         (if_then_else:DF
9312          (match_operator 3 "equality_op" [(match_operand:CC 4
9313                                                             "register_operand"
9314                                                             "z,z")
9315                                           (const_int 0)])
9316          (match_operand:DF 1 "register_operand" "f,0")
9317          (match_operand:DF 2 "register_operand" "0,f")))]
9318   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9319   "@
9320     mov%T3.d\\t%0,%1,%4
9321     mov%t3.d\\t%0,%2,%4"
9322   [(set_attr "type" "move")
9323    (set_attr "mode" "DF")])
9324
9325 ;; These are the main define_expand's used to make conditional moves.
9326
9327 (define_expand "movsicc"
9328   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
9329    (set (match_operand:SI 0 "register_operand" "")
9330         (if_then_else:SI (match_dup 5)
9331                          (match_operand:SI 2 "reg_or_0_operand" "")
9332                          (match_operand:SI 3 "reg_or_0_operand" "")))]
9333   "ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE"
9334   "
9335 {
9336   gen_conditional_move (operands);
9337   DONE;
9338 }")
9339
9340 (define_expand "movdicc"
9341   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
9342    (set (match_operand:DI 0 "register_operand" "")
9343         (if_then_else:DI (match_dup 5)
9344                          (match_operand:DI 2 "reg_or_0_operand" "")
9345                          (match_operand:DI 3 "reg_or_0_operand" "")))]
9346   "(ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE) && TARGET_64BIT"
9347   "
9348 {
9349   gen_conditional_move (operands);
9350   DONE;
9351 }")
9352
9353 (define_expand "movsfcc"
9354   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
9355    (set (match_operand:SF 0 "register_operand" "")
9356         (if_then_else:SF (match_dup 5)
9357                          (match_operand:SF 2 "register_operand" "")
9358                          (match_operand:SF 3 "register_operand" "")))]
9359   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
9360   "
9361 {
9362   gen_conditional_move (operands);
9363   DONE;
9364 }")
9365
9366 (define_expand "movdfcc"
9367   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
9368    (set (match_operand:DF 0 "register_operand" "")
9369         (if_then_else:DF (match_dup 5)
9370                          (match_operand:DF 2 "register_operand" "")
9371                          (match_operand:DF 3 "register_operand" "")))]
9372   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9373   "
9374 {
9375   gen_conditional_move (operands);
9376   DONE;
9377 }")
9378 \f
9379 ;;
9380 ;;  ....................
9381 ;;
9382 ;;      mips16 inline constant tables
9383 ;;
9384 ;;  ....................
9385 ;;
9386
9387 (define_insn "consttable_qi"
9388   [(unspec_volatile [(match_operand:QI 0 "consttable_operand" "=g")]
9389                     UNSPEC_CONSTTABLE_QI)]
9390   "TARGET_MIPS16"
9391   "*
9392 {
9393   assemble_integer (operands[0], 1, BITS_PER_UNIT, 1);
9394   return \"\";
9395 }"
9396   [(set_attr "type"     "unknown")
9397    (set_attr "mode"     "QI")
9398    (set_attr "length"   "8")])
9399
9400 (define_insn "consttable_hi"
9401   [(unspec_volatile [(match_operand:HI 0 "consttable_operand" "=g")]
9402                     UNSPEC_CONSTTABLE_HI)]
9403   "TARGET_MIPS16"
9404   "*
9405 {
9406   assemble_integer (operands[0], 2, BITS_PER_UNIT * 2, 1);
9407   return \"\";
9408 }"
9409   [(set_attr "type"     "unknown")
9410    (set_attr "mode"     "HI")
9411    (set_attr "length"   "8")])
9412
9413 (define_insn "consttable_si"
9414   [(unspec_volatile [(match_operand:SI 0 "consttable_operand" "=g")]
9415                     UNSPEC_CONSTTABLE_SI)]
9416   "TARGET_MIPS16"
9417   "*
9418 {
9419   assemble_integer (operands[0], 4, BITS_PER_UNIT * 4, 1);
9420   return \"\";
9421 }"
9422   [(set_attr "type"     "unknown")
9423    (set_attr "mode"     "SI")
9424    (set_attr "length"   "8")])
9425
9426 (define_insn "consttable_di"
9427   [(unspec_volatile [(match_operand:DI 0 "consttable_operand" "=g")]
9428                     UNSPEC_CONSTTABLE_DI)]
9429   "TARGET_MIPS16"
9430   "*
9431 {
9432   assemble_integer (operands[0], 8, BITS_PER_UNIT * 8, 1);
9433   return \"\";
9434 }"
9435   [(set_attr "type"     "unknown")
9436    (set_attr "mode"     "DI")
9437    (set_attr "length"   "16")])
9438
9439 (define_insn "consttable_sf"
9440   [(unspec_volatile [(match_operand:SF 0 "consttable_operand" "=g")]
9441                     UNSPEC_CONSTTABLE_SF)]
9442   "TARGET_MIPS16"
9443   "*
9444 {
9445   REAL_VALUE_TYPE d;
9446
9447   if (GET_CODE (operands[0]) != CONST_DOUBLE)
9448     abort ();
9449   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
9450   assemble_real (d, SFmode, GET_MODE_ALIGNMENT (SFmode));
9451   return \"\";
9452 }"
9453   [(set_attr "type"     "unknown")
9454    (set_attr "mode"     "SF")
9455    (set_attr "length"   "8")])
9456
9457 (define_insn "consttable_df"
9458   [(unspec_volatile [(match_operand:DF 0 "consttable_operand" "=g")]
9459                     UNSPEC_CONSTTABLE_DF)]
9460   "TARGET_MIPS16"
9461   "*
9462 {
9463   REAL_VALUE_TYPE d;
9464
9465   if (GET_CODE (operands[0]) != CONST_DOUBLE)
9466     abort ();
9467   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
9468   assemble_real (d, DFmode, GET_MODE_ALIGNMENT (DFmode));
9469   return \"\";
9470 }"
9471   [(set_attr "type"     "unknown")
9472    (set_attr "mode"     "DF")
9473    (set_attr "length"   "16")])
9474
9475 (define_insn "align_2"
9476   [(unspec_volatile [(const_int 0)] UNSPEC_ALIGN_2)]
9477   "TARGET_MIPS16"
9478   ".align 1"
9479   [(set_attr "type"     "unknown")
9480    (set_attr "mode"     "HI")
9481    (set_attr "length"   "8")])
9482
9483 (define_insn "align_4"
9484   [(unspec_volatile [(const_int 0)] UNSPEC_ALIGN_4)]
9485   "TARGET_MIPS16"
9486   ".align 2"
9487   [(set_attr "type"     "unknown")
9488    (set_attr "mode"     "SI")
9489    (set_attr "length"   "8")])
9490
9491 (define_insn "align_8"
9492   [(unspec_volatile [(const_int 0)] UNSPEC_ALIGN_8)]
9493   "TARGET_MIPS16"
9494   ".align 3"
9495   [(set_attr "type"     "unknown")
9496    (set_attr "mode"     "DI")
9497    (set_attr "length"   "12")])
9498 \f
9499 ;;
9500 ;;  ....................
9501 ;;
9502 ;;      mips16 peepholes
9503 ;;
9504 ;;  ....................
9505 ;;
9506
9507 ;; On the mips16, reload will sometimes decide that a pseudo register
9508 ;; should go into $24, and then later on have to reload that register.
9509 ;; When that happens, we get a load of a general register followed by
9510 ;; a move from the general register to $24 followed by a branch.
9511 ;; These peepholes catch the common case, and fix it to just use the
9512 ;; general register for the branch.
9513
9514 (define_peephole
9515   [(set (match_operand:SI 0 "register_operand" "=t")
9516         (match_operand:SI 1 "register_operand" "d"))
9517    (set (pc)
9518         (if_then_else (match_operator:SI 2 "equality_op" [(match_dup 0)
9519                                                           (const_int 0)])
9520                       (match_operand 3 "pc_or_label_operand" "")
9521                       (match_operand 4 "pc_or_label_operand" "")))]
9522   "TARGET_MIPS16
9523    && GET_CODE (operands[0]) == REG
9524    && REGNO (operands[0]) == 24
9525    && dead_or_set_p (insn, operands[0])
9526    && GET_CODE (operands[1]) == REG
9527    && M16_REG_P (REGNO (operands[1]))"
9528   "*
9529 {
9530   if (operands[3] != pc_rtx)
9531     return \"b%C2z\\t%1,%3\";
9532   else
9533     return \"b%N2z\\t%1,%4\";
9534 }"
9535   [(set_attr "type"     "branch")
9536    (set_attr "mode"     "none")
9537    (set_attr "length"   "8")])
9538
9539 (define_peephole
9540   [(set (match_operand:DI 0 "register_operand" "=t")
9541         (match_operand:DI 1 "register_operand" "d"))
9542    (set (pc)
9543         (if_then_else (match_operator:DI 2 "equality_op" [(match_dup 0)
9544                                                           (const_int 0)])
9545                       (match_operand 3 "pc_or_label_operand" "")
9546                       (match_operand 4 "pc_or_label_operand" "")))]
9547   "TARGET_MIPS16 && TARGET_64BIT
9548    && GET_CODE (operands[0]) == REG
9549    && REGNO (operands[0]) == 24
9550    && dead_or_set_p (insn, operands[0])
9551    && GET_CODE (operands[1]) == REG
9552    && M16_REG_P (REGNO (operands[1]))"
9553   "*
9554 {
9555   if (operands[3] != pc_rtx)
9556     return \"b%C2z\\t%1,%3\";
9557   else
9558     return \"b%N2z\\t%1,%4\";
9559 }"
9560   [(set_attr "type"     "branch")
9561    (set_attr "mode"     "none")
9562    (set_attr "length"   "8")])
9563
9564 ;; We can also have the reverse reload: reload will spill $24 into
9565 ;; another register, and then do a branch on that register when it
9566 ;; could have just stuck with $24.
9567
9568 (define_peephole
9569   [(set (match_operand:SI 0 "register_operand" "=d")
9570         (match_operand:SI 1 "register_operand" "t"))
9571    (set (pc)
9572         (if_then_else (match_operator:SI 2 "equality_op" [(match_dup 0)
9573                                                           (const_int 0)])
9574                       (match_operand 3 "pc_or_label_operand" "")
9575                       (match_operand 4 "pc_or_label_operand" "")))]
9576   "TARGET_MIPS16
9577    && GET_CODE (operands[1]) == REG
9578    && REGNO (operands[1]) == 24
9579    && GET_CODE (operands[0]) == REG
9580    && M16_REG_P (REGNO (operands[0]))
9581    && dead_or_set_p (insn, operands[0])"
9582   "*
9583 {
9584   if (operands[3] != pc_rtx)
9585     return \"bt%C2z\\t%3\";
9586   else
9587     return \"bt%N2z\\t%4\";
9588 }"
9589   [(set_attr "type"     "branch")
9590    (set_attr "mode"     "none")
9591    (set_attr "length"   "8")])
9592
9593 (define_peephole
9594   [(set (match_operand:DI 0 "register_operand" "=d")
9595         (match_operand:DI 1 "register_operand" "t"))
9596    (set (pc)
9597         (if_then_else (match_operator:DI 2 "equality_op" [(match_dup 0)
9598                                                           (const_int 0)])
9599                       (match_operand 3 "pc_or_label_operand" "")
9600                       (match_operand 4 "pc_or_label_operand" "")))]
9601   "TARGET_MIPS16 && TARGET_64BIT
9602    && GET_CODE (operands[1]) == REG
9603    && REGNO (operands[1]) == 24
9604    && GET_CODE (operands[0]) == REG
9605    && M16_REG_P (REGNO (operands[0]))
9606    && dead_or_set_p (insn, operands[0])"
9607   "*
9608 {
9609   if (operands[3] != pc_rtx)
9610     return \"bt%C2z\\t%3\";
9611   else
9612     return \"bt%N2z\\t%4\";
9613 }"
9614   [(set_attr "type"     "branch")
9615    (set_attr "mode"     "none")
9616    (set_attr "length"   "8")])