* config/sparc/sparc.c (sparc_option_override): Set MASK_FSMULD flag
[official-gcc.git] / gcc / config / mips / mips.md
blob971af6f8e097d811e8a1279a93921a1b6feadb70
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989-2017 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   m5100
71   i6400
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
124   UNSPEC_CONSTTABLE_END
125   UNSPEC_CONSTTABLE_INT
126   UNSPEC_CONSTTABLE_FLOAT
128   ;; Blockage and synchronisation.
129   UNSPEC_BLOCKAGE
130   UNSPEC_CLEAR_HAZARD
131   UNSPEC_RDHWR
132   UNSPEC_SYNCI
133   UNSPEC_SYNC
135   ;; Cache manipulation.
136   UNSPEC_MIPS_CACHE
137   UNSPEC_R10K_CACHE_BARRIER
139   ;; Interrupt handling.
140   UNSPEC_ERET
141   UNSPEC_DERET
142   UNSPEC_DI
143   UNSPEC_EHB
144   UNSPEC_RDPGPR
145   UNSPEC_COP0
147   ;; Used in a call expression in place of args_size.  It's present for PIC
148   ;; indirect calls where it contains args_size and the function symbol.
149   UNSPEC_CALL_ATTR
151   ;; MIPS16 casesi jump table dispatch.
152   UNSPEC_CASESI_DISPATCH
154   ;; Stack checking.
155   UNSPEC_PROBE_STACK_RANGE
157   ;; The `.insn' pseudo-op.
158   UNSPEC_INSN_PSEUDO
161 (define_constants
162   [(TLS_GET_TP_REGNUM           3)
163    (GET_FCSR_REGNUM             2)
164    (SET_FCSR_REGNUM             4)
165    (PIC_FUNCTION_ADDR_REGNUM    25)
166    (RETURN_ADDR_REGNUM          31)
167    (CPRESTORE_SLOT_REGNUM       76)
168    (GOT_VERSION_REGNUM          79)
170    ;; PIC long branch sequences are never longer than 100 bytes.
171    (MAX_PIC_BRANCH_LENGTH       100)
172   ]
175 (include "predicates.md")
176 (include "constraints.md")
178 ;; ....................
180 ;;      Attributes
182 ;; ....................
184 (define_attr "got" "unset,xgot_high,load"
185   (const_string "unset"))
187 ;; For jal instructions, this attribute is DIRECT when the target address
188 ;; is symbolic and INDIRECT when it is a register.
189 (define_attr "jal" "unset,direct,indirect"
190   (const_string "unset"))
192 ;; This attribute is YES if the instruction is a jal macro (not a
193 ;; real jal instruction).
195 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
196 ;; an instruction to restore $gp.  Direct jals are also macros for
197 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
198 ;; into a register.
199 (define_attr "jal_macro" "no,yes"
200   (cond [(eq_attr "jal" "direct")
201          (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
202                        ? JAL_MACRO_YES : JAL_MACRO_NO)")
203          (eq_attr "jal" "indirect")
204          (symbol_ref "(TARGET_CALL_CLOBBERED_GP
205                        ? JAL_MACRO_YES : JAL_MACRO_NO)")]
206         (const_string "no")))
208 ;; Classification of moves, extensions and truncations.  Most values
209 ;; are as for "type" (see below) but there are also the following
210 ;; move-specific values:
212 ;; constN       move an N-constraint integer into a MIPS16 register
213 ;; sll0         "sll DEST,SRC,0", which on 64-bit targets is guaranteed
214 ;;              to produce a sign-extended DEST, even if SRC is not
215 ;;              properly sign-extended
216 ;; ext_ins      EXT, DEXT, INS or DINS instruction
217 ;; andi         a single ANDI instruction
218 ;; loadpool     move a constant into a MIPS16 register by loading it
219 ;;              from the pool
220 ;; shift_shift  a shift left followed by a shift right
222 ;; This attribute is used to determine the instruction's length and
223 ;; scheduling type.  For doubleword moves, the attribute always describes
224 ;; the split instructions; in some cases, it is more appropriate for the
225 ;; scheduling type to be "multi" instead.
226 (define_attr "move_type"
227   "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
228    const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
229    shift_shift"
230   (const_string "unknown"))
232 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor,simd_add"
233   (const_string "unknown"))
235 ;; Main data type used by the insn
236 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW,
237   V2DI,V4SI,V8HI,V16QI,V2DF,V4SF"
238   (const_string "unknown"))
240 ;; True if the main data type is twice the size of a word.
241 (define_attr "dword_mode" "no,yes"
242   (cond [(and (eq_attr "mode" "DI,DF")
243               (not (match_test "TARGET_64BIT")))
244          (const_string "yes")
246          (and (eq_attr "mode" "TI,TF")
247               (match_test "TARGET_64BIT"))
248          (const_string "yes")]
249         (const_string "no")))
251 ;; True if the main data type is four times of the size of a word.
252 (define_attr "qword_mode" "no,yes"
253   (cond [(and (eq_attr "mode" "TI,TF")
254               (not (match_test "TARGET_64BIT")))
255          (const_string "yes")]
256         (const_string "no")))
258 ;; Attributes describing a sync loop.  These loops have the form:
260 ;;       if (RELEASE_BARRIER == YES) sync
261 ;;    1: OLDVAL = *MEM
262 ;;       if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
263 ;;         CMP  = 0 [delay slot]
264 ;;       $TMP1 = OLDVAL & EXCLUSIVE_MASK
265 ;;       $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
266 ;;       $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
267 ;;       $AT |= $TMP1 | $TMP3
268 ;;       if (!commit (*MEM = $AT)) goto 1.
269 ;;         if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
270 ;;       CMP  = 1
271 ;;       if (ACQUIRE_BARRIER == YES) sync
272 ;;    2:
274 ;; where "$" values are temporaries and where the other values are
275 ;; specified by the attributes below.  Values are specified as operand
276 ;; numbers and insns are specified as enums.  If no operand number is
277 ;; specified, the following values are used instead:
279 ;;    - OLDVAL: $AT
280 ;;    - CMP: NONE
281 ;;    - NEWVAL: $AT
282 ;;    - INCLUSIVE_MASK: -1
283 ;;    - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
284 ;;    - EXCLUSIVE_MASK: 0
286 ;; MEM and INSN1_OP2 are required.
288 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
289 ;; but the gen* programs don't yet support that.
290 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
291 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
292 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
293 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
294 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
295 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
296 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
297 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
298 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
299   (const_string "move"))
300 (define_attr "sync_insn2" "nop,and,xor,not"
301   (const_string "nop"))
302 ;; Memory model specifier.
303 ;; "0"-"9" values specify the operand that stores the memory model value.
304 ;; "10" specifies MEMMODEL_ACQ_REL,
305 ;; "11" specifies MEMMODEL_ACQUIRE.
306 (define_attr "sync_memmodel" "" (const_int 10))
308 ;; Accumulator operand for madd patterns.
309 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
311 ;; Classification of each insn.
312 ;; branch       conditional branch
313 ;; jump         unconditional jump
314 ;; call         unconditional call
315 ;; load         load instruction(s)
316 ;; fpload       floating point load
317 ;; fpidxload    floating point indexed load
318 ;; store        store instruction(s)
319 ;; fpstore      floating point store
320 ;; fpidxstore   floating point indexed store
321 ;; prefetch     memory prefetch (register + offset)
322 ;; prefetchx    memory indexed prefetch (register + register)
323 ;; condmove     conditional moves
324 ;; mtc          transfer to coprocessor
325 ;; mfc          transfer from coprocessor
326 ;; mthi         transfer to a hi register
327 ;; mtlo         transfer to a lo register
328 ;; mfhi         transfer from a hi register
329 ;; mflo         transfer from a lo register
330 ;; const        load constant
331 ;; arith        integer arithmetic instructions
332 ;; logical      integer logical instructions
333 ;; shift        integer shift instructions
334 ;; slt          set less than instructions
335 ;; signext      sign extend instructions
336 ;; clz          the clz and clo instructions
337 ;; pop          the pop instruction
338 ;; trap         trap if instructions
339 ;; imul         integer multiply 2 operands
340 ;; imul3        integer multiply 3 operands
341 ;; imul3nc      integer multiply 3 operands without clobbering HI/LO
342 ;; imadd        integer multiply-add
343 ;; idiv         integer divide 2 operands
344 ;; idiv3        integer divide 3 operands
345 ;; move         integer register move ({,D}ADD{,U} with rt = 0)
346 ;; fmove        floating point register move
347 ;; fadd         floating point add/subtract
348 ;; fmul         floating point multiply
349 ;; fmadd        floating point multiply-add
350 ;; fdiv         floating point divide
351 ;; frdiv        floating point reciprocal divide
352 ;; frdiv1       floating point reciprocal divide step 1
353 ;; frdiv2       floating point reciprocal divide step 2
354 ;; fabs         floating point absolute value
355 ;; fneg         floating point negation
356 ;; fcmp         floating point compare
357 ;; fcvt         floating point convert
358 ;; fsqrt        floating point square root
359 ;; frsqrt       floating point reciprocal square root
360 ;; frsqrt1      floating point reciprocal square root step1
361 ;; frsqrt2      floating point reciprocal square root step2
362 ;; dspmac       DSP MAC instructions not saturating the accumulator
363 ;; dspmacsat    DSP MAC instructions that saturate the accumulator
364 ;; accext       DSP accumulator extract instructions
365 ;; accmod       DSP accumulator modify instructions
366 ;; dspalu       DSP ALU instructions not saturating the result
367 ;; dspalusat    DSP ALU instructions that saturate the result
368 ;; multi        multiword sequence (or user asm statements)
369 ;; atomic       atomic memory update instruction
370 ;; syncloop     memory atomic operation implemented as a sync loop
371 ;; nop          no operation
372 ;; ghost        an instruction that produces no real code
373 ;; multimem     microMIPS multiword load and store
374 (define_attr "type"
375   "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
376    prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
377    shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
378    fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
379    frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
380    multi,atomic,syncloop,nop,ghost,multimem,
381    simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd,
382    simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp,
383    simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill,
384    simd_permute,simd_shf,simd_sat,simd_pcnt,simd_copy,simd_branch,simd_cmsa,
385    simd_fminmax,simd_logic,simd_move,simd_load,simd_store"
386   (cond [(eq_attr "jal" "!unset") (const_string "call")
387          (eq_attr "got" "load") (const_string "load")
389          (eq_attr "alu_type" "add,sub") (const_string "arith")
391          (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
393          ;; If a doubleword move uses these expensive instructions,
394          ;; it is usually better to schedule them in the same way
395          ;; as the singleword form, rather than as "multi".
396          (eq_attr "move_type" "load") (const_string "load")
397          (eq_attr "move_type" "fpload") (const_string "fpload")
398          (eq_attr "move_type" "store") (const_string "store")
399          (eq_attr "move_type" "fpstore") (const_string "fpstore")
400          (eq_attr "move_type" "mtc") (const_string "mtc")
401          (eq_attr "move_type" "mfc") (const_string "mfc")
402          (eq_attr "move_type" "mtlo") (const_string "mtlo")
403          (eq_attr "move_type" "mflo") (const_string "mflo")
405          ;; These types of move are always single insns.
406          (eq_attr "move_type" "imul") (const_string "imul")
407          (eq_attr "move_type" "fmove") (const_string "fmove")
408          (eq_attr "move_type" "loadpool") (const_string "load")
409          (eq_attr "move_type" "signext") (const_string "signext")
410          (eq_attr "move_type" "ext_ins") (const_string "arith")
411          (eq_attr "move_type" "arith") (const_string "arith")
412          (eq_attr "move_type" "logical") (const_string "logical")
413          (eq_attr "move_type" "sll0") (const_string "shift")
414          (eq_attr "move_type" "andi") (const_string "logical")
416          ;; These types of move are always split.
417          (eq_attr "move_type" "constN,shift_shift")
418            (const_string "multi")
420          ;; These types of move are split for quadword modes only.
421          (and (eq_attr "move_type" "move,const")
422               (eq_attr "qword_mode" "yes"))
423            (const_string "multi")
425          ;; These types of move are split for doubleword modes only.
426          (and (eq_attr "move_type" "move,const")
427               (eq_attr "dword_mode" "yes"))
428            (const_string "multi")
429          (eq_attr "move_type" "move") (const_string "move")
430          (eq_attr "move_type" "const") (const_string "const")
431          (eq_attr "sync_mem" "!none") (const_string "syncloop")]
432         (const_string "unknown")))
434 (define_attr "compact_form" "always,maybe,never"
435   (cond [(eq_attr "jal" "direct")
436          (const_string "always")
437          (eq_attr "jal" "indirect")
438          (const_string "maybe")
439          (eq_attr "type" "jump")
440          (const_string "maybe")]
441         (const_string "never")))
443 ;; Mode for conversion types (fcvt)
444 ;; I2S          integer to float single (SI/DI to SF)
445 ;; I2D          integer to float double (SI/DI to DF)
446 ;; S2I          float to integer (SF to SI/DI)
447 ;; D2I          float to integer (DF to SI/DI)
448 ;; D2S          double to float single
449 ;; S2D          float single to double
451 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D" 
452   (const_string "unknown"))
454 ;; Is this an extended instruction in mips16 mode?
455 (define_attr "extended_mips16" "no,yes"
456   (if_then_else (ior ;; In general, constant-pool loads are extended
457                      ;; instructions.  We don't yet optimize for 16-bit
458                      ;; PC-relative references.
459                      (eq_attr "move_type" "sll0,loadpool")
460                      (eq_attr "jal" "direct")
461                      (eq_attr "got" "load"))
462                 (const_string "yes")
463                 (const_string "no")))
465 (define_attr "compression" "none,all,micromips32,micromips"
466   (const_string "none"))
468 (define_attr "enabled" "no,yes"
469   (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
470          ;; GR_REG and FR_REG for 64-bit values.
471          (and (eq_attr "move_type" "mtc,mfc")
472               (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
473                            || TARGET_O32_FP64A_ABI")
474               (eq_attr "dword_mode" "yes"))
475          (const_string "no")
476          (and (eq_attr "compression" "micromips32,micromips")
477               (match_test "!TARGET_MICROMIPS"))
478          (const_string "no")]
479         (const_string "yes")))
481 ;; The number of individual instructions that a non-branch pattern generates,
482 ;; using units of BASE_INSN_LENGTH.
483 (define_attr "insn_count" ""
484   (cond [;; "Ghost" instructions occupy no space.
485          (eq_attr "type" "ghost")
486          (const_int 0)
488          ;; Extended instructions count as 2.
489          (and (eq_attr "extended_mips16" "yes")
490               (match_test "TARGET_MIPS16"))
491          (const_int 2)
493          ;; A GOT load followed by an add of $gp.  This is not used for MIPS16.
494          (eq_attr "got" "xgot_high")
495          (const_int 2)
497          ;; SHIFT_SHIFTs are decomposed into two separate instructions.
498          ;; They are extended instructions on MIPS16 targets.
499          (eq_attr "move_type" "shift_shift")
500          (if_then_else (match_test "TARGET_MIPS16")
501                        (const_int 4)
502                        (const_int 2))
504          ;; Check for doubleword moves that are decomposed into two
505          ;; instructions.  The individual instructions are unextended
506          ;; MIPS16 ones.
507          (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
508               (eq_attr "dword_mode" "yes"))
509          (const_int 2)
511          ;; Check for quadword moves that are decomposed into four
512          ;; instructions.
513          (and (eq_attr "move_type" "mtc,mfc,move")
514               (eq_attr "qword_mode" "yes"))
515          (const_int 4)
517          ;; Constants, loads and stores are handled by external routines.
518          (and (eq_attr "move_type" "const,constN")
519               (eq_attr "dword_mode" "yes"))
520          (symbol_ref "mips_split_const_insns (operands[1])")
521          (eq_attr "move_type" "const,constN")
522          (symbol_ref "mips_const_insns (operands[1])")
523          (eq_attr "move_type" "load,fpload")
524          (symbol_ref "mips_load_store_insns (operands[1], insn)")
525          (eq_attr "move_type" "store,fpstore")
526          (symbol_ref "mips_load_store_insns (operands[0], insn)
527                       + (TARGET_FIX_24K ? 1 : 0)")
529          ;; In the worst case, a call macro will take 8 instructions:
530          ;;
531          ;;     lui $25,%call_hi(FOO)
532          ;;     addu $25,$25,$28
533          ;;     lw $25,%call_lo(FOO)($25)
534          ;;     nop
535          ;;     jalr $25
536          ;;     nop
537          ;;     lw $gp,X($sp)
538          ;;     nop
539          (eq_attr "jal_macro" "yes")
540          (const_int 8)
542          ;; Various VR4120 errata require a nop to be inserted after a macc
543          ;; instruction.  The assembler does this for us, so account for
544          ;; the worst-case length here.
545          (and (eq_attr "type" "imadd")
546               (match_test "TARGET_FIX_VR4120"))
547          (const_int 2)
549          ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
550          ;; the result of the second one is missed.  The assembler should work
551          ;; around this by inserting a nop after the first dmult.
552          (and (eq_attr "type" "imul,imul3")
553               (eq_attr "mode" "DI")
554               (match_test "TARGET_FIX_VR4120"))
555          (const_int 2)
557          (eq_attr "type" "idiv,idiv3")
558          (symbol_ref "mips_idiv_insns (GET_MODE (PATTERN (insn)))")
560          (not (eq_attr "sync_mem" "none"))
561          (symbol_ref "mips_sync_loop_insns (insn, operands)")]
562         (const_int 1)))
564 ;; Length of instruction in bytes.  The default is derived from "insn_count",
565 ;; but there are special cases for branches (which must be handled here)
566 ;; and for compressed single instructions.
567 (define_attr "length" ""
568    (cond [(and (ior (eq_attr "compression" "micromips,all")
569                     (and (eq_attr "compression" "micromips32")
570                          (eq_attr "mode" "SI,SF")))
571                (eq_attr "dword_mode" "no")
572                (match_test "TARGET_MICROMIPS"))
573           (const_int 2)
575           ;; Direct microMIPS branch instructions have a range of
576           ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
577           ;; If a branch is outside this range, we have a choice of two
578           ;; sequences.
579           ;;
580           ;; For PIC, an out-of-range branch like:
581           ;;
582           ;;    bne     r1,r2,target
583           ;;    dslot
584           ;;
585           ;; becomes the equivalent of:
586           ;;
587           ;;    beq     r1,r2,1f
588           ;;    dslot
589           ;;    la      $at,target
590           ;;    jr      $at
591           ;;    nop
592           ;; 1:
593           ;;
594           ;; The non-PIC case is similar except that we use a direct
595           ;; jump instead of an la/jr pair.  Since the target of this
596           ;; jump is an absolute 28-bit bit address (the other bits
597           ;; coming from the address of the delay slot) this form cannot
598           ;; cross a 256MB boundary.  We could provide the option of
599           ;; using la/jr in this case too, but we do not do so at
600           ;; present.
601           ;;
602           ;; The value we specify here does not account for the delay slot
603           ;; instruction, whose length is added separately.  If the RTL
604           ;; pattern has no explicit delay slot, mips_adjust_insn_length
605           ;; will add the length of the implicit nop.  The range of
606           ;; [-0x20000, 0x1fffc] from the address of the delay slot
607           ;; therefore translates to a range of:
608           ;;
609           ;;    [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
610           ;; == [-0x1fffc, 0x1fff8]
611           ;;
612           ;; from the shorten_branches reference address.
613           (and (eq_attr "type" "branch")
614                (not (match_test "TARGET_MIPS16")))
615           (cond [;; Any variant can handle the 17-bit range.
616                  (and (le (minus (match_dup 0) (pc)) (const_int 65532))
617                       (le (minus (pc) (match_dup 0)) (const_int 65534)))
618                    (const_int 4)
620                  ;; The 18-bit range is OK other than for microMIPS.
621                  (and (not (match_test "TARGET_MICROMIPS"))
622                       (and (le (minus (match_dup 0) (pc)) (const_int 131064))
623                            (le (minus (pc) (match_dup 0)) (const_int 131068))))
624                    (const_int 4)
626                  ;; The non-PIC case: branch, first delay slot, and J.
627                  (match_test "TARGET_ABSOLUTE_JUMPS")
628                    (const_int 12)]
630                  ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
631                  ;; mips_adjust_insn_length substitutes the correct length.
632                  ;;
633                  ;; Note that we can't simply use (symbol_ref ...) here
634                  ;; because genattrtab needs to know the maximum length
635                  ;; of an insn.
636                  (const_int MAX_PIC_BRANCH_LENGTH))
638           ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
639           ;; from the address of the following instruction, which leads
640           ;; to a range of:
641           ;;
642           ;;    [-(0x100 - sizeof (branch)), 0xfe]
643           ;; == [-0xfe, 0xfe]
644           ;;
645           ;; from the shorten_branches reference address.  Extended branches
646           ;; likewise have a range of [-0x10000, 0xfffe] from the address
647           ;; of the following instruction, which leads to a range of:
648           ;;
649           ;;    [-(0x10000 - sizeof (branch)), 0xfffe]
650           ;; == [-0xfffc, 0xfffe]
651           ;;
652           ;; from the reference address.
653           ;;
654           ;; When a branch is out of range, mips_reorg splits it into a form
655           ;; that uses in-range branches.  There are four basic sequences:
656           ;;
657           ;; (1) Absolute addressing with a readable text segment
658           ;;     (32-bit addresses):
659           ;;
660           ;;     b... foo               2 bytes
661           ;;     move $1,$2             2 bytes
662           ;;     lw $2,label            2 bytes
663           ;;     jr $2                  2 bytes
664           ;;     move $2,$1             2 bytes
665           ;;     .align 2               0 or 2 bytes
666           ;; label:
667           ;;     .word target           4 bytes
668           ;; foo:
669           ;;                            (16 bytes in the worst case)
670           ;;
671           ;; (2) Absolute addressing with a readable text segment
672           ;;     (64-bit addresses):
673           ;;
674           ;;     b... foo               2 bytes
675           ;;     move $1,$2             2 bytes
676           ;;     ld $2,label            2 bytes
677           ;;     jr $2                  2 bytes
678           ;;     move $2,$1             2 bytes
679           ;;     .align 3               0 to 6 bytes
680           ;; label:
681           ;;     .dword target          8 bytes
682           ;; foo:
683           ;;                            (24 bytes in the worst case)
684           ;;
685           ;; (3) Absolute addressing without a readable text segment
686           ;;     (which requires 32-bit addresses at present):
687           ;;
688           ;;     b... foo               2 bytes
689           ;;     move $1,$2             2 bytes
690           ;;     lui $2,%hi(target)     4 bytes
691           ;;     sll $2,8               2 bytes
692           ;;     sll $2,8               2 bytes
693           ;;     addiu $2,%lo(target)   4 bytes
694           ;;     jr $2                  2 bytes
695           ;;     move $2,$1             2 bytes
696           ;; foo:
697           ;;                            (20 bytes)
698           ;;
699           ;; (4) PIC addressing (which requires 32-bit addresses at present):
700           ;;
701           ;;     b... foo               2 bytes
702           ;;     move $1,$2             2 bytes
703           ;;     lw $2,cprestore        0, 2 or 4 bytes
704           ;;     lw $2,%got(target)($2) 4 bytes
705           ;;     addiu $2,%lo(target)   4 bytes
706           ;;     jr $2                  2 bytes
707           ;;     move $2,$1             2 bytes
708           ;; foo:
709           ;;                            (20 bytes in the worst case)
710           (and (eq_attr "type" "branch")
711                (match_test "TARGET_MIPS16"))
712           (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
713                       (le (minus (pc) (match_dup 0)) (const_int 254)))
714                  (const_int 2)
715                  (and (le (minus (match_dup 0) (pc)) (const_int 65534))
716                       (le (minus (pc) (match_dup 0)) (const_int 65532)))
717                  (const_int 4)
718                  (and (match_test "TARGET_ABICALLS")
719                       (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
720                  (const_int 20)
721                  (match_test "Pmode == SImode")
722                  (const_int 16)
723                  ] (const_int 24))]
724          (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
726 ;; Attribute describing the processor.
727 (define_enum_attr "cpu" "processor"
728   (const (symbol_ref "mips_tune")))
730 ;; The type of hardware hazard associated with this instruction.
731 ;; DELAY means that the next instruction cannot read the result
732 ;; of this one.  HILO means that the next two instructions cannot
733 ;; write to HI or LO.
734 (define_attr "hazard" "none,delay,hilo,forbidden_slot"
735   (cond [(and (eq_attr "type" "load,fpload,fpidxload")
736               (match_test "ISA_HAS_LOAD_DELAY"))
737          (const_string "delay")
739          (and (eq_attr "type" "mfc,mtc")
740               (match_test "ISA_HAS_XFER_DELAY"))
741          (const_string "delay")
743          (and (eq_attr "type" "fcmp")
744               (match_test "ISA_HAS_FCMP_DELAY"))
745          (const_string "delay")
747          ;; The r4000 multiplication patterns include an mflo instruction.
748          (and (eq_attr "type" "imul")
749               (match_test "TARGET_FIX_R4000"))
750          (const_string "hilo")
752          (and (eq_attr "type" "mfhi,mflo")
753               (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
754          (const_string "hilo")]
755         (const_string "none")))
757 ;; Can the instruction be put into a delay slot?
758 (define_attr "can_delay" "no,yes"
759   (if_then_else (and (eq_attr "type" "!branch,call,jump")
760                      (eq_attr "hazard" "none")
761                      (match_test "get_attr_insn_count (insn) == 1"))
762                 (const_string "yes")
763                 (const_string "no")))
765 ;; Attribute defining whether or not we can use the branch-likely
766 ;; instructions.
767 (define_attr "branch_likely" "no,yes"
768   (if_then_else (match_test "GENERATE_BRANCHLIKELY")
769                 (const_string "yes")
770                 (const_string "no")))
772 ;; True if an instruction might assign to hi or lo when reloaded.
773 ;; This is used by the TUNE_MACC_CHAINS code.
774 (define_attr "may_clobber_hilo" "no,yes"
775   (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
776                 (const_string "yes")
777                 (const_string "no")))
779 ;; Describe a user's asm statement.
780 (define_asm_attributes
781   [(set_attr "type" "multi")
782    (set_attr "can_delay" "no")])
784 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
785 ;; from the same template.
786 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
788 ;; A copy of GPR that can be used when a pattern has two independent
789 ;; modes.
790 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
792 (define_mode_iterator MOVEP1 [SI SF])
793 (define_mode_iterator MOVEP2 [SI SF])
794 (define_mode_iterator JOIN_MODE [HI
795                                  SI
796                                  (SF "TARGET_HARD_FLOAT")
797                                  (DF "TARGET_HARD_FLOAT
798                                       && TARGET_DOUBLE_FLOAT")])
800 ;; This mode iterator allows :HILO to be used as the mode of the
801 ;; concatenated HI and LO registers.
802 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
804 ;; This mode iterator allows :P to be used for patterns that operate on
805 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
806 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
808 ;; This mode iterator allows :MOVECC to be used anywhere that a
809 ;; conditional-move-type condition is needed.
810 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
811                               (CC "TARGET_HARD_FLOAT
812                                    && !TARGET_LOONGSON_2EF
813                                    && !TARGET_MIPS5900")])
815 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
816 ;; is needed.
817 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
818                             (CCF "ISA_HAS_CCF")])
820 ;; 32-bit integer moves for which we provide move patterns.
821 (define_mode_iterator IMOVE32
822   [SI
823    (V2HI "TARGET_DSP")
824    (V4QI "TARGET_DSP")
825    (V2HQ "TARGET_DSP")
826    (V2UHQ "TARGET_DSP")
827    (V2HA "TARGET_DSP")
828    (V2UHA "TARGET_DSP")
829    (V4QQ "TARGET_DSP")
830    (V4UQQ "TARGET_DSP")])
832 ;; 64-bit modes for which we provide move patterns.
833 (define_mode_iterator MOVE64
834   [DI DF
835    (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
836    (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
837    (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
838    (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
840 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
841 (define_mode_iterator MOVE128 [TI TF])
843 ;; This mode iterator allows the QI and HI extension patterns to be
844 ;; defined from the same template.
845 (define_mode_iterator SHORT [QI HI])
847 ;; Likewise the 64-bit truncate-and-shift patterns.
848 (define_mode_iterator SUBDI [QI HI SI])
850 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
851 ;; floating-point mode is allowed.
852 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
853                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
854                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
856 ;; Like ANYF, but only applies to scalar modes.
857 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
858                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
860 ;; A floating-point mode for which moves involving FPRs may need to be split.
861 (define_mode_iterator SPLITF
862   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
863    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
864    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
865    (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
866    (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
867    (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
868    (TF "TARGET_64BIT && TARGET_FLOAT64")])
870 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
871 ;; 32-bit version and "dsubu" in the 64-bit version.
872 (define_mode_attr d [(SI "") (DI "d")
873                      (QQ "") (HQ "") (SQ "") (DQ "d")
874                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
875                      (HA "") (SA "") (DA "d")
876                      (UHA "") (USA "") (UDA "d")])
878 ;; Same as d but upper-case.
879 (define_mode_attr D [(SI "") (DI "D")
880                      (QQ "") (HQ "") (SQ "") (DQ "D")
881                      (UQQ "") (UHQ "") (USQ "") (UDQ "D")
882                      (HA "") (SA "") (DA "D")
883                      (UHA "") (USA "") (UDA "D")])
885 ;; This attribute gives the length suffix for a load or store instruction.
886 ;; The same suffixes work for zero and sign extensions.
887 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
888 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
890 ;; This attributes gives the mode mask of a SHORT.
891 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
893 ;; Mode attributes for GPR loads.
894 (define_mode_attr load [(SI "lw") (DI "ld")])
895 ;; Instruction names for stores.
896 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
898 ;; Similarly for MIPS IV indexed FPR loads and stores.
899 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
900 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
902 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
903 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
904 ;; field but the equivalent daddiu has only a 5-bit field.
905 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
907 ;; This attribute gives the best constraint to use for registers of
908 ;; a given mode.
909 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
911 ;; This attribute gives the format suffix for floating-point operations.
912 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
914 ;; This attribute gives the upper-case mode name for one unit of a
915 ;; floating-point mode or vector mode.
916 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF") (V4SF "SF")
917                             (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
918                             (V2DF "DF")])
920 ;; This attribute gives the integer mode that has the same size as a
921 ;; fixed-point mode.
922 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
923                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
924                          (HA "HI") (SA "SI") (DA "DI")
925                          (UHA "HI") (USA "SI") (UDA "DI")
926                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
927                          (V2HQ "SI") (V2HA "SI")])
929 ;; This attribute gives the integer mode that has half the size of
930 ;; the controlling mode.
931 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
932                             (V2SI "SI") (V4HI "SI") (V8QI "SI")
933                             (TF "DI")])
935 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
937 ;; In certain cases, div.s and div.ps may have a rounding error
938 ;; and/or wrong inexact flag.
940 ;; Therefore, we only allow div.s if not working around SB-1 rev2
941 ;; errata or if a slight loss of precision is OK.
942 (define_mode_attr divide_condition
943   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
944    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
946 ;; This attribute gives the conditions under which SQRT.fmt instructions
947 ;; can be used.
948 (define_mode_attr sqrt_condition
949   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
951 ;; This attribute provides the correct mnemonic for each FP condition mode.
952 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
954 ;; This code iterator allows signed and unsigned widening multiplications
955 ;; to use the same template.
956 (define_code_iterator any_extend [sign_extend zero_extend])
958 ;; This code iterator allows the two right shift instructions to be
959 ;; generated from the same template.
960 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
962 ;; This code iterator allows the three shift instructions to be generated
963 ;; from the same template.
964 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
966 ;; This code iterator allows unsigned and signed division to be generated
967 ;; from the same template.
968 (define_code_iterator any_div [div udiv])
970 ;; This code iterator allows unsigned and signed modulus to be generated
971 ;; from the same template.
972 (define_code_iterator any_mod [mod umod])
974 ;; This code iterator allows addition and subtraction to be generated
975 ;; from the same template.
976 (define_code_iterator addsub [plus minus])
978 ;; This code iterator allows all native floating-point comparisons to be
979 ;; generated from the same template.
980 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
981                              (ordered "ISA_HAS_CCF")
982                              (ltgt "ISA_HAS_CCF")
983                              (ne "ISA_HAS_CCF")])
985 ;; This code iterator is used for comparisons that can be implemented
986 ;; by swapping the operands.
987 (define_code_iterator swapped_fcond [ge gt unge ungt])
989 ;; Equality operators.
990 (define_code_iterator equality_op [eq ne])
992 ;; These code iterators allow the signed and unsigned scc operations to use
993 ;; the same template.
994 (define_code_iterator any_gt [gt gtu])
995 (define_code_iterator any_ge [ge geu])
996 (define_code_iterator any_lt [lt ltu])
997 (define_code_iterator any_le [le leu])
999 (define_code_iterator any_return [return simple_return])
1001 ;; <u> expands to an empty string when doing a signed operation and
1002 ;; "u" when doing an unsigned operation.
1003 (define_code_attr u [(sign_extend "") (zero_extend "u")
1004                      (div "") (udiv "u")
1005                      (mod "") (umod "u")
1006                      (gt "") (gtu "u")
1007                      (ge "") (geu "u")
1008                      (lt "") (ltu "u")
1009                      (le "") (leu "u")])
1011 ;; <U> is like <u> except uppercase.
1012 (define_code_attr U [(sign_extend "") (zero_extend "U")])
1014 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
1015 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
1017 ;; <optab> expands to the name of the optab for a particular code.
1018 (define_code_attr optab [(ashift "ashl")
1019                          (ashiftrt "ashr")
1020                          (lshiftrt "lshr")
1021                          (ior "ior")
1022                          (xor "xor")
1023                          (and "and")
1024                          (plus "add")
1025                          (minus "sub")
1026                          (return "return")
1027                          (simple_return "simple_return")])
1029 ;; <insn> expands to the name of the insn that implements a particular code.
1030 (define_code_attr insn [(ashift "sll")
1031                         (ashiftrt "sra")
1032                         (lshiftrt "srl")
1033                         (ior "or")
1034                         (xor "xor")
1035                         (and "and")
1036                         (plus "addu")
1037                         (minus "subu")])
1039 ;; <immediate_insn> expands to the name of the insn that implements
1040 ;; a particular code to operate on immediate values.
1041 (define_code_attr immediate_insn [(ior "ori")
1042                                   (xor "xori")
1043                                   (and "andi")])
1045 (define_code_attr shift_compression [(ashift "micromips32")
1046                                      (lshiftrt "micromips32")
1047                                      (ashiftrt "none")])
1049 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1050 (define_code_attr fcond [(unordered "un")
1051                          (uneq "ueq")
1052                          (unlt "ult")
1053                          (unle "ule")
1054                          (eq "eq")
1055                          (lt "lt")
1056                          (le "le")
1057                          (ordered "or")
1058                          (ltgt "ne")
1059                          (ne "une")])
1061 ;; Similar, but for swapped conditions.
1062 (define_code_attr swapped_fcond [(ge "le")
1063                                  (gt "lt")
1064                                  (unge "ule")
1065                                  (ungt "ult")])
1067 ;; The value of the bit when the branch is taken for branch_bit patterns.
1068 ;; Comparison is always against zero so this depends on the operator.
1069 (define_code_attr bbv [(eq "0") (ne "1")])
1071 ;; This is the inverse value of bbv.
1072 (define_code_attr bbinv [(eq "1") (ne "0")])
1074 ;; The sel mnemonic to use depending on the condition test.
1075 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1076 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1078 ;; .........................
1080 ;;      Branch, call and jump delay slots
1082 ;; .........................
1084 (define_delay (and (eq_attr "type" "branch")
1085                    (not (match_test "TARGET_MIPS16"))
1086                    (eq_attr "branch_likely" "yes"))
1087   [(eq_attr "can_delay" "yes")
1088    (nil)
1089    (eq_attr "can_delay" "yes")])
1091 ;; Branches that have delay slots and don't have likely variants do
1092 ;; not annul on false.
1093 (define_delay (and (eq_attr "type" "branch")
1094                    (not (match_test "TARGET_MIPS16"))
1095                    (ior (match_test "TARGET_CB_NEVER")
1096                         (and (eq_attr "compact_form" "maybe")
1097                              (not (match_test "TARGET_CB_ALWAYS")))
1098                         (eq_attr "compact_form" "never"))
1099                    (eq_attr "branch_likely" "no"))
1100   [(eq_attr "can_delay" "yes")
1101    (nil)
1102    (nil)])
1104 (define_delay (and (eq_attr "type" "jump")
1105                    (ior (match_test "TARGET_CB_NEVER")
1106                         (and (eq_attr "compact_form" "maybe")
1107                              (not (match_test "TARGET_CB_ALWAYS")))
1108                         (eq_attr "compact_form" "never")))
1109   [(eq_attr "can_delay" "yes")
1110    (nil)
1111    (nil)])
1113 ;; Call type instructions should never have a compact form as the
1114 ;; type is only used for MIPS16 patterns.  For safety put the compact
1115 ;; branch detection condition in anyway.
1116 (define_delay (and (eq_attr "type" "call")
1117                    (eq_attr "jal_macro" "no")
1118                    (ior (match_test "TARGET_CB_NEVER")
1119                         (and (eq_attr "compact_form" "maybe")
1120                              (not (match_test "TARGET_CB_ALWAYS")))
1121                         (eq_attr "compact_form" "never")))
1122   [(eq_attr "can_delay" "yes")
1123    (nil)
1124    (nil)])
1126 ;; Pipeline descriptions.
1128 ;; generic.md provides a fallback for processors without a specific
1129 ;; pipeline description.  It is derived from the old define_function_unit
1130 ;; version and uses the "alu" and "imuldiv" units declared below.
1132 ;; Some of the processor-specific files are also derived from old
1133 ;; define_function_unit descriptions and simply override the parts of
1134 ;; generic.md that don't apply.  The other processor-specific files
1135 ;; are self-contained.
1136 (define_automaton "alu,imuldiv")
1138 (define_cpu_unit "alu" "alu")
1139 (define_cpu_unit "imuldiv" "imuldiv")
1141 ;; Ghost instructions produce no real code and introduce no hazards.
1142 ;; They exist purely to express an effect on dataflow.
1143 (define_insn_reservation "ghost" 0
1144   (eq_attr "type" "ghost")
1145   "nothing")
1147 (include "i6400.md")
1148 (include "p5600.md")
1149 (include "m5100.md")
1150 (include "4k.md")
1151 (include "5k.md")
1152 (include "20kc.md")
1153 (include "24k.md")
1154 (include "74k.md")
1155 (include "3000.md")
1156 (include "4000.md")
1157 (include "4100.md")
1158 (include "4130.md")
1159 (include "4300.md")
1160 (include "4600.md")
1161 (include "5000.md")
1162 (include "5400.md")
1163 (include "5500.md")
1164 (include "6000.md")
1165 (include "7000.md")
1166 (include "9000.md")
1167 (include "10000.md")
1168 (include "loongson2ef.md")
1169 (include "loongson3a.md")
1170 (include "octeon.md")
1171 (include "sb1.md")
1172 (include "sr71k.md")
1173 (include "xlr.md")
1174 (include "xlp.md")
1175 (include "generic.md")
1178 ;;  ....................
1180 ;;      CONDITIONAL TRAPS
1182 ;;  ....................
1185 (define_insn "trap"
1186   [(trap_if (const_int 1) (const_int 0))]
1187   ""
1189   if (ISA_HAS_COND_TRAP)
1190     return "teq\t$0,$0";
1191   else if (TARGET_MIPS16)
1192     return "break 0";
1193   else
1194     return "break";
1196   [(set_attr "type" "trap")])
1198 (define_expand "ctrap<mode>4"
1199   [(trap_if (match_operator 0 "comparison_operator"
1200                             [(match_operand:GPR 1 "reg_or_0_operand")
1201                              (match_operand:GPR 2 "arith_operand")])
1202             (match_operand 3 "const_0_operand"))]
1203   "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1205   mips_expand_conditional_trap (operands[0]);
1206   DONE;
1209 (define_insn "*conditional_trap_reg<mode>"
1210   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1211                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1212                                  (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1213             (const_int 0))]
1214   "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1215   "t%C0\t%z1,%2"
1216   [(set_attr "type" "trap")])
1218 (define_insn "*conditional_trap<mode>"
1219   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1220                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1221                                  (match_operand:GPR 2 "arith_operand" "dI")])
1222             (const_int 0))]
1223   "ISA_HAS_COND_TRAPI"
1224   "t%C0\t%z1,%2"
1225   [(set_attr "type" "trap")])
1228 ;;  ....................
1230 ;;      ADDITION
1232 ;;  ....................
1235 (define_insn "add<mode>3"
1236   [(set (match_operand:ANYF 0 "register_operand" "=f")
1237         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1238                    (match_operand:ANYF 2 "register_operand" "f")))]
1239   ""
1240   "add.<fmt>\t%0,%1,%2"
1241   [(set_attr "type" "fadd")
1242    (set_attr "mode" "<UNITMODE>")])
1244 (define_expand "add<mode>3"
1245   [(set (match_operand:GPR 0 "register_operand")
1246         (plus:GPR (match_operand:GPR 1 "register_operand")
1247                   (match_operand:GPR 2 "arith_operand")))]
1248   "")
1250 (define_insn "*add<mode>3"
1251   [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1252         (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1253                   (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1254   "!TARGET_MIPS16"
1256   if (which_alternative == 0 
1257       || which_alternative == 1)
1258     return "<d>addu\t%0,%1,%2";
1259   else
1260     return "<d>addiu\t%0,%1,%2";
1262   [(set_attr "alu_type" "add")
1263    (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1264    (set_attr "mode" "<MODE>")])
1266 (define_insn "*add<mode>3_mips16"
1267   [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1268         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1269                   (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1270   "TARGET_MIPS16"
1271   "@
1272     <d>addiu\t%0,%2
1273     <d>addiu\t%0,%2
1274     <d>addiu\t%0,%1,%2
1275     <d>addiu\t%0,%1,%2
1276     <d>addiu\t%0,%2
1277     <d>addiu\t%0,%2
1278     <d>addiu\t%0,%1,%2
1279     <d>addiu\t%0,%1,%2
1280     <d>addu\t%0,%1,%2"
1281   [(set_attr "alu_type" "add")
1282    (set_attr "mode" "<MODE>")
1283    (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1285 ;; On the mips16, we can sometimes split an add of a constant which is
1286 ;; a 4 byte instruction into two adds which are both 2 byte
1287 ;; instructions.  There are two cases: one where we are adding a
1288 ;; constant plus a register to another register, and one where we are
1289 ;; simply adding a constant to a register.
1291 (define_split
1292   [(set (match_operand:SI 0 "d_operand")
1293         (plus:SI (match_dup 0)
1294                  (match_operand:SI 1 "const_int_operand")))]
1295   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1296    && ((INTVAL (operands[1]) > 0x7f
1297         && INTVAL (operands[1]) <= 0x7f + 0x7f)
1298        || (INTVAL (operands[1]) < - 0x80
1299            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1300   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1301    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1303   HOST_WIDE_INT val = INTVAL (operands[1]);
1305   if (val >= 0)
1306     {
1307       operands[1] = GEN_INT (0x7f);
1308       operands[2] = GEN_INT (val - 0x7f);
1309     }
1310   else
1311     {
1312       operands[1] = GEN_INT (- 0x80);
1313       operands[2] = GEN_INT (val + 0x80);
1314     }
1317 (define_split
1318   [(set (match_operand:SI 0 "d_operand")
1319         (plus:SI (match_operand:SI 1 "d_operand")
1320                  (match_operand:SI 2 "const_int_operand")))]
1321   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1322    && REGNO (operands[0]) != REGNO (operands[1])
1323    && ((INTVAL (operands[2]) > 0x7
1324         && INTVAL (operands[2]) <= 0x7 + 0x7f)
1325        || (INTVAL (operands[2]) < - 0x8
1326            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1327   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1328    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1330   HOST_WIDE_INT val = INTVAL (operands[2]);
1332   if (val >= 0)
1333     {
1334       operands[2] = GEN_INT (0x7);
1335       operands[3] = GEN_INT (val - 0x7);
1336     }
1337   else
1338     {
1339       operands[2] = GEN_INT (- 0x8);
1340       operands[3] = GEN_INT (val + 0x8);
1341     }
1344 (define_split
1345   [(set (match_operand:DI 0 "d_operand")
1346         (plus:DI (match_dup 0)
1347                  (match_operand:DI 1 "const_int_operand")))]
1348   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1349    && ((INTVAL (operands[1]) > 0xf
1350         && INTVAL (operands[1]) <= 0xf + 0xf)
1351        || (INTVAL (operands[1]) < - 0x10
1352            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1353   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1354    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1356   HOST_WIDE_INT val = INTVAL (operands[1]);
1358   if (val >= 0)
1359     {
1360       operands[1] = GEN_INT (0xf);
1361       operands[2] = GEN_INT (val - 0xf);
1362     }
1363   else
1364     {
1365       operands[1] = GEN_INT (- 0x10);
1366       operands[2] = GEN_INT (val + 0x10);
1367     }
1370 (define_split
1371   [(set (match_operand:DI 0 "d_operand")
1372         (plus:DI (match_operand:DI 1 "d_operand")
1373                  (match_operand:DI 2 "const_int_operand")))]
1374   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1375    && REGNO (operands[0]) != REGNO (operands[1])
1376    && ((INTVAL (operands[2]) > 0x7
1377         && INTVAL (operands[2]) <= 0x7 + 0xf)
1378        || (INTVAL (operands[2]) < - 0x8
1379            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1380   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1381    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1383   HOST_WIDE_INT val = INTVAL (operands[2]);
1385   if (val >= 0)
1386     {
1387       operands[2] = GEN_INT (0x7);
1388       operands[3] = GEN_INT (val - 0x7);
1389     }
1390   else
1391     {
1392       operands[2] = GEN_INT (- 0x8);
1393       operands[3] = GEN_INT (val + 0x8);
1394     }
1397 (define_insn "*addsi3_extended"
1398   [(set (match_operand:DI 0 "register_operand" "=d,d")
1399         (sign_extend:DI
1400              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1401                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
1402   "TARGET_64BIT && !TARGET_MIPS16"
1403   "@
1404     addu\t%0,%1,%2
1405     addiu\t%0,%1,%2"
1406   [(set_attr "alu_type" "add")
1407    (set_attr "mode" "SI")])
1409 ;; Split this insn so that the addiu splitters can have a crack at it.
1410 ;; Use a conservative length estimate until the split.
1411 (define_insn_and_split "*addsi3_extended_mips16"
1412   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1413         (sign_extend:DI
1414              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1415                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1416   "TARGET_64BIT && TARGET_MIPS16"
1417   "#"
1418   "&& reload_completed"
1419   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1420   { operands[3] = gen_lowpart (SImode, operands[0]); }
1421   [(set_attr "alu_type" "add")
1422    (set_attr "mode" "SI")
1423    (set_attr "extended_mips16" "yes")])
1425 ;; Combiner patterns for unsigned byte-add.
1427 (define_insn "*baddu_si_eb"
1428   [(set (match_operand:SI 0 "register_operand" "=d")
1429         (zero_extend:SI
1430          (subreg:QI
1431           (plus:SI (match_operand:SI 1 "register_operand" "d")
1432                    (match_operand:SI 2 "register_operand" "d")) 3)))]
1433   "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1434   "baddu\\t%0,%1,%2"
1435   [(set_attr "alu_type" "add")])
1437 (define_insn "*baddu_si_el"
1438   [(set (match_operand:SI 0 "register_operand" "=d")
1439         (zero_extend:SI
1440          (subreg:QI
1441           (plus:SI (match_operand:SI 1 "register_operand" "d")
1442                    (match_operand:SI 2 "register_operand" "d")) 0)))]
1443   "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1444   "baddu\\t%0,%1,%2"
1445   [(set_attr "alu_type" "add")])
1447 (define_insn "*baddu_di<mode>"
1448   [(set (match_operand:GPR 0 "register_operand" "=d")
1449         (zero_extend:GPR
1450          (truncate:QI
1451           (plus:DI (match_operand:DI 1 "register_operand" "d")
1452                    (match_operand:DI 2 "register_operand" "d")))))]
1453   "ISA_HAS_BADDU && TARGET_64BIT"
1454   "baddu\\t%0,%1,%2"
1455   [(set_attr "alu_type" "add")])
1458 ;;  ....................
1460 ;;      SUBTRACTION
1462 ;;  ....................
1465 (define_insn "sub<mode>3"
1466   [(set (match_operand:ANYF 0 "register_operand" "=f")
1467         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1468                     (match_operand:ANYF 2 "register_operand" "f")))]
1469   ""
1470   "sub.<fmt>\t%0,%1,%2"
1471   [(set_attr "type" "fadd")
1472    (set_attr "mode" "<UNITMODE>")])
1474 (define_insn "sub<mode>3"
1475   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1476         (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1477                    (match_operand:GPR 2 "register_operand" "!u,d")))]
1478   ""
1479   "<d>subu\t%0,%1,%2"
1480   [(set_attr "alu_type" "sub")
1481    (set_attr "compression" "micromips32,*")
1482    (set_attr "mode" "<MODE>")])
1484 (define_insn "*subsi3_extended"
1485   [(set (match_operand:DI 0 "register_operand" "=d")
1486         (sign_extend:DI
1487             (minus:SI (match_operand:SI 1 "register_operand" "d")
1488                       (match_operand:SI 2 "register_operand" "d"))))]
1489   "TARGET_64BIT"
1490   "subu\t%0,%1,%2"
1491   [(set_attr "alu_type" "sub")
1492    (set_attr "mode" "DI")])
1495 ;;  ....................
1497 ;;      MULTIPLICATION
1499 ;;  ....................
1502 (define_expand "mul<mode>3"
1503   [(set (match_operand:SCALARF 0 "register_operand")
1504         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1505                       (match_operand:SCALARF 2 "register_operand")))]
1506   ""
1507   "")
1509 (define_insn "*mul<mode>3"
1510   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1511         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1512                       (match_operand:SCALARF 2 "register_operand" "f")))]
1513   "!TARGET_4300_MUL_FIX"
1514   "mul.<fmt>\t%0,%1,%2"
1515   [(set_attr "type" "fmul")
1516    (set_attr "mode" "<MODE>")])
1518 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1519 ;; operands may corrupt immediately following multiplies. This is a
1520 ;; simple fix to insert NOPs.
1522 (define_insn "*mul<mode>3_r4300"
1523   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1524         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1525                       (match_operand:SCALARF 2 "register_operand" "f")))]
1526   "TARGET_4300_MUL_FIX"
1527   "mul.<fmt>\t%0,%1,%2\;nop"
1528   [(set_attr "type" "fmul")
1529    (set_attr "mode" "<MODE>")
1530    (set_attr "insn_count" "2")])
1532 (define_insn "mulv2sf3"
1533   [(set (match_operand:V2SF 0 "register_operand" "=f")
1534         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1535                    (match_operand:V2SF 2 "register_operand" "f")))]
1536   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1537   "mul.ps\t%0,%1,%2"
1538   [(set_attr "type" "fmul")
1539    (set_attr "mode" "SF")])
1541 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1542 ;; shift executes while an integer multiplication is in progress, the
1543 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1544 ;; with the mult on the R4000.
1546 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1547 ;; (also valid for MIPS R4000MC processors):
1549 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1550 ;;      this errata description.
1551 ;;      The following code sequence causes the R4000 to incorrectly
1552 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1553 ;;      instruction.  If the dsra32 instruction is executed during an
1554 ;;      integer multiply, the dsra32 will only shift by the amount in
1555 ;;      specified in the instruction rather than the amount plus 32
1556 ;;      bits.
1557 ;;      instruction 1:          mult    rs,rt           integer multiply
1558 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1559 ;;                                                      right arithmetic + 32
1560 ;;      Workaround: A dsra32 instruction placed after an integer
1561 ;;      multiply should not be one of the 11 instructions after the
1562 ;;      multiply instruction."
1564 ;; and:
1566 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1567 ;;      the following description.
1568 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1569 ;;      64-bit versions) may produce incorrect results under the
1570 ;;      following conditions:
1571 ;;      1) An integer multiply is currently executing
1572 ;;      2) These types of shift instructions are executed immediately
1573 ;;         following an integer divide instruction.
1574 ;;      Workaround:
1575 ;;      1) Make sure no integer multiply is running wihen these
1576 ;;         instruction are executed.  If this cannot be predicted at
1577 ;;         compile time, then insert a "mfhi" to R0 instruction
1578 ;;         immediately after the integer multiply instruction.  This
1579 ;;         will cause the integer multiply to complete before the shift
1580 ;;         is executed.
1581 ;;      2) Separate integer divide and these two classes of shift
1582 ;;         instructions by another instruction or a noop."
1584 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1585 ;; respectively.
1587 (define_expand "mul<mode>3"
1588   [(set (match_operand:GPR 0 "register_operand")
1589         (mult:GPR (match_operand:GPR 1 "register_operand")
1590                   (match_operand:GPR 2 "register_operand")))]
1591   "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1593   rtx lo;
1595   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL)
1596     emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1597                                            operands[2]));
1598   else if (ISA_HAS_<D>MUL3)
1599     emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1600   else if (TARGET_MIPS16)
1601     {
1602       lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1603       emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1604       emit_move_insn (operands[0], lo);
1605     }
1606   else if (TARGET_FIX_R4000)
1607     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1608   else
1609     emit_insn
1610       (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1611   DONE;
1614 (define_insn "mul<mode>3_mul3_nohilo"
1615   [(set (match_operand:GPR 0 "register_operand" "=d")
1616         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1617                   (match_operand:GPR 2 "register_operand" "d")))]
1618   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL"
1620   if (TARGET_LOONGSON_2EF)
1621     return "<d>multu.g\t%0,%1,%2";
1622   else if (TARGET_LOONGSON_3A)
1623     return "gs<d>multu\t%0,%1,%2";
1624   else
1625     return "<d>mul\t%0,%1,%2";
1627   [(set_attr "type" "imul3nc")
1628    (set_attr "mode" "<MODE>")])
1630 (define_insn "mul<mode>3_mul3"
1631   [(set (match_operand:GPR 0 "register_operand" "=d,l")
1632         (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1633                   (match_operand:GPR 2 "register_operand" "d,d")))
1634    (clobber (match_scratch:GPR 3 "=l,X"))]
1635   "ISA_HAS_<D>MUL3"
1637   if (which_alternative == 1)
1638     return "<d>mult\t%1,%2";
1639   if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1640     return "mult\t%0,%1,%2";
1641   return "<d>mul\t%0,%1,%2";
1643   [(set_attr "type" "imul3,imul")
1644    (set_attr "mode" "<MODE>")])
1646 ;; If a register gets allocated to LO, and we spill to memory, the reload
1647 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1648 ;; if it can set the GPR directly.
1650 ;; Operand 0: LO
1651 ;; Operand 1: GPR (1st multiplication operand)
1652 ;; Operand 2: GPR (2nd multiplication operand)
1653 ;; Operand 3: GPR (destination)
1654 (define_peephole2
1655   [(parallel
1656        [(set (match_operand:SI 0 "lo_operand")
1657              (mult:SI (match_operand:SI 1 "d_operand")
1658                       (match_operand:SI 2 "d_operand")))
1659         (clobber (scratch:SI))])
1660    (set (match_operand:SI 3 "d_operand")
1661         (match_dup 0))]
1662   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1663   [(parallel
1664        [(set (match_dup 3)
1665              (mult:SI (match_dup 1)
1666                       (match_dup 2)))
1667         (clobber (match_dup 0))])])
1669 (define_insn "mul<mode>3_internal"
1670   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1671         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1672                   (match_operand:GPR 2 "register_operand" "d")))]
1673   "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1674   "<d>mult\t%1,%2"
1675   [(set_attr "type" "imul")
1676    (set_attr "mode" "<MODE>")])
1678 (define_insn "mul<mode>3_r4000"
1679   [(set (match_operand:GPR 0 "register_operand" "=d")
1680         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1681                   (match_operand:GPR 2 "register_operand" "d")))
1682    (clobber (match_scratch:GPR 3 "=l"))]
1683   "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1684   "<d>mult\t%1,%2\;mflo\t%0"
1685   [(set_attr "type" "imul")
1686    (set_attr "mode" "<MODE>")
1687    (set_attr "insn_count" "2")])
1689 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1690 ;; of "mult; mflo".  They have the same latency, but the first form gives
1691 ;; us an extra cycle to compute the operands.
1693 ;; Operand 0: LO
1694 ;; Operand 1: GPR (1st multiplication operand)
1695 ;; Operand 2: GPR (2nd multiplication operand)
1696 ;; Operand 3: GPR (destination)
1697 (define_peephole2
1698   [(set (match_operand:SI 0 "lo_operand")
1699         (mult:SI (match_operand:SI 1 "d_operand")
1700                  (match_operand:SI 2 "d_operand")))
1701    (set (match_operand:SI 3 "d_operand")
1702         (match_dup 0))]
1703   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1704   [(set (match_dup 0)
1705         (const_int 0))
1706    (parallel
1707        [(set (match_dup 0)
1708              (plus:SI (mult:SI (match_dup 1)
1709                                (match_dup 2))
1710                       (match_dup 0)))
1711         (set (match_dup 3)
1712              (plus:SI (mult:SI (match_dup 1)
1713                                (match_dup 2))
1714                       (match_dup 0)))])])
1716 ;; Multiply-accumulate patterns
1718 ;; This pattern is first matched by combine, which tries to use the
1719 ;; pattern wherever it can.  We don't know until later whether it
1720 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1721 ;; so we need to keep both options open.
1723 ;; The second alternative has a "?" marker because it is generally
1724 ;; one instruction more costly than the first alternative.  This "?"
1725 ;; marker is enough to convey the relative costs to the register
1726 ;; allocator.
1728 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1729 ;; reloads of the other operands, even though operands 4 and 5 need no
1730 ;; copy instructions.  Reload therefore thinks that the second alternative
1731 ;; is two reloads more costly than the first.  We add "*?*?" to the first
1732 ;; alternative as a counterweight.
1734 ;; LRA simulates reload but the cost of reloading scratches is lower
1735 ;; than of the classic reload. For the time being, removing the counterweight
1736 ;; for LRA is more profitable.
1737 (define_insn "*mul_acc_si"
1738   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1739         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1740                           (match_operand:SI 2 "register_operand" "d,d,d"))
1741                  (match_operand:SI 3 "register_operand" "0,0,d")))
1742    (clobber (match_scratch:SI 4 "=X,X,l"))
1743    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1744   "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1745   "@
1746     madd\t%1,%2
1747     madd\t%1,%2
1748     #"
1749   [(set_attr "type"     "imadd")
1750    (set_attr "accum_in" "3")
1751    (set_attr "mode"     "SI")
1752    (set_attr "insn_count" "1,1,2")
1753    (set (attr "enabled")
1754         (cond [(and (eq_attr "alternative" "0")
1755                     (match_test "!mips_lra_flag"))
1756                   (const_string "yes")
1757                (and (eq_attr "alternative" "1")
1758                     (match_test "mips_lra_flag"))
1759                   (const_string "yes")
1760                (eq_attr "alternative" "2")
1761                   (const_string "yes")]
1762               (const_string "no")))])
1764 ;; The same idea applies here.  The middle alternative needs one less
1765 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1766 (define_insn "*mul_acc_si_r3900"
1767   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1768         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1769                           (match_operand:SI 2 "register_operand" "d,d,d,d"))
1770                  (match_operand:SI 3 "register_operand" "0,0,l,d")))
1771    (clobber (match_scratch:SI 4 "=X,X,3,l"))
1772    (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1773   "TARGET_MIPS3900 && !TARGET_MIPS16"
1774   "@
1775     madd\t%1,%2
1776     madd\t%1,%2
1777     madd\t%0,%1,%2
1778     #"
1779   [(set_attr "type"     "imadd")
1780    (set_attr "accum_in" "3")
1781    (set_attr "mode"     "SI")
1782    (set_attr "insn_count" "1,1,1,2")
1783    (set (attr "enabled")
1784         (cond [(and (eq_attr "alternative" "0")
1785                     (match_test "!mips_lra_flag"))
1786                   (const_string "yes")
1787                (and (eq_attr "alternative" "1")
1788                     (match_test "mips_lra_flag"))
1789                   (const_string "yes")
1790                (eq_attr "alternative" "2,3")
1791                   (const_string "yes")]
1792               (const_string "no")))])
1794 ;; Split *mul_acc_si if both the source and destination accumulator
1795 ;; values are GPRs.
1796 (define_split
1797   [(set (match_operand:SI 0 "d_operand")
1798         (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1799                           (match_operand:SI 2 "d_operand"))
1800                  (match_operand:SI 3 "d_operand")))
1801    (clobber (match_operand:SI 4 "lo_operand"))
1802    (clobber (match_operand:SI 5 "d_operand"))]
1803   "reload_completed"
1804   [(parallel [(set (match_dup 5)
1805                    (mult:SI (match_dup 1) (match_dup 2)))
1806               (clobber (match_dup 4))])
1807    (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1808   "")
1810 (define_insn "*macc"
1811   [(set (match_operand:SI 0 "register_operand" "=l,d")
1812         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1813                           (match_operand:SI 2 "register_operand" "d,d"))
1814                  (match_operand:SI 3 "register_operand" "0,l")))
1815    (clobber (match_scratch:SI 4 "=X,3"))]
1816   "ISA_HAS_MACC"
1818   if (which_alternative == 1)
1819     return "macc\t%0,%1,%2";
1820   else if (TARGET_MIPS5500)
1821     return "madd\t%1,%2";
1822   else
1823     /* The VR4130 assumes that there is a two-cycle latency between a macc
1824        that "writes" to $0 and an instruction that reads from it.  We avoid
1825        this by assigning to $1 instead.  */
1826     return "%[macc\t%@,%1,%2%]";
1828   [(set_attr "type" "imadd")
1829    (set_attr "accum_in" "3")
1830    (set_attr "mode" "SI")])
1832 (define_insn "*msac"
1833   [(set (match_operand:SI 0 "register_operand" "=l,d")
1834         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1835                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1836                            (match_operand:SI 3 "register_operand" "d,d"))))
1837    (clobber (match_scratch:SI 4 "=X,1"))]
1838   "ISA_HAS_MSAC"
1840   if (which_alternative == 1)
1841     return "msac\t%0,%2,%3";
1842   else if (TARGET_MIPS5500)
1843     return "msub\t%2,%3";
1844   else
1845     return "msac\t$0,%2,%3";
1847   [(set_attr "type"     "imadd")
1848    (set_attr "accum_in" "1")
1849    (set_attr "mode"     "SI")])
1851 ;; An msac-like instruction implemented using negation and a macc.
1852 (define_insn_and_split "*msac_using_macc"
1853   [(set (match_operand:SI 0 "register_operand" "=l,d")
1854         (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1855                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1856                            (match_operand:SI 3 "register_operand" "d,d"))))
1857    (clobber (match_scratch:SI 4 "=X,1"))
1858    (clobber (match_scratch:SI 5 "=d,d"))]
1859   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1860   "#"
1861   "&& reload_completed"
1862   [(set (match_dup 5)
1863         (neg:SI (match_dup 3)))
1864    (parallel
1865        [(set (match_dup 0)
1866              (plus:SI (mult:SI (match_dup 2)
1867                                (match_dup 5))
1868                       (match_dup 1)))
1869         (clobber (match_dup 4))])]
1870   ""
1871   [(set_attr "type"     "imadd")
1872    (set_attr "accum_in" "1")
1873    (set_attr "insn_count" "2")])
1875 ;; Patterns generated by the define_peephole2 below.
1877 (define_insn "*macc2"
1878   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1879         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1880                           (match_operand:SI 2 "register_operand" "d"))
1881                  (match_dup 0)))
1882    (set (match_operand:SI 3 "register_operand" "=d")
1883         (plus:SI (mult:SI (match_dup 1)
1884                           (match_dup 2))
1885                  (match_dup 0)))]
1886   "ISA_HAS_MACC && reload_completed"
1887   "macc\t%3,%1,%2"
1888   [(set_attr "type"     "imadd")
1889    (set_attr "accum_in" "0")
1890    (set_attr "mode"     "SI")])
1892 (define_insn "*msac2"
1893   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1894         (minus:SI (match_dup 0)
1895                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1896                            (match_operand:SI 2 "register_operand" "d"))))
1897    (set (match_operand:SI 3 "register_operand" "=d")
1898         (minus:SI (match_dup 0)
1899                   (mult:SI (match_dup 1)
1900                            (match_dup 2))))]
1901   "ISA_HAS_MSAC && reload_completed"
1902   "msac\t%3,%1,%2"
1903   [(set_attr "type"     "imadd")
1904    (set_attr "accum_in" "0")
1905    (set_attr "mode"     "SI")])
1907 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1908 ;; Similarly msac.
1910 ;; Operand 0: LO
1911 ;; Operand 1: macc/msac
1912 ;; Operand 2: GPR (destination)
1913 (define_peephole2
1914   [(parallel
1915        [(set (match_operand:SI 0 "lo_operand")
1916              (match_operand:SI 1 "macc_msac_operand"))
1917         (clobber (scratch:SI))])
1918    (set (match_operand:SI 2 "d_operand")
1919         (match_dup 0))]
1920   ""
1921   [(parallel [(set (match_dup 0)
1922                    (match_dup 1))
1923               (set (match_dup 2)
1924                    (match_dup 1))])])
1926 ;; When we have a three-address multiplication instruction, it should
1927 ;; be faster to do a separate multiply and add, rather than moving
1928 ;; something into LO in order to use a macc instruction.
1930 ;; This peephole needs a scratch register to cater for the case when one
1931 ;; of the multiplication operands is the same as the destination.
1933 ;; Operand 0: GPR (scratch)
1934 ;; Operand 1: LO
1935 ;; Operand 2: GPR (addend)
1936 ;; Operand 3: GPR (destination)
1937 ;; Operand 4: macc/msac
1938 ;; Operand 5: new multiplication
1939 ;; Operand 6: new addition/subtraction
1940 (define_peephole2
1941   [(match_scratch:SI 0 "d")
1942    (set (match_operand:SI 1 "lo_operand")
1943         (match_operand:SI 2 "d_operand"))
1944    (match_dup 0)
1945    (parallel
1946        [(set (match_operand:SI 3 "d_operand")
1947              (match_operand:SI 4 "macc_msac_operand"))
1948         (clobber (match_dup 1))])]
1949   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1950   [(parallel [(set (match_dup 0)
1951                    (match_dup 5))
1952               (clobber (match_dup 1))])
1953    (set (match_dup 3)
1954         (match_dup 6))]
1956   operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1957   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1958                                 operands[2], operands[0]);
1961 ;; Same as above, except LO is the initial target of the macc.
1963 ;; Operand 0: GPR (scratch)
1964 ;; Operand 1: LO
1965 ;; Operand 2: GPR (addend)
1966 ;; Operand 3: macc/msac
1967 ;; Operand 4: GPR (destination)
1968 ;; Operand 5: new multiplication
1969 ;; Operand 6: new addition/subtraction
1970 (define_peephole2
1971   [(match_scratch:SI 0 "d")
1972    (set (match_operand:SI 1 "lo_operand")
1973         (match_operand:SI 2 "d_operand"))
1974    (match_dup 0)
1975    (parallel
1976        [(set (match_dup 1)
1977              (match_operand:SI 3 "macc_msac_operand"))
1978         (clobber (scratch:SI))])
1979    (match_dup 0)
1980    (set (match_operand:SI 4 "d_operand")
1981         (match_dup 1))]
1982   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1983   [(parallel [(set (match_dup 0)
1984                    (match_dup 5))
1985               (clobber (match_dup 1))])
1986    (set (match_dup 4)
1987         (match_dup 6))]
1989   operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1990   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1991                                 operands[2], operands[0]);
1994 ;; See the comment above *mul_add_si for details.
1995 (define_insn "*mul_sub_si"
1996   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1997         (minus:SI (match_operand:SI 1 "register_operand" "0,0,d")
1998                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1999                            (match_operand:SI 3 "register_operand" "d,d,d"))))
2000    (clobber (match_scratch:SI 4 "=X,X,l"))
2001    (clobber (match_scratch:SI 5 "=X,X,&d"))]
2002   "GENERATE_MADD_MSUB"
2003   "@
2004    msub\t%2,%3
2005    msub\t%2,%3
2006    #"
2007   [(set_attr "type"     "imadd")
2008    (set_attr "accum_in" "1")
2009    (set_attr "mode"     "SI")
2010    (set_attr "insn_count" "1,1,2")
2011    (set (attr "enabled")
2012         (cond [(and (eq_attr "alternative" "0")
2013                     (match_test "!mips_lra_flag"))
2014                   (const_string "yes")
2015                (and (eq_attr "alternative" "1")
2016                     (match_test "mips_lra_flag"))
2017                   (const_string "yes")
2018                (eq_attr "alternative" "2")
2019                   (const_string "yes")]
2020               (const_string "no")))])
2022 ;; Split *mul_sub_si if both the source and destination accumulator
2023 ;; values are GPRs.
2024 (define_split
2025   [(set (match_operand:SI 0 "d_operand")
2026         (minus:SI (match_operand:SI 1 "d_operand")
2027                   (mult:SI (match_operand:SI 2 "d_operand")
2028                            (match_operand:SI 3 "d_operand"))))
2029    (clobber (match_operand:SI 4 "lo_operand"))
2030    (clobber (match_operand:SI 5 "d_operand"))]
2031   "reload_completed"
2032   [(parallel [(set (match_dup 5)
2033                    (mult:SI (match_dup 2) (match_dup 3)))
2034               (clobber (match_dup 4))])
2035    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
2036   "")
2038 (define_insn "*muls"
2039   [(set (match_operand:SI 0 "register_operand" "=l,d")
2040         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2041                          (match_operand:SI 2 "register_operand" "d,d"))))
2042    (clobber (match_scratch:SI 3 "=X,l"))]
2043   "ISA_HAS_MULS"
2044   "@
2045    muls\t$0,%1,%2
2046    muls\t%0,%1,%2"
2047   [(set_attr "type"     "imul,imul3")
2048    (set_attr "mode"     "SI")])
2050 (define_expand "<u>mulsidi3"
2051   [(set (match_operand:DI 0 "register_operand")
2052         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2053                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2054   "mips_mulsidi3_gen_fn (<CODE>) != NULL"
2056   mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
2057   emit_insn (fn (operands[0], operands[1], operands[2]));
2058   DONE;
2061 (define_expand "<u>mulsidi3_32bit_r6"
2062   [(set (match_operand:DI 0 "register_operand")
2063         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2064                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2065   "!TARGET_64BIT && ISA_HAS_R6MUL"
2067   rtx dest = gen_reg_rtx (DImode);
2068   rtx low = mips_subword (dest, 0);
2069   rtx high = mips_subword (dest, 1);
2071   emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2072   emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2074   emit_move_insn (mips_subword (operands[0], 0), low);
2075   emit_move_insn (mips_subword (operands[0], 1), high);
2076   DONE;
2079 (define_expand "<u>mulsidi3_32bit_mips16"
2080   [(set (match_operand:DI 0 "register_operand")
2081         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2082                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2083   "!TARGET_64BIT && TARGET_MIPS16"
2085   rtx hilo;
2087   hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2088   emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2089   emit_move_insn (operands[0], hilo);
2090   DONE;
2093 ;; As well as being named patterns, these instructions are used by the
2094 ;; __builtin_mips_mult<u>() functions.  We must always make those functions
2095 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2096 (define_insn "<u>mulsidi3_32bit"
2097   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2098         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2099                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2100   "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2102   if (ISA_HAS_DSP_MULT)
2103     return "mult<u>\t%q0,%1,%2";
2104   else
2105     return "mult<u>\t%1,%2";
2107   [(set_attr "type" "imul")
2108    (set_attr "mode" "SI")])
2110 (define_insn "<u>mulsidi3_32bit_r4000"
2111   [(set (match_operand:DI 0 "register_operand" "=d")
2112         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2113                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2114    (clobber (match_scratch:DI 3 "=x"))]
2115   "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2116   "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2117   [(set_attr "type" "imul")
2118    (set_attr "mode" "SI")
2119    (set_attr "insn_count" "3")])
2121 (define_insn_and_split "<u>mulsidi3_64bit"
2122   [(set (match_operand:DI 0 "register_operand" "=d")
2123         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2124                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2125    (clobber (match_scratch:TI 3 "=x"))
2126    (clobber (match_scratch:DI 4 "=d"))]
2127   "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2128    && !TARGET_MIPS16 && ISA_HAS_MULT"
2129   "#"
2130   "&& reload_completed"
2131   [(const_int 0)]
2133   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2134                                           operands[2], operands[4]));
2135   DONE;
2137   [(set_attr "type" "imul")
2138    (set_attr "mode" "SI")
2139    (set (attr "insn_count")
2140         (if_then_else (match_test "ISA_HAS_EXT_INS")
2141                       (const_int 4)
2142                       (const_int 7)))])
2144 (define_expand "<u>mulsidi3_64bit_mips16"
2145   [(set (match_operand:DI 0 "register_operand")
2146         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2147                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2148   "TARGET_64BIT && TARGET_MIPS16"
2150   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2151                                           operands[2], gen_reg_rtx (DImode)));
2152   DONE;
2155 (define_expand "<u>mulsidi3_64bit_split"
2156   [(set (match_operand:DI 0 "register_operand")
2157         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2158                  (any_extend:DI (match_operand:SI 2 "register_operand"))))
2159    (clobber (match_operand:DI 3 "register_operand"))]
2160   ""
2162   rtx hilo;
2164   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2165   emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2167   emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2168   emit_insn (gen_mfhidi_ti (operands[3], hilo));
2170   if (ISA_HAS_EXT_INS)
2171     emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2172                            operands[3]));
2173   else
2174     {
2175       /* Zero-extend the low part.  */
2176       mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2177       mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2179       /* Shift the high part into place.  */
2180       mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2182       /* OR the two halves together.  */
2183       mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2184     }
2185   DONE;
2188 (define_insn "<u>mulsidi3_64bit_hilo"
2189   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2190         (unspec:TI
2191           [(mult:DI
2192              (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2193              (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2194           UNSPEC_SET_HILO))]
2195   "TARGET_64BIT && !TARGET_FIX_R4000"
2196   "mult<u>\t%1,%2"
2197   [(set_attr "type" "imul")
2198    (set_attr "mode" "SI")])
2200 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2201 (define_insn "mulsidi3_64bit_dmul"
2202   [(set (match_operand:DI 0 "register_operand" "=d")
2203         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2204                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2205    (clobber (match_scratch:DI 3 "=l"))]
2206   "ISA_HAS_DMUL3"
2207   "dmul\t%0,%1,%2"
2208   [(set_attr "type" "imul3")
2209    (set_attr "mode" "DI")])
2211 (define_insn "mulsidi3_64bit_r6dmul"
2212   [(set (match_operand:DI 0 "register_operand" "=d")
2213         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2214                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2215   "ISA_HAS_R6DMUL"
2216   "dmul\t%0,%1,%2"
2217   [(set_attr "type" "imul3nc")
2218    (set_attr "mode" "DI")])
2220 ;; Widening multiply with negation.
2221 (define_insn "*muls<u>_di"
2222   [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2223         (neg:DI
2224          (mult:DI
2225           (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2226           (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2227   "!TARGET_64BIT && ISA_HAS_MULS"
2228   "muls<u>\t$0,%1,%2"
2229   [(set_attr "type" "imul")
2230    (set_attr "mode" "SI")])
2232 ;; As well as being named patterns, these instructions are used by the
2233 ;; __builtin_mips_msub<u>() functions.  We must always make those functions
2234 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2236 ;; This leads to a slight inconsistency.  We honor any tuning overrides
2237 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2238 ;; even if !ISA_HAS_DSP_MULT.
2239 (define_insn "<u>msubsidi4"
2240   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2241         (minus:DI
2242            (match_operand:DI 3 "muldiv_target_operand" "0")
2243            (mult:DI
2244               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2245               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2246   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2248   if (ISA_HAS_DSP_MULT)
2249     return "msub<u>\t%q0,%1,%2";
2250   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2251     return "msub<u>\t%1,%2";
2252   else
2253     return "msac<u>\t$0,%1,%2";
2255   [(set_attr "type" "imadd")
2256    (set_attr "accum_in" "3")
2257    (set_attr "mode" "SI")])
2259 ;; _highpart patterns
2261 (define_expand "<su>mulsi3_highpart"
2262   [(set (match_operand:SI 0 "register_operand")
2263         (truncate:SI
2264          (lshiftrt:DI
2265           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2266                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2267           (const_int 32))))]
2268   ""
2270   if (ISA_HAS_MULHI)
2271     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2272                                                        operands[1],
2273                                                        operands[2]));
2274   else if (TARGET_MIPS16)
2275     emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2276                                               operands[2]));
2277   else if (ISA_HAS_R6MUL)
2278     emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2279                                            operands[2]));
2280   else
2281     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2282                                                  operands[2]));
2283   DONE;
2286 (define_insn "<su>mulsi3_highpart_r6"
2287   [(set (match_operand:SI 0 "register_operand" "=d")
2288         (truncate:SI
2289          (lshiftrt:DI
2290           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2291                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2292           (const_int 32))))]
2293   "ISA_HAS_R6MUL"
2294   "muh<u>\t%0,%1,%2"
2295   [(set_attr "type" "imul3nc")
2296    (set_attr "mode" "SI")])
2298 (define_insn_and_split "<su>mulsi3_highpart_internal"
2299   [(set (match_operand:SI 0 "register_operand" "=d")
2300         (truncate:SI
2301          (lshiftrt:DI
2302           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2303                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2304           (const_int 32))))
2305    (clobber (match_scratch:SI 3 "=l"))]
2306   "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2307   { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2308   "&& reload_completed && !TARGET_FIX_R4000"
2309   [(const_int 0)]
2311   emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2312                                             operands[2]));
2313   DONE;
2315   [(set_attr "type" "imul")
2316    (set_attr "mode" "SI")
2317    (set_attr "insn_count" "2")])
2319 (define_expand "<su>mulsi3_highpart_split"
2320   [(set (match_operand:SI 0 "register_operand")
2321         (truncate:SI
2322          (lshiftrt:DI
2323           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2324                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2325           (const_int 32))))]
2326   ""
2328   rtx hilo;
2330   if (TARGET_64BIT)
2331     {
2332       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2333       emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2334       emit_insn (gen_mfhisi_ti (operands[0], hilo));
2335     }
2336   else
2337     {
2338       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2339       emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2340       emit_insn (gen_mfhisi_di (operands[0], hilo));
2341     }
2342   DONE;
2345 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2346   [(set (match_operand:SI 0 "register_operand" "=d")
2347         (truncate:SI
2348          (lshiftrt:DI
2349           (mult:DI
2350            (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2351            (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2352           (const_int 32))))
2353    (clobber (match_scratch:SI 3 "=l"))]
2354   "ISA_HAS_MULHI"
2355   "mulhi<u>\t%0,%1,%2"
2356   [(set_attr "type" "imul3")
2357    (set_attr "mode" "SI")])
2359 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2360   [(set (match_operand:SI 0 "register_operand" "=d")
2361         (truncate:SI
2362          (lshiftrt:DI
2363           (neg:DI
2364            (mult:DI
2365             (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2366             (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2367           (const_int 32))))
2368    (clobber (match_scratch:SI 3 "=l"))]
2369   "ISA_HAS_MULHI"
2370   "mulshi<u>\t%0,%1,%2"
2371   [(set_attr "type" "imul3")
2372    (set_attr "mode" "SI")])
2374 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
2375 ;; errata MD(0), which says that dmultu does not always produce the
2376 ;; correct result.
2377 (define_expand "<su>muldi3_highpart"
2378   [(set (match_operand:DI 0 "register_operand")
2379         (truncate:DI
2380          (lshiftrt:TI
2381           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2382                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2383           (const_int 64))))]
2384   "ISA_HAS_R6DMUL
2385    || (ISA_HAS_DMULT
2386        && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2388   if (TARGET_MIPS16)
2389     emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2390                                               operands[2]));
2391   else if (ISA_HAS_R6DMUL)
2392     emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2393                                            operands[2]));
2394   else
2395     emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2396                                                  operands[2]));
2397   DONE;
2400 (define_insn "<su>muldi3_highpart_r6"
2401   [(set (match_operand:DI 0 "register_operand" "=d")
2402         (truncate:DI
2403          (lshiftrt:TI
2404           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2405                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2406           (const_int 64))))]
2407   "ISA_HAS_R6DMUL"
2408   "dmuh<u>\t%0,%1,%2"
2409   [(set_attr "type" "imul3nc")
2410    (set_attr "mode" "DI")])
2412 (define_insn_and_split "<su>muldi3_highpart_internal"
2413   [(set (match_operand:DI 0 "register_operand" "=d")
2414         (truncate:DI
2415          (lshiftrt:TI
2416           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2417                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2418           (const_int 64))))
2419    (clobber (match_scratch:DI 3 "=l"))]
2420   "ISA_HAS_DMULT
2421    && !TARGET_MIPS16
2422    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2423   { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2424   "&& reload_completed && !TARGET_FIX_R4000"
2425   [(const_int 0)]
2427   emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2428                                             operands[2]));
2429   DONE;
2431   [(set_attr "type" "imul")
2432    (set_attr "mode" "DI")
2433    (set_attr "insn_count" "2")])
2435 (define_expand "<su>muldi3_highpart_split"
2436   [(set (match_operand:DI 0 "register_operand")
2437         (truncate:DI
2438          (lshiftrt:TI
2439           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2440                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2441           (const_int 64))))]
2442   ""
2444   rtx hilo;
2446   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2447   emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2448   emit_insn (gen_mfhidi_ti (operands[0], hilo));
2449   DONE;
2452 (define_expand "<u>mulditi3"
2453   [(set (match_operand:TI 0 "register_operand")
2454         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2455                  (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2456   "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2458   rtx hilo;
2460   if (TARGET_MIPS16)
2461     {
2462       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2463       emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2464       emit_move_insn (operands[0], hilo);
2465     }
2466   else if (TARGET_FIX_R4000)
2467     emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2468   else
2469     emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2470                                          operands[2]));
2471   DONE;
2474 (define_insn "<u>mulditi3_internal"
2475   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2476         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2477                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2478   "ISA_HAS_DMULT
2479    && !TARGET_FIX_R4000
2480    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2481   "dmult<u>\t%1,%2"
2482   [(set_attr "type" "imul")
2483    (set_attr "mode" "DI")])
2485 (define_insn "<u>mulditi3_r4000"
2486   [(set (match_operand:TI 0 "register_operand" "=d")
2487         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2488                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2489    (clobber (match_scratch:TI 3 "=x"))]
2490   "ISA_HAS_DMULT
2491    && TARGET_FIX_R4000
2492    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2493   "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2494   [(set_attr "type" "imul")
2495    (set_attr "mode" "DI")
2496    (set_attr "insn_count" "3")])
2498 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2499 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
2501 (define_insn "madsi"
2502   [(set (match_operand:SI 0 "register_operand" "+l")
2503         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2504                           (match_operand:SI 2 "register_operand" "d"))
2505                  (match_dup 0)))]
2506   "TARGET_MAD"
2507   "mad\t%1,%2"
2508   [(set_attr "type"     "imadd")
2509    (set_attr "accum_in" "0")
2510    (set_attr "mode"     "SI")])
2512 ;; See the comment above <u>msubsidi4 for the relationship between
2513 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2514 (define_insn "<u>maddsidi4"
2515   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2516         (plus:DI
2517          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2518                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2519          (match_operand:DI 3 "muldiv_target_operand" "0")))]
2520   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2521    && !TARGET_64BIT"
2523   if (TARGET_MAD)
2524     return "mad<u>\t%1,%2";
2525   else if (ISA_HAS_DSP_MULT)
2526     return "madd<u>\t%q0,%1,%2";
2527   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2528     return "madd<u>\t%1,%2";
2529   else
2530     /* See comment in *macc.  */
2531     return "%[macc<u>\t%@,%1,%2%]";
2533   [(set_attr "type" "imadd")
2534    (set_attr "accum_in" "3")
2535    (set_attr "mode" "SI")])
2537 ;; Floating point multiply accumulate instructions.
2539 (define_expand "fma<mode>4"
2540   [(set (match_operand:ANYF 0 "register_operand")
2541         (fma:ANYF (match_operand:ANYF 1 "register_operand")
2542                   (match_operand:ANYF 2 "register_operand")
2543                   (match_operand:ANYF 3 "register_operand")))]
2544   "ISA_HAS_FUSED_MADDF || ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4")
2546 (define_insn "*fma<mode>4_madd3"
2547   [(set (match_operand:ANYF 0 "register_operand" "=f")
2548         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2549                   (match_operand:ANYF 2 "register_operand" "f")
2550                   (match_operand:ANYF 3 "register_operand" "0")))]
2551   "ISA_HAS_FUSED_MADD3"
2552   "madd.<fmt>\t%0,%1,%2"
2553   [(set_attr "type" "fmadd")
2554    (set_attr "mode" "<UNITMODE>")])
2556 (define_insn "*fma<mode>4_madd4"
2557   [(set (match_operand:ANYF 0 "register_operand" "=f")
2558         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2559                   (match_operand:ANYF 2 "register_operand" "f")
2560                   (match_operand:ANYF 3 "register_operand" "f")))]
2561   "ISA_HAS_FUSED_MADD4"
2562   "madd.<fmt>\t%0,%3,%1,%2"
2563   [(set_attr "type" "fmadd")
2564    (set_attr "mode" "<UNITMODE>")])
2566 (define_insn "*fma<mode>4_maddf"
2567   [(set (match_operand:ANYF 0 "register_operand" "=f")
2568         (fma: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_FUSED_MADDF"
2572   "maddf.<fmt>\t%0,%1,%2"
2573   [(set_attr "type" "fmadd")
2574    (set_attr "mode" "<UNITMODE>")])
2576 ;; The fms, fnma, and fnms instructions can be used even when HONOR_NANS
2577 ;; is true because while IEEE 754-2008 requires the negate operation to
2578 ;; negate the sign of a NAN and the MIPS neg instruction does not do this,
2579 ;; the fma part of the instruction has no requirement on how the sign of
2580 ;; a NAN is handled and so the final sign bit of the entire operation is
2581 ;; undefined.
2583 (define_expand "fms<mode>4"
2584   [(set (match_operand:ANYF 0 "register_operand")
2585         (fma:ANYF (match_operand:ANYF 1 "register_operand")
2586                   (match_operand:ANYF 2 "register_operand")
2587                   (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2588   "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)")
2590 (define_insn "*fms<mode>4_msub3"
2591   [(set (match_operand:ANYF 0 "register_operand" "=f")
2592         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2593                   (match_operand:ANYF 2 "register_operand" "f")
2594                   (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2595   "ISA_HAS_FUSED_MADD3"
2596   "msub.<fmt>\t%0,%1,%2"
2597   [(set_attr "type" "fmadd")
2598    (set_attr "mode" "<UNITMODE>")])
2600 (define_insn "*fms<mode>4_msub4"
2601   [(set (match_operand:ANYF 0 "register_operand" "=f")
2602         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2603                   (match_operand:ANYF 2 "register_operand" "f")
2604                   (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2605   "ISA_HAS_FUSED_MADD4"
2606   "msub.<fmt>\t%0,%3,%1,%2"
2607   [(set_attr "type" "fmadd")
2608    (set_attr "mode" "<UNITMODE>")])
2610 ;; fnma is defined in GCC as (fma (neg op1) op2 op3)
2611 ;; (-op1 * op2) + op3 ==> -(op1 * op2) + op3 ==> -((op1 * op2) - op3)
2612 ;; The mips nmsub instructions implement -((op1 * op2) - op3)
2613 ;; This transformation means we may return the wrong signed zero
2614 ;; so we check HONOR_SIGNED_ZEROS.
2616 (define_expand "fnma<mode>4"
2617   [(set (match_operand:ANYF 0 "register_operand")
2618         (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2619                   (match_operand:ANYF 2 "register_operand")
2620                   (match_operand:ANYF 3 "register_operand")))]
2621   "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2622    && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2624 (define_insn "*fnma<mode>4_nmsub3"
2625   [(set (match_operand:ANYF 0 "register_operand" "=f")
2626         (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2627                   (match_operand:ANYF 2 "register_operand" "f")
2628                   (match_operand:ANYF 3 "register_operand" "0")))]
2629   "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2630   "nmsub.<fmt>\t%0,%1,%2"
2631   [(set_attr "type" "fmadd")
2632    (set_attr "mode" "<UNITMODE>")])
2634 (define_insn "*fnma<mode>4_nmsub4"
2635   [(set (match_operand:ANYF 0 "register_operand" "=f")
2636         (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2637                   (match_operand:ANYF 2 "register_operand" "f")
2638                   (match_operand:ANYF 3 "register_operand" "f")))]
2639   "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2640   "nmsub.<fmt>\t%0,%3,%1,%2"
2641   [(set_attr "type" "fmadd")
2642    (set_attr "mode" "<UNITMODE>")])
2644 ;; fnms is defined as: (fma (neg op1) op2 (neg op3))
2645 ;; ((-op1) * op2) - op3 ==> -(op1 * op2) - op3 ==> -((op1 * op2) + op3)
2646 ;; The mips nmadd instructions implement -((op1 * op2) + op3)
2647 ;; This transformation means we may return the wrong signed zero
2648 ;; so we check HONOR_SIGNED_ZEROS.
2650 (define_expand "fnms<mode>4"
2651   [(set (match_operand:ANYF 0 "register_operand")
2652         (fma:ANYF
2653           (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2654           (match_operand:ANYF 2 "register_operand")
2655           (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2656   "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2657    && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2659 (define_insn "*fnms<mode>4_nmadd3"
2660   [(set (match_operand:ANYF 0 "register_operand" "=f")
2661         (fma:ANYF
2662           (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2663           (match_operand:ANYF 2 "register_operand" "f")
2664           (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2665   "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2666   "nmadd.<fmt>\t%0,%1,%2"
2667   [(set_attr "type" "fmadd")
2668    (set_attr "mode" "<UNITMODE>")])
2670 (define_insn "*fnms<mode>4_nmadd4"
2671   [(set (match_operand:ANYF 0 "register_operand" "=f")
2672         (fma:ANYF
2673           (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2674           (match_operand:ANYF 2 "register_operand" "f")
2675           (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2676   "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2677   "nmadd.<fmt>\t%0,%3,%1,%2"
2678   [(set_attr "type" "fmadd")
2679    (set_attr "mode" "<UNITMODE>")])
2681 ;; Non-fused Floating point multiply accumulate instructions.
2683 ;; These instructions are not fused and round in between the multiply
2684 ;; and the add (or subtract) so they are equivalent to the separate
2685 ;; multiply and add/sub instructions.
2687 (define_insn "*madd4<mode>"
2688   [(set (match_operand:ANYF 0 "register_operand" "=f")
2689         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2690                               (match_operand:ANYF 2 "register_operand" "f"))
2691                    (match_operand:ANYF 3 "register_operand" "f")))]
2692   "ISA_HAS_UNFUSED_MADD4"
2693   "madd.<fmt>\t%0,%3,%1,%2"
2694   [(set_attr "type" "fmadd")
2695    (set_attr "mode" "<UNITMODE>")])
2697 (define_insn "*msub4<mode>"
2698   [(set (match_operand:ANYF 0 "register_operand" "=f")
2699         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2700                                (match_operand:ANYF 2 "register_operand" "f"))
2701                     (match_operand:ANYF 3 "register_operand" "f")))]
2702   "ISA_HAS_UNFUSED_MADD4"
2703   "msub.<fmt>\t%0,%3,%1,%2"
2704   [(set_attr "type" "fmadd")
2705    (set_attr "mode" "<UNITMODE>")])
2707 ;; Like with the fused fms, fnma, and fnms instructions, these unfused
2708 ;; instructions can be used even if HONOR_NANS is set because while
2709 ;; IEEE 754-2008 requires the negate operation to negate the sign of a
2710 ;; NAN and the MIPS neg instruction does not do this, the multiply and
2711 ;; add (or subtract) part of the instruction has no requirement on how
2712 ;; the sign of a NAN is handled and so the final sign bit of the entire
2713 ;; operation is undefined.
2715 (define_insn "*nmadd4<mode>"
2716   [(set (match_operand:ANYF 0 "register_operand" "=f")
2717         (neg:ANYF (plus:ANYF
2718                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2719                               (match_operand:ANYF 2 "register_operand" "f"))
2720                    (match_operand:ANYF 3 "register_operand" "f"))))]
2721   "ISA_HAS_UNFUSED_MADD4"
2722   "nmadd.<fmt>\t%0,%3,%1,%2"
2723   [(set_attr "type" "fmadd")
2724    (set_attr "mode" "<UNITMODE>")])
2726 (define_insn "*nmsub4<mode>"
2727   [(set (match_operand:ANYF 0 "register_operand" "=f")
2728         (neg:ANYF (minus:ANYF
2729                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2730                               (match_operand:ANYF 2 "register_operand" "f"))
2731                    (match_operand:ANYF 3 "register_operand" "f"))))]
2732   "ISA_HAS_UNFUSED_MADD4"
2733   "nmsub.<fmt>\t%0,%3,%1,%2"
2734   [(set_attr "type" "fmadd")
2735    (set_attr "mode" "<UNITMODE>")])
2737 ;; Fast-math Non-fused Floating point multiply accumulate instructions.
2739 ;; These instructions are not fused but the expressions they match are
2740 ;; not exactly what the instruction implements in the sense that they
2741 ;; may not generate the properly signed zeros.
2743 ;; This instruction recognizes  ((-op1) * op2) - op3 and generates an
2744 ;; nmadd which is really -((op1 * op2) + op3).  They are equivalent
2745 ;; except for the sign bit when the result is zero or NaN.
2747 (define_insn "*nmadd4<mode>_fastmath"
2748   [(set (match_operand:ANYF 0 "register_operand" "=f")
2749         (minus:ANYF
2750           (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2751                      (match_operand:ANYF 2 "register_operand" "f"))
2752           (match_operand:ANYF 3 "register_operand" "f")))]
2753   "ISA_HAS_UNFUSED_MADD4
2754    && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2755   "nmadd.<fmt>\t%0,%3,%1,%2"
2756   [(set_attr "type" "fmadd")
2757    (set_attr "mode" "<UNITMODE>")])
2759 ;; This instruction recognizes (op1 - (op2 * op3) and generates an
2760 ;; nmsub which is really -((op2 * op3) - op1).  They are equivalent
2761 ;; except for the sign bit when the result is zero or NaN.
2763 (define_insn "*nmsub4<mode>_fastmath"
2764   [(set (match_operand:ANYF 0 "register_operand" "=f")
2765         (minus:ANYF
2766           (match_operand:ANYF 1 "register_operand" "f")
2767           (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2768                      (match_operand:ANYF 3 "register_operand" "f"))))]
2769   "ISA_HAS_UNFUSED_MADD4
2770    && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2771   "nmsub.<fmt>\t%0,%1,%2,%3"
2772   [(set_attr "type" "fmadd")
2773    (set_attr "mode" "<UNITMODE>")])
2776 ;;  ....................
2778 ;;      DIVISION and REMAINDER
2780 ;;  ....................
2783 (define_expand "div<mode>3"
2784   [(set (match_operand:ANYF 0 "register_operand")
2785         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2786                   (match_operand:ANYF 2 "register_operand")))]
2787   "<divide_condition>"
2789   if (const_1_operand (operands[1], <MODE>mode))
2790     if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2791           && flag_unsafe_math_optimizations))
2792       operands[1] = force_reg (<MODE>mode, operands[1]);
2795 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2797 ;; If an mfc1 or dmfc1 happens to access the floating point register
2798 ;; file at the same time a long latency operation (div, sqrt, recip,
2799 ;; sqrt) iterates an intermediate result back through the floating
2800 ;; point register file bypass, then instead returning the correct
2801 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2802 ;; result of the long latency operation.
2804 ;; The workaround is to insert an unconditional 'mov' from/to the
2805 ;; long latency op destination register.
2807 (define_insn "*div<mode>3"
2808   [(set (match_operand:ANYF 0 "register_operand" "=f")
2809         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2810                   (match_operand:ANYF 2 "register_operand" "f")))]
2811   "<divide_condition>"
2813   if (TARGET_FIX_SB1)
2814     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2815   else
2816     return "div.<fmt>\t%0,%1,%2";
2818   [(set_attr "type" "fdiv")
2819    (set_attr "mode" "<UNITMODE>")
2820    (set (attr "insn_count")
2821         (if_then_else (match_test "TARGET_FIX_SB1")
2822                       (const_int 2)
2823                       (const_int 1)))])
2825 (define_insn "*recip<mode>3"
2826   [(set (match_operand:ANYF 0 "register_operand" "=f")
2827         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2828                   (match_operand:ANYF 2 "register_operand" "f")))]
2829   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2831   if (TARGET_FIX_SB1)
2832     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2833   else
2834     return "recip.<fmt>\t%0,%2";
2836   [(set_attr "type" "frdiv")
2837    (set_attr "mode" "<UNITMODE>")
2838    (set (attr "insn_count")
2839         (if_then_else (match_test "TARGET_FIX_SB1")
2840                       (const_int 2)
2841                       (const_int 1)))])
2843 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2844 ;; with negative operands.  We use special libgcc functions instead.
2845 (define_expand "divmod<mode>4"
2846   [(parallel
2847      [(set (match_operand:GPR 0 "register_operand")
2848            (div:GPR (match_operand:GPR 1 "register_operand")
2849                     (match_operand:GPR 2 "register_operand")))
2850       (set (match_operand:GPR 3 "register_operand")
2851            (mod:GPR (match_dup 1)
2852                     (match_dup 2)))])]
2853   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2855   if (TARGET_MIPS16)
2856     {
2857       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2858       emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2859                                            operands[2], operands[3], lo));
2860       DONE;
2861     }
2864 (define_insn_and_split "*divmod<mode>4"
2865   [(set (match_operand:GPR 0 "register_operand" "=l")
2866         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2867                  (match_operand:GPR 2 "register_operand" "d")))
2868    (set (match_operand:GPR 3 "register_operand" "=d")
2869         (mod:GPR (match_dup 1)
2870                  (match_dup 2)))]
2871   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2872   "#"
2873   "&& reload_completed"
2874   [(const_int 0)]
2876   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2877   DONE;
2879  [(set_attr "type" "idiv")
2880   (set_attr "mode" "<MODE>")
2881   (set_attr "insn_count" "2")])
2883 ;; Expand generates divmod instructions for individual division and modulus
2884 ;; operations.  We then rely on CSE to reuse earlier divmods where possible.
2885 ;; This means that, when generating MIPS16 code, it is better not to expose
2886 ;; the fixed LO register until after CSE has finished.  However, it's still
2887 ;; better to split before register allocation, so that we don't allocate
2888 ;; one of the scarce MIPS16 registers to an unused result.
2889 (define_insn_and_split "divmod<mode>4_mips16"
2890   [(set (match_operand:GPR 0 "register_operand" "=d")
2891         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2892                  (match_operand:GPR 2 "register_operand" "d")))
2893    (set (match_operand:GPR 3 "register_operand" "=d")
2894         (mod:GPR (match_dup 1)
2895                  (match_dup 2)))
2896    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2897   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2898   "#"
2899   "&& cse_not_expected"
2900   [(const_int 0)]
2902   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2903   emit_move_insn (operands[0], operands[4]);
2904   DONE;
2906  [(set_attr "type" "idiv")
2907   (set_attr "mode" "<MODE>")
2908   (set_attr "insn_count" "3")])
2910 (define_expand "udivmod<mode>4"
2911   [(parallel
2912      [(set (match_operand:GPR 0 "register_operand")
2913            (udiv:GPR (match_operand:GPR 1 "register_operand")
2914                      (match_operand:GPR 2 "register_operand")))
2915       (set (match_operand:GPR 3 "register_operand")
2916            (umod:GPR (match_dup 1)
2917                      (match_dup 2)))])]
2918   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2920   if (TARGET_MIPS16)
2921     {
2922       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2923       emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2924                                             operands[2], operands[3], lo));
2925       DONE;
2926     }
2929 (define_insn_and_split "*udivmod<mode>4"
2930   [(set (match_operand:GPR 0 "register_operand" "=l")
2931         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2932                   (match_operand:GPR 2 "register_operand" "d")))
2933    (set (match_operand:GPR 3 "register_operand" "=d")
2934         (umod:GPR (match_dup 1)
2935                   (match_dup 2)))]
2936   "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2937   "#"
2938   "reload_completed"
2939   [(const_int 0)]
2941   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2942   DONE;
2944   [(set_attr "type" "idiv")
2945    (set_attr "mode" "<MODE>")
2946    (set_attr "insn_count" "2")])
2948 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2949 (define_insn_and_split "udivmod<mode>4_mips16"
2950   [(set (match_operand:GPR 0 "register_operand" "=d")
2951         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2952                   (match_operand:GPR 2 "register_operand" "d")))
2953    (set (match_operand:GPR 3 "register_operand" "=d")
2954         (umod:GPR (match_dup 1)
2955                   (match_dup 2)))
2956    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2957   "ISA_HAS_<D>DIV && TARGET_MIPS16"
2958   "#"
2959   "cse_not_expected"
2960   [(const_int 0)]
2962   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2963   emit_move_insn (operands[0], operands[4]);
2964   DONE;
2966   [(set_attr "type" "idiv")
2967    (set_attr "mode" "<MODE>")
2968    (set_attr "insn_count" "3")])
2970 (define_expand "<u>divmod<mode>4_split"
2971   [(set (match_operand:GPR 0 "register_operand")
2972         (any_mod:GPR (match_operand:GPR 1 "register_operand")
2973                      (match_operand:GPR 2 "register_operand")))]
2974   ""
2976   rtx hilo;
2978   if (TARGET_64BIT)
2979     {
2980       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2981       emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2982                                                operands[2]));
2983       emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2984     }
2985   else
2986     {
2987       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2988       emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2989                                                operands[2]));
2990       emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2991     }
2992   DONE;
2995 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2996   [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2997         (unspec:HILO
2998           [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2999                         (match_operand:GPR 2 "register_operand" "d"))]
3000           UNSPEC_SET_HILO))]
3001   "ISA_HAS_<GPR:D>DIV"
3002   { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
3003   [(set_attr "type" "idiv")
3004    (set_attr "mode" "<GPR:MODE>")])
3006 ;; Integer division and modulus.
3008 (define_insn "<u>div<mode>3"
3009   [(set (match_operand:GPR 0 "register_operand" "=&d")
3010         (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3011                      (match_operand:GPR 2 "register_operand" "d")))]
3012   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
3013   {
3014     if (TARGET_LOONGSON_2EF)
3015       return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
3016     else if (TARGET_LOONGSON_3A)
3017       return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
3018     else
3019       return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
3020   }
3021   [(set_attr "type" "idiv3")
3022    (set_attr "mode" "<MODE>")])
3024 (define_insn "<u>mod<mode>3"
3025   [(set (match_operand:GPR 0 "register_operand" "=&d")
3026         (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
3027                      (match_operand:GPR 2 "register_operand" "d")))]
3028   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
3029   {
3030     if (TARGET_LOONGSON_2EF)
3031       return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
3032     else if (TARGET_LOONGSON_3A)
3033       return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
3034     else
3035       return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
3036   }
3037   [(set_attr "type" "idiv3")
3038    (set_attr "mode" "<MODE>")])
3041 ;;  ....................
3043 ;;      SQUARE ROOT
3045 ;;  ....................
3047 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
3048 ;; "*div[sd]f3" comment for details).
3050 (define_insn "sqrt<mode>2"
3051   [(set (match_operand:ANYF 0 "register_operand" "=f")
3052         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3053   "<sqrt_condition>"
3055   if (TARGET_FIX_SB1)
3056     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
3057   else
3058     return "sqrt.<fmt>\t%0,%1";
3060   [(set_attr "type" "fsqrt")
3061    (set_attr "mode" "<UNITMODE>")
3062    (set (attr "insn_count")
3063         (if_then_else (match_test "TARGET_FIX_SB1")
3064                       (const_int 2)
3065                       (const_int 1)))])
3067 (define_insn "*rsqrt<mode>a"
3068   [(set (match_operand:ANYF 0 "register_operand" "=f")
3069         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3070                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
3071   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3073   if (TARGET_FIX_SB1)
3074     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3075   else
3076     return "rsqrt.<fmt>\t%0,%2";
3078   [(set_attr "type" "frsqrt")
3079    (set_attr "mode" "<UNITMODE>")
3080    (set (attr "insn_count")
3081         (if_then_else (match_test "TARGET_FIX_SB1")
3082                       (const_int 2)
3083                       (const_int 1)))])
3085 (define_insn "*rsqrt<mode>b"
3086   [(set (match_operand:ANYF 0 "register_operand" "=f")
3087         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3088                              (match_operand:ANYF 2 "register_operand" "f"))))]
3089   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3091   if (TARGET_FIX_SB1)
3092     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3093   else
3094     return "rsqrt.<fmt>\t%0,%2";
3096   [(set_attr "type" "frsqrt")
3097    (set_attr "mode" "<UNITMODE>")
3098    (set (attr "insn_count")
3099         (if_then_else (match_test "TARGET_FIX_SB1")
3100                       (const_int 2)
3101                       (const_int 1)))])
3104 ;;  ....................
3106 ;;      ABSOLUTE VALUE
3108 ;;  ....................
3110 ;; Do not use the integer abs macro instruction, since that signals an
3111 ;; exception on -2147483648 (sigh).
3113 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
3114 ;; instruction that treats all NaN inputs as invalid; it does not clear
3115 ;; their sign bit.  We therefore can't use that form if the signs of
3116 ;; NaNs matter.
3118 (define_insn "abs<mode>2"
3119   [(set (match_operand:ANYF 0 "register_operand" "=f")
3120         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3121   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3122   "abs.<fmt>\t%0,%1"
3123   [(set_attr "type" "fabs")
3124    (set_attr "mode" "<UNITMODE>")])
3127 ;;  ...................
3129 ;;  Count leading zeroes.
3131 ;;  ...................
3134 (define_insn "clz<mode>2"
3135   [(set (match_operand:GPR 0 "register_operand" "=d")
3136         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3137   "ISA_HAS_CLZ_CLO"
3138   "<d>clz\t%0,%1"
3139   [(set_attr "type" "clz")
3140    (set_attr "mode" "<MODE>")])
3143 ;;  ...................
3145 ;;  Count number of set bits.
3147 ;;  ...................
3150 (define_insn "popcount<mode>2"
3151   [(set (match_operand:GPR 0 "register_operand" "=d")
3152         (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3153   "ISA_HAS_POP"
3154   "<d>pop\t%0,%1"
3155   [(set_attr "type" "pop")
3156    (set_attr "mode" "<MODE>")])
3158 ;; The POP instruction is special as it does not take into account the upper
3159 ;; 32bits and is documented that way.
3160 (define_insn "*popcountdi2_trunc"
3161   [(set (match_operand:SI 0 "register_operand" "=d")
3162        (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3163   "ISA_HAS_POP && TARGET_64BIT"
3164   "pop\t%0,%1"
3165   [(set_attr "type" "pop")
3166    (set_attr "mode" "SI")])
3169 ;;  ....................
3171 ;;      NEGATION and ONE'S COMPLEMENT
3173 ;;  ....................
3175 (define_insn "negsi2"
3176   [(set (match_operand:SI 0 "register_operand" "=d")
3177         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3178   ""
3180   if (TARGET_MIPS16)
3181     return "neg\t%0,%1";
3182   else
3183     return "subu\t%0,%.,%1";
3185   [(set_attr "alu_type" "sub")
3186    (set_attr "mode"     "SI")])
3188 (define_insn "negdi2"
3189   [(set (match_operand:DI 0 "register_operand" "=d")
3190         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3191   "TARGET_64BIT && !TARGET_MIPS16"
3192   "dsubu\t%0,%.,%1"
3193   [(set_attr "alu_type" "sub")
3194    (set_attr "mode"     "DI")])
3196 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3197 ;; instruction that treats all NaN inputs as invalid; it does not flip
3198 ;; their sign bit.  We therefore can't use that form if the signs of
3199 ;; NaNs matter.
3201 (define_insn "neg<mode>2"
3202   [(set (match_operand:ANYF 0 "register_operand" "=f")
3203         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3204   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3205   "neg.<fmt>\t%0,%1"
3206   [(set_attr "type" "fneg")
3207    (set_attr "mode" "<UNITMODE>")])
3209 (define_insn "one_cmpl<mode>2"
3210   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3211         (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3212   ""
3214   if (TARGET_MIPS16)
3215     return "not\t%0,%1";
3216   else
3217     return "nor\t%0,%.,%1";
3219   [(set_attr "alu_type" "not")
3220    (set_attr "compression" "micromips,*")
3221    (set_attr "mode" "<MODE>")])
3224 ;;  ....................
3226 ;;      LOGICAL
3228 ;;  ....................
3231 ;; Many of these instructions use trivial define_expands, because we
3232 ;; want to use a different set of constraints when TARGET_MIPS16.
3234 (define_expand "and<mode>3"
3235   [(set (match_operand:GPR 0 "register_operand")
3236         (and:GPR (match_operand:GPR 1 "register_operand")
3237                  (match_operand:GPR 2 "and_reg_operand")))])
3239 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3240 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
3241 ;; Note that this variant does not trigger for SI mode because we require
3242 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3243 ;; sign-extended SImode value.
3245 ;; These are possible combinations for operand 1 and 2.  The table
3246 ;; includes both MIPS and MIPS16 cases.  (r=register, mem=memory,
3247 ;; 16=MIPS16, x=match, S=split):
3249 ;;     \ op1    r/EXT   r/!EXT  mem   r/16   mem/16
3250 ;;  op2
3252 ;;  andi           x     x
3253 ;;  0xff           x     x       x             x
3254 ;;  0xffff         x     x       x             x
3255 ;;  0xffff_ffff    x     S       x     S       x
3256 ;;  low-bitmask    x
3257 ;;  register       x     x
3258 ;;  register =op1                      x
3260 (define_insn "*and<mode>3"
3261   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3262         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3263                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3264   "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3266   int len;
3268   switch (which_alternative)
3269     {
3270     case 0:
3271       operands[1] = gen_lowpart (QImode, operands[1]);
3272       return "lbu\t%0,%1";
3273     case 1:
3274       operands[1] = gen_lowpart (HImode, operands[1]);
3275       return "lhu\t%0,%1";
3276     case 2:
3277       operands[1] = gen_lowpart (SImode, operands[1]);
3278       return "lwu\t%0,%1";
3279     case 3:
3280     case 4:
3281       return "andi\t%0,%1,%x2";
3282     case 5:
3283       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3284       operands[2] = GEN_INT (len);
3285       return "<d>ext\t%0,%1,0,%2";
3286     case 6:
3287       return "#";
3288     case 7:
3289     case 8:
3290       return "and\t%0,%1,%2";
3291     default:
3292       gcc_unreachable ();
3293     }
3295   [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3296    (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3297    (set_attr "mode" "<MODE>")])
3299 (define_insn "*and<mode>3_mips16"
3300   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3301         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3302                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3303   "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3305   switch (which_alternative)
3306     {
3307     case 0:
3308       operands[1] = gen_lowpart (QImode, operands[1]);
3309       return "lbu\t%0,%1";
3310     case 1:
3311       operands[1] = gen_lowpart (HImode, operands[1]);
3312       return "lhu\t%0,%1";
3313     case 2:
3314       operands[1] = gen_lowpart (SImode, operands[1]);
3315       return "lwu\t%0,%1";
3316     case 3:
3317       return "#";
3318     case 4:
3319       return "and\t%0,%2";
3320     default:
3321       gcc_unreachable ();
3322     }
3324   [(set_attr "move_type" "load,load,load,shift_shift,logical")
3325    (set_attr "mode" "<MODE>")])
3327 (define_expand "ior<mode>3"
3328   [(set (match_operand:GPR 0 "register_operand")
3329         (ior:GPR (match_operand:GPR 1 "register_operand")
3330                  (match_operand:GPR 2 "uns_arith_operand")))]
3331   ""
3333   if (TARGET_MIPS16)
3334     operands[2] = force_reg (<MODE>mode, operands[2]);
3337 (define_insn "*ior<mode>3"
3338   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3339         (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3340                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3341   "!TARGET_MIPS16"
3342   "@
3343    or\t%0,%1,%2
3344    or\t%0,%1,%2
3345    ori\t%0,%1,%x2"
3346   [(set_attr "alu_type" "or")
3347    (set_attr "compression" "micromips,*,*")
3348    (set_attr "mode" "<MODE>")])
3350 (define_insn "*ior<mode>3_mips16"
3351   [(set (match_operand:GPR 0 "register_operand" "=d")
3352         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3353                  (match_operand:GPR 2 "register_operand" "d")))]
3354   "TARGET_MIPS16"
3355   "or\t%0,%2"
3356   [(set_attr "alu_type" "or")
3357    (set_attr "mode" "<MODE>")])
3359 (define_expand "xor<mode>3"
3360   [(set (match_operand:GPR 0 "register_operand")
3361         (xor:GPR (match_operand:GPR 1 "register_operand")
3362                  (match_operand:GPR 2 "uns_arith_operand")))]
3363   ""
3364   "")
3366 (define_insn "*xor<mode>3"
3367   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3368         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3369                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3370   "!TARGET_MIPS16"
3371   "@
3372    xor\t%0,%1,%2
3373    xor\t%0,%1,%2
3374    xori\t%0,%1,%x2"
3375   [(set_attr "alu_type" "xor")
3376    (set_attr "compression" "micromips,*,*")
3377    (set_attr "mode" "<MODE>")])
3379 (define_insn "*xor<mode>3_mips16"
3380   [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3381         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3382                  (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3383   "TARGET_MIPS16"
3384   "@
3385    xor\t%0,%2
3386    cmpi\t%1,%2
3387    cmpi\t%1,%2
3388    cmp\t%1,%2"
3389   [(set_attr "alu_type" "xor")
3390    (set_attr "mode" "<MODE>")
3391    (set_attr "extended_mips16" "no,no,yes,no")])
3393 (define_insn "*nor<mode>3"
3394   [(set (match_operand:GPR 0 "register_operand" "=d")
3395         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3396                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3397   "!TARGET_MIPS16"
3398   "nor\t%0,%1,%2"
3399   [(set_attr "alu_type" "nor")
3400    (set_attr "mode" "<MODE>")])
3403 ;;  ....................
3405 ;;      TRUNCATION
3407 ;;  ....................
3411 (define_insn "truncdfsf2"
3412   [(set (match_operand:SF 0 "register_operand" "=f")
3413         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3414   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3415   "cvt.s.d\t%0,%1"
3416   [(set_attr "type"     "fcvt")
3417    (set_attr "cnv_mode" "D2S")   
3418    (set_attr "mode"     "SF")])
3420 ;; Integer truncation patterns.  Truncating SImode values to smaller
3421 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3422 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3423 ;; need to make sure that the lower 32 bits are properly sign-extended
3424 ;; (see TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3425 ;; smaller than SImode is equivalent to two separate truncations:
3427 ;;                        A       B
3428 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3429 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3431 ;; Step A needs a real instruction but step B does not.
3433 (define_insn "truncdi<mode>2"
3434   [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3435         (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3436   "TARGET_64BIT"
3437   "@
3438     sll\t%0,%1,0
3439     <store>\t%1,%0"
3440   [(set_attr "move_type" "sll0,store")
3441    (set_attr "mode" "SI")])
3443 ;; Combiner patterns to optimize shift/truncate combinations.
3445 (define_insn "*ashr_trunc<mode>"
3446   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3447         (truncate:SUBDI
3448           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3449                        (match_operand:DI 2 "const_arith_operand" ""))))]
3450   "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3451   "dsra\t%0,%1,%2"
3452   [(set_attr "type" "shift")
3453    (set_attr "mode" "<MODE>")])
3455 (define_insn "*lshr32_trunc<mode>"
3456   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3457         (truncate:SUBDI
3458           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3459                        (const_int 32))))]
3460   "TARGET_64BIT && !TARGET_MIPS16"
3461   "dsra\t%0,%1,32"
3462   [(set_attr "type" "shift")
3463    (set_attr "mode" "<MODE>")])
3465 ;; Logical shift by more than 32 results in proper SI values so truncation is
3466 ;; removed by the middle end.  Note that a logical shift by 32 is handled by
3467 ;; the previous pattern.
3468 (define_insn "*<optab>_trunc<mode>_exts"
3469   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3470         (truncate:SUBDI
3471          (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3472                          (match_operand:DI 2 "const_arith_operand" ""))))]
3473   "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3474   "exts\t%0,%1,%2,31"
3475   [(set_attr "type" "arith")
3476    (set_attr "mode" "<MODE>")])
3479 ;;  ....................
3481 ;;      ZERO EXTENSION
3483 ;;  ....................
3485 ;; Extension insns.
3487 (define_expand "zero_extendsidi2"
3488   [(set (match_operand:DI 0 "register_operand")
3489         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3490   "TARGET_64BIT")
3492 (define_insn_and_split "*zero_extendsidi2"
3493   [(set (match_operand:DI 0 "register_operand" "=d,d")
3494         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3495   "TARGET_64BIT && !ISA_HAS_EXT_INS"
3496   "@
3497    #
3498    lwu\t%0,%1"
3499   "&& reload_completed && REG_P (operands[1])"
3500   [(set (match_dup 0)
3501         (ashift:DI (match_dup 1) (const_int 32)))
3502    (set (match_dup 0)
3503         (lshiftrt:DI (match_dup 0) (const_int 32)))]
3504   { operands[1] = gen_lowpart (DImode, operands[1]); }
3505   [(set_attr "move_type" "shift_shift,load")
3506    (set_attr "mode" "DI")])
3508 (define_insn "*zero_extendsidi2_dext"
3509   [(set (match_operand:DI 0 "register_operand" "=d,d")
3510         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3511   "TARGET_64BIT && ISA_HAS_EXT_INS"
3512   "@
3513    dext\t%0,%1,0,32
3514    lwu\t%0,%1"
3515   [(set_attr "move_type" "arith,load")
3516    (set_attr "mode" "DI")])
3518 ;; See the comment before the *and<mode>3 pattern why this is generated by
3519 ;; combine.
3521 (define_split
3522   [(set (match_operand:DI 0 "register_operand")
3523         (and:DI (match_operand:DI 1 "register_operand")
3524                 (const_int 4294967295)))]
3525   "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3526   [(set (match_dup 0)
3527         (ashift:DI (match_dup 1) (const_int 32)))
3528    (set (match_dup 0)
3529         (lshiftrt:DI (match_dup 0) (const_int 32)))])
3531 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3532   [(set (match_operand:GPR 0 "register_operand")
3533         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3534   ""
3536   if (TARGET_MIPS16 && !GENERATE_MIPS16E
3537       && !memory_operand (operands[1], <SHORT:MODE>mode))
3538     {
3539       emit_insn (gen_and<GPR:mode>3 (operands[0],
3540                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
3541                                      force_reg (<GPR:MODE>mode,
3542                                                 GEN_INT (<SHORT:mask>))));
3543       DONE;
3544     }
3547 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3548   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3549         (zero_extend:GPR
3550              (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3551   "!TARGET_MIPS16"
3552   "@
3553    andi\t%0,%1,<SHORT:mask>
3554    andi\t%0,%1,<SHORT:mask>
3555    l<SHORT:size>u\t%0,%1"
3556   [(set_attr "move_type" "andi,andi,load")
3557    (set_attr "compression" "micromips,*,*")
3558    (set_attr "mode" "<GPR:MODE>")])
3560 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3561   [(set (match_operand:GPR 0 "register_operand" "=d")
3562         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3563   "GENERATE_MIPS16E"
3564   "ze<SHORT:size>\t%0"
3565   ;; This instruction is effectively a special encoding of ANDI.
3566   [(set_attr "move_type" "andi")
3567    (set_attr "mode" "<GPR:MODE>")])
3569 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3570   [(set (match_operand:GPR 0 "register_operand" "=d")
3571         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3572   "TARGET_MIPS16"
3573   "l<SHORT:size>u\t%0,%1"
3574   [(set_attr "move_type" "load")
3575    (set_attr "mode" "<GPR:MODE>")])
3577 (define_expand "zero_extendqihi2"
3578   [(set (match_operand:HI 0 "register_operand")
3579         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3580   ""
3582   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3583     {
3584       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3585                                        operands[1]));
3586       DONE;
3587     }
3590 (define_insn "*zero_extendqihi2"
3591   [(set (match_operand:HI 0 "register_operand" "=d,d")
3592         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3593   "!TARGET_MIPS16"
3594   "@
3595    andi\t%0,%1,0x00ff
3596    lbu\t%0,%1"
3597   [(set_attr "move_type" "andi,load")
3598    (set_attr "mode" "HI")])
3600 (define_insn "*zero_extendqihi2_mips16"
3601   [(set (match_operand:HI 0 "register_operand" "=d")
3602         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3603   "TARGET_MIPS16"
3604   "lbu\t%0,%1"
3605   [(set_attr "move_type" "load")
3606    (set_attr "mode" "HI")])
3608 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3610 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3611   [(set (match_operand:GPR 0 "register_operand" "=d")
3612         (zero_extend:GPR
3613             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3614   "TARGET_64BIT && !TARGET_MIPS16"
3616   operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3617   return "andi\t%0,%1,%x2";
3619   [(set_attr "alu_type" "and")
3620    (set_attr "mode" "<GPR:MODE>")])
3622 (define_insn "*zero_extendhi_truncqi"
3623   [(set (match_operand:HI 0 "register_operand" "=d")
3624         (zero_extend:HI
3625             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3626   "TARGET_64BIT && !TARGET_MIPS16"
3627   "andi\t%0,%1,0xff"
3628   [(set_attr "alu_type" "and")
3629    (set_attr "mode" "HI")])
3632 ;;  ....................
3634 ;;      SIGN EXTENSION
3636 ;;  ....................
3638 ;; Extension insns.
3639 ;; Those for integer source operand are ordered widest source type first.
3641 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3642 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3643 ;; and truncdisi2).  We can therefore get rid of register->register
3644 ;; instructions if we constrain the source to be in the same register as
3645 ;; the destination.
3647 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3648 ;; we split them into nothing before the post-reload scheduler runs.
3649 ;; These alternatives therefore have type "move" in order to reflect
3650 ;; what happens if the two pre-reload operands cannot be tied, and are
3651 ;; instead allocated two separate GPRs.  We don't distinguish between
3652 ;; the GPR and LO cases because we don't usually know during pre-reload
3653 ;; scheduling whether an operand will be LO or not.
3654 (define_insn_and_split "extendsidi2"
3655   [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3656         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3657   "TARGET_64BIT"
3658   "@
3659    #
3660    #
3661    lw\t%0,%1"
3662   "&& reload_completed && register_operand (operands[1], VOIDmode)"
3663   [(const_int 0)]
3665   emit_note (NOTE_INSN_DELETED);
3666   DONE;
3668   [(set_attr "move_type" "move,move,load")
3669    (set_attr "mode" "DI")])
3671 (define_expand "extend<SHORT:mode><GPR:mode>2"
3672   [(set (match_operand:GPR 0 "register_operand")
3673         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3674   "")
3676 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3677   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3678         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3679   "GENERATE_MIPS16E"
3680   "@
3681    se<SHORT:size>\t%0
3682    l<SHORT:size>\t%0,%1"
3683   [(set_attr "move_type" "signext,load")
3684    (set_attr "mode" "<GPR:MODE>")])
3686 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3687   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3688         (sign_extend:GPR
3689              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3690   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3691   "@
3692    #
3693    l<SHORT:size>\t%0,%1"
3694   "&& reload_completed && REG_P (operands[1])"
3695   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3696    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3698   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3699   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3700                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3702   [(set_attr "move_type" "shift_shift,load")
3703    (set_attr "mode" "<GPR:MODE>")])
3705 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3706   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3707         (sign_extend:GPR
3708              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3709   "ISA_HAS_SEB_SEH"
3710   "@
3711    se<SHORT:size>\t%0,%1
3712    l<SHORT:size>\t%0,%1"
3713   [(set_attr "move_type" "signext,load")
3714    (set_attr "mode" "<GPR:MODE>")])
3716 (define_expand "extendqihi2"
3717   [(set (match_operand:HI 0 "register_operand")
3718         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3719   "")
3721 (define_insn "*extendqihi2_mips16e"
3722   [(set (match_operand:HI 0 "register_operand" "=d,d")
3723         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3724   "GENERATE_MIPS16E"
3725   "@
3726    seb\t%0
3727    lb\t%0,%1"
3728   [(set_attr "move_type" "signext,load")
3729    (set_attr "mode" "SI")])
3731 (define_insn_and_split "*extendqihi2"
3732   [(set (match_operand:HI 0 "register_operand" "=d,d")
3733         (sign_extend:HI
3734              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3735   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3736   "@
3737    #
3738    lb\t%0,%1"
3739   "&& reload_completed && REG_P (operands[1])"
3740   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3741    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3743   operands[0] = gen_lowpart (SImode, operands[0]);
3744   operands[1] = gen_lowpart (SImode, operands[1]);
3745   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3746                          - GET_MODE_BITSIZE (QImode));
3748   [(set_attr "move_type" "shift_shift,load")
3749    (set_attr "mode" "SI")])
3751 (define_insn "*extendqihi2_seb"
3752   [(set (match_operand:HI 0 "register_operand" "=d,d")
3753         (sign_extend:HI
3754              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3755   "ISA_HAS_SEB_SEH"
3756   "@
3757    seb\t%0,%1
3758    lb\t%0,%1"
3759   [(set_attr "move_type" "signext,load")
3760    (set_attr "mode" "SI")])
3762 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
3763 ;; use the shift/truncate patterns.
3765 (define_insn_and_split "*extenddi_truncate<mode>"
3766   [(set (match_operand:DI 0 "register_operand" "=d")
3767         (sign_extend:DI
3768             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3769   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3770   "#"
3771   "&& reload_completed"
3772   [(set (match_dup 2)
3773         (ashift:DI (match_dup 1)
3774                    (match_dup 3)))
3775    (set (match_dup 0)
3776         (ashiftrt:DI (match_dup 2)
3777                      (match_dup 3)))]
3779   operands[2] = gen_lowpart (DImode, operands[0]);
3780   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3782   [(set_attr "move_type" "shift_shift")
3783    (set_attr "mode" "DI")])
3785 (define_insn_and_split "*extendsi_truncate<mode>"
3786   [(set (match_operand:SI 0 "register_operand" "=d")
3787         (sign_extend:SI
3788             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3789   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3790   "#"
3791   "&& reload_completed"
3792   [(set (match_dup 2)
3793         (ashift:DI (match_dup 1)
3794                    (match_dup 3)))
3795    (set (match_dup 0)
3796         (truncate:SI (ashiftrt:DI (match_dup 2)
3797                                   (match_dup 3))))]
3799   operands[2] = gen_lowpart (DImode, operands[0]);
3800   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3802   [(set_attr "move_type" "shift_shift")
3803    (set_attr "mode" "SI")])
3805 (define_insn_and_split "*extendhi_truncateqi"
3806   [(set (match_operand:HI 0 "register_operand" "=d")
3807         (sign_extend:HI
3808             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3809   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3810   "#"
3811   "&& reload_completed"
3812   [(set (match_dup 2)
3813         (ashift:DI (match_dup 1)
3814                    (const_int 56)))
3815    (set (match_dup 0)
3816         (truncate:HI (ashiftrt:DI (match_dup 2)
3817                                   (const_int 56))))]
3819   operands[2] = gen_lowpart (DImode, operands[0]);
3821   [(set_attr "move_type" "shift_shift")
3822    (set_attr "mode" "SI")])
3824 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3825   [(set (match_operand:GPR 0 "register_operand" "=d")
3826         (sign_extend:GPR
3827             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3828   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3830   operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3831   return "exts\t%0,%1,0,%m2";
3833   [(set_attr "type" "arith")
3834    (set_attr "mode" "<GPR:MODE>")])
3836 (define_insn "*extendhi_truncateqi_exts"
3837   [(set (match_operand:HI 0 "register_operand" "=d")
3838         (sign_extend:HI
3839             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3840   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3841   "exts\t%0,%1,0,7"
3842   [(set_attr "type" "arith")
3843    (set_attr "mode" "SI")])
3845 (define_insn "extendsfdf2"
3846   [(set (match_operand:DF 0 "register_operand" "=f")
3847         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3848   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3849   "cvt.d.s\t%0,%1"
3850   [(set_attr "type"     "fcvt")
3851    (set_attr "cnv_mode" "S2D")   
3852    (set_attr "mode"     "DF")])
3855 ;;  ....................
3857 ;;      CONVERSIONS
3859 ;;  ....................
3861 (define_expand "fix_truncdfsi2"
3862   [(set (match_operand:SI 0 "register_operand")
3863         (fix:SI (match_operand:DF 1 "register_operand")))]
3864   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3866   if (!ISA_HAS_TRUNC_W)
3867     {
3868       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3869       DONE;
3870     }
3873 (define_insn "fix_truncdfsi2_insn"
3874   [(set (match_operand:SI 0 "register_operand" "=f")
3875         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3876   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3877   "trunc.w.d %0,%1"
3878   [(set_attr "type"     "fcvt")
3879    (set_attr "mode"     "DF")
3880    (set_attr "cnv_mode" "D2I")])
3882 (define_insn "fix_truncdfsi2_macro"
3883   [(set (match_operand:SI 0 "register_operand" "=f")
3884         (fix:SI (match_operand:DF 1 "register_operand" "f")))
3885    (clobber (match_scratch:DF 2 "=d"))]
3886   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3888   if (mips_nomacro.nesting_level > 0)
3889     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3890   else
3891     return "trunc.w.d %0,%1,%2";
3893   [(set_attr "type"     "fcvt")
3894    (set_attr "mode"     "DF")
3895    (set_attr "cnv_mode" "D2I")
3896    (set_attr "insn_count" "9")])
3898 (define_expand "fix_truncsfsi2"
3899   [(set (match_operand:SI 0 "register_operand")
3900         (fix:SI (match_operand:SF 1 "register_operand")))]
3901   "TARGET_HARD_FLOAT"
3903   if (!ISA_HAS_TRUNC_W)
3904     {
3905       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3906       DONE;
3907     }
3910 (define_insn "fix_truncsfsi2_insn"
3911   [(set (match_operand:SI 0 "register_operand" "=f")
3912         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3913   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3914   "trunc.w.s %0,%1"
3915   [(set_attr "type"     "fcvt")
3916    (set_attr "mode"     "SF")
3917    (set_attr "cnv_mode" "S2I")])
3919 (define_insn "fix_truncsfsi2_macro"
3920   [(set (match_operand:SI 0 "register_operand" "=f")
3921         (fix:SI (match_operand:SF 1 "register_operand" "f")))
3922    (clobber (match_scratch:SF 2 "=d"))]
3923   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3925   if (mips_nomacro.nesting_level > 0)
3926     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3927   else
3928     return "trunc.w.s %0,%1,%2";
3930   [(set_attr "type"     "fcvt")
3931    (set_attr "mode"     "SF")
3932    (set_attr "cnv_mode" "S2I")
3933    (set_attr "insn_count" "9")])
3936 (define_insn "fix_truncdfdi2"
3937   [(set (match_operand:DI 0 "register_operand" "=f")
3938         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3939   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3940   "trunc.l.d %0,%1"
3941   [(set_attr "type"     "fcvt")
3942    (set_attr "mode"     "DF")
3943    (set_attr "cnv_mode" "D2I")])
3946 (define_insn "fix_truncsfdi2"
3947   [(set (match_operand:DI 0 "register_operand" "=f")
3948         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3949   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3950   "trunc.l.s %0,%1"
3951   [(set_attr "type"     "fcvt")
3952    (set_attr "mode"     "SF")
3953    (set_attr "cnv_mode" "S2I")])
3956 (define_insn "floatsidf2"
3957   [(set (match_operand:DF 0 "register_operand" "=f")
3958         (float:DF (match_operand:SI 1 "register_operand" "f")))]
3959   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3960   "cvt.d.w\t%0,%1"
3961   [(set_attr "type"     "fcvt")
3962    (set_attr "mode"     "DF")
3963    (set_attr "cnv_mode" "I2D")])
3966 (define_insn "floatdidf2"
3967   [(set (match_operand:DF 0 "register_operand" "=f")
3968         (float:DF (match_operand:DI 1 "register_operand" "f")))]
3969   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3970   "cvt.d.l\t%0,%1"
3971   [(set_attr "type"     "fcvt")
3972    (set_attr "mode"     "DF")
3973    (set_attr "cnv_mode" "I2D")])
3976 (define_insn "floatsisf2"
3977   [(set (match_operand:SF 0 "register_operand" "=f")
3978         (float:SF (match_operand:SI 1 "register_operand" "f")))]
3979   "TARGET_HARD_FLOAT"
3980   "cvt.s.w\t%0,%1"
3981   [(set_attr "type"     "fcvt")
3982    (set_attr "mode"     "SF")
3983    (set_attr "cnv_mode" "I2S")])
3986 (define_insn "floatdisf2"
3987   [(set (match_operand:SF 0 "register_operand" "=f")
3988         (float:SF (match_operand:DI 1 "register_operand" "f")))]
3989   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3990   "cvt.s.l\t%0,%1"
3991   [(set_attr "type"     "fcvt")
3992    (set_attr "mode"     "SF")
3993    (set_attr "cnv_mode" "I2S")])
3996 (define_expand "fixuns_truncdfsi2"
3997   [(set (match_operand:SI 0 "register_operand")
3998         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3999   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4001   rtx reg1 = gen_reg_rtx (DFmode);
4002   rtx reg2 = gen_reg_rtx (DFmode);
4003   rtx reg3 = gen_reg_rtx (SImode);
4004   rtx_code_label *label1 = gen_label_rtx ();
4005   rtx_code_label *label2 = gen_label_rtx ();
4006   rtx test;
4007   REAL_VALUE_TYPE offset;
4009   real_2expN (&offset, 31, DFmode);
4011   if (reg1)                     /* Turn off complaints about unreached code.  */
4012     {
4013       mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4014       do_pending_stack_adjust ();
4016       test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4017       emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4019       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4020       emit_jump_insn (gen_rtx_SET (pc_rtx,
4021                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4022       emit_barrier ();
4024       emit_label (label1);
4025       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4026       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4027                                      (BITMASK_HIGH, SImode)));
4029       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4030       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4032       emit_label (label2);
4034       /* Allow REG_NOTES to be set on last insn (labels don't have enough
4035          fields, and can't be used for REG_NOTES anyway).  */
4036       emit_use (stack_pointer_rtx);
4037       DONE;
4038     }
4042 (define_expand "fixuns_truncdfdi2"
4043   [(set (match_operand:DI 0 "register_operand")
4044         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
4045   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4047   rtx reg1 = gen_reg_rtx (DFmode);
4048   rtx reg2 = gen_reg_rtx (DFmode);
4049   rtx reg3 = gen_reg_rtx (DImode);
4050   rtx_code_label *label1 = gen_label_rtx ();
4051   rtx_code_label *label2 = gen_label_rtx ();
4052   rtx test;
4053   REAL_VALUE_TYPE offset;
4055   real_2expN (&offset, 63, DFmode);
4057   mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4058   do_pending_stack_adjust ();
4060   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4061   emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4063   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4064   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4065   emit_barrier ();
4067   emit_label (label1);
4068   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4069   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4070   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4072   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4073   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4075   emit_label (label2);
4077   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4078      fields, and can't be used for REG_NOTES anyway).  */
4079   emit_use (stack_pointer_rtx);
4080   DONE;
4084 (define_expand "fixuns_truncsfsi2"
4085   [(set (match_operand:SI 0 "register_operand")
4086         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
4087   "TARGET_HARD_FLOAT"
4089   rtx reg1 = gen_reg_rtx (SFmode);
4090   rtx reg2 = gen_reg_rtx (SFmode);
4091   rtx reg3 = gen_reg_rtx (SImode);
4092   rtx_code_label *label1 = gen_label_rtx ();
4093   rtx_code_label *label2 = gen_label_rtx ();
4094   rtx test;
4095   REAL_VALUE_TYPE offset;
4097   real_2expN (&offset, 31, SFmode);
4099   mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4100   do_pending_stack_adjust ();
4102   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4103   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4105   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4106   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4107   emit_barrier ();
4109   emit_label (label1);
4110   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4111   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4112                                  (BITMASK_HIGH, SImode)));
4114   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4115   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4117   emit_label (label2);
4119   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4120      fields, and can't be used for REG_NOTES anyway).  */
4121   emit_use (stack_pointer_rtx);
4122   DONE;
4126 (define_expand "fixuns_truncsfdi2"
4127   [(set (match_operand:DI 0 "register_operand")
4128         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
4129   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4131   rtx reg1 = gen_reg_rtx (SFmode);
4132   rtx reg2 = gen_reg_rtx (SFmode);
4133   rtx reg3 = gen_reg_rtx (DImode);
4134   rtx_code_label *label1 = gen_label_rtx ();
4135   rtx_code_label *label2 = gen_label_rtx ();
4136   rtx test;
4137   REAL_VALUE_TYPE offset;
4139   real_2expN (&offset, 63, SFmode);
4141   mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4142   do_pending_stack_adjust ();
4144   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4145   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4147   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4148   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4149   emit_barrier ();
4151   emit_label (label1);
4152   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4153   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4154   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4156   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4157   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4159   emit_label (label2);
4161   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4162      fields, and can't be used for REG_NOTES anyway).  */
4163   emit_use (stack_pointer_rtx);
4164   DONE;
4168 ;;  ....................
4170 ;;      DATA MOVEMENT
4172 ;;  ....................
4174 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4176 (define_expand "extvmisalign<mode>"
4177   [(set (match_operand:GPR 0 "register_operand")
4178         (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4179                           (match_operand 2 "const_int_operand")
4180                           (match_operand 3 "const_int_operand")))]
4181   "ISA_HAS_LWL_LWR"
4183   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4184                                          INTVAL (operands[2]),
4185                                          INTVAL (operands[3]),
4186                                          /*unsigned=*/ false))
4187     DONE;
4188   else
4189     FAIL;
4192 (define_expand "extv<mode>"
4193   [(set (match_operand:GPR 0 "register_operand")
4194         (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4195                           (match_operand 2 "const_int_operand")
4196                           (match_operand 3 "const_int_operand")))]
4197   "ISA_HAS_EXTS"
4199   if (UINTVAL (operands[2]) > 32)
4200     FAIL;
4203 (define_insn "*extv<mode>"
4204   [(set (match_operand:GPR 0 "register_operand" "=d")
4205         (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4206                           (match_operand 2 "const_int_operand" "")
4207                           (match_operand 3 "const_int_operand" "")))]
4208   "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4209   "exts\t%0,%1,%3,%m2"
4210   [(set_attr "type"     "arith")
4211    (set_attr "mode"     "<MODE>")])
4213 (define_expand "extzvmisalign<mode>"
4214   [(set (match_operand:GPR 0 "register_operand")
4215         (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4216                           (match_operand 2 "const_int_operand")
4217                           (match_operand 3 "const_int_operand")))]
4218   "ISA_HAS_LWL_LWR"
4220   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4221                                          INTVAL (operands[2]),
4222                                          INTVAL (operands[3]),
4223                                          /*unsigned=*/ true))
4224     DONE;
4225   else
4226     FAIL;
4229 (define_expand "extzv<mode>"
4230   [(set (match_operand:GPR 0 "register_operand")
4231         (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4232                           (match_operand 2 "const_int_operand")
4233                           (match_operand 3 "const_int_operand")))]
4234   ""
4236   if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4237                            INTVAL (operands[3])))
4238     FAIL;
4241 (define_insn "*extzv<mode>"
4242   [(set (match_operand:GPR 0 "register_operand" "=d")
4243         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4244                           (match_operand 2 "const_int_operand" "")
4245                           (match_operand 3 "const_int_operand" "")))]
4246   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4247                        INTVAL (operands[3]))"
4248   "<d>ext\t%0,%1,%3,%2"
4249   [(set_attr "type"     "arith")
4250    (set_attr "mode"     "<MODE>")])
4252 (define_insn "*extzv_truncsi_exts"
4253   [(set (match_operand:SI 0 "register_operand" "=d")
4254         (truncate:SI
4255          (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4256                           (match_operand 2 "const_int_operand" "")
4257                           (match_operand 3 "const_int_operand" ""))))]
4258   "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4259   "exts\t%0,%1,%3,31"
4260   [(set_attr "type"     "arith")
4261    (set_attr "mode"     "SI")])
4264 (define_expand "insvmisalign<mode>"
4265   [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4266                           (match_operand 1 "const_int_operand")
4267                           (match_operand 2 "const_int_operand"))
4268         (match_operand:GPR 3 "reg_or_0_operand"))]
4269   "ISA_HAS_LWL_LWR"
4271   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4272                                           INTVAL (operands[1]),
4273                                           INTVAL (operands[2])))
4274     DONE;
4275   else
4276     FAIL;
4279 (define_expand "insv<mode>"
4280   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4281                           (match_operand 1 "const_int_operand")
4282                           (match_operand 2 "const_int_operand"))
4283         (match_operand:GPR 3 "reg_or_0_operand"))]
4284   ""
4286   if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4287                            INTVAL (operands[2])))
4288     FAIL;
4291 (define_insn "*insv<mode>"
4292   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4293                           (match_operand:SI 1 "const_int_operand" "")
4294                           (match_operand:SI 2 "const_int_operand" ""))
4295         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4296   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4297                        INTVAL (operands[2]))"
4298   "<d>ins\t%0,%z3,%2,%1"
4299   [(set_attr "type"     "arith")
4300    (set_attr "mode"     "<MODE>")])
4302 ;; Combiner pattern for cins (clear and insert bit field).  We can
4303 ;; implement mask-and-shift-left operation with this.  Note that if
4304 ;; the upper bit of the mask is set in an SImode operation, the mask
4305 ;; itself will be sign-extended.  mask_low_and_shift_len will
4306 ;; therefore be greater than our threshold of 32.
4308 (define_insn "*cins<mode>"
4309   [(set (match_operand:GPR 0 "register_operand" "=d")
4310         (and:GPR
4311          (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4312                      (match_operand:GPR 2 "const_int_operand" ""))
4313          (match_operand:GPR 3 "const_int_operand" "")))]
4314   "ISA_HAS_CINS
4315    && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4317   operands[3] =
4318     GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4319   return "cins\t%0,%1,%2,%m3";
4321   [(set_attr "type"     "shift")
4322    (set_attr "mode"     "<MODE>")])
4324 ;; Unaligned word moves generated by the bit field patterns.
4326 ;; As far as the rtl is concerned, both the left-part and right-part
4327 ;; instructions can access the whole field.  However, the real operand
4328 ;; refers to just the first or the last byte (depending on endianness).
4329 ;; We therefore use two memory operands to each instruction, one to
4330 ;; describe the rtl effect and one to use in the assembly output.
4332 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4333 ;; This allows us to use the standard length calculations for the "load"
4334 ;; and "store" type attributes.
4336 (define_insn "mov_<load>l"
4337   [(set (match_operand:GPR 0 "register_operand" "=d")
4338         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4339                      (match_operand:QI 2 "memory_operand" "ZC")]
4340                     UNSPEC_LOAD_LEFT))]
4341   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4342   "<load>l\t%0,%2"
4343   [(set_attr "move_type" "load")
4344    (set_attr "mode" "<MODE>")])
4346 (define_insn "mov_<load>r"
4347   [(set (match_operand:GPR 0 "register_operand" "=d")
4348         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4349                      (match_operand:QI 2 "memory_operand" "ZC")
4350                      (match_operand:GPR 3 "register_operand" "0")]
4351                     UNSPEC_LOAD_RIGHT))]
4352   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4353   "<load>r\t%0,%2"
4354   [(set_attr "move_type" "load")
4355    (set_attr "mode" "<MODE>")])
4357 (define_insn "mov_<store>l"
4358   [(set (match_operand:BLK 0 "memory_operand" "=m")
4359         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4360                      (match_operand:QI 2 "memory_operand" "ZC")]
4361                     UNSPEC_STORE_LEFT))]
4362   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4363   "<store>l\t%z1,%2"
4364   [(set_attr "move_type" "store")
4365    (set_attr "mode" "<MODE>")])
4367 (define_insn "mov_<store>r"
4368   [(set (match_operand:BLK 0 "memory_operand" "+m")
4369         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4370                      (match_operand:QI 2 "memory_operand" "ZC")
4371                      (match_dup 0)]
4372                     UNSPEC_STORE_RIGHT))]
4373   "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4374   "<store>r\t%z1,%2"
4375   [(set_attr "move_type" "store")
4376    (set_attr "mode" "<MODE>")])
4378 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4379 ;; The required value is:
4381 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4383 ;; which translates to:
4385 ;;      lui     op0,%highest(op1)
4386 ;;      daddiu  op0,op0,%higher(op1)
4387 ;;      dsll    op0,op0,16
4388 ;;      daddiu  op0,op0,%hi(op1)
4389 ;;      dsll    op0,op0,16
4391 ;; The split is deferred until after flow2 to allow the peephole2 below
4392 ;; to take effect.
4393 (define_insn_and_split "*lea_high64"
4394   [(set (match_operand:DI 0 "register_operand" "=d")
4395         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4396   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4397   "#"
4398   "&& epilogue_completed"
4399   [(set (match_dup 0) (high:DI (match_dup 2)))
4400    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4401    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4402    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4403    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4405   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4406   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4408   [(set_attr "insn_count" "5")])
4410 ;; Use a scratch register to reduce the latency of the above pattern
4411 ;; on superscalar machines.  The optimized sequence is:
4413 ;;      lui     op1,%highest(op2)
4414 ;;      lui     op0,%hi(op2)
4415 ;;      daddiu  op1,op1,%higher(op2)
4416 ;;      dsll32  op1,op1,0
4417 ;;      daddu   op1,op1,op0
4418 (define_peephole2
4419   [(set (match_operand:DI 1 "d_operand")
4420         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4421    (match_scratch:DI 0 "d")]
4422   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4423   [(set (match_dup 1) (high:DI (match_dup 3)))
4424    (set (match_dup 0) (high:DI (match_dup 4)))
4425    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4426    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4427    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4429   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4430   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4433 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4434 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
4435 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4436 ;; used once.  We can then use the sequence:
4438 ;;      lui     op0,%highest(op1)
4439 ;;      lui     op2,%hi(op1)
4440 ;;      daddiu  op0,op0,%higher(op1)
4441 ;;      daddiu  op2,op2,%lo(op1)
4442 ;;      dsll32  op0,op0,0
4443 ;;      daddu   op0,op0,op2
4445 ;; which takes 4 cycles on most superscalar targets.
4446 (define_insn_and_split "*lea64"
4447   [(set (match_operand:DI 0 "register_operand" "=d")
4448         (match_operand:DI 1 "absolute_symbolic_operand" ""))
4449    (clobber (match_scratch:DI 2 "=&d"))]
4450   "!TARGET_MIPS16
4451    && TARGET_EXPLICIT_RELOCS
4452    && ABI_HAS_64BIT_SYMBOLS
4453    && cse_not_expected"
4454   "#"
4455   "&& reload_completed"
4456   [(set (match_dup 0) (high:DI (match_dup 3)))
4457    (set (match_dup 2) (high:DI (match_dup 4)))
4458    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4459    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4460    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4461    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4463   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4464   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4466   [(set_attr "insn_count" "6")])
4468 ;; Split HIGHs into:
4470 ;;      li op0,%hi(sym)
4471 ;;      sll op0,16
4473 ;; on MIPS16 targets.
4474 (define_split
4475   [(set (match_operand:P 0 "d_operand")
4476         (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4477   "TARGET_MIPS16 && reload_completed"
4478   [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4479    (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4481 (define_insn "*unshifted_high"
4482   [(set (match_operand:P 0 "d_operand" "=d")
4483         (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4484                   UNSPEC_UNSHIFTED_HIGH))]
4485   ""
4486   "li\t%0,%h1"
4487   [(set_attr "extended_mips16" "yes")])
4489 ;; Insns to fetch a symbol from a big GOT.
4491 (define_insn_and_split "*xgot_hi<mode>"
4492   [(set (match_operand:P 0 "register_operand" "=d")
4493         (high:P (match_operand:P 1 "got_disp_operand" "")))]
4494   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4495   "#"
4496   "&& reload_completed"
4497   [(set (match_dup 0) (high:P (match_dup 2)))
4498    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4500   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4501   operands[3] = pic_offset_table_rtx;
4503   [(set_attr "got" "xgot_high")
4504    (set_attr "mode" "<MODE>")])
4506 (define_insn_and_split "*xgot_lo<mode>"
4507   [(set (match_operand:P 0 "register_operand" "=d")
4508         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4509                   (match_operand:P 2 "got_disp_operand" "")))]
4510   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4511   "#"
4512   "&& reload_completed"
4513   [(set (match_dup 0)
4514         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4515   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4516   [(set_attr "got" "load")
4517    (set_attr "mode" "<MODE>")])
4519 ;; Insns to fetch a symbol from a normal GOT.
4521 (define_insn_and_split "*got_disp<mode>"
4522   [(set (match_operand:P 0 "register_operand" "=d")
4523         (match_operand:P 1 "got_disp_operand" ""))]
4524   "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4525   "#"
4526   "&& reload_completed"
4527   [(set (match_dup 0) (match_dup 2))]
4528   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4529   [(set_attr "got" "load")
4530    (set_attr "mode" "<MODE>")])
4532 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4534 (define_insn_and_split "*got_page<mode>"
4535   [(set (match_operand:P 0 "register_operand" "=d")
4536         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4537   "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4538   "#"
4539   "&& reload_completed"
4540   [(set (match_dup 0) (match_dup 2))]
4541   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4542   [(set_attr "got" "load")
4543    (set_attr "mode" "<MODE>")])
4545 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4546 (define_expand "unspec_got_<mode>"
4547   [(unspec:P [(match_operand:P 0)
4548               (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4550 ;; Lower-level instructions for loading an address from the GOT.
4551 ;; We could use MEMs, but an unspec gives more optimization
4552 ;; opportunities.
4554 (define_insn "load_got<mode>"
4555   [(set (match_operand:P 0 "register_operand" "=d")
4556         (unspec:P [(match_operand:P 1 "register_operand" "d")
4557                    (match_operand:P 2 "immediate_operand" "")]
4558                   UNSPEC_LOAD_GOT))]
4559   ""
4560   "<load>\t%0,%R2(%1)"
4561   [(set_attr "got" "load")
4562    (set_attr "mode" "<MODE>")])
4564 ;; Instructions for adding the low 16 bits of an address to a register.
4565 ;; Operand 2 is the address: mips_print_operand works out which relocation
4566 ;; should be applied.
4568 (define_insn "*low<mode>"
4569   [(set (match_operand:P 0 "register_operand" "=d")
4570         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4571                   (match_operand:P 2 "immediate_operand" "")))]
4572   "!TARGET_MIPS16"
4573   "<d>addiu\t%0,%1,%R2"
4574   [(set_attr "alu_type" "add")
4575    (set_attr "mode" "<MODE>")])
4577 (define_insn "*low<mode>_mips16"
4578   [(set (match_operand:P 0 "register_operand" "=d")
4579         (lo_sum:P (match_operand:P 1 "register_operand" "0")
4580                   (match_operand:P 2 "immediate_operand" "")))]
4581   "TARGET_MIPS16"
4582   "<d>addiu\t%0,%R2"
4583   [(set_attr "alu_type" "add")
4584    (set_attr "mode" "<MODE>")
4585    (set_attr "extended_mips16" "yes")])
4587 ;; Expose MIPS16 uses of the global pointer after reload if the function
4588 ;; is responsible for setting up the register itself.
4589 (define_split
4590   [(set (match_operand:GPR 0 "d_operand")
4591         (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4592   "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4593   [(set (match_dup 0) (match_dup 1))]
4594   { operands[1] = pic_offset_table_rtx; })
4596 ;; Allow combine to split complex const_int load sequences, using operand 2
4597 ;; to store the intermediate results.  See move_operand for details.
4598 (define_split
4599   [(set (match_operand:GPR 0 "register_operand")
4600         (match_operand:GPR 1 "splittable_const_int_operand"))
4601    (clobber (match_operand:GPR 2 "register_operand"))]
4602   ""
4603   [(const_int 0)]
4605   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4606   DONE;
4609 ;; Likewise, for symbolic operands.
4610 (define_split
4611   [(set (match_operand:P 0 "register_operand")
4612         (match_operand:P 1))
4613    (clobber (match_operand:P 2 "register_operand"))]
4614   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4615   [(set (match_dup 0) (match_dup 3))]
4617   mips_split_symbol (operands[2], operands[1],
4618                      MAX_MACHINE_MODE, &operands[3]);
4621 ;; 64-bit integer moves
4623 ;; Unlike most other insns, the move insns can't be split with
4624 ;; different predicates, because register spilling and other parts of
4625 ;; the compiler, have memoized the insn number already.
4627 (define_expand "movdi"
4628   [(set (match_operand:DI 0 "")
4629         (match_operand:DI 1 ""))]
4630   ""
4632   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4633     DONE;
4636 ;; For mips16, we need a special case to handle storing $31 into
4637 ;; memory, since we don't have a constraint to match $31.  This
4638 ;; instruction can be generated by save_restore_insns.
4640 (define_insn "*mov<mode>_ra"
4641   [(set (match_operand:GPR 0 "stack_operand" "=m")
4642         (reg:GPR RETURN_ADDR_REGNUM))]
4643   "TARGET_MIPS16"
4644   "<store>\t$31,%0"
4645   [(set_attr "move_type" "store")
4646    (set_attr "mode" "<MODE>")])
4648 (define_insn "*movdi_32bit"
4649   [(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")
4650         (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"))]
4651   "!TARGET_64BIT && !TARGET_MIPS16
4652    && (register_operand (operands[0], DImode)
4653        || reg_or_0_operand (operands[1], DImode))"
4654   { return mips_output_move (operands[0], operands[1]); }
4655   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4656    (set (attr "mode")
4657         (if_then_else (eq_attr "move_type" "imul")
4658                       (const_string "SI")
4659                       (const_string "DI")))])
4661 (define_insn "*movdi_32bit_mips16"
4662   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4663         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4664   "!TARGET_64BIT && TARGET_MIPS16
4665    && (register_operand (operands[0], DImode)
4666        || register_operand (operands[1], DImode))"
4667   { return mips_output_move (operands[0], operands[1]); }
4668   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4669    (set_attr "mode" "DI")])
4671 (define_insn "*movdi_64bit"
4672   [(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")
4673         (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"))]
4674   "TARGET_64BIT && !TARGET_MIPS16
4675    && (register_operand (operands[0], DImode)
4676        || reg_or_0_operand (operands[1], DImode))"
4677   { return mips_output_move (operands[0], operands[1]); }
4678   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4679    (set_attr "mode" "DI")])
4681 (define_insn "*movdi_64bit_mips16"
4682   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4683         (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4684   "TARGET_64BIT && TARGET_MIPS16
4685    && (register_operand (operands[0], DImode)
4686        || register_operand (operands[1], DImode))"
4687   { return mips_output_move (operands[0], operands[1]); }
4688   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4689    (set_attr "mode" "DI")])
4691 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4692 ;; when the original load is a 4 byte instruction but the add and the
4693 ;; load are 2 2 byte instructions.
4695 (define_split
4696   [(set (match_operand:DI 0 "d_operand")
4697         (mem:DI (plus:DI (match_dup 0)
4698                          (match_operand:DI 1 "const_int_operand"))))]
4699   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4700    && !TARGET_DEBUG_D_MODE
4701    && ((INTVAL (operands[1]) < 0
4702         && INTVAL (operands[1]) >= -0x10)
4703        || (INTVAL (operands[1]) >= 32 * 8
4704            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4705        || (INTVAL (operands[1]) >= 0
4706            && INTVAL (operands[1]) < 32 * 8
4707            && (INTVAL (operands[1]) & 7) != 0))"
4708   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4709    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4711   HOST_WIDE_INT val = INTVAL (operands[1]);
4713   if (val < 0)
4714     operands[2] = const0_rtx;
4715   else if (val >= 32 * 8)
4716     {
4717       int off = val & 7;
4719       operands[1] = GEN_INT (0x8 + off);
4720       operands[2] = GEN_INT (val - off - 0x8);
4721     }
4722   else
4723     {
4724       int off = val & 7;
4726       operands[1] = GEN_INT (off);
4727       operands[2] = GEN_INT (val - off);
4728     }
4731 ;; 32-bit Integer moves
4733 ;; Unlike most other insns, the move insns can't be split with
4734 ;; different predicates, because register spilling and other parts of
4735 ;; the compiler, have memoized the insn number already.
4737 (define_expand "mov<mode>"
4738   [(set (match_operand:IMOVE32 0 "")
4739         (match_operand:IMOVE32 1 ""))]
4740   ""
4742   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4743     DONE;
4746 ;; The difference between these two is whether or not ints are allowed
4747 ;; in FP registers (off by default, use -mdebugh to enable).
4749 (define_insn "*mov<mode>_internal"
4750   [(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")
4751         (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"))]
4752   "!TARGET_MIPS16
4753    && (register_operand (operands[0], <MODE>mode)
4754        || reg_or_0_operand (operands[1], <MODE>mode))"
4755   { return mips_output_move (operands[0], operands[1]); }
4756   [(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")
4757    (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4758    (set_attr "mode" "SI")])
4760 (define_insn "*mov<mode>_mips16"
4761   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4762         (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4763   "TARGET_MIPS16
4764    && (register_operand (operands[0], <MODE>mode)
4765        || register_operand (operands[1], <MODE>mode))"
4766   { return mips_output_move (operands[0], operands[1]); }
4767   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4768    (set_attr "mode" "SI")])
4770 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4771 ;; when the original load is a 4 byte instruction but the add and the
4772 ;; load are 2 2 byte instructions.
4774 (define_split
4775   [(set (match_operand:SI 0 "d_operand")
4776         (mem:SI (plus:SI (match_dup 0)
4777                          (match_operand:SI 1 "const_int_operand"))))]
4778   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4779    && ((INTVAL (operands[1]) < 0
4780         && INTVAL (operands[1]) >= -0x80)
4781        || (INTVAL (operands[1]) >= 32 * 4
4782            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4783        || (INTVAL (operands[1]) >= 0
4784            && INTVAL (operands[1]) < 32 * 4
4785            && (INTVAL (operands[1]) & 3) != 0))"
4786   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4787    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4789   HOST_WIDE_INT val = INTVAL (operands[1]);
4791   if (val < 0)
4792     operands[2] = const0_rtx;
4793   else if (val >= 32 * 4)
4794     {
4795       int off = val & 3;
4797       operands[1] = GEN_INT (0x7c + off);
4798       operands[2] = GEN_INT (val - off - 0x7c);
4799     }
4800   else
4801     {
4802       int off = val & 3;
4804       operands[1] = GEN_INT (off);
4805       operands[2] = GEN_INT (val - off);
4806     }
4809 ;; On the mips16, we can split a load of certain constants into a load
4810 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
4811 ;; instructions.
4813 (define_split
4814   [(set (match_operand:SI 0 "d_operand")
4815         (match_operand:SI 1 "const_int_operand"))]
4816   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4817    && INTVAL (operands[1]) >= 0x100
4818    && INTVAL (operands[1]) <= 0xff + 0x7f"
4819   [(set (match_dup 0) (match_dup 1))
4820    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4822   int val = INTVAL (operands[1]);
4824   operands[1] = GEN_INT (0xff);
4825   operands[2] = GEN_INT (val - 0xff);
4828 ;; MIPS4 supports loading and storing a floating point register from
4829 ;; the sum of two general registers.  We use two versions for each of
4830 ;; these four instructions: one where the two general registers are
4831 ;; SImode, and one where they are DImode.  This is because general
4832 ;; registers will be in SImode when they hold 32-bit values, but,
4833 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4834 ;; instructions will still work correctly.
4836 ;; ??? Perhaps it would be better to support these instructions by
4837 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends.  However, since
4838 ;; these instructions can only be used to load and store floating
4839 ;; point registers, that would probably cause trouble in reload.
4841 (define_insn "*<ANYF:loadx>_<P:mode>"
4842   [(set (match_operand:ANYF 0 "register_operand" "=f")
4843         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4844                           (match_operand:P 2 "register_operand" "d"))))]
4845   "ISA_HAS_LXC1_SXC1"
4846   "<ANYF:loadx>\t%0,%1(%2)"
4847   [(set_attr "type" "fpidxload")
4848    (set_attr "mode" "<ANYF:UNITMODE>")])
4850 (define_insn "*<ANYF:storex>_<P:mode>"
4851   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4852                           (match_operand:P 2 "register_operand" "d")))
4853         (match_operand:ANYF 0 "register_operand" "f"))]
4854   "ISA_HAS_LXC1_SXC1"
4855   "<ANYF:storex>\t%0,%1(%2)"
4856   [(set_attr "type" "fpidxstore")
4857    (set_attr "mode" "<ANYF:UNITMODE>")])
4859 ;; Scaled indexed address load.
4860 ;; Per md.texi, we only need to look for a pattern with multiply in the
4861 ;; address expression, not shift.
4863 (define_insn "*lwxs"
4864   [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4865         (mem:IMOVE32
4866           (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4867                           (const_int 4))
4868                   (match_operand:P 2 "register_operand" "d"))))]
4869   "ISA_HAS_LWXS"
4870   "lwxs\t%0,%1(%2)"
4871   [(set_attr "type"     "load")
4872    (set_attr "mode"     "SI")])
4874 ;; 16-bit Integer moves
4876 ;; Unlike most other insns, the move insns can't be split with
4877 ;; different predicates, because register spilling and other parts of
4878 ;; the compiler, have memoized the insn number already.
4879 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4881 (define_expand "movhi"
4882   [(set (match_operand:HI 0 "")
4883         (match_operand:HI 1 ""))]
4884   ""
4886   if (mips_legitimize_move (HImode, operands[0], operands[1]))
4887     DONE;
4890 (define_insn "*movhi_internal"
4891   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4892         (match_operand:HI 1 "move_operand"         "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4893   "!TARGET_MIPS16
4894    && (register_operand (operands[0], HImode)
4895        || reg_or_0_operand (operands[1], HImode))"
4896   { return mips_output_move (operands[0], operands[1]); }
4897   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4898    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4899    (set_attr "mode" "HI")])
4901 (define_insn "*movhi_mips16"
4902   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4903         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4904   "TARGET_MIPS16
4905    && (register_operand (operands[0], HImode)
4906        || register_operand (operands[1], HImode))"
4907   { return mips_output_move (operands[0], operands[1]); }
4908   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4909    (set_attr "mode" "HI")])
4911 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4912 ;; when the original load is a 4 byte instruction but the add and the
4913 ;; load are 2 2 byte instructions.
4915 (define_split
4916   [(set (match_operand:HI 0 "d_operand")
4917         (mem:HI (plus:SI (match_dup 0)
4918                          (match_operand:SI 1 "const_int_operand"))))]
4919   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4920    && ((INTVAL (operands[1]) < 0
4921         && INTVAL (operands[1]) >= -0x80)
4922        || (INTVAL (operands[1]) >= 32 * 2
4923            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4924        || (INTVAL (operands[1]) >= 0
4925            && INTVAL (operands[1]) < 32 * 2
4926            && (INTVAL (operands[1]) & 1) != 0))"
4927   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4928    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4930   HOST_WIDE_INT val = INTVAL (operands[1]);
4932   if (val < 0)
4933     operands[2] = const0_rtx;
4934   else if (val >= 32 * 2)
4935     {
4936       int off = val & 1;
4938       operands[1] = GEN_INT (0x7e + off);
4939       operands[2] = GEN_INT (val - off - 0x7e);
4940     }
4941   else
4942     {
4943       int off = val & 1;
4945       operands[1] = GEN_INT (off);
4946       operands[2] = GEN_INT (val - off);
4947     }
4950 ;; 8-bit Integer moves
4952 ;; Unlike most other insns, the move insns can't be split with
4953 ;; different predicates, because register spilling and other parts of
4954 ;; the compiler, have memoized the insn number already.
4955 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4957 (define_expand "movqi"
4958   [(set (match_operand:QI 0 "")
4959         (match_operand:QI 1 ""))]
4960   ""
4962   if (mips_legitimize_move (QImode, operands[0], operands[1]))
4963     DONE;
4966 (define_insn "*movqi_internal"
4967   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
4968         (match_operand:QI 1 "move_operand"         "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
4969   "!TARGET_MIPS16
4970    && (register_operand (operands[0], QImode)
4971        || reg_or_0_operand (operands[1], QImode))"
4972   { return mips_output_move (operands[0], operands[1]); }
4973   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4974    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4975    (set_attr "mode" "QI")])
4977 (define_insn "*movqi_mips16"
4978   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4979         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
4980   "TARGET_MIPS16
4981    && (register_operand (operands[0], QImode)
4982        || register_operand (operands[1], QImode))"
4983   { return mips_output_move (operands[0], operands[1]); }
4984   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4985    (set_attr "mode" "QI")])
4987 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4988 ;; when the original load is a 4 byte instruction but the add and the
4989 ;; load are 2 2 byte instructions.
4991 (define_split
4992   [(set (match_operand:QI 0 "d_operand")
4993         (mem:QI (plus:SI (match_dup 0)
4994                          (match_operand:SI 1 "const_int_operand"))))]
4995   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4996    && ((INTVAL (operands[1]) < 0
4997         && INTVAL (operands[1]) >= -0x80)
4998        || (INTVAL (operands[1]) >= 32
4999            && INTVAL (operands[1]) <= 31 + 0x7f))"
5000   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5001    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
5003   HOST_WIDE_INT val = INTVAL (operands[1]);
5005   if (val < 0)
5006     operands[2] = const0_rtx;
5007   else
5008     {
5009       operands[1] = GEN_INT (0x7f);
5010       operands[2] = GEN_INT (val - 0x7f);
5011     }
5014 ;; 32-bit floating point moves
5016 (define_expand "movsf"
5017   [(set (match_operand:SF 0 "")
5018         (match_operand:SF 1 ""))]
5019   ""
5021   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
5022     DONE;
5025 (define_insn "movccf"
5026   [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
5027         (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
5028   "ISA_HAS_CCF"
5029   { return mips_output_move (operands[0], operands[1]); }
5030   [(set_attr "move_type" "fmove,fpload,fpstore")])
5032 (define_insn "*movsf_hardfloat"
5033   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5034         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
5035   "TARGET_HARD_FLOAT
5036    && (register_operand (operands[0], SFmode)
5037        || reg_or_0_operand (operands[1], SFmode))"
5038   { return mips_output_move (operands[0], operands[1]); }
5039   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5040    (set_attr "mode" "SF")])
5042 (define_insn "*movsf_softfloat"
5043   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
5044         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
5045   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
5046    && (register_operand (operands[0], SFmode)
5047        || reg_or_0_operand (operands[1], SFmode))"
5048   { return mips_output_move (operands[0], operands[1]); }
5049   [(set_attr "move_type" "move,load,store")
5050    (set_attr "mode" "SF")])
5052 (define_insn "*movsf_mips16"
5053   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
5054         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
5055   "TARGET_MIPS16
5056    && (register_operand (operands[0], SFmode)
5057        || register_operand (operands[1], SFmode))"
5058   { return mips_output_move (operands[0], operands[1]); }
5059   [(set_attr "move_type" "move,move,move,load,store")
5060    (set_attr "mode" "SF")])
5062 ;; 64-bit floating point moves
5064 (define_expand "movdf"
5065   [(set (match_operand:DF 0 "")
5066         (match_operand:DF 1 ""))]
5067   ""
5069   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
5070     DONE;
5073 (define_insn "*movdf_hardfloat"
5074   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5075         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
5076   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
5077    && (register_operand (operands[0], DFmode)
5078        || reg_or_0_operand (operands[1], DFmode))"
5079   { return mips_output_move (operands[0], operands[1]); }
5080   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5081    (set_attr "mode" "DF")])
5083 (define_insn "*movdf_softfloat"
5084   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
5085         (match_operand:DF 1 "move_operand" "dG,m,dG"))]
5086   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
5087    && (register_operand (operands[0], DFmode)
5088        || reg_or_0_operand (operands[1], DFmode))"
5089   { return mips_output_move (operands[0], operands[1]); }
5090   [(set_attr "move_type" "move,load,store")
5091    (set_attr "mode" "DF")])
5093 (define_insn "*movdf_mips16"
5094   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
5095         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
5096   "TARGET_MIPS16
5097    && (register_operand (operands[0], DFmode)
5098        || register_operand (operands[1], DFmode))"
5099   { return mips_output_move (operands[0], operands[1]); }
5100   [(set_attr "move_type" "move,move,move,load,store")
5101    (set_attr "mode" "DF")])
5103 ;; 128-bit integer moves
5105 (define_expand "movti"
5106   [(set (match_operand:TI 0)
5107         (match_operand:TI 1))]
5108   "TARGET_64BIT"
5110   if (mips_legitimize_move (TImode, operands[0], operands[1]))
5111     DONE;
5114 (define_insn "*movti"
5115   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
5116         (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
5117   "TARGET_64BIT
5118    && !TARGET_MIPS16
5119    && (register_operand (operands[0], TImode)
5120        || reg_or_0_operand (operands[1], TImode))"
5121   { return mips_output_move (operands[0], operands[1]); }
5122   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
5123    (set (attr "mode")
5124         (if_then_else (eq_attr "move_type" "imul")
5125                       (const_string "SI")
5126                       (const_string "TI")))])
5128 (define_insn "*movti_mips16"
5129   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5130         (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5131   "TARGET_64BIT
5132    && TARGET_MIPS16
5133    && (register_operand (operands[0], TImode)
5134        || register_operand (operands[1], TImode))"
5135   "#"
5136   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5137    (set_attr "mode" "TI")])
5139 ;; 128-bit floating point moves
5141 (define_expand "movtf"
5142   [(set (match_operand:TF 0)
5143         (match_operand:TF 1))]
5144   "TARGET_64BIT"
5146   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5147     DONE;
5150 ;; This pattern handles both hard- and soft-float cases.
5151 (define_insn "*movtf"
5152   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5153         (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5154   "TARGET_64BIT
5155    && !TARGET_MIPS16
5156    && (register_operand (operands[0], TFmode)
5157        || reg_or_0_operand (operands[1], TFmode))"
5158   "#"
5159   [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5160    (set_attr "mode" "TF")])
5162 (define_insn "*movtf_mips16"
5163   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5164         (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5165   "TARGET_64BIT
5166    && TARGET_MIPS16
5167    && (register_operand (operands[0], TFmode)
5168        || register_operand (operands[1], TFmode))"
5169   "#"
5170   [(set_attr "move_type" "move,move,move,load,store")
5171    (set_attr "mode" "TF")])
5173 (define_split
5174   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5175         (match_operand:MOVE64 1 "move_operand"))]
5176   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5177   [(const_int 0)]
5179   mips_split_move_insn (operands[0], operands[1], curr_insn);
5180   DONE;
5183 (define_split
5184   [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5185         (match_operand:MOVE128 1 "move_operand"))]
5186   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5187   [(const_int 0)]
5189   mips_split_move_insn (operands[0], operands[1], curr_insn);
5190   DONE;
5193 ;; When generating mips16 code, split moves of negative constants into
5194 ;; a positive "li" followed by a negation.
5195 (define_split
5196   [(set (match_operand 0 "d_operand")
5197         (match_operand 1 "const_int_operand"))]
5198   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5199   [(set (match_dup 2)
5200         (match_dup 3))
5201    (set (match_dup 2)
5202         (neg:SI (match_dup 2)))]
5204   operands[2] = gen_lowpart (SImode, operands[0]);
5205   operands[3] = GEN_INT (-INTVAL (operands[1]));
5208 ;; 64-bit paired-single floating point moves
5210 (define_expand "movv2sf"
5211   [(set (match_operand:V2SF 0)
5212         (match_operand:V2SF 1))]
5213   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5215   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5216     DONE;
5219 (define_insn "*movv2sf"
5220   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5221         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5222   "TARGET_HARD_FLOAT
5223    && TARGET_PAIRED_SINGLE_FLOAT
5224    && (register_operand (operands[0], V2SFmode)
5225        || reg_or_0_operand (operands[1], V2SFmode))"
5226   { return mips_output_move (operands[0], operands[1]); }
5227   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5228    (set_attr "mode" "DF")])
5230 ;; Extract the high part of a HI/LO value.  See mips_hard_regno_mode_ok_p
5231 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5233 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5234 ;; instead of MFHI.  This avoids both the normal MIPS III hi/lo hazards
5235 ;; and the errata related to -mfix-vr4130.
5236 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5237   [(set (match_operand:GPR 0 "register_operand" "=d")
5238         (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5239                     UNSPEC_MFHI))]
5240   ""
5241   { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5242   [(set_attr "type" "mfhi")
5243    (set_attr "mode" "<GPR:MODE>")])
5245 ;; Set the high part of a HI/LO value, given that the low part has
5246 ;; already been set.  See mips_hard_regno_mode_ok_p for the reason
5247 ;; why we can't just use (reg:GPR HI_REGNUM).
5248 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5249   [(set (match_operand:HILO 0 "register_operand" "=x")
5250         (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5251                       (match_operand:GPR 2 "register_operand" "l")]
5252                      UNSPEC_MTHI))]
5253   ""
5254   "mthi\t%z1"
5255   [(set_attr "type" "mthi")
5256    (set_attr "mode" "SI")])
5258 ;; Emit a doubleword move in which exactly one of the operands is
5259 ;; a floating-point register.  We can't just emit two normal moves
5260 ;; because of the constraints imposed by the FPU register model;
5261 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
5262 ;; the FPR whole and use special patterns to refer to each word of
5263 ;; the other operand.
5265 (define_expand "move_doubleword_fpr<mode>"
5266   [(set (match_operand:SPLITF 0)
5267         (match_operand:SPLITF 1))]
5268   ""
5270   if (FP_REG_RTX_P (operands[0]))
5271     {
5272       rtx low = mips_subword (operands[1], 0);
5273       rtx high = mips_subword (operands[1], 1);
5274       emit_insn (gen_load_low<mode> (operands[0], low));
5275       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5276         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5277       else
5278         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5279     }
5280   else
5281     {
5282       rtx low = mips_subword (operands[0], 0);
5283       rtx high = mips_subword (operands[0], 1);
5284       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5285       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5286         emit_insn (gen_mfhc1<mode> (high, operands[1]));
5287       else
5288         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5289     }
5290   DONE;
5293 ;; Load the low word of operand 0 with operand 1.
5294 (define_insn "load_low<mode>"
5295   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5296         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5297                        UNSPEC_LOAD_LOW))]
5298   "TARGET_HARD_FLOAT"
5300   operands[0] = mips_subword (operands[0], 0);
5301   return mips_output_move (operands[0], operands[1]);
5303   [(set_attr "move_type" "mtc,fpload")
5304    (set_attr "mode" "<HALFMODE>")])
5306 ;; Load the high word of operand 0 from operand 1, preserving the value
5307 ;; in the low word.
5308 (define_insn "load_high<mode>"
5309   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5310         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5311                         (match_operand:SPLITF 2 "register_operand" "0,0")]
5312                        UNSPEC_LOAD_HIGH))]
5313   "TARGET_HARD_FLOAT"
5315   operands[0] = mips_subword (operands[0], 1);
5316   return mips_output_move (operands[0], operands[1]);
5318   [(set_attr "move_type" "mtc,fpload")
5319    (set_attr "mode" "<HALFMODE>")])
5321 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
5322 ;; high word and 0 to store the low word.
5323 (define_insn "store_word<mode>"
5324   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5325         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5326                             (match_operand 2 "const_int_operand")]
5327                            UNSPEC_STORE_WORD))]
5328   "TARGET_HARD_FLOAT"
5330   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5331   return mips_output_move (operands[0], operands[1]);
5333   [(set_attr "move_type" "mfc,fpstore")
5334    (set_attr "mode" "<HALFMODE>")])
5336 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5337 ;; value in the low word.
5338 (define_insn "mthc1<mode>"
5339   [(set (match_operand:SPLITF 0 "register_operand" "=f")
5340         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5341                         (match_operand:SPLITF 2 "register_operand" "0")]
5342                        UNSPEC_MTHC1))]
5343   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5344   "mthc1\t%z1,%0"
5345   [(set_attr "move_type" "mtc")
5346    (set_attr "mode" "<HALFMODE>")])
5348 ;; Move high word of operand 1 to operand 0 using mfhc1.
5349 (define_insn "mfhc1<mode>"
5350   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5351         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5352                             UNSPEC_MFHC1))]
5353   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5354   "mfhc1\t%0,%1"
5355   [(set_attr "move_type" "mfc")
5356    (set_attr "mode" "<HALFMODE>")])
5358 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5359 (define_expand "load_const_gp_<mode>"
5360   [(set (match_operand:P 0 "register_operand" "=d")
5361         (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5363 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
5364 ;; of _gp from the start of this function.  Operand 1 is the incoming
5365 ;; function address.
5366 (define_insn_and_split "loadgp_newabi_<mode>"
5367   [(set (match_operand:P 0 "register_operand" "=&d")
5368         (unspec:P [(match_operand:P 1)
5369                    (match_operand:P 2 "register_operand" "d")]
5370                   UNSPEC_LOADGP))]
5371   "mips_current_loadgp_style () == LOADGP_NEWABI"
5372   { return mips_must_initialize_gp_p () ? "#" : ""; }
5373   "&& mips_must_initialize_gp_p ()"
5374   [(set (match_dup 0) (match_dup 3))
5375    (set (match_dup 0) (match_dup 4))
5376    (set (match_dup 0) (match_dup 5))]
5378   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5379   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5380   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5382   [(set_attr "type" "ghost")])
5384 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
5385 (define_insn_and_split "loadgp_absolute_<mode>"
5386   [(set (match_operand:P 0 "register_operand" "=d")
5387         (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5388   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5389   { return mips_must_initialize_gp_p () ? "#" : ""; }
5390   "&& mips_must_initialize_gp_p ()"
5391   [(const_int 0)]
5393   mips_emit_move (operands[0], operands[1]);
5394   DONE;
5396   [(set_attr "type" "ghost")])
5398 ;; This blockage instruction prevents the gp load from being
5399 ;; scheduled after an implicit use of gp.  It also prevents
5400 ;; the load from being deleted as dead.
5401 (define_insn "loadgp_blockage"
5402   [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5403   ""
5404   ""
5405   [(set_attr "type" "ghost")])
5407 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
5408 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5409 (define_insn_and_split "loadgp_rtp_<mode>"
5410   [(set (match_operand:P 0 "register_operand" "=d")
5411         (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5412                    (match_operand:P 2 "symbol_ref_operand")]
5413                   UNSPEC_LOADGP))]
5414   "mips_current_loadgp_style () == LOADGP_RTP"
5415   { return mips_must_initialize_gp_p () ? "#" : ""; }
5416   "&& mips_must_initialize_gp_p ()"
5417   [(set (match_dup 0) (high:P (match_dup 3)))
5418    (set (match_dup 0) (unspec:P [(match_dup 0)
5419                                  (match_dup 3)] UNSPEC_LOAD_GOT))
5420    (set (match_dup 0) (unspec:P [(match_dup 0)
5421                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
5423   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5424   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5426   [(set_attr "type" "ghost")])
5428 ;; Initialize the global pointer for MIPS16 code.  Operand 0 is the
5429 ;; global pointer and operand 1 is the MIPS16 register that holds
5430 ;; the required value.
5431 (define_insn_and_split "copygp_mips16_<mode>"
5432   [(set (match_operand:P 0 "register_operand" "=y")
5433         (unspec:P [(match_operand:P 1 "register_operand" "d")]
5434                   UNSPEC_COPYGP))]
5435   "TARGET_MIPS16"
5436   { return mips_must_initialize_gp_p () ? "#" : ""; }
5437   "&& mips_must_initialize_gp_p ()"
5438   [(set (match_dup 0) (match_dup 1))]
5439   ""
5440   [(set_attr "type" "ghost")])
5442 ;; A placeholder for where the cprestore instruction should go,
5443 ;; if we decide we need one.  Operand 0 and operand 1 are as for
5444 ;; "cprestore".  Operand 2 is a register that holds the gp value.
5446 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5447 ;; otherwise any register that holds the correct value will do.
5448 (define_insn_and_split "potential_cprestore_<mode>"
5449   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5450         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5451                    (match_operand:P 2 "register_operand" "d,d")]
5452                   UNSPEC_POTENTIAL_CPRESTORE))
5453    (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5454   "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5455   { return mips_must_initialize_gp_p () ? "#" : ""; }
5456   "mips_must_initialize_gp_p ()"
5457   [(const_int 0)]
5459   mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5460                                   operands[2], operands[3]);
5461   DONE;
5463   [(set_attr "type" "ghost")])
5465 ;; Emit a .cprestore directive, which normally expands to a single store
5466 ;; instruction.  Operand 0 is a (possibly illegitimate) sp-based MEM
5467 ;; for the cprestore slot.  Operand 1 is the offset of the slot from
5468 ;; the stack pointer.  (This is redundant with operand 0, but it makes
5469 ;; things a little simpler.)
5470 (define_insn "cprestore_<mode>"
5471   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5472         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5473                    (reg:P 28)]
5474                   UNSPEC_CPRESTORE))]
5475   "TARGET_CPRESTORE_DIRECTIVE"
5477   if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5478     return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5479   else
5480     return ".cprestore\t%1";
5482   [(set_attr "type" "store")
5483    (set_attr "insn_count" "1,3")])
5485 (define_insn "use_cprestore_<mode>"
5486   [(set (reg:P CPRESTORE_SLOT_REGNUM)
5487         (match_operand:P 0 "cprestore_load_slot_operand"))]
5488   ""
5489   ""
5490   [(set_attr "type" "ghost")])
5492 ;; Expand in-line code to clear the instruction cache between operand[0] and
5493 ;; operand[1].
5494 (define_expand "clear_cache"
5495   [(match_operand 0 "pmode_register_operand")
5496    (match_operand 1 "pmode_register_operand")]
5497   ""
5498   "
5500   if (TARGET_SYNCI)
5501     {
5502       mips_expand_synci_loop (operands[0], operands[1]);
5503       emit_insn (gen_sync ());
5504       emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5505     }
5506   else if (mips_cache_flush_func && mips_cache_flush_func[0])
5507     {
5508       rtx len = gen_reg_rtx (Pmode);
5509       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5510       MIPS_ICACHE_SYNC (operands[0], len);
5511     }
5512   DONE;
5515 (define_insn "sync"
5516   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5517   "GENERATE_SYNC"
5518   { return mips_output_sync (); })
5520 (define_insn "synci"
5521   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5522                     UNSPEC_SYNCI)]
5523   "TARGET_SYNCI"
5524   "synci\t0(%0)")
5526 (define_insn "rdhwr_synci_step_<mode>"
5527   [(set (match_operand:P 0 "register_operand" "=d")
5528         (unspec_volatile [(const_int 1)]
5529         UNSPEC_RDHWR))]
5530   "ISA_HAS_SYNCI"
5531   "rdhwr\t%0,$1")
5533 (define_insn "clear_hazard_<mode>"
5534   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5535    (clobber (reg:P RETURN_ADDR_REGNUM))]
5536   "ISA_HAS_SYNCI"
5538   return "%(%<bal\t1f\n"
5539          "\tnop\n"
5540          "1:\t<d>addiu\t$31,$31,12\n"
5541          "\tjr.hb\t$31\n"
5542          "\tnop%>%)";
5544   [(set_attr "insn_count" "5")])
5546 ;; Cache operations for R4000-style caches.
5547 (define_insn "mips_cache"
5548   [(set (mem:BLK (scratch))
5549         (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5550                      (match_operand:QI 1 "address_operand" "ZD")]
5551                     UNSPEC_MIPS_CACHE))]
5552   "ISA_HAS_CACHE"
5553   "cache\t%X0,%a1")
5555 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5556 ;; operation.  We keep the pattern distinct so that we can identify
5557 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5558 ;; the operation is never inserted into a delay slot.
5559 (define_insn "r10k_cache_barrier"
5560   [(set (mem:BLK (scratch))
5561         (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5562   "ISA_HAS_CACHE"
5563   "cache\t0x14,0(%$)"
5564   [(set_attr "can_delay" "no")])
5566 ;; Block moves, see mips.c for more details.
5567 ;; Argument 0 is the destination
5568 ;; Argument 1 is the source
5569 ;; Argument 2 is the length
5570 ;; Argument 3 is the alignment
5572 (define_expand "movmemsi"
5573   [(parallel [(set (match_operand:BLK 0 "general_operand")
5574                    (match_operand:BLK 1 "general_operand"))
5575               (use (match_operand:SI 2 ""))
5576               (use (match_operand:SI 3 "const_int_operand"))])]
5577   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5579   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5580     DONE;
5581   else
5582     FAIL;
5586 ;;  ....................
5588 ;;      SHIFTS
5590 ;;  ....................
5592 (define_expand "<optab><mode>3"
5593   [(set (match_operand:GPR 0 "register_operand")
5594         (any_shift:GPR (match_operand:GPR 1 "register_operand")
5595                        (match_operand:SI 2 "arith_operand")))]
5596   ""
5598   /* On the mips16, a shift of more than 8 is a four byte instruction,
5599      so, for a shift between 8 and 16, it is just as fast to do two
5600      shifts of 8 or less.  If there is a lot of shifting going on, we
5601      may win in CSE.  Otherwise combine will put the shifts back
5602      together again.  This can be called by mips_function_arg, so we must
5603      be careful not to allocate a new register if we've reached the
5604      reload pass.  */
5605   if (TARGET_MIPS16
5606       && optimize
5607       && CONST_INT_P (operands[2])
5608       && INTVAL (operands[2]) > 8
5609       && INTVAL (operands[2]) <= 16
5610       && !reload_in_progress
5611       && !reload_completed)
5612     {
5613       rtx temp = gen_reg_rtx (<MODE>mode);
5615       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5616       emit_insn (gen_<optab><mode>3 (operands[0], temp,
5617                                      GEN_INT (INTVAL (operands[2]) - 8)));
5618       DONE;
5619     }
5622 (define_insn "*<optab><mode>3"
5623   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5624         (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5625                        (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5626   "!TARGET_MIPS16"
5628   if (CONST_INT_P (operands[2]))
5629     operands[2] = GEN_INT (INTVAL (operands[2])
5630                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5632   return "<d><insn>\t%0,%1,%2";
5634   [(set_attr "type" "shift")
5635    (set_attr "compression" "<shift_compression>,none")
5636    (set_attr "mode" "<MODE>")])
5638 (define_insn "*<optab>si3_extend"
5639   [(set (match_operand:DI 0 "register_operand" "=d")
5640         (sign_extend:DI
5641            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5642                          (match_operand:SI 2 "arith_operand" "dI"))))]
5643   "TARGET_64BIT && !TARGET_MIPS16"
5645   if (CONST_INT_P (operands[2]))
5646     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5648   return "<insn>\t%0,%1,%2";
5650   [(set_attr "type" "shift")
5651    (set_attr "mode" "SI")])
5653 (define_insn "*<optab>si3_mips16"
5654   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5655         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5656                       (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5657   "TARGET_MIPS16"
5659   if (which_alternative == 0)
5660     return "<insn>\t%0,%2";
5662   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5663   return "<insn>\t%0,%1,%2";
5665   [(set_attr "type" "shift")
5666    (set_attr "mode" "SI")
5667    (set_attr "extended_mips16" "no,no,yes")])
5669 (define_insn "<GPR:d>lsa"
5670  [(set (match_operand:GPR 0 "register_operand" "=d")
5671        (plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
5672                              (match_operand 2 "const_immlsa_operand" ""))
5673                 (match_operand:GPR 3 "register_operand" "d")))]
5674  "ISA_HAS_<GPR:D>LSA"
5675  "<GPR:d>lsa\t%0,%1,%3,%2"
5676  [(set_attr "type" "arith")
5677   (set_attr "mode" "<GPR:MODE>")])
5679 ;; We need separate DImode MIPS16 patterns because of the irregularity
5680 ;; of right shifts.
5681 (define_insn "*ashldi3_mips16"
5682   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5683         (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5684                    (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5685   "TARGET_64BIT && TARGET_MIPS16"
5687   if (which_alternative == 0)
5688     return "dsll\t%0,%2";
5690   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5691   return "dsll\t%0,%1,%2";
5693   [(set_attr "type" "shift")
5694    (set_attr "mode" "DI")
5695    (set_attr "extended_mips16" "no,no,yes")])
5697 (define_insn "*ashrdi3_mips16"
5698   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5699         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5700                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5701   "TARGET_64BIT && TARGET_MIPS16"
5703   if (CONST_INT_P (operands[2]))
5704     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5706   return "dsra\t%0,%2";
5708   [(set_attr "type" "shift")
5709    (set_attr "mode" "DI")
5710    (set_attr "extended_mips16" "no,no,yes")])
5712 (define_insn "*lshrdi3_mips16"
5713   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5714         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5715                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5716   "TARGET_64BIT && TARGET_MIPS16"
5718   if (CONST_INT_P (operands[2]))
5719     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5721   return "dsrl\t%0,%2";
5723   [(set_attr "type" "shift")
5724    (set_attr "mode" "DI")
5725    (set_attr "extended_mips16" "no,no,yes")])
5727 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5729 (define_split
5730   [(set (match_operand:GPR 0 "d_operand")
5731         (any_shift:GPR (match_operand:GPR 1 "d_operand")
5732                        (match_operand:GPR 2 "const_int_operand")))]
5733   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5734    && INTVAL (operands[2]) > 8
5735    && INTVAL (operands[2]) <= 16"
5736   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5737    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5738   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5740 ;; If we load a byte on the mips16 as a bitfield, the resulting
5741 ;; sequence of instructions is too complicated for combine, because it
5742 ;; involves four instructions: a load, a shift, a constant load into a
5743 ;; register, and an and (the key problem here is that the mips16 does
5744 ;; not have and immediate).  We recognize a shift of a load in order
5745 ;; to make it simple enough for combine to understand.
5747 ;; The instruction count here is the worst case.
5748 (define_insn_and_split ""
5749   [(set (match_operand:SI 0 "register_operand" "=d")
5750         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5751                      (match_operand:SI 2 "immediate_operand" "I")))]
5752   "TARGET_MIPS16"
5753   "#"
5754   ""
5755   [(set (match_dup 0) (match_dup 1))
5756    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5757   ""
5758   [(set_attr "type"     "load")
5759    (set_attr "mode"     "SI")
5760    (set (attr "insn_count")
5761         (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5763 (define_insn "rotr<mode>3"
5764   [(set (match_operand:GPR 0 "register_operand" "=d")
5765         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5766                       (match_operand:SI 2 "arith_operand" "dI")))]
5767   "ISA_HAS_ROR"
5769   if (CONST_INT_P (operands[2]))
5770     gcc_assert (INTVAL (operands[2]) >= 0
5771                 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5773   return "<d>ror\t%0,%1,%2";
5775   [(set_attr "type" "shift")
5776    (set_attr "mode" "<MODE>")])
5778 (define_insn "bswaphi2"
5779   [(set (match_operand:HI 0 "register_operand" "=d")
5780         (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5781   "ISA_HAS_WSBH"
5782   "wsbh\t%0,%1"
5783   [(set_attr "type" "shift")])
5785 (define_insn_and_split "bswapsi2"
5786   [(set (match_operand:SI 0 "register_operand" "=d")
5787         (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5788   "ISA_HAS_WSBH && ISA_HAS_ROR"
5789   "#"
5790   ""
5791   [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5792    (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5793   ""
5794   [(set_attr "insn_count" "2")])
5796 (define_insn_and_split "bswapdi2"
5797   [(set (match_operand:DI 0 "register_operand" "=d")
5798         (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5799   "TARGET_64BIT && ISA_HAS_WSBH"
5800   "#"
5801   ""
5802   [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5803    (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5804   ""
5805   [(set_attr "insn_count" "2")])
5807 (define_insn "wsbh"
5808   [(set (match_operand:SI 0 "register_operand" "=d")
5809         (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5810   "ISA_HAS_WSBH"
5811   "wsbh\t%0,%1"
5812   [(set_attr "type" "shift")])
5814 (define_insn "dsbh"
5815   [(set (match_operand:DI 0 "register_operand" "=d")
5816         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5817   "TARGET_64BIT && ISA_HAS_WSBH"
5818   "dsbh\t%0,%1"
5819   [(set_attr "type" "shift")])
5821 (define_insn "dshd"
5822   [(set (match_operand:DI 0 "register_operand" "=d")
5823         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5824   "TARGET_64BIT && ISA_HAS_WSBH"
5825   "dshd\t%0,%1"
5826   [(set_attr "type" "shift")])
5829 ;;  ....................
5831 ;;      CONDITIONAL BRANCHES
5833 ;;  ....................
5835 ;; Conditional branches on floating-point equality tests.
5837 (define_insn "*branch_fp_<mode>"
5838   [(set (pc)
5839         (if_then_else
5840          (match_operator 1 "equality_operator"
5841                          [(match_operand:FPCC 2 "register_operand" "<reg>")
5842                           (const_int 0)])
5843          (label_ref (match_operand 0 "" ""))
5844          (pc)))]
5845   "TARGET_HARD_FLOAT"
5847   return mips_output_conditional_branch (insn, operands,
5848                                          MIPS_BRANCH ("b%F1", "%Z2%0"),
5849                                          MIPS_BRANCH ("b%W1", "%Z2%0"));
5851   [(set_attr "type" "branch")])
5853 (define_insn "*branch_fp_inverted_<mode>"
5854   [(set (pc)
5855         (if_then_else
5856          (match_operator 1 "equality_operator"
5857                          [(match_operand:FPCC 2 "register_operand" "<reg>")
5858                           (const_int 0)])
5859          (pc)
5860          (label_ref (match_operand 0 "" ""))))]
5861   "TARGET_HARD_FLOAT"
5863   return mips_output_conditional_branch (insn, operands,
5864                                          MIPS_BRANCH ("b%W1", "%Z2%0"),
5865                                          MIPS_BRANCH ("b%F1", "%Z2%0"));
5867   [(set_attr "type" "branch")])
5869 ;; Conditional branches on ordered comparisons with zero.
5871 (define_insn "*branch_order<mode>"
5872   [(set (pc)
5873         (if_then_else
5874          (match_operator 1 "order_operator"
5875                          [(match_operand:GPR 2 "register_operand" "d,d")
5876                           (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5877          (label_ref (match_operand 0 "" ""))
5878          (pc)))]
5879   "!TARGET_MIPS16"
5880   { return mips_output_order_conditional_branch (insn, operands, false); }
5881   [(set_attr "type" "branch")
5882    (set_attr "compact_form" "maybe,always")
5883    (set_attr "hazard" "forbidden_slot")])
5885 (define_insn "*branch_order<mode>_inverted"
5886   [(set (pc)
5887         (if_then_else
5888          (match_operator 1 "order_operator"
5889                          [(match_operand:GPR 2 "register_operand" "d,d")
5890                           (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5891          (pc)
5892          (label_ref (match_operand 0 "" ""))))]
5893   "!TARGET_MIPS16"
5894   { return mips_output_order_conditional_branch (insn, operands, true); }
5895   [(set_attr "type" "branch")
5896    (set_attr "compact_form" "maybe,always")
5897    (set_attr "hazard" "forbidden_slot")])
5899 ;; Conditional branch on equality comparison.
5901 (define_insn "*branch_equality<mode>"
5902   [(set (pc)
5903         (if_then_else
5904          (match_operator 1 "equality_operator"
5905                          [(match_operand:GPR 2 "register_operand" "d")
5906                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5907          (label_ref (match_operand 0 "" ""))
5908          (pc)))]
5909   "!TARGET_MIPS16"
5910   { return mips_output_equal_conditional_branch (insn, operands, false); }
5911   [(set_attr "type" "branch")
5912    (set_attr "compact_form" "maybe")
5913    (set_attr "hazard" "forbidden_slot")])
5915 (define_insn "*branch_equality<mode>_inverted"
5916   [(set (pc)
5917         (if_then_else
5918          (match_operator 1 "equality_operator"
5919                          [(match_operand:GPR 2 "register_operand" "d")
5920                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5921          (pc)
5922          (label_ref (match_operand 0 "" ""))))]
5923   "!TARGET_MIPS16"
5924   { return mips_output_equal_conditional_branch (insn, operands, true); }
5925   [(set_attr "type" "branch")
5926    (set_attr "compact_form" "maybe")
5927    (set_attr "hazard" "forbidden_slot")])
5929 ;; MIPS16 branches
5931 (define_insn "*branch_equality<mode>_mips16"
5932   [(set (pc)
5933         (if_then_else
5934          (match_operator 1 "equality_operator"
5935                          [(match_operand:GPR 2 "register_operand" "d,t")
5936                           (const_int 0)])
5937          (label_ref (match_operand 0 "" ""))
5938          (pc)))]
5939   "TARGET_MIPS16"
5940   "@
5941    b%C1z\t%2,%0
5942    bt%C1z\t%0"
5943   [(set_attr "type" "branch")])
5945 (define_insn "*branch_equality<mode>_mips16_inverted"
5946   [(set (pc)
5947         (if_then_else
5948          (match_operator 1 "equality_operator"
5949                          [(match_operand:GPR 2 "register_operand" "d,t")
5950                           (const_int 0)])
5951          (pc)
5952          (label_ref (match_operand 0 "" ""))))]
5953   "TARGET_MIPS16"
5954   "@
5955    b%N1z\t%2,%0
5956    bt%N1z\t%0"
5957   [(set_attr "type" "branch")])
5959 (define_expand "cbranch<mode>4"
5960   [(set (pc)
5961         (if_then_else (match_operator 0 "comparison_operator"
5962                        [(match_operand:GPR 1 "register_operand")
5963                         (match_operand:GPR 2 "nonmemory_operand")])
5964                       (label_ref (match_operand 3 ""))
5965                       (pc)))]
5966   ""
5968   mips_expand_conditional_branch (operands);
5969   DONE;
5972 (define_expand "cbranch<mode>4"
5973   [(set (pc)
5974         (if_then_else (match_operator 0 "comparison_operator"
5975                        [(match_operand:SCALARF 1 "register_operand")
5976                         (match_operand:SCALARF 2 "register_operand")])
5977                       (label_ref (match_operand 3 ""))
5978                       (pc)))]
5979   ""
5981   mips_expand_conditional_branch (operands);
5982   DONE;
5985 ;; Used to implement built-in functions.
5986 (define_expand "condjump"
5987   [(set (pc)
5988         (if_then_else (match_operand 0)
5989                       (label_ref (match_operand 1))
5990                       (pc)))])
5992 ;; Branch if bit is set/clear.
5994 (define_insn "*branch_bit<bbv><mode>"
5995   [(set (pc)
5996         (if_then_else
5997          (equality_op (zero_extract:GPR
5998                        (match_operand:GPR 1 "register_operand" "d")
5999                        (const_int 1)
6000                        (match_operand 2 "const_int_operand" ""))
6001                       (const_int 0))
6002          (label_ref (match_operand 0 ""))
6003          (pc)))]
6004   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6006   return
6007     mips_output_conditional_branch (insn, operands,
6008                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
6009                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
6011   [(set_attr "type"          "branch")
6012    (set_attr "branch_likely" "no")])
6014 (define_insn "*branch_bit<bbv><mode>_inverted"
6015   [(set (pc)
6016         (if_then_else
6017          (equality_op (zero_extract:GPR
6018                        (match_operand:GPR 1 "register_operand" "d")
6019                        (const_int 1)
6020                        (match_operand 2 "const_int_operand" ""))
6021                       (const_int 0))
6022          (pc)
6023          (label_ref (match_operand 0 ""))))]
6024   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6026   return
6027     mips_output_conditional_branch (insn, operands,
6028                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
6029                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
6031   [(set_attr "type"          "branch")
6032    (set_attr "branch_likely" "no")])
6035 ;;  ....................
6037 ;;      SETTING A REGISTER FROM A COMPARISON
6039 ;;  ....................
6041 ;; Destination is always set in SI mode.
6043 (define_expand "cstore<mode>4"
6044   [(set (match_operand:SI 0 "register_operand")
6045         (match_operator:SI 1 "mips_cstore_operator"
6046          [(match_operand:GPR 2 "register_operand")
6047           (match_operand:GPR 3 "nonmemory_operand")]))]
6048   ""
6050   mips_expand_scc (operands);
6051   DONE;
6054 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
6055   [(set (match_operand:GPR2 0 "register_operand" "=d")
6056         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6057                  (const_int 0)))]
6058   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6059   "sltu\t%0,%1,1"
6060   [(set_attr "type" "slt")
6061    (set_attr "mode" "<GPR:MODE>")])
6063 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
6064   [(set (match_operand:GPR2 0 "register_operand" "=t")
6065         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6066                  (const_int 0)))]
6067   "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6068   "sltu\t%1,1"
6069   [(set_attr "type" "slt")
6070    (set_attr "mode" "<GPR:MODE>")])
6072 ;; Generate sltiu unless using seq results in better code.
6073 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
6074   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6075         (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6076                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6077   "ISA_HAS_SEQ_SNE"
6078   "@
6079    seq\t%0,%1,%2
6080    sltiu\t%0,%1,1
6081    seqi\t%0,%1,%2"
6082   [(set_attr "type" "slt")
6083    (set_attr "mode" "<GPR:MODE>")])
6085 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
6086   [(set (match_operand:GPR2 0 "register_operand" "=d")
6087         (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
6088                  (const_int 0)))]
6089   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6090   "sltu\t%0,%.,%1"
6091   [(set_attr "type" "slt")
6092    (set_attr "mode" "<GPR:MODE>")])
6094 ;; Generate sltu unless using sne results in better code.
6095 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
6096   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6097         (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6098                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6099   "ISA_HAS_SEQ_SNE"
6100   "@
6101    sne\t%0,%1,%2
6102    sltu\t%0,%.,%1
6103    snei\t%0,%1,%2"
6104   [(set_attr "type" "slt")
6105    (set_attr "mode" "<GPR:MODE>")])
6107 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
6108   [(set (match_operand:GPR2 0 "register_operand" "=d")
6109         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6110                      (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
6111   "!TARGET_MIPS16"
6112   "slt<u>\t%0,%z2,%1"
6113   [(set_attr "type" "slt")
6114    (set_attr "mode" "<GPR:MODE>")])
6116 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
6117   [(set (match_operand:GPR2 0 "register_operand" "=t")
6118         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6119                      (match_operand:GPR 2 "register_operand" "d")))]
6120   "TARGET_MIPS16"
6121   "slt<u>\t%2,%1"
6122   [(set_attr "type" "slt")
6123    (set_attr "mode" "<GPR:MODE>")])
6125 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6126   [(set (match_operand:GPR2 0 "register_operand" "=d")
6127         (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6128                      (const_int 1)))]
6129   "!TARGET_MIPS16"
6130   "slt<u>\t%0,%.,%1"
6131   [(set_attr "type" "slt")
6132    (set_attr "mode" "<GPR:MODE>")])
6134 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6135   [(set (match_operand:GPR2 0 "register_operand" "=d")
6136         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6137                      (match_operand:GPR 2 "arith_operand" "dI")))]
6138   "!TARGET_MIPS16"
6139   "slt<u>\t%0,%1,%2"
6140   [(set_attr "type" "slt")
6141    (set_attr "mode" "<GPR:MODE>")])
6143 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6144   [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6145         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6146                      (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6147   "TARGET_MIPS16"
6148   "slt<u>\t%1,%2"
6149   [(set_attr "type" "slt")
6150    (set_attr "mode" "<GPR:MODE>")
6151    (set_attr "extended_mips16" "no,no,yes")])
6153 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6154   [(set (match_operand:GPR2 0 "register_operand" "=d")
6155         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6156                      (match_operand:GPR 2 "sle_operand" "")))]
6157   "!TARGET_MIPS16"
6159   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6160   return "slt<u>\t%0,%1,%2";
6162   [(set_attr "type" "slt")
6163    (set_attr "mode" "<GPR:MODE>")])
6165 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6166   [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6167         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6168                      (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6169   "TARGET_MIPS16"
6171   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6172   return "slt<u>\t%1,%2";
6174   [(set_attr "type" "slt")
6175    (set_attr "mode" "<GPR:MODE>")
6176    (set_attr "extended_mips16" "no,yes")])
6179 ;;  ....................
6181 ;;      FLOATING POINT COMPARISONS
6183 ;;  ....................
6185 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6186   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6187         (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6188                     (match_operand:SCALARF 2 "register_operand" "f")))]
6189   ""
6190   "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6191   [(set_attr "type" "fcmp")
6192    (set_attr "mode" "FPSW")])
6194 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6195   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6196         (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6197                             (match_operand:SCALARF 2 "register_operand" "f")))]
6198   ""
6199   "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6200   [(set_attr "type" "fcmp")
6201    (set_attr "mode" "FPSW")])
6204 ;;  ....................
6206 ;;      UNCONDITIONAL BRANCHES
6208 ;;  ....................
6210 ;; Unconditional branches.
6212 (define_expand "jump"
6213   [(set (pc)
6214         (label_ref (match_operand 0)))])
6216 (define_insn "*jump_absolute"
6217   [(set (pc)
6218         (label_ref (match_operand 0)))]
6219   "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6221   if (get_attr_length (insn) <= 8)
6222     {
6223       if (TARGET_CB_MAYBE)
6224         return MIPS_ABSOLUTE_JUMP ("%*b%:\t%l0");
6225       else
6226         return MIPS_ABSOLUTE_JUMP ("%*b\t%l0%/");
6227     }
6228   else
6229     {
6230       if (TARGET_CB_MAYBE && !final_sequence)
6231         return MIPS_ABSOLUTE_JUMP ("%*bc\t%l0");
6232       else
6233         return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6234     }
6236   [(set_attr "type" "branch")
6237    (set_attr "compact_form" "maybe")])
6239 (define_insn "*jump_pic"
6240   [(set (pc)
6241         (label_ref (match_operand 0)))]
6242   "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6244   if (get_attr_length (insn) <= 8)
6245     {
6246       if (TARGET_CB_MAYBE)
6247         return "%*b%:\t%l0";
6248       else
6249         return "%*b\t%l0%/";
6250     }
6251   else
6252     {
6253       mips_output_load_label (operands[0]);
6254       if (TARGET_CB_MAYBE)
6255         return "%*jr%:\t%@%]";
6256       else
6257         return "%*jr\t%@%/%]";
6258     }
6260   [(set_attr "type" "branch")
6261    (set_attr "compact_form" "maybe")])
6263 ;; We need a different insn for the mips16, because a mips16 branch
6264 ;; does not have a delay slot.
6266 (define_insn "*jump_mips16"
6267   [(set (pc)
6268         (label_ref (match_operand 0 "" "")))]
6269   "TARGET_MIPS16"
6270   "b\t%l0"
6271   [(set_attr "type" "branch")
6272    (set (attr "length")
6273         ;; This calculation is like the normal branch one, but the
6274         ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6275         ;; than [-0x100, 0xfe].  This translates to a range of:
6276         ;;
6277         ;;    [-(0x800 - sizeof (branch)), 0x7fe]
6278         ;; == [-0x7fe, 0x7fe]
6279         ;;
6280         ;; from the shorten_branches reference address.  Long-branch
6281         ;; sequences will replace this one, so the minimum length
6282         ;; is one instruction shorter than for conditional branches.
6283         (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6284                     (le (minus (pc) (match_dup 0)) (const_int 2046)))
6285                (const_int 2)
6286                (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6287                     (le (minus (pc) (match_dup 0)) (const_int 65532)))
6288                (const_int 4)
6289                (and (match_test "TARGET_ABICALLS")
6290                     (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6291                (const_int 18)
6292                (match_test "Pmode == SImode")
6293                (const_int 14)
6294                ] (const_int 22)))])
6296 (define_expand "indirect_jump"
6297   [(set (pc) (match_operand 0 "register_operand"))]
6298   ""
6300   operands[0] = force_reg (Pmode, operands[0]);
6301   emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6302   DONE;
6305 (define_insn "indirect_jump_<mode>"
6306   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6307   ""
6308   {
6309     return mips_output_jump (operands, 0, -1, false);
6310   }
6311   [(set_attr "type" "jump")
6312    (set_attr "mode" "none")])
6314 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6315 ;; sequences.  Having a dedicated pattern is more convenient than
6316 ;; creating a SEQUENCE for this special case.
6317 (define_insn "indirect_jump_and_restore_<mode>"
6318   [(set (pc) (match_operand:P 1 "register_operand" "d"))
6319    (set (match_operand:P 0 "register_operand" "=d")
6320         (match_operand:P 2 "register_operand" "y"))]
6321   ""
6322   "%(%<jr\t%1\;move\t%0,%2%>%)"
6323   [(set_attr "type" "multi")
6324    (set_attr "extended_mips16" "yes")])
6326 (define_expand "tablejump"
6327   [(set (pc)
6328         (match_operand 0 "register_operand"))
6329    (use (label_ref (match_operand 1 "")))]
6330   "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6332   if (TARGET_GPWORD)
6333     operands[0] = expand_binop (Pmode, add_optab, operands[0],
6334                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6335   else if (TARGET_RTP_PIC)
6336     {
6337       /* When generating RTP PIC, we use case table entries that are relative
6338          to the start of the function.  Add the function's address to the
6339          value we loaded.  */
6340       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6341       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6342                                   start, 0, 0, OPTAB_WIDEN);
6343     }
6345   emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6346   DONE;
6349 (define_insn "tablejump_<mode>"
6350   [(set (pc)
6351         (match_operand:P 0 "register_operand" "d"))
6352    (use (label_ref (match_operand 1 "" "")))]
6353   ""
6354   {
6355     return mips_output_jump (operands, 0, -1, false);
6356   }
6357   [(set_attr "type" "jump")
6358    (set_attr "mode" "none")])
6360 ;; For MIPS16, we don't know whether a given jump table will use short or
6361 ;; word-sized offsets until late in compilation, when we are able to determine
6362 ;; the sizes of the insns which comprise the containing function.  This
6363 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6364 ;; the latter tries to calculate the index of the offset to jump through early
6365 ;; in compilation, i.e. at expand time, when nothing is known about the
6366 ;; eventual function layout.
6368 (define_expand "casesi"
6369   [(match_operand:SI 0 "register_operand" "")   ; index to jump on
6370    (match_operand:SI 1 "const_int_operand" "")  ; lower bound
6371    (match_operand:SI 2 "const_int_operand" "")  ; total range
6372    (match_operand 3 "" "")                      ; table label
6373    (match_operand 4 "" "")]                     ; out of range label
6374   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6376   if (operands[1] != const0_rtx)
6377     {
6378       rtx reg = gen_reg_rtx (SImode);
6379       rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6380       
6381       if (!arith_operand (offset, SImode))
6382         offset = force_reg (SImode, offset);
6383       
6384       emit_insn (gen_addsi3 (reg, operands[0], offset));
6385       operands[0] = reg;
6386     }
6388   if (!arith_operand (operands[0], SImode))
6389     operands[0] = force_reg (SImode, operands[0]);
6391   emit_cmp_and_jump_insns (operands[0], operands[2], GTU,
6392                            NULL_RTX, SImode, 1, operands[4]);
6393   emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6394                               (operands[0], operands[3])));
6395   DONE;
6398 (define_insn "casesi_internal_mips16_<mode>"
6399   [(set (pc)
6400         (unspec:P [(match_operand:SI 0 "register_operand" "d")
6401                    (label_ref (match_operand 1 "" ""))]
6402          UNSPEC_CASESI_DISPATCH))
6403    (clobber (match_scratch:P 2 "=d"))
6404    (clobber (match_scratch:P 3 "=d"))]
6405   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6407   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[1])));
6409   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6411   switch (GET_MODE (diff_vec))
6412     {
6413     case HImode:
6414       output_asm_insn ("sll\t%3,%0,1", operands);
6415       output_asm_insn ("<d>la\t%2,%1", operands);
6416       output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6417       output_asm_insn ("lh\t%3,0(%3)", operands);
6418       break;
6420     case SImode:
6421       output_asm_insn ("sll\t%3,%0,2", operands);
6422       output_asm_insn ("<d>la\t%2,%1", operands);
6423       output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6424       output_asm_insn ("lw\t%3,0(%3)", operands);
6425       break;
6427     default:
6428       gcc_unreachable ();
6429     }
6431   output_asm_insn ("<d>addu\t%2,%2,%3", operands);
6433   if (GENERATE_MIPS16E)
6434     return "jrc\t%2";
6435   else
6436     return "jr\t%2";
6438   [(set (attr "insn_count")
6439         (if_then_else (match_test "GENERATE_MIPS16E")
6440                       (const_string "6")
6441                       (const_string "7")))])
6443 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6444 ;; While it is possible to either pull it off the stack (in the
6445 ;; o32 case) or recalculate it given t9 and our target label,
6446 ;; it takes 3 or 4 insns to do so.
6448 (define_expand "builtin_setjmp_setup"
6449   [(use (match_operand 0 "register_operand"))]
6450   "TARGET_USE_GOT"
6452   rtx addr;
6454   addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6455   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6456   DONE;
6459 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
6460 ;; that older code did recalculate the gp from $25.  Continue to jump through
6461 ;; $25 for compatibility (we lose nothing by doing so).
6463 (define_expand "builtin_longjmp"
6464   [(use (match_operand 0 "register_operand"))]
6465   "TARGET_USE_GOT"
6467   /* The elements of the buffer are, in order:  */
6468   int W = GET_MODE_SIZE (Pmode);
6469   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6470   rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6471   rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6472   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6473   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6474   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6475      The target is bound to be using $28 as the global pointer
6476      but the current function might not be.  */
6477   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6479   /* This bit is similar to expand_builtin_longjmp except that it
6480      restores $gp as well.  */
6481   mips_emit_move (hard_frame_pointer_rtx, fp);
6482   mips_emit_move (pv, lab);
6483   emit_stack_restore (SAVE_NONLOCAL, stack);
6484   mips_emit_move (gp, gpv);
6485   emit_use (hard_frame_pointer_rtx);
6486   emit_use (stack_pointer_rtx);
6487   emit_use (gp);
6488   emit_indirect_jump (pv);
6489   DONE;
6493 ;;  ....................
6495 ;;      Function prologue/epilogue
6497 ;;  ....................
6500 (define_expand "prologue"
6501   [(const_int 1)]
6502   ""
6504   mips_expand_prologue ();
6505   DONE;
6508 ;; Block any insns from being moved before this point, since the
6509 ;; profiling call to mcount can use various registers that aren't
6510 ;; saved or used to pass arguments.
6512 (define_insn "blockage"
6513   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6514   ""
6515   ""
6516   [(set_attr "type" "ghost")
6517    (set_attr "mode" "none")])
6519 (define_insn "probe_stack_range_<P:mode>"
6520   [(set (match_operand:P 0 "register_operand" "=d")
6521         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6522                             (match_operand:P 2 "register_operand" "d")]
6523                             UNSPEC_PROBE_STACK_RANGE))]
6524   ""
6525  { return mips_output_probe_stack_range (operands[0], operands[2]); }
6526   [(set_attr "type" "unknown")
6527    (set_attr "can_delay" "no")
6528    (set_attr "mode" "<MODE>")])
6530 (define_expand "epilogue"
6531   [(const_int 2)]
6532   ""
6534   mips_expand_epilogue (false);
6535   DONE;
6538 (define_expand "sibcall_epilogue"
6539   [(const_int 2)]
6540   ""
6542   mips_expand_epilogue (true);
6543   DONE;
6546 ;; Trivial return.  Make it look like a normal return insn as that
6547 ;; allows jump optimizations to work better.
6549 (define_expand "return"
6550   [(simple_return)]
6551   "mips_can_use_return_insn ()"
6552   { mips_expand_before_return (); })
6554 (define_expand "simple_return"
6555   [(simple_return)]
6556   ""
6557   { mips_expand_before_return (); })
6559 (define_insn "*<optab>"
6560   [(any_return)]
6561   ""
6562   {
6563     operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
6564     return mips_output_jump (operands, 0, -1, false);
6565   }
6566   [(set_attr "type"     "jump")
6567    (set_attr "mode"     "none")])
6569 ;; Normal return.
6571 (define_insn "<optab>_internal"
6572   [(any_return)
6573    (use (match_operand 0 "pmode_register_operand" ""))]
6574   ""
6575   {
6576     return mips_output_jump (operands, 0, -1, false);
6577   }
6578   [(set_attr "type"     "jump")
6579    (set_attr "mode"     "none")])
6581 ;; Exception return.
6582 (define_insn "mips_eret"
6583   [(return)
6584    (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6585   ""
6586   "eret"
6587   [(set_attr "type"     "trap")
6588    (set_attr "mode"     "none")])
6590 ;; Debug exception return.
6591 (define_insn "mips_deret"
6592   [(return)
6593    (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6594   ""
6595   "deret"
6596   [(set_attr "type"     "trap")
6597    (set_attr "mode"     "none")])
6599 ;; Disable interrupts.
6600 (define_insn "mips_di"
6601   [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6602   ""
6603   "di"
6604   [(set_attr "type"     "trap")
6605    (set_attr "mode"     "none")])
6607 ;; Execution hazard barrier.
6608 (define_insn "mips_ehb"
6609   [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6610   ""
6611   "ehb"
6612   [(set_attr "type"     "trap")
6613    (set_attr "mode"     "none")])
6615 ;; Read GPR from previous shadow register set.
6616 (define_insn "mips_rdpgpr_<mode>"
6617   [(set (match_operand:P 0 "register_operand" "=d")
6618         (unspec_volatile:P [(match_operand:P 1 "register_operand" "d")]
6619                            UNSPEC_RDPGPR))]
6620   ""
6621   "rdpgpr\t%0,%1"
6622   [(set_attr "type"     "move")
6623    (set_attr "mode"     "<MODE>")])
6625 ;; Move involving COP0 registers.
6626 (define_insn "cop0_move"
6627   [(set (match_operand:SI 0 "register_operand" "=B,d")
6628         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6629                             UNSPEC_COP0))]
6630   ""
6631 { return mips_output_move (operands[0], operands[1]); }
6632   [(set_attr "type"     "mtc,mfc")
6633    (set_attr "mode"     "SI")])
6635 ;; This is used in compiling the unwind routines.
6636 (define_expand "eh_return"
6637   [(use (match_operand 0 "general_operand"))]
6638   ""
6640   if (GET_MODE (operands[0]) != word_mode)
6641     operands[0] = convert_to_mode (word_mode, operands[0], 0);
6642   if (TARGET_64BIT)
6643     emit_insn (gen_eh_set_lr_di (operands[0]));
6644   else
6645     emit_insn (gen_eh_set_lr_si (operands[0]));
6646   DONE;
6649 ;; Clobber the return address on the stack.  We can't expand this
6650 ;; until we know where it will be put in the stack frame.
6652 (define_insn "eh_set_lr_si"
6653   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6654    (clobber (match_scratch:SI 1 "=&d"))]
6655   "! TARGET_64BIT"
6656   "#")
6658 (define_insn "eh_set_lr_di"
6659   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6660    (clobber (match_scratch:DI 1 "=&d"))]
6661   "TARGET_64BIT"
6662   "#")
6664 (define_split
6665   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6666    (clobber (match_scratch 1))]
6667   "reload_completed"
6668   [(const_int 0)]
6670   mips_set_return_address (operands[0], operands[1]);
6671   DONE;
6674 (define_expand "exception_receiver"
6675   [(const_int 0)]
6676   "TARGET_USE_GOT"
6678   /* See the comment above load_call<mode> for details.  */
6679   emit_insn (gen_set_got_version ());
6681   /* If we have a call-clobbered $gp, restore it from its save slot.  */
6682   if (HAVE_restore_gp_si)
6683     emit_insn (gen_restore_gp_si ());
6684   else if (HAVE_restore_gp_di)
6685     emit_insn (gen_restore_gp_di ());
6686   DONE;
6689 (define_expand "nonlocal_goto_receiver"
6690   [(const_int 0)]
6691   "TARGET_USE_GOT"
6693   /* See the comment above load_call<mode> for details.  */
6694   emit_insn (gen_set_got_version ());
6695   DONE;
6698 ;; Restore $gp from its .cprestore stack slot.  The instruction remains
6699 ;; volatile until all uses of $28 are exposed.
6700 (define_insn_and_split "restore_gp_<mode>"
6701   [(set (reg:P 28)
6702         (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6703    (clobber (match_scratch:P 0 "=&d"))]
6704   "TARGET_CALL_CLOBBERED_GP"
6705   "#"
6706   "&& epilogue_completed"
6707   [(const_int 0)]
6709   mips_restore_gp_from_cprestore_slot (operands[0]);
6710   DONE;
6712   [(set_attr "type" "ghost")])
6714 ;; Move between $gp and its register save slot.
6715 (define_insn_and_split "move_gp<mode>"
6716   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6717         (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6718                     UNSPEC_MOVE_GP))]
6719   ""
6720   { return mips_must_initialize_gp_p () ? "#" : ""; }
6721   "mips_must_initialize_gp_p ()"
6722   [(const_int 0)]
6724   mips_emit_move (operands[0], operands[1]);
6725   DONE;
6727   [(set_attr "type" "ghost")])
6730 ;;  ....................
6732 ;;      FUNCTION CALLS
6734 ;;  ....................
6736 ;; Instructions to load a call address from the GOT.  The address might
6737 ;; point to a function or to a lazy binding stub.  In the latter case,
6738 ;; the stub will use the dynamic linker to resolve the function, which
6739 ;; in turn will change the GOT entry to point to the function's real
6740 ;; address.
6742 ;; This means that every call, even pure and constant ones, can
6743 ;; potentially modify the GOT entry.  And once a stub has been called,
6744 ;; we must not call it again.
6746 ;; We represent this restriction using an imaginary, fixed, call-saved
6747 ;; register called GOT_VERSION_REGNUM.  The idea is to make the register
6748 ;; live throughout the function and to change its value after every
6749 ;; potential call site.  This stops any rtx value that uses the register
6750 ;; from being computed before an earlier call.  To do this, we:
6752 ;;    - Ensure that the register is live on entry to the function,
6753 ;;      so that it is never thought to be used uninitalized.
6755 ;;    - Ensure that the register is live on exit from the function,
6756 ;;      so that it is live throughout.
6758 ;;    - Make each call (lazily-bound or not) use the current value
6759 ;;      of GOT_VERSION_REGNUM, so that updates of the register are
6760 ;;      not moved across call boundaries.
6762 ;;    - Add "ghost" definitions of the register to the beginning of
6763 ;;      blocks reached by EH and ABNORMAL_CALL edges, because those
6764 ;;      edges may involve calls that normal paths don't.  (E.g. the
6765 ;;      unwinding code that handles a non-call exception may change
6766 ;;      lazily-bound GOT entries.)  We do this by making the
6767 ;;      exception_receiver and nonlocal_goto_receiver expanders emit
6768 ;;      a set_got_version instruction.
6770 ;;    - After each call (lazily-bound or not), use a "ghost"
6771 ;;      update_got_version instruction to change the register's value.
6772 ;;      This instruction mimics the _possible_ effect of the dynamic
6773 ;;      resolver during the call and it remains live even if the call
6774 ;;      itself becomes dead.
6776 ;;    - Leave GOT_VERSION_REGNUM out of all register classes.
6777 ;;      The register is therefore not a valid register_operand
6778 ;;      and cannot be moved to or from other registers.
6780 (define_insn "load_call<mode>"
6781   [(set (match_operand:P 0 "register_operand" "=d")
6782         (unspec:P [(match_operand:P 1 "register_operand" "d")
6783                    (match_operand:P 2 "immediate_operand" "")
6784                    (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6785   "TARGET_USE_GOT"
6786   "<load>\t%0,%R2(%1)"
6787   [(set_attr "got" "load")
6788    (set_attr "mode" "<MODE>")])
6790 (define_insn "set_got_version"
6791   [(set (reg:SI GOT_VERSION_REGNUM)
6792         (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6793   "TARGET_USE_GOT"
6794   ""
6795   [(set_attr "type" "ghost")])
6797 (define_insn "update_got_version"
6798   [(set (reg:SI GOT_VERSION_REGNUM)
6799         (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6800   "TARGET_USE_GOT"
6801   ""
6802   [(set_attr "type" "ghost")])
6804 ;; Sibling calls.  All these patterns use jump instructions.
6806 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6807 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
6808 ;; is defined in terms of call_insn_operand, the same is true of the
6809 ;; constraints.
6811 ;; When we use an indirect jump, we need a register that will be
6812 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
6813 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6814 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6815 ;; as well.
6817 (define_expand "sibcall"
6818   [(parallel [(call (match_operand 0 "")
6819                     (match_operand 1 ""))
6820               (use (match_operand 2 ""))        ;; next_arg_reg
6821               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6822   "TARGET_SIBCALLS"
6824   mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6825                     operands[1], operands[2], false);
6826   DONE;
6829 (define_insn "sibcall_internal"
6830   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6831          (match_operand 1 "" ""))]
6832   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6833   { return mips_output_jump (operands, 0, 1, false); }
6834   [(set_attr "jal" "indirect,direct")
6835    (set_attr "jal_macro" "no")])
6837 (define_expand "sibcall_value"
6838   [(parallel [(set (match_operand 0 "")
6839                    (call (match_operand 1 "")
6840                          (match_operand 2 "")))
6841               (use (match_operand 3 ""))])]             ;; next_arg_reg
6842   "TARGET_SIBCALLS"
6844   mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6845                     operands[2], operands[3], false);
6846   DONE;
6849 (define_insn "sibcall_value_internal"
6850   [(set (match_operand 0 "register_operand" "")
6851         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6852               (match_operand 2 "" "")))]
6853   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6854   { return mips_output_jump (operands, 1, 2, false); }
6855   [(set_attr "jal" "indirect,direct")
6856    (set_attr "jal_macro" "no")])
6858 (define_insn "sibcall_value_multiple_internal"
6859   [(set (match_operand 0 "register_operand" "")
6860         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6861               (match_operand 2 "" "")))
6862    (set (match_operand 3 "register_operand" "")
6863         (call (mem:SI (match_dup 1))
6864               (match_dup 2)))]
6865   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6866   { return mips_output_jump (operands, 1, 2, false); }
6867   [(set_attr "jal" "indirect,direct")
6868    (set_attr "jal_macro" "no")])
6870 (define_expand "call"
6871   [(parallel [(call (match_operand 0 "")
6872                     (match_operand 1 ""))
6873               (use (match_operand 2 ""))        ;; next_arg_reg
6874               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
6875   ""
6877   mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6878                     operands[1], operands[2], false);
6879   DONE;
6882 ;; This instruction directly corresponds to an assembly-language "jal".
6883 ;; There are four cases:
6885 ;;    - -mno-abicalls:
6886 ;;        Both symbolic and register destinations are OK.  The pattern
6887 ;;        always expands to a single mips instruction.
6889 ;;    - -mabicalls/-mno-explicit-relocs:
6890 ;;        Again, both symbolic and register destinations are OK.
6891 ;;        The call is treated as a multi-instruction black box.
6893 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
6894 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
6895 ;;        instruction.
6897 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
6898 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
6899 ;;        "jalr $25" followed by an insn to reload $gp.
6901 ;; In the last case, we can generate the individual instructions with
6902 ;; a define_split.  There are several things to be wary of:
6904 ;;   - We can't expose the load of $gp before reload.  If we did,
6905 ;;     it might get removed as dead, but reload can introduce new
6906 ;;     uses of $gp by rematerializing constants.
6908 ;;   - We shouldn't restore $gp after calls that never return.
6909 ;;     It isn't valid to insert instructions between a noreturn
6910 ;;     call and the following barrier.
6912 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
6913 ;;     instruction preserves $gp and so have no effect on its liveness.
6914 ;;     But once we generate the separate insns, it becomes obvious that
6915 ;;     $gp is not live on entry to the call.
6917 (define_insn_and_split "call_internal"
6918   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6919          (match_operand 1 "" ""))
6920    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6921   ""
6922   {
6923     return (TARGET_SPLIT_CALLS ? "#"
6924             : mips_output_jump (operands, 0, 1, true));
6925   }
6926   "reload_completed && TARGET_SPLIT_CALLS"
6927   [(const_int 0)]
6929   mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6930   DONE;
6932   [(set_attr "jal" "indirect,direct")])
6934 (define_insn "call_split"
6935   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6936          (match_operand 1 "" ""))
6937    (clobber (reg:SI RETURN_ADDR_REGNUM))
6938    (clobber (reg:SI 28))]
6939   "TARGET_SPLIT_CALLS"
6940   { return mips_output_jump (operands, 0, 1, true); }
6941   [(set_attr "jal" "indirect,direct")
6942    (set_attr "jal_macro" "no")])
6944 ;; A pattern for calls that must be made directly.  It is used for
6945 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6946 ;; stub; the linker relies on the call relocation type to detect when
6947 ;; such redirection is needed.
6948 (define_insn_and_split "call_internal_direct"
6949   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6950          (match_operand 1))
6951    (const_int 1)
6952    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6953   ""
6954   {
6955     return (TARGET_SPLIT_CALLS ? "#"
6956             : mips_output_jump (operands, 0, -1, true));
6957   }
6958   "reload_completed && TARGET_SPLIT_CALLS"
6959   [(const_int 0)]
6961   mips_split_call (curr_insn,
6962                    gen_call_direct_split (operands[0], operands[1]));
6963   DONE;
6965   [(set_attr "jal" "direct")])
6967 (define_insn "call_direct_split"
6968   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6969          (match_operand 1))
6970    (const_int 1)
6971    (clobber (reg:SI RETURN_ADDR_REGNUM))
6972    (clobber (reg:SI 28))]
6973   "TARGET_SPLIT_CALLS"
6974   { return mips_output_jump (operands, 0, -1, true); }
6975   [(set_attr "jal" "direct")
6976    (set_attr "jal_macro" "no")])
6978 (define_expand "call_value"
6979   [(parallel [(set (match_operand 0 "")
6980                    (call (match_operand 1 "")
6981                          (match_operand 2 "")))
6982               (use (match_operand 3 ""))])]             ;; next_arg_reg
6983   ""
6985   mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6986                     operands[2], operands[3], false);
6987   DONE;
6990 ;; See comment for call_internal.
6991 (define_insn_and_split "call_value_internal"
6992   [(set (match_operand 0 "register_operand" "")
6993         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6994               (match_operand 2 "" "")))
6995    (clobber (reg:SI RETURN_ADDR_REGNUM))]
6996   ""
6997   {
6998     return (TARGET_SPLIT_CALLS ? "#"
6999             : mips_output_jump (operands, 1, 2, true));
7000   }
7001   "reload_completed && TARGET_SPLIT_CALLS"
7002   [(const_int 0)]
7004   mips_split_call (curr_insn,
7005                    gen_call_value_split (operands[0], operands[1],
7006                                          operands[2]));
7007   DONE;
7009   [(set_attr "jal" "indirect,direct")])
7011 (define_insn "call_value_split"
7012   [(set (match_operand 0 "register_operand" "")
7013         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7014               (match_operand 2 "" "")))
7015    (clobber (reg:SI RETURN_ADDR_REGNUM))
7016    (clobber (reg:SI 28))]
7017   "TARGET_SPLIT_CALLS"
7018   { return mips_output_jump (operands, 1, 2, true); }
7019   [(set_attr "jal" "indirect,direct")
7020    (set_attr "jal_macro" "no")])
7022 ;; See call_internal_direct.
7023 (define_insn_and_split "call_value_internal_direct"
7024   [(set (match_operand 0 "register_operand")
7025         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7026               (match_operand 2)))
7027    (const_int 1)
7028    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7029   ""
7030   {
7031     return (TARGET_SPLIT_CALLS ? "#"
7032             : mips_output_jump (operands, 1, -1, true));
7033   }
7034   "reload_completed && TARGET_SPLIT_CALLS"
7035   [(const_int 0)]
7037   mips_split_call (curr_insn,
7038                    gen_call_value_direct_split (operands[0], operands[1],
7039                                                 operands[2]));
7040   DONE;
7042   [(set_attr "jal" "direct")])
7044 (define_insn "call_value_direct_split"
7045   [(set (match_operand 0 "register_operand")
7046         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7047               (match_operand 2)))
7048    (const_int 1)
7049    (clobber (reg:SI RETURN_ADDR_REGNUM))
7050    (clobber (reg:SI 28))]
7051   "TARGET_SPLIT_CALLS"
7052   { return mips_output_jump (operands, 1, -1, true); }
7053   [(set_attr "jal" "direct")
7054    (set_attr "jal_macro" "no")])
7056 ;; See comment for call_internal.
7057 (define_insn_and_split "call_value_multiple_internal"
7058   [(set (match_operand 0 "register_operand" "")
7059         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7060               (match_operand 2 "" "")))
7061    (set (match_operand 3 "register_operand" "")
7062         (call (mem:SI (match_dup 1))
7063               (match_dup 2)))
7064    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7065   ""
7066   {
7067     return (TARGET_SPLIT_CALLS ? "#"
7068             : mips_output_jump (operands, 1, 2, true));
7069   }
7070   "reload_completed && TARGET_SPLIT_CALLS"
7071   [(const_int 0)]
7073   mips_split_call (curr_insn,
7074                    gen_call_value_multiple_split (operands[0], operands[1],
7075                                                   operands[2], operands[3]));
7076   DONE;
7078   [(set_attr "jal" "indirect,direct")])
7080 (define_insn "call_value_multiple_split"
7081   [(set (match_operand 0 "register_operand" "")
7082         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7083               (match_operand 2 "" "")))
7084    (set (match_operand 3 "register_operand" "")
7085         (call (mem:SI (match_dup 1))
7086               (match_dup 2)))
7087    (clobber (reg:SI RETURN_ADDR_REGNUM))
7088    (clobber (reg:SI 28))]
7089   "TARGET_SPLIT_CALLS"
7090   { return mips_output_jump (operands, 1, 2, true); }
7091   [(set_attr "jal" "indirect,direct")
7092    (set_attr "jal_macro" "no")])
7094 ;; Call subroutine returning any type.
7096 (define_expand "untyped_call"
7097   [(parallel [(call (match_operand 0 "")
7098                     (const_int 0))
7099               (match_operand 1 "")
7100               (match_operand 2 "")])]
7101   ""
7103   int i;
7105   emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
7107   for (i = 0; i < XVECLEN (operands[2], 0); i++)
7108     {
7109       rtx set = XVECEXP (operands[2], 0, i);
7110       mips_emit_move (SET_DEST (set), SET_SRC (set));
7111     }
7113   emit_insn (gen_blockage ());
7114   DONE;
7118 ;;  ....................
7120 ;;      MISC.
7122 ;;  ....................
7126 (define_insn "prefetch"
7127   [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7128              (match_operand 1 "const_int_operand" "n")
7129              (match_operand 2 "const_int_operand" "n"))]
7130   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7132   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
7133     {
7134       /* Loongson 2[ef] and Loongson 3a use load to $0 for prefetching.  */
7135       if (TARGET_64BIT)
7136         return "ld\t$0,%a0";
7137       else
7138         return "lw\t$0,%a0";
7139     }
7140   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7141   return "pref\t%1,%a0";
7143   [(set_attr "type" "prefetch")])
7145 (define_insn "*prefetch_indexed_<mode>"
7146   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7147                      (match_operand:P 1 "register_operand" "d"))
7148              (match_operand 2 "const_int_operand" "n")
7149              (match_operand 3 "const_int_operand" "n"))]
7150   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7152   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7153   return "prefx\t%2,%1(%0)";
7155   [(set_attr "type" "prefetchx")])
7157 (define_insn "nop"
7158   [(const_int 0)]
7159   ""
7160   "%(nop%)"
7161   [(set_attr "type"     "nop")
7162    (set_attr "mode"     "none")])
7164 ;; Like nop, but commented out when outside a .set noreorder block.
7165 (define_insn "hazard_nop"
7166   [(const_int 1)]
7167   ""
7168   {
7169     if (mips_noreorder.nesting_level > 0)
7170       return "nop";
7171     else
7172       return "#nop";
7173   }
7174   [(set_attr "type"     "nop")])
7176 ;; The `.insn' pseudo-op.
7177 (define_insn "insn_pseudo"
7178   [(unspec_volatile [(const_int 0)] UNSPEC_INSN_PSEUDO)]
7179   ""
7180   ".insn"
7181   [(set_attr "mode" "none")
7182    (set_attr "insn_count" "0")])
7184 ;; MIPS4 Conditional move instructions.
7186 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7187   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7188         (if_then_else:GPR
7189          (match_operator 4 "equality_operator"
7190                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7191                  (const_int 0)])
7192          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7193          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7194   "ISA_HAS_CONDMOVE"
7195   "@
7196     mov%T4\t%0,%z2,%1
7197     mov%t4\t%0,%z3,%1"
7198   [(set_attr "type" "condmove")
7199    (set_attr "mode" "<GPR:MODE>")])
7201 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7202   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7203        (if_then_else:GPR
7204         (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7205         (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7206         (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7207   "ISA_HAS_CONDMOVE"
7208   "@
7209     movn\t%0,%z2,%1
7210     movz\t%0,%z3,%1"
7211   [(set_attr "type" "condmove")
7212    (set_attr "mode" "<GPR:MODE>")])
7214 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7215   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7216         (if_then_else:SCALARF
7217          (match_operator 4 "equality_operator"
7218                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7219                  (const_int 0)])
7220          (match_operand:SCALARF 2 "register_operand" "f,0")
7221          (match_operand:SCALARF 3 "register_operand" "0,f")))]
7222   "ISA_HAS_FP_CONDMOVE"
7223   "@
7224     mov%T4.<fmt>\t%0,%2,%1
7225     mov%t4.<fmt>\t%0,%3,%1"
7226   [(set_attr "type" "condmove")
7227    (set_attr "mode" "<SCALARF:MODE>")])
7229 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7230   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7231         (if_then_else:GPR
7232          (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7233                            (const_int 0))
7234          (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7235          (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7236   "ISA_HAS_SEL
7237    && (register_operand (operands[2], <GPR:MODE>mode)
7238        != register_operand (operands[3], <GPR:MODE>mode))"
7239   "@
7240    <sel>\t%0,%2,%1
7241    <selinv>\t%0,%3,%1"
7242   [(set_attr "type" "condmove")
7243    (set_attr "mode" "<GPR:MODE>")])
7245 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7246 ;; argument if the 1st is zero.  This means operand 2 and 3 are
7247 ;; inverted in the instruction.
7249 (define_insn "*sel<mode>"
7250   [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7251         (if_then_else:SCALARF
7252          (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7253                  (const_int 0))
7254          (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7255          (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7256   "ISA_HAS_SEL && ISA_HAS_CCF"
7257   "@
7258    sel.<fmt>\t%0,%3,%2
7259    seleqz.<fmt>\t%0,%3,%1
7260    selnez.<fmt>\t%0,%2,%1"
7261   [(set_attr "type" "condmove")
7262    (set_attr "mode" "<SCALARF:MODE>")])
7264 ;; These are the main define_expand's used to make conditional moves.
7266 (define_expand "mov<mode>cc"
7267   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7268    (set (match_operand:GPR 0 "register_operand")
7269         (if_then_else:GPR (match_dup 5)
7270                           (match_operand:GPR 2 "reg_or_0_operand")
7271                           (match_operand:GPR 3 "reg_or_0_operand")))]
7272   "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7274   if (!ISA_HAS_FP_CONDMOVE
7275       && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7276     FAIL;
7278   mips_expand_conditional_move (operands);
7279   DONE;
7282 (define_expand "mov<mode>cc"
7283   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7284    (set (match_operand:SCALARF 0 "register_operand")
7285         (if_then_else:SCALARF (match_dup 5)
7286                               (match_operand:SCALARF 2 "reg_or_0_operand")
7287                               (match_operand:SCALARF 3 "reg_or_0_operand")))]
7288   "ISA_HAS_FP_CONDMOVE
7289    || (ISA_HAS_SEL && ISA_HAS_CCF)"
7291   if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7292     FAIL;
7294   /* Workaround an LRA bug which means that tied operands in the sel.fmt
7295      pattern lead to the double precision destination of sel.d getting
7296      reloaded with the full register file usable and the restrictions on
7297      whether the CCFmode input can be used in odd-numbered single-precision
7298      registers are ignored.  For consistency reasons the CCF mode values
7299      must be guaranteed to only exist in the even-registers because of
7300      the unusual duality between single and double precision values.  */
7301   if (ISA_HAS_SEL && <MODE>mode == DFmode
7302       && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7303     FAIL;
7305   mips_expand_conditional_move (operands);
7306   DONE;
7310 ;;  ....................
7312 ;;      mips16 inline constant tables
7314 ;;  ....................
7317 (define_insn "consttable"
7318   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7319                     UNSPEC_CONSTTABLE)]
7320   ""
7321   ""
7322   [(set_attr "mode" "none")
7323    (set_attr "insn_count" "0")])
7325 (define_insn "consttable_end"
7326   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7327                     UNSPEC_CONSTTABLE_END)]
7328   ""
7329   ""
7330   [(set_attr "mode" "none")
7331    (set_attr "insn_count" "0")])
7333 (define_insn "consttable_tls_reloc"
7334   [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7335                      (match_operand 1 "const_int_operand" "")]
7336                     UNSPEC_CONSTTABLE_INT)]
7337   "TARGET_MIPS16_PCREL_LOADS"
7338   { return mips_output_tls_reloc_directive (&operands[0]); }
7339   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7341 (define_insn "consttable_int"
7342   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7343                      (match_operand 1 "const_int_operand" "")]
7344                     UNSPEC_CONSTTABLE_INT)]
7345   "TARGET_MIPS16"
7347   assemble_integer (mips_strip_unspec_address (operands[0]),
7348                     INTVAL (operands[1]),
7349                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
7350   return "";
7352   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7354 (define_insn "consttable_float"
7355   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7356                     UNSPEC_CONSTTABLE_FLOAT)]
7357   "TARGET_MIPS16"
7359   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7360   assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
7361                  GET_MODE (operands[0]),
7362                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
7363   return "";
7365   [(set (attr "length")
7366         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7368 (define_insn "align"
7369   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7370   ""
7371   ".align\t%0"
7372   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7374 (define_split
7375   [(match_operand 0 "small_data_pattern")]
7376   "reload_completed"
7377   [(match_dup 0)]
7378   { operands[0] = mips_rewrite_small_data (operands[0]); })
7381 ;;  ....................
7383 ;;      MIPS16e Save/Restore
7385 ;;  ....................
7388 (define_insn "*mips16e_save_restore"
7389   [(match_parallel 0 ""
7390        [(set (match_operand:SI 1 "register_operand")
7391              (plus:SI (match_dup 1)
7392                       (match_operand:SI 2 "const_int_operand")))])]
7393   "operands[1] == stack_pointer_rtx
7394    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7395   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7396   [(set_attr "type" "arith")
7397    (set_attr "extended_mips16" "yes")])
7399 ;; Thread-Local Storage
7401 ;; The TLS base pointer is accessed via "rdhwr $3, $29".  No current
7402 ;; MIPS architecture defines this register, and no current
7403 ;; implementation provides it; instead, any OS which supports TLS is
7404 ;; expected to trap and emulate this instruction.  rdhwr is part of the
7405 ;; MIPS 32r2 specification, but we use it on any architecture because
7406 ;; we expect it to be emulated.  Use .set to force the assembler to
7407 ;; accept it.
7409 ;; We do not use a constraint to force the destination to be $3
7410 ;; because $3 can appear explicitly as a function return value.
7411 ;; If we leave the use of $3 implicit in the constraints until
7412 ;; reload, we may end up making a $3 return value live across
7413 ;; the instruction, leading to a spill failure when reloading it.
7414 (define_insn_and_split "tls_get_tp_<mode>"
7415   [(set (match_operand:P 0 "register_operand" "=d")
7416         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7417    (clobber (reg:P TLS_GET_TP_REGNUM))]
7418   "HAVE_AS_TLS && !TARGET_MIPS16"
7419   "#"
7420   "&& reload_completed"
7421   [(set (reg:P TLS_GET_TP_REGNUM)
7422         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7423    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7424   ""
7425   [(set_attr "type" "unknown")
7426    (set_attr "mode" "<MODE>")
7427    (set_attr "insn_count" "2")])
7429 (define_insn "*tls_get_tp_<mode>_split"
7430   [(set (reg:P TLS_GET_TP_REGNUM)
7431         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7432   "HAVE_AS_TLS && !TARGET_MIPS16"
7433   {
7434     if (mips_isa_rev >= 2)
7435       return "rdhwr\t$3,$29";
7437     return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7438   }
7439   [(set_attr "type" "unknown")
7440    ; Since rdhwr always generates a trap for now, putting it in a delay
7441    ; slot would make the kernel's emulation of it much slower.
7442    (set_attr "can_delay" "no")
7443    (set_attr "mode" "<MODE>")])
7445 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7446 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7447 ;; accessible in MIPS16.
7449 ;; This is not represented as a call insn, to avoid the
7450 ;; unnecesarry clobbering of caller-save registers by a
7451 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7453 ;; A $25 clobber is added to cater for a $25 load stub added by the
7454 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7456 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7457   [(set (match_operand:P 0 "register_operand" "=d")
7458         (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7459                   UNSPEC_TLS_GET_TP))
7460    (clobber (reg:P TLS_GET_TP_REGNUM))
7461    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7462    (clobber (reg:P RETURN_ADDR_REGNUM))]
7463   "HAVE_AS_TLS && TARGET_MIPS16"
7464   "#"
7465   "&& reload_completed"
7466   [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7467                    (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7468               (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7469               (clobber (reg:P RETURN_ADDR_REGNUM))])
7470    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7471   ""
7472   [(set_attr "type" "multi")
7473    (set_attr "insn_count" "4")
7474    (set_attr "mode" "<MODE>")])
7476 (define_insn "*tls_get_tp_mips16_call_<mode>"
7477   [(set (reg:P TLS_GET_TP_REGNUM)
7478         (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7479                   UNSPEC_TLS_GET_TP))
7480    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7481    (clobber (reg:P RETURN_ADDR_REGNUM))]
7482   "HAVE_AS_TLS && TARGET_MIPS16"
7483   { return mips_output_jump (operands, 0, -1, true); }
7484   [(set_attr "type" "call")
7485    (set_attr "insn_count" "3")
7486    (set_attr "mode" "<MODE>")])
7488 ;; Named pattern for expanding thread pointer reference.
7489 (define_expand "get_thread_pointer<mode>"
7490   [(match_operand:P 0 "register_operand" "=d")]
7491   "HAVE_AS_TLS"
7493   mips_expand_thread_pointer (operands[0]);
7494   DONE;
7497 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7498 (define_expand "mips_get_fcsr"
7499   [(set (match_operand:SI 0 "register_operand")
7500         (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7501   "TARGET_HARD_FLOAT_ABI"
7503   if (TARGET_MIPS16)
7504     {
7505       mips16_expand_get_fcsr (operands[0]);
7506       DONE;
7507     }
7510 (define_insn "*mips_get_fcsr"
7511   [(set (match_operand:SI 0 "register_operand" "=d")
7512         (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7513   "TARGET_HARD_FLOAT"
7514   "cfc1\t%0,$31")
7516 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7517 (define_insn "mips_get_fcsr_mips16_<mode>"
7518   [(set (reg:SI GET_FCSR_REGNUM)
7519         (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7520                    UNSPEC_GET_FCSR))
7521    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7522    (clobber (reg:P RETURN_ADDR_REGNUM))]
7523   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7524   { return mips_output_jump (operands, 0, -1, true); }
7525   [(set_attr "type" "call")
7526    (set_attr "insn_count" "3")])
7528 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7529 (define_expand "mips_set_fcsr"
7530   [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7531                     UNSPEC_SET_FCSR)]
7532   "TARGET_HARD_FLOAT_ABI"
7534   if (TARGET_MIPS16)
7535     {
7536       mips16_expand_set_fcsr (operands[0]);
7537       DONE;
7538     }
7541 (define_insn "*mips_set_fcsr"
7542   [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7543                     UNSPEC_SET_FCSR)]
7544   "TARGET_HARD_FLOAT"
7545   "ctc1\t%0,$31")
7547 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7548 (define_insn "mips_set_fcsr_mips16_<mode>"
7549   [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7550                         (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7551    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7552    (clobber (reg:P RETURN_ADDR_REGNUM))]
7553   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7554   { return mips_output_jump (operands, 0, -1, true); }
7555   [(set_attr "type" "call")
7556    (set_attr "insn_count" "3")])
7558 ;; Match paired HI/SI/SF/DFmode load/stores.
7559 (define_insn "*join2_load_store<JOIN_MODE:mode>"
7560   [(set (match_operand:JOIN_MODE 0 "nonimmediate_operand" "=d,f,m,m")
7561         (match_operand:JOIN_MODE 1 "nonimmediate_operand" "m,m,d,f"))
7562    (set (match_operand:JOIN_MODE 2 "nonimmediate_operand" "=d,f,m,m")
7563         (match_operand:JOIN_MODE 3 "nonimmediate_operand" "m,m,d,f"))]
7564   "ENABLE_LD_ST_PAIRS && reload_completed"
7565   {
7566     bool load_p = (which_alternative == 0 || which_alternative == 1);
7567     /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7568        Hardware does not bond those loads, even when they are consecutive.
7569        However, order of the loads need to be checked for correctness.  */
7570     if (!load_p || !reg_overlap_mentioned_p (operands[0], operands[1]))
7571       {
7572         output_asm_insn (mips_output_move (operands[0], operands[1]),
7573                          operands);
7574         output_asm_insn (mips_output_move (operands[2], operands[3]),
7575                          &operands[2]);
7576       }
7577     else
7578       {
7579         output_asm_insn (mips_output_move (operands[2], operands[3]),
7580                          &operands[2]);
7581         output_asm_insn (mips_output_move (operands[0], operands[1]),
7582                          operands);
7583       }
7584     return "";
7585   }
7586   [(set_attr "move_type" "load,fpload,store,fpstore")
7587    (set_attr "insn_count" "2,2,2,2")])
7589 ;; 2 HI/SI/SF/DF loads are joined.
7590 ;; P5600 does not support bonding of two LBs, hence QI mode is not included.
7591 ;; The loads must be non-volatile as they might be reordered at the time of asm
7592 ;; generation.
7593 (define_peephole2
7594   [(set (match_operand:JOIN_MODE 0 "register_operand")
7595         (match_operand:JOIN_MODE 1 "non_volatile_mem_operand"))
7596    (set (match_operand:JOIN_MODE 2 "register_operand")
7597         (match_operand:JOIN_MODE 3 "non_volatile_mem_operand"))]
7598   "ENABLE_LD_ST_PAIRS
7599    && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, true)"
7600   [(parallel [(set (match_dup 0)
7601                    (match_dup 1))
7602               (set (match_dup 2)
7603                    (match_dup 3))])]
7604   "")
7606 ;; 2 HI/SI/SF/DF stores are joined.
7607 ;; P5600 does not support bonding of two SBs, hence QI mode is not included.
7608 (define_peephole2
7609   [(set (match_operand:JOIN_MODE 0 "memory_operand")
7610         (match_operand:JOIN_MODE 1 "register_operand"))
7611    (set (match_operand:JOIN_MODE 2 "memory_operand")
7612         (match_operand:JOIN_MODE 3 "register_operand"))]
7613   "ENABLE_LD_ST_PAIRS
7614    && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, false)"
7615   [(parallel [(set (match_dup 0)
7616                    (match_dup 1))
7617               (set (match_dup 2)
7618                    (match_dup 3))])]
7619   "")
7621 ;; Match paired HImode loads.
7622 (define_insn "*join2_loadhi"
7623   [(set (match_operand:SI 0 "register_operand" "=r")
7624         (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand" "m")))
7625    (set (match_operand:SI 2 "register_operand" "=r")
7626         (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand" "m")))]
7627   "ENABLE_LD_ST_PAIRS && reload_completed"
7628   {
7629     /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7630        Hardware does not bond those loads, even when they are consecutive.
7631        However, order of the loads need to be checked for correctness.  */
7632     if (!reg_overlap_mentioned_p (operands[0], operands[1]))
7633       {
7634         output_asm_insn ("lh<u>\t%0,%1", operands);
7635         output_asm_insn ("lh<u>\t%2,%3", operands);
7636       }
7637     else
7638       {
7639         output_asm_insn ("lh<u>\t%2,%3", operands);
7640         output_asm_insn ("lh<u>\t%0,%1", operands);
7641       }
7643     return "";
7644   }
7645   [(set_attr "move_type" "load")
7646    (set_attr "insn_count" "2")])
7649 ;; 2 HI loads are joined.
7650 (define_peephole2
7651   [(set (match_operand:SI 0 "register_operand")
7652         (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand")))
7653    (set (match_operand:SI 2 "register_operand")
7654         (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand")))]
7655   "ENABLE_LD_ST_PAIRS
7656    && mips_load_store_bonding_p (operands, HImode, true)"
7657   [(parallel [(set (match_dup 0)
7658                    (any_extend:SI (match_dup 1)))
7659               (set (match_dup 2)
7660                    (any_extend:SI (match_dup 3)))])]
7661   "")
7664 ;; Synchronization instructions.
7666 (include "sync.md")
7668 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7670 (include "mips-ps-3d.md")
7672 ; The MIPS DSP Instructions.
7674 (include "mips-dsp.md")
7676 ; The MIPS DSP REV 2 Instructions.
7678 (include "mips-dspr2.md")
7680 ; MIPS fixed-point instructions.
7681 (include "mips-fixed.md")
7683 ; microMIPS patterns.
7684 (include "micromips.md")
7686 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7687 (include "loongson.md")
7689 ; The MIPS MSA Instructions.
7690 (include "mips-msa.md")
7692 (define_c_enum "unspec" [
7693   UNSPEC_ADDRESS_FIRST