OSDN Git Service

c91d27f14f419421076496971cbff11fb09bc923
[pf3gnuchains/gcc-fork.git] / gcc / config / mips / mips.md
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;;  1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
5 ;;  Changes by       Michael Meissner, meissner@osf.org
6 ;;  64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 ;;  Brendan Eich, brendan@microunity.com.
8
9 ;; This file is part of GNU CC.
10
11 ;; GNU CC is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU CC is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU CC; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;; ??? Currently does not have define_function_unit support for the R8000.
27 ;; Must include new entries for fmadd in addition to existing entries.
28
29 (define_constants
30   [(UNSPEC_LOAD_DF_LOW           0)
31    (UNSPEC_LOAD_DF_HIGH          1)
32    (UNSPEC_STORE_DF_HIGH         2)
33    (UNSPEC_GET_FNADDR            4)
34    (UNSPEC_HILO_DELAY            5)
35    (UNSPEC_BLOCKAGE              6)
36    (UNSPEC_LOADGP                7)
37    (UNSPEC_SETJMP                8)
38    (UNSPEC_LONGJMP               9)
39    (UNSPEC_EH_RECEIVER          10)
40    (UNSPEC_EH_RETURN            11)
41    (UNSPEC_CONSTTABLE_QI        12)
42    (UNSPEC_CONSTTABLE_HI        13)
43    (UNSPEC_CONSTTABLE_SI        14)
44    (UNSPEC_CONSTTABLE_DI        15)
45    (UNSPEC_CONSTTABLE_SF        16)
46    (UNSPEC_CONSTTABLE_DF        17)
47    (UNSPEC_ALIGN_2              18)
48    (UNSPEC_ALIGN_4              19)
49    (UNSPEC_ALIGN_8              20)
50    (UNSPEC_HIGH                 22)
51    (UNSPEC_LWL                  23)
52    (UNSPEC_LWR                  24)
53    (UNSPEC_SWL                  25)
54    (UNSPEC_SWR                  26)
55    (UNSPEC_LDL                  27)
56    (UNSPEC_LDR                  28)
57    (UNSPEC_SDL                  29)
58    (UNSPEC_SDR                  30)
59
60    ;; Constants used in relocation unspecs.  RELOC_GOT_PAGE and RELOC_GOT_DISP
61    ;; are really only available for n32 and n64.  However, it is convenient
62    ;; to reuse them for SVR4 PIC, where they represent the local and global
63    ;; forms of R_MIPS_GOT16.
64    (RELOC_GPREL16               100)
65    (RELOC_GOT_HI                101)
66    (RELOC_GOT_LO                102)
67    (RELOC_GOT_PAGE              103)
68    (RELOC_GOT_DISP              104)
69    (RELOC_CALL16                105)
70    (RELOC_CALL_HI               106)
71    (RELOC_CALL_LO               107)])
72 \f
73
74 ;; ....................
75 ;;
76 ;;      Attributes
77 ;;
78 ;; ....................
79
80 ;; For jal instructions, this attribute is DIRECT when the target address
81 ;; is symbolic and INDIRECT when it is a register.
82 (define_attr "jal" "unset,direct,indirect"
83   (const_string "unset"))
84
85 ;; True for multi-instruction jal macros.  jal is always a macro
86 ;; in SVR4 PIC since it includes an instruction to restore $gp.
87 ;; Direct jals are also macros in NewABI PIC since they load the
88 ;; target address into $25.
89 (define_attr "jal_macro" "no,yes"
90   (cond [(eq_attr "jal" "direct")
91          (symbol_ref "TARGET_ABICALLS != 0")
92          (eq_attr "jal" "indirect")
93          (symbol_ref "(TARGET_ABICALLS && !TARGET_NEWABI) != 0")]
94         (const_string "no")))
95
96 ;; Classification of each insn.
97 ;; branch       conditional branch
98 ;; jump         unconditional jump
99 ;; call         unconditional call
100 ;; load         load instruction(s)
101 ;; store        store instruction(s)
102 ;; prefetch     memory prefetch
103 ;; move         data movement within same register set
104 ;; xfer         transfer to/from coprocessor
105 ;; hilo         transfer of hi/lo registers
106 ;; arith        integer arithmetic instruction
107 ;; darith       double precision integer arithmetic instructions
108 ;; const        load constant
109 ;; imul         integer multiply
110 ;; imadd        integer multiply-add
111 ;; idiv         integer divide
112 ;; icmp         integer compare
113 ;; fadd         floating point add/subtract
114 ;; fmul         floating point multiply
115 ;; fmadd        floating point multiply-add
116 ;; fdiv         floating point divide
117 ;; fabs         floating point absolute value
118 ;; fneg         floating point negation
119 ;; fcmp         floating point compare
120 ;; fcvt         floating point convert
121 ;; fsqrt        floating point square root
122 ;; frsqrt       floating point reciprocal square root
123 ;; multi        multiword sequence (or user asm statements)
124 ;; nop          no operation
125 (define_attr "type"
126   "unknown,branch,jump,call,load,store,prefetch,move,xfer,hilo,const,arith,darith,imul,imadd,idiv,icmp,fadd,fmul,fmadd,fdiv,fabs,fneg,fcmp,fcvt,fsqrt,frsqrt,multi,nop"
127   (cond [(eq_attr "jal" "!unset")
128          (const_string "call")]
129         (const_string "unknown")))
130
131 ;; Main data type used by the insn
132 (define_attr "mode" "unknown,none,QI,HI,SI,DI,SF,DF,FPSW" (const_string "unknown"))
133
134 ;; Is this an extended instruction in mips16 mode?
135 (define_attr "extended_mips16" "no,yes"
136   (const_string "no"))
137
138 ;; Length (in # of bytes).  A conditional branch is allowed only to a
139 ;; location within a signed 18-bit offset of the delay slot.  If that
140 ;; provides too smal a range, we use the `j' instruction.  This
141 ;; instruction takes a 28-bit value, but that value is not an offset.
142 ;; Instead, it's bitwise-ored with the high-order four bits of the
143 ;; instruction in the delay slot, which means it cannot be used to
144 ;; cross a 256MB boundary.  We could fall back back on the jr,
145 ;; instruction which allows full access to the entire address space,
146 ;; but we do not do so at present.
147
148 (define_attr "length" ""
149    (cond [(eq_attr "type" "branch")
150           (cond [(lt (abs (minus (match_dup 1) (plus (pc) (const_int 4))))
151                      (const_int 131072))
152                  (const_int 4)
153                  (ne (symbol_ref "flag_pic && ! TARGET_EMBEDDED_PIC")
154                      (const_int 0))
155                  (const_int 24)
156                  ] (const_int 12))
157           (eq_attr "type" "const")
158           (symbol_ref "mips_const_insns (operands[1]) * 4")
159           (eq_attr "type" "load")
160           (symbol_ref "mips_fetch_insns (operands[1]) * 4")
161           (eq_attr "type" "store")
162           (symbol_ref "mips_fetch_insns (operands[0]) * 4")
163           ;; In the worst case, a call macro will take 8 instructions:
164           ;;
165           ;;     lui $25,%call_hi(FOO)
166           ;;     addu $25,$25,$28
167           ;;     lw $25,%call_lo(FOO)($25)
168           ;;     nop
169           ;;     jalr $25
170           ;;     nop
171           ;;     lw $gp,X($sp)
172           ;;     nop
173           (eq_attr "jal_macro" "yes")
174           (const_int 32)
175           (and (eq_attr "extended_mips16" "yes")
176                (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
177           (const_int 8)
178           ] (const_int 4)))
179
180 ;; Attribute describing the processor.  This attribute must match exactly
181 ;; with the processor_type enumeration in mips.h.
182
183 ;; Attribute describing the processor
184 ;; (define_attr "cpu" "default,r3000,r6000,r4000"
185 ;;   (const
186 ;;    (cond [(eq (symbol_ref "mips_cpu") (symbol_ref "PROCESSOR_R3000"))   (const_string "r3000")
187 ;;           (eq (symbol_ref "mips_cpu") (symbol_ref "PROCESSOR_R4000"))   (const_string "r4000")
188 ;;           (eq (symbol_ref "mips_cpu") (symbol_ref "PROCESSOR_R6000"))   (const_string "r6000")]
189 ;;          (const_string "default"))))
190
191 ;; ??? Fix everything that tests this attribute.
192 (define_attr "cpu"
193   "default,4kc,5kc,20kc,m4k,r3000,r3900,r6000,r4000,r4100,r4111,r4120,r4300,r4600,r4650,r5000,r5400,r5500,r8000,sb1,sr71000"
194   (const (symbol_ref "mips_cpu_attr")))
195
196 ;; The type of hardware hazard associated with this instruction.
197 ;; DELAY means that the next instruction cannot read the result
198 ;; of this one.  HILO means that the next two instructions cannot
199 ;; write to HI or LO.
200 (define_attr "hazard" "none,delay,hilo"
201   (cond [(and (eq_attr "type" "load")
202               (ne (symbol_ref "ISA_HAS_LOAD_DELAY") (const_int 0)))
203          (const_string "delay")
204
205          (and (eq_attr "type" "xfer")
206               (ne (symbol_ref "ISA_HAS_XFER_DELAY") (const_int 0)))
207          (const_string "delay")
208
209          (and (eq_attr "type" "fcmp")
210               (ne (symbol_ref "ISA_HAS_FCMP_DELAY") (const_int 0)))
211          (const_string "delay")
212
213          ;; The r4000 multiplication patterns include an mflo instruction.
214          (and (eq_attr "type" "imul")
215               (ne (symbol_ref "TARGET_MIPS4000") (const_int 0)))
216          (const_string "hilo")
217
218          (and (eq_attr "type" "hilo")
219               (and (eq (symbol_ref "ISA_HAS_HILO_INTERLOCKS") (const_int 0))
220                    (match_operand 1 "hilo_operand" "")))
221          (const_string "hilo")]
222         (const_string "none")))
223
224 ;; Is it a single instruction?
225 (define_attr "single_insn" "no,yes"
226   (symbol_ref "get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)"))
227
228 ;; Can the instruction be put into a delay slot?
229 (define_attr "can_delay" "no,yes"
230   (if_then_else (and (eq_attr "type" "!branch,call,jump")
231                      (and (eq_attr "hazard" "none")
232                           (eq_attr "single_insn" "yes")))
233                 (const_string "yes")
234                 (const_string "no")))
235
236 ;; Attribute defining whether or not we can use the branch-likely instructions
237
238 (define_attr "branch_likely" "no,yes"
239   (const
240    (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
241                  (const_string "yes")
242                  (const_string "no"))))
243
244
245 ;; Describe a user's asm statement.
246 (define_asm_attributes
247   [(set_attr "type" "multi")])
248
249 \f
250
251 ;; .........................
252 ;;
253 ;;      Delay slots, can't describe load/fcmp/xfer delay slots here
254 ;;
255 ;; .........................
256
257 (define_delay (and (eq_attr "type" "branch")
258                    (eq (symbol_ref "mips16") (const_int 0)))
259   [(eq_attr "can_delay" "yes")
260    (nil)
261    (and (eq_attr "branch_likely" "yes")
262         (eq_attr "can_delay" "yes"))])
263
264 (define_delay (eq_attr "type" "jump")
265   [(eq_attr "can_delay" "yes")
266    (nil)
267    (nil)])
268
269 (define_delay (and (eq_attr "type" "call")
270                    (eq_attr "jal_macro" "no"))
271   [(eq_attr "can_delay" "yes")
272    (nil)
273    (nil)])
274
275 \f
276
277 ;; .........................
278 ;;
279 ;;      Functional units
280 ;;
281 ;; .........................
282
283 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
284 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
285
286 ;; Make the default case (PROCESSOR_DEFAULT) handle the worst case
287
288 (define_function_unit "memory" 1 0
289   (and (eq_attr "type" "load")
290        (eq_attr "cpu" "!r3000,r3900,r4600,r4650,r4100,r4120,r4300,r5000"))
291   3 0)
292
293 (define_function_unit "memory" 1 0
294   (and (eq_attr "type" "load")
295        (eq_attr "cpu" "r3000,r3900,r4600,r4650,r4100,r4120,r4300,r5000"))
296   2 0)
297
298 (define_function_unit "memory"   1 0 (eq_attr "type" "store") 1 0)
299
300 (define_function_unit "memory"   1 0 (eq_attr "type" "xfer") 2 0)
301
302 (define_function_unit "imuldiv"  1 0
303   (eq_attr "type" "hilo")
304   1 3)
305
306 (define_function_unit "imuldiv"  1 0
307   (and (eq_attr "type" "imul,imadd")
308        (eq_attr "cpu" "!r3000,r3900,r4000,r4600,r4650,r4100,r4120,r4300,r5000"))
309   17 17)
310
311 ;; On them mips16, we want to stronly discourage a mult from appearing
312 ;; after an mflo, since that requires explicit nop instructions.  We
313 ;; do this by pretending that mflo ties up the function unit for long
314 ;; enough that the scheduler will ignore load stalls and the like when
315 ;; selecting instructions to between the two instructions.
316
317 (define_function_unit "imuldiv" 1 0
318   (and (eq_attr "type" "hilo") (ne (symbol_ref "mips16") (const_int 0)))
319   1 5)
320
321 (define_function_unit "imuldiv"  1 0
322   (and (eq_attr "type" "imul,imadd") (eq_attr "cpu" "r3000,r3900"))
323   12 12)
324
325 (define_function_unit "imuldiv"  1 0
326   (and (eq_attr "type" "imul,imadd") (eq_attr "cpu" "r4000,r4600"))
327   10 10)
328
329 (define_function_unit "imuldiv"  1 0
330   (and (eq_attr "type" "imul,imadd") (eq_attr "cpu" "r4650"))
331   4 4)
332
333 (define_function_unit "imuldiv"  1 0
334   (and (eq_attr "type" "imul,imadd")
335        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4100,r4120")))
336   1 1)
337
338 (define_function_unit "imuldiv"  1 0
339   (and (eq_attr "type" "imul,imadd")
340        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4100,r4120")))
341   4 4)
342
343 (define_function_unit "imuldiv"  1 0
344   (and (eq_attr "type" "imul,imadd")
345        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4300,r5000")))
346   5 5)
347
348 (define_function_unit "imuldiv"  1 0
349   (and (eq_attr "type" "imul,imadd")
350        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4300")))
351   8 8)
352
353 (define_function_unit "imuldiv"  1 0
354   (and (eq_attr "type" "imul,imadd")
355        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r5000")))
356   9 9)
357
358 (define_function_unit "imuldiv"  1 0
359   (and (eq_attr "type" "idiv")
360        (eq_attr "cpu" "!r3000,r3900,r4000,r4600,r4650,r4100,r4120,r4300,r5000"))
361   38 38)
362
363 (define_function_unit "imuldiv"  1 0
364   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r3000,r3900"))
365   35 35)
366
367 (define_function_unit "imuldiv"  1 0
368   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r4600"))
369   42 42)
370
371 (define_function_unit "imuldiv"  1 0
372   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r4650"))
373   36 36)
374
375 (define_function_unit "imuldiv"  1 0
376   (and (eq_attr "type" "idiv") (eq_attr "cpu" "r4000"))
377   69 69)
378
379 (define_function_unit "imuldiv" 1 0
380   (and (eq_attr "type" "idiv")
381        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4100,r4120")))
382   35 35)
383
384 (define_function_unit "imuldiv" 1 0
385   (and (eq_attr "type" "idiv")
386        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4100,r4120")))
387   67 67)
388
389 (define_function_unit "imuldiv" 1 0
390   (and (eq_attr "type" "idiv")
391        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r4300")))
392   37 37)
393
394 (define_function_unit "imuldiv" 1 0
395   (and (eq_attr "type" "idiv")
396        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r4300")))
397   69 69)
398
399 (define_function_unit "imuldiv" 1 0
400   (and (eq_attr "type" "idiv")
401        (and (eq_attr "mode" "SI") (eq_attr "cpu" "r5000")))
402   36 36)
403
404 (define_function_unit "imuldiv" 1 0
405   (and (eq_attr "type" "idiv")
406        (and (eq_attr "mode" "DI") (eq_attr "cpu" "r5000")))
407   68 68)
408
409 ;; The R4300 does *NOT* have a separate Floating Point Unit, instead
410 ;; the FP hardware is part of the normal ALU circuitry.  This means FP
411 ;; instructions affect the pipe-line, and no functional unit
412 ;; parallelism can occur on R4300 processors.  To force GCC into coding
413 ;; for only a single functional unit, we force the R4300 FP
414 ;; instructions to be processed in the "imuldiv" unit.
415
416 (define_function_unit "adder" 1 1
417   (and (eq_attr "type" "fcmp") (eq_attr "cpu" "!r3000,r3900,r6000,r4300,r5000"))
418   3 0)
419
420 (define_function_unit "adder" 1 1
421   (and (eq_attr "type" "fcmp") (eq_attr "cpu" "r3000,r3900,r6000"))
422   2 0)
423
424 (define_function_unit "adder" 1 1
425   (and (eq_attr "type" "fcmp") (eq_attr "cpu" "r5000"))
426   1 0)
427
428 (define_function_unit "adder" 1 1
429   (and (eq_attr "type" "fadd") (eq_attr "cpu" "!r3000,r3900,r6000,r4300"))
430   4 0)
431
432 (define_function_unit "adder" 1 1
433   (and (eq_attr "type" "fadd") (eq_attr "cpu" "r3000,r3900"))
434   2 0)
435
436 (define_function_unit "adder" 1 1
437   (and (eq_attr "type" "fadd") (eq_attr "cpu" "r6000"))
438   3 0)
439
440 (define_function_unit "adder" 1 1
441   (and (eq_attr "type" "fabs,fneg")
442        (eq_attr "cpu" "!r3000,r3900,r4600,r4650,r4300,r5000"))
443   2 0)
444
445 (define_function_unit "adder" 1 1
446   (and (eq_attr "type" "fabs,fneg") (eq_attr "cpu" "r3000,r3900,r4600,r4650,r5000"))
447   1 0)
448
449 (define_function_unit "mult" 1 1
450   (and (eq_attr "type" "fmul")
451        (and (eq_attr "mode" "SF")
452             (eq_attr "cpu" "!r3000,r3900,r6000,r4600,r4650,r4300,r5000")))
453   7 0)
454
455 (define_function_unit "mult" 1 1
456   (and (eq_attr "type" "fmul")
457        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r3000,r3900,r5000")))
458   4 0)
459
460 (define_function_unit "mult" 1 1
461   (and (eq_attr "type" "fmul")
462        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r6000")))
463   5 0)
464
465 (define_function_unit "mult" 1 1
466   (and (eq_attr "type" "fmul")
467        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4600,r4650")))
468   8 0)
469
470 (define_function_unit "mult" 1 1
471   (and (eq_attr "type" "fmul")
472        (and (eq_attr "mode" "DF") (eq_attr "cpu" "!r3000,r3900,r6000,r4300,r5000")))
473   8 0)
474
475 (define_function_unit "mult" 1 1
476   (and (eq_attr "type" "fmul")
477        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r3000,r3900,r5000")))
478   5 0)
479
480 (define_function_unit "mult" 1 1
481   (and (eq_attr "type" "fmul")
482        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r6000")))
483   6 0)
484
485 (define_function_unit "divide" 1 1
486   (and (eq_attr "type" "fdiv")
487        (and (eq_attr "mode" "SF")
488             (eq_attr "cpu" "!r3000,r3900,r6000,r4600,r4650,r4300,r5000")))
489   23 0)
490
491 (define_function_unit "divide" 1 1
492   (and (eq_attr "type" "fdiv")
493        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r3000,r3900")))
494   12 0)
495
496 (define_function_unit "divide" 1 1
497   (and (eq_attr "type" "fdiv")
498        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r6000")))
499   15 0)
500
501 (define_function_unit "divide" 1 1
502   (and (eq_attr "type" "fdiv")
503        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4600,r4650")))
504   32 0)
505
506 (define_function_unit "divide" 1 1
507   (and (eq_attr "type" "fdiv")
508        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r5000")))
509   21 0)
510
511 (define_function_unit "divide" 1 1
512   (and (eq_attr "type" "fdiv")
513        (and (eq_attr "mode" "DF")
514             (eq_attr "cpu" "!r3000,r3900,r6000,r4600,r4650,r4300")))
515   36 0)
516
517 (define_function_unit "divide" 1 1
518   (and (eq_attr "type" "fdiv")
519        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r3000,r3900")))
520   19 0)
521
522 (define_function_unit "divide" 1 1
523   (and (eq_attr "type" "fdiv")
524        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r6000")))
525   16 0)
526
527 (define_function_unit "divide" 1 1
528   (and (eq_attr "type" "fdiv")
529        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4600,r4650")))
530   61 0)
531
532 ;;; ??? Is this number right?
533 (define_function_unit "divide" 1 1
534   (and (eq_attr "type" "fsqrt,frsqrt")
535        (and (eq_attr "mode" "SF") (eq_attr "cpu" "!r4600,r4650,r4300,r5000")))
536   54 0)
537
538 (define_function_unit "divide" 1 1
539   (and (eq_attr "type" "fsqrt,frsqrt")
540        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4600,r4650")))
541   31 0)
542
543 (define_function_unit "divide" 1 1
544   (and (eq_attr "type" "fsqrt,frsqrt")
545        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r5000")))
546   21 0)
547
548 ;;; ??? Is this number right?
549 (define_function_unit "divide" 1 1
550   (and (eq_attr "type" "fsqrt,frsqrt")
551        (and (eq_attr "mode" "DF") (eq_attr "cpu" "!r4600,r4650,r4300,r5000")))
552   112 0)
553
554 (define_function_unit "divide" 1 1
555   (and (eq_attr "type" "fsqrt,frsqrt")
556        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4600,r4650")))
557   60 0)
558
559 (define_function_unit "divide" 1 1
560   (and (eq_attr "type" "fsqrt,frsqrt")
561        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r5000")))
562   36 0)
563
564 ;; R4300 FP instruction classes treated as part of the "imuldiv"
565 ;; functional unit:
566
567 (define_function_unit "imuldiv" 1 0
568   (and (eq_attr "type" "fadd") (eq_attr "cpu" "r4300"))
569   3 3)
570
571 (define_function_unit "imuldiv" 1 0
572   (and (eq_attr "type" "fcmp,fabs,fneg") (eq_attr "cpu" "r4300"))
573   1 1)
574
575 (define_function_unit "imuldiv" 1 0
576   (and (eq_attr "type" "fmul") (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4300")))
577   5 5)
578 (define_function_unit "imuldiv" 1 0
579   (and (eq_attr "type" "fmul") (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4300")))
580   8 8)
581
582 (define_function_unit "imuldiv" 1 0
583   (and (and (eq_attr "type" "fdiv") (eq_attr "type" "fsqrt,frsqrt"))
584        (and (eq_attr "mode" "SF") (eq_attr "cpu" "r4300")))
585   29 29)
586 (define_function_unit "imuldiv" 1 0
587   (and (and (eq_attr "type" "fdiv") (eq_attr "type" "fsqrt,frsqrt"))
588        (and (eq_attr "mode" "DF") (eq_attr "cpu" "r4300")))
589   58 58)
590 \f
591 ;; The following functional units do not use the cpu type, and use
592 ;; much less memory in genattrtab.c.
593
594 ;; (define_function_unit "memory"   1 0 (eq_attr "type" "load")                                3 0)
595 ;; (define_function_unit "memory"   1 0 (eq_attr "type" "store")                               1 0)
596 ;;
597 ;; (define_function_unit "fp_comp"  1 0 (eq_attr "type" "fcmp")                                2 0)
598 ;;
599 ;; (define_function_unit "transfer" 1 0 (eq_attr "type" "xfer")                                2 0)
600 ;; (define_function_unit "transfer" 1 0 (eq_attr "type" "hilo")                                3 0)
601 ;;
602 ;; (define_function_unit "imuldiv"  1 1 (eq_attr "type" "imul")                               17 0)
603 ;; (define_function_unit "imuldiv"  1 1 (eq_attr "type" "idiv")                               38 0)
604 ;;
605 ;; (define_function_unit "adder"    1 1 (eq_attr "type" "fadd")                                4 0)
606 ;; (define_function_unit "adder"    1 1 (eq_attr "type" "fabs,fneg")                           2 0)
607 ;;
608 ;; (define_function_unit "mult"     1 1 (and (eq_attr "type" "fmul") (eq_attr "mode" "SF"))    7 0)
609 ;; (define_function_unit "mult"     1 1 (and (eq_attr "type" "fmul") (eq_attr "mode" "DF"))    8 0)
610 ;;
611 ;; (define_function_unit "divide"   1 1 (and (eq_attr "type" "fdiv") (eq_attr "mode" "SF"))   23 0)
612 ;; (define_function_unit "divide"   1 1 (and (eq_attr "type" "fdiv") (eq_attr "mode" "DF"))   36 0)
613 ;;
614 ;; (define_function_unit "sqrt"     1 1 (and (eq_attr "type" "fsqrt") (eq_attr "mode" "SF"))  54 0)
615 ;; (define_function_unit "sqrt"     1 1 (and (eq_attr "type" "fsqrt") (eq_attr "mode" "DF")) 112 0)
616 \f
617 ;; Include scheduling descriptions.
618
619 (include "5400.md")
620 (include "5500.md")
621 (include "sr71k.md")
622
623
624 ;;
625 ;;  ....................
626 ;;
627 ;;      CONDITIONAL TRAPS
628 ;;
629 ;;  ....................
630 ;;
631
632 (define_insn "trap"
633   [(trap_if (const_int 1) (const_int 0))]
634   ""
635   "*
636 {
637   if (ISA_HAS_COND_TRAP)
638     return \"teq\\t$0,$0\";
639   else if (TARGET_MIPS16)
640     return \"break 0\";
641   else
642     return \"break\";
643 }")
644
645 (define_expand "conditional_trap"
646   [(trap_if (match_operator 0 "cmp_op"
647                             [(match_dup 2) (match_dup 3)])
648             (match_operand 1 "const_int_operand" ""))]
649   "ISA_HAS_COND_TRAP"
650   "
651 {
652   mips_gen_conditional_trap (operands);
653   DONE;
654 }")
655
656 ;; Match a TRAP_IF with 2nd arg of 0.  The div_trap_* insns match a
657 ;; 2nd arg of any CONST_INT, so this insn must appear first.
658 ;; gen_div_trap always generates TRAP_IF with 2nd arg of 6 or 7.
659
660 (define_insn ""
661   [(trap_if (match_operator 0 "trap_cmp_op"
662                             [(match_operand:SI 1 "reg_or_0_operand" "d")
663                              (match_operand:SI 2 "nonmemory_operand" "dI")])
664             (const_int 0))]
665   "ISA_HAS_COND_TRAP"
666   "t%C0\\t%z1,%z2")
667 \f
668 ;;
669 ;;  ....................
670 ;;
671 ;;      ADDITION
672 ;;
673 ;;  ....................
674 ;;
675
676 (define_insn "adddf3"
677   [(set (match_operand:DF 0 "register_operand" "=f")
678         (plus:DF (match_operand:DF 1 "register_operand" "f")
679                  (match_operand:DF 2 "register_operand" "f")))]
680   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
681   "add.d\\t%0,%1,%2"
682   [(set_attr "type"     "fadd")
683    (set_attr "mode"     "DF")])
684
685 (define_insn "addsf3"
686   [(set (match_operand:SF 0 "register_operand" "=f")
687         (plus:SF (match_operand:SF 1 "register_operand" "f")
688                  (match_operand:SF 2 "register_operand" "f")))]
689   "TARGET_HARD_FLOAT"
690   "add.s\\t%0,%1,%2"
691   [(set_attr "type"     "fadd")
692    (set_attr "mode"     "SF")])
693
694 (define_expand "addsi3"
695   [(set (match_operand:SI 0 "register_operand" "")
696         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "")
697                  (match_operand:SI 2 "arith_operand" "")))]
698   ""
699   "
700 {
701   /* The mips16 assembler handles -32768 correctly, and so does gas,
702      but some other MIPS assemblers think that -32768 needs to be
703      loaded into a register before it can be added in.  */
704   if (! TARGET_MIPS16
705       && ! TARGET_GAS
706       && GET_CODE (operands[2]) == CONST_INT
707       && INTVAL (operands[2]) == -32768)
708     operands[2] = force_reg (SImode, operands[2]);
709
710   /* If a large stack adjustment was forced into a register, we may be
711      asked to generate rtx such as:
712
713         (set (reg:SI sp) (plus:SI (reg:SI sp) (reg:SI pseudo)))
714
715      but no such instruction is available in mips16.  Handle it by
716      using a temporary.  */
717   if (TARGET_MIPS16
718       && REGNO (operands[0]) == STACK_POINTER_REGNUM
719       && ((GET_CODE (operands[1]) == REG
720            && REGNO (operands[1]) != STACK_POINTER_REGNUM)
721           || GET_CODE (operands[2]) != CONST_INT))
722     {
723       rtx tmp = gen_reg_rtx (SImode);
724
725       emit_move_insn (tmp, operands[1]);
726       emit_insn (gen_addsi3 (tmp, tmp, operands[2]));
727       emit_move_insn (operands[0], tmp);
728       DONE;
729     }
730 }")
731
732 (define_insn "addsi3_internal"
733   [(set (match_operand:SI 0 "register_operand" "=d,d")
734         (plus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ,dJ")
735                  (match_operand:SI 2 "arith_operand" "d,Q")))]
736   "! TARGET_MIPS16
737    && (TARGET_GAS
738        || GET_CODE (operands[2]) != CONST_INT
739        || INTVAL (operands[2]) != -32768)"
740   "@
741     addu\\t%0,%z1,%2
742     addiu\\t%0,%z1,%2"
743   [(set_attr "type"     "arith")
744    (set_attr "mode"     "SI")])
745
746 ;; For the mips16, we need to recognize stack pointer additions
747 ;; explicitly, since we don't have a constraint for $sp.  These insns
748 ;; will be generated by the save_restore_insns functions.
749
750 (define_insn ""
751   [(set (reg:SI 29)
752         (plus:SI (reg:SI 29)
753                  (match_operand:SI 0 "small_int" "I")))]
754   "TARGET_MIPS16"
755   "addu\\t%$,%$,%0"
756   [(set_attr "type"     "arith")
757    (set_attr "mode"     "SI")
758    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_simm8_8" "")
759                                       (const_int 4)
760                                       (const_int 8)))])
761
762 (define_insn ""
763   [(set (match_operand:SI 0 "register_operand" "=d")
764         (plus:SI (reg:SI 29)
765                  (match_operand:SI 1 "small_int" "I")))]
766   "TARGET_MIPS16"
767   "addu\\t%0,%$,%1"
768   [(set_attr "type"     "arith")
769    (set_attr "mode"     "SI")
770    (set (attr "length") (if_then_else (match_operand:VOID 1 "m16_uimm8_4" "")
771                                       (const_int 4)
772                                       (const_int 8)))])
773
774 (define_insn ""
775   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
776         (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
777                  (match_operand:SI 2 "arith_operand" "Q,O,d")))]
778   "TARGET_MIPS16
779    && (GET_CODE (operands[1]) != REG
780        || REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER
781        || M16_REG_P (REGNO (operands[1]))
782        || REGNO (operands[1]) == ARG_POINTER_REGNUM
783        || REGNO (operands[1]) == FRAME_POINTER_REGNUM
784        || REGNO (operands[1]) == STACK_POINTER_REGNUM)
785    && (GET_CODE (operands[2]) != REG
786        || REGNO (operands[2]) >= FIRST_PSEUDO_REGISTER
787        || M16_REG_P (REGNO (operands[2]))
788        || REGNO (operands[2]) == ARG_POINTER_REGNUM
789        || REGNO (operands[2]) == FRAME_POINTER_REGNUM
790        || REGNO (operands[2]) == STACK_POINTER_REGNUM)"
791   "*
792 {
793   if (REGNO (operands[0]) == REGNO (operands[1]))
794     return \"addu\\t%0,%2\";
795   return \"addu\\t%0,%1,%2\";
796 }"
797   [(set_attr "type"     "arith")
798    (set_attr "mode"     "SI")
799    (set_attr_alternative "length"
800                 [(if_then_else (match_operand:VOID 2 "m16_simm8_1" "")
801                                (const_int 4)
802                                (const_int 8))
803                  (if_then_else (match_operand:VOID 2 "m16_simm4_1" "")
804                                (const_int 4)
805                                (const_int 8))
806                  (const_int 4)])])
807
808
809 ;; On the mips16, we can sometimes split an add of a constant which is
810 ;; a 4 byte instruction into two adds which are both 2 byte
811 ;; instructions.  There are two cases: one where we are adding a
812 ;; constant plus a register to another register, and one where we are
813 ;; simply adding a constant to a register.
814
815 (define_split
816   [(set (match_operand:SI 0 "register_operand" "")
817         (plus:SI (match_dup 0)
818                  (match_operand:SI 1 "const_int_operand" "")))]
819   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
820    && GET_CODE (operands[0]) == REG
821    && M16_REG_P (REGNO (operands[0]))
822    && GET_CODE (operands[1]) == CONST_INT
823    && ((INTVAL (operands[1]) > 0x7f
824         && INTVAL (operands[1]) <= 0x7f + 0x7f)
825        || (INTVAL (operands[1]) < - 0x80
826            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
827   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
828    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
829   "
830 {
831   HOST_WIDE_INT val = INTVAL (operands[1]);
832
833   if (val >= 0)
834     {
835       operands[1] = GEN_INT (0x7f);
836       operands[2] = GEN_INT (val - 0x7f);
837     }
838   else
839     {
840       operands[1] = GEN_INT (- 0x80);
841       operands[2] = GEN_INT (val + 0x80);
842     }
843 }")
844
845 (define_split
846   [(set (match_operand:SI 0 "register_operand" "")
847         (plus:SI (match_operand:SI 1 "register_operand" "")
848                  (match_operand:SI 2 "const_int_operand" "")))]
849   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
850    && GET_CODE (operands[0]) == REG
851    && M16_REG_P (REGNO (operands[0]))
852    && GET_CODE (operands[1]) == REG
853    && M16_REG_P (REGNO (operands[1]))
854    && REGNO (operands[0]) != REGNO (operands[1])
855    && GET_CODE (operands[2]) == CONST_INT
856    && ((INTVAL (operands[2]) > 0x7
857         && INTVAL (operands[2]) <= 0x7 + 0x7f)
858        || (INTVAL (operands[2]) < - 0x8
859            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
860   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
861    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
862   "
863 {
864   HOST_WIDE_INT val = INTVAL (operands[2]);
865
866   if (val >= 0)
867     {
868       operands[2] = GEN_INT (0x7);
869       operands[3] = GEN_INT (val - 0x7);
870     }
871   else
872     {
873       operands[2] = GEN_INT (- 0x8);
874       operands[3] = GEN_INT (val + 0x8);
875     }
876 }")
877
878 (define_expand "adddi3"
879   [(parallel [(set (match_operand:DI 0 "register_operand" "")
880                    (plus:DI (match_operand:DI 1 "register_operand" "")
881                             (match_operand:DI 2 "arith_operand" "")))
882               (clobber (match_dup 3))])]
883   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
884   "
885 {
886   /* The mips16 assembler handles -32768 correctly, and so does gas,
887      but some other MIPS assemblers think that -32768 needs to be
888      loaded into a register before it can be added in.  */
889   if (! TARGET_MIPS16
890       && ! TARGET_GAS
891       && GET_CODE (operands[2]) == CONST_INT
892       && INTVAL (operands[2]) == -32768)
893     operands[2] = force_reg (DImode, operands[2]);
894
895   /* If a large stack adjustment was forced into a register, we may be
896      asked to generate rtx such as:
897
898         (set (reg:DI sp) (plus:DI (reg:DI sp) (reg:DI pseudo)))
899
900      but no such instruction is available in mips16.  Handle it by
901      using a temporary.  */
902   if (TARGET_MIPS16
903       && REGNO (operands[0]) == STACK_POINTER_REGNUM
904       && ((GET_CODE (operands[1]) == REG
905            && REGNO (operands[1]) != STACK_POINTER_REGNUM)
906           || GET_CODE (operands[2]) != CONST_INT))
907     {
908       rtx tmp = gen_reg_rtx (DImode);
909
910       emit_move_insn (tmp, operands[1]);
911       emit_insn (gen_addsi3 (tmp, tmp, operands[2]));
912       emit_move_insn (operands[0], tmp);
913       DONE;
914     }
915
916   if (TARGET_64BIT)
917     {
918       emit_insn (gen_adddi3_internal_3 (operands[0], operands[1],
919                                         operands[2]));
920       DONE;
921     }
922
923   operands[3] = gen_reg_rtx (SImode);
924 }")
925
926 (define_insn "adddi3_internal_1"
927   [(set (match_operand:DI 0 "register_operand" "=d,&d")
928         (plus:DI (match_operand:DI 1 "register_operand" "0,d")
929                  (match_operand:DI 2 "register_operand" "d,d")))
930    (clobber (match_operand:SI 3 "register_operand" "=d,d"))]
931   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
932   "*
933 {
934   return (REGNO (operands[0]) == REGNO (operands[1])
935           && REGNO (operands[0]) == REGNO (operands[2]))
936     ? \"srl\\t%3,%L0,31\;sll\\t%M0,%M0,1\;sll\\t%L0,%L1,1\;addu\\t%M0,%M0,%3\"
937     : \"addu\\t%L0,%L1,%L2\;sltu\\t%3,%L0,%L2\;addu\\t%M0,%M1,%M2\;addu\\t%M0,%M0,%3\";
938 }"
939   [(set_attr "type"     "darith")
940    (set_attr "mode"     "DI")
941    (set_attr "length"   "16")])
942
943 (define_split
944   [(set (match_operand:DI 0 "register_operand" "")
945         (plus:DI (match_operand:DI 1 "register_operand" "")
946                  (match_operand:DI 2 "register_operand" "")))
947    (clobber (match_operand:SI 3 "register_operand" ""))]
948   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
949    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
950    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
951    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
952    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))
953    && (REGNO (operands[0]) != REGNO (operands[1])
954        || REGNO (operands[0]) != REGNO (operands[2]))"
955
956   [(set (subreg:SI (match_dup 0) 0)
957         (plus:SI (subreg:SI (match_dup 1) 0)
958                  (subreg:SI (match_dup 2) 0)))
959
960    (set (match_dup 3)
961         (ltu:SI (subreg:SI (match_dup 0) 0)
962                 (subreg:SI (match_dup 2) 0)))
963
964    (set (subreg:SI (match_dup 0) 4)
965         (plus:SI (subreg:SI (match_dup 1) 4)
966                  (subreg:SI (match_dup 2) 4)))
967
968    (set (subreg:SI (match_dup 0) 4)
969         (plus:SI (subreg:SI (match_dup 0) 4)
970                  (match_dup 3)))]
971   "")
972
973 (define_split
974   [(set (match_operand:DI 0 "register_operand" "")
975         (plus:DI (match_operand:DI 1 "register_operand" "")
976                  (match_operand:DI 2 "register_operand" "")))
977    (clobber (match_operand:SI 3 "register_operand" ""))]
978   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
979    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
980    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
981    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
982    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))
983    && (REGNO (operands[0]) != REGNO (operands[1])
984        || REGNO (operands[0]) != REGNO (operands[2]))"
985
986   [(set (subreg:SI (match_dup 0) 4)
987         (plus:SI (subreg:SI (match_dup 1) 4)
988                  (subreg:SI (match_dup 2) 4)))
989
990    (set (match_dup 3)
991         (ltu:SI (subreg:SI (match_dup 0) 4)
992                 (subreg:SI (match_dup 2) 4)))
993
994    (set (subreg:SI (match_dup 0) 0)
995         (plus:SI (subreg:SI (match_dup 1) 0)
996                  (subreg:SI (match_dup 2) 0)))
997
998    (set (subreg:SI (match_dup 0) 0)
999         (plus:SI (subreg:SI (match_dup 0) 0)
1000                  (match_dup 3)))]
1001   "")
1002
1003 (define_insn "adddi3_internal_2"
1004   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1005         (plus:DI (match_operand:DI 1 "register_operand" "%d,%d,%d")
1006                  (match_operand:DI 2 "small_int" "P,J,N")))
1007    (clobber (match_operand:SI 3 "register_operand" "=d,d,d"))]
1008   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1009    && (TARGET_GAS
1010        || GET_CODE (operands[2]) != CONST_INT
1011        || INTVAL (operands[2]) != -32768)"
1012   "@
1013    addu\\t%L0,%L1,%2\;sltu\\t%3,%L0,%2\;addu\\t%M0,%M1,%3
1014    move\\t%L0,%L1\;move\\t%M0,%M1
1015    subu\\t%L0,%L1,%n2\;sltu\\t%3,%L0,%2\;subu\\t%M0,%M1,1\;addu\\t%M0,%M0,%3"
1016   [(set_attr "type"     "darith")
1017    (set_attr "mode"     "DI")
1018    (set_attr "length"   "12,8,16")])
1019
1020 (define_split
1021   [(set (match_operand:DI 0 "register_operand" "")
1022         (plus:DI (match_operand:DI 1 "register_operand" "")
1023                  (match_operand:DI 2 "small_int" "")))
1024    (clobber (match_operand:SI 3 "register_operand" ""))]
1025   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
1026    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1027    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1028    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1029    && INTVAL (operands[2]) > 0"
1030
1031   [(set (subreg:SI (match_dup 0) 0)
1032         (plus:SI (subreg:SI (match_dup 1) 0)
1033                  (match_dup 2)))
1034
1035    (set (match_dup 3)
1036         (ltu:SI (subreg:SI (match_dup 0) 0)
1037                 (match_dup 2)))
1038
1039    (set (subreg:SI (match_dup 0) 4)
1040         (plus:SI (subreg:SI (match_dup 1) 4)
1041                  (match_dup 3)))]
1042   "")
1043
1044 (define_split
1045   [(set (match_operand:DI 0 "register_operand" "")
1046         (plus:DI (match_operand:DI 1 "register_operand" "")
1047                  (match_operand:DI 2 "small_int" "")))
1048    (clobber (match_operand:SI 3 "register_operand" ""))]
1049   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
1050    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1051    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1052    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1053    && INTVAL (operands[2]) > 0"
1054
1055   [(set (subreg:SI (match_dup 0) 4)
1056         (plus:SI (subreg:SI (match_dup 1) 4)
1057                  (match_dup 2)))
1058
1059    (set (match_dup 3)
1060         (ltu:SI (subreg:SI (match_dup 0) 4)
1061                 (match_dup 2)))
1062
1063    (set (subreg:SI (match_dup 0) 0)
1064         (plus:SI (subreg:SI (match_dup 1) 0)
1065                  (match_dup 3)))]
1066   "")
1067
1068 (define_insn "adddi3_internal_3"
1069   [(set (match_operand:DI 0 "register_operand" "=d,d")
1070         (plus:DI (match_operand:DI 1 "reg_or_0_operand" "dJ,dJ")
1071                  (match_operand:DI 2 "arith_operand" "d,Q")))]
1072   "TARGET_64BIT
1073    && !TARGET_MIPS16
1074    && (TARGET_GAS
1075        || GET_CODE (operands[2]) != CONST_INT
1076        || INTVAL (operands[2]) != -32768)"
1077   "@
1078     daddu\\t%0,%z1,%2
1079     daddiu\\t%0,%z1,%2"
1080   [(set_attr "type"     "darith")
1081    (set_attr "mode"     "DI")])
1082
1083 ;; For the mips16, we need to recognize stack pointer additions
1084 ;; explicitly, since we don't have a constraint for $sp.  These insns
1085 ;; will be generated by the save_restore_insns functions.
1086
1087 (define_insn ""
1088   [(set (reg:DI 29)
1089         (plus:DI (reg:DI 29)
1090                  (match_operand:DI 0 "small_int" "I")))]
1091   "TARGET_MIPS16 && TARGET_64BIT"
1092   "daddu\\t%$,%$,%0"
1093   [(set_attr "type"     "arith")
1094    (set_attr "mode"     "DI")
1095    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_simm8_8" "")
1096                                       (const_int 4)
1097                                       (const_int 8)))])
1098
1099 (define_insn ""
1100   [(set (match_operand:DI 0 "register_operand" "=d")
1101         (plus:DI (reg:DI 29)
1102                  (match_operand:DI 1 "small_int" "I")))]
1103   "TARGET_MIPS16 && TARGET_64BIT"
1104   "daddu\\t%0,%$,%1"
1105   [(set_attr "type"     "arith")
1106    (set_attr "mode"     "DI")
1107    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_uimm5_4" "")
1108                                       (const_int 4)
1109                                       (const_int 8)))])
1110
1111 (define_insn ""
1112   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1113         (plus:DI (match_operand:DI 1 "register_operand" "0,d,d")
1114                  (match_operand:DI 2 "arith_operand" "Q,O,d")))]
1115   "TARGET_MIPS16 && TARGET_64BIT
1116    && (GET_CODE (operands[1]) != REG
1117        || REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER
1118        || M16_REG_P (REGNO (operands[1]))
1119        || REGNO (operands[1]) == ARG_POINTER_REGNUM
1120        || REGNO (operands[1]) == FRAME_POINTER_REGNUM
1121        || REGNO (operands[1]) == STACK_POINTER_REGNUM)
1122    && (GET_CODE (operands[2]) != REG
1123        || REGNO (operands[2]) >= FIRST_PSEUDO_REGISTER
1124        || M16_REG_P (REGNO (operands[2]))
1125        || REGNO (operands[2]) == ARG_POINTER_REGNUM
1126        || REGNO (operands[2]) == FRAME_POINTER_REGNUM
1127        || REGNO (operands[2]) == STACK_POINTER_REGNUM)"
1128   "*
1129 {
1130   if (REGNO (operands[0]) == REGNO (operands[1]))
1131     return \"daddu\\t%0,%2\";
1132   return \"daddu\\t%0,%1,%2\";
1133 }"
1134   [(set_attr "type"     "arith")
1135    (set_attr "mode"     "DI")
1136    (set_attr_alternative "length"
1137                 [(if_then_else (match_operand:VOID 2 "m16_simm5_1" "")
1138                                (const_int 4)
1139                                (const_int 8))
1140                  (if_then_else (match_operand:VOID 2 "m16_simm4_1" "")
1141                                (const_int 4)
1142                                (const_int 8))
1143                  (const_int 4)])])
1144
1145
1146 ;; On the mips16, we can sometimes split an add of a constant which is
1147 ;; a 4 byte instruction into two adds which are both 2 byte
1148 ;; instructions.  There are two cases: one where we are adding a
1149 ;; constant plus a register to another register, and one where we are
1150 ;; simply adding a constant to a register.
1151
1152 (define_split
1153   [(set (match_operand:DI 0 "register_operand" "")
1154         (plus:DI (match_dup 0)
1155                  (match_operand:DI 1 "const_int_operand" "")))]
1156   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1157    && GET_CODE (operands[0]) == REG
1158    && M16_REG_P (REGNO (operands[0]))
1159    && GET_CODE (operands[1]) == CONST_INT
1160    && ((INTVAL (operands[1]) > 0xf
1161         && INTVAL (operands[1]) <= 0xf + 0xf)
1162        || (INTVAL (operands[1]) < - 0x10
1163            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1164   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1165    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1166   "
1167 {
1168   HOST_WIDE_INT val = INTVAL (operands[1]);
1169
1170   if (val >= 0)
1171     {
1172       operands[1] = GEN_INT (0xf);
1173       operands[2] = GEN_INT (val - 0xf);
1174     }
1175   else
1176     {
1177       operands[1] = GEN_INT (- 0x10);
1178       operands[2] = GEN_INT (val + 0x10);
1179     }
1180 }")
1181
1182 (define_split
1183   [(set (match_operand:DI 0 "register_operand" "")
1184         (plus:DI (match_operand:DI 1 "register_operand" "")
1185                  (match_operand:DI 2 "const_int_operand" "")))]
1186   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1187    && GET_CODE (operands[0]) == REG
1188    && M16_REG_P (REGNO (operands[0]))
1189    && GET_CODE (operands[1]) == REG
1190    && M16_REG_P (REGNO (operands[1]))
1191    && REGNO (operands[0]) != REGNO (operands[1])
1192    && GET_CODE (operands[2]) == CONST_INT
1193    && ((INTVAL (operands[2]) > 0x7
1194         && INTVAL (operands[2]) <= 0x7 + 0xf)
1195        || (INTVAL (operands[2]) < - 0x8
1196            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1197   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1198    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1199   "
1200 {
1201   HOST_WIDE_INT val = INTVAL (operands[2]);
1202
1203   if (val >= 0)
1204     {
1205       operands[2] = GEN_INT (0x7);
1206       operands[3] = GEN_INT (val - 0x7);
1207     }
1208   else
1209     {
1210       operands[2] = GEN_INT (- 0x8);
1211       operands[3] = GEN_INT (val + 0x8);
1212     }
1213 }")
1214
1215 (define_insn "addsi3_internal_2"
1216   [(set (match_operand:DI 0 "register_operand" "=d,d")
1217         (sign_extend:DI (plus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ,dJ")
1218                                  (match_operand:SI 2 "arith_operand" "d,Q"))))]
1219   "TARGET_64BIT
1220    && !TARGET_MIPS16
1221    && (TARGET_GAS
1222        || GET_CODE (operands[2]) != CONST_INT
1223        || INTVAL (operands[2]) != -32768)"
1224   "@
1225     addu\\t%0,%z1,%2
1226     addiu\\t%0,%z1,%2"
1227   [(set_attr "type"     "arith")
1228    (set_attr "mode"     "SI")])
1229
1230 (define_insn ""
1231   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1232         (sign_extend:DI (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1233                                  (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1234   "TARGET_MIPS16 && TARGET_64BIT"
1235   "*
1236 {
1237   if (REGNO (operands[0]) == REGNO (operands[1]))
1238     return \"addu\\t%0,%2\";
1239   return \"addu\\t%0,%1,%2\";
1240 }"
1241   [(set_attr "type"     "arith")
1242    (set_attr "mode"     "SI")
1243    (set_attr_alternative "length"
1244                 [(if_then_else (match_operand:VOID 2 "m16_simm8_1" "")
1245                                (const_int 4)
1246                                (const_int 8))
1247                  (if_then_else (match_operand:VOID 2 "m16_simm4_1" "")
1248                                (const_int 4)
1249                                (const_int 8))
1250                  (const_int 4)])])
1251
1252 \f
1253 ;;
1254 ;;  ....................
1255 ;;
1256 ;;      SUBTRACTION
1257 ;;
1258 ;;  ....................
1259 ;;
1260
1261 (define_insn "subdf3"
1262   [(set (match_operand:DF 0 "register_operand" "=f")
1263         (minus:DF (match_operand:DF 1 "register_operand" "f")
1264                   (match_operand:DF 2 "register_operand" "f")))]
1265   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
1266   "sub.d\\t%0,%1,%2"
1267   [(set_attr "type"     "fadd")
1268    (set_attr "mode"     "DF")])
1269
1270 (define_insn "subsf3"
1271   [(set (match_operand:SF 0 "register_operand" "=f")
1272         (minus:SF (match_operand:SF 1 "register_operand" "f")
1273                   (match_operand:SF 2 "register_operand" "f")))]
1274   "TARGET_HARD_FLOAT"
1275   "sub.s\\t%0,%1,%2"
1276   [(set_attr "type"     "fadd")
1277    (set_attr "mode"     "SF")])
1278
1279 (define_expand "subsi3"
1280   [(set (match_operand:SI 0 "register_operand" "=d")
1281         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ")
1282                   (match_operand:SI 2 "arith_operand" "dI")))]
1283   ""
1284   "
1285 {
1286   if (GET_CODE (operands[2]) == CONST_INT
1287       && (INTVAL (operands[2]) == -32768
1288           || (TARGET_MIPS16
1289               && INTVAL (operands[2]) == -0x4000)))
1290     operands[2] = force_reg (SImode, operands[2]);
1291 }")
1292
1293 (define_insn "subsi3_internal"
1294   [(set (match_operand:SI 0 "register_operand" "=d")
1295         (minus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ")
1296                   (match_operand:SI 2 "arith_operand" "dI")))]
1297   "!TARGET_MIPS16
1298    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1299   "subu\\t%0,%z1,%2"
1300   [(set_attr "type"     "arith")
1301    (set_attr "mode"     "SI")])
1302
1303 ;; For the mips16, we need to recognize stack pointer subtractions
1304 ;; explicitly, since we don't have a constraint for $sp.  These insns
1305 ;; will be generated by the save_restore_insns functions.
1306
1307 (define_insn ""
1308   [(set (reg:SI 29)
1309         (minus:SI (reg:SI 29)
1310                   (match_operand:SI 0 "small_int" "I")))]
1311   "TARGET_MIPS16
1312    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1313   "addu\\t%$,%$,%n0"
1314   [(set_attr "type"     "arith")
1315    (set_attr "mode"     "SI")
1316    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_nsimm8_8" "")
1317                                       (const_int 4)
1318                                       (const_int 8)))])
1319
1320 (define_insn ""
1321   [(set (match_operand:SI 0 "register_operand" "=d")
1322         (minus:SI (reg:SI 29)
1323                   (match_operand:SI 1 "small_int" "I")))]
1324   "TARGET_MIPS16
1325    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1326   "addu\\t%0,%$,%n1"
1327   [(set_attr "type"     "arith")
1328    (set_attr "mode"     "SI")
1329    (set (attr "length") (if_then_else (match_operand:VOID 1 "m16_nuimm8_4" "")
1330                                       (const_int 4)
1331                                       (const_int 8)))])
1332
1333
1334 (define_insn ""
1335   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
1336         (minus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1337                   (match_operand:SI 2 "arith_operand" "I,O,d")))]
1338   "TARGET_MIPS16
1339    && (GET_CODE (operands[2]) != CONST_INT
1340        || (INTVAL (operands[2]) != -32768 && INTVAL (operands[2]) != -0x4000))"
1341   "*
1342 {
1343   if (REGNO (operands[0]) == REGNO (operands[1]))
1344     return \"subu\\t%0,%2\";
1345   return \"subu\\t%0,%1,%2\";
1346 }"
1347   [(set_attr "type"     "arith")
1348    (set_attr "mode"     "SI")
1349    (set_attr_alternative "length"
1350                 [(if_then_else (match_operand:VOID 2 "m16_nsimm8_1" "")
1351                                (const_int 4)
1352                                (const_int 8))
1353                  (if_then_else (match_operand:VOID 2 "m16_nsimm4_1" "")
1354                                (const_int 4)
1355                                (const_int 8))
1356                  (const_int 4)])])
1357
1358 ;; On the mips16, we can sometimes split a subtract of a constant
1359 ;; which is a 4 byte instruction into two adds which are both 2 byte
1360 ;; instructions.  There are two cases: one where we are setting a
1361 ;; register to a register minus a constant, and one where we are
1362 ;; simply subtracting a constant from a register.
1363
1364 (define_split
1365   [(set (match_operand:SI 0 "register_operand" "")
1366         (minus:SI (match_dup 0)
1367                   (match_operand:SI 1 "const_int_operand" "")))]
1368   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1369    && GET_CODE (operands[0]) == REG
1370    && M16_REG_P (REGNO (operands[0]))
1371    && GET_CODE (operands[1]) == CONST_INT
1372    && ((INTVAL (operands[1]) > 0x80
1373         && INTVAL (operands[1]) <= 0x80 + 0x80)
1374        || (INTVAL (operands[1]) < - 0x7f
1375            && INTVAL (operands[1]) >= - 0x7f - 0x7f))"
1376   [(set (match_dup 0) (minus:SI (match_dup 0) (match_dup 1)))
1377    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1378   "
1379 {
1380   HOST_WIDE_INT val = INTVAL (operands[1]);
1381
1382   if (val >= 0)
1383     {
1384       operands[1] = GEN_INT (0x80);
1385       operands[2] = GEN_INT (val - 0x80);
1386     }
1387   else
1388     {
1389       operands[1] = GEN_INT (- 0x7f);
1390       operands[2] = GEN_INT (val + 0x7f);
1391     }
1392 }")
1393
1394 (define_split
1395   [(set (match_operand:SI 0 "register_operand" "")
1396         (minus:SI (match_operand:SI 1 "register_operand" "")
1397                   (match_operand:SI 2 "const_int_operand" "")))]
1398   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1399    && GET_CODE (operands[0]) == REG
1400    && M16_REG_P (REGNO (operands[0]))
1401    && GET_CODE (operands[1]) == REG
1402    && M16_REG_P (REGNO (operands[1]))
1403    && REGNO (operands[0]) != REGNO (operands[1])
1404    && GET_CODE (operands[2]) == CONST_INT
1405    && ((INTVAL (operands[2]) > 0x8
1406         && INTVAL (operands[2]) <= 0x8 + 0x80)
1407        || (INTVAL (operands[2]) < - 0x7
1408            && INTVAL (operands[2]) >= - 0x7 - 0x7f))"
1409   [(set (match_dup 0) (minus:SI (match_dup 1) (match_dup 2)))
1410    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 3)))]
1411   "
1412 {
1413   HOST_WIDE_INT val = INTVAL (operands[2]);
1414
1415   if (val >= 0)
1416     {
1417       operands[2] = GEN_INT (0x8);
1418       operands[3] = GEN_INT (val - 0x8);
1419     }
1420   else
1421     {
1422       operands[2] = GEN_INT (- 0x7);
1423       operands[3] = GEN_INT (val + 0x7);
1424     }
1425 }")
1426
1427 (define_expand "subdi3"
1428   [(parallel [(set (match_operand:DI 0 "register_operand" "=d")
1429                    (minus:DI (match_operand:DI 1 "register_operand" "d")
1430                              (match_operand:DI 2 "register_operand" "d")))
1431               (clobber (match_dup 3))])]
1432   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
1433   "
1434 {
1435   if (TARGET_64BIT)
1436     {
1437       emit_insn (gen_subdi3_internal_3 (operands[0], operands[1],
1438                                         operands[2]));
1439       DONE;
1440     }
1441
1442   operands[3] = gen_reg_rtx (SImode);
1443 }")
1444
1445 (define_insn "subdi3_internal"
1446   [(set (match_operand:DI 0 "register_operand" "=d")
1447         (minus:DI (match_operand:DI 1 "register_operand" "d")
1448                   (match_operand:DI 2 "register_operand" "d")))
1449    (clobber (match_operand:SI 3 "register_operand" "=d"))]
1450   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
1451   "sltu\\t%3,%L1,%L2\;subu\\t%L0,%L1,%L2\;subu\\t%M0,%M1,%M2\;subu\\t%M0,%M0,%3"
1452   [(set_attr "type"     "darith")
1453    (set_attr "mode"     "DI")
1454    (set_attr "length"   "16")])
1455
1456 (define_split
1457   [(set (match_operand:DI 0 "register_operand" "")
1458         (minus:DI (match_operand:DI 1 "register_operand" "")
1459                   (match_operand:DI 2 "register_operand" "")))
1460    (clobber (match_operand:SI 3 "register_operand" ""))]
1461   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
1462    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1463    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1464    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1465    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))"
1466
1467   [(set (match_dup 3)
1468         (ltu:SI (subreg:SI (match_dup 1) 0)
1469                 (subreg:SI (match_dup 2) 0)))
1470
1471    (set (subreg:SI (match_dup 0) 0)
1472         (minus:SI (subreg:SI (match_dup 1) 0)
1473                   (subreg:SI (match_dup 2) 0)))
1474
1475    (set (subreg:SI (match_dup 0) 4)
1476         (minus:SI (subreg:SI (match_dup 1) 4)
1477                   (subreg:SI (match_dup 2) 4)))
1478
1479    (set (subreg:SI (match_dup 0) 4)
1480         (minus:SI (subreg:SI (match_dup 0) 4)
1481                   (match_dup 3)))]
1482   "")
1483
1484 (define_split
1485   [(set (match_operand:DI 0 "register_operand" "")
1486         (minus:DI (match_operand:DI 1 "register_operand" "")
1487                   (match_operand:DI 2 "register_operand" "")))
1488    (clobber (match_operand:SI 3 "register_operand" ""))]
1489   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
1490    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1491    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1492    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1493    && GET_CODE (operands[2]) == REG && GP_REG_P (REGNO (operands[2]))"
1494
1495   [(set (match_dup 3)
1496         (ltu:SI (subreg:SI (match_dup 1) 4)
1497                 (subreg:SI (match_dup 2) 4)))
1498
1499    (set (subreg:SI (match_dup 0) 4)
1500         (minus:SI (subreg:SI (match_dup 1) 4)
1501                   (subreg:SI (match_dup 2) 4)))
1502
1503    (set (subreg:SI (match_dup 0) 0)
1504         (minus:SI (subreg:SI (match_dup 1) 0)
1505                   (subreg:SI (match_dup 2) 0)))
1506
1507    (set (subreg:SI (match_dup 0) 0)
1508         (minus:SI (subreg:SI (match_dup 0) 0)
1509                   (match_dup 3)))]
1510   "")
1511
1512 (define_insn "subdi3_internal_2"
1513   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1514         (minus:DI (match_operand:DI 1 "register_operand" "d,d,d")
1515                   (match_operand:DI 2 "small_int" "P,J,N")))
1516    (clobber (match_operand:SI 3 "register_operand" "=d,d,d"))]
1517   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1518    && INTVAL (operands[2]) != -32768"
1519   "@
1520    sltu\\t%3,%L1,%2\;subu\\t%L0,%L1,%2\;subu\\t%M0,%M1,%3
1521    move\\t%L0,%L1\;move\\t%M0,%M1
1522    sltu\\t%3,%L1,%2\;subu\\t%L0,%L1,%2\;subu\\t%M0,%M1,1\;subu\\t%M0,%M0,%3"
1523   [(set_attr "type"     "darith")
1524    (set_attr "mode"     "DI")
1525    (set_attr "length"   "12,8,16")])
1526
1527 (define_split
1528   [(set (match_operand:DI 0 "register_operand" "")
1529         (minus:DI (match_operand:DI 1 "register_operand" "")
1530                   (match_operand:DI 2 "small_int" "")))
1531    (clobber (match_operand:SI 3 "register_operand" ""))]
1532   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
1533    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1534    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1535    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1536    && INTVAL (operands[2]) > 0"
1537
1538   [(set (match_dup 3)
1539         (ltu:SI (subreg:SI (match_dup 1) 0)
1540                 (match_dup 2)))
1541
1542    (set (subreg:SI (match_dup 0) 0)
1543         (minus:SI (subreg:SI (match_dup 1) 0)
1544                   (match_dup 2)))
1545
1546    (set (subreg:SI (match_dup 0) 4)
1547         (minus:SI (subreg:SI (match_dup 1) 4)
1548                   (match_dup 3)))]
1549   "")
1550
1551 (define_split
1552   [(set (match_operand:DI 0 "register_operand" "")
1553         (minus:DI (match_operand:DI 1 "register_operand" "")
1554                   (match_operand:DI 2 "small_int" "")))
1555    (clobber (match_operand:SI 3 "register_operand" ""))]
1556   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
1557    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
1558    && GET_CODE (operands[0]) == REG && GP_REG_P (REGNO (operands[0]))
1559    && GET_CODE (operands[1]) == REG && GP_REG_P (REGNO (operands[1]))
1560    && INTVAL (operands[2]) > 0"
1561
1562   [(set (match_dup 3)
1563         (ltu:SI (subreg:SI (match_dup 1) 4)
1564                 (match_dup 2)))
1565
1566    (set (subreg:SI (match_dup 0) 4)
1567         (minus:SI (subreg:SI (match_dup 1) 4)
1568                   (match_dup 2)))
1569
1570    (set (subreg:SI (match_dup 0) 0)
1571         (minus:SI (subreg:SI (match_dup 1) 0)
1572                   (match_dup 3)))]
1573   "")
1574
1575 (define_insn "subdi3_internal_3"
1576   [(set (match_operand:DI 0 "register_operand" "=d")
1577         (minus:DI (match_operand:DI 1 "reg_or_0_operand" "dJ")
1578                   (match_operand:DI 2 "arith_operand" "dI")))]
1579   "TARGET_64BIT && !TARGET_MIPS16
1580    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1581   "*
1582 {
1583   return (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
1584     ? \"daddu\\t%0,%z1,%n2\"
1585     : \"dsubu\\t%0,%z1,%2\";
1586 }"
1587   [(set_attr "type"     "darith")
1588    (set_attr "mode"     "DI")])
1589
1590 ;; For the mips16, we need to recognize stack pointer subtractions
1591 ;; explicitly, since we don't have a constraint for $sp.  These insns
1592 ;; will be generated by the save_restore_insns functions.
1593
1594 (define_insn ""
1595   [(set (reg:DI 29)
1596         (minus:DI (reg:DI 29)
1597                   (match_operand:DI 0 "small_int" "I")))]
1598   "TARGET_MIPS16
1599    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1600   "daddu\\t%$,%$,%n0"
1601   [(set_attr "type"     "arith")
1602    (set_attr "mode"     "DI")
1603    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_nsimm8_8" "")
1604                                       (const_int 4)
1605                                       (const_int 8)))])
1606
1607 (define_insn ""
1608   [(set (match_operand:DI 0 "register_operand" "=d")
1609         (minus:DI (reg:DI 29)
1610                   (match_operand:DI 1 "small_int" "I")))]
1611   "TARGET_MIPS16
1612    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1613   "daddu\\t%0,%$,%n1"
1614   [(set_attr "type"     "arith")
1615    (set_attr "mode"     "DI")
1616    (set (attr "length") (if_then_else (match_operand:VOID 0 "m16_nuimm5_4" "")
1617                                       (const_int 4)
1618                                       (const_int 8)))])
1619
1620 (define_insn ""
1621   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1622         (minus:DI (match_operand:DI 1 "register_operand" "0,d,d")
1623                   (match_operand:DI 2 "arith_operand" "I,O,d")))]
1624   "TARGET_MIPS16
1625    && (GET_CODE (operands[2]) != CONST_INT
1626        || (INTVAL (operands[2]) != -32768 && INTVAL (operands[2]) != -0x4000))"
1627   "*
1628 {
1629   if (REGNO (operands[0]) == REGNO (operands[1]))
1630     return \"dsubu\\t%0,%2\";
1631   return \"dsubu\\t%0,%1,%2\";
1632 }"
1633   [(set_attr "type"     "arith")
1634    (set_attr "mode"     "DI")
1635    (set_attr_alternative "length"
1636                 [(if_then_else (match_operand:VOID 2 "m16_nsimm5_1" "")
1637                                (const_int 4)
1638                                (const_int 8))
1639                  (if_then_else (match_operand:VOID 2 "m16_nsimm4_1" "")
1640                                (const_int 4)
1641                                (const_int 8))
1642                  (const_int 4)])])
1643
1644 ;; On the mips16, we can sometimes split an add of a constant which is
1645 ;; a 4 byte instruction into two adds which are both 2 byte
1646 ;; instructions.  There are two cases: one where we are adding a
1647 ;; constant plus a register to another register, and one where we are
1648 ;; simply adding a constant to a register.
1649
1650 (define_split
1651   [(set (match_operand:DI 0 "register_operand" "")
1652         (minus:DI (match_dup 0)
1653                   (match_operand:DI 1 "const_int_operand" "")))]
1654   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1655    && GET_CODE (operands[0]) == REG
1656    && M16_REG_P (REGNO (operands[0]))
1657    && GET_CODE (operands[1]) == CONST_INT
1658    && ((INTVAL (operands[1]) > 0x10
1659         && INTVAL (operands[1]) <= 0x10 + 0x10)
1660        || (INTVAL (operands[1]) < - 0xf
1661            && INTVAL (operands[1]) >= - 0xf - 0xf))"
1662   [(set (match_dup 0) (minus:DI (match_dup 0) (match_dup 1)))
1663    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
1664   "
1665 {
1666   HOST_WIDE_INT val = INTVAL (operands[1]);
1667
1668   if (val >= 0)
1669     {
1670       operands[1] = GEN_INT (0xf);
1671       operands[2] = GEN_INT (val - 0xf);
1672     }
1673   else
1674     {
1675       operands[1] = GEN_INT (- 0x10);
1676       operands[2] = GEN_INT (val + 0x10);
1677     }
1678 }")
1679
1680 (define_split
1681   [(set (match_operand:DI 0 "register_operand" "")
1682         (minus:DI (match_operand:DI 1 "register_operand" "")
1683                   (match_operand:DI 2 "const_int_operand" "")))]
1684   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1685    && GET_CODE (operands[0]) == REG
1686    && M16_REG_P (REGNO (operands[0]))
1687    && GET_CODE (operands[1]) == REG
1688    && M16_REG_P (REGNO (operands[1]))
1689    && REGNO (operands[0]) != REGNO (operands[1])
1690    && GET_CODE (operands[2]) == CONST_INT
1691    && ((INTVAL (operands[2]) > 0x8
1692         && INTVAL (operands[2]) <= 0x8 + 0x10)
1693        || (INTVAL (operands[2]) < - 0x7
1694            && INTVAL (operands[2]) >= - 0x7 - 0xf))"
1695   [(set (match_dup 0) (minus:DI (match_dup 1) (match_dup 2)))
1696    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 3)))]
1697   "
1698 {
1699   HOST_WIDE_INT val = INTVAL (operands[2]);
1700
1701   if (val >= 0)
1702     {
1703       operands[2] = GEN_INT (0x8);
1704       operands[3] = GEN_INT (val - 0x8);
1705     }
1706   else
1707     {
1708       operands[2] = GEN_INT (- 0x7);
1709       operands[3] = GEN_INT (val + 0x7);
1710     }
1711 }")
1712
1713 (define_insn "subsi3_internal_2"
1714   [(set (match_operand:DI 0 "register_operand" "=d")
1715         (sign_extend:DI (minus:SI (match_operand:SI 1 "reg_or_0_operand" "dJ")
1716                                   (match_operand:SI 2 "arith_operand" "dI"))))]
1717   "TARGET_64BIT && !TARGET_MIPS16
1718    && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != -32768)"
1719   "*
1720 {
1721   return (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
1722     ? \"addu\\t%0,%z1,%n2\"
1723     : \"subu\\t%0,%z1,%2\";
1724 }"
1725   [(set_attr "type"     "arith")
1726    (set_attr "mode"     "DI")])
1727
1728 (define_insn ""
1729   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1730         (sign_extend:DI (minus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1731                                   (match_operand:SI 2 "arith_operand" "I,O,d"))))]
1732   "TARGET_64BIT && TARGET_MIPS16
1733    && (GET_CODE (operands[2]) != CONST_INT
1734        || (INTVAL (operands[2]) != -32768 && INTVAL (operands[2]) != -0x4000))"
1735   "*
1736 {
1737   if (REGNO (operands[0]) == REGNO (operands[1]))
1738     return \"subu\\t%0,%2\";
1739   return \"subu\\t%0,%1,%2\";
1740 }"
1741   [(set_attr "type"     "arith")
1742    (set_attr "mode"     "SI")
1743    (set_attr_alternative "length"
1744                 [(if_then_else (match_operand:VOID 2 "m16_nsimm8_1" "")
1745                                (const_int 4)
1746                                (const_int 8))
1747                  (if_then_else (match_operand:VOID 2 "m16_nsimm4_1" "")
1748                                (const_int 4)
1749                                (const_int 8))
1750                  (const_int 4)])])
1751
1752
1753 \f
1754 ;;
1755 ;;  ....................
1756 ;;
1757 ;;      MULTIPLICATION
1758 ;;
1759 ;;  ....................
1760 ;;
1761
1762 ;; Early Vr4300 silicon has a CPU bug where multiplies with certain
1763 ;; operands may corrupt immediately following multiplies. This is a
1764 ;; simple fix to insert NOPs.
1765
1766 (define_expand "muldf3"
1767   [(set (match_operand:DF 0 "register_operand" "=f")
1768         (mult:DF (match_operand:DF 1 "register_operand" "f")
1769                  (match_operand:DF 2 "register_operand" "f")))]
1770   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
1771   "
1772 {
1773   if (!TARGET_MIPS4300)
1774     emit_insn (gen_muldf3_internal (operands[0], operands[1], operands[2]));
1775   else
1776     emit_insn (gen_muldf3_r4300 (operands[0], operands[1], operands[2]));
1777   DONE;
1778 }")
1779
1780 (define_insn "muldf3_internal"
1781   [(set (match_operand:DF 0 "register_operand" "=f")
1782         (mult:DF (match_operand:DF 1 "register_operand" "f")
1783                  (match_operand:DF 2 "register_operand" "f")))]
1784   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_MIPS4300"
1785   "mul.d\\t%0,%1,%2"
1786   [(set_attr "type"     "fmul")
1787    (set_attr "mode"     "DF")])
1788
1789 (define_insn "muldf3_r4300"
1790   [(set (match_operand:DF 0 "register_operand" "=f")
1791         (mult:DF (match_operand:DF 1 "register_operand" "f")
1792                  (match_operand:DF 2 "register_operand" "f")))]
1793   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_MIPS4300"
1794   "*
1795 {
1796   output_asm_insn (\"mul.d\\t%0,%1,%2\", operands);
1797   if (TARGET_4300_MUL_FIX)
1798     output_asm_insn (\"nop\", operands);
1799   return \"\";
1800 }"
1801   [(set_attr "type"     "fmul")
1802    (set_attr "mode"     "DF")
1803    (set_attr "length"   "8")])  ;; mul.d + nop
1804
1805 (define_expand "mulsf3"
1806   [(set (match_operand:SF 0 "register_operand" "=f")
1807         (mult:SF (match_operand:SF 1 "register_operand" "f")
1808                  (match_operand:SF 2 "register_operand" "f")))]
1809   "TARGET_HARD_FLOAT"
1810   "
1811 {
1812   if (!TARGET_MIPS4300)
1813     emit_insn( gen_mulsf3_internal (operands[0], operands[1], operands[2]));
1814   else
1815     emit_insn( gen_mulsf3_r4300 (operands[0], operands[1], operands[2]));
1816   DONE;
1817 }")
1818
1819 (define_insn "mulsf3_internal"
1820   [(set (match_operand:SF 0 "register_operand" "=f")
1821         (mult:SF (match_operand:SF 1 "register_operand" "f")
1822                  (match_operand:SF 2 "register_operand" "f")))]
1823   "TARGET_HARD_FLOAT && !TARGET_MIPS4300"
1824   "mul.s\\t%0,%1,%2"
1825   [(set_attr "type"     "fmul")
1826    (set_attr "mode"     "SF")])
1827
1828 (define_insn "mulsf3_r4300"
1829   [(set (match_operand:SF 0 "register_operand" "=f")
1830         (mult:SF (match_operand:SF 1 "register_operand" "f")
1831                  (match_operand:SF 2 "register_operand" "f")))]
1832   "TARGET_HARD_FLOAT && TARGET_MIPS4300"
1833   "*
1834 {
1835   output_asm_insn (\"mul.s\\t%0,%1,%2\", operands);
1836   if (TARGET_4300_MUL_FIX)
1837     output_asm_insn (\"nop\", operands);
1838   return \"\";
1839 }"
1840   [(set_attr "type"     "fmul")
1841    (set_attr "mode"     "SF")
1842    (set_attr "length"   "8")])  ;; mul.s + nop
1843
1844
1845 ;; ??? The R4000 (only) has a cpu bug.  If a double-word shift executes while
1846 ;; a multiply is in progress, it may give an incorrect result.  Avoid
1847 ;; this by keeping the mflo with the mult on the R4000.
1848
1849 (define_expand "mulsi3"
1850   [(set (match_operand:SI 0 "register_operand" "=l")
1851         (mult:SI (match_operand:SI 1 "register_operand" "d")
1852                  (match_operand:SI 2 "register_operand" "d")))
1853    (clobber (match_scratch:SI 3 "=h"))
1854    (clobber (match_scratch:SI 4 "=a"))]
1855   ""
1856   "
1857 {
1858   if (GENERATE_MULT3_SI || TARGET_MAD)
1859     emit_insn (gen_mulsi3_mult3 (operands[0], operands[1], operands[2]));
1860   else if (!TARGET_MIPS4000 || TARGET_MIPS16)
1861     emit_insn (gen_mulsi3_internal (operands[0], operands[1], operands[2]));
1862   else
1863     emit_insn (gen_mulsi3_r4000 (operands[0], operands[1], operands[2]));
1864   DONE;
1865 }")
1866
1867 (define_insn "mulsi3_mult3"
1868   [(set (match_operand:SI 0 "register_operand" "=d,l")
1869         (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1870                  (match_operand:SI 2 "register_operand" "d,d")))
1871    (clobber (match_scratch:SI 3 "=h,h"))
1872    (clobber (match_scratch:SI 4 "=l,X"))
1873    (clobber (match_scratch:SI 5 "=a,a"))]
1874   "GENERATE_MULT3_SI
1875    || TARGET_MAD"
1876   "*
1877 {
1878   if (which_alternative == 1)
1879     return \"mult\\t%1,%2\";
1880   if (TARGET_MAD
1881       || TARGET_MIPS5400
1882       || TARGET_MIPS5500
1883       || ISA_MIPS32
1884       || ISA_MIPS32R2
1885       || ISA_MIPS64)
1886     return \"mul\\t%0,%1,%2\";
1887   return \"mult\\t%0,%1,%2\";
1888 }"
1889   [(set_attr "type"     "imul")
1890    (set_attr "mode"     "SI")])
1891
1892 ;; If a register gets allocated to LO, and we spill to memory, the reload
1893 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1894 ;; if it can set the GPR directly.
1895 ;;
1896 ;; Operand 0: LO
1897 ;; Operand 1: GPR (1st multiplication operand)
1898 ;; Operand 2: GPR (2nd multiplication operand)
1899 ;; Operand 3: HI
1900 ;; Operand 4: HILO
1901 ;; Operand 5: GPR (destination)
1902 (define_peephole2
1903   [(parallel
1904        [(set (match_operand:SI 0 "register_operand" "")
1905              (mult:SI (match_operand:SI 1 "register_operand" "")
1906                       (match_operand:SI 2 "register_operand" "")))
1907         (clobber (match_operand:SI 3 "register_operand" ""))
1908         (clobber (scratch:SI))
1909         (clobber (match_operand:SI 4 "register_operand" ""))])
1910    (set (match_operand:SI 5 "register_operand" "")
1911         (match_dup 0))]
1912   "GENERATE_MULT3_SI
1913    && true_regnum (operands[0]) == LO_REGNUM
1914    && GP_REG_P (true_regnum (operands[5]))
1915    && peep2_reg_dead_p (2, operands[0])"
1916   [(parallel
1917        [(set (match_dup 5)
1918              (mult:SI (match_dup 1)
1919                       (match_dup 2)))
1920         (clobber (match_dup 3))
1921         (clobber (match_dup 0))
1922         (clobber (match_dup 4))])])
1923
1924 (define_insn "mulsi3_internal"
1925   [(set (match_operand:SI 0 "register_operand" "=l")
1926         (mult:SI (match_operand:SI 1 "register_operand" "d")
1927                  (match_operand:SI 2 "register_operand" "d")))
1928    (clobber (match_scratch:SI 3 "=h"))
1929    (clobber (match_scratch:SI 4 "=a"))]
1930   "!TARGET_MIPS4000 || TARGET_MIPS16"
1931   "mult\\t%1,%2"
1932   [(set_attr "type"     "imul")
1933    (set_attr "mode"     "SI")])
1934
1935 (define_insn "mulsi3_r4000"
1936   [(set (match_operand:SI 0 "register_operand" "=d")
1937         (mult:SI (match_operand:SI 1 "register_operand" "d")
1938                  (match_operand:SI 2 "register_operand" "d")))
1939    (clobber (match_scratch:SI 3 "=h"))
1940    (clobber (match_scratch:SI 4 "=l"))
1941    (clobber (match_scratch:SI 5 "=a"))]
1942   "TARGET_MIPS4000 && !TARGET_MIPS16"
1943   "mult\t%1,%2\;mflo\t%0"
1944   [(set_attr "type"     "imul")
1945    (set_attr "mode"     "SI")
1946    (set_attr "length"   "8")])
1947
1948 ;; Multiply-accumulate patterns
1949
1950 ;; For processors that can copy the output to a general register:
1951 ;;
1952 ;; The all-d alternative is needed because the combiner will find this
1953 ;; pattern and then register alloc/reload will move registers around to
1954 ;; make them fit, and we don't want to trigger unnecessary loads to LO.
1955 ;;
1956 ;; The last alternative should be made slightly less desirable, but adding
1957 ;; "?" to the constraint is too strong, and causes values to be loaded into
1958 ;; LO even when that's more costly.  For now, using "*d" mostly does the
1959 ;; trick.
1960 (define_insn "*mul_acc_si"
1961   [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1962         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1963                           (match_operand:SI 2 "register_operand" "d,d,d"))
1964                  (match_operand:SI 3 "register_operand" "0,l,*d")))
1965    (clobber (match_scratch:SI 4 "=h,h,h"))
1966    (clobber (match_scratch:SI 5 "=X,3,l"))
1967    (clobber (match_scratch:SI 6 "=a,a,a"))
1968    (clobber (match_scratch:SI 7 "=X,X,d"))]
1969   "(TARGET_MIPS3900
1970    || ISA_HAS_MADD_MSUB)
1971    && !TARGET_MIPS16"
1972   "*
1973 {
1974   static const char *const madd[] = { \"madd\\t%1,%2\", \"madd\\t%0,%1,%2\" };
1975   if (which_alternative == 2)
1976     return \"#\";
1977   if (ISA_HAS_MADD_MSUB && which_alternative != 0)
1978     return \"#\";
1979   return madd[which_alternative];
1980 }"
1981   [(set_attr "type"     "imadd,imadd,multi")
1982    (set_attr "mode"     "SI")
1983    (set_attr "length"   "4,4,8")])
1984
1985 ;; Split the above insn if we failed to get LO allocated.
1986 (define_split
1987   [(set (match_operand:SI 0 "register_operand" "")
1988         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
1989                           (match_operand:SI 2 "register_operand" ""))
1990                  (match_operand:SI 3 "register_operand" "")))
1991    (clobber (match_scratch:SI 4 ""))
1992    (clobber (match_scratch:SI 5 ""))
1993    (clobber (match_scratch:SI 6 ""))
1994    (clobber (match_scratch:SI 7 ""))]
1995   "reload_completed && !TARGET_DEBUG_D_MODE
1996    && GP_REG_P (true_regnum (operands[0]))
1997    && GP_REG_P (true_regnum (operands[3]))"
1998   [(parallel [(set (match_dup 7)
1999                    (mult:SI (match_dup 1) (match_dup 2)))
2000               (clobber (match_dup 4))
2001               (clobber (match_dup 5))
2002               (clobber (match_dup 6))])
2003    (set (match_dup 0) (plus:SI (match_dup 7) (match_dup 3)))]
2004   "")
2005
2006 ;; Splitter to copy result of MADD to a general register
2007 (define_split
2008   [(set (match_operand:SI                   0 "register_operand" "")
2009         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
2010                           (match_operand:SI 2 "register_operand" ""))
2011                  (match_operand:SI          3 "register_operand" "")))
2012    (clobber (match_scratch:SI               4 ""))
2013    (clobber (match_scratch:SI               5 ""))
2014    (clobber (match_scratch:SI               6 ""))
2015    (clobber (match_scratch:SI               7 ""))]
2016   "reload_completed && !TARGET_DEBUG_D_MODE
2017    && GP_REG_P (true_regnum (operands[0]))
2018    && true_regnum (operands[3]) == LO_REGNUM"
2019   [(parallel [(set (match_dup 3)
2020                    (plus:SI (mult:SI (match_dup 1) (match_dup 2))
2021                             (match_dup 3)))
2022               (clobber (match_dup 4))
2023               (clobber (match_dup 5))
2024               (clobber (match_dup 6))
2025               (clobber (match_dup 7))])
2026    (set (match_dup 0) (match_dup 3))]
2027   "")
2028
2029 (define_insn "*macc"
2030   [(set (match_operand:SI 0 "register_operand" "=l,d")
2031         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2032                           (match_operand:SI 2 "register_operand" "d,d"))
2033                  (match_operand:SI 3 "register_operand" "0,l")))
2034    (clobber (match_scratch:SI 4 "=h,h"))
2035    (clobber (match_scratch:SI 5 "=X,3"))
2036    (clobber (match_scratch:SI 6 "=a,a"))]
2037   "ISA_HAS_MACC"
2038   "*
2039 {
2040   if (which_alternative == 1)
2041     return \"macc\\t%0,%1,%2\";
2042   else if (TARGET_MIPS5500)
2043     return \"madd\\t%1,%2\";
2044   else
2045     return \"macc\\t%.,%1,%2\";
2046 }"
2047   [(set_attr "type" "imadd")
2048    (set_attr "mode" "SI")])
2049
2050 ;; Pattern generated by define_peephole2 below
2051 (define_insn "*macc2"
2052   [(set (match_operand:SI 0 "register_operand" "=l")
2053         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2054                           (match_operand:SI 2 "register_operand" "d"))
2055                  (match_dup 0)))
2056    (set (match_operand:SI 3 "register_operand" "=d")
2057         (plus:SI (mult:SI (match_dup 1)
2058                           (match_dup 2))
2059                  (match_dup 0)))
2060    (clobber (match_scratch:SI 4 "=h"))
2061    (clobber (match_scratch:SI 5 "=a"))]
2062   "ISA_HAS_MACC && reload_completed"
2063   "macc\\t%3,%1,%2"
2064   [(set_attr "type"     "imadd")
2065    (set_attr "mode"     "SI")])
2066
2067 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
2068 ;;
2069 ;; Operand 0: LO
2070 ;; Operand 1: GPR (1st multiplication operand)
2071 ;; Operand 2: GPR (2nd multiplication operand)
2072 ;; Operand 3: HI
2073 ;; Operand 4: HILO
2074 ;; Operand 5: GPR (destination)
2075 (define_peephole2
2076   [(parallel
2077        [(set (match_operand:SI 0 "register_operand" "")
2078              (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "")
2079                                (match_operand:SI 2 "register_operand" ""))
2080                       (match_dup 0)))
2081         (clobber (match_operand:SI 3 "register_operand" ""))
2082         (clobber (scratch:SI))
2083         (clobber (match_operand:SI 4 "register_operand" ""))])
2084    (set (match_operand:SI 5 "register_operand" "")
2085         (match_dup 0))]
2086   "ISA_HAS_MACC
2087    && true_regnum (operands[0]) == LO_REGNUM
2088    && GP_REG_P (true_regnum (operands[5]))"
2089   [(parallel [(set (match_dup 0)
2090                    (plus:SI (mult:SI (match_dup 1)
2091                                      (match_dup 2))
2092                             (match_dup 0)))
2093               (set (match_dup 5)
2094                    (plus:SI (mult:SI (match_dup 1)
2095                                      (match_dup 2))
2096                             (match_dup 0)))
2097               (clobber (match_dup 3))
2098               (clobber (match_dup 4))])]
2099   "")
2100
2101 ;; When we have a three-address multiplication instruction, it should
2102 ;; be faster to do a separate multiply and add, rather than moving
2103 ;; something into LO in order to use a macc instruction.
2104 ;;
2105 ;; This peephole needs a scratch register to cater for the case when one
2106 ;; of the multiplication operands is the same as the destination.
2107 ;;
2108 ;; Operand 0: GPR (scratch)
2109 ;; Operand 1: LO
2110 ;; Operand 2: GPR (addend)
2111 ;; Operand 3: GPR (destination)
2112 ;; Operand 4: GPR (1st multiplication operand)
2113 ;; Operand 5: GPR (2nd multiplication operand)
2114 ;; Operand 6: HI
2115 ;; Operand 7: HILO
2116 (define_peephole2
2117   [(match_scratch:SI 0 "d")
2118    (set (match_operand:SI 1 "register_operand" "")
2119         (match_operand:SI 2 "register_operand" ""))
2120    (match_dup 0)
2121    (parallel
2122        [(set (match_operand:SI 3 "register_operand" "")
2123              (plus:SI (mult:SI (match_operand:SI 4 "register_operand" "")
2124                                (match_operand:SI 5 "register_operand" ""))
2125                       (match_dup 1)))
2126         (clobber (match_operand:SI 6 "register_operand" ""))
2127         (clobber (match_dup 1))
2128         (clobber (match_operand:SI 7 "register_operand" ""))])]
2129   "ISA_HAS_MACC && GENERATE_MULT3_SI
2130    && true_regnum (operands[1]) == LO_REGNUM
2131    && peep2_reg_dead_p (2, operands[1])
2132    && GP_REG_P (true_regnum (operands[3]))"
2133   [(parallel [(set (match_dup 0)
2134                    (mult:SI (match_dup 4)
2135                             (match_dup 5)))
2136               (clobber (match_dup 6))
2137               (clobber (match_dup 1))
2138               (clobber (match_dup 7))])
2139    (set (match_dup 3)
2140         (plus:SI (match_dup 0)
2141                  (match_dup 2)))]
2142   "")
2143
2144 ;; Same as above, except LO is the initial target of the macc.
2145 ;;
2146 ;; Operand 0: GPR (scratch)
2147 ;; Operand 1: LO
2148 ;; Operand 2: GPR (addend)
2149 ;; Operand 3: GPR (1st multiplication operand)
2150 ;; Operand 4: GPR (2nd multiplication operand)
2151 ;; Operand 5: HI
2152 ;; Operand 6: HILO
2153 ;; Operand 7: GPR (destination)
2154 (define_peephole2
2155   [(match_scratch:SI 0 "d")
2156    (set (match_operand:SI 1 "register_operand" "")
2157         (match_operand:SI 2 "register_operand" ""))
2158    (match_dup 0)
2159    (parallel
2160        [(set (match_dup 1)
2161              (plus:SI (mult:SI (match_operand:SI 3 "register_operand" "")
2162                                (match_operand:SI 4 "register_operand" ""))
2163                       (match_dup 1)))
2164         (clobber (match_operand:SI 5 "register_operand" ""))
2165         (clobber (scratch:SI))
2166         (clobber (match_operand:SI 6 "register_operand" ""))])
2167    (match_dup 0)
2168    (set (match_operand:SI 7 "register_operand" "")
2169         (match_dup 1))]
2170   "ISA_HAS_MACC && GENERATE_MULT3_SI
2171    && true_regnum (operands[1]) == LO_REGNUM
2172    && peep2_reg_dead_p (3, operands[1])
2173    && GP_REG_P (true_regnum (operands[7]))"
2174   [(parallel [(set (match_dup 0)
2175                    (mult:SI (match_dup 3)
2176                             (match_dup 4)))
2177               (clobber (match_dup 5))
2178               (clobber (match_dup 1))
2179               (clobber (match_dup 6))])
2180    (set (match_dup 7)
2181         (plus:SI (match_dup 0)
2182                  (match_dup 2)))]
2183   "")
2184
2185 (define_insn "*mul_sub_si"
2186   [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
2187         (minus:SI (match_operand:SI 1 "register_operand" "0,l,*d")
2188                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
2189                            (match_operand:SI 3 "register_operand" "d,d,d"))))
2190    (clobber (match_scratch:SI 4 "=h,h,h"))
2191    (clobber (match_scratch:SI 5 "=X,1,l"))
2192    (clobber (match_scratch:SI 6 "=a,a,a"))
2193    (clobber (match_scratch:SI 7 "=X,X,d"))]
2194   "ISA_HAS_MADD_MSUB"
2195   "*
2196 {
2197   if (which_alternative != 0)
2198     return \"#\";
2199   return \"msub\\t%2,%3\";
2200 }"
2201   [(set_attr "type"     "imadd,multi,multi")
2202    (set_attr "mode"     "SI")
2203    (set_attr "length"   "4,8,8")])
2204
2205 ;; Split the above insn if we failed to get LO allocated.
2206 (define_split
2207   [(set (match_operand:SI 0 "register_operand" "")
2208         (minus:SI (match_operand:SI 1 "register_operand" "")
2209                   (mult:SI (match_operand:SI 2 "register_operand" "")
2210                            (match_operand:SI 3 "register_operand" ""))))
2211    (clobber (match_scratch:SI 4 ""))
2212    (clobber (match_scratch:SI 5 ""))
2213    (clobber (match_scratch:SI 6 ""))
2214    (clobber (match_scratch:SI 7 ""))]
2215   "reload_completed && !TARGET_DEBUG_D_MODE
2216    && GP_REG_P (true_regnum (operands[0]))
2217    && GP_REG_P (true_regnum (operands[1]))"
2218   [(parallel [(set (match_dup 7)
2219                    (mult:SI (match_dup 2) (match_dup 3)))
2220               (clobber (match_dup 4))
2221               (clobber (match_dup 5))
2222               (clobber (match_dup 6))])
2223    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 7)))]
2224   "")
2225
2226 ;; Splitter to copy result of MSUB to a general register
2227 (define_split
2228   [(set (match_operand:SI 0 "register_operand" "")
2229         (minus:SI (match_operand:SI 1 "register_operand" "")
2230                   (mult:SI (match_operand:SI 2 "register_operand" "")
2231                            (match_operand:SI 3 "register_operand" ""))))
2232    (clobber (match_scratch:SI 4 ""))
2233    (clobber (match_scratch:SI 5 ""))
2234    (clobber (match_scratch:SI 6 ""))
2235    (clobber (match_scratch:SI 7 ""))]
2236   "reload_completed && !TARGET_DEBUG_D_MODE
2237    && GP_REG_P (true_regnum (operands[0]))
2238    && true_regnum (operands[1]) == LO_REGNUM"
2239   [(parallel [(set (match_dup 1)
2240                    (minus:SI (match_dup 1)
2241                              (mult:SI (match_dup 2) (match_dup 3))))
2242               (clobber (match_dup 4))
2243               (clobber (match_dup 5))
2244               (clobber (match_dup 6))
2245               (clobber (match_dup 7))])
2246    (set (match_dup 0) (match_dup 1))]
2247   "")
2248
2249 (define_insn "*muls"
2250   [(set (match_operand:SI                  0 "register_operand" "=l,d")
2251         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2252                          (match_operand:SI 2 "register_operand" "d,d"))))
2253    (clobber (match_scratch:SI              3                    "=h,h"))
2254    (clobber (match_scratch:SI              4                    "=a,a"))
2255    (clobber (match_scratch:SI              5                    "=X,l"))]
2256   "ISA_HAS_MULS"
2257   "@
2258    muls\\t$0,%1,%2
2259    muls\\t%0,%1,%2"
2260   [(set_attr "type"     "imul")
2261    (set_attr "mode"     "SI")])
2262
2263 (define_insn "*msac"
2264   [(set (match_operand:SI 0 "register_operand" "=l,d")
2265         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
2266                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
2267                            (match_operand:SI 3 "register_operand" "d,d"))))
2268    (clobber (match_scratch:SI 4 "=h,h"))
2269    (clobber (match_scratch:SI 5 "=X,1"))
2270    (clobber (match_scratch:SI 6 "=a,a"))]
2271   "ISA_HAS_MSAC"
2272   "*
2273 {
2274   if (which_alternative == 1)
2275     return \"msac\\t%0,%2,%3\";
2276   else if (TARGET_MIPS5500)
2277     return \"msub\\t%2,%3\";
2278   else
2279     return \"msac\\t$0,%2,%3\";
2280 }"
2281   [(set_attr "type"     "imadd")
2282    (set_attr "mode"     "SI")])
2283
2284 (define_expand "muldi3"
2285   [(set (match_operand:DI 0 "register_operand" "=l")
2286         (mult:DI (match_operand:DI 1 "register_operand" "d")
2287                  (match_operand:DI 2 "register_operand" "d")))
2288    (clobber (match_scratch:DI 3 "=h"))
2289    (clobber (match_scratch:DI 4 "=a"))]
2290   "TARGET_64BIT"
2291
2292   "
2293 {
2294   if (GENERATE_MULT3_DI || TARGET_MIPS4000)
2295     emit_insn (gen_muldi3_internal2 (operands[0], operands[1], operands[2]));
2296   else
2297     emit_insn (gen_muldi3_internal (operands[0], operands[1], operands[2]));
2298   DONE;
2299 }")
2300
2301 (define_insn "muldi3_internal"
2302   [(set (match_operand:DI 0 "register_operand" "=l")
2303         (mult:DI (match_operand:DI 1 "register_operand" "d")
2304                  (match_operand:DI 2 "register_operand" "d")))
2305    (clobber (match_scratch:DI 3 "=h"))
2306    (clobber (match_scratch:DI 4 "=a"))]
2307   "TARGET_64BIT && !TARGET_MIPS4000"
2308   "dmult\\t%1,%2"
2309   [(set_attr "type"     "imul")
2310    (set_attr "mode"     "DI")])
2311
2312 (define_insn "muldi3_internal2"
2313   [(set (match_operand:DI 0 "register_operand" "=d")
2314         (mult:DI (match_operand:DI 1 "register_operand" "d")
2315                  (match_operand:DI 2 "register_operand" "d")))
2316    (clobber (match_scratch:DI 3 "=h"))
2317    (clobber (match_scratch:DI 4 "=l"))
2318    (clobber (match_scratch:DI 5 "=a"))]
2319   "TARGET_64BIT && (GENERATE_MULT3_DI || TARGET_MIPS4000)"
2320   {
2321     if (GENERATE_MULT3_DI)
2322       return "dmult\t%0,%1,%2";
2323     else
2324       return "dmult\t%1,%2\n\tmflo\t%0";
2325   }
2326   [(set_attr "type"     "imul")
2327    (set_attr "mode"     "DI")
2328    (set (attr "length")
2329         (if_then_else (ne (symbol_ref "GENERATE_MULT3_DI") (const_int 0))
2330                       (const_int 4)
2331                       (const_int 8)))])
2332
2333 ;; ??? We could define a mulditi3 pattern when TARGET_64BIT.
2334
2335 (define_expand "mulsidi3"
2336   [(set (match_operand:DI 0 "register_operand" "=x")
2337         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2338                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2339   ""
2340   "
2341 {
2342   if (TARGET_64BIT)
2343     emit_insn (gen_mulsidi3_64bit (operands[0], operands[1], operands[2]));
2344   else
2345     emit_insn (gen_mulsidi3_internal (operands[0], operands[1], operands[2]));
2346   DONE;
2347 }")
2348
2349 (define_insn "mulsidi3_internal"
2350   [(set (match_operand:DI 0 "register_operand" "=x")
2351         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2352                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2353    (clobber (match_scratch:SI 3 "=a"))]
2354   "!TARGET_64BIT"
2355   "mult\\t%1,%2"
2356   [(set_attr "type"     "imul")
2357    (set_attr "mode"     "SI")])
2358
2359 (define_insn "mulsidi3_64bit"
2360   [(set (match_operand:DI 0 "register_operand" "=a")
2361         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2362                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2363    (clobber (match_scratch:DI 3 "=l"))
2364    (clobber (match_scratch:DI 4 "=h"))]
2365   "TARGET_64BIT"
2366   "mult\\t%1,%2"
2367   [(set_attr "type"     "imul")
2368    (set_attr "mode"     "SI")])
2369
2370 (define_expand "umulsidi3"
2371   [(set (match_operand:DI 0 "register_operand" "=x")
2372         (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2373                  (zero_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2374   ""
2375   "
2376 {
2377   if (TARGET_64BIT)
2378     emit_insn (gen_umulsidi3_64bit (operands[0], operands[1], operands[2]));
2379   else
2380     emit_insn (gen_umulsidi3_internal (operands[0], operands[1], operands[2]));
2381
2382   DONE;
2383 }")
2384
2385
2386 (define_insn "umulsidi3_internal"
2387   [(set (match_operand:DI 0 "register_operand" "=x")
2388         (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2389                  (zero_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2390    (clobber (match_scratch:SI 3 "=a"))]
2391   "!TARGET_64BIT"
2392   "multu\\t%1,%2"
2393   [(set_attr "type"     "imul")
2394    (set_attr "mode"     "SI")])
2395
2396 (define_insn "umulsidi3_64bit"
2397   [(set (match_operand:DI 0 "register_operand" "=a")
2398         (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2399                  (zero_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2400    (clobber (match_scratch:DI 3 "=l"))
2401    (clobber (match_scratch:DI 4 "=h"))]
2402   "TARGET_64BIT"
2403   "multu\\t%1,%2"
2404   [(set_attr "type"     "imul")
2405    (set_attr "mode"     "SI")])
2406
2407 ;; Widening multiply with negation.  It isn't worth using this pattern
2408 ;; for 64-bit code since the reload sequence for HILO_REGNUM is so long.
2409 (define_insn "*muls_di"
2410   [(set (match_operand:DI 0 "register_operand" "=x")
2411         (neg:DI
2412          (mult:DI
2413           (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2414           (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))))
2415    (clobber (match_scratch:SI 3 "=a"))]
2416   "!TARGET_64BIT && ISA_HAS_MULS"
2417   "muls\\t$0,%1,%2"
2418   [(set_attr "type"     "imul")
2419    (set_attr "length"   "4")
2420    (set_attr "mode"     "SI")])
2421
2422 (define_insn "*umuls_di"
2423   [(set (match_operand:DI 0 "register_operand" "=x")
2424         (neg:DI
2425          (mult:DI
2426           (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2427           (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))))
2428    (clobber (match_scratch:SI 3 "=a"))]
2429   "!TARGET_64BIT && ISA_HAS_MULS"
2430   "mulsu\\t$0,%1,%2"
2431   [(set_attr "type"     "imul")
2432    (set_attr "length"   "4")
2433    (set_attr "mode"     "SI")])
2434
2435 ;; Not used for 64-bit code: see comment for *muls_di.
2436 (define_insn "*smsac_di"
2437   [(set (match_operand:DI 0 "register_operand" "=x")
2438         (minus:DI (match_operand:DI 3 "register_operand" "0")
2439                   (mult:DI
2440                    (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2441                    (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))))
2442    (clobber (match_scratch:SI 4 "=a"))]
2443   "!TARGET_64BIT && ISA_HAS_MSAC"
2444   "*
2445 {
2446   if (TARGET_MIPS5500)
2447     return \"msub\\t%1,%2\";
2448   else
2449     return \"msac\\t$0,%1,%2\";
2450 }"
2451   [(set_attr "type"     "imadd")
2452    (set_attr "length"   "4")
2453    (set_attr "mode"     "SI")])
2454
2455 (define_insn "*umsac_di"
2456   [(set (match_operand:DI 0 "register_operand" "=x")
2457         (minus:DI (match_operand:DI 3 "register_operand" "0")
2458                   (mult:DI
2459                    (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2460                    (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))))
2461    (clobber (match_scratch:SI 4 "=a"))]
2462   "!TARGET_64BIT && ISA_HAS_MSAC"
2463   "*
2464 {
2465   if (TARGET_MIPS5500)
2466     return \"msubu\\t%1,%2\";
2467   else
2468     return \"msacu\\t$0,%1,%2\";
2469 }"
2470   [(set_attr "type"     "imadd")
2471    (set_attr "length"   "4")
2472    (set_attr "mode"     "SI")])
2473
2474 ;; _highpart patterns
2475 (define_expand "umulsi3_highpart"
2476   [(set (match_operand:SI 0 "register_operand" "=h")
2477         (truncate:SI
2478          (lshiftrt:DI
2479           (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2480                    (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))
2481           (const_int 32))))]
2482   ""
2483   "
2484 {
2485   if (ISA_HAS_MULHI)
2486     emit_insn (gen_umulsi3_highpart_mulhi_internal (operands[0], operands[1],
2487                                                     operands[2]));
2488   else
2489     emit_insn (gen_umulsi3_highpart_internal (operands[0], operands[1],
2490                                               operands[2]));
2491   DONE;
2492 }")
2493
2494 (define_insn "umulsi3_highpart_internal"
2495   [(set (match_operand:SI 0 "register_operand" "=h")
2496         (truncate:SI
2497          (lshiftrt:DI
2498           (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2499                    (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))
2500           (const_int 32))))
2501    (clobber (match_scratch:SI 3 "=l"))
2502    (clobber (match_scratch:SI 4 "=a"))]
2503   "!ISA_HAS_MULHI"
2504   "multu\\t%1,%2"
2505   [(set_attr "type"   "imul")
2506    (set_attr "mode"   "SI")
2507    (set_attr "length" "4")])
2508
2509 (define_insn "umulsi3_highpart_mulhi_internal"
2510   [(set (match_operand:SI 0 "register_operand" "=h,d")
2511         (truncate:SI
2512          (lshiftrt:DI
2513           (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2514                    (zero_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
2515           (const_int 32))))
2516    (clobber (match_scratch:SI 3 "=l,l"))
2517    (clobber (match_scratch:SI 4 "=a,a"))
2518    (clobber (match_scratch:SI 5 "=X,h"))]
2519   "ISA_HAS_MULHI"
2520   "@
2521    multu\\t%1,%2
2522    mulhiu\\t%0,%1,%2"
2523   [(set_attr "type"   "imul")
2524    (set_attr "mode"   "SI")
2525    (set_attr "length" "4")])
2526
2527 (define_insn "umulsi3_highpart_neg_mulhi_internal"
2528   [(set (match_operand:SI 0 "register_operand" "=h,d")
2529         (truncate:SI
2530          (lshiftrt:DI
2531           (neg:DI
2532            (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2533                     (zero_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
2534           (const_int 32))))
2535    (clobber (match_scratch:SI 3 "=l,l"))
2536    (clobber (match_scratch:SI 4 "=a,a"))
2537    (clobber (match_scratch:SI 5 "=X,h"))]
2538   "ISA_HAS_MULHI"
2539   "@
2540    mulshiu\\t%.,%1,%2
2541    mulshiu\\t%0,%1,%2"
2542   [(set_attr "type"   "imul")
2543    (set_attr "mode"   "SI")
2544    (set_attr "length" "4")])
2545
2546 (define_expand "smulsi3_highpart"
2547   [(set (match_operand:SI 0 "register_operand" "=h")
2548         (truncate:SI
2549          (lshiftrt:DI
2550           (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2551                    (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))
2552          (const_int 32))))]
2553   ""
2554   "
2555 {
2556   if (ISA_HAS_MULHI)
2557     emit_insn (gen_smulsi3_highpart_mulhi_internal (operands[0], operands[1],
2558                                                     operands[2]));
2559   else
2560     emit_insn (gen_smulsi3_highpart_internal (operands[0], operands[1],
2561                                               operands[2]));
2562   DONE;
2563 }")
2564
2565 (define_insn "smulsi3_highpart_internal"
2566   [(set (match_operand:SI 0 "register_operand" "=h")
2567         (truncate:SI
2568          (lshiftrt:DI
2569           (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2570                    (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))
2571           (const_int 32))))
2572    (clobber (match_scratch:SI 3 "=l"))
2573    (clobber (match_scratch:SI 4 "=a"))]
2574   "!ISA_HAS_MULHI"
2575   "mult\\t%1,%2"
2576   [(set_attr "type"     "imul")
2577    (set_attr "mode"     "SI")
2578    (set_attr "length"   "4")])
2579
2580 (define_insn "smulsi3_highpart_mulhi_internal"
2581   [(set (match_operand:SI 0 "register_operand" "=h,d")
2582         (truncate:SI
2583          (lshiftrt:DI
2584           (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2585                    (sign_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
2586           (const_int 32))))
2587    (clobber (match_scratch:SI 3 "=l,l"))
2588    (clobber (match_scratch:SI 4 "=a,a"))
2589    (clobber (match_scratch:SI 5 "=X,h"))]
2590   "ISA_HAS_MULHI"
2591   "@
2592    mult\\t%1,%2
2593    mulhi\\t%0,%1,%2"
2594   [(set_attr "type"   "imul")
2595    (set_attr "mode"   "SI")
2596    (set_attr "length" "4")])
2597
2598 (define_insn "smulsi3_highpart_neg_mulhi_internal"
2599   [(set (match_operand:SI 0 "register_operand" "=h,d")
2600         (truncate:SI
2601          (lshiftrt:DI
2602           (neg:DI
2603            (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
2604                     (sign_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
2605           (const_int 32))))
2606    (clobber (match_scratch:SI 3 "=l,l"))
2607    (clobber (match_scratch:SI 4 "=a,a"))
2608    (clobber (match_scratch:SI 5 "=X,h"))]
2609   "ISA_HAS_MULHI"
2610   "@
2611    mulshi\\t%.,%1,%2
2612    mulshi\\t%0,%1,%2"
2613   [(set_attr "type"   "imul")
2614    (set_attr "mode"   "SI")])
2615
2616 (define_insn "smuldi3_highpart"
2617   [(set (match_operand:DI 0 "register_operand" "=h")
2618         (truncate:DI
2619          (lshiftrt:TI
2620           (mult:TI
2621            (sign_extend:TI (match_operand:DI 1 "register_operand" "d"))
2622            (sign_extend:TI (match_operand:DI 2 "register_operand" "d")))
2623          (const_int 64))))
2624    (clobber (match_scratch:DI 3 "=l"))
2625    (clobber (match_scratch:DI 4 "=a"))]
2626   "TARGET_64BIT"
2627   "dmult\\t%1,%2"
2628   [(set_attr "type"     "imul")
2629    (set_attr "mode"     "DI")])
2630
2631 (define_insn "umuldi3_highpart"
2632   [(set (match_operand:DI 0 "register_operand" "=h")
2633         (truncate:DI
2634          (lshiftrt:TI
2635           (mult:TI
2636            (zero_extend:TI (match_operand:DI 1 "register_operand" "d"))
2637            (zero_extend:TI (match_operand:DI 2 "register_operand" "d")))
2638           (const_int 64))))
2639    (clobber (match_scratch:DI 3 "=l"))
2640    (clobber (match_scratch:DI 4 "=a"))]
2641   "TARGET_64BIT"
2642   "dmultu\\t%1,%2"
2643   [(set_attr "type"     "imul")
2644    (set_attr "mode"     "DI")])
2645
2646
2647 ;; The R4650 supports a 32 bit multiply/ 64 bit accumulate
2648 ;; instruction.  The HI/LO registers are used as a 64 bit accumulator.
2649
2650 (define_insn "madsi"
2651   [(set (match_operand:SI 0 "register_operand" "+l")
2652         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2653                           (match_operand:SI 2 "register_operand" "d"))
2654                  (match_dup 0)))
2655    (clobber (match_scratch:SI 3 "=h"))
2656    (clobber (match_scratch:SI 4 "=a"))]
2657   "TARGET_MAD"
2658   "mad\\t%1,%2"
2659   [(set_attr "type"     "imadd")
2660    (set_attr "mode"     "SI")])
2661
2662 ;; Only use this pattern in 32-bit code: see *muls_di.
2663 (define_insn "*umul_acc_di"
2664   [(set (match_operand:DI 0 "register_operand" "=x")
2665         (plus:DI
2666          (mult:DI (zero_extend:DI (match_operand:SI 1 "register_operand" "d"))
2667                   (zero_extend:DI (match_operand:SI 2 "register_operand" "d")))
2668          (match_operand:DI 3 "register_operand" "0")))
2669    (clobber (match_scratch:SI 4 "=a"))]
2670   "(TARGET_MAD || ISA_HAS_MACC)
2671    && !TARGET_64BIT"
2672   "*
2673 {
2674   if (TARGET_MAD)
2675     return \"madu\\t%1,%2\";
2676   else if (TARGET_MIPS5500)
2677     return \"maddu\\t%1,%2\";
2678   else
2679     return \"maccu\\t%.,%1,%2\";
2680 }"
2681   [(set_attr "type"   "imadd")
2682    (set_attr "mode"   "SI")])
2683
2684
2685 (define_insn "*smul_acc_di"
2686   [(set (match_operand:DI 0 "register_operand" "=x")
2687         (plus:DI
2688          (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2689                   (sign_extend:DI (match_operand:SI 2 "register_operand" "d")))
2690          (match_operand:DI 3 "register_operand" "0")))
2691    (clobber (match_scratch:SI 4 "=a"))]
2692   "(TARGET_MAD || ISA_HAS_MACC)
2693    && !TARGET_64BIT"
2694   "*
2695 {
2696   if (TARGET_MAD)
2697     return \"mad\\t%1,%2\";
2698   else if (TARGET_MIPS5500)
2699     return \"madd\\t%1,%2\";
2700   else
2701     return \"macc\\t%.,%1,%2\";
2702 }"
2703   [(set_attr "type"   "imadd")
2704    (set_attr "mode"   "SI")])
2705
2706 ;; Floating point multiply accumulate instructions.
2707
2708 (define_insn ""
2709   [(set (match_operand:DF 0 "register_operand" "=f")
2710         (plus:DF (mult:DF (match_operand:DF 1 "register_operand" "f")
2711                           (match_operand:DF 2 "register_operand" "f"))
2712                  (match_operand:DF 3 "register_operand" "f")))]
2713   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2714   "madd.d\\t%0,%3,%1,%2"
2715   [(set_attr "type"     "fmadd")
2716    (set_attr "mode"     "DF")])
2717
2718 (define_insn ""
2719   [(set (match_operand:SF 0 "register_operand" "=f")
2720         (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "f")
2721                           (match_operand:SF 2 "register_operand" "f"))
2722                  (match_operand:SF 3 "register_operand" "f")))]
2723   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2724   "madd.s\\t%0,%3,%1,%2"
2725   [(set_attr "type"     "fmadd")
2726    (set_attr "mode"     "SF")])
2727
2728 (define_insn ""
2729   [(set (match_operand:DF 0 "register_operand" "=f")
2730         (minus:DF (mult:DF (match_operand:DF 1 "register_operand" "f")
2731                            (match_operand:DF 2 "register_operand" "f"))
2732                   (match_operand:DF 3 "register_operand" "f")))]
2733   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2734   "msub.d\\t%0,%3,%1,%2"
2735   [(set_attr "type"     "fmadd")
2736    (set_attr "mode"     "DF")])
2737
2738 (define_insn ""
2739   [(set (match_operand:SF 0 "register_operand" "=f")
2740         (minus:SF (mult:SF (match_operand:SF 1 "register_operand" "f")
2741                            (match_operand:SF 2 "register_operand" "f"))
2742                   (match_operand:SF 3 "register_operand" "f")))]
2743
2744   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2745   "msub.s\\t%0,%3,%1,%2"
2746   [(set_attr "type"     "fmadd")
2747    (set_attr "mode"     "SF")])
2748
2749 (define_insn ""
2750   [(set (match_operand:DF 0 "register_operand" "=f")
2751         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "register_operand" "f")
2752                                   (match_operand:DF 2 "register_operand" "f"))
2753                          (match_operand:DF 3 "register_operand" "f"))))]
2754   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2755   "nmadd.d\\t%0,%3,%1,%2"
2756   [(set_attr "type"     "fmadd")
2757    (set_attr "mode"     "DF")])
2758
2759 (define_insn ""
2760   [(set (match_operand:SF 0 "register_operand" "=f")
2761         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "register_operand" "f")
2762                                   (match_operand:SF 2 "register_operand" "f"))
2763                          (match_operand:SF 3 "register_operand" "f"))))]
2764   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2765   "nmadd.s\\t%0,%3,%1,%2"
2766   [(set_attr "type"     "fmadd")
2767    (set_attr "mode"     "SF")])
2768
2769 (define_insn ""
2770   [(set (match_operand:DF 0 "register_operand" "=f")
2771         (minus:DF (match_operand:DF 1 "register_operand" "f")
2772                   (mult:DF (match_operand:DF 2 "register_operand" "f")
2773                            (match_operand:DF 3 "register_operand" "f"))))]
2774   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_FUSED_MADD"
2775   "nmsub.d\\t%0,%1,%2,%3"
2776   [(set_attr "type"     "fmadd")
2777    (set_attr "mode"     "DF")])
2778
2779 (define_insn ""
2780   [(set (match_operand:SF 0 "register_operand" "=f")
2781         (minus:SF (match_operand:SF 1 "register_operand" "f")
2782                   (mult:SF (match_operand:SF 2 "register_operand" "f")
2783                            (match_operand:SF 3 "register_operand" "f"))))]
2784   "ISA_HAS_NMADD_NMSUB && TARGET_HARD_FLOAT && TARGET_FUSED_MADD"
2785   "nmsub.s\\t%0,%1,%2,%3"
2786   [(set_attr "type"     "fmadd")
2787    (set_attr "mode"     "SF")])
2788 \f
2789 ;;
2790 ;;  ....................
2791 ;;
2792 ;;      DIVISION and REMAINDER
2793 ;;
2794 ;;  ....................
2795 ;;
2796
2797 (define_insn "divdf3"
2798   [(set (match_operand:DF 0 "register_operand" "=f")
2799         (div:DF (match_operand:DF 1 "register_operand" "f")
2800                 (match_operand:DF 2 "register_operand" "f")))]
2801   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2802   "div.d\\t%0,%1,%2"
2803   [(set_attr "type"     "fdiv")
2804    (set_attr "mode"     "DF")])
2805
2806 (define_insn "divsf3"
2807   [(set (match_operand:SF 0 "register_operand" "=f")
2808         (div:SF (match_operand:SF 1 "register_operand" "f")
2809                 (match_operand:SF 2 "register_operand" "f")))]
2810   "TARGET_HARD_FLOAT"
2811   "div.s\\t%0,%1,%2"
2812   [(set_attr "type"     "fdiv")
2813    (set_attr "mode"     "SF")])
2814
2815 (define_insn ""
2816   [(set (match_operand:DF 0 "register_operand" "=f")
2817         (div:DF (match_operand:DF 1 "const_float_1_operand" "")
2818                 (match_operand:DF 2 "register_operand" "f")))]
2819   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && flag_unsafe_math_optimizations"
2820   "recip.d\\t%0,%2"
2821   [(set_attr "type"     "fdiv")
2822    (set_attr "mode"     "DF")])
2823
2824 (define_insn ""
2825   [(set (match_operand:SF 0 "register_operand" "=f")
2826         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
2827                 (match_operand:SF 2 "register_operand" "f")))]
2828   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
2829   "recip.s\\t%0,%2"
2830   [(set_attr "type"     "fdiv")
2831    (set_attr "mode"     "SF")])
2832
2833 ;; If optimizing, prefer the divmod functions over separate div and
2834 ;; mod functions, since this will allow using one instruction for both
2835 ;; the quotient and remainder.  At present, the divmod is not moved out
2836 ;; of loops if it is constant within the loop, so allow -mdebugc to
2837 ;; use the old method of doing things.
2838
2839 ;; 64 is the multiply/divide hi register
2840 ;; 65 is the multiply/divide lo register
2841
2842 ;; ??? We can't accept constants here, because the MIPS assembler will replace
2843 ;; a divide by power of 2 with a shift, and then the remainder is no longer
2844 ;; available.
2845
2846 (define_expand "divmodsi4"
2847   [(set (match_operand:SI 0 "register_operand" "=d")
2848         (div:SI (match_operand:SI 1 "register_operand" "d")
2849                 (match_operand:SI 2 "register_operand" "d")))
2850    (set (match_operand:SI 3 "register_operand" "=d")
2851         (mod:SI (match_dup 1)
2852                 (match_dup 2)))
2853    (clobber (match_scratch:SI 4 "=l"))
2854    (clobber (match_scratch:SI 5 "=h"))
2855    (clobber (match_scratch:SI 6 "=a"))]
2856   "optimize"
2857   "
2858 {
2859   emit_insn (gen_divmodsi4_internal (operands[0], operands[1], operands[2],
2860              operands[3]));
2861   if (!TARGET_NO_CHECK_ZERO_DIV)
2862     {
2863       emit_insn (gen_div_trap (operands[2],
2864                                GEN_INT (0),
2865                                GEN_INT (0x7)));
2866     }
2867   if (TARGET_CHECK_RANGE_DIV)
2868     {
2869       emit_insn (gen_div_trap (operands[2],
2870                                copy_to_mode_reg (SImode, GEN_INT (-1)),
2871                                GEN_INT (0x6)));
2872       emit_insn (gen_div_trap (operands[2],
2873                                copy_to_mode_reg (SImode,
2874                                                  GEN_INT
2875                                                  (trunc_int_for_mode
2876                                                   (BITMASK_HIGH, SImode))),
2877                                GEN_INT (0x6)));
2878     }
2879
2880   DONE;
2881 }")
2882
2883 (define_insn "divmodsi4_internal"
2884   [(set (match_operand:SI 0 "register_operand" "=l")
2885         (div:SI (match_operand:SI 1 "register_operand" "d")
2886                 (match_operand:SI 2 "register_operand" "d")))
2887    (set (match_operand:SI 3 "register_operand" "=h")
2888         (mod:SI (match_dup 1)
2889                 (match_dup 2)))
2890    (clobber (match_scratch:SI 4 "=a"))]
2891   "optimize"
2892   "div\\t$0,%1,%2"
2893   [(set_attr "type"     "idiv")
2894    (set_attr "mode"     "SI")])
2895
2896 (define_expand "divmoddi4"
2897   [(set (match_operand:DI 0 "register_operand" "=d")
2898         (div:DI (match_operand:DI 1 "register_operand" "d")
2899                 (match_operand:DI 2 "register_operand" "d")))
2900    (set (match_operand:DI 3 "register_operand" "=d")
2901         (mod:DI (match_dup 1)
2902                 (match_dup 2)))
2903    (clobber (match_scratch:DI 4 "=l"))
2904    (clobber (match_scratch:DI 5 "=h"))
2905    (clobber (match_scratch:DI 6 "=a"))]
2906   "TARGET_64BIT && optimize"
2907   "
2908 {
2909   emit_insn (gen_divmoddi4_internal (operands[0], operands[1], operands[2],
2910              operands[3]));
2911   if (!TARGET_NO_CHECK_ZERO_DIV)
2912     {
2913       emit_insn (gen_div_trap (operands[2],
2914                                GEN_INT (0),
2915                                GEN_INT (0x7)));
2916     }
2917   if (TARGET_CHECK_RANGE_DIV)
2918     {
2919       emit_insn (gen_div_trap (operands[2],
2920                                copy_to_mode_reg (DImode, GEN_INT (-1)),
2921                                GEN_INT (0x6)));
2922       emit_insn (gen_div_trap (operands[2],
2923                                copy_to_mode_reg (DImode,
2924                                                  GEN_INT (BITMASK_HIGH)),
2925                                GEN_INT (0x6)));
2926     }
2927
2928   DONE;
2929 }")
2930
2931 (define_insn "divmoddi4_internal"
2932   [(set (match_operand:DI 0 "register_operand" "=l")
2933         (div:DI (match_operand:DI 1 "register_operand" "d")
2934                 (match_operand:DI 2 "register_operand" "d")))
2935    (set (match_operand:DI 3 "register_operand" "=h")
2936         (mod:DI (match_dup 1)
2937                 (match_dup 2)))
2938    (clobber (match_scratch:DI 4 "=a"))]
2939   "TARGET_64BIT && optimize"
2940   "ddiv\\t$0,%1,%2"
2941   [(set_attr "type"     "idiv")
2942    (set_attr "mode"     "SI")])
2943
2944 (define_expand "udivmodsi4"
2945   [(set (match_operand:SI 0 "register_operand" "=d")
2946         (udiv:SI (match_operand:SI 1 "register_operand" "d")
2947                  (match_operand:SI 2 "register_operand" "d")))
2948    (set (match_operand:SI 3 "register_operand" "=d")
2949         (umod:SI (match_dup 1)
2950                  (match_dup 2)))
2951    (clobber (match_scratch:SI 4 "=l"))
2952    (clobber (match_scratch:SI 5 "=h"))
2953    (clobber (match_scratch:SI 6 "=a"))]
2954   "optimize"
2955   "
2956 {
2957   emit_insn (gen_udivmodsi4_internal (operands[0], operands[1], operands[2],
2958                                       operands[3]));
2959   if (!TARGET_NO_CHECK_ZERO_DIV)
2960     {
2961       emit_insn (gen_div_trap (operands[2],
2962                                GEN_INT (0),
2963                                GEN_INT (0x7)));
2964     }
2965
2966   DONE;
2967 }")
2968
2969 (define_insn "udivmodsi4_internal"
2970   [(set (match_operand:SI 0 "register_operand" "=l")
2971         (udiv:SI (match_operand:SI 1 "register_operand" "d")
2972                  (match_operand:SI 2 "register_operand" "d")))
2973    (set (match_operand:SI 3 "register_operand" "=h")
2974         (umod:SI (match_dup 1)
2975                  (match_dup 2)))
2976    (clobber (match_scratch:SI 4 "=a"))]
2977   "optimize"
2978   "divu\\t$0,%1,%2"
2979   [(set_attr "type"     "idiv")
2980    (set_attr "mode"     "SI")])
2981
2982 (define_expand "udivmoddi4"
2983   [(set (match_operand:DI 0 "register_operand" "=d")
2984         (udiv:DI (match_operand:DI 1 "register_operand" "d")
2985                  (match_operand:DI 2 "register_operand" "d")))
2986    (set (match_operand:DI 3 "register_operand" "=d")
2987         (umod:DI (match_dup 1)
2988                  (match_dup 2)))
2989    (clobber (match_scratch:DI 4 "=l"))
2990    (clobber (match_scratch:DI 5 "=h"))
2991    (clobber (match_scratch:DI 6 "=a"))]
2992   "TARGET_64BIT && optimize"
2993   "
2994 {
2995   emit_insn (gen_udivmoddi4_internal (operands[0], operands[1], operands[2],
2996                                       operands[3]));
2997   if (!TARGET_NO_CHECK_ZERO_DIV)
2998     {
2999       emit_insn (gen_div_trap (operands[2],
3000                                GEN_INT (0),
3001                                GEN_INT (0x7)));
3002     }
3003
3004   DONE;
3005 }")
3006
3007 (define_insn "udivmoddi4_internal"
3008   [(set (match_operand:DI 0 "register_operand" "=l")
3009         (udiv:DI (match_operand:DI 1 "register_operand" "d")
3010                  (match_operand:DI 2 "register_operand" "d")))
3011    (set (match_operand:DI 3 "register_operand" "=h")
3012         (umod:DI (match_dup 1)
3013                  (match_dup 2)))
3014    (clobber (match_scratch:DI 4 "=a"))]
3015   "TARGET_64BIT && optimize"
3016   "ddivu\\t$0,%1,%2"
3017   [(set_attr "type"     "idiv")
3018    (set_attr "mode"     "SI")])
3019
3020 ;; Division trap
3021
3022 (define_expand "div_trap"
3023   [(trap_if (eq (match_operand 0 "register_operand" "d")
3024                 (match_operand 1 "true_reg_or_0_operand" "dJ"))
3025             (match_operand 2 "immediate_operand" ""))]
3026   ""
3027   "
3028 {
3029   if (TARGET_MIPS16)
3030     emit_insn (gen_div_trap_mips16 (operands[0],operands[1],operands[2]));
3031   else
3032     emit_insn (gen_div_trap_normal (operands[0],operands[1],operands[2]));
3033   DONE;
3034 }")
3035
3036 (define_insn "div_trap_normal"
3037   [(trap_if (eq (match_operand 0 "register_operand" "d,d")
3038                 (match_operand 1 "true_reg_or_0_operand" "d,J"))
3039             (match_operand 2 "immediate_operand" ""))]
3040   "!TARGET_MIPS16"
3041   "*
3042 {
3043   rtx link;
3044   int have_dep_anti = 0;
3045
3046   /* For divmod if one division is not needed then we don't need an extra
3047      divide by zero trap, which is anti dependent on previous trap */
3048   for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
3049
3050     if ((int) REG_DEP_ANTI == (int) REG_NOTE_KIND (link)
3051         && GET_CODE (XEXP (link, 0)) == INSN
3052         && GET_CODE (PATTERN (XEXP (link, 0))) == TRAP_IF
3053         && which_alternative == 1)
3054       have_dep_anti = 1;
3055   if (! have_dep_anti)
3056     {
3057       if (GENERATE_BRANCHLIKELY)
3058         {
3059           if (which_alternative == 1)
3060             return \"%(beql\\t%0,$0,1f\\n\\tbreak\\t%2\\n%~1:%)\";
3061           else
3062             return \"%(beql\\t%0,%1,1f\\n\\tbreak\\t%2\\n%~1:%)\";
3063         }
3064       else
3065         {
3066           if (which_alternative == 1)
3067             return \"%(bne\\t%0,$0,1f\\n\\tnop\\n\\tbreak\\t%2\\n%~1:%)\";
3068           else
3069             return \"%(bne\\t%0,%1,1f\\n\\tnop\\n\\tbreak\\t%2\\n%~1:%)\";
3070         }
3071     }
3072   return \"\";
3073 }"
3074   [(set_attr "type" "unknown")
3075    (set_attr "length" "12")])
3076
3077
3078 ;; The mips16 bne insns is a macro which uses reg 24 as an intermediate.
3079
3080 (define_insn "div_trap_mips16"
3081   [(trap_if (eq (match_operand 0 "register_operand" "d,d")
3082                 (match_operand 1 "true_reg_or_0_operand" "d,J"))
3083             (match_operand 2 "immediate_operand" ""))
3084    (clobber (reg:SI 24))]
3085   "TARGET_MIPS16"
3086   "*
3087 {
3088   rtx link;
3089   int have_dep_anti = 0;
3090
3091   /* For divmod if one division is not needed then we don't need an extra
3092      divide by zero trap, which is anti dependent on previous trap */
3093   for (link = LOG_LINKS (insn); link; link = XEXP (link, 1))
3094
3095     if ((int) REG_DEP_ANTI == (int) REG_NOTE_KIND (link)
3096         && GET_CODE (XEXP (link, 0)) == INSN
3097         && GET_CODE (PATTERN (XEXP (link, 0))) == TRAP_IF
3098         && which_alternative == 1)
3099       have_dep_anti = 1;
3100   if (! have_dep_anti)
3101     {
3102       /* No branch delay slots on mips16.  */
3103       if (which_alternative == 1)
3104         return \"%(bnez\\t%0,1f\\n\\tbreak\\t%2\\n%~1:%)\";
3105       else
3106         return \"%(bne\\t%0,%1,1f\\n\\tbreak\\t%2\\n%~1:%)\";
3107     }
3108   return \"\";
3109 }"
3110   [(set_attr "type" "unknown")
3111    (set_attr "length" "12")])
3112
3113 (define_expand "divsi3"
3114   [(set (match_operand:SI 0 "register_operand" "=l")
3115         (div:SI (match_operand:SI 1 "register_operand" "d")
3116                 (match_operand:SI 2 "register_operand" "d")))
3117    (clobber (match_scratch:SI 3 "=h"))
3118    (clobber (match_scratch:SI 4 "=a"))]
3119   "!optimize"
3120   "
3121 {
3122   emit_insn (gen_divsi3_internal (operands[0], operands[1], operands[2]));
3123
3124   if (!TARGET_NO_CHECK_ZERO_DIV)
3125     {
3126       emit_insn (gen_div_trap (operands[2],
3127                                GEN_INT (0),
3128                                GEN_INT (0x7)));
3129     }
3130   if (TARGET_CHECK_RANGE_DIV)
3131     {
3132       emit_insn (gen_div_trap (operands[2],
3133                                copy_to_mode_reg (SImode, GEN_INT (-1)),
3134                                GEN_INT (0x6)));
3135       emit_insn (gen_div_trap (operands[2],
3136                                copy_to_mode_reg (SImode,
3137                                                  GEN_INT
3138                                                  (trunc_int_for_mode
3139                                                   (BITMASK_HIGH, SImode))),
3140                                GEN_INT (0x6)));
3141     }
3142
3143   DONE;
3144 }")
3145
3146 (define_insn "divsi3_internal"
3147   [(set (match_operand:SI 0 "register_operand" "=l")
3148         (div:SI (match_operand:SI 1 "register_operand" "d")
3149                 (match_operand:SI 2 "nonmemory_operand" "di")))
3150    (clobber (match_scratch:SI 3 "=h"))
3151    (clobber (match_scratch:SI 4 "=a"))]
3152   "!optimize"
3153   "div\\t$0,%1,%2"
3154   [(set_attr "type"     "idiv")
3155    (set_attr "mode"     "SI")])
3156
3157 (define_expand "divdi3"
3158   [(set (match_operand:DI 0 "register_operand" "=l")
3159         (div:DI (match_operand:DI 1 "register_operand" "d")
3160                 (match_operand:DI 2 "register_operand" "d")))
3161    (clobber (match_scratch:DI 3 "=h"))
3162    (clobber (match_scratch:DI 4 "=a"))]
3163   "TARGET_64BIT && !optimize"
3164   "
3165 {
3166   emit_insn (gen_divdi3_internal (operands[0], operands[1], operands[2]));
3167   if (!TARGET_NO_CHECK_ZERO_DIV)
3168     {
3169       emit_insn (gen_div_trap (operands[2],
3170                                GEN_INT (0),
3171                                GEN_INT (0x7)));
3172     }
3173   if (TARGET_CHECK_RANGE_DIV)
3174     {
3175       emit_insn (gen_div_trap (operands[2],
3176                                copy_to_mode_reg (DImode, GEN_INT (-1)),
3177                                GEN_INT (0x6)));
3178       emit_insn (gen_div_trap (operands[2],
3179                                copy_to_mode_reg (DImode,
3180                                                  GEN_INT (BITMASK_HIGH)),
3181                                GEN_INT (0x6)));
3182     }
3183
3184   DONE;
3185 }")
3186
3187 (define_insn "divdi3_internal"
3188   [(set (match_operand:DI 0 "register_operand" "=l")
3189         (div:DI (match_operand:DI 1 "register_operand" "d")
3190                 (match_operand:DI 2 "nonmemory_operand" "di")))
3191    (clobber (match_scratch:SI 3 "=h"))
3192    (clobber (match_scratch:SI 4 "=a"))]
3193   "TARGET_64BIT && !optimize"
3194   "ddiv\\t$0,%1,%2"
3195   [(set_attr "type"     "idiv")
3196    (set_attr "mode"     "DI")])
3197
3198 (define_expand "modsi3"
3199   [(set (match_operand:SI 0 "register_operand" "=h")
3200         (mod:SI (match_operand:SI 1 "register_operand" "d")
3201                 (match_operand:SI 2 "register_operand" "d")))
3202    (clobber (match_scratch:SI 3 "=l"))
3203    (clobber (match_scratch:SI 4 "=a"))]
3204   "!optimize"
3205   "
3206 {
3207   emit_insn (gen_modsi3_internal (operands[0], operands[1], operands[2]));
3208   if (!TARGET_NO_CHECK_ZERO_DIV)
3209     {
3210       emit_insn (gen_div_trap (operands[2],
3211                                GEN_INT (0),
3212                                GEN_INT (0x7)));
3213     }
3214   if (TARGET_CHECK_RANGE_DIV)
3215     {
3216       emit_insn (gen_div_trap (operands[2],
3217                                copy_to_mode_reg (SImode, GEN_INT (-1)),
3218                                GEN_INT (0x6)));
3219       emit_insn (gen_div_trap (operands[2],
3220                                copy_to_mode_reg (SImode,
3221                                                  GEN_INT
3222                                                  (trunc_int_for_mode
3223                                                   (BITMASK_HIGH, SImode))),
3224                                GEN_INT (0x6)));
3225     }
3226
3227   DONE;
3228 }")
3229
3230 (define_insn "modsi3_internal"
3231   [(set (match_operand:SI 0 "register_operand" "=h")
3232         (mod:SI (match_operand:SI 1 "register_operand" "d")
3233                 (match_operand:SI 2 "nonmemory_operand" "di")))
3234    (clobber (match_scratch:SI 3 "=l"))
3235    (clobber (match_scratch:SI 4 "=a"))]
3236   "!optimize"
3237   "div\\t$0,%1,%2"
3238   [(set_attr "type"     "idiv")
3239    (set_attr "mode"     "SI")])
3240
3241 (define_expand "moddi3"
3242   [(set (match_operand:DI 0 "register_operand" "=h")
3243         (mod:DI (match_operand:DI 1 "register_operand" "d")
3244                 (match_operand:DI 2 "register_operand" "d")))
3245    (clobber (match_scratch:DI 3 "=l"))
3246    (clobber (match_scratch:DI 4 "=a"))]
3247   "TARGET_64BIT && !optimize"
3248   "
3249 {
3250   emit_insn (gen_moddi3_internal (operands[0], operands[1], operands[2]));
3251   if (!TARGET_NO_CHECK_ZERO_DIV)
3252     {
3253       emit_insn (gen_div_trap (operands[2],
3254                                GEN_INT (0),
3255                                GEN_INT (0x7)));
3256     }
3257   if (TARGET_CHECK_RANGE_DIV)
3258     {
3259       emit_insn (gen_div_trap (operands[2],
3260                                copy_to_mode_reg (DImode, GEN_INT (-1)),
3261                                GEN_INT (0x6)));
3262       emit_insn (gen_div_trap (operands[2],
3263                                copy_to_mode_reg (DImode,
3264                                                  GEN_INT (BITMASK_HIGH)),
3265                                GEN_INT (0x6)));
3266     }
3267
3268   DONE;
3269 }")
3270
3271 (define_insn "moddi3_internal"
3272   [(set (match_operand:DI 0 "register_operand" "=h")
3273         (mod:DI (match_operand:DI 1 "register_operand" "d")
3274                 (match_operand:DI 2 "nonmemory_operand" "di")))
3275    (clobber (match_scratch:SI 3 "=l"))
3276    (clobber (match_scratch:SI 4 "=a"))]
3277   "TARGET_64BIT && !optimize"
3278   "ddiv\\t$0,%1,%2"
3279   [(set_attr "type"     "idiv")
3280    (set_attr "mode"     "DI")])
3281
3282 (define_expand "udivsi3"
3283   [(set (match_operand:SI 0 "register_operand" "=l")
3284         (udiv:SI (match_operand:SI 1 "register_operand" "d")
3285                  (match_operand:SI 2 "register_operand" "d")))
3286    (clobber (match_scratch:SI 3 "=h"))
3287    (clobber (match_scratch:SI 4 "=a"))]
3288   "!optimize"
3289   "
3290 {
3291   emit_insn (gen_udivsi3_internal (operands[0], operands[1], operands[2]));
3292   if (!TARGET_NO_CHECK_ZERO_DIV)
3293     {
3294       emit_insn (gen_div_trap (operands[2],
3295                                GEN_INT (0),
3296                                GEN_INT (0x7)));
3297     }
3298
3299   DONE;
3300 }")
3301
3302 (define_insn "udivsi3_internal"
3303   [(set (match_operand:SI 0 "register_operand" "=l")
3304         (udiv:SI (match_operand:SI 1 "register_operand" "d")
3305                  (match_operand:SI 2 "nonmemory_operand" "di")))
3306    (clobber (match_scratch:SI 3 "=h"))
3307    (clobber (match_scratch:SI 4 "=a"))]
3308   "!optimize"
3309   "divu\\t$0,%1,%2"
3310   [(set_attr "type"     "idiv")
3311    (set_attr "mode"     "SI")])
3312
3313 (define_expand "udivdi3"
3314   [(set (match_operand:DI 0 "register_operand" "=l")
3315         (udiv:DI (match_operand:DI 1 "register_operand" "d")
3316                  (match_operand:DI 2 "register_operand" "di")))
3317    (clobber (match_scratch:DI 3 "=h"))
3318    (clobber (match_scratch:DI 4 "=a"))]
3319   "TARGET_64BIT && !optimize"
3320   "
3321 {
3322   emit_insn (gen_udivdi3_internal (operands[0], operands[1], operands[2]));
3323   if (!TARGET_NO_CHECK_ZERO_DIV)
3324     {
3325       emit_insn (gen_div_trap (operands[2],
3326                                GEN_INT (0),
3327                                GEN_INT (0x7)));
3328     }
3329
3330   DONE;
3331 }")
3332
3333 (define_insn "udivdi3_internal"
3334   [(set (match_operand:DI 0 "register_operand" "=l")
3335         (udiv:DI (match_operand:DI 1 "register_operand" "d")
3336                  (match_operand:DI 2 "nonmemory_operand" "di")))
3337    (clobber (match_scratch:SI 3 "=h"))
3338    (clobber (match_scratch:SI 4 "=a"))]
3339   "TARGET_64BIT && !optimize"
3340   "ddivu\\t$0,%1,%2"
3341   [(set_attr "type"     "idiv")
3342    (set_attr "mode"     "DI")])
3343
3344 (define_expand "umodsi3"
3345   [(set (match_operand:SI 0 "register_operand" "=h")
3346         (umod:SI (match_operand:SI 1 "register_operand" "d")
3347                  (match_operand:SI 2 "register_operand" "d")))
3348    (clobber (match_scratch:SI 3 "=l"))
3349    (clobber (match_scratch:SI 4 "=a"))]
3350   "!optimize"
3351   "
3352 {
3353   emit_insn (gen_umodsi3_internal (operands[0], operands[1], operands[2]));
3354   if (!TARGET_NO_CHECK_ZERO_DIV)
3355     {
3356       emit_insn (gen_div_trap (operands[2],
3357                                GEN_INT (0),
3358                                GEN_INT (0x7)));
3359     }
3360
3361   DONE;
3362 }")
3363
3364 (define_insn "umodsi3_internal"
3365   [(set (match_operand:SI 0 "register_operand" "=h")
3366         (umod:SI (match_operand:SI 1 "register_operand" "d")
3367                  (match_operand:SI 2 "nonmemory_operand" "di")))
3368    (clobber (match_scratch:SI 3 "=l"))
3369    (clobber (match_scratch:SI 4 "=a"))]
3370   "!optimize"
3371   "divu\\t$0,%1,%2"
3372   [(set_attr "type"     "idiv")
3373    (set_attr "mode"     "SI")])
3374
3375 (define_expand "umoddi3"
3376   [(set (match_operand:DI 0 "register_operand" "=h")
3377         (umod:DI (match_operand:DI 1 "register_operand" "d")
3378                  (match_operand:DI 2 "register_operand" "di")))
3379    (clobber (match_scratch:DI 3 "=l"))
3380    (clobber (match_scratch:DI 4 "=a"))]
3381   "TARGET_64BIT && !optimize"
3382   "
3383 {
3384   emit_insn (gen_umoddi3_internal (operands[0], operands[1], operands[2]));
3385   if (!TARGET_NO_CHECK_ZERO_DIV)
3386     {
3387       emit_insn (gen_div_trap (operands[2],
3388                                GEN_INT (0),
3389                                GEN_INT (0x7)));
3390     }
3391
3392   DONE;
3393 }")
3394
3395 (define_insn "umoddi3_internal"
3396   [(set (match_operand:DI 0 "register_operand" "=h")
3397         (umod:DI (match_operand:DI 1 "register_operand" "d")
3398                  (match_operand:DI 2 "nonmemory_operand" "di")))
3399    (clobber (match_scratch:SI 3 "=l"))
3400    (clobber (match_scratch:SI 4 "=a"))]
3401   "TARGET_64BIT && !optimize"
3402   "ddivu\\t$0,%1,%2"
3403   [(set_attr "type"     "idiv")
3404    (set_attr "mode"     "DI")])
3405 \f
3406 ;;
3407 ;;  ....................
3408 ;;
3409 ;;      SQUARE ROOT
3410 ;;
3411 ;;  ....................
3412
3413 (define_insn "sqrtdf2"
3414   [(set (match_operand:DF 0 "register_operand" "=f")
3415         (sqrt:DF (match_operand:DF 1 "register_operand" "f")))]
3416   "TARGET_HARD_FLOAT && HAVE_SQRT_P() && TARGET_DOUBLE_FLOAT"
3417   "sqrt.d\\t%0,%1"
3418   [(set_attr "type"     "fsqrt")
3419    (set_attr "mode"     "DF")])
3420
3421 (define_insn "sqrtsf2"
3422   [(set (match_operand:SF 0 "register_operand" "=f")
3423         (sqrt:SF (match_operand:SF 1 "register_operand" "f")))]
3424   "TARGET_HARD_FLOAT && HAVE_SQRT_P()"
3425   "sqrt.s\\t%0,%1"
3426   [(set_attr "type"     "fsqrt")
3427    (set_attr "mode"     "SF")])
3428
3429 (define_insn ""
3430   [(set (match_operand:DF 0 "register_operand" "=f")
3431         (div:DF (match_operand:DF 1 "const_float_1_operand" "")
3432                 (sqrt:DF (match_operand:DF 2 "register_operand" "f"))))]
3433   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && flag_unsafe_math_optimizations"
3434   "rsqrt.d\\t%0,%2"
3435   [(set_attr "type"     "frsqrt")
3436    (set_attr "mode"     "DF")])
3437
3438 (define_insn ""
3439   [(set (match_operand:SF 0 "register_operand" "=f")
3440         (div:SF (match_operand:SF 1 "const_float_1_operand" "")
3441                 (sqrt:SF (match_operand:SF 2 "register_operand" "f"))))]
3442   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && flag_unsafe_math_optimizations"
3443   "rsqrt.s\\t%0,%2"
3444   [(set_attr "type"     "frsqrt")
3445    (set_attr "mode"     "SF")])
3446
3447 \f
3448 ;;
3449 ;;  ....................
3450 ;;
3451 ;;      ABSOLUTE VALUE
3452 ;;
3453 ;;  ....................
3454
3455 ;; Do not use the integer abs macro instruction, since that signals an
3456 ;; exception on -2147483648 (sigh).
3457
3458 (define_insn "abssi2"
3459   [(set (match_operand:SI 0 "register_operand" "=d")
3460         (abs:SI (match_operand:SI 1 "register_operand" "d")))]
3461   "!TARGET_MIPS16"
3462   "*
3463 {
3464   operands[2] = const0_rtx;
3465
3466   if (REGNO (operands[0]) == REGNO (operands[1]))
3467     {
3468       if (GENERATE_BRANCHLIKELY)
3469         return \"%(bltzl\\t%1,1f\\n\\tsubu\\t%0,%z2,%0\\n%~1:%)\";
3470       else
3471         return \"bgez\\t%1,1f%#\\n\\tsubu\\t%0,%z2,%0\\n%~1:\";
3472     }
3473   else
3474     return \"%(bgez\\t%1,1f\\n\\tmove\\t%0,%1\\n\\tsubu\\t%0,%z2,%0\\n%~1:%)\";
3475 }"
3476   [(set_attr "type"     "multi")
3477    (set_attr "mode"     "SI")
3478    (set_attr "length"   "12")])
3479
3480 (define_insn "absdi2"
3481   [(set (match_operand:DI 0 "register_operand" "=d")
3482         (abs:DI (match_operand:DI 1 "register_operand" "d")))]
3483   "TARGET_64BIT && !TARGET_MIPS16"
3484   "*
3485 {
3486   unsigned int regno1;
3487   operands[2] = const0_rtx;
3488
3489   if (GET_CODE (operands[1]) == REG)
3490     regno1 = REGNO (operands[1]);
3491   else
3492     regno1 = REGNO (XEXP (operands[1], 0));
3493
3494   if (REGNO (operands[0]) == regno1)
3495     return \"%(bltzl\\t%1,1f\\n\\tdsubu\\t%0,%z2,%0\\n%~1:%)\";
3496   else
3497     return \"%(bgez\\t%1,1f\\n\\tmove\\t%0,%1\\n\\tdsubu\\t%0,%z2,%0\\n%~1:%)\";
3498 }"
3499   [(set_attr "type"     "multi")
3500    (set_attr "mode"     "DI")
3501    (set_attr "length"   "12")])
3502
3503 (define_insn "absdf2"
3504   [(set (match_operand:DF 0 "register_operand" "=f")
3505         (abs:DF (match_operand:DF 1 "register_operand" "f")))]
3506   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3507   "abs.d\\t%0,%1"
3508   [(set_attr "type"     "fabs")
3509    (set_attr "mode"     "DF")])
3510
3511 (define_insn "abssf2"
3512   [(set (match_operand:SF 0 "register_operand" "=f")
3513         (abs:SF (match_operand:SF 1 "register_operand" "f")))]
3514   "TARGET_HARD_FLOAT"
3515   "abs.s\\t%0,%1"
3516   [(set_attr "type"     "fabs")
3517    (set_attr "mode"     "SF")])
3518
3519 \f
3520 ;;
3521 ;;  ....................
3522 ;;
3523 ;;      FIND FIRST BIT INSTRUCTION
3524 ;;
3525 ;;  ....................
3526 ;;
3527
3528 (define_insn "ffssi2"
3529   [(set (match_operand:SI 0 "register_operand" "=&d")
3530         (ffs:SI (match_operand:SI 1 "register_operand" "d")))
3531    (clobber (match_scratch:SI 2 "=&d"))
3532    (clobber (match_scratch:SI 3 "=&d"))]
3533   "!TARGET_MIPS16"
3534   "*
3535 {
3536   operands[4] = const0_rtx;
3537
3538   if (optimize && find_reg_note (insn, REG_DEAD, operands[1]))
3539     return \"%(\\
3540 move\\t%0,%z4\\n\\
3541 \\tbeq\\t%1,%z4,2f\\n\\
3542 %~1:\\tand\\t%2,%1,0x0001\\n\\
3543 \\taddu\\t%0,%0,1\\n\\
3544 \\tbeq\\t%2,%z4,1b\\n\\
3545 \\tsrl\\t%1,%1,1\\n\\
3546 %~2:%)\";
3547
3548   return \"%(\\
3549 move\\t%0,%z4\\n\\
3550 \\tmove\\t%3,%1\\n\\
3551 \\tbeq\\t%3,%z4,2f\\n\\
3552 %~1:\\tand\\t%2,%3,0x0001\\n\\
3553 \\taddu\\t%0,%0,1\\n\\
3554 \\tbeq\\t%2,%z4,1b\\n\\
3555 \\tsrl\\t%3,%3,1\\n\\
3556 %~2:%)\";
3557 }"
3558   [(set_attr "type"     "multi")
3559    (set_attr "mode"     "SI")
3560    (set_attr "length"   "12")])
3561
3562 (define_insn "ffsdi2"
3563   [(set (match_operand:DI 0 "register_operand" "=&d")
3564         (ffs:DI (match_operand:DI 1 "register_operand" "d")))
3565    (clobber (match_scratch:DI 2 "=&d"))
3566    (clobber (match_scratch:DI 3 "=&d"))]
3567   "TARGET_64BIT && !TARGET_MIPS16"
3568   "*
3569 {
3570   operands[4] = const0_rtx;
3571
3572   if (optimize && find_reg_note (insn, REG_DEAD, operands[1]))
3573     return \"%(\\
3574 move\\t%0,%z4\\n\\
3575 \\tbeq\\t%1,%z4,2f\\n\\
3576 %~1:\\tand\\t%2,%1,0x0001\\n\\
3577 \\tdaddu\\t%0,%0,1\\n\\
3578 \\tbeq\\t%2,%z4,1b\\n\\
3579 \\tdsrl\\t%1,%1,1\\n\\
3580 %~2:%)\";
3581
3582   return \"%(\\
3583 move\\t%0,%z4\\n\\
3584 \\tmove\\t%3,%1\\n\\
3585 \\tbeq\\t%3,%z4,2f\\n\\
3586 %~1:\\tand\\t%2,%3,0x0001\\n\\
3587 \\tdaddu\\t%0,%0,1\\n\\
3588 \\tbeq\\t%2,%z4,1b\\n\\
3589 \\tdsrl\\t%3,%3,1\\n\\
3590 %~2:%)\";
3591 }"
3592   [(set_attr "type"     "multi")
3593    (set_attr "mode"     "DI")
3594    (set_attr "length"   "24")])
3595
3596 \f
3597 ;;
3598 ;;  ....................
3599 ;;
3600 ;;      NEGATION and ONE'S COMPLEMENT
3601 ;;
3602 ;;  ....................
3603
3604 (define_insn "negsi2"
3605   [(set (match_operand:SI 0 "register_operand" "=d")
3606         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3607   ""
3608   "*
3609 {
3610   if (TARGET_MIPS16)
3611     return \"neg\\t%0,%1\";
3612   operands[2] = const0_rtx;
3613   return \"subu\\t%0,%z2,%1\";
3614 }"
3615   [(set_attr "type"     "arith")
3616    (set_attr "mode"     "SI")])
3617
3618 (define_expand "negdi2"
3619   [(parallel [(set (match_operand:DI 0 "register_operand" "=d")
3620                    (neg:DI (match_operand:DI 1 "register_operand" "d")))
3621               (clobber (match_dup 2))])]
3622   "(TARGET_64BIT || !TARGET_DEBUG_G_MODE) && !TARGET_MIPS16"
3623   "
3624 {
3625   if (TARGET_64BIT)
3626     {
3627       emit_insn (gen_negdi2_internal_2 (operands[0], operands[1]));
3628       DONE;
3629     }
3630
3631   operands[2] = gen_reg_rtx (SImode);
3632 }")
3633
3634 (define_insn "negdi2_internal"
3635   [(set (match_operand:DI 0 "register_operand" "=d")
3636         (neg:DI (match_operand:DI 1 "register_operand" "d")))
3637    (clobber (match_operand:SI 2 "register_operand" "=d"))]
3638   "! TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
3639   "*
3640 {
3641   operands[3] = const0_rtx;
3642   return \"subu\\t%L0,%z3,%L1\;subu\\t%M0,%z3,%M1\;sltu\\t%2,%z3,%L0\;subu\\t%M0,%M0,%2\";
3643 }"
3644   [(set_attr "type"     "darith")
3645    (set_attr "mode"     "DI")
3646    (set_attr "length"   "16")])
3647
3648 (define_insn "negdi2_internal_2"
3649   [(set (match_operand:DI 0 "register_operand" "=d")
3650         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3651   "TARGET_64BIT && !TARGET_MIPS16"
3652   "*
3653 {
3654   operands[2] = const0_rtx;
3655   return \"dsubu\\t%0,%z2,%1\";
3656 }"
3657   [(set_attr "type"     "arith")
3658    (set_attr "mode"     "DI")])
3659
3660 (define_insn "negdf2"
3661   [(set (match_operand:DF 0 "register_operand" "=f")
3662         (neg:DF (match_operand:DF 1 "register_operand" "f")))]
3663   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3664   "neg.d\\t%0,%1"
3665   [(set_attr "type"     "fneg")
3666    (set_attr "mode"     "DF")])
3667
3668 (define_insn "negsf2"
3669   [(set (match_operand:SF 0 "register_operand" "=f")
3670         (neg:SF (match_operand:SF 1 "register_operand" "f")))]
3671   "TARGET_HARD_FLOAT"
3672   "neg.s\\t%0,%1"
3673   [(set_attr "type"     "fneg")
3674    (set_attr "mode"     "SF")])
3675
3676 (define_insn "one_cmplsi2"
3677   [(set (match_operand:SI 0 "register_operand" "=d")
3678         (not:SI (match_operand:SI 1 "register_operand" "d")))]
3679   ""
3680   "*
3681 {
3682   if (TARGET_MIPS16)
3683     return \"not\\t%0,%1\";
3684   operands[2] = const0_rtx;
3685   return \"nor\\t%0,%z2,%1\";
3686 }"
3687   [(set_attr "type"     "arith")
3688    (set_attr "mode"     "SI")])
3689
3690 (define_insn "one_cmpldi2"
3691   [(set (match_operand:DI 0 "register_operand" "=d")
3692         (not:DI (match_operand:DI 1 "register_operand" "d")))]
3693   "TARGET_64BIT"
3694   "*
3695 {
3696   if (TARGET_MIPS16)
3697     return \"not\\t%0,%1\";
3698   return \"nor\\t%0,%.,%1\";
3699 }"
3700   [(set_attr "type"     "darith")
3701    (set_attr "mode"     "DI")])
3702 \f
3703 ;;
3704 ;;  ....................
3705 ;;
3706 ;;      LOGICAL
3707 ;;
3708 ;;  ....................
3709 ;;
3710
3711 ;; Many of these instructions uses trivial define_expands, because we
3712 ;; want to use a different set of constraints when TARGET_MIPS16.
3713
3714 (define_expand "andsi3"
3715   [(set (match_operand:SI 0 "register_operand" "=d,d")
3716         (and:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3717                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3718   ""
3719   "
3720 {
3721   if (TARGET_MIPS16)
3722     {
3723       operands[1] = force_reg (SImode, operands[1]);
3724       operands[2] = force_reg (SImode, operands[2]);
3725     }
3726 }")
3727
3728 (define_insn ""
3729   [(set (match_operand:SI 0 "register_operand" "=d,d")
3730         (and:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3731                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3732   "!TARGET_MIPS16"
3733   "@
3734    and\\t%0,%1,%2
3735    andi\\t%0,%1,%x2"
3736   [(set_attr "type"     "arith")
3737    (set_attr "mode"     "SI")])
3738
3739 (define_insn ""
3740   [(set (match_operand:SI 0 "register_operand" "=d")
3741         (and:SI (match_operand:SI 1 "register_operand" "%0")
3742                 (match_operand:SI 2 "register_operand" "d")))]
3743   "TARGET_MIPS16"
3744   "and\\t%0,%2"
3745   [(set_attr "type"     "arith")
3746    (set_attr "mode"     "SI")])
3747
3748 (define_expand "anddi3"
3749   [(set (match_operand:DI 0 "register_operand" "")
3750         (and:DI (match_operand:DI 1 "register_operand" "")
3751                 (match_operand:DI 2 "uns_arith_operand" "")))]
3752   "TARGET_64BIT"
3753   "
3754 {
3755   if (TARGET_MIPS16)
3756     {
3757       operands[1] = force_reg (DImode, operands[1]);
3758       operands[2] = force_reg (DImode, operands[2]);
3759     }
3760 }")
3761
3762 (define_insn ""
3763   [(set (match_operand:DI 0 "register_operand" "=d,d")
3764         (and:DI (match_operand:DI 1 "register_operand" "d,d")
3765                 (match_operand:DI 2 "uns_arith_operand" "d,K")))]
3766   "TARGET_64BIT && !TARGET_MIPS16"
3767   "@
3768    and\\t%0,%1,%2
3769    andi\\t%0,%1,%x2"
3770   [(set_attr "type"     "darith")
3771    (set_attr "mode"     "DI")])
3772
3773 (define_insn ""
3774   [(set (match_operand:DI 0 "register_operand" "=d")
3775         (and:DI (match_operand:DI 1 "register_operand" "0")
3776                 (match_operand:DI 2 "register_operand" "d")))]
3777   "TARGET_64BIT && TARGET_MIPS16"
3778   "and\\t%0,%2"
3779   [(set_attr "type"     "darith")
3780    (set_attr "mode"     "DI")])
3781
3782 (define_expand "iorsi3"
3783   [(set (match_operand:SI 0 "register_operand" "=d,d")
3784         (ior:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3785                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3786   ""
3787   "
3788 {
3789   if (TARGET_MIPS16)
3790     {
3791       operands[1] = force_reg (SImode, operands[1]);
3792       operands[2] = force_reg (SImode, operands[2]);
3793     }
3794 }")
3795
3796 (define_insn ""
3797   [(set (match_operand:SI 0 "register_operand" "=d,d")
3798         (ior:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3799                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3800   "!TARGET_MIPS16"
3801   "@
3802    or\\t%0,%1,%2
3803    ori\\t%0,%1,%x2"
3804   [(set_attr "type"     "arith")
3805    (set_attr "mode"     "SI")])
3806
3807 (define_insn ""
3808   [(set (match_operand:SI 0 "register_operand" "=d")
3809         (ior:SI (match_operand:SI 1 "register_operand" "%0")
3810                 (match_operand:SI 2 "register_operand" "d")))]
3811   "TARGET_MIPS16"
3812   "or\\t%0,%2"
3813   [(set_attr "type"     "arith")
3814    (set_attr "mode"     "SI")])
3815
3816 (define_expand "iordi3"
3817   [(set (match_operand:DI 0 "register_operand" "")
3818         (ior:DI (match_operand:DI 1 "register_operand" "")
3819                 (match_operand:DI 2 "uns_arith_operand" "")))]
3820   "TARGET_64BIT"
3821   "
3822 {
3823   if (TARGET_MIPS16)
3824     {
3825       operands[1] = force_reg (DImode, operands[1]);
3826       operands[2] = force_reg (DImode, operands[2]);
3827     }
3828 }")
3829
3830 (define_insn ""
3831   [(set (match_operand:DI 0 "register_operand" "=d,d")
3832         (ior:DI (match_operand:DI 1 "register_operand" "d,d")
3833                 (match_operand:DI 2 "uns_arith_operand" "d,K")))]
3834   "TARGET_64BIT && !TARGET_MIPS16"
3835   "@
3836    or\t%0,%1,%2
3837    ori\t%0,%1,%x2"
3838   [(set_attr "type"     "darith")
3839    (set_attr "mode"     "DI")])
3840
3841 (define_insn ""
3842   [(set (match_operand:DI 0 "register_operand" "=d")
3843         (ior:DI (match_operand:DI 1 "register_operand" "0")
3844                 (match_operand:DI 2 "register_operand" "d")))]
3845   "TARGET_64BIT && TARGET_MIPS16"
3846   "or\t%0,%2"
3847   [(set_attr "type"     "darith")
3848    (set_attr "mode"     "DI")])
3849
3850 (define_expand "xorsi3"
3851   [(set (match_operand:SI 0 "register_operand" "=d,d")
3852         (xor:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3853                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3854   ""
3855   "")
3856
3857 (define_insn ""
3858   [(set (match_operand:SI 0 "register_operand" "=d,d")
3859         (xor:SI (match_operand:SI 1 "uns_arith_operand" "%d,d")
3860                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3861   "!TARGET_MIPS16"
3862   "@
3863    xor\\t%0,%1,%2
3864    xori\\t%0,%1,%x2"
3865   [(set_attr "type"     "arith")
3866    (set_attr "mode"     "SI")])
3867
3868 (define_insn ""
3869   [(set (match_operand:SI 0 "register_operand" "=d,t,t")
3870         (xor:SI (match_operand:SI 1 "uns_arith_operand" "%0,d,d")
3871                 (match_operand:SI 2 "uns_arith_operand" "d,K,d")))]
3872   "TARGET_MIPS16"
3873   "@
3874    xor\\t%0,%2
3875    cmpi\\t%1,%2
3876    cmp\\t%1,%2"
3877   [(set_attr "type"     "arith")
3878    (set_attr "mode"     "SI")
3879    (set_attr_alternative "length"
3880                 [(const_int 4)
3881                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
3882                                (const_int 4)
3883                                (const_int 8))
3884                  (const_int 4)])])
3885
3886 (define_expand "xordi3"
3887   [(set (match_operand:DI 0 "register_operand" "")
3888         (xor:DI (match_operand:DI 1 "register_operand" "")
3889                 (match_operand:DI 2 "uns_arith_operand" "")))]
3890   "TARGET_64BIT"
3891   "
3892 {
3893   if (TARGET_MIPS16)
3894     {
3895       operands[1] = force_reg (DImode, operands[1]);
3896       operands[2] = force_reg (DImode, operands[2]);
3897     }
3898 }")
3899
3900 (define_insn ""
3901   [(set (match_operand:DI 0 "register_operand" "=d,d")
3902         (xor:DI (match_operand:DI 1 "register_operand" "d,d")
3903                 (match_operand:DI 2 "uns_arith_operand" "d,K")))]
3904   "TARGET_64BIT && !TARGET_MIPS16"
3905   "@
3906    xor\t%0,%1,%2
3907    xori\t%0,%1,%x2"
3908   [(set_attr "type"     "darith")
3909    (set_attr "mode"     "DI")])
3910
3911 (define_insn ""
3912   [(set (match_operand:DI 0 "register_operand" "=d,t,t")
3913         (xor:DI (match_operand:DI 1 "register_operand" "%0,d,d")
3914                 (match_operand:DI 2 "uns_arith_operand" "d,K,d")))]
3915   "TARGET_64BIT && TARGET_MIPS16"
3916   "@
3917    xor\\t%0,%2
3918    cmpi\\t%1,%2
3919    cmp\\t%1,%2"
3920   [(set_attr "type"     "arith")
3921    (set_attr "mode"     "DI")
3922    (set_attr_alternative "length"
3923                 [(const_int 4)
3924                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
3925                                (const_int 4)
3926                                (const_int 8))
3927                  (const_int 4)])])
3928
3929 (define_insn "*norsi3"
3930   [(set (match_operand:SI 0 "register_operand" "=d")
3931         (and:SI (not:SI (match_operand:SI 1 "register_operand" "d"))
3932                 (not:SI (match_operand:SI 2 "register_operand" "d"))))]
3933   "!TARGET_MIPS16"
3934   "nor\\t%0,%z1,%z2"
3935   [(set_attr "type"     "arith")
3936    (set_attr "mode"     "SI")])
3937
3938 (define_insn "*nordi3"
3939   [(set (match_operand:DI 0 "register_operand" "=d")
3940         (and:DI (not:DI (match_operand:DI 1 "register_operand" "d"))
3941                 (not:DI (match_operand:DI 2 "register_operand" "d"))))]
3942   "TARGET_64BIT && !TARGET_MIPS16"
3943   "nor\\t%0,%z1,%z2"
3944   [(set_attr "type"     "darith")
3945    (set_attr "mode"     "DI")])
3946 \f
3947 ;;
3948 ;;  ....................
3949 ;;
3950 ;;      TRUNCATION
3951 ;;
3952 ;;  ....................
3953
3954
3955
3956 (define_insn "truncdfsf2"
3957   [(set (match_operand:SF 0 "register_operand" "=f")
3958         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3959   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3960   "cvt.s.d\\t%0,%1"
3961   [(set_attr "type"     "fcvt")
3962    (set_attr "mode"     "SF")])
3963
3964 ;; Integer truncation patterns.  Truncating SImode values to smaller
3965 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3966 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3967 ;; need to make sure that the lower 32 bits are properly sign-extended
3968 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3969 ;; smaller than SImode is equivalent to two separate truncations:
3970 ;;
3971 ;;                        A       B
3972 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3973 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3974 ;;
3975 ;; Step A needs a real instruction but step B does not.
3976
3977 (define_insn "truncdisi2"
3978   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
3979         (truncate:SI (match_operand:DI 1 "register_operand" "d,d")))]
3980   "TARGET_64BIT"
3981   "@
3982     sll\t%0,%1,0
3983     sw\t%1,%0"
3984   [(set_attr "type" "darith")
3985    (set_attr "mode" "SI")
3986    (set_attr "extended_mips16" "yes,*")])
3987
3988 (define_insn "truncdihi2"
3989   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,m")
3990         (truncate:HI (match_operand:DI 1 "register_operand" "d,d")))]
3991   "TARGET_64BIT"
3992   "@
3993     sll\t%0,%1,0
3994     sh\t%1,%0"
3995   [(set_attr "type" "darith")
3996    (set_attr "mode" "SI")
3997    (set_attr "extended_mips16" "yes,*")])
3998
3999 (define_insn "truncdiqi2"
4000   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,m")
4001         (truncate:QI (match_operand:DI 1 "register_operand" "d,d")))]
4002   "TARGET_64BIT"
4003   "@
4004     sll\t%0,%1,0
4005     sb\t%1,%0"
4006   [(set_attr "type" "darith")
4007    (set_attr "mode" "SI")
4008    (set_attr "extended_mips16" "yes,*")])
4009
4010 ;; Combiner patterns to optimize shift/truncate combinations.
4011
4012 (define_insn ""
4013   [(set (match_operand:SI 0 "register_operand" "=d")
4014         (truncate:SI (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
4015                                   (match_operand:DI 2 "small_int" "I"))))]
4016   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) >= 32"
4017   "dsra\\t%0,%1,%2"
4018   [(set_attr "type" "darith")
4019    (set_attr "mode" "SI")])
4020
4021 (define_insn ""
4022   [(set (match_operand:SI 0 "register_operand" "=d")
4023         (truncate:SI (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
4024                                   (const_int 32))))]
4025   "TARGET_64BIT && !TARGET_MIPS16"
4026   "dsra\\t%0,%1,32"
4027   [(set_attr "type" "darith")
4028    (set_attr "mode" "SI")])
4029
4030
4031 ;; Combiner patterns for truncate/sign_extend combinations.  They use
4032 ;; the shift/truncate patterns above.
4033
4034 (define_insn_and_split ""
4035   [(set (match_operand:SI 0 "register_operand" "=d")
4036         (sign_extend:SI
4037             (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
4038   "TARGET_64BIT && !TARGET_MIPS16"
4039   "#"
4040   "&& reload_completed"
4041   [(set (match_dup 2)
4042         (ashift:DI (match_dup 1)
4043                    (const_int 48)))
4044    (set (match_dup 0)
4045         (truncate:SI (ashiftrt:DI (match_dup 2)
4046                                   (const_int 48))))]
4047   { operands[2] = gen_lowpart (DImode, operands[0]); })
4048
4049 (define_insn_and_split ""
4050   [(set (match_operand:SI 0 "register_operand" "=d")
4051         (sign_extend:SI
4052             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
4053   "TARGET_64BIT && !TARGET_MIPS16"
4054   "#"
4055   "&& reload_completed"
4056   [(set (match_dup 2)
4057         (ashift:DI (match_dup 1)
4058                    (const_int 56)))
4059    (set (match_dup 0)
4060         (truncate:SI (ashiftrt:DI (match_dup 2)
4061                                   (const_int 56))))]
4062   { operands[2] = gen_lowpart (DImode, operands[0]); })
4063
4064
4065 ;; Combiner patterns to optimize truncate/zero_extend combinations.
4066
4067 (define_insn ""
4068   [(set (match_operand:SI 0 "register_operand" "=d")
4069         (zero_extend:SI (truncate:HI
4070                          (match_operand:DI 1 "register_operand" "d"))))]
4071   "TARGET_64BIT && !TARGET_MIPS16"
4072   "andi\\t%0,%1,0xffff"
4073   [(set_attr "type"     "darith")
4074    (set_attr "mode"     "SI")])
4075
4076 (define_insn ""
4077   [(set (match_operand:SI 0 "register_operand" "=d")
4078         (zero_extend:SI (truncate:QI
4079                          (match_operand:DI 1 "register_operand" "d"))))]
4080   "TARGET_64BIT && !TARGET_MIPS16"
4081   "andi\\t%0,%1,0xff"
4082   [(set_attr "type"     "darith")
4083    (set_attr "mode"     "SI")])
4084
4085 (define_insn ""
4086   [(set (match_operand:HI 0 "register_operand" "=d")
4087         (zero_extend:HI (truncate:QI
4088                          (match_operand:DI 1 "register_operand" "d"))))]
4089   "TARGET_64BIT && !TARGET_MIPS16"
4090   "andi\\t%0,%1,0xff"
4091   [(set_attr "type"     "darith")
4092    (set_attr "mode"     "HI")])
4093
4094 \f
4095 ;;
4096 ;;  ....................
4097 ;;
4098 ;;      ZERO EXTENSION
4099 ;;
4100 ;;  ....................
4101
4102 ;; Extension insns.
4103 ;; Those for integer source operand are ordered widest source type first.
4104
4105 (define_insn_and_split "zero_extendsidi2"
4106   [(set (match_operand:DI 0 "register_operand" "=d")
4107         (zero_extend:DI (match_operand:SI 1 "register_operand" "d")))]
4108   "TARGET_64BIT"
4109   "#"
4110   "&& reload_completed"
4111   [(set (match_dup 0)
4112         (ashift:DI (match_dup 1) (const_int 32)))
4113    (set (match_dup 0)
4114         (lshiftrt:DI (match_dup 0) (const_int 32)))]
4115   "operands[1] = gen_lowpart (DImode, operands[1]);"
4116   [(set_attr "type" "arith")
4117    (set_attr "mode" "DI")])
4118
4119 (define_insn "*zero_extendsidi2_mem"
4120   [(set (match_operand:DI 0 "register_operand" "=d")
4121         (zero_extend:DI (match_operand:SI 1 "memory_operand" "m")))]
4122   "TARGET_64BIT && !TARGET_MIPS16"
4123   "lwu\t%0,%1"
4124   [(set_attr "type"     "load")
4125    (set_attr "mode"     "DI")])
4126
4127 (define_expand "zero_extendhisi2"
4128   [(set (match_operand:SI 0 "register_operand" "")
4129         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
4130   ""
4131   "
4132 {
4133   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
4134     {
4135       rtx op = gen_lowpart (SImode, operands[1]);
4136       rtx temp = force_reg (SImode, GEN_INT (0xffff));
4137
4138       emit_insn (gen_andsi3 (operands[0], op, temp));
4139       DONE;
4140     }
4141 }")
4142
4143 (define_insn ""
4144   [(set (match_operand:SI 0 "register_operand" "=d,d")
4145         (zero_extend:SI (match_operand:HI 1 "nonimmediate_operand" "d,m")))]
4146   "!TARGET_MIPS16"
4147   "@
4148    andi\t%0,%1,0xffff
4149    lhu\t%0,%1"
4150   [(set_attr "type"     "arith,load")
4151    (set_attr "mode"     "SI")
4152    (set_attr "length"   "4,*")])
4153
4154 (define_insn ""
4155   [(set (match_operand:SI 0 "register_operand" "=d")
4156         (zero_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
4157   "TARGET_MIPS16"
4158   "lhu\t%0,%1"
4159   [(set_attr "type"     "load")
4160    (set_attr "mode"     "SI")])
4161
4162 (define_expand "zero_extendhidi2"
4163   [(set (match_operand:DI 0 "register_operand" "")
4164         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "")))]
4165   "TARGET_64BIT"
4166   "
4167 {
4168   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
4169     {
4170       rtx op = gen_lowpart (DImode, operands[1]);
4171       rtx temp = force_reg (DImode, GEN_INT (0xffff));
4172
4173       emit_insn (gen_anddi3 (operands[0], op, temp));
4174       DONE;
4175     }
4176 }")
4177
4178 (define_insn ""
4179   [(set (match_operand:DI 0 "register_operand" "=d,d")
4180         (zero_extend:DI (match_operand:HI 1 "nonimmediate_operand" "d,m")))]
4181   "TARGET_64BIT && !TARGET_MIPS16"
4182   "@
4183    andi\t%0,%1,0xffff
4184    lhu\t%0,%1"
4185   [(set_attr "type"     "arith,load")
4186    (set_attr "mode"     "DI")
4187    (set_attr "length"   "4,*")])
4188
4189 (define_insn ""
4190   [(set (match_operand:DI 0 "register_operand" "=d")
4191         (zero_extend:DI (match_operand:HI 1 "memory_operand" "m")))]
4192   "TARGET_64BIT && TARGET_MIPS16"
4193   "lhu\t%0,%1"
4194   [(set_attr "type"     "load")
4195    (set_attr "mode"     "DI")])
4196
4197 (define_expand "zero_extendqihi2"
4198   [(set (match_operand:HI 0 "register_operand" "")
4199         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
4200   ""
4201   "
4202 {
4203   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
4204     {
4205       rtx op0 = gen_lowpart (SImode, operands[0]);
4206       rtx op1 = gen_lowpart (SImode, operands[1]);
4207       rtx temp = force_reg (SImode, GEN_INT (0xff));
4208
4209       emit_insn (gen_andsi3 (op0, op1, temp));
4210       DONE;
4211     }
4212 }")
4213
4214 (define_insn ""
4215   [(set (match_operand:HI 0 "register_operand" "=d,d")
4216         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
4217   "!TARGET_MIPS16"
4218   "@
4219    andi\t%0,%1,0x00ff
4220    lbu\t%0,%1"
4221   [(set_attr "type"     "arith,load")
4222    (set_attr "mode"     "HI")
4223    (set_attr "length"   "4,*")])
4224
4225 (define_insn ""
4226   [(set (match_operand:HI 0 "register_operand" "=d")
4227         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
4228   "TARGET_MIPS16"
4229   "lbu\t%0,%1"
4230   [(set_attr "type"     "load")
4231    (set_attr "mode"     "HI")])
4232
4233 (define_expand "zero_extendqisi2"
4234   [(set (match_operand:SI 0 "register_operand" "")
4235         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
4236   ""
4237   "
4238 {
4239   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
4240     {
4241       rtx op = gen_lowpart (SImode, operands[1]);
4242       rtx temp = force_reg (SImode, GEN_INT (0xff));
4243
4244       emit_insn (gen_andsi3 (operands[0], op, temp));
4245       DONE;
4246     }
4247 }")
4248
4249 (define_insn ""
4250   [(set (match_operand:SI 0 "register_operand" "=d,d")
4251         (zero_extend:SI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
4252   "!TARGET_MIPS16"
4253   "@
4254    andi\t%0,%1,0x00ff
4255    lbu\t%0,%1"
4256   [(set_attr "type"     "arith,load")
4257    (set_attr "mode"     "SI")
4258    (set_attr "length"   "4,*")])
4259
4260 (define_insn ""
4261   [(set (match_operand:SI 0 "register_operand" "=d")
4262         (zero_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
4263   "TARGET_MIPS16"
4264   "lbu\t%0,%1"
4265   [(set_attr "type"     "load")
4266    (set_attr "mode"     "SI")])
4267
4268 (define_expand "zero_extendqidi2"
4269   [(set (match_operand:DI 0 "register_operand" "")
4270         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "")))]
4271   "TARGET_64BIT"
4272   "
4273 {
4274   if (TARGET_MIPS16 && GET_CODE (operands[1]) != MEM)
4275     {
4276       rtx op = gen_lowpart (DImode, operands[1]);
4277       rtx temp = force_reg (DImode, GEN_INT (0xff));
4278
4279       emit_insn (gen_anddi3 (operands[0], op, temp));
4280       DONE;
4281     }
4282 }")
4283
4284 (define_insn ""
4285   [(set (match_operand:DI 0 "register_operand" "=d,d")
4286         (zero_extend:DI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
4287   "TARGET_64BIT && !TARGET_MIPS16"
4288   "@
4289    andi\t%0,%1,0x00ff
4290    lbu\t%0,%1"
4291   [(set_attr "type"     "arith,load")
4292    (set_attr "mode"     "DI")
4293    (set_attr "length"   "4,*")])
4294
4295 (define_insn ""
4296   [(set (match_operand:DI 0 "register_operand" "=d")
4297         (zero_extend:DI (match_operand:QI 1 "memory_operand" "m")))]
4298   "TARGET_64BIT && TARGET_MIPS16"
4299   "lbu\t%0,%1"
4300   [(set_attr "type"     "load")
4301    (set_attr "mode"     "DI")])
4302 \f
4303 ;;
4304 ;;  ....................
4305 ;;
4306 ;;      SIGN EXTENSION
4307 ;;
4308 ;;  ....................
4309
4310 ;; Extension insns.
4311 ;; Those for integer source operand are ordered widest source type first.
4312
4313 (define_expand "extendsidi2"
4314   [(set (match_operand:DI 0 "register_operand" "")
4315         (sign_extend:DI (match_operand:SI 1 "move_operand" "")))]
4316   "TARGET_64BIT"
4317   "
4318 {
4319  if (symbolic_operand (operands[1], SImode))
4320    {
4321       emit_move_insn (operands[0], convert_memory_address (DImode, operands[1]));
4322       DONE;
4323    }
4324
4325 }")
4326
4327 (define_insn "*extendsidi2"
4328   [(set (match_operand:DI 0 "register_operand" "=d,d")
4329         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,m")))]
4330   "TARGET_64BIT"
4331   "@
4332    sll\t%0,%1,0
4333    lw\t%0,%1"
4334   [(set_attr "type" "arith,load")
4335    (set_attr "mode" "DI")
4336    (set_attr "extended_mips16" "yes,*")])
4337
4338 ;; These patterns originally accepted general_operands, however, slightly
4339 ;; better code is generated by only accepting register_operands, and then
4340 ;; letting combine generate the lh and lb insns.
4341
4342 ;; These expanders originally put values in registers first. We split
4343 ;; all non-mem patterns after reload.
4344
4345 (define_expand "extendhidi2"
4346   [(set (match_operand:DI 0 "register_operand" "")
4347         (sign_extend:DI (match_operand:HI 1 "nonimmediate_operand" "")))]
4348   "TARGET_64BIT"
4349   "")
4350
4351 (define_insn "*extendhidi2"
4352   [(set (match_operand:DI 0 "register_operand" "=d")
4353         (sign_extend:DI (match_operand:HI 1 "register_operand" "d")))]
4354   "TARGET_64BIT"
4355   "#")
4356
4357 (define_split
4358   [(set (match_operand:DI 0 "register_operand" "")
4359         (sign_extend:DI (match_operand:HI 1 "register_operand" "")))]
4360   "TARGET_64BIT && reload_completed"
4361   [(set (match_dup 0)
4362         (ashift:DI (match_dup 1) (const_int 48)))
4363    (set (match_dup 0)
4364         (ashiftrt:DI (match_dup 0) (const_int 48)))]
4365   "operands[1] = gen_lowpart (DImode, operands[1]);")
4366
4367 (define_insn "*extendhidi2_mem"
4368   [(set (match_operand:DI 0 "register_operand" "=d")
4369         (sign_extend:DI (match_operand:HI 1 "memory_operand" "m")))]
4370   "TARGET_64BIT"
4371   "lh\t%0,%1"
4372   [(set_attr "type"     "load")
4373    (set_attr "mode"     "DI")])
4374
4375 (define_expand "extendhisi2"
4376   [(set (match_operand:SI 0 "register_operand" "")
4377         (sign_extend:SI (match_operand:HI 1 "nonimmediate_operand" "")))]
4378   ""
4379   "
4380    if (ISA_HAS_SEB_SEH)
4381      {
4382         emit_insn (gen_extendhisi2_hw (operands[0],
4383                                        force_reg (HImode, operands[1])));
4384         DONE;
4385      }
4386 ")
4387
4388 (define_insn "*extendhisi2"
4389   [(set (match_operand:SI 0 "register_operand" "=d")
4390         (sign_extend:SI (match_operand:HI 1 "register_operand" "d")))]
4391   ""
4392   "#")
4393
4394 (define_split
4395   [(set (match_operand:SI 0 "register_operand" "")
4396         (sign_extend:SI (match_operand:HI 1 "register_operand" "")))]
4397   "reload_completed"
4398   [(set (match_dup 0)
4399         (ashift:SI (match_dup 1) (const_int 16)))
4400    (set (match_dup 0)
4401         (ashiftrt:SI (match_dup 0) (const_int 16)))]
4402   "operands[1] = gen_lowpart (SImode, operands[1]);")
4403
4404 (define_insn "extendhisi2_mem"
4405   [(set (match_operand:SI 0 "register_operand" "=d")
4406         (sign_extend:SI (match_operand:HI 1 "memory_operand" "m")))]
4407   ""
4408   "lh\t%0,%1"
4409   [(set_attr "type"     "load")
4410    (set_attr "mode"     "SI")])
4411
4412 (define_insn "extendhisi2_hw"
4413   [(set (match_operand:SI 0 "register_operand" "=r")
4414         (sign_extend:SI (match_operand:HI 1 "register_operand" "r")))]
4415   "ISA_HAS_SEB_SEH"
4416   "seh\\t%0,%1"
4417   [(set_attr "type" "arith")
4418    (set_attr "mode" "SI")])
4419
4420 (define_expand "extendqihi2"
4421   [(set (match_operand:HI 0 "register_operand" "")
4422         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "")))]
4423   ""
4424   "")
4425
4426 (define_insn "*extendqihi2"
4427   [(set (match_operand:HI 0 "register_operand" "=d")
4428         (sign_extend:HI (match_operand:QI 1 "register_operand" "d")))]
4429   ""
4430   "#")
4431
4432 (define_split
4433   [(set (match_operand:HI 0 "register_operand" "")
4434         (sign_extend:HI (match_operand:QI 1 "register_operand" "")))]
4435   "reload_completed"
4436   [(set (match_dup 0)
4437         (ashift:SI (match_dup 1) (const_int 24)))
4438    (set (match_dup 0)
4439         (ashiftrt:SI (match_dup 0) (const_int 24)))]
4440   "operands[0] = gen_lowpart (SImode, operands[0]);
4441    operands[1] = gen_lowpart (SImode, operands[1]);")
4442
4443 (define_insn "*extendqihi2_internal_mem"
4444   [(set (match_operand:HI 0 "register_operand" "=d")
4445         (sign_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
4446   ""
4447   "lb\t%0,%1"
4448   [(set_attr "type"     "load")
4449    (set_attr "mode"     "SI")])
4450
4451
4452 (define_expand "extendqisi2"
4453   [(set (match_operand:SI 0 "register_operand" "")
4454         (sign_extend:SI (match_operand:QI 1 "nonimmediate_operand" "")))]
4455   ""
4456   "
4457    if (ISA_HAS_SEB_SEH)
4458      {
4459        emit_insn (gen_extendqisi2_hw (operands[0],
4460                                       force_reg (QImode, operands[1])));
4461        DONE;
4462      }
4463 ")
4464
4465 (define_insn "*extendqisi2"
4466   [(set (match_operand:SI 0 "register_operand" "=d")
4467         (sign_extend:SI (match_operand:QI 1 "register_operand" "d")))]
4468   ""
4469   "#")
4470
4471 (define_split
4472   [(set (match_operand:SI 0 "register_operand" "")
4473         (sign_extend:SI (match_operand:QI 1 "register_operand" "")))]
4474   "reload_completed"
4475   [(set (match_dup 0)
4476         (ashift:SI (match_dup 1) (const_int 24)))
4477    (set (match_dup 0)
4478         (ashiftrt:SI (match_dup 0) (const_int 24)))]
4479   "operands[1] = gen_lowpart (SImode, operands[1]);")
4480
4481 (define_insn "*extendqisi2_mem"
4482   [(set (match_operand:SI 0 "register_operand" "=d")
4483         (sign_extend:SI (match_operand:QI 1 "memory_operand" "m")))]
4484   ""
4485   "lb\t%0,%1"
4486   [(set_attr "type"     "load")
4487    (set_attr "mode"     "SI")])
4488
4489 (define_insn "extendqisi2_hw"
4490   [(set (match_operand:SI 0 "register_operand" "=r")
4491         (sign_extend:SI (match_operand:QI 1 "register_operand" "r")))]
4492   "ISA_HAS_SEB_SEH"
4493   "seb\\t%0,%1"
4494   [(set_attr "type" "arith")
4495    (set_attr "mode" "SI")])
4496
4497 (define_expand "extendqidi2"
4498   [(set (match_operand:DI 0 "register_operand" "")
4499         (sign_extend:DI (match_operand:QI 1 "nonimmediate_operand" "")))]
4500   "TARGET_64BIT"
4501   "")
4502
4503 (define_insn "*extendqidi2"
4504   [(set (match_operand:DI 0 "register_operand" "=d")
4505         (sign_extend:DI (match_operand:QI 1 "register_operand" "d")))]
4506   "TARGET_64BIT"
4507   "#")
4508
4509 (define_split
4510   [(set (match_operand:DI 0 "register_operand" "")
4511         (sign_extend:DI (match_operand:QI 1 "register_operand" "")))]
4512   "TARGET_64BIT && reload_completed"
4513   [(set (match_dup 0)
4514         (ashift:DI (match_dup 1) (const_int 56)))
4515    (set (match_dup 0)
4516         (ashiftrt:DI (match_dup 0) (const_int 56)))]
4517   "operands[1] = gen_lowpart (DImode, operands[1]);")
4518
4519 (define_insn "*extendqidi2_mem"
4520   [(set (match_operand:DI 0 "register_operand" "=d")
4521         (sign_extend:DI (match_operand:QI 1 "memory_operand" "m")))]
4522   "TARGET_64BIT"
4523   "lb\t%0,%1"
4524   [(set_attr "type"     "load")
4525    (set_attr "mode"     "DI")])
4526
4527 (define_insn "extendsfdf2"
4528   [(set (match_operand:DF 0 "register_operand" "=f")
4529         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
4530   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4531   "cvt.d.s\\t%0,%1"
4532   [(set_attr "type"     "fcvt")
4533    (set_attr "mode"     "DF")])
4534
4535 \f
4536
4537 ;;
4538 ;;  ....................
4539 ;;
4540 ;;      CONVERSIONS
4541 ;;
4542 ;;  ....................
4543
4544 (define_expand "fix_truncdfsi2"
4545   [(set (match_operand:SI 0 "register_operand" "=f")
4546         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
4547   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4548 {
4549   if (!ISA_HAS_TRUNC_W)
4550     {
4551       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
4552       DONE;
4553     }
4554 })
4555
4556 (define_insn "fix_truncdfsi2_insn"
4557   [(set (match_operand:SI 0 "register_operand" "=f")
4558         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
4559   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
4560   "trunc.w.d %0,%1"
4561   [(set_attr "type"     "fcvt")
4562    (set_attr "mode"     "DF")
4563    (set_attr "length"   "4")])
4564
4565 (define_insn "fix_truncdfsi2_macro"
4566   [(set (match_operand:SI 0 "register_operand" "=f")
4567         (fix:SI (match_operand:DF 1 "register_operand" "f")))
4568    (clobber (match_scratch:DF 2 "=d"))]
4569   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
4570   "trunc.w.d %0,%1,%2"
4571   [(set_attr "type"     "fcvt")
4572    (set_attr "mode"     "DF")
4573    (set_attr "length"   "36")])
4574
4575 (define_expand "fix_truncsfsi2"
4576   [(set (match_operand:SI 0 "register_operand" "=f")
4577         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
4578   "TARGET_HARD_FLOAT"
4579 {
4580   if (!ISA_HAS_TRUNC_W)
4581     {
4582       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
4583       DONE;
4584     }
4585 })
4586
4587 (define_insn "fix_truncsfsi2_insn"
4588   [(set (match_operand:SI 0 "register_operand" "=f")
4589         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
4590   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
4591   "trunc.w.s %0,%1"
4592   [(set_attr "type"     "fcvt")
4593    (set_attr "mode"     "DF")
4594    (set_attr "length"   "4")])
4595
4596 (define_insn "fix_truncsfsi2_macro"
4597   [(set (match_operand:SI 0 "register_operand" "=f")
4598         (fix:SI (match_operand:SF 1 "register_operand" "f")))
4599    (clobber (match_scratch:SF 2 "=d"))]
4600   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
4601   "trunc.w.s %0,%1,%2"
4602   [(set_attr "type"     "fcvt")
4603    (set_attr "mode"     "DF")
4604    (set_attr "length"   "36")])
4605
4606 ;;; ??? trunc.l.d is mentioned in the appendix of the 1993 r4000/r4600 manuals
4607 ;;; but not in the chapter that describes the FPU.  It is not mentioned at all
4608 ;;; in the 1991 manuals.  The r4000 at Cygnus does not have this instruction.
4609
4610 ;;; Deleting this means that we now need two libgcc2.a libraries.  One for
4611 ;;; the 32 bit calling convention and one for the 64 bit calling convention.
4612
4613 ;;; If this is disabled, then fixuns_truncdfdi2 must be disabled also.
4614
4615 (define_insn "fix_truncdfdi2"
4616   [(set (match_operand:DI 0 "register_operand" "=f")
4617         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
4618   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4619   "trunc.l.d %0,%1"
4620   [(set_attr "type"     "fcvt")
4621    (set_attr "mode"     "DF")
4622    (set_attr "length"   "4")])
4623
4624
4625 ;;; ??? trunc.l.s is mentioned in the appendix of the 1993 r4000/r4600 manuals
4626 ;;; but not in the chapter that describes the FPU.  It is not mentioned at all
4627 ;;; in the 1991 manuals.  The r4000 at Cygnus does not have this instruction.
4628 (define_insn "fix_truncsfdi2"
4629   [(set (match_operand:DI 0 "register_operand" "=f")
4630         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
4631   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4632   "trunc.l.s %0,%1"
4633   [(set_attr "type"     "fcvt")
4634    (set_attr "mode"     "SF")
4635    (set_attr "length"   "4")])
4636
4637
4638 (define_insn "floatsidf2"
4639   [(set (match_operand:DF 0 "register_operand" "=f")
4640         (float:DF (match_operand:SI 1 "register_operand" "f")))]
4641   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4642   "cvt.d.w\\t%0,%1"
4643   [(set_attr "type"     "fcvt")
4644    (set_attr "mode"     "DF")
4645    (set_attr "length"   "4")])
4646
4647
4648 (define_insn "floatdidf2"
4649   [(set (match_operand:DF 0 "register_operand" "=f")
4650         (float:DF (match_operand:DI 1 "register_operand" "f")))]
4651   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4652   "cvt.d.l\\t%0,%1"
4653   [(set_attr "type"     "fcvt")
4654    (set_attr "mode"     "DF")
4655    (set_attr "length"   "4")])
4656
4657
4658 (define_insn "floatsisf2"
4659   [(set (match_operand:SF 0 "register_operand" "=f")
4660         (float:SF (match_operand:SI 1 "register_operand" "f")))]
4661   "TARGET_HARD_FLOAT"
4662   "cvt.s.w\\t%0,%1"
4663   [(set_attr "type"     "fcvt")
4664    (set_attr "mode"     "SF")
4665    (set_attr "length"   "4")])
4666
4667
4668 (define_insn "floatdisf2"
4669   [(set (match_operand:SF 0 "register_operand" "=f")
4670         (float:SF (match_operand:DI 1 "register_operand" "f")))]
4671   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4672   "cvt.s.l\\t%0,%1"
4673   [(set_attr "type"     "fcvt")
4674    (set_attr "mode"     "SF")
4675    (set_attr "length"   "4")])
4676
4677
4678 (define_expand "fixuns_truncdfsi2"
4679   [(set (match_operand:SI 0 "register_operand" "")
4680         (unsigned_fix:SI (match_operand:DF 1 "register_operand" "")))]
4681   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4682   "
4683 {
4684   rtx reg1 = gen_reg_rtx (DFmode);
4685   rtx reg2 = gen_reg_rtx (DFmode);
4686   rtx reg3 = gen_reg_rtx (SImode);
4687   rtx label1 = gen_label_rtx ();
4688   rtx label2 = gen_label_rtx ();
4689   REAL_VALUE_TYPE offset;
4690
4691   real_2expN (&offset, 31);
4692
4693   if (reg1)                     /* turn off complaints about unreached code */
4694     {
4695       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
4696       do_pending_stack_adjust ();
4697
4698       emit_insn (gen_cmpdf (operands[1], reg1));
4699       emit_jump_insn (gen_bge (label1));
4700
4701       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4702       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4703                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4704       emit_barrier ();
4705
4706       emit_label (label1);
4707       emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4708       emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
4709                                      (BITMASK_HIGH, SImode)));
4710
4711       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4712       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4713
4714       emit_label (label2);
4715
4716       /* allow REG_NOTES to be set on last insn (labels don't have enough
4717          fields, and can't be used for REG_NOTES anyway).  */
4718       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4719       DONE;
4720     }
4721 }")
4722
4723
4724 (define_expand "fixuns_truncdfdi2"
4725   [(set (match_operand:DI 0 "register_operand" "")
4726         (unsigned_fix:DI (match_operand:DF 1 "register_operand" "")))]
4727   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4728   "
4729 {
4730   rtx reg1 = gen_reg_rtx (DFmode);
4731   rtx reg2 = gen_reg_rtx (DFmode);
4732   rtx reg3 = gen_reg_rtx (DImode);
4733   rtx label1 = gen_label_rtx ();
4734   rtx label2 = gen_label_rtx ();
4735   REAL_VALUE_TYPE offset;
4736
4737   real_2expN (&offset, 63);
4738
4739   if (reg1)                     /* turn off complaints about unreached code */
4740     {
4741       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
4742       do_pending_stack_adjust ();
4743
4744       emit_insn (gen_cmpdf (operands[1], reg1));
4745       emit_jump_insn (gen_bge (label1));
4746
4747       emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4748       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4749                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4750       emit_barrier ();
4751
4752       emit_label (label1);
4753       emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4754       emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
4755       emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4756
4757       emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4758       emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4759
4760       emit_label (label2);
4761
4762       /* allow REG_NOTES to be set on last insn (labels don't have enough
4763          fields, and can't be used for REG_NOTES anyway).  */
4764       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4765       DONE;
4766     }
4767 }")
4768
4769
4770 (define_expand "fixuns_truncsfsi2"
4771   [(set (match_operand:SI 0 "register_operand" "")
4772         (unsigned_fix:SI (match_operand:SF 1 "register_operand" "")))]
4773   "TARGET_HARD_FLOAT"
4774   "
4775 {
4776   rtx reg1 = gen_reg_rtx (SFmode);
4777   rtx reg2 = gen_reg_rtx (SFmode);
4778   rtx reg3 = gen_reg_rtx (SImode);
4779   rtx label1 = gen_label_rtx ();
4780   rtx label2 = gen_label_rtx ();
4781   REAL_VALUE_TYPE offset;
4782
4783   real_2expN (&offset, 31);
4784
4785   if (reg1)                     /* turn off complaints about unreached code */
4786     {
4787       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4788       do_pending_stack_adjust ();
4789
4790       emit_insn (gen_cmpsf (operands[1], reg1));
4791       emit_jump_insn (gen_bge (label1));
4792
4793       emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4794       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4795                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4796       emit_barrier ();
4797
4798       emit_label (label1);
4799       emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4800       emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
4801                                      (BITMASK_HIGH, SImode)));
4802
4803       emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4804       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4805
4806       emit_label (label2);
4807
4808       /* allow REG_NOTES to be set on last insn (labels don't have enough
4809          fields, and can't be used for REG_NOTES anyway).  */
4810       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4811       DONE;
4812     }
4813 }")
4814
4815
4816 (define_expand "fixuns_truncsfdi2"
4817   [(set (match_operand:DI 0 "register_operand" "")
4818         (unsigned_fix:DI (match_operand:SF 1 "register_operand" "")))]
4819   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4820   "
4821 {
4822   rtx reg1 = gen_reg_rtx (SFmode);
4823   rtx reg2 = gen_reg_rtx (SFmode);
4824   rtx reg3 = gen_reg_rtx (DImode);
4825   rtx label1 = gen_label_rtx ();
4826   rtx label2 = gen_label_rtx ();
4827   REAL_VALUE_TYPE offset;
4828
4829   real_2expN (&offset, 63);
4830
4831   if (reg1)                     /* turn off complaints about unreached code */
4832     {
4833       emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4834       do_pending_stack_adjust ();
4835
4836       emit_insn (gen_cmpsf (operands[1], reg1));
4837       emit_jump_insn (gen_bge (label1));
4838
4839       emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4840       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4841                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4842       emit_barrier ();
4843
4844       emit_label (label1);
4845       emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4846       emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
4847       emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4848
4849       emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4850       emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4851
4852       emit_label (label2);
4853
4854       /* allow REG_NOTES to be set on last insn (labels don't have enough
4855          fields, and can't be used for REG_NOTES anyway).  */
4856       emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4857       DONE;
4858     }
4859 }")
4860
4861 \f
4862 ;;
4863 ;;  ....................
4864 ;;
4865 ;;      DATA MOVEMENT
4866 ;;
4867 ;;  ....................
4868
4869 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4870
4871 (define_expand "extv"
4872   [(set (match_operand 0 "register_operand" "")
4873         (sign_extract (match_operand:QI 1 "memory_operand" "")
4874                       (match_operand 2 "immediate_operand" "")
4875                       (match_operand 3 "immediate_operand" "")))]
4876   "!TARGET_MIPS16"
4877   {
4878     if (mips_expand_unaligned_load (operands[0], operands[1],
4879                                     INTVAL (operands[2]),
4880                                     INTVAL (operands[3])))
4881       DONE;
4882     else
4883       FAIL;
4884   })
4885
4886 (define_expand "extzv"
4887   [(set (match_operand 0 "register_operand" "")
4888         (zero_extract (match_operand:QI 1 "memory_operand" "")
4889                       (match_operand 2 "immediate_operand" "")
4890                       (match_operand 3 "immediate_operand" "")))]
4891   "!TARGET_MIPS16"
4892   {
4893     if (mips_expand_unaligned_load (operands[0], operands[1],
4894                                     INTVAL (operands[2]),
4895                                     INTVAL (operands[3])))
4896       DONE;
4897     else
4898       FAIL;
4899   })
4900
4901 (define_expand "insv"
4902   [(set (zero_extract (match_operand:QI 0 "memory_operand" "")
4903                       (match_operand 1 "immediate_operand" "")
4904                       (match_operand 2 "immediate_operand" ""))
4905         (match_operand 3 "reg_or_0_operand" ""))]
4906   "!TARGET_MIPS16"
4907   {
4908     if (mips_expand_unaligned_store (operands[0], operands[3],
4909                                      INTVAL (operands[1]),
4910                                      INTVAL (operands[2])))
4911       DONE;
4912     else
4913       FAIL;
4914   })
4915
4916 ;; Unaligned word moves generated by the bit field patterns.
4917 ;;
4918 ;; As far as the rtl is concerned, both the left-part and right-part
4919 ;; instructions can access the whole field.  However, the real operand
4920 ;; refers to just the first or the last byte (depending on endianness).
4921 ;; We therefore use two memory operands to each instruction, one to
4922 ;; describe the rtl effect and one to use in the assembly output.
4923
4924 (define_insn "mov_lwl"
4925   [(set (match_operand:SI 0 "register_operand" "=d")
4926         (unspec:SI [(match_operand:BLK 1 "general_operand" "m")
4927                     (match_operand:QI 2 "general_operand" "m")]
4928                    UNSPEC_LWL))]
4929   "!TARGET_MIPS16"
4930   "lwl\t%0,%2"
4931   [(set_attr "type" "load")
4932    (set_attr "mode" "SI")])
4933
4934 (define_insn "mov_lwr"
4935   [(set (match_operand:SI 0 "register_operand" "=d")
4936         (unspec:SI [(match_operand:BLK 1 "general_operand" "m")
4937                     (match_operand:QI 2 "general_operand" "m")
4938                     (match_operand:SI 3 "register_operand" "0")]
4939                    UNSPEC_LWR))]
4940   "!TARGET_MIPS16"
4941   "lwr\t%0,%2"
4942   [(set_attr "type" "load")
4943    (set_attr "mode" "SI")])
4944
4945
4946 (define_insn "mov_swl"
4947   [(set (match_operand:BLK 0 "memory_operand" "=m")
4948         (unspec:BLK [(match_operand:SI 1 "reg_or_0_operand" "dJ")
4949                      (match_operand:QI 2 "general_operand" "m")]
4950                     UNSPEC_SWL))]
4951   "!TARGET_MIPS16"
4952   "swl\t%z1,%2"
4953   [(set_attr "type" "store")
4954    (set_attr "mode" "SI")])
4955
4956 (define_insn "mov_swr"
4957   [(set (match_operand:BLK 0 "memory_operand" "+m")
4958         (unspec:BLK [(match_operand:SI 1 "reg_or_0_operand" "dJ")
4959                      (match_operand:QI 2 "general_operand" "m")
4960                      (match_dup 0)]
4961                     UNSPEC_SWR))]
4962   "!TARGET_MIPS16"
4963   "swr\t%z1,%2"
4964   [(set_attr "type" "store")
4965    (set_attr "mode" "SI")])
4966
4967
4968 (define_insn "mov_ldl"
4969   [(set (match_operand:DI 0 "register_operand" "=d")
4970         (unspec:DI [(match_operand:BLK 1 "general_operand" "m")
4971                     (match_operand:QI 2 "general_operand" "m")]
4972                    UNSPEC_LDL))]
4973   "TARGET_64BIT && !TARGET_MIPS16"
4974   "ldl\t%0,%2"
4975   [(set_attr "type" "load")
4976    (set_attr "mode" "DI")])
4977
4978 (define_insn "mov_ldr"
4979   [(set (match_operand:DI 0 "register_operand" "=d")
4980         (unspec:DI [(match_operand:BLK 1 "general_operand" "m")
4981                     (match_operand:QI 2 "general_operand" "m")
4982                     (match_operand:DI 3 "register_operand" "0")]
4983                    UNSPEC_LDR))]
4984   "TARGET_64BIT && !TARGET_MIPS16"
4985   "ldr\t%0,%2"
4986   [(set_attr "type" "load")
4987    (set_attr "mode" "DI")])
4988
4989
4990 (define_insn "mov_sdl"
4991   [(set (match_operand:BLK 0 "memory_operand" "=m")
4992         (unspec:BLK [(match_operand:DI 1 "reg_or_0_operand" "dJ")
4993                      (match_operand:QI 2 "general_operand" "m")]
4994                     UNSPEC_SDL))]
4995   "TARGET_64BIT && !TARGET_MIPS16"
4996   "sdl\t%z1,%2"
4997   [(set_attr "type" "store")
4998    (set_attr "mode" "DI")])
4999
5000 (define_insn "mov_sdr"
5001   [(set (match_operand:BLK 0 "memory_operand" "+m")
5002         (unspec:BLK [(match_operand:DI 1 "reg_or_0_operand" "dJ")
5003                      (match_operand:QI 2 "general_operand" "m")
5004                      (match_dup 0)]
5005                     UNSPEC_SDR))]
5006   "TARGET_64BIT && !TARGET_MIPS16"
5007   "sdr\t%z1,%2"
5008   [(set_attr "type" "store")
5009    (set_attr "mode" "DI")])
5010
5011
5012 ;; Instructions for loading a relocation expression using "lui".
5013
5014 (define_insn "luisi"
5015   [(set (match_operand:SI 0 "register_operand" "=r")
5016         (unspec:SI [(match_operand 1 "const_arith_operand" "")] UNSPEC_HIGH))]
5017   ""
5018   "lui\t%0,%1"
5019   [(set_attr "type" "arith")])
5020
5021 (define_insn "luidi"
5022   [(set (match_operand:DI 0 "register_operand" "=r")
5023         (unspec:DI [(match_operand 1 "const_arith_operand" "")] UNSPEC_HIGH))]
5024   "TARGET_64BIT"
5025   "lui\t%0,%1"
5026   [(set_attr "type" "arith")])
5027
5028
5029 ;; Instructions for adding the low 16 bits of an address to a register.
5030 ;; Operand 2 is the address: print_operand works out which relocation
5031 ;; should be applied.
5032
5033 (define_insn "lowsi"
5034   [(set (match_operand:SI 0 "register_operand" "=r")
5035         (lo_sum:SI (match_operand:SI 1 "register_operand" "r")
5036                    (match_operand:SI 2 "immediate_operand" "")))]
5037   "!TARGET_MIPS16"
5038   "addiu\\t%0,%1,%R2"
5039   [(set_attr "type"     "arith")
5040    (set_attr "mode"     "SI")])
5041
5042 (define_insn "lowdi"
5043   [(set (match_operand:DI 0 "register_operand" "=r")
5044         (lo_sum:DI (match_operand:DI 1 "register_operand" "r")
5045                    (match_operand:DI 2 "immediate_operand" "")))]
5046   "!TARGET_MIPS16 && TARGET_64BIT"
5047   "daddiu\\t%0,%1,%R2"
5048   [(set_attr "type"     "arith")
5049    (set_attr "mode"     "DI")])
5050
5051 ;; 64-bit integer moves
5052
5053 ;; Unlike most other insns, the move insns can't be split with
5054 ;; different predicates, because register spilling and other parts of
5055 ;; the compiler, have memoized the insn number already.
5056
5057 (define_expand "movdi"
5058   [(set (match_operand:DI 0 "nonimmediate_operand" "")
5059         (match_operand:DI 1 "" ""))]
5060   ""
5061   "
5062 {
5063   if (mips_legitimize_move (DImode, operands[0], operands[1]))
5064     DONE;
5065
5066   /* If we are generating embedded PIC code, and we are referring to a
5067      symbol in the .text section, we must use an offset from the start
5068      of the function.  */
5069   if (TARGET_EMBEDDED_PIC
5070       && (GET_CODE (operands[1]) == LABEL_REF
5071           || (GET_CODE (operands[1]) == SYMBOL_REF
5072               && ! SYMBOL_REF_FLAG (operands[1]))))
5073     {
5074       rtx temp;
5075
5076       temp = embedded_pic_offset (operands[1]);
5077       temp = gen_rtx_PLUS (Pmode, embedded_pic_fnaddr_reg (),
5078                            force_reg (DImode, temp));
5079       emit_move_insn (operands[0], force_reg (DImode, temp));
5080       DONE;
5081     }
5082 }")
5083
5084 ;; For mips16, we need a special case to handle storing $31 into
5085 ;; memory, since we don't have a constraint to match $31.  This
5086 ;; instruction can be generated by save_restore_insns.
5087
5088 (define_insn ""
5089   [(set (match_operand:DI 0 "memory_operand" "=m")
5090         (reg:DI 31))]
5091   "TARGET_MIPS16 && TARGET_64BIT"
5092   "sd\t$31,%0"
5093   [(set_attr "type"     "store")
5094    (set_attr "mode"     "DI")])
5095
5096 (define_insn "movdi_internal"
5097   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*x,*d,*x,*B*C*D,*B*C*D,*d,*m")
5098         (match_operand:DI 1 "general_operand" "d,iF,m,d,J,*x,*d,*d,*m,*B*C*D,*B*C*D"))]
5099   "!TARGET_64BIT && !TARGET_MIPS16
5100    && (register_operand (operands[0], DImode)
5101        || register_operand (operands[1], DImode)
5102        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0)
5103        || operands[1] == CONST0_RTX (DImode))"
5104   { return mips_output_move (operands[0], operands[1]); }
5105   [(set_attr "type"     "move,arith,load,store,hilo,hilo,hilo,xfer,load,xfer,store")
5106    (set_attr "mode"     "DI")
5107    (set_attr "length"   "8,16,*,*,8,8,8,8,*,8,*")])
5108
5109 (define_insn ""
5110   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5111         (match_operand:DI 1 "general_operand" "d,d,y,K,N,m,d,*x"))]
5112   "!TARGET_64BIT && TARGET_MIPS16
5113    && (register_operand (operands[0], DImode)
5114        || register_operand (operands[1], DImode))"
5115   { return mips_output_move (operands[0], operands[1]); }
5116   [(set_attr "type"     "move,move,move,arith,arith,load,store,hilo")
5117    (set_attr "mode"     "DI")
5118    (set_attr "length"   "8,8,8,8,12,*,*,8")])
5119
5120 (define_insn "movdi_internal2"
5121   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*x,*d,*x,*a,*B*C*D,*B*C*D,*d,*m")
5122         (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*J,*x,*d,*J,*d,*m,*B*C*D,*B*C*D"))]
5123   "TARGET_64BIT && !TARGET_MIPS16
5124    && (register_operand (operands[0], DImode)
5125        || register_operand (operands[1], DImode)
5126        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0)
5127        || operands[1] == CONST0_RTX (DImode))"
5128   { return mips_output_move (operands[0], operands[1]); }
5129   [(set_attr "type"     "move,const,const,load,store,move,xfer,load,xfer,store,hilo,hilo,hilo,hilo,xfer,load,xfer,store")
5130    (set_attr "mode"     "DI")
5131    (set_attr "length"   "4,*,*,*,*,4,4,*,4,*,4,4,4,8,8,*,8,*")])
5132
5133 (define_insn "*movdi_internal2_mips16"
5134   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m,*d")
5135         (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,m,d,*x"))]
5136   "TARGET_64BIT && TARGET_MIPS16
5137    && (register_operand (operands[0], DImode)
5138        || register_operand (operands[1], DImode))"
5139   { return mips_output_move (operands[0], operands[1]); }
5140   [(set_attr "type"     "move,move,move,arith,arith,const,load,store,hilo")
5141    (set_attr "mode"     "DI")
5142    (set_attr_alternative "length"
5143                 [(const_int 4)
5144                  (const_int 4)
5145                  (const_int 4)
5146                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1" "")
5147                                (const_int 4)
5148                                (const_int 8))
5149                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1" "")
5150                                (const_int 8)
5151                                (const_int 12))
5152                  (const_string "*")
5153                  (const_string "*")
5154                  (const_string "*")
5155                  (const_int 4)])])
5156
5157
5158 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
5159 ;; when the original load is a 4 byte instruction but the add and the
5160 ;; load are 2 2 byte instructions.
5161
5162 (define_split
5163   [(set (match_operand:DI 0 "register_operand" "")
5164         (mem:DI (plus:DI (match_dup 0)
5165                          (match_operand:DI 1 "const_int_operand" ""))))]
5166   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
5167    && !TARGET_DEBUG_D_MODE
5168    && GET_CODE (operands[0]) == REG
5169    && M16_REG_P (REGNO (operands[0]))
5170    && GET_CODE (operands[1]) == CONST_INT
5171    && ((INTVAL (operands[1]) < 0
5172         && INTVAL (operands[1]) >= -0x10)
5173        || (INTVAL (operands[1]) >= 32 * 8
5174            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
5175        || (INTVAL (operands[1]) >= 0
5176            && INTVAL (operands[1]) < 32 * 8
5177            && (INTVAL (operands[1]) & 7) != 0))"
5178   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
5179    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
5180   "
5181 {
5182   HOST_WIDE_INT val = INTVAL (operands[1]);
5183
5184   if (val < 0)
5185     operands[2] = GEN_INT (0);
5186   else if (val >= 32 * 8)
5187     {
5188       int off = val & 7;
5189
5190       operands[1] = GEN_INT (0x8 + off);
5191       operands[2] = GEN_INT (val - off - 0x8);
5192     }
5193   else
5194     {
5195       int off = val & 7;
5196
5197       operands[1] = GEN_INT (off);
5198       operands[2] = GEN_INT (val - off);
5199     }
5200 }")
5201
5202 ;; Handle input reloads in DImode.
5203 ;; This is mainly to handle reloading HILO_REGNUM.  Note that we may
5204 ;; see it as the source or the destination, depending upon which way
5205 ;; reload handles the instruction.
5206 ;; Making the second operand TImode is a trick.  The compiler may
5207 ;; reuse the same register for operand 0 and operand 2.  Using TImode
5208 ;; gives us two registers, so we can always use the one which is not
5209 ;; used.
5210
5211 (define_expand "reload_indi"
5212   [(set (match_operand:DI 0 "register_operand" "=b")
5213         (match_operand:DI 1 "" "b"))
5214    (clobber (match_operand:TI 2 "register_operand" "=&d"))]
5215   "TARGET_64BIT"
5216   "
5217 {
5218   rtx scratch = gen_rtx_REG (DImode,
5219                              (REGNO (operands[0]) == REGNO (operands[2])
5220                               ? REGNO (operands[2]) + 1
5221                               : REGNO (operands[2])));
5222
5223   if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == HILO_REGNUM)
5224     {
5225       if (GET_CODE (operands[1]) == MEM)
5226         {
5227           rtx memword, offword, hi_word, lo_word;
5228           rtx addr = find_replacement (&XEXP (operands[1], 0));
5229           rtx op1 = replace_equiv_address (operands[1], addr);
5230
5231           scratch = gen_rtx_REG (SImode, REGNO (scratch));
5232           memword = adjust_address (op1, SImode, 0);
5233           offword = adjust_address (op1, SImode, 4);
5234
5235           if (BYTES_BIG_ENDIAN)
5236             {
5237               hi_word = memword;
5238               lo_word = offword;
5239             }
5240           else
5241             {
5242               hi_word = offword;
5243               lo_word = memword;
5244             }
5245           emit_move_insn (scratch, hi_word);
5246           emit_move_insn (gen_rtx_REG (SImode, 64), scratch);
5247           emit_move_insn (scratch, lo_word);
5248           emit_move_insn (gen_rtx (REG, SImode, 65), scratch);
5249           emit_insn (gen_hilo_delay (operands[0]));
5250         }
5251       else
5252         {
5253           emit_insn (gen_ashrdi3 (scratch, operands[1], GEN_INT (32)));
5254           emit_insn (gen_movdi (gen_rtx_REG (DImode, 64), scratch));
5255           emit_insn (gen_ashldi3 (scratch, operands[1], GEN_INT (32)));
5256           emit_insn (gen_ashrdi3 (scratch, scratch, GEN_INT (32)));
5257           emit_insn (gen_movdi (gen_rtx (REG, DImode, 65), scratch));
5258           emit_insn (gen_hilo_delay (operands[0]));
5259         }
5260       DONE;
5261     }
5262   if (GET_CODE (operands[1]) == REG && REGNO (operands[1]) == HILO_REGNUM)
5263     {
5264       emit_insn (gen_movdi (scratch, gen_rtx_REG (DImode, 65)));
5265       emit_insn (gen_ashldi3 (scratch, scratch, GEN_INT (32)));
5266       emit_insn (gen_lshrdi3 (scratch, scratch, GEN_INT (32)));
5267       emit_insn (gen_movdi (operands[0], gen_rtx_REG (DImode, 64)));
5268       emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT (32)));
5269       emit_insn (gen_iordi3 (operands[0], operands[0], scratch));
5270       emit_insn (gen_hilo_delay (operands[1]));
5271       DONE;
5272     }
5273   /* This handles moves between a float register and HI/LO.  */
5274   emit_move_insn (scratch, operands[1]);
5275   emit_move_insn (operands[0], scratch);
5276   DONE;
5277 }")
5278
5279 ;; Handle output reloads in DImode.
5280
5281 ;; Reloading HILO_REG in MIPS16 mode requires two scratch registers, so we
5282 ;; use a TImode scratch reg.
5283
5284 (define_expand "reload_outdi"
5285   [(set (match_operand:DI 0 "general_operand" "=b")
5286         (match_operand:DI 1 "register_operand" "b"))
5287    (clobber (match_operand:TI 2 "register_operand" "=&d"))]
5288   "TARGET_64BIT"
5289   "
5290 {
5291   rtx scratch = gen_rtx_REG (DImode, REGNO (operands[2]));
5292
5293   if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) == HILO_REGNUM)
5294     {
5295       emit_insn (gen_ashrdi3 (scratch, operands[1], GEN_INT (32)));
5296       emit_insn (gen_movdi (gen_rtx (REG, DImode, 64), scratch));
5297       emit_insn (gen_ashldi3 (scratch, operands[1], GEN_INT (32)));
5298       emit_insn (gen_ashrdi3 (scratch, scratch, GEN_INT (32)));
5299       emit_insn (gen_movdi (gen_rtx (REG, DImode, 65), scratch));
5300       emit_insn (gen_hilo_delay (operands[0]));
5301       DONE;
5302     }
5303   if (GET_CODE (operands[1]) == REG && REGNO (operands[1]) == HILO_REGNUM)
5304     {
5305       if (GET_CODE (operands[0]) == MEM)
5306         {
5307           rtx scratch, memword, offword, hi_word, lo_word;
5308           rtx addr = find_replacement (&XEXP (operands[0], 0));
5309           rtx op0 = replace_equiv_address (operands[0], addr);
5310
5311           scratch = gen_rtx_REG (SImode, REGNO (operands[2]));
5312           memword = adjust_address (op0, SImode, 0);
5313           offword = adjust_address (op0, SImode, 4);
5314
5315           if (BYTES_BIG_ENDIAN)
5316             {
5317               hi_word = memword;
5318               lo_word = offword;
5319             }
5320           else
5321             {
5322               hi_word = offword;
5323               lo_word = memword;
5324             }
5325           emit_move_insn (scratch, gen_rtx_REG (SImode, 64));
5326           emit_move_insn (hi_word, scratch);
5327           emit_move_insn (scratch, gen_rtx_REG (SImode, 65));
5328           emit_move_insn (lo_word, scratch);
5329           emit_insn (gen_hilo_delay (operands[1]));
5330         }
5331       else if (TARGET_MIPS16 && ! M16_REG_P (REGNO (operands[0])))
5332         {
5333           /* Handle the case where operand[0] is not a 'd' register,
5334              and hence we can not directly move from the HILO register
5335              into it.  */
5336           rtx scratch2 = gen_rtx_REG (DImode, REGNO (operands[2]) + 1);
5337           emit_insn (gen_movdi (scratch, gen_rtx (REG, DImode, 65)));
5338           emit_insn (gen_ashldi3 (scratch, scratch, GEN_INT (32)));
5339           emit_insn (gen_lshrdi3 (scratch, scratch, GEN_INT (32)));
5340           emit_insn (gen_movdi (scratch2, gen_rtx (REG, DImode, 64)));
5341           emit_insn (gen_ashldi3 (scratch2, scratch2, GEN_INT (32)));
5342           emit_insn (gen_iordi3 (scratch, scratch, scratch2));
5343           emit_insn (gen_movdi (operands[0], scratch));
5344           emit_insn (gen_hilo_delay (operands[1]));
5345         }
5346       else
5347         {
5348           emit_insn (gen_movdi (scratch, gen_rtx (REG, DImode, 65)));
5349           emit_insn (gen_ashldi3 (scratch, scratch, GEN_INT (32)));
5350           emit_insn (gen_lshrdi3 (scratch, scratch, GEN_INT (32)));
5351           emit_insn (gen_movdi (operands[0], gen_rtx (REG, DImode, 64)));
5352           emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT (32)));
5353           emit_insn (gen_iordi3 (operands[0], operands[0], scratch));
5354           emit_insn (gen_hilo_delay (operands[1]));
5355         }
5356       DONE;
5357     }
5358   /* This handles moves between a float register and HI/LO.  */
5359   emit_move_insn (scratch, operands[1]);
5360   emit_move_insn (operands[0], scratch);
5361   DONE;
5362 }")
5363
5364 ;; 32-bit Integer moves
5365
5366 ;; Unlike most other insns, the move insns can't be split with
5367 ;; different predicates, because register spilling and other parts of
5368 ;; the compiler, have memoized the insn number already.
5369
5370 (define_expand "movsi"
5371   [(set (match_operand:SI 0 "nonimmediate_operand" "")
5372         (match_operand:SI 1 "" ""))]
5373   ""
5374   "
5375 {
5376   if (mips_legitimize_move (SImode, operands[0], operands[1]))
5377     DONE;
5378
5379   /* If we are generating embedded PIC code, and we are referring to a
5380      symbol in the .text section, we must use an offset from the start
5381      of the function.  */
5382   if (TARGET_EMBEDDED_PIC
5383       && (GET_CODE (operands[1]) == LABEL_REF
5384           || (GET_CODE (operands[1]) == SYMBOL_REF
5385               && ! SYMBOL_REF_FLAG (operands[1]))))
5386     {
5387       rtx temp;
5388
5389       temp = embedded_pic_offset (operands[1]);
5390       temp = gen_rtx_PLUS (Pmode, embedded_pic_fnaddr_reg (),
5391                            force_reg (SImode, temp));
5392       emit_move_insn (operands[0], force_reg (SImode, temp));
5393       DONE;
5394     }
5395 }")
5396
5397 ;; We can only store $ra directly into a small sp offset.  Should the
5398 ;; offset be too wide, non-constant or not sp-based, leave it up to
5399 ;; reload to choose a scratch register.
5400
5401 (define_insn ""
5402   [(set (mem:SI (plus:SI (reg:SI 29)
5403                          (match_operand:SI 0 "small_int" "n")))
5404         (reg:SI 31))]
5405   "TARGET_MIPS16"
5406   "sw\\t$31,%0($sp)"
5407   [(set_attr "type"     "store")
5408    (set_attr "mode"     "SI")
5409    (set_attr_alternative
5410     "length"
5411     [(if_then_else
5412       (lt (symbol_ref "(unsigned HOST_WIDE_INT) INTVAL (operands[0])")
5413           (const_int 1024))
5414       (const_int 4)
5415       (const_int 8))])])
5416
5417 ;; The difference between these two is whether or not ints are allowed
5418 ;; in FP registers (off by default, use -mdebugh to enable).
5419
5420 (define_insn "movsi_internal"
5421   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*d,*z,*x,*d,*x,*d,*B*C*D,*B*C*D,*d,*m")
5422         (match_operand:SI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*z,*d,J,*x,*d,*a,*d,*m,*B*C*D,*B*C*D"))]
5423   "!TARGET_MIPS16
5424    && (register_operand (operands[0], SImode)
5425        || register_operand (operands[1], SImode)
5426        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
5427   { return mips_output_move (operands[0], operands[1]); }
5428   [(set_attr "type"     "move,const,const,load,store,move,xfer,load,xfer,store,xfer,xfer,hilo,hilo,hilo,hilo,xfer,load,xfer,store")
5429    (set_attr "mode"     "SI")
5430    (set_attr "length"   "4,*,*,*,*,4,4,*,4,*,4,4,4,4,4,4,4,*,4,*")])
5431
5432 (define_insn ""
5433   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m,*d,*d")
5434         (match_operand:SI 1 "move_operand" "d,d,y,K,N,U,m,d,*x,*a"))]
5435   "TARGET_MIPS16
5436    && (register_operand (operands[0], SImode)
5437        || register_operand (operands[1], SImode))"
5438   { return mips_output_move (operands[0], operands[1]); }
5439   [(set_attr "type"     "move,move,move,arith,arith,const,load,store,hilo,hilo")
5440    (set_attr "mode"     "SI")
5441    (set_attr_alternative "length"
5442                 [(const_int 4)
5443                  (const_int 4)
5444                  (const_int 4)
5445                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1" "")
5446                                (const_int 4)
5447                                (const_int 8))
5448                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1" "")
5449                                (const_int 8)
5450                                (const_int 12))
5451                  (const_string "*")
5452                  (const_string "*")
5453                  (const_string "*")
5454                  (const_int 4)
5455                  (const_int 4)])])
5456
5457 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
5458 ;; when the original load is a 4 byte instruction but the add and the
5459 ;; load are 2 2 byte instructions.
5460
5461 (define_split
5462   [(set (match_operand:SI 0 "register_operand" "")
5463         (mem:SI (plus:SI (match_dup 0)
5464                          (match_operand:SI 1 "const_int_operand" ""))))]
5465   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5466    && GET_CODE (operands[0]) == REG
5467    && M16_REG_P (REGNO (operands[0]))
5468    && GET_CODE (operands[1]) == CONST_INT
5469    && ((INTVAL (operands[1]) < 0
5470         && INTVAL (operands[1]) >= -0x80)
5471        || (INTVAL (operands[1]) >= 32 * 4
5472            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
5473        || (INTVAL (operands[1]) >= 0
5474            && INTVAL (operands[1]) < 32 * 4
5475            && (INTVAL (operands[1]) & 3) != 0))"
5476   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5477    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
5478   "
5479 {
5480   HOST_WIDE_INT val = INTVAL (operands[1]);
5481
5482   if (val < 0)
5483     operands[2] = GEN_INT (0);
5484   else if (val >= 32 * 4)
5485     {
5486       int off = val & 3;
5487
5488       operands[1] = GEN_INT (0x7c + off);
5489       operands[2] = GEN_INT (val - off - 0x7c);
5490     }
5491   else
5492     {
5493       int off = val & 3;
5494
5495       operands[1] = GEN_INT (off);
5496       operands[2] = GEN_INT (val - off);
5497     }
5498 }")
5499
5500 ;; On the mips16, we can split a load of certain constants into a load
5501 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
5502 ;; instructions.
5503
5504 (define_split
5505   [(set (match_operand:SI 0 "register_operand" "")
5506         (match_operand:SI 1 "const_int_operand" ""))]
5507   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5508    && GET_CODE (operands[0]) == REG
5509    && M16_REG_P (REGNO (operands[0]))
5510    && GET_CODE (operands[1]) == CONST_INT
5511    && INTVAL (operands[1]) >= 0x100
5512    && INTVAL (operands[1]) <= 0xff + 0x7f"
5513   [(set (match_dup 0) (match_dup 1))
5514    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
5515   "
5516 {
5517   int val = INTVAL (operands[1]);
5518
5519   operands[1] = GEN_INT (0xff);
5520   operands[2] = GEN_INT (val - 0xff);
5521 }")
5522
5523 ;; On the mips16, we can split a load of a negative constant into a
5524 ;; load and a neg.  That's what mips_output_move will generate anyhow.
5525
5526 (define_split
5527   [(set (match_operand:SI 0 "register_operand" "")
5528         (match_operand:SI 1 "const_int_operand" ""))]
5529   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5530    && GET_CODE (operands[0]) == REG
5531    && M16_REG_P (REGNO (operands[0]))
5532    && GET_CODE (operands[1]) == CONST_INT
5533    && INTVAL (operands[1]) < 0
5534    && INTVAL (operands[1]) > - 0x8000"
5535   [(set (match_dup 0) (match_dup 1))
5536    (set (match_dup 0) (neg:SI (match_dup 0)))]
5537   "
5538 {
5539   operands[1] = GEN_INT (- INTVAL (operands[1]));
5540 }")
5541
5542 ;; Reload HILO_REGNUM in SI mode.  This needs a scratch register in
5543 ;; order to set the sign bit correctly in the HI register.
5544
5545 (define_expand "reload_outsi"
5546   [(set (match_operand:SI 0 "general_operand" "=b")
5547         (match_operand:SI 1 "register_operand" "b"))
5548    (clobber (match_operand:SI 2 "register_operand" "=&d"))]
5549   "TARGET_64BIT || TARGET_MIPS16"
5550   "
5551 {
5552   if (TARGET_64BIT
5553       && GET_CODE (operands[0]) == REG && REGNO (operands[0]) == HILO_REGNUM)
5554     {
5555       emit_insn (gen_movsi (gen_rtx_REG (SImode, 65), operands[1]));
5556       emit_insn (gen_ashrsi3 (operands[2], operands[1], GEN_INT (31)));
5557       emit_insn (gen_movsi (gen_rtx (REG, SImode, 64), operands[2]));
5558       emit_insn (gen_hilo_delay (operands[0]));
5559       DONE;
5560     }
5561   /* Use a mult to reload LO on mips16.  ??? This is hideous.  */
5562   if (TARGET_MIPS16
5563       && GET_CODE (operands[0]) == REG && REGNO (operands[0]) == LO_REGNUM)
5564     {
5565       emit_insn (gen_movsi (operands[2], GEN_INT (1)));
5566       /* This is gen_mulsi3_internal, but we need to fill in the
5567          scratch registers.  */
5568       emit_insn (gen_rtx (PARALLEL, VOIDmode,
5569                           gen_rtvec (3,
5570                                      gen_rtx (SET, VOIDmode,
5571                                               operands[0],
5572                                               gen_rtx (MULT, SImode,
5573                                                        operands[1],
5574                                                        operands[2])),
5575                                      gen_rtx (CLOBBER, VOIDmode,
5576                                               gen_rtx (REG, SImode, 64)),
5577                                      gen_rtx (CLOBBER, VOIDmode,
5578                                               gen_rtx (REG, SImode, 66)))));
5579       DONE;
5580     }
5581   /* FIXME: I don't know how to get a value into the HI register.  */
5582   if (GET_CODE (operands[0]) == REG
5583       && (TARGET_MIPS16 ? M16_REG_P (REGNO (operands[0]))
5584           : GP_REG_P (REGNO (operands[0]))))
5585     {
5586       emit_move_insn (operands[0], operands[1]);
5587       DONE;
5588     }
5589   /* This handles moves between a float register and HI/LO.  */
5590   emit_move_insn (operands[2], operands[1]);
5591   emit_move_insn (operands[0], operands[2]);
5592   DONE;
5593 }")
5594
5595 ;; Reload a value into HI or LO.  There is no mthi or mtlo on mips16,
5596 ;; so we use a mult.  ??? This is hideous, and we ought to figure out
5597 ;; something better.
5598
5599 ;; We use no predicate for operand1, because it may be a PLUS, and there
5600 ;; is no convenient predicate for that.
5601
5602 (define_expand "reload_insi"
5603   [(set (match_operand:SI 0 "register_operand" "=b")
5604         (match_operand:SI 1 "" "b"))
5605    (clobber (match_operand:SI 2 "register_operand" "=&d"))]
5606   "TARGET_MIPS16"
5607   "
5608 {
5609   if (TARGET_MIPS16
5610       && GET_CODE (operands[0]) == REG && REGNO (operands[0]) == LO_REGNUM)
5611     {
5612       emit_insn (gen_movsi (operands[2], GEN_INT (1)));
5613       /* This is gen_mulsi3_internal, but we need to fill in the
5614          scratch registers.  */
5615       emit_insn (gen_rtx (PARALLEL, VOIDmode,
5616                           gen_rtvec (3,
5617                                      gen_rtx (SET, VOIDmode,
5618                                               operands[0],
5619                                               gen_rtx (MULT, SImode,
5620                                                        operands[1],
5621                                                        operands[2])),
5622                                      gen_rtx (CLOBBER, VOIDmode,
5623                                               gen_rtx (REG, SImode, 64)),
5624                                      gen_rtx (CLOBBER, VOIDmode,
5625                                               gen_rtx (REG, SImode, 66)))));
5626       DONE;
5627     }
5628
5629   /* If this is a plus, then this must be an add of the stack pointer against
5630      either a hard register or a pseudo.  */
5631   if (TARGET_MIPS16 && GET_CODE (operands[1]) == PLUS)
5632     {
5633       rtx plus_op;
5634
5635       if (XEXP (operands[1], 0) == stack_pointer_rtx)
5636         plus_op = XEXP (operands[1], 1);
5637       else if (XEXP (operands[1], 1) == stack_pointer_rtx)
5638         plus_op = XEXP (operands[1], 0);
5639       else
5640         abort ();
5641
5642       /* We should have a register now.  */
5643       if (GET_CODE (plus_op) != REG)
5644         abort ();
5645
5646       if (REGNO (plus_op) < FIRST_PSEUDO_REGISTER)
5647         {
5648           /* We have to have at least one temporary register which is not
5649              overlapping plus_op.  */
5650           if (! rtx_equal_p (plus_op, operands[0]))
5651             {
5652               emit_move_insn (operands[0], stack_pointer_rtx);
5653               emit_insn (gen_addsi3 (operands[0], operands[0], plus_op));
5654             }
5655           else if (! rtx_equal_p (plus_op, operands[2]))
5656             {
5657               emit_move_insn (operands[2], stack_pointer_rtx);
5658               emit_insn (gen_addsi3 (operands[0], plus_op, operands[2]));
5659             }
5660           else
5661             abort ();
5662         }
5663       else
5664         {
5665           /* We need two registers in this case.  */
5666           if (! rtx_equal_p (operands[0], operands[2]))
5667             {
5668               emit_move_insn (operands[0], stack_pointer_rtx);
5669               emit_move_insn (operands[2], plus_op);
5670               emit_insn (gen_addsi3 (operands[0], operands[0], operands[2]));
5671             }
5672           else
5673             abort ();
5674         }
5675       DONE;
5676     }
5677
5678   /* FIXME: I don't know how to get a value into the HI register.  */
5679   emit_move_insn (operands[0], operands[1]);
5680   DONE;
5681 }")
5682
5683 ;; This insn is for the unspec delay for HILO.
5684
5685 (define_insn "hilo_delay"
5686   [(unspec [(match_operand 0 "register_operand" "=b")] UNSPEC_HILO_DELAY)]
5687   ""
5688   ""
5689   [(set_attr "type" "nop")
5690    (set_attr "mode" "none")
5691    (set_attr "can_delay" "no")])
5692
5693 ;; This insn handles moving CCmode values.  It's really just a
5694 ;; slightly simplified copy of movsi_internal2, with additional cases
5695 ;; to move a condition register to a general register and to move
5696 ;; between the general registers and the floating point registers.
5697
5698 (define_insn "movcc"
5699   [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
5700         (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
5701   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
5702   { return mips_output_move (operands[0], operands[1]); }
5703   [(set_attr "type"     "move,move,load,store,xfer,xfer,move,load,store")
5704    (set_attr "mode"     "SI")
5705    (set_attr "length"   "8,4,*,*,4,4,4,*,*")])
5706
5707 ;; Reload condition code registers.  reload_incc and reload_outcc
5708 ;; both handle moves from arbitrary operands into condition code
5709 ;; registers.  reload_incc handles the more common case in which
5710 ;; a source operand is constrained to be in a condition-code
5711 ;; register, but has not been allocated to one.
5712 ;;
5713 ;; Sometimes, such as in movcc, we have a CCmode destination whose
5714 ;; constraints do not include 'z'.  reload_outcc handles the case
5715 ;; when such an operand is allocated to a condition-code register.
5716 ;;
5717 ;; Note that reloads from a condition code register to some
5718 ;; other location can be done using ordinary moves.  Moving
5719 ;; into a GPR takes a single movcc, moving elsewhere takes
5720 ;; two.  We can leave these cases to the generic reload code.
5721 (define_expand "reload_incc"
5722   [(set (match_operand:CC 0 "fcc_register_operand" "=z")
5723         (match_operand:CC 1 "general_operand" ""))
5724    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
5725   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
5726   "
5727 {
5728   mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
5729   DONE;
5730 }")
5731
5732 (define_expand "reload_outcc"
5733   [(set (match_operand:CC 0 "fcc_register_operand" "=z")
5734         (match_operand:CC 1 "register_operand" ""))
5735    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
5736   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
5737   "
5738 {
5739   mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
5740   DONE;
5741 }")
5742
5743 ;; MIPS4 supports loading and storing a floating point register from
5744 ;; the sum of two general registers.  We use two versions for each of
5745 ;; these four instructions: one where the two general registers are
5746 ;; SImode, and one where they are DImode.  This is because general
5747 ;; registers will be in SImode when they hold 32 bit values, but,
5748 ;; since the 32 bit values are always sign extended, the [ls][wd]xc1
5749 ;; instructions will still work correctly.
5750
5751 ;; ??? Perhaps it would be better to support these instructions by
5752 ;; modifying GO_IF_LEGITIMATE_ADDRESS and friends.  However, since
5753 ;; these instructions can only be used to load and store floating
5754 ;; point registers, that would probably cause trouble in reload.
5755
5756 (define_insn ""
5757   [(set (match_operand:SF 0 "register_operand" "=f")
5758         (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "d")
5759                          (match_operand:SI 2 "register_operand" "d"))))]
5760   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
5761   "lwxc1\\t%0,%1(%2)"
5762   [(set_attr "type"     "load")
5763    (set_attr "mode"     "SF")
5764    (set_attr "length"   "4")])
5765
5766 (define_insn ""
5767   [(set (match_operand:SF 0 "register_operand" "=f")
5768         (mem:SF (plus:DI (match_operand:DI 1 "register_operand" "d")
5769                          (match_operand:DI 2 "register_operand" "d"))))]
5770   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
5771   "lwxc1\\t%0,%1(%2)"
5772   [(set_attr "type"     "load")
5773    (set_attr "mode"     "SF")
5774    (set_attr "length"   "4")])
5775
5776 (define_insn ""
5777   [(set (match_operand:DF 0 "register_operand" "=f")
5778         (mem:DF (plus:SI (match_operand:SI 1 "register_operand" "d")
5779                          (match_operand:SI 2 "register_operand" "d"))))]
5780   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5781   "ldxc1\\t%0,%1(%2)"
5782   [(set_attr "type"     "load")
5783    (set_attr "mode"     "DF")
5784    (set_attr "length"   "4")])
5785
5786 (define_insn ""
5787   [(set (match_operand:DF 0 "register_operand" "=f")
5788         (mem:DF (plus:DI (match_operand:DI 1 "register_operand" "d")
5789                          (match_operand:DI 2 "register_operand" "d"))))]
5790   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5791   "ldxc1\\t%0,%1(%2)"
5792   [(set_attr "type"     "load")
5793    (set_attr "mode"     "DF")
5794    (set_attr "length"   "4")])
5795
5796 (define_insn ""
5797   [(set (mem:SF (plus:SI (match_operand:SI 1 "register_operand" "d")
5798                          (match_operand:SI 2 "register_operand" "d")))
5799         (match_operand:SF 0 "register_operand" "f"))]
5800   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
5801   "swxc1\\t%0,%1(%2)"
5802   [(set_attr "type"     "store")
5803    (set_attr "mode"     "SF")
5804    (set_attr "length"   "4")])
5805
5806 (define_insn ""
5807   [(set (mem:SF (plus:DI (match_operand:DI 1 "register_operand" "d")
5808                          (match_operand:DI 2 "register_operand" "d")))
5809         (match_operand:SF 0 "register_operand" "f"))]
5810   "ISA_HAS_FP4 && TARGET_HARD_FLOAT"
5811   "swxc1\\t%0,%1(%2)"
5812   [(set_attr "type"     "store")
5813    (set_attr "mode"     "SF")
5814    (set_attr "length"   "4")])
5815
5816 (define_insn ""
5817   [(set (mem:DF (plus:SI (match_operand:SI 1 "register_operand" "d")
5818                          (match_operand:SI 2 "register_operand" "d")))
5819         (match_operand:DF 0 "register_operand" "f"))]
5820   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5821   "sdxc1\\t%0,%1(%2)"
5822   [(set_attr "type"     "store")
5823    (set_attr "mode"     "DF")
5824    (set_attr "length"   "4")])
5825
5826 (define_insn ""
5827   [(set (mem:DF (plus:DI (match_operand:DI 1 "register_operand" "d")
5828                          (match_operand:DI 2 "register_operand" "d")))
5829         (match_operand:DF 0 "register_operand" "f"))]
5830   "ISA_HAS_FP4 && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5831   "sdxc1\\t%0,%1(%2)"
5832   [(set_attr "type"     "store")
5833    (set_attr "mode"     "DF")
5834    (set_attr "length"   "4")])
5835
5836 ;; 16-bit Integer moves
5837
5838 ;; Unlike most other insns, the move insns can't be split with
5839 ;; different predicates, because register spilling and other parts of
5840 ;; the compiler, have memoized the insn number already.
5841 ;; Unsigned loads are used because BYTE_LOADS_ZERO_EXTEND is defined
5842
5843 (define_expand "movhi"
5844   [(set (match_operand:HI 0 "nonimmediate_operand" "")
5845         (match_operand:HI 1 "general_operand" ""))]
5846   ""
5847   "
5848 {
5849   if ((reload_in_progress | reload_completed) == 0
5850       && !register_operand (operands[0], HImode)
5851       && !register_operand (operands[1], HImode)
5852       && (TARGET_MIPS16
5853           || (GET_CODE (operands[1]) != CONST_INT
5854           || INTVAL (operands[1]) != 0)))
5855     {
5856       rtx temp = force_reg (HImode, operands[1]);
5857       emit_move_insn (operands[0], temp);
5858       DONE;
5859     }
5860 }")
5861
5862 ;; The difference between these two is whether or not ints are allowed
5863 ;; in FP registers (off by default, use -mdebugh to enable).
5864
5865 (define_insn "movhi_internal"
5866   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x,*d")
5867         (match_operand:HI 1 "general_operand"       "d,IK,m,dJ,*f,*d,*f,*d,*x"))]
5868   "!TARGET_MIPS16
5869    && (register_operand (operands[0], HImode)
5870        || register_operand (operands[1], HImode)
5871        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
5872   "@
5873     move\t%0,%1
5874     li\t%0,%1
5875     lhu\t%0,%1
5876     sh\t%z1,%0
5877     mfc1\t%0,%1
5878     mtc1\t%1,%0
5879     mov.s\t%0,%1
5880     mt%0\t%1
5881     mf%1\t%0"
5882   [(set_attr "type"     "move,arith,load,store,xfer,xfer,move,hilo,hilo")
5883    (set_attr "mode"     "HI")
5884    (set_attr "length"   "4,4,*,*,4,4,4,4,4")])
5885
5886 (define_insn ""
5887   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5888         (match_operand:HI 1 "general_operand"      "d,d,y,K,N,m,d,*x"))]
5889   "TARGET_MIPS16
5890    && (register_operand (operands[0], HImode)
5891        || register_operand (operands[1], HImode))"
5892   "@
5893     move\t%0,%1
5894     move\t%0,%1
5895     move\t%0,%1
5896     li\t%0,%1
5897     li\t%0,%n1\;neg\t%0
5898     lhu\t%0,%1
5899     sh\t%1,%0
5900     mf%1\t%0"
5901   [(set_attr "type"     "move,move,move,arith,arith,load,store,hilo")
5902    (set_attr "mode"     "HI")
5903    (set_attr_alternative "length"
5904                 [(const_int 4)
5905                  (const_int 4)
5906                  (const_int 4)
5907                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1" "")
5908                                (const_int 4)
5909                                (const_int 8))
5910                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1" "")
5911                                (const_int 8)
5912                                (const_int 12))
5913                  (const_string "*")
5914                  (const_string "*")
5915                  (const_int 4)])])
5916
5917
5918 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
5919 ;; when the original load is a 4 byte instruction but the add and the
5920 ;; load are 2 2 byte instructions.
5921
5922 (define_split
5923   [(set (match_operand:HI 0 "register_operand" "")
5924         (mem:HI (plus:SI (match_dup 0)
5925                          (match_operand:SI 1 "const_int_operand" ""))))]
5926   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5927    && GET_CODE (operands[0]) == REG
5928    && M16_REG_P (REGNO (operands[0]))
5929    && GET_CODE (operands[1]) == CONST_INT
5930    && ((INTVAL (operands[1]) < 0
5931         && INTVAL (operands[1]) >= -0x80)
5932        || (INTVAL (operands[1]) >= 32 * 2
5933            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
5934        || (INTVAL (operands[1]) >= 0
5935            && INTVAL (operands[1]) < 32 * 2
5936            && (INTVAL (operands[1]) & 1) != 0))"
5937   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5938    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
5939   "
5940 {
5941   HOST_WIDE_INT val = INTVAL (operands[1]);
5942
5943   if (val < 0)
5944     operands[2] = GEN_INT (0);
5945   else if (val >= 32 * 2)
5946     {
5947       int off = val & 1;
5948
5949       operands[1] = GEN_INT (0x7e + off);
5950       operands[2] = GEN_INT (val - off - 0x7e);
5951     }
5952   else
5953     {
5954       int off = val & 1;
5955
5956       operands[1] = GEN_INT (off);
5957       operands[2] = GEN_INT (val - off);
5958     }
5959 }")
5960
5961 ;; 8-bit Integer moves
5962
5963 ;; Unlike most other insns, the move insns can't be split with
5964 ;; different predicates, because register spilling and other parts of
5965 ;; the compiler, have memoized the insn number already.
5966 ;; Unsigned loads are used because BYTE_LOADS_ZERO_EXTEND is defined
5967
5968 (define_expand "movqi"
5969   [(set (match_operand:QI 0 "nonimmediate_operand" "")
5970         (match_operand:QI 1 "general_operand" ""))]
5971   ""
5972   "
5973 {
5974   if ((reload_in_progress | reload_completed) == 0
5975       && !register_operand (operands[0], QImode)
5976       && !register_operand (operands[1], QImode)
5977       && (TARGET_MIPS16
5978           || (GET_CODE (operands[1]) != CONST_INT
5979           || INTVAL (operands[1]) != 0)))
5980     {
5981       rtx temp = force_reg (QImode, operands[1]);
5982       emit_move_insn (operands[0], temp);
5983       DONE;
5984     }
5985 }")
5986
5987 ;; The difference between these two is whether or not ints are allowed
5988 ;; in FP registers (off by default, use -mdebugh to enable).
5989
5990 (define_insn "movqi_internal"
5991   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x,*d")
5992         (match_operand:QI 1 "general_operand"       "d,IK,m,dJ,*f,*d,*f,*d,*x"))]
5993   "!TARGET_MIPS16
5994    && (register_operand (operands[0], QImode)
5995        || register_operand (operands[1], QImode)
5996        || (GET_CODE (operands[1]) == CONST_INT && INTVAL (operands[1]) == 0))"
5997   "@
5998     move\t%0,%1
5999     li\t%0,%1
6000     lbu\t%0,%1
6001     sb\t%z1,%0
6002     mfc1\t%0,%1
6003     mtc1\t%1,%0
6004     mov.s\t%0,%1
6005     mt%0\t%1
6006     mf%1\t%0"
6007   [(set_attr "type"     "move,arith,load,store,xfer,xfer,move,hilo,hilo")
6008    (set_attr "mode"     "QI")
6009    (set_attr "length"   "4,4,*,*,4,4,4,4,4")])
6010
6011 (define_insn ""
6012   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
6013         (match_operand:QI 1 "general_operand"      "d,d,y,K,N,m,d,*x"))]
6014   "TARGET_MIPS16
6015    && (register_operand (operands[0], QImode)
6016        || register_operand (operands[1], QImode))"
6017   "@
6018     move\t%0,%1
6019     move\t%0,%1
6020     move\t%0,%1
6021     li\t%0,%1
6022     li\t%0,%n1\;neg\t%0
6023     lbu\t%0,%1
6024     sb\t%1,%0
6025     mf%1\t%0"
6026   [(set_attr "type"     "move,move,move,arith,arith,load,store,hilo")
6027    (set_attr "mode"     "QI")
6028    (set_attr "length"   "4,4,4,4,8,*,*,4")])
6029
6030 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
6031 ;; when the original load is a 4 byte instruction but the add and the
6032 ;; load are 2 2 byte instructions.
6033
6034 (define_split
6035   [(set (match_operand:QI 0 "register_operand" "")
6036         (mem:QI (plus:SI (match_dup 0)
6037                          (match_operand:SI 1 "const_int_operand" ""))))]
6038   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
6039    && GET_CODE (operands[0]) == REG
6040    && M16_REG_P (REGNO (operands[0]))
6041    && GET_CODE (operands[1]) == CONST_INT
6042    && ((INTVAL (operands[1]) < 0
6043         && INTVAL (operands[1]) >= -0x80)
6044        || (INTVAL (operands[1]) >= 32
6045            && INTVAL (operands[1]) <= 31 + 0x7f))"
6046   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
6047    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
6048   "
6049 {
6050   HOST_WIDE_INT val = INTVAL (operands[1]);
6051
6052   if (val < 0)
6053     operands[2] = GEN_INT (0);
6054   else
6055     {
6056       operands[1] = GEN_INT (0x7f);
6057       operands[2] = GEN_INT (val - 0x7f);
6058     }
6059 }")
6060
6061 ;; 32-bit floating point moves
6062
6063 (define_expand "movsf"
6064   [(set (match_operand:SF 0 "nonimmediate_operand" "")
6065         (match_operand:SF 1 "general_operand" ""))]
6066   ""
6067   "
6068 {
6069   if ((reload_in_progress | reload_completed) == 0
6070       && !register_operand (operands[0], SFmode)
6071       && !nonmemory_operand (operands[1], SFmode))
6072     operands[1] = force_reg (SFmode, operands[1]);
6073 }")
6074
6075 (define_insn "movsf_internal1"
6076   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,*f,*d,*d,*d,*m")
6077         (match_operand:SF 1 "general_operand" "f,G,m,fG,*d,*f,*G*d,*m,*d"))]
6078   "TARGET_HARD_FLOAT
6079    && (register_operand (operands[0], SFmode)
6080        || nonmemory_operand (operands[1], SFmode))"
6081   { return mips_output_move (operands[0], operands[1]); }
6082   [(set_attr "type"     "move,xfer,load,store,xfer,xfer,move,load,store")
6083    (set_attr "mode"     "SF")
6084    (set_attr "length"   "4,4,*,*,4,4,4,*,*")])
6085
6086 (define_insn "movsf_internal2"
6087   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
6088         (match_operand:SF 1 "general_operand" "      Gd,m,d"))]
6089   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
6090    && (register_operand (operands[0], SFmode)
6091        || nonmemory_operand (operands[1], SFmode))"
6092   { return mips_output_move (operands[0], operands[1]); }
6093   [(set_attr "type"     "move,load,store")
6094    (set_attr "mode"     "SF")
6095    (set_attr "length"   "4,*,*")])
6096
6097 (define_insn ""
6098   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
6099         (match_operand:SF 1 "nonimmediate_operand" "d,d,y,m,d"))]
6100   "TARGET_MIPS16
6101    && (register_operand (operands[0], SFmode)
6102        || register_operand (operands[1], SFmode))"
6103   { return mips_output_move (operands[0], operands[1]); }
6104   [(set_attr "type"     "move,move,move,load,store")
6105    (set_attr "mode"     "SF")
6106    (set_attr "length"   "4,4,4,*,*")])
6107
6108
6109 ;; 64-bit floating point moves
6110
6111 (define_expand "movdf"
6112   [(set (match_operand:DF 0 "nonimmediate_operand" "")
6113         (match_operand:DF 1 "general_operand" ""))]
6114   ""
6115   "
6116 {
6117   if ((reload_in_progress | reload_completed) == 0
6118       && !register_operand (operands[0], DFmode)
6119       && !nonmemory_operand (operands[1], DFmode))
6120     operands[1] = force_reg (DFmode, operands[1]);
6121 }")
6122
6123 (define_insn "movdf_internal1a"
6124   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,*f,*d,*d,*d,*m")
6125         (match_operand:DF 1 "general_operand" "f,G,m,fG,*d,*f,*d*G,*m,*d"))]
6126   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_64BIT
6127    && (register_operand (operands[0], DFmode)
6128        || nonmemory_operand (operands[1], DFmode))"
6129   { return mips_output_move (operands[0], operands[1]); }
6130   [(set_attr "type"     "move,xfer,load,store,xfer,xfer,move,load,store")
6131    (set_attr "mode"     "DF")
6132    (set_attr "length"   "4,4,*,*,4,4,4,*,*")])
6133
6134 (define_insn "movdf_internal1b"
6135   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,*f,*d,*d,*d,*m")
6136         (match_operand:DF 1 "general_operand" "f,G,m,fG,*d,*f,*d*G,*m,*d"))]
6137   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT
6138    && (register_operand (operands[0], DFmode)
6139        || nonmemory_operand (operands[1], DFmode))"
6140   { return mips_output_move (operands[0], operands[1]); }
6141   [(set_attr "type"     "move,xfer,load,store,xfer,xfer,move,load,store")
6142    (set_attr "mode"     "DF")
6143    (set_attr "length"   "4,8,*,*,8,8,8,*,*")])
6144
6145 (define_insn "movdf_internal2"
6146   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m,d,f,f")
6147         (match_operand:DF 1 "general_operand" "dG,m,dG,f,d,f"))]
6148   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
6149    && (register_operand (operands[0], DFmode)
6150        || nonmemory_operand (operands[1], DFmode))"
6151   { return mips_output_move (operands[0], operands[1]); }
6152   [(set_attr "type"     "move,load,store,xfer,xfer,move")
6153    (set_attr "mode"     "DF")
6154    (set_attr "length"   "8,*,*,4,4,4")])
6155
6156 (define_insn ""
6157   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
6158         (match_operand:DF 1 "nonimmediate_operand" "d,d,y,m,d"))]
6159   "TARGET_MIPS16
6160    && (register_operand (operands[0], DFmode)
6161        || register_operand (operands[1], DFmode))"
6162   { return mips_output_move (operands[0], operands[1]); }
6163   [(set_attr "type"     "move,move,move,load,store")
6164    (set_attr "mode"     "DF")
6165    (set_attr "length"   "8,8,8,*,*")])
6166
6167 (define_split
6168   [(set (match_operand:DI 0 "nonimmediate_operand" "")
6169         (match_operand:DI 1 "general_operand" ""))]
6170   "reload_completed && !TARGET_64BIT
6171    && mips_split_64bit_move_p (operands[0], operands[1])"
6172   [(const_int 0)]
6173   {
6174     mips_split_64bit_move (operands[0], operands[1]);
6175     DONE;
6176   })
6177
6178 (define_split
6179   [(set (match_operand:DF 0 "nonimmediate_operand" "")
6180         (match_operand:DF 1 "general_operand" ""))]
6181   "reload_completed && !TARGET_64BIT
6182    && mips_split_64bit_move_p (operands[0], operands[1])"
6183   [(const_int 0)]
6184   {
6185     mips_split_64bit_move (operands[0], operands[1]);
6186     DONE;
6187   })
6188
6189 ;; Patterns for loading or storing part of a paired floating point
6190 ;; register.  We need them because odd-numbered floating-point registers
6191 ;; are not fully independent: see mips_split_64bit_move.
6192
6193 ;; Load the low word of operand 0 with operand 1.
6194 (define_insn "load_df_low"
6195   [(set (match_operand:DF 0 "register_operand" "=f,f")
6196         (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")]
6197                    UNSPEC_LOAD_DF_LOW))]
6198   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
6199   {
6200     operands[0] = mips_subword (operands[0], 0);
6201     return mips_output_move (operands[0], operands[1]);
6202   }
6203   [(set_attr "type"     "xfer,load")
6204    (set_attr "mode"     "SF")
6205    (set_attr "length"   "4")])
6206
6207 ;; Load the high word of operand 0 from operand 1, preserving the value
6208 ;; in the low word.
6209 (define_insn "load_df_high"
6210   [(set (match_operand:DF 0 "register_operand" "=f,f")
6211         (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")
6212                     (match_operand:DF 2 "register_operand" "0,0")]
6213                    UNSPEC_LOAD_DF_HIGH))]
6214   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
6215   {
6216     operands[0] = mips_subword (operands[0], 1);
6217     return mips_output_move (operands[0], operands[1]);
6218   }
6219   [(set_attr "type"     "xfer,load")
6220    (set_attr "mode"     "SF")
6221    (set_attr "length"   "4")])
6222
6223 ;; Store the high word of operand 1 in operand 0.  The corresponding
6224 ;; low-word move is done in the normal way.
6225 (define_insn "store_df_high"
6226   [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
6227         (unspec:SI [(match_operand:DF 1 "register_operand" "f,f")]
6228                    UNSPEC_STORE_DF_HIGH))]
6229   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
6230   {
6231     operands[1] = mips_subword (operands[1], 1);
6232     return mips_output_move (operands[0], operands[1]);
6233   }
6234   [(set_attr "type"     "xfer,store")
6235    (set_attr "mode"     "SF")
6236    (set_attr "length"   "4")])
6237
6238 ;; Instructions to load the global pointer register.
6239 ;; This is volatile to make sure that the scheduler won't move any symbol_ref
6240 ;; uses in front of it.  All symbol_refs implicitly use the gp reg.
6241
6242 (define_insn "loadgp"
6243   [(set (reg:DI 28)
6244         (unspec_volatile:DI [(match_operand 0 "immediate_operand" "")
6245                              (match_operand:DI 1 "register_operand" "")]
6246                             UNSPEC_LOADGP))
6247    (clobber (reg:DI 1))]
6248   ""
6249   "%[lui\\t$1,%%hi(%%neg(%%gp_rel(%0)))\\n\\taddiu\\t$1,$1,%%lo(%%neg(%%gp_rel(%0)))\\n\\tdaddu\\t$gp,$1,%1%]"
6250   [(set_attr "type"     "move")
6251    (set_attr "mode"     "DI")
6252    (set_attr "length"   "12")])
6253 \f
6254 ;; Block moves, see mips.c for more details.
6255 ;; Argument 0 is the destination
6256 ;; Argument 1 is the source
6257 ;; Argument 2 is the length
6258 ;; Argument 3 is the alignment
6259
6260 (define_expand "movstrsi"
6261   [(parallel [(set (match_operand:BLK 0 "general_operand" "")
6262                    (match_operand:BLK 1 "general_operand" ""))
6263               (use (match_operand:SI 2 "arith32_operand" ""))
6264               (use (match_operand:SI 3 "immediate_operand" ""))])]
6265   "!TARGET_MIPS16"
6266   "
6267 {
6268   if (operands[0])              /* avoid unused code messages */
6269     {
6270       expand_block_move (operands);
6271       DONE;
6272     }
6273 }")
6274
6275 ;; Insn generated by block moves
6276
6277 (define_insn "movstrsi_internal"
6278   [(set (match_operand:BLK 0 "memory_operand" "=o")     ;; destination
6279         (match_operand:BLK 1 "memory_operand" "o"))     ;; source
6280    (clobber (match_scratch:SI 4 "=&d"))                 ;; temp 1
6281    (clobber (match_scratch:SI 5 "=&d"))                 ;; temp 2
6282    (clobber (match_scratch:SI 6 "=&d"))                 ;; temp 3
6283    (clobber (match_scratch:SI 7 "=&d"))                 ;; temp 4
6284    (use (match_operand:SI 2 "small_int" "I"))           ;; # bytes to move
6285    (use (match_operand:SI 3 "small_int" "I"))           ;; alignment
6286    (use (const_int 0))]                                 ;; normal block move
6287   ""
6288   "* return output_block_move (insn, operands, 4, BLOCK_MOVE_NORMAL);"
6289   [(set_attr "type"     "store")
6290    (set_attr "mode"     "none")
6291    (set_attr "length"   "80")])
6292
6293 ;; We need mips16 versions, because an offset from the stack pointer
6294 ;; is not offsettable, since the stack pointer can only handle 4 and 8
6295 ;; byte loads.
6296
6297 (define_insn ""
6298   [(set (match_operand:BLK 0 "memory_operand" "=o")     ;; destination
6299         (match_operand:BLK 1 "memory_operand" "o"))     ;; source
6300    (clobber (match_scratch:SI 4 "=&d"))                 ;; temp 1
6301    (clobber (match_scratch:SI 5 "=&d"))                 ;; temp 2
6302    (clobber (match_scratch:SI 6 "=&d"))                 ;; temp 3
6303    (clobber (match_scratch:SI 7 "=&d"))                 ;; temp 4
6304    (use (match_operand:SI 2 "small_int" "I"))           ;; # bytes to move
6305    (use (match_operand:SI 3 "small_int" "I"))           ;; alignment
6306    (use (const_int 0))]                                 ;; normal block move
6307   "TARGET_MIPS16"
6308   "* return output_block_move (insn, operands, 4, BLOCK_MOVE_NORMAL);"
6309   [(set_attr "type"     "multi")
6310    (set_attr "mode"     "none")
6311    (set_attr "length"   "80")])
6312
6313 ;; Split a block move into 2 parts, the first part is everything
6314 ;; except for the last move, and the second part is just the last
6315 ;; store, which is exactly 1 instruction (ie, not a usw), so it can
6316 ;; fill a delay slot.  This also prevents a bug in delayed branches
6317 ;; from showing up, which reuses one of the registers in our clobbers.
6318
6319 ;; ??? Disabled because it doesn't preserve alias information for
6320 ;; operands 0 and 1.  Also, the rtl for the second insn doesn't mention
6321 ;; that it uses the registers clobbered by the first.
6322 ;;
6323 ;; It would probably be better to split the block into individual
6324 ;; instructions instead.
6325 (define_split
6326   [(set (mem:BLK (match_operand:SI 0 "register_operand" ""))
6327         (mem:BLK (match_operand:SI 1 "register_operand" "")))
6328    (clobber (match_operand:SI 4 "register_operand" ""))
6329    (clobber (match_operand:SI 5 "register_operand" ""))
6330    (clobber (match_operand:SI 6 "register_operand" ""))
6331    (clobber (match_operand:SI 7 "register_operand" ""))
6332    (use (match_operand:SI 2 "small_int" ""))
6333    (use (match_operand:SI 3 "small_int" ""))
6334    (use (const_int 0))]
6335
6336   "reload_completed && 0 && INTVAL (operands[2]) > 0"
6337
6338   ;; All but the last move
6339   [(parallel [(set (mem:BLK (match_dup 0))
6340                    (mem:BLK (match_dup 1)))
6341               (clobber (match_dup 4))
6342               (clobber (match_dup 5))
6343               (clobber (match_dup 6))
6344               (clobber (match_dup 7))
6345               (use (match_dup 2))
6346               (use (match_dup 3))
6347               (use (const_int 1))])
6348
6349    ;; The last store, so it can fill a delay slot
6350    (parallel [(set (mem:BLK (match_dup 0))
6351                    (mem:BLK (match_dup 1)))
6352               (clobber (match_dup 4))
6353               (clobber (match_dup 5))
6354               (clobber (match_dup 6))
6355               (clobber (match_dup 7))
6356               (use (match_dup 2))
6357               (use (match_dup 3))
6358               (use (const_int 2))])]
6359
6360   "")
6361
6362 (define_insn "movstrsi_internal2"
6363   [(set (match_operand:BLK 0 "memory_operand" "=o")     ;; destination
6364         (match_operand:BLK 1 "memory_operand" "o"))     ;; source
6365    (clobber (match_scratch:SI 4 "=&d"))                 ;; temp 1
6366    (clobber (match_scratch:SI 5 "=&d"))                 ;; temp 2
6367    (clobber (match_scratch:SI 6 "=&d"))                 ;; temp 3
6368    (clobber (match_scratch:SI 7 "=&d"))                 ;; temp 4
6369    (use (match_operand:SI 2 "small_int" "I"))           ;; # bytes to move
6370    (use (match_operand:SI 3 "small_int" "I"))           ;; alignment
6371    (use (const_int 1))]                                 ;; all but last store
6372   ""
6373   "* return output_block_move (insn, operands, 4, BLOCK_MOVE_NOT_LAST);"
6374   [(set_attr "type"     "store")
6375    (set_attr "mode"     "none")
6376    (set_attr "length"   "80")])
6377
6378 (define_insn ""
6379   [(set (match_operand:BLK 0 "memory_operand" "=o")     ;; destination
6380         (match_operand:BLK 1 "memory_operand" "o"))     ;; source
6381    (clobber (match_scratch:SI 4 "=&d"))                 ;; temp 1
6382    (clobber (match_scratch:SI 5 "=&d"))                 ;; temp 2
6383    (clobber (match_scratch:SI 6 "=&d"))                 ;; temp 3
6384    (clobber (match_scratch:SI 7 "=&d"))                 ;; temp 4
6385    (use (match_operand:SI 2 "small_int" "I"))           ;; # bytes to move
6386    (use (match_operand:SI 3 "small_int" "I"))           ;; alignment
6387    (use (const_int 1))]                                 ;; all but last store
6388   "TARGET_MIPS16"
6389   "* return output_block_move (insn, operands, 4, BLOCK_MOVE_NOT_LAST);"
6390   [(set_attr "type"     "multi")
6391    (set_attr "mode"     "none")
6392    (set_attr "length"   "80")])
6393
6394 (define_insn "movstrsi_internal3"
6395   [(set (match_operand:BLK 0 "memory_operand" "=m")     ;; destination
6396         (match_operand:BLK 1 "memory_operand" "m"))     ;; source
6397    (clobber (match_scratch:SI 4 "=&d"))                 ;; temp 1
6398    (clobber (match_scratch:SI 5 "=&d"))                 ;; temp 2
6399    (clobber (match_scratch:SI 6 "=&d"))                 ;; temp 3
6400    (clobber (match_scratch:SI 7 "=&d"))                 ;; temp 4
6401    (use (match_operand:SI 2 "small_int" "I"))           ;; # bytes to move
6402    (use (match_operand:SI 3 "small_int" "I"))           ;; alignment
6403    (use (const_int 2))]                                 ;; just last store of block move
6404   ""
6405   "* return output_block_move (insn, operands, 4, BLOCK_MOVE_LAST);"
6406   [(set_attr "type"     "store")
6407    (set_attr "mode"     "none")])
6408 \f
6409 ;;
6410 ;;  ....................
6411 ;;
6412 ;;      SHIFTS
6413 ;;
6414 ;;  ....................
6415
6416 ;; Many of these instructions uses trivial define_expands, because we
6417 ;; want to use a different set of constraints when TARGET_MIPS16.
6418
6419 (define_expand "ashlsi3"
6420   [(set (match_operand:SI 0 "register_operand" "=d")
6421         (ashift:SI (match_operand:SI 1 "register_operand" "d")
6422                    (match_operand:SI 2 "arith_operand" "dI")))]
6423   ""
6424   "
6425 {
6426   /* On the mips16, a shift of more than 8 is a four byte instruction,
6427      so, for a shift between 8 and 16, it is just as fast to do two
6428      shifts of 8 or less.  If there is a lot of shifting going on, we
6429      may win in CSE.  Otherwise combine will put the shifts back
6430      together again.  This can be called by function_arg, so we must
6431      be careful not to allocate a new register if we've reached the
6432      reload pass.  */
6433   if (TARGET_MIPS16
6434       && optimize
6435       && GET_CODE (operands[2]) == CONST_INT
6436       && INTVAL (operands[2]) > 8
6437       && INTVAL (operands[2]) <= 16
6438       && ! reload_in_progress
6439       && ! reload_completed)
6440     {
6441       rtx temp = gen_reg_rtx (SImode);
6442
6443       emit_insn (gen_ashlsi3_internal2 (temp, operands[1], GEN_INT (8)));
6444       emit_insn (gen_ashlsi3_internal2 (operands[0], temp,
6445                                         GEN_INT (INTVAL (operands[2]) - 8)));
6446       DONE;
6447     }
6448 }")
6449
6450 (define_insn "ashlsi3_internal1"
6451   [(set (match_operand:SI 0 "register_operand" "=d")
6452         (ashift:SI (match_operand:SI 1 "register_operand" "d")
6453                    (match_operand:SI 2 "arith_operand" "dI")))]
6454   "!TARGET_MIPS16"
6455   "*
6456 {
6457   if (GET_CODE (operands[2]) == CONST_INT)
6458     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6459
6460   return \"sll\\t%0,%1,%2\";
6461 }"
6462   [(set_attr "type"     "arith")
6463    (set_attr "mode"     "SI")])
6464
6465 (define_insn "ashlsi3_internal1_extend"
6466   [(set (match_operand:DI 0 "register_operand" "=d")
6467        (sign_extend:DI (ashift:SI (match_operand:SI 1 "register_operand" "d")
6468                                   (match_operand:SI 2 "arith_operand" "dI"))))]
6469   "TARGET_64BIT && !TARGET_MIPS16"
6470   "*
6471 {
6472   if (GET_CODE (operands[2]) == CONST_INT)
6473     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6474
6475   return \"sll\\t%0,%1,%2\";
6476 }"
6477   [(set_attr "type"    "arith")
6478    (set_attr "mode"    "DI")])
6479
6480
6481 (define_insn "ashlsi3_internal2"
6482   [(set (match_operand:SI 0 "register_operand" "=d,d")
6483         (ashift:SI (match_operand:SI 1 "register_operand" "0,d")
6484                    (match_operand:SI 2 "arith_operand" "d,I")))]
6485   "TARGET_MIPS16"
6486   "*
6487 {
6488   if (which_alternative == 0)
6489     return \"sll\\t%0,%2\";
6490
6491   if (GET_CODE (operands[2]) == CONST_INT)
6492     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6493
6494   return \"sll\\t%0,%1,%2\";
6495 }"
6496   [(set_attr "type"     "arith")
6497    (set_attr "mode"     "SI")
6498    (set_attr_alternative "length"
6499                 [(const_int 4)
6500                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6501                                (const_int 4)
6502                                (const_int 8))])])
6503
6504 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
6505
6506 (define_split
6507   [(set (match_operand:SI 0 "register_operand" "")
6508         (ashift:SI (match_operand:SI 1 "register_operand" "")
6509                    (match_operand:SI 2 "const_int_operand" "")))]
6510   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
6511    && GET_CODE (operands[2]) == CONST_INT
6512    && INTVAL (operands[2]) > 8
6513    && INTVAL (operands[2]) <= 16"
6514   [(set (match_dup 0) (ashift:SI (match_dup 1) (const_int 8)))
6515    (set (match_dup 0) (ashift:SI (match_dup 0) (match_dup 2)))]
6516 "
6517 {
6518   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
6519 }")
6520
6521 (define_expand "ashldi3"
6522   [(parallel [(set (match_operand:DI 0 "register_operand" "")
6523                    (ashift:DI (match_operand:DI 1 "register_operand" "")
6524                               (match_operand:SI 2 "arith_operand" "")))
6525               (clobber (match_dup  3))])]
6526   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
6527   "
6528 {
6529   if (TARGET_64BIT)
6530     {
6531       /* On the mips16, a shift of more than 8 is a four byte
6532          instruction, so, for a shift between 8 and 16, it is just as
6533          fast to do two shifts of 8 or less.  If there is a lot of
6534          shifting going on, we may win in CSE.  Otherwise combine will
6535          put the shifts back together again.  This can be called by
6536          function_arg, so we must be careful not to allocate a new
6537          register if we've reached the reload pass.  */
6538       if (TARGET_MIPS16
6539           && optimize
6540           && GET_CODE (operands[2]) == CONST_INT
6541           && INTVAL (operands[2]) > 8
6542           && INTVAL (operands[2]) <= 16
6543           && ! reload_in_progress
6544           && ! reload_completed)
6545         {
6546           rtx temp = gen_reg_rtx (DImode);
6547
6548           emit_insn (gen_ashldi3_internal4 (temp, operands[1], GEN_INT (8)));
6549           emit_insn (gen_ashldi3_internal4 (operands[0], temp,
6550                                             GEN_INT (INTVAL (operands[2]) - 8)));
6551           DONE;
6552         }
6553
6554       emit_insn (gen_ashldi3_internal4 (operands[0], operands[1],
6555                                         operands[2]));
6556       DONE;
6557     }
6558
6559   operands[3] = gen_reg_rtx (SImode);
6560 }")
6561
6562
6563 (define_insn "ashldi3_internal"
6564   [(set (match_operand:DI 0 "register_operand" "=&d")
6565         (ashift:DI (match_operand:DI 1 "register_operand" "d")
6566                    (match_operand:SI 2 "register_operand" "d")))
6567    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6568   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
6569   "*
6570 {
6571   operands[4] = const0_rtx;
6572
6573   return \"sll\\t%3,%2,26\\n\\
6574 \\tbgez\\t%3,1f\\n\\
6575 \\tsll\\t%M0,%L1,%2\\n\\
6576 \\t%(b\\t3f\\n\\
6577 \\tmove\\t%L0,%z4%)\\n\\
6578 \\n\\
6579 %~1:\\n\\
6580 \\t%(beq\\t%3,%z4,2f\\n\\
6581 \\tsll\\t%M0,%M1,%2%)\\n\\
6582 \\n\\
6583 \\tsubu\\t%3,%z4,%2\\n\\
6584 \\tsrl\\t%3,%L1,%3\\n\\
6585 \\tor\\t%M0,%M0,%3\\n\\
6586 %~2:\\n\\
6587 \\tsll\\t%L0,%L1,%2\\n\\
6588 %~3:\";
6589 }"
6590   [(set_attr "type"     "darith")
6591    (set_attr "mode"     "SI")
6592    (set_attr "length"   "48")])
6593
6594
6595 (define_insn "ashldi3_internal2"
6596   [(set (match_operand:DI 0 "register_operand" "=d")
6597         (ashift:DI (match_operand:DI 1 "register_operand" "d")
6598                    (match_operand:SI 2 "small_int" "IJK")))
6599    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6600   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6601    && (INTVAL (operands[2]) & 32) != 0"
6602   "*
6603 {
6604   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6605   operands[4] = const0_rtx;
6606   return \"sll\\t%M0,%L1,%2\;move\\t%L0,%z4\";
6607 }"
6608   [(set_attr "type"     "darith")
6609    (set_attr "mode"     "DI")
6610    (set_attr "length"   "8")])
6611
6612
6613 (define_split
6614   [(set (match_operand:DI 0 "register_operand" "")
6615         (ashift:DI (match_operand:DI 1 "register_operand" "")
6616                    (match_operand:SI 2 "small_int" "")))
6617    (clobber (match_operand:SI 3 "register_operand" ""))]
6618   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6619    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6620    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6621    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6622    && (INTVAL (operands[2]) & 32) != 0"
6623
6624   [(set (subreg:SI (match_dup 0) 4) (ashift:SI (subreg:SI (match_dup 1) 0) (match_dup 2)))
6625    (set (subreg:SI (match_dup 0) 0) (const_int 0))]
6626
6627   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6628
6629
6630 (define_split
6631   [(set (match_operand:DI 0 "register_operand" "")
6632         (ashift:DI (match_operand:DI 1 "register_operand" "")
6633                    (match_operand:SI 2 "small_int" "")))
6634    (clobber (match_operand:SI 3 "register_operand" ""))]
6635   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6636    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6637    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6638    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6639    && (INTVAL (operands[2]) & 32) != 0"
6640
6641   [(set (subreg:SI (match_dup 0) 0) (ashift:SI (subreg:SI (match_dup 1) 4) (match_dup 2)))
6642    (set (subreg:SI (match_dup 0) 4) (const_int 0))]
6643
6644   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6645
6646
6647 (define_insn "ashldi3_internal3"
6648   [(set (match_operand:DI 0 "register_operand" "=d")
6649         (ashift:DI (match_operand:DI 1 "register_operand" "d")
6650                    (match_operand:SI 2 "small_int" "IJK")))
6651    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6652   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6653    && (INTVAL (operands[2]) & 63) < 32
6654    && (INTVAL (operands[2]) & 63) != 0"
6655   "*
6656 {
6657   int amount = INTVAL (operands[2]);
6658
6659   operands[2] = GEN_INT (amount & 31);
6660   operands[4] = const0_rtx;
6661   operands[5] = GEN_INT ((-amount) & 31);
6662
6663   return \"sll\\t%M0,%M1,%2\;srl\\t%3,%L1,%5\;or\\t%M0,%M0,%3\;sll\\t%L0,%L1,%2\";
6664 }"
6665   [(set_attr "type"     "darith")
6666    (set_attr "mode"     "DI")
6667    (set_attr "length"   "16")])
6668
6669
6670 (define_split
6671   [(set (match_operand:DI 0 "register_operand" "")
6672         (ashift:DI (match_operand:DI 1 "register_operand" "")
6673                    (match_operand:SI 2 "small_int" "")))
6674    (clobber (match_operand:SI 3 "register_operand" ""))]
6675   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6676    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6677    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6678    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6679    && (INTVAL (operands[2]) & 63) < 32
6680    && (INTVAL (operands[2]) & 63) != 0"
6681
6682   [(set (subreg:SI (match_dup 0) 4)
6683         (ashift:SI (subreg:SI (match_dup 1) 4)
6684                    (match_dup 2)))
6685
6686    (set (match_dup 3)
6687         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
6688                      (match_dup 4)))
6689
6690    (set (subreg:SI (match_dup 0) 4)
6691         (ior:SI (subreg:SI (match_dup 0) 4)
6692                 (match_dup 3)))
6693
6694    (set (subreg:SI (match_dup 0) 0)
6695         (ashift:SI (subreg:SI (match_dup 1) 0)
6696                    (match_dup 2)))]
6697   "
6698 {
6699   int amount = INTVAL (operands[2]);
6700   operands[2] = GEN_INT (amount & 31);
6701   operands[4] = GEN_INT ((-amount) & 31);
6702 }")
6703
6704
6705 (define_split
6706   [(set (match_operand:DI 0 "register_operand" "")
6707         (ashift:DI (match_operand:DI 1 "register_operand" "")
6708                    (match_operand:SI 2 "small_int" "")))
6709    (clobber (match_operand:SI 3 "register_operand" ""))]
6710   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6711    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
6712    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6713    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6714    && (INTVAL (operands[2]) & 63) < 32
6715    && (INTVAL (operands[2]) & 63) != 0"
6716
6717   [(set (subreg:SI (match_dup 0) 0)
6718         (ashift:SI (subreg:SI (match_dup 1) 0)
6719                    (match_dup 2)))
6720
6721    (set (match_dup 3)
6722         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
6723                      (match_dup 4)))
6724
6725    (set (subreg:SI (match_dup 0) 0)
6726         (ior:SI (subreg:SI (match_dup 0) 0)
6727                 (match_dup 3)))
6728
6729    (set (subreg:SI (match_dup 0) 4)
6730         (ashift:SI (subreg:SI (match_dup 1) 4)
6731                    (match_dup 2)))]
6732   "
6733 {
6734   int amount = INTVAL (operands[2]);
6735   operands[2] = GEN_INT (amount & 31);
6736   operands[4] = GEN_INT ((-amount) & 31);
6737 }")
6738
6739
6740 (define_insn "ashldi3_internal4"
6741   [(set (match_operand:DI 0 "register_operand" "=d")
6742         (ashift:DI (match_operand:DI 1 "register_operand" "d")
6743                    (match_operand:SI 2 "arith_operand" "dI")))]
6744   "TARGET_64BIT && !TARGET_MIPS16"
6745   "*
6746 {
6747   if (GET_CODE (operands[2]) == CONST_INT)
6748     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
6749
6750   return \"dsll\\t%0,%1,%2\";
6751 }"
6752   [(set_attr "type"     "arith")
6753    (set_attr "mode"     "DI")])
6754
6755 (define_insn ""
6756   [(set (match_operand:DI 0 "register_operand" "=d,d")
6757         (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
6758                    (match_operand:SI 2 "arith_operand" "d,I")))]
6759   "TARGET_64BIT && TARGET_MIPS16"
6760   "*
6761 {
6762   if (which_alternative == 0)
6763     return \"dsll\\t%0,%2\";
6764
6765   if (GET_CODE (operands[2]) == CONST_INT)
6766     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
6767
6768   return \"dsll\\t%0,%1,%2\";
6769 }"
6770   [(set_attr "type"     "arith")
6771    (set_attr "mode"     "DI")
6772    (set_attr_alternative "length"
6773                 [(const_int 4)
6774                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6775                                (const_int 4)
6776                                (const_int 8))])])
6777
6778
6779 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
6780
6781 (define_split
6782   [(set (match_operand:DI 0 "register_operand" "")
6783         (ashift:DI (match_operand:DI 1 "register_operand" "")
6784                    (match_operand:SI 2 "const_int_operand" "")))]
6785   "TARGET_MIPS16 && TARGET_64BIT && !TARGET_DEBUG_D_MODE
6786    && reload_completed
6787    && GET_CODE (operands[2]) == CONST_INT
6788    && INTVAL (operands[2]) > 8
6789    && INTVAL (operands[2]) <= 16"
6790   [(set (match_dup 0) (ashift:DI (match_dup 1) (const_int 8)))
6791    (set (match_dup 0) (ashift:DI (match_dup 0) (match_dup 2)))]
6792 "
6793 {
6794   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
6795 }")
6796
6797 (define_expand "ashrsi3"
6798   [(set (match_operand:SI 0 "register_operand" "=d")
6799         (ashiftrt:SI (match_operand:SI 1 "register_operand" "d")
6800                      (match_operand:SI 2 "arith_operand" "dI")))]
6801   ""
6802   "
6803 {
6804   /* On the mips16, a shift of more than 8 is a four byte instruction,
6805      so, for a shift between 8 and 16, it is just as fast to do two
6806      shifts of 8 or less.  If there is a lot of shifting going on, we
6807      may win in CSE.  Otherwise combine will put the shifts back
6808      together again.  */
6809   if (TARGET_MIPS16
6810       && optimize
6811       && GET_CODE (operands[2]) == CONST_INT
6812       && INTVAL (operands[2]) > 8
6813       && INTVAL (operands[2]) <= 16)
6814     {
6815       rtx temp = gen_reg_rtx (SImode);
6816
6817       emit_insn (gen_ashrsi3_internal2 (temp, operands[1], GEN_INT (8)));
6818       emit_insn (gen_ashrsi3_internal2 (operands[0], temp,
6819                                         GEN_INT (INTVAL (operands[2]) - 8)));
6820       DONE;
6821     }
6822 }")
6823
6824 (define_insn "ashrsi3_internal1"
6825   [(set (match_operand:SI 0 "register_operand" "=d")
6826         (ashiftrt:SI (match_operand:SI 1 "register_operand" "d")
6827                      (match_operand:SI 2 "arith_operand" "dI")))]
6828   "!TARGET_MIPS16"
6829   "*
6830 {
6831   if (GET_CODE (operands[2]) == CONST_INT)
6832     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6833
6834   return \"sra\\t%0,%1,%2\";
6835 }"
6836   [(set_attr "type"     "arith")
6837    (set_attr "mode"     "SI")])
6838
6839 (define_insn "ashrsi3_internal2"
6840   [(set (match_operand:SI 0 "register_operand" "=d,d")
6841         (ashiftrt:SI (match_operand:SI 1 "register_operand" "0,d")
6842                      (match_operand:SI 2 "arith_operand" "d,I")))]
6843   "TARGET_MIPS16"
6844   "*
6845 {
6846   if (which_alternative == 0)
6847     return \"sra\\t%0,%2\";
6848
6849   if (GET_CODE (operands[2]) == CONST_INT)
6850     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6851
6852   return \"sra\\t%0,%1,%2\";
6853 }"
6854   [(set_attr "type"     "arith")
6855    (set_attr "mode"     "SI")
6856    (set_attr_alternative "length"
6857                 [(const_int 4)
6858                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
6859                                (const_int 4)
6860                                (const_int 8))])])
6861
6862
6863 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
6864
6865 (define_split
6866   [(set (match_operand:SI 0 "register_operand" "")
6867         (ashiftrt:SI (match_operand:SI 1 "register_operand" "")
6868                      (match_operand:SI 2 "const_int_operand" "")))]
6869   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
6870    && GET_CODE (operands[2]) == CONST_INT
6871    && INTVAL (operands[2]) > 8
6872    && INTVAL (operands[2]) <= 16"
6873   [(set (match_dup 0) (ashiftrt:SI (match_dup 1) (const_int 8)))
6874    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
6875 "
6876 {
6877   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
6878 }")
6879
6880 (define_expand "ashrdi3"
6881   [(parallel [(set (match_operand:DI 0 "register_operand" "")
6882                    (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6883                                 (match_operand:SI 2 "arith_operand" "")))
6884               (clobber (match_dup  3))])]
6885   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
6886   "
6887 {
6888   if (TARGET_64BIT)
6889     {
6890       /* On the mips16, a shift of more than 8 is a four byte
6891          instruction, so, for a shift between 8 and 16, it is just as
6892          fast to do two shifts of 8 or less.  If there is a lot of
6893          shifting going on, we may win in CSE.  Otherwise combine will
6894          put the shifts back together again.  */
6895       if (TARGET_MIPS16
6896           && optimize
6897           && GET_CODE (operands[2]) == CONST_INT
6898           && INTVAL (operands[2]) > 8
6899           && INTVAL (operands[2]) <= 16)
6900         {
6901           rtx temp = gen_reg_rtx (DImode);
6902
6903           emit_insn (gen_ashrdi3_internal4 (temp, operands[1], GEN_INT (8)));
6904           emit_insn (gen_ashrdi3_internal4 (operands[0], temp,
6905                                             GEN_INT (INTVAL (operands[2]) - 8)));
6906           DONE;
6907         }
6908
6909       emit_insn (gen_ashrdi3_internal4 (operands[0], operands[1],
6910                                         operands[2]));
6911       DONE;
6912     }
6913
6914   operands[3] = gen_reg_rtx (SImode);
6915 }")
6916
6917
6918 (define_insn "ashrdi3_internal"
6919   [(set (match_operand:DI 0 "register_operand" "=&d")
6920         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
6921                      (match_operand:SI 2 "register_operand" "d")))
6922    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6923   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
6924   "*
6925 {
6926   operands[4] = const0_rtx;
6927
6928   return \"sll\\t%3,%2,26\\n\\
6929 \\tbgez\\t%3,1f\\n\\
6930 \\tsra\\t%L0,%M1,%2\\n\\
6931 \\t%(b\\t3f\\n\\
6932 \\tsra\\t%M0,%M1,31%)\\n\\
6933 \\n\\
6934 %~1:\\n\\
6935 \\t%(beq\\t%3,%z4,2f\\n\\
6936 \\tsrl\\t%L0,%L1,%2%)\\n\\
6937 \\n\\
6938 \\tsubu\\t%3,%z4,%2\\n\\
6939 \\tsll\\t%3,%M1,%3\\n\\
6940 \\tor\\t%L0,%L0,%3\\n\\
6941 %~2:\\n\\
6942 \\tsra\\t%M0,%M1,%2\\n\\
6943 %~3:\";
6944 }"
6945   [(set_attr "type"     "darith")
6946    (set_attr "mode"     "DI")
6947    (set_attr "length"   "48")])
6948
6949
6950 (define_insn "ashrdi3_internal2"
6951   [(set (match_operand:DI 0 "register_operand" "=d")
6952         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
6953                      (match_operand:SI 2 "small_int" "IJK")))
6954    (clobber (match_operand:SI 3 "register_operand" "=d"))]
6955   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && (INTVAL (operands[2]) & 32) != 0"
6956   "*
6957 {
6958   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
6959   return \"sra\\t%L0,%M1,%2\;sra\\t%M0,%M1,31\";
6960 }"
6961   [(set_attr "type"     "darith")
6962    (set_attr "mode"     "DI")
6963    (set_attr "length"   "8")])
6964
6965
6966 (define_split
6967   [(set (match_operand:DI 0 "register_operand" "")
6968         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6969                      (match_operand:SI 2 "small_int" "")))
6970    (clobber (match_operand:SI 3 "register_operand" ""))]
6971   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
6972    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE
6973    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6974    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6975    && (INTVAL (operands[2]) & 32) != 0"
6976
6977   [(set (subreg:SI (match_dup 0) 0) (ashiftrt:SI (subreg:SI (match_dup 1) 4) (match_dup 2)))
6978    (set (subreg:SI (match_dup 0) 4) (ashiftrt:SI (subreg:SI (match_dup 1) 4) (const_int 31)))]
6979
6980   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6981
6982
6983 (define_split
6984   [(set (match_operand:DI 0 "register_operand" "")
6985         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
6986                      (match_operand:SI 2 "small_int" "")))
6987    (clobber (match_operand:SI 3 "register_operand" ""))]
6988   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
6989    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE
6990    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
6991    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
6992    && (INTVAL (operands[2]) & 32) != 0"
6993
6994   [(set (subreg:SI (match_dup 0) 4) (ashiftrt:SI (subreg:SI (match_dup 1) 0) (match_dup 2)))
6995    (set (subreg:SI (match_dup 0) 0) (ashiftrt:SI (subreg:SI (match_dup 1) 0) (const_int 31)))]
6996
6997   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
6998
6999
7000 (define_insn "ashrdi3_internal3"
7001   [(set (match_operand:DI 0 "register_operand" "=d")
7002         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
7003                      (match_operand:SI 2 "small_int" "IJK")))
7004    (clobber (match_operand:SI 3 "register_operand" "=d"))]
7005   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7006    && (INTVAL (operands[2]) & 63) < 32
7007    && (INTVAL (operands[2]) & 63) != 0"
7008   "*
7009 {
7010   int amount = INTVAL (operands[2]);
7011
7012   operands[2] = GEN_INT (amount & 31);
7013   operands[4] = GEN_INT ((-amount) & 31);
7014
7015   return \"srl\\t%L0,%L1,%2\;sll\\t%3,%M1,%4\;or\\t%L0,%L0,%3\;sra\\t%M0,%M1,%2\";
7016 }"
7017   [(set_attr "type"     "darith")
7018    (set_attr "mode"     "DI")
7019    (set_attr "length"   "16")])
7020
7021
7022 (define_split
7023   [(set (match_operand:DI 0 "register_operand" "")
7024         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
7025                      (match_operand:SI 2 "small_int" "")))
7026    (clobber (match_operand:SI 3 "register_operand" ""))]
7027   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
7028    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7029    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
7030    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
7031    && (INTVAL (operands[2]) & 63) < 32
7032    && (INTVAL (operands[2]) & 63) != 0"
7033
7034   [(set (subreg:SI (match_dup 0) 0)
7035         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
7036                      (match_dup 2)))
7037
7038    (set (match_dup 3)
7039         (ashift:SI (subreg:SI (match_dup 1) 4)
7040                    (match_dup 4)))
7041
7042    (set (subreg:SI (match_dup 0) 0)
7043         (ior:SI (subreg:SI (match_dup 0) 0)
7044                 (match_dup 3)))
7045
7046    (set (subreg:SI (match_dup 0) 4)
7047         (ashiftrt:SI (subreg:SI (match_dup 1) 4)
7048                      (match_dup 2)))]
7049   "
7050 {
7051   int amount = INTVAL (operands[2]);
7052   operands[2] = GEN_INT (amount & 31);
7053   operands[4] = GEN_INT ((-amount) & 31);
7054 }")
7055
7056
7057 (define_split
7058   [(set (match_operand:DI 0 "register_operand" "")
7059         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
7060                      (match_operand:SI 2 "small_int" "")))
7061    (clobber (match_operand:SI 3 "register_operand" ""))]
7062   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
7063    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7064    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
7065    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
7066    && (INTVAL (operands[2]) & 63) < 32
7067    && (INTVAL (operands[2]) & 63) != 0"
7068
7069   [(set (subreg:SI (match_dup 0) 4)
7070         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
7071                      (match_dup 2)))
7072
7073    (set (match_dup 3)
7074         (ashift:SI (subreg:SI (match_dup 1) 0)
7075                    (match_dup 4)))
7076
7077    (set (subreg:SI (match_dup 0) 4)
7078         (ior:SI (subreg:SI (match_dup 0) 4)
7079                 (match_dup 3)))
7080
7081    (set (subreg:SI (match_dup 0) 0)
7082         (ashiftrt:SI (subreg:SI (match_dup 1) 0)
7083                      (match_dup 2)))]
7084   "
7085 {
7086   int amount = INTVAL (operands[2]);
7087   operands[2] = GEN_INT (amount & 31);
7088   operands[4] = GEN_INT ((-amount) & 31);
7089 }")
7090
7091
7092 (define_insn "ashrdi3_internal4"
7093   [(set (match_operand:DI 0 "register_operand" "=d")
7094         (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
7095                      (match_operand:SI 2 "arith_operand" "dI")))]
7096   "TARGET_64BIT && !TARGET_MIPS16"
7097   "*
7098 {
7099   if (GET_CODE (operands[2]) == CONST_INT)
7100     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
7101
7102   return \"dsra\\t%0,%1,%2\";
7103 }"
7104   [(set_attr "type"     "arith")
7105    (set_attr "mode"     "DI")])
7106
7107 (define_insn ""
7108   [(set (match_operand:DI 0 "register_operand" "=d,d")
7109         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
7110                      (match_operand:SI 2 "arith_operand" "d,I")))]
7111   "TARGET_64BIT && TARGET_MIPS16"
7112   "*
7113 {
7114   if (GET_CODE (operands[2]) == CONST_INT)
7115     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
7116
7117   return \"dsra\\t%0,%2\";
7118 }"
7119   [(set_attr "type"     "arith")
7120    (set_attr "mode"     "DI")
7121    (set_attr_alternative "length"
7122                 [(const_int 4)
7123                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
7124                                (const_int 4)
7125                                (const_int 8))])])
7126
7127 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
7128
7129 (define_split
7130   [(set (match_operand:DI 0 "register_operand" "")
7131         (ashiftrt:DI (match_operand:DI 1 "register_operand" "")
7132                      (match_operand:SI 2 "const_int_operand" "")))]
7133   "TARGET_MIPS16 && TARGET_64BIT && !TARGET_DEBUG_D_MODE
7134    && reload_completed
7135    && GET_CODE (operands[2]) == CONST_INT
7136    && INTVAL (operands[2]) > 8
7137    && INTVAL (operands[2]) <= 16"
7138   [(set (match_dup 0) (ashiftrt:DI (match_dup 1) (const_int 8)))
7139    (set (match_dup 0) (ashiftrt:DI (match_dup 0) (match_dup 2)))]
7140 "
7141 {
7142   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
7143 }")
7144
7145 (define_expand "lshrsi3"
7146   [(set (match_operand:SI 0 "register_operand" "=d")
7147         (lshiftrt:SI (match_operand:SI 1 "register_operand" "d")
7148                      (match_operand:SI 2 "arith_operand" "dI")))]
7149   ""
7150   "
7151 {
7152   /* On the mips16, a shift of more than 8 is a four byte instruction,
7153      so, for a shift between 8 and 16, it is just as fast to do two
7154      shifts of 8 or less.  If there is a lot of shifting going on, we
7155      may win in CSE.  Otherwise combine will put the shifts back
7156      together again.  */
7157   if (TARGET_MIPS16
7158       && optimize
7159       && GET_CODE (operands[2]) == CONST_INT
7160       && INTVAL (operands[2]) > 8
7161       && INTVAL (operands[2]) <= 16)
7162     {
7163       rtx temp = gen_reg_rtx (SImode);
7164
7165       emit_insn (gen_lshrsi3_internal2 (temp, operands[1], GEN_INT (8)));
7166       emit_insn (gen_lshrsi3_internal2 (operands[0], temp,
7167                                         GEN_INT (INTVAL (operands[2]) - 8)));
7168       DONE;
7169     }
7170 }")
7171
7172 (define_insn "lshrsi3_internal1"
7173   [(set (match_operand:SI 0 "register_operand" "=d")
7174         (lshiftrt:SI (match_operand:SI 1 "register_operand" "d")
7175                      (match_operand:SI 2 "arith_operand" "dI")))]
7176   "!TARGET_MIPS16"
7177   "*
7178 {
7179   if (GET_CODE (operands[2]) == CONST_INT)
7180     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
7181
7182   return \"srl\\t%0,%1,%2\";
7183 }"
7184   [(set_attr "type"     "arith")
7185    (set_attr "mode"     "SI")])
7186
7187 (define_insn "lshrsi3_internal2"
7188   [(set (match_operand:SI 0 "register_operand" "=d,d")
7189         (lshiftrt:SI (match_operand:SI 1 "register_operand" "0,d")
7190                      (match_operand:SI 2 "arith_operand" "d,I")))]
7191   "TARGET_MIPS16"
7192   "*
7193 {
7194   if (which_alternative == 0)
7195     return \"srl\\t%0,%2\";
7196
7197   if (GET_CODE (operands[2]) == CONST_INT)
7198     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
7199
7200   return \"srl\\t%0,%1,%2\";
7201 }"
7202   [(set_attr "type"     "arith")
7203    (set_attr "mode"     "SI")
7204    (set_attr_alternative "length"
7205                 [(const_int 4)
7206                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
7207                                (const_int 4)
7208                                (const_int 8))])])
7209
7210
7211 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
7212
7213 (define_split
7214   [(set (match_operand:SI 0 "register_operand" "")
7215         (lshiftrt:SI (match_operand:SI 1 "register_operand" "")
7216                      (match_operand:SI 2 "const_int_operand" "")))]
7217   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
7218    && GET_CODE (operands[2]) == CONST_INT
7219    && INTVAL (operands[2]) > 8
7220    && INTVAL (operands[2]) <= 16"
7221   [(set (match_dup 0) (lshiftrt:SI (match_dup 1) (const_int 8)))
7222    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
7223 "
7224 {
7225   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
7226 }")
7227
7228 ;; If we load a byte on the mips16 as a bitfield, the resulting
7229 ;; sequence of instructions is too complicated for combine, because it
7230 ;; involves four instructions: a load, a shift, a constant load into a
7231 ;; register, and an and (the key problem here is that the mips16 does
7232 ;; not have and immediate).  We recognize a shift of a load in order
7233 ;; to make it simple enough for combine to understand.
7234
7235 ;; ??? FIXME: turn into a define_insn_and_split
7236 (define_insn ""
7237   [(set (match_operand:SI 0 "register_operand" "=d")
7238         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
7239                      (match_operand:SI 2 "immediate_operand" "I")))]
7240   "0 && TARGET_MIPS16"
7241   "lw\\t%0,%1\;srl\\t%0,%2"
7242   [(set_attr "type"     "load")
7243    (set_attr "mode"     "SI")
7244    (set_attr_alternative "length"
7245                 [(if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
7246                                (const_int 12)
7247                                (const_int 16))])])
7248
7249 (define_split
7250   [(set (match_operand:SI 0 "register_operand" "")
7251         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "")
7252                      (match_operand:SI 2 "immediate_operand" "")))]
7253   "TARGET_MIPS16 && !TARGET_DEBUG_D_MODE"
7254   [(set (match_dup 0) (match_dup 1))
7255    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
7256   "")
7257
7258 (define_expand "lshrdi3"
7259   [(parallel [(set (match_operand:DI 0 "register_operand" "")
7260                    (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
7261                                 (match_operand:SI 2 "arith_operand" "")))
7262               (clobber (match_dup  3))])]
7263   "TARGET_64BIT || (!TARGET_DEBUG_G_MODE && !TARGET_MIPS16)"
7264   "
7265 {
7266   if (TARGET_64BIT)
7267     {
7268       /* On the mips16, a shift of more than 8 is a four byte
7269          instruction, so, for a shift between 8 and 16, it is just as
7270          fast to do two shifts of 8 or less.  If there is a lot of
7271          shifting going on, we may win in CSE.  Otherwise combine will
7272          put the shifts back together again.  */
7273       if (TARGET_MIPS16
7274           && optimize
7275           && GET_CODE (operands[2]) == CONST_INT
7276           && INTVAL (operands[2]) > 8
7277           && INTVAL (operands[2]) <= 16)
7278         {
7279           rtx temp = gen_reg_rtx (DImode);
7280
7281           emit_insn (gen_lshrdi3_internal4 (temp, operands[1], GEN_INT (8)));
7282           emit_insn (gen_lshrdi3_internal4 (operands[0], temp,
7283                                             GEN_INT (INTVAL (operands[2]) - 8)));
7284           DONE;
7285         }
7286
7287       emit_insn (gen_lshrdi3_internal4 (operands[0], operands[1],
7288                                         operands[2]));
7289       DONE;
7290     }
7291
7292   operands[3] = gen_reg_rtx (SImode);
7293 }")
7294
7295
7296 (define_insn "lshrdi3_internal"
7297   [(set (match_operand:DI 0 "register_operand" "=&d")
7298         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
7299                      (match_operand:SI 2 "register_operand" "d")))
7300    (clobber (match_operand:SI 3 "register_operand" "=d"))]
7301   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16"
7302   "*
7303 {
7304   operands[4] = const0_rtx;
7305
7306   return \"sll\\t%3,%2,26\\n\\
7307 \\tbgez\\t%3,1f\\n\\
7308 \\tsrl\\t%L0,%M1,%2\\n\\
7309 \\t%(b\\t3f\\n\\
7310 \\tmove\\t%M0,%z4%)\\n\\
7311 \\n\\
7312 %~1:\\n\\
7313 \\t%(beq\\t%3,%z4,2f\\n\\
7314 \\tsrl\\t%L0,%L1,%2%)\\n\\
7315 \\n\\
7316 \\tsubu\\t%3,%z4,%2\\n\\
7317 \\tsll\\t%3,%M1,%3\\n\\
7318 \\tor\\t%L0,%L0,%3\\n\\
7319 %~2:\\n\\
7320 \\tsrl\\t%M0,%M1,%2\\n\\
7321 %~3:\";
7322 }"
7323   [(set_attr "type"     "darith")
7324    (set_attr "mode"     "DI")
7325    (set_attr "length"   "48")])
7326
7327
7328 (define_insn "lshrdi3_internal2"
7329   [(set (match_operand:DI 0 "register_operand" "=d")
7330         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
7331                      (match_operand:SI 2 "small_int" "IJK")))
7332    (clobber (match_operand:SI 3 "register_operand" "=d"))]
7333   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7334    && (INTVAL (operands[2]) & 32) != 0"
7335   "*
7336 {
7337   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
7338   operands[4] = const0_rtx;
7339   return \"srl\\t%L0,%M1,%2\;move\\t%M0,%z4\";
7340 }"
7341   [(set_attr "type"     "darith")
7342    (set_attr "mode"     "DI")
7343    (set_attr "length"   "8")])
7344
7345
7346 (define_split
7347   [(set (match_operand:DI 0 "register_operand" "")
7348         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
7349                      (match_operand:SI 2 "small_int" "")))
7350    (clobber (match_operand:SI 3 "register_operand" ""))]
7351   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
7352    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7353    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
7354    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
7355    && (INTVAL (operands[2]) & 32) != 0"
7356
7357   [(set (subreg:SI (match_dup 0) 0) (lshiftrt:SI (subreg:SI (match_dup 1) 4) (match_dup 2)))
7358    (set (subreg:SI (match_dup 0) 4) (const_int 0))]
7359
7360   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
7361
7362
7363 (define_split
7364   [(set (match_operand:DI 0 "register_operand" "")
7365         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
7366                      (match_operand:SI 2 "small_int" "")))
7367    (clobber (match_operand:SI 3 "register_operand" ""))]
7368   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
7369    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7370    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
7371    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
7372    && (INTVAL (operands[2]) & 32) != 0"
7373
7374   [(set (subreg:SI (match_dup 0) 4) (lshiftrt:SI (subreg:SI (match_dup 1) 0) (match_dup 2)))
7375    (set (subreg:SI (match_dup 0) 0) (const_int 0))]
7376
7377   "operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);")
7378
7379
7380 (define_insn "lshrdi3_internal3"
7381   [(set (match_operand:DI 0 "register_operand" "=d")
7382         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
7383                    (match_operand:SI 2 "small_int" "IJK")))
7384    (clobber (match_operand:SI 3 "register_operand" "=d"))]
7385   "!TARGET_64BIT && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7386    && (INTVAL (operands[2]) & 63) < 32
7387    && (INTVAL (operands[2]) & 63) != 0"
7388   "*
7389 {
7390   int amount = INTVAL (operands[2]);
7391
7392   operands[2] = GEN_INT (amount & 31);
7393   operands[4] = GEN_INT ((-amount) & 31);
7394
7395   return \"srl\\t%L0,%L1,%2\;sll\\t%3,%M1,%4\;or\\t%L0,%L0,%3\;srl\\t%M0,%M1,%2\";
7396 }"
7397   [(set_attr "type"     "darith")
7398    (set_attr "mode"     "DI")
7399    (set_attr "length"   "16")])
7400
7401
7402 (define_split
7403   [(set (match_operand:DI 0 "register_operand" "")
7404         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
7405                      (match_operand:SI 2 "small_int" "")))
7406    (clobber (match_operand:SI 3 "register_operand" ""))]
7407   "reload_completed && !WORDS_BIG_ENDIAN && !TARGET_64BIT
7408    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7409    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
7410    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
7411    && (INTVAL (operands[2]) & 63) < 32
7412    && (INTVAL (operands[2]) & 63) != 0"
7413
7414   [(set (subreg:SI (match_dup 0) 0)
7415         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
7416                      (match_dup 2)))
7417
7418    (set (match_dup 3)
7419         (ashift:SI (subreg:SI (match_dup 1) 4)
7420                    (match_dup 4)))
7421
7422    (set (subreg:SI (match_dup 0) 0)
7423         (ior:SI (subreg:SI (match_dup 0) 0)
7424                 (match_dup 3)))
7425
7426    (set (subreg:SI (match_dup 0) 4)
7427         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
7428                      (match_dup 2)))]
7429   "
7430 {
7431   int amount = INTVAL (operands[2]);
7432   operands[2] = GEN_INT (amount & 31);
7433   operands[4] = GEN_INT ((-amount) & 31);
7434 }")
7435
7436
7437 (define_split
7438   [(set (match_operand:DI 0 "register_operand" "")
7439         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
7440                      (match_operand:SI 2 "small_int" "")))
7441    (clobber (match_operand:SI 3 "register_operand" ""))]
7442   "reload_completed && WORDS_BIG_ENDIAN && !TARGET_64BIT
7443    && !TARGET_DEBUG_D_MODE && !TARGET_DEBUG_G_MODE && !TARGET_MIPS16
7444    && GET_CODE (operands[0]) == REG && REGNO (operands[0]) < FIRST_PSEUDO_REGISTER
7445    && GET_CODE (operands[1]) == REG && REGNO (operands[1]) < FIRST_PSEUDO_REGISTER
7446    && (INTVAL (operands[2]) & 63) < 32
7447    && (INTVAL (operands[2]) & 63) != 0"
7448
7449   [(set (subreg:SI (match_dup 0) 4)
7450         (lshiftrt:SI (subreg:SI (match_dup 1) 4)
7451                      (match_dup 2)))
7452
7453    (set (match_dup 3)
7454         (ashift:SI (subreg:SI (match_dup 1) 0)
7455                    (match_dup 4)))
7456
7457    (set (subreg:SI (match_dup 0) 4)
7458         (ior:SI (subreg:SI (match_dup 0) 4)
7459                 (match_dup 3)))
7460
7461    (set (subreg:SI (match_dup 0) 0)
7462         (lshiftrt:SI (subreg:SI (match_dup 1) 0)
7463                      (match_dup 2)))]
7464   "
7465 {
7466   int amount = INTVAL (operands[2]);
7467   operands[2] = GEN_INT (amount & 31);
7468   operands[4] = GEN_INT ((-amount) & 31);
7469 }")
7470
7471
7472 (define_insn "lshrdi3_internal4"
7473   [(set (match_operand:DI 0 "register_operand" "=d")
7474         (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
7475                      (match_operand:SI 2 "arith_operand" "dI")))]
7476   "TARGET_64BIT && !TARGET_MIPS16"
7477   "*
7478 {
7479   if (GET_CODE (operands[2]) == CONST_INT)
7480     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
7481
7482   return \"dsrl\\t%0,%1,%2\";
7483 }"
7484   [(set_attr "type"     "arith")
7485    (set_attr "mode"     "DI")])
7486
7487 (define_insn ""
7488   [(set (match_operand:DI 0 "register_operand" "=d,d")
7489         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
7490                      (match_operand:SI 2 "arith_operand" "d,I")))]
7491   "TARGET_64BIT && TARGET_MIPS16"
7492   "*
7493 {
7494   if (GET_CODE (operands[2]) == CONST_INT)
7495     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
7496
7497   return \"dsrl\\t%0,%2\";
7498 }"
7499   [(set_attr "type"     "arith")
7500    (set_attr "mode"     "DI")
7501    (set_attr_alternative "length"
7502                 [(const_int 4)
7503                  (if_then_else (match_operand:VOID 2 "m16_uimm3_b" "")
7504                                (const_int 4)
7505                                (const_int 8))])])
7506
7507 (define_insn "rotrsi3"
7508   [(set (match_operand:SI              0 "register_operand" "=d")
7509         (rotatert:SI (match_operand:SI 1 "register_operand" "d")
7510                      (match_operand:SI 2 "arith_operand"    "dn")))]
7511   "ISA_HAS_ROTR_SI"
7512   "*
7513 {
7514   if (TARGET_SR71K && GET_CODE (operands[2]) != CONST_INT)
7515     return \"rorv\\t%0,%1,%2\";
7516
7517   if ((GET_CODE (operands[2]) == CONST_INT)
7518       && (INTVAL (operands[2]) < 0 || INTVAL (operands[2]) >= 32))
7519     abort ();
7520
7521   return \"ror\\t%0,%1,%2\";
7522 }"
7523   [(set_attr "type"     "arith")
7524    (set_attr "mode"     "SI")])
7525
7526 (define_insn "rotrdi3"
7527   [(set (match_operand:DI              0 "register_operand" "=d")
7528         (rotatert:DI (match_operand:DI 1 "register_operand" "d")
7529                      (match_operand:DI 2 "arith_operand"    "dn")))]
7530   "ISA_HAS_ROTR_DI"
7531   "*
7532 {
7533    if (TARGET_SR71K)
7534     {
7535       if (GET_CODE (operands[2]) != CONST_INT)
7536         return \"drorv\\t%0,%1,%2\";
7537
7538       if (INTVAL (operands[2]) >= 32 && INTVAL (operands[2]) <= 63)
7539         return \"dror32\\t%0,%1,%2\";
7540     }
7541
7542   if ((GET_CODE (operands[2]) == CONST_INT)
7543       && (INTVAL (operands[2]) < 0 || INTVAL (operands[2]) >= 64))
7544     abort ();
7545
7546   return \"dror\\t%0,%1,%2\";
7547 }"
7548   [(set_attr "type"     "arith")
7549    (set_attr "mode"     "DI")])
7550
7551
7552 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
7553
7554 (define_split
7555   [(set (match_operand:DI 0 "register_operand" "")
7556         (lshiftrt:DI (match_operand:DI 1 "register_operand" "")
7557                      (match_operand:SI 2 "const_int_operand" "")))]
7558   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
7559    && GET_CODE (operands[2]) == CONST_INT
7560    && INTVAL (operands[2]) > 8
7561    && INTVAL (operands[2]) <= 16"
7562   [(set (match_dup 0) (lshiftrt:DI (match_dup 1) (const_int 8)))
7563    (set (match_dup 0) (lshiftrt:DI (match_dup 0) (match_dup 2)))]
7564 "
7565 {
7566   operands[2] = GEN_INT (INTVAL (operands[2]) - 8);
7567 }")
7568
7569 \f
7570 ;;
7571 ;;  ....................
7572 ;;
7573 ;;      COMPARISONS
7574 ;;
7575 ;;  ....................
7576
7577 ;; Flow here is rather complex:
7578 ;;
7579 ;;  1)  The cmp{si,di,sf,df} routine is called.  It deposits the
7580 ;;      arguments into the branch_cmp array, and the type into
7581 ;;      branch_type.  No RTL is generated.
7582 ;;
7583 ;;  2)  The appropriate branch define_expand is called, which then
7584 ;;      creates the appropriate RTL for the comparison and branch.
7585 ;;      Different CC modes are used, based on what type of branch is
7586 ;;      done, so that we can constrain things appropriately.  There
7587 ;;      are assumptions in the rest of GCC that break if we fold the
7588 ;;      operands into the branchs for integer operations, and use cc0
7589 ;;      for floating point, so we use the fp status register instead.
7590 ;;      If needed, an appropriate temporary is created to hold the
7591 ;;      of the integer compare.
7592
7593 (define_expand "cmpsi"
7594   [(set (cc0)
7595         (compare:CC (match_operand:SI 0 "register_operand" "")
7596                     (match_operand:SI 1 "arith_operand" "")))]
7597   ""
7598   "
7599 {
7600   if (operands[0])              /* avoid unused code message */
7601     {
7602       branch_cmp[0] = operands[0];
7603       branch_cmp[1] = operands[1];
7604       branch_type = CMP_SI;
7605       DONE;
7606     }
7607 }")
7608
7609 (define_expand "tstsi"
7610   [(set (cc0)
7611         (match_operand:SI 0 "register_operand" ""))]
7612   ""
7613   "
7614 {
7615   if (operands[0])              /* avoid unused code message */
7616     {
7617       branch_cmp[0] = operands[0];
7618       branch_cmp[1] = const0_rtx;
7619       branch_type = CMP_SI;
7620       DONE;
7621     }
7622 }")
7623
7624 (define_expand "cmpdi"
7625   [(set (cc0)
7626         (compare:CC (match_operand:DI 0 "register_operand" "")
7627                     (match_operand:DI 1 "arith_operand" "")))]
7628   "TARGET_64BIT"
7629   "
7630 {
7631   if (operands[0])              /* avoid unused code message */
7632     {
7633       branch_cmp[0] = operands[0];
7634       branch_cmp[1] = operands[1];
7635       branch_type = CMP_DI;
7636       DONE;
7637     }
7638 }")
7639
7640 (define_expand "tstdi"
7641   [(set (cc0)
7642         (match_operand:DI 0 "register_operand" ""))]
7643   "TARGET_64BIT"
7644   "
7645 {
7646   if (operands[0])              /* avoid unused code message */
7647     {
7648       branch_cmp[0] = operands[0];
7649       branch_cmp[1] = const0_rtx;
7650       branch_type = CMP_DI;
7651       DONE;
7652     }
7653 }")
7654
7655 (define_expand "cmpdf"
7656   [(set (cc0)
7657         (compare:CC (match_operand:DF 0 "register_operand" "")
7658                     (match_operand:DF 1 "register_operand" "")))]
7659   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7660   "
7661 {
7662   if (operands[0])              /* avoid unused code message */
7663     {
7664       branch_cmp[0] = operands[0];
7665       branch_cmp[1] = operands[1];
7666       branch_type = CMP_DF;
7667       DONE;
7668     }
7669 }")
7670
7671 (define_expand "cmpsf"
7672   [(set (cc0)
7673         (compare:CC (match_operand:SF 0 "register_operand" "")
7674                     (match_operand:SF 1 "register_operand" "")))]
7675   "TARGET_HARD_FLOAT"
7676   "
7677 {
7678   if (operands[0])              /* avoid unused code message */
7679     {
7680       branch_cmp[0] = operands[0];
7681       branch_cmp[1] = operands[1];
7682       branch_type = CMP_SF;
7683       DONE;
7684     }
7685 }")
7686
7687 \f
7688 ;;
7689 ;;  ....................
7690 ;;
7691 ;;      CONDITIONAL BRANCHES
7692 ;;
7693 ;;  ....................
7694
7695 ;; Conditional branches on floating-point equality tests.
7696
7697 (define_insn "branch_fp"
7698   [(set (pc)
7699         (if_then_else
7700          (match_operator:CC 0 "cmp_op"
7701                             [(match_operand:CC 2 "register_operand" "z")
7702                              (const_int 0)])
7703          (label_ref (match_operand 1 "" ""))
7704          (pc)))]
7705   "TARGET_HARD_FLOAT"
7706   "*
7707 {
7708   return mips_output_conditional_branch (insn,
7709                                          operands,
7710                                          /*two_operands_p=*/0,
7711                                          /*float_p=*/1,
7712                                          /*inverted_p=*/0,
7713                                          get_attr_length (insn));
7714 }"
7715   [(set_attr "type"     "branch")
7716    (set_attr "mode"     "none")])
7717
7718 (define_insn "branch_fp_inverted"
7719   [(set (pc)
7720         (if_then_else
7721          (match_operator:CC 0 "cmp_op"
7722                             [(match_operand:CC 2 "register_operand" "z")
7723                              (const_int 0)])
7724          (pc)
7725          (label_ref (match_operand 1 "" ""))))]
7726   "TARGET_HARD_FLOAT"
7727   "*
7728 {
7729   return mips_output_conditional_branch (insn,
7730                                          operands,
7731                                          /*two_operands_p=*/0,
7732                                          /*float_p=*/1,
7733                                          /*inverted_p=*/1,
7734                                          get_attr_length (insn));
7735 }"
7736   [(set_attr "type"     "branch")
7737    (set_attr "mode"     "none")])
7738
7739 ;; Conditional branches on comparisons with zero.
7740
7741 (define_insn "branch_zero"
7742   [(set (pc)
7743         (if_then_else
7744          (match_operator:SI 0 "cmp_op"
7745                             [(match_operand:SI 2 "register_operand" "d")
7746                              (const_int 0)])
7747         (label_ref (match_operand 1 "" ""))
7748         (pc)))]
7749   "!TARGET_MIPS16"
7750   "*
7751 {
7752   return mips_output_conditional_branch (insn,
7753                                          operands,
7754                                          /*two_operands_p=*/0,
7755                                          /*float_p=*/0,
7756                                          /*inverted_p=*/0,
7757                                          get_attr_length (insn));
7758 }"
7759   [(set_attr "type"     "branch")
7760    (set_attr "mode"     "none")])
7761
7762 (define_insn "branch_zero_inverted"
7763   [(set (pc)
7764         (if_then_else
7765          (match_operator:SI 0 "cmp_op"
7766                             [(match_operand:SI 2 "register_operand" "d")
7767                              (const_int 0)])
7768         (pc)
7769         (label_ref (match_operand 1 "" ""))))]
7770   "!TARGET_MIPS16"
7771   "*
7772 {
7773   return mips_output_conditional_branch (insn,
7774                                          operands,
7775                                          /*two_operands_p=*/0,
7776                                          /*float_p=*/0,
7777                                          /*inverted_p=*/1,
7778                                          get_attr_length (insn));
7779 }"
7780   [(set_attr "type"     "branch")
7781    (set_attr "mode"     "none")])
7782
7783 (define_insn "branch_zero_di"
7784   [(set (pc)
7785         (if_then_else
7786          (match_operator:DI 0 "cmp_op"
7787                             [(match_operand:DI 2 "register_operand" "d")
7788                              (const_int 0)])
7789         (label_ref (match_operand 1 "" ""))
7790         (pc)))]
7791   "!TARGET_MIPS16"
7792   "*
7793 {
7794   return mips_output_conditional_branch (insn,
7795                                          operands,
7796                                          /*two_operands_p=*/0,
7797                                          /*float_p=*/0,
7798                                          /*inverted_p=*/0,
7799                                          get_attr_length (insn));
7800 }"
7801   [(set_attr "type"     "branch")
7802    (set_attr "mode"     "none")])
7803
7804 (define_insn "branch_zero_di_inverted"
7805   [(set (pc)
7806         (if_then_else
7807          (match_operator:DI 0 "cmp_op"
7808                             [(match_operand:DI 2 "register_operand" "d")
7809                              (const_int 0)])
7810         (pc)
7811         (label_ref (match_operand 1 "" ""))))]
7812   "!TARGET_MIPS16"
7813   "*
7814 {
7815   return mips_output_conditional_branch (insn,
7816                                          operands,
7817                                          /*two_operands_p=*/0,
7818                                          /*float_p=*/0,
7819                                          /*inverted_p=*/1,
7820                                          get_attr_length (insn));
7821 }"
7822   [(set_attr "type"     "branch")
7823    (set_attr "mode"     "none")])
7824
7825 ;; Conditional branch on equality comparision.
7826
7827 (define_insn "branch_equality"
7828   [(set (pc)
7829         (if_then_else
7830          (match_operator:SI 0 "equality_op"
7831                             [(match_operand:SI 2 "register_operand" "d")
7832                              (match_operand:SI 3 "register_operand" "d")])
7833          (label_ref (match_operand 1 "" ""))
7834          (pc)))]
7835   "!TARGET_MIPS16"
7836   "*
7837 {
7838   return mips_output_conditional_branch (insn,
7839                                          operands,
7840                                          /*two_operands_p=*/1,
7841                                          /*float_p=*/0,
7842                                          /*inverted_p=*/0,
7843                                          get_attr_length (insn));
7844 }"
7845   [(set_attr "type"     "branch")
7846    (set_attr "mode"     "none")])
7847
7848 (define_insn "branch_equality_di"
7849   [(set (pc)
7850         (if_then_else
7851          (match_operator:DI 0 "equality_op"
7852                             [(match_operand:DI 2 "register_operand" "d")
7853                              (match_operand:DI 3 "register_operand" "d")])
7854         (label_ref (match_operand 1 "" ""))
7855         (pc)))]
7856   "!TARGET_MIPS16"
7857   "*
7858 {
7859   return mips_output_conditional_branch (insn,
7860                                          operands,
7861                                          /*two_operands_p=*/1,
7862                                          /*float_p=*/0,
7863                                          /*inverted_p=*/0,
7864                                          get_attr_length (insn));
7865 }"
7866   [(set_attr "type"     "branch")
7867    (set_attr "mode"     "none")])
7868
7869 (define_insn "branch_equality_inverted"
7870   [(set (pc)
7871         (if_then_else
7872          (match_operator:SI 0 "equality_op"
7873                             [(match_operand:SI 2 "register_operand" "d")
7874                              (match_operand:SI 3 "register_operand" "d")])
7875          (pc)
7876          (label_ref (match_operand 1 "" ""))))]
7877   "!TARGET_MIPS16"
7878   "*
7879 {
7880   return mips_output_conditional_branch (insn,
7881                                          operands,
7882                                          /*two_operands_p=*/1,
7883                                          /*float_p=*/0,
7884                                          /*inverted_p=*/1,
7885                                          get_attr_length (insn));
7886 }"
7887   [(set_attr "type"     "branch")
7888    (set_attr "mode"     "none")])
7889
7890 (define_insn "branch_equality_di_inverted"
7891   [(set (pc)
7892         (if_then_else
7893          (match_operator:DI 0 "equality_op"
7894                             [(match_operand:DI 2 "register_operand" "d")
7895                              (match_operand:DI 3 "register_operand" "d")])
7896         (pc)
7897         (label_ref (match_operand 1 "" ""))))]
7898   "!TARGET_MIPS16"
7899   "*
7900 {
7901   return mips_output_conditional_branch (insn,
7902                                          operands,
7903                                          /*two_operands_p=*/1,
7904                                          /*float_p=*/0,
7905                                          /*inverted_p=*/1,
7906                                          get_attr_length (insn));
7907 }"
7908   [(set_attr "type"     "branch")
7909    (set_attr "mode"     "none")])
7910
7911 ;; MIPS16 branches
7912
7913 (define_insn ""
7914   [(set (pc)
7915         (if_then_else (match_operator:SI 0 "equality_op"
7916                                          [(match_operand:SI 1 "register_operand" "d,t")
7917                                           (const_int 0)])
7918         (match_operand 2 "pc_or_label_operand" "")
7919         (match_operand 3 "pc_or_label_operand" "")))]
7920   "TARGET_MIPS16"
7921   "*
7922 {
7923   if (operands[2] != pc_rtx)
7924     {
7925       if (which_alternative == 0)
7926         return \"%*b%C0z\\t%1,%2\";
7927       else
7928         return \"%*bt%C0z\\t%2\";
7929     }
7930   else
7931     {
7932       if (which_alternative == 0)
7933         return \"%*b%N0z\\t%1,%3\";
7934       else
7935         return \"%*bt%N0z\\t%3\";
7936     }
7937 }"
7938   [(set_attr "type"     "branch")
7939    (set_attr "mode"     "none")
7940    (set_attr "length"   "8")])
7941
7942 (define_insn ""
7943   [(set (pc)
7944         (if_then_else (match_operator:DI 0 "equality_op"
7945                                          [(match_operand:DI 1 "register_operand" "d,t")
7946                                           (const_int 0)])
7947         (match_operand 2 "pc_or_label_operand" "")
7948         (match_operand 3 "pc_or_label_operand" "")))]
7949   "TARGET_MIPS16"
7950   "*
7951 {
7952   if (operands[2] != pc_rtx)
7953     {
7954       if (which_alternative == 0)
7955         return \"%*b%C0z\\t%1,%2\";
7956       else
7957         return \"%*bt%C0z\\t%2\";
7958     }
7959   else
7960     {
7961       if (which_alternative == 0)
7962         return \"%*b%N0z\\t%1,%3\";
7963       else
7964         return \"%*bt%N0z\\t%3\";
7965     }
7966 }"
7967   [(set_attr "type"     "branch")
7968    (set_attr "mode"     "none")
7969    (set_attr "length"   "8")])
7970
7971 (define_expand "bunordered"
7972   [(set (pc)
7973         (if_then_else (unordered:CC (cc0)
7974                                     (const_int 0))
7975                       (label_ref (match_operand 0 "" ""))
7976                       (pc)))]
7977   ""
7978   "
7979 {
7980   if (operands[0])              /* avoid unused code warning */
7981     {
7982       gen_conditional_branch (operands, UNORDERED);
7983       DONE;
7984     }
7985 }")
7986
7987 (define_expand "bordered"
7988   [(set (pc)
7989         (if_then_else (ordered:CC (cc0)
7990                                   (const_int 0))
7991                       (label_ref (match_operand 0 "" ""))
7992                       (pc)))]
7993   ""
7994   "
7995 {
7996   if (operands[0])              /* avoid unused code warning */
7997      {
7998         gen_conditional_branch (operands, ORDERED);
7999         DONE;
8000      }
8001 }")
8002
8003 (define_expand "bunlt"
8004   [(set (pc)
8005         (if_then_else (unlt:CC (cc0)
8006                                (const_int 0))
8007                       (label_ref (match_operand 0 "" ""))
8008                       (pc)))]
8009   ""
8010   "
8011 {
8012   if (operands[0])              /* avoid unused code warning */
8013      {
8014         gen_conditional_branch (operands, UNLT);
8015         DONE;
8016      }
8017 }")
8018
8019 (define_expand "bunge"
8020   [(set (pc)
8021         (if_then_else (unge:CC (cc0)
8022                                (const_int 0))
8023                       (label_ref (match_operand 0 "" ""))
8024                       (pc)))]
8025   ""
8026   "
8027 {
8028   gen_conditional_branch (operands, UNGE);
8029   DONE;
8030 }")
8031
8032 (define_expand "buneq"
8033   [(set (pc)
8034         (if_then_else (uneq:CC (cc0)
8035                                (const_int 0))
8036                       (label_ref (match_operand 0 "" ""))
8037                       (pc)))]
8038   ""
8039   "
8040 {
8041   if (operands[0])              /* avoid unused code warning */
8042      {
8043         gen_conditional_branch (operands, UNEQ);
8044         DONE;
8045      }
8046 }")
8047
8048 (define_expand "bltgt"
8049   [(set (pc)
8050         (if_then_else (ltgt:CC (cc0)
8051                                (const_int 0))
8052                       (label_ref (match_operand 0 "" ""))
8053                       (pc)))]
8054   ""
8055   "
8056 {
8057   gen_conditional_branch (operands, LTGT);
8058   DONE;
8059 }")
8060
8061 (define_expand "bunle"
8062   [(set (pc)
8063         (if_then_else (unle:CC (cc0)
8064                                (const_int 0))
8065                       (label_ref (match_operand 0 "" ""))
8066                       (pc)))]
8067   ""
8068   "
8069 {
8070   if (operands[0])              /* avoid unused code warning */
8071      {
8072         gen_conditional_branch (operands, UNLE);
8073         DONE;
8074      }
8075 }")
8076
8077 (define_expand "bungt"
8078   [(set (pc)
8079         (if_then_else (ungt:CC (cc0)
8080                                (const_int 0))
8081                       (label_ref (match_operand 0 "" ""))
8082                       (pc)))]
8083   ""
8084   "
8085 {
8086   gen_conditional_branch (operands, UNGT);
8087   DONE;
8088 }")
8089
8090 (define_expand "beq"
8091   [(set (pc)
8092         (if_then_else (eq:CC (cc0)
8093                              (const_int 0))
8094                       (label_ref (match_operand 0 "" ""))
8095                       (pc)))]
8096   ""
8097   "
8098 {
8099   if (operands[0])              /* avoid unused code warning */
8100     {
8101       gen_conditional_branch (operands, EQ);
8102       DONE;
8103     }
8104 }")
8105
8106 (define_expand "bne"
8107   [(set (pc)
8108         (if_then_else (ne:CC (cc0)
8109                              (const_int 0))
8110                       (label_ref (match_operand 0 "" ""))
8111                       (pc)))]
8112   ""
8113   "
8114 {
8115   if (operands[0])              /* avoid unused code warning */
8116     {
8117       gen_conditional_branch (operands, NE);
8118       DONE;
8119     }
8120 }")
8121
8122 (define_expand "bgt"
8123   [(set (pc)
8124         (if_then_else (gt:CC (cc0)
8125                              (const_int 0))
8126                       (label_ref (match_operand 0 "" ""))
8127                       (pc)))]
8128   ""
8129   "
8130 {
8131   if (operands[0])              /* avoid unused code warning */
8132     {
8133       gen_conditional_branch (operands, GT);
8134       DONE;
8135     }
8136 }")
8137
8138 (define_expand "bge"
8139   [(set (pc)
8140         (if_then_else (ge:CC (cc0)
8141                              (const_int 0))
8142                       (label_ref (match_operand 0 "" ""))
8143                       (pc)))]
8144   ""
8145   "
8146 {
8147   if (operands[0])              /* avoid unused code warning */
8148     {
8149       gen_conditional_branch (operands, GE);
8150       DONE;
8151     }
8152 }")
8153
8154 (define_expand "blt"
8155   [(set (pc)
8156         (if_then_else (lt:CC (cc0)
8157                              (const_int 0))
8158                       (label_ref (match_operand 0 "" ""))
8159                       (pc)))]
8160   ""
8161   "
8162 {
8163   if (operands[0])              /* avoid unused code warning */
8164     {
8165       gen_conditional_branch (operands, LT);
8166       DONE;
8167     }
8168 }")
8169
8170 (define_expand "ble"
8171   [(set (pc)
8172         (if_then_else (le:CC (cc0)
8173                              (const_int 0))
8174                       (label_ref (match_operand 0 "" ""))
8175                       (pc)))]
8176   ""
8177   "
8178 {
8179   if (operands[0])              /* avoid unused code warning */
8180     {
8181       gen_conditional_branch (operands, LE);
8182       DONE;
8183     }
8184 }")
8185
8186 (define_expand "bgtu"
8187   [(set (pc)
8188         (if_then_else (gtu:CC (cc0)
8189                               (const_int 0))
8190                       (label_ref (match_operand 0 "" ""))
8191                       (pc)))]
8192   ""
8193   "
8194 {
8195   if (operands[0])              /* avoid unused code warning */
8196     {
8197       gen_conditional_branch (operands, GTU);
8198       DONE;
8199     }
8200 }")
8201
8202 (define_expand "bgeu"
8203   [(set (pc)
8204         (if_then_else (geu:CC (cc0)
8205                               (const_int 0))
8206                       (label_ref (match_operand 0 "" ""))
8207                       (pc)))]
8208   ""
8209   "
8210 {
8211   if (operands[0])              /* avoid unused code warning */
8212     {
8213       gen_conditional_branch (operands, GEU);
8214       DONE;
8215     }
8216 }")
8217
8218
8219 (define_expand "bltu"
8220   [(set (pc)
8221         (if_then_else (ltu:CC (cc0)
8222                               (const_int 0))
8223                       (label_ref (match_operand 0 "" ""))
8224                       (pc)))]
8225   ""
8226   "
8227 {
8228   if (operands[0])              /* avoid unused code warning */
8229     {
8230       gen_conditional_branch (operands, LTU);
8231       DONE;
8232     }
8233 }")
8234
8235 (define_expand "bleu"
8236   [(set (pc)
8237         (if_then_else (leu:CC (cc0)
8238                               (const_int 0))
8239                       (label_ref (match_operand 0 "" ""))
8240                       (pc)))]
8241   ""
8242   "
8243 {
8244   if (operands[0])              /* avoid unused code warning */
8245     {
8246       gen_conditional_branch (operands, LEU);
8247       DONE;
8248     }
8249 }")
8250
8251 \f
8252 ;;
8253 ;;  ....................
8254 ;;
8255 ;;      SETTING A REGISTER FROM A COMPARISON
8256 ;;
8257 ;;  ....................
8258
8259 (define_expand "seq"
8260   [(set (match_operand:SI 0 "register_operand" "=d")
8261         (eq:SI (match_dup 1)
8262                (match_dup 2)))]
8263   ""
8264   "
8265 {
8266   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8267     FAIL;
8268
8269   /* set up operands from compare.  */
8270   operands[1] = branch_cmp[0];
8271   operands[2] = branch_cmp[1];
8272
8273   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8274     {
8275       gen_int_relational (EQ, operands[0], operands[1], operands[2], (int *)0);
8276       DONE;
8277     }
8278
8279   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
8280     operands[2] = force_reg (SImode, operands[2]);
8281
8282   /* fall through and generate default code */
8283 }")
8284
8285
8286 (define_insn "seq_si_zero"
8287   [(set (match_operand:SI 0 "register_operand" "=d")
8288         (eq:SI (match_operand:SI 1 "register_operand" "d")
8289                (const_int 0)))]
8290   "!TARGET_MIPS16"
8291   "sltu\\t%0,%1,1"
8292   [(set_attr "type"     "arith")
8293    (set_attr "mode"     "SI")])
8294
8295 (define_insn ""
8296   [(set (match_operand:SI 0 "register_operand" "=t")
8297         (eq:SI (match_operand:SI 1 "register_operand" "d")
8298                (const_int 0)))]
8299   "TARGET_MIPS16"
8300   "sltu\\t%1,1"
8301   [(set_attr "type"     "arith")
8302    (set_attr "mode"     "SI")])
8303
8304 (define_insn "seq_di_zero"
8305   [(set (match_operand:DI 0 "register_operand" "=d")
8306         (eq:DI (match_operand:DI 1 "register_operand" "d")
8307                (const_int 0)))]
8308   "TARGET_64BIT && !TARGET_MIPS16"
8309   "sltu\\t%0,%1,1"
8310   [(set_attr "type"     "arith")
8311    (set_attr "mode"     "DI")])
8312
8313 (define_insn ""
8314   [(set (match_operand:DI 0 "register_operand" "=t")
8315         (eq:DI (match_operand:DI 1 "register_operand" "d")
8316                (const_int 0)))]
8317   "TARGET_64BIT && TARGET_MIPS16"
8318   "sltu\\t%1,1"
8319   [(set_attr "type"     "arith")
8320    (set_attr "mode"     "DI")])
8321
8322 (define_insn "seq_si"
8323   [(set (match_operand:SI 0 "register_operand" "=d,d")
8324         (eq:SI (match_operand:SI 1 "register_operand" "%d,d")
8325                (match_operand:SI 2 "uns_arith_operand" "d,K")))]
8326   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8327   "@
8328    xor\\t%0,%1,%2\;sltu\\t%0,%0,1
8329    xori\\t%0,%1,%2\;sltu\\t%0,%0,1"
8330   [(set_attr "type"     "arith")
8331    (set_attr "mode"     "SI")
8332    (set_attr "length"   "8")])
8333
8334 (define_split
8335   [(set (match_operand:SI 0 "register_operand" "")
8336         (eq:SI (match_operand:SI 1 "register_operand" "")
8337                (match_operand:SI 2 "uns_arith_operand" "")))]
8338   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16
8339     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
8340   [(set (match_dup 0)
8341         (xor:SI (match_dup 1)
8342                 (match_dup 2)))
8343    (set (match_dup 0)
8344         (ltu:SI (match_dup 0)
8345                 (const_int 1)))]
8346   "")
8347
8348 (define_insn "seq_di"
8349   [(set (match_operand:DI 0 "register_operand" "=d,d")
8350         (eq:DI (match_operand:DI 1 "register_operand" "%d,d")
8351                (match_operand:DI 2 "uns_arith_operand" "d,K")))]
8352   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8353   "@
8354    xor\\t%0,%1,%2\;sltu\\t%0,%0,1
8355    xori\\t%0,%1,%2\;sltu\\t%0,%0,1"
8356   [(set_attr "type"     "arith")
8357    (set_attr "mode"     "DI")
8358    (set_attr "length"   "8")])
8359
8360 (define_split
8361   [(set (match_operand:DI 0 "register_operand" "")
8362         (eq:DI (match_operand:DI 1 "register_operand" "")
8363                (match_operand:DI 2 "uns_arith_operand" "")))]
8364   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8365     && !TARGET_MIPS16
8366     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
8367   [(set (match_dup 0)
8368         (xor:DI (match_dup 1)
8369                 (match_dup 2)))
8370    (set (match_dup 0)
8371         (ltu:DI (match_dup 0)
8372                 (const_int 1)))]
8373   "")
8374
8375 ;; On the mips16 the default code is better than using sltu.
8376
8377 (define_expand "sne"
8378   [(set (match_operand:SI 0 "register_operand" "=d")
8379         (ne:SI (match_dup 1)
8380                (match_dup 2)))]
8381   "!TARGET_MIPS16"
8382   "
8383 {
8384   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8385     FAIL;
8386
8387   /* set up operands from compare.  */
8388   operands[1] = branch_cmp[0];
8389   operands[2] = branch_cmp[1];
8390
8391   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE)
8392     {
8393       gen_int_relational (NE, operands[0], operands[1], operands[2], (int *)0);
8394       DONE;
8395     }
8396
8397   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) < 0)
8398     operands[2] = force_reg (SImode, operands[2]);
8399
8400   /* fall through and generate default code */
8401 }")
8402
8403 (define_insn "sne_si_zero"
8404   [(set (match_operand:SI 0 "register_operand" "=d")
8405         (ne:SI (match_operand:SI 1 "register_operand" "d")
8406                (const_int 0)))]
8407   "!TARGET_MIPS16"
8408   "sltu\\t%0,%.,%1"
8409   [(set_attr "type"     "arith")
8410    (set_attr "mode"     "SI")])
8411
8412 (define_insn "sne_di_zero"
8413   [(set (match_operand:DI 0 "register_operand" "=d")
8414         (ne:DI (match_operand:DI 1 "register_operand" "d")
8415                (const_int 0)))]
8416   "TARGET_64BIT && !TARGET_MIPS16"
8417   "sltu\\t%0,%.,%1"
8418   [(set_attr "type"     "arith")
8419    (set_attr "mode"     "DI")])
8420
8421 (define_insn "sne_si"
8422   [(set (match_operand:SI 0 "register_operand" "=d,d")
8423         (ne:SI (match_operand:SI 1 "register_operand" "%d,d")
8424                (match_operand:SI 2 "uns_arith_operand" "d,K")))]
8425   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8426   "@
8427     xor\\t%0,%1,%2\;sltu\\t%0,%.,%0
8428     xori\\t%0,%1,%x2\;sltu\\t%0,%.,%0"
8429   [(set_attr "type"     "arith")
8430    (set_attr "mode"     "SI")
8431    (set_attr "length"   "8")])
8432
8433 (define_split
8434   [(set (match_operand:SI 0 "register_operand" "")
8435         (ne:SI (match_operand:SI 1 "register_operand" "")
8436                (match_operand:SI 2 "uns_arith_operand" "")))]
8437   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16
8438     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
8439   [(set (match_dup 0)
8440         (xor:SI (match_dup 1)
8441                 (match_dup 2)))
8442    (set (match_dup 0)
8443         (gtu:SI (match_dup 0)
8444                 (const_int 0)))]
8445   "")
8446
8447 (define_insn "sne_di"
8448   [(set (match_operand:DI 0 "register_operand" "=d,d")
8449         (ne:DI (match_operand:DI 1 "register_operand" "%d,d")
8450                (match_operand:DI 2 "uns_arith_operand" "d,K")))]
8451   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8452   "@
8453     xor\\t%0,%1,%2\;sltu\\t%0,%.,%0
8454     xori\\t%0,%1,%x2\;sltu\\t%0,%.,%0"
8455   [(set_attr "type"     "arith")
8456    (set_attr "mode"     "DI")
8457    (set_attr "length"   "8")])
8458
8459 (define_split
8460   [(set (match_operand:DI 0 "register_operand" "")
8461         (ne:DI (match_operand:DI 1 "register_operand" "")
8462                (match_operand:DI 2 "uns_arith_operand" "")))]
8463   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8464     && !TARGET_MIPS16
8465     && (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) != 0)"
8466   [(set (match_dup 0)
8467         (xor:DI (match_dup 1)
8468                 (match_dup 2)))
8469    (set (match_dup 0)
8470         (gtu:DI (match_dup 0)
8471                 (const_int 0)))]
8472   "")
8473
8474 (define_expand "sgt"
8475   [(set (match_operand:SI 0 "register_operand" "=d")
8476         (gt:SI (match_dup 1)
8477                (match_dup 2)))]
8478   ""
8479   "
8480 {
8481   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8482     FAIL;
8483
8484   /* set up operands from compare.  */
8485   operands[1] = branch_cmp[0];
8486   operands[2] = branch_cmp[1];
8487
8488   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8489     {
8490       gen_int_relational (GT, operands[0], operands[1], operands[2], (int *)0);
8491       DONE;
8492     }
8493
8494   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
8495     operands[2] = force_reg (SImode, operands[2]);
8496
8497   /* fall through and generate default code */
8498 }")
8499
8500 (define_insn "sgt_si"
8501   [(set (match_operand:SI 0 "register_operand" "=d")
8502         (gt:SI (match_operand:SI 1 "register_operand" "d")
8503                (match_operand:SI 2 "reg_or_0_operand" "dJ")))]
8504   "!TARGET_MIPS16"
8505   "slt\\t%0,%z2,%1"
8506   [(set_attr "type"     "arith")
8507    (set_attr "mode"     "SI")])
8508
8509 (define_insn ""
8510   [(set (match_operand:SI 0 "register_operand" "=t")
8511         (gt:SI (match_operand:SI 1 "register_operand" "d")
8512                (match_operand:SI 2 "register_operand" "d")))]
8513   "TARGET_MIPS16"
8514   "slt\\t%2,%1"
8515   [(set_attr "type"     "arith")
8516    (set_attr "mode"     "SI")])
8517
8518 (define_insn "sgt_di"
8519   [(set (match_operand:DI 0 "register_operand" "=d")
8520         (gt:DI (match_operand:DI 1 "register_operand" "d")
8521                (match_operand:DI 2 "reg_or_0_operand" "dJ")))]
8522   "TARGET_64BIT && !TARGET_MIPS16"
8523   "slt\\t%0,%z2,%1"
8524   [(set_attr "type"     "arith")
8525    (set_attr "mode"     "DI")])
8526
8527 (define_insn ""
8528   [(set (match_operand:DI 0 "register_operand" "=d")
8529         (gt:DI (match_operand:DI 1 "register_operand" "d")
8530                (match_operand:DI 2 "register_operand" "d")))]
8531   "TARGET_64BIT && TARGET_MIPS16"
8532   "slt\\t%2,%1"
8533   [(set_attr "type"     "arith")
8534    (set_attr "mode"     "DI")])
8535
8536 (define_expand "sge"
8537   [(set (match_operand:SI 0 "register_operand" "=d")
8538         (ge:SI (match_dup 1)
8539                (match_dup 2)))]
8540   ""
8541   "
8542 {
8543   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8544     FAIL;
8545
8546   /* set up operands from compare.  */
8547   operands[1] = branch_cmp[0];
8548   operands[2] = branch_cmp[1];
8549
8550   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8551     {
8552       gen_int_relational (GE, operands[0], operands[1], operands[2], (int *)0);
8553       DONE;
8554     }
8555
8556   /* fall through and generate default code */
8557 }")
8558
8559 (define_insn "sge_si"
8560   [(set (match_operand:SI 0 "register_operand" "=d")
8561         (ge:SI (match_operand:SI 1 "register_operand" "d")
8562                (match_operand:SI 2 "arith_operand" "dI")))]
8563   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8564   "slt\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
8565   [(set_attr "type"     "arith")
8566    (set_attr "mode"     "SI")
8567    (set_attr "length"   "8")])
8568
8569 (define_split
8570   [(set (match_operand:SI 0 "register_operand" "")
8571         (ge:SI (match_operand:SI 1 "register_operand" "")
8572                (match_operand:SI 2 "arith_operand" "")))]
8573   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
8574   [(set (match_dup 0)
8575         (lt:SI (match_dup 1)
8576                (match_dup 2)))
8577    (set (match_dup 0)
8578         (xor:SI (match_dup 0)
8579                 (const_int 1)))]
8580   "")
8581
8582 (define_insn "sge_di"
8583   [(set (match_operand:DI 0 "register_operand" "=d")
8584         (ge:DI (match_operand:DI 1 "register_operand" "d")
8585                (match_operand:DI 2 "arith_operand" "dI")))]
8586   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8587   "slt\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
8588   [(set_attr "type"     "arith")
8589    (set_attr "mode"     "DI")
8590    (set_attr "length"   "8")])
8591
8592 (define_split
8593   [(set (match_operand:DI 0 "register_operand" "")
8594         (ge:DI (match_operand:DI 1 "register_operand" "")
8595                (match_operand:DI 2 "arith_operand" "")))]
8596   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8597    && !TARGET_MIPS16"
8598   [(set (match_dup 0)
8599         (lt:DI (match_dup 1)
8600                (match_dup 2)))
8601    (set (match_dup 0)
8602         (xor:DI (match_dup 0)
8603                 (const_int 1)))]
8604   "")
8605
8606 (define_expand "slt"
8607   [(set (match_operand:SI 0 "register_operand" "=d")
8608         (lt:SI (match_dup 1)
8609                (match_dup 2)))]
8610   ""
8611   "
8612 {
8613   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8614     FAIL;
8615
8616   /* set up operands from compare.  */
8617   operands[1] = branch_cmp[0];
8618   operands[2] = branch_cmp[1];
8619
8620   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8621     {
8622       gen_int_relational (LT, operands[0], operands[1], operands[2], (int *)0);
8623       DONE;
8624     }
8625
8626   /* fall through and generate default code */
8627 }")
8628
8629 (define_insn "slt_si"
8630   [(set (match_operand:SI 0 "register_operand" "=d")
8631         (lt:SI (match_operand:SI 1 "register_operand" "d")
8632                (match_operand:SI 2 "arith_operand" "dI")))]
8633   "!TARGET_MIPS16"
8634   "slt\\t%0,%1,%2"
8635   [(set_attr "type"     "arith")
8636    (set_attr "mode"     "SI")])
8637
8638 (define_insn ""
8639   [(set (match_operand:SI 0 "register_operand" "=t,t")
8640         (lt:SI (match_operand:SI 1 "register_operand" "d,d")
8641                (match_operand:SI 2 "arith_operand" "d,I")))]
8642   "TARGET_MIPS16"
8643   "slt\\t%1,%2"
8644   [(set_attr "type"     "arith")
8645    (set_attr "mode"     "SI")
8646    (set_attr_alternative "length"
8647                 [(const_int 4)
8648                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
8649                                (const_int 4)
8650                                (const_int 8))])])
8651
8652 (define_insn "slt_di"
8653   [(set (match_operand:DI 0 "register_operand" "=d")
8654         (lt:DI (match_operand:DI 1 "register_operand" "d")
8655                (match_operand:DI 2 "arith_operand" "dI")))]
8656   "TARGET_64BIT && !TARGET_MIPS16"
8657   "slt\\t%0,%1,%2"
8658   [(set_attr "type"     "arith")
8659    (set_attr "mode"     "DI")])
8660
8661 (define_insn ""
8662   [(set (match_operand:DI 0 "register_operand" "=t,t")
8663         (lt:DI (match_operand:DI 1 "register_operand" "d,d")
8664                (match_operand:DI 2 "arith_operand" "d,I")))]
8665   "TARGET_64BIT && TARGET_MIPS16"
8666   "slt\\t%1,%2"
8667   [(set_attr "type"     "arith")
8668    (set_attr "mode"     "DI")
8669    (set_attr_alternative "length"
8670                 [(const_int 4)
8671                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
8672                                (const_int 4)
8673                                (const_int 8))])])
8674
8675 (define_expand "sle"
8676   [(set (match_operand:SI 0 "register_operand" "=d")
8677         (le:SI (match_dup 1)
8678                (match_dup 2)))]
8679   ""
8680   "
8681 {
8682   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8683     FAIL;
8684
8685   /* set up operands from compare.  */
8686   operands[1] = branch_cmp[0];
8687   operands[2] = branch_cmp[1];
8688
8689   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8690     {
8691       gen_int_relational (LE, operands[0], operands[1], operands[2], (int *)0);
8692       DONE;
8693     }
8694
8695   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 32767)
8696     operands[2] = force_reg (SImode, operands[2]);
8697
8698   /* fall through and generate default code */
8699 }")
8700
8701 (define_insn "sle_si_const"
8702   [(set (match_operand:SI 0 "register_operand" "=d")
8703         (le:SI (match_operand:SI 1 "register_operand" "d")
8704                (match_operand:SI 2 "small_int" "I")))]
8705   "!TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8706   "*
8707 {
8708   operands[2] = GEN_INT (INTVAL (operands[2])+1);
8709   return \"slt\\t%0,%1,%2\";
8710 }"
8711   [(set_attr "type"     "arith")
8712    (set_attr "mode"     "SI")])
8713
8714 (define_insn ""
8715   [(set (match_operand:SI 0 "register_operand" "=t")
8716         (le:SI (match_operand:SI 1 "register_operand" "d")
8717                (match_operand:SI 2 "small_int" "I")))]
8718   "TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8719   "*
8720 {
8721   operands[2] = GEN_INT (INTVAL (operands[2])+1);
8722   return \"slt\\t%1,%2\";
8723 }"
8724   [(set_attr "type"     "arith")
8725    (set_attr "mode"     "SI")
8726    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
8727                                       (const_int 4)
8728                                       (const_int 8)))])
8729
8730 (define_insn "sle_di_const"
8731   [(set (match_operand:DI 0 "register_operand" "=d")
8732         (le:DI (match_operand:DI 1 "register_operand" "d")
8733                (match_operand:DI 2 "small_int" "I")))]
8734   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8735   "*
8736 {
8737   operands[2] = GEN_INT (INTVAL (operands[2])+1);
8738   return \"slt\\t%0,%1,%2\";
8739 }"
8740   [(set_attr "type"     "arith")
8741    (set_attr "mode"     "DI")])
8742
8743 (define_insn ""
8744   [(set (match_operand:DI 0 "register_operand" "=t")
8745         (le:DI (match_operand:DI 1 "register_operand" "d")
8746                (match_operand:DI 2 "small_int" "I")))]
8747   "TARGET_64BIT && TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
8748   "*
8749 {
8750   operands[2] = GEN_INT (INTVAL (operands[2])+1);
8751   return \"slt\\t%1,%2\";
8752 }"
8753   [(set_attr "type"     "arith")
8754    (set_attr "mode"     "DI")
8755    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
8756                                       (const_int 4)
8757                                       (const_int 8)))])
8758
8759 (define_insn "sle_si_reg"
8760   [(set (match_operand:SI 0 "register_operand" "=d")
8761         (le:SI (match_operand:SI 1 "register_operand" "d")
8762                (match_operand:SI 2 "register_operand" "d")))]
8763   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8764   "slt\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
8765   [(set_attr "type"     "arith")
8766    (set_attr "mode"     "SI")
8767    (set_attr "length"   "8")])
8768
8769 (define_split
8770   [(set (match_operand:SI 0 "register_operand" "")
8771         (le:SI (match_operand:SI 1 "register_operand" "")
8772                (match_operand:SI 2 "register_operand" "")))]
8773   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
8774   [(set (match_dup 0)
8775         (lt:SI (match_dup 2)
8776                (match_dup 1)))
8777    (set (match_dup 0)
8778         (xor:SI (match_dup 0)
8779                 (const_int 1)))]
8780   "")
8781
8782 (define_insn "sle_di_reg"
8783   [(set (match_operand:DI 0 "register_operand" "=d")
8784         (le:DI (match_operand:DI 1 "register_operand" "d")
8785                (match_operand:DI 2 "register_operand" "d")))]
8786   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8787   "slt\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
8788   [(set_attr "type"     "arith")
8789    (set_attr "mode"     "DI")
8790    (set_attr "length"   "8")])
8791
8792 (define_split
8793   [(set (match_operand:DI 0 "register_operand" "")
8794         (le:DI (match_operand:DI 1 "register_operand" "")
8795                (match_operand:DI 2 "register_operand" "")))]
8796   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8797    && !TARGET_MIPS16"
8798   [(set (match_dup 0)
8799         (lt:DI (match_dup 2)
8800                (match_dup 1)))
8801    (set (match_dup 0)
8802         (xor:DI (match_dup 0)
8803                 (const_int 1)))]
8804   "")
8805
8806 (define_expand "sgtu"
8807   [(set (match_operand:SI 0 "register_operand" "=d")
8808         (gtu:SI (match_dup 1)
8809                 (match_dup 2)))]
8810   ""
8811   "
8812 {
8813   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8814     FAIL;
8815
8816   /* set up operands from compare.  */
8817   operands[1] = branch_cmp[0];
8818   operands[2] = branch_cmp[1];
8819
8820   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8821     {
8822       gen_int_relational (GTU, operands[0], operands[1], operands[2], (int *)0);
8823       DONE;
8824     }
8825
8826   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) != 0)
8827     operands[2] = force_reg (SImode, operands[2]);
8828
8829   /* fall through and generate default code */
8830 }")
8831
8832 (define_insn "sgtu_si"
8833   [(set (match_operand:SI 0 "register_operand" "=d")
8834         (gtu:SI (match_operand:SI 1 "register_operand" "d")
8835                 (match_operand:SI 2 "reg_or_0_operand" "dJ")))]
8836   "!TARGET_MIPS16"
8837   "sltu\\t%0,%z2,%1"
8838   [(set_attr "type"     "arith")
8839    (set_attr "mode"     "SI")])
8840
8841 (define_insn ""
8842   [(set (match_operand:SI 0 "register_operand" "=t")
8843         (gtu:SI (match_operand:SI 1 "register_operand" "d")
8844                 (match_operand:SI 2 "register_operand" "d")))]
8845   "TARGET_MIPS16"
8846   "sltu\\t%2,%1"
8847   [(set_attr "type"     "arith")
8848    (set_attr "mode"     "SI")])
8849
8850 (define_insn "sgtu_di"
8851   [(set (match_operand:DI 0 "register_operand" "=d")
8852         (gtu:DI (match_operand:DI 1 "register_operand" "d")
8853                 (match_operand:DI 2 "reg_or_0_operand" "dJ")))]
8854   "TARGET_64BIT && !TARGET_MIPS16"
8855   "sltu\\t%0,%z2,%1"
8856   [(set_attr "type"     "arith")
8857    (set_attr "mode"     "DI")])
8858
8859 (define_insn ""
8860   [(set (match_operand:DI 0 "register_operand" "=t")
8861         (gtu:DI (match_operand:DI 1 "register_operand" "d")
8862                 (match_operand:DI 2 "register_operand" "d")))]
8863   "TARGET_64BIT && TARGET_MIPS16"
8864   "sltu\\t%2,%1"
8865   [(set_attr "type"     "arith")
8866    (set_attr "mode"     "DI")])
8867
8868 (define_expand "sgeu"
8869   [(set (match_operand:SI 0 "register_operand" "=d")
8870         (geu:SI (match_dup 1)
8871                 (match_dup 2)))]
8872   ""
8873   "
8874 {
8875   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8876     FAIL;
8877
8878   /* set up operands from compare.  */
8879   operands[1] = branch_cmp[0];
8880   operands[2] = branch_cmp[1];
8881
8882   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8883     {
8884       gen_int_relational (GEU, operands[0], operands[1], operands[2], (int *)0);
8885       DONE;
8886     }
8887
8888   /* fall through and generate default code */
8889 }")
8890
8891 (define_insn "sgeu_si"
8892   [(set (match_operand:SI 0 "register_operand" "=d")
8893         (geu:SI (match_operand:SI 1 "register_operand" "d")
8894                 (match_operand:SI 2 "arith_operand" "dI")))]
8895   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8896   "sltu\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
8897   [(set_attr "type"     "arith")
8898    (set_attr "mode"     "SI")
8899    (set_attr "length"   "8")])
8900
8901 (define_split
8902   [(set (match_operand:SI 0 "register_operand" "")
8903         (geu:SI (match_operand:SI 1 "register_operand" "")
8904                 (match_operand:SI 2 "arith_operand" "")))]
8905   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
8906   [(set (match_dup 0)
8907         (ltu:SI (match_dup 1)
8908                 (match_dup 2)))
8909    (set (match_dup 0)
8910         (xor:SI (match_dup 0)
8911                 (const_int 1)))]
8912   "")
8913
8914 (define_insn "sgeu_di"
8915   [(set (match_operand:DI 0 "register_operand" "=d")
8916         (geu:DI (match_operand:DI 1 "register_operand" "d")
8917                 (match_operand:DI 2 "arith_operand" "dI")))]
8918   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
8919   "sltu\\t%0,%1,%2\;xori\\t%0,%0,0x0001"
8920   [(set_attr "type"     "arith")
8921    (set_attr "mode"     "DI")
8922    (set_attr "length"   "8")])
8923
8924 (define_split
8925   [(set (match_operand:DI 0 "register_operand" "")
8926         (geu:DI (match_operand:DI 1 "register_operand" "")
8927                 (match_operand:DI 2 "arith_operand" "")))]
8928   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
8929    && !TARGET_MIPS16"
8930   [(set (match_dup 0)
8931         (ltu:DI (match_dup 1)
8932                 (match_dup 2)))
8933    (set (match_dup 0)
8934         (xor:DI (match_dup 0)
8935                 (const_int 1)))]
8936   "")
8937
8938 (define_expand "sltu"
8939   [(set (match_operand:SI 0 "register_operand" "=d")
8940         (ltu:SI (match_dup 1)
8941                 (match_dup 2)))]
8942   ""
8943   "
8944 {
8945   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
8946     FAIL;
8947
8948   /* set up operands from compare.  */
8949   operands[1] = branch_cmp[0];
8950   operands[2] = branch_cmp[1];
8951
8952   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
8953     {
8954       gen_int_relational (LTU, operands[0], operands[1], operands[2], (int *)0);
8955       DONE;
8956     }
8957
8958   /* fall through and generate default code */
8959 }")
8960
8961 (define_insn "sltu_si"
8962   [(set (match_operand:SI 0 "register_operand" "=d")
8963         (ltu:SI (match_operand:SI 1 "register_operand" "d")
8964                 (match_operand:SI 2 "arith_operand" "dI")))]
8965   "!TARGET_MIPS16"
8966   "sltu\\t%0,%1,%2"
8967   [(set_attr "type"     "arith")
8968    (set_attr "mode"     "SI")])
8969
8970 (define_insn ""
8971   [(set (match_operand:SI 0 "register_operand" "=t,t")
8972         (ltu:SI (match_operand:SI 1 "register_operand" "d,d")
8973                 (match_operand:SI 2 "arith_operand" "d,I")))]
8974   "TARGET_MIPS16"
8975   "sltu\\t%1,%2"
8976   [(set_attr "type"     "arith")
8977    (set_attr "mode"     "SI")
8978    (set_attr_alternative "length"
8979                 [(const_int 4)
8980                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
8981                                (const_int 4)
8982                                (const_int 8))])])
8983
8984 (define_insn "sltu_di"
8985   [(set (match_operand:DI 0 "register_operand" "=d")
8986         (ltu:DI (match_operand:DI 1 "register_operand" "d")
8987                 (match_operand:DI 2 "arith_operand" "dI")))]
8988   "TARGET_64BIT && !TARGET_MIPS16"
8989   "sltu\\t%0,%1,%2"
8990   [(set_attr "type"     "arith")
8991    (set_attr "mode"     "DI")])
8992
8993 (define_insn ""
8994   [(set (match_operand:DI 0 "register_operand" "=t,t")
8995         (ltu:DI (match_operand:DI 1 "register_operand" "d,d")
8996                 (match_operand:DI 2 "arith_operand" "d,I")))]
8997   "TARGET_64BIT && TARGET_MIPS16"
8998   "sltu\\t%1,%2"
8999   [(set_attr "type"     "arith")
9000    (set_attr "mode"     "DI")
9001    (set_attr_alternative "length"
9002                 [(const_int 4)
9003                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1" "")
9004                                (const_int 4)
9005                                (const_int 8))])])
9006
9007 (define_expand "sleu"
9008   [(set (match_operand:SI 0 "register_operand" "=d")
9009         (leu:SI (match_dup 1)
9010                 (match_dup 2)))]
9011   ""
9012   "
9013 {
9014   if (branch_type != CMP_SI && (!TARGET_64BIT || branch_type != CMP_DI))
9015     FAIL;
9016
9017   /* set up operands from compare.  */
9018   operands[1] = branch_cmp[0];
9019   operands[2] = branch_cmp[1];
9020
9021   if (TARGET_64BIT || !TARGET_DEBUG_C_MODE || TARGET_MIPS16)
9022     {
9023       gen_int_relational (LEU, operands[0], operands[1], operands[2], (int *)0);
9024       DONE;
9025     }
9026
9027   if (GET_CODE (operands[2]) == CONST_INT && INTVAL (operands[2]) >= 32767)
9028     operands[2] = force_reg (SImode, operands[2]);
9029
9030   /* fall through and generate default code */
9031 }")
9032
9033 (define_insn "sleu_si_const"
9034   [(set (match_operand:SI 0 "register_operand" "=d")
9035         (leu:SI (match_operand:SI 1 "register_operand" "d")
9036                 (match_operand:SI 2 "small_int" "I")))]
9037   "!TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
9038   "*
9039 {
9040   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
9041   return \"sltu\\t%0,%1,%2\";
9042 }"
9043   [(set_attr "type"     "arith")
9044    (set_attr "mode"     "SI")])
9045
9046 (define_insn ""
9047   [(set (match_operand:SI 0 "register_operand" "=t")
9048         (leu:SI (match_operand:SI 1 "register_operand" "d")
9049                 (match_operand:SI 2 "small_int" "I")))]
9050   "TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
9051   "*
9052 {
9053   operands[2] = GEN_INT (INTVAL (operands[2])+1);
9054   return \"sltu\\t%1,%2\";
9055 }"
9056   [(set_attr "type"     "arith")
9057    (set_attr "mode"     "SI")
9058    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
9059                                       (const_int 4)
9060                                       (const_int 8)))])
9061
9062 (define_insn "sleu_di_const"
9063   [(set (match_operand:DI 0 "register_operand" "=d")
9064         (leu:DI (match_operand:DI 1 "register_operand" "d")
9065                 (match_operand:DI 2 "small_int" "I")))]
9066   "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
9067   "*
9068 {
9069   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
9070   return \"sltu\\t%0,%1,%2\";
9071 }"
9072   [(set_attr "type"     "arith")
9073    (set_attr "mode"     "DI")])
9074
9075 (define_insn ""
9076   [(set (match_operand:DI 0 "register_operand" "=t")
9077         (leu:DI (match_operand:DI 1 "register_operand" "d")
9078                 (match_operand:DI 2 "small_int" "I")))]
9079   "TARGET_64BIT && TARGET_MIPS16 && INTVAL (operands[2]) < 32767"
9080   "*
9081 {
9082   operands[2] = GEN_INT (INTVAL (operands[2])+1);
9083   return \"sltu\\t%1,%2\";
9084 }"
9085   [(set_attr "type"     "arith")
9086    (set_attr "mode"     "DI")
9087    (set (attr "length") (if_then_else (match_operand:VOID 2 "m16_uimm8_m1_1" "")
9088                                       (const_int 4)
9089                                       (const_int 8)))])
9090
9091 (define_insn "sleu_si_reg"
9092   [(set (match_operand:SI 0 "register_operand" "=d")
9093         (leu:SI (match_operand:SI 1 "register_operand" "d")
9094                 (match_operand:SI 2 "register_operand" "d")))]
9095   "TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
9096   "sltu\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
9097   [(set_attr "type"     "arith")
9098    (set_attr "mode"     "SI")
9099    (set_attr "length"   "8")])
9100
9101 (define_split
9102   [(set (match_operand:SI 0 "register_operand" "")
9103         (leu:SI (match_operand:SI 1 "register_operand" "")
9104                 (match_operand:SI 2 "register_operand" "")))]
9105   "TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE && !TARGET_MIPS16"
9106   [(set (match_dup 0)
9107         (ltu:SI (match_dup 2)
9108                 (match_dup 1)))
9109    (set (match_dup 0)
9110         (xor:SI (match_dup 0)
9111                 (const_int 1)))]
9112   "")
9113
9114 (define_insn "sleu_di_reg"
9115   [(set (match_operand:DI 0 "register_operand" "=d")
9116         (leu:DI (match_operand:DI 1 "register_operand" "d")
9117                 (match_operand:DI 2 "register_operand" "d")))]
9118   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_MIPS16"
9119   "sltu\\t%0,%z2,%1\;xori\\t%0,%0,0x0001"
9120   [(set_attr "type"     "arith")
9121    (set_attr "mode"     "DI")
9122    (set_attr "length"   "8")])
9123
9124 (define_split
9125   [(set (match_operand:DI 0 "register_operand" "")
9126         (leu:DI (match_operand:DI 1 "register_operand" "")
9127                 (match_operand:DI 2 "register_operand" "")))]
9128   "TARGET_64BIT && TARGET_DEBUG_C_MODE && !TARGET_DEBUG_D_MODE
9129    && !TARGET_MIPS16"
9130   [(set (match_dup 0)
9131         (ltu:DI (match_dup 2)
9132                 (match_dup 1)))
9133    (set (match_dup 0)
9134         (xor:DI (match_dup 0)
9135                 (const_int 1)))]
9136   "")
9137
9138 \f
9139 ;;
9140 ;;  ....................
9141 ;;
9142 ;;      FLOATING POINT COMPARISONS
9143 ;;
9144 ;;  ....................
9145
9146 (define_insn "sunordered_df"
9147   [(set (match_operand:CC 0 "register_operand" "=z")
9148         (unordered:CC (match_operand:DF 1 "register_operand" "f")
9149                       (match_operand:DF 2 "register_operand" "f")))]
9150   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9151   "c.un.d\t%Z0%1,%2"
9152   [(set_attr "type" "fcmp")
9153    (set_attr "mode" "FPSW")])
9154
9155 (define_insn "sunlt_df"
9156   [(set (match_operand:CC 0 "register_operand" "=z")
9157         (unlt:CC (match_operand:DF 1 "register_operand" "f")
9158                  (match_operand:DF 2 "register_operand" "f")))]
9159   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9160   "c.ult.d\t%Z0%1,%2"
9161   [(set_attr "type" "fcmp")
9162    (set_attr "mode" "FPSW")])
9163
9164 (define_insn "suneq_df"
9165   [(set (match_operand:CC 0 "register_operand" "=z")
9166         (uneq:CC (match_operand:DF 1 "register_operand" "f")
9167                  (match_operand:DF 2 "register_operand" "f")))]
9168   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9169   "c.ueq.d\t%Z0%1,%2"
9170   [(set_attr "type" "fcmp")
9171    (set_attr "mode" "FPSW")])
9172
9173 (define_insn "sunle_df"
9174   [(set (match_operand:CC 0 "register_operand" "=z")
9175         (unle:CC (match_operand:DF 1 "register_operand" "f")
9176                  (match_operand:DF 2 "register_operand" "f")))]
9177   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9178   "c.ule.d\t%Z0%1,%2"
9179   [(set_attr "type" "fcmp")
9180    (set_attr "mode" "FPSW")])
9181
9182 (define_insn "seq_df"
9183   [(set (match_operand:CC 0 "register_operand" "=z")
9184         (eq:CC (match_operand:DF 1 "register_operand" "f")
9185                (match_operand:DF 2 "register_operand" "f")))]
9186   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9187   "c.eq.d\t%Z0%1,%2"
9188   [(set_attr "type" "fcmp")
9189    (set_attr "mode" "FPSW")])
9190
9191 (define_insn "slt_df"
9192   [(set (match_operand:CC 0 "register_operand" "=z")
9193         (lt:CC (match_operand:DF 1 "register_operand" "f")
9194                (match_operand:DF 2 "register_operand" "f")))]
9195   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9196   "c.lt.d\t%Z0%1,%2"
9197   [(set_attr "type" "fcmp")
9198    (set_attr "mode" "FPSW")])
9199
9200 (define_insn "sle_df"
9201   [(set (match_operand:CC 0 "register_operand" "=z")
9202         (le:CC (match_operand:DF 1 "register_operand" "f")
9203                (match_operand:DF 2 "register_operand" "f")))]
9204   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9205   "c.le.d\t%Z0%1,%2"
9206   [(set_attr "type" "fcmp")
9207    (set_attr "mode" "FPSW")])
9208
9209 (define_insn "sgt_df"
9210   [(set (match_operand:CC 0 "register_operand" "=z")
9211         (gt:CC (match_operand:DF 1 "register_operand" "f")
9212                (match_operand:DF 2 "register_operand" "f")))]
9213   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9214   "c.lt.d\t%Z0%2,%1"
9215   [(set_attr "type" "fcmp")
9216    (set_attr "mode" "FPSW")])
9217
9218 (define_insn "sge_df"
9219   [(set (match_operand:CC 0 "register_operand" "=z")
9220         (ge:CC (match_operand:DF 1 "register_operand" "f")
9221                (match_operand:DF 2 "register_operand" "f")))]
9222   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
9223   "c.le.d\t%Z0%2,%1"
9224   [(set_attr "type" "fcmp")
9225    (set_attr "mode" "FPSW")])
9226
9227 (define_insn "sunordered_sf"
9228   [(set (match_operand:CC 0 "register_operand" "=z")
9229         (unordered:CC (match_operand:SF 1 "register_operand" "f")
9230                       (match_operand:SF 2 "register_operand" "f")))]
9231   "TARGET_HARD_FLOAT"
9232   "c.un.s\t%Z0%1,%2"
9233   [(set_attr "type" "fcmp")
9234    (set_attr "mode" "FPSW")])
9235
9236 (define_insn "sunlt_sf"
9237   [(set (match_operand:CC 0 "register_operand" "=z")
9238         (unlt:CC (match_operand:SF 1 "register_operand" "f")
9239                  (match_operand:SF 2 "register_operand" "f")))]
9240   "TARGET_HARD_FLOAT"
9241   "c.ult.s\t%Z0%1,%2"
9242   [(set_attr "type" "fcmp")
9243    (set_attr "mode" "FPSW")])
9244
9245 (define_insn "suneq_sf"
9246   [(set (match_operand:CC 0 "register_operand" "=z")
9247         (uneq:CC (match_operand:SF 1 "register_operand" "f")
9248                  (match_operand:SF 2 "register_operand" "f")))]
9249   "TARGET_HARD_FLOAT"
9250   "c.ueq.s\t%Z0%1,%2"
9251   [(set_attr "type" "fcmp")
9252    (set_attr "mode" "FPSW")])
9253
9254 (define_insn "sunle_sf"
9255   [(set (match_operand:CC 0 "register_operand" "=z")
9256         (unle:CC (match_operand:SF 1 "register_operand" "f")
9257                  (match_operand:SF 2 "register_operand" "f")))]
9258   "TARGET_HARD_FLOAT"
9259   "c.ule.s\t%Z0%1,%2"
9260   [(set_attr "type" "fcmp")
9261    (set_attr "mode" "FPSW")])
9262
9263 (define_insn "seq_sf"
9264   [(set (match_operand:CC 0 "register_operand" "=z")
9265         (eq:CC (match_operand:SF 1 "register_operand" "f")
9266                (match_operand:SF 2 "register_operand" "f")))]
9267   "TARGET_HARD_FLOAT"
9268   "c.eq.s\t%Z0%1,%2"
9269   [(set_attr "type" "fcmp")
9270    (set_attr "mode" "FPSW")])
9271
9272 (define_insn "slt_sf"
9273   [(set (match_operand:CC 0 "register_operand" "=z")
9274         (lt:CC (match_operand:SF 1 "register_operand" "f")
9275                (match_operand:SF 2 "register_operand" "f")))]
9276   "TARGET_HARD_FLOAT"
9277   "c.lt.s\t%Z0%1,%2"
9278   [(set_attr "type" "fcmp")
9279    (set_attr "mode" "FPSW")])
9280
9281 (define_insn "sle_sf"
9282   [(set (match_operand:CC 0 "register_operand" "=z")
9283         (le:CC (match_operand:SF 1 "register_operand" "f")
9284                (match_operand:SF 2 "register_operand" "f")))]
9285   "TARGET_HARD_FLOAT"
9286   "c.le.s\t%Z0%1,%2"
9287   [(set_attr "type" "fcmp")
9288    (set_attr "mode" "FPSW")])
9289
9290 (define_insn "sgt_sf"
9291   [(set (match_operand:CC 0 "register_operand" "=z")
9292         (gt:CC (match_operand:SF 1 "register_operand" "f")
9293                (match_operand:SF 2 "register_operand" "f")))]
9294   "TARGET_HARD_FLOAT"
9295   "c.lt.s\t%Z0%2,%1"
9296   [(set_attr "type" "fcmp")
9297    (set_attr "mode" "FPSW")])
9298
9299 (define_insn "sge_sf"
9300   [(set (match_operand:CC 0 "register_operand" "=z")
9301         (ge:CC (match_operand:SF 1 "register_operand" "f")
9302                (match_operand:SF 2 "register_operand" "f")))]
9303   "TARGET_HARD_FLOAT"
9304   "c.le.s\t%Z0%2,%1"
9305   [(set_attr "type" "fcmp")
9306    (set_attr "mode" "FPSW")])
9307
9308 \f
9309 ;;
9310 ;;  ....................
9311 ;;
9312 ;;      UNCONDITIONAL BRANCHES
9313 ;;
9314 ;;  ....................
9315
9316 ;; Unconditional branches.
9317
9318 (define_insn "jump"
9319   [(set (pc)
9320         (label_ref (match_operand 0 "" "")))]
9321   "!TARGET_MIPS16"
9322   "*
9323 {
9324   if (flag_pic && ! TARGET_EMBEDDED_PIC)
9325     {
9326       if (get_attr_length (insn) <= 8)
9327         return \"%*b\\t%l0\";
9328       else if (Pmode == DImode)
9329         return \"%[dla\\t%@,%l0\;%*jr\\t%@%]\";
9330       else
9331         return \"%[la\\t%@,%l0\;%*jr\\t%@%]\";
9332     }
9333   else
9334     return \"%*j\\t%l0\";
9335 }"
9336   [(set_attr "type"     "jump")
9337    (set_attr "mode"     "none")
9338    (set (attr "length")
9339         ;; we can't use `j' when emitting non-embedded PIC, so we emit
9340         ;; branch, if it's in range, or load the address of the branch
9341         ;; target into $at in a PIC-compatible way and then jump to it.
9342         (if_then_else
9343          (ior (eq (symbol_ref "flag_pic && ! TARGET_EMBEDDED_PIC")
9344                   (const_int 0))
9345               (lt (abs (minus (match_dup 0)
9346                               (plus (pc) (const_int 4))))
9347                   (const_int 131072)))
9348          (const_int 4) (const_int 16)))])
9349
9350 ;; We need a different insn for the mips16, because a mips16 branch
9351 ;; does not have a delay slot.
9352
9353 (define_insn ""
9354   [(set (pc)
9355         (label_ref (match_operand 0 "" "")))]
9356   "TARGET_MIPS16"
9357   "b\\t%l0"
9358   [(set_attr "type"     "branch")
9359    (set_attr "mode"     "none")
9360    (set_attr "length"   "8")])
9361
9362 (define_expand "indirect_jump"
9363   [(set (pc) (match_operand 0 "register_operand" "d"))]
9364   ""
9365   "
9366 {
9367   rtx dest;
9368
9369   if (operands[0])              /* eliminate unused code warnings */
9370     {
9371       dest = operands[0];
9372       if (GET_CODE (dest) != REG || GET_MODE (dest) != Pmode)
9373         operands[0] = copy_to_mode_reg (Pmode, dest);
9374
9375       if (!(Pmode == DImode))
9376         emit_jump_insn (gen_indirect_jump_internal1 (operands[0]));
9377       else
9378         emit_jump_insn (gen_indirect_jump_internal2 (operands[0]));
9379
9380       DONE;
9381     }
9382 }")
9383
9384 (define_insn "indirect_jump_internal1"
9385   [(set (pc) (match_operand:SI 0 "register_operand" "d"))]
9386   "!(Pmode == DImode)"
9387   "%*j\\t%0"
9388   [(set_attr "type"     "jump")
9389    (set_attr "mode"     "none")])
9390
9391 (define_insn "indirect_jump_internal2"
9392   [(set (pc) (match_operand:DI 0 "register_operand" "d"))]
9393   "Pmode == DImode"
9394   "%*j\\t%0"
9395   [(set_attr "type"     "jump")
9396    (set_attr "mode"     "none")])
9397
9398 (define_expand "tablejump"
9399   [(set (pc)
9400         (match_operand 0 "register_operand" "d"))
9401    (use (label_ref (match_operand 1 "" "")))]
9402   ""
9403   "
9404 {
9405   if (operands[0])              /* eliminate unused code warnings */
9406     {
9407       if (TARGET_MIPS16)
9408         {
9409           if (GET_MODE (operands[0]) != HImode)
9410             abort ();
9411           if (!(Pmode == DImode))
9412             emit_insn (gen_tablejump_mips161 (operands[0], operands[1]));
9413           else
9414             emit_insn (gen_tablejump_mips162 (operands[0], operands[1]));
9415           DONE;
9416         }
9417
9418       if (GET_MODE (operands[0]) != ptr_mode)
9419         abort ();
9420
9421       if (TARGET_GPWORD)
9422         operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
9423                                     pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
9424
9425       if (Pmode == SImode)
9426         emit_jump_insn (gen_tablejump_internal1 (operands[0], operands[1]));
9427       else
9428         emit_jump_insn (gen_tablejump_internal2 (operands[0], operands[1]));
9429       DONE;
9430     }
9431 }")
9432
9433 (define_insn "tablejump_internal1"
9434   [(set (pc)
9435         (match_operand:SI 0 "register_operand" "d"))
9436    (use (label_ref (match_operand 1 "" "")))]
9437   ""
9438   "%*j\\t%0"
9439   [(set_attr "type"     "jump")
9440    (set_attr "mode"     "none")])
9441
9442 (define_insn "tablejump_internal2"
9443   [(set (pc)
9444         (match_operand:DI 0 "register_operand" "d"))
9445    (use (label_ref (match_operand 1 "" "")))]
9446   "TARGET_64BIT"
9447   "%*j\\t%0"
9448   [(set_attr "type"     "jump")
9449    (set_attr "mode"     "none")])
9450
9451 (define_expand "tablejump_mips161"
9452   [(set (pc) (plus:SI (sign_extend:SI
9453                        (match_operand:HI 0 "register_operand" "d"))
9454                       (label_ref:SI (match_operand 1 "" ""))))]
9455   "TARGET_MIPS16 && !(Pmode == DImode)"
9456   "
9457 {
9458   if (operands[0])      /* eliminate unused code warnings.  */
9459     {
9460       rtx t1, t2, t3;
9461
9462       t1 = gen_reg_rtx (SImode);
9463       t2 = gen_reg_rtx (SImode);
9464       t3 = gen_reg_rtx (SImode);
9465       emit_insn (gen_extendhisi2 (t1, operands[0]));
9466       emit_move_insn (t2, gen_rtx_LABEL_REF (SImode, operands[1]));
9467       emit_insn (gen_addsi3 (t3, t1, t2));
9468       emit_jump_insn (gen_tablejump_internal1 (t3, operands[1]));
9469       DONE;
9470     }
9471 }")
9472
9473 (define_expand "tablejump_mips162"
9474   [(set (pc) (plus:DI (sign_extend:DI
9475                        (match_operand:HI 0 "register_operand" "d"))
9476                       (label_ref:DI (match_operand 1 "" ""))))]
9477   "TARGET_MIPS16 && Pmode == DImode"
9478   "
9479 {
9480   if (operands[0])      /* eliminate unused code warnings.  */
9481     {
9482       rtx t1, t2, t3;
9483
9484       t1 = gen_reg_rtx (DImode);
9485       t2 = gen_reg_rtx (DImode);
9486       t3 = gen_reg_rtx (DImode);
9487       emit_insn (gen_extendhidi2 (t1, operands[0]));
9488       emit_move_insn (t2, gen_rtx_LABEL_REF (DImode, operands[1]));
9489       emit_insn (gen_adddi3 (t3, t1, t2));
9490       emit_jump_insn (gen_tablejump_internal2 (t3, operands[1]));
9491       DONE;
9492     }
9493 }")
9494
9495 ;; Implement a switch statement when generating embedded PIC code.
9496 ;; Switches are implemented by `tablejump' when not using -membedded-pic.
9497
9498 (define_expand "casesi"
9499   [(set (match_dup 5)
9500         (minus:SI (match_operand:SI 0 "register_operand" "d")
9501                   (match_operand:SI 1 "arith_operand" "dI")))
9502    (set (cc0)
9503         (compare:CC (match_dup 5)
9504                     (match_operand:SI 2 "arith_operand" "")))
9505    (set (pc)
9506         (if_then_else (gtu (cc0)
9507                            (const_int 0))
9508                       (label_ref (match_operand 4 "" ""))
9509                       (pc)))
9510    (parallel
9511     [(set (pc)
9512           (mem:SI (plus:SI (mult:SI (match_dup 5)
9513                                     (const_int 4))
9514                            (label_ref (match_operand 3 "" "")))))
9515      (clobber (match_scratch:SI 6 ""))
9516      (clobber (reg:SI 31))])]
9517   "TARGET_EMBEDDED_PIC"
9518   "
9519 {
9520   if (operands[0])
9521     {
9522       rtx reg = gen_reg_rtx (SImode);
9523
9524       /* If the index is too large, go to the default label.  */
9525       emit_insn (gen_subsi3 (reg, operands[0], operands[1]));
9526       emit_insn (gen_cmpsi (reg, operands[2]));
9527       emit_insn (gen_bgtu (operands[4]));
9528
9529       /* Do the PIC jump.  */
9530       if (Pmode != DImode)
9531         emit_jump_insn (gen_casesi_internal (reg, operands[3],
9532                                              gen_reg_rtx (SImode)));
9533       else
9534         emit_jump_insn (gen_casesi_internal_di (reg, operands[3],
9535                                                 gen_reg_rtx (DImode)));
9536
9537       DONE;
9538     }
9539 }")
9540
9541 ;; An embedded PIC switch statement looks like this:
9542 ;;      bal     $LS1
9543 ;;      sll     $reg,$index,2
9544 ;; $LS1:
9545 ;;      addu    $reg,$reg,$31
9546 ;;      lw      $reg,$L1-$LS1($reg)
9547 ;;      addu    $reg,$reg,$31
9548 ;;      j       $reg
9549 ;; $L1:
9550 ;;      .word   case1-$LS1
9551 ;;      .word   case2-$LS1
9552 ;;      ...
9553
9554 (define_insn "casesi_internal"
9555   [(set (pc)
9556         (mem:SI (plus:SI (mult:SI (match_operand:SI 0 "register_operand" "d")
9557                                   (const_int 4))
9558                          (label_ref (match_operand 1 "" "")))))
9559    (clobber (match_operand:SI 2 "register_operand" "=d"))
9560    (clobber (reg:SI 31))]
9561   "TARGET_EMBEDDED_PIC"
9562   "%(bal\\t%S1\;sll\\t%2,%0,2\\n%~%S1:\;addu\\t%2,%2,$31%)\;\\
9563 lw\\t%2,%1-%S1(%2)\;addu\\t%2,%2,$31\\n\\t%*j\\t%2"
9564   [(set_attr "type"     "jump")
9565    (set_attr "mode"     "none")
9566    (set_attr "length"   "24")])
9567
9568 ;; This code assumes that the table index will never be >= 29 bits wide,
9569 ;; which allows the 'sign extend' from SI to DI be a no-op.
9570 (define_insn "casesi_internal_di"
9571   [(set (pc)
9572         (mem:DI (plus:DI (sign_extend:DI
9573                           (mult:SI (match_operand:SI 0 "register_operand" "d")
9574                                   (const_int 8)))
9575                          (label_ref (match_operand 1 "" "")))))
9576    (clobber (match_operand:DI 2 "register_operand" "=d"))
9577    (clobber (reg:DI 31))]
9578   "TARGET_EMBEDDED_PIC"
9579   "%(bal\\t%S1\;sll\\t%2,%0,3\\n%~%S1:\;daddu\\t%2,%2,$31%)\;\\
9580 ld\\t%2,%1-%S1(%2)\;daddu\\t%2,%2,$31\\n\\t%*j\\t%2"
9581   [(set_attr "type"     "jump")
9582    (set_attr "mode"     "none")
9583    (set_attr "length"   "24")])
9584
9585 ;; For o32/n32/n64, we save the gp in the jmp_buf as well.  While it is
9586 ;; possible to either pull it off the stack (in the o32 case) or recalculate
9587 ;; it given t9 and our target label, it takes 3 or 4 insns to do so, and
9588 ;; this is easy.
9589
9590 (define_expand "builtin_setjmp_setup"
9591   [(unspec [(match_operand 0 "register_operand" "r")] UNSPEC_SETJMP)]
9592   "TARGET_ABICALLS"
9593   "
9594 {
9595   if (Pmode == DImode)
9596     emit_insn (gen_builtin_setjmp_setup_64 (operands[0]));
9597   else
9598     emit_insn (gen_builtin_setjmp_setup_32 (operands[0]));
9599   DONE;
9600 }")
9601
9602 (define_expand "builtin_setjmp_setup_32"
9603   [(set (mem:SI (plus:SI (match_operand:SI 0 "register_operand" "r")
9604                    (const_int 12)))
9605       (reg:SI 28))]
9606   "TARGET_ABICALLS && ! (Pmode == DImode)"
9607   "")
9608
9609 (define_expand "builtin_setjmp_setup_64"
9610   [(set (mem:DI (plus:DI (match_operand:DI 0 "register_operand" "r")
9611                    (const_int 24)))
9612       (reg:DI 28))]
9613   "TARGET_ABICALLS && Pmode == DImode"
9614   "")
9615
9616 ;; For o32/n32/n64, we need to arrange for longjmp to put the
9617 ;; target address in t9 so that we can use it for loading $gp.
9618
9619 (define_expand "builtin_longjmp"
9620   [(unspec_volatile [(match_operand 0 "register_operand" "r")] UNSPEC_LONGJMP)]
9621   "TARGET_ABICALLS"
9622   "
9623 {
9624   /* The elements of the buffer are, in order:  */
9625   int W = (Pmode == DImode ? 8 : 4);
9626   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
9627   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
9628   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
9629   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
9630   rtx pv = gen_rtx_REG (Pmode, 25);
9631   rtx gp = gen_rtx_REG (Pmode, 28);
9632
9633   /* This bit is the same as expand_builtin_longjmp.  */
9634   emit_move_insn (hard_frame_pointer_rtx, fp);
9635   emit_move_insn (pv, lab);
9636   emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
9637   emit_move_insn (gp, gpv);
9638   emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
9639   emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
9640   emit_insn (gen_rtx_USE (VOIDmode, gp));
9641   emit_indirect_jump (pv);
9642   DONE;
9643 }")
9644 \f
9645 ;;
9646 ;;  ....................
9647 ;;
9648 ;;      Function prologue/epilogue
9649 ;;
9650 ;;  ....................
9651 ;;
9652
9653 (define_expand "prologue"
9654   [(const_int 1)]
9655   ""
9656   "
9657 {
9658   if (mips_isa >= 0)            /* avoid unused code warnings */
9659     {
9660       mips_expand_prologue ();
9661       DONE;
9662     }
9663 }")
9664
9665 ;; Block any insns from being moved before this point, since the
9666 ;; profiling call to mcount can use various registers that aren't
9667 ;; saved or used to pass arguments.
9668
9669 (define_insn "blockage"
9670   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
9671   ""
9672   ""
9673   [(set_attr "type"     "unknown")
9674    (set_attr "mode"     "none")
9675    (set_attr "length"   "0")])
9676
9677 (define_expand "epilogue"
9678   [(const_int 2)]
9679   ""
9680 {
9681   mips_expand_epilogue (false);
9682   DONE;
9683 })
9684
9685 (define_expand "sibcall_epilogue"
9686   [(const_int 2)]
9687   ""
9688 {
9689   mips_expand_epilogue (true);
9690   DONE;
9691 })
9692
9693 ;; Trivial return.  Make it look like a normal return insn as that
9694 ;; allows jump optimizations to work better .
9695 (define_insn "return"
9696   [(return)]
9697   "mips_can_use_return_insn ()"
9698   "%*j\\t$31"
9699   [(set_attr "type"     "jump")
9700    (set_attr "mode"     "none")])
9701
9702 ;; Normal return.
9703
9704 (define_insn "return_internal"
9705   [(use (match_operand 0 "pmode_register_operand" ""))
9706    (return)]
9707   ""
9708   "*
9709 {
9710   return \"%*j\\t%0\";
9711 }"
9712   [(set_attr "type"     "jump")
9713    (set_attr "mode"     "none")])
9714
9715 ;; When generating embedded PIC code we need to get the address of the
9716 ;; current function.  This specialized instruction does just that.
9717
9718 (define_insn "get_fnaddr"
9719   [(set (match_operand 0 "register_operand" "=d")
9720         (unspec [(match_operand 1 "" "")] UNSPEC_GET_FNADDR))
9721    (clobber (reg:SI 31))]
9722   "TARGET_EMBEDDED_PIC
9723    && GET_CODE (operands[1]) == SYMBOL_REF"
9724   "%($LF%= = . + 8\;bal\\t$LF%=\;nop;la\\t%0,%1-$LF%=%)\;addu\\t%0,%0,$31"
9725   [(set_attr "type"     "call")
9726    (set_attr "mode"     "none")
9727    (set_attr "length"   "20")])
9728
9729 ;; This is used in compiling the unwind routines.
9730 (define_expand "eh_return"
9731   [(use (match_operand 0 "general_operand" ""))]
9732   ""
9733   "
9734 {
9735   enum machine_mode gpr_mode = TARGET_64BIT ? DImode : SImode;
9736
9737   if (GET_MODE (operands[0]) != gpr_mode)
9738     operands[0] = convert_to_mode (gpr_mode, operands[0], 0);
9739   if (TARGET_64BIT)
9740     emit_insn (gen_eh_set_lr_di (operands[0]));
9741   else
9742     emit_insn (gen_eh_set_lr_si (operands[0]));
9743
9744   DONE;
9745 }")
9746
9747 ;; Clobber the return address on the stack.  We can't expand this
9748 ;; until we know where it will be put in the stack frame.
9749
9750 (define_insn "eh_set_lr_si"
9751   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
9752    (clobber (match_scratch:SI 1 "=&d"))]
9753   "! TARGET_64BIT"
9754   "#")
9755
9756 (define_insn "eh_set_lr_di"
9757   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
9758    (clobber (match_scratch:DI 1 "=&d"))]
9759   "TARGET_64BIT"
9760   "#")
9761
9762 (define_split
9763   [(unspec [(match_operand 0 "register_operand" "")] UNSPEC_EH_RETURN)
9764    (clobber (match_scratch 1 ""))]
9765   "reload_completed && !TARGET_DEBUG_D_MODE"
9766   [(const_int 0)]
9767   "
9768 {
9769   mips_set_return_address (operands[0], operands[1]);
9770   DONE;
9771 }")
9772
9773 (define_insn "exception_receiver"
9774   [(unspec_volatile [(const_int 0)] UNSPEC_EH_RECEIVER)]
9775   "TARGET_ABICALLS && (mips_abi == ABI_32 || mips_abi == ABI_O64)"
9776   { return mips_restore_gp (operands); }
9777   [(set_attr "type"   "load")
9778    (set_attr "length" "8")])
9779 \f
9780 ;;
9781 ;;  ....................
9782 ;;
9783 ;;      FUNCTION CALLS
9784 ;;
9785 ;;  ....................
9786
9787 ;; Sibling calls.  All these patterns use direct jumps.
9788
9789 ;; call_insn_operand will only accepts constant addresses if a direct
9790 ;; jump is acceptable.  Since the 'S' constraint is defined in terms of
9791 ;; call_insn_operand, the same is true of the contraints.
9792
9793 ;; When we use an indirect jump, we need a register that will be
9794 ;; preserved by the epilogue.  Since TARGET_ABICALLS forces us to
9795 ;; use $25 for this purpose -- and $25 is never clobbered by the
9796 ;; epilogue -- we might as well use it for !TARGET_ABICALLS as well.
9797
9798 (define_expand "sibcall"
9799   [(parallel [(call (match_operand 0 "" "")
9800                     (match_operand 1 "" ""))
9801               (use (match_operand 2 "" ""))     ;; next_arg_reg
9802               (use (match_operand 3 "" ""))])]  ;; struct_value_size_rtx
9803   "TARGET_SIBCALLS"
9804 {
9805   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
9806   DONE;
9807 })
9808
9809 (define_insn "sibcall_internal"
9810   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
9811          (match_operand 1 "" ""))]
9812   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
9813   "@
9814     %*jr\\t%0
9815     %*j\\t%0"
9816   [(set_attr "type" "call")])
9817
9818 (define_expand "sibcall_value"
9819   [(parallel [(set (match_operand 0 "" "")
9820                    (call (match_operand 1 "" "")
9821                          (match_operand 2 "" "")))
9822               (use (match_operand 3 "" ""))])]          ;; next_arg_reg
9823   "TARGET_SIBCALLS"
9824 {
9825   mips_expand_call (operands[0], XEXP (operands[1], 0),
9826                     operands[2], operands[3], true);
9827   DONE;
9828 })
9829
9830 (define_insn "sibcall_value_internal"
9831   [(set (match_operand 0 "register_operand" "=df,df")
9832         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
9833               (match_operand 2 "" "")))]
9834   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
9835   "@
9836     %*jr\\t%1
9837     %*j\\t%1"
9838   [(set_attr "type" "call")])
9839
9840 (define_insn "sibcall_value_multiple_internal"
9841   [(set (match_operand 0 "register_operand" "=df,df")
9842         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
9843               (match_operand 2 "" "")))
9844    (set (match_operand 3 "register_operand" "=df,df")
9845         (call (mem:SI (match_dup 1))
9846               (match_dup 2)))]
9847   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
9848   "@
9849     %*jr\\t%1
9850     %*j\\t%1"
9851   [(set_attr "type" "call")])
9852
9853 (define_expand "call"
9854   [(parallel [(call (match_operand 0 "" "")
9855                     (match_operand 1 "" ""))
9856               (use (match_operand 2 "" ""))     ;; next_arg_reg
9857               (use (match_operand 3 "" ""))])]  ;; struct_value_size_rtx
9858   ""
9859 {
9860   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
9861   DONE;
9862 })
9863
9864 (define_insn_and_split "call_internal"
9865   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
9866          (match_operand 1 "" ""))
9867    (clobber (reg:SI 31))]
9868   ""
9869   "%*jal\\t%0"
9870   "reload_completed && TARGET_SPLIT_CALLS"
9871   [(const_int 0)]
9872   {
9873     emit_call_insn (gen_call_split (operands[0], operands[1]));
9874     emit_insn (gen_exception_receiver ());
9875     DONE;
9876   }
9877   [(set_attr "jal" "indirect,direct")
9878    (set_attr "extended_mips16" "no,yes")])
9879
9880 (define_insn "call_split"
9881   [(call (mem:SI (match_operand 0 "call_insn_operand" "c"))
9882          (match_operand 1 "" ""))
9883    (clobber (reg:SI 31))
9884    (const_int 1)]
9885   "TARGET_SPLIT_CALLS"
9886   "%*jalr\\t%0"
9887   [(set_attr "type" "call")])
9888
9889 (define_expand "call_value"
9890   [(parallel [(set (match_operand 0 "" "")
9891                    (call (match_operand 1 "" "")
9892                          (match_operand 2 "" "")))
9893               (use (match_operand 3 "" ""))])]          ;; next_arg_reg
9894   ""
9895 {
9896   mips_expand_call (operands[0], XEXP (operands[1], 0),
9897                     operands[2], operands[3], false);
9898   DONE;
9899 })
9900
9901 (define_insn_and_split "call_value_internal"
9902   [(set (match_operand 0 "register_operand" "=df,df")
9903         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
9904               (match_operand 2 "" "")))
9905    (clobber (reg:SI 31))]
9906   ""
9907   "%*jal\\t%1"
9908   "reload_completed && TARGET_SPLIT_CALLS"
9909   [(const_int 0)]
9910   {
9911     emit_call_insn (gen_call_value_split (operands[0], operands[1],
9912                                           operands[2]));
9913     emit_insn (gen_exception_receiver ());
9914     DONE;
9915   }
9916   [(set_attr "jal" "indirect,direct")
9917    (set_attr "extended_mips16" "no,yes")])
9918
9919 (define_insn "call_value_split"
9920   [(set (match_operand 0 "register_operand" "=df")
9921         (call (mem:SI (match_operand 1 "call_insn_operand" "c"))
9922               (match_operand 2 "" "")))
9923    (clobber (reg:SI 31))
9924    (const_int 1)]
9925   "TARGET_SPLIT_CALLS"
9926   "%*jalr\\t%1"
9927   [(set_attr "type" "call")])
9928
9929 (define_insn_and_split "call_value_multiple_internal"
9930   [(set (match_operand 0 "register_operand" "=df,df")
9931         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
9932               (match_operand 2 "" "")))
9933    (set (match_operand 3 "register_operand" "=df,df")
9934         (call (mem:SI (match_dup 1))
9935               (match_dup 2)))
9936    (clobber (reg:SI 31))]
9937   ""
9938   "%*jal\\t%1"
9939   "reload_completed && TARGET_SPLIT_CALLS"
9940   [(const_int 0)]
9941   {
9942     emit_call_insn (gen_call_value_multiple_split (operands[0], operands[1],
9943                                                    operands[2], operands[3]));
9944     emit_insn (gen_exception_receiver ());
9945     DONE;
9946   }
9947   [(set_attr "jal" "indirect,direct")
9948    (set_attr "extended_mips16" "no,yes")])
9949
9950 (define_insn "call_value_multiple_split"
9951   [(set (match_operand 0 "register_operand" "=df")
9952         (call (mem:SI (match_operand 1 "call_insn_operand" "c"))
9953               (match_operand 2 "" "")))
9954    (set (match_operand 3 "register_operand" "=df")
9955         (call (mem:SI (match_dup 1))
9956               (match_dup 2)))
9957    (clobber (reg:SI 31))
9958    (const_int 1)]
9959   "TARGET_SPLIT_CALLS"
9960   "%*jalr\\t%1"
9961   [(set_attr "type" "call")])
9962
9963 ;; Call subroutine returning any type.
9964
9965 (define_expand "untyped_call"
9966   [(parallel [(call (match_operand 0 "" "")
9967                     (const_int 0))
9968               (match_operand 1 "" "")
9969               (match_operand 2 "" "")])]
9970   ""
9971   "
9972 {
9973   int i;
9974
9975   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
9976
9977   for (i = 0; i < XVECLEN (operands[2], 0); i++)
9978     {
9979       rtx set = XVECEXP (operands[2], 0, i);
9980       emit_move_insn (SET_DEST (set), SET_SRC (set));
9981     }
9982
9983   emit_insn (gen_blockage ());
9984   DONE;
9985 }")
9986 \f
9987 ;;
9988 ;;  ....................
9989 ;;
9990 ;;      MISC.
9991 ;;
9992 ;;  ....................
9993 ;;
9994
9995
9996 (define_expand "prefetch"
9997   [(prefetch (match_operand 0 "address_operand" "")
9998              (match_operand 1 "const_int_operand" "")
9999              (match_operand 2 "const_int_operand" ""))]
10000   "ISA_HAS_PREFETCH"
10001 {
10002   if (symbolic_operand (operands[0], GET_MODE (operands[0])))
10003     operands[0] = force_reg (GET_MODE (operands[0]), operands[0]);
10004 })
10005
10006 (define_insn "prefetch_si_address"
10007   [(prefetch (plus:SI (match_operand:SI 0 "register_operand" "r")
10008                       (match_operand:SI 3 "const_int_operand" "i"))
10009              (match_operand:SI 1 "const_int_operand" "n")
10010              (match_operand:SI 2 "const_int_operand" "n"))]
10011   "ISA_HAS_PREFETCH && Pmode == SImode"
10012   "* return mips_emit_prefetch (operands);"
10013   [(set_attr "type" "prefetch")])
10014
10015 (define_insn "prefetch_si"
10016   [(prefetch (match_operand:SI 0 "register_operand" "r")
10017              (match_operand:SI 1 "const_int_operand" "n")
10018              (match_operand:SI 2 "const_int_operand" "n"))]
10019   "ISA_HAS_PREFETCH && Pmode == SImode"
10020   "* return mips_emit_prefetch (operands);"
10021   [(set_attr "type" "prefetch")])
10022
10023 (define_insn "prefetch_di_address"
10024   [(prefetch (plus:DI (match_operand:DI 0 "register_operand" "r")
10025                       (match_operand:DI 3 "const_int_operand" "i"))
10026              (match_operand:DI 1 "const_int_operand" "n")
10027              (match_operand:DI 2 "const_int_operand" "n"))]
10028   "ISA_HAS_PREFETCH && Pmode == DImode"
10029   "* return mips_emit_prefetch (operands);"
10030   [(set_attr "type" "prefetch")])
10031
10032 (define_insn "prefetch_di"
10033   [(prefetch (match_operand:DI 0 "register_operand" "r")
10034              (match_operand:DI 1 "const_int_operand" "n")
10035              (match_operand:DI 2 "const_int_operand" "n"))]
10036   "ISA_HAS_PREFETCH && Pmode == DImode"
10037   "* return mips_emit_prefetch (operands);"
10038   [(set_attr "type" "prefetch")])
10039
10040 (define_insn "nop"
10041   [(const_int 0)]
10042   ""
10043   "%(nop%)"
10044   [(set_attr "type"     "nop")
10045    (set_attr "mode"     "none")])
10046
10047 ;; The MIPS chip does not seem to require stack probes.
10048 ;;
10049 ;; (define_expand "probe"
10050 ;;   [(set (match_dup 0)
10051 ;;      (match_dup 1))]
10052 ;;   ""
10053 ;;   "
10054 ;; {
10055 ;;   operands[0] = gen_reg_rtx (SImode);
10056 ;;   operands[1] = gen_rtx_MEM (SImode, stack_pointer_rtx);
10057 ;;   MEM_VOLATILE_P (operands[1]) = TRUE;
10058 ;;
10059 ;;   /* fall through and generate default code */
10060 ;; }")
10061 ;;
10062 \f
10063 ;;
10064 ;; MIPS4 Conditional move instructions.
10065
10066 (define_insn ""
10067   [(set (match_operand:SI 0 "register_operand" "=d,d")
10068         (if_then_else:SI
10069          (match_operator 4 "equality_op"
10070                          [(match_operand:SI 1 "register_operand" "d,d")
10071                           (const_int 0)])
10072          (match_operand:SI 2 "reg_or_0_operand" "dJ,0")
10073          (match_operand:SI 3 "reg_or_0_operand" "0,dJ")))]
10074   "ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE"
10075   "@
10076     mov%B4\\t%0,%z2,%1
10077     mov%b4\\t%0,%z3,%1"
10078   [(set_attr "type" "move")
10079    (set_attr "mode" "SI")])
10080
10081 (define_insn ""
10082   [(set (match_operand:SI 0 "register_operand" "=d,d")
10083         (if_then_else:SI
10084          (match_operator 4 "equality_op"
10085                          [(match_operand:DI 1 "register_operand" "d,d")
10086                           (const_int 0)])
10087          (match_operand:SI 2 "reg_or_0_operand" "dJ,0")
10088          (match_operand:SI 3 "reg_or_0_operand" "0,dJ")))]
10089   "ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE"
10090   "@
10091     mov%B4\\t%0,%z2,%1
10092     mov%b4\\t%0,%z3,%1"
10093   [(set_attr "type" "move")
10094    (set_attr "mode" "SI")])
10095
10096 (define_insn ""
10097   [(set (match_operand:SI 0 "register_operand" "=d,d")
10098         (if_then_else:SI
10099          (match_operator 3 "equality_op" [(match_operand:CC 4
10100                                                             "register_operand"
10101                                                             "z,z")
10102                                           (const_int 0)])
10103          (match_operand:SI 1 "reg_or_0_operand" "dJ,0")
10104          (match_operand:SI 2 "reg_or_0_operand" "0,dJ")))]
10105   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
10106   "@
10107     mov%T3\\t%0,%z1,%4
10108     mov%t3\\t%0,%z2,%4"
10109   [(set_attr "type" "move")
10110    (set_attr "mode" "SI")])
10111
10112 (define_insn ""
10113   [(set (match_operand:DI 0 "register_operand" "=d,d")
10114         (if_then_else:DI
10115          (match_operator 4 "equality_op"
10116                          [(match_operand:SI 1 "register_operand" "d,d")
10117                           (const_int 0)])
10118          (match_operand:DI 2 "reg_or_0_operand" "dJ,0")
10119          (match_operand:DI 3 "reg_or_0_operand" "0,dJ")))]
10120   "(ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE) && TARGET_64BIT"
10121   "@
10122     mov%B4\\t%0,%z2,%1
10123     mov%b4\\t%0,%z3,%1"
10124   [(set_attr "type" "move")
10125    (set_attr "mode" "DI")])
10126
10127 (define_insn ""
10128   [(set (match_operand:DI 0 "register_operand" "=d,d")
10129         (if_then_else:DI
10130          (match_operator 4 "equality_op"
10131                          [(match_operand:DI 1 "register_operand" "d,d")
10132                           (const_int 0)])
10133          (match_operand:DI 2 "reg_or_0_operand" "dJ,0")
10134          (match_operand:DI 3 "reg_or_0_operand" "0,dJ")))]
10135   "(ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE) && TARGET_64BIT"
10136   "@
10137     mov%B4\\t%0,%z2,%1
10138     mov%b4\\t%0,%z3,%1"
10139   [(set_attr "type" "move")
10140    (set_attr "mode" "DI")])
10141
10142 (define_insn ""
10143   [(set (match_operand:DI 0 "register_operand" "=d,d")
10144         (if_then_else:DI
10145          (match_operator 3 "equality_op" [(match_operand:CC 4
10146                                                             "register_operand"
10147                                                             "z,z")
10148                                           (const_int 0)])
10149          (match_operand:DI 1 "reg_or_0_operand" "dJ,0")
10150          (match_operand:DI 2 "reg_or_0_operand" "0,dJ")))]
10151   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_64BIT"
10152   "@
10153     mov%T3\\t%0,%z1,%4
10154     mov%t3\\t%0,%z2,%4"
10155   [(set_attr "type" "move")
10156    (set_attr "mode" "DI")])
10157
10158 (define_insn ""
10159   [(set (match_operand:SF 0 "register_operand" "=f,f")
10160         (if_then_else:SF
10161          (match_operator 4 "equality_op"
10162                          [(match_operand:SI 1 "register_operand" "d,d")
10163                           (const_int 0)])
10164          (match_operand:SF 2 "register_operand" "f,0")
10165          (match_operand:SF 3 "register_operand" "0,f")))]
10166   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
10167   "@
10168     mov%B4.s\\t%0,%2,%1
10169     mov%b4.s\\t%0,%3,%1"
10170   [(set_attr "type" "move")
10171    (set_attr "mode" "SF")])
10172
10173 (define_insn ""
10174   [(set (match_operand:SF 0 "register_operand" "=f,f")
10175         (if_then_else:SF
10176          (match_operator 4 "equality_op"
10177                          [(match_operand:DI 1 "register_operand" "d,d")
10178                           (const_int 0)])
10179          (match_operand:SF 2 "register_operand" "f,0")
10180          (match_operand:SF 3 "register_operand" "0,f")))]
10181   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
10182   "@
10183     mov%B4.s\\t%0,%2,%1
10184     mov%b4.s\\t%0,%3,%1"
10185   [(set_attr "type" "move")
10186    (set_attr "mode" "SF")])
10187
10188 (define_insn ""
10189   [(set (match_operand:SF 0 "register_operand" "=f,f")
10190         (if_then_else:SF
10191          (match_operator 3 "equality_op" [(match_operand:CC 4
10192                                                             "register_operand"
10193                                                             "z,z")
10194                                           (const_int 0)])
10195          (match_operand:SF 1 "register_operand" "f,0")
10196          (match_operand:SF 2 "register_operand" "0,f")))]
10197   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
10198   "@
10199     mov%T3.s\\t%0,%1,%4
10200     mov%t3.s\\t%0,%2,%4"
10201   [(set_attr "type" "move")
10202    (set_attr "mode" "SF")])
10203
10204 (define_insn ""
10205   [(set (match_operand:DF 0 "register_operand" "=f,f")
10206         (if_then_else:DF
10207          (match_operator 4 "equality_op"
10208                          [(match_operand:SI 1 "register_operand" "d,d")
10209                           (const_int 0)])
10210          (match_operand:DF 2 "register_operand" "f,0")
10211          (match_operand:DF 3 "register_operand" "0,f")))]
10212   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
10213   "@
10214     mov%B4.d\\t%0,%2,%1
10215     mov%b4.d\\t%0,%3,%1"
10216   [(set_attr "type" "move")
10217    (set_attr "mode" "DF")])
10218
10219 (define_insn ""
10220   [(set (match_operand:DF 0 "register_operand" "=f,f")
10221         (if_then_else:DF
10222          (match_operator 4 "equality_op"
10223                          [(match_operand:DI 1 "register_operand" "d,d")
10224                           (const_int 0)])
10225          (match_operand:DF 2 "register_operand" "f,0")
10226          (match_operand:DF 3 "register_operand" "0,f")))]
10227   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
10228   "@
10229     mov%B4.d\\t%0,%2,%1
10230     mov%b4.d\\t%0,%3,%1"
10231   [(set_attr "type" "move")
10232    (set_attr "mode" "DF")])
10233
10234 (define_insn ""
10235   [(set (match_operand:DF 0 "register_operand" "=f,f")
10236         (if_then_else:DF
10237          (match_operator 3 "equality_op" [(match_operand:CC 4
10238                                                             "register_operand"
10239                                                             "z,z")
10240                                           (const_int 0)])
10241          (match_operand:DF 1 "register_operand" "f,0")
10242          (match_operand:DF 2 "register_operand" "0,f")))]
10243   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
10244   "@
10245     mov%T3.d\\t%0,%1,%4
10246     mov%t3.d\\t%0,%2,%4"
10247   [(set_attr "type" "move")
10248    (set_attr "mode" "DF")])
10249
10250 ;; These are the main define_expand's used to make conditional moves.
10251
10252 (define_expand "movsicc"
10253   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
10254    (set (match_operand:SI 0 "register_operand" "")
10255         (if_then_else:SI (match_dup 5)
10256                          (match_operand:SI 2 "reg_or_0_operand" "")
10257                          (match_operand:SI 3 "reg_or_0_operand" "")))]
10258   "ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE"
10259   "
10260 {
10261   gen_conditional_move (operands);
10262   DONE;
10263 }")
10264
10265 (define_expand "movdicc"
10266   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
10267    (set (match_operand:DI 0 "register_operand" "")
10268         (if_then_else:DI (match_dup 5)
10269                          (match_operand:DI 2 "reg_or_0_operand" "")
10270                          (match_operand:DI 3 "reg_or_0_operand" "")))]
10271   "(ISA_HAS_CONDMOVE || ISA_HAS_INT_CONDMOVE) && TARGET_64BIT"
10272   "
10273 {
10274   gen_conditional_move (operands);
10275   DONE;
10276 }")
10277
10278 (define_expand "movsfcc"
10279   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
10280    (set (match_operand:SF 0 "register_operand" "")
10281         (if_then_else:SF (match_dup 5)
10282                          (match_operand:SF 2 "register_operand" "")
10283                          (match_operand:SF 3 "register_operand" "")))]
10284   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT"
10285   "
10286 {
10287   gen_conditional_move (operands);
10288   DONE;
10289 }")
10290
10291 (define_expand "movdfcc"
10292   [(set (match_dup 4) (match_operand 1 "comparison_operator" ""))
10293    (set (match_operand:DF 0 "register_operand" "")
10294         (if_then_else:DF (match_dup 5)
10295                          (match_operand:DF 2 "register_operand" "")
10296                          (match_operand:DF 3 "register_operand" "")))]
10297   "ISA_HAS_CONDMOVE && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
10298   "
10299 {
10300   gen_conditional_move (operands);
10301   DONE;
10302 }")
10303 \f
10304 ;;
10305 ;;  ....................
10306 ;;
10307 ;;      mips16 inline constant tables
10308 ;;
10309 ;;  ....................
10310 ;;
10311
10312 (define_insn "consttable_qi"
10313   [(unspec_volatile [(match_operand:QI 0 "consttable_operand" "=g")]
10314                     UNSPEC_CONSTTABLE_QI)]
10315   "TARGET_MIPS16"
10316   "*
10317 {
10318   assemble_integer (operands[0], 1, BITS_PER_UNIT, 1);
10319   return \"\";
10320 }"
10321   [(set_attr "type"     "unknown")
10322    (set_attr "mode"     "QI")
10323    (set_attr "length"   "8")])
10324
10325 (define_insn "consttable_hi"
10326   [(unspec_volatile [(match_operand:HI 0 "consttable_operand" "=g")]
10327                     UNSPEC_CONSTTABLE_HI)]
10328   "TARGET_MIPS16"
10329   "*
10330 {
10331   assemble_integer (operands[0], 2, BITS_PER_UNIT * 2, 1);
10332   return \"\";
10333 }"
10334   [(set_attr "type"     "unknown")
10335    (set_attr "mode"     "HI")
10336    (set_attr "length"   "8")])
10337
10338 (define_insn "consttable_si"
10339   [(unspec_volatile [(match_operand:SI 0 "consttable_operand" "=g")]
10340                     UNSPEC_CONSTTABLE_SI)]
10341   "TARGET_MIPS16"
10342   "*
10343 {
10344   assemble_integer (operands[0], 4, BITS_PER_UNIT * 4, 1);
10345   return \"\";
10346 }"
10347   [(set_attr "type"     "unknown")
10348    (set_attr "mode"     "SI")
10349    (set_attr "length"   "8")])
10350
10351 (define_insn "consttable_di"
10352   [(unspec_volatile [(match_operand:DI 0 "consttable_operand" "=g")]
10353                     UNSPEC_CONSTTABLE_DI)]
10354   "TARGET_MIPS16"
10355   "*
10356 {
10357   assemble_integer (operands[0], 8, BITS_PER_UNIT * 8, 1);
10358   return \"\";
10359 }"
10360   [(set_attr "type"     "unknown")
10361    (set_attr "mode"     "DI")
10362    (set_attr "length"   "16")])
10363
10364 (define_insn "consttable_sf"
10365   [(unspec_volatile [(match_operand:SF 0 "consttable_operand" "=g")]
10366                     UNSPEC_CONSTTABLE_SF)]
10367   "TARGET_MIPS16"
10368   "*
10369 {
10370   REAL_VALUE_TYPE d;
10371
10372   if (GET_CODE (operands[0]) != CONST_DOUBLE)
10373     abort ();
10374   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
10375   assemble_real (d, SFmode, GET_MODE_ALIGNMENT (SFmode));
10376   return \"\";
10377 }"
10378   [(set_attr "type"     "unknown")
10379    (set_attr "mode"     "SF")
10380    (set_attr "length"   "8")])
10381
10382 (define_insn "consttable_df"
10383   [(unspec_volatile [(match_operand:DF 0 "consttable_operand" "=g")]
10384                     UNSPEC_CONSTTABLE_DF)]
10385   "TARGET_MIPS16"
10386   "*
10387 {
10388   REAL_VALUE_TYPE d;
10389
10390   if (GET_CODE (operands[0]) != CONST_DOUBLE)
10391     abort ();
10392   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
10393   assemble_real (d, DFmode, GET_MODE_ALIGNMENT (DFmode));
10394   return \"\";
10395 }"
10396   [(set_attr "type"     "unknown")
10397    (set_attr "mode"     "DF")
10398    (set_attr "length"   "16")])
10399
10400 (define_insn "align_2"
10401   [(unspec_volatile [(const_int 0)] UNSPEC_ALIGN_2)]
10402   "TARGET_MIPS16"
10403   ".align 1"
10404   [(set_attr "type"     "unknown")
10405    (set_attr "mode"     "HI")
10406    (set_attr "length"   "8")])
10407
10408 (define_insn "align_4"
10409   [(unspec_volatile [(const_int 0)] UNSPEC_ALIGN_4)]
10410   "TARGET_MIPS16"
10411   ".align 2"
10412   [(set_attr "type"     "unknown")
10413    (set_attr "mode"     "SI")
10414    (set_attr "length"   "8")])
10415
10416 (define_insn "align_8"
10417   [(unspec_volatile [(const_int 0)] UNSPEC_ALIGN_8)]
10418   "TARGET_MIPS16"
10419   ".align 3"
10420   [(set_attr "type"     "unknown")
10421    (set_attr "mode"     "DI")
10422    (set_attr "length"   "12")])
10423 \f
10424 ;;
10425 ;;  ....................
10426 ;;
10427 ;;      mips16 peepholes
10428 ;;
10429 ;;  ....................
10430 ;;
10431
10432 ;; On the mips16, reload will sometimes decide that a pseudo register
10433 ;; should go into $24, and then later on have to reload that register.
10434 ;; When that happens, we get a load of a general register followed by
10435 ;; a move from the general register to $24 followed by a branch.
10436 ;; These peepholes catch the common case, and fix it to just use the
10437 ;; general register for the branch.
10438
10439 (define_peephole
10440   [(set (match_operand:SI 0 "register_operand" "=t")
10441         (match_operand:SI 1 "register_operand" "d"))
10442    (set (pc)
10443         (if_then_else (match_operator:SI 2 "equality_op" [(match_dup 0)
10444                                                           (const_int 0)])
10445                       (match_operand 3 "pc_or_label_operand" "")
10446                       (match_operand 4 "pc_or_label_operand" "")))]
10447   "TARGET_MIPS16
10448    && GET_CODE (operands[0]) == REG
10449    && REGNO (operands[0]) == 24
10450    && dead_or_set_p (insn, operands[0])
10451    && GET_CODE (operands[1]) == REG
10452    && M16_REG_P (REGNO (operands[1]))"
10453   "*
10454 {
10455   if (operands[3] != pc_rtx)
10456     return \"%*b%C2z\\t%1,%3\";
10457   else
10458     return \"%*b%N2z\\t%1,%4\";
10459 }"
10460   [(set_attr "type"     "branch")
10461    (set_attr "mode"     "none")
10462    (set_attr "length"   "8")])
10463
10464 (define_peephole
10465   [(set (match_operand:DI 0 "register_operand" "=t")
10466         (match_operand:DI 1 "register_operand" "d"))
10467    (set (pc)
10468         (if_then_else (match_operator:DI 2 "equality_op" [(match_dup 0)
10469                                                           (const_int 0)])
10470                       (match_operand 3 "pc_or_label_operand" "")
10471                       (match_operand 4 "pc_or_label_operand" "")))]
10472   "TARGET_MIPS16 && TARGET_64BIT
10473    && GET_CODE (operands[0]) == REG
10474    && REGNO (operands[0]) == 24
10475    && dead_or_set_p (insn, operands[0])
10476    && GET_CODE (operands[1]) == REG
10477    && M16_REG_P (REGNO (operands[1]))"
10478   "*
10479 {
10480   if (operands[3] != pc_rtx)
10481     return \"%*b%C2z\\t%1,%3\";
10482   else
10483     return \"%*b%N2z\\t%1,%4\";
10484 }"
10485   [(set_attr "type"     "branch")
10486    (set_attr "mode"     "none")
10487    (set_attr "length"   "8")])
10488
10489 ;; We can also have the reverse reload: reload will spill $24 into
10490 ;; another register, and then do a branch on that register when it
10491 ;; could have just stuck with $24.
10492
10493 (define_peephole
10494   [(set (match_operand:SI 0 "register_operand" "=d")
10495         (match_operand:SI 1 "register_operand" "t"))
10496    (set (pc)
10497         (if_then_else (match_operator:SI 2 "equality_op" [(match_dup 0)
10498                                                           (const_int 0)])
10499                       (match_operand 3 "pc_or_label_operand" "")
10500                       (match_operand 4 "pc_or_label_operand" "")))]
10501   "TARGET_MIPS16
10502    && GET_CODE (operands[1]) == REG
10503    && REGNO (operands[1]) == 24
10504    && GET_CODE (operands[0]) == REG
10505    && M16_REG_P (REGNO (operands[0]))
10506    && dead_or_set_p (insn, operands[0])"
10507   "*
10508 {
10509   if (operands[3] != pc_rtx)
10510     return \"%*bt%C2z\\t%3\";
10511   else
10512     return \"%*bt%N2z\\t%4\";
10513 }"
10514   [(set_attr "type"     "branch")
10515    (set_attr "mode"     "none")
10516    (set_attr "length"   "8")])
10517
10518 (define_peephole
10519   [(set (match_operand:DI 0 "register_operand" "=d")
10520         (match_operand:DI 1 "register_operand" "t"))
10521    (set (pc)
10522         (if_then_else (match_operator:DI 2 "equality_op" [(match_dup 0)
10523                                                           (const_int 0)])
10524                       (match_operand 3 "pc_or_label_operand" "")
10525                       (match_operand 4 "pc_or_label_operand" "")))]
10526   "TARGET_MIPS16 && TARGET_64BIT
10527    && GET_CODE (operands[1]) == REG
10528    && REGNO (operands[1]) == 24
10529    && GET_CODE (operands[0]) == REG
10530    && M16_REG_P (REGNO (operands[0]))
10531    && dead_or_set_p (insn, operands[0])"
10532   "*
10533 {
10534   if (operands[3] != pc_rtx)
10535     return \"%*bt%C2z\\t%3\";
10536   else
10537     return \"%*bt%N2z\\t%4\";
10538 }"
10539   [(set_attr "type"     "branch")
10540    (set_attr "mode"     "none")
10541    (set_attr "length"   "8")])