OSDN Git Service

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