modula2: Tidyup remove unnecessary parameters
[official-gcc.git] / gcc / config / mips / mips.md
blobf147667d63a8cd3657245d86c434f1a6f6d6ebdd
1 ;;  Mips.md          Machine Description for MIPS based processors
2 ;;  Copyright (C) 1989-2024 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   gs464
41   gs464e
42   gs264e
43   m4k
44   octeon
45   octeon2
46   octeon3
47   r3900
48   r6000
49   r4000
50   r4100
51   r4111
52   r4120
53   r4130
54   r4300
55   r4600
56   r4650
57   r4700
58   r5000
59   r5400
60   r5500
61   r5900
62   r7000
63   r8000
64   r9000
65   r10000
66   sb1
67   sb1a
68   sr71000
69   xlr
70   xlp
71   p5600
72   m5100
73   i6400
74   p6600
77 (define_c_enum "unspec" [
78   ;; Unaligned accesses.
79   UNSPEC_LOAD_LEFT
80   UNSPEC_LOAD_RIGHT
81   UNSPEC_STORE_LEFT
82   UNSPEC_STORE_RIGHT
84   ;; Integer operations that are too cumbersome to describe directly.
85   UNSPEC_WSBH
86   UNSPEC_DSBH
87   UNSPEC_DSHD
89   ;; Floating-point moves.
90   UNSPEC_LOAD_LOW
91   UNSPEC_LOAD_HIGH
92   UNSPEC_STORE_WORD
93   UNSPEC_MFHC1
94   UNSPEC_MTHC1
96   ;; Floating-point environment.
97   UNSPEC_GET_FCSR
98   UNSPEC_SET_FCSR
100   ;; Floating-point unspecs.
101   UNSPEC_FMIN
102   UNSPEC_FMAX
104   ;; HI/LO moves.
105   UNSPEC_MFHI
106   UNSPEC_MTHI
107   UNSPEC_SET_HILO
109   ;; GP manipulation.
110   UNSPEC_LOADGP
111   UNSPEC_COPYGP
112   UNSPEC_MOVE_GP
113   UNSPEC_POTENTIAL_CPRESTORE
114   UNSPEC_CPRESTORE
115   UNSPEC_RESTORE_GP
116   UNSPEC_EH_RETURN
117   UNSPEC_GP
118   UNSPEC_SET_GOT_VERSION
119   UNSPEC_UPDATE_GOT_VERSION
121   ;; Symbolic accesses.
122   UNSPEC_LOAD_CALL
123   UNSPEC_LOAD_GOT
124   UNSPEC_TLS_LDM
125   UNSPEC_TLS_GET_TP
126   UNSPEC_UNSHIFTED_HIGH
128   ;; MIPS16 constant pools.
129   UNSPEC_ALIGN
130   UNSPEC_CONSTTABLE
131   UNSPEC_CONSTTABLE_END
132   UNSPEC_CONSTTABLE_INT
133   UNSPEC_CONSTTABLE_FLOAT
135   ;; Blockage and synchronisation.
136   UNSPEC_BLOCKAGE
137   UNSPEC_CLEAR_HAZARD
138   UNSPEC_RDHWR
139   UNSPEC_SYNCI
140   UNSPEC_SYNC
142   ;; Cache manipulation.
143   UNSPEC_MIPS_CACHE
144   UNSPEC_R10K_CACHE_BARRIER
146   ;; Interrupt handling.
147   UNSPEC_ERET
148   UNSPEC_DERET
149   UNSPEC_DI
150   UNSPEC_EHB
151   UNSPEC_RDPGPR
152   UNSPEC_COP0
154   ;; Used in a call expression in place of args_size.  It's present for PIC
155   ;; indirect calls where it contains args_size and the function symbol.
156   UNSPEC_CALL_ATTR
158   ;; MIPS16 casesi jump table dispatch.
159   UNSPEC_CASESI_DISPATCH
161   ;; Stack checking.
162   UNSPEC_PROBE_STACK_RANGE
164   ;; The `.insn' pseudo-op.
165   UNSPEC_INSN_PSEUDO
166   UNSPEC_JRHB
168   VUNSPEC_SPECULATION_BARRIER
171 (define_constants
172   [(TLS_GET_TP_REGNUM           3)
173    (GET_FCSR_REGNUM             2)
174    (SET_FCSR_REGNUM             4)
175    (PIC_FUNCTION_ADDR_REGNUM    25)
176    (GLOBAL_POINTER_REGNUM       28)
177    (RETURN_ADDR_REGNUM          31)
178    (CPRESTORE_SLOT_REGNUM       76)
179    (GOT_VERSION_REGNUM          79)
181    ;; PIC long branch sequences are never longer than 100 bytes.
182    (MAX_PIC_BRANCH_LENGTH       100)
183   ]
186 (include "predicates.md")
187 (include "constraints.md")
189 ;; ....................
191 ;;      Attributes
193 ;; ....................
195 (define_attr "got" "unset,xgot_high,load"
196   (const_string "unset"))
198 ;; For jal instructions, this attribute is DIRECT when the target address
199 ;; is symbolic and INDIRECT when it is a register.
200 (define_attr "jal" "unset,direct,indirect"
201   (const_string "unset"))
203 ;; This attribute is YES if the instruction is a jal macro (not a
204 ;; real jal instruction).
206 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
207 ;; an instruction to restore $gp.  Direct jals are also macros for
208 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
209 ;; into a register.
210 (define_attr "jal_macro" "no,yes"
211   (cond [(eq_attr "jal" "direct")
212          (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
213                        ? JAL_MACRO_YES : JAL_MACRO_NO)")
214          (eq_attr "jal" "indirect")
215          (symbol_ref "(TARGET_CALL_CLOBBERED_GP
216                        ? JAL_MACRO_YES : JAL_MACRO_NO)")]
217         (const_string "no")))
219 ;; Classification of moves, extensions and truncations.  Most values
220 ;; are as for "type" (see below) but there are also the following
221 ;; move-specific values:
223 ;; constN       move an N-constraint integer into a MIPS16 register
224 ;; sll0         "sll DEST,SRC,0", which on 64-bit targets is guaranteed
225 ;;              to produce a sign-extended DEST, even if SRC is not
226 ;;              properly sign-extended
227 ;; ext_ins      EXT, DEXT, INS or DINS instruction
228 ;; andi         a single ANDI instruction
229 ;; loadpool     move a constant into a MIPS16 register by loading it
230 ;;              from the pool
231 ;; shift_shift  a shift left followed by a shift right
233 ;; This attribute is used to determine the instruction's length and
234 ;; scheduling type.  For doubleword moves, the attribute always describes
235 ;; the split instructions; in some cases, it is more appropriate for the
236 ;; scheduling type to be "multi" instead.
237 (define_attr "move_type"
238   "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
239    const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
240    shift_shift"
241   (const_string "unknown"))
243 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor,simd_add"
244   (const_string "unknown"))
246 ;; Main data type used by the insn
247 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW,
248   V2DI,V4SI,V8HI,V16QI,V2DF,V4SF"
249   (const_string "unknown"))
251 ;; True if the main data type is twice the size of a word.
252 (define_attr "dword_mode" "no,yes"
253   (cond [(and (eq_attr "mode" "DI,DF")
254               (not (match_test "TARGET_64BIT")))
255          (const_string "yes")
257          (and (eq_attr "mode" "TI,TF")
258               (match_test "TARGET_64BIT"))
259          (const_string "yes")]
260         (const_string "no")))
262 ;; True if the main data type is four times of the size of a word.
263 (define_attr "qword_mode" "no,yes"
264   (cond [(and (eq_attr "mode" "TI,TF")
265               (not (match_test "TARGET_64BIT")))
266          (const_string "yes")]
267         (const_string "no")))
269 ;; Attributes describing a sync loop.  These loops have the form:
271 ;;       if (RELEASE_BARRIER == YES) sync
272 ;;    1: OLDVAL = *MEM
273 ;;       if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
274 ;;         CMP  = 0 [delay slot]
275 ;;       $TMP1 = OLDVAL & EXCLUSIVE_MASK
276 ;;       $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
277 ;;       $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
278 ;;       $AT |= $TMP1 | $TMP3
279 ;;       if (!commit (*MEM = $AT)) goto 1.
280 ;;         if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
281 ;;       CMP  = 1
282 ;;       if (ACQUIRE_BARRIER == YES) sync
283 ;;    2:
285 ;; where "$" values are temporaries and where the other values are
286 ;; specified by the attributes below.  Values are specified as operand
287 ;; numbers and insns are specified as enums.  If no operand number is
288 ;; specified, the following values are used instead:
290 ;;    - OLDVAL: $AT
291 ;;    - CMP: NONE
292 ;;    - NEWVAL: $AT
293 ;;    - INCLUSIVE_MASK: -1
294 ;;    - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
295 ;;    - EXCLUSIVE_MASK: 0
297 ;; MEM and INSN1_OP2 are required.
299 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
300 ;; but the gen* programs don't yet support that.
301 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
302 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
303 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
304 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
305 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
306 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
307 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
308 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
309 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
310   (const_string "move"))
311 (define_attr "sync_insn2" "nop,and,xor,not"
312   (const_string "nop"))
313 ;; Memory model specifier.
314 ;; "0"-"9" values specify the operand that stores the memory model value.
315 ;; "10" specifies MEMMODEL_ACQ_REL,
316 ;; "11" specifies MEMMODEL_ACQUIRE.
317 (define_attr "sync_memmodel" "" (const_int 10))
319 ;; Performance ratio.  Add this attr to the slow INSNs.
320 ;; Used by mips_insn_cost.
321 (define_attr "perf_ratio" "" (const_int 0))
323 ;; Accumulator operand for madd patterns.
324 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
326 ;; Classification of each insn.
327 ;; branch       conditional branch
328 ;; jump         unconditional jump
329 ;; call         unconditional call
330 ;; load         load instruction(s)
331 ;; fpload       floating point load
332 ;; fpidxload    floating point indexed load
333 ;; store        store instruction(s)
334 ;; fpstore      floating point store
335 ;; fpidxstore   floating point indexed store
336 ;; prefetch     memory prefetch (register + offset)
337 ;; prefetchx    memory indexed prefetch (register + register)
338 ;; condmove     conditional moves
339 ;; mtc          transfer to coprocessor
340 ;; mfc          transfer from coprocessor
341 ;; mthi         transfer to a hi register
342 ;; mtlo         transfer to a lo register
343 ;; mfhi         transfer from a hi register
344 ;; mflo         transfer from a lo register
345 ;; const        load constant
346 ;; arith        integer arithmetic instructions
347 ;; logical      integer logical instructions
348 ;; shift        integer shift instructions
349 ;; slt          set less than instructions
350 ;; signext      sign extend instructions
351 ;; clz          the clz and clo instructions
352 ;; pop          the pop instruction
353 ;; trap         trap if instructions
354 ;; imul         integer multiply 2 operands
355 ;; imul3        integer multiply 3 operands
356 ;; imul3nc      integer multiply 3 operands without clobbering HI/LO
357 ;; imadd        integer multiply-add
358 ;; idiv         integer divide 2 operands
359 ;; idiv3        integer divide 3 operands
360 ;; move         integer register move ({,D}ADD{,U} with rt = 0)
361 ;; fmove        floating point register move
362 ;; fadd         floating point add/subtract
363 ;; fmul         floating point multiply
364 ;; fmadd        floating point multiply-add
365 ;; fdiv         floating point divide
366 ;; frdiv        floating point reciprocal divide
367 ;; frdiv1       floating point reciprocal divide step 1
368 ;; frdiv2       floating point reciprocal divide step 2
369 ;; fabs         floating point absolute value
370 ;; fneg         floating point negation
371 ;; fcmp         floating point compare
372 ;; fcvt         floating point convert
373 ;; fsqrt        floating point square root
374 ;; frsqrt       floating point reciprocal square root
375 ;; frsqrt1      floating point reciprocal square root step1
376 ;; frsqrt2      floating point reciprocal square root step2
377 ;; fminmax      floating point min/max
378 ;; dspmac       DSP MAC instructions not saturating the accumulator
379 ;; dspmacsat    DSP MAC instructions that saturate the accumulator
380 ;; accext       DSP accumulator extract instructions
381 ;; accmod       DSP accumulator modify instructions
382 ;; dspalu       DSP ALU instructions not saturating the result
383 ;; dspalusat    DSP ALU instructions that saturate the result
384 ;; multi        multiword sequence (or user asm statements)
385 ;; atomic       atomic memory update instruction
386 ;; syncloop     memory atomic operation implemented as a sync loop
387 ;; nop          no operation
388 ;; ghost        an instruction that produces no real code
389 ;; multimem     microMIPS multiword load and store
390 (define_attr "type"
391   "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
392    prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
393    shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
394    fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
395    frsqrt,frsqrt1,frsqrt2,fminmax,dspmac,dspmacsat,accext,accmod,dspalu,
396    dspalusat,multi,atomic,syncloop,nop,ghost,multimem,
397    simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd,
398    simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp,
399    simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill,
400    simd_permute,simd_shf,simd_sat,simd_pcnt,simd_copy,simd_branch,simd_cmsa,
401    simd_fminmax,simd_logic,simd_move,simd_load,simd_store"
402   (cond [(eq_attr "jal" "!unset") (const_string "call")
403          (eq_attr "got" "load") (const_string "load")
405          (eq_attr "alu_type" "add,sub") (const_string "arith")
407          (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
409          ;; If a doubleword move uses these expensive instructions,
410          ;; it is usually better to schedule them in the same way
411          ;; as the singleword form, rather than as "multi".
412          (eq_attr "move_type" "load") (const_string "load")
413          (eq_attr "move_type" "fpload") (const_string "fpload")
414          (eq_attr "move_type" "store") (const_string "store")
415          (eq_attr "move_type" "fpstore") (const_string "fpstore")
416          (eq_attr "move_type" "mtc") (const_string "mtc")
417          (eq_attr "move_type" "mfc") (const_string "mfc")
418          (eq_attr "move_type" "mtlo") (const_string "mtlo")
419          (eq_attr "move_type" "mflo") (const_string "mflo")
421          ;; These types of move are always single insns.
422          (eq_attr "move_type" "imul") (const_string "imul")
423          (eq_attr "move_type" "fmove") (const_string "fmove")
424          (eq_attr "move_type" "loadpool") (const_string "load")
425          (eq_attr "move_type" "signext") (const_string "signext")
426          (eq_attr "move_type" "ext_ins") (const_string "arith")
427          (eq_attr "move_type" "arith") (const_string "arith")
428          (eq_attr "move_type" "logical") (const_string "logical")
429          (eq_attr "move_type" "sll0") (const_string "shift")
430          (eq_attr "move_type" "andi") (const_string "logical")
432          ;; These types of move are always split.
433          (eq_attr "move_type" "constN,shift_shift")
434            (const_string "multi")
436          ;; These types of move are split for quadword modes only.
437          (and (eq_attr "move_type" "move,const")
438               (eq_attr "qword_mode" "yes"))
439            (const_string "multi")
441          ;; These types of move are split for doubleword modes only.
442          (and (eq_attr "move_type" "move,const")
443               (eq_attr "dword_mode" "yes"))
444            (const_string "multi")
445          (eq_attr "move_type" "move") (const_string "move")
446          (eq_attr "move_type" "const") (const_string "const")
447          (eq_attr "sync_mem" "!none") (const_string "syncloop")]
448         (const_string "unknown")))
450 (define_attr "compact_form" "always,maybe,never"
451   (cond [(eq_attr "jal" "direct")
452          (const_string "always")
453          (eq_attr "jal" "indirect")
454          (const_string "maybe")
455          (eq_attr "type" "jump")
456          (const_string "maybe")]
457         (const_string "never")))
459 ;; Mode for conversion types (fcvt)
460 ;; I2S          integer to float single (SI/DI to SF)
461 ;; I2D          integer to float double (SI/DI to DF)
462 ;; S2I          float to integer (SF to SI/DI)
463 ;; D2I          float to integer (DF to SI/DI)
464 ;; D2S          double to float single
465 ;; S2D          float single to double
467 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D" 
468   (const_string "unknown"))
470 ;; Is this an extended instruction in mips16 mode?
471 (define_attr "extended_mips16" "no,yes"
472   (if_then_else (ior ;; In general, constant-pool loads are extended
473                      ;; instructions.  We don't yet optimize for 16-bit
474                      ;; PC-relative references.
475                      (eq_attr "move_type" "sll0,loadpool,ext_ins")
476                      (eq_attr "jal" "direct")
477                      (eq_attr "got" "load"))
478                 (const_string "yes")
479                 (const_string "no")))
481 (define_attr "compression" "none,all,micromips32,micromips"
482   (const_string "none"))
484 (define_attr "enabled" "no,yes"
485   (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
486          ;; GR_REG and FR_REG for 64-bit values.
487          (and (eq_attr "move_type" "mtc,mfc")
488               (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
489                            || TARGET_O32_FP64A_ABI")
490               (eq_attr "dword_mode" "yes"))
491          (const_string "no")
492          (and (eq_attr "compression" "micromips32,micromips")
493               (match_test "!TARGET_MICROMIPS"))
494          (const_string "no")]
495         (const_string "yes")))
497 ;; The number of individual instructions that a non-branch pattern generates,
498 ;; using units of BASE_INSN_LENGTH.
499 (define_attr "insn_count" ""
500   (cond [;; "Ghost" instructions occupy no space.
501          (eq_attr "type" "ghost")
502          (const_int 0)
504          ;; Extended instructions count as 2.
505          (and (eq_attr "extended_mips16" "yes")
506               (match_test "TARGET_MIPS16"))
507          (const_int 2)
509          ;; A GOT load followed by an add of $gp.  This is not used for MIPS16.
510          (eq_attr "got" "xgot_high")
511          (const_int 2)
513          ;; SHIFT_SHIFTs are decomposed into two separate instructions.
514          ;; They are extended instructions on MIPS16 targets.
515          (eq_attr "move_type" "shift_shift")
516          (if_then_else (match_test "TARGET_MIPS16")
517                        (const_int 4)
518                        (const_int 2))
520          ;; Check for doubleword moves that are decomposed into two
521          ;; instructions.  The individual instructions are unextended
522          ;; MIPS16 ones.
523          (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
524               (eq_attr "dword_mode" "yes"))
525          (const_int 2)
527          ;; Check for quadword moves that are decomposed into four
528          ;; instructions.
529          (and (eq_attr "move_type" "mtc,mfc,move")
530               (eq_attr "qword_mode" "yes"))
531          (const_int 4)
533          ;; Constants, loads and stores are handled by external routines.
534          (and (eq_attr "move_type" "const,constN")
535               (eq_attr "dword_mode" "yes"))
536          (symbol_ref "mips_split_const_insns (operands[1])")
537          (eq_attr "move_type" "const,constN")
538          (symbol_ref "mips_const_insns (operands[1])")
539          (eq_attr "move_type" "load,fpload")
540          (symbol_ref "mips_load_store_insns (operands[1], insn)")
541          (eq_attr "move_type" "store,fpstore")
542          (symbol_ref "mips_load_store_insns (operands[0], insn)
543                       + (TARGET_FIX_24K ? 1 : 0)")
545          ;; In the worst case, a call macro will take 8 instructions:
546          ;;
547          ;;     lui $25,%call_hi(FOO)
548          ;;     addu $25,$25,$28
549          ;;     lw $25,%call_lo(FOO)($25)
550          ;;     nop
551          ;;     jalr $25
552          ;;     nop
553          ;;     lw $gp,X($sp)
554          ;;     nop
555          (eq_attr "jal_macro" "yes")
556          (const_int 8)
558          ;; Various VR4120 errata require a nop to be inserted after a macc
559          ;; instruction.  The assembler does this for us, so account for
560          ;; the worst-case length here.
561          (and (eq_attr "type" "imadd")
562               (match_test "TARGET_FIX_VR4120"))
563          (const_int 2)
565          ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
566          ;; the result of the second one is missed.  The assembler should work
567          ;; around this by inserting a nop after the first dmult.
568          (and (eq_attr "type" "imul,imul3")
569               (eq_attr "mode" "DI")
570               (match_test "TARGET_FIX_VR4120"))
571          (const_int 2)
573          (eq_attr "type" "idiv,idiv3")
574          (symbol_ref "mips_idiv_insns (GET_MODE (PATTERN (insn)))")
576          ;; simd div have 3 instruction if TARGET_CHECK_ZERO_DIV is true.
577          (eq_attr "type" "simd_div")
578          (if_then_else (match_test "TARGET_CHECK_ZERO_DIV")
579                        (const_int 3)
580                        (const_int 1))
582          (not (eq_attr "sync_mem" "none"))
583          (symbol_ref "mips_sync_loop_insns (insn, operands)")]
584         (const_int 1)))
586 ;; Length of instruction in bytes.  The default is derived from "insn_count",
587 ;; but there are special cases for branches (which must be handled here)
588 ;; and for compressed single instructions.
589 (define_attr "length" ""
590    (cond [(and (ior (eq_attr "compression" "micromips,all")
591                     (and (eq_attr "compression" "micromips32")
592                          (eq_attr "mode" "SI,SF")))
593                (eq_attr "dword_mode" "no")
594                (match_test "TARGET_MICROMIPS"))
595           (const_int 2)
597           ;; Direct microMIPS branch instructions have a range of
598           ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
599           ;; If a branch is outside this range, we have a choice of two
600           ;; sequences.
601           ;;
602           ;; For PIC, an out-of-range branch like:
603           ;;
604           ;;    bne     r1,r2,target
605           ;;    dslot
606           ;;
607           ;; becomes the equivalent of:
608           ;;
609           ;;    beq     r1,r2,1f
610           ;;    dslot
611           ;;    la      $at,target
612           ;;    jr      $at
613           ;;    nop
614           ;; 1:
615           ;;
616           ;; The non-PIC case is similar except that we use a direct
617           ;; jump instead of an la/jr pair.  Since the target of this
618           ;; jump is an absolute 28-bit bit address (the other bits
619           ;; coming from the address of the delay slot) this form cannot
620           ;; cross a 256MB boundary.  We could provide the option of
621           ;; using la/jr in this case too, but we do not do so at
622           ;; present.
623           ;;
624           ;; The value we specify here does not account for the delay slot
625           ;; instruction, whose length is added separately.  If the RTL
626           ;; pattern has no explicit delay slot, mips_adjust_insn_length
627           ;; will add the length of the implicit nop.  The range of
628           ;; [-0x20000, 0x1fffc] from the address of the delay slot
629           ;; therefore translates to a range of:
630           ;;
631           ;;    [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
632           ;; == [-0x1fffc, 0x1fff8]
633           ;;
634           ;; from the shorten_branches reference address.
635           (and (eq_attr "type" "branch")
636                (not (match_test "TARGET_MIPS16")))
637           (cond [;; Any variant can handle the 17-bit range.
638                  (and (le (minus (match_dup 0) (pc)) (const_int 65532))
639                       (le (minus (pc) (match_dup 0)) (const_int 65534)))
640                    (const_int 4)
642                  ;; The 18-bit range is OK other than for microMIPS.
643                  (and (not (match_test "TARGET_MICROMIPS"))
644                       (and (le (minus (match_dup 0) (pc)) (const_int 131064))
645                            (le (minus (pc) (match_dup 0)) (const_int 131068))))
646                    (const_int 4)
648                  ;; The non-PIC case: branch, first delay slot, and J.
649                  (match_test "TARGET_ABSOLUTE_JUMPS")
650                    (const_int 12)]
652                  ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
653                  ;; mips_adjust_insn_length substitutes the correct length.
654                  ;;
655                  ;; Note that we can't simply use (symbol_ref ...) here
656                  ;; because genattrtab needs to know the maximum length
657                  ;; of an insn.
658                  (const_int MAX_PIC_BRANCH_LENGTH))
660           ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
661           ;; from the address of the following instruction, which leads
662           ;; to a range of:
663           ;;
664           ;;    [-(0x100 - sizeof (branch)), 0xfe]
665           ;; == [-0xfe, 0xfe]
666           ;;
667           ;; from the shorten_branches reference address.  Extended branches
668           ;; likewise have a range of [-0x10000, 0xfffe] from the address
669           ;; of the following instruction, which leads to a range of:
670           ;;
671           ;;    [-(0x10000 - sizeof (branch)), 0xfffe]
672           ;; == [-0xfffc, 0xfffe]
673           ;;
674           ;; from the reference address.
675           ;;
676           ;; When a branch is out of range, mips_reorg splits it into a form
677           ;; that uses in-range branches.  There are four basic sequences:
678           ;;
679           ;; (1) Absolute addressing with a readable text segment
680           ;;     (32-bit addresses):
681           ;;
682           ;;     b... foo               2 bytes
683           ;;     move $1,$2             2 bytes
684           ;;     lw $2,label            2 bytes
685           ;;     jr $2                  2 bytes
686           ;;     move $2,$1             2 bytes
687           ;;     .align 2               0 or 2 bytes
688           ;; label:
689           ;;     .word target           4 bytes
690           ;; foo:
691           ;;                            (16 bytes in the worst case)
692           ;;
693           ;; (2) Absolute addressing with a readable text segment
694           ;;     (64-bit addresses):
695           ;;
696           ;;     b... foo               2 bytes
697           ;;     move $1,$2             2 bytes
698           ;;     ld $2,label            2 bytes
699           ;;     jr $2                  2 bytes
700           ;;     move $2,$1             2 bytes
701           ;;     .align 3               0 to 6 bytes
702           ;; label:
703           ;;     .dword target          8 bytes
704           ;; foo:
705           ;;                            (24 bytes in the worst case)
706           ;;
707           ;; (3) Absolute addressing without a readable text segment
708           ;;     (which requires 32-bit addresses at present):
709           ;;
710           ;;     b... foo               2 bytes
711           ;;     move $1,$2             2 bytes
712           ;;     lui $2,%hi(target)     4 bytes
713           ;;     sll $2,8               2 bytes
714           ;;     sll $2,8               2 bytes
715           ;;     addiu $2,%lo(target)   4 bytes
716           ;;     jr $2                  2 bytes
717           ;;     move $2,$1             2 bytes
718           ;; foo:
719           ;;                            (20 bytes)
720           ;;
721           ;; (4) PIC addressing (which requires 32-bit addresses at present):
722           ;;
723           ;;     b... foo               2 bytes
724           ;;     move $1,$2             2 bytes
725           ;;     lw $2,cprestore        0, 2 or 4 bytes
726           ;;     lw $2,%got(target)($2) 4 bytes
727           ;;     addiu $2,%lo(target)   4 bytes
728           ;;     jr $2                  2 bytes
729           ;;     move $2,$1             2 bytes
730           ;; foo:
731           ;;                            (20 bytes in the worst case)
732           (and (eq_attr "type" "branch")
733                (match_test "TARGET_MIPS16"))
734           (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
735                       (le (minus (pc) (match_dup 0)) (const_int 254)))
736                  (const_int 2)
737                  (and (le (minus (match_dup 0) (pc)) (const_int 65534))
738                       (le (minus (pc) (match_dup 0)) (const_int 65532)))
739                  (const_int 4)
740                  (and (match_test "TARGET_ABICALLS")
741                       (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
742                  (const_int 20)
743                  (match_test "Pmode == SImode")
744                  (const_int 16)
745                  ] (const_int 24))]
746          (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
748 ;; Attribute describing the processor.
749 (define_enum_attr "cpu" "processor"
750   (const (symbol_ref "mips_tune")))
752 ;; The type of hardware hazard associated with this instruction.
753 ;; DELAY means that the next instruction cannot read the result
754 ;; of this one.  HILO means that the next two instructions cannot
755 ;; write to HI or LO.
756 (define_attr "hazard" "none,delay,hilo,forbidden_slot"
757   (cond [(and (eq_attr "type" "load,fpload,fpidxload")
758               (match_test "ISA_HAS_LOAD_DELAY"))
759          (const_string "delay")
761          (and (eq_attr "type" "mfc,mtc")
762               (match_test "ISA_HAS_XFER_DELAY"))
763          (const_string "delay")
765          (and (eq_attr "type" "fcmp")
766               (match_test "ISA_HAS_FCMP_DELAY"))
767          (const_string "delay")
769          ;; The r4000 multiplication patterns include an mflo instruction.
770          (and (eq_attr "type" "imul")
771               (match_test "TARGET_FIX_R4000"))
772          (const_string "hilo")
774          (and (eq_attr "type" "mfhi,mflo")
775               (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
776          (const_string "hilo")]
777         (const_string "none")))
779 ;; Can the instruction be put into a delay slot?
780 (define_attr "can_delay" "no,yes"
781   (if_then_else (and (eq_attr "type" "!branch,call,jump,simd_branch")
782                      (eq_attr "hazard" "none")
783                      (match_test "get_attr_insn_count (insn) == 1"))
784                 (const_string "yes")
785                 (const_string "no")))
787 ;; Attribute defining whether or not we can use the branch-likely
788 ;; instructions.
789 (define_attr "branch_likely" "no,yes"
790   (if_then_else (match_test "GENERATE_BRANCHLIKELY")
791                 (const_string "yes")
792                 (const_string "no")))
794 ;; True if an instruction might assign to hi or lo when reloaded.
795 ;; This is used by the TUNE_MACC_CHAINS code.
796 (define_attr "may_clobber_hilo" "no,yes"
797   (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
798                 (const_string "yes")
799                 (const_string "no")))
801 ;; Describe a user's asm statement.
802 (define_asm_attributes
803   [(set_attr "type" "multi")
804    (set_attr "can_delay" "no")])
806 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
807 ;; from the same template.
808 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
810 ;; A copy of GPR that can be used when a pattern has two independent
811 ;; modes.
812 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
814 (define_mode_iterator MOVEP1 [SI SF])
815 (define_mode_iterator MOVEP2 [SI SF])
816 (define_mode_iterator JOIN_MODE [HI
817                                  SI
818                                  (SF "TARGET_HARD_FLOAT")
819                                  (DF "TARGET_HARD_FLOAT
820                                       && TARGET_DOUBLE_FLOAT")])
822 ;; This mode iterator allows :HILO to be used as the mode of the
823 ;; concatenated HI and LO registers.
824 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
826 ;; This mode iterator allows :P to be used for patterns that operate on
827 ;; pointer-sized quantities.  Exactly one of the two alternatives will match.
828 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
830 ;; This mode iterator allows :MOVECC to be used anywhere that a
831 ;; conditional-move-type condition is needed.
832 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
833                               (CC "TARGET_HARD_FLOAT
834                                    && !TARGET_LOONGSON_2EF
835                                    && !TARGET_MIPS5900")
836                               (CCE "TARGET_HARD_FLOAT
837                                    && !TARGET_LOONGSON_2EF
838                                    && !TARGET_MIPS5900")])
840 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
841 ;; is needed.
842 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF") (CCE "!ISA_HAS_CCF")
843                             (CCF "ISA_HAS_CCF")])
845 ;; 32-bit integer moves for which we provide move patterns.
846 (define_mode_iterator IMOVE32
847   [SI
848    (V2HI "TARGET_DSP")
849    (V4QI "TARGET_DSP")
850    (V2HQ "TARGET_DSP")
851    (V2UHQ "TARGET_DSP")
852    (V2HA "TARGET_DSP")
853    (V2UHA "TARGET_DSP")
854    (V4QQ "TARGET_DSP")
855    (V4UQQ "TARGET_DSP")])
857 ;; 64-bit modes for which we provide move patterns.
858 (define_mode_iterator MOVE64
859   [DI DF
860    (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
861    (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")
862    (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")
863    (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")])
865 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
866 (define_mode_iterator MOVE128 [TI TF])
868 ;; This mode iterator allows the QI and HI extension patterns to be
869 ;; defined from the same template.
870 (define_mode_iterator SHORT [QI HI])
872 ;; Likewise the 64-bit truncate-and-shift patterns.
873 (define_mode_iterator SUBDI [QI HI SI])
875 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
876 ;; floating-point mode is allowed.
877 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
878                             (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
879                             (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
881 ;; Like ANYF, but only applies to scalar modes.
882 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
883                                (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
885 ;; A floating-point mode for which moves involving FPRs may need to be split.
886 (define_mode_iterator SPLITF
887   [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
888    (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
889    (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
890    (V2SI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
891    (V4HI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
892    (V8QI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
893    (TF "TARGET_64BIT && TARGET_FLOAT64")])
895 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
896 ;; 32-bit version and "dsubu" in the 64-bit version.
897 (define_mode_attr d [(SI "") (DI "d")
898                      (QQ "") (HQ "") (SQ "") (DQ "d")
899                      (UQQ "") (UHQ "") (USQ "") (UDQ "d")
900                      (HA "") (SA "") (DA "d")
901                      (UHA "") (USA "") (UDA "d")])
903 ;; Same as d but upper-case.
904 (define_mode_attr D [(SI "") (DI "D")
905                      (QQ "") (HQ "") (SQ "") (DQ "D")
906                      (UQQ "") (UHQ "") (USQ "") (UDQ "D")
907                      (HA "") (SA "") (DA "D")
908                      (UHA "") (USA "") (UDA "D")])
910 ;; This attribute gives the length suffix for a load or store instruction.
911 ;; The same suffixes work for zero and sign extensions.
912 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
913 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
915 ;; This attributes gives the mode mask of a SHORT.
916 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
918 ;; Mode attributes for GPR loads.
919 (define_mode_attr load [(SI "lw") (DI "ld")])
920 ;; Instruction names for stores.
921 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
923 ;; Similarly for MIPS IV indexed FPR loads and stores.
924 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
925 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
927 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
928 ;; are different.  Some forms of unextended addiu have an 8-bit immediate
929 ;; field but the equivalent daddiu has only a 5-bit field.
930 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
932 ;; This attribute gives the best constraint to use for registers of
933 ;; a given mode.
934 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCE "z") (CCF "f")])
936 ;; This attribute gives the format suffix for floating-point operations.
937 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
939 ;; This attribute gives the upper-case mode name for one unit of a
940 ;; floating-point mode or vector mode.
941 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF") (V4SF "SF")
942                             (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
943                             (V2DF "DF")])
945 ;; As above, but in lower case.
946 (define_mode_attr unitmode [(SF "sf") (DF "df") (V2SF "sf") (V4SF "sf")
947                             (V16QI "qi") (V8QI "qi") (V8HI "hi") (V4HI "hi")
948                             (V4SI "si") (V2SI "si") (V2DI "di") (V2DF "df")])
950 ;; This attribute gives the integer mode that has the same size as a
951 ;; fixed-point mode.
952 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
953                          (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
954                          (HA "HI") (SA "SI") (DA "DI")
955                          (UHA "HI") (USA "SI") (UDA "DI")
956                          (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
957                          (V2HQ "SI") (V2HA "SI")])
959 ;; This attribute gives the integer mode that has half the size of
960 ;; the controlling mode.
961 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
962                             (V2SI "SI") (V4HI "SI") (V8QI "SI")
963                             (TF "DI")])
965 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
967 ;; In certain cases, div.s and div.ps may have a rounding error
968 ;; and/or wrong inexact flag.
970 ;; Therefore, we only allow div.s if not working around SB-1 rev2
971 ;; errata or if a slight loss of precision is OK.
972 (define_mode_attr divide_condition
973   [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
974    (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
976 ;; This attribute gives the conditions under which SQRT.fmt instructions
977 ;; can be used.
978 (define_mode_attr sqrt_condition
979   [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
981 ;; This attribute provides the correct mnemonic for each FP condition mode.
982 (define_mode_attr fpcmp [(CC "c") (CCE "c") (CCF "cmp")])
984 ;; This code iterator allows signed and unsigned widening multiplications
985 ;; to use the same template.
986 (define_code_iterator any_extend [sign_extend zero_extend])
988 ;; This code iterator allows the two right shift instructions to be
989 ;; generated from the same template.
990 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
992 ;; This code iterator allows the three shift instructions to be generated
993 ;; from the same template.
994 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
996 ;; This code iterator allows the three bitwise instructions to be generated
997 ;; from the same template.
998 (define_code_iterator any_bitwise [and ior xor])
1000 ;; This code iterator allows unsigned and signed division to be generated
1001 ;; from the same template.
1002 (define_code_iterator any_div [div udiv])
1004 ;; This code iterator allows unsigned and signed modulus to be generated
1005 ;; from the same template.
1006 (define_code_iterator any_mod [mod umod])
1008 ;; This code iterator allows addition and subtraction to be generated
1009 ;; from the same template.
1010 (define_code_iterator addsub [plus minus])
1012 ;; This code iterator allows all native floating-point comparisons to be
1013 ;; generated from the same template.
1014 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
1015                              (ordered "ISA_HAS_CCF")
1016                              (ltgt "ISA_HAS_CCF")
1017                              (ne "ISA_HAS_CCF")])
1019 ;; This code iterator is used for comparisons that can be implemented
1020 ;; by swapping the operands.
1021 (define_code_iterator swapped_fcond [ge gt unge ungt])
1023 ;; Equality operators.
1024 (define_code_iterator equality_op [eq ne])
1026 ;; These code iterators allow the signed and unsigned scc operations to use
1027 ;; the same template.
1028 (define_code_iterator any_gt [gt gtu])
1029 (define_code_iterator any_ge [ge geu])
1030 (define_code_iterator any_lt [lt ltu])
1031 (define_code_iterator any_le [le leu])
1033 (define_code_iterator any_return [return simple_return])
1035 ;; <u> expands to an empty string when doing a signed operation and
1036 ;; "u" when doing an unsigned operation.
1037 (define_code_attr u [(sign_extend "") (zero_extend "u")
1038                      (div "") (udiv "u")
1039                      (mod "") (umod "u")
1040                      (gt "") (gtu "u")
1041                      (ge "") (geu "u")
1042                      (lt "") (ltu "u")
1043                      (le "") (leu "u")])
1045 ;; <U> is like <u> except uppercase.
1046 (define_code_attr U [(sign_extend "") (zero_extend "U")])
1048 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
1049 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
1051 ;; <optab> expands to the name of the optab for a particular code.
1052 (define_code_attr optab [(ashift "ashl")
1053                          (ashiftrt "ashr")
1054                          (lshiftrt "lshr")
1055                          (ior "ior")
1056                          (xor "xor")
1057                          (and "and")
1058                          (plus "add")
1059                          (minus "sub")
1060                          (return "return")
1061                          (simple_return "simple_return")])
1063 ;; <insn> expands to the name of the insn that implements a particular code.
1064 (define_code_attr insn [(ashift "sll")
1065                         (ashiftrt "sra")
1066                         (lshiftrt "srl")
1067                         (ior "or")
1068                         (xor "xor")
1069                         (and "and")
1070                         (plus "addu")
1071                         (minus "subu")])
1073 ;; <immediate_insn> expands to the name of the insn that implements
1074 ;; a particular code to operate on immediate values.
1075 (define_code_attr immediate_insn [(ior "ori")
1076                                   (xor "xori")
1077                                   (and "andi")])
1079 (define_code_attr shift_compression [(ashift "micromips32")
1080                                      (lshiftrt "micromips32")
1081                                      (ashiftrt "none")])
1083 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1084 (define_code_attr fcond [(unordered "un")
1085                          (uneq "ueq")
1086                          (unlt "ult")
1087                          (unle "ule")
1088                          (eq "eq")
1089                          (lt "lt")
1090                          (le "le")
1091                          (ordered "or")
1092                          (ltgt "sne")
1093                          (ne "une")])
1095 ;; Similar, but for swapped conditions.
1096 (define_code_attr swapped_fcond [(ge "le")
1097                                  (gt "lt")
1098                                  (unge "ule")
1099                                  (ungt "ult")])
1101 ;; The value of the bit when the branch is taken for branch_bit patterns.
1102 ;; Comparison is always against zero so this depends on the operator.
1103 (define_code_attr bbv [(eq "0") (ne "1")])
1105 ;; This is the inverse value of bbv.
1106 (define_code_attr bbinv [(eq "1") (ne "0")])
1108 ;; The sel mnemonic to use depending on the condition test.
1109 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1110 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1112 ;; .........................
1114 ;;      Branch, call and jump delay slots
1116 ;; .........................
1118 (define_delay (and (eq_attr "type" "branch")
1119                    (not (match_test "TARGET_MIPS16"))
1120                    (eq_attr "branch_likely" "yes"))
1121   [(eq_attr "can_delay" "yes")
1122    (nil)
1123    (eq_attr "can_delay" "yes")])
1125 ;; Branches that have delay slots and don't have likely variants do
1126 ;; not annul on false.
1127 (define_delay (and (eq_attr "type" "branch,simd_branch")
1128                    (not (match_test "TARGET_MIPS16"))
1129                    (ior (match_test "TARGET_CB_NEVER")
1130                         (and (eq_attr "compact_form" "maybe")
1131                              (not (match_test "TARGET_CB_ALWAYS")))
1132                         (eq_attr "compact_form" "never"))
1133                    (eq_attr "branch_likely" "no"))
1134   [(eq_attr "can_delay" "yes")
1135    (nil)
1136    (nil)])
1138 (define_delay (and (eq_attr "type" "jump")
1139                    (ior (match_test "TARGET_CB_NEVER")
1140                         (and (eq_attr "compact_form" "maybe")
1141                              (not (match_test "TARGET_CB_ALWAYS")))
1142                         (eq_attr "compact_form" "never")))
1143   [(eq_attr "can_delay" "yes")
1144    (nil)
1145    (nil)])
1147 ;; Call type instructions should never have a compact form as the
1148 ;; type is only used for MIPS16 patterns.  For safety put the compact
1149 ;; branch detection condition in anyway.
1150 (define_delay (and (eq_attr "type" "call")
1151                    (eq_attr "jal_macro" "no")
1152                    (ior (match_test "TARGET_CB_NEVER")
1153                         (and (eq_attr "compact_form" "maybe")
1154                              (not (match_test "TARGET_CB_ALWAYS")))
1155                         (eq_attr "compact_form" "never")))
1156   [(eq_attr "can_delay" "yes")
1157    (nil)
1158    (nil)])
1160 ;; Pipeline descriptions.
1162 ;; generic.md provides a fallback for processors without a specific
1163 ;; pipeline description.  It is derived from the old define_function_unit
1164 ;; version and uses the "alu" and "imuldiv" units declared below.
1166 ;; Some of the processor-specific files are also derived from old
1167 ;; define_function_unit descriptions and simply override the parts of
1168 ;; generic.md that don't apply.  The other processor-specific files
1169 ;; are self-contained.
1170 (define_automaton "alu,imuldiv")
1172 (define_cpu_unit "alu" "alu")
1173 (define_cpu_unit "imuldiv" "imuldiv")
1175 ;; Ghost instructions produce no real code and introduce no hazards.
1176 ;; They exist purely to express an effect on dataflow.
1177 (define_insn_reservation "ghost" 0
1178   (eq_attr "type" "ghost")
1179   "nothing")
1181 (include "i6400.md")
1182 (include "p5600.md")
1183 (include "m5100.md")
1184 (include "p6600.md")
1185 (include "4k.md")
1186 (include "5k.md")
1187 (include "20kc.md")
1188 (include "24k.md")
1189 (include "74k.md")
1190 (include "3000.md")
1191 (include "4000.md")
1192 (include "4100.md")
1193 (include "4130.md")
1194 (include "4300.md")
1195 (include "4600.md")
1196 (include "5000.md")
1197 (include "5400.md")
1198 (include "5500.md")
1199 (include "6000.md")
1200 (include "7000.md")
1201 (include "9000.md")
1202 (include "10000.md")
1203 (include "loongson2ef.md")
1204 (include "gs464.md")
1205 (include "gs464e.md")
1206 (include "gs264e.md")
1207 (include "octeon.md")
1208 (include "sb1.md")
1209 (include "sr71k.md")
1210 (include "xlr.md")
1211 (include "xlp.md")
1212 (include "generic.md")
1215 ;;  ....................
1217 ;;      CONDITIONAL TRAPS
1219 ;;  ....................
1222 (define_insn "trap"
1223   [(trap_if (const_int 1) (const_int 0))]
1224   ""
1226   if (ISA_HAS_COND_TRAP)
1227     return "teq\t$0,$0";
1228   else if (TARGET_MIPS16)
1229     return "break 0";
1230   else
1231     return "break";
1233   [(set_attr "type" "trap")])
1235 (define_expand "ctrap<mode>4"
1236   [(trap_if (match_operator 0 "comparison_operator"
1237                             [(match_operand:GPR 1 "reg_or_0_operand")
1238                              (match_operand:GPR 2 "arith_operand")])
1239             (match_operand 3 "const_0_operand"))]
1240   "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1242   mips_expand_conditional_trap (operands[0]);
1243   DONE;
1246 (define_insn "*conditional_trap_reg<mode>"
1247   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1248                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1249                                  (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1250             (const_int 0))]
1251   "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1252   "t%C0\t%z1,%z2"
1253   [(set_attr "type" "trap")])
1255 (define_insn "*conditional_trap<mode>"
1256   [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1257                                 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1258                                  (match_operand:GPR 2 "arith_operand" "dI")])
1259             (const_int 0))]
1260   "ISA_HAS_COND_TRAPI"
1261   "t%C0\t%z1,%2"
1262   [(set_attr "type" "trap")])
1265 ;;  ....................
1267 ;;      ADDITION
1269 ;;  ....................
1272 (define_insn "add<mode>3"
1273   [(set (match_operand:ANYF 0 "register_operand" "=f")
1274         (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1275                    (match_operand:ANYF 2 "register_operand" "f")))]
1276   ""
1277   "add.<fmt>\t%0,%1,%2"
1278   [(set_attr "type" "fadd")
1279    (set_attr "mode" "<UNITMODE>")])
1281 (define_expand "add<mode>3"
1282   [(set (match_operand:GPR 0 "register_operand")
1283         (plus:GPR (match_operand:GPR 1 "register_operand")
1284                   (match_operand:GPR 2 "arith_operand")))]
1285   "")
1287 (define_insn "*add<mode>3"
1288   [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1289         (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1290                   (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1291   "!TARGET_MIPS16"
1293   if (which_alternative == 0 
1294       || which_alternative == 1)
1295     return "<d>addu\t%0,%1,%2";
1296   else
1297     return "<d>addiu\t%0,%1,%2";
1299   [(set_attr "alu_type" "add")
1300    (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1301    (set_attr "mode" "<MODE>")])
1303 (define_insn "*add<mode>3_mips16"
1304   [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1305         (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1306                   (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1307   "TARGET_MIPS16"
1308   "@
1309     <d>addiu\t%0,%2
1310     <d>addiu\t%0,%2
1311     <d>addiu\t%0,%1,%2
1312     <d>addiu\t%0,%1,%2
1313     <d>addiu\t%0,%2
1314     <d>addiu\t%0,%2
1315     <d>addiu\t%0,%1,%2
1316     <d>addiu\t%0,%1,%2
1317     <d>addu\t%0,%1,%2"
1318   [(set_attr "alu_type" "add")
1319    (set_attr "mode" "<MODE>")
1320    (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1322 ;; On the mips16, we can sometimes split an add of a constant which is
1323 ;; a 4 byte instruction into two adds which are both 2 byte
1324 ;; instructions.  There are two cases: one where we are adding a
1325 ;; constant plus a register to another register, and one where we are
1326 ;; simply adding a constant to a register.
1328 (define_split
1329   [(set (match_operand:SI 0 "d_operand")
1330         (plus:SI (match_dup 0)
1331                  (match_operand:SI 1 "const_int_operand")))]
1332   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1333    && ((INTVAL (operands[1]) > 0x7f
1334         && INTVAL (operands[1]) <= 0x7f + 0x7f)
1335        || (INTVAL (operands[1]) < - 0x80
1336            && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1337   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1338    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1340   HOST_WIDE_INT val = INTVAL (operands[1]);
1342   if (val >= 0)
1343     {
1344       operands[1] = GEN_INT (0x7f);
1345       operands[2] = GEN_INT (val - 0x7f);
1346     }
1347   else
1348     {
1349       operands[1] = GEN_INT (- 0x80);
1350       operands[2] = GEN_INT (val + 0x80);
1351     }
1354 (define_split
1355   [(set (match_operand:SI 0 "d_operand")
1356         (plus:SI (match_operand:SI 1 "d_operand")
1357                  (match_operand:SI 2 "const_int_operand")))]
1358   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1359    && REGNO (operands[0]) != REGNO (operands[1])
1360    && ((INTVAL (operands[2]) > 0x7
1361         && INTVAL (operands[2]) <= 0x7 + 0x7f)
1362        || (INTVAL (operands[2]) < - 0x8
1363            && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1364   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1365    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1367   HOST_WIDE_INT val = INTVAL (operands[2]);
1369   if (val >= 0)
1370     {
1371       operands[2] = GEN_INT (0x7);
1372       operands[3] = GEN_INT (val - 0x7);
1373     }
1374   else
1375     {
1376       operands[2] = GEN_INT (- 0x8);
1377       operands[3] = GEN_INT (val + 0x8);
1378     }
1381 (define_split
1382   [(set (match_operand:DI 0 "d_operand")
1383         (plus:DI (match_dup 0)
1384                  (match_operand:DI 1 "const_int_operand")))]
1385   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1386    && ((INTVAL (operands[1]) > 0xf
1387         && INTVAL (operands[1]) <= 0xf + 0xf)
1388        || (INTVAL (operands[1]) < - 0x10
1389            && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1390   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1391    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1393   HOST_WIDE_INT val = INTVAL (operands[1]);
1395   if (val >= 0)
1396     {
1397       operands[1] = GEN_INT (0xf);
1398       operands[2] = GEN_INT (val - 0xf);
1399     }
1400   else
1401     {
1402       operands[1] = GEN_INT (- 0x10);
1403       operands[2] = GEN_INT (val + 0x10);
1404     }
1407 (define_split
1408   [(set (match_operand:DI 0 "d_operand")
1409         (plus:DI (match_operand:DI 1 "d_operand")
1410                  (match_operand:DI 2 "const_int_operand")))]
1411   "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1412    && REGNO (operands[0]) != REGNO (operands[1])
1413    && ((INTVAL (operands[2]) > 0x7
1414         && INTVAL (operands[2]) <= 0x7 + 0xf)
1415        || (INTVAL (operands[2]) < - 0x8
1416            && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1417   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1418    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1420   HOST_WIDE_INT val = INTVAL (operands[2]);
1422   if (val >= 0)
1423     {
1424       operands[2] = GEN_INT (0x7);
1425       operands[3] = GEN_INT (val - 0x7);
1426     }
1427   else
1428     {
1429       operands[2] = GEN_INT (- 0x8);
1430       operands[3] = GEN_INT (val + 0x8);
1431     }
1434 (define_insn "*addsi3_extended"
1435   [(set (match_operand:DI 0 "register_operand" "=d,d")
1436         (sign_extend:DI
1437              (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1438                       (match_operand:SI 2 "arith_operand" "d,Q"))))]
1439   "TARGET_64BIT && !TARGET_MIPS16"
1440   "@
1441     addu\t%0,%1,%2
1442     addiu\t%0,%1,%2"
1443   [(set_attr "alu_type" "add")
1444    (set_attr "mode" "SI")])
1446 ;; Split this insn so that the addiu splitters can have a crack at it.
1447 ;; Use a conservative length estimate until the split.
1448 (define_insn_and_split "*addsi3_extended_mips16"
1449   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1450         (sign_extend:DI
1451              (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1452                       (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1453   "TARGET_64BIT && TARGET_MIPS16"
1454   "#"
1455   "&& reload_completed"
1456   [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1457   { operands[3] = gen_lowpart (SImode, operands[0]); }
1458   [(set_attr "alu_type" "add")
1459    (set_attr "mode" "SI")
1460    (set_attr "extended_mips16" "yes")])
1462 ;; Combiner patterns for unsigned byte-add.
1464 (define_insn "*baddu_si_eb"
1465   [(set (match_operand:SI 0 "register_operand" "=d")
1466         (zero_extend:SI
1467          (subreg:QI
1468           (plus:SI (match_operand:SI 1 "register_operand" "d")
1469                    (match_operand:SI 2 "register_operand" "d")) 3)))]
1470   "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1471   "baddu\\t%0,%1,%2"
1472   [(set_attr "alu_type" "add")])
1474 (define_insn "*baddu_si_el"
1475   [(set (match_operand:SI 0 "register_operand" "=d")
1476         (zero_extend:SI
1477          (subreg:QI
1478           (plus:SI (match_operand:SI 1 "register_operand" "d")
1479                    (match_operand:SI 2 "register_operand" "d")) 0)))]
1480   "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1481   "baddu\\t%0,%1,%2"
1482   [(set_attr "alu_type" "add")])
1484 (define_insn "*baddu_di<mode>"
1485   [(set (match_operand:GPR 0 "register_operand" "=d")
1486         (zero_extend:GPR
1487          (truncate:QI
1488           (plus:DI (match_operand:DI 1 "register_operand" "d")
1489                    (match_operand:DI 2 "register_operand" "d")))))]
1490   "ISA_HAS_BADDU && TARGET_64BIT"
1491   "baddu\\t%0,%1,%2"
1492   [(set_attr "alu_type" "add")])
1495 ;;  ....................
1497 ;;      SUBTRACTION
1499 ;;  ....................
1502 (define_insn "sub<mode>3"
1503   [(set (match_operand:ANYF 0 "register_operand" "=f")
1504         (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1505                     (match_operand:ANYF 2 "register_operand" "f")))]
1506   ""
1507   "sub.<fmt>\t%0,%1,%2"
1508   [(set_attr "type" "fadd")
1509    (set_attr "mode" "<UNITMODE>")])
1511 (define_insn "sub<mode>3"
1512   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1513         (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1514                    (match_operand:GPR 2 "register_operand" "!u,d")))]
1515   ""
1516   "<d>subu\t%0,%1,%2"
1517   [(set_attr "alu_type" "sub")
1518    (set_attr "compression" "micromips32,*")
1519    (set_attr "mode" "<MODE>")])
1521 (define_insn "*subsi3_extended"
1522   [(set (match_operand:DI 0 "register_operand" "=d")
1523         (sign_extend:DI
1524             (minus:SI (match_operand:SI 1 "register_operand" "d")
1525                       (match_operand:SI 2 "register_operand" "d"))))]
1526   "TARGET_64BIT"
1527   "subu\t%0,%1,%2"
1528   [(set_attr "alu_type" "sub")
1529    (set_attr "mode" "DI")])
1532 ;;  ....................
1534 ;;      MULTIPLICATION
1536 ;;  ....................
1539 (define_expand "mul<mode>3"
1540   [(set (match_operand:SCALARF 0 "register_operand")
1541         (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1542                       (match_operand:SCALARF 2 "register_operand")))]
1543   ""
1544   "")
1546 (define_insn "*mul<mode>3"
1547   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1548         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1549                       (match_operand:SCALARF 2 "register_operand" "f")))]
1550   "!TARGET_4300_MUL_FIX"
1551   "mul.<fmt>\t%0,%1,%2"
1552   [(set_attr "type" "fmul")
1553    (set_attr "mode" "<MODE>")])
1555 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1556 ;; operands may corrupt immediately following multiplies. This is a
1557 ;; simple fix to insert NOPs.
1559 (define_insn "*mul<mode>3_r4300"
1560   [(set (match_operand:SCALARF 0 "register_operand" "=f")
1561         (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1562                       (match_operand:SCALARF 2 "register_operand" "f")))]
1563   "TARGET_4300_MUL_FIX"
1564   "mul.<fmt>\t%0,%1,%2\;nop"
1565   [(set_attr "type" "fmul")
1566    (set_attr "mode" "<MODE>")
1567    (set_attr "insn_count" "2")])
1569 (define_insn "mulv2sf3"
1570   [(set (match_operand:V2SF 0 "register_operand" "=f")
1571         (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1572                    (match_operand:V2SF 2 "register_operand" "f")))]
1573   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1574   "mul.ps\t%0,%1,%2"
1575   [(set_attr "type" "fmul")
1576    (set_attr "mode" "SF")])
1578 ;; The original R4000 has a cpu bug.  If a double-word or a variable
1579 ;; shift executes while an integer multiplication is in progress, the
1580 ;; shift may give an incorrect result.  Avoid this by keeping the mflo
1581 ;; with the mult on the R4000.
1583 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1584 ;; (also valid for MIPS R4000MC processors):
1586 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1587 ;;      this errata description.
1588 ;;      The following code sequence causes the R4000 to incorrectly
1589 ;;      execute the Double Shift Right Arithmetic 32 (dsra32)
1590 ;;      instruction.  If the dsra32 instruction is executed during an
1591 ;;      integer multiply, the dsra32 will only shift by the amount in
1592 ;;      specified in the instruction rather than the amount plus 32
1593 ;;      bits.
1594 ;;      instruction 1:          mult    rs,rt           integer multiply
1595 ;;      instruction 2-12:       dsra32  rd,rt,rs        doubleword shift
1596 ;;                                                      right arithmetic + 32
1597 ;;      Workaround: A dsra32 instruction placed after an integer
1598 ;;      multiply should not be one of the 11 instructions after the
1599 ;;      multiply instruction."
1601 ;; and:
1603 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1604 ;;      the following description.
1605 ;;      All extended shifts (shift by n+32) and variable shifts (32 and
1606 ;;      64-bit versions) may produce incorrect results under the
1607 ;;      following conditions:
1608 ;;      1) An integer multiply is currently executing
1609 ;;      2) These types of shift instructions are executed immediately
1610 ;;         following an integer divide instruction.
1611 ;;      Workaround:
1612 ;;      1) Make sure no integer multiply is running wihen these
1613 ;;         instruction are executed.  If this cannot be predicted at
1614 ;;         compile time, then insert a "mfhi" to R0 instruction
1615 ;;         immediately after the integer multiply instruction.  This
1616 ;;         will cause the integer multiply to complete before the shift
1617 ;;         is executed.
1618 ;;      2) Separate integer divide and these two classes of shift
1619 ;;         instructions by another instruction or a noop."
1621 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1622 ;; respectively.
1624 (define_expand "mul<mode>3"
1625   [(set (match_operand:GPR 0 "register_operand")
1626         (mult:GPR (match_operand:GPR 1 "register_operand")
1627                   (match_operand:GPR 2 "register_operand")))]
1628   "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1630   rtx lo;
1632   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>MUL)
1633     emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1634                                            operands[2]));
1635   else if (ISA_HAS_<D>MUL3)
1636     emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1637   else if (TARGET_MIPS16)
1638     {
1639       lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1640       emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1641       emit_move_insn (operands[0], lo);
1642     }
1643   else if (TARGET_FIX_R4000)
1644     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1645   else
1646     emit_insn
1647       (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1648   DONE;
1651 (define_insn "mul<mode>3_mul3_nohilo"
1652   [(set (match_operand:GPR 0 "register_operand" "=d")
1653         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1654                   (match_operand:GPR 2 "register_operand" "d")))]
1655   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>MUL"
1657   if (TARGET_LOONGSON_2EF)
1658     return "<d>multu.g\t%0,%1,%2";
1659   else if (TARGET_LOONGSON_EXT)
1660     return "gs<d>multu\t%0,%1,%2";
1661   else
1662     return "<d>mul\t%0,%1,%2";
1664   [(set_attr "type" "imul3nc")
1665    (set_attr "mode" "<MODE>")])
1667 (define_insn "mul<mode>3_mul3"
1668   [(set (match_operand:GPR 0 "register_operand" "=d,l")
1669         (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1670                   (match_operand:GPR 2 "register_operand" "d,d")))
1671    (clobber (match_scratch:GPR 3 "=l,X"))]
1672   "ISA_HAS_<D>MUL3"
1674   if (which_alternative == 1)
1675     return "<d>mult\t%1,%2";
1676   if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1677     return "mult\t%0,%1,%2";
1678   return "<d>mul\t%0,%1,%2";
1680   [(set_attr "type" "imul3,imul")
1681    (set_attr "mode" "<MODE>")])
1683 ;; If a register gets allocated to LO, and we spill to memory, the reload
1684 ;; will include a move from LO to a GPR.  Merge it into the multiplication
1685 ;; if it can set the GPR directly.
1687 ;; Operand 0: LO
1688 ;; Operand 1: GPR (1st multiplication operand)
1689 ;; Operand 2: GPR (2nd multiplication operand)
1690 ;; Operand 3: GPR (destination)
1691 (define_peephole2
1692   [(parallel
1693        [(set (match_operand:SI 0 "lo_operand")
1694              (mult:SI (match_operand:SI 1 "d_operand")
1695                       (match_operand:SI 2 "d_operand")))
1696         (clobber (scratch:SI))])
1697    (set (match_operand:SI 3 "d_operand")
1698         (match_dup 0))]
1699   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1700   [(parallel
1701        [(set (match_dup 3)
1702              (mult:SI (match_dup 1)
1703                       (match_dup 2)))
1704         (clobber (match_dup 0))])])
1706 (define_insn "mul<mode>3_internal"
1707   [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1708         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1709                   (match_operand:GPR 2 "register_operand" "d")))]
1710   "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1711   "<d>mult\t%1,%2"
1712   [(set_attr "type" "imul")
1713    (set_attr "mode" "<MODE>")])
1715 (define_insn "mul<mode>3_r4000"
1716   [(set (match_operand:GPR 0 "register_operand" "=d")
1717         (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1718                   (match_operand:GPR 2 "register_operand" "d")))
1719    (clobber (match_scratch:GPR 3 "=l"))]
1720   "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1721   "<d>mult\t%1,%2\;mflo\t%0"
1722   [(set_attr "type" "imul")
1723    (set_attr "mode" "<MODE>")
1724    (set_attr "insn_count" "2")])
1726 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1727 ;; of "mult; mflo".  They have the same latency, but the first form gives
1728 ;; us an extra cycle to compute the operands.
1730 ;; Operand 0: LO
1731 ;; Operand 1: GPR (1st multiplication operand)
1732 ;; Operand 2: GPR (2nd multiplication operand)
1733 ;; Operand 3: GPR (destination)
1734 (define_peephole2
1735   [(set (match_operand:SI 0 "lo_operand")
1736         (mult:SI (match_operand:SI 1 "d_operand")
1737                  (match_operand:SI 2 "d_operand")))
1738    (set (match_operand:SI 3 "d_operand")
1739         (match_dup 0))]
1740   "ISA_HAS_MACC && !ISA_HAS_MUL3"
1741   [(set (match_dup 0)
1742         (const_int 0))
1743    (parallel
1744        [(set (match_dup 0)
1745              (plus:SI (mult:SI (match_dup 1)
1746                                (match_dup 2))
1747                       (match_dup 0)))
1748         (set (match_dup 3)
1749              (plus:SI (mult:SI (match_dup 1)
1750                                (match_dup 2))
1751                       (match_dup 0)))])])
1753 ;; Multiply-accumulate patterns
1755 ;; This pattern is first matched by combine, which tries to use the
1756 ;; pattern wherever it can.  We don't know until later whether it
1757 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1758 ;; so we need to keep both options open.
1760 ;; The second alternative has a "?" marker because it is generally
1761 ;; one instruction more costly than the first alternative.  This "?"
1762 ;; marker is enough to convey the relative costs to the register
1763 ;; allocator.
1765 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1766 ;; reloads of the other operands, even though operands 4 and 5 need no
1767 ;; copy instructions.  Reload therefore thinks that the second alternative
1768 ;; is two reloads more costly than the first.  We add "*?*?" to the first
1769 ;; alternative as a counterweight.
1771 ;; LRA simulates reload but the cost of reloading scratches is lower
1772 ;; than of the classic reload. For the time being, removing the counterweight
1773 ;; for LRA is more profitable.
1774 (define_insn "*mul_acc_si"
1775   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1776         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1777                           (match_operand:SI 2 "register_operand" "d,d,d"))
1778                  (match_operand:SI 3 "register_operand" "l,l,d")))
1779    (clobber (match_scratch:SI 4 "=X,X,l"))
1780    (clobber (match_scratch:SI 5 "=X,X,&d"))]
1781   "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1782   "@
1783     madd\t%1,%2
1784     madd\t%1,%2
1785     #"
1786   [(set_attr "type"     "imadd")
1787    (set_attr "accum_in" "3")
1788    (set_attr "mode"     "SI")
1789    (set_attr "insn_count" "1,1,2")
1790    (set (attr "enabled")
1791         (cond [(eq_attr "alternative" "1,2")
1792                   (const_string "yes")]
1793               (const_string "no")))])
1795 ;; The same idea applies here.  The middle alternative needs one less
1796 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1797 (define_insn "*mul_acc_si_r3900"
1798   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1799         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1800                           (match_operand:SI 2 "register_operand" "d,d,d,d"))
1801                  (match_operand:SI 3 "register_operand" "l,l,l,d")))
1802    (clobber (match_scratch:SI 4 "=X,X,3,l"))
1803    (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1804   "TARGET_MIPS3900 && !TARGET_MIPS16"
1805   "@
1806     madd\t%1,%2
1807     madd\t%1,%2
1808     madd\t%0,%1,%2
1809     #"
1810   [(set_attr "type"     "imadd")
1811    (set_attr "accum_in" "3")
1812    (set_attr "mode"     "SI")
1813    (set_attr "insn_count" "1,1,1,2")
1814    (set (attr "enabled")
1815         (cond [(eq_attr "alternative" "1,2,3")
1816                   (const_string "yes")]
1817               (const_string "no")))])
1819 ;; Split *mul_acc_si if both the source and destination accumulator
1820 ;; values are GPRs.
1821 (define_split
1822   [(set (match_operand:SI 0 "d_operand")
1823         (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1824                           (match_operand:SI 2 "d_operand"))
1825                  (match_operand:SI 3 "d_operand")))
1826    (clobber (match_operand:SI 4 "lo_operand"))
1827    (clobber (match_operand:SI 5 "d_operand"))]
1828   "reload_completed"
1829   [(parallel [(set (match_dup 5)
1830                    (mult:SI (match_dup 1) (match_dup 2)))
1831               (clobber (match_dup 4))])
1832    (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1833   "")
1835 (define_insn "*macc"
1836   [(set (match_operand:SI 0 "register_operand" "=l,d")
1837         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1838                           (match_operand:SI 2 "register_operand" "d,d"))
1839                  (match_operand:SI 3 "register_operand" "l,l")))
1840    (clobber (match_scratch:SI 4 "=X,3"))]
1841   "ISA_HAS_MACC"
1843   if (which_alternative == 1)
1844     return "macc\t%0,%1,%2";
1845   else if (TARGET_MIPS5500)
1846     return "madd\t%1,%2";
1847   else
1848     /* The VR4130 assumes that there is a two-cycle latency between a macc
1849        that "writes" to $0 and an instruction that reads from it.  We avoid
1850        this by assigning to $1 instead.  */
1851     return "%[macc\t%@,%1,%2%]";
1853   [(set_attr "type" "imadd")
1854    (set_attr "accum_in" "3")
1855    (set_attr "mode" "SI")])
1857 (define_insn "*msac"
1858   [(set (match_operand:SI 0 "register_operand" "=l,d")
1859         (minus:SI (match_operand:SI 1 "register_operand" "l,l")
1860                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1861                            (match_operand:SI 3 "register_operand" "d,d"))))
1862    (clobber (match_scratch:SI 4 "=X,1"))]
1863   "ISA_HAS_MSAC"
1865   if (which_alternative == 1)
1866     return "msac\t%0,%2,%3";
1867   else if (TARGET_MIPS5500)
1868     return "msub\t%2,%3";
1869   else
1870     return "msac\t$0,%2,%3";
1872   [(set_attr "type"     "imadd")
1873    (set_attr "accum_in" "1")
1874    (set_attr "mode"     "SI")])
1876 ;; An msac-like instruction implemented using negation and a macc.
1877 (define_insn_and_split "*msac_using_macc"
1878   [(set (match_operand:SI 0 "register_operand" "=l,d")
1879         (minus:SI (match_operand:SI 1 "register_operand" "l,l")
1880                   (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1881                            (match_operand:SI 3 "register_operand" "d,d"))))
1882    (clobber (match_scratch:SI 4 "=X,1"))
1883    (clobber (match_scratch:SI 5 "=d,d"))]
1884   "ISA_HAS_MACC && !ISA_HAS_MSAC"
1885   "#"
1886   "&& reload_completed"
1887   [(set (match_dup 5)
1888         (neg:SI (match_dup 3)))
1889    (parallel
1890        [(set (match_dup 0)
1891              (plus:SI (mult:SI (match_dup 2)
1892                                (match_dup 5))
1893                       (match_dup 1)))
1894         (clobber (match_dup 4))])]
1895   ""
1896   [(set_attr "type"     "imadd")
1897    (set_attr "accum_in" "1")
1898    (set_attr "insn_count" "2")])
1900 ;; Patterns generated by the define_peephole2 below.
1902 (define_insn "*macc2"
1903   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1904         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1905                           (match_operand:SI 2 "register_operand" "d"))
1906                  (match_dup 0)))
1907    (set (match_operand:SI 3 "register_operand" "=d")
1908         (plus:SI (mult:SI (match_dup 1)
1909                           (match_dup 2))
1910                  (match_dup 0)))]
1911   "ISA_HAS_MACC && reload_completed"
1912   "macc\t%3,%1,%2"
1913   [(set_attr "type"     "imadd")
1914    (set_attr "accum_in" "0")
1915    (set_attr "mode"     "SI")])
1917 (define_insn "*msac2"
1918   [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1919         (minus:SI (match_dup 0)
1920                   (mult:SI (match_operand:SI 1 "register_operand" "d")
1921                            (match_operand:SI 2 "register_operand" "d"))))
1922    (set (match_operand:SI 3 "register_operand" "=d")
1923         (minus:SI (match_dup 0)
1924                   (mult:SI (match_dup 1)
1925                            (match_dup 2))))]
1926   "ISA_HAS_MSAC && reload_completed"
1927   "msac\t%3,%1,%2"
1928   [(set_attr "type"     "imadd")
1929    (set_attr "accum_in" "0")
1930    (set_attr "mode"     "SI")])
1932 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1933 ;; Similarly msac.
1935 ;; Operand 0: LO
1936 ;; Operand 1: macc/msac
1937 ;; Operand 2: GPR (destination)
1938 (define_peephole2
1939   [(parallel
1940        [(set (match_operand:SI 0 "lo_operand")
1941              (match_operand:SI 1 "macc_msac_operand"))
1942         (clobber (scratch:SI))])
1943    (set (match_operand:SI 2 "d_operand")
1944         (match_dup 0))]
1945   ""
1946   [(parallel [(set (match_dup 0)
1947                    (match_dup 1))
1948               (set (match_dup 2)
1949                    (match_dup 1))])])
1951 ;; When we have a three-address multiplication instruction, it should
1952 ;; be faster to do a separate multiply and add, rather than moving
1953 ;; something into LO in order to use a macc instruction.
1955 ;; This peephole needs a scratch register to cater for the case when one
1956 ;; of the multiplication operands is the same as the destination.
1958 ;; Operand 0: GPR (scratch)
1959 ;; Operand 1: LO
1960 ;; Operand 2: GPR (addend)
1961 ;; Operand 3: GPR (destination)
1962 ;; Operand 4: macc/msac
1963 ;; Operand 5: new multiplication
1964 ;; Operand 6: new addition/subtraction
1965 (define_peephole2
1966   [(match_scratch:SI 0 "d")
1967    (set (match_operand:SI 1 "lo_operand")
1968         (match_operand:SI 2 "d_operand"))
1969    (match_dup 0)
1970    (parallel
1971        [(set (match_operand:SI 3 "d_operand")
1972              (match_operand:SI 4 "macc_msac_operand"))
1973         (clobber (match_dup 1))])]
1974   "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1975   [(parallel [(set (match_dup 0)
1976                    (match_dup 5))
1977               (clobber (match_dup 1))])
1978    (set (match_dup 3)
1979         (match_dup 6))]
1981   operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1982   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1983                                 operands[2], operands[0]);
1986 ;; Same as above, except LO is the initial target of the macc.
1988 ;; Operand 0: GPR (scratch)
1989 ;; Operand 1: LO
1990 ;; Operand 2: GPR (addend)
1991 ;; Operand 3: macc/msac
1992 ;; Operand 4: GPR (destination)
1993 ;; Operand 5: new multiplication
1994 ;; Operand 6: new addition/subtraction
1995 (define_peephole2
1996   [(match_scratch:SI 0 "d")
1997    (set (match_operand:SI 1 "lo_operand")
1998         (match_operand:SI 2 "d_operand"))
1999    (match_dup 0)
2000    (parallel
2001        [(set (match_dup 1)
2002              (match_operand:SI 3 "macc_msac_operand"))
2003         (clobber (scratch:SI))])
2004    (match_dup 0)
2005    (set (match_operand:SI 4 "d_operand")
2006         (match_dup 1))]
2007   "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
2008   [(parallel [(set (match_dup 0)
2009                    (match_dup 5))
2010               (clobber (match_dup 1))])
2011    (set (match_dup 4)
2012         (match_dup 6))]
2014   operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
2015   operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2016                                 operands[2], operands[0]);
2019 ;; See the comment above *mul_add_si for details.
2020 (define_insn "*mul_sub_si"
2021   [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
2022         (minus:SI (match_operand:SI 1 "register_operand" "l,l,d")
2023                   (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
2024                            (match_operand:SI 3 "register_operand" "d,d,d"))))
2025    (clobber (match_scratch:SI 4 "=X,X,l"))
2026    (clobber (match_scratch:SI 5 "=X,X,&d"))]
2027   "GENERATE_MADD_MSUB"
2028   "@
2029    msub\t%2,%3
2030    msub\t%2,%3
2031    #"
2032   [(set_attr "type"     "imadd")
2033    (set_attr "accum_in" "1")
2034    (set_attr "mode"     "SI")
2035    (set_attr "insn_count" "1,1,2")
2036    (set (attr "enabled")
2037         (cond [(eq_attr "alternative" "1,2")
2038                   (const_string "yes")]
2039               (const_string "no")))])
2041 ;; Split *mul_sub_si if both the source and destination accumulator
2042 ;; values are GPRs.
2043 (define_split
2044   [(set (match_operand:SI 0 "d_operand")
2045         (minus:SI (match_operand:SI 1 "d_operand")
2046                   (mult:SI (match_operand:SI 2 "d_operand")
2047                            (match_operand:SI 3 "d_operand"))))
2048    (clobber (match_operand:SI 4 "lo_operand"))
2049    (clobber (match_operand:SI 5 "d_operand"))]
2050   "reload_completed"
2051   [(parallel [(set (match_dup 5)
2052                    (mult:SI (match_dup 2) (match_dup 3)))
2053               (clobber (match_dup 4))])
2054    (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
2055   "")
2057 (define_insn "*muls"
2058   [(set (match_operand:SI 0 "register_operand" "=l,d")
2059         (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2060                          (match_operand:SI 2 "register_operand" "d,d"))))
2061    (clobber (match_scratch:SI 3 "=X,l"))]
2062   "ISA_HAS_MULS"
2063   "@
2064    muls\t$0,%1,%2
2065    muls\t%0,%1,%2"
2066   [(set_attr "type"     "imul,imul3")
2067    (set_attr "mode"     "SI")])
2069 (define_expand "<u>mulsidi3"
2070   [(set (match_operand:DI 0 "register_operand")
2071         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2072                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2073   "mips_mulsidi3_gen_fn (<CODE>) != NULL"
2075   mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
2076   emit_insn (fn (operands[0], operands[1], operands[2]));
2077   DONE;
2080 (define_expand "<u>mulsidi3_32bit_r6"
2081   [(set (match_operand:DI 0 "register_operand")
2082         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2083                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2084   "!TARGET_64BIT && ISA_HAS_R6MUL"
2086   rtx dest = gen_reg_rtx (DImode);
2087   rtx low = mips_subword (dest, 0);
2088   rtx high = mips_subword (dest, 1);
2090   emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2091   emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2093   emit_move_insn (mips_subword (operands[0], 0), low);
2094   emit_move_insn (mips_subword (operands[0], 1), high);
2095   DONE;
2098 (define_expand "<u>mulsidi3_32bit_mips16"
2099   [(set (match_operand:DI 0 "register_operand")
2100         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2101                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2102   "!TARGET_64BIT && TARGET_MIPS16"
2104   rtx hilo;
2106   hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2107   emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2108   emit_move_insn (operands[0], hilo);
2109   DONE;
2112 ;; As well as being named patterns, these instructions are used by the
2113 ;; __builtin_mips_mult<u>() functions.  We must always make those functions
2114 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2115 (define_insn "<u>mulsidi3_32bit"
2116   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2117         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2118                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2119   "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2121   if (ISA_HAS_DSP_MULT)
2122     return "mult<u>\t%q0,%1,%2";
2123   else
2124     return "mult<u>\t%1,%2";
2126   [(set_attr "type" "imul")
2127    (set_attr "mode" "SI")])
2129 (define_insn "<u>mulsidi3_32bit_r4000"
2130   [(set (match_operand:DI 0 "register_operand" "=d")
2131         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2132                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2133    (clobber (match_scratch:DI 3 "=x"))]
2134   "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2135   "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2136   [(set_attr "type" "imul")
2137    (set_attr "mode" "SI")
2138    (set_attr "insn_count" "3")])
2140 (define_insn_and_split "<u>mulsidi3_64bit"
2141   [(set (match_operand:DI 0 "register_operand" "=d")
2142         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2143                  (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2144    (clobber (match_scratch:TI 3 "=x"))
2145    (clobber (match_scratch:DI 4 "=d"))]
2146   "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2147    && !TARGET_MIPS16 && ISA_HAS_MULT"
2148   "#"
2149   "&& reload_completed"
2150   [(const_int 0)]
2152   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2153                                           operands[2], operands[4]));
2154   DONE;
2156   [(set_attr "type" "imul")
2157    (set_attr "mode" "SI")
2158    (set (attr "insn_count")
2159         (if_then_else (match_test "ISA_HAS_EXT_INS")
2160                       (const_int 4)
2161                       (const_int 7)))])
2163 (define_expand "<u>mulsidi3_64bit_mips16"
2164   [(set (match_operand:DI 0 "register_operand")
2165         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2166                  (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2167   "TARGET_64BIT && TARGET_MIPS16"
2169   emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2170                                           operands[2], gen_reg_rtx (DImode)));
2171   DONE;
2174 (define_expand "<u>mulsidi3_64bit_split"
2175   [(set (match_operand:DI 0 "register_operand")
2176         (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2177                  (any_extend:DI (match_operand:SI 2 "register_operand"))))
2178    (clobber (match_operand:DI 3 "register_operand"))]
2179   ""
2181   rtx hilo;
2183   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2184   emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2186   emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2187   emit_insn (gen_mfhidi_ti (operands[3], hilo));
2189   if (ISA_HAS_EXT_INS)
2190     emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2191                            operands[3]));
2192   else
2193     {
2194       /* Zero-extend the low part.  */
2195       mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2196       mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2198       /* Shift the high part into place.  */
2199       mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2201       /* OR the two halves together.  */
2202       mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2203     }
2204   DONE;
2207 (define_insn "<u>mulsidi3_64bit_hilo"
2208   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2209         (unspec:TI
2210           [(mult:DI
2211              (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2212              (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2213           UNSPEC_SET_HILO))]
2214   "TARGET_64BIT && !TARGET_FIX_R4000"
2215   "mult<u>\t%1,%2"
2216   [(set_attr "type" "imul")
2217    (set_attr "mode" "SI")])
2219 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2220 (define_insn "mulsidi3_64bit_dmul"
2221   [(set (match_operand:DI 0 "register_operand" "=d")
2222         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2223                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2224    (clobber (match_scratch:DI 3 "=l"))]
2225   "ISA_HAS_DMUL3"
2226   "dmul\t%0,%1,%2"
2227   [(set_attr "type" "imul3")
2228    (set_attr "mode" "DI")])
2230 (define_insn "mulsidi3_64bit_r6dmul"
2231   [(set (match_operand:DI 0 "register_operand" "=d")
2232         (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2233                  (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2234   "ISA_HAS_R6DMUL"
2235   "dmul\t%0,%1,%2"
2236   [(set_attr "type" "imul3nc")
2237    (set_attr "mode" "DI")])
2239 ;; Widening multiply with negation.
2240 (define_insn "*muls<u>_di"
2241   [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2242         (neg:DI
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_MULS"
2247   "muls<u>\t$0,%1,%2"
2248   [(set_attr "type" "imul")
2249    (set_attr "mode" "SI")])
2251 ;; As well as being named patterns, these instructions are used by the
2252 ;; __builtin_mips_msub<u>() functions.  We must always make those functions
2253 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2255 ;; This leads to a slight inconsistency.  We honor any tuning overrides
2256 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2257 ;; even if !ISA_HAS_DSP_MULT.
2258 (define_insn "<u>msubsidi4"
2259   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2260         (minus:DI
2261            (match_operand:DI 3 "muldiv_target_operand" "0")
2262            (mult:DI
2263               (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2264               (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2265   "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2267   if (ISA_HAS_DSP_MULT)
2268     return "msub<u>\t%q0,%1,%2";
2269   else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2270     return "msub<u>\t%1,%2";
2271   else
2272     return "msac<u>\t$0,%1,%2";
2274   [(set_attr "type" "imadd")
2275    (set_attr "accum_in" "3")
2276    (set_attr "mode" "SI")])
2278 ;; _highpart patterns
2280 (define_expand "<su>mulsi3_highpart"
2281   [(set (match_operand:SI 0 "register_operand")
2282         (truncate:SI
2283          (lshiftrt:DI
2284           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2285                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2286           (const_int 32))))]
2287   ""
2289   if (ISA_HAS_MULHI)
2290     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2291                                                        operands[1],
2292                                                        operands[2]));
2293   else if (TARGET_MIPS16)
2294     emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2295                                               operands[2]));
2296   else if (ISA_HAS_R6MUL)
2297     emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2298                                            operands[2]));
2299   else
2300     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2301                                                  operands[2]));
2302   DONE;
2305 (define_insn "<su>mulsi3_highpart_r6"
2306   [(set (match_operand:SI 0 "register_operand" "=d")
2307         (truncate:SI
2308          (lshiftrt:DI
2309           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2310                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2311           (const_int 32))))]
2312   "ISA_HAS_R6MUL"
2313   "muh<u>\t%0,%1,%2"
2314   [(set_attr "type" "imul3nc")
2315    (set_attr "mode" "SI")])
2317 (define_insn_and_split "<su>mulsi3_highpart_internal"
2318   [(set (match_operand:SI 0 "register_operand" "=d")
2319         (truncate:SI
2320          (lshiftrt:DI
2321           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2322                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2323           (const_int 32))))
2324    (clobber (match_scratch:SI 3 "=l"))]
2325   "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2326   { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2327   "&& reload_completed && !TARGET_FIX_R4000"
2328   [(const_int 0)]
2330   emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2331                                             operands[2]));
2332   DONE;
2334   [(set_attr "type" "imul")
2335    (set_attr "mode" "SI")
2336    (set_attr "insn_count" "2")])
2338 (define_expand "<su>mulsi3_highpart_split"
2339   [(set (match_operand:SI 0 "register_operand")
2340         (truncate:SI
2341          (lshiftrt:DI
2342           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2343                    (any_extend:DI (match_operand:SI 2 "register_operand")))
2344           (const_int 32))))]
2345   ""
2347   rtx hilo;
2349   if (TARGET_64BIT)
2350     {
2351       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2352       emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2353       emit_insn (gen_mfhisi_ti (operands[0], hilo));
2354     }
2355   else
2356     {
2357       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2358       emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2359       emit_insn (gen_mfhisi_di (operands[0], hilo));
2360     }
2361   DONE;
2364 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2365   [(set (match_operand:SI 0 "register_operand" "=d")
2366         (truncate:SI
2367          (lshiftrt:DI
2368           (mult:DI
2369            (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2370            (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2371           (const_int 32))))
2372    (clobber (match_scratch:SI 3 "=l"))]
2373   "ISA_HAS_MULHI"
2374   "mulhi<u>\t%0,%1,%2"
2375   [(set_attr "type" "imul3")
2376    (set_attr "mode" "SI")])
2378 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2379   [(set (match_operand:SI 0 "register_operand" "=d")
2380         (truncate:SI
2381          (lshiftrt:DI
2382           (neg:DI
2383            (mult:DI
2384             (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2385             (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2386           (const_int 32))))
2387    (clobber (match_scratch:SI 3 "=l"))]
2388   "ISA_HAS_MULHI"
2389   "mulshi<u>\t%0,%1,%2"
2390   [(set_attr "type" "imul3")
2391    (set_attr "mode" "SI")])
2393 ;; Disable unsigned multiplication for -mfix-vr4120.  This is for VR4120
2394 ;; errata MD(0), which says that dmultu does not always produce the
2395 ;; correct result.
2396 (define_expand "<su>muldi3_highpart"
2397   [(set (match_operand:DI 0 "register_operand")
2398         (truncate:DI
2399          (lshiftrt:TI
2400           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2401                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2402           (const_int 64))))]
2403   "ISA_HAS_R6DMUL
2404    || (ISA_HAS_DMULT
2405        && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2407   if (TARGET_MIPS16)
2408     emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2409                                               operands[2]));
2410   else if (ISA_HAS_R6DMUL)
2411     emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2412                                            operands[2]));
2413   else
2414     emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2415                                                  operands[2]));
2416   DONE;
2419 (define_insn "<su>muldi3_highpart_r6"
2420   [(set (match_operand:DI 0 "register_operand" "=d")
2421         (truncate:DI
2422          (lshiftrt:TI
2423           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2424                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2425           (const_int 64))))]
2426   "ISA_HAS_R6DMUL"
2427   "dmuh<u>\t%0,%1,%2"
2428   [(set_attr "type" "imul3nc")
2429    (set_attr "mode" "DI")])
2431 (define_insn_and_split "<su>muldi3_highpart_internal"
2432   [(set (match_operand:DI 0 "register_operand" "=d")
2433         (truncate:DI
2434          (lshiftrt:TI
2435           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2436                    (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2437           (const_int 64))))
2438    (clobber (match_scratch:DI 3 "=l"))]
2439   "ISA_HAS_DMULT
2440    && !TARGET_MIPS16
2441    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2442   { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2443   "&& reload_completed && !TARGET_FIX_R4000"
2444   [(const_int 0)]
2446   emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2447                                             operands[2]));
2448   DONE;
2450   [(set_attr "type" "imul")
2451    (set_attr "mode" "DI")
2452    (set_attr "insn_count" "2")])
2454 (define_expand "<su>muldi3_highpart_split"
2455   [(set (match_operand:DI 0 "register_operand")
2456         (truncate:DI
2457          (lshiftrt:TI
2458           (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2459                    (any_extend:TI (match_operand:DI 2 "register_operand")))
2460           (const_int 64))))]
2461   ""
2463   rtx hilo;
2465   hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2466   emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2467   emit_insn (gen_mfhidi_ti (operands[0], hilo));
2468   DONE;
2471 (define_expand "<u>mulditi3"
2472   [(set (match_operand:TI 0 "register_operand")
2473         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2474                  (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2475   "ISA_HAS_R6DMUL
2476    || (ISA_HAS_DMULT
2477        && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2479   rtx hilo, hi, lo;
2481   if (TARGET_MIPS16)
2482     {
2483       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2484       emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2485       emit_move_insn (operands[0], hilo);
2486     }
2487   else if (TARGET_FIX_R4000)
2488     emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2489   else if (ISA_HAS_DMULT)
2490     emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2491                                          operands[2]));
2492   else
2493     {
2494       hi = mips_subword (operands[0], 1);
2495       lo = mips_subword (operands[0], 0);
2496       emit_insn (gen_muldi3_mul3_nohilo (lo, operands[1], operands[2]));
2497       emit_insn (gen_<su>muldi3_highpart_r6 (hi, operands[1], operands[2]));
2498     }
2499   DONE;
2502 (define_insn "<u>mulditi3_internal"
2503   [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2504         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2505                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2506   "ISA_HAS_DMULT
2507    && !TARGET_FIX_R4000
2508    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2509   "dmult<u>\t%1,%2"
2510   [(set_attr "type" "imul")
2511    (set_attr "mode" "DI")])
2513 (define_insn "<u>mulditi3_r4000"
2514   [(set (match_operand:TI 0 "register_operand" "=d")
2515         (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2516                  (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2517    (clobber (match_scratch:TI 3 "=x"))]
2518   "ISA_HAS_DMULT
2519    && TARGET_FIX_R4000
2520    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2521   "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2522   [(set_attr "type" "imul")
2523    (set_attr "mode" "DI")
2524    (set_attr "insn_count" "3")])
2526 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2527 ;; instruction.  The HI/LO registers are used as a 64-bit accumulator.
2529 (define_insn "madsi"
2530   [(set (match_operand:SI 0 "register_operand" "+l")
2531         (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2532                           (match_operand:SI 2 "register_operand" "d"))
2533                  (match_dup 0)))]
2534   "TARGET_MAD"
2535   "mad\t%1,%2"
2536   [(set_attr "type"     "imadd")
2537    (set_attr "accum_in" "0")
2538    (set_attr "mode"     "SI")])
2540 ;; See the comment above <u>msubsidi4 for the relationship between
2541 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2542 (define_insn "<u>maddsidi4"
2543   [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2544         (plus:DI
2545          (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2546                   (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2547          (match_operand:DI 3 "muldiv_target_operand" "0")))]
2548   "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2549    && !TARGET_64BIT"
2551   if (TARGET_MAD)
2552     return "mad<u>\t%1,%2";
2553   else if (ISA_HAS_DSP_MULT)
2554     return "madd<u>\t%q0,%1,%2";
2555   else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2556     return "madd<u>\t%1,%2";
2557   else
2558     /* See comment in *macc.  */
2559     return "%[macc<u>\t%@,%1,%2%]";
2561   [(set_attr "type" "imadd")
2562    (set_attr "accum_in" "3")
2563    (set_attr "mode" "SI")])
2565 ;; Floating point multiply accumulate instructions.
2567 (define_expand "fma<mode>4"
2568   [(set (match_operand:ANYF 0 "register_operand")
2569         (fma:ANYF (match_operand:ANYF 1 "register_operand")
2570                   (match_operand:ANYF 2 "register_operand")
2571                   (match_operand:ANYF 3 "register_operand")))]
2572   "ISA_HAS_FUSED_MADDF || ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4")
2574 (define_insn "*fma<mode>4_madd3"
2575   [(set (match_operand:ANYF 0 "register_operand" "=f")
2576         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2577                   (match_operand:ANYF 2 "register_operand" "f")
2578                   (match_operand:ANYF 3 "register_operand" "0")))]
2579   "ISA_HAS_FUSED_MADD3"
2580   "madd.<fmt>\t%0,%1,%2"
2581   [(set_attr "type" "fmadd")
2582    (set_attr "mode" "<UNITMODE>")])
2584 (define_insn "*fma<mode>4_madd4"
2585   [(set (match_operand:ANYF 0 "register_operand" "=f")
2586         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2587                   (match_operand:ANYF 2 "register_operand" "f")
2588                   (match_operand:ANYF 3 "register_operand" "f")))]
2589   "ISA_HAS_FUSED_MADD4"
2590   "madd.<fmt>\t%0,%3,%1,%2"
2591   [(set_attr "type" "fmadd")
2592    (set_attr "mode" "<UNITMODE>")])
2594 (define_insn "*fma<mode>4_maddf"
2595   [(set (match_operand:ANYF 0 "register_operand" "=f")
2596         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2597                   (match_operand:ANYF 2 "register_operand" "f")
2598                   (match_operand:ANYF 3 "register_operand" "0")))]
2599   "ISA_HAS_FUSED_MADDF"
2600   "maddf.<fmt>\t%0,%1,%2"
2601   [(set_attr "type" "fmadd")
2602    (set_attr "mode" "<UNITMODE>")])
2604 ;; The fms, fnma, and fnms instructions can be used even when HONOR_NANS
2605 ;; is true because while IEEE 754-2008 requires the negate operation to
2606 ;; negate the sign of a NAN and the MIPS neg instruction does not do this,
2607 ;; the fma part of the instruction has no requirement on how the sign of
2608 ;; a NAN is handled and so the final sign bit of the entire operation is
2609 ;; undefined.
2611 (define_expand "fms<mode>4"
2612   [(set (match_operand:ANYF 0 "register_operand")
2613         (fma:ANYF (match_operand:ANYF 1 "register_operand")
2614                   (match_operand:ANYF 2 "register_operand")
2615                   (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2616   "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)")
2618 (define_insn "*fms<mode>4_msub3"
2619   [(set (match_operand:ANYF 0 "register_operand" "=f")
2620         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2621                   (match_operand:ANYF 2 "register_operand" "f")
2622                   (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2623   "ISA_HAS_FUSED_MADD3"
2624   "msub.<fmt>\t%0,%1,%2"
2625   [(set_attr "type" "fmadd")
2626    (set_attr "mode" "<UNITMODE>")])
2628 (define_insn "*fms<mode>4_msub4"
2629   [(set (match_operand:ANYF 0 "register_operand" "=f")
2630         (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2631                   (match_operand:ANYF 2 "register_operand" "f")
2632                   (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2633   "ISA_HAS_FUSED_MADD4"
2634   "msub.<fmt>\t%0,%3,%1,%2"
2635   [(set_attr "type" "fmadd")
2636    (set_attr "mode" "<UNITMODE>")])
2638 ;; fnma is defined in GCC as (fma (neg op1) op2 op3)
2639 ;; (-op1 * op2) + op3 ==> -(op1 * op2) + op3 ==> -((op1 * op2) - op3)
2640 ;; The mips nmsub instructions implement -((op1 * op2) - op3)
2641 ;; This transformation means we may return the wrong signed zero
2642 ;; so we check HONOR_SIGNED_ZEROS.
2644 (define_expand "fnma<mode>4"
2645   [(set (match_operand:ANYF 0 "register_operand")
2646         (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2647                   (match_operand:ANYF 2 "register_operand")
2648                   (match_operand:ANYF 3 "register_operand")))]
2649   "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2650    && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2652 (define_insn "*fnma<mode>4_nmsub3"
2653   [(set (match_operand:ANYF 0 "register_operand" "=f")
2654         (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2655                   (match_operand:ANYF 2 "register_operand" "f")
2656                   (match_operand:ANYF 3 "register_operand" "0")))]
2657   "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2658   "nmsub.<fmt>\t%0,%1,%2"
2659   [(set_attr "type" "fmadd")
2660    (set_attr "mode" "<UNITMODE>")])
2662 (define_insn "*fnma<mode>4_nmsub4"
2663   [(set (match_operand:ANYF 0 "register_operand" "=f")
2664         (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2665                   (match_operand:ANYF 2 "register_operand" "f")
2666                   (match_operand:ANYF 3 "register_operand" "f")))]
2667   "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2668   "nmsub.<fmt>\t%0,%3,%1,%2"
2669   [(set_attr "type" "fmadd")
2670    (set_attr "mode" "<UNITMODE>")])
2672 ;; fnms is defined as: (fma (neg op1) op2 (neg op3))
2673 ;; ((-op1) * op2) - op3 ==> -(op1 * op2) - op3 ==> -((op1 * op2) + op3)
2674 ;; The mips nmadd instructions implement -((op1 * op2) + op3)
2675 ;; This transformation means we may return the wrong signed zero
2676 ;; so we check HONOR_SIGNED_ZEROS.
2678 (define_expand "fnms<mode>4"
2679   [(set (match_operand:ANYF 0 "register_operand")
2680         (fma:ANYF
2681           (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2682           (match_operand:ANYF 2 "register_operand")
2683           (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2684   "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2685    && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2687 (define_insn "*fnms<mode>4_nmadd3"
2688   [(set (match_operand:ANYF 0 "register_operand" "=f")
2689         (fma:ANYF
2690           (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2691           (match_operand:ANYF 2 "register_operand" "f")
2692           (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2693   "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2694   "nmadd.<fmt>\t%0,%1,%2"
2695   [(set_attr "type" "fmadd")
2696    (set_attr "mode" "<UNITMODE>")])
2698 (define_insn "*fnms<mode>4_nmadd4"
2699   [(set (match_operand:ANYF 0 "register_operand" "=f")
2700         (fma:ANYF
2701           (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2702           (match_operand:ANYF 2 "register_operand" "f")
2703           (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2704   "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2705   "nmadd.<fmt>\t%0,%3,%1,%2"
2706   [(set_attr "type" "fmadd")
2707    (set_attr "mode" "<UNITMODE>")])
2709 ;; Non-fused Floating point multiply accumulate instructions.
2711 ;; These instructions are not fused and round in between the multiply
2712 ;; and the add (or subtract) so they are equivalent to the separate
2713 ;; multiply and add/sub instructions.
2715 (define_insn "*madd4<mode>"
2716   [(set (match_operand:ANYF 0 "register_operand" "=f")
2717         (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2718                               (match_operand:ANYF 2 "register_operand" "f"))
2719                    (match_operand:ANYF 3 "register_operand" "f")))]
2720   "ISA_HAS_UNFUSED_MADD4"
2721   "madd.<fmt>\t%0,%3,%1,%2"
2722   [(set_attr "type" "fmadd")
2723    (set_attr "mode" "<UNITMODE>")])
2725 (define_insn "*msub4<mode>"
2726   [(set (match_operand:ANYF 0 "register_operand" "=f")
2727         (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2728                                (match_operand:ANYF 2 "register_operand" "f"))
2729                     (match_operand:ANYF 3 "register_operand" "f")))]
2730   "ISA_HAS_UNFUSED_MADD4"
2731   "msub.<fmt>\t%0,%3,%1,%2"
2732   [(set_attr "type" "fmadd")
2733    (set_attr "mode" "<UNITMODE>")])
2735 ;; Like with the fused fms, fnma, and fnms instructions, these unfused
2736 ;; instructions can be used even if HONOR_NANS is set because while
2737 ;; IEEE 754-2008 requires the negate operation to negate the sign of a
2738 ;; NAN and the MIPS neg instruction does not do this, the multiply and
2739 ;; add (or subtract) part of the instruction has no requirement on how
2740 ;; the sign of a NAN is handled and so the final sign bit of the entire
2741 ;; operation is undefined.
2743 (define_insn "*nmadd4<mode>"
2744   [(set (match_operand:ANYF 0 "register_operand" "=f")
2745         (neg:ANYF (plus:ANYF
2746                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2747                               (match_operand:ANYF 2 "register_operand" "f"))
2748                    (match_operand:ANYF 3 "register_operand" "f"))))]
2749   "ISA_HAS_UNFUSED_MADD4"
2750   "nmadd.<fmt>\t%0,%3,%1,%2"
2751   [(set_attr "type" "fmadd")
2752    (set_attr "mode" "<UNITMODE>")])
2754 (define_insn "*nmsub4<mode>"
2755   [(set (match_operand:ANYF 0 "register_operand" "=f")
2756         (neg:ANYF (minus:ANYF
2757                    (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2758                               (match_operand:ANYF 2 "register_operand" "f"))
2759                    (match_operand:ANYF 3 "register_operand" "f"))))]
2760   "ISA_HAS_UNFUSED_MADD4"
2761   "nmsub.<fmt>\t%0,%3,%1,%2"
2762   [(set_attr "type" "fmadd")
2763    (set_attr "mode" "<UNITMODE>")])
2765 ;; Fast-math Non-fused Floating point multiply accumulate instructions.
2767 ;; These instructions are not fused but the expressions they match are
2768 ;; not exactly what the instruction implements in the sense that they
2769 ;; may not generate the properly signed zeros.
2771 ;; This instruction recognizes  ((-op1) * op2) - op3 and generates an
2772 ;; nmadd which is really -((op1 * op2) + op3).  They are equivalent
2773 ;; except for the sign bit when the result is zero or NaN.
2775 (define_insn "*nmadd4<mode>_fastmath"
2776   [(set (match_operand:ANYF 0 "register_operand" "=f")
2777         (minus:ANYF
2778           (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2779                      (match_operand:ANYF 2 "register_operand" "f"))
2780           (match_operand:ANYF 3 "register_operand" "f")))]
2781   "ISA_HAS_UNFUSED_MADD4
2782    && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2783   "nmadd.<fmt>\t%0,%3,%1,%2"
2784   [(set_attr "type" "fmadd")
2785    (set_attr "mode" "<UNITMODE>")])
2787 ;; This instruction recognizes (op1 - (op2 * op3) and generates an
2788 ;; nmsub which is really -((op2 * op3) - op1).  They are equivalent
2789 ;; except for the sign bit when the result is zero or NaN.
2791 (define_insn "*nmsub4<mode>_fastmath"
2792   [(set (match_operand:ANYF 0 "register_operand" "=f")
2793         (minus:ANYF
2794           (match_operand:ANYF 1 "register_operand" "f")
2795           (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2796                      (match_operand:ANYF 3 "register_operand" "f"))))]
2797   "ISA_HAS_UNFUSED_MADD4
2798    && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2799   "nmsub.<fmt>\t%0,%1,%2,%3"
2800   [(set_attr "type" "fmadd")
2801    (set_attr "mode" "<UNITMODE>")])
2804 ;;  ....................
2806 ;;      DIVISION and REMAINDER
2808 ;;  ....................
2811 (define_expand "div<mode>3"
2812   [(set (match_operand:ANYF 0 "register_operand")
2813         (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2814                   (match_operand:ANYF 2 "register_operand")))]
2815   "<divide_condition>"
2817   if (const_1_operand (operands[1], <MODE>mode))
2818     if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2819           && flag_unsafe_math_optimizations))
2820       operands[1] = force_reg (<MODE>mode, operands[1]);
2823 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2825 ;; If an mfc1 or dmfc1 happens to access the floating point register
2826 ;; file at the same time a long latency operation (div, sqrt, recip,
2827 ;; sqrt) iterates an intermediate result back through the floating
2828 ;; point register file bypass, then instead returning the correct
2829 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2830 ;; result of the long latency operation.
2832 ;; The workaround is to insert an unconditional 'mov' from/to the
2833 ;; long latency op destination register.
2835 (define_insn "*div<mode>3"
2836   [(set (match_operand:ANYF 0 "register_operand" "=f")
2837         (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2838                   (match_operand:ANYF 2 "register_operand" "f")))]
2839   "<divide_condition>"
2841   if (TARGET_FIX_SB1)
2842     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2843   else
2844     return "div.<fmt>\t%0,%1,%2";
2846   [(set_attr "type" "fdiv")
2847    (set_attr "mode" "<UNITMODE>")
2848    (set (attr "insn_count")
2849         (if_then_else (match_test "TARGET_FIX_SB1")
2850                       (const_int 2)
2851                       (const_int 1)))])
2853 (define_insn "*recip<mode>3"
2854   [(set (match_operand:ANYF 0 "register_operand" "=f")
2855         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2856                   (match_operand:ANYF 2 "register_operand" "f")))]
2857   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2859   if (TARGET_FIX_SB1)
2860     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2861   else
2862     return "recip.<fmt>\t%0,%2";
2864   [(set_attr "type" "frdiv")
2865    (set_attr "mode" "<UNITMODE>")
2866    (set (attr "insn_count")
2867         (if_then_else (match_test "TARGET_FIX_SB1")
2868                       (const_int 2)
2869                       (const_int 1)))])
2871 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2872 ;; with negative operands.  We use special libgcc functions instead.
2873 (define_expand "divmod<mode>4"
2874   [(parallel
2875      [(set (match_operand:GPR 0 "register_operand")
2876            (div:GPR (match_operand:GPR 1 "register_operand")
2877                     (match_operand:GPR 2 "register_operand")))
2878       (set (match_operand:GPR 3 "register_operand")
2879            (mod:GPR (match_dup 1)
2880                     (match_dup 2)))])]
2881   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2883   if (TARGET_MIPS16)
2884     {
2885       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2886       emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2887                                            operands[2], operands[3], lo));
2888       DONE;
2889     }
2892 (define_insn_and_split "*divmod<mode>4"
2893   [(set (match_operand:GPR 0 "register_operand" "=l")
2894         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2895                  (match_operand:GPR 2 "register_operand" "d")))
2896    (set (match_operand:GPR 3 "register_operand" "=d")
2897         (mod:GPR (match_dup 1)
2898                  (match_dup 2)))]
2899   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2900   "#"
2901   "&& reload_completed"
2902   [(const_int 0)]
2904   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2905   DONE;
2907  [(set_attr "type" "idiv")
2908   (set_attr "mode" "<MODE>")
2909   (set_attr "insn_count" "2")])
2911 ;; Expand generates divmod instructions for individual division and modulus
2912 ;; operations.  We then rely on CSE to reuse earlier divmods where possible.
2913 ;; This means that, when generating MIPS16 code, it is better not to expose
2914 ;; the fixed LO register until after CSE has finished.  However, it's still
2915 ;; better to split before register allocation, so that we don't allocate
2916 ;; one of the scarce MIPS16 registers to an unused result.
2917 (define_insn_and_split "divmod<mode>4_mips16"
2918   [(set (match_operand:GPR 0 "register_operand" "=d")
2919         (div:GPR (match_operand:GPR 1 "register_operand" "d")
2920                  (match_operand:GPR 2 "register_operand" "d")))
2921    (set (match_operand:GPR 3 "register_operand" "=d")
2922         (mod:GPR (match_dup 1)
2923                  (match_dup 2)))
2924    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2925   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2926   "#"
2927   "&& cse_not_expected"
2928   [(const_int 0)]
2930   emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2931   emit_move_insn (operands[0], operands[4]);
2932   DONE;
2934  [(set_attr "type" "idiv")
2935   (set_attr "mode" "<MODE>")
2936   (set_attr "insn_count" "3")])
2938 (define_expand "udivmod<mode>4"
2939   [(parallel
2940      [(set (match_operand:GPR 0 "register_operand")
2941            (udiv:GPR (match_operand:GPR 1 "register_operand")
2942                      (match_operand:GPR 2 "register_operand")))
2943       (set (match_operand:GPR 3 "register_operand")
2944            (umod:GPR (match_dup 1)
2945                      (match_dup 2)))])]
2946   "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2948   if (TARGET_MIPS16)
2949     {
2950       rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2951       emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2952                                             operands[2], operands[3], lo));
2953       DONE;
2954     }
2957 (define_insn_and_split "*udivmod<mode>4"
2958   [(set (match_operand:GPR 0 "register_operand" "=l")
2959         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2960                   (match_operand:GPR 2 "register_operand" "d")))
2961    (set (match_operand:GPR 3 "register_operand" "=d")
2962         (umod:GPR (match_dup 1)
2963                   (match_dup 2)))]
2964   "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2965   "#"
2966   "reload_completed"
2967   [(const_int 0)]
2969   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2970   DONE;
2972   [(set_attr "type" "idiv")
2973    (set_attr "mode" "<MODE>")
2974    (set_attr "insn_count" "2")])
2976 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2977 (define_insn_and_split "udivmod<mode>4_mips16"
2978   [(set (match_operand:GPR 0 "register_operand" "=d")
2979         (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2980                   (match_operand:GPR 2 "register_operand" "d")))
2981    (set (match_operand:GPR 3 "register_operand" "=d")
2982         (umod:GPR (match_dup 1)
2983                   (match_dup 2)))
2984    (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2985   "ISA_HAS_<D>DIV && TARGET_MIPS16"
2986   "#"
2987   "cse_not_expected"
2988   [(const_int 0)]
2990   emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2991   emit_move_insn (operands[0], operands[4]);
2992   DONE;
2994   [(set_attr "type" "idiv")
2995    (set_attr "mode" "<MODE>")
2996    (set_attr "insn_count" "3")])
2998 (define_expand "<u>divmod<mode>4_split"
2999   [(set (match_operand:GPR 0 "register_operand")
3000         (any_mod:GPR (match_operand:GPR 1 "register_operand")
3001                      (match_operand:GPR 2 "register_operand")))]
3002   ""
3004   rtx hilo;
3006   if (TARGET_64BIT)
3007     {
3008       hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
3009       emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
3010                                                operands[2]));
3011       emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
3012     }
3013   else
3014     {
3015       hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
3016       emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
3017                                                operands[2]));
3018       emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
3019     }
3020   DONE;
3023 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
3024   [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
3025         (unspec:HILO
3026           [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3027                         (match_operand:GPR 2 "register_operand" "d"))]
3028           UNSPEC_SET_HILO))]
3029   "ISA_HAS_<GPR:D>DIV"
3030   { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
3031   [(set_attr "type" "idiv")
3032    (set_attr "mode" "<GPR:MODE>")])
3034 ;; Integer division and modulus.
3036 (define_insn "<u>div<mode>3"
3037   [(set (match_operand:GPR 0 "register_operand" "=&d")
3038         (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3039                      (match_operand:GPR 2 "register_operand" "d")))]
3040   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>DIV"
3041   {
3042     if (TARGET_LOONGSON_2EF)
3043       return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
3044     else if (TARGET_LOONGSON_EXT)
3045       return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
3046     else
3047       return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
3048   }
3049   [(set_attr "type" "idiv3")
3050    (set_attr "mode" "<MODE>")])
3052 (define_insn "<u>mod<mode>3"
3053   [(set (match_operand:GPR 0 "register_operand" "=&d")
3054         (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
3055                      (match_operand:GPR 2 "register_operand" "d")))]
3056   "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>DIV"
3057   {
3058     if (TARGET_LOONGSON_2EF)
3059       return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
3060     else if (TARGET_LOONGSON_EXT)
3061       return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
3062     else
3063       return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
3064   }
3065   [(set_attr "type" "idiv3")
3066    (set_attr "mode" "<MODE>")])
3069 ;;  ....................
3071 ;;      SQUARE ROOT
3073 ;;  ....................
3075 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
3076 ;; "*div[sd]f3" comment for details).
3078 (define_insn "sqrt<mode>2"
3079   [(set (match_operand:ANYF 0 "register_operand" "=f")
3080         (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3081   "<sqrt_condition>"
3083   if (TARGET_FIX_SB1)
3084     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
3085   else
3086     return "sqrt.<fmt>\t%0,%1";
3088   [(set_attr "type" "fsqrt")
3089    (set_attr "mode" "<UNITMODE>")
3090    (set (attr "insn_count")
3091         (if_then_else (match_test "TARGET_FIX_SB1")
3092                       (const_int 2)
3093                       (const_int 1)))])
3095 (define_insn "*rsqrt<mode>a"
3096   [(set (match_operand:ANYF 0 "register_operand" "=f")
3097         (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3098                   (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
3099   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3101   if (TARGET_FIX_SB1)
3102     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3103   else
3104     return "rsqrt.<fmt>\t%0,%2";
3106   [(set_attr "type" "frsqrt")
3107    (set_attr "mode" "<UNITMODE>")
3108    (set (attr "insn_count")
3109         (if_then_else (match_test "TARGET_FIX_SB1")
3110                       (const_int 2)
3111                       (const_int 1)))])
3113 (define_insn "*rsqrt<mode>b"
3114   [(set (match_operand:ANYF 0 "register_operand" "=f")
3115         (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3116                              (match_operand:ANYF 2 "register_operand" "f"))))]
3117   "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3119   if (TARGET_FIX_SB1)
3120     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3121   else
3122     return "rsqrt.<fmt>\t%0,%2";
3124   [(set_attr "type" "frsqrt")
3125    (set_attr "mode" "<UNITMODE>")
3126    (set (attr "insn_count")
3127         (if_then_else (match_test "TARGET_FIX_SB1")
3128                       (const_int 2)
3129                       (const_int 1)))])
3132 ;;  ....................
3134 ;;      ABSOLUTE VALUE
3136 ;;  ....................
3138 ;; Do not use the integer abs macro instruction, since that signals an
3139 ;; exception on -2147483648 (sigh).
3141 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
3142 ;; instruction that treats all NaN inputs as invalid; it does not clear
3143 ;; their sign bit.  We therefore can't use that form if the signs of
3144 ;; NaNs matter.
3146 (define_insn "abs<mode>2"
3147   [(set (match_operand:ANYF 0 "register_operand" "=f")
3148         (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3149   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3150   "abs.<fmt>\t%0,%1"
3151   [(set_attr "type" "fabs")
3152    (set_attr "mode" "<UNITMODE>")])
3155 ;;  ...................
3157 ;;  Count leading zeroes.
3159 ;;  ...................
3162 (define_insn "clz<mode>2"
3163   [(set (match_operand:GPR 0 "register_operand" "=d")
3164         (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3165   "ISA_HAS_CLZ_CLO"
3166   "<d>clz\t%0,%1"
3167   [(set_attr "type" "clz")
3168    (set_attr "mode" "<MODE>")])
3171 (define_insn "*clo<mode>2"
3172   [(set (match_operand:GPR 0 "register_operand" "=d")
3173         (clz:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))))]
3174   "ISA_HAS_CLZ_CLO"
3175   "<d>clo\t%0,%1"
3176   [(set_attr "type" "clz")
3177    (set_attr "mode" "<MODE>")])
3180 ;;  ...................
3182 ;;  Count trailing zeroes.
3184 ;;  ...................
3187 (define_insn "ctz<mode>2"
3188   [(set (match_operand:GPR 0 "register_operand" "=d")
3189         (ctz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3190   "ISA_HAS_CTZ_CTO"
3191   "<d>ctz\t%0,%1"
3192   [(set_attr "type" "clz")
3193    (set_attr "mode" "<MODE>")])
3197 ;;  ...................
3199 ;;  Count number of set bits.
3201 ;;  ...................
3204 (define_insn "popcount<mode>2"
3205   [(set (match_operand:GPR 0 "register_operand" "=d")
3206         (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3207   "ISA_HAS_POP"
3208   "<d>pop\t%0,%1"
3209   [(set_attr "type" "pop")
3210    (set_attr "mode" "<MODE>")])
3212 ;; The POP instruction is special as it does not take into account the upper
3213 ;; 32bits and is documented that way.
3214 (define_insn "*popcountdi2_trunc"
3215   [(set (match_operand:SI 0 "register_operand" "=d")
3216        (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3217   "ISA_HAS_POP && TARGET_64BIT"
3218   "pop\t%0,%1"
3219   [(set_attr "type" "pop")
3220    (set_attr "mode" "SI")])
3223 ;;  ....................
3225 ;;      NEGATION and ONE'S COMPLEMENT
3227 ;;  ....................
3229 (define_insn "negsi2"
3230   [(set (match_operand:SI 0 "register_operand" "=d")
3231         (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3232   ""
3234   if (TARGET_MIPS16)
3235     return "neg\t%0,%1";
3236   else
3237     return "subu\t%0,%.,%1";
3239   [(set_attr "alu_type" "sub")
3240    (set_attr "mode"     "SI")])
3242 (define_insn "negdi2"
3243   [(set (match_operand:DI 0 "register_operand" "=d")
3244         (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3245   "TARGET_64BIT && !TARGET_MIPS16"
3246   "dsubu\t%0,%.,%1"
3247   [(set_attr "alu_type" "sub")
3248    (set_attr "mode"     "DI")])
3250 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3251 ;; instruction that treats all NaN inputs as invalid; it does not flip
3252 ;; their sign bit.  We therefore can't use that form if the signs of
3253 ;; NaNs matter.
3255 (define_insn "neg<mode>2"
3256   [(set (match_operand:ANYF 0 "register_operand" "=f")
3257         (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3258   "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3259   "neg.<fmt>\t%0,%1"
3260   [(set_attr "type" "fneg")
3261    (set_attr "mode" "<UNITMODE>")])
3263 (define_insn "one_cmpl<mode>2"
3264   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3265         (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3266   ""
3268   if (TARGET_MIPS16)
3269     return "not\t%0,%1";
3270   else
3271     return "nor\t%0,%.,%1";
3273   [(set_attr "alu_type" "not")
3274    (set_attr "compression" "micromips,*")
3275    (set_attr "mode" "<MODE>")])
3278 ;;  ....................
3280 ;;      LOGICAL
3282 ;;  ....................
3285 ;; Many of these instructions use trivial define_expands, because we
3286 ;; want to use a different set of constraints when TARGET_MIPS16.
3288 (define_expand "and<mode>3"
3289   [(set (match_operand:GPR 0 "register_operand")
3290         (and:GPR (match_operand:GPR 1 "register_operand")
3291                  (match_operand:GPR 2 "and_reg_operand")))])
3293 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3294 ;; zero_extendsidi2 because of TARGET_TRULY_NOOP_TRUNCATION, so handle these
3295 ;; here.  Note that this variant does not trigger for SI mode because we
3296 ;; require a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3297 ;; sign-extended SImode value.
3299 ;; These are possible combinations for operand 1 and 2.  The table
3300 ;; includes both MIPS and MIPS16 cases.  (r=register, mem=memory,
3301 ;; 16=MIPS16, x=match, S=split):
3303 ;;     \ op1    r/EXT   r/!EXT  mem   r/16   mem/16
3304 ;;  op2
3306 ;;  andi           x     x
3307 ;;  0xff           x     x       x             x
3308 ;;  0xffff         x     x       x             x
3309 ;;  0xffff_ffff    x     S       x     S       x
3310 ;;  low-bitmask    x
3311 ;;  register       x     x
3312 ;;  register =op1                      x
3314 (define_insn "*and<mode>3"
3315   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d,d")
3316         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d,0")
3317                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d,Yz")))]
3318   "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3320   int len;
3321   int pos;
3323   switch (which_alternative)
3324     {
3325     case 0:
3326       operands[1] = gen_lowpart (QImode, operands[1]);
3327       return "lbu\t%0,%1";
3328     case 1:
3329       operands[1] = gen_lowpart (HImode, operands[1]);
3330       return "lhu\t%0,%1";
3331     case 2:
3332       operands[1] = gen_lowpart (SImode, operands[1]);
3333       return "lwu\t%0,%1";
3334     case 3:
3335     case 4:
3336       return "andi\t%0,%1,%x2";
3337     case 5:
3338       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3339       operands[2] = GEN_INT (len);
3340       return "<d>ext\t%0,%1,0,%2";
3341     case 6:
3342       return "#";
3343     case 7:
3344     case 8:
3345       return "and\t%0,%1,%2";
3346     case 9:
3347       mips_bit_clear_info (<MODE>mode, INTVAL (operands[2]), &pos, &len);
3348       operands[1] = GEN_INT (pos);
3349       operands[2] = GEN_INT (len);
3350       return "<d>ins\t%0,$0,%1,%2";
3351     default:
3352       gcc_unreachable ();
3353     }
3355   [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical,ext_ins")
3356    (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*,*")
3357    (set_attr "mode" "<MODE>")])
3359 (define_insn "*and<mode>3_mips16"
3360   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d,d,d,d,d,d")
3361         (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%0,0,W,W,W,d,0,d,0,0?")
3362                  (match_operand:GPR 2 "and_operand" "Yb,Yh,Yb,Yh,Yw,Yw,d,Yx,Yz,K")))]
3363   "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3365   int len;
3366   int pos;
3368   switch (which_alternative)
3369     {
3370     case 0:
3371       return "zeb\t%0";
3372     case 1:
3373       return "zeh\t%0";
3374     case 2:
3375       operands[1] = gen_lowpart (QImode, operands[1]);
3376       return "lbu\t%0,%1";
3377     case 3:
3378       operands[1] = gen_lowpart (HImode, operands[1]);
3379       return "lhu\t%0,%1";
3380     case 4:
3381       operands[1] = gen_lowpart (SImode, operands[1]);
3382       return "lwu\t%0,%1";
3383     case 5:
3384       return "#";
3385     case 6:
3386       return "and\t%0,%2";
3387     case 7:
3388       len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3389       operands[2] = GEN_INT (len);
3390       return "ext\t%0,%1,0,%2";
3391     case 8:
3392       mips_bit_clear_info (<MODE>mode, INTVAL (operands[2]), &pos, &len);
3393       operands[1] = GEN_INT (pos);
3394       operands[2] = GEN_INT (len);
3395       return "ins\t%0,$0,%1,%2";
3396     case 9:
3397       return "andi\t%0,%x2";
3398     default:
3399       gcc_unreachable ();
3400     }
3402   [(set_attr "move_type" "andi,andi,load,load,load,shift_shift,logical,ext_ins,ext_ins,andi")
3403    (set_attr "mode" "<MODE>")
3404    (set_attr "extended_mips16" "no,no,no,no,no,no,no,yes,yes,yes")
3405    (set (attr "enabled")
3406    (cond [(and (eq_attr "alternative" "9")
3407                            (not (match_test "ISA_HAS_MIPS16E2")))
3408                   (const_string "no")
3409                   (and (eq_attr "alternative" "0,1")
3410                            (match_test "!GENERATE_MIPS16E"))
3411                   (const_string "no")]
3412                  (const_string "yes")))])
3414 (define_expand "ior<mode>3"
3415   [(set (match_operand:GPR 0 "register_operand")
3416         (ior:GPR (match_operand:GPR 1 "register_operand")
3417                  (match_operand:GPR 2 "uns_arith_operand")))]
3418   ""
3420   if (TARGET_MIPS16 && !ISA_HAS_MIPS16E2)
3421     operands[2] = force_reg (<MODE>mode, operands[2]);
3424 (define_insn "*ior<mode>3"
3425   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3426         (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3427                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3428   "!TARGET_MIPS16"
3429   "@
3430    or\t%0,%1,%2
3431    or\t%0,%1,%2
3432    ori\t%0,%1,%x2"
3433   [(set_attr "alu_type" "or")
3434    (set_attr "compression" "micromips,*,*")
3435    (set_attr "mode" "<MODE>")])
3437 (define_insn "*iorsi3_mips16_asmacro"
3438   [(set (match_operand:SI 0 "register_operand" "=d,d")
3439         (ior:SI (match_operand:SI 1 "register_operand" "%0,0")
3440                 (match_operand:SI 2 "uns_arith_operand" "d,K")))]
3441   "ISA_HAS_MIPS16E2"
3442   "@
3443    or\t%0,%2
3444    ori\t%0,%x2"
3445    [(set_attr "alu_type" "or")
3446     (set_attr "mode" "SI")
3447     (set_attr "extended_mips16" "*,yes")])
3449 (define_insn "*ior<mode>3_mips16"
3450   [(set (match_operand:GPR 0 "register_operand" "=d")
3451         (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3452                  (match_operand:GPR 2 "register_operand" "d")))]
3453   "TARGET_MIPS16 && !ISA_HAS_MIPS16E2"
3454   "or\t%0,%2"
3455   [(set_attr "alu_type" "or")
3456    (set_attr "mode" "<MODE>")])
3458 (define_expand "xor<mode>3"
3459   [(set (match_operand:GPR 0 "register_operand")
3460         (xor:GPR (match_operand:GPR 1 "register_operand")
3461                  (match_operand:GPR 2 "uns_arith_operand")))]
3462   ""
3463   "")
3465 (define_insn "*xor<mode>3"
3466   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3467         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3468                  (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3469   "!TARGET_MIPS16"
3470   "@
3471    xor\t%0,%1,%2
3472    xor\t%0,%1,%2
3473    xori\t%0,%1,%x2"
3474   [(set_attr "alu_type" "xor")
3475    (set_attr "compression" "micromips,*,*")
3476    (set_attr "mode" "<MODE>")])
3478 ;; We increase statically the cost of the output register for XORI
3479 ;; to counterweight LRA cost calculation as XORI tends to be chosen
3480 ;; frequently hurting the code size.  The reason of not choosing CMPI is
3481 ;; that LRA tends to add up the cost of the T register as it is in a small
3482 ;; class and a possible reload.  In reality, the use of T register comes for
3483 ;; free in a number of cases as we don't need any MIPS16 registers.
3484 (define_insn "*xor<mode>3_mips16"
3485   [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t,d?")
3486         (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d,0")
3487                  (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d,K")))]
3488   "TARGET_MIPS16"
3489   "@
3490    xor\t%0,%2
3491    cmpi\t%1,%2
3492    cmpi\t%1,%2
3493    cmp\t%1,%2
3494    xori\t%0,%x2"
3495   [(set_attr "alu_type" "xor")
3496    (set_attr "mode" "<MODE>")
3497    (set_attr "extended_mips16" "no,no,yes,no,yes")
3498    (set (attr "enabled")
3499                 (cond [(and (eq_attr "alternative" "4")
3500                                         (not (match_test "ISA_HAS_MIPS16E2")))
3501                            (const_string "no")]
3502                           (const_string "yes")))])
3504 (define_insn "*nor<mode>3"
3505   [(set (match_operand:GPR 0 "register_operand" "=d")
3506         (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3507                  (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3508   "!TARGET_MIPS16"
3509   "nor\t%0,%1,%2"
3510   [(set_attr "alu_type" "nor")
3511    (set_attr "mode" "<MODE>")])
3514 ;;  ....................
3516 ;;      TRUNCATION
3518 ;;  ....................
3522 (define_insn "truncdfsf2"
3523   [(set (match_operand:SF 0 "register_operand" "=f")
3524         (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3525   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3526   "cvt.s.d\t%0,%1"
3527   [(set_attr "type"     "fcvt")
3528    (set_attr "cnv_mode" "D2S")   
3529    (set_attr "mode"     "SF")])
3531 ;; Integer truncation patterns.  Truncating SImode values to smaller
3532 ;; modes is a no-op, as it is for most other GCC ports.  Truncating
3533 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3534 ;; need to make sure that the lower 32 bits are properly sign-extended
3535 ;; (see TARGET_TRULY_NOOP_TRUNCATION).  Truncating DImode values into modes
3536 ;; smaller than SImode is equivalent to two separate truncations:
3538 ;;                        A       B
3539 ;;    DI ---> HI  ==  DI ---> SI ---> HI
3540 ;;    DI ---> QI  ==  DI ---> SI ---> QI
3542 ;; Step A needs a real instruction but step B does not.
3544 (define_insn "truncdi<mode>2"
3545   [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3546         (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3547   "TARGET_64BIT"
3548   "@
3549     sll\t%0,%1,0
3550     <store>\t%1,%0"
3551   [(set_attr "move_type" "sll0,store")
3552    (set_attr "mode" "SI")])
3554 ;; Combiner patterns to optimize shift/truncate combinations.
3556 (define_insn "*ashr_trunc<mode>"
3557   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3558         (truncate:SUBDI
3559           (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3560                        (match_operand:DI 2 "const_arith_operand" ""))))]
3561   "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3562   "dsra\t%0,%1,%2"
3563   [(set_attr "type" "shift")
3564    (set_attr "mode" "<MODE>")])
3566 (define_insn "*lshr32_trunc<mode>"
3567   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3568         (truncate:SUBDI
3569           (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3570                        (const_int 32))))]
3571   "TARGET_64BIT && !TARGET_MIPS16"
3572   "dsra\t%0,%1,32"
3573   [(set_attr "type" "shift")
3574    (set_attr "mode" "<MODE>")])
3576 ;; Logical shift by more than 32 results in proper SI values so truncation is
3577 ;; removed by the middle end.  Note that a logical shift by 32 is handled by
3578 ;; the previous pattern.
3579 (define_insn "*<optab>_trunc<mode>_exts"
3580   [(set (match_operand:SUBDI 0 "register_operand" "=d")
3581         (truncate:SUBDI
3582          (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3583                          (match_operand:DI 2 "const_arith_operand" ""))))]
3584   "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3585   "exts\t%0,%1,%2,31"
3586   [(set_attr "type" "arith")
3587    (set_attr "mode" "<MODE>")])
3589 ;; This could likely be generalized for any SUBDI mode, and any right
3590 ;; shift, but AFAICT this is used so rarely it is not worth the additional
3591 ;; complexity.
3592 (define_insn ""
3593   [(set (match_operand:SI 0 "register_operand" "=d")
3594         (ashiftrt:SI
3595           (truncate:SI
3596             (ashift:DI (match_operand:DI 1 "register_operand" "d")
3597                        (match_operand:DI 2 "const_arith_operand" "")))
3598           (match_operand:DI 3 "const_arith_operand" "")))]
3599   "(ISA_HAS_EXTS && TARGET_64BIT
3600     && UINTVAL (operands[2]) < 32 && UINTVAL (operands[3]) < 32
3601     && UINTVAL (operands[3]) >= UINTVAL (operands[2]))"
3602   {
3603     rtx xoperands[4];
3604     xoperands[0] = operands[0];
3605     xoperands[1] = operands[1];
3607     /* The length of the field is the size of the outer mode less the outer
3608        shift constant.  We fix the outer mode as SImode for simplicity.  */
3609     unsigned int right_shift = INTVAL (operands[3]);
3610     xoperands[3] = GEN_INT (32 - right_shift);
3612     /* The field starts at the outer shift constant less the inner shift
3613        constant.  */
3614     unsigned int left_shift = INTVAL (operands[2]);
3615     xoperands[2] = GEN_INT (right_shift - left_shift);
3617     /* Sanity checks.  These constraints are taken from the MIPS ISA
3618        manual.  */
3619     gcc_assert (INTVAL (xoperands[2]) >= 0 && INTVAL (xoperands[2]) < 32);
3620     gcc_assert (INTVAL (xoperands[3]) > 0 && INTVAL (xoperands[3]) <= 32);
3621     gcc_assert (INTVAL (xoperands[2]) + INTVAL (xoperands[3]) > 0
3622                 && INTVAL (xoperands[2]) + INTVAL (xoperands[3]) <= 32);
3624     output_asm_insn ("exts\t%0,%1,%2,%m3", xoperands);
3625     return "";
3626   }
3627   [(set_attr "type" "arith")
3628    (set_attr "mode" "SI")])
3631 ;;  ....................
3633 ;;      ZERO EXTENSION
3635 ;;  ....................
3637 ;; Extension insns.
3639 (define_expand "zero_extendsidi2"
3640   [(set (match_operand:DI 0 "register_operand")
3641         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3642   "TARGET_64BIT")
3644 (define_insn_and_split "*zero_extendsidi2"
3645   [(set (match_operand:DI 0 "register_operand" "=d,d")
3646         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3647   "TARGET_64BIT && !ISA_HAS_EXT_INS"
3648   "@
3649    #
3650    lwu\t%0,%1"
3651   "&& reload_completed && REG_P (operands[1])"
3652   [(set (match_dup 0)
3653         (ashift:DI (match_dup 1) (const_int 32)))
3654    (set (match_dup 0)
3655         (lshiftrt:DI (match_dup 0) (const_int 32)))]
3656   { operands[1] = gen_lowpart (DImode, operands[1]); }
3657   [(set_attr "move_type" "shift_shift,load")
3658    (set_attr "mode" "DI")])
3660 (define_insn "*zero_extendsidi2_dext"
3661   [(set (match_operand:DI 0 "register_operand" "=d,d")
3662         (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3663   "TARGET_64BIT && ISA_HAS_EXT_INS"
3664   "@
3665    dext\t%0,%1,0,32
3666    lwu\t%0,%1"
3667   [(set_attr "move_type" "arith,load")
3668    (set_attr "mode" "DI")])
3670 ;; See the comment before the *and<mode>3 pattern why this is generated by
3671 ;; combine.
3673 (define_split
3674   [(set (match_operand:DI 0 "register_operand")
3675         (and:DI (match_operand:DI 1 "register_operand")
3676                 (const_int 4294967295)))]
3677   "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3678   [(set (match_dup 0)
3679         (ashift:DI (match_dup 1) (const_int 32)))
3680    (set (match_dup 0)
3681         (lshiftrt:DI (match_dup 0) (const_int 32)))])
3683 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3684   [(set (match_operand:GPR 0 "register_operand")
3685         (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3686   ""
3688   if (TARGET_MIPS16 && !GENERATE_MIPS16E
3689       && !memory_operand (operands[1], <SHORT:MODE>mode))
3690     {
3691       emit_insn (gen_and<GPR:mode>3 (operands[0],
3692                                      gen_lowpart (<GPR:MODE>mode, operands[1]),
3693                                      force_reg (<GPR:MODE>mode,
3694                                                 GEN_INT (<SHORT:mask>))));
3695       DONE;
3696     }
3699 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3700   [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3701         (zero_extend:GPR
3702              (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3703   "!TARGET_MIPS16"
3704   "@
3705    andi\t%0,%1,<SHORT:mask>
3706    andi\t%0,%1,<SHORT:mask>
3707    l<SHORT:size>u\t%0,%1"
3708   [(set_attr "move_type" "andi,andi,load")
3709    (set_attr "compression" "micromips,*,*")
3710    (set_attr "mode" "<GPR:MODE>")])
3712 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3713   [(set (match_operand:GPR 0 "register_operand" "=d")
3714         (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3715   "GENERATE_MIPS16E"
3716   "ze<SHORT:size>\t%0"
3717   ;; This instruction is effectively a special encoding of ANDI.
3718   [(set_attr "move_type" "andi")
3719    (set_attr "mode" "<GPR:MODE>")])
3721 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3722   [(set (match_operand:GPR 0 "register_operand" "=d")
3723         (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3724   "TARGET_MIPS16"
3725   "l<SHORT:size>u\t%0,%1"
3726   [(set_attr "move_type" "load")
3727    (set_attr "mode" "<GPR:MODE>")])
3729 (define_expand "zero_extendqihi2"
3730   [(set (match_operand:HI 0 "register_operand")
3731         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3732   ""
3734   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3735     {
3736       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3737                                        operands[1]));
3738       DONE;
3739     }
3742 (define_insn "*zero_extendqihi2"
3743   [(set (match_operand:HI 0 "register_operand" "=d,d")
3744         (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3745   "!TARGET_MIPS16"
3746   "@
3747    andi\t%0,%1,0x00ff
3748    lbu\t%0,%1"
3749   [(set_attr "move_type" "andi,load")
3750    (set_attr "mode" "HI")])
3752 (define_insn "*zero_extendqihi2_mips16"
3753   [(set (match_operand:HI 0 "register_operand" "=d")
3754         (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3755   "TARGET_MIPS16"
3756   "lbu\t%0,%1"
3757   [(set_attr "move_type" "load")
3758    (set_attr "mode" "HI")])
3760 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3762 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3763   [(set (match_operand:GPR 0 "register_operand" "=d")
3764         (zero_extend:GPR
3765             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3766   "TARGET_64BIT && !TARGET_MIPS16"
3768   operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3769   return "andi\t%0,%1,%x2";
3771   [(set_attr "alu_type" "and")
3772    (set_attr "mode" "<GPR:MODE>")])
3774 (define_insn "*zero_extendhi_truncqi"
3775   [(set (match_operand:HI 0 "register_operand" "=d")
3776         (zero_extend:HI
3777             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3778   "TARGET_64BIT && !TARGET_MIPS16"
3779   "andi\t%0,%1,0xff"
3780   [(set_attr "alu_type" "and")
3781    (set_attr "mode" "HI")])
3784 ;;  ....................
3786 ;;      SIGN EXTENSION
3788 ;;  ....................
3790 ;; Extension insns.
3791 ;; Those for integer source operand are ordered widest source type first.
3793 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3794 ;; should already be in sign-extended form (see TARGET_TRULY_NOOP_TRUNCATION
3795 ;; and truncdisi2).  We can therefore get rid of register->register
3796 ;; instructions if we constrain the source to be in the same register as
3797 ;; the destination.
3799 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3800 ;; we split them into nothing before the post-reload scheduler runs.
3801 ;; These alternatives therefore have type "move" in order to reflect
3802 ;; what happens if the two pre-reload operands cannot be tied, and are
3803 ;; instead allocated two separate GPRs.  We don't distinguish between
3804 ;; the GPR and LO cases because we don't usually know during pre-reload
3805 ;; scheduling whether an operand will be LO or not.
3806 (define_insn_and_split "extendsidi2"
3807   [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3808         (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3809   "TARGET_64BIT"
3810   "@
3811    #
3812    #
3813    lw\t%0,%1"
3814   "&& reload_completed && register_operand (operands[1], VOIDmode)"
3815   [(const_int 0)]
3817   emit_note (NOTE_INSN_DELETED);
3818   DONE;
3820   [(set_attr "move_type" "move,move,load")
3821    (set_attr "mode" "DI")])
3823 (define_expand "extend<SHORT:mode><GPR:mode>2"
3824   [(set (match_operand:GPR 0 "register_operand")
3825         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3826   "")
3828 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3829   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3830         (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3831   "GENERATE_MIPS16E"
3832   "@
3833    se<SHORT:size>\t%0
3834    l<SHORT:size>\t%0,%1"
3835   [(set_attr "move_type" "signext,load")
3836    (set_attr "mode" "<GPR:MODE>")])
3838 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3839   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3840         (sign_extend:GPR
3841              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3842   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3843   "@
3844    #
3845    l<SHORT:size>\t%0,%1"
3846   "&& reload_completed && REG_P (operands[1])"
3847   [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3848    (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3850   operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3851   operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3852                          - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3854   [(set_attr "move_type" "shift_shift,load")
3855    (set_attr "mode" "<GPR:MODE>")])
3857 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3858   [(set (match_operand:GPR 0 "register_operand" "=d,d")
3859         (sign_extend:GPR
3860              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3861   "ISA_HAS_SEB_SEH"
3862   "@
3863    se<SHORT:size>\t%0,%1
3864    l<SHORT:size>\t%0,%1"
3865   [(set_attr "move_type" "signext,load")
3866    (set_attr "mode" "<GPR:MODE>")])
3868 (define_expand "extendqihi2"
3869   [(set (match_operand:HI 0 "register_operand")
3870         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3871   "")
3873 (define_insn "*extendqihi2_mips16e"
3874   [(set (match_operand:HI 0 "register_operand" "=d,d")
3875         (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3876   "GENERATE_MIPS16E"
3877   "@
3878    seb\t%0
3879    lb\t%0,%1"
3880   [(set_attr "move_type" "signext,load")
3881    (set_attr "mode" "SI")])
3883 (define_insn_and_split "*extendqihi2"
3884   [(set (match_operand:HI 0 "register_operand" "=d,d")
3885         (sign_extend:HI
3886              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3887   "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3888   "@
3889    #
3890    lb\t%0,%1"
3891   "&& reload_completed && REG_P (operands[1])"
3892   [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3893    (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3895   operands[0] = gen_lowpart (SImode, operands[0]);
3896   operands[1] = gen_lowpart (SImode, operands[1]);
3897   operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3898                          - GET_MODE_BITSIZE (QImode));
3900   [(set_attr "move_type" "shift_shift,load")
3901    (set_attr "mode" "SI")])
3903 (define_insn "*extendqihi2_seb"
3904   [(set (match_operand:HI 0 "register_operand" "=d,d")
3905         (sign_extend:HI
3906              (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3907   "ISA_HAS_SEB_SEH"
3908   "@
3909    seb\t%0,%1
3910    lb\t%0,%1"
3911   [(set_attr "move_type" "signext,load")
3912    (set_attr "mode" "SI")])
3914 ;; Combiner patterns for truncate/sign_extend combinations.  The SI versions
3915 ;; use the shift/truncate patterns.
3917 (define_insn_and_split "*extenddi_truncate<mode>"
3918   [(set (match_operand:DI 0 "register_operand" "=d")
3919         (sign_extend:DI
3920             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3921   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3922   "#"
3923   "&& reload_completed"
3924   [(set (match_dup 2)
3925         (ashift:DI (match_dup 1)
3926                    (match_dup 3)))
3927    (set (match_dup 0)
3928         (ashiftrt:DI (match_dup 2)
3929                      (match_dup 3)))]
3931   operands[2] = gen_lowpart (DImode, operands[0]);
3932   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3934   [(set_attr "move_type" "shift_shift")
3935    (set_attr "mode" "DI")])
3937 (define_insn_and_split "*extendsi_truncate<mode>"
3938   [(set (match_operand:SI 0 "register_operand" "=d")
3939         (sign_extend:SI
3940             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3941   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3942   "#"
3943   "&& reload_completed"
3944   [(set (match_dup 2)
3945         (ashift:DI (match_dup 1)
3946                    (match_dup 3)))
3947    (set (match_dup 0)
3948         (truncate:SI (ashiftrt:DI (match_dup 2)
3949                                   (match_dup 3))))]
3951   operands[2] = gen_lowpart (DImode, operands[0]);
3952   operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3954   [(set_attr "move_type" "shift_shift")
3955    (set_attr "mode" "SI")])
3957 (define_insn_and_split "*extendhi_truncateqi"
3958   [(set (match_operand:HI 0 "register_operand" "=d")
3959         (sign_extend:HI
3960             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3961   "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3962   "#"
3963   "&& reload_completed"
3964   [(set (match_dup 2)
3965         (ashift:DI (match_dup 1)
3966                    (const_int 56)))
3967    (set (match_dup 0)
3968         (truncate:HI (ashiftrt:DI (match_dup 2)
3969                                   (const_int 56))))]
3971   operands[2] = gen_lowpart (DImode, operands[0]);
3973   [(set_attr "move_type" "shift_shift")
3974    (set_attr "mode" "SI")])
3976 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3977   [(set (match_operand:GPR 0 "register_operand" "=d")
3978         (sign_extend:GPR
3979             (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3980   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3982   operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3983   return "exts\t%0,%1,0,%m2";
3985   [(set_attr "type" "arith")
3986    (set_attr "mode" "<GPR:MODE>")])
3988 (define_insn "*extendhi_truncateqi_exts"
3989   [(set (match_operand:HI 0 "register_operand" "=d")
3990         (sign_extend:HI
3991             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3992   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3993   "exts\t%0,%1,0,7"
3994   [(set_attr "type" "arith")
3995    (set_attr "mode" "SI")])
3997 (define_insn "extendsfdf2"
3998   [(set (match_operand:DF 0 "register_operand" "=f")
3999         (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
4000   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4001   "cvt.d.s\t%0,%1"
4002   [(set_attr "type"     "fcvt")
4003    (set_attr "cnv_mode" "S2D")   
4004    (set_attr "mode"     "DF")])
4007 ;;  ....................
4009 ;;      CONVERSIONS
4011 ;;  ....................
4013 (define_expand "fix_truncdfsi2"
4014   [(set (match_operand:SI 0 "register_operand")
4015         (fix:SI (match_operand:DF 1 "register_operand")))]
4016   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4018   if (!ISA_HAS_TRUNC_W)
4019     {
4020       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
4021       DONE;
4022     }
4025 (define_insn "fix_truncdfsi2_insn"
4026   [(set (match_operand:SI 0 "register_operand" "=f")
4027         (fix:SI (match_operand:DF 1 "register_operand" "f")))]
4028   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
4029   "trunc.w.d %0,%1"
4030   [(set_attr "type"     "fcvt")
4031    (set_attr "mode"     "DF")
4032    (set_attr "cnv_mode" "D2I")])
4034 (define_insn "fix_truncdfsi2_macro"
4035   [(set (match_operand:SI 0 "register_operand" "=f")
4036         (fix:SI (match_operand:DF 1 "register_operand" "f")))
4037    (clobber (match_scratch:DF 2 "=d"))]
4038   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
4040   if (mips_nomacro.nesting_level > 0)
4041     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
4042   else
4043     return "trunc.w.d %0,%1,%2";
4045   [(set_attr "type"     "fcvt")
4046    (set_attr "mode"     "DF")
4047    (set_attr "cnv_mode" "D2I")
4048    (set_attr "insn_count" "9")])
4050 (define_expand "fix_truncsfsi2"
4051   [(set (match_operand:SI 0 "register_operand")
4052         (fix:SI (match_operand:SF 1 "register_operand")))]
4053   "TARGET_HARD_FLOAT"
4055   if (!ISA_HAS_TRUNC_W)
4056     {
4057       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
4058       DONE;
4059     }
4062 (define_insn "fix_truncsfsi2_insn"
4063   [(set (match_operand:SI 0 "register_operand" "=f")
4064         (fix:SI (match_operand:SF 1 "register_operand" "f")))]
4065   "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
4066   "trunc.w.s %0,%1"
4067   [(set_attr "type"     "fcvt")
4068    (set_attr "mode"     "SF")
4069    (set_attr "cnv_mode" "S2I")])
4071 (define_insn "fix_truncsfsi2_macro"
4072   [(set (match_operand:SI 0 "register_operand" "=f")
4073         (fix:SI (match_operand:SF 1 "register_operand" "f")))
4074    (clobber (match_scratch:SF 2 "=d"))]
4075   "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
4077   if (mips_nomacro.nesting_level > 0)
4078     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
4079   else
4080     return "trunc.w.s %0,%1,%2";
4082   [(set_attr "type"     "fcvt")
4083    (set_attr "mode"     "SF")
4084    (set_attr "cnv_mode" "S2I")
4085    (set_attr "insn_count" "9")])
4088 (define_insn "fix_truncdfdi2"
4089   [(set (match_operand:DI 0 "register_operand" "=f")
4090         (fix:DI (match_operand:DF 1 "register_operand" "f")))]
4091   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4092   "trunc.l.d %0,%1"
4093   [(set_attr "type"     "fcvt")
4094    (set_attr "mode"     "DF")
4095    (set_attr "cnv_mode" "D2I")])
4098 (define_insn "fix_truncsfdi2"
4099   [(set (match_operand:DI 0 "register_operand" "=f")
4100         (fix:DI (match_operand:SF 1 "register_operand" "f")))]
4101   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4102   "trunc.l.s %0,%1"
4103   [(set_attr "type"     "fcvt")
4104    (set_attr "mode"     "SF")
4105    (set_attr "cnv_mode" "S2I")])
4108 (define_insn "floatsidf2"
4109   [(set (match_operand:DF 0 "register_operand" "=f")
4110         (float:DF (match_operand:SI 1 "register_operand" "f")))]
4111   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4112   "cvt.d.w\t%0,%1"
4113   [(set_attr "type"     "fcvt")
4114    (set_attr "mode"     "DF")
4115    (set_attr "cnv_mode" "I2D")])
4118 (define_insn "floatdidf2"
4119   [(set (match_operand:DF 0 "register_operand" "=f")
4120         (float:DF (match_operand:DI 1 "register_operand" "f")))]
4121   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4122   "cvt.d.l\t%0,%1"
4123   [(set_attr "type"     "fcvt")
4124    (set_attr "mode"     "DF")
4125    (set_attr "cnv_mode" "I2D")])
4128 (define_insn "floatsisf2"
4129   [(set (match_operand:SF 0 "register_operand" "=f")
4130         (float:SF (match_operand:SI 1 "register_operand" "f")))]
4131   "TARGET_HARD_FLOAT"
4132   "cvt.s.w\t%0,%1"
4133   [(set_attr "type"     "fcvt")
4134    (set_attr "mode"     "SF")
4135    (set_attr "cnv_mode" "I2S")])
4138 (define_insn "floatdisf2"
4139   [(set (match_operand:SF 0 "register_operand" "=f")
4140         (float:SF (match_operand:DI 1 "register_operand" "f")))]
4141   "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4142   "cvt.s.l\t%0,%1"
4143   [(set_attr "type"     "fcvt")
4144    (set_attr "mode"     "SF")
4145    (set_attr "cnv_mode" "I2S")])
4148 (define_expand "fixuns_truncdfsi2"
4149   [(set (match_operand:SI 0 "register_operand")
4150         (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
4151   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4153   rtx reg1 = gen_reg_rtx (DFmode);
4154   rtx reg2 = gen_reg_rtx (DFmode);
4155   rtx reg3 = gen_reg_rtx (SImode);
4156   rtx_code_label *label1 = gen_label_rtx ();
4157   rtx_code_label *label2 = gen_label_rtx ();
4158   rtx test;
4159   REAL_VALUE_TYPE offset;
4161   real_2expN (&offset, 31, DFmode);
4163   if (reg1)                     /* Turn off complaints about unreached code.  */
4164     {
4165       mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4166       do_pending_stack_adjust ();
4168       test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4169       emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4171       emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4172       emit_jump_insn (gen_rtx_SET (pc_rtx,
4173                                    gen_rtx_LABEL_REF (VOIDmode, label2)));
4174       emit_barrier ();
4176       emit_label (label1);
4177       mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4178       mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4179                                      (BITMASK_HIGH, SImode)));
4181       emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4182       emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4184       emit_label (label2);
4186       /* Allow REG_NOTES to be set on last insn (labels don't have enough
4187          fields, and can't be used for REG_NOTES anyway).  */
4188       emit_use (stack_pointer_rtx);
4189       DONE;
4190     }
4194 (define_expand "fixuns_truncdfdi2"
4195   [(set (match_operand:DI 0 "register_operand")
4196         (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
4197   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4199   rtx reg1 = gen_reg_rtx (DFmode);
4200   rtx reg2 = gen_reg_rtx (DFmode);
4201   rtx reg3 = gen_reg_rtx (DImode);
4202   rtx_code_label *label1 = gen_label_rtx ();
4203   rtx_code_label *label2 = gen_label_rtx ();
4204   rtx test;
4205   REAL_VALUE_TYPE offset;
4207   real_2expN (&offset, 63, DFmode);
4209   mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4210   do_pending_stack_adjust ();
4212   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4213   emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4215   emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4216   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4217   emit_barrier ();
4219   emit_label (label1);
4220   mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4221   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4222   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4224   emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4225   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4227   emit_label (label2);
4229   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4230      fields, and can't be used for REG_NOTES anyway).  */
4231   emit_use (stack_pointer_rtx);
4232   DONE;
4236 (define_expand "fixuns_truncsfsi2"
4237   [(set (match_operand:SI 0 "register_operand")
4238         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
4239   "TARGET_HARD_FLOAT"
4241   rtx reg1 = gen_reg_rtx (SFmode);
4242   rtx reg2 = gen_reg_rtx (SFmode);
4243   rtx reg3 = gen_reg_rtx (SImode);
4244   rtx_code_label *label1 = gen_label_rtx ();
4245   rtx_code_label *label2 = gen_label_rtx ();
4246   rtx test;
4247   REAL_VALUE_TYPE offset;
4249   real_2expN (&offset, 31, SFmode);
4251   mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4252   do_pending_stack_adjust ();
4254   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4255   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4257   emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4258   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4259   emit_barrier ();
4261   emit_label (label1);
4262   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4263   mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4264                                  (BITMASK_HIGH, SImode)));
4266   emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4267   emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4269   emit_label (label2);
4271   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4272      fields, and can't be used for REG_NOTES anyway).  */
4273   emit_use (stack_pointer_rtx);
4274   DONE;
4278 (define_expand "fixuns_truncsfdi2"
4279   [(set (match_operand:DI 0 "register_operand")
4280         (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
4281   "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4283   rtx reg1 = gen_reg_rtx (SFmode);
4284   rtx reg2 = gen_reg_rtx (SFmode);
4285   rtx reg3 = gen_reg_rtx (DImode);
4286   rtx_code_label *label1 = gen_label_rtx ();
4287   rtx_code_label *label2 = gen_label_rtx ();
4288   rtx test;
4289   REAL_VALUE_TYPE offset;
4291   real_2expN (&offset, 63, SFmode);
4293   mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4294   do_pending_stack_adjust ();
4296   test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4297   emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4299   emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4300   emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4301   emit_barrier ();
4303   emit_label (label1);
4304   mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4305   mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4306   emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4308   emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4309   emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4311   emit_label (label2);
4313   /* Allow REG_NOTES to be set on last insn (labels don't have enough
4314      fields, and can't be used for REG_NOTES anyway).  */
4315   emit_use (stack_pointer_rtx);
4316   DONE;
4320 ;;  ....................
4322 ;;      DATA MOVEMENT
4324 ;;  ....................
4326 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4328 (define_expand "extvmisalign<mode>"
4329   [(set (match_operand:GPR 0 "register_operand")
4330         (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4331                           (match_operand 2 "const_int_operand")
4332                           (match_operand 3 "const_int_operand")))]
4333   "ISA_HAS_LWL_LWR"
4335   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4336                                          INTVAL (operands[2]),
4337                                          INTVAL (operands[3]),
4338                                          /*unsigned=*/ false))
4339     DONE;
4340   else
4341     FAIL;
4344 (define_expand "extv<mode>"
4345   [(set (match_operand:GPR 0 "register_operand")
4346         (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4347                           (match_operand 2 "const_int_operand")
4348                           (match_operand 3 "const_int_operand")))]
4349   "ISA_HAS_EXTS"
4351   if (UINTVAL (operands[2]) > 32)
4352     FAIL;
4355 (define_insn "*extv<mode>"
4356   [(set (match_operand:GPR 0 "register_operand" "=d")
4357         (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4358                           (match_operand 2 "const_int_operand" "")
4359                           (match_operand 3 "const_int_operand" "")))]
4360   "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4361   "exts\t%0,%1,%3,%m2"
4362   [(set_attr "type"     "arith")
4363    (set_attr "mode"     "<MODE>")])
4365 (define_expand "extzvmisalign<mode>"
4366   [(set (match_operand:GPR 0 "register_operand")
4367         (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4368                           (match_operand 2 "const_int_operand")
4369                           (match_operand 3 "const_int_operand")))]
4370   "ISA_HAS_LWL_LWR"
4372   if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4373                                          INTVAL (operands[2]),
4374                                          INTVAL (operands[3]),
4375                                          /*unsigned=*/ true))
4376     DONE;
4377   else
4378     FAIL;
4381 (define_expand "extzv<mode>"
4382   [(set (match_operand:GPR 0 "register_operand")
4383         (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4384                           (match_operand 2 "const_int_operand")
4385                           (match_operand 3 "const_int_operand")))]
4386   ""
4388   if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4389                            INTVAL (operands[3])))
4390     FAIL;
4393 (define_insn "*extzv<mode>"
4394   [(set (match_operand:GPR 0 "register_operand" "=d")
4395         (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4396                           (match_operand 2 "const_int_operand" "")
4397                           (match_operand 3 "const_int_operand" "")))]
4398   "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4399                        INTVAL (operands[3]))"
4400   "<d>ext\t%0,%1,%3,%2"
4401   [(set_attr "type"     "arith")
4402    (set_attr "extended_mips16"  "yes")
4403    (set_attr "mode"     "<MODE>")])
4405 (define_insn "*extzv_truncsi_exts"
4406   [(set (match_operand:SI 0 "register_operand" "=d")
4407         (truncate:SI
4408          (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4409                           (match_operand 2 "const_int_operand" "")
4410                           (match_operand 3 "const_int_operand" ""))))]
4411   "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4412   "exts\t%0,%1,%3,31"
4413   [(set_attr "type"     "arith")
4414    (set_attr "mode"     "SI")])
4416 (define_insn "*insqisi_extended"
4417   [(set (match_operand:DI 0 "register_operand" "=d")
4418     (sign_extend:DI
4419       (ior:SI (and:SI (subreg:SI (match_dup 0) 0)
4420                 (const_int 16777215))
4421               (ashift:SI
4422                 (subreg:SI (match_operand:QI 1 "register_operand" "d") 0)
4423                 (const_int 24)))))]
4424   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXT_INS"
4425   "ins\t%0,%1,24,8"
4426   [(set_attr "mode" "SI")
4427    (set_attr "perf_ratio" "1")])
4429 (define_insn "*inshisi_extended"
4430   [(set (match_operand:DI 0 "register_operand" "=d")
4431     (sign_extend:DI
4432       (ior:SI
4433         (ashift:SI (subreg:SI (match_operand:HI 1 "register_operand" "d") 0)
4434           (const_int 16))
4435         (zero_extend:SI (subreg:HI (match_dup 0) 0)))))]
4436   "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXT_INS"
4437   "ins\t%0,%1,16,16"
4438   [(set_attr "mode" "SI")
4439    (set_attr "perf_ratio" "1")])
4441 (define_expand "insvmisalign<mode>"
4442   [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4443                           (match_operand 1 "const_int_operand")
4444                           (match_operand 2 "const_int_operand"))
4445         (match_operand:GPR 3 "reg_or_0_operand"))]
4446   "ISA_HAS_LWL_LWR"
4448   if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4449                                           INTVAL (operands[1]),
4450                                           INTVAL (operands[2])))
4451     DONE;
4452   else
4453     FAIL;
4456 (define_expand "insv<mode>"
4457   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4458                           (match_operand 1 "const_int_operand")
4459                           (match_operand 2 "const_int_operand"))
4460         (match_operand:GPR 3 "reg_or_0_operand"))]
4461   ""
4463   if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4464                            INTVAL (operands[2])))
4465     FAIL;
4468 (define_insn "*insv<mode>"
4469   [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4470                           (match_operand:SI 1 "const_int_operand" "")
4471                           (match_operand:SI 2 "const_int_operand" ""))
4472         (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4473   "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4474                        INTVAL (operands[2]))"
4475   "<d>ins\t%0,%z3,%2,%1"
4476   [(set_attr "type"     "arith")
4477    (set_attr "extended_mips16"  "yes")
4478    (set_attr "mode"     "<MODE>")])
4480 ;; Combiner pattern for cins (clear and insert bit field).  We can
4481 ;; implement mask-and-shift-left operation with this.  Note that if
4482 ;; the upper bit of the mask is set in an SImode operation, the mask
4483 ;; itself will be sign-extended.  mask_low_and_shift_len will
4484 ;; therefore be greater than our threshold of 32.
4486 (define_insn "*cins<mode>"
4487   [(set (match_operand:GPR 0 "register_operand" "=d")
4488         (and:GPR
4489          (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4490                      (match_operand:GPR 2 "const_int_operand" ""))
4491          (match_operand:GPR 3 "const_int_operand" "")))]
4492   "ISA_HAS_CINS
4493    && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4495   operands[3] =
4496     GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4497   return "cins\t%0,%1,%2,%m3";
4499   [(set_attr "type"     "shift")
4500    (set_attr "mode"     "<MODE>")])
4502 ;; Unaligned word moves generated by the bit field patterns.
4504 ;; As far as the rtl is concerned, both the left-part and right-part
4505 ;; instructions can access the whole field.  However, the real operand
4506 ;; refers to just the first or the last byte (depending on endianness).
4507 ;; We therefore use two memory operands to each instruction, one to
4508 ;; describe the rtl effect and one to use in the assembly output.
4510 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4511 ;; This allows us to use the standard length calculations for the "load"
4512 ;; and "store" type attributes.
4514 (define_insn "mov_<load>l"
4515   [(set (match_operand:GPR 0 "register_operand" "=d")
4516         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4517                      (match_operand:QI 2 "memory_operand" "ZC")]
4518                     UNSPEC_LOAD_LEFT))]
4519   "(!TARGET_MIPS16 || ISA_HAS_MIPS16E2)
4520     && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4521   "<load>l\t%0,%2"
4522   [(set_attr "move_type" "load")
4523    (set_attr "mode" "<MODE>")
4524    (set_attr "extended_mips16" "yes")])
4526 (define_insn "mov_<load>r"
4527   [(set (match_operand:GPR 0 "register_operand" "=d")
4528         (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4529                      (match_operand:QI 2 "memory_operand" "ZC")
4530                      (match_operand:GPR 3 "register_operand" "0")]
4531                     UNSPEC_LOAD_RIGHT))]
4532   "(!TARGET_MIPS16 || ISA_HAS_MIPS16E2)
4533     && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4534   "<load>r\t%0,%2"
4535   [(set_attr "move_type" "load")
4536    (set_attr "mode" "<MODE>")
4537    (set_attr "extended_mips16" "yes")])
4539 (define_insn "mov_<store>l"
4540   [(set (match_operand:BLK 0 "memory_operand" "=m")
4541         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4542                      (match_operand:QI 2 "memory_operand" "ZC")]
4543                     UNSPEC_STORE_LEFT))]
4544   "!TARGET_MIPS16
4545    && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4546   "<store>l\t%z1,%2"
4547   [(set_attr "move_type" "store")
4548    (set_attr "mode" "<MODE>")])
4550 (define_insn "mov_<store>r"
4551   [(set (match_operand:BLK 0 "memory_operand" "+m")
4552         (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4553                      (match_operand:QI 2 "memory_operand" "ZC")
4554                      (match_dup 0)]
4555                     UNSPEC_STORE_RIGHT))]
4556   "!TARGET_MIPS16
4557    && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4558   "<store>r\t%z1,%2"
4559   [(set_attr "move_type" "store")
4560    (set_attr "mode" "<MODE>")])
4562 (define_insn "mov_<store>l_mips16e2"
4563   [(set (match_operand:BLK 0 "memory_operand" "=m")
4564     (unspec:BLK [(match_operand:GPR 1 "register_operand" "d")
4565                      (match_operand:QI 2 "memory_operand" "ZC")]
4566                     UNSPEC_STORE_LEFT))]
4567   "TARGET_MIPS16 && ISA_HAS_MIPS16E2
4568    && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4569   "<store>l\t%1,%2"
4570   [(set_attr "move_type" "store")
4571    (set_attr "mode" "<MODE>")
4572    (set_attr "extended_mips16" "yes")])
4574 (define_insn "mov_<store>r_mips16e2"
4575   [(set (match_operand:BLK 0 "memory_operand" "+m")
4576     (unspec:BLK [(match_operand:GPR 1 "register_operand" "d")
4577                      (match_operand:QI 2 "memory_operand" "ZC")
4578                      (match_dup 0)]
4579                     UNSPEC_STORE_RIGHT))]
4580   "TARGET_MIPS16 && ISA_HAS_MIPS16E2
4581    && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4582   "<store>r\t%1,%2"
4583   [(set_attr "move_type" "store")
4584    (set_attr "mode" "<MODE>")
4585    (set_attr "extended_mips16" "yes")])
4587 ;; Unaligned direct access
4588 (define_expand "movmisalign<mode>"
4589   [(set (match_operand:JOIN_MODE 0)
4590         (match_operand:JOIN_MODE 1))]
4591   "ISA_HAS_UNALIGNED_ACCESS"
4593   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4594     DONE;
4597 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4598 ;; The required value is:
4600 ;;      (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4602 ;; which translates to:
4604 ;;      lui     op0,%highest(op1)
4605 ;;      daddiu  op0,op0,%higher(op1)
4606 ;;      dsll    op0,op0,16
4607 ;;      daddiu  op0,op0,%hi(op1)
4608 ;;      dsll    op0,op0,16
4610 ;; The split is deferred until after flow2 to allow the peephole2 below
4611 ;; to take effect.
4612 (define_insn_and_split "*lea_high64"
4613   [(set (match_operand:DI 0 "register_operand" "=d")
4614         (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4615   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4616   "#"
4617   "&& epilogue_completed"
4618   [(set (match_dup 0) (high:DI (match_dup 2)))
4619    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4620    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4621    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4622    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4624   operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4625   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4627   [(set_attr "insn_count" "5")])
4629 ;; Use a scratch register to reduce the latency of the above pattern
4630 ;; on superscalar machines.  The optimized sequence is:
4632 ;;      lui     op1,%highest(op2)
4633 ;;      lui     op0,%hi(op2)
4634 ;;      daddiu  op1,op1,%higher(op2)
4635 ;;      dsll32  op1,op1,0
4636 ;;      daddu   op1,op1,op0
4637 (define_peephole2
4638   [(set (match_operand:DI 1 "d_operand")
4639         (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4640    (match_scratch:DI 0 "d")]
4641   "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4642   [(set (match_dup 1) (high:DI (match_dup 3)))
4643    (set (match_dup 0) (high:DI (match_dup 4)))
4644    (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4645    (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4646    (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4648   operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4649   operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4652 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4653 ;; SYMBOL_ABSOLUTE X will take 6 cycles.  This next pattern allows combine
4654 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4655 ;; used once.  We can then use the sequence:
4657 ;;      lui     op0,%highest(op1)
4658 ;;      lui     op2,%hi(op1)
4659 ;;      daddiu  op0,op0,%higher(op1)
4660 ;;      daddiu  op2,op2,%lo(op1)
4661 ;;      dsll32  op0,op0,0
4662 ;;      daddu   op0,op0,op2
4664 ;; which takes 4 cycles on most superscalar targets.
4665 (define_insn_and_split "*lea64"
4666   [(set (match_operand:DI 0 "register_operand" "=d")
4667         (match_operand:DI 1 "absolute_symbolic_operand" ""))
4668    (clobber (match_scratch:DI 2 "=&d"))]
4669   "!TARGET_MIPS16
4670    && TARGET_EXPLICIT_RELOCS
4671    && ABI_HAS_64BIT_SYMBOLS
4672    && cse_not_expected"
4673   "#"
4674   "&& reload_completed"
4675   [(set (match_dup 0) (high:DI (match_dup 3)))
4676    (set (match_dup 2) (high:DI (match_dup 4)))
4677    (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4678    (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4679    (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4680    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4682   operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4683   operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4685   [(set_attr "insn_count" "6")])
4687 ;; Split HIGHs into:
4689 ;;      li op0,%hi(sym)
4690 ;;      sll op0,16
4692 ;; on MIPS16 targets.
4693 (define_split
4694   [(set (match_operand:P 0 "d_operand")
4695         (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4696   "TARGET_MIPS16 && reload_completed && !ISA_HAS_MIPS16E2"
4697   [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4698    (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4700 (define_insn "*unshifted_high"
4701   [(set (match_operand:P 0 "d_operand" "=d")
4702         (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4703                   UNSPEC_UNSHIFTED_HIGH))]
4704   ""
4705   "li\t%0,%h1"
4706   [(set_attr "extended_mips16" "yes")])
4708 ;; Insns to fetch a symbol from a big GOT.
4710 (define_insn_and_split "*xgot_hi<mode>"
4711   [(set (match_operand:P 0 "register_operand" "=d")
4712         (high:P (match_operand:P 1 "got_disp_operand" "")))]
4713   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4714   "#"
4715   "&& reload_completed"
4716   [(set (match_dup 0) (high:P (match_dup 2)))
4717    (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4719   operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4720   operands[3] = pic_offset_table_rtx;
4722   [(set_attr "got" "xgot_high")
4723    (set_attr "mode" "<MODE>")])
4725 (define_insn_and_split "*xgot_lo<mode>"
4726   [(set (match_operand:P 0 "register_operand" "=d")
4727         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4728                   (match_operand:P 2 "got_disp_operand" "")))]
4729   "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4730   "#"
4731   "&& reload_completed"
4732   [(set (match_dup 0)
4733         (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4734   { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4735   [(set_attr "got" "load")
4736    (set_attr "mode" "<MODE>")])
4738 ;; Insns to fetch a symbol from a normal GOT.
4740 (define_insn_and_split "*got_disp<mode>"
4741   [(set (match_operand:P 0 "register_operand" "=d")
4742         (match_operand:P 1 "got_disp_operand" ""))]
4743   "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4744   "#"
4745   "&& reload_completed"
4746   [(set (match_dup 0) (match_dup 2))]
4747   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4748   [(set_attr "got" "load")
4749    (set_attr "mode" "<MODE>")])
4751 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4753 (define_insn_and_split "*got_page<mode>"
4754   [(set (match_operand:P 0 "register_operand" "=d")
4755         (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4756   "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4757   "#"
4758   "&& reload_completed"
4759   [(set (match_dup 0) (match_dup 2))]
4760   { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4761   [(set_attr "got" "load")
4762    (set_attr "mode" "<MODE>")])
4764 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4765 (define_expand "unspec_got_<mode>"
4766   [(unspec:P [(match_operand:P 0)
4767               (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4769 ;; Lower-level instructions for loading an address from the GOT.
4770 ;; We could use MEMs, but an unspec gives more optimization
4771 ;; opportunities.
4773 (define_insn "load_got<mode>"
4774   [(set (match_operand:P 0 "register_operand" "=d")
4775         (unspec:P [(match_operand:P 1 "register_operand" "d")
4776                    (match_operand:P 2 "immediate_operand" "")]
4777                   UNSPEC_LOAD_GOT))]
4778   ""
4779   "<load>\t%0,%R2(%1)"
4780   [(set_attr "got" "load")
4781    (set_attr "mode" "<MODE>")])
4783 ;; Instructions for adding the low 16 bits of an address to a register.
4784 ;; Operand 2 is the address: mips_print_operand works out which relocation
4785 ;; should be applied.
4787 (define_insn "*low<mode>"
4788   [(set (match_operand:P 0 "register_operand" "=d")
4789         (lo_sum:P (match_operand:P 1 "register_operand" "d")
4790                   (match_operand:P 2 "immediate_operand" "")))]
4791   "!TARGET_MIPS16"
4792   "<d>addiu\t%0,%1,%R2"
4793   [(set_attr "alu_type" "add")
4794    (set_attr "mode" "<MODE>")])
4796 (define_insn "*lowsi_mips16_gp"
4797   [(set (match_operand:SI 0 "register_operand" "=d")
4798     (lo_sum:SI (reg:SI GLOBAL_POINTER_REGNUM)
4799                   (match_operand 1 "immediate_operand" "")))]
4800   "MIPS16_GP_LOADS"
4801   "addiu\t%0,$28,%R1"
4802   [(set_attr "alu_type" "add")
4803    (set_attr "mode" "SI")
4804    (set_attr "extended_mips16" "yes")])
4806 (define_insn "*low<mode>_mips16"
4807   [(set (match_operand:P 0 "register_operand" "=d")
4808         (lo_sum:P (match_operand:P 1 "register_operand" "0")
4809                   (match_operand:P 2 "immediate_operand" "")))]
4810   "TARGET_MIPS16"
4811   "<d>addiu\t%0,%R2"
4812   [(set_attr "alu_type" "add")
4813    (set_attr "mode" "<MODE>")
4814    (set_attr "extended_mips16" "yes")])
4816 ;; Expose MIPS16 uses of the global pointer after reload if the function
4817 ;; is responsible for setting up the register itself.
4818 (define_split
4819   [(set (match_operand:GPR 0 "d_operand")
4820         (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4821   "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4822   [(set (match_dup 0) (match_dup 1))]
4823   { operands[1] = pic_offset_table_rtx; })
4825 ;; Allow combine to split complex const_int load sequences, using operand 2
4826 ;; to store the intermediate results.  See move_operand for details.
4827 (define_split
4828   [(set (match_operand:GPR 0 "register_operand")
4829         (match_operand:GPR 1 "splittable_const_int_operand"))
4830    (clobber (match_operand:GPR 2 "register_operand"))]
4831   ""
4832   [(const_int 0)]
4834   mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4835   DONE;
4838 ;; Likewise, for symbolic operands.
4839 (define_split
4840   [(set (match_operand:P 0 "register_operand")
4841         (match_operand:P 1))
4842    (clobber (match_operand:P 2 "register_operand"))]
4843   "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4844   [(set (match_dup 0) (match_dup 3))]
4846   mips_split_symbol (operands[2], operands[1],
4847                      MAX_MACHINE_MODE, &operands[3]);
4850 ;; 64-bit integer moves
4852 ;; Unlike most other insns, the move insns can't be split with
4853 ;; different predicates, because register spilling and other parts of
4854 ;; the compiler, have memoized the insn number already.
4856 (define_expand "movdi"
4857   [(set (match_operand:DI 0 "")
4858         (match_operand:DI 1 ""))]
4859   ""
4861   if (mips_legitimize_move (DImode, operands[0], operands[1]))
4862     DONE;
4865 ;; For mips16, we need a special case to handle storing $31 into
4866 ;; memory, since we don't have a constraint to match $31.  This
4867 ;; instruction can be generated by save_restore_insns.
4869 (define_insn "*mov<mode>_ra"
4870   [(set (match_operand:GPR 0 "stack_operand" "=m")
4871         (reg:GPR RETURN_ADDR_REGNUM))]
4872   "TARGET_MIPS16"
4873   "<store>\t$31,%0"
4874   [(set_attr "move_type" "store")
4875    (set_attr "mode" "<MODE>")])
4877 (define_insn "*movdi_32bit"
4878   [(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")
4879         (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"))]
4880   "!TARGET_64BIT && !TARGET_MIPS16
4881    && (register_operand (operands[0], DImode)
4882        || reg_or_0_operand (operands[1], DImode))"
4883   { return mips_output_move (operands[0], operands[1]); }
4884   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4885    (set (attr "mode")
4886         (if_then_else (eq_attr "move_type" "imul")
4887                       (const_string "SI")
4888                       (const_string "DI")))])
4890 (define_insn "*movdi_32bit_mips16"
4891   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4892         (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4893   "!TARGET_64BIT && TARGET_MIPS16
4894    && (register_operand (operands[0], DImode)
4895        || register_operand (operands[1], DImode))"
4896   { return mips_output_move (operands[0], operands[1]); }
4897   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4898    (set_attr "mode" "DI")])
4900 (define_insn "*movdi_64bit"
4901   [(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")
4902         (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"))]
4903   "TARGET_64BIT && !TARGET_MIPS16
4904    && (register_operand (operands[0], DImode)
4905        || reg_or_0_operand (operands[1], DImode))"
4906   { return mips_output_move (operands[0], operands[1]); }
4907   [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4908    (set_attr "mode" "DI")])
4910 (define_insn "*movdi_64bit_mips16"
4911   [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4912         (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4913   "TARGET_64BIT && TARGET_MIPS16
4914    && (register_operand (operands[0], DImode)
4915        || register_operand (operands[1], DImode))"
4916   { return mips_output_move (operands[0], operands[1]); }
4917   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4918    (set_attr "mode" "DI")])
4920 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4921 ;; when the original load is a 4 byte instruction but the add and the
4922 ;; load are 2 2 byte instructions.
4924 (define_split
4925   [(set (match_operand:DI 0 "d_operand")
4926         (mem:DI (plus:DI (match_dup 0)
4927                          (match_operand:DI 1 "const_int_operand"))))]
4928   "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4929    && !TARGET_DEBUG_D_MODE
4930    && ((INTVAL (operands[1]) < 0
4931         && INTVAL (operands[1]) >= -0x10)
4932        || (INTVAL (operands[1]) >= 32 * 8
4933            && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4934        || (INTVAL (operands[1]) >= 0
4935            && INTVAL (operands[1]) < 32 * 8
4936            && (INTVAL (operands[1]) & 7) != 0))"
4937   [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4938    (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4940   HOST_WIDE_INT val = INTVAL (operands[1]);
4942   if (val < 0)
4943     operands[2] = const0_rtx;
4944   else if (val >= 32 * 8)
4945     {
4946       int off = val & 7;
4948       operands[1] = GEN_INT (0x8 + off);
4949       operands[2] = GEN_INT (val - off - 0x8);
4950     }
4951   else
4952     {
4953       int off = val & 7;
4955       operands[1] = GEN_INT (off);
4956       operands[2] = GEN_INT (val - off);
4957     }
4960 ;; 32-bit Integer moves
4962 ;; Unlike most other insns, the move insns can't be split with
4963 ;; different predicates, because register spilling and other parts of
4964 ;; the compiler, have memoized the insn number already.
4966 (define_expand "mov<mode>"
4967   [(set (match_operand:IMOVE32 0 "")
4968         (match_operand:IMOVE32 1 ""))]
4969   ""
4971   if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4972     DONE;
4975 ;; The difference between these two is whether or not ints are allowed
4976 ;; in FP registers (off by default, use -mdebugh to enable).
4978 (define_insn "*mov<mode>_internal"
4979   [(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")
4980         (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"))]
4981   "!TARGET_MIPS16
4982    && (register_operand (operands[0], <MODE>mode)
4983        || reg_or_0_operand (operands[1], <MODE>mode))"
4984   { return mips_output_move (operands[0], operands[1]); }
4985   [(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")
4986    (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4987    (set_attr "mode" "SI")])
4989 (define_insn "*mov<mode>_mips16"
4990   [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4991         (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4992   "TARGET_MIPS16
4993    && (register_operand (operands[0], <MODE>mode)
4994        || register_operand (operands[1], <MODE>mode))"
4995   { return mips_output_move (operands[0], operands[1]); }
4996   [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4997    (set_attr "mode" "SI")])
4999 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
5000 ;; when the original load is a 4 byte instruction but the add and the
5001 ;; load are 2 2 byte instructions.
5003 (define_split
5004   [(set (match_operand:SI 0 "d_operand")
5005         (mem:SI (plus:SI (match_dup 0)
5006                          (match_operand:SI 1 "const_int_operand"))))]
5007   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5008    && ((INTVAL (operands[1]) < 0
5009         && INTVAL (operands[1]) >= -0x80)
5010        || (INTVAL (operands[1]) >= 32 * 4
5011            && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
5012        || (INTVAL (operands[1]) >= 0
5013            && INTVAL (operands[1]) < 32 * 4
5014            && (INTVAL (operands[1]) & 3) != 0))"
5015   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5016    (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
5018   HOST_WIDE_INT val = INTVAL (operands[1]);
5020   if (val < 0)
5021     operands[2] = const0_rtx;
5022   else if (val >= 32 * 4)
5023     {
5024       int off = val & 3;
5026       operands[1] = GEN_INT (0x7c + off);
5027       operands[2] = GEN_INT (val - off - 0x7c);
5028     }
5029   else
5030     {
5031       int off = val & 3;
5033       operands[1] = GEN_INT (off);
5034       operands[2] = GEN_INT (val - off);
5035     }
5038 ;; On the mips16, we can split a load of certain constants into a load
5039 ;; and an add.  This turns a 4 byte instruction into 2 2 byte
5040 ;; instructions.
5042 (define_split
5043   [(set (match_operand:SI 0 "d_operand")
5044         (match_operand:SI 1 "const_int_operand"))]
5045   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5046    && INTVAL (operands[1]) >= 0x100
5047    && INTVAL (operands[1]) <= 0xff + 0x7f"
5048   [(set (match_dup 0) (match_dup 1))
5049    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
5051   int val = INTVAL (operands[1]);
5053   operands[1] = GEN_INT (0xff);
5054   operands[2] = GEN_INT (val - 0xff);
5057 ;; MIPS4 supports loading and storing a floating point register from
5058 ;; the sum of two general registers.  We use two versions for each of
5059 ;; these four instructions: one where the two general registers are
5060 ;; SImode, and one where they are DImode.  This is because general
5061 ;; registers will be in SImode when they hold 32-bit values, but,
5062 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
5063 ;; instructions will still work correctly.
5065 ;; ??? Perhaps it would be better to support these instructions by
5066 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends.  However, since
5067 ;; these instructions can only be used to load and store floating
5068 ;; point registers, that would probably cause trouble in reload.
5070 (define_insn "*<ANYF:loadx>_<P:mode>"
5071   [(set (match_operand:ANYF 0 "register_operand" "=f")
5072         (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
5073                           (match_operand:P 2 "register_operand" "d"))))]
5074   "ISA_HAS_LXC1_SXC1"
5075   "<ANYF:loadx>\t%0,%1(%2)"
5076   [(set_attr "type" "fpidxload")
5077    (set_attr "mode" "<ANYF:UNITMODE>")])
5079 (define_insn "*<ANYF:storex>_<P:mode>"
5080   [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
5081                           (match_operand:P 2 "register_operand" "d")))
5082         (match_operand:ANYF 0 "register_operand" "f"))]
5083   "ISA_HAS_LXC1_SXC1"
5084   "<ANYF:storex>\t%0,%1(%2)"
5085   [(set_attr "type" "fpidxstore")
5086    (set_attr "mode" "<ANYF:UNITMODE>")])
5088 ;; Scaled indexed address load.
5089 ;; Per md.texi, we only need to look for a pattern with multiply in the
5090 ;; address expression, not shift.
5092 (define_insn "*lwxs"
5093   [(set (match_operand:IMOVE32 0 "register_operand" "=d")
5094         (mem:IMOVE32
5095           (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
5096                           (const_int 4))
5097                   (match_operand:P 2 "register_operand" "d"))))]
5098   "ISA_HAS_LWXS"
5099   "lwxs\t%0,%1(%2)"
5100   [(set_attr "type"     "load")
5101    (set_attr "mode"     "SI")])
5103 ;; 16-bit Integer moves
5105 ;; Unlike most other insns, the move insns can't be split with
5106 ;; different predicates, because register spilling and other parts of
5107 ;; the compiler, have memoized the insn number already.
5108 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
5110 (define_expand "movhi"
5111   [(set (match_operand:HI 0 "")
5112         (match_operand:HI 1 ""))]
5113   ""
5115   if (mips_legitimize_move (HImode, operands[0], operands[1]))
5116     DONE;
5119 (define_insn "*movhi_internal"
5120   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
5121         (match_operand:HI 1 "move_operand"         "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
5122   "!TARGET_MIPS16
5123    && (register_operand (operands[0], HImode)
5124        || reg_or_0_operand (operands[1], HImode))"
5125   { return mips_output_move (operands[0], operands[1]); }
5126   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
5127    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
5128    (set_attr "mode" "HI")])
5130 (define_insn "*movhi_mips16"
5131   [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5132         (match_operand:HI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
5133   "TARGET_MIPS16
5134    && (register_operand (operands[0], HImode)
5135        || register_operand (operands[1], HImode))"
5136   { return mips_output_move (operands[0], operands[1]); }
5137   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5138    (set_attr "mode" "HI")])
5140 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
5141 ;; when the original load is a 4 byte instruction but the add and the
5142 ;; load are 2 2 byte instructions.
5144 (define_split
5145   [(set (match_operand:HI 0 "d_operand")
5146         (mem:HI (plus:SI (match_dup 0)
5147                          (match_operand:SI 1 "const_int_operand"))))]
5148   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5149    && ((INTVAL (operands[1]) < 0
5150         && INTVAL (operands[1]) >= -0x80)
5151        || (INTVAL (operands[1]) >= 32 * 2
5152            && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
5153        || (INTVAL (operands[1]) >= 0
5154            && INTVAL (operands[1]) < 32 * 2
5155            && (INTVAL (operands[1]) & 1) != 0))"
5156   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5157    (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
5159   HOST_WIDE_INT val = INTVAL (operands[1]);
5161   if (val < 0)
5162     operands[2] = const0_rtx;
5163   else if (val >= 32 * 2)
5164     {
5165       int off = val & 1;
5167       operands[1] = GEN_INT (0x7e + off);
5168       operands[2] = GEN_INT (val - off - 0x7e);
5169     }
5170   else
5171     {
5172       int off = val & 1;
5174       operands[1] = GEN_INT (off);
5175       operands[2] = GEN_INT (val - off);
5176     }
5179 ;; 8-bit Integer moves
5181 ;; Unlike most other insns, the move insns can't be split with
5182 ;; different predicates, because register spilling and other parts of
5183 ;; the compiler, have memoized the insn number already.
5184 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
5186 (define_expand "movqi"
5187   [(set (match_operand:QI 0 "")
5188         (match_operand:QI 1 ""))]
5189   ""
5191   if (mips_legitimize_move (QImode, operands[0], operands[1]))
5192     DONE;
5195 (define_insn "*movqi_internal"
5196   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
5197         (match_operand:QI 1 "move_operand"         "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
5198   "!TARGET_MIPS16
5199    && (register_operand (operands[0], QImode)
5200        || reg_or_0_operand (operands[1], QImode))"
5201   { return mips_output_move (operands[0], operands[1]); }
5202   [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
5203    (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
5204    (set_attr "mode" "QI")])
5206 (define_insn "*movqi_mips16"
5207   [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5208         (match_operand:QI 1 "move_operand"         "d,d,y,K,N,m,d,*a"))]
5209   "TARGET_MIPS16
5210    && (register_operand (operands[0], QImode)
5211        || register_operand (operands[1], QImode))"
5212   { return mips_output_move (operands[0], operands[1]); }
5213   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5214    (set_attr "mode" "QI")])
5216 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
5217 ;; when the original load is a 4 byte instruction but the add and the
5218 ;; load are 2 2 byte instructions.
5220 (define_split
5221   [(set (match_operand:QI 0 "d_operand")
5222         (mem:QI (plus:SI (match_dup 0)
5223                          (match_operand:SI 1 "const_int_operand"))))]
5224   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5225    && ((INTVAL (operands[1]) < 0
5226         && INTVAL (operands[1]) >= -0x80)
5227        || (INTVAL (operands[1]) >= 32
5228            && INTVAL (operands[1]) <= 31 + 0x7f))"
5229   [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5230    (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
5232   HOST_WIDE_INT val = INTVAL (operands[1]);
5234   if (val < 0)
5235     operands[2] = const0_rtx;
5236   else
5237     {
5238       operands[1] = GEN_INT (0x7f);
5239       operands[2] = GEN_INT (val - 0x7f);
5240     }
5243 ;; 32-bit floating point moves
5245 (define_expand "movsf"
5246   [(set (match_operand:SF 0 "")
5247         (match_operand:SF 1 ""))]
5248   ""
5250   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
5251     DONE;
5254 (define_insn "movccf"
5255   [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
5256         (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
5257   "ISA_HAS_CCF"
5258   { return mips_output_move (operands[0], operands[1]); }
5259   [(set_attr "move_type" "fmove,fpload,fpstore")])
5261 (define_insn "*movsf_hardfloat"
5262   [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5263         (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
5264   "TARGET_HARD_FLOAT
5265    && (register_operand (operands[0], SFmode)
5266        || reg_or_0_operand (operands[1], SFmode))"
5267   { return mips_output_move (operands[0], operands[1]); }
5268   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5269    (set_attr "mode" "SF")])
5271 (define_insn "*movsf_softfloat"
5272   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
5273         (match_operand:SF 1 "move_operand" "Gd,m,d"))]
5274   "TARGET_SOFT_FLOAT && !TARGET_MIPS16
5275    && (register_operand (operands[0], SFmode)
5276        || reg_or_0_operand (operands[1], SFmode))"
5277   { return mips_output_move (operands[0], operands[1]); }
5278   [(set_attr "move_type" "move,load,store")
5279    (set_attr "mode" "SF")])
5281 (define_insn "*movsf_mips16"
5282   [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
5283         (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
5284   "TARGET_MIPS16
5285    && (register_operand (operands[0], SFmode)
5286        || register_operand (operands[1], SFmode))"
5287   { return mips_output_move (operands[0], operands[1]); }
5288   [(set_attr "move_type" "move,move,move,load,store")
5289    (set_attr "mode" "SF")])
5291 ;; 64-bit floating point moves
5293 (define_expand "movdf"
5294   [(set (match_operand:DF 0 "")
5295         (match_operand:DF 1 ""))]
5296   ""
5298   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
5299     DONE;
5302 (define_insn "*movdf_hardfloat"
5303   [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5304         (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
5305   "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
5306    && (register_operand (operands[0], DFmode)
5307        || reg_or_0_operand (operands[1], DFmode))"
5308   { return mips_output_move (operands[0], operands[1]); }
5309   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5310    (set_attr "mode" "DF")])
5312 (define_insn "*movdf_softfloat"
5313   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
5314         (match_operand:DF 1 "move_operand" "dG,m,dG"))]
5315   "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
5316    && (register_operand (operands[0], DFmode)
5317        || reg_or_0_operand (operands[1], DFmode))"
5318   { return mips_output_move (operands[0], operands[1]); }
5319   [(set_attr "move_type" "move,load,store")
5320    (set_attr "mode" "DF")])
5322 (define_insn "*movdf_mips16"
5323   [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
5324         (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
5325   "TARGET_MIPS16
5326    && (register_operand (operands[0], DFmode)
5327        || register_operand (operands[1], DFmode))"
5328   { return mips_output_move (operands[0], operands[1]); }
5329   [(set_attr "move_type" "move,move,move,load,store")
5330    (set_attr "mode" "DF")])
5332 ;; 128-bit integer moves
5334 (define_expand "movti"
5335   [(set (match_operand:TI 0)
5336         (match_operand:TI 1))]
5337   "TARGET_64BIT"
5339   if (mips_legitimize_move (TImode, operands[0], operands[1]))
5340     DONE;
5343 (define_insn "*movti"
5344   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
5345         (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
5346   "TARGET_64BIT
5347    && !TARGET_MIPS16
5348    && (register_operand (operands[0], TImode)
5349        || reg_or_0_operand (operands[1], TImode))"
5350   { return mips_output_move (operands[0], operands[1]); }
5351   [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
5352    (set (attr "mode")
5353         (if_then_else (eq_attr "move_type" "imul")
5354                       (const_string "SI")
5355                       (const_string "TI")))])
5357 (define_insn "*movti_mips16"
5358   [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5359         (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5360   "TARGET_64BIT
5361    && TARGET_MIPS16
5362    && (register_operand (operands[0], TImode)
5363        || register_operand (operands[1], TImode))"
5364   "#"
5365   [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5366    (set_attr "mode" "TI")])
5368 ;; 128-bit floating point moves
5370 (define_expand "movtf"
5371   [(set (match_operand:TF 0)
5372         (match_operand:TF 1))]
5373   "TARGET_64BIT"
5375   if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5376     DONE;
5379 ;; This pattern handles both hard- and soft-float cases.
5380 (define_insn "*movtf"
5381   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5382         (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5383   "TARGET_64BIT
5384    && !TARGET_MIPS16
5385    && (register_operand (operands[0], TFmode)
5386        || reg_or_0_operand (operands[1], TFmode))"
5387   "#"
5388   [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5389    (set_attr "mode" "TF")])
5391 (define_insn "*movtf_mips16"
5392   [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5393         (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5394   "TARGET_64BIT
5395    && TARGET_MIPS16
5396    && (register_operand (operands[0], TFmode)
5397        || register_operand (operands[1], TFmode))"
5398   "#"
5399   [(set_attr "move_type" "move,move,move,load,store")
5400    (set_attr "mode" "TF")])
5402 (define_split
5403   [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5404         (match_operand:MOVE64 1 "move_operand"))]
5405   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5406   [(const_int 0)]
5408   mips_split_move_insn (operands[0], operands[1], curr_insn);
5409   DONE;
5412 (define_split
5413   [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5414         (match_operand:MOVE128 1 "move_operand"))]
5415   "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5416   [(const_int 0)]
5418   mips_split_move_insn (operands[0], operands[1], curr_insn);
5419   DONE;
5422 ;; When generating mips16 code, split moves of negative constants into
5423 ;; a positive "li" followed by a negation.
5424 (define_split
5425   [(set (match_operand 0 "d_operand")
5426         (match_operand 1 "const_int_operand"))]
5427   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5428   [(set (match_dup 2)
5429         (match_dup 3))
5430    (set (match_dup 2)
5431         (neg:SI (match_dup 2)))]
5433   operands[2] = gen_lowpart (SImode, operands[0]);
5434   operands[3] = GEN_INT (-INTVAL (operands[1]));
5437 ;; 64-bit paired-single floating point moves
5439 (define_expand "movv2sf"
5440   [(set (match_operand:V2SF 0)
5441         (match_operand:V2SF 1))]
5442   "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5444   if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5445     DONE;
5448 (define_insn "*movv2sf"
5449   [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5450         (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5451   "TARGET_HARD_FLOAT
5452    && TARGET_PAIRED_SINGLE_FLOAT
5453    && (register_operand (operands[0], V2SFmode)
5454        || reg_or_0_operand (operands[1], V2SFmode))"
5455   { return mips_output_move (operands[0], operands[1]); }
5456   [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5457    (set_attr "mode" "DF")])
5459 ;; Extract the high part of a HI/LO value.  See mips_hard_regno_mode_ok_p
5460 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5462 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5463 ;; instead of MFHI.  This avoids both the normal MIPS III hi/lo hazards
5464 ;; and the errata related to -mfix-vr4130.
5465 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5466   [(set (match_operand:GPR 0 "register_operand" "=d")
5467         (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5468                     UNSPEC_MFHI))]
5469   ""
5470   { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5471   [(set_attr "type" "mfhi")
5472    (set_attr "mode" "<GPR:MODE>")])
5474 ;; Set the high part of a HI/LO value, given that the low part has
5475 ;; already been set.  See mips_hard_regno_mode_ok_p for the reason
5476 ;; why we can't just use (reg:GPR HI_REGNUM).
5477 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5478   [(set (match_operand:HILO 0 "register_operand" "=x")
5479         (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5480                       (match_operand:GPR 2 "register_operand" "l")]
5481                      UNSPEC_MTHI))]
5482   ""
5483   "mthi\t%z1"
5484   [(set_attr "type" "mthi")
5485    (set_attr "mode" "SI")])
5487 ;; Emit a doubleword move in which exactly one of the operands is
5488 ;; a floating-point register.  We can't just emit two normal moves
5489 ;; because of the constraints imposed by the FPU register model;
5490 ;; see mips_cannot_change_mode_class for details.  Instead, we keep
5491 ;; the FPR whole and use special patterns to refer to each word of
5492 ;; the other operand.
5494 (define_expand "move_doubleword_fpr<mode>"
5495   [(set (match_operand:SPLITF 0)
5496         (match_operand:SPLITF 1))]
5497   ""
5499   if (FP_REG_RTX_P (operands[0]))
5500     {
5501       rtx low = mips_subword (operands[1], 0);
5502       rtx high = mips_subword (operands[1], 1);
5503       emit_insn (gen_load_low<mode> (operands[0], low));
5504       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5505         emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5506       else
5507         emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5508     }
5509   else
5510     {
5511       rtx low = mips_subword (operands[0], 0);
5512       rtx high = mips_subword (operands[0], 1);
5513       emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5514       if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5515         emit_insn (gen_mfhc1<mode> (high, operands[1]));
5516       else
5517         emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5518     }
5519   DONE;
5522 ;; Load the low word of operand 0 with operand 1.
5523 (define_insn "load_low<mode>"
5524   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5525         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5526                        UNSPEC_LOAD_LOW))]
5527   "TARGET_HARD_FLOAT"
5529   operands[0] = mips_subword (operands[0], 0);
5530   return mips_output_move (operands[0], operands[1]);
5532   [(set_attr "move_type" "mtc,fpload")
5533    (set_attr "mode" "<HALFMODE>")])
5535 ;; Load the high word of operand 0 from operand 1, preserving the value
5536 ;; in the low word.
5537 (define_insn "load_high<mode>"
5538   [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5539         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5540                         (match_operand:SPLITF 2 "register_operand" "0,0")]
5541                        UNSPEC_LOAD_HIGH))]
5542   "TARGET_HARD_FLOAT"
5544   operands[0] = mips_subword (operands[0], 1);
5545   return mips_output_move (operands[0], operands[1]);
5547   [(set_attr "move_type" "mtc,fpload")
5548    (set_attr "mode" "<HALFMODE>")])
5550 ;; Store one word of operand 1 in operand 0.  Operand 2 is 1 to store the
5551 ;; high word and 0 to store the low word.
5552 (define_insn "store_word<mode>"
5553   [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5554         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5555                             (match_operand 2 "const_int_operand")]
5556                            UNSPEC_STORE_WORD))]
5557   "TARGET_HARD_FLOAT"
5559   operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5560   return mips_output_move (operands[0], operands[1]);
5562   [(set_attr "move_type" "mfc,fpstore")
5563    (set_attr "mode" "<HALFMODE>")])
5565 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5566 ;; value in the low word.
5567 (define_insn "mthc1<mode>"
5568   [(set (match_operand:SPLITF 0 "register_operand" "=f")
5569         (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5570                         (match_operand:SPLITF 2 "register_operand" "0")]
5571                        UNSPEC_MTHC1))]
5572   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5573   "mthc1\t%z1,%0"
5574   [(set_attr "move_type" "mtc")
5575    (set_attr "mode" "<HALFMODE>")])
5577 ;; Move high word of operand 1 to operand 0 using mfhc1.
5578 (define_insn "mfhc1<mode>"
5579   [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5580         (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5581                             UNSPEC_MFHC1))]
5582   "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5583   "mfhc1\t%0,%1"
5584   [(set_attr "move_type" "mfc")
5585    (set_attr "mode" "<HALFMODE>")])
5587 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5588 (define_expand "load_const_gp_<mode>"
5589   [(set (match_operand:P 0 "register_operand" "=d")
5590         (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5592 ;; Insn to initialize $gp for n32/n64 abicalls.  Operand 0 is the offset
5593 ;; of _gp from the start of this function.  Operand 1 is the incoming
5594 ;; function address.
5595 (define_insn_and_split "loadgp_newabi_<mode>"
5596   [(set (match_operand:P 0 "register_operand" "=&d")
5597         (unspec:P [(match_operand:P 1)
5598                    (match_operand:P 2 "register_operand" "d")]
5599                   UNSPEC_LOADGP))]
5600   "mips_current_loadgp_style () == LOADGP_NEWABI"
5601   { return mips_must_initialize_gp_p () ? "#" : ""; }
5602   "&& mips_must_initialize_gp_p ()"
5603   [(set (match_dup 0) (match_dup 3))
5604    (set (match_dup 0) (match_dup 4))
5605    (set (match_dup 0) (match_dup 5))]
5607   operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5608   operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5609   operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5611   [(set_attr "type" "ghost")])
5613 ;; Likewise, for -mno-shared code.  Operand 0 is the __gnu_local_gp symbol.
5614 (define_insn_and_split "loadgp_absolute_<mode>"
5615   [(set (match_operand:P 0 "register_operand" "=d")
5616         (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5617   "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5618   { return mips_must_initialize_gp_p () ? "#" : ""; }
5619   "&& mips_must_initialize_gp_p ()"
5620   [(const_int 0)]
5622   mips_emit_move (operands[0], operands[1]);
5623   DONE;
5625   [(set_attr "type" "ghost")])
5627 ;; This blockage instruction prevents the gp load from being
5628 ;; scheduled after an implicit use of gp.  It also prevents
5629 ;; the load from being deleted as dead.
5630 (define_insn "loadgp_blockage"
5631   [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5632   ""
5633   ""
5634   [(set_attr "type" "ghost")])
5636 ;; Initialize $gp for RTP PIC.  Operand 0 is the __GOTT_BASE__ symbol
5637 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5638 (define_insn_and_split "loadgp_rtp_<mode>"
5639   [(set (match_operand:P 0 "register_operand" "=d")
5640         (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5641                    (match_operand:P 2 "symbol_ref_operand")]
5642                   UNSPEC_LOADGP))]
5643   "mips_current_loadgp_style () == LOADGP_RTP"
5644   { return mips_must_initialize_gp_p () ? "#" : ""; }
5645   "&& mips_must_initialize_gp_p ()"
5646   [(set (match_dup 0) (high:P (match_dup 3)))
5647    (set (match_dup 0) (unspec:P [(match_dup 0)
5648                                  (match_dup 3)] UNSPEC_LOAD_GOT))
5649    (set (match_dup 0) (unspec:P [(match_dup 0)
5650                                  (match_dup 4)] UNSPEC_LOAD_GOT))]
5652   operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5653   operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5655   [(set_attr "type" "ghost")])
5657 ;; Initialize the global pointer for MIPS16 code.  Operand 0 is the
5658 ;; global pointer and operand 1 is the MIPS16 register that holds
5659 ;; the required value.
5660 (define_insn_and_split "copygp_mips16_<mode>"
5661   [(set (match_operand:P 0 "register_operand" "=y")
5662         (unspec:P [(match_operand:P 1 "register_operand" "d")]
5663                   UNSPEC_COPYGP))]
5664   "TARGET_MIPS16"
5665   { return mips_must_initialize_gp_p () ? "#" : ""; }
5666   "&& mips_must_initialize_gp_p ()"
5667   [(set (match_dup 0) (match_dup 1))]
5668   ""
5669   [(set_attr "type" "ghost")])
5671 ;; A placeholder for where the cprestore instruction should go,
5672 ;; if we decide we need one.  Operand 0 and operand 1 are as for
5673 ;; "cprestore".  Operand 2 is a register that holds the gp value.
5675 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5676 ;; otherwise any register that holds the correct value will do.
5677 (define_insn_and_split "potential_cprestore_<mode>"
5678   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5679         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5680                    (match_operand:P 2 "register_operand" "d,d")]
5681                   UNSPEC_POTENTIAL_CPRESTORE))
5682    (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5683   "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5684   { return mips_must_initialize_gp_p () ? "#" : ""; }
5685   "mips_must_initialize_gp_p ()"
5686   [(const_int 0)]
5688   mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5689                                   operands[2], operands[3]);
5690   DONE;
5692   [(set_attr "type" "ghost")])
5694 ;; Emit a .cprestore directive, which normally expands to a single store
5695 ;; instruction.  Operand 0 is a (possibly illegitimate) sp-based MEM
5696 ;; for the cprestore slot.  Operand 1 is the offset of the slot from
5697 ;; the stack pointer.  (This is redundant with operand 0, but it makes
5698 ;; things a little simpler.)
5699 (define_insn "cprestore_<mode>"
5700   [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5701         (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5702                    (reg:P 28)]
5703                   UNSPEC_CPRESTORE))]
5704   "TARGET_CPRESTORE_DIRECTIVE"
5706   if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5707     return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5708   else
5709     return ".cprestore\t%1";
5711   [(set_attr "type" "store")
5712    (set_attr "insn_count" "1,3")])
5714 (define_insn "use_cprestore_<mode>"
5715   [(set (reg:P CPRESTORE_SLOT_REGNUM)
5716         (match_operand:P 0 "cprestore_load_slot_operand"))]
5717   ""
5718   ""
5719   [(set_attr "type" "ghost")])
5721 ;; Expand in-line code to clear the instruction cache between operand[0] and
5722 ;; operand[1].
5723 (define_expand "clear_cache"
5724   [(match_operand 0 "pmode_register_operand")
5725    (match_operand 1 "pmode_register_operand")]
5726   ""
5727   "
5729   if (TARGET_SYNCI)
5730     {
5731       mips_expand_synci_loop (operands[0], operands[1]);
5732       emit_insn (gen_sync ());
5733       emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5734     }
5735   else if (mips_cache_flush_func && mips_cache_flush_func[0])
5736     {
5737       rtx len = gen_reg_rtx (Pmode);
5738       emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5739       MIPS_ICACHE_SYNC (operands[0], len);
5740     }
5741   DONE;
5744 (define_insn "sync"
5745   [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5746   "GENERATE_SYNC"
5747   { return mips_output_sync (); })
5749 (define_insn "synci"
5750   [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5751                     UNSPEC_SYNCI)]
5752   "TARGET_SYNCI"
5753   "synci\t0(%0)")
5755 (define_insn "rdhwr_synci_step_<mode>"
5756   [(set (match_operand:P 0 "register_operand" "=d")
5757         (unspec_volatile:P [(const_int 1)]
5758         UNSPEC_RDHWR))]
5759   "ISA_HAS_SYNCI"
5760   "rdhwr\t%0,$1")
5762 (define_insn "clear_hazard_<mode>"
5763   [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5764    (clobber (reg:P RETURN_ADDR_REGNUM))]
5765   "ISA_HAS_SYNCI"
5767   return "%(%<bal\t1f\n"
5768          "\tnop\n"
5769          "1:\t<d>addiu\t$31,$31,12\n"
5770          "\tjr.hb\t$31\n"
5771          "\tnop%>%)";
5773   [(set_attr "insn_count" "5")])
5775 ;; Cache operations for R4000-style caches.
5776 (define_insn "mips_cache"
5777   [(set (mem:BLK (scratch))
5778         (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5779                      (match_operand:QI 1 "address_operand" "ZD")]
5780                     UNSPEC_MIPS_CACHE))]
5781   "ISA_HAS_CACHE"
5782   "cache\t%X0,%a1"
5783   [(set_attr "extended_mips16" "yes")])
5785 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5786 ;; operation.  We keep the pattern distinct so that we can identify
5787 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5788 ;; the operation is never inserted into a delay slot.
5789 (define_insn "r10k_cache_barrier"
5790   [(set (mem:BLK (scratch))
5791         (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5792   "ISA_HAS_CACHE"
5793   "cache\t0x14,0(%$)"
5794   [(set_attr "can_delay" "no")])
5796 ;; Block moves, see mips.cc for more details.
5797 ;; Argument 0 is the destination
5798 ;; Argument 1 is the source
5799 ;; Argument 2 is the length
5800 ;; Argument 3 is the alignment
5802 (define_expand "cpymemsi"
5803   [(parallel [(set (match_operand:BLK 0 "general_operand")
5804                    (match_operand:BLK 1 "general_operand"))
5805               (use (match_operand:SI 2 ""))
5806               (use (match_operand:SI 3 "const_int_operand"))])]
5807   "!TARGET_MIPS16 && !TARGET_MEMCPY"
5809   if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5810     DONE;
5811   else
5812     FAIL;
5816 ;;  ....................
5818 ;;      SHIFTS
5820 ;;  ....................
5822 (define_expand "<optab><mode>3"
5823   [(set (match_operand:GPR 0 "register_operand")
5824         (any_shift:GPR (match_operand:GPR 1 "register_operand")
5825                        (match_operand:SI 2 "arith_operand")))]
5826   ""
5828   /* On the mips16, a shift of more than 8 is a four byte instruction,
5829      so, for a shift between 8 and 16, it is just as fast to do two
5830      shifts of 8 or less.  If there is a lot of shifting going on, we
5831      may win in CSE.  Otherwise combine will put the shifts back
5832      together again.  This can be called by mips_function_arg, so we must
5833      be careful not to allocate a new register if we've reached the
5834      reload pass.  */
5835   if (TARGET_MIPS16
5836       && optimize
5837       && CONST_INT_P (operands[2])
5838       && INTVAL (operands[2]) > 8
5839       && INTVAL (operands[2]) <= 16
5840       && !reload_in_progress
5841       && !reload_completed)
5842     {
5843       rtx temp = gen_reg_rtx (<MODE>mode);
5845       emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5846       emit_insn (gen_<optab><mode>3 (operands[0], temp,
5847                                      GEN_INT (INTVAL (operands[2]) - 8)));
5848       DONE;
5849     }
5852 (define_insn "*<optab><mode>3"
5853   [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5854         (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5855                        (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5856   "!TARGET_MIPS16"
5858   if (CONST_INT_P (operands[2]))
5859     operands[2] = GEN_INT (INTVAL (operands[2])
5860                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5862   return "<d><insn>\t%0,%1,%2";
5864   [(set_attr "type" "shift")
5865    (set_attr "compression" "<shift_compression>,none")
5866    (set_attr "mode" "<MODE>")])
5868 (define_insn "*<optab>si3_extend"
5869   [(set (match_operand:DI 0 "register_operand" "=d")
5870         (sign_extend:DI
5871            (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5872                          (match_operand:SI 2 "arith_operand" "dI"))))]
5873   "TARGET_64BIT && !TARGET_MIPS16"
5875   if (CONST_INT_P (operands[2]))
5876     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5878   return "<insn>\t%0,%1,%2";
5880   [(set_attr "type" "shift")
5881    (set_attr "mode" "SI")])
5883 (define_insn "*<optab>si3_mips16"
5884   [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5885         (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5886                       (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5887   "TARGET_MIPS16"
5889   if (which_alternative == 0)
5890     return "<insn>\t%0,%2";
5892   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5893   return "<insn>\t%0,%1,%2";
5895   [(set_attr "type" "shift")
5896    (set_attr "mode" "SI")
5897    (set_attr "extended_mips16" "no,no,yes")])
5899 (define_insn "<GPR:d>lsa"
5900  [(set (match_operand:GPR 0 "register_operand" "=d")
5901        (plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
5902                              (match_operand 2 "const_immlsa_operand" ""))
5903                 (match_operand:GPR 3 "register_operand" "d")))]
5904  "ISA_HAS_<GPR:D>LSA"
5905  "<GPR:d>lsa\t%0,%1,%3,%2"
5906  [(set_attr "type" "arith")
5907   (set_attr "mode" "<GPR:MODE>")])
5909 ;; We need separate DImode MIPS16 patterns because of the irregularity
5910 ;; of right shifts.
5911 (define_insn "*ashldi3_mips16"
5912   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5913         (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5914                    (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5915   "TARGET_64BIT && TARGET_MIPS16"
5917   if (which_alternative == 0)
5918     return "dsll\t%0,%2";
5920   operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5921   return "dsll\t%0,%1,%2";
5923   [(set_attr "type" "shift")
5924    (set_attr "mode" "DI")
5925    (set_attr "extended_mips16" "no,no,yes")])
5927 (define_insn "*ashrdi3_mips16"
5928   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5929         (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5930                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5931   "TARGET_64BIT && TARGET_MIPS16"
5933   if (CONST_INT_P (operands[2]))
5934     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5936   return "dsra\t%0,%2";
5938   [(set_attr "type" "shift")
5939    (set_attr "mode" "DI")
5940    (set_attr "extended_mips16" "no,no,yes")])
5942 (define_insn "*lshrdi3_mips16"
5943   [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5944         (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5945                      (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5946   "TARGET_64BIT && TARGET_MIPS16"
5948   if (CONST_INT_P (operands[2]))
5949     operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5951   return "dsrl\t%0,%2";
5953   [(set_attr "type" "shift")
5954    (set_attr "mode" "DI")
5955    (set_attr "extended_mips16" "no,no,yes")])
5957 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5959 (define_split
5960   [(set (match_operand:GPR 0 "d_operand")
5961         (any_shift:GPR (match_operand:GPR 1 "d_operand")
5962                        (match_operand:GPR 2 "const_int_operand")))]
5963   "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5964    && INTVAL (operands[2]) > 8
5965    && INTVAL (operands[2]) <= 16"
5966   [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5967    (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5968   { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5970 ;; If we load a byte on the mips16 as a bitfield, the resulting
5971 ;; sequence of instructions is too complicated for combine, because it
5972 ;; involves four instructions: a load, a shift, a constant load into a
5973 ;; register, and an and (the key problem here is that the mips16 does
5974 ;; not have and immediate).  We recognize a shift of a load in order
5975 ;; to make it simple enough for combine to understand.
5977 ;; The instruction count here is the worst case.
5978 (define_insn_and_split ""
5979   [(set (match_operand:SI 0 "register_operand" "=d")
5980         (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5981                      (match_operand:SI 2 "immediate_operand" "I")))]
5982   "TARGET_MIPS16"
5983   "#"
5984   "&& 1"
5985   [(set (match_dup 0) (match_dup 1))
5986    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5987   ""
5988   [(set_attr "type"     "load")
5989    (set_attr "mode"     "SI")
5990    (set (attr "insn_count")
5991         (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5993 (define_insn "rotr<mode>3"
5994   [(set (match_operand:GPR 0 "register_operand" "=d")
5995         (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5996                       (match_operand:SI 2 "arith_operand" "dI")))]
5997   "ISA_HAS_ROR"
5999   if (CONST_INT_P (operands[2]))
6000     operands[2] = GEN_INT (INTVAL (operands[2])
6001                            & (GET_MODE_BITSIZE (<MODE>mode) - 1));
6003   return "<d>ror\t%0,%1,%2";
6005   [(set_attr "type" "shift")
6006    (set_attr "mode" "<MODE>")])
6008 (define_insn "bswaphi2"
6009   [(set (match_operand:HI 0 "register_operand" "=d")
6010         (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
6011   "ISA_HAS_WSBH"
6012   "wsbh\t%0,%1"
6013   [(set_attr "type" "shift")])
6015 (define_insn_and_split "bswapsi2"
6016   [(set (match_operand:SI 0 "register_operand" "=d")
6017         (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
6018   "ISA_HAS_WSBH && ISA_HAS_ROR"
6019   "#"
6020   "&& 1"
6021   [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
6022    (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
6023   ""
6024   [(set_attr "insn_count" "2")])
6026 (define_insn_and_split "bswapdi2"
6027   [(set (match_operand:DI 0 "register_operand" "=d")
6028         (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
6029   "TARGET_64BIT && ISA_HAS_WSBH"
6030   "#"
6031   "&& 1"
6032   [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
6033    (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
6034   ""
6035   [(set_attr "insn_count" "2")])
6037 (define_insn "wsbh"
6038   [(set (match_operand:SI 0 "register_operand" "=d")
6039         (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
6040   "ISA_HAS_WSBH"
6041   "wsbh\t%0,%1"
6042   [(set_attr "type" "shift")])
6044 (define_insn "dsbh"
6045   [(set (match_operand:DI 0 "register_operand" "=d")
6046         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
6047   "TARGET_64BIT && ISA_HAS_WSBH"
6048   "dsbh\t%0,%1"
6049   [(set_attr "type" "shift")])
6051 (define_insn "dshd"
6052   [(set (match_operand:DI 0 "register_operand" "=d")
6053         (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
6054   "TARGET_64BIT && ISA_HAS_WSBH"
6055   "dshd\t%0,%1"
6056   [(set_attr "type" "shift")])
6059 ;;  ....................
6061 ;;      CONDITIONAL BRANCHES
6063 ;;  ....................
6065 ;; Conditional branches on floating-point equality tests.
6067 (define_insn "*branch_fp_<mode>"
6068   [(set (pc)
6069         (if_then_else
6070          (match_operator 1 "equality_operator"
6071                          [(match_operand:FPCC 2 "register_operand" "<reg>")
6072                           (const_int 0)])
6073          (label_ref (match_operand 0 "" ""))
6074          (pc)))]
6075   "TARGET_HARD_FLOAT"
6077   return mips_output_conditional_branch (insn, operands,
6078                                          MIPS_BRANCH ("b%F1", "%Z2%0"),
6079                                          MIPS_BRANCH ("b%W1", "%Z2%0"));
6081   [(set_attr "type" "branch")])
6083 (define_insn "*branch_fp_inverted_<mode>"
6084   [(set (pc)
6085         (if_then_else
6086          (match_operator 1 "equality_operator"
6087                          [(match_operand:FPCC 2 "register_operand" "<reg>")
6088                           (const_int 0)])
6089          (pc)
6090          (label_ref (match_operand 0 "" ""))))]
6091   "TARGET_HARD_FLOAT"
6093   return mips_output_conditional_branch (insn, operands,
6094                                          MIPS_BRANCH ("b%W1", "%Z2%0"),
6095                                          MIPS_BRANCH ("b%F1", "%Z2%0"));
6097   [(set_attr "type" "branch")])
6099 ;; Conditional branches on ordered comparisons with zero.
6101 (define_insn "*branch_order<mode>"
6102   [(set (pc)
6103         (if_then_else
6104          (match_operator 1 "order_operator"
6105                          [(match_operand:GPR 2 "register_operand" "d,d")
6106                           (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
6107          (label_ref (match_operand 0 "" ""))
6108          (pc)))]
6109   "!TARGET_MIPS16"
6110   { return mips_output_order_conditional_branch (insn, operands, false); }
6111   [(set_attr "type" "branch")
6112    (set_attr "compact_form" "maybe,always")
6113    (set_attr "hazard" "forbidden_slot")])
6115 (define_insn "*branch_order<mode>_inverted"
6116   [(set (pc)
6117         (if_then_else
6118          (match_operator 1 "order_operator"
6119                          [(match_operand:GPR 2 "register_operand" "d,d")
6120                           (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
6121          (pc)
6122          (label_ref (match_operand 0 "" ""))))]
6123   "!TARGET_MIPS16"
6124   { return mips_output_order_conditional_branch (insn, operands, true); }
6125   [(set_attr "type" "branch")
6126    (set_attr "compact_form" "maybe,always")
6127    (set_attr "hazard" "forbidden_slot")])
6129 ;; Conditional branch on equality comparison.
6131 (define_insn "*branch_equality<mode>"
6132   [(set (pc)
6133         (if_then_else
6134          (match_operator 1 "equality_operator"
6135                          [(match_operand:GPR 2 "register_operand" "d")
6136                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
6137          (label_ref (match_operand 0 "" ""))
6138          (pc)))]
6139   "!TARGET_MIPS16"
6140   { return mips_output_equal_conditional_branch (insn, operands, false); }
6141   [(set_attr "type" "branch")
6142    (set_attr "compact_form" "maybe")
6143    (set_attr "hazard" "forbidden_slot")])
6145 (define_insn "*branch_equality<mode>_inverted"
6146   [(set (pc)
6147         (if_then_else
6148          (match_operator 1 "equality_operator"
6149                          [(match_operand:GPR 2 "register_operand" "d")
6150                           (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
6151          (pc)
6152          (label_ref (match_operand 0 "" ""))))]
6153   "!TARGET_MIPS16"
6154   { return mips_output_equal_conditional_branch (insn, operands, true); }
6155   [(set_attr "type" "branch")
6156    (set_attr "compact_form" "maybe")
6157    (set_attr "hazard" "forbidden_slot")])
6159 ;; MIPS16 branches
6161 (define_insn "*branch_equality<mode>_mips16"
6162   [(set (pc)
6163         (if_then_else
6164          (match_operator 1 "equality_operator"
6165                          [(match_operand:GPR 2 "register_operand" "d,t")
6166                           (const_int 0)])
6167          (label_ref (match_operand 0 "" ""))
6168          (pc)))]
6169   "TARGET_MIPS16"
6170   "@
6171    b%C1z\t%2,%0
6172    bt%C1z\t%0"
6173   [(set_attr "type" "branch")])
6175 (define_insn "*branch_equality<mode>_mips16_inverted"
6176   [(set (pc)
6177         (if_then_else
6178          (match_operator 1 "equality_operator"
6179                          [(match_operand:GPR 2 "register_operand" "d,t")
6180                           (const_int 0)])
6181          (pc)
6182          (label_ref (match_operand 0 "" ""))))]
6183   "TARGET_MIPS16"
6184   "@
6185    b%N1z\t%2,%0
6186    bt%N1z\t%0"
6187   [(set_attr "type" "branch")])
6189 (define_expand "cbranch<mode>4"
6190   [(set (pc)
6191         (if_then_else (match_operator 0 "comparison_operator"
6192                        [(match_operand:GPR 1 "register_operand")
6193                         (match_operand:GPR 2 "nonmemory_operand")])
6194                       (label_ref (match_operand 3 ""))
6195                       (pc)))]
6196   ""
6198   mips_expand_conditional_branch (operands);
6199   DONE;
6202 (define_expand "cbranch<mode>4"
6203   [(set (pc)
6204         (if_then_else (match_operator 0 "comparison_operator"
6205                        [(match_operand:SCALARF 1 "register_operand")
6206                         (match_operand:SCALARF 2 "register_operand")])
6207                       (label_ref (match_operand 3 ""))
6208                       (pc)))]
6209   ""
6211   mips_expand_conditional_branch (operands);
6212   DONE;
6215 ;; Used to implement built-in functions.
6216 (define_expand "condjump"
6217   [(set (pc)
6218         (if_then_else (match_operand 0)
6219                       (label_ref (match_operand 1))
6220                       (pc)))])
6222 ;; Branch if bit is set/clear.
6224 (define_insn "*branch_bit<bbv><mode>"
6225   [(set (pc)
6226         (if_then_else
6227          (equality_op (zero_extract:GPR
6228                        (match_operand:GPR 1 "register_operand" "d")
6229                        (const_int 1)
6230                        (match_operand 2 "const_int_operand" ""))
6231                       (const_int 0))
6232          (label_ref (match_operand 0 ""))
6233          (pc)))]
6234   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6236   return
6237     mips_output_conditional_branch (insn, operands,
6238                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
6239                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
6241   [(set_attr "type"          "branch")
6242    (set_attr "branch_likely" "no")])
6244 (define_insn "*branch_bit<bbv><mode>_inverted"
6245   [(set (pc)
6246         (if_then_else
6247          (equality_op (zero_extract:GPR
6248                        (match_operand:GPR 1 "register_operand" "d")
6249                        (const_int 1)
6250                        (match_operand 2 "const_int_operand" ""))
6251                       (const_int 0))
6252          (pc)
6253          (label_ref (match_operand 0 ""))))]
6254   "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6256   return
6257     mips_output_conditional_branch (insn, operands,
6258                                     MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
6259                                     MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
6261   [(set_attr "type"          "branch")
6262    (set_attr "branch_likely" "no")])
6265 ;;  ....................
6267 ;;      SETTING A REGISTER FROM A COMPARISON
6269 ;;  ....................
6271 ;; Destination is always set in SI mode.
6273 (define_expand "cstore<mode>4"
6274   [(set (match_operand:SI 0 "register_operand")
6275         (match_operator:SI 1 "mips_cstore_operator"
6276          [(match_operand:GPR 2 "register_operand")
6277           (match_operand:GPR 3 "nonmemory_operand")]))]
6278   ""
6280   mips_expand_scc (operands);
6281   DONE;
6284 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
6285   [(set (match_operand:GPR2 0 "register_operand" "=d")
6286         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6287                  (const_int 0)))]
6288   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6289   "sltu\t%0,%1,1"
6290   [(set_attr "type" "slt")
6291    (set_attr "mode" "<GPR:MODE>")])
6293 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
6294   [(set (match_operand:GPR2 0 "register_operand" "=t")
6295         (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6296                  (const_int 0)))]
6297   "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6298   "sltu\t%1,1"
6299   [(set_attr "type" "slt")
6300    (set_attr "mode" "<GPR:MODE>")])
6302 ;; Generate sltiu unless using seq results in better code.
6303 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
6304   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6305         (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6306                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6307   "ISA_HAS_SEQ_SNE"
6308   "@
6309    seq\t%0,%1,%2
6310    sltiu\t%0,%1,1
6311    seqi\t%0,%1,%2"
6312   [(set_attr "type" "slt")
6313    (set_attr "mode" "<GPR:MODE>")])
6315 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
6316   [(set (match_operand:GPR2 0 "register_operand" "=d")
6317         (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
6318                  (const_int 0)))]
6319   "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6320   "sltu\t%0,%.,%1"
6321   [(set_attr "type" "slt")
6322    (set_attr "mode" "<GPR:MODE>")])
6324 ;; Generate sltu unless using sne results in better code.
6325 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
6326   [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6327         (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6328                  (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6329   "ISA_HAS_SEQ_SNE"
6330   "@
6331    sne\t%0,%1,%2
6332    sltu\t%0,%.,%1
6333    snei\t%0,%1,%2"
6334   [(set_attr "type" "slt")
6335    (set_attr "mode" "<GPR:MODE>")])
6337 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
6338   [(set (match_operand:GPR2 0 "register_operand" "=d")
6339         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6340                      (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
6341   "!TARGET_MIPS16"
6342   "slt<u>\t%0,%z2,%1"
6343   [(set_attr "type" "slt")
6344    (set_attr "mode" "<GPR:MODE>")])
6346 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
6347   [(set (match_operand:GPR2 0 "register_operand" "=t")
6348         (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6349                      (match_operand:GPR 2 "register_operand" "d")))]
6350   "TARGET_MIPS16"
6351   "slt<u>\t%2,%1"
6352   [(set_attr "type" "slt")
6353    (set_attr "mode" "<GPR:MODE>")])
6355 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6356   [(set (match_operand:GPR2 0 "register_operand" "=d")
6357         (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6358                      (const_int 1)))]
6359   "!TARGET_MIPS16"
6360   "slt<u>\t%0,%.,%1"
6361   [(set_attr "type" "slt")
6362    (set_attr "mode" "<GPR:MODE>")])
6364 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6365   [(set (match_operand:GPR2 0 "register_operand" "=d")
6366         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6367                      (match_operand:GPR 2 "arith_operand" "dI")))]
6368   "!TARGET_MIPS16"
6369   "slt<u>\t%0,%1,%2"
6370   [(set_attr "type" "slt")
6371    (set_attr "mode" "<GPR:MODE>")])
6373 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6374   [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6375         (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6376                      (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6377   "TARGET_MIPS16"
6378   "slt<u>\t%1,%2"
6379   [(set_attr "type" "slt")
6380    (set_attr "mode" "<GPR:MODE>")
6381    (set_attr "extended_mips16" "no,no,yes")])
6383 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6384   [(set (match_operand:GPR2 0 "register_operand" "=d")
6385         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6386                      (match_operand:GPR 2 "sle_operand" "")))]
6387   "!TARGET_MIPS16"
6389   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6390   return "slt<u>\t%0,%1,%2";
6392   [(set_attr "type" "slt")
6393    (set_attr "mode" "<GPR:MODE>")])
6395 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6396   [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6397         (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6398                      (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6399   "TARGET_MIPS16"
6401   operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6402   return "slt<u>\t%1,%2";
6404   [(set_attr "type" "slt")
6405    (set_attr "mode" "<GPR:MODE>")
6406    (set_attr "extended_mips16" "no,yes")])
6409 ;;  ....................
6411 ;;      FLOATING POINT COMPARISONS
6413 ;;  ....................
6415 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6416   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6417         (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6418                     (match_operand:SCALARF 2 "register_operand" "f")))]
6419   ""
6420   {
6421     return mips_output_compare ("<fpcmp>", "<fcond>", "<fmt>", "<FPCC:mode>", false);
6422   }
6423   [(set_attr "type" "fcmp")
6424    (set_attr "mode" "FPSW")])
6426 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6427   [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6428         (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6429                             (match_operand:SCALARF 2 "register_operand" "f")))]
6430   ""
6431   {
6432     return mips_output_compare ("<fpcmp>", "<swapped_fcond>", "<fmt>", "<FPCC:mode>", true);
6433   }
6434   [(set_attr "type" "fcmp")
6435    (set_attr "mode" "FPSW")])
6438 ;;  ....................
6440 ;;      UNCONDITIONAL BRANCHES
6442 ;;  ....................
6444 ;; Unconditional branches.
6446 (define_expand "jump"
6447   [(set (pc)
6448         (label_ref (match_operand 0)))])
6450 (define_insn "*jump_absolute"
6451   [(set (pc)
6452         (label_ref (match_operand 0)))]
6453   "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6455   if (get_attr_length (insn) <= 8)
6456     {
6457       if (TARGET_CB_MAYBE)
6458         return MIPS_ABSOLUTE_JUMP ("%*b%:\t%l0");
6459       else
6460         return MIPS_ABSOLUTE_JUMP ("%*b\t%l0%/");
6461     }
6462   else
6463     {
6464       if (TARGET_CB_MAYBE && !final_sequence)
6465         return MIPS_ABSOLUTE_JUMP ("%*bc\t%l0");
6466       else
6467         return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6468     }
6470   [(set_attr "type" "branch")
6471    (set_attr "compact_form" "maybe")])
6473 (define_insn "*jump_pic"
6474   [(set (pc)
6475         (label_ref (match_operand 0)))]
6476   "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6478   if (get_attr_length (insn) <= 8)
6479     {
6480       if (TARGET_CB_MAYBE)
6481         return "%*b%:\t%l0";
6482       else
6483         return "%*b\t%l0%/";
6484     }
6485   else
6486     {
6487       mips_output_load_label (operands[0]);
6488       if (TARGET_CB_MAYBE)
6489         return "%*jr%:\t%@%]";
6490       else
6491         return "%*jr\t%@%/%]";
6492     }
6494   [(set_attr "type" "branch")
6495    (set_attr "compact_form" "maybe")])
6497 ;; We need a different insn for the mips16, because a mips16 branch
6498 ;; does not have a delay slot.
6500 (define_insn "*jump_mips16"
6501   [(set (pc)
6502         (label_ref (match_operand 0 "" "")))]
6503   "TARGET_MIPS16"
6504   "b\t%l0"
6505   [(set_attr "type" "branch")
6506    (set (attr "length")
6507         ;; This calculation is like the normal branch one, but the
6508         ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6509         ;; than [-0x100, 0xfe].  This translates to a range of:
6510         ;;
6511         ;;    [-(0x800 - sizeof (branch)), 0x7fe]
6512         ;; == [-0x7fe, 0x7fe]
6513         ;;
6514         ;; from the shorten_branches reference address.  Long-branch
6515         ;; sequences will replace this one, so the minimum length
6516         ;; is one instruction shorter than for conditional branches.
6517         (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6518                     (le (minus (pc) (match_dup 0)) (const_int 2046)))
6519                (const_int 2)
6520                (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6521                     (le (minus (pc) (match_dup 0)) (const_int 65532)))
6522                (const_int 4)
6523                (and (match_test "TARGET_ABICALLS")
6524                     (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6525                (const_int 18)
6526                (match_test "Pmode == SImode")
6527                (const_int 14)
6528                ] (const_int 22)))])
6530 (define_expand "indirect_jump"
6531   [(set (pc) (match_operand 0 "register_operand"))]
6532   ""
6534   operands[0] = force_reg (Pmode, operands[0]);
6535   emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6536   DONE;
6539 (define_insn "indirect_jump_<mode>"
6540   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6541   ""
6542   {
6543     return mips_output_jump (operands, 0, -1, false);
6544   }
6545   [(set_attr "type" "jump")
6546    (set_attr "mode" "none")])
6548 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6549 ;; sequences.  Having a dedicated pattern is more convenient than
6550 ;; creating a SEQUENCE for this special case.
6551 (define_insn "indirect_jump_and_restore_<mode>"
6552   [(set (pc) (match_operand:P 1 "register_operand" "d"))
6553    (set (match_operand:P 0 "register_operand" "=d")
6554         (match_operand:P 2 "register_operand" "y"))]
6555   ""
6556   "%(%<jr\t%1\;move\t%0,%2%>%)"
6557   [(set_attr "type" "multi")
6558    (set_attr "extended_mips16" "yes")])
6560 (define_expand "tablejump"
6561   [(set (pc)
6562         (match_operand 0 "register_operand"))
6563    (use (label_ref (match_operand 1 "")))]
6564   "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6566   if (TARGET_GPWORD)
6567     operands[0] = expand_binop (Pmode, add_optab, operands[0],
6568                                 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6569   else if (TARGET_RTP_PIC)
6570     {
6571       /* When generating RTP PIC, we use case table entries that are relative
6572          to the start of the function.  Add the function's address to the
6573          value we loaded.  */
6574       rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6575       operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6576                                   start, 0, 0, OPTAB_WIDEN);
6577     }
6579   emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6580   DONE;
6583 (define_insn "tablejump_<mode>"
6584   [(set (pc)
6585         (match_operand:P 0 "register_operand" "d"))
6586    (use (label_ref (match_operand 1 "" "")))]
6587   ""
6588   {
6589     return mips_output_jump (operands, 0, -1, false);
6590   }
6591   [(set_attr "type" "jump")
6592    (set_attr "mode" "none")])
6594 ;; For MIPS16, we don't know whether a given jump table will use short or
6595 ;; word-sized offsets until late in compilation, when we are able to determine
6596 ;; the sizes of the insns which comprise the containing function.  This
6597 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6598 ;; the latter tries to calculate the index of the offset to jump through early
6599 ;; in compilation, i.e. at expand time, when nothing is known about the
6600 ;; eventual function layout.
6602 (define_expand "casesi"
6603   [(match_operand:SI 0 "register_operand" "")   ; index to jump on
6604    (match_operand:SI 1 "const_int_operand" "")  ; lower bound
6605    (match_operand:SI 2 "const_int_operand" "")  ; total range
6606    (match_operand 3 "" "")                      ; table label
6607    (match_operand 4 "" "")]                     ; out of range label
6608   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6610   if (operands[1] != const0_rtx)
6611     {
6612       rtx reg = gen_reg_rtx (SImode);
6613       rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6614       
6615       if (!arith_operand (offset, SImode))
6616         offset = force_reg (SImode, offset);
6617       
6618       emit_insn (gen_addsi3 (reg, operands[0], offset));
6619       operands[0] = reg;
6620     }
6622   if (!arith_operand (operands[0], SImode))
6623     operands[0] = force_reg (SImode, operands[0]);
6625   emit_cmp_and_jump_insns (operands[0], operands[2], GTU,
6626                            NULL_RTX, SImode, 1, operands[4]);
6627   emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6628                               (operands[0], operands[3])));
6629   DONE;
6632 (define_insn "casesi_internal_mips16_<mode>"
6633   [(set (pc)
6634         (unspec:P [(match_operand:SI 0 "register_operand" "d")
6635                    (label_ref (match_operand 1 "" ""))]
6636          UNSPEC_CASESI_DISPATCH))
6637    (clobber (match_scratch:P 2 "=d"))
6638    (clobber (match_scratch:P 3 "=d"))]
6639   "TARGET_MIPS16_SHORT_JUMP_TABLES"
6641   rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[1])));
6643   gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6645   switch (GET_MODE (diff_vec))
6646     {
6647     case E_HImode:
6648       output_asm_insn ("sll\t%3,%0,1", operands);
6649       output_asm_insn ("<d>la\t%2,%1", operands);
6650       output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6651       output_asm_insn ("lh\t%3,0(%3)", operands);
6652       break;
6654     case E_SImode:
6655       output_asm_insn ("sll\t%3,%0,2", operands);
6656       output_asm_insn ("<d>la\t%2,%1", operands);
6657       output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6658       output_asm_insn ("lw\t%3,0(%3)", operands);
6659       break;
6661     default:
6662       gcc_unreachable ();
6663     }
6665   output_asm_insn ("<d>addu\t%2,%2,%3", operands);
6667   if (GENERATE_MIPS16E)
6668     return "jrc\t%2";
6669   else
6670     return "jr\t%2";
6672   [(set (attr "insn_count")
6673         (if_then_else (match_test "GENERATE_MIPS16E")
6674                       (const_string "6")
6675                       (const_string "7")))])
6677 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6678 ;; While it is possible to either pull it off the stack (in the
6679 ;; o32 case) or recalculate it given t9 and our target label,
6680 ;; it takes 3 or 4 insns to do so.
6682 (define_expand "builtin_setjmp_setup"
6683   [(use (match_operand 0 "register_operand"))]
6684   "TARGET_USE_GOT"
6686   rtx addr;
6688   addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6689   mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6690   DONE;
6693 ;; Restore the gp that we saved above.  Despite the earlier comment, it seems
6694 ;; that older code did recalculate the gp from $25.  Continue to jump through
6695 ;; $25 for compatibility (we lose nothing by doing so).
6697 (define_expand "builtin_longjmp"
6698   [(use (match_operand 0 "register_operand"))]
6699   "TARGET_USE_GOT"
6701   /* The elements of the buffer are, in order:  */
6702   int W = GET_MODE_SIZE (Pmode);
6703   rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6704   rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6705   rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6706   rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6707   rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6708   /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6709      The target is bound to be using $28 as the global pointer
6710      but the current function might not be.  */
6711   rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6713   /* This bit is similar to expand_builtin_longjmp except that it
6714      restores $gp as well.  */
6715   mips_emit_move (pv, lab);
6716   /* Restore the frame pointer and stack pointer and gp.  We must use a
6717      temporary since the setjmp buffer may be a local.  */
6718   fp = copy_to_reg (fp);
6719   gpv = copy_to_reg (gpv);
6720   emit_stack_restore (SAVE_NONLOCAL, stack);
6722   /* Ensure the frame pointer move is not optimized.  */
6723   emit_insn (gen_blockage ());
6724   emit_clobber (hard_frame_pointer_rtx);
6725   emit_clobber (frame_pointer_rtx);
6726   emit_clobber (gp);
6727   mips_emit_move (hard_frame_pointer_rtx, fp);
6728   mips_emit_move (gp, gpv);
6729   emit_use (hard_frame_pointer_rtx);
6730   emit_use (stack_pointer_rtx);
6731   emit_use (gp);
6732   emit_indirect_jump (pv);
6733   DONE;
6737 ;;  ....................
6739 ;;      Function prologue/epilogue
6741 ;;  ....................
6744 (define_expand "prologue"
6745   [(const_int 1)]
6746   ""
6748   mips_expand_prologue ();
6749   DONE;
6752 ;; Block any insns from being moved before this point, since the
6753 ;; profiling call to mcount can use various registers that aren't
6754 ;; saved or used to pass arguments.
6756 (define_insn "blockage"
6757   [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6758   ""
6759   ""
6760   [(set_attr "type" "ghost")
6761    (set_attr "mode" "none")])
6763 (define_insn "probe_stack_range_<P:mode>"
6764   [(set (match_operand:P 0 "register_operand" "=d")
6765         (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6766                             (match_operand:P 2 "register_operand" "d")]
6767                             UNSPEC_PROBE_STACK_RANGE))]
6768   ""
6769  { return mips_output_probe_stack_range (operands[0], operands[2]); }
6770   [(set_attr "type" "unknown")
6771    (set_attr "can_delay" "no")
6772    (set_attr "mode" "<MODE>")])
6774 (define_expand "epilogue"
6775   [(const_int 2)]
6776   ""
6778   mips_expand_epilogue (false);
6779   DONE;
6782 (define_expand "sibcall_epilogue"
6783   [(const_int 2)]
6784   ""
6786   mips_expand_epilogue (true);
6787   DONE;
6790 ;; Trivial return.  Make it look like a normal return insn as that
6791 ;; allows jump optimizations to work better.
6793 (define_expand "return"
6794   [(simple_return)]
6795   "mips_can_use_return_insn ()"
6796   { mips_expand_before_return (); })
6798 (define_expand "simple_return"
6799   [(simple_return)]
6800   ""
6801   { mips_expand_before_return (); })
6803 (define_insn "*<optab>"
6804   [(any_return)]
6805   ""
6806   {
6807     operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
6808     return mips_output_jump (operands, 0, -1, false);
6809   }
6810   [(set_attr "type"     "jump")
6811    (set_attr "mode"     "none")])
6813 ;; Insn to clear execution and instruction hazards while returning.
6814 ;; However, it doesn't clear hazards created by the insn in its delay slot.
6815 ;; Thus, explicitly place a nop in its delay slot.
6817 (define_insn "mips_hb_return_internal"
6818   [(return)
6819    (unspec_volatile [(match_operand 0 "pmode_register_operand" "")]
6820                     UNSPEC_JRHB)]
6821   ""
6822   {
6823     return "%(jr.hb\t$31%/%)";
6824   }
6825   [(set_attr "insn_count" "2")])
6827 ;; Normal return.
6829 (define_insn "<optab>_internal"
6830   [(any_return)
6831    (use (match_operand 0 "pmode_register_operand" ""))]
6832   ""
6833   {
6834     return mips_output_jump (operands, 0, -1, false);
6835   }
6836   [(set_attr "type"     "jump")
6837    (set_attr "mode"     "none")])
6839 ;; Exception return.
6840 (define_insn "mips_eret"
6841   [(return)
6842    (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6843   ""
6844   "eret"
6845   [(set_attr "type"     "trap")
6846    (set_attr "mode"     "none")])
6848 ;; Debug exception return.
6849 (define_insn "mips_deret"
6850   [(return)
6851    (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6852   ""
6853   "deret"
6854   [(set_attr "type"     "trap")
6855    (set_attr "mode"     "none")])
6857 ;; Disable interrupts.
6858 (define_insn "mips_di"
6859   [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6860   ""
6861   "di"
6862   [(set_attr "type"     "trap")
6863    (set_attr "mode"     "none")])
6865 ;; Execution hazard barrier.
6866 (define_insn "mips_ehb"
6867   [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6868   ""
6869   "ehb"
6870   [(set_attr "type"     "trap")
6871    (set_attr "mode"     "none")])
6873 ;; Read GPR from previous shadow register set.
6874 (define_insn "mips_rdpgpr_<mode>"
6875   [(set (match_operand:P 0 "register_operand" "=d")
6876         (unspec_volatile:P [(match_operand:P 1 "register_operand" "d")]
6877                            UNSPEC_RDPGPR))]
6878   ""
6879   "rdpgpr\t%0,%1"
6880   [(set_attr "type"     "move")
6881    (set_attr "mode"     "<MODE>")])
6883 ;; Move involving COP0 registers.
6884 (define_insn "cop0_move"
6885   [(set (match_operand:SI 0 "register_operand" "=B,d")
6886         (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6887                             UNSPEC_COP0))]
6888   ""
6889 { return mips_output_move (operands[0], operands[1]); }
6890   [(set_attr "type"     "mtc,mfc")
6891    (set_attr "mode"     "SI")])
6893 ;; This is used in compiling the unwind routines.
6894 (define_expand "eh_return"
6895   [(use (match_operand 0 "general_operand"))]
6896   ""
6898   if (GET_MODE (operands[0]) != word_mode)
6899     operands[0] = convert_to_mode (word_mode, operands[0], 0);
6900   if (TARGET_64BIT)
6901     emit_insn (gen_eh_set_lr_di (operands[0]));
6902   else
6903     emit_insn (gen_eh_set_lr_si (operands[0]));
6904   DONE;
6907 ;; Clobber the return address on the stack.  We can't expand this
6908 ;; until we know where it will be put in the stack frame.
6910 (define_insn "eh_set_lr_si"
6911   [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6912    (clobber (match_scratch:SI 1 "=&d"))]
6913   "! TARGET_64BIT"
6914   "#")
6916 (define_insn "eh_set_lr_di"
6917   [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6918    (clobber (match_scratch:DI 1 "=&d"))]
6919   "TARGET_64BIT"
6920   "#")
6922 (define_split
6923   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6924    (clobber (match_scratch 1))]
6925   "reload_completed"
6926   [(const_int 0)]
6928   mips_set_return_address (operands[0], operands[1]);
6929   DONE;
6932 (define_expand "exception_receiver"
6933   [(const_int 0)]
6934   "TARGET_USE_GOT"
6936   /* See the comment above load_call<mode> for details.  */
6937   emit_insn (gen_set_got_version ());
6939   /* If we have a call-clobbered $gp, restore it from its save slot.  */
6940   if (HAVE_restore_gp_si)
6941     emit_insn (gen_restore_gp_si ());
6942   else if (HAVE_restore_gp_di)
6943     emit_insn (gen_restore_gp_di ());
6944   DONE;
6947 (define_expand "nonlocal_goto_receiver"
6948   [(const_int 0)]
6949   "TARGET_USE_GOT"
6951   /* See the comment above load_call<mode> for details.  */
6952   emit_insn (gen_set_got_version ());
6953   DONE;
6956 ;; Restore $gp from its .cprestore stack slot.  The instruction remains
6957 ;; volatile until all uses of $28 are exposed.
6958 (define_insn_and_split "restore_gp_<mode>"
6959   [(set (reg:P 28)
6960         (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6961    (clobber (match_scratch:P 0 "=&d"))]
6962   "TARGET_CALL_CLOBBERED_GP"
6963   "#"
6964   "&& epilogue_completed"
6965   [(const_int 0)]
6967   mips_restore_gp_from_cprestore_slot (operands[0]);
6968   DONE;
6970   [(set_attr "type" "ghost")])
6972 ;; Move between $gp and its register save slot.
6973 (define_insn_and_split "move_gp<mode>"
6974   [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6975         (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6976                     UNSPEC_MOVE_GP))]
6977   ""
6978   { return mips_must_initialize_gp_p () ? "#" : ""; }
6979   "mips_must_initialize_gp_p ()"
6980   [(const_int 0)]
6982   mips_emit_move (operands[0], operands[1]);
6983   DONE;
6985   [(set_attr "type" "ghost")])
6988 ;;  ....................
6990 ;;      FUNCTION CALLS
6992 ;;  ....................
6994 ;; Instructions to load a call address from the GOT.  The address might
6995 ;; point to a function or to a lazy binding stub.  In the latter case,
6996 ;; the stub will use the dynamic linker to resolve the function, which
6997 ;; in turn will change the GOT entry to point to the function's real
6998 ;; address.
7000 ;; This means that every call, even pure and constant ones, can
7001 ;; potentially modify the GOT entry.  And once a stub has been called,
7002 ;; we must not call it again.
7004 ;; We represent this restriction using an imaginary, fixed, call-saved
7005 ;; register called GOT_VERSION_REGNUM.  The idea is to make the register
7006 ;; live throughout the function and to change its value after every
7007 ;; potential call site.  This stops any rtx value that uses the register
7008 ;; from being computed before an earlier call.  To do this, we:
7010 ;;    - Ensure that the register is live on entry to the function,
7011 ;;      so that it is never thought to be used uninitalized.
7013 ;;    - Ensure that the register is live on exit from the function,
7014 ;;      so that it is live throughout.
7016 ;;    - Make each call (lazily-bound or not) use the current value
7017 ;;      of GOT_VERSION_REGNUM, so that updates of the register are
7018 ;;      not moved across call boundaries.
7020 ;;    - Add "ghost" definitions of the register to the beginning of
7021 ;;      blocks reached by EH and ABNORMAL_CALL edges, because those
7022 ;;      edges may involve calls that normal paths don't.  (E.g. the
7023 ;;      unwinding code that handles a non-call exception may change
7024 ;;      lazily-bound GOT entries.)  We do this by making the
7025 ;;      exception_receiver and nonlocal_goto_receiver expanders emit
7026 ;;      a set_got_version instruction.
7028 ;;    - After each call (lazily-bound or not), use a "ghost"
7029 ;;      update_got_version instruction to change the register's value.
7030 ;;      This instruction mimics the _possible_ effect of the dynamic
7031 ;;      resolver during the call and it remains live even if the call
7032 ;;      itself becomes dead.
7034 ;;    - Leave GOT_VERSION_REGNUM out of all register classes.
7035 ;;      The register is therefore not a valid register_operand
7036 ;;      and cannot be moved to or from other registers.
7038 (define_insn "load_call<mode>"
7039   [(set (match_operand:P 0 "register_operand" "=d")
7040         (unspec:P [(match_operand:P 1 "register_operand" "d")
7041                    (match_operand:P 2 "immediate_operand" "")
7042                    (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
7043   "TARGET_USE_GOT"
7044   "<load>\t%0,%R2(%1)"
7045   [(set_attr "got" "load")
7046    (set_attr "mode" "<MODE>")])
7048 (define_insn "set_got_version"
7049   [(set (reg:SI GOT_VERSION_REGNUM)
7050         (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
7051   "TARGET_USE_GOT"
7052   ""
7053   [(set_attr "type" "ghost")])
7055 (define_insn "update_got_version"
7056   [(set (reg:SI GOT_VERSION_REGNUM)
7057         (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
7058   "TARGET_USE_GOT"
7059   ""
7060   [(set_attr "type" "ghost")])
7062 ;; Sibling calls.  All these patterns use jump instructions.
7064 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
7065 ;; addresses if a direct jump is acceptable.  Since the 'S' constraint
7066 ;; is defined in terms of call_insn_operand, the same is true of the
7067 ;; constraints.
7069 ;; When we use an indirect jump, we need a register that will be
7070 ;; preserved by the epilogue.  Since TARGET_USE_PIC_FN_ADDR_REG forces
7071 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
7072 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
7073 ;; as well.
7075 (define_expand "sibcall"
7076   [(parallel [(call (match_operand 0 "")
7077                     (match_operand 1 ""))
7078               (use (match_operand 2 ""))        ;; next_arg_reg
7079               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
7080   "TARGET_SIBCALLS"
7082   mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
7083                     operands[1], operands[2], false);
7084   DONE;
7087 (define_insn "sibcall_internal"
7088   [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
7089          (match_operand 1 "" ""))]
7090   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
7091   { return mips_output_jump (operands, 0, 1, false); }
7092   [(set_attr "jal" "indirect,direct")
7093    (set_attr "jal_macro" "no")])
7095 (define_expand "sibcall_value"
7096   [(parallel [(set (match_operand 0 "")
7097                    (call (match_operand 1 "")
7098                          (match_operand 2 "")))
7099               (use (match_operand 3 ""))])]             ;; next_arg_reg
7100   "TARGET_SIBCALLS"
7102   mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
7103                     operands[2], operands[3], false);
7104   DONE;
7107 (define_insn "sibcall_value_internal"
7108   [(set (match_operand 0 "register_operand" "")
7109         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
7110               (match_operand 2 "" "")))]
7111   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
7112   { return mips_output_jump (operands, 1, 2, false); }
7113   [(set_attr "jal" "indirect,direct")
7114    (set_attr "jal_macro" "no")])
7116 (define_insn "sibcall_value_multiple_internal"
7117   [(set (match_operand 0 "register_operand" "")
7118         (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
7119               (match_operand 2 "" "")))
7120    (set (match_operand 3 "register_operand" "")
7121         (call (mem:SI (match_dup 1))
7122               (match_dup 2)))]
7123   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
7124   { return mips_output_jump (operands, 1, 2, false); }
7125   [(set_attr "jal" "indirect,direct")
7126    (set_attr "jal_macro" "no")])
7128 (define_expand "call"
7129   [(parallel [(call (match_operand 0 "")
7130                     (match_operand 1 ""))
7131               (use (match_operand 2 ""))        ;; next_arg_reg
7132               (use (match_operand 3 ""))])]     ;; struct_value_size_rtx
7133   ""
7135   mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
7136                     operands[1], operands[2], false);
7137   DONE;
7140 ;; This instruction directly corresponds to an assembly-language "jal".
7141 ;; There are four cases:
7143 ;;    - -mno-abicalls:
7144 ;;        Both symbolic and register destinations are OK.  The pattern
7145 ;;        always expands to a single mips instruction.
7147 ;;    - -mabicalls/-mno-explicit-relocs:
7148 ;;        Again, both symbolic and register destinations are OK.
7149 ;;        The call is treated as a multi-instruction black box.
7151 ;;    - -mabicalls/-mexplicit-relocs with n32 or n64:
7152 ;;        Only "jal $25" is allowed.  This expands to a single "jalr $25"
7153 ;;        instruction.
7155 ;;    - -mabicalls/-mexplicit-relocs with o32 or o64:
7156 ;;        Only "jal $25" is allowed.  The call is actually two instructions:
7157 ;;        "jalr $25" followed by an insn to reload $gp.
7159 ;; In the last case, we can generate the individual instructions with
7160 ;; a define_split.  There are several things to be wary of:
7162 ;;   - We can't expose the load of $gp before reload.  If we did,
7163 ;;     it might get removed as dead, but reload can introduce new
7164 ;;     uses of $gp by rematerializing constants.
7166 ;;   - We shouldn't restore $gp after calls that never return.
7167 ;;     It isn't valid to insert instructions between a noreturn
7168 ;;     call and the following barrier.
7170 ;;   - The splitter deliberately changes the liveness of $gp.  The unsplit
7171 ;;     instruction preserves $gp and so have no effect on its liveness.
7172 ;;     But once we generate the separate insns, it becomes obvious that
7173 ;;     $gp is not live on entry to the call.
7175 (define_insn_and_split "call_internal"
7176   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
7177          (match_operand 1 "" ""))
7178    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7179   ""
7180   {
7181     return (TARGET_SPLIT_CALLS ? "#"
7182             : mips_output_jump (operands, 0, 1, true));
7183   }
7184   "reload_completed && TARGET_SPLIT_CALLS"
7185   [(const_int 0)]
7187   mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
7188   DONE;
7190   [(set_attr "jal" "indirect,direct")])
7192 (define_insn "call_split"
7193   [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
7194          (match_operand 1 "" ""))
7195    (clobber (reg:SI RETURN_ADDR_REGNUM))
7196    (clobber (reg:SI 28))]
7197   "TARGET_SPLIT_CALLS"
7198   { return mips_output_jump (operands, 0, 1, true); }
7199   [(set_attr "jal" "indirect,direct")
7200    (set_attr "jal_macro" "no")])
7202 ;; A pattern for calls that must be made directly.  It is used for
7203 ;; MIPS16 calls that the linker may need to redirect to a hard-float
7204 ;; stub; the linker relies on the call relocation type to detect when
7205 ;; such redirection is needed.
7206 (define_insn_and_split "call_internal_direct"
7207   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
7208          (match_operand 1))
7209    (const_int 1)
7210    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7211   ""
7212   {
7213     return (TARGET_SPLIT_CALLS ? "#"
7214             : mips_output_jump (operands, 0, -1, true));
7215   }
7216   "reload_completed && TARGET_SPLIT_CALLS"
7217   [(const_int 0)]
7219   mips_split_call (curr_insn,
7220                    gen_call_direct_split (operands[0], operands[1]));
7221   DONE;
7223   [(set_attr "jal" "direct")])
7225 (define_insn "call_direct_split"
7226   [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
7227          (match_operand 1))
7228    (const_int 1)
7229    (clobber (reg:SI RETURN_ADDR_REGNUM))
7230    (clobber (reg:SI 28))]
7231   "TARGET_SPLIT_CALLS"
7232   { return mips_output_jump (operands, 0, -1, true); }
7233   [(set_attr "jal" "direct")
7234    (set_attr "jal_macro" "no")])
7236 (define_expand "call_value"
7237   [(parallel [(set (match_operand 0 "")
7238                    (call (match_operand 1 "")
7239                          (match_operand 2 "")))
7240               (use (match_operand 3 ""))])]             ;; next_arg_reg
7241   ""
7243   mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
7244                     operands[2], operands[3], false);
7245   DONE;
7248 ;; See comment for call_internal.
7249 (define_insn_and_split "call_value_internal"
7250   [(set (match_operand 0 "register_operand" "")
7251         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7252               (match_operand 2 "" "")))
7253    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7254   ""
7255   {
7256     return (TARGET_SPLIT_CALLS ? "#"
7257             : mips_output_jump (operands, 1, 2, true));
7258   }
7259   "reload_completed && TARGET_SPLIT_CALLS"
7260   [(const_int 0)]
7262   mips_split_call (curr_insn,
7263                    gen_call_value_split (operands[0], operands[1],
7264                                          operands[2]));
7265   DONE;
7267   [(set_attr "jal" "indirect,direct")])
7269 (define_insn "call_value_split"
7270   [(set (match_operand 0 "register_operand" "")
7271         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7272               (match_operand 2 "" "")))
7273    (clobber (reg:SI RETURN_ADDR_REGNUM))
7274    (clobber (reg:SI 28))]
7275   "TARGET_SPLIT_CALLS"
7276   { return mips_output_jump (operands, 1, 2, true); }
7277   [(set_attr "jal" "indirect,direct")
7278    (set_attr "jal_macro" "no")])
7280 ;; See call_internal_direct.
7281 (define_insn_and_split "call_value_internal_direct"
7282   [(set (match_operand 0 "register_operand")
7283         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7284               (match_operand 2)))
7285    (const_int 1)
7286    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7287   ""
7288   {
7289     return (TARGET_SPLIT_CALLS ? "#"
7290             : mips_output_jump (operands, 1, -1, true));
7291   }
7292   "reload_completed && TARGET_SPLIT_CALLS"
7293   [(const_int 0)]
7295   mips_split_call (curr_insn,
7296                    gen_call_value_direct_split (operands[0], operands[1],
7297                                                 operands[2]));
7298   DONE;
7300   [(set_attr "jal" "direct")])
7302 (define_insn "call_value_direct_split"
7303   [(set (match_operand 0 "register_operand")
7304         (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7305               (match_operand 2)))
7306    (const_int 1)
7307    (clobber (reg:SI RETURN_ADDR_REGNUM))
7308    (clobber (reg:SI 28))]
7309   "TARGET_SPLIT_CALLS"
7310   { return mips_output_jump (operands, 1, -1, true); }
7311   [(set_attr "jal" "direct")
7312    (set_attr "jal_macro" "no")])
7314 ;; See comment for call_internal.
7315 (define_insn_and_split "call_value_multiple_internal"
7316   [(set (match_operand 0 "register_operand" "")
7317         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7318               (match_operand 2 "" "")))
7319    (set (match_operand 3 "register_operand" "")
7320         (call (mem:SI (match_dup 1))
7321               (match_dup 2)))
7322    (clobber (reg:SI RETURN_ADDR_REGNUM))]
7323   ""
7324   {
7325     return (TARGET_SPLIT_CALLS ? "#"
7326             : mips_output_jump (operands, 1, 2, true));
7327   }
7328   "reload_completed && TARGET_SPLIT_CALLS"
7329   [(const_int 0)]
7331   mips_split_call (curr_insn,
7332                    gen_call_value_multiple_split (operands[0], operands[1],
7333                                                   operands[2], operands[3]));
7334   DONE;
7336   [(set_attr "jal" "indirect,direct")])
7338 (define_insn "call_value_multiple_split"
7339   [(set (match_operand 0 "register_operand" "")
7340         (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7341               (match_operand 2 "" "")))
7342    (set (match_operand 3 "register_operand" "")
7343         (call (mem:SI (match_dup 1))
7344               (match_dup 2)))
7345    (clobber (reg:SI RETURN_ADDR_REGNUM))
7346    (clobber (reg:SI 28))]
7347   "TARGET_SPLIT_CALLS"
7348   { return mips_output_jump (operands, 1, 2, true); }
7349   [(set_attr "jal" "indirect,direct")
7350    (set_attr "jal_macro" "no")])
7352 ;; Call subroutine returning any type.
7354 (define_expand "untyped_call"
7355   [(parallel [(call (match_operand 0 "")
7356                     (const_int 0))
7357               (match_operand 1 "")
7358               (match_operand 2 "")])]
7359   ""
7361   int i;
7363   emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
7365   for (i = 0; i < XVECLEN (operands[2], 0); i++)
7366     {
7367       rtx set = XVECEXP (operands[2], 0, i);
7368       mips_emit_move (SET_DEST (set), SET_SRC (set));
7369     }
7371   emit_insn (gen_blockage ());
7372   DONE;
7376 ;;  ....................
7378 ;;      MISC.
7380 ;;  ....................
7384 (define_insn "prefetch"
7385   [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7386              (match_operand 1 "const_int_operand" "n")
7387              (match_operand 2 "const_int_operand" "n"))]
7388   "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7390   if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT)
7391     {
7392       /* Loongson 2[ef] and Loongson ext use load to $0 for prefetching.  */
7393       if (TARGET_64BIT)
7394         return "ld\t$0,%a0";
7395       else
7396         return "lw\t$0,%a0";
7397     }
7398   /* Loongson ext2 implementation pref instructions.  */
7399   if (TARGET_LOONGSON_EXT2)
7400     {
7401       operands[1] = mips_loongson_ext2_prefetch_cookie (operands[1],
7402                                                         operands[2]);
7403       return "pref\t%1, %a0";
7404     }
7405   operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7406   return "pref\t%1,%a0";
7408   [(set_attr "type" "prefetch")])
7410 (define_insn "*prefetch_indexed_<mode>"
7411   [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7412                      (match_operand:P 1 "register_operand" "d"))
7413              (match_operand 2 "const_int_operand" "n")
7414              (match_operand 3 "const_int_operand" "n"))]
7415   "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7417   if (TARGET_LOONGSON_EXT)
7418     {
7419       /* Loongson Loongson ext use index load to $0 for prefetching.  */
7420       if (TARGET_64BIT)
7421         return "gsldx\t$0,0(%0,%1)";
7422       else
7423         return "gslwx\t$0,0(%0,%1)";
7424     }
7425   /* Loongson ext2 implementation pref instructions.  */
7426   if (TARGET_LOONGSON_EXT2)
7427     {
7428       operands[2] = mips_loongson_ext2_prefetch_cookie (operands[2],
7429                                                         operands[3]);
7430       return "prefx\t%2,%1(%0)";
7431     }
7432   operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7433   return "prefx\t%2,%1(%0)";
7435   [(set_attr "type" "prefetchx")])
7437 (define_insn "nop"
7438   [(const_int 0)]
7439   ""
7440   "%(nop%)"
7441   [(set_attr "type"     "nop")
7442    (set_attr "mode"     "none")])
7444 ;; Like nop, but commented out when outside a .set noreorder block.
7445 (define_insn "hazard_nop"
7446   [(const_int 1)]
7447   ""
7448   {
7449     if (mips_noreorder.nesting_level > 0)
7450       return "nop";
7451     else
7452       return "#nop";
7453   }
7454   [(set_attr "type"     "nop")])
7456 ;; The `.insn' pseudo-op.
7457 (define_insn "insn_pseudo"
7458   [(unspec_volatile [(const_int 0)] UNSPEC_INSN_PSEUDO)]
7459   ""
7460   ".insn"
7461   [(set_attr "mode" "none")
7462    (set_attr "insn_count" "0")])
7464 ;; MIPS4 Conditional move instructions.
7466 (define_insn "mov<GPR:mode>_on_<MOVECC:mode>"
7467   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7468         (if_then_else:GPR
7469          (match_operator 4 "equality_operator"
7470                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7471                  (const_int 0)])
7472          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7473          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7474   "!TARGET_MIPS16 && ISA_HAS_CONDMOVE"
7475   "@
7476     mov%T4\t%0,%z2,%1
7477     mov%t4\t%0,%z3,%1"
7478   [(set_attr "type" "condmove")
7479    (set_attr "mode" "<GPR:MODE>")])
7481 (define_insn "mov<GPR:mode>_on_<MOVECC:mode>_mips16e2"
7482   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d")
7483         (if_then_else:GPR
7484          (match_operator 4 "equality_operator"
7485                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>,t,t")
7486                  (const_int 0)])
7487          (match_operand:GPR 2 "reg_or_0_operand_mips16e2" "dJ,0,dJ,0")
7488          (match_operand:GPR 3 "reg_or_0_operand_mips16e2" "0,dJ,0,dJ")))]
7489   "ISA_HAS_MIPS16E2 && ISA_HAS_CONDMOVE"
7490   "@
7491     mov%T4\t%0,%z2,%1
7492     mov%t4\t%0,%z3,%1
7493     movt%T4\t%0,%z2
7494     movt%t4\t%0,%z3"
7495   [(set_attr "type" "condmove")
7496    (set_attr "mode" "<GPR:MODE>")
7497    (set_attr "extended_mips16" "yes")])
7499 (define_insn "mov<GPR:mode>_on_<GPR2:mode>_ne"
7500   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7501        (if_then_else:GPR
7502         (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7503         (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7504         (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7505   "!TARGET_MIPS16 && ISA_HAS_CONDMOVE"
7506   "@
7507     movn\t%0,%z2,%1
7508     movz\t%0,%z3,%1"
7509   [(set_attr "type" "condmove")
7510    (set_attr "mode" "<GPR:MODE>")])
7512 (define_insn "mov<GPR:mode>_on_<GPR2:mode>_ne_mips16e2"
7513   [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d")
7514            (if_then_else:GPR
7515                 (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>,t,t")
7516                 (match_operand:GPR 2 "reg_or_0_operand_mips16e2" "dJ,0,dJ,0")
7517                 (match_operand:GPR 3 "reg_or_0_operand_mips16e2" "0,dJ,0,dJ")))]
7518  "ISA_HAS_MIPS16E2 && ISA_HAS_CONDMOVE"
7519   "@
7520     movn\t%0,%z2,%1
7521     movz\t%0,%z3,%1
7522     movtn\t%0,%z2
7523     movtz\t%0,%z3"
7524   [(set_attr "type" "condmove")
7525    (set_attr "mode" "<GPR:MODE>")
7526    (set_attr "extended_mips16" "yes")])
7528 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7529   [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7530         (if_then_else:SCALARF
7531          (match_operator 4 "equality_operator"
7532                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7533                  (const_int 0)])
7534          (match_operand:SCALARF 2 "register_operand" "f,0")
7535          (match_operand:SCALARF 3 "register_operand" "0,f")))]
7536   "ISA_HAS_FP_CONDMOVE"
7537   "@
7538     mov%T4.<fmt>\t%0,%2,%1
7539     mov%t4.<fmt>\t%0,%3,%1"
7540   [(set_attr "type" "condmove")
7541    (set_attr "mode" "<SCALARF:MODE>")])
7543 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7544   [(set (match_operand:GPR 0 "register_operand" "=d,d")
7545         (if_then_else:GPR
7546          (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7547                            (const_int 0))
7548          (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7549          (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7550   "ISA_HAS_SEL
7551    && (register_operand (operands[2], <GPR:MODE>mode)
7552        != register_operand (operands[3], <GPR:MODE>mode))"
7553   "@
7554    <sel>\t%0,%2,%1
7555    <selinv>\t%0,%3,%1"
7556   [(set_attr "type" "condmove")
7557    (set_attr "mode" "<GPR:MODE>")])
7559 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7560 ;; argument if the 1st is zero.  This means operand 2 and 3 are
7561 ;; inverted in the instruction.
7563 (define_insn "*sel<mode>"
7564   [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7565         (if_then_else:SCALARF
7566          (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7567                  (const_int 0))
7568          (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7569          (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7570   "ISA_HAS_SEL && ISA_HAS_CCF"
7571   "@
7572    sel.<fmt>\t%0,%3,%2
7573    seleqz.<fmt>\t%0,%3,%1
7574    selnez.<fmt>\t%0,%2,%1"
7575   [(set_attr "type" "condmove")
7576    (set_attr "mode" "<SCALARF:MODE>")])
7578 ;; These are the main define_expand's used to make conditional moves.
7580 (define_expand "mov<mode>cc"
7581   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7582    (set (match_operand:GPR 0 "register_operand")
7583         (if_then_else:GPR (match_dup 5)
7584                           (match_operand:GPR 2 "reg_or_0_operand")
7585                           (match_operand:GPR 3 "reg_or_0_operand")))]
7586   "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7588   if (!ISA_HAS_FP_CONDMOVE
7589       && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7590     FAIL;
7592   mips_expand_conditional_move (operands);
7593   DONE;
7596 (define_expand "mov<mode>cc"
7597   [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7598    (set (match_operand:SCALARF 0 "register_operand")
7599         (if_then_else:SCALARF (match_dup 5)
7600                               (match_operand:SCALARF 2 "reg_or_0_operand")
7601                               (match_operand:SCALARF 3 "reg_or_0_operand")))]
7602   "ISA_HAS_FP_CONDMOVE
7603    || (ISA_HAS_SEL && ISA_HAS_CCF)"
7605   if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7606     FAIL;
7608   /* Workaround an LRA bug which means that tied operands in the sel.fmt
7609      pattern lead to the double precision destination of sel.d getting
7610      reloaded with the full register file usable and the restrictions on
7611      whether the CCFmode input can be used in odd-numbered single-precision
7612      registers are ignored.  For consistency reasons the CCF mode values
7613      must be guaranteed to only exist in the even-registers because of
7614      the unusual duality between single and double precision values.  */
7615   if (ISA_HAS_SEL && <MODE>mode == DFmode
7616       && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7617     FAIL;
7619   mips_expand_conditional_move (operands);
7620   DONE;
7623 (define_expand "speculation_barrier"
7624   [(unspec_volatile [(const_int 0)] VUNSPEC_SPECULATION_BARRIER)]
7625   ""
7626   "
7627   mips_emit_speculation_barrier_function ();
7628   DONE;
7629   "
7634 ;;  ....................
7636 ;;      mips16 inline constant tables
7638 ;;  ....................
7641 (define_insn "consttable"
7642   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7643                     UNSPEC_CONSTTABLE)]
7644   ""
7645   ""
7646   [(set_attr "mode" "none")
7647    (set_attr "insn_count" "0")])
7649 (define_insn "consttable_end"
7650   [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7651                     UNSPEC_CONSTTABLE_END)]
7652   ""
7653   ""
7654   [(set_attr "mode" "none")
7655    (set_attr "insn_count" "0")])
7657 (define_insn "consttable_tls_reloc"
7658   [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7659                      (match_operand 1 "const_int_operand" "")]
7660                     UNSPEC_CONSTTABLE_INT)]
7661   "TARGET_MIPS16_PCREL_LOADS"
7662   { return mips_output_tls_reloc_directive (&operands[0]); }
7663   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7665 (define_insn "consttable_int"
7666   [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7667                      (match_operand 1 "const_int_operand" "")]
7668                     UNSPEC_CONSTTABLE_INT)]
7669   "TARGET_MIPS16"
7671   assemble_integer (mips_strip_unspec_address (operands[0]),
7672                     INTVAL (operands[1]),
7673                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
7674   return "";
7676   [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7678 (define_insn "consttable_float"
7679   [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7680                     UNSPEC_CONSTTABLE_FLOAT)]
7681   "TARGET_MIPS16"
7683   gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7684   assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
7685                  as_a <scalar_float_mode> (GET_MODE (operands[0])),
7686                  GET_MODE_BITSIZE (GET_MODE (operands[0])));
7687   return "";
7689   [(set (attr "length")
7690         (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7692 (define_insn "align"
7693   [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7694   ""
7695   ".align\t%0"
7696   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7698 (define_split
7699   [(match_operand 0 "small_data_pattern")]
7700   "reload_completed"
7701   [(match_dup 0)]
7702   { operands[0] = mips_rewrite_small_data (operands[0]); })
7705 ;;  ....................
7707 ;;      MIPS16e Save/Restore
7709 ;;  ....................
7712 (define_insn "*mips16e_save_restore"
7713   [(match_parallel 0 ""
7714        [(set (match_operand:SI 1 "register_operand")
7715              (plus:SI (match_dup 1)
7716                       (match_operand:SI 2 "const_int_operand")))])]
7717   "operands[1] == stack_pointer_rtx
7718    && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7719   { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7720   [(set_attr "type" "arith")
7721    (set_attr "extended_mips16" "yes")])
7723 ;; Thread-Local Storage
7725 ;; The TLS base pointer is accessed via "rdhwr $3, $29".  No current
7726 ;; MIPS architecture defines this register, and no current
7727 ;; implementation provides it; instead, any OS which supports TLS is
7728 ;; expected to trap and emulate this instruction.  rdhwr is part of the
7729 ;; MIPS 32r2 specification, but we use it on any architecture because
7730 ;; we expect it to be emulated.  Use .set to force the assembler to
7731 ;; accept it.
7733 ;; We do not use a constraint to force the destination to be $3
7734 ;; because $3 can appear explicitly as a function return value.
7735 ;; If we leave the use of $3 implicit in the constraints until
7736 ;; reload, we may end up making a $3 return value live across
7737 ;; the instruction, leading to a spill failure when reloading it.
7738 (define_insn_and_split "tls_get_tp_<mode>"
7739   [(set (match_operand:P 0 "register_operand" "=d")
7740         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7741    (clobber (reg:P TLS_GET_TP_REGNUM))]
7742   "HAVE_AS_TLS && !TARGET_MIPS16"
7743   "#"
7744   "&& reload_completed"
7745   [(set (reg:P TLS_GET_TP_REGNUM)
7746         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7747    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7748   ""
7749   [(set_attr "type" "unknown")
7750    (set_attr "mode" "<MODE>")
7751    (set_attr "insn_count" "2")])
7753 (define_insn "*tls_get_tp_<mode>_split"
7754   [(set (reg:P TLS_GET_TP_REGNUM)
7755         (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7756   "HAVE_AS_TLS && !TARGET_MIPS16"
7757   {
7758     if (mips_isa_rev >= 2)
7759       return "rdhwr\t$3,$29";
7761     return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7762   }
7763   [(set_attr "type" "unknown")
7764    ; Since rdhwr always generates a trap for now, putting it in a delay
7765    ; slot would make the kernel's emulation of it much slower.
7766    (set_attr "can_delay" "no")
7767    (set_attr "mode" "<MODE>")])
7769 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7770 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7771 ;; accessible in MIPS16.
7773 ;; This is not represented as a call insn, to avoid the
7774 ;; unnecesarry clobbering of caller-save registers by a
7775 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7777 ;; A $25 clobber is added to cater for a $25 load stub added by the
7778 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7780 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7781   [(set (match_operand:P 0 "register_operand" "=d")
7782         (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7783                   UNSPEC_TLS_GET_TP))
7784    (clobber (reg:P TLS_GET_TP_REGNUM))
7785    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7786    (clobber (reg:P RETURN_ADDR_REGNUM))]
7787   "HAVE_AS_TLS && TARGET_MIPS16"
7788   "#"
7789   "&& reload_completed"
7790   [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7791                    (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7792               (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7793               (clobber (reg:P RETURN_ADDR_REGNUM))])
7794    (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7795   ""
7796   [(set_attr "type" "multi")
7797    (set_attr "insn_count" "4")
7798    (set_attr "mode" "<MODE>")])
7800 (define_insn "*tls_get_tp_mips16_call_<mode>"
7801   [(set (reg:P TLS_GET_TP_REGNUM)
7802         (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7803                   UNSPEC_TLS_GET_TP))
7804    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7805    (clobber (reg:P RETURN_ADDR_REGNUM))]
7806   "HAVE_AS_TLS && TARGET_MIPS16"
7807   { return mips_output_jump (operands, 0, -1, true); }
7808   [(set_attr "type" "call")
7809    (set_attr "insn_count" "3")
7810    (set_attr "mode" "<MODE>")])
7812 ;; Named pattern for expanding thread pointer reference.
7813 (define_expand "get_thread_pointer<mode>"
7814   [(match_operand:P 0 "register_operand" "=d")]
7815   "HAVE_AS_TLS"
7817   mips_expand_thread_pointer (operands[0]);
7818   DONE;
7821 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7822 (define_expand "mips_get_fcsr"
7823   [(set (match_operand:SI 0 "register_operand")
7824        (unspec_volatile:SI [(const_int 0)] UNSPEC_GET_FCSR))]
7825   "TARGET_HARD_FLOAT_ABI"
7827   if (TARGET_MIPS16)
7828     {
7829       mips16_expand_get_fcsr (operands[0]);
7830       DONE;
7831     }
7834 (define_insn "*mips_get_fcsr"
7835   [(set (match_operand:SI 0 "register_operand" "=d")
7836        (unspec_volatile:SI [(const_int 0)] UNSPEC_GET_FCSR))]
7837   "TARGET_HARD_FLOAT"
7838   "cfc1\t%0,$31")
7840 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7841 (define_insn "mips_get_fcsr_mips16_<mode>"
7842   [(set (reg:SI GET_FCSR_REGNUM)
7843         (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7844                    UNSPEC_GET_FCSR))
7845    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7846    (clobber (reg:P RETURN_ADDR_REGNUM))]
7847   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7848   { return mips_output_jump (operands, 0, -1, true); }
7849   [(set_attr "type" "call")
7850    (set_attr "insn_count" "3")])
7852 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7853 (define_expand "mips_set_fcsr"
7854   [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7855                     UNSPEC_SET_FCSR)]
7856   "TARGET_HARD_FLOAT_ABI"
7858   if (TARGET_MIPS16)
7859     {
7860       mips16_expand_set_fcsr (operands[0]);
7861       DONE;
7862     }
7865 (define_insn "*mips_set_fcsr"
7866   [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7867                     UNSPEC_SET_FCSR)]
7868   "TARGET_HARD_FLOAT"
7869   "ctc1\t%0,$31")
7871 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7872 (define_insn "mips_set_fcsr_mips16_<mode>"
7873   [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7874                         (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7875    (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7876    (clobber (reg:P RETURN_ADDR_REGNUM))]
7877   "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7878   { return mips_output_jump (operands, 0, -1, true); }
7879   [(set_attr "type" "call")
7880    (set_attr "insn_count" "3")])
7882 ;; Match paired HI/SI/SF/DFmode load/stores.
7883 (define_insn "*join2_load_store<JOIN_MODE:mode>"
7884   [(set (match_operand:JOIN_MODE 0 "nonimmediate_operand" "=d,f,m,m")
7885         (match_operand:JOIN_MODE 1 "nonimmediate_operand" "m,m,d,f"))
7886    (set (match_operand:JOIN_MODE 2 "nonimmediate_operand" "=d,f,m,m")
7887         (match_operand:JOIN_MODE 3 "nonimmediate_operand" "m,m,d,f"))]
7888   "ENABLE_LD_ST_PAIRS && reload_completed"
7889   {
7890     bool load_p = (which_alternative == 0 || which_alternative == 1);
7891     /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7892        Hardware does not bond those loads, even when they are consecutive.
7893        However, order of the loads need to be checked for correctness.  */
7894     if (!load_p || !reg_overlap_mentioned_p (operands[0], operands[1]))
7895       {
7896         output_asm_insn (mips_output_move (operands[0], operands[1]),
7897                          operands);
7898         output_asm_insn (mips_output_move (operands[2], operands[3]),
7899                          &operands[2]);
7900       }
7901     else
7902       {
7903         output_asm_insn (mips_output_move (operands[2], operands[3]),
7904                          &operands[2]);
7905         output_asm_insn (mips_output_move (operands[0], operands[1]),
7906                          operands);
7907       }
7908     return "";
7909   }
7910   [(set_attr "move_type" "load,fpload,store,fpstore")
7911    (set_attr "insn_count" "2,2,2,2")])
7913 ;; 2 HI/SI/SF/DF loads are joined.
7914 ;; P5600 does not support bonding of two LBs, hence QI mode is not included.
7915 ;; The loads must be non-volatile as they might be reordered at the time of asm
7916 ;; generation.
7917 (define_peephole2
7918   [(set (match_operand:JOIN_MODE 0 "register_operand")
7919         (match_operand:JOIN_MODE 1 "non_volatile_mem_operand"))
7920    (set (match_operand:JOIN_MODE 2 "register_operand")
7921         (match_operand:JOIN_MODE 3 "non_volatile_mem_operand"))]
7922   "ENABLE_LD_ST_PAIRS
7923    && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, true)"
7924   [(parallel [(set (match_dup 0)
7925                    (match_dup 1))
7926               (set (match_dup 2)
7927                    (match_dup 3))])]
7928   "")
7930 ;; 2 HI/SI/SF/DF stores are joined.
7931 ;; P5600 does not support bonding of two SBs, hence QI mode is not included.
7932 (define_peephole2
7933   [(set (match_operand:JOIN_MODE 0 "memory_operand")
7934         (match_operand:JOIN_MODE 1 "register_operand"))
7935    (set (match_operand:JOIN_MODE 2 "memory_operand")
7936         (match_operand:JOIN_MODE 3 "register_operand"))]
7937   "ENABLE_LD_ST_PAIRS
7938    && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, false)"
7939   [(parallel [(set (match_dup 0)
7940                    (match_dup 1))
7941               (set (match_dup 2)
7942                    (match_dup 3))])]
7943   "")
7945 ;; Match paired HImode loads.
7946 (define_insn "*join2_loadhi"
7947   [(set (match_operand:SI 0 "register_operand" "=r")
7948         (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand" "m")))
7949    (set (match_operand:SI 2 "register_operand" "=r")
7950         (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand" "m")))]
7951   "ENABLE_LD_ST_PAIRS && reload_completed"
7952   {
7953     /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7954        Hardware does not bond those loads, even when they are consecutive.
7955        However, order of the loads need to be checked for correctness.  */
7956     if (!reg_overlap_mentioned_p (operands[0], operands[1]))
7957       {
7958         output_asm_insn ("lh<u>\t%0,%1", operands);
7959         output_asm_insn ("lh<u>\t%2,%3", operands);
7960       }
7961     else
7962       {
7963         output_asm_insn ("lh<u>\t%2,%3", operands);
7964         output_asm_insn ("lh<u>\t%0,%1", operands);
7965       }
7967     return "";
7968   }
7969   [(set_attr "move_type" "load")
7970    (set_attr "insn_count" "2")])
7973 ;;  Float point MIN/MAX
7976 (define_insn "smin<mode>3"
7977   [(set (match_operand:SCALARF 0 "register_operand" "=f")
7978         (smin:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
7979                       (match_operand:SCALARF 2 "register_operand" "f")))]
7980   "ISA_HAS_FMIN_FMAX"
7981   "min.<fmt>\t%0,%1,%2"
7982   [(set_attr "type" "fminmax")
7983    (set_attr "mode" "<UNITMODE>")])
7985 (define_insn "smax<mode>3"
7986   [(set (match_operand:SCALARF 0 "register_operand" "=f")
7987         (smax:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
7988                       (match_operand:SCALARF 2 "register_operand" "f")))]
7989   "ISA_HAS_FMIN_FMAX"
7990   "max.<fmt>\t%0,%1,%2"
7991   [(set_attr "type" "fminmax")
7992   (set_attr "mode" "<UNITMODE>")])
7994 (define_insn "fmin<mode>3"
7995   [(set (match_operand:SCALARF 0 "register_operand" "=f")
7996         (unspec:SCALARF [(use (match_operand:SCALARF 1 "register_operand" "f"))
7997                          (use (match_operand:SCALARF 2 "register_operand" "f"))]
7998                         UNSPEC_FMIN))]
7999   "ISA_HAS_FMIN_FMAX"
8000   "min.<fmt>\t%0,%1,%2"
8001   [(set_attr "type" "fminmax")
8002    (set_attr "mode" "<UNITMODE>")])
8004 (define_insn "fmax<mode>3"
8005   [(set (match_operand:SCALARF 0 "register_operand" "=f")
8006         (unspec:SCALARF [(use (match_operand:SCALARF 1 "register_operand" "f"))
8007                          (use (match_operand:SCALARF 2 "register_operand" "f"))]
8008                         UNSPEC_FMAX))]
8009   "ISA_HAS_FMIN_FMAX"
8010   "max.<fmt>\t%0,%1,%2"
8011   [(set_attr "type" "fminmax")
8012   (set_attr "mode" "<UNITMODE>")])
8014 ;; 2 HI loads are joined.
8015 (define_peephole2
8016   [(set (match_operand:SI 0 "register_operand")
8017         (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand")))
8018    (set (match_operand:SI 2 "register_operand")
8019         (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand")))]
8020   "ENABLE_LD_ST_PAIRS
8021    && mips_load_store_bonding_p (operands, HImode, true)"
8022   [(parallel [(set (match_dup 0)
8023                    (any_extend:SI (match_dup 1)))
8024               (set (match_dup 2)
8025                    (any_extend:SI (match_dup 3)))])]
8026   "")
8029 ;; Synchronization instructions.
8031 (include "sync.md")
8033 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
8035 (include "mips-ps-3d.md")
8037 ; The MIPS DSP Instructions.
8039 (include "mips-dsp.md")
8041 ; The MIPS DSP REV 2 Instructions.
8043 (include "mips-dspr2.md")
8045 ; MIPS fixed-point instructions.
8046 (include "mips-fixed.md")
8048 ; microMIPS patterns.
8049 (include "micromips.md")
8051 ; Loongson MultiMedia extensions Instructions (MMI) patterns.
8052 (include "loongson-mmi.md")
8054 ; The MIPS MSA Instructions.
8055 (include "mips-msa.md")
8057 (define_c_enum "unspec" [
8058   UNSPEC_ADDRESS_FIRST