1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 ;; 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
4 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
5 ;; Changes by Michael Meissner, meissner@osf.org
6 ;; 64 bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
7 ;; Brendan Eich, brendan@microunity.com.
9 ;; This file is part of GCC.
11 ;; GCC is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GCC is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GCC; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
27 [(UNSPEC_LOAD_DF_LOW 0)
28 (UNSPEC_LOAD_DF_HIGH 1)
29 (UNSPEC_STORE_DF_HIGH 2)
33 (UNSPEC_EH_RECEIVER 6)
35 (UNSPEC_CONSTTABLE_INT 8)
36 (UNSPEC_CONSTTABLE_FLOAT 9)
40 (UNSPEC_LOAD_RIGHT 19)
41 (UNSPEC_STORE_LEFT 20)
42 (UNSPEC_STORE_RIGHT 21)
49 (UNSPEC_ADDRESS_FIRST 100)
53 ;; For MIPS Paired-Singled Floating Point Instructions.
55 (UNSPEC_MOVE_TF_PS 200)
58 ;; MIPS64/MIPS32R2 alnv.ps
61 ;; MIPS-3D instructions
65 (UNSPEC_CVT_PW_PS 205)
66 (UNSPEC_CVT_PS_PW 206)
76 (include "predicates.md")
78 ;; ....................
82 ;; ....................
84 (define_attr "got" "unset,xgot_high,load"
85 (const_string "unset"))
87 ;; For jal instructions, this attribute is DIRECT when the target address
88 ;; is symbolic and INDIRECT when it is a register.
89 (define_attr "jal" "unset,direct,indirect"
90 (const_string "unset"))
92 ;; This attribute is YES if the instruction is a jal macro (not a
93 ;; real jal instruction).
95 ;; jal is always a macro in SVR4 PIC since it includes an instruction to
96 ;; restore $gp. Direct jals are also macros in NewABI PIC since they
97 ;; load the target address into $25.
98 (define_attr "jal_macro" "no,yes"
99 (cond [(eq_attr "jal" "direct")
100 (symbol_ref "TARGET_ABICALLS != 0")
101 (eq_attr "jal" "indirect")
102 (symbol_ref "(TARGET_ABICALLS && !TARGET_NEWABI) != 0")]
103 (const_string "no")))
105 ;; Classification of each insn.
106 ;; branch conditional branch
107 ;; jump unconditional jump
108 ;; call unconditional call
109 ;; load load instruction(s)
110 ;; fpload floating point load
111 ;; fpidxload floating point indexed load
112 ;; store store instruction(s)
113 ;; fpstore floating point store
114 ;; fpidxstore floating point indexed store
115 ;; prefetch memory prefetch (register + offset)
116 ;; prefetchx memory indexed prefetch (register + register)
117 ;; condmove conditional moves
118 ;; xfer transfer to/from coprocessor
119 ;; mthilo transfer to hi/lo registers
120 ;; mfhilo transfer from hi/lo registers
121 ;; const load constant
122 ;; arith integer arithmetic and logical instructions
123 ;; shift integer shift instructions
124 ;; slt set less than instructions
125 ;; clz the clz and clo instructions
126 ;; trap trap if instructions
127 ;; imul integer multiply
128 ;; imadd integer multiply-add
129 ;; idiv integer divide
130 ;; fmove floating point register move
131 ;; fadd floating point add/subtract
132 ;; fmul floating point multiply
133 ;; fmadd floating point multiply-add
134 ;; fdiv floating point divide
135 ;; frdiv floating point reciprocal divide
136 ;; frdiv1 floating point reciprocal divide step 1
137 ;; frdiv2 floating point reciprocal divide step 2
138 ;; fabs floating point absolute value
139 ;; fneg floating point negation
140 ;; fcmp floating point compare
141 ;; fcvt floating point convert
142 ;; fsqrt floating point square root
143 ;; frsqrt floating point reciprocal square root
144 ;; frsqrt1 floating point reciprocal square root step1
145 ;; frsqrt2 floating point reciprocal square root step2
146 ;; multi multiword sequence (or user asm statements)
149 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,prefetch,prefetchx,condmove,xfer,mthilo,mfhilo,const,arith,shift,slt,clz,trap,imul,imadd,idiv,fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,frsqrt,frsqrt1,frsqrt2,multi,nop"
150 (cond [(eq_attr "jal" "!unset") (const_string "call")
151 (eq_attr "got" "load") (const_string "load")]
152 (const_string "unknown")))
154 ;; Main data type used by the insn
155 (define_attr "mode" "unknown,none,QI,HI,SI,DI,SF,DF,FPSW"
156 (const_string "unknown"))
158 ;; Is this an extended instruction in mips16 mode?
159 (define_attr "extended_mips16" "no,yes"
162 ;; Length of instruction in bytes.
163 (define_attr "length" ""
164 (cond [;; Direct branch instructions have a range of [-0x40000,0x3fffc].
165 ;; If a branch is outside this range, we have a choice of two
166 ;; sequences. For PIC, an out-of-range branch like:
171 ;; becomes the equivalent of:
180 ;; where the load address can be up to three instructions long
183 ;; The non-PIC case is similar except that we use a direct
184 ;; jump instead of an la/jr pair. Since the target of this
185 ;; jump is an absolute 28-bit bit address (the other bits
186 ;; coming from the address of the delay slot) this form cannot
187 ;; cross a 256MB boundary. We could provide the option of
188 ;; using la/jr in this case too, but we do not do so at
191 ;; Note that this value does not account for the delay slot
192 ;; instruction, whose length is added separately. If the RTL
193 ;; pattern has no explicit delay slot, mips_adjust_insn_length
194 ;; will add the length of the implicit nop. The values for
195 ;; forward and backward branches will be different as well.
196 (eq_attr "type" "branch")
197 (cond [(and (le (minus (match_dup 1) (pc)) (const_int 131064))
198 (le (minus (pc) (match_dup 1)) (const_int 131068)))
200 (ne (symbol_ref "flag_pic") (const_int 0))
204 (eq_attr "got" "load")
206 (eq_attr "got" "xgot_high")
209 (eq_attr "type" "const")
210 (symbol_ref "mips_const_insns (operands[1]) * 4")
211 (eq_attr "type" "load,fpload")
212 (symbol_ref "mips_fetch_insns (operands[1]) * 4")
213 (eq_attr "type" "store,fpstore")
214 (symbol_ref "mips_fetch_insns (operands[0]) * 4")
216 ;; In the worst case, a call macro will take 8 instructions:
218 ;; lui $25,%call_hi(FOO)
220 ;; lw $25,%call_lo(FOO)($25)
226 (eq_attr "jal_macro" "yes")
229 (and (eq_attr "extended_mips16" "yes")
230 (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
233 ;; Various VR4120 errata require a nop to be inserted after a macc
234 ;; instruction. The assembler does this for us, so account for
235 ;; the worst-case length here.
236 (and (eq_attr "type" "imadd")
237 (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0)))
240 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
241 ;; the result of the second one is missed. The assembler should work
242 ;; around this by inserting a nop after the first dmult.
243 (and (eq_attr "type" "imul")
244 (and (eq_attr "mode" "DI")
245 (ne (symbol_ref "TARGET_FIX_VR4120") (const_int 0))))
248 (eq_attr "type" "idiv")
249 (symbol_ref "mips_idiv_insns () * 4")
252 ;; Attribute describing the processor. This attribute must match exactly
253 ;; with the processor_type enumeration in mips.h.
255 "default,4kc,5kc,20kc,m4k,r3000,r3900,r6000,r4000,r4100,r4111,r4120,r4130,r4300,r4600,r4650,r5000,r5400,r5500,r7000,r8000,r9000,sb1,sr71000"
256 (const (symbol_ref "mips_tune")))
258 ;; The type of hardware hazard associated with this instruction.
259 ;; DELAY means that the next instruction cannot read the result
260 ;; of this one. HILO means that the next two instructions cannot
261 ;; write to HI or LO.
262 (define_attr "hazard" "none,delay,hilo"
263 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
264 (ne (symbol_ref "ISA_HAS_LOAD_DELAY") (const_int 0)))
265 (const_string "delay")
267 (and (eq_attr "type" "xfer")
268 (ne (symbol_ref "ISA_HAS_XFER_DELAY") (const_int 0)))
269 (const_string "delay")
271 (and (eq_attr "type" "fcmp")
272 (ne (symbol_ref "ISA_HAS_FCMP_DELAY") (const_int 0)))
273 (const_string "delay")
275 ;; The r4000 multiplication patterns include an mflo instruction.
276 (and (eq_attr "type" "imul")
277 (ne (symbol_ref "TARGET_FIX_R4000") (const_int 0)))
278 (const_string "hilo")
280 (and (eq_attr "type" "mfhilo")
281 (eq (symbol_ref "ISA_HAS_HILO_INTERLOCKS") (const_int 0)))
282 (const_string "hilo")]
283 (const_string "none")))
285 ;; Is it a single instruction?
286 (define_attr "single_insn" "no,yes"
287 (symbol_ref "get_attr_length (insn) == (TARGET_MIPS16 ? 2 : 4)"))
289 ;; Can the instruction be put into a delay slot?
290 (define_attr "can_delay" "no,yes"
291 (if_then_else (and (eq_attr "type" "!branch,call,jump")
292 (and (eq_attr "hazard" "none")
293 (eq_attr "single_insn" "yes")))
295 (const_string "no")))
297 ;; Attribute defining whether or not we can use the branch-likely instructions
298 (define_attr "branch_likely" "no,yes"
300 (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
302 (const_string "no"))))
304 ;; True if an instruction might assign to hi or lo when reloaded.
305 ;; This is used by the TUNE_MACC_CHAINS code.
306 (define_attr "may_clobber_hilo" "no,yes"
307 (if_then_else (eq_attr "type" "imul,imadd,idiv,mthilo")
309 (const_string "no")))
311 ;; Describe a user's asm statement.
312 (define_asm_attributes
313 [(set_attr "type" "multi")
314 (set_attr "can_delay" "no")])
316 ;; This mode macro allows 32-bit and 64-bit GPR patterns to be generated
317 ;; from the same template.
318 (define_mode_macro GPR [SI (DI "TARGET_64BIT")])
320 ;; This mode macro allows :P to be used for patterns that operate on
321 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
322 (define_mode_macro P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
324 ;; This mode macro allows :MOVECC to be used anywhere that a
325 ;; conditional-move-type condition is needed.
326 (define_mode_macro MOVECC [SI (DI "TARGET_64BIT") (CC "TARGET_HARD_FLOAT")])
328 ;; This mode macro allows the QI and HI extension patterns to be defined from
329 ;; the same template.
330 (define_mode_macro SHORT [QI HI])
332 ;; This mode macro allows :ANYF to be used wherever a scalar or vector
333 ;; floating-point mode is allowed.
334 (define_mode_macro ANYF [(SF "TARGET_HARD_FLOAT")
335 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
336 (V2SF "TARGET_PAIRED_SINGLE_FLOAT")])
338 ;; Like ANYF, but only applies to scalar modes.
339 (define_mode_macro SCALARF [(SF "TARGET_HARD_FLOAT")
340 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
342 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
343 ;; 32-bit version and "dsubu" in the 64-bit version.
344 (define_mode_attr d [(SI "") (DI "d")])
346 ;; This attribute gives the length suffix for a sign- or zero-extension
348 (define_mode_attr size [(QI "b") (HI "h")])
350 ;; This attributes gives the mode mask of a SHORT.
351 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
353 ;; Mode attributes for GPR loads and stores.
354 (define_mode_attr load [(SI "lw") (DI "ld")])
355 (define_mode_attr store [(SI "sw") (DI "sd")])
357 ;; Similarly for MIPS IV indexed FPR loads and stores.
358 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
359 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
361 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
362 ;; are different. Some forms of unextended addiu have an 8-bit immediate
363 ;; field but the equivalent daddiu has only a 5-bit field.
364 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
366 ;; This attribute gives the best constraint to use for registers of
368 (define_mode_attr reg [(SI "d") (DI "d") (CC "z")])
370 ;; This attribute gives the format suffix for floating-point operations.
371 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
373 ;; This attribute gives the upper-case mode name for one unit of a
374 ;; floating-point mode.
375 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF")])
377 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
379 ;; In certain cases, div.s and div.ps may have a rounding error
380 ;; and/or wrong inexact flag.
382 ;; Therefore, we only allow div.s if not working around SB-1 rev2
383 ;; errata or if a slight loss of precision is OK.
384 (define_mode_attr divide_condition
385 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
386 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
388 ; This attribute gives the condition for which sqrt instructions exist.
389 (define_mode_attr sqrt_condition
390 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
392 ; This attribute gives the condition for which recip and rsqrt instructions
394 (define_mode_attr recip_condition
395 [(SF "ISA_HAS_FP4") (DF "ISA_HAS_FP4") (V2SF "TARGET_SB1")])
397 ;; This code macro allows all branch instructions to be generated from
398 ;; a single define_expand template.
399 (define_code_macro any_cond [unordered ordered unlt unge uneq ltgt unle ungt
400 eq ne gt ge lt le gtu geu ltu leu])
402 ;; This code macro allows signed and unsigned widening multiplications
403 ;; to use the same template.
404 (define_code_macro any_extend [sign_extend zero_extend])
406 ;; This code macro allows the three shift instructions to be generated
407 ;; from the same template.
408 (define_code_macro any_shift [ashift ashiftrt lshiftrt])
410 ;; This code macro allows all native floating-point comparisons to be
411 ;; generated from the same template.
412 (define_code_macro fcond [unordered uneq unlt unle eq lt le])
414 ;; <u> expands to an empty string when doing a signed operation and
415 ;; "u" when doing an unsigned operation.
416 (define_code_attr u [(sign_extend "") (zero_extend "u")])
418 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
419 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
421 ;; <optab> expands to the name of the optab for a particular code.
422 (define_code_attr optab [(ashift "ashl")
426 ;; <insn> expands to the name of the insn that implements a particular code.
427 (define_code_attr insn [(ashift "sll")
431 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
432 (define_code_attr fcond [(unordered "un")
440 ;; .........................
442 ;; Branch, call and jump delay slots
444 ;; .........................
446 (define_delay (and (eq_attr "type" "branch")
447 (eq (symbol_ref "TARGET_MIPS16") (const_int 0)))
448 [(eq_attr "can_delay" "yes")
450 (and (eq_attr "branch_likely" "yes")
451 (eq_attr "can_delay" "yes"))])
453 (define_delay (eq_attr "type" "jump")
454 [(eq_attr "can_delay" "yes")
458 (define_delay (and (eq_attr "type" "call")
459 (eq_attr "jal_macro" "no"))
460 [(eq_attr "can_delay" "yes")
464 ;; Pipeline descriptions.
466 ;; generic.md provides a fallback for processors without a specific
467 ;; pipeline description. It is derived from the old define_function_unit
468 ;; version and uses the "alu" and "imuldiv" units declared below.
470 ;; Some of the processor-specific files are also derived from old
471 ;; define_function_unit descriptions and simply override the parts of
472 ;; generic.md that don't apply. The other processor-specific files
473 ;; are self-contained.
474 (define_automaton "alu,imuldiv")
476 (define_cpu_unit "alu" "alu")
477 (define_cpu_unit "imuldiv" "imuldiv")
493 (include "generic.md")
496 ;; ....................
500 ;; ....................
504 [(trap_if (const_int 1) (const_int 0))]
507 if (ISA_HAS_COND_TRAP)
509 else if (TARGET_MIPS16)
514 [(set_attr "type" "trap")])
516 (define_expand "conditional_trap"
517 [(trap_if (match_operator 0 "comparison_operator"
518 [(match_dup 2) (match_dup 3)])
519 (match_operand 1 "const_int_operand"))]
522 if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT
523 && operands[1] == const0_rtx)
525 mips_gen_conditional_trap (operands);
532 (define_insn "*conditional_trap<mode>"
533 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
534 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
535 (match_operand:GPR 2 "arith_operand" "dI")])
539 [(set_attr "type" "trap")])
542 ;; ....................
546 ;; ....................
549 (define_insn "add<mode>3"
550 [(set (match_operand:ANYF 0 "register_operand" "=f")
551 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
552 (match_operand:ANYF 2 "register_operand" "f")))]
554 "add.<fmt>\t%0,%1,%2"
555 [(set_attr "type" "fadd")
556 (set_attr "mode" "<UNITMODE>")])
558 (define_expand "add<mode>3"
559 [(set (match_operand:GPR 0 "register_operand")
560 (plus:GPR (match_operand:GPR 1 "register_operand")
561 (match_operand:GPR 2 "arith_operand")))]
564 (define_insn "*add<mode>3"
565 [(set (match_operand:GPR 0 "register_operand" "=d,d")
566 (plus:GPR (match_operand:GPR 1 "register_operand" "d,d")
567 (match_operand:GPR 2 "arith_operand" "d,Q")))]
572 [(set_attr "type" "arith")
573 (set_attr "mode" "<MODE>")])
575 ;; We need to recognize MIPS16 stack pointer additions explicitly, since
576 ;; we don't have a constraint for $sp. These insns will be generated by
577 ;; the save_restore_insns functions.
579 (define_insn "*add<mode>3_sp1"
581 (plus:GPR (reg:GPR 29)
582 (match_operand:GPR 0 "const_arith_operand" "")))]
585 [(set_attr "type" "arith")
586 (set_attr "mode" "<MODE>")
587 (set (attr "length") (if_then_else (match_operand 0 "m16_simm8_8")
591 (define_insn "*add<mode>3_sp2"
592 [(set (match_operand:GPR 0 "register_operand" "=d")
593 (plus:GPR (reg:GPR 29)
594 (match_operand:GPR 1 "const_arith_operand" "")))]
597 [(set_attr "type" "arith")
598 (set_attr "mode" "<MODE>")
599 (set (attr "length") (if_then_else (match_operand 1 "m16_uimm<si8_di5>_4")
603 (define_insn "*add<mode>3_mips16"
604 [(set (match_operand:GPR 0 "register_operand" "=d,d,d")
605 (plus:GPR (match_operand:GPR 1 "register_operand" "0,d,d")
606 (match_operand:GPR 2 "arith_operand" "Q,O,d")))]
612 [(set_attr "type" "arith")
613 (set_attr "mode" "<MODE>")
614 (set_attr_alternative "length"
615 [(if_then_else (match_operand 2 "m16_simm<si8_di5>_1")
618 (if_then_else (match_operand 2 "m16_simm4_1")
624 ;; On the mips16, we can sometimes split an add of a constant which is
625 ;; a 4 byte instruction into two adds which are both 2 byte
626 ;; instructions. There are two cases: one where we are adding a
627 ;; constant plus a register to another register, and one where we are
628 ;; simply adding a constant to a register.
631 [(set (match_operand:SI 0 "register_operand")
632 (plus:SI (match_dup 0)
633 (match_operand:SI 1 "const_int_operand")))]
634 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
635 && GET_CODE (operands[0]) == REG
636 && M16_REG_P (REGNO (operands[0]))
637 && GET_CODE (operands[1]) == CONST_INT
638 && ((INTVAL (operands[1]) > 0x7f
639 && INTVAL (operands[1]) <= 0x7f + 0x7f)
640 || (INTVAL (operands[1]) < - 0x80
641 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
642 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
643 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
645 HOST_WIDE_INT val = INTVAL (operands[1]);
649 operands[1] = GEN_INT (0x7f);
650 operands[2] = GEN_INT (val - 0x7f);
654 operands[1] = GEN_INT (- 0x80);
655 operands[2] = GEN_INT (val + 0x80);
660 [(set (match_operand:SI 0 "register_operand")
661 (plus:SI (match_operand:SI 1 "register_operand")
662 (match_operand:SI 2 "const_int_operand")))]
663 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
664 && GET_CODE (operands[0]) == REG
665 && M16_REG_P (REGNO (operands[0]))
666 && GET_CODE (operands[1]) == REG
667 && M16_REG_P (REGNO (operands[1]))
668 && REGNO (operands[0]) != REGNO (operands[1])
669 && GET_CODE (operands[2]) == CONST_INT
670 && ((INTVAL (operands[2]) > 0x7
671 && INTVAL (operands[2]) <= 0x7 + 0x7f)
672 || (INTVAL (operands[2]) < - 0x8
673 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
674 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
675 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
677 HOST_WIDE_INT val = INTVAL (operands[2]);
681 operands[2] = GEN_INT (0x7);
682 operands[3] = GEN_INT (val - 0x7);
686 operands[2] = GEN_INT (- 0x8);
687 operands[3] = GEN_INT (val + 0x8);
692 [(set (match_operand:DI 0 "register_operand")
693 (plus:DI (match_dup 0)
694 (match_operand:DI 1 "const_int_operand")))]
695 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
696 && GET_CODE (operands[0]) == REG
697 && M16_REG_P (REGNO (operands[0]))
698 && GET_CODE (operands[1]) == CONST_INT
699 && ((INTVAL (operands[1]) > 0xf
700 && INTVAL (operands[1]) <= 0xf + 0xf)
701 || (INTVAL (operands[1]) < - 0x10
702 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
703 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
704 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
706 HOST_WIDE_INT val = INTVAL (operands[1]);
710 operands[1] = GEN_INT (0xf);
711 operands[2] = GEN_INT (val - 0xf);
715 operands[1] = GEN_INT (- 0x10);
716 operands[2] = GEN_INT (val + 0x10);
721 [(set (match_operand:DI 0 "register_operand")
722 (plus:DI (match_operand:DI 1 "register_operand")
723 (match_operand:DI 2 "const_int_operand")))]
724 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
725 && GET_CODE (operands[0]) == REG
726 && M16_REG_P (REGNO (operands[0]))
727 && GET_CODE (operands[1]) == REG
728 && M16_REG_P (REGNO (operands[1]))
729 && REGNO (operands[0]) != REGNO (operands[1])
730 && GET_CODE (operands[2]) == CONST_INT
731 && ((INTVAL (operands[2]) > 0x7
732 && INTVAL (operands[2]) <= 0x7 + 0xf)
733 || (INTVAL (operands[2]) < - 0x8
734 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
735 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
736 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
738 HOST_WIDE_INT val = INTVAL (operands[2]);
742 operands[2] = GEN_INT (0x7);
743 operands[3] = GEN_INT (val - 0x7);
747 operands[2] = GEN_INT (- 0x8);
748 operands[3] = GEN_INT (val + 0x8);
752 (define_insn "*addsi3_extended"
753 [(set (match_operand:DI 0 "register_operand" "=d,d")
755 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
756 (match_operand:SI 2 "arith_operand" "d,Q"))))]
757 "TARGET_64BIT && !TARGET_MIPS16"
761 [(set_attr "type" "arith")
762 (set_attr "mode" "SI")])
764 ;; Split this insn so that the addiu splitters can have a crack at it.
765 ;; Use a conservative length estimate until the split.
766 (define_insn_and_split "*addsi3_extended_mips16"
767 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
769 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
770 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
771 "TARGET_64BIT && TARGET_MIPS16"
773 "&& reload_completed"
774 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
775 { operands[3] = gen_lowpart (SImode, operands[0]); }
776 [(set_attr "type" "arith")
777 (set_attr "mode" "SI")
778 (set_attr "extended_mips16" "yes")])
781 ;; ....................
785 ;; ....................
788 (define_insn "sub<mode>3"
789 [(set (match_operand:ANYF 0 "register_operand" "=f")
790 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
791 (match_operand:ANYF 2 "register_operand" "f")))]
793 "sub.<fmt>\t%0,%1,%2"
794 [(set_attr "type" "fadd")
795 (set_attr "mode" "<UNITMODE>")])
797 (define_insn "sub<mode>3"
798 [(set (match_operand:GPR 0 "register_operand" "=d")
799 (minus:GPR (match_operand:GPR 1 "register_operand" "d")
800 (match_operand:GPR 2 "register_operand" "d")))]
803 [(set_attr "type" "arith")
804 (set_attr "mode" "<MODE>")])
806 (define_insn "*subsi3_extended"
807 [(set (match_operand:DI 0 "register_operand" "=d")
809 (minus:SI (match_operand:SI 1 "register_operand" "d")
810 (match_operand:SI 2 "register_operand" "d"))))]
813 [(set_attr "type" "arith")
814 (set_attr "mode" "DI")])
817 ;; ....................
821 ;; ....................
824 (define_expand "mul<mode>3"
825 [(set (match_operand:SCALARF 0 "register_operand")
826 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
827 (match_operand:SCALARF 2 "register_operand")))]
831 (define_insn "*mul<mode>3"
832 [(set (match_operand:SCALARF 0 "register_operand" "=f")
833 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
834 (match_operand:SCALARF 2 "register_operand" "f")))]
835 "!TARGET_4300_MUL_FIX"
836 "mul.<fmt>\t%0,%1,%2"
837 [(set_attr "type" "fmul")
838 (set_attr "mode" "<MODE>")])
840 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
841 ;; operands may corrupt immediately following multiplies. This is a
842 ;; simple fix to insert NOPs.
844 (define_insn "*mul<mode>3_r4300"
845 [(set (match_operand:SCALARF 0 "register_operand" "=f")
846 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
847 (match_operand:SCALARF 2 "register_operand" "f")))]
848 "TARGET_4300_MUL_FIX"
849 "mul.<fmt>\t%0,%1,%2\;nop"
850 [(set_attr "type" "fmul")
851 (set_attr "mode" "<MODE>")
852 (set_attr "length" "8")])
854 (define_insn "mulv2sf3"
855 [(set (match_operand:V2SF 0 "register_operand" "=f")
856 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
857 (match_operand:V2SF 2 "register_operand" "f")))]
858 "TARGET_PAIRED_SINGLE_FLOAT"
860 [(set_attr "type" "fmul")
861 (set_attr "mode" "SF")])
863 ;; The original R4000 has a cpu bug. If a double-word or a variable
864 ;; shift executes while an integer multiplication is in progress, the
865 ;; shift may give an incorrect result. Avoid this by keeping the mflo
866 ;; with the mult on the R4000.
868 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
869 ;; (also valid for MIPS R4000MC processors):
871 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
872 ;; this errata description.
873 ;; The following code sequence causes the R4000 to incorrectly
874 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
875 ;; instruction. If the dsra32 instruction is executed during an
876 ;; integer multiply, the dsra32 will only shift by the amount in
877 ;; specified in the instruction rather than the amount plus 32
879 ;; instruction 1: mult rs,rt integer multiply
880 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
881 ;; right arithmetic + 32
882 ;; Workaround: A dsra32 instruction placed after an integer
883 ;; multiply should not be one of the 11 instructions after the
884 ;; multiply instruction."
888 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
889 ;; the following description.
890 ;; All extended shifts (shift by n+32) and variable shifts (32 and
891 ;; 64-bit versions) may produce incorrect results under the
892 ;; following conditions:
893 ;; 1) An integer multiply is currently executing
894 ;; 2) These types of shift instructions are executed immediately
895 ;; following an integer divide instruction.
897 ;; 1) Make sure no integer multiply is running wihen these
898 ;; instruction are executed. If this cannot be predicted at
899 ;; compile time, then insert a "mfhi" to R0 instruction
900 ;; immediately after the integer multiply instruction. This
901 ;; will cause the integer multiply to complete before the shift
903 ;; 2) Separate integer divide and these two classes of shift
904 ;; instructions by another instruction or a noop."
906 ;; These processors have PRId values of 0x00004220 and 0x00004300,
909 (define_expand "mul<mode>3"
910 [(set (match_operand:GPR 0 "register_operand")
911 (mult:GPR (match_operand:GPR 1 "register_operand")
912 (match_operand:GPR 2 "register_operand")))]
915 if (GENERATE_MULT3_<MODE>)
916 emit_insn (gen_mul<mode>3_mult3 (operands[0], operands[1], operands[2]));
917 else if (!TARGET_FIX_R4000)
918 emit_insn (gen_mul<mode>3_internal (operands[0], operands[1],
921 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
925 (define_insn "mulsi3_mult3"
926 [(set (match_operand:SI 0 "register_operand" "=d,l")
927 (mult:SI (match_operand:SI 1 "register_operand" "d,d")
928 (match_operand:SI 2 "register_operand" "d,d")))
929 (clobber (match_scratch:SI 3 "=h,h"))
930 (clobber (match_scratch:SI 4 "=l,X"))]
933 if (which_alternative == 1)
934 return "mult\t%1,%2";
943 return "mul\t%0,%1,%2";
944 return "mult\t%0,%1,%2";
946 [(set_attr "type" "imul")
947 (set_attr "mode" "SI")])
949 (define_insn "muldi3_mult3"
950 [(set (match_operand:DI 0 "register_operand" "=d")
951 (mult:DI (match_operand:DI 1 "register_operand" "d")
952 (match_operand:DI 2 "register_operand" "d")))
953 (clobber (match_scratch:DI 3 "=h"))
954 (clobber (match_scratch:DI 4 "=l"))]
955 "TARGET_64BIT && GENERATE_MULT3_DI"
957 [(set_attr "type" "imul")
958 (set_attr "mode" "DI")])
960 ;; If a register gets allocated to LO, and we spill to memory, the reload
961 ;; will include a move from LO to a GPR. Merge it into the multiplication
962 ;; if it can set the GPR directly.
965 ;; Operand 1: GPR (1st multiplication operand)
966 ;; Operand 2: GPR (2nd multiplication operand)
968 ;; Operand 4: GPR (destination)
971 [(set (match_operand:SI 0 "register_operand")
972 (mult:SI (match_operand:SI 1 "register_operand")
973 (match_operand:SI 2 "register_operand")))
974 (clobber (match_operand:SI 3 "register_operand"))
975 (clobber (scratch:SI))])
976 (set (match_operand:SI 4 "register_operand")
977 (unspec [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
978 "GENERATE_MULT3_SI && peep2_reg_dead_p (2, operands[0])"
981 (mult:SI (match_dup 1)
983 (clobber (match_dup 3))
984 (clobber (match_dup 0))])])
986 (define_insn "mul<mode>3_internal"
987 [(set (match_operand:GPR 0 "register_operand" "=l")
988 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
989 (match_operand:GPR 2 "register_operand" "d")))
990 (clobber (match_scratch:GPR 3 "=h"))]
993 [(set_attr "type" "imul")
994 (set_attr "mode" "<MODE>")])
996 (define_insn "mul<mode>3_r4000"
997 [(set (match_operand:GPR 0 "register_operand" "=d")
998 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
999 (match_operand:GPR 2 "register_operand" "d")))
1000 (clobber (match_scratch:GPR 3 "=h"))
1001 (clobber (match_scratch:GPR 4 "=l"))]
1003 "<d>mult\t%1,%2\;mflo\t%0"
1004 [(set_attr "type" "imul")
1005 (set_attr "mode" "<MODE>")
1006 (set_attr "length" "8")])
1008 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1009 ;; of "mult; mflo". They have the same latency, but the first form gives
1010 ;; us an extra cycle to compute the operands.
1013 ;; Operand 1: GPR (1st multiplication operand)
1014 ;; Operand 2: GPR (2nd multiplication operand)
1016 ;; Operand 4: GPR (destination)
1019 [(set (match_operand:SI 0 "register_operand")
1020 (mult:SI (match_operand:SI 1 "register_operand")
1021 (match_operand:SI 2 "register_operand")))
1022 (clobber (match_operand:SI 3 "register_operand"))])
1023 (set (match_operand:SI 4 "register_operand")
1024 (unspec:SI [(match_dup 0) (match_dup 3)] UNSPEC_MFHILO))]
1025 "ISA_HAS_MACC && !GENERATE_MULT3_SI"
1030 (plus:SI (mult:SI (match_dup 1)
1034 (plus:SI (mult:SI (match_dup 1)
1037 (clobber (match_dup 3))])])
1039 ;; Multiply-accumulate patterns
1041 ;; For processors that can copy the output to a general register:
1043 ;; The all-d alternative is needed because the combiner will find this
1044 ;; pattern and then register alloc/reload will move registers around to
1045 ;; make them fit, and we don't want to trigger unnecessary loads to LO.
1047 ;; The last alternative should be made slightly less desirable, but adding
1048 ;; "?" to the constraint is too strong, and causes values to be loaded into
1049 ;; LO even when that's more costly. For now, using "*d" mostly does the
1051 (define_insn "*mul_acc_si"
1052 [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1053 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1054 (match_operand:SI 2 "register_operand" "d,d,d"))
1055 (match_operand:SI 3 "register_operand" "0,l,*d")))
1056 (clobber (match_scratch:SI 4 "=h,h,h"))
1057 (clobber (match_scratch:SI 5 "=X,3,l"))
1058 (clobber (match_scratch:SI 6 "=X,X,&d"))]
1060 || ISA_HAS_MADD_MSUB)
1063 static const char *const madd[] = { "madd\t%1,%2", "madd\t%0,%1,%2" };
1064 if (which_alternative == 2)
1066 if (ISA_HAS_MADD_MSUB && which_alternative != 0)
1068 return madd[which_alternative];
1070 [(set_attr "type" "imadd,imadd,multi")
1071 (set_attr "mode" "SI")
1072 (set_attr "length" "4,4,8")])
1074 ;; Split the above insn if we failed to get LO allocated.
1076 [(set (match_operand:SI 0 "register_operand")
1077 (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1078 (match_operand:SI 2 "register_operand"))
1079 (match_operand:SI 3 "register_operand")))
1080 (clobber (match_scratch:SI 4))
1081 (clobber (match_scratch:SI 5))
1082 (clobber (match_scratch:SI 6))]
1083 "reload_completed && !TARGET_DEBUG_D_MODE
1084 && GP_REG_P (true_regnum (operands[0]))
1085 && GP_REG_P (true_regnum (operands[3]))"
1086 [(parallel [(set (match_dup 6)
1087 (mult:SI (match_dup 1) (match_dup 2)))
1088 (clobber (match_dup 4))
1089 (clobber (match_dup 5))])
1090 (set (match_dup 0) (plus:SI (match_dup 6) (match_dup 3)))]
1093 ;; Splitter to copy result of MADD to a general register
1095 [(set (match_operand:SI 0 "register_operand")
1096 (plus:SI (mult:SI (match_operand:SI 1 "register_operand")
1097 (match_operand:SI 2 "register_operand"))
1098 (match_operand:SI 3 "register_operand")))
1099 (clobber (match_scratch:SI 4))
1100 (clobber (match_scratch:SI 5))
1101 (clobber (match_scratch:SI 6))]
1102 "reload_completed && !TARGET_DEBUG_D_MODE
1103 && GP_REG_P (true_regnum (operands[0]))
1104 && true_regnum (operands[3]) == LO_REGNUM"
1105 [(parallel [(set (match_dup 3)
1106 (plus:SI (mult:SI (match_dup 1) (match_dup 2))
1108 (clobber (match_dup 4))
1109 (clobber (match_dup 5))
1110 (clobber (match_dup 6))])
1111 (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1114 (define_insn "*macc"
1115 [(set (match_operand:SI 0 "register_operand" "=l,d")
1116 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1117 (match_operand:SI 2 "register_operand" "d,d"))
1118 (match_operand:SI 3 "register_operand" "0,l")))
1119 (clobber (match_scratch:SI 4 "=h,h"))
1120 (clobber (match_scratch:SI 5 "=X,3"))]
1123 if (which_alternative == 1)
1124 return "macc\t%0,%1,%2";
1125 else if (TARGET_MIPS5500)
1126 return "madd\t%1,%2";
1128 /* The VR4130 assumes that there is a two-cycle latency between a macc
1129 that "writes" to $0 and an instruction that reads from it. We avoid
1130 this by assigning to $1 instead. */
1131 return "%[macc\t%@,%1,%2%]";
1133 [(set_attr "type" "imadd")
1134 (set_attr "mode" "SI")])
1136 (define_insn "*msac"
1137 [(set (match_operand:SI 0 "register_operand" "=l,d")
1138 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1139 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1140 (match_operand:SI 3 "register_operand" "d,d"))))
1141 (clobber (match_scratch:SI 4 "=h,h"))
1142 (clobber (match_scratch:SI 5 "=X,1"))]
1145 if (which_alternative == 1)
1146 return "msac\t%0,%2,%3";
1147 else if (TARGET_MIPS5500)
1148 return "msub\t%2,%3";
1150 return "msac\t$0,%2,%3";
1152 [(set_attr "type" "imadd")
1153 (set_attr "mode" "SI")])
1155 ;; An msac-like instruction implemented using negation and a macc.
1156 (define_insn_and_split "*msac_using_macc"
1157 [(set (match_operand:SI 0 "register_operand" "=l,d")
1158 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1159 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1160 (match_operand:SI 3 "register_operand" "d,d"))))
1161 (clobber (match_scratch:SI 4 "=h,h"))
1162 (clobber (match_scratch:SI 5 "=X,1"))
1163 (clobber (match_scratch:SI 6 "=d,d"))]
1164 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1166 "&& reload_completed"
1168 (neg:SI (match_dup 3)))
1171 (plus:SI (mult:SI (match_dup 2)
1174 (clobber (match_dup 4))
1175 (clobber (match_dup 5))])]
1177 [(set_attr "type" "imadd")
1178 (set_attr "length" "8")])
1180 ;; Patterns generated by the define_peephole2 below.
1182 (define_insn "*macc2"
1183 [(set (match_operand:SI 0 "register_operand" "=l")
1184 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1185 (match_operand:SI 2 "register_operand" "d"))
1187 (set (match_operand:SI 3 "register_operand" "=d")
1188 (plus:SI (mult:SI (match_dup 1)
1191 (clobber (match_scratch:SI 4 "=h"))]
1192 "ISA_HAS_MACC && reload_completed"
1194 [(set_attr "type" "imadd")
1195 (set_attr "mode" "SI")])
1197 (define_insn "*msac2"
1198 [(set (match_operand:SI 0 "register_operand" "=l")
1199 (minus:SI (match_dup 0)
1200 (mult:SI (match_operand:SI 1 "register_operand" "d")
1201 (match_operand:SI 2 "register_operand" "d"))))
1202 (set (match_operand:SI 3 "register_operand" "=d")
1203 (minus:SI (match_dup 0)
1204 (mult:SI (match_dup 1)
1206 (clobber (match_scratch:SI 4 "=h"))]
1207 "ISA_HAS_MSAC && reload_completed"
1209 [(set_attr "type" "imadd")
1210 (set_attr "mode" "SI")])
1212 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1216 ;; Operand 1: macc/msac
1218 ;; Operand 3: GPR (destination)
1221 [(set (match_operand:SI 0 "register_operand")
1222 (match_operand:SI 1 "macc_msac_operand"))
1223 (clobber (match_operand:SI 2 "register_operand"))
1224 (clobber (scratch:SI))])
1225 (set (match_operand:SI 3 "register_operand")
1226 (unspec:SI [(match_dup 0) (match_dup 2)] UNSPEC_MFHILO))]
1228 [(parallel [(set (match_dup 0)
1232 (clobber (match_dup 2))])]
1235 ;; When we have a three-address multiplication instruction, it should
1236 ;; be faster to do a separate multiply and add, rather than moving
1237 ;; something into LO in order to use a macc instruction.
1239 ;; This peephole needs a scratch register to cater for the case when one
1240 ;; of the multiplication operands is the same as the destination.
1242 ;; Operand 0: GPR (scratch)
1244 ;; Operand 2: GPR (addend)
1245 ;; Operand 3: GPR (destination)
1246 ;; Operand 4: macc/msac
1248 ;; Operand 6: new multiplication
1249 ;; Operand 7: new addition/subtraction
1251 [(match_scratch:SI 0 "d")
1252 (set (match_operand:SI 1 "register_operand")
1253 (match_operand:SI 2 "register_operand"))
1256 [(set (match_operand:SI 3 "register_operand")
1257 (match_operand:SI 4 "macc_msac_operand"))
1258 (clobber (match_operand:SI 5 "register_operand"))
1259 (clobber (match_dup 1))])]
1261 && true_regnum (operands[1]) == LO_REGNUM
1262 && peep2_reg_dead_p (2, operands[1])
1263 && GP_REG_P (true_regnum (operands[3]))"
1264 [(parallel [(set (match_dup 0)
1266 (clobber (match_dup 5))
1267 (clobber (match_dup 1))])
1271 operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1272 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1273 operands[2], operands[0]);
1276 ;; Same as above, except LO is the initial target of the macc.
1278 ;; Operand 0: GPR (scratch)
1280 ;; Operand 2: GPR (addend)
1281 ;; Operand 3: macc/msac
1283 ;; Operand 5: GPR (destination)
1284 ;; Operand 6: new multiplication
1285 ;; Operand 7: new addition/subtraction
1287 [(match_scratch:SI 0 "d")
1288 (set (match_operand:SI 1 "register_operand")
1289 (match_operand:SI 2 "register_operand"))
1293 (match_operand:SI 3 "macc_msac_operand"))
1294 (clobber (match_operand:SI 4 "register_operand"))
1295 (clobber (scratch:SI))])
1297 (set (match_operand:SI 5 "register_operand")
1298 (unspec:SI [(match_dup 1) (match_dup 4)] UNSPEC_MFHILO))]
1299 "GENERATE_MULT3_SI && peep2_reg_dead_p (3, operands[1])"
1300 [(parallel [(set (match_dup 0)
1302 (clobber (match_dup 4))
1303 (clobber (match_dup 1))])
1307 operands[6] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1308 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1309 operands[2], operands[0]);
1312 (define_insn "*mul_sub_si"
1313 [(set (match_operand:SI 0 "register_operand" "=l,*d,*d")
1314 (minus:SI (match_operand:SI 1 "register_operand" "0,l,*d")
1315 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
1316 (match_operand:SI 3 "register_operand" "d,d,d"))))
1317 (clobber (match_scratch:SI 4 "=h,h,h"))
1318 (clobber (match_scratch:SI 5 "=X,1,l"))
1319 (clobber (match_scratch:SI 6 "=X,X,&d"))]
1325 [(set_attr "type" "imadd,multi,multi")
1326 (set_attr "mode" "SI")
1327 (set_attr "length" "4,8,8")])
1329 ;; Split the above insn if we failed to get LO allocated.
1331 [(set (match_operand:SI 0 "register_operand")
1332 (minus:SI (match_operand:SI 1 "register_operand")
1333 (mult:SI (match_operand:SI 2 "register_operand")
1334 (match_operand:SI 3 "register_operand"))))
1335 (clobber (match_scratch:SI 4))
1336 (clobber (match_scratch:SI 5))
1337 (clobber (match_scratch:SI 6))]
1338 "reload_completed && !TARGET_DEBUG_D_MODE
1339 && GP_REG_P (true_regnum (operands[0]))
1340 && GP_REG_P (true_regnum (operands[1]))"
1341 [(parallel [(set (match_dup 6)
1342 (mult:SI (match_dup 2) (match_dup 3)))
1343 (clobber (match_dup 4))
1344 (clobber (match_dup 5))])
1345 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 6)))]
1348 ;; Splitter to copy result of MSUB to a general register
1350 [(set (match_operand:SI 0 "register_operand")
1351 (minus:SI (match_operand:SI 1 "register_operand")
1352 (mult:SI (match_operand:SI 2 "register_operand")
1353 (match_operand:SI 3 "register_operand"))))
1354 (clobber (match_scratch:SI 4))
1355 (clobber (match_scratch:SI 5))
1356 (clobber (match_scratch:SI 6))]
1357 "reload_completed && !TARGET_DEBUG_D_MODE
1358 && GP_REG_P (true_regnum (operands[0]))
1359 && true_regnum (operands[1]) == LO_REGNUM"
1360 [(parallel [(set (match_dup 1)
1361 (minus:SI (match_dup 1)
1362 (mult:SI (match_dup 2) (match_dup 3))))
1363 (clobber (match_dup 4))
1364 (clobber (match_dup 5))
1365 (clobber (match_dup 6))])
1366 (set (match_dup 0) (unspec:SI [(match_dup 5) (match_dup 4)] UNSPEC_MFHILO))]
1369 (define_insn "*muls"
1370 [(set (match_operand:SI 0 "register_operand" "=l,d")
1371 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1372 (match_operand:SI 2 "register_operand" "d,d"))))
1373 (clobber (match_scratch:SI 3 "=h,h"))
1374 (clobber (match_scratch:SI 4 "=X,l"))]
1379 [(set_attr "type" "imul")
1380 (set_attr "mode" "SI")])
1382 ;; ??? We could define a mulditi3 pattern when TARGET_64BIT.
1384 (define_expand "<u>mulsidi3"
1386 [(set (match_operand:DI 0 "register_operand")
1387 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1388 (any_extend:DI (match_operand:SI 2 "register_operand"))))
1389 (clobber (scratch:DI))
1390 (clobber (scratch:DI))
1391 (clobber (scratch:DI))])]
1392 "!TARGET_64BIT || !TARGET_FIX_R4000"
1396 if (!TARGET_FIX_R4000)
1397 emit_insn (gen_<u>mulsidi3_32bit_internal (operands[0], operands[1],
1400 emit_insn (gen_<u>mulsidi3_32bit_r4000 (operands[0], operands[1],
1406 (define_insn "<u>mulsidi3_32bit_internal"
1407 [(set (match_operand:DI 0 "register_operand" "=x")
1408 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1409 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
1410 "!TARGET_64BIT && !TARGET_FIX_R4000"
1412 [(set_attr "type" "imul")
1413 (set_attr "mode" "SI")])
1415 (define_insn "<u>mulsidi3_32bit_r4000"
1416 [(set (match_operand:DI 0 "register_operand" "=d")
1417 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1418 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1419 (clobber (match_scratch:DI 3 "=x"))]
1420 "!TARGET_64BIT && TARGET_FIX_R4000"
1421 "mult<u>\t%1,%2\;mflo\t%L0;mfhi\t%M0"
1422 [(set_attr "type" "imul")
1423 (set_attr "mode" "SI")
1424 (set_attr "length" "12")])
1426 (define_insn_and_split "*<u>mulsidi3_64bit"
1427 [(set (match_operand:DI 0 "register_operand" "=d")
1428 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1429 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
1430 (clobber (match_scratch:DI 3 "=l"))
1431 (clobber (match_scratch:DI 4 "=h"))
1432 (clobber (match_scratch:DI 5 "=d"))]
1433 "TARGET_64BIT && !TARGET_FIX_R4000"
1435 "&& reload_completed"
1439 (mult:SI (match_dup 1)
1443 (mult:DI (any_extend:DI (match_dup 1))
1444 (any_extend:DI (match_dup 2)))
1447 ;; OP5 <- LO, OP0 <- HI
1448 (set (match_dup 5) (unspec:DI [(match_dup 3) (match_dup 4)] UNSPEC_MFHILO))
1449 (set (match_dup 0) (unspec:DI [(match_dup 4) (match_dup 3)] UNSPEC_MFHILO))
1453 (ashift:DI (match_dup 5)
1456 (lshiftrt:DI (match_dup 5)
1459 ;; Shift OP0 into place.
1461 (ashift:DI (match_dup 0)
1464 ;; OR the two halves together
1466 (ior:DI (match_dup 0)
1469 [(set_attr "type" "imul")
1470 (set_attr "mode" "SI")
1471 (set_attr "length" "24")])
1473 (define_insn "*<u>mulsidi3_64bit_parts"
1474 [(set (match_operand:DI 0 "register_operand" "=l")
1476 (mult:SI (match_operand:SI 2 "register_operand" "d")
1477 (match_operand:SI 3 "register_operand" "d"))))
1478 (set (match_operand:DI 1 "register_operand" "=h")
1480 (mult:DI (any_extend:DI (match_dup 2))
1481 (any_extend:DI (match_dup 3)))
1483 "TARGET_64BIT && !TARGET_FIX_R4000"
1485 [(set_attr "type" "imul")
1486 (set_attr "mode" "SI")])
1488 ;; Widening multiply with negation.
1489 (define_insn "*muls<u>_di"
1490 [(set (match_operand:DI 0 "register_operand" "=x")
1493 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1494 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1495 "!TARGET_64BIT && ISA_HAS_MULS"
1497 [(set_attr "type" "imul")
1498 (set_attr "mode" "SI")])
1500 (define_insn "*msac<u>_di"
1501 [(set (match_operand:DI 0 "register_operand" "=x")
1503 (match_operand:DI 3 "register_operand" "0")
1505 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1506 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
1507 "!TARGET_64BIT && ISA_HAS_MSAC"
1509 if (TARGET_MIPS5500)
1510 return "msub<u>\t%1,%2";
1512 return "msac<u>\t$0,%1,%2";
1514 [(set_attr "type" "imadd")
1515 (set_attr "mode" "SI")])
1517 ;; _highpart patterns
1519 (define_expand "<su>mulsi3_highpart"
1520 [(set (match_operand:SI 0 "register_operand")
1523 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1524 (any_extend:DI (match_operand:SI 2 "register_operand")))
1526 "ISA_HAS_MULHI || !TARGET_FIX_R4000"
1529 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1533 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1538 (define_insn "<su>mulsi3_highpart_internal"
1539 [(set (match_operand:SI 0 "register_operand" "=h")
1542 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1543 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1545 (clobber (match_scratch:SI 3 "=l"))]
1546 "!ISA_HAS_MULHI && !TARGET_FIX_R4000"
1548 [(set_attr "type" "imul")
1549 (set_attr "mode" "SI")])
1551 (define_insn "<su>mulsi3_highpart_mulhi_internal"
1552 [(set (match_operand:SI 0 "register_operand" "=h,d")
1556 (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1557 (any_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
1559 (clobber (match_scratch:SI 3 "=l,l"))
1560 (clobber (match_scratch:SI 4 "=X,h"))]
1565 [(set_attr "type" "imul")
1566 (set_attr "mode" "SI")])
1568 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
1569 [(set (match_operand:SI 0 "register_operand" "=h,d")
1574 (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1575 (any_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
1577 (clobber (match_scratch:SI 3 "=l,l"))
1578 (clobber (match_scratch:SI 4 "=X,h"))]
1582 mulshi<u>\t%0,%1,%2"
1583 [(set_attr "type" "imul")
1584 (set_attr "mode" "SI")])
1586 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
1587 ;; errata MD(0), which says that dmultu does not always produce the
1589 (define_insn "<su>muldi3_highpart"
1590 [(set (match_operand:DI 0 "register_operand" "=h")
1594 (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
1595 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
1597 (clobber (match_scratch:DI 3 "=l"))]
1598 "TARGET_64BIT && !TARGET_FIX_R4000
1599 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
1601 [(set_attr "type" "imul")
1602 (set_attr "mode" "DI")])
1604 ;; The R4650 supports a 32 bit multiply/ 64 bit accumulate
1605 ;; instruction. The HI/LO registers are used as a 64 bit accumulator.
1607 (define_insn "madsi"
1608 [(set (match_operand:SI 0 "register_operand" "+l")
1609 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1610 (match_operand:SI 2 "register_operand" "d"))
1612 (clobber (match_scratch:SI 3 "=h"))]
1615 [(set_attr "type" "imadd")
1616 (set_attr "mode" "SI")])
1618 (define_insn "*<su>mul_acc_di"
1619 [(set (match_operand:DI 0 "register_operand" "=x")
1621 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1622 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1623 (match_operand:DI 3 "register_operand" "0")))]
1624 "(TARGET_MAD || ISA_HAS_MACC)
1628 return "mad<u>\t%1,%2";
1629 else if (TARGET_MIPS5500)
1630 return "madd<u>\t%1,%2";
1632 /* See comment in *macc. */
1633 return "%[macc<u>\t%@,%1,%2%]";
1635 [(set_attr "type" "imadd")
1636 (set_attr "mode" "SI")])
1638 ;; Floating point multiply accumulate instructions.
1640 (define_insn "*madd<mode>"
1641 [(set (match_operand:ANYF 0 "register_operand" "=f")
1642 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1643 (match_operand:ANYF 2 "register_operand" "f"))
1644 (match_operand:ANYF 3 "register_operand" "f")))]
1645 "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1646 "madd.<fmt>\t%0,%3,%1,%2"
1647 [(set_attr "type" "fmadd")
1648 (set_attr "mode" "<UNITMODE>")])
1650 (define_insn "*msub<mode>"
1651 [(set (match_operand:ANYF 0 "register_operand" "=f")
1652 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1653 (match_operand:ANYF 2 "register_operand" "f"))
1654 (match_operand:ANYF 3 "register_operand" "f")))]
1655 "ISA_HAS_FP4 && TARGET_FUSED_MADD"
1656 "msub.<fmt>\t%0,%3,%1,%2"
1657 [(set_attr "type" "fmadd")
1658 (set_attr "mode" "<UNITMODE>")])
1660 (define_insn "*nmadd<mode>"
1661 [(set (match_operand:ANYF 0 "register_operand" "=f")
1662 (neg:ANYF (plus:ANYF
1663 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
1664 (match_operand:ANYF 2 "register_operand" "f"))
1665 (match_operand:ANYF 3 "register_operand" "f"))))]
1666 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1667 && HONOR_SIGNED_ZEROS (<MODE>mode)"
1668 "nmadd.<fmt>\t%0,%3,%1,%2"
1669 [(set_attr "type" "fmadd")
1670 (set_attr "mode" "<UNITMODE>")])
1672 (define_insn "*nmadd<mode>_fastmath"
1673 [(set (match_operand:ANYF 0 "register_operand" "=f")
1675 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
1676 (match_operand:ANYF 2 "register_operand" "f"))
1677 (match_operand:ANYF 3 "register_operand" "f")))]
1678 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1679 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
1680 "nmadd.<fmt>\t%0,%3,%1,%2"
1681 [(set_attr "type" "fmadd")
1682 (set_attr "mode" "<UNITMODE>")])
1684 (define_insn "*nmsub<mode>"
1685 [(set (match_operand:ANYF 0 "register_operand" "=f")
1686 (neg:ANYF (minus:ANYF
1687 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1688 (match_operand:ANYF 3 "register_operand" "f"))
1689 (match_operand:ANYF 1 "register_operand" "f"))))]
1690 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1691 && HONOR_SIGNED_ZEROS (<MODE>mode)"
1692 "nmsub.<fmt>\t%0,%1,%2,%3"
1693 [(set_attr "type" "fmadd")
1694 (set_attr "mode" "<UNITMODE>")])
1696 (define_insn "*nmsub<mode>_fastmath"
1697 [(set (match_operand:ANYF 0 "register_operand" "=f")
1699 (match_operand:ANYF 1 "register_operand" "f")
1700 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
1701 (match_operand:ANYF 3 "register_operand" "f"))))]
1702 "ISA_HAS_NMADD_NMSUB && TARGET_FUSED_MADD
1703 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
1704 "nmsub.<fmt>\t%0,%1,%2,%3"
1705 [(set_attr "type" "fmadd")
1706 (set_attr "mode" "<UNITMODE>")])
1709 ;; ....................
1711 ;; DIVISION and REMAINDER
1713 ;; ....................
1716 (define_expand "div<mode>3"
1717 [(set (match_operand:ANYF 0 "register_operand")
1718 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
1719 (match_operand:ANYF 2 "register_operand")))]
1720 "<divide_condition>"
1722 if (const_1_operand (operands[1], <MODE>mode))
1723 if (!(ISA_HAS_FP4 && flag_unsafe_math_optimizations))
1724 operands[1] = force_reg (<MODE>mode, operands[1]);
1727 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
1729 ;; If an mfc1 or dmfc1 happens to access the floating point register
1730 ;; file at the same time a long latency operation (div, sqrt, recip,
1731 ;; sqrt) iterates an intermediate result back through the floating
1732 ;; point register file bypass, then instead returning the correct
1733 ;; register value the mfc1 or dmfc1 operation returns the intermediate
1734 ;; result of the long latency operation.
1736 ;; The workaround is to insert an unconditional 'mov' from/to the
1737 ;; long latency op destination register.
1739 (define_insn "*div<mode>3"
1740 [(set (match_operand:ANYF 0 "register_operand" "=f")
1741 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
1742 (match_operand:ANYF 2 "register_operand" "f")))]
1743 "<divide_condition>"
1746 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
1748 return "div.<fmt>\t%0,%1,%2";
1750 [(set_attr "type" "fdiv")
1751 (set_attr "mode" "<UNITMODE>")
1752 (set (attr "length")
1753 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1757 (define_insn "*recip<mode>3"
1758 [(set (match_operand:ANYF 0 "register_operand" "=f")
1759 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1760 (match_operand:ANYF 2 "register_operand" "f")))]
1761 "<recip_condition> && flag_unsafe_math_optimizations"
1764 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1766 return "recip.<fmt>\t%0,%2";
1768 [(set_attr "type" "frdiv")
1769 (set_attr "mode" "<UNITMODE>")
1770 (set (attr "length")
1771 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1775 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
1776 ;; with negative operands. We use special libgcc functions instead.
1777 (define_insn "divmod<mode>4"
1778 [(set (match_operand:GPR 0 "register_operand" "=l")
1779 (div:GPR (match_operand:GPR 1 "register_operand" "d")
1780 (match_operand:GPR 2 "register_operand" "d")))
1781 (set (match_operand:GPR 3 "register_operand" "=h")
1782 (mod:GPR (match_dup 1)
1784 "!TARGET_FIX_VR4120"
1785 { return mips_output_division ("<d>div\t$0,%1,%2", operands); }
1786 [(set_attr "type" "idiv")
1787 (set_attr "mode" "<MODE>")])
1789 (define_insn "udivmod<mode>4"
1790 [(set (match_operand:GPR 0 "register_operand" "=l")
1791 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
1792 (match_operand:GPR 2 "register_operand" "d")))
1793 (set (match_operand:GPR 3 "register_operand" "=h")
1794 (umod:GPR (match_dup 1)
1797 { return mips_output_division ("<d>divu\t$0,%1,%2", operands); }
1798 [(set_attr "type" "idiv")
1799 (set_attr "mode" "<MODE>")])
1802 ;; ....................
1806 ;; ....................
1808 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
1809 ;; "*div[sd]f3" comment for details).
1811 (define_insn "sqrt<mode>2"
1812 [(set (match_operand:ANYF 0 "register_operand" "=f")
1813 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
1817 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
1819 return "sqrt.<fmt>\t%0,%1";
1821 [(set_attr "type" "fsqrt")
1822 (set_attr "mode" "<UNITMODE>")
1823 (set (attr "length")
1824 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1828 (define_insn "*rsqrt<mode>a"
1829 [(set (match_operand:ANYF 0 "register_operand" "=f")
1830 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1831 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
1832 "<recip_condition> && flag_unsafe_math_optimizations"
1835 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1837 return "rsqrt.<fmt>\t%0,%2";
1839 [(set_attr "type" "frsqrt")
1840 (set_attr "mode" "<UNITMODE>")
1841 (set (attr "length")
1842 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1846 (define_insn "*rsqrt<mode>b"
1847 [(set (match_operand:ANYF 0 "register_operand" "=f")
1848 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
1849 (match_operand:ANYF 2 "register_operand" "f"))))]
1850 "<recip_condition> && flag_unsafe_math_optimizations"
1853 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1855 return "rsqrt.<fmt>\t%0,%2";
1857 [(set_attr "type" "frsqrt")
1858 (set_attr "mode" "<UNITMODE>")
1859 (set (attr "length")
1860 (if_then_else (ne (symbol_ref "TARGET_FIX_SB1") (const_int 0))
1865 ;; ....................
1869 ;; ....................
1871 ;; Do not use the integer abs macro instruction, since that signals an
1872 ;; exception on -2147483648 (sigh).
1874 (define_insn "abs<mode>2"
1875 [(set (match_operand:GPR 0 "register_operand" "=d")
1876 (abs:GPR (match_operand:GPR 1 "register_operand" "d")))]
1879 if (REGNO (operands[0]) == REGNO (operands[1]) && GENERATE_BRANCHLIKELY)
1880 return "%(bltzl\t%1,1f\;<d>subu\t%0,%.,%0\n%~1:%)";
1882 return "%(bgez\t%1,1f\;move\t%0,%1\;<d>subu\t%0,%.,%0\n%~1:%)";
1884 [(set_attr "type" "multi")
1885 (set_attr "mode" "<MODE>")
1886 (set_attr "length" "12")])
1888 (define_insn "abs<mode>2"
1889 [(set (match_operand:ANYF 0 "register_operand" "=f")
1890 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
1893 [(set_attr "type" "fabs")
1894 (set_attr "mode" "<UNITMODE>")])
1897 ;; ....................
1899 ;; FIND FIRST BIT INSTRUCTION
1901 ;; ....................
1904 (define_insn "ffs<mode>2"
1905 [(set (match_operand:GPR 0 "register_operand" "=&d")
1906 (ffs:GPR (match_operand:GPR 1 "register_operand" "d")))
1907 (clobber (match_scratch:GPR 2 "=&d"))
1908 (clobber (match_scratch:GPR 3 "=&d"))]
1911 if (optimize && find_reg_note (insn, REG_DEAD, operands[1]))
1915 %~1:\tand\t%2,%1,0x0001\;\
1925 %~1:\tand\t%2,%3,0x0001\;\
1931 [(set_attr "type" "multi")
1932 (set_attr "mode" "<MODE>")
1933 (set_attr "length" "28")])
1936 ;; ...................
1938 ;; Count leading zeroes.
1940 ;; ...................
1943 (define_insn "clz<mode>2"
1944 [(set (match_operand:GPR 0 "register_operand" "=d")
1945 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
1948 [(set_attr "type" "clz")
1949 (set_attr "mode" "<MODE>")])
1952 ;; ....................
1954 ;; NEGATION and ONE'S COMPLEMENT
1956 ;; ....................
1958 (define_insn "negsi2"
1959 [(set (match_operand:SI 0 "register_operand" "=d")
1960 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
1964 return "neg\t%0,%1";
1966 return "subu\t%0,%.,%1";
1968 [(set_attr "type" "arith")
1969 (set_attr "mode" "SI")])
1971 (define_insn "negdi2"
1972 [(set (match_operand:DI 0 "register_operand" "=d")
1973 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
1974 "TARGET_64BIT && !TARGET_MIPS16"
1976 [(set_attr "type" "arith")
1977 (set_attr "mode" "DI")])
1979 (define_insn "neg<mode>2"
1980 [(set (match_operand:ANYF 0 "register_operand" "=f")
1981 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
1984 [(set_attr "type" "fneg")
1985 (set_attr "mode" "<UNITMODE>")])
1987 (define_insn "one_cmpl<mode>2"
1988 [(set (match_operand:GPR 0 "register_operand" "=d")
1989 (not:GPR (match_operand:GPR 1 "register_operand" "d")))]
1993 return "not\t%0,%1";
1995 return "nor\t%0,%.,%1";
1997 [(set_attr "type" "arith")
1998 (set_attr "mode" "<MODE>")])
2001 ;; ....................
2005 ;; ....................
2008 ;; Many of these instructions use trivial define_expands, because we
2009 ;; want to use a different set of constraints when TARGET_MIPS16.
2011 (define_expand "and<mode>3"
2012 [(set (match_operand:GPR 0 "register_operand")
2013 (and:GPR (match_operand:GPR 1 "register_operand")
2014 (match_operand:GPR 2 "uns_arith_operand")))]
2018 operands[2] = force_reg (<MODE>mode, operands[2]);
2021 (define_insn "*and<mode>3"
2022 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2023 (and:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2024 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2029 [(set_attr "type" "arith")
2030 (set_attr "mode" "<MODE>")])
2032 (define_insn "*and<mode>3_mips16"
2033 [(set (match_operand:GPR 0 "register_operand" "=d")
2034 (and:GPR (match_operand:GPR 1 "register_operand" "%0")
2035 (match_operand:GPR 2 "register_operand" "d")))]
2038 [(set_attr "type" "arith")
2039 (set_attr "mode" "<MODE>")])
2041 (define_expand "ior<mode>3"
2042 [(set (match_operand:GPR 0 "register_operand")
2043 (ior:GPR (match_operand:GPR 1 "register_operand")
2044 (match_operand:GPR 2 "uns_arith_operand")))]
2048 operands[2] = force_reg (<MODE>mode, operands[2]);
2051 (define_insn "*ior<mode>3"
2052 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2053 (ior:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2054 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2059 [(set_attr "type" "arith")
2060 (set_attr "mode" "<MODE>")])
2062 (define_insn "*ior<mode>3_mips16"
2063 [(set (match_operand:GPR 0 "register_operand" "=d")
2064 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
2065 (match_operand:GPR 2 "register_operand" "d")))]
2068 [(set_attr "type" "arith")
2069 (set_attr "mode" "<MODE>")])
2071 (define_expand "xor<mode>3"
2072 [(set (match_operand:GPR 0 "register_operand")
2073 (xor:GPR (match_operand:GPR 1 "register_operand")
2074 (match_operand:GPR 2 "uns_arith_operand")))]
2079 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2080 (xor:GPR (match_operand:GPR 1 "register_operand" "%d,d")
2081 (match_operand:GPR 2 "uns_arith_operand" "d,K")))]
2086 [(set_attr "type" "arith")
2087 (set_attr "mode" "<MODE>")])
2090 [(set (match_operand:GPR 0 "register_operand" "=d,t,t")
2091 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
2092 (match_operand:GPR 2 "uns_arith_operand" "d,K,d")))]
2098 [(set_attr "type" "arith")
2099 (set_attr "mode" "<MODE>")
2100 (set_attr_alternative "length"
2102 (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2107 (define_insn "*nor<mode>3"
2108 [(set (match_operand:GPR 0 "register_operand" "=d")
2109 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
2110 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
2113 [(set_attr "type" "arith")
2114 (set_attr "mode" "<MODE>")])
2117 ;; ....................
2121 ;; ....................
2125 (define_insn "truncdfsf2"
2126 [(set (match_operand:SF 0 "register_operand" "=f")
2127 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
2128 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2130 [(set_attr "type" "fcvt")
2131 (set_attr "mode" "SF")])
2133 ;; Integer truncation patterns. Truncating SImode values to smaller
2134 ;; modes is a no-op, as it is for most other GCC ports. Truncating
2135 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
2136 ;; need to make sure that the lower 32 bits are properly sign-extended
2137 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
2138 ;; smaller than SImode is equivalent to two separate truncations:
2141 ;; DI ---> HI == DI ---> SI ---> HI
2142 ;; DI ---> QI == DI ---> SI ---> QI
2144 ;; Step A needs a real instruction but step B does not.
2146 (define_insn "truncdisi2"
2147 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
2148 (truncate:SI (match_operand:DI 1 "register_operand" "d,d")))]
2153 [(set_attr "type" "shift,store")
2154 (set_attr "mode" "SI")
2155 (set_attr "extended_mips16" "yes,*")])
2157 (define_insn "truncdihi2"
2158 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,m")
2159 (truncate:HI (match_operand:DI 1 "register_operand" "d,d")))]
2164 [(set_attr "type" "shift,store")
2165 (set_attr "mode" "SI")
2166 (set_attr "extended_mips16" "yes,*")])
2168 (define_insn "truncdiqi2"
2169 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,m")
2170 (truncate:QI (match_operand:DI 1 "register_operand" "d,d")))]
2175 [(set_attr "type" "shift,store")
2176 (set_attr "mode" "SI")
2177 (set_attr "extended_mips16" "yes,*")])
2179 ;; Combiner patterns to optimize shift/truncate combinations.
2182 [(set (match_operand:SI 0 "register_operand" "=d")
2184 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
2185 (match_operand:DI 2 "const_arith_operand" ""))))]
2186 "TARGET_64BIT && !TARGET_MIPS16 && INTVAL (operands[2]) >= 32"
2188 [(set_attr "type" "shift")
2189 (set_attr "mode" "SI")])
2192 [(set (match_operand:SI 0 "register_operand" "=d")
2193 (truncate:SI (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2195 "TARGET_64BIT && !TARGET_MIPS16"
2197 [(set_attr "type" "shift")
2198 (set_attr "mode" "SI")])
2201 ;; Combiner patterns for truncate/sign_extend combinations. They use
2202 ;; the shift/truncate patterns above.
2204 (define_insn_and_split ""
2205 [(set (match_operand:SI 0 "register_operand" "=d")
2207 (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
2208 "TARGET_64BIT && !TARGET_MIPS16"
2210 "&& reload_completed"
2212 (ashift:DI (match_dup 1)
2215 (truncate:SI (ashiftrt:DI (match_dup 2)
2217 { operands[2] = gen_lowpart (DImode, operands[0]); })
2219 (define_insn_and_split ""
2220 [(set (match_operand:SI 0 "register_operand" "=d")
2222 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
2223 "TARGET_64BIT && !TARGET_MIPS16"
2225 "&& reload_completed"
2227 (ashift:DI (match_dup 1)
2230 (truncate:SI (ashiftrt:DI (match_dup 2)
2232 { operands[2] = gen_lowpart (DImode, operands[0]); })
2235 ;; Combiner patterns to optimize truncate/zero_extend combinations.
2238 [(set (match_operand:SI 0 "register_operand" "=d")
2239 (zero_extend:SI (truncate:HI
2240 (match_operand:DI 1 "register_operand" "d"))))]
2241 "TARGET_64BIT && !TARGET_MIPS16"
2242 "andi\t%0,%1,0xffff"
2243 [(set_attr "type" "arith")
2244 (set_attr "mode" "SI")])
2247 [(set (match_operand:SI 0 "register_operand" "=d")
2248 (zero_extend:SI (truncate:QI
2249 (match_operand:DI 1 "register_operand" "d"))))]
2250 "TARGET_64BIT && !TARGET_MIPS16"
2252 [(set_attr "type" "arith")
2253 (set_attr "mode" "SI")])
2256 [(set (match_operand:HI 0 "register_operand" "=d")
2257 (zero_extend:HI (truncate:QI
2258 (match_operand:DI 1 "register_operand" "d"))))]
2259 "TARGET_64BIT && !TARGET_MIPS16"
2261 [(set_attr "type" "arith")
2262 (set_attr "mode" "HI")])
2265 ;; ....................
2269 ;; ....................
2273 (define_insn_and_split "zero_extendsidi2"
2274 [(set (match_operand:DI 0 "register_operand" "=d,d")
2275 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
2280 "&& reload_completed && REG_P (operands[1])"
2282 (ashift:DI (match_dup 1) (const_int 32)))
2284 (lshiftrt:DI (match_dup 0) (const_int 32)))]
2285 { operands[1] = gen_lowpart (DImode, operands[1]); }
2286 [(set_attr "type" "multi,load")
2287 (set_attr "mode" "DI")
2288 (set_attr "length" "8,*")])
2290 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
2291 [(set (match_operand:GPR 0 "register_operand")
2292 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2295 if (TARGET_MIPS16 && !memory_operand (operands[1], <SHORT:MODE>mode))
2297 emit_insn (gen_and<GPR:mode>3 (operands[0],
2298 gen_lowpart (<GPR:MODE>mode, operands[1]),
2299 force_reg (<GPR:MODE>mode,
2300 GEN_INT (<SHORT:mask>))));
2305 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2306 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2308 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2311 andi\t%0,%1,<SHORT:mask>
2312 l<SHORT:size>u\t%0,%1"
2313 [(set_attr "type" "arith,load")
2314 (set_attr "mode" "<GPR:MODE>")])
2316 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
2317 [(set (match_operand:GPR 0 "register_operand" "=d")
2318 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
2320 "l<SHORT:size>u\t%0,%1"
2321 [(set_attr "type" "load")
2322 (set_attr "mode" "<GPR:MODE>")])
2324 (define_expand "zero_extendqihi2"
2325 [(set (match_operand:HI 0 "register_operand")
2326 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
2329 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
2331 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
2337 (define_insn "*zero_extendqihi2"
2338 [(set (match_operand:HI 0 "register_operand" "=d,d")
2339 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2344 [(set_attr "type" "arith,load")
2345 (set_attr "mode" "HI")])
2347 (define_insn "*zero_extendqihi2_mips16"
2348 [(set (match_operand:HI 0 "register_operand" "=d")
2349 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
2352 [(set_attr "type" "load")
2353 (set_attr "mode" "HI")])
2356 ;; ....................
2360 ;; ....................
2363 ;; Those for integer source operand are ordered widest source type first.
2365 ;; When TARGET_64BIT, all SImode integer registers should already be in
2366 ;; sign-extended form (see TRULY_NOOP_TRUNCATION and truncdisi2). We can
2367 ;; therefore get rid of register->register instructions if we constrain
2368 ;; the source to be in the same register as the destination.
2370 ;; The register alternative has type "arith" so that the pre-reload
2371 ;; scheduler will treat it as a move. This reflects what happens if
2372 ;; the register alternative needs a reload.
2373 (define_insn_and_split "extendsidi2"
2374 [(set (match_operand:DI 0 "register_operand" "=d,d")
2375 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,m")))]
2380 "&& reload_completed && register_operand (operands[1], VOIDmode)"
2383 emit_note (NOTE_INSN_DELETED);
2386 [(set_attr "type" "arith,load")
2387 (set_attr "mode" "DI")])
2389 (define_expand "extend<SHORT:mode><GPR:mode>2"
2390 [(set (match_operand:GPR 0 "register_operand")
2391 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
2394 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
2395 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2397 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2401 l<SHORT:size>\t%0,%1"
2402 "&& reload_completed && REG_P (operands[1])"
2403 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
2404 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
2406 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
2407 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
2408 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
2410 [(set_attr "type" "arith,load")
2411 (set_attr "mode" "<GPR:MODE>")
2412 (set_attr "length" "8,*")])
2414 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
2415 [(set (match_operand:GPR 0 "register_operand" "=d,d")
2417 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2420 se<SHORT:size>\t%0,%1
2421 l<SHORT:size>\t%0,%1"
2422 [(set_attr "type" "arith,load")
2423 (set_attr "mode" "<GPR:MODE>")])
2425 ;; This pattern generates the same code as extendqisi2; split it into
2426 ;; that form after reload.
2427 (define_insn_and_split "extendqihi2"
2428 [(set (match_operand:HI 0 "register_operand" "=d,d")
2429 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
2433 [(set (match_dup 0) (sign_extend:SI (match_dup 1)))]
2434 { operands[0] = gen_lowpart (SImode, operands[0]); }
2435 [(set_attr "type" "arith,load")
2436 (set_attr "mode" "SI")
2437 (set_attr "length" "8,*")])
2439 (define_insn "extendsfdf2"
2440 [(set (match_operand:DF 0 "register_operand" "=f")
2441 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
2442 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2444 [(set_attr "type" "fcvt")
2445 (set_attr "mode" "DF")])
2448 ;; ....................
2452 ;; ....................
2454 (define_expand "fix_truncdfsi2"
2455 [(set (match_operand:SI 0 "register_operand")
2456 (fix:SI (match_operand:DF 1 "register_operand")))]
2457 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2459 if (!ISA_HAS_TRUNC_W)
2461 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
2466 (define_insn "fix_truncdfsi2_insn"
2467 [(set (match_operand:SI 0 "register_operand" "=f")
2468 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
2469 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
2471 [(set_attr "type" "fcvt")
2472 (set_attr "mode" "DF")
2473 (set_attr "length" "4")])
2475 (define_insn "fix_truncdfsi2_macro"
2476 [(set (match_operand:SI 0 "register_operand" "=f")
2477 (fix:SI (match_operand:DF 1 "register_operand" "f")))
2478 (clobber (match_scratch:DF 2 "=d"))]
2479 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
2482 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
2484 return "trunc.w.d %0,%1,%2";
2486 [(set_attr "type" "fcvt")
2487 (set_attr "mode" "DF")
2488 (set_attr "length" "36")])
2490 (define_expand "fix_truncsfsi2"
2491 [(set (match_operand:SI 0 "register_operand")
2492 (fix:SI (match_operand:SF 1 "register_operand")))]
2495 if (!ISA_HAS_TRUNC_W)
2497 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
2502 (define_insn "fix_truncsfsi2_insn"
2503 [(set (match_operand:SI 0 "register_operand" "=f")
2504 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
2505 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
2507 [(set_attr "type" "fcvt")
2508 (set_attr "mode" "DF")
2509 (set_attr "length" "4")])
2511 (define_insn "fix_truncsfsi2_macro"
2512 [(set (match_operand:SI 0 "register_operand" "=f")
2513 (fix:SI (match_operand:SF 1 "register_operand" "f")))
2514 (clobber (match_scratch:SF 2 "=d"))]
2515 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
2518 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
2520 return "trunc.w.s %0,%1,%2";
2522 [(set_attr "type" "fcvt")
2523 (set_attr "mode" "DF")
2524 (set_attr "length" "36")])
2527 (define_insn "fix_truncdfdi2"
2528 [(set (match_operand:DI 0 "register_operand" "=f")
2529 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
2530 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2532 [(set_attr "type" "fcvt")
2533 (set_attr "mode" "DF")
2534 (set_attr "length" "4")])
2537 (define_insn "fix_truncsfdi2"
2538 [(set (match_operand:DI 0 "register_operand" "=f")
2539 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
2540 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2542 [(set_attr "type" "fcvt")
2543 (set_attr "mode" "SF")
2544 (set_attr "length" "4")])
2547 (define_insn "floatsidf2"
2548 [(set (match_operand:DF 0 "register_operand" "=f")
2549 (float:DF (match_operand:SI 1 "register_operand" "f")))]
2550 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2552 [(set_attr "type" "fcvt")
2553 (set_attr "mode" "DF")
2554 (set_attr "length" "4")])
2557 (define_insn "floatdidf2"
2558 [(set (match_operand:DF 0 "register_operand" "=f")
2559 (float:DF (match_operand:DI 1 "register_operand" "f")))]
2560 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2562 [(set_attr "type" "fcvt")
2563 (set_attr "mode" "DF")
2564 (set_attr "length" "4")])
2567 (define_insn "floatsisf2"
2568 [(set (match_operand:SF 0 "register_operand" "=f")
2569 (float:SF (match_operand:SI 1 "register_operand" "f")))]
2572 [(set_attr "type" "fcvt")
2573 (set_attr "mode" "SF")
2574 (set_attr "length" "4")])
2577 (define_insn "floatdisf2"
2578 [(set (match_operand:SF 0 "register_operand" "=f")
2579 (float:SF (match_operand:DI 1 "register_operand" "f")))]
2580 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
2582 [(set_attr "type" "fcvt")
2583 (set_attr "mode" "SF")
2584 (set_attr "length" "4")])
2587 (define_expand "fixuns_truncdfsi2"
2588 [(set (match_operand:SI 0 "register_operand")
2589 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
2590 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
2592 rtx reg1 = gen_reg_rtx (DFmode);
2593 rtx reg2 = gen_reg_rtx (DFmode);
2594 rtx reg3 = gen_reg_rtx (SImode);
2595 rtx label1 = gen_label_rtx ();
2596 rtx label2 = gen_label_rtx ();
2597 REAL_VALUE_TYPE offset;
2599 real_2expN (&offset, 31);
2601 if (reg1) /* Turn off complaints about unreached code. */
2603 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2604 do_pending_stack_adjust ();
2606 emit_insn (gen_cmpdf (operands[1], reg1));
2607 emit_jump_insn (gen_bge (label1));
2609 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
2610 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2611 gen_rtx_LABEL_REF (VOIDmode, label2)));
2614 emit_label (label1);
2615 emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2616 emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
2617 (BITMASK_HIGH, SImode)));
2619 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
2620 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2622 emit_label (label2);
2624 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2625 fields, and can't be used for REG_NOTES anyway). */
2626 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2632 (define_expand "fixuns_truncdfdi2"
2633 [(set (match_operand:DI 0 "register_operand")
2634 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
2635 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2637 rtx reg1 = gen_reg_rtx (DFmode);
2638 rtx reg2 = gen_reg_rtx (DFmode);
2639 rtx reg3 = gen_reg_rtx (DImode);
2640 rtx label1 = gen_label_rtx ();
2641 rtx label2 = gen_label_rtx ();
2642 REAL_VALUE_TYPE offset;
2644 real_2expN (&offset, 63);
2646 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, DFmode));
2647 do_pending_stack_adjust ();
2649 emit_insn (gen_cmpdf (operands[1], reg1));
2650 emit_jump_insn (gen_bge (label1));
2652 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
2653 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2654 gen_rtx_LABEL_REF (VOIDmode, label2)));
2657 emit_label (label1);
2658 emit_move_insn (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
2659 emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
2660 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2662 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
2663 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2665 emit_label (label2);
2667 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2668 fields, and can't be used for REG_NOTES anyway). */
2669 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2674 (define_expand "fixuns_truncsfsi2"
2675 [(set (match_operand:SI 0 "register_operand")
2676 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
2679 rtx reg1 = gen_reg_rtx (SFmode);
2680 rtx reg2 = gen_reg_rtx (SFmode);
2681 rtx reg3 = gen_reg_rtx (SImode);
2682 rtx label1 = gen_label_rtx ();
2683 rtx label2 = gen_label_rtx ();
2684 REAL_VALUE_TYPE offset;
2686 real_2expN (&offset, 31);
2688 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2689 do_pending_stack_adjust ();
2691 emit_insn (gen_cmpsf (operands[1], reg1));
2692 emit_jump_insn (gen_bge (label1));
2694 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
2695 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2696 gen_rtx_LABEL_REF (VOIDmode, label2)));
2699 emit_label (label1);
2700 emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2701 emit_move_insn (reg3, GEN_INT (trunc_int_for_mode
2702 (BITMASK_HIGH, SImode)));
2704 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
2705 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
2707 emit_label (label2);
2709 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2710 fields, and can't be used for REG_NOTES anyway). */
2711 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2716 (define_expand "fixuns_truncsfdi2"
2717 [(set (match_operand:DI 0 "register_operand")
2718 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
2719 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
2721 rtx reg1 = gen_reg_rtx (SFmode);
2722 rtx reg2 = gen_reg_rtx (SFmode);
2723 rtx reg3 = gen_reg_rtx (DImode);
2724 rtx label1 = gen_label_rtx ();
2725 rtx label2 = gen_label_rtx ();
2726 REAL_VALUE_TYPE offset;
2728 real_2expN (&offset, 63);
2730 emit_move_insn (reg1, CONST_DOUBLE_FROM_REAL_VALUE (offset, SFmode));
2731 do_pending_stack_adjust ();
2733 emit_insn (gen_cmpsf (operands[1], reg1));
2734 emit_jump_insn (gen_bge (label1));
2736 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
2737 emit_jump_insn (gen_rtx_SET (VOIDmode, pc_rtx,
2738 gen_rtx_LABEL_REF (VOIDmode, label2)));
2741 emit_label (label1);
2742 emit_move_insn (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
2743 emit_move_insn (reg3, GEN_INT (BITMASK_HIGH));
2744 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
2746 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
2747 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
2749 emit_label (label2);
2751 /* Allow REG_NOTES to be set on last insn (labels don't have enough
2752 fields, and can't be used for REG_NOTES anyway). */
2753 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
2758 ;; ....................
2762 ;; ....................
2764 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
2766 (define_expand "extv"
2767 [(set (match_operand 0 "register_operand")
2768 (sign_extract (match_operand:QI 1 "memory_operand")
2769 (match_operand 2 "immediate_operand")
2770 (match_operand 3 "immediate_operand")))]
2773 if (mips_expand_unaligned_load (operands[0], operands[1],
2774 INTVAL (operands[2]),
2775 INTVAL (operands[3])))
2781 (define_expand "extzv"
2782 [(set (match_operand 0 "register_operand")
2783 (zero_extract (match_operand:QI 1 "memory_operand")
2784 (match_operand 2 "immediate_operand")
2785 (match_operand 3 "immediate_operand")))]
2788 if (mips_expand_unaligned_load (operands[0], operands[1],
2789 INTVAL (operands[2]),
2790 INTVAL (operands[3])))
2796 (define_expand "insv"
2797 [(set (zero_extract (match_operand:QI 0 "memory_operand")
2798 (match_operand 1 "immediate_operand")
2799 (match_operand 2 "immediate_operand"))
2800 (match_operand 3 "reg_or_0_operand"))]
2803 if (mips_expand_unaligned_store (operands[0], operands[3],
2804 INTVAL (operands[1]),
2805 INTVAL (operands[2])))
2811 ;; Unaligned word moves generated by the bit field patterns.
2813 ;; As far as the rtl is concerned, both the left-part and right-part
2814 ;; instructions can access the whole field. However, the real operand
2815 ;; refers to just the first or the last byte (depending on endianness).
2816 ;; We therefore use two memory operands to each instruction, one to
2817 ;; describe the rtl effect and one to use in the assembly output.
2819 ;; Operands 0 and 1 are the rtl-level target and source respectively.
2820 ;; This allows us to use the standard length calculations for the "load"
2821 ;; and "store" type attributes.
2823 (define_insn "mov_<load>l"
2824 [(set (match_operand:GPR 0 "register_operand" "=d")
2825 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
2826 (match_operand:QI 2 "memory_operand" "m")]
2830 [(set_attr "type" "load")
2831 (set_attr "mode" "<MODE>")
2832 (set_attr "hazard" "none")])
2834 (define_insn "mov_<load>r"
2835 [(set (match_operand:GPR 0 "register_operand" "=d")
2836 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
2837 (match_operand:QI 2 "memory_operand" "m")
2838 (match_operand:GPR 3 "register_operand" "0")]
2839 UNSPEC_LOAD_RIGHT))]
2842 [(set_attr "type" "load")
2843 (set_attr "mode" "<MODE>")])
2845 (define_insn "mov_<store>l"
2846 [(set (match_operand:BLK 0 "memory_operand" "=m")
2847 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
2848 (match_operand:QI 2 "memory_operand" "m")]
2849 UNSPEC_STORE_LEFT))]
2852 [(set_attr "type" "store")
2853 (set_attr "mode" "<MODE>")])
2855 (define_insn "mov_<store>r"
2856 [(set (match_operand:BLK 0 "memory_operand" "+m")
2857 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
2858 (match_operand:QI 2 "memory_operand" "m")
2860 UNSPEC_STORE_RIGHT))]
2863 [(set_attr "type" "store")
2864 (set_attr "mode" "<MODE>")])
2866 ;; An instruction to calculate the high part of a 64-bit SYMBOL_GENERAL.
2867 ;; The required value is:
2869 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
2871 ;; which translates to:
2873 ;; lui op0,%highest(op1)
2874 ;; daddiu op0,op0,%higher(op1)
2876 ;; daddiu op0,op0,%hi(op1)
2879 ;; The split is deferred until after flow2 to allow the peephole2 below
2881 (define_insn_and_split "*lea_high64"
2882 [(set (match_operand:DI 0 "register_operand" "=d")
2883 (high:DI (match_operand:DI 1 "general_symbolic_operand" "")))]
2884 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
2886 "&& flow2_completed"
2887 [(set (match_dup 0) (high:DI (match_dup 2)))
2888 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
2889 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
2890 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
2891 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
2893 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
2894 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
2896 [(set_attr "length" "20")])
2898 ;; Use a scratch register to reduce the latency of the above pattern
2899 ;; on superscalar machines. The optimized sequence is:
2901 ;; lui op1,%highest(op2)
2903 ;; daddiu op1,op1,%higher(op2)
2905 ;; daddu op1,op1,op0
2907 [(match_scratch:DI 0 "d")
2908 (set (match_operand:DI 1 "register_operand")
2909 (high:DI (match_operand:DI 2 "general_symbolic_operand")))]
2910 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
2911 [(set (match_dup 1) (high:DI (match_dup 3)))
2912 (set (match_dup 0) (high:DI (match_dup 4)))
2913 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
2914 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
2915 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
2917 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
2918 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
2921 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
2922 ;; SYMBOL_GENERAL X will take 6 cycles. This next pattern allows combine
2923 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
2924 ;; used once. We can then use the sequence:
2926 ;; lui op0,%highest(op1)
2928 ;; daddiu op0,op0,%higher(op1)
2929 ;; daddiu op2,op2,%lo(op1)
2931 ;; daddu op0,op0,op2
2933 ;; which takes 4 cycles on most superscalar targets.
2934 (define_insn_and_split "*lea64"
2935 [(set (match_operand:DI 0 "register_operand" "=d")
2936 (match_operand:DI 1 "general_symbolic_operand" ""))
2937 (clobber (match_scratch:DI 2 "=&d"))]
2938 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS && cse_not_expected"
2940 "&& reload_completed"
2941 [(set (match_dup 0) (high:DI (match_dup 3)))
2942 (set (match_dup 2) (high:DI (match_dup 4)))
2943 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
2944 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
2945 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
2946 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
2948 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
2949 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
2951 [(set_attr "length" "24")])
2953 ;; Insns to fetch a global symbol from a big GOT.
2955 (define_insn_and_split "*xgot_hi<mode>"
2956 [(set (match_operand:P 0 "register_operand" "=d")
2957 (high:P (match_operand:P 1 "global_got_operand" "")))]
2958 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
2960 "&& reload_completed"
2961 [(set (match_dup 0) (high:P (match_dup 2)))
2962 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
2964 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_GLOBAL);
2965 operands[3] = pic_offset_table_rtx;
2967 [(set_attr "got" "xgot_high")
2968 (set_attr "mode" "<MODE>")])
2970 (define_insn_and_split "*xgot_lo<mode>"
2971 [(set (match_operand:P 0 "register_operand" "=d")
2972 (lo_sum:P (match_operand:P 1 "register_operand" "d")
2973 (match_operand:P 2 "global_got_operand" "")))]
2974 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
2976 "&& reload_completed"
2978 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
2979 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_GLOBAL); }
2980 [(set_attr "got" "load")
2981 (set_attr "mode" "<MODE>")])
2983 ;; Insns to fetch a global symbol from a normal GOT.
2985 (define_insn_and_split "*got_disp<mode>"
2986 [(set (match_operand:P 0 "register_operand" "=d")
2987 (match_operand:P 1 "global_got_operand" ""))]
2988 "TARGET_EXPLICIT_RELOCS && !TARGET_XGOT"
2990 "&& reload_completed"
2992 (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
2994 operands[2] = pic_offset_table_rtx;
2995 operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_GLOBAL);
2997 [(set_attr "got" "load")
2998 (set_attr "mode" "<MODE>")])
3000 ;; Insns for loading the high part of a local symbol.
3002 (define_insn_and_split "*got_page<mode>"
3003 [(set (match_operand:P 0 "register_operand" "=d")
3004 (high:P (match_operand:P 1 "local_got_operand" "")))]
3005 "TARGET_EXPLICIT_RELOCS"
3007 "&& reload_completed"
3009 (unspec:P [(match_dup 2) (match_dup 3)] UNSPEC_LOAD_GOT))]
3011 operands[2] = pic_offset_table_rtx;
3012 operands[3] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_PAGE);
3014 [(set_attr "got" "load")
3015 (set_attr "mode" "<MODE>")])
3017 ;; Lower-level instructions for loading an address from the GOT.
3018 ;; We could use MEMs, but an unspec gives more optimization
3021 (define_insn "*load_got<mode>"
3022 [(set (match_operand:P 0 "register_operand" "=d")
3023 (unspec:P [(match_operand:P 1 "register_operand" "d")
3024 (match_operand:P 2 "immediate_operand" "")]
3027 "<load>\t%0,%R2(%1)"
3028 [(set_attr "type" "load")
3029 (set_attr "mode" "<MODE>")
3030 (set_attr "length" "4")])
3032 ;; Instructions for adding the low 16 bits of an address to a register.
3033 ;; Operand 2 is the address: print_operand works out which relocation
3034 ;; should be applied.
3036 (define_insn "*low<mode>"
3037 [(set (match_operand:P 0 "register_operand" "=d")
3038 (lo_sum:P (match_operand:P 1 "register_operand" "d")
3039 (match_operand:P 2 "immediate_operand" "")))]
3041 "<d>addiu\t%0,%1,%R2"
3042 [(set_attr "type" "arith")
3043 (set_attr "mode" "<MODE>")])
3045 (define_insn "*low<mode>_mips16"
3046 [(set (match_operand:P 0 "register_operand" "=d")
3047 (lo_sum:P (match_operand:P 1 "register_operand" "0")
3048 (match_operand:P 2 "immediate_operand" "")))]
3051 [(set_attr "type" "arith")
3052 (set_attr "mode" "<MODE>")
3053 (set_attr "length" "8")])
3055 ;; 64-bit integer moves
3057 ;; Unlike most other insns, the move insns can't be split with
3058 ;; different predicates, because register spilling and other parts of
3059 ;; the compiler, have memoized the insn number already.
3061 (define_expand "movdi"
3062 [(set (match_operand:DI 0 "")
3063 (match_operand:DI 1 ""))]
3066 if (mips_legitimize_move (DImode, operands[0], operands[1]))
3070 ;; For mips16, we need a special case to handle storing $31 into
3071 ;; memory, since we don't have a constraint to match $31. This
3072 ;; instruction can be generated by save_restore_insns.
3074 (define_insn "*mov<mode>_ra"
3075 [(set (match_operand:GPR 0 "stack_operand" "=m")
3079 [(set_attr "type" "store")
3080 (set_attr "mode" "<MODE>")])
3082 (define_insn "*movdi_32bit"
3083 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*x,*d,*B*C*D,*B*C*D,*d,*m")
3084 (match_operand:DI 1 "move_operand" "d,i,m,d,*J*d,*x,*d,*m,*B*C*D,*B*C*D"))]
3085 "!TARGET_64BIT && !TARGET_MIPS16
3086 && (register_operand (operands[0], DImode)
3087 || reg_or_0_operand (operands[1], DImode))"
3088 { return mips_output_move (operands[0], operands[1]); }
3089 [(set_attr "type" "arith,arith,load,store,mthilo,mfhilo,xfer,load,xfer,store")
3090 (set_attr "mode" "DI")
3091 (set_attr "length" "8,16,*,*,8,8,8,*,8,*")])
3093 (define_insn "*movdi_32bit_mips16"
3094 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
3095 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
3096 "!TARGET_64BIT && TARGET_MIPS16
3097 && (register_operand (operands[0], DImode)
3098 || register_operand (operands[1], DImode))"
3099 { return mips_output_move (operands[0], operands[1]); }
3100 [(set_attr "type" "arith,arith,arith,arith,arith,load,store,mfhilo")
3101 (set_attr "mode" "DI")
3102 (set_attr "length" "8,8,8,8,12,*,*,8")])
3104 (define_insn "*movdi_64bit"
3105 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*x,*B*C*D,*B*C*D,*d,*m")
3106 (match_operand:DI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*J*d,*d,*m,*B*C*D,*B*C*D"))]
3107 "TARGET_64BIT && !TARGET_MIPS16
3108 && (register_operand (operands[0], DImode)
3109 || reg_or_0_operand (operands[1], DImode))"
3110 { return mips_output_move (operands[0], operands[1]); }
3111 [(set_attr "type" "arith,const,const,load,store,fmove,xfer,fpload,xfer,fpstore,mthilo,xfer,load,xfer,store")
3112 (set_attr "mode" "DI")
3113 (set_attr "length" "4,*,*,*,*,4,4,*,4,*,4,8,*,8,*")])
3115 (define_insn "*movdi_64bit_mips16"
3116 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m")
3117 (match_operand:DI 1 "move_operand" "d,d,y,K,N,U,m,d"))]
3118 "TARGET_64BIT && TARGET_MIPS16
3119 && (register_operand (operands[0], DImode)
3120 || register_operand (operands[1], DImode))"
3121 { return mips_output_move (operands[0], operands[1]); }
3122 [(set_attr "type" "arith,arith,arith,arith,arith,const,load,store")
3123 (set_attr "mode" "DI")
3124 (set_attr_alternative "length"
3128 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3131 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3136 (const_string "*")])])
3139 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
3140 ;; when the original load is a 4 byte instruction but the add and the
3141 ;; load are 2 2 byte instructions.
3144 [(set (match_operand:DI 0 "register_operand")
3145 (mem:DI (plus:DI (match_dup 0)
3146 (match_operand:DI 1 "const_int_operand"))))]
3147 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
3148 && !TARGET_DEBUG_D_MODE
3149 && GET_CODE (operands[0]) == REG
3150 && M16_REG_P (REGNO (operands[0]))
3151 && GET_CODE (operands[1]) == CONST_INT
3152 && ((INTVAL (operands[1]) < 0
3153 && INTVAL (operands[1]) >= -0x10)
3154 || (INTVAL (operands[1]) >= 32 * 8
3155 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
3156 || (INTVAL (operands[1]) >= 0
3157 && INTVAL (operands[1]) < 32 * 8
3158 && (INTVAL (operands[1]) & 7) != 0))"
3159 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
3160 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
3162 HOST_WIDE_INT val = INTVAL (operands[1]);
3165 operands[2] = const0_rtx;
3166 else if (val >= 32 * 8)
3170 operands[1] = GEN_INT (0x8 + off);
3171 operands[2] = GEN_INT (val - off - 0x8);
3177 operands[1] = GEN_INT (off);
3178 operands[2] = GEN_INT (val - off);
3182 ;; 32-bit Integer moves
3184 ;; Unlike most other insns, the move insns can't be split with
3185 ;; different predicates, because register spilling and other parts of
3186 ;; the compiler, have memoized the insn number already.
3188 (define_expand "movsi"
3189 [(set (match_operand:SI 0 "")
3190 (match_operand:SI 1 ""))]
3193 if (mips_legitimize_move (SImode, operands[0], operands[1]))
3197 ;; The difference between these two is whether or not ints are allowed
3198 ;; in FP registers (off by default, use -mdebugh to enable).
3200 (define_insn "*movsi_internal"
3201 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*f,*d,*m,*d,*z,*x,*B*C*D,*B*C*D,*d,*m")
3202 (match_operand:SI 1 "move_operand" "d,U,T,m,dJ,*f,*d*J,*m,*f,*f,*z,*d,*J*d,*d,*m,*B*C*D,*B*C*D"))]
3204 && (register_operand (operands[0], SImode)
3205 || reg_or_0_operand (operands[1], SImode))"
3206 { return mips_output_move (operands[0], operands[1]); }
3207 [(set_attr "type" "arith,const,const,load,store,fmove,xfer,fpload,xfer,fpstore,xfer,xfer,mthilo,xfer,load,xfer,store")
3208 (set_attr "mode" "SI")
3209 (set_attr "length" "4,*,*,*,*,4,4,*,4,*,4,4,4,4,*,4,*")])
3211 (define_insn "*movsi_mips16"
3212 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,m")
3213 (match_operand:SI 1 "move_operand" "d,d,y,K,N,U,m,d"))]
3215 && (register_operand (operands[0], SImode)
3216 || register_operand (operands[1], SImode))"
3217 { return mips_output_move (operands[0], operands[1]); }
3218 [(set_attr "type" "arith,arith,arith,arith,arith,const,load,store")
3219 (set_attr "mode" "SI")
3220 (set_attr_alternative "length"
3224 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3227 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3232 (const_string "*")])])
3234 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
3235 ;; when the original load is a 4 byte instruction but the add and the
3236 ;; load are 2 2 byte instructions.
3239 [(set (match_operand:SI 0 "register_operand")
3240 (mem:SI (plus:SI (match_dup 0)
3241 (match_operand:SI 1 "const_int_operand"))))]
3242 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3243 && GET_CODE (operands[0]) == REG
3244 && M16_REG_P (REGNO (operands[0]))
3245 && GET_CODE (operands[1]) == CONST_INT
3246 && ((INTVAL (operands[1]) < 0
3247 && INTVAL (operands[1]) >= -0x80)
3248 || (INTVAL (operands[1]) >= 32 * 4
3249 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
3250 || (INTVAL (operands[1]) >= 0
3251 && INTVAL (operands[1]) < 32 * 4
3252 && (INTVAL (operands[1]) & 3) != 0))"
3253 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3254 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
3256 HOST_WIDE_INT val = INTVAL (operands[1]);
3259 operands[2] = const0_rtx;
3260 else if (val >= 32 * 4)
3264 operands[1] = GEN_INT (0x7c + off);
3265 operands[2] = GEN_INT (val - off - 0x7c);
3271 operands[1] = GEN_INT (off);
3272 operands[2] = GEN_INT (val - off);
3276 ;; On the mips16, we can split a load of certain constants into a load
3277 ;; and an add. This turns a 4 byte instruction into 2 2 byte
3281 [(set (match_operand:SI 0 "register_operand")
3282 (match_operand:SI 1 "const_int_operand"))]
3283 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3284 && GET_CODE (operands[0]) == REG
3285 && M16_REG_P (REGNO (operands[0]))
3286 && GET_CODE (operands[1]) == CONST_INT
3287 && INTVAL (operands[1]) >= 0x100
3288 && INTVAL (operands[1]) <= 0xff + 0x7f"
3289 [(set (match_dup 0) (match_dup 1))
3290 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
3292 int val = INTVAL (operands[1]);
3294 operands[1] = GEN_INT (0xff);
3295 operands[2] = GEN_INT (val - 0xff);
3298 ;; This insn handles moving CCmode values. It's really just a
3299 ;; slightly simplified copy of movsi_internal2, with additional cases
3300 ;; to move a condition register to a general register and to move
3301 ;; between the general registers and the floating point registers.
3303 (define_insn "movcc"
3304 [(set (match_operand:CC 0 "nonimmediate_operand" "=d,*d,*d,*m,*d,*f,*f,*f,*m")
3305 (match_operand:CC 1 "general_operand" "z,*d,*m,*d,*f,*d,*f,*m,*f"))]
3306 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3307 { return mips_output_move (operands[0], operands[1]); }
3308 [(set_attr "type" "xfer,arith,load,store,xfer,xfer,fmove,fpload,fpstore")
3309 (set_attr "mode" "SI")
3310 (set_attr "length" "8,4,*,*,4,4,4,*,*")])
3312 ;; Reload condition code registers. reload_incc and reload_outcc
3313 ;; both handle moves from arbitrary operands into condition code
3314 ;; registers. reload_incc handles the more common case in which
3315 ;; a source operand is constrained to be in a condition-code
3316 ;; register, but has not been allocated to one.
3318 ;; Sometimes, such as in movcc, we have a CCmode destination whose
3319 ;; constraints do not include 'z'. reload_outcc handles the case
3320 ;; when such an operand is allocated to a condition-code register.
3322 ;; Note that reloads from a condition code register to some
3323 ;; other location can be done using ordinary moves. Moving
3324 ;; into a GPR takes a single movcc, moving elsewhere takes
3325 ;; two. We can leave these cases to the generic reload code.
3326 (define_expand "reload_incc"
3327 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3328 (match_operand:CC 1 "general_operand" ""))
3329 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3330 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3332 mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
3336 (define_expand "reload_outcc"
3337 [(set (match_operand:CC 0 "fcc_reload_operand" "=z")
3338 (match_operand:CC 1 "register_operand" ""))
3339 (clobber (match_operand:TF 2 "register_operand" "=&f"))]
3340 "ISA_HAS_8CC && TARGET_HARD_FLOAT"
3342 mips_emit_fcc_reload (operands[0], operands[1], operands[2]);
3346 ;; MIPS4 supports loading and storing a floating point register from
3347 ;; the sum of two general registers. We use two versions for each of
3348 ;; these four instructions: one where the two general registers are
3349 ;; SImode, and one where they are DImode. This is because general
3350 ;; registers will be in SImode when they hold 32 bit values, but,
3351 ;; since the 32 bit values are always sign extended, the [ls][wd]xc1
3352 ;; instructions will still work correctly.
3354 ;; ??? Perhaps it would be better to support these instructions by
3355 ;; modifying GO_IF_LEGITIMATE_ADDRESS and friends. However, since
3356 ;; these instructions can only be used to load and store floating
3357 ;; point registers, that would probably cause trouble in reload.
3359 (define_insn "*<ANYF:loadx>_<P:mode>"
3360 [(set (match_operand:ANYF 0 "register_operand" "=f")
3361 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3362 (match_operand:P 2 "register_operand" "d"))))]
3364 "<ANYF:loadx>\t%0,%1(%2)"
3365 [(set_attr "type" "fpidxload")
3366 (set_attr "mode" "<ANYF:UNITMODE>")])
3368 (define_insn "*<ANYF:storex>_<P:mode>"
3369 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
3370 (match_operand:P 2 "register_operand" "d")))
3371 (match_operand:ANYF 0 "register_operand" "f"))]
3373 "<ANYF:storex>\t%0,%1(%2)"
3374 [(set_attr "type" "fpidxstore")
3375 (set_attr "mode" "<ANYF:UNITMODE>")])
3377 ;; 16-bit Integer moves
3379 ;; Unlike most other insns, the move insns can't be split with
3380 ;; different predicates, because register spilling and other parts of
3381 ;; the compiler, have memoized the insn number already.
3382 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3384 (define_expand "movhi"
3385 [(set (match_operand:HI 0 "")
3386 (match_operand:HI 1 ""))]
3389 if (mips_legitimize_move (HImode, operands[0], operands[1]))
3393 (define_insn "*movhi_internal"
3394 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x")
3395 (match_operand:HI 1 "move_operand" "d,I,m,dJ,*f,*d,*f,*d"))]
3397 && (register_operand (operands[0], HImode)
3398 || reg_or_0_operand (operands[1], HImode))"
3408 [(set_attr "type" "arith,arith,load,store,xfer,xfer,fmove,mthilo")
3409 (set_attr "mode" "HI")
3410 (set_attr "length" "4,4,*,*,4,4,4,4")])
3412 (define_insn "*movhi_mips16"
3413 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3414 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d"))]
3416 && (register_operand (operands[0], HImode)
3417 || register_operand (operands[1], HImode))"
3426 [(set_attr "type" "arith,arith,arith,arith,arith,load,store")
3427 (set_attr "mode" "HI")
3428 (set_attr_alternative "length"
3432 (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3435 (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3439 (const_string "*")])])
3442 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
3443 ;; when the original load is a 4 byte instruction but the add and the
3444 ;; load are 2 2 byte instructions.
3447 [(set (match_operand:HI 0 "register_operand")
3448 (mem:HI (plus:SI (match_dup 0)
3449 (match_operand:SI 1 "const_int_operand"))))]
3450 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3451 && GET_CODE (operands[0]) == REG
3452 && M16_REG_P (REGNO (operands[0]))
3453 && GET_CODE (operands[1]) == CONST_INT
3454 && ((INTVAL (operands[1]) < 0
3455 && INTVAL (operands[1]) >= -0x80)
3456 || (INTVAL (operands[1]) >= 32 * 2
3457 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
3458 || (INTVAL (operands[1]) >= 0
3459 && INTVAL (operands[1]) < 32 * 2
3460 && (INTVAL (operands[1]) & 1) != 0))"
3461 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3462 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
3464 HOST_WIDE_INT val = INTVAL (operands[1]);
3467 operands[2] = const0_rtx;
3468 else if (val >= 32 * 2)
3472 operands[1] = GEN_INT (0x7e + off);
3473 operands[2] = GEN_INT (val - off - 0x7e);
3479 operands[1] = GEN_INT (off);
3480 operands[2] = GEN_INT (val - off);
3484 ;; 8-bit Integer moves
3486 ;; Unlike most other insns, the move insns can't be split with
3487 ;; different predicates, because register spilling and other parts of
3488 ;; the compiler, have memoized the insn number already.
3489 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
3491 (define_expand "movqi"
3492 [(set (match_operand:QI 0 "")
3493 (match_operand:QI 1 ""))]
3496 if (mips_legitimize_move (QImode, operands[0], operands[1]))
3500 (define_insn "*movqi_internal"
3501 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,d,d,m,*d,*f,*f,*x")
3502 (match_operand:QI 1 "move_operand" "d,I,m,dJ,*f,*d,*f,*d"))]
3504 && (register_operand (operands[0], QImode)
3505 || reg_or_0_operand (operands[1], QImode))"
3515 [(set_attr "type" "arith,arith,load,store,xfer,xfer,fmove,mthilo")
3516 (set_attr "mode" "QI")
3517 (set_attr "length" "4,4,*,*,4,4,4,4")])
3519 (define_insn "*movqi_mips16"
3520 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m")
3521 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d"))]
3523 && (register_operand (operands[0], QImode)
3524 || register_operand (operands[1], QImode))"
3533 [(set_attr "type" "arith,arith,arith,arith,arith,load,store")
3534 (set_attr "mode" "QI")
3535 (set_attr "length" "4,4,4,4,8,*,*")])
3537 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
3538 ;; when the original load is a 4 byte instruction but the add and the
3539 ;; load are 2 2 byte instructions.
3542 [(set (match_operand:QI 0 "register_operand")
3543 (mem:QI (plus:SI (match_dup 0)
3544 (match_operand:SI 1 "const_int_operand"))))]
3545 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
3546 && GET_CODE (operands[0]) == REG
3547 && M16_REG_P (REGNO (operands[0]))
3548 && GET_CODE (operands[1]) == CONST_INT
3549 && ((INTVAL (operands[1]) < 0
3550 && INTVAL (operands[1]) >= -0x80)
3551 || (INTVAL (operands[1]) >= 32
3552 && INTVAL (operands[1]) <= 31 + 0x7f))"
3553 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
3554 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
3556 HOST_WIDE_INT val = INTVAL (operands[1]);
3559 operands[2] = const0_rtx;
3562 operands[1] = GEN_INT (0x7f);
3563 operands[2] = GEN_INT (val - 0x7f);
3567 ;; 32-bit floating point moves
3569 (define_expand "movsf"
3570 [(set (match_operand:SF 0 "")
3571 (match_operand:SF 1 ""))]
3574 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
3578 (define_insn "*movsf_hardfloat"
3579 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3580 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
3582 && (register_operand (operands[0], SFmode)
3583 || reg_or_0_operand (operands[1], SFmode))"
3584 { return mips_output_move (operands[0], operands[1]); }
3585 [(set_attr "type" "fmove,xfer,fpload,fpstore,store,xfer,xfer,arith,load,store")
3586 (set_attr "mode" "SF")
3587 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3589 (define_insn "*movsf_softfloat"
3590 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
3591 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
3592 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
3593 && (register_operand (operands[0], SFmode)
3594 || reg_or_0_operand (operands[1], SFmode))"
3595 { return mips_output_move (operands[0], operands[1]); }
3596 [(set_attr "type" "arith,load,store")
3597 (set_attr "mode" "SF")
3598 (set_attr "length" "4,*,*")])
3600 (define_insn "*movsf_mips16"
3601 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
3602 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
3604 && (register_operand (operands[0], SFmode)
3605 || register_operand (operands[1], SFmode))"
3606 { return mips_output_move (operands[0], operands[1]); }
3607 [(set_attr "type" "arith,arith,arith,load,store")
3608 (set_attr "mode" "SF")
3609 (set_attr "length" "4,4,4,*,*")])
3612 ;; 64-bit floating point moves
3614 (define_expand "movdf"
3615 [(set (match_operand:DF 0 "")
3616 (match_operand:DF 1 ""))]
3619 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
3623 (define_insn "*movdf_hardfloat_64bit"
3624 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3625 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3626 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && TARGET_64BIT
3627 && (register_operand (operands[0], DFmode)
3628 || reg_or_0_operand (operands[1], DFmode))"
3629 { return mips_output_move (operands[0], operands[1]); }
3630 [(set_attr "type" "fmove,xfer,fpload,fpstore,store,xfer,xfer,arith,load,store")
3631 (set_attr "mode" "DF")
3632 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3634 (define_insn "*movdf_hardfloat_32bit"
3635 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3636 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
3637 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT
3638 && (register_operand (operands[0], DFmode)
3639 || reg_or_0_operand (operands[1], DFmode))"
3640 { return mips_output_move (operands[0], operands[1]); }
3641 [(set_attr "type" "fmove,xfer,fpload,fpstore,store,xfer,xfer,arith,load,store")
3642 (set_attr "mode" "DF")
3643 (set_attr "length" "4,8,*,*,*,8,8,8,*,*")])
3645 (define_insn "*movdf_softfloat"
3646 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m,d,f,f")
3647 (match_operand:DF 1 "move_operand" "dG,m,dG,f,d,f"))]
3648 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
3649 && (register_operand (operands[0], DFmode)
3650 || reg_or_0_operand (operands[1], DFmode))"
3651 { return mips_output_move (operands[0], operands[1]); }
3652 [(set_attr "type" "arith,load,store,xfer,xfer,fmove")
3653 (set_attr "mode" "DF")
3654 (set_attr "length" "8,*,*,4,4,4")])
3656 (define_insn "*movdf_mips16"
3657 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
3658 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
3660 && (register_operand (operands[0], DFmode)
3661 || register_operand (operands[1], DFmode))"
3662 { return mips_output_move (operands[0], operands[1]); }
3663 [(set_attr "type" "arith,arith,arith,load,store")
3664 (set_attr "mode" "DF")
3665 (set_attr "length" "8,8,8,*,*")])
3668 [(set (match_operand:DI 0 "nonimmediate_operand")
3669 (match_operand:DI 1 "move_operand"))]
3670 "reload_completed && !TARGET_64BIT
3671 && mips_split_64bit_move_p (operands[0], operands[1])"
3674 mips_split_64bit_move (operands[0], operands[1]);
3679 [(set (match_operand:DF 0 "nonimmediate_operand")
3680 (match_operand:DF 1 "move_operand"))]
3681 "reload_completed && !TARGET_64BIT
3682 && mips_split_64bit_move_p (operands[0], operands[1])"
3685 mips_split_64bit_move (operands[0], operands[1]);
3689 ;; When generating mips16 code, split moves of negative constants into
3690 ;; a positive "li" followed by a negation.
3692 [(set (match_operand 0 "register_operand")
3693 (match_operand 1 "const_int_operand"))]
3694 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
3698 (neg:SI (match_dup 2)))]
3700 operands[2] = gen_lowpart (SImode, operands[0]);
3701 operands[3] = GEN_INT (-INTVAL (operands[1]));
3704 ;; 64-bit paired-single floating point moves
3706 (define_expand "movv2sf"
3707 [(set (match_operand:V2SF 0)
3708 (match_operand:V2SF 1))]
3709 "TARGET_PAIRED_SINGLE_FLOAT"
3711 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
3715 (define_insn "movv2sf_hardfloat_64bit"
3716 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
3717 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
3718 "TARGET_PAIRED_SINGLE_FLOAT
3720 && (register_operand (operands[0], V2SFmode)
3721 || reg_or_0_operand (operands[1], V2SFmode))"
3722 { return mips_output_move (operands[0], operands[1]); }
3723 [(set_attr "type" "fmove,xfer,fpload,fpstore,store,xfer,xfer,arith,load,store")
3724 (set_attr "mode" "SF")
3725 (set_attr "length" "4,4,*,*,*,4,4,4,*,*")])
3727 ;; The HI and LO registers are not truly independent. If we move an mthi
3728 ;; instruction before an mflo instruction, it will make the result of the
3729 ;; mflo unpredictable. The same goes for mtlo and mfhi.
3731 ;; We cope with this by making the mflo and mfhi patterns use both HI and LO.
3732 ;; Operand 1 is the register we want, operand 2 is the other one.
3734 (define_insn "mfhilo_<mode>"
3735 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3736 (unspec:GPR [(match_operand:GPR 1 "register_operand" "h,l")
3737 (match_operand:GPR 2 "register_operand" "l,h")]
3741 [(set_attr "type" "mfhilo")
3742 (set_attr "mode" "<MODE>")])
3744 ;; Patterns for loading or storing part of a paired floating point
3745 ;; register. We need them because odd-numbered floating-point registers
3746 ;; are not fully independent: see mips_split_64bit_move.
3748 ;; Load the low word of operand 0 with operand 1.
3749 (define_insn "load_df_low"
3750 [(set (match_operand:DF 0 "register_operand" "=f,f")
3751 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")]
3752 UNSPEC_LOAD_DF_LOW))]
3753 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
3755 operands[0] = mips_subword (operands[0], 0);
3756 return mips_output_move (operands[0], operands[1]);
3758 [(set_attr "type" "xfer,fpload")
3759 (set_attr "mode" "SF")])
3761 ;; Load the high word of operand 0 from operand 1, preserving the value
3763 (define_insn "load_df_high"
3764 [(set (match_operand:DF 0 "register_operand" "=f,f")
3765 (unspec:DF [(match_operand:SI 1 "general_operand" "dJ,m")
3766 (match_operand:DF 2 "register_operand" "0,0")]
3767 UNSPEC_LOAD_DF_HIGH))]
3768 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
3770 operands[0] = mips_subword (operands[0], 1);
3771 return mips_output_move (operands[0], operands[1]);
3773 [(set_attr "type" "xfer,fpload")
3774 (set_attr "mode" "SF")])
3776 ;; Store the high word of operand 1 in operand 0. The corresponding
3777 ;; low-word move is done in the normal way.
3778 (define_insn "store_df_high"
3779 [(set (match_operand:SI 0 "nonimmediate_operand" "=d,m")
3780 (unspec:SI [(match_operand:DF 1 "register_operand" "f,f")]
3781 UNSPEC_STORE_DF_HIGH))]
3782 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !TARGET_64BIT"
3784 operands[1] = mips_subword (operands[1], 1);
3785 return mips_output_move (operands[0], operands[1]);
3787 [(set_attr "type" "xfer,fpstore")
3788 (set_attr "mode" "SF")])
3790 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
3791 ;; of _gp from the start of this function. Operand 1 is the incoming
3792 ;; function address.
3793 (define_insn_and_split "loadgp"
3794 [(unspec_volatile [(match_operand 0 "" "")
3795 (match_operand 1 "register_operand" "")] UNSPEC_LOADGP)]
3796 "TARGET_ABICALLS && TARGET_NEWABI"
3799 [(set (match_dup 2) (match_dup 3))
3800 (set (match_dup 2) (match_dup 4))
3801 (set (match_dup 2) (match_dup 5))]
3803 operands[2] = pic_offset_table_rtx;
3804 operands[3] = gen_rtx_HIGH (Pmode, operands[0]);
3805 operands[4] = gen_rtx_PLUS (Pmode, operands[2], operands[1]);
3806 operands[5] = gen_rtx_LO_SUM (Pmode, operands[2], operands[0]);
3808 [(set_attr "length" "12")])
3810 ;; The use of gp is hidden when not using explicit relocations.
3811 ;; This blockage instruction prevents the gp load from being
3812 ;; scheduled after an implicit use of gp. It also prevents
3813 ;; the load from being deleted as dead.
3814 (define_insn "loadgp_blockage"
3815 [(unspec_volatile [(reg:DI 28)] UNSPEC_BLOCKAGE)]
3818 [(set_attr "type" "unknown")
3819 (set_attr "mode" "none")
3820 (set_attr "length" "0")])
3822 ;; Emit a .cprestore directive, which normally expands to a single store
3823 ;; instruction. Note that we continue to use .cprestore for explicit reloc
3824 ;; code so that jals inside inline asms will work correctly.
3825 (define_insn "cprestore"
3826 [(unspec_volatile [(match_operand 0 "const_int_operand" "I,i")]
3830 if (set_nomacro && which_alternative == 1)
3831 return ".set\tmacro\;.cprestore\t%0\;.set\tnomacro";
3833 return ".cprestore\t%0";
3835 [(set_attr "type" "store")
3836 (set_attr "length" "4,12")])
3838 ;; Block moves, see mips.c for more details.
3839 ;; Argument 0 is the destination
3840 ;; Argument 1 is the source
3841 ;; Argument 2 is the length
3842 ;; Argument 3 is the alignment
3844 (define_expand "movmemsi"
3845 [(parallel [(set (match_operand:BLK 0 "general_operand")
3846 (match_operand:BLK 1 "general_operand"))
3847 (use (match_operand:SI 2 ""))
3848 (use (match_operand:SI 3 "const_int_operand"))])]
3849 "!TARGET_MIPS16 && !TARGET_MEMCPY"
3851 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
3858 ;; ....................
3862 ;; ....................
3864 (define_expand "<optab><mode>3"
3865 [(set (match_operand:GPR 0 "register_operand")
3866 (any_shift:GPR (match_operand:GPR 1 "register_operand")
3867 (match_operand:SI 2 "arith_operand")))]
3870 /* On the mips16, a shift of more than 8 is a four byte instruction,
3871 so, for a shift between 8 and 16, it is just as fast to do two
3872 shifts of 8 or less. If there is a lot of shifting going on, we
3873 may win in CSE. Otherwise combine will put the shifts back
3874 together again. This can be called by function_arg, so we must
3875 be careful not to allocate a new register if we've reached the
3879 && GET_CODE (operands[2]) == CONST_INT
3880 && INTVAL (operands[2]) > 8
3881 && INTVAL (operands[2]) <= 16
3882 && !reload_in_progress
3883 && !reload_completed)
3885 rtx temp = gen_reg_rtx (<MODE>mode);
3887 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
3888 emit_insn (gen_<optab><mode>3 (operands[0], temp,
3889 GEN_INT (INTVAL (operands[2]) - 8)));
3894 (define_insn "*<optab><mode>3"
3895 [(set (match_operand:GPR 0 "register_operand" "=d")
3896 (any_shift:GPR (match_operand:GPR 1 "register_operand" "d")
3897 (match_operand:SI 2 "arith_operand" "dI")))]
3900 if (GET_CODE (operands[2]) == CONST_INT)
3901 operands[2] = GEN_INT (INTVAL (operands[2])
3902 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
3904 return "<d><insn>\t%0,%1,%2";
3906 [(set_attr "type" "shift")
3907 (set_attr "mode" "<MODE>")])
3909 (define_insn "*<optab>si3_extend"
3910 [(set (match_operand:DI 0 "register_operand" "=d")
3912 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
3913 (match_operand:SI 2 "arith_operand" "dI"))))]
3914 "TARGET_64BIT && !TARGET_MIPS16"
3916 if (GET_CODE (operands[2]) == CONST_INT)
3917 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
3919 return "<insn>\t%0,%1,%2";
3921 [(set_attr "type" "shift")
3922 (set_attr "mode" "SI")])
3924 (define_insn "*<optab>si3_mips16"
3925 [(set (match_operand:SI 0 "register_operand" "=d,d")
3926 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d")
3927 (match_operand:SI 2 "arith_operand" "d,I")))]
3930 if (which_alternative == 0)
3931 return "<insn>\t%0,%2";
3933 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
3934 return "<insn>\t%0,%1,%2";
3936 [(set_attr "type" "shift")
3937 (set_attr "mode" "SI")
3938 (set_attr_alternative "length"
3940 (if_then_else (match_operand 2 "m16_uimm3_b")
3944 ;; We need separate DImode MIPS16 patterns because of the irregularity
3946 (define_insn "*ashldi3_mips16"
3947 [(set (match_operand:DI 0 "register_operand" "=d,d")
3948 (ashift:DI (match_operand:DI 1 "register_operand" "0,d")
3949 (match_operand:SI 2 "arith_operand" "d,I")))]
3950 "TARGET_64BIT && TARGET_MIPS16"
3952 if (which_alternative == 0)
3953 return "dsll\t%0,%2";
3955 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
3956 return "dsll\t%0,%1,%2";
3958 [(set_attr "type" "shift")
3959 (set_attr "mode" "DI")
3960 (set_attr_alternative "length"
3962 (if_then_else (match_operand 2 "m16_uimm3_b")
3966 (define_insn "*ashrdi3_mips16"
3967 [(set (match_operand:DI 0 "register_operand" "=d,d")
3968 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
3969 (match_operand:SI 2 "arith_operand" "d,I")))]
3970 "TARGET_64BIT && TARGET_MIPS16"
3972 if (GET_CODE (operands[2]) == CONST_INT)
3973 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
3975 return "dsra\t%0,%2";
3977 [(set_attr "type" "shift")
3978 (set_attr "mode" "DI")
3979 (set_attr_alternative "length"
3981 (if_then_else (match_operand 2 "m16_uimm3_b")
3985 (define_insn "*lshrdi3_mips16"
3986 [(set (match_operand:DI 0 "register_operand" "=d,d")
3987 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0")
3988 (match_operand:SI 2 "arith_operand" "d,I")))]
3989 "TARGET_64BIT && TARGET_MIPS16"
3991 if (GET_CODE (operands[2]) == CONST_INT)
3992 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
3994 return "dsrl\t%0,%2";
3996 [(set_attr "type" "shift")
3997 (set_attr "mode" "DI")
3998 (set_attr_alternative "length"
4000 (if_then_else (match_operand 2 "m16_uimm3_b")
4004 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
4007 [(set (match_operand:GPR 0 "register_operand")
4008 (any_shift:GPR (match_operand:GPR 1 "register_operand")
4009 (match_operand:GPR 2 "const_int_operand")))]
4010 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4011 && GET_CODE (operands[2]) == CONST_INT
4012 && INTVAL (operands[2]) > 8
4013 && INTVAL (operands[2]) <= 16"
4014 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
4015 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
4016 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
4018 ;; If we load a byte on the mips16 as a bitfield, the resulting
4019 ;; sequence of instructions is too complicated for combine, because it
4020 ;; involves four instructions: a load, a shift, a constant load into a
4021 ;; register, and an and (the key problem here is that the mips16 does
4022 ;; not have and immediate). We recognize a shift of a load in order
4023 ;; to make it simple enough for combine to understand.
4025 ;; The length here is the worst case: the length of the split version
4026 ;; will be more accurate.
4027 (define_insn_and_split ""
4028 [(set (match_operand:SI 0 "register_operand" "=d")
4029 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
4030 (match_operand:SI 2 "immediate_operand" "I")))]
4034 [(set (match_dup 0) (match_dup 1))
4035 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
4037 [(set_attr "type" "load")
4038 (set_attr "mode" "SI")
4039 (set_attr "length" "16")])
4041 (define_insn "rotr<mode>3"
4042 [(set (match_operand:GPR 0 "register_operand" "=d")
4043 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
4044 (match_operand:SI 2 "arith_operand" "dI")))]
4045 "ISA_HAS_ROTR_<MODE>"
4047 if (GET_CODE (operands[2]) == CONST_INT)
4048 gcc_assert (INTVAL (operands[2]) >= 0
4049 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
4051 return "<d>ror\t%0,%1,%2";
4053 [(set_attr "type" "shift")
4054 (set_attr "mode" "<MODE>")])
4057 ;; ....................
4061 ;; ....................
4063 ;; Flow here is rather complex:
4065 ;; 1) The cmp{si,di,sf,df} routine is called. It deposits the arguments
4066 ;; into cmp_operands[] but generates no RTL.
4068 ;; 2) The appropriate branch define_expand is called, which then
4069 ;; creates the appropriate RTL for the comparison and branch.
4070 ;; Different CC modes are used, based on what type of branch is
4071 ;; done, so that we can constrain things appropriately. There
4072 ;; are assumptions in the rest of GCC that break if we fold the
4073 ;; operands into the branches for integer operations, and use cc0
4074 ;; for floating point, so we use the fp status register instead.
4075 ;; If needed, an appropriate temporary is created to hold the
4076 ;; of the integer compare.
4078 (define_expand "cmp<mode>"
4080 (compare:CC (match_operand:GPR 0 "register_operand")
4081 (match_operand:GPR 1 "nonmemory_operand")))]
4084 cmp_operands[0] = operands[0];
4085 cmp_operands[1] = operands[1];
4089 (define_expand "cmp<mode>"
4091 (compare:CC (match_operand:SCALARF 0 "register_operand")
4092 (match_operand:SCALARF 1 "register_operand")))]
4095 cmp_operands[0] = operands[0];
4096 cmp_operands[1] = operands[1];
4101 ;; ....................
4103 ;; CONDITIONAL BRANCHES
4105 ;; ....................
4107 ;; Conditional branches on floating-point equality tests.
4109 (define_insn "branch_fp"
4112 (match_operator:CC 0 "comparison_operator"
4113 [(match_operand:CC 2 "register_operand" "z")
4115 (label_ref (match_operand 1 "" ""))
4119 return mips_output_conditional_branch (insn,
4121 /*two_operands_p=*/0,
4124 get_attr_length (insn));
4126 [(set_attr "type" "branch")
4127 (set_attr "mode" "none")])
4129 (define_insn "branch_fp_inverted"
4132 (match_operator:CC 0 "comparison_operator"
4133 [(match_operand:CC 2 "register_operand" "z")
4136 (label_ref (match_operand 1 "" ""))))]
4139 return mips_output_conditional_branch (insn,
4141 /*two_operands_p=*/0,
4144 get_attr_length (insn));
4146 [(set_attr "type" "branch")
4147 (set_attr "mode" "none")])
4149 ;; Conditional branches on comparisons with zero.
4151 (define_insn "*branch_zero<mode>"
4154 (match_operator:GPR 0 "comparison_operator"
4155 [(match_operand:GPR 2 "register_operand" "d")
4157 (label_ref (match_operand 1 "" ""))
4161 return mips_output_conditional_branch (insn,
4163 /*two_operands_p=*/0,
4166 get_attr_length (insn));
4168 [(set_attr "type" "branch")
4169 (set_attr "mode" "none")])
4171 (define_insn "*branch_zero<mode>_inverted"
4174 (match_operator:GPR 0 "comparison_operator"
4175 [(match_operand:GPR 2 "register_operand" "d")
4178 (label_ref (match_operand 1 "" ""))))]
4181 return mips_output_conditional_branch (insn,
4183 /*two_operands_p=*/0,
4186 get_attr_length (insn));
4188 [(set_attr "type" "branch")
4189 (set_attr "mode" "none")])
4191 ;; Conditional branch on equality comparison.
4193 (define_insn "*branch_equality<mode>"
4196 (match_operator:GPR 0 "equality_operator"
4197 [(match_operand:GPR 2 "register_operand" "d")
4198 (match_operand:GPR 3 "register_operand" "d")])
4199 (label_ref (match_operand 1 "" ""))
4203 return mips_output_conditional_branch (insn,
4205 /*two_operands_p=*/1,
4208 get_attr_length (insn));
4210 [(set_attr "type" "branch")
4211 (set_attr "mode" "none")])
4213 (define_insn "*branch_equality<mode>_inverted"
4216 (match_operator:GPR 0 "equality_operator"
4217 [(match_operand:GPR 2 "register_operand" "d")
4218 (match_operand:GPR 3 "register_operand" "d")])
4220 (label_ref (match_operand 1 "" ""))))]
4223 return mips_output_conditional_branch (insn,
4225 /*two_operands_p=*/1,
4228 get_attr_length (insn));
4230 [(set_attr "type" "branch")
4231 (set_attr "mode" "none")])
4235 (define_insn "*branch_equality<mode>_mips16"
4238 (match_operator:GPR 0 "equality_operator"
4239 [(match_operand:GPR 1 "register_operand" "d,t")
4241 (match_operand 2 "pc_or_label_operand" "")
4242 (match_operand 3 "pc_or_label_operand" "")))]
4245 if (operands[2] != pc_rtx)
4247 if (which_alternative == 0)
4248 return "b%C0z\t%1,%2";
4250 return "bt%C0z\t%2";
4254 if (which_alternative == 0)
4255 return "b%N0z\t%1,%3";
4257 return "bt%N0z\t%3";
4260 [(set_attr "type" "branch")
4261 (set_attr "mode" "none")
4262 (set_attr "length" "8")])
4264 (define_expand "b<code>"
4266 (if_then_else (any_cond:CC (cc0)
4268 (label_ref (match_operand 0 ""))
4272 gen_conditional_branch (operands, <CODE>);
4277 ;; ....................
4279 ;; SETTING A REGISTER FROM A COMPARISON
4281 ;; ....................
4283 (define_expand "seq"
4284 [(set (match_operand:SI 0 "register_operand")
4285 (eq:SI (match_dup 1)
4288 { if (mips_emit_scc (EQ, operands[0])) DONE; else FAIL; })
4290 (define_insn "*seq_<mode>"
4291 [(set (match_operand:GPR 0 "register_operand" "=d")
4292 (eq:GPR (match_operand:GPR 1 "register_operand" "d")
4296 [(set_attr "type" "slt")
4297 (set_attr "mode" "<MODE>")])
4299 (define_insn "*seq_<mode>_mips16"
4300 [(set (match_operand:GPR 0 "register_operand" "=t")
4301 (eq:GPR (match_operand:GPR 1 "register_operand" "d")
4305 [(set_attr "type" "slt")
4306 (set_attr "mode" "<MODE>")])
4308 ;; "sne" uses sltu instructions in which the first operand is $0.
4309 ;; This isn't possible in mips16 code.
4311 (define_expand "sne"
4312 [(set (match_operand:SI 0 "register_operand")
4313 (ne:SI (match_dup 1)
4316 { if (mips_emit_scc (NE, operands[0])) DONE; else FAIL; })
4318 (define_insn "*sne_<mode>"
4319 [(set (match_operand:GPR 0 "register_operand" "=d")
4320 (ne:GPR (match_operand:GPR 1 "register_operand" "d")
4324 [(set_attr "type" "slt")
4325 (set_attr "mode" "<MODE>")])
4327 (define_expand "sgt"
4328 [(set (match_operand:SI 0 "register_operand")
4329 (gt:SI (match_dup 1)
4332 { if (mips_emit_scc (GT, operands[0])) DONE; else FAIL; })
4334 (define_insn "*sgt_<mode>"
4335 [(set (match_operand:GPR 0 "register_operand" "=d")
4336 (gt:GPR (match_operand:GPR 1 "register_operand" "d")
4337 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
4340 [(set_attr "type" "slt")
4341 (set_attr "mode" "<MODE>")])
4343 (define_insn "*sgt_<mode>_mips16"
4344 [(set (match_operand:GPR 0 "register_operand" "=t")
4345 (gt:GPR (match_operand:GPR 1 "register_operand" "d")
4346 (match_operand:GPR 2 "register_operand" "d")))]
4349 [(set_attr "type" "slt")
4350 (set_attr "mode" "<MODE>")])
4352 (define_expand "sge"
4353 [(set (match_operand:SI 0 "register_operand")
4354 (ge:SI (match_dup 1)
4357 { if (mips_emit_scc (GE, operands[0])) DONE; else FAIL; })
4359 (define_insn "*sge_<mode>"
4360 [(set (match_operand:GPR 0 "register_operand" "=d")
4361 (ge:GPR (match_operand:GPR 1 "register_operand" "d")
4365 [(set_attr "type" "slt")
4366 (set_attr "mode" "<MODE>")])
4368 (define_expand "slt"
4369 [(set (match_operand:SI 0 "register_operand")
4370 (lt:SI (match_dup 1)
4373 { if (mips_emit_scc (LT, operands[0])) DONE; else FAIL; })
4375 (define_insn "*slt_<mode>"
4376 [(set (match_operand:GPR 0 "register_operand" "=d")
4377 (lt:GPR (match_operand:GPR 1 "register_operand" "d")
4378 (match_operand:GPR 2 "arith_operand" "dI")))]
4381 [(set_attr "type" "slt")
4382 (set_attr "mode" "<MODE>")])
4384 (define_insn "*slt_<mode>_mips16"
4385 [(set (match_operand:GPR 0 "register_operand" "=t,t")
4386 (lt:GPR (match_operand:GPR 1 "register_operand" "d,d")
4387 (match_operand:GPR 2 "arith_operand" "d,I")))]
4390 [(set_attr "type" "slt")
4391 (set_attr "mode" "<MODE>")
4392 (set_attr_alternative "length"
4394 (if_then_else (match_operand 2 "m16_uimm8_1")
4398 (define_expand "sle"
4399 [(set (match_operand:SI 0 "register_operand")
4400 (le:SI (match_dup 1)
4403 { if (mips_emit_scc (LE, operands[0])) DONE; else FAIL; })
4405 (define_insn "*sle_<mode>"
4406 [(set (match_operand:GPR 0 "register_operand" "=d")
4407 (le:GPR (match_operand:GPR 1 "register_operand" "d")
4408 (match_operand:GPR 2 "sle_operand" "")))]
4411 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4412 return "slt\t%0,%1,%2";
4414 [(set_attr "type" "slt")
4415 (set_attr "mode" "<MODE>")])
4417 (define_insn "*sle_<mode>_mips16"
4418 [(set (match_operand:GPR 0 "register_operand" "=t")
4419 (le:GPR (match_operand:GPR 1 "register_operand" "d")
4420 (match_operand:GPR 2 "sle_operand" "")))]
4423 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4424 return "slt\t%1,%2";
4426 [(set_attr "type" "slt")
4427 (set_attr "mode" "<MODE>")
4428 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
4432 (define_expand "sgtu"
4433 [(set (match_operand:SI 0 "register_operand")
4434 (gtu:SI (match_dup 1)
4437 { if (mips_emit_scc (GTU, operands[0])) DONE; else FAIL; })
4439 (define_insn "*sgtu_<mode>"
4440 [(set (match_operand:GPR 0 "register_operand" "=d")
4441 (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
4442 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
4445 [(set_attr "type" "slt")
4446 (set_attr "mode" "<MODE>")])
4448 (define_insn "*sgtu_<mode>_mips16"
4449 [(set (match_operand:GPR 0 "register_operand" "=t")
4450 (gtu:GPR (match_operand:GPR 1 "register_operand" "d")
4451 (match_operand:GPR 2 "register_operand" "d")))]
4454 [(set_attr "type" "slt")
4455 (set_attr "mode" "<MODE>")])
4457 (define_expand "sgeu"
4458 [(set (match_operand:SI 0 "register_operand")
4459 (geu:SI (match_dup 1)
4462 { if (mips_emit_scc (GEU, operands[0])) DONE; else FAIL; })
4464 (define_insn "*sge_<mode>"
4465 [(set (match_operand:GPR 0 "register_operand" "=d")
4466 (geu:GPR (match_operand:GPR 1 "register_operand" "d")
4470 [(set_attr "type" "slt")
4471 (set_attr "mode" "<MODE>")])
4473 (define_expand "sltu"
4474 [(set (match_operand:SI 0 "register_operand")
4475 (ltu:SI (match_dup 1)
4478 { if (mips_emit_scc (LTU, operands[0])) DONE; else FAIL; })
4480 (define_insn "*sltu_<mode>"
4481 [(set (match_operand:GPR 0 "register_operand" "=d")
4482 (ltu:GPR (match_operand:GPR 1 "register_operand" "d")
4483 (match_operand:GPR 2 "arith_operand" "dI")))]
4486 [(set_attr "type" "slt")
4487 (set_attr "mode" "<MODE>")])
4489 (define_insn "*sltu_<mode>_mips16"
4490 [(set (match_operand:GPR 0 "register_operand" "=t,t")
4491 (ltu:GPR (match_operand:GPR 1 "register_operand" "d,d")
4492 (match_operand:GPR 2 "arith_operand" "d,I")))]
4495 [(set_attr "type" "slt")
4496 (set_attr "mode" "<MODE>")
4497 (set_attr_alternative "length"
4499 (if_then_else (match_operand 2 "m16_uimm8_1")
4503 (define_expand "sleu"
4504 [(set (match_operand:SI 0 "register_operand")
4505 (leu:SI (match_dup 1)
4508 { if (mips_emit_scc (LEU, operands[0])) DONE; else FAIL; })
4510 (define_insn "*sleu_<mode>"
4511 [(set (match_operand:GPR 0 "register_operand" "=d")
4512 (leu:GPR (match_operand:GPR 1 "register_operand" "d")
4513 (match_operand:GPR 2 "sleu_operand" "")))]
4516 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4517 return "sltu\t%0,%1,%2";
4519 [(set_attr "type" "slt")
4520 (set_attr "mode" "<MODE>")])
4522 (define_insn "*sleu_<mode>_mips16"
4523 [(set (match_operand:GPR 0 "register_operand" "=t")
4524 (leu:GPR (match_operand:GPR 1 "register_operand" "d")
4525 (match_operand:GPR 2 "sleu_operand" "")))]
4528 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
4529 return "sltu\t%1,%2";
4531 [(set_attr "type" "slt")
4532 (set_attr "mode" "<MODE>")
4533 (set (attr "length") (if_then_else (match_operand 2 "m16_uimm8_m1_1")
4538 ;; ....................
4540 ;; FLOATING POINT COMPARISONS
4542 ;; ....................
4544 (define_insn "s<code>_<mode>"
4545 [(set (match_operand:CC 0 "register_operand" "=z")
4546 (fcond:CC (match_operand:SCALARF 1 "register_operand" "f")
4547 (match_operand:SCALARF 2 "register_operand" "f")))]
4549 "c.<fcond>.<fmt>\t%Z0%1,%2"
4550 [(set_attr "type" "fcmp")
4551 (set_attr "mode" "FPSW")])
4553 (define_insn "sgt_<mode>"
4554 [(set (match_operand:CC 0 "register_operand" "=z")
4555 (gt:CC (match_operand:SCALARF 1 "register_operand" "f")
4556 (match_operand:SCALARF 2 "register_operand" "f")))]
4558 "c.lt.<fmt>\t%Z0%2,%1"
4559 [(set_attr "type" "fcmp")
4560 (set_attr "mode" "FPSW")])
4562 (define_insn "sge_<mode>"
4563 [(set (match_operand:CC 0 "register_operand" "=z")
4564 (ge:CC (match_operand:SCALARF 1 "register_operand" "f")
4565 (match_operand:SCALARF 2 "register_operand" "f")))]
4567 "c.le.<fmt>\t%Z0%2,%1"
4568 [(set_attr "type" "fcmp")
4569 (set_attr "mode" "FPSW")])
4572 ;; ....................
4574 ;; UNCONDITIONAL BRANCHES
4576 ;; ....................
4578 ;; Unconditional branches.
4582 (label_ref (match_operand 0 "" "")))]
4587 if (get_attr_length (insn) <= 8)
4588 return "%*b\t%l0%/";
4591 output_asm_insn (mips_output_load_label (), operands);
4592 return "%*jr\t%@%/%]";
4596 return "%*j\t%l0%/";
4598 [(set_attr "type" "jump")
4599 (set_attr "mode" "none")
4600 (set (attr "length")
4601 ;; We can't use `j' when emitting PIC. Emit a branch if it's
4602 ;; in range, otherwise load the address of the branch target into
4603 ;; $at and then jump to it.
4605 (ior (eq (symbol_ref "flag_pic") (const_int 0))
4606 (lt (abs (minus (match_dup 0)
4607 (plus (pc) (const_int 4))))
4608 (const_int 131072)))
4609 (const_int 4) (const_int 16)))])
4611 ;; We need a different insn for the mips16, because a mips16 branch
4612 ;; does not have a delay slot.
4616 (label_ref (match_operand 0 "" "")))]
4619 [(set_attr "type" "branch")
4620 (set_attr "mode" "none")
4621 (set_attr "length" "8")])
4623 (define_expand "indirect_jump"
4624 [(set (pc) (match_operand 0 "register_operand"))]
4627 operands[0] = force_reg (Pmode, operands[0]);
4628 if (Pmode == SImode)
4629 emit_jump_insn (gen_indirect_jumpsi (operands[0]));
4631 emit_jump_insn (gen_indirect_jumpdi (operands[0]));
4635 (define_insn "indirect_jump<mode>"
4636 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
4639 [(set_attr "type" "jump")
4640 (set_attr "mode" "none")])
4642 (define_expand "tablejump"
4644 (match_operand 0 "register_operand"))
4645 (use (label_ref (match_operand 1 "")))]
4649 operands[0] = expand_binop (Pmode, add_optab,
4650 convert_to_mode (Pmode, operands[0], false),
4651 gen_rtx_LABEL_REF (Pmode, operands[1]),
4653 else if (TARGET_GPWORD)
4654 operands[0] = expand_binop (Pmode, add_optab, operands[0],
4655 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
4657 if (Pmode == SImode)
4658 emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
4660 emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
4664 (define_insn "tablejump<mode>"
4666 (match_operand:P 0 "register_operand" "d"))
4667 (use (label_ref (match_operand 1 "" "")))]
4670 [(set_attr "type" "jump")
4671 (set_attr "mode" "none")])
4673 ;; For TARGET_ABICALLS, we save the gp in the jmp_buf as well.
4674 ;; While it is possible to either pull it off the stack (in the
4675 ;; o32 case) or recalculate it given t9 and our target label,
4676 ;; it takes 3 or 4 insns to do so.
4678 (define_expand "builtin_setjmp_setup"
4679 [(use (match_operand 0 "register_operand"))]
4684 addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
4685 emit_move_insn (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
4689 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
4690 ;; that older code did recalculate the gp from $25. Continue to jump through
4691 ;; $25 for compatibility (we lose nothing by doing so).
4693 (define_expand "builtin_longjmp"
4694 [(use (match_operand 0 "register_operand"))]
4697 /* The elements of the buffer are, in order: */
4698 int W = GET_MODE_SIZE (Pmode);
4699 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
4700 rtx lab = gen_rtx_MEM (Pmode, plus_constant (operands[0], 1*W));
4701 rtx stack = gen_rtx_MEM (Pmode, plus_constant (operands[0], 2*W));
4702 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (operands[0], 3*W));
4703 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
4704 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
4705 The target is bound to be using $28 as the global pointer
4706 but the current function might not be. */
4707 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
4709 /* This bit is similar to expand_builtin_longjmp except that it
4710 restores $gp as well. */
4711 emit_move_insn (hard_frame_pointer_rtx, fp);
4712 emit_move_insn (pv, lab);
4713 emit_stack_restore (SAVE_NONLOCAL, stack, NULL_RTX);
4714 emit_move_insn (gp, gpv);
4715 emit_insn (gen_rtx_USE (VOIDmode, hard_frame_pointer_rtx));
4716 emit_insn (gen_rtx_USE (VOIDmode, stack_pointer_rtx));
4717 emit_insn (gen_rtx_USE (VOIDmode, gp));
4718 emit_indirect_jump (pv);
4723 ;; ....................
4725 ;; Function prologue/epilogue
4727 ;; ....................
4730 (define_expand "prologue"
4734 mips_expand_prologue ();
4738 ;; Block any insns from being moved before this point, since the
4739 ;; profiling call to mcount can use various registers that aren't
4740 ;; saved or used to pass arguments.
4742 (define_insn "blockage"
4743 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
4746 [(set_attr "type" "unknown")
4747 (set_attr "mode" "none")
4748 (set_attr "length" "0")])
4750 (define_expand "epilogue"
4754 mips_expand_epilogue (false);
4758 (define_expand "sibcall_epilogue"
4762 mips_expand_epilogue (true);
4766 ;; Trivial return. Make it look like a normal return insn as that
4767 ;; allows jump optimizations to work better.
4769 (define_insn "return"
4771 "mips_can_use_return_insn ()"
4773 [(set_attr "type" "jump")
4774 (set_attr "mode" "none")])
4778 (define_insn "return_internal"
4780 (use (match_operand 0 "pmode_register_operand" ""))]
4783 [(set_attr "type" "jump")
4784 (set_attr "mode" "none")])
4786 ;; This is used in compiling the unwind routines.
4787 (define_expand "eh_return"
4788 [(use (match_operand 0 "general_operand"))]
4791 enum machine_mode gpr_mode = TARGET_64BIT ? DImode : SImode;
4793 if (GET_MODE (operands[0]) != gpr_mode)
4794 operands[0] = convert_to_mode (gpr_mode, operands[0], 0);
4796 emit_insn (gen_eh_set_lr_di (operands[0]));
4798 emit_insn (gen_eh_set_lr_si (operands[0]));
4803 ;; Clobber the return address on the stack. We can't expand this
4804 ;; until we know where it will be put in the stack frame.
4806 (define_insn "eh_set_lr_si"
4807 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
4808 (clobber (match_scratch:SI 1 "=&d"))]
4812 (define_insn "eh_set_lr_di"
4813 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
4814 (clobber (match_scratch:DI 1 "=&d"))]
4819 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
4820 (clobber (match_scratch 1))]
4821 "reload_completed && !TARGET_DEBUG_D_MODE"
4824 mips_set_return_address (operands[0], operands[1]);
4828 (define_insn_and_split "exception_receiver"
4830 (unspec_volatile:SI [(const_int 0)] UNSPEC_EH_RECEIVER))]
4831 "TARGET_ABICALLS && TARGET_OLDABI"
4833 "&& reload_completed"
4839 [(set_attr "type" "load")
4840 (set_attr "length" "12")])
4843 ;; ....................
4847 ;; ....................
4849 ;; Instructions to load a call address from the GOT. The address might
4850 ;; point to a function or to a lazy binding stub. In the latter case,
4851 ;; the stub will use the dynamic linker to resolve the function, which
4852 ;; in turn will change the GOT entry to point to the function's real
4855 ;; This means that every call, even pure and constant ones, can
4856 ;; potentially modify the GOT entry. And once a stub has been called,
4857 ;; we must not call it again.
4859 ;; We represent this restriction using an imaginary fixed register that
4860 ;; acts like a GOT version number. By making the register call-clobbered,
4861 ;; we tell the target-independent code that the address could be changed
4862 ;; by any call insn.
4863 (define_insn "load_call<mode>"
4864 [(set (match_operand:P 0 "register_operand" "=c")
4865 (unspec:P [(match_operand:P 1 "register_operand" "r")
4866 (match_operand:P 2 "immediate_operand" "")
4867 (reg:P FAKE_CALL_REGNO)]
4870 "<load>\t%0,%R2(%1)"
4871 [(set_attr "type" "load")
4872 (set_attr "mode" "<MODE>")
4873 (set_attr "length" "4")])
4875 ;; Sibling calls. All these patterns use jump instructions.
4877 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
4878 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
4879 ;; is defined in terms of call_insn_operand, the same is true of the
4882 ;; When we use an indirect jump, we need a register that will be
4883 ;; preserved by the epilogue. Since TARGET_ABICALLS forces us to
4884 ;; use $25 for this purpose -- and $25 is never clobbered by the
4885 ;; epilogue -- we might as well use it for !TARGET_ABICALLS as well.
4887 (define_expand "sibcall"
4888 [(parallel [(call (match_operand 0 "")
4889 (match_operand 1 ""))
4890 (use (match_operand 2 "")) ;; next_arg_reg
4891 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
4894 mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
4898 (define_insn "sibcall_internal"
4899 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
4900 (match_operand 1 "" ""))]
4901 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
4905 [(set_attr "type" "call")])
4907 (define_expand "sibcall_value"
4908 [(parallel [(set (match_operand 0 "")
4909 (call (match_operand 1 "")
4910 (match_operand 2 "")))
4911 (use (match_operand 3 ""))])] ;; next_arg_reg
4914 mips_expand_call (operands[0], XEXP (operands[1], 0),
4915 operands[2], operands[3], true);
4919 (define_insn "sibcall_value_internal"
4920 [(set (match_operand 0 "register_operand" "=df,df")
4921 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
4922 (match_operand 2 "" "")))]
4923 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
4927 [(set_attr "type" "call")])
4929 (define_insn "sibcall_value_multiple_internal"
4930 [(set (match_operand 0 "register_operand" "=df,df")
4931 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
4932 (match_operand 2 "" "")))
4933 (set (match_operand 3 "register_operand" "=df,df")
4934 (call (mem:SI (match_dup 1))
4936 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
4940 [(set_attr "type" "call")])
4942 (define_expand "call"
4943 [(parallel [(call (match_operand 0 "")
4944 (match_operand 1 ""))
4945 (use (match_operand 2 "")) ;; next_arg_reg
4946 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
4949 mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
4953 ;; This instruction directly corresponds to an assembly-language "jal".
4954 ;; There are four cases:
4957 ;; Both symbolic and register destinations are OK. The pattern
4958 ;; always expands to a single mips instruction.
4960 ;; - -mabicalls/-mno-explicit-relocs:
4961 ;; Again, both symbolic and register destinations are OK.
4962 ;; The call is treated as a multi-instruction black box.
4964 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
4965 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
4968 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
4969 ;; Only "jal $25" is allowed. The call is actually two instructions:
4970 ;; "jalr $25" followed by an insn to reload $gp.
4972 ;; In the last case, we can generate the individual instructions with
4973 ;; a define_split. There are several things to be wary of:
4975 ;; - We can't expose the load of $gp before reload. If we did,
4976 ;; it might get removed as dead, but reload can introduce new
4977 ;; uses of $gp by rematerializing constants.
4979 ;; - We shouldn't restore $gp after calls that never return.
4980 ;; It isn't valid to insert instructions between a noreturn
4981 ;; call and the following barrier.
4983 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
4984 ;; instruction preserves $gp and so have no effect on its liveness.
4985 ;; But once we generate the separate insns, it becomes obvious that
4986 ;; $gp is not live on entry to the call.
4988 ;; ??? The operands[2] = insn check is a hack to make the original insn
4989 ;; available to the splitter.
4990 (define_insn_and_split "call_internal"
4991 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
4992 (match_operand 1 "" ""))
4993 (clobber (reg:SI 31))]
4995 { return TARGET_SPLIT_CALLS ? "#" : "%*jal\t%0%/"; }
4996 "reload_completed && TARGET_SPLIT_CALLS && (operands[2] = insn)"
4999 emit_call_insn (gen_call_split (operands[0], operands[1]));
5000 if (!find_reg_note (operands[2], REG_NORETURN, 0))
5004 [(set_attr "jal" "indirect,direct")
5005 (set_attr "extended_mips16" "no,yes")])
5007 (define_insn "call_split"
5008 [(call (mem:SI (match_operand 0 "call_insn_operand" "c"))
5009 (match_operand 1 "" ""))
5010 (clobber (reg:SI 31))
5011 (clobber (reg:SI 28))]
5012 "TARGET_SPLIT_CALLS"
5014 [(set_attr "type" "call")])
5016 (define_expand "call_value"
5017 [(parallel [(set (match_operand 0 "")
5018 (call (match_operand 1 "")
5019 (match_operand 2 "")))
5020 (use (match_operand 3 ""))])] ;; next_arg_reg
5023 mips_expand_call (operands[0], XEXP (operands[1], 0),
5024 operands[2], operands[3], false);
5028 ;; See comment for call_internal.
5029 (define_insn_and_split "call_value_internal"
5030 [(set (match_operand 0 "register_operand" "=df,df")
5031 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5032 (match_operand 2 "" "")))
5033 (clobber (reg:SI 31))]
5035 { return TARGET_SPLIT_CALLS ? "#" : "%*jal\t%1%/"; }
5036 "reload_completed && TARGET_SPLIT_CALLS && (operands[3] = insn)"
5039 emit_call_insn (gen_call_value_split (operands[0], operands[1],
5041 if (!find_reg_note (operands[3], REG_NORETURN, 0))
5045 [(set_attr "jal" "indirect,direct")
5046 (set_attr "extended_mips16" "no,yes")])
5048 (define_insn "call_value_split"
5049 [(set (match_operand 0 "register_operand" "=df")
5050 (call (mem:SI (match_operand 1 "call_insn_operand" "c"))
5051 (match_operand 2 "" "")))
5052 (clobber (reg:SI 31))
5053 (clobber (reg:SI 28))]
5054 "TARGET_SPLIT_CALLS"
5056 [(set_attr "type" "call")])
5058 ;; See comment for call_internal.
5059 (define_insn_and_split "call_value_multiple_internal"
5060 [(set (match_operand 0 "register_operand" "=df,df")
5061 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
5062 (match_operand 2 "" "")))
5063 (set (match_operand 3 "register_operand" "=df,df")
5064 (call (mem:SI (match_dup 1))
5066 (clobber (reg:SI 31))]
5068 { return TARGET_SPLIT_CALLS ? "#" : "%*jal\t%1%/"; }
5069 "reload_completed && TARGET_SPLIT_CALLS && (operands[4] = insn)"
5072 emit_call_insn (gen_call_value_multiple_split (operands[0], operands[1],
5073 operands[2], operands[3]));
5074 if (!find_reg_note (operands[4], REG_NORETURN, 0))
5078 [(set_attr "jal" "indirect,direct")
5079 (set_attr "extended_mips16" "no,yes")])
5081 (define_insn "call_value_multiple_split"
5082 [(set (match_operand 0 "register_operand" "=df")
5083 (call (mem:SI (match_operand 1 "call_insn_operand" "c"))
5084 (match_operand 2 "" "")))
5085 (set (match_operand 3 "register_operand" "=df")
5086 (call (mem:SI (match_dup 1))
5088 (clobber (reg:SI 31))
5089 (clobber (reg:SI 28))]
5090 "TARGET_SPLIT_CALLS"
5092 [(set_attr "type" "call")])
5094 ;; Call subroutine returning any type.
5096 (define_expand "untyped_call"
5097 [(parallel [(call (match_operand 0 "")
5099 (match_operand 1 "")
5100 (match_operand 2 "")])]
5105 emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
5107 for (i = 0; i < XVECLEN (operands[2], 0); i++)
5109 rtx set = XVECEXP (operands[2], 0, i);
5110 emit_move_insn (SET_DEST (set), SET_SRC (set));
5113 emit_insn (gen_blockage ());
5118 ;; ....................
5122 ;; ....................
5126 (define_insn "prefetch"
5127 [(prefetch (match_operand:QI 0 "address_operand" "p")
5128 (match_operand 1 "const_int_operand" "n")
5129 (match_operand 2 "const_int_operand" "n"))]
5130 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
5132 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
5133 return "pref\t%1,%a0";
5135 [(set_attr "type" "prefetch")])
5137 (define_insn "*prefetch_indexed_<mode>"
5138 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
5139 (match_operand:P 1 "register_operand" "d"))
5140 (match_operand 2 "const_int_operand" "n")
5141 (match_operand 3 "const_int_operand" "n"))]
5142 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
5144 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
5145 return "prefx\t%2,%1(%0)";
5147 [(set_attr "type" "prefetchx")])
5153 [(set_attr "type" "nop")
5154 (set_attr "mode" "none")])
5156 ;; Like nop, but commented out when outside a .set noreorder block.
5157 (define_insn "hazard_nop"
5166 [(set_attr "type" "nop")])
5168 ;; MIPS4 Conditional move instructions.
5170 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
5171 [(set (match_operand:GPR 0 "register_operand" "=d,d")
5173 (match_operator:MOVECC 4 "equality_operator"
5174 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5176 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
5177 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
5182 [(set_attr "type" "condmove")
5183 (set_attr "mode" "<GPR:MODE>")])
5185 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
5186 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
5187 (if_then_else:SCALARF
5188 (match_operator:MOVECC 4 "equality_operator"
5189 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5191 (match_operand:SCALARF 2 "register_operand" "f,0")
5192 (match_operand:SCALARF 3 "register_operand" "0,f")))]
5195 mov%T4.<fmt>\t%0,%2,%1
5196 mov%t4.<fmt>\t%0,%3,%1"
5197 [(set_attr "type" "condmove")
5198 (set_attr "mode" "<SCALARF:MODE>")])
5200 ;; These are the main define_expand's used to make conditional moves.
5202 (define_expand "mov<mode>cc"
5203 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5204 (set (match_operand:GPR 0 "register_operand")
5205 (if_then_else:GPR (match_dup 5)
5206 (match_operand:GPR 2 "reg_or_0_operand")
5207 (match_operand:GPR 3 "reg_or_0_operand")))]
5210 gen_conditional_move (operands);
5214 (define_expand "mov<mode>cc"
5215 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
5216 (set (match_operand:SCALARF 0 "register_operand")
5217 (if_then_else:SCALARF (match_dup 5)
5218 (match_operand:SCALARF 2 "register_operand")
5219 (match_operand:SCALARF 3 "register_operand")))]
5222 gen_conditional_move (operands);
5227 ;; ....................
5229 ;; mips16 inline constant tables
5231 ;; ....................
5234 (define_insn "consttable_int"
5235 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
5236 (match_operand 1 "const_int_operand" "")]
5237 UNSPEC_CONSTTABLE_INT)]
5240 assemble_integer (operands[0], INTVAL (operands[1]),
5241 BITS_PER_UNIT * INTVAL (operands[1]), 1);
5244 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
5246 (define_insn "consttable_float"
5247 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
5248 UNSPEC_CONSTTABLE_FLOAT)]
5253 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
5254 REAL_VALUE_FROM_CONST_DOUBLE (d, operands[0]);
5255 assemble_real (d, GET_MODE (operands[0]),
5256 GET_MODE_BITSIZE (GET_MODE (operands[0])));
5259 [(set (attr "length")
5260 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
5262 (define_insn "align"
5263 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
5266 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
5269 [(match_operand 0 "small_data_pattern")]
5272 { operands[0] = mips_rewrite_small_data (operands[0]); })
5274 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
5276 (include "mips-ps-3d.md")