1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989-2013 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" [
69 (define_c_enum "unspec" [
70 ;; Unaligned accesses.
76 ;; Floating-point moves.
92 UNSPEC_POTENTIAL_CPRESTORE
97 UNSPEC_SET_GOT_VERSION
98 UNSPEC_UPDATE_GOT_VERSION
100 ;; Symbolic accesses.
105 UNSPEC_UNSHIFTED_HIGH
107 ;; MIPS16 constant pools.
109 UNSPEC_CONSTTABLE_INT
110 UNSPEC_CONSTTABLE_FLOAT
112 ;; Blockage and synchronisation.
119 ;; Cache manipulation.
121 UNSPEC_R10K_CACHE_BARRIER
123 ;; Interrupt handling.
131 ;; Used in a call expression in place of args_size. It's present for PIC
132 ;; indirect calls where it contains args_size and the function symbol.
135 ;; MIPS16 casesi jump table dispatch.
136 UNSPEC_CASESI_DISPATCH
139 UNSPEC_PROBE_STACK_RANGE
143 [(TLS_GET_TP_REGNUM 3)
145 (PIC_FUNCTION_ADDR_REGNUM 25)
146 (RETURN_ADDR_REGNUM 31)
147 (CPRESTORE_SLOT_REGNUM 76)
148 (GOT_VERSION_REGNUM 79)
150 ;; PIC long branch sequences are never longer than 100 bytes.
151 (MAX_PIC_BRANCH_LENGTH 100)
155 (include "predicates.md")
156 (include "constraints.md")
158 ;; ....................
162 ;; ....................
164 (define_attr "got" "unset,xgot_high,load"
165 (const_string "unset"))
167 ;; For jal instructions, this attribute is DIRECT when the target address
168 ;; is symbolic and INDIRECT when it is a register.
169 (define_attr "jal" "unset,direct,indirect"
170 (const_string "unset"))
172 ;; This attribute is YES if the instruction is a jal macro (not a
173 ;; real jal instruction).
175 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
176 ;; an instruction to restore $gp. Direct jals are also macros for
177 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
179 (define_attr "jal_macro" "no,yes"
180 (cond [(eq_attr "jal" "direct")
181 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
182 ? JAL_MACRO_YES : JAL_MACRO_NO)")
183 (eq_attr "jal" "indirect")
184 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
185 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
186 (const_string "no")))
188 ;; Classification of moves, extensions and truncations. Most values
189 ;; are as for "type" (see below) but there are also the following
190 ;; move-specific values:
192 ;; constN move an N-constraint integer into a MIPS16 register
193 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
194 ;; to produce a sign-extended DEST, even if SRC is not
195 ;; properly sign-extended
196 ;; ext_ins EXT, DEXT, INS or DINS instruction
197 ;; andi a single ANDI instruction
198 ;; loadpool move a constant into a MIPS16 register by loading it
200 ;; shift_shift a shift left followed by a shift right
202 ;; This attribute is used to determine the instruction's length and
203 ;; scheduling type. For doubleword moves, the attribute always describes
204 ;; the split instructions; in some cases, it is more appropriate for the
205 ;; scheduling type to be "multi" instead.
206 (define_attr "move_type"
207 "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
208 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
210 (const_string "unknown"))
212 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor"
213 (const_string "unknown"))
215 ;; Main data type used by the insn
216 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW"
217 (const_string "unknown"))
219 ;; True if the main data type is twice the size of a word.
220 (define_attr "dword_mode" "no,yes"
221 (cond [(and (eq_attr "mode" "DI,DF")
222 (not (match_test "TARGET_64BIT")))
225 (and (eq_attr "mode" "TI,TF")
226 (match_test "TARGET_64BIT"))
227 (const_string "yes")]
228 (const_string "no")))
230 ;; Attributes describing a sync loop. These loops have the form:
232 ;; if (RELEASE_BARRIER == YES) sync
234 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
235 ;; CMP = 0 [delay slot]
236 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
237 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
238 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
239 ;; $AT |= $TMP1 | $TMP3
240 ;; if (!commit (*MEM = $AT)) goto 1.
241 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
243 ;; if (ACQUIRE_BARRIER == YES) sync
246 ;; where "$" values are temporaries and where the other values are
247 ;; specified by the attributes below. Values are specified as operand
248 ;; numbers and insns are specified as enums. If no operand number is
249 ;; specified, the following values are used instead:
254 ;; - INCLUSIVE_MASK: -1
255 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
256 ;; - EXCLUSIVE_MASK: 0
258 ;; MEM and INSN1_OP2 are required.
260 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
261 ;; but the gen* programs don't yet support that.
262 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
263 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
264 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
265 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
266 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
267 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
268 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
269 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
270 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
271 (const_string "move"))
272 (define_attr "sync_insn2" "nop,and,xor,not"
273 (const_string "nop"))
274 ;; Memory model specifier.
275 ;; "0"-"9" values specify the operand that stores the memory model value.
276 ;; "10" specifies MEMMODEL_ACQ_REL,
277 ;; "11" specifies MEMMODEL_ACQUIRE.
278 (define_attr "sync_memmodel" "" (const_int 10))
280 ;; Accumulator operand for madd patterns.
281 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
283 ;; Classification of each insn.
284 ;; branch conditional branch
285 ;; jump unconditional jump
286 ;; call unconditional call
287 ;; load load instruction(s)
288 ;; fpload floating point load
289 ;; fpidxload floating point indexed load
290 ;; store store instruction(s)
291 ;; fpstore floating point store
292 ;; fpidxstore floating point indexed store
293 ;; prefetch memory prefetch (register + offset)
294 ;; prefetchx memory indexed prefetch (register + register)
295 ;; condmove conditional moves
296 ;; mtc transfer to coprocessor
297 ;; mfc transfer from coprocessor
298 ;; mthi transfer to a hi register
299 ;; mtlo transfer to a lo register
300 ;; mfhi transfer from a hi register
301 ;; mflo transfer from a lo register
302 ;; const load constant
303 ;; arith integer arithmetic instructions
304 ;; logical integer logical instructions
305 ;; shift integer shift instructions
306 ;; slt set less than instructions
307 ;; signext sign extend instructions
308 ;; clz the clz and clo instructions
309 ;; pop the pop instruction
310 ;; trap trap if instructions
311 ;; imul integer multiply 2 operands
312 ;; imul3 integer multiply 3 operands
313 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
314 ;; imadd integer multiply-add
315 ;; idiv integer divide 2 operands
316 ;; idiv3 integer divide 3 operands
317 ;; move integer register move ({,D}ADD{,U} with rt = 0)
318 ;; fmove floating point register move
319 ;; fadd floating point add/subtract
320 ;; fmul floating point multiply
321 ;; fmadd floating point multiply-add
322 ;; fdiv floating point divide
323 ;; frdiv floating point reciprocal divide
324 ;; frdiv1 floating point reciprocal divide step 1
325 ;; frdiv2 floating point reciprocal divide step 2
326 ;; fabs floating point absolute value
327 ;; fneg floating point negation
328 ;; fcmp floating point compare
329 ;; fcvt floating point convert
330 ;; fsqrt floating point square root
331 ;; frsqrt floating point reciprocal square root
332 ;; frsqrt1 floating point reciprocal square root step1
333 ;; frsqrt2 floating point reciprocal square root step2
334 ;; dspmac DSP MAC instructions not saturating the accumulator
335 ;; dspmacsat DSP MAC instructions that saturate the accumulator
336 ;; accext DSP accumulator extract instructions
337 ;; accmod DSP accumulator modify instructions
338 ;; dspalu DSP ALU instructions not saturating the result
339 ;; dspalusat DSP ALU instructions that saturate the result
340 ;; multi multiword sequence (or user asm statements)
341 ;; atomic atomic memory update instruction
342 ;; syncloop memory atomic operation implemented as a sync loop
344 ;; ghost an instruction that produces no real code
345 ;; multimem microMIPS multiword load and store
347 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
348 prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
349 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
350 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
351 frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
352 multi,atomic,syncloop,nop,ghost,multimem"
353 (cond [(eq_attr "jal" "!unset") (const_string "call")
354 (eq_attr "got" "load") (const_string "load")
356 (eq_attr "alu_type" "add,sub") (const_string "arith")
358 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
360 ;; If a doubleword move uses these expensive instructions,
361 ;; it is usually better to schedule them in the same way
362 ;; as the singleword form, rather than as "multi".
363 (eq_attr "move_type" "load") (const_string "load")
364 (eq_attr "move_type" "fpload") (const_string "fpload")
365 (eq_attr "move_type" "store") (const_string "store")
366 (eq_attr "move_type" "fpstore") (const_string "fpstore")
367 (eq_attr "move_type" "mtc") (const_string "mtc")
368 (eq_attr "move_type" "mfc") (const_string "mfc")
369 (eq_attr "move_type" "mtlo") (const_string "mtlo")
370 (eq_attr "move_type" "mflo") (const_string "mflo")
372 ;; These types of move are always single insns.
373 (eq_attr "move_type" "imul") (const_string "imul")
374 (eq_attr "move_type" "fmove") (const_string "fmove")
375 (eq_attr "move_type" "loadpool") (const_string "load")
376 (eq_attr "move_type" "signext") (const_string "signext")
377 (eq_attr "move_type" "ext_ins") (const_string "arith")
378 (eq_attr "move_type" "arith") (const_string "arith")
379 (eq_attr "move_type" "logical") (const_string "logical")
380 (eq_attr "move_type" "sll0") (const_string "shift")
381 (eq_attr "move_type" "andi") (const_string "logical")
383 ;; These types of move are always split.
384 (eq_attr "move_type" "constN,shift_shift")
385 (const_string "multi")
387 ;; These types of move are split for doubleword modes only.
388 (and (eq_attr "move_type" "move,const")
389 (eq_attr "dword_mode" "yes"))
390 (const_string "multi")
391 (eq_attr "move_type" "move") (const_string "move")
392 (eq_attr "move_type" "const") (const_string "const")
393 (eq_attr "sync_mem" "!none") (const_string "syncloop")]
394 (const_string "unknown")))
396 ;; Mode for conversion types (fcvt)
397 ;; I2S integer to float single (SI/DI to SF)
398 ;; I2D integer to float double (SI/DI to DF)
399 ;; S2I float to integer (SF to SI/DI)
400 ;; D2I float to integer (DF to SI/DI)
401 ;; D2S double to float single
402 ;; S2D float single to double
404 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
405 (const_string "unknown"))
407 ;; Is this an extended instruction in mips16 mode?
408 (define_attr "extended_mips16" "no,yes"
409 (if_then_else (ior (eq_attr "move_type" "sll0")
410 (eq_attr "type" "branch")
411 (eq_attr "jal" "direct"))
413 (const_string "no")))
415 (define_attr "compression" "none,all,micromips"
416 (const_string "none"))
418 (define_attr "enabled" "no,yes"
419 (if_then_else (ior (eq_attr "compression" "all,none")
420 (and (eq_attr "compression" "micromips")
421 (match_test "TARGET_MICROMIPS")))
423 (const_string "no")))
425 ;; Length of instruction in bytes.
426 (define_attr "length" ""
427 (cond [(and (eq_attr "extended_mips16" "yes")
428 (match_test "TARGET_MIPS16"))
431 (and (eq_attr "compression" "micromips,all")
432 (eq_attr "dword_mode" "no")
433 (match_test "TARGET_MICROMIPS"))
436 ;; Direct microMIPS branch instructions have a range of
437 ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
438 ;; If a branch is outside this range, we have a choice of two
441 ;; For PIC, an out-of-range branch like:
446 ;; becomes the equivalent of:
455 ;; The non-PIC case is similar except that we use a direct
456 ;; jump instead of an la/jr pair. Since the target of this
457 ;; jump is an absolute 28-bit bit address (the other bits
458 ;; coming from the address of the delay slot) this form cannot
459 ;; cross a 256MB boundary. We could provide the option of
460 ;; using la/jr in this case too, but we do not do so at
463 ;; The value we specify here does not account for the delay slot
464 ;; instruction, whose length is added separately. If the RTL
465 ;; pattern has no explicit delay slot, mips_adjust_insn_length
466 ;; will add the length of the implicit nop. The range of
467 ;; [-0x20000, 0x1fffc] from the address of the delay slot
468 ;; therefore translates to a range of:
470 ;; [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
471 ;; == [-0x1fffc, 0x1fff8]
473 ;; from the shorten_branches reference address.
474 (and (eq_attr "type" "branch")
475 (not (match_test "TARGET_MIPS16")))
476 (cond [;; Any variant can handle the 17-bit range.
477 (and (le (minus (match_dup 0) (pc)) (const_int 65532))
478 (le (minus (pc) (match_dup 0)) (const_int 65534)))
481 ;; The 18-bit range is OK other than for microMIPS.
482 (and (not (match_test "TARGET_MICROMIPS"))
483 (and (le (minus (match_dup 0) (pc)) (const_int 131064))
484 (le (minus (pc) (match_dup 0)) (const_int 131068))))
487 ;; The non-PIC case: branch, first delay slot, and J.
488 (match_test "TARGET_ABSOLUTE_JUMPS")
491 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
492 ;; mips_adjust_insn_length substitutes the correct length.
494 ;; Note that we can't simply use (symbol_ref ...) here
495 ;; because genattrtab needs to know the maximum length
497 (const_int MAX_PIC_BRANCH_LENGTH))
499 ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
500 ;; from the address of the following instruction, which leads
503 ;; [-(0x100 - sizeof (branch)), 0xfe]
506 ;; from the shorten_branches reference address. Extended branches
507 ;; likewise have a range of [-0x10000, 0xfffe] from the address
508 ;; of the following instruction, which leads to a range of:
510 ;; [-(0x10000 - sizeof (branch)), 0xfffe]
511 ;; == [-0xfffc, 0xfffe]
513 ;; from the reference address.
515 ;; When a branch is out of range, mips_reorg splits it into a form
516 ;; that uses in-range branches. There are four basic sequences:
518 ;; (1) Absolute addressing with a readable text segment
519 ;; (32-bit addresses):
522 ;; move $1,$2 2 bytes
523 ;; lw $2,label 2 bytes
525 ;; move $2,$1 2 bytes
526 ;; .align 2 0 or 2 bytes
528 ;; .word target 4 bytes
530 ;; (16 bytes in the worst case)
532 ;; (2) Absolute addressing with a readable text segment
533 ;; (64-bit addresses):
536 ;; move $1,$2 2 bytes
537 ;; ld $2,label 2 bytes
539 ;; move $2,$1 2 bytes
540 ;; .align 3 0 to 6 bytes
542 ;; .dword target 8 bytes
544 ;; (24 bytes in the worst case)
546 ;; (3) Absolute addressing without a readable text segment
547 ;; (which requires 32-bit addresses at present):
550 ;; move $1,$2 2 bytes
551 ;; lui $2,%hi(target) 4 bytes
554 ;; addiu $2,%lo(target) 4 bytes
556 ;; move $2,$1 2 bytes
560 ;; (4) PIC addressing (which requires 32-bit addresses at present):
563 ;; move $1,$2 2 bytes
564 ;; lw $2,cprestore 0, 2 or 4 bytes
565 ;; lw $2,%got(target)($2) 4 bytes
566 ;; addiu $2,%lo(target) 4 bytes
568 ;; move $2,$1 2 bytes
570 ;; (20 bytes in the worst case)
572 ;; Note that the conditions test adjusted lengths, whereas the
573 ;; result is an unadjusted length, and is thus twice the true value.
574 (and (eq_attr "type" "branch")
575 (match_test "TARGET_MIPS16"))
576 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
577 (le (minus (pc) (match_dup 0)) (const_int 254)))
579 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
580 (le (minus (pc) (match_dup 0)) (const_int 65532)))
582 (and (match_test "TARGET_ABICALLS")
583 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
585 (match_test "Pmode == SImode")
589 (and (eq_attr "extended_mips16" "yes")
590 (match_test "TARGET_MIPS16"))
593 ;; "Ghost" instructions occupy no space.
594 (eq_attr "type" "ghost")
597 (eq_attr "got" "load")
598 (if_then_else (match_test "TARGET_MIPS16")
601 (eq_attr "got" "xgot_high")
604 ;; In general, constant-pool loads are extended instructions.
605 (eq_attr "move_type" "loadpool")
608 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
609 ;; They are extended instructions on MIPS16 targets.
610 (eq_attr "move_type" "shift_shift")
611 (if_then_else (match_test "TARGET_MIPS16")
615 ;; Check for doubleword moves that are decomposed into two
617 (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
618 (eq_attr "dword_mode" "yes"))
621 ;; Doubleword CONST{,N} moves are split into two word
623 (and (eq_attr "move_type" "const,constN")
624 (eq_attr "dword_mode" "yes"))
625 (symbol_ref "mips_split_const_insns (operands[1]) * 4")
627 ;; Otherwise, constants, loads and stores are handled by external
629 (eq_attr "move_type" "const,constN")
630 (symbol_ref "mips_const_insns (operands[1]) * 4")
631 (eq_attr "move_type" "load,fpload")
632 (symbol_ref "mips_load_store_insns (operands[1], insn) * 4")
633 (eq_attr "move_type" "store,fpstore")
634 (cond [(not (match_test "TARGET_FIX_24K"))
635 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4")]
636 (symbol_ref "mips_load_store_insns (operands[0], insn) * 4 + 4"))
638 ;; In the worst case, a call macro will take 8 instructions:
640 ;; lui $25,%call_hi(FOO)
642 ;; lw $25,%call_lo(FOO)($25)
648 (eq_attr "jal_macro" "yes")
651 ;; Various VR4120 errata require a nop to be inserted after a macc
652 ;; instruction. The assembler does this for us, so account for
653 ;; the worst-case length here.
654 (and (eq_attr "type" "imadd")
655 (match_test "TARGET_FIX_VR4120"))
658 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
659 ;; the result of the second one is missed. The assembler should work
660 ;; around this by inserting a nop after the first dmult.
661 (and (eq_attr "type" "imul,imul3")
662 (and (eq_attr "mode" "DI")
663 (match_test "TARGET_FIX_VR4120")))
666 (eq_attr "type" "idiv,idiv3")
667 (symbol_ref "mips_idiv_insns () * 4")
669 (not (eq_attr "sync_mem" "none"))
670 (symbol_ref "mips_sync_loop_insns (insn, operands) * 4")
673 ;; Attribute describing the processor.
674 (define_enum_attr "cpu" "processor"
675 (const (symbol_ref "mips_tune")))
677 ;; The type of hardware hazard associated with this instruction.
678 ;; DELAY means that the next instruction cannot read the result
679 ;; of this one. HILO means that the next two instructions cannot
680 ;; write to HI or LO.
681 (define_attr "hazard" "none,delay,hilo"
682 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
683 (match_test "ISA_HAS_LOAD_DELAY"))
684 (const_string "delay")
686 (and (eq_attr "type" "mfc,mtc")
687 (match_test "ISA_HAS_XFER_DELAY"))
688 (const_string "delay")
690 (and (eq_attr "type" "fcmp")
691 (match_test "ISA_HAS_FCMP_DELAY"))
692 (const_string "delay")
694 ;; The r4000 multiplication patterns include an mflo instruction.
695 (and (eq_attr "type" "imul")
696 (match_test "TARGET_FIX_R4000"))
697 (const_string "hilo")
699 (and (eq_attr "type" "mfhi,mflo")
700 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
701 (const_string "hilo")]
702 (const_string "none")))
704 ;; Is it a single instruction?
705 (define_attr "single_insn" "no,yes"
706 (symbol_ref "(get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)
707 ? SINGLE_INSN_YES : SINGLE_INSN_NO)"))
709 ;; Can the instruction be put into a delay slot?
710 (define_attr "can_delay" "no,yes"
711 (if_then_else (and (eq_attr "type" "!branch,call,jump")
712 (and (eq_attr "hazard" "none")
713 (eq_attr "single_insn" "yes")))
715 (const_string "no")))
717 ;; Attribute defining whether or not we can use the branch-likely
719 (define_attr "branch_likely" "no,yes"
720 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
722 (const_string "no")))
724 ;; True if an instruction might assign to hi or lo when reloaded.
725 ;; This is used by the TUNE_MACC_CHAINS code.
726 (define_attr "may_clobber_hilo" "no,yes"
727 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
729 (const_string "no")))
731 ;; Describe a user's asm statement.
732 (define_asm_attributes
733 [(set_attr "type" "multi")
734 (set_attr "can_delay" "no")])
736 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
737 ;; from the same template.
738 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
740 ;; A copy of GPR that can be used when a pattern has two independent
742 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
744 (define_mode_iterator MOVEP1 [SI SF])
745 (define_mode_iterator MOVEP2 [SI SF])
747 ;; This mode iterator allows :HILO to be used as the mode of the
748 ;; concatenated HI and LO registers.
749 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
751 ;; This mode iterator allows :P to be used for patterns that operate on
752 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
753 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
755 ;; This mode iterator allows :MOVECC to be used anywhere that a
756 ;; conditional-move-type condition is needed.
757 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
758 (CC "TARGET_HARD_FLOAT && !TARGET_LOONGSON_2EF")])
760 ;; 32-bit integer moves for which we provide move patterns.
761 (define_mode_iterator IMOVE32
770 (V4UQQ "TARGET_DSP")])
772 ;; 64-bit modes for which we provide move patterns.
773 (define_mode_iterator MOVE64
775 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
776 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
777 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
778 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
780 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
781 (define_mode_iterator MOVE128 [TI TF])
783 ;; This mode iterator allows the QI and HI extension patterns to be
784 ;; defined from the same template.
785 (define_mode_iterator SHORT [QI HI])
787 ;; Likewise the 64-bit truncate-and-shift patterns.
788 (define_mode_iterator SUBDI [QI HI SI])
790 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
791 ;; floating-point mode is allowed.
792 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
793 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
794 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
796 ;; Like ANYF, but only applies to scalar modes.
797 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
798 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
800 ;; A floating-point mode for which moves involving FPRs may need to be split.
801 (define_mode_iterator SPLITF
802 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
803 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
804 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
805 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
806 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
807 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
808 (TF "TARGET_64BIT && TARGET_FLOAT64")])
810 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
811 ;; 32-bit version and "dsubu" in the 64-bit version.
812 (define_mode_attr d [(SI "") (DI "d")
813 (QQ "") (HQ "") (SQ "") (DQ "d")
814 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
815 (HA "") (SA "") (DA "d")
816 (UHA "") (USA "") (UDA "d")])
818 ;; Same as d but upper-case.
819 (define_mode_attr D [(SI "") (DI "D")
820 (QQ "") (HQ "") (SQ "") (DQ "D")
821 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
822 (HA "") (SA "") (DA "D")
823 (UHA "") (USA "") (UDA "D")])
825 ;; This attribute gives the length suffix for a load or store instruction.
826 ;; The same suffixes work for zero and sign extensions.
827 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
828 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
830 ;; This attributes gives the mode mask of a SHORT.
831 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
833 ;; Mode attributes for GPR loads.
834 (define_mode_attr load [(SI "lw") (DI "ld")])
835 ;; Instruction names for stores.
836 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
838 ;; Similarly for MIPS IV indexed FPR loads and stores.
839 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
840 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
842 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
843 ;; are different. Some forms of unextended addiu have an 8-bit immediate
844 ;; field but the equivalent daddiu has only a 5-bit field.
845 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
847 ;; This attribute gives the best constraint to use for registers of
849 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
851 ;; This attribute gives the format suffix for floating-point operations.
852 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
854 ;; This attribute gives the upper-case mode name for one unit of a
855 ;; floating-point mode.
856 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
858 ;; This attribute gives the integer mode that has the same size as a
860 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
861 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
862 (HA "HI") (SA "SI") (DA "DI")
863 (UHA "HI") (USA "SI") (UDA "DI")
864 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
865 (V2HQ "SI") (V2HA "SI")])
867 ;; This attribute gives the integer mode that has half the size of
868 ;; the controlling mode.
869 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
870 (V2SI "SI") (V4HI "SI") (V8QI "SI")
873 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
875 ;; In certain cases, div.s and div.ps may have a rounding error
876 ;; and/or wrong inexact flag.
878 ;; Therefore, we only allow div.s if not working around SB-1 rev2
879 ;; errata or if a slight loss of precision is OK.
880 (define_mode_attr divide_condition
881 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
882 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
884 ;; This attribute gives the conditions under which SQRT.fmt instructions
886 (define_mode_attr sqrt_condition
887 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
889 ;; This attribute gives the conditions under which RECIP.fmt and RSQRT.fmt
890 ;; instructions can be used. The MIPS32 and MIPS64 ISAs say that RECIP.D
891 ;; and RSQRT.D are unpredictable when doubles are stored in pairs of FPRs,
892 ;; so for safety's sake, we apply this restriction to all targets.
893 (define_mode_attr recip_condition
895 (DF "ISA_HAS_FP4 && TARGET_FLOAT64")
896 (V2SF "TARGET_SB1")])
898 ;; This code iterator allows signed and unsigned widening multiplications
899 ;; to use the same template.
900 (define_code_iterator any_extend [sign_extend zero_extend])
902 ;; This code iterator allows the two right shift instructions to be
903 ;; generated from the same template.
904 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
906 ;; This code iterator allows the three shift instructions to be generated
907 ;; from the same template.
908 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
910 ;; This code iterator allows unsigned and signed division to be generated
911 ;; from the same template.
912 (define_code_iterator any_div [div udiv])
914 ;; This code iterator allows unsigned and signed modulus to be generated
915 ;; from the same template.
916 (define_code_iterator any_mod [mod umod])
918 ;; This code iterator allows all native floating-point comparisons to be
919 ;; generated from the same template.
920 (define_code_iterator fcond [unordered uneq unlt unle eq lt le])
922 ;; This code iterator is used for comparisons that can be implemented
923 ;; by swapping the operands.
924 (define_code_iterator swapped_fcond [ge gt unge ungt])
926 ;; Equality operators.
927 (define_code_iterator equality_op [eq ne])
929 ;; These code iterators allow the signed and unsigned scc operations to use
930 ;; the same template.
931 (define_code_iterator any_gt [gt gtu])
932 (define_code_iterator any_ge [ge geu])
933 (define_code_iterator any_lt [lt ltu])
934 (define_code_iterator any_le [le leu])
936 (define_code_iterator any_return [return simple_return])
938 ;; <u> expands to an empty string when doing a signed operation and
939 ;; "u" when doing an unsigned operation.
940 (define_code_attr u [(sign_extend "") (zero_extend "u")
948 ;; <U> is like <u> except uppercase.
949 (define_code_attr U [(sign_extend "") (zero_extend "U")])
951 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
952 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
954 ;; <optab> expands to the name of the optab for a particular code.
955 (define_code_attr optab [(ashift "ashl")
964 (simple_return "simple_return")])
966 ;; <insn> expands to the name of the insn that implements a particular code.
967 (define_code_attr insn [(ashift "sll")
976 ;; <immediate_insn> expands to the name of the insn that implements
977 ;; a particular code to operate on immediate values.
978 (define_code_attr immediate_insn [(ior "ori")
982 (define_code_attr shift_compression [(ashift "micromips")
983 (lshiftrt "micromips")
986 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
987 (define_code_attr fcond [(unordered "un")
995 ;; Similar, but for swapped conditions.
996 (define_code_attr swapped_fcond [(ge "le")
1001 ;; The value of the bit when the branch is taken for branch_bit patterns.
1002 ;; Comparison is always against zero so this depends on the operator.
1003 (define_code_attr bbv [(eq "0") (ne "1")])
1005 ;; This is the inverse value of bbv.
1006 (define_code_attr bbinv [(eq "1") (ne "0")])
1008 ;; .........................
1010 ;; Branch, call and jump delay slots
1012 ;; .........................
1014 (define_delay (and (eq_attr "type" "branch")
1015 (not (match_test "TARGET_MIPS16"))
1016 (eq_attr "branch_likely" "yes"))
1017 [(eq_attr "can_delay" "yes")
1019 (eq_attr "can_delay" "yes")])
1021 ;; Branches that don't have likely variants do not annul on false.
1022 (define_delay (and (eq_attr "type" "branch")
1023 (not (match_test "TARGET_MIPS16"))
1024 (eq_attr "branch_likely" "no"))
1025 [(eq_attr "can_delay" "yes")
1029 (define_delay (eq_attr "type" "jump")
1030 [(eq_attr "can_delay" "yes")
1034 (define_delay (and (eq_attr "type" "call")
1035 (eq_attr "jal_macro" "no"))
1036 [(eq_attr "can_delay" "yes")
1040 ;; Pipeline descriptions.
1042 ;; generic.md provides a fallback for processors without a specific
1043 ;; pipeline description. It is derived from the old define_function_unit
1044 ;; version and uses the "alu" and "imuldiv" units declared below.
1046 ;; Some of the processor-specific files are also derived from old
1047 ;; define_function_unit descriptions and simply override the parts of
1048 ;; generic.md that don't apply. The other processor-specific files
1049 ;; are self-contained.
1050 (define_automaton "alu,imuldiv")
1052 (define_cpu_unit "alu" "alu")
1053 (define_cpu_unit "imuldiv" "imuldiv")
1055 ;; Ghost instructions produce no real code and introduce no hazards.
1056 ;; They exist purely to express an effect on dataflow.
1057 (define_insn_reservation "ghost" 0
1058 (eq_attr "type" "ghost")
1078 (include "10000.md")
1079 (include "loongson2ef.md")
1080 (include "loongson3a.md")
1081 (include "octeon.md")
1083 (include "sr71k.md")
1086 (include "generic.md")
1089 ;; ....................
1091 ;; CONDITIONAL TRAPS
1093 ;; ....................
1097 [(trap_if (const_int 1) (const_int 0))]
1100 if (ISA_HAS_COND_TRAP)
1101 return "teq\t$0,$0";
1102 else if (TARGET_MIPS16)
1107 [(set_attr "type" "trap")])
1109 (define_expand "ctrap<mode>4"
1110 [(trap_if (match_operator 0 "comparison_operator"
1111 [(match_operand:GPR 1 "reg_or_0_operand")
1112 (match_operand:GPR 2 "arith_operand")])
1113 (match_operand 3 "const_0_operand"))]
1116 mips_expand_conditional_trap (operands[0]);
1120 (define_insn "*conditional_trap<mode>"
1121 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1122 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1123 (match_operand:GPR 2 "arith_operand" "dI")])
1127 [(set_attr "type" "trap")])
1130 ;; ....................
1134 ;; ....................
1137 (define_insn "add<mode>3"
1138 [(set (match_operand:ANYF 0 "register_operand" "=f")
1139 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1140 (match_operand:ANYF 2 "register_operand" "f")))]
1142 "add.<fmt>\t%0,%1,%2"
1143 [(set_attr "type" "fadd")
1144 (set_attr "mode" "<UNITMODE>")])
1146 (define_expand "add<mode>3"
1147 [(set (match_operand:GPR 0 "register_operand")
1148 (plus:GPR (match_operand:GPR 1 "register_operand")
1149 (match_operand:GPR 2 "arith_operand")))]
1152 (define_insn "*add<mode>3"
1153 [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1154 (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1155 (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1158 if (which_alternative == 0
1159 || which_alternative == 1)
1160 return "<d>addu\t%0,%1,%2";
1162 return "<d>addiu\t%0,%1,%2";
1164 [(set_attr "alu_type" "add")
1165 (set_attr "compression" "micromips,*,micromips,micromips,micromips,micromips,*")
1166 (set_attr "mode" "<MODE>")])
1168 (define_insn "*add<mode>3_mips16"
1169 [(set (match_operand:GPR 0 "register_operand" "=ks,d,d,d,d")
1170 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,0,d,d")
1171 (match_operand:GPR 2 "arith_operand" "Q,Q,Q,O,d")))]
1179 [(set_attr "alu_type" "add")
1180 (set_attr "mode" "<MODE>")
1181 (set_attr_alternative "length"
1182 [(if_then_else (match_operand 2 "m16_simm8_8")
1185 (if_then_else (match_operand 2 "m16_uimm<si8_di5>_4")
1188 (if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
1191 (if_then_else (match_operand 2 "m16_simm4_1")
1196 ;; On the mips16, we can sometimes split an add of a constant which is
1197 ;; a 4 byte instruction into two adds which are both 2 byte
1198 ;; instructions. There are two cases: one where we are adding a
1199 ;; constant plus a register to another register, and one where we are
1200 ;; simply adding a constant to a register.
1203 [(set (match_operand:SI 0 "d_operand")
1204 (plus:SI (match_dup 0)
1205 (match_operand:SI 1 "const_int_operand")))]
1206 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1207 && ((INTVAL (operands[1]) > 0x7f
1208 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1209 || (INTVAL (operands[1]) < - 0x80
1210 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1211 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1212 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1214 HOST_WIDE_INT val = INTVAL (operands[1]);
1218 operands[1] = GEN_INT (0x7f);
1219 operands[2] = GEN_INT (val - 0x7f);
1223 operands[1] = GEN_INT (- 0x80);
1224 operands[2] = GEN_INT (val + 0x80);
1229 [(set (match_operand:SI 0 "d_operand")
1230 (plus:SI (match_operand:SI 1 "d_operand")
1231 (match_operand:SI 2 "const_int_operand")))]
1232 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1233 && REGNO (operands[0]) != REGNO (operands[1])
1234 && ((INTVAL (operands[2]) > 0x7
1235 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1236 || (INTVAL (operands[2]) < - 0x8
1237 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1238 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1239 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1241 HOST_WIDE_INT val = INTVAL (operands[2]);
1245 operands[2] = GEN_INT (0x7);
1246 operands[3] = GEN_INT (val - 0x7);
1250 operands[2] = GEN_INT (- 0x8);
1251 operands[3] = GEN_INT (val + 0x8);
1256 [(set (match_operand:DI 0 "d_operand")
1257 (plus:DI (match_dup 0)
1258 (match_operand:DI 1 "const_int_operand")))]
1259 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1260 && ((INTVAL (operands[1]) > 0xf
1261 && INTVAL (operands[1]) <= 0xf + 0xf)
1262 || (INTVAL (operands[1]) < - 0x10
1263 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1264 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1265 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1267 HOST_WIDE_INT val = INTVAL (operands[1]);
1271 operands[1] = GEN_INT (0xf);
1272 operands[2] = GEN_INT (val - 0xf);
1276 operands[1] = GEN_INT (- 0x10);
1277 operands[2] = GEN_INT (val + 0x10);
1282 [(set (match_operand:DI 0 "d_operand")
1283 (plus:DI (match_operand:DI 1 "d_operand")
1284 (match_operand:DI 2 "const_int_operand")))]
1285 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1286 && REGNO (operands[0]) != REGNO (operands[1])
1287 && ((INTVAL (operands[2]) > 0x7
1288 && INTVAL (operands[2]) <= 0x7 + 0xf)
1289 || (INTVAL (operands[2]) < - 0x8
1290 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1291 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1292 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1294 HOST_WIDE_INT val = INTVAL (operands[2]);
1298 operands[2] = GEN_INT (0x7);
1299 operands[3] = GEN_INT (val - 0x7);
1303 operands[2] = GEN_INT (- 0x8);
1304 operands[3] = GEN_INT (val + 0x8);
1308 (define_insn "*addsi3_extended"
1309 [(set (match_operand:DI 0 "register_operand" "=d,d")
1311 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1312 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1313 "TARGET_64BIT && !TARGET_MIPS16"
1317 [(set_attr "alu_type" "add")
1318 (set_attr "mode" "SI")])
1320 ;; Split this insn so that the addiu splitters can have a crack at it.
1321 ;; Use a conservative length estimate until the split.
1322 (define_insn_and_split "*addsi3_extended_mips16"
1323 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1325 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1326 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1327 "TARGET_64BIT && TARGET_MIPS16"
1329 "&& reload_completed"
1330 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1331 { operands[3] = gen_lowpart (SImode, operands[0]); }
1332 [(set_attr "alu_type" "add")
1333 (set_attr "mode" "SI")
1334 (set_attr "extended_mips16" "yes")])
1336 ;; Combiner patterns for unsigned byte-add.
1338 (define_insn "*baddu_si"
1339 [(set (match_operand:SI 0 "register_operand" "=d")
1341 (plus:QI (match_operand:QI 1 "register_operand" "d")
1342 (match_operand:QI 2 "register_operand" "d"))))]
1345 [(set_attr "alu_type" "add")])
1347 (define_insn "*baddu_di<mode>"
1348 [(set (match_operand:GPR 0 "register_operand" "=d")
1350 (plus:QI (truncate:QI (match_operand:DI 1 "register_operand" "d"))
1351 (truncate:QI (match_operand:DI 2 "register_operand" "d")))))]
1352 "ISA_HAS_BADDU && TARGET_64BIT"
1354 [(set_attr "alu_type" "add")])
1357 ;; ....................
1361 ;; ....................
1364 (define_insn "sub<mode>3"
1365 [(set (match_operand:ANYF 0 "register_operand" "=f")
1366 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1367 (match_operand:ANYF 2 "register_operand" "f")))]
1369 "sub.<fmt>\t%0,%1,%2"
1370 [(set_attr "type" "fadd")
1371 (set_attr "mode" "<UNITMODE>")])
1373 (define_insn "sub<mode>3"
1374 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1375 (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1376 (match_operand:GPR 2 "register_operand" "!u,d")))]
1379 [(set_attr "alu_type" "sub")
1380 (set_attr "compression" "micromips,*")
1381 (set_attr "mode" "<MODE>")])
1383 (define_insn "*subsi3_extended"
1384 [(set (match_operand:DI 0 "register_operand" "=d")
1386 (minus:SI (match_operand:SI 1 "register_operand" "d")
1387 (match_operand:SI 2 "register_operand" "d"))))]
1390 [(set_attr "alu_type" "sub")
1391 (set_attr "mode" "DI")])
1394 ;; ....................
1398 ;; ....................
1401 (define_expand "mul<mode>3"
1402 [(set (match_operand:SCALARF 0 "register_operand")
1403 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1404 (match_operand:SCALARF 2 "register_operand")))]
1408 (define_insn "*mul<mode>3"
1409 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1410 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1411 (match_operand:SCALARF 2 "register_operand" "f")))]
1412 "!TARGET_4300_MUL_FIX"
1413 "mul.<fmt>\t%0,%1,%2"
1414 [(set_attr "type" "fmul")
1415 (set_attr "mode" "<MODE>")])
1417 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1418 ;; operands may corrupt immediately following multiplies. This is a
1419 ;; simple fix to insert NOPs.
1421 (define_insn "*mul<mode>3_r4300"
1422 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1423 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1424 (match_operand:SCALARF 2 "register_operand" "f")))]
1425 "TARGET_4300_MUL_FIX"
1426 "mul.<fmt>\t%0,%1,%2\;nop"
1427 [(set_attr "type" "fmul")
1428 (set_attr "mode" "<MODE>")
1429 (set_attr "length" "8")])
1431 (define_insn "mulv2sf3"
1432 [(set (match_operand:V2SF 0 "register_operand" "=f")
1433 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1434 (match_operand:V2SF 2 "register_operand" "f")))]
1435 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1437 [(set_attr "type" "fmul")
1438 (set_attr "mode" "SF")])
1440 ;; The original R4000 has a cpu bug. If a double-word or a variable
1441 ;; shift executes while an integer multiplication is in progress, the
1442 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1443 ;; with the mult on the R4000.
1445 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1446 ;; (also valid for MIPS R4000MC processors):
1448 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1449 ;; this errata description.
1450 ;; The following code sequence causes the R4000 to incorrectly
1451 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1452 ;; instruction. If the dsra32 instruction is executed during an
1453 ;; integer multiply, the dsra32 will only shift by the amount in
1454 ;; specified in the instruction rather than the amount plus 32
1456 ;; instruction 1: mult rs,rt integer multiply
1457 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1458 ;; right arithmetic + 32
1459 ;; Workaround: A dsra32 instruction placed after an integer
1460 ;; multiply should not be one of the 11 instructions after the
1461 ;; multiply instruction."
1465 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1466 ;; the following description.
1467 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1468 ;; 64-bit versions) may produce incorrect results under the
1469 ;; following conditions:
1470 ;; 1) An integer multiply is currently executing
1471 ;; 2) These types of shift instructions are executed immediately
1472 ;; following an integer divide instruction.
1474 ;; 1) Make sure no integer multiply is running wihen these
1475 ;; instruction are executed. If this cannot be predicted at
1476 ;; compile time, then insert a "mfhi" to R0 instruction
1477 ;; immediately after the integer multiply instruction. This
1478 ;; will cause the integer multiply to complete before the shift
1480 ;; 2) Separate integer divide and these two classes of shift
1481 ;; instructions by another instruction or a noop."
1483 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1486 (define_expand "mul<mode>3"
1487 [(set (match_operand:GPR 0 "register_operand")
1488 (mult:GPR (match_operand:GPR 1 "register_operand")
1489 (match_operand:GPR 2 "register_operand")))]
1494 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
1495 emit_insn (gen_mul<mode>3_mul3_loongson (operands[0], operands[1],
1497 else if (ISA_HAS_<D>MUL3)
1498 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1499 else if (TARGET_MIPS16)
1501 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1502 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1503 emit_move_insn (operands[0], lo);
1505 else if (TARGET_FIX_R4000)
1506 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1509 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1513 (define_insn "mul<mode>3_mul3_loongson"
1514 [(set (match_operand:GPR 0 "register_operand" "=d")
1515 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1516 (match_operand:GPR 2 "register_operand" "d")))]
1517 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A"
1519 if (TARGET_LOONGSON_2EF)
1520 return "<d>multu.g\t%0,%1,%2";
1522 return "gs<d>multu\t%0,%1,%2";
1524 [(set_attr "type" "imul3nc")
1525 (set_attr "mode" "<MODE>")])
1527 (define_insn "mul<mode>3_mul3"
1528 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1529 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1530 (match_operand:GPR 2 "register_operand" "d,d")))
1531 (clobber (match_scratch:GPR 3 "=l,X"))]
1534 if (which_alternative == 1)
1535 return "<d>mult\t%1,%2";
1536 if (<MODE>mode == SImode && TARGET_MIPS3900)
1537 return "mult\t%0,%1,%2";
1538 return "<d>mul\t%0,%1,%2";
1540 [(set_attr "type" "imul3,imul")
1541 (set_attr "mode" "<MODE>")])
1543 ;; If a register gets allocated to LO, and we spill to memory, the reload
1544 ;; will include a move from LO to a GPR. Merge it into the multiplication
1545 ;; if it can set the GPR directly.
1548 ;; Operand 1: GPR (1st multiplication operand)
1549 ;; Operand 2: GPR (2nd multiplication operand)
1550 ;; Operand 3: GPR (destination)
1553 [(set (match_operand:SI 0 "lo_operand")
1554 (mult:SI (match_operand:SI 1 "d_operand")
1555 (match_operand:SI 2 "d_operand")))
1556 (clobber (scratch:SI))])
1557 (set (match_operand:SI 3 "d_operand")
1559 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1562 (mult:SI (match_dup 1)
1564 (clobber (match_dup 0))])])
1566 (define_insn "mul<mode>3_internal"
1567 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1568 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1569 (match_operand:GPR 2 "register_operand" "d")))]
1572 [(set_attr "type" "imul")
1573 (set_attr "mode" "<MODE>")])
1575 (define_insn "mul<mode>3_r4000"
1576 [(set (match_operand:GPR 0 "register_operand" "=d")
1577 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1578 (match_operand:GPR 2 "register_operand" "d")))
1579 (clobber (match_scratch:GPR 3 "=l"))]
1581 "<d>mult\t%1,%2\;mflo\t%0"
1582 [(set_attr "type" "imul")
1583 (set_attr "mode" "<MODE>")
1584 (set_attr "length" "8")])
1586 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1587 ;; of "mult; mflo". They have the same latency, but the first form gives
1588 ;; us an extra cycle to compute the operands.
1591 ;; Operand 1: GPR (1st multiplication operand)
1592 ;; Operand 2: GPR (2nd multiplication operand)
1593 ;; Operand 3: GPR (destination)
1595 [(set (match_operand:SI 0 "lo_operand")
1596 (mult:SI (match_operand:SI 1 "d_operand")
1597 (match_operand:SI 2 "d_operand")))
1598 (set (match_operand:SI 3 "d_operand")
1600 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1605 (plus:SI (mult:SI (match_dup 1)
1609 (plus:SI (mult:SI (match_dup 1)
1613 ;; Multiply-accumulate patterns
1615 ;; This pattern is first matched by combine, which tries to use the
1616 ;; pattern wherever it can. We don't know until later whether it
1617 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1618 ;; so we need to keep both options open.
1620 ;; The second alternative has a "?" marker because it is generally
1621 ;; one instruction more costly than the first alternative. This "?"
1622 ;; marker is enough to convey the relative costs to the register
1625 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1626 ;; reloads of the other operands, even though operands 4 and 5 need no
1627 ;; copy instructions. Reload therefore thinks that the second alternative
1628 ;; is two reloads more costly than the first. We add "*?*?" to the first
1629 ;; alternative as a counterweight.
1630 (define_insn "*mul_acc_si"
1631 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1632 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1633 (match_operand:SI 2 "register_operand" "d,d"))
1634 (match_operand:SI 3 "register_operand" "0,d")))
1635 (clobber (match_scratch:SI 4 "=X,l"))
1636 (clobber (match_scratch:SI 5 "=X,&d"))]
1637 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1641 [(set_attr "type" "imadd")
1642 (set_attr "accum_in" "3")
1643 (set_attr "mode" "SI")
1644 (set_attr "length" "4,8")])
1646 ;; The same idea applies here. The middle alternative needs one less
1647 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1648 (define_insn "*mul_acc_si_r3900"
1649 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d*?,d?")
1650 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1651 (match_operand:SI 2 "register_operand" "d,d,d"))
1652 (match_operand:SI 3 "register_operand" "0,l,d")))
1653 (clobber (match_scratch:SI 4 "=X,3,l"))
1654 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1655 "TARGET_MIPS3900 && !TARGET_MIPS16"
1660 [(set_attr "type" "imadd")
1661 (set_attr "accum_in" "3")
1662 (set_attr "mode" "SI")
1663 (set_attr "length" "4,4,8")])
1665 ;; Split *mul_acc_si if both the source and destination accumulator
1668 [(set (match_operand:SI 0 "d_operand")
1669 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1670 (match_operand:SI 2 "d_operand"))
1671 (match_operand:SI 3 "d_operand")))
1672 (clobber (match_operand:SI 4 "lo_operand"))
1673 (clobber (match_operand:SI 5 "d_operand"))]
1675 [(parallel [(set (match_dup 5)
1676 (mult:SI (match_dup 1) (match_dup 2)))
1677 (clobber (match_dup 4))])
1678 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1681 (define_insn "*macc"
1682 [(set (match_operand:SI 0 "register_operand" "=l,d")
1683 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1684 (match_operand:SI 2 "register_operand" "d,d"))
1685 (match_operand:SI 3 "register_operand" "0,l")))
1686 (clobber (match_scratch:SI 4 "=X,3"))]
1689 if (which_alternative == 1)
1690 return "macc\t%0,%1,%2";
1691 else if (TARGET_MIPS5500)
1692 return "madd\t%1,%2";
1694 /* The VR4130 assumes that there is a two-cycle latency between a macc
1695 that "writes" to $0 and an instruction that reads from it. We avoid
1696 this by assigning to $1 instead. */
1697 return "%[macc\t%@,%1,%2%]";
1699 [(set_attr "type" "imadd")
1700 (set_attr "accum_in" "3")
1701 (set_attr "mode" "SI")])
1703 (define_insn "*msac"
1704 [(set (match_operand:SI 0 "register_operand" "=l,d")
1705 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1706 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1707 (match_operand:SI 3 "register_operand" "d,d"))))
1708 (clobber (match_scratch:SI 4 "=X,1"))]
1711 if (which_alternative == 1)
1712 return "msac\t%0,%2,%3";
1713 else if (TARGET_MIPS5500)
1714 return "msub\t%2,%3";
1716 return "msac\t$0,%2,%3";
1718 [(set_attr "type" "imadd")
1719 (set_attr "accum_in" "1")
1720 (set_attr "mode" "SI")])
1722 ;; An msac-like instruction implemented using negation and a macc.
1723 (define_insn_and_split "*msac_using_macc"
1724 [(set (match_operand:SI 0 "register_operand" "=l,d")
1725 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1726 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1727 (match_operand:SI 3 "register_operand" "d,d"))))
1728 (clobber (match_scratch:SI 4 "=X,1"))
1729 (clobber (match_scratch:SI 5 "=d,d"))]
1730 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1732 "&& reload_completed"
1734 (neg:SI (match_dup 3)))
1737 (plus:SI (mult:SI (match_dup 2)
1740 (clobber (match_dup 4))])]
1742 [(set_attr "type" "imadd")
1743 (set_attr "accum_in" "1")
1744 (set_attr "length" "8")])
1746 ;; Patterns generated by the define_peephole2 below.
1748 (define_insn "*macc2"
1749 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1750 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1751 (match_operand:SI 2 "register_operand" "d"))
1753 (set (match_operand:SI 3 "register_operand" "=d")
1754 (plus:SI (mult:SI (match_dup 1)
1757 "ISA_HAS_MACC && reload_completed"
1759 [(set_attr "type" "imadd")
1760 (set_attr "accum_in" "0")
1761 (set_attr "mode" "SI")])
1763 (define_insn "*msac2"
1764 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1765 (minus:SI (match_dup 0)
1766 (mult:SI (match_operand:SI 1 "register_operand" "d")
1767 (match_operand:SI 2 "register_operand" "d"))))
1768 (set (match_operand:SI 3 "register_operand" "=d")
1769 (minus:SI (match_dup 0)
1770 (mult:SI (match_dup 1)
1772 "ISA_HAS_MSAC && reload_completed"
1774 [(set_attr "type" "imadd")
1775 (set_attr "accum_in" "0")
1776 (set_attr "mode" "SI")])
1778 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1782 ;; Operand 1: macc/msac
1783 ;; Operand 2: GPR (destination)
1786 [(set (match_operand:SI 0 "lo_operand")
1787 (match_operand:SI 1 "macc_msac_operand"))
1788 (clobber (scratch:SI))])
1789 (set (match_operand:SI 2 "d_operand")
1792 [(parallel [(set (match_dup 0)
1797 ;; When we have a three-address multiplication instruction, it should
1798 ;; be faster to do a separate multiply and add, rather than moving
1799 ;; something into LO in order to use a macc instruction.
1801 ;; This peephole needs a scratch register to cater for the case when one
1802 ;; of the multiplication operands is the same as the destination.
1804 ;; Operand 0: GPR (scratch)
1806 ;; Operand 2: GPR (addend)
1807 ;; Operand 3: GPR (destination)
1808 ;; Operand 4: macc/msac
1809 ;; Operand 5: new multiplication
1810 ;; Operand 6: new addition/subtraction
1812 [(match_scratch:SI 0 "d")
1813 (set (match_operand:SI 1 "lo_operand")
1814 (match_operand:SI 2 "d_operand"))
1817 [(set (match_operand:SI 3 "d_operand")
1818 (match_operand:SI 4 "macc_msac_operand"))
1819 (clobber (match_dup 1))])]
1820 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1821 [(parallel [(set (match_dup 0)
1823 (clobber (match_dup 1))])
1827 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1828 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1829 operands[2], operands[0]);
1832 ;; Same as above, except LO is the initial target of the macc.
1834 ;; Operand 0: GPR (scratch)
1836 ;; Operand 2: GPR (addend)
1837 ;; Operand 3: macc/msac
1838 ;; Operand 4: GPR (destination)
1839 ;; Operand 5: new multiplication
1840 ;; Operand 6: new addition/subtraction
1842 [(match_scratch:SI 0 "d")
1843 (set (match_operand:SI 1 "lo_operand")
1844 (match_operand:SI 2 "d_operand"))
1848 (match_operand:SI 3 "macc_msac_operand"))
1849 (clobber (scratch:SI))])
1851 (set (match_operand:SI 4 "d_operand")
1853 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1854 [(parallel [(set (match_dup 0)
1856 (clobber (match_dup 1))])
1860 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1861 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1862 operands[2], operands[0]);
1865 ;; See the comment above *mul_add_si for details.
1866 (define_insn "*mul_sub_si"
1867 [(set (match_operand:SI 0 "register_operand" "=l*?*?,d?")
1868 (minus:SI (match_operand:SI 1 "register_operand" "0,d")
1869 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1870 (match_operand:SI 3 "register_operand" "d,d"))))
1871 (clobber (match_scratch:SI 4 "=X,l"))
1872 (clobber (match_scratch:SI 5 "=X,&d"))]
1873 "GENERATE_MADD_MSUB"
1877 [(set_attr "type" "imadd")
1878 (set_attr "accum_in" "1")
1879 (set_attr "mode" "SI")
1880 (set_attr "length" "4,8")])
1882 ;; Split *mul_sub_si if both the source and destination accumulator
1885 [(set (match_operand:SI 0 "d_operand")
1886 (minus:SI (match_operand:SI 1 "d_operand")
1887 (mult:SI (match_operand:SI 2 "d_operand")
1888 (match_operand:SI 3 "d_operand"))))
1889 (clobber (match_operand:SI 4 "lo_operand"))
1890 (clobber (match_operand:SI 5 "d_operand"))]
1892 [(parallel [(set (match_dup 5)
1893 (mult:SI (match_dup 2) (match_dup 3)))
1894 (clobber (match_dup 4))])
1895 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
1898 (define_insn "*muls"
1899 [(set (match_operand:SI 0 "register_operand" "=l,d")
1900 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1901 (match_operand:SI 2 "register_operand" "d,d"))))
1902 (clobber (match_scratch:SI 3 "=X,l"))]
1907 [(set_attr "type" "imul,imul3")
1908 (set_attr "mode" "SI")])
1910 (define_expand "<u>mulsidi3"
1911 [(set (match_operand:DI 0 "register_operand")
1912 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1913 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1914 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
1916 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
1917 emit_insn (fn (operands[0], operands[1], operands[2]));
1921 (define_expand "<u>mulsidi3_32bit_mips16"
1922 [(set (match_operand:DI 0 "register_operand")
1923 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1924 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1925 "!TARGET_64BIT && TARGET_MIPS16"
1929 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
1930 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
1931 emit_move_insn (operands[0], hilo);
1935 ;; As well as being named patterns, these instructions are used by the
1936 ;; __builtin_mips_mult<u>() functions. We must always make those functions
1937 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
1938 (define_insn "<u>mulsidi3_32bit"
1939 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
1940 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1941 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1942 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP)"
1944 if (ISA_HAS_DSP_MULT)
1945 return "mult<u>\t%q0,%1,%2";
1947 return "mult<u>\t%1,%2";
1949 [(set_attr "type" "imul")
1950 (set_attr "mode" "SI")])
1952 (define_insn "<u>mulsidi3_32bit_r4000"
1953 [(set (match_operand:DI 0 "register_operand" "=d")
1954 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1955 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1956 (clobber (match_scratch:DI 3 "=x"))]
1957 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP"
1958 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
1959 [(set_attr "type" "imul")
1960 (set_attr "mode" "SI")
1961 (set_attr "length" "12")])
1963 (define_insn_and_split "<u>mulsidi3_64bit"
1964 [(set (match_operand:DI 0 "register_operand" "=d")
1965 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1966 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1967 (clobber (match_scratch:TI 3 "=x"))
1968 (clobber (match_scratch:DI 4 "=d"))]
1969 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3 && !TARGET_MIPS16"
1971 "&& reload_completed"
1974 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1975 operands[2], operands[4]));
1978 [(set_attr "type" "imul")
1979 (set_attr "mode" "SI")
1980 (set (attr "length")
1981 (if_then_else (match_test "ISA_HAS_EXT_INS")
1985 (define_expand "<u>mulsidi3_64bit_mips16"
1986 [(set (match_operand:DI 0 "register_operand")
1987 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1988 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
1989 "TARGET_64BIT && TARGET_MIPS16"
1991 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
1992 operands[2], gen_reg_rtx (DImode)));
1996 (define_expand "<u>mulsidi3_64bit_split"
1997 [(set (match_operand:DI 0 "register_operand")
1998 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1999 (any_extend:DI (match_operand:SI 2 "register_operand"))))
2000 (clobber (match_operand:DI 3 "register_operand"))]
2005 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2006 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2008 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2009 emit_insn (gen_mfhidi_ti (operands[3], hilo));
2011 if (ISA_HAS_EXT_INS)
2012 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2016 /* Zero-extend the low part. */
2017 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2018 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2020 /* Shift the high part into place. */
2021 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2023 /* OR the two halves together. */
2024 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2029 (define_insn "<u>mulsidi3_64bit_hilo"
2030 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2033 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2034 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2036 "TARGET_64BIT && !TARGET_FIX_R4000"
2038 [(set_attr "type" "imul")
2039 (set_attr "mode" "SI")])
2041 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2042 (define_insn "mulsidi3_64bit_dmul"
2043 [(set (match_operand:DI 0 "register_operand" "=d")
2044 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2045 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2046 (clobber (match_scratch:DI 3 "=l"))]
2047 "TARGET_64BIT && ISA_HAS_DMUL3"
2049 [(set_attr "type" "imul3")
2050 (set_attr "mode" "DI")])
2052 ;; Widening multiply with negation.
2053 (define_insn "*muls<u>_di"
2054 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2057 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2058 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2059 "!TARGET_64BIT && ISA_HAS_MULS"
2061 [(set_attr "type" "imul")
2062 (set_attr "mode" "SI")])
2064 ;; As well as being named patterns, these instructions are used by the
2065 ;; __builtin_mips_msub<u>() functions. We must always make those functions
2066 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2068 ;; This leads to a slight inconsistency. We honor any tuning overrides
2069 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2070 ;; even if !ISA_HAS_DSP_MULT.
2071 (define_insn "<u>msubsidi4"
2072 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2074 (match_operand:DI 3 "muldiv_target_operand" "0")
2076 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2077 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2078 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2080 if (ISA_HAS_DSP_MULT)
2081 return "msub<u>\t%q0,%1,%2";
2082 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2083 return "msub<u>\t%1,%2";
2085 return "msac<u>\t$0,%1,%2";
2087 [(set_attr "type" "imadd")
2088 (set_attr "accum_in" "3")
2089 (set_attr "mode" "SI")])
2091 ;; _highpart patterns
2093 (define_expand "<su>mulsi3_highpart"
2094 [(set (match_operand:SI 0 "register_operand")
2097 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2098 (any_extend:DI (match_operand:SI 2 "register_operand")))
2103 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2106 else if (TARGET_MIPS16)
2107 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2110 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2115 (define_insn_and_split "<su>mulsi3_highpart_internal"
2116 [(set (match_operand:SI 0 "register_operand" "=d")
2119 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2120 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2122 (clobber (match_scratch:SI 3 "=l"))]
2123 "!ISA_HAS_MULHI && !TARGET_MIPS16"
2124 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2125 "&& reload_completed && !TARGET_FIX_R4000"
2128 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2132 [(set_attr "type" "imul")
2133 (set_attr "mode" "SI")
2134 (set_attr "length" "8")])
2136 (define_expand "<su>mulsi3_highpart_split"
2137 [(set (match_operand:SI 0 "register_operand")
2140 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2141 (any_extend:DI (match_operand:SI 2 "register_operand")))
2149 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2150 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2151 emit_insn (gen_mfhisi_ti (operands[0], hilo));
2155 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2156 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2157 emit_insn (gen_mfhisi_di (operands[0], hilo));
2162 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2163 [(set (match_operand:SI 0 "register_operand" "=d")
2167 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2168 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2170 (clobber (match_scratch:SI 3 "=l"))]
2172 "mulhi<u>\t%0,%1,%2"
2173 [(set_attr "type" "imul3")
2174 (set_attr "mode" "SI")])
2176 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2177 [(set (match_operand:SI 0 "register_operand" "=d")
2182 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2183 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2185 (clobber (match_scratch:SI 3 "=l"))]
2187 "mulshi<u>\t%0,%1,%2"
2188 [(set_attr "type" "imul3")
2189 (set_attr "mode" "SI")])
2191 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2192 ;; errata MD(0), which says that dmultu does not always produce the
2194 (define_expand "<su>muldi3_highpart"
2195 [(set (match_operand:DI 0 "register_operand")
2198 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2199 (any_extend:TI (match_operand:DI 2 "register_operand")))
2201 "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2204 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2207 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2212 (define_insn_and_split "<su>muldi3_highpart_internal"
2213 [(set (match_operand:DI 0 "register_operand" "=d")
2216 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2217 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2219 (clobber (match_scratch:DI 3 "=l"))]
2222 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2223 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2224 "&& reload_completed && !TARGET_FIX_R4000"
2227 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2231 [(set_attr "type" "imul")
2232 (set_attr "mode" "DI")
2233 (set_attr "length" "8")])
2235 (define_expand "<su>muldi3_highpart_split"
2236 [(set (match_operand:DI 0 "register_operand")
2239 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2240 (any_extend:TI (match_operand:DI 2 "register_operand")))
2246 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2247 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2248 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2252 (define_expand "<u>mulditi3"
2253 [(set (match_operand:TI 0 "register_operand")
2254 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2255 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2256 "TARGET_64BIT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2262 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2263 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2264 emit_move_insn (operands[0], hilo);
2266 else if (TARGET_FIX_R4000)
2267 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2269 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2274 (define_insn "<u>mulditi3_internal"
2275 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2276 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2277 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2279 && !TARGET_FIX_R4000
2280 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2282 [(set_attr "type" "imul")
2283 (set_attr "mode" "DI")])
2285 (define_insn "<u>mulditi3_r4000"
2286 [(set (match_operand:TI 0 "register_operand" "=d")
2287 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2288 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2289 (clobber (match_scratch:TI 3 "=x"))]
2292 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2293 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2294 [(set_attr "type" "imul")
2295 (set_attr "mode" "DI")
2296 (set_attr "length" "12")])
2298 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2299 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2301 (define_insn "madsi"
2302 [(set (match_operand:SI 0 "register_operand" "+l")
2303 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2304 (match_operand:SI 2 "register_operand" "d"))
2308 [(set_attr "type" "imadd")
2309 (set_attr "accum_in" "0")
2310 (set_attr "mode" "SI")])
2312 ;; See the comment above <u>msubsidi4 for the relationship between
2313 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2314 (define_insn "<u>maddsidi4"
2315 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2317 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2318 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2319 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2320 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2324 return "mad<u>\t%1,%2";
2325 else if (ISA_HAS_DSP_MULT)
2326 return "madd<u>\t%q0,%1,%2";
2327 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2328 return "madd<u>\t%1,%2";
2330 /* See comment in *macc. */
2331 return "%[macc<u>\t%@,%1,%2%]";
2333 [(set_attr "type" "imadd")
2334 (set_attr "accum_in" "3")
2335 (set_attr "mode" "SI")])
2337 ;; Floating point multiply accumulate instructions.
2339 (define_insn "*madd4<mode>"
2340 [(set (match_operand:ANYF 0 "register_operand" "=f")
2341 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2342 (match_operand:ANYF 2 "register_operand" "f"))
2343 (match_operand:ANYF 3 "register_operand" "f")))]
2344 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2345 "madd.<fmt>\t%0,%3,%1,%2"
2346 [(set_attr "type" "fmadd")
2347 (set_attr "accum_in" "3")
2348 (set_attr "mode" "<UNITMODE>")])
2350 (define_insn "*madd3<mode>"
2351 [(set (match_operand:ANYF 0 "register_operand" "=f")
2352 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2353 (match_operand:ANYF 2 "register_operand" "f"))
2354 (match_operand:ANYF 3 "register_operand" "0")))]
2355 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2356 "madd.<fmt>\t%0,%1,%2"
2357 [(set_attr "type" "fmadd")
2358 (set_attr "accum_in" "3")
2359 (set_attr "mode" "<UNITMODE>")])
2361 (define_insn "*msub4<mode>"
2362 [(set (match_operand:ANYF 0 "register_operand" "=f")
2363 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2364 (match_operand:ANYF 2 "register_operand" "f"))
2365 (match_operand:ANYF 3 "register_operand" "f")))]
2366 "ISA_HAS_FP_MADD4_MSUB4 && TARGET_FUSED_MADD"
2367 "msub.<fmt>\t%0,%3,%1,%2"
2368 [(set_attr "type" "fmadd")
2369 (set_attr "accum_in" "3")
2370 (set_attr "mode" "<UNITMODE>")])
2372 (define_insn "*msub3<mode>"
2373 [(set (match_operand:ANYF 0 "register_operand" "=f")
2374 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2375 (match_operand:ANYF 2 "register_operand" "f"))
2376 (match_operand:ANYF 3 "register_operand" "0")))]
2377 "ISA_HAS_FP_MADD3_MSUB3 && TARGET_FUSED_MADD"
2378 "msub.<fmt>\t%0,%1,%2"
2379 [(set_attr "type" "fmadd")
2380 (set_attr "accum_in" "3")
2381 (set_attr "mode" "<UNITMODE>")])
2383 (define_insn "*nmadd4<mode>"
2384 [(set (match_operand:ANYF 0 "register_operand" "=f")
2385 (neg:ANYF (plus:ANYF
2386 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2387 (match_operand:ANYF 2 "register_operand" "f"))
2388 (match_operand:ANYF 3 "register_operand" "f"))))]
2389 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2390 && TARGET_FUSED_MADD
2391 && HONOR_SIGNED_ZEROS (<MODE>mode)
2392 && !HONOR_NANS (<MODE>mode)"
2393 "nmadd.<fmt>\t%0,%3,%1,%2"
2394 [(set_attr "type" "fmadd")
2395 (set_attr "accum_in" "3")
2396 (set_attr "mode" "<UNITMODE>")])
2398 (define_insn "*nmadd3<mode>"
2399 [(set (match_operand:ANYF 0 "register_operand" "=f")
2400 (neg:ANYF (plus:ANYF
2401 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2402 (match_operand:ANYF 2 "register_operand" "f"))
2403 (match_operand:ANYF 3 "register_operand" "0"))))]
2404 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2405 && TARGET_FUSED_MADD
2406 && HONOR_SIGNED_ZEROS (<MODE>mode)
2407 && !HONOR_NANS (<MODE>mode)"
2408 "nmadd.<fmt>\t%0,%1,%2"
2409 [(set_attr "type" "fmadd")
2410 (set_attr "accum_in" "3")
2411 (set_attr "mode" "<UNITMODE>")])
2413 (define_insn "*nmadd4<mode>_fastmath"
2414 [(set (match_operand:ANYF 0 "register_operand" "=f")
2416 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2417 (match_operand:ANYF 2 "register_operand" "f"))
2418 (match_operand:ANYF 3 "register_operand" "f")))]
2419 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2420 && TARGET_FUSED_MADD
2421 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2422 && !HONOR_NANS (<MODE>mode)"
2423 "nmadd.<fmt>\t%0,%3,%1,%2"
2424 [(set_attr "type" "fmadd")
2425 (set_attr "accum_in" "3")
2426 (set_attr "mode" "<UNITMODE>")])
2428 (define_insn "*nmadd3<mode>_fastmath"
2429 [(set (match_operand:ANYF 0 "register_operand" "=f")
2431 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2432 (match_operand:ANYF 2 "register_operand" "f"))
2433 (match_operand:ANYF 3 "register_operand" "0")))]
2434 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2435 && TARGET_FUSED_MADD
2436 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2437 && !HONOR_NANS (<MODE>mode)"
2438 "nmadd.<fmt>\t%0,%1,%2"
2439 [(set_attr "type" "fmadd")
2440 (set_attr "accum_in" "3")
2441 (set_attr "mode" "<UNITMODE>")])
2443 (define_insn "*nmsub4<mode>"
2444 [(set (match_operand:ANYF 0 "register_operand" "=f")
2445 (neg:ANYF (minus:ANYF
2446 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2447 (match_operand:ANYF 3 "register_operand" "f"))
2448 (match_operand:ANYF 1 "register_operand" "f"))))]
2449 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2450 && TARGET_FUSED_MADD
2451 && HONOR_SIGNED_ZEROS (<MODE>mode)
2452 && !HONOR_NANS (<MODE>mode)"
2453 "nmsub.<fmt>\t%0,%1,%2,%3"
2454 [(set_attr "type" "fmadd")
2455 (set_attr "accum_in" "1")
2456 (set_attr "mode" "<UNITMODE>")])
2458 (define_insn "*nmsub3<mode>"
2459 [(set (match_operand:ANYF 0 "register_operand" "=f")
2460 (neg:ANYF (minus:ANYF
2461 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2462 (match_operand:ANYF 3 "register_operand" "f"))
2463 (match_operand:ANYF 1 "register_operand" "0"))))]
2464 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2465 && TARGET_FUSED_MADD
2466 && HONOR_SIGNED_ZEROS (<MODE>mode)
2467 && !HONOR_NANS (<MODE>mode)"
2468 "nmsub.<fmt>\t%0,%1,%2"
2469 [(set_attr "type" "fmadd")
2470 (set_attr "accum_in" "1")
2471 (set_attr "mode" "<UNITMODE>")])
2473 (define_insn "*nmsub4<mode>_fastmath"
2474 [(set (match_operand:ANYF 0 "register_operand" "=f")
2476 (match_operand:ANYF 1 "register_operand" "f")
2477 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2478 (match_operand:ANYF 3 "register_operand" "f"))))]
2479 "ISA_HAS_NMADD4_NMSUB4 (<MODE>mode)
2480 && TARGET_FUSED_MADD
2481 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2482 && !HONOR_NANS (<MODE>mode)"
2483 "nmsub.<fmt>\t%0,%1,%2,%3"
2484 [(set_attr "type" "fmadd")
2485 (set_attr "accum_in" "1")
2486 (set_attr "mode" "<UNITMODE>")])
2488 (define_insn "*nmsub3<mode>_fastmath"
2489 [(set (match_operand:ANYF 0 "register_operand" "=f")
2491 (match_operand:ANYF 1 "register_operand" "f")
2492 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2493 (match_operand:ANYF 3 "register_operand" "0"))))]
2494 "ISA_HAS_NMADD3_NMSUB3 (<MODE>mode)
2495 && TARGET_FUSED_MADD
2496 && !HONOR_SIGNED_ZEROS (<MODE>mode)
2497 && !HONOR_NANS (<MODE>mode)"
2498 "nmsub.<fmt>\t%0,%1,%2"
2499 [(set_attr "type" "fmadd")
2500 (set_attr "accum_in" "1")
2501 (set_attr "mode" "<UNITMODE>")])
2504 ;; ....................
2506 ;; DIVISION and REMAINDER
2508 ;; ....................
2511 (define_expand "div<mode>3"
2512 [(set (match_operand:ANYF 0 "register_operand")
2513 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2514 (match_operand:ANYF 2 "register_operand")))]
2515 "<divide_condition>"
2517 if (const_1_operand (operands[1], <MODE>mode))
2518 if (!(<recip_condition> && flag_unsafe_math_optimizations))
2519 operands[1] = force_reg (<MODE>mode, operands[1]);
2522 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2524 ;; If an mfc1 or dmfc1 happens to access the floating point register
2525 ;; file at the same time a long latency operation (div, sqrt, recip,
2526 ;; sqrt) iterates an intermediate result back through the floating
2527 ;; point register file bypass, then instead returning the correct
2528 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2529 ;; result of the long latency operation.
2531 ;; The workaround is to insert an unconditional 'mov' from/to the
2532 ;; long latency op destination register.
2534 (define_insn "*div<mode>3"
2535 [(set (match_operand:ANYF 0 "register_operand" "=f")
2536 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2537 (match_operand:ANYF 2 "register_operand" "f")))]
2538 "<divide_condition>"
2541 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2543 return "div.<fmt>\t%0,%1,%2";
2545 [(set_attr "type" "fdiv")
2546 (set_attr "mode" "<UNITMODE>")
2547 (set (attr "length")
2548 (if_then_else (match_test "TARGET_FIX_SB1")
2552 (define_insn "*recip<mode>3"
2553 [(set (match_operand:ANYF 0 "register_operand" "=f")
2554 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2555 (match_operand:ANYF 2 "register_operand" "f")))]
2556 "<recip_condition> && flag_unsafe_math_optimizations"
2559 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2561 return "recip.<fmt>\t%0,%2";
2563 [(set_attr "type" "frdiv")
2564 (set_attr "mode" "<UNITMODE>")
2565 (set (attr "length")
2566 (if_then_else (match_test "TARGET_FIX_SB1")
2570 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2571 ;; with negative operands. We use special libgcc functions instead.
2572 (define_expand "divmod<mode>4"
2573 [(set (match_operand:GPR 0 "register_operand")
2574 (div:GPR (match_operand:GPR 1 "register_operand")
2575 (match_operand:GPR 2 "register_operand")))
2576 (set (match_operand:GPR 3 "register_operand")
2577 (mod:GPR (match_dup 1)
2579 "!TARGET_FIX_VR4120"
2583 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1],
2585 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2588 emit_insn (gen_divmod<mode>4_internal (operands[0], operands[1],
2589 operands[2], operands[3]));
2593 (define_insn_and_split "divmod<mode>4_internal"
2594 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2595 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2596 (match_operand:GPR 2 "register_operand" "d")))
2597 (set (match_operand:GPR 3 "register_operand" "=d")
2598 (mod:GPR (match_dup 1)
2600 "!TARGET_FIX_VR4120 && !TARGET_MIPS16"
2602 "&& reload_completed"
2605 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2608 [(set_attr "type" "idiv")
2609 (set_attr "mode" "<MODE>")
2610 (set_attr "length" "8")])
2612 (define_expand "udivmod<mode>4"
2613 [(set (match_operand:GPR 0 "register_operand")
2614 (udiv:GPR (match_operand:GPR 1 "register_operand")
2615 (match_operand:GPR 2 "register_operand")))
2616 (set (match_operand:GPR 3 "register_operand")
2617 (umod:GPR (match_dup 1)
2623 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1],
2625 emit_move_insn (operands[0], gen_rtx_REG (<MODE>mode, LO_REGNUM));
2628 emit_insn (gen_udivmod<mode>4_internal (operands[0], operands[1],
2629 operands[2], operands[3]));
2633 (define_insn_and_split "udivmod<mode>4_internal"
2634 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
2635 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2636 (match_operand:GPR 2 "register_operand" "d")))
2637 (set (match_operand:GPR 3 "register_operand" "=d")
2638 (umod:GPR (match_dup 1)
2645 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2648 [(set_attr "type" "idiv")
2649 (set_attr "mode" "<MODE>")
2650 (set_attr "length" "8")])
2652 (define_expand "<u>divmod<mode>4_split"
2653 [(set (match_operand:GPR 0 "register_operand")
2654 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2655 (match_operand:GPR 2 "register_operand")))]
2662 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2663 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2665 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2669 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2670 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2672 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2677 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2678 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2680 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
2681 (match_operand:GPR 2 "register_operand" "d"))]
2684 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
2685 [(set_attr "type" "idiv")
2686 (set_attr "mode" "<GPR:MODE>")])
2689 ;; ....................
2693 ;; ....................
2695 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
2696 ;; "*div[sd]f3" comment for details).
2698 (define_insn "sqrt<mode>2"
2699 [(set (match_operand:ANYF 0 "register_operand" "=f")
2700 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2704 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
2706 return "sqrt.<fmt>\t%0,%1";
2708 [(set_attr "type" "fsqrt")
2709 (set_attr "mode" "<UNITMODE>")
2710 (set (attr "length")
2711 (if_then_else (match_test "TARGET_FIX_SB1")
2715 (define_insn "*rsqrt<mode>a"
2716 [(set (match_operand:ANYF 0 "register_operand" "=f")
2717 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2718 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
2719 "<recip_condition> && flag_unsafe_math_optimizations"
2722 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2724 return "rsqrt.<fmt>\t%0,%2";
2726 [(set_attr "type" "frsqrt")
2727 (set_attr "mode" "<UNITMODE>")
2728 (set (attr "length")
2729 (if_then_else (match_test "TARGET_FIX_SB1")
2733 (define_insn "*rsqrt<mode>b"
2734 [(set (match_operand:ANYF 0 "register_operand" "=f")
2735 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2736 (match_operand:ANYF 2 "register_operand" "f"))))]
2737 "<recip_condition> && flag_unsafe_math_optimizations"
2740 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2742 return "rsqrt.<fmt>\t%0,%2";
2744 [(set_attr "type" "frsqrt")
2745 (set_attr "mode" "<UNITMODE>")
2746 (set (attr "length")
2747 (if_then_else (match_test "TARGET_FIX_SB1")
2752 ;; ....................
2756 ;; ....................
2758 ;; Do not use the integer abs macro instruction, since that signals an
2759 ;; exception on -2147483648 (sigh).
2761 ;; abs.fmt is an arithmetic instruction and treats all NaN inputs as
2762 ;; invalid; it does not clear their sign bits. We therefore can't use
2763 ;; abs.fmt if the signs of NaNs matter.
2765 (define_insn "abs<mode>2"
2766 [(set (match_operand:ANYF 0 "register_operand" "=f")
2767 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2768 "!HONOR_NANS (<MODE>mode)"
2770 [(set_attr "type" "fabs")
2771 (set_attr "mode" "<UNITMODE>")])
2774 ;; ...................
2776 ;; Count leading zeroes.
2778 ;; ...................
2781 (define_insn "clz<mode>2"
2782 [(set (match_operand:GPR 0 "register_operand" "=d")
2783 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
2786 [(set_attr "type" "clz")
2787 (set_attr "mode" "<MODE>")])
2790 ;; ...................
2792 ;; Count number of set bits.
2794 ;; ...................
2797 (define_insn "popcount<mode>2"
2798 [(set (match_operand:GPR 0 "register_operand" "=d")
2799 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
2802 [(set_attr "type" "pop")
2803 (set_attr "mode" "<MODE>")])
2805 ;; The POP instruction is special as it does not take into account the upper
2806 ;; 32bits and is documented that way.
2807 (define_insn "*popcountdi2_trunc"
2808 [(set (match_operand:SI 0 "register_operand" "=d")
2809 (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
2810 "ISA_HAS_POP && TARGET_64BIT"
2812 [(set_attr "type" "pop")
2813 (set_attr "mode" "SI")])
2816 ;; ....................
2818 ;; NEGATION and ONE'S COMPLEMENT
2820 ;; ....................
2822 (define_insn "negsi2"
2823 [(set (match_operand:SI 0 "register_operand" "=d")
2824 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
2828 return "neg\t%0,%1";
2830 return "subu\t%0,%.,%1";
2832 [(set_attr "alu_type" "sub")
2833 (set_attr "mode" "SI")])
2835 (define_insn "negdi2"
2836 [(set (match_operand:DI 0 "register_operand" "=d")
2837 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
2838 "TARGET_64BIT && !TARGET_MIPS16"
2840 [(set_attr "alu_type" "sub")
2841 (set_attr "mode" "DI")])
2843 ;; neg.fmt is an arithmetic instruction and treats all NaN inputs as
2844 ;; invalid; it does not flip their sign bit. We therefore can't use
2845 ;; neg.fmt if the signs of NaNs matter.
2847 (define_insn "neg<mode>2"
2848 [(set (match_operand:ANYF 0 "register_operand" "=f")
2849 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
2850 "!HONOR_NANS (<MODE>mode)"
2852 [(set_attr "type" "fneg")
2853 (set_attr "mode" "<UNITMODE>")])
2855 (define_insn "one_cmpl<mode>2"
2856 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
2857 (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
2861 return "not\t%0,%1";
2863 return "nor\t%0,%.,%1";
2865 [(set_attr "alu_type" "not")
2866 (set_attr "compression" "micromips,*")
2867 (set_attr "mode" "<MODE>")])
2870 ;; ....................
2874 ;; ....................
2877 ;; Many of these instructions use trivial define_expands, because we
2878 ;; want to use a different set of constraints when TARGET_MIPS16.
2880 (define_expand "and<mode>3"
2881 [(set (match_operand:GPR 0 "register_operand")
2882 (and:GPR (match_operand:GPR 1 "register_operand")
2883 (match_operand:GPR 2 "and_reg_operand")))])
2885 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
2886 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
2887 ;; Note that this variant does not trigger for SI mode because we require
2888 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
2889 ;; sign-extended SImode value.
2891 ;; These are possible combinations for operand 1 and 2. The table
2892 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
2893 ;; 16=MIPS16, x=match, S=split):
2895 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
2901 ;; 0xffff_ffff x S x S x
2906 (define_insn "*and<mode>3"
2907 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
2908 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
2909 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
2910 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2914 switch (which_alternative)
2917 operands[1] = gen_lowpart (QImode, operands[1]);
2918 return "lbu\t%0,%1";
2920 operands[1] = gen_lowpart (HImode, operands[1]);
2921 return "lhu\t%0,%1";
2923 operands[1] = gen_lowpart (SImode, operands[1]);
2924 return "lwu\t%0,%1";
2927 return "andi\t%0,%1,%x2";
2929 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
2930 operands[2] = GEN_INT (len);
2931 return "<d>ext\t%0,%1,0,%2";
2936 return "and\t%0,%1,%2";
2941 [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
2942 (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
2943 (set_attr "mode" "<MODE>")])
2945 (define_insn "*and<mode>3_mips16"
2946 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
2947 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
2948 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
2949 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
2951 switch (which_alternative)
2954 operands[1] = gen_lowpart (QImode, operands[1]);
2955 return "lbu\t%0,%1";
2957 operands[1] = gen_lowpart (HImode, operands[1]);
2958 return "lhu\t%0,%1";
2960 operands[1] = gen_lowpart (SImode, operands[1]);
2961 return "lwu\t%0,%1";
2965 return "and\t%0,%2";
2970 [(set_attr "move_type" "load,load,load,shift_shift,logical")
2971 (set_attr "mode" "<MODE>")])
2973 (define_expand "ior<mode>3"
2974 [(set (match_operand:GPR 0 "register_operand")
2975 (ior:GPR (match_operand:GPR 1 "register_operand")
2976 (match_operand:GPR 2 "uns_arith_operand")))]
2980 operands[2] = force_reg (<MODE>mode, operands[2]);
2983 (define_insn "*ior<mode>3"
2984 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
2985 (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2986 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
2992 [(set_attr "alu_type" "or")
2993 (set_attr "compression" "micromips,*,*")
2994 (set_attr "mode" "<MODE>")])
2996 (define_insn "*ior<mode>3_mips16"
2997 [(set (match_operand:GPR 0 "register_operand" "=d")
2998 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2999 (match_operand:GPR 2 "register_operand" "d")))]
3002 [(set_attr "alu_type" "or")
3003 (set_attr "mode" "<MODE>")])
3005 (define_expand "xor<mode>3"
3006 [(set (match_operand:GPR 0 "register_operand")
3007 (xor:GPR (match_operand:GPR 1 "register_operand")
3008 (match_operand:GPR 2 "uns_arith_operand")))]
3013 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3014 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3015 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3021 [(set_attr "alu_type" "xor")
3022 (set_attr "compression" "micromips,*,*")
3023 (set_attr "mode" "<MODE>")])
3026 [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
3027 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3028 (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
3034 [(set_attr "alu_type" "xor")
3035 (set_attr "mode" "<MODE>")
3036 (set_attr_alternative "length"
3038 (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
3043 (define_insn "*nor<mode>3"
3044 [(set (match_operand:GPR 0 "register_operand" "=d")
3045 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3046 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3049 [(set_attr "alu_type" "nor")
3050 (set_attr "mode" "<MODE>")])
3053 ;; ....................
3057 ;; ....................
3061 (define_insn "truncdfsf2"
3062 [(set (match_operand:SF 0 "register_operand" "=f")
3063 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3064 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3066 [(set_attr "type" "fcvt")
3067 (set_attr "cnv_mode" "D2S")
3068 (set_attr "mode" "SF")])
3070 ;; Integer truncation patterns. Truncating SImode values to smaller
3071 ;; modes is a no-op, as it is for most other GCC ports. Truncating
3072 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3073 ;; need to make sure that the lower 32 bits are properly sign-extended
3074 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
3075 ;; smaller than SImode is equivalent to two separate truncations:
3078 ;; DI ---> HI == DI ---> SI ---> HI
3079 ;; DI ---> QI == DI ---> SI ---> QI
3081 ;; Step A needs a real instruction but step B does not.
3083 (define_insn "truncdi<mode>2"
3084 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3085 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3090 [(set_attr "move_type" "sll0,store")
3091 (set_attr "mode" "SI")])
3093 ;; Combiner patterns to optimize shift/truncate combinations.
3095 (define_insn "*ashr_trunc<mode>"
3096 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3098 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3099 (match_operand:DI 2 "const_arith_operand" ""))))]
3100 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3102 [(set_attr "type" "shift")
3103 (set_attr "mode" "<MODE>")])
3105 (define_insn "*lshr32_trunc<mode>"
3106 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3108 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3110 "TARGET_64BIT && !TARGET_MIPS16"
3112 [(set_attr "type" "shift")
3113 (set_attr "mode" "<MODE>")])
3115 ;; Logical shift by more than 32 results in proper SI values so truncation is
3116 ;; removed by the middle end. Note that a logical shift by 32 is handled by
3117 ;; the previous pattern.
3118 (define_insn "*<optab>_trunc<mode>_exts"
3119 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3121 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3122 (match_operand:DI 2 "const_arith_operand" ""))))]
3123 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3125 [(set_attr "type" "arith")
3126 (set_attr "mode" "<MODE>")])
3129 ;; ....................
3133 ;; ....................
3137 (define_expand "zero_extendsidi2"
3138 [(set (match_operand:DI 0 "register_operand")
3139 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3142 (define_insn_and_split "*zero_extendsidi2"
3143 [(set (match_operand:DI 0 "register_operand" "=d,d")
3144 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3145 "TARGET_64BIT && !ISA_HAS_EXT_INS"
3149 "&& reload_completed && REG_P (operands[1])"
3151 (ashift:DI (match_dup 1) (const_int 32)))
3153 (lshiftrt:DI (match_dup 0) (const_int 32)))]
3154 { operands[1] = gen_lowpart (DImode, operands[1]); }
3155 [(set_attr "move_type" "shift_shift,load")
3156 (set_attr "mode" "DI")])
3158 (define_insn "*zero_extendsidi2_dext"
3159 [(set (match_operand:DI 0 "register_operand" "=d,d")
3160 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3161 "TARGET_64BIT && ISA_HAS_EXT_INS"
3165 [(set_attr "move_type" "arith,load")
3166 (set_attr "mode" "DI")])
3168 ;; See the comment before the *and<mode>3 pattern why this is generated by
3172 [(set (match_operand:DI 0 "register_operand")
3173 (and:DI (match_operand:DI 1 "register_operand")
3174 (const_int 4294967295)))]
3175 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3177 (ashift:DI (match_dup 1) (const_int 32)))
3179 (lshiftrt:DI (match_dup 0) (const_int 32)))])
3181 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3182 [(set (match_operand:GPR 0 "register_operand")
3183 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3186 if (TARGET_MIPS16 && !GENERATE_MIPS16E
3187 && !memory_operand (operands[1], <SHORT:MODE>mode))
3189 emit_insn (gen_and<GPR:mode>3 (operands[0],
3190 gen_lowpart (<GPR:MODE>mode, operands[1]),
3191 force_reg (<GPR:MODE>mode,
3192 GEN_INT (<SHORT:mask>))));
3197 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3198 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3200 (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3203 andi\t%0,%1,<SHORT:mask>
3204 andi\t%0,%1,<SHORT:mask>
3205 l<SHORT:size>u\t%0,%1"
3206 [(set_attr "move_type" "andi,andi,load")
3207 (set_attr "compression" "micromips,*,*")
3208 (set_attr "mode" "<GPR:MODE>")])
3210 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3211 [(set (match_operand:GPR 0 "register_operand" "=d")
3212 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3214 "ze<SHORT:size>\t%0"
3215 ;; This instruction is effectively a special encoding of ANDI.
3216 [(set_attr "move_type" "andi")
3217 (set_attr "mode" "<GPR:MODE>")])
3219 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3220 [(set (match_operand:GPR 0 "register_operand" "=d")
3221 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3223 "l<SHORT:size>u\t%0,%1"
3224 [(set_attr "move_type" "load")
3225 (set_attr "mode" "<GPR:MODE>")])
3227 (define_expand "zero_extendqihi2"
3228 [(set (match_operand:HI 0 "register_operand")
3229 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3232 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3234 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3240 (define_insn "*zero_extendqihi2"
3241 [(set (match_operand:HI 0 "register_operand" "=d,d")
3242 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3247 [(set_attr "move_type" "andi,load")
3248 (set_attr "mode" "HI")])
3250 (define_insn "*zero_extendqihi2_mips16"
3251 [(set (match_operand:HI 0 "register_operand" "=d")
3252 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3255 [(set_attr "move_type" "load")
3256 (set_attr "mode" "HI")])
3258 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3260 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3261 [(set (match_operand:GPR 0 "register_operand" "=d")
3263 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3264 "TARGET_64BIT && !TARGET_MIPS16"
3266 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3267 return "andi\t%0,%1,%x2";
3269 [(set_attr "alu_type" "and")
3270 (set_attr "mode" "<GPR:MODE>")])
3272 (define_insn "*zero_extendhi_truncqi"
3273 [(set (match_operand:HI 0 "register_operand" "=d")
3275 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3276 "TARGET_64BIT && !TARGET_MIPS16"
3278 [(set_attr "alu_type" "and")
3279 (set_attr "mode" "HI")])
3282 ;; ....................
3286 ;; ....................
3289 ;; Those for integer source operand are ordered widest source type first.
3291 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3292 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3293 ;; and truncdisi2). We can therefore get rid of register->register
3294 ;; instructions if we constrain the source to be in the same register as
3297 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3298 ;; we split them into nothing before the post-reload scheduler runs.
3299 ;; These alternatives therefore have type "move" in order to reflect
3300 ;; what happens if the two pre-reload operands cannot be tied, and are
3301 ;; instead allocated two separate GPRs. We don't distinguish between
3302 ;; the GPR and LO cases because we don't usually know during pre-reload
3303 ;; scheduling whether an operand will be LO or not.
3304 (define_insn_and_split "extendsidi2"
3305 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3306 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3312 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3315 emit_note (NOTE_INSN_DELETED);
3318 [(set_attr "move_type" "move,move,load")
3319 (set_attr "mode" "DI")])
3321 (define_expand "extend<SHORT:mode><GPR:mode>2"
3322 [(set (match_operand:GPR 0 "register_operand")
3323 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3326 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3327 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3328 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3332 l<SHORT:size>\t%0,%1"
3333 [(set_attr "move_type" "signext,load")
3334 (set_attr "mode" "<GPR:MODE>")])
3336 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3337 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3339 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3340 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3343 l<SHORT:size>\t%0,%1"
3344 "&& reload_completed && REG_P (operands[1])"
3345 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3346 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3348 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3349 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3350 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3352 [(set_attr "move_type" "shift_shift,load")
3353 (set_attr "mode" "<GPR:MODE>")])
3355 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3356 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3358 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3361 se<SHORT:size>\t%0,%1
3362 l<SHORT:size>\t%0,%1"
3363 [(set_attr "move_type" "signext,load")
3364 (set_attr "mode" "<GPR:MODE>")])
3366 (define_expand "extendqihi2"
3367 [(set (match_operand:HI 0 "register_operand")
3368 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3371 (define_insn "*extendqihi2_mips16e"
3372 [(set (match_operand:HI 0 "register_operand" "=d,d")
3373 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3378 [(set_attr "move_type" "signext,load")
3379 (set_attr "mode" "SI")])
3381 (define_insn_and_split "*extendqihi2"
3382 [(set (match_operand:HI 0 "register_operand" "=d,d")
3384 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3385 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3389 "&& reload_completed && REG_P (operands[1])"
3390 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3391 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3393 operands[0] = gen_lowpart (SImode, operands[0]);
3394 operands[1] = gen_lowpart (SImode, operands[1]);
3395 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3396 - GET_MODE_BITSIZE (QImode));
3398 [(set_attr "move_type" "shift_shift,load")
3399 (set_attr "mode" "SI")])
3401 (define_insn "*extendqihi2_seb"
3402 [(set (match_operand:HI 0 "register_operand" "=d,d")
3404 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3409 [(set_attr "move_type" "signext,load")
3410 (set_attr "mode" "SI")])
3412 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3413 ;; use the shift/truncate patterns.
3415 (define_insn_and_split "*extenddi_truncate<mode>"
3416 [(set (match_operand:DI 0 "register_operand" "=d")
3418 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3419 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3421 "&& reload_completed"
3423 (ashift:DI (match_dup 1)
3426 (ashiftrt:DI (match_dup 2)
3429 operands[2] = gen_lowpart (DImode, operands[0]);
3430 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3432 [(set_attr "move_type" "shift_shift")
3433 (set_attr "mode" "DI")])
3435 (define_insn_and_split "*extendsi_truncate<mode>"
3436 [(set (match_operand:SI 0 "register_operand" "=d")
3438 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3439 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3441 "&& reload_completed"
3443 (ashift:DI (match_dup 1)
3446 (truncate:SI (ashiftrt:DI (match_dup 2)
3449 operands[2] = gen_lowpart (DImode, operands[0]);
3450 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3452 [(set_attr "move_type" "shift_shift")
3453 (set_attr "mode" "SI")])
3455 (define_insn_and_split "*extendhi_truncateqi"
3456 [(set (match_operand:HI 0 "register_operand" "=d")
3458 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3459 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3461 "&& reload_completed"
3463 (ashift:DI (match_dup 1)
3466 (truncate:HI (ashiftrt:DI (match_dup 2)
3469 operands[2] = gen_lowpart (DImode, operands[0]);
3471 [(set_attr "move_type" "shift_shift")
3472 (set_attr "mode" "SI")])
3474 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3475 [(set (match_operand:GPR 0 "register_operand" "=d")
3477 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3478 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3480 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3481 return "exts\t%0,%1,0,%m2";
3483 [(set_attr "type" "arith")
3484 (set_attr "mode" "<GPR:MODE>")])
3486 (define_insn "*extendhi_truncateqi_exts"
3487 [(set (match_operand:HI 0 "register_operand" "=d")
3489 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3490 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3492 [(set_attr "type" "arith")
3493 (set_attr "mode" "SI")])
3495 (define_insn "extendsfdf2"
3496 [(set (match_operand:DF 0 "register_operand" "=f")
3497 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3498 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3500 [(set_attr "type" "fcvt")
3501 (set_attr "cnv_mode" "S2D")
3502 (set_attr "mode" "DF")])
3505 ;; ....................
3509 ;; ....................
3511 (define_expand "fix_truncdfsi2"
3512 [(set (match_operand:SI 0 "register_operand")
3513 (fix:SI (match_operand:DF 1 "register_operand")))]
3514 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3516 if (!ISA_HAS_TRUNC_W)
3518 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3523 (define_insn "fix_truncdfsi2_insn"
3524 [(set (match_operand:SI 0 "register_operand" "=f")
3525 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3526 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3528 [(set_attr "type" "fcvt")
3529 (set_attr "mode" "DF")
3530 (set_attr "cnv_mode" "D2I")])
3532 (define_insn "fix_truncdfsi2_macro"
3533 [(set (match_operand:SI 0 "register_operand" "=f")
3534 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3535 (clobber (match_scratch:DF 2 "=d"))]
3536 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3538 if (mips_nomacro.nesting_level > 0)
3539 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3541 return "trunc.w.d %0,%1,%2";
3543 [(set_attr "type" "fcvt")
3544 (set_attr "mode" "DF")
3545 (set_attr "cnv_mode" "D2I")
3546 (set_attr "length" "36")])
3548 (define_expand "fix_truncsfsi2"
3549 [(set (match_operand:SI 0 "register_operand")
3550 (fix:SI (match_operand:SF 1 "register_operand")))]
3553 if (!ISA_HAS_TRUNC_W)
3555 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3560 (define_insn "fix_truncsfsi2_insn"
3561 [(set (match_operand:SI 0 "register_operand" "=f")
3562 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3563 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3565 [(set_attr "type" "fcvt")
3566 (set_attr "mode" "SF")
3567 (set_attr "cnv_mode" "S2I")])
3569 (define_insn "fix_truncsfsi2_macro"
3570 [(set (match_operand:SI 0 "register_operand" "=f")
3571 (fix:SI (match_operand:SF 1 "register_operand" "f")))
3572 (clobber (match_scratch:SF 2 "=d"))]
3573 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3575 if (mips_nomacro.nesting_level > 0)
3576 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3578 return "trunc.w.s %0,%1,%2";
3580 [(set_attr "type" "fcvt")
3581 (set_attr "mode" "SF")
3582 (set_attr "cnv_mode" "S2I")
3583 (set_attr "length" "36")])
3586 (define_insn "fix_truncdfdi2"
3587 [(set (match_operand:DI 0 "register_operand" "=f")
3588 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3589 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3591 [(set_attr "type" "fcvt")
3592 (set_attr "mode" "DF")
3593 (set_attr "cnv_mode" "D2I")])
3596 (define_insn "fix_truncsfdi2"
3597 [(set (match_operand:DI 0 "register_operand" "=f")
3598 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3599 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3601 [(set_attr "type" "fcvt")
3602 (set_attr "mode" "SF")
3603 (set_attr "cnv_mode" "S2I")])
3606 (define_insn "floatsidf2"
3607 [(set (match_operand:DF 0 "register_operand" "=f")
3608 (float:DF (match_operand:SI 1 "register_operand" "f")))]
3609 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3611 [(set_attr "type" "fcvt")
3612 (set_attr "mode" "DF")
3613 (set_attr "cnv_mode" "I2D")])
3616 (define_insn "floatdidf2"
3617 [(set (match_operand:DF 0 "register_operand" "=f")
3618 (float:DF (match_operand:DI 1 "register_operand" "f")))]
3619 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3621 [(set_attr "type" "fcvt")
3622 (set_attr "mode" "DF")
3623 (set_attr "cnv_mode" "I2D")])
3626 (define_insn "floatsisf2"
3627 [(set (match_operand:SF 0 "register_operand" "=f")
3628 (float:SF (match_operand:SI 1 "register_operand" "f")))]
3631 [(set_attr "type" "fcvt")
3632 (set_attr "mode" "SF")
3633 (set_attr "cnv_mode" "I2S")])
3636 (define_insn "floatdisf2"
3637 [(set (match_operand:SF 0 "register_operand" "=f")
3638 (float:SF (match_operand:DI 1 "register_operand" "f")))]
3639 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3641 [(set_attr "type" "fcvt")
3642 (set_attr "mode" "SF")
3643 (set_attr "cnv_mode" "I2S")])
3646 (define_expand "fixuns_truncdfsi2"
3647 [(set (match_operand:SI 0 "register_operand")
3648 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
3649 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3651 rtx reg1 = gen_reg_rtx (DFmode);
3652 rtx reg2 = gen_reg_rtx (DFmode);
3653 rtx reg3 = gen_reg_rtx (SImode);
3654 rtx label1 = gen_label_rtx ();
3655 rtx label2 = gen_label_rtx ();
3657 REAL_VALUE_TYPE offset;
3659 real_2expN (&offset, 31, DFmode);
3661 if (reg1) /* Turn off complaints about unreached code. */
3663 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3664 do_pending_stack_adjust ();
3666 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3667 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3669 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
3670 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3671 gen_rtx_LABEL_REF (VOIDmode, label2)));
3674 emit_label (label1);
3675 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3676 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3677 (BITMASK_HIGH, SImode)));
3679 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
3680 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3682 emit_label (label2);
3684 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3685 fields, and can't be used for REG_NOTES anyway). */
3686 emit_use (stack_pointer_rtx);
3692 (define_expand "fixuns_truncdfdi2"
3693 [(set (match_operand:DI 0 "register_operand")
3694 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
3695 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3697 rtx reg1 = gen_reg_rtx (DFmode);
3698 rtx reg2 = gen_reg_rtx (DFmode);
3699 rtx reg3 = gen_reg_rtx (DImode);
3700 rtx label1 = gen_label_rtx ();
3701 rtx label2 = gen_label_rtx ();
3703 REAL_VALUE_TYPE offset;
3705 real_2expN (&offset, 63, DFmode);
3707 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
3708 do_pending_stack_adjust ();
3710 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3711 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
3713 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
3714 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3715 gen_rtx_LABEL_REF (VOIDmode, label2)));
3718 emit_label (label1);
3719 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
3720 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3721 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3723 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
3724 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3726 emit_label (label2);
3728 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3729 fields, and can't be used for REG_NOTES anyway). */
3730 emit_use (stack_pointer_rtx);
3735 (define_expand "fixuns_truncsfsi2"
3736 [(set (match_operand:SI 0 "register_operand")
3737 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
3740 rtx reg1 = gen_reg_rtx (SFmode);
3741 rtx reg2 = gen_reg_rtx (SFmode);
3742 rtx reg3 = gen_reg_rtx (SImode);
3743 rtx label1 = gen_label_rtx ();
3744 rtx label2 = gen_label_rtx ();
3746 REAL_VALUE_TYPE offset;
3748 real_2expN (&offset, 31, SFmode);
3750 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3751 do_pending_stack_adjust ();
3753 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3754 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3756 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
3757 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3758 gen_rtx_LABEL_REF (VOIDmode, label2)));
3761 emit_label (label1);
3762 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3763 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
3764 (BITMASK_HIGH, SImode)));
3766 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
3767 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
3769 emit_label (label2);
3771 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3772 fields, and can't be used for REG_NOTES anyway). */
3773 emit_use (stack_pointer_rtx);
3778 (define_expand "fixuns_truncsfdi2"
3779 [(set (match_operand:DI 0 "register_operand")
3780 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
3781 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
3783 rtx reg1 = gen_reg_rtx (SFmode);
3784 rtx reg2 = gen_reg_rtx (SFmode);
3785 rtx reg3 = gen_reg_rtx (DImode);
3786 rtx label1 = gen_label_rtx ();
3787 rtx label2 = gen_label_rtx ();
3789 REAL_VALUE_TYPE offset;
3791 real_2expN (&offset, 63, SFmode);
3793 mips_emit_move (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
3794 do_pending_stack_adjust ();
3796 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
3797 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
3799 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
3800 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
3801 gen_rtx_LABEL_REF (VOIDmode, label2)));
3804 emit_label (label1);
3805 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
3806 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
3807 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
3809 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
3810 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
3812 emit_label (label2);
3814 /* Allow REG_NOTES to be set on last insn (labels don't have enough
3815 fields, and can't be used for REG_NOTES anyway). */
3816 emit_use (stack_pointer_rtx);
3821 ;; ....................
3825 ;; ....................
3827 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
3829 (define_expand "extvmisalign<mode>"
3830 [(set (match_operand:GPR 0 "register_operand")
3831 (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
3832 (match_operand 2 "const_int_operand")
3833 (match_operand 3 "const_int_operand")))]
3836 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3837 INTVAL (operands[2]),
3838 INTVAL (operands[3]),
3839 /*unsigned=*/ false))
3845 (define_expand "extv<mode>"
3846 [(set (match_operand:GPR 0 "register_operand")
3847 (sign_extract:GPR (match_operand:GPR 1 "register_operand")
3848 (match_operand 2 "const_int_operand")
3849 (match_operand 3 "const_int_operand")))]
3852 if (UINTVAL (operands[2]) > 32)
3856 (define_insn "*extv<mode>"
3857 [(set (match_operand:GPR 0 "register_operand" "=d")
3858 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3859 (match_operand 2 "const_int_operand" "")
3860 (match_operand 3 "const_int_operand" "")))]
3861 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
3862 "exts\t%0,%1,%3,%m2"
3863 [(set_attr "type" "arith")
3864 (set_attr "mode" "<MODE>")])
3866 (define_expand "extzvmisalign<mode>"
3867 [(set (match_operand:GPR 0 "register_operand")
3868 (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
3869 (match_operand 2 "const_int_operand")
3870 (match_operand 3 "const_int_operand")))]
3873 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
3874 INTVAL (operands[2]),
3875 INTVAL (operands[3]),
3876 /*unsigned=*/ true))
3882 (define_expand "extzv<mode>"
3883 [(set (match_operand:GPR 0 "register_operand")
3884 (zero_extract:GPR (match_operand:GPR 1 "register_operand")
3885 (match_operand 2 "const_int_operand")
3886 (match_operand 3 "const_int_operand")))]
3889 if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3890 INTVAL (operands[3])))
3894 (define_insn "*extzv<mode>"
3895 [(set (match_operand:GPR 0 "register_operand" "=d")
3896 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
3897 (match_operand 2 "const_int_operand" "")
3898 (match_operand 3 "const_int_operand" "")))]
3899 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
3900 INTVAL (operands[3]))"
3901 "<d>ext\t%0,%1,%3,%2"
3902 [(set_attr "type" "arith")
3903 (set_attr "mode" "<MODE>")])
3905 (define_insn "*extzv_truncsi_exts"
3906 [(set (match_operand:SI 0 "register_operand" "=d")
3908 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
3909 (match_operand 2 "const_int_operand" "")
3910 (match_operand 3 "const_int_operand" ""))))]
3911 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3913 [(set_attr "type" "arith")
3914 (set_attr "mode" "SI")])
3917 (define_expand "insvmisalign<mode>"
3918 [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
3919 (match_operand 1 "const_int_operand")
3920 (match_operand 2 "const_int_operand"))
3921 (match_operand:GPR 3 "reg_or_0_operand"))]
3924 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
3925 INTVAL (operands[1]),
3926 INTVAL (operands[2])))
3932 (define_expand "insv<mode>"
3933 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
3934 (match_operand 1 "const_int_operand")
3935 (match_operand 2 "const_int_operand"))
3936 (match_operand:GPR 3 "reg_or_0_operand"))]
3939 if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3940 INTVAL (operands[2])))
3944 (define_insn "*insv<mode>"
3945 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
3946 (match_operand:SI 1 "const_int_operand" "")
3947 (match_operand:SI 2 "const_int_operand" ""))
3948 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
3949 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
3950 INTVAL (operands[2]))"
3951 "<d>ins\t%0,%z3,%2,%1"
3952 [(set_attr "type" "arith")
3953 (set_attr "mode" "<MODE>")])
3955 ;; Combiner pattern for cins (clear and insert bit field). We can
3956 ;; implement mask-and-shift-left operation with this. Note that if
3957 ;; the upper bit of the mask is set in an SImode operation, the mask
3958 ;; itself will be sign-extended. mask_low_and_shift_len will
3959 ;; therefore be greater than our threshold of 32.
3961 (define_insn "*cins<mode>"
3962 [(set (match_operand:GPR 0 "register_operand" "=d")
3964 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
3965 (match_operand:GPR 2 "const_int_operand" ""))
3966 (match_operand:GPR 3 "const_int_operand" "")))]
3968 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
3971 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
3972 return "cins\t%0,%1,%2,%m3";
3974 [(set_attr "type" "shift")
3975 (set_attr "mode" "<MODE>")])
3977 ;; Unaligned word moves generated by the bit field patterns.
3979 ;; As far as the rtl is concerned, both the left-part and right-part
3980 ;; instructions can access the whole field. However, the real operand
3981 ;; refers to just the first or the last byte (depending on endianness).
3982 ;; We therefore use two memory operands to each instruction, one to
3983 ;; describe the rtl effect and one to use in the assembly output.
3985 ;; Operands 0 and 1 are the rtl-level target and source respectively.
3986 ;; This allows us to use the standard length calculations for the "load"
3987 ;; and "store" type attributes.
3989 (define_insn "mov_<load>l"
3990 [(set (match_operand:GPR 0 "register_operand" "=d")
3991 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
3992 (match_operand:QI 2 "memory_operand" "ZC")]
3994 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
3996 [(set_attr "move_type" "load")
3997 (set_attr "mode" "<MODE>")])
3999 (define_insn "mov_<load>r"
4000 [(set (match_operand:GPR 0 "register_operand" "=d")
4001 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4002 (match_operand:QI 2 "memory_operand" "ZC")
4003 (match_operand:GPR 3 "register_operand" "0")]
4004 UNSPEC_LOAD_RIGHT))]
4005 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4007 [(set_attr "move_type" "load")
4008 (set_attr "mode" "<MODE>")])
4010 (define_insn "mov_<store>l"
4011 [(set (match_operand:BLK 0 "memory_operand" "=m")
4012 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4013 (match_operand:QI 2 "memory_operand" "ZC")]
4014 UNSPEC_STORE_LEFT))]
4015 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4017 [(set_attr "move_type" "store")
4018 (set_attr "mode" "<MODE>")])
4020 (define_insn "mov_<store>r"
4021 [(set (match_operand:BLK 0 "memory_operand" "+m")
4022 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4023 (match_operand:QI 2 "memory_operand" "ZC")
4025 UNSPEC_STORE_RIGHT))]
4026 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4028 [(set_attr "move_type" "store")
4029 (set_attr "mode" "<MODE>")])
4031 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4032 ;; The required value is:
4034 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4036 ;; which translates to:
4038 ;; lui op0,%highest(op1)
4039 ;; daddiu op0,op0,%higher(op1)
4041 ;; daddiu op0,op0,%hi(op1)
4044 ;; The split is deferred until after flow2 to allow the peephole2 below
4046 (define_insn_and_split "*lea_high64"
4047 [(set (match_operand:DI 0 "register_operand" "=d")
4048 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4049 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4051 "&& epilogue_completed"
4052 [(set (match_dup 0) (high:DI (match_dup 2)))
4053 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4054 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4055 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4056 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4058 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4059 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4061 [(set_attr "length" "20")])
4063 ;; Use a scratch register to reduce the latency of the above pattern
4064 ;; on superscalar machines. The optimized sequence is:
4066 ;; lui op1,%highest(op2)
4068 ;; daddiu op1,op1,%higher(op2)
4070 ;; daddu op1,op1,op0
4072 [(set (match_operand:DI 1 "d_operand")
4073 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4074 (match_scratch:DI 0 "d")]
4075 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4076 [(set (match_dup 1) (high:DI (match_dup 3)))
4077 (set (match_dup 0) (high:DI (match_dup 4)))
4078 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4079 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4080 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4082 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4083 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4086 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4087 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
4088 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4089 ;; used once. We can then use the sequence:
4091 ;; lui op0,%highest(op1)
4093 ;; daddiu op0,op0,%higher(op1)
4094 ;; daddiu op2,op2,%lo(op1)
4096 ;; daddu op0,op0,op2
4098 ;; which takes 4 cycles on most superscalar targets.
4099 (define_insn_and_split "*lea64"
4100 [(set (match_operand:DI 0 "register_operand" "=d")
4101 (match_operand:DI 1 "absolute_symbolic_operand" ""))
4102 (clobber (match_scratch:DI 2 "=&d"))]
4103 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
4105 "&& reload_completed"
4106 [(set (match_dup 0) (high:DI (match_dup 3)))
4107 (set (match_dup 2) (high:DI (match_dup 4)))
4108 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4109 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4110 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4111 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4113 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4114 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4116 [(set_attr "length" "24")])
4118 ;; Split HIGHs into:
4123 ;; on MIPS16 targets.
4125 [(set (match_operand:P 0 "d_operand")
4126 (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4127 "TARGET_MIPS16 && reload_completed"
4128 [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4129 (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4131 (define_insn "*unshifted_high"
4132 [(set (match_operand:P 0 "d_operand" "=d")
4133 (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4134 UNSPEC_UNSHIFTED_HIGH))]
4137 [(set_attr "extended_mips16" "yes")])
4139 ;; Insns to fetch a symbol from a big GOT.
4141 (define_insn_and_split "*xgot_hi<mode>"
4142 [(set (match_operand:P 0 "register_operand" "=d")
4143 (high:P (match_operand:P 1 "got_disp_operand" "")))]
4144 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4146 "&& reload_completed"
4147 [(set (match_dup 0) (high:P (match_dup 2)))
4148 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4150 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4151 operands[3] = pic_offset_table_rtx;
4153 [(set_attr "got" "xgot_high")
4154 (set_attr "mode" "<MODE>")])
4156 (define_insn_and_split "*xgot_lo<mode>"
4157 [(set (match_operand:P 0 "register_operand" "=d")
4158 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4159 (match_operand:P 2 "got_disp_operand" "")))]
4160 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4162 "&& reload_completed"
4164 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4165 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4166 [(set_attr "got" "load")
4167 (set_attr "mode" "<MODE>")])
4169 ;; Insns to fetch a symbol from a normal GOT.
4171 (define_insn_and_split "*got_disp<mode>"
4172 [(set (match_operand:P 0 "register_operand" "=d")
4173 (match_operand:P 1 "got_disp_operand" ""))]
4174 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4176 "&& reload_completed"
4177 [(set (match_dup 0) (match_dup 2))]
4178 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4179 [(set_attr "got" "load")
4180 (set_attr "mode" "<MODE>")])
4182 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4184 (define_insn_and_split "*got_page<mode>"
4185 [(set (match_operand:P 0 "register_operand" "=d")
4186 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4187 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4189 "&& reload_completed"
4190 [(set (match_dup 0) (match_dup 2))]
4191 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4192 [(set_attr "got" "load")
4193 (set_attr "mode" "<MODE>")])
4195 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4196 (define_expand "unspec_got_<mode>"
4197 [(unspec:P [(match_operand:P 0)
4198 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4200 ;; Lower-level instructions for loading an address from the GOT.
4201 ;; We could use MEMs, but an unspec gives more optimization
4204 (define_insn "load_got<mode>"
4205 [(set (match_operand:P 0 "register_operand" "=d")
4206 (unspec:P [(match_operand:P 1 "register_operand" "d")
4207 (match_operand:P 2 "immediate_operand" "")]
4210 "<load>\t%0,%R2(%1)"
4211 [(set_attr "got" "load")
4212 (set_attr "mode" "<MODE>")])
4214 ;; Instructions for adding the low 16 bits of an address to a register.
4215 ;; Operand 2 is the address: mips_print_operand works out which relocation
4216 ;; should be applied.
4218 (define_insn "*low<mode>"
4219 [(set (match_operand:P 0 "register_operand" "=d")
4220 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4221 (match_operand:P 2 "immediate_operand" "")))]
4223 "<d>addiu\t%0,%1,%R2"
4224 [(set_attr "alu_type" "add")
4225 (set_attr "mode" "<MODE>")])
4227 (define_insn "*low<mode>_mips16"
4228 [(set (match_operand:P 0 "register_operand" "=d")
4229 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4230 (match_operand:P 2 "immediate_operand" "")))]
4233 [(set_attr "alu_type" "add")
4234 (set_attr "mode" "<MODE>")
4235 (set_attr "extended_mips16" "yes")])
4237 ;; Expose MIPS16 uses of the global pointer after reload if the function
4238 ;; is responsible for setting up the register itself.
4240 [(set (match_operand:GPR 0 "d_operand")
4241 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4242 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4243 [(set (match_dup 0) (match_dup 1))]
4244 { operands[1] = pic_offset_table_rtx; })
4246 ;; Allow combine to split complex const_int load sequences, using operand 2
4247 ;; to store the intermediate results. See move_operand for details.
4249 [(set (match_operand:GPR 0 "register_operand")
4250 (match_operand:GPR 1 "splittable_const_int_operand"))
4251 (clobber (match_operand:GPR 2 "register_operand"))]
4255 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4259 ;; Likewise, for symbolic operands.
4261 [(set (match_operand:P 0 "register_operand")
4262 (match_operand:P 1))
4263 (clobber (match_operand:P 2 "register_operand"))]
4264 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4265 [(set (match_dup 0) (match_dup 3))]
4267 mips_split_symbol (operands[2], operands[1],
4268 MAX_MACHINE_MODE, &operands[3]);
4271 ;; 64-bit integer moves
4273 ;; Unlike most other insns, the move insns can't be split with
4274 ;; different predicates, because register spilling and other parts of
4275 ;; the compiler, have memoized the insn number already.
4277 (define_expand "movdi"
4278 [(set (match_operand:DI 0 "")
4279 (match_operand:DI 1 ""))]
4282 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4286 ;; For mips16, we need a special case to handle storing $31 into
4287 ;; memory, since we don't have a constraint to match $31. This
4288 ;; instruction can be generated by save_restore_insns.
4290 (define_insn "*mov<mode>_ra"
4291 [(set (match_operand:GPR 0 "stack_operand" "=m")
4292 (reg:GPR RETURN_ADDR_REGNUM))]
4295 [(set_attr "move_type" "store")
4296 (set_attr "mode" "<MODE>")])
4298 (define_insn "*movdi_32bit"
4299 [(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")
4300 (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"))]
4301 "!TARGET_64BIT && !TARGET_MIPS16
4302 && (register_operand (operands[0], DImode)
4303 || reg_or_0_operand (operands[1], DImode))"
4304 { return mips_output_move (operands[0], operands[1]); }
4305 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4307 (if_then_else (eq_attr "move_type" "imul")
4309 (const_string "DI")))])
4311 (define_insn "*movdi_32bit_mips16"
4312 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4313 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4314 "!TARGET_64BIT && TARGET_MIPS16
4315 && (register_operand (operands[0], DImode)
4316 || register_operand (operands[1], DImode))"
4317 { return mips_output_move (operands[0], operands[1]); }
4318 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4319 (set_attr "mode" "DI")])
4321 (define_insn "*movdi_64bit"
4322 [(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")
4323 (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"))]
4324 "TARGET_64BIT && !TARGET_MIPS16
4325 && (register_operand (operands[0], DImode)
4326 || reg_or_0_operand (operands[1], DImode))"
4327 { return mips_output_move (operands[0], operands[1]); }
4328 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4329 (set_attr "mode" "DI")])
4331 (define_insn "*movdi_64bit_mips16"
4332 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4333 (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4334 "TARGET_64BIT && TARGET_MIPS16
4335 && (register_operand (operands[0], DImode)
4336 || register_operand (operands[1], DImode))"
4337 { return mips_output_move (operands[0], operands[1]); }
4338 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4339 (set_attr "mode" "DI")])
4341 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4342 ;; when the original load is a 4 byte instruction but the add and the
4343 ;; load are 2 2 byte instructions.
4346 [(set (match_operand:DI 0 "d_operand")
4347 (mem:DI (plus:DI (match_dup 0)
4348 (match_operand:DI 1 "const_int_operand"))))]
4349 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4350 && !TARGET_DEBUG_D_MODE
4351 && ((INTVAL (operands[1]) < 0
4352 && INTVAL (operands[1]) >= -0x10)
4353 || (INTVAL (operands[1]) >= 32 * 8
4354 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4355 || (INTVAL (operands[1]) >= 0
4356 && INTVAL (operands[1]) < 32 * 8
4357 && (INTVAL (operands[1]) & 7) != 0))"
4358 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4359 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4361 HOST_WIDE_INT val = INTVAL (operands[1]);
4364 operands[2] = const0_rtx;
4365 else if (val >= 32 * 8)
4369 operands[1] = GEN_INT (0x8 + off);
4370 operands[2] = GEN_INT (val - off - 0x8);
4376 operands[1] = GEN_INT (off);
4377 operands[2] = GEN_INT (val - off);
4381 ;; 32-bit Integer moves
4383 ;; Unlike most other insns, the move insns can't be split with
4384 ;; different predicates, because register spilling and other parts of
4385 ;; the compiler, have memoized the insn number already.
4387 (define_expand "mov<mode>"
4388 [(set (match_operand:IMOVE32 0 "")
4389 (match_operand:IMOVE32 1 ""))]
4392 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4396 ;; The difference between these two is whether or not ints are allowed
4397 ;; in FP registers (off by default, use -mdebugh to enable).
4399 (define_insn "*mov<mode>_internal"
4400 [(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")
4401 (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!u,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4403 && (register_operand (operands[0], <MODE>mode)
4404 || reg_or_0_operand (operands[1], <MODE>mode))"
4405 { return mips_output_move (operands[0], operands[1]); }
4406 [(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")
4407 (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4408 (set_attr "mode" "SI")])
4410 (define_insn "*mov<mode>_mips16"
4411 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4412 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4414 && (register_operand (operands[0], <MODE>mode)
4415 || register_operand (operands[1], <MODE>mode))"
4416 { return mips_output_move (operands[0], operands[1]); }
4417 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4418 (set_attr "mode" "SI")])
4420 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4421 ;; when the original load is a 4 byte instruction but the add and the
4422 ;; load are 2 2 byte instructions.
4425 [(set (match_operand:SI 0 "d_operand")
4426 (mem:SI (plus:SI (match_dup 0)
4427 (match_operand:SI 1 "const_int_operand"))))]
4428 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4429 && ((INTVAL (operands[1]) < 0
4430 && INTVAL (operands[1]) >= -0x80)
4431 || (INTVAL (operands[1]) >= 32 * 4
4432 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4433 || (INTVAL (operands[1]) >= 0
4434 && INTVAL (operands[1]) < 32 * 4
4435 && (INTVAL (operands[1]) & 3) != 0))"
4436 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4437 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4439 HOST_WIDE_INT val = INTVAL (operands[1]);
4442 operands[2] = const0_rtx;
4443 else if (val >= 32 * 4)
4447 operands[1] = GEN_INT (0x7c + off);
4448 operands[2] = GEN_INT (val - off - 0x7c);
4454 operands[1] = GEN_INT (off);
4455 operands[2] = GEN_INT (val - off);
4459 ;; On the mips16, we can split a load of certain constants into a load
4460 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4464 [(set (match_operand:SI 0 "d_operand")
4465 (match_operand:SI 1 "const_int_operand"))]
4466 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4467 && INTVAL (operands[1]) >= 0x100
4468 && INTVAL (operands[1]) <= 0xff + 0x7f"
4469 [(set (match_dup 0) (match_dup 1))
4470 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4472 int val = INTVAL (operands[1]);
4474 operands[1] = GEN_INT (0xff);
4475 operands[2] = GEN_INT (val - 0xff);
4478 ;; MIPS4 supports loading and storing a floating point register from
4479 ;; the sum of two general registers. We use two versions for each of
4480 ;; these four instructions: one where the two general registers are
4481 ;; SImode, and one where they are DImode. This is because general
4482 ;; registers will be in SImode when they hold 32-bit values, but,
4483 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4484 ;; instructions will still work correctly.
4486 ;; ??? Perhaps it would be better to support these instructions by
4487 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4488 ;; these instructions can only be used to load and store floating
4489 ;; point registers, that would probably cause trouble in reload.
4491 (define_insn "*<ANYF:loadx>_<P:mode>"
4492 [(set (match_operand:ANYF 0 "register_operand" "=f")
4493 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4494 (match_operand:P 2 "register_operand" "d"))))]
4496 "<ANYF:loadx>\t%0,%1(%2)"
4497 [(set_attr "type" "fpidxload")
4498 (set_attr "mode" "<ANYF:UNITMODE>")])
4500 (define_insn "*<ANYF:storex>_<P:mode>"
4501 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4502 (match_operand:P 2 "register_operand" "d")))
4503 (match_operand:ANYF 0 "register_operand" "f"))]
4505 "<ANYF:storex>\t%0,%1(%2)"
4506 [(set_attr "type" "fpidxstore")
4507 (set_attr "mode" "<ANYF:UNITMODE>")])
4509 ;; Scaled indexed address load.
4510 ;; Per md.texi, we only need to look for a pattern with multiply in the
4511 ;; address expression, not shift.
4513 (define_insn "*lwxs"
4514 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4516 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4518 (match_operand:P 2 "register_operand" "d"))))]
4521 [(set_attr "type" "load")
4522 (set_attr "mode" "SI")])
4524 ;; 16-bit Integer moves
4526 ;; Unlike most other insns, the move insns can't be split with
4527 ;; different predicates, because register spilling and other parts of
4528 ;; the compiler, have memoized the insn number already.
4529 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4531 (define_expand "movhi"
4532 [(set (match_operand:HI 0 "")
4533 (match_operand:HI 1 ""))]
4536 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4540 (define_insn "*movhi_internal"
4541 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4542 (match_operand:HI 1 "move_operand" "d,I,m,dJ,*d*J,*a"))]
4544 && (register_operand (operands[0], HImode)
4545 || reg_or_0_operand (operands[1], HImode))"
4546 { return mips_output_move (operands[0], operands[1]); }
4547 [(set_attr "move_type" "move,const,load,store,mtlo,mflo")
4548 (set_attr "mode" "HI")])
4550 (define_insn "*movhi_mips16"
4551 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4552 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4554 && (register_operand (operands[0], HImode)
4555 || register_operand (operands[1], HImode))"
4556 { return mips_output_move (operands[0], operands[1]); }
4557 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4558 (set_attr "mode" "HI")])
4560 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4561 ;; when the original load is a 4 byte instruction but the add and the
4562 ;; load are 2 2 byte instructions.
4565 [(set (match_operand:HI 0 "d_operand")
4566 (mem:HI (plus:SI (match_dup 0)
4567 (match_operand:SI 1 "const_int_operand"))))]
4568 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4569 && ((INTVAL (operands[1]) < 0
4570 && INTVAL (operands[1]) >= -0x80)
4571 || (INTVAL (operands[1]) >= 32 * 2
4572 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4573 || (INTVAL (operands[1]) >= 0
4574 && INTVAL (operands[1]) < 32 * 2
4575 && (INTVAL (operands[1]) & 1) != 0))"
4576 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4577 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4579 HOST_WIDE_INT val = INTVAL (operands[1]);
4582 operands[2] = const0_rtx;
4583 else if (val >= 32 * 2)
4587 operands[1] = GEN_INT (0x7e + off);
4588 operands[2] = GEN_INT (val - off - 0x7e);
4594 operands[1] = GEN_INT (off);
4595 operands[2] = GEN_INT (val - off);
4599 ;; 8-bit Integer moves
4601 ;; Unlike most other insns, the move insns can't be split with
4602 ;; different predicates, because register spilling and other parts of
4603 ;; the compiler, have memoized the insn number already.
4604 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4606 (define_expand "movqi"
4607 [(set (match_operand:QI 0 "")
4608 (match_operand:QI 1 ""))]
4611 if (mips_legitimize_move (QImode, operands[0], operands[1]))
4615 (define_insn "*movqi_internal"
4616 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*a,*d")
4617 (match_operand:QI 1 "move_operand" "d,I,m,dJ,*d*J,*a"))]
4619 && (register_operand (operands[0], QImode)
4620 || reg_or_0_operand (operands[1], QImode))"
4621 { return mips_output_move (operands[0], operands[1]); }
4622 [(set_attr "move_type" "move,const,load,store,mtlo,mflo")
4623 (set_attr "mode" "QI")])
4625 (define_insn "*movqi_mips16"
4626 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4627 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4629 && (register_operand (operands[0], QImode)
4630 || register_operand (operands[1], QImode))"
4631 { return mips_output_move (operands[0], operands[1]); }
4632 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4633 (set_attr "mode" "QI")])
4635 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4636 ;; when the original load is a 4 byte instruction but the add and the
4637 ;; load are 2 2 byte instructions.
4640 [(set (match_operand:QI 0 "d_operand")
4641 (mem:QI (plus:SI (match_dup 0)
4642 (match_operand:SI 1 "const_int_operand"))))]
4643 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4644 && ((INTVAL (operands[1]) < 0
4645 && INTVAL (operands[1]) >= -0x80)
4646 || (INTVAL (operands[1]) >= 32
4647 && INTVAL (operands[1]) <= 31 + 0x7f))"
4648 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4649 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
4651 HOST_WIDE_INT val = INTVAL (operands[1]);
4654 operands[2] = const0_rtx;
4657 operands[1] = GEN_INT (0x7f);
4658 operands[2] = GEN_INT (val - 0x7f);
4662 ;; 32-bit floating point moves
4664 (define_expand "movsf"
4665 [(set (match_operand:SF 0 "")
4666 (match_operand:SF 1 ""))]
4669 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
4673 (define_insn "*movsf_hardfloat"
4674 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4675 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
4677 && (register_operand (operands[0], SFmode)
4678 || reg_or_0_operand (operands[1], SFmode))"
4679 { return mips_output_move (operands[0], operands[1]); }
4680 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4681 (set_attr "mode" "SF")])
4683 (define_insn "*movsf_softfloat"
4684 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
4685 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
4686 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
4687 && (register_operand (operands[0], SFmode)
4688 || reg_or_0_operand (operands[1], SFmode))"
4689 { return mips_output_move (operands[0], operands[1]); }
4690 [(set_attr "move_type" "move,load,store")
4691 (set_attr "mode" "SF")])
4693 (define_insn "*movsf_mips16"
4694 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
4695 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
4697 && (register_operand (operands[0], SFmode)
4698 || register_operand (operands[1], SFmode))"
4699 { return mips_output_move (operands[0], operands[1]); }
4700 [(set_attr "move_type" "move,move,move,load,store")
4701 (set_attr "mode" "SF")])
4703 ;; 64-bit floating point moves
4705 (define_expand "movdf"
4706 [(set (match_operand:DF 0 "")
4707 (match_operand:DF 1 ""))]
4710 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
4714 (define_insn "*movdf_hardfloat"
4715 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4716 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
4717 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
4718 && (register_operand (operands[0], DFmode)
4719 || reg_or_0_operand (operands[1], DFmode))"
4720 { return mips_output_move (operands[0], operands[1]); }
4721 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4722 (set_attr "mode" "DF")])
4724 (define_insn "*movdf_softfloat"
4725 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
4726 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
4727 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
4728 && (register_operand (operands[0], DFmode)
4729 || reg_or_0_operand (operands[1], DFmode))"
4730 { return mips_output_move (operands[0], operands[1]); }
4731 [(set_attr "move_type" "move,load,store")
4732 (set_attr "mode" "DF")])
4734 (define_insn "*movdf_mips16"
4735 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
4736 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
4738 && (register_operand (operands[0], DFmode)
4739 || register_operand (operands[1], DFmode))"
4740 { return mips_output_move (operands[0], operands[1]); }
4741 [(set_attr "move_type" "move,move,move,load,store")
4742 (set_attr "mode" "DF")])
4744 ;; 128-bit integer moves
4746 (define_expand "movti"
4747 [(set (match_operand:TI 0)
4748 (match_operand:TI 1))]
4751 if (mips_legitimize_move (TImode, operands[0], operands[1]))
4755 (define_insn "*movti"
4756 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
4757 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
4760 && (register_operand (operands[0], TImode)
4761 || reg_or_0_operand (operands[1], TImode))"
4762 { return mips_output_move (operands[0], operands[1]); }
4763 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
4765 (if_then_else (eq_attr "move_type" "imul")
4767 (const_string "TI")))])
4769 (define_insn "*movti_mips16"
4770 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4771 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4774 && (register_operand (operands[0], TImode)
4775 || register_operand (operands[1], TImode))"
4777 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4778 (set_attr "mode" "TI")])
4780 ;; 128-bit floating point moves
4782 (define_expand "movtf"
4783 [(set (match_operand:TF 0)
4784 (match_operand:TF 1))]
4787 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
4791 ;; This pattern handles both hard- and soft-float cases.
4792 (define_insn "*movtf"
4793 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
4794 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
4797 && (register_operand (operands[0], TFmode)
4798 || reg_or_0_operand (operands[1], TFmode))"
4800 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
4801 (set_attr "mode" "TF")])
4803 (define_insn "*movtf_mips16"
4804 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
4805 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
4808 && (register_operand (operands[0], TFmode)
4809 || register_operand (operands[1], TFmode))"
4811 [(set_attr "move_type" "move,move,move,load,store")
4812 (set_attr "mode" "TF")])
4815 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
4816 (match_operand:MOVE64 1 "move_operand"))]
4817 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
4820 mips_split_move_insn (operands[0], operands[1], curr_insn);
4825 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
4826 (match_operand:MOVE128 1 "move_operand"))]
4827 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
4830 mips_split_move_insn (operands[0], operands[1], curr_insn);
4834 ;; When generating mips16 code, split moves of negative constants into
4835 ;; a positive "li" followed by a negation.
4837 [(set (match_operand 0 "d_operand")
4838 (match_operand 1 "const_int_operand"))]
4839 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
4843 (neg:SI (match_dup 2)))]
4845 operands[2] = gen_lowpart (SImode, operands[0]);
4846 operands[3] = GEN_INT (-INTVAL (operands[1]));
4849 ;; 64-bit paired-single floating point moves
4851 (define_expand "movv2sf"
4852 [(set (match_operand:V2SF 0)
4853 (match_operand:V2SF 1))]
4854 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
4856 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
4860 (define_insn "*movv2sf"
4861 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
4862 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
4864 && TARGET_PAIRED_SINGLE_FLOAT
4865 && (register_operand (operands[0], V2SFmode)
4866 || reg_or_0_operand (operands[1], V2SFmode))"
4867 { return mips_output_move (operands[0], operands[1]); }
4868 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
4869 (set_attr "mode" "DF")])
4871 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
4872 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
4874 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
4875 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
4876 ;; and the errata related to -mfix-vr4130.
4877 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
4878 [(set (match_operand:GPR 0 "register_operand" "=d")
4879 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
4882 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
4883 [(set_attr "type" "mfhi")
4884 (set_attr "mode" "<GPR:MODE>")])
4886 ;; Set the high part of a HI/LO value, given that the low part has
4887 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
4888 ;; why we can't just use (reg:GPR HI_REGNUM).
4889 (define_insn "mthi<GPR:mode>_<HILO:mode>"
4890 [(set (match_operand:HILO 0 "register_operand" "=x")
4891 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4892 (match_operand:GPR 2 "register_operand" "l")]
4896 [(set_attr "type" "mthi")
4897 (set_attr "mode" "SI")])
4899 ;; Emit a doubleword move in which exactly one of the operands is
4900 ;; a floating-point register. We can't just emit two normal moves
4901 ;; because of the constraints imposed by the FPU register model;
4902 ;; see mips_cannot_change_mode_class for details. Instead, we keep
4903 ;; the FPR whole and use special patterns to refer to each word of
4904 ;; the other operand.
4906 (define_expand "move_doubleword_fpr<mode>"
4907 [(set (match_operand:SPLITF 0)
4908 (match_operand:SPLITF 1))]
4911 if (FP_REG_RTX_P (operands[0]))
4913 rtx low = mips_subword (operands[1], 0);
4914 rtx high = mips_subword (operands[1], 1);
4915 emit_insn (gen_load_low<mode> (operands[0], low));
4916 if (TARGET_FLOAT64 && !TARGET_64BIT)
4917 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
4919 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
4923 rtx low = mips_subword (operands[0], 0);
4924 rtx high = mips_subword (operands[0], 1);
4925 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
4926 if (TARGET_FLOAT64 && !TARGET_64BIT)
4927 emit_insn (gen_mfhc1<mode> (high, operands[1]));
4929 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
4934 ;; Load the low word of operand 0 with operand 1.
4935 (define_insn "load_low<mode>"
4936 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4937 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
4941 operands[0] = mips_subword (operands[0], 0);
4942 return mips_output_move (operands[0], operands[1]);
4944 [(set_attr "move_type" "mtc,fpload")
4945 (set_attr "mode" "<HALFMODE>")])
4947 ;; Load the high word of operand 0 from operand 1, preserving the value
4949 (define_insn "load_high<mode>"
4950 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
4951 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
4952 (match_operand:SPLITF 2 "register_operand" "0,0")]
4956 operands[0] = mips_subword (operands[0], 1);
4957 return mips_output_move (operands[0], operands[1]);
4959 [(set_attr "move_type" "mtc,fpload")
4960 (set_attr "mode" "<HALFMODE>")])
4962 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
4963 ;; high word and 0 to store the low word.
4964 (define_insn "store_word<mode>"
4965 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
4966 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
4967 (match_operand 2 "const_int_operand")]
4968 UNSPEC_STORE_WORD))]
4971 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
4972 return mips_output_move (operands[0], operands[1]);
4974 [(set_attr "move_type" "mfc,fpstore")
4975 (set_attr "mode" "<HALFMODE>")])
4977 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
4978 ;; value in the low word.
4979 (define_insn "mthc1<mode>"
4980 [(set (match_operand:SPLITF 0 "register_operand" "=f")
4981 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
4982 (match_operand:SPLITF 2 "register_operand" "0")]
4984 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4986 [(set_attr "move_type" "mtc")
4987 (set_attr "mode" "<HALFMODE>")])
4989 ;; Move high word of operand 1 to operand 0 using mfhc1.
4990 (define_insn "mfhc1<mode>"
4991 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
4992 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
4994 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
4996 [(set_attr "move_type" "mfc")
4997 (set_attr "mode" "<HALFMODE>")])
4999 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5000 (define_expand "load_const_gp_<mode>"
5001 [(set (match_operand:P 0 "register_operand" "=d")
5002 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5004 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
5005 ;; of _gp from the start of this function. Operand 1 is the incoming
5006 ;; function address.
5007 (define_insn_and_split "loadgp_newabi_<mode>"
5008 [(set (match_operand:P 0 "register_operand" "=&d")
5009 (unspec:P [(match_operand:P 1)
5010 (match_operand:P 2 "register_operand" "d")]
5012 "mips_current_loadgp_style () == LOADGP_NEWABI"
5013 { return mips_must_initialize_gp_p () ? "#" : ""; }
5014 "&& mips_must_initialize_gp_p ()"
5015 [(set (match_dup 0) (match_dup 3))
5016 (set (match_dup 0) (match_dup 4))
5017 (set (match_dup 0) (match_dup 5))]
5019 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5020 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5021 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5023 [(set_attr "type" "ghost")])
5025 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
5026 (define_insn_and_split "loadgp_absolute_<mode>"
5027 [(set (match_operand:P 0 "register_operand" "=d")
5028 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5029 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5030 { return mips_must_initialize_gp_p () ? "#" : ""; }
5031 "&& mips_must_initialize_gp_p ()"
5034 mips_emit_move (operands[0], operands[1]);
5037 [(set_attr "type" "ghost")])
5039 ;; This blockage instruction prevents the gp load from being
5040 ;; scheduled after an implicit use of gp. It also prevents
5041 ;; the load from being deleted as dead.
5042 (define_insn "loadgp_blockage"
5043 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5046 [(set_attr "type" "ghost")])
5048 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
5049 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5050 (define_insn_and_split "loadgp_rtp_<mode>"
5051 [(set (match_operand:P 0 "register_operand" "=d")
5052 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5053 (match_operand:P 2 "symbol_ref_operand")]
5055 "mips_current_loadgp_style () == LOADGP_RTP"
5056 { return mips_must_initialize_gp_p () ? "#" : ""; }
5057 "&& mips_must_initialize_gp_p ()"
5058 [(set (match_dup 0) (high:P (match_dup 3)))
5059 (set (match_dup 0) (unspec:P [(match_dup 0)
5060 (match_dup 3)] UNSPEC_LOAD_GOT))
5061 (set (match_dup 0) (unspec:P [(match_dup 0)
5062 (match_dup 4)] UNSPEC_LOAD_GOT))]
5064 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5065 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5067 [(set_attr "type" "ghost")])
5069 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
5070 ;; global pointer and operand 1 is the MIPS16 register that holds
5071 ;; the required value.
5072 (define_insn_and_split "copygp_mips16_<mode>"
5073 [(set (match_operand:P 0 "register_operand" "=y")
5074 (unspec:P [(match_operand:P 1 "register_operand" "d")]
5077 { return mips_must_initialize_gp_p () ? "#" : ""; }
5078 "&& mips_must_initialize_gp_p ()"
5079 [(set (match_dup 0) (match_dup 1))]
5081 [(set_attr "type" "ghost")])
5083 ;; A placeholder for where the cprestore instruction should go,
5084 ;; if we decide we need one. Operand 0 and operand 1 are as for
5085 ;; "cprestore". Operand 2 is a register that holds the gp value.
5087 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5088 ;; otherwise any register that holds the correct value will do.
5089 (define_insn_and_split "potential_cprestore_<mode>"
5090 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5091 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5092 (match_operand:P 2 "register_operand" "d,d")]
5093 UNSPEC_POTENTIAL_CPRESTORE))
5094 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5095 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5096 { return mips_must_initialize_gp_p () ? "#" : ""; }
5097 "mips_must_initialize_gp_p ()"
5100 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5101 operands[2], operands[3]);
5104 [(set_attr "type" "ghost")])
5106 ;; Emit a .cprestore directive, which normally expands to a single store
5107 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
5108 ;; for the cprestore slot. Operand 1 is the offset of the slot from
5109 ;; the stack pointer. (This is redundant with operand 0, but it makes
5110 ;; things a little simpler.)
5111 (define_insn "cprestore_<mode>"
5112 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5113 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5116 "TARGET_CPRESTORE_DIRECTIVE"
5118 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5119 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5121 return ".cprestore\t%1";
5123 [(set_attr "type" "store")
5124 (set_attr "length" "4,12")])
5126 (define_insn "use_cprestore_<mode>"
5127 [(set (reg:P CPRESTORE_SLOT_REGNUM)
5128 (match_operand:P 0 "cprestore_load_slot_operand"))]
5131 [(set_attr "type" "ghost")])
5133 ;; Expand in-line code to clear the instruction cache between operand[0] and
5135 (define_expand "clear_cache"
5136 [(match_operand 0 "pmode_register_operand")
5137 (match_operand 1 "pmode_register_operand")]
5143 mips_expand_synci_loop (operands[0], operands[1]);
5144 emit_insn (gen_sync ());
5145 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5147 else if (mips_cache_flush_func && mips_cache_flush_func[0])
5149 rtx len = gen_reg_rtx (Pmode);
5150 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5151 MIPS_ICACHE_SYNC (operands[0], len);
5157 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5159 { return mips_output_sync (); })
5161 (define_insn "synci"
5162 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5167 (define_insn "rdhwr_synci_step_<mode>"
5168 [(set (match_operand:P 0 "register_operand" "=d")
5169 (unspec_volatile [(const_int 1)]
5174 (define_insn "clear_hazard_<mode>"
5175 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5176 (clobber (reg:P RETURN_ADDR_REGNUM))]
5179 return "%(%<bal\t1f\n"
5181 "1:\t<d>addiu\t$31,$31,12\n"
5185 [(set_attr "length" "20")])
5187 ;; Cache operations for R4000-style caches.
5188 (define_insn "mips_cache"
5189 [(set (mem:BLK (scratch))
5190 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5191 (match_operand:QI 1 "address_operand" "p")]
5192 UNSPEC_MIPS_CACHE))]
5196 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5197 ;; operation. We keep the pattern distinct so that we can identify
5198 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5199 ;; the operation is never inserted into a delay slot.
5200 (define_insn "r10k_cache_barrier"
5201 [(set (mem:BLK (scratch))
5202 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5205 [(set_attr "can_delay" "no")])
5207 ;; Block moves, see mips.c for more details.
5208 ;; Argument 0 is the destination
5209 ;; Argument 1 is the source
5210 ;; Argument 2 is the length
5211 ;; Argument 3 is the alignment
5213 (define_expand "movmemsi"
5214 [(parallel [(set (match_operand:BLK 0 "general_operand")
5215 (match_operand:BLK 1 "general_operand"))
5216 (use (match_operand:SI 2 ""))
5217 (use (match_operand:SI 3 "const_int_operand"))])]
5218 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5220 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5227 ;; ....................
5231 ;; ....................
5233 (define_expand "<optab><mode>3"
5234 [(set (match_operand:GPR 0 "register_operand")
5235 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5236 (match_operand:SI 2 "arith_operand")))]
5239 /* On the mips16, a shift of more than 8 is a four byte instruction,
5240 so, for a shift between 8 and 16, it is just as fast to do two
5241 shifts of 8 or less. If there is a lot of shifting going on, we
5242 may win in CSE. Otherwise combine will put the shifts back
5243 together again. This can be called by mips_function_arg, so we must
5244 be careful not to allocate a new register if we've reached the
5248 && CONST_INT_P (operands[2])
5249 && INTVAL (operands[2]) > 8
5250 && INTVAL (operands[2]) <= 16
5251 && !reload_in_progress
5252 && !reload_completed)
5254 rtx temp = gen_reg_rtx (<MODE>mode);
5256 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5257 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5258 GEN_INT (INTVAL (operands[2]) - 8)));
5263 (define_insn "*<optab><mode>3"
5264 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5265 (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5266 (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5269 if (CONST_INT_P (operands[2]))
5270 operands[2] = GEN_INT (INTVAL (operands[2])
5271 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5273 return "<d><insn>\t%0,%1,%2";
5275 [(set_attr "type" "shift")
5276 (set_attr "compression" "<shift_compression>,none")
5277 (set_attr "mode" "<MODE>")])
5279 (define_insn "*<optab>si3_extend"
5280 [(set (match_operand:DI 0 "register_operand" "=d")
5282 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5283 (match_operand:SI 2 "arith_operand" "dI"))))]
5284 "TARGET_64BIT && !TARGET_MIPS16"
5286 if (CONST_INT_P (operands[2]))
5287 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5289 return "<insn>\t%0,%1,%2";
5291 [(set_attr "type" "shift")
5292 (set_attr "mode" "SI")])
5294 (define_insn "*<optab>si3_mips16"
5295 [(set (match_operand:SI 0 "register_operand" "=d,d")
5296 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
5297 (match_operand:SI 2 "arith_operand" "d,I")))]
5300 if (which_alternative == 0)
5301 return "<insn>\t%0,%2";
5303 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5304 return "<insn>\t%0,%1,%2";
5306 [(set_attr "type" "shift")
5307 (set_attr "mode" "SI")
5308 (set_attr_alternative "length"
5310 (if_then_else (match_operand 2 "m16_uimm3_b")
5314 ;; We need separate DImode MIPS16 patterns because of the irregularity
5316 (define_insn "*ashldi3_mips16"
5317 [(set (match_operand:DI 0 "register_operand" "=d,d")
5318 (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
5319 (match_operand:SI 2 "arith_operand" "d,I")))]
5320 "TARGET_64BIT && TARGET_MIPS16"
5322 if (which_alternative == 0)
5323 return "dsll\t%0,%2";
5325 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5326 return "dsll\t%0,%1,%2";
5328 [(set_attr "type" "shift")
5329 (set_attr "mode" "DI")
5330 (set_attr_alternative "length"
5332 (if_then_else (match_operand 2 "m16_uimm3_b")
5336 (define_insn "*ashrdi3_mips16"
5337 [(set (match_operand:DI 0 "register_operand" "=d,d")
5338 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5339 (match_operand:SI 2 "arith_operand" "d,I")))]
5340 "TARGET_64BIT && TARGET_MIPS16"
5342 if (CONST_INT_P (operands[2]))
5343 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5345 return "dsra\t%0,%2";
5347 [(set_attr "type" "shift")
5348 (set_attr "mode" "DI")
5349 (set_attr_alternative "length"
5351 (if_then_else (match_operand 2 "m16_uimm3_b")
5355 (define_insn "*lshrdi3_mips16"
5356 [(set (match_operand:DI 0 "register_operand" "=d,d")
5357 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
5358 (match_operand:SI 2 "arith_operand" "d,I")))]
5359 "TARGET_64BIT && TARGET_MIPS16"
5361 if (CONST_INT_P (operands[2]))
5362 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5364 return "dsrl\t%0,%2";
5366 [(set_attr "type" "shift")
5367 (set_attr "mode" "DI")
5368 (set_attr_alternative "length"
5370 (if_then_else (match_operand 2 "m16_uimm3_b")
5374 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5377 [(set (match_operand:GPR 0 "d_operand")
5378 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5379 (match_operand:GPR 2 "const_int_operand")))]
5380 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5381 && INTVAL (operands[2]) > 8
5382 && INTVAL (operands[2]) <= 16"
5383 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5384 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5385 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5387 ;; If we load a byte on the mips16 as a bitfield, the resulting
5388 ;; sequence of instructions is too complicated for combine, because it
5389 ;; involves four instructions: a load, a shift, a constant load into a
5390 ;; register, and an and (the key problem here is that the mips16 does
5391 ;; not have and immediate). We recognize a shift of a load in order
5392 ;; to make it simple enough for combine to understand.
5394 ;; The length here is the worst case: the length of the split version
5395 ;; will be more accurate.
5396 (define_insn_and_split ""
5397 [(set (match_operand:SI 0 "register_operand" "=d")
5398 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5399 (match_operand:SI 2 "immediate_operand" "I")))]
5403 [(set (match_dup 0) (match_dup 1))
5404 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5406 [(set_attr "type" "load")
5407 (set_attr "mode" "SI")
5408 (set_attr "length" "16")])
5410 (define_insn "rotr<mode>3"
5411 [(set (match_operand:GPR 0 "register_operand" "=d")
5412 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5413 (match_operand:SI 2 "arith_operand" "dI")))]
5416 if (CONST_INT_P (operands[2]))
5417 gcc_assert (INTVAL (operands[2]) >= 0
5418 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5420 return "<d>ror\t%0,%1,%2";
5422 [(set_attr "type" "shift")
5423 (set_attr "mode" "<MODE>")])
5426 ;; ....................
5428 ;; CONDITIONAL BRANCHES
5430 ;; ....................
5432 ;; Conditional branches on floating-point equality tests.
5434 (define_insn "*branch_fp"
5437 (match_operator 1 "equality_operator"
5438 [(match_operand:CC 2 "register_operand" "z")
5440 (label_ref (match_operand 0 "" ""))
5444 return mips_output_conditional_branch (insn, operands,
5445 MIPS_BRANCH ("b%F1", "%Z2%0"),
5446 MIPS_BRANCH ("b%W1", "%Z2%0"));
5448 [(set_attr "type" "branch")])
5450 (define_insn "*branch_fp_inverted"
5453 (match_operator 1 "equality_operator"
5454 [(match_operand:CC 2 "register_operand" "z")
5457 (label_ref (match_operand 0 "" ""))))]
5460 return mips_output_conditional_branch (insn, operands,
5461 MIPS_BRANCH ("b%W1", "%Z2%0"),
5462 MIPS_BRANCH ("b%F1", "%Z2%0"));
5464 [(set_attr "type" "branch")])
5466 ;; Conditional branches on ordered comparisons with zero.
5468 (define_insn "*branch_order<mode>"
5471 (match_operator 1 "order_operator"
5472 [(match_operand:GPR 2 "register_operand" "d")
5474 (label_ref (match_operand 0 "" ""))
5477 { return mips_output_order_conditional_branch (insn, operands, false); }
5478 [(set_attr "type" "branch")])
5480 (define_insn "*branch_order<mode>_inverted"
5483 (match_operator 1 "order_operator"
5484 [(match_operand:GPR 2 "register_operand" "d")
5487 (label_ref (match_operand 0 "" ""))))]
5489 { return mips_output_order_conditional_branch (insn, operands, true); }
5490 [(set_attr "type" "branch")])
5492 ;; Conditional branch on equality comparison.
5494 (define_insn "*branch_equality<mode>"
5497 (match_operator 1 "equality_operator"
5498 [(match_operand:GPR 2 "register_operand" "d")
5499 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5500 (label_ref (match_operand 0 "" ""))
5504 /* For a simple BNEZ or BEQZ microMIPS branch. */
5505 if (TARGET_MICROMIPS
5506 && operands[3] == const0_rtx
5507 && get_attr_length (insn) <= 8)
5508 return mips_output_conditional_branch (insn, operands,
5510 "%*b%N1z%:\t%2,%0");
5512 return mips_output_conditional_branch (insn, operands,
5513 MIPS_BRANCH ("b%C1", "%2,%z3,%0"),
5514 MIPS_BRANCH ("b%N1", "%2,%z3,%0"));
5516 [(set_attr "type" "branch")])
5518 (define_insn "*branch_equality<mode>_inverted"
5521 (match_operator 1 "equality_operator"
5522 [(match_operand:GPR 2 "register_operand" "d")
5523 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5525 (label_ref (match_operand 0 "" ""))))]
5528 /* For a simple BNEZ or BEQZ microMIPS branch. */
5529 if (TARGET_MICROMIPS
5530 && operands[3] == const0_rtx
5531 && get_attr_length (insn) <= 8)
5532 return mips_output_conditional_branch (insn, operands,
5534 "%*b%C0z%:\t%2,%1");
5536 return mips_output_conditional_branch (insn, operands,
5537 MIPS_BRANCH ("b%N1", "%2,%z3,%0"),
5538 MIPS_BRANCH ("b%C1", "%2,%z3,%0"));
5540 [(set_attr "type" "branch")])
5544 (define_insn "*branch_equality<mode>_mips16"
5547 (match_operator 1 "equality_operator"
5548 [(match_operand:GPR 2 "register_operand" "d,t")
5550 (label_ref (match_operand 0 "" ""))
5556 [(set_attr "type" "branch")])
5558 (define_insn "*branch_equality<mode>_mips16_inverted"
5561 (match_operator 1 "equality_operator"
5562 [(match_operand:GPR 2 "register_operand" "d,t")
5565 (label_ref (match_operand 0 "" ""))))]
5570 [(set_attr "type" "branch")])
5572 (define_expand "cbranch<mode>4"
5574 (if_then_else (match_operator 0 "comparison_operator"
5575 [(match_operand:GPR 1 "register_operand")
5576 (match_operand:GPR 2 "nonmemory_operand")])
5577 (label_ref (match_operand 3 ""))
5581 mips_expand_conditional_branch (operands);
5585 (define_expand "cbranch<mode>4"
5587 (if_then_else (match_operator 0 "comparison_operator"
5588 [(match_operand:SCALARF 1 "register_operand")
5589 (match_operand:SCALARF 2 "register_operand")])
5590 (label_ref (match_operand 3 ""))
5594 mips_expand_conditional_branch (operands);
5598 ;; Used to implement built-in functions.
5599 (define_expand "condjump"
5601 (if_then_else (match_operand 0)
5602 (label_ref (match_operand 1))
5605 ;; Branch if bit is set/clear.
5607 (define_insn "*branch_bit<bbv><mode>"
5610 (equality_op (zero_extract:GPR
5611 (match_operand:GPR 1 "register_operand" "d")
5613 (match_operand 2 "const_int_operand" ""))
5615 (label_ref (match_operand 0 ""))
5617 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5620 mips_output_conditional_branch (insn, operands,
5621 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
5622 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
5624 [(set_attr "type" "branch")
5625 (set_attr "branch_likely" "no")])
5627 (define_insn "*branch_bit<bbv><mode>_inverted"
5630 (equality_op (zero_extract:GPR
5631 (match_operand:GPR 1 "register_operand" "d")
5633 (match_operand 2 "const_int_operand" ""))
5636 (label_ref (match_operand 0 ""))))]
5637 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
5640 mips_output_conditional_branch (insn, operands,
5641 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
5642 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
5644 [(set_attr "type" "branch")
5645 (set_attr "branch_likely" "no")])
5648 ;; ....................
5650 ;; SETTING A REGISTER FROM A COMPARISON
5652 ;; ....................
5654 ;; Destination is always set in SI mode.
5656 (define_expand "cstore<mode>4"
5657 [(set (match_operand:SI 0 "register_operand")
5658 (match_operator:SI 1 "mips_cstore_operator"
5659 [(match_operand:GPR 2 "register_operand")
5660 (match_operand:GPR 3 "nonmemory_operand")]))]
5663 mips_expand_scc (operands);
5667 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
5668 [(set (match_operand:GPR2 0 "register_operand" "=d")
5669 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5671 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5673 [(set_attr "type" "slt")
5674 (set_attr "mode" "<GPR:MODE>")])
5676 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
5677 [(set (match_operand:GPR2 0 "register_operand" "=t")
5678 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
5680 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5682 [(set_attr "type" "slt")
5683 (set_attr "mode" "<GPR:MODE>")])
5685 ;; Generate sltiu unless using seq results in better code.
5686 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
5687 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5688 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5689 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5695 [(set_attr "type" "slt")
5696 (set_attr "mode" "<GPR:MODE>")])
5698 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
5699 [(set (match_operand:GPR2 0 "register_operand" "=d")
5700 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
5702 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
5704 [(set_attr "type" "slt")
5705 (set_attr "mode" "<GPR:MODE>")])
5707 ;; Generate sltu unless using sne results in better code.
5708 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
5709 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
5710 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
5711 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
5717 [(set_attr "type" "slt")
5718 (set_attr "mode" "<GPR:MODE>")])
5720 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
5721 [(set (match_operand:GPR2 0 "register_operand" "=d")
5722 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5723 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
5726 [(set_attr "type" "slt")
5727 (set_attr "mode" "<GPR:MODE>")])
5729 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
5730 [(set (match_operand:GPR2 0 "register_operand" "=t")
5731 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5732 (match_operand:GPR 2 "register_operand" "d")))]
5735 [(set_attr "type" "slt")
5736 (set_attr "mode" "<GPR:MODE>")])
5738 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
5739 [(set (match_operand:GPR2 0 "register_operand" "=d")
5740 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
5744 [(set_attr "type" "slt")
5745 (set_attr "mode" "<GPR:MODE>")])
5747 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
5748 [(set (match_operand:GPR2 0 "register_operand" "=d")
5749 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
5750 (match_operand:GPR 2 "arith_operand" "dI")))]
5753 [(set_attr "type" "slt")
5754 (set_attr "mode" "<GPR:MODE>")])
5756 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
5757 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
5758 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
5759 (match_operand:GPR 2 "arith_operand" "d,I")))]
5762 [(set_attr "type" "slt")
5763 (set_attr "mode" "<GPR:MODE>")
5764 (set_attr_alternative "length"
5766 (if_then_else (match_operand 2 "m16_uimm8_1")
5770 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
5771 [(set (match_operand:GPR2 0 "register_operand" "=d")
5772 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5773 (match_operand:GPR 2 "sle_operand" "")))]
5776 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5777 return "slt<u>\t%0,%1,%2";
5779 [(set_attr "type" "slt")
5780 (set_attr "mode" "<GPR:MODE>")])
5782 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
5783 [(set (match_operand:GPR2 0 "register_operand" "=t")
5784 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
5785 (match_operand:GPR 2 "sle_operand" "")))]
5788 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
5789 return "slt<u>\t%1,%2";
5791 [(set_attr "type" "slt")
5792 (set_attr "mode" "<GPR:MODE>")
5793 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
5798 ;; ....................
5800 ;; FLOATING POINT COMPARISONS
5802 ;; ....................
5804 (define_insn "s<code>_<mode>"
5805 [(set (match_operand:CC 0 "register_operand" "=z")
5806 (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5807 (match_operand:SCALARF 2 "register_operand" "f")))]
5809 "c.<fcond>.<fmt>\t%Z0%1,%2"
5810 [(set_attr "type" "fcmp")
5811 (set_attr "mode" "FPSW")])
5813 (define_insn "s<code>_<mode>"
5814 [(set (match_operand:CC 0 "register_operand" "=z")
5815 (swapped_fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
5816 (match_operand:SCALARF 2 "register_operand" "f")))]
5818 "c.<swapped_fcond>.<fmt>\t%Z0%2,%1"
5819 [(set_attr "type" "fcmp")
5820 (set_attr "mode" "FPSW")])
5823 ;; ....................
5825 ;; UNCONDITIONAL BRANCHES
5827 ;; ....................
5829 ;; Unconditional branches.
5831 (define_expand "jump"
5833 (label_ref (match_operand 0)))])
5835 (define_insn "*jump_absolute"
5837 (label_ref (match_operand 0)))]
5838 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
5840 /* Use a branch for microMIPS. The assembler will choose
5841 a 16-bit branch, a 32-bit branch, or a 32-bit jump. */
5842 if (TARGET_MICROMIPS && !TARGET_ABICALLS_PIC2)
5843 return "%*b\t%l0%/";
5845 return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
5847 [(set_attr "type" "jump")])
5849 (define_insn "*jump_pic"
5851 (label_ref (match_operand 0)))]
5852 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
5854 if (get_attr_length (insn) <= 8)
5855 return "%*b\t%l0%/";
5858 mips_output_load_label (operands[0]);
5859 return "%*jr\t%@%/%]";
5862 [(set_attr "type" "branch")])
5864 ;; We need a different insn for the mips16, because a mips16 branch
5865 ;; does not have a delay slot.
5867 (define_insn "*jump_mips16"
5869 (label_ref (match_operand 0 "" "")))]
5872 [(set_attr "type" "branch")
5873 (set (attr "length")
5874 ;; This calculation is like the normal branch one, but the
5875 ;; range of the unextended instruction is [-0x800, 0x7fe] rather
5876 ;; than [-0x100, 0xfe]. This translates to a range of:
5878 ;; [-(0x800 - sizeof (branch)), 0x7fe]
5879 ;; == [-0x7fe, 0x7fe]
5881 ;; from the shorten_branches reference address. Long-branch
5882 ;; sequences will replace this one, so the minimum length
5883 ;; is one instruction shorter than for conditional branches.
5884 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
5885 (le (minus (pc) (match_dup 0)) (const_int 2046)))
5887 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
5888 (le (minus (pc) (match_dup 0)) (const_int 65532)))
5890 (and (match_test "TARGET_ABICALLS")
5891 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
5893 (match_test "Pmode == SImode")
5895 ] (const_int 44)))])
5897 (define_expand "indirect_jump"
5898 [(set (pc) (match_operand 0 "register_operand"))]
5901 operands[0] = force_reg (Pmode, operands[0]);
5902 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
5906 (define_insn "indirect_jump_<mode>"
5907 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
5910 if (TARGET_MICROMIPS)
5911 return "%*jr%:\t%0";
5915 [(set_attr "type" "jump")
5916 (set_attr "mode" "none")])
5918 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
5919 ;; sequences. Having a dedicated pattern is more convenient than
5920 ;; creating a SEQUENCE for this special case.
5921 (define_insn "indirect_jump_and_restore_<mode>"
5922 [(set (pc) (match_operand:P 1 "register_operand" "d"))
5923 (set (match_operand:P 0 "register_operand" "=d")
5924 (match_operand:P 2 "register_operand" "y"))]
5926 "%(%<jr\t%1\;move\t%0,%2%>%)"
5927 [(set_attr "type" "multi")
5928 (set_attr "extended_mips16" "yes")])
5930 (define_expand "tablejump"
5932 (match_operand 0 "register_operand"))
5933 (use (label_ref (match_operand 1 "")))]
5934 "!TARGET_MIPS16_SHORT_JUMP_TABLES"
5937 operands[0] = expand_binop (Pmode, add_optab, operands[0],
5938 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
5939 else if (TARGET_RTP_PIC)
5941 /* When generating RTP PIC, we use case table entries that are relative
5942 to the start of the function. Add the function's address to the
5944 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
5945 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
5946 start, 0, 0, OPTAB_WIDEN);
5949 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
5953 (define_insn "tablejump_<mode>"
5955 (match_operand:P 0 "register_operand" "d"))
5956 (use (label_ref (match_operand 1 "" "")))]
5959 if (TARGET_MICROMIPS)
5960 return "%*jr%:\t%0";
5964 [(set_attr "type" "jump")
5965 (set_attr "mode" "none")])
5967 ;; For MIPS16, we don't know whether a given jump table will use short or
5968 ;; word-sized offsets until late in compilation, when we are able to determine
5969 ;; the sizes of the insns which comprise the containing function. This
5970 ;; necessitates the use of the casesi rather than the tablejump pattern, since
5971 ;; the latter tries to calculate the index of the offset to jump through early
5972 ;; in compilation, i.e. at expand time, when nothing is known about the
5973 ;; eventual function layout.
5975 (define_expand "casesi"
5976 [(match_operand:SI 0 "register_operand" "") ; index to jump on
5977 (match_operand:SI 1 "const_int_operand" "") ; lower bound
5978 (match_operand:SI 2 "const_int_operand" "") ; total range
5979 (match_operand 3 "" "") ; table label
5980 (match_operand 4 "" "")] ; out of range label
5981 "TARGET_MIPS16_SHORT_JUMP_TABLES"
5983 if (operands[1] != const0_rtx)
5985 rtx reg = gen_reg_rtx (SImode);
5986 rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
5988 if (!arith_operand (offset, SImode))
5989 offset = force_reg (SImode, offset);
5991 emit_insn (gen_addsi3 (reg, operands[0], offset));
5995 if (!arith_operand (operands[0], SImode))
5996 operands[0] = force_reg (SImode, operands[0]);
5998 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6000 emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6001 (operands[0], operands[2],
6002 operands[3], operands[4])));
6007 (define_insn "casesi_internal_mips16_<mode>"
6010 (leu (match_operand:SI 0 "register_operand" "d")
6011 (match_operand:SI 1 "arith_operand" "dI"))
6014 (label_ref (match_operand 2 "" ""))]
6015 UNSPEC_CASESI_DISPATCH)
6016 (label_ref (match_operand 3 "" ""))))
6017 (clobber (match_scratch:P 4 "=d"))
6018 (clobber (match_scratch:P 5 "=d"))
6019 (clobber (reg:SI MIPS16_T_REGNUM))]
6020 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6022 rtx diff_vec = PATTERN (next_real_insn (operands[2]));
6024 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6026 output_asm_insn ("sltu\t%0, %1", operands);
6027 output_asm_insn ("bteqz\t%3", operands);
6029 switch (GET_MODE (diff_vec))
6032 output_asm_insn ("sll\t%5, %0, 1", operands);
6033 output_asm_insn ("la\t%4, %2", operands);
6034 output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6035 output_asm_insn ("lh\t%5, 0(%5)", operands);
6039 output_asm_insn ("sll\t%5, %0, 2", operands);
6040 output_asm_insn ("la\t%4, %2", operands);
6041 output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6042 output_asm_insn ("lw\t%5, 0(%5)", operands);
6049 output_asm_insn ("addu\t%4, %4, %5", operands);
6053 [(set_attr "length" "32")])
6055 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6056 ;; While it is possible to either pull it off the stack (in the
6057 ;; o32 case) or recalculate it given t9 and our target label,
6058 ;; it takes 3 or 4 insns to do so.
6060 (define_expand "builtin_setjmp_setup"
6061 [(use (match_operand 0 "register_operand"))]
6066 addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6067 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6071 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
6072 ;; that older code did recalculate the gp from $25. Continue to jump through
6073 ;; $25 for compatibility (we lose nothing by doing so).
6075 (define_expand "builtin_longjmp"
6076 [(use (match_operand 0 "register_operand"))]
6079 /* The elements of the buffer are, in order: */
6080 int W = GET_MODE_SIZE (Pmode);
6081 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6082 rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6083 rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6084 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6085 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6086 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6087 The target is bound to be using $28 as the global pointer
6088 but the current function might not be. */
6089 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6091 /* This bit is similar to expand_builtin_longjmp except that it
6092 restores $gp as well. */
6093 mips_emit_move (hard_frame_pointer_rtx, fp);
6094 mips_emit_move (pv, lab);
6095 emit_stack_restore (SAVE_NONLOCAL, stack);
6096 mips_emit_move (gp, gpv);
6097 emit_use (hard_frame_pointer_rtx);
6098 emit_use (stack_pointer_rtx);
6100 emit_indirect_jump (pv);
6105 ;; ....................
6107 ;; Function prologue/epilogue
6109 ;; ....................
6112 (define_expand "prologue"
6116 mips_expand_prologue ();
6120 ;; Block any insns from being moved before this point, since the
6121 ;; profiling call to mcount can use various registers that aren't
6122 ;; saved or used to pass arguments.
6124 (define_insn "blockage"
6125 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6128 [(set_attr "type" "ghost")
6129 (set_attr "mode" "none")])
6131 (define_insn "probe_stack_range_<P:mode>"
6132 [(set (match_operand:P 0 "register_operand" "=d")
6133 (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6134 (match_operand:P 2 "register_operand" "d")]
6135 UNSPEC_PROBE_STACK_RANGE))]
6137 { return mips_output_probe_stack_range (operands[0], operands[2]); }
6138 [(set_attr "type" "unknown")
6139 (set_attr "can_delay" "no")
6140 (set_attr "mode" "<MODE>")])
6142 (define_expand "epilogue"
6146 mips_expand_epilogue (false);
6150 (define_expand "sibcall_epilogue"
6154 mips_expand_epilogue (true);
6158 ;; Trivial return. Make it look like a normal return insn as that
6159 ;; allows jump optimizations to work better.
6161 (define_expand "return"
6163 "mips_can_use_return_insn ()"
6164 { mips_expand_before_return (); })
6166 (define_expand "simple_return"
6169 { mips_expand_before_return (); })
6171 (define_insn "*<optab>"
6175 [(set_attr "type" "jump")
6176 (set_attr "mode" "none")])
6180 (define_insn "<optab>_internal"
6182 (use (match_operand 0 "pmode_register_operand" ""))]
6185 if (TARGET_MICROMIPS)
6186 return "%*jr%:\t%0";
6190 [(set_attr "type" "jump")
6191 (set_attr "mode" "none")])
6193 ;; Exception return.
6194 (define_insn "mips_eret"
6196 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6199 [(set_attr "type" "trap")
6200 (set_attr "mode" "none")])
6202 ;; Debug exception return.
6203 (define_insn "mips_deret"
6205 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6208 [(set_attr "type" "trap")
6209 (set_attr "mode" "none")])
6211 ;; Disable interrupts.
6212 (define_insn "mips_di"
6213 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6216 [(set_attr "type" "trap")
6217 (set_attr "mode" "none")])
6219 ;; Execution hazard barrier.
6220 (define_insn "mips_ehb"
6221 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6224 [(set_attr "type" "trap")
6225 (set_attr "mode" "none")])
6227 ;; Read GPR from previous shadow register set.
6228 (define_insn "mips_rdpgpr"
6229 [(set (match_operand:SI 0 "register_operand" "=d")
6230 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d")]
6234 [(set_attr "type" "move")
6235 (set_attr "mode" "SI")])
6237 ;; Move involving COP0 registers.
6238 (define_insn "cop0_move"
6239 [(set (match_operand:SI 0 "register_operand" "=B,d")
6240 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6243 { return mips_output_move (operands[0], operands[1]); }
6244 [(set_attr "type" "mtc,mfc")
6245 (set_attr "mode" "SI")])
6247 ;; This is used in compiling the unwind routines.
6248 (define_expand "eh_return"
6249 [(use (match_operand 0 "general_operand"))]
6252 if (GET_MODE (operands[0]) != word_mode)
6253 operands[0] = convert_to_mode (word_mode, operands[0], 0);
6255 emit_insn (gen_eh_set_lr_di (operands[0]));
6257 emit_insn (gen_eh_set_lr_si (operands[0]));
6261 ;; Clobber the return address on the stack. We can't expand this
6262 ;; until we know where it will be put in the stack frame.
6264 (define_insn "eh_set_lr_si"
6265 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6266 (clobber (match_scratch:SI 1 "=&d"))]
6270 (define_insn "eh_set_lr_di"
6271 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6272 (clobber (match_scratch:DI 1 "=&d"))]
6277 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6278 (clobber (match_scratch 1))]
6282 mips_set_return_address (operands[0], operands[1]);
6286 (define_expand "exception_receiver"
6290 /* See the comment above load_call<mode> for details. */
6291 emit_insn (gen_set_got_version ());
6293 /* If we have a call-clobbered $gp, restore it from its save slot. */
6294 if (HAVE_restore_gp_si)
6295 emit_insn (gen_restore_gp_si ());
6296 else if (HAVE_restore_gp_di)
6297 emit_insn (gen_restore_gp_di ());
6301 (define_expand "nonlocal_goto_receiver"
6305 /* See the comment above load_call<mode> for details. */
6306 emit_insn (gen_set_got_version ());
6310 ;; Restore $gp from its .cprestore stack slot. The instruction remains
6311 ;; volatile until all uses of $28 are exposed.
6312 (define_insn_and_split "restore_gp_<mode>"
6314 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6315 (clobber (match_scratch:P 0 "=&d"))]
6316 "TARGET_CALL_CLOBBERED_GP"
6318 "&& epilogue_completed"
6321 mips_restore_gp_from_cprestore_slot (operands[0]);
6324 [(set_attr "type" "ghost")])
6326 ;; Move between $gp and its register save slot.
6327 (define_insn_and_split "move_gp<mode>"
6328 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6329 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6332 { return mips_must_initialize_gp_p () ? "#" : ""; }
6333 "mips_must_initialize_gp_p ()"
6336 mips_emit_move (operands[0], operands[1]);
6339 [(set_attr "type" "ghost")])
6342 ;; ....................
6346 ;; ....................
6348 ;; Instructions to load a call address from the GOT. The address might
6349 ;; point to a function or to a lazy binding stub. In the latter case,
6350 ;; the stub will use the dynamic linker to resolve the function, which
6351 ;; in turn will change the GOT entry to point to the function's real
6354 ;; This means that every call, even pure and constant ones, can
6355 ;; potentially modify the GOT entry. And once a stub has been called,
6356 ;; we must not call it again.
6358 ;; We represent this restriction using an imaginary, fixed, call-saved
6359 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6360 ;; live throughout the function and to change its value after every
6361 ;; potential call site. This stops any rtx value that uses the register
6362 ;; from being computed before an earlier call. To do this, we:
6364 ;; - Ensure that the register is live on entry to the function,
6365 ;; so that it is never thought to be used uninitalized.
6367 ;; - Ensure that the register is live on exit from the function,
6368 ;; so that it is live throughout.
6370 ;; - Make each call (lazily-bound or not) use the current value
6371 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6372 ;; not moved across call boundaries.
6374 ;; - Add "ghost" definitions of the register to the beginning of
6375 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6376 ;; edges may involve calls that normal paths don't. (E.g. the
6377 ;; unwinding code that handles a non-call exception may change
6378 ;; lazily-bound GOT entries.) We do this by making the
6379 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6380 ;; a set_got_version instruction.
6382 ;; - After each call (lazily-bound or not), use a "ghost"
6383 ;; update_got_version instruction to change the register's value.
6384 ;; This instruction mimics the _possible_ effect of the dynamic
6385 ;; resolver during the call and it remains live even if the call
6386 ;; itself becomes dead.
6388 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6389 ;; The register is therefore not a valid register_operand
6390 ;; and cannot be moved to or from other registers.
6392 (define_insn "load_call<mode>"
6393 [(set (match_operand:P 0 "register_operand" "=d")
6394 (unspec:P [(match_operand:P 1 "register_operand" "d")
6395 (match_operand:P 2 "immediate_operand" "")
6396 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6398 "<load>\t%0,%R2(%1)"
6399 [(set_attr "got" "load")
6400 (set_attr "mode" "<MODE>")])
6402 (define_insn "set_got_version"
6403 [(set (reg:SI GOT_VERSION_REGNUM)
6404 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6407 [(set_attr "type" "ghost")])
6409 (define_insn "update_got_version"
6410 [(set (reg:SI GOT_VERSION_REGNUM)
6411 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6414 [(set_attr "type" "ghost")])
6416 ;; Sibling calls. All these patterns use jump instructions.
6418 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6419 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6420 ;; is defined in terms of call_insn_operand, the same is true of the
6423 ;; When we use an indirect jump, we need a register that will be
6424 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6425 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6426 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6429 (define_expand "sibcall"
6430 [(parallel [(call (match_operand 0 "")
6431 (match_operand 1 ""))
6432 (use (match_operand 2 "")) ;; next_arg_reg
6433 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6436 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6437 operands[1], operands[2], false);
6441 (define_insn "sibcall_internal"
6442 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6443 (match_operand 1 "" ""))]
6444 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6446 if (TARGET_MICROMIPS)
6447 return MICROMIPS_J ("j", operands, 0);
6449 return MIPS_CALL ("j", operands, 0, 1);
6451 [(set_attr "jal" "indirect,direct")
6452 (set_attr "jal_macro" "no")])
6454 (define_expand "sibcall_value"
6455 [(parallel [(set (match_operand 0 "")
6456 (call (match_operand 1 "")
6457 (match_operand 2 "")))
6458 (use (match_operand 3 ""))])] ;; next_arg_reg
6461 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6462 operands[2], operands[3], false);
6466 (define_insn "sibcall_value_internal"
6467 [(set (match_operand 0 "register_operand" "")
6468 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6469 (match_operand 2 "" "")))]
6470 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6472 if (TARGET_MICROMIPS)
6473 return MICROMIPS_J ("j", operands, 1);
6475 return MIPS_CALL ("j", operands, 1, 2);
6477 [(set_attr "jal" "indirect,direct")
6478 (set_attr "jal_macro" "no")])
6480 (define_insn "sibcall_value_multiple_internal"
6481 [(set (match_operand 0 "register_operand" "")
6482 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6483 (match_operand 2 "" "")))
6484 (set (match_operand 3 "register_operand" "")
6485 (call (mem:SI (match_dup 1))
6487 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6489 if (TARGET_MICROMIPS)
6490 return MICROMIPS_J ("j", operands, 1);
6492 return MIPS_CALL ("j", operands, 1, 2);
6494 [(set_attr "jal" "indirect,direct")
6495 (set_attr "jal_macro" "no")])
6497 (define_expand "call"
6498 [(parallel [(call (match_operand 0 "")
6499 (match_operand 1 ""))
6500 (use (match_operand 2 "")) ;; next_arg_reg
6501 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6504 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6505 operands[1], operands[2], false);
6509 ;; This instruction directly corresponds to an assembly-language "jal".
6510 ;; There are four cases:
6513 ;; Both symbolic and register destinations are OK. The pattern
6514 ;; always expands to a single mips instruction.
6516 ;; - -mabicalls/-mno-explicit-relocs:
6517 ;; Again, both symbolic and register destinations are OK.
6518 ;; The call is treated as a multi-instruction black box.
6520 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6521 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
6524 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
6525 ;; Only "jal $25" is allowed. The call is actually two instructions:
6526 ;; "jalr $25" followed by an insn to reload $gp.
6528 ;; In the last case, we can generate the individual instructions with
6529 ;; a define_split. There are several things to be wary of:
6531 ;; - We can't expose the load of $gp before reload. If we did,
6532 ;; it might get removed as dead, but reload can introduce new
6533 ;; uses of $gp by rematerializing constants.
6535 ;; - We shouldn't restore $gp after calls that never return.
6536 ;; It isn't valid to insert instructions between a noreturn
6537 ;; call and the following barrier.
6539 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
6540 ;; instruction preserves $gp and so have no effect on its liveness.
6541 ;; But once we generate the separate insns, it becomes obvious that
6542 ;; $gp is not live on entry to the call.
6544 (define_insn_and_split "call_internal"
6545 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6546 (match_operand 1 "" ""))
6547 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6549 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, 1); }
6550 "reload_completed && TARGET_SPLIT_CALLS"
6553 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6556 [(set_attr "jal" "indirect,direct")])
6558 (define_insn "call_split"
6559 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6560 (match_operand 1 "" ""))
6561 (clobber (reg:SI RETURN_ADDR_REGNUM))
6562 (clobber (reg:SI 28))]
6563 "TARGET_SPLIT_CALLS"
6564 { return MIPS_CALL ("jal", operands, 0, 1); }
6565 [(set_attr "jal" "indirect,direct")
6566 (set_attr "jal_macro" "no")])
6568 ;; A pattern for calls that must be made directly. It is used for
6569 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6570 ;; stub; the linker relies on the call relocation type to detect when
6571 ;; such redirection is needed.
6572 (define_insn_and_split "call_internal_direct"
6573 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6576 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6578 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 0, -1); }
6579 "reload_completed && TARGET_SPLIT_CALLS"
6582 mips_split_call (curr_insn,
6583 gen_call_direct_split (operands[0], operands[1]));
6586 [(set_attr "jal" "direct")])
6588 (define_insn "call_direct_split"
6589 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6592 (clobber (reg:SI RETURN_ADDR_REGNUM))
6593 (clobber (reg:SI 28))]
6594 "TARGET_SPLIT_CALLS"
6595 { return MIPS_CALL ("jal", operands, 0, -1); }
6596 [(set_attr "jal" "direct")
6597 (set_attr "jal_macro" "no")])
6599 (define_expand "call_value"
6600 [(parallel [(set (match_operand 0 "")
6601 (call (match_operand 1 "")
6602 (match_operand 2 "")))
6603 (use (match_operand 3 ""))])] ;; next_arg_reg
6606 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6607 operands[2], operands[3], false);
6611 ;; See comment for call_internal.
6612 (define_insn_and_split "call_value_internal"
6613 [(set (match_operand 0 "register_operand" "")
6614 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6615 (match_operand 2 "" "")))
6616 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6618 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6619 "reload_completed && TARGET_SPLIT_CALLS"
6622 mips_split_call (curr_insn,
6623 gen_call_value_split (operands[0], operands[1],
6627 [(set_attr "jal" "indirect,direct")])
6629 (define_insn "call_value_split"
6630 [(set (match_operand 0 "register_operand" "")
6631 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6632 (match_operand 2 "" "")))
6633 (clobber (reg:SI RETURN_ADDR_REGNUM))
6634 (clobber (reg:SI 28))]
6635 "TARGET_SPLIT_CALLS"
6636 { return MIPS_CALL ("jal", operands, 1, 2); }
6637 [(set_attr "jal" "indirect,direct")
6638 (set_attr "jal_macro" "no")])
6640 ;; See call_internal_direct.
6641 (define_insn_and_split "call_value_internal_direct"
6642 [(set (match_operand 0 "register_operand")
6643 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6646 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6648 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, -1); }
6649 "reload_completed && TARGET_SPLIT_CALLS"
6652 mips_split_call (curr_insn,
6653 gen_call_value_direct_split (operands[0], operands[1],
6657 [(set_attr "jal" "direct")])
6659 (define_insn "call_value_direct_split"
6660 [(set (match_operand 0 "register_operand")
6661 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
6664 (clobber (reg:SI RETURN_ADDR_REGNUM))
6665 (clobber (reg:SI 28))]
6666 "TARGET_SPLIT_CALLS"
6667 { return MIPS_CALL ("jal", operands, 1, -1); }
6668 [(set_attr "jal" "direct")
6669 (set_attr "jal_macro" "no")])
6671 ;; See comment for call_internal.
6672 (define_insn_and_split "call_value_multiple_internal"
6673 [(set (match_operand 0 "register_operand" "")
6674 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6675 (match_operand 2 "" "")))
6676 (set (match_operand 3 "register_operand" "")
6677 (call (mem:SI (match_dup 1))
6679 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6681 { return TARGET_SPLIT_CALLS ? "#" : MIPS_CALL ("jal", operands, 1, 2); }
6682 "reload_completed && TARGET_SPLIT_CALLS"
6685 mips_split_call (curr_insn,
6686 gen_call_value_multiple_split (operands[0], operands[1],
6687 operands[2], operands[3]));
6690 [(set_attr "jal" "indirect,direct")])
6692 (define_insn "call_value_multiple_split"
6693 [(set (match_operand 0 "register_operand" "")
6694 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
6695 (match_operand 2 "" "")))
6696 (set (match_operand 3 "register_operand" "")
6697 (call (mem:SI (match_dup 1))
6699 (clobber (reg:SI RETURN_ADDR_REGNUM))
6700 (clobber (reg:SI 28))]
6701 "TARGET_SPLIT_CALLS"
6702 { return MIPS_CALL ("jal", operands, 1, 2); }
6703 [(set_attr "jal" "indirect,direct")
6704 (set_attr "jal_macro" "no")])
6706 ;; Call subroutine returning any type.
6708 (define_expand "untyped_call"
6709 [(parallel [(call (match_operand 0 "")
6711 (match_operand 1 "")
6712 (match_operand 2 "")])]
6717 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
6719 for (i = 0; i < XVECLEN (operands[2], 0); i++)
6721 rtx set = XVECEXP (operands[2], 0, i);
6722 mips_emit_move (SET_DEST (set), SET_SRC (set));
6725 emit_insn (gen_blockage ());
6730 ;; ....................
6734 ;; ....................
6738 (define_insn "prefetch"
6739 [(prefetch (match_operand:QI 0 "address_operand" "ZD")
6740 (match_operand 1 "const_int_operand" "n")
6741 (match_operand 2 "const_int_operand" "n"))]
6742 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
6744 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
6745 /* Loongson 2[ef] and Loongson 3a use load to $0 to perform prefetching. */
6746 return "ld\t$0,%a0";
6747 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
6748 return "pref\t%1,%a0";
6750 [(set_attr "type" "prefetch")])
6752 (define_insn "*prefetch_indexed_<mode>"
6753 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
6754 (match_operand:P 1 "register_operand" "d"))
6755 (match_operand 2 "const_int_operand" "n")
6756 (match_operand 3 "const_int_operand" "n"))]
6757 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
6759 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
6760 return "prefx\t%2,%1(%0)";
6762 [(set_attr "type" "prefetchx")])
6768 [(set_attr "type" "nop")
6769 (set_attr "mode" "none")])
6771 ;; Like nop, but commented out when outside a .set noreorder block.
6772 (define_insn "hazard_nop"
6776 if (mips_noreorder.nesting_level > 0)
6781 [(set_attr "type" "nop")])
6783 ;; MIPS4 Conditional move instructions.
6785 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
6786 [(set (match_operand:GPR 0 "register_operand" "=d,d")
6788 (match_operator:MOVECC 4 "equality_operator"
6789 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6791 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
6792 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
6797 [(set_attr "type" "condmove")
6798 (set_attr "mode" "<GPR:MODE>")])
6800 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
6801 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
6802 (if_then_else:SCALARF
6803 (match_operator:MOVECC 4 "equality_operator"
6804 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
6806 (match_operand:SCALARF 2 "register_operand" "f,0")
6807 (match_operand:SCALARF 3 "register_operand" "0,f")))]
6808 "ISA_HAS_FP_CONDMOVE"
6810 mov%T4.<fmt>\t%0,%2,%1
6811 mov%t4.<fmt>\t%0,%3,%1"
6812 [(set_attr "type" "condmove")
6813 (set_attr "mode" "<SCALARF:MODE>")])
6815 ;; These are the main define_expand's used to make conditional moves.
6817 (define_expand "mov<mode>cc"
6818 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6819 (set (match_operand:GPR 0 "register_operand")
6820 (if_then_else:GPR (match_dup 5)
6821 (match_operand:GPR 2 "reg_or_0_operand")
6822 (match_operand:GPR 3 "reg_or_0_operand")))]
6825 mips_expand_conditional_move (operands);
6829 (define_expand "mov<mode>cc"
6830 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
6831 (set (match_operand:SCALARF 0 "register_operand")
6832 (if_then_else:SCALARF (match_dup 5)
6833 (match_operand:SCALARF 2 "register_operand")
6834 (match_operand:SCALARF 3 "register_operand")))]
6835 "ISA_HAS_FP_CONDMOVE"
6837 mips_expand_conditional_move (operands);
6842 ;; ....................
6844 ;; mips16 inline constant tables
6846 ;; ....................
6849 (define_insn "consttable_tls_reloc"
6850 [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
6851 (match_operand 1 "const_int_operand" "")]
6852 UNSPEC_CONSTTABLE_INT)]
6853 "TARGET_MIPS16_PCREL_LOADS"
6854 { return mips_output_tls_reloc_directive (&operands[0]); }
6855 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6857 (define_insn "consttable_int"
6858 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
6859 (match_operand 1 "const_int_operand" "")]
6860 UNSPEC_CONSTTABLE_INT)]
6863 assemble_integer (mips_strip_unspec_address (operands[0]),
6864 INTVAL (operands[1]),
6865 BITS_PER_UNIT * INTVAL (operands[1]), 1);
6868 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
6870 (define_insn "consttable_float"
6871 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
6872 UNSPEC_CONSTTABLE_FLOAT)]
6877 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
6878 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
6879 assemble_real (d, GET_MODE (operands[0]),
6880 GET_MODE_BITSIZE (GET_MODE (operands[0])));
6883 [(set (attr "length")
6884 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
6886 (define_insn "align"
6887 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
6890 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
6893 [(match_operand 0 "small_data_pattern")]
6896 { operands[0] = mips_rewrite_small_data (operands[0]); })
6899 ;; ....................
6901 ;; MIPS16e Save/Restore
6903 ;; ....................
6906 (define_insn "*mips16e_save_restore"
6907 [(match_parallel 0 ""
6908 [(set (match_operand:SI 1 "register_operand")
6909 (plus:SI (match_dup 1)
6910 (match_operand:SI 2 "const_int_operand")))])]
6911 "operands[1] == stack_pointer_rtx
6912 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
6913 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
6914 [(set_attr "type" "arith")
6915 (set_attr "extended_mips16" "yes")])
6917 ;; Thread-Local Storage
6919 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
6920 ;; MIPS architecture defines this register, and no current
6921 ;; implementation provides it; instead, any OS which supports TLS is
6922 ;; expected to trap and emulate this instruction. rdhwr is part of the
6923 ;; MIPS 32r2 specification, but we use it on any architecture because
6924 ;; we expect it to be emulated. Use .set to force the assembler to
6927 ;; We do not use a constraint to force the destination to be $3
6928 ;; because $3 can appear explicitly as a function return value.
6929 ;; If we leave the use of $3 implicit in the constraints until
6930 ;; reload, we may end up making a $3 return value live across
6931 ;; the instruction, leading to a spill failure when reloading it.
6932 (define_insn_and_split "tls_get_tp_<mode>"
6933 [(set (match_operand:P 0 "register_operand" "=d")
6934 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6935 (clobber (reg:P TLS_GET_TP_REGNUM))]
6936 "HAVE_AS_TLS && !TARGET_MIPS16"
6938 "&& reload_completed"
6939 [(set (reg:P TLS_GET_TP_REGNUM)
6940 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
6941 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6943 [(set_attr "type" "unknown")
6944 ; Since rdhwr always generates a trap for now, putting it in a delay
6945 ; slot would make the kernel's emulation of it much slower.
6946 (set_attr "can_delay" "no")
6947 (set_attr "mode" "<MODE>")
6948 (set_attr "length" "8")])
6950 (define_insn "*tls_get_tp_<mode>_split"
6951 [(set (reg:P TLS_GET_TP_REGNUM)
6952 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
6953 "HAVE_AS_TLS && !TARGET_MIPS16"
6954 ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop"
6955 [(set_attr "type" "unknown")
6956 ; See tls_get_tp_<mode>
6957 (set_attr "can_delay" "no")
6958 (set_attr "mode" "<MODE>")])
6960 ;; In MIPS16 mode, the TLS base pointer is accessed by a
6961 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
6962 ;; accessible in MIPS16.
6964 ;; This is not represented as a call insn, to avoid the
6965 ;; unnecesarry clobbering of caller-save registers by a
6966 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
6968 ;; A $25 clobber is added to cater for a $25 load stub added by the
6969 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
6971 (define_insn_and_split "tls_get_tp_mips16_<mode>"
6972 [(set (match_operand:P 0 "register_operand" "=d")
6973 (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
6975 (clobber (reg:P TLS_GET_TP_REGNUM))
6976 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6977 (clobber (reg:P RETURN_ADDR_REGNUM))]
6978 "HAVE_AS_TLS && TARGET_MIPS16"
6980 "&& reload_completed"
6981 [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
6982 (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
6983 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6984 (clobber (reg:P RETURN_ADDR_REGNUM))])
6985 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
6987 [(set_attr "type" "multi")
6988 (set_attr "length" "16")
6989 (set_attr "mode" "<MODE>")])
6991 (define_insn "*tls_get_tp_mips16_call_<mode>"
6992 [(set (reg:P TLS_GET_TP_REGNUM)
6993 (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
6995 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
6996 (clobber (reg:P RETURN_ADDR_REGNUM))]
6997 "HAVE_AS_TLS && TARGET_MIPS16"
6998 { return MIPS_CALL ("jal", operands, 0, -1); }
6999 [(set_attr "type" "call")
7000 (set_attr "length" "12")
7001 (set_attr "mode" "<MODE>")])
7003 ;; Named pattern for expanding thread pointer reference.
7004 (define_expand "get_thread_pointer<mode>"
7005 [(match_operand:P 0 "register_operand" "=d")]
7008 mips_expand_thread_pointer (operands[0]);
7013 ;; Synchronization instructions.
7017 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7019 (include "mips-ps-3d.md")
7021 ; The MIPS DSP Instructions.
7023 (include "mips-dsp.md")
7025 ; The MIPS DSP REV 2 Instructions.
7027 (include "mips-dspr2.md")
7029 ; MIPS fixed-point instructions.
7030 (include "mips-fixed.md")
7032 ; microMIPS patterns.
7033 (include "micromips.md")
7035 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7036 (include "loongson.md")
7038 (define_c_enum "unspec" [
7039 UNSPEC_ADDRESS_FIRST