2015-04-24 Steve Ellcey <sellcey@imgtec.com>
[official-gcc.git] / gcc / config / mips / mips.md
blobed4c0ba65f86725644f154fed0aa30cec918a002
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])
758 ;; This mode iterator allows :HILO to be used as the mode of the
759 ;; concatenated HI and LO registers.
760 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
762 ;; This mode iterator allows :P to be used for patterns that operate on
763 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
764 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
766 ;; This mode iterator allows :MOVECC to be used anywhere that a
767 ;; conditional-move-type condition is needed.
768 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
769                               (CC "TARGET_HARD_FLOAT
770                                    && !TARGET_LOONGSON_2EF
771                                    && !TARGET_MIPS5900")])
773 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
774 ;; is needed.
775 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
776                             (CCF "ISA_HAS_CCF")])
778 ;; 32-bit integer moves for which we provide move patterns.
779 (define_mode_iterator IMOVE32
780   [SI
781    (V2HI "TARGET_DSP")
782    (V4QI "TARGET_DSP")
783    (V2HQ "TARGET_DSP")
784    (V2UHQ "TARGET_DSP")
785    (V2HA "TARGET_DSP")
786    (V2UHA "TARGET_DSP")
787    (V4QQ "TARGET_DSP")
788    (V4UQQ "TARGET_DSP")])
790 ;; 64-bit modes for which we provide move patterns.
791 (define_mode_iterator MOVE64
792   [DI DF
793    (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
794    (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
795    (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
796    (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
798 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
799 (define_mode_iterator MOVE128 [TI TF])
801 ;; This mode iterator allows the QI and HI extension patterns to be
802 ;; defined from the same template.
803 (define_mode_iterator SHORT [QI HI])
805 ;; Likewise the 64-bit truncate-and-shift patterns.
806 (define_mode_iterator SUBDI [QI HI SI])
808 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
809 ;; floating-point mode is allowed.
810 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
811                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
812                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
814 ;; Like ANYF, but only applies to scalar modes.
815 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
816                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
818 ;; A floating-point mode for which moves involving FPRs may need to be split.
819 (define_mode_iterator SPLITF
820   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
821    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
822    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
823    (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
824    (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
825    (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
826    (TF "TARGET_64BIT && TARGET_FLOAT64")])
828 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
829 ;; 32-bit version and "dsubu" in the 64-bit version.
830 (define_mode_attr d [(SI "") (DI "d")
831                      (QQ "") (HQ "") (SQ "") (DQ "d")
832                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
833                      (HA "") (SA "") (DA "d")
834                      (UHA "") (USA "") (UDA "d")])
836 ;; Same as d but upper-case.
837 (define_mode_attr D [(SI "") (DI "D")
838                      (QQ "") (HQ "") (SQ "") (DQ "D")
839                      (UQQ "") (UHQ "") (USQ "") (UDQ "D")
840                      (HA "") (SA "") (DA "D")
841                      (UHA "") (USA "") (UDA "D")])
843 ;; This attribute gives the length suffix for a load or store instruction.
844 ;; The same suffixes work for zero and sign extensions.
845 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
846 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
848 ;; This attributes gives the mode mask of a SHORT.
849 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
851 ;; Mode attributes for GPR loads.
852 (define_mode_attr load [(SI "lw") (DI "ld")])
853 ;; Instruction names for stores.
854 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
856 ;; Similarly for MIPS IV indexed FPR loads and stores.
857 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
858 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
860 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
861 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
862 ;; field but the equivalent daddiu has only a 5-bit field.
863 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
865 ;; This attribute gives the best constraint to use for registers of
866 ;; a given mode.
867 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
869 ;; This attribute gives the format suffix for floating-point operations.
870 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
872 ;; This attribute gives the upper-case mode name for one unit of a
873 ;; floating-point mode.
874 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
876 ;; This attribute gives the integer mode that has the same size as a
877 ;; fixed-point mode.
878 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
879                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
880                          (HA "HI") (SA "SI") (DA "DI")
881                          (UHA "HI") (USA "SI") (UDA "DI")
882                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
883                          (V2HQ "SI") (V2HA "SI")])
885 ;; This attribute gives the integer mode that has half the size of
886 ;; the controlling mode.
887 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
888                             (V2SI "SI") (V4HI "SI") (V8QI "SI")
889                             (TF "DI")])
891 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
893 ;; In certain cases, div.s and div.ps may have a rounding error
894 ;; and/or wrong inexact flag.
896 ;; Therefore, we only allow div.s if not working around SB-1 rev2
897 ;; errata or if a slight loss of precision is OK.
898 (define_mode_attr divide_condition
899   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
900    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
902 ;; This attribute gives the conditions under which SQRT.fmt instructions
903 ;; can be used.
904 (define_mode_attr sqrt_condition
905   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
907 ;; This attribute provides the correct mnemonic for each FP condition mode.
908 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
910 ;; This code iterator allows signed and unsigned widening multiplications
911 ;; to use the same template.
912 (define_code_iterator any_extend [sign_extend zero_extend])
914 ;; This code iterator allows the two right shift instructions to be
915 ;; generated from the same template.
916 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
918 ;; This code iterator allows the three shift instructions to be generated
919 ;; from the same template.
920 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
922 ;; This code iterator allows unsigned and signed division to be generated
923 ;; from the same template.
924 (define_code_iterator any_div [div udiv])
926 ;; This code iterator allows unsigned and signed modulus to be generated
927 ;; from the same template.
928 (define_code_iterator any_mod [mod umod])
930 ;; This code iterator allows all native floating-point comparisons to be
931 ;; generated from the same template.
932 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
933                              (ordered "ISA_HAS_CCF")
934                              (ltgt "ISA_HAS_CCF")
935                              (ne "ISA_HAS_CCF")])
937 ;; This code iterator is used for comparisons that can be implemented
938 ;; by swapping the operands.
939 (define_code_iterator swapped_fcond [ge gt unge ungt])
941 ;; Equality operators.
942 (define_code_iterator equality_op [eq ne])
944 ;; These code iterators allow the signed and unsigned scc operations to use
945 ;; the same template.
946 (define_code_iterator any_gt [gt gtu])
947 (define_code_iterator any_ge [ge geu])
948 (define_code_iterator any_lt [lt ltu])
949 (define_code_iterator any_le [le leu])
951 (define_code_iterator any_return [return simple_return])
953 ;; <u> expands to an empty string when doing a signed operation and
954 ;; "u" when doing an unsigned operation.
955 (define_code_attr u [(sign_extend "") (zero_extend "u")
956                      (div "") (udiv "u")
957                      (mod "") (umod "u")
958                      (gt "") (gtu "u")
959                      (ge "") (geu "u")
960                      (lt "") (ltu "u")
961                      (le "") (leu "u")])
963 ;; <U> is like <u> except uppercase.
964 (define_code_attr U [(sign_extend "") (zero_extend "U")])
966 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
967 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
969 ;; <optab> expands to the name of the optab for a particular code.
970 (define_code_attr optab [(ashift "ashl")
971                          (ashiftrt "ashr")
972                          (lshiftrt "lshr")
973                          (ior "ior")
974                          (xor "xor")
975                          (and "and")
976                          (plus "add")
977                          (minus "sub")
978                          (return "return")
979                          (simple_return "simple_return")])
981 ;; <insn> expands to the name of the insn that implements a particular code.
982 (define_code_attr insn [(ashift "sll")
983                         (ashiftrt "sra")
984                         (lshiftrt "srl")
985                         (ior "or")
986                         (xor "xor")
987                         (and "and")
988                         (plus "addu")
989                         (minus "subu")])
991 ;; <immediate_insn> expands to the name of the insn that implements
992 ;; a particular code to operate on immediate values.
993 (define_code_attr immediate_insn [(ior "ori")
994                                   (xor "xori")
995                                   (and "andi")])
997 (define_code_attr shift_compression [(ashift "micromips32")
998                                      (lshiftrt "micromips32")
999                                      (ashiftrt "none")])
1001 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1002 (define_code_attr fcond [(unordered "un")
1003                          (uneq "ueq")
1004                          (unlt "ult")
1005                          (unle "ule")
1006                          (eq "eq")
1007                          (lt "lt")
1008                          (le "le")
1009                          (ordered "or")
1010                          (ltgt "ne")
1011                          (ne "une")])
1013 ;; Similar, but for swapped conditions.
1014 (define_code_attr swapped_fcond [(ge "le")
1015                                  (gt "lt")
1016                                  (unge "ule")
1017                                  (ungt "ult")])
1019 ;; The value of the bit when the branch is taken for branch_bit patterns.
1020 ;; Comparison is always against zero so this depends on the operator.
1021 (define_code_attr bbv [(eq "0") (ne "1")])
1023 ;; This is the inverse value of bbv.
1024 (define_code_attr bbinv [(eq "1") (ne "0")])
1026 ;; The sel mnemonic to use depending on the condition test.
1027 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1028 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1030 ;; .........................
1032 ;;      Branch, call and jump delay slots
1034 ;; .........................
1036 (define_delay (and (eq_attr "type" "branch")
1037                    (not (match_test "TARGET_MIPS16"))
1038                    (eq_attr "branch_likely" "yes"))
1039   [(eq_attr "can_delay" "yes")
1040    (nil)
1041    (eq_attr "can_delay" "yes")])
1043 ;; Branches that don't have likely variants do not annul on false.
1044 (define_delay (and (eq_attr "type" "branch")
1045                    (not (match_test "TARGET_MIPS16"))
1046                    (eq_attr "branch_likely" "no"))
1047   [(eq_attr "can_delay" "yes")
1048    (nil)
1049    (nil)])
1051 (define_delay (eq_attr "type" "jump")
1052   [(eq_attr "can_delay" "yes")
1053    (nil)
1054    (nil)])
1056 (define_delay (and (eq_attr "type" "call")
1057                    (eq_attr "jal_macro" "no"))
1058   [(eq_attr "can_delay" "yes")
1059    (nil)
1060    (nil)])
1062 ;; Pipeline descriptions.
1064 ;; generic.md provides a fallback for processors without a specific
1065 ;; pipeline description.  It is derived from the old define_function_unit
1066 ;; version and uses the "alu" and "imuldiv" units declared below.
1068 ;; Some of the processor-specific files are also derived from old
1069 ;; define_function_unit descriptions and simply override the parts of
1070 ;; generic.md that don't apply.  The other processor-specific files
1071 ;; are self-contained.
1072 (define_automaton "alu,imuldiv")
1074 (define_cpu_unit "alu" "alu")
1075 (define_cpu_unit "imuldiv" "imuldiv")
1077 ;; Ghost instructions produce no real code and introduce no hazards.
1078 ;; They exist purely to express an effect on dataflow.
1079 (define_insn_reservation "ghost" 0
1080   (eq_attr "type" "ghost")
1081   "nothing")
1083 (include "p5600.md")
1084 (include "4k.md")
1085 (include "5k.md")
1086 (include "20kc.md")
1087 (include "24k.md")
1088 (include "74k.md")
1089 (include "3000.md")
1090 (include "4000.md")
1091 (include "4100.md")
1092 (include "4130.md")
1093 (include "4300.md")
1094 (include "4600.md")
1095 (include "5000.md")
1096 (include "5400.md")
1097 (include "5500.md")
1098 (include "6000.md")
1099 (include "7000.md")
1100 (include "9000.md")
1101 (include "10000.md")
1102 (include "loongson2ef.md")
1103 (include "loongson3a.md")
1104 (include "octeon.md")
1105 (include "sb1.md")
1106 (include "sr71k.md")
1107 (include "xlr.md")
1108 (include "xlp.md")
1109 (include "generic.md")
1112 ;;  ....................
1114 ;;      CONDITIONAL TRAPS
1116 ;;  ....................
1119 (define_insn "trap"
1120   [(trap_if (const_int 1) (const_int 0))]
1121   ""
1123   if (ISA_HAS_COND_TRAP)
1124     return "teq\t$0,$0";
1125   else if (TARGET_MIPS16)
1126     return "break 0";
1127   else
1128     return "break";
1130   [(set_attr "type" "trap")])
1132 (define_expand "ctrap<mode>4"
1133   [(trap_if (match_operator 0 "comparison_operator"
1134                             [(match_operand:GPR 1 "reg_or_0_operand")
1135                              (match_operand:GPR 2 "arith_operand")])
1136             (match_operand 3 "const_0_operand"))]
1137   "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1139   mips_expand_conditional_trap (operands[0]);
1140   DONE;
1143 (define_insn "*conditional_trap_reg<mode>"
1144   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1145                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1146                                  (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1147             (const_int 0))]
1148   "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1149   "t%C0\t%z1,%2"
1150   [(set_attr "type" "trap")])
1152 (define_insn "*conditional_trap<mode>"
1153   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1154                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1155                                  (match_operand:GPR 2 "arith_operand" "dI")])
1156             (const_int 0))]
1157   "ISA_HAS_COND_TRAPI"
1158   "t%C0\t%z1,%2"
1159   [(set_attr "type" "trap")])
1162 ;;  ....................
1164 ;;      ADDITION
1166 ;;  ....................
1169 (define_insn "add<mode>3"
1170   [(set (match_operand:ANYF 0 "register_operand" "=f")
1171         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1172                    (match_operand:ANYF 2 "register_operand" "f")))]
1173   ""
1174   "add.<fmt>\t%0,%1,%2"
1175   [(set_attr "type" "fadd")
1176    (set_attr "mode" "<UNITMODE>")])
1178 (define_expand "add<mode>3"
1179   [(set (match_operand:GPR 0 "register_operand")
1180         (plus:GPR (match_operand:GPR 1 "register_operand")
1181                   (match_operand:GPR 2 "arith_operand")))]
1182   "")
1184 (define_insn "*add<mode>3"
1185   [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1186         (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1187                   (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1188   "!TARGET_MIPS16"
1190   if (which_alternative == 0 
1191       || which_alternative == 1)
1192     return "<d>addu\t%0,%1,%2";
1193   else
1194     return "<d>addiu\t%0,%1,%2";
1196   [(set_attr "alu_type" "add")
1197    (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1198    (set_attr "mode" "<MODE>")])
1200 (define_insn "*add<mode>3_mips16"
1201   [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1202         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1203                   (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1204   "TARGET_MIPS16"
1205   "@
1206     <d>addiu\t%0,%2
1207     <d>addiu\t%0,%2
1208     <d>addiu\t%0,%1,%2
1209     <d>addiu\t%0,%1,%2
1210     <d>addiu\t%0,%2
1211     <d>addiu\t%0,%2
1212     <d>addiu\t%0,%1,%2
1213     <d>addiu\t%0,%1,%2
1214     <d>addu\t%0,%1,%2"
1215   [(set_attr "alu_type" "add")
1216    (set_attr "mode" "<MODE>")
1217    (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1219 ;; On the mips16, we can sometimes split an add of a constant which is
1220 ;; a 4 byte instruction into two adds which are both 2 byte
1221 ;; instructions.  There are two cases: one where we are adding a
1222 ;; constant plus a register to another register, and one where we are
1223 ;; simply adding a constant to a register.
1225 (define_split
1226   [(set (match_operand:SI 0 "d_operand")
1227         (plus:SI (match_dup 0)
1228                  (match_operand:SI 1 "const_int_operand")))]
1229   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1230    && ((INTVAL (operands[1]) > 0x7f
1231         && INTVAL (operands[1]) <= 0x7f + 0x7f)
1232        || (INTVAL (operands[1]) < - 0x80
1233            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1234   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1235    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1237   HOST_WIDE_INT val = INTVAL (operands[1]);
1239   if (val >= 0)
1240     {
1241       operands[1] = GEN_INT (0x7f);
1242       operands[2] = GEN_INT (val - 0x7f);
1243     }
1244   else
1245     {
1246       operands[1] = GEN_INT (- 0x80);
1247       operands[2] = GEN_INT (val + 0x80);
1248     }
1251 (define_split
1252   [(set (match_operand:SI 0 "d_operand")
1253         (plus:SI (match_operand:SI 1 "d_operand")
1254                  (match_operand:SI 2 "const_int_operand")))]
1255   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1256    && REGNO (operands[0]) != REGNO (operands[1])
1257    && ((INTVAL (operands[2]) > 0x7
1258         && INTVAL (operands[2]) <= 0x7 + 0x7f)
1259        || (INTVAL (operands[2]) < - 0x8
1260            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1261   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1262    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1264   HOST_WIDE_INT val = INTVAL (operands[2]);
1266   if (val >= 0)
1267     {
1268       operands[2] = GEN_INT (0x7);
1269       operands[3] = GEN_INT (val - 0x7);
1270     }
1271   else
1272     {
1273       operands[2] = GEN_INT (- 0x8);
1274       operands[3] = GEN_INT (val + 0x8);
1275     }
1278 (define_split
1279   [(set (match_operand:DI 0 "d_operand")
1280         (plus:DI (match_dup 0)
1281                  (match_operand:DI 1 "const_int_operand")))]
1282   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1283    && ((INTVAL (operands[1]) > 0xf
1284         && INTVAL (operands[1]) <= 0xf + 0xf)
1285        || (INTVAL (operands[1]) < - 0x10
1286            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1287   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1288    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1290   HOST_WIDE_INT val = INTVAL (operands[1]);
1292   if (val >= 0)
1293     {
1294       operands[1] = GEN_INT (0xf);
1295       operands[2] = GEN_INT (val - 0xf);
1296     }
1297   else
1298     {
1299       operands[1] = GEN_INT (- 0x10);
1300       operands[2] = GEN_INT (val + 0x10);
1301     }
1304 (define_split
1305   [(set (match_operand:DI 0 "d_operand")
1306         (plus:DI (match_operand:DI 1 "d_operand")
1307                  (match_operand:DI 2 "const_int_operand")))]
1308   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1309    && REGNO (operands[0]) != REGNO (operands[1])
1310    && ((INTVAL (operands[2]) > 0x7
1311         && INTVAL (operands[2]) <= 0x7 + 0xf)
1312        || (INTVAL (operands[2]) < - 0x8
1313            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1314   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1315    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1317   HOST_WIDE_INT val = INTVAL (operands[2]);
1319   if (val >= 0)
1320     {
1321       operands[2] = GEN_INT (0x7);
1322       operands[3] = GEN_INT (val - 0x7);
1323     }
1324   else
1325     {
1326       operands[2] = GEN_INT (- 0x8);
1327       operands[3] = GEN_INT (val + 0x8);
1328     }
1331 (define_insn "*addsi3_extended"
1332   [(set (match_operand:DI 0 "register_operand" "=d,d")
1333         (sign_extend:DI
1334              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1335                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
1336   "TARGET_64BIT && !TARGET_MIPS16"
1337   "@
1338     addu\t%0,%1,%2
1339     addiu\t%0,%1,%2"
1340   [(set_attr "alu_type" "add")
1341    (set_attr "mode" "SI")])
1343 ;; Split this insn so that the addiu splitters can have a crack at it.
1344 ;; Use a conservative length estimate until the split.
1345 (define_insn_and_split "*addsi3_extended_mips16"
1346   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1347         (sign_extend:DI
1348              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1349                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1350   "TARGET_64BIT && TARGET_MIPS16"
1351   "#"
1352   "&& reload_completed"
1353   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1354   { operands[3] = gen_lowpart (SImode, operands[0]); }
1355   [(set_attr "alu_type" "add")
1356    (set_attr "mode" "SI")
1357    (set_attr "extended_mips16" "yes")])
1359 ;; Combiner patterns for unsigned byte-add.
1361 (define_insn "*baddu_si_eb"
1362   [(set (match_operand:SI 0 "register_operand" "=d")
1363         (zero_extend:SI
1364          (subreg:QI
1365           (plus:SI (match_operand:SI 1 "register_operand" "d")
1366                    (match_operand:SI 2 "register_operand" "d")) 3)))]
1367   "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1368   "baddu\\t%0,%1,%2"
1369   [(set_attr "alu_type" "add")])
1371 (define_insn "*baddu_si_el"
1372   [(set (match_operand:SI 0 "register_operand" "=d")
1373         (zero_extend:SI
1374          (subreg:QI
1375           (plus:SI (match_operand:SI 1 "register_operand" "d")
1376                    (match_operand:SI 2 "register_operand" "d")) 0)))]
1377   "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1378   "baddu\\t%0,%1,%2"
1379   [(set_attr "alu_type" "add")])
1381 (define_insn "*baddu_di<mode>"
1382   [(set (match_operand:GPR 0 "register_operand" "=d")
1383         (zero_extend:GPR
1384          (truncate:QI
1385           (plus:DI (match_operand:DI 1 "register_operand" "d")
1386                    (match_operand:DI 2 "register_operand" "d")))))]
1387   "ISA_HAS_BADDU && TARGET_64BIT"
1388   "baddu\\t%0,%1,%2"
1389   [(set_attr "alu_type" "add")])
1392 ;;  ....................
1394 ;;      SUBTRACTION
1396 ;;  ....................
1399 (define_insn "sub<mode>3"
1400   [(set (match_operand:ANYF 0 "register_operand" "=f")
1401         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1402                     (match_operand:ANYF 2 "register_operand" "f")))]
1403   ""
1404   "sub.<fmt>\t%0,%1,%2"
1405   [(set_attr "type" "fadd")
1406    (set_attr "mode" "<UNITMODE>")])
1408 (define_insn "sub<mode>3"
1409   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1410         (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1411                    (match_operand:GPR 2 "register_operand" "!u,d")))]
1412   ""
1413   "<d>subu\t%0,%1,%2"
1414   [(set_attr "alu_type" "sub")
1415    (set_attr "compression" "micromips32,*")
1416    (set_attr "mode" "<MODE>")])
1418 (define_insn "*subsi3_extended"
1419   [(set (match_operand:DI 0 "register_operand" "=d")
1420         (sign_extend:DI
1421             (minus:SI (match_operand:SI 1 "register_operand" "d")
1422                       (match_operand:SI 2 "register_operand" "d"))))]
1423   "TARGET_64BIT"
1424   "subu\t%0,%1,%2"
1425   [(set_attr "alu_type" "sub")
1426    (set_attr "mode" "DI")])
1429 ;;  ....................
1431 ;;      MULTIPLICATION
1433 ;;  ....................
1436 (define_expand "mul<mode>3"
1437   [(set (match_operand:SCALARF 0 "register_operand")
1438         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1439                       (match_operand:SCALARF 2 "register_operand")))]
1440   ""
1441   "")
1443 (define_insn "*mul<mode>3"
1444   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1445         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1446                       (match_operand:SCALARF 2 "register_operand" "f")))]
1447   "!TARGET_4300_MUL_FIX"
1448   "mul.<fmt>\t%0,%1,%2"
1449   [(set_attr "type" "fmul")
1450    (set_attr "mode" "<MODE>")])
1452 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1453 ;; operands may corrupt immediately following multiplies. This is a
1454 ;; simple fix to insert NOPs.
1456 (define_insn "*mul<mode>3_r4300"
1457   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1458         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1459                       (match_operand:SCALARF 2 "register_operand" "f")))]
1460   "TARGET_4300_MUL_FIX"
1461   "mul.<fmt>\t%0,%1,%2\;nop"
1462   [(set_attr "type" "fmul")
1463    (set_attr "mode" "<MODE>")
1464    (set_attr "insn_count" "2")])
1466 (define_insn "mulv2sf3"
1467   [(set (match_operand:V2SF 0 "register_operand" "=f")
1468         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1469                    (match_operand:V2SF 2 "register_operand" "f")))]
1470   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1471   "mul.ps\t%0,%1,%2"
1472   [(set_attr "type" "fmul")
1473    (set_attr "mode" "SF")])
1475 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1476 ;; shift executes while an integer multiplication is in progress, the
1477 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1478 ;; with the mult on the R4000.
1480 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1481 ;; (also valid for MIPS R4000MC processors):
1483 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1484 ;;      this errata description.
1485 ;;      The following code sequence causes the R4000 to incorrectly
1486 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1487 ;;      instruction.  If the dsra32 instruction is executed during an
1488 ;;      integer multiply, the dsra32 will only shift by the amount in
1489 ;;      specified in the instruction rather than the amount plus 32
1490 ;;      bits.
1491 ;;      instruction 1:          mult    rs,rt           integer multiply
1492 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1493 ;;                                                      right arithmetic + 32
1494 ;;      Workaround: A dsra32 instruction placed after an integer
1495 ;;      multiply should not be one of the 11 instructions after the
1496 ;;      multiply instruction."
1498 ;; and:
1500 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1501 ;;      the following description.
1502 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1503 ;;      64-bit versions) may produce incorrect results under the
1504 ;;      following conditions:
1505 ;;      1) An integer multiply is currently executing
1506 ;;      2) These types of shift instructions are executed immediately
1507 ;;         following an integer divide instruction.
1508 ;;      Workaround:
1509 ;;      1) Make sure no integer multiply is running wihen these
1510 ;;         instruction are executed.  If this cannot be predicted at
1511 ;;         compile time, then insert a "mfhi" to R0 instruction
1512 ;;         immediately after the integer multiply instruction.  This
1513 ;;         will cause the integer multiply to complete before the shift
1514 ;;         is executed.
1515 ;;      2) Separate integer divide and these two classes of shift
1516 ;;         instructions by another instruction or a noop."
1518 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1519 ;; respectively.
1521 (define_expand "mul<mode>3"
1522   [(set (match_operand:GPR 0 "register_operand")
1523         (mult:GPR (match_operand:GPR 1 "register_operand")
1524                   (match_operand:GPR 2 "register_operand")))]
1525   "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1527   rtx lo;
1529   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL)
1530     emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1531                                            operands[2]));
1532   else if (ISA_HAS_<D>MUL3)
1533     emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1534   else if (TARGET_MIPS16)
1535     {
1536       lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1537       emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1538       emit_move_insn (operands[0], lo);
1539     }
1540   else if (TARGET_FIX_R4000)
1541     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1542   else
1543     emit_insn
1544       (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1545   DONE;
1548 (define_insn "mul<mode>3_mul3_nohilo"
1549   [(set (match_operand:GPR 0 "register_operand" "=d")
1550         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1551                   (match_operand:GPR 2 "register_operand" "d")))]
1552   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL"
1554   if (TARGET_LOONGSON_2EF)
1555     return "<d>multu.g\t%0,%1,%2";
1556   else if (TARGET_LOONGSON_3A)
1557     return "gs<d>multu\t%0,%1,%2";
1558   else
1559     return "<d>mul\t%0,%1,%2";
1561   [(set_attr "type" "imul3nc")
1562    (set_attr "mode" "<MODE>")])
1564 (define_insn "mul<mode>3_mul3"
1565   [(set (match_operand:GPR 0 "register_operand" "=d,l")
1566         (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1567                   (match_operand:GPR 2 "register_operand" "d,d")))
1568    (clobber (match_scratch:GPR 3 "=l,X"))]
1569   "ISA_HAS_<D>MUL3"
1571   if (which_alternative == 1)
1572     return "<d>mult\t%1,%2";
1573   if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1574     return "mult\t%0,%1,%2";
1575   return "<d>mul\t%0,%1,%2";
1577   [(set_attr "type" "imul3,imul")
1578    (set_attr "mode" "<MODE>")])
1580 ;; If a register gets allocated to LO, and we spill to memory, the reload
1581 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1582 ;; if it can set the GPR directly.
1584 ;; Operand 0: LO
1585 ;; Operand 1: GPR (1st multiplication operand)
1586 ;; Operand 2: GPR (2nd multiplication operand)
1587 ;; Operand 3: GPR (destination)
1588 (define_peephole2
1589   [(parallel
1590        [(set (match_operand:SI 0 "lo_operand")
1591              (mult:SI (match_operand:SI 1 "d_operand")
1592                       (match_operand:SI 2 "d_operand")))
1593         (clobber (scratch:SI))])
1594    (set (match_operand:SI 3 "d_operand")
1595         (match_dup 0))]
1596   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1597   [(parallel
1598        [(set (match_dup 3)
1599              (mult:SI (match_dup 1)
1600                       (match_dup 2)))
1601         (clobber (match_dup 0))])])
1603 (define_insn "mul<mode>3_internal"
1604   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1605         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1606                   (match_operand:GPR 2 "register_operand" "d")))]
1607   "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1608   "<d>mult\t%1,%2"
1609   [(set_attr "type" "imul")
1610    (set_attr "mode" "<MODE>")])
1612 (define_insn "mul<mode>3_r4000"
1613   [(set (match_operand:GPR 0 "register_operand" "=d")
1614         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1615                   (match_operand:GPR 2 "register_operand" "d")))
1616    (clobber (match_scratch:GPR 3 "=l"))]
1617   "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1618   "<d>mult\t%1,%2\;mflo\t%0"
1619   [(set_attr "type" "imul")
1620    (set_attr "mode" "<MODE>")
1621    (set_attr "insn_count" "2")])
1623 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1624 ;; of "mult; mflo".  They have the same latency, but the first form gives
1625 ;; us an extra cycle to compute the operands.
1627 ;; Operand 0: LO
1628 ;; Operand 1: GPR (1st multiplication operand)
1629 ;; Operand 2: GPR (2nd multiplication operand)
1630 ;; Operand 3: GPR (destination)
1631 (define_peephole2
1632   [(set (match_operand:SI 0 "lo_operand")
1633         (mult:SI (match_operand:SI 1 "d_operand")
1634                  (match_operand:SI 2 "d_operand")))
1635    (set (match_operand:SI 3 "d_operand")
1636         (match_dup 0))]
1637   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1638   [(set (match_dup 0)
1639         (const_int 0))
1640    (parallel
1641        [(set (match_dup 0)
1642              (plus:SI (mult:SI (match_dup 1)
1643                                (match_dup 2))
1644                       (match_dup 0)))
1645         (set (match_dup 3)
1646              (plus:SI (mult:SI (match_dup 1)
1647                                (match_dup 2))
1648                       (match_dup 0)))])])
1650 ;; Multiply-accumulate patterns
1652 ;; This pattern is first matched by combine, which tries to use the
1653 ;; pattern wherever it can.  We don't know until later whether it
1654 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1655 ;; so we need to keep both options open.
1657 ;; The second alternative has a "?" marker because it is generally
1658 ;; one instruction more costly than the first alternative.  This "?"
1659 ;; marker is enough to convey the relative costs to the register
1660 ;; allocator.
1662 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1663 ;; reloads of the other operands, even though operands 4 and 5 need no
1664 ;; copy instructions.  Reload therefore thinks that the second alternative
1665 ;; is two reloads more costly than the first.  We add "*?*?" to the first
1666 ;; alternative as a counterweight.
1668 ;; LRA simulates reload but the cost of reloading scratches is lower
1669 ;; than of the classic reload. For the time being, removing the counterweight
1670 ;; for LRA is more profitable.
1671 (define_insn "*mul_acc_si"
1672   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1673         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1674                           (match_operand:SI 2 "register_operand" "d,d,d"))
1675                  (match_operand:SI 3 "register_operand" "0,0,d")))
1676    (clobber (match_scratch:SI 4 "=X,X,l"))
1677    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1678   "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1679   "@
1680     madd\t%1,%2
1681     madd\t%1,%2
1682     #"
1683   [(set_attr "type"     "imadd")
1684    (set_attr "accum_in" "3")
1685    (set_attr "mode"     "SI")
1686    (set_attr "insn_count" "1,1,2")
1687    (set (attr "enabled")
1688         (cond [(and (eq_attr "alternative" "0")
1689                     (match_test "!mips_lra_flag"))
1690                   (const_string "yes")
1691                (and (eq_attr "alternative" "1")
1692                     (match_test "mips_lra_flag"))
1693                   (const_string "yes")
1694                (eq_attr "alternative" "2")
1695                   (const_string "yes")]
1696               (const_string "no")))])
1698 ;; The same idea applies here.  The middle alternative needs one less
1699 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1700 (define_insn "*mul_acc_si_r3900"
1701   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1702         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1703                           (match_operand:SI 2 "register_operand" "d,d,d,d"))
1704                  (match_operand:SI 3 "register_operand" "0,0,l,d")))
1705    (clobber (match_scratch:SI 4 "=X,X,3,l"))
1706    (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1707   "TARGET_MIPS3900 && !TARGET_MIPS16"
1708   "@
1709     madd\t%1,%2
1710     madd\t%1,%2
1711     madd\t%0,%1,%2
1712     #"
1713   [(set_attr "type"     "imadd")
1714    (set_attr "accum_in" "3")
1715    (set_attr "mode"     "SI")
1716    (set_attr "insn_count" "1,1,1,2")
1717    (set (attr "enabled")
1718         (cond [(and (eq_attr "alternative" "0")
1719                     (match_test "!mips_lra_flag"))
1720                   (const_string "yes")
1721                (and (eq_attr "alternative" "1")
1722                     (match_test "mips_lra_flag"))
1723                   (const_string "yes")
1724                (eq_attr "alternative" "2,3")
1725                   (const_string "yes")]
1726               (const_string "no")))])
1728 ;; Split *mul_acc_si if both the source and destination accumulator
1729 ;; values are GPRs.
1730 (define_split
1731   [(set (match_operand:SI 0 "d_operand")
1732         (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1733                           (match_operand:SI 2 "d_operand"))
1734                  (match_operand:SI 3 "d_operand")))
1735    (clobber (match_operand:SI 4 "lo_operand"))
1736    (clobber (match_operand:SI 5 "d_operand"))]
1737   "reload_completed"
1738   [(parallel [(set (match_dup 5)
1739                    (mult:SI (match_dup 1) (match_dup 2)))
1740               (clobber (match_dup 4))])
1741    (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1742   "")
1744 (define_insn "*macc"
1745   [(set (match_operand:SI 0 "register_operand" "=l,d")
1746         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1747                           (match_operand:SI 2 "register_operand" "d,d"))
1748                  (match_operand:SI 3 "register_operand" "0,l")))
1749    (clobber (match_scratch:SI 4 "=X,3"))]
1750   "ISA_HAS_MACC"
1752   if (which_alternative == 1)
1753     return "macc\t%0,%1,%2";
1754   else if (TARGET_MIPS5500)
1755     return "madd\t%1,%2";
1756   else
1757     /* The VR4130 assumes that there is a two-cycle latency between a macc
1758        that "writes" to $0 and an instruction that reads from it.  We avoid
1759        this by assigning to $1 instead.  */
1760     return "%[macc\t%@,%1,%2%]";
1762   [(set_attr "type" "imadd")
1763    (set_attr "accum_in" "3")
1764    (set_attr "mode" "SI")])
1766 (define_insn "*msac"
1767   [(set (match_operand:SI 0 "register_operand" "=l,d")
1768         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1769                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1770                            (match_operand:SI 3 "register_operand" "d,d"))))
1771    (clobber (match_scratch:SI 4 "=X,1"))]
1772   "ISA_HAS_MSAC"
1774   if (which_alternative == 1)
1775     return "msac\t%0,%2,%3";
1776   else if (TARGET_MIPS5500)
1777     return "msub\t%2,%3";
1778   else
1779     return "msac\t$0,%2,%3";
1781   [(set_attr "type"     "imadd")
1782    (set_attr "accum_in" "1")
1783    (set_attr "mode"     "SI")])
1785 ;; An msac-like instruction implemented using negation and a macc.
1786 (define_insn_and_split "*msac_using_macc"
1787   [(set (match_operand:SI 0 "register_operand" "=l,d")
1788         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1789                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1790                            (match_operand:SI 3 "register_operand" "d,d"))))
1791    (clobber (match_scratch:SI 4 "=X,1"))
1792    (clobber (match_scratch:SI 5 "=d,d"))]
1793   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1794   "#"
1795   "&& reload_completed"
1796   [(set (match_dup 5)
1797         (neg:SI (match_dup 3)))
1798    (parallel
1799        [(set (match_dup 0)
1800              (plus:SI (mult:SI (match_dup 2)
1801                                (match_dup 5))
1802                       (match_dup 1)))
1803         (clobber (match_dup 4))])]
1804   ""
1805   [(set_attr "type"     "imadd")
1806    (set_attr "accum_in" "1")
1807    (set_attr "insn_count" "2")])
1809 ;; Patterns generated by the define_peephole2 below.
1811 (define_insn "*macc2"
1812   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1813         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1814                           (match_operand:SI 2 "register_operand" "d"))
1815                  (match_dup 0)))
1816    (set (match_operand:SI 3 "register_operand" "=d")
1817         (plus:SI (mult:SI (match_dup 1)
1818                           (match_dup 2))
1819                  (match_dup 0)))]
1820   "ISA_HAS_MACC && reload_completed"
1821   "macc\t%3,%1,%2"
1822   [(set_attr "type"     "imadd")
1823    (set_attr "accum_in" "0")
1824    (set_attr "mode"     "SI")])
1826 (define_insn "*msac2"
1827   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1828         (minus:SI (match_dup 0)
1829                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1830                            (match_operand:SI 2 "register_operand" "d"))))
1831    (set (match_operand:SI 3 "register_operand" "=d")
1832         (minus:SI (match_dup 0)
1833                   (mult:SI (match_dup 1)
1834                            (match_dup 2))))]
1835   "ISA_HAS_MSAC && reload_completed"
1836   "msac\t%3,%1,%2"
1837   [(set_attr "type"     "imadd")
1838    (set_attr "accum_in" "0")
1839    (set_attr "mode"     "SI")])
1841 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1842 ;; Similarly msac.
1844 ;; Operand 0: LO
1845 ;; Operand 1: macc/msac
1846 ;; Operand 2: GPR (destination)
1847 (define_peephole2
1848   [(parallel
1849        [(set (match_operand:SI 0 "lo_operand")
1850              (match_operand:SI 1 "macc_msac_operand"))
1851         (clobber (scratch:SI))])
1852    (set (match_operand:SI 2 "d_operand")
1853         (match_dup 0))]
1854   ""
1855   [(parallel [(set (match_dup 0)
1856                    (match_dup 1))
1857               (set (match_dup 2)
1858                    (match_dup 1))])])
1860 ;; When we have a three-address multiplication instruction, it should
1861 ;; be faster to do a separate multiply and add, rather than moving
1862 ;; something into LO in order to use a macc instruction.
1864 ;; This peephole needs a scratch register to cater for the case when one
1865 ;; of the multiplication operands is the same as the destination.
1867 ;; Operand 0: GPR (scratch)
1868 ;; Operand 1: LO
1869 ;; Operand 2: GPR (addend)
1870 ;; Operand 3: GPR (destination)
1871 ;; Operand 4: macc/msac
1872 ;; Operand 5: new multiplication
1873 ;; Operand 6: new addition/subtraction
1874 (define_peephole2
1875   [(match_scratch:SI 0 "d")
1876    (set (match_operand:SI 1 "lo_operand")
1877         (match_operand:SI 2 "d_operand"))
1878    (match_dup 0)
1879    (parallel
1880        [(set (match_operand:SI 3 "d_operand")
1881              (match_operand:SI 4 "macc_msac_operand"))
1882         (clobber (match_dup 1))])]
1883   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1884   [(parallel [(set (match_dup 0)
1885                    (match_dup 5))
1886               (clobber (match_dup 1))])
1887    (set (match_dup 3)
1888         (match_dup 6))]
1890   operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1891   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1892                                 operands[2], operands[0]);
1895 ;; Same as above, except LO is the initial target of the macc.
1897 ;; Operand 0: GPR (scratch)
1898 ;; Operand 1: LO
1899 ;; Operand 2: GPR (addend)
1900 ;; Operand 3: macc/msac
1901 ;; Operand 4: GPR (destination)
1902 ;; Operand 5: new multiplication
1903 ;; Operand 6: new addition/subtraction
1904 (define_peephole2
1905   [(match_scratch:SI 0 "d")
1906    (set (match_operand:SI 1 "lo_operand")
1907         (match_operand:SI 2 "d_operand"))
1908    (match_dup 0)
1909    (parallel
1910        [(set (match_dup 1)
1911              (match_operand:SI 3 "macc_msac_operand"))
1912         (clobber (scratch:SI))])
1913    (match_dup 0)
1914    (set (match_operand:SI 4 "d_operand")
1915         (match_dup 1))]
1916   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1917   [(parallel [(set (match_dup 0)
1918                    (match_dup 5))
1919               (clobber (match_dup 1))])
1920    (set (match_dup 4)
1921         (match_dup 6))]
1923   operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1924   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1925                                 operands[2], operands[0]);
1928 ;; See the comment above *mul_add_si for details.
1929 (define_insn "*mul_sub_si"
1930   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1931         (minus:SI (match_operand:SI 1 "register_operand" "0,0,d")
1932                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1933                            (match_operand:SI 3 "register_operand" "d,d,d"))))
1934    (clobber (match_scratch:SI 4 "=X,X,l"))
1935    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1936   "GENERATE_MADD_MSUB"
1937   "@
1938    msub\t%2,%3
1939    msub\t%2,%3
1940    #"
1941   [(set_attr "type"     "imadd")
1942    (set_attr "accum_in" "1")
1943    (set_attr "mode"     "SI")
1944    (set_attr "insn_count" "1,1,2")
1945    (set (attr "enabled")
1946         (cond [(and (eq_attr "alternative" "0")
1947                     (match_test "!mips_lra_flag"))
1948                   (const_string "yes")
1949                (and (eq_attr "alternative" "1")
1950                     (match_test "mips_lra_flag"))
1951                   (const_string "yes")
1952                (eq_attr "alternative" "2")
1953                   (const_string "yes")]
1954               (const_string "no")))])
1956 ;; Split *mul_sub_si if both the source and destination accumulator
1957 ;; values are GPRs.
1958 (define_split
1959   [(set (match_operand:SI 0 "d_operand")
1960         (minus:SI (match_operand:SI 1 "d_operand")
1961                   (mult:SI (match_operand:SI 2 "d_operand")
1962                            (match_operand:SI 3 "d_operand"))))
1963    (clobber (match_operand:SI 4 "lo_operand"))
1964    (clobber (match_operand:SI 5 "d_operand"))]
1965   "reload_completed"
1966   [(parallel [(set (match_dup 5)
1967                    (mult:SI (match_dup 2) (match_dup 3)))
1968               (clobber (match_dup 4))])
1969    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1970   "")
1972 (define_insn "*muls"
1973   [(set (match_operand:SI 0 "register_operand" "=l,d")
1974         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1975                          (match_operand:SI 2 "register_operand" "d,d"))))
1976    (clobber (match_scratch:SI 3 "=X,l"))]
1977   "ISA_HAS_MULS"
1978   "@
1979    muls\t$0,%1,%2
1980    muls\t%0,%1,%2"
1981   [(set_attr "type"     "imul,imul3")
1982    (set_attr "mode"     "SI")])
1984 (define_expand "<u>mulsidi3"
1985   [(set (match_operand:DI 0 "register_operand")
1986         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1987                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1988   "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1990   mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1991   emit_insn (fn (operands[0], operands[1], operands[2]));
1992   DONE;
1995 (define_expand "<u>mulsidi3_32bit_r6"
1996   [(set (match_operand:DI 0 "register_operand")
1997         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1998                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1999   "!TARGET_64BIT && ISA_HAS_R6MUL"
2001   rtx dest = gen_reg_rtx (DImode);
2002   rtx low = mips_subword (dest, 0);
2003   rtx high = mips_subword (dest, 1);
2005   emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2006   emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2008   emit_move_insn (mips_subword (operands[0], 0), low);
2009   emit_move_insn (mips_subword (operands[0], 1), high);
2010   DONE;
2013 (define_expand "<u>mulsidi3_32bit_mips16"
2014   [(set (match_operand:DI 0 "register_operand")
2015         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2016                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2017   "!TARGET_64BIT && TARGET_MIPS16"
2019   rtx hilo;
2021   hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2022   emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2023   emit_move_insn (operands[0], hilo);
2024   DONE;
2027 ;; As well as being named patterns, these instructions are used by the
2028 ;; __builtin_mips_mult<u>() functions.  We must always make those functions
2029 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2030 (define_insn "<u>mulsidi3_32bit"
2031   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2032         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2033                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2034   "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2036   if (ISA_HAS_DSP_MULT)
2037     return "mult<u>\t%q0,%1,%2";
2038   else
2039     return "mult<u>\t%1,%2";
2041   [(set_attr "type" "imul")
2042    (set_attr "mode" "SI")])
2044 (define_insn "<u>mulsidi3_32bit_r4000"
2045   [(set (match_operand:DI 0 "register_operand" "=d")
2046         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2047                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2048    (clobber (match_scratch:DI 3 "=x"))]
2049   "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2050   "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2051   [(set_attr "type" "imul")
2052    (set_attr "mode" "SI")
2053    (set_attr "insn_count" "3")])
2055 (define_insn_and_split "<u>mulsidi3_64bit"
2056   [(set (match_operand:DI 0 "register_operand" "=d")
2057         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2058                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2059    (clobber (match_scratch:TI 3 "=x"))
2060    (clobber (match_scratch:DI 4 "=d"))]
2061   "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2062    && !TARGET_MIPS16 && ISA_HAS_MULT"
2063   "#"
2064   "&& reload_completed"
2065   [(const_int 0)]
2067   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2068                                           operands[2], operands[4]));
2069   DONE;
2071   [(set_attr "type" "imul")
2072    (set_attr "mode" "SI")
2073    (set (attr "insn_count")
2074         (if_then_else (match_test "ISA_HAS_EXT_INS")
2075                       (const_int 4)
2076                       (const_int 7)))])
2078 (define_expand "<u>mulsidi3_64bit_mips16"
2079   [(set (match_operand:DI 0 "register_operand")
2080         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2081                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2082   "TARGET_64BIT && TARGET_MIPS16"
2084   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2085                                           operands[2], gen_reg_rtx (DImode)));
2086   DONE;
2089 (define_expand "<u>mulsidi3_64bit_split"
2090   [(set (match_operand:DI 0 "register_operand")
2091         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2092                  (any_extend:DI (match_operand:SI 2 "register_operand"))))
2093    (clobber (match_operand:DI 3 "register_operand"))]
2094   ""
2096   rtx hilo;
2098   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2099   emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2101   emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2102   emit_insn (gen_mfhidi_ti (operands[3], hilo));
2104   if (ISA_HAS_EXT_INS)
2105     emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2106                            operands[3]));
2107   else
2108     {
2109       /* Zero-extend the low part.  */
2110       mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2111       mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2113       /* Shift the high part into place.  */
2114       mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2116       /* OR the two halves together.  */
2117       mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2118     }
2119   DONE;
2122 (define_insn "<u>mulsidi3_64bit_hilo"
2123   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2124         (unspec:TI
2125           [(mult:DI
2126              (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2127              (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2128           UNSPEC_SET_HILO))]
2129   "TARGET_64BIT && !TARGET_FIX_R4000"
2130   "mult<u>\t%1,%2"
2131   [(set_attr "type" "imul")
2132    (set_attr "mode" "SI")])
2134 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2135 (define_insn "mulsidi3_64bit_dmul"
2136   [(set (match_operand:DI 0 "register_operand" "=d")
2137         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2138                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2139    (clobber (match_scratch:DI 3 "=l"))]
2140   "ISA_HAS_DMUL3"
2141   "dmul\t%0,%1,%2"
2142   [(set_attr "type" "imul3")
2143    (set_attr "mode" "DI")])
2145 (define_insn "mulsidi3_64bit_r6dmul"
2146   [(set (match_operand:DI 0 "register_operand" "=d")
2147         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2148                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2149   "ISA_HAS_R6DMUL"
2150   "dmul\t%0,%1,%2"
2151   [(set_attr "type" "imul3nc")
2152    (set_attr "mode" "DI")])
2154 ;; Widening multiply with negation.
2155 (define_insn "*muls<u>_di"
2156   [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2157         (neg:DI
2158          (mult:DI
2159           (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2160           (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2161   "!TARGET_64BIT && ISA_HAS_MULS"
2162   "muls<u>\t$0,%1,%2"
2163   [(set_attr "type" "imul")
2164    (set_attr "mode" "SI")])
2166 ;; As well as being named patterns, these instructions are used by the
2167 ;; __builtin_mips_msub<u>() functions.  We must always make those functions
2168 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2170 ;; This leads to a slight inconsistency.  We honor any tuning overrides
2171 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2172 ;; even if !ISA_HAS_DSP_MULT.
2173 (define_insn "<u>msubsidi4"
2174   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2175         (minus:DI
2176            (match_operand:DI 3 "muldiv_target_operand" "0")
2177            (mult:DI
2178               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2179               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2180   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2182   if (ISA_HAS_DSP_MULT)
2183     return "msub<u>\t%q0,%1,%2";
2184   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2185     return "msub<u>\t%1,%2";
2186   else
2187     return "msac<u>\t$0,%1,%2";
2189   [(set_attr "type" "imadd")
2190    (set_attr "accum_in" "3")
2191    (set_attr "mode" "SI")])
2193 ;; _highpart patterns
2195 (define_expand "<su>mulsi3_highpart"
2196   [(set (match_operand:SI 0 "register_operand")
2197         (truncate:SI
2198          (lshiftrt:DI
2199           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2200                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2201           (const_int 32))))]
2202   ""
2204   if (ISA_HAS_MULHI)
2205     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2206                                                        operands[1],
2207                                                        operands[2]));
2208   else if (TARGET_MIPS16)
2209     emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2210                                               operands[2]));
2211   else if (ISA_HAS_R6MUL)
2212     emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2213                                            operands[2]));
2214   else
2215     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2216                                                  operands[2]));
2217   DONE;
2220 (define_insn "<su>mulsi3_highpart_r6"
2221   [(set (match_operand:SI 0 "register_operand" "=d")
2222         (truncate:SI
2223          (lshiftrt:DI
2224           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2225                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2226           (const_int 32))))]
2227   "ISA_HAS_R6MUL"
2228   "muh<u>\t%0,%1,%2"
2229   [(set_attr "type" "imul3nc")
2230    (set_attr "mode" "SI")])
2232 (define_insn_and_split "<su>mulsi3_highpart_internal"
2233   [(set (match_operand:SI 0 "register_operand" "=d")
2234         (truncate:SI
2235          (lshiftrt:DI
2236           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2237                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2238           (const_int 32))))
2239    (clobber (match_scratch:SI 3 "=l"))]
2240   "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2241   { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2242   "&& reload_completed && !TARGET_FIX_R4000"
2243   [(const_int 0)]
2245   emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2246                                             operands[2]));
2247   DONE;
2249   [(set_attr "type" "imul")
2250    (set_attr "mode" "SI")
2251    (set_attr "insn_count" "2")])
2253 (define_expand "<su>mulsi3_highpart_split"
2254   [(set (match_operand:SI 0 "register_operand")
2255         (truncate:SI
2256          (lshiftrt:DI
2257           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2258                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2259           (const_int 32))))]
2260   ""
2262   rtx hilo;
2264   if (TARGET_64BIT)
2265     {
2266       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2267       emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2268       emit_insn (gen_mfhisi_ti (operands[0], hilo));
2269     }
2270   else
2271     {
2272       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2273       emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2274       emit_insn (gen_mfhisi_di (operands[0], hilo));
2275     }
2276   DONE;
2279 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2280   [(set (match_operand:SI 0 "register_operand" "=d")
2281         (truncate:SI
2282          (lshiftrt:DI
2283           (mult:DI
2284            (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2285            (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2286           (const_int 32))))
2287    (clobber (match_scratch:SI 3 "=l"))]
2288   "ISA_HAS_MULHI"
2289   "mulhi<u>\t%0,%1,%2"
2290   [(set_attr "type" "imul3")
2291    (set_attr "mode" "SI")])
2293 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2294   [(set (match_operand:SI 0 "register_operand" "=d")
2295         (truncate:SI
2296          (lshiftrt:DI
2297           (neg:DI
2298            (mult:DI
2299             (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2300             (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2301           (const_int 32))))
2302    (clobber (match_scratch:SI 3 "=l"))]
2303   "ISA_HAS_MULHI"
2304   "mulshi<u>\t%0,%1,%2"
2305   [(set_attr "type" "imul3")
2306    (set_attr "mode" "SI")])
2308 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
2309 ;; errata MD(0), which says that dmultu does not always produce the
2310 ;; correct result.
2311 (define_expand "<su>muldi3_highpart"
2312   [(set (match_operand:DI 0 "register_operand")
2313         (truncate:DI
2314          (lshiftrt:TI
2315           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2316                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2317           (const_int 64))))]
2318   "ISA_HAS_R6DMUL
2319    || (ISA_HAS_DMULT
2320        && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2322   if (TARGET_MIPS16)
2323     emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2324                                               operands[2]));
2325   else if (ISA_HAS_R6DMUL)
2326     emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2327                                            operands[2]));
2328   else
2329     emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2330                                                  operands[2]));
2331   DONE;
2334 (define_insn "<su>muldi3_highpart_r6"
2335   [(set (match_operand:DI 0 "register_operand" "=d")
2336         (truncate:DI
2337          (lshiftrt:TI
2338           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2339                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2340           (const_int 64))))]
2341   "ISA_HAS_R6DMUL"
2342   "dmuh<u>\t%0,%1,%2"
2343   [(set_attr "type" "imul3nc")
2344    (set_attr "mode" "DI")])
2346 (define_insn_and_split "<su>muldi3_highpart_internal"
2347   [(set (match_operand:DI 0 "register_operand" "=d")
2348         (truncate:DI
2349          (lshiftrt:TI
2350           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2351                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2352           (const_int 64))))
2353    (clobber (match_scratch:DI 3 "=l"))]
2354   "ISA_HAS_DMULT
2355    && !TARGET_MIPS16
2356    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2357   { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2358   "&& reload_completed && !TARGET_FIX_R4000"
2359   [(const_int 0)]
2361   emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2362                                             operands[2]));
2363   DONE;
2365   [(set_attr "type" "imul")
2366    (set_attr "mode" "DI")
2367    (set_attr "insn_count" "2")])
2369 (define_expand "<su>muldi3_highpart_split"
2370   [(set (match_operand:DI 0 "register_operand")
2371         (truncate:DI
2372          (lshiftrt:TI
2373           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2374                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2375           (const_int 64))))]
2376   ""
2378   rtx hilo;
2380   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2381   emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2382   emit_insn (gen_mfhidi_ti (operands[0], hilo));
2383   DONE;
2386 (define_expand "<u>mulditi3"
2387   [(set (match_operand:TI 0 "register_operand")
2388         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2389                  (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2390   "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2392   rtx hilo;
2394   if (TARGET_MIPS16)
2395     {
2396       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2397       emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2398       emit_move_insn (operands[0], hilo);
2399     }
2400   else if (TARGET_FIX_R4000)
2401     emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2402   else
2403     emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2404                                          operands[2]));
2405   DONE;
2408 (define_insn "<u>mulditi3_internal"
2409   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2410         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2411                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2412   "ISA_HAS_DMULT
2413    && !TARGET_FIX_R4000
2414    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2415   "dmult<u>\t%1,%2"
2416   [(set_attr "type" "imul")
2417    (set_attr "mode" "DI")])
2419 (define_insn "<u>mulditi3_r4000"
2420   [(set (match_operand:TI 0 "register_operand" "=d")
2421         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2422                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2423    (clobber (match_scratch:TI 3 "=x"))]
2424   "ISA_HAS_DMULT
2425    && TARGET_FIX_R4000
2426    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2427   "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2428   [(set_attr "type" "imul")
2429    (set_attr "mode" "DI")
2430    (set_attr "insn_count" "3")])
2432 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2433 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
2435 (define_insn "madsi"
2436   [(set (match_operand:SI 0 "register_operand" "+l")
2437         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2438                           (match_operand:SI 2 "register_operand" "d"))
2439                  (match_dup 0)))]
2440   "TARGET_MAD"
2441   "mad\t%1,%2"
2442   [(set_attr "type"     "imadd")
2443    (set_attr "accum_in" "0")
2444    (set_attr "mode"     "SI")])
2446 ;; See the comment above <u>msubsidi4 for the relationship between
2447 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2448 (define_insn "<u>maddsidi4"
2449   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2450         (plus:DI
2451          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2452                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2453          (match_operand:DI 3 "muldiv_target_operand" "0")))]
2454   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2455    && !TARGET_64BIT"
2457   if (TARGET_MAD)
2458     return "mad<u>\t%1,%2";
2459   else if (ISA_HAS_DSP_MULT)
2460     return "madd<u>\t%q0,%1,%2";
2461   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2462     return "madd<u>\t%1,%2";
2463   else
2464     /* See comment in *macc.  */
2465     return "%[macc<u>\t%@,%1,%2%]";
2467   [(set_attr "type" "imadd")
2468    (set_attr "accum_in" "3")
2469    (set_attr "mode" "SI")])
2471 ;; Floating point multiply accumulate instructions.
2473 (define_insn "*madd4<mode>"
2474   [(set (match_operand:ANYF 0 "register_operand" "=f")
2475         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2476                               (match_operand:ANYF 2 "register_operand" "f"))
2477                    (match_operand:ANYF 3 "register_operand" "f")))]
2478   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2479   "madd.<fmt>\t%0,%3,%1,%2"
2480   [(set_attr "type" "fmadd")
2481    (set_attr "mode" "<UNITMODE>")])
2483 (define_insn "fma<mode>4"
2484   [(set (match_operand:ANYF 0 "register_operand" "=f")
2485         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2486                   (match_operand:ANYF 2 "register_operand" "f")
2487                   (match_operand:ANYF 3 "register_operand" "0")))]
2488   "ISA_HAS_FP_MADDF_MSUBF"
2489   "maddf.<fmt>\t%0,%1,%2"
2490   [(set_attr "type" "fmadd")
2491    (set_attr "mode" "<UNITMODE>")])
2493 (define_insn "*madd3<mode>"
2494   [(set (match_operand:ANYF 0 "register_operand" "=f")
2495         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2496                               (match_operand:ANYF 2 "register_operand" "f"))
2497                    (match_operand:ANYF 3 "register_operand" "0")))]
2498   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2499   "madd.<fmt>\t%0,%1,%2"
2500   [(set_attr "type" "fmadd")
2501    (set_attr "mode" "<UNITMODE>")])
2503 (define_insn "*msub4<mode>"
2504   [(set (match_operand:ANYF 0 "register_operand" "=f")
2505         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2506                                (match_operand:ANYF 2 "register_operand" "f"))
2507                     (match_operand:ANYF 3 "register_operand" "f")))]
2508   "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2509   "msub.<fmt>\t%0,%3,%1,%2"
2510   [(set_attr "type" "fmadd")
2511    (set_attr "mode" "<UNITMODE>")])
2513 (define_insn "*msub3<mode>"
2514   [(set (match_operand:ANYF 0 "register_operand" "=f")
2515         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2516                                (match_operand:ANYF 2 "register_operand" "f"))
2517                     (match_operand:ANYF 3 "register_operand" "0")))]
2518   "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2519   "msub.<fmt>\t%0,%1,%2"
2520   [(set_attr "type" "fmadd")
2521    (set_attr "mode" "<UNITMODE>")])
2523 (define_insn "*nmadd4<mode>"
2524   [(set (match_operand:ANYF 0 "register_operand" "=f")
2525         (neg:ANYF (plus:ANYF
2526                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2527                               (match_operand:ANYF 2 "register_operand" "f"))
2528                    (match_operand:ANYF 3 "register_operand" "f"))))]
2529   "ISA_HAS_NMADD4_NMSUB4
2530    && TARGET_FUSED_MADD
2531    && HONOR_SIGNED_ZEROS (<MODE>mode)
2532    && !HONOR_NANS (<MODE>mode)"
2533   "nmadd.<fmt>\t%0,%3,%1,%2"
2534   [(set_attr "type" "fmadd")
2535    (set_attr "mode" "<UNITMODE>")])
2537 (define_insn "*nmadd3<mode>"
2538   [(set (match_operand:ANYF 0 "register_operand" "=f")
2539         (neg:ANYF (plus:ANYF
2540                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2541                               (match_operand:ANYF 2 "register_operand" "f"))
2542                    (match_operand:ANYF 3 "register_operand" "0"))))]
2543   "ISA_HAS_NMADD3_NMSUB3
2544    && TARGET_FUSED_MADD
2545    && HONOR_SIGNED_ZEROS (<MODE>mode)
2546    && !HONOR_NANS (<MODE>mode)"
2547   "nmadd.<fmt>\t%0,%1,%2"
2548   [(set_attr "type" "fmadd")
2549    (set_attr "mode" "<UNITMODE>")])
2551 (define_insn "*nmadd4<mode>_fastmath"
2552   [(set (match_operand:ANYF 0 "register_operand" "=f")
2553         (minus:ANYF
2554          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2555                     (match_operand:ANYF 2 "register_operand" "f"))
2556          (match_operand:ANYF 3 "register_operand" "f")))]
2557   "ISA_HAS_NMADD4_NMSUB4
2558    && TARGET_FUSED_MADD
2559    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2560    && !HONOR_NANS (<MODE>mode)"
2561   "nmadd.<fmt>\t%0,%3,%1,%2"
2562   [(set_attr "type" "fmadd")
2563    (set_attr "mode" "<UNITMODE>")])
2565 (define_insn "*nmadd3<mode>_fastmath"
2566   [(set (match_operand:ANYF 0 "register_operand" "=f")
2567         (minus:ANYF
2568          (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2569                     (match_operand:ANYF 2 "register_operand" "f"))
2570          (match_operand:ANYF 3 "register_operand" "0")))]
2571   "ISA_HAS_NMADD3_NMSUB3
2572    && TARGET_FUSED_MADD
2573    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2574    && !HONOR_NANS (<MODE>mode)"
2575   "nmadd.<fmt>\t%0,%1,%2"
2576   [(set_attr "type" "fmadd")
2577    (set_attr "mode" "<UNITMODE>")])
2579 (define_insn "*nmsub4<mode>"
2580   [(set (match_operand:ANYF 0 "register_operand" "=f")
2581         (neg:ANYF (minus:ANYF
2582                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2583                               (match_operand:ANYF 3 "register_operand" "f"))
2584                    (match_operand:ANYF 1 "register_operand" "f"))))]
2585   "ISA_HAS_NMADD4_NMSUB4
2586    && TARGET_FUSED_MADD
2587    && HONOR_SIGNED_ZEROS (<MODE>mode)
2588    && !HONOR_NANS (<MODE>mode)"
2589   "nmsub.<fmt>\t%0,%1,%2,%3"
2590   [(set_attr "type" "fmadd")
2591    (set_attr "mode" "<UNITMODE>")])
2593 (define_insn "*nmsub3<mode>"
2594   [(set (match_operand:ANYF 0 "register_operand" "=f")
2595         (neg:ANYF (minus:ANYF
2596                    (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2597                               (match_operand:ANYF 3 "register_operand" "f"))
2598                    (match_operand:ANYF 1 "register_operand" "0"))))]
2599   "ISA_HAS_NMADD3_NMSUB3
2600    && TARGET_FUSED_MADD
2601    && HONOR_SIGNED_ZEROS (<MODE>mode)
2602    && !HONOR_NANS (<MODE>mode)"
2603   "nmsub.<fmt>\t%0,%1,%2"
2604   [(set_attr "type" "fmadd")
2605    (set_attr "mode" "<UNITMODE>")])
2607 (define_insn "*nmsub4<mode>_fastmath"
2608   [(set (match_operand:ANYF 0 "register_operand" "=f")
2609         (minus:ANYF
2610          (match_operand:ANYF 1 "register_operand" "f")
2611          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2612                     (match_operand:ANYF 3 "register_operand" "f"))))]
2613   "ISA_HAS_NMADD4_NMSUB4
2614    && TARGET_FUSED_MADD
2615    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2616    && !HONOR_NANS (<MODE>mode)"
2617   "nmsub.<fmt>\t%0,%1,%2,%3"
2618   [(set_attr "type" "fmadd")
2619    (set_attr "mode" "<UNITMODE>")])
2621 (define_insn "*nmsub3<mode>_fastmath"
2622   [(set (match_operand:ANYF 0 "register_operand" "=f")
2623         (minus:ANYF
2624          (match_operand:ANYF 1 "register_operand" "f")
2625          (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2626                     (match_operand:ANYF 3 "register_operand" "0"))))]
2627   "ISA_HAS_NMADD3_NMSUB3
2628    && TARGET_FUSED_MADD
2629    && !HONOR_SIGNED_ZEROS (<MODE>mode)
2630    && !HONOR_NANS (<MODE>mode)"
2631   "nmsub.<fmt>\t%0,%1,%2"
2632   [(set_attr "type" "fmadd")
2633    (set_attr "mode" "<UNITMODE>")])
2636 ;;  ....................
2638 ;;      DIVISION and REMAINDER
2640 ;;  ....................
2643 (define_expand "div<mode>3"
2644   [(set (match_operand:ANYF 0 "register_operand")
2645         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2646                   (match_operand:ANYF 2 "register_operand")))]
2647   "<divide_condition>"
2649   if (const_1_operand (operands[1], <MODE>mode))
2650     if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2651           && flag_unsafe_math_optimizations))
2652       operands[1] = force_reg (<MODE>mode, operands[1]);
2655 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2657 ;; If an mfc1 or dmfc1 happens to access the floating point register
2658 ;; file at the same time a long latency operation (div, sqrt, recip,
2659 ;; sqrt) iterates an intermediate result back through the floating
2660 ;; point register file bypass, then instead returning the correct
2661 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2662 ;; result of the long latency operation.
2664 ;; The workaround is to insert an unconditional 'mov' from/to the
2665 ;; long latency op destination register.
2667 (define_insn "*div<mode>3"
2668   [(set (match_operand:ANYF 0 "register_operand" "=f")
2669         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2670                   (match_operand:ANYF 2 "register_operand" "f")))]
2671   "<divide_condition>"
2673   if (TARGET_FIX_SB1)
2674     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2675   else
2676     return "div.<fmt>\t%0,%1,%2";
2678   [(set_attr "type" "fdiv")
2679    (set_attr "mode" "<UNITMODE>")
2680    (set (attr "insn_count")
2681         (if_then_else (match_test "TARGET_FIX_SB1")
2682                       (const_int 2)
2683                       (const_int 1)))])
2685 (define_insn "*recip<mode>3"
2686   [(set (match_operand:ANYF 0 "register_operand" "=f")
2687         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2688                   (match_operand:ANYF 2 "register_operand" "f")))]
2689   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2691   if (TARGET_FIX_SB1)
2692     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2693   else
2694     return "recip.<fmt>\t%0,%2";
2696   [(set_attr "type" "frdiv")
2697    (set_attr "mode" "<UNITMODE>")
2698    (set (attr "insn_count")
2699         (if_then_else (match_test "TARGET_FIX_SB1")
2700                       (const_int 2)
2701                       (const_int 1)))])
2703 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2704 ;; with negative operands.  We use special libgcc functions instead.
2705 (define_expand "divmod<mode>4"
2706   [(parallel
2707      [(set (match_operand:GPR 0 "register_operand")
2708            (div:GPR (match_operand:GPR 1 "register_operand")
2709                     (match_operand:GPR 2 "register_operand")))
2710       (set (match_operand:GPR 3 "register_operand")
2711            (mod:GPR (match_dup 1)
2712                     (match_dup 2)))])]
2713   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2715   if (TARGET_MIPS16)
2716     {
2717       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2718       emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2719                                            operands[2], operands[3], lo));
2720       DONE;
2721     }
2724 (define_insn_and_split "*divmod<mode>4"
2725   [(set (match_operand:GPR 0 "register_operand" "=l")
2726         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2727                  (match_operand:GPR 2 "register_operand" "d")))
2728    (set (match_operand:GPR 3 "register_operand" "=d")
2729         (mod:GPR (match_dup 1)
2730                  (match_dup 2)))]
2731   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2732   "#"
2733   "&& reload_completed"
2734   [(const_int 0)]
2736   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2737   DONE;
2739  [(set_attr "type" "idiv")
2740   (set_attr "mode" "<MODE>")
2741   (set_attr "insn_count" "2")])
2743 ;; Expand generates divmod instructions for individual division and modulus
2744 ;; operations.  We then rely on CSE to reuse earlier divmods where possible.
2745 ;; This means that, when generating MIPS16 code, it is better not to expose
2746 ;; the fixed LO register until after CSE has finished.  However, it's still
2747 ;; better to split before register allocation, so that we don't allocate
2748 ;; one of the scarce MIPS16 registers to an unused result.
2749 (define_insn_and_split "divmod<mode>4_mips16"
2750   [(set (match_operand:GPR 0 "register_operand" "=d")
2751         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2752                  (match_operand:GPR 2 "register_operand" "d")))
2753    (set (match_operand:GPR 3 "register_operand" "=d")
2754         (mod:GPR (match_dup 1)
2755                  (match_dup 2)))
2756    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2757   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2758   "#"
2759   "&& cse_not_expected"
2760   [(const_int 0)]
2762   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2763   emit_move_insn (operands[0], operands[4]);
2764   DONE;
2766  [(set_attr "type" "idiv")
2767   (set_attr "mode" "<MODE>")
2768   (set_attr "insn_count" "3")])
2770 (define_expand "udivmod<mode>4"
2771   [(parallel
2772      [(set (match_operand:GPR 0 "register_operand")
2773            (udiv:GPR (match_operand:GPR 1 "register_operand")
2774                      (match_operand:GPR 2 "register_operand")))
2775       (set (match_operand:GPR 3 "register_operand")
2776            (umod:GPR (match_dup 1)
2777                      (match_dup 2)))])]
2778   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2780   if (TARGET_MIPS16)
2781     {
2782       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2783       emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2784                                             operands[2], operands[3], lo));
2785       DONE;
2786     }
2789 (define_insn_and_split "*udivmod<mode>4"
2790   [(set (match_operand:GPR 0 "register_operand" "=l")
2791         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2792                   (match_operand:GPR 2 "register_operand" "d")))
2793    (set (match_operand:GPR 3 "register_operand" "=d")
2794         (umod:GPR (match_dup 1)
2795                   (match_dup 2)))]
2796   "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2797   "#"
2798   "reload_completed"
2799   [(const_int 0)]
2801   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2802   DONE;
2804   [(set_attr "type" "idiv")
2805    (set_attr "mode" "<MODE>")
2806    (set_attr "insn_count" "2")])
2808 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2809 (define_insn_and_split "udivmod<mode>4_mips16"
2810   [(set (match_operand:GPR 0 "register_operand" "=d")
2811         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2812                   (match_operand:GPR 2 "register_operand" "d")))
2813    (set (match_operand:GPR 3 "register_operand" "=d")
2814         (umod:GPR (match_dup 1)
2815                   (match_dup 2)))
2816    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2817   "ISA_HAS_<D>DIV && TARGET_MIPS16"
2818   "#"
2819   "cse_not_expected"
2820   [(const_int 0)]
2822   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2823   emit_move_insn (operands[0], operands[4]);
2824   DONE;
2826   [(set_attr "type" "idiv")
2827    (set_attr "mode" "<MODE>")
2828    (set_attr "insn_count" "3")])
2830 (define_expand "<u>divmod<mode>4_split"
2831   [(set (match_operand:GPR 0 "register_operand")
2832         (any_mod:GPR (match_operand:GPR 1 "register_operand")
2833                      (match_operand:GPR 2 "register_operand")))]
2834   ""
2836   rtx hilo;
2838   if (TARGET_64BIT)
2839     {
2840       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2841       emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2842                                                operands[2]));
2843       emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2844     }
2845   else
2846     {
2847       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2848       emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2849                                                operands[2]));
2850       emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2851     }
2852   DONE;
2855 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2856   [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2857         (unspec:HILO
2858           [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2859                         (match_operand:GPR 2 "register_operand" "d"))]
2860           UNSPEC_SET_HILO))]
2861   "ISA_HAS_<GPR:D>DIV"
2862   { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2863   [(set_attr "type" "idiv")
2864    (set_attr "mode" "<GPR:MODE>")])
2866 ;; Integer division and modulus.
2868 (define_insn "<u>div<mode>3"
2869   [(set (match_operand:GPR 0 "register_operand" "=&d")
2870         (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2871                      (match_operand:GPR 2 "register_operand" "d")))]
2872   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
2873   {
2874     if (TARGET_LOONGSON_2EF)
2875       return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
2876     else if (TARGET_LOONGSON_3A)
2877       return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
2878     else
2879       return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
2880   }
2881   [(set_attr "type" "idiv3")
2882    (set_attr "mode" "<MODE>")])
2884 (define_insn "<u>mod<mode>3"
2885   [(set (match_operand:GPR 0 "register_operand" "=&d")
2886         (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
2887                      (match_operand:GPR 2 "register_operand" "d")))]
2888   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
2889   {
2890     if (TARGET_LOONGSON_2EF)
2891       return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
2892     else if (TARGET_LOONGSON_3A)
2893       return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
2894     else
2895       return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
2896   }
2897   [(set_attr "type" "idiv3")
2898    (set_attr "mode" "<MODE>")])
2901 ;;  ....................
2903 ;;      SQUARE ROOT
2905 ;;  ....................
2907 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2908 ;; "*div[sd]f3" comment for details).
2910 (define_insn "sqrt<mode>2"
2911   [(set (match_operand:ANYF 0 "register_operand" "=f")
2912         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2913   "<sqrt_condition>"
2915   if (TARGET_FIX_SB1)
2916     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2917   else
2918     return "sqrt.<fmt>\t%0,%1";
2920   [(set_attr "type" "fsqrt")
2921    (set_attr "mode" "<UNITMODE>")
2922    (set (attr "insn_count")
2923         (if_then_else (match_test "TARGET_FIX_SB1")
2924                       (const_int 2)
2925                       (const_int 1)))])
2927 (define_insn "*rsqrt<mode>a"
2928   [(set (match_operand:ANYF 0 "register_operand" "=f")
2929         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2930                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2931   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2933   if (TARGET_FIX_SB1)
2934     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2935   else
2936     return "rsqrt.<fmt>\t%0,%2";
2938   [(set_attr "type" "frsqrt")
2939    (set_attr "mode" "<UNITMODE>")
2940    (set (attr "insn_count")
2941         (if_then_else (match_test "TARGET_FIX_SB1")
2942                       (const_int 2)
2943                       (const_int 1)))])
2945 (define_insn "*rsqrt<mode>b"
2946   [(set (match_operand:ANYF 0 "register_operand" "=f")
2947         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2948                              (match_operand:ANYF 2 "register_operand" "f"))))]
2949   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2951   if (TARGET_FIX_SB1)
2952     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2953   else
2954     return "rsqrt.<fmt>\t%0,%2";
2956   [(set_attr "type" "frsqrt")
2957    (set_attr "mode" "<UNITMODE>")
2958    (set (attr "insn_count")
2959         (if_then_else (match_test "TARGET_FIX_SB1")
2960                       (const_int 2)
2961                       (const_int 1)))])
2964 ;;  ....................
2966 ;;      ABSOLUTE VALUE
2968 ;;  ....................
2970 ;; Do not use the integer abs macro instruction, since that signals an
2971 ;; exception on -2147483648 (sigh).
2973 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
2974 ;; instruction that treats all NaN inputs as invalid; it does not clear
2975 ;; their sign bit.  We therefore can't use that form if the signs of
2976 ;; NaNs matter.
2978 (define_insn "abs<mode>2"
2979   [(set (match_operand:ANYF 0 "register_operand" "=f")
2980         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2981   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
2982   "abs.<fmt>\t%0,%1"
2983   [(set_attr "type" "fabs")
2984    (set_attr "mode" "<UNITMODE>")])
2987 ;;  ...................
2989 ;;  Count leading zeroes.
2991 ;;  ...................
2994 (define_insn "clz<mode>2"
2995   [(set (match_operand:GPR 0 "register_operand" "=d")
2996         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2997   "ISA_HAS_CLZ_CLO"
2998   "<d>clz\t%0,%1"
2999   [(set_attr "type" "clz")
3000    (set_attr "mode" "<MODE>")])
3003 ;;  ...................
3005 ;;  Count number of set bits.
3007 ;;  ...................
3010 (define_insn "popcount<mode>2"
3011   [(set (match_operand:GPR 0 "register_operand" "=d")
3012         (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3013   "ISA_HAS_POP"
3014   "<d>pop\t%0,%1"
3015   [(set_attr "type" "pop")
3016    (set_attr "mode" "<MODE>")])
3018 ;; The POP instruction is special as it does not take into account the upper
3019 ;; 32bits and is documented that way.
3020 (define_insn "*popcountdi2_trunc"
3021   [(set (match_operand:SI 0 "register_operand" "=d")
3022        (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3023   "ISA_HAS_POP && TARGET_64BIT"
3024   "pop\t%0,%1"
3025   [(set_attr "type" "pop")
3026    (set_attr "mode" "SI")])
3029 ;;  ....................
3031 ;;      NEGATION and ONE'S COMPLEMENT
3033 ;;  ....................
3035 (define_insn "negsi2"
3036   [(set (match_operand:SI 0 "register_operand" "=d")
3037         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3038   ""
3040   if (TARGET_MIPS16)
3041     return "neg\t%0,%1";
3042   else
3043     return "subu\t%0,%.,%1";
3045   [(set_attr "alu_type" "sub")
3046    (set_attr "mode"     "SI")])
3048 (define_insn "negdi2"
3049   [(set (match_operand:DI 0 "register_operand" "=d")
3050         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3051   "TARGET_64BIT && !TARGET_MIPS16"
3052   "dsubu\t%0,%.,%1"
3053   [(set_attr "alu_type" "sub")
3054    (set_attr "mode"     "DI")])
3056 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3057 ;; instruction that treats all NaN inputs as invalid; it does not flip
3058 ;; their sign bit.  We therefore can't use that form if the signs of
3059 ;; NaNs matter.
3061 (define_insn "neg<mode>2"
3062   [(set (match_operand:ANYF 0 "register_operand" "=f")
3063         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3064   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3065   "neg.<fmt>\t%0,%1"
3066   [(set_attr "type" "fneg")
3067    (set_attr "mode" "<UNITMODE>")])
3069 (define_insn "one_cmpl<mode>2"
3070   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3071         (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3072   ""
3074   if (TARGET_MIPS16)
3075     return "not\t%0,%1";
3076   else
3077     return "nor\t%0,%.,%1";
3079   [(set_attr "alu_type" "not")
3080    (set_attr "compression" "micromips,*")
3081    (set_attr "mode" "<MODE>")])
3084 ;;  ....................
3086 ;;      LOGICAL
3088 ;;  ....................
3091 ;; Many of these instructions use trivial define_expands, because we
3092 ;; want to use a different set of constraints when TARGET_MIPS16.
3094 (define_expand "and<mode>3"
3095   [(set (match_operand:GPR 0 "register_operand")
3096         (and:GPR (match_operand:GPR 1 "register_operand")
3097                  (match_operand:GPR 2 "and_reg_operand")))])
3099 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3100 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
3101 ;; Note that this variant does not trigger for SI mode because we require
3102 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3103 ;; sign-extended SImode value.
3105 ;; These are possible combinations for operand 1 and 2.  The table
3106 ;; includes both MIPS and MIPS16 cases.  (r=register, mem=memory,
3107 ;; 16=MIPS16, x=match, S=split):
3109 ;;     \ op1    r/EXT   r/!EXT  mem   r/16   mem/16
3110 ;;  op2
3112 ;;  andi           x     x
3113 ;;  0xff           x     x       x             x
3114 ;;  0xffff         x     x       x             x
3115 ;;  0xffff_ffff    x     S       x     S       x
3116 ;;  low-bitmask    x
3117 ;;  register       x     x
3118 ;;  register =op1                      x
3120 (define_insn "*and<mode>3"
3121   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3122         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3123                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3124   "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3126   int len;
3128   switch (which_alternative)
3129     {
3130     case 0:
3131       operands[1] = gen_lowpart (QImode, operands[1]);
3132       return "lbu\t%0,%1";
3133     case 1:
3134       operands[1] = gen_lowpart (HImode, operands[1]);
3135       return "lhu\t%0,%1";
3136     case 2:
3137       operands[1] = gen_lowpart (SImode, operands[1]);
3138       return "lwu\t%0,%1";
3139     case 3:
3140     case 4:
3141       return "andi\t%0,%1,%x2";
3142     case 5:
3143       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3144       operands[2] = GEN_INT (len);
3145       return "<d>ext\t%0,%1,0,%2";
3146     case 6:
3147       return "#";
3148     case 7:
3149     case 8:
3150       return "and\t%0,%1,%2";
3151     default:
3152       gcc_unreachable ();
3153     }
3155   [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3156    (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3157    (set_attr "mode" "<MODE>")])
3159 (define_insn "*and<mode>3_mips16"
3160   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3161         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3162                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3163   "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3165   switch (which_alternative)
3166     {
3167     case 0:
3168       operands[1] = gen_lowpart (QImode, operands[1]);
3169       return "lbu\t%0,%1";
3170     case 1:
3171       operands[1] = gen_lowpart (HImode, operands[1]);
3172       return "lhu\t%0,%1";
3173     case 2:
3174       operands[1] = gen_lowpart (SImode, operands[1]);
3175       return "lwu\t%0,%1";
3176     case 3:
3177       return "#";
3178     case 4:
3179       return "and\t%0,%2";
3180     default:
3181       gcc_unreachable ();
3182     }
3184   [(set_attr "move_type" "load,load,load,shift_shift,logical")
3185    (set_attr "mode" "<MODE>")])
3187 (define_expand "ior<mode>3"
3188   [(set (match_operand:GPR 0 "register_operand")
3189         (ior:GPR (match_operand:GPR 1 "register_operand")
3190                  (match_operand:GPR 2 "uns_arith_operand")))]
3191   ""
3193   if (TARGET_MIPS16)
3194     operands[2] = force_reg (<MODE>mode, operands[2]);
3197 (define_insn "*ior<mode>3"
3198   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3199         (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3200                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3201   "!TARGET_MIPS16"
3202   "@
3203    or\t%0,%1,%2
3204    or\t%0,%1,%2
3205    ori\t%0,%1,%x2"
3206   [(set_attr "alu_type" "or")
3207    (set_attr "compression" "micromips,*,*")
3208    (set_attr "mode" "<MODE>")])
3210 (define_insn "*ior<mode>3_mips16"
3211   [(set (match_operand:GPR 0 "register_operand" "=d")
3212         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3213                  (match_operand:GPR 2 "register_operand" "d")))]
3214   "TARGET_MIPS16"
3215   "or\t%0,%2"
3216   [(set_attr "alu_type" "or")
3217    (set_attr "mode" "<MODE>")])
3219 (define_expand "xor<mode>3"
3220   [(set (match_operand:GPR 0 "register_operand")
3221         (xor:GPR (match_operand:GPR 1 "register_operand")
3222                  (match_operand:GPR 2 "uns_arith_operand")))]
3223   ""
3224   "")
3226 (define_insn "*xor<mode>3"
3227   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3228         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3229                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3230   "!TARGET_MIPS16"
3231   "@
3232    xor\t%0,%1,%2
3233    xor\t%0,%1,%2
3234    xori\t%0,%1,%x2"
3235   [(set_attr "alu_type" "xor")
3236    (set_attr "compression" "micromips,*,*")
3237    (set_attr "mode" "<MODE>")])
3239 (define_insn "*xor<mode>3_mips16"
3240   [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3241         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3242                  (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3243   "TARGET_MIPS16"
3244   "@
3245    xor\t%0,%2
3246    cmpi\t%1,%2
3247    cmpi\t%1,%2
3248    cmp\t%1,%2"
3249   [(set_attr "alu_type" "xor")
3250    (set_attr "mode" "<MODE>")
3251    (set_attr "extended_mips16" "no,no,yes,no")])
3253 (define_insn "*nor<mode>3"
3254   [(set (match_operand:GPR 0 "register_operand" "=d")
3255         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3256                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3257   "!TARGET_MIPS16"
3258   "nor\t%0,%1,%2"
3259   [(set_attr "alu_type" "nor")
3260    (set_attr "mode" "<MODE>")])
3263 ;;  ....................
3265 ;;      TRUNCATION
3267 ;;  ....................
3271 (define_insn "truncdfsf2"
3272   [(set (match_operand:SF 0 "register_operand" "=f")
3273         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3274   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3275   "cvt.s.d\t%0,%1"
3276   [(set_attr "type"     "fcvt")
3277    (set_attr "cnv_mode" "D2S")   
3278    (set_attr "mode"     "SF")])
3280 ;; Integer truncation patterns.  Truncating SImode values to smaller
3281 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3282 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3283 ;; need to make sure that the lower 32 bits are properly sign-extended
3284 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3285 ;; smaller than SImode is equivalent to two separate truncations:
3287 ;;                        A       B
3288 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3289 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3291 ;; Step A needs a real instruction but step B does not.
3293 (define_insn "truncdi<mode>2"
3294   [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3295         (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3296   "TARGET_64BIT"
3297   "@
3298     sll\t%0,%1,0
3299     <store>\t%1,%0"
3300   [(set_attr "move_type" "sll0,store")
3301    (set_attr "mode" "SI")])
3303 ;; Combiner patterns to optimize shift/truncate combinations.
3305 (define_insn "*ashr_trunc<mode>"
3306   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3307         (truncate:SUBDI
3308           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3309                        (match_operand:DI 2 "const_arith_operand" ""))))]
3310   "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3311   "dsra\t%0,%1,%2"
3312   [(set_attr "type" "shift")
3313    (set_attr "mode" "<MODE>")])
3315 (define_insn "*lshr32_trunc<mode>"
3316   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3317         (truncate:SUBDI
3318           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3319                        (const_int 32))))]
3320   "TARGET_64BIT && !TARGET_MIPS16"
3321   "dsra\t%0,%1,32"
3322   [(set_attr "type" "shift")
3323    (set_attr "mode" "<MODE>")])
3325 ;; Logical shift by more than 32 results in proper SI values so truncation is
3326 ;; removed by the middle end.  Note that a logical shift by 32 is handled by
3327 ;; the previous pattern.
3328 (define_insn "*<optab>_trunc<mode>_exts"
3329   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3330         (truncate:SUBDI
3331          (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3332                          (match_operand:DI 2 "const_arith_operand" ""))))]
3333   "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3334   "exts\t%0,%1,%2,31"
3335   [(set_attr "type" "arith")
3336    (set_attr "mode" "<MODE>")])
3339 ;;  ....................
3341 ;;      ZERO EXTENSION
3343 ;;  ....................
3345 ;; Extension insns.
3347 (define_expand "zero_extendsidi2"
3348   [(set (match_operand:DI 0 "register_operand")
3349         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3350   "TARGET_64BIT")
3352 (define_insn_and_split "*zero_extendsidi2"
3353   [(set (match_operand:DI 0 "register_operand" "=d,d")
3354         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3355   "TARGET_64BIT && !ISA_HAS_EXT_INS"
3356   "@
3357    #
3358    lwu\t%0,%1"
3359   "&& reload_completed && REG_P (operands[1])"
3360   [(set (match_dup 0)
3361         (ashift:DI (match_dup 1) (const_int 32)))
3362    (set (match_dup 0)
3363         (lshiftrt:DI (match_dup 0) (const_int 32)))]
3364   { operands[1] = gen_lowpart (DImode, operands[1]); }
3365   [(set_attr "move_type" "shift_shift,load")
3366    (set_attr "mode" "DI")])
3368 (define_insn "*zero_extendsidi2_dext"
3369   [(set (match_operand:DI 0 "register_operand" "=d,d")
3370         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3371   "TARGET_64BIT && ISA_HAS_EXT_INS"
3372   "@
3373    dext\t%0,%1,0,32
3374    lwu\t%0,%1"
3375   [(set_attr "move_type" "arith,load")
3376    (set_attr "mode" "DI")])
3378 ;; See the comment before the *and<mode>3 pattern why this is generated by
3379 ;; combine.
3381 (define_split
3382   [(set (match_operand:DI 0 "register_operand")
3383         (and:DI (match_operand:DI 1 "register_operand")
3384                 (const_int 4294967295)))]
3385   "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3386   [(set (match_dup 0)
3387         (ashift:DI (match_dup 1) (const_int 32)))
3388    (set (match_dup 0)
3389         (lshiftrt:DI (match_dup 0) (const_int 32)))])
3391 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3392   [(set (match_operand:GPR 0 "register_operand")
3393         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3394   ""
3396   if (TARGET_MIPS16 && !GENERATE_MIPS16E
3397       && !memory_operand (operands[1], <SHORT:MODE>mode))
3398     {
3399       emit_insn (gen_and<GPR:mode>3 (operands[0],
3400                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
3401                                      force_reg (<GPR:MODE>mode,
3402                                                 GEN_INT (<SHORT:mask>))));
3403       DONE;
3404     }
3407 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3408   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3409         (zero_extend:GPR
3410              (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3411   "!TARGET_MIPS16"
3412   "@
3413    andi\t%0,%1,<SHORT:mask>
3414    andi\t%0,%1,<SHORT:mask>
3415    l<SHORT:size>u\t%0,%1"
3416   [(set_attr "move_type" "andi,andi,load")
3417    (set_attr "compression" "micromips,*,*")
3418    (set_attr "mode" "<GPR:MODE>")])
3420 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3421   [(set (match_operand:GPR 0 "register_operand" "=d")
3422         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3423   "GENERATE_MIPS16E"
3424   "ze<SHORT:size>\t%0"
3425   ;; This instruction is effectively a special encoding of ANDI.
3426   [(set_attr "move_type" "andi")
3427    (set_attr "mode" "<GPR:MODE>")])
3429 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3430   [(set (match_operand:GPR 0 "register_operand" "=d")
3431         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3432   "TARGET_MIPS16"
3433   "l<SHORT:size>u\t%0,%1"
3434   [(set_attr "move_type" "load")
3435    (set_attr "mode" "<GPR:MODE>")])
3437 (define_expand "zero_extendqihi2"
3438   [(set (match_operand:HI 0 "register_operand")
3439         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3440   ""
3442   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3443     {
3444       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3445                                        operands[1]));
3446       DONE;
3447     }
3450 (define_insn "*zero_extendqihi2"
3451   [(set (match_operand:HI 0 "register_operand" "=d,d")
3452         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3453   "!TARGET_MIPS16"
3454   "@
3455    andi\t%0,%1,0x00ff
3456    lbu\t%0,%1"
3457   [(set_attr "move_type" "andi,load")
3458    (set_attr "mode" "HI")])
3460 (define_insn "*zero_extendqihi2_mips16"
3461   [(set (match_operand:HI 0 "register_operand" "=d")
3462         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3463   "TARGET_MIPS16"
3464   "lbu\t%0,%1"
3465   [(set_attr "move_type" "load")
3466    (set_attr "mode" "HI")])
3468 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3470 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3471   [(set (match_operand:GPR 0 "register_operand" "=d")
3472         (zero_extend:GPR
3473             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3474   "TARGET_64BIT && !TARGET_MIPS16"
3476   operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3477   return "andi\t%0,%1,%x2";
3479   [(set_attr "alu_type" "and")
3480    (set_attr "mode" "<GPR:MODE>")])
3482 (define_insn "*zero_extendhi_truncqi"
3483   [(set (match_operand:HI 0 "register_operand" "=d")
3484         (zero_extend:HI
3485             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3486   "TARGET_64BIT && !TARGET_MIPS16"
3487   "andi\t%0,%1,0xff"
3488   [(set_attr "alu_type" "and")
3489    (set_attr "mode" "HI")])
3492 ;;  ....................
3494 ;;      SIGN EXTENSION
3496 ;;  ....................
3498 ;; Extension insns.
3499 ;; Those for integer source operand are ordered widest source type first.
3501 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3502 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3503 ;; and truncdisi2).  We can therefore get rid of register->register
3504 ;; instructions if we constrain the source to be in the same register as
3505 ;; the destination.
3507 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3508 ;; we split them into nothing before the post-reload scheduler runs.
3509 ;; These alternatives therefore have type "move" in order to reflect
3510 ;; what happens if the two pre-reload operands cannot be tied, and are
3511 ;; instead allocated two separate GPRs.  We don't distinguish between
3512 ;; the GPR and LO cases because we don't usually know during pre-reload
3513 ;; scheduling whether an operand will be LO or not.
3514 (define_insn_and_split "extendsidi2"
3515   [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3516         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3517   "TARGET_64BIT"
3518   "@
3519    #
3520    #
3521    lw\t%0,%1"
3522   "&& reload_completed && register_operand (operands[1], VOIDmode)"
3523   [(const_int 0)]
3525   emit_note (NOTE_INSN_DELETED);
3526   DONE;
3528   [(set_attr "move_type" "move,move,load")
3529    (set_attr "mode" "DI")])
3531 (define_expand "extend<SHORT:mode><GPR:mode>2"
3532   [(set (match_operand:GPR 0 "register_operand")
3533         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3534   "")
3536 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3537   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3538         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3539   "GENERATE_MIPS16E"
3540   "@
3541    se<SHORT:size>\t%0
3542    l<SHORT:size>\t%0,%1"
3543   [(set_attr "move_type" "signext,load")
3544    (set_attr "mode" "<GPR:MODE>")])
3546 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3547   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3548         (sign_extend:GPR
3549              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3550   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3551   "@
3552    #
3553    l<SHORT:size>\t%0,%1"
3554   "&& reload_completed && REG_P (operands[1])"
3555   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3556    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3558   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3559   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3560                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3562   [(set_attr "move_type" "shift_shift,load")
3563    (set_attr "mode" "<GPR:MODE>")])
3565 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3566   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3567         (sign_extend:GPR
3568              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3569   "ISA_HAS_SEB_SEH"
3570   "@
3571    se<SHORT:size>\t%0,%1
3572    l<SHORT:size>\t%0,%1"
3573   [(set_attr "move_type" "signext,load")
3574    (set_attr "mode" "<GPR:MODE>")])
3576 (define_expand "extendqihi2"
3577   [(set (match_operand:HI 0 "register_operand")
3578         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3579   "")
3581 (define_insn "*extendqihi2_mips16e"
3582   [(set (match_operand:HI 0 "register_operand" "=d,d")
3583         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3584   "GENERATE_MIPS16E"
3585   "@
3586    seb\t%0
3587    lb\t%0,%1"
3588   [(set_attr "move_type" "signext,load")
3589    (set_attr "mode" "SI")])
3591 (define_insn_and_split "*extendqihi2"
3592   [(set (match_operand:HI 0 "register_operand" "=d,d")
3593         (sign_extend:HI
3594              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3595   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3596   "@
3597    #
3598    lb\t%0,%1"
3599   "&& reload_completed && REG_P (operands[1])"
3600   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3601    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3603   operands[0] = gen_lowpart (SImode, operands[0]);
3604   operands[1] = gen_lowpart (SImode, operands[1]);
3605   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3606                          - GET_MODE_BITSIZE (QImode));
3608   [(set_attr "move_type" "shift_shift,load")
3609    (set_attr "mode" "SI")])
3611 (define_insn "*extendqihi2_seb"
3612   [(set (match_operand:HI 0 "register_operand" "=d,d")
3613         (sign_extend:HI
3614              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3615   "ISA_HAS_SEB_SEH"
3616   "@
3617    seb\t%0,%1
3618    lb\t%0,%1"
3619   [(set_attr "move_type" "signext,load")
3620    (set_attr "mode" "SI")])
3622 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
3623 ;; use the shift/truncate patterns.
3625 (define_insn_and_split "*extenddi_truncate<mode>"
3626   [(set (match_operand:DI 0 "register_operand" "=d")
3627         (sign_extend:DI
3628             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3629   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3630   "#"
3631   "&& reload_completed"
3632   [(set (match_dup 2)
3633         (ashift:DI (match_dup 1)
3634                    (match_dup 3)))
3635    (set (match_dup 0)
3636         (ashiftrt:DI (match_dup 2)
3637                      (match_dup 3)))]
3639   operands[2] = gen_lowpart (DImode, operands[0]);
3640   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3642   [(set_attr "move_type" "shift_shift")
3643    (set_attr "mode" "DI")])
3645 (define_insn_and_split "*extendsi_truncate<mode>"
3646   [(set (match_operand:SI 0 "register_operand" "=d")
3647         (sign_extend:SI
3648             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3649   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3650   "#"
3651   "&& reload_completed"
3652   [(set (match_dup 2)
3653         (ashift:DI (match_dup 1)
3654                    (match_dup 3)))
3655    (set (match_dup 0)
3656         (truncate:SI (ashiftrt:DI (match_dup 2)
3657                                   (match_dup 3))))]
3659   operands[2] = gen_lowpart (DImode, operands[0]);
3660   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3662   [(set_attr "move_type" "shift_shift")
3663    (set_attr "mode" "SI")])
3665 (define_insn_and_split "*extendhi_truncateqi"
3666   [(set (match_operand:HI 0 "register_operand" "=d")
3667         (sign_extend:HI
3668             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3669   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3670   "#"
3671   "&& reload_completed"
3672   [(set (match_dup 2)
3673         (ashift:DI (match_dup 1)
3674                    (const_int 56)))
3675    (set (match_dup 0)
3676         (truncate:HI (ashiftrt:DI (match_dup 2)
3677                                   (const_int 56))))]
3679   operands[2] = gen_lowpart (DImode, operands[0]);
3681   [(set_attr "move_type" "shift_shift")
3682    (set_attr "mode" "SI")])
3684 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3685   [(set (match_operand:GPR 0 "register_operand" "=d")
3686         (sign_extend:GPR
3687             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3688   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3690   operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3691   return "exts\t%0,%1,0,%m2";
3693   [(set_attr "type" "arith")
3694    (set_attr "mode" "<GPR:MODE>")])
3696 (define_insn "*extendhi_truncateqi_exts"
3697   [(set (match_operand:HI 0 "register_operand" "=d")
3698         (sign_extend:HI
3699             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3700   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3701   "exts\t%0,%1,0,7"
3702   [(set_attr "type" "arith")
3703    (set_attr "mode" "SI")])
3705 (define_insn "extendsfdf2"
3706   [(set (match_operand:DF 0 "register_operand" "=f")
3707         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3708   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3709   "cvt.d.s\t%0,%1"
3710   [(set_attr "type"     "fcvt")
3711    (set_attr "cnv_mode" "S2D")   
3712    (set_attr "mode"     "DF")])
3715 ;;  ....................
3717 ;;      CONVERSIONS
3719 ;;  ....................
3721 (define_expand "fix_truncdfsi2"
3722   [(set (match_operand:SI 0 "register_operand")
3723         (fix:SI (match_operand:DF 1 "register_operand")))]
3724   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3726   if (!ISA_HAS_TRUNC_W)
3727     {
3728       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3729       DONE;
3730     }
3733 (define_insn "fix_truncdfsi2_insn"
3734   [(set (match_operand:SI 0 "register_operand" "=f")
3735         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3736   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3737   "trunc.w.d %0,%1"
3738   [(set_attr "type"     "fcvt")
3739    (set_attr "mode"     "DF")
3740    (set_attr "cnv_mode" "D2I")])
3742 (define_insn "fix_truncdfsi2_macro"
3743   [(set (match_operand:SI 0 "register_operand" "=f")
3744         (fix:SI (match_operand:DF 1 "register_operand" "f")))
3745    (clobber (match_scratch:DF 2 "=d"))]
3746   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3748   if (mips_nomacro.nesting_level > 0)
3749     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3750   else
3751     return "trunc.w.d %0,%1,%2";
3753   [(set_attr "type"     "fcvt")
3754    (set_attr "mode"     "DF")
3755    (set_attr "cnv_mode" "D2I")
3756    (set_attr "insn_count" "9")])
3758 (define_expand "fix_truncsfsi2"
3759   [(set (match_operand:SI 0 "register_operand")
3760         (fix:SI (match_operand:SF 1 "register_operand")))]
3761   "TARGET_HARD_FLOAT"
3763   if (!ISA_HAS_TRUNC_W)
3764     {
3765       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3766       DONE;
3767     }
3770 (define_insn "fix_truncsfsi2_insn"
3771   [(set (match_operand:SI 0 "register_operand" "=f")
3772         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3773   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3774   "trunc.w.s %0,%1"
3775   [(set_attr "type"     "fcvt")
3776    (set_attr "mode"     "SF")
3777    (set_attr "cnv_mode" "S2I")])
3779 (define_insn "fix_truncsfsi2_macro"
3780   [(set (match_operand:SI 0 "register_operand" "=f")
3781         (fix:SI (match_operand:SF 1 "register_operand" "f")))
3782    (clobber (match_scratch:SF 2 "=d"))]
3783   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3785   if (mips_nomacro.nesting_level > 0)
3786     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3787   else
3788     return "trunc.w.s %0,%1,%2";
3790   [(set_attr "type"     "fcvt")
3791    (set_attr "mode"     "SF")
3792    (set_attr "cnv_mode" "S2I")
3793    (set_attr "insn_count" "9")])
3796 (define_insn "fix_truncdfdi2"
3797   [(set (match_operand:DI 0 "register_operand" "=f")
3798         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3799   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3800   "trunc.l.d %0,%1"
3801   [(set_attr "type"     "fcvt")
3802    (set_attr "mode"     "DF")
3803    (set_attr "cnv_mode" "D2I")])
3806 (define_insn "fix_truncsfdi2"
3807   [(set (match_operand:DI 0 "register_operand" "=f")
3808         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3809   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3810   "trunc.l.s %0,%1"
3811   [(set_attr "type"     "fcvt")
3812    (set_attr "mode"     "SF")
3813    (set_attr "cnv_mode" "S2I")])
3816 (define_insn "floatsidf2"
3817   [(set (match_operand:DF 0 "register_operand" "=f")
3818         (float:DF (match_operand:SI 1 "register_operand" "f")))]
3819   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3820   "cvt.d.w\t%0,%1"
3821   [(set_attr "type"     "fcvt")
3822    (set_attr "mode"     "DF")
3823    (set_attr "cnv_mode" "I2D")])
3826 (define_insn "floatdidf2"
3827   [(set (match_operand:DF 0 "register_operand" "=f")
3828         (float:DF (match_operand:DI 1 "register_operand" "f")))]
3829   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3830   "cvt.d.l\t%0,%1"
3831   [(set_attr "type"     "fcvt")
3832    (set_attr "mode"     "DF")
3833    (set_attr "cnv_mode" "I2D")])
3836 (define_insn "floatsisf2"
3837   [(set (match_operand:SF 0 "register_operand" "=f")
3838         (float:SF (match_operand:SI 1 "register_operand" "f")))]
3839   "TARGET_HARD_FLOAT"
3840   "cvt.s.w\t%0,%1"
3841   [(set_attr "type"     "fcvt")
3842    (set_attr "mode"     "SF")
3843    (set_attr "cnv_mode" "I2S")])
3846 (define_insn "floatdisf2"
3847   [(set (match_operand:SF 0 "register_operand" "=f")
3848         (float:SF (match_operand:DI 1 "register_operand" "f")))]
3849   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3850   "cvt.s.l\t%0,%1"
3851   [(set_attr "type"     "fcvt")
3852    (set_attr "mode"     "SF")
3853    (set_attr "cnv_mode" "I2S")])
3856 (define_expand "fixuns_truncdfsi2"
3857   [(set (match_operand:SI 0 "register_operand")
3858         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3859   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3861   rtx reg1 = gen_reg_rtx (DFmode);
3862   rtx reg2 = gen_reg_rtx (DFmode);
3863   rtx reg3 = gen_reg_rtx (SImode);
3864   rtx_code_label *label1 = gen_label_rtx ();
3865   rtx_code_label *label2 = gen_label_rtx ();
3866   rtx test;
3867   REAL_VALUE_TYPE offset;
3869   real_2expN (&offset, 31, DFmode);
3871   if (reg1)                     /* Turn off complaints about unreached code.  */
3872     {
3873       mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3874       do_pending_stack_adjust ();
3876       test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3877       emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3879       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3880       emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3881                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
3882       emit_barrier ();
3884       emit_label (label1);
3885       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3886       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3887                                      (BITMASK_HIGH, SImode)));
3889       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3890       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3892       emit_label (label2);
3894       /* Allow REG_NOTES to be set on last insn (labels don't have enough
3895          fields, and can't be used for REG_NOTES anyway).  */
3896       emit_use (stack_pointer_rtx);
3897       DONE;
3898     }
3902 (define_expand "fixuns_truncdfdi2"
3903   [(set (match_operand:DI 0 "register_operand")
3904         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3905   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3907   rtx reg1 = gen_reg_rtx (DFmode);
3908   rtx reg2 = gen_reg_rtx (DFmode);
3909   rtx reg3 = gen_reg_rtx (DImode);
3910   rtx_code_label *label1 = gen_label_rtx ();
3911   rtx_code_label *label2 = gen_label_rtx ();
3912   rtx test;
3913   REAL_VALUE_TYPE offset;
3915   real_2expN (&offset, 63, DFmode);
3917   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3918   do_pending_stack_adjust ();
3920   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3921   emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3923   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3924   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3925                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3926   emit_barrier ();
3928   emit_label (label1);
3929   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3930   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3931   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3933   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3934   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3936   emit_label (label2);
3938   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3939      fields, and can't be used for REG_NOTES anyway).  */
3940   emit_use (stack_pointer_rtx);
3941   DONE;
3945 (define_expand "fixuns_truncsfsi2"
3946   [(set (match_operand:SI 0 "register_operand")
3947         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3948   "TARGET_HARD_FLOAT"
3950   rtx reg1 = gen_reg_rtx (SFmode);
3951   rtx reg2 = gen_reg_rtx (SFmode);
3952   rtx reg3 = gen_reg_rtx (SImode);
3953   rtx_code_label *label1 = gen_label_rtx ();
3954   rtx_code_label *label2 = gen_label_rtx ();
3955   rtx test;
3956   REAL_VALUE_TYPE offset;
3958   real_2expN (&offset, 31, SFmode);
3960   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3961   do_pending_stack_adjust ();
3963   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3964   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3966   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3967   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3968                                gen_rtx_LABEL_REF (VOIDmode, label2)));
3969   emit_barrier ();
3971   emit_label (label1);
3972   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3973   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3974                                  (BITMASK_HIGH, SImode)));
3976   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3977   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3979   emit_label (label2);
3981   /* Allow REG_NOTES to be set on last insn (labels don't have enough
3982      fields, and can't be used for REG_NOTES anyway).  */
3983   emit_use (stack_pointer_rtx);
3984   DONE;
3988 (define_expand "fixuns_truncsfdi2"
3989   [(set (match_operand:DI 0 "register_operand")
3990         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3991   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3993   rtx reg1 = gen_reg_rtx (SFmode);
3994   rtx reg2 = gen_reg_rtx (SFmode);
3995   rtx reg3 = gen_reg_rtx (DImode);
3996   rtx_code_label *label1 = gen_label_rtx ();
3997   rtx_code_label *label2 = gen_label_rtx ();
3998   rtx test;
3999   REAL_VALUE_TYPE offset;
4001   real_2expN (&offset, 63, SFmode);
4003   mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
4004   do_pending_stack_adjust ();
4006   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4007   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4009   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4010   emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
4011                                gen_rtx_LABEL_REF (VOIDmode, label2)));
4012   emit_barrier ();
4014   emit_label (label1);
4015   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4016   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4017   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4019   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4020   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4022   emit_label (label2);
4024   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4025      fields, and can't be used for REG_NOTES anyway).  */
4026   emit_use (stack_pointer_rtx);
4027   DONE;
4031 ;;  ....................
4033 ;;      DATA MOVEMENT
4035 ;;  ....................
4037 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4039 (define_expand "extvmisalign<mode>"
4040   [(set (match_operand:GPR 0 "register_operand")
4041         (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4042                           (match_operand 2 "const_int_operand")
4043                           (match_operand 3 "const_int_operand")))]
4044   "ISA_HAS_LWL_LWR"
4046   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4047                                          INTVAL (operands[2]),
4048                                          INTVAL (operands[3]),
4049                                          /*unsigned=*/ false))
4050     DONE;
4051   else
4052     FAIL;
4055 (define_expand "extv<mode>"
4056   [(set (match_operand:GPR 0 "register_operand")
4057         (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4058                           (match_operand 2 "const_int_operand")
4059                           (match_operand 3 "const_int_operand")))]
4060   "ISA_HAS_EXTS"
4062   if (UINTVAL (operands[2]) > 32)
4063     FAIL;
4066 (define_insn "*extv<mode>"
4067   [(set (match_operand:GPR 0 "register_operand" "=d")
4068         (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4069                           (match_operand 2 "const_int_operand" "")
4070                           (match_operand 3 "const_int_operand" "")))]
4071   "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4072   "exts\t%0,%1,%3,%m2"
4073   [(set_attr "type"     "arith")
4074    (set_attr "mode"     "<MODE>")])
4076 (define_expand "extzvmisalign<mode>"
4077   [(set (match_operand:GPR 0 "register_operand")
4078         (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4079                           (match_operand 2 "const_int_operand")
4080                           (match_operand 3 "const_int_operand")))]
4081   "ISA_HAS_LWL_LWR"
4083   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4084                                          INTVAL (operands[2]),
4085                                          INTVAL (operands[3]),
4086                                          /*unsigned=*/ true))
4087     DONE;
4088   else
4089     FAIL;
4092 (define_expand "extzv<mode>"
4093   [(set (match_operand:GPR 0 "register_operand")
4094         (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4095                           (match_operand 2 "const_int_operand")
4096                           (match_operand 3 "const_int_operand")))]
4097   ""
4099   if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4100                            INTVAL (operands[3])))
4101     FAIL;
4104 (define_insn "*extzv<mode>"
4105   [(set (match_operand:GPR 0 "register_operand" "=d")
4106         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4107                           (match_operand 2 "const_int_operand" "")
4108                           (match_operand 3 "const_int_operand" "")))]
4109   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4110                        INTVAL (operands[3]))"
4111   "<d>ext\t%0,%1,%3,%2"
4112   [(set_attr "type"     "arith")
4113    (set_attr "mode"     "<MODE>")])
4115 (define_insn "*extzv_truncsi_exts"
4116   [(set (match_operand:SI 0 "register_operand" "=d")
4117         (truncate:SI
4118          (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4119                           (match_operand 2 "const_int_operand" "")
4120                           (match_operand 3 "const_int_operand" ""))))]
4121   "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4122   "exts\t%0,%1,%3,31"
4123   [(set_attr "type"     "arith")
4124    (set_attr "mode"     "SI")])
4127 (define_expand "insvmisalign<mode>"
4128   [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4129                           (match_operand 1 "const_int_operand")
4130                           (match_operand 2 "const_int_operand"))
4131         (match_operand:GPR 3 "reg_or_0_operand"))]
4132   "ISA_HAS_LWL_LWR"
4134   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4135                                           INTVAL (operands[1]),
4136                                           INTVAL (operands[2])))
4137     DONE;
4138   else
4139     FAIL;
4142 (define_expand "insv<mode>"
4143   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4144                           (match_operand 1 "const_int_operand")
4145                           (match_operand 2 "const_int_operand"))
4146         (match_operand:GPR 3 "reg_or_0_operand"))]
4147   ""
4149   if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4150                            INTVAL (operands[2])))
4151     FAIL;
4154 (define_insn "*insv<mode>"
4155   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4156                           (match_operand:SI 1 "const_int_operand" "")
4157                           (match_operand:SI 2 "const_int_operand" ""))
4158         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4159   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4160                        INTVAL (operands[2]))"
4161   "<d>ins\t%0,%z3,%2,%1"
4162   [(set_attr "type"     "arith")
4163    (set_attr "mode"     "<MODE>")])
4165 ;; Combiner pattern for cins (clear and insert bit field).  We can
4166 ;; implement mask-and-shift-left operation with this.  Note that if
4167 ;; the upper bit of the mask is set in an SImode operation, the mask
4168 ;; itself will be sign-extended.  mask_low_and_shift_len will
4169 ;; therefore be greater than our threshold of 32.
4171 (define_insn "*cins<mode>"
4172   [(set (match_operand:GPR 0 "register_operand" "=d")
4173         (and:GPR
4174          (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4175                      (match_operand:GPR 2 "const_int_operand" ""))
4176          (match_operand:GPR 3 "const_int_operand" "")))]
4177   "ISA_HAS_CINS
4178    && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4180   operands[3] =
4181     GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4182   return "cins\t%0,%1,%2,%m3";
4184   [(set_attr "type"     "shift")
4185    (set_attr "mode"     "<MODE>")])
4187 ;; Unaligned word moves generated by the bit field patterns.
4189 ;; As far as the rtl is concerned, both the left-part and right-part
4190 ;; instructions can access the whole field.  However, the real operand
4191 ;; refers to just the first or the last byte (depending on endianness).
4192 ;; We therefore use two memory operands to each instruction, one to
4193 ;; describe the rtl effect and one to use in the assembly output.
4195 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4196 ;; This allows us to use the standard length calculations for the "load"
4197 ;; and "store" type attributes.
4199 (define_insn "mov_<load>l"
4200   [(set (match_operand:GPR 0 "register_operand" "=d")
4201         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4202                      (match_operand:QI 2 "memory_operand" "ZC")]
4203                     UNSPEC_LOAD_LEFT))]
4204   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4205   "<load>l\t%0,%2"
4206   [(set_attr "move_type" "load")
4207    (set_attr "mode" "<MODE>")])
4209 (define_insn "mov_<load>r"
4210   [(set (match_operand:GPR 0 "register_operand" "=d")
4211         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4212                      (match_operand:QI 2 "memory_operand" "ZC")
4213                      (match_operand:GPR 3 "register_operand" "0")]
4214                     UNSPEC_LOAD_RIGHT))]
4215   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4216   "<load>r\t%0,%2"
4217   [(set_attr "move_type" "load")
4218    (set_attr "mode" "<MODE>")])
4220 (define_insn "mov_<store>l"
4221   [(set (match_operand:BLK 0 "memory_operand" "=m")
4222         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4223                      (match_operand:QI 2 "memory_operand" "ZC")]
4224                     UNSPEC_STORE_LEFT))]
4225   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4226   "<store>l\t%z1,%2"
4227   [(set_attr "move_type" "store")
4228    (set_attr "mode" "<MODE>")])
4230 (define_insn "mov_<store>r"
4231   [(set (match_operand:BLK 0 "memory_operand" "+m")
4232         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4233                      (match_operand:QI 2 "memory_operand" "ZC")
4234                      (match_dup 0)]
4235                     UNSPEC_STORE_RIGHT))]
4236   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4237   "<store>r\t%z1,%2"
4238   [(set_attr "move_type" "store")
4239    (set_attr "mode" "<MODE>")])
4241 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4242 ;; The required value is:
4244 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4246 ;; which translates to:
4248 ;;      lui     op0,%highest(op1)
4249 ;;      daddiu  op0,op0,%higher(op1)
4250 ;;      dsll    op0,op0,16
4251 ;;      daddiu  op0,op0,%hi(op1)
4252 ;;      dsll    op0,op0,16
4254 ;; The split is deferred until after flow2 to allow the peephole2 below
4255 ;; to take effect.
4256 (define_insn_and_split "*lea_high64"
4257   [(set (match_operand:DI 0 "register_operand" "=d")
4258         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4259   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4260   "#"
4261   "&& epilogue_completed"
4262   [(set (match_dup 0) (high:DI (match_dup 2)))
4263    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4264    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4265    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4266    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4268   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4269   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4271   [(set_attr "insn_count" "5")])
4273 ;; Use a scratch register to reduce the latency of the above pattern
4274 ;; on superscalar machines.  The optimized sequence is:
4276 ;;      lui     op1,%highest(op2)
4277 ;;      lui     op0,%hi(op2)
4278 ;;      daddiu  op1,op1,%higher(op2)
4279 ;;      dsll32  op1,op1,0
4280 ;;      daddu   op1,op1,op0
4281 (define_peephole2
4282   [(set (match_operand:DI 1 "d_operand")
4283         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4284    (match_scratch:DI 0 "d")]
4285   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4286   [(set (match_dup 1) (high:DI (match_dup 3)))
4287    (set (match_dup 0) (high:DI (match_dup 4)))
4288    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4289    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4290    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4292   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4293   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4296 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4297 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
4298 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4299 ;; used once.  We can then use the sequence:
4301 ;;      lui     op0,%highest(op1)
4302 ;;      lui     op2,%hi(op1)
4303 ;;      daddiu  op0,op0,%higher(op1)
4304 ;;      daddiu  op2,op2,%lo(op1)
4305 ;;      dsll32  op0,op0,0
4306 ;;      daddu   op0,op0,op2
4308 ;; which takes 4 cycles on most superscalar targets.
4309 (define_insn_and_split "*lea64"
4310   [(set (match_operand:DI 0 "register_operand" "=d")
4311         (match_operand:DI 1 "absolute_symbolic_operand" ""))
4312    (clobber (match_scratch:DI 2 "=&d"))]
4313   "!TARGET_MIPS16
4314    && TARGET_EXPLICIT_RELOCS
4315    && ABI_HAS_64BIT_SYMBOLS
4316    && cse_not_expected"
4317   "#"
4318   "&& reload_completed"
4319   [(set (match_dup 0) (high:DI (match_dup 3)))
4320    (set (match_dup 2) (high:DI (match_dup 4)))
4321    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4322    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4323    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4324    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4326   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4327   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4329   [(set_attr "insn_count" "6")])
4331 ;; Split HIGHs into:
4333 ;;      li op0,%hi(sym)
4334 ;;      sll op0,16
4336 ;; on MIPS16 targets.
4337 (define_split
4338   [(set (match_operand:P 0 "d_operand")
4339         (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4340   "TARGET_MIPS16 && reload_completed"
4341   [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4342    (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4344 (define_insn "*unshifted_high"
4345   [(set (match_operand:P 0 "d_operand" "=d")
4346         (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4347                   UNSPEC_UNSHIFTED_HIGH))]
4348   ""
4349   "li\t%0,%h1"
4350   [(set_attr "extended_mips16" "yes")])
4352 ;; Insns to fetch a symbol from a big GOT.
4354 (define_insn_and_split "*xgot_hi<mode>"
4355   [(set (match_operand:P 0 "register_operand" "=d")
4356         (high:P (match_operand:P 1 "got_disp_operand" "")))]
4357   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4358   "#"
4359   "&& reload_completed"
4360   [(set (match_dup 0) (high:P (match_dup 2)))
4361    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4363   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4364   operands[3] = pic_offset_table_rtx;
4366   [(set_attr "got" "xgot_high")
4367    (set_attr "mode" "<MODE>")])
4369 (define_insn_and_split "*xgot_lo<mode>"
4370   [(set (match_operand:P 0 "register_operand" "=d")
4371         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4372                   (match_operand:P 2 "got_disp_operand" "")))]
4373   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4374   "#"
4375   "&& reload_completed"
4376   [(set (match_dup 0)
4377         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4378   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4379   [(set_attr "got" "load")
4380    (set_attr "mode" "<MODE>")])
4382 ;; Insns to fetch a symbol from a normal GOT.
4384 (define_insn_and_split "*got_disp<mode>"
4385   [(set (match_operand:P 0 "register_operand" "=d")
4386         (match_operand:P 1 "got_disp_operand" ""))]
4387   "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4388   "#"
4389   "&& reload_completed"
4390   [(set (match_dup 0) (match_dup 2))]
4391   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4392   [(set_attr "got" "load")
4393    (set_attr "mode" "<MODE>")])
4395 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4397 (define_insn_and_split "*got_page<mode>"
4398   [(set (match_operand:P 0 "register_operand" "=d")
4399         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4400   "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4401   "#"
4402   "&& reload_completed"
4403   [(set (match_dup 0) (match_dup 2))]
4404   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4405   [(set_attr "got" "load")
4406    (set_attr "mode" "<MODE>")])
4408 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4409 (define_expand "unspec_got_<mode>"
4410   [(unspec:P [(match_operand:P 0)
4411               (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4413 ;; Lower-level instructions for loading an address from the GOT.
4414 ;; We could use MEMs, but an unspec gives more optimization
4415 ;; opportunities.
4417 (define_insn "load_got<mode>"
4418   [(set (match_operand:P 0 "register_operand" "=d")
4419         (unspec:P [(match_operand:P 1 "register_operand" "d")
4420                    (match_operand:P 2 "immediate_operand" "")]
4421                   UNSPEC_LOAD_GOT))]
4422   ""
4423   "<load>\t%0,%R2(%1)"
4424   [(set_attr "got" "load")
4425    (set_attr "mode" "<MODE>")])
4427 ;; Instructions for adding the low 16 bits of an address to a register.
4428 ;; Operand 2 is the address: mips_print_operand works out which relocation
4429 ;; should be applied.
4431 (define_insn "*low<mode>"
4432   [(set (match_operand:P 0 "register_operand" "=d")
4433         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4434                   (match_operand:P 2 "immediate_operand" "")))]
4435   "!TARGET_MIPS16"
4436   "<d>addiu\t%0,%1,%R2"
4437   [(set_attr "alu_type" "add")
4438    (set_attr "mode" "<MODE>")])
4440 (define_insn "*low<mode>_mips16"
4441   [(set (match_operand:P 0 "register_operand" "=d")
4442         (lo_sum:P (match_operand:P 1 "register_operand" "0")
4443                   (match_operand:P 2 "immediate_operand" "")))]
4444   "TARGET_MIPS16"
4445   "<d>addiu\t%0,%R2"
4446   [(set_attr "alu_type" "add")
4447    (set_attr "mode" "<MODE>")
4448    (set_attr "extended_mips16" "yes")])
4450 ;; Expose MIPS16 uses of the global pointer after reload if the function
4451 ;; is responsible for setting up the register itself.
4452 (define_split
4453   [(set (match_operand:GPR 0 "d_operand")
4454         (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4455   "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4456   [(set (match_dup 0) (match_dup 1))]
4457   { operands[1] = pic_offset_table_rtx; })
4459 ;; Allow combine to split complex const_int load sequences, using operand 2
4460 ;; to store the intermediate results.  See move_operand for details.
4461 (define_split
4462   [(set (match_operand:GPR 0 "register_operand")
4463         (match_operand:GPR 1 "splittable_const_int_operand"))
4464    (clobber (match_operand:GPR 2 "register_operand"))]
4465   ""
4466   [(const_int 0)]
4468   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4469   DONE;
4472 ;; Likewise, for symbolic operands.
4473 (define_split
4474   [(set (match_operand:P 0 "register_operand")
4475         (match_operand:P 1))
4476    (clobber (match_operand:P 2 "register_operand"))]
4477   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4478   [(set (match_dup 0) (match_dup 3))]
4480   mips_split_symbol (operands[2], operands[1],
4481                      MAX_MACHINE_MODE, &operands[3]);
4484 ;; 64-bit integer moves
4486 ;; Unlike most other insns, the move insns can't be split with
4487 ;; different predicates, because register spilling and other parts of
4488 ;; the compiler, have memoized the insn number already.
4490 (define_expand "movdi"
4491   [(set (match_operand:DI 0 "")
4492         (match_operand:DI 1 ""))]
4493   ""
4495   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4496     DONE;
4499 ;; For mips16, we need a special case to handle storing $31 into
4500 ;; memory, since we don't have a constraint to match $31.  This
4501 ;; instruction can be generated by save_restore_insns.
4503 (define_insn "*mov<mode>_ra"
4504   [(set (match_operand:GPR 0 "stack_operand" "=m")
4505         (reg:GPR RETURN_ADDR_REGNUM))]
4506   "TARGET_MIPS16"
4507   "<store>\t$31,%0"
4508   [(set_attr "move_type" "store")
4509    (set_attr "mode" "<MODE>")])
4511 (define_insn "*movdi_32bit"
4512   [(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")
4513         (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"))]
4514   "!TARGET_64BIT && !TARGET_MIPS16
4515    && (register_operand (operands[0], DImode)
4516        || reg_or_0_operand (operands[1], DImode))"
4517   { return mips_output_move (operands[0], operands[1]); }
4518   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4519    (set (attr "mode")
4520         (if_then_else (eq_attr "move_type" "imul")
4521                       (const_string "SI")
4522                       (const_string "DI")))])
4524 (define_insn "*movdi_32bit_mips16"
4525   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4526         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4527   "!TARGET_64BIT && TARGET_MIPS16
4528    && (register_operand (operands[0], DImode)
4529        || register_operand (operands[1], DImode))"
4530   { return mips_output_move (operands[0], operands[1]); }
4531   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4532    (set_attr "mode" "DI")])
4534 (define_insn "*movdi_64bit"
4535   [(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")
4536         (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"))]
4537   "TARGET_64BIT && !TARGET_MIPS16
4538    && (register_operand (operands[0], DImode)
4539        || reg_or_0_operand (operands[1], DImode))"
4540   { return mips_output_move (operands[0], operands[1]); }
4541   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4542    (set_attr "mode" "DI")])
4544 (define_insn "*movdi_64bit_mips16"
4545   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4546         (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4547   "TARGET_64BIT && TARGET_MIPS16
4548    && (register_operand (operands[0], DImode)
4549        || register_operand (operands[1], DImode))"
4550   { return mips_output_move (operands[0], operands[1]); }
4551   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4552    (set_attr "mode" "DI")])
4554 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4555 ;; when the original load is a 4 byte instruction but the add and the
4556 ;; load are 2 2 byte instructions.
4558 (define_split
4559   [(set (match_operand:DI 0 "d_operand")
4560         (mem:DI (plus:DI (match_dup 0)
4561                          (match_operand:DI 1 "const_int_operand"))))]
4562   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4563    && !TARGET_DEBUG_D_MODE
4564    && ((INTVAL (operands[1]) < 0
4565         && INTVAL (operands[1]) >= -0x10)
4566        || (INTVAL (operands[1]) >= 32 * 8
4567            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4568        || (INTVAL (operands[1]) >= 0
4569            && INTVAL (operands[1]) < 32 * 8
4570            && (INTVAL (operands[1]) & 7) != 0))"
4571   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4572    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4574   HOST_WIDE_INT val = INTVAL (operands[1]);
4576   if (val < 0)
4577     operands[2] = const0_rtx;
4578   else if (val >= 32 * 8)
4579     {
4580       int off = val & 7;
4582       operands[1] = GEN_INT (0x8 + off);
4583       operands[2] = GEN_INT (val - off - 0x8);
4584     }
4585   else
4586     {
4587       int off = val & 7;
4589       operands[1] = GEN_INT (off);
4590       operands[2] = GEN_INT (val - off);
4591     }
4594 ;; 32-bit Integer moves
4596 ;; Unlike most other insns, the move insns can't be split with
4597 ;; different predicates, because register spilling and other parts of
4598 ;; the compiler, have memoized the insn number already.
4600 (define_expand "mov<mode>"
4601   [(set (match_operand:IMOVE32 0 "")
4602         (match_operand:IMOVE32 1 ""))]
4603   ""
4605   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4606     DONE;
4609 ;; The difference between these two is whether or not ints are allowed
4610 ;; in FP registers (off by default, use -mdebugh to enable).
4612 (define_insn "*mov<mode>_internal"
4613   [(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")
4614         (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"))]
4615   "!TARGET_MIPS16
4616    && (register_operand (operands[0], <MODE>mode)
4617        || reg_or_0_operand (operands[1], <MODE>mode))"
4618   { return mips_output_move (operands[0], operands[1]); }
4619   [(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")
4620    (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4621    (set_attr "mode" "SI")])
4623 (define_insn "*mov<mode>_mips16"
4624   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4625         (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4626   "TARGET_MIPS16
4627    && (register_operand (operands[0], <MODE>mode)
4628        || register_operand (operands[1], <MODE>mode))"
4629   { return mips_output_move (operands[0], operands[1]); }
4630   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4631    (set_attr "mode" "SI")])
4633 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4634 ;; when the original load is a 4 byte instruction but the add and the
4635 ;; load are 2 2 byte instructions.
4637 (define_split
4638   [(set (match_operand:SI 0 "d_operand")
4639         (mem:SI (plus:SI (match_dup 0)
4640                          (match_operand:SI 1 "const_int_operand"))))]
4641   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4642    && ((INTVAL (operands[1]) < 0
4643         && INTVAL (operands[1]) >= -0x80)
4644        || (INTVAL (operands[1]) >= 32 * 4
4645            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4646        || (INTVAL (operands[1]) >= 0
4647            && INTVAL (operands[1]) < 32 * 4
4648            && (INTVAL (operands[1]) & 3) != 0))"
4649   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4650    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4652   HOST_WIDE_INT val = INTVAL (operands[1]);
4654   if (val < 0)
4655     operands[2] = const0_rtx;
4656   else if (val >= 32 * 4)
4657     {
4658       int off = val & 3;
4660       operands[1] = GEN_INT (0x7c + off);
4661       operands[2] = GEN_INT (val - off - 0x7c);
4662     }
4663   else
4664     {
4665       int off = val & 3;
4667       operands[1] = GEN_INT (off);
4668       operands[2] = GEN_INT (val - off);
4669     }
4672 ;; On the mips16, we can split a load of certain constants into a load
4673 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
4674 ;; instructions.
4676 (define_split
4677   [(set (match_operand:SI 0 "d_operand")
4678         (match_operand:SI 1 "const_int_operand"))]
4679   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4680    && INTVAL (operands[1]) >= 0x100
4681    && INTVAL (operands[1]) <= 0xff + 0x7f"
4682   [(set (match_dup 0) (match_dup 1))
4683    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4685   int val = INTVAL (operands[1]);
4687   operands[1] = GEN_INT (0xff);
4688   operands[2] = GEN_INT (val - 0xff);
4691 ;; MIPS4 supports loading and storing a floating point register from
4692 ;; the sum of two general registers.  We use two versions for each of
4693 ;; these four instructions: one where the two general registers are
4694 ;; SImode, and one where they are DImode.  This is because general
4695 ;; registers will be in SImode when they hold 32-bit values, but,
4696 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4697 ;; instructions will still work correctly.
4699 ;; ??? Perhaps it would be better to support these instructions by
4700 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends.  However, since
4701 ;; these instructions can only be used to load and store floating
4702 ;; point registers, that would probably cause trouble in reload.
4704 (define_insn "*<ANYF:loadx>_<P:mode>"
4705   [(set (match_operand:ANYF 0 "register_operand" "=f")
4706         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4707                           (match_operand:P 2 "register_operand" "d"))))]
4708   "ISA_HAS_LXC1_SXC1"
4709   "<ANYF:loadx>\t%0,%1(%2)"
4710   [(set_attr "type" "fpidxload")
4711    (set_attr "mode" "<ANYF:UNITMODE>")])
4713 (define_insn "*<ANYF:storex>_<P:mode>"
4714   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4715                           (match_operand:P 2 "register_operand" "d")))
4716         (match_operand:ANYF 0 "register_operand" "f"))]
4717   "ISA_HAS_LXC1_SXC1"
4718   "<ANYF:storex>\t%0,%1(%2)"
4719   [(set_attr "type" "fpidxstore")
4720    (set_attr "mode" "<ANYF:UNITMODE>")])
4722 ;; Scaled indexed address load.
4723 ;; Per md.texi, we only need to look for a pattern with multiply in the
4724 ;; address expression, not shift.
4726 (define_insn "*lwxs"
4727   [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4728         (mem:IMOVE32
4729           (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4730                           (const_int 4))
4731                   (match_operand:P 2 "register_operand" "d"))))]
4732   "ISA_HAS_LWXS"
4733   "lwxs\t%0,%1(%2)"
4734   [(set_attr "type"     "load")
4735    (set_attr "mode"     "SI")])
4737 ;; 16-bit Integer moves
4739 ;; Unlike most other insns, the move insns can't be split with
4740 ;; different predicates, because register spilling and other parts of
4741 ;; the compiler, have memoized the insn number already.
4742 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4744 (define_expand "movhi"
4745   [(set (match_operand:HI 0 "")
4746         (match_operand:HI 1 ""))]
4747   ""
4749   if (mips_legitimize_move (HImode, operands[0], operands[1]))
4750     DONE;
4753 (define_insn "*movhi_internal"
4754   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4755         (match_operand:HI 1 "move_operand"         "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4756   "!TARGET_MIPS16
4757    && (register_operand (operands[0], HImode)
4758        || reg_or_0_operand (operands[1], HImode))"
4759   { return mips_output_move (operands[0], operands[1]); }
4760   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4761    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4762    (set_attr "mode" "HI")])
4764 (define_insn "*movhi_mips16"
4765   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4766         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4767   "TARGET_MIPS16
4768    && (register_operand (operands[0], HImode)
4769        || register_operand (operands[1], HImode))"
4770   { return mips_output_move (operands[0], operands[1]); }
4771   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4772    (set_attr "mode" "HI")])
4774 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4775 ;; when the original load is a 4 byte instruction but the add and the
4776 ;; load are 2 2 byte instructions.
4778 (define_split
4779   [(set (match_operand:HI 0 "d_operand")
4780         (mem:HI (plus:SI (match_dup 0)
4781                          (match_operand:SI 1 "const_int_operand"))))]
4782   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4783    && ((INTVAL (operands[1]) < 0
4784         && INTVAL (operands[1]) >= -0x80)
4785        || (INTVAL (operands[1]) >= 32 * 2
4786            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4787        || (INTVAL (operands[1]) >= 0
4788            && INTVAL (operands[1]) < 32 * 2
4789            && (INTVAL (operands[1]) & 1) != 0))"
4790   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4791    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4793   HOST_WIDE_INT val = INTVAL (operands[1]);
4795   if (val < 0)
4796     operands[2] = const0_rtx;
4797   else if (val >= 32 * 2)
4798     {
4799       int off = val & 1;
4801       operands[1] = GEN_INT (0x7e + off);
4802       operands[2] = GEN_INT (val - off - 0x7e);
4803     }
4804   else
4805     {
4806       int off = val & 1;
4808       operands[1] = GEN_INT (off);
4809       operands[2] = GEN_INT (val - off);
4810     }
4813 ;; 8-bit Integer moves
4815 ;; Unlike most other insns, the move insns can't be split with
4816 ;; different predicates, because register spilling and other parts of
4817 ;; the compiler, have memoized the insn number already.
4818 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4820 (define_expand "movqi"
4821   [(set (match_operand:QI 0 "")
4822         (match_operand:QI 1 ""))]
4823   ""
4825   if (mips_legitimize_move (QImode, operands[0], operands[1]))
4826     DONE;
4829 (define_insn "*movqi_internal"
4830   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
4831         (match_operand:QI 1 "move_operand"         "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
4832   "!TARGET_MIPS16
4833    && (register_operand (operands[0], QImode)
4834        || reg_or_0_operand (operands[1], QImode))"
4835   { return mips_output_move (operands[0], operands[1]); }
4836   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4837    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4838    (set_attr "mode" "QI")])
4840 (define_insn "*movqi_mips16"
4841   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4842         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4843   "TARGET_MIPS16
4844    && (register_operand (operands[0], QImode)
4845        || register_operand (operands[1], QImode))"
4846   { return mips_output_move (operands[0], operands[1]); }
4847   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4848    (set_attr "mode" "QI")])
4850 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4851 ;; when the original load is a 4 byte instruction but the add and the
4852 ;; load are 2 2 byte instructions.
4854 (define_split
4855   [(set (match_operand:QI 0 "d_operand")
4856         (mem:QI (plus:SI (match_dup 0)
4857                          (match_operand:SI 1 "const_int_operand"))))]
4858   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4859    && ((INTVAL (operands[1]) < 0
4860         && INTVAL (operands[1]) >= -0x80)
4861        || (INTVAL (operands[1]) >= 32
4862            && INTVAL (operands[1]) <= 31 + 0x7f))"
4863   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4864    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4866   HOST_WIDE_INT val = INTVAL (operands[1]);
4868   if (val < 0)
4869     operands[2] = const0_rtx;
4870   else
4871     {
4872       operands[1] = GEN_INT (0x7f);
4873       operands[2] = GEN_INT (val - 0x7f);
4874     }
4877 ;; 32-bit floating point moves
4879 (define_expand "movsf"
4880   [(set (match_operand:SF 0 "")
4881         (match_operand:SF 1 ""))]
4882   ""
4884   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4885     DONE;
4888 (define_insn "movccf"
4889   [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
4890         (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
4891   "ISA_HAS_CCF"
4892   { return mips_output_move (operands[0], operands[1]); }
4893   [(set_attr "move_type" "fmove,fpload,fpstore")])
4895 (define_insn "*movsf_hardfloat"
4896   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4897         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4898   "TARGET_HARD_FLOAT
4899    && (register_operand (operands[0], SFmode)
4900        || reg_or_0_operand (operands[1], SFmode))"
4901   { return mips_output_move (operands[0], operands[1]); }
4902   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4903    (set_attr "mode" "SF")])
4905 (define_insn "*movsf_softfloat"
4906   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4907         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4908   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4909    && (register_operand (operands[0], SFmode)
4910        || reg_or_0_operand (operands[1], SFmode))"
4911   { return mips_output_move (operands[0], operands[1]); }
4912   [(set_attr "move_type" "move,load,store")
4913    (set_attr "mode" "SF")])
4915 (define_insn "*movsf_mips16"
4916   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4917         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4918   "TARGET_MIPS16
4919    && (register_operand (operands[0], SFmode)
4920        || register_operand (operands[1], SFmode))"
4921   { return mips_output_move (operands[0], operands[1]); }
4922   [(set_attr "move_type" "move,move,move,load,store")
4923    (set_attr "mode" "SF")])
4925 ;; 64-bit floating point moves
4927 (define_expand "movdf"
4928   [(set (match_operand:DF 0 "")
4929         (match_operand:DF 1 ""))]
4930   ""
4932   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4933     DONE;
4936 (define_insn "*movdf_hardfloat"
4937   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4938         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4939   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4940    && (register_operand (operands[0], DFmode)
4941        || reg_or_0_operand (operands[1], DFmode))"
4942   { return mips_output_move (operands[0], operands[1]); }
4943   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4944    (set_attr "mode" "DF")])
4946 (define_insn "*movdf_softfloat"
4947   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4948         (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4949   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4950    && (register_operand (operands[0], DFmode)
4951        || reg_or_0_operand (operands[1], DFmode))"
4952   { return mips_output_move (operands[0], operands[1]); }
4953   [(set_attr "move_type" "move,load,store")
4954    (set_attr "mode" "DF")])
4956 (define_insn "*movdf_mips16"
4957   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4958         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4959   "TARGET_MIPS16
4960    && (register_operand (operands[0], DFmode)
4961        || register_operand (operands[1], DFmode))"
4962   { return mips_output_move (operands[0], operands[1]); }
4963   [(set_attr "move_type" "move,move,move,load,store")
4964    (set_attr "mode" "DF")])
4966 ;; 128-bit integer moves
4968 (define_expand "movti"
4969   [(set (match_operand:TI 0)
4970         (match_operand:TI 1))]
4971   "TARGET_64BIT"
4973   if (mips_legitimize_move (TImode, operands[0], operands[1]))
4974     DONE;
4977 (define_insn "*movti"
4978   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
4979         (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
4980   "TARGET_64BIT
4981    && !TARGET_MIPS16
4982    && (register_operand (operands[0], TImode)
4983        || reg_or_0_operand (operands[1], TImode))"
4984   { return mips_output_move (operands[0], operands[1]); }
4985   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
4986    (set (attr "mode")
4987         (if_then_else (eq_attr "move_type" "imul")
4988                       (const_string "SI")
4989                       (const_string "TI")))])
4991 (define_insn "*movti_mips16"
4992   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4993         (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4994   "TARGET_64BIT
4995    && TARGET_MIPS16
4996    && (register_operand (operands[0], TImode)
4997        || register_operand (operands[1], TImode))"
4998   "#"
4999   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5000    (set_attr "mode" "TI")])
5002 ;; 128-bit floating point moves
5004 (define_expand "movtf"
5005   [(set (match_operand:TF 0)
5006         (match_operand:TF 1))]
5007   "TARGET_64BIT"
5009   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5010     DONE;
5013 ;; This pattern handles both hard- and soft-float cases.
5014 (define_insn "*movtf"
5015   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5016         (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5017   "TARGET_64BIT
5018    && !TARGET_MIPS16
5019    && (register_operand (operands[0], TFmode)
5020        || reg_or_0_operand (operands[1], TFmode))"
5021   "#"
5022   [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5023    (set_attr "mode" "TF")])
5025 (define_insn "*movtf_mips16"
5026   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5027         (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5028   "TARGET_64BIT
5029    && TARGET_MIPS16
5030    && (register_operand (operands[0], TFmode)
5031        || register_operand (operands[1], TFmode))"
5032   "#"
5033   [(set_attr "move_type" "move,move,move,load,store")
5034    (set_attr "mode" "TF")])
5036 (define_split
5037   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5038         (match_operand:MOVE64 1 "move_operand"))]
5039   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5040   [(const_int 0)]
5042   mips_split_move_insn (operands[0], operands[1], curr_insn);
5043   DONE;
5046 (define_split
5047   [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5048         (match_operand:MOVE128 1 "move_operand"))]
5049   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5050   [(const_int 0)]
5052   mips_split_move_insn (operands[0], operands[1], curr_insn);
5053   DONE;
5056 ;; When generating mips16 code, split moves of negative constants into
5057 ;; a positive "li" followed by a negation.
5058 (define_split
5059   [(set (match_operand 0 "d_operand")
5060         (match_operand 1 "const_int_operand"))]
5061   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5062   [(set (match_dup 2)
5063         (match_dup 3))
5064    (set (match_dup 2)
5065         (neg:SI (match_dup 2)))]
5067   operands[2] = gen_lowpart (SImode, operands[0]);
5068   operands[3] = GEN_INT (-INTVAL (operands[1]));
5071 ;; 64-bit paired-single floating point moves
5073 (define_expand "movv2sf"
5074   [(set (match_operand:V2SF 0)
5075         (match_operand:V2SF 1))]
5076   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5078   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5079     DONE;
5082 (define_insn "*movv2sf"
5083   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5084         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5085   "TARGET_HARD_FLOAT
5086    && TARGET_PAIRED_SINGLE_FLOAT
5087    && (register_operand (operands[0], V2SFmode)
5088        || reg_or_0_operand (operands[1], V2SFmode))"
5089   { return mips_output_move (operands[0], operands[1]); }
5090   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5091    (set_attr "mode" "DF")])
5093 ;; Extract the high part of a HI/LO value.  See mips_hard_regno_mode_ok_p
5094 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5096 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5097 ;; instead of MFHI.  This avoids both the normal MIPS III hi/lo hazards
5098 ;; and the errata related to -mfix-vr4130.
5099 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5100   [(set (match_operand:GPR 0 "register_operand" "=d")
5101         (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5102                     UNSPEC_MFHI))]
5103   ""
5104   { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5105   [(set_attr "type" "mfhi")
5106    (set_attr "mode" "<GPR:MODE>")])
5108 ;; Set the high part of a HI/LO value, given that the low part has
5109 ;; already been set.  See mips_hard_regno_mode_ok_p for the reason
5110 ;; why we can't just use (reg:GPR HI_REGNUM).
5111 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5112   [(set (match_operand:HILO 0 "register_operand" "=x")
5113         (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5114                       (match_operand:GPR 2 "register_operand" "l")]
5115                      UNSPEC_MTHI))]
5116   ""
5117   "mthi\t%z1"
5118   [(set_attr "type" "mthi")
5119    (set_attr "mode" "SI")])
5121 ;; Emit a doubleword move in which exactly one of the operands is
5122 ;; a floating-point register.  We can't just emit two normal moves
5123 ;; because of the constraints imposed by the FPU register model;
5124 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
5125 ;; the FPR whole and use special patterns to refer to each word of
5126 ;; the other operand.
5128 (define_expand "move_doubleword_fpr<mode>"
5129   [(set (match_operand:SPLITF 0)
5130         (match_operand:SPLITF 1))]
5131   ""
5133   if (FP_REG_RTX_P (operands[0]))
5134     {
5135       rtx low = mips_subword (operands[1], 0);
5136       rtx high = mips_subword (operands[1], 1);
5137       emit_insn (gen_load_low<mode> (operands[0], low));
5138       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5139         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5140       else
5141         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5142     }
5143   else
5144     {
5145       rtx low = mips_subword (operands[0], 0);
5146       rtx high = mips_subword (operands[0], 1);
5147       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5148       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5149         emit_insn (gen_mfhc1<mode> (high, operands[1]));
5150       else
5151         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5152     }
5153   DONE;
5156 ;; Load the low word of operand 0 with operand 1.
5157 (define_insn "load_low<mode>"
5158   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5159         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5160                        UNSPEC_LOAD_LOW))]
5161   "TARGET_HARD_FLOAT"
5163   operands[0] = mips_subword (operands[0], 0);
5164   return mips_output_move (operands[0], operands[1]);
5166   [(set_attr "move_type" "mtc,fpload")
5167    (set_attr "mode" "<HALFMODE>")])
5169 ;; Load the high word of operand 0 from operand 1, preserving the value
5170 ;; in the low word.
5171 (define_insn "load_high<mode>"
5172   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5173         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5174                         (match_operand:SPLITF 2 "register_operand" "0,0")]
5175                        UNSPEC_LOAD_HIGH))]
5176   "TARGET_HARD_FLOAT"
5178   operands[0] = mips_subword (operands[0], 1);
5179   return mips_output_move (operands[0], operands[1]);
5181   [(set_attr "move_type" "mtc,fpload")
5182    (set_attr "mode" "<HALFMODE>")])
5184 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
5185 ;; high word and 0 to store the low word.
5186 (define_insn "store_word<mode>"
5187   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5188         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5189                             (match_operand 2 "const_int_operand")]
5190                            UNSPEC_STORE_WORD))]
5191   "TARGET_HARD_FLOAT"
5193   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5194   return mips_output_move (operands[0], operands[1]);
5196   [(set_attr "move_type" "mfc,fpstore")
5197    (set_attr "mode" "<HALFMODE>")])
5199 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5200 ;; value in the low word.
5201 (define_insn "mthc1<mode>"
5202   [(set (match_operand:SPLITF 0 "register_operand" "=f")
5203         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5204                         (match_operand:SPLITF 2 "register_operand" "0")]
5205                        UNSPEC_MTHC1))]
5206   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5207   "mthc1\t%z1,%0"
5208   [(set_attr "move_type" "mtc")
5209    (set_attr "mode" "<HALFMODE>")])
5211 ;; Move high word of operand 1 to operand 0 using mfhc1.
5212 (define_insn "mfhc1<mode>"
5213   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5214         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5215                             UNSPEC_MFHC1))]
5216   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5217   "mfhc1\t%0,%1"
5218   [(set_attr "move_type" "mfc")
5219    (set_attr "mode" "<HALFMODE>")])
5221 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5222 (define_expand "load_const_gp_<mode>"
5223   [(set (match_operand:P 0 "register_operand" "=d")
5224         (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5226 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
5227 ;; of _gp from the start of this function.  Operand 1 is the incoming
5228 ;; function address.
5229 (define_insn_and_split "loadgp_newabi_<mode>"
5230   [(set (match_operand:P 0 "register_operand" "=&d")
5231         (unspec:P [(match_operand:P 1)
5232                    (match_operand:P 2 "register_operand" "d")]
5233                   UNSPEC_LOADGP))]
5234   "mips_current_loadgp_style () == LOADGP_NEWABI"
5235   { return mips_must_initialize_gp_p () ? "#" : ""; }
5236   "&& mips_must_initialize_gp_p ()"
5237   [(set (match_dup 0) (match_dup 3))
5238    (set (match_dup 0) (match_dup 4))
5239    (set (match_dup 0) (match_dup 5))]
5241   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5242   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5243   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5245   [(set_attr "type" "ghost")])
5247 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
5248 (define_insn_and_split "loadgp_absolute_<mode>"
5249   [(set (match_operand:P 0 "register_operand" "=d")
5250         (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5251   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5252   { return mips_must_initialize_gp_p () ? "#" : ""; }
5253   "&& mips_must_initialize_gp_p ()"
5254   [(const_int 0)]
5256   mips_emit_move (operands[0], operands[1]);
5257   DONE;
5259   [(set_attr "type" "ghost")])
5261 ;; This blockage instruction prevents the gp load from being
5262 ;; scheduled after an implicit use of gp.  It also prevents
5263 ;; the load from being deleted as dead.
5264 (define_insn "loadgp_blockage"
5265   [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5266   ""
5267   ""
5268   [(set_attr "type" "ghost")])
5270 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
5271 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5272 (define_insn_and_split "loadgp_rtp_<mode>"
5273   [(set (match_operand:P 0 "register_operand" "=d")
5274         (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5275                    (match_operand:P 2 "symbol_ref_operand")]
5276                   UNSPEC_LOADGP))]
5277   "mips_current_loadgp_style () == LOADGP_RTP"
5278   { return mips_must_initialize_gp_p () ? "#" : ""; }
5279   "&& mips_must_initialize_gp_p ()"
5280   [(set (match_dup 0) (high:P (match_dup 3)))
5281    (set (match_dup 0) (unspec:P [(match_dup 0)
5282                                  (match_dup 3)] UNSPEC_LOAD_GOT))
5283    (set (match_dup 0) (unspec:P [(match_dup 0)
5284                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
5286   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5287   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5289   [(set_attr "type" "ghost")])
5291 ;; Initialize the global pointer for MIPS16 code.  Operand 0 is the
5292 ;; global pointer and operand 1 is the MIPS16 register that holds
5293 ;; the required value.
5294 (define_insn_and_split "copygp_mips16_<mode>"
5295   [(set (match_operand:P 0 "register_operand" "=y")
5296         (unspec:P [(match_operand:P 1 "register_operand" "d")]
5297                   UNSPEC_COPYGP))]
5298   "TARGET_MIPS16"
5299   { return mips_must_initialize_gp_p () ? "#" : ""; }
5300   "&& mips_must_initialize_gp_p ()"
5301   [(set (match_dup 0) (match_dup 1))]
5302   ""
5303   [(set_attr "type" "ghost")])
5305 ;; A placeholder for where the cprestore instruction should go,
5306 ;; if we decide we need one.  Operand 0 and operand 1 are as for
5307 ;; "cprestore".  Operand 2 is a register that holds the gp value.
5309 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5310 ;; otherwise any register that holds the correct value will do.
5311 (define_insn_and_split "potential_cprestore_<mode>"
5312   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5313         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5314                    (match_operand:P 2 "register_operand" "d,d")]
5315                   UNSPEC_POTENTIAL_CPRESTORE))
5316    (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5317   "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5318   { return mips_must_initialize_gp_p () ? "#" : ""; }
5319   "mips_must_initialize_gp_p ()"
5320   [(const_int 0)]
5322   mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5323                                   operands[2], operands[3]);
5324   DONE;
5326   [(set_attr "type" "ghost")])
5328 ;; Emit a .cprestore directive, which normally expands to a single store
5329 ;; instruction.  Operand 0 is a (possibly illegitimate) sp-based MEM
5330 ;; for the cprestore slot.  Operand 1 is the offset of the slot from
5331 ;; the stack pointer.  (This is redundant with operand 0, but it makes
5332 ;; things a little simpler.)
5333 (define_insn "cprestore_<mode>"
5334   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5335         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5336                    (reg:P 28)]
5337                   UNSPEC_CPRESTORE))]
5338   "TARGET_CPRESTORE_DIRECTIVE"
5340   if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5341     return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5342   else
5343     return ".cprestore\t%1";
5345   [(set_attr "type" "store")
5346    (set_attr "insn_count" "1,3")])
5348 (define_insn "use_cprestore_<mode>"
5349   [(set (reg:P CPRESTORE_SLOT_REGNUM)
5350         (match_operand:P 0 "cprestore_load_slot_operand"))]
5351   ""
5352   ""
5353   [(set_attr "type" "ghost")])
5355 ;; Expand in-line code to clear the instruction cache between operand[0] and
5356 ;; operand[1].
5357 (define_expand "clear_cache"
5358   [(match_operand 0 "pmode_register_operand")
5359    (match_operand 1 "pmode_register_operand")]
5360   ""
5361   "
5363   if (TARGET_SYNCI)
5364     {
5365       mips_expand_synci_loop (operands[0], operands[1]);
5366       emit_insn (gen_sync ());
5367       emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5368     }
5369   else if (mips_cache_flush_func && mips_cache_flush_func[0])
5370     {
5371       rtx len = gen_reg_rtx (Pmode);
5372       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5373       MIPS_ICACHE_SYNC (operands[0], len);
5374     }
5375   DONE;
5378 (define_insn "sync"
5379   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5380   "GENERATE_SYNC"
5381   { return mips_output_sync (); })
5383 (define_insn "synci"
5384   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5385                     UNSPEC_SYNCI)]
5386   "TARGET_SYNCI"
5387   "synci\t0(%0)")
5389 (define_insn "rdhwr_synci_step_<mode>"
5390   [(set (match_operand:P 0 "register_operand" "=d")
5391         (unspec_volatile [(const_int 1)]
5392         UNSPEC_RDHWR))]
5393   "ISA_HAS_SYNCI"
5394   "rdhwr\t%0,$1")
5396 (define_insn "clear_hazard_<mode>"
5397   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5398    (clobber (reg:P RETURN_ADDR_REGNUM))]
5399   "ISA_HAS_SYNCI"
5401   return "%(%<bal\t1f\n"
5402          "\tnop\n"
5403          "1:\t<d>addiu\t$31,$31,12\n"
5404          "\tjr.hb\t$31\n"
5405          "\tnop%>%)";
5407   [(set_attr "insn_count" "5")])
5409 ;; Cache operations for R4000-style caches.
5410 (define_insn "mips_cache"
5411   [(set (mem:BLK (scratch))
5412         (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5413                      (match_operand:QI 1 "address_operand" "ZD")]
5414                     UNSPEC_MIPS_CACHE))]
5415   "ISA_HAS_CACHE"
5416   "cache\t%X0,%a1")
5418 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5419 ;; operation.  We keep the pattern distinct so that we can identify
5420 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5421 ;; the operation is never inserted into a delay slot.
5422 (define_insn "r10k_cache_barrier"
5423   [(set (mem:BLK (scratch))
5424         (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5425   "ISA_HAS_CACHE"
5426   "cache\t0x14,0(%$)"
5427   [(set_attr "can_delay" "no")])
5429 ;; Block moves, see mips.c for more details.
5430 ;; Argument 0 is the destination
5431 ;; Argument 1 is the source
5432 ;; Argument 2 is the length
5433 ;; Argument 3 is the alignment
5435 (define_expand "movmemsi"
5436   [(parallel [(set (match_operand:BLK 0 "general_operand")
5437                    (match_operand:BLK 1 "general_operand"))
5438               (use (match_operand:SI 2 ""))
5439               (use (match_operand:SI 3 "const_int_operand"))])]
5440   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5442   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5443     DONE;
5444   else
5445     FAIL;
5449 ;;  ....................
5451 ;;      SHIFTS
5453 ;;  ....................
5455 (define_expand "<optab><mode>3"
5456   [(set (match_operand:GPR 0 "register_operand")
5457         (any_shift:GPR (match_operand:GPR 1 "register_operand")
5458                        (match_operand:SI 2 "arith_operand")))]
5459   ""
5461   /* On the mips16, a shift of more than 8 is a four byte instruction,
5462      so, for a shift between 8 and 16, it is just as fast to do two
5463      shifts of 8 or less.  If there is a lot of shifting going on, we
5464      may win in CSE.  Otherwise combine will put the shifts back
5465      together again.  This can be called by mips_function_arg, so we must
5466      be careful not to allocate a new register if we've reached the
5467      reload pass.  */
5468   if (TARGET_MIPS16
5469       && optimize
5470       && CONST_INT_P (operands[2])
5471       && INTVAL (operands[2]) > 8
5472       && INTVAL (operands[2]) <= 16
5473       && !reload_in_progress
5474       && !reload_completed)
5475     {
5476       rtx temp = gen_reg_rtx (<MODE>mode);
5478       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5479       emit_insn (gen_<optab><mode>3 (operands[0], temp,
5480                                      GEN_INT (INTVAL (operands[2]) - 8)));
5481       DONE;
5482     }
5485 (define_insn "*<optab><mode>3"
5486   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5487         (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5488                        (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5489   "!TARGET_MIPS16"
5491   if (CONST_INT_P (operands[2]))
5492     operands[2] = GEN_INT (INTVAL (operands[2])
5493                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5495   return "<d><insn>\t%0,%1,%2";
5497   [(set_attr "type" "shift")
5498    (set_attr "compression" "<shift_compression>,none")
5499    (set_attr "mode" "<MODE>")])
5501 (define_insn "*<optab>si3_extend"
5502   [(set (match_operand:DI 0 "register_operand" "=d")
5503         (sign_extend:DI
5504            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5505                          (match_operand:SI 2 "arith_operand" "dI"))))]
5506   "TARGET_64BIT && !TARGET_MIPS16"
5508   if (CONST_INT_P (operands[2]))
5509     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5511   return "<insn>\t%0,%1,%2";
5513   [(set_attr "type" "shift")
5514    (set_attr "mode" "SI")])
5516 (define_insn "*<optab>si3_mips16"
5517   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5518         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5519                       (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5520   "TARGET_MIPS16"
5522   if (which_alternative == 0)
5523     return "<insn>\t%0,%2";
5525   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5526   return "<insn>\t%0,%1,%2";
5528   [(set_attr "type" "shift")
5529    (set_attr "mode" "SI")
5530    (set_attr "extended_mips16" "no,no,yes")])
5532 (define_insn "<GPR:d>lsa"
5533  [(set (match_operand:GPR 0 "register_operand" "=d")
5534        (plus:GPR (mult:GPR (match_operand:GPR 1 "register_operand" "d")
5535                            (match_operand 2 "const_immlsa_operand" ""))
5536                 (match_operand:GPR 3 "register_operand" "d")))]
5537  "ISA_HAS_<GPR:D>LSA"
5538  "<GPR:d>lsa\t%0,%1,%3,%y2"
5539  [(set_attr "type" "arith")
5540   (set_attr "mode" "<GPR:MODE>")])
5542 ;; We need separate DImode MIPS16 patterns because of the irregularity
5543 ;; of right shifts.
5544 (define_insn "*ashldi3_mips16"
5545   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5546         (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5547                    (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5548   "TARGET_64BIT && TARGET_MIPS16"
5550   if (which_alternative == 0)
5551     return "dsll\t%0,%2";
5553   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5554   return "dsll\t%0,%1,%2";
5556   [(set_attr "type" "shift")
5557    (set_attr "mode" "DI")
5558    (set_attr "extended_mips16" "no,no,yes")])
5560 (define_insn "*ashrdi3_mips16"
5561   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5562         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5563                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5564   "TARGET_64BIT && TARGET_MIPS16"
5566   if (CONST_INT_P (operands[2]))
5567     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5569   return "dsra\t%0,%2";
5571   [(set_attr "type" "shift")
5572    (set_attr "mode" "DI")
5573    (set_attr "extended_mips16" "no,no,yes")])
5575 (define_insn "*lshrdi3_mips16"
5576   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5577         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5578                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5579   "TARGET_64BIT && TARGET_MIPS16"
5581   if (CONST_INT_P (operands[2]))
5582     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5584   return "dsrl\t%0,%2";
5586   [(set_attr "type" "shift")
5587    (set_attr "mode" "DI")
5588    (set_attr "extended_mips16" "no,no,yes")])
5590 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5592 (define_split
5593   [(set (match_operand:GPR 0 "d_operand")
5594         (any_shift:GPR (match_operand:GPR 1 "d_operand")
5595                        (match_operand:GPR 2 "const_int_operand")))]
5596   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5597    && INTVAL (operands[2]) > 8
5598    && INTVAL (operands[2]) <= 16"
5599   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5600    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5601   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5603 ;; If we load a byte on the mips16 as a bitfield, the resulting
5604 ;; sequence of instructions is too complicated for combine, because it
5605 ;; involves four instructions: a load, a shift, a constant load into a
5606 ;; register, and an and (the key problem here is that the mips16 does
5607 ;; not have and immediate).  We recognize a shift of a load in order
5608 ;; to make it simple enough for combine to understand.
5610 ;; The instruction count here is the worst case.
5611 (define_insn_and_split ""
5612   [(set (match_operand:SI 0 "register_operand" "=d")
5613         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5614                      (match_operand:SI 2 "immediate_operand" "I")))]
5615   "TARGET_MIPS16"
5616   "#"
5617   ""
5618   [(set (match_dup 0) (match_dup 1))
5619    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5620   ""
5621   [(set_attr "type"     "load")
5622    (set_attr "mode"     "SI")
5623    (set (attr "insn_count")
5624         (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5626 (define_insn "rotr<mode>3"
5627   [(set (match_operand:GPR 0 "register_operand" "=d")
5628         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5629                       (match_operand:SI 2 "arith_operand" "dI")))]
5630   "ISA_HAS_ROR"
5632   if (CONST_INT_P (operands[2]))
5633     gcc_assert (INTVAL (operands[2]) >= 0
5634                 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5636   return "<d>ror\t%0,%1,%2";
5638   [(set_attr "type" "shift")
5639    (set_attr "mode" "<MODE>")])
5641 (define_insn "bswaphi2"
5642   [(set (match_operand:HI 0 "register_operand" "=d")
5643         (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5644   "ISA_HAS_WSBH"
5645   "wsbh\t%0,%1"
5646   [(set_attr "type" "shift")])
5648 (define_insn_and_split "bswapsi2"
5649   [(set (match_operand:SI 0 "register_operand" "=d")
5650         (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5651   "ISA_HAS_WSBH && ISA_HAS_ROR"
5652   "#"
5653   ""
5654   [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5655    (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5656   ""
5657   [(set_attr "insn_count" "2")])
5659 (define_insn_and_split "bswapdi2"
5660   [(set (match_operand:DI 0 "register_operand" "=d")
5661         (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5662   "TARGET_64BIT && ISA_HAS_WSBH"
5663   "#"
5664   ""
5665   [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5666    (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5667   ""
5668   [(set_attr "insn_count" "2")])
5670 (define_insn "wsbh"
5671   [(set (match_operand:SI 0 "register_operand" "=d")
5672         (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5673   "ISA_HAS_WSBH"
5674   "wsbh\t%0,%1"
5675   [(set_attr "type" "shift")])
5677 (define_insn "dsbh"
5678   [(set (match_operand:DI 0 "register_operand" "=d")
5679         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5680   "TARGET_64BIT && ISA_HAS_WSBH"
5681   "dsbh\t%0,%1"
5682   [(set_attr "type" "shift")])
5684 (define_insn "dshd"
5685   [(set (match_operand:DI 0 "register_operand" "=d")
5686         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5687   "TARGET_64BIT && ISA_HAS_WSBH"
5688   "dshd\t%0,%1"
5689   [(set_attr "type" "shift")])
5692 ;;  ....................
5694 ;;      CONDITIONAL BRANCHES
5696 ;;  ....................
5698 ;; Conditional branches on floating-point equality tests.
5700 (define_insn "*branch_fp_<mode>"
5701   [(set (pc)
5702         (if_then_else
5703          (match_operator 1 "equality_operator"
5704                          [(match_operand:FPCC 2 "register_operand" "<reg>")
5705                           (const_int 0)])
5706          (label_ref (match_operand 0 "" ""))
5707          (pc)))]
5708   "TARGET_HARD_FLOAT"
5710   return mips_output_conditional_branch (insn, operands,
5711                                          MIPS_BRANCH ("b%F1", "%Z2%0"),
5712                                          MIPS_BRANCH ("b%W1", "%Z2%0"));
5714   [(set_attr "type" "branch")])
5716 (define_insn "*branch_fp_inverted_<mode>"
5717   [(set (pc)
5718         (if_then_else
5719          (match_operator 1 "equality_operator"
5720                          [(match_operand:FPCC 2 "register_operand" "<reg>")
5721                           (const_int 0)])
5722          (pc)
5723          (label_ref (match_operand 0 "" ""))))]
5724   "TARGET_HARD_FLOAT"
5726   return mips_output_conditional_branch (insn, operands,
5727                                          MIPS_BRANCH ("b%W1", "%Z2%0"),
5728                                          MIPS_BRANCH ("b%F1", "%Z2%0"));
5730   [(set_attr "type" "branch")])
5732 ;; Conditional branches on ordered comparisons with zero.
5734 (define_insn "*branch_order<mode>"
5735   [(set (pc)
5736         (if_then_else
5737          (match_operator 1 "order_operator"
5738                          [(match_operand:GPR 2 "register_operand" "d")
5739                           (const_int 0)])
5740          (label_ref (match_operand 0 "" ""))
5741          (pc)))]
5742   "!TARGET_MIPS16"
5743   { return mips_output_order_conditional_branch (insn, operands, false); }
5744   [(set_attr "type" "branch")])
5746 (define_insn "*branch_order<mode>_inverted"
5747   [(set (pc)
5748         (if_then_else
5749          (match_operator 1 "order_operator"
5750                          [(match_operand:GPR 2 "register_operand" "d")
5751                           (const_int 0)])
5752          (pc)
5753          (label_ref (match_operand 0 "" ""))))]
5754   "!TARGET_MIPS16"
5755   { return mips_output_order_conditional_branch (insn, operands, true); }
5756   [(set_attr "type" "branch")])
5758 ;; Conditional branch on equality comparison.
5760 (define_insn "*branch_equality<mode>"
5761   [(set (pc)
5762         (if_then_else
5763          (match_operator 1 "equality_operator"
5764                          [(match_operand:GPR 2 "register_operand" "d")
5765                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5766          (label_ref (match_operand 0 "" ""))
5767          (pc)))]
5768   "!TARGET_MIPS16"
5770   /* For a simple BNEZ or BEQZ microMIPS branch.  */
5771   if (TARGET_MICROMIPS
5772       && operands[3] == const0_rtx
5773       && get_attr_length (insn) <= 8)
5774     return mips_output_conditional_branch (insn, operands,
5775                                            "%*b%C1z%:\t%2,%0",
5776                                            "%*b%N1z%:\t%2,%0");
5778   return mips_output_conditional_branch (insn, operands,
5779                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5780                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5782   [(set_attr "type" "branch")])
5784 (define_insn "*branch_equality<mode>_inverted"
5785   [(set (pc)
5786         (if_then_else
5787          (match_operator 1 "equality_operator"
5788                          [(match_operand:GPR 2 "register_operand" "d")
5789                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5790          (pc)
5791          (label_ref (match_operand 0 "" ""))))]
5792   "!TARGET_MIPS16"
5794   /* For a simple BNEZ or BEQZ microMIPS branch.  */
5795   if (TARGET_MICROMIPS
5796       && operands[3] == const0_rtx
5797       && get_attr_length (insn) <= 8)
5798     return mips_output_conditional_branch (insn, operands,
5799                                            "%*b%N0z%:\t%2,%1",
5800                                            "%*b%C0z%:\t%2,%1");
5802   return mips_output_conditional_branch (insn, operands,
5803                                          MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5804                                          MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5806   [(set_attr "type" "branch")])
5808 ;; MIPS16 branches
5810 (define_insn "*branch_equality<mode>_mips16"
5811   [(set (pc)
5812         (if_then_else
5813          (match_operator 1 "equality_operator"
5814                          [(match_operand:GPR 2 "register_operand" "d,t")
5815                           (const_int 0)])
5816          (label_ref (match_operand 0 "" ""))
5817          (pc)))]
5818   "TARGET_MIPS16"
5819   "@
5820    b%C1z\t%2,%0
5821    bt%C1z\t%0"
5822   [(set_attr "type" "branch")])
5824 (define_insn "*branch_equality<mode>_mips16_inverted"
5825   [(set (pc)
5826         (if_then_else
5827          (match_operator 1 "equality_operator"
5828                          [(match_operand:GPR 2 "register_operand" "d,t")
5829                           (const_int 0)])
5830          (pc)
5831          (label_ref (match_operand 0 "" ""))))]
5832   "TARGET_MIPS16"
5833   "@
5834    b%N1z\t%2,%0
5835    bt%N1z\t%0"
5836   [(set_attr "type" "branch")])
5838 (define_expand "cbranch<mode>4"
5839   [(set (pc)
5840         (if_then_else (match_operator 0 "comparison_operator"
5841                        [(match_operand:GPR 1 "register_operand")
5842                         (match_operand:GPR 2 "nonmemory_operand")])
5843                       (label_ref (match_operand 3 ""))
5844                       (pc)))]
5845   ""
5847   mips_expand_conditional_branch (operands);
5848   DONE;
5851 (define_expand "cbranch<mode>4"
5852   [(set (pc)
5853         (if_then_else (match_operator 0 "comparison_operator"
5854                        [(match_operand:SCALARF 1 "register_operand")
5855                         (match_operand:SCALARF 2 "register_operand")])
5856                       (label_ref (match_operand 3 ""))
5857                       (pc)))]
5858   ""
5860   mips_expand_conditional_branch (operands);
5861   DONE;
5864 ;; Used to implement built-in functions.
5865 (define_expand "condjump"
5866   [(set (pc)
5867         (if_then_else (match_operand 0)
5868                       (label_ref (match_operand 1))
5869                       (pc)))])
5871 ;; Branch if bit is set/clear.
5873 (define_insn "*branch_bit<bbv><mode>"
5874   [(set (pc)
5875         (if_then_else
5876          (equality_op (zero_extract:GPR
5877                        (match_operand:GPR 1 "register_operand" "d")
5878                        (const_int 1)
5879                        (match_operand 2 "const_int_operand" ""))
5880                       (const_int 0))
5881          (label_ref (match_operand 0 ""))
5882          (pc)))]
5883   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5885   return
5886     mips_output_conditional_branch (insn, operands,
5887                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5888                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5890   [(set_attr "type"          "branch")
5891    (set_attr "branch_likely" "no")])
5893 (define_insn "*branch_bit<bbv><mode>_inverted"
5894   [(set (pc)
5895         (if_then_else
5896          (equality_op (zero_extract:GPR
5897                        (match_operand:GPR 1 "register_operand" "d")
5898                        (const_int 1)
5899                        (match_operand 2 "const_int_operand" ""))
5900                       (const_int 0))
5901          (pc)
5902          (label_ref (match_operand 0 ""))))]
5903   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5905   return
5906     mips_output_conditional_branch (insn, operands,
5907                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5908                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5910   [(set_attr "type"          "branch")
5911    (set_attr "branch_likely" "no")])
5914 ;;  ....................
5916 ;;      SETTING A REGISTER FROM A COMPARISON
5918 ;;  ....................
5920 ;; Destination is always set in SI mode.
5922 (define_expand "cstore<mode>4"
5923   [(set (match_operand:SI 0 "register_operand")
5924         (match_operator:SI 1 "mips_cstore_operator"
5925          [(match_operand:GPR 2 "register_operand")
5926           (match_operand:GPR 3 "nonmemory_operand")]))]
5927   ""
5929   mips_expand_scc (operands);
5930   DONE;
5933 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5934   [(set (match_operand:GPR2 0 "register_operand" "=d")
5935         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5936                  (const_int 0)))]
5937   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5938   "sltu\t%0,%1,1"
5939   [(set_attr "type" "slt")
5940    (set_attr "mode" "<GPR:MODE>")])
5942 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5943   [(set (match_operand:GPR2 0 "register_operand" "=t")
5944         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5945                  (const_int 0)))]
5946   "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5947   "sltu\t%1,1"
5948   [(set_attr "type" "slt")
5949    (set_attr "mode" "<GPR:MODE>")])
5951 ;; Generate sltiu unless using seq results in better code.
5952 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5953   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5954         (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5955                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5956   "ISA_HAS_SEQ_SNE"
5957   "@
5958    seq\t%0,%1,%2
5959    sltiu\t%0,%1,1
5960    seqi\t%0,%1,%2"
5961   [(set_attr "type" "slt")
5962    (set_attr "mode" "<GPR:MODE>")])
5964 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5965   [(set (match_operand:GPR2 0 "register_operand" "=d")
5966         (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5967                  (const_int 0)))]
5968   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5969   "sltu\t%0,%.,%1"
5970   [(set_attr "type" "slt")
5971    (set_attr "mode" "<GPR:MODE>")])
5973 ;; Generate sltu unless using sne results in better code.
5974 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5975   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5976         (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5977                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5978   "ISA_HAS_SEQ_SNE"
5979   "@
5980    sne\t%0,%1,%2
5981    sltu\t%0,%.,%1
5982    snei\t%0,%1,%2"
5983   [(set_attr "type" "slt")
5984    (set_attr "mode" "<GPR:MODE>")])
5986 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5987   [(set (match_operand:GPR2 0 "register_operand" "=d")
5988         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5989                      (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5990   "!TARGET_MIPS16"
5991   "slt<u>\t%0,%z2,%1"
5992   [(set_attr "type" "slt")
5993    (set_attr "mode" "<GPR:MODE>")])
5995 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5996   [(set (match_operand:GPR2 0 "register_operand" "=t")
5997         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5998                      (match_operand:GPR 2 "register_operand" "d")))]
5999   "TARGET_MIPS16"
6000   "slt<u>\t%2,%1"
6001   [(set_attr "type" "slt")
6002    (set_attr "mode" "<GPR:MODE>")])
6004 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6005   [(set (match_operand:GPR2 0 "register_operand" "=d")
6006         (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6007                      (const_int 1)))]
6008   "!TARGET_MIPS16"
6009   "slt<u>\t%0,%.,%1"
6010   [(set_attr "type" "slt")
6011    (set_attr "mode" "<GPR:MODE>")])
6013 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6014   [(set (match_operand:GPR2 0 "register_operand" "=d")
6015         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6016                      (match_operand:GPR 2 "arith_operand" "dI")))]
6017   "!TARGET_MIPS16"
6018   "slt<u>\t%0,%1,%2"
6019   [(set_attr "type" "slt")
6020    (set_attr "mode" "<GPR:MODE>")])
6022 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6023   [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6024         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6025                      (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6026   "TARGET_MIPS16"
6027   "slt<u>\t%1,%2"
6028   [(set_attr "type" "slt")
6029    (set_attr "mode" "<GPR:MODE>")
6030    (set_attr "extended_mips16" "no,no,yes")])
6032 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6033   [(set (match_operand:GPR2 0 "register_operand" "=d")
6034         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6035                      (match_operand:GPR 2 "sle_operand" "")))]
6036   "!TARGET_MIPS16"
6038   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6039   return "slt<u>\t%0,%1,%2";
6041   [(set_attr "type" "slt")
6042    (set_attr "mode" "<GPR:MODE>")])
6044 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6045   [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6046         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6047                      (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6048   "TARGET_MIPS16"
6050   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6051   return "slt<u>\t%1,%2";
6053   [(set_attr "type" "slt")
6054    (set_attr "mode" "<GPR:MODE>")
6055    (set_attr "extended_mips16" "no,yes")])
6058 ;;  ....................
6060 ;;      FLOATING POINT COMPARISONS
6062 ;;  ....................
6064 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6065   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6066         (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6067                     (match_operand:SCALARF 2 "register_operand" "f")))]
6068   ""
6069   "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6070   [(set_attr "type" "fcmp")
6071    (set_attr "mode" "FPSW")])
6073 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6074   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6075         (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6076                             (match_operand:SCALARF 2 "register_operand" "f")))]
6077   ""
6078   "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6079   [(set_attr "type" "fcmp")
6080    (set_attr "mode" "FPSW")])
6083 ;;  ....................
6085 ;;      UNCONDITIONAL BRANCHES
6087 ;;  ....................
6089 ;; Unconditional branches.
6091 (define_expand "jump"
6092   [(set (pc)
6093         (label_ref (match_operand 0)))])
6095 (define_insn "*jump_absolute"
6096   [(set (pc)
6097         (label_ref (match_operand 0)))]
6098   "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6100   if (get_attr_length (insn) <= 8)
6101     return "%*b\t%l0%/";
6102   else
6103     return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6105   [(set_attr "type" "branch")])
6107 (define_insn "*jump_pic"
6108   [(set (pc)
6109         (label_ref (match_operand 0)))]
6110   "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6112   if (get_attr_length (insn) <= 8)
6113     return "%*b\t%l0%/";
6114   else
6115     {
6116       mips_output_load_label (operands[0]);
6117       return "%*jr\t%@%/%]";
6118     }
6120   [(set_attr "type" "branch")])
6122 ;; We need a different insn for the mips16, because a mips16 branch
6123 ;; does not have a delay slot.
6125 (define_insn "*jump_mips16"
6126   [(set (pc)
6127         (label_ref (match_operand 0 "" "")))]
6128   "TARGET_MIPS16"
6129   "b\t%l0"
6130   [(set_attr "type" "branch")
6131    (set (attr "length")
6132         ;; This calculation is like the normal branch one, but the
6133         ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6134         ;; than [-0x100, 0xfe].  This translates to a range of:
6135         ;;
6136         ;;    [-(0x800 - sizeof (branch)), 0x7fe]
6137         ;; == [-0x7fe, 0x7fe]
6138         ;;
6139         ;; from the shorten_branches reference address.  Long-branch
6140         ;; sequences will replace this one, so the minimum length
6141         ;; is one instruction shorter than for conditional branches.
6142         (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6143                     (le (minus (pc) (match_dup 0)) (const_int 2046)))
6144                (const_int 2)
6145                (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6146                     (le (minus (pc) (match_dup 0)) (const_int 65532)))
6147                (const_int 4)
6148                (and (match_test "TARGET_ABICALLS")
6149                     (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6150                (const_int 18)
6151                (match_test "Pmode == SImode")
6152                (const_int 14)
6153                ] (const_int 22)))])
6155 (define_expand "indirect_jump"
6156   [(set (pc) (match_operand 0 "register_operand"))]
6157   ""
6159   operands[0] = force_reg (Pmode, operands[0]);
6160   emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6161   DONE;
6164 (define_insn "indirect_jump_<mode>"
6165   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6166   ""
6168   if (TARGET_MICROMIPS)
6169     return "%*jr%:\t%0";
6170   else
6171     return "%*j\t%0%/";
6173   [(set_attr "type" "jump")
6174    (set_attr "mode" "none")])
6176 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6177 ;; sequences.  Having a dedicated pattern is more convenient than
6178 ;; creating a SEQUENCE for this special case.
6179 (define_insn "indirect_jump_and_restore_<mode>"
6180   [(set (pc) (match_operand:P 1 "register_operand" "d"))
6181    (set (match_operand:P 0 "register_operand" "=d")
6182         (match_operand:P 2 "register_operand" "y"))]
6183   ""
6184   "%(%<jr\t%1\;move\t%0,%2%>%)"
6185   [(set_attr "type" "multi")
6186    (set_attr "extended_mips16" "yes")])
6188 (define_expand "tablejump"
6189   [(set (pc)
6190         (match_operand 0 "register_operand"))
6191    (use (label_ref (match_operand 1 "")))]
6192   "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6194   if (TARGET_GPWORD)
6195     operands[0] = expand_binop (Pmode, add_optab, operands[0],
6196                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6197   else if (TARGET_RTP_PIC)
6198     {
6199       /* When generating RTP PIC, we use case table entries that are relative
6200          to the start of the function.  Add the function's address to the
6201          value we loaded.  */
6202       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6203       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6204                                   start, 0, 0, OPTAB_WIDEN);
6205     }
6207   emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6208   DONE;
6211 (define_insn "tablejump_<mode>"
6212   [(set (pc)
6213         (match_operand:P 0 "register_operand" "d"))
6214    (use (label_ref (match_operand 1 "" "")))]
6215   ""
6217   if (TARGET_MICROMIPS)
6218     return "%*jr%:\t%0";
6219   else
6220     return "%*j\t%0%/";
6222   [(set_attr "type" "jump")
6223    (set_attr "mode" "none")])
6225 ;; For MIPS16, we don't know whether a given jump table will use short or
6226 ;; word-sized offsets until late in compilation, when we are able to determine
6227 ;; the sizes of the insns which comprise the containing function.  This
6228 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6229 ;; the latter tries to calculate the index of the offset to jump through early
6230 ;; in compilation, i.e. at expand time, when nothing is known about the
6231 ;; eventual function layout.
6233 (define_expand "casesi"
6234   [(match_operand:SI 0 "register_operand" "")   ; index to jump on
6235    (match_operand:SI 1 "const_int_operand" "")  ; lower bound
6236    (match_operand:SI 2 "const_int_operand" "")  ; total range
6237    (match_operand 3 "" "")                      ; table label
6238    (match_operand 4 "" "")]                     ; out of range label
6239   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6241   if (operands[1] != const0_rtx)
6242     {
6243       rtx reg = gen_reg_rtx (SImode);
6244       rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6245       
6246       if (!arith_operand (offset, SImode))
6247         offset = force_reg (SImode, offset);
6248       
6249       emit_insn (gen_addsi3 (reg, operands[0], offset));
6250       operands[0] = reg;
6251     }
6253   if (!arith_operand (operands[0], SImode))
6254     operands[0] = force_reg (SImode, operands[0]);
6256   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6258   emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6259                               (operands[0], operands[2],
6260                                operands[3], operands[4])));
6262   DONE;
6265 (define_insn "casesi_internal_mips16_<mode>"
6266   [(set (pc)
6267      (if_then_else
6268        (leu (match_operand:SI 0 "register_operand" "d")
6269             (match_operand:SI 1 "arith_operand" "dI"))
6270        (unspec:P
6271         [(match_dup 0)
6272          (label_ref (match_operand 2 "" ""))]
6273         UNSPEC_CASESI_DISPATCH)
6274        (label_ref (match_operand 3 "" ""))))
6275    (clobber (match_scratch:P 4 "=d"))
6276    (clobber (match_scratch:P 5 "=d"))
6277    (clobber (reg:SI MIPS16_T_REGNUM))]
6278   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6280   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
6282   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6283   
6284   output_asm_insn ("sltu\t%0, %1", operands);
6285   output_asm_insn ("bteqz\t%3", operands);
6286   
6287   switch (GET_MODE (diff_vec))
6288     {
6289     case HImode:
6290       output_asm_insn ("sll\t%5, %0, 1", operands);
6291       output_asm_insn ("la\t%4, %2", operands);
6292       output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6293       output_asm_insn ("lh\t%5, 0(%5)", operands);
6294       break;
6295     
6296     case SImode:
6297       output_asm_insn ("sll\t%5, %0, 2", operands);
6298       output_asm_insn ("la\t%4, %2", operands);
6299       output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6300       output_asm_insn ("lw\t%5, 0(%5)", operands);
6301       break;
6303     default:
6304       gcc_unreachable ();
6305     }
6306   
6307   output_asm_insn ("addu\t%4, %4, %5", operands);
6308   
6309   return "j\t%4";
6311   [(set_attr "insn_count" "16")])
6313 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6314 ;; While it is possible to either pull it off the stack (in the
6315 ;; o32 case) or recalculate it given t9 and our target label,
6316 ;; it takes 3 or 4 insns to do so.
6318 (define_expand "builtin_setjmp_setup"
6319   [(use (match_operand 0 "register_operand"))]
6320   "TARGET_USE_GOT"
6322   rtx addr;
6324   addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6325   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6326   DONE;
6329 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
6330 ;; that older code did recalculate the gp from $25.  Continue to jump through
6331 ;; $25 for compatibility (we lose nothing by doing so).
6333 (define_expand "builtin_longjmp"
6334   [(use (match_operand 0 "register_operand"))]
6335   "TARGET_USE_GOT"
6337   /* The elements of the buffer are, in order:  */
6338   int W = GET_MODE_SIZE (Pmode);
6339   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6340   rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6341   rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6342   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6343   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6344   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6345      The target is bound to be using $28 as the global pointer
6346      but the current function might not be.  */
6347   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6349   /* This bit is similar to expand_builtin_longjmp except that it
6350      restores $gp as well.  */
6351   mips_emit_move (hard_frame_pointer_rtx, fp);
6352   mips_emit_move (pv, lab);
6353   emit_stack_restore (SAVE_NONLOCAL, stack);
6354   mips_emit_move (gp, gpv);
6355   emit_use (hard_frame_pointer_rtx);
6356   emit_use (stack_pointer_rtx);
6357   emit_use (gp);
6358   emit_indirect_jump (pv);
6359   DONE;
6363 ;;  ....................
6365 ;;      Function prologue/epilogue
6367 ;;  ....................
6370 (define_expand "prologue"
6371   [(const_int 1)]
6372   ""
6374   mips_expand_prologue ();
6375   DONE;
6378 ;; Block any insns from being moved before this point, since the
6379 ;; profiling call to mcount can use various registers that aren't
6380 ;; saved or used to pass arguments.
6382 (define_insn "blockage"
6383   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6384   ""
6385   ""
6386   [(set_attr "type" "ghost")
6387    (set_attr "mode" "none")])
6389 (define_insn "probe_stack_range_<P:mode>"
6390   [(set (match_operand:P 0 "register_operand" "=d")
6391         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6392                             (match_operand:P 2 "register_operand" "d")]
6393                             UNSPEC_PROBE_STACK_RANGE))]
6394   ""
6395  { return mips_output_probe_stack_range (operands[0], operands[2]); }
6396   [(set_attr "type" "unknown")
6397    (set_attr "can_delay" "no")
6398    (set_attr "mode" "<MODE>")])
6400 (define_expand "epilogue"
6401   [(const_int 2)]
6402   ""
6404   mips_expand_epilogue (false);
6405   DONE;
6408 (define_expand "sibcall_epilogue"
6409   [(const_int 2)]
6410   ""
6412   mips_expand_epilogue (true);
6413   DONE;
6416 ;; Trivial return.  Make it look like a normal return insn as that
6417 ;; allows jump optimizations to work better.
6419 (define_expand "return"
6420   [(simple_return)]
6421   "mips_can_use_return_insn ()"
6422   { mips_expand_before_return (); })
6424 (define_expand "simple_return"
6425   [(simple_return)]
6426   ""
6427   { mips_expand_before_return (); })
6429 (define_insn "*<optab>"
6430   [(any_return)]
6431   ""
6432   {
6433     if (TARGET_MICROMIPS)
6434       return "%*jr%:\t$31";
6435     else
6436       return "%*j\t$31%/";
6437   }
6438   [(set_attr "type"     "jump")
6439    (set_attr "mode"     "none")])
6441 ;; Normal return.
6443 (define_insn "<optab>_internal"
6444   [(any_return)
6445    (use (match_operand 0 "pmode_register_operand" ""))]
6446   ""
6448   if (TARGET_MICROMIPS)
6449     return "%*jr%:\t%0";
6450   else
6451     return "%*j\t%0%/";
6453   [(set_attr "type"     "jump")
6454    (set_attr "mode"     "none")])
6456 ;; Exception return.
6457 (define_insn "mips_eret"
6458   [(return)
6459    (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6460   ""
6461   "eret"
6462   [(set_attr "type"     "trap")
6463    (set_attr "mode"     "none")])
6465 ;; Debug exception return.
6466 (define_insn "mips_deret"
6467   [(return)
6468    (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6469   ""
6470   "deret"
6471   [(set_attr "type"     "trap")
6472    (set_attr "mode"     "none")])
6474 ;; Disable interrupts.
6475 (define_insn "mips_di"
6476   [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6477   ""
6478   "di"
6479   [(set_attr "type"     "trap")
6480    (set_attr "mode"     "none")])
6482 ;; Execution hazard barrier.
6483 (define_insn "mips_ehb"
6484   [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6485   ""
6486   "ehb"
6487   [(set_attr "type"     "trap")
6488    (set_attr "mode"     "none")])
6490 ;; Read GPR from previous shadow register set.
6491 (define_insn "mips_rdpgpr"
6492   [(set (match_operand:SI 0 "register_operand" "=d")
6493         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
6494                             UNSPEC_RDPGPR))]
6495   ""
6496   "rdpgpr\t%0,%1"
6497   [(set_attr "type"     "move")
6498    (set_attr "mode"     "SI")])
6500 ;; Move involving COP0 registers.
6501 (define_insn "cop0_move"
6502   [(set (match_operand:SI 0 "register_operand" "=B,d")
6503         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6504                             UNSPEC_COP0))]
6505   ""
6506 { return mips_output_move (operands[0], operands[1]); }
6507   [(set_attr "type"     "mtc,mfc")
6508    (set_attr "mode"     "SI")])
6510 ;; This is used in compiling the unwind routines.
6511 (define_expand "eh_return"
6512   [(use (match_operand 0 "general_operand"))]
6513   ""
6515   if (GET_MODE (operands[0]) != word_mode)
6516     operands[0] = convert_to_mode (word_mode, operands[0], 0);
6517   if (TARGET_64BIT)
6518     emit_insn (gen_eh_set_lr_di (operands[0]));
6519   else
6520     emit_insn (gen_eh_set_lr_si (operands[0]));
6521   DONE;
6524 ;; Clobber the return address on the stack.  We can't expand this
6525 ;; until we know where it will be put in the stack frame.
6527 (define_insn "eh_set_lr_si"
6528   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6529    (clobber (match_scratch:SI 1 "=&d"))]
6530   "! TARGET_64BIT"
6531   "#")
6533 (define_insn "eh_set_lr_di"
6534   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6535    (clobber (match_scratch:DI 1 "=&d"))]
6536   "TARGET_64BIT"
6537   "#")
6539 (define_split
6540   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6541    (clobber (match_scratch 1))]
6542   "reload_completed"
6543   [(const_int 0)]
6545   mips_set_return_address (operands[0], operands[1]);
6546   DONE;
6549 (define_expand "exception_receiver"
6550   [(const_int 0)]
6551   "TARGET_USE_GOT"
6553   /* See the comment above load_call<mode> for details.  */
6554   emit_insn (gen_set_got_version ());
6556   /* If we have a call-clobbered $gp, restore it from its save slot.  */
6557   if (HAVE_restore_gp_si)
6558     emit_insn (gen_restore_gp_si ());
6559   else if (HAVE_restore_gp_di)
6560     emit_insn (gen_restore_gp_di ());
6561   DONE;
6564 (define_expand "nonlocal_goto_receiver"
6565   [(const_int 0)]
6566   "TARGET_USE_GOT"
6568   /* See the comment above load_call<mode> for details.  */
6569   emit_insn (gen_set_got_version ());
6570   DONE;
6573 ;; Restore $gp from its .cprestore stack slot.  The instruction remains
6574 ;; volatile until all uses of $28 are exposed.
6575 (define_insn_and_split "restore_gp_<mode>"
6576   [(set (reg:P 28)
6577         (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6578    (clobber (match_scratch:P 0 "=&d"))]
6579   "TARGET_CALL_CLOBBERED_GP"
6580   "#"
6581   "&& epilogue_completed"
6582   [(const_int 0)]
6584   mips_restore_gp_from_cprestore_slot (operands[0]);
6585   DONE;
6587   [(set_attr "type" "ghost")])
6589 ;; Move between $gp and its register save slot.
6590 (define_insn_and_split "move_gp<mode>"
6591   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6592         (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6593                     UNSPEC_MOVE_GP))]
6594   ""
6595   { return mips_must_initialize_gp_p () ? "#" : ""; }
6596   "mips_must_initialize_gp_p ()"
6597   [(const_int 0)]
6599   mips_emit_move (operands[0], operands[1]);
6600   DONE;
6602   [(set_attr "type" "ghost")])
6605 ;;  ....................
6607 ;;      FUNCTION CALLS
6609 ;;  ....................
6611 ;; Instructions to load a call address from the GOT.  The address might
6612 ;; point to a function or to a lazy binding stub.  In the latter case,
6613 ;; the stub will use the dynamic linker to resolve the function, which
6614 ;; in turn will change the GOT entry to point to the function's real
6615 ;; address.
6617 ;; This means that every call, even pure and constant ones, can
6618 ;; potentially modify the GOT entry.  And once a stub has been called,
6619 ;; we must not call it again.
6621 ;; We represent this restriction using an imaginary, fixed, call-saved
6622 ;; register called GOT_VERSION_REGNUM.  The idea is to make the register
6623 ;; live throughout the function and to change its value after every
6624 ;; potential call site.  This stops any rtx value that uses the register
6625 ;; from being computed before an earlier call.  To do this, we:
6627 ;;    - Ensure that the register is live on entry to the function,
6628 ;;      so that it is never thought to be used uninitalized.
6630 ;;    - Ensure that the register is live on exit from the function,
6631 ;;      so that it is live throughout.
6633 ;;    - Make each call (lazily-bound or not) use the current value
6634 ;;      of GOT_VERSION_REGNUM, so that updates of the register are
6635 ;;      not moved across call boundaries.
6637 ;;    - Add "ghost" definitions of the register to the beginning of
6638 ;;      blocks reached by EH and ABNORMAL_CALL edges, because those
6639 ;;      edges may involve calls that normal paths don't.  (E.g. the
6640 ;;      unwinding code that handles a non-call exception may change
6641 ;;      lazily-bound GOT entries.)  We do this by making the
6642 ;;      exception_receiver and nonlocal_goto_receiver expanders emit
6643 ;;      a set_got_version instruction.
6645 ;;    - After each call (lazily-bound or not), use a "ghost"
6646 ;;      update_got_version instruction to change the register's value.
6647 ;;      This instruction mimics the _possible_ effect of the dynamic
6648 ;;      resolver during the call and it remains live even if the call
6649 ;;      itself becomes dead.
6651 ;;    - Leave GOT_VERSION_REGNUM out of all register classes.
6652 ;;      The register is therefore not a valid register_operand
6653 ;;      and cannot be moved to or from other registers.
6655 (define_insn "load_call<mode>"
6656   [(set (match_operand:P 0 "register_operand" "=d")
6657         (unspec:P [(match_operand:P 1 "register_operand" "d")
6658                    (match_operand:P 2 "immediate_operand" "")
6659                    (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6660   "TARGET_USE_GOT"
6661   "<load>\t%0,%R2(%1)"
6662   [(set_attr "got" "load")
6663    (set_attr "mode" "<MODE>")])
6665 (define_insn "set_got_version"
6666   [(set (reg:SI GOT_VERSION_REGNUM)
6667         (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6668   "TARGET_USE_GOT"
6669   ""
6670   [(set_attr "type" "ghost")])
6672 (define_insn "update_got_version"
6673   [(set (reg:SI GOT_VERSION_REGNUM)
6674         (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6675   "TARGET_USE_GOT"
6676   ""
6677   [(set_attr "type" "ghost")])
6679 ;; Sibling calls.  All these patterns use jump instructions.
6681 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6682 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
6683 ;; is defined in terms of call_insn_operand, the same is true of the
6684 ;; constraints.
6686 ;; When we use an indirect jump, we need a register that will be
6687 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
6688 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6689 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6690 ;; as well.
6692 (define_expand "sibcall"
6693   [(parallel [(call (match_operand 0 "")
6694                     (match_operand 1 ""))
6695               (use (match_operand 2 ""))        ;; next_arg_reg
6696               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6697   "TARGET_SIBCALLS"
6699   mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6700                     operands[1], operands[2], false);
6701   DONE;
6704 (define_insn "sibcall_internal"
6705   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6706          (match_operand 1 "" ""))]
6707   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6709   if (TARGET_MICROMIPS)
6710     return MICROMIPS_J ("j", operands, 0);
6711   else
6712     return MIPS_CALL ("j", operands, 0, 1);
6714   [(set_attr "jal" "indirect,direct")
6715    (set_attr "jal_macro" "no")])
6717 (define_expand "sibcall_value"
6718   [(parallel [(set (match_operand 0 "")
6719                    (call (match_operand 1 "")
6720                          (match_operand 2 "")))
6721               (use (match_operand 3 ""))])]             ;; next_arg_reg
6722   "TARGET_SIBCALLS"
6724   mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6725                     operands[2], operands[3], false);
6726   DONE;
6729 (define_insn "sibcall_value_internal"
6730   [(set (match_operand 0 "register_operand" "")
6731         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6732               (match_operand 2 "" "")))]
6733   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6735   if (TARGET_MICROMIPS)
6736     return MICROMIPS_J ("j", operands, 1);
6737   else
6738     return MIPS_CALL ("j", operands, 1, 2);
6740   [(set_attr "jal" "indirect,direct")
6741    (set_attr "jal_macro" "no")])
6743 (define_insn "sibcall_value_multiple_internal"
6744   [(set (match_operand 0 "register_operand" "")
6745         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6746               (match_operand 2 "" "")))
6747    (set (match_operand 3 "register_operand" "")
6748         (call (mem:SI (match_dup 1))
6749               (match_dup 2)))]
6750   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6752   if (TARGET_MICROMIPS)
6753     return MICROMIPS_J ("j", operands, 1);
6754   else
6755     return MIPS_CALL ("j", operands, 1, 2);
6757   [(set_attr "jal" "indirect,direct")
6758    (set_attr "jal_macro" "no")])
6760 (define_expand "call"
6761   [(parallel [(call (match_operand 0 "")
6762                     (match_operand 1 ""))
6763               (use (match_operand 2 ""))        ;; next_arg_reg
6764               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6765   ""
6767   mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6768                     operands[1], operands[2], false);
6769   DONE;
6772 ;; This instruction directly corresponds to an assembly-language "jal".
6773 ;; There are four cases:
6775 ;;    - -mno-abicalls:
6776 ;;        Both symbolic and register destinations are OK.  The pattern
6777 ;;        always expands to a single mips instruction.
6779 ;;    - -mabicalls/-mno-explicit-relocs:
6780 ;;        Again, both symbolic and register destinations are OK.
6781 ;;        The call is treated as a multi-instruction black box.
6783 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
6784 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
6785 ;;        instruction.
6787 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
6788 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
6789 ;;        "jalr $25" followed by an insn to reload $gp.
6791 ;; In the last case, we can generate the individual instructions with
6792 ;; a define_split.  There are several things to be wary of:
6794 ;;   - We can't expose the load of $gp before reload.  If we did,
6795 ;;     it might get removed as dead, but reload can introduce new
6796 ;;     uses of $gp by rematerializing constants.
6798 ;;   - We shouldn't restore $gp after calls that never return.
6799 ;;     It isn't valid to insert instructions between a noreturn
6800 ;;     call and the following barrier.
6802 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
6803 ;;     instruction preserves $gp and so have no effect on its liveness.
6804 ;;     But once we generate the separate insns, it becomes obvious that
6805 ;;     $gp is not live on entry to the call.
6807 (define_insn_and_split "call_internal"
6808   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6809          (match_operand 1 "" ""))
6810    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6811   ""
6812   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6813   "reload_completed && TARGET_SPLIT_CALLS"
6814   [(const_int 0)]
6816   mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6817   DONE;
6819   [(set_attr "jal" "indirect,direct")])
6821 (define_insn "call_split"
6822   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6823          (match_operand 1 "" ""))
6824    (clobber (reg:SI RETURN_ADDR_REGNUM))
6825    (clobber (reg:SI 28))]
6826   "TARGET_SPLIT_CALLS"
6827   { return MIPS_CALL ("jal", operands, 0, 1); }
6828   [(set_attr "jal" "indirect,direct")
6829    (set_attr "jal_macro" "no")])
6831 ;; A pattern for calls that must be made directly.  It is used for
6832 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6833 ;; stub; the linker relies on the call relocation type to detect when
6834 ;; such redirection is needed.
6835 (define_insn_and_split "call_internal_direct"
6836   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6837          (match_operand 1))
6838    (const_int 1)
6839    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6840   ""
6841   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6842   "reload_completed && TARGET_SPLIT_CALLS"
6843   [(const_int 0)]
6845   mips_split_call (curr_insn,
6846                    gen_call_direct_split (operands[0], operands[1]));
6847   DONE;
6849   [(set_attr "jal" "direct")])
6851 (define_insn "call_direct_split"
6852   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6853          (match_operand 1))
6854    (const_int 1)
6855    (clobber (reg:SI RETURN_ADDR_REGNUM))
6856    (clobber (reg:SI 28))]
6857   "TARGET_SPLIT_CALLS"
6858   { return MIPS_CALL ("jal", operands, 0, -1); }
6859   [(set_attr "jal" "direct")
6860    (set_attr "jal_macro" "no")])
6862 (define_expand "call_value"
6863   [(parallel [(set (match_operand 0 "")
6864                    (call (match_operand 1 "")
6865                          (match_operand 2 "")))
6866               (use (match_operand 3 ""))])]             ;; next_arg_reg
6867   ""
6869   mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6870                     operands[2], operands[3], false);
6871   DONE;
6874 ;; See comment for call_internal.
6875 (define_insn_and_split "call_value_internal"
6876   [(set (match_operand 0 "register_operand" "")
6877         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6878               (match_operand 2 "" "")))
6879    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6880   ""
6881   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6882   "reload_completed && TARGET_SPLIT_CALLS"
6883   [(const_int 0)]
6885   mips_split_call (curr_insn,
6886                    gen_call_value_split (operands[0], operands[1],
6887                                          operands[2]));
6888   DONE;
6890   [(set_attr "jal" "indirect,direct")])
6892 (define_insn "call_value_split"
6893   [(set (match_operand 0 "register_operand" "")
6894         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6895               (match_operand 2 "" "")))
6896    (clobber (reg:SI RETURN_ADDR_REGNUM))
6897    (clobber (reg:SI 28))]
6898   "TARGET_SPLIT_CALLS"
6899   { return MIPS_CALL ("jal", operands, 1, 2); }
6900   [(set_attr "jal" "indirect,direct")
6901    (set_attr "jal_macro" "no")])
6903 ;; See call_internal_direct.
6904 (define_insn_and_split "call_value_internal_direct"
6905   [(set (match_operand 0 "register_operand")
6906         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6907               (match_operand 2)))
6908    (const_int 1)
6909    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6910   ""
6911   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6912   "reload_completed && TARGET_SPLIT_CALLS"
6913   [(const_int 0)]
6915   mips_split_call (curr_insn,
6916                    gen_call_value_direct_split (operands[0], operands[1],
6917                                                 operands[2]));
6918   DONE;
6920   [(set_attr "jal" "direct")])
6922 (define_insn "call_value_direct_split"
6923   [(set (match_operand 0 "register_operand")
6924         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6925               (match_operand 2)))
6926    (const_int 1)
6927    (clobber (reg:SI RETURN_ADDR_REGNUM))
6928    (clobber (reg:SI 28))]
6929   "TARGET_SPLIT_CALLS"
6930   { return MIPS_CALL ("jal", operands, 1, -1); }
6931   [(set_attr "jal" "direct")
6932    (set_attr "jal_macro" "no")])
6934 ;; See comment for call_internal.
6935 (define_insn_and_split "call_value_multiple_internal"
6936   [(set (match_operand 0 "register_operand" "")
6937         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6938               (match_operand 2 "" "")))
6939    (set (match_operand 3 "register_operand" "")
6940         (call (mem:SI (match_dup 1))
6941               (match_dup 2)))
6942    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6943   ""
6944   { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6945   "reload_completed && TARGET_SPLIT_CALLS"
6946   [(const_int 0)]
6948   mips_split_call (curr_insn,
6949                    gen_call_value_multiple_split (operands[0], operands[1],
6950                                                   operands[2], operands[3]));
6951   DONE;
6953   [(set_attr "jal" "indirect,direct")])
6955 (define_insn "call_value_multiple_split"
6956   [(set (match_operand 0 "register_operand" "")
6957         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6958               (match_operand 2 "" "")))
6959    (set (match_operand 3 "register_operand" "")
6960         (call (mem:SI (match_dup 1))
6961               (match_dup 2)))
6962    (clobber (reg:SI RETURN_ADDR_REGNUM))
6963    (clobber (reg:SI 28))]
6964   "TARGET_SPLIT_CALLS"
6965   { return MIPS_CALL ("jal", operands, 1, 2); }
6966   [(set_attr "jal" "indirect,direct")
6967    (set_attr "jal_macro" "no")])
6969 ;; Call subroutine returning any type.
6971 (define_expand "untyped_call"
6972   [(parallel [(call (match_operand 0 "")
6973                     (const_int 0))
6974               (match_operand 1 "")
6975               (match_operand 2 "")])]
6976   ""
6978   int i;
6980   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6982   for (i = 0; i < XVECLEN (operands[2], 0); i++)
6983     {
6984       rtx set = XVECEXP (operands[2], 0, i);
6985       mips_emit_move (SET_DEST (set), SET_SRC (set));
6986     }
6988   emit_insn (gen_blockage ());
6989   DONE;
6993 ;;  ....................
6995 ;;      MISC.
6997 ;;  ....................
7001 (define_insn "prefetch"
7002   [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7003              (match_operand 1 "const_int_operand" "n")
7004              (match_operand 2 "const_int_operand" "n"))]
7005   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7007   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
7008     {
7009       /* Loongson 2[ef] and Loongson 3a use load to $0 for prefetching.  */
7010       if (TARGET_64BIT)
7011         return "ld\t$0,%a0";
7012       else
7013         return "lw\t$0,%a0";
7014     }
7015   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7016   return "pref\t%1,%a0";
7018   [(set_attr "type" "prefetch")])
7020 (define_insn "*prefetch_indexed_<mode>"
7021   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7022                      (match_operand:P 1 "register_operand" "d"))
7023              (match_operand 2 "const_int_operand" "n")
7024              (match_operand 3 "const_int_operand" "n"))]
7025   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7027   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7028   return "prefx\t%2,%1(%0)";
7030   [(set_attr "type" "prefetchx")])
7032 (define_insn "nop"
7033   [(const_int 0)]
7034   ""
7035   "%(nop%)"
7036   [(set_attr "type"     "nop")
7037    (set_attr "mode"     "none")])
7039 ;; Like nop, but commented out when outside a .set noreorder block.
7040 (define_insn "hazard_nop"
7041   [(const_int 1)]
7042   ""
7043   {
7044     if (mips_noreorder.nesting_level > 0)
7045       return "nop";
7046     else
7047       return "#nop";
7048   }
7049   [(set_attr "type"     "nop")])
7051 ;; MIPS4 Conditional move instructions.
7053 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7054   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7055         (if_then_else:GPR
7056          (match_operator 4 "equality_operator"
7057                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7058                  (const_int 0)])
7059          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7060          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7061   "ISA_HAS_CONDMOVE"
7062   "@
7063     mov%T4\t%0,%z2,%1
7064     mov%t4\t%0,%z3,%1"
7065   [(set_attr "type" "condmove")
7066    (set_attr "mode" "<GPR:MODE>")])
7068 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7069   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7070        (if_then_else:GPR
7071         (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7072         (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7073         (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7074   "ISA_HAS_CONDMOVE"
7075   "@
7076     movn\t%0,%z2,%1
7077     movz\t%0,%z3,%1"
7078   [(set_attr "type" "condmove")
7079    (set_attr "mode" "<GPR:MODE>")])
7081 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7082   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7083         (if_then_else:SCALARF
7084          (match_operator 4 "equality_operator"
7085                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7086                  (const_int 0)])
7087          (match_operand:SCALARF 2 "register_operand" "f,0")
7088          (match_operand:SCALARF 3 "register_operand" "0,f")))]
7089   "ISA_HAS_FP_CONDMOVE"
7090   "@
7091     mov%T4.<fmt>\t%0,%2,%1
7092     mov%t4.<fmt>\t%0,%3,%1"
7093   [(set_attr "type" "condmove")
7094    (set_attr "mode" "<SCALARF:MODE>")])
7096 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7097   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7098         (if_then_else:GPR
7099          (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7100                            (const_int 0))
7101          (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7102          (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7103   "ISA_HAS_SEL
7104    && (register_operand (operands[2], <GPR:MODE>mode)
7105        != register_operand (operands[3], <GPR:MODE>mode))"
7106   "@
7107    <sel>\t%0,%2,%1
7108    <selinv>\t%0,%3,%1"
7109   [(set_attr "type" "condmove")
7110    (set_attr "mode" "<GPR:MODE>")])
7112 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7113 ;; argument if the 1st is zero.  This means operand 2 and 3 are
7114 ;; inverted in the instruction.
7116 (define_insn "*sel<mode>"
7117   [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7118         (if_then_else:SCALARF
7119          (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7120                  (const_int 0))
7121          (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7122          (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7123   "ISA_HAS_SEL && ISA_HAS_CCF"
7124   "@
7125    sel.<fmt>\t%0,%3,%2
7126    seleqz.<fmt>\t%0,%3,%1
7127    selnez.<fmt>\t%0,%2,%1"
7128   [(set_attr "type" "condmove")
7129    (set_attr "mode" "<SCALARF:MODE>")])
7131 ;; These are the main define_expand's used to make conditional moves.
7133 (define_expand "mov<mode>cc"
7134   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7135    (set (match_operand:GPR 0 "register_operand")
7136         (if_then_else:GPR (match_dup 5)
7137                           (match_operand:GPR 2 "reg_or_0_operand")
7138                           (match_operand:GPR 3 "reg_or_0_operand")))]
7139   "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7141   if (!ISA_HAS_FP_CONDMOVE
7142       && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7143     FAIL;
7145   mips_expand_conditional_move (operands);
7146   DONE;
7149 (define_expand "mov<mode>cc"
7150   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7151    (set (match_operand:SCALARF 0 "register_operand")
7152         (if_then_else:SCALARF (match_dup 5)
7153                               (match_operand:SCALARF 2 "reg_or_0_operand")
7154                               (match_operand:SCALARF 3 "reg_or_0_operand")))]
7155   "ISA_HAS_FP_CONDMOVE
7156    || (ISA_HAS_SEL && ISA_HAS_CCF)"
7158   if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7159     FAIL;
7161   /* Workaround an LRA bug which means that tied operands in the sel.fmt
7162      pattern lead to the double precision destination of sel.d getting
7163      reloaded with the full register file usable and the restrictions on
7164      whether the CCFmode input can be used in odd-numbered single-precision
7165      registers are ignored.  For consistency reasons the CCF mode values
7166      must be guaranteed to only exist in the even-registers because of
7167      the unusual duality between single and double precision values.  */
7168   if (ISA_HAS_SEL && <MODE>mode == DFmode
7169       && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7170     FAIL;
7172   mips_expand_conditional_move (operands);
7173   DONE;
7177 ;;  ....................
7179 ;;      mips16 inline constant tables
7181 ;;  ....................
7184 (define_insn "consttable_tls_reloc"
7185   [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7186                      (match_operand 1 "const_int_operand" "")]
7187                     UNSPEC_CONSTTABLE_INT)]
7188   "TARGET_MIPS16_PCREL_LOADS"
7189   { return mips_output_tls_reloc_directive (&operands[0]); }
7190   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7192 (define_insn "consttable_int"
7193   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7194                      (match_operand 1 "const_int_operand" "")]
7195                     UNSPEC_CONSTTABLE_INT)]
7196   "TARGET_MIPS16"
7198   assemble_integer (mips_strip_unspec_address (operands[0]),
7199                     INTVAL (operands[1]),
7200                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
7201   return "";
7203   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7205 (define_insn "consttable_float"
7206   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7207                     UNSPEC_CONSTTABLE_FLOAT)]
7208   "TARGET_MIPS16"
7210   REAL_VALUE_TYPE d;
7212   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7213   REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
7214   assemble_real (d, GET_MODE (operands[0]),
7215                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
7216   return "";
7218   [(set (attr "length")
7219         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7221 (define_insn "align"
7222   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7223   ""
7224   ".align\t%0"
7225   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7227 (define_split
7228   [(match_operand 0 "small_data_pattern")]
7229   "reload_completed"
7230   [(match_dup 0)]
7231   { operands[0] = mips_rewrite_small_data (operands[0]); })
7234 ;;  ....................
7236 ;;      MIPS16e Save/Restore
7238 ;;  ....................
7241 (define_insn "*mips16e_save_restore"
7242   [(match_parallel 0 ""
7243        [(set (match_operand:SI 1 "register_operand")
7244              (plus:SI (match_dup 1)
7245                       (match_operand:SI 2 "const_int_operand")))])]
7246   "operands[1] == stack_pointer_rtx
7247    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7248   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7249   [(set_attr "type" "arith")
7250    (set_attr "extended_mips16" "yes")])
7252 ;; Thread-Local Storage
7254 ;; The TLS base pointer is accessed via "rdhwr $3, $29".  No current
7255 ;; MIPS architecture defines this register, and no current
7256 ;; implementation provides it; instead, any OS which supports TLS is
7257 ;; expected to trap and emulate this instruction.  rdhwr is part of the
7258 ;; MIPS 32r2 specification, but we use it on any architecture because
7259 ;; we expect it to be emulated.  Use .set to force the assembler to
7260 ;; accept it.
7262 ;; We do not use a constraint to force the destination to be $3
7263 ;; because $3 can appear explicitly as a function return value.
7264 ;; If we leave the use of $3 implicit in the constraints until
7265 ;; reload, we may end up making a $3 return value live across
7266 ;; the instruction, leading to a spill failure when reloading it.
7267 (define_insn_and_split "tls_get_tp_<mode>"
7268   [(set (match_operand:P 0 "register_operand" "=d")
7269         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7270    (clobber (reg:P TLS_GET_TP_REGNUM))]
7271   "HAVE_AS_TLS && !TARGET_MIPS16"
7272   "#"
7273   "&& reload_completed"
7274   [(set (reg:P TLS_GET_TP_REGNUM)
7275         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7276    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7277   ""
7278   [(set_attr "type" "unknown")
7279    (set_attr "mode" "<MODE>")
7280    (set_attr "insn_count" "2")])
7282 (define_insn "*tls_get_tp_<mode>_split"
7283   [(set (reg:P TLS_GET_TP_REGNUM)
7284         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7285   "HAVE_AS_TLS && !TARGET_MIPS16"
7286   {
7287     if (mips_isa_rev >= 2)
7288       return "rdhwr\t$3,$29";
7290     return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7291   }
7292   [(set_attr "type" "unknown")
7293    ; Since rdhwr always generates a trap for now, putting it in a delay
7294    ; slot would make the kernel's emulation of it much slower.
7295    (set_attr "can_delay" "no")
7296    (set_attr "mode" "<MODE>")])
7298 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7299 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7300 ;; accessible in MIPS16.
7302 ;; This is not represented as a call insn, to avoid the
7303 ;; unnecesarry clobbering of caller-save registers by a
7304 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7306 ;; A $25 clobber is added to cater for a $25 load stub added by the
7307 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7309 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7310   [(set (match_operand:P 0 "register_operand" "=d")
7311         (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7312                   UNSPEC_TLS_GET_TP))
7313    (clobber (reg:P TLS_GET_TP_REGNUM))
7314    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7315    (clobber (reg:P RETURN_ADDR_REGNUM))]
7316   "HAVE_AS_TLS && TARGET_MIPS16"
7317   "#"
7318   "&& reload_completed"
7319   [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7320                    (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7321               (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7322               (clobber (reg:P RETURN_ADDR_REGNUM))])
7323    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7324   ""
7325   [(set_attr "type" "multi")
7326    (set_attr "insn_count" "4")
7327    (set_attr "mode" "<MODE>")])
7329 (define_insn "*tls_get_tp_mips16_call_<mode>"
7330   [(set (reg:P TLS_GET_TP_REGNUM)
7331         (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7332                   UNSPEC_TLS_GET_TP))
7333    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7334    (clobber (reg:P RETURN_ADDR_REGNUM))]
7335   "HAVE_AS_TLS && TARGET_MIPS16"
7336   { return MIPS_CALL ("jal", operands, 0, -1); }
7337   [(set_attr "type" "call")
7338    (set_attr "insn_count" "3")
7339    (set_attr "mode" "<MODE>")])
7341 ;; Named pattern for expanding thread pointer reference.
7342 (define_expand "get_thread_pointer<mode>"
7343   [(match_operand:P 0 "register_operand" "=d")]
7344   "HAVE_AS_TLS"
7346   mips_expand_thread_pointer (operands[0]);
7347   DONE;
7350 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7351 (define_expand "mips_get_fcsr"
7352   [(set (match_operand:SI 0 "register_operand")
7353         (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7354   "TARGET_HARD_FLOAT_ABI"
7356   if (TARGET_MIPS16)
7357     {
7358       mips16_expand_get_fcsr (operands[0]);
7359       DONE;
7360     }
7363 (define_insn "*mips_get_fcsr"
7364   [(set (match_operand:SI 0 "register_operand" "=d")
7365         (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7366   "TARGET_HARD_FLOAT"
7367   "cfc1\t%0,$31")
7369 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7370 (define_insn "mips_get_fcsr_mips16_<mode>"
7371   [(set (reg:SI GET_FCSR_REGNUM)
7372         (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7373                    UNSPEC_GET_FCSR))
7374    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7375    (clobber (reg:P RETURN_ADDR_REGNUM))]
7376   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7377   { return MIPS_CALL ("jal", operands, 0, -1); }
7378   [(set_attr "type" "call")
7379    (set_attr "insn_count" "3")])
7381 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7382 (define_expand "mips_set_fcsr"
7383   [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7384                     UNSPEC_SET_FCSR)]
7385   "TARGET_HARD_FLOAT_ABI"
7387   if (TARGET_MIPS16)
7388     {
7389       mips16_expand_set_fcsr (operands[0]);
7390       DONE;
7391     }
7394 (define_insn "*mips_set_fcsr"
7395   [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7396                     UNSPEC_SET_FCSR)]
7397   "TARGET_HARD_FLOAT"
7398   "ctc1\t%0,$31")
7400 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7401 (define_insn "mips_set_fcsr_mips16_<mode>"
7402   [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7403                         (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7404    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7405    (clobber (reg:P RETURN_ADDR_REGNUM))]
7406   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7407   { return MIPS_CALL ("jal", operands, 0, -1); }
7408   [(set_attr "type" "call")
7409    (set_attr "insn_count" "3")])
7411 ;; Synchronization instructions.
7413 (include "sync.md")
7415 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7417 (include "mips-ps-3d.md")
7419 ; The MIPS DSP Instructions.
7421 (include "mips-dsp.md")
7423 ; The MIPS DSP REV 2 Instructions.
7425 (include "mips-dspr2.md")
7427 ; MIPS fixed-point instructions.
7428 (include "mips-fixed.md")
7430 ; microMIPS patterns.
7431 (include "micromips.md")
7433 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7434 (include "loongson.md")
7436 (define_c_enum "unspec" [
7437   UNSPEC_ADDRESS_FIRST