* config/mips/mips.md (<u>mulsidi3_32bit_r4000): Fix unsigned case.
[official-gcc.git] / gcc / config / mips / mips.md
blob70428ae78ed52e5ade2cf22dda00ca36c3096a4e
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)
14 ;; any later version.
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.
26 (define_constants
27   [(UNSPEC_LOAD_DF_LOW           0)
28    (UNSPEC_LOAD_DF_HIGH          1)
29    (UNSPEC_STORE_DF_HIGH         2)
30    (UNSPEC_GET_FNADDR            3)
31    (UNSPEC_BLOCKAGE              4)
32    (UNSPEC_CPRESTORE             5)
33    (UNSPEC_EH_RECEIVER           6)
34    (UNSPEC_EH_RETURN             7)
35    (UNSPEC_CONSTTABLE_INT        8)
36    (UNSPEC_CONSTTABLE_FLOAT      9)
37    (UNSPEC_ALIGN                14)
38    (UNSPEC_HIGH                 17)
39    (UNSPEC_LOAD_LEFT            18)
40    (UNSPEC_LOAD_RIGHT           19)
41    (UNSPEC_STORE_LEFT           20)
42    (UNSPEC_STORE_RIGHT          21)
43    (UNSPEC_LOADGP               22)
44    (UNSPEC_LOAD_CALL            23)
45    (UNSPEC_LOAD_GOT             24)
46    (UNSPEC_GP                   25)
47    (UNSPEC_MFHILO               26)
49    (UNSPEC_ADDRESS_FIRST        100)
51    (FAKE_CALL_REGNO             79)
53    ;; For MIPS Paired-Singled Floating Point Instructions.
55    (UNSPEC_MOVE_TF_PS           200)
56    (UNSPEC_C                    201)
58    ;; MIPS64/MIPS32R2 alnv.ps
59    (UNSPEC_ALNV_PS              202)
61    ;; MIPS-3D instructions
62    (UNSPEC_CABS                 203)
64    (UNSPEC_ADDR_PS              204)
65    (UNSPEC_CVT_PW_PS            205)
66    (UNSPEC_CVT_PS_PW            206)
67    (UNSPEC_MULR_PS              207)
69    (UNSPEC_RSQRT1               208)
70    (UNSPEC_RSQRT2               209)
71    (UNSPEC_RECIP1               210)
72    (UNSPEC_RECIP2               211)
73   ]
76 (include "predicates.md")
78 ;; ....................
80 ;;      Attributes
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)
147 ;; nop          no operation
148 (define_attr "type"
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"
160   (const_string "no"))
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:
167           ;;
168           ;;    bne     r1,r2,target
169           ;;    dslot
170           ;;
171           ;; becomes the equivalent of:
172           ;;
173           ;;    beq     r1,r2,1f
174           ;;    dslot
175           ;;    la      $at,target
176           ;;    jr      $at
177           ;;    nop
178           ;; 1:
179           ;;
180           ;; where the load address can be up to three instructions long
181           ;; (lw, nop, addiu).
182           ;;
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
189           ;; present.
190           ;;
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)))
199                   (const_int 4)
200                  (ne (symbol_ref "flag_pic") (const_int 0))
201                  (const_int 24)
202                  ] (const_int 12))
204           (eq_attr "got" "load")
205           (const_int 4)
206           (eq_attr "got" "xgot_high")
207           (const_int 8)
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:
217           ;;
218           ;;     lui $25,%call_hi(FOO)
219           ;;     addu $25,$25,$28
220           ;;     lw $25,%call_lo(FOO)($25)
221           ;;     nop
222           ;;     jalr $25
223           ;;     nop
224           ;;     lw $gp,X($sp)
225           ;;     nop
226           (eq_attr "jal_macro" "yes")
227           (const_int 32)
229           (and (eq_attr "extended_mips16" "yes")
230                (ne (symbol_ref "TARGET_MIPS16") (const_int 0)))
231           (const_int 8)
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)))
238           (const_int 8)
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))))
246           (const_int 8)
248           (eq_attr "type" "idiv")
249           (symbol_ref "mips_idiv_insns () * 4")
250           ] (const_int 4)))
252 ;; Attribute describing the processor.  This attribute must match exactly
253 ;; with the processor_type enumeration in mips.h.
254 (define_attr "cpu"
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")))
294                 (const_string "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"
299   (const
300    (if_then_else (ne (symbol_ref "GENERATE_BRANCHLIKELY") (const_int 0))
301                  (const_string "yes")
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")
308                 (const_string "yes")
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
347 ;; instruction.
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
367 ;; a given mode.
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
393 ; exist.
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")
423                          (ashiftrt "ashr")
424                          (lshiftrt "lshr")])
426 ;; <insn> expands to the name of the insn that implements a particular code.
427 (define_code_attr insn [(ashift "sll")
428                         (ashiftrt "sra")
429                         (lshiftrt "srl")])
431 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
432 (define_code_attr fcond [(unordered "un")
433                          (uneq "ueq")
434                          (unlt "ult")
435                          (unle "ule")
436                          (eq "eq")
437                          (lt "lt")
438                          (le "le")])
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")
449    (nil)
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")
455    (nil)
456    (nil)])
458 (define_delay (and (eq_attr "type" "call")
459                    (eq_attr "jal_macro" "no"))
460   [(eq_attr "can_delay" "yes")
461    (nil)
462    (nil)])
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")
479 (include "3000.md")
480 (include "4000.md")
481 (include "4100.md")
482 (include "4130.md")
483 (include "4300.md")
484 (include "4600.md")
485 (include "5000.md")
486 (include "5400.md")
487 (include "5500.md")
488 (include "6000.md")
489 (include "7000.md")
490 (include "9000.md")
491 (include "sb1.md")
492 (include "sr71k.md")
493 (include "generic.md")
496 ;;  ....................
498 ;;      CONDITIONAL TRAPS
500 ;;  ....................
503 (define_insn "trap"
504   [(trap_if (const_int 1) (const_int 0))]
505   ""
507   if (ISA_HAS_COND_TRAP)
508     return "teq\t$0,$0";
509   else if (TARGET_MIPS16)
510     return "break 0";
511   else
512     return "break";
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"))]
520   "ISA_HAS_COND_TRAP"
522   if (GET_MODE_CLASS (GET_MODE (cmp_operands[0])) == MODE_INT
523       && operands[1] == const0_rtx)
524     {
525       mips_gen_conditional_trap (operands);
526       DONE;
527     }
528   else
529     FAIL;
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")])
536             (const_int 0))]
537   "ISA_HAS_COND_TRAP"
538   "t%C0\t%z1,%2"
539   [(set_attr "type" "trap")])
542 ;;  ....................
544 ;;      ADDITION
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")))]
553   ""
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")))]
562   "")
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")))]
568   "!TARGET_MIPS16"
569   "@
570     <d>addu\t%0,%1,%2
571     <d>addiu\t%0,%1,%2"
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"
580   [(set (reg:GPR 29)
581         (plus:GPR (reg:GPR 29)
582                   (match_operand:GPR 0 "const_arith_operand" "")))]
583   "TARGET_MIPS16"
584   "<d>addiu\t%$,%$,%0"
585   [(set_attr "type" "arith")
586    (set_attr "mode" "<MODE>")
587    (set (attr "length") (if_then_else (match_operand 0 "m16_simm8_8")
588                                       (const_int 4)
589                                       (const_int 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" "")))]
595   "TARGET_MIPS16"
596   "<d>addiu\t%0,%$,%1"
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")
600                                       (const_int 4)
601                                       (const_int 8)))])
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")))]
607   "TARGET_MIPS16"
608   "@
609     <d>addiu\t%0,%2
610     <d>addiu\t%0,%1,%2
611     <d>addu\t%0,%1,%2"
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")
616                                (const_int 4)
617                                (const_int 8))
618                  (if_then_else (match_operand 2 "m16_simm4_1")
619                                (const_int 4)
620                                (const_int 8))
621                  (const_int 4)])])
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.
630 (define_split
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]);
647   if (val >= 0)
648     {
649       operands[1] = GEN_INT (0x7f);
650       operands[2] = GEN_INT (val - 0x7f);
651     }
652   else
653     {
654       operands[1] = GEN_INT (- 0x80);
655       operands[2] = GEN_INT (val + 0x80);
656     }
659 (define_split
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]);
679   if (val >= 0)
680     {
681       operands[2] = GEN_INT (0x7);
682       operands[3] = GEN_INT (val - 0x7);
683     }
684   else
685     {
686       operands[2] = GEN_INT (- 0x8);
687       operands[3] = GEN_INT (val + 0x8);
688     }
691 (define_split
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]);
708   if (val >= 0)
709     {
710       operands[1] = GEN_INT (0xf);
711       operands[2] = GEN_INT (val - 0xf);
712     }
713   else
714     {
715       operands[1] = GEN_INT (- 0x10);
716       operands[2] = GEN_INT (val + 0x10);
717     }
720 (define_split
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]);
740   if (val >= 0)
741     {
742       operands[2] = GEN_INT (0x7);
743       operands[3] = GEN_INT (val - 0x7);
744     }
745   else
746     {
747       operands[2] = GEN_INT (- 0x8);
748       operands[3] = GEN_INT (val + 0x8);
749     }
752 (define_insn "*addsi3_extended"
753   [(set (match_operand:DI 0 "register_operand" "=d,d")
754         (sign_extend:DI
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"
758   "@
759     addu\t%0,%1,%2
760     addiu\t%0,%1,%2"
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")
768         (sign_extend:DI
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"
772   "#"
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 ;;  ....................
783 ;;      SUBTRACTION
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")))]
792   ""
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")))]
801   ""
802   "<d>subu\t%0,%1,%2"
803   [(set_attr "type" "arith")
804    (set_attr "mode" "<MODE>")])
806 (define_insn "*subsi3_extended"
807   [(set (match_operand:DI 0 "register_operand" "=d")
808         (sign_extend:DI
809             (minus:SI (match_operand:SI 1 "register_operand" "d")
810                       (match_operand:SI 2 "register_operand" "d"))))]
811   "TARGET_64BIT"
812   "subu\t%0,%1,%2"
813   [(set_attr "type" "arith")
814    (set_attr "mode" "DI")])
817 ;;  ....................
819 ;;      MULTIPLICATION
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")))]
828   ""
829   "")
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"
859   "mul.ps\t%0,%1,%2"
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
878 ;;      bits.
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."
886 ;; and:
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.
896 ;;      Workaround:
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
902 ;;         is executed.
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,
907 ;; respectively.
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")))]
913   ""
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],
919                                         operands[2]));
920   else
921     emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
922   DONE;
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"))]
931   "GENERATE_MULT3_SI"
933   if (which_alternative == 1)
934     return "mult\t%1,%2";
935   if (TARGET_MAD
936       || TARGET_MIPS5400
937       || TARGET_MIPS5500
938       || TARGET_MIPS7000
939       || TARGET_MIPS9000
940       || ISA_MIPS32
941       || ISA_MIPS32R2
942       || ISA_MIPS64)
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"
956   "dmult\t%0,%1,%2"
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.
964 ;; Operand 0: LO
965 ;; Operand 1: GPR (1st multiplication operand)
966 ;; Operand 2: GPR (2nd multiplication operand)
967 ;; Operand 3: HI
968 ;; Operand 4: GPR (destination)
969 (define_peephole2
970   [(parallel
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])"
979   [(parallel
980        [(set (match_dup 4)
981              (mult:SI (match_dup 1)
982                       (match_dup 2)))
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"))]
991   "!TARGET_FIX_R4000"
992   "<d>mult\t%1,%2"
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"))]
1002   "TARGET_FIX_R4000"
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.
1012 ;; Operand 0: LO
1013 ;; Operand 1: GPR (1st multiplication operand)
1014 ;; Operand 2: GPR (2nd multiplication operand)
1015 ;; Operand 3: HI
1016 ;; Operand 4: GPR (destination)
1017 (define_peephole2
1018   [(parallel
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"
1026   [(set (match_dup 0)
1027         (const_int 0))
1028    (parallel
1029        [(set (match_dup 0)
1030              (plus:SI (mult:SI (match_dup 1)
1031                                (match_dup 2))
1032                       (match_dup 0)))
1033         (set (match_dup 4)
1034              (plus:SI (mult:SI (match_dup 1)
1035                                (match_dup 2))
1036                       (match_dup 0)))
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
1050 ;; trick.
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"))]
1059   "(TARGET_MIPS3900
1060    || ISA_HAS_MADD_MSUB)
1061    && !TARGET_MIPS16"
1063   static const char *const madd[] = { "madd\t%1,%2", "madd\t%0,%1,%2" };
1064   if (which_alternative == 2)
1065     return "#";
1066   if (ISA_HAS_MADD_MSUB && which_alternative != 0)
1067     return "#";
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.
1075 (define_split
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)))]
1091   "")
1093 ;; Splitter to copy result of MADD to a general register
1094 (define_split
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))
1107                             (match_dup 3)))
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))]
1112   "")
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"))]
1121   "ISA_HAS_MACC"
1123   if (which_alternative == 1)
1124     return "macc\t%0,%1,%2";
1125   else if (TARGET_MIPS5500)
1126     return "madd\t%1,%2";
1127   else
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"))]
1143   "ISA_HAS_MSAC"
1145   if (which_alternative == 1)
1146     return "msac\t%0,%2,%3";
1147   else if (TARGET_MIPS5500)
1148     return "msub\t%2,%3";
1149   else
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"
1165   "#"
1166   "&& reload_completed"
1167   [(set (match_dup 6)
1168         (neg:SI (match_dup 3)))
1169    (parallel
1170        [(set (match_dup 0)
1171              (plus:SI (mult:SI (match_dup 2)
1172                                (match_dup 6))
1173                       (match_dup 1)))
1174         (clobber (match_dup 4))
1175         (clobber (match_dup 5))])]
1176   ""
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"))
1186                  (match_dup 0)))
1187    (set (match_operand:SI 3 "register_operand" "=d")
1188         (plus:SI (mult:SI (match_dup 1)
1189                           (match_dup 2))
1190                  (match_dup 0)))
1191    (clobber (match_scratch:SI 4 "=h"))]
1192   "ISA_HAS_MACC && reload_completed"
1193   "macc\t%3,%1,%2"
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)
1205                            (match_dup 2))))
1206    (clobber (match_scratch:SI 4 "=h"))]
1207   "ISA_HAS_MSAC && reload_completed"
1208   "msac\t%3,%1,%2"
1209   [(set_attr "type"     "imadd")
1210    (set_attr "mode"     "SI")])
1212 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1213 ;; Similarly msac.
1215 ;; Operand 0: LO
1216 ;; Operand 1: macc/msac
1217 ;; Operand 2: HI
1218 ;; Operand 3: GPR (destination)
1219 (define_peephole2
1220   [(parallel
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))]
1227   ""
1228   [(parallel [(set (match_dup 0)
1229                    (match_dup 1))
1230               (set (match_dup 3)
1231                    (match_dup 1))
1232               (clobber (match_dup 2))])]
1233   "")
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)
1243 ;; Operand 1: LO
1244 ;; Operand 2: GPR (addend)
1245 ;; Operand 3: GPR (destination)
1246 ;; Operand 4: macc/msac
1247 ;; Operand 5: HI
1248 ;; Operand 6: new multiplication
1249 ;; Operand 7: new addition/subtraction
1250 (define_peephole2
1251   [(match_scratch:SI 0 "d")
1252    (set (match_operand:SI 1 "register_operand")
1253         (match_operand:SI 2 "register_operand"))
1254    (match_dup 0)
1255    (parallel
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))])]
1260   "GENERATE_MULT3_SI
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)
1265                    (match_dup 6))
1266               (clobber (match_dup 5))
1267               (clobber (match_dup 1))])
1268    (set (match_dup 3)
1269         (match_dup 7))]
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)
1279 ;; Operand 1: LO
1280 ;; Operand 2: GPR (addend)
1281 ;; Operand 3: macc/msac
1282 ;; Operand 4: HI
1283 ;; Operand 5: GPR (destination)
1284 ;; Operand 6: new multiplication
1285 ;; Operand 7: new addition/subtraction
1286 (define_peephole2
1287   [(match_scratch:SI 0 "d")
1288    (set (match_operand:SI 1 "register_operand")
1289         (match_operand:SI 2 "register_operand"))
1290    (match_dup 0)
1291    (parallel
1292        [(set (match_dup 1)
1293              (match_operand:SI 3 "macc_msac_operand"))
1294         (clobber (match_operand:SI 4 "register_operand"))
1295         (clobber (scratch:SI))])
1296    (match_dup 0)
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)
1301                    (match_dup 6))
1302               (clobber (match_dup 4))
1303               (clobber (match_dup 1))])
1304    (set (match_dup 5)
1305         (match_dup 7))]
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"))]
1320   "ISA_HAS_MADD_MSUB"
1321   "@
1322    msub\t%2,%3
1323    #
1324    #"
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.
1330 (define_split
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)))]
1346   "")
1348 ;; Splitter to copy result of MSUB to a general register
1349 (define_split
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))]
1367   "")
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"))]
1375   "ISA_HAS_MULS"
1376   "@
1377    muls\t$0,%1,%2
1378    muls\t%0,%1,%2"
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"
1385   [(parallel
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"
1394   if (!TARGET_64BIT)
1395     {
1396       if (!TARGET_FIX_R4000)
1397         emit_insn (gen_<u>mulsidi3_32bit_internal (operands[0], operands[1],
1398                                                    operands[2]));
1399       else
1400         emit_insn (gen_<u>mulsidi3_32bit_r4000 (operands[0], operands[1],
1401                                                 operands[2]));
1402       DONE;
1403     }
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"
1411   "mult<u>\t%1,%2"
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"
1434   "#"
1435   "&& reload_completed"
1436   [(parallel
1437        [(set (match_dup 3)
1438              (sign_extend:DI
1439                 (mult:SI (match_dup 1)
1440                          (match_dup 2))))
1441         (set (match_dup 4)
1442              (ashiftrt:DI
1443                 (mult:DI (any_extend:DI (match_dup 1))
1444                          (any_extend:DI (match_dup 2)))
1445                 (const_int 32)))])
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))
1451    ;; Zero-extend OP5.
1452    (set (match_dup 5)
1453         (ashift:DI (match_dup 5)
1454                    (const_int 32)))
1455    (set (match_dup 5)
1456         (lshiftrt:DI (match_dup 5)
1457                      (const_int 32)))
1459    ;; Shift OP0 into place.
1460    (set (match_dup 0)
1461         (ashift:DI (match_dup 0)
1462                    (const_int 32)))
1464    ;; OR the two halves together
1465    (set (match_dup 0)
1466         (ior:DI (match_dup 0)
1467                 (match_dup 5)))]
1468   ""
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")
1475         (sign_extend:DI
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")
1479         (ashiftrt:DI
1480            (mult:DI (any_extend:DI (match_dup 2))
1481                     (any_extend:DI (match_dup 3)))
1482            (const_int 32)))]
1483   "TARGET_64BIT && !TARGET_FIX_R4000"
1484   "mult<u>\t%2,%3"
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")
1491         (neg:DI
1492          (mult:DI
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"
1496   "muls<u>\t$0,%1,%2"
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")
1502         (minus:DI
1503            (match_operand:DI 3 "register_operand" "0")
1504            (mult:DI
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";
1511   else
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")
1521         (truncate:SI
1522          (lshiftrt:DI
1523           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
1524                    (any_extend:DI (match_operand:SI 2 "register_operand")))
1525           (const_int 32))))]
1526   "ISA_HAS_MULHI || !TARGET_FIX_R4000"
1528   if (ISA_HAS_MULHI)
1529     emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
1530                                                        operands[1],
1531                                                        operands[2]));
1532   else
1533     emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
1534                                                  operands[2]));
1535   DONE;
1538 (define_insn "<su>mulsi3_highpart_internal"
1539   [(set (match_operand:SI 0 "register_operand" "=h")
1540         (truncate:SI
1541          (lshiftrt:DI
1542           (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
1543                    (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
1544           (const_int 32))))
1545    (clobber (match_scratch:SI 3 "=l"))]
1546   "!ISA_HAS_MULHI && !TARGET_FIX_R4000"
1547   "mult<u>\t%1,%2"
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")
1553         (truncate:SI
1554          (lshiftrt:DI
1555           (mult:DI
1556            (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1557            (any_extend:DI (match_operand:SI 2 "register_operand" "d,d")))
1558           (const_int 32))))
1559    (clobber (match_scratch:SI 3 "=l,l"))
1560    (clobber (match_scratch:SI 4 "=X,h"))]
1561   "ISA_HAS_MULHI"
1562   "@
1563    mult<u>\t%1,%2
1564    mulhi<u>\t%0,%1,%2"
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")
1570         (truncate:SI
1571          (lshiftrt:DI
1572           (neg:DI
1573            (mult:DI
1574             (any_extend:DI (match_operand:SI 1 "register_operand" "d,d"))
1575             (any_extend:DI (match_operand:SI 2 "register_operand" "d,d"))))
1576           (const_int 32))))
1577    (clobber (match_scratch:SI 3 "=l,l"))
1578    (clobber (match_scratch:SI 4 "=X,h"))]
1579   "ISA_HAS_MULHI"
1580   "@
1581    mulshi<u>\t%.,%1,%2
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
1588 ;; correct result.
1589 (define_insn "<su>muldi3_highpart"
1590   [(set (match_operand:DI 0 "register_operand" "=h")
1591         (truncate:DI
1592          (lshiftrt:TI
1593           (mult:TI
1594            (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
1595            (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
1596           (const_int 64))))
1597    (clobber (match_scratch:DI 3 "=l"))]
1598   "TARGET_64BIT && !TARGET_FIX_R4000
1599    && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
1600   "dmult<u>\t%1,%2"
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"))
1611                  (match_dup 0)))
1612    (clobber (match_scratch:SI 3 "=h"))]
1613   "TARGET_MAD"
1614   "mad\t%1,%2"
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")
1620         (plus:DI
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)
1625    && !TARGET_64BIT"
1627   if (TARGET_MAD)
1628     return "mad<u>\t%1,%2";
1629   else if (TARGET_MIPS5500)
1630     return "madd<u>\t%1,%2";
1631   else
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")
1674         (minus:ANYF
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")
1698         (minus:ANYF
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>"
1745   if (TARGET_FIX_SB1)
1746     return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
1747   else
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))
1754                       (const_int 8)
1755                       (const_int 4)))])
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"
1763   if (TARGET_FIX_SB1)
1764     return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1765   else
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))
1772                       (const_int 8)
1773                       (const_int 4)))])
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)
1783                  (match_dup 2)))]
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)
1795                   (match_dup 2)))]
1796   ""
1797   { return mips_output_division ("<d>divu\t$0,%1,%2", operands); }
1798   [(set_attr "type" "idiv")
1799    (set_attr "mode" "<MODE>")])
1802 ;;  ....................
1804 ;;      SQUARE ROOT
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")))]
1814   "<sqrt_condition>"
1816   if (TARGET_FIX_SB1)
1817     return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
1818   else
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))
1825                       (const_int 8)
1826                       (const_int 4)))])
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"
1834   if (TARGET_FIX_SB1)
1835     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1836   else
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))
1843                       (const_int 8)
1844                       (const_int 4)))])
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"
1852   if (TARGET_FIX_SB1)
1853     return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
1854   else
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))
1861                       (const_int 8)
1862                       (const_int 4)))])
1865 ;;  ....................
1867 ;;      ABSOLUTE VALUE
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")))]
1877   "!TARGET_MIPS16"
1879   if (REGNO (operands[0]) == REGNO (operands[1]) && GENERATE_BRANCHLIKELY)
1880     return "%(bltzl\t%1,1f\;<d>subu\t%0,%.,%0\n%~1:%)";
1881   else
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")))]
1891   ""
1892   "abs.<fmt>\t%0,%1"
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"))]
1909   "!TARGET_MIPS16"
1911   if (optimize && find_reg_note (insn, REG_DEAD, operands[1]))
1912     return "%(\
1913 move\t%0,%.\;\
1914 beq\t%1,%.,2f\n\
1915 %~1:\tand\t%2,%1,0x0001\;\
1916 <d>addu\t%0,%0,1\;\
1917 beq\t%2,%.,1b\;\
1918 <d>srl\t%1,%1,1\n\
1919 %~2:%)";
1921   return "%(\
1922 move\t%0,%.\;\
1923 move\t%3,%1\;\
1924 beq\t%3,%.,2f\n\
1925 %~1:\tand\t%2,%3,0x0001\;\
1926 <d>addu\t%0,%0,1\;\
1927 beq\t%2,%.,1b\;\
1928 <d>srl\t%3,%3,1\n\
1929 %~2:%)";
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")))]
1946   "ISA_HAS_CLZ_CLO"
1947   "<d>clz\t%0,%1"
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")))]
1961   ""
1963   if (TARGET_MIPS16)
1964     return "neg\t%0,%1";
1965   else
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"
1975   "dsubu\t%0,%.,%1"
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")))]
1982   ""
1983   "neg.<fmt>\t%0,%1"
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")))]
1990   ""
1992   if (TARGET_MIPS16)
1993     return "not\t%0,%1";
1994   else
1995     return "nor\t%0,%.,%1";
1997   [(set_attr "type" "arith")
1998    (set_attr "mode" "<MODE>")])
2001 ;;  ....................
2003 ;;      LOGICAL
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")))]
2015   ""
2017   if (TARGET_MIPS16)
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")))]
2025   "!TARGET_MIPS16"
2026   "@
2027    and\t%0,%1,%2
2028    andi\t%0,%1,%x2"
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")))]
2036   "TARGET_MIPS16"
2037   "and\t%0,%2"
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")))]
2045   ""
2047   if (TARGET_MIPS16)
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")))]
2055   "!TARGET_MIPS16"
2056   "@
2057    or\t%0,%1,%2
2058    ori\t%0,%1,%x2"
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")))]
2066   "TARGET_MIPS16"
2067   "or\t%0,%2"
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")))]
2075   ""
2076   "")
2078 (define_insn ""
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")))]
2082   "!TARGET_MIPS16"
2083   "@
2084    xor\t%0,%1,%2
2085    xori\t%0,%1,%x2"
2086   [(set_attr "type" "arith")
2087    (set_attr "mode" "<MODE>")])
2089 (define_insn ""
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")))]
2093   "TARGET_MIPS16"
2094   "@
2095    xor\t%0,%2
2096    cmpi\t%1,%2
2097    cmp\t%1,%2"
2098   [(set_attr "type" "arith")
2099    (set_attr "mode" "<MODE>")
2100    (set_attr_alternative "length"
2101                 [(const_int 4)
2102                  (if_then_else (match_operand:VOID 2 "m16_uimm8_1")
2103                                (const_int 4)
2104                                (const_int 8))
2105                  (const_int 4)])])
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"))))]
2111   "!TARGET_MIPS16"
2112   "nor\t%0,%1,%2"
2113   [(set_attr "type" "arith")
2114    (set_attr "mode" "<MODE>")])
2117 ;;  ....................
2119 ;;      TRUNCATION
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"
2129   "cvt.s.d\t%0,%1"
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:
2140 ;;                        A       B
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")))]
2149   "TARGET_64BIT"
2150   "@
2151     sll\t%0,%1,0
2152     sw\t%1,%0"
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")))]
2160   "TARGET_64BIT"
2161   "@
2162     sll\t%0,%1,0
2163     sh\t%1,%0"
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")))]
2171   "TARGET_64BIT"
2172   "@
2173     sll\t%0,%1,0
2174     sb\t%1,%0"
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.
2181 (define_insn ""
2182   [(set (match_operand:SI 0 "register_operand" "=d")
2183         (truncate:SI
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"
2187   "dsra\t%0,%1,%2"
2188   [(set_attr "type" "shift")
2189    (set_attr "mode" "SI")])
2191 (define_insn ""
2192   [(set (match_operand:SI 0 "register_operand" "=d")
2193         (truncate:SI (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
2194                                   (const_int 32))))]
2195   "TARGET_64BIT && !TARGET_MIPS16"
2196   "dsra\t%0,%1,32"
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")
2206         (sign_extend:SI
2207             (truncate:HI (match_operand:DI 1 "register_operand" "d"))))]
2208   "TARGET_64BIT && !TARGET_MIPS16"
2209   "#"
2210   "&& reload_completed"
2211   [(set (match_dup 2)
2212         (ashift:DI (match_dup 1)
2213                    (const_int 48)))
2214    (set (match_dup 0)
2215         (truncate:SI (ashiftrt:DI (match_dup 2)
2216                                   (const_int 48))))]
2217   { operands[2] = gen_lowpart (DImode, operands[0]); })
2219 (define_insn_and_split ""
2220   [(set (match_operand:SI 0 "register_operand" "=d")
2221         (sign_extend:SI
2222             (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
2223   "TARGET_64BIT && !TARGET_MIPS16"
2224   "#"
2225   "&& reload_completed"
2226   [(set (match_dup 2)
2227         (ashift:DI (match_dup 1)
2228                    (const_int 56)))
2229    (set (match_dup 0)
2230         (truncate:SI (ashiftrt:DI (match_dup 2)
2231                                   (const_int 56))))]
2232   { operands[2] = gen_lowpart (DImode, operands[0]); })
2235 ;; Combiner patterns to optimize truncate/zero_extend combinations.
2237 (define_insn ""
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")])
2246 (define_insn ""
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"
2251   "andi\t%0,%1,0xff"
2252   [(set_attr "type"     "arith")
2253    (set_attr "mode"     "SI")])
2255 (define_insn ""
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"
2260   "andi\t%0,%1,0xff"
2261   [(set_attr "type"     "arith")
2262    (set_attr "mode"     "HI")])
2265 ;;  ....................
2267 ;;      ZERO EXTENSION
2269 ;;  ....................
2271 ;; Extension insns.
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")))]
2276   "TARGET_64BIT"
2277   "@
2278    #
2279    lwu\t%0,%1"
2280   "&& reload_completed && REG_P (operands[1])"
2281   [(set (match_dup 0)
2282         (ashift:DI (match_dup 1) (const_int 32)))
2283    (set (match_dup 0)
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")))]
2293   ""
2295   if (TARGET_MIPS16 && !memory_operand (operands[1], <SHORT:MODE>mode))
2296     {
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>))));
2301       DONE;
2302     }
2305 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
2306   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2307         (zero_extend:GPR
2308              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2309   "!TARGET_MIPS16"
2310   "@
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")))]
2319   "TARGET_MIPS16"
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")))]
2327   ""
2329   if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
2330     {
2331       emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
2332                                        operands[1]));
2333       DONE;
2334     }
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")))]
2340   "!TARGET_MIPS16"
2341   "@
2342    andi\t%0,%1,0x00ff
2343    lbu\t%0,%1"
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")))]
2350   "TARGET_MIPS16"
2351   "lbu\t%0,%1"
2352   [(set_attr "type" "load")
2353    (set_attr "mode" "HI")])
2356 ;;  ....................
2358 ;;      SIGN EXTENSION
2360 ;;  ....................
2362 ;; Extension insns.
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")))]
2376   "TARGET_64BIT"
2377   "@
2378    #
2379    lw\t%0,%1"
2380   "&& reload_completed && register_operand (operands[1], VOIDmode)"
2381   [(const_int 0)]
2383   emit_note (NOTE_INSN_DELETED);
2384   DONE;
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")))]
2392   "")
2394 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
2395   [(set (match_operand:GPR 0 "register_operand" "=d,d")
2396         (sign_extend:GPR
2397              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2398   "!ISA_HAS_SEB_SEH"
2399   "@
2400    #
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")
2416         (sign_extend:GPR
2417              (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
2418   "ISA_HAS_SEB_SEH"
2419   "@
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")))]
2430   ""
2431   "#"
2432   "reload_completed"
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"
2443   "cvt.d.s\t%0,%1"
2444   [(set_attr "type"     "fcvt")
2445    (set_attr "mode"     "DF")])
2448 ;;  ....................
2450 ;;      CONVERSIONS
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)
2460     {
2461       emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
2462       DONE;
2463     }
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"
2470   "trunc.w.d %0,%1"
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"
2481   if (set_nomacro)
2482     return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
2483   else
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")))]
2493   "TARGET_HARD_FLOAT"
2495   if (!ISA_HAS_TRUNC_W)
2496     {
2497       emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
2498       DONE;
2499     }
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"
2506   "trunc.w.s %0,%1"
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"
2517   if (set_nomacro)
2518     return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
2519   else
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"
2531   "trunc.l.d %0,%1"
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"
2541   "trunc.l.s %0,%1"
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"
2551   "cvt.d.w\t%0,%1"
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"
2561   "cvt.d.l\t%0,%1"
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")))]
2570   "TARGET_HARD_FLOAT"
2571   "cvt.s.w\t%0,%1"
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"
2581   "cvt.s.l\t%0,%1"
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.  */
2602     {
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)));
2612       emit_barrier ();
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));
2627       DONE;
2628     }
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)));
2655   emit_barrier ();
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));
2670   DONE;
2674 (define_expand "fixuns_truncsfsi2"
2675   [(set (match_operand:SI 0 "register_operand")
2676         (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
2677   "TARGET_HARD_FLOAT"
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)));
2697   emit_barrier ();
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));
2712   DONE;
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)));
2739   emit_barrier ();
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));
2754   DONE;
2758 ;;  ....................
2760 ;;      DATA MOVEMENT
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")))]
2771   "!TARGET_MIPS16"
2773   if (mips_expand_unaligned_load (operands[0], operands[1],
2774                                   INTVAL (operands[2]),
2775                                   INTVAL (operands[3])))
2776     DONE;
2777   else
2778     FAIL;
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")))]
2786   "!TARGET_MIPS16"
2788   if (mips_expand_unaligned_load (operands[0], operands[1],
2789                                   INTVAL (operands[2]),
2790                                   INTVAL (operands[3])))
2791     DONE;
2792   else
2793     FAIL;
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"))]
2801   "!TARGET_MIPS16"
2803   if (mips_expand_unaligned_store (operands[0], operands[3],
2804                                    INTVAL (operands[1]),
2805                                    INTVAL (operands[2])))
2806     DONE;
2807   else
2808     FAIL;
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")]
2827                     UNSPEC_LOAD_LEFT))]
2828   "!TARGET_MIPS16"
2829   "<load>l\t%0,%2"
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))]
2840   "!TARGET_MIPS16"
2841   "<load>r\t%0,%2"
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))]
2850   "!TARGET_MIPS16"
2851   "<store>l\t%z1,%2"
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")
2859                      (match_dup 0)]
2860                     UNSPEC_STORE_RIGHT))]
2861   "!TARGET_MIPS16"
2862   "<store>r\t%z1,%2"
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)
2875 ;;      dsll    op0,op0,16
2876 ;;      daddiu  op0,op0,%hi(op1)
2877 ;;      dsll    op0,op0,16
2879 ;; The split is deferred until after flow2 to allow the peephole2 below
2880 ;; to take effect.
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"
2885   "#"
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)
2902 ;;      lui     op0,%hi(op2)
2903 ;;      daddiu  op1,op1,%higher(op2)
2904 ;;      dsll32  op1,op1,0
2905 ;;      daddu   op1,op1,op0
2906 (define_peephole2
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)
2927 ;;      lui     op2,%hi(op1)
2928 ;;      daddiu  op0,op0,%higher(op1)
2929 ;;      daddiu  op2,op2,%lo(op1)
2930 ;;      dsll32  op0,op0,0
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"
2939   "#"
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"
2959   "#"
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"
2975   "#"
2976   "&& reload_completed"
2977   [(set (match_dup 0)
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"
2989   "#"
2990   "&& reload_completed"
2991   [(set (match_dup 0)
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"
3006   "#"
3007   "&& reload_completed"
3008   [(set (match_dup 0)
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
3019 ;; opportunities.
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" "")]
3025                   UNSPEC_LOAD_GOT))]
3026   "TARGET_ABICALLS"
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" "")))]
3040   "!TARGET_MIPS16"
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" "")))]
3049   "TARGET_MIPS16"
3050   "<d>addiu\t%0,%R2"
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 ""))]
3064   ""
3066   if (mips_legitimize_move (DImode, operands[0], operands[1]))
3067     DONE;
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")
3076         (reg:GPR 31))]
3077   "TARGET_MIPS16"
3078   "<store>\t$31,%0"
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"
3125                 [(const_int 4)
3126                  (const_int 4)
3127                  (const_int 4)
3128                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3129                                (const_int 4)
3130                                (const_int 8))
3131                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3132                                (const_int 8)
3133                                (const_int 12))
3134                  (const_string "*")
3135                  (const_string "*")
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.
3143 (define_split
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]);
3164   if (val < 0)
3165     operands[2] = const0_rtx;
3166   else if (val >= 32 * 8)
3167     {
3168       int off = val & 7;
3170       operands[1] = GEN_INT (0x8 + off);
3171       operands[2] = GEN_INT (val - off - 0x8);
3172     }
3173   else
3174     {
3175       int off = val & 7;
3177       operands[1] = GEN_INT (off);
3178       operands[2] = GEN_INT (val - off);
3179     }
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 ""))]
3191   ""
3193   if (mips_legitimize_move (SImode, operands[0], operands[1]))
3194     DONE;
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"))]
3203   "!TARGET_MIPS16
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"))]
3214   "TARGET_MIPS16
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"
3221                 [(const_int 4)
3222                  (const_int 4)
3223                  (const_int 4)
3224                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3225                                (const_int 4)
3226                                (const_int 8))
3227                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3228                                (const_int 8)
3229                                (const_int 12))
3230                  (const_string "*")
3231                  (const_string "*")
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.
3238 (define_split
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]);
3258   if (val < 0)
3259     operands[2] = const0_rtx;
3260   else if (val >= 32 * 4)
3261     {
3262       int off = val & 3;
3264       operands[1] = GEN_INT (0x7c + off);
3265       operands[2] = GEN_INT (val - off - 0x7c);
3266     }
3267   else
3268     {
3269       int off = val & 3;
3271       operands[1] = GEN_INT (off);
3272       operands[2] = GEN_INT (val - off);
3273     }
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
3278 ;; instructions.
3280 (define_split
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]);
3333   DONE;
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]);
3343   DONE;
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"))))]
3363   "ISA_HAS_FP4"
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"))]
3372   "ISA_HAS_FP4"
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 ""))]
3387   ""
3389   if (mips_legitimize_move (HImode, operands[0], operands[1]))
3390     DONE;
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"))]
3396   "!TARGET_MIPS16
3397    && (register_operand (operands[0], HImode)
3398        || reg_or_0_operand (operands[1], HImode))"
3399   "@
3400     move\t%0,%1
3401     li\t%0,%1
3402     lhu\t%0,%1
3403     sh\t%z1,%0
3404     mfc1\t%0,%1
3405     mtc1\t%1,%0
3406     mov.s\t%0,%1
3407     mt%0\t%1"
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"))]
3415   "TARGET_MIPS16
3416    && (register_operand (operands[0], HImode)
3417        || register_operand (operands[1], HImode))"
3418   "@
3419     move\t%0,%1
3420     move\t%0,%1
3421     move\t%0,%1
3422     li\t%0,%1
3423     #
3424     lhu\t%0,%1
3425     sh\t%1,%0"
3426   [(set_attr "type"     "arith,arith,arith,arith,arith,load,store")
3427    (set_attr "mode"     "HI")
3428    (set_attr_alternative "length"
3429                 [(const_int 4)
3430                  (const_int 4)
3431                  (const_int 4)
3432                  (if_then_else (match_operand:VOID 1 "m16_uimm8_1")
3433                                (const_int 4)
3434                                (const_int 8))
3435                  (if_then_else (match_operand:VOID 1 "m16_nuimm8_1")
3436                                (const_int 8)
3437                                (const_int 12))
3438                  (const_string "*")
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.
3446 (define_split
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]);
3466   if (val < 0)
3467     operands[2] = const0_rtx;
3468   else if (val >= 32 * 2)
3469     {
3470       int off = val & 1;
3472       operands[1] = GEN_INT (0x7e + off);
3473       operands[2] = GEN_INT (val - off - 0x7e);
3474     }
3475   else
3476     {
3477       int off = val & 1;
3479       operands[1] = GEN_INT (off);
3480       operands[2] = GEN_INT (val - off);
3481     }
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 ""))]
3494   ""
3496   if (mips_legitimize_move (QImode, operands[0], operands[1]))
3497     DONE;
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"))]
3503   "!TARGET_MIPS16
3504    && (register_operand (operands[0], QImode)
3505        || reg_or_0_operand (operands[1], QImode))"
3506   "@
3507     move\t%0,%1
3508     li\t%0,%1
3509     lbu\t%0,%1
3510     sb\t%z1,%0
3511     mfc1\t%0,%1
3512     mtc1\t%1,%0
3513     mov.s\t%0,%1
3514     mt%0\t%1"
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"))]
3522   "TARGET_MIPS16
3523    && (register_operand (operands[0], QImode)
3524        || register_operand (operands[1], QImode))"
3525   "@
3526     move\t%0,%1
3527     move\t%0,%1
3528     move\t%0,%1
3529     li\t%0,%1
3530     #
3531     lbu\t%0,%1
3532     sb\t%1,%0"
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.
3541 (define_split
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]);
3558   if (val < 0)
3559     operands[2] = const0_rtx;
3560   else
3561     {
3562       operands[1] = GEN_INT (0x7f);
3563       operands[2] = GEN_INT (val - 0x7f);
3564     }
3567 ;; 32-bit floating point moves
3569 (define_expand "movsf"
3570   [(set (match_operand:SF 0 "")
3571         (match_operand:SF 1 ""))]
3572   ""
3574   if (mips_legitimize_move (SFmode, operands[0], operands[1]))
3575     DONE;
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"))]
3581   "TARGET_HARD_FLOAT
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"))]
3603   "TARGET_MIPS16
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 ""))]
3617   ""
3619   if (mips_legitimize_move (DFmode, operands[0], operands[1]))
3620     DONE;
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"))]
3659   "TARGET_MIPS16
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,*,*")])
3667 (define_split
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])"
3672   [(const_int 0)]
3674   mips_split_64bit_move (operands[0], operands[1]);
3675   DONE;
3678 (define_split
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])"
3683   [(const_int 0)]
3685   mips_split_64bit_move (operands[0], operands[1]);
3686   DONE;
3689 ;; When generating mips16 code, split moves of negative constants into
3690 ;; a positive "li" followed by a negation.
3691 (define_split
3692   [(set (match_operand 0 "register_operand")
3693         (match_operand 1 "const_int_operand"))]
3694   "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
3695   [(set (match_dup 2)
3696         (match_dup 3))
3697    (set (match_dup 2)
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]))
3712     DONE;
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
3719    && TARGET_64BIT
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")]
3738                     UNSPEC_MFHILO))]
3739   ""
3740   "mf%1\t%0"
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
3762 ;; in the low word.
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"
3797   "#"
3798   ""
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)]
3816   ""
3817   ""
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")]
3827                     UNSPEC_CPRESTORE)]
3828   ""
3830   if (set_nomacro && which_alternative == 1)
3831     return ".set\tmacro\;.cprestore\t%0\;.set\tnomacro";
3832   else
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]))
3852     DONE;
3853   else
3854     FAIL;
3858 ;;  ....................
3860 ;;      SHIFTS
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")))]
3868   ""
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
3876      reload pass.  */
3877   if (TARGET_MIPS16
3878       && optimize
3879       && GET_CODE (operands[2]) == CONST_INT
3880       && INTVAL (operands[2]) > 8
3881       && INTVAL (operands[2]) <= 16
3882       && !reload_in_progress
3883       && !reload_completed)
3884     {
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)));
3890       DONE;
3891     }
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")))]
3898   "!TARGET_MIPS16"
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")
3911         (sign_extend:DI
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")))]
3928   "TARGET_MIPS16"
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"
3939                 [(const_int 4)
3940                  (if_then_else (match_operand 2 "m16_uimm3_b")
3941                                (const_int 4)
3942                                (const_int 8))])])
3944 ;; We need separate DImode MIPS16 patterns because of the irregularity
3945 ;; of right shifts.
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"
3961                 [(const_int 4)
3962                  (if_then_else (match_operand 2 "m16_uimm3_b")
3963                                (const_int 4)
3964                                (const_int 8))])])
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"
3980                 [(const_int 4)
3981                  (if_then_else (match_operand 2 "m16_uimm3_b")
3982                                (const_int 4)
3983                                (const_int 8))])])
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"
3999                 [(const_int 4)
4000                  (if_then_else (match_operand 2 "m16_uimm3_b")
4001                                (const_int 4)
4002                                (const_int 8))])])
4004 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
4006 (define_split
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")))]
4031   "TARGET_MIPS16"
4032   "#"
4033   ""
4034   [(set (match_dup 0) (match_dup 1))
4035    (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
4036   ""
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 ;;  ....................
4059 ;;      COMPARISONS
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>"
4079   [(set (cc0)
4080         (compare:CC (match_operand:GPR 0 "register_operand")
4081                     (match_operand:GPR 1 "nonmemory_operand")))]
4082   ""
4084   cmp_operands[0] = operands[0];
4085   cmp_operands[1] = operands[1];
4086   DONE;
4089 (define_expand "cmp<mode>"
4090   [(set (cc0)
4091         (compare:CC (match_operand:SCALARF 0 "register_operand")
4092                     (match_operand:SCALARF 1 "register_operand")))]
4093   ""
4095   cmp_operands[0] = operands[0];
4096   cmp_operands[1] = operands[1];
4097   DONE;
4101 ;;  ....................
4103 ;;      CONDITIONAL BRANCHES
4105 ;;  ....................
4107 ;; Conditional branches on floating-point equality tests.
4109 (define_insn "branch_fp"
4110   [(set (pc)
4111         (if_then_else
4112          (match_operator:CC 0 "comparison_operator"
4113                             [(match_operand:CC 2 "register_operand" "z")
4114                              (const_int 0)])
4115          (label_ref (match_operand 1 "" ""))
4116          (pc)))]
4117   "TARGET_HARD_FLOAT"
4119   return mips_output_conditional_branch (insn,
4120                                          operands,
4121                                          /*two_operands_p=*/0,
4122                                          /*float_p=*/1,
4123                                          /*inverted_p=*/0,
4124                                          get_attr_length (insn));
4126   [(set_attr "type"     "branch")
4127    (set_attr "mode"     "none")])
4129 (define_insn "branch_fp_inverted"
4130   [(set (pc)
4131         (if_then_else
4132          (match_operator:CC 0 "comparison_operator"
4133                             [(match_operand:CC 2 "register_operand" "z")
4134                              (const_int 0)])
4135          (pc)
4136          (label_ref (match_operand 1 "" ""))))]
4137   "TARGET_HARD_FLOAT"
4139   return mips_output_conditional_branch (insn,
4140                                          operands,
4141                                          /*two_operands_p=*/0,
4142                                          /*float_p=*/1,
4143                                          /*inverted_p=*/1,
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>"
4152   [(set (pc)
4153         (if_then_else
4154          (match_operator:GPR 0 "comparison_operator"
4155                              [(match_operand:GPR 2 "register_operand" "d")
4156                               (const_int 0)])
4157          (label_ref (match_operand 1 "" ""))
4158          (pc)))]
4159   "!TARGET_MIPS16"
4161   return mips_output_conditional_branch (insn,
4162                                          operands,
4163                                          /*two_operands_p=*/0,
4164                                          /*float_p=*/0,
4165                                          /*inverted_p=*/0,
4166                                          get_attr_length (insn));
4168   [(set_attr "type" "branch")
4169    (set_attr "mode" "none")])
4171 (define_insn "*branch_zero<mode>_inverted"
4172   [(set (pc)
4173         (if_then_else
4174          (match_operator:GPR 0 "comparison_operator"
4175                              [(match_operand:GPR 2 "register_operand" "d")
4176                               (const_int 0)])
4177          (pc)
4178          (label_ref (match_operand 1 "" ""))))]
4179   "!TARGET_MIPS16"
4181   return mips_output_conditional_branch (insn,
4182                                          operands,
4183                                          /*two_operands_p=*/0,
4184                                          /*float_p=*/0,
4185                                          /*inverted_p=*/1,
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>"
4194   [(set (pc)
4195         (if_then_else
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 "" ""))
4200          (pc)))]
4201   "!TARGET_MIPS16"
4203   return mips_output_conditional_branch (insn,
4204                                          operands,
4205                                          /*two_operands_p=*/1,
4206                                          /*float_p=*/0,
4207                                          /*inverted_p=*/0,
4208                                          get_attr_length (insn));
4210   [(set_attr "type" "branch")
4211    (set_attr "mode" "none")])
4213 (define_insn "*branch_equality<mode>_inverted"
4214   [(set (pc)
4215         (if_then_else
4216          (match_operator:GPR 0 "equality_operator"
4217                              [(match_operand:GPR 2 "register_operand" "d")
4218                               (match_operand:GPR 3 "register_operand" "d")])
4219          (pc)
4220          (label_ref (match_operand 1 "" ""))))]
4221   "!TARGET_MIPS16"
4223   return mips_output_conditional_branch (insn,
4224                                          operands,
4225                                          /*two_operands_p=*/1,
4226                                          /*float_p=*/0,
4227                                          /*inverted_p=*/1,
4228                                          get_attr_length (insn));
4230   [(set_attr "type" "branch")
4231    (set_attr "mode" "none")])
4233 ;; MIPS16 branches
4235 (define_insn "*branch_equality<mode>_mips16"
4236   [(set (pc)
4237         (if_then_else
4238          (match_operator:GPR 0 "equality_operator"
4239                              [(match_operand:GPR 1 "register_operand" "d,t")
4240                               (const_int 0)])
4241          (match_operand 2 "pc_or_label_operand" "")
4242          (match_operand 3 "pc_or_label_operand" "")))]
4243   "TARGET_MIPS16"
4245   if (operands[2] != pc_rtx)
4246     {
4247       if (which_alternative == 0)
4248         return "b%C0z\t%1,%2";
4249       else
4250         return "bt%C0z\t%2";
4251     }
4252   else
4253     {
4254       if (which_alternative == 0)
4255         return "b%N0z\t%1,%3";
4256       else
4257         return "bt%N0z\t%3";
4258     }
4260   [(set_attr "type" "branch")
4261    (set_attr "mode" "none")
4262    (set_attr "length" "8")])
4264 (define_expand "b<code>"
4265   [(set (pc)
4266         (if_then_else (any_cond:CC (cc0)
4267                                    (const_int 0))
4268                       (label_ref (match_operand 0 ""))
4269                       (pc)))]
4270   ""
4272   gen_conditional_branch (operands, <CODE>);
4273   DONE;
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)
4286                (match_dup 2)))]
4287   ""
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")
4293                 (const_int 0)))]
4294   "!TARGET_MIPS16"
4295   "sltu\t%0,%1,1"
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")
4302                 (const_int 0)))]
4303   "TARGET_MIPS16"
4304   "sltu\t%1,1"
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)
4314                (match_dup 2)))]
4315   "!TARGET_MIPS16"
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")
4321                 (const_int 0)))]
4322   "!TARGET_MIPS16"
4323   "sltu\t%0,%.,%1"
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)
4330                (match_dup 2)))]
4331   ""
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")))]
4338   "!TARGET_MIPS16"
4339   "slt\t%0,%z2,%1"
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")))]
4347   "TARGET_MIPS16"
4348   "slt\t%2,%1"
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)
4355                (match_dup 2)))]
4356   ""
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")
4362                 (const_int 1)))]
4363   "!TARGET_MIPS16"
4364   "slt\t%0,%.,%1"
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)
4371                (match_dup 2)))]
4372   ""
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")))]
4379   "!TARGET_MIPS16"
4380   "slt\t%0,%1,%2"
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")))]
4388   "TARGET_MIPS16"
4389   "slt\t%1,%2"
4390   [(set_attr "type" "slt")
4391    (set_attr "mode" "<MODE>")
4392    (set_attr_alternative "length"
4393                 [(const_int 4)
4394                  (if_then_else (match_operand 2 "m16_uimm8_1")
4395                                (const_int 4)
4396                                (const_int 8))])])
4398 (define_expand "sle"
4399   [(set (match_operand:SI 0 "register_operand")
4400         (le:SI (match_dup 1)
4401                (match_dup 2)))]
4402   ""
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" "")))]
4409   "!TARGET_MIPS16"
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" "")))]
4421   "TARGET_MIPS16"
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")
4429                                       (const_int 4)
4430                                       (const_int 8)))])
4432 (define_expand "sgtu"
4433   [(set (match_operand:SI 0 "register_operand")
4434         (gtu:SI (match_dup 1)
4435                 (match_dup 2)))]
4436   ""
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")))]
4443   "!TARGET_MIPS16"
4444   "sltu\t%0,%z2,%1"
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")))]
4452   "TARGET_MIPS16"
4453   "sltu\t%2,%1"
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)
4460                 (match_dup 2)))]
4461   ""
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")
4467                  (const_int 1)))]
4468   "!TARGET_MIPS16"
4469   "sltu\t%0,%.,%1"
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)
4476                 (match_dup 2)))]
4477   ""
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")))]
4484   "!TARGET_MIPS16"
4485   "sltu\t%0,%1,%2"
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")))]
4493   "TARGET_MIPS16"
4494   "sltu\t%1,%2"
4495   [(set_attr "type" "slt")
4496    (set_attr "mode" "<MODE>")
4497    (set_attr_alternative "length"
4498                 [(const_int 4)
4499                  (if_then_else (match_operand 2 "m16_uimm8_1")
4500                                (const_int 4)
4501                                (const_int 8))])])
4503 (define_expand "sleu"
4504   [(set (match_operand:SI 0 "register_operand")
4505         (leu:SI (match_dup 1)
4506                 (match_dup 2)))]
4507   ""
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" "")))]
4514   "!TARGET_MIPS16"
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" "")))]
4526   "TARGET_MIPS16"
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")
4534                                       (const_int 4)
4535                                       (const_int 8)))])
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")))]
4548   ""
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")))]
4557   ""
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")))]
4566   ""
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.
4580 (define_insn "jump"
4581   [(set (pc)
4582         (label_ref (match_operand 0 "" "")))]
4583   "!TARGET_MIPS16"
4585   if (flag_pic)
4586     {
4587       if (get_attr_length (insn) <= 8)
4588         return "%*b\t%l0%/";
4589       else
4590         {
4591           output_asm_insn (mips_output_load_label (), operands);
4592           return "%*jr\t%@%/%]";
4593         }
4594     }
4595   else
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.
4604         (if_then_else
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.
4614 (define_insn ""
4615   [(set (pc)
4616         (label_ref (match_operand 0 "" "")))]
4617   "TARGET_MIPS16"
4618   "b\t%l0"
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"))]
4625   ""
4627   operands[0] = force_reg (Pmode, operands[0]);
4628   if (Pmode == SImode)
4629     emit_jump_insn (gen_indirect_jumpsi (operands[0]));
4630   else
4631     emit_jump_insn (gen_indirect_jumpdi (operands[0]));
4632   DONE;
4635 (define_insn "indirect_jump<mode>"
4636   [(set (pc) (match_operand:P 0 "register_operand" "d"))]
4637   ""
4638   "%*j\t%0%/"
4639   [(set_attr "type" "jump")
4640    (set_attr "mode" "none")])
4642 (define_expand "tablejump"
4643   [(set (pc)
4644         (match_operand 0 "register_operand"))
4645    (use (label_ref (match_operand 1 "")))]
4646   ""
4648   if (TARGET_MIPS16)
4649     operands[0] = expand_binop (Pmode, add_optab,
4650                                 convert_to_mode (Pmode, operands[0], false),
4651                                 gen_rtx_LABEL_REF (Pmode, operands[1]),
4652                                 0, 0, OPTAB_WIDEN);
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]));
4659   else
4660     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
4661   DONE;
4664 (define_insn "tablejump<mode>"
4665   [(set (pc)
4666         (match_operand:P 0 "register_operand" "d"))
4667    (use (label_ref (match_operand 1 "" "")))]
4668   ""
4669   "%*j\t%0%/"
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"))]
4680   "TARGET_ABICALLS"
4682   rtx addr;
4684   addr = plus_constant (operands[0], GET_MODE_SIZE (Pmode) * 3);
4685   emit_move_insn (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
4686   DONE;
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"))]
4695   "TARGET_ABICALLS"
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);
4719   DONE;
4723 ;;  ....................
4725 ;;      Function prologue/epilogue
4727 ;;  ....................
4730 (define_expand "prologue"
4731   [(const_int 1)]
4732   ""
4734   mips_expand_prologue ();
4735   DONE;
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)]
4744   ""
4745   ""
4746   [(set_attr "type"     "unknown")
4747    (set_attr "mode"     "none")
4748    (set_attr "length"   "0")])
4750 (define_expand "epilogue"
4751   [(const_int 2)]
4752   ""
4754   mips_expand_epilogue (false);
4755   DONE;
4758 (define_expand "sibcall_epilogue"
4759   [(const_int 2)]
4760   ""
4762   mips_expand_epilogue (true);
4763   DONE;
4766 ;; Trivial return.  Make it look like a normal return insn as that
4767 ;; allows jump optimizations to work better.
4769 (define_insn "return"
4770   [(return)]
4771   "mips_can_use_return_insn ()"
4772   "%*j\t$31%/"
4773   [(set_attr "type"     "jump")
4774    (set_attr "mode"     "none")])
4776 ;; Normal return.
4778 (define_insn "return_internal"
4779   [(return)
4780    (use (match_operand 0 "pmode_register_operand" ""))]
4781   ""
4782   "%*j\t%0%/"
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"))]
4789   ""
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);
4795   if (TARGET_64BIT)
4796     emit_insn (gen_eh_set_lr_di (operands[0]));
4797   else
4798     emit_insn (gen_eh_set_lr_si (operands[0]));
4800   DONE;
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"))]
4809   "! TARGET_64BIT"
4810   "#")
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"))]
4815   "TARGET_64BIT"
4816   "#")
4818 (define_split
4819   [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
4820    (clobber (match_scratch 1))]
4821   "reload_completed && !TARGET_DEBUG_D_MODE"
4822   [(const_int 0)]
4824   mips_set_return_address (operands[0], operands[1]);
4825   DONE;
4828 (define_insn_and_split "exception_receiver"
4829   [(set (reg:SI 28)
4830         (unspec_volatile:SI [(const_int 0)] UNSPEC_EH_RECEIVER))]
4831   "TARGET_ABICALLS && TARGET_OLDABI"
4832   "#"
4833   "&& reload_completed"
4834   [(const_int 0)]
4836   mips_restore_gp ();
4837   DONE;
4839   [(set_attr "type"   "load")
4840    (set_attr "length" "12")])
4843 ;;  ....................
4845 ;;      FUNCTION CALLS
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
4853 ;; address.
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)]
4868                   UNSPEC_LOAD_CALL))]
4869   "TARGET_ABICALLS"
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
4880 ;; constraints.
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
4892   "TARGET_SIBCALLS"
4894   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], true);
4895   DONE;
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)"
4902   "@
4903     %*jr\t%0%/
4904     %*j\t%0%/"
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
4912   "TARGET_SIBCALLS"
4914   mips_expand_call (operands[0], XEXP (operands[1], 0),
4915                     operands[2], operands[3], true);
4916   DONE;
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)"
4924   "@
4925     %*jr\t%1%/
4926     %*j\t%1%/"
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))
4935               (match_dup 2)))]
4936   "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
4937   "@
4938     %*jr\t%1%/
4939     %*j\t%1%/"
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
4947   ""
4949   mips_expand_call (0, XEXP (operands[0], 0), operands[1], operands[2], false);
4950   DONE;
4953 ;; This instruction directly corresponds to an assembly-language "jal".
4954 ;; There are four cases:
4956 ;;    - -mno-abicalls:
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"
4966 ;;        instruction.
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))]
4994   ""
4995   { return TARGET_SPLIT_CALLS ? "#" : "%*jal\t%0%/"; }
4996   "reload_completed && TARGET_SPLIT_CALLS && (operands[2] = insn)"
4997   [(const_int 0)]
4999   emit_call_insn (gen_call_split (operands[0], operands[1]));
5000   if (!find_reg_note (operands[2], REG_NORETURN, 0))
5001     mips_restore_gp ();
5002   DONE;
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"
5013   "%*jalr\t%0%/"
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
5021   ""
5023   mips_expand_call (operands[0], XEXP (operands[1], 0),
5024                     operands[2], operands[3], false);
5025   DONE;
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))]
5034   ""
5035   { return TARGET_SPLIT_CALLS ? "#" : "%*jal\t%1%/"; }
5036   "reload_completed && TARGET_SPLIT_CALLS && (operands[3] = insn)"
5037   [(const_int 0)]
5039   emit_call_insn (gen_call_value_split (operands[0], operands[1],
5040                                         operands[2]));
5041   if (!find_reg_note (operands[3], REG_NORETURN, 0))
5042     mips_restore_gp ();
5043   DONE;
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"
5055   "%*jalr\t%1%/"
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))
5065               (match_dup 2)))
5066    (clobber (reg:SI 31))]
5067   ""
5068   { return TARGET_SPLIT_CALLS ? "#" : "%*jal\t%1%/"; }
5069   "reload_completed && TARGET_SPLIT_CALLS && (operands[4] = insn)"
5070   [(const_int 0)]
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))
5075     mips_restore_gp ();
5076   DONE;
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))
5087               (match_dup 2)))
5088    (clobber (reg:SI 31))
5089    (clobber (reg:SI 28))]
5090   "TARGET_SPLIT_CALLS"
5091   "%*jalr\t%1%/"
5092   [(set_attr "type" "call")])
5094 ;; Call subroutine returning any type.
5096 (define_expand "untyped_call"
5097   [(parallel [(call (match_operand 0 "")
5098                     (const_int 0))
5099               (match_operand 1 "")
5100               (match_operand 2 "")])]
5101   ""
5103   int i;
5105   emit_call_insn (GEN_CALL (operands[0], const0_rtx, NULL, const0_rtx));
5107   for (i = 0; i < XVECLEN (operands[2], 0); i++)
5108     {
5109       rtx set = XVECEXP (operands[2], 0, i);
5110       emit_move_insn (SET_DEST (set), SET_SRC (set));
5111     }
5113   emit_insn (gen_blockage ());
5114   DONE;
5118 ;;  ....................
5120 ;;      MISC.
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")])
5149 (define_insn "nop"
5150   [(const_int 0)]
5151   ""
5152   "%(nop%)"
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"
5158   [(const_int 1)]
5159   ""
5160   {
5161     if (set_noreorder)
5162       return "nop";
5163     else
5164       return "#nop";
5165   }
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")
5172         (if_then_else:GPR
5173          (match_operator:MOVECC 4 "equality_operator"
5174                 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
5175                  (const_int 0)])
5176          (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
5177          (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
5178   "ISA_HAS_CONDMOVE"
5179   "@
5180     mov%T4\t%0,%z2,%1
5181     mov%t4\t%0,%z3,%1"
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>")
5190                  (const_int 0)])
5191          (match_operand:SCALARF 2 "register_operand" "f,0")
5192          (match_operand:SCALARF 3 "register_operand" "0,f")))]
5193   "ISA_HAS_CONDMOVE"
5194   "@
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")))]
5208   "ISA_HAS_CONDMOVE"
5210   gen_conditional_move (operands);
5211   DONE;
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")))]
5220   "ISA_HAS_CONDMOVE"
5222   gen_conditional_move (operands);
5223   DONE;
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)]
5238   "TARGET_MIPS16"
5240   assemble_integer (operands[0], INTVAL (operands[1]),
5241                     BITS_PER_UNIT * INTVAL (operands[1]), 1);
5242   return "";
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)]
5249   "TARGET_MIPS16"
5251   REAL_VALUE_TYPE d;
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])));
5257   return "";
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)]
5264   ""
5265   ".align\t%0"
5266   [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
5268 (define_split
5269   [(match_operand 0 "small_data_pattern")]
5270   "reload_completed"
5271   [(match_dup 0)]
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")