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