2015-05-22 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / config / mips / mips.md
blob0a23fa214b0ef489ef138bd8dda989f7b2511c1a
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989-2015 Free Software Foundation, Inc.
3 ;;  Contributed by   A. Lichnewsky, lich@inria.inria.fr
4 ;;  Changes by       Michael Meissner, meissner@osf.org
5 ;;  64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
6 ;;  Brendan Eich, brendan@microunity.com.
8 ;; This file is part of GCC.
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3.  If not see
22 ;; <http://www.gnu.org/licenses/>.
24 (define_enum "processor" [
25   r3000
26   4kc
27   4kp
28   5kc
29   5kf
30   20kc
31   24kc
32   24kf2_1
33   24kf1_1
34   74kc
35   74kf2_1
36   74kf1_1
37   74kf3_2
38   loongson_2e
39   loongson_2f
40   loongson_3a
41   m4k
42   octeon
43   octeon2
44   octeon3
45   r3900
46   r6000
47   r4000
48   r4100
49   r4111
50   r4120
51   r4130
52   r4300
53   r4600
54   r4650
55   r4700
56   r5000
57   r5400
58   r5500
59   r5900
60   r7000
61   r8000
62   r9000
63   r10000
64   sb1
65   sb1a
66   sr71000
67   xlr
68   xlp
69   p5600
70   w32
71   w64
74 (define_c_enum "unspec" [
75   ;; Unaligned accesses.
76   UNSPEC_LOAD_LEFT
77   UNSPEC_LOAD_RIGHT
78   UNSPEC_STORE_LEFT
79   UNSPEC_STORE_RIGHT
81   ;; Integer operations that are too cumbersome to describe directly.
82   UNSPEC_WSBH
83   UNSPEC_DSBH
84   UNSPEC_DSHD
86   ;; Floating-point moves.
87   UNSPEC_LOAD_LOW
88   UNSPEC_LOAD_HIGH
89   UNSPEC_STORE_WORD
90   UNSPEC_MFHC1
91   UNSPEC_MTHC1
93   ;; Floating-point environment.
94   UNSPEC_GET_FCSR
95   UNSPEC_SET_FCSR
97   ;; HI/LO moves.
98   UNSPEC_MFHI
99   UNSPEC_MTHI
100   UNSPEC_SET_HILO
102   ;; GP manipulation.
103   UNSPEC_LOADGP
104   UNSPEC_COPYGP
105   UNSPEC_MOVE_GP
106   UNSPEC_POTENTIAL_CPRESTORE
107   UNSPEC_CPRESTORE
108   UNSPEC_RESTORE_GP
109   UNSPEC_EH_RETURN
110   UNSPEC_GP
111   UNSPEC_SET_GOT_VERSION
112   UNSPEC_UPDATE_GOT_VERSION
114   ;; Symbolic accesses.
115   UNSPEC_LOAD_CALL
116   UNSPEC_LOAD_GOT
117   UNSPEC_TLS_LDM
118   UNSPEC_TLS_GET_TP
119   UNSPEC_UNSHIFTED_HIGH
121   ;; MIPS16 constant pools.
122   UNSPEC_ALIGN
123   UNSPEC_CONSTTABLE_INT
124   UNSPEC_CONSTTABLE_FLOAT
126   ;; Blockage and synchronisation.
127   UNSPEC_BLOCKAGE
128   UNSPEC_CLEAR_HAZARD
129   UNSPEC_RDHWR
130   UNSPEC_SYNCI
131   UNSPEC_SYNC
133   ;; Cache manipulation.
134   UNSPEC_MIPS_CACHE
135   UNSPEC_R10K_CACHE_BARRIER
137   ;; Interrupt handling.
138   UNSPEC_ERET
139   UNSPEC_DERET
140   UNSPEC_DI
141   UNSPEC_EHB
142   UNSPEC_RDPGPR
143   UNSPEC_COP0
145   ;; Used in a call expression in place of args_size.  It's present for PIC
146   ;; indirect calls where it contains args_size and the function symbol.
147   UNSPEC_CALL_ATTR
149   ;; MIPS16 casesi jump table dispatch.
150   UNSPEC_CASESI_DISPATCH
152   ;; Stack checking.
153   UNSPEC_PROBE_STACK_RANGE
156 (define_constants
157   [(TLS_GET_TP_REGNUM           3)
158    (GET_FCSR_REGNUM             2)
159    (SET_FCSR_REGNUM             4)
160    (MIPS16_T_REGNUM             24)
161    (PIC_FUNCTION_ADDR_REGNUM    25)
162    (RETURN_ADDR_REGNUM          31)
163    (CPRESTORE_SLOT_REGNUM       76)
164    (GOT_VERSION_REGNUM          79)
166    ;; PIC long branch sequences are never longer than 100 bytes.
167    (MAX_PIC_BRANCH_LENGTH       100)
168   ]
171 (include "predicates.md")
172 (include "constraints.md")
174 ;; ....................
176 ;;      Attributes
178 ;; ....................
180 (define_attr "got" "unset,xgot_high,load"
181   (const_string "unset"))
183 ;; For jal instructions, this attribute is DIRECT when the target address
184 ;; is symbolic and INDIRECT when it is a register.
185 (define_attr "jal" "unset,direct,indirect"
186   (const_string "unset"))
188 ;; This attribute is YES if the instruction is a jal macro (not a
189 ;; real jal instruction).
191 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
192 ;; an instruction to restore $gp.  Direct jals are also macros for
193 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
194 ;; into a register.
195 (define_attr "jal_macro" "no,yes"
196   (cond [(eq_attr "jal" "direct")
197          (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
198                        ? JAL_MACRO_YES : JAL_MACRO_NO)")
199          (eq_attr "jal" "indirect")
200          (symbol_ref "(TARGET_CALL_CLOBBERED_GP
201                        ? JAL_MACRO_YES : JAL_MACRO_NO)")]
202         (const_string "no")))
204 ;; Classification of moves, extensions and truncations.  Most values
205 ;; are as for "type" (see below) but there are also the following
206 ;; move-specific values:
208 ;; constN       move an N-constraint integer into a MIPS16 register
209 ;; sll0         "sll DEST,SRC,0", which on 64-bit targets is guaranteed
210 ;;              to produce a sign-extended DEST, even if SRC is not
211 ;;              properly sign-extended
212 ;; ext_ins      EXT, DEXT, INS or DINS instruction
213 ;; andi         a single ANDI instruction
214 ;; loadpool     move a constant into a MIPS16 register by loading it
215 ;;              from the pool
216 ;; shift_shift  a shift left followed by a shift right
218 ;; This attribute is used to determine the instruction's length and
219 ;; scheduling type.  For doubleword moves, the attribute always describes
220 ;; the split instructions; in some cases, it is more appropriate for the
221 ;; scheduling type to be "multi" instead.
222 (define_attr "move_type"
223   "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
224    const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
225    shift_shift"
226   (const_string "unknown"))
228 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
229   (const_string "unknown"))
231 ;; Main data type used by the insn
232 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
233   (const_string "unknown"))
235 ;; True if the main data type is twice the size of a word.
236 (define_attr "dword_mode" "no,yes"
237   (cond [(and (eq_attr "mode" "DI,DF")
238               (not (match_test "TARGET_64BIT")))
239          (const_string "yes")
241          (and (eq_attr "mode" "TI,TF")
242               (match_test "TARGET_64BIT"))
243          (const_string "yes")]
244         (const_string "no")))
246 ;; Attributes describing a sync loop.  These loops have the form:
248 ;;       if (RELEASE_BARRIER == YES) sync
249 ;;    1: OLDVAL = *MEM
250 ;;       if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
251 ;;         CMP  = 0 [delay slot]
252 ;;       $TMP1 = OLDVAL & EXCLUSIVE_MASK
253 ;;       $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
254 ;;       $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
255 ;;       $AT |= $TMP1 | $TMP3
256 ;;       if (!commit (*MEM = $AT)) goto 1.
257 ;;         if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
258 ;;       CMP  = 1
259 ;;       if (ACQUIRE_BARRIER == YES) sync
260 ;;    2:
262 ;; where "$" values are temporaries and where the other values are
263 ;; specified by the attributes below.  Values are specified as operand
264 ;; numbers and insns are specified as enums.  If no operand number is
265 ;; specified, the following values are used instead:
267 ;;    - OLDVAL: $AT
268 ;;    - CMP: NONE
269 ;;    - NEWVAL: $AT
270 ;;    - INCLUSIVE_MASK: -1
271 ;;    - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
272 ;;    - EXCLUSIVE_MASK: 0
274 ;; MEM and INSN1_OP2 are required.
276 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
277 ;; but the gen* programs don't yet support that.
278 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
279 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
280 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
281 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
282 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
283 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
284 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
285 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
286 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
287   (const_string "move"))
288 (define_attr "sync_insn2" "nop,and,xor,not"
289   (const_string "nop"))
290 ;; Memory model specifier.
291 ;; "0"-"9" values specify the operand that stores the memory model value.
292 ;; "10" specifies MEMMODEL_ACQ_REL,
293 ;; "11" specifies MEMMODEL_ACQUIRE.
294 (define_attr "sync_memmodel" "" (const_int 10))
296 ;; Accumulator operand for madd patterns.
297 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
299 ;; Classification of each insn.
300 ;; branch       conditional branch
301 ;; jump         unconditional jump
302 ;; call         unconditional call
303 ;; load         load instruction(s)
304 ;; fpload       floating point load
305 ;; fpidxload    floating point indexed load
306 ;; store        store instruction(s)
307 ;; fpstore      floating point store
308 ;; fpidxstore   floating point indexed store
309 ;; prefetch     memory prefetch (register + offset)
310 ;; prefetchx    memory indexed prefetch (register + register)
311 ;; condmove     conditional moves
312 ;; mtc          transfer to coprocessor
313 ;; mfc          transfer from coprocessor
314 ;; mthi         transfer to a hi register
315 ;; mtlo         transfer to a lo register
316 ;; mfhi         transfer from a hi register
317 ;; mflo         transfer from a lo register
318 ;; const        load constant
319 ;; arith        integer arithmetic instructions
320 ;; logical      integer logical instructions
321 ;; shift        integer shift instructions
322 ;; slt          set less than instructions
323 ;; signext      sign extend instructions
324 ;; clz          the clz and clo instructions
325 ;; pop          the pop instruction
326 ;; trap         trap if instructions
327 ;; imul         integer multiply 2 operands
328 ;; imul3        integer multiply 3 operands
329 ;; imul3nc      integer multiply 3 operands without clobbering HI/LO
330 ;; imadd        integer multiply-add
331 ;; idiv         integer divide 2 operands
332 ;; idiv3        integer divide 3 operands
333 ;; move         integer register move ({,D}ADD{,U} with rt = 0)
334 ;; fmove        floating point register move
335 ;; fadd         floating point add/subtract
336 ;; fmul         floating point multiply
337 ;; fmadd        floating point multiply-add
338 ;; fdiv         floating point divide
339 ;; frdiv        floating point reciprocal divide
340 ;; frdiv1       floating point reciprocal divide step 1
341 ;; frdiv2       floating point reciprocal divide step 2
342 ;; fabs         floating point absolute value
343 ;; fneg         floating point negation
344 ;; fcmp         floating point compare
345 ;; fcvt         floating point convert
346 ;; fsqrt        floating point square root
347 ;; frsqrt       floating point reciprocal square root
348 ;; frsqrt1      floating point reciprocal square root step1
349 ;; frsqrt2      floating point reciprocal square root step2
350 ;; dspmac       DSP MAC instructions not saturating the accumulator
351 ;; dspmacsat    DSP MAC instructions that saturate the accumulator
352 ;; accext       DSP accumulator extract instructions
353 ;; accmod       DSP accumulator modify instructions
354 ;; dspalu       DSP ALU instructions not saturating the result
355 ;; dspalusat    DSP ALU instructions that saturate the result
356 ;; multi        multiword sequence (or user asm statements)
357 ;; atomic       atomic memory update instruction
358 ;; syncloop     memory atomic operation implemented as a sync loop
359 ;; nop          no operation
360 ;; ghost        an instruction that produces no real code
361 ;; multimem     microMIPS multiword load and store
362 (define_attr "type"
363   "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
364    prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
365    shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
366    fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
367    frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
368    multi,atomic,syncloop,nop,ghost,multimem"
369   (cond [(eq_attr "jal" "!unset") (const_string "call")
370          (eq_attr "got" "load") (const_string "load")
372          (eq_attr "alu_type" "add,sub") (const_string "arith")
374          (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
376          ;; If a doubleword move uses these expensive instructions,
377          ;; it is usually better to schedule them in the same way
378          ;; as the singleword form, rather than as "multi".
379          (eq_attr "move_type" "load") (const_string "load")
380          (eq_attr "move_type" "fpload") (const_string "fpload")
381          (eq_attr "move_type" "store") (const_string "store")
382          (eq_attr "move_type" "fpstore") (const_string "fpstore")
383          (eq_attr "move_type" "mtc") (const_string "mtc")
384          (eq_attr "move_type" "mfc") (const_string "mfc")
385          (eq_attr "move_type" "mtlo") (const_string "mtlo")
386          (eq_attr "move_type" "mflo") (const_string "mflo")
388          ;; These types of move are always single insns.
389          (eq_attr "move_type" "imul") (const_string "imul")
390          (eq_attr "move_type" "fmove") (const_string "fmove")
391          (eq_attr "move_type" "loadpool") (const_string "load")
392          (eq_attr "move_type" "signext") (const_string "signext")
393          (eq_attr "move_type" "ext_ins") (const_string "arith")
394          (eq_attr "move_type" "arith") (const_string "arith")
395          (eq_attr "move_type" "logical") (const_string "logical")
396          (eq_attr "move_type" "sll0") (const_string "shift")
397          (eq_attr "move_type" "andi") (const_string "logical")
399          ;; These types of move are always split.
400          (eq_attr "move_type" "constN,shift_shift")
401            (const_string "multi")
403          ;; These types of move are split for doubleword modes only.
404          (and (eq_attr "move_type" "move,const")
405               (eq_attr "dword_mode" "yes"))
406            (const_string "multi")
407          (eq_attr "move_type" "move") (const_string "move")
408          (eq_attr "move_type" "const") (const_string "const")
409          (eq_attr "sync_mem" "!none") (const_string "syncloop")]
410         (const_string "unknown")))
412 ;; Mode for conversion types (fcvt)
413 ;; I2S          integer to float single (SI/DI to SF)
414 ;; I2D          integer to float double (SI/DI to DF)
415 ;; S2I          float to integer (SF to SI/DI)
416 ;; D2I          float to integer (DF to SI/DI)
417 ;; D2S          double to float single
418 ;; S2D          float single to double
420 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D" 
421   (const_string "unknown"))
423 ;; Is this an extended instruction in mips16 mode?
424 (define_attr "extended_mips16" "no,yes"
425   (if_then_else (ior ;; In general, constant-pool loads are extended
426                      ;; instructions.  We don't yet optimize for 16-bit
427                      ;; PC-relative references.
428                      (eq_attr "move_type" "sll0,loadpool")
429                      (eq_attr "jal" "direct")
430                      (eq_attr "got" "load"))
431                 (const_string "yes")
432                 (const_string "no")))
434 (define_attr "compression" "none,all,micromips32,micromips"
435   (const_string "none"))
437 (define_attr "enabled" "no,yes"
438   (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
439          ;; GR_REG and FR_REG for 64-bit values.
440          (and (eq_attr "move_type" "mtc,mfc")
441               (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
442                            || TARGET_O32_FP64A_ABI")
443               (eq_attr "dword_mode" "yes"))
444          (const_string "no")
445          (and (eq_attr "compression" "micromips32,micromips")
446               (match_test "!TARGET_MICROMIPS"))
447          (const_string "no")]
448         (const_string "yes")))
450 ;; The number of individual instructions that a non-branch pattern generates,
451 ;; using units of BASE_INSN_LENGTH.
452 (define_attr "insn_count" ""
453   (cond [;; "Ghost" instructions occupy no space.
454          (eq_attr "type" "ghost")
455          (const_int 0)
457          ;; Extended instructions count as 2.
458          (and (eq_attr "extended_mips16" "yes")
459               (match_test "TARGET_MIPS16"))
460          (const_int 2)
462          ;; A GOT load followed by an add of $gp.  This is not used for MIPS16.
463          (eq_attr "got" "xgot_high")
464          (const_int 2)
466          ;; SHIFT_SHIFTs are decomposed into two separate instructions.
467          ;; They are extended instructions on MIPS16 targets.
468          (eq_attr "move_type" "shift_shift")
469          (if_then_else (match_test "TARGET_MIPS16")
470                        (const_int 4)
471                        (const_int 2))
473          ;; Check for doubleword moves that are decomposed into two
474          ;; instructions.  The individual instructions are unextended
475          ;; MIPS16 ones.
476          (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
477               (eq_attr "dword_mode" "yes"))
478          (const_int 2)
480          ;; Constants, loads and stores are handled by external routines.
481          (and (eq_attr "move_type" "const,constN")
482               (eq_attr "dword_mode" "yes"))
483          (symbol_ref "mips_split_const_insns (operands[1])")
484          (eq_attr "move_type" "const,constN")
485          (symbol_ref "mips_const_insns (operands[1])")
486          (eq_attr "move_type" "load,fpload")
487          (symbol_ref "mips_load_store_insns (operands[1], insn)")
488          (eq_attr "move_type" "store,fpstore")
489          (symbol_ref "mips_load_store_insns (operands[0], insn)
490                       + (TARGET_FIX_24K ? 1 : 0)")
492          ;; In the worst case, a call macro will take 8 instructions:
493          ;;
494          ;;     lui $25,%call_hi(FOO)
495          ;;     addu $25,$25,$28
496          ;;     lw $25,%call_lo(FOO)($25)
497          ;;     nop
498          ;;     jalr $25
499          ;;     nop
500          ;;     lw $gp,X($sp)
501          ;;     nop
502          (eq_attr "jal_macro" "yes")
503          (const_int 8)
505          ;; Various VR4120 errata require a nop to be inserted after a macc
506          ;; instruction.  The assembler does this for us, so account for
507          ;; the worst-case length here.
508          (and (eq_attr "type" "imadd")
509               (match_test "TARGET_FIX_VR4120"))
510          (const_int 2)
512          ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
513          ;; the result of the second one is missed.  The assembler should work
514          ;; around this by inserting a nop after the first dmult.
515          (and (eq_attr "type" "imul,imul3")
516               (eq_attr "mode" "DI")
517               (match_test "TARGET_FIX_VR4120"))
518          (const_int 2)
520          (eq_attr "type" "idiv,idiv3")
521          (symbol_ref "mips_idiv_insns ()")
523          (not (eq_attr "sync_mem" "none"))
524          (symbol_ref "mips_sync_loop_insns (insn, operands)")]
525         (const_int 1)))
527 ;; Length of instruction in bytes.  The default is derived from "insn_count",
528 ;; but there are special cases for branches (which must be handled here)
529 ;; and for compressed single instructions.
530 (define_attr "length" ""
531    (cond [(and (ior (eq_attr "compression" "micromips,all")
532                     (and (eq_attr "compression" "micromips32")
533                          (eq_attr "mode" "SI,SF")))
534                (eq_attr "dword_mode" "no")
535                (match_test "TARGET_MICROMIPS"))
536           (const_int 2)
538           ;; Direct microMIPS branch instructions have a range of
539           ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
540           ;; If a branch is outside this range, we have a choice of two
541           ;; sequences.
542           ;;
543           ;; For PIC, an out-of-range branch like:
544           ;;
545           ;;    bne     r1,r2,target
546           ;;    dslot
547           ;;
548           ;; becomes the equivalent of:
549           ;;
550           ;;    beq     r1,r2,1f
551           ;;    dslot
552           ;;    la      $at,target
553           ;;    jr      $at
554           ;;    nop
555           ;; 1:
556           ;;
557           ;; The non-PIC case is similar except that we use a direct
558           ;; jump instead of an la/jr pair.  Since the target of this
559           ;; jump is an absolute 28-bit bit address (the other bits
560           ;; coming from the address of the delay slot) this form cannot
561           ;; cross a 256MB boundary.  We could provide the option of
562           ;; using la/jr in this case too, but we do not do so at
563           ;; present.
564           ;;
565           ;; The value we specify here does not account for the delay slot
566           ;; instruction, whose length is added separately.  If the RTL
567           ;; pattern has no explicit delay slot, mips_adjust_insn_length
568           ;; will add the length of the implicit nop.  The range of
569           ;; [-0x20000, 0x1fffc] from the address of the delay slot
570           ;; therefore translates to a range of:
571           ;;
572           ;;    [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
573           ;; == [-0x1fffc, 0x1fff8]
574           ;;
575           ;; from the shorten_branches reference address.
576           (and (eq_attr "type" "branch")
577                (not (match_test "TARGET_MIPS16")))
578           (cond [;; Any variant can handle the 17-bit range.
579                  (and (le (minus (match_dup 0) (pc)) (const_int 65532))
580                       (le (minus (pc) (match_dup 0)) (const_int 65534)))
581                    (const_int 4)
583                  ;; The 18-bit range is OK other than for microMIPS.
584                  (and (not (match_test "TARGET_MICROMIPS"))
585                       (and (le (minus (match_dup 0) (pc)) (const_int 131064))
586                            (le (minus (pc) (match_dup 0)) (const_int 131068))))
587                    (const_int 4)
589                  ;; The non-PIC case: branch, first delay slot, and J.
590                  (match_test "TARGET_ABSOLUTE_JUMPS")
591                    (const_int 12)]
593                  ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
594                  ;; mips_adjust_insn_length substitutes the correct length.
595                  ;;
596                  ;; Note that we can't simply use (symbol_ref ...) here
597                  ;; because genattrtab needs to know the maximum length
598                  ;; of an insn.
599                  (const_int MAX_PIC_BRANCH_LENGTH))
601           ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
602           ;; from the address of the following instruction, which leads
603           ;; to a range of:
604           ;;
605           ;;    [-(0x100 - sizeof (branch)), 0xfe]
606           ;; == [-0xfe, 0xfe]
607           ;;
608           ;; from the shorten_branches reference address.  Extended branches
609           ;; likewise have a range of [-0x10000, 0xfffe] from the address
610           ;; of the following instruction, which leads to a range of:
611           ;;
612           ;;    [-(0x10000 - sizeof (branch)), 0xfffe]
613           ;; == [-0xfffc, 0xfffe]
614           ;;
615           ;; from the reference address.
616           ;;
617           ;; When a branch is out of range, mips_reorg splits it into a form
618           ;; that uses in-range branches.  There are four basic sequences:
619           ;;
620           ;; (1) Absolute addressing with a readable text segment
621           ;;     (32-bit addresses):
622           ;;
623           ;;     b... foo               2 bytes
624           ;;     move $1,$2             2 bytes
625           ;;     lw $2,label            2 bytes
626           ;;     jr $2                  2 bytes
627           ;;     move $2,$1             2 bytes
628           ;;     .align 2               0 or 2 bytes
629           ;; label:
630           ;;     .word target           4 bytes
631           ;; foo:
632           ;;                            (16 bytes in the worst case)
633           ;;
634           ;; (2) Absolute addressing with a readable text segment
635           ;;     (64-bit addresses):
636           ;;
637           ;;     b... foo               2 bytes
638           ;;     move $1,$2             2 bytes
639           ;;     ld $2,label            2 bytes
640           ;;     jr $2                  2 bytes
641           ;;     move $2,$1             2 bytes
642           ;;     .align 3               0 to 6 bytes
643           ;; label:
644           ;;     .dword target          8 bytes
645           ;; foo:
646           ;;                            (24 bytes in the worst case)
647           ;;
648           ;; (3) Absolute addressing without a readable text segment
649           ;;     (which requires 32-bit addresses at present):
650           ;;
651           ;;     b... foo               2 bytes
652           ;;     move $1,$2             2 bytes
653           ;;     lui $2,%hi(target)     4 bytes
654           ;;     sll $2,8               2 bytes
655           ;;     sll $2,8               2 bytes
656           ;;     addiu $2,%lo(target)   4 bytes
657           ;;     jr $2                  2 bytes
658           ;;     move $2,$1             2 bytes
659           ;; foo:
660           ;;                            (20 bytes)
661           ;;
662           ;; (4) PIC addressing (which requires 32-bit addresses at present):
663           ;;
664           ;;     b... foo               2 bytes
665           ;;     move $1,$2             2 bytes
666           ;;     lw $2,cprestore        0, 2 or 4 bytes
667           ;;     lw $2,%got(target)($2) 4 bytes
668           ;;     addiu $2,%lo(target)   4 bytes
669           ;;     jr $2                  2 bytes
670           ;;     move $2,$1             2 bytes
671           ;; foo:
672           ;;                            (20 bytes in the worst case)
673           (and (eq_attr "type" "branch")
674                (match_test "TARGET_MIPS16"))
675           (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
676                       (le (minus (pc) (match_dup 0)) (const_int 254)))
677                  (const_int 2)
678                  (and (le (minus (match_dup 0) (pc)) (const_int 65534))
679                       (le (minus (pc) (match_dup 0)) (const_int 65532)))
680                  (const_int 4)
681                  (and (match_test "TARGET_ABICALLS")
682                       (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
683                  (const_int 20)
684                  (match_test "Pmode == SImode")
685                  (const_int 16)
686                  ] (const_int 24))]
687          (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
689 ;; Attribute describing the processor.
690 (define_enum_attr "cpu" "processor"
691   (const (symbol_ref "mips_tune")))
693 ;; The type of hardware hazard associated with this instruction.
694 ;; DELAY means that the next instruction cannot read the result
695 ;; of this one.  HILO means that the next two instructions cannot
696 ;; write to HI or LO.
697 (define_attr "hazard" "none,delay,hilo"
698   (cond [(and (eq_attr "type" "load,fpload,fpidxload")
699               (match_test "ISA_HAS_LOAD_DELAY"))
700          (const_string "delay")
702          (and (eq_attr "type" "mfc,mtc")
703               (match_test "ISA_HAS_XFER_DELAY"))
704          (const_string "delay")
706          (and (eq_attr "type" "fcmp")
707               (match_test "ISA_HAS_FCMP_DELAY"))
708          (const_string "delay")
710          ;; The r4000 multiplication patterns include an mflo instruction.
711          (and (eq_attr "type" "imul")
712               (match_test "TARGET_FIX_R4000"))
713          (const_string "hilo")
715          (and (eq_attr "type" "mfhi,mflo")
716               (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
717          (const_string "hilo")]
718         (const_string "none")))
720 ;; Can the instruction be put into a delay slot?
721 (define_attr "can_delay" "no,yes"
722   (if_then_else (and (eq_attr "type" "!branch,call,jump")
723                      (eq_attr "hazard" "none")
724                      (match_test "get_attr_insn_count (insn) == 1"))
725                 (const_string "yes")
726                 (const_string "no")))
728 ;; Attribute defining whether or not we can use the branch-likely
729 ;; instructions.
730 (define_attr "branch_likely" "no,yes"
731   (if_then_else (match_test "GENERATE_BRANCHLIKELY")
732                 (const_string "yes")
733                 (const_string "no")))
735 ;; True if an instruction might assign to hi or lo when reloaded.
736 ;; This is used by the TUNE_MACC_CHAINS code.
737 (define_attr "may_clobber_hilo" "no,yes"
738   (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
739                 (const_string "yes")
740                 (const_string "no")))
742 ;; Describe a user's asm statement.
743 (define_asm_attributes
744   [(set_attr "type" "multi")
745    (set_attr "can_delay" "no")])
747 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
748 ;; from the same template.
749 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
751 ;; A copy of GPR that can be used when a pattern has two independent
752 ;; modes.
753 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
755 (define_mode_iterator MOVEP1 [SI SF])
756 (define_mode_iterator MOVEP2 [SI SF])
757 (define_mode_iterator JOIN_MODE [HI
758                                  SI
759                                  (SF "TARGET_HARD_FLOAT")
760                                  (DF "TARGET_HARD_FLOAT
761                                       && TARGET_DOUBLE_FLOAT")])
763 ;; This mode iterator allows :HILO to be used as the mode of the
764 ;; concatenated HI and LO registers.
765 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
767 ;; This mode iterator allows :P to be used for patterns that operate on
768 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
769 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
771 ;; This mode iterator allows :MOVECC to be used anywhere that a
772 ;; conditional-move-type condition is needed.
773 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
774                               (CC "TARGET_HARD_FLOAT
775                                    && !TARGET_LOONGSON_2EF
776                                    && !TARGET_MIPS5900")])
778 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
779 ;; is needed.
780 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
781                             (CCF "ISA_HAS_CCF")])
783 ;; 32-bit integer moves for which we provide move patterns.
784 (define_mode_iterator IMOVE32
785   [SI
786    (V2HI "TARGET_DSP")
787    (V4QI "TARGET_DSP")
788    (V2HQ "TARGET_DSP")
789    (V2UHQ "TARGET_DSP")
790    (V2HA "TARGET_DSP")
791    (V2UHA "TARGET_DSP")
792    (V4QQ "TARGET_DSP")
793    (V4UQQ "TARGET_DSP")])
795 ;; 64-bit modes for which we provide move patterns.
796 (define_mode_iterator MOVE64
797   [DI DF
798    (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
799    (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
800    (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
801    (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
803 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
804 (define_mode_iterator MOVE128 [TI TF])
806 ;; This mode iterator allows the QI and HI extension patterns to be
807 ;; defined from the same template.
808 (define_mode_iterator SHORT [QI HI])
810 ;; Likewise the 64-bit truncate-and-shift patterns.
811 (define_mode_iterator SUBDI [QI HI SI])
813 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
814 ;; floating-point mode is allowed.
815 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
816                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
817                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
819 ;; Like ANYF, but only applies to scalar modes.
820 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
821                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
823 ;; A floating-point mode for which moves involving FPRs may need to be split.
824 (define_mode_iterator SPLITF
825   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
826    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
827    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
828    (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
829    (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
830    (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
831    (TF "TARGET_64BIT && TARGET_FLOAT64")])
833 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
834 ;; 32-bit version and "dsubu" in the 64-bit version.
835 (define_mode_attr d [(SI "") (DI "d")
836                      (QQ "") (HQ "") (SQ "") (DQ "d")
837                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
838                      (HA "") (SA "") (DA "d")
839                      (UHA "") (USA "") (UDA "d")])
841 ;; Same as d but upper-case.
842 (define_mode_attr D [(SI "") (DI "D")
843                      (QQ "") (HQ "") (SQ "") (DQ "D")
844                      (UQQ "") (UHQ "") (USQ "") (UDQ "D")
845                      (HA "") (SA "") (DA "D")
846                      (UHA "") (USA "") (UDA "D")])
848 ;; This attribute gives the length suffix for a load or store instruction.
849 ;; The same suffixes work for zero and sign extensions.
850 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
851 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
853 ;; This attributes gives the mode mask of a SHORT.
854 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
856 ;; Mode attributes for GPR loads.
857 (define_mode_attr load [(SI "lw") (DI "ld")])
858 ;; Instruction names for stores.
859 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
861 ;; Similarly for MIPS IV indexed FPR loads and stores.
862 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
863 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
865 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
866 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
867 ;; field but the equivalent daddiu has only a 5-bit field.
868 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
870 ;; This attribute gives the best constraint to use for registers of
871 ;; a given mode.
872 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
874 ;; This attribute gives the format suffix for floating-point operations.
875 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
877 ;; This attribute gives the upper-case mode name for one unit of a
878 ;; floating-point mode.
879 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
881 ;; This attribute gives the integer mode that has the same size as a
882 ;; fixed-point mode.
883 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
884                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
885                          (HA "HI") (SA "SI") (DA "DI")
886                          (UHA "HI") (USA "SI") (UDA "DI")
887                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
888                          (V2HQ "SI") (V2HA "SI")])
890 ;; This attribute gives the integer mode that has half the size of
891 ;; the controlling mode.
892 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
893                             (V2SI "SI") (V4HI "SI") (V8QI "SI")
894                             (TF "DI")])
896 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
898 ;; In certain cases, div.s and div.ps may have a rounding error
899 ;; and/or wrong inexact flag.
901 ;; Therefore, we only allow div.s if not working around SB-1 rev2
902 ;; errata or if a slight loss of precision is OK.
903 (define_mode_attr divide_condition
904   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
905    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
907 ;; This attribute gives the conditions under which SQRT.fmt instructions
908 ;; can be used.
909 (define_mode_attr sqrt_condition
910   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
912 ;; This attribute provides the correct mnemonic for each FP condition mode.
913 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
915 ;; This code iterator allows signed and unsigned widening multiplications
916 ;; to use the same template.
917 (define_code_iterator any_extend [sign_extend zero_extend])
919 ;; This code iterator allows the two right shift instructions to be
920 ;; generated from the same template.
921 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
923 ;; This code iterator allows the three shift instructions to be generated
924 ;; from the same template.
925 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
927 ;; This code iterator allows unsigned and signed division to be generated
928 ;; from the same template.
929 (define_code_iterator any_div [div udiv])
931 ;; This code iterator allows unsigned and signed modulus to be generated
932 ;; from the same template.
933 (define_code_iterator any_mod [mod umod])
935 ;; This code iterator allows all native floating-point comparisons to be
936 ;; generated from the same template.
937 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
938                              (ordered "ISA_HAS_CCF")
939                              (ltgt "ISA_HAS_CCF")
940                              (ne "ISA_HAS_CCF")])
942 ;; This code iterator is used for comparisons that can be implemented
943 ;; by swapping the operands.
944 (define_code_iterator swapped_fcond [ge gt unge ungt])
946 ;; Equality operators.
947 (define_code_iterator equality_op [eq ne])
949 ;; These code iterators allow the signed and unsigned scc operations to use
950 ;; the same template.
951 (define_code_iterator any_gt [gt gtu])
952 (define_code_iterator any_ge [ge geu])
953 (define_code_iterator any_lt [lt ltu])
954 (define_code_iterator any_le [le leu])
956 (define_code_iterator any_return [return simple_return])
958 ;; <u> expands to an empty string when doing a signed operation and
959 ;; "u" when doing an unsigned operation.
960 (define_code_attr u [(sign_extend "") (zero_extend "u")
961                      (div "") (udiv "u")
962                      (mod "") (umod "u")
963                      (gt "") (gtu "u")
964                      (ge "") (geu "u")
965                      (lt "") (ltu "u")
966                      (le "") (leu "u")])
968 ;; <U> is like <u> except uppercase.
969 (define_code_attr U [(sign_extend "") (zero_extend "U")])
971 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
972 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
974 ;; <optab> expands to the name of the optab for a particular code.
975 (define_code_attr optab [(ashift "ashl")
976                          (ashiftrt "ashr")
977                          (lshiftrt "lshr")
978                          (ior "ior")
979                          (xor "xor")
980                          (and "and")
981                          (plus "add")
982                          (minus "sub")
983                          (return "return")
984                          (simple_return "simple_return")])
986 ;; <insn> expands to the name of the insn that implements a particular code.
987 (define_code_attr insn [(ashift "sll")
988                         (ashiftrt "sra")
989                         (lshiftrt "srl")
990                         (ior "or")
991                         (xor "xor")
992                         (and "and")
993                         (plus "addu")
994                         (minus "subu")])
996 ;; <immediate_insn> expands to the name of the insn that implements
997 ;; a particular code to operate on immediate values.
998 (define_code_attr immediate_insn [(ior "ori")
999                                   (xor "xori")
1000                                   (and "andi")])
1002 (define_code_attr shift_compression [(ashift "micromips32")
1003                                      (lshiftrt "micromips32")
1004                                      (ashiftrt "none")])
1006 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1007 (define_code_attr fcond [(unordered "un")
1008                          (uneq "ueq")
1009                          (unlt "ult")
1010                          (unle "ule")
1011                          (eq "eq")
1012                          (lt "lt")
1013                          (le "le")
1014                          (ordered "or")
1015                          (ltgt "ne")
1016                          (ne "une")])
1018 ;; Similar, but for swapped conditions.
1019 (define_code_attr swapped_fcond [(ge "le")
1020                                  (gt "lt")
1021                                  (unge "ule")
1022                                  (ungt "ult")])
1024 ;; The value of the bit when the branch is taken for branch_bit patterns.
1025 ;; Comparison is always against zero so this depends on the operator.
1026 (define_code_attr bbv [(eq "0") (ne "1")])
1028 ;; This is the inverse value of bbv.
1029 (define_code_attr bbinv [(eq "1") (ne "0")])
1031 ;; The sel mnemonic to use depending on the condition test.
1032 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1033 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1035 ;; .........................
1037 ;;      Branch, call and jump delay slots
1039 ;; .........................
1041 (define_delay (and (eq_attr "type" "branch")
1042                    (not (match_test "TARGET_MIPS16"))
1043                    (eq_attr "branch_likely" "yes"))
1044   [(eq_attr "can_delay" "yes")
1045    (nil)
1046    (eq_attr "can_delay" "yes")])
1048 ;; Branches that don't have likely variants do not annul on false.
1049 (define_delay (and (eq_attr "type" "branch")
1050                    (not (match_test "TARGET_MIPS16"))
1051                    (eq_attr "branch_likely" "no"))
1052   [(eq_attr "can_delay" "yes")
1053    (nil)
1054    (nil)])
1056 (define_delay (eq_attr "type" "jump")
1057   [(eq_attr "can_delay" "yes")
1058    (nil)
1059    (nil)])
1061 (define_delay (and (eq_attr "type" "call")
1062                    (eq_attr "jal_macro" "no"))
1063   [(eq_attr "can_delay" "yes")
1064    (nil)
1065    (nil)])
1067 ;; Pipeline descriptions.
1069 ;; generic.md provides a fallback for processors without a specific
1070 ;; pipeline description.  It is derived from the old define_function_unit
1071 ;; version and uses the "alu" and "imuldiv" units declared below.
1073 ;; Some of the processor-specific files are also derived from old
1074 ;; define_function_unit descriptions and simply override the parts of
1075 ;; generic.md that don't apply.  The other processor-specific files
1076 ;; are self-contained.
1077 (define_automaton "alu,imuldiv")
1079 (define_cpu_unit "alu" "alu")
1080 (define_cpu_unit "imuldiv" "imuldiv")
1082 ;; Ghost instructions produce no real code and introduce no hazards.
1083 ;; They exist purely to express an effect on dataflow.
1084 (define_insn_reservation "ghost" 0
1085   (eq_attr "type" "ghost")
1086   "nothing")
1088 (include "p5600.md")
1089 (include "4k.md")
1090 (include "5k.md")
1091 (include "20kc.md")
1092 (include "24k.md")
1093 (include "74k.md")
1094 (include "3000.md")
1095 (include "4000.md")
1096 (include "4100.md")
1097 (include "4130.md")
1098 (include "4300.md")
1099 (include "4600.md")
1100 (include "5000.md")
1101 (include "5400.md")
1102 (include "5500.md")
1103 (include "6000.md")
1104 (include "7000.md")
1105 (include "9000.md")
1106 (include "10000.md")
1107 (include "loongson2ef.md")
1108 (include "loongson3a.md")
1109 (include "octeon.md")
1110 (include "sb1.md")
1111 (include "sr71k.md")
1112 (include "xlr.md")
1113 (include "xlp.md")
1114 (include "generic.md")
1117 ;;  ....................
1119 ;;      CONDITIONAL TRAPS
1121 ;;  ....................
1124 (define_insn "trap"
1125   [(trap_if (const_int 1) (const_int 0))]
1126   ""
1128   if (ISA_HAS_COND_TRAP)
1129     return "teq\t$0,$0";
1130   else if (TARGET_MIPS16)
1131     return "break 0";
1132   else
1133     return "break";
1135   [(set_attr "type" "trap")])
1137 (define_expand "ctrap<mode>4"
1138   [(trap_if (match_operator 0 "comparison_operator"
1139                             [(match_operand:GPR 1 "reg_or_0_operand")
1140                              (match_operand:GPR 2 "arith_operand")])
1141             (match_operand 3 "const_0_operand"))]
1142   "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1144   mips_expand_conditional_trap (operands[0]);
1145   DONE;
1148 (define_insn "*conditional_trap_reg<mode>"
1149   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1150                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1151                                  (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1152             (const_int 0))]
1153   "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1154   "t%C0\t%z1,%2"
1155   [(set_attr "type" "trap")])
1157 (define_insn "*conditional_trap<mode>"
1158   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1159                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1160                                  (match_operand:GPR 2 "arith_operand" "dI")])
1161             (const_int 0))]
1162   "ISA_HAS_COND_TRAPI"
1163   "t%C0\t%z1,%2"
1164   [(set_attr "type" "trap")])
1167 ;;  ....................
1169 ;;      ADDITION
1171 ;;  ....................
1174 (define_insn "add<mode>3"
1175   [(set (match_operand:ANYF 0 "register_operand" "=f")
1176         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1177                    (match_operand:ANYF 2 "register_operand" "f")))]
1178   ""
1179   "add.<fmt>\t%0,%1,%2"
1180   [(set_attr "type" "fadd")
1181    (set_attr "mode" "<UNITMODE>")])
1183 (define_expand "add<mode>3"
1184   [(set (match_operand:GPR 0 "register_operand")
1185         (plus:GPR (match_operand:GPR 1 "register_operand")
1186                   (match_operand:GPR 2 "arith_operand")))]
1187   "")
1189 (define_insn "*add<mode>3"
1190   [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1191         (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1192                   (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1193   "!TARGET_MIPS16"
1195   if (which_alternative == 0 
1196       || which_alternative == 1)
1197     return "<d>addu\t%0,%1,%2";
1198   else
1199     return "<d>addiu\t%0,%1,%2";
1201   [(set_attr "alu_type" "add")
1202    (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1203    (set_attr "mode" "<MODE>")])
1205 (define_insn "*add<mode>3_mips16"
1206   [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1207         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1208                   (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1209   "TARGET_MIPS16"
1210   "@
1211     <d>addiu\t%0,%2
1212     <d>addiu\t%0,%2
1213     <d>addiu\t%0,%1,%2
1214     <d>addiu\t%0,%1,%2
1215     <d>addiu\t%0,%2
1216     <d>addiu\t%0,%2
1217     <d>addiu\t%0,%1,%2
1218     <d>addiu\t%0,%1,%2
1219     <d>addu\t%0,%1,%2"
1220   [(set_attr "alu_type" "add")
1221    (set_attr "mode" "<MODE>")
1222    (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1224 ;; On the mips16, we can sometimes split an add of a constant which is
1225 ;; a 4 byte instruction into two adds which are both 2 byte
1226 ;; instructions.  There are two cases: one where we are adding a
1227 ;; constant plus a register to another register, and one where we are
1228 ;; simply adding a constant to a register.
1230 (define_split
1231   [(set (match_operand:SI 0 "d_operand")
1232         (plus:SI (match_dup 0)
1233                  (match_operand:SI 1 "const_int_operand")))]
1234   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1235    && ((INTVAL (operands[1]) > 0x7f
1236         && INTVAL (operands[1]) <= 0x7f + 0x7f)
1237        || (INTVAL (operands[1]) < - 0x80
1238            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1239   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1240    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1242   HOST_WIDE_INT val = INTVAL (operands[1]);
1244   if (val >= 0)
1245     {
1246       operands[1] = GEN_INT (0x7f);
1247       operands[2] = GEN_INT (val - 0x7f);
1248     }
1249   else
1250     {
1251       operands[1] = GEN_INT (- 0x80);
1252       operands[2] = GEN_INT (val + 0x80);
1253     }
1256 (define_split
1257   [(set (match_operand:SI 0 "d_operand")
1258         (plus:SI (match_operand:SI 1 "d_operand")
1259                  (match_operand:SI 2 "const_int_operand")))]
1260   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1261    && REGNO (operands[0]) != REGNO (operands[1])
1262    && ((INTVAL (operands[2]) > 0x7
1263         && INTVAL (operands[2]) <= 0x7 + 0x7f)
1264        || (INTVAL (operands[2]) < - 0x8
1265            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1266   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1267    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1269   HOST_WIDE_INT val = INTVAL (operands[2]);
1271   if (val >= 0)
1272     {
1273       operands[2] = GEN_INT (0x7);
1274       operands[3] = GEN_INT (val - 0x7);
1275     }
1276   else
1277     {
1278       operands[2] = GEN_INT (- 0x8);
1279       operands[3] = GEN_INT (val + 0x8);
1280     }
1283 (define_split
1284   [(set (match_operand:DI 0 "d_operand")
1285         (plus:DI (match_dup 0)
1286                  (match_operand:DI 1 "const_int_operand")))]
1287   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1288    && ((INTVAL (operands[1]) > 0xf
1289         && INTVAL (operands[1]) <= 0xf + 0xf)
1290        || (INTVAL (operands[1]) < - 0x10
1291            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1292   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1293    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1295   HOST_WIDE_INT val = INTVAL (operands[1]);
1297   if (val >= 0)
1298     {
1299       operands[1] = GEN_INT (0xf);
1300       operands[2] = GEN_INT (val - 0xf);
1301     }
1302   else
1303     {
1304       operands[1] = GEN_INT (- 0x10);
1305       operands[2] = GEN_INT (val + 0x10);
1306     }
1309 (define_split
1310   [(set (match_operand:DI 0 "d_operand")
1311         (plus:DI (match_operand:DI 1 "d_operand")
1312                  (match_operand:DI 2 "const_int_operand")))]
1313   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1314    && REGNO (operands[0]) != REGNO (operands[1])
1315    && ((INTVAL (operands[2]) > 0x7
1316         && INTVAL (operands[2]) <= 0x7 + 0xf)
1317        || (INTVAL (operands[2]) < - 0x8
1318            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1319   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1320    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1322   HOST_WIDE_INT val = INTVAL (operands[2]);
1324   if (val >= 0)
1325     {
1326       operands[2] = GEN_INT (0x7);
1327       operands[3] = GEN_INT (val - 0x7);
1328     }
1329   else
1330     {
1331       operands[2] = GEN_INT (- 0x8);
1332       operands[3] = GEN_INT (val + 0x8);
1333     }
1336 (define_insn "*addsi3_extended"
1337   [(set (match_operand:DI 0 "register_operand" "=d,d")
1338         (sign_extend:DI
1339              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1340                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
1341   "TARGET_64BIT && !TARGET_MIPS16"
1342   "@
1343     addu\t%0,%1,%2
1344     addiu\t%0,%1,%2"
1345   [(set_attr "alu_type" "add")
1346    (set_attr "mode" "SI")])
1348 ;; Split this insn so that the addiu splitters can have a crack at it.
1349 ;; Use a conservative length estimate until the split.
1350 (define_insn_and_split "*addsi3_extended_mips16"
1351   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1352         (sign_extend:DI
1353              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1354                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1355   "TARGET_64BIT && TARGET_MIPS16"
1356   "#"
1357   "&& reload_completed"
1358   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1359   { operands[3] = gen_lowpart (SImode, operands[0]); }
1360   [(set_attr "alu_type" "add")
1361    (set_attr "mode" "SI")
1362    (set_attr "extended_mips16" "yes")])
1364 ;; Combiner patterns for unsigned byte-add.
1366 (define_insn "*baddu_si_eb"
1367   [(set (match_operand:SI 0 "register_operand" "=d")
1368         (zero_extend:SI
1369          (subreg:QI
1370           (plus:SI (match_operand:SI 1 "register_operand" "d")
1371                    (match_operand:SI 2 "register_operand" "d")) 3)))]
1372   "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1373   "baddu\\t%0,%1,%2"
1374   [(set_attr "alu_type" "add")])
1376 (define_insn "*baddu_si_el"
1377   [(set (match_operand:SI 0 "register_operand" "=d")
1378         (zero_extend:SI
1379          (subreg:QI
1380           (plus:SI (match_operand:SI 1 "register_operand" "d")
1381                    (match_operand:SI 2 "register_operand" "d")) 0)))]
1382   "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1383   "baddu\\t%0,%1,%2"
1384   [(set_attr "alu_type" "add")])
1386 (define_insn "*baddu_di<mode>"
1387   [(set (match_operand:GPR 0 "register_operand" "=d")
1388         (zero_extend:GPR
1389          (truncate:QI
1390           (plus:DI (match_operand:DI 1 "register_operand" "d")
1391                    (match_operand:DI 2 "register_operand" "d")))))]
1392   "ISA_HAS_BADDU && TARGET_64BIT"
1393   "baddu\\t%0,%1,%2"
1394   [(set_attr "alu_type" "add")])
1397 ;;  ....................
1399 ;;      SUBTRACTION
1401 ;;  ....................
1404 (define_insn "sub<mode>3"
1405   [(set (match_operand:ANYF 0 "register_operand" "=f")
1406         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1407                     (match_operand:ANYF 2 "register_operand" "f")))]
1408   ""
1409   "sub.<fmt>\t%0,%1,%2"
1410   [(set_attr "type" "fadd")
1411    (set_attr "mode" "<UNITMODE>")])
1413 (define_insn "sub<mode>3"
1414   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1415         (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1416                    (match_operand:GPR 2 "register_operand" "!u,d")))]
1417   ""
1418   "<d>subu\t%0,%1,%2"
1419   [(set_attr "alu_type" "sub")
1420    (set_attr "compression" "micromips32,*")
1421    (set_attr "mode" "<MODE>")])
1423 (define_insn "*subsi3_extended"
1424   [(set (match_operand:DI 0 "register_operand" "=d")
1425         (sign_extend:DI
1426             (minus:SI (match_operand:SI 1 "register_operand" "d")
1427                       (match_operand:SI 2 "register_operand" "d"))))]
1428   "TARGET_64BIT"
1429   "subu\t%0,%1,%2"
1430   [(set_attr "alu_type" "sub")
1431    (set_attr "mode" "DI")])
1434 ;;  ....................
1436 ;;      MULTIPLICATION
1438 ;;  ....................
1441 (define_expand "mul<mode>3"
1442   [(set (match_operand:SCALARF 0 "register_operand")
1443         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1444                       (match_operand:SCALARF 2 "register_operand")))]
1445   ""
1446   "")
1448 (define_insn "*mul<mode>3"
1449   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1450         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1451                       (match_operand:SCALARF 2 "register_operand" "f")))]
1452   "!TARGET_4300_MUL_FIX"
1453   "mul.<fmt>\t%0,%1,%2"
1454   [(set_attr "type" "fmul")
1455    (set_attr "mode" "<MODE>")])
1457 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1458 ;; operands may corrupt immediately following multiplies. This is a
1459 ;; simple fix to insert NOPs.
1461 (define_insn "*mul<mode>3_r4300"
1462   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1463         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1464                       (match_operand:SCALARF 2 "register_operand" "f")))]
1465   "TARGET_4300_MUL_FIX"
1466   "mul.<fmt>\t%0,%1,%2\;nop"
1467   [(set_attr "type" "fmul")
1468    (set_attr "mode" "<MODE>")
1469    (set_attr "insn_count" "2")])
1471 (define_insn "mulv2sf3"
1472   [(set (match_operand:V2SF 0 "register_operand" "=f")
1473         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1474                    (match_operand:V2SF 2 "register_operand" "f")))]
1475   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1476   "mul.ps\t%0,%1,%2"
1477   [(set_attr "type" "fmul")
1478    (set_attr "mode" "SF")])
1480 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1481 ;; shift executes while an integer multiplication is in progress, the
1482 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1483 ;; with the mult on the R4000.
1485 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1486 ;; (also valid for MIPS R4000MC processors):
1488 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1489 ;;      this errata description.
1490 ;;      The following code sequence causes the R4000 to incorrectly
1491 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1492 ;;      instruction.  If the dsra32 instruction is executed during an
1493 ;;      integer multiply, the dsra32 will only shift by the amount in
1494 ;;      specified in the instruction rather than the amount plus 32
1495 ;;      bits.
1496 ;;      instruction 1:          mult    rs,rt           integer multiply
1497 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1498 ;;                                                      right arithmetic + 32
1499 ;;      Workaround: A dsra32 instruction placed after an integer
1500 ;;      multiply should not be one of the 11 instructions after the
1501 ;;      multiply instruction."
1503 ;; and:
1505 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1506 ;;      the following description.
1507 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1508 ;;      64-bit versions) may produce incorrect results under the
1509 ;;      following conditions:
1510 ;;      1) An integer multiply is currently executing
1511 ;;      2) These types of shift instructions are executed immediately
1512 ;;         following an integer divide instruction.
1513 ;;      Workaround:
1514 ;;      1) Make sure no integer multiply is running wihen these
1515 ;;         instruction are executed.  If this cannot be predicted at
1516 ;;         compile time, then insert a "mfhi" to R0 instruction
1517 ;;         immediately after the integer multiply instruction.  This
1518 ;;         will cause the integer multiply to complete before the shift
1519 ;;         is executed.
1520 ;;      2) Separate integer divide and these two classes of shift
1521 ;;         instructions by another instruction or a noop."
1523 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1524 ;; respectively.
1526 (define_expand "mul<mode>3"
1527   [(set (match_operand:GPR 0 "register_operand")
1528         (mult:GPR (match_operand:GPR 1 "register_operand")
1529                   (match_operand:GPR 2 "register_operand")))]
1530   "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1532   rtx lo;
1534   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL)
1535     emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1536                                            operands[2]));
1537   else if (ISA_HAS_<D>MUL3)
1538     emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1539   else if (TARGET_MIPS16)
1540     {
1541       lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1542       emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1543       emit_move_insn (operands[0], lo);
1544     }
1545   else if (TARGET_FIX_R4000)
1546     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1547   else
1548     emit_insn
1549       (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1550   DONE;
1553 (define_insn "mul<mode>3_mul3_nohilo"
1554   [(set (match_operand:GPR 0 "register_operand" "=d")
1555         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1556                   (match_operand:GPR 2 "register_operand" "d")))]
1557   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL"
1559   if (TARGET_LOONGSON_2EF)
1560     return "<d>multu.g\t%0,%1,%2";
1561   else if (TARGET_LOONGSON_3A)
1562     return "gs<d>multu\t%0,%1,%2";
1563   else
1564     return "<d>mul\t%0,%1,%2";
1566   [(set_attr "type" "imul3nc")
1567    (set_attr "mode" "<MODE>")])
1569 (define_insn "mul<mode>3_mul3"
1570   [(set (match_operand:GPR 0 "register_operand" "=d,l")
1571         (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1572                   (match_operand:GPR 2 "register_operand" "d,d")))
1573    (clobber (match_scratch:GPR 3 "=l,X"))]
1574   "ISA_HAS_<D>MUL3"
1576   if (which_alternative == 1)
1577     return "<d>mult\t%1,%2";
1578   if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1579     return "mult\t%0,%1,%2";
1580   return "<d>mul\t%0,%1,%2";
1582   [(set_attr "type" "imul3,imul")
1583    (set_attr "mode" "<MODE>")])
1585 ;; If a register gets allocated to LO, and we spill to memory, the reload
1586 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1587 ;; if it can set the GPR directly.
1589 ;; Operand 0: LO
1590 ;; Operand 1: GPR (1st multiplication operand)
1591 ;; Operand 2: GPR (2nd multiplication operand)
1592 ;; Operand 3: GPR (destination)
1593 (define_peephole2
1594   [(parallel
1595        [(set (match_operand:SI 0 "lo_operand")
1596              (mult:SI (match_operand:SI 1 "d_operand")
1597                       (match_operand:SI 2 "d_operand")))
1598         (clobber (scratch:SI))])
1599    (set (match_operand:SI 3 "d_operand")
1600         (match_dup 0))]
1601   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1602   [(parallel
1603        [(set (match_dup 3)
1604              (mult:SI (match_dup 1)
1605                       (match_dup 2)))
1606         (clobber (match_dup 0))])])
1608 (define_insn "mul<mode>3_internal"
1609   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1610         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1611                   (match_operand:GPR 2 "register_operand" "d")))]
1612   "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1613   "<d>mult\t%1,%2"
1614   [(set_attr "type" "imul")
1615    (set_attr "mode" "<MODE>")])
1617 (define_insn "mul<mode>3_r4000"
1618   [(set (match_operand:GPR 0 "register_operand" "=d")
1619         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1620                   (match_operand:GPR 2 "register_operand" "d")))
1621    (clobber (match_scratch:GPR 3 "=l"))]
1622   "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1623   "<d>mult\t%1,%2\;mflo\t%0"
1624   [(set_attr "type" "imul")
1625    (set_attr "mode" "<MODE>")
1626    (set_attr "insn_count" "2")])
1628 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1629 ;; of "mult; mflo".  They have the same latency, but the first form gives
1630 ;; us an extra cycle to compute the operands.
1632 ;; Operand 0: LO
1633 ;; Operand 1: GPR (1st multiplication operand)
1634 ;; Operand 2: GPR (2nd multiplication operand)
1635 ;; Operand 3: GPR (destination)
1636 (define_peephole2
1637   [(set (match_operand:SI 0 "lo_operand")
1638         (mult:SI (match_operand:SI 1 "d_operand")
1639                  (match_operand:SI 2 "d_operand")))
1640    (set (match_operand:SI 3 "d_operand")
1641         (match_dup 0))]
1642   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1643   [(set (match_dup 0)
1644         (const_int 0))
1645    (parallel
1646        [(set (match_dup 0)
1647              (plus:SI (mult:SI (match_dup 1)
1648                                (match_dup 2))
1649                       (match_dup 0)))
1650         (set (match_dup 3)
1651              (plus:SI (mult:SI (match_dup 1)
1652                                (match_dup 2))
1653                       (match_dup 0)))])])
1655 ;; Multiply-accumulate patterns
1657 ;; This pattern is first matched by combine, which tries to use the
1658 ;; pattern wherever it can.  We don't know until later whether it
1659 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1660 ;; so we need to keep both options open.
1662 ;; The second alternative has a "?" marker because it is generally
1663 ;; one instruction more costly than the first alternative.  This "?"
1664 ;; marker is enough to convey the relative costs to the register
1665 ;; allocator.
1667 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1668 ;; reloads of the other operands, even though operands 4 and 5 need no
1669 ;; copy instructions.  Reload therefore thinks that the second alternative
1670 ;; is two reloads more costly than the first.  We add "*?*?" to the first
1671 ;; alternative as a counterweight.
1673 ;; LRA simulates reload but the cost of reloading scratches is lower
1674 ;; than of the classic reload. For the time being, removing the counterweight
1675 ;; for LRA is more profitable.
1676 (define_insn "*mul_acc_si"
1677   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1678         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1679                           (match_operand:SI 2 "register_operand" "d,d,d"))
1680                  (match_operand:SI 3 "register_operand" "0,0,d")))
1681    (clobber (match_scratch:SI 4 "=X,X,l"))
1682    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1683   "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1684   "@
1685     madd\t%1,%2
1686     madd\t%1,%2
1687     #"
1688   [(set_attr "type"     "imadd")
1689    (set_attr "accum_in" "3")
1690    (set_attr "mode"     "SI")
1691    (set_attr "insn_count" "1,1,2")
1692    (set (attr "enabled")
1693         (cond [(and (eq_attr "alternative" "0")
1694                     (match_test "!mips_lra_flag"))
1695                   (const_string "yes")
1696                (and (eq_attr "alternative" "1")
1697                     (match_test "mips_lra_flag"))
1698                   (const_string "yes")
1699                (eq_attr "alternative" "2")
1700                   (const_string "yes")]
1701               (const_string "no")))])
1703 ;; The same idea applies here.  The middle alternative needs one less
1704 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1705 (define_insn "*mul_acc_si_r3900"
1706   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1707         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1708                           (match_operand:SI 2 "register_operand" "d,d,d,d"))
1709                  (match_operand:SI 3 "register_operand" "0,0,l,d")))
1710    (clobber (match_scratch:SI 4 "=X,X,3,l"))
1711    (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1712   "TARGET_MIPS3900 && !TARGET_MIPS16"
1713   "@
1714     madd\t%1,%2
1715     madd\t%1,%2
1716     madd\t%0,%1,%2
1717     #"
1718   [(set_attr "type"     "imadd")
1719    (set_attr "accum_in" "3")
1720    (set_attr "mode"     "SI")
1721    (set_attr "insn_count" "1,1,1,2")
1722    (set (attr "enabled")
1723         (cond [(and (eq_attr "alternative" "0")
1724                     (match_test "!mips_lra_flag"))
1725                   (const_string "yes")
1726                (and (eq_attr "alternative" "1")
1727                     (match_test "mips_lra_flag"))
1728                   (const_string "yes")
1729                (eq_attr "alternative" "2,3")
1730                   (const_string "yes")]
1731               (const_string "no")))])
1733 ;; Split *mul_acc_si if both the source and destination accumulator
1734 ;; values are GPRs.
1735 (define_split
1736   [(set (match_operand:SI 0 "d_operand")
1737         (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1738                           (match_operand:SI 2 "d_operand"))
1739                  (match_operand:SI 3 "d_operand")))
1740    (clobber (match_operand:SI 4 "lo_operand"))
1741    (clobber (match_operand:SI 5 "d_operand"))]
1742   "reload_completed"
1743   [(parallel [(set (match_dup 5)
1744                    (mult:SI (match_dup 1) (match_dup 2)))
1745               (clobber (match_dup 4))])
1746    (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1747   "")
1749 (define_insn "*macc"
1750   [(set (match_operand:SI 0 "register_operand" "=l,d")
1751         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1752                           (match_operand:SI 2 "register_operand" "d,d"))
1753                  (match_operand:SI 3 "register_operand" "0,l")))
1754    (clobber (match_scratch:SI 4 "=X,3"))]
1755   "ISA_HAS_MACC"
1757   if (which_alternative == 1)
1758     return "macc\t%0,%1,%2";
1759   else if (TARGET_MIPS5500)
1760     return "madd\t%1,%2";
1761   else
1762     /* The VR4130 assumes that there is a two-cycle latency between a macc
1763        that "writes" to $0 and an instruction that reads from it.  We avoid
1764        this by assigning to $1 instead.  */
1765     return "%[macc\t%@,%1,%2%]";
1767   [(set_attr "type" "imadd")
1768    (set_attr "accum_in" "3")
1769    (set_attr "mode" "SI")])
1771 (define_insn "*msac"
1772   [(set (match_operand:SI 0 "register_operand" "=l,d")
1773         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1774                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1775                            (match_operand:SI 3 "register_operand" "d,d"))))
1776    (clobber (match_scratch:SI 4 "=X,1"))]
1777   "ISA_HAS_MSAC"
1779   if (which_alternative == 1)
1780     return "msac\t%0,%2,%3";
1781   else if (TARGET_MIPS5500)
1782     return "msub\t%2,%3";
1783   else
1784     return "msac\t$0,%2,%3";
1786   [(set_attr "type"     "imadd")
1787    (set_attr "accum_in" "1")
1788    (set_attr "mode"     "SI")])
1790 ;; An msac-like instruction implemented using negation and a macc.
1791 (define_insn_and_split "*msac_using_macc"
1792   [(set (match_operand:SI 0 "register_operand" "=l,d")
1793         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1794                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1795                            (match_operand:SI 3 "register_operand" "d,d"))))
1796    (clobber (match_scratch:SI 4 "=X,1"))
1797    (clobber (match_scratch:SI 5 "=d,d"))]
1798   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1799   "#"
1800   "&& reload_completed"
1801   [(set (match_dup 5)
1802         (neg:SI (match_dup 3)))
1803    (parallel
1804        [(set (match_dup 0)
1805              (plus:SI (mult:SI (match_dup 2)
1806                                (match_dup 5))
1807                       (match_dup 1)))
1808         (clobber (match_dup 4))])]
1809   ""
1810   [(set_attr "type"     "imadd")
1811    (set_attr "accum_in" "1")
1812    (set_attr "insn_count" "2")])
1814 ;; Patterns generated by the define_peephole2 below.
1816 (define_insn "*macc2"
1817   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1818         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1819                           (match_operand:SI 2 "register_operand" "d"))
1820                  (match_dup 0)))
1821    (set (match_operand:SI 3 "register_operand" "=d")
1822         (plus:SI (mult:SI (match_dup 1)
1823                           (match_dup 2))
1824                  (match_dup 0)))]
1825   "ISA_HAS_MACC && reload_completed"
1826   "macc\t%3,%1,%2"
1827   [(set_attr "type"     "imadd")
1828    (set_attr "accum_in" "0")
1829    (set_attr "mode"     "SI")])
1831 (define_insn "*msac2"
1832   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1833         (minus:SI (match_dup 0)
1834                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1835                            (match_operand:SI 2 "register_operand" "d"))))
1836    (set (match_operand:SI 3 "register_operand" "=d")
1837         (minus:SI (match_dup 0)
1838                   (mult:SI (match_dup 1)
1839                            (match_dup 2))))]
1840   "ISA_HAS_MSAC && reload_completed"
1841   "msac\t%3,%1,%2"
1842   [(set_attr "type"     "imadd")
1843    (set_attr "accum_in" "0")
1844    (set_attr "mode"     "SI")])
1846 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1847 ;; Similarly msac.
1849 ;; Operand 0: LO
1850 ;; Operand 1: macc/msac
1851 ;; Operand 2: GPR (destination)
1852 (define_peephole2
1853   [(parallel
1854        [(set (match_operand:SI 0 "lo_operand")
1855              (match_operand:SI 1 "macc_msac_operand"))
1856         (clobber (scratch:SI))])
1857    (set (match_operand:SI 2 "d_operand")
1858         (match_dup 0))]
1859   ""
1860   [(parallel [(set (match_dup 0)
1861                    (match_dup 1))
1862               (set (match_dup 2)
1863                    (match_dup 1))])])
1865 ;; When we have a three-address multiplication instruction, it should
1866 ;; be faster to do a separate multiply and add, rather than moving
1867 ;; something into LO in order to use a macc instruction.
1869 ;; This peephole needs a scratch register to cater for the case when one
1870 ;; of the multiplication operands is the same as the destination.
1872 ;; Operand 0: GPR (scratch)
1873 ;; Operand 1: LO
1874 ;; Operand 2: GPR (addend)
1875 ;; Operand 3: GPR (destination)
1876 ;; Operand 4: macc/msac
1877 ;; Operand 5: new multiplication
1878 ;; Operand 6: new addition/subtraction
1879 (define_peephole2
1880   [(match_scratch:SI 0 "d")
1881    (set (match_operand:SI 1 "lo_operand")
1882         (match_operand:SI 2 "d_operand"))
1883    (match_dup 0)
1884    (parallel
1885        [(set (match_operand:SI 3 "d_operand")
1886              (match_operand:SI 4 "macc_msac_operand"))
1887         (clobber (match_dup 1))])]
1888   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1889   [(parallel [(set (match_dup 0)
1890                    (match_dup 5))
1891               (clobber (match_dup 1))])
1892    (set (match_dup 3)
1893         (match_dup 6))]
1895   operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1896   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1897                                 operands[2], operands[0]);
1900 ;; Same as above, except LO is the initial target of the macc.
1902 ;; Operand 0: GPR (scratch)
1903 ;; Operand 1: LO
1904 ;; Operand 2: GPR (addend)
1905 ;; Operand 3: macc/msac
1906 ;; Operand 4: GPR (destination)
1907 ;; Operand 5: new multiplication
1908 ;; Operand 6: new addition/subtraction
1909 (define_peephole2
1910   [(match_scratch:SI 0 "d")
1911    (set (match_operand:SI 1 "lo_operand")
1912         (match_operand:SI 2 "d_operand"))
1913    (match_dup 0)
1914    (parallel
1915        [(set (match_dup 1)
1916              (match_operand:SI 3 "macc_msac_operand"))
1917         (clobber (scratch:SI))])
1918    (match_dup 0)
1919    (set (match_operand:SI 4 "d_operand")
1920         (match_dup 1))]
1921   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1922   [(parallel [(set (match_dup 0)
1923                    (match_dup 5))
1924               (clobber (match_dup 1))])
1925    (set (match_dup 4)
1926         (match_dup 6))]
1928   operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1929   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1930                                 operands[2], operands[0]);
1933 ;; See the comment above *mul_add_si for details.
1934 (define_insn "*mul_sub_si"
1935   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1936         (minus:SI (match_operand:SI 1 "register_operand" "0,0,d")
1937                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1938                            (match_operand:SI 3 "register_operand" "d,d,d"))))
1939    (clobber (match_scratch:SI 4 "=X,X,l"))
1940    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1941   "GENERATE_MADD_MSUB"
1942   "@
1943    msub\t%2,%3
1944    msub\t%2,%3
1945    #"
1946   [(set_attr "type"     "imadd")
1947    (set_attr "accum_in" "1")
1948    (set_attr "mode"     "SI")
1949    (set_attr "insn_count" "1,1,2")
1950    (set (attr "enabled")
1951         (cond [(and (eq_attr "alternative" "0")
1952                     (match_test "!mips_lra_flag"))
1953                   (const_string "yes")
1954                (and (eq_attr "alternative" "1")
1955                     (match_test "mips_lra_flag"))
1956                   (const_string "yes")
1957                (eq_attr "alternative" "2")
1958                   (const_string "yes")]
1959               (const_string "no")))])
1961 ;; Split *mul_sub_si if both the source and destination accumulator
1962 ;; values are GPRs.
1963 (define_split
1964   [(set (match_operand:SI 0 "d_operand")
1965         (minus:SI (match_operand:SI 1 "d_operand")
1966                   (mult:SI (match_operand:SI 2 "d_operand")
1967                            (match_operand:SI 3 "d_operand"))))
1968    (clobber (match_operand:SI 4 "lo_operand"))
1969    (clobber (match_operand:SI 5 "d_operand"))]
1970   "reload_completed"
1971   [(parallel [(set (match_dup 5)
1972                    (mult:SI (match_dup 2) (match_dup 3)))
1973               (clobber (match_dup 4))])
1974    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1975   "")
1977 (define_insn "*muls"
1978   [(set (match_operand:SI 0 "register_operand" "=l,d")
1979         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1980                          (match_operand:SI 2 "register_operand" "d,d"))))
1981    (clobber (match_scratch:SI 3 "=X,l"))]
1982   "ISA_HAS_MULS"
1983   "@
1984    muls\t$0,%1,%2
1985    muls\t%0,%1,%2"
1986   [(set_attr "type"     "imul,imul3")
1987    (set_attr "mode"     "SI")])
1989 (define_expand "<u>mulsidi3"
1990   [(set (match_operand:DI 0 "register_operand")
1991         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1992                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1993   "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1995   mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1996   emit_insn (fn (operands[0], operands[1], operands[2]));
1997   DONE;
2000 (define_expand "<u>mulsidi3_32bit_r6"
2001   [(set (match_operand:DI 0 "register_operand")
2002         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2003                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2004   "!TARGET_64BIT && ISA_HAS_R6MUL"
2006   rtx dest = gen_reg_rtx (DImode);
2007   rtx low = mips_subword (dest, 0);
2008   rtx high = mips_subword (dest, 1);
2010   emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2011   emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2013   emit_move_insn (mips_subword (operands[0], 0), low);
2014   emit_move_insn (mips_subword (operands[0], 1), high);
2015   DONE;
2018 (define_expand "<u>mulsidi3_32bit_mips16"
2019   [(set (match_operand:DI 0 "register_operand")
2020         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2021                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2022   "!TARGET_64BIT && TARGET_MIPS16"
2024   rtx hilo;
2026   hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2027   emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2028   emit_move_insn (operands[0], hilo);
2029   DONE;
2032 ;; As well as being named patterns, these instructions are used by the
2033 ;; __builtin_mips_mult<u>() functions.  We must always make those functions
2034 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2035 (define_insn "<u>mulsidi3_32bit"
2036   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2037         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2038                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2039   "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2041   if (ISA_HAS_DSP_MULT)
2042     return "mult<u>\t%q0,%1,%2";
2043   else
2044     return "mult<u>\t%1,%2";
2046   [(set_attr "type" "imul")
2047    (set_attr "mode" "SI")])
2049 (define_insn "<u>mulsidi3_32bit_r4000"
2050   [(set (match_operand:DI 0 "register_operand" "=d")
2051         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2052                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2053    (clobber (match_scratch:DI 3 "=x"))]
2054   "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2055   "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2056   [(set_attr "type" "imul")
2057    (set_attr "mode" "SI")
2058    (set_attr "insn_count" "3")])
2060 (define_insn_and_split "<u>mulsidi3_64bit"
2061   [(set (match_operand:DI 0 "register_operand" "=d")
2062         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2063                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2064    (clobber (match_scratch:TI 3 "=x"))
2065    (clobber (match_scratch:DI 4 "=d"))]
2066   "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2067    && !TARGET_MIPS16 && ISA_HAS_MULT"
2068   "#"
2069   "&& reload_completed"
2070   [(const_int 0)]
2072   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2073                                           operands[2], operands[4]));
2074   DONE;
2076   [(set_attr "type" "imul")
2077    (set_attr "mode" "SI")
2078    (set (attr "insn_count")
2079         (if_then_else (match_test "ISA_HAS_EXT_INS")
2080                       (const_int 4)
2081                       (const_int 7)))])
2083 (define_expand "<u>mulsidi3_64bit_mips16"
2084   [(set (match_operand:DI 0 "register_operand")
2085         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2086                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2087   "TARGET_64BIT && TARGET_MIPS16"
2089   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2090                                           operands[2], gen_reg_rtx (DImode)));
2091   DONE;
2094 (define_expand "<u>mulsidi3_64bit_split"
2095   [(set (match_operand:DI 0 "register_operand")
2096         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2097                  (any_extend:DI (match_operand:SI 2 "register_operand"))))
2098    (clobber (match_operand:DI 3 "register_operand"))]
2099   ""
2101   rtx hilo;
2103   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2104   emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2106   emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2107   emit_insn (gen_mfhidi_ti (operands[3], hilo));
2109   if (ISA_HAS_EXT_INS)
2110     emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2111                            operands[3]));
2112   else
2113     {
2114       /* Zero-extend the low part.  */
2115       mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2116       mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2118       /* Shift the high part into place.  */
2119       mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2121       /* OR the two halves together.  */
2122       mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2123     }
2124   DONE;
2127 (define_insn "<u>mulsidi3_64bit_hilo"
2128   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2129         (unspec:TI
2130           [(mult:DI
2131              (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2132              (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2133           UNSPEC_SET_HILO))]
2134   "TARGET_64BIT && !TARGET_FIX_R4000"
2135   "mult<u>\t%1,%2"
2136   [(set_attr "type" "imul")
2137    (set_attr "mode" "SI")])
2139 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2140 (define_insn "mulsidi3_64bit_dmul"
2141   [(set (match_operand:DI 0 "register_operand" "=d")
2142         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2143                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2144    (clobber (match_scratch:DI 3 "=l"))]
2145   "ISA_HAS_DMUL3"
2146   "dmul\t%0,%1,%2"
2147   [(set_attr "type" "imul3")
2148    (set_attr "mode" "DI")])
2150 (define_insn "mulsidi3_64bit_r6dmul"
2151   [(set (match_operand:DI 0 "register_operand" "=d")
2152         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2153                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2154   "ISA_HAS_R6DMUL"
2155   "dmul\t%0,%1,%2"
2156   [(set_attr "type" "imul3nc")
2157    (set_attr "mode" "DI")])
2159 ;; Widening multiply with negation.
2160 (define_insn "*muls<u>_di"
2161   [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2162         (neg:DI
2163          (mult:DI
2164           (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2165           (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2166   "!TARGET_64BIT && ISA_HAS_MULS"
2167   "muls<u>\t$0,%1,%2"
2168   [(set_attr "type" "imul")
2169    (set_attr "mode" "SI")])
2171 ;; As well as being named patterns, these instructions are used by the
2172 ;; __builtin_mips_msub<u>() functions.  We must always make those functions
2173 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2175 ;; This leads to a slight inconsistency.  We honor any tuning overrides
2176 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2177 ;; even if !ISA_HAS_DSP_MULT.
2178 (define_insn "<u>msubsidi4"
2179   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2180         (minus:DI
2181            (match_operand:DI 3 "muldiv_target_operand" "0")
2182            (mult:DI
2183               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2184               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2185   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2187   if (ISA_HAS_DSP_MULT)
2188     return "msub<u>\t%q0,%1,%2";
2189   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2190     return "msub<u>\t%1,%2";
2191   else
2192     return "msac<u>\t$0,%1,%2";
2194   [(set_attr "type" "imadd")
2195    (set_attr "accum_in" "3")
2196    (set_attr "mode" "SI")])
2198 ;; _highpart patterns
2200 (define_expand "<su>mulsi3_highpart"
2201   [(set (match_operand:SI 0 "register_operand")
2202         (truncate:SI
2203          (lshiftrt:DI
2204           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2205                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2206           (const_int 32))))]
2207   ""
2209   if (ISA_HAS_MULHI)
2210     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2211                                                        operands[1],
2212                                                        operands[2]));
2213   else if (TARGET_MIPS16)
2214     emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2215                                               operands[2]));
2216   else if (ISA_HAS_R6MUL)
2217     emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2218                                            operands[2]));
2219   else
2220     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2221                                                  operands[2]));
2222   DONE;
2225 (define_insn "<su>mulsi3_highpart_r6"
2226   [(set (match_operand:SI 0 "register_operand" "=d")
2227         (truncate:SI
2228          (lshiftrt:DI
2229           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2230                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2231           (const_int 32))))]
2232   "ISA_HAS_R6MUL"
2233   "muh<u>\t%0,%1,%2"
2234   [(set_attr "type" "imul3nc")
2235    (set_attr "mode" "SI")])
2237 (define_insn_and_split "<su>mulsi3_highpart_internal"
2238   [(set (match_operand:SI 0 "register_operand" "=d")
2239         (truncate:SI
2240          (lshiftrt:DI
2241           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2242                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2243           (const_int 32))))
2244    (clobber (match_scratch:SI 3 "=l"))]
2245   "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2246   { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2247   "&& reload_completed && !TARGET_FIX_R4000"
2248   [(const_int 0)]
2250   emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2251                                             operands[2]));
2252   DONE;
2254   [(set_attr "type" "imul")
2255    (set_attr "mode" "SI")
2256    (set_attr "insn_count" "2")])
2258 (define_expand "<su>mulsi3_highpart_split"
2259   [(set (match_operand:SI 0 "register_operand")
2260         (truncate:SI
2261          (lshiftrt:DI
2262           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2263                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2264           (const_int 32))))]
2265   ""
2267   rtx hilo;
2269   if (TARGET_64BIT)
2270     {
2271       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2272       emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2273       emit_insn (gen_mfhisi_ti (operands[0], hilo));
2274     }
2275   else
2276     {
2277       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2278       emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2279       emit_insn (gen_mfhisi_di (operands[0], hilo));
2280     }
2281   DONE;
2284 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2285   [(set (match_operand:SI 0 "register_operand" "=d")
2286         (truncate:SI
2287          (lshiftrt:DI
2288           (mult:DI
2289            (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2290            (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2291           (const_int 32))))
2292    (clobber (match_scratch:SI 3 "=l"))]
2293   "ISA_HAS_MULHI"
2294   "mulhi<u>\t%0,%1,%2"
2295   [(set_attr "type" "imul3")
2296    (set_attr "mode" "SI")])
2298 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2299   [(set (match_operand:SI 0 "register_operand" "=d")
2300         (truncate:SI
2301          (lshiftrt:DI
2302           (neg:DI
2303            (mult:DI
2304             (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2305             (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2306           (const_int 32))))
2307    (clobber (match_scratch:SI 3 "=l"))]
2308   "ISA_HAS_MULHI"
2309   "mulshi<u>\t%0,%1,%2"
2310   [(set_attr "type" "imul3")
2311    (set_attr "mode" "SI")])
2313 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
2314 ;; errata MD(0), which says that dmultu does not always produce the
2315 ;; correct result.
2316 (define_expand "<su>muldi3_highpart"
2317   [(set (match_operand:DI 0 "register_operand")
2318         (truncate:DI
2319          (lshiftrt:TI
2320           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2321                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2322           (const_int 64))))]
2323   "ISA_HAS_R6DMUL
2324    || (ISA_HAS_DMULT
2325        && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2327   if (TARGET_MIPS16)
2328     emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2329                                               operands[2]));
2330   else if (ISA_HAS_R6DMUL)
2331     emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2332                                            operands[2]));
2333   else
2334     emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2335                                                  operands[2]));
2336   DONE;
2339 (define_insn "<su>muldi3_highpart_r6"
2340   [(set (match_operand:DI 0 "register_operand" "=d")
2341         (truncate:DI
2342          (lshiftrt:TI
2343           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2344                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2345           (const_int 64))))]
2346   "ISA_HAS_R6DMUL"
2347   "dmuh<u>\t%0,%1,%2"
2348   [(set_attr "type" "imul3nc")
2349    (set_attr "mode" "DI")])
2351 (define_insn_and_split "<su>muldi3_highpart_internal"
2352   [(set (match_operand:DI 0 "register_operand" "=d")
2353         (truncate:DI
2354          (lshiftrt:TI
2355           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2356                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2357           (const_int 64))))
2358    (clobber (match_scratch:DI 3 "=l"))]
2359   "ISA_HAS_DMULT
2360    && !TARGET_MIPS16
2361    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2362   { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2363   "&& reload_completed && !TARGET_FIX_R4000"
2364   [(const_int 0)]
2366   emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2367                                             operands[2]));
2368   DONE;
2370   [(set_attr "type" "imul")
2371    (set_attr "mode" "DI")
2372    (set_attr "insn_count" "2")])
2374 (define_expand "<su>muldi3_highpart_split"
2375   [(set (match_operand:DI 0 "register_operand")
2376         (truncate:DI
2377          (lshiftrt:TI
2378           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2379                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2380           (const_int 64))))]
2381   ""
2383   rtx hilo;
2385   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2386   emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2387   emit_insn (gen_mfhidi_ti (operands[0], hilo));
2388   DONE;
2391 (define_expand "<u>mulditi3"
2392   [(set (match_operand:TI 0 "register_operand")
2393         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2394                  (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2395   "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2397   rtx hilo;
2399   if (TARGET_MIPS16)
2400     {
2401       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2402       emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2403       emit_move_insn (operands[0], hilo);
2404     }
2405   else if (TARGET_FIX_R4000)
2406     emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2407   else
2408     emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2409                                          operands[2]));
2410   DONE;
2413 (define_insn "<u>mulditi3_internal"
2414   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2415         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2416                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2417   "ISA_HAS_DMULT
2418    && !TARGET_FIX_R4000
2419    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2420   "dmult<u>\t%1,%2"
2421   [(set_attr "type" "imul")
2422    (set_attr "mode" "DI")])
2424 (define_insn "<u>mulditi3_r4000"
2425   [(set (match_operand:TI 0 "register_operand" "=d")
2426         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2427                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2428    (clobber (match_scratch:TI 3 "=x"))]
2429   "ISA_HAS_DMULT
2430    && TARGET_FIX_R4000
2431    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2432   "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2433   [(set_attr "type" "imul")
2434    (set_attr "mode" "DI")
2435    (set_attr "insn_count" "3")])
2437 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2438 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
2440 (define_insn "madsi"
2441   [(set (match_operand:SI 0 "register_operand" "+l")
2442         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2443                           (match_operand:SI 2 "register_operand" "d"))
2444                  (match_dup 0)))]
2445   "TARGET_MAD"
2446   "mad\t%1,%2"
2447   [(set_attr "type"     "imadd")
2448    (set_attr "accum_in" "0")
2449    (set_attr "mode"     "SI")])
2451 ;; See the comment above <u>msubsidi4 for the relationship between
2452 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2453 (define_insn "<u>maddsidi4"
2454   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2455         (plus:DI
2456          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2457                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2458          (match_operand:DI 3 "muldiv_target_operand" "0")))]
2459   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2460    && !TARGET_64BIT"
2462   if (TARGET_MAD)
2463     return "mad<u>\t%1,%2";
2464   else if (ISA_HAS_DSP_MULT)
2465     return "madd<u>\t%q0,%1,%2";
2466   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2467     return "madd<u>\t%1,%2";
2468   else
2469     /* See comment in *macc.  */
2470     return "%[macc<u>\t%@,%1,%2%]";
2472   [(set_attr "type" "imadd")
2473    (set_attr "accum_in" "3")
2474    (set_attr "mode" "SI")])
2476 ;; Floating point multiply accumulate instructions.
2478 (define_insn "*madd4<mode>"
2479   [(set (match_operand:ANYF 0 "register_operand" "=f")
2480         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2481                               (match_operand:ANYF 2 "register_operand" "f"))
2482                    (match_operand:ANYF 3 "register_operand" "f")))]
2483   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2484   "madd.<fmt>\t%0,%3,%1,%2"
2485   [(set_attr "type" "fmadd")
2486    (set_attr "mode" "<UNITMODE>")])
2488 (define_insn "fma<mode>4"
2489   [(set (match_operand:ANYF 0 "register_operand" "=f")
2490         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2491                   (match_operand:ANYF 2 "register_operand" "f")
2492                   (match_operand:ANYF 3 "register_operand" "0")))]
2493   "ISA_HAS_FP_MADDF_MSUBF"
2494   "maddf.<fmt>\t%0,%1,%2"
2495   [(set_attr "type" "fmadd")
2496    (set_attr "mode" "<UNITMODE>")])
2498 (define_insn "*madd3<mode>"
2499   [(set (match_operand:ANYF 0 "register_operand" "=f")
2500         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2501                               (match_operand:ANYF 2 "register_operand" "f"))
2502                    (match_operand:ANYF 3 "register_operand" "0")))]
2503   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2504   "madd.<fmt>\t%0,%1,%2"
2505   [(set_attr "type" "fmadd")
2506    (set_attr "mode" "<UNITMODE>")])
2508 (define_insn "*msub4<mode>"
2509   [(set (match_operand:ANYF 0 "register_operand" "=f")
2510         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2511                                (match_operand:ANYF 2 "register_operand" "f"))
2512                     (match_operand:ANYF 3 "register_operand" "f")))]
2513   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2514   "msub.<fmt>\t%0,%3,%1,%2"
2515   [(set_attr "type" "fmadd")
2516    (set_attr "mode" "<UNITMODE>")])
2518 (define_insn "*msub3<mode>"
2519   [(set (match_operand:ANYF 0 "register_operand" "=f")
2520         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2521                                (match_operand:ANYF 2 "register_operand" "f"))
2522                     (match_operand:ANYF 3 "register_operand" "0")))]
2523   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2524   "msub.<fmt>\t%0,%1,%2"
2525   [(set_attr "type" "fmadd")
2526    (set_attr "mode" "<UNITMODE>")])
2528 (define_insn "*nmadd4<mode>"
2529   [(set (match_operand:ANYF 0 "register_operand" "=f")
2530         (neg:ANYF (plus:ANYF
2531                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2532                               (match_operand:ANYF 2 "register_operand" "f"))
2533                    (match_operand:ANYF 3 "register_operand" "f"))))]
2534   "ISA_HAS_NMADD4_NMSUB4
2535    && TARGET_FUSED_MADD
2536    && HONOR_SIGNED_ZEROS (<MODE>mode)
2537    && !HONOR_NANS (<MODE>mode)"
2538   "nmadd.<fmt>\t%0,%3,%1,%2"
2539   [(set_attr "type" "fmadd")
2540    (set_attr "mode" "<UNITMODE>")])
2542 (define_insn "*nmadd3<mode>"
2543   [(set (match_operand:ANYF 0 "register_operand" "=f")
2544         (neg:ANYF (plus:ANYF
2545                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2546                               (match_operand:ANYF 2 "register_operand" "f"))
2547                    (match_operand:ANYF 3 "register_operand" "0"))))]
2548   "ISA_HAS_NMADD3_NMSUB3
2549    && TARGET_FUSED_MADD
2550    && HONOR_SIGNED_ZEROS (<MODE>mode)
2551    && !HONOR_NANS (<MODE>mode)"
2552   "nmadd.<fmt>\t%0,%1,%2"
2553   [(set_attr "type" "fmadd")
2554    (set_attr "mode" "<UNITMODE>")])
2556 (define_insn "*nmadd4<mode>_fastmath"
2557   [(set (match_operand:ANYF 0 "register_operand" "=f")
2558         (minus:ANYF
2559          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2560                     (match_operand:ANYF 2 "register_operand" "f"))
2561          (match_operand:ANYF 3 "register_operand" "f")))]
2562   "ISA_HAS_NMADD4_NMSUB4
2563    && TARGET_FUSED_MADD
2564    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2565    && !HONOR_NANS (<MODE>mode)"
2566   "nmadd.<fmt>\t%0,%3,%1,%2"
2567   [(set_attr "type" "fmadd")
2568    (set_attr "mode" "<UNITMODE>")])
2570 (define_insn "*nmadd3<mode>_fastmath"
2571   [(set (match_operand:ANYF 0 "register_operand" "=f")
2572         (minus:ANYF
2573          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2574                     (match_operand:ANYF 2 "register_operand" "f"))
2575          (match_operand:ANYF 3 "register_operand" "0")))]
2576   "ISA_HAS_NMADD3_NMSUB3
2577    && TARGET_FUSED_MADD
2578    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2579    && !HONOR_NANS (<MODE>mode)"
2580   "nmadd.<fmt>\t%0,%1,%2"
2581   [(set_attr "type" "fmadd")
2582    (set_attr "mode" "<UNITMODE>")])
2584 (define_insn "*nmsub4<mode>"
2585   [(set (match_operand:ANYF 0 "register_operand" "=f")
2586         (neg:ANYF (minus:ANYF
2587                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2588                               (match_operand:ANYF 3 "register_operand" "f"))
2589                    (match_operand:ANYF 1 "register_operand" "f"))))]
2590   "ISA_HAS_NMADD4_NMSUB4
2591    && TARGET_FUSED_MADD
2592    && HONOR_SIGNED_ZEROS (<MODE>mode)
2593    && !HONOR_NANS (<MODE>mode)"
2594   "nmsub.<fmt>\t%0,%1,%2,%3"
2595   [(set_attr "type" "fmadd")
2596    (set_attr "mode" "<UNITMODE>")])
2598 (define_insn "*nmsub3<mode>"
2599   [(set (match_operand:ANYF 0 "register_operand" "=f")
2600         (neg:ANYF (minus:ANYF
2601                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2602                               (match_operand:ANYF 3 "register_operand" "f"))
2603                    (match_operand:ANYF 1 "register_operand" "0"))))]
2604   "ISA_HAS_NMADD3_NMSUB3
2605    && TARGET_FUSED_MADD
2606    && HONOR_SIGNED_ZEROS (<MODE>mode)
2607    && !HONOR_NANS (<MODE>mode)"
2608   "nmsub.<fmt>\t%0,%1,%2"
2609   [(set_attr "type" "fmadd")
2610    (set_attr "mode" "<UNITMODE>")])
2612 (define_insn "*nmsub4<mode>_fastmath"
2613   [(set (match_operand:ANYF 0 "register_operand" "=f")
2614         (minus:ANYF
2615          (match_operand:ANYF 1 "register_operand" "f")
2616          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2617                     (match_operand:ANYF 3 "register_operand" "f"))))]
2618   "ISA_HAS_NMADD4_NMSUB4
2619    && TARGET_FUSED_MADD
2620    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2621    && !HONOR_NANS (<MODE>mode)"
2622   "nmsub.<fmt>\t%0,%1,%2,%3"
2623   [(set_attr "type" "fmadd")
2624    (set_attr "mode" "<UNITMODE>")])
2626 (define_insn "*nmsub3<mode>_fastmath"
2627   [(set (match_operand:ANYF 0 "register_operand" "=f")
2628         (minus:ANYF
2629          (match_operand:ANYF 1 "register_operand" "f")
2630          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2631                     (match_operand:ANYF 3 "register_operand" "0"))))]
2632   "ISA_HAS_NMADD3_NMSUB3
2633    && TARGET_FUSED_MADD
2634    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2635    && !HONOR_NANS (<MODE>mode)"
2636   "nmsub.<fmt>\t%0,%1,%2"
2637   [(set_attr "type" "fmadd")
2638    (set_attr "mode" "<UNITMODE>")])
2641 ;;  ....................
2643 ;;      DIVISION and REMAINDER
2645 ;;  ....................
2648 (define_expand "div<mode>3"
2649   [(set (match_operand:ANYF 0 "register_operand")
2650         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2651                   (match_operand:ANYF 2 "register_operand")))]
2652   "<divide_condition>"
2654   if (const_1_operand (operands[1], <MODE>mode))
2655     if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2656           && flag_unsafe_math_optimizations))
2657       operands[1] = force_reg (<MODE>mode, operands[1]);
2660 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2662 ;; If an mfc1 or dmfc1 happens to access the floating point register
2663 ;; file at the same time a long latency operation (div, sqrt, recip,
2664 ;; sqrt) iterates an intermediate result back through the floating
2665 ;; point register file bypass, then instead returning the correct
2666 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2667 ;; result of the long latency operation.
2669 ;; The workaround is to insert an unconditional 'mov' from/to the
2670 ;; long latency op destination register.
2672 (define_insn "*div<mode>3"
2673   [(set (match_operand:ANYF 0 "register_operand" "=f")
2674         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2675                   (match_operand:ANYF 2 "register_operand" "f")))]
2676   "<divide_condition>"
2678   if (TARGET_FIX_SB1)
2679     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2680   else
2681     return "div.<fmt>\t%0,%1,%2";
2683   [(set_attr "type" "fdiv")
2684    (set_attr "mode" "<UNITMODE>")
2685    (set (attr "insn_count")
2686         (if_then_else (match_test "TARGET_FIX_SB1")
2687                       (const_int 2)
2688                       (const_int 1)))])
2690 (define_insn "*recip<mode>3"
2691   [(set (match_operand:ANYF 0 "register_operand" "=f")
2692         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2693                   (match_operand:ANYF 2 "register_operand" "f")))]
2694   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2696   if (TARGET_FIX_SB1)
2697     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2698   else
2699     return "recip.<fmt>\t%0,%2";
2701   [(set_attr "type" "frdiv")
2702    (set_attr "mode" "<UNITMODE>")
2703    (set (attr "insn_count")
2704         (if_then_else (match_test "TARGET_FIX_SB1")
2705                       (const_int 2)
2706                       (const_int 1)))])
2708 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2709 ;; with negative operands.  We use special libgcc functions instead.
2710 (define_expand "divmod<mode>4"
2711   [(parallel
2712      [(set (match_operand:GPR 0 "register_operand")
2713            (div:GPR (match_operand:GPR 1 "register_operand")
2714                     (match_operand:GPR 2 "register_operand")))
2715       (set (match_operand:GPR 3 "register_operand")
2716            (mod:GPR (match_dup 1)
2717                     (match_dup 2)))])]
2718   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2720   if (TARGET_MIPS16)
2721     {
2722       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2723       emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2724                                            operands[2], operands[3], lo));
2725       DONE;
2726     }
2729 (define_insn_and_split "*divmod<mode>4"
2730   [(set (match_operand:GPR 0 "register_operand" "=l")
2731         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2732                  (match_operand:GPR 2 "register_operand" "d")))
2733    (set (match_operand:GPR 3 "register_operand" "=d")
2734         (mod:GPR (match_dup 1)
2735                  (match_dup 2)))]
2736   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2737   "#"
2738   "&& reload_completed"
2739   [(const_int 0)]
2741   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2742   DONE;
2744  [(set_attr "type" "idiv")
2745   (set_attr "mode" "<MODE>")
2746   (set_attr "insn_count" "2")])
2748 ;; Expand generates divmod instructions for individual division and modulus
2749 ;; operations.  We then rely on CSE to reuse earlier divmods where possible.
2750 ;; This means that, when generating MIPS16 code, it is better not to expose
2751 ;; the fixed LO register until after CSE has finished.  However, it's still
2752 ;; better to split before register allocation, so that we don't allocate
2753 ;; one of the scarce MIPS16 registers to an unused result.
2754 (define_insn_and_split "divmod<mode>4_mips16"
2755   [(set (match_operand:GPR 0 "register_operand" "=d")
2756         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2757                  (match_operand:GPR 2 "register_operand" "d")))
2758    (set (match_operand:GPR 3 "register_operand" "=d")
2759         (mod:GPR (match_dup 1)
2760                  (match_dup 2)))
2761    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2762   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2763   "#"
2764   "&& cse_not_expected"
2765   [(const_int 0)]
2767   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2768   emit_move_insn (operands[0], operands[4]);
2769   DONE;
2771  [(set_attr "type" "idiv")
2772   (set_attr "mode" "<MODE>")
2773   (set_attr "insn_count" "3")])
2775 (define_expand "udivmod<mode>4"
2776   [(parallel
2777      [(set (match_operand:GPR 0 "register_operand")
2778            (udiv:GPR (match_operand:GPR 1 "register_operand")
2779                      (match_operand:GPR 2 "register_operand")))
2780       (set (match_operand:GPR 3 "register_operand")
2781            (umod:GPR (match_dup 1)
2782                      (match_dup 2)))])]
2783   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2785   if (TARGET_MIPS16)
2786     {
2787       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2788       emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2789                                             operands[2], operands[3], lo));
2790       DONE;
2791     }
2794 (define_insn_and_split "*udivmod<mode>4"
2795   [(set (match_operand:GPR 0 "register_operand" "=l")
2796         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2797                   (match_operand:GPR 2 "register_operand" "d")))
2798    (set (match_operand:GPR 3 "register_operand" "=d")
2799         (umod:GPR (match_dup 1)
2800                   (match_dup 2)))]
2801   "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2802   "#"
2803   "reload_completed"
2804   [(const_int 0)]
2806   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2807   DONE;
2809   [(set_attr "type" "idiv")
2810    (set_attr "mode" "<MODE>")
2811    (set_attr "insn_count" "2")])
2813 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2814 (define_insn_and_split "udivmod<mode>4_mips16"
2815   [(set (match_operand:GPR 0 "register_operand" "=d")
2816         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2817                   (match_operand:GPR 2 "register_operand" "d")))
2818    (set (match_operand:GPR 3 "register_operand" "=d")
2819         (umod:GPR (match_dup 1)
2820                   (match_dup 2)))
2821    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2822   "ISA_HAS_<D>DIV && TARGET_MIPS16"
2823   "#"
2824   "cse_not_expected"
2825   [(const_int 0)]
2827   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2828   emit_move_insn (operands[0], operands[4]);
2829   DONE;
2831   [(set_attr "type" "idiv")
2832    (set_attr "mode" "<MODE>")
2833    (set_attr "insn_count" "3")])
2835 (define_expand "<u>divmod<mode>4_split"
2836   [(set (match_operand:GPR 0 "register_operand")
2837         (any_mod:GPR (match_operand:GPR 1 "register_operand")
2838                      (match_operand:GPR 2 "register_operand")))]
2839   ""
2841   rtx hilo;
2843   if (TARGET_64BIT)
2844     {
2845       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2846       emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2847                                                operands[2]));
2848       emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2849     }
2850   else
2851     {
2852       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2853       emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2854                                                operands[2]));
2855       emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2856     }
2857   DONE;
2860 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2861   [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2862         (unspec:HILO
2863           [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2864                         (match_operand:GPR 2 "register_operand" "d"))]
2865           UNSPEC_SET_HILO))]
2866   "ISA_HAS_<GPR:D>DIV"
2867   { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2868   [(set_attr "type" "idiv")
2869    (set_attr "mode" "<GPR:MODE>")])
2871 ;; Integer division and modulus.
2873 (define_insn "<u>div<mode>3"
2874   [(set (match_operand:GPR 0 "register_operand" "=&d")
2875         (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2876                      (match_operand:GPR 2 "register_operand" "d")))]
2877   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
2878   {
2879     if (TARGET_LOONGSON_2EF)
2880       return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
2881     else if (TARGET_LOONGSON_3A)
2882       return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
2883     else
2884       return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
2885   }
2886   [(set_attr "type" "idiv3")
2887    (set_attr "mode" "<MODE>")])
2889 (define_insn "<u>mod<mode>3"
2890   [(set (match_operand:GPR 0 "register_operand" "=&d")
2891         (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
2892                      (match_operand:GPR 2 "register_operand" "d")))]
2893   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
2894   {
2895     if (TARGET_LOONGSON_2EF)
2896       return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
2897     else if (TARGET_LOONGSON_3A)
2898       return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
2899     else
2900       return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
2901   }
2902   [(set_attr "type" "idiv3")
2903    (set_attr "mode" "<MODE>")])
2906 ;;  ....................
2908 ;;      SQUARE ROOT
2910 ;;  ....................
2912 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2913 ;; "*div[sd]f3" comment for details).
2915 (define_insn "sqrt<mode>2"
2916   [(set (match_operand:ANYF 0 "register_operand" "=f")
2917         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2918   "<sqrt_condition>"
2920   if (TARGET_FIX_SB1)
2921     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2922   else
2923     return "sqrt.<fmt>\t%0,%1";
2925   [(set_attr "type" "fsqrt")
2926    (set_attr "mode" "<UNITMODE>")
2927    (set (attr "insn_count")
2928         (if_then_else (match_test "TARGET_FIX_SB1")
2929                       (const_int 2)
2930                       (const_int 1)))])
2932 (define_insn "*rsqrt<mode>a"
2933   [(set (match_operand:ANYF 0 "register_operand" "=f")
2934         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2935                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2936   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2938   if (TARGET_FIX_SB1)
2939     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2940   else
2941     return "rsqrt.<fmt>\t%0,%2";
2943   [(set_attr "type" "frsqrt")
2944    (set_attr "mode" "<UNITMODE>")
2945    (set (attr "insn_count")
2946         (if_then_else (match_test "TARGET_FIX_SB1")
2947                       (const_int 2)
2948                       (const_int 1)))])
2950 (define_insn "*rsqrt<mode>b"
2951   [(set (match_operand:ANYF 0 "register_operand" "=f")
2952         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2953                              (match_operand:ANYF 2 "register_operand" "f"))))]
2954   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2956   if (TARGET_FIX_SB1)
2957     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2958   else
2959     return "rsqrt.<fmt>\t%0,%2";
2961   [(set_attr "type" "frsqrt")
2962    (set_attr "mode" "<UNITMODE>")
2963    (set (attr "insn_count")
2964         (if_then_else (match_test "TARGET_FIX_SB1")
2965                       (const_int 2)
2966                       (const_int 1)))])
2969 ;;  ....................
2971 ;;      ABSOLUTE VALUE
2973 ;;  ....................
2975 ;; Do not use the integer abs macro instruction, since that signals an
2976 ;; exception on -2147483648 (sigh).
2978 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
2979 ;; instruction that treats all NaN inputs as invalid; it does not clear
2980 ;; their sign bit.  We therefore can't use that form if the signs of
2981 ;; NaNs matter.
2983 (define_insn "abs<mode>2"
2984   [(set (match_operand:ANYF 0 "register_operand" "=f")
2985         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2986   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
2987   "abs.<fmt>\t%0,%1"
2988   [(set_attr "type" "fabs")
2989    (set_attr "mode" "<UNITMODE>")])
2992 ;;  ...................
2994 ;;  Count leading zeroes.
2996 ;;  ...................
2999 (define_insn "clz<mode>2"
3000   [(set (match_operand:GPR 0 "register_operand" "=d")
3001         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3002   "ISA_HAS_CLZ_CLO"
3003   "<d>clz\t%0,%1"
3004   [(set_attr "type" "clz")
3005    (set_attr "mode" "<MODE>")])
3008 ;;  ...................
3010 ;;  Count number of set bits.
3012 ;;  ...................
3015 (define_insn "popcount<mode>2"
3016   [(set (match_operand:GPR 0 "register_operand" "=d")
3017         (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3018   "ISA_HAS_POP"
3019   "<d>pop\t%0,%1"
3020   [(set_attr "type" "pop")
3021    (set_attr "mode" "<MODE>")])
3023 ;; The POP instruction is special as it does not take into account the upper
3024 ;; 32bits and is documented that way.
3025 (define_insn "*popcountdi2_trunc"
3026   [(set (match_operand:SI 0 "register_operand" "=d")
3027        (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3028   "ISA_HAS_POP && TARGET_64BIT"
3029   "pop\t%0,%1"
3030   [(set_attr "type" "pop")
3031    (set_attr "mode" "SI")])
3034 ;;  ....................
3036 ;;      NEGATION and ONE'S COMPLEMENT
3038 ;;  ....................
3040 (define_insn "negsi2"
3041   [(set (match_operand:SI 0 "register_operand" "=d")
3042         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3043   ""
3045   if (TARGET_MIPS16)
3046     return "neg\t%0,%1";
3047   else
3048     return "subu\t%0,%.,%1";
3050   [(set_attr "alu_type" "sub")
3051    (set_attr "mode"     "SI")])
3053 (define_insn "negdi2"
3054   [(set (match_operand:DI 0 "register_operand" "=d")
3055         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3056   "TARGET_64BIT && !TARGET_MIPS16"
3057   "dsubu\t%0,%.,%1"
3058   [(set_attr "alu_type" "sub")
3059    (set_attr "mode"     "DI")])
3061 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3062 ;; instruction that treats all NaN inputs as invalid; it does not flip
3063 ;; their sign bit.  We therefore can't use that form if the signs of
3064 ;; NaNs matter.
3066 (define_insn "neg<mode>2"
3067   [(set (match_operand:ANYF 0 "register_operand" "=f")
3068         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3069   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3070   "neg.<fmt>\t%0,%1"
3071   [(set_attr "type" "fneg")
3072    (set_attr "mode" "<UNITMODE>")])
3074 (define_insn "one_cmpl<mode>2"
3075   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3076         (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3077   ""
3079   if (TARGET_MIPS16)
3080     return "not\t%0,%1";
3081   else
3082     return "nor\t%0,%.,%1";
3084   [(set_attr "alu_type" "not")
3085    (set_attr "compression" "micromips,*")
3086    (set_attr "mode" "<MODE>")])
3089 ;;  ....................
3091 ;;      LOGICAL
3093 ;;  ....................
3096 ;; Many of these instructions use trivial define_expands, because we
3097 ;; want to use a different set of constraints when TARGET_MIPS16.
3099 (define_expand "and<mode>3"
3100   [(set (match_operand:GPR 0 "register_operand")
3101         (and:GPR (match_operand:GPR 1 "register_operand")
3102                  (match_operand:GPR 2 "and_reg_operand")))])
3104 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3105 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
3106 ;; Note that this variant does not trigger for SI mode because we require
3107 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3108 ;; sign-extended SImode value.
3110 ;; These are possible combinations for operand 1 and 2.  The table
3111 ;; includes both MIPS and MIPS16 cases.  (r=register, mem=memory,
3112 ;; 16=MIPS16, x=match, S=split):
3114 ;;     \ op1    r/EXT   r/!EXT  mem   r/16   mem/16
3115 ;;  op2
3117 ;;  andi           x     x
3118 ;;  0xff           x     x       x             x
3119 ;;  0xffff         x     x       x             x
3120 ;;  0xffff_ffff    x     S       x     S       x
3121 ;;  low-bitmask    x
3122 ;;  register       x     x
3123 ;;  register =op1                      x
3125 (define_insn "*and<mode>3"
3126   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3127         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3128                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3129   "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3131   int len;
3133   switch (which_alternative)
3134     {
3135     case 0:
3136       operands[1] = gen_lowpart (QImode, operands[1]);
3137       return "lbu\t%0,%1";
3138     case 1:
3139       operands[1] = gen_lowpart (HImode, operands[1]);
3140       return "lhu\t%0,%1";
3141     case 2:
3142       operands[1] = gen_lowpart (SImode, operands[1]);
3143       return "lwu\t%0,%1";
3144     case 3:
3145     case 4:
3146       return "andi\t%0,%1,%x2";
3147     case 5:
3148       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3149       operands[2] = GEN_INT (len);
3150       return "<d>ext\t%0,%1,0,%2";
3151     case 6:
3152       return "#";
3153     case 7:
3154     case 8:
3155       return "and\t%0,%1,%2";
3156     default:
3157       gcc_unreachable ();
3158     }
3160   [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3161    (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3162    (set_attr "mode" "<MODE>")])
3164 (define_insn "*and<mode>3_mips16"
3165   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3166         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3167                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3168   "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3170   switch (which_alternative)
3171     {
3172     case 0:
3173       operands[1] = gen_lowpart (QImode, operands[1]);
3174       return "lbu\t%0,%1";
3175     case 1:
3176       operands[1] = gen_lowpart (HImode, operands[1]);
3177       return "lhu\t%0,%1";
3178     case 2:
3179       operands[1] = gen_lowpart (SImode, operands[1]);
3180       return "lwu\t%0,%1";
3181     case 3:
3182       return "#";
3183     case 4:
3184       return "and\t%0,%2";
3185     default:
3186       gcc_unreachable ();
3187     }
3189   [(set_attr "move_type" "load,load,load,shift_shift,logical")
3190    (set_attr "mode" "<MODE>")])
3192 (define_expand "ior<mode>3"
3193   [(set (match_operand:GPR 0 "register_operand")
3194         (ior:GPR (match_operand:GPR 1 "register_operand")
3195                  (match_operand:GPR 2 "uns_arith_operand")))]
3196   ""
3198   if (TARGET_MIPS16)
3199     operands[2] = force_reg (<MODE>mode, operands[2]);
3202 (define_insn "*ior<mode>3"
3203   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3204         (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3205                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3206   "!TARGET_MIPS16"
3207   "@
3208    or\t%0,%1,%2
3209    or\t%0,%1,%2
3210    ori\t%0,%1,%x2"
3211   [(set_attr "alu_type" "or")
3212    (set_attr "compression" "micromips,*,*")
3213    (set_attr "mode" "<MODE>")])
3215 (define_insn "*ior<mode>3_mips16"
3216   [(set (match_operand:GPR 0 "register_operand" "=d")
3217         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3218                  (match_operand:GPR 2 "register_operand" "d")))]
3219   "TARGET_MIPS16"
3220   "or\t%0,%2"
3221   [(set_attr "alu_type" "or")
3222    (set_attr "mode" "<MODE>")])
3224 (define_expand "xor<mode>3"
3225   [(set (match_operand:GPR 0 "register_operand")
3226         (xor:GPR (match_operand:GPR 1 "register_operand")
3227                  (match_operand:GPR 2 "uns_arith_operand")))]
3228   ""
3229   "")
3231 (define_insn "*xor<mode>3"
3232   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3233         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3234                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3235   "!TARGET_MIPS16"
3236   "@
3237    xor\t%0,%1,%2
3238    xor\t%0,%1,%2
3239    xori\t%0,%1,%x2"
3240   [(set_attr "alu_type" "xor")
3241    (set_attr "compression" "micromips,*,*")
3242    (set_attr "mode" "<MODE>")])
3244 (define_insn "*xor<mode>3_mips16"
3245   [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3246         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3247                  (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3248   "TARGET_MIPS16"
3249   "@
3250    xor\t%0,%2
3251    cmpi\t%1,%2
3252    cmpi\t%1,%2
3253    cmp\t%1,%2"
3254   [(set_attr "alu_type" "xor")
3255    (set_attr "mode" "<MODE>")
3256    (set_attr "extended_mips16" "no,no,yes,no")])
3258 (define_insn "*nor<mode>3"
3259   [(set (match_operand:GPR 0 "register_operand" "=d")
3260         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3261                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3262   "!TARGET_MIPS16"
3263   "nor\t%0,%1,%2"
3264   [(set_attr "alu_type" "nor")
3265    (set_attr "mode" "<MODE>")])
3268 ;;  ....................
3270 ;;      TRUNCATION
3272 ;;  ....................
3276 (define_insn "truncdfsf2"
3277   [(set (match_operand:SF 0 "register_operand" "=f")
3278         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3279   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3280   "cvt.s.d\t%0,%1"
3281   [(set_attr "type"     "fcvt")
3282    (set_attr "cnv_mode" "D2S")   
3283    (set_attr "mode"     "SF")])
3285 ;; Integer truncation patterns.  Truncating SImode values to smaller
3286 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3287 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3288 ;; need to make sure that the lower 32 bits are properly sign-extended
3289 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3290 ;; smaller than SImode is equivalent to two separate truncations:
3292 ;;                        A       B
3293 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3294 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3296 ;; Step A needs a real instruction but step B does not.
3298 (define_insn "truncdi<mode>2"
3299   [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3300         (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3301   "TARGET_64BIT"
3302   "@
3303     sll\t%0,%1,0
3304     <store>\t%1,%0"
3305   [(set_attr "move_type" "sll0,store")
3306    (set_attr "mode" "SI")])
3308 ;; Combiner patterns to optimize shift/truncate combinations.
3310 (define_insn "*ashr_trunc<mode>"
3311   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3312         (truncate:SUBDI
3313           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3314                        (match_operand:DI 2 "const_arith_operand" ""))))]
3315   "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3316   "dsra\t%0,%1,%2"
3317   [(set_attr "type" "shift")
3318    (set_attr "mode" "<MODE>")])
3320 (define_insn "*lshr32_trunc<mode>"
3321   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3322         (truncate:SUBDI
3323           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3324                        (const_int 32))))]
3325   "TARGET_64BIT && !TARGET_MIPS16"
3326   "dsra\t%0,%1,32"
3327   [(set_attr "type" "shift")
3328    (set_attr "mode" "<MODE>")])
3330 ;; Logical shift by more than 32 results in proper SI values so truncation is
3331 ;; removed by the middle end.  Note that a logical shift by 32 is handled by
3332 ;; the previous pattern.
3333 (define_insn "*<optab>_trunc<mode>_exts"
3334   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3335         (truncate:SUBDI
3336          (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3337                          (match_operand:DI 2 "const_arith_operand" ""))))]
3338   "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3339   "exts\t%0,%1,%2,31"
3340   [(set_attr "type" "arith")
3341    (set_attr "mode" "<MODE>")])
3344 ;;  ....................
3346 ;;      ZERO EXTENSION
3348 ;;  ....................
3350 ;; Extension insns.
3352 (define_expand "zero_extendsidi2"
3353   [(set (match_operand:DI 0 "register_operand")
3354         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3355   "TARGET_64BIT")
3357 (define_insn_and_split "*zero_extendsidi2"
3358   [(set (match_operand:DI 0 "register_operand" "=d,d")
3359         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3360   "TARGET_64BIT && !ISA_HAS_EXT_INS"
3361   "@
3362    #
3363    lwu\t%0,%1"
3364   "&& reload_completed && REG_P (operands[1])"
3365   [(set (match_dup 0)
3366         (ashift:DI (match_dup 1) (const_int 32)))
3367    (set (match_dup 0)
3368         (lshiftrt:DI (match_dup 0) (const_int 32)))]
3369   { operands[1] = gen_lowpart (DImode, operands[1]); }
3370   [(set_attr "move_type" "shift_shift,load")
3371    (set_attr "mode" "DI")])
3373 (define_insn "*zero_extendsidi2_dext"
3374   [(set (match_operand:DI 0 "register_operand" "=d,d")
3375         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3376   "TARGET_64BIT && ISA_HAS_EXT_INS"
3377   "@
3378    dext\t%0,%1,0,32
3379    lwu\t%0,%1"
3380   [(set_attr "move_type" "arith,load")
3381    (set_attr "mode" "DI")])
3383 ;; See the comment before the *and<mode>3 pattern why this is generated by
3384 ;; combine.
3386 (define_split
3387   [(set (match_operand:DI 0 "register_operand")
3388         (and:DI (match_operand:DI 1 "register_operand")
3389                 (const_int 4294967295)))]
3390   "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3391   [(set (match_dup 0)
3392         (ashift:DI (match_dup 1) (const_int 32)))
3393    (set (match_dup 0)
3394         (lshiftrt:DI (match_dup 0) (const_int 32)))])
3396 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3397   [(set (match_operand:GPR 0 "register_operand")
3398         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3399   ""
3401   if (TARGET_MIPS16 && !GENERATE_MIPS16E
3402       && !memory_operand (operands[1], <SHORT:MODE>mode))
3403     {
3404       emit_insn (gen_and<GPR:mode>3 (operands[0],
3405                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
3406                                      force_reg (<GPR:MODE>mode,
3407                                                 GEN_INT (<SHORT:mask>))));
3408       DONE;
3409     }
3412 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3413   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3414         (zero_extend:GPR
3415              (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3416   "!TARGET_MIPS16"
3417   "@
3418    andi\t%0,%1,<SHORT:mask>
3419    andi\t%0,%1,<SHORT:mask>
3420    l<SHORT:size>u\t%0,%1"
3421   [(set_attr "move_type" "andi,andi,load")
3422    (set_attr "compression" "micromips,*,*")
3423    (set_attr "mode" "<GPR:MODE>")])
3425 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3426   [(set (match_operand:GPR 0 "register_operand" "=d")
3427         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3428   "GENERATE_MIPS16E"
3429   "ze<SHORT:size>\t%0"
3430   ;; This instruction is effectively a special encoding of ANDI.
3431   [(set_attr "move_type" "andi")
3432    (set_attr "mode" "<GPR:MODE>")])
3434 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3435   [(set (match_operand:GPR 0 "register_operand" "=d")
3436         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3437   "TARGET_MIPS16"
3438   "l<SHORT:size>u\t%0,%1"
3439   [(set_attr "move_type" "load")
3440    (set_attr "mode" "<GPR:MODE>")])
3442 (define_expand "zero_extendqihi2"
3443   [(set (match_operand:HI 0 "register_operand")
3444         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3445   ""
3447   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3448     {
3449       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3450                                        operands[1]));
3451       DONE;
3452     }
3455 (define_insn "*zero_extendqihi2"
3456   [(set (match_operand:HI 0 "register_operand" "=d,d")
3457         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3458   "!TARGET_MIPS16"
3459   "@
3460    andi\t%0,%1,0x00ff
3461    lbu\t%0,%1"
3462   [(set_attr "move_type" "andi,load")
3463    (set_attr "mode" "HI")])
3465 (define_insn "*zero_extendqihi2_mips16"
3466   [(set (match_operand:HI 0 "register_operand" "=d")
3467         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3468   "TARGET_MIPS16"
3469   "lbu\t%0,%1"
3470   [(set_attr "move_type" "load")
3471    (set_attr "mode" "HI")])
3473 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3475 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3476   [(set (match_operand:GPR 0 "register_operand" "=d")
3477         (zero_extend:GPR
3478             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3479   "TARGET_64BIT && !TARGET_MIPS16"
3481   operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3482   return "andi\t%0,%1,%x2";
3484   [(set_attr "alu_type" "and")
3485    (set_attr "mode" "<GPR:MODE>")])
3487 (define_insn "*zero_extendhi_truncqi"
3488   [(set (match_operand:HI 0 "register_operand" "=d")
3489         (zero_extend:HI
3490             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3491   "TARGET_64BIT && !TARGET_MIPS16"
3492   "andi\t%0,%1,0xff"
3493   [(set_attr "alu_type" "and")
3494    (set_attr "mode" "HI")])
3497 ;;  ....................
3499 ;;      SIGN EXTENSION
3501 ;;  ....................
3503 ;; Extension insns.
3504 ;; Those for integer source operand are ordered widest source type first.
3506 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3507 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3508 ;; and truncdisi2).  We can therefore get rid of register->register
3509 ;; instructions if we constrain the source to be in the same register as
3510 ;; the destination.
3512 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3513 ;; we split them into nothing before the post-reload scheduler runs.
3514 ;; These alternatives therefore have type "move" in order to reflect
3515 ;; what happens if the two pre-reload operands cannot be tied, and are
3516 ;; instead allocated two separate GPRs.  We don't distinguish between
3517 ;; the GPR and LO cases because we don't usually know during pre-reload
3518 ;; scheduling whether an operand will be LO or not.
3519 (define_insn_and_split "extendsidi2"
3520   [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3521         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3522   "TARGET_64BIT"
3523   "@
3524    #
3525    #
3526    lw\t%0,%1"
3527   "&& reload_completed && register_operand (operands[1], VOIDmode)"
3528   [(const_int 0)]
3530   emit_note (NOTE_INSN_DELETED);
3531   DONE;
3533   [(set_attr "move_type" "move,move,load")
3534    (set_attr "mode" "DI")])
3536 (define_expand "extend<SHORT:mode><GPR:mode>2"
3537   [(set (match_operand:GPR 0 "register_operand")
3538         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3539   "")
3541 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3542   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3543         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3544   "GENERATE_MIPS16E"
3545   "@
3546    se<SHORT:size>\t%0
3547    l<SHORT:size>\t%0,%1"
3548   [(set_attr "move_type" "signext,load")
3549    (set_attr "mode" "<GPR:MODE>")])
3551 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3552   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3553         (sign_extend:GPR
3554              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3555   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3556   "@
3557    #
3558    l<SHORT:size>\t%0,%1"
3559   "&& reload_completed && REG_P (operands[1])"
3560   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3561    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3563   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3564   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3565                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3567   [(set_attr "move_type" "shift_shift,load")
3568    (set_attr "mode" "<GPR:MODE>")])
3570 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3571   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3572         (sign_extend:GPR
3573              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3574   "ISA_HAS_SEB_SEH"
3575   "@
3576    se<SHORT:size>\t%0,%1
3577    l<SHORT:size>\t%0,%1"
3578   [(set_attr "move_type" "signext,load")
3579    (set_attr "mode" "<GPR:MODE>")])
3581 (define_expand "extendqihi2"
3582   [(set (match_operand:HI 0 "register_operand")
3583         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3584   "")
3586 (define_insn "*extendqihi2_mips16e"
3587   [(set (match_operand:HI 0 "register_operand" "=d,d")
3588         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3589   "GENERATE_MIPS16E"
3590   "@
3591    seb\t%0
3592    lb\t%0,%1"
3593   [(set_attr "move_type" "signext,load")
3594    (set_attr "mode" "SI")])
3596 (define_insn_and_split "*extendqihi2"
3597   [(set (match_operand:HI 0 "register_operand" "=d,d")
3598         (sign_extend:HI
3599              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3600   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3601   "@
3602    #
3603    lb\t%0,%1"
3604   "&& reload_completed && REG_P (operands[1])"
3605   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3606    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3608   operands[0] = gen_lowpart (SImode, operands[0]);
3609   operands[1] = gen_lowpart (SImode, operands[1]);
3610   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3611                          - GET_MODE_BITSIZE (QImode));
3613   [(set_attr "move_type" "shift_shift,load")
3614    (set_attr "mode" "SI")])
3616 (define_insn "*extendqihi2_seb"
3617   [(set (match_operand:HI 0 "register_operand" "=d,d")
3618         (sign_extend:HI
3619              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3620   "ISA_HAS_SEB_SEH"
3621   "@
3622    seb\t%0,%1
3623    lb\t%0,%1"
3624   [(set_attr "move_type" "signext,load")
3625    (set_attr "mode" "SI")])
3627 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
3628 ;; use the shift/truncate patterns.
3630 (define_insn_and_split "*extenddi_truncate<mode>"
3631   [(set (match_operand:DI 0 "register_operand" "=d")
3632         (sign_extend:DI
3633             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3634   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3635   "#"
3636   "&& reload_completed"
3637   [(set (match_dup 2)
3638         (ashift:DI (match_dup 1)
3639                    (match_dup 3)))
3640    (set (match_dup 0)
3641         (ashiftrt:DI (match_dup 2)
3642                      (match_dup 3)))]
3644   operands[2] = gen_lowpart (DImode, operands[0]);
3645   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3647   [(set_attr "move_type" "shift_shift")
3648    (set_attr "mode" "DI")])
3650 (define_insn_and_split "*extendsi_truncate<mode>"
3651   [(set (match_operand:SI 0 "register_operand" "=d")
3652         (sign_extend:SI
3653             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3654   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3655   "#"
3656   "&& reload_completed"
3657   [(set (match_dup 2)
3658         (ashift:DI (match_dup 1)
3659                    (match_dup 3)))
3660    (set (match_dup 0)
3661         (truncate:SI (ashiftrt:DI (match_dup 2)
3662                                   (match_dup 3))))]
3664   operands[2] = gen_lowpart (DImode, operands[0]);
3665   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3667   [(set_attr "move_type" "shift_shift")
3668    (set_attr "mode" "SI")])
3670 (define_insn_and_split "*extendhi_truncateqi"
3671   [(set (match_operand:HI 0 "register_operand" "=d")
3672         (sign_extend:HI
3673             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3674   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3675   "#"
3676   "&& reload_completed"
3677   [(set (match_dup 2)
3678         (ashift:DI (match_dup 1)
3679                    (const_int 56)))
3680    (set (match_dup 0)
3681         (truncate:HI (ashiftrt:DI (match_dup 2)
3682                                   (const_int 56))))]
3684   operands[2] = gen_lowpart (DImode, operands[0]);
3686   [(set_attr "move_type" "shift_shift")
3687    (set_attr "mode" "SI")])
3689 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3690   [(set (match_operand:GPR 0 "register_operand" "=d")
3691         (sign_extend:GPR
3692             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3693   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3695   operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3696   return "exts\t%0,%1,0,%m2";
3698   [(set_attr "type" "arith")
3699    (set_attr "mode" "<GPR:MODE>")])
3701 (define_insn "*extendhi_truncateqi_exts"
3702   [(set (match_operand:HI 0 "register_operand" "=d")
3703         (sign_extend:HI
3704             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3705   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3706   "exts\t%0,%1,0,7"
3707   [(set_attr "type" "arith")
3708    (set_attr "mode" "SI")])
3710 (define_insn "extendsfdf2"
3711   [(set (match_operand:DF 0 "register_operand" "=f")
3712         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3713   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3714   "cvt.d.s\t%0,%1"
3715   [(set_attr "type"     "fcvt")
3716    (set_attr "cnv_mode" "S2D")   
3717    (set_attr "mode"     "DF")])
3720 ;;  ....................
3722 ;;      CONVERSIONS
3724 ;;  ....................
3726 (define_expand "fix_truncdfsi2"
3727   [(set (match_operand:SI 0 "register_operand")
3728         (fix:SI (match_operand:DF 1 "register_operand")))]
3729   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3731   if (!ISA_HAS_TRUNC_W)
3732     {
3733       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3734       DONE;
3735     }
3738 (define_insn "fix_truncdfsi2_insn"
3739   [(set (match_operand:SI 0 "register_operand" "=f")
3740         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3741   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3742   "trunc.w.d %0,%1"
3743   [(set_attr "type"     "fcvt")
3744    (set_attr "mode"     "DF")
3745    (set_attr "cnv_mode" "D2I")])
3747 (define_insn "fix_truncdfsi2_macro"
3748   [(set (match_operand:SI 0 "register_operand" "=f")
3749         (fix:SI (match_operand:DF 1 "register_operand" "f")))
3750    (clobber (match_scratch:DF 2 "=d"))]
3751   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3753   if (mips_nomacro.nesting_level > 0)
3754     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3755   else
3756     return "trunc.w.d %0,%1,%2";
3758   [(set_attr "type"     "fcvt")
3759    (set_attr "mode"     "DF")
3760    (set_attr "cnv_mode" "D2I")
3761    (set_attr "insn_count" "9")])
3763 (define_expand "fix_truncsfsi2"
3764   [(set (match_operand:SI 0 "register_operand")
3765         (fix:SI (match_operand:SF 1 "register_operand")))]
3766   "TARGET_HARD_FLOAT"
3768   if (!ISA_HAS_TRUNC_W)
3769     {
3770       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3771       DONE;
3772     }
3775 (define_insn "fix_truncsfsi2_insn"
3776   [(set (match_operand:SI 0 "register_operand" "=f")
3777         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3778   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3779   "trunc.w.s %0,%1"
3780   [(set_attr "type"     "fcvt")
3781    (set_attr "mode"     "SF")
3782    (set_attr "cnv_mode" "S2I")])
3784 (define_insn "fix_truncsfsi2_macro"
3785   [(set (match_operand:SI 0 "register_operand" "=f")
3786         (fix:SI (match_operand:SF 1 "register_operand" "f")))
3787    (clobber (match_scratch:SF 2 "=d"))]
3788   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3790   if (mips_nomacro.nesting_level > 0)
3791     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3792   else
3793     return "trunc.w.s %0,%1,%2";
3795   [(set_attr "type"     "fcvt")
3796    (set_attr "mode"     "SF")
3797    (set_attr "cnv_mode" "S2I")
3798    (set_attr "insn_count" "9")])
3801 (define_insn "fix_truncdfdi2"
3802   [(set (match_operand:DI 0 "register_operand" "=f")
3803         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3804   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3805   "trunc.l.d %0,%1"
3806   [(set_attr "type"     "fcvt")
3807    (set_attr "mode"     "DF")
3808    (set_attr "cnv_mode" "D2I")])
3811 (define_insn "fix_truncsfdi2"
3812   [(set (match_operand:DI 0 "register_operand" "=f")
3813         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3814   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3815   "trunc.l.s %0,%1"
3816   [(set_attr "type"     "fcvt")
3817    (set_attr "mode"     "SF")
3818    (set_attr "cnv_mode" "S2I")])
3821 (define_insn "floatsidf2"
3822   [(set (match_operand:DF 0 "register_operand" "=f")
3823         (float:DF (match_operand:SI 1 "register_operand" "f")))]
3824   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3825   "cvt.d.w\t%0,%1"
3826   [(set_attr "type"     "fcvt")
3827    (set_attr "mode"     "DF")
3828    (set_attr "cnv_mode" "I2D")])
3831 (define_insn "floatdidf2"
3832   [(set (match_operand:DF 0 "register_operand" "=f")
3833         (float:DF (match_operand:DI 1 "register_operand" "f")))]
3834   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3835   "cvt.d.l\t%0,%1"
3836   [(set_attr "type"     "fcvt")
3837    (set_attr "mode"     "DF")
3838    (set_attr "cnv_mode" "I2D")])
3841 (define_insn "floatsisf2"
3842   [(set (match_operand:SF 0 "register_operand" "=f")
3843         (float:SF (match_operand:SI 1 "register_operand" "f")))]
3844   "TARGET_HARD_FLOAT"
3845   "cvt.s.w\t%0,%1"
3846   [(set_attr "type"     "fcvt")
3847    (set_attr "mode"     "SF")
3848    (set_attr "cnv_mode" "I2S")])
3851 (define_insn "floatdisf2"
3852   [(set (match_operand:SF 0 "register_operand" "=f")
3853         (float:SF (match_operand:DI 1 "register_operand" "f")))]
3854   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3855   "cvt.s.l\t%0,%1"
3856   [(set_attr "type"     "fcvt")
3857    (set_attr "mode"     "SF")
3858    (set_attr "cnv_mode" "I2S")])
3861 (define_expand "fixuns_truncdfsi2"
3862   [(set (match_operand:SI 0 "register_operand")
3863         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3864   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3866   rtx reg1 = gen_reg_rtx (DFmode);
3867   rtx reg2 = gen_reg_rtx (DFmode);
3868   rtx reg3 = gen_reg_rtx (SImode);
3869   rtx_code_label *label1 = gen_label_rtx ();
3870   rtx_code_label *label2 = gen_label_rtx ();
3871   rtx test;
3872   REAL_VALUE_TYPE offset;
3874   real_2expN (&offset, 31, DFmode);
3876   if (reg1)                     /* Turn off complaints about unreached code.  */
3877     {
3878       mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3879       do_pending_stack_adjust ();
3881       test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3882       emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3884       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3885       emit_jump_insn (gen_rtx_SET (pc_rtx,
3886                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
3887       emit_barrier ();
3889       emit_label (label1);
3890       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3891       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3892                                      (BITMASK_HIGH, SImode)));
3894       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3895       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3897       emit_label (label2);
3899       /* Allow REG_NOTES to be set on last insn (labels don't have enough
3900          fields, and can't be used for REG_NOTES anyway).  */
3901       emit_use (stack_pointer_rtx);
3902       DONE;
3903     }
3907 (define_expand "fixuns_truncdfdi2"
3908   [(set (match_operand:DI 0 "register_operand")
3909         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3910   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3912   rtx reg1 = gen_reg_rtx (DFmode);
3913   rtx reg2 = gen_reg_rtx (DFmode);
3914   rtx reg3 = gen_reg_rtx (DImode);
3915   rtx_code_label *label1 = gen_label_rtx ();
3916   rtx_code_label *label2 = gen_label_rtx ();
3917   rtx test;
3918   REAL_VALUE_TYPE offset;
3920   real_2expN (&offset, 63, DFmode);
3922   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3923   do_pending_stack_adjust ();
3925   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3926   emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3928   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3929   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
3930   emit_barrier ();
3932   emit_label (label1);
3933   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3934   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3935   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3937   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3938   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3940   emit_label (label2);
3942   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3943      fields, and can't be used for REG_NOTES anyway).  */
3944   emit_use (stack_pointer_rtx);
3945   DONE;
3949 (define_expand "fixuns_truncsfsi2"
3950   [(set (match_operand:SI 0 "register_operand")
3951         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3952   "TARGET_HARD_FLOAT"
3954   rtx reg1 = gen_reg_rtx (SFmode);
3955   rtx reg2 = gen_reg_rtx (SFmode);
3956   rtx reg3 = gen_reg_rtx (SImode);
3957   rtx_code_label *label1 = gen_label_rtx ();
3958   rtx_code_label *label2 = gen_label_rtx ();
3959   rtx test;
3960   REAL_VALUE_TYPE offset;
3962   real_2expN (&offset, 31, SFmode);
3964   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3965   do_pending_stack_adjust ();
3967   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3968   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3970   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3971   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
3972   emit_barrier ();
3974   emit_label (label1);
3975   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3976   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3977                                  (BITMASK_HIGH, SImode)));
3979   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3980   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3982   emit_label (label2);
3984   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3985      fields, and can't be used for REG_NOTES anyway).  */
3986   emit_use (stack_pointer_rtx);
3987   DONE;
3991 (define_expand "fixuns_truncsfdi2"
3992   [(set (match_operand:DI 0 "register_operand")
3993         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3994   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3996   rtx reg1 = gen_reg_rtx (SFmode);
3997   rtx reg2 = gen_reg_rtx (SFmode);
3998   rtx reg3 = gen_reg_rtx (DImode);
3999   rtx_code_label *label1 = gen_label_rtx ();
4000   rtx_code_label *label2 = gen_label_rtx ();
4001   rtx test;
4002   REAL_VALUE_TYPE offset;
4004   real_2expN (&offset, 63, SFmode);
4006   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4007   do_pending_stack_adjust ();
4009   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4010   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4012   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4013   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4014   emit_barrier ();
4016   emit_label (label1);
4017   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4018   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4019   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4021   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4022   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4024   emit_label (label2);
4026   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4027      fields, and can't be used for REG_NOTES anyway).  */
4028   emit_use (stack_pointer_rtx);
4029   DONE;
4033 ;;  ....................
4035 ;;      DATA MOVEMENT
4037 ;;  ....................
4039 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4041 (define_expand "extvmisalign<mode>"
4042   [(set (match_operand:GPR 0 "register_operand")
4043         (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4044                           (match_operand 2 "const_int_operand")
4045                           (match_operand 3 "const_int_operand")))]
4046   "ISA_HAS_LWL_LWR"
4048   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4049                                          INTVAL (operands[2]),
4050                                          INTVAL (operands[3]),
4051                                          /*unsigned=*/ false))
4052     DONE;
4053   else
4054     FAIL;
4057 (define_expand "extv<mode>"
4058   [(set (match_operand:GPR 0 "register_operand")
4059         (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4060                           (match_operand 2 "const_int_operand")
4061                           (match_operand 3 "const_int_operand")))]
4062   "ISA_HAS_EXTS"
4064   if (UINTVAL (operands[2]) > 32)
4065     FAIL;
4068 (define_insn "*extv<mode>"
4069   [(set (match_operand:GPR 0 "register_operand" "=d")
4070         (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4071                           (match_operand 2 "const_int_operand" "")
4072                           (match_operand 3 "const_int_operand" "")))]
4073   "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4074   "exts\t%0,%1,%3,%m2"
4075   [(set_attr "type"     "arith")
4076    (set_attr "mode"     "<MODE>")])
4078 (define_expand "extzvmisalign<mode>"
4079   [(set (match_operand:GPR 0 "register_operand")
4080         (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4081                           (match_operand 2 "const_int_operand")
4082                           (match_operand 3 "const_int_operand")))]
4083   "ISA_HAS_LWL_LWR"
4085   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4086                                          INTVAL (operands[2]),
4087                                          INTVAL (operands[3]),
4088                                          /*unsigned=*/ true))
4089     DONE;
4090   else
4091     FAIL;
4094 (define_expand "extzv<mode>"
4095   [(set (match_operand:GPR 0 "register_operand")
4096         (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4097                           (match_operand 2 "const_int_operand")
4098                           (match_operand 3 "const_int_operand")))]
4099   ""
4101   if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4102                            INTVAL (operands[3])))
4103     FAIL;
4106 (define_insn "*extzv<mode>"
4107   [(set (match_operand:GPR 0 "register_operand" "=d")
4108         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4109                           (match_operand 2 "const_int_operand" "")
4110                           (match_operand 3 "const_int_operand" "")))]
4111   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4112                        INTVAL (operands[3]))"
4113   "<d>ext\t%0,%1,%3,%2"
4114   [(set_attr "type"     "arith")
4115    (set_attr "mode"     "<MODE>")])
4117 (define_insn "*extzv_truncsi_exts"
4118   [(set (match_operand:SI 0 "register_operand" "=d")
4119         (truncate:SI
4120          (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4121                           (match_operand 2 "const_int_operand" "")
4122                           (match_operand 3 "const_int_operand" ""))))]
4123   "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4124   "exts\t%0,%1,%3,31"
4125   [(set_attr "type"     "arith")
4126    (set_attr "mode"     "SI")])
4129 (define_expand "insvmisalign<mode>"
4130   [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4131                           (match_operand 1 "const_int_operand")
4132                           (match_operand 2 "const_int_operand"))
4133         (match_operand:GPR 3 "reg_or_0_operand"))]
4134   "ISA_HAS_LWL_LWR"
4136   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4137                                           INTVAL (operands[1]),
4138                                           INTVAL (operands[2])))
4139     DONE;
4140   else
4141     FAIL;
4144 (define_expand "insv<mode>"
4145   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4146                           (match_operand 1 "const_int_operand")
4147                           (match_operand 2 "const_int_operand"))
4148         (match_operand:GPR 3 "reg_or_0_operand"))]
4149   ""
4151   if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4152                            INTVAL (operands[2])))
4153     FAIL;
4156 (define_insn "*insv<mode>"
4157   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4158                           (match_operand:SI 1 "const_int_operand" "")
4159                           (match_operand:SI 2 "const_int_operand" ""))
4160         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4161   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4162                        INTVAL (operands[2]))"
4163   "<d>ins\t%0,%z3,%2,%1"
4164   [(set_attr "type"     "arith")
4165    (set_attr "mode"     "<MODE>")])
4167 ;; Combiner pattern for cins (clear and insert bit field).  We can
4168 ;; implement mask-and-shift-left operation with this.  Note that if
4169 ;; the upper bit of the mask is set in an SImode operation, the mask
4170 ;; itself will be sign-extended.  mask_low_and_shift_len will
4171 ;; therefore be greater than our threshold of 32.
4173 (define_insn "*cins<mode>"
4174   [(set (match_operand:GPR 0 "register_operand" "=d")
4175         (and:GPR
4176          (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4177                      (match_operand:GPR 2 "const_int_operand" ""))
4178          (match_operand:GPR 3 "const_int_operand" "")))]
4179   "ISA_HAS_CINS
4180    && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4182   operands[3] =
4183     GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4184   return "cins\t%0,%1,%2,%m3";
4186   [(set_attr "type"     "shift")
4187    (set_attr "mode"     "<MODE>")])
4189 ;; Unaligned word moves generated by the bit field patterns.
4191 ;; As far as the rtl is concerned, both the left-part and right-part
4192 ;; instructions can access the whole field.  However, the real operand
4193 ;; refers to just the first or the last byte (depending on endianness).
4194 ;; We therefore use two memory operands to each instruction, one to
4195 ;; describe the rtl effect and one to use in the assembly output.
4197 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4198 ;; This allows us to use the standard length calculations for the "load"
4199 ;; and "store" type attributes.
4201 (define_insn "mov_<load>l"
4202   [(set (match_operand:GPR 0 "register_operand" "=d")
4203         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4204                      (match_operand:QI 2 "memory_operand" "ZC")]
4205                     UNSPEC_LOAD_LEFT))]
4206   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4207   "<load>l\t%0,%2"
4208   [(set_attr "move_type" "load")
4209    (set_attr "mode" "<MODE>")])
4211 (define_insn "mov_<load>r"
4212   [(set (match_operand:GPR 0 "register_operand" "=d")
4213         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4214                      (match_operand:QI 2 "memory_operand" "ZC")
4215                      (match_operand:GPR 3 "register_operand" "0")]
4216                     UNSPEC_LOAD_RIGHT))]
4217   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4218   "<load>r\t%0,%2"
4219   [(set_attr "move_type" "load")
4220    (set_attr "mode" "<MODE>")])
4222 (define_insn "mov_<store>l"
4223   [(set (match_operand:BLK 0 "memory_operand" "=m")
4224         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4225                      (match_operand:QI 2 "memory_operand" "ZC")]
4226                     UNSPEC_STORE_LEFT))]
4227   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4228   "<store>l\t%z1,%2"
4229   [(set_attr "move_type" "store")
4230    (set_attr "mode" "<MODE>")])
4232 (define_insn "mov_<store>r"
4233   [(set (match_operand:BLK 0 "memory_operand" "+m")
4234         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4235                      (match_operand:QI 2 "memory_operand" "ZC")
4236                      (match_dup 0)]
4237                     UNSPEC_STORE_RIGHT))]
4238   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4239   "<store>r\t%z1,%2"
4240   [(set_attr "move_type" "store")
4241    (set_attr "mode" "<MODE>")])
4243 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4244 ;; The required value is:
4246 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4248 ;; which translates to:
4250 ;;      lui     op0,%highest(op1)
4251 ;;      daddiu  op0,op0,%higher(op1)
4252 ;;      dsll    op0,op0,16
4253 ;;      daddiu  op0,op0,%hi(op1)
4254 ;;      dsll    op0,op0,16
4256 ;; The split is deferred until after flow2 to allow the peephole2 below
4257 ;; to take effect.
4258 (define_insn_and_split "*lea_high64"
4259   [(set (match_operand:DI 0 "register_operand" "=d")
4260         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4261   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4262   "#"
4263   "&& epilogue_completed"
4264   [(set (match_dup 0) (high:DI (match_dup 2)))
4265    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4266    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4267    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4268    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4270   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4271   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4273   [(set_attr "insn_count" "5")])
4275 ;; Use a scratch register to reduce the latency of the above pattern
4276 ;; on superscalar machines.  The optimized sequence is:
4278 ;;      lui     op1,%highest(op2)
4279 ;;      lui     op0,%hi(op2)
4280 ;;      daddiu  op1,op1,%higher(op2)
4281 ;;      dsll32  op1,op1,0
4282 ;;      daddu   op1,op1,op0
4283 (define_peephole2
4284   [(set (match_operand:DI 1 "d_operand")
4285         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4286    (match_scratch:DI 0 "d")]
4287   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4288   [(set (match_dup 1) (high:DI (match_dup 3)))
4289    (set (match_dup 0) (high:DI (match_dup 4)))
4290    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4291    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4292    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4294   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4295   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4298 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4299 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
4300 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4301 ;; used once.  We can then use the sequence:
4303 ;;      lui     op0,%highest(op1)
4304 ;;      lui     op2,%hi(op1)
4305 ;;      daddiu  op0,op0,%higher(op1)
4306 ;;      daddiu  op2,op2,%lo(op1)
4307 ;;      dsll32  op0,op0,0
4308 ;;      daddu   op0,op0,op2
4310 ;; which takes 4 cycles on most superscalar targets.
4311 (define_insn_and_split "*lea64"
4312   [(set (match_operand:DI 0 "register_operand" "=d")
4313         (match_operand:DI 1 "absolute_symbolic_operand" ""))
4314    (clobber (match_scratch:DI 2 "=&d"))]
4315   "!TARGET_MIPS16
4316    && TARGET_EXPLICIT_RELOCS
4317    && ABI_HAS_64BIT_SYMBOLS
4318    && cse_not_expected"
4319   "#"
4320   "&& reload_completed"
4321   [(set (match_dup 0) (high:DI (match_dup 3)))
4322    (set (match_dup 2) (high:DI (match_dup 4)))
4323    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4324    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4325    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4326    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4328   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4329   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4331   [(set_attr "insn_count" "6")])
4333 ;; Split HIGHs into:
4335 ;;      li op0,%hi(sym)
4336 ;;      sll op0,16
4338 ;; on MIPS16 targets.
4339 (define_split
4340   [(set (match_operand:P 0 "d_operand")
4341         (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4342   "TARGET_MIPS16 && reload_completed"
4343   [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4344    (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4346 (define_insn "*unshifted_high"
4347   [(set (match_operand:P 0 "d_operand" "=d")
4348         (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4349                   UNSPEC_UNSHIFTED_HIGH))]
4350   ""
4351   "li\t%0,%h1"
4352   [(set_attr "extended_mips16" "yes")])
4354 ;; Insns to fetch a symbol from a big GOT.
4356 (define_insn_and_split "*xgot_hi<mode>"
4357   [(set (match_operand:P 0 "register_operand" "=d")
4358         (high:P (match_operand:P 1 "got_disp_operand" "")))]
4359   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4360   "#"
4361   "&& reload_completed"
4362   [(set (match_dup 0) (high:P (match_dup 2)))
4363    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4365   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4366   operands[3] = pic_offset_table_rtx;
4368   [(set_attr "got" "xgot_high")
4369    (set_attr "mode" "<MODE>")])
4371 (define_insn_and_split "*xgot_lo<mode>"
4372   [(set (match_operand:P 0 "register_operand" "=d")
4373         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4374                   (match_operand:P 2 "got_disp_operand" "")))]
4375   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4376   "#"
4377   "&& reload_completed"
4378   [(set (match_dup 0)
4379         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4380   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4381   [(set_attr "got" "load")
4382    (set_attr "mode" "<MODE>")])
4384 ;; Insns to fetch a symbol from a normal GOT.
4386 (define_insn_and_split "*got_disp<mode>"
4387   [(set (match_operand:P 0 "register_operand" "=d")
4388         (match_operand:P 1 "got_disp_operand" ""))]
4389   "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4390   "#"
4391   "&& reload_completed"
4392   [(set (match_dup 0) (match_dup 2))]
4393   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4394   [(set_attr "got" "load")
4395    (set_attr "mode" "<MODE>")])
4397 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4399 (define_insn_and_split "*got_page<mode>"
4400   [(set (match_operand:P 0 "register_operand" "=d")
4401         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4402   "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4403   "#"
4404   "&& reload_completed"
4405   [(set (match_dup 0) (match_dup 2))]
4406   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4407   [(set_attr "got" "load")
4408    (set_attr "mode" "<MODE>")])
4410 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4411 (define_expand "unspec_got_<mode>"
4412   [(unspec:P [(match_operand:P 0)
4413               (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4415 ;; Lower-level instructions for loading an address from the GOT.
4416 ;; We could use MEMs, but an unspec gives more optimization
4417 ;; opportunities.
4419 (define_insn "load_got<mode>"
4420   [(set (match_operand:P 0 "register_operand" "=d")
4421         (unspec:P [(match_operand:P 1 "register_operand" "d")
4422                    (match_operand:P 2 "immediate_operand" "")]
4423                   UNSPEC_LOAD_GOT))]
4424   ""
4425   "<load>\t%0,%R2(%1)"
4426   [(set_attr "got" "load")
4427    (set_attr "mode" "<MODE>")])
4429 ;; Instructions for adding the low 16 bits of an address to a register.
4430 ;; Operand 2 is the address: mips_print_operand works out which relocation
4431 ;; should be applied.
4433 (define_insn "*low<mode>"
4434   [(set (match_operand:P 0 "register_operand" "=d")
4435         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4436                   (match_operand:P 2 "immediate_operand" "")))]
4437   "!TARGET_MIPS16"
4438   "<d>addiu\t%0,%1,%R2"
4439   [(set_attr "alu_type" "add")
4440    (set_attr "mode" "<MODE>")])
4442 (define_insn "*low<mode>_mips16"
4443   [(set (match_operand:P 0 "register_operand" "=d")
4444         (lo_sum:P (match_operand:P 1 "register_operand" "0")
4445                   (match_operand:P 2 "immediate_operand" "")))]
4446   "TARGET_MIPS16"
4447   "<d>addiu\t%0,%R2"
4448   [(set_attr "alu_type" "add")
4449    (set_attr "mode" "<MODE>")
4450    (set_attr "extended_mips16" "yes")])
4452 ;; Expose MIPS16 uses of the global pointer after reload if the function
4453 ;; is responsible for setting up the register itself.
4454 (define_split
4455   [(set (match_operand:GPR 0 "d_operand")
4456         (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4457   "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4458   [(set (match_dup 0) (match_dup 1))]
4459   { operands[1] = pic_offset_table_rtx; })
4461 ;; Allow combine to split complex const_int load sequences, using operand 2
4462 ;; to store the intermediate results.  See move_operand for details.
4463 (define_split
4464   [(set (match_operand:GPR 0 "register_operand")
4465         (match_operand:GPR 1 "splittable_const_int_operand"))
4466    (clobber (match_operand:GPR 2 "register_operand"))]
4467   ""
4468   [(const_int 0)]
4470   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4471   DONE;
4474 ;; Likewise, for symbolic operands.
4475 (define_split
4476   [(set (match_operand:P 0 "register_operand")
4477         (match_operand:P 1))
4478    (clobber (match_operand:P 2 "register_operand"))]
4479   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4480   [(set (match_dup 0) (match_dup 3))]
4482   mips_split_symbol (operands[2], operands[1],
4483                      MAX_MACHINE_MODE, &operands[3]);
4486 ;; 64-bit integer moves
4488 ;; Unlike most other insns, the move insns can't be split with
4489 ;; different predicates, because register spilling and other parts of
4490 ;; the compiler, have memoized the insn number already.
4492 (define_expand "movdi"
4493   [(set (match_operand:DI 0 "")
4494         (match_operand:DI 1 ""))]
4495   ""
4497   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4498     DONE;
4501 ;; For mips16, we need a special case to handle storing $31 into
4502 ;; memory, since we don't have a constraint to match $31.  This
4503 ;; instruction can be generated by save_restore_insns.
4505 (define_insn "*mov<mode>_ra"
4506   [(set (match_operand:GPR 0 "stack_operand" "=m")
4507         (reg:GPR RETURN_ADDR_REGNUM))]
4508   "TARGET_MIPS16"
4509   "<store>\t$31,%0"
4510   [(set_attr "move_type" "store")
4511    (set_attr "mode" "<MODE>")])
4513 (define_insn "*movdi_32bit"
4514   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4515         (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"))]
4516   "!TARGET_64BIT && !TARGET_MIPS16
4517    && (register_operand (operands[0], DImode)
4518        || reg_or_0_operand (operands[1], DImode))"
4519   { return mips_output_move (operands[0], operands[1]); }
4520   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4521    (set (attr "mode")
4522         (if_then_else (eq_attr "move_type" "imul")
4523                       (const_string "SI")
4524                       (const_string "DI")))])
4526 (define_insn "*movdi_32bit_mips16"
4527   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4528         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4529   "!TARGET_64BIT && TARGET_MIPS16
4530    && (register_operand (operands[0], DImode)
4531        || register_operand (operands[1], DImode))"
4532   { return mips_output_move (operands[0], operands[1]); }
4533   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4534    (set_attr "mode" "DI")])
4536 (define_insn "*movdi_64bit"
4537   [(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")
4538         (match_operand:DI 1 "move_operand" "d,Yd,Yf,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4539   "TARGET_64BIT && !TARGET_MIPS16
4540    && (register_operand (operands[0], DImode)
4541        || reg_or_0_operand (operands[1], DImode))"
4542   { return mips_output_move (operands[0], operands[1]); }
4543   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4544    (set_attr "mode" "DI")])
4546 (define_insn "*movdi_64bit_mips16"
4547   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4548         (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4549   "TARGET_64BIT && TARGET_MIPS16
4550    && (register_operand (operands[0], DImode)
4551        || register_operand (operands[1], DImode))"
4552   { return mips_output_move (operands[0], operands[1]); }
4553   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4554    (set_attr "mode" "DI")])
4556 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4557 ;; when the original load is a 4 byte instruction but the add and the
4558 ;; load are 2 2 byte instructions.
4560 (define_split
4561   [(set (match_operand:DI 0 "d_operand")
4562         (mem:DI (plus:DI (match_dup 0)
4563                          (match_operand:DI 1 "const_int_operand"))))]
4564   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4565    && !TARGET_DEBUG_D_MODE
4566    && ((INTVAL (operands[1]) < 0
4567         && INTVAL (operands[1]) >= -0x10)
4568        || (INTVAL (operands[1]) >= 32 * 8
4569            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4570        || (INTVAL (operands[1]) >= 0
4571            && INTVAL (operands[1]) < 32 * 8
4572            && (INTVAL (operands[1]) & 7) != 0))"
4573   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4574    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4576   HOST_WIDE_INT val = INTVAL (operands[1]);
4578   if (val < 0)
4579     operands[2] = const0_rtx;
4580   else if (val >= 32 * 8)
4581     {
4582       int off = val & 7;
4584       operands[1] = GEN_INT (0x8 + off);
4585       operands[2] = GEN_INT (val - off - 0x8);
4586     }
4587   else
4588     {
4589       int off = val & 7;
4591       operands[1] = GEN_INT (off);
4592       operands[2] = GEN_INT (val - off);
4593     }
4596 ;; 32-bit Integer moves
4598 ;; Unlike most other insns, the move insns can't be split with
4599 ;; different predicates, because register spilling and other parts of
4600 ;; the compiler, have memoized the insn number already.
4602 (define_expand "mov<mode>"
4603   [(set (match_operand:IMOVE32 0 "")
4604         (match_operand:IMOVE32 1 ""))]
4605   ""
4607   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4608     DONE;
4611 ;; The difference between these two is whether or not ints are allowed
4612 ;; in FP registers (off by default, use -mdebugh to enable).
4614 (define_insn "*mov<mode>_internal"
4615   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,!u,!u,d,e,!u,!ks,d,ZS,ZT,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4616         (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!kbJ,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4617   "!TARGET_MIPS16
4618    && (register_operand (operands[0], <MODE>mode)
4619        || reg_or_0_operand (operands[1], <MODE>mode))"
4620   { return mips_output_move (operands[0], operands[1]); }
4621   [(set_attr "move_type" "move,move,const,const,const,load,load,load,store,store,store,mtc,fpload,mfc,fpstore,mfc,mtc,mtlo,mflo,mtc,fpload,mfc,fpstore")
4622    (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4623    (set_attr "mode" "SI")])
4625 (define_insn "*mov<mode>_mips16"
4626   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4627         (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4628   "TARGET_MIPS16
4629    && (register_operand (operands[0], <MODE>mode)
4630        || register_operand (operands[1], <MODE>mode))"
4631   { return mips_output_move (operands[0], operands[1]); }
4632   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4633    (set_attr "mode" "SI")])
4635 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4636 ;; when the original load is a 4 byte instruction but the add and the
4637 ;; load are 2 2 byte instructions.
4639 (define_split
4640   [(set (match_operand:SI 0 "d_operand")
4641         (mem:SI (plus:SI (match_dup 0)
4642                          (match_operand:SI 1 "const_int_operand"))))]
4643   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4644    && ((INTVAL (operands[1]) < 0
4645         && INTVAL (operands[1]) >= -0x80)
4646        || (INTVAL (operands[1]) >= 32 * 4
4647            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4648        || (INTVAL (operands[1]) >= 0
4649            && INTVAL (operands[1]) < 32 * 4
4650            && (INTVAL (operands[1]) & 3) != 0))"
4651   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4652    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4654   HOST_WIDE_INT val = INTVAL (operands[1]);
4656   if (val < 0)
4657     operands[2] = const0_rtx;
4658   else if (val >= 32 * 4)
4659     {
4660       int off = val & 3;
4662       operands[1] = GEN_INT (0x7c + off);
4663       operands[2] = GEN_INT (val - off - 0x7c);
4664     }
4665   else
4666     {
4667       int off = val & 3;
4669       operands[1] = GEN_INT (off);
4670       operands[2] = GEN_INT (val - off);
4671     }
4674 ;; On the mips16, we can split a load of certain constants into a load
4675 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
4676 ;; instructions.
4678 (define_split
4679   [(set (match_operand:SI 0 "d_operand")
4680         (match_operand:SI 1 "const_int_operand"))]
4681   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4682    && INTVAL (operands[1]) >= 0x100
4683    && INTVAL (operands[1]) <= 0xff + 0x7f"
4684   [(set (match_dup 0) (match_dup 1))
4685    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4687   int val = INTVAL (operands[1]);
4689   operands[1] = GEN_INT (0xff);
4690   operands[2] = GEN_INT (val - 0xff);
4693 ;; MIPS4 supports loading and storing a floating point register from
4694 ;; the sum of two general registers.  We use two versions for each of
4695 ;; these four instructions: one where the two general registers are
4696 ;; SImode, and one where they are DImode.  This is because general
4697 ;; registers will be in SImode when they hold 32-bit values, but,
4698 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4699 ;; instructions will still work correctly.
4701 ;; ??? Perhaps it would be better to support these instructions by
4702 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends.  However, since
4703 ;; these instructions can only be used to load and store floating
4704 ;; point registers, that would probably cause trouble in reload.
4706 (define_insn "*<ANYF:loadx>_<P:mode>"
4707   [(set (match_operand:ANYF 0 "register_operand" "=f")
4708         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4709                           (match_operand:P 2 "register_operand" "d"))))]
4710   "ISA_HAS_LXC1_SXC1"
4711   "<ANYF:loadx>\t%0,%1(%2)"
4712   [(set_attr "type" "fpidxload")
4713    (set_attr "mode" "<ANYF:UNITMODE>")])
4715 (define_insn "*<ANYF:storex>_<P:mode>"
4716   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4717                           (match_operand:P 2 "register_operand" "d")))
4718         (match_operand:ANYF 0 "register_operand" "f"))]
4719   "ISA_HAS_LXC1_SXC1"
4720   "<ANYF:storex>\t%0,%1(%2)"
4721   [(set_attr "type" "fpidxstore")
4722    (set_attr "mode" "<ANYF:UNITMODE>")])
4724 ;; Scaled indexed address load.
4725 ;; Per md.texi, we only need to look for a pattern with multiply in the
4726 ;; address expression, not shift.
4728 (define_insn "*lwxs"
4729   [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4730         (mem:IMOVE32
4731           (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4732                           (const_int 4))
4733                   (match_operand:P 2 "register_operand" "d"))))]
4734   "ISA_HAS_LWXS"
4735   "lwxs\t%0,%1(%2)"
4736   [(set_attr "type"     "load")
4737    (set_attr "mode"     "SI")])
4739 ;; 16-bit Integer moves
4741 ;; Unlike most other insns, the move insns can't be split with
4742 ;; different predicates, because register spilling and other parts of
4743 ;; the compiler, have memoized the insn number already.
4744 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4746 (define_expand "movhi"
4747   [(set (match_operand:HI 0 "")
4748         (match_operand:HI 1 ""))]
4749   ""
4751   if (mips_legitimize_move (HImode, operands[0], operands[1]))
4752     DONE;
4755 (define_insn "*movhi_internal"
4756   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4757         (match_operand:HI 1 "move_operand"         "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4758   "!TARGET_MIPS16
4759    && (register_operand (operands[0], HImode)
4760        || reg_or_0_operand (operands[1], HImode))"
4761   { return mips_output_move (operands[0], operands[1]); }
4762   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4763    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4764    (set_attr "mode" "HI")])
4766 (define_insn "*movhi_mips16"
4767   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4768         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4769   "TARGET_MIPS16
4770    && (register_operand (operands[0], HImode)
4771        || register_operand (operands[1], HImode))"
4772   { return mips_output_move (operands[0], operands[1]); }
4773   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4774    (set_attr "mode" "HI")])
4776 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4777 ;; when the original load is a 4 byte instruction but the add and the
4778 ;; load are 2 2 byte instructions.
4780 (define_split
4781   [(set (match_operand:HI 0 "d_operand")
4782         (mem:HI (plus:SI (match_dup 0)
4783                          (match_operand:SI 1 "const_int_operand"))))]
4784   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4785    && ((INTVAL (operands[1]) < 0
4786         && INTVAL (operands[1]) >= -0x80)
4787        || (INTVAL (operands[1]) >= 32 * 2
4788            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4789        || (INTVAL (operands[1]) >= 0
4790            && INTVAL (operands[1]) < 32 * 2
4791            && (INTVAL (operands[1]) & 1) != 0))"
4792   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4793    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4795   HOST_WIDE_INT val = INTVAL (operands[1]);
4797   if (val < 0)
4798     operands[2] = const0_rtx;
4799   else if (val >= 32 * 2)
4800     {
4801       int off = val & 1;
4803       operands[1] = GEN_INT (0x7e + off);
4804       operands[2] = GEN_INT (val - off - 0x7e);
4805     }
4806   else
4807     {
4808       int off = val & 1;
4810       operands[1] = GEN_INT (off);
4811       operands[2] = GEN_INT (val - off);
4812     }
4815 ;; 8-bit Integer moves
4817 ;; Unlike most other insns, the move insns can't be split with
4818 ;; different predicates, because register spilling and other parts of
4819 ;; the compiler, have memoized the insn number already.
4820 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4822 (define_expand "movqi"
4823   [(set (match_operand:QI 0 "")
4824         (match_operand:QI 1 ""))]
4825   ""
4827   if (mips_legitimize_move (QImode, operands[0], operands[1]))
4828     DONE;
4831 (define_insn "*movqi_internal"
4832   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
4833         (match_operand:QI 1 "move_operand"         "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
4834   "!TARGET_MIPS16
4835    && (register_operand (operands[0], QImode)
4836        || reg_or_0_operand (operands[1], QImode))"
4837   { return mips_output_move (operands[0], operands[1]); }
4838   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4839    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4840    (set_attr "mode" "QI")])
4842 (define_insn "*movqi_mips16"
4843   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4844         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4845   "TARGET_MIPS16
4846    && (register_operand (operands[0], QImode)
4847        || register_operand (operands[1], QImode))"
4848   { return mips_output_move (operands[0], operands[1]); }
4849   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4850    (set_attr "mode" "QI")])
4852 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4853 ;; when the original load is a 4 byte instruction but the add and the
4854 ;; load are 2 2 byte instructions.
4856 (define_split
4857   [(set (match_operand:QI 0 "d_operand")
4858         (mem:QI (plus:SI (match_dup 0)
4859                          (match_operand:SI 1 "const_int_operand"))))]
4860   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4861    && ((INTVAL (operands[1]) < 0
4862         && INTVAL (operands[1]) >= -0x80)
4863        || (INTVAL (operands[1]) >= 32
4864            && INTVAL (operands[1]) <= 31 + 0x7f))"
4865   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4866    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4868   HOST_WIDE_INT val = INTVAL (operands[1]);
4870   if (val < 0)
4871     operands[2] = const0_rtx;
4872   else
4873     {
4874       operands[1] = GEN_INT (0x7f);
4875       operands[2] = GEN_INT (val - 0x7f);
4876     }
4879 ;; 32-bit floating point moves
4881 (define_expand "movsf"
4882   [(set (match_operand:SF 0 "")
4883         (match_operand:SF 1 ""))]
4884   ""
4886   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4887     DONE;
4890 (define_insn "movccf"
4891   [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
4892         (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
4893   "ISA_HAS_CCF"
4894   { return mips_output_move (operands[0], operands[1]); }
4895   [(set_attr "move_type" "fmove,fpload,fpstore")])
4897 (define_insn "*movsf_hardfloat"
4898   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4899         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4900   "TARGET_HARD_FLOAT
4901    && (register_operand (operands[0], SFmode)
4902        || reg_or_0_operand (operands[1], SFmode))"
4903   { return mips_output_move (operands[0], operands[1]); }
4904   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4905    (set_attr "mode" "SF")])
4907 (define_insn "*movsf_softfloat"
4908   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4909         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4910   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4911    && (register_operand (operands[0], SFmode)
4912        || reg_or_0_operand (operands[1], SFmode))"
4913   { return mips_output_move (operands[0], operands[1]); }
4914   [(set_attr "move_type" "move,load,store")
4915    (set_attr "mode" "SF")])
4917 (define_insn "*movsf_mips16"
4918   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4919         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4920   "TARGET_MIPS16
4921    && (register_operand (operands[0], SFmode)
4922        || register_operand (operands[1], SFmode))"
4923   { return mips_output_move (operands[0], operands[1]); }
4924   [(set_attr "move_type" "move,move,move,load,store")
4925    (set_attr "mode" "SF")])
4927 ;; 64-bit floating point moves
4929 (define_expand "movdf"
4930   [(set (match_operand:DF 0 "")
4931         (match_operand:DF 1 ""))]
4932   ""
4934   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4935     DONE;
4938 (define_insn "*movdf_hardfloat"
4939   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4940         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4941   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4942    && (register_operand (operands[0], DFmode)
4943        || reg_or_0_operand (operands[1], DFmode))"
4944   { return mips_output_move (operands[0], operands[1]); }
4945   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4946    (set_attr "mode" "DF")])
4948 (define_insn "*movdf_softfloat"
4949   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4950         (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4951   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4952    && (register_operand (operands[0], DFmode)
4953        || reg_or_0_operand (operands[1], DFmode))"
4954   { return mips_output_move (operands[0], operands[1]); }
4955   [(set_attr "move_type" "move,load,store")
4956    (set_attr "mode" "DF")])
4958 (define_insn "*movdf_mips16"
4959   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4960         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4961   "TARGET_MIPS16
4962    && (register_operand (operands[0], DFmode)
4963        || register_operand (operands[1], DFmode))"
4964   { return mips_output_move (operands[0], operands[1]); }
4965   [(set_attr "move_type" "move,move,move,load,store")
4966    (set_attr "mode" "DF")])
4968 ;; 128-bit integer moves
4970 (define_expand "movti"
4971   [(set (match_operand:TI 0)
4972         (match_operand:TI 1))]
4973   "TARGET_64BIT"
4975   if (mips_legitimize_move (TImode, operands[0], operands[1]))
4976     DONE;
4979 (define_insn "*movti"
4980   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
4981         (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
4982   "TARGET_64BIT
4983    && !TARGET_MIPS16
4984    && (register_operand (operands[0], TImode)
4985        || reg_or_0_operand (operands[1], TImode))"
4986   { return mips_output_move (operands[0], operands[1]); }
4987   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
4988    (set (attr "mode")
4989         (if_then_else (eq_attr "move_type" "imul")
4990                       (const_string "SI")
4991                       (const_string "TI")))])
4993 (define_insn "*movti_mips16"
4994   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4995         (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4996   "TARGET_64BIT
4997    && TARGET_MIPS16
4998    && (register_operand (operands[0], TImode)
4999        || register_operand (operands[1], TImode))"
5000   "#"
5001   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5002    (set_attr "mode" "TI")])
5004 ;; 128-bit floating point moves
5006 (define_expand "movtf"
5007   [(set (match_operand:TF 0)
5008         (match_operand:TF 1))]
5009   "TARGET_64BIT"
5011   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5012     DONE;
5015 ;; This pattern handles both hard- and soft-float cases.
5016 (define_insn "*movtf"
5017   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5018         (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5019   "TARGET_64BIT
5020    && !TARGET_MIPS16
5021    && (register_operand (operands[0], TFmode)
5022        || reg_or_0_operand (operands[1], TFmode))"
5023   "#"
5024   [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5025    (set_attr "mode" "TF")])
5027 (define_insn "*movtf_mips16"
5028   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5029         (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5030   "TARGET_64BIT
5031    && TARGET_MIPS16
5032    && (register_operand (operands[0], TFmode)
5033        || register_operand (operands[1], TFmode))"
5034   "#"
5035   [(set_attr "move_type" "move,move,move,load,store")
5036    (set_attr "mode" "TF")])
5038 (define_split
5039   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5040         (match_operand:MOVE64 1 "move_operand"))]
5041   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5042   [(const_int 0)]
5044   mips_split_move_insn (operands[0], operands[1], curr_insn);
5045   DONE;
5048 (define_split
5049   [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5050         (match_operand:MOVE128 1 "move_operand"))]
5051   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5052   [(const_int 0)]
5054   mips_split_move_insn (operands[0], operands[1], curr_insn);
5055   DONE;
5058 ;; When generating mips16 code, split moves of negative constants into
5059 ;; a positive "li" followed by a negation.
5060 (define_split
5061   [(set (match_operand 0 "d_operand")
5062         (match_operand 1 "const_int_operand"))]
5063   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5064   [(set (match_dup 2)
5065         (match_dup 3))
5066    (set (match_dup 2)
5067         (neg:SI (match_dup 2)))]
5069   operands[2] = gen_lowpart (SImode, operands[0]);
5070   operands[3] = GEN_INT (-INTVAL (operands[1]));
5073 ;; 64-bit paired-single floating point moves
5075 (define_expand "movv2sf"
5076   [(set (match_operand:V2SF 0)
5077         (match_operand:V2SF 1))]
5078   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5080   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5081     DONE;
5084 (define_insn "*movv2sf"
5085   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5086         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5087   "TARGET_HARD_FLOAT
5088    && TARGET_PAIRED_SINGLE_FLOAT
5089    && (register_operand (operands[0], V2SFmode)
5090        || reg_or_0_operand (operands[1], V2SFmode))"
5091   { return mips_output_move (operands[0], operands[1]); }
5092   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5093    (set_attr "mode" "DF")])
5095 ;; Extract the high part of a HI/LO value.  See mips_hard_regno_mode_ok_p
5096 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5098 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5099 ;; instead of MFHI.  This avoids both the normal MIPS III hi/lo hazards
5100 ;; and the errata related to -mfix-vr4130.
5101 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5102   [(set (match_operand:GPR 0 "register_operand" "=d")
5103         (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5104                     UNSPEC_MFHI))]
5105   ""
5106   { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5107   [(set_attr "type" "mfhi")
5108    (set_attr "mode" "<GPR:MODE>")])
5110 ;; Set the high part of a HI/LO value, given that the low part has
5111 ;; already been set.  See mips_hard_regno_mode_ok_p for the reason
5112 ;; why we can't just use (reg:GPR HI_REGNUM).
5113 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5114   [(set (match_operand:HILO 0 "register_operand" "=x")
5115         (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5116                       (match_operand:GPR 2 "register_operand" "l")]
5117                      UNSPEC_MTHI))]
5118   ""
5119   "mthi\t%z1"
5120   [(set_attr "type" "mthi")
5121    (set_attr "mode" "SI")])
5123 ;; Emit a doubleword move in which exactly one of the operands is
5124 ;; a floating-point register.  We can't just emit two normal moves
5125 ;; because of the constraints imposed by the FPU register model;
5126 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
5127 ;; the FPR whole and use special patterns to refer to each word of
5128 ;; the other operand.
5130 (define_expand "move_doubleword_fpr<mode>"
5131   [(set (match_operand:SPLITF 0)
5132         (match_operand:SPLITF 1))]
5133   ""
5135   if (FP_REG_RTX_P (operands[0]))
5136     {
5137       rtx low = mips_subword (operands[1], 0);
5138       rtx high = mips_subword (operands[1], 1);
5139       emit_insn (gen_load_low<mode> (operands[0], low));
5140       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5141         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5142       else
5143         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5144     }
5145   else
5146     {
5147       rtx low = mips_subword (operands[0], 0);
5148       rtx high = mips_subword (operands[0], 1);
5149       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5150       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5151         emit_insn (gen_mfhc1<mode> (high, operands[1]));
5152       else
5153         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5154     }
5155   DONE;
5158 ;; Load the low word of operand 0 with operand 1.
5159 (define_insn "load_low<mode>"
5160   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5161         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5162                        UNSPEC_LOAD_LOW))]
5163   "TARGET_HARD_FLOAT"
5165   operands[0] = mips_subword (operands[0], 0);
5166   return mips_output_move (operands[0], operands[1]);
5168   [(set_attr "move_type" "mtc,fpload")
5169    (set_attr "mode" "<HALFMODE>")])
5171 ;; Load the high word of operand 0 from operand 1, preserving the value
5172 ;; in the low word.
5173 (define_insn "load_high<mode>"
5174   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5175         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5176                         (match_operand:SPLITF 2 "register_operand" "0,0")]
5177                        UNSPEC_LOAD_HIGH))]
5178   "TARGET_HARD_FLOAT"
5180   operands[0] = mips_subword (operands[0], 1);
5181   return mips_output_move (operands[0], operands[1]);
5183   [(set_attr "move_type" "mtc,fpload")
5184    (set_attr "mode" "<HALFMODE>")])
5186 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
5187 ;; high word and 0 to store the low word.
5188 (define_insn "store_word<mode>"
5189   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5190         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5191                             (match_operand 2 "const_int_operand")]
5192                            UNSPEC_STORE_WORD))]
5193   "TARGET_HARD_FLOAT"
5195   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5196   return mips_output_move (operands[0], operands[1]);
5198   [(set_attr "move_type" "mfc,fpstore")
5199    (set_attr "mode" "<HALFMODE>")])
5201 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5202 ;; value in the low word.
5203 (define_insn "mthc1<mode>"
5204   [(set (match_operand:SPLITF 0 "register_operand" "=f")
5205         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5206                         (match_operand:SPLITF 2 "register_operand" "0")]
5207                        UNSPEC_MTHC1))]
5208   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5209   "mthc1\t%z1,%0"
5210   [(set_attr "move_type" "mtc")
5211    (set_attr "mode" "<HALFMODE>")])
5213 ;; Move high word of operand 1 to operand 0 using mfhc1.
5214 (define_insn "mfhc1<mode>"
5215   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5216         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5217                             UNSPEC_MFHC1))]
5218   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5219   "mfhc1\t%0,%1"
5220   [(set_attr "move_type" "mfc")
5221    (set_attr "mode" "<HALFMODE>")])
5223 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5224 (define_expand "load_const_gp_<mode>"
5225   [(set (match_operand:P 0 "register_operand" "=d")
5226         (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5228 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
5229 ;; of _gp from the start of this function.  Operand 1 is the incoming
5230 ;; function address.
5231 (define_insn_and_split "loadgp_newabi_<mode>"
5232   [(set (match_operand:P 0 "register_operand" "=&d")
5233         (unspec:P [(match_operand:P 1)
5234                    (match_operand:P 2 "register_operand" "d")]
5235                   UNSPEC_LOADGP))]
5236   "mips_current_loadgp_style () == LOADGP_NEWABI"
5237   { return mips_must_initialize_gp_p () ? "#" : ""; }
5238   "&& mips_must_initialize_gp_p ()"
5239   [(set (match_dup 0) (match_dup 3))
5240    (set (match_dup 0) (match_dup 4))
5241    (set (match_dup 0) (match_dup 5))]
5243   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5244   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5245   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5247   [(set_attr "type" "ghost")])
5249 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
5250 (define_insn_and_split "loadgp_absolute_<mode>"
5251   [(set (match_operand:P 0 "register_operand" "=d")
5252         (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5253   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5254   { return mips_must_initialize_gp_p () ? "#" : ""; }
5255   "&& mips_must_initialize_gp_p ()"
5256   [(const_int 0)]
5258   mips_emit_move (operands[0], operands[1]);
5259   DONE;
5261   [(set_attr "type" "ghost")])
5263 ;; This blockage instruction prevents the gp load from being
5264 ;; scheduled after an implicit use of gp.  It also prevents
5265 ;; the load from being deleted as dead.
5266 (define_insn "loadgp_blockage"
5267   [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5268   ""
5269   ""
5270   [(set_attr "type" "ghost")])
5272 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
5273 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5274 (define_insn_and_split "loadgp_rtp_<mode>"
5275   [(set (match_operand:P 0 "register_operand" "=d")
5276         (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5277                    (match_operand:P 2 "symbol_ref_operand")]
5278                   UNSPEC_LOADGP))]
5279   "mips_current_loadgp_style () == LOADGP_RTP"
5280   { return mips_must_initialize_gp_p () ? "#" : ""; }
5281   "&& mips_must_initialize_gp_p ()"
5282   [(set (match_dup 0) (high:P (match_dup 3)))
5283    (set (match_dup 0) (unspec:P [(match_dup 0)
5284                                  (match_dup 3)] UNSPEC_LOAD_GOT))
5285    (set (match_dup 0) (unspec:P [(match_dup 0)
5286                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
5288   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5289   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5291   [(set_attr "type" "ghost")])
5293 ;; Initialize the global pointer for MIPS16 code.  Operand 0 is the
5294 ;; global pointer and operand 1 is the MIPS16 register that holds
5295 ;; the required value.
5296 (define_insn_and_split "copygp_mips16_<mode>"
5297   [(set (match_operand:P 0 "register_operand" "=y")
5298         (unspec:P [(match_operand:P 1 "register_operand" "d")]
5299                   UNSPEC_COPYGP))]
5300   "TARGET_MIPS16"
5301   { return mips_must_initialize_gp_p () ? "#" : ""; }
5302   "&& mips_must_initialize_gp_p ()"
5303   [(set (match_dup 0) (match_dup 1))]
5304   ""
5305   [(set_attr "type" "ghost")])
5307 ;; A placeholder for where the cprestore instruction should go,
5308 ;; if we decide we need one.  Operand 0 and operand 1 are as for
5309 ;; "cprestore".  Operand 2 is a register that holds the gp value.
5311 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5312 ;; otherwise any register that holds the correct value will do.
5313 (define_insn_and_split "potential_cprestore_<mode>"
5314   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5315         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5316                    (match_operand:P 2 "register_operand" "d,d")]
5317                   UNSPEC_POTENTIAL_CPRESTORE))
5318    (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5319   "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5320   { return mips_must_initialize_gp_p () ? "#" : ""; }
5321   "mips_must_initialize_gp_p ()"
5322   [(const_int 0)]
5324   mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5325                                   operands[2], operands[3]);
5326   DONE;
5328   [(set_attr "type" "ghost")])
5330 ;; Emit a .cprestore directive, which normally expands to a single store
5331 ;; instruction.  Operand 0 is a (possibly illegitimate) sp-based MEM
5332 ;; for the cprestore slot.  Operand 1 is the offset of the slot from
5333 ;; the stack pointer.  (This is redundant with operand 0, but it makes
5334 ;; things a little simpler.)
5335 (define_insn "cprestore_<mode>"
5336   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5337         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5338                    (reg:P 28)]
5339                   UNSPEC_CPRESTORE))]
5340   "TARGET_CPRESTORE_DIRECTIVE"
5342   if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5343     return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5344   else
5345     return ".cprestore\t%1";
5347   [(set_attr "type" "store")
5348    (set_attr "insn_count" "1,3")])
5350 (define_insn "use_cprestore_<mode>"
5351   [(set (reg:P CPRESTORE_SLOT_REGNUM)
5352         (match_operand:P 0 "cprestore_load_slot_operand"))]
5353   ""
5354   ""
5355   [(set_attr "type" "ghost")])
5357 ;; Expand in-line code to clear the instruction cache between operand[0] and
5358 ;; operand[1].
5359 (define_expand "clear_cache"
5360   [(match_operand 0 "pmode_register_operand")
5361    (match_operand 1 "pmode_register_operand")]
5362   ""
5363   "
5365   if (TARGET_SYNCI)
5366     {
5367       mips_expand_synci_loop (operands[0], operands[1]);
5368       emit_insn (gen_sync ());
5369       emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5370     }
5371   else if (mips_cache_flush_func && mips_cache_flush_func[0])
5372     {
5373       rtx len = gen_reg_rtx (Pmode);
5374       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5375       MIPS_ICACHE_SYNC (operands[0], len);
5376     }
5377   DONE;
5380 (define_insn "sync"
5381   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5382   "GENERATE_SYNC"
5383   { return mips_output_sync (); })
5385 (define_insn "synci"
5386   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5387                     UNSPEC_SYNCI)]
5388   "TARGET_SYNCI"
5389   "synci\t0(%0)")
5391 (define_insn "rdhwr_synci_step_<mode>"
5392   [(set (match_operand:P 0 "register_operand" "=d")
5393         (unspec_volatile [(const_int 1)]
5394         UNSPEC_RDHWR))]
5395   "ISA_HAS_SYNCI"
5396   "rdhwr\t%0,$1")
5398 (define_insn "clear_hazard_<mode>"
5399   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5400    (clobber (reg:P RETURN_ADDR_REGNUM))]
5401   "ISA_HAS_SYNCI"
5403   return "%(%<bal\t1f\n"
5404          "\tnop\n"
5405          "1:\t<d>addiu\t$31,$31,12\n"
5406          "\tjr.hb\t$31\n"
5407          "\tnop%>%)";
5409   [(set_attr "insn_count" "5")])
5411 ;; Cache operations for R4000-style caches.
5412 (define_insn "mips_cache"
5413   [(set (mem:BLK (scratch))
5414         (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5415                      (match_operand:QI 1 "address_operand" "ZD")]
5416                     UNSPEC_MIPS_CACHE))]
5417   "ISA_HAS_CACHE"
5418   "cache\t%X0,%a1")
5420 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5421 ;; operation.  We keep the pattern distinct so that we can identify
5422 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5423 ;; the operation is never inserted into a delay slot.
5424 (define_insn "r10k_cache_barrier"
5425   [(set (mem:BLK (scratch))
5426         (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5427   "ISA_HAS_CACHE"
5428   "cache\t0x14,0(%$)"
5429   [(set_attr "can_delay" "no")])
5431 ;; Block moves, see mips.c for more details.
5432 ;; Argument 0 is the destination
5433 ;; Argument 1 is the source
5434 ;; Argument 2 is the length
5435 ;; Argument 3 is the alignment
5437 (define_expand "movmemsi"
5438   [(parallel [(set (match_operand:BLK 0 "general_operand")
5439                    (match_operand:BLK 1 "general_operand"))
5440               (use (match_operand:SI 2 ""))
5441               (use (match_operand:SI 3 "const_int_operand"))])]
5442   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5444   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5445     DONE;
5446   else
5447     FAIL;
5451 ;;  ....................
5453 ;;      SHIFTS
5455 ;;  ....................
5457 (define_expand "<optab><mode>3"
5458   [(set (match_operand:GPR 0 "register_operand")
5459         (any_shift:GPR (match_operand:GPR 1 "register_operand")
5460                        (match_operand:SI 2 "arith_operand")))]
5461   ""
5463   /* On the mips16, a shift of more than 8 is a four byte instruction,
5464      so, for a shift between 8 and 16, it is just as fast to do two
5465      shifts of 8 or less.  If there is a lot of shifting going on, we
5466      may win in CSE.  Otherwise combine will put the shifts back
5467      together again.  This can be called by mips_function_arg, so we must
5468      be careful not to allocate a new register if we've reached the
5469      reload pass.  */
5470   if (TARGET_MIPS16
5471       && optimize
5472       && CONST_INT_P (operands[2])
5473       && INTVAL (operands[2]) > 8
5474       && INTVAL (operands[2]) <= 16
5475       && !reload_in_progress
5476       && !reload_completed)
5477     {
5478       rtx temp = gen_reg_rtx (<MODE>mode);
5480       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5481       emit_insn (gen_<optab><mode>3 (operands[0], temp,
5482                                      GEN_INT (INTVAL (operands[2]) - 8)));
5483       DONE;
5484     }
5487 (define_insn "*<optab><mode>3"
5488   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5489         (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5490                        (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5491   "!TARGET_MIPS16"
5493   if (CONST_INT_P (operands[2]))
5494     operands[2] = GEN_INT (INTVAL (operands[2])
5495                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5497   return "<d><insn>\t%0,%1,%2";
5499   [(set_attr "type" "shift")
5500    (set_attr "compression" "<shift_compression>,none")
5501    (set_attr "mode" "<MODE>")])
5503 (define_insn "*<optab>si3_extend"
5504   [(set (match_operand:DI 0 "register_operand" "=d")
5505         (sign_extend:DI
5506            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5507                          (match_operand:SI 2 "arith_operand" "dI"))))]
5508   "TARGET_64BIT && !TARGET_MIPS16"
5510   if (CONST_INT_P (operands[2]))
5511     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5513   return "<insn>\t%0,%1,%2";
5515   [(set_attr "type" "shift")
5516    (set_attr "mode" "SI")])
5518 (define_insn "*<optab>si3_mips16"
5519   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5520         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5521                       (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5522   "TARGET_MIPS16"
5524   if (which_alternative == 0)
5525     return "<insn>\t%0,%2";
5527   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5528   return "<insn>\t%0,%1,%2";
5530   [(set_attr "type" "shift")
5531    (set_attr "mode" "SI")
5532    (set_attr "extended_mips16" "no,no,yes")])
5534 (define_insn "<GPR:d>lsa"
5535  [(set (match_operand:GPR 0 "register_operand" "=d")
5536        (plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
5537                              (match_operand 2 "const_immlsa_operand" ""))
5538                 (match_operand:GPR 3 "register_operand" "d")))]
5539  "ISA_HAS_<GPR:D>LSA"
5540  "<GPR:d>lsa\t%0,%1,%3,%2"
5541  [(set_attr "type" "arith")
5542   (set_attr "mode" "<GPR:MODE>")])
5544 ;; We need separate DImode MIPS16 patterns because of the irregularity
5545 ;; of right shifts.
5546 (define_insn "*ashldi3_mips16"
5547   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5548         (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5549                    (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5550   "TARGET_64BIT && TARGET_MIPS16"
5552   if (which_alternative == 0)
5553     return "dsll\t%0,%2";
5555   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5556   return "dsll\t%0,%1,%2";
5558   [(set_attr "type" "shift")
5559    (set_attr "mode" "DI")
5560    (set_attr "extended_mips16" "no,no,yes")])
5562 (define_insn "*ashrdi3_mips16"
5563   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5564         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5565                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5566   "TARGET_64BIT && TARGET_MIPS16"
5568   if (CONST_INT_P (operands[2]))
5569     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5571   return "dsra\t%0,%2";
5573   [(set_attr "type" "shift")
5574    (set_attr "mode" "DI")
5575    (set_attr "extended_mips16" "no,no,yes")])
5577 (define_insn "*lshrdi3_mips16"
5578   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5579         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5580                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5581   "TARGET_64BIT && TARGET_MIPS16"
5583   if (CONST_INT_P (operands[2]))
5584     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5586   return "dsrl\t%0,%2";
5588   [(set_attr "type" "shift")
5589    (set_attr "mode" "DI")
5590    (set_attr "extended_mips16" "no,no,yes")])
5592 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5594 (define_split
5595   [(set (match_operand:GPR 0 "d_operand")
5596         (any_shift:GPR (match_operand:GPR 1 "d_operand")
5597                        (match_operand:GPR 2 "const_int_operand")))]
5598   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5599    && INTVAL (operands[2]) > 8
5600    && INTVAL (operands[2]) <= 16"
5601   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5602    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5603   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5605 ;; If we load a byte on the mips16 as a bitfield, the resulting
5606 ;; sequence of instructions is too complicated for combine, because it
5607 ;; involves four instructions: a load, a shift, a constant load into a
5608 ;; register, and an and (the key problem here is that the mips16 does
5609 ;; not have and immediate).  We recognize a shift of a load in order
5610 ;; to make it simple enough for combine to understand.
5612 ;; The instruction count here is the worst case.
5613 (define_insn_and_split ""
5614   [(set (match_operand:SI 0 "register_operand" "=d")
5615         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5616                      (match_operand:SI 2 "immediate_operand" "I")))]
5617   "TARGET_MIPS16"
5618   "#"
5619   ""
5620   [(set (match_dup 0) (match_dup 1))
5621    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5622   ""
5623   [(set_attr "type"     "load")
5624    (set_attr "mode"     "SI")
5625    (set (attr "insn_count")
5626         (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5628 (define_insn "rotr<mode>3"
5629   [(set (match_operand:GPR 0 "register_operand" "=d")
5630         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5631                       (match_operand:SI 2 "arith_operand" "dI")))]
5632   "ISA_HAS_ROR"
5634   if (CONST_INT_P (operands[2]))
5635     gcc_assert (INTVAL (operands[2]) >= 0
5636                 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5638   return "<d>ror\t%0,%1,%2";
5640   [(set_attr "type" "shift")
5641    (set_attr "mode" "<MODE>")])
5643 (define_insn "bswaphi2"
5644   [(set (match_operand:HI 0 "register_operand" "=d")
5645         (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5646   "ISA_HAS_WSBH"
5647   "wsbh\t%0,%1"
5648   [(set_attr "type" "shift")])
5650 (define_insn_and_split "bswapsi2"
5651   [(set (match_operand:SI 0 "register_operand" "=d")
5652         (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5653   "ISA_HAS_WSBH && ISA_HAS_ROR"
5654   "#"
5655   ""
5656   [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5657    (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5658   ""
5659   [(set_attr "insn_count" "2")])
5661 (define_insn_and_split "bswapdi2"
5662   [(set (match_operand:DI 0 "register_operand" "=d")
5663         (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5664   "TARGET_64BIT && ISA_HAS_WSBH"
5665   "#"
5666   ""
5667   [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5668    (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5669   ""
5670   [(set_attr "insn_count" "2")])
5672 (define_insn "wsbh"
5673   [(set (match_operand:SI 0 "register_operand" "=d")
5674         (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5675   "ISA_HAS_WSBH"
5676   "wsbh\t%0,%1"
5677   [(set_attr "type" "shift")])
5679 (define_insn "dsbh"
5680   [(set (match_operand:DI 0 "register_operand" "=d")
5681         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5682   "TARGET_64BIT && ISA_HAS_WSBH"
5683   "dsbh\t%0,%1"
5684   [(set_attr "type" "shift")])
5686 (define_insn "dshd"
5687   [(set (match_operand:DI 0 "register_operand" "=d")
5688         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5689   "TARGET_64BIT && ISA_HAS_WSBH"
5690   "dshd\t%0,%1"
5691   [(set_attr "type" "shift")])
5694 ;;  ....................
5696 ;;      CONDITIONAL BRANCHES
5698 ;;  ....................
5700 ;; Conditional branches on floating-point equality tests.
5702 (define_insn "*branch_fp_<mode>"
5703   [(set (pc)
5704         (if_then_else
5705          (match_operator 1 "equality_operator"
5706                          [(match_operand:FPCC 2 "register_operand" "<reg>")
5707                           (const_int 0)])
5708          (label_ref (match_operand 0 "" ""))
5709          (pc)))]
5710   "TARGET_HARD_FLOAT"
5712   return mips_output_conditional_branch (insn, operands,
5713                                          MIPS_BRANCH ("b%F1", "%Z2%0"),
5714                                          MIPS_BRANCH ("b%W1", "%Z2%0"));
5716   [(set_attr "type" "branch")])
5718 (define_insn "*branch_fp_inverted_<mode>"
5719   [(set (pc)
5720         (if_then_else
5721          (match_operator 1 "equality_operator"
5722                          [(match_operand:FPCC 2 "register_operand" "<reg>")
5723                           (const_int 0)])
5724          (pc)
5725          (label_ref (match_operand 0 "" ""))))]
5726   "TARGET_HARD_FLOAT"
5728   return mips_output_conditional_branch (insn, operands,
5729                                          MIPS_BRANCH ("b%W1", "%Z2%0"),
5730                                          MIPS_BRANCH ("b%F1", "%Z2%0"));
5732   [(set_attr "type" "branch")])
5734 ;; Conditional branches on ordered comparisons with zero.
5736 (define_insn "*branch_order<mode>"
5737   [(set (pc)
5738         (if_then_else
5739          (match_operator 1 "order_operator"
5740                          [(match_operand:GPR 2 "register_operand" "d")
5741                           (const_int 0)])
5742          (label_ref (match_operand 0 "" ""))
5743          (pc)))]
5744   "!TARGET_MIPS16"
5745   { return mips_output_order_conditional_branch (insn, operands, false); }
5746   [(set_attr "type" "branch")])
5748 (define_insn "*branch_order<mode>_inverted"
5749   [(set (pc)
5750         (if_then_else
5751          (match_operator 1 "order_operator"
5752                          [(match_operand:GPR 2 "register_operand" "d")
5753                           (const_int 0)])
5754          (pc)
5755          (label_ref (match_operand 0 "" ""))))]
5756   "!TARGET_MIPS16"
5757   { return mips_output_order_conditional_branch (insn, operands, true); }
5758   [(set_attr "type" "branch")])
5760 ;; Conditional branch on equality comparison.
5762 (define_insn "*branch_equality<mode>"
5763   [(set (pc)
5764         (if_then_else
5765          (match_operator 1 "equality_operator"
5766                          [(match_operand:GPR 2 "register_operand" "d")
5767                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5768          (label_ref (match_operand 0 "" ""))
5769          (pc)))]
5770   "!TARGET_MIPS16"
5772   /* For a simple BNEZ or BEQZ microMIPS branch.  */
5773   if (TARGET_MICROMIPS
5774       && operands[3] == const0_rtx
5775       && get_attr_length (insn) <= 8)
5776     return mips_output_conditional_branch (insn, operands,
5777                                            "%*b%C1z%:\t%2,%0",
5778                                            "%*b%N1z%:\t%2,%0");
5780   return mips_output_conditional_branch (insn, operands,
5781                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5782                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5784   [(set_attr "type" "branch")])
5786 (define_insn "*branch_equality<mode>_inverted"
5787   [(set (pc)
5788         (if_then_else
5789          (match_operator 1 "equality_operator"
5790                          [(match_operand:GPR 2 "register_operand" "d")
5791                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5792          (pc)
5793          (label_ref (match_operand 0 "" ""))))]
5794   "!TARGET_MIPS16"
5796   /* For a simple BNEZ or BEQZ microMIPS branch.  */
5797   if (TARGET_MICROMIPS
5798       && operands[3] == const0_rtx
5799       && get_attr_length (insn) <= 8)
5800     return mips_output_conditional_branch (insn, operands,
5801                                            "%*b%N0z%:\t%2,%1",
5802                                            "%*b%C0z%:\t%2,%1");
5804   return mips_output_conditional_branch (insn, operands,
5805                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5806                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5808   [(set_attr "type" "branch")])
5810 ;; MIPS16 branches
5812 (define_insn "*branch_equality<mode>_mips16"
5813   [(set (pc)
5814         (if_then_else
5815          (match_operator 1 "equality_operator"
5816                          [(match_operand:GPR 2 "register_operand" "d,t")
5817                           (const_int 0)])
5818          (label_ref (match_operand 0 "" ""))
5819          (pc)))]
5820   "TARGET_MIPS16"
5821   "@
5822    b%C1z\t%2,%0
5823    bt%C1z\t%0"
5824   [(set_attr "type" "branch")])
5826 (define_insn "*branch_equality<mode>_mips16_inverted"
5827   [(set (pc)
5828         (if_then_else
5829          (match_operator 1 "equality_operator"
5830                          [(match_operand:GPR 2 "register_operand" "d,t")
5831                           (const_int 0)])
5832          (pc)
5833          (label_ref (match_operand 0 "" ""))))]
5834   "TARGET_MIPS16"
5835   "@
5836    b%N1z\t%2,%0
5837    bt%N1z\t%0"
5838   [(set_attr "type" "branch")])
5840 (define_expand "cbranch<mode>4"
5841   [(set (pc)
5842         (if_then_else (match_operator 0 "comparison_operator"
5843                        [(match_operand:GPR 1 "register_operand")
5844                         (match_operand:GPR 2 "nonmemory_operand")])
5845                       (label_ref (match_operand 3 ""))
5846                       (pc)))]
5847   ""
5849   mips_expand_conditional_branch (operands);
5850   DONE;
5853 (define_expand "cbranch<mode>4"
5854   [(set (pc)
5855         (if_then_else (match_operator 0 "comparison_operator"
5856                        [(match_operand:SCALARF 1 "register_operand")
5857                         (match_operand:SCALARF 2 "register_operand")])
5858                       (label_ref (match_operand 3 ""))
5859                       (pc)))]
5860   ""
5862   mips_expand_conditional_branch (operands);
5863   DONE;
5866 ;; Used to implement built-in functions.
5867 (define_expand "condjump"
5868   [(set (pc)
5869         (if_then_else (match_operand 0)
5870                       (label_ref (match_operand 1))
5871                       (pc)))])
5873 ;; Branch if bit is set/clear.
5875 (define_insn "*branch_bit<bbv><mode>"
5876   [(set (pc)
5877         (if_then_else
5878          (equality_op (zero_extract:GPR
5879                        (match_operand:GPR 1 "register_operand" "d")
5880                        (const_int 1)
5881                        (match_operand 2 "const_int_operand" ""))
5882                       (const_int 0))
5883          (label_ref (match_operand 0 ""))
5884          (pc)))]
5885   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5887   return
5888     mips_output_conditional_branch (insn, operands,
5889                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5890                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5892   [(set_attr "type"          "branch")
5893    (set_attr "branch_likely" "no")])
5895 (define_insn "*branch_bit<bbv><mode>_inverted"
5896   [(set (pc)
5897         (if_then_else
5898          (equality_op (zero_extract:GPR
5899                        (match_operand:GPR 1 "register_operand" "d")
5900                        (const_int 1)
5901                        (match_operand 2 "const_int_operand" ""))
5902                       (const_int 0))
5903          (pc)
5904          (label_ref (match_operand 0 ""))))]
5905   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5907   return
5908     mips_output_conditional_branch (insn, operands,
5909                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5910                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5912   [(set_attr "type"          "branch")
5913    (set_attr "branch_likely" "no")])
5916 ;;  ....................
5918 ;;      SETTING A REGISTER FROM A COMPARISON
5920 ;;  ....................
5922 ;; Destination is always set in SI mode.
5924 (define_expand "cstore<mode>4"
5925   [(set (match_operand:SI 0 "register_operand")
5926         (match_operator:SI 1 "mips_cstore_operator"
5927          [(match_operand:GPR 2 "register_operand")
5928           (match_operand:GPR 3 "nonmemory_operand")]))]
5929   ""
5931   mips_expand_scc (operands);
5932   DONE;
5935 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5936   [(set (match_operand:GPR2 0 "register_operand" "=d")
5937         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5938                  (const_int 0)))]
5939   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5940   "sltu\t%0,%1,1"
5941   [(set_attr "type" "slt")
5942    (set_attr "mode" "<GPR:MODE>")])
5944 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5945   [(set (match_operand:GPR2 0 "register_operand" "=t")
5946         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5947                  (const_int 0)))]
5948   "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5949   "sltu\t%1,1"
5950   [(set_attr "type" "slt")
5951    (set_attr "mode" "<GPR:MODE>")])
5953 ;; Generate sltiu unless using seq results in better code.
5954 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5955   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5956         (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5957                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5958   "ISA_HAS_SEQ_SNE"
5959   "@
5960    seq\t%0,%1,%2
5961    sltiu\t%0,%1,1
5962    seqi\t%0,%1,%2"
5963   [(set_attr "type" "slt")
5964    (set_attr "mode" "<GPR:MODE>")])
5966 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5967   [(set (match_operand:GPR2 0 "register_operand" "=d")
5968         (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5969                  (const_int 0)))]
5970   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5971   "sltu\t%0,%.,%1"
5972   [(set_attr "type" "slt")
5973    (set_attr "mode" "<GPR:MODE>")])
5975 ;; Generate sltu unless using sne results in better code.
5976 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5977   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5978         (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5979                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5980   "ISA_HAS_SEQ_SNE"
5981   "@
5982    sne\t%0,%1,%2
5983    sltu\t%0,%.,%1
5984    snei\t%0,%1,%2"
5985   [(set_attr "type" "slt")
5986    (set_attr "mode" "<GPR:MODE>")])
5988 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5989   [(set (match_operand:GPR2 0 "register_operand" "=d")
5990         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5991                      (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5992   "!TARGET_MIPS16"
5993   "slt<u>\t%0,%z2,%1"
5994   [(set_attr "type" "slt")
5995    (set_attr "mode" "<GPR:MODE>")])
5997 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5998   [(set (match_operand:GPR2 0 "register_operand" "=t")
5999         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6000                      (match_operand:GPR 2 "register_operand" "d")))]
6001   "TARGET_MIPS16"
6002   "slt<u>\t%2,%1"
6003   [(set_attr "type" "slt")
6004    (set_attr "mode" "<GPR:MODE>")])
6006 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6007   [(set (match_operand:GPR2 0 "register_operand" "=d")
6008         (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6009                      (const_int 1)))]
6010   "!TARGET_MIPS16"
6011   "slt<u>\t%0,%.,%1"
6012   [(set_attr "type" "slt")
6013    (set_attr "mode" "<GPR:MODE>")])
6015 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6016   [(set (match_operand:GPR2 0 "register_operand" "=d")
6017         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6018                      (match_operand:GPR 2 "arith_operand" "dI")))]
6019   "!TARGET_MIPS16"
6020   "slt<u>\t%0,%1,%2"
6021   [(set_attr "type" "slt")
6022    (set_attr "mode" "<GPR:MODE>")])
6024 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6025   [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6026         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6027                      (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6028   "TARGET_MIPS16"
6029   "slt<u>\t%1,%2"
6030   [(set_attr "type" "slt")
6031    (set_attr "mode" "<GPR:MODE>")
6032    (set_attr "extended_mips16" "no,no,yes")])
6034 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6035   [(set (match_operand:GPR2 0 "register_operand" "=d")
6036         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6037                      (match_operand:GPR 2 "sle_operand" "")))]
6038   "!TARGET_MIPS16"
6040   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6041   return "slt<u>\t%0,%1,%2";
6043   [(set_attr "type" "slt")
6044    (set_attr "mode" "<GPR:MODE>")])
6046 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6047   [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6048         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6049                      (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6050   "TARGET_MIPS16"
6052   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6053   return "slt<u>\t%1,%2";
6055   [(set_attr "type" "slt")
6056    (set_attr "mode" "<GPR:MODE>")
6057    (set_attr "extended_mips16" "no,yes")])
6060 ;;  ....................
6062 ;;      FLOATING POINT COMPARISONS
6064 ;;  ....................
6066 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6067   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6068         (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6069                     (match_operand:SCALARF 2 "register_operand" "f")))]
6070   ""
6071   "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6072   [(set_attr "type" "fcmp")
6073    (set_attr "mode" "FPSW")])
6075 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6076   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6077         (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6078                             (match_operand:SCALARF 2 "register_operand" "f")))]
6079   ""
6080   "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6081   [(set_attr "type" "fcmp")
6082    (set_attr "mode" "FPSW")])
6085 ;;  ....................
6087 ;;      UNCONDITIONAL BRANCHES
6089 ;;  ....................
6091 ;; Unconditional branches.
6093 (define_expand "jump"
6094   [(set (pc)
6095         (label_ref (match_operand 0)))])
6097 (define_insn "*jump_absolute"
6098   [(set (pc)
6099         (label_ref (match_operand 0)))]
6100   "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6102   if (get_attr_length (insn) <= 8)
6103     return "%*b\t%l0%/";
6104   else
6105     return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6107   [(set_attr "type" "branch")])
6109 (define_insn "*jump_pic"
6110   [(set (pc)
6111         (label_ref (match_operand 0)))]
6112   "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6114   if (get_attr_length (insn) <= 8)
6115     return "%*b\t%l0%/";
6116   else
6117     {
6118       mips_output_load_label (operands[0]);
6119       return "%*jr\t%@%/%]";
6120     }
6122   [(set_attr "type" "branch")])
6124 ;; We need a different insn for the mips16, because a mips16 branch
6125 ;; does not have a delay slot.
6127 (define_insn "*jump_mips16"
6128   [(set (pc)
6129         (label_ref (match_operand 0 "" "")))]
6130   "TARGET_MIPS16"
6131   "b\t%l0"
6132   [(set_attr "type" "branch")
6133    (set (attr "length")
6134         ;; This calculation is like the normal branch one, but the
6135         ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6136         ;; than [-0x100, 0xfe].  This translates to a range of:
6137         ;;
6138         ;;    [-(0x800 - sizeof (branch)), 0x7fe]
6139         ;; == [-0x7fe, 0x7fe]
6140         ;;
6141         ;; from the shorten_branches reference address.  Long-branch
6142         ;; sequences will replace this one, so the minimum length
6143         ;; is one instruction shorter than for conditional branches.
6144         (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6145                     (le (minus (pc) (match_dup 0)) (const_int 2046)))
6146                (const_int 2)
6147                (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6148                     (le (minus (pc) (match_dup 0)) (const_int 65532)))
6149                (const_int 4)
6150                (and (match_test "TARGET_ABICALLS")
6151                     (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6152                (const_int 18)
6153                (match_test "Pmode == SImode")
6154                (const_int 14)
6155                ] (const_int 22)))])
6157 (define_expand "indirect_jump"
6158   [(set (pc) (match_operand 0 "register_operand"))]
6159   ""
6161   operands[0] = force_reg (Pmode, operands[0]);
6162   emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6163   DONE;
6166 (define_insn "indirect_jump_<mode>"
6167   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6168   ""
6170   if (TARGET_MICROMIPS)
6171     return "%*jr%:\t%0";
6172   else
6173     return "%*j\t%0%/";
6175   [(set_attr "type" "jump")
6176    (set_attr "mode" "none")])
6178 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6179 ;; sequences.  Having a dedicated pattern is more convenient than
6180 ;; creating a SEQUENCE for this special case.
6181 (define_insn "indirect_jump_and_restore_<mode>"
6182   [(set (pc) (match_operand:P 1 "register_operand" "d"))
6183    (set (match_operand:P 0 "register_operand" "=d")
6184         (match_operand:P 2 "register_operand" "y"))]
6185   ""
6186   "%(%<jr\t%1\;move\t%0,%2%>%)"
6187   [(set_attr "type" "multi")
6188    (set_attr "extended_mips16" "yes")])
6190 (define_expand "tablejump"
6191   [(set (pc)
6192         (match_operand 0 "register_operand"))
6193    (use (label_ref (match_operand 1 "")))]
6194   "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6196   if (TARGET_GPWORD)
6197     operands[0] = expand_binop (Pmode, add_optab, operands[0],
6198                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6199   else if (TARGET_RTP_PIC)
6200     {
6201       /* When generating RTP PIC, we use case table entries that are relative
6202          to the start of the function.  Add the function's address to the
6203          value we loaded.  */
6204       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6205       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6206                                   start, 0, 0, OPTAB_WIDEN);
6207     }
6209   emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6210   DONE;
6213 (define_insn "tablejump_<mode>"
6214   [(set (pc)
6215         (match_operand:P 0 "register_operand" "d"))
6216    (use (label_ref (match_operand 1 "" "")))]
6217   ""
6219   if (TARGET_MICROMIPS)
6220     return "%*jr%:\t%0";
6221   else
6222     return "%*j\t%0%/";
6224   [(set_attr "type" "jump")
6225    (set_attr "mode" "none")])
6227 ;; For MIPS16, we don't know whether a given jump table will use short or
6228 ;; word-sized offsets until late in compilation, when we are able to determine
6229 ;; the sizes of the insns which comprise the containing function.  This
6230 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6231 ;; the latter tries to calculate the index of the offset to jump through early
6232 ;; in compilation, i.e. at expand time, when nothing is known about the
6233 ;; eventual function layout.
6235 (define_expand "casesi"
6236   [(match_operand:SI 0 "register_operand" "")   ; index to jump on
6237    (match_operand:SI 1 "const_int_operand" "")  ; lower bound
6238    (match_operand:SI 2 "const_int_operand" "")  ; total range
6239    (match_operand 3 "" "")                      ; table label
6240    (match_operand 4 "" "")]                     ; out of range label
6241   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6243   if (operands[1] != const0_rtx)
6244     {
6245       rtx reg = gen_reg_rtx (SImode);
6246       rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6247       
6248       if (!arith_operand (offset, SImode))
6249         offset = force_reg (SImode, offset);
6250       
6251       emit_insn (gen_addsi3 (reg, operands[0], offset));
6252       operands[0] = reg;
6253     }
6255   if (!arith_operand (operands[0], SImode))
6256     operands[0] = force_reg (SImode, operands[0]);
6258   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6260   emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6261                               (operands[0], operands[2],
6262                                operands[3], operands[4])));
6264   DONE;
6267 (define_insn "casesi_internal_mips16_<mode>"
6268   [(set (pc)
6269      (if_then_else
6270        (leu (match_operand:SI 0 "register_operand" "d")
6271             (match_operand:SI 1 "arith_operand" "dI"))
6272        (unspec:P
6273         [(match_dup 0)
6274          (label_ref (match_operand 2 "" ""))]
6275         UNSPEC_CASESI_DISPATCH)
6276        (label_ref (match_operand 3 "" ""))))
6277    (clobber (match_scratch:P 4 "=d"))
6278    (clobber (match_scratch:P 5 "=d"))
6279    (clobber (reg:SI MIPS16_T_REGNUM))]
6280   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6282   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
6284   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6285   
6286   output_asm_insn ("sltu\t%0, %1", operands);
6287   output_asm_insn ("bteqz\t%3", operands);
6288   
6289   switch (GET_MODE (diff_vec))
6290     {
6291     case HImode:
6292       output_asm_insn ("sll\t%5, %0, 1", operands);
6293       output_asm_insn ("la\t%4, %2", operands);
6294       output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6295       output_asm_insn ("lh\t%5, 0(%5)", operands);
6296       break;
6297     
6298     case SImode:
6299       output_asm_insn ("sll\t%5, %0, 2", operands);
6300       output_asm_insn ("la\t%4, %2", operands);
6301       output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6302       output_asm_insn ("lw\t%5, 0(%5)", operands);
6303       break;
6305     default:
6306       gcc_unreachable ();
6307     }
6308   
6309   output_asm_insn ("addu\t%4, %4, %5", operands);
6310   
6311   return "j\t%4";
6313   [(set_attr "insn_count" "16")])
6315 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6316 ;; While it is possible to either pull it off the stack (in the
6317 ;; o32 case) or recalculate it given t9 and our target label,
6318 ;; it takes 3 or 4 insns to do so.
6320 (define_expand "builtin_setjmp_setup"
6321   [(use (match_operand 0 "register_operand"))]
6322   "TARGET_USE_GOT"
6324   rtx addr;
6326   addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6327   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6328   DONE;
6331 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
6332 ;; that older code did recalculate the gp from $25.  Continue to jump through
6333 ;; $25 for compatibility (we lose nothing by doing so).
6335 (define_expand "builtin_longjmp"
6336   [(use (match_operand 0 "register_operand"))]
6337   "TARGET_USE_GOT"
6339   /* The elements of the buffer are, in order:  */
6340   int W = GET_MODE_SIZE (Pmode);
6341   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6342   rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6343   rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6344   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6345   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6346   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6347      The target is bound to be using $28 as the global pointer
6348      but the current function might not be.  */
6349   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6351   /* This bit is similar to expand_builtin_longjmp except that it
6352      restores $gp as well.  */
6353   mips_emit_move (hard_frame_pointer_rtx, fp);
6354   mips_emit_move (pv, lab);
6355   emit_stack_restore (SAVE_NONLOCAL, stack);
6356   mips_emit_move (gp, gpv);
6357   emit_use (hard_frame_pointer_rtx);
6358   emit_use (stack_pointer_rtx);
6359   emit_use (gp);
6360   emit_indirect_jump (pv);
6361   DONE;
6365 ;;  ....................
6367 ;;      Function prologue/epilogue
6369 ;;  ....................
6372 (define_expand "prologue"
6373   [(const_int 1)]
6374   ""
6376   mips_expand_prologue ();
6377   DONE;
6380 ;; Block any insns from being moved before this point, since the
6381 ;; profiling call to mcount can use various registers that aren't
6382 ;; saved or used to pass arguments.
6384 (define_insn "blockage"
6385   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6386   ""
6387   ""
6388   [(set_attr "type" "ghost")
6389    (set_attr "mode" "none")])
6391 (define_insn "probe_stack_range_<P:mode>"
6392   [(set (match_operand:P 0 "register_operand" "=d")
6393         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6394                             (match_operand:P 2 "register_operand" "d")]
6395                             UNSPEC_PROBE_STACK_RANGE))]
6396   ""
6397  { return mips_output_probe_stack_range (operands[0], operands[2]); }
6398   [(set_attr "type" "unknown")
6399    (set_attr "can_delay" "no")
6400    (set_attr "mode" "<MODE>")])
6402 (define_expand "epilogue"
6403   [(const_int 2)]
6404   ""
6406   mips_expand_epilogue (false);
6407   DONE;
6410 (define_expand "sibcall_epilogue"
6411   [(const_int 2)]
6412   ""
6414   mips_expand_epilogue (true);
6415   DONE;
6418 ;; Trivial return.  Make it look like a normal return insn as that
6419 ;; allows jump optimizations to work better.
6421 (define_expand "return"
6422   [(simple_return)]
6423   "mips_can_use_return_insn ()"
6424   { mips_expand_before_return (); })
6426 (define_expand "simple_return"
6427   [(simple_return)]
6428   ""
6429   { mips_expand_before_return (); })
6431 (define_insn "*<optab>"
6432   [(any_return)]
6433   ""
6434   {
6435     if (TARGET_MICROMIPS)
6436       return "%*jr%:\t$31";
6437     else
6438       return "%*j\t$31%/";
6439   }
6440   [(set_attr "type"     "jump")
6441    (set_attr "mode"     "none")])
6443 ;; Normal return.
6445 (define_insn "<optab>_internal"
6446   [(any_return)
6447    (use (match_operand 0 "pmode_register_operand" ""))]
6448   ""
6450   if (TARGET_MICROMIPS)
6451     return "%*jr%:\t%0";
6452   else
6453     return "%*j\t%0%/";
6455   [(set_attr "type"     "jump")
6456    (set_attr "mode"     "none")])
6458 ;; Exception return.
6459 (define_insn "mips_eret"
6460   [(return)
6461    (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6462   ""
6463   "eret"
6464   [(set_attr "type"     "trap")
6465    (set_attr "mode"     "none")])
6467 ;; Debug exception return.
6468 (define_insn "mips_deret"
6469   [(return)
6470    (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6471   ""
6472   "deret"
6473   [(set_attr "type"     "trap")
6474    (set_attr "mode"     "none")])
6476 ;; Disable interrupts.
6477 (define_insn "mips_di"
6478   [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6479   ""
6480   "di"
6481   [(set_attr "type"     "trap")
6482    (set_attr "mode"     "none")])
6484 ;; Execution hazard barrier.
6485 (define_insn "mips_ehb"
6486   [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6487   ""
6488   "ehb"
6489   [(set_attr "type"     "trap")
6490    (set_attr "mode"     "none")])
6492 ;; Read GPR from previous shadow register set.
6493 (define_insn "mips_rdpgpr"
6494   [(set (match_operand:SI 0 "register_operand" "=d")
6495         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
6496                             UNSPEC_RDPGPR))]
6497   ""
6498   "rdpgpr\t%0,%1"
6499   [(set_attr "type"     "move")
6500    (set_attr "mode"     "SI")])
6502 ;; Move involving COP0 registers.
6503 (define_insn "cop0_move"
6504   [(set (match_operand:SI 0 "register_operand" "=B,d")
6505         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6506                             UNSPEC_COP0))]
6507   ""
6508 { return mips_output_move (operands[0], operands[1]); }
6509   [(set_attr "type"     "mtc,mfc")
6510    (set_attr "mode"     "SI")])
6512 ;; This is used in compiling the unwind routines.
6513 (define_expand "eh_return"
6514   [(use (match_operand 0 "general_operand"))]
6515   ""
6517   if (GET_MODE (operands[0]) != word_mode)
6518     operands[0] = convert_to_mode (word_mode, operands[0], 0);
6519   if (TARGET_64BIT)
6520     emit_insn (gen_eh_set_lr_di (operands[0]));
6521   else
6522     emit_insn (gen_eh_set_lr_si (operands[0]));
6523   DONE;
6526 ;; Clobber the return address on the stack.  We can't expand this
6527 ;; until we know where it will be put in the stack frame.
6529 (define_insn "eh_set_lr_si"
6530   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6531    (clobber (match_scratch:SI 1 "=&d"))]
6532   "! TARGET_64BIT"
6533   "#")
6535 (define_insn "eh_set_lr_di"
6536   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6537    (clobber (match_scratch:DI 1 "=&d"))]
6538   "TARGET_64BIT"
6539   "#")
6541 (define_split
6542   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6543    (clobber (match_scratch 1))]
6544   "reload_completed"
6545   [(const_int 0)]
6547   mips_set_return_address (operands[0], operands[1]);
6548   DONE;
6551 (define_expand "exception_receiver"
6552   [(const_int 0)]
6553   "TARGET_USE_GOT"
6555   /* See the comment above load_call<mode> for details.  */
6556   emit_insn (gen_set_got_version ());
6558   /* If we have a call-clobbered $gp, restore it from its save slot.  */
6559   if (HAVE_restore_gp_si)
6560     emit_insn (gen_restore_gp_si ());
6561   else if (HAVE_restore_gp_di)
6562     emit_insn (gen_restore_gp_di ());
6563   DONE;
6566 (define_expand "nonlocal_goto_receiver"
6567   [(const_int 0)]
6568   "TARGET_USE_GOT"
6570   /* See the comment above load_call<mode> for details.  */
6571   emit_insn (gen_set_got_version ());
6572   DONE;
6575 ;; Restore $gp from its .cprestore stack slot.  The instruction remains
6576 ;; volatile until all uses of $28 are exposed.
6577 (define_insn_and_split "restore_gp_<mode>"
6578   [(set (reg:P 28)
6579         (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6580    (clobber (match_scratch:P 0 "=&d"))]
6581   "TARGET_CALL_CLOBBERED_GP"
6582   "#"
6583   "&& epilogue_completed"
6584   [(const_int 0)]
6586   mips_restore_gp_from_cprestore_slot (operands[0]);
6587   DONE;
6589   [(set_attr "type" "ghost")])
6591 ;; Move between $gp and its register save slot.
6592 (define_insn_and_split "move_gp<mode>"
6593   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6594         (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6595                     UNSPEC_MOVE_GP))]
6596   ""
6597   { return mips_must_initialize_gp_p () ? "#" : ""; }
6598   "mips_must_initialize_gp_p ()"
6599   [(const_int 0)]
6601   mips_emit_move (operands[0], operands[1]);
6602   DONE;
6604   [(set_attr "type" "ghost")])
6607 ;;  ....................
6609 ;;      FUNCTION CALLS
6611 ;;  ....................
6613 ;; Instructions to load a call address from the GOT.  The address might
6614 ;; point to a function or to a lazy binding stub.  In the latter case,
6615 ;; the stub will use the dynamic linker to resolve the function, which
6616 ;; in turn will change the GOT entry to point to the function's real
6617 ;; address.
6619 ;; This means that every call, even pure and constant ones, can
6620 ;; potentially modify the GOT entry.  And once a stub has been called,
6621 ;; we must not call it again.
6623 ;; We represent this restriction using an imaginary, fixed, call-saved
6624 ;; register called GOT_VERSION_REGNUM.  The idea is to make the register
6625 ;; live throughout the function and to change its value after every
6626 ;; potential call site.  This stops any rtx value that uses the register
6627 ;; from being computed before an earlier call.  To do this, we:
6629 ;;    - Ensure that the register is live on entry to the function,
6630 ;;      so that it is never thought to be used uninitalized.
6632 ;;    - Ensure that the register is live on exit from the function,
6633 ;;      so that it is live throughout.
6635 ;;    - Make each call (lazily-bound or not) use the current value
6636 ;;      of GOT_VERSION_REGNUM, so that updates of the register are
6637 ;;      not moved across call boundaries.
6639 ;;    - Add "ghost" definitions of the register to the beginning of
6640 ;;      blocks reached by EH and ABNORMAL_CALL edges, because those
6641 ;;      edges may involve calls that normal paths don't.  (E.g. the
6642 ;;      unwinding code that handles a non-call exception may change
6643 ;;      lazily-bound GOT entries.)  We do this by making the
6644 ;;      exception_receiver and nonlocal_goto_receiver expanders emit
6645 ;;      a set_got_version instruction.
6647 ;;    - After each call (lazily-bound or not), use a "ghost"
6648 ;;      update_got_version instruction to change the register's value.
6649 ;;      This instruction mimics the _possible_ effect of the dynamic
6650 ;;      resolver during the call and it remains live even if the call
6651 ;;      itself becomes dead.
6653 ;;    - Leave GOT_VERSION_REGNUM out of all register classes.
6654 ;;      The register is therefore not a valid register_operand
6655 ;;      and cannot be moved to or from other registers.
6657 (define_insn "load_call<mode>"
6658   [(set (match_operand:P 0 "register_operand" "=d")
6659         (unspec:P [(match_operand:P 1 "register_operand" "d")
6660                    (match_operand:P 2 "immediate_operand" "")
6661                    (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6662   "TARGET_USE_GOT"
6663   "<load>\t%0,%R2(%1)"
6664   [(set_attr "got" "load")
6665    (set_attr "mode" "<MODE>")])
6667 (define_insn "set_got_version"
6668   [(set (reg:SI GOT_VERSION_REGNUM)
6669         (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6670   "TARGET_USE_GOT"
6671   ""
6672   [(set_attr "type" "ghost")])
6674 (define_insn "update_got_version"
6675   [(set (reg:SI GOT_VERSION_REGNUM)
6676         (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6677   "TARGET_USE_GOT"
6678   ""
6679   [(set_attr "type" "ghost")])
6681 ;; Sibling calls.  All these patterns use jump instructions.
6683 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6684 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
6685 ;; is defined in terms of call_insn_operand, the same is true of the
6686 ;; constraints.
6688 ;; When we use an indirect jump, we need a register that will be
6689 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
6690 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6691 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6692 ;; as well.
6694 (define_expand "sibcall"
6695   [(parallel [(call (match_operand 0 "")
6696                     (match_operand 1 ""))
6697               (use (match_operand 2 ""))        ;; next_arg_reg
6698               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6699   "TARGET_SIBCALLS"
6701   mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6702                     operands[1], operands[2], false);
6703   DONE;
6706 (define_insn "sibcall_internal"
6707   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6708          (match_operand 1 "" ""))]
6709   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6711   if (TARGET_MICROMIPS)
6712     return MICROMIPS_J ("j", operands, 0);
6713   else
6714     return MIPS_CALL ("j", operands, 0, 1);
6716   [(set_attr "jal" "indirect,direct")
6717    (set_attr "jal_macro" "no")])
6719 (define_expand "sibcall_value"
6720   [(parallel [(set (match_operand 0 "")
6721                    (call (match_operand 1 "")
6722                          (match_operand 2 "")))
6723               (use (match_operand 3 ""))])]             ;; next_arg_reg
6724   "TARGET_SIBCALLS"
6726   mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6727                     operands[2], operands[3], false);
6728   DONE;
6731 (define_insn "sibcall_value_internal"
6732   [(set (match_operand 0 "register_operand" "")
6733         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6734               (match_operand 2 "" "")))]
6735   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6737   if (TARGET_MICROMIPS)
6738     return MICROMIPS_J ("j", operands, 1);
6739   else
6740     return MIPS_CALL ("j", operands, 1, 2);
6742   [(set_attr "jal" "indirect,direct")
6743    (set_attr "jal_macro" "no")])
6745 (define_insn "sibcall_value_multiple_internal"
6746   [(set (match_operand 0 "register_operand" "")
6747         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6748               (match_operand 2 "" "")))
6749    (set (match_operand 3 "register_operand" "")
6750         (call (mem:SI (match_dup 1))
6751               (match_dup 2)))]
6752   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6754   if (TARGET_MICROMIPS)
6755     return MICROMIPS_J ("j", operands, 1);
6756   else
6757     return MIPS_CALL ("j", operands, 1, 2);
6759   [(set_attr "jal" "indirect,direct")
6760    (set_attr "jal_macro" "no")])
6762 (define_expand "call"
6763   [(parallel [(call (match_operand 0 "")
6764                     (match_operand 1 ""))
6765               (use (match_operand 2 ""))        ;; next_arg_reg
6766               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6767   ""
6769   mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6770                     operands[1], operands[2], false);
6771   DONE;
6774 ;; This instruction directly corresponds to an assembly-language "jal".
6775 ;; There are four cases:
6777 ;;    - -mno-abicalls:
6778 ;;        Both symbolic and register destinations are OK.  The pattern
6779 ;;        always expands to a single mips instruction.
6781 ;;    - -mabicalls/-mno-explicit-relocs:
6782 ;;        Again, both symbolic and register destinations are OK.
6783 ;;        The call is treated as a multi-instruction black box.
6785 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
6786 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
6787 ;;        instruction.
6789 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
6790 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
6791 ;;        "jalr $25" followed by an insn to reload $gp.
6793 ;; In the last case, we can generate the individual instructions with
6794 ;; a define_split.  There are several things to be wary of:
6796 ;;   - We can't expose the load of $gp before reload.  If we did,
6797 ;;     it might get removed as dead, but reload can introduce new
6798 ;;     uses of $gp by rematerializing constants.
6800 ;;   - We shouldn't restore $gp after calls that never return.
6801 ;;     It isn't valid to insert instructions between a noreturn
6802 ;;     call and the following barrier.
6804 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
6805 ;;     instruction preserves $gp and so have no effect on its liveness.
6806 ;;     But once we generate the separate insns, it becomes obvious that
6807 ;;     $gp is not live on entry to the call.
6809 (define_insn_and_split "call_internal"
6810   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6811          (match_operand 1 "" ""))
6812    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6813   ""
6814   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6815   "reload_completed && TARGET_SPLIT_CALLS"
6816   [(const_int 0)]
6818   mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6819   DONE;
6821   [(set_attr "jal" "indirect,direct")])
6823 (define_insn "call_split"
6824   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6825          (match_operand 1 "" ""))
6826    (clobber (reg:SI RETURN_ADDR_REGNUM))
6827    (clobber (reg:SI 28))]
6828   "TARGET_SPLIT_CALLS"
6829   { return MIPS_CALL ("jal", operands, 0, 1); }
6830   [(set_attr "jal" "indirect,direct")
6831    (set_attr "jal_macro" "no")])
6833 ;; A pattern for calls that must be made directly.  It is used for
6834 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6835 ;; stub; the linker relies on the call relocation type to detect when
6836 ;; such redirection is needed.
6837 (define_insn_and_split "call_internal_direct"
6838   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6839          (match_operand 1))
6840    (const_int 1)
6841    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6842   ""
6843   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6844   "reload_completed && TARGET_SPLIT_CALLS"
6845   [(const_int 0)]
6847   mips_split_call (curr_insn,
6848                    gen_call_direct_split (operands[0], operands[1]));
6849   DONE;
6851   [(set_attr "jal" "direct")])
6853 (define_insn "call_direct_split"
6854   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6855          (match_operand 1))
6856    (const_int 1)
6857    (clobber (reg:SI RETURN_ADDR_REGNUM))
6858    (clobber (reg:SI 28))]
6859   "TARGET_SPLIT_CALLS"
6860   { return MIPS_CALL ("jal", operands, 0, -1); }
6861   [(set_attr "jal" "direct")
6862    (set_attr "jal_macro" "no")])
6864 (define_expand "call_value"
6865   [(parallel [(set (match_operand 0 "")
6866                    (call (match_operand 1 "")
6867                          (match_operand 2 "")))
6868               (use (match_operand 3 ""))])]             ;; next_arg_reg
6869   ""
6871   mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6872                     operands[2], operands[3], false);
6873   DONE;
6876 ;; See comment for call_internal.
6877 (define_insn_and_split "call_value_internal"
6878   [(set (match_operand 0 "register_operand" "")
6879         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6880               (match_operand 2 "" "")))
6881    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6882   ""
6883   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6884   "reload_completed && TARGET_SPLIT_CALLS"
6885   [(const_int 0)]
6887   mips_split_call (curr_insn,
6888                    gen_call_value_split (operands[0], operands[1],
6889                                          operands[2]));
6890   DONE;
6892   [(set_attr "jal" "indirect,direct")])
6894 (define_insn "call_value_split"
6895   [(set (match_operand 0 "register_operand" "")
6896         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6897               (match_operand 2 "" "")))
6898    (clobber (reg:SI RETURN_ADDR_REGNUM))
6899    (clobber (reg:SI 28))]
6900   "TARGET_SPLIT_CALLS"
6901   { return MIPS_CALL ("jal", operands, 1, 2); }
6902   [(set_attr "jal" "indirect,direct")
6903    (set_attr "jal_macro" "no")])
6905 ;; See call_internal_direct.
6906 (define_insn_and_split "call_value_internal_direct"
6907   [(set (match_operand 0 "register_operand")
6908         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6909               (match_operand 2)))
6910    (const_int 1)
6911    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6912   ""
6913   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6914   "reload_completed && TARGET_SPLIT_CALLS"
6915   [(const_int 0)]
6917   mips_split_call (curr_insn,
6918                    gen_call_value_direct_split (operands[0], operands[1],
6919                                                 operands[2]));
6920   DONE;
6922   [(set_attr "jal" "direct")])
6924 (define_insn "call_value_direct_split"
6925   [(set (match_operand 0 "register_operand")
6926         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6927               (match_operand 2)))
6928    (const_int 1)
6929    (clobber (reg:SI RETURN_ADDR_REGNUM))
6930    (clobber (reg:SI 28))]
6931   "TARGET_SPLIT_CALLS"
6932   { return MIPS_CALL ("jal", operands, 1, -1); }
6933   [(set_attr "jal" "direct")
6934    (set_attr "jal_macro" "no")])
6936 ;; See comment for call_internal.
6937 (define_insn_and_split "call_value_multiple_internal"
6938   [(set (match_operand 0 "register_operand" "")
6939         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6940               (match_operand 2 "" "")))
6941    (set (match_operand 3 "register_operand" "")
6942         (call (mem:SI (match_dup 1))
6943               (match_dup 2)))
6944    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6945   ""
6946   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6947   "reload_completed && TARGET_SPLIT_CALLS"
6948   [(const_int 0)]
6950   mips_split_call (curr_insn,
6951                    gen_call_value_multiple_split (operands[0], operands[1],
6952                                                   operands[2], operands[3]));
6953   DONE;
6955   [(set_attr "jal" "indirect,direct")])
6957 (define_insn "call_value_multiple_split"
6958   [(set (match_operand 0 "register_operand" "")
6959         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6960               (match_operand 2 "" "")))
6961    (set (match_operand 3 "register_operand" "")
6962         (call (mem:SI (match_dup 1))
6963               (match_dup 2)))
6964    (clobber (reg:SI RETURN_ADDR_REGNUM))
6965    (clobber (reg:SI 28))]
6966   "TARGET_SPLIT_CALLS"
6967   { return MIPS_CALL ("jal", operands, 1, 2); }
6968   [(set_attr "jal" "indirect,direct")
6969    (set_attr "jal_macro" "no")])
6971 ;; Call subroutine returning any type.
6973 (define_expand "untyped_call"
6974   [(parallel [(call (match_operand 0 "")
6975                     (const_int 0))
6976               (match_operand 1 "")
6977               (match_operand 2 "")])]
6978   ""
6980   int i;
6982   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6984   for (i = 0; i < XVECLEN (operands[2], 0); i++)
6985     {
6986       rtx set = XVECEXP (operands[2], 0, i);
6987       mips_emit_move (SET_DEST (set), SET_SRC (set));
6988     }
6990   emit_insn (gen_blockage ());
6991   DONE;
6995 ;;  ....................
6997 ;;      MISC.
6999 ;;  ....................
7003 (define_insn "prefetch"
7004   [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7005              (match_operand 1 "const_int_operand" "n")
7006              (match_operand 2 "const_int_operand" "n"))]
7007   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7009   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
7010     {
7011       /* Loongson 2[ef] and Loongson 3a use load to $0 for prefetching.  */
7012       if (TARGET_64BIT)
7013         return "ld\t$0,%a0";
7014       else
7015         return "lw\t$0,%a0";
7016     }
7017   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7018   return "pref\t%1,%a0";
7020   [(set_attr "type" "prefetch")])
7022 (define_insn "*prefetch_indexed_<mode>"
7023   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7024                      (match_operand:P 1 "register_operand" "d"))
7025              (match_operand 2 "const_int_operand" "n")
7026              (match_operand 3 "const_int_operand" "n"))]
7027   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7029   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7030   return "prefx\t%2,%1(%0)";
7032   [(set_attr "type" "prefetchx")])
7034 (define_insn "nop"
7035   [(const_int 0)]
7036   ""
7037   "%(nop%)"
7038   [(set_attr "type"     "nop")
7039    (set_attr "mode"     "none")])
7041 ;; Like nop, but commented out when outside a .set noreorder block.
7042 (define_insn "hazard_nop"
7043   [(const_int 1)]
7044   ""
7045   {
7046     if (mips_noreorder.nesting_level > 0)
7047       return "nop";
7048     else
7049       return "#nop";
7050   }
7051   [(set_attr "type"     "nop")])
7053 ;; MIPS4 Conditional move instructions.
7055 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7056   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7057         (if_then_else:GPR
7058          (match_operator 4 "equality_operator"
7059                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7060                  (const_int 0)])
7061          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7062          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7063   "ISA_HAS_CONDMOVE"
7064   "@
7065     mov%T4\t%0,%z2,%1
7066     mov%t4\t%0,%z3,%1"
7067   [(set_attr "type" "condmove")
7068    (set_attr "mode" "<GPR:MODE>")])
7070 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7071   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7072        (if_then_else:GPR
7073         (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7074         (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7075         (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7076   "ISA_HAS_CONDMOVE"
7077   "@
7078     movn\t%0,%z2,%1
7079     movz\t%0,%z3,%1"
7080   [(set_attr "type" "condmove")
7081    (set_attr "mode" "<GPR:MODE>")])
7083 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7084   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7085         (if_then_else:SCALARF
7086          (match_operator 4 "equality_operator"
7087                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7088                  (const_int 0)])
7089          (match_operand:SCALARF 2 "register_operand" "f,0")
7090          (match_operand:SCALARF 3 "register_operand" "0,f")))]
7091   "ISA_HAS_FP_CONDMOVE"
7092   "@
7093     mov%T4.<fmt>\t%0,%2,%1
7094     mov%t4.<fmt>\t%0,%3,%1"
7095   [(set_attr "type" "condmove")
7096    (set_attr "mode" "<SCALARF:MODE>")])
7098 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7099   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7100         (if_then_else:GPR
7101          (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7102                            (const_int 0))
7103          (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7104          (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7105   "ISA_HAS_SEL
7106    && (register_operand (operands[2], <GPR:MODE>mode)
7107        != register_operand (operands[3], <GPR:MODE>mode))"
7108   "@
7109    <sel>\t%0,%2,%1
7110    <selinv>\t%0,%3,%1"
7111   [(set_attr "type" "condmove")
7112    (set_attr "mode" "<GPR:MODE>")])
7114 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7115 ;; argument if the 1st is zero.  This means operand 2 and 3 are
7116 ;; inverted in the instruction.
7118 (define_insn "*sel<mode>"
7119   [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7120         (if_then_else:SCALARF
7121          (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7122                  (const_int 0))
7123          (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7124          (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7125   "ISA_HAS_SEL && ISA_HAS_CCF"
7126   "@
7127    sel.<fmt>\t%0,%3,%2
7128    seleqz.<fmt>\t%0,%3,%1
7129    selnez.<fmt>\t%0,%2,%1"
7130   [(set_attr "type" "condmove")
7131    (set_attr "mode" "<SCALARF:MODE>")])
7133 ;; These are the main define_expand's used to make conditional moves.
7135 (define_expand "mov<mode>cc"
7136   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7137    (set (match_operand:GPR 0 "register_operand")
7138         (if_then_else:GPR (match_dup 5)
7139                           (match_operand:GPR 2 "reg_or_0_operand")
7140                           (match_operand:GPR 3 "reg_or_0_operand")))]
7141   "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7143   if (!ISA_HAS_FP_CONDMOVE
7144       && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7145     FAIL;
7147   mips_expand_conditional_move (operands);
7148   DONE;
7151 (define_expand "mov<mode>cc"
7152   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7153    (set (match_operand:SCALARF 0 "register_operand")
7154         (if_then_else:SCALARF (match_dup 5)
7155                               (match_operand:SCALARF 2 "reg_or_0_operand")
7156                               (match_operand:SCALARF 3 "reg_or_0_operand")))]
7157   "ISA_HAS_FP_CONDMOVE
7158    || (ISA_HAS_SEL && ISA_HAS_CCF)"
7160   if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7161     FAIL;
7163   /* Workaround an LRA bug which means that tied operands in the sel.fmt
7164      pattern lead to the double precision destination of sel.d getting
7165      reloaded with the full register file usable and the restrictions on
7166      whether the CCFmode input can be used in odd-numbered single-precision
7167      registers are ignored.  For consistency reasons the CCF mode values
7168      must be guaranteed to only exist in the even-registers because of
7169      the unusual duality between single and double precision values.  */
7170   if (ISA_HAS_SEL && <MODE>mode == DFmode
7171       && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7172     FAIL;
7174   mips_expand_conditional_move (operands);
7175   DONE;
7179 ;;  ....................
7181 ;;      mips16 inline constant tables
7183 ;;  ....................
7186 (define_insn "consttable_tls_reloc"
7187   [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7188                      (match_operand 1 "const_int_operand" "")]
7189                     UNSPEC_CONSTTABLE_INT)]
7190   "TARGET_MIPS16_PCREL_LOADS"
7191   { return mips_output_tls_reloc_directive (&operands[0]); }
7192   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7194 (define_insn "consttable_int"
7195   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7196                      (match_operand 1 "const_int_operand" "")]
7197                     UNSPEC_CONSTTABLE_INT)]
7198   "TARGET_MIPS16"
7200   assemble_integer (mips_strip_unspec_address (operands[0]),
7201                     INTVAL (operands[1]),
7202                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
7203   return "";
7205   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7207 (define_insn "consttable_float"
7208   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7209                     UNSPEC_CONSTTABLE_FLOAT)]
7210   "TARGET_MIPS16"
7212   REAL_VALUE_TYPE d;
7214   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7215   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
7216   assemble_real (d, GET_MODE (operands[0]),
7217                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
7218   return "";
7220   [(set (attr "length")
7221         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7223 (define_insn "align"
7224   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7225   ""
7226   ".align\t%0"
7227   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7229 (define_split
7230   [(match_operand 0 "small_data_pattern")]
7231   "reload_completed"
7232   [(match_dup 0)]
7233   { operands[0] = mips_rewrite_small_data (operands[0]); })
7236 ;;  ....................
7238 ;;      MIPS16e Save/Restore
7240 ;;  ....................
7243 (define_insn "*mips16e_save_restore"
7244   [(match_parallel 0 ""
7245        [(set (match_operand:SI 1 "register_operand")
7246              (plus:SI (match_dup 1)
7247                       (match_operand:SI 2 "const_int_operand")))])]
7248   "operands[1] == stack_pointer_rtx
7249    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7250   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7251   [(set_attr "type" "arith")
7252    (set_attr "extended_mips16" "yes")])
7254 ;; Thread-Local Storage
7256 ;; The TLS base pointer is accessed via "rdhwr $3, $29".  No current
7257 ;; MIPS architecture defines this register, and no current
7258 ;; implementation provides it; instead, any OS which supports TLS is
7259 ;; expected to trap and emulate this instruction.  rdhwr is part of the
7260 ;; MIPS 32r2 specification, but we use it on any architecture because
7261 ;; we expect it to be emulated.  Use .set to force the assembler to
7262 ;; accept it.
7264 ;; We do not use a constraint to force the destination to be $3
7265 ;; because $3 can appear explicitly as a function return value.
7266 ;; If we leave the use of $3 implicit in the constraints until
7267 ;; reload, we may end up making a $3 return value live across
7268 ;; the instruction, leading to a spill failure when reloading it.
7269 (define_insn_and_split "tls_get_tp_<mode>"
7270   [(set (match_operand:P 0 "register_operand" "=d")
7271         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7272    (clobber (reg:P TLS_GET_TP_REGNUM))]
7273   "HAVE_AS_TLS && !TARGET_MIPS16"
7274   "#"
7275   "&& reload_completed"
7276   [(set (reg:P TLS_GET_TP_REGNUM)
7277         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7278    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7279   ""
7280   [(set_attr "type" "unknown")
7281    (set_attr "mode" "<MODE>")
7282    (set_attr "insn_count" "2")])
7284 (define_insn "*tls_get_tp_<mode>_split"
7285   [(set (reg:P TLS_GET_TP_REGNUM)
7286         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7287   "HAVE_AS_TLS && !TARGET_MIPS16"
7288   {
7289     if (mips_isa_rev >= 2)
7290       return "rdhwr\t$3,$29";
7292     return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7293   }
7294   [(set_attr "type" "unknown")
7295    ; Since rdhwr always generates a trap for now, putting it in a delay
7296    ; slot would make the kernel's emulation of it much slower.
7297    (set_attr "can_delay" "no")
7298    (set_attr "mode" "<MODE>")])
7300 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7301 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7302 ;; accessible in MIPS16.
7304 ;; This is not represented as a call insn, to avoid the
7305 ;; unnecesarry clobbering of caller-save registers by a
7306 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7308 ;; A $25 clobber is added to cater for a $25 load stub added by the
7309 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7311 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7312   [(set (match_operand:P 0 "register_operand" "=d")
7313         (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7314                   UNSPEC_TLS_GET_TP))
7315    (clobber (reg:P TLS_GET_TP_REGNUM))
7316    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7317    (clobber (reg:P RETURN_ADDR_REGNUM))]
7318   "HAVE_AS_TLS && TARGET_MIPS16"
7319   "#"
7320   "&& reload_completed"
7321   [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7322                    (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7323               (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7324               (clobber (reg:P RETURN_ADDR_REGNUM))])
7325    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7326   ""
7327   [(set_attr "type" "multi")
7328    (set_attr "insn_count" "4")
7329    (set_attr "mode" "<MODE>")])
7331 (define_insn "*tls_get_tp_mips16_call_<mode>"
7332   [(set (reg:P TLS_GET_TP_REGNUM)
7333         (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7334                   UNSPEC_TLS_GET_TP))
7335    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7336    (clobber (reg:P RETURN_ADDR_REGNUM))]
7337   "HAVE_AS_TLS && TARGET_MIPS16"
7338   { return MIPS_CALL ("jal", operands, 0, -1); }
7339   [(set_attr "type" "call")
7340    (set_attr "insn_count" "3")
7341    (set_attr "mode" "<MODE>")])
7343 ;; Named pattern for expanding thread pointer reference.
7344 (define_expand "get_thread_pointer<mode>"
7345   [(match_operand:P 0 "register_operand" "=d")]
7346   "HAVE_AS_TLS"
7348   mips_expand_thread_pointer (operands[0]);
7349   DONE;
7352 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7353 (define_expand "mips_get_fcsr"
7354   [(set (match_operand:SI 0 "register_operand")
7355         (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7356   "TARGET_HARD_FLOAT_ABI"
7358   if (TARGET_MIPS16)
7359     {
7360       mips16_expand_get_fcsr (operands[0]);
7361       DONE;
7362     }
7365 (define_insn "*mips_get_fcsr"
7366   [(set (match_operand:SI 0 "register_operand" "=d")
7367         (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7368   "TARGET_HARD_FLOAT"
7369   "cfc1\t%0,$31")
7371 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7372 (define_insn "mips_get_fcsr_mips16_<mode>"
7373   [(set (reg:SI GET_FCSR_REGNUM)
7374         (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7375                    UNSPEC_GET_FCSR))
7376    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7377    (clobber (reg:P RETURN_ADDR_REGNUM))]
7378   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7379   { return MIPS_CALL ("jal", operands, 0, -1); }
7380   [(set_attr "type" "call")
7381    (set_attr "insn_count" "3")])
7383 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7384 (define_expand "mips_set_fcsr"
7385   [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7386                     UNSPEC_SET_FCSR)]
7387   "TARGET_HARD_FLOAT_ABI"
7389   if (TARGET_MIPS16)
7390     {
7391       mips16_expand_set_fcsr (operands[0]);
7392       DONE;
7393     }
7396 (define_insn "*mips_set_fcsr"
7397   [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7398                     UNSPEC_SET_FCSR)]
7399   "TARGET_HARD_FLOAT"
7400   "ctc1\t%0,$31")
7402 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7403 (define_insn "mips_set_fcsr_mips16_<mode>"
7404   [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7405                         (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7406    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7407    (clobber (reg:P RETURN_ADDR_REGNUM))]
7408   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7409   { return MIPS_CALL ("jal", operands, 0, -1); }
7410   [(set_attr "type" "call")
7411    (set_attr "insn_count" "3")])
7413 ;; Match paired HI/SI/SF/DFmode load/stores.
7414 (define_insn "*join2_load_store<JOIN_MODE:mode>"
7415   [(set (match_operand:JOIN_MODE 0 "nonimmediate_operand" "=d,f,m,m")
7416         (match_operand:JOIN_MODE 1 "nonimmediate_operand" "m,m,d,f"))
7417    (set (match_operand:JOIN_MODE 2 "nonimmediate_operand" "=d,f,m,m")
7418         (match_operand:JOIN_MODE 3 "nonimmediate_operand" "m,m,d,f"))]
7419   "ENABLE_LD_ST_PAIRS && reload_completed"
7420   {
7421     bool load_p = (which_alternative == 0 || which_alternative == 1);
7422     /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7423        Hardware does not bond those loads, even when they are consecutive.
7424        However, order of the loads need to be checked for correctness.  */
7425     if (!load_p || !reg_overlap_mentioned_p (operands[0], operands[1]))
7426       {
7427         output_asm_insn (mips_output_move (operands[0], operands[1]),
7428                          operands);
7429         output_asm_insn (mips_output_move (operands[2], operands[3]),
7430                          &operands[2]);
7431       }
7432     else
7433       {
7434         output_asm_insn (mips_output_move (operands[2], operands[3]),
7435                          &operands[2]);
7436         output_asm_insn (mips_output_move (operands[0], operands[1]),
7437                          operands);
7438       }
7439     return "";
7440   }
7441   [(set_attr "move_type" "load,fpload,store,fpstore")
7442    (set_attr "insn_count" "2,2,2,2")])
7444 ;; 2 HI/SI/SF/DF loads are joined.
7445 ;; P5600 does not support bonding of two LBs, hence QI mode is not included.
7446 ;; The loads must be non-volatile as they might be reordered at the time of asm
7447 ;; generation.
7448 (define_peephole2
7449   [(set (match_operand:JOIN_MODE 0 "register_operand")
7450         (match_operand:JOIN_MODE 1 "non_volatile_mem_operand"))
7451    (set (match_operand:JOIN_MODE 2 "register_operand")
7452         (match_operand:JOIN_MODE 3 "non_volatile_mem_operand"))]
7453   "ENABLE_LD_ST_PAIRS
7454    && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, true)"
7455   [(parallel [(set (match_dup 0)
7456                    (match_dup 1))
7457               (set (match_dup 2)
7458                    (match_dup 3))])]
7459   "")
7461 ;; 2 HI/SI/SF/DF stores are joined.
7462 ;; P5600 does not support bonding of two SBs, hence QI mode is not included.
7463 (define_peephole2
7464   [(set (match_operand:JOIN_MODE 0 "memory_operand")
7465         (match_operand:JOIN_MODE 1 "register_operand"))
7466    (set (match_operand:JOIN_MODE 2 "memory_operand")
7467         (match_operand:JOIN_MODE 3 "register_operand"))]
7468   "ENABLE_LD_ST_PAIRS
7469    && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, false)"
7470   [(parallel [(set (match_dup 0)
7471                    (match_dup 1))
7472               (set (match_dup 2)
7473                    (match_dup 3))])]
7474   "")
7476 ;; Match paired HImode loads.
7477 (define_insn "*join2_loadhi"
7478   [(set (match_operand:SI 0 "register_operand" "=r")
7479         (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand" "m")))
7480    (set (match_operand:SI 2 "register_operand" "=r")
7481         (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand" "m")))]
7482   "ENABLE_LD_ST_PAIRS && reload_completed"
7483   {
7484     /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7485        Hardware does not bond those loads, even when they are consecutive.
7486        However, order of the loads need to be checked for correctness.  */
7487     if (!reg_overlap_mentioned_p (operands[0], operands[1]))
7488       {
7489         output_asm_insn ("lh<u>\t%0,%1", operands);
7490         output_asm_insn ("lh<u>\t%2,%3", operands);
7491       }
7492     else
7493       {
7494         output_asm_insn ("lh<u>\t%2,%3", operands);
7495         output_asm_insn ("lh<u>\t%0,%1", operands);
7496       }
7498     return "";
7499   }
7500   [(set_attr "move_type" "load")
7501    (set_attr "insn_count" "2")])
7504 ;; 2 HI loads are joined.
7505 (define_peephole2
7506   [(set (match_operand:SI 0 "register_operand")
7507         (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand")))
7508    (set (match_operand:SI 2 "register_operand")
7509         (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand")))]
7510   "ENABLE_LD_ST_PAIRS
7511    && mips_load_store_bonding_p (operands, HImode, true)"
7512   [(parallel [(set (match_dup 0)
7513                    (any_extend:SI (match_dup 1)))
7514               (set (match_dup 2)
7515                    (any_extend:SI (match_dup 3)))])]
7516   "")
7519 ;; Synchronization instructions.
7521 (include "sync.md")
7523 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7525 (include "mips-ps-3d.md")
7527 ; The MIPS DSP Instructions.
7529 (include "mips-dsp.md")
7531 ; The MIPS DSP REV 2 Instructions.
7533 (include "mips-dspr2.md")
7535 ; MIPS fixed-point instructions.
7536 (include "mips-fixed.md")
7538 ; microMIPS patterns.
7539 (include "micromips.md")
7541 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7542 (include "loongson.md")
7544 (define_c_enum "unspec" [
7545   UNSPEC_ADDRESS_FIRST