OSDN Git Service

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