1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989-2022 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" [
77 (define_c_enum "unspec" [
78 ;; Unaligned accesses.
84 ;; Integer operations that are too cumbersome to describe directly.
89 ;; Floating-point moves.
96 ;; Floating-point environment.
109 UNSPEC_POTENTIAL_CPRESTORE
114 UNSPEC_SET_GOT_VERSION
115 UNSPEC_UPDATE_GOT_VERSION
117 ;; Symbolic accesses.
122 UNSPEC_UNSHIFTED_HIGH
124 ;; MIPS16 constant pools.
127 UNSPEC_CONSTTABLE_END
128 UNSPEC_CONSTTABLE_INT
129 UNSPEC_CONSTTABLE_FLOAT
131 ;; Blockage and synchronisation.
138 ;; Cache manipulation.
140 UNSPEC_R10K_CACHE_BARRIER
142 ;; Interrupt handling.
150 ;; Used in a call expression in place of args_size. It's present for PIC
151 ;; indirect calls where it contains args_size and the function symbol.
154 ;; MIPS16 casesi jump table dispatch.
155 UNSPEC_CASESI_DISPATCH
158 UNSPEC_PROBE_STACK_RANGE
160 ;; The `.insn' pseudo-op.
165 [(TLS_GET_TP_REGNUM 3)
168 (PIC_FUNCTION_ADDR_REGNUM 25)
169 (RETURN_ADDR_REGNUM 31)
170 (CPRESTORE_SLOT_REGNUM 76)
171 (GOT_VERSION_REGNUM 79)
173 ;; PIC long branch sequences are never longer than 100 bytes.
174 (MAX_PIC_BRANCH_LENGTH 100)
178 (include "predicates.md")
179 (include "constraints.md")
181 ;; ....................
185 ;; ....................
187 (define_attr "got" "unset,xgot_high,load"
188 (const_string "unset"))
190 ;; For jal instructions, this attribute is DIRECT when the target address
191 ;; is symbolic and INDIRECT when it is a register.
192 (define_attr "jal" "unset,direct,indirect"
193 (const_string "unset"))
195 ;; This attribute is YES if the instruction is a jal macro (not a
196 ;; real jal instruction).
198 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
199 ;; an instruction to restore $gp. Direct jals are also macros for
200 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
202 (define_attr "jal_macro" "no,yes"
203 (cond [(eq_attr "jal" "direct")
204 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
205 ? JAL_MACRO_YES : JAL_MACRO_NO)")
206 (eq_attr "jal" "indirect")
207 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
208 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
209 (const_string "no")))
211 ;; Classification of moves, extensions and truncations. Most values
212 ;; are as for "type" (see below) but there are also the following
213 ;; move-specific values:
215 ;; constN move an N-constraint integer into a MIPS16 register
216 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
217 ;; to produce a sign-extended DEST, even if SRC is not
218 ;; properly sign-extended
219 ;; ext_ins EXT, DEXT, INS or DINS instruction
220 ;; andi a single ANDI instruction
221 ;; loadpool move a constant into a MIPS16 register by loading it
223 ;; shift_shift a shift left followed by a shift right
225 ;; This attribute is used to determine the instruction's length and
226 ;; scheduling type. For doubleword moves, the attribute always describes
227 ;; the split instructions; in some cases, it is more appropriate for the
228 ;; scheduling type to be "multi" instead.
229 (define_attr "move_type"
230 "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
231 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
233 (const_string "unknown"))
235 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor,simd_add"
236 (const_string "unknown"))
238 ;; Main data type used by the insn
239 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW,
240 V2DI,V4SI,V8HI,V16QI,V2DF,V4SF"
241 (const_string "unknown"))
243 ;; True if the main data type is twice the size of a word.
244 (define_attr "dword_mode" "no,yes"
245 (cond [(and (eq_attr "mode" "DI,DF")
246 (not (match_test "TARGET_64BIT")))
249 (and (eq_attr "mode" "TI,TF")
250 (match_test "TARGET_64BIT"))
251 (const_string "yes")]
252 (const_string "no")))
254 ;; True if the main data type is four times of the size of a word.
255 (define_attr "qword_mode" "no,yes"
256 (cond [(and (eq_attr "mode" "TI,TF")
257 (not (match_test "TARGET_64BIT")))
258 (const_string "yes")]
259 (const_string "no")))
261 ;; Attributes describing a sync loop. These loops have the form:
263 ;; if (RELEASE_BARRIER == YES) sync
265 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
266 ;; CMP = 0 [delay slot]
267 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
268 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
269 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
270 ;; $AT |= $TMP1 | $TMP3
271 ;; if (!commit (*MEM = $AT)) goto 1.
272 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
274 ;; if (ACQUIRE_BARRIER == YES) sync
277 ;; where "$" values are temporaries and where the other values are
278 ;; specified by the attributes below. Values are specified as operand
279 ;; numbers and insns are specified as enums. If no operand number is
280 ;; specified, the following values are used instead:
285 ;; - INCLUSIVE_MASK: -1
286 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
287 ;; - EXCLUSIVE_MASK: 0
289 ;; MEM and INSN1_OP2 are required.
291 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
292 ;; but the gen* programs don't yet support that.
293 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
294 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
295 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
296 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
297 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
298 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
299 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
300 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
301 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
302 (const_string "move"))
303 (define_attr "sync_insn2" "nop,and,xor,not"
304 (const_string "nop"))
305 ;; Memory model specifier.
306 ;; "0"-"9" values specify the operand that stores the memory model value.
307 ;; "10" specifies MEMMODEL_ACQ_REL,
308 ;; "11" specifies MEMMODEL_ACQUIRE.
309 (define_attr "sync_memmodel" "" (const_int 10))
311 ;; Accumulator operand for madd patterns.
312 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
314 ;; Classification of each insn.
315 ;; branch conditional branch
316 ;; jump unconditional jump
317 ;; call unconditional call
318 ;; load load instruction(s)
319 ;; fpload floating point load
320 ;; fpidxload floating point indexed load
321 ;; store store instruction(s)
322 ;; fpstore floating point store
323 ;; fpidxstore floating point indexed store
324 ;; prefetch memory prefetch (register + offset)
325 ;; prefetchx memory indexed prefetch (register + register)
326 ;; condmove conditional moves
327 ;; mtc transfer to coprocessor
328 ;; mfc transfer from coprocessor
329 ;; mthi transfer to a hi register
330 ;; mtlo transfer to a lo register
331 ;; mfhi transfer from a hi register
332 ;; mflo transfer from a lo register
333 ;; const load constant
334 ;; arith integer arithmetic instructions
335 ;; logical integer logical instructions
336 ;; shift integer shift instructions
337 ;; slt set less than instructions
338 ;; signext sign extend instructions
339 ;; clz the clz and clo instructions
340 ;; pop the pop instruction
341 ;; trap trap if instructions
342 ;; imul integer multiply 2 operands
343 ;; imul3 integer multiply 3 operands
344 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
345 ;; imadd integer multiply-add
346 ;; idiv integer divide 2 operands
347 ;; idiv3 integer divide 3 operands
348 ;; move integer register move ({,D}ADD{,U} with rt = 0)
349 ;; fmove floating point register move
350 ;; fadd floating point add/subtract
351 ;; fmul floating point multiply
352 ;; fmadd floating point multiply-add
353 ;; fdiv floating point divide
354 ;; frdiv floating point reciprocal divide
355 ;; frdiv1 floating point reciprocal divide step 1
356 ;; frdiv2 floating point reciprocal divide step 2
357 ;; fabs floating point absolute value
358 ;; fneg floating point negation
359 ;; fcmp floating point compare
360 ;; fcvt floating point convert
361 ;; fsqrt floating point square root
362 ;; frsqrt floating point reciprocal square root
363 ;; frsqrt1 floating point reciprocal square root step1
364 ;; frsqrt2 floating point reciprocal square root step2
365 ;; dspmac DSP MAC instructions not saturating the accumulator
366 ;; dspmacsat DSP MAC instructions that saturate the accumulator
367 ;; accext DSP accumulator extract instructions
368 ;; accmod DSP accumulator modify instructions
369 ;; dspalu DSP ALU instructions not saturating the result
370 ;; dspalusat DSP ALU instructions that saturate the result
371 ;; multi multiword sequence (or user asm statements)
372 ;; atomic atomic memory update instruction
373 ;; syncloop memory atomic operation implemented as a sync loop
375 ;; ghost an instruction that produces no real code
376 ;; multimem microMIPS multiword load and store
378 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
379 prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
380 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
381 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
382 frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
383 multi,atomic,syncloop,nop,ghost,multimem,
384 simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd,
385 simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp,
386 simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill,
387 simd_permute,simd_shf,simd_sat,simd_pcnt,simd_copy,simd_branch,simd_cmsa,
388 simd_fminmax,simd_logic,simd_move,simd_load,simd_store"
389 (cond [(eq_attr "jal" "!unset") (const_string "call")
390 (eq_attr "got" "load") (const_string "load")
392 (eq_attr "alu_type" "add,sub") (const_string "arith")
394 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
396 ;; If a doubleword move uses these expensive instructions,
397 ;; it is usually better to schedule them in the same way
398 ;; as the singleword form, rather than as "multi".
399 (eq_attr "move_type" "load") (const_string "load")
400 (eq_attr "move_type" "fpload") (const_string "fpload")
401 (eq_attr "move_type" "store") (const_string "store")
402 (eq_attr "move_type" "fpstore") (const_string "fpstore")
403 (eq_attr "move_type" "mtc") (const_string "mtc")
404 (eq_attr "move_type" "mfc") (const_string "mfc")
405 (eq_attr "move_type" "mtlo") (const_string "mtlo")
406 (eq_attr "move_type" "mflo") (const_string "mflo")
408 ;; These types of move are always single insns.
409 (eq_attr "move_type" "imul") (const_string "imul")
410 (eq_attr "move_type" "fmove") (const_string "fmove")
411 (eq_attr "move_type" "loadpool") (const_string "load")
412 (eq_attr "move_type" "signext") (const_string "signext")
413 (eq_attr "move_type" "ext_ins") (const_string "arith")
414 (eq_attr "move_type" "arith") (const_string "arith")
415 (eq_attr "move_type" "logical") (const_string "logical")
416 (eq_attr "move_type" "sll0") (const_string "shift")
417 (eq_attr "move_type" "andi") (const_string "logical")
419 ;; These types of move are always split.
420 (eq_attr "move_type" "constN,shift_shift")
421 (const_string "multi")
423 ;; These types of move are split for quadword modes only.
424 (and (eq_attr "move_type" "move,const")
425 (eq_attr "qword_mode" "yes"))
426 (const_string "multi")
428 ;; These types of move are split for doubleword modes only.
429 (and (eq_attr "move_type" "move,const")
430 (eq_attr "dword_mode" "yes"))
431 (const_string "multi")
432 (eq_attr "move_type" "move") (const_string "move")
433 (eq_attr "move_type" "const") (const_string "const")
434 (eq_attr "sync_mem" "!none") (const_string "syncloop")]
435 (const_string "unknown")))
437 (define_attr "compact_form" "always,maybe,never"
438 (cond [(eq_attr "jal" "direct")
439 (const_string "always")
440 (eq_attr "jal" "indirect")
441 (const_string "maybe")
442 (eq_attr "type" "jump")
443 (const_string "maybe")]
444 (const_string "never")))
446 ;; Mode for conversion types (fcvt)
447 ;; I2S integer to float single (SI/DI to SF)
448 ;; I2D integer to float double (SI/DI to DF)
449 ;; S2I float to integer (SF to SI/DI)
450 ;; D2I float to integer (DF to SI/DI)
451 ;; D2S double to float single
452 ;; S2D float single to double
454 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
455 (const_string "unknown"))
457 ;; Is this an extended instruction in mips16 mode?
458 (define_attr "extended_mips16" "no,yes"
459 (if_then_else (ior ;; In general, constant-pool loads are extended
460 ;; instructions. We don't yet optimize for 16-bit
461 ;; PC-relative references.
462 (eq_attr "move_type" "sll0,loadpool")
463 (eq_attr "jal" "direct")
464 (eq_attr "got" "load"))
466 (const_string "no")))
468 (define_attr "compression" "none,all,micromips32,micromips"
469 (const_string "none"))
471 (define_attr "enabled" "no,yes"
472 (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
473 ;; GR_REG and FR_REG for 64-bit values.
474 (and (eq_attr "move_type" "mtc,mfc")
475 (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
476 || TARGET_O32_FP64A_ABI")
477 (eq_attr "dword_mode" "yes"))
479 (and (eq_attr "compression" "micromips32,micromips")
480 (match_test "!TARGET_MICROMIPS"))
482 (const_string "yes")))
484 ;; The number of individual instructions that a non-branch pattern generates,
485 ;; using units of BASE_INSN_LENGTH.
486 (define_attr "insn_count" ""
487 (cond [;; "Ghost" instructions occupy no space.
488 (eq_attr "type" "ghost")
491 ;; Extended instructions count as 2.
492 (and (eq_attr "extended_mips16" "yes")
493 (match_test "TARGET_MIPS16"))
496 ;; A GOT load followed by an add of $gp. This is not used for MIPS16.
497 (eq_attr "got" "xgot_high")
500 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
501 ;; They are extended instructions on MIPS16 targets.
502 (eq_attr "move_type" "shift_shift")
503 (if_then_else (match_test "TARGET_MIPS16")
507 ;; Check for doubleword moves that are decomposed into two
508 ;; instructions. The individual instructions are unextended
510 (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
511 (eq_attr "dword_mode" "yes"))
514 ;; Check for quadword moves that are decomposed into four
516 (and (eq_attr "move_type" "mtc,mfc,move")
517 (eq_attr "qword_mode" "yes"))
520 ;; Constants, loads and stores are handled by external routines.
521 (and (eq_attr "move_type" "const,constN")
522 (eq_attr "dword_mode" "yes"))
523 (symbol_ref "mips_split_const_insns (operands[1])")
524 (eq_attr "move_type" "const,constN")
525 (symbol_ref "mips_const_insns (operands[1])")
526 (eq_attr "move_type" "load,fpload")
527 (symbol_ref "mips_load_store_insns (operands[1], insn)")
528 (eq_attr "move_type" "store,fpstore")
529 (symbol_ref "mips_load_store_insns (operands[0], insn)
530 + (TARGET_FIX_24K ? 1 : 0)")
532 ;; In the worst case, a call macro will take 8 instructions:
534 ;; lui $25,%call_hi(FOO)
536 ;; lw $25,%call_lo(FOO)($25)
542 (eq_attr "jal_macro" "yes")
545 ;; Various VR4120 errata require a nop to be inserted after a macc
546 ;; instruction. The assembler does this for us, so account for
547 ;; the worst-case length here.
548 (and (eq_attr "type" "imadd")
549 (match_test "TARGET_FIX_VR4120"))
552 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
553 ;; the result of the second one is missed. The assembler should work
554 ;; around this by inserting a nop after the first dmult.
555 (and (eq_attr "type" "imul,imul3")
556 (eq_attr "mode" "DI")
557 (match_test "TARGET_FIX_VR4120"))
560 (eq_attr "type" "idiv,idiv3")
561 (symbol_ref "mips_idiv_insns (GET_MODE (PATTERN (insn)))")
563 ;; simd div have 3 instruction if TARGET_CHECK_ZERO_DIV is true.
564 (eq_attr "type" "simd_div")
565 (if_then_else (match_test "TARGET_CHECK_ZERO_DIV")
569 (not (eq_attr "sync_mem" "none"))
570 (symbol_ref "mips_sync_loop_insns (insn, operands)")]
573 ;; Length of instruction in bytes. The default is derived from "insn_count",
574 ;; but there are special cases for branches (which must be handled here)
575 ;; and for compressed single instructions.
576 (define_attr "length" ""
577 (cond [(and (ior (eq_attr "compression" "micromips,all")
578 (and (eq_attr "compression" "micromips32")
579 (eq_attr "mode" "SI,SF")))
580 (eq_attr "dword_mode" "no")
581 (match_test "TARGET_MICROMIPS"))
584 ;; Direct microMIPS branch instructions have a range of
585 ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
586 ;; If a branch is outside this range, we have a choice of two
589 ;; For PIC, an out-of-range branch like:
594 ;; becomes the equivalent of:
603 ;; The non-PIC case is similar except that we use a direct
604 ;; jump instead of an la/jr pair. Since the target of this
605 ;; jump is an absolute 28-bit bit address (the other bits
606 ;; coming from the address of the delay slot) this form cannot
607 ;; cross a 256MB boundary. We could provide the option of
608 ;; using la/jr in this case too, but we do not do so at
611 ;; The value we specify here does not account for the delay slot
612 ;; instruction, whose length is added separately. If the RTL
613 ;; pattern has no explicit delay slot, mips_adjust_insn_length
614 ;; will add the length of the implicit nop. The range of
615 ;; [-0x20000, 0x1fffc] from the address of the delay slot
616 ;; therefore translates to a range of:
618 ;; [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
619 ;; == [-0x1fffc, 0x1fff8]
621 ;; from the shorten_branches reference address.
622 (and (eq_attr "type" "branch")
623 (not (match_test "TARGET_MIPS16")))
624 (cond [;; Any variant can handle the 17-bit range.
625 (and (le (minus (match_dup 0) (pc)) (const_int 65532))
626 (le (minus (pc) (match_dup 0)) (const_int 65534)))
629 ;; The 18-bit range is OK other than for microMIPS.
630 (and (not (match_test "TARGET_MICROMIPS"))
631 (and (le (minus (match_dup 0) (pc)) (const_int 131064))
632 (le (minus (pc) (match_dup 0)) (const_int 131068))))
635 ;; The non-PIC case: branch, first delay slot, and J.
636 (match_test "TARGET_ABSOLUTE_JUMPS")
639 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
640 ;; mips_adjust_insn_length substitutes the correct length.
642 ;; Note that we can't simply use (symbol_ref ...) here
643 ;; because genattrtab needs to know the maximum length
645 (const_int MAX_PIC_BRANCH_LENGTH))
647 ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
648 ;; from the address of the following instruction, which leads
651 ;; [-(0x100 - sizeof (branch)), 0xfe]
654 ;; from the shorten_branches reference address. Extended branches
655 ;; likewise have a range of [-0x10000, 0xfffe] from the address
656 ;; of the following instruction, which leads to a range of:
658 ;; [-(0x10000 - sizeof (branch)), 0xfffe]
659 ;; == [-0xfffc, 0xfffe]
661 ;; from the reference address.
663 ;; When a branch is out of range, mips_reorg splits it into a form
664 ;; that uses in-range branches. There are four basic sequences:
666 ;; (1) Absolute addressing with a readable text segment
667 ;; (32-bit addresses):
670 ;; move $1,$2 2 bytes
671 ;; lw $2,label 2 bytes
673 ;; move $2,$1 2 bytes
674 ;; .align 2 0 or 2 bytes
676 ;; .word target 4 bytes
678 ;; (16 bytes in the worst case)
680 ;; (2) Absolute addressing with a readable text segment
681 ;; (64-bit addresses):
684 ;; move $1,$2 2 bytes
685 ;; ld $2,label 2 bytes
687 ;; move $2,$1 2 bytes
688 ;; .align 3 0 to 6 bytes
690 ;; .dword target 8 bytes
692 ;; (24 bytes in the worst case)
694 ;; (3) Absolute addressing without a readable text segment
695 ;; (which requires 32-bit addresses at present):
698 ;; move $1,$2 2 bytes
699 ;; lui $2,%hi(target) 4 bytes
702 ;; addiu $2,%lo(target) 4 bytes
704 ;; move $2,$1 2 bytes
708 ;; (4) PIC addressing (which requires 32-bit addresses at present):
711 ;; move $1,$2 2 bytes
712 ;; lw $2,cprestore 0, 2 or 4 bytes
713 ;; lw $2,%got(target)($2) 4 bytes
714 ;; addiu $2,%lo(target) 4 bytes
716 ;; move $2,$1 2 bytes
718 ;; (20 bytes in the worst case)
719 (and (eq_attr "type" "branch")
720 (match_test "TARGET_MIPS16"))
721 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
722 (le (minus (pc) (match_dup 0)) (const_int 254)))
724 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
725 (le (minus (pc) (match_dup 0)) (const_int 65532)))
727 (and (match_test "TARGET_ABICALLS")
728 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
730 (match_test "Pmode == SImode")
733 (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
735 ;; Attribute describing the processor.
736 (define_enum_attr "cpu" "processor"
737 (const (symbol_ref "mips_tune")))
739 ;; The type of hardware hazard associated with this instruction.
740 ;; DELAY means that the next instruction cannot read the result
741 ;; of this one. HILO means that the next two instructions cannot
742 ;; write to HI or LO.
743 (define_attr "hazard" "none,delay,hilo,forbidden_slot"
744 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
745 (match_test "ISA_HAS_LOAD_DELAY"))
746 (const_string "delay")
748 (and (eq_attr "type" "mfc,mtc")
749 (match_test "ISA_HAS_XFER_DELAY"))
750 (const_string "delay")
752 (and (eq_attr "type" "fcmp")
753 (match_test "ISA_HAS_FCMP_DELAY"))
754 (const_string "delay")
756 ;; The r4000 multiplication patterns include an mflo instruction.
757 (and (eq_attr "type" "imul")
758 (match_test "TARGET_FIX_R4000"))
759 (const_string "hilo")
761 (and (eq_attr "type" "mfhi,mflo")
762 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
763 (const_string "hilo")]
764 (const_string "none")))
766 ;; Can the instruction be put into a delay slot?
767 (define_attr "can_delay" "no,yes"
768 (if_then_else (and (eq_attr "type" "!branch,call,jump,simd_branch")
769 (eq_attr "hazard" "none")
770 (match_test "get_attr_insn_count (insn) == 1"))
772 (const_string "no")))
774 ;; Attribute defining whether or not we can use the branch-likely
776 (define_attr "branch_likely" "no,yes"
777 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
779 (const_string "no")))
781 ;; True if an instruction might assign to hi or lo when reloaded.
782 ;; This is used by the TUNE_MACC_CHAINS code.
783 (define_attr "may_clobber_hilo" "no,yes"
784 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
786 (const_string "no")))
788 ;; Describe a user's asm statement.
789 (define_asm_attributes
790 [(set_attr "type" "multi")
791 (set_attr "can_delay" "no")])
793 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
794 ;; from the same template.
795 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
797 ;; A copy of GPR that can be used when a pattern has two independent
799 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
801 (define_mode_iterator MOVEP1 [SI SF])
802 (define_mode_iterator MOVEP2 [SI SF])
803 (define_mode_iterator JOIN_MODE [HI
805 (SF "TARGET_HARD_FLOAT")
806 (DF "TARGET_HARD_FLOAT
807 && TARGET_DOUBLE_FLOAT")])
809 ;; This mode iterator allows :HILO to be used as the mode of the
810 ;; concatenated HI and LO registers.
811 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
813 ;; This mode iterator allows :P to be used for patterns that operate on
814 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
815 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
817 ;; This mode iterator allows :MOVECC to be used anywhere that a
818 ;; conditional-move-type condition is needed.
819 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
820 (CC "TARGET_HARD_FLOAT
821 && !TARGET_LOONGSON_2EF
822 && !TARGET_MIPS5900")])
824 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
826 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
827 (CCF "ISA_HAS_CCF")])
829 ;; 32-bit integer moves for which we provide move patterns.
830 (define_mode_iterator IMOVE32
839 (V4UQQ "TARGET_DSP")])
841 ;; 64-bit modes for which we provide move patterns.
842 (define_mode_iterator MOVE64
844 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
845 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")
846 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")
847 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_MMI")])
849 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
850 (define_mode_iterator MOVE128 [TI TF])
852 ;; This mode iterator allows the QI and HI extension patterns to be
853 ;; defined from the same template.
854 (define_mode_iterator SHORT [QI HI])
856 ;; Likewise the 64-bit truncate-and-shift patterns.
857 (define_mode_iterator SUBDI [QI HI SI])
859 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
860 ;; floating-point mode is allowed.
861 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
862 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
863 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
865 ;; Like ANYF, but only applies to scalar modes.
866 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
867 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
869 ;; A floating-point mode for which moves involving FPRs may need to be split.
870 (define_mode_iterator SPLITF
871 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
872 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
873 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
874 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
875 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
876 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_MMI")
877 (TF "TARGET_64BIT && TARGET_FLOAT64")])
879 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
880 ;; 32-bit version and "dsubu" in the 64-bit version.
881 (define_mode_attr d [(SI "") (DI "d")
882 (QQ "") (HQ "") (SQ "") (DQ "d")
883 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
884 (HA "") (SA "") (DA "d")
885 (UHA "") (USA "") (UDA "d")])
887 ;; Same as d but upper-case.
888 (define_mode_attr D [(SI "") (DI "D")
889 (QQ "") (HQ "") (SQ "") (DQ "D")
890 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
891 (HA "") (SA "") (DA "D")
892 (UHA "") (USA "") (UDA "D")])
894 ;; This attribute gives the length suffix for a load or store instruction.
895 ;; The same suffixes work for zero and sign extensions.
896 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
897 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
899 ;; This attributes gives the mode mask of a SHORT.
900 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
902 ;; Mode attributes for GPR loads.
903 (define_mode_attr load [(SI "lw") (DI "ld")])
904 ;; Instruction names for stores.
905 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
907 ;; Similarly for MIPS IV indexed FPR loads and stores.
908 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
909 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
911 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
912 ;; are different. Some forms of unextended addiu have an 8-bit immediate
913 ;; field but the equivalent daddiu has only a 5-bit field.
914 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
916 ;; This attribute gives the best constraint to use for registers of
918 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
920 ;; This attribute gives the format suffix for floating-point operations.
921 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
923 ;; This attribute gives the upper-case mode name for one unit of a
924 ;; floating-point mode or vector mode.
925 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF") (V4SF "SF")
926 (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
929 ;; As above, but in lower case.
930 (define_mode_attr unitmode [(SF "sf") (DF "df") (V2SF "sf") (V4SF "sf")
931 (V16QI "qi") (V8QI "qi") (V8HI "hi") (V4HI "hi")
932 (V4SI "si") (V2SI "si") (V2DI "di") (V2DF "df")])
934 ;; This attribute gives the integer mode that has the same size as a
936 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
937 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
938 (HA "HI") (SA "SI") (DA "DI")
939 (UHA "HI") (USA "SI") (UDA "DI")
940 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
941 (V2HQ "SI") (V2HA "SI")])
943 ;; This attribute gives the integer mode that has half the size of
944 ;; the controlling mode.
945 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
946 (V2SI "SI") (V4HI "SI") (V8QI "SI")
949 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
951 ;; In certain cases, div.s and div.ps may have a rounding error
952 ;; and/or wrong inexact flag.
954 ;; Therefore, we only allow div.s if not working around SB-1 rev2
955 ;; errata or if a slight loss of precision is OK.
956 (define_mode_attr divide_condition
957 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
958 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
960 ;; This attribute gives the conditions under which SQRT.fmt instructions
962 (define_mode_attr sqrt_condition
963 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
965 ;; This attribute provides the correct mnemonic for each FP condition mode.
966 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
968 ;; This code iterator allows signed and unsigned widening multiplications
969 ;; to use the same template.
970 (define_code_iterator any_extend [sign_extend zero_extend])
972 ;; This code iterator allows the two right shift instructions to be
973 ;; generated from the same template.
974 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
976 ;; This code iterator allows the three shift instructions to be generated
977 ;; from the same template.
978 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
980 ;; This code iterator allows unsigned and signed division to be generated
981 ;; from the same template.
982 (define_code_iterator any_div [div udiv])
984 ;; This code iterator allows unsigned and signed modulus to be generated
985 ;; from the same template.
986 (define_code_iterator any_mod [mod umod])
988 ;; This code iterator allows addition and subtraction to be generated
989 ;; from the same template.
990 (define_code_iterator addsub [plus minus])
992 ;; This code iterator allows all native floating-point comparisons to be
993 ;; generated from the same template.
994 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
995 (ordered "ISA_HAS_CCF")
999 ;; This code iterator is used for comparisons that can be implemented
1000 ;; by swapping the operands.
1001 (define_code_iterator swapped_fcond [ge gt unge ungt])
1003 ;; Equality operators.
1004 (define_code_iterator equality_op [eq ne])
1006 ;; These code iterators allow the signed and unsigned scc operations to use
1007 ;; the same template.
1008 (define_code_iterator any_gt [gt gtu])
1009 (define_code_iterator any_ge [ge geu])
1010 (define_code_iterator any_lt [lt ltu])
1011 (define_code_iterator any_le [le leu])
1013 (define_code_iterator any_return [return simple_return])
1015 ;; <u> expands to an empty string when doing a signed operation and
1016 ;; "u" when doing an unsigned operation.
1017 (define_code_attr u [(sign_extend "") (zero_extend "u")
1025 ;; <U> is like <u> except uppercase.
1026 (define_code_attr U [(sign_extend "") (zero_extend "U")])
1028 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
1029 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
1031 ;; <optab> expands to the name of the optab for a particular code.
1032 (define_code_attr optab [(ashift "ashl")
1041 (simple_return "simple_return")])
1043 ;; <insn> expands to the name of the insn that implements a particular code.
1044 (define_code_attr insn [(ashift "sll")
1053 ;; <immediate_insn> expands to the name of the insn that implements
1054 ;; a particular code to operate on immediate values.
1055 (define_code_attr immediate_insn [(ior "ori")
1059 (define_code_attr shift_compression [(ashift "micromips32")
1060 (lshiftrt "micromips32")
1063 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1064 (define_code_attr fcond [(unordered "un")
1075 ;; Similar, but for swapped conditions.
1076 (define_code_attr swapped_fcond [(ge "le")
1081 ;; The value of the bit when the branch is taken for branch_bit patterns.
1082 ;; Comparison is always against zero so this depends on the operator.
1083 (define_code_attr bbv [(eq "0") (ne "1")])
1085 ;; This is the inverse value of bbv.
1086 (define_code_attr bbinv [(eq "1") (ne "0")])
1088 ;; The sel mnemonic to use depending on the condition test.
1089 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1090 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1092 ;; .........................
1094 ;; Branch, call and jump delay slots
1096 ;; .........................
1098 (define_delay (and (eq_attr "type" "branch")
1099 (not (match_test "TARGET_MIPS16"))
1100 (eq_attr "branch_likely" "yes"))
1101 [(eq_attr "can_delay" "yes")
1103 (eq_attr "can_delay" "yes")])
1105 ;; Branches that have delay slots and don't have likely variants do
1106 ;; not annul on false.
1107 (define_delay (and (eq_attr "type" "branch,simd_branch")
1108 (not (match_test "TARGET_MIPS16"))
1109 (ior (match_test "TARGET_CB_NEVER")
1110 (and (eq_attr "compact_form" "maybe")
1111 (not (match_test "TARGET_CB_ALWAYS")))
1112 (eq_attr "compact_form" "never"))
1113 (eq_attr "branch_likely" "no"))
1114 [(eq_attr "can_delay" "yes")
1118 (define_delay (and (eq_attr "type" "jump")
1119 (ior (match_test "TARGET_CB_NEVER")
1120 (and (eq_attr "compact_form" "maybe")
1121 (not (match_test "TARGET_CB_ALWAYS")))
1122 (eq_attr "compact_form" "never")))
1123 [(eq_attr "can_delay" "yes")
1127 ;; Call type instructions should never have a compact form as the
1128 ;; type is only used for MIPS16 patterns. For safety put the compact
1129 ;; branch detection condition in anyway.
1130 (define_delay (and (eq_attr "type" "call")
1131 (eq_attr "jal_macro" "no")
1132 (ior (match_test "TARGET_CB_NEVER")
1133 (and (eq_attr "compact_form" "maybe")
1134 (not (match_test "TARGET_CB_ALWAYS")))
1135 (eq_attr "compact_form" "never")))
1136 [(eq_attr "can_delay" "yes")
1140 ;; Pipeline descriptions.
1142 ;; generic.md provides a fallback for processors without a specific
1143 ;; pipeline description. It is derived from the old define_function_unit
1144 ;; version and uses the "alu" and "imuldiv" units declared below.
1146 ;; Some of the processor-specific files are also derived from old
1147 ;; define_function_unit descriptions and simply override the parts of
1148 ;; generic.md that don't apply. The other processor-specific files
1149 ;; are self-contained.
1150 (define_automaton "alu,imuldiv")
1152 (define_cpu_unit "alu" "alu")
1153 (define_cpu_unit "imuldiv" "imuldiv")
1155 ;; Ghost instructions produce no real code and introduce no hazards.
1156 ;; They exist purely to express an effect on dataflow.
1157 (define_insn_reservation "ghost" 0
1158 (eq_attr "type" "ghost")
1161 (include "i6400.md")
1162 (include "p5600.md")
1163 (include "m5100.md")
1164 (include "p6600.md")
1182 (include "10000.md")
1183 (include "loongson2ef.md")
1184 (include "gs464.md")
1185 (include "gs464e.md")
1186 (include "gs264e.md")
1187 (include "octeon.md")
1189 (include "sr71k.md")
1192 (include "generic.md")
1195 ;; ....................
1197 ;; CONDITIONAL TRAPS
1199 ;; ....................
1203 [(trap_if (const_int 1) (const_int 0))]
1206 if (ISA_HAS_COND_TRAP)
1207 return "teq\t$0,$0";
1208 else if (TARGET_MIPS16)
1213 [(set_attr "type" "trap")])
1215 (define_expand "ctrap<mode>4"
1216 [(trap_if (match_operator 0 "comparison_operator"
1217 [(match_operand:GPR 1 "reg_or_0_operand")
1218 (match_operand:GPR 2 "arith_operand")])
1219 (match_operand 3 "const_0_operand"))]
1220 "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1222 mips_expand_conditional_trap (operands[0]);
1226 (define_insn "*conditional_trap_reg<mode>"
1227 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1228 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1229 (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1231 "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1233 [(set_attr "type" "trap")])
1235 (define_insn "*conditional_trap<mode>"
1236 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1237 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1238 (match_operand:GPR 2 "arith_operand" "dI")])
1240 "ISA_HAS_COND_TRAPI"
1242 [(set_attr "type" "trap")])
1245 ;; ....................
1249 ;; ....................
1252 (define_insn "add<mode>3"
1253 [(set (match_operand:ANYF 0 "register_operand" "=f")
1254 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1255 (match_operand:ANYF 2 "register_operand" "f")))]
1257 "add.<fmt>\t%0,%1,%2"
1258 [(set_attr "type" "fadd")
1259 (set_attr "mode" "<UNITMODE>")])
1261 (define_expand "add<mode>3"
1262 [(set (match_operand:GPR 0 "register_operand")
1263 (plus:GPR (match_operand:GPR 1 "register_operand")
1264 (match_operand:GPR 2 "arith_operand")))]
1267 (define_insn "*add<mode>3"
1268 [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1269 (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1270 (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1273 if (which_alternative == 0
1274 || which_alternative == 1)
1275 return "<d>addu\t%0,%1,%2";
1277 return "<d>addiu\t%0,%1,%2";
1279 [(set_attr "alu_type" "add")
1280 (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1281 (set_attr "mode" "<MODE>")])
1283 (define_insn "*add<mode>3_mips16"
1284 [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1285 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1286 (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1298 [(set_attr "alu_type" "add")
1299 (set_attr "mode" "<MODE>")
1300 (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1302 ;; On the mips16, we can sometimes split an add of a constant which is
1303 ;; a 4 byte instruction into two adds which are both 2 byte
1304 ;; instructions. There are two cases: one where we are adding a
1305 ;; constant plus a register to another register, and one where we are
1306 ;; simply adding a constant to a register.
1309 [(set (match_operand:SI 0 "d_operand")
1310 (plus:SI (match_dup 0)
1311 (match_operand:SI 1 "const_int_operand")))]
1312 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1313 && ((INTVAL (operands[1]) > 0x7f
1314 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1315 || (INTVAL (operands[1]) < - 0x80
1316 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1317 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1318 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1320 HOST_WIDE_INT val = INTVAL (operands[1]);
1324 operands[1] = GEN_INT (0x7f);
1325 operands[2] = GEN_INT (val - 0x7f);
1329 operands[1] = GEN_INT (- 0x80);
1330 operands[2] = GEN_INT (val + 0x80);
1335 [(set (match_operand:SI 0 "d_operand")
1336 (plus:SI (match_operand:SI 1 "d_operand")
1337 (match_operand:SI 2 "const_int_operand")))]
1338 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1339 && REGNO (operands[0]) != REGNO (operands[1])
1340 && ((INTVAL (operands[2]) > 0x7
1341 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1342 || (INTVAL (operands[2]) < - 0x8
1343 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1344 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1345 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1347 HOST_WIDE_INT val = INTVAL (operands[2]);
1351 operands[2] = GEN_INT (0x7);
1352 operands[3] = GEN_INT (val - 0x7);
1356 operands[2] = GEN_INT (- 0x8);
1357 operands[3] = GEN_INT (val + 0x8);
1362 [(set (match_operand:DI 0 "d_operand")
1363 (plus:DI (match_dup 0)
1364 (match_operand:DI 1 "const_int_operand")))]
1365 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1366 && ((INTVAL (operands[1]) > 0xf
1367 && INTVAL (operands[1]) <= 0xf + 0xf)
1368 || (INTVAL (operands[1]) < - 0x10
1369 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1370 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1371 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1373 HOST_WIDE_INT val = INTVAL (operands[1]);
1377 operands[1] = GEN_INT (0xf);
1378 operands[2] = GEN_INT (val - 0xf);
1382 operands[1] = GEN_INT (- 0x10);
1383 operands[2] = GEN_INT (val + 0x10);
1388 [(set (match_operand:DI 0 "d_operand")
1389 (plus:DI (match_operand:DI 1 "d_operand")
1390 (match_operand:DI 2 "const_int_operand")))]
1391 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1392 && REGNO (operands[0]) != REGNO (operands[1])
1393 && ((INTVAL (operands[2]) > 0x7
1394 && INTVAL (operands[2]) <= 0x7 + 0xf)
1395 || (INTVAL (operands[2]) < - 0x8
1396 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1397 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1398 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1400 HOST_WIDE_INT val = INTVAL (operands[2]);
1404 operands[2] = GEN_INT (0x7);
1405 operands[3] = GEN_INT (val - 0x7);
1409 operands[2] = GEN_INT (- 0x8);
1410 operands[3] = GEN_INT (val + 0x8);
1414 (define_insn "*addsi3_extended"
1415 [(set (match_operand:DI 0 "register_operand" "=d,d")
1417 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1418 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1419 "TARGET_64BIT && !TARGET_MIPS16"
1423 [(set_attr "alu_type" "add")
1424 (set_attr "mode" "SI")])
1426 ;; Split this insn so that the addiu splitters can have a crack at it.
1427 ;; Use a conservative length estimate until the split.
1428 (define_insn_and_split "*addsi3_extended_mips16"
1429 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1431 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1432 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1433 "TARGET_64BIT && TARGET_MIPS16"
1435 "&& reload_completed"
1436 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1437 { operands[3] = gen_lowpart (SImode, operands[0]); }
1438 [(set_attr "alu_type" "add")
1439 (set_attr "mode" "SI")
1440 (set_attr "extended_mips16" "yes")])
1442 ;; Combiner patterns for unsigned byte-add.
1444 (define_insn "*baddu_si_eb"
1445 [(set (match_operand:SI 0 "register_operand" "=d")
1448 (plus:SI (match_operand:SI 1 "register_operand" "d")
1449 (match_operand:SI 2 "register_operand" "d")) 3)))]
1450 "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1452 [(set_attr "alu_type" "add")])
1454 (define_insn "*baddu_si_el"
1455 [(set (match_operand:SI 0 "register_operand" "=d")
1458 (plus:SI (match_operand:SI 1 "register_operand" "d")
1459 (match_operand:SI 2 "register_operand" "d")) 0)))]
1460 "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1462 [(set_attr "alu_type" "add")])
1464 (define_insn "*baddu_di<mode>"
1465 [(set (match_operand:GPR 0 "register_operand" "=d")
1468 (plus:DI (match_operand:DI 1 "register_operand" "d")
1469 (match_operand:DI 2 "register_operand" "d")))))]
1470 "ISA_HAS_BADDU && TARGET_64BIT"
1472 [(set_attr "alu_type" "add")])
1475 ;; ....................
1479 ;; ....................
1482 (define_insn "sub<mode>3"
1483 [(set (match_operand:ANYF 0 "register_operand" "=f")
1484 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1485 (match_operand:ANYF 2 "register_operand" "f")))]
1487 "sub.<fmt>\t%0,%1,%2"
1488 [(set_attr "type" "fadd")
1489 (set_attr "mode" "<UNITMODE>")])
1491 (define_insn "sub<mode>3"
1492 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1493 (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1494 (match_operand:GPR 2 "register_operand" "!u,d")))]
1497 [(set_attr "alu_type" "sub")
1498 (set_attr "compression" "micromips32,*")
1499 (set_attr "mode" "<MODE>")])
1501 (define_insn "*subsi3_extended"
1502 [(set (match_operand:DI 0 "register_operand" "=d")
1504 (minus:SI (match_operand:SI 1 "register_operand" "d")
1505 (match_operand:SI 2 "register_operand" "d"))))]
1508 [(set_attr "alu_type" "sub")
1509 (set_attr "mode" "DI")])
1512 ;; ....................
1516 ;; ....................
1519 (define_expand "mul<mode>3"
1520 [(set (match_operand:SCALARF 0 "register_operand")
1521 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1522 (match_operand:SCALARF 2 "register_operand")))]
1526 (define_insn "*mul<mode>3"
1527 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1528 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1529 (match_operand:SCALARF 2 "register_operand" "f")))]
1530 "!TARGET_4300_MUL_FIX"
1531 "mul.<fmt>\t%0,%1,%2"
1532 [(set_attr "type" "fmul")
1533 (set_attr "mode" "<MODE>")])
1535 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1536 ;; operands may corrupt immediately following multiplies. This is a
1537 ;; simple fix to insert NOPs.
1539 (define_insn "*mul<mode>3_r4300"
1540 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1541 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1542 (match_operand:SCALARF 2 "register_operand" "f")))]
1543 "TARGET_4300_MUL_FIX"
1544 "mul.<fmt>\t%0,%1,%2\;nop"
1545 [(set_attr "type" "fmul")
1546 (set_attr "mode" "<MODE>")
1547 (set_attr "insn_count" "2")])
1549 (define_insn "mulv2sf3"
1550 [(set (match_operand:V2SF 0 "register_operand" "=f")
1551 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1552 (match_operand:V2SF 2 "register_operand" "f")))]
1553 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1555 [(set_attr "type" "fmul")
1556 (set_attr "mode" "SF")])
1558 ;; The original R4000 has a cpu bug. If a double-word or a variable
1559 ;; shift executes while an integer multiplication is in progress, the
1560 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1561 ;; with the mult on the R4000.
1563 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1564 ;; (also valid for MIPS R4000MC processors):
1566 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1567 ;; this errata description.
1568 ;; The following code sequence causes the R4000 to incorrectly
1569 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1570 ;; instruction. If the dsra32 instruction is executed during an
1571 ;; integer multiply, the dsra32 will only shift by the amount in
1572 ;; specified in the instruction rather than the amount plus 32
1574 ;; instruction 1: mult rs,rt integer multiply
1575 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1576 ;; right arithmetic + 32
1577 ;; Workaround: A dsra32 instruction placed after an integer
1578 ;; multiply should not be one of the 11 instructions after the
1579 ;; multiply instruction."
1583 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1584 ;; the following description.
1585 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1586 ;; 64-bit versions) may produce incorrect results under the
1587 ;; following conditions:
1588 ;; 1) An integer multiply is currently executing
1589 ;; 2) These types of shift instructions are executed immediately
1590 ;; following an integer divide instruction.
1592 ;; 1) Make sure no integer multiply is running wihen these
1593 ;; instruction are executed. If this cannot be predicted at
1594 ;; compile time, then insert a "mfhi" to R0 instruction
1595 ;; immediately after the integer multiply instruction. This
1596 ;; will cause the integer multiply to complete before the shift
1598 ;; 2) Separate integer divide and these two classes of shift
1599 ;; instructions by another instruction or a noop."
1601 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1604 (define_expand "mul<mode>3"
1605 [(set (match_operand:GPR 0 "register_operand")
1606 (mult:GPR (match_operand:GPR 1 "register_operand")
1607 (match_operand:GPR 2 "register_operand")))]
1608 "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1612 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>MUL)
1613 emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1615 else if (ISA_HAS_<D>MUL3)
1616 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1617 else if (TARGET_MIPS16)
1619 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1620 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1621 emit_move_insn (operands[0], lo);
1623 else if (TARGET_FIX_R4000)
1624 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1627 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1631 (define_insn "mul<mode>3_mul3_nohilo"
1632 [(set (match_operand:GPR 0 "register_operand" "=d")
1633 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1634 (match_operand:GPR 2 "register_operand" "d")))]
1635 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>MUL"
1637 if (TARGET_LOONGSON_2EF)
1638 return "<d>multu.g\t%0,%1,%2";
1639 else if (TARGET_LOONGSON_EXT)
1640 return "gs<d>multu\t%0,%1,%2";
1642 return "<d>mul\t%0,%1,%2";
1644 [(set_attr "type" "imul3nc")
1645 (set_attr "mode" "<MODE>")])
1647 (define_insn "mul<mode>3_mul3"
1648 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1649 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1650 (match_operand:GPR 2 "register_operand" "d,d")))
1651 (clobber (match_scratch:GPR 3 "=l,X"))]
1654 if (which_alternative == 1)
1655 return "<d>mult\t%1,%2";
1656 if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1657 return "mult\t%0,%1,%2";
1658 return "<d>mul\t%0,%1,%2";
1660 [(set_attr "type" "imul3,imul")
1661 (set_attr "mode" "<MODE>")])
1663 ;; If a register gets allocated to LO, and we spill to memory, the reload
1664 ;; will include a move from LO to a GPR. Merge it into the multiplication
1665 ;; if it can set the GPR directly.
1668 ;; Operand 1: GPR (1st multiplication operand)
1669 ;; Operand 2: GPR (2nd multiplication operand)
1670 ;; Operand 3: GPR (destination)
1673 [(set (match_operand:SI 0 "lo_operand")
1674 (mult:SI (match_operand:SI 1 "d_operand")
1675 (match_operand:SI 2 "d_operand")))
1676 (clobber (scratch:SI))])
1677 (set (match_operand:SI 3 "d_operand")
1679 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1682 (mult:SI (match_dup 1)
1684 (clobber (match_dup 0))])])
1686 (define_insn "mul<mode>3_internal"
1687 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1688 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1689 (match_operand:GPR 2 "register_operand" "d")))]
1690 "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1692 [(set_attr "type" "imul")
1693 (set_attr "mode" "<MODE>")])
1695 (define_insn "mul<mode>3_r4000"
1696 [(set (match_operand:GPR 0 "register_operand" "=d")
1697 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1698 (match_operand:GPR 2 "register_operand" "d")))
1699 (clobber (match_scratch:GPR 3 "=l"))]
1700 "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1701 "<d>mult\t%1,%2\;mflo\t%0"
1702 [(set_attr "type" "imul")
1703 (set_attr "mode" "<MODE>")
1704 (set_attr "insn_count" "2")])
1706 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1707 ;; of "mult; mflo". They have the same latency, but the first form gives
1708 ;; us an extra cycle to compute the operands.
1711 ;; Operand 1: GPR (1st multiplication operand)
1712 ;; Operand 2: GPR (2nd multiplication operand)
1713 ;; Operand 3: GPR (destination)
1715 [(set (match_operand:SI 0 "lo_operand")
1716 (mult:SI (match_operand:SI 1 "d_operand")
1717 (match_operand:SI 2 "d_operand")))
1718 (set (match_operand:SI 3 "d_operand")
1720 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1725 (plus:SI (mult:SI (match_dup 1)
1729 (plus:SI (mult:SI (match_dup 1)
1733 ;; Multiply-accumulate patterns
1735 ;; This pattern is first matched by combine, which tries to use the
1736 ;; pattern wherever it can. We don't know until later whether it
1737 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1738 ;; so we need to keep both options open.
1740 ;; The second alternative has a "?" marker because it is generally
1741 ;; one instruction more costly than the first alternative. This "?"
1742 ;; marker is enough to convey the relative costs to the register
1745 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1746 ;; reloads of the other operands, even though operands 4 and 5 need no
1747 ;; copy instructions. Reload therefore thinks that the second alternative
1748 ;; is two reloads more costly than the first. We add "*?*?" to the first
1749 ;; alternative as a counterweight.
1751 ;; LRA simulates reload but the cost of reloading scratches is lower
1752 ;; than of the classic reload. For the time being, removing the counterweight
1753 ;; for LRA is more profitable.
1754 (define_insn "*mul_acc_si"
1755 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1756 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1757 (match_operand:SI 2 "register_operand" "d,d,d"))
1758 (match_operand:SI 3 "register_operand" "l,l,d")))
1759 (clobber (match_scratch:SI 4 "=X,X,l"))
1760 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1761 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1766 [(set_attr "type" "imadd")
1767 (set_attr "accum_in" "3")
1768 (set_attr "mode" "SI")
1769 (set_attr "insn_count" "1,1,2")
1770 (set (attr "enabled")
1771 (cond [(and (eq_attr "alternative" "0")
1772 (match_test "!mips_lra_flag"))
1773 (const_string "yes")
1774 (and (eq_attr "alternative" "1")
1775 (match_test "mips_lra_flag"))
1776 (const_string "yes")
1777 (eq_attr "alternative" "2")
1778 (const_string "yes")]
1779 (const_string "no")))])
1781 ;; The same idea applies here. The middle alternative needs one less
1782 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1783 (define_insn "*mul_acc_si_r3900"
1784 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1785 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1786 (match_operand:SI 2 "register_operand" "d,d,d,d"))
1787 (match_operand:SI 3 "register_operand" "l,l,l,d")))
1788 (clobber (match_scratch:SI 4 "=X,X,3,l"))
1789 (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1790 "TARGET_MIPS3900 && !TARGET_MIPS16"
1796 [(set_attr "type" "imadd")
1797 (set_attr "accum_in" "3")
1798 (set_attr "mode" "SI")
1799 (set_attr "insn_count" "1,1,1,2")
1800 (set (attr "enabled")
1801 (cond [(and (eq_attr "alternative" "0")
1802 (match_test "!mips_lra_flag"))
1803 (const_string "yes")
1804 (and (eq_attr "alternative" "1")
1805 (match_test "mips_lra_flag"))
1806 (const_string "yes")
1807 (eq_attr "alternative" "2,3")
1808 (const_string "yes")]
1809 (const_string "no")))])
1811 ;; Split *mul_acc_si if both the source and destination accumulator
1814 [(set (match_operand:SI 0 "d_operand")
1815 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1816 (match_operand:SI 2 "d_operand"))
1817 (match_operand:SI 3 "d_operand")))
1818 (clobber (match_operand:SI 4 "lo_operand"))
1819 (clobber (match_operand:SI 5 "d_operand"))]
1821 [(parallel [(set (match_dup 5)
1822 (mult:SI (match_dup 1) (match_dup 2)))
1823 (clobber (match_dup 4))])
1824 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1827 (define_insn "*macc"
1828 [(set (match_operand:SI 0 "register_operand" "=l,d")
1829 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1830 (match_operand:SI 2 "register_operand" "d,d"))
1831 (match_operand:SI 3 "register_operand" "l,l")))
1832 (clobber (match_scratch:SI 4 "=X,3"))]
1835 if (which_alternative == 1)
1836 return "macc\t%0,%1,%2";
1837 else if (TARGET_MIPS5500)
1838 return "madd\t%1,%2";
1840 /* The VR4130 assumes that there is a two-cycle latency between a macc
1841 that "writes" to $0 and an instruction that reads from it. We avoid
1842 this by assigning to $1 instead. */
1843 return "%[macc\t%@,%1,%2%]";
1845 [(set_attr "type" "imadd")
1846 (set_attr "accum_in" "3")
1847 (set_attr "mode" "SI")])
1849 (define_insn "*msac"
1850 [(set (match_operand:SI 0 "register_operand" "=l,d")
1851 (minus:SI (match_operand:SI 1 "register_operand" "l,l")
1852 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1853 (match_operand:SI 3 "register_operand" "d,d"))))
1854 (clobber (match_scratch:SI 4 "=X,1"))]
1857 if (which_alternative == 1)
1858 return "msac\t%0,%2,%3";
1859 else if (TARGET_MIPS5500)
1860 return "msub\t%2,%3";
1862 return "msac\t$0,%2,%3";
1864 [(set_attr "type" "imadd")
1865 (set_attr "accum_in" "1")
1866 (set_attr "mode" "SI")])
1868 ;; An msac-like instruction implemented using negation and a macc.
1869 (define_insn_and_split "*msac_using_macc"
1870 [(set (match_operand:SI 0 "register_operand" "=l,d")
1871 (minus:SI (match_operand:SI 1 "register_operand" "l,l")
1872 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1873 (match_operand:SI 3 "register_operand" "d,d"))))
1874 (clobber (match_scratch:SI 4 "=X,1"))
1875 (clobber (match_scratch:SI 5 "=d,d"))]
1876 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1878 "&& reload_completed"
1880 (neg:SI (match_dup 3)))
1883 (plus:SI (mult:SI (match_dup 2)
1886 (clobber (match_dup 4))])]
1888 [(set_attr "type" "imadd")
1889 (set_attr "accum_in" "1")
1890 (set_attr "insn_count" "2")])
1892 ;; Patterns generated by the define_peephole2 below.
1894 (define_insn "*macc2"
1895 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1896 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1897 (match_operand:SI 2 "register_operand" "d"))
1899 (set (match_operand:SI 3 "register_operand" "=d")
1900 (plus:SI (mult:SI (match_dup 1)
1903 "ISA_HAS_MACC && reload_completed"
1905 [(set_attr "type" "imadd")
1906 (set_attr "accum_in" "0")
1907 (set_attr "mode" "SI")])
1909 (define_insn "*msac2"
1910 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1911 (minus:SI (match_dup 0)
1912 (mult:SI (match_operand:SI 1 "register_operand" "d")
1913 (match_operand:SI 2 "register_operand" "d"))))
1914 (set (match_operand:SI 3 "register_operand" "=d")
1915 (minus:SI (match_dup 0)
1916 (mult:SI (match_dup 1)
1918 "ISA_HAS_MSAC && reload_completed"
1920 [(set_attr "type" "imadd")
1921 (set_attr "accum_in" "0")
1922 (set_attr "mode" "SI")])
1924 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1928 ;; Operand 1: macc/msac
1929 ;; Operand 2: GPR (destination)
1932 [(set (match_operand:SI 0 "lo_operand")
1933 (match_operand:SI 1 "macc_msac_operand"))
1934 (clobber (scratch:SI))])
1935 (set (match_operand:SI 2 "d_operand")
1938 [(parallel [(set (match_dup 0)
1943 ;; When we have a three-address multiplication instruction, it should
1944 ;; be faster to do a separate multiply and add, rather than moving
1945 ;; something into LO in order to use a macc instruction.
1947 ;; This peephole needs a scratch register to cater for the case when one
1948 ;; of the multiplication operands is the same as the destination.
1950 ;; Operand 0: GPR (scratch)
1952 ;; Operand 2: GPR (addend)
1953 ;; Operand 3: GPR (destination)
1954 ;; Operand 4: macc/msac
1955 ;; Operand 5: new multiplication
1956 ;; Operand 6: new addition/subtraction
1958 [(match_scratch:SI 0 "d")
1959 (set (match_operand:SI 1 "lo_operand")
1960 (match_operand:SI 2 "d_operand"))
1963 [(set (match_operand:SI 3 "d_operand")
1964 (match_operand:SI 4 "macc_msac_operand"))
1965 (clobber (match_dup 1))])]
1966 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1967 [(parallel [(set (match_dup 0)
1969 (clobber (match_dup 1))])
1973 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1974 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1975 operands[2], operands[0]);
1978 ;; Same as above, except LO is the initial target of the macc.
1980 ;; Operand 0: GPR (scratch)
1982 ;; Operand 2: GPR (addend)
1983 ;; Operand 3: macc/msac
1984 ;; Operand 4: GPR (destination)
1985 ;; Operand 5: new multiplication
1986 ;; Operand 6: new addition/subtraction
1988 [(match_scratch:SI 0 "d")
1989 (set (match_operand:SI 1 "lo_operand")
1990 (match_operand:SI 2 "d_operand"))
1994 (match_operand:SI 3 "macc_msac_operand"))
1995 (clobber (scratch:SI))])
1997 (set (match_operand:SI 4 "d_operand")
1999 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
2000 [(parallel [(set (match_dup 0)
2002 (clobber (match_dup 1))])
2006 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
2007 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
2008 operands[2], operands[0]);
2011 ;; See the comment above *mul_add_si for details.
2012 (define_insn "*mul_sub_si"
2013 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
2014 (minus:SI (match_operand:SI 1 "register_operand" "l,l,d")
2015 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
2016 (match_operand:SI 3 "register_operand" "d,d,d"))))
2017 (clobber (match_scratch:SI 4 "=X,X,l"))
2018 (clobber (match_scratch:SI 5 "=X,X,&d"))]
2019 "GENERATE_MADD_MSUB"
2024 [(set_attr "type" "imadd")
2025 (set_attr "accum_in" "1")
2026 (set_attr "mode" "SI")
2027 (set_attr "insn_count" "1,1,2")
2028 (set (attr "enabled")
2029 (cond [(and (eq_attr "alternative" "0")
2030 (match_test "!mips_lra_flag"))
2031 (const_string "yes")
2032 (and (eq_attr "alternative" "1")
2033 (match_test "mips_lra_flag"))
2034 (const_string "yes")
2035 (eq_attr "alternative" "2")
2036 (const_string "yes")]
2037 (const_string "no")))])
2039 ;; Split *mul_sub_si if both the source and destination accumulator
2042 [(set (match_operand:SI 0 "d_operand")
2043 (minus:SI (match_operand:SI 1 "d_operand")
2044 (mult:SI (match_operand:SI 2 "d_operand")
2045 (match_operand:SI 3 "d_operand"))))
2046 (clobber (match_operand:SI 4 "lo_operand"))
2047 (clobber (match_operand:SI 5 "d_operand"))]
2049 [(parallel [(set (match_dup 5)
2050 (mult:SI (match_dup 2) (match_dup 3)))
2051 (clobber (match_dup 4))])
2052 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
2055 (define_insn "*muls"
2056 [(set (match_operand:SI 0 "register_operand" "=l,d")
2057 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2058 (match_operand:SI 2 "register_operand" "d,d"))))
2059 (clobber (match_scratch:SI 3 "=X,l"))]
2064 [(set_attr "type" "imul,imul3")
2065 (set_attr "mode" "SI")])
2067 (define_expand "<u>mulsidi3"
2068 [(set (match_operand:DI 0 "register_operand")
2069 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2070 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2071 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
2073 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
2074 emit_insn (fn (operands[0], operands[1], operands[2]));
2078 (define_expand "<u>mulsidi3_32bit_r6"
2079 [(set (match_operand:DI 0 "register_operand")
2080 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2081 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2082 "!TARGET_64BIT && ISA_HAS_R6MUL"
2084 rtx dest = gen_reg_rtx (DImode);
2085 rtx low = mips_subword (dest, 0);
2086 rtx high = mips_subword (dest, 1);
2088 emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2089 emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2091 emit_move_insn (mips_subword (operands[0], 0), low);
2092 emit_move_insn (mips_subword (operands[0], 1), high);
2096 (define_expand "<u>mulsidi3_32bit_mips16"
2097 [(set (match_operand:DI 0 "register_operand")
2098 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2099 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2100 "!TARGET_64BIT && TARGET_MIPS16"
2104 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2105 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2106 emit_move_insn (operands[0], hilo);
2110 ;; As well as being named patterns, these instructions are used by the
2111 ;; __builtin_mips_mult<u>() functions. We must always make those functions
2112 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2113 (define_insn "<u>mulsidi3_32bit"
2114 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2115 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2116 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2117 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2119 if (ISA_HAS_DSP_MULT)
2120 return "mult<u>\t%q0,%1,%2";
2122 return "mult<u>\t%1,%2";
2124 [(set_attr "type" "imul")
2125 (set_attr "mode" "SI")])
2127 (define_insn "<u>mulsidi3_32bit_r4000"
2128 [(set (match_operand:DI 0 "register_operand" "=d")
2129 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2130 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2131 (clobber (match_scratch:DI 3 "=x"))]
2132 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2133 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2134 [(set_attr "type" "imul")
2135 (set_attr "mode" "SI")
2136 (set_attr "insn_count" "3")])
2138 (define_insn_and_split "<u>mulsidi3_64bit"
2139 [(set (match_operand:DI 0 "register_operand" "=d")
2140 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2141 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2142 (clobber (match_scratch:TI 3 "=x"))
2143 (clobber (match_scratch:DI 4 "=d"))]
2144 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2145 && !TARGET_MIPS16 && ISA_HAS_MULT"
2147 "&& reload_completed"
2150 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2151 operands[2], operands[4]));
2154 [(set_attr "type" "imul")
2155 (set_attr "mode" "SI")
2156 (set (attr "insn_count")
2157 (if_then_else (match_test "ISA_HAS_EXT_INS")
2161 (define_expand "<u>mulsidi3_64bit_mips16"
2162 [(set (match_operand:DI 0 "register_operand")
2163 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2164 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2165 "TARGET_64BIT && TARGET_MIPS16"
2167 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2168 operands[2], gen_reg_rtx (DImode)));
2172 (define_expand "<u>mulsidi3_64bit_split"
2173 [(set (match_operand:DI 0 "register_operand")
2174 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2175 (any_extend:DI (match_operand:SI 2 "register_operand"))))
2176 (clobber (match_operand:DI 3 "register_operand"))]
2181 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2182 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2184 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2185 emit_insn (gen_mfhidi_ti (operands[3], hilo));
2187 if (ISA_HAS_EXT_INS)
2188 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2192 /* Zero-extend the low part. */
2193 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2194 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2196 /* Shift the high part into place. */
2197 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2199 /* OR the two halves together. */
2200 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2205 (define_insn "<u>mulsidi3_64bit_hilo"
2206 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2209 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2210 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2212 "TARGET_64BIT && !TARGET_FIX_R4000"
2214 [(set_attr "type" "imul")
2215 (set_attr "mode" "SI")])
2217 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2218 (define_insn "mulsidi3_64bit_dmul"
2219 [(set (match_operand:DI 0 "register_operand" "=d")
2220 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2221 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2222 (clobber (match_scratch:DI 3 "=l"))]
2225 [(set_attr "type" "imul3")
2226 (set_attr "mode" "DI")])
2228 (define_insn "mulsidi3_64bit_r6dmul"
2229 [(set (match_operand:DI 0 "register_operand" "=d")
2230 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2231 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2234 [(set_attr "type" "imul3nc")
2235 (set_attr "mode" "DI")])
2237 ;; Widening multiply with negation.
2238 (define_insn "*muls<u>_di"
2239 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2242 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2243 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2244 "!TARGET_64BIT && ISA_HAS_MULS"
2246 [(set_attr "type" "imul")
2247 (set_attr "mode" "SI")])
2249 ;; As well as being named patterns, these instructions are used by the
2250 ;; __builtin_mips_msub<u>() functions. We must always make those functions
2251 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2253 ;; This leads to a slight inconsistency. We honor any tuning overrides
2254 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2255 ;; even if !ISA_HAS_DSP_MULT.
2256 (define_insn "<u>msubsidi4"
2257 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2259 (match_operand:DI 3 "muldiv_target_operand" "0")
2261 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2262 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2263 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2265 if (ISA_HAS_DSP_MULT)
2266 return "msub<u>\t%q0,%1,%2";
2267 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2268 return "msub<u>\t%1,%2";
2270 return "msac<u>\t$0,%1,%2";
2272 [(set_attr "type" "imadd")
2273 (set_attr "accum_in" "3")
2274 (set_attr "mode" "SI")])
2276 ;; _highpart patterns
2278 (define_expand "<su>mulsi3_highpart"
2279 [(set (match_operand:SI 0 "register_operand")
2282 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2283 (any_extend:DI (match_operand:SI 2 "register_operand")))
2288 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2291 else if (TARGET_MIPS16)
2292 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2294 else if (ISA_HAS_R6MUL)
2295 emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2298 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2303 (define_insn "<su>mulsi3_highpart_r6"
2304 [(set (match_operand:SI 0 "register_operand" "=d")
2307 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2308 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2312 [(set_attr "type" "imul3nc")
2313 (set_attr "mode" "SI")])
2315 (define_insn_and_split "<su>mulsi3_highpart_internal"
2316 [(set (match_operand:SI 0 "register_operand" "=d")
2319 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2320 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2322 (clobber (match_scratch:SI 3 "=l"))]
2323 "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2324 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2325 "&& reload_completed && !TARGET_FIX_R4000"
2328 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2332 [(set_attr "type" "imul")
2333 (set_attr "mode" "SI")
2334 (set_attr "insn_count" "2")])
2336 (define_expand "<su>mulsi3_highpart_split"
2337 [(set (match_operand:SI 0 "register_operand")
2340 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2341 (any_extend:DI (match_operand:SI 2 "register_operand")))
2349 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2350 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2351 emit_insn (gen_mfhisi_ti (operands[0], hilo));
2355 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2356 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2357 emit_insn (gen_mfhisi_di (operands[0], hilo));
2362 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2363 [(set (match_operand:SI 0 "register_operand" "=d")
2367 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2368 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2370 (clobber (match_scratch:SI 3 "=l"))]
2372 "mulhi<u>\t%0,%1,%2"
2373 [(set_attr "type" "imul3")
2374 (set_attr "mode" "SI")])
2376 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2377 [(set (match_operand:SI 0 "register_operand" "=d")
2382 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2383 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2385 (clobber (match_scratch:SI 3 "=l"))]
2387 "mulshi<u>\t%0,%1,%2"
2388 [(set_attr "type" "imul3")
2389 (set_attr "mode" "SI")])
2391 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2392 ;; errata MD(0), which says that dmultu does not always produce the
2394 (define_expand "<su>muldi3_highpart"
2395 [(set (match_operand:DI 0 "register_operand")
2398 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2399 (any_extend:TI (match_operand:DI 2 "register_operand")))
2403 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2406 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2408 else if (ISA_HAS_R6DMUL)
2409 emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2412 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2417 (define_insn "<su>muldi3_highpart_r6"
2418 [(set (match_operand:DI 0 "register_operand" "=d")
2421 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2422 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2426 [(set_attr "type" "imul3nc")
2427 (set_attr "mode" "DI")])
2429 (define_insn_and_split "<su>muldi3_highpart_internal"
2430 [(set (match_operand:DI 0 "register_operand" "=d")
2433 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2434 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2436 (clobber (match_scratch:DI 3 "=l"))]
2439 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2440 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2441 "&& reload_completed && !TARGET_FIX_R4000"
2444 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2448 [(set_attr "type" "imul")
2449 (set_attr "mode" "DI")
2450 (set_attr "insn_count" "2")])
2452 (define_expand "<su>muldi3_highpart_split"
2453 [(set (match_operand:DI 0 "register_operand")
2456 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2457 (any_extend:TI (match_operand:DI 2 "register_operand")))
2463 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2464 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2465 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2469 (define_expand "<u>mulditi3"
2470 [(set (match_operand:TI 0 "register_operand")
2471 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2472 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2475 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2481 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2482 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2483 emit_move_insn (operands[0], hilo);
2485 else if (TARGET_FIX_R4000)
2486 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2487 else if (ISA_HAS_DMULT)
2488 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2492 hi = mips_subword (operands[0], 1);
2493 lo = mips_subword (operands[0], 0);
2494 emit_insn (gen_muldi3_mul3_nohilo (lo, operands[1], operands[2]));
2495 emit_insn (gen_<su>muldi3_highpart_r6 (hi, operands[1], operands[2]));
2500 (define_insn "<u>mulditi3_internal"
2501 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2502 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2503 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2505 && !TARGET_FIX_R4000
2506 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2508 [(set_attr "type" "imul")
2509 (set_attr "mode" "DI")])
2511 (define_insn "<u>mulditi3_r4000"
2512 [(set (match_operand:TI 0 "register_operand" "=d")
2513 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2514 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2515 (clobber (match_scratch:TI 3 "=x"))]
2518 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2519 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2520 [(set_attr "type" "imul")
2521 (set_attr "mode" "DI")
2522 (set_attr "insn_count" "3")])
2524 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2525 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2527 (define_insn "madsi"
2528 [(set (match_operand:SI 0 "register_operand" "+l")
2529 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2530 (match_operand:SI 2 "register_operand" "d"))
2534 [(set_attr "type" "imadd")
2535 (set_attr "accum_in" "0")
2536 (set_attr "mode" "SI")])
2538 ;; See the comment above <u>msubsidi4 for the relationship between
2539 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2540 (define_insn "<u>maddsidi4"
2541 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2543 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2544 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2545 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2546 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2550 return "mad<u>\t%1,%2";
2551 else if (ISA_HAS_DSP_MULT)
2552 return "madd<u>\t%q0,%1,%2";
2553 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2554 return "madd<u>\t%1,%2";
2556 /* See comment in *macc. */
2557 return "%[macc<u>\t%@,%1,%2%]";
2559 [(set_attr "type" "imadd")
2560 (set_attr "accum_in" "3")
2561 (set_attr "mode" "SI")])
2563 ;; Floating point multiply accumulate instructions.
2565 (define_expand "fma<mode>4"
2566 [(set (match_operand:ANYF 0 "register_operand")
2567 (fma:ANYF (match_operand:ANYF 1 "register_operand")
2568 (match_operand:ANYF 2 "register_operand")
2569 (match_operand:ANYF 3 "register_operand")))]
2570 "ISA_HAS_FUSED_MADDF || ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4")
2572 (define_insn "*fma<mode>4_madd3"
2573 [(set (match_operand:ANYF 0 "register_operand" "=f")
2574 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2575 (match_operand:ANYF 2 "register_operand" "f")
2576 (match_operand:ANYF 3 "register_operand" "0")))]
2577 "ISA_HAS_FUSED_MADD3"
2578 "madd.<fmt>\t%0,%1,%2"
2579 [(set_attr "type" "fmadd")
2580 (set_attr "mode" "<UNITMODE>")])
2582 (define_insn "*fma<mode>4_madd4"
2583 [(set (match_operand:ANYF 0 "register_operand" "=f")
2584 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2585 (match_operand:ANYF 2 "register_operand" "f")
2586 (match_operand:ANYF 3 "register_operand" "f")))]
2587 "ISA_HAS_FUSED_MADD4"
2588 "madd.<fmt>\t%0,%3,%1,%2"
2589 [(set_attr "type" "fmadd")
2590 (set_attr "mode" "<UNITMODE>")])
2592 (define_insn "*fma<mode>4_maddf"
2593 [(set (match_operand:ANYF 0 "register_operand" "=f")
2594 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2595 (match_operand:ANYF 2 "register_operand" "f")
2596 (match_operand:ANYF 3 "register_operand" "0")))]
2597 "ISA_HAS_FUSED_MADDF"
2598 "maddf.<fmt>\t%0,%1,%2"
2599 [(set_attr "type" "fmadd")
2600 (set_attr "mode" "<UNITMODE>")])
2602 ;; The fms, fnma, and fnms instructions can be used even when HONOR_NANS
2603 ;; is true because while IEEE 754-2008 requires the negate operation to
2604 ;; negate the sign of a NAN and the MIPS neg instruction does not do this,
2605 ;; the fma part of the instruction has no requirement on how the sign of
2606 ;; a NAN is handled and so the final sign bit of the entire operation is
2609 (define_expand "fms<mode>4"
2610 [(set (match_operand:ANYF 0 "register_operand")
2611 (fma:ANYF (match_operand:ANYF 1 "register_operand")
2612 (match_operand:ANYF 2 "register_operand")
2613 (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2614 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)")
2616 (define_insn "*fms<mode>4_msub3"
2617 [(set (match_operand:ANYF 0 "register_operand" "=f")
2618 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2619 (match_operand:ANYF 2 "register_operand" "f")
2620 (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2621 "ISA_HAS_FUSED_MADD3"
2622 "msub.<fmt>\t%0,%1,%2"
2623 [(set_attr "type" "fmadd")
2624 (set_attr "mode" "<UNITMODE>")])
2626 (define_insn "*fms<mode>4_msub4"
2627 [(set (match_operand:ANYF 0 "register_operand" "=f")
2628 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2629 (match_operand:ANYF 2 "register_operand" "f")
2630 (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2631 "ISA_HAS_FUSED_MADD4"
2632 "msub.<fmt>\t%0,%3,%1,%2"
2633 [(set_attr "type" "fmadd")
2634 (set_attr "mode" "<UNITMODE>")])
2636 ;; fnma is defined in GCC as (fma (neg op1) op2 op3)
2637 ;; (-op1 * op2) + op3 ==> -(op1 * op2) + op3 ==> -((op1 * op2) - op3)
2638 ;; The mips nmsub instructions implement -((op1 * op2) - op3)
2639 ;; This transformation means we may return the wrong signed zero
2640 ;; so we check HONOR_SIGNED_ZEROS.
2642 (define_expand "fnma<mode>4"
2643 [(set (match_operand:ANYF 0 "register_operand")
2644 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2645 (match_operand:ANYF 2 "register_operand")
2646 (match_operand:ANYF 3 "register_operand")))]
2647 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2648 && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2650 (define_insn "*fnma<mode>4_nmsub3"
2651 [(set (match_operand:ANYF 0 "register_operand" "=f")
2652 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2653 (match_operand:ANYF 2 "register_operand" "f")
2654 (match_operand:ANYF 3 "register_operand" "0")))]
2655 "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2656 "nmsub.<fmt>\t%0,%1,%2"
2657 [(set_attr "type" "fmadd")
2658 (set_attr "mode" "<UNITMODE>")])
2660 (define_insn "*fnma<mode>4_nmsub4"
2661 [(set (match_operand:ANYF 0 "register_operand" "=f")
2662 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2663 (match_operand:ANYF 2 "register_operand" "f")
2664 (match_operand:ANYF 3 "register_operand" "f")))]
2665 "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2666 "nmsub.<fmt>\t%0,%3,%1,%2"
2667 [(set_attr "type" "fmadd")
2668 (set_attr "mode" "<UNITMODE>")])
2670 ;; fnms is defined as: (fma (neg op1) op2 (neg op3))
2671 ;; ((-op1) * op2) - op3 ==> -(op1 * op2) - op3 ==> -((op1 * op2) + op3)
2672 ;; The mips nmadd instructions implement -((op1 * op2) + op3)
2673 ;; This transformation means we may return the wrong signed zero
2674 ;; so we check HONOR_SIGNED_ZEROS.
2676 (define_expand "fnms<mode>4"
2677 [(set (match_operand:ANYF 0 "register_operand")
2679 (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2680 (match_operand:ANYF 2 "register_operand")
2681 (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2682 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2683 && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2685 (define_insn "*fnms<mode>4_nmadd3"
2686 [(set (match_operand:ANYF 0 "register_operand" "=f")
2688 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2689 (match_operand:ANYF 2 "register_operand" "f")
2690 (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2691 "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2692 "nmadd.<fmt>\t%0,%1,%2"
2693 [(set_attr "type" "fmadd")
2694 (set_attr "mode" "<UNITMODE>")])
2696 (define_insn "*fnms<mode>4_nmadd4"
2697 [(set (match_operand:ANYF 0 "register_operand" "=f")
2699 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2700 (match_operand:ANYF 2 "register_operand" "f")
2701 (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2702 "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2703 "nmadd.<fmt>\t%0,%3,%1,%2"
2704 [(set_attr "type" "fmadd")
2705 (set_attr "mode" "<UNITMODE>")])
2707 ;; Non-fused Floating point multiply accumulate instructions.
2709 ;; These instructions are not fused and round in between the multiply
2710 ;; and the add (or subtract) so they are equivalent to the separate
2711 ;; multiply and add/sub instructions.
2713 (define_insn "*madd4<mode>"
2714 [(set (match_operand:ANYF 0 "register_operand" "=f")
2715 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2716 (match_operand:ANYF 2 "register_operand" "f"))
2717 (match_operand:ANYF 3 "register_operand" "f")))]
2718 "ISA_HAS_UNFUSED_MADD4"
2719 "madd.<fmt>\t%0,%3,%1,%2"
2720 [(set_attr "type" "fmadd")
2721 (set_attr "mode" "<UNITMODE>")])
2723 (define_insn "*msub4<mode>"
2724 [(set (match_operand:ANYF 0 "register_operand" "=f")
2725 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2726 (match_operand:ANYF 2 "register_operand" "f"))
2727 (match_operand:ANYF 3 "register_operand" "f")))]
2728 "ISA_HAS_UNFUSED_MADD4"
2729 "msub.<fmt>\t%0,%3,%1,%2"
2730 [(set_attr "type" "fmadd")
2731 (set_attr "mode" "<UNITMODE>")])
2733 ;; Like with the fused fms, fnma, and fnms instructions, these unfused
2734 ;; instructions can be used even if HONOR_NANS is set because while
2735 ;; IEEE 754-2008 requires the negate operation to negate the sign of a
2736 ;; NAN and the MIPS neg instruction does not do this, the multiply and
2737 ;; add (or subtract) part of the instruction has no requirement on how
2738 ;; the sign of a NAN is handled and so the final sign bit of the entire
2739 ;; operation is undefined.
2741 (define_insn "*nmadd4<mode>"
2742 [(set (match_operand:ANYF 0 "register_operand" "=f")
2743 (neg:ANYF (plus:ANYF
2744 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2745 (match_operand:ANYF 2 "register_operand" "f"))
2746 (match_operand:ANYF 3 "register_operand" "f"))))]
2747 "ISA_HAS_UNFUSED_MADD4"
2748 "nmadd.<fmt>\t%0,%3,%1,%2"
2749 [(set_attr "type" "fmadd")
2750 (set_attr "mode" "<UNITMODE>")])
2752 (define_insn "*nmsub4<mode>"
2753 [(set (match_operand:ANYF 0 "register_operand" "=f")
2754 (neg:ANYF (minus:ANYF
2755 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2756 (match_operand:ANYF 2 "register_operand" "f"))
2757 (match_operand:ANYF 3 "register_operand" "f"))))]
2758 "ISA_HAS_UNFUSED_MADD4"
2759 "nmsub.<fmt>\t%0,%3,%1,%2"
2760 [(set_attr "type" "fmadd")
2761 (set_attr "mode" "<UNITMODE>")])
2763 ;; Fast-math Non-fused Floating point multiply accumulate instructions.
2765 ;; These instructions are not fused but the expressions they match are
2766 ;; not exactly what the instruction implements in the sense that they
2767 ;; may not generate the properly signed zeros.
2769 ;; This instruction recognizes ((-op1) * op2) - op3 and generates an
2770 ;; nmadd which is really -((op1 * op2) + op3). They are equivalent
2771 ;; except for the sign bit when the result is zero or NaN.
2773 (define_insn "*nmadd4<mode>_fastmath"
2774 [(set (match_operand:ANYF 0 "register_operand" "=f")
2776 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2777 (match_operand:ANYF 2 "register_operand" "f"))
2778 (match_operand:ANYF 3 "register_operand" "f")))]
2779 "ISA_HAS_UNFUSED_MADD4
2780 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2781 "nmadd.<fmt>\t%0,%3,%1,%2"
2782 [(set_attr "type" "fmadd")
2783 (set_attr "mode" "<UNITMODE>")])
2785 ;; This instruction recognizes (op1 - (op2 * op3) and generates an
2786 ;; nmsub which is really -((op2 * op3) - op1). They are equivalent
2787 ;; except for the sign bit when the result is zero or NaN.
2789 (define_insn "*nmsub4<mode>_fastmath"
2790 [(set (match_operand:ANYF 0 "register_operand" "=f")
2792 (match_operand:ANYF 1 "register_operand" "f")
2793 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2794 (match_operand:ANYF 3 "register_operand" "f"))))]
2795 "ISA_HAS_UNFUSED_MADD4
2796 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2797 "nmsub.<fmt>\t%0,%1,%2,%3"
2798 [(set_attr "type" "fmadd")
2799 (set_attr "mode" "<UNITMODE>")])
2802 ;; ....................
2804 ;; DIVISION and REMAINDER
2806 ;; ....................
2809 (define_expand "div<mode>3"
2810 [(set (match_operand:ANYF 0 "register_operand")
2811 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2812 (match_operand:ANYF 2 "register_operand")))]
2813 "<divide_condition>"
2815 if (const_1_operand (operands[1], <MODE>mode))
2816 if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2817 && flag_unsafe_math_optimizations))
2818 operands[1] = force_reg (<MODE>mode, operands[1]);
2821 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2823 ;; If an mfc1 or dmfc1 happens to access the floating point register
2824 ;; file at the same time a long latency operation (div, sqrt, recip,
2825 ;; sqrt) iterates an intermediate result back through the floating
2826 ;; point register file bypass, then instead returning the correct
2827 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2828 ;; result of the long latency operation.
2830 ;; The workaround is to insert an unconditional 'mov' from/to the
2831 ;; long latency op destination register.
2833 (define_insn "*div<mode>3"
2834 [(set (match_operand:ANYF 0 "register_operand" "=f")
2835 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2836 (match_operand:ANYF 2 "register_operand" "f")))]
2837 "<divide_condition>"
2840 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2842 return "div.<fmt>\t%0,%1,%2";
2844 [(set_attr "type" "fdiv")
2845 (set_attr "mode" "<UNITMODE>")
2846 (set (attr "insn_count")
2847 (if_then_else (match_test "TARGET_FIX_SB1")
2851 (define_insn "*recip<mode>3"
2852 [(set (match_operand:ANYF 0 "register_operand" "=f")
2853 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2854 (match_operand:ANYF 2 "register_operand" "f")))]
2855 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2858 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2860 return "recip.<fmt>\t%0,%2";
2862 [(set_attr "type" "frdiv")
2863 (set_attr "mode" "<UNITMODE>")
2864 (set (attr "insn_count")
2865 (if_then_else (match_test "TARGET_FIX_SB1")
2869 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2870 ;; with negative operands. We use special libgcc functions instead.
2871 (define_expand "divmod<mode>4"
2873 [(set (match_operand:GPR 0 "register_operand")
2874 (div:GPR (match_operand:GPR 1 "register_operand")
2875 (match_operand:GPR 2 "register_operand")))
2876 (set (match_operand:GPR 3 "register_operand")
2877 (mod:GPR (match_dup 1)
2879 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2883 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2884 emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2885 operands[2], operands[3], lo));
2890 (define_insn_and_split "*divmod<mode>4"
2891 [(set (match_operand:GPR 0 "register_operand" "=l")
2892 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2893 (match_operand:GPR 2 "register_operand" "d")))
2894 (set (match_operand:GPR 3 "register_operand" "=d")
2895 (mod:GPR (match_dup 1)
2897 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2899 "&& reload_completed"
2902 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2905 [(set_attr "type" "idiv")
2906 (set_attr "mode" "<MODE>")
2907 (set_attr "insn_count" "2")])
2909 ;; Expand generates divmod instructions for individual division and modulus
2910 ;; operations. We then rely on CSE to reuse earlier divmods where possible.
2911 ;; This means that, when generating MIPS16 code, it is better not to expose
2912 ;; the fixed LO register until after CSE has finished. However, it's still
2913 ;; better to split before register allocation, so that we don't allocate
2914 ;; one of the scarce MIPS16 registers to an unused result.
2915 (define_insn_and_split "divmod<mode>4_mips16"
2916 [(set (match_operand:GPR 0 "register_operand" "=d")
2917 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2918 (match_operand:GPR 2 "register_operand" "d")))
2919 (set (match_operand:GPR 3 "register_operand" "=d")
2920 (mod:GPR (match_dup 1)
2922 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2923 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2925 "&& cse_not_expected"
2928 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2929 emit_move_insn (operands[0], operands[4]);
2932 [(set_attr "type" "idiv")
2933 (set_attr "mode" "<MODE>")
2934 (set_attr "insn_count" "3")])
2936 (define_expand "udivmod<mode>4"
2938 [(set (match_operand:GPR 0 "register_operand")
2939 (udiv:GPR (match_operand:GPR 1 "register_operand")
2940 (match_operand:GPR 2 "register_operand")))
2941 (set (match_operand:GPR 3 "register_operand")
2942 (umod:GPR (match_dup 1)
2944 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2948 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2949 emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2950 operands[2], operands[3], lo));
2955 (define_insn_and_split "*udivmod<mode>4"
2956 [(set (match_operand:GPR 0 "register_operand" "=l")
2957 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2958 (match_operand:GPR 2 "register_operand" "d")))
2959 (set (match_operand:GPR 3 "register_operand" "=d")
2960 (umod:GPR (match_dup 1)
2962 "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2967 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2970 [(set_attr "type" "idiv")
2971 (set_attr "mode" "<MODE>")
2972 (set_attr "insn_count" "2")])
2974 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2975 (define_insn_and_split "udivmod<mode>4_mips16"
2976 [(set (match_operand:GPR 0 "register_operand" "=d")
2977 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2978 (match_operand:GPR 2 "register_operand" "d")))
2979 (set (match_operand:GPR 3 "register_operand" "=d")
2980 (umod:GPR (match_dup 1)
2982 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2983 "ISA_HAS_<D>DIV && TARGET_MIPS16"
2988 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2989 emit_move_insn (operands[0], operands[4]);
2992 [(set_attr "type" "idiv")
2993 (set_attr "mode" "<MODE>")
2994 (set_attr "insn_count" "3")])
2996 (define_expand "<u>divmod<mode>4_split"
2997 [(set (match_operand:GPR 0 "register_operand")
2998 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2999 (match_operand:GPR 2 "register_operand")))]
3006 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
3007 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
3009 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
3013 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
3014 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
3016 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
3021 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
3022 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
3024 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3025 (match_operand:GPR 2 "register_operand" "d"))]
3027 "ISA_HAS_<GPR:D>DIV"
3028 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
3029 [(set_attr "type" "idiv")
3030 (set_attr "mode" "<GPR:MODE>")])
3032 ;; Integer division and modulus.
3034 (define_insn "<u>div<mode>3"
3035 [(set (match_operand:GPR 0 "register_operand" "=&d")
3036 (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3037 (match_operand:GPR 2 "register_operand" "d")))]
3038 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>DIV"
3040 if (TARGET_LOONGSON_2EF)
3041 return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
3042 else if (TARGET_LOONGSON_EXT)
3043 return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
3045 return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
3047 [(set_attr "type" "idiv3")
3048 (set_attr "mode" "<MODE>")])
3050 (define_insn "<u>mod<mode>3"
3051 [(set (match_operand:GPR 0 "register_operand" "=&d")
3052 (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
3053 (match_operand:GPR 2 "register_operand" "d")))]
3054 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT || ISA_HAS_R6<D>DIV"
3056 if (TARGET_LOONGSON_2EF)
3057 return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
3058 else if (TARGET_LOONGSON_EXT)
3059 return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
3061 return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
3063 [(set_attr "type" "idiv3")
3064 (set_attr "mode" "<MODE>")])
3067 ;; ....................
3071 ;; ....................
3073 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
3074 ;; "*div[sd]f3" comment for details).
3076 (define_insn "sqrt<mode>2"
3077 [(set (match_operand:ANYF 0 "register_operand" "=f")
3078 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3082 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
3084 return "sqrt.<fmt>\t%0,%1";
3086 [(set_attr "type" "fsqrt")
3087 (set_attr "mode" "<UNITMODE>")
3088 (set (attr "insn_count")
3089 (if_then_else (match_test "TARGET_FIX_SB1")
3093 (define_insn "*rsqrt<mode>a"
3094 [(set (match_operand:ANYF 0 "register_operand" "=f")
3095 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3096 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
3097 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3100 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3102 return "rsqrt.<fmt>\t%0,%2";
3104 [(set_attr "type" "frsqrt")
3105 (set_attr "mode" "<UNITMODE>")
3106 (set (attr "insn_count")
3107 (if_then_else (match_test "TARGET_FIX_SB1")
3111 (define_insn "*rsqrt<mode>b"
3112 [(set (match_operand:ANYF 0 "register_operand" "=f")
3113 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3114 (match_operand:ANYF 2 "register_operand" "f"))))]
3115 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3118 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3120 return "rsqrt.<fmt>\t%0,%2";
3122 [(set_attr "type" "frsqrt")
3123 (set_attr "mode" "<UNITMODE>")
3124 (set (attr "insn_count")
3125 (if_then_else (match_test "TARGET_FIX_SB1")
3130 ;; ....................
3134 ;; ....................
3136 ;; Do not use the integer abs macro instruction, since that signals an
3137 ;; exception on -2147483648 (sigh).
3139 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
3140 ;; instruction that treats all NaN inputs as invalid; it does not clear
3141 ;; their sign bit. We therefore can't use that form if the signs of
3144 (define_insn "abs<mode>2"
3145 [(set (match_operand:ANYF 0 "register_operand" "=f")
3146 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3147 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3149 [(set_attr "type" "fabs")
3150 (set_attr "mode" "<UNITMODE>")])
3153 ;; ...................
3155 ;; Count leading zeroes.
3157 ;; ...................
3160 (define_insn "clz<mode>2"
3161 [(set (match_operand:GPR 0 "register_operand" "=d")
3162 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3165 [(set_attr "type" "clz")
3166 (set_attr "mode" "<MODE>")])
3169 ;; ...................
3171 ;; Count trailing zeroes.
3173 ;; ...................
3176 (define_insn "ctz<mode>2"
3177 [(set (match_operand:GPR 0 "register_operand" "=d")
3178 (ctz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3181 [(set_attr "type" "clz")
3182 (set_attr "mode" "<MODE>")])
3186 ;; ...................
3188 ;; Count number of set bits.
3190 ;; ...................
3193 (define_insn "popcount<mode>2"
3194 [(set (match_operand:GPR 0 "register_operand" "=d")
3195 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3198 [(set_attr "type" "pop")
3199 (set_attr "mode" "<MODE>")])
3201 ;; The POP instruction is special as it does not take into account the upper
3202 ;; 32bits and is documented that way.
3203 (define_insn "*popcountdi2_trunc"
3204 [(set (match_operand:SI 0 "register_operand" "=d")
3205 (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3206 "ISA_HAS_POP && TARGET_64BIT"
3208 [(set_attr "type" "pop")
3209 (set_attr "mode" "SI")])
3212 ;; ....................
3214 ;; NEGATION and ONE'S COMPLEMENT
3216 ;; ....................
3218 (define_insn "negsi2"
3219 [(set (match_operand:SI 0 "register_operand" "=d")
3220 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3224 return "neg\t%0,%1";
3226 return "subu\t%0,%.,%1";
3228 [(set_attr "alu_type" "sub")
3229 (set_attr "mode" "SI")])
3231 (define_insn "negdi2"
3232 [(set (match_operand:DI 0 "register_operand" "=d")
3233 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3234 "TARGET_64BIT && !TARGET_MIPS16"
3236 [(set_attr "alu_type" "sub")
3237 (set_attr "mode" "DI")])
3239 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3240 ;; instruction that treats all NaN inputs as invalid; it does not flip
3241 ;; their sign bit. We therefore can't use that form if the signs of
3244 (define_insn "neg<mode>2"
3245 [(set (match_operand:ANYF 0 "register_operand" "=f")
3246 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3247 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3249 [(set_attr "type" "fneg")
3250 (set_attr "mode" "<UNITMODE>")])
3252 (define_insn "one_cmpl<mode>2"
3253 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3254 (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3258 return "not\t%0,%1";
3260 return "nor\t%0,%.,%1";
3262 [(set_attr "alu_type" "not")
3263 (set_attr "compression" "micromips,*")
3264 (set_attr "mode" "<MODE>")])
3267 ;; ....................
3271 ;; ....................
3274 ;; Many of these instructions use trivial define_expands, because we
3275 ;; want to use a different set of constraints when TARGET_MIPS16.
3277 (define_expand "and<mode>3"
3278 [(set (match_operand:GPR 0 "register_operand")
3279 (and:GPR (match_operand:GPR 1 "register_operand")
3280 (match_operand:GPR 2 "and_reg_operand")))])
3282 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3283 ;; zero_extendsidi2 because of TARGET_TRULY_NOOP_TRUNCATION, so handle these
3284 ;; here. Note that this variant does not trigger for SI mode because we
3285 ;; require a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3286 ;; sign-extended SImode value.
3288 ;; These are possible combinations for operand 1 and 2. The table
3289 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
3290 ;; 16=MIPS16, x=match, S=split):
3292 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
3298 ;; 0xffff_ffff x S x S x
3303 (define_insn "*and<mode>3"
3304 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3305 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3306 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3307 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3311 switch (which_alternative)
3314 operands[1] = gen_lowpart (QImode, operands[1]);
3315 return "lbu\t%0,%1";
3317 operands[1] = gen_lowpart (HImode, operands[1]);
3318 return "lhu\t%0,%1";
3320 operands[1] = gen_lowpart (SImode, operands[1]);
3321 return "lwu\t%0,%1";
3324 return "andi\t%0,%1,%x2";
3326 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3327 operands[2] = GEN_INT (len);
3328 return "<d>ext\t%0,%1,0,%2";
3333 return "and\t%0,%1,%2";
3338 [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3339 (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3340 (set_attr "mode" "<MODE>")])
3342 (define_insn "*and<mode>3_mips16"
3343 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3344 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3345 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3346 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3348 switch (which_alternative)
3351 operands[1] = gen_lowpart (QImode, operands[1]);
3352 return "lbu\t%0,%1";
3354 operands[1] = gen_lowpart (HImode, operands[1]);
3355 return "lhu\t%0,%1";
3357 operands[1] = gen_lowpart (SImode, operands[1]);
3358 return "lwu\t%0,%1";
3362 return "and\t%0,%2";
3367 [(set_attr "move_type" "load,load,load,shift_shift,logical")
3368 (set_attr "mode" "<MODE>")])
3370 (define_expand "ior<mode>3"
3371 [(set (match_operand:GPR 0 "register_operand")
3372 (ior:GPR (match_operand:GPR 1 "register_operand")
3373 (match_operand:GPR 2 "uns_arith_operand")))]
3377 operands[2] = force_reg (<MODE>mode, operands[2]);
3380 (define_insn "*ior<mode>3"
3381 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3382 (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3383 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3389 [(set_attr "alu_type" "or")
3390 (set_attr "compression" "micromips,*,*")
3391 (set_attr "mode" "<MODE>")])
3393 (define_insn "*ior<mode>3_mips16"
3394 [(set (match_operand:GPR 0 "register_operand" "=d")
3395 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3396 (match_operand:GPR 2 "register_operand" "d")))]
3399 [(set_attr "alu_type" "or")
3400 (set_attr "mode" "<MODE>")])
3402 (define_expand "xor<mode>3"
3403 [(set (match_operand:GPR 0 "register_operand")
3404 (xor:GPR (match_operand:GPR 1 "register_operand")
3405 (match_operand:GPR 2 "uns_arith_operand")))]
3409 (define_insn "*xor<mode>3"
3410 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3411 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3412 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3418 [(set_attr "alu_type" "xor")
3419 (set_attr "compression" "micromips,*,*")
3420 (set_attr "mode" "<MODE>")])
3422 (define_insn "*xor<mode>3_mips16"
3423 [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3424 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3425 (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3432 [(set_attr "alu_type" "xor")
3433 (set_attr "mode" "<MODE>")
3434 (set_attr "extended_mips16" "no,no,yes,no")])
3436 (define_insn "*nor<mode>3"
3437 [(set (match_operand:GPR 0 "register_operand" "=d")
3438 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3439 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3442 [(set_attr "alu_type" "nor")
3443 (set_attr "mode" "<MODE>")])
3446 ;; ....................
3450 ;; ....................
3454 (define_insn "truncdfsf2"
3455 [(set (match_operand:SF 0 "register_operand" "=f")
3456 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3457 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3459 [(set_attr "type" "fcvt")
3460 (set_attr "cnv_mode" "D2S")
3461 (set_attr "mode" "SF")])
3463 ;; Integer truncation patterns. Truncating SImode values to smaller
3464 ;; modes is a no-op, as it is for most other GCC ports. Truncating
3465 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3466 ;; need to make sure that the lower 32 bits are properly sign-extended
3467 ;; (see TARGET_TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
3468 ;; smaller than SImode is equivalent to two separate truncations:
3471 ;; DI ---> HI == DI ---> SI ---> HI
3472 ;; DI ---> QI == DI ---> SI ---> QI
3474 ;; Step A needs a real instruction but step B does not.
3476 (define_insn "truncdi<mode>2"
3477 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3478 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3483 [(set_attr "move_type" "sll0,store")
3484 (set_attr "mode" "SI")])
3486 ;; Combiner patterns to optimize shift/truncate combinations.
3488 (define_insn "*ashr_trunc<mode>"
3489 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3491 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3492 (match_operand:DI 2 "const_arith_operand" ""))))]
3493 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3495 [(set_attr "type" "shift")
3496 (set_attr "mode" "<MODE>")])
3498 (define_insn "*lshr32_trunc<mode>"
3499 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3501 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3503 "TARGET_64BIT && !TARGET_MIPS16"
3505 [(set_attr "type" "shift")
3506 (set_attr "mode" "<MODE>")])
3508 ;; Logical shift by more than 32 results in proper SI values so truncation is
3509 ;; removed by the middle end. Note that a logical shift by 32 is handled by
3510 ;; the previous pattern.
3511 (define_insn "*<optab>_trunc<mode>_exts"
3512 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3514 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3515 (match_operand:DI 2 "const_arith_operand" ""))))]
3516 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3518 [(set_attr "type" "arith")
3519 (set_attr "mode" "<MODE>")])
3521 ;; This could likely be generalized for any SUBDI mode, and any right
3522 ;; shift, but AFAICT this is used so rarely it is not worth the additional
3525 [(set (match_operand:SI 0 "register_operand" "=d")
3528 (ashift:DI (match_operand:DI 1 "register_operand" "d")
3529 (match_operand:DI 2 "const_arith_operand" "")))
3530 (match_operand:DI 3 "const_arith_operand" "")))]
3531 "(ISA_HAS_EXTS && TARGET_64BIT
3532 && UINTVAL (operands[2]) < 32 && UINTVAL (operands[3]) < 32
3533 && UINTVAL (operands[3]) >= UINTVAL (operands[2]))"
3536 xoperands[0] = operands[0];
3537 xoperands[1] = operands[1];
3539 /* The length of the field is the size of the outer mode less the outer
3540 shift constant. We fix the outer mode as SImode for simplicity. */
3541 unsigned int right_shift = INTVAL (operands[3]);
3542 xoperands[3] = GEN_INT (32 - right_shift);
3544 /* The field starts at the outer shift constant less the inner shift
3546 unsigned int left_shift = INTVAL (operands[2]);
3547 xoperands[2] = GEN_INT (right_shift - left_shift);
3549 /* Sanity checks. These constraints are taken from the MIPS ISA
3551 gcc_assert (INTVAL (xoperands[2]) >= 0 && INTVAL (xoperands[2]) < 32);
3552 gcc_assert (INTVAL (xoperands[3]) > 0 && INTVAL (xoperands[3]) <= 32);
3553 gcc_assert (INTVAL (xoperands[2]) + INTVAL (xoperands[3]) > 0
3554 && INTVAL (xoperands[2]) + INTVAL (xoperands[3]) <= 32);
3556 output_asm_insn ("exts\t%0,%1,%2,%m3", xoperands);
3559 [(set_attr "type" "arith")
3560 (set_attr "mode" "SI")])
3563 ;; ....................
3567 ;; ....................
3571 (define_expand "zero_extendsidi2"
3572 [(set (match_operand:DI 0 "register_operand")
3573 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3576 (define_insn_and_split "*zero_extendsidi2"
3577 [(set (match_operand:DI 0 "register_operand" "=d,d")
3578 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3579 "TARGET_64BIT && !ISA_HAS_EXT_INS"
3583 "&& reload_completed && REG_P (operands[1])"
3585 (ashift:DI (match_dup 1) (const_int 32)))
3587 (lshiftrt:DI (match_dup 0) (const_int 32)))]
3588 { operands[1] = gen_lowpart (DImode, operands[1]); }
3589 [(set_attr "move_type" "shift_shift,load")
3590 (set_attr "mode" "DI")])
3592 (define_insn "*zero_extendsidi2_dext"
3593 [(set (match_operand:DI 0 "register_operand" "=d,d")
3594 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3595 "TARGET_64BIT && ISA_HAS_EXT_INS"
3599 [(set_attr "move_type" "arith,load")
3600 (set_attr "mode" "DI")])
3602 ;; See the comment before the *and<mode>3 pattern why this is generated by
3606 [(set (match_operand:DI 0 "register_operand")
3607 (and:DI (match_operand:DI 1 "register_operand")
3608 (const_int 4294967295)))]
3609 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3611 (ashift:DI (match_dup 1) (const_int 32)))
3613 (lshiftrt:DI (match_dup 0) (const_int 32)))])
3615 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3616 [(set (match_operand:GPR 0 "register_operand")
3617 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3620 if (TARGET_MIPS16 && !GENERATE_MIPS16E
3621 && !memory_operand (operands[1], <SHORT:MODE>mode))
3623 emit_insn (gen_and<GPR:mode>3 (operands[0],
3624 gen_lowpart (<GPR:MODE>mode, operands[1]),
3625 force_reg (<GPR:MODE>mode,
3626 GEN_INT (<SHORT:mask>))));
3631 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3632 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3634 (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3637 andi\t%0,%1,<SHORT:mask>
3638 andi\t%0,%1,<SHORT:mask>
3639 l<SHORT:size>u\t%0,%1"
3640 [(set_attr "move_type" "andi,andi,load")
3641 (set_attr "compression" "micromips,*,*")
3642 (set_attr "mode" "<GPR:MODE>")])
3644 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3645 [(set (match_operand:GPR 0 "register_operand" "=d")
3646 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3648 "ze<SHORT:size>\t%0"
3649 ;; This instruction is effectively a special encoding of ANDI.
3650 [(set_attr "move_type" "andi")
3651 (set_attr "mode" "<GPR:MODE>")])
3653 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3654 [(set (match_operand:GPR 0 "register_operand" "=d")
3655 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3657 "l<SHORT:size>u\t%0,%1"
3658 [(set_attr "move_type" "load")
3659 (set_attr "mode" "<GPR:MODE>")])
3661 (define_expand "zero_extendqihi2"
3662 [(set (match_operand:HI 0 "register_operand")
3663 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3666 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3668 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3674 (define_insn "*zero_extendqihi2"
3675 [(set (match_operand:HI 0 "register_operand" "=d,d")
3676 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3681 [(set_attr "move_type" "andi,load")
3682 (set_attr "mode" "HI")])
3684 (define_insn "*zero_extendqihi2_mips16"
3685 [(set (match_operand:HI 0 "register_operand" "=d")
3686 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3689 [(set_attr "move_type" "load")
3690 (set_attr "mode" "HI")])
3692 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3694 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3695 [(set (match_operand:GPR 0 "register_operand" "=d")
3697 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3698 "TARGET_64BIT && !TARGET_MIPS16"
3700 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3701 return "andi\t%0,%1,%x2";
3703 [(set_attr "alu_type" "and")
3704 (set_attr "mode" "<GPR:MODE>")])
3706 (define_insn "*zero_extendhi_truncqi"
3707 [(set (match_operand:HI 0 "register_operand" "=d")
3709 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3710 "TARGET_64BIT && !TARGET_MIPS16"
3712 [(set_attr "alu_type" "and")
3713 (set_attr "mode" "HI")])
3716 ;; ....................
3720 ;; ....................
3723 ;; Those for integer source operand are ordered widest source type first.
3725 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3726 ;; should already be in sign-extended form (see TARGET_TRULY_NOOP_TRUNCATION
3727 ;; and truncdisi2). We can therefore get rid of register->register
3728 ;; instructions if we constrain the source to be in the same register as
3731 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3732 ;; we split them into nothing before the post-reload scheduler runs.
3733 ;; These alternatives therefore have type "move" in order to reflect
3734 ;; what happens if the two pre-reload operands cannot be tied, and are
3735 ;; instead allocated two separate GPRs. We don't distinguish between
3736 ;; the GPR and LO cases because we don't usually know during pre-reload
3737 ;; scheduling whether an operand will be LO or not.
3738 (define_insn_and_split "extendsidi2"
3739 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3740 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3746 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3749 emit_note (NOTE_INSN_DELETED);
3752 [(set_attr "move_type" "move,move,load")
3753 (set_attr "mode" "DI")])
3755 (define_expand "extend<SHORT:mode><GPR:mode>2"
3756 [(set (match_operand:GPR 0 "register_operand")
3757 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3760 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3761 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3762 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3766 l<SHORT:size>\t%0,%1"
3767 [(set_attr "move_type" "signext,load")
3768 (set_attr "mode" "<GPR:MODE>")])
3770 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3771 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3773 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3774 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3777 l<SHORT:size>\t%0,%1"
3778 "&& reload_completed && REG_P (operands[1])"
3779 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3780 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3782 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3783 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3784 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3786 [(set_attr "move_type" "shift_shift,load")
3787 (set_attr "mode" "<GPR:MODE>")])
3789 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3790 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3792 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3795 se<SHORT:size>\t%0,%1
3796 l<SHORT:size>\t%0,%1"
3797 [(set_attr "move_type" "signext,load")
3798 (set_attr "mode" "<GPR:MODE>")])
3800 (define_expand "extendqihi2"
3801 [(set (match_operand:HI 0 "register_operand")
3802 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3805 (define_insn "*extendqihi2_mips16e"
3806 [(set (match_operand:HI 0 "register_operand" "=d,d")
3807 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3812 [(set_attr "move_type" "signext,load")
3813 (set_attr "mode" "SI")])
3815 (define_insn_and_split "*extendqihi2"
3816 [(set (match_operand:HI 0 "register_operand" "=d,d")
3818 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3819 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3823 "&& reload_completed && REG_P (operands[1])"
3824 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3825 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3827 operands[0] = gen_lowpart (SImode, operands[0]);
3828 operands[1] = gen_lowpart (SImode, operands[1]);
3829 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3830 - GET_MODE_BITSIZE (QImode));
3832 [(set_attr "move_type" "shift_shift,load")
3833 (set_attr "mode" "SI")])
3835 (define_insn "*extendqihi2_seb"
3836 [(set (match_operand:HI 0 "register_operand" "=d,d")
3838 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3843 [(set_attr "move_type" "signext,load")
3844 (set_attr "mode" "SI")])
3846 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3847 ;; use the shift/truncate patterns.
3849 (define_insn_and_split "*extenddi_truncate<mode>"
3850 [(set (match_operand:DI 0 "register_operand" "=d")
3852 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3853 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3855 "&& reload_completed"
3857 (ashift:DI (match_dup 1)
3860 (ashiftrt:DI (match_dup 2)
3863 operands[2] = gen_lowpart (DImode, operands[0]);
3864 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3866 [(set_attr "move_type" "shift_shift")
3867 (set_attr "mode" "DI")])
3869 (define_insn_and_split "*extendsi_truncate<mode>"
3870 [(set (match_operand:SI 0 "register_operand" "=d")
3872 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3873 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3875 "&& reload_completed"
3877 (ashift:DI (match_dup 1)
3880 (truncate:SI (ashiftrt:DI (match_dup 2)
3883 operands[2] = gen_lowpart (DImode, operands[0]);
3884 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3886 [(set_attr "move_type" "shift_shift")
3887 (set_attr "mode" "SI")])
3889 (define_insn_and_split "*extendhi_truncateqi"
3890 [(set (match_operand:HI 0 "register_operand" "=d")
3892 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3893 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3895 "&& reload_completed"
3897 (ashift:DI (match_dup 1)
3900 (truncate:HI (ashiftrt:DI (match_dup 2)
3903 operands[2] = gen_lowpart (DImode, operands[0]);
3905 [(set_attr "move_type" "shift_shift")
3906 (set_attr "mode" "SI")])
3908 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3909 [(set (match_operand:GPR 0 "register_operand" "=d")
3911 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3912 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3914 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3915 return "exts\t%0,%1,0,%m2";
3917 [(set_attr "type" "arith")
3918 (set_attr "mode" "<GPR:MODE>")])
3920 (define_insn "*extendhi_truncateqi_exts"
3921 [(set (match_operand:HI 0 "register_operand" "=d")
3923 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3924 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3926 [(set_attr "type" "arith")
3927 (set_attr "mode" "SI")])
3929 (define_insn "extendsfdf2"
3930 [(set (match_operand:DF 0 "register_operand" "=f")
3931 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3932 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3934 [(set_attr "type" "fcvt")
3935 (set_attr "cnv_mode" "S2D")
3936 (set_attr "mode" "DF")])
3939 ;; ....................
3943 ;; ....................
3945 (define_expand "fix_truncdfsi2"
3946 [(set (match_operand:SI 0 "register_operand")
3947 (fix:SI (match_operand:DF 1 "register_operand")))]
3948 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3950 if (!ISA_HAS_TRUNC_W)
3952 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3957 (define_insn "fix_truncdfsi2_insn"
3958 [(set (match_operand:SI 0 "register_operand" "=f")
3959 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3960 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3962 [(set_attr "type" "fcvt")
3963 (set_attr "mode" "DF")
3964 (set_attr "cnv_mode" "D2I")])
3966 (define_insn "fix_truncdfsi2_macro"
3967 [(set (match_operand:SI 0 "register_operand" "=f")
3968 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3969 (clobber (match_scratch:DF 2 "=d"))]
3970 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3972 if (mips_nomacro.nesting_level > 0)
3973 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3975 return "trunc.w.d %0,%1,%2";
3977 [(set_attr "type" "fcvt")
3978 (set_attr "mode" "DF")
3979 (set_attr "cnv_mode" "D2I")
3980 (set_attr "insn_count" "9")])
3982 (define_expand "fix_truncsfsi2"
3983 [(set (match_operand:SI 0 "register_operand")
3984 (fix:SI (match_operand:SF 1 "register_operand")))]
3987 if (!ISA_HAS_TRUNC_W)
3989 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3994 (define_insn "fix_truncsfsi2_insn"
3995 [(set (match_operand:SI 0 "register_operand" "=f")
3996 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3997 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3999 [(set_attr "type" "fcvt")
4000 (set_attr "mode" "SF")
4001 (set_attr "cnv_mode" "S2I")])
4003 (define_insn "fix_truncsfsi2_macro"
4004 [(set (match_operand:SI 0 "register_operand" "=f")
4005 (fix:SI (match_operand:SF 1 "register_operand" "f")))
4006 (clobber (match_scratch:SF 2 "=d"))]
4007 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
4009 if (mips_nomacro.nesting_level > 0)
4010 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
4012 return "trunc.w.s %0,%1,%2";
4014 [(set_attr "type" "fcvt")
4015 (set_attr "mode" "SF")
4016 (set_attr "cnv_mode" "S2I")
4017 (set_attr "insn_count" "9")])
4020 (define_insn "fix_truncdfdi2"
4021 [(set (match_operand:DI 0 "register_operand" "=f")
4022 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
4023 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4025 [(set_attr "type" "fcvt")
4026 (set_attr "mode" "DF")
4027 (set_attr "cnv_mode" "D2I")])
4030 (define_insn "fix_truncsfdi2"
4031 [(set (match_operand:DI 0 "register_operand" "=f")
4032 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
4033 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4035 [(set_attr "type" "fcvt")
4036 (set_attr "mode" "SF")
4037 (set_attr "cnv_mode" "S2I")])
4040 (define_insn "floatsidf2"
4041 [(set (match_operand:DF 0 "register_operand" "=f")
4042 (float:DF (match_operand:SI 1 "register_operand" "f")))]
4043 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4045 [(set_attr "type" "fcvt")
4046 (set_attr "mode" "DF")
4047 (set_attr "cnv_mode" "I2D")])
4050 (define_insn "floatdidf2"
4051 [(set (match_operand:DF 0 "register_operand" "=f")
4052 (float:DF (match_operand:DI 1 "register_operand" "f")))]
4053 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4055 [(set_attr "type" "fcvt")
4056 (set_attr "mode" "DF")
4057 (set_attr "cnv_mode" "I2D")])
4060 (define_insn "floatsisf2"
4061 [(set (match_operand:SF 0 "register_operand" "=f")
4062 (float:SF (match_operand:SI 1 "register_operand" "f")))]
4065 [(set_attr "type" "fcvt")
4066 (set_attr "mode" "SF")
4067 (set_attr "cnv_mode" "I2S")])
4070 (define_insn "floatdisf2"
4071 [(set (match_operand:SF 0 "register_operand" "=f")
4072 (float:SF (match_operand:DI 1 "register_operand" "f")))]
4073 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
4075 [(set_attr "type" "fcvt")
4076 (set_attr "mode" "SF")
4077 (set_attr "cnv_mode" "I2S")])
4080 (define_expand "fixuns_truncdfsi2"
4081 [(set (match_operand:SI 0 "register_operand")
4082 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
4083 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4085 rtx reg1 = gen_reg_rtx (DFmode);
4086 rtx reg2 = gen_reg_rtx (DFmode);
4087 rtx reg3 = gen_reg_rtx (SImode);
4088 rtx_code_label *label1 = gen_label_rtx ();
4089 rtx_code_label *label2 = gen_label_rtx ();
4091 REAL_VALUE_TYPE offset;
4093 real_2expN (&offset, 31, DFmode);
4095 if (reg1) /* Turn off complaints about unreached code. */
4097 mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4098 do_pending_stack_adjust ();
4100 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4101 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4103 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4104 emit_jump_insn (gen_rtx_SET (pc_rtx,
4105 gen_rtx_LABEL_REF (VOIDmode, label2)));
4108 emit_label (label1);
4109 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4110 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4111 (BITMASK_HIGH, SImode)));
4113 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4114 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4116 emit_label (label2);
4118 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4119 fields, and can't be used for REG_NOTES anyway). */
4120 emit_use (stack_pointer_rtx);
4126 (define_expand "fixuns_truncdfdi2"
4127 [(set (match_operand:DI 0 "register_operand")
4128 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
4129 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4131 rtx reg1 = gen_reg_rtx (DFmode);
4132 rtx reg2 = gen_reg_rtx (DFmode);
4133 rtx reg3 = gen_reg_rtx (DImode);
4134 rtx_code_label *label1 = gen_label_rtx ();
4135 rtx_code_label *label2 = gen_label_rtx ();
4137 REAL_VALUE_TYPE offset;
4139 real_2expN (&offset, 63, DFmode);
4141 mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4142 do_pending_stack_adjust ();
4144 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4145 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4147 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4148 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4151 emit_label (label1);
4152 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4153 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4154 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4156 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4157 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4159 emit_label (label2);
4161 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4162 fields, and can't be used for REG_NOTES anyway). */
4163 emit_use (stack_pointer_rtx);
4168 (define_expand "fixuns_truncsfsi2"
4169 [(set (match_operand:SI 0 "register_operand")
4170 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
4173 rtx reg1 = gen_reg_rtx (SFmode);
4174 rtx reg2 = gen_reg_rtx (SFmode);
4175 rtx reg3 = gen_reg_rtx (SImode);
4176 rtx_code_label *label1 = gen_label_rtx ();
4177 rtx_code_label *label2 = gen_label_rtx ();
4179 REAL_VALUE_TYPE offset;
4181 real_2expN (&offset, 31, SFmode);
4183 mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4184 do_pending_stack_adjust ();
4186 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4187 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4189 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4190 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4193 emit_label (label1);
4194 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4195 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4196 (BITMASK_HIGH, SImode)));
4198 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4199 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4201 emit_label (label2);
4203 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4204 fields, and can't be used for REG_NOTES anyway). */
4205 emit_use (stack_pointer_rtx);
4210 (define_expand "fixuns_truncsfdi2"
4211 [(set (match_operand:DI 0 "register_operand")
4212 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
4213 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4215 rtx reg1 = gen_reg_rtx (SFmode);
4216 rtx reg2 = gen_reg_rtx (SFmode);
4217 rtx reg3 = gen_reg_rtx (DImode);
4218 rtx_code_label *label1 = gen_label_rtx ();
4219 rtx_code_label *label2 = gen_label_rtx ();
4221 REAL_VALUE_TYPE offset;
4223 real_2expN (&offset, 63, SFmode);
4225 mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4226 do_pending_stack_adjust ();
4228 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4229 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4231 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4232 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4235 emit_label (label1);
4236 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4237 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4238 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4240 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4241 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4243 emit_label (label2);
4245 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4246 fields, and can't be used for REG_NOTES anyway). */
4247 emit_use (stack_pointer_rtx);
4252 ;; ....................
4256 ;; ....................
4258 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4260 (define_expand "extvmisalign<mode>"
4261 [(set (match_operand:GPR 0 "register_operand")
4262 (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4263 (match_operand 2 "const_int_operand")
4264 (match_operand 3 "const_int_operand")))]
4267 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4268 INTVAL (operands[2]),
4269 INTVAL (operands[3]),
4270 /*unsigned=*/ false))
4276 (define_expand "extv<mode>"
4277 [(set (match_operand:GPR 0 "register_operand")
4278 (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4279 (match_operand 2 "const_int_operand")
4280 (match_operand 3 "const_int_operand")))]
4283 if (UINTVAL (operands[2]) > 32)
4287 (define_insn "*extv<mode>"
4288 [(set (match_operand:GPR 0 "register_operand" "=d")
4289 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4290 (match_operand 2 "const_int_operand" "")
4291 (match_operand 3 "const_int_operand" "")))]
4292 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4293 "exts\t%0,%1,%3,%m2"
4294 [(set_attr "type" "arith")
4295 (set_attr "mode" "<MODE>")])
4297 (define_expand "extzvmisalign<mode>"
4298 [(set (match_operand:GPR 0 "register_operand")
4299 (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4300 (match_operand 2 "const_int_operand")
4301 (match_operand 3 "const_int_operand")))]
4304 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4305 INTVAL (operands[2]),
4306 INTVAL (operands[3]),
4307 /*unsigned=*/ true))
4313 (define_expand "extzv<mode>"
4314 [(set (match_operand:GPR 0 "register_operand")
4315 (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4316 (match_operand 2 "const_int_operand")
4317 (match_operand 3 "const_int_operand")))]
4320 if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4321 INTVAL (operands[3])))
4325 (define_insn "*extzv<mode>"
4326 [(set (match_operand:GPR 0 "register_operand" "=d")
4327 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4328 (match_operand 2 "const_int_operand" "")
4329 (match_operand 3 "const_int_operand" "")))]
4330 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4331 INTVAL (operands[3]))"
4332 "<d>ext\t%0,%1,%3,%2"
4333 [(set_attr "type" "arith")
4334 (set_attr "mode" "<MODE>")])
4336 (define_insn "*extzv_truncsi_exts"
4337 [(set (match_operand:SI 0 "register_operand" "=d")
4339 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4340 (match_operand 2 "const_int_operand" "")
4341 (match_operand 3 "const_int_operand" ""))))]
4342 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4344 [(set_attr "type" "arith")
4345 (set_attr "mode" "SI")])
4348 (define_expand "insvmisalign<mode>"
4349 [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4350 (match_operand 1 "const_int_operand")
4351 (match_operand 2 "const_int_operand"))
4352 (match_operand:GPR 3 "reg_or_0_operand"))]
4355 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4356 INTVAL (operands[1]),
4357 INTVAL (operands[2])))
4363 (define_expand "insv<mode>"
4364 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4365 (match_operand 1 "const_int_operand")
4366 (match_operand 2 "const_int_operand"))
4367 (match_operand:GPR 3 "reg_or_0_operand"))]
4370 if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4371 INTVAL (operands[2])))
4375 (define_insn "*insv<mode>"
4376 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4377 (match_operand:SI 1 "const_int_operand" "")
4378 (match_operand:SI 2 "const_int_operand" ""))
4379 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4380 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4381 INTVAL (operands[2]))"
4382 "<d>ins\t%0,%z3,%2,%1"
4383 [(set_attr "type" "arith")
4384 (set_attr "mode" "<MODE>")])
4386 ;; Combiner pattern for cins (clear and insert bit field). We can
4387 ;; implement mask-and-shift-left operation with this. Note that if
4388 ;; the upper bit of the mask is set in an SImode operation, the mask
4389 ;; itself will be sign-extended. mask_low_and_shift_len will
4390 ;; therefore be greater than our threshold of 32.
4392 (define_insn "*cins<mode>"
4393 [(set (match_operand:GPR 0 "register_operand" "=d")
4395 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4396 (match_operand:GPR 2 "const_int_operand" ""))
4397 (match_operand:GPR 3 "const_int_operand" "")))]
4399 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4402 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4403 return "cins\t%0,%1,%2,%m3";
4405 [(set_attr "type" "shift")
4406 (set_attr "mode" "<MODE>")])
4408 ;; Unaligned word moves generated by the bit field patterns.
4410 ;; As far as the rtl is concerned, both the left-part and right-part
4411 ;; instructions can access the whole field. However, the real operand
4412 ;; refers to just the first or the last byte (depending on endianness).
4413 ;; We therefore use two memory operands to each instruction, one to
4414 ;; describe the rtl effect and one to use in the assembly output.
4416 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4417 ;; This allows us to use the standard length calculations for the "load"
4418 ;; and "store" type attributes.
4420 (define_insn "mov_<load>l"
4421 [(set (match_operand:GPR 0 "register_operand" "=d")
4422 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4423 (match_operand:QI 2 "memory_operand" "ZC")]
4425 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4427 [(set_attr "move_type" "load")
4428 (set_attr "mode" "<MODE>")])
4430 (define_insn "mov_<load>r"
4431 [(set (match_operand:GPR 0 "register_operand" "=d")
4432 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4433 (match_operand:QI 2 "memory_operand" "ZC")
4434 (match_operand:GPR 3 "register_operand" "0")]
4435 UNSPEC_LOAD_RIGHT))]
4436 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4438 [(set_attr "move_type" "load")
4439 (set_attr "mode" "<MODE>")])
4441 (define_insn "mov_<store>l"
4442 [(set (match_operand:BLK 0 "memory_operand" "=m")
4443 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4444 (match_operand:QI 2 "memory_operand" "ZC")]
4445 UNSPEC_STORE_LEFT))]
4446 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4448 [(set_attr "move_type" "store")
4449 (set_attr "mode" "<MODE>")])
4451 (define_insn "mov_<store>r"
4452 [(set (match_operand:BLK 0 "memory_operand" "+m")
4453 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4454 (match_operand:QI 2 "memory_operand" "ZC")
4456 UNSPEC_STORE_RIGHT))]
4457 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4459 [(set_attr "move_type" "store")
4460 (set_attr "mode" "<MODE>")])
4462 ;; Unaligned direct access
4463 (define_expand "movmisalign<mode>"
4464 [(set (match_operand:JOIN_MODE 0)
4465 (match_operand:JOIN_MODE 1))]
4466 "ISA_HAS_UNALIGNED_ACCESS"
4468 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4472 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4473 ;; The required value is:
4475 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4477 ;; which translates to:
4479 ;; lui op0,%highest(op1)
4480 ;; daddiu op0,op0,%higher(op1)
4482 ;; daddiu op0,op0,%hi(op1)
4485 ;; The split is deferred until after flow2 to allow the peephole2 below
4487 (define_insn_and_split "*lea_high64"
4488 [(set (match_operand:DI 0 "register_operand" "=d")
4489 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4490 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4492 "&& epilogue_completed"
4493 [(set (match_dup 0) (high:DI (match_dup 2)))
4494 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4495 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4496 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4497 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4499 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4500 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4502 [(set_attr "insn_count" "5")])
4504 ;; Use a scratch register to reduce the latency of the above pattern
4505 ;; on superscalar machines. The optimized sequence is:
4507 ;; lui op1,%highest(op2)
4509 ;; daddiu op1,op1,%higher(op2)
4511 ;; daddu op1,op1,op0
4513 [(set (match_operand:DI 1 "d_operand")
4514 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4515 (match_scratch:DI 0 "d")]
4516 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4517 [(set (match_dup 1) (high:DI (match_dup 3)))
4518 (set (match_dup 0) (high:DI (match_dup 4)))
4519 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4520 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4521 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4523 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4524 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4527 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4528 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
4529 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4530 ;; used once. We can then use the sequence:
4532 ;; lui op0,%highest(op1)
4534 ;; daddiu op0,op0,%higher(op1)
4535 ;; daddiu op2,op2,%lo(op1)
4537 ;; daddu op0,op0,op2
4539 ;; which takes 4 cycles on most superscalar targets.
4540 (define_insn_and_split "*lea64"
4541 [(set (match_operand:DI 0 "register_operand" "=d")
4542 (match_operand:DI 1 "absolute_symbolic_operand" ""))
4543 (clobber (match_scratch:DI 2 "=&d"))]
4545 && TARGET_EXPLICIT_RELOCS
4546 && ABI_HAS_64BIT_SYMBOLS
4547 && cse_not_expected"
4549 "&& reload_completed"
4550 [(set (match_dup 0) (high:DI (match_dup 3)))
4551 (set (match_dup 2) (high:DI (match_dup 4)))
4552 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4553 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4554 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4555 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4557 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4558 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4560 [(set_attr "insn_count" "6")])
4562 ;; Split HIGHs into:
4567 ;; on MIPS16 targets.
4569 [(set (match_operand:P 0 "d_operand")
4570 (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4571 "TARGET_MIPS16 && reload_completed"
4572 [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4573 (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4575 (define_insn "*unshifted_high"
4576 [(set (match_operand:P 0 "d_operand" "=d")
4577 (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4578 UNSPEC_UNSHIFTED_HIGH))]
4581 [(set_attr "extended_mips16" "yes")])
4583 ;; Insns to fetch a symbol from a big GOT.
4585 (define_insn_and_split "*xgot_hi<mode>"
4586 [(set (match_operand:P 0 "register_operand" "=d")
4587 (high:P (match_operand:P 1 "got_disp_operand" "")))]
4588 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4590 "&& reload_completed"
4591 [(set (match_dup 0) (high:P (match_dup 2)))
4592 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4594 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4595 operands[3] = pic_offset_table_rtx;
4597 [(set_attr "got" "xgot_high")
4598 (set_attr "mode" "<MODE>")])
4600 (define_insn_and_split "*xgot_lo<mode>"
4601 [(set (match_operand:P 0 "register_operand" "=d")
4602 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4603 (match_operand:P 2 "got_disp_operand" "")))]
4604 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4606 "&& reload_completed"
4608 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4609 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4610 [(set_attr "got" "load")
4611 (set_attr "mode" "<MODE>")])
4613 ;; Insns to fetch a symbol from a normal GOT.
4615 (define_insn_and_split "*got_disp<mode>"
4616 [(set (match_operand:P 0 "register_operand" "=d")
4617 (match_operand:P 1 "got_disp_operand" ""))]
4618 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4620 "&& reload_completed"
4621 [(set (match_dup 0) (match_dup 2))]
4622 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4623 [(set_attr "got" "load")
4624 (set_attr "mode" "<MODE>")])
4626 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4628 (define_insn_and_split "*got_page<mode>"
4629 [(set (match_operand:P 0 "register_operand" "=d")
4630 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4631 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4633 "&& reload_completed"
4634 [(set (match_dup 0) (match_dup 2))]
4635 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4636 [(set_attr "got" "load")
4637 (set_attr "mode" "<MODE>")])
4639 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4640 (define_expand "unspec_got_<mode>"
4641 [(unspec:P [(match_operand:P 0)
4642 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4644 ;; Lower-level instructions for loading an address from the GOT.
4645 ;; We could use MEMs, but an unspec gives more optimization
4648 (define_insn "load_got<mode>"
4649 [(set (match_operand:P 0 "register_operand" "=d")
4650 (unspec:P [(match_operand:P 1 "register_operand" "d")
4651 (match_operand:P 2 "immediate_operand" "")]
4654 "<load>\t%0,%R2(%1)"
4655 [(set_attr "got" "load")
4656 (set_attr "mode" "<MODE>")])
4658 ;; Instructions for adding the low 16 bits of an address to a register.
4659 ;; Operand 2 is the address: mips_print_operand works out which relocation
4660 ;; should be applied.
4662 (define_insn "*low<mode>"
4663 [(set (match_operand:P 0 "register_operand" "=d")
4664 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4665 (match_operand:P 2 "immediate_operand" "")))]
4667 "<d>addiu\t%0,%1,%R2"
4668 [(set_attr "alu_type" "add")
4669 (set_attr "mode" "<MODE>")])
4671 (define_insn "*low<mode>_mips16"
4672 [(set (match_operand:P 0 "register_operand" "=d")
4673 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4674 (match_operand:P 2 "immediate_operand" "")))]
4677 [(set_attr "alu_type" "add")
4678 (set_attr "mode" "<MODE>")
4679 (set_attr "extended_mips16" "yes")])
4681 ;; Expose MIPS16 uses of the global pointer after reload if the function
4682 ;; is responsible for setting up the register itself.
4684 [(set (match_operand:GPR 0 "d_operand")
4685 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4686 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4687 [(set (match_dup 0) (match_dup 1))]
4688 { operands[1] = pic_offset_table_rtx; })
4690 ;; Allow combine to split complex const_int load sequences, using operand 2
4691 ;; to store the intermediate results. See move_operand for details.
4693 [(set (match_operand:GPR 0 "register_operand")
4694 (match_operand:GPR 1 "splittable_const_int_operand"))
4695 (clobber (match_operand:GPR 2 "register_operand"))]
4699 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4703 ;; Likewise, for symbolic operands.
4705 [(set (match_operand:P 0 "register_operand")
4706 (match_operand:P 1))
4707 (clobber (match_operand:P 2 "register_operand"))]
4708 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4709 [(set (match_dup 0) (match_dup 3))]
4711 mips_split_symbol (operands[2], operands[1],
4712 MAX_MACHINE_MODE, &operands[3]);
4715 ;; 64-bit integer moves
4717 ;; Unlike most other insns, the move insns can't be split with
4718 ;; different predicates, because register spilling and other parts of
4719 ;; the compiler, have memoized the insn number already.
4721 (define_expand "movdi"
4722 [(set (match_operand:DI 0 "")
4723 (match_operand:DI 1 ""))]
4726 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4730 ;; For mips16, we need a special case to handle storing $31 into
4731 ;; memory, since we don't have a constraint to match $31. This
4732 ;; instruction can be generated by save_restore_insns.
4734 (define_insn "*mov<mode>_ra"
4735 [(set (match_operand:GPR 0 "stack_operand" "=m")
4736 (reg:GPR RETURN_ADDR_REGNUM))]
4739 [(set_attr "move_type" "store")
4740 (set_attr "mode" "<MODE>")])
4742 (define_insn "*movdi_32bit"
4743 [(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")
4744 (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"))]
4745 "!TARGET_64BIT && !TARGET_MIPS16
4746 && (register_operand (operands[0], DImode)
4747 || reg_or_0_operand (operands[1], DImode))"
4748 { return mips_output_move (operands[0], operands[1]); }
4749 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4751 (if_then_else (eq_attr "move_type" "imul")
4753 (const_string "DI")))])
4755 (define_insn "*movdi_32bit_mips16"
4756 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4757 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4758 "!TARGET_64BIT && TARGET_MIPS16
4759 && (register_operand (operands[0], DImode)
4760 || register_operand (operands[1], DImode))"
4761 { return mips_output_move (operands[0], operands[1]); }
4762 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4763 (set_attr "mode" "DI")])
4765 (define_insn "*movdi_64bit"
4766 [(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")
4767 (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"))]
4768 "TARGET_64BIT && !TARGET_MIPS16
4769 && (register_operand (operands[0], DImode)
4770 || reg_or_0_operand (operands[1], DImode))"
4771 { return mips_output_move (operands[0], operands[1]); }
4772 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4773 (set_attr "mode" "DI")])
4775 (define_insn "*movdi_64bit_mips16"
4776 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4777 (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4778 "TARGET_64BIT && TARGET_MIPS16
4779 && (register_operand (operands[0], DImode)
4780 || register_operand (operands[1], DImode))"
4781 { return mips_output_move (operands[0], operands[1]); }
4782 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4783 (set_attr "mode" "DI")])
4785 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4786 ;; when the original load is a 4 byte instruction but the add and the
4787 ;; load are 2 2 byte instructions.
4790 [(set (match_operand:DI 0 "d_operand")
4791 (mem:DI (plus:DI (match_dup 0)
4792 (match_operand:DI 1 "const_int_operand"))))]
4793 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4794 && !TARGET_DEBUG_D_MODE
4795 && ((INTVAL (operands[1]) < 0
4796 && INTVAL (operands[1]) >= -0x10)
4797 || (INTVAL (operands[1]) >= 32 * 8
4798 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4799 || (INTVAL (operands[1]) >= 0
4800 && INTVAL (operands[1]) < 32 * 8
4801 && (INTVAL (operands[1]) & 7) != 0))"
4802 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4803 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4805 HOST_WIDE_INT val = INTVAL (operands[1]);
4808 operands[2] = const0_rtx;
4809 else if (val >= 32 * 8)
4813 operands[1] = GEN_INT (0x8 + off);
4814 operands[2] = GEN_INT (val - off - 0x8);
4820 operands[1] = GEN_INT (off);
4821 operands[2] = GEN_INT (val - off);
4825 ;; 32-bit Integer moves
4827 ;; Unlike most other insns, the move insns can't be split with
4828 ;; different predicates, because register spilling and other parts of
4829 ;; the compiler, have memoized the insn number already.
4831 (define_expand "mov<mode>"
4832 [(set (match_operand:IMOVE32 0 "")
4833 (match_operand:IMOVE32 1 ""))]
4836 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4840 ;; The difference between these two is whether or not ints are allowed
4841 ;; in FP registers (off by default, use -mdebugh to enable).
4843 (define_insn "*mov<mode>_internal"
4844 [(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")
4845 (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!kbJ,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4847 && (register_operand (operands[0], <MODE>mode)
4848 || reg_or_0_operand (operands[1], <MODE>mode))"
4849 { return mips_output_move (operands[0], operands[1]); }
4850 [(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")
4851 (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4852 (set_attr "mode" "SI")])
4854 (define_insn "*mov<mode>_mips16"
4855 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4856 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4858 && (register_operand (operands[0], <MODE>mode)
4859 || register_operand (operands[1], <MODE>mode))"
4860 { return mips_output_move (operands[0], operands[1]); }
4861 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4862 (set_attr "mode" "SI")])
4864 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4865 ;; when the original load is a 4 byte instruction but the add and the
4866 ;; load are 2 2 byte instructions.
4869 [(set (match_operand:SI 0 "d_operand")
4870 (mem:SI (plus:SI (match_dup 0)
4871 (match_operand:SI 1 "const_int_operand"))))]
4872 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4873 && ((INTVAL (operands[1]) < 0
4874 && INTVAL (operands[1]) >= -0x80)
4875 || (INTVAL (operands[1]) >= 32 * 4
4876 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4877 || (INTVAL (operands[1]) >= 0
4878 && INTVAL (operands[1]) < 32 * 4
4879 && (INTVAL (operands[1]) & 3) != 0))"
4880 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4881 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4883 HOST_WIDE_INT val = INTVAL (operands[1]);
4886 operands[2] = const0_rtx;
4887 else if (val >= 32 * 4)
4891 operands[1] = GEN_INT (0x7c + off);
4892 operands[2] = GEN_INT (val - off - 0x7c);
4898 operands[1] = GEN_INT (off);
4899 operands[2] = GEN_INT (val - off);
4903 ;; On the mips16, we can split a load of certain constants into a load
4904 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4908 [(set (match_operand:SI 0 "d_operand")
4909 (match_operand:SI 1 "const_int_operand"))]
4910 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4911 && INTVAL (operands[1]) >= 0x100
4912 && INTVAL (operands[1]) <= 0xff + 0x7f"
4913 [(set (match_dup 0) (match_dup 1))
4914 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4916 int val = INTVAL (operands[1]);
4918 operands[1] = GEN_INT (0xff);
4919 operands[2] = GEN_INT (val - 0xff);
4922 ;; MIPS4 supports loading and storing a floating point register from
4923 ;; the sum of two general registers. We use two versions for each of
4924 ;; these four instructions: one where the two general registers are
4925 ;; SImode, and one where they are DImode. This is because general
4926 ;; registers will be in SImode when they hold 32-bit values, but,
4927 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4928 ;; instructions will still work correctly.
4930 ;; ??? Perhaps it would be better to support these instructions by
4931 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4932 ;; these instructions can only be used to load and store floating
4933 ;; point registers, that would probably cause trouble in reload.
4935 (define_insn "*<ANYF:loadx>_<P:mode>"
4936 [(set (match_operand:ANYF 0 "register_operand" "=f")
4937 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4938 (match_operand:P 2 "register_operand" "d"))))]
4940 "<ANYF:loadx>\t%0,%1(%2)"
4941 [(set_attr "type" "fpidxload")
4942 (set_attr "mode" "<ANYF:UNITMODE>")])
4944 (define_insn "*<ANYF:storex>_<P:mode>"
4945 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4946 (match_operand:P 2 "register_operand" "d")))
4947 (match_operand:ANYF 0 "register_operand" "f"))]
4949 "<ANYF:storex>\t%0,%1(%2)"
4950 [(set_attr "type" "fpidxstore")
4951 (set_attr "mode" "<ANYF:UNITMODE>")])
4953 ;; Scaled indexed address load.
4954 ;; Per md.texi, we only need to look for a pattern with multiply in the
4955 ;; address expression, not shift.
4957 (define_insn "*lwxs"
4958 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4960 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4962 (match_operand:P 2 "register_operand" "d"))))]
4965 [(set_attr "type" "load")
4966 (set_attr "mode" "SI")])
4968 ;; 16-bit Integer moves
4970 ;; Unlike most other insns, the move insns can't be split with
4971 ;; different predicates, because register spilling and other parts of
4972 ;; the compiler, have memoized the insn number already.
4973 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4975 (define_expand "movhi"
4976 [(set (match_operand:HI 0 "")
4977 (match_operand:HI 1 ""))]
4980 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4984 (define_insn "*movhi_internal"
4985 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4986 (match_operand:HI 1 "move_operand" "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4988 && (register_operand (operands[0], HImode)
4989 || reg_or_0_operand (operands[1], HImode))"
4990 { return mips_output_move (operands[0], operands[1]); }
4991 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4992 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4993 (set_attr "mode" "HI")])
4995 (define_insn "*movhi_mips16"
4996 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4997 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4999 && (register_operand (operands[0], HImode)
5000 || register_operand (operands[1], HImode))"
5001 { return mips_output_move (operands[0], operands[1]); }
5002 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5003 (set_attr "mode" "HI")])
5005 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
5006 ;; when the original load is a 4 byte instruction but the add and the
5007 ;; load are 2 2 byte instructions.
5010 [(set (match_operand:HI 0 "d_operand")
5011 (mem:HI (plus:SI (match_dup 0)
5012 (match_operand:SI 1 "const_int_operand"))))]
5013 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5014 && ((INTVAL (operands[1]) < 0
5015 && INTVAL (operands[1]) >= -0x80)
5016 || (INTVAL (operands[1]) >= 32 * 2
5017 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
5018 || (INTVAL (operands[1]) >= 0
5019 && INTVAL (operands[1]) < 32 * 2
5020 && (INTVAL (operands[1]) & 1) != 0))"
5021 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5022 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
5024 HOST_WIDE_INT val = INTVAL (operands[1]);
5027 operands[2] = const0_rtx;
5028 else if (val >= 32 * 2)
5032 operands[1] = GEN_INT (0x7e + off);
5033 operands[2] = GEN_INT (val - off - 0x7e);
5039 operands[1] = GEN_INT (off);
5040 operands[2] = GEN_INT (val - off);
5044 ;; 8-bit Integer moves
5046 ;; Unlike most other insns, the move insns can't be split with
5047 ;; different predicates, because register spilling and other parts of
5048 ;; the compiler, have memoized the insn number already.
5049 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
5051 (define_expand "movqi"
5052 [(set (match_operand:QI 0 "")
5053 (match_operand:QI 1 ""))]
5056 if (mips_legitimize_move (QImode, operands[0], operands[1]))
5060 (define_insn "*movqi_internal"
5061 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
5062 (match_operand:QI 1 "move_operand" "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
5064 && (register_operand (operands[0], QImode)
5065 || reg_or_0_operand (operands[1], QImode))"
5066 { return mips_output_move (operands[0], operands[1]); }
5067 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
5068 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
5069 (set_attr "mode" "QI")])
5071 (define_insn "*movqi_mips16"
5072 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5073 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5075 && (register_operand (operands[0], QImode)
5076 || register_operand (operands[1], QImode))"
5077 { return mips_output_move (operands[0], operands[1]); }
5078 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5079 (set_attr "mode" "QI")])
5081 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
5082 ;; when the original load is a 4 byte instruction but the add and the
5083 ;; load are 2 2 byte instructions.
5086 [(set (match_operand:QI 0 "d_operand")
5087 (mem:QI (plus:SI (match_dup 0)
5088 (match_operand:SI 1 "const_int_operand"))))]
5089 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5090 && ((INTVAL (operands[1]) < 0
5091 && INTVAL (operands[1]) >= -0x80)
5092 || (INTVAL (operands[1]) >= 32
5093 && INTVAL (operands[1]) <= 31 + 0x7f))"
5094 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5095 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
5097 HOST_WIDE_INT val = INTVAL (operands[1]);
5100 operands[2] = const0_rtx;
5103 operands[1] = GEN_INT (0x7f);
5104 operands[2] = GEN_INT (val - 0x7f);
5108 ;; 32-bit floating point moves
5110 (define_expand "movsf"
5111 [(set (match_operand:SF 0 "")
5112 (match_operand:SF 1 ""))]
5115 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
5119 (define_insn "movccf"
5120 [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
5121 (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
5123 { return mips_output_move (operands[0], operands[1]); }
5124 [(set_attr "move_type" "fmove,fpload,fpstore")])
5126 (define_insn "*movsf_hardfloat"
5127 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5128 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
5130 && (register_operand (operands[0], SFmode)
5131 || reg_or_0_operand (operands[1], SFmode))"
5132 { return mips_output_move (operands[0], operands[1]); }
5133 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5134 (set_attr "mode" "SF")])
5136 (define_insn "*movsf_softfloat"
5137 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
5138 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
5139 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
5140 && (register_operand (operands[0], SFmode)
5141 || reg_or_0_operand (operands[1], SFmode))"
5142 { return mips_output_move (operands[0], operands[1]); }
5143 [(set_attr "move_type" "move,load,store")
5144 (set_attr "mode" "SF")])
5146 (define_insn "*movsf_mips16"
5147 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
5148 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
5150 && (register_operand (operands[0], SFmode)
5151 || register_operand (operands[1], SFmode))"
5152 { return mips_output_move (operands[0], operands[1]); }
5153 [(set_attr "move_type" "move,move,move,load,store")
5154 (set_attr "mode" "SF")])
5156 ;; 64-bit floating point moves
5158 (define_expand "movdf"
5159 [(set (match_operand:DF 0 "")
5160 (match_operand:DF 1 ""))]
5163 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
5167 (define_insn "*movdf_hardfloat"
5168 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5169 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
5170 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
5171 && (register_operand (operands[0], DFmode)
5172 || reg_or_0_operand (operands[1], DFmode))"
5173 { return mips_output_move (operands[0], operands[1]); }
5174 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5175 (set_attr "mode" "DF")])
5177 (define_insn "*movdf_softfloat"
5178 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
5179 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
5180 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
5181 && (register_operand (operands[0], DFmode)
5182 || reg_or_0_operand (operands[1], DFmode))"
5183 { return mips_output_move (operands[0], operands[1]); }
5184 [(set_attr "move_type" "move,load,store")
5185 (set_attr "mode" "DF")])
5187 (define_insn "*movdf_mips16"
5188 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
5189 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
5191 && (register_operand (operands[0], DFmode)
5192 || register_operand (operands[1], DFmode))"
5193 { return mips_output_move (operands[0], operands[1]); }
5194 [(set_attr "move_type" "move,move,move,load,store")
5195 (set_attr "mode" "DF")])
5197 ;; 128-bit integer moves
5199 (define_expand "movti"
5200 [(set (match_operand:TI 0)
5201 (match_operand:TI 1))]
5204 if (mips_legitimize_move (TImode, operands[0], operands[1]))
5208 (define_insn "*movti"
5209 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
5210 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
5213 && (register_operand (operands[0], TImode)
5214 || reg_or_0_operand (operands[1], TImode))"
5215 { return mips_output_move (operands[0], operands[1]); }
5216 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
5218 (if_then_else (eq_attr "move_type" "imul")
5220 (const_string "TI")))])
5222 (define_insn "*movti_mips16"
5223 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5224 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5227 && (register_operand (operands[0], TImode)
5228 || register_operand (operands[1], TImode))"
5230 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5231 (set_attr "mode" "TI")])
5233 ;; 128-bit floating point moves
5235 (define_expand "movtf"
5236 [(set (match_operand:TF 0)
5237 (match_operand:TF 1))]
5240 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5244 ;; This pattern handles both hard- and soft-float cases.
5245 (define_insn "*movtf"
5246 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5247 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5250 && (register_operand (operands[0], TFmode)
5251 || reg_or_0_operand (operands[1], TFmode))"
5253 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5254 (set_attr "mode" "TF")])
5256 (define_insn "*movtf_mips16"
5257 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5258 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5261 && (register_operand (operands[0], TFmode)
5262 || register_operand (operands[1], TFmode))"
5264 [(set_attr "move_type" "move,move,move,load,store")
5265 (set_attr "mode" "TF")])
5268 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5269 (match_operand:MOVE64 1 "move_operand"))]
5270 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5273 mips_split_move_insn (operands[0], operands[1], curr_insn);
5278 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5279 (match_operand:MOVE128 1 "move_operand"))]
5280 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5283 mips_split_move_insn (operands[0], operands[1], curr_insn);
5287 ;; When generating mips16 code, split moves of negative constants into
5288 ;; a positive "li" followed by a negation.
5290 [(set (match_operand 0 "d_operand")
5291 (match_operand 1 "const_int_operand"))]
5292 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5296 (neg:SI (match_dup 2)))]
5298 operands[2] = gen_lowpart (SImode, operands[0]);
5299 operands[3] = GEN_INT (-INTVAL (operands[1]));
5302 ;; 64-bit paired-single floating point moves
5304 (define_expand "movv2sf"
5305 [(set (match_operand:V2SF 0)
5306 (match_operand:V2SF 1))]
5307 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5309 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5313 (define_insn "*movv2sf"
5314 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5315 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5317 && TARGET_PAIRED_SINGLE_FLOAT
5318 && (register_operand (operands[0], V2SFmode)
5319 || reg_or_0_operand (operands[1], V2SFmode))"
5320 { return mips_output_move (operands[0], operands[1]); }
5321 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5322 (set_attr "mode" "DF")])
5324 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
5325 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5327 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5328 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
5329 ;; and the errata related to -mfix-vr4130.
5330 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5331 [(set (match_operand:GPR 0 "register_operand" "=d")
5332 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5335 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5336 [(set_attr "type" "mfhi")
5337 (set_attr "mode" "<GPR:MODE>")])
5339 ;; Set the high part of a HI/LO value, given that the low part has
5340 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
5341 ;; why we can't just use (reg:GPR HI_REGNUM).
5342 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5343 [(set (match_operand:HILO 0 "register_operand" "=x")
5344 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5345 (match_operand:GPR 2 "register_operand" "l")]
5349 [(set_attr "type" "mthi")
5350 (set_attr "mode" "SI")])
5352 ;; Emit a doubleword move in which exactly one of the operands is
5353 ;; a floating-point register. We can't just emit two normal moves
5354 ;; because of the constraints imposed by the FPU register model;
5355 ;; see mips_cannot_change_mode_class for details. Instead, we keep
5356 ;; the FPR whole and use special patterns to refer to each word of
5357 ;; the other operand.
5359 (define_expand "move_doubleword_fpr<mode>"
5360 [(set (match_operand:SPLITF 0)
5361 (match_operand:SPLITF 1))]
5364 if (FP_REG_RTX_P (operands[0]))
5366 rtx low = mips_subword (operands[1], 0);
5367 rtx high = mips_subword (operands[1], 1);
5368 emit_insn (gen_load_low<mode> (operands[0], low));
5369 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5370 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5372 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5376 rtx low = mips_subword (operands[0], 0);
5377 rtx high = mips_subword (operands[0], 1);
5378 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5379 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5380 emit_insn (gen_mfhc1<mode> (high, operands[1]));
5382 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5387 ;; Load the low word of operand 0 with operand 1.
5388 (define_insn "load_low<mode>"
5389 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5390 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5394 operands[0] = mips_subword (operands[0], 0);
5395 return mips_output_move (operands[0], operands[1]);
5397 [(set_attr "move_type" "mtc,fpload")
5398 (set_attr "mode" "<HALFMODE>")])
5400 ;; Load the high word of operand 0 from operand 1, preserving the value
5402 (define_insn "load_high<mode>"
5403 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5404 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5405 (match_operand:SPLITF 2 "register_operand" "0,0")]
5409 operands[0] = mips_subword (operands[0], 1);
5410 return mips_output_move (operands[0], operands[1]);
5412 [(set_attr "move_type" "mtc,fpload")
5413 (set_attr "mode" "<HALFMODE>")])
5415 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
5416 ;; high word and 0 to store the low word.
5417 (define_insn "store_word<mode>"
5418 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5419 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5420 (match_operand 2 "const_int_operand")]
5421 UNSPEC_STORE_WORD))]
5424 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5425 return mips_output_move (operands[0], operands[1]);
5427 [(set_attr "move_type" "mfc,fpstore")
5428 (set_attr "mode" "<HALFMODE>")])
5430 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5431 ;; value in the low word.
5432 (define_insn "mthc1<mode>"
5433 [(set (match_operand:SPLITF 0 "register_operand" "=f")
5434 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5435 (match_operand:SPLITF 2 "register_operand" "0")]
5437 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5439 [(set_attr "move_type" "mtc")
5440 (set_attr "mode" "<HALFMODE>")])
5442 ;; Move high word of operand 1 to operand 0 using mfhc1.
5443 (define_insn "mfhc1<mode>"
5444 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5445 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5447 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5449 [(set_attr "move_type" "mfc")
5450 (set_attr "mode" "<HALFMODE>")])
5452 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5453 (define_expand "load_const_gp_<mode>"
5454 [(set (match_operand:P 0 "register_operand" "=d")
5455 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5457 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
5458 ;; of _gp from the start of this function. Operand 1 is the incoming
5459 ;; function address.
5460 (define_insn_and_split "loadgp_newabi_<mode>"
5461 [(set (match_operand:P 0 "register_operand" "=&d")
5462 (unspec:P [(match_operand:P 1)
5463 (match_operand:P 2 "register_operand" "d")]
5465 "mips_current_loadgp_style () == LOADGP_NEWABI"
5466 { return mips_must_initialize_gp_p () ? "#" : ""; }
5467 "&& mips_must_initialize_gp_p ()"
5468 [(set (match_dup 0) (match_dup 3))
5469 (set (match_dup 0) (match_dup 4))
5470 (set (match_dup 0) (match_dup 5))]
5472 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5473 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5474 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5476 [(set_attr "type" "ghost")])
5478 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
5479 (define_insn_and_split "loadgp_absolute_<mode>"
5480 [(set (match_operand:P 0 "register_operand" "=d")
5481 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5482 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5483 { return mips_must_initialize_gp_p () ? "#" : ""; }
5484 "&& mips_must_initialize_gp_p ()"
5487 mips_emit_move (operands[0], operands[1]);
5490 [(set_attr "type" "ghost")])
5492 ;; This blockage instruction prevents the gp load from being
5493 ;; scheduled after an implicit use of gp. It also prevents
5494 ;; the load from being deleted as dead.
5495 (define_insn "loadgp_blockage"
5496 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5499 [(set_attr "type" "ghost")])
5501 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
5502 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5503 (define_insn_and_split "loadgp_rtp_<mode>"
5504 [(set (match_operand:P 0 "register_operand" "=d")
5505 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5506 (match_operand:P 2 "symbol_ref_operand")]
5508 "mips_current_loadgp_style () == LOADGP_RTP"
5509 { return mips_must_initialize_gp_p () ? "#" : ""; }
5510 "&& mips_must_initialize_gp_p ()"
5511 [(set (match_dup 0) (high:P (match_dup 3)))
5512 (set (match_dup 0) (unspec:P [(match_dup 0)
5513 (match_dup 3)] UNSPEC_LOAD_GOT))
5514 (set (match_dup 0) (unspec:P [(match_dup 0)
5515 (match_dup 4)] UNSPEC_LOAD_GOT))]
5517 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5518 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5520 [(set_attr "type" "ghost")])
5522 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
5523 ;; global pointer and operand 1 is the MIPS16 register that holds
5524 ;; the required value.
5525 (define_insn_and_split "copygp_mips16_<mode>"
5526 [(set (match_operand:P 0 "register_operand" "=y")
5527 (unspec:P [(match_operand:P 1 "register_operand" "d")]
5530 { return mips_must_initialize_gp_p () ? "#" : ""; }
5531 "&& mips_must_initialize_gp_p ()"
5532 [(set (match_dup 0) (match_dup 1))]
5534 [(set_attr "type" "ghost")])
5536 ;; A placeholder for where the cprestore instruction should go,
5537 ;; if we decide we need one. Operand 0 and operand 1 are as for
5538 ;; "cprestore". Operand 2 is a register that holds the gp value.
5540 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5541 ;; otherwise any register that holds the correct value will do.
5542 (define_insn_and_split "potential_cprestore_<mode>"
5543 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5544 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5545 (match_operand:P 2 "register_operand" "d,d")]
5546 UNSPEC_POTENTIAL_CPRESTORE))
5547 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5548 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5549 { return mips_must_initialize_gp_p () ? "#" : ""; }
5550 "mips_must_initialize_gp_p ()"
5553 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5554 operands[2], operands[3]);
5557 [(set_attr "type" "ghost")])
5559 ;; Emit a .cprestore directive, which normally expands to a single store
5560 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
5561 ;; for the cprestore slot. Operand 1 is the offset of the slot from
5562 ;; the stack pointer. (This is redundant with operand 0, but it makes
5563 ;; things a little simpler.)
5564 (define_insn "cprestore_<mode>"
5565 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5566 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5569 "TARGET_CPRESTORE_DIRECTIVE"
5571 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5572 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5574 return ".cprestore\t%1";
5576 [(set_attr "type" "store")
5577 (set_attr "insn_count" "1,3")])
5579 (define_insn "use_cprestore_<mode>"
5580 [(set (reg:P CPRESTORE_SLOT_REGNUM)
5581 (match_operand:P 0 "cprestore_load_slot_operand"))]
5584 [(set_attr "type" "ghost")])
5586 ;; Expand in-line code to clear the instruction cache between operand[0] and
5588 (define_expand "clear_cache"
5589 [(match_operand 0 "pmode_register_operand")
5590 (match_operand 1 "pmode_register_operand")]
5596 mips_expand_synci_loop (operands[0], operands[1]);
5597 emit_insn (gen_sync ());
5598 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5600 else if (mips_cache_flush_func && mips_cache_flush_func[0])
5602 rtx len = gen_reg_rtx (Pmode);
5603 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5604 MIPS_ICACHE_SYNC (operands[0], len);
5610 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5612 { return mips_output_sync (); })
5614 (define_insn "synci"
5615 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5620 (define_insn "rdhwr_synci_step_<mode>"
5621 [(set (match_operand:P 0 "register_operand" "=d")
5622 (unspec_volatile [(const_int 1)]
5627 (define_insn "clear_hazard_<mode>"
5628 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5629 (clobber (reg:P RETURN_ADDR_REGNUM))]
5632 return "%(%<bal\t1f\n"
5634 "1:\t<d>addiu\t$31,$31,12\n"
5638 [(set_attr "insn_count" "5")])
5640 ;; Cache operations for R4000-style caches.
5641 (define_insn "mips_cache"
5642 [(set (mem:BLK (scratch))
5643 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5644 (match_operand:QI 1 "address_operand" "ZD")]
5645 UNSPEC_MIPS_CACHE))]
5649 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5650 ;; operation. We keep the pattern distinct so that we can identify
5651 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5652 ;; the operation is never inserted into a delay slot.
5653 (define_insn "r10k_cache_barrier"
5654 [(set (mem:BLK (scratch))
5655 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5658 [(set_attr "can_delay" "no")])
5660 ;; Block moves, see mips.c for more details.
5661 ;; Argument 0 is the destination
5662 ;; Argument 1 is the source
5663 ;; Argument 2 is the length
5664 ;; Argument 3 is the alignment
5666 (define_expand "cpymemsi"
5667 [(parallel [(set (match_operand:BLK 0 "general_operand")
5668 (match_operand:BLK 1 "general_operand"))
5669 (use (match_operand:SI 2 ""))
5670 (use (match_operand:SI 3 "const_int_operand"))])]
5671 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5673 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5680 ;; ....................
5684 ;; ....................
5686 (define_expand "<optab><mode>3"
5687 [(set (match_operand:GPR 0 "register_operand")
5688 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5689 (match_operand:SI 2 "arith_operand")))]
5692 /* On the mips16, a shift of more than 8 is a four byte instruction,
5693 so, for a shift between 8 and 16, it is just as fast to do two
5694 shifts of 8 or less. If there is a lot of shifting going on, we
5695 may win in CSE. Otherwise combine will put the shifts back
5696 together again. This can be called by mips_function_arg, so we must
5697 be careful not to allocate a new register if we've reached the
5701 && CONST_INT_P (operands[2])
5702 && INTVAL (operands[2]) > 8
5703 && INTVAL (operands[2]) <= 16
5704 && !reload_in_progress
5705 && !reload_completed)
5707 rtx temp = gen_reg_rtx (<MODE>mode);
5709 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5710 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5711 GEN_INT (INTVAL (operands[2]) - 8)));
5716 (define_insn "*<optab><mode>3"
5717 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5718 (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5719 (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5722 if (CONST_INT_P (operands[2]))
5723 operands[2] = GEN_INT (INTVAL (operands[2])
5724 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5726 return "<d><insn>\t%0,%1,%2";
5728 [(set_attr "type" "shift")
5729 (set_attr "compression" "<shift_compression>,none")
5730 (set_attr "mode" "<MODE>")])
5732 (define_insn "*<optab>si3_extend"
5733 [(set (match_operand:DI 0 "register_operand" "=d")
5735 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5736 (match_operand:SI 2 "arith_operand" "dI"))))]
5737 "TARGET_64BIT && !TARGET_MIPS16"
5739 if (CONST_INT_P (operands[2]))
5740 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5742 return "<insn>\t%0,%1,%2";
5744 [(set_attr "type" "shift")
5745 (set_attr "mode" "SI")])
5747 (define_insn "*<optab>si3_mips16"
5748 [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5749 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5750 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5753 if (which_alternative == 0)
5754 return "<insn>\t%0,%2";
5756 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5757 return "<insn>\t%0,%1,%2";
5759 [(set_attr "type" "shift")
5760 (set_attr "mode" "SI")
5761 (set_attr "extended_mips16" "no,no,yes")])
5763 (define_insn "<GPR:d>lsa"
5764 [(set (match_operand:GPR 0 "register_operand" "=d")
5765 (plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
5766 (match_operand 2 "const_immlsa_operand" ""))
5767 (match_operand:GPR 3 "register_operand" "d")))]
5768 "ISA_HAS_<GPR:D>LSA"
5769 "<GPR:d>lsa\t%0,%1,%3,%2"
5770 [(set_attr "type" "arith")
5771 (set_attr "mode" "<GPR:MODE>")])
5773 ;; We need separate DImode MIPS16 patterns because of the irregularity
5775 (define_insn "*ashldi3_mips16"
5776 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5777 (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5778 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5779 "TARGET_64BIT && TARGET_MIPS16"
5781 if (which_alternative == 0)
5782 return "dsll\t%0,%2";
5784 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5785 return "dsll\t%0,%1,%2";
5787 [(set_attr "type" "shift")
5788 (set_attr "mode" "DI")
5789 (set_attr "extended_mips16" "no,no,yes")])
5791 (define_insn "*ashrdi3_mips16"
5792 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5793 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5794 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5795 "TARGET_64BIT && TARGET_MIPS16"
5797 if (CONST_INT_P (operands[2]))
5798 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5800 return "dsra\t%0,%2";
5802 [(set_attr "type" "shift")
5803 (set_attr "mode" "DI")
5804 (set_attr "extended_mips16" "no,no,yes")])
5806 (define_insn "*lshrdi3_mips16"
5807 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5808 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5809 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5810 "TARGET_64BIT && TARGET_MIPS16"
5812 if (CONST_INT_P (operands[2]))
5813 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5815 return "dsrl\t%0,%2";
5817 [(set_attr "type" "shift")
5818 (set_attr "mode" "DI")
5819 (set_attr "extended_mips16" "no,no,yes")])
5821 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5824 [(set (match_operand:GPR 0 "d_operand")
5825 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5826 (match_operand:GPR 2 "const_int_operand")))]
5827 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5828 && INTVAL (operands[2]) > 8
5829 && INTVAL (operands[2]) <= 16"
5830 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5831 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5832 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5834 ;; If we load a byte on the mips16 as a bitfield, the resulting
5835 ;; sequence of instructions is too complicated for combine, because it
5836 ;; involves four instructions: a load, a shift, a constant load into a
5837 ;; register, and an and (the key problem here is that the mips16 does
5838 ;; not have and immediate). We recognize a shift of a load in order
5839 ;; to make it simple enough for combine to understand.
5841 ;; The instruction count here is the worst case.
5842 (define_insn_and_split ""
5843 [(set (match_operand:SI 0 "register_operand" "=d")
5844 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5845 (match_operand:SI 2 "immediate_operand" "I")))]
5849 [(set (match_dup 0) (match_dup 1))
5850 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5852 [(set_attr "type" "load")
5853 (set_attr "mode" "SI")
5854 (set (attr "insn_count")
5855 (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5857 (define_insn "rotr<mode>3"
5858 [(set (match_operand:GPR 0 "register_operand" "=d")
5859 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5860 (match_operand:SI 2 "arith_operand" "dI")))]
5863 if (CONST_INT_P (operands[2]))
5864 operands[2] = GEN_INT (INTVAL (operands[2])
5865 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5867 return "<d>ror\t%0,%1,%2";
5869 [(set_attr "type" "shift")
5870 (set_attr "mode" "<MODE>")])
5872 (define_insn "bswaphi2"
5873 [(set (match_operand:HI 0 "register_operand" "=d")
5874 (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5877 [(set_attr "type" "shift")])
5879 (define_insn_and_split "bswapsi2"
5880 [(set (match_operand:SI 0 "register_operand" "=d")
5881 (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5882 "ISA_HAS_WSBH && ISA_HAS_ROR"
5885 [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5886 (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5888 [(set_attr "insn_count" "2")])
5890 (define_insn_and_split "bswapdi2"
5891 [(set (match_operand:DI 0 "register_operand" "=d")
5892 (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5893 "TARGET_64BIT && ISA_HAS_WSBH"
5896 [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5897 (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5899 [(set_attr "insn_count" "2")])
5902 [(set (match_operand:SI 0 "register_operand" "=d")
5903 (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5906 [(set_attr "type" "shift")])
5909 [(set (match_operand:DI 0 "register_operand" "=d")
5910 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5911 "TARGET_64BIT && ISA_HAS_WSBH"
5913 [(set_attr "type" "shift")])
5916 [(set (match_operand:DI 0 "register_operand" "=d")
5917 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5918 "TARGET_64BIT && ISA_HAS_WSBH"
5920 [(set_attr "type" "shift")])
5923 ;; ....................
5925 ;; CONDITIONAL BRANCHES
5927 ;; ....................
5929 ;; Conditional branches on floating-point equality tests.
5931 (define_insn "*branch_fp_<mode>"
5934 (match_operator 1 "equality_operator"
5935 [(match_operand:FPCC 2 "register_operand" "<reg>")
5937 (label_ref (match_operand 0 "" ""))
5941 return mips_output_conditional_branch (insn, operands,
5942 MIPS_BRANCH ("b%F1", "%Z2%0"),
5943 MIPS_BRANCH ("b%W1", "%Z2%0"));
5945 [(set_attr "type" "branch")])
5947 (define_insn "*branch_fp_inverted_<mode>"
5950 (match_operator 1 "equality_operator"
5951 [(match_operand:FPCC 2 "register_operand" "<reg>")
5954 (label_ref (match_operand 0 "" ""))))]
5957 return mips_output_conditional_branch (insn, operands,
5958 MIPS_BRANCH ("b%W1", "%Z2%0"),
5959 MIPS_BRANCH ("b%F1", "%Z2%0"));
5961 [(set_attr "type" "branch")])
5963 ;; Conditional branches on ordered comparisons with zero.
5965 (define_insn "*branch_order<mode>"
5968 (match_operator 1 "order_operator"
5969 [(match_operand:GPR 2 "register_operand" "d,d")
5970 (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5971 (label_ref (match_operand 0 "" ""))
5974 { return mips_output_order_conditional_branch (insn, operands, false); }
5975 [(set_attr "type" "branch")
5976 (set_attr "compact_form" "maybe,always")
5977 (set_attr "hazard" "forbidden_slot")])
5979 (define_insn "*branch_order<mode>_inverted"
5982 (match_operator 1 "order_operator"
5983 [(match_operand:GPR 2 "register_operand" "d,d")
5984 (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5986 (label_ref (match_operand 0 "" ""))))]
5988 { return mips_output_order_conditional_branch (insn, operands, true); }
5989 [(set_attr "type" "branch")
5990 (set_attr "compact_form" "maybe,always")
5991 (set_attr "hazard" "forbidden_slot")])
5993 ;; Conditional branch on equality comparison.
5995 (define_insn "*branch_equality<mode>"
5998 (match_operator 1 "equality_operator"
5999 [(match_operand:GPR 2 "register_operand" "d")
6000 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
6001 (label_ref (match_operand 0 "" ""))
6004 { return mips_output_equal_conditional_branch (insn, operands, false); }
6005 [(set_attr "type" "branch")
6006 (set_attr "compact_form" "maybe")
6007 (set_attr "hazard" "forbidden_slot")])
6009 (define_insn "*branch_equality<mode>_inverted"
6012 (match_operator 1 "equality_operator"
6013 [(match_operand:GPR 2 "register_operand" "d")
6014 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
6016 (label_ref (match_operand 0 "" ""))))]
6018 { return mips_output_equal_conditional_branch (insn, operands, true); }
6019 [(set_attr "type" "branch")
6020 (set_attr "compact_form" "maybe")
6021 (set_attr "hazard" "forbidden_slot")])
6025 (define_insn "*branch_equality<mode>_mips16"
6028 (match_operator 1 "equality_operator"
6029 [(match_operand:GPR 2 "register_operand" "d,t")
6031 (label_ref (match_operand 0 "" ""))
6037 [(set_attr "type" "branch")])
6039 (define_insn "*branch_equality<mode>_mips16_inverted"
6042 (match_operator 1 "equality_operator"
6043 [(match_operand:GPR 2 "register_operand" "d,t")
6046 (label_ref (match_operand 0 "" ""))))]
6051 [(set_attr "type" "branch")])
6053 (define_expand "cbranch<mode>4"
6055 (if_then_else (match_operator 0 "comparison_operator"
6056 [(match_operand:GPR 1 "register_operand")
6057 (match_operand:GPR 2 "nonmemory_operand")])
6058 (label_ref (match_operand 3 ""))
6062 mips_expand_conditional_branch (operands);
6066 (define_expand "cbranch<mode>4"
6068 (if_then_else (match_operator 0 "comparison_operator"
6069 [(match_operand:SCALARF 1 "register_operand")
6070 (match_operand:SCALARF 2 "register_operand")])
6071 (label_ref (match_operand 3 ""))
6075 mips_expand_conditional_branch (operands);
6079 ;; Used to implement built-in functions.
6080 (define_expand "condjump"
6082 (if_then_else (match_operand 0)
6083 (label_ref (match_operand 1))
6086 ;; Branch if bit is set/clear.
6088 (define_insn "*branch_bit<bbv><mode>"
6091 (equality_op (zero_extract:GPR
6092 (match_operand:GPR 1 "register_operand" "d")
6094 (match_operand 2 "const_int_operand" ""))
6096 (label_ref (match_operand 0 ""))
6098 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6101 mips_output_conditional_branch (insn, operands,
6102 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
6103 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
6105 [(set_attr "type" "branch")
6106 (set_attr "branch_likely" "no")])
6108 (define_insn "*branch_bit<bbv><mode>_inverted"
6111 (equality_op (zero_extract:GPR
6112 (match_operand:GPR 1 "register_operand" "d")
6114 (match_operand 2 "const_int_operand" ""))
6117 (label_ref (match_operand 0 ""))))]
6118 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6121 mips_output_conditional_branch (insn, operands,
6122 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
6123 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
6125 [(set_attr "type" "branch")
6126 (set_attr "branch_likely" "no")])
6129 ;; ....................
6131 ;; SETTING A REGISTER FROM A COMPARISON
6133 ;; ....................
6135 ;; Destination is always set in SI mode.
6137 (define_expand "cstore<mode>4"
6138 [(set (match_operand:SI 0 "register_operand")
6139 (match_operator:SI 1 "mips_cstore_operator"
6140 [(match_operand:GPR 2 "register_operand")
6141 (match_operand:GPR 3 "nonmemory_operand")]))]
6144 mips_expand_scc (operands);
6148 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
6149 [(set (match_operand:GPR2 0 "register_operand" "=d")
6150 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6152 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6154 [(set_attr "type" "slt")
6155 (set_attr "mode" "<GPR:MODE>")])
6157 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
6158 [(set (match_operand:GPR2 0 "register_operand" "=t")
6159 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6161 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6163 [(set_attr "type" "slt")
6164 (set_attr "mode" "<GPR:MODE>")])
6166 ;; Generate sltiu unless using seq results in better code.
6167 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
6168 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6169 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6170 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6176 [(set_attr "type" "slt")
6177 (set_attr "mode" "<GPR:MODE>")])
6179 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
6180 [(set (match_operand:GPR2 0 "register_operand" "=d")
6181 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
6183 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6185 [(set_attr "type" "slt")
6186 (set_attr "mode" "<GPR:MODE>")])
6188 ;; Generate sltu unless using sne results in better code.
6189 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
6190 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6191 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6192 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6198 [(set_attr "type" "slt")
6199 (set_attr "mode" "<GPR:MODE>")])
6201 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
6202 [(set (match_operand:GPR2 0 "register_operand" "=d")
6203 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6204 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
6207 [(set_attr "type" "slt")
6208 (set_attr "mode" "<GPR:MODE>")])
6210 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
6211 [(set (match_operand:GPR2 0 "register_operand" "=t")
6212 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6213 (match_operand:GPR 2 "register_operand" "d")))]
6216 [(set_attr "type" "slt")
6217 (set_attr "mode" "<GPR:MODE>")])
6219 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6220 [(set (match_operand:GPR2 0 "register_operand" "=d")
6221 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6225 [(set_attr "type" "slt")
6226 (set_attr "mode" "<GPR:MODE>")])
6228 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6229 [(set (match_operand:GPR2 0 "register_operand" "=d")
6230 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6231 (match_operand:GPR 2 "arith_operand" "dI")))]
6234 [(set_attr "type" "slt")
6235 (set_attr "mode" "<GPR:MODE>")])
6237 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6238 [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6239 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6240 (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6243 [(set_attr "type" "slt")
6244 (set_attr "mode" "<GPR:MODE>")
6245 (set_attr "extended_mips16" "no,no,yes")])
6247 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6248 [(set (match_operand:GPR2 0 "register_operand" "=d")
6249 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6250 (match_operand:GPR 2 "sle_operand" "")))]
6253 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6254 return "slt<u>\t%0,%1,%2";
6256 [(set_attr "type" "slt")
6257 (set_attr "mode" "<GPR:MODE>")])
6259 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6260 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6261 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6262 (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6265 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6266 return "slt<u>\t%1,%2";
6268 [(set_attr "type" "slt")
6269 (set_attr "mode" "<GPR:MODE>")
6270 (set_attr "extended_mips16" "no,yes")])
6273 ;; ....................
6275 ;; FLOATING POINT COMPARISONS
6277 ;; ....................
6279 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6280 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6281 (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6282 (match_operand:SCALARF 2 "register_operand" "f")))]
6284 "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6285 [(set_attr "type" "fcmp")
6286 (set_attr "mode" "FPSW")])
6288 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6289 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6290 (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6291 (match_operand:SCALARF 2 "register_operand" "f")))]
6293 "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6294 [(set_attr "type" "fcmp")
6295 (set_attr "mode" "FPSW")])
6298 ;; ....................
6300 ;; UNCONDITIONAL BRANCHES
6302 ;; ....................
6304 ;; Unconditional branches.
6306 (define_expand "jump"
6308 (label_ref (match_operand 0)))])
6310 (define_insn "*jump_absolute"
6312 (label_ref (match_operand 0)))]
6313 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6315 if (get_attr_length (insn) <= 8)
6317 if (TARGET_CB_MAYBE)
6318 return MIPS_ABSOLUTE_JUMP ("%*b%:\t%l0");
6320 return MIPS_ABSOLUTE_JUMP ("%*b\t%l0%/");
6324 if (TARGET_CB_MAYBE && !final_sequence)
6325 return MIPS_ABSOLUTE_JUMP ("%*bc\t%l0");
6327 return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6330 [(set_attr "type" "branch")
6331 (set_attr "compact_form" "maybe")])
6333 (define_insn "*jump_pic"
6335 (label_ref (match_operand 0)))]
6336 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6338 if (get_attr_length (insn) <= 8)
6340 if (TARGET_CB_MAYBE)
6341 return "%*b%:\t%l0";
6343 return "%*b\t%l0%/";
6347 mips_output_load_label (operands[0]);
6348 if (TARGET_CB_MAYBE)
6349 return "%*jr%:\t%@%]";
6351 return "%*jr\t%@%/%]";
6354 [(set_attr "type" "branch")
6355 (set_attr "compact_form" "maybe")])
6357 ;; We need a different insn for the mips16, because a mips16 branch
6358 ;; does not have a delay slot.
6360 (define_insn "*jump_mips16"
6362 (label_ref (match_operand 0 "" "")))]
6365 [(set_attr "type" "branch")
6366 (set (attr "length")
6367 ;; This calculation is like the normal branch one, but the
6368 ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6369 ;; than [-0x100, 0xfe]. This translates to a range of:
6371 ;; [-(0x800 - sizeof (branch)), 0x7fe]
6372 ;; == [-0x7fe, 0x7fe]
6374 ;; from the shorten_branches reference address. Long-branch
6375 ;; sequences will replace this one, so the minimum length
6376 ;; is one instruction shorter than for conditional branches.
6377 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6378 (le (minus (pc) (match_dup 0)) (const_int 2046)))
6380 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6381 (le (minus (pc) (match_dup 0)) (const_int 65532)))
6383 (and (match_test "TARGET_ABICALLS")
6384 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6386 (match_test "Pmode == SImode")
6388 ] (const_int 22)))])
6390 (define_expand "indirect_jump"
6391 [(set (pc) (match_operand 0 "register_operand"))]
6394 operands[0] = force_reg (Pmode, operands[0]);
6395 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6399 (define_insn "indirect_jump_<mode>"
6400 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6403 return mips_output_jump (operands, 0, -1, false);
6405 [(set_attr "type" "jump")
6406 (set_attr "mode" "none")])
6408 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6409 ;; sequences. Having a dedicated pattern is more convenient than
6410 ;; creating a SEQUENCE for this special case.
6411 (define_insn "indirect_jump_and_restore_<mode>"
6412 [(set (pc) (match_operand:P 1 "register_operand" "d"))
6413 (set (match_operand:P 0 "register_operand" "=d")
6414 (match_operand:P 2 "register_operand" "y"))]
6416 "%(%<jr\t%1\;move\t%0,%2%>%)"
6417 [(set_attr "type" "multi")
6418 (set_attr "extended_mips16" "yes")])
6420 (define_expand "tablejump"
6422 (match_operand 0 "register_operand"))
6423 (use (label_ref (match_operand 1 "")))]
6424 "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6427 operands[0] = expand_binop (Pmode, add_optab, operands[0],
6428 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6429 else if (TARGET_RTP_PIC)
6431 /* When generating RTP PIC, we use case table entries that are relative
6432 to the start of the function. Add the function's address to the
6434 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6435 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6436 start, 0, 0, OPTAB_WIDEN);
6439 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6443 (define_insn "tablejump_<mode>"
6445 (match_operand:P 0 "register_operand" "d"))
6446 (use (label_ref (match_operand 1 "" "")))]
6449 return mips_output_jump (operands, 0, -1, false);
6451 [(set_attr "type" "jump")
6452 (set_attr "mode" "none")])
6454 ;; For MIPS16, we don't know whether a given jump table will use short or
6455 ;; word-sized offsets until late in compilation, when we are able to determine
6456 ;; the sizes of the insns which comprise the containing function. This
6457 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6458 ;; the latter tries to calculate the index of the offset to jump through early
6459 ;; in compilation, i.e. at expand time, when nothing is known about the
6460 ;; eventual function layout.
6462 (define_expand "casesi"
6463 [(match_operand:SI 0 "register_operand" "") ; index to jump on
6464 (match_operand:SI 1 "const_int_operand" "") ; lower bound
6465 (match_operand:SI 2 "const_int_operand" "") ; total range
6466 (match_operand 3 "" "") ; table label
6467 (match_operand 4 "" "")] ; out of range label
6468 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6470 if (operands[1] != const0_rtx)
6472 rtx reg = gen_reg_rtx (SImode);
6473 rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6475 if (!arith_operand (offset, SImode))
6476 offset = force_reg (SImode, offset);
6478 emit_insn (gen_addsi3 (reg, operands[0], offset));
6482 if (!arith_operand (operands[0], SImode))
6483 operands[0] = force_reg (SImode, operands[0]);
6485 emit_cmp_and_jump_insns (operands[0], operands[2], GTU,
6486 NULL_RTX, SImode, 1, operands[4]);
6487 emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6488 (operands[0], operands[3])));
6492 (define_insn "casesi_internal_mips16_<mode>"
6494 (unspec:P [(match_operand:SI 0 "register_operand" "d")
6495 (label_ref (match_operand 1 "" ""))]
6496 UNSPEC_CASESI_DISPATCH))
6497 (clobber (match_scratch:P 2 "=d"))
6498 (clobber (match_scratch:P 3 "=d"))]
6499 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6501 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[1])));
6503 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6505 switch (GET_MODE (diff_vec))
6508 output_asm_insn ("sll\t%3,%0,1", operands);
6509 output_asm_insn ("<d>la\t%2,%1", operands);
6510 output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6511 output_asm_insn ("lh\t%3,0(%3)", operands);
6515 output_asm_insn ("sll\t%3,%0,2", operands);
6516 output_asm_insn ("<d>la\t%2,%1", operands);
6517 output_asm_insn ("<d>addu\t%3,%2,%3", operands);
6518 output_asm_insn ("lw\t%3,0(%3)", operands);
6525 output_asm_insn ("<d>addu\t%2,%2,%3", operands);
6527 if (GENERATE_MIPS16E)
6532 [(set (attr "insn_count")
6533 (if_then_else (match_test "GENERATE_MIPS16E")
6535 (const_string "7")))])
6537 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6538 ;; While it is possible to either pull it off the stack (in the
6539 ;; o32 case) or recalculate it given t9 and our target label,
6540 ;; it takes 3 or 4 insns to do so.
6542 (define_expand "builtin_setjmp_setup"
6543 [(use (match_operand 0 "register_operand"))]
6548 addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6549 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6553 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
6554 ;; that older code did recalculate the gp from $25. Continue to jump through
6555 ;; $25 for compatibility (we lose nothing by doing so).
6557 (define_expand "builtin_longjmp"
6558 [(use (match_operand 0 "register_operand"))]
6561 /* The elements of the buffer are, in order: */
6562 int W = GET_MODE_SIZE (Pmode);
6563 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6564 rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6565 rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6566 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6567 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6568 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6569 The target is bound to be using $28 as the global pointer
6570 but the current function might not be. */
6571 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6573 /* This bit is similar to expand_builtin_longjmp except that it
6574 restores $gp as well. */
6575 mips_emit_move (pv, lab);
6576 /* Restore the frame pointer and stack pointer and gp. We must use a
6577 temporary since the setjmp buffer may be a local. */
6578 fp = copy_to_reg (fp);
6579 gpv = copy_to_reg (gpv);
6580 emit_stack_restore (SAVE_NONLOCAL, stack);
6582 /* Ensure the frame pointer move is not optimized. */
6583 emit_insn (gen_blockage ());
6584 emit_clobber (hard_frame_pointer_rtx);
6585 emit_clobber (frame_pointer_rtx);
6587 mips_emit_move (hard_frame_pointer_rtx, fp);
6588 mips_emit_move (gp, gpv);
6589 emit_use (hard_frame_pointer_rtx);
6590 emit_use (stack_pointer_rtx);
6592 emit_indirect_jump (pv);
6597 ;; ....................
6599 ;; Function prologue/epilogue
6601 ;; ....................
6604 (define_expand "prologue"
6608 mips_expand_prologue ();
6612 ;; Block any insns from being moved before this point, since the
6613 ;; profiling call to mcount can use various registers that aren't
6614 ;; saved or used to pass arguments.
6616 (define_insn "blockage"
6617 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6620 [(set_attr "type" "ghost")
6621 (set_attr "mode" "none")])
6623 (define_insn "probe_stack_range_<P:mode>"
6624 [(set (match_operand:P 0 "register_operand" "=d")
6625 (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6626 (match_operand:P 2 "register_operand" "d")]
6627 UNSPEC_PROBE_STACK_RANGE))]
6629 { return mips_output_probe_stack_range (operands[0], operands[2]); }
6630 [(set_attr "type" "unknown")
6631 (set_attr "can_delay" "no")
6632 (set_attr "mode" "<MODE>")])
6634 (define_expand "epilogue"
6638 mips_expand_epilogue (false);
6642 (define_expand "sibcall_epilogue"
6646 mips_expand_epilogue (true);
6650 ;; Trivial return. Make it look like a normal return insn as that
6651 ;; allows jump optimizations to work better.
6653 (define_expand "return"
6655 "mips_can_use_return_insn ()"
6656 { mips_expand_before_return (); })
6658 (define_expand "simple_return"
6661 { mips_expand_before_return (); })
6663 (define_insn "*<optab>"
6667 operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
6668 return mips_output_jump (operands, 0, -1, false);
6670 [(set_attr "type" "jump")
6671 (set_attr "mode" "none")])
6675 (define_insn "<optab>_internal"
6677 (use (match_operand 0 "pmode_register_operand" ""))]
6680 return mips_output_jump (operands, 0, -1, false);
6682 [(set_attr "type" "jump")
6683 (set_attr "mode" "none")])
6685 ;; Exception return.
6686 (define_insn "mips_eret"
6688 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6691 [(set_attr "type" "trap")
6692 (set_attr "mode" "none")])
6694 ;; Debug exception return.
6695 (define_insn "mips_deret"
6697 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6700 [(set_attr "type" "trap")
6701 (set_attr "mode" "none")])
6703 ;; Disable interrupts.
6704 (define_insn "mips_di"
6705 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6708 [(set_attr "type" "trap")
6709 (set_attr "mode" "none")])
6711 ;; Execution hazard barrier.
6712 (define_insn "mips_ehb"
6713 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6716 [(set_attr "type" "trap")
6717 (set_attr "mode" "none")])
6719 ;; Read GPR from previous shadow register set.
6720 (define_insn "mips_rdpgpr_<mode>"
6721 [(set (match_operand:P 0 "register_operand" "=d")
6722 (unspec_volatile:P [(match_operand:P 1 "register_operand" "d")]
6726 [(set_attr "type" "move")
6727 (set_attr "mode" "<MODE>")])
6729 ;; Move involving COP0 registers.
6730 (define_insn "cop0_move"
6731 [(set (match_operand:SI 0 "register_operand" "=B,d")
6732 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6735 { return mips_output_move (operands[0], operands[1]); }
6736 [(set_attr "type" "mtc,mfc")
6737 (set_attr "mode" "SI")])
6739 ;; This is used in compiling the unwind routines.
6740 (define_expand "eh_return"
6741 [(use (match_operand 0 "general_operand"))]
6744 if (GET_MODE (operands[0]) != word_mode)
6745 operands[0] = convert_to_mode (word_mode, operands[0], 0);
6747 emit_insn (gen_eh_set_lr_di (operands[0]));
6749 emit_insn (gen_eh_set_lr_si (operands[0]));
6753 ;; Clobber the return address on the stack. We can't expand this
6754 ;; until we know where it will be put in the stack frame.
6756 (define_insn "eh_set_lr_si"
6757 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6758 (clobber (match_scratch:SI 1 "=&d"))]
6762 (define_insn "eh_set_lr_di"
6763 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6764 (clobber (match_scratch:DI 1 "=&d"))]
6769 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6770 (clobber (match_scratch 1))]
6774 mips_set_return_address (operands[0], operands[1]);
6778 (define_expand "exception_receiver"
6782 /* See the comment above load_call<mode> for details. */
6783 emit_insn (gen_set_got_version ());
6785 /* If we have a call-clobbered $gp, restore it from its save slot. */
6786 if (HAVE_restore_gp_si)
6787 emit_insn (gen_restore_gp_si ());
6788 else if (HAVE_restore_gp_di)
6789 emit_insn (gen_restore_gp_di ());
6793 (define_expand "nonlocal_goto_receiver"
6797 /* See the comment above load_call<mode> for details. */
6798 emit_insn (gen_set_got_version ());
6802 ;; Restore $gp from its .cprestore stack slot. The instruction remains
6803 ;; volatile until all uses of $28 are exposed.
6804 (define_insn_and_split "restore_gp_<mode>"
6806 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6807 (clobber (match_scratch:P 0 "=&d"))]
6808 "TARGET_CALL_CLOBBERED_GP"
6810 "&& epilogue_completed"
6813 mips_restore_gp_from_cprestore_slot (operands[0]);
6816 [(set_attr "type" "ghost")])
6818 ;; Move between $gp and its register save slot.
6819 (define_insn_and_split "move_gp<mode>"
6820 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6821 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6824 { return mips_must_initialize_gp_p () ? "#" : ""; }
6825 "mips_must_initialize_gp_p ()"
6828 mips_emit_move (operands[0], operands[1]);
6831 [(set_attr "type" "ghost")])
6834 ;; ....................
6838 ;; ....................
6840 ;; Instructions to load a call address from the GOT. The address might
6841 ;; point to a function or to a lazy binding stub. In the latter case,
6842 ;; the stub will use the dynamic linker to resolve the function, which
6843 ;; in turn will change the GOT entry to point to the function's real
6846 ;; This means that every call, even pure and constant ones, can
6847 ;; potentially modify the GOT entry. And once a stub has been called,
6848 ;; we must not call it again.
6850 ;; We represent this restriction using an imaginary, fixed, call-saved
6851 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6852 ;; live throughout the function and to change its value after every
6853 ;; potential call site. This stops any rtx value that uses the register
6854 ;; from being computed before an earlier call. To do this, we:
6856 ;; - Ensure that the register is live on entry to the function,
6857 ;; so that it is never thought to be used uninitalized.
6859 ;; - Ensure that the register is live on exit from the function,
6860 ;; so that it is live throughout.
6862 ;; - Make each call (lazily-bound or not) use the current value
6863 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6864 ;; not moved across call boundaries.
6866 ;; - Add "ghost" definitions of the register to the beginning of
6867 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6868 ;; edges may involve calls that normal paths don't. (E.g. the
6869 ;; unwinding code that handles a non-call exception may change
6870 ;; lazily-bound GOT entries.) We do this by making the
6871 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6872 ;; a set_got_version instruction.
6874 ;; - After each call (lazily-bound or not), use a "ghost"
6875 ;; update_got_version instruction to change the register's value.
6876 ;; This instruction mimics the _possible_ effect of the dynamic
6877 ;; resolver during the call and it remains live even if the call
6878 ;; itself becomes dead.
6880 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6881 ;; The register is therefore not a valid register_operand
6882 ;; and cannot be moved to or from other registers.
6884 (define_insn "load_call<mode>"
6885 [(set (match_operand:P 0 "register_operand" "=d")
6886 (unspec:P [(match_operand:P 1 "register_operand" "d")
6887 (match_operand:P 2 "immediate_operand" "")
6888 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6890 "<load>\t%0,%R2(%1)"
6891 [(set_attr "got" "load")
6892 (set_attr "mode" "<MODE>")])
6894 (define_insn "set_got_version"
6895 [(set (reg:SI GOT_VERSION_REGNUM)
6896 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6899 [(set_attr "type" "ghost")])
6901 (define_insn "update_got_version"
6902 [(set (reg:SI GOT_VERSION_REGNUM)
6903 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6906 [(set_attr "type" "ghost")])
6908 ;; Sibling calls. All these patterns use jump instructions.
6910 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6911 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6912 ;; is defined in terms of call_insn_operand, the same is true of the
6915 ;; When we use an indirect jump, we need a register that will be
6916 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6917 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6918 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6921 (define_expand "sibcall"
6922 [(parallel [(call (match_operand 0 "")
6923 (match_operand 1 ""))
6924 (use (match_operand 2 "")) ;; next_arg_reg
6925 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6928 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6929 operands[1], operands[2], false);
6933 (define_insn "sibcall_internal"
6934 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6935 (match_operand 1 "" ""))]
6936 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6937 { return mips_output_jump (operands, 0, 1, false); }
6938 [(set_attr "jal" "indirect,direct")
6939 (set_attr "jal_macro" "no")])
6941 (define_expand "sibcall_value"
6942 [(parallel [(set (match_operand 0 "")
6943 (call (match_operand 1 "")
6944 (match_operand 2 "")))
6945 (use (match_operand 3 ""))])] ;; next_arg_reg
6948 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6949 operands[2], operands[3], false);
6953 (define_insn "sibcall_value_internal"
6954 [(set (match_operand 0 "register_operand" "")
6955 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6956 (match_operand 2 "" "")))]
6957 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6958 { return mips_output_jump (operands, 1, 2, false); }
6959 [(set_attr "jal" "indirect,direct")
6960 (set_attr "jal_macro" "no")])
6962 (define_insn "sibcall_value_multiple_internal"
6963 [(set (match_operand 0 "register_operand" "")
6964 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6965 (match_operand 2 "" "")))
6966 (set (match_operand 3 "register_operand" "")
6967 (call (mem:SI (match_dup 1))
6969 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6970 { return mips_output_jump (operands, 1, 2, false); }
6971 [(set_attr "jal" "indirect,direct")
6972 (set_attr "jal_macro" "no")])
6974 (define_expand "call"
6975 [(parallel [(call (match_operand 0 "")
6976 (match_operand 1 ""))
6977 (use (match_operand 2 "")) ;; next_arg_reg
6978 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6981 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6982 operands[1], operands[2], false);
6986 ;; This instruction directly corresponds to an assembly-language "jal".
6987 ;; There are four cases:
6990 ;; Both symbolic and register destinations are OK. The pattern
6991 ;; always expands to a single mips instruction.
6993 ;; - -mabicalls/-mno-explicit-relocs:
6994 ;; Again, both symbolic and register destinations are OK.
6995 ;; The call is treated as a multi-instruction black box.
6997 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6998 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
7001 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
7002 ;; Only "jal $25" is allowed. The call is actually two instructions:
7003 ;; "jalr $25" followed by an insn to reload $gp.
7005 ;; In the last case, we can generate the individual instructions with
7006 ;; a define_split. There are several things to be wary of:
7008 ;; - We can't expose the load of $gp before reload. If we did,
7009 ;; it might get removed as dead, but reload can introduce new
7010 ;; uses of $gp by rematerializing constants.
7012 ;; - We shouldn't restore $gp after calls that never return.
7013 ;; It isn't valid to insert instructions between a noreturn
7014 ;; call and the following barrier.
7016 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
7017 ;; instruction preserves $gp and so have no effect on its liveness.
7018 ;; But once we generate the separate insns, it becomes obvious that
7019 ;; $gp is not live on entry to the call.
7021 (define_insn_and_split "call_internal"
7022 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
7023 (match_operand 1 "" ""))
7024 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7027 return (TARGET_SPLIT_CALLS ? "#"
7028 : mips_output_jump (operands, 0, 1, true));
7030 "reload_completed && TARGET_SPLIT_CALLS"
7033 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
7036 [(set_attr "jal" "indirect,direct")])
7038 (define_insn "call_split"
7039 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
7040 (match_operand 1 "" ""))
7041 (clobber (reg:SI RETURN_ADDR_REGNUM))
7042 (clobber (reg:SI 28))]
7043 "TARGET_SPLIT_CALLS"
7044 { return mips_output_jump (operands, 0, 1, true); }
7045 [(set_attr "jal" "indirect,direct")
7046 (set_attr "jal_macro" "no")])
7048 ;; A pattern for calls that must be made directly. It is used for
7049 ;; MIPS16 calls that the linker may need to redirect to a hard-float
7050 ;; stub; the linker relies on the call relocation type to detect when
7051 ;; such redirection is needed.
7052 (define_insn_and_split "call_internal_direct"
7053 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
7056 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7059 return (TARGET_SPLIT_CALLS ? "#"
7060 : mips_output_jump (operands, 0, -1, true));
7062 "reload_completed && TARGET_SPLIT_CALLS"
7065 mips_split_call (curr_insn,
7066 gen_call_direct_split (operands[0], operands[1]));
7069 [(set_attr "jal" "direct")])
7071 (define_insn "call_direct_split"
7072 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
7075 (clobber (reg:SI RETURN_ADDR_REGNUM))
7076 (clobber (reg:SI 28))]
7077 "TARGET_SPLIT_CALLS"
7078 { return mips_output_jump (operands, 0, -1, true); }
7079 [(set_attr "jal" "direct")
7080 (set_attr "jal_macro" "no")])
7082 (define_expand "call_value"
7083 [(parallel [(set (match_operand 0 "")
7084 (call (match_operand 1 "")
7085 (match_operand 2 "")))
7086 (use (match_operand 3 ""))])] ;; next_arg_reg
7089 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
7090 operands[2], operands[3], false);
7094 ;; See comment for call_internal.
7095 (define_insn_and_split "call_value_internal"
7096 [(set (match_operand 0 "register_operand" "")
7097 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7098 (match_operand 2 "" "")))
7099 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7102 return (TARGET_SPLIT_CALLS ? "#"
7103 : mips_output_jump (operands, 1, 2, true));
7105 "reload_completed && TARGET_SPLIT_CALLS"
7108 mips_split_call (curr_insn,
7109 gen_call_value_split (operands[0], operands[1],
7113 [(set_attr "jal" "indirect,direct")])
7115 (define_insn "call_value_split"
7116 [(set (match_operand 0 "register_operand" "")
7117 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7118 (match_operand 2 "" "")))
7119 (clobber (reg:SI RETURN_ADDR_REGNUM))
7120 (clobber (reg:SI 28))]
7121 "TARGET_SPLIT_CALLS"
7122 { return mips_output_jump (operands, 1, 2, true); }
7123 [(set_attr "jal" "indirect,direct")
7124 (set_attr "jal_macro" "no")])
7126 ;; See call_internal_direct.
7127 (define_insn_and_split "call_value_internal_direct"
7128 [(set (match_operand 0 "register_operand")
7129 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7132 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7135 return (TARGET_SPLIT_CALLS ? "#"
7136 : mips_output_jump (operands, 1, -1, true));
7138 "reload_completed && TARGET_SPLIT_CALLS"
7141 mips_split_call (curr_insn,
7142 gen_call_value_direct_split (operands[0], operands[1],
7146 [(set_attr "jal" "direct")])
7148 (define_insn "call_value_direct_split"
7149 [(set (match_operand 0 "register_operand")
7150 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7153 (clobber (reg:SI RETURN_ADDR_REGNUM))
7154 (clobber (reg:SI 28))]
7155 "TARGET_SPLIT_CALLS"
7156 { return mips_output_jump (operands, 1, -1, true); }
7157 [(set_attr "jal" "direct")
7158 (set_attr "jal_macro" "no")])
7160 ;; See comment for call_internal.
7161 (define_insn_and_split "call_value_multiple_internal"
7162 [(set (match_operand 0 "register_operand" "")
7163 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7164 (match_operand 2 "" "")))
7165 (set (match_operand 3 "register_operand" "")
7166 (call (mem:SI (match_dup 1))
7168 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7171 return (TARGET_SPLIT_CALLS ? "#"
7172 : mips_output_jump (operands, 1, 2, true));
7174 "reload_completed && TARGET_SPLIT_CALLS"
7177 mips_split_call (curr_insn,
7178 gen_call_value_multiple_split (operands[0], operands[1],
7179 operands[2], operands[3]));
7182 [(set_attr "jal" "indirect,direct")])
7184 (define_insn "call_value_multiple_split"
7185 [(set (match_operand 0 "register_operand" "")
7186 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7187 (match_operand 2 "" "")))
7188 (set (match_operand 3 "register_operand" "")
7189 (call (mem:SI (match_dup 1))
7191 (clobber (reg:SI RETURN_ADDR_REGNUM))
7192 (clobber (reg:SI 28))]
7193 "TARGET_SPLIT_CALLS"
7194 { return mips_output_jump (operands, 1, 2, true); }
7195 [(set_attr "jal" "indirect,direct")
7196 (set_attr "jal_macro" "no")])
7198 ;; Call subroutine returning any type.
7200 (define_expand "untyped_call"
7201 [(parallel [(call (match_operand 0 "")
7203 (match_operand 1 "")
7204 (match_operand 2 "")])]
7209 emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
7211 for (i = 0; i < XVECLEN (operands[2], 0); i++)
7213 rtx set = XVECEXP (operands[2], 0, i);
7214 mips_emit_move (SET_DEST (set), SET_SRC (set));
7217 emit_insn (gen_blockage ());
7222 ;; ....................
7226 ;; ....................
7230 (define_insn "prefetch"
7231 [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7232 (match_operand 1 "const_int_operand" "n")
7233 (match_operand 2 "const_int_operand" "n"))]
7234 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7236 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_EXT)
7238 /* Loongson 2[ef] and Loongson ext use load to $0 for prefetching. */
7240 return "ld\t$0,%a0";
7242 return "lw\t$0,%a0";
7244 /* Loongson ext2 implementation pref instructions. */
7245 if (TARGET_LOONGSON_EXT2)
7247 operands[1] = mips_loongson_ext2_prefetch_cookie (operands[1],
7249 return "pref\t%1, %a0";
7251 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7252 return "pref\t%1,%a0";
7254 [(set_attr "type" "prefetch")])
7256 (define_insn "*prefetch_indexed_<mode>"
7257 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7258 (match_operand:P 1 "register_operand" "d"))
7259 (match_operand 2 "const_int_operand" "n")
7260 (match_operand 3 "const_int_operand" "n"))]
7261 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7263 if (TARGET_LOONGSON_EXT)
7265 /* Loongson Loongson ext use index load to $0 for prefetching. */
7267 return "gsldx\t$0,0(%0,%1)";
7269 return "gslwx\t$0,0(%0,%1)";
7271 /* Loongson ext2 implementation pref instructions. */
7272 if (TARGET_LOONGSON_EXT2)
7274 operands[2] = mips_loongson_ext2_prefetch_cookie (operands[2],
7276 return "prefx\t%2,%1(%0)";
7278 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7279 return "prefx\t%2,%1(%0)";
7281 [(set_attr "type" "prefetchx")])
7287 [(set_attr "type" "nop")
7288 (set_attr "mode" "none")])
7290 ;; Like nop, but commented out when outside a .set noreorder block.
7291 (define_insn "hazard_nop"
7295 if (mips_noreorder.nesting_level > 0)
7300 [(set_attr "type" "nop")])
7302 ;; The `.insn' pseudo-op.
7303 (define_insn "insn_pseudo"
7304 [(unspec_volatile [(const_int 0)] UNSPEC_INSN_PSEUDO)]
7307 [(set_attr "mode" "none")
7308 (set_attr "insn_count" "0")])
7310 ;; MIPS4 Conditional move instructions.
7312 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7313 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7315 (match_operator 4 "equality_operator"
7316 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7318 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7319 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7324 [(set_attr "type" "condmove")
7325 (set_attr "mode" "<GPR:MODE>")])
7327 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7328 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7330 (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7331 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7332 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7337 [(set_attr "type" "condmove")
7338 (set_attr "mode" "<GPR:MODE>")])
7340 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7341 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7342 (if_then_else:SCALARF
7343 (match_operator 4 "equality_operator"
7344 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7346 (match_operand:SCALARF 2 "register_operand" "f,0")
7347 (match_operand:SCALARF 3 "register_operand" "0,f")))]
7348 "ISA_HAS_FP_CONDMOVE"
7350 mov%T4.<fmt>\t%0,%2,%1
7351 mov%t4.<fmt>\t%0,%3,%1"
7352 [(set_attr "type" "condmove")
7353 (set_attr "mode" "<SCALARF:MODE>")])
7355 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7356 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7358 (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7360 (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7361 (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7363 && (register_operand (operands[2], <GPR:MODE>mode)
7364 != register_operand (operands[3], <GPR:MODE>mode))"
7368 [(set_attr "type" "condmove")
7369 (set_attr "mode" "<GPR:MODE>")])
7371 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7372 ;; argument if the 1st is zero. This means operand 2 and 3 are
7373 ;; inverted in the instruction.
7375 (define_insn "*sel<mode>"
7376 [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7377 (if_then_else:SCALARF
7378 (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7380 (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7381 (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7382 "ISA_HAS_SEL && ISA_HAS_CCF"
7385 seleqz.<fmt>\t%0,%3,%1
7386 selnez.<fmt>\t%0,%2,%1"
7387 [(set_attr "type" "condmove")
7388 (set_attr "mode" "<SCALARF:MODE>")])
7390 ;; These are the main define_expand's used to make conditional moves.
7392 (define_expand "mov<mode>cc"
7393 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7394 (set (match_operand:GPR 0 "register_operand")
7395 (if_then_else:GPR (match_dup 5)
7396 (match_operand:GPR 2 "reg_or_0_operand")
7397 (match_operand:GPR 3 "reg_or_0_operand")))]
7398 "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7400 if (!ISA_HAS_FP_CONDMOVE
7401 && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7404 mips_expand_conditional_move (operands);
7408 (define_expand "mov<mode>cc"
7409 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7410 (set (match_operand:SCALARF 0 "register_operand")
7411 (if_then_else:SCALARF (match_dup 5)
7412 (match_operand:SCALARF 2 "reg_or_0_operand")
7413 (match_operand:SCALARF 3 "reg_or_0_operand")))]
7414 "ISA_HAS_FP_CONDMOVE
7415 || (ISA_HAS_SEL && ISA_HAS_CCF)"
7417 if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7420 /* Workaround an LRA bug which means that tied operands in the sel.fmt
7421 pattern lead to the double precision destination of sel.d getting
7422 reloaded with the full register file usable and the restrictions on
7423 whether the CCFmode input can be used in odd-numbered single-precision
7424 registers are ignored. For consistency reasons the CCF mode values
7425 must be guaranteed to only exist in the even-registers because of
7426 the unusual duality between single and double precision values. */
7427 if (ISA_HAS_SEL && <MODE>mode == DFmode
7428 && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7431 mips_expand_conditional_move (operands);
7436 ;; ....................
7438 ;; mips16 inline constant tables
7440 ;; ....................
7443 (define_insn "consttable"
7444 [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7448 [(set_attr "mode" "none")
7449 (set_attr "insn_count" "0")])
7451 (define_insn "consttable_end"
7452 [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7453 UNSPEC_CONSTTABLE_END)]
7456 [(set_attr "mode" "none")
7457 (set_attr "insn_count" "0")])
7459 (define_insn "consttable_tls_reloc"
7460 [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7461 (match_operand 1 "const_int_operand" "")]
7462 UNSPEC_CONSTTABLE_INT)]
7463 "TARGET_MIPS16_PCREL_LOADS"
7464 { return mips_output_tls_reloc_directive (&operands[0]); }
7465 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7467 (define_insn "consttable_int"
7468 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7469 (match_operand 1 "const_int_operand" "")]
7470 UNSPEC_CONSTTABLE_INT)]
7473 assemble_integer (mips_strip_unspec_address (operands[0]),
7474 INTVAL (operands[1]),
7475 BITS_PER_UNIT * INTVAL (operands[1]), 1);
7478 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7480 (define_insn "consttable_float"
7481 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7482 UNSPEC_CONSTTABLE_FLOAT)]
7485 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7486 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
7487 as_a <scalar_float_mode> (GET_MODE (operands[0])),
7488 GET_MODE_BITSIZE (GET_MODE (operands[0])));
7491 [(set (attr "length")
7492 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7494 (define_insn "align"
7495 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7498 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7501 [(match_operand 0 "small_data_pattern")]
7504 { operands[0] = mips_rewrite_small_data (operands[0]); })
7507 ;; ....................
7509 ;; MIPS16e Save/Restore
7511 ;; ....................
7514 (define_insn "*mips16e_save_restore"
7515 [(match_parallel 0 ""
7516 [(set (match_operand:SI 1 "register_operand")
7517 (plus:SI (match_dup 1)
7518 (match_operand:SI 2 "const_int_operand")))])]
7519 "operands[1] == stack_pointer_rtx
7520 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7521 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7522 [(set_attr "type" "arith")
7523 (set_attr "extended_mips16" "yes")])
7525 ;; Thread-Local Storage
7527 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
7528 ;; MIPS architecture defines this register, and no current
7529 ;; implementation provides it; instead, any OS which supports TLS is
7530 ;; expected to trap and emulate this instruction. rdhwr is part of the
7531 ;; MIPS 32r2 specification, but we use it on any architecture because
7532 ;; we expect it to be emulated. Use .set to force the assembler to
7535 ;; We do not use a constraint to force the destination to be $3
7536 ;; because $3 can appear explicitly as a function return value.
7537 ;; If we leave the use of $3 implicit in the constraints until
7538 ;; reload, we may end up making a $3 return value live across
7539 ;; the instruction, leading to a spill failure when reloading it.
7540 (define_insn_and_split "tls_get_tp_<mode>"
7541 [(set (match_operand:P 0 "register_operand" "=d")
7542 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7543 (clobber (reg:P TLS_GET_TP_REGNUM))]
7544 "HAVE_AS_TLS && !TARGET_MIPS16"
7546 "&& reload_completed"
7547 [(set (reg:P TLS_GET_TP_REGNUM)
7548 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7549 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7551 [(set_attr "type" "unknown")
7552 (set_attr "mode" "<MODE>")
7553 (set_attr "insn_count" "2")])
7555 (define_insn "*tls_get_tp_<mode>_split"
7556 [(set (reg:P TLS_GET_TP_REGNUM)
7557 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7558 "HAVE_AS_TLS && !TARGET_MIPS16"
7560 if (mips_isa_rev >= 2)
7561 return "rdhwr\t$3,$29";
7563 return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7565 [(set_attr "type" "unknown")
7566 ; Since rdhwr always generates a trap for now, putting it in a delay
7567 ; slot would make the kernel's emulation of it much slower.
7568 (set_attr "can_delay" "no")
7569 (set_attr "mode" "<MODE>")])
7571 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7572 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7573 ;; accessible in MIPS16.
7575 ;; This is not represented as a call insn, to avoid the
7576 ;; unnecesarry clobbering of caller-save registers by a
7577 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7579 ;; A $25 clobber is added to cater for a $25 load stub added by the
7580 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7582 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7583 [(set (match_operand:P 0 "register_operand" "=d")
7584 (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7586 (clobber (reg:P TLS_GET_TP_REGNUM))
7587 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7588 (clobber (reg:P RETURN_ADDR_REGNUM))]
7589 "HAVE_AS_TLS && TARGET_MIPS16"
7591 "&& reload_completed"
7592 [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7593 (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7594 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7595 (clobber (reg:P RETURN_ADDR_REGNUM))])
7596 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7598 [(set_attr "type" "multi")
7599 (set_attr "insn_count" "4")
7600 (set_attr "mode" "<MODE>")])
7602 (define_insn "*tls_get_tp_mips16_call_<mode>"
7603 [(set (reg:P TLS_GET_TP_REGNUM)
7604 (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7606 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7607 (clobber (reg:P RETURN_ADDR_REGNUM))]
7608 "HAVE_AS_TLS && TARGET_MIPS16"
7609 { return mips_output_jump (operands, 0, -1, true); }
7610 [(set_attr "type" "call")
7611 (set_attr "insn_count" "3")
7612 (set_attr "mode" "<MODE>")])
7614 ;; Named pattern for expanding thread pointer reference.
7615 (define_expand "get_thread_pointer<mode>"
7616 [(match_operand:P 0 "register_operand" "=d")]
7619 mips_expand_thread_pointer (operands[0]);
7623 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7624 (define_expand "mips_get_fcsr"
7625 [(set (match_operand:SI 0 "register_operand")
7626 (unspec_volatile:SI [(const_int 0)] UNSPEC_GET_FCSR))]
7627 "TARGET_HARD_FLOAT_ABI"
7631 mips16_expand_get_fcsr (operands[0]);
7636 (define_insn "*mips_get_fcsr"
7637 [(set (match_operand:SI 0 "register_operand" "=d")
7638 (unspec_volatile:SI [(const_int 0)] UNSPEC_GET_FCSR))]
7642 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7643 (define_insn "mips_get_fcsr_mips16_<mode>"
7644 [(set (reg:SI GET_FCSR_REGNUM)
7645 (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7647 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7648 (clobber (reg:P RETURN_ADDR_REGNUM))]
7649 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7650 { return mips_output_jump (operands, 0, -1, true); }
7651 [(set_attr "type" "call")
7652 (set_attr "insn_count" "3")])
7654 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7655 (define_expand "mips_set_fcsr"
7656 [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7658 "TARGET_HARD_FLOAT_ABI"
7662 mips16_expand_set_fcsr (operands[0]);
7667 (define_insn "*mips_set_fcsr"
7668 [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7673 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7674 (define_insn "mips_set_fcsr_mips16_<mode>"
7675 [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7676 (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7677 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7678 (clobber (reg:P RETURN_ADDR_REGNUM))]
7679 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7680 { return mips_output_jump (operands, 0, -1, true); }
7681 [(set_attr "type" "call")
7682 (set_attr "insn_count" "3")])
7684 ;; Match paired HI/SI/SF/DFmode load/stores.
7685 (define_insn "*join2_load_store<JOIN_MODE:mode>"
7686 [(set (match_operand:JOIN_MODE 0 "nonimmediate_operand" "=d,f,m,m")
7687 (match_operand:JOIN_MODE 1 "nonimmediate_operand" "m,m,d,f"))
7688 (set (match_operand:JOIN_MODE 2 "nonimmediate_operand" "=d,f,m,m")
7689 (match_operand:JOIN_MODE 3 "nonimmediate_operand" "m,m,d,f"))]
7690 "ENABLE_LD_ST_PAIRS && reload_completed"
7692 bool load_p = (which_alternative == 0 || which_alternative == 1);
7693 /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7694 Hardware does not bond those loads, even when they are consecutive.
7695 However, order of the loads need to be checked for correctness. */
7696 if (!load_p || !reg_overlap_mentioned_p (operands[0], operands[1]))
7698 output_asm_insn (mips_output_move (operands[0], operands[1]),
7700 output_asm_insn (mips_output_move (operands[2], operands[3]),
7705 output_asm_insn (mips_output_move (operands[2], operands[3]),
7707 output_asm_insn (mips_output_move (operands[0], operands[1]),
7712 [(set_attr "move_type" "load,fpload,store,fpstore")
7713 (set_attr "insn_count" "2,2,2,2")])
7715 ;; 2 HI/SI/SF/DF loads are joined.
7716 ;; P5600 does not support bonding of two LBs, hence QI mode is not included.
7717 ;; The loads must be non-volatile as they might be reordered at the time of asm
7720 [(set (match_operand:JOIN_MODE 0 "register_operand")
7721 (match_operand:JOIN_MODE 1 "non_volatile_mem_operand"))
7722 (set (match_operand:JOIN_MODE 2 "register_operand")
7723 (match_operand:JOIN_MODE 3 "non_volatile_mem_operand"))]
7725 && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, true)"
7726 [(parallel [(set (match_dup 0)
7732 ;; 2 HI/SI/SF/DF stores are joined.
7733 ;; P5600 does not support bonding of two SBs, hence QI mode is not included.
7735 [(set (match_operand:JOIN_MODE 0 "memory_operand")
7736 (match_operand:JOIN_MODE 1 "register_operand"))
7737 (set (match_operand:JOIN_MODE 2 "memory_operand")
7738 (match_operand:JOIN_MODE 3 "register_operand"))]
7740 && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, false)"
7741 [(parallel [(set (match_dup 0)
7747 ;; Match paired HImode loads.
7748 (define_insn "*join2_loadhi"
7749 [(set (match_operand:SI 0 "register_operand" "=r")
7750 (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand" "m")))
7751 (set (match_operand:SI 2 "register_operand" "=r")
7752 (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand" "m")))]
7753 "ENABLE_LD_ST_PAIRS && reload_completed"
7755 /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7756 Hardware does not bond those loads, even when they are consecutive.
7757 However, order of the loads need to be checked for correctness. */
7758 if (!reg_overlap_mentioned_p (operands[0], operands[1]))
7760 output_asm_insn ("lh<u>\t%0,%1", operands);
7761 output_asm_insn ("lh<u>\t%2,%3", operands);
7765 output_asm_insn ("lh<u>\t%2,%3", operands);
7766 output_asm_insn ("lh<u>\t%0,%1", operands);
7771 [(set_attr "move_type" "load")
7772 (set_attr "insn_count" "2")])
7775 ;; 2 HI loads are joined.
7777 [(set (match_operand:SI 0 "register_operand")
7778 (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand")))
7779 (set (match_operand:SI 2 "register_operand")
7780 (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand")))]
7782 && mips_load_store_bonding_p (operands, HImode, true)"
7783 [(parallel [(set (match_dup 0)
7784 (any_extend:SI (match_dup 1)))
7786 (any_extend:SI (match_dup 3)))])]
7790 ;; Synchronization instructions.
7794 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7796 (include "mips-ps-3d.md")
7798 ; The MIPS DSP Instructions.
7800 (include "mips-dsp.md")
7802 ; The MIPS DSP REV 2 Instructions.
7804 (include "mips-dspr2.md")
7806 ; MIPS fixed-point instructions.
7807 (include "mips-fixed.md")
7809 ; microMIPS patterns.
7810 (include "micromips.md")
7812 ; Loongson MultiMedia extensions Instructions (MMI) patterns.
7813 (include "loongson-mmi.md")
7815 ; The MIPS MSA Instructions.
7816 (include "mips-msa.md")
7818 (define_c_enum "unspec" [
7819 UNSPEC_ADDRESS_FIRST