OSDN Git Service

* config/epiphany/epiphany.h (USE_LOAD_POST_INCREMENT): Define.
[pf3gnuchains/gcc-fork.git] / gcc / config / mips / mips.md
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;;  1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 ;;  Free Software Foundation, Inc.
5 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
6 ;;  Changes by       Michael Meissner, meissner@osf.org
7 ;;  64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
8 ;;  Brendan Eich, brendan@microunity.com.
9
10 ;; This file is part of GCC.
11
12 ;; GCC is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; any later version.
16
17 ;; GCC is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GCC; see the file COPYING3.  If not see
24 ;; <http://www.gnu.org/licenses/>.
25
26 (define_enum "processor" [
27   r3000
28   4kc
29   4kp
30   5kc
31   5kf
32   20kc
33   24kc
34   24kf2_1
35   24kf1_1
36   74kc
37   74kf2_1
38   74kf1_1
39   74kf3_2
40   loongson_2e
41   loongson_2f
42   loongson_3a
43   m4k
44   octeon
45   r3900
46   r6000
47   r4000
48   r4100
49   r4111
50   r4120
51   r4130
52   r4300
53   r4600
54   r4650
55   r5000
56   r5400
57   r5500
58   r7000
59   r8000
60   r9000
61   r10000
62   sb1
63   sb1a
64   sr71000
65   xlr
66 ])
67
68 (define_c_enum "unspec" [
69   ;; Unaligned accesses.
70   UNSPEC_LOAD_LEFT
71   UNSPEC_LOAD_RIGHT
72   UNSPEC_STORE_LEFT
73   UNSPEC_STORE_RIGHT
74
75   ;; Floating-point moves.
76   UNSPEC_LOAD_LOW
77   UNSPEC_LOAD_HIGH
78   UNSPEC_STORE_WORD
79   UNSPEC_MFHC1
80   UNSPEC_MTHC1
81
82   ;; HI/LO moves.
83   UNSPEC_MFHI
84   UNSPEC_MTHI
85   UNSPEC_SET_HILO
86
87   ;; GP manipulation.
88   UNSPEC_LOADGP
89   UNSPEC_COPYGP
90   UNSPEC_MOVE_GP
91   UNSPEC_POTENTIAL_CPRESTORE
92   UNSPEC_CPRESTORE
93   UNSPEC_RESTORE_GP
94   UNSPEC_EH_RETURN
95   UNSPEC_GP
96   UNSPEC_SET_GOT_VERSION
97   UNSPEC_UPDATE_GOT_VERSION
98
99   ;; Symbolic accesses.
100   UNSPEC_LOAD_CALL
101   UNSPEC_LOAD_GOT
102   UNSPEC_TLS_LDM
103   UNSPEC_TLS_GET_TP
104
105   ;; MIPS16 constant pools.
106   UNSPEC_ALIGN
107   UNSPEC_CONSTTABLE_INT
108   UNSPEC_CONSTTABLE_FLOAT
109
110   ;; Blockage and synchronisation.
111   UNSPEC_BLOCKAGE
112   UNSPEC_CLEAR_HAZARD
113   UNSPEC_RDHWR
114   UNSPEC_SYNCI
115   UNSPEC_SYNC
116
117   ;; Cache manipulation.
118   UNSPEC_MIPS_CACHE
119   UNSPEC_R10K_CACHE_BARRIER
120
121   ;; Interrupt handling.
122   UNSPEC_ERET
123   UNSPEC_DERET
124   UNSPEC_DI
125   UNSPEC_EHB
126   UNSPEC_RDPGPR
127   UNSPEC_COP0
128
129   ;; Used in a call expression in place of args_size.  It's present for PIC
130   ;; indirect calls where it contains args_size and the function symbol.
131   UNSPEC_CALL_ATTR
132 ])
133
134 (define_constants
135   [(TLS_GET_TP_REGNUM           3)
136    (RETURN_ADDR_REGNUM          31)
137    (CPRESTORE_SLOT_REGNUM       76)
138    (GOT_VERSION_REGNUM          79)
139
140    ;; PIC long branch sequences are never longer than 100 bytes.
141    (MAX_PIC_BRANCH_LENGTH       100)
142   ]
143 )
144
145 (include "predicates.md")
146 (include "constraints.md")
147 \f
148 ;; ....................
149 ;;
150 ;;      Attributes
151 ;;
152 ;; ....................
153
154 (define_attr "got" "unset,xgot_high,load"
155   (const_string "unset"))
156
157 ;; For jal instructions, this attribute is DIRECT when the target address
158 ;; is symbolic and INDIRECT when it is a register.
159 (define_attr "jal" "unset,direct,indirect"
160   (const_string "unset"))
161
162 ;; This attribute is YES if the instruction is a jal macro (not a
163 ;; real jal instruction).
164 ;;
165 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
166 ;; an instruction to restore $gp.  Direct jals are also macros for
167 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
168 ;; into a register.
169 (define_attr "jal_macro" "no,yes"
170   (cond [(eq_attr "jal" "direct")
171          (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
172                        ? JAL_MACRO_YES : JAL_MACRO_NO)")
173          (eq_attr "jal" "indirect")
174          (symbol_ref "(TARGET_CALL_CLOBBERED_GP
175                        ? JAL_MACRO_YES : JAL_MACRO_NO)")]
176         (const_string "no")))
177
178 ;; Classification of moves, extensions and truncations.  Most values
179 ;; are as for "type" (see below) but there are also the following
180 ;; move-specific values:
181 ;;
182 ;; constN       move an N-constraint integer into a MIPS16 register
183 ;; sll0         "sll DEST,SRC,0", which on 64-bit targets is guaranteed
184 ;;              to produce a sign-extended DEST, even if SRC is not
185 ;;              properly sign-extended
186 ;; ext_ins      EXT, DEXT, INS or DINS instruction
187 ;; andi         a single ANDI instruction
188 ;; loadpool     move a constant into a MIPS16 register by loading it
189 ;;              from the pool
190 ;; shift_shift  a shift left followed by a shift right
191 ;; lui_movf     an LUI followed by a MOVF (for d<-z CC moves)
192 ;;
193 ;; This attribute is used to determine the instruction's length and
194 ;; scheduling type.  For doubleword moves, the attribute always describes
195 ;; the split instructions; in some cases, it is more appropriate for the
196 ;; scheduling type to be "multi" instead.
197 (define_attr "move_type"
198   "unknown,load,fpload,store,fpstore,mtc,mfc,mthilo,mfhilo,move,fmove,
199    const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
200    shift_shift,lui_movf"
201   (const_string "unknown"))
202
203 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
204   (const_string "unknown"))
205
206 ;; Main data type used by the insn
207 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
208   (const_string "unknown"))
209
210 ;; True if the main data type is twice the size of a word.
211 (define_attr "dword_mode" "no,yes"
212   (cond [(and (eq_attr "mode" "DI,DF")
213               (not (match_test "TARGET_64BIT")))
214          (const_string "yes")
215
216          (and (eq_attr "mode" "TI,TF")
217               (match_test "TARGET_64BIT"))
218          (const_string "yes")]
219         (const_string "no")))
220
221 ;; Classification of each insn.
222 ;; branch       conditional branch
223 ;; jump         unconditional jump
224 ;; call         unconditional call
225 ;; load         load instruction(s)
226 ;; fpload       floating point load
227 ;; fpidxload    floating point indexed load
228 ;; store        store instruction(s)
229 ;; fpstore      floating point store
230 ;; fpidxstore   floating point indexed store
231 ;; prefetch     memory prefetch (register + offset)
232 ;; prefetchx    memory indexed prefetch (register + register)
233 ;; condmove     conditional moves
234 ;; mtc          transfer to coprocessor
235 ;; mfc          transfer from coprocessor
236 ;; mthilo       transfer to hi/lo registers
237 ;; mfhilo       transfer from hi/lo registers
238 ;; const        load constant
239 ;; arith        integer arithmetic instructions
240 ;; logical      integer logical instructions
241 ;; shift        integer shift instructions
242 ;; slt          set less than instructions
243 ;; signext      sign extend instructions
244 ;; clz          the clz and clo instructions
245 ;; pop          the pop instruction
246 ;; trap         trap if instructions
247 ;; imul         integer multiply 2 operands
248 ;; imul3        integer multiply 3 operands
249 ;; imul3nc      integer multiply 3 operands without clobbering HI/LO
250 ;; imadd        integer multiply-add
251 ;; idiv         integer divide 2 operands
252 ;; idiv3        integer divide 3 operands
253 ;; move         integer register move ({,D}ADD{,U} with rt = 0)
254 ;; fmove        floating point register move
255 ;; fadd         floating point add/subtract
256 ;; fmul         floating point multiply
257 ;; fmadd        floating point multiply-add
258 ;; fdiv         floating point divide
259 ;; frdiv        floating point reciprocal divide
260 ;; frdiv1       floating point reciprocal divide step 1
261 ;; frdiv2       floating point reciprocal divide step 2
262 ;; fabs         floating point absolute value
263 ;; fneg         floating point negation
264 ;; fcmp         floating point compare
265 ;; fcvt         floating point convert
266 ;; fsqrt        floating point square root
267 ;; frsqrt       floating point reciprocal square root
268 ;; frsqrt1      floating point reciprocal square root step1
269 ;; frsqrt2      floating point reciprocal square root step2
270 ;; multi        multiword sequence (or user asm statements)
271 ;; nop          no operation
272 ;; ghost        an instruction that produces no real code
273 (define_attr "type"
274   "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
275    prefetch,prefetchx,condmove,mtc,mfc,mthilo,mfhilo,const,arith,logical,
276    shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
277    fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
278    frsqrt,frsqrt1,frsqrt2,multi,nop,ghost"
279   (cond [(eq_attr "jal" "!unset") (const_string "call")
280          (eq_attr "got" "load") (const_string "load")
281
282          (eq_attr "alu_type" "add,sub") (const_string "arith")
283
284          (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
285
286          ;; If a doubleword move uses these expensive instructions,
287          ;; it is usually better to schedule them in the same way
288          ;; as the singleword form, rather than as "multi".
289          (eq_attr "move_type" "load") (const_string "load")
290          (eq_attr "move_type" "fpload") (const_string "fpload")
291          (eq_attr "move_type" "store") (const_string "store")
292          (eq_attr "move_type" "fpstore") (const_string "fpstore")
293          (eq_attr "move_type" "mtc") (const_string "mtc")
294          (eq_attr "move_type" "mfc") (const_string "mfc")
295          (eq_attr "move_type" "mthilo") (const_string "mthilo")
296          (eq_attr "move_type" "mfhilo") (const_string "mfhilo")
297
298          ;; These types of move are always single insns.
299          (eq_attr "move_type" "fmove") (const_string "fmove")
300          (eq_attr "move_type" "loadpool") (const_string "load")
301          (eq_attr "move_type" "signext") (const_string "signext")
302          (eq_attr "move_type" "ext_ins") (const_string "arith")
303          (eq_attr "move_type" "arith") (const_string "arith")
304          (eq_attr "move_type" "logical") (const_string "logical")
305          (eq_attr "move_type" "sll0") (const_string "shift")
306          (eq_attr "move_type" "andi") (const_string "logical")
307
308          ;; These types of move are always split.
309          (eq_attr "move_type" "constN,shift_shift")
310            (const_string "multi")
311
312          ;; These types of move are split for doubleword modes only.
313          (and (eq_attr "move_type" "move,const")
314               (eq_attr "dword_mode" "yes"))
315            (const_string "multi")
316          (eq_attr "move_type" "move") (const_string "move")
317          (eq_attr "move_type" "const") (const_string "const")]
318         ;; We classify "lui_movf" as "unknown" rather than "multi"
319         ;; because we don't split it.  FIXME: we should split instead.
320         (const_string "unknown")))
321
322 ;; Mode for conversion types (fcvt)
323 ;; I2S          integer to float single (SI/DI to SF)
324 ;; I2D          integer to float double (SI/DI to DF)
325 ;; S2I          float to integer (SF to SI/DI)
326 ;; D2I          float to integer (DF to SI/DI)
327 ;; D2S          double to float single
328 ;; S2D          float single to double
329
330 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D" 
331   (const_string "unknown"))
332
333 ;; Is this an extended instruction in mips16 mode?
334 (define_attr "extended_mips16" "no,yes"
335   (if_then_else (ior (eq_attr "move_type" "sll0")
336                      (eq_attr "type" "branch")
337                      (eq_attr "jal" "direct"))
338                 (const_string "yes")
339                 (const_string "no")))
340
341 ;; Attributes describing a sync loop.  These loops have the form:
342 ;;
343 ;;       if (RELEASE_BARRIER == YES) sync
344 ;;    1: OLDVAL = *MEM
345 ;;       if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
346 ;;       $TMP1 = OLDVAL & EXCLUSIVE_MASK
347 ;;       $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
348 ;;       $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
349 ;;       $AT |= $TMP1 | $TMP3
350 ;;       if (!commit (*MEM = $AT)) goto 1.
351 ;;         if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
352 ;;       sync
353 ;;    2:
354 ;;
355 ;; where "$" values are temporaries and where the other values are
356 ;; specified by the attributes below.  Values are specified as operand
357 ;; numbers and insns are specified as enums.  If no operand number is
358 ;; specified, the following values are used instead:
359 ;;
360 ;;    - OLDVAL: $AT
361 ;;    - NEWVAL: $AT
362 ;;    - INCLUSIVE_MASK: -1
363 ;;    - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
364 ;;    - EXCLUSIVE_MASK: 0
365 ;;
366 ;; MEM and INSN1_OP2 are required.
367 ;;
368 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
369 ;; but the gen* programs don't yet support that.
370 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
371 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
372 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
373 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
374 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
375 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
376 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
377 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
378   (const_string "move"))
379 (define_attr "sync_insn2" "nop,and,xor,not"
380   (const_string "nop"))
381 (define_attr "sync_release_barrier" "yes,no"
382   (const_string "yes"))
383
384 ;; Length of instruction in bytes.
385 (define_attr "length" ""
386    (cond [(and (eq_attr "extended_mips16" "yes")
387                (match_test "TARGET_MIPS16"))
388           (const_int 8)
389
390           ;; Direct branch instructions have a range of [-0x20000,0x1fffc],
391           ;; relative to the address of the delay slot.  If a branch is
392           ;; outside this range, we have a choice of two sequences.
393           ;; For PIC, an out-of-range branch like:
394           ;;
395           ;;    bne     r1,r2,target
396           ;;    dslot
397           ;;
398           ;; becomes the equivalent of:
399           ;;
400           ;;    beq     r1,r2,1f
401           ;;    dslot
402           ;;    la      $at,target
403           ;;    jr      $at
404           ;;    nop
405           ;; 1:
406           ;;
407           ;; The non-PIC case is similar except that we use a direct
408           ;; jump instead of an la/jr pair.  Since the target of this
409           ;; jump is an absolute 28-bit bit address (the other bits
410           ;; coming from the address of the delay slot) this form cannot
411           ;; cross a 256MB boundary.  We could provide the option of
412           ;; using la/jr in this case too, but we do not do so at
413           ;; present.
414           ;;
415           ;; Note that this value does not account for the delay slot
416           ;; instruction, whose length is added separately.  If the RTL
417           ;; pattern has no explicit delay slot, mips_adjust_insn_length
418           ;; will add the length of the implicit nop.  The values for
419           ;; forward and backward branches will be different as well.
420           (eq_attr "type" "branch")
421           (cond [(and (le (minus (match_dup 0) (pc)) (const_int 131064))
422                           (le (minus (pc) (match_dup 0)) (const_int 131068)))
423                    (const_int 4)
424
425                  ;; The non-PIC case: branch, first delay slot, and J.
426                  (match_test "TARGET_ABSOLUTE_JUMPS")
427                    (const_int 12)]
428
429                  ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
430                  ;; mips_adjust_insn_length substitutes the correct length.
431                  ;;
432                  ;; Note that we can't simply use (symbol_ref ...) here
433                  ;; because genattrtab needs to know the maximum length
434                  ;; of an insn.
435                  (const_int MAX_PIC_BRANCH_LENGTH))
436
437           ;; "Ghost" instructions occupy no space.
438           (eq_attr "type" "ghost")
439           (const_int 0)
440
441           (eq_attr "got" "load")
442           (if_then_else (match_test "TARGET_MIPS16")
443                         (const_int 8)
444                         (const_int 4))
445           (eq_attr "got" "xgot_high")
446           (const_int 8)
447
448           ;; In general, constant-pool loads are extended instructions.
449           (eq_attr "move_type" "loadpool")
450           (const_int 8)
451
452           ;; LUI_MOVFs are decomposed into two separate instructions.
453           (eq_attr "move_type" "lui_movf")
454           (const_int 8)
455
456           ;; SHIFT_SHIFTs are decomposed into two separate instructions.
457           ;; They are extended instructions on MIPS16 targets.
458           (eq_attr "move_type" "shift_shift")
459           (if_then_else (match_test "TARGET_MIPS16")
460                         (const_int 16)
461                         (const_int 8))
462
463           ;; Check for doubleword moves that are decomposed into two
464           ;; instructions.
465           (and (eq_attr "move_type" "mtc,mfc,mthilo,mfhilo,move")
466                (eq_attr "dword_mode" "yes"))
467           (const_int 8)
468
469           ;; Doubleword CONST{,N} moves are split into two word
470           ;; CONST{,N} moves.
471           (and (eq_attr "move_type" "const,constN")
472                (eq_attr "dword_mode" "yes"))
473           (symbol_ref "mips_split_const_insns (operands[1]) * 4")
474
475           ;; Otherwise, constants, loads and stores are handled by external
476           ;; routines.
477           (eq_attr "move_type" "const,constN")
478           (symbol_ref "mips_const_insns (operands[1]) * 4")
479           (eq_attr "move_type" "load,fpload")
480           (symbol_ref "mips_load_store_insns (operands[1], insn) * 4")
481           (eq_attr "move_type" "store,fpstore")
482           (cond [(not (match_test "TARGET_FIX_24K"))
483                  (symbol_ref "mips_load_store_insns (operands[0], insn) * 4")]
484                  (symbol_ref "mips_load_store_insns (operands[0], insn) * 4 + 4"))
485
486           ;; In the worst case, a call macro will take 8 instructions:
487           ;;
488           ;;     lui $25,%call_hi(FOO)
489           ;;     addu $25,$25,$28
490           ;;     lw $25,%call_lo(FOO)($25)
491           ;;     nop
492           ;;     jalr $25
493           ;;     nop
494           ;;     lw $gp,X($sp)
495           ;;     nop
496           (eq_attr "jal_macro" "yes")
497           (const_int 32)
498
499           ;; Various VR4120 errata require a nop to be inserted after a macc
500           ;; instruction.  The assembler does this for us, so account for
501           ;; the worst-case length here.
502           (and (eq_attr "type" "imadd")
503                (match_test "TARGET_FIX_VR4120"))
504           (const_int 8)
505
506           ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
507           ;; the result of the second one is missed.  The assembler should work
508           ;; around this by inserting a nop after the first dmult.
509           (and (eq_attr "type" "imul,imul3")
510                (and (eq_attr "mode" "DI")
511                     (match_test "TARGET_FIX_VR4120")))
512           (const_int 8)
513
514           (eq_attr "type" "idiv,idiv3")
515           (symbol_ref "mips_idiv_insns () * 4")
516
517           (not (eq_attr "sync_mem" "none"))
518           (symbol_ref "mips_sync_loop_insns (insn, operands) * 4")
519           ] (const_int 4)))
520
521 ;; Attribute describing the processor.
522 (define_enum_attr "cpu" "processor"
523   (const (symbol_ref "mips_tune")))
524
525 ;; The type of hardware hazard associated with this instruction.
526 ;; DELAY means that the next instruction cannot read the result
527 ;; of this one.  HILO means that the next two instructions cannot
528 ;; write to HI or LO.
529 (define_attr "hazard" "none,delay,hilo"
530   (cond [(and (eq_attr "type" "load,fpload,fpidxload")
531               (match_test "ISA_HAS_LOAD_DELAY"))
532          (const_string "delay")
533
534          (and (eq_attr "type" "mfc,mtc")
535               (match_test "ISA_HAS_XFER_DELAY"))
536          (const_string "delay")
537
538          (and (eq_attr "type" "fcmp")
539               (match_test "ISA_HAS_FCMP_DELAY"))
540          (const_string "delay")
541
542          ;; The r4000 multiplication patterns include an mflo instruction.
543          (and (eq_attr "type" "imul")
544               (match_test "TARGET_FIX_R4000"))
545          (const_string "hilo")
546
547          (and (eq_attr "type" "mfhilo")
548               (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
549          (const_string "hilo")]
550         (const_string "none")))
551
552 ;; Is it a single instruction?
553 (define_attr "single_insn" "no,yes"
554   (symbol_ref "(get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)
555                 ? SINGLE_INSN_YES : SINGLE_INSN_NO)"))
556
557 ;; Can the instruction be put into a delay slot?
558 (define_attr "can_delay" "no,yes"
559   (if_then_else (and (eq_attr "type" "!branch,call,jump")
560                      (and (eq_attr "hazard" "none")
561                           (eq_attr "single_insn" "yes")))
562                 (const_string "yes")
563                 (const_string "no")))
564
565 ;; Attribute defining whether or not we can use the branch-likely
566 ;; instructions.
567 (define_attr "branch_likely" "no,yes"
568   (if_then_else (match_test "GENERATE_BRANCHLIKELY")
569                 (const_string "yes")
570                 (const_string "no")))
571
572 ;; True if an instruction might assign to hi or lo when reloaded.
573 ;; This is used by the TUNE_MACC_CHAINS code.
574 (define_attr "may_clobber_hilo" "no,yes"
575   (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthilo")
576                 (const_string "yes")
577                 (const_string "no")))
578
579 ;; Describe a user's asm statement.
580 (define_asm_attributes
581   [(set_attr "type" "multi")
582    (set_attr "can_delay" "no")])
583 \f
584 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
585 ;; from the same template.
586 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
587
588 ;; A copy of GPR that can be used when a pattern has two independent
589 ;; modes.
590 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
591
592 ;; This mode iterator allows :HILO to be used as the mode of the
593 ;; concatenated HI and LO registers.
594 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
595
596 ;; This mode iterator allows :P to be used for patterns that operate on
597 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
598 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
599
600 ;; This mode iterator allows :MOVECC to be used anywhere that a
601 ;; conditional-move-type condition is needed.
602 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
603                               (CC "TARGET_HARD_FLOAT && !TARGET_LOONGSON_2EF")])
604
605 ;; 32-bit integer moves for which we provide move patterns.
606 (define_mode_iterator IMOVE32
607   [SI
608    (V2HI "TARGET_DSP")
609    (V4QI "TARGET_DSP")
610    (V2HQ "TARGET_DSP")
611    (V2UHQ "TARGET_DSP")
612    (V2HA "TARGET_DSP")
613    (V2UHA "TARGET_DSP")
614    (V4QQ "TARGET_DSP")
615    (V4UQQ "TARGET_DSP")])
616
617 ;; 64-bit modes for which we provide move patterns.
618 (define_mode_iterator MOVE64
619   [DI DF
620    (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
621    (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
622    (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
623    (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
624
625 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
626 (define_mode_iterator MOVE128 [TI TF])
627
628 ;; This mode iterator allows the QI and HI extension patterns to be
629 ;; defined from the same template.
630 (define_mode_iterator SHORT [QI HI])
631
632 ;; Likewise the 64-bit truncate-and-shift patterns.
633 (define_mode_iterator SUBDI [QI HI SI])
634
635 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
636 ;; floating-point mode is allowed.
637 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
638                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
639                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
640
641 ;; Like ANYF, but only applies to scalar modes.
642 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
643                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
644
645 ;; A floating-point mode for which moves involving FPRs may need to be split.
646 (define_mode_iterator SPLITF
647   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
648    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
649    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
650    (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
651    (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
652    (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
653    (TF "TARGET_64BIT && TARGET_FLOAT64")])
654
655 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
656 ;; 32-bit version and "dsubu" in the 64-bit version.
657 (define_mode_attr d [(SI "") (DI "d")
658                      (QQ "") (HQ "") (SQ "") (DQ "d")
659                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
660                      (HA "") (SA "") (DA "d")
661                      (UHA "") (USA "") (UDA "d")])
662
663 ;; Same as d but upper-case.
664 (define_mode_attr D [(SI "") (DI "D")
665                      (QQ "") (HQ "") (SQ "") (DQ "D")
666                      (UQQ "") (UHQ "") (USQ "") (UDQ "D")
667                      (HA "") (SA "") (DA "D")
668                      (UHA "") (USA "") (UDA "D")])
669
670 ;; This attribute gives the length suffix for a sign- or zero-extension
671 ;; instruction.
672 (define_mode_attr size [(QI "b") (HI "h")])
673
674 ;; This attributes gives the mode mask of a SHORT.
675 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
676
677 ;; Mode attributes for GPR loads.
678 (define_mode_attr load [(SI "lw") (DI "ld")])
679 ;; Instruction names for stores.
680 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
681
682 ;; Similarly for MIPS IV indexed FPR loads and stores.
683 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
684 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
685
686 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
687 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
688 ;; field but the equivalent daddiu has only a 5-bit field.
689 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
690
691 ;; This attribute gives the best constraint to use for registers of
692 ;; a given mode.
693 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
694
695 ;; This attribute gives the format suffix for floating-point operations.
696 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
697
698 ;; This attribute gives the upper-case mode name for one unit of a
699 ;; floating-point mode.
700 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
701
702 ;; This attribute gives the integer mode that has the same size as a
703 ;; fixed-point mode.
704 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
705                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
706                          (HA "HI") (SA "SI") (DA "DI")
707                          (UHA "HI") (USA "SI") (UDA "DI")
708                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
709                          (V2HQ "SI") (V2HA "SI")])
710
711 ;; This attribute gives the integer mode that has half the size of
712 ;; the controlling mode.
713 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
714                             (V2SI "SI") (V4HI "SI") (V8QI "SI")
715                             (TF "DI")])
716
717 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
718 ;;
719 ;; In certain cases, div.s and div.ps may have a rounding error
720 ;; and/or wrong inexact flag.
721 ;;
722 ;; Therefore, we only allow div.s if not working around SB-1 rev2
723 ;; errata or if a slight loss of precision is OK.
724 (define_mode_attr divide_condition
725   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
726    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
727
728 ;; This attribute gives the conditions under which SQRT.fmt instructions
729 ;; can be used.
730 (define_mode_attr sqrt_condition
731   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
732
733 ;; This attribute gives the conditions under which RECIP.fmt and RSQRT.fmt
734 ;; instructions can be used.  The MIPS32 and MIPS64 ISAs say that RECIP.D
735 ;; and RSQRT.D are unpredictable when doubles are stored in pairs of FPRs,
736 ;; so for safety's sake, we apply this restriction to all targets.
737 (define_mode_attr recip_condition
738   [(SF "ISA_HAS_FP4")
739    (DF "ISA_HAS_FP4 && TARGET_FLOAT64")
740    (V2SF "TARGET_SB1")])
741
742 ;; This code iterator allows signed and unsigned widening multiplications
743 ;; to use the same template.
744 (define_code_iterator any_extend [sign_extend zero_extend])
745
746 ;; This code iterator allows the two right shift instructions to be
747 ;; generated from the same template.
748 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
749
750 ;; This code iterator allows the three shift instructions to be generated
751 ;; from the same template.
752 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
753
754 ;; This code iterator allows unsigned and signed division to be generated
755 ;; from the same template.
756 (define_code_iterator any_div [div udiv])
757
758 ;; This code iterator allows unsigned and signed modulus to be generated
759 ;; from the same template.
760 (define_code_iterator any_mod [mod umod])
761
762 ;; This code iterator allows all native floating-point comparisons to be
763 ;; generated from the same template.
764 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
765
766 ;; This code iterator is used for comparisons that can be implemented
767 ;; by swapping the operands.
768 (define_code_iterator swapped_fcond [ge gt unge ungt])
769
770 ;; Equality operators.
771 (define_code_iterator equality_op [eq ne])
772
773 ;; These code iterators allow the signed and unsigned scc operations to use
774 ;; the same template.
775 (define_code_iterator any_gt [gt gtu])
776 (define_code_iterator any_ge [ge geu])
777 (define_code_iterator any_lt [lt ltu])
778 (define_code_iterator any_le [le leu])
779
780 (define_code_iterator any_return [return simple_return])
781
782 ;; <u> expands to an empty string when doing a signed operation and
783 ;; "u" when doing an unsigned operation.
784 (define_code_attr u [(sign_extend "") (zero_extend "u")
785                      (div "") (udiv "u")
786                      (mod "") (umod "u")
787                      (gt "") (gtu "u")
788                      (ge "") (geu "u")
789                      (lt "") (ltu "u")
790                      (le "") (leu "u")])
791
792 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
793 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
794
795 ;; <optab> expands to the name of the optab for a particular code.
796 (define_code_attr optab [(ashift "ashl")
797                          (ashiftrt "ashr")
798                          (lshiftrt "lshr")
799                          (ior "ior")
800                          (xor "xor")
801                          (and "and")
802                          (plus "add")
803                          (minus "sub")
804                          (return "return")
805                          (simple_return "simple_return")])
806
807 ;; <insn> expands to the name of the insn that implements a particular code.
808 (define_code_attr insn [(ashift "sll")
809                         (ashiftrt "sra")
810                         (lshiftrt "srl")
811                         (ior "or")
812                         (xor "xor")
813                         (and "and")
814                         (plus "addu")
815                         (minus "subu")])
816
817 ;; <immediate_insn> expands to the name of the insn that implements
818 ;; a particular code to operate on immediate values.
819 (define_code_attr immediate_insn [(ior "ori")
820                                   (xor "xori")
821                                   (and "andi")])
822
823 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
824 (define_code_attr fcond [(unordered "un")
825                          (uneq "ueq")
826                          (unlt "ult")
827                          (unle "ule")
828                          (eq "eq")
829                          (lt "lt")
830                          (le "le")])
831
832 ;; Similar, but for swapped conditions.
833 (define_code_attr swapped_fcond [(ge "le")
834                                  (gt "lt")
835                                  (unge "ule")
836                                  (ungt "ult")])
837
838 ;; The value of the bit when the branch is taken for branch_bit patterns.
839 ;; Comparison is always against zero so this depends on the operator.
840 (define_code_attr bbv [(eq "0") (ne "1")])
841
842 ;; This is the inverse value of bbv.
843 (define_code_attr bbinv [(eq "1") (ne "0")])
844 \f
845 ;; .........................
846 ;;
847 ;;      Branch, call and jump delay slots
848 ;;
849 ;; .........................
850
851 (define_delay (and (eq_attr "type" "branch")
852                    (not (match_test "TARGET_MIPS16"))
853                    (eq_attr "branch_likely" "yes"))
854   [(eq_attr "can_delay" "yes")
855    (nil)
856    (eq_attr "can_delay" "yes")])
857
858 ;; Branches that don't have likely variants do not annul on false.
859 (define_delay (and (eq_attr "type" "branch")
860                    (not (match_test "TARGET_MIPS16"))
861                    (eq_attr "branch_likely" "no"))
862   [(eq_attr "can_delay" "yes")
863    (nil)
864    (nil)])
865
866 (define_delay (eq_attr "type" "jump")
867   [(eq_attr "can_delay" "yes")
868    (nil)
869    (nil)])
870
871 (define_delay (and (eq_attr "type" "call")
872                    (eq_attr "jal_macro" "no"))
873   [(eq_attr "can_delay" "yes")
874    (nil)
875    (nil)])
876 \f
877 ;; Pipeline descriptions.
878 ;;
879 ;; generic.md provides a fallback for processors without a specific
880 ;; pipeline description.  It is derived from the old define_function_unit
881 ;; version and uses the "alu" and "imuldiv" units declared below.
882 ;;
883 ;; Some of the processor-specific files are also derived from old
884 ;; define_function_unit descriptions and simply override the parts of
885 ;; generic.md that don't apply.  The other processor-specific files
886 ;; are self-contained.
887 (define_automaton "alu,imuldiv")
888
889 (define_cpu_unit "alu" "alu")
890 (define_cpu_unit "imuldiv" "imuldiv")
891
892 ;; Ghost instructions produce no real code and introduce no hazards.
893 ;; They exist purely to express an effect on dataflow.
894 (define_insn_reservation "ghost" 0
895   (eq_attr "type" "ghost")
896   "nothing")
897
898 (include "4k.md")
899 (include "5k.md")
900 (include "20kc.md")
901 (include "24k.md")
902 (include "74k.md")
903 (include "3000.md")
904 (include "4000.md")
905 (include "4100.md")
906 (include "4130.md")
907 (include "4300.md")
908 (include "4600.md")
909 (include "5000.md")
910 (include "5400.md")
911 (include "5500.md")
912 (include "6000.md")
913 (include "7000.md")
914 (include "9000.md")
915 (include "10000.md")
916 (include "loongson2ef.md")
917 (include "loongson3a.md")
918 (include "octeon.md")
919 (include "sb1.md")
920 (include "sr71k.md")
921 (include "xlr.md")
922 (include "generic.md")
923 \f
924 ;;
925 ;;  ....................
926 ;;
927 ;;      CONDITIONAL TRAPS
928 ;;
929 ;;  ....................
930 ;;
931
932 (define_insn "trap"
933   [(trap_if (const_int 1) (const_int 0))]
934   ""
935 {
936   if (ISA_HAS_COND_TRAP)
937     return "teq\t$0,$0";
938   else if (TARGET_MIPS16)
939     return "break 0";
940   else
941     return "break";
942 }
943   [(set_attr "type" "trap")])
944
945 (define_expand "ctrap<mode>4"
946   [(trap_if (match_operator 0 "comparison_operator"
947                             [(match_operand:GPR 1 "reg_or_0_operand")
948                              (match_operand:GPR 2 "arith_operand")])
949             (match_operand 3 "const_0_operand"))]
950   "ISA_HAS_COND_TRAP"
951 {
952   mips_expand_conditional_trap (operands[0]);
953   DONE;
954 })
955
956 (define_insn "*conditional_trap<mode>"
957   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
958                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
959                                  (match_operand:GPR 2 "arith_operand" "dI")])
960             (const_int 0))]
961   "ISA_HAS_COND_TRAP"
962   "t%C0\t%z1,%2"
963   [(set_attr "type" "trap")])
964 \f
965 ;;
966 ;;  ....................
967 ;;
968 ;;      ADDITION
969 ;;
970 ;;  ....................
971 ;;
972
973 (define_insn "add<mode>3"
974   [(set (match_operand:ANYF 0 "register_operand" "=f")
975         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
976                    (match_operand:ANYF 2 "register_operand" "f")))]
977   ""
978   "add.<fmt>\t%0,%1,%2"
979   [(set_attr "type" "fadd")
980    (set_attr "mode" "<UNITMODE>")])
981
982 (define_expand "add<mode>3"
983   [(set (match_operand:GPR 0 "register_operand")
984         (plus:GPR (match_operand:GPR 1 "register_operand")
985                   (match_operand:GPR 2 "arith_operand")))]
986   "")
987
988 (define_insn "*add<mode>3"
989   [(set (match_operand:GPR 0 "register_operand" "=d,d")
990         (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
991                   (match_operand:GPR 2 "arith_operand" "d,Q")))]
992   "!TARGET_MIPS16"
993   "@
994     <d>addu\t%0,%1,%2
995     <d>addiu\t%0,%1,%2"
996   [(set_attr "alu_type" "add")
997    (set_attr "mode" "<MODE>")])
998
999 (define_insn "*add<mode>3_mips16"
1000   [(set (match_operand:GPR 0 "register_operand" "=ks,d,d,d,d")
1001         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,0,d,d")
1002                   (match_operand:GPR 2 "arith_operand" "Q,Q,Q,O,d")))]
1003   "TARGET_MIPS16"
1004   "@
1005     <d>addiu\t%0,%2
1006     <d>addiu\t%0,%1,%2
1007     <d>addiu\t%0,%2
1008     <d>addiu\t%0,%1,%2
1009     <d>addu\t%0,%1,%2"
1010   [(set_attr "alu_type" "add")
1011    (set_attr "mode" "<MODE>")
1012    (set_attr_alternative "length"
1013                 [(if_then_else (match_operand 2 "m16_simm8_8")
1014                                (const_int 4)
1015                                (const_int 8))
1016                  (if_then_else (match_operand 2 "m16_uimm<si8_di5>_4")
1017                                (const_int 4)
1018                                (const_int 8))
1019                  (if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
1020                                (const_int 4)
1021                                (const_int 8))
1022                  (if_then_else (match_operand 2 "m16_simm4_1")
1023                                (const_int 4)
1024                                (const_int 8))
1025                  (const_int 4)])])
1026
1027 ;; On the mips16, we can sometimes split an add of a constant which is
1028 ;; a 4 byte instruction into two adds which are both 2 byte
1029 ;; instructions.  There are two cases: one where we are adding a
1030 ;; constant plus a register to another register, and one where we are
1031 ;; simply adding a constant to a register.
1032
1033 (define_split
1034   [(set (match_operand:SI 0 "d_operand")
1035         (plus:SI (match_dup 0)
1036                  (match_operand:SI 1 "const_int_operand")))]
1037   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1038    && ((INTVAL (operands[1]) > 0x7f
1039         && INTVAL (operands[1]) <= 0x7f + 0x7f)
1040        || (INTVAL (operands[1]) < - 0x80
1041            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1042   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1043    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1044 {
1045   HOST_WIDE_INT val = INTVAL (operands[1]);
1046
1047   if (val >= 0)
1048     {
1049       operands[1] = GEN_INT (0x7f);
1050       operands[2] = GEN_INT (val - 0x7f);
1051     }
1052   else
1053     {
1054       operands[1] = GEN_INT (- 0x80);
1055       operands[2] = GEN_INT (val + 0x80);
1056     }
1057 })
1058
1059 (define_split
1060   [(set (match_operand:SI 0 "d_operand")
1061         (plus:SI (match_operand:SI 1 "d_operand")
1062                  (match_operand:SI 2 "const_int_operand")))]
1063   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1064    && REGNO (operands[0]) != REGNO (operands[1])
1065    && ((INTVAL (operands[2]) > 0x7
1066         && INTVAL (operands[2]) <= 0x7 + 0x7f)
1067        || (INTVAL (operands[2]) < - 0x8
1068            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1069   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1070    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1071 {
1072   HOST_WIDE_INT val = INTVAL (operands[2]);
1073
1074   if (val >= 0)
1075     {
1076       operands[2] = GEN_INT (0x7);
1077       operands[3] = GEN_INT (val - 0x7);
1078     }
1079   else
1080     {
1081       operands[2] = GEN_INT (- 0x8);
1082       operands[3] = GEN_INT (val + 0x8);
1083     }
1084 })
1085
1086 (define_split
1087   [(set (match_operand:DI 0 "d_operand")
1088         (plus:DI (match_dup 0)
1089                  (match_operand:DI 1 "const_int_operand")))]
1090   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1091    && ((INTVAL (operands[1]) > 0xf
1092         && INTVAL (operands[1]) <= 0xf + 0xf)
1093        || (INTVAL (operands[1]) < - 0x10
1094            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1095   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1096    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1097 {
1098   HOST_WIDE_INT val = INTVAL (operands[1]);
1099
1100   if (val >= 0)
1101     {
1102       operands[1] = GEN_INT (0xf);
1103       operands[2] = GEN_INT (val - 0xf);
1104     }
1105   else
1106     {
1107       operands[1] = GEN_INT (- 0x10);
1108       operands[2] = GEN_INT (val + 0x10);
1109     }
1110 })
1111
1112 (define_split
1113   [(set (match_operand:DI 0 "d_operand")
1114         (plus:DI (match_operand:DI 1 "d_operand")
1115                  (match_operand:DI 2 "const_int_operand")))]
1116   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1117    && REGNO (operands[0]) != REGNO (operands[1])
1118    && ((INTVAL (operands[2]) > 0x7
1119         && INTVAL (operands[2]) <= 0x7 + 0xf)
1120        || (INTVAL (operands[2]) < - 0x8
1121            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1122   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1123    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1124 {
1125   HOST_WIDE_INT val = INTVAL (operands[2]);
1126
1127   if (val >= 0)
1128     {
1129       operands[2] = GEN_INT (0x7);
1130       operands[3] = GEN_INT (val - 0x7);
1131     }
1132   else
1133     {
1134       operands[2] = GEN_INT (- 0x8);
1135       operands[3] = GEN_INT (val + 0x8);
1136     }
1137 })
1138
1139 (define_insn "*addsi3_extended"
1140   [(set (match_operand:DI 0 "register_operand" "=d,d")
1141         (sign_extend:DI
1142              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1143                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
1144   "TARGET_64BIT && !TARGET_MIPS16"
1145   "@
1146     addu\t%0,%1,%2
1147     addiu\t%0,%1,%2"
1148   [(set_attr "alu_type" "add")
1149    (set_attr "mode" "SI")])
1150
1151 ;; Split this insn so that the addiu splitters can have a crack at it.
1152 ;; Use a conservative length estimate until the split.
1153 (define_insn_and_split "*addsi3_extended_mips16"
1154   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1155         (sign_extend:DI
1156              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1157                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1158   "TARGET_64BIT && TARGET_MIPS16"
1159   "#"
1160   "&& reload_completed"
1161   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1162   { operands[3] = gen_lowpart (SImode, operands[0]); }
1163   [(set_attr "alu_type" "add")
1164    (set_attr "mode" "SI")
1165    (set_attr "extended_mips16" "yes")])
1166
1167 ;; Combiner patterns for unsigned byte-add.
1168
1169 (define_insn "*baddu_si_eb"
1170   [(set (match_operand:SI 0 "register_operand" "=d")
1171         (zero_extend:SI
1172          (subreg:QI
1173           (plus:SI (match_operand:SI 1 "register_operand" "d")
1174                    (match_operand:SI 2 "register_operand" "d")) 3)))]
1175   "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1176   "baddu\\t%0,%1,%2"
1177   [(set_attr "alu_type" "add")])
1178
1179 (define_insn "*baddu_si_el"
1180   [(set (match_operand:SI 0 "register_operand" "=d")
1181         (zero_extend:SI
1182          (subreg:QI
1183           (plus:SI (match_operand:SI 1 "register_operand" "d")
1184                    (match_operand:SI 2 "register_operand" "d")) 0)))]
1185   "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1186   "baddu\\t%0,%1,%2"
1187   [(set_attr "alu_type" "add")])
1188
1189 (define_insn "*baddu_di<mode>"
1190   [(set (match_operand:GPR 0 "register_operand" "=d")
1191         (zero_extend:GPR
1192          (truncate:QI
1193           (plus:DI (match_operand:DI 1 "register_operand" "d")
1194                    (match_operand:DI 2 "register_operand" "d")))))]
1195   "ISA_HAS_BADDU && TARGET_64BIT"
1196   "baddu\\t%0,%1,%2"
1197   [(set_attr "alu_type" "add")])
1198 \f
1199 ;;
1200 ;;  ....................
1201 ;;
1202 ;;      SUBTRACTION
1203 ;;
1204 ;;  ....................
1205 ;;
1206
1207 (define_insn "sub<mode>3"
1208   [(set (match_operand:ANYF 0 "register_operand" "=f")
1209         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1210                     (match_operand:ANYF 2 "register_operand" "f")))]
1211   ""
1212   "sub.<fmt>\t%0,%1,%2"
1213   [(set_attr "type" "fadd")
1214    (set_attr "mode" "<UNITMODE>")])
1215
1216 (define_insn "sub<mode>3"
1217   [(set (match_operand:GPR 0 "register_operand" "=d")
1218         (minus:GPR (match_operand:GPR 1 "register_operand" "d")
1219                    (match_operand:GPR 2 "register_operand" "d")))]
1220   ""
1221   "<d>subu\t%0,%1,%2"
1222   [(set_attr "alu_type" "sub")
1223    (set_attr "mode" "<MODE>")])
1224
1225 (define_insn "*subsi3_extended"
1226   [(set (match_operand:DI 0 "register_operand" "=d")
1227         (sign_extend:DI
1228             (minus:SI (match_operand:SI 1 "register_operand" "d")
1229                       (match_operand:SI 2 "register_operand" "d"))))]
1230   "TARGET_64BIT"
1231   "subu\t%0,%1,%2"
1232   [(set_attr "alu_type" "sub")
1233    (set_attr "mode" "DI")])
1234 \f
1235 ;;
1236 ;;  ....................
1237 ;;
1238 ;;      MULTIPLICATION
1239 ;;
1240 ;;  ....................
1241 ;;
1242
1243 (define_expand "mul<mode>3"
1244   [(set (match_operand:SCALARF 0 "register_operand")
1245         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1246                       (match_operand:SCALARF 2 "register_operand")))]
1247   ""
1248   "")
1249
1250 (define_insn "*mul<mode>3"
1251   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1252         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1253                       (match_operand:SCALARF 2 "register_operand" "f")))]
1254   "!TARGET_4300_MUL_FIX"
1255   "mul.<fmt>\t%0,%1,%2"
1256   [(set_attr "type" "fmul")
1257    (set_attr "mode" "<MODE>")])
1258
1259 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1260 ;; operands may corrupt immediately following multiplies. This is a
1261 ;; simple fix to insert NOPs.
1262
1263 (define_insn "*mul<mode>3_r4300"
1264   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1265         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1266                       (match_operand:SCALARF 2 "register_operand" "f")))]
1267   "TARGET_4300_MUL_FIX"
1268   "mul.<fmt>\t%0,%1,%2\;nop"
1269   [(set_attr "type" "fmul")
1270    (set_attr "mode" "<MODE>")
1271    (set_attr "length" "8")])
1272
1273 (define_insn "mulv2sf3"
1274   [(set (match_operand:V2SF 0 "register_operand" "=f")
1275         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1276                    (match_operand:V2SF 2 "register_operand" "f")))]
1277   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1278   "mul.ps\t%0,%1,%2"
1279   [(set_attr "type" "fmul")
1280    (set_attr "mode" "SF")])
1281
1282 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1283 ;; shift executes while an integer multiplication is in progress, the
1284 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1285 ;; with the mult on the R4000.
1286 ;;
1287 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1288 ;; (also valid for MIPS R4000MC processors):
1289 ;;
1290 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1291 ;;      this errata description.
1292 ;;      The following code sequence causes the R4000 to incorrectly
1293 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1294 ;;      instruction.  If the dsra32 instruction is executed during an
1295 ;;      integer multiply, the dsra32 will only shift by the amount in
1296 ;;      specified in the instruction rather than the amount plus 32
1297 ;;      bits.
1298 ;;      instruction 1:          mult    rs,rt           integer multiply
1299 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1300 ;;                                                      right arithmetic + 32
1301 ;;      Workaround: A dsra32 instruction placed after an integer
1302 ;;      multiply should not be one of the 11 instructions after the
1303 ;;      multiply instruction."
1304 ;;
1305 ;; and:
1306 ;;
1307 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1308 ;;      the following description.
1309 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1310 ;;      64-bit versions) may produce incorrect results under the
1311 ;;      following conditions:
1312 ;;      1) An integer multiply is currently executing
1313 ;;      2) These types of shift instructions are executed immediately
1314 ;;         following an integer divide instruction.
1315 ;;      Workaround:
1316 ;;      1) Make sure no integer multiply is running wihen these
1317 ;;         instruction are executed.  If this cannot be predicted at
1318 ;;         compile time, then insert a "mfhi" to R0 instruction
1319 ;;         immediately after the integer multiply instruction.  This
1320 ;;         will cause the integer multiply to complete before the shift
1321 ;;         is executed.
1322 ;;      2) Separate integer divide and these two classes of shift
1323 ;;         instructions by another instruction or a noop."
1324 ;;
1325 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1326 ;; respectively.
1327
1328 (define_expand "mul<mode>3"
1329   [(set (match_operand:GPR 0 "register_operand")
1330         (mult:GPR (match_operand:GPR 1 "register_operand")
1331                   (match_operand:GPR 2 "register_operand")))]
1332   ""
1333 {
1334   rtx lo;
1335
1336   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
1337     emit_insn (gen_mul<mode>3_mul3_loongson (operands[0], operands[1],
1338                                              operands[2]));
1339   else if (ISA_HAS_<D>MUL3)
1340     emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1341   else if (TARGET_MIPS16)
1342     {
1343       lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1344       emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1345       emit_move_insn (operands[0], lo);
1346     }
1347   else if (TARGET_FIX_R4000)
1348     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1349   else
1350     emit_insn
1351       (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1352   DONE;
1353 })
1354
1355 (define_insn "mul<mode>3_mul3_loongson"
1356   [(set (match_operand:GPR 0 "register_operand" "=d")
1357         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1358                   (match_operand:GPR 2 "register_operand" "d")))]
1359   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A"
1360 {
1361   if (TARGET_LOONGSON_2EF)
1362     return "<d>multu.g\t%0,%1,%2";
1363   else
1364     return "gs<d>multu\t%0,%1,%2";
1365 }
1366   [(set_attr "type" "imul3nc")
1367    (set_attr "mode" "<MODE>")])
1368
1369 (define_insn "mul<mode>3_mul3"
1370   [(set (match_operand:GPR 0 "register_operand" "=d,l")
1371         (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1372                   (match_operand:GPR 2 "register_operand" "d,d")))
1373    (clobber (match_scratch:GPR 3 "=l,X"))]
1374   "ISA_HAS_<D>MUL3"
1375 {
1376   if (which_alternative == 1)
1377     return "<d>mult\t%1,%2";
1378   if (<MODE>mode == SImode && TARGET_MIPS3900)
1379     return "mult\t%0,%1,%2";
1380   return "<d>mul\t%0,%1,%2";
1381 }
1382   [(set_attr "type" "imul3,imul")
1383    (set_attr "mode" "<MODE>")])
1384
1385 ;; If a register gets allocated to LO, and we spill to memory, the reload
1386 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1387 ;; if it can set the GPR directly.
1388 ;;
1389 ;; Operand 0: LO
1390 ;; Operand 1: GPR (1st multiplication operand)
1391 ;; Operand 2: GPR (2nd multiplication operand)
1392 ;; Operand 3: GPR (destination)
1393 (define_peephole2
1394   [(parallel
1395        [(set (match_operand:SI 0 "lo_operand")
1396              (mult:SI (match_operand:SI 1 "d_operand")
1397                       (match_operand:SI 2 "d_operand")))
1398         (clobber (scratch:SI))])
1399    (set (match_operand:SI 3 "d_operand")
1400         (match_dup 0))]
1401   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1402   [(parallel
1403        [(set (match_dup 3)
1404              (mult:SI (match_dup 1)
1405                       (match_dup 2)))
1406         (clobber (match_dup 0))])])
1407
1408 (define_insn "mul<mode>3_internal"
1409   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1410         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1411                   (match_operand:GPR 2 "register_operand" "d")))]
1412   "!TARGET_FIX_R4000"
1413   "<d>mult\t%1,%2"
1414   [(set_attr "type" "imul")
1415    (set_attr "mode" "<MODE>")])
1416
1417 (define_insn "mul<mode>3_r4000"
1418   [(set (match_operand:GPR 0 "register_operand" "=d")
1419         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1420                   (match_operand:GPR 2 "register_operand" "d")))
1421    (clobber (match_scratch:GPR 3 "=l"))]
1422   "TARGET_FIX_R4000"
1423   "<d>mult\t%1,%2\;mflo\t%0"
1424   [(set_attr "type" "imul")
1425    (set_attr "mode" "<MODE>")
1426    (set_attr "length" "8")])
1427
1428 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1429 ;; of "mult; mflo".  They have the same latency, but the first form gives
1430 ;; us an extra cycle to compute the operands.
1431
1432 ;; Operand 0: LO
1433 ;; Operand 1: GPR (1st multiplication operand)
1434 ;; Operand 2: GPR (2nd multiplication operand)
1435 ;; Operand 3: GPR (destination)
1436 (define_peephole2
1437   [(set (match_operand:SI 0 "lo_operand")
1438         (mult:SI (match_operand:SI 1 "d_operand")
1439                  (match_operand:SI 2 "d_operand")))
1440    (set (match_operand:SI 3 "d_operand")
1441         (match_dup 0))]
1442   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1443   [(set (match_dup 0)
1444         (const_int 0))
1445    (parallel
1446        [(set (match_dup 0)
1447              (plus:SI (mult:SI (match_dup 1)
1448                                (match_dup 2))
1449                       (match_dup 0)))
1450         (set (match_dup 3)
1451              (plus:SI (mult:SI (match_dup 1)
1452                                (match_dup 2))
1453                       (match_dup 0)))])])
1454
1455 ;; Multiply-accumulate patterns
1456
1457 ;; This pattern is first matched by combine, which tries to use the
1458 ;; pattern wherever it can.  We don't know until later whether it
1459 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1460 ;; so we need to keep both options open.
1461 ;;
1462 ;; The second alternative has a "?" marker because it is generally
1463 ;; one instruction more costly than the first alternative.  This "?"
1464 ;; marker is enough to convey the relative costs to the register
1465 ;; allocator.
1466 ;;
1467 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1468 ;; reloads of the other operands, even though operands 4 and 5 need no
1469 ;; copy instructions.  Reload therefore thinks that the second alternative
1470 ;; is two reloads more costly than the first.  We add "*?*?" to the first
1471 ;; alternative as a counterweight.
1472 (define_insn "*mul_acc_si"
1473   [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1474         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1475                           (match_operand:SI 2 "register_operand" "d,d"))
1476                  (match_operand:SI 3 "register_operand" "0,d")))
1477    (clobber (match_scratch:SI 4 "=X,l"))
1478    (clobber (match_scratch:SI 5 "=X,&d"))]
1479   "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1480   "@
1481     madd\t%1,%2
1482     #"
1483   [(set_attr "type"     "imadd")
1484    (set_attr "mode"     "SI")
1485    (set_attr "length"   "4,8")])
1486
1487 ;; The same idea applies here.  The middle alternative needs one less
1488 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1489 (define_insn "*mul_acc_si_r3900"
1490   [(set (match_operand:SI 0 "register_operand" "=l*?*?,d*?,d?")
1491         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1492                           (match_operand:SI 2 "register_operand" "d,d,d"))
1493                  (match_operand:SI 3 "register_operand" "0,l,d")))
1494    (clobber (match_scratch:SI 4 "=X,3,l"))
1495    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1496   "TARGET_MIPS3900 && !TARGET_MIPS16"
1497   "@
1498     madd\t%1,%2
1499     madd\t%0,%1,%2
1500     #"
1501   [(set_attr "type"     "imadd")
1502    (set_attr "mode"     "SI")
1503    (set_attr "length"   "4,4,8")])
1504
1505 ;; Split *mul_acc_si if both the source and destination accumulator
1506 ;; values are GPRs.
1507 (define_split
1508   [(set (match_operand:SI 0 "d_operand")
1509         (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1510                           (match_operand:SI 2 "d_operand"))
1511                  (match_operand:SI 3 "d_operand")))
1512    (clobber (match_operand:SI 4 "lo_operand"))
1513    (clobber (match_operand:SI 5 "d_operand"))]
1514   "reload_completed"
1515   [(parallel [(set (match_dup 5)
1516                    (mult:SI (match_dup 1) (match_dup 2)))
1517               (clobber (match_dup 4))])
1518    (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1519   "")
1520
1521 (define_insn "*macc"
1522   [(set (match_operand:SI 0 "register_operand" "=l,d")
1523         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1524                           (match_operand:SI 2 "register_operand" "d,d"))
1525                  (match_operand:SI 3 "register_operand" "0,l")))
1526    (clobber (match_scratch:SI 4 "=X,3"))]
1527   "ISA_HAS_MACC"
1528 {
1529   if (which_alternative == 1)
1530     return "macc\t%0,%1,%2";
1531   else if (TARGET_MIPS5500)
1532     return "madd\t%1,%2";
1533   else
1534     /* The VR4130 assumes that there is a two-cycle latency between a macc
1535        that "writes" to $0 and an instruction that reads from it.  We avoid
1536        this by assigning to $1 instead.  */
1537     return "%[macc\t%@,%1,%2%]";
1538 }
1539   [(set_attr "type" "imadd")
1540    (set_attr "mode" "SI")])
1541
1542 (define_insn "*msac"
1543   [(set (match_operand:SI 0 "register_operand" "=l,d")
1544         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1545                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1546                            (match_operand:SI 3 "register_operand" "d,d"))))
1547    (clobber (match_scratch:SI 4 "=X,1"))]
1548   "ISA_HAS_MSAC"
1549 {
1550   if (which_alternative == 1)
1551     return "msac\t%0,%2,%3";
1552   else if (TARGET_MIPS5500)
1553     return "msub\t%2,%3";
1554   else
1555     return "msac\t$0,%2,%3";
1556 }
1557   [(set_attr "type"     "imadd")
1558    (set_attr "mode"     "SI")])
1559
1560 ;; An msac-like instruction implemented using negation and a macc.
1561 (define_insn_and_split "*msac_using_macc"
1562   [(set (match_operand:SI 0 "register_operand" "=l,d")
1563         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1564                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1565                            (match_operand:SI 3 "register_operand" "d,d"))))
1566    (clobber (match_scratch:SI 4 "=X,1"))
1567    (clobber (match_scratch:SI 5 "=d,d"))]
1568   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1569   "#"
1570   "&& reload_completed"
1571   [(set (match_dup 5)
1572         (neg:SI (match_dup 3)))
1573    (parallel
1574        [(set (match_dup 0)
1575              (plus:SI (mult:SI (match_dup 2)
1576                                (match_dup 5))
1577                       (match_dup 1)))
1578         (clobber (match_dup 4))])]
1579   ""
1580   [(set_attr "type"     "imadd")
1581    (set_attr "length"   "8")])
1582
1583 ;; Patterns generated by the define_peephole2 below.
1584
1585 (define_insn "*macc2"
1586   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1587         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1588                           (match_operand:SI 2 "register_operand" "d"))
1589                  (match_dup 0)))
1590    (set (match_operand:SI 3 "register_operand" "=d")
1591         (plus:SI (mult:SI (match_dup 1)
1592                           (match_dup 2))
1593                  (match_dup 0)))]
1594   "ISA_HAS_MACC && reload_completed"
1595   "macc\t%3,%1,%2"
1596   [(set_attr "type"     "imadd")
1597    (set_attr "mode"     "SI")])
1598
1599 (define_insn "*msac2"
1600   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1601         (minus:SI (match_dup 0)
1602                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1603                            (match_operand:SI 2 "register_operand" "d"))))
1604    (set (match_operand:SI 3 "register_operand" "=d")
1605         (minus:SI (match_dup 0)
1606                   (mult:SI (match_dup 1)
1607                            (match_dup 2))))]
1608   "ISA_HAS_MSAC && reload_completed"
1609   "msac\t%3,%1,%2"
1610   [(set_attr "type"     "imadd")
1611    (set_attr "mode"     "SI")])
1612
1613 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1614 ;; Similarly msac.
1615 ;;
1616 ;; Operand 0: LO
1617 ;; Operand 1: macc/msac
1618 ;; Operand 2: GPR (destination)
1619 (define_peephole2
1620   [(parallel
1621        [(set (match_operand:SI 0 "lo_operand")
1622              (match_operand:SI 1 "macc_msac_operand"))
1623         (clobber (scratch:SI))])
1624    (set (match_operand:SI 2 "d_operand")
1625         (match_dup 0))]
1626   ""
1627   [(parallel [(set (match_dup 0)
1628                    (match_dup 1))
1629               (set (match_dup 2)
1630                    (match_dup 1))])])
1631
1632 ;; When we have a three-address multiplication instruction, it should
1633 ;; be faster to do a separate multiply and add, rather than moving
1634 ;; something into LO in order to use a macc instruction.
1635 ;;
1636 ;; This peephole needs a scratch register to cater for the case when one
1637 ;; of the multiplication operands is the same as the destination.
1638 ;;
1639 ;; Operand 0: GPR (scratch)
1640 ;; Operand 1: LO
1641 ;; Operand 2: GPR (addend)
1642 ;; Operand 3: GPR (destination)
1643 ;; Operand 4: macc/msac
1644 ;; Operand 5: new multiplication
1645 ;; Operand 6: new addition/subtraction
1646 (define_peephole2
1647   [(match_scratch:SI 0 "d")
1648    (set (match_operand:SI 1 "lo_operand")
1649         (match_operand:SI 2 "d_operand"))
1650    (match_dup 0)
1651    (parallel
1652        [(set (match_operand:SI 3 "d_operand")
1653              (match_operand:SI 4 "macc_msac_operand"))
1654         (clobber (match_dup 1))])]
1655   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1656   [(parallel [(set (match_dup 0)
1657                    (match_dup 5))
1658               (clobber (match_dup 1))])
1659    (set (match_dup 3)
1660         (match_dup 6))]
1661 {
1662   operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1663   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1664                                 operands[2], operands[0]);
1665 })
1666
1667 ;; Same as above, except LO is the initial target of the macc.
1668 ;;
1669 ;; Operand 0: GPR (scratch)
1670 ;; Operand 1: LO
1671 ;; Operand 2: GPR (addend)
1672 ;; Operand 3: macc/msac
1673 ;; Operand 4: GPR (destination)
1674 ;; Operand 5: new multiplication
1675 ;; Operand 6: new addition/subtraction
1676 (define_peephole2
1677   [(match_scratch:SI 0 "d")
1678    (set (match_operand:SI 1 "lo_operand")
1679         (match_operand:SI 2 "d_operand"))
1680    (match_dup 0)
1681    (parallel
1682        [(set (match_dup 1)
1683              (match_operand:SI 3 "macc_msac_operand"))
1684         (clobber (scratch:SI))])
1685    (match_dup 0)
1686    (set (match_operand:SI 4 "d_operand")
1687         (match_dup 1))]
1688   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1689   [(parallel [(set (match_dup 0)
1690                    (match_dup 5))
1691               (clobber (match_dup 1))])
1692    (set (match_dup 4)
1693         (match_dup 6))]
1694 {
1695   operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1696   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1697                                 operands[2], operands[0]);
1698 })
1699
1700 ;; See the comment above *mul_add_si for details.
1701 (define_insn "*mul_sub_si"
1702   [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1703         (minus:SI (match_operand:SI 1 "register_operand" "0,d")
1704                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1705                            (match_operand:SI 3 "register_operand" "d,d"))))
1706    (clobber (match_scratch:SI 4 "=X,l"))
1707    (clobber (match_scratch:SI 5 "=X,&d"))]
1708   "GENERATE_MADD_MSUB"
1709   "@
1710    msub\t%2,%3
1711    #"
1712   [(set_attr "type"     "imadd")
1713    (set_attr "mode"     "SI")
1714    (set_attr "length"   "4,8")])
1715
1716 ;; Split *mul_sub_si if both the source and destination accumulator
1717 ;; values are GPRs.
1718 (define_split
1719   [(set (match_operand:SI 0 "d_operand")
1720         (minus:SI (match_operand:SI 1 "d_operand")
1721                   (mult:SI (match_operand:SI 2 "d_operand")
1722                            (match_operand:SI 3 "d_operand"))))
1723    (clobber (match_operand:SI 4 "lo_operand"))
1724    (clobber (match_operand:SI 5 "d_operand"))]
1725   "reload_completed"
1726   [(parallel [(set (match_dup 5)
1727                    (mult:SI (match_dup 2) (match_dup 3)))
1728               (clobber (match_dup 4))])
1729    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1730   "")
1731
1732 (define_insn "*muls"
1733   [(set (match_operand:SI 0 "register_operand" "=l,d")
1734         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1735                          (match_operand:SI 2 "register_operand" "d,d"))))
1736    (clobber (match_scratch:SI 3 "=X,l"))]
1737   "ISA_HAS_MULS"
1738   "@
1739    muls\t$0,%1,%2
1740    muls\t%0,%1,%2"
1741   [(set_attr "type"     "imul,imul3")
1742    (set_attr "mode"     "SI")])
1743
1744 (define_expand "<u>mulsidi3"
1745   [(set (match_operand:DI 0 "register_operand")
1746         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1747                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1748   "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1749 {
1750   mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1751   emit_insn (fn (operands[0], operands[1], operands[2]));
1752   DONE;
1753 })
1754
1755 (define_expand "<u>mulsidi3_32bit_mips16"
1756   [(set (match_operand:DI 0 "register_operand")
1757         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1758                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1759   "!TARGET_64BIT && TARGET_MIPS16"
1760 {
1761   rtx hilo;
1762
1763   hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1764   emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1765   emit_move_insn (operands[0], hilo);
1766   DONE;
1767 })
1768
1769 ;; As well as being named patterns, these instructions are used by the
1770 ;; __builtin_mips_mult<u>() functions.  We must always make those functions
1771 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1772 (define_insn "<u>mulsidi3_32bit"
1773   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1774         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1775                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1776   "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP)"
1777 {
1778   if (ISA_HAS_DSP_MULT)
1779     return "mult<u>\t%q0,%1,%2";
1780   else
1781     return "mult<u>\t%1,%2";
1782 }
1783   [(set_attr "type" "imul")
1784    (set_attr "mode" "SI")])
1785
1786 (define_insn "<u>mulsidi3_32bit_r4000"
1787   [(set (match_operand:DI 0 "register_operand" "=d")
1788         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1789                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1790    (clobber (match_scratch:DI 3 "=x"))]
1791   "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP"
1792   "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
1793   [(set_attr "type" "imul")
1794    (set_attr "mode" "SI")
1795    (set_attr "length" "12")])
1796
1797 (define_insn_and_split "<u>mulsidi3_64bit"
1798   [(set (match_operand:DI 0 "register_operand" "=d")
1799         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1800                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1801    (clobber (match_scratch:TI 3 "=x"))
1802    (clobber (match_scratch:DI 4 "=d"))]
1803   "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3 && !TARGET_MIPS16"
1804   "#"
1805   "&& reload_completed"
1806   [(const_int 0)]
1807 {
1808   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1809                                           operands[2], operands[4]));
1810   DONE;
1811 }
1812   [(set_attr "type" "imul")
1813    (set_attr "mode" "SI")
1814    (set (attr "length")
1815         (if_then_else (match_test "ISA_HAS_EXT_INS")
1816                       (const_int 16)
1817                       (const_int 28)))])
1818
1819 (define_expand "<u>mulsidi3_64bit_mips16"
1820   [(set (match_operand:DI 0 "register_operand")
1821         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1822                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1823   "TARGET_64BIT && TARGET_MIPS16"
1824 {
1825   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1826                                           operands[2], gen_reg_rtx (DImode)));
1827   DONE;
1828 })
1829
1830 (define_expand "<u>mulsidi3_64bit_split"
1831   [(set (match_operand:DI 0 "register_operand")
1832         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1833                  (any_extend:DI (match_operand:SI 2 "register_operand"))))
1834    (clobber (match_operand:DI 3 "register_operand"))]
1835   ""
1836 {
1837   rtx hilo;
1838
1839   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
1840   emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
1841
1842   emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
1843   emit_insn (gen_mfhidi_ti (operands[3], hilo));
1844
1845   if (ISA_HAS_EXT_INS)
1846     emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
1847                            operands[3]));
1848   else
1849     {
1850       /* Zero-extend the low part.  */
1851       mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
1852       mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
1853
1854       /* Shift the high part into place.  */
1855       mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
1856
1857       /* OR the two halves together.  */
1858       mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
1859     }
1860   DONE;
1861 })
1862
1863 (define_insn "<u>mulsidi3_64bit_hilo"
1864   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
1865         (unspec:TI
1866           [(mult:DI
1867              (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1868              (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
1869           UNSPEC_SET_HILO))]
1870   "TARGET_64BIT && !TARGET_FIX_R4000"
1871   "mult<u>\t%1,%2"
1872   [(set_attr "type" "imul")
1873    (set_attr "mode" "SI")])
1874
1875 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
1876 (define_insn "mulsidi3_64bit_dmul"
1877   [(set (match_operand:DI 0 "register_operand" "=d")
1878         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
1879                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1880    (clobber (match_scratch:DI 3 "=l"))]
1881   "TARGET_64BIT && ISA_HAS_DMUL3"
1882   "dmul\t%0,%1,%2"
1883   [(set_attr "type" "imul3")
1884    (set_attr "mode" "DI")])
1885
1886 ;; Widening multiply with negation.
1887 (define_insn "*muls<u>_di"
1888   [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
1889         (neg:DI
1890          (mult:DI
1891           (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1892           (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1893   "!TARGET_64BIT && ISA_HAS_MULS"
1894   "muls<u>\t$0,%1,%2"
1895   [(set_attr "type" "imul")
1896    (set_attr "mode" "SI")])
1897
1898 ;; As well as being named patterns, these instructions are used by the
1899 ;; __builtin_mips_msub<u>() functions.  We must always make those functions
1900 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1901 ;;
1902 ;; This leads to a slight inconsistency.  We honor any tuning overrides
1903 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
1904 ;; even if !ISA_HAS_DSP_MULT.
1905 (define_insn "<u>msubsidi4"
1906   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1907         (minus:DI
1908            (match_operand:DI 3 "muldiv_target_operand" "0")
1909            (mult:DI
1910               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1911               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1912   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
1913 {
1914   if (ISA_HAS_DSP_MULT)
1915     return "msub<u>\t%q0,%1,%2";
1916   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
1917     return "msub<u>\t%1,%2";
1918   else
1919     return "msac<u>\t$0,%1,%2";
1920 }
1921   [(set_attr "type" "imadd")
1922    (set_attr "mode" "SI")])
1923
1924 ;; _highpart patterns
1925
1926 (define_expand "<su>mulsi3_highpart"
1927   [(set (match_operand:SI 0 "register_operand")
1928         (truncate:SI
1929          (lshiftrt:DI
1930           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1931                    (any_extend:DI (match_operand:SI 2 "register_operand")))
1932           (const_int 32))))]
1933   ""
1934 {
1935   if (ISA_HAS_MULHI)
1936     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1937                                                        operands[1],
1938                                                        operands[2]));
1939   else if (TARGET_MIPS16)
1940     emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
1941                                               operands[2]));
1942   else
1943     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1944                                                  operands[2]));
1945   DONE;
1946 })
1947
1948 (define_insn_and_split "<su>mulsi3_highpart_internal"
1949   [(set (match_operand:SI 0 "register_operand" "=d")
1950         (truncate:SI
1951          (lshiftrt:DI
1952           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1953                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1954           (const_int 32))))
1955    (clobber (match_scratch:SI 3 "=l"))]
1956   "!ISA_HAS_MULHI && !TARGET_MIPS16"
1957   { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
1958   "&& reload_completed && !TARGET_FIX_R4000"
1959   [(const_int 0)]
1960 {
1961   emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
1962                                             operands[2]));
1963   DONE;
1964 }
1965   [(set_attr "type" "imul")
1966    (set_attr "mode" "SI")
1967    (set_attr "length" "8")])
1968
1969 (define_expand "<su>mulsi3_highpart_split"
1970   [(set (match_operand:SI 0 "register_operand")
1971         (truncate:SI
1972          (lshiftrt:DI
1973           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1974                    (any_extend:DI (match_operand:SI 2 "register_operand")))
1975           (const_int 32))))]
1976   ""
1977 {
1978   rtx hilo;
1979
1980   if (TARGET_64BIT)
1981     {
1982       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
1983       emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
1984       emit_insn (gen_mfhisi_ti (operands[0], hilo));
1985     }
1986   else
1987     {
1988       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1989       emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1990       emit_insn (gen_mfhisi_di (operands[0], hilo));
1991     }
1992   DONE;
1993 })
1994
1995 (define_insn "<su>mulsi3_highpart_mulhi_internal"
1996   [(set (match_operand:SI 0 "register_operand" "=d")
1997         (truncate:SI
1998          (lshiftrt:DI
1999           (mult:DI
2000            (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2001            (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2002           (const_int 32))))
2003    (clobber (match_scratch:SI 3 "=l"))]
2004   "ISA_HAS_MULHI"
2005   "mulhi<u>\t%0,%1,%2"
2006   [(set_attr "type" "imul3")
2007    (set_attr "mode" "SI")])
2008
2009 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2010   [(set (match_operand:SI 0 "register_operand" "=d")
2011         (truncate:SI
2012          (lshiftrt:DI
2013           (neg:DI
2014            (mult:DI
2015             (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2016             (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2017           (const_int 32))))
2018    (clobber (match_scratch:SI 3 "=l"))]
2019   "ISA_HAS_MULHI"
2020   "mulshi<u>\t%0,%1,%2"
2021   [(set_attr "type" "imul3")
2022    (set_attr "mode" "SI")])
2023
2024 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
2025 ;; errata MD(0), which says that dmultu does not always produce the
2026 ;; correct result.
2027 (define_expand "<su>muldi3_highpart"
2028   [(set (match_operand:DI 0 "register_operand")
2029         (truncate:DI
2030          (lshiftrt:TI
2031           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2032                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2033           (const_int 64))))]
2034   "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2035 {
2036   if (TARGET_MIPS16)
2037     emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2038                                               operands[2]));
2039   else
2040     emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2041                                                  operands[2]));
2042   DONE;
2043 })
2044
2045 (define_insn_and_split "<su>muldi3_highpart_internal"
2046   [(set (match_operand:DI 0 "register_operand" "=d")
2047         (truncate:DI
2048          (lshiftrt:TI
2049           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2050                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2051           (const_int 64))))
2052    (clobber (match_scratch:DI 3 "=l"))]
2053   "TARGET_64BIT
2054    && !TARGET_MIPS16
2055    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2056   { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2057   "&& reload_completed && !TARGET_FIX_R4000"
2058   [(const_int 0)]
2059 {
2060   emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2061                                             operands[2]));
2062   DONE;
2063 }
2064   [(set_attr "type" "imul")
2065    (set_attr "mode" "DI")
2066    (set_attr "length" "8")])
2067
2068 (define_expand "<su>muldi3_highpart_split"
2069   [(set (match_operand:DI 0 "register_operand")
2070         (truncate:DI
2071          (lshiftrt:TI
2072           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2073                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2074           (const_int 64))))]
2075   ""
2076 {
2077   rtx hilo;
2078
2079   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2080   emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2081   emit_insn (gen_mfhidi_ti (operands[0], hilo));
2082   DONE;
2083 })
2084
2085 (define_expand "<u>mulditi3"
2086   [(set (match_operand:TI 0 "register_operand")
2087         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2088                  (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2089   "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2090 {
2091   rtx hilo;
2092
2093   if (TARGET_MIPS16)
2094     {
2095       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2096       emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2097       emit_move_insn (operands[0], hilo);
2098     }
2099   else if (TARGET_FIX_R4000)
2100     emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2101   else
2102     emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2103                                          operands[2]));
2104   DONE;
2105 })
2106
2107 (define_insn "<u>mulditi3_internal"
2108   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2109         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2110                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2111   "TARGET_64BIT
2112    && !TARGET_FIX_R4000
2113    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2114   "dmult<u>\t%1,%2"
2115   [(set_attr "type" "imul")
2116    (set_attr "mode" "DI")])
2117
2118 (define_insn "<u>mulditi3_r4000"
2119   [(set (match_operand:TI 0 "register_operand" "=d")
2120         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2121                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2122    (clobber (match_scratch:TI 3 "=x"))]
2123   "TARGET_64BIT
2124    && TARGET_FIX_R4000
2125    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2126   "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2127   [(set_attr "type" "imul")
2128    (set_attr "mode" "DI")
2129    (set_attr "length" "12")])
2130
2131 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2132 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
2133
2134 (define_insn "madsi"
2135   [(set (match_operand:SI 0 "register_operand" "+l")
2136         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2137                           (match_operand:SI 2 "register_operand" "d"))
2138                  (match_dup 0)))]
2139   "TARGET_MAD"
2140   "mad\t%1,%2"
2141   [(set_attr "type"     "imadd")
2142    (set_attr "mode"     "SI")])
2143
2144 ;; See the comment above <u>msubsidi4 for the relationship between
2145 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2146 (define_insn "<u>maddsidi4"
2147   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2148         (plus:DI
2149          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2150                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2151          (match_operand:DI 3 "muldiv_target_operand" "0")))]
2152   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2153    && !TARGET_64BIT"
2154 {
2155   if (TARGET_MAD)
2156     return "mad<u>\t%1,%2";
2157   else if (ISA_HAS_DSP_MULT)
2158     return "madd<u>\t%q0,%1,%2";
2159   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2160     return "madd<u>\t%1,%2";
2161   else
2162     /* See comment in *macc.  */
2163     return "%[macc<u>\t%@,%1,%2%]";
2164 }
2165   [(set_attr "type" "imadd")
2166    (set_attr "mode" "SI")])
2167
2168 ;; Floating point multiply accumulate instructions.
2169
2170 (define_insn "*madd4<mode>"
2171   [(set (match_operand:ANYF 0 "register_operand" "=f")
2172         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2173                               (match_operand:ANYF 2 "register_operand" "f"))
2174                    (match_operand:ANYF 3 "register_operand" "f")))]
2175   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2176   "madd.<fmt>\t%0,%3,%1,%2"
2177   [(set_attr "type" "fmadd")
2178    (set_attr "mode" "<UNITMODE>")])
2179
2180 (define_insn "*madd3<mode>"
2181   [(set (match_operand:ANYF 0 "register_operand" "=f")
2182         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2183                               (match_operand:ANYF 2 "register_operand" "f"))
2184                    (match_operand:ANYF 3 "register_operand" "0")))]
2185   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2186   "madd.<fmt>\t%0,%1,%2"
2187   [(set_attr "type" "fmadd")
2188    (set_attr "mode" "<UNITMODE>")])
2189
2190 (define_insn "*msub4<mode>"
2191   [(set (match_operand:ANYF 0 "register_operand" "=f")
2192         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2193                                (match_operand:ANYF 2 "register_operand" "f"))
2194                     (match_operand:ANYF 3 "register_operand" "f")))]
2195   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2196   "msub.<fmt>\t%0,%3,%1,%2"
2197   [(set_attr "type" "fmadd")
2198    (set_attr "mode" "<UNITMODE>")])
2199
2200 (define_insn "*msub3<mode>"
2201   [(set (match_operand:ANYF 0 "register_operand" "=f")
2202         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2203                                (match_operand:ANYF 2 "register_operand" "f"))
2204                     (match_operand:ANYF 3 "register_operand" "0")))]
2205   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2206   "msub.<fmt>\t%0,%1,%2"
2207   [(set_attr "type" "fmadd")
2208    (set_attr "mode" "<UNITMODE>")])
2209
2210 (define_insn "*nmadd4<mode>"
2211   [(set (match_operand:ANYF 0 "register_operand" "=f")
2212         (neg:ANYF (plus:ANYF
2213                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2214                               (match_operand:ANYF 2 "register_operand" "f"))
2215                    (match_operand:ANYF 3 "register_operand" "f"))))]
2216   "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2217    && TARGET_FUSED_MADD
2218    && HONOR_SIGNED_ZEROS (<MODE>mode)
2219    && !HONOR_NANS (<MODE>mode)"
2220   "nmadd.<fmt>\t%0,%3,%1,%2"
2221   [(set_attr "type" "fmadd")
2222    (set_attr "mode" "<UNITMODE>")])
2223
2224 (define_insn "*nmadd3<mode>"
2225   [(set (match_operand:ANYF 0 "register_operand" "=f")
2226         (neg:ANYF (plus:ANYF
2227                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2228                               (match_operand:ANYF 2 "register_operand" "f"))
2229                    (match_operand:ANYF 3 "register_operand" "0"))))]
2230   "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2231    && TARGET_FUSED_MADD
2232    && HONOR_SIGNED_ZEROS (<MODE>mode)
2233    && !HONOR_NANS (<MODE>mode)"
2234   "nmadd.<fmt>\t%0,%1,%2"
2235   [(set_attr "type" "fmadd")
2236    (set_attr "mode" "<UNITMODE>")])
2237
2238 (define_insn "*nmadd4<mode>_fastmath"
2239   [(set (match_operand:ANYF 0 "register_operand" "=f")
2240         (minus:ANYF
2241          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2242                     (match_operand:ANYF 2 "register_operand" "f"))
2243          (match_operand:ANYF 3 "register_operand" "f")))]
2244   "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2245    && TARGET_FUSED_MADD
2246    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2247    && !HONOR_NANS (<MODE>mode)"
2248   "nmadd.<fmt>\t%0,%3,%1,%2"
2249   [(set_attr "type" "fmadd")
2250    (set_attr "mode" "<UNITMODE>")])
2251
2252 (define_insn "*nmadd3<mode>_fastmath"
2253   [(set (match_operand:ANYF 0 "register_operand" "=f")
2254         (minus:ANYF
2255          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2256                     (match_operand:ANYF 2 "register_operand" "f"))
2257          (match_operand:ANYF 3 "register_operand" "0")))]
2258   "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2259    && TARGET_FUSED_MADD
2260    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2261    && !HONOR_NANS (<MODE>mode)"
2262   "nmadd.<fmt>\t%0,%1,%2"
2263   [(set_attr "type" "fmadd")
2264    (set_attr "mode" "<UNITMODE>")])
2265
2266 (define_insn "*nmsub4<mode>"
2267   [(set (match_operand:ANYF 0 "register_operand" "=f")
2268         (neg:ANYF (minus:ANYF
2269                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2270                               (match_operand:ANYF 3 "register_operand" "f"))
2271                    (match_operand:ANYF 1 "register_operand" "f"))))]
2272   "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2273    && TARGET_FUSED_MADD
2274    && HONOR_SIGNED_ZEROS (<MODE>mode)
2275    && !HONOR_NANS (<MODE>mode)"
2276   "nmsub.<fmt>\t%0,%1,%2,%3"
2277   [(set_attr "type" "fmadd")
2278    (set_attr "mode" "<UNITMODE>")])
2279
2280 (define_insn "*nmsub3<mode>"
2281   [(set (match_operand:ANYF 0 "register_operand" "=f")
2282         (neg:ANYF (minus:ANYF
2283                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2284                               (match_operand:ANYF 3 "register_operand" "f"))
2285                    (match_operand:ANYF 1 "register_operand" "0"))))]
2286   "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2287    && TARGET_FUSED_MADD
2288    && HONOR_SIGNED_ZEROS (<MODE>mode)
2289    && !HONOR_NANS (<MODE>mode)"
2290   "nmsub.<fmt>\t%0,%1,%2"
2291   [(set_attr "type" "fmadd")
2292    (set_attr "mode" "<UNITMODE>")])
2293
2294 (define_insn "*nmsub4<mode>_fastmath"
2295   [(set (match_operand:ANYF 0 "register_operand" "=f")
2296         (minus:ANYF
2297          (match_operand:ANYF 1 "register_operand" "f")
2298          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2299                     (match_operand:ANYF 3 "register_operand" "f"))))]
2300   "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2301    && TARGET_FUSED_MADD
2302    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2303    && !HONOR_NANS (<MODE>mode)"
2304   "nmsub.<fmt>\t%0,%1,%2,%3"
2305   [(set_attr "type" "fmadd")
2306    (set_attr "mode" "<UNITMODE>")])
2307
2308 (define_insn "*nmsub3<mode>_fastmath"
2309   [(set (match_operand:ANYF 0 "register_operand" "=f")
2310         (minus:ANYF
2311          (match_operand:ANYF 1 "register_operand" "f")
2312          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2313                     (match_operand:ANYF 3 "register_operand" "0"))))]
2314   "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2315    && TARGET_FUSED_MADD
2316    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2317    && !HONOR_NANS (<MODE>mode)"
2318   "nmsub.<fmt>\t%0,%1,%2"
2319   [(set_attr "type" "fmadd")
2320    (set_attr "mode" "<UNITMODE>")])
2321
2322 ;;
2323 ;;  ....................
2324 ;;
2325 ;;      DIVISION and REMAINDER
2326 ;;
2327 ;;  ....................
2328 ;;
2329
2330 (define_expand "div<mode>3"
2331   [(set (match_operand:ANYF 0 "register_operand")
2332         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2333                   (match_operand:ANYF 2 "register_operand")))]
2334   "<divide_condition>"
2335 {
2336   if (const_1_operand (operands[1], <MODE>mode))
2337     if (!(<recip_condition> && flag_unsafe_math_optimizations))
2338       operands[1] = force_reg (<MODE>mode, operands[1]);
2339 })
2340
2341 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2342 ;;
2343 ;; If an mfc1 or dmfc1 happens to access the floating point register
2344 ;; file at the same time a long latency operation (div, sqrt, recip,
2345 ;; sqrt) iterates an intermediate result back through the floating
2346 ;; point register file bypass, then instead returning the correct
2347 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2348 ;; result of the long latency operation.
2349 ;;
2350 ;; The workaround is to insert an unconditional 'mov' from/to the
2351 ;; long latency op destination register.
2352
2353 (define_insn "*div<mode>3"
2354   [(set (match_operand:ANYF 0 "register_operand" "=f")
2355         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2356                   (match_operand:ANYF 2 "register_operand" "f")))]
2357   "<divide_condition>"
2358 {
2359   if (TARGET_FIX_SB1)
2360     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2361   else
2362     return "div.<fmt>\t%0,%1,%2";
2363 }
2364   [(set_attr "type" "fdiv")
2365    (set_attr "mode" "<UNITMODE>")
2366    (set (attr "length")
2367         (if_then_else (match_test "TARGET_FIX_SB1")
2368                       (const_int 8)
2369                       (const_int 4)))])
2370
2371 (define_insn "*recip<mode>3"
2372   [(set (match_operand:ANYF 0 "register_operand" "=f")
2373         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2374                   (match_operand:ANYF 2 "register_operand" "f")))]
2375   "<recip_condition> && flag_unsafe_math_optimizations"
2376 {
2377   if (TARGET_FIX_SB1)
2378     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2379   else
2380     return "recip.<fmt>\t%0,%2";
2381 }
2382   [(set_attr "type" "frdiv")
2383    (set_attr "mode" "<UNITMODE>")
2384    (set (attr "length")
2385         (if_then_else (match_test "TARGET_FIX_SB1")
2386                       (const_int 8)
2387                       (const_int 4)))])
2388
2389 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2390 ;; with negative operands.  We use special libgcc functions instead.
2391 (define_expand "divmod<mode>4"
2392   [(set (match_operand:GPR 0 "register_operand")
2393         (div:GPR (match_operand:GPR 1 "register_operand")
2394                  (match_operand:GPR 2 "register_operand")))
2395    (set (match_operand:GPR 3 "register_operand")
2396         (mod:GPR (match_dup 1)
2397                  (match_dup 2)))]
2398   "!TARGET_FIX_VR4120"
2399 {
2400   if (TARGET_MIPS16)
2401     {
2402       emit_insn (gen_divmod<mode>4_split (operands[3], operands[1],
2403                                           operands[2]));
2404       emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2405     }
2406   else
2407     emit_insn (gen_divmod<mode>4_internal (operands[0], operands[1],
2408                                            operands[2], operands[3]));
2409   DONE;
2410 })
2411
2412 (define_insn_and_split "divmod<mode>4_internal"
2413   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2414         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2415                  (match_operand:GPR 2 "register_operand" "d")))
2416    (set (match_operand:GPR 3 "register_operand" "=d")
2417         (mod:GPR (match_dup 1)
2418                  (match_dup 2)))]
2419   "!TARGET_FIX_VR4120 && !TARGET_MIPS16"
2420   "#"
2421   "&& reload_completed"
2422   [(const_int 0)]
2423 {
2424   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2425   DONE;
2426 }
2427  [(set_attr "type" "idiv")
2428   (set_attr "mode" "<MODE>")
2429   (set_attr "length" "8")])
2430
2431 (define_expand "udivmod<mode>4"
2432   [(set (match_operand:GPR 0 "register_operand")
2433         (udiv:GPR (match_operand:GPR 1 "register_operand")
2434                   (match_operand:GPR 2 "register_operand")))
2435    (set (match_operand:GPR 3 "register_operand")
2436         (umod:GPR (match_dup 1)
2437                   (match_dup 2)))]
2438   ""
2439 {
2440   if (TARGET_MIPS16)
2441     {
2442       emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1],
2443                                            operands[2]));
2444       emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2445     }
2446   else
2447     emit_insn (gen_udivmod<mode>4_internal (operands[0], operands[1],
2448                                             operands[2], operands[3]));
2449   DONE;
2450 })
2451
2452 (define_insn_and_split "udivmod<mode>4_internal"
2453   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2454         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2455                   (match_operand:GPR 2 "register_operand" "d")))
2456    (set (match_operand:GPR 3 "register_operand" "=d")
2457         (umod:GPR (match_dup 1)
2458                   (match_dup 2)))]
2459   "!TARGET_MIPS16"
2460   "#"
2461   "reload_completed"
2462   [(const_int 0)]
2463 {
2464   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2465   DONE;
2466 }
2467  [(set_attr "type" "idiv")
2468   (set_attr "mode" "<MODE>")
2469   (set_attr "length" "8")])
2470
2471 (define_expand "<u>divmod<mode>4_split"
2472   [(set (match_operand:GPR 0 "register_operand")
2473         (any_mod:GPR (match_operand:GPR 1 "register_operand")
2474                      (match_operand:GPR 2 "register_operand")))]
2475   ""
2476 {
2477   rtx hilo;
2478
2479   if (TARGET_64BIT)
2480     {
2481       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2482       emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2483                                                operands[2]));
2484       emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2485     }
2486   else
2487     {
2488       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2489       emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2490                                                operands[2]));
2491       emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2492     }
2493   DONE;
2494 })
2495
2496 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2497   [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2498         (unspec:HILO
2499           [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2500                         (match_operand:GPR 2 "register_operand" "d"))]
2501           UNSPEC_SET_HILO))]
2502   ""
2503   { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2504   [(set_attr "type" "idiv")
2505    (set_attr "mode" "<GPR:MODE>")])
2506 \f
2507 ;;
2508 ;;  ....................
2509 ;;
2510 ;;      SQUARE ROOT
2511 ;;
2512 ;;  ....................
2513
2514 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2515 ;; "*div[sd]f3" comment for details).
2516
2517 (define_insn "sqrt<mode>2"
2518   [(set (match_operand:ANYF 0 "register_operand" "=f")
2519         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2520   "<sqrt_condition>"
2521 {
2522   if (TARGET_FIX_SB1)
2523     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2524   else
2525     return "sqrt.<fmt>\t%0,%1";
2526 }
2527   [(set_attr "type" "fsqrt")
2528    (set_attr "mode" "<UNITMODE>")
2529    (set (attr "length")
2530         (if_then_else (match_test "TARGET_FIX_SB1")
2531                       (const_int 8)
2532                       (const_int 4)))])
2533
2534 (define_insn "*rsqrt<mode>a"
2535   [(set (match_operand:ANYF 0 "register_operand" "=f")
2536         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2537                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2538   "<recip_condition> && flag_unsafe_math_optimizations"
2539 {
2540   if (TARGET_FIX_SB1)
2541     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2542   else
2543     return "rsqrt.<fmt>\t%0,%2";
2544 }
2545   [(set_attr "type" "frsqrt")
2546    (set_attr "mode" "<UNITMODE>")
2547    (set (attr "length")
2548         (if_then_else (match_test "TARGET_FIX_SB1")
2549                       (const_int 8)
2550                       (const_int 4)))])
2551
2552 (define_insn "*rsqrt<mode>b"
2553   [(set (match_operand:ANYF 0 "register_operand" "=f")
2554         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2555                              (match_operand:ANYF 2 "register_operand" "f"))))]
2556   "<recip_condition> && flag_unsafe_math_optimizations"
2557 {
2558   if (TARGET_FIX_SB1)
2559     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2560   else
2561     return "rsqrt.<fmt>\t%0,%2";
2562 }
2563   [(set_attr "type" "frsqrt")
2564    (set_attr "mode" "<UNITMODE>")
2565    (set (attr "length")
2566         (if_then_else (match_test "TARGET_FIX_SB1")
2567                       (const_int 8)
2568                       (const_int 4)))])
2569 \f
2570 ;;
2571 ;;  ....................
2572 ;;
2573 ;;      ABSOLUTE VALUE
2574 ;;
2575 ;;  ....................
2576
2577 ;; Do not use the integer abs macro instruction, since that signals an
2578 ;; exception on -2147483648 (sigh).
2579
2580 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2581 ;; invalid; it does not clear their sign bits.  We therefore can't use
2582 ;; abs.fmt if the signs of NaNs matter.
2583
2584 (define_insn "abs<mode>2"
2585   [(set (match_operand:ANYF 0 "register_operand" "=f")
2586         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2587   "!HONOR_NANS (<MODE>mode)"
2588   "abs.<fmt>\t%0,%1"
2589   [(set_attr "type" "fabs")
2590    (set_attr "mode" "<UNITMODE>")])
2591 \f
2592 ;;
2593 ;;  ...................
2594 ;;
2595 ;;  Count leading zeroes.
2596 ;;
2597 ;;  ...................
2598 ;;
2599
2600 (define_insn "clz<mode>2"
2601   [(set (match_operand:GPR 0 "register_operand" "=d")
2602         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2603   "ISA_HAS_CLZ_CLO"
2604   "<d>clz\t%0,%1"
2605   [(set_attr "type" "clz")
2606    (set_attr "mode" "<MODE>")])
2607
2608 ;;
2609 ;;  ...................
2610 ;;
2611 ;;  Count number of set bits.
2612 ;;
2613 ;;  ...................
2614 ;;
2615
2616 (define_insn "popcount<mode>2"
2617   [(set (match_operand:GPR 0 "register_operand" "=d")
2618         (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
2619   "ISA_HAS_POP"
2620   "<d>pop\t%0,%1"
2621   [(set_attr "type" "pop")
2622    (set_attr "mode" "<MODE>")])
2623 \f
2624 ;;
2625 ;;  ....................
2626 ;;
2627 ;;      NEGATION and ONE'S COMPLEMENT
2628 ;;
2629 ;;  ....................
2630
2631 (define_insn "negsi2"
2632   [(set (match_operand:SI 0 "register_operand" "=d")
2633         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2634   ""
2635 {
2636   if (TARGET_MIPS16)
2637     return "neg\t%0,%1";
2638   else
2639     return "subu\t%0,%.,%1";
2640 }
2641   [(set_attr "alu_type" "sub")
2642    (set_attr "mode"     "SI")])
2643
2644 (define_insn "negdi2"
2645   [(set (match_operand:DI 0 "register_operand" "=d")
2646         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2647   "TARGET_64BIT && !TARGET_MIPS16"
2648   "dsubu\t%0,%.,%1"
2649   [(set_attr "alu_type" "sub")
2650    (set_attr "mode"     "DI")])
2651
2652 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2653 ;; invalid; it does not flip their sign bit.  We therefore can't use
2654 ;; neg.fmt if the signs of NaNs matter.
2655
2656 (define_insn "neg<mode>2"
2657   [(set (match_operand:ANYF 0 "register_operand" "=f")
2658         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2659   "!HONOR_NANS (<MODE>mode)"
2660   "neg.<fmt>\t%0,%1"
2661   [(set_attr "type" "fneg")
2662    (set_attr "mode" "<UNITMODE>")])
2663
2664 (define_insn "one_cmpl<mode>2"
2665   [(set (match_operand:GPR 0 "register_operand" "=d")
2666         (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
2667   ""
2668 {
2669   if (TARGET_MIPS16)
2670     return "not\t%0,%1";
2671   else
2672     return "nor\t%0,%.,%1";
2673 }
2674   [(set_attr "alu_type" "not")
2675    (set_attr "mode" "<MODE>")])
2676 \f
2677 ;;
2678 ;;  ....................
2679 ;;
2680 ;;      LOGICAL
2681 ;;
2682 ;;  ....................
2683 ;;
2684
2685 ;; Many of these instructions use trivial define_expands, because we
2686 ;; want to use a different set of constraints when TARGET_MIPS16.
2687
2688 (define_expand "and<mode>3"
2689   [(set (match_operand:GPR 0 "register_operand")
2690         (and:GPR (match_operand:GPR 1 "register_operand")
2691                  (match_operand:GPR 2 "and_reg_operand")))])
2692
2693 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
2694 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
2695 ;; Note that this variant does not trigger for SI mode because we require
2696 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
2697 ;; sign-extended SImode value.
2698 ;;
2699 ;; These are possible combinations for operand 1 and 2.  The table
2700 ;; includes both MIPS and MIPS16 cases.  (r=register, mem=memory,
2701 ;; 16=MIPS16, x=match, S=split):
2702 ;;
2703 ;;     \ op1    r/EXT   r/!EXT  mem   r/16   mem/16
2704 ;;  op2
2705 ;;
2706 ;;  andi           x     x
2707 ;;  0xff           x     x       x             x
2708 ;;  0xffff         x     x       x             x
2709 ;;  0xffff_ffff    x     S       x     S       x
2710 ;;  low-bitmask    x
2711 ;;  register       x     x
2712 ;;  register =op1                      x
2713
2714 (define_insn "*and<mode>3"
2715   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d,d,d")
2716         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,d,d,d,d")
2717                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,K,Yx,Yw,d")))]
2718   "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2719 {
2720   int len;
2721
2722   switch (which_alternative)
2723     {
2724     case 0:
2725       operands[1] = gen_lowpart (QImode, operands[1]);
2726       return "lbu\t%0,%1";
2727     case 1:
2728       operands[1] = gen_lowpart (HImode, operands[1]);
2729       return "lhu\t%0,%1";
2730     case 2:
2731       operands[1] = gen_lowpart (SImode, operands[1]);
2732       return "lwu\t%0,%1";
2733     case 3:
2734       return "andi\t%0,%1,%x2";
2735     case 4:
2736       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
2737       operands[2] = GEN_INT (len);
2738       return "<d>ext\t%0,%1,0,%2";
2739     case 5:
2740       return "#";
2741     case 6:
2742       return "and\t%0,%1,%2";
2743     default:
2744       gcc_unreachable ();
2745     }
2746 }
2747   [(set_attr "move_type" "load,load,load,andi,ext_ins,shift_shift,logical")
2748    (set_attr "mode" "<MODE>")])
2749
2750 (define_insn "*and<mode>3_mips16"
2751   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
2752         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%o,o,W,d,0")
2753                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
2754   "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2755 {
2756   switch (which_alternative)
2757     {
2758     case 0:
2759       operands[1] = gen_lowpart (QImode, operands[1]);
2760       return "lbu\t%0,%1";
2761     case 1:
2762       operands[1] = gen_lowpart (HImode, operands[1]);
2763       return "lhu\t%0,%1";
2764     case 2:
2765       operands[1] = gen_lowpart (SImode, operands[1]);
2766       return "lwu\t%0,%1";
2767     case 3:
2768       return "#";
2769     case 4:
2770       return "and\t%0,%2";
2771     default:
2772       gcc_unreachable ();
2773     }
2774 }
2775   [(set_attr "move_type" "load,load,load,shift_shift,logical")
2776    (set_attr "mode" "<MODE>")])
2777
2778 (define_expand "ior<mode>3"
2779   [(set (match_operand:GPR 0 "register_operand")
2780         (ior:GPR (match_operand:GPR 1 "register_operand")
2781                  (match_operand:GPR 2 "uns_arith_operand")))]
2782   ""
2783 {
2784   if (TARGET_MIPS16)
2785     operands[2] = force_reg (<MODE>mode, operands[2]);
2786 })
2787
2788 (define_insn "*ior<mode>3"
2789   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2790         (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2791                  (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2792   "!TARGET_MIPS16"
2793   "@
2794    or\t%0,%1,%2
2795    ori\t%0,%1,%x2"
2796   [(set_attr "alu_type" "or")
2797    (set_attr "mode" "<MODE>")])
2798
2799 (define_insn "*ior<mode>3_mips16"
2800   [(set (match_operand:GPR 0 "register_operand" "=d")
2801         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2802                  (match_operand:GPR 2 "register_operand" "d")))]
2803   "TARGET_MIPS16"
2804   "or\t%0,%2"
2805   [(set_attr "alu_type" "or")
2806    (set_attr "mode" "<MODE>")])
2807
2808 (define_expand "xor<mode>3"
2809   [(set (match_operand:GPR 0 "register_operand")
2810         (xor:GPR (match_operand:GPR 1 "register_operand")
2811                  (match_operand:GPR 2 "uns_arith_operand")))]
2812   ""
2813   "")
2814
2815 (define_insn ""
2816   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2817         (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2818                  (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2819   "!TARGET_MIPS16"
2820   "@
2821    xor\t%0,%1,%2
2822    xori\t%0,%1,%x2"
2823   [(set_attr "alu_type" "xor")
2824    (set_attr "mode" "<MODE>")])
2825
2826 (define_insn ""
2827   [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2828         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2829                  (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2830   "TARGET_MIPS16"
2831   "@
2832    xor\t%0,%2
2833    cmpi\t%1,%2
2834    cmp\t%1,%2"
2835   [(set_attr "alu_type" "xor")
2836    (set_attr "mode" "<MODE>")
2837    (set_attr_alternative "length"
2838                 [(const_int 4)
2839                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2840                                (const_int 4)
2841                                (const_int 8))
2842                  (const_int 4)])])
2843
2844 (define_insn "*nor<mode>3"
2845   [(set (match_operand:GPR 0 "register_operand" "=d")
2846         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2847                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2848   "!TARGET_MIPS16"
2849   "nor\t%0,%1,%2"
2850   [(set_attr "alu_type" "nor")
2851    (set_attr "mode" "<MODE>")])
2852 \f
2853 ;;
2854 ;;  ....................
2855 ;;
2856 ;;      TRUNCATION
2857 ;;
2858 ;;  ....................
2859
2860
2861
2862 (define_insn "truncdfsf2"
2863   [(set (match_operand:SF 0 "register_operand" "=f")
2864         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2865   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2866   "cvt.s.d\t%0,%1"
2867   [(set_attr "type"     "fcvt")
2868    (set_attr "cnv_mode" "D2S")   
2869    (set_attr "mode"     "SF")])
2870
2871 ;; Integer truncation patterns.  Truncating SImode values to smaller
2872 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
2873 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
2874 ;; need to make sure that the lower 32 bits are properly sign-extended
2875 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
2876 ;; smaller than SImode is equivalent to two separate truncations:
2877 ;;
2878 ;;                        A       B
2879 ;;    DI ---> HI  ==  DI ---> SI ---> HI
2880 ;;    DI ---> QI  ==  DI ---> SI ---> QI
2881 ;;
2882 ;; Step A needs a real instruction but step B does not.
2883
2884 (define_insn "truncdi<mode>2"
2885   [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
2886         (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
2887   "TARGET_64BIT"
2888   "@
2889     sll\t%0,%1,0
2890     <store>\t%1,%0"
2891   [(set_attr "move_type" "sll0,store")
2892    (set_attr "mode" "SI")])
2893
2894 ;; Combiner patterns to optimize shift/truncate combinations.
2895
2896 (define_insn "*ashr_trunc<mode>"
2897   [(set (match_operand:SUBDI 0 "register_operand" "=d")
2898         (truncate:SUBDI
2899           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
2900                        (match_operand:DI 2 "const_arith_operand" ""))))]
2901   "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
2902   "dsra\t%0,%1,%2"
2903   [(set_attr "type" "shift")
2904    (set_attr "mode" "<MODE>")])
2905
2906 (define_insn "*lshr32_trunc<mode>"
2907   [(set (match_operand:SUBDI 0 "register_operand" "=d")
2908         (truncate:SUBDI
2909           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2910                        (const_int 32))))]
2911   "TARGET_64BIT && !TARGET_MIPS16"
2912   "dsra\t%0,%1,32"
2913   [(set_attr "type" "shift")
2914    (set_attr "mode" "<MODE>")])
2915
2916 ;; Logical shift by more than 32 results in proper SI values so truncation is
2917 ;; removed by the middle end.  Note that a logical shift by 32 is handled by
2918 ;; the previous pattern.
2919 (define_insn "*<optab>_trunc<mode>_exts"
2920   [(set (match_operand:SUBDI 0 "register_operand" "=d")
2921         (truncate:SUBDI
2922          (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
2923                          (match_operand:DI 2 "const_arith_operand" ""))))]
2924   "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
2925   "exts\t%0,%1,%2,31"
2926   [(set_attr "type" "arith")
2927    (set_attr "mode" "<MODE>")])
2928 \f
2929 ;;
2930 ;;  ....................
2931 ;;
2932 ;;      ZERO EXTENSION
2933 ;;
2934 ;;  ....................
2935
2936 ;; Extension insns.
2937
2938 (define_expand "zero_extendsidi2"
2939   [(set (match_operand:DI 0 "register_operand")
2940         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
2941   "TARGET_64BIT")
2942
2943 (define_insn_and_split "*zero_extendsidi2"
2944   [(set (match_operand:DI 0 "register_operand" "=d,d")
2945         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2946   "TARGET_64BIT && !ISA_HAS_EXT_INS"
2947   "@
2948    #
2949    lwu\t%0,%1"
2950   "&& reload_completed && REG_P (operands[1])"
2951   [(set (match_dup 0)
2952         (ashift:DI (match_dup 1) (const_int 32)))
2953    (set (match_dup 0)
2954         (lshiftrt:DI (match_dup 0) (const_int 32)))]
2955   { operands[1] = gen_lowpart (DImode, operands[1]); }
2956   [(set_attr "move_type" "shift_shift,load")
2957    (set_attr "mode" "DI")])
2958
2959 (define_insn "*zero_extendsidi2_dext"
2960   [(set (match_operand:DI 0 "register_operand" "=d,d")
2961         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2962   "TARGET_64BIT && ISA_HAS_EXT_INS"
2963   "@
2964    dext\t%0,%1,0,32
2965    lwu\t%0,%1"
2966   [(set_attr "move_type" "arith,load")
2967    (set_attr "mode" "DI")])
2968
2969 ;; See the comment before the *and<mode>3 pattern why this is generated by
2970 ;; combine.
2971
2972 (define_split
2973   [(set (match_operand:DI 0 "register_operand")
2974         (and:DI (match_operand:DI 1 "register_operand")
2975                 (const_int 4294967295)))]
2976   "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
2977   [(set (match_dup 0)
2978         (ashift:DI (match_dup 1) (const_int 32)))
2979    (set (match_dup 0)
2980         (lshiftrt:DI (match_dup 0) (const_int 32)))])
2981
2982 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
2983   [(set (match_operand:GPR 0 "register_operand")
2984         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2985   ""
2986 {
2987   if (TARGET_MIPS16 && !GENERATE_MIPS16E
2988       && !memory_operand (operands[1], <SHORT:MODE>mode))
2989     {
2990       emit_insn (gen_and<GPR:mode>3 (operands[0],
2991                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
2992                                      force_reg (<GPR:MODE>mode,
2993                                                 GEN_INT (<SHORT:mask>))));
2994       DONE;
2995     }
2996 })
2997
2998 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2999   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3000         (zero_extend:GPR
3001              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3002   "!TARGET_MIPS16"
3003   "@
3004    andi\t%0,%1,<SHORT:mask>
3005    l<SHORT:size>u\t%0,%1"
3006   [(set_attr "move_type" "andi,load")
3007    (set_attr "mode" "<GPR:MODE>")])
3008
3009 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3010   [(set (match_operand:GPR 0 "register_operand" "=d")
3011         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3012   "GENERATE_MIPS16E"
3013   "ze<SHORT:size>\t%0"
3014   ;; This instruction is effectively a special encoding of ANDI.
3015   [(set_attr "move_type" "andi")
3016    (set_attr "mode" "<GPR:MODE>")])
3017
3018 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3019   [(set (match_operand:GPR 0 "register_operand" "=d")
3020         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3021   "TARGET_MIPS16"
3022   "l<SHORT:size>u\t%0,%1"
3023   [(set_attr "move_type" "load")
3024    (set_attr "mode" "<GPR:MODE>")])
3025
3026 (define_expand "zero_extendqihi2"
3027   [(set (match_operand:HI 0 "register_operand")
3028         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3029   ""
3030 {
3031   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3032     {
3033       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3034                                        operands[1]));
3035       DONE;
3036     }
3037 })
3038
3039 (define_insn "*zero_extendqihi2"
3040   [(set (match_operand:HI 0 "register_operand" "=d,d")
3041         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3042   "!TARGET_MIPS16"
3043   "@
3044    andi\t%0,%1,0x00ff
3045    lbu\t%0,%1"
3046   [(set_attr "move_type" "andi,load")
3047    (set_attr "mode" "HI")])
3048
3049 (define_insn "*zero_extendqihi2_mips16"
3050   [(set (match_operand:HI 0 "register_operand" "=d")
3051         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3052   "TARGET_MIPS16"
3053   "lbu\t%0,%1"
3054   [(set_attr "move_type" "load")
3055    (set_attr "mode" "HI")])
3056
3057 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3058
3059 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3060   [(set (match_operand:GPR 0 "register_operand" "=d")
3061         (zero_extend:GPR
3062             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3063   "TARGET_64BIT && !TARGET_MIPS16"
3064 {
3065   operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3066   return "andi\t%0,%1,%x2";
3067 }
3068   [(set_attr "alu_type" "and")
3069    (set_attr "mode" "<GPR:MODE>")])
3070
3071 (define_insn "*zero_extendhi_truncqi"
3072   [(set (match_operand:HI 0 "register_operand" "=d")
3073         (zero_extend:HI
3074             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3075   "TARGET_64BIT && !TARGET_MIPS16"
3076   "andi\t%0,%1,0xff"
3077   [(set_attr "alu_type" "and")
3078    (set_attr "mode" "HI")])
3079 \f
3080 ;;
3081 ;;  ....................
3082 ;;
3083 ;;      SIGN EXTENSION
3084 ;;
3085 ;;  ....................
3086
3087 ;; Extension insns.
3088 ;; Those for integer source operand are ordered widest source type first.
3089
3090 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3091 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3092 ;; and truncdisi2).  We can therefore get rid of register->register
3093 ;; instructions if we constrain the source to be in the same register as
3094 ;; the destination.
3095 ;;
3096 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3097 ;; we split them into nothing before the post-reload scheduler runs.
3098 ;; These alternatives therefore have type "move" in order to reflect
3099 ;; what happens if the two pre-reload operands cannot be tied, and are
3100 ;; instead allocated two separate GPRs.  We don't distinguish between
3101 ;; the GPR and LO cases because we don't usually know during pre-reload
3102 ;; scheduling whether an operand will be LO or not.
3103 (define_insn_and_split "extendsidi2"
3104   [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3105         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3106   "TARGET_64BIT"
3107   "@
3108    #
3109    #
3110    lw\t%0,%1"
3111   "&& reload_completed && register_operand (operands[1], VOIDmode)"
3112   [(const_int 0)]
3113 {
3114   emit_note (NOTE_INSN_DELETED);
3115   DONE;
3116 }
3117   [(set_attr "move_type" "move,move,load")
3118    (set_attr "mode" "DI")])
3119
3120 (define_expand "extend<SHORT:mode><GPR:mode>2"
3121   [(set (match_operand:GPR 0 "register_operand")
3122         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3123   "")
3124
3125 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3126   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3127         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3128   "GENERATE_MIPS16E"
3129   "@
3130    se<SHORT:size>\t%0
3131    l<SHORT:size>\t%0,%1"
3132   [(set_attr "move_type" "signext,load")
3133    (set_attr "mode" "<GPR:MODE>")])
3134
3135 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3136   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3137         (sign_extend:GPR
3138              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3139   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3140   "@
3141    #
3142    l<SHORT:size>\t%0,%1"
3143   "&& reload_completed && REG_P (operands[1])"
3144   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3145    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3146 {
3147   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3148   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3149                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3150 }
3151   [(set_attr "move_type" "shift_shift,load")
3152    (set_attr "mode" "<GPR:MODE>")])
3153
3154 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3155   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3156         (sign_extend:GPR
3157              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3158   "ISA_HAS_SEB_SEH"
3159   "@
3160    se<SHORT:size>\t%0,%1
3161    l<SHORT:size>\t%0,%1"
3162   [(set_attr "move_type" "signext,load")
3163    (set_attr "mode" "<GPR:MODE>")])
3164
3165 (define_expand "extendqihi2"
3166   [(set (match_operand:HI 0 "register_operand")
3167         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3168   "")
3169
3170 (define_insn "*extendqihi2_mips16e"
3171   [(set (match_operand:HI 0 "register_operand" "=d,d")
3172         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3173   "GENERATE_MIPS16E"
3174   "@
3175    seb\t%0
3176    lb\t%0,%1"
3177   [(set_attr "move_type" "signext,load")
3178    (set_attr "mode" "SI")])
3179
3180 (define_insn_and_split "*extendqihi2"
3181   [(set (match_operand:HI 0 "register_operand" "=d,d")
3182         (sign_extend:HI
3183              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3184   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3185   "@
3186    #
3187    lb\t%0,%1"
3188   "&& reload_completed && REG_P (operands[1])"
3189   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3190    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3191 {
3192   operands[0] = gen_lowpart (SImode, operands[0]);
3193   operands[1] = gen_lowpart (SImode, operands[1]);
3194   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3195                          - GET_MODE_BITSIZE (QImode));
3196 }
3197   [(set_attr "move_type" "shift_shift,load")
3198    (set_attr "mode" "SI")])
3199
3200 (define_insn "*extendqihi2_seb"
3201   [(set (match_operand:HI 0 "register_operand" "=d,d")
3202         (sign_extend:HI
3203              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3204   "ISA_HAS_SEB_SEH"
3205   "@
3206    seb\t%0,%1
3207    lb\t%0,%1"
3208   [(set_attr "move_type" "signext,load")
3209    (set_attr "mode" "SI")])
3210
3211 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
3212 ;; use the shift/truncate patterns.
3213
3214 (define_insn_and_split "*extenddi_truncate<mode>"
3215   [(set (match_operand:DI 0 "register_operand" "=d")
3216         (sign_extend:DI
3217             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3218   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3219   "#"
3220   "&& reload_completed"
3221   [(set (match_dup 2)
3222         (ashift:DI (match_dup 1)
3223                    (match_dup 3)))
3224    (set (match_dup 0)
3225         (ashiftrt:DI (match_dup 2)
3226                      (match_dup 3)))]
3227 {
3228   operands[2] = gen_lowpart (DImode, operands[0]);
3229   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3230 }
3231   [(set_attr "move_type" "shift_shift")
3232    (set_attr "mode" "DI")])
3233
3234 (define_insn_and_split "*extendsi_truncate<mode>"
3235   [(set (match_operand:SI 0 "register_operand" "=d")
3236         (sign_extend:SI
3237             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3238   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3239   "#"
3240   "&& reload_completed"
3241   [(set (match_dup 2)
3242         (ashift:DI (match_dup 1)
3243                    (match_dup 3)))
3244    (set (match_dup 0)
3245         (truncate:SI (ashiftrt:DI (match_dup 2)
3246                                   (match_dup 3))))]
3247 {
3248   operands[2] = gen_lowpart (DImode, operands[0]);
3249   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3250 }
3251   [(set_attr "move_type" "shift_shift")
3252    (set_attr "mode" "SI")])
3253
3254 (define_insn_and_split "*extendhi_truncateqi"
3255   [(set (match_operand:HI 0 "register_operand" "=d")
3256         (sign_extend:HI
3257             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3258   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3259   "#"
3260   "&& reload_completed"
3261   [(set (match_dup 2)
3262         (ashift:DI (match_dup 1)
3263                    (const_int 56)))
3264    (set (match_dup 0)
3265         (truncate:HI (ashiftrt:DI (match_dup 2)
3266                                   (const_int 56))))]
3267 {
3268   operands[2] = gen_lowpart (DImode, operands[0]);
3269 }
3270   [(set_attr "move_type" "shift_shift")
3271    (set_attr "mode" "SI")])
3272
3273 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3274   [(set (match_operand:GPR 0 "register_operand" "=d")
3275         (sign_extend:GPR
3276             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3277   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3278 {
3279   operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3280   return "exts\t%0,%1,0,%m2";
3281 }
3282   [(set_attr "type" "arith")
3283    (set_attr "mode" "<GPR:MODE>")])
3284
3285 (define_insn "*extendhi_truncateqi_exts"
3286   [(set (match_operand:HI 0 "register_operand" "=d")
3287         (sign_extend:HI
3288             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3289   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3290   "exts\t%0,%1,0,7"
3291   [(set_attr "type" "arith")
3292    (set_attr "mode" "SI")])
3293
3294 (define_insn "extendsfdf2"
3295   [(set (match_operand:DF 0 "register_operand" "=f")
3296         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3297   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3298   "cvt.d.s\t%0,%1"
3299   [(set_attr "type"     "fcvt")
3300    (set_attr "cnv_mode" "S2D")   
3301    (set_attr "mode"     "DF")])
3302 \f
3303 ;;
3304 ;;  ....................
3305 ;;
3306 ;;      CONVERSIONS
3307 ;;
3308 ;;  ....................
3309
3310 (define_expand "fix_truncdfsi2"
3311   [(set (match_operand:SI 0 "register_operand")
3312         (fix:SI (match_operand:DF 1 "register_operand")))]
3313   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3314 {
3315   if (!ISA_HAS_TRUNC_W)
3316     {
3317       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3318       DONE;
3319     }
3320 })
3321
3322 (define_insn "fix_truncdfsi2_insn"
3323   [(set (match_operand:SI 0 "register_operand" "=f")
3324         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3325   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3326   "trunc.w.d %0,%1"
3327   [(set_attr "type"     "fcvt")
3328    (set_attr "mode"     "DF")
3329    (set_attr "cnv_mode" "D2I")])
3330
3331 (define_insn "fix_truncdfsi2_macro"
3332   [(set (match_operand:SI 0 "register_operand" "=f")
3333         (fix:SI (match_operand:DF 1 "register_operand" "f")))
3334    (clobber (match_scratch:DF 2 "=d"))]
3335   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3336 {
3337   if (mips_nomacro.nesting_level > 0)
3338     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3339   else
3340     return "trunc.w.d %0,%1,%2";
3341 }
3342   [(set_attr "type"     "fcvt")
3343    (set_attr "mode"     "DF")
3344    (set_attr "cnv_mode" "D2I")
3345    (set_attr "length"   "36")])
3346
3347 (define_expand "fix_truncsfsi2"
3348   [(set (match_operand:SI 0 "register_operand")
3349         (fix:SI (match_operand:SF 1 "register_operand")))]
3350   "TARGET_HARD_FLOAT"
3351 {
3352   if (!ISA_HAS_TRUNC_W)
3353     {
3354       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3355       DONE;
3356     }
3357 })
3358
3359 (define_insn "fix_truncsfsi2_insn"
3360   [(set (match_operand:SI 0 "register_operand" "=f")
3361         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3362   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3363   "trunc.w.s %0,%1"
3364   [(set_attr "type"     "fcvt")
3365    (set_attr "mode"     "SF")
3366    (set_attr "cnv_mode" "S2I")])
3367
3368 (define_insn "fix_truncsfsi2_macro"
3369   [(set (match_operand:SI 0 "register_operand" "=f")
3370         (fix:SI (match_operand:SF 1 "register_operand" "f")))
3371    (clobber (match_scratch:SF 2 "=d"))]
3372   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3373 {
3374   if (mips_nomacro.nesting_level > 0)
3375     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3376   else
3377     return "trunc.w.s %0,%1,%2";
3378 }
3379   [(set_attr "type"     "fcvt")
3380    (set_attr "mode"     "SF")
3381    (set_attr "cnv_mode" "S2I")
3382    (set_attr "length"   "36")])
3383
3384
3385 (define_insn "fix_truncdfdi2"
3386   [(set (match_operand:DI 0 "register_operand" "=f")
3387         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3388   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3389   "trunc.l.d %0,%1"
3390   [(set_attr "type"     "fcvt")
3391    (set_attr "mode"     "DF")
3392    (set_attr "cnv_mode" "D2I")])
3393
3394
3395 (define_insn "fix_truncsfdi2"
3396   [(set (match_operand:DI 0 "register_operand" "=f")
3397         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3398   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3399   "trunc.l.s %0,%1"
3400   [(set_attr "type"     "fcvt")
3401    (set_attr "mode"     "SF")
3402    (set_attr "cnv_mode" "S2I")])
3403
3404
3405 (define_insn "floatsidf2"
3406   [(set (match_operand:DF 0 "register_operand" "=f")
3407         (float:DF (match_operand:SI 1 "register_operand" "f")))]
3408   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3409   "cvt.d.w\t%0,%1"
3410   [(set_attr "type"     "fcvt")
3411    (set_attr "mode"     "DF")
3412    (set_attr "cnv_mode" "I2D")])
3413
3414
3415 (define_insn "floatdidf2"
3416   [(set (match_operand:DF 0 "register_operand" "=f")
3417         (float:DF (match_operand:DI 1 "register_operand" "f")))]
3418   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3419   "cvt.d.l\t%0,%1"
3420   [(set_attr "type"     "fcvt")
3421    (set_attr "mode"     "DF")
3422    (set_attr "cnv_mode" "I2D")])
3423
3424
3425 (define_insn "floatsisf2"
3426   [(set (match_operand:SF 0 "register_operand" "=f")
3427         (float:SF (match_operand:SI 1 "register_operand" "f")))]
3428   "TARGET_HARD_FLOAT"
3429   "cvt.s.w\t%0,%1"
3430   [(set_attr "type"     "fcvt")
3431    (set_attr "mode"     "SF")
3432    (set_attr "cnv_mode" "I2S")])
3433
3434
3435 (define_insn "floatdisf2"
3436   [(set (match_operand:SF 0 "register_operand" "=f")
3437         (float:SF (match_operand:DI 1 "register_operand" "f")))]
3438   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3439   "cvt.s.l\t%0,%1"
3440   [(set_attr "type"     "fcvt")
3441    (set_attr "mode"     "SF")
3442    (set_attr "cnv_mode" "I2S")])
3443
3444
3445 (define_expand "fixuns_truncdfsi2"
3446   [(set (match_operand:SI 0 "register_operand")
3447         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3448   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3449 {
3450   rtx reg1 = gen_reg_rtx (DFmode);
3451   rtx reg2 = gen_reg_rtx (DFmode);
3452   rtx reg3 = gen_reg_rtx (SImode);
3453   rtx label1 = gen_label_rtx ();
3454   rtx label2 = gen_label_rtx ();
3455   rtx test;
3456   REAL_VALUE_TYPE offset;
3457
3458   real_2expN (&offset, 31, DFmode);
3459
3460   if (reg1)                     /* Turn off complaints about unreached code.  */
3461     {
3462       mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3463       do_pending_stack_adjust ();
3464
3465       test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3466       emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3467
3468       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3469       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3470                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
3471       emit_barrier ();
3472
3473       emit_label (label1);
3474       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3475       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3476                                      (BITMASK_HIGH, SImode)));
3477
3478       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3479       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3480
3481       emit_label (label2);
3482
3483       /* Allow REG_NOTES to be set on last insn (labels don't have enough
3484          fields, and can't be used for REG_NOTES anyway).  */
3485       emit_use (stack_pointer_rtx);
3486       DONE;
3487     }
3488 })
3489
3490
3491 (define_expand "fixuns_truncdfdi2"
3492   [(set (match_operand:DI 0 "register_operand")
3493         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3494   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3495 {
3496   rtx reg1 = gen_reg_rtx (DFmode);
3497   rtx reg2 = gen_reg_rtx (DFmode);
3498   rtx reg3 = gen_reg_rtx (DImode);
3499   rtx label1 = gen_label_rtx ();
3500   rtx label2 = gen_label_rtx ();
3501   rtx test;
3502   REAL_VALUE_TYPE offset;
3503
3504   real_2expN (&offset, 63, DFmode);
3505
3506   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3507   do_pending_stack_adjust ();
3508
3509   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3510   emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3511
3512   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3513   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3514                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3515   emit_barrier ();
3516
3517   emit_label (label1);
3518   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3519   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3520   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3521
3522   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3523   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3524
3525   emit_label (label2);
3526
3527   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3528      fields, and can't be used for REG_NOTES anyway).  */
3529   emit_use (stack_pointer_rtx);
3530   DONE;
3531 })
3532
3533
3534 (define_expand "fixuns_truncsfsi2"
3535   [(set (match_operand:SI 0 "register_operand")
3536         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3537   "TARGET_HARD_FLOAT"
3538 {
3539   rtx reg1 = gen_reg_rtx (SFmode);
3540   rtx reg2 = gen_reg_rtx (SFmode);
3541   rtx reg3 = gen_reg_rtx (SImode);
3542   rtx label1 = gen_label_rtx ();
3543   rtx label2 = gen_label_rtx ();
3544   rtx test;
3545   REAL_VALUE_TYPE offset;
3546
3547   real_2expN (&offset, 31, SFmode);
3548
3549   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3550   do_pending_stack_adjust ();
3551
3552   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3553   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3554
3555   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3556   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3557                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3558   emit_barrier ();
3559
3560   emit_label (label1);
3561   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3562   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3563                                  (BITMASK_HIGH, SImode)));
3564
3565   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3566   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3567
3568   emit_label (label2);
3569
3570   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3571      fields, and can't be used for REG_NOTES anyway).  */
3572   emit_use (stack_pointer_rtx);
3573   DONE;
3574 })
3575
3576
3577 (define_expand "fixuns_truncsfdi2"
3578   [(set (match_operand:DI 0 "register_operand")
3579         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3580   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3581 {
3582   rtx reg1 = gen_reg_rtx (SFmode);
3583   rtx reg2 = gen_reg_rtx (SFmode);
3584   rtx reg3 = gen_reg_rtx (DImode);
3585   rtx label1 = gen_label_rtx ();
3586   rtx label2 = gen_label_rtx ();
3587   rtx test;
3588   REAL_VALUE_TYPE offset;
3589
3590   real_2expN (&offset, 63, SFmode);
3591
3592   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3593   do_pending_stack_adjust ();
3594
3595   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3596   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3597
3598   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
3599   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3600                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3601   emit_barrier ();
3602
3603   emit_label (label1);
3604   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3605   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3606   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3607
3608   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
3609   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3610
3611   emit_label (label2);
3612
3613   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3614      fields, and can't be used for REG_NOTES anyway).  */
3615   emit_use (stack_pointer_rtx);
3616   DONE;
3617 })
3618 \f
3619 ;;
3620 ;;  ....................
3621 ;;
3622 ;;      DATA MOVEMENT
3623 ;;
3624 ;;  ....................
3625
3626 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
3627
3628 (define_expand "extv"
3629   [(set (match_operand 0 "register_operand")
3630         (sign_extract (match_operand 1 "nonimmediate_operand")
3631                       (match_operand 2 "const_int_operand")
3632                       (match_operand 3 "const_int_operand")))]
3633   "!TARGET_MIPS16"
3634 {
3635   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3636                                          INTVAL (operands[2]),
3637                                          INTVAL (operands[3])))
3638     DONE;
3639   else if (register_operand (operands[1], GET_MODE (operands[0]))
3640            && ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32)
3641     {
3642       if (GET_MODE (operands[0]) == DImode)
3643         emit_insn (gen_extvdi (operands[0], operands[1], operands[2],
3644                                operands[3]));
3645       else
3646         emit_insn (gen_extvsi (operands[0], operands[1], operands[2],
3647                                operands[3]));
3648       DONE;
3649     }
3650   else
3651     FAIL;
3652 })
3653
3654 (define_insn "extv<mode>"
3655   [(set (match_operand:GPR 0 "register_operand" "=d")
3656         (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3657                           (match_operand 2 "const_int_operand" "")
3658                           (match_operand 3 "const_int_operand" "")))]
3659   "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
3660   "exts\t%0,%1,%3,%m2"
3661   [(set_attr "type"     "arith")
3662    (set_attr "mode"     "<MODE>")])
3663
3664
3665 (define_expand "extzv"
3666   [(set (match_operand 0 "register_operand")
3667         (zero_extract (match_operand 1 "nonimmediate_operand")
3668                       (match_operand 2 "const_int_operand")
3669                       (match_operand 3 "const_int_operand")))]
3670   "!TARGET_MIPS16"
3671 {
3672   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3673                                          INTVAL (operands[2]),
3674                                          INTVAL (operands[3])))
3675     DONE;
3676   else if (mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3677                                INTVAL (operands[3])))
3678     {
3679       if (GET_MODE (operands[0]) == DImode)
3680         emit_insn (gen_extzvdi (operands[0], operands[1], operands[2],
3681                                 operands[3]));
3682       else
3683         emit_insn (gen_extzvsi (operands[0], operands[1], operands[2],
3684                                 operands[3]));
3685       DONE;
3686     }
3687   else
3688     FAIL;
3689 })
3690
3691 (define_insn "extzv<mode>"
3692   [(set (match_operand:GPR 0 "register_operand" "=d")
3693         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3694                           (match_operand 2 "const_int_operand" "")
3695                           (match_operand 3 "const_int_operand" "")))]
3696   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3697                        INTVAL (operands[3]))"
3698   "<d>ext\t%0,%1,%3,%2"
3699   [(set_attr "type"     "arith")
3700    (set_attr "mode"     "<MODE>")])
3701
3702 (define_insn "*extzv_truncsi_exts"
3703   [(set (match_operand:SI 0 "register_operand" "=d")
3704         (truncate:SI
3705          (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
3706                           (match_operand 2 "const_int_operand" "")
3707                           (match_operand 3 "const_int_operand" ""))))]
3708   "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3709   "exts\t%0,%1,%3,31"
3710   [(set_attr "type"     "arith")
3711    (set_attr "mode"     "SI")])
3712
3713
3714 (define_expand "insv"
3715   [(set (zero_extract (match_operand 0 "nonimmediate_operand")
3716                       (match_operand 1 "immediate_operand")
3717                       (match_operand 2 "immediate_operand"))
3718         (match_operand 3 "reg_or_0_operand"))]
3719   "!TARGET_MIPS16"
3720 {
3721   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
3722                                           INTVAL (operands[1]),
3723                                           INTVAL (operands[2])))
3724     DONE;
3725   else if (mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3726                                INTVAL (operands[2])))
3727     {
3728       if (GET_MODE (operands[0]) == DImode)
3729         emit_insn (gen_insvdi (operands[0], operands[1], operands[2],
3730                                operands[3]));
3731       else
3732         emit_insn (gen_insvsi (operands[0], operands[1], operands[2],
3733                                operands[3]));
3734       DONE;
3735    }
3736    else
3737      FAIL;
3738 })
3739
3740 (define_insn "insv<mode>"
3741   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3742                           (match_operand:SI 1 "immediate_operand" "I")
3743                           (match_operand:SI 2 "immediate_operand" "I"))
3744         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3745   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3746                        INTVAL (operands[2]))"
3747   "<d>ins\t%0,%z3,%2,%1"
3748   [(set_attr "type"     "arith")
3749    (set_attr "mode"     "<MODE>")])
3750
3751 ;; Combiner pattern for cins (clear and insert bit field).  We can
3752 ;; implement mask-and-shift-left operation with this.  Note that if
3753 ;; the upper bit of the mask is set in an SImode operation, the mask
3754 ;; itself will be sign-extended.  mask_low_and_shift_len will
3755 ;; therefore be greater than our threshold of 32.
3756
3757 (define_insn "*cins<mode>"
3758   [(set (match_operand:GPR 0 "register_operand" "=d")
3759         (and:GPR
3760          (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
3761                      (match_operand:GPR 2 "const_int_operand" ""))
3762          (match_operand:GPR 3 "const_int_operand" "")))]
3763   "ISA_HAS_CINS
3764    && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
3765 {
3766   operands[3] =
3767     GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
3768   return "cins\t%0,%1,%2,%m3";
3769 }
3770   [(set_attr "type"     "shift")
3771    (set_attr "mode"     "<MODE>")])
3772
3773 ;; Unaligned word moves generated by the bit field patterns.
3774 ;;
3775 ;; As far as the rtl is concerned, both the left-part and right-part
3776 ;; instructions can access the whole field.  However, the real operand
3777 ;; refers to just the first or the last byte (depending on endianness).
3778 ;; We therefore use two memory operands to each instruction, one to
3779 ;; describe the rtl effect and one to use in the assembly output.
3780 ;;
3781 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3782 ;; This allows us to use the standard length calculations for the "load"
3783 ;; and "store" type attributes.
3784
3785 (define_insn "mov_<load>l"
3786   [(set (match_operand:GPR 0 "register_operand" "=d")
3787         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3788                      (match_operand:QI 2 "memory_operand" "m")]
3789                     UNSPEC_LOAD_LEFT))]
3790   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3791   "<load>l\t%0,%2"
3792   [(set_attr "move_type" "load")
3793    (set_attr "mode" "<MODE>")])
3794
3795 (define_insn "mov_<load>r"
3796   [(set (match_operand:GPR 0 "register_operand" "=d")
3797         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3798                      (match_operand:QI 2 "memory_operand" "m")
3799                      (match_operand:GPR 3 "register_operand" "0")]
3800                     UNSPEC_LOAD_RIGHT))]
3801   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3802   "<load>r\t%0,%2"
3803   [(set_attr "move_type" "load")
3804    (set_attr "mode" "<MODE>")])
3805
3806 (define_insn "mov_<store>l"
3807   [(set (match_operand:BLK 0 "memory_operand" "=m")
3808         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3809                      (match_operand:QI 2 "memory_operand" "m")]
3810                     UNSPEC_STORE_LEFT))]
3811   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3812   "<store>l\t%z1,%2"
3813   [(set_attr "move_type" "store")
3814    (set_attr "mode" "<MODE>")])
3815
3816 (define_insn "mov_<store>r"
3817   [(set (match_operand:BLK 0 "memory_operand" "+m")
3818         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
3819                      (match_operand:QI 2 "memory_operand" "m")
3820                      (match_dup 0)]
3821                     UNSPEC_STORE_RIGHT))]
3822   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
3823   "<store>r\t%z1,%2"
3824   [(set_attr "move_type" "store")
3825    (set_attr "mode" "<MODE>")])
3826
3827 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
3828 ;; The required value is:
3829 ;;
3830 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
3831 ;;
3832 ;; which translates to:
3833 ;;
3834 ;;      lui     op0,%highest(op1)
3835 ;;      daddiu  op0,op0,%higher(op1)
3836 ;;      dsll    op0,op0,16
3837 ;;      daddiu  op0,op0,%hi(op1)
3838 ;;      dsll    op0,op0,16
3839 ;;
3840 ;; The split is deferred until after flow2 to allow the peephole2 below
3841 ;; to take effect.
3842 (define_insn_and_split "*lea_high64"
3843   [(set (match_operand:DI 0 "register_operand" "=d")
3844         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
3845   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3846   "#"
3847   "&& epilogue_completed"
3848   [(set (match_dup 0) (high:DI (match_dup 2)))
3849    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
3850    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
3851    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3852    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
3853 {
3854   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3855   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
3856 }
3857   [(set_attr "length" "20")])
3858
3859 ;; Use a scratch register to reduce the latency of the above pattern
3860 ;; on superscalar machines.  The optimized sequence is:
3861 ;;
3862 ;;      lui     op1,%highest(op2)
3863 ;;      lui     op0,%hi(op2)
3864 ;;      daddiu  op1,op1,%higher(op2)
3865 ;;      dsll32  op1,op1,0
3866 ;;      daddu   op1,op1,op0
3867 (define_peephole2
3868   [(set (match_operand:DI 1 "d_operand")
3869         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
3870    (match_scratch:DI 0 "d")]
3871   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
3872   [(set (match_dup 1) (high:DI (match_dup 3)))
3873    (set (match_dup 0) (high:DI (match_dup 4)))
3874    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
3875    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
3876    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
3877 {
3878   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
3879   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
3880 })
3881
3882 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
3883 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
3884 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
3885 ;; used once.  We can then use the sequence:
3886 ;;
3887 ;;      lui     op0,%highest(op1)
3888 ;;      lui     op2,%hi(op1)
3889 ;;      daddiu  op0,op0,%higher(op1)
3890 ;;      daddiu  op2,op2,%lo(op1)
3891 ;;      dsll32  op0,op0,0
3892 ;;      daddu   op0,op0,op2
3893 ;;
3894 ;; which takes 4 cycles on most superscalar targets.
3895 (define_insn_and_split "*lea64"
3896   [(set (match_operand:DI 0 "register_operand" "=d")
3897         (match_operand:DI 1 "absolute_symbolic_operand" ""))
3898    (clobber (match_scratch:DI 2 "=&d"))]
3899   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
3900   "#"
3901   "&& reload_completed"
3902   [(set (match_dup 0) (high:DI (match_dup 3)))
3903    (set (match_dup 2) (high:DI (match_dup 4)))
3904    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
3905    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
3906    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
3907    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
3908 {
3909   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
3910   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
3911 }
3912   [(set_attr "length" "24")])
3913
3914 ;; Split HIGHs into:
3915 ;;
3916 ;;      li op0,%hi(sym)
3917 ;;      sll op0,16
3918 ;;
3919 ;; on MIPS16 targets.
3920 (define_split
3921   [(set (match_operand:SI 0 "d_operand")
3922         (high:SI (match_operand:SI 1 "absolute_symbolic_operand")))]
3923   "TARGET_MIPS16 && reload_completed"
3924   [(set (match_dup 0) (match_dup 2))
3925    (set (match_dup 0) (ashift:SI (match_dup 0) (const_int 16)))]
3926 {
3927   operands[2] = mips_unspec_address (operands[1], SYMBOL_32_HIGH);
3928 })
3929
3930 ;; Insns to fetch a symbol from a big GOT.
3931
3932 (define_insn_and_split "*xgot_hi<mode>"
3933   [(set (match_operand:P 0 "register_operand" "=d")
3934         (high:P (match_operand:P 1 "got_disp_operand" "")))]
3935   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3936   "#"
3937   "&& reload_completed"
3938   [(set (match_dup 0) (high:P (match_dup 2)))
3939    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
3940 {
3941   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
3942   operands[3] = pic_offset_table_rtx;
3943 }
3944   [(set_attr "got" "xgot_high")
3945    (set_attr "mode" "<MODE>")])
3946
3947 (define_insn_and_split "*xgot_lo<mode>"
3948   [(set (match_operand:P 0 "register_operand" "=d")
3949         (lo_sum:P (match_operand:P 1 "register_operand" "d")
3950                   (match_operand:P 2 "got_disp_operand" "")))]
3951   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
3952   "#"
3953   "&& reload_completed"
3954   [(set (match_dup 0)
3955         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
3956   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
3957   [(set_attr "got" "load")
3958    (set_attr "mode" "<MODE>")])
3959
3960 ;; Insns to fetch a symbol from a normal GOT.
3961
3962 (define_insn_and_split "*got_disp<mode>"
3963   [(set (match_operand:P 0 "register_operand" "=d")
3964         (match_operand:P 1 "got_disp_operand" ""))]
3965   "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
3966   "#"
3967   "&& reload_completed"
3968   [(set (match_dup 0) (match_dup 2))]
3969   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
3970   [(set_attr "got" "load")
3971    (set_attr "mode" "<MODE>")])
3972
3973 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
3974
3975 (define_insn_and_split "*got_page<mode>"
3976   [(set (match_operand:P 0 "register_operand" "=d")
3977         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
3978   "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
3979   "#"
3980   "&& reload_completed"
3981   [(set (match_dup 0) (match_dup 2))]
3982   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
3983   [(set_attr "got" "load")
3984    (set_attr "mode" "<MODE>")])
3985
3986 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
3987 (define_expand "unspec_got_<mode>"
3988   [(unspec:P [(match_operand:P 0)
3989               (match_operand:P 1)] UNSPEC_LOAD_GOT)])
3990
3991 ;; Lower-level instructions for loading an address from the GOT.
3992 ;; We could use MEMs, but an unspec gives more optimization
3993 ;; opportunities.
3994
3995 (define_insn "load_got<mode>"
3996   [(set (match_operand:P 0 "register_operand" "=d")
3997         (unspec:P [(match_operand:P 1 "register_operand" "d")
3998                    (match_operand:P 2 "immediate_operand" "")]
3999                   UNSPEC_LOAD_GOT))]
4000   ""
4001   "<load>\t%0,%R2(%1)"
4002   [(set_attr "got" "load")
4003    (set_attr "mode" "<MODE>")])
4004
4005 ;; Instructions for adding the low 16 bits of an address to a register.
4006 ;; Operand 2 is the address: mips_print_operand works out which relocation
4007 ;; should be applied.
4008
4009 (define_insn "*low<mode>"
4010   [(set (match_operand:P 0 "register_operand" "=d")
4011         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4012                   (match_operand:P 2 "immediate_operand" "")))]
4013   "!TARGET_MIPS16"
4014   "<d>addiu\t%0,%1,%R2"
4015   [(set_attr "alu_type" "add")
4016    (set_attr "mode" "<MODE>")])
4017
4018 (define_insn "*low<mode>_mips16"
4019   [(set (match_operand:P 0 "register_operand" "=d")
4020         (lo_sum:P (match_operand:P 1 "register_operand" "0")
4021                   (match_operand:P 2 "immediate_operand" "")))]
4022   "TARGET_MIPS16"
4023   "<d>addiu\t%0,%R2"
4024   [(set_attr "alu_type" "add")
4025    (set_attr "mode" "<MODE>")
4026    (set_attr "extended_mips16" "yes")])
4027
4028 ;; Expose MIPS16 uses of the global pointer after reload if the function
4029 ;; is responsible for setting up the register itself.
4030 (define_split
4031   [(set (match_operand:GPR 0 "d_operand")
4032         (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4033   "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4034   [(set (match_dup 0) (match_dup 1))]
4035   { operands[1] = pic_offset_table_rtx; })
4036
4037 ;; Allow combine to split complex const_int load sequences, using operand 2
4038 ;; to store the intermediate results.  See move_operand for details.
4039 (define_split
4040   [(set (match_operand:GPR 0 "register_operand")
4041         (match_operand:GPR 1 "splittable_const_int_operand"))
4042    (clobber (match_operand:GPR 2 "register_operand"))]
4043   ""
4044   [(const_int 0)]
4045 {
4046   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4047   DONE;
4048 })
4049
4050 ;; Likewise, for symbolic operands.
4051 (define_split
4052   [(set (match_operand:P 0 "register_operand")
4053         (match_operand:P 1))
4054    (clobber (match_operand:P 2 "register_operand"))]
4055   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4056   [(set (match_dup 0) (match_dup 3))]
4057 {
4058   mips_split_symbol (operands[2], operands[1],
4059                      MAX_MACHINE_MODE, &operands[3]);
4060 })
4061
4062 ;; 64-bit integer moves
4063
4064 ;; Unlike most other insns, the move insns can't be split with
4065 ;; different predicates, because register spilling and other parts of
4066 ;; the compiler, have memoized the insn number already.
4067
4068 (define_expand "movdi"
4069   [(set (match_operand:DI 0 "")
4070         (match_operand:DI 1 ""))]
4071   ""
4072 {
4073   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4074     DONE;
4075 })
4076
4077 ;; For mips16, we need a special case to handle storing $31 into
4078 ;; memory, since we don't have a constraint to match $31.  This
4079 ;; instruction can be generated by save_restore_insns.
4080
4081 (define_insn "*mov<mode>_ra"
4082   [(set (match_operand:GPR 0 "stack_operand" "=m")
4083         (reg:GPR RETURN_ADDR_REGNUM))]
4084   "TARGET_MIPS16"
4085   "<store>\t$31,%0"
4086   [(set_attr "move_type" "store")
4087    (set_attr "mode" "<MODE>")])
4088
4089 (define_insn "*movdi_32bit"
4090   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4091         (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*a,*J*d,*m,*f,*f,*d,*m,*B*C*D,*B*C*D"))]
4092   "!TARGET_64BIT && !TARGET_MIPS16
4093    && (register_operand (operands[0], DImode)
4094        || reg_or_0_operand (operands[1], DImode))"
4095   { return mips_output_move (operands[0], operands[1]); }
4096   [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4097    (set_attr "mode" "DI")])
4098
4099 (define_insn "*movdi_32bit_mips16"
4100   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4101         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4102   "!TARGET_64BIT && TARGET_MIPS16
4103    && (register_operand (operands[0], DImode)
4104        || register_operand (operands[1], DImode))"
4105   { return mips_output_move (operands[0], operands[1]); }
4106   [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4107    (set_attr "mode" "DI")])
4108
4109 (define_insn "*movdi_64bit"
4110   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*a,*d,*B*C*D,*B*C*D,*d,*m")
4111         (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4112   "TARGET_64BIT && !TARGET_MIPS16
4113    && (register_operand (operands[0], DImode)
4114        || reg_or_0_operand (operands[1], DImode))"
4115   { return mips_output_move (operands[0], operands[1]); }
4116   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mthilo,mfhilo,mtc,fpload,mfc,fpstore")
4117    (set_attr "mode" "DI")])
4118
4119 (define_insn "*movdi_64bit_mips16"
4120   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4121         (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,kf,m,d,*a"))]
4122   "TARGET_64BIT && TARGET_MIPS16
4123    && (register_operand (operands[0], DImode)
4124        || register_operand (operands[1], DImode))"
4125   { return mips_output_move (operands[0], operands[1]); }
4126   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mfhilo")
4127    (set_attr "mode" "DI")])
4128
4129 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4130 ;; when the original load is a 4 byte instruction but the add and the
4131 ;; load are 2 2 byte instructions.
4132
4133 (define_split
4134   [(set (match_operand:DI 0 "d_operand")
4135         (mem:DI (plus:DI (match_dup 0)
4136                          (match_operand:DI 1 "const_int_operand"))))]
4137   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4138    && !TARGET_DEBUG_D_MODE
4139    && ((INTVAL (operands[1]) < 0
4140         && INTVAL (operands[1]) >= -0x10)
4141        || (INTVAL (operands[1]) >= 32 * 8
4142            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4143        || (INTVAL (operands[1]) >= 0
4144            && INTVAL (operands[1]) < 32 * 8
4145            && (INTVAL (operands[1]) & 7) != 0))"
4146   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4147    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4148 {
4149   HOST_WIDE_INT val = INTVAL (operands[1]);
4150
4151   if (val < 0)
4152     operands[2] = const0_rtx;
4153   else if (val >= 32 * 8)
4154     {
4155       int off = val & 7;
4156
4157       operands[1] = GEN_INT (0x8 + off);
4158       operands[2] = GEN_INT (val - off - 0x8);
4159     }
4160   else
4161     {
4162       int off = val & 7;
4163
4164       operands[1] = GEN_INT (off);
4165       operands[2] = GEN_INT (val - off);
4166     }
4167 })
4168
4169 ;; 32-bit Integer moves
4170
4171 ;; Unlike most other insns, the move insns can't be split with
4172 ;; different predicates, because register spilling and other parts of
4173 ;; the compiler, have memoized the insn number already.
4174
4175 (define_expand "mov<mode>"
4176   [(set (match_operand:IMOVE32 0 "")
4177         (match_operand:IMOVE32 1 ""))]
4178   ""
4179 {
4180   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4181     DONE;
4182 })
4183
4184 ;; The difference between these two is whether or not ints are allowed
4185 ;; in FP registers (off by default, use -mdebugh to enable).
4186
4187 (define_insn "*mov<mode>_internal"
4188   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4189         (match_operand:IMOVE32 1 "move_operand" "d,U,T,m,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4190   "!TARGET_MIPS16
4191    && (register_operand (operands[0], <MODE>mode)
4192        || reg_or_0_operand (operands[1], <MODE>mode))"
4193   { return mips_output_move (operands[0], operands[1]); }
4194   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mfc,mtc,mthilo,mfhilo,mtc,fpload,mfc,fpstore")
4195    (set_attr "mode" "SI")])
4196
4197 (define_insn "*mov<mode>_mips16"
4198   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4199         (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,U,kf,m,d,*a"))]
4200   "TARGET_MIPS16
4201    && (register_operand (operands[0], <MODE>mode)
4202        || register_operand (operands[1], <MODE>mode))"
4203   { return mips_output_move (operands[0], operands[1]); }
4204   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mfhilo")
4205    (set_attr "mode" "SI")])
4206
4207 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4208 ;; when the original load is a 4 byte instruction but the add and the
4209 ;; load are 2 2 byte instructions.
4210
4211 (define_split
4212   [(set (match_operand:SI 0 "d_operand")
4213         (mem:SI (plus:SI (match_dup 0)
4214                          (match_operand:SI 1 "const_int_operand"))))]
4215   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4216    && ((INTVAL (operands[1]) < 0
4217         && INTVAL (operands[1]) >= -0x80)
4218        || (INTVAL (operands[1]) >= 32 * 4
4219            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4220        || (INTVAL (operands[1]) >= 0
4221            && INTVAL (operands[1]) < 32 * 4
4222            && (INTVAL (operands[1]) & 3) != 0))"
4223   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4224    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4225 {
4226   HOST_WIDE_INT val = INTVAL (operands[1]);
4227
4228   if (val < 0)
4229     operands[2] = const0_rtx;
4230   else if (val >= 32 * 4)
4231     {
4232       int off = val & 3;
4233
4234       operands[1] = GEN_INT (0x7c + off);
4235       operands[2] = GEN_INT (val - off - 0x7c);
4236     }
4237   else
4238     {
4239       int off = val & 3;
4240
4241       operands[1] = GEN_INT (off);
4242       operands[2] = GEN_INT (val - off);
4243     }
4244 })
4245
4246 ;; On the mips16, we can split a load of certain constants into a load
4247 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
4248 ;; instructions.
4249
4250 (define_split
4251   [(set (match_operand:SI 0 "d_operand")
4252         (match_operand:SI 1 "const_int_operand"))]
4253   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4254    && INTVAL (operands[1]) >= 0x100
4255    && INTVAL (operands[1]) <= 0xff + 0x7f"
4256   [(set (match_dup 0) (match_dup 1))
4257    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4258 {
4259   int val = INTVAL (operands[1]);
4260
4261   operands[1] = GEN_INT (0xff);
4262   operands[2] = GEN_INT (val - 0xff);
4263 })
4264
4265 ;; This insn handles moving CCmode values.  It's really just a
4266 ;; slightly simplified copy of movsi_internal2, with additional cases
4267 ;; to move a condition register to a general register and to move
4268 ;; between the general registers and the floating point registers.
4269
4270 (define_insn "movcc"
4271   [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
4272         (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
4273   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4274   { return mips_output_move (operands[0], operands[1]); }
4275   [(set_attr "move_type" "lui_movf,move,load,store,mfc,mtc,fmove,fpload,fpstore")
4276    (set_attr "mode" "SI")])
4277
4278 ;; Reload condition code registers.  reload_incc and reload_outcc
4279 ;; both handle moves from arbitrary operands into condition code
4280 ;; registers.  reload_incc handles the more common case in which
4281 ;; a source operand is constrained to be in a condition-code
4282 ;; register, but has not been allocated to one.
4283 ;;
4284 ;; Sometimes, such as in movcc, we have a CCmode destination whose
4285 ;; constraints do not include 'z'.  reload_outcc handles the case
4286 ;; when such an operand is allocated to a condition-code register.
4287 ;;
4288 ;; Note that reloads from a condition code register to some
4289 ;; other location can be done using ordinary moves.  Moving
4290 ;; into a GPR takes a single movcc, moving elsewhere takes
4291 ;; two.  We can leave these cases to the generic reload code.
4292 (define_expand "reload_incc"
4293   [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
4294         (match_operand:CC 1 "general_operand" ""))
4295    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4296   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4297 {
4298   mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
4299   DONE;
4300 })
4301
4302 (define_expand "reload_outcc"
4303   [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
4304         (match_operand:CC 1 "register_operand" ""))
4305    (clobber (match_operand:TF 2 "register_operand" "=&f"))]
4306   "ISA_HAS_8CC && TARGET_HARD_FLOAT"
4307 {
4308   mips_expand_fcc_reload (operands[0], operands[1], operands[2]);
4309   DONE;
4310 })
4311
4312 ;; MIPS4 supports loading and storing a floating point register from
4313 ;; the sum of two general registers.  We use two versions for each of
4314 ;; these four instructions: one where the two general registers are
4315 ;; SImode, and one where they are DImode.  This is because general
4316 ;; registers will be in SImode when they hold 32-bit values, but,
4317 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4318 ;; instructions will still work correctly.
4319
4320 ;; ??? Perhaps it would be better to support these instructions by
4321 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends.  However, since
4322 ;; these instructions can only be used to load and store floating
4323 ;; point registers, that would probably cause trouble in reload.
4324
4325 (define_insn "*<ANYF:loadx>_<P:mode>"
4326   [(set (match_operand:ANYF 0 "register_operand" "=f")
4327         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4328                           (match_operand:P 2 "register_operand" "d"))))]
4329   "ISA_HAS_FP4"
4330   "<ANYF:loadx>\t%0,%1(%2)"
4331   [(set_attr "type" "fpidxload")
4332    (set_attr "mode" "<ANYF:UNITMODE>")])
4333
4334 (define_insn "*<ANYF:storex>_<P:mode>"
4335   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4336                           (match_operand:P 2 "register_operand" "d")))
4337         (match_operand:ANYF 0 "register_operand" "f"))]
4338   "ISA_HAS_FP4"
4339   "<ANYF:storex>\t%0,%1(%2)"
4340   [(set_attr "type" "fpidxstore")
4341    (set_attr "mode" "<ANYF:UNITMODE>")])
4342
4343 ;; Scaled indexed address load.
4344 ;; Per md.texi, we only need to look for a pattern with multiply in the
4345 ;; address expression, not shift.
4346
4347 (define_insn "*lwxs"
4348   [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4349         (mem:IMOVE32
4350           (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4351                           (const_int 4))
4352                   (match_operand:P 2 "register_operand" "d"))))]
4353   "ISA_HAS_LWXS"
4354   "lwxs\t%0,%1(%2)"
4355   [(set_attr "type"     "load")
4356    (set_attr "mode"     "SI")])
4357
4358 ;; 16-bit Integer moves
4359
4360 ;; Unlike most other insns, the move insns can't be split with
4361 ;; different predicates, because register spilling and other parts of
4362 ;; the compiler, have memoized the insn number already.
4363 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4364
4365 (define_expand "movhi"
4366   [(set (match_operand:HI 0 "")
4367         (match_operand:HI 1 ""))]
4368   ""
4369 {
4370   if (mips_legitimize_move (HImode, operands[0], operands[1]))
4371     DONE;
4372 })
4373
4374 (define_insn "*movhi_internal"
4375   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4376         (match_operand:HI 1 "move_operand"         "d,I,m,dJ,*d*J,*a"))]
4377   "!TARGET_MIPS16
4378    && (register_operand (operands[0], HImode)
4379        || reg_or_0_operand (operands[1], HImode))"
4380   { return mips_output_move (operands[0], operands[1]); }
4381   [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo")
4382    (set_attr "mode" "HI")])
4383
4384 (define_insn "*movhi_mips16"
4385   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4386         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4387   "TARGET_MIPS16
4388    && (register_operand (operands[0], HImode)
4389        || register_operand (operands[1], HImode))"
4390   { return mips_output_move (operands[0], operands[1]); }
4391   [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4392    (set_attr "mode" "HI")])
4393
4394 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4395 ;; when the original load is a 4 byte instruction but the add and the
4396 ;; load are 2 2 byte instructions.
4397
4398 (define_split
4399   [(set (match_operand:HI 0 "d_operand")
4400         (mem:HI (plus:SI (match_dup 0)
4401                          (match_operand:SI 1 "const_int_operand"))))]
4402   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4403    && ((INTVAL (operands[1]) < 0
4404         && INTVAL (operands[1]) >= -0x80)
4405        || (INTVAL (operands[1]) >= 32 * 2
4406            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4407        || (INTVAL (operands[1]) >= 0
4408            && INTVAL (operands[1]) < 32 * 2
4409            && (INTVAL (operands[1]) & 1) != 0))"
4410   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4411    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4412 {
4413   HOST_WIDE_INT val = INTVAL (operands[1]);
4414
4415   if (val < 0)
4416     operands[2] = const0_rtx;
4417   else if (val >= 32 * 2)
4418     {
4419       int off = val & 1;
4420
4421       operands[1] = GEN_INT (0x7e + off);
4422       operands[2] = GEN_INT (val - off - 0x7e);
4423     }
4424   else
4425     {
4426       int off = val & 1;
4427
4428       operands[1] = GEN_INT (off);
4429       operands[2] = GEN_INT (val - off);
4430     }
4431 })
4432
4433 ;; 8-bit Integer moves
4434
4435 ;; Unlike most other insns, the move insns can't be split with
4436 ;; different predicates, because register spilling and other parts of
4437 ;; the compiler, have memoized the insn number already.
4438 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4439
4440 (define_expand "movqi"
4441   [(set (match_operand:QI 0 "")
4442         (match_operand:QI 1 ""))]
4443   ""
4444 {
4445   if (mips_legitimize_move (QImode, operands[0], operands[1]))
4446     DONE;
4447 })
4448
4449 (define_insn "*movqi_internal"
4450   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4451         (match_operand:QI 1 "move_operand"         "d,I,m,dJ,*d*J,*a"))]
4452   "!TARGET_MIPS16
4453    && (register_operand (operands[0], QImode)
4454        || reg_or_0_operand (operands[1], QImode))"
4455   { return mips_output_move (operands[0], operands[1]); }
4456   [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo")
4457    (set_attr "mode" "QI")])
4458
4459 (define_insn "*movqi_mips16"
4460   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4461         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4462   "TARGET_MIPS16
4463    && (register_operand (operands[0], QImode)
4464        || register_operand (operands[1], QImode))"
4465   { return mips_output_move (operands[0], operands[1]); }
4466   [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4467    (set_attr "mode" "QI")])
4468
4469 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4470 ;; when the original load is a 4 byte instruction but the add and the
4471 ;; load are 2 2 byte instructions.
4472
4473 (define_split
4474   [(set (match_operand:QI 0 "d_operand")
4475         (mem:QI (plus:SI (match_dup 0)
4476                          (match_operand:SI 1 "const_int_operand"))))]
4477   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4478    && ((INTVAL (operands[1]) < 0
4479         && INTVAL (operands[1]) >= -0x80)
4480        || (INTVAL (operands[1]) >= 32
4481            && INTVAL (operands[1]) <= 31 + 0x7f))"
4482   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4483    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4484 {
4485   HOST_WIDE_INT val = INTVAL (operands[1]);
4486
4487   if (val < 0)
4488     operands[2] = const0_rtx;
4489   else
4490     {
4491       operands[1] = GEN_INT (0x7f);
4492       operands[2] = GEN_INT (val - 0x7f);
4493     }
4494 })
4495
4496 ;; 32-bit floating point moves
4497
4498 (define_expand "movsf"
4499   [(set (match_operand:SF 0 "")
4500         (match_operand:SF 1 ""))]
4501   ""
4502 {
4503   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4504     DONE;
4505 })
4506
4507 (define_insn "*movsf_hardfloat"
4508   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4509         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4510   "TARGET_HARD_FLOAT
4511    && (register_operand (operands[0], SFmode)
4512        || reg_or_0_operand (operands[1], SFmode))"
4513   { return mips_output_move (operands[0], operands[1]); }
4514   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4515    (set_attr "mode" "SF")])
4516
4517 (define_insn "*movsf_softfloat"
4518   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4519         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4520   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4521    && (register_operand (operands[0], SFmode)
4522        || reg_or_0_operand (operands[1], SFmode))"
4523   { return mips_output_move (operands[0], operands[1]); }
4524   [(set_attr "move_type" "move,load,store")
4525    (set_attr "mode" "SF")])
4526
4527 (define_insn "*movsf_mips16"
4528   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4529         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4530   "TARGET_MIPS16
4531    && (register_operand (operands[0], SFmode)
4532        || register_operand (operands[1], SFmode))"
4533   { return mips_output_move (operands[0], operands[1]); }
4534   [(set_attr "move_type" "move,move,move,load,store")
4535    (set_attr "mode" "SF")])
4536
4537 ;; 64-bit floating point moves
4538
4539 (define_expand "movdf"
4540   [(set (match_operand:DF 0 "")
4541         (match_operand:DF 1 ""))]
4542   ""
4543 {
4544   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4545     DONE;
4546 })
4547
4548 (define_insn "*movdf_hardfloat"
4549   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4550         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4551   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4552    && (register_operand (operands[0], DFmode)
4553        || reg_or_0_operand (operands[1], DFmode))"
4554   { return mips_output_move (operands[0], operands[1]); }
4555   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4556    (set_attr "mode" "DF")])
4557
4558 (define_insn "*movdf_softfloat"
4559   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4560         (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4561   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4562    && (register_operand (operands[0], DFmode)
4563        || reg_or_0_operand (operands[1], DFmode))"
4564   { return mips_output_move (operands[0], operands[1]); }
4565   [(set_attr "move_type" "move,load,store")
4566    (set_attr "mode" "DF")])
4567
4568 (define_insn "*movdf_mips16"
4569   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4570         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4571   "TARGET_MIPS16
4572    && (register_operand (operands[0], DFmode)
4573        || register_operand (operands[1], DFmode))"
4574   { return mips_output_move (operands[0], operands[1]); }
4575   [(set_attr "move_type" "move,move,move,load,store")
4576    (set_attr "mode" "DF")])
4577
4578 ;; 128-bit integer moves
4579
4580 (define_expand "movti"
4581   [(set (match_operand:TI 0)
4582         (match_operand:TI 1))]
4583   "TARGET_64BIT"
4584 {
4585   if (mips_legitimize_move (TImode, operands[0], operands[1]))
4586     DONE;
4587 })
4588
4589 (define_insn "*movti"
4590   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4591         (match_operand:TI 1 "move_operand" "d,i,m,dJ,*d*J,*a"))]
4592   "TARGET_64BIT
4593    && !TARGET_MIPS16
4594    && (register_operand (operands[0], TImode)
4595        || reg_or_0_operand (operands[1], TImode))"
4596   "#"
4597   [(set_attr "move_type" "move,const,load,store,mthilo,mfhilo")
4598    (set_attr "mode" "TI")])
4599
4600 (define_insn "*movti_mips16"
4601   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4602         (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4603   "TARGET_64BIT
4604    && TARGET_MIPS16
4605    && (register_operand (operands[0], TImode)
4606        || register_operand (operands[1], TImode))"
4607   "#"
4608   [(set_attr "move_type" "move,move,move,const,constN,load,store,mfhilo")
4609    (set_attr "mode" "TI")])
4610
4611 ;; 128-bit floating point moves
4612
4613 (define_expand "movtf"
4614   [(set (match_operand:TF 0)
4615         (match_operand:TF 1))]
4616   "TARGET_64BIT"
4617 {
4618   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
4619     DONE;
4620 })
4621
4622 ;; This pattern handles both hard- and soft-float cases.
4623 (define_insn "*movtf"
4624   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
4625         (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
4626   "TARGET_64BIT
4627    && !TARGET_MIPS16
4628    && (register_operand (operands[0], TFmode)
4629        || reg_or_0_operand (operands[1], TFmode))"
4630   "#"
4631   [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
4632    (set_attr "mode" "TF")])
4633
4634 (define_insn "*movtf_mips16"
4635   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
4636         (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
4637   "TARGET_64BIT
4638    && TARGET_MIPS16
4639    && (register_operand (operands[0], TFmode)
4640        || register_operand (operands[1], TFmode))"
4641   "#"
4642   [(set_attr "move_type" "move,move,move,load,store")
4643    (set_attr "mode" "TF")])
4644
4645 (define_split
4646   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
4647         (match_operand:MOVE64 1 "move_operand"))]
4648   "reload_completed && !TARGET_64BIT
4649    && mips_split_64bit_move_p (operands[0], operands[1])"
4650   [(const_int 0)]
4651 {
4652   mips_split_doubleword_move (operands[0], operands[1]);
4653   DONE;
4654 })
4655
4656 (define_split
4657   [(set (match_operand:MOVE128 0 "nonimmediate_operand")
4658         (match_operand:MOVE128 1 "move_operand"))]
4659   "TARGET_64BIT && reload_completed"
4660   [(const_int 0)]
4661 {
4662   mips_split_doubleword_move (operands[0], operands[1]);
4663   DONE;
4664 })
4665
4666 ;; When generating mips16 code, split moves of negative constants into
4667 ;; a positive "li" followed by a negation.
4668 (define_split
4669   [(set (match_operand 0 "d_operand")
4670         (match_operand 1 "const_int_operand"))]
4671   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4672   [(set (match_dup 2)
4673         (match_dup 3))
4674    (set (match_dup 2)
4675         (neg:SI (match_dup 2)))]
4676 {
4677   operands[2] = gen_lowpart (SImode, operands[0]);
4678   operands[3] = GEN_INT (-INTVAL (operands[1]));
4679 })
4680
4681 ;; 64-bit paired-single floating point moves
4682
4683 (define_expand "movv2sf"
4684   [(set (match_operand:V2SF 0)
4685         (match_operand:V2SF 1))]
4686   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
4687 {
4688   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4689     DONE;
4690 })
4691
4692 (define_insn "*movv2sf"
4693   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4694         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4695   "TARGET_HARD_FLOAT
4696    && TARGET_PAIRED_SINGLE_FLOAT
4697    && (register_operand (operands[0], V2SFmode)
4698        || reg_or_0_operand (operands[1], V2SFmode))"
4699   { return mips_output_move (operands[0], operands[1]); }
4700   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4701    (set_attr "mode" "DF")])
4702
4703 ;; Extract the high part of a HI/LO value.  See mips_hard_regno_mode_ok_p
4704 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
4705 ;;
4706 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
4707 ;; instead of MFHI.  This avoids both the normal MIPS III hi/lo hazards
4708 ;; and the errata related to -mfix-vr4130.
4709 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
4710   [(set (match_operand:GPR 0 "register_operand" "=d")
4711         (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
4712                     UNSPEC_MFHI))]
4713   ""
4714   { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
4715   [(set_attr "move_type" "mfhilo")
4716    (set_attr "mode" "<GPR:MODE>")])
4717
4718 ;; Set the high part of a HI/LO value, given that the low part has
4719 ;; already been set.  See mips_hard_regno_mode_ok_p for the reason
4720 ;; why we can't just use (reg:GPR HI_REGNUM).
4721 (define_insn "mthi<GPR:mode>_<HILO:mode>"
4722   [(set (match_operand:HILO 0 "register_operand" "=x")
4723         (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4724                       (match_operand:GPR 2 "register_operand" "l")]
4725                      UNSPEC_MTHI))]
4726   ""
4727   "mthi\t%z1"
4728   [(set_attr "move_type" "mthilo")
4729    (set_attr "mode" "SI")])
4730
4731 ;; Emit a doubleword move in which exactly one of the operands is
4732 ;; a floating-point register.  We can't just emit two normal moves
4733 ;; because of the constraints imposed by the FPU register model;
4734 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
4735 ;; the FPR whole and use special patterns to refer to each word of
4736 ;; the other operand.
4737
4738 (define_expand "move_doubleword_fpr<mode>"
4739   [(set (match_operand:SPLITF 0)
4740         (match_operand:SPLITF 1))]
4741   ""
4742 {
4743   if (FP_REG_RTX_P (operands[0]))
4744     {
4745       rtx low = mips_subword (operands[1], 0);
4746       rtx high = mips_subword (operands[1], 1);
4747       emit_insn (gen_load_low<mode> (operands[0], low));
4748       if (TARGET_FLOAT64 && !TARGET_64BIT)
4749         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
4750       else
4751         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
4752     }
4753   else
4754     {
4755       rtx low = mips_subword (operands[0], 0);
4756       rtx high = mips_subword (operands[0], 1);
4757       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
4758       if (TARGET_FLOAT64 && !TARGET_64BIT)
4759         emit_insn (gen_mfhc1<mode> (high, operands[1]));
4760       else
4761         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
4762     }
4763   DONE;
4764 })
4765
4766 ;; Load the low word of operand 0 with operand 1.
4767 (define_insn "load_low<mode>"
4768   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4769         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
4770                        UNSPEC_LOAD_LOW))]
4771   "TARGET_HARD_FLOAT"
4772 {
4773   operands[0] = mips_subword (operands[0], 0);
4774   return mips_output_move (operands[0], operands[1]);
4775 }
4776   [(set_attr "move_type" "mtc,fpload")
4777    (set_attr "mode" "<HALFMODE>")])
4778
4779 ;; Load the high word of operand 0 from operand 1, preserving the value
4780 ;; in the low word.
4781 (define_insn "load_high<mode>"
4782   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4783         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
4784                         (match_operand:SPLITF 2 "register_operand" "0,0")]
4785                        UNSPEC_LOAD_HIGH))]
4786   "TARGET_HARD_FLOAT"
4787 {
4788   operands[0] = mips_subword (operands[0], 1);
4789   return mips_output_move (operands[0], operands[1]);
4790 }
4791   [(set_attr "move_type" "mtc,fpload")
4792    (set_attr "mode" "<HALFMODE>")])
4793
4794 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
4795 ;; high word and 0 to store the low word.
4796 (define_insn "store_word<mode>"
4797   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
4798         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
4799                             (match_operand 2 "const_int_operand")]
4800                            UNSPEC_STORE_WORD))]
4801   "TARGET_HARD_FLOAT"
4802 {
4803   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
4804   return mips_output_move (operands[0], operands[1]);
4805 }
4806   [(set_attr "move_type" "mfc,fpstore")
4807    (set_attr "mode" "<HALFMODE>")])
4808
4809 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4810 ;; value in the low word.
4811 (define_insn "mthc1<mode>"
4812   [(set (match_operand:SPLITF 0 "register_operand" "=f")
4813         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
4814                         (match_operand:SPLITF 2 "register_operand" "0")]
4815                        UNSPEC_MTHC1))]
4816   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4817   "mthc1\t%z1,%0"
4818   [(set_attr "move_type" "mtc")
4819    (set_attr "mode" "<HALFMODE>")])
4820
4821 ;; Move high word of operand 1 to operand 0 using mfhc1.
4822 (define_insn "mfhc1<mode>"
4823   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
4824         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
4825                             UNSPEC_MFHC1))]
4826   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4827   "mfhc1\t%0,%1"
4828   [(set_attr "move_type" "mfc")
4829    (set_attr "mode" "<HALFMODE>")])
4830
4831 ;; Move a constant that satisfies CONST_GP_P into operand 0.
4832 (define_expand "load_const_gp_<mode>"
4833   [(set (match_operand:P 0 "register_operand" "=d")
4834         (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
4835
4836 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
4837 ;; of _gp from the start of this function.  Operand 1 is the incoming
4838 ;; function address.
4839 (define_insn_and_split "loadgp_newabi_<mode>"
4840   [(set (match_operand:P 0 "register_operand" "=d")
4841         (unspec:P [(match_operand:P 1)
4842                    (match_operand:P 2 "register_operand" "d")]
4843                   UNSPEC_LOADGP))]
4844   "mips_current_loadgp_style () == LOADGP_NEWABI"
4845   { return mips_must_initialize_gp_p () ? "#" : ""; }
4846   "&& mips_must_initialize_gp_p ()"
4847   [(set (match_dup 0) (match_dup 3))
4848    (set (match_dup 0) (match_dup 4))
4849    (set (match_dup 0) (match_dup 5))]
4850 {
4851   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
4852   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
4853   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
4854 }
4855   [(set_attr "type" "ghost")])
4856
4857 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
4858 (define_insn_and_split "loadgp_absolute_<mode>"
4859   [(set (match_operand:P 0 "register_operand" "=d")
4860         (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
4861   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
4862   { return mips_must_initialize_gp_p () ? "#" : ""; }
4863   "&& mips_must_initialize_gp_p ()"
4864   [(const_int 0)]
4865 {
4866   mips_emit_move (operands[0], operands[1]);
4867   DONE;
4868 }
4869   [(set_attr "type" "ghost")])
4870
4871 ;; This blockage instruction prevents the gp load from being
4872 ;; scheduled after an implicit use of gp.  It also prevents
4873 ;; the load from being deleted as dead.
4874 (define_insn "loadgp_blockage"
4875   [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
4876   ""
4877   ""
4878   [(set_attr "type" "ghost")])
4879
4880 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
4881 ;; and operand 1 is the __GOTT_INDEX__ symbol.
4882 (define_insn_and_split "loadgp_rtp_<mode>"
4883   [(set (match_operand:P 0 "register_operand" "=d")
4884         (unspec:P [(match_operand:P 1 "symbol_ref_operand")
4885                    (match_operand:P 2 "symbol_ref_operand")]
4886                   UNSPEC_LOADGP))]
4887   "mips_current_loadgp_style () == LOADGP_RTP"
4888   { return mips_must_initialize_gp_p () ? "#" : ""; }
4889   "&& mips_must_initialize_gp_p ()"
4890   [(set (match_dup 0) (high:P (match_dup 3)))
4891    (set (match_dup 0) (unspec:P [(match_dup 0)
4892                                  (match_dup 3)] UNSPEC_LOAD_GOT))
4893    (set (match_dup 0) (unspec:P [(match_dup 0)
4894                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
4895 {
4896   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
4897   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
4898 }
4899   [(set_attr "type" "ghost")])
4900
4901 ;; Initialize the global pointer for MIPS16 code.  Operand 0 is the
4902 ;; global pointer and operand 1 is the MIPS16 register that holds
4903 ;; the required value.
4904 (define_insn_and_split "copygp_mips16_<mode>"
4905   [(set (match_operand:P 0 "register_operand" "=y")
4906         (unspec:P [(match_operand:P 1 "register_operand" "d")]
4907                   UNSPEC_COPYGP))]
4908   "TARGET_MIPS16"
4909   { return mips_must_initialize_gp_p () ? "#" : ""; }
4910   "&& mips_must_initialize_gp_p ()"
4911   [(set (match_dup 0) (match_dup 1))]
4912   ""
4913   [(set_attr "type" "ghost")])
4914
4915 ;; A placeholder for where the cprestore instruction should go,
4916 ;; if we decide we need one.  Operand 0 and operand 1 are as for
4917 ;; "cprestore".  Operand 2 is a register that holds the gp value.
4918 ;;
4919 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
4920 ;; otherwise any register that holds the correct value will do.
4921 (define_insn_and_split "potential_cprestore_<mode>"
4922   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
4923         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
4924                    (match_operand:P 2 "register_operand" "d,d")]
4925                   UNSPEC_POTENTIAL_CPRESTORE))
4926    (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
4927   "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
4928   { return mips_must_initialize_gp_p () ? "#" : ""; }
4929   "mips_must_initialize_gp_p ()"
4930   [(const_int 0)]
4931 {
4932   mips_save_gp_to_cprestore_slot (operands[0], operands[1],
4933                                   operands[2], operands[3]);
4934   DONE;
4935 }
4936   [(set_attr "type" "ghost")])
4937
4938 ;; Emit a .cprestore directive, which normally expands to a single store
4939 ;; instruction.  Operand 0 is a (possibly illegitimate) sp-based MEM
4940 ;; for the cprestore slot.  Operand 1 is the offset of the slot from
4941 ;; the stack pointer.  (This is redundant with operand 0, but it makes
4942 ;; things a little simpler.)
4943 (define_insn "cprestore_<mode>"
4944   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
4945         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
4946                    (reg:P 28)]
4947                   UNSPEC_CPRESTORE))]
4948   "TARGET_CPRESTORE_DIRECTIVE"
4949 {
4950   if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
4951     return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
4952   else
4953     return ".cprestore\t%1";
4954 }
4955   [(set_attr "type" "store")
4956    (set_attr "length" "4,12")])
4957
4958 (define_insn "use_cprestore_<mode>"
4959   [(set (reg:P CPRESTORE_SLOT_REGNUM)
4960         (match_operand:P 0 "cprestore_load_slot_operand"))]
4961   ""
4962   ""
4963   [(set_attr "type" "ghost")])
4964
4965 ;; Expand in-line code to clear the instruction cache between operand[0] and
4966 ;; operand[1].
4967 (define_expand "clear_cache"
4968   [(match_operand 0 "pmode_register_operand")
4969    (match_operand 1 "pmode_register_operand")]
4970   ""
4971   "
4972 {
4973   if (TARGET_SYNCI)
4974     {
4975       mips_expand_synci_loop (operands[0], operands[1]);
4976       emit_insn (gen_sync ());
4977       emit_insn (PMODE_INSN (gen_clear_hazard, ()));
4978     }
4979   else if (mips_cache_flush_func && mips_cache_flush_func[0])
4980     {
4981       rtx len = gen_reg_rtx (Pmode);
4982       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
4983       MIPS_ICACHE_SYNC (operands[0], len);
4984     }
4985   DONE;
4986 }")
4987
4988 (define_insn "sync"
4989   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
4990   "GENERATE_SYNC"
4991   { return mips_output_sync (); })
4992
4993 (define_insn "synci"
4994   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
4995                     UNSPEC_SYNCI)]
4996   "TARGET_SYNCI"
4997   "synci\t0(%0)")
4998
4999 (define_insn "rdhwr_synci_step_<mode>"
5000   [(set (match_operand:P 0 "register_operand" "=d")
5001         (unspec_volatile [(const_int 1)]
5002         UNSPEC_RDHWR))]
5003   "ISA_HAS_SYNCI"
5004   "rdhwr\t%0,$1")
5005
5006 (define_insn "clear_hazard_<mode>"
5007   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5008    (clobber (reg:P RETURN_ADDR_REGNUM))]
5009   "ISA_HAS_SYNCI"
5010 {
5011   return "%(%<bal\t1f\n"
5012          "\tnop\n"
5013          "1:\t<d>addiu\t$31,$31,12\n"
5014          "\tjr.hb\t$31\n"
5015          "\tnop%>%)";
5016 }
5017   [(set_attr "length" "20")])
5018
5019 ;; Cache operations for R4000-style caches.
5020 (define_insn "mips_cache"
5021   [(set (mem:BLK (scratch))
5022         (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5023                      (match_operand:QI 1 "address_operand" "p")]
5024                     UNSPEC_MIPS_CACHE))]
5025   "ISA_HAS_CACHE"
5026   "cache\t%X0,%a1")
5027
5028 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5029 ;; operation.  We keep the pattern distinct so that we can identify
5030 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5031 ;; the operation is never inserted into a delay slot.
5032 (define_insn "r10k_cache_barrier"
5033   [(set (mem:BLK (scratch))
5034         (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5035   "ISA_HAS_CACHE"
5036   "cache\t0x14,0(%$)"
5037   [(set_attr "can_delay" "no")])
5038 \f
5039 ;; Block moves, see mips.c for more details.
5040 ;; Argument 0 is the destination
5041 ;; Argument 1 is the source
5042 ;; Argument 2 is the length
5043 ;; Argument 3 is the alignment
5044
5045 (define_expand "movmemsi"
5046   [(parallel [(set (match_operand:BLK 0 "general_operand")
5047                    (match_operand:BLK 1 "general_operand"))
5048               (use (match_operand:SI 2 ""))
5049               (use (match_operand:SI 3 "const_int_operand"))])]
5050   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5051 {
5052   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5053     DONE;
5054   else
5055     FAIL;
5056 })
5057 \f
5058 ;;
5059 ;;  ....................
5060 ;;
5061 ;;      SHIFTS
5062 ;;
5063 ;;  ....................
5064
5065 (define_expand "<optab><mode>3"
5066   [(set (match_operand:GPR 0 "register_operand")
5067         (any_shift:GPR (match_operand:GPR 1 "register_operand")
5068                        (match_operand:SI 2 "arith_operand")))]
5069   ""
5070 {
5071   /* On the mips16, a shift of more than 8 is a four byte instruction,
5072      so, for a shift between 8 and 16, it is just as fast to do two
5073      shifts of 8 or less.  If there is a lot of shifting going on, we
5074      may win in CSE.  Otherwise combine will put the shifts back
5075      together again.  This can be called by mips_function_arg, so we must
5076      be careful not to allocate a new register if we've reached the
5077      reload pass.  */
5078   if (TARGET_MIPS16
5079       && optimize
5080       && CONST_INT_P (operands[2])
5081       && INTVAL (operands[2]) > 8
5082       && INTVAL (operands[2]) <= 16
5083       && !reload_in_progress
5084       && !reload_completed)
5085     {
5086       rtx temp = gen_reg_rtx (<MODE>mode);
5087
5088       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5089       emit_insn (gen_<optab><mode>3 (operands[0], temp,
5090                                      GEN_INT (INTVAL (operands[2]) - 8)));
5091       DONE;
5092     }
5093 })
5094
5095 (define_insn "*<optab><mode>3"
5096   [(set (match_operand:GPR 0 "register_operand" "=d")
5097         (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
5098                        (match_operand:SI 2 "arith_operand" "dI")))]
5099   "!TARGET_MIPS16"
5100 {
5101   if (CONST_INT_P (operands[2]))
5102     operands[2] = GEN_INT (INTVAL (operands[2])
5103                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5104
5105   return "<d><insn>\t%0,%1,%2";
5106 }
5107   [(set_attr "type" "shift")
5108    (set_attr "mode" "<MODE>")])
5109
5110 (define_insn "*<optab>si3_extend"
5111   [(set (match_operand:DI 0 "register_operand" "=d")
5112         (sign_extend:DI
5113            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5114                          (match_operand:SI 2 "arith_operand" "dI"))))]
5115   "TARGET_64BIT && !TARGET_MIPS16"
5116 {
5117   if (CONST_INT_P (operands[2]))
5118     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5119
5120   return "<insn>\t%0,%1,%2";
5121 }
5122   [(set_attr "type" "shift")
5123    (set_attr "mode" "SI")])
5124
5125 (define_insn "*<optab>si3_mips16"
5126   [(set (match_operand:SI 0 "register_operand" "=d,d")
5127         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
5128                       (match_operand:SI 2 "arith_operand" "d,I")))]
5129   "TARGET_MIPS16"
5130 {
5131   if (which_alternative == 0)
5132     return "<insn>\t%0,%2";
5133
5134   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5135   return "<insn>\t%0,%1,%2";
5136 }
5137   [(set_attr "type" "shift")
5138    (set_attr "mode" "SI")
5139    (set_attr_alternative "length"
5140                 [(const_int 4)
5141                  (if_then_else (match_operand 2 "m16_uimm3_b")
5142                                (const_int 4)
5143                                (const_int 8))])])
5144
5145 ;; We need separate DImode MIPS16 patterns because of the irregularity
5146 ;; of right shifts.
5147 (define_insn "*ashldi3_mips16"
5148   [(set (match_operand:DI 0 "register_operand" "=d,d")
5149         (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
5150                    (match_operand:SI 2 "arith_operand" "d,I")))]
5151   "TARGET_64BIT && TARGET_MIPS16"
5152 {
5153   if (which_alternative == 0)
5154     return "dsll\t%0,%2";
5155
5156   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5157   return "dsll\t%0,%1,%2";
5158 }
5159   [(set_attr "type" "shift")
5160    (set_attr "mode" "DI")
5161    (set_attr_alternative "length"
5162                 [(const_int 4)
5163                  (if_then_else (match_operand 2 "m16_uimm3_b")
5164                                (const_int 4)
5165                                (const_int 8))])])
5166
5167 (define_insn "*ashrdi3_mips16"
5168   [(set (match_operand:DI 0 "register_operand" "=d,d")
5169         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5170                      (match_operand:SI 2 "arith_operand" "d,I")))]
5171   "TARGET_64BIT && TARGET_MIPS16"
5172 {
5173   if (CONST_INT_P (operands[2]))
5174     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5175
5176   return "dsra\t%0,%2";
5177 }
5178   [(set_attr "type" "shift")
5179    (set_attr "mode" "DI")
5180    (set_attr_alternative "length"
5181                 [(const_int 4)
5182                  (if_then_else (match_operand 2 "m16_uimm3_b")
5183                                (const_int 4)
5184                                (const_int 8))])])
5185
5186 (define_insn "*lshrdi3_mips16"
5187   [(set (match_operand:DI 0 "register_operand" "=d,d")
5188         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5189                      (match_operand:SI 2 "arith_operand" "d,I")))]
5190   "TARGET_64BIT && TARGET_MIPS16"
5191 {
5192   if (CONST_INT_P (operands[2]))
5193     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5194
5195   return "dsrl\t%0,%2";
5196 }
5197   [(set_attr "type" "shift")
5198    (set_attr "mode" "DI")
5199    (set_attr_alternative "length"
5200                 [(const_int 4)
5201                  (if_then_else (match_operand 2 "m16_uimm3_b")
5202                                (const_int 4)
5203                                (const_int 8))])])
5204
5205 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5206
5207 (define_split
5208   [(set (match_operand:GPR 0 "d_operand")
5209         (any_shift:GPR (match_operand:GPR 1 "d_operand")
5210                        (match_operand:GPR 2 "const_int_operand")))]
5211   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5212    && INTVAL (operands[2]) > 8
5213    && INTVAL (operands[2]) <= 16"
5214   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5215    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5216   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5217
5218 ;; If we load a byte on the mips16 as a bitfield, the resulting
5219 ;; sequence of instructions is too complicated for combine, because it
5220 ;; involves four instructions: a load, a shift, a constant load into a
5221 ;; register, and an and (the key problem here is that the mips16 does
5222 ;; not have and immediate).  We recognize a shift of a load in order
5223 ;; to make it simple enough for combine to understand.
5224 ;;
5225 ;; The length here is the worst case: the length of the split version
5226 ;; will be more accurate.
5227 (define_insn_and_split ""
5228   [(set (match_operand:SI 0 "register_operand" "=d")
5229         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5230                      (match_operand:SI 2 "immediate_operand" "I")))]
5231   "TARGET_MIPS16"
5232   "#"
5233   ""
5234   [(set (match_dup 0) (match_dup 1))
5235    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5236   ""
5237   [(set_attr "type"     "load")
5238    (set_attr "mode"     "SI")
5239    (set_attr "length"   "16")])
5240
5241 (define_insn "rotr<mode>3"
5242   [(set (match_operand:GPR 0 "register_operand" "=d")
5243         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5244                       (match_operand:SI 2 "arith_operand" "dI")))]
5245   "ISA_HAS_ROR"
5246 {
5247   if (CONST_INT_P (operands[2]))
5248     gcc_assert (INTVAL (operands[2]) >= 0
5249                 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5250
5251   return "<d>ror\t%0,%1,%2";
5252 }
5253   [(set_attr "type" "shift")
5254    (set_attr "mode" "<MODE>")])
5255 \f
5256 ;;
5257 ;;  ....................
5258 ;;
5259 ;;      CONDITIONAL BRANCHES
5260 ;;
5261 ;;  ....................
5262
5263 ;; Conditional branches on floating-point equality tests.
5264
5265 (define_insn "*branch_fp"
5266   [(set (pc)
5267         (if_then_else
5268          (match_operator 1 "equality_operator"
5269                          [(match_operand:CC 2 "register_operand" "z")
5270                           (const_int 0)])
5271          (label_ref (match_operand 0 "" ""))
5272          (pc)))]
5273   "TARGET_HARD_FLOAT"
5274 {
5275   return mips_output_conditional_branch (insn, operands,
5276                                          MIPS_BRANCH ("b%F1", "%Z2%0"),
5277                                          MIPS_BRANCH ("b%W1", "%Z2%0"));
5278 }
5279   [(set_attr "type" "branch")])
5280
5281 (define_insn "*branch_fp_inverted"
5282   [(set (pc)
5283         (if_then_else
5284          (match_operator 1 "equality_operator"
5285                          [(match_operand:CC 2 "register_operand" "z")
5286                           (const_int 0)])
5287          (pc)
5288          (label_ref (match_operand 0 "" ""))))]
5289   "TARGET_HARD_FLOAT"
5290 {
5291   return mips_output_conditional_branch (insn, operands,
5292                                          MIPS_BRANCH ("b%W1", "%Z2%0"),
5293                                          MIPS_BRANCH ("b%F1", "%Z2%0"));
5294 }
5295   [(set_attr "type" "branch")])
5296
5297 ;; Conditional branches on ordered comparisons with zero.
5298
5299 (define_insn "*branch_order<mode>"
5300   [(set (pc)
5301         (if_then_else
5302          (match_operator 1 "order_operator"
5303                          [(match_operand:GPR 2 "register_operand" "d")
5304                           (const_int 0)])
5305          (label_ref (match_operand 0 "" ""))
5306          (pc)))]
5307   "!TARGET_MIPS16"
5308   { return mips_output_order_conditional_branch (insn, operands, false); }
5309   [(set_attr "type" "branch")])
5310
5311 (define_insn "*branch_order<mode>_inverted"
5312   [(set (pc)
5313         (if_then_else
5314          (match_operator 1 "order_operator"
5315                          [(match_operand:GPR 2 "register_operand" "d")
5316                           (const_int 0)])
5317          (pc)
5318          (label_ref (match_operand 0 "" ""))))]
5319   "!TARGET_MIPS16"
5320   { return mips_output_order_conditional_branch (insn, operands, true); }
5321   [(set_attr "type" "branch")])
5322
5323 ;; Conditional branch on equality comparison.
5324
5325 (define_insn "*branch_equality<mode>"
5326   [(set (pc)
5327         (if_then_else
5328          (match_operator 1 "equality_operator"
5329                          [(match_operand:GPR 2 "register_operand" "d")
5330                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5331          (label_ref (match_operand 0 "" ""))
5332          (pc)))]
5333   "!TARGET_MIPS16"
5334 {
5335   return mips_output_conditional_branch (insn, operands,
5336                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5337                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5338 }
5339   [(set_attr "type" "branch")])
5340
5341 (define_insn "*branch_equality<mode>_inverted"
5342   [(set (pc)
5343         (if_then_else
5344          (match_operator 1 "equality_operator"
5345                          [(match_operand:GPR 2 "register_operand" "d")
5346                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5347          (pc)
5348          (label_ref (match_operand 0 "" ""))))]
5349   "!TARGET_MIPS16"
5350 {
5351   return mips_output_conditional_branch (insn, operands,
5352                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5353                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5354 }
5355   [(set_attr "type" "branch")])
5356
5357 ;; MIPS16 branches
5358
5359 (define_insn "*branch_equality<mode>_mips16"
5360   [(set (pc)
5361         (if_then_else
5362          (match_operator 0 "equality_operator"
5363                          [(match_operand:GPR 1 "register_operand" "d,t")
5364                           (const_int 0)])
5365          (match_operand 2 "pc_or_label_operand" "")
5366          (match_operand 3 "pc_or_label_operand" "")))]
5367   "TARGET_MIPS16"
5368 {
5369   if (operands[2] != pc_rtx)
5370     {
5371       if (which_alternative == 0)
5372         return "b%C0z\t%1,%2";
5373       else
5374         return "bt%C0z\t%2";
5375     }
5376   else
5377     {
5378       if (which_alternative == 0)
5379         return "b%N0z\t%1,%3";
5380       else
5381         return "bt%N0z\t%3";
5382     }
5383 }
5384   [(set_attr "type" "branch")])
5385
5386 (define_expand "cbranch<mode>4"
5387   [(set (pc)
5388         (if_then_else (match_operator 0 "comparison_operator"
5389                        [(match_operand:GPR 1 "register_operand")
5390                         (match_operand:GPR 2 "nonmemory_operand")])
5391                       (label_ref (match_operand 3 ""))
5392                       (pc)))]
5393   ""
5394 {
5395   mips_expand_conditional_branch (operands);
5396   DONE;
5397 })
5398
5399 (define_expand "cbranch<mode>4"
5400   [(set (pc)
5401         (if_then_else (match_operator 0 "comparison_operator"
5402                        [(match_operand:SCALARF 1 "register_operand")
5403                         (match_operand:SCALARF 2 "register_operand")])
5404                       (label_ref (match_operand 3 ""))
5405                       (pc)))]
5406   ""
5407 {
5408   mips_expand_conditional_branch (operands);
5409   DONE;
5410 })
5411
5412 ;; Used to implement built-in functions.
5413 (define_expand "condjump"
5414   [(set (pc)
5415         (if_then_else (match_operand 0)
5416                       (label_ref (match_operand 1))
5417                       (pc)))])
5418
5419 ;; Branch if bit is set/clear.
5420
5421 (define_insn "*branch_bit<bbv><mode>"
5422   [(set (pc)
5423         (if_then_else
5424          (equality_op (zero_extract:GPR
5425                        (match_operand:GPR 1 "register_operand" "d")
5426                        (const_int 1)
5427                        (match_operand 2 "const_int_operand" ""))
5428                       (const_int 0))
5429          (label_ref (match_operand 0 ""))
5430          (pc)))]
5431   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5432 {
5433   return
5434     mips_output_conditional_branch (insn, operands,
5435                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5436                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5437 }
5438   [(set_attr "type"          "branch")
5439    (set_attr "branch_likely" "no")])
5440
5441 (define_insn "*branch_bit<bbv><mode>_inverted"
5442   [(set (pc)
5443         (if_then_else
5444          (equality_op (zero_extract:GPR
5445                        (match_operand:GPR 1 "register_operand" "d")
5446                        (const_int 1)
5447                        (match_operand 2 "const_int_operand" ""))
5448                       (const_int 0))
5449          (pc)
5450          (label_ref (match_operand 0 ""))))]
5451   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5452 {
5453   return
5454     mips_output_conditional_branch (insn, operands,
5455                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5456                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5457 }
5458   [(set_attr "type"          "branch")
5459    (set_attr "branch_likely" "no")])
5460 \f
5461 ;;
5462 ;;  ....................
5463 ;;
5464 ;;      SETTING A REGISTER FROM A COMPARISON
5465 ;;
5466 ;;  ....................
5467
5468 ;; Destination is always set in SI mode.
5469
5470 (define_expand "cstore<mode>4"
5471   [(set (match_operand:SI 0 "register_operand")
5472         (match_operator:SI 1 "mips_cstore_operator"
5473          [(match_operand:GPR 2 "register_operand")
5474           (match_operand:GPR 3 "nonmemory_operand")]))]
5475   ""
5476 {
5477   mips_expand_scc (operands);
5478   DONE;
5479 })
5480
5481 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5482   [(set (match_operand:GPR2 0 "register_operand" "=d")
5483         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5484                  (const_int 0)))]
5485   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5486   "sltu\t%0,%1,1"
5487   [(set_attr "type" "slt")
5488    (set_attr "mode" "<GPR:MODE>")])
5489
5490 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5491   [(set (match_operand:GPR2 0 "register_operand" "=t")
5492         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5493                  (const_int 0)))]
5494   "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5495   "sltu\t%1,1"
5496   [(set_attr "type" "slt")
5497    (set_attr "mode" "<GPR:MODE>")])
5498
5499 ;; Generate sltiu unless using seq results in better code.
5500 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5501   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5502         (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5503                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5504   "ISA_HAS_SEQ_SNE"
5505   "@
5506    seq\t%0,%1,%2
5507    sltiu\t%0,%1,1
5508    seqi\t%0,%1,%2"
5509   [(set_attr "type" "slt")
5510    (set_attr "mode" "<GPR:MODE>")])
5511
5512 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5513   [(set (match_operand:GPR2 0 "register_operand" "=d")
5514         (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5515                  (const_int 0)))]
5516   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5517   "sltu\t%0,%.,%1"
5518   [(set_attr "type" "slt")
5519    (set_attr "mode" "<GPR:MODE>")])
5520
5521 ;; Generate sltu unless using sne results in better code.
5522 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5523   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5524         (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5525                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5526   "ISA_HAS_SEQ_SNE"
5527   "@
5528    sne\t%0,%1,%2
5529    sltu\t%0,%.,%1
5530    snei\t%0,%1,%2"
5531   [(set_attr "type" "slt")
5532    (set_attr "mode" "<GPR:MODE>")])
5533
5534 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5535   [(set (match_operand:GPR2 0 "register_operand" "=d")
5536         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5537                      (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5538   "!TARGET_MIPS16"
5539   "slt<u>\t%0,%z2,%1"
5540   [(set_attr "type" "slt")
5541    (set_attr "mode" "<GPR:MODE>")])
5542
5543 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5544   [(set (match_operand:GPR2 0 "register_operand" "=t")
5545         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5546                      (match_operand:GPR 2 "register_operand" "d")))]
5547   "TARGET_MIPS16"
5548   "slt<u>\t%2,%1"
5549   [(set_attr "type" "slt")
5550    (set_attr "mode" "<GPR:MODE>")])
5551
5552 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
5553   [(set (match_operand:GPR2 0 "register_operand" "=d")
5554         (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
5555                      (const_int 1)))]
5556   "!TARGET_MIPS16"
5557   "slt<u>\t%0,%.,%1"
5558   [(set_attr "type" "slt")
5559    (set_attr "mode" "<GPR:MODE>")])
5560
5561 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
5562   [(set (match_operand:GPR2 0 "register_operand" "=d")
5563         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5564                      (match_operand:GPR 2 "arith_operand" "dI")))]
5565   "!TARGET_MIPS16"
5566   "slt<u>\t%0,%1,%2"
5567   [(set_attr "type" "slt")
5568    (set_attr "mode" "<GPR:MODE>")])
5569
5570 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
5571   [(set (match_operand:GPR2 0 "register_operand" "=t,t")
5572         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
5573                      (match_operand:GPR 2 "arith_operand" "d,I")))]
5574   "TARGET_MIPS16"
5575   "slt<u>\t%1,%2"
5576   [(set_attr "type" "slt")
5577    (set_attr "mode" "<GPR:MODE>")
5578    (set_attr_alternative "length"
5579                 [(const_int 4)
5580                  (if_then_else (match_operand 2 "m16_uimm8_1")
5581                                (const_int 4)
5582                                (const_int 8))])])
5583
5584 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
5585   [(set (match_operand:GPR2 0 "register_operand" "=d")
5586         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5587                      (match_operand:GPR 2 "sle_operand" "")))]
5588   "!TARGET_MIPS16"
5589 {
5590   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5591   return "slt<u>\t%0,%1,%2";
5592 }
5593   [(set_attr "type" "slt")
5594    (set_attr "mode" "<GPR:MODE>")])
5595
5596 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
5597   [(set (match_operand:GPR2 0 "register_operand" "=t")
5598         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5599                      (match_operand:GPR 2 "sle_operand" "")))]
5600   "TARGET_MIPS16"
5601 {
5602   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5603   return "slt<u>\t%1,%2";
5604 }
5605   [(set_attr "type" "slt")
5606    (set_attr "mode" "<GPR:MODE>")
5607    (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5608                                       (const_int 4)
5609                                       (const_int 8)))])
5610 \f
5611 ;;
5612 ;;  ....................
5613 ;;
5614 ;;      FLOATING POINT COMPARISONS
5615 ;;
5616 ;;  ....................
5617
5618 (define_insn "s<code>_<mode>"
5619   [(set (match_operand:CC 0 "register_operand" "=z")
5620         (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5621                   (match_operand:SCALARF 2 "register_operand" "f")))]
5622   ""
5623   "c.<fcond>.<fmt>\t%Z0%1,%2"
5624   [(set_attr "type" "fcmp")
5625    (set_attr "mode" "FPSW")])
5626
5627 (define_insn "s<code>_<mode>"
5628   [(set (match_operand:CC 0 "register_operand" "=z")
5629         (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5630                           (match_operand:SCALARF 2 "register_operand" "f")))]
5631   ""
5632   "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5633   [(set_attr "type" "fcmp")
5634    (set_attr "mode" "FPSW")])
5635 \f
5636 ;;
5637 ;;  ....................
5638 ;;
5639 ;;      UNCONDITIONAL BRANCHES
5640 ;;
5641 ;;  ....................
5642
5643 ;; Unconditional branches.
5644
5645 (define_expand "jump"
5646   [(set (pc)
5647         (label_ref (match_operand 0)))])
5648
5649 (define_insn "*jump_absolute"
5650   [(set (pc)
5651         (label_ref (match_operand 0)))]
5652   "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
5653   { return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/"); }
5654   [(set_attr "type" "jump")])
5655
5656 (define_insn "*jump_pic"
5657   [(set (pc)
5658         (label_ref (match_operand 0)))]
5659   "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
5660 {
5661   if (get_attr_length (insn) <= 8)
5662     return "%*b\t%l0%/";
5663   else
5664     {
5665       mips_output_load_label (operands[0]);
5666       return "%*jr\t%@%/%]";
5667     }
5668 }
5669   [(set_attr "type" "branch")])
5670
5671 ;; We need a different insn for the mips16, because a mips16 branch
5672 ;; does not have a delay slot.
5673
5674 (define_insn "*jump_mips16"
5675   [(set (pc)
5676         (label_ref (match_operand 0 "" "")))]
5677   "TARGET_MIPS16"
5678   "b\t%l0"
5679   [(set_attr "type" "branch")])
5680
5681 (define_expand "indirect_jump"
5682   [(set (pc) (match_operand 0 "register_operand"))]
5683   ""
5684 {
5685   operands[0] = force_reg (Pmode, operands[0]);
5686   emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
5687   DONE;
5688 })
5689
5690 (define_insn "indirect_jump_<mode>"
5691   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5692   ""
5693   "%*j\t%0%/"
5694   [(set_attr "type" "jump")
5695    (set_attr "mode" "none")])
5696
5697 (define_expand "tablejump"
5698   [(set (pc)
5699         (match_operand 0 "register_operand"))
5700    (use (label_ref (match_operand 1 "")))]
5701   ""
5702 {
5703   if (TARGET_MIPS16_SHORT_JUMP_TABLES)
5704     operands[0] = expand_binop (Pmode, add_optab,
5705                                 convert_to_mode (Pmode, operands[0], false),
5706                                 gen_rtx_LABEL_REF (Pmode, operands[1]),
5707                                 0, 0, OPTAB_WIDEN);
5708   else if (TARGET_GPWORD)
5709     operands[0] = expand_binop (Pmode, add_optab, operands[0],
5710                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5711   else if (TARGET_RTP_PIC)
5712     {
5713       /* When generating RTP PIC, we use case table entries that are relative
5714          to the start of the function.  Add the function's address to the
5715          value we loaded.  */
5716       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5717       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5718                                   start, 0, 0, OPTAB_WIDEN);
5719     }
5720
5721   emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
5722   DONE;
5723 })
5724
5725 (define_insn "tablejump_<mode>"
5726   [(set (pc)
5727         (match_operand:P 0 "register_operand" "d"))
5728    (use (label_ref (match_operand 1 "" "")))]
5729   ""
5730   "%*j\t%0%/"
5731   [(set_attr "type" "jump")
5732    (set_attr "mode" "none")])
5733
5734 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
5735 ;; While it is possible to either pull it off the stack (in the
5736 ;; o32 case) or recalculate it given t9 and our target label,
5737 ;; it takes 3 or 4 insns to do so.
5738
5739 (define_expand "builtin_setjmp_setup"
5740   [(use (match_operand 0 "register_operand"))]
5741   "TARGET_USE_GOT"
5742 {
5743   rtx addr;
5744
5745   addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
5746   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
5747   DONE;
5748 })
5749
5750 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
5751 ;; that older code did recalculate the gp from $25.  Continue to jump through
5752 ;; $25 for compatibility (we lose nothing by doing so).
5753
5754 (define_expand "builtin_longjmp"
5755   [(use (match_operand 0 "register_operand"))]
5756   "TARGET_USE_GOT"
5757 {
5758   /* The elements of the buffer are, in order:  */
5759   int W = GET_MODE_SIZE (Pmode);
5760   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
5761   rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
5762   rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
5763   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
5764   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5765   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
5766      The target is bound to be using $28 as the global pointer
5767      but the current function might not be.  */
5768   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
5769
5770   /* This bit is similar to expand_builtin_longjmp except that it
5771      restores $gp as well.  */
5772   mips_emit_move (hard_frame_pointer_rtx, fp);
5773   mips_emit_move (pv, lab);
5774   emit_stack_restore (SAVE_NONLOCAL, stack);
5775   mips_emit_move (gp, gpv);
5776   emit_use (hard_frame_pointer_rtx);
5777   emit_use (stack_pointer_rtx);
5778   emit_use (gp);
5779   emit_indirect_jump (pv);
5780   DONE;
5781 })
5782 \f
5783 ;;
5784 ;;  ....................
5785 ;;
5786 ;;      Function prologue/epilogue
5787 ;;
5788 ;;  ....................
5789 ;;
5790
5791 (define_expand "prologue"
5792   [(const_int 1)]
5793   ""
5794 {
5795   mips_expand_prologue ();
5796   DONE;
5797 })
5798
5799 ;; Block any insns from being moved before this point, since the
5800 ;; profiling call to mcount can use various registers that aren't
5801 ;; saved or used to pass arguments.
5802
5803 (define_insn "blockage"
5804   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
5805   ""
5806   ""
5807   [(set_attr "type" "ghost")
5808    (set_attr "mode" "none")])
5809
5810 (define_expand "epilogue"
5811   [(const_int 2)]
5812   ""
5813 {
5814   mips_expand_epilogue (false);
5815   DONE;
5816 })
5817
5818 (define_expand "sibcall_epilogue"
5819   [(const_int 2)]
5820   ""
5821 {
5822   mips_expand_epilogue (true);
5823   DONE;
5824 })
5825
5826 ;; Trivial return.  Make it look like a normal return insn as that
5827 ;; allows jump optimizations to work better.
5828
5829 (define_expand "return"
5830   [(simple_return)]
5831   "mips_can_use_return_insn ()"
5832   { mips_expand_before_return (); })
5833
5834 (define_expand "simple_return"
5835   [(simple_return)]
5836   ""
5837   { mips_expand_before_return (); })
5838
5839 (define_insn "*<optab>"
5840   [(any_return)]
5841   ""
5842   "%*j\t$31%/"
5843   [(set_attr "type"     "jump")
5844    (set_attr "mode"     "none")])
5845
5846 ;; Normal return.
5847
5848 (define_insn "<optab>_internal"
5849   [(any_return)
5850    (use (match_operand 0 "pmode_register_operand" ""))]
5851   ""
5852   "%*j\t%0%/"
5853   [(set_attr "type"     "jump")
5854    (set_attr "mode"     "none")])
5855
5856 ;; Exception return.
5857 (define_insn "mips_eret"
5858   [(return)
5859    (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
5860   ""
5861   "eret"
5862   [(set_attr "type"     "trap")
5863    (set_attr "mode"     "none")])
5864
5865 ;; Debug exception return.
5866 (define_insn "mips_deret"
5867   [(return)
5868    (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
5869   ""
5870   "deret"
5871   [(set_attr "type"     "trap")
5872    (set_attr "mode"     "none")])
5873
5874 ;; Disable interrupts.
5875 (define_insn "mips_di"
5876   [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
5877   ""
5878   "di"
5879   [(set_attr "type"     "trap")
5880    (set_attr "mode"     "none")])
5881
5882 ;; Execution hazard barrier.
5883 (define_insn "mips_ehb"
5884   [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
5885   ""
5886   "ehb"
5887   [(set_attr "type"     "trap")
5888    (set_attr "mode"     "none")])
5889
5890 ;; Read GPR from previous shadow register set.
5891 (define_insn "mips_rdpgpr"
5892   [(set (match_operand:SI 0 "register_operand" "=d")
5893         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
5894                             UNSPEC_RDPGPR))]
5895   ""
5896   "rdpgpr\t%0,%1"
5897   [(set_attr "type"     "move")
5898    (set_attr "mode"     "SI")])
5899
5900 ;; Move involving COP0 registers.
5901 (define_insn "cop0_move"
5902   [(set (match_operand:SI 0 "register_operand" "=B,d")
5903         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
5904                             UNSPEC_COP0))]
5905   ""
5906 { return mips_output_move (operands[0], operands[1]); }
5907   [(set_attr "type"     "mtc,mfc")
5908    (set_attr "mode"     "SI")])
5909
5910 ;; This is used in compiling the unwind routines.
5911 (define_expand "eh_return"
5912   [(use (match_operand 0 "general_operand"))]
5913   ""
5914 {
5915   if (GET_MODE (operands[0]) != word_mode)
5916     operands[0] = convert_to_mode (word_mode, operands[0], 0);
5917   if (TARGET_64BIT)
5918     emit_insn (gen_eh_set_lr_di (operands[0]));
5919   else
5920     emit_insn (gen_eh_set_lr_si (operands[0]));
5921   DONE;
5922 })
5923
5924 ;; Clobber the return address on the stack.  We can't expand this
5925 ;; until we know where it will be put in the stack frame.
5926
5927 (define_insn "eh_set_lr_si"
5928   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5929    (clobber (match_scratch:SI 1 "=&d"))]
5930   "! TARGET_64BIT"
5931   "#")
5932
5933 (define_insn "eh_set_lr_di"
5934   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
5935    (clobber (match_scratch:DI 1 "=&d"))]
5936   "TARGET_64BIT"
5937   "#")
5938
5939 (define_split
5940   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
5941    (clobber (match_scratch 1))]
5942   "reload_completed"
5943   [(const_int 0)]
5944 {
5945   mips_set_return_address (operands[0], operands[1]);
5946   DONE;
5947 })
5948
5949 (define_expand "exception_receiver"
5950   [(const_int 0)]
5951   "TARGET_USE_GOT"
5952 {
5953   /* See the comment above load_call<mode> for details.  */
5954   emit_insn (gen_set_got_version ());
5955
5956   /* If we have a call-clobbered $gp, restore it from its save slot.  */
5957   if (HAVE_restore_gp_si)
5958     emit_insn (gen_restore_gp_si ());
5959   else if (HAVE_restore_gp_di)
5960     emit_insn (gen_restore_gp_di ());
5961   DONE;
5962 })
5963
5964 (define_expand "nonlocal_goto_receiver"
5965   [(const_int 0)]
5966   "TARGET_USE_GOT"
5967 {
5968   /* See the comment above load_call<mode> for details.  */
5969   emit_insn (gen_set_got_version ());
5970   DONE;
5971 })
5972
5973 ;; Restore $gp from its .cprestore stack slot.  The instruction remains
5974 ;; volatile until all uses of $28 are exposed.
5975 (define_insn_and_split "restore_gp_<mode>"
5976   [(set (reg:P 28)
5977         (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
5978    (clobber (match_scratch:P 0 "=&d"))]
5979   "TARGET_CALL_CLOBBERED_GP"
5980   "#"
5981   "&& epilogue_completed"
5982   [(const_int 0)]
5983 {
5984   mips_restore_gp_from_cprestore_slot (operands[0]);
5985   DONE;
5986 }
5987   [(set_attr "type" "ghost")])
5988
5989 ;; Move between $gp and its register save slot.
5990 (define_insn_and_split "move_gp<mode>"
5991   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
5992         (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
5993                     UNSPEC_MOVE_GP))]
5994   ""
5995   { return mips_must_initialize_gp_p () ? "#" : ""; }
5996   "mips_must_initialize_gp_p ()"
5997   [(const_int 0)]
5998 {
5999   mips_emit_move (operands[0], operands[1]);
6000   DONE;
6001 }
6002   [(set_attr "type" "ghost")])
6003 \f
6004 ;;
6005 ;;  ....................
6006 ;;
6007 ;;      FUNCTION CALLS
6008 ;;
6009 ;;  ....................
6010
6011 ;; Instructions to load a call address from the GOT.  The address might
6012 ;; point to a function or to a lazy binding stub.  In the latter case,
6013 ;; the stub will use the dynamic linker to resolve the function, which
6014 ;; in turn will change the GOT entry to point to the function's real
6015 ;; address.
6016 ;;
6017 ;; This means that every call, even pure and constant ones, can
6018 ;; potentially modify the GOT entry.  And once a stub has been called,
6019 ;; we must not call it again.
6020 ;;
6021 ;; We represent this restriction using an imaginary, fixed, call-saved
6022 ;; register called GOT_VERSION_REGNUM.  The idea is to make the register
6023 ;; live throughout the function and to change its value after every
6024 ;; potential call site.  This stops any rtx value that uses the register
6025 ;; from being computed before an earlier call.  To do this, we:
6026 ;;
6027 ;;    - Ensure that the register is live on entry to the function,
6028 ;;      so that it is never thought to be used uninitalized.
6029 ;;
6030 ;;    - Ensure that the register is live on exit from the function,
6031 ;;      so that it is live throughout.
6032 ;;
6033 ;;    - Make each call (lazily-bound or not) use the current value
6034 ;;      of GOT_VERSION_REGNUM, so that updates of the register are
6035 ;;      not moved across call boundaries.
6036 ;;
6037 ;;    - Add "ghost" definitions of the register to the beginning of
6038 ;;      blocks reached by EH and ABNORMAL_CALL edges, because those
6039 ;;      edges may involve calls that normal paths don't.  (E.g. the
6040 ;;      unwinding code that handles a non-call exception may change
6041 ;;      lazily-bound GOT entries.)  We do this by making the
6042 ;;      exception_receiver and nonlocal_goto_receiver expanders emit
6043 ;;      a set_got_version instruction.
6044 ;;
6045 ;;    - After each call (lazily-bound or not), use a "ghost"
6046 ;;      update_got_version instruction to change the register's value.
6047 ;;      This instruction mimics the _possible_ effect of the dynamic
6048 ;;      resolver during the call and it remains live even if the call
6049 ;;      itself becomes dead.
6050 ;;
6051 ;;    - Leave GOT_VERSION_REGNUM out of all register classes.
6052 ;;      The register is therefore not a valid register_operand
6053 ;;      and cannot be moved to or from other registers.
6054
6055 (define_insn "load_call<mode>"
6056   [(set (match_operand:P 0 "register_operand" "=d")
6057         (unspec:P [(match_operand:P 1 "register_operand" "d")
6058                    (match_operand:P 2 "immediate_operand" "")
6059                    (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6060   "TARGET_USE_GOT"
6061   "<load>\t%0,%R2(%1)"
6062   [(set_attr "got" "load")
6063    (set_attr "mode" "<MODE>")])
6064
6065 (define_insn "set_got_version"
6066   [(set (reg:SI GOT_VERSION_REGNUM)
6067         (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6068   "TARGET_USE_GOT"
6069   ""
6070   [(set_attr "type" "ghost")])
6071
6072 (define_insn "update_got_version"
6073   [(set (reg:SI GOT_VERSION_REGNUM)
6074         (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6075   "TARGET_USE_GOT"
6076   ""
6077   [(set_attr "type" "ghost")])
6078
6079 ;; Sibling calls.  All these patterns use jump instructions.
6080
6081 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6082 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
6083 ;; is defined in terms of call_insn_operand, the same is true of the
6084 ;; constraints.
6085
6086 ;; When we use an indirect jump, we need a register that will be
6087 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
6088 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6089 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6090 ;; as well.
6091
6092 (define_expand "sibcall"
6093   [(parallel [(call (match_operand 0 "")
6094                     (match_operand 1 ""))
6095               (use (match_operand 2 ""))        ;; next_arg_reg
6096               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6097   "TARGET_SIBCALLS"
6098 {
6099   mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6100                     operands[1], operands[2], false);
6101   DONE;
6102 })
6103
6104 (define_insn "sibcall_internal"
6105   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6106          (match_operand 1 "" ""))]
6107   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6108   { return MIPS_CALL ("j", operands, 0, 1); }
6109   [(set_attr "type" "call")])
6110
6111 (define_expand "sibcall_value"
6112   [(parallel [(set (match_operand 0 "")
6113                    (call (match_operand 1 "")
6114                          (match_operand 2 "")))
6115               (use (match_operand 3 ""))])]             ;; next_arg_reg
6116   "TARGET_SIBCALLS"
6117 {
6118   mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6119                     operands[2], operands[3], false);
6120   DONE;
6121 })
6122
6123 (define_insn "sibcall_value_internal"
6124   [(set (match_operand 0 "register_operand" "")
6125         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6126               (match_operand 2 "" "")))]
6127   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6128   { return MIPS_CALL ("j", operands, 1, 2); }
6129   [(set_attr "type" "call")])
6130
6131 (define_insn "sibcall_value_multiple_internal"
6132   [(set (match_operand 0 "register_operand" "")
6133         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6134               (match_operand 2 "" "")))
6135    (set (match_operand 3 "register_operand" "")
6136         (call (mem:SI (match_dup 1))
6137               (match_dup 2)))]
6138   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6139   { return MIPS_CALL ("j", operands, 1, 2); }
6140   [(set_attr "type" "call")])
6141
6142 (define_expand "call"
6143   [(parallel [(call (match_operand 0 "")
6144                     (match_operand 1 ""))
6145               (use (match_operand 2 ""))        ;; next_arg_reg
6146               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6147   ""
6148 {
6149   mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6150                     operands[1], operands[2], false);
6151   DONE;
6152 })
6153
6154 ;; This instruction directly corresponds to an assembly-language "jal".
6155 ;; There are four cases:
6156 ;;
6157 ;;    - -mno-abicalls:
6158 ;;        Both symbolic and register destinations are OK.  The pattern
6159 ;;        always expands to a single mips instruction.
6160 ;;
6161 ;;    - -mabicalls/-mno-explicit-relocs:
6162 ;;        Again, both symbolic and register destinations are OK.
6163 ;;        The call is treated as a multi-instruction black box.
6164 ;;
6165 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
6166 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
6167 ;;        instruction.
6168 ;;
6169 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
6170 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
6171 ;;        "jalr $25" followed by an insn to reload $gp.
6172 ;;
6173 ;; In the last case, we can generate the individual instructions with
6174 ;; a define_split.  There are several things to be wary of:
6175 ;;
6176 ;;   - We can't expose the load of $gp before reload.  If we did,
6177 ;;     it might get removed as dead, but reload can introduce new
6178 ;;     uses of $gp by rematerializing constants.
6179 ;;
6180 ;;   - We shouldn't restore $gp after calls that never return.
6181 ;;     It isn't valid to insert instructions between a noreturn
6182 ;;     call and the following barrier.
6183 ;;
6184 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
6185 ;;     instruction preserves $gp and so have no effect on its liveness.
6186 ;;     But once we generate the separate insns, it becomes obvious that
6187 ;;     $gp is not live on entry to the call.
6188 ;;
6189 (define_insn_and_split "call_internal"
6190   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6191          (match_operand 1 "" ""))
6192    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6193   ""
6194   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6195   "reload_completed && TARGET_SPLIT_CALLS"
6196   [(const_int 0)]
6197 {
6198   mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6199   DONE;
6200 }
6201   [(set_attr "jal" "indirect,direct")])
6202
6203 (define_insn "call_split"
6204   [(call (mem:SI (match_operand 0 "call_insn_operand" "cS"))
6205          (match_operand 1 "" ""))
6206    (clobber (reg:SI RETURN_ADDR_REGNUM))
6207    (clobber (reg:SI 28))]
6208   "TARGET_SPLIT_CALLS"
6209   { return MIPS_CALL ("jal", operands, 0, 1); }
6210   [(set_attr "type" "call")])
6211
6212 ;; A pattern for calls that must be made directly.  It is used for
6213 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6214 ;; stub; the linker relies on the call relocation type to detect when
6215 ;; such redirection is needed.
6216 (define_insn_and_split "call_internal_direct"
6217   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6218          (match_operand 1))
6219    (const_int 1)
6220    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6221   ""
6222   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6223   "reload_completed && TARGET_SPLIT_CALLS"
6224   [(const_int 0)]
6225 {
6226   mips_split_call (curr_insn,
6227                    gen_call_direct_split (operands[0], operands[1]));
6228   DONE;
6229 }
6230   [(set_attr "type" "call")])
6231
6232 (define_insn "call_direct_split"
6233   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6234          (match_operand 1))
6235    (const_int 1)
6236    (clobber (reg:SI RETURN_ADDR_REGNUM))
6237    (clobber (reg:SI 28))]
6238   "TARGET_SPLIT_CALLS"
6239   { return MIPS_CALL ("jal", operands, 0, -1); }
6240   [(set_attr "type" "call")])
6241
6242 (define_expand "call_value"
6243   [(parallel [(set (match_operand 0 "")
6244                    (call (match_operand 1 "")
6245                          (match_operand 2 "")))
6246               (use (match_operand 3 ""))])]             ;; next_arg_reg
6247   ""
6248 {
6249   mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6250                     operands[2], operands[3], false);
6251   DONE;
6252 })
6253
6254 ;; See comment for call_internal.
6255 (define_insn_and_split "call_value_internal"
6256   [(set (match_operand 0 "register_operand" "")
6257         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6258               (match_operand 2 "" "")))
6259    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6260   ""
6261   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6262   "reload_completed && TARGET_SPLIT_CALLS"
6263   [(const_int 0)]
6264 {
6265   mips_split_call (curr_insn,
6266                    gen_call_value_split (operands[0], operands[1],
6267                                          operands[2]));
6268   DONE;
6269 }
6270   [(set_attr "jal" "indirect,direct")])
6271
6272 (define_insn "call_value_split"
6273   [(set (match_operand 0 "register_operand" "")
6274         (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
6275               (match_operand 2 "" "")))
6276    (clobber (reg:SI RETURN_ADDR_REGNUM))
6277    (clobber (reg:SI 28))]
6278   "TARGET_SPLIT_CALLS"
6279   { return MIPS_CALL ("jal", operands, 1, 2); }
6280   [(set_attr "type" "call")])
6281
6282 ;; See call_internal_direct.
6283 (define_insn_and_split "call_value_internal_direct"
6284   [(set (match_operand 0 "register_operand")
6285         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6286               (match_operand 2)))
6287    (const_int 1)
6288    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6289   ""
6290   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6291   "reload_completed && TARGET_SPLIT_CALLS"
6292   [(const_int 0)]
6293 {
6294   mips_split_call (curr_insn,
6295                    gen_call_value_direct_split (operands[0], operands[1],
6296                                                 operands[2]));
6297   DONE;
6298 }
6299   [(set_attr "type" "call")])
6300
6301 (define_insn "call_value_direct_split"
6302   [(set (match_operand 0 "register_operand")
6303         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6304               (match_operand 2)))
6305    (const_int 1)
6306    (clobber (reg:SI RETURN_ADDR_REGNUM))
6307    (clobber (reg:SI 28))]
6308   "TARGET_SPLIT_CALLS"
6309   { return MIPS_CALL ("jal", operands, 1, -1); }
6310   [(set_attr "type" "call")])
6311
6312 ;; See comment for call_internal.
6313 (define_insn_and_split "call_value_multiple_internal"
6314   [(set (match_operand 0 "register_operand" "")
6315         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6316               (match_operand 2 "" "")))
6317    (set (match_operand 3 "register_operand" "")
6318         (call (mem:SI (match_dup 1))
6319               (match_dup 2)))
6320    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6321   ""
6322   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6323   "reload_completed && TARGET_SPLIT_CALLS"
6324   [(const_int 0)]
6325 {
6326   mips_split_call (curr_insn,
6327                    gen_call_value_multiple_split (operands[0], operands[1],
6328                                                   operands[2], operands[3]));
6329   DONE;
6330 }
6331   [(set_attr "jal" "indirect,direct")])
6332
6333 (define_insn "call_value_multiple_split"
6334   [(set (match_operand 0 "register_operand" "")
6335         (call (mem:SI (match_operand 1 "call_insn_operand" "cS"))
6336               (match_operand 2 "" "")))
6337    (set (match_operand 3 "register_operand" "")
6338         (call (mem:SI (match_dup 1))
6339               (match_dup 2)))
6340    (clobber (reg:SI RETURN_ADDR_REGNUM))
6341    (clobber (reg:SI 28))]
6342   "TARGET_SPLIT_CALLS"
6343   { return MIPS_CALL ("jal", operands, 1, 2); }
6344   [(set_attr "type" "call")])
6345
6346 ;; Call subroutine returning any type.
6347
6348 (define_expand "untyped_call"
6349   [(parallel [(call (match_operand 0 "")
6350                     (const_int 0))
6351               (match_operand 1 "")
6352               (match_operand 2 "")])]
6353   ""
6354 {
6355   int i;
6356
6357   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6358
6359   for (i = 0; i < XVECLEN (operands[2], 0); i++)
6360     {
6361       rtx set = XVECEXP (operands[2], 0, i);
6362       mips_emit_move (SET_DEST (set), SET_SRC (set));
6363     }
6364
6365   emit_insn (gen_blockage ());
6366   DONE;
6367 })
6368 \f
6369 ;;
6370 ;;  ....................
6371 ;;
6372 ;;      MISC.
6373 ;;
6374 ;;  ....................
6375 ;;
6376
6377
6378 (define_insn "prefetch"
6379   [(prefetch (match_operand:QI 0 "address_operand" "p")
6380              (match_operand 1 "const_int_operand" "n")
6381              (match_operand 2 "const_int_operand" "n"))]
6382   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
6383 {
6384   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
6385     /* Loongson 2[ef] and Loongson 3a use load to $0 to perform prefetching.  */
6386     return "ld\t$0,%a0";
6387   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
6388   return "pref\t%1,%a0";
6389 }
6390   [(set_attr "type" "prefetch")])
6391
6392 (define_insn "*prefetch_indexed_<mode>"
6393   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
6394                      (match_operand:P 1 "register_operand" "d"))
6395              (match_operand 2 "const_int_operand" "n")
6396              (match_operand 3 "const_int_operand" "n"))]
6397   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
6398 {
6399   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
6400   return "prefx\t%2,%1(%0)";
6401 }
6402   [(set_attr "type" "prefetchx")])
6403
6404 (define_insn "nop"
6405   [(const_int 0)]
6406   ""
6407   "%(nop%)"
6408   [(set_attr "type"     "nop")
6409    (set_attr "mode"     "none")])
6410
6411 ;; Like nop, but commented out when outside a .set noreorder block.
6412 (define_insn "hazard_nop"
6413   [(const_int 1)]
6414   ""
6415   {
6416     if (mips_noreorder.nesting_level > 0)
6417       return "nop";
6418     else
6419       return "#nop";
6420   }
6421   [(set_attr "type"     "nop")])
6422 \f
6423 ;; MIPS4 Conditional move instructions.
6424
6425 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
6426   [(set (match_operand:GPR 0 "register_operand" "=d,d")
6427         (if_then_else:GPR
6428          (match_operator:MOVECC 4 "equality_operator"
6429                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6430                  (const_int 0)])
6431          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
6432          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
6433   "ISA_HAS_CONDMOVE"
6434   "@
6435     mov%T4\t%0,%z2,%1
6436     mov%t4\t%0,%z3,%1"
6437   [(set_attr "type" "condmove")
6438    (set_attr "mode" "<GPR:MODE>")])
6439
6440 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
6441   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
6442         (if_then_else:SCALARF
6443          (match_operator:MOVECC 4 "equality_operator"
6444                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6445                  (const_int 0)])
6446          (match_operand:SCALARF 2 "register_operand" "f,0")
6447          (match_operand:SCALARF 3 "register_operand" "0,f")))]
6448   "ISA_HAS_FP_CONDMOVE"
6449   "@
6450     mov%T4.<fmt>\t%0,%2,%1
6451     mov%t4.<fmt>\t%0,%3,%1"
6452   [(set_attr "type" "condmove")
6453    (set_attr "mode" "<SCALARF:MODE>")])
6454
6455 ;; These are the main define_expand's used to make conditional moves.
6456
6457 (define_expand "mov<mode>cc"
6458   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6459    (set (match_operand:GPR 0 "register_operand")
6460         (if_then_else:GPR (match_dup 5)
6461                           (match_operand:GPR 2 "reg_or_0_operand")
6462                           (match_operand:GPR 3 "reg_or_0_operand")))]
6463   "ISA_HAS_CONDMOVE"
6464 {
6465   mips_expand_conditional_move (operands);
6466   DONE;
6467 })
6468
6469 (define_expand "mov<mode>cc"
6470   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6471    (set (match_operand:SCALARF 0 "register_operand")
6472         (if_then_else:SCALARF (match_dup 5)
6473                               (match_operand:SCALARF 2 "register_operand")
6474                               (match_operand:SCALARF 3 "register_operand")))]
6475   "ISA_HAS_FP_CONDMOVE"
6476 {
6477   mips_expand_conditional_move (operands);
6478   DONE;
6479 })
6480 \f
6481 ;;
6482 ;;  ....................
6483 ;;
6484 ;;      mips16 inline constant tables
6485 ;;
6486 ;;  ....................
6487 ;;
6488
6489 (define_insn "consttable_int"
6490   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
6491                      (match_operand 1 "const_int_operand" "")]
6492                     UNSPEC_CONSTTABLE_INT)]
6493   "TARGET_MIPS16"
6494 {
6495   assemble_integer (operands[0], INTVAL (operands[1]),
6496                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
6497   return "";
6498 }
6499   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6500
6501 (define_insn "consttable_float"
6502   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
6503                     UNSPEC_CONSTTABLE_FLOAT)]
6504   "TARGET_MIPS16"
6505 {
6506   REAL_VALUE_TYPE d;
6507
6508   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
6509   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
6510   assemble_real (d, GET_MODE (operands[0]),
6511                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
6512   return "";
6513 }
6514   [(set (attr "length")
6515         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
6516
6517 (define_insn "align"
6518   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
6519   ""
6520   ".align\t%0"
6521   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
6522 \f
6523 (define_split
6524   [(match_operand 0 "small_data_pattern")]
6525   "reload_completed"
6526   [(match_dup 0)]
6527   { operands[0] = mips_rewrite_small_data (operands[0]); })
6528
6529 ;;
6530 ;;  ....................
6531 ;;
6532 ;;      MIPS16e Save/Restore
6533 ;;
6534 ;;  ....................
6535 ;;
6536
6537 (define_insn "*mips16e_save_restore"
6538   [(match_parallel 0 ""
6539        [(set (match_operand:SI 1 "register_operand")
6540              (plus:SI (match_dup 1)
6541                       (match_operand:SI 2 "const_int_operand")))])]
6542   "operands[1] == stack_pointer_rtx
6543    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
6544   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
6545   [(set_attr "type" "arith")
6546    (set_attr "extended_mips16" "yes")])
6547
6548 ;; Thread-Local Storage
6549
6550 ;; The TLS base pointer is accessed via "rdhwr $3, $29".  No current
6551 ;; MIPS architecture defines this register, and no current
6552 ;; implementation provides it; instead, any OS which supports TLS is
6553 ;; expected to trap and emulate this instruction.  rdhwr is part of the
6554 ;; MIPS 32r2 specification, but we use it on any architecture because
6555 ;; we expect it to be emulated.  Use .set to force the assembler to
6556 ;; accept it.
6557 ;;
6558 ;; We do not use a constraint to force the destination to be $3
6559 ;; because $3 can appear explicitly as a function return value.
6560 ;; If we leave the use of $3 implicit in the constraints until
6561 ;; reload, we may end up making a $3 return value live across
6562 ;; the instruction, leading to a spill failure when reloading it.
6563 (define_insn_and_split "tls_get_tp_<mode>"
6564   [(set (match_operand:P 0 "register_operand" "=d")
6565         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6566    (clobber (reg:P TLS_GET_TP_REGNUM))]
6567   "HAVE_AS_TLS && !TARGET_MIPS16"
6568   "#"
6569   "&& reload_completed"
6570   [(set (reg:P TLS_GET_TP_REGNUM)
6571         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6572    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6573   ""
6574   [(set_attr "type" "unknown")
6575    ; Since rdhwr always generates a trap for now, putting it in a delay
6576    ; slot would make the kernel's emulation of it much slower.
6577    (set_attr "can_delay" "no")
6578    (set_attr "mode" "<MODE>")
6579    (set_attr "length" "8")])
6580
6581 (define_insn "*tls_get_tp_<mode>_split"
6582   [(set (reg:P TLS_GET_TP_REGNUM)
6583         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
6584   "HAVE_AS_TLS && !TARGET_MIPS16"
6585   ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop"
6586   [(set_attr "type" "unknown")
6587    ; See tls_get_tp_<mode>
6588    (set_attr "can_delay" "no")
6589    (set_attr "mode" "<MODE>")])
6590 \f
6591 ;; Synchronization instructions.
6592
6593 (include "sync.md")
6594
6595 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
6596
6597 (include "mips-ps-3d.md")
6598
6599 ; The MIPS DSP Instructions.
6600
6601 (include "mips-dsp.md")
6602
6603 ; The MIPS DSP REV 2 Instructions.
6604
6605 (include "mips-dspr2.md")
6606
6607 ; MIPS fixed-point instructions.
6608 (include "mips-fixed.md")
6609
6610 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
6611 (include "loongson.md")
6612
6613 (define_c_enum "unspec" [
6614   UNSPEC_ADDRESS_FIRST
6615 ])