]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/mips/mips.md
* regcprop.c (maybe_mode_change): Avoid creating copies of the
[thirdparty/gcc.git] / gcc / config / mips / mips.md
1 ;; Mips.md Machine Description for MIPS based processors
2 ;; Copyright (C) 1989-2017 Free Software Foundation, Inc.
3 ;; Contributed by A. Lichnewsky, lich@inria.inria.fr
4 ;; Changes by Michael Meissner, meissner@osf.org
5 ;; 64-bit r4000 support by Ian Lance Taylor, ian@cygnus.com, and
6 ;; Brendan Eich, brendan@microunity.com.
7
8 ;; This file is part of GCC.
9
10 ;; GCC is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
13 ;; any later version.
14
15 ;; GCC is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GCC; see the file COPYING3. If not see
22 ;; <http://www.gnu.org/licenses/>.
23
24 (define_enum "processor" [
25 r3000
26 4kc
27 4kp
28 5kc
29 5kf
30 20kc
31 24kc
32 24kf2_1
33 24kf1_1
34 74kc
35 74kf2_1
36 74kf1_1
37 74kf3_2
38 loongson_2e
39 loongson_2f
40 loongson_3a
41 m4k
42 octeon
43 octeon2
44 octeon3
45 r3900
46 r6000
47 r4000
48 r4100
49 r4111
50 r4120
51 r4130
52 r4300
53 r4600
54 r4650
55 r4700
56 r5000
57 r5400
58 r5500
59 r5900
60 r7000
61 r8000
62 r9000
63 r10000
64 sb1
65 sb1a
66 sr71000
67 xlr
68 xlp
69 p5600
70 m5100
71 i6400
72 ])
73
74 (define_c_enum "unspec" [
75 ;; Unaligned accesses.
76 UNSPEC_LOAD_LEFT
77 UNSPEC_LOAD_RIGHT
78 UNSPEC_STORE_LEFT
79 UNSPEC_STORE_RIGHT
80
81 ;; Integer operations that are too cumbersome to describe directly.
82 UNSPEC_WSBH
83 UNSPEC_DSBH
84 UNSPEC_DSHD
85
86 ;; Floating-point moves.
87 UNSPEC_LOAD_LOW
88 UNSPEC_LOAD_HIGH
89 UNSPEC_STORE_WORD
90 UNSPEC_MFHC1
91 UNSPEC_MTHC1
92
93 ;; Floating-point environment.
94 UNSPEC_GET_FCSR
95 UNSPEC_SET_FCSR
96
97 ;; HI/LO moves.
98 UNSPEC_MFHI
99 UNSPEC_MTHI
100 UNSPEC_SET_HILO
101
102 ;; GP manipulation.
103 UNSPEC_LOADGP
104 UNSPEC_COPYGP
105 UNSPEC_MOVE_GP
106 UNSPEC_POTENTIAL_CPRESTORE
107 UNSPEC_CPRESTORE
108 UNSPEC_RESTORE_GP
109 UNSPEC_EH_RETURN
110 UNSPEC_GP
111 UNSPEC_SET_GOT_VERSION
112 UNSPEC_UPDATE_GOT_VERSION
113
114 ;; Symbolic accesses.
115 UNSPEC_LOAD_CALL
116 UNSPEC_LOAD_GOT
117 UNSPEC_TLS_LDM
118 UNSPEC_TLS_GET_TP
119 UNSPEC_UNSHIFTED_HIGH
120
121 ;; MIPS16 constant pools.
122 UNSPEC_ALIGN
123 UNSPEC_CONSTTABLE
124 UNSPEC_CONSTTABLE_END
125 UNSPEC_CONSTTABLE_INT
126 UNSPEC_CONSTTABLE_FLOAT
127
128 ;; Blockage and synchronisation.
129 UNSPEC_BLOCKAGE
130 UNSPEC_CLEAR_HAZARD
131 UNSPEC_RDHWR
132 UNSPEC_SYNCI
133 UNSPEC_SYNC
134
135 ;; Cache manipulation.
136 UNSPEC_MIPS_CACHE
137 UNSPEC_R10K_CACHE_BARRIER
138
139 ;; Interrupt handling.
140 UNSPEC_ERET
141 UNSPEC_DERET
142 UNSPEC_DI
143 UNSPEC_EHB
144 UNSPEC_RDPGPR
145 UNSPEC_COP0
146
147 ;; Used in a call expression in place of args_size. It's present for PIC
148 ;; indirect calls where it contains args_size and the function symbol.
149 UNSPEC_CALL_ATTR
150
151 ;; MIPS16 casesi jump table dispatch.
152 UNSPEC_CASESI_DISPATCH
153
154 ;; Stack checking.
155 UNSPEC_PROBE_STACK_RANGE
156
157 ;; The `.insn' pseudo-op.
158 UNSPEC_INSN_PSEUDO
159 ])
160
161 (define_constants
162 [(TLS_GET_TP_REGNUM 3)
163 (GET_FCSR_REGNUM 2)
164 (SET_FCSR_REGNUM 4)
165 (MIPS16_T_REGNUM 24)
166 (PIC_FUNCTION_ADDR_REGNUM 25)
167 (RETURN_ADDR_REGNUM 31)
168 (CPRESTORE_SLOT_REGNUM 76)
169 (GOT_VERSION_REGNUM 79)
170
171 ;; PIC long branch sequences are never longer than 100 bytes.
172 (MAX_PIC_BRANCH_LENGTH 100)
173 ]
174 )
175
176 (include "predicates.md")
177 (include "constraints.md")
178 \f
179 ;; ....................
180 ;;
181 ;; Attributes
182 ;;
183 ;; ....................
184
185 (define_attr "got" "unset,xgot_high,load"
186 (const_string "unset"))
187
188 ;; For jal instructions, this attribute is DIRECT when the target address
189 ;; is symbolic and INDIRECT when it is a register.
190 (define_attr "jal" "unset,direct,indirect"
191 (const_string "unset"))
192
193 ;; This attribute is YES if the instruction is a jal macro (not a
194 ;; real jal instruction).
195 ;;
196 ;; jal is always a macro for TARGET_CALL_CLOBBERED_GP because it includes
197 ;; an instruction to restore $gp. Direct jals are also macros for
198 ;; !TARGET_ABSOLUTE_JUMPS because they first load the target address
199 ;; into a register.
200 (define_attr "jal_macro" "no,yes"
201 (cond [(eq_attr "jal" "direct")
202 (symbol_ref "(TARGET_CALL_CLOBBERED_GP || !TARGET_ABSOLUTE_JUMPS
203 ? JAL_MACRO_YES : JAL_MACRO_NO)")
204 (eq_attr "jal" "indirect")
205 (symbol_ref "(TARGET_CALL_CLOBBERED_GP
206 ? JAL_MACRO_YES : JAL_MACRO_NO)")]
207 (const_string "no")))
208
209 ;; Classification of moves, extensions and truncations. Most values
210 ;; are as for "type" (see below) but there are also the following
211 ;; move-specific values:
212 ;;
213 ;; constN move an N-constraint integer into a MIPS16 register
214 ;; sll0 "sll DEST,SRC,0", which on 64-bit targets is guaranteed
215 ;; to produce a sign-extended DEST, even if SRC is not
216 ;; properly sign-extended
217 ;; ext_ins EXT, DEXT, INS or DINS instruction
218 ;; andi a single ANDI instruction
219 ;; loadpool move a constant into a MIPS16 register by loading it
220 ;; from the pool
221 ;; shift_shift a shift left followed by a shift right
222 ;;
223 ;; This attribute is used to determine the instruction's length and
224 ;; scheduling type. For doubleword moves, the attribute always describes
225 ;; the split instructions; in some cases, it is more appropriate for the
226 ;; scheduling type to be "multi" instead.
227 (define_attr "move_type"
228 "unknown,load,fpload,store,fpstore,mtc,mfc,mtlo,mflo,imul,move,fmove,
229 const,constN,signext,ext_ins,logical,arith,sll0,andi,loadpool,
230 shift_shift"
231 (const_string "unknown"))
232
233 (define_attr "alu_type" "unknown,add,sub,not,nor,and,or,xor,simd_add"
234 (const_string "unknown"))
235
236 ;; Main data type used by the insn
237 (define_attr "mode" "unknown,none,QI,HI,SI,DI,TI,SF,DF,TF,FPSW,
238 V2DI,V4SI,V8HI,V16QI,V2DF,V4SF"
239 (const_string "unknown"))
240
241 ;; True if the main data type is twice the size of a word.
242 (define_attr "dword_mode" "no,yes"
243 (cond [(and (eq_attr "mode" "DI,DF")
244 (not (match_test "TARGET_64BIT")))
245 (const_string "yes")
246
247 (and (eq_attr "mode" "TI,TF")
248 (match_test "TARGET_64BIT"))
249 (const_string "yes")]
250 (const_string "no")))
251
252 ;; True if the main data type is four times of the size of a word.
253 (define_attr "qword_mode" "no,yes"
254 (cond [(and (eq_attr "mode" "TI,TF")
255 (not (match_test "TARGET_64BIT")))
256 (const_string "yes")]
257 (const_string "no")))
258
259 ;; Attributes describing a sync loop. These loops have the form:
260 ;;
261 ;; if (RELEASE_BARRIER == YES) sync
262 ;; 1: OLDVAL = *MEM
263 ;; if ((OLDVAL & INCLUSIVE_MASK) != REQUIRED_OLDVAL) goto 2
264 ;; CMP = 0 [delay slot]
265 ;; $TMP1 = OLDVAL & EXCLUSIVE_MASK
266 ;; $TMP2 = INSN1 (OLDVAL, INSN1_OP2)
267 ;; $TMP3 = INSN2 ($TMP2, INCLUSIVE_MASK)
268 ;; $AT |= $TMP1 | $TMP3
269 ;; if (!commit (*MEM = $AT)) goto 1.
270 ;; if (INSN1 != MOVE && INSN1 != LI) NEWVAL = $TMP3 [delay slot]
271 ;; CMP = 1
272 ;; if (ACQUIRE_BARRIER == YES) sync
273 ;; 2:
274 ;;
275 ;; where "$" values are temporaries and where the other values are
276 ;; specified by the attributes below. Values are specified as operand
277 ;; numbers and insns are specified as enums. If no operand number is
278 ;; specified, the following values are used instead:
279 ;;
280 ;; - OLDVAL: $AT
281 ;; - CMP: NONE
282 ;; - NEWVAL: $AT
283 ;; - INCLUSIVE_MASK: -1
284 ;; - REQUIRED_OLDVAL: OLDVAL & INCLUSIVE_MASK
285 ;; - EXCLUSIVE_MASK: 0
286 ;;
287 ;; MEM and INSN1_OP2 are required.
288 ;;
289 ;; Ideally, the operand attributes would be integers, with -1 meaning "none",
290 ;; but the gen* programs don't yet support that.
291 (define_attr "sync_mem" "none,0,1,2,3,4,5" (const_string "none"))
292 (define_attr "sync_oldval" "none,0,1,2,3,4,5" (const_string "none"))
293 (define_attr "sync_cmp" "none,0,1,2,3,4,5" (const_string "none"))
294 (define_attr "sync_newval" "none,0,1,2,3,4,5" (const_string "none"))
295 (define_attr "sync_inclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
296 (define_attr "sync_exclusive_mask" "none,0,1,2,3,4,5" (const_string "none"))
297 (define_attr "sync_required_oldval" "none,0,1,2,3,4,5" (const_string "none"))
298 (define_attr "sync_insn1_op2" "none,0,1,2,3,4,5" (const_string "none"))
299 (define_attr "sync_insn1" "move,li,addu,addiu,subu,and,andi,or,ori,xor,xori"
300 (const_string "move"))
301 (define_attr "sync_insn2" "nop,and,xor,not"
302 (const_string "nop"))
303 ;; Memory model specifier.
304 ;; "0"-"9" values specify the operand that stores the memory model value.
305 ;; "10" specifies MEMMODEL_ACQ_REL,
306 ;; "11" specifies MEMMODEL_ACQUIRE.
307 (define_attr "sync_memmodel" "" (const_int 10))
308
309 ;; Accumulator operand for madd patterns.
310 (define_attr "accum_in" "none,0,1,2,3,4,5" (const_string "none"))
311
312 ;; Classification of each insn.
313 ;; branch conditional branch
314 ;; jump unconditional jump
315 ;; call unconditional call
316 ;; load load instruction(s)
317 ;; fpload floating point load
318 ;; fpidxload floating point indexed load
319 ;; store store instruction(s)
320 ;; fpstore floating point store
321 ;; fpidxstore floating point indexed store
322 ;; prefetch memory prefetch (register + offset)
323 ;; prefetchx memory indexed prefetch (register + register)
324 ;; condmove conditional moves
325 ;; mtc transfer to coprocessor
326 ;; mfc transfer from coprocessor
327 ;; mthi transfer to a hi register
328 ;; mtlo transfer to a lo register
329 ;; mfhi transfer from a hi register
330 ;; mflo transfer from a lo register
331 ;; const load constant
332 ;; arith integer arithmetic instructions
333 ;; logical integer logical instructions
334 ;; shift integer shift instructions
335 ;; slt set less than instructions
336 ;; signext sign extend instructions
337 ;; clz the clz and clo instructions
338 ;; pop the pop instruction
339 ;; trap trap if instructions
340 ;; imul integer multiply 2 operands
341 ;; imul3 integer multiply 3 operands
342 ;; imul3nc integer multiply 3 operands without clobbering HI/LO
343 ;; imadd integer multiply-add
344 ;; idiv integer divide 2 operands
345 ;; idiv3 integer divide 3 operands
346 ;; move integer register move ({,D}ADD{,U} with rt = 0)
347 ;; fmove floating point register move
348 ;; fadd floating point add/subtract
349 ;; fmul floating point multiply
350 ;; fmadd floating point multiply-add
351 ;; fdiv floating point divide
352 ;; frdiv floating point reciprocal divide
353 ;; frdiv1 floating point reciprocal divide step 1
354 ;; frdiv2 floating point reciprocal divide step 2
355 ;; fabs floating point absolute value
356 ;; fneg floating point negation
357 ;; fcmp floating point compare
358 ;; fcvt floating point convert
359 ;; fsqrt floating point square root
360 ;; frsqrt floating point reciprocal square root
361 ;; frsqrt1 floating point reciprocal square root step1
362 ;; frsqrt2 floating point reciprocal square root step2
363 ;; dspmac DSP MAC instructions not saturating the accumulator
364 ;; dspmacsat DSP MAC instructions that saturate the accumulator
365 ;; accext DSP accumulator extract instructions
366 ;; accmod DSP accumulator modify instructions
367 ;; dspalu DSP ALU instructions not saturating the result
368 ;; dspalusat DSP ALU instructions that saturate the result
369 ;; multi multiword sequence (or user asm statements)
370 ;; atomic atomic memory update instruction
371 ;; syncloop memory atomic operation implemented as a sync loop
372 ;; nop no operation
373 ;; ghost an instruction that produces no real code
374 ;; multimem microMIPS multiword load and store
375 (define_attr "type"
376 "unknown,branch,jump,call,load,fpload,fpidxload,store,fpstore,fpidxstore,
377 prefetch,prefetchx,condmove,mtc,mfc,mthi,mtlo,mfhi,mflo,const,arith,logical,
378 shift,slt,signext,clz,pop,trap,imul,imul3,imul3nc,imadd,idiv,idiv3,move,
379 fmove,fadd,fmul,fmadd,fdiv,frdiv,frdiv1,frdiv2,fabs,fneg,fcmp,fcvt,fsqrt,
380 frsqrt,frsqrt1,frsqrt2,dspmac,dspmacsat,accext,accmod,dspalu,dspalusat,
381 multi,atomic,syncloop,nop,ghost,multimem,
382 simd_div,simd_fclass,simd_flog2,simd_fadd,simd_fcvt,simd_fmul,simd_fmadd,
383 simd_fdiv,simd_bitins,simd_bitmov,simd_insert,simd_sld,simd_mul,simd_fcmp,
384 simd_fexp2,simd_int_arith,simd_bit,simd_shift,simd_splat,simd_fill,
385 simd_permute,simd_shf,simd_sat,simd_pcnt,simd_copy,simd_branch,simd_cmsa,
386 simd_fminmax,simd_logic,simd_move,simd_load,simd_store"
387 (cond [(eq_attr "jal" "!unset") (const_string "call")
388 (eq_attr "got" "load") (const_string "load")
389
390 (eq_attr "alu_type" "add,sub") (const_string "arith")
391
392 (eq_attr "alu_type" "not,nor,and,or,xor") (const_string "logical")
393
394 ;; If a doubleword move uses these expensive instructions,
395 ;; it is usually better to schedule them in the same way
396 ;; as the singleword form, rather than as "multi".
397 (eq_attr "move_type" "load") (const_string "load")
398 (eq_attr "move_type" "fpload") (const_string "fpload")
399 (eq_attr "move_type" "store") (const_string "store")
400 (eq_attr "move_type" "fpstore") (const_string "fpstore")
401 (eq_attr "move_type" "mtc") (const_string "mtc")
402 (eq_attr "move_type" "mfc") (const_string "mfc")
403 (eq_attr "move_type" "mtlo") (const_string "mtlo")
404 (eq_attr "move_type" "mflo") (const_string "mflo")
405
406 ;; These types of move are always single insns.
407 (eq_attr "move_type" "imul") (const_string "imul")
408 (eq_attr "move_type" "fmove") (const_string "fmove")
409 (eq_attr "move_type" "loadpool") (const_string "load")
410 (eq_attr "move_type" "signext") (const_string "signext")
411 (eq_attr "move_type" "ext_ins") (const_string "arith")
412 (eq_attr "move_type" "arith") (const_string "arith")
413 (eq_attr "move_type" "logical") (const_string "logical")
414 (eq_attr "move_type" "sll0") (const_string "shift")
415 (eq_attr "move_type" "andi") (const_string "logical")
416
417 ;; These types of move are always split.
418 (eq_attr "move_type" "constN,shift_shift")
419 (const_string "multi")
420
421 ;; These types of move are split for quadword modes only.
422 (and (eq_attr "move_type" "move,const")
423 (eq_attr "qword_mode" "yes"))
424 (const_string "multi")
425
426 ;; These types of move are split for doubleword modes only.
427 (and (eq_attr "move_type" "move,const")
428 (eq_attr "dword_mode" "yes"))
429 (const_string "multi")
430 (eq_attr "move_type" "move") (const_string "move")
431 (eq_attr "move_type" "const") (const_string "const")
432 (eq_attr "sync_mem" "!none") (const_string "syncloop")]
433 (const_string "unknown")))
434
435 (define_attr "compact_form" "always,maybe,never"
436 (cond [(eq_attr "jal" "direct")
437 (const_string "always")
438 (eq_attr "jal" "indirect")
439 (const_string "maybe")
440 (eq_attr "type" "jump")
441 (const_string "maybe")]
442 (const_string "never")))
443
444 ;; Mode for conversion types (fcvt)
445 ;; I2S integer to float single (SI/DI to SF)
446 ;; I2D integer to float double (SI/DI to DF)
447 ;; S2I float to integer (SF to SI/DI)
448 ;; D2I float to integer (DF to SI/DI)
449 ;; D2S double to float single
450 ;; S2D float single to double
451
452 (define_attr "cnv_mode" "unknown,I2S,I2D,S2I,D2I,D2S,S2D"
453 (const_string "unknown"))
454
455 ;; Is this an extended instruction in mips16 mode?
456 (define_attr "extended_mips16" "no,yes"
457 (if_then_else (ior ;; In general, constant-pool loads are extended
458 ;; instructions. We don't yet optimize for 16-bit
459 ;; PC-relative references.
460 (eq_attr "move_type" "sll0,loadpool")
461 (eq_attr "jal" "direct")
462 (eq_attr "got" "load"))
463 (const_string "yes")
464 (const_string "no")))
465
466 (define_attr "compression" "none,all,micromips32,micromips"
467 (const_string "none"))
468
469 (define_attr "enabled" "no,yes"
470 (cond [;; The o32 FPXX and FP64A ABI extensions prohibit direct moves between
471 ;; GR_REG and FR_REG for 64-bit values.
472 (and (eq_attr "move_type" "mtc,mfc")
473 (match_test "(TARGET_FLOATXX && !ISA_HAS_MXHC1)
474 || TARGET_O32_FP64A_ABI")
475 (eq_attr "dword_mode" "yes"))
476 (const_string "no")
477 (and (eq_attr "compression" "micromips32,micromips")
478 (match_test "!TARGET_MICROMIPS"))
479 (const_string "no")]
480 (const_string "yes")))
481
482 ;; The number of individual instructions that a non-branch pattern generates,
483 ;; using units of BASE_INSN_LENGTH.
484 (define_attr "insn_count" ""
485 (cond [;; "Ghost" instructions occupy no space.
486 (eq_attr "type" "ghost")
487 (const_int 0)
488
489 ;; Extended instructions count as 2.
490 (and (eq_attr "extended_mips16" "yes")
491 (match_test "TARGET_MIPS16"))
492 (const_int 2)
493
494 ;; A GOT load followed by an add of $gp. This is not used for MIPS16.
495 (eq_attr "got" "xgot_high")
496 (const_int 2)
497
498 ;; SHIFT_SHIFTs are decomposed into two separate instructions.
499 ;; They are extended instructions on MIPS16 targets.
500 (eq_attr "move_type" "shift_shift")
501 (if_then_else (match_test "TARGET_MIPS16")
502 (const_int 4)
503 (const_int 2))
504
505 ;; Check for doubleword moves that are decomposed into two
506 ;; instructions. The individual instructions are unextended
507 ;; MIPS16 ones.
508 (and (eq_attr "move_type" "mtc,mfc,mtlo,mflo,move")
509 (eq_attr "dword_mode" "yes"))
510 (const_int 2)
511
512 ;; Check for quadword moves that are decomposed into four
513 ;; instructions.
514 (and (eq_attr "move_type" "mtc,mfc,move")
515 (eq_attr "qword_mode" "yes"))
516 (const_int 4)
517
518 ;; Constants, loads and stores are handled by external routines.
519 (and (eq_attr "move_type" "const,constN")
520 (eq_attr "dword_mode" "yes"))
521 (symbol_ref "mips_split_const_insns (operands[1])")
522 (eq_attr "move_type" "const,constN")
523 (symbol_ref "mips_const_insns (operands[1])")
524 (eq_attr "move_type" "load,fpload")
525 (symbol_ref "mips_load_store_insns (operands[1], insn)")
526 (eq_attr "move_type" "store,fpstore")
527 (symbol_ref "mips_load_store_insns (operands[0], insn)
528 + (TARGET_FIX_24K ? 1 : 0)")
529
530 ;; In the worst case, a call macro will take 8 instructions:
531 ;;
532 ;; lui $25,%call_hi(FOO)
533 ;; addu $25,$25,$28
534 ;; lw $25,%call_lo(FOO)($25)
535 ;; nop
536 ;; jalr $25
537 ;; nop
538 ;; lw $gp,X($sp)
539 ;; nop
540 (eq_attr "jal_macro" "yes")
541 (const_int 8)
542
543 ;; Various VR4120 errata require a nop to be inserted after a macc
544 ;; instruction. The assembler does this for us, so account for
545 ;; the worst-case length here.
546 (and (eq_attr "type" "imadd")
547 (match_test "TARGET_FIX_VR4120"))
548 (const_int 2)
549
550 ;; VR4120 errata MD(4): if there are consecutive dmult instructions,
551 ;; the result of the second one is missed. The assembler should work
552 ;; around this by inserting a nop after the first dmult.
553 (and (eq_attr "type" "imul,imul3")
554 (eq_attr "mode" "DI")
555 (match_test "TARGET_FIX_VR4120"))
556 (const_int 2)
557
558 (eq_attr "type" "idiv,idiv3")
559 (symbol_ref "mips_idiv_insns (GET_MODE (PATTERN (insn)))")
560
561 (not (eq_attr "sync_mem" "none"))
562 (symbol_ref "mips_sync_loop_insns (insn, operands)")]
563 (const_int 1)))
564
565 ;; Length of instruction in bytes. The default is derived from "insn_count",
566 ;; but there are special cases for branches (which must be handled here)
567 ;; and for compressed single instructions.
568 (define_attr "length" ""
569 (cond [(and (ior (eq_attr "compression" "micromips,all")
570 (and (eq_attr "compression" "micromips32")
571 (eq_attr "mode" "SI,SF")))
572 (eq_attr "dword_mode" "no")
573 (match_test "TARGET_MICROMIPS"))
574 (const_int 2)
575
576 ;; Direct microMIPS branch instructions have a range of
577 ;; [-0x10000,0xfffe], otherwise the range is [-0x20000,0x1fffc].
578 ;; If a branch is outside this range, we have a choice of two
579 ;; sequences.
580 ;;
581 ;; For PIC, an out-of-range branch like:
582 ;;
583 ;; bne r1,r2,target
584 ;; dslot
585 ;;
586 ;; becomes the equivalent of:
587 ;;
588 ;; beq r1,r2,1f
589 ;; dslot
590 ;; la $at,target
591 ;; jr $at
592 ;; nop
593 ;; 1:
594 ;;
595 ;; The non-PIC case is similar except that we use a direct
596 ;; jump instead of an la/jr pair. Since the target of this
597 ;; jump is an absolute 28-bit bit address (the other bits
598 ;; coming from the address of the delay slot) this form cannot
599 ;; cross a 256MB boundary. We could provide the option of
600 ;; using la/jr in this case too, but we do not do so at
601 ;; present.
602 ;;
603 ;; The value we specify here does not account for the delay slot
604 ;; instruction, whose length is added separately. If the RTL
605 ;; pattern has no explicit delay slot, mips_adjust_insn_length
606 ;; will add the length of the implicit nop. The range of
607 ;; [-0x20000, 0x1fffc] from the address of the delay slot
608 ;; therefore translates to a range of:
609 ;;
610 ;; [-(0x20000 - sizeof (branch)), 0x1fffc - sizeof (slot)]
611 ;; == [-0x1fffc, 0x1fff8]
612 ;;
613 ;; from the shorten_branches reference address.
614 (and (eq_attr "type" "branch")
615 (not (match_test "TARGET_MIPS16")))
616 (cond [;; Any variant can handle the 17-bit range.
617 (and (le (minus (match_dup 0) (pc)) (const_int 65532))
618 (le (minus (pc) (match_dup 0)) (const_int 65534)))
619 (const_int 4)
620
621 ;; The 18-bit range is OK other than for microMIPS.
622 (and (not (match_test "TARGET_MICROMIPS"))
623 (and (le (minus (match_dup 0) (pc)) (const_int 131064))
624 (le (minus (pc) (match_dup 0)) (const_int 131068))))
625 (const_int 4)
626
627 ;; The non-PIC case: branch, first delay slot, and J.
628 (match_test "TARGET_ABSOLUTE_JUMPS")
629 (const_int 12)]
630
631 ;; Use MAX_PIC_BRANCH_LENGTH as a (gross) overestimate.
632 ;; mips_adjust_insn_length substitutes the correct length.
633 ;;
634 ;; Note that we can't simply use (symbol_ref ...) here
635 ;; because genattrtab needs to know the maximum length
636 ;; of an insn.
637 (const_int MAX_PIC_BRANCH_LENGTH))
638
639 ;; An unextended MIPS16 branch has a range of [-0x100, 0xfe]
640 ;; from the address of the following instruction, which leads
641 ;; to a range of:
642 ;;
643 ;; [-(0x100 - sizeof (branch)), 0xfe]
644 ;; == [-0xfe, 0xfe]
645 ;;
646 ;; from the shorten_branches reference address. Extended branches
647 ;; likewise have a range of [-0x10000, 0xfffe] from the address
648 ;; of the following instruction, which leads to a range of:
649 ;;
650 ;; [-(0x10000 - sizeof (branch)), 0xfffe]
651 ;; == [-0xfffc, 0xfffe]
652 ;;
653 ;; from the reference address.
654 ;;
655 ;; When a branch is out of range, mips_reorg splits it into a form
656 ;; that uses in-range branches. There are four basic sequences:
657 ;;
658 ;; (1) Absolute addressing with a readable text segment
659 ;; (32-bit addresses):
660 ;;
661 ;; b... foo 2 bytes
662 ;; move $1,$2 2 bytes
663 ;; lw $2,label 2 bytes
664 ;; jr $2 2 bytes
665 ;; move $2,$1 2 bytes
666 ;; .align 2 0 or 2 bytes
667 ;; label:
668 ;; .word target 4 bytes
669 ;; foo:
670 ;; (16 bytes in the worst case)
671 ;;
672 ;; (2) Absolute addressing with a readable text segment
673 ;; (64-bit addresses):
674 ;;
675 ;; b... foo 2 bytes
676 ;; move $1,$2 2 bytes
677 ;; ld $2,label 2 bytes
678 ;; jr $2 2 bytes
679 ;; move $2,$1 2 bytes
680 ;; .align 3 0 to 6 bytes
681 ;; label:
682 ;; .dword target 8 bytes
683 ;; foo:
684 ;; (24 bytes in the worst case)
685 ;;
686 ;; (3) Absolute addressing without a readable text segment
687 ;; (which requires 32-bit addresses at present):
688 ;;
689 ;; b... foo 2 bytes
690 ;; move $1,$2 2 bytes
691 ;; lui $2,%hi(target) 4 bytes
692 ;; sll $2,8 2 bytes
693 ;; sll $2,8 2 bytes
694 ;; addiu $2,%lo(target) 4 bytes
695 ;; jr $2 2 bytes
696 ;; move $2,$1 2 bytes
697 ;; foo:
698 ;; (20 bytes)
699 ;;
700 ;; (4) PIC addressing (which requires 32-bit addresses at present):
701 ;;
702 ;; b... foo 2 bytes
703 ;; move $1,$2 2 bytes
704 ;; lw $2,cprestore 0, 2 or 4 bytes
705 ;; lw $2,%got(target)($2) 4 bytes
706 ;; addiu $2,%lo(target) 4 bytes
707 ;; jr $2 2 bytes
708 ;; move $2,$1 2 bytes
709 ;; foo:
710 ;; (20 bytes in the worst case)
711 (and (eq_attr "type" "branch")
712 (match_test "TARGET_MIPS16"))
713 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 254))
714 (le (minus (pc) (match_dup 0)) (const_int 254)))
715 (const_int 2)
716 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
717 (le (minus (pc) (match_dup 0)) (const_int 65532)))
718 (const_int 4)
719 (and (match_test "TARGET_ABICALLS")
720 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
721 (const_int 20)
722 (match_test "Pmode == SImode")
723 (const_int 16)
724 ] (const_int 24))]
725 (symbol_ref "get_attr_insn_count (insn) * BASE_INSN_LENGTH")))
726
727 ;; Attribute describing the processor.
728 (define_enum_attr "cpu" "processor"
729 (const (symbol_ref "mips_tune")))
730
731 ;; The type of hardware hazard associated with this instruction.
732 ;; DELAY means that the next instruction cannot read the result
733 ;; of this one. HILO means that the next two instructions cannot
734 ;; write to HI or LO.
735 (define_attr "hazard" "none,delay,hilo,forbidden_slot"
736 (cond [(and (eq_attr "type" "load,fpload,fpidxload")
737 (match_test "ISA_HAS_LOAD_DELAY"))
738 (const_string "delay")
739
740 (and (eq_attr "type" "mfc,mtc")
741 (match_test "ISA_HAS_XFER_DELAY"))
742 (const_string "delay")
743
744 (and (eq_attr "type" "fcmp")
745 (match_test "ISA_HAS_FCMP_DELAY"))
746 (const_string "delay")
747
748 ;; The r4000 multiplication patterns include an mflo instruction.
749 (and (eq_attr "type" "imul")
750 (match_test "TARGET_FIX_R4000"))
751 (const_string "hilo")
752
753 (and (eq_attr "type" "mfhi,mflo")
754 (not (match_test "ISA_HAS_HILO_INTERLOCKS")))
755 (const_string "hilo")]
756 (const_string "none")))
757
758 ;; Can the instruction be put into a delay slot?
759 (define_attr "can_delay" "no,yes"
760 (if_then_else (and (eq_attr "type" "!branch,call,jump")
761 (eq_attr "hazard" "none")
762 (match_test "get_attr_insn_count (insn) == 1"))
763 (const_string "yes")
764 (const_string "no")))
765
766 ;; Attribute defining whether or not we can use the branch-likely
767 ;; instructions.
768 (define_attr "branch_likely" "no,yes"
769 (if_then_else (match_test "GENERATE_BRANCHLIKELY")
770 (const_string "yes")
771 (const_string "no")))
772
773 ;; True if an instruction might assign to hi or lo when reloaded.
774 ;; This is used by the TUNE_MACC_CHAINS code.
775 (define_attr "may_clobber_hilo" "no,yes"
776 (if_then_else (eq_attr "type" "imul,imul3,imadd,idiv,mthi,mtlo")
777 (const_string "yes")
778 (const_string "no")))
779
780 ;; Describe a user's asm statement.
781 (define_asm_attributes
782 [(set_attr "type" "multi")
783 (set_attr "can_delay" "no")])
784 \f
785 ;; This mode iterator allows 32-bit and 64-bit GPR patterns to be generated
786 ;; from the same template.
787 (define_mode_iterator GPR [SI (DI "TARGET_64BIT")])
788
789 ;; A copy of GPR that can be used when a pattern has two independent
790 ;; modes.
791 (define_mode_iterator GPR2 [SI (DI "TARGET_64BIT")])
792
793 (define_mode_iterator MOVEP1 [SI SF])
794 (define_mode_iterator MOVEP2 [SI SF])
795 (define_mode_iterator JOIN_MODE [HI
796 SI
797 (SF "TARGET_HARD_FLOAT")
798 (DF "TARGET_HARD_FLOAT
799 && TARGET_DOUBLE_FLOAT")])
800
801 ;; This mode iterator allows :HILO to be used as the mode of the
802 ;; concatenated HI and LO registers.
803 (define_mode_iterator HILO [(DI "!TARGET_64BIT") (TI "TARGET_64BIT")])
804
805 ;; This mode iterator allows :P to be used for patterns that operate on
806 ;; pointer-sized quantities. Exactly one of the two alternatives will match.
807 (define_mode_iterator P [(SI "Pmode == SImode") (DI "Pmode == DImode")])
808
809 ;; This mode iterator allows :MOVECC to be used anywhere that a
810 ;; conditional-move-type condition is needed.
811 (define_mode_iterator MOVECC [SI (DI "TARGET_64BIT")
812 (CC "TARGET_HARD_FLOAT
813 && !TARGET_LOONGSON_2EF
814 && !TARGET_MIPS5900")])
815
816 ;; This mode iterator allows :FPCC to be used anywhere that an FP condition
817 ;; is needed.
818 (define_mode_iterator FPCC [(CC "!ISA_HAS_CCF")
819 (CCF "ISA_HAS_CCF")])
820
821 ;; 32-bit integer moves for which we provide move patterns.
822 (define_mode_iterator IMOVE32
823 [SI
824 (V2HI "TARGET_DSP")
825 (V4QI "TARGET_DSP")
826 (V2HQ "TARGET_DSP")
827 (V2UHQ "TARGET_DSP")
828 (V2HA "TARGET_DSP")
829 (V2UHA "TARGET_DSP")
830 (V4QQ "TARGET_DSP")
831 (V4UQQ "TARGET_DSP")])
832
833 ;; 64-bit modes for which we provide move patterns.
834 (define_mode_iterator MOVE64
835 [DI DF
836 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")
837 (V2SI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
838 (V4HI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")
839 (V8QI "TARGET_HARD_FLOAT && TARGET_LOONGSON_VECTORS")])
840
841 ;; 128-bit modes for which we provide move patterns on 64-bit targets.
842 (define_mode_iterator MOVE128 [TI TF])
843
844 ;; This mode iterator allows the QI and HI extension patterns to be
845 ;; defined from the same template.
846 (define_mode_iterator SHORT [QI HI])
847
848 ;; Likewise the 64-bit truncate-and-shift patterns.
849 (define_mode_iterator SUBDI [QI HI SI])
850
851 ;; This mode iterator allows :ANYF to be used wherever a scalar or vector
852 ;; floating-point mode is allowed.
853 (define_mode_iterator ANYF [(SF "TARGET_HARD_FLOAT")
854 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")
855 (V2SF "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT")])
856
857 ;; Like ANYF, but only applies to scalar modes.
858 (define_mode_iterator SCALARF [(SF "TARGET_HARD_FLOAT")
859 (DF "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT")])
860
861 ;; A floating-point mode for which moves involving FPRs may need to be split.
862 (define_mode_iterator SPLITF
863 [(DF "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
864 (DI "!TARGET_64BIT && TARGET_DOUBLE_FLOAT")
865 (V2SF "!TARGET_64BIT && TARGET_PAIRED_SINGLE_FLOAT")
866 (V2SI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
867 (V4HI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
868 (V8QI "!TARGET_64BIT && TARGET_LOONGSON_VECTORS")
869 (TF "TARGET_64BIT && TARGET_FLOAT64")])
870
871 ;; In GPR templates, a string like "<d>subu" will expand to "subu" in the
872 ;; 32-bit version and "dsubu" in the 64-bit version.
873 (define_mode_attr d [(SI "") (DI "d")
874 (QQ "") (HQ "") (SQ "") (DQ "d")
875 (UQQ "") (UHQ "") (USQ "") (UDQ "d")
876 (HA "") (SA "") (DA "d")
877 (UHA "") (USA "") (UDA "d")])
878
879 ;; Same as d but upper-case.
880 (define_mode_attr D [(SI "") (DI "D")
881 (QQ "") (HQ "") (SQ "") (DQ "D")
882 (UQQ "") (UHQ "") (USQ "") (UDQ "D")
883 (HA "") (SA "") (DA "D")
884 (UHA "") (USA "") (UDA "D")])
885
886 ;; This attribute gives the length suffix for a load or store instruction.
887 ;; The same suffixes work for zero and sign extensions.
888 (define_mode_attr size [(QI "b") (HI "h") (SI "w") (DI "d")])
889 (define_mode_attr SIZE [(QI "B") (HI "H") (SI "W") (DI "D")])
890
891 ;; This attributes gives the mode mask of a SHORT.
892 (define_mode_attr mask [(QI "0x00ff") (HI "0xffff")])
893
894 ;; Mode attributes for GPR loads.
895 (define_mode_attr load [(SI "lw") (DI "ld")])
896 ;; Instruction names for stores.
897 (define_mode_attr store [(QI "sb") (HI "sh") (SI "sw") (DI "sd")])
898
899 ;; Similarly for MIPS IV indexed FPR loads and stores.
900 (define_mode_attr loadx [(SF "lwxc1") (DF "ldxc1") (V2SF "ldxc1")])
901 (define_mode_attr storex [(SF "swxc1") (DF "sdxc1") (V2SF "sdxc1")])
902
903 ;; The unextended ranges of the MIPS16 addiu and daddiu instructions
904 ;; are different. Some forms of unextended addiu have an 8-bit immediate
905 ;; field but the equivalent daddiu has only a 5-bit field.
906 (define_mode_attr si8_di5 [(SI "8") (DI "5")])
907
908 ;; This attribute gives the best constraint to use for registers of
909 ;; a given mode.
910 (define_mode_attr reg [(SI "d") (DI "d") (CC "z") (CCF "f")])
911
912 ;; This attribute gives the format suffix for floating-point operations.
913 (define_mode_attr fmt [(SF "s") (DF "d") (V2SF "ps")])
914
915 ;; This attribute gives the upper-case mode name for one unit of a
916 ;; floating-point mode or vector mode.
917 (define_mode_attr UNITMODE [(SF "SF") (DF "DF") (V2SF "SF") (V4SF "SF")
918 (V16QI "QI") (V8HI "HI") (V4SI "SI") (V2DI "DI")
919 (V2DF "DF")])
920
921 ;; This attribute gives the integer mode that has the same size as a
922 ;; fixed-point mode.
923 (define_mode_attr IMODE [(QQ "QI") (HQ "HI") (SQ "SI") (DQ "DI")
924 (UQQ "QI") (UHQ "HI") (USQ "SI") (UDQ "DI")
925 (HA "HI") (SA "SI") (DA "DI")
926 (UHA "HI") (USA "SI") (UDA "DI")
927 (V4UQQ "SI") (V2UHQ "SI") (V2UHA "SI")
928 (V2HQ "SI") (V2HA "SI")])
929
930 ;; This attribute gives the integer mode that has half the size of
931 ;; the controlling mode.
932 (define_mode_attr HALFMODE [(DF "SI") (DI "SI") (V2SF "SI")
933 (V2SI "SI") (V4HI "SI") (V8QI "SI")
934 (TF "DI")])
935
936 ;; This attribute works around the early SB-1 rev2 core "F2" erratum:
937 ;;
938 ;; In certain cases, div.s and div.ps may have a rounding error
939 ;; and/or wrong inexact flag.
940 ;;
941 ;; Therefore, we only allow div.s if not working around SB-1 rev2
942 ;; errata or if a slight loss of precision is OK.
943 (define_mode_attr divide_condition
944 [DF (SF "!TARGET_FIX_SB1 || flag_unsafe_math_optimizations")
945 (V2SF "TARGET_SB1 && (!TARGET_FIX_SB1 || flag_unsafe_math_optimizations)")])
946
947 ;; This attribute gives the conditions under which SQRT.fmt instructions
948 ;; can be used.
949 (define_mode_attr sqrt_condition
950 [(SF "!ISA_MIPS1") (DF "!ISA_MIPS1") (V2SF "TARGET_SB1")])
951
952 ;; This attribute provides the correct mnemonic for each FP condition mode.
953 (define_mode_attr fpcmp [(CC "c") (CCF "cmp")])
954
955 ;; This code iterator allows signed and unsigned widening multiplications
956 ;; to use the same template.
957 (define_code_iterator any_extend [sign_extend zero_extend])
958
959 ;; This code iterator allows the two right shift instructions to be
960 ;; generated from the same template.
961 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
962
963 ;; This code iterator allows the three shift instructions to be generated
964 ;; from the same template.
965 (define_code_iterator any_shift [ashift ashiftrt lshiftrt])
966
967 ;; This code iterator allows unsigned and signed division to be generated
968 ;; from the same template.
969 (define_code_iterator any_div [div udiv])
970
971 ;; This code iterator allows unsigned and signed modulus to be generated
972 ;; from the same template.
973 (define_code_iterator any_mod [mod umod])
974
975 ;; This code iterator allows addition and subtraction to be generated
976 ;; from the same template.
977 (define_code_iterator addsub [plus minus])
978
979 ;; This code iterator allows all native floating-point comparisons to be
980 ;; generated from the same template.
981 (define_code_iterator fcond [unordered uneq unlt unle eq lt le
982 (ordered "ISA_HAS_CCF")
983 (ltgt "ISA_HAS_CCF")
984 (ne "ISA_HAS_CCF")])
985
986 ;; This code iterator is used for comparisons that can be implemented
987 ;; by swapping the operands.
988 (define_code_iterator swapped_fcond [ge gt unge ungt])
989
990 ;; Equality operators.
991 (define_code_iterator equality_op [eq ne])
992
993 ;; These code iterators allow the signed and unsigned scc operations to use
994 ;; the same template.
995 (define_code_iterator any_gt [gt gtu])
996 (define_code_iterator any_ge [ge geu])
997 (define_code_iterator any_lt [lt ltu])
998 (define_code_iterator any_le [le leu])
999
1000 (define_code_iterator any_return [return simple_return])
1001
1002 ;; <u> expands to an empty string when doing a signed operation and
1003 ;; "u" when doing an unsigned operation.
1004 (define_code_attr u [(sign_extend "") (zero_extend "u")
1005 (div "") (udiv "u")
1006 (mod "") (umod "u")
1007 (gt "") (gtu "u")
1008 (ge "") (geu "u")
1009 (lt "") (ltu "u")
1010 (le "") (leu "u")])
1011
1012 ;; <U> is like <u> except uppercase.
1013 (define_code_attr U [(sign_extend "") (zero_extend "U")])
1014
1015 ;; <su> is like <u>, but the signed form expands to "s" rather than "".
1016 (define_code_attr su [(sign_extend "s") (zero_extend "u")])
1017
1018 ;; <optab> expands to the name of the optab for a particular code.
1019 (define_code_attr optab [(ashift "ashl")
1020 (ashiftrt "ashr")
1021 (lshiftrt "lshr")
1022 (ior "ior")
1023 (xor "xor")
1024 (and "and")
1025 (plus "add")
1026 (minus "sub")
1027 (return "return")
1028 (simple_return "simple_return")])
1029
1030 ;; <insn> expands to the name of the insn that implements a particular code.
1031 (define_code_attr insn [(ashift "sll")
1032 (ashiftrt "sra")
1033 (lshiftrt "srl")
1034 (ior "or")
1035 (xor "xor")
1036 (and "and")
1037 (plus "addu")
1038 (minus "subu")])
1039
1040 ;; <immediate_insn> expands to the name of the insn that implements
1041 ;; a particular code to operate on immediate values.
1042 (define_code_attr immediate_insn [(ior "ori")
1043 (xor "xori")
1044 (and "andi")])
1045
1046 (define_code_attr shift_compression [(ashift "micromips32")
1047 (lshiftrt "micromips32")
1048 (ashiftrt "none")])
1049
1050 ;; <fcond> is the c.cond.fmt condition associated with a particular code.
1051 (define_code_attr fcond [(unordered "un")
1052 (uneq "ueq")
1053 (unlt "ult")
1054 (unle "ule")
1055 (eq "eq")
1056 (lt "lt")
1057 (le "le")
1058 (ordered "or")
1059 (ltgt "ne")
1060 (ne "une")])
1061
1062 ;; Similar, but for swapped conditions.
1063 (define_code_attr swapped_fcond [(ge "le")
1064 (gt "lt")
1065 (unge "ule")
1066 (ungt "ult")])
1067
1068 ;; The value of the bit when the branch is taken for branch_bit patterns.
1069 ;; Comparison is always against zero so this depends on the operator.
1070 (define_code_attr bbv [(eq "0") (ne "1")])
1071
1072 ;; This is the inverse value of bbv.
1073 (define_code_attr bbinv [(eq "1") (ne "0")])
1074
1075 ;; The sel mnemonic to use depending on the condition test.
1076 (define_code_attr sel [(eq "seleqz") (ne "selnez")])
1077 (define_code_attr selinv [(eq "selnez") (ne "seleqz")])
1078 \f
1079 ;; .........................
1080 ;;
1081 ;; Branch, call and jump delay slots
1082 ;;
1083 ;; .........................
1084
1085 (define_delay (and (eq_attr "type" "branch")
1086 (not (match_test "TARGET_MIPS16"))
1087 (eq_attr "branch_likely" "yes"))
1088 [(eq_attr "can_delay" "yes")
1089 (nil)
1090 (eq_attr "can_delay" "yes")])
1091
1092 ;; Branches that have delay slots and don't have likely variants do
1093 ;; not annul on false.
1094 (define_delay (and (eq_attr "type" "branch")
1095 (not (match_test "TARGET_MIPS16"))
1096 (ior (match_test "TARGET_CB_NEVER")
1097 (and (eq_attr "compact_form" "maybe")
1098 (not (match_test "TARGET_CB_ALWAYS")))
1099 (eq_attr "compact_form" "never"))
1100 (eq_attr "branch_likely" "no"))
1101 [(eq_attr "can_delay" "yes")
1102 (nil)
1103 (nil)])
1104
1105 (define_delay (and (eq_attr "type" "jump")
1106 (ior (match_test "TARGET_CB_NEVER")
1107 (and (eq_attr "compact_form" "maybe")
1108 (not (match_test "TARGET_CB_ALWAYS")))
1109 (eq_attr "compact_form" "never")))
1110 [(eq_attr "can_delay" "yes")
1111 (nil)
1112 (nil)])
1113
1114 ;; Call type instructions should never have a compact form as the
1115 ;; type is only used for MIPS16 patterns. For safety put the compact
1116 ;; branch detection condition in anyway.
1117 (define_delay (and (eq_attr "type" "call")
1118 (eq_attr "jal_macro" "no")
1119 (ior (match_test "TARGET_CB_NEVER")
1120 (and (eq_attr "compact_form" "maybe")
1121 (not (match_test "TARGET_CB_ALWAYS")))
1122 (eq_attr "compact_form" "never")))
1123 [(eq_attr "can_delay" "yes")
1124 (nil)
1125 (nil)])
1126 \f
1127 ;; Pipeline descriptions.
1128 ;;
1129 ;; generic.md provides a fallback for processors without a specific
1130 ;; pipeline description. It is derived from the old define_function_unit
1131 ;; version and uses the "alu" and "imuldiv" units declared below.
1132 ;;
1133 ;; Some of the processor-specific files are also derived from old
1134 ;; define_function_unit descriptions and simply override the parts of
1135 ;; generic.md that don't apply. The other processor-specific files
1136 ;; are self-contained.
1137 (define_automaton "alu,imuldiv")
1138
1139 (define_cpu_unit "alu" "alu")
1140 (define_cpu_unit "imuldiv" "imuldiv")
1141
1142 ;; Ghost instructions produce no real code and introduce no hazards.
1143 ;; They exist purely to express an effect on dataflow.
1144 (define_insn_reservation "ghost" 0
1145 (eq_attr "type" "ghost")
1146 "nothing")
1147
1148 (include "i6400.md")
1149 (include "p5600.md")
1150 (include "m5100.md")
1151 (include "4k.md")
1152 (include "5k.md")
1153 (include "20kc.md")
1154 (include "24k.md")
1155 (include "74k.md")
1156 (include "3000.md")
1157 (include "4000.md")
1158 (include "4100.md")
1159 (include "4130.md")
1160 (include "4300.md")
1161 (include "4600.md")
1162 (include "5000.md")
1163 (include "5400.md")
1164 (include "5500.md")
1165 (include "6000.md")
1166 (include "7000.md")
1167 (include "9000.md")
1168 (include "10000.md")
1169 (include "loongson2ef.md")
1170 (include "loongson3a.md")
1171 (include "octeon.md")
1172 (include "sb1.md")
1173 (include "sr71k.md")
1174 (include "xlr.md")
1175 (include "xlp.md")
1176 (include "generic.md")
1177 \f
1178 ;;
1179 ;; ....................
1180 ;;
1181 ;; CONDITIONAL TRAPS
1182 ;;
1183 ;; ....................
1184 ;;
1185
1186 (define_insn "trap"
1187 [(trap_if (const_int 1) (const_int 0))]
1188 ""
1189 {
1190 if (ISA_HAS_COND_TRAP)
1191 return "teq\t$0,$0";
1192 else if (TARGET_MIPS16)
1193 return "break 0";
1194 else
1195 return "break";
1196 }
1197 [(set_attr "type" "trap")])
1198
1199 (define_expand "ctrap<mode>4"
1200 [(trap_if (match_operator 0 "comparison_operator"
1201 [(match_operand:GPR 1 "reg_or_0_operand")
1202 (match_operand:GPR 2 "arith_operand")])
1203 (match_operand 3 "const_0_operand"))]
1204 "ISA_HAS_COND_TRAPI || ISA_HAS_COND_TRAP"
1205 {
1206 mips_expand_conditional_trap (operands[0]);
1207 DONE;
1208 })
1209
1210 (define_insn "*conditional_trap_reg<mode>"
1211 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1212 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1213 (match_operand:GPR 2 "reg_or_0_operand" "dJ")])
1214 (const_int 0))]
1215 "ISA_HAS_COND_TRAP && !ISA_HAS_COND_TRAPI"
1216 "t%C0\t%z1,%2"
1217 [(set_attr "type" "trap")])
1218
1219 (define_insn "*conditional_trap<mode>"
1220 [(trap_if (match_operator:GPR 0 "trap_comparison_operator"
1221 [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
1222 (match_operand:GPR 2 "arith_operand" "dI")])
1223 (const_int 0))]
1224 "ISA_HAS_COND_TRAPI"
1225 "t%C0\t%z1,%2"
1226 [(set_attr "type" "trap")])
1227 \f
1228 ;;
1229 ;; ....................
1230 ;;
1231 ;; ADDITION
1232 ;;
1233 ;; ....................
1234 ;;
1235
1236 (define_insn "add<mode>3"
1237 [(set (match_operand:ANYF 0 "register_operand" "=f")
1238 (plus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1239 (match_operand:ANYF 2 "register_operand" "f")))]
1240 ""
1241 "add.<fmt>\t%0,%1,%2"
1242 [(set_attr "type" "fadd")
1243 (set_attr "mode" "<UNITMODE>")])
1244
1245 (define_expand "add<mode>3"
1246 [(set (match_operand:GPR 0 "register_operand")
1247 (plus:GPR (match_operand:GPR 1 "register_operand")
1248 (match_operand:GPR 2 "arith_operand")))]
1249 "")
1250
1251 (define_insn "*add<mode>3"
1252 [(set (match_operand:GPR 0 "register_operand" "=!u,d,!u,!u,!ks,!d,d")
1253 (plus:GPR (match_operand:GPR 1 "register_operand" "!u,d,!u,!ks,!ks,0,d")
1254 (match_operand:GPR 2 "arith_operand" "!u,d,Uead,Uuw6,Uesp,Usb4,Q")))]
1255 "!TARGET_MIPS16"
1256 {
1257 if (which_alternative == 0
1258 || which_alternative == 1)
1259 return "<d>addu\t%0,%1,%2";
1260 else
1261 return "<d>addiu\t%0,%1,%2";
1262 }
1263 [(set_attr "alu_type" "add")
1264 (set_attr "compression" "micromips32,*,micromips32,micromips32,micromips32,micromips32,*")
1265 (set_attr "mode" "<MODE>")])
1266
1267 (define_insn "*add<mode>3_mips16"
1268 [(set (match_operand:GPR 0 "register_operand" "=ks,ks,d,d,d,d,d,d,d")
1269 (plus:GPR (match_operand:GPR 1 "register_operand" "ks,ks,ks,ks,0,0,d,d,d")
1270 (match_operand:GPR 2 "arith_operand" "Usd8,Q,Uuw<si8_di5>,Q,Usb<si8_di5>,Q,Usb4,O,d")))]
1271 "TARGET_MIPS16"
1272 "@
1273 <d>addiu\t%0,%2
1274 <d>addiu\t%0,%2
1275 <d>addiu\t%0,%1,%2
1276 <d>addiu\t%0,%1,%2
1277 <d>addiu\t%0,%2
1278 <d>addiu\t%0,%2
1279 <d>addiu\t%0,%1,%2
1280 <d>addiu\t%0,%1,%2
1281 <d>addu\t%0,%1,%2"
1282 [(set_attr "alu_type" "add")
1283 (set_attr "mode" "<MODE>")
1284 (set_attr "extended_mips16" "no,yes,no,yes,no,yes,no,yes,no")])
1285
1286 ;; On the mips16, we can sometimes split an add of a constant which is
1287 ;; a 4 byte instruction into two adds which are both 2 byte
1288 ;; instructions. There are two cases: one where we are adding a
1289 ;; constant plus a register to another register, and one where we are
1290 ;; simply adding a constant to a register.
1291
1292 (define_split
1293 [(set (match_operand:SI 0 "d_operand")
1294 (plus:SI (match_dup 0)
1295 (match_operand:SI 1 "const_int_operand")))]
1296 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1297 && ((INTVAL (operands[1]) > 0x7f
1298 && INTVAL (operands[1]) <= 0x7f + 0x7f)
1299 || (INTVAL (operands[1]) < - 0x80
1300 && INTVAL (operands[1]) >= - 0x80 - 0x80))"
1301 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
1302 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
1303 {
1304 HOST_WIDE_INT val = INTVAL (operands[1]);
1305
1306 if (val >= 0)
1307 {
1308 operands[1] = GEN_INT (0x7f);
1309 operands[2] = GEN_INT (val - 0x7f);
1310 }
1311 else
1312 {
1313 operands[1] = GEN_INT (- 0x80);
1314 operands[2] = GEN_INT (val + 0x80);
1315 }
1316 })
1317
1318 (define_split
1319 [(set (match_operand:SI 0 "d_operand")
1320 (plus:SI (match_operand:SI 1 "d_operand")
1321 (match_operand:SI 2 "const_int_operand")))]
1322 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
1323 && REGNO (operands[0]) != REGNO (operands[1])
1324 && ((INTVAL (operands[2]) > 0x7
1325 && INTVAL (operands[2]) <= 0x7 + 0x7f)
1326 || (INTVAL (operands[2]) < - 0x8
1327 && INTVAL (operands[2]) >= - 0x8 - 0x80))"
1328 [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 2)))
1329 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 3)))]
1330 {
1331 HOST_WIDE_INT val = INTVAL (operands[2]);
1332
1333 if (val >= 0)
1334 {
1335 operands[2] = GEN_INT (0x7);
1336 operands[3] = GEN_INT (val - 0x7);
1337 }
1338 else
1339 {
1340 operands[2] = GEN_INT (- 0x8);
1341 operands[3] = GEN_INT (val + 0x8);
1342 }
1343 })
1344
1345 (define_split
1346 [(set (match_operand:DI 0 "d_operand")
1347 (plus:DI (match_dup 0)
1348 (match_operand:DI 1 "const_int_operand")))]
1349 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1350 && ((INTVAL (operands[1]) > 0xf
1351 && INTVAL (operands[1]) <= 0xf + 0xf)
1352 || (INTVAL (operands[1]) < - 0x10
1353 && INTVAL (operands[1]) >= - 0x10 - 0x10))"
1354 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
1355 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
1356 {
1357 HOST_WIDE_INT val = INTVAL (operands[1]);
1358
1359 if (val >= 0)
1360 {
1361 operands[1] = GEN_INT (0xf);
1362 operands[2] = GEN_INT (val - 0xf);
1363 }
1364 else
1365 {
1366 operands[1] = GEN_INT (- 0x10);
1367 operands[2] = GEN_INT (val + 0x10);
1368 }
1369 })
1370
1371 (define_split
1372 [(set (match_operand:DI 0 "d_operand")
1373 (plus:DI (match_operand:DI 1 "d_operand")
1374 (match_operand:DI 2 "const_int_operand")))]
1375 "TARGET_MIPS16 && TARGET_64BIT && reload_completed && !TARGET_DEBUG_D_MODE
1376 && REGNO (operands[0]) != REGNO (operands[1])
1377 && ((INTVAL (operands[2]) > 0x7
1378 && INTVAL (operands[2]) <= 0x7 + 0xf)
1379 || (INTVAL (operands[2]) < - 0x8
1380 && INTVAL (operands[2]) >= - 0x8 - 0x10))"
1381 [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 2)))
1382 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 3)))]
1383 {
1384 HOST_WIDE_INT val = INTVAL (operands[2]);
1385
1386 if (val >= 0)
1387 {
1388 operands[2] = GEN_INT (0x7);
1389 operands[3] = GEN_INT (val - 0x7);
1390 }
1391 else
1392 {
1393 operands[2] = GEN_INT (- 0x8);
1394 operands[3] = GEN_INT (val + 0x8);
1395 }
1396 })
1397
1398 (define_insn "*addsi3_extended"
1399 [(set (match_operand:DI 0 "register_operand" "=d,d")
1400 (sign_extend:DI
1401 (plus:SI (match_operand:SI 1 "register_operand" "d,d")
1402 (match_operand:SI 2 "arith_operand" "d,Q"))))]
1403 "TARGET_64BIT && !TARGET_MIPS16"
1404 "@
1405 addu\t%0,%1,%2
1406 addiu\t%0,%1,%2"
1407 [(set_attr "alu_type" "add")
1408 (set_attr "mode" "SI")])
1409
1410 ;; Split this insn so that the addiu splitters can have a crack at it.
1411 ;; Use a conservative length estimate until the split.
1412 (define_insn_and_split "*addsi3_extended_mips16"
1413 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
1414 (sign_extend:DI
1415 (plus:SI (match_operand:SI 1 "register_operand" "0,d,d")
1416 (match_operand:SI 2 "arith_operand" "Q,O,d"))))]
1417 "TARGET_64BIT && TARGET_MIPS16"
1418 "#"
1419 "&& reload_completed"
1420 [(set (match_dup 3) (plus:SI (match_dup 1) (match_dup 2)))]
1421 { operands[3] = gen_lowpart (SImode, operands[0]); }
1422 [(set_attr "alu_type" "add")
1423 (set_attr "mode" "SI")
1424 (set_attr "extended_mips16" "yes")])
1425
1426 ;; Combiner patterns for unsigned byte-add.
1427
1428 (define_insn "*baddu_si_eb"
1429 [(set (match_operand:SI 0 "register_operand" "=d")
1430 (zero_extend:SI
1431 (subreg:QI
1432 (plus:SI (match_operand:SI 1 "register_operand" "d")
1433 (match_operand:SI 2 "register_operand" "d")) 3)))]
1434 "ISA_HAS_BADDU && BYTES_BIG_ENDIAN"
1435 "baddu\\t%0,%1,%2"
1436 [(set_attr "alu_type" "add")])
1437
1438 (define_insn "*baddu_si_el"
1439 [(set (match_operand:SI 0 "register_operand" "=d")
1440 (zero_extend:SI
1441 (subreg:QI
1442 (plus:SI (match_operand:SI 1 "register_operand" "d")
1443 (match_operand:SI 2 "register_operand" "d")) 0)))]
1444 "ISA_HAS_BADDU && !BYTES_BIG_ENDIAN"
1445 "baddu\\t%0,%1,%2"
1446 [(set_attr "alu_type" "add")])
1447
1448 (define_insn "*baddu_di<mode>"
1449 [(set (match_operand:GPR 0 "register_operand" "=d")
1450 (zero_extend:GPR
1451 (truncate:QI
1452 (plus:DI (match_operand:DI 1 "register_operand" "d")
1453 (match_operand:DI 2 "register_operand" "d")))))]
1454 "ISA_HAS_BADDU && TARGET_64BIT"
1455 "baddu\\t%0,%1,%2"
1456 [(set_attr "alu_type" "add")])
1457 \f
1458 ;;
1459 ;; ....................
1460 ;;
1461 ;; SUBTRACTION
1462 ;;
1463 ;; ....................
1464 ;;
1465
1466 (define_insn "sub<mode>3"
1467 [(set (match_operand:ANYF 0 "register_operand" "=f")
1468 (minus:ANYF (match_operand:ANYF 1 "register_operand" "f")
1469 (match_operand:ANYF 2 "register_operand" "f")))]
1470 ""
1471 "sub.<fmt>\t%0,%1,%2"
1472 [(set_attr "type" "fadd")
1473 (set_attr "mode" "<UNITMODE>")])
1474
1475 (define_insn "sub<mode>3"
1476 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
1477 (minus:GPR (match_operand:GPR 1 "register_operand" "!u,d")
1478 (match_operand:GPR 2 "register_operand" "!u,d")))]
1479 ""
1480 "<d>subu\t%0,%1,%2"
1481 [(set_attr "alu_type" "sub")
1482 (set_attr "compression" "micromips32,*")
1483 (set_attr "mode" "<MODE>")])
1484
1485 (define_insn "*subsi3_extended"
1486 [(set (match_operand:DI 0 "register_operand" "=d")
1487 (sign_extend:DI
1488 (minus:SI (match_operand:SI 1 "register_operand" "d")
1489 (match_operand:SI 2 "register_operand" "d"))))]
1490 "TARGET_64BIT"
1491 "subu\t%0,%1,%2"
1492 [(set_attr "alu_type" "sub")
1493 (set_attr "mode" "DI")])
1494 \f
1495 ;;
1496 ;; ....................
1497 ;;
1498 ;; MULTIPLICATION
1499 ;;
1500 ;; ....................
1501 ;;
1502
1503 (define_expand "mul<mode>3"
1504 [(set (match_operand:SCALARF 0 "register_operand")
1505 (mult:SCALARF (match_operand:SCALARF 1 "register_operand")
1506 (match_operand:SCALARF 2 "register_operand")))]
1507 ""
1508 "")
1509
1510 (define_insn "*mul<mode>3"
1511 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1512 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1513 (match_operand:SCALARF 2 "register_operand" "f")))]
1514 "!TARGET_4300_MUL_FIX"
1515 "mul.<fmt>\t%0,%1,%2"
1516 [(set_attr "type" "fmul")
1517 (set_attr "mode" "<MODE>")])
1518
1519 ;; Early VR4300 silicon has a CPU bug where multiplies with certain
1520 ;; operands may corrupt immediately following multiplies. This is a
1521 ;; simple fix to insert NOPs.
1522
1523 (define_insn "*mul<mode>3_r4300"
1524 [(set (match_operand:SCALARF 0 "register_operand" "=f")
1525 (mult:SCALARF (match_operand:SCALARF 1 "register_operand" "f")
1526 (match_operand:SCALARF 2 "register_operand" "f")))]
1527 "TARGET_4300_MUL_FIX"
1528 "mul.<fmt>\t%0,%1,%2\;nop"
1529 [(set_attr "type" "fmul")
1530 (set_attr "mode" "<MODE>")
1531 (set_attr "insn_count" "2")])
1532
1533 (define_insn "mulv2sf3"
1534 [(set (match_operand:V2SF 0 "register_operand" "=f")
1535 (mult:V2SF (match_operand:V2SF 1 "register_operand" "f")
1536 (match_operand:V2SF 2 "register_operand" "f")))]
1537 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
1538 "mul.ps\t%0,%1,%2"
1539 [(set_attr "type" "fmul")
1540 (set_attr "mode" "SF")])
1541
1542 ;; The original R4000 has a cpu bug. If a double-word or a variable
1543 ;; shift executes while an integer multiplication is in progress, the
1544 ;; shift may give an incorrect result. Avoid this by keeping the mflo
1545 ;; with the mult on the R4000.
1546 ;;
1547 ;; From "MIPS R4000PC/SC Errata, Processor Revision 2.2 and 3.0"
1548 ;; (also valid for MIPS R4000MC processors):
1549 ;;
1550 ;; "16. R4000PC, R4000SC: Please refer to errata 28 for an update to
1551 ;; this errata description.
1552 ;; The following code sequence causes the R4000 to incorrectly
1553 ;; execute the Double Shift Right Arithmetic 32 (dsra32)
1554 ;; instruction. If the dsra32 instruction is executed during an
1555 ;; integer multiply, the dsra32 will only shift by the amount in
1556 ;; specified in the instruction rather than the amount plus 32
1557 ;; bits.
1558 ;; instruction 1: mult rs,rt integer multiply
1559 ;; instruction 2-12: dsra32 rd,rt,rs doubleword shift
1560 ;; right arithmetic + 32
1561 ;; Workaround: A dsra32 instruction placed after an integer
1562 ;; multiply should not be one of the 11 instructions after the
1563 ;; multiply instruction."
1564 ;;
1565 ;; and:
1566 ;;
1567 ;; "28. R4000PC, R4000SC: The text from errata 16 should be replaced by
1568 ;; the following description.
1569 ;; All extended shifts (shift by n+32) and variable shifts (32 and
1570 ;; 64-bit versions) may produce incorrect results under the
1571 ;; following conditions:
1572 ;; 1) An integer multiply is currently executing
1573 ;; 2) These types of shift instructions are executed immediately
1574 ;; following an integer divide instruction.
1575 ;; Workaround:
1576 ;; 1) Make sure no integer multiply is running wihen these
1577 ;; instruction are executed. If this cannot be predicted at
1578 ;; compile time, then insert a "mfhi" to R0 instruction
1579 ;; immediately after the integer multiply instruction. This
1580 ;; will cause the integer multiply to complete before the shift
1581 ;; is executed.
1582 ;; 2) Separate integer divide and these two classes of shift
1583 ;; instructions by another instruction or a noop."
1584 ;;
1585 ;; These processors have PRId values of 0x00004220 and 0x00004300,
1586 ;; respectively.
1587
1588 (define_expand "mul<mode>3"
1589 [(set (match_operand:GPR 0 "register_operand")
1590 (mult:GPR (match_operand:GPR 1 "register_operand")
1591 (match_operand:GPR 2 "register_operand")))]
1592 "ISA_HAS_<D>MULT || ISA_HAS_R6<D>MUL"
1593 {
1594 rtx lo;
1595
1596 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL)
1597 emit_insn (gen_mul<mode>3_mul3_nohilo (operands[0], operands[1],
1598 operands[2]));
1599 else if (ISA_HAS_<D>MUL3)
1600 emit_insn (gen_mul<mode>3_mul3 (operands[0], operands[1], operands[2]));
1601 else if (TARGET_MIPS16)
1602 {
1603 lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
1604 emit_insn (gen_mul<mode>3_internal (lo, operands[1], operands[2]));
1605 emit_move_insn (operands[0], lo);
1606 }
1607 else if (TARGET_FIX_R4000)
1608 emit_insn (gen_mul<mode>3_r4000 (operands[0], operands[1], operands[2]));
1609 else
1610 emit_insn
1611 (gen_mul<mode>3_internal (operands[0], operands[1], operands[2]));
1612 DONE;
1613 })
1614
1615 (define_insn "mul<mode>3_mul3_nohilo"
1616 [(set (match_operand:GPR 0 "register_operand" "=d")
1617 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1618 (match_operand:GPR 2 "register_operand" "d")))]
1619 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>MUL"
1620 {
1621 if (TARGET_LOONGSON_2EF)
1622 return "<d>multu.g\t%0,%1,%2";
1623 else if (TARGET_LOONGSON_3A)
1624 return "gs<d>multu\t%0,%1,%2";
1625 else
1626 return "<d>mul\t%0,%1,%2";
1627 }
1628 [(set_attr "type" "imul3nc")
1629 (set_attr "mode" "<MODE>")])
1630
1631 (define_insn "mul<mode>3_mul3"
1632 [(set (match_operand:GPR 0 "register_operand" "=d,l")
1633 (mult:GPR (match_operand:GPR 1 "register_operand" "d,d")
1634 (match_operand:GPR 2 "register_operand" "d,d")))
1635 (clobber (match_scratch:GPR 3 "=l,X"))]
1636 "ISA_HAS_<D>MUL3"
1637 {
1638 if (which_alternative == 1)
1639 return "<d>mult\t%1,%2";
1640 if (<MODE>mode == SImode && (TARGET_MIPS3900 || TARGET_MIPS5900))
1641 return "mult\t%0,%1,%2";
1642 return "<d>mul\t%0,%1,%2";
1643 }
1644 [(set_attr "type" "imul3,imul")
1645 (set_attr "mode" "<MODE>")])
1646
1647 ;; If a register gets allocated to LO, and we spill to memory, the reload
1648 ;; will include a move from LO to a GPR. Merge it into the multiplication
1649 ;; if it can set the GPR directly.
1650 ;;
1651 ;; Operand 0: LO
1652 ;; Operand 1: GPR (1st multiplication operand)
1653 ;; Operand 2: GPR (2nd multiplication operand)
1654 ;; Operand 3: GPR (destination)
1655 (define_peephole2
1656 [(parallel
1657 [(set (match_operand:SI 0 "lo_operand")
1658 (mult:SI (match_operand:SI 1 "d_operand")
1659 (match_operand:SI 2 "d_operand")))
1660 (clobber (scratch:SI))])
1661 (set (match_operand:SI 3 "d_operand")
1662 (match_dup 0))]
1663 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[0])"
1664 [(parallel
1665 [(set (match_dup 3)
1666 (mult:SI (match_dup 1)
1667 (match_dup 2)))
1668 (clobber (match_dup 0))])])
1669
1670 (define_insn "mul<mode>3_internal"
1671 [(set (match_operand:GPR 0 "muldiv_target_operand" "=l")
1672 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1673 (match_operand:GPR 2 "register_operand" "d")))]
1674 "ISA_HAS_<D>MULT && !TARGET_FIX_R4000"
1675 "<d>mult\t%1,%2"
1676 [(set_attr "type" "imul")
1677 (set_attr "mode" "<MODE>")])
1678
1679 (define_insn "mul<mode>3_r4000"
1680 [(set (match_operand:GPR 0 "register_operand" "=d")
1681 (mult:GPR (match_operand:GPR 1 "register_operand" "d")
1682 (match_operand:GPR 2 "register_operand" "d")))
1683 (clobber (match_scratch:GPR 3 "=l"))]
1684 "ISA_HAS_<D>MULT && TARGET_FIX_R4000"
1685 "<d>mult\t%1,%2\;mflo\t%0"
1686 [(set_attr "type" "imul")
1687 (set_attr "mode" "<MODE>")
1688 (set_attr "insn_count" "2")])
1689
1690 ;; On the VR4120 and VR4130, it is better to use "mtlo $0; macc" instead
1691 ;; of "mult; mflo". They have the same latency, but the first form gives
1692 ;; us an extra cycle to compute the operands.
1693
1694 ;; Operand 0: LO
1695 ;; Operand 1: GPR (1st multiplication operand)
1696 ;; Operand 2: GPR (2nd multiplication operand)
1697 ;; Operand 3: GPR (destination)
1698 (define_peephole2
1699 [(set (match_operand:SI 0 "lo_operand")
1700 (mult:SI (match_operand:SI 1 "d_operand")
1701 (match_operand:SI 2 "d_operand")))
1702 (set (match_operand:SI 3 "d_operand")
1703 (match_dup 0))]
1704 "ISA_HAS_MACC && !ISA_HAS_MUL3"
1705 [(set (match_dup 0)
1706 (const_int 0))
1707 (parallel
1708 [(set (match_dup 0)
1709 (plus:SI (mult:SI (match_dup 1)
1710 (match_dup 2))
1711 (match_dup 0)))
1712 (set (match_dup 3)
1713 (plus:SI (mult:SI (match_dup 1)
1714 (match_dup 2))
1715 (match_dup 0)))])])
1716
1717 ;; Multiply-accumulate patterns
1718
1719 ;; This pattern is first matched by combine, which tries to use the
1720 ;; pattern wherever it can. We don't know until later whether it
1721 ;; is actually profitable to use MADD over a "MUL; ADDIU" sequence,
1722 ;; so we need to keep both options open.
1723 ;;
1724 ;; The second alternative has a "?" marker because it is generally
1725 ;; one instruction more costly than the first alternative. This "?"
1726 ;; marker is enough to convey the relative costs to the register
1727 ;; allocator.
1728 ;;
1729 ;; However, reload counts reloads of operands 4 and 5 in the same way as
1730 ;; reloads of the other operands, even though operands 4 and 5 need no
1731 ;; copy instructions. Reload therefore thinks that the second alternative
1732 ;; is two reloads more costly than the first. We add "*?*?" to the first
1733 ;; alternative as a counterweight.
1734 ;;
1735 ;; LRA simulates reload but the cost of reloading scratches is lower
1736 ;; than of the classic reload. For the time being, removing the counterweight
1737 ;; for LRA is more profitable.
1738 (define_insn "*mul_acc_si"
1739 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1740 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d")
1741 (match_operand:SI 2 "register_operand" "d,d,d"))
1742 (match_operand:SI 3 "register_operand" "0,0,d")))
1743 (clobber (match_scratch:SI 4 "=X,X,l"))
1744 (clobber (match_scratch:SI 5 "=X,X,&d"))]
1745 "GENERATE_MADD_MSUB && !TARGET_MIPS16"
1746 "@
1747 madd\t%1,%2
1748 madd\t%1,%2
1749 #"
1750 [(set_attr "type" "imadd")
1751 (set_attr "accum_in" "3")
1752 (set_attr "mode" "SI")
1753 (set_attr "insn_count" "1,1,2")
1754 (set (attr "enabled")
1755 (cond [(and (eq_attr "alternative" "0")
1756 (match_test "!mips_lra_flag"))
1757 (const_string "yes")
1758 (and (eq_attr "alternative" "1")
1759 (match_test "mips_lra_flag"))
1760 (const_string "yes")
1761 (eq_attr "alternative" "2")
1762 (const_string "yes")]
1763 (const_string "no")))])
1764
1765 ;; The same idea applies here. The middle alternative needs one less
1766 ;; clobber than the final alternative, so we add "*?" as a counterweight.
1767 (define_insn "*mul_acc_si_r3900"
1768 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d*?,d?")
1769 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d,d,d")
1770 (match_operand:SI 2 "register_operand" "d,d,d,d"))
1771 (match_operand:SI 3 "register_operand" "0,0,l,d")))
1772 (clobber (match_scratch:SI 4 "=X,X,3,l"))
1773 (clobber (match_scratch:SI 5 "=X,X,X,&d"))]
1774 "TARGET_MIPS3900 && !TARGET_MIPS16"
1775 "@
1776 madd\t%1,%2
1777 madd\t%1,%2
1778 madd\t%0,%1,%2
1779 #"
1780 [(set_attr "type" "imadd")
1781 (set_attr "accum_in" "3")
1782 (set_attr "mode" "SI")
1783 (set_attr "insn_count" "1,1,1,2")
1784 (set (attr "enabled")
1785 (cond [(and (eq_attr "alternative" "0")
1786 (match_test "!mips_lra_flag"))
1787 (const_string "yes")
1788 (and (eq_attr "alternative" "1")
1789 (match_test "mips_lra_flag"))
1790 (const_string "yes")
1791 (eq_attr "alternative" "2,3")
1792 (const_string "yes")]
1793 (const_string "no")))])
1794
1795 ;; Split *mul_acc_si if both the source and destination accumulator
1796 ;; values are GPRs.
1797 (define_split
1798 [(set (match_operand:SI 0 "d_operand")
1799 (plus:SI (mult:SI (match_operand:SI 1 "d_operand")
1800 (match_operand:SI 2 "d_operand"))
1801 (match_operand:SI 3 "d_operand")))
1802 (clobber (match_operand:SI 4 "lo_operand"))
1803 (clobber (match_operand:SI 5 "d_operand"))]
1804 "reload_completed"
1805 [(parallel [(set (match_dup 5)
1806 (mult:SI (match_dup 1) (match_dup 2)))
1807 (clobber (match_dup 4))])
1808 (set (match_dup 0) (plus:SI (match_dup 5) (match_dup 3)))]
1809 "")
1810
1811 (define_insn "*macc"
1812 [(set (match_operand:SI 0 "register_operand" "=l,d")
1813 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
1814 (match_operand:SI 2 "register_operand" "d,d"))
1815 (match_operand:SI 3 "register_operand" "0,l")))
1816 (clobber (match_scratch:SI 4 "=X,3"))]
1817 "ISA_HAS_MACC"
1818 {
1819 if (which_alternative == 1)
1820 return "macc\t%0,%1,%2";
1821 else if (TARGET_MIPS5500)
1822 return "madd\t%1,%2";
1823 else
1824 /* The VR4130 assumes that there is a two-cycle latency between a macc
1825 that "writes" to $0 and an instruction that reads from it. We avoid
1826 this by assigning to $1 instead. */
1827 return "%[macc\t%@,%1,%2%]";
1828 }
1829 [(set_attr "type" "imadd")
1830 (set_attr "accum_in" "3")
1831 (set_attr "mode" "SI")])
1832
1833 (define_insn "*msac"
1834 [(set (match_operand:SI 0 "register_operand" "=l,d")
1835 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1836 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1837 (match_operand:SI 3 "register_operand" "d,d"))))
1838 (clobber (match_scratch:SI 4 "=X,1"))]
1839 "ISA_HAS_MSAC"
1840 {
1841 if (which_alternative == 1)
1842 return "msac\t%0,%2,%3";
1843 else if (TARGET_MIPS5500)
1844 return "msub\t%2,%3";
1845 else
1846 return "msac\t$0,%2,%3";
1847 }
1848 [(set_attr "type" "imadd")
1849 (set_attr "accum_in" "1")
1850 (set_attr "mode" "SI")])
1851
1852 ;; An msac-like instruction implemented using negation and a macc.
1853 (define_insn_and_split "*msac_using_macc"
1854 [(set (match_operand:SI 0 "register_operand" "=l,d")
1855 (minus:SI (match_operand:SI 1 "register_operand" "0,l")
1856 (mult:SI (match_operand:SI 2 "register_operand" "d,d")
1857 (match_operand:SI 3 "register_operand" "d,d"))))
1858 (clobber (match_scratch:SI 4 "=X,1"))
1859 (clobber (match_scratch:SI 5 "=d,d"))]
1860 "ISA_HAS_MACC && !ISA_HAS_MSAC"
1861 "#"
1862 "&& reload_completed"
1863 [(set (match_dup 5)
1864 (neg:SI (match_dup 3)))
1865 (parallel
1866 [(set (match_dup 0)
1867 (plus:SI (mult:SI (match_dup 2)
1868 (match_dup 5))
1869 (match_dup 1)))
1870 (clobber (match_dup 4))])]
1871 ""
1872 [(set_attr "type" "imadd")
1873 (set_attr "accum_in" "1")
1874 (set_attr "insn_count" "2")])
1875
1876 ;; Patterns generated by the define_peephole2 below.
1877
1878 (define_insn "*macc2"
1879 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1880 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
1881 (match_operand:SI 2 "register_operand" "d"))
1882 (match_dup 0)))
1883 (set (match_operand:SI 3 "register_operand" "=d")
1884 (plus:SI (mult:SI (match_dup 1)
1885 (match_dup 2))
1886 (match_dup 0)))]
1887 "ISA_HAS_MACC && reload_completed"
1888 "macc\t%3,%1,%2"
1889 [(set_attr "type" "imadd")
1890 (set_attr "accum_in" "0")
1891 (set_attr "mode" "SI")])
1892
1893 (define_insn "*msac2"
1894 [(set (match_operand:SI 0 "muldiv_target_operand" "=l")
1895 (minus:SI (match_dup 0)
1896 (mult:SI (match_operand:SI 1 "register_operand" "d")
1897 (match_operand:SI 2 "register_operand" "d"))))
1898 (set (match_operand:SI 3 "register_operand" "=d")
1899 (minus:SI (match_dup 0)
1900 (mult:SI (match_dup 1)
1901 (match_dup 2))))]
1902 "ISA_HAS_MSAC && reload_completed"
1903 "msac\t%3,%1,%2"
1904 [(set_attr "type" "imadd")
1905 (set_attr "accum_in" "0")
1906 (set_attr "mode" "SI")])
1907
1908 ;; Convert macc $0,<r1>,<r2> & mflo <r3> into macc <r3>,<r1>,<r2>
1909 ;; Similarly msac.
1910 ;;
1911 ;; Operand 0: LO
1912 ;; Operand 1: macc/msac
1913 ;; Operand 2: GPR (destination)
1914 (define_peephole2
1915 [(parallel
1916 [(set (match_operand:SI 0 "lo_operand")
1917 (match_operand:SI 1 "macc_msac_operand"))
1918 (clobber (scratch:SI))])
1919 (set (match_operand:SI 2 "d_operand")
1920 (match_dup 0))]
1921 ""
1922 [(parallel [(set (match_dup 0)
1923 (match_dup 1))
1924 (set (match_dup 2)
1925 (match_dup 1))])])
1926
1927 ;; When we have a three-address multiplication instruction, it should
1928 ;; be faster to do a separate multiply and add, rather than moving
1929 ;; something into LO in order to use a macc instruction.
1930 ;;
1931 ;; This peephole needs a scratch register to cater for the case when one
1932 ;; of the multiplication operands is the same as the destination.
1933 ;;
1934 ;; Operand 0: GPR (scratch)
1935 ;; Operand 1: LO
1936 ;; Operand 2: GPR (addend)
1937 ;; Operand 3: GPR (destination)
1938 ;; Operand 4: macc/msac
1939 ;; Operand 5: new multiplication
1940 ;; Operand 6: new addition/subtraction
1941 (define_peephole2
1942 [(match_scratch:SI 0 "d")
1943 (set (match_operand:SI 1 "lo_operand")
1944 (match_operand:SI 2 "d_operand"))
1945 (match_dup 0)
1946 (parallel
1947 [(set (match_operand:SI 3 "d_operand")
1948 (match_operand:SI 4 "macc_msac_operand"))
1949 (clobber (match_dup 1))])]
1950 "ISA_HAS_MUL3 && peep2_reg_dead_p (2, operands[1])"
1951 [(parallel [(set (match_dup 0)
1952 (match_dup 5))
1953 (clobber (match_dup 1))])
1954 (set (match_dup 3)
1955 (match_dup 6))]
1956 {
1957 operands[5] = XEXP (operands[4], GET_CODE (operands[4]) == PLUS ? 0 : 1);
1958 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[4]), SImode,
1959 operands[2], operands[0]);
1960 })
1961
1962 ;; Same as above, except LO is the initial target of the macc.
1963 ;;
1964 ;; Operand 0: GPR (scratch)
1965 ;; Operand 1: LO
1966 ;; Operand 2: GPR (addend)
1967 ;; Operand 3: macc/msac
1968 ;; Operand 4: GPR (destination)
1969 ;; Operand 5: new multiplication
1970 ;; Operand 6: new addition/subtraction
1971 (define_peephole2
1972 [(match_scratch:SI 0 "d")
1973 (set (match_operand:SI 1 "lo_operand")
1974 (match_operand:SI 2 "d_operand"))
1975 (match_dup 0)
1976 (parallel
1977 [(set (match_dup 1)
1978 (match_operand:SI 3 "macc_msac_operand"))
1979 (clobber (scratch:SI))])
1980 (match_dup 0)
1981 (set (match_operand:SI 4 "d_operand")
1982 (match_dup 1))]
1983 "ISA_HAS_MUL3 && peep2_reg_dead_p (3, operands[1])"
1984 [(parallel [(set (match_dup 0)
1985 (match_dup 5))
1986 (clobber (match_dup 1))])
1987 (set (match_dup 4)
1988 (match_dup 6))]
1989 {
1990 operands[5] = XEXP (operands[3], GET_CODE (operands[3]) == PLUS ? 0 : 1);
1991 operands[6] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
1992 operands[2], operands[0]);
1993 })
1994
1995 ;; See the comment above *mul_add_si for details.
1996 (define_insn "*mul_sub_si"
1997 [(set (match_operand:SI 0 "register_operand" "=l*?*?,l,d?")
1998 (minus:SI (match_operand:SI 1 "register_operand" "0,0,d")
1999 (mult:SI (match_operand:SI 2 "register_operand" "d,d,d")
2000 (match_operand:SI 3 "register_operand" "d,d,d"))))
2001 (clobber (match_scratch:SI 4 "=X,X,l"))
2002 (clobber (match_scratch:SI 5 "=X,X,&d"))]
2003 "GENERATE_MADD_MSUB"
2004 "@
2005 msub\t%2,%3
2006 msub\t%2,%3
2007 #"
2008 [(set_attr "type" "imadd")
2009 (set_attr "accum_in" "1")
2010 (set_attr "mode" "SI")
2011 (set_attr "insn_count" "1,1,2")
2012 (set (attr "enabled")
2013 (cond [(and (eq_attr "alternative" "0")
2014 (match_test "!mips_lra_flag"))
2015 (const_string "yes")
2016 (and (eq_attr "alternative" "1")
2017 (match_test "mips_lra_flag"))
2018 (const_string "yes")
2019 (eq_attr "alternative" "2")
2020 (const_string "yes")]
2021 (const_string "no")))])
2022
2023 ;; Split *mul_sub_si if both the source and destination accumulator
2024 ;; values are GPRs.
2025 (define_split
2026 [(set (match_operand:SI 0 "d_operand")
2027 (minus:SI (match_operand:SI 1 "d_operand")
2028 (mult:SI (match_operand:SI 2 "d_operand")
2029 (match_operand:SI 3 "d_operand"))))
2030 (clobber (match_operand:SI 4 "lo_operand"))
2031 (clobber (match_operand:SI 5 "d_operand"))]
2032 "reload_completed"
2033 [(parallel [(set (match_dup 5)
2034 (mult:SI (match_dup 2) (match_dup 3)))
2035 (clobber (match_dup 4))])
2036 (set (match_dup 0) (minus:SI (match_dup 1) (match_dup 5)))]
2037 "")
2038
2039 (define_insn "*muls"
2040 [(set (match_operand:SI 0 "register_operand" "=l,d")
2041 (neg:SI (mult:SI (match_operand:SI 1 "register_operand" "d,d")
2042 (match_operand:SI 2 "register_operand" "d,d"))))
2043 (clobber (match_scratch:SI 3 "=X,l"))]
2044 "ISA_HAS_MULS"
2045 "@
2046 muls\t$0,%1,%2
2047 muls\t%0,%1,%2"
2048 [(set_attr "type" "imul,imul3")
2049 (set_attr "mode" "SI")])
2050
2051 (define_expand "<u>mulsidi3"
2052 [(set (match_operand:DI 0 "register_operand")
2053 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2054 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2055 "mips_mulsidi3_gen_fn (<CODE>) != NULL"
2056 {
2057 mulsidi3_gen_fn fn = mips_mulsidi3_gen_fn (<CODE>);
2058 emit_insn (fn (operands[0], operands[1], operands[2]));
2059 DONE;
2060 })
2061
2062 (define_expand "<u>mulsidi3_32bit_r6"
2063 [(set (match_operand:DI 0 "register_operand")
2064 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2065 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2066 "!TARGET_64BIT && ISA_HAS_R6MUL"
2067 {
2068 rtx dest = gen_reg_rtx (DImode);
2069 rtx low = mips_subword (dest, 0);
2070 rtx high = mips_subword (dest, 1);
2071
2072 emit_insn (gen_mulsi3_mul3_nohilo (low, operands[1], operands[2]));
2073 emit_insn (gen_<su>mulsi3_highpart_r6 (high, operands[1], operands[2]));
2074
2075 emit_move_insn (mips_subword (operands[0], 0), low);
2076 emit_move_insn (mips_subword (operands[0], 1), high);
2077 DONE;
2078 })
2079
2080 (define_expand "<u>mulsidi3_32bit_mips16"
2081 [(set (match_operand:DI 0 "register_operand")
2082 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2083 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2084 "!TARGET_64BIT && TARGET_MIPS16"
2085 {
2086 rtx hilo;
2087
2088 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2089 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2090 emit_move_insn (operands[0], hilo);
2091 DONE;
2092 })
2093
2094 ;; As well as being named patterns, these instructions are used by the
2095 ;; __builtin_mips_mult<u>() functions. We must always make those functions
2096 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2097 (define_insn "<u>mulsidi3_32bit"
2098 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2099 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2100 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2101 "!TARGET_64BIT && (!TARGET_FIX_R4000 || ISA_HAS_DSP) && ISA_HAS_MULT"
2102 {
2103 if (ISA_HAS_DSP_MULT)
2104 return "mult<u>\t%q0,%1,%2";
2105 else
2106 return "mult<u>\t%1,%2";
2107 }
2108 [(set_attr "type" "imul")
2109 (set_attr "mode" "SI")])
2110
2111 (define_insn "<u>mulsidi3_32bit_r4000"
2112 [(set (match_operand:DI 0 "register_operand" "=d")
2113 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2114 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2115 (clobber (match_scratch:DI 3 "=x"))]
2116 "!TARGET_64BIT && TARGET_FIX_R4000 && !ISA_HAS_DSP && ISA_HAS_MULT"
2117 "mult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2118 [(set_attr "type" "imul")
2119 (set_attr "mode" "SI")
2120 (set_attr "insn_count" "3")])
2121
2122 (define_insn_and_split "<u>mulsidi3_64bit"
2123 [(set (match_operand:DI 0 "register_operand" "=d")
2124 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2125 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2126 (clobber (match_scratch:TI 3 "=x"))
2127 (clobber (match_scratch:DI 4 "=d"))]
2128 "TARGET_64BIT && !TARGET_FIX_R4000 && !ISA_HAS_DMUL3
2129 && !TARGET_MIPS16 && ISA_HAS_MULT"
2130 "#"
2131 "&& reload_completed"
2132 [(const_int 0)]
2133 {
2134 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2135 operands[2], operands[4]));
2136 DONE;
2137 }
2138 [(set_attr "type" "imul")
2139 (set_attr "mode" "SI")
2140 (set (attr "insn_count")
2141 (if_then_else (match_test "ISA_HAS_EXT_INS")
2142 (const_int 4)
2143 (const_int 7)))])
2144
2145 (define_expand "<u>mulsidi3_64bit_mips16"
2146 [(set (match_operand:DI 0 "register_operand")
2147 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2148 (any_extend:DI (match_operand:SI 2 "register_operand"))))]
2149 "TARGET_64BIT && TARGET_MIPS16"
2150 {
2151 emit_insn (gen_<u>mulsidi3_64bit_split (operands[0], operands[1],
2152 operands[2], gen_reg_rtx (DImode)));
2153 DONE;
2154 })
2155
2156 (define_expand "<u>mulsidi3_64bit_split"
2157 [(set (match_operand:DI 0 "register_operand")
2158 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2159 (any_extend:DI (match_operand:SI 2 "register_operand"))))
2160 (clobber (match_operand:DI 3 "register_operand"))]
2161 ""
2162 {
2163 rtx hilo;
2164
2165 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2166 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2167
2168 emit_move_insn (operands[0], gen_rtx_REG (DImode, LO_REGNUM));
2169 emit_insn (gen_mfhidi_ti (operands[3], hilo));
2170
2171 if (ISA_HAS_EXT_INS)
2172 emit_insn (gen_insvdi (operands[0], GEN_INT (32), GEN_INT (32),
2173 operands[3]));
2174 else
2175 {
2176 /* Zero-extend the low part. */
2177 mips_emit_binary (ASHIFT, operands[0], operands[0], GEN_INT (32));
2178 mips_emit_binary (LSHIFTRT, operands[0], operands[0], GEN_INT (32));
2179
2180 /* Shift the high part into place. */
2181 mips_emit_binary (ASHIFT, operands[3], operands[3], GEN_INT (32));
2182
2183 /* OR the two halves together. */
2184 mips_emit_binary (IOR, operands[0], operands[0], operands[3]);
2185 }
2186 DONE;
2187 })
2188
2189 (define_insn "<u>mulsidi3_64bit_hilo"
2190 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2191 (unspec:TI
2192 [(mult:DI
2193 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2194 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))]
2195 UNSPEC_SET_HILO))]
2196 "TARGET_64BIT && !TARGET_FIX_R4000"
2197 "mult<u>\t%1,%2"
2198 [(set_attr "type" "imul")
2199 (set_attr "mode" "SI")])
2200
2201 ;; See comment before the ISA_HAS_DMUL3 case in mips_mulsidi3_gen_fn.
2202 (define_insn "mulsidi3_64bit_dmul"
2203 [(set (match_operand:DI 0 "register_operand" "=d")
2204 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2205 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2206 (clobber (match_scratch:DI 3 "=l"))]
2207 "ISA_HAS_DMUL3"
2208 "dmul\t%0,%1,%2"
2209 [(set_attr "type" "imul3")
2210 (set_attr "mode" "DI")])
2211
2212 (define_insn "mulsidi3_64bit_r6dmul"
2213 [(set (match_operand:DI 0 "register_operand" "=d")
2214 (mult:DI (sign_extend:DI (match_operand:SI 1 "register_operand" "d"))
2215 (sign_extend:DI (match_operand:SI 2 "register_operand" "d"))))]
2216 "ISA_HAS_R6DMUL"
2217 "dmul\t%0,%1,%2"
2218 [(set_attr "type" "imul3nc")
2219 (set_attr "mode" "DI")])
2220
2221 ;; Widening multiply with negation.
2222 (define_insn "*muls<u>_di"
2223 [(set (match_operand:DI 0 "muldiv_target_operand" "=x")
2224 (neg:DI
2225 (mult:DI
2226 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2227 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2228 "!TARGET_64BIT && ISA_HAS_MULS"
2229 "muls<u>\t$0,%1,%2"
2230 [(set_attr "type" "imul")
2231 (set_attr "mode" "SI")])
2232
2233 ;; As well as being named patterns, these instructions are used by the
2234 ;; __builtin_mips_msub<u>() functions. We must always make those functions
2235 ;; available if !TARGET_64BIT && ISA_HAS_DSP.
2236 ;;
2237 ;; This leads to a slight inconsistency. We honor any tuning overrides
2238 ;; in GENERATE_MADD_MSUB for -mno-dsp, but always ignore them for -mdsp,
2239 ;; even if !ISA_HAS_DSP_MULT.
2240 (define_insn "<u>msubsidi4"
2241 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2242 (minus:DI
2243 (match_operand:DI 3 "muldiv_target_operand" "0")
2244 (mult:DI
2245 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2246 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))))]
2247 "!TARGET_64BIT && (ISA_HAS_MSAC || GENERATE_MADD_MSUB || ISA_HAS_DSP)"
2248 {
2249 if (ISA_HAS_DSP_MULT)
2250 return "msub<u>\t%q0,%1,%2";
2251 else if (TARGET_MIPS5500 || GENERATE_MADD_MSUB)
2252 return "msub<u>\t%1,%2";
2253 else
2254 return "msac<u>\t$0,%1,%2";
2255 }
2256 [(set_attr "type" "imadd")
2257 (set_attr "accum_in" "3")
2258 (set_attr "mode" "SI")])
2259
2260 ;; _highpart patterns
2261
2262 (define_expand "<su>mulsi3_highpart"
2263 [(set (match_operand:SI 0 "register_operand")
2264 (truncate:SI
2265 (lshiftrt:DI
2266 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2267 (any_extend:DI (match_operand:SI 2 "register_operand")))
2268 (const_int 32))))]
2269 ""
2270 {
2271 if (ISA_HAS_MULHI)
2272 emit_insn (gen_<su>mulsi3_highpart_mulhi_internal (operands[0],
2273 operands[1],
2274 operands[2]));
2275 else if (TARGET_MIPS16)
2276 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2277 operands[2]));
2278 else if (ISA_HAS_R6MUL)
2279 emit_insn (gen_<su>mulsi3_highpart_r6 (operands[0], operands[1],
2280 operands[2]));
2281 else
2282 emit_insn (gen_<su>mulsi3_highpart_internal (operands[0], operands[1],
2283 operands[2]));
2284 DONE;
2285 })
2286
2287 (define_insn "<su>mulsi3_highpart_r6"
2288 [(set (match_operand:SI 0 "register_operand" "=d")
2289 (truncate:SI
2290 (lshiftrt:DI
2291 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2292 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2293 (const_int 32))))]
2294 "ISA_HAS_R6MUL"
2295 "muh<u>\t%0,%1,%2"
2296 [(set_attr "type" "imul3nc")
2297 (set_attr "mode" "SI")])
2298
2299 (define_insn_and_split "<su>mulsi3_highpart_internal"
2300 [(set (match_operand:SI 0 "register_operand" "=d")
2301 (truncate:SI
2302 (lshiftrt:DI
2303 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2304 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2305 (const_int 32))))
2306 (clobber (match_scratch:SI 3 "=l"))]
2307 "ISA_HAS_MULT && !ISA_HAS_MULHI && !TARGET_MIPS16"
2308 { return TARGET_FIX_R4000 ? "mult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2309 "&& reload_completed && !TARGET_FIX_R4000"
2310 [(const_int 0)]
2311 {
2312 emit_insn (gen_<su>mulsi3_highpart_split (operands[0], operands[1],
2313 operands[2]));
2314 DONE;
2315 }
2316 [(set_attr "type" "imul")
2317 (set_attr "mode" "SI")
2318 (set_attr "insn_count" "2")])
2319
2320 (define_expand "<su>mulsi3_highpart_split"
2321 [(set (match_operand:SI 0 "register_operand")
2322 (truncate:SI
2323 (lshiftrt:DI
2324 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand"))
2325 (any_extend:DI (match_operand:SI 2 "register_operand")))
2326 (const_int 32))))]
2327 ""
2328 {
2329 rtx hilo;
2330
2331 if (TARGET_64BIT)
2332 {
2333 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2334 emit_insn (gen_<u>mulsidi3_64bit_hilo (hilo, operands[1], operands[2]));
2335 emit_insn (gen_mfhisi_ti (operands[0], hilo));
2336 }
2337 else
2338 {
2339 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2340 emit_insn (gen_<u>mulsidi3_32bit (hilo, operands[1], operands[2]));
2341 emit_insn (gen_mfhisi_di (operands[0], hilo));
2342 }
2343 DONE;
2344 })
2345
2346 (define_insn "<su>mulsi3_highpart_mulhi_internal"
2347 [(set (match_operand:SI 0 "register_operand" "=d")
2348 (truncate:SI
2349 (lshiftrt:DI
2350 (mult:DI
2351 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2352 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2353 (const_int 32))))
2354 (clobber (match_scratch:SI 3 "=l"))]
2355 "ISA_HAS_MULHI"
2356 "mulhi<u>\t%0,%1,%2"
2357 [(set_attr "type" "imul3")
2358 (set_attr "mode" "SI")])
2359
2360 (define_insn "*<su>mulsi3_highpart_neg_mulhi_internal"
2361 [(set (match_operand:SI 0 "register_operand" "=d")
2362 (truncate:SI
2363 (lshiftrt:DI
2364 (neg:DI
2365 (mult:DI
2366 (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2367 (any_extend:DI (match_operand:SI 2 "register_operand" "d"))))
2368 (const_int 32))))
2369 (clobber (match_scratch:SI 3 "=l"))]
2370 "ISA_HAS_MULHI"
2371 "mulshi<u>\t%0,%1,%2"
2372 [(set_attr "type" "imul3")
2373 (set_attr "mode" "SI")])
2374
2375 ;; Disable unsigned multiplication for -mfix-vr4120. This is for VR4120
2376 ;; errata MD(0), which says that dmultu does not always produce the
2377 ;; correct result.
2378 (define_expand "<su>muldi3_highpart"
2379 [(set (match_operand:DI 0 "register_operand")
2380 (truncate:DI
2381 (lshiftrt:TI
2382 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2383 (any_extend:TI (match_operand:DI 2 "register_operand")))
2384 (const_int 64))))]
2385 "ISA_HAS_R6DMUL
2386 || (ISA_HAS_DMULT
2387 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120))"
2388 {
2389 if (TARGET_MIPS16)
2390 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2391 operands[2]));
2392 else if (ISA_HAS_R6DMUL)
2393 emit_insn (gen_<su>muldi3_highpart_r6 (operands[0], operands[1],
2394 operands[2]));
2395 else
2396 emit_insn (gen_<su>muldi3_highpart_internal (operands[0], operands[1],
2397 operands[2]));
2398 DONE;
2399 })
2400
2401 (define_insn "<su>muldi3_highpart_r6"
2402 [(set (match_operand:DI 0 "register_operand" "=d")
2403 (truncate:DI
2404 (lshiftrt:TI
2405 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2406 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2407 (const_int 64))))]
2408 "ISA_HAS_R6DMUL"
2409 "dmuh<u>\t%0,%1,%2"
2410 [(set_attr "type" "imul3nc")
2411 (set_attr "mode" "DI")])
2412
2413 (define_insn_and_split "<su>muldi3_highpart_internal"
2414 [(set (match_operand:DI 0 "register_operand" "=d")
2415 (truncate:DI
2416 (lshiftrt:TI
2417 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2418 (any_extend:TI (match_operand:DI 2 "register_operand" "d")))
2419 (const_int 64))))
2420 (clobber (match_scratch:DI 3 "=l"))]
2421 "ISA_HAS_DMULT
2422 && !TARGET_MIPS16
2423 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2424 { return TARGET_FIX_R4000 ? "dmult<u>\t%1,%2\n\tmfhi\t%0" : "#"; }
2425 "&& reload_completed && !TARGET_FIX_R4000"
2426 [(const_int 0)]
2427 {
2428 emit_insn (gen_<su>muldi3_highpart_split (operands[0], operands[1],
2429 operands[2]));
2430 DONE;
2431 }
2432 [(set_attr "type" "imul")
2433 (set_attr "mode" "DI")
2434 (set_attr "insn_count" "2")])
2435
2436 (define_expand "<su>muldi3_highpart_split"
2437 [(set (match_operand:DI 0 "register_operand")
2438 (truncate:DI
2439 (lshiftrt:TI
2440 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2441 (any_extend:TI (match_operand:DI 2 "register_operand")))
2442 (const_int 64))))]
2443 ""
2444 {
2445 rtx hilo;
2446
2447 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2448 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2449 emit_insn (gen_mfhidi_ti (operands[0], hilo));
2450 DONE;
2451 })
2452
2453 (define_expand "<u>mulditi3"
2454 [(set (match_operand:TI 0 "register_operand")
2455 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand"))
2456 (any_extend:TI (match_operand:DI 2 "register_operand"))))]
2457 "ISA_HAS_DMULT && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2458 {
2459 rtx hilo;
2460
2461 if (TARGET_MIPS16)
2462 {
2463 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2464 emit_insn (gen_<u>mulditi3_internal (hilo, operands[1], operands[2]));
2465 emit_move_insn (operands[0], hilo);
2466 }
2467 else if (TARGET_FIX_R4000)
2468 emit_insn (gen_<u>mulditi3_r4000 (operands[0], operands[1], operands[2]));
2469 else
2470 emit_insn (gen_<u>mulditi3_internal (operands[0], operands[1],
2471 operands[2]));
2472 DONE;
2473 })
2474
2475 (define_insn "<u>mulditi3_internal"
2476 [(set (match_operand:TI 0 "muldiv_target_operand" "=x")
2477 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2478 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))]
2479 "ISA_HAS_DMULT
2480 && !TARGET_FIX_R4000
2481 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2482 "dmult<u>\t%1,%2"
2483 [(set_attr "type" "imul")
2484 (set_attr "mode" "DI")])
2485
2486 (define_insn "<u>mulditi3_r4000"
2487 [(set (match_operand:TI 0 "register_operand" "=d")
2488 (mult:TI (any_extend:TI (match_operand:DI 1 "register_operand" "d"))
2489 (any_extend:TI (match_operand:DI 2 "register_operand" "d"))))
2490 (clobber (match_scratch:TI 3 "=x"))]
2491 "ISA_HAS_DMULT
2492 && TARGET_FIX_R4000
2493 && !(<CODE> == ZERO_EXTEND && TARGET_FIX_VR4120)"
2494 "dmult<u>\t%1,%2\;mflo\t%L0\;mfhi\t%M0"
2495 [(set_attr "type" "imul")
2496 (set_attr "mode" "DI")
2497 (set_attr "insn_count" "3")])
2498
2499 ;; The R4650 supports a 32-bit multiply/ 64-bit accumulate
2500 ;; instruction. The HI/LO registers are used as a 64-bit accumulator.
2501
2502 (define_insn "madsi"
2503 [(set (match_operand:SI 0 "register_operand" "+l")
2504 (plus:SI (mult:SI (match_operand:SI 1 "register_operand" "d")
2505 (match_operand:SI 2 "register_operand" "d"))
2506 (match_dup 0)))]
2507 "TARGET_MAD"
2508 "mad\t%1,%2"
2509 [(set_attr "type" "imadd")
2510 (set_attr "accum_in" "0")
2511 (set_attr "mode" "SI")])
2512
2513 ;; See the comment above <u>msubsidi4 for the relationship between
2514 ;; ISA_HAS_DSP and ISA_HAS_DSP_MULT.
2515 (define_insn "<u>maddsidi4"
2516 [(set (match_operand:DI 0 "muldiv_target_operand" "=ka")
2517 (plus:DI
2518 (mult:DI (any_extend:DI (match_operand:SI 1 "register_operand" "d"))
2519 (any_extend:DI (match_operand:SI 2 "register_operand" "d")))
2520 (match_operand:DI 3 "muldiv_target_operand" "0")))]
2521 "(TARGET_MAD || ISA_HAS_MACC || GENERATE_MADD_MSUB || ISA_HAS_DSP)
2522 && !TARGET_64BIT"
2523 {
2524 if (TARGET_MAD)
2525 return "mad<u>\t%1,%2";
2526 else if (ISA_HAS_DSP_MULT)
2527 return "madd<u>\t%q0,%1,%2";
2528 else if (GENERATE_MADD_MSUB || TARGET_MIPS5500)
2529 return "madd<u>\t%1,%2";
2530 else
2531 /* See comment in *macc. */
2532 return "%[macc<u>\t%@,%1,%2%]";
2533 }
2534 [(set_attr "type" "imadd")
2535 (set_attr "accum_in" "3")
2536 (set_attr "mode" "SI")])
2537
2538 ;; Floating point multiply accumulate instructions.
2539
2540 (define_expand "fma<mode>4"
2541 [(set (match_operand:ANYF 0 "register_operand")
2542 (fma:ANYF (match_operand:ANYF 1 "register_operand")
2543 (match_operand:ANYF 2 "register_operand")
2544 (match_operand:ANYF 3 "register_operand")))]
2545 "ISA_HAS_FUSED_MADDF || ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4")
2546
2547 (define_insn "*fma<mode>4_madd3"
2548 [(set (match_operand:ANYF 0 "register_operand" "=f")
2549 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2550 (match_operand:ANYF 2 "register_operand" "f")
2551 (match_operand:ANYF 3 "register_operand" "0")))]
2552 "ISA_HAS_FUSED_MADD3"
2553 "madd.<fmt>\t%0,%1,%2"
2554 [(set_attr "type" "fmadd")
2555 (set_attr "mode" "<UNITMODE>")])
2556
2557 (define_insn "*fma<mode>4_madd4"
2558 [(set (match_operand:ANYF 0 "register_operand" "=f")
2559 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2560 (match_operand:ANYF 2 "register_operand" "f")
2561 (match_operand:ANYF 3 "register_operand" "f")))]
2562 "ISA_HAS_FUSED_MADD4"
2563 "madd.<fmt>\t%0,%3,%1,%2"
2564 [(set_attr "type" "fmadd")
2565 (set_attr "mode" "<UNITMODE>")])
2566
2567 (define_insn "*fma<mode>4_maddf"
2568 [(set (match_operand:ANYF 0 "register_operand" "=f")
2569 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2570 (match_operand:ANYF 2 "register_operand" "f")
2571 (match_operand:ANYF 3 "register_operand" "0")))]
2572 "ISA_HAS_FUSED_MADDF"
2573 "maddf.<fmt>\t%0,%1,%2"
2574 [(set_attr "type" "fmadd")
2575 (set_attr "mode" "<UNITMODE>")])
2576
2577 ;; The fms, fnma, and fnms instructions can be used even when HONOR_NANS
2578 ;; is true because while IEEE 754-2008 requires the negate operation to
2579 ;; negate the sign of a NAN and the MIPS neg instruction does not do this,
2580 ;; the fma part of the instruction has no requirement on how the sign of
2581 ;; a NAN is handled and so the final sign bit of the entire operation is
2582 ;; undefined.
2583
2584 (define_expand "fms<mode>4"
2585 [(set (match_operand:ANYF 0 "register_operand")
2586 (fma:ANYF (match_operand:ANYF 1 "register_operand")
2587 (match_operand:ANYF 2 "register_operand")
2588 (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2589 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)")
2590
2591 (define_insn "*fms<mode>4_msub3"
2592 [(set (match_operand:ANYF 0 "register_operand" "=f")
2593 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2594 (match_operand:ANYF 2 "register_operand" "f")
2595 (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2596 "ISA_HAS_FUSED_MADD3"
2597 "msub.<fmt>\t%0,%1,%2"
2598 [(set_attr "type" "fmadd")
2599 (set_attr "mode" "<UNITMODE>")])
2600
2601 (define_insn "*fms<mode>4_msub4"
2602 [(set (match_operand:ANYF 0 "register_operand" "=f")
2603 (fma:ANYF (match_operand:ANYF 1 "register_operand" "f")
2604 (match_operand:ANYF 2 "register_operand" "f")
2605 (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2606 "ISA_HAS_FUSED_MADD4"
2607 "msub.<fmt>\t%0,%3,%1,%2"
2608 [(set_attr "type" "fmadd")
2609 (set_attr "mode" "<UNITMODE>")])
2610
2611 ;; fnma is defined in GCC as (fma (neg op1) op2 op3)
2612 ;; (-op1 * op2) + op3 ==> -(op1 * op2) + op3 ==> -((op1 * op2) - op3)
2613 ;; The mips nmsub instructions implement -((op1 * op2) - op3)
2614 ;; This transformation means we may return the wrong signed zero
2615 ;; so we check HONOR_SIGNED_ZEROS.
2616
2617 (define_expand "fnma<mode>4"
2618 [(set (match_operand:ANYF 0 "register_operand")
2619 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2620 (match_operand:ANYF 2 "register_operand")
2621 (match_operand:ANYF 3 "register_operand")))]
2622 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2623 && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2624
2625 (define_insn "*fnma<mode>4_nmsub3"
2626 [(set (match_operand:ANYF 0 "register_operand" "=f")
2627 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2628 (match_operand:ANYF 2 "register_operand" "f")
2629 (match_operand:ANYF 3 "register_operand" "0")))]
2630 "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2631 "nmsub.<fmt>\t%0,%1,%2"
2632 [(set_attr "type" "fmadd")
2633 (set_attr "mode" "<UNITMODE>")])
2634
2635 (define_insn "*fnma<mode>4_nmsub4"
2636 [(set (match_operand:ANYF 0 "register_operand" "=f")
2637 (fma:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2638 (match_operand:ANYF 2 "register_operand" "f")
2639 (match_operand:ANYF 3 "register_operand" "f")))]
2640 "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2641 "nmsub.<fmt>\t%0,%3,%1,%2"
2642 [(set_attr "type" "fmadd")
2643 (set_attr "mode" "<UNITMODE>")])
2644
2645 ;; fnms is defined as: (fma (neg op1) op2 (neg op3))
2646 ;; ((-op1) * op2) - op3 ==> -(op1 * op2) - op3 ==> -((op1 * op2) + op3)
2647 ;; The mips nmadd instructions implement -((op1 * op2) + op3)
2648 ;; This transformation means we may return the wrong signed zero
2649 ;; so we check HONOR_SIGNED_ZEROS.
2650
2651 (define_expand "fnms<mode>4"
2652 [(set (match_operand:ANYF 0 "register_operand")
2653 (fma:ANYF
2654 (neg:ANYF (match_operand:ANYF 1 "register_operand"))
2655 (match_operand:ANYF 2 "register_operand")
2656 (neg:ANYF (match_operand:ANYF 3 "register_operand"))))]
2657 "(ISA_HAS_FUSED_MADD3 || ISA_HAS_FUSED_MADD4)
2658 && !HONOR_SIGNED_ZEROS (<MODE>mode)")
2659
2660 (define_insn "*fnms<mode>4_nmadd3"
2661 [(set (match_operand:ANYF 0 "register_operand" "=f")
2662 (fma:ANYF
2663 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2664 (match_operand:ANYF 2 "register_operand" "f")
2665 (neg:ANYF (match_operand:ANYF 3 "register_operand" "0"))))]
2666 "ISA_HAS_FUSED_MADD3 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2667 "nmadd.<fmt>\t%0,%1,%2"
2668 [(set_attr "type" "fmadd")
2669 (set_attr "mode" "<UNITMODE>")])
2670
2671 (define_insn "*fnms<mode>4_nmadd4"
2672 [(set (match_operand:ANYF 0 "register_operand" "=f")
2673 (fma:ANYF
2674 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2675 (match_operand:ANYF 2 "register_operand" "f")
2676 (neg:ANYF (match_operand:ANYF 3 "register_operand" "f"))))]
2677 "ISA_HAS_FUSED_MADD4 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2678 "nmadd.<fmt>\t%0,%3,%1,%2"
2679 [(set_attr "type" "fmadd")
2680 (set_attr "mode" "<UNITMODE>")])
2681
2682 ;; Non-fused Floating point multiply accumulate instructions.
2683
2684 ;; These instructions are not fused and round in between the multiply
2685 ;; and the add (or subtract) so they are equivalent to the separate
2686 ;; multiply and add/sub instructions.
2687
2688 (define_insn "*madd4<mode>"
2689 [(set (match_operand:ANYF 0 "register_operand" "=f")
2690 (plus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2691 (match_operand:ANYF 2 "register_operand" "f"))
2692 (match_operand:ANYF 3 "register_operand" "f")))]
2693 "ISA_HAS_UNFUSED_MADD4"
2694 "madd.<fmt>\t%0,%3,%1,%2"
2695 [(set_attr "type" "fmadd")
2696 (set_attr "mode" "<UNITMODE>")])
2697
2698 (define_insn "*msub4<mode>"
2699 [(set (match_operand:ANYF 0 "register_operand" "=f")
2700 (minus:ANYF (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2701 (match_operand:ANYF 2 "register_operand" "f"))
2702 (match_operand:ANYF 3 "register_operand" "f")))]
2703 "ISA_HAS_UNFUSED_MADD4"
2704 "msub.<fmt>\t%0,%3,%1,%2"
2705 [(set_attr "type" "fmadd")
2706 (set_attr "mode" "<UNITMODE>")])
2707
2708 ;; Like with the fused fms, fnma, and fnms instructions, these unfused
2709 ;; instructions can be used even if HONOR_NANS is set because while
2710 ;; IEEE 754-2008 requires the negate operation to negate the sign of a
2711 ;; NAN and the MIPS neg instruction does not do this, the multiply and
2712 ;; add (or subtract) part of the instruction has no requirement on how
2713 ;; the sign of a NAN is handled and so the final sign bit of the entire
2714 ;; operation is undefined.
2715
2716 (define_insn "*nmadd4<mode>"
2717 [(set (match_operand:ANYF 0 "register_operand" "=f")
2718 (neg:ANYF (plus:ANYF
2719 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2720 (match_operand:ANYF 2 "register_operand" "f"))
2721 (match_operand:ANYF 3 "register_operand" "f"))))]
2722 "ISA_HAS_UNFUSED_MADD4"
2723 "nmadd.<fmt>\t%0,%3,%1,%2"
2724 [(set_attr "type" "fmadd")
2725 (set_attr "mode" "<UNITMODE>")])
2726
2727 (define_insn "*nmsub4<mode>"
2728 [(set (match_operand:ANYF 0 "register_operand" "=f")
2729 (neg:ANYF (minus:ANYF
2730 (mult:ANYF (match_operand:ANYF 1 "register_operand" "f")
2731 (match_operand:ANYF 2 "register_operand" "f"))
2732 (match_operand:ANYF 3 "register_operand" "f"))))]
2733 "ISA_HAS_UNFUSED_MADD4"
2734 "nmsub.<fmt>\t%0,%3,%1,%2"
2735 [(set_attr "type" "fmadd")
2736 (set_attr "mode" "<UNITMODE>")])
2737
2738 ;; Fast-math Non-fused Floating point multiply accumulate instructions.
2739
2740 ;; These instructions are not fused but the expressions they match are
2741 ;; not exactly what the instruction implements in the sense that they
2742 ;; may not generate the properly signed zeros.
2743
2744 ;; This instruction recognizes ((-op1) * op2) - op3 and generates an
2745 ;; nmadd which is really -((op1 * op2) + op3). They are equivalent
2746 ;; except for the sign bit when the result is zero or NaN.
2747
2748 (define_insn "*nmadd4<mode>_fastmath"
2749 [(set (match_operand:ANYF 0 "register_operand" "=f")
2750 (minus:ANYF
2751 (mult:ANYF (neg:ANYF (match_operand:ANYF 1 "register_operand" "f"))
2752 (match_operand:ANYF 2 "register_operand" "f"))
2753 (match_operand:ANYF 3 "register_operand" "f")))]
2754 "ISA_HAS_UNFUSED_MADD4
2755 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2756 "nmadd.<fmt>\t%0,%3,%1,%2"
2757 [(set_attr "type" "fmadd")
2758 (set_attr "mode" "<UNITMODE>")])
2759
2760 ;; This instruction recognizes (op1 - (op2 * op3) and generates an
2761 ;; nmsub which is really -((op2 * op3) - op1). They are equivalent
2762 ;; except for the sign bit when the result is zero or NaN.
2763
2764 (define_insn "*nmsub4<mode>_fastmath"
2765 [(set (match_operand:ANYF 0 "register_operand" "=f")
2766 (minus:ANYF
2767 (match_operand:ANYF 1 "register_operand" "f")
2768 (mult:ANYF (match_operand:ANYF 2 "register_operand" "f")
2769 (match_operand:ANYF 3 "register_operand" "f"))))]
2770 "ISA_HAS_UNFUSED_MADD4
2771 && !HONOR_SIGNED_ZEROS (<MODE>mode)"
2772 "nmsub.<fmt>\t%0,%1,%2,%3"
2773 [(set_attr "type" "fmadd")
2774 (set_attr "mode" "<UNITMODE>")])
2775
2776 ;;
2777 ;; ....................
2778 ;;
2779 ;; DIVISION and REMAINDER
2780 ;;
2781 ;; ....................
2782 ;;
2783
2784 (define_expand "div<mode>3"
2785 [(set (match_operand:ANYF 0 "register_operand")
2786 (div:ANYF (match_operand:ANYF 1 "reg_or_1_operand")
2787 (match_operand:ANYF 2 "register_operand")))]
2788 "<divide_condition>"
2789 {
2790 if (const_1_operand (operands[1], <MODE>mode))
2791 if (!(ISA_HAS_FP_RECIP_RSQRT (<MODE>mode)
2792 && flag_unsafe_math_optimizations))
2793 operands[1] = force_reg (<MODE>mode, operands[1]);
2794 })
2795
2796 ;; These patterns work around the early SB-1 rev2 core "F1" erratum:
2797 ;;
2798 ;; If an mfc1 or dmfc1 happens to access the floating point register
2799 ;; file at the same time a long latency operation (div, sqrt, recip,
2800 ;; sqrt) iterates an intermediate result back through the floating
2801 ;; point register file bypass, then instead returning the correct
2802 ;; register value the mfc1 or dmfc1 operation returns the intermediate
2803 ;; result of the long latency operation.
2804 ;;
2805 ;; The workaround is to insert an unconditional 'mov' from/to the
2806 ;; long latency op destination register.
2807
2808 (define_insn "*div<mode>3"
2809 [(set (match_operand:ANYF 0 "register_operand" "=f")
2810 (div:ANYF (match_operand:ANYF 1 "register_operand" "f")
2811 (match_operand:ANYF 2 "register_operand" "f")))]
2812 "<divide_condition>"
2813 {
2814 if (TARGET_FIX_SB1)
2815 return "div.<fmt>\t%0,%1,%2\;mov.<fmt>\t%0,%0";
2816 else
2817 return "div.<fmt>\t%0,%1,%2";
2818 }
2819 [(set_attr "type" "fdiv")
2820 (set_attr "mode" "<UNITMODE>")
2821 (set (attr "insn_count")
2822 (if_then_else (match_test "TARGET_FIX_SB1")
2823 (const_int 2)
2824 (const_int 1)))])
2825
2826 (define_insn "*recip<mode>3"
2827 [(set (match_operand:ANYF 0 "register_operand" "=f")
2828 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
2829 (match_operand:ANYF 2 "register_operand" "f")))]
2830 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
2831 {
2832 if (TARGET_FIX_SB1)
2833 return "recip.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
2834 else
2835 return "recip.<fmt>\t%0,%2";
2836 }
2837 [(set_attr "type" "frdiv")
2838 (set_attr "mode" "<UNITMODE>")
2839 (set (attr "insn_count")
2840 (if_then_else (match_test "TARGET_FIX_SB1")
2841 (const_int 2)
2842 (const_int 1)))])
2843
2844 ;; VR4120 errata MD(A1): signed division instructions do not work correctly
2845 ;; with negative operands. We use special libgcc functions instead.
2846 (define_expand "divmod<mode>4"
2847 [(parallel
2848 [(set (match_operand:GPR 0 "register_operand")
2849 (div:GPR (match_operand:GPR 1 "register_operand")
2850 (match_operand:GPR 2 "register_operand")))
2851 (set (match_operand:GPR 3 "register_operand")
2852 (mod:GPR (match_dup 1)
2853 (match_dup 2)))])]
2854 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2855 {
2856 if (TARGET_MIPS16)
2857 {
2858 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2859 emit_insn (gen_divmod<mode>4_mips16 (operands[0], operands[1],
2860 operands[2], operands[3], lo));
2861 DONE;
2862 }
2863 })
2864
2865 (define_insn_and_split "*divmod<mode>4"
2866 [(set (match_operand:GPR 0 "register_operand" "=l")
2867 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2868 (match_operand:GPR 2 "register_operand" "d")))
2869 (set (match_operand:GPR 3 "register_operand" "=d")
2870 (mod:GPR (match_dup 1)
2871 (match_dup 2)))]
2872 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && !TARGET_MIPS16"
2873 "#"
2874 "&& reload_completed"
2875 [(const_int 0)]
2876 {
2877 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2878 DONE;
2879 }
2880 [(set_attr "type" "idiv")
2881 (set_attr "mode" "<MODE>")
2882 (set_attr "insn_count" "2")])
2883
2884 ;; Expand generates divmod instructions for individual division and modulus
2885 ;; operations. We then rely on CSE to reuse earlier divmods where possible.
2886 ;; This means that, when generating MIPS16 code, it is better not to expose
2887 ;; the fixed LO register until after CSE has finished. However, it's still
2888 ;; better to split before register allocation, so that we don't allocate
2889 ;; one of the scarce MIPS16 registers to an unused result.
2890 (define_insn_and_split "divmod<mode>4_mips16"
2891 [(set (match_operand:GPR 0 "register_operand" "=d")
2892 (div:GPR (match_operand:GPR 1 "register_operand" "d")
2893 (match_operand:GPR 2 "register_operand" "d")))
2894 (set (match_operand:GPR 3 "register_operand" "=d")
2895 (mod:GPR (match_dup 1)
2896 (match_dup 2)))
2897 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2898 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120 && TARGET_MIPS16"
2899 "#"
2900 "&& cse_not_expected"
2901 [(const_int 0)]
2902 {
2903 emit_insn (gen_divmod<mode>4_split (operands[3], operands[1], operands[2]));
2904 emit_move_insn (operands[0], operands[4]);
2905 DONE;
2906 }
2907 [(set_attr "type" "idiv")
2908 (set_attr "mode" "<MODE>")
2909 (set_attr "insn_count" "3")])
2910
2911 (define_expand "udivmod<mode>4"
2912 [(parallel
2913 [(set (match_operand:GPR 0 "register_operand")
2914 (udiv:GPR (match_operand:GPR 1 "register_operand")
2915 (match_operand:GPR 2 "register_operand")))
2916 (set (match_operand:GPR 3 "register_operand")
2917 (umod:GPR (match_dup 1)
2918 (match_dup 2)))])]
2919 "ISA_HAS_<D>DIV && !TARGET_FIX_VR4120"
2920 {
2921 if (TARGET_MIPS16)
2922 {
2923 rtx lo = gen_rtx_REG (<MODE>mode, LO_REGNUM);
2924 emit_insn (gen_udivmod<mode>4_mips16 (operands[0], operands[1],
2925 operands[2], operands[3], lo));
2926 DONE;
2927 }
2928 })
2929
2930 (define_insn_and_split "*udivmod<mode>4"
2931 [(set (match_operand:GPR 0 "register_operand" "=l")
2932 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2933 (match_operand:GPR 2 "register_operand" "d")))
2934 (set (match_operand:GPR 3 "register_operand" "=d")
2935 (umod:GPR (match_dup 1)
2936 (match_dup 2)))]
2937 "ISA_HAS_<D>DIV && !TARGET_MIPS16"
2938 "#"
2939 "reload_completed"
2940 [(const_int 0)]
2941 {
2942 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2943 DONE;
2944 }
2945 [(set_attr "type" "idiv")
2946 (set_attr "mode" "<MODE>")
2947 (set_attr "insn_count" "2")])
2948
2949 ;; See the comment above "divmod<mode>4_mips16" for the split timing.
2950 (define_insn_and_split "udivmod<mode>4_mips16"
2951 [(set (match_operand:GPR 0 "register_operand" "=d")
2952 (udiv:GPR (match_operand:GPR 1 "register_operand" "d")
2953 (match_operand:GPR 2 "register_operand" "d")))
2954 (set (match_operand:GPR 3 "register_operand" "=d")
2955 (umod:GPR (match_dup 1)
2956 (match_dup 2)))
2957 (clobber (match_operand:GPR 4 "lo_operand" "=l"))]
2958 "ISA_HAS_<D>DIV && TARGET_MIPS16"
2959 "#"
2960 "cse_not_expected"
2961 [(const_int 0)]
2962 {
2963 emit_insn (gen_udivmod<mode>4_split (operands[3], operands[1], operands[2]));
2964 emit_move_insn (operands[0], operands[4]);
2965 DONE;
2966 }
2967 [(set_attr "type" "idiv")
2968 (set_attr "mode" "<MODE>")
2969 (set_attr "insn_count" "3")])
2970
2971 (define_expand "<u>divmod<mode>4_split"
2972 [(set (match_operand:GPR 0 "register_operand")
2973 (any_mod:GPR (match_operand:GPR 1 "register_operand")
2974 (match_operand:GPR 2 "register_operand")))]
2975 ""
2976 {
2977 rtx hilo;
2978
2979 if (TARGET_64BIT)
2980 {
2981 hilo = gen_rtx_REG (TImode, MD_REG_FIRST);
2982 emit_insn (gen_<u>divmod<mode>4_hilo_ti (hilo, operands[1],
2983 operands[2]));
2984 emit_insn (gen_mfhi<mode>_ti (operands[0], hilo));
2985 }
2986 else
2987 {
2988 hilo = gen_rtx_REG (DImode, MD_REG_FIRST);
2989 emit_insn (gen_<u>divmod<mode>4_hilo_di (hilo, operands[1],
2990 operands[2]));
2991 emit_insn (gen_mfhi<mode>_di (operands[0], hilo));
2992 }
2993 DONE;
2994 })
2995
2996 (define_insn "<u>divmod<GPR:mode>4_hilo_<HILO:mode>"
2997 [(set (match_operand:HILO 0 "muldiv_target_operand" "=x")
2998 (unspec:HILO
2999 [(any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3000 (match_operand:GPR 2 "register_operand" "d"))]
3001 UNSPEC_SET_HILO))]
3002 "ISA_HAS_<GPR:D>DIV"
3003 { return mips_output_division ("<GPR:d>div<u>\t%.,%1,%2", operands); }
3004 [(set_attr "type" "idiv")
3005 (set_attr "mode" "<GPR:MODE>")])
3006
3007 ;; Integer division and modulus.
3008
3009 (define_insn "<u>div<mode>3"
3010 [(set (match_operand:GPR 0 "register_operand" "=&d")
3011 (any_div:GPR (match_operand:GPR 1 "register_operand" "d")
3012 (match_operand:GPR 2 "register_operand" "d")))]
3013 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
3014 {
3015 if (TARGET_LOONGSON_2EF)
3016 return mips_output_division ("<d>div<u>.g\t%0,%1,%2", operands);
3017 else if (TARGET_LOONGSON_3A)
3018 return mips_output_division ("gs<d>div<u>\t%0,%1,%2", operands);
3019 else
3020 return mips_output_division ("<d>div<u>\t%0,%1,%2", operands);
3021 }
3022 [(set_attr "type" "idiv3")
3023 (set_attr "mode" "<MODE>")])
3024
3025 (define_insn "<u>mod<mode>3"
3026 [(set (match_operand:GPR 0 "register_operand" "=&d")
3027 (any_mod:GPR (match_operand:GPR 1 "register_operand" "d")
3028 (match_operand:GPR 2 "register_operand" "d")))]
3029 "TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A || ISA_HAS_R6<D>DIV"
3030 {
3031 if (TARGET_LOONGSON_2EF)
3032 return mips_output_division ("<d>mod<u>.g\t%0,%1,%2", operands);
3033 else if (TARGET_LOONGSON_3A)
3034 return mips_output_division ("gs<d>mod<u>\t%0,%1,%2", operands);
3035 else
3036 return mips_output_division ("<d>mod<u>\t%0,%1,%2", operands);
3037 }
3038 [(set_attr "type" "idiv3")
3039 (set_attr "mode" "<MODE>")])
3040 \f
3041 ;;
3042 ;; ....................
3043 ;;
3044 ;; SQUARE ROOT
3045 ;;
3046 ;; ....................
3047
3048 ;; These patterns work around the early SB-1 rev2 core "F1" erratum (see
3049 ;; "*div[sd]f3" comment for details).
3050
3051 (define_insn "sqrt<mode>2"
3052 [(set (match_operand:ANYF 0 "register_operand" "=f")
3053 (sqrt:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3054 "<sqrt_condition>"
3055 {
3056 if (TARGET_FIX_SB1)
3057 return "sqrt.<fmt>\t%0,%1\;mov.<fmt>\t%0,%0";
3058 else
3059 return "sqrt.<fmt>\t%0,%1";
3060 }
3061 [(set_attr "type" "fsqrt")
3062 (set_attr "mode" "<UNITMODE>")
3063 (set (attr "insn_count")
3064 (if_then_else (match_test "TARGET_FIX_SB1")
3065 (const_int 2)
3066 (const_int 1)))])
3067
3068 (define_insn "*rsqrt<mode>a"
3069 [(set (match_operand:ANYF 0 "register_operand" "=f")
3070 (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3071 (sqrt:ANYF (match_operand:ANYF 2 "register_operand" "f"))))]
3072 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3073 {
3074 if (TARGET_FIX_SB1)
3075 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3076 else
3077 return "rsqrt.<fmt>\t%0,%2";
3078 }
3079 [(set_attr "type" "frsqrt")
3080 (set_attr "mode" "<UNITMODE>")
3081 (set (attr "insn_count")
3082 (if_then_else (match_test "TARGET_FIX_SB1")
3083 (const_int 2)
3084 (const_int 1)))])
3085
3086 (define_insn "*rsqrt<mode>b"
3087 [(set (match_operand:ANYF 0 "register_operand" "=f")
3088 (sqrt:ANYF (div:ANYF (match_operand:ANYF 1 "const_1_operand" "")
3089 (match_operand:ANYF 2 "register_operand" "f"))))]
3090 "ISA_HAS_FP_RECIP_RSQRT (<MODE>mode) && flag_unsafe_math_optimizations"
3091 {
3092 if (TARGET_FIX_SB1)
3093 return "rsqrt.<fmt>\t%0,%2\;mov.<fmt>\t%0,%0";
3094 else
3095 return "rsqrt.<fmt>\t%0,%2";
3096 }
3097 [(set_attr "type" "frsqrt")
3098 (set_attr "mode" "<UNITMODE>")
3099 (set (attr "insn_count")
3100 (if_then_else (match_test "TARGET_FIX_SB1")
3101 (const_int 2)
3102 (const_int 1)))])
3103 \f
3104 ;;
3105 ;; ....................
3106 ;;
3107 ;; ABSOLUTE VALUE
3108 ;;
3109 ;; ....................
3110
3111 ;; Do not use the integer abs macro instruction, since that signals an
3112 ;; exception on -2147483648 (sigh).
3113
3114 ;; The "legacy" (as opposed to "2008") form of ABS.fmt is an arithmetic
3115 ;; instruction that treats all NaN inputs as invalid; it does not clear
3116 ;; their sign bit. We therefore can't use that form if the signs of
3117 ;; NaNs matter.
3118
3119 (define_insn "abs<mode>2"
3120 [(set (match_operand:ANYF 0 "register_operand" "=f")
3121 (abs:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3122 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3123 "abs.<fmt>\t%0,%1"
3124 [(set_attr "type" "fabs")
3125 (set_attr "mode" "<UNITMODE>")])
3126 \f
3127 ;;
3128 ;; ...................
3129 ;;
3130 ;; Count leading zeroes.
3131 ;;
3132 ;; ...................
3133 ;;
3134
3135 (define_insn "clz<mode>2"
3136 [(set (match_operand:GPR 0 "register_operand" "=d")
3137 (clz:GPR (match_operand:GPR 1 "register_operand" "d")))]
3138 "ISA_HAS_CLZ_CLO"
3139 "<d>clz\t%0,%1"
3140 [(set_attr "type" "clz")
3141 (set_attr "mode" "<MODE>")])
3142
3143 ;;
3144 ;; ...................
3145 ;;
3146 ;; Count number of set bits.
3147 ;;
3148 ;; ...................
3149 ;;
3150
3151 (define_insn "popcount<mode>2"
3152 [(set (match_operand:GPR 0 "register_operand" "=d")
3153 (popcount:GPR (match_operand:GPR 1 "register_operand" "d")))]
3154 "ISA_HAS_POP"
3155 "<d>pop\t%0,%1"
3156 [(set_attr "type" "pop")
3157 (set_attr "mode" "<MODE>")])
3158
3159 ;; The POP instruction is special as it does not take into account the upper
3160 ;; 32bits and is documented that way.
3161 (define_insn "*popcountdi2_trunc"
3162 [(set (match_operand:SI 0 "register_operand" "=d")
3163 (popcount:SI (truncate:SI (match_operand:DI 1 "register_operand" "d"))))]
3164 "ISA_HAS_POP && TARGET_64BIT"
3165 "pop\t%0,%1"
3166 [(set_attr "type" "pop")
3167 (set_attr "mode" "SI")])
3168 \f
3169 ;;
3170 ;; ....................
3171 ;;
3172 ;; NEGATION and ONE'S COMPLEMENT
3173 ;;
3174 ;; ....................
3175
3176 (define_insn "negsi2"
3177 [(set (match_operand:SI 0 "register_operand" "=d")
3178 (neg:SI (match_operand:SI 1 "register_operand" "d")))]
3179 ""
3180 {
3181 if (TARGET_MIPS16)
3182 return "neg\t%0,%1";
3183 else
3184 return "subu\t%0,%.,%1";
3185 }
3186 [(set_attr "alu_type" "sub")
3187 (set_attr "mode" "SI")])
3188
3189 (define_insn "negdi2"
3190 [(set (match_operand:DI 0 "register_operand" "=d")
3191 (neg:DI (match_operand:DI 1 "register_operand" "d")))]
3192 "TARGET_64BIT && !TARGET_MIPS16"
3193 "dsubu\t%0,%.,%1"
3194 [(set_attr "alu_type" "sub")
3195 (set_attr "mode" "DI")])
3196
3197 ;; The "legacy" (as opposed to "2008") form of NEG.fmt is an arithmetic
3198 ;; instruction that treats all NaN inputs as invalid; it does not flip
3199 ;; their sign bit. We therefore can't use that form if the signs of
3200 ;; NaNs matter.
3201
3202 (define_insn "neg<mode>2"
3203 [(set (match_operand:ANYF 0 "register_operand" "=f")
3204 (neg:ANYF (match_operand:ANYF 1 "register_operand" "f")))]
3205 "mips_abs == MIPS_IEEE_754_2008 || !HONOR_NANS (<MODE>mode)"
3206 "neg.<fmt>\t%0,%1"
3207 [(set_attr "type" "fneg")
3208 (set_attr "mode" "<UNITMODE>")])
3209
3210 (define_insn "one_cmpl<mode>2"
3211 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
3212 (not:GPR (match_operand:GPR 1 "register_operand" "!u,d")))]
3213 ""
3214 {
3215 if (TARGET_MIPS16)
3216 return "not\t%0,%1";
3217 else
3218 return "nor\t%0,%.,%1";
3219 }
3220 [(set_attr "alu_type" "not")
3221 (set_attr "compression" "micromips,*")
3222 (set_attr "mode" "<MODE>")])
3223 \f
3224 ;;
3225 ;; ....................
3226 ;;
3227 ;; LOGICAL
3228 ;;
3229 ;; ....................
3230 ;;
3231
3232 ;; Many of these instructions use trivial define_expands, because we
3233 ;; want to use a different set of constraints when TARGET_MIPS16.
3234
3235 (define_expand "and<mode>3"
3236 [(set (match_operand:GPR 0 "register_operand")
3237 (and:GPR (match_operand:GPR 1 "register_operand")
3238 (match_operand:GPR 2 "and_reg_operand")))])
3239
3240 ;; The middle-end is not allowed to convert ANDing with 0xffff_ffff into a
3241 ;; zero_extendsidi2 because of TRULY_NOOP_TRUNCATION, so handle these here.
3242 ;; Note that this variant does not trigger for SI mode because we require
3243 ;; a 64-bit HOST_WIDE_INT and 0xffff_ffff wouldn't be a canonical
3244 ;; sign-extended SImode value.
3245 ;;
3246 ;; These are possible combinations for operand 1 and 2. The table
3247 ;; includes both MIPS and MIPS16 cases. (r=register, mem=memory,
3248 ;; 16=MIPS16, x=match, S=split):
3249 ;;
3250 ;; \ op1 r/EXT r/!EXT mem r/16 mem/16
3251 ;; op2
3252 ;;
3253 ;; andi x x
3254 ;; 0xff x x x x
3255 ;; 0xffff x x x x
3256 ;; 0xffff_ffff x S x S x
3257 ;; low-bitmask x
3258 ;; register x x
3259 ;; register =op1 x
3260
3261 (define_insn "*and<mode>3"
3262 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,!u,d,d,d,!u,d")
3263 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "o,o,W,!u,d,d,d,0,d")
3264 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Uean,K,Yx,Yw,!u,d")))]
3265 "!TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3266 {
3267 int len;
3268
3269 switch (which_alternative)
3270 {
3271 case 0:
3272 operands[1] = gen_lowpart (QImode, operands[1]);
3273 return "lbu\t%0,%1";
3274 case 1:
3275 operands[1] = gen_lowpart (HImode, operands[1]);
3276 return "lhu\t%0,%1";
3277 case 2:
3278 operands[1] = gen_lowpart (SImode, operands[1]);
3279 return "lwu\t%0,%1";
3280 case 3:
3281 case 4:
3282 return "andi\t%0,%1,%x2";
3283 case 5:
3284 len = low_bitmask_len (<MODE>mode, INTVAL (operands[2]));
3285 operands[2] = GEN_INT (len);
3286 return "<d>ext\t%0,%1,0,%2";
3287 case 6:
3288 return "#";
3289 case 7:
3290 case 8:
3291 return "and\t%0,%1,%2";
3292 default:
3293 gcc_unreachable ();
3294 }
3295 }
3296 [(set_attr "move_type" "load,load,load,andi,andi,ext_ins,shift_shift,logical,logical")
3297 (set_attr "compression" "*,*,*,micromips,*,*,*,micromips,*")
3298 (set_attr "mode" "<MODE>")])
3299
3300 (define_insn "*and<mode>3_mips16"
3301 [(set (match_operand:GPR 0 "register_operand" "=d,d,d,d,d")
3302 (and:GPR (match_operand:GPR 1 "nonimmediate_operand" "%W,W,W,d,0")
3303 (match_operand:GPR 2 "and_operand" "Yb,Yh,Yw,Yw,d")))]
3304 "TARGET_MIPS16 && and_operands_ok (<MODE>mode, operands[1], operands[2])"
3305 {
3306 switch (which_alternative)
3307 {
3308 case 0:
3309 operands[1] = gen_lowpart (QImode, operands[1]);
3310 return "lbu\t%0,%1";
3311 case 1:
3312 operands[1] = gen_lowpart (HImode, operands[1]);
3313 return "lhu\t%0,%1";
3314 case 2:
3315 operands[1] = gen_lowpart (SImode, operands[1]);
3316 return "lwu\t%0,%1";
3317 case 3:
3318 return "#";
3319 case 4:
3320 return "and\t%0,%2";
3321 default:
3322 gcc_unreachable ();
3323 }
3324 }
3325 [(set_attr "move_type" "load,load,load,shift_shift,logical")
3326 (set_attr "mode" "<MODE>")])
3327
3328 (define_expand "ior<mode>3"
3329 [(set (match_operand:GPR 0 "register_operand")
3330 (ior:GPR (match_operand:GPR 1 "register_operand")
3331 (match_operand:GPR 2 "uns_arith_operand")))]
3332 ""
3333 {
3334 if (TARGET_MIPS16)
3335 operands[2] = force_reg (<MODE>mode, operands[2]);
3336 })
3337
3338 (define_insn "*ior<mode>3"
3339 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3340 (ior:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3341 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3342 "!TARGET_MIPS16"
3343 "@
3344 or\t%0,%1,%2
3345 or\t%0,%1,%2
3346 ori\t%0,%1,%x2"
3347 [(set_attr "alu_type" "or")
3348 (set_attr "compression" "micromips,*,*")
3349 (set_attr "mode" "<MODE>")])
3350
3351 (define_insn "*ior<mode>3_mips16"
3352 [(set (match_operand:GPR 0 "register_operand" "=d")
3353 (ior:GPR (match_operand:GPR 1 "register_operand" "%0")
3354 (match_operand:GPR 2 "register_operand" "d")))]
3355 "TARGET_MIPS16"
3356 "or\t%0,%2"
3357 [(set_attr "alu_type" "or")
3358 (set_attr "mode" "<MODE>")])
3359
3360 (define_expand "xor<mode>3"
3361 [(set (match_operand:GPR 0 "register_operand")
3362 (xor:GPR (match_operand:GPR 1 "register_operand")
3363 (match_operand:GPR 2 "uns_arith_operand")))]
3364 ""
3365 "")
3366
3367 (define_insn "*xor<mode>3"
3368 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3369 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d")
3370 (match_operand:GPR 2 "uns_arith_operand" "!u,d,K")))]
3371 "!TARGET_MIPS16"
3372 "@
3373 xor\t%0,%1,%2
3374 xor\t%0,%1,%2
3375 xori\t%0,%1,%x2"
3376 [(set_attr "alu_type" "xor")
3377 (set_attr "compression" "micromips,*,*")
3378 (set_attr "mode" "<MODE>")])
3379
3380 (define_insn "*xor<mode>3_mips16"
3381 [(set (match_operand:GPR 0 "register_operand" "=d,t,t,t")
3382 (xor:GPR (match_operand:GPR 1 "register_operand" "%0,d,d,d")
3383 (match_operand:GPR 2 "uns_arith_operand" "d,Uub8,K,d")))]
3384 "TARGET_MIPS16"
3385 "@
3386 xor\t%0,%2
3387 cmpi\t%1,%2
3388 cmpi\t%1,%2
3389 cmp\t%1,%2"
3390 [(set_attr "alu_type" "xor")
3391 (set_attr "mode" "<MODE>")
3392 (set_attr "extended_mips16" "no,no,yes,no")])
3393
3394 (define_insn "*nor<mode>3"
3395 [(set (match_operand:GPR 0 "register_operand" "=d")
3396 (and:GPR (not:GPR (match_operand:GPR 1 "register_operand" "d"))
3397 (not:GPR (match_operand:GPR 2 "register_operand" "d"))))]
3398 "!TARGET_MIPS16"
3399 "nor\t%0,%1,%2"
3400 [(set_attr "alu_type" "nor")
3401 (set_attr "mode" "<MODE>")])
3402 \f
3403 ;;
3404 ;; ....................
3405 ;;
3406 ;; TRUNCATION
3407 ;;
3408 ;; ....................
3409
3410
3411
3412 (define_insn "truncdfsf2"
3413 [(set (match_operand:SF 0 "register_operand" "=f")
3414 (float_truncate:SF (match_operand:DF 1 "register_operand" "f")))]
3415 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3416 "cvt.s.d\t%0,%1"
3417 [(set_attr "type" "fcvt")
3418 (set_attr "cnv_mode" "D2S")
3419 (set_attr "mode" "SF")])
3420
3421 ;; Integer truncation patterns. Truncating SImode values to smaller
3422 ;; modes is a no-op, as it is for most other GCC ports. Truncating
3423 ;; DImode values to SImode is not a no-op for TARGET_64BIT since we
3424 ;; need to make sure that the lower 32 bits are properly sign-extended
3425 ;; (see TRULY_NOOP_TRUNCATION). Truncating DImode values into modes
3426 ;; smaller than SImode is equivalent to two separate truncations:
3427 ;;
3428 ;; A B
3429 ;; DI ---> HI == DI ---> SI ---> HI
3430 ;; DI ---> QI == DI ---> SI ---> QI
3431 ;;
3432 ;; Step A needs a real instruction but step B does not.
3433
3434 (define_insn "truncdi<mode>2"
3435 [(set (match_operand:SUBDI 0 "nonimmediate_operand" "=d,m")
3436 (truncate:SUBDI (match_operand:DI 1 "register_operand" "d,d")))]
3437 "TARGET_64BIT"
3438 "@
3439 sll\t%0,%1,0
3440 <store>\t%1,%0"
3441 [(set_attr "move_type" "sll0,store")
3442 (set_attr "mode" "SI")])
3443
3444 ;; Combiner patterns to optimize shift/truncate combinations.
3445
3446 (define_insn "*ashr_trunc<mode>"
3447 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3448 (truncate:SUBDI
3449 (ashiftrt:DI (match_operand:DI 1 "register_operand" "d")
3450 (match_operand:DI 2 "const_arith_operand" ""))))]
3451 "TARGET_64BIT && !TARGET_MIPS16 && IN_RANGE (INTVAL (operands[2]), 32, 63)"
3452 "dsra\t%0,%1,%2"
3453 [(set_attr "type" "shift")
3454 (set_attr "mode" "<MODE>")])
3455
3456 (define_insn "*lshr32_trunc<mode>"
3457 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3458 (truncate:SUBDI
3459 (lshiftrt:DI (match_operand:DI 1 "register_operand" "d")
3460 (const_int 32))))]
3461 "TARGET_64BIT && !TARGET_MIPS16"
3462 "dsra\t%0,%1,32"
3463 [(set_attr "type" "shift")
3464 (set_attr "mode" "<MODE>")])
3465
3466 ;; Logical shift by more than 32 results in proper SI values so truncation is
3467 ;; removed by the middle end. Note that a logical shift by 32 is handled by
3468 ;; the previous pattern.
3469 (define_insn "*<optab>_trunc<mode>_exts"
3470 [(set (match_operand:SUBDI 0 "register_operand" "=d")
3471 (truncate:SUBDI
3472 (any_shiftrt:DI (match_operand:DI 1 "register_operand" "d")
3473 (match_operand:DI 2 "const_arith_operand" ""))))]
3474 "ISA_HAS_EXTS && TARGET_64BIT && UINTVAL (operands[2]) < 32"
3475 "exts\t%0,%1,%2,31"
3476 [(set_attr "type" "arith")
3477 (set_attr "mode" "<MODE>")])
3478 \f
3479 ;;
3480 ;; ....................
3481 ;;
3482 ;; ZERO EXTENSION
3483 ;;
3484 ;; ....................
3485
3486 ;; Extension insns.
3487
3488 (define_expand "zero_extendsidi2"
3489 [(set (match_operand:DI 0 "register_operand")
3490 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand")))]
3491 "TARGET_64BIT")
3492
3493 (define_insn_and_split "*zero_extendsidi2"
3494 [(set (match_operand:DI 0 "register_operand" "=d,d")
3495 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3496 "TARGET_64BIT && !ISA_HAS_EXT_INS"
3497 "@
3498 #
3499 lwu\t%0,%1"
3500 "&& reload_completed && REG_P (operands[1])"
3501 [(set (match_dup 0)
3502 (ashift:DI (match_dup 1) (const_int 32)))
3503 (set (match_dup 0)
3504 (lshiftrt:DI (match_dup 0) (const_int 32)))]
3505 { operands[1] = gen_lowpart (DImode, operands[1]); }
3506 [(set_attr "move_type" "shift_shift,load")
3507 (set_attr "mode" "DI")])
3508
3509 (define_insn "*zero_extendsidi2_dext"
3510 [(set (match_operand:DI 0 "register_operand" "=d,d")
3511 (zero_extend:DI (match_operand:SI 1 "nonimmediate_operand" "d,W")))]
3512 "TARGET_64BIT && ISA_HAS_EXT_INS"
3513 "@
3514 dext\t%0,%1,0,32
3515 lwu\t%0,%1"
3516 [(set_attr "move_type" "arith,load")
3517 (set_attr "mode" "DI")])
3518
3519 ;; See the comment before the *and<mode>3 pattern why this is generated by
3520 ;; combine.
3521
3522 (define_split
3523 [(set (match_operand:DI 0 "register_operand")
3524 (and:DI (match_operand:DI 1 "register_operand")
3525 (const_int 4294967295)))]
3526 "TARGET_64BIT && !ISA_HAS_EXT_INS && reload_completed"
3527 [(set (match_dup 0)
3528 (ashift:DI (match_dup 1) (const_int 32)))
3529 (set (match_dup 0)
3530 (lshiftrt:DI (match_dup 0) (const_int 32)))])
3531
3532 (define_expand "zero_extend<SHORT:mode><GPR:mode>2"
3533 [(set (match_operand:GPR 0 "register_operand")
3534 (zero_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3535 ""
3536 {
3537 if (TARGET_MIPS16 && !GENERATE_MIPS16E
3538 && !memory_operand (operands[1], <SHORT:MODE>mode))
3539 {
3540 emit_insn (gen_and<GPR:mode>3 (operands[0],
3541 gen_lowpart (<GPR:MODE>mode, operands[1]),
3542 force_reg (<GPR:MODE>mode,
3543 GEN_INT (<SHORT:mask>))));
3544 DONE;
3545 }
3546 })
3547
3548 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2"
3549 [(set (match_operand:GPR 0 "register_operand" "=!u,d,d")
3550 (zero_extend:GPR
3551 (match_operand:SHORT 1 "nonimmediate_operand" "!u,d,m")))]
3552 "!TARGET_MIPS16"
3553 "@
3554 andi\t%0,%1,<SHORT:mask>
3555 andi\t%0,%1,<SHORT:mask>
3556 l<SHORT:size>u\t%0,%1"
3557 [(set_attr "move_type" "andi,andi,load")
3558 (set_attr "compression" "micromips,*,*")
3559 (set_attr "mode" "<GPR:MODE>")])
3560
3561 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16e"
3562 [(set (match_operand:GPR 0 "register_operand" "=d")
3563 (zero_extend:GPR (match_operand:SHORT 1 "register_operand" "0")))]
3564 "GENERATE_MIPS16E"
3565 "ze<SHORT:size>\t%0"
3566 ;; This instruction is effectively a special encoding of ANDI.
3567 [(set_attr "move_type" "andi")
3568 (set_attr "mode" "<GPR:MODE>")])
3569
3570 (define_insn "*zero_extend<SHORT:mode><GPR:mode>2_mips16"
3571 [(set (match_operand:GPR 0 "register_operand" "=d")
3572 (zero_extend:GPR (match_operand:SHORT 1 "memory_operand" "m")))]
3573 "TARGET_MIPS16"
3574 "l<SHORT:size>u\t%0,%1"
3575 [(set_attr "move_type" "load")
3576 (set_attr "mode" "<GPR:MODE>")])
3577
3578 (define_expand "zero_extendqihi2"
3579 [(set (match_operand:HI 0 "register_operand")
3580 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3581 ""
3582 {
3583 if (TARGET_MIPS16 && !memory_operand (operands[1], QImode))
3584 {
3585 emit_insn (gen_zero_extendqisi2 (gen_lowpart (SImode, operands[0]),
3586 operands[1]));
3587 DONE;
3588 }
3589 })
3590
3591 (define_insn "*zero_extendqihi2"
3592 [(set (match_operand:HI 0 "register_operand" "=d,d")
3593 (zero_extend:HI (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3594 "!TARGET_MIPS16"
3595 "@
3596 andi\t%0,%1,0x00ff
3597 lbu\t%0,%1"
3598 [(set_attr "move_type" "andi,load")
3599 (set_attr "mode" "HI")])
3600
3601 (define_insn "*zero_extendqihi2_mips16"
3602 [(set (match_operand:HI 0 "register_operand" "=d")
3603 (zero_extend:HI (match_operand:QI 1 "memory_operand" "m")))]
3604 "TARGET_MIPS16"
3605 "lbu\t%0,%1"
3606 [(set_attr "move_type" "load")
3607 (set_attr "mode" "HI")])
3608
3609 ;; Combiner patterns to optimize truncate/zero_extend combinations.
3610
3611 (define_insn "*zero_extend<GPR:mode>_trunc<SHORT:mode>"
3612 [(set (match_operand:GPR 0 "register_operand" "=d")
3613 (zero_extend:GPR
3614 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3615 "TARGET_64BIT && !TARGET_MIPS16"
3616 {
3617 operands[2] = GEN_INT (GET_MODE_MASK (<SHORT:MODE>mode));
3618 return "andi\t%0,%1,%x2";
3619 }
3620 [(set_attr "alu_type" "and")
3621 (set_attr "mode" "<GPR:MODE>")])
3622
3623 (define_insn "*zero_extendhi_truncqi"
3624 [(set (match_operand:HI 0 "register_operand" "=d")
3625 (zero_extend:HI
3626 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3627 "TARGET_64BIT && !TARGET_MIPS16"
3628 "andi\t%0,%1,0xff"
3629 [(set_attr "alu_type" "and")
3630 (set_attr "mode" "HI")])
3631 \f
3632 ;;
3633 ;; ....................
3634 ;;
3635 ;; SIGN EXTENSION
3636 ;;
3637 ;; ....................
3638
3639 ;; Extension insns.
3640 ;; Those for integer source operand are ordered widest source type first.
3641
3642 ;; When TARGET_64BIT, all SImode integer and accumulator registers
3643 ;; should already be in sign-extended form (see TRULY_NOOP_TRUNCATION
3644 ;; and truncdisi2). We can therefore get rid of register->register
3645 ;; instructions if we constrain the source to be in the same register as
3646 ;; the destination.
3647 ;;
3648 ;; Only the pre-reload scheduler sees the type of the register alternatives;
3649 ;; we split them into nothing before the post-reload scheduler runs.
3650 ;; These alternatives therefore have type "move" in order to reflect
3651 ;; what happens if the two pre-reload operands cannot be tied, and are
3652 ;; instead allocated two separate GPRs. We don't distinguish between
3653 ;; the GPR and LO cases because we don't usually know during pre-reload
3654 ;; scheduling whether an operand will be LO or not.
3655 (define_insn_and_split "extendsidi2"
3656 [(set (match_operand:DI 0 "register_operand" "=d,l,d")
3657 (sign_extend:DI (match_operand:SI 1 "nonimmediate_operand" "0,0,m")))]
3658 "TARGET_64BIT"
3659 "@
3660 #
3661 #
3662 lw\t%0,%1"
3663 "&& reload_completed && register_operand (operands[1], VOIDmode)"
3664 [(const_int 0)]
3665 {
3666 emit_note (NOTE_INSN_DELETED);
3667 DONE;
3668 }
3669 [(set_attr "move_type" "move,move,load")
3670 (set_attr "mode" "DI")])
3671
3672 (define_expand "extend<SHORT:mode><GPR:mode>2"
3673 [(set (match_operand:GPR 0 "register_operand")
3674 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand")))]
3675 "")
3676
3677 (define_insn "*extend<SHORT:mode><GPR:mode>2_mips16e"
3678 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3679 (sign_extend:GPR (match_operand:SHORT 1 "nonimmediate_operand" "0,m")))]
3680 "GENERATE_MIPS16E"
3681 "@
3682 se<SHORT:size>\t%0
3683 l<SHORT:size>\t%0,%1"
3684 [(set_attr "move_type" "signext,load")
3685 (set_attr "mode" "<GPR:MODE>")])
3686
3687 (define_insn_and_split "*extend<SHORT:mode><GPR:mode>2"
3688 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3689 (sign_extend:GPR
3690 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3691 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3692 "@
3693 #
3694 l<SHORT:size>\t%0,%1"
3695 "&& reload_completed && REG_P (operands[1])"
3696 [(set (match_dup 0) (ashift:GPR (match_dup 1) (match_dup 2)))
3697 (set (match_dup 0) (ashiftrt:GPR (match_dup 0) (match_dup 2)))]
3698 {
3699 operands[1] = gen_lowpart (<GPR:MODE>mode, operands[1]);
3700 operands[2] = GEN_INT (GET_MODE_BITSIZE (<GPR:MODE>mode)
3701 - GET_MODE_BITSIZE (<SHORT:MODE>mode));
3702 }
3703 [(set_attr "move_type" "shift_shift,load")
3704 (set_attr "mode" "<GPR:MODE>")])
3705
3706 (define_insn "*extend<SHORT:mode><GPR:mode>2_se<SHORT:size>"
3707 [(set (match_operand:GPR 0 "register_operand" "=d,d")
3708 (sign_extend:GPR
3709 (match_operand:SHORT 1 "nonimmediate_operand" "d,m")))]
3710 "ISA_HAS_SEB_SEH"
3711 "@
3712 se<SHORT:size>\t%0,%1
3713 l<SHORT:size>\t%0,%1"
3714 [(set_attr "move_type" "signext,load")
3715 (set_attr "mode" "<GPR:MODE>")])
3716
3717 (define_expand "extendqihi2"
3718 [(set (match_operand:HI 0 "register_operand")
3719 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand")))]
3720 "")
3721
3722 (define_insn "*extendqihi2_mips16e"
3723 [(set (match_operand:HI 0 "register_operand" "=d,d")
3724 (sign_extend:HI (match_operand:QI 1 "nonimmediate_operand" "0,m")))]
3725 "GENERATE_MIPS16E"
3726 "@
3727 seb\t%0
3728 lb\t%0,%1"
3729 [(set_attr "move_type" "signext,load")
3730 (set_attr "mode" "SI")])
3731
3732 (define_insn_and_split "*extendqihi2"
3733 [(set (match_operand:HI 0 "register_operand" "=d,d")
3734 (sign_extend:HI
3735 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3736 "!ISA_HAS_SEB_SEH && !GENERATE_MIPS16E"
3737 "@
3738 #
3739 lb\t%0,%1"
3740 "&& reload_completed && REG_P (operands[1])"
3741 [(set (match_dup 0) (ashift:SI (match_dup 1) (match_dup 2)))
3742 (set (match_dup 0) (ashiftrt:SI (match_dup 0) (match_dup 2)))]
3743 {
3744 operands[0] = gen_lowpart (SImode, operands[0]);
3745 operands[1] = gen_lowpart (SImode, operands[1]);
3746 operands[2] = GEN_INT (GET_MODE_BITSIZE (SImode)
3747 - GET_MODE_BITSIZE (QImode));
3748 }
3749 [(set_attr "move_type" "shift_shift,load")
3750 (set_attr "mode" "SI")])
3751
3752 (define_insn "*extendqihi2_seb"
3753 [(set (match_operand:HI 0 "register_operand" "=d,d")
3754 (sign_extend:HI
3755 (match_operand:QI 1 "nonimmediate_operand" "d,m")))]
3756 "ISA_HAS_SEB_SEH"
3757 "@
3758 seb\t%0,%1
3759 lb\t%0,%1"
3760 [(set_attr "move_type" "signext,load")
3761 (set_attr "mode" "SI")])
3762
3763 ;; Combiner patterns for truncate/sign_extend combinations. The SI versions
3764 ;; use the shift/truncate patterns.
3765
3766 (define_insn_and_split "*extenddi_truncate<mode>"
3767 [(set (match_operand:DI 0 "register_operand" "=d")
3768 (sign_extend:DI
3769 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3770 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3771 "#"
3772 "&& reload_completed"
3773 [(set (match_dup 2)
3774 (ashift:DI (match_dup 1)
3775 (match_dup 3)))
3776 (set (match_dup 0)
3777 (ashiftrt:DI (match_dup 2)
3778 (match_dup 3)))]
3779 {
3780 operands[2] = gen_lowpart (DImode, operands[0]);
3781 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3782 }
3783 [(set_attr "move_type" "shift_shift")
3784 (set_attr "mode" "DI")])
3785
3786 (define_insn_and_split "*extendsi_truncate<mode>"
3787 [(set (match_operand:SI 0 "register_operand" "=d")
3788 (sign_extend:SI
3789 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3790 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3791 "#"
3792 "&& reload_completed"
3793 [(set (match_dup 2)
3794 (ashift:DI (match_dup 1)
3795 (match_dup 3)))
3796 (set (match_dup 0)
3797 (truncate:SI (ashiftrt:DI (match_dup 2)
3798 (match_dup 3))))]
3799 {
3800 operands[2] = gen_lowpart (DImode, operands[0]);
3801 operands[3] = GEN_INT (BITS_PER_WORD - GET_MODE_BITSIZE (<MODE>mode));
3802 }
3803 [(set_attr "move_type" "shift_shift")
3804 (set_attr "mode" "SI")])
3805
3806 (define_insn_and_split "*extendhi_truncateqi"
3807 [(set (match_operand:HI 0 "register_operand" "=d")
3808 (sign_extend:HI
3809 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3810 "TARGET_64BIT && !TARGET_MIPS16 && !ISA_HAS_EXTS"
3811 "#"
3812 "&& reload_completed"
3813 [(set (match_dup 2)
3814 (ashift:DI (match_dup 1)
3815 (const_int 56)))
3816 (set (match_dup 0)
3817 (truncate:HI (ashiftrt:DI (match_dup 2)
3818 (const_int 56))))]
3819 {
3820 operands[2] = gen_lowpart (DImode, operands[0]);
3821 }
3822 [(set_attr "move_type" "shift_shift")
3823 (set_attr "mode" "SI")])
3824
3825 (define_insn "*extend<GPR:mode>_truncate<SHORT:mode>_exts"
3826 [(set (match_operand:GPR 0 "register_operand" "=d")
3827 (sign_extend:GPR
3828 (truncate:SHORT (match_operand:DI 1 "register_operand" "d"))))]
3829 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3830 {
3831 operands[2] = GEN_INT (GET_MODE_BITSIZE (<SHORT:MODE>mode));
3832 return "exts\t%0,%1,0,%m2";
3833 }
3834 [(set_attr "type" "arith")
3835 (set_attr "mode" "<GPR:MODE>")])
3836
3837 (define_insn "*extendhi_truncateqi_exts"
3838 [(set (match_operand:HI 0 "register_operand" "=d")
3839 (sign_extend:HI
3840 (truncate:QI (match_operand:DI 1 "register_operand" "d"))))]
3841 "TARGET_64BIT && !TARGET_MIPS16 && ISA_HAS_EXTS"
3842 "exts\t%0,%1,0,7"
3843 [(set_attr "type" "arith")
3844 (set_attr "mode" "SI")])
3845
3846 (define_insn "extendsfdf2"
3847 [(set (match_operand:DF 0 "register_operand" "=f")
3848 (float_extend:DF (match_operand:SF 1 "register_operand" "f")))]
3849 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3850 "cvt.d.s\t%0,%1"
3851 [(set_attr "type" "fcvt")
3852 (set_attr "cnv_mode" "S2D")
3853 (set_attr "mode" "DF")])
3854 \f
3855 ;;
3856 ;; ....................
3857 ;;
3858 ;; CONVERSIONS
3859 ;;
3860 ;; ....................
3861
3862 (define_expand "fix_truncdfsi2"
3863 [(set (match_operand:SI 0 "register_operand")
3864 (fix:SI (match_operand:DF 1 "register_operand")))]
3865 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3866 {
3867 if (!ISA_HAS_TRUNC_W)
3868 {
3869 emit_insn (gen_fix_truncdfsi2_macro (operands[0], operands[1]));
3870 DONE;
3871 }
3872 })
3873
3874 (define_insn "fix_truncdfsi2_insn"
3875 [(set (match_operand:SI 0 "register_operand" "=f")
3876 (fix:SI (match_operand:DF 1 "register_operand" "f")))]
3877 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && ISA_HAS_TRUNC_W"
3878 "trunc.w.d %0,%1"
3879 [(set_attr "type" "fcvt")
3880 (set_attr "mode" "DF")
3881 (set_attr "cnv_mode" "D2I")])
3882
3883 (define_insn "fix_truncdfsi2_macro"
3884 [(set (match_operand:SI 0 "register_operand" "=f")
3885 (fix:SI (match_operand:DF 1 "register_operand" "f")))
3886 (clobber (match_scratch:DF 2 "=d"))]
3887 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT && !ISA_HAS_TRUNC_W"
3888 {
3889 if (mips_nomacro.nesting_level > 0)
3890 return ".set\tmacro\;trunc.w.d %0,%1,%2\;.set\tnomacro";
3891 else
3892 return "trunc.w.d %0,%1,%2";
3893 }
3894 [(set_attr "type" "fcvt")
3895 (set_attr "mode" "DF")
3896 (set_attr "cnv_mode" "D2I")
3897 (set_attr "insn_count" "9")])
3898
3899 (define_expand "fix_truncsfsi2"
3900 [(set (match_operand:SI 0 "register_operand")
3901 (fix:SI (match_operand:SF 1 "register_operand")))]
3902 "TARGET_HARD_FLOAT"
3903 {
3904 if (!ISA_HAS_TRUNC_W)
3905 {
3906 emit_insn (gen_fix_truncsfsi2_macro (operands[0], operands[1]));
3907 DONE;
3908 }
3909 })
3910
3911 (define_insn "fix_truncsfsi2_insn"
3912 [(set (match_operand:SI 0 "register_operand" "=f")
3913 (fix:SI (match_operand:SF 1 "register_operand" "f")))]
3914 "TARGET_HARD_FLOAT && ISA_HAS_TRUNC_W"
3915 "trunc.w.s %0,%1"
3916 [(set_attr "type" "fcvt")
3917 (set_attr "mode" "SF")
3918 (set_attr "cnv_mode" "S2I")])
3919
3920 (define_insn "fix_truncsfsi2_macro"
3921 [(set (match_operand:SI 0 "register_operand" "=f")
3922 (fix:SI (match_operand:SF 1 "register_operand" "f")))
3923 (clobber (match_scratch:SF 2 "=d"))]
3924 "TARGET_HARD_FLOAT && !ISA_HAS_TRUNC_W"
3925 {
3926 if (mips_nomacro.nesting_level > 0)
3927 return ".set\tmacro\;trunc.w.s %0,%1,%2\;.set\tnomacro";
3928 else
3929 return "trunc.w.s %0,%1,%2";
3930 }
3931 [(set_attr "type" "fcvt")
3932 (set_attr "mode" "SF")
3933 (set_attr "cnv_mode" "S2I")
3934 (set_attr "insn_count" "9")])
3935
3936
3937 (define_insn "fix_truncdfdi2"
3938 [(set (match_operand:DI 0 "register_operand" "=f")
3939 (fix:DI (match_operand:DF 1 "register_operand" "f")))]
3940 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3941 "trunc.l.d %0,%1"
3942 [(set_attr "type" "fcvt")
3943 (set_attr "mode" "DF")
3944 (set_attr "cnv_mode" "D2I")])
3945
3946
3947 (define_insn "fix_truncsfdi2"
3948 [(set (match_operand:DI 0 "register_operand" "=f")
3949 (fix:DI (match_operand:SF 1 "register_operand" "f")))]
3950 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3951 "trunc.l.s %0,%1"
3952 [(set_attr "type" "fcvt")
3953 (set_attr "mode" "SF")
3954 (set_attr "cnv_mode" "S2I")])
3955
3956
3957 (define_insn "floatsidf2"
3958 [(set (match_operand:DF 0 "register_operand" "=f")
3959 (float:DF (match_operand:SI 1 "register_operand" "f")))]
3960 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
3961 "cvt.d.w\t%0,%1"
3962 [(set_attr "type" "fcvt")
3963 (set_attr "mode" "DF")
3964 (set_attr "cnv_mode" "I2D")])
3965
3966
3967 (define_insn "floatdidf2"
3968 [(set (match_operand:DF 0 "register_operand" "=f")
3969 (float:DF (match_operand:DI 1 "register_operand" "f")))]
3970 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3971 "cvt.d.l\t%0,%1"
3972 [(set_attr "type" "fcvt")
3973 (set_attr "mode" "DF")
3974 (set_attr "cnv_mode" "I2D")])
3975
3976
3977 (define_insn "floatsisf2"
3978 [(set (match_operand:SF 0 "register_operand" "=f")
3979 (float:SF (match_operand:SI 1 "register_operand" "f")))]
3980 "TARGET_HARD_FLOAT"
3981 "cvt.s.w\t%0,%1"
3982 [(set_attr "type" "fcvt")
3983 (set_attr "mode" "SF")
3984 (set_attr "cnv_mode" "I2S")])
3985
3986
3987 (define_insn "floatdisf2"
3988 [(set (match_operand:SF 0 "register_operand" "=f")
3989 (float:SF (match_operand:DI 1 "register_operand" "f")))]
3990 "TARGET_HARD_FLOAT && TARGET_FLOAT64 && TARGET_DOUBLE_FLOAT"
3991 "cvt.s.l\t%0,%1"
3992 [(set_attr "type" "fcvt")
3993 (set_attr "mode" "SF")
3994 (set_attr "cnv_mode" "I2S")])
3995
3996
3997 (define_expand "fixuns_truncdfsi2"
3998 [(set (match_operand:SI 0 "register_operand")
3999 (unsigned_fix:SI (match_operand:DF 1 "register_operand")))]
4000 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
4001 {
4002 rtx reg1 = gen_reg_rtx (DFmode);
4003 rtx reg2 = gen_reg_rtx (DFmode);
4004 rtx reg3 = gen_reg_rtx (SImode);
4005 rtx_code_label *label1 = gen_label_rtx ();
4006 rtx_code_label *label2 = gen_label_rtx ();
4007 rtx test;
4008 REAL_VALUE_TYPE offset;
4009
4010 real_2expN (&offset, 31, DFmode);
4011
4012 if (reg1) /* Turn off complaints about unreached code. */
4013 {
4014 mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4015 do_pending_stack_adjust ();
4016
4017 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4018 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4019
4020 emit_insn (gen_fix_truncdfsi2 (operands[0], operands[1]));
4021 emit_jump_insn (gen_rtx_SET (pc_rtx,
4022 gen_rtx_LABEL_REF (VOIDmode, label2)));
4023 emit_barrier ();
4024
4025 emit_label (label1);
4026 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4027 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4028 (BITMASK_HIGH, SImode)));
4029
4030 emit_insn (gen_fix_truncdfsi2 (operands[0], reg2));
4031 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4032
4033 emit_label (label2);
4034
4035 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4036 fields, and can't be used for REG_NOTES anyway). */
4037 emit_use (stack_pointer_rtx);
4038 DONE;
4039 }
4040 })
4041
4042
4043 (define_expand "fixuns_truncdfdi2"
4044 [(set (match_operand:DI 0 "register_operand")
4045 (unsigned_fix:DI (match_operand:DF 1 "register_operand")))]
4046 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4047 {
4048 rtx reg1 = gen_reg_rtx (DFmode);
4049 rtx reg2 = gen_reg_rtx (DFmode);
4050 rtx reg3 = gen_reg_rtx (DImode);
4051 rtx_code_label *label1 = gen_label_rtx ();
4052 rtx_code_label *label2 = gen_label_rtx ();
4053 rtx test;
4054 REAL_VALUE_TYPE offset;
4055
4056 real_2expN (&offset, 63, DFmode);
4057
4058 mips_emit_move (reg1, const_double_from_real_value (offset, DFmode));
4059 do_pending_stack_adjust ();
4060
4061 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4062 emit_jump_insn (gen_cbranchdf4 (test, operands[1], reg1, label1));
4063
4064 emit_insn (gen_fix_truncdfdi2 (operands[0], operands[1]));
4065 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4066 emit_barrier ();
4067
4068 emit_label (label1);
4069 mips_emit_move (reg2, gen_rtx_MINUS (DFmode, operands[1], reg1));
4070 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4071 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4072
4073 emit_insn (gen_fix_truncdfdi2 (operands[0], reg2));
4074 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4075
4076 emit_label (label2);
4077
4078 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4079 fields, and can't be used for REG_NOTES anyway). */
4080 emit_use (stack_pointer_rtx);
4081 DONE;
4082 })
4083
4084
4085 (define_expand "fixuns_truncsfsi2"
4086 [(set (match_operand:SI 0 "register_operand")
4087 (unsigned_fix:SI (match_operand:SF 1 "register_operand")))]
4088 "TARGET_HARD_FLOAT"
4089 {
4090 rtx reg1 = gen_reg_rtx (SFmode);
4091 rtx reg2 = gen_reg_rtx (SFmode);
4092 rtx reg3 = gen_reg_rtx (SImode);
4093 rtx_code_label *label1 = gen_label_rtx ();
4094 rtx_code_label *label2 = gen_label_rtx ();
4095 rtx test;
4096 REAL_VALUE_TYPE offset;
4097
4098 real_2expN (&offset, 31, SFmode);
4099
4100 mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4101 do_pending_stack_adjust ();
4102
4103 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4104 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4105
4106 emit_insn (gen_fix_truncsfsi2 (operands[0], operands[1]));
4107 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4108 emit_barrier ();
4109
4110 emit_label (label1);
4111 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4112 mips_emit_move (reg3, GEN_INT (trunc_int_for_mode
4113 (BITMASK_HIGH, SImode)));
4114
4115 emit_insn (gen_fix_truncsfsi2 (operands[0], reg2));
4116 emit_insn (gen_iorsi3 (operands[0], operands[0], reg3));
4117
4118 emit_label (label2);
4119
4120 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4121 fields, and can't be used for REG_NOTES anyway). */
4122 emit_use (stack_pointer_rtx);
4123 DONE;
4124 })
4125
4126
4127 (define_expand "fixuns_truncsfdi2"
4128 [(set (match_operand:DI 0 "register_operand")
4129 (unsigned_fix:DI (match_operand:SF 1 "register_operand")))]
4130 "TARGET_HARD_FLOAT && TARGET_64BIT && TARGET_DOUBLE_FLOAT"
4131 {
4132 rtx reg1 = gen_reg_rtx (SFmode);
4133 rtx reg2 = gen_reg_rtx (SFmode);
4134 rtx reg3 = gen_reg_rtx (DImode);
4135 rtx_code_label *label1 = gen_label_rtx ();
4136 rtx_code_label *label2 = gen_label_rtx ();
4137 rtx test;
4138 REAL_VALUE_TYPE offset;
4139
4140 real_2expN (&offset, 63, SFmode);
4141
4142 mips_emit_move (reg1, const_double_from_real_value (offset, SFmode));
4143 do_pending_stack_adjust ();
4144
4145 test = gen_rtx_GE (VOIDmode, operands[1], reg1);
4146 emit_jump_insn (gen_cbranchsf4 (test, operands[1], reg1, label1));
4147
4148 emit_insn (gen_fix_truncsfdi2 (operands[0], operands[1]));
4149 emit_jump_insn (gen_rtx_SET (pc_rtx, gen_rtx_LABEL_REF (VOIDmode, label2)));
4150 emit_barrier ();
4151
4152 emit_label (label1);
4153 mips_emit_move (reg2, gen_rtx_MINUS (SFmode, operands[1], reg1));
4154 mips_emit_move (reg3, GEN_INT (BITMASK_HIGH));
4155 emit_insn (gen_ashldi3 (reg3, reg3, GEN_INT (32)));
4156
4157 emit_insn (gen_fix_truncsfdi2 (operands[0], reg2));
4158 emit_insn (gen_iordi3 (operands[0], operands[0], reg3));
4159
4160 emit_label (label2);
4161
4162 /* Allow REG_NOTES to be set on last insn (labels don't have enough
4163 fields, and can't be used for REG_NOTES anyway). */
4164 emit_use (stack_pointer_rtx);
4165 DONE;
4166 })
4167 \f
4168 ;;
4169 ;; ....................
4170 ;;
4171 ;; DATA MOVEMENT
4172 ;;
4173 ;; ....................
4174
4175 ;; Bit field extract patterns which use lwl/lwr or ldl/ldr.
4176
4177 (define_expand "extvmisalign<mode>"
4178 [(set (match_operand:GPR 0 "register_operand")
4179 (sign_extract:GPR (match_operand:BLK 1 "memory_operand")
4180 (match_operand 2 "const_int_operand")
4181 (match_operand 3 "const_int_operand")))]
4182 "ISA_HAS_LWL_LWR"
4183 {
4184 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4185 INTVAL (operands[2]),
4186 INTVAL (operands[3]),
4187 /*unsigned=*/ false))
4188 DONE;
4189 else
4190 FAIL;
4191 })
4192
4193 (define_expand "extv<mode>"
4194 [(set (match_operand:GPR 0 "register_operand")
4195 (sign_extract:GPR (match_operand:GPR 1 "register_operand")
4196 (match_operand 2 "const_int_operand")
4197 (match_operand 3 "const_int_operand")))]
4198 "ISA_HAS_EXTS"
4199 {
4200 if (UINTVAL (operands[2]) > 32)
4201 FAIL;
4202 })
4203
4204 (define_insn "*extv<mode>"
4205 [(set (match_operand:GPR 0 "register_operand" "=d")
4206 (sign_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4207 (match_operand 2 "const_int_operand" "")
4208 (match_operand 3 "const_int_operand" "")))]
4209 "ISA_HAS_EXTS && UINTVAL (operands[2]) <= 32"
4210 "exts\t%0,%1,%3,%m2"
4211 [(set_attr "type" "arith")
4212 (set_attr "mode" "<MODE>")])
4213
4214 (define_expand "extzvmisalign<mode>"
4215 [(set (match_operand:GPR 0 "register_operand")
4216 (zero_extract:GPR (match_operand:BLK 1 "memory_operand")
4217 (match_operand 2 "const_int_operand")
4218 (match_operand 3 "const_int_operand")))]
4219 "ISA_HAS_LWL_LWR"
4220 {
4221 if (mips_expand_ext_as_unaligned_load (operands[0], operands[1],
4222 INTVAL (operands[2]),
4223 INTVAL (operands[3]),
4224 /*unsigned=*/ true))
4225 DONE;
4226 else
4227 FAIL;
4228 })
4229
4230 (define_expand "extzv<mode>"
4231 [(set (match_operand:GPR 0 "register_operand")
4232 (zero_extract:GPR (match_operand:GPR 1 "register_operand")
4233 (match_operand 2 "const_int_operand")
4234 (match_operand 3 "const_int_operand")))]
4235 ""
4236 {
4237 if (!mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4238 INTVAL (operands[3])))
4239 FAIL;
4240 })
4241
4242 (define_insn "*extzv<mode>"
4243 [(set (match_operand:GPR 0 "register_operand" "=d")
4244 (zero_extract:GPR (match_operand:GPR 1 "register_operand" "d")
4245 (match_operand 2 "const_int_operand" "")
4246 (match_operand 3 "const_int_operand" "")))]
4247 "mips_use_ins_ext_p (operands[1], INTVAL (operands[2]),
4248 INTVAL (operands[3]))"
4249 "<d>ext\t%0,%1,%3,%2"
4250 [(set_attr "type" "arith")
4251 (set_attr "mode" "<MODE>")])
4252
4253 (define_insn "*extzv_truncsi_exts"
4254 [(set (match_operand:SI 0 "register_operand" "=d")
4255 (truncate:SI
4256 (zero_extract:DI (match_operand:DI 1 "register_operand" "d")
4257 (match_operand 2 "const_int_operand" "")
4258 (match_operand 3 "const_int_operand" ""))))]
4259 "ISA_HAS_EXTS && TARGET_64BIT && IN_RANGE (INTVAL (operands[2]), 32, 63)"
4260 "exts\t%0,%1,%3,31"
4261 [(set_attr "type" "arith")
4262 (set_attr "mode" "SI")])
4263
4264
4265 (define_expand "insvmisalign<mode>"
4266 [(set (zero_extract:GPR (match_operand:BLK 0 "memory_operand")
4267 (match_operand 1 "const_int_operand")
4268 (match_operand 2 "const_int_operand"))
4269 (match_operand:GPR 3 "reg_or_0_operand"))]
4270 "ISA_HAS_LWL_LWR"
4271 {
4272 if (mips_expand_ins_as_unaligned_store (operands[0], operands[3],
4273 INTVAL (operands[1]),
4274 INTVAL (operands[2])))
4275 DONE;
4276 else
4277 FAIL;
4278 })
4279
4280 (define_expand "insv<mode>"
4281 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand")
4282 (match_operand 1 "const_int_operand")
4283 (match_operand 2 "const_int_operand"))
4284 (match_operand:GPR 3 "reg_or_0_operand"))]
4285 ""
4286 {
4287 if (!mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4288 INTVAL (operands[2])))
4289 FAIL;
4290 })
4291
4292 (define_insn "*insv<mode>"
4293 [(set (zero_extract:GPR (match_operand:GPR 0 "register_operand" "+d")
4294 (match_operand:SI 1 "const_int_operand" "")
4295 (match_operand:SI 2 "const_int_operand" ""))
4296 (match_operand:GPR 3 "reg_or_0_operand" "dJ"))]
4297 "mips_use_ins_ext_p (operands[0], INTVAL (operands[1]),
4298 INTVAL (operands[2]))"
4299 "<d>ins\t%0,%z3,%2,%1"
4300 [(set_attr "type" "arith")
4301 (set_attr "mode" "<MODE>")])
4302
4303 ;; Combiner pattern for cins (clear and insert bit field). We can
4304 ;; implement mask-and-shift-left operation with this. Note that if
4305 ;; the upper bit of the mask is set in an SImode operation, the mask
4306 ;; itself will be sign-extended. mask_low_and_shift_len will
4307 ;; therefore be greater than our threshold of 32.
4308
4309 (define_insn "*cins<mode>"
4310 [(set (match_operand:GPR 0 "register_operand" "=d")
4311 (and:GPR
4312 (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
4313 (match_operand:GPR 2 "const_int_operand" ""))
4314 (match_operand:GPR 3 "const_int_operand" "")))]
4315 "ISA_HAS_CINS
4316 && mask_low_and_shift_p (<MODE>mode, operands[3], operands[2], 32)"
4317 {
4318 operands[3] =
4319 GEN_INT (mask_low_and_shift_len (<MODE>mode, operands[3], operands[2]));
4320 return "cins\t%0,%1,%2,%m3";
4321 }
4322 [(set_attr "type" "shift")
4323 (set_attr "mode" "<MODE>")])
4324
4325 ;; Unaligned word moves generated by the bit field patterns.
4326 ;;
4327 ;; As far as the rtl is concerned, both the left-part and right-part
4328 ;; instructions can access the whole field. However, the real operand
4329 ;; refers to just the first or the last byte (depending on endianness).
4330 ;; We therefore use two memory operands to each instruction, one to
4331 ;; describe the rtl effect and one to use in the assembly output.
4332 ;;
4333 ;; Operands 0 and 1 are the rtl-level target and source respectively.
4334 ;; This allows us to use the standard length calculations for the "load"
4335 ;; and "store" type attributes.
4336
4337 (define_insn "mov_<load>l"
4338 [(set (match_operand:GPR 0 "register_operand" "=d")
4339 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4340 (match_operand:QI 2 "memory_operand" "ZC")]
4341 UNSPEC_LOAD_LEFT))]
4342 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4343 "<load>l\t%0,%2"
4344 [(set_attr "move_type" "load")
4345 (set_attr "mode" "<MODE>")])
4346
4347 (define_insn "mov_<load>r"
4348 [(set (match_operand:GPR 0 "register_operand" "=d")
4349 (unspec:GPR [(match_operand:BLK 1 "memory_operand" "m")
4350 (match_operand:QI 2 "memory_operand" "ZC")
4351 (match_operand:GPR 3 "register_operand" "0")]
4352 UNSPEC_LOAD_RIGHT))]
4353 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[1])"
4354 "<load>r\t%0,%2"
4355 [(set_attr "move_type" "load")
4356 (set_attr "mode" "<MODE>")])
4357
4358 (define_insn "mov_<store>l"
4359 [(set (match_operand:BLK 0 "memory_operand" "=m")
4360 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4361 (match_operand:QI 2 "memory_operand" "ZC")]
4362 UNSPEC_STORE_LEFT))]
4363 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4364 "<store>l\t%z1,%2"
4365 [(set_attr "move_type" "store")
4366 (set_attr "mode" "<MODE>")])
4367
4368 (define_insn "mov_<store>r"
4369 [(set (match_operand:BLK 0 "memory_operand" "+m")
4370 (unspec:BLK [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
4371 (match_operand:QI 2 "memory_operand" "ZC")
4372 (match_dup 0)]
4373 UNSPEC_STORE_RIGHT))]
4374 "!TARGET_MIPS16 && mips_mem_fits_mode_p (<MODE>mode, operands[0])"
4375 "<store>r\t%z1,%2"
4376 [(set_attr "move_type" "store")
4377 (set_attr "mode" "<MODE>")])
4378
4379 ;; An instruction to calculate the high part of a 64-bit SYMBOL_ABSOLUTE.
4380 ;; The required value is:
4381 ;;
4382 ;; (%highest(op1) << 48) + (%higher(op1) << 32) + (%hi(op1) << 16)
4383 ;;
4384 ;; which translates to:
4385 ;;
4386 ;; lui op0,%highest(op1)
4387 ;; daddiu op0,op0,%higher(op1)
4388 ;; dsll op0,op0,16
4389 ;; daddiu op0,op0,%hi(op1)
4390 ;; dsll op0,op0,16
4391 ;;
4392 ;; The split is deferred until after flow2 to allow the peephole2 below
4393 ;; to take effect.
4394 (define_insn_and_split "*lea_high64"
4395 [(set (match_operand:DI 0 "register_operand" "=d")
4396 (high:DI (match_operand:DI 1 "absolute_symbolic_operand" "")))]
4397 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4398 "#"
4399 "&& epilogue_completed"
4400 [(set (match_dup 0) (high:DI (match_dup 2)))
4401 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 2)))
4402 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))
4403 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4404 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 16)))]
4405 {
4406 operands[2] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4407 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_MID);
4408 }
4409 [(set_attr "insn_count" "5")])
4410
4411 ;; Use a scratch register to reduce the latency of the above pattern
4412 ;; on superscalar machines. The optimized sequence is:
4413 ;;
4414 ;; lui op1,%highest(op2)
4415 ;; lui op0,%hi(op2)
4416 ;; daddiu op1,op1,%higher(op2)
4417 ;; dsll32 op1,op1,0
4418 ;; daddu op1,op1,op0
4419 (define_peephole2
4420 [(set (match_operand:DI 1 "d_operand")
4421 (high:DI (match_operand:DI 2 "absolute_symbolic_operand")))
4422 (match_scratch:DI 0 "d")]
4423 "TARGET_EXPLICIT_RELOCS && ABI_HAS_64BIT_SYMBOLS"
4424 [(set (match_dup 1) (high:DI (match_dup 3)))
4425 (set (match_dup 0) (high:DI (match_dup 4)))
4426 (set (match_dup 1) (lo_sum:DI (match_dup 1) (match_dup 3)))
4427 (set (match_dup 1) (ashift:DI (match_dup 1) (const_int 32)))
4428 (set (match_dup 1) (plus:DI (match_dup 1) (match_dup 0)))]
4429 {
4430 operands[3] = mips_unspec_address (operands[2], SYMBOL_64_HIGH);
4431 operands[4] = mips_unspec_address (operands[2], SYMBOL_64_LOW);
4432 })
4433
4434 ;; On most targets, the expansion of (lo_sum (high X) X) for a 64-bit
4435 ;; SYMBOL_ABSOLUTE X will take 6 cycles. This next pattern allows combine
4436 ;; to merge the HIGH and LO_SUM parts of a move if the HIGH part is only
4437 ;; used once. We can then use the sequence:
4438 ;;
4439 ;; lui op0,%highest(op1)
4440 ;; lui op2,%hi(op1)
4441 ;; daddiu op0,op0,%higher(op1)
4442 ;; daddiu op2,op2,%lo(op1)
4443 ;; dsll32 op0,op0,0
4444 ;; daddu op0,op0,op2
4445 ;;
4446 ;; which takes 4 cycles on most superscalar targets.
4447 (define_insn_and_split "*lea64"
4448 [(set (match_operand:DI 0 "register_operand" "=d")
4449 (match_operand:DI 1 "absolute_symbolic_operand" ""))
4450 (clobber (match_scratch:DI 2 "=&d"))]
4451 "!TARGET_MIPS16
4452 && TARGET_EXPLICIT_RELOCS
4453 && ABI_HAS_64BIT_SYMBOLS
4454 && cse_not_expected"
4455 "#"
4456 "&& reload_completed"
4457 [(set (match_dup 0) (high:DI (match_dup 3)))
4458 (set (match_dup 2) (high:DI (match_dup 4)))
4459 (set (match_dup 0) (lo_sum:DI (match_dup 0) (match_dup 3)))
4460 (set (match_dup 2) (lo_sum:DI (match_dup 2) (match_dup 4)))
4461 (set (match_dup 0) (ashift:DI (match_dup 0) (const_int 32)))
4462 (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 2)))]
4463 {
4464 operands[3] = mips_unspec_address (operands[1], SYMBOL_64_HIGH);
4465 operands[4] = mips_unspec_address (operands[1], SYMBOL_64_LOW);
4466 }
4467 [(set_attr "insn_count" "6")])
4468
4469 ;; Split HIGHs into:
4470 ;;
4471 ;; li op0,%hi(sym)
4472 ;; sll op0,16
4473 ;;
4474 ;; on MIPS16 targets.
4475 (define_split
4476 [(set (match_operand:P 0 "d_operand")
4477 (high:P (match_operand:P 1 "symbolic_operand_with_high")))]
4478 "TARGET_MIPS16 && reload_completed"
4479 [(set (match_dup 0) (unspec:P [(match_dup 1)] UNSPEC_UNSHIFTED_HIGH))
4480 (set (match_dup 0) (ashift:P (match_dup 0) (const_int 16)))])
4481
4482 (define_insn "*unshifted_high"
4483 [(set (match_operand:P 0 "d_operand" "=d")
4484 (unspec:P [(match_operand:P 1 "symbolic_operand_with_high")]
4485 UNSPEC_UNSHIFTED_HIGH))]
4486 ""
4487 "li\t%0,%h1"
4488 [(set_attr "extended_mips16" "yes")])
4489
4490 ;; Insns to fetch a symbol from a big GOT.
4491
4492 (define_insn_and_split "*xgot_hi<mode>"
4493 [(set (match_operand:P 0 "register_operand" "=d")
4494 (high:P (match_operand:P 1 "got_disp_operand" "")))]
4495 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4496 "#"
4497 "&& reload_completed"
4498 [(set (match_dup 0) (high:P (match_dup 2)))
4499 (set (match_dup 0) (plus:P (match_dup 0) (match_dup 3)))]
4500 {
4501 operands[2] = mips_unspec_address (operands[1], SYMBOL_GOTOFF_DISP);
4502 operands[3] = pic_offset_table_rtx;
4503 }
4504 [(set_attr "got" "xgot_high")
4505 (set_attr "mode" "<MODE>")])
4506
4507 (define_insn_and_split "*xgot_lo<mode>"
4508 [(set (match_operand:P 0 "register_operand" "=d")
4509 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4510 (match_operand:P 2 "got_disp_operand" "")))]
4511 "TARGET_EXPLICIT_RELOCS && TARGET_XGOT"
4512 "#"
4513 "&& reload_completed"
4514 [(set (match_dup 0)
4515 (unspec:P [(match_dup 1) (match_dup 3)] UNSPEC_LOAD_GOT))]
4516 { operands[3] = mips_unspec_address (operands[2], SYMBOL_GOTOFF_DISP); }
4517 [(set_attr "got" "load")
4518 (set_attr "mode" "<MODE>")])
4519
4520 ;; Insns to fetch a symbol from a normal GOT.
4521
4522 (define_insn_and_split "*got_disp<mode>"
4523 [(set (match_operand:P 0 "register_operand" "=d")
4524 (match_operand:P 1 "got_disp_operand" ""))]
4525 "TARGET_EXPLICIT_RELOCS && !mips_split_p[SYMBOL_GOT_DISP]"
4526 "#"
4527 "&& reload_completed"
4528 [(set (match_dup 0) (match_dup 2))]
4529 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_DISP); }
4530 [(set_attr "got" "load")
4531 (set_attr "mode" "<MODE>")])
4532
4533 ;; Insns for loading the "page" part of a page/ofst address from the GOT.
4534
4535 (define_insn_and_split "*got_page<mode>"
4536 [(set (match_operand:P 0 "register_operand" "=d")
4537 (high:P (match_operand:P 1 "got_page_ofst_operand" "")))]
4538 "TARGET_EXPLICIT_RELOCS && !mips_split_hi_p[SYMBOL_GOT_PAGE_OFST]"
4539 "#"
4540 "&& reload_completed"
4541 [(set (match_dup 0) (match_dup 2))]
4542 { operands[2] = mips_got_load (NULL, operands[1], SYMBOL_GOTOFF_PAGE); }
4543 [(set_attr "got" "load")
4544 (set_attr "mode" "<MODE>")])
4545
4546 ;; Convenience expander that generates the rhs of a load_got<mode> insn.
4547 (define_expand "unspec_got_<mode>"
4548 [(unspec:P [(match_operand:P 0)
4549 (match_operand:P 1)] UNSPEC_LOAD_GOT)])
4550
4551 ;; Lower-level instructions for loading an address from the GOT.
4552 ;; We could use MEMs, but an unspec gives more optimization
4553 ;; opportunities.
4554
4555 (define_insn "load_got<mode>"
4556 [(set (match_operand:P 0 "register_operand" "=d")
4557 (unspec:P [(match_operand:P 1 "register_operand" "d")
4558 (match_operand:P 2 "immediate_operand" "")]
4559 UNSPEC_LOAD_GOT))]
4560 ""
4561 "<load>\t%0,%R2(%1)"
4562 [(set_attr "got" "load")
4563 (set_attr "mode" "<MODE>")])
4564
4565 ;; Instructions for adding the low 16 bits of an address to a register.
4566 ;; Operand 2 is the address: mips_print_operand works out which relocation
4567 ;; should be applied.
4568
4569 (define_insn "*low<mode>"
4570 [(set (match_operand:P 0 "register_operand" "=d")
4571 (lo_sum:P (match_operand:P 1 "register_operand" "d")
4572 (match_operand:P 2 "immediate_operand" "")))]
4573 "!TARGET_MIPS16"
4574 "<d>addiu\t%0,%1,%R2"
4575 [(set_attr "alu_type" "add")
4576 (set_attr "mode" "<MODE>")])
4577
4578 (define_insn "*low<mode>_mips16"
4579 [(set (match_operand:P 0 "register_operand" "=d")
4580 (lo_sum:P (match_operand:P 1 "register_operand" "0")
4581 (match_operand:P 2 "immediate_operand" "")))]
4582 "TARGET_MIPS16"
4583 "<d>addiu\t%0,%R2"
4584 [(set_attr "alu_type" "add")
4585 (set_attr "mode" "<MODE>")
4586 (set_attr "extended_mips16" "yes")])
4587
4588 ;; Expose MIPS16 uses of the global pointer after reload if the function
4589 ;; is responsible for setting up the register itself.
4590 (define_split
4591 [(set (match_operand:GPR 0 "d_operand")
4592 (const:GPR (unspec:GPR [(const_int 0)] UNSPEC_GP)))]
4593 "TARGET_MIPS16 && TARGET_USE_GOT && reload_completed"
4594 [(set (match_dup 0) (match_dup 1))]
4595 { operands[1] = pic_offset_table_rtx; })
4596
4597 ;; Allow combine to split complex const_int load sequences, using operand 2
4598 ;; to store the intermediate results. See move_operand for details.
4599 (define_split
4600 [(set (match_operand:GPR 0 "register_operand")
4601 (match_operand:GPR 1 "splittable_const_int_operand"))
4602 (clobber (match_operand:GPR 2 "register_operand"))]
4603 ""
4604 [(const_int 0)]
4605 {
4606 mips_move_integer (operands[2], operands[0], INTVAL (operands[1]));
4607 DONE;
4608 })
4609
4610 ;; Likewise, for symbolic operands.
4611 (define_split
4612 [(set (match_operand:P 0 "register_operand")
4613 (match_operand:P 1))
4614 (clobber (match_operand:P 2 "register_operand"))]
4615 "mips_split_symbol (operands[2], operands[1], MAX_MACHINE_MODE, NULL)"
4616 [(set (match_dup 0) (match_dup 3))]
4617 {
4618 mips_split_symbol (operands[2], operands[1],
4619 MAX_MACHINE_MODE, &operands[3]);
4620 })
4621
4622 ;; 64-bit integer moves
4623
4624 ;; Unlike most other insns, the move insns can't be split with
4625 ;; different predicates, because register spilling and other parts of
4626 ;; the compiler, have memoized the insn number already.
4627
4628 (define_expand "movdi"
4629 [(set (match_operand:DI 0 "")
4630 (match_operand:DI 1 ""))]
4631 ""
4632 {
4633 if (mips_legitimize_move (DImode, operands[0], operands[1]))
4634 DONE;
4635 })
4636
4637 ;; For mips16, we need a special case to handle storing $31 into
4638 ;; memory, since we don't have a constraint to match $31. This
4639 ;; instruction can be generated by save_restore_insns.
4640
4641 (define_insn "*mov<mode>_ra"
4642 [(set (match_operand:GPR 0 "stack_operand" "=m")
4643 (reg:GPR RETURN_ADDR_REGNUM))]
4644 "TARGET_MIPS16"
4645 "<store>\t$31,%0"
4646 [(set_attr "move_type" "store")
4647 (set_attr "mode" "<MODE>")])
4648
4649 (define_insn "*movdi_32bit"
4650 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d,*f,*f,*d,*m,*B*C*D,*B*C*D,*d,*m")
4651 (match_operand:DI 1 "move_operand" "d,i,m,d,*J,*d,*a,*J*d,*m,*f,*f,*d,*m,*B*C*D,*B*C*D"))]
4652 "!TARGET_64BIT && !TARGET_MIPS16
4653 && (register_operand (operands[0], DImode)
4654 || reg_or_0_operand (operands[1], DImode))"
4655 { return mips_output_move (operands[0], operands[1]); }
4656 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo,mtc,fpload,mfc,fpstore,mtc,fpload,mfc,fpstore")
4657 (set (attr "mode")
4658 (if_then_else (eq_attr "move_type" "imul")
4659 (const_string "SI")
4660 (const_string "DI")))])
4661
4662 (define_insn "*movdi_32bit_mips16"
4663 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4664 (match_operand:DI 1 "move_operand" "d,d,y,K,N,m,d,*x"))]
4665 "!TARGET_64BIT && TARGET_MIPS16
4666 && (register_operand (operands[0], DImode)
4667 || register_operand (operands[1], DImode))"
4668 { return mips_output_move (operands[0], operands[1]); }
4669 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4670 (set_attr "mode" "DI")])
4671
4672 (define_insn "*movdi_64bit"
4673 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,d,e,d,m,*f,*f,*d,*m,*a,*d,*B*C*D,*B*C*D,*d,*m")
4674 (match_operand:DI 1 "move_operand" "d,Yd,Yf,m,dJ,*d*J,*m,*f,*f,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4675 "TARGET_64BIT && !TARGET_MIPS16
4676 && (register_operand (operands[0], DImode)
4677 || reg_or_0_operand (operands[1], DImode))"
4678 { return mips_output_move (operands[0], operands[1]); }
4679 [(set_attr "move_type" "move,const,const,load,store,mtc,fpload,mfc,fpstore,mtlo,mflo,mtc,fpload,mfc,fpstore")
4680 (set_attr "mode" "DI")])
4681
4682 (define_insn "*movdi_64bit_mips16"
4683 [(set (match_operand:DI 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4684 (match_operand:DI 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4685 "TARGET_64BIT && TARGET_MIPS16
4686 && (register_operand (operands[0], DImode)
4687 || register_operand (operands[1], DImode))"
4688 { return mips_output_move (operands[0], operands[1]); }
4689 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4690 (set_attr "mode" "DI")])
4691
4692 ;; On the mips16, we can split ld $r,N($r) into an add and a load,
4693 ;; when the original load is a 4 byte instruction but the add and the
4694 ;; load are 2 2 byte instructions.
4695
4696 (define_split
4697 [(set (match_operand:DI 0 "d_operand")
4698 (mem:DI (plus:DI (match_dup 0)
4699 (match_operand:DI 1 "const_int_operand"))))]
4700 "TARGET_64BIT && TARGET_MIPS16 && reload_completed
4701 && !TARGET_DEBUG_D_MODE
4702 && ((INTVAL (operands[1]) < 0
4703 && INTVAL (operands[1]) >= -0x10)
4704 || (INTVAL (operands[1]) >= 32 * 8
4705 && INTVAL (operands[1]) <= 31 * 8 + 0x8)
4706 || (INTVAL (operands[1]) >= 0
4707 && INTVAL (operands[1]) < 32 * 8
4708 && (INTVAL (operands[1]) & 7) != 0))"
4709 [(set (match_dup 0) (plus:DI (match_dup 0) (match_dup 1)))
4710 (set (match_dup 0) (mem:DI (plus:DI (match_dup 0) (match_dup 2))))]
4711 {
4712 HOST_WIDE_INT val = INTVAL (operands[1]);
4713
4714 if (val < 0)
4715 operands[2] = const0_rtx;
4716 else if (val >= 32 * 8)
4717 {
4718 int off = val & 7;
4719
4720 operands[1] = GEN_INT (0x8 + off);
4721 operands[2] = GEN_INT (val - off - 0x8);
4722 }
4723 else
4724 {
4725 int off = val & 7;
4726
4727 operands[1] = GEN_INT (off);
4728 operands[2] = GEN_INT (val - off);
4729 }
4730 })
4731
4732 ;; 32-bit Integer moves
4733
4734 ;; Unlike most other insns, the move insns can't be split with
4735 ;; different predicates, because register spilling and other parts of
4736 ;; the compiler, have memoized the insn number already.
4737
4738 (define_expand "mov<mode>"
4739 [(set (match_operand:IMOVE32 0 "")
4740 (match_operand:IMOVE32 1 ""))]
4741 ""
4742 {
4743 if (mips_legitimize_move (<MODE>mode, operands[0], operands[1]))
4744 DONE;
4745 })
4746
4747 ;; The difference between these two is whether or not ints are allowed
4748 ;; in FP registers (off by default, use -mdebugh to enable).
4749
4750 (define_insn "*mov<mode>_internal"
4751 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,!u,!u,d,e,!u,!ks,d,ZS,ZT,m,*f,*f,*d,*m,*d,*z,*a,*d,*B*C*D,*B*C*D,*d,*m")
4752 (match_operand:IMOVE32 1 "move_operand" "d,J,Udb7,Yd,Yf,ZT,ZS,m,!ks,!kbJ,dJ,*d*J,*m,*f,*f,*z,*d,*J*d,*a,*d,*m,*B*C*D,*B*C*D"))]
4753 "!TARGET_MIPS16
4754 && (register_operand (operands[0], <MODE>mode)
4755 || reg_or_0_operand (operands[1], <MODE>mode))"
4756 { return mips_output_move (operands[0], operands[1]); }
4757 [(set_attr "move_type" "move,move,const,const,const,load,load,load,store,store,store,mtc,fpload,mfc,fpstore,mfc,mtc,mtlo,mflo,mtc,fpload,mfc,fpstore")
4758 (set_attr "compression" "all,micromips,micromips,*,*,micromips,micromips,*,micromips,micromips,*,*,*,*,*,*,*,*,*,*,*,*,*")
4759 (set_attr "mode" "SI")])
4760
4761 (define_insn "*mov<mode>_mips16"
4762 [(set (match_operand:IMOVE32 0 "nonimmediate_operand" "=d,y,d,d,d,d,d,d,m,*d")
4763 (match_operand:IMOVE32 1 "move_operand" "d,d,y,K,N,Yd,kf,m,d,*a"))]
4764 "TARGET_MIPS16
4765 && (register_operand (operands[0], <MODE>mode)
4766 || register_operand (operands[1], <MODE>mode))"
4767 { return mips_output_move (operands[0], operands[1]); }
4768 [(set_attr "move_type" "move,move,move,const,constN,const,loadpool,load,store,mflo")
4769 (set_attr "mode" "SI")])
4770
4771 ;; On the mips16, we can split lw $r,N($r) into an add and a load,
4772 ;; when the original load is a 4 byte instruction but the add and the
4773 ;; load are 2 2 byte instructions.
4774
4775 (define_split
4776 [(set (match_operand:SI 0 "d_operand")
4777 (mem:SI (plus:SI (match_dup 0)
4778 (match_operand:SI 1 "const_int_operand"))))]
4779 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4780 && ((INTVAL (operands[1]) < 0
4781 && INTVAL (operands[1]) >= -0x80)
4782 || (INTVAL (operands[1]) >= 32 * 4
4783 && INTVAL (operands[1]) <= 31 * 4 + 0x7c)
4784 || (INTVAL (operands[1]) >= 0
4785 && INTVAL (operands[1]) < 32 * 4
4786 && (INTVAL (operands[1]) & 3) != 0))"
4787 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4788 (set (match_dup 0) (mem:SI (plus:SI (match_dup 0) (match_dup 2))))]
4789 {
4790 HOST_WIDE_INT val = INTVAL (operands[1]);
4791
4792 if (val < 0)
4793 operands[2] = const0_rtx;
4794 else if (val >= 32 * 4)
4795 {
4796 int off = val & 3;
4797
4798 operands[1] = GEN_INT (0x7c + off);
4799 operands[2] = GEN_INT (val - off - 0x7c);
4800 }
4801 else
4802 {
4803 int off = val & 3;
4804
4805 operands[1] = GEN_INT (off);
4806 operands[2] = GEN_INT (val - off);
4807 }
4808 })
4809
4810 ;; On the mips16, we can split a load of certain constants into a load
4811 ;; and an add. This turns a 4 byte instruction into 2 2 byte
4812 ;; instructions.
4813
4814 (define_split
4815 [(set (match_operand:SI 0 "d_operand")
4816 (match_operand:SI 1 "const_int_operand"))]
4817 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4818 && INTVAL (operands[1]) >= 0x100
4819 && INTVAL (operands[1]) <= 0xff + 0x7f"
4820 [(set (match_dup 0) (match_dup 1))
4821 (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 2)))]
4822 {
4823 int val = INTVAL (operands[1]);
4824
4825 operands[1] = GEN_INT (0xff);
4826 operands[2] = GEN_INT (val - 0xff);
4827 })
4828
4829 ;; MIPS4 supports loading and storing a floating point register from
4830 ;; the sum of two general registers. We use two versions for each of
4831 ;; these four instructions: one where the two general registers are
4832 ;; SImode, and one where they are DImode. This is because general
4833 ;; registers will be in SImode when they hold 32-bit values, but,
4834 ;; since the 32-bit values are always sign extended, the [ls][wd]xc1
4835 ;; instructions will still work correctly.
4836
4837 ;; ??? Perhaps it would be better to support these instructions by
4838 ;; modifying TARGET_LEGITIMATE_ADDRESS_P and friends. However, since
4839 ;; these instructions can only be used to load and store floating
4840 ;; point registers, that would probably cause trouble in reload.
4841
4842 (define_insn "*<ANYF:loadx>_<P:mode>"
4843 [(set (match_operand:ANYF 0 "register_operand" "=f")
4844 (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4845 (match_operand:P 2 "register_operand" "d"))))]
4846 "ISA_HAS_LXC1_SXC1"
4847 "<ANYF:loadx>\t%0,%1(%2)"
4848 [(set_attr "type" "fpidxload")
4849 (set_attr "mode" "<ANYF:UNITMODE>")])
4850
4851 (define_insn "*<ANYF:storex>_<P:mode>"
4852 [(set (mem:ANYF (plus:P (match_operand:P 1 "register_operand" "d")
4853 (match_operand:P 2 "register_operand" "d")))
4854 (match_operand:ANYF 0 "register_operand" "f"))]
4855 "ISA_HAS_LXC1_SXC1"
4856 "<ANYF:storex>\t%0,%1(%2)"
4857 [(set_attr "type" "fpidxstore")
4858 (set_attr "mode" "<ANYF:UNITMODE>")])
4859
4860 ;; Scaled indexed address load.
4861 ;; Per md.texi, we only need to look for a pattern with multiply in the
4862 ;; address expression, not shift.
4863
4864 (define_insn "*lwxs"
4865 [(set (match_operand:IMOVE32 0 "register_operand" "=d")
4866 (mem:IMOVE32
4867 (plus:P (mult:P (match_operand:P 1 "register_operand" "d")
4868 (const_int 4))
4869 (match_operand:P 2 "register_operand" "d"))))]
4870 "ISA_HAS_LWXS"
4871 "lwxs\t%0,%1(%2)"
4872 [(set_attr "type" "load")
4873 (set_attr "mode" "SI")])
4874
4875 ;; 16-bit Integer moves
4876
4877 ;; Unlike most other insns, the move insns can't be split with
4878 ;; different predicates, because register spilling and other parts of
4879 ;; the compiler, have memoized the insn number already.
4880 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4881
4882 (define_expand "movhi"
4883 [(set (match_operand:HI 0 "")
4884 (match_operand:HI 1 ""))]
4885 ""
4886 {
4887 if (mips_legitimize_move (HImode, operands[0], operands[1]))
4888 DONE;
4889 })
4890
4891 (define_insn "*movhi_internal"
4892 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZU,m,*a,*d")
4893 (match_operand:HI 1 "move_operand" "d,J,I,ZU,m,!kbJ,dJ,*d*J,*a"))]
4894 "!TARGET_MIPS16
4895 && (register_operand (operands[0], HImode)
4896 || reg_or_0_operand (operands[1], HImode))"
4897 { return mips_output_move (operands[0], operands[1]); }
4898 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4899 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4900 (set_attr "mode" "HI")])
4901
4902 (define_insn "*movhi_mips16"
4903 [(set (match_operand:HI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4904 (match_operand:HI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4905 "TARGET_MIPS16
4906 && (register_operand (operands[0], HImode)
4907 || register_operand (operands[1], HImode))"
4908 { return mips_output_move (operands[0], operands[1]); }
4909 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4910 (set_attr "mode" "HI")])
4911
4912 ;; On the mips16, we can split lh $r,N($r) into an add and a load,
4913 ;; when the original load is a 4 byte instruction but the add and the
4914 ;; load are 2 2 byte instructions.
4915
4916 (define_split
4917 [(set (match_operand:HI 0 "d_operand")
4918 (mem:HI (plus:SI (match_dup 0)
4919 (match_operand:SI 1 "const_int_operand"))))]
4920 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4921 && ((INTVAL (operands[1]) < 0
4922 && INTVAL (operands[1]) >= -0x80)
4923 || (INTVAL (operands[1]) >= 32 * 2
4924 && INTVAL (operands[1]) <= 31 * 2 + 0x7e)
4925 || (INTVAL (operands[1]) >= 0
4926 && INTVAL (operands[1]) < 32 * 2
4927 && (INTVAL (operands[1]) & 1) != 0))"
4928 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
4929 (set (match_dup 0) (mem:HI (plus:SI (match_dup 0) (match_dup 2))))]
4930 {
4931 HOST_WIDE_INT val = INTVAL (operands[1]);
4932
4933 if (val < 0)
4934 operands[2] = const0_rtx;
4935 else if (val >= 32 * 2)
4936 {
4937 int off = val & 1;
4938
4939 operands[1] = GEN_INT (0x7e + off);
4940 operands[2] = GEN_INT (val - off - 0x7e);
4941 }
4942 else
4943 {
4944 int off = val & 1;
4945
4946 operands[1] = GEN_INT (off);
4947 operands[2] = GEN_INT (val - off);
4948 }
4949 })
4950
4951 ;; 8-bit Integer moves
4952
4953 ;; Unlike most other insns, the move insns can't be split with
4954 ;; different predicates, because register spilling and other parts of
4955 ;; the compiler, have memoized the insn number already.
4956 ;; Unsigned loads are used because LOAD_EXTEND_OP returns ZERO_EXTEND.
4957
4958 (define_expand "movqi"
4959 [(set (match_operand:QI 0 "")
4960 (match_operand:QI 1 ""))]
4961 ""
4962 {
4963 if (mips_legitimize_move (QImode, operands[0], operands[1]))
4964 DONE;
4965 })
4966
4967 (define_insn "*movqi_internal"
4968 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,!u,d,!u,d,ZV,m,*a,*d")
4969 (match_operand:QI 1 "move_operand" "d,J,I,ZW,m,!kbJ,dJ,*d*J,*a"))]
4970 "!TARGET_MIPS16
4971 && (register_operand (operands[0], QImode)
4972 || reg_or_0_operand (operands[1], QImode))"
4973 { return mips_output_move (operands[0], operands[1]); }
4974 [(set_attr "move_type" "move,const,const,load,load,store,store,mtlo,mflo")
4975 (set_attr "compression" "all,micromips,*,micromips,*,micromips,*,*,*")
4976 (set_attr "mode" "QI")])
4977
4978 (define_insn "*movqi_mips16"
4979 [(set (match_operand:QI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
4980 (match_operand:QI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
4981 "TARGET_MIPS16
4982 && (register_operand (operands[0], QImode)
4983 || register_operand (operands[1], QImode))"
4984 { return mips_output_move (operands[0], operands[1]); }
4985 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
4986 (set_attr "mode" "QI")])
4987
4988 ;; On the mips16, we can split lb $r,N($r) into an add and a load,
4989 ;; when the original load is a 4 byte instruction but the add and the
4990 ;; load are 2 2 byte instructions.
4991
4992 (define_split
4993 [(set (match_operand:QI 0 "d_operand")
4994 (mem:QI (plus:SI (match_dup 0)
4995 (match_operand:SI 1 "const_int_operand"))))]
4996 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
4997 && ((INTVAL (operands[1]) < 0
4998 && INTVAL (operands[1]) >= -0x80)
4999 || (INTVAL (operands[1]) >= 32
5000 && INTVAL (operands[1]) <= 31 + 0x7f))"
5001 [(set (match_dup 0) (plus:SI (match_dup 0) (match_dup 1)))
5002 (set (match_dup 0) (mem:QI (plus:SI (match_dup 0) (match_dup 2))))]
5003 {
5004 HOST_WIDE_INT val = INTVAL (operands[1]);
5005
5006 if (val < 0)
5007 operands[2] = const0_rtx;
5008 else
5009 {
5010 operands[1] = GEN_INT (0x7f);
5011 operands[2] = GEN_INT (val - 0x7f);
5012 }
5013 })
5014
5015 ;; 32-bit floating point moves
5016
5017 (define_expand "movsf"
5018 [(set (match_operand:SF 0 "")
5019 (match_operand:SF 1 ""))]
5020 ""
5021 {
5022 if (mips_legitimize_move (SFmode, operands[0], operands[1]))
5023 DONE;
5024 })
5025
5026 (define_insn "movccf"
5027 [(set (match_operand:CCF 0 "nonimmediate_operand" "=f,f,m")
5028 (match_operand:CCF 1 "nonimmediate_operand" "f,m,f"))]
5029 "ISA_HAS_CCF"
5030 { return mips_output_move (operands[0], operands[1]); }
5031 [(set_attr "move_type" "fmove,fpload,fpstore")])
5032
5033 (define_insn "*movsf_hardfloat"
5034 [(set (match_operand:SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5035 (match_operand:SF 1 "move_operand" "f,G,m,f,G,*d,*f,*G*d,*m,*d"))]
5036 "TARGET_HARD_FLOAT
5037 && (register_operand (operands[0], SFmode)
5038 || reg_or_0_operand (operands[1], SFmode))"
5039 { return mips_output_move (operands[0], operands[1]); }
5040 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5041 (set_attr "mode" "SF")])
5042
5043 (define_insn "*movsf_softfloat"
5044 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,d,m")
5045 (match_operand:SF 1 "move_operand" "Gd,m,d"))]
5046 "TARGET_SOFT_FLOAT && !TARGET_MIPS16
5047 && (register_operand (operands[0], SFmode)
5048 || reg_or_0_operand (operands[1], SFmode))"
5049 { return mips_output_move (operands[0], operands[1]); }
5050 [(set_attr "move_type" "move,load,store")
5051 (set_attr "mode" "SF")])
5052
5053 (define_insn "*movsf_mips16"
5054 [(set (match_operand:SF 0 "nonimmediate_operand" "=d,y,d,d,m")
5055 (match_operand:SF 1 "move_operand" "d,d,y,m,d"))]
5056 "TARGET_MIPS16
5057 && (register_operand (operands[0], SFmode)
5058 || register_operand (operands[1], SFmode))"
5059 { return mips_output_move (operands[0], operands[1]); }
5060 [(set_attr "move_type" "move,move,move,load,store")
5061 (set_attr "mode" "SF")])
5062
5063 ;; 64-bit floating point moves
5064
5065 (define_expand "movdf"
5066 [(set (match_operand:DF 0 "")
5067 (match_operand:DF 1 ""))]
5068 ""
5069 {
5070 if (mips_legitimize_move (DFmode, operands[0], operands[1]))
5071 DONE;
5072 })
5073
5074 (define_insn "*movdf_hardfloat"
5075 [(set (match_operand:DF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5076 (match_operand:DF 1 "move_operand" "f,G,m,f,G,*d,*f,*d*G,*m,*d"))]
5077 "TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT
5078 && (register_operand (operands[0], DFmode)
5079 || reg_or_0_operand (operands[1], DFmode))"
5080 { return mips_output_move (operands[0], operands[1]); }
5081 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5082 (set_attr "mode" "DF")])
5083
5084 (define_insn "*movdf_softfloat"
5085 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,d,m")
5086 (match_operand:DF 1 "move_operand" "dG,m,dG"))]
5087 "(TARGET_SOFT_FLOAT || TARGET_SINGLE_FLOAT) && !TARGET_MIPS16
5088 && (register_operand (operands[0], DFmode)
5089 || reg_or_0_operand (operands[1], DFmode))"
5090 { return mips_output_move (operands[0], operands[1]); }
5091 [(set_attr "move_type" "move,load,store")
5092 (set_attr "mode" "DF")])
5093
5094 (define_insn "*movdf_mips16"
5095 [(set (match_operand:DF 0 "nonimmediate_operand" "=d,y,d,d,m")
5096 (match_operand:DF 1 "move_operand" "d,d,y,m,d"))]
5097 "TARGET_MIPS16
5098 && (register_operand (operands[0], DFmode)
5099 || register_operand (operands[1], DFmode))"
5100 { return mips_output_move (operands[0], operands[1]); }
5101 [(set_attr "move_type" "move,move,move,load,store")
5102 (set_attr "mode" "DF")])
5103
5104 ;; 128-bit integer moves
5105
5106 (define_expand "movti"
5107 [(set (match_operand:TI 0)
5108 (match_operand:TI 1))]
5109 "TARGET_64BIT"
5110 {
5111 if (mips_legitimize_move (TImode, operands[0], operands[1]))
5112 DONE;
5113 })
5114
5115 (define_insn "*movti"
5116 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,d,d,m,*a,*a,*d")
5117 (match_operand:TI 1 "move_operand" "d,i,m,dJ,*J,*d,*a"))]
5118 "TARGET_64BIT
5119 && !TARGET_MIPS16
5120 && (register_operand (operands[0], TImode)
5121 || reg_or_0_operand (operands[1], TImode))"
5122 { return mips_output_move (operands[0], operands[1]); }
5123 [(set_attr "move_type" "move,const,load,store,imul,mtlo,mflo")
5124 (set (attr "mode")
5125 (if_then_else (eq_attr "move_type" "imul")
5126 (const_string "SI")
5127 (const_string "TI")))])
5128
5129 (define_insn "*movti_mips16"
5130 [(set (match_operand:TI 0 "nonimmediate_operand" "=d,y,d,d,d,d,m,*d")
5131 (match_operand:TI 1 "move_operand" "d,d,y,K,N,m,d,*a"))]
5132 "TARGET_64BIT
5133 && TARGET_MIPS16
5134 && (register_operand (operands[0], TImode)
5135 || register_operand (operands[1], TImode))"
5136 "#"
5137 [(set_attr "move_type" "move,move,move,const,constN,load,store,mflo")
5138 (set_attr "mode" "TI")])
5139
5140 ;; 128-bit floating point moves
5141
5142 (define_expand "movtf"
5143 [(set (match_operand:TF 0)
5144 (match_operand:TF 1))]
5145 "TARGET_64BIT"
5146 {
5147 if (mips_legitimize_move (TFmode, operands[0], operands[1]))
5148 DONE;
5149 })
5150
5151 ;; This pattern handles both hard- and soft-float cases.
5152 (define_insn "*movtf"
5153 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,d,m,f,d,f,m")
5154 (match_operand:TF 1 "move_operand" "dG,m,dG,dG,f,m,f"))]
5155 "TARGET_64BIT
5156 && !TARGET_MIPS16
5157 && (register_operand (operands[0], TFmode)
5158 || reg_or_0_operand (operands[1], TFmode))"
5159 "#"
5160 [(set_attr "move_type" "move,load,store,mtc,mfc,fpload,fpstore")
5161 (set_attr "mode" "TF")])
5162
5163 (define_insn "*movtf_mips16"
5164 [(set (match_operand:TF 0 "nonimmediate_operand" "=d,y,d,d,m")
5165 (match_operand:TF 1 "move_operand" "d,d,y,m,d"))]
5166 "TARGET_64BIT
5167 && TARGET_MIPS16
5168 && (register_operand (operands[0], TFmode)
5169 || register_operand (operands[1], TFmode))"
5170 "#"
5171 [(set_attr "move_type" "move,move,move,load,store")
5172 (set_attr "mode" "TF")])
5173
5174 (define_split
5175 [(set (match_operand:MOVE64 0 "nonimmediate_operand")
5176 (match_operand:MOVE64 1 "move_operand"))]
5177 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5178 [(const_int 0)]
5179 {
5180 mips_split_move_insn (operands[0], operands[1], curr_insn);
5181 DONE;
5182 })
5183
5184 (define_split
5185 [(set (match_operand:MOVE128 0 "nonimmediate_operand")
5186 (match_operand:MOVE128 1 "move_operand"))]
5187 "reload_completed && mips_split_move_insn_p (operands[0], operands[1], insn)"
5188 [(const_int 0)]
5189 {
5190 mips_split_move_insn (operands[0], operands[1], curr_insn);
5191 DONE;
5192 })
5193
5194 ;; When generating mips16 code, split moves of negative constants into
5195 ;; a positive "li" followed by a negation.
5196 (define_split
5197 [(set (match_operand 0 "d_operand")
5198 (match_operand 1 "const_int_operand"))]
5199 "TARGET_MIPS16 && reload_completed && INTVAL (operands[1]) < 0"
5200 [(set (match_dup 2)
5201 (match_dup 3))
5202 (set (match_dup 2)
5203 (neg:SI (match_dup 2)))]
5204 {
5205 operands[2] = gen_lowpart (SImode, operands[0]);
5206 operands[3] = GEN_INT (-INTVAL (operands[1]));
5207 })
5208
5209 ;; 64-bit paired-single floating point moves
5210
5211 (define_expand "movv2sf"
5212 [(set (match_operand:V2SF 0)
5213 (match_operand:V2SF 1))]
5214 "TARGET_HARD_FLOAT && TARGET_PAIRED_SINGLE_FLOAT"
5215 {
5216 if (mips_legitimize_move (V2SFmode, operands[0], operands[1]))
5217 DONE;
5218 })
5219
5220 (define_insn "*movv2sf"
5221 [(set (match_operand:V2SF 0 "nonimmediate_operand" "=f,f,f,m,m,*f,*d,*d,*d,*m")
5222 (match_operand:V2SF 1 "move_operand" "f,YG,m,f,YG,*d,*f,*d*YG,*m,*d"))]
5223 "TARGET_HARD_FLOAT
5224 && TARGET_PAIRED_SINGLE_FLOAT
5225 && (register_operand (operands[0], V2SFmode)
5226 || reg_or_0_operand (operands[1], V2SFmode))"
5227 { return mips_output_move (operands[0], operands[1]); }
5228 [(set_attr "move_type" "fmove,mtc,fpload,fpstore,store,mtc,mfc,move,load,store")
5229 (set_attr "mode" "DF")])
5230
5231 ;; Extract the high part of a HI/LO value. See mips_hard_regno_mode_ok_p
5232 ;; for the reason why we can't just use (reg:GPR HI_REGNUM).
5233 ;;
5234 ;; When generating VR4120 or VR4130 code, we use MACCHI and DMACCHI
5235 ;; instead of MFHI. This avoids both the normal MIPS III hi/lo hazards
5236 ;; and the errata related to -mfix-vr4130.
5237 (define_insn "mfhi<GPR:mode>_<HILO:mode>"
5238 [(set (match_operand:GPR 0 "register_operand" "=d")
5239 (unspec:GPR [(match_operand:HILO 1 "hilo_operand" "x")]
5240 UNSPEC_MFHI))]
5241 ""
5242 { return ISA_HAS_MACCHI ? "<GPR:d>macchi\t%0,%.,%." : "mfhi\t%0"; }
5243 [(set_attr "type" "mfhi")
5244 (set_attr "mode" "<GPR:MODE>")])
5245
5246 ;; Set the high part of a HI/LO value, given that the low part has
5247 ;; already been set. See mips_hard_regno_mode_ok_p for the reason
5248 ;; why we can't just use (reg:GPR HI_REGNUM).
5249 (define_insn "mthi<GPR:mode>_<HILO:mode>"
5250 [(set (match_operand:HILO 0 "register_operand" "=x")
5251 (unspec:HILO [(match_operand:GPR 1 "reg_or_0_operand" "dJ")
5252 (match_operand:GPR 2 "register_operand" "l")]
5253 UNSPEC_MTHI))]
5254 ""
5255 "mthi\t%z1"
5256 [(set_attr "type" "mthi")
5257 (set_attr "mode" "SI")])
5258
5259 ;; Emit a doubleword move in which exactly one of the operands is
5260 ;; a floating-point register. We can't just emit two normal moves
5261 ;; because of the constraints imposed by the FPU register model;
5262 ;; see mips_cannot_change_mode_class for details. Instead, we keep
5263 ;; the FPR whole and use special patterns to refer to each word of
5264 ;; the other operand.
5265
5266 (define_expand "move_doubleword_fpr<mode>"
5267 [(set (match_operand:SPLITF 0)
5268 (match_operand:SPLITF 1))]
5269 ""
5270 {
5271 if (FP_REG_RTX_P (operands[0]))
5272 {
5273 rtx low = mips_subword (operands[1], 0);
5274 rtx high = mips_subword (operands[1], 1);
5275 emit_insn (gen_load_low<mode> (operands[0], low));
5276 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5277 emit_insn (gen_mthc1<mode> (operands[0], high, operands[0]));
5278 else
5279 emit_insn (gen_load_high<mode> (operands[0], high, operands[0]));
5280 }
5281 else
5282 {
5283 rtx low = mips_subword (operands[0], 0);
5284 rtx high = mips_subword (operands[0], 1);
5285 emit_insn (gen_store_word<mode> (low, operands[1], const0_rtx));
5286 if (ISA_HAS_MXHC1 && !TARGET_64BIT)
5287 emit_insn (gen_mfhc1<mode> (high, operands[1]));
5288 else
5289 emit_insn (gen_store_word<mode> (high, operands[1], const1_rtx));
5290 }
5291 DONE;
5292 })
5293
5294 ;; Load the low word of operand 0 with operand 1.
5295 (define_insn "load_low<mode>"
5296 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5297 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")]
5298 UNSPEC_LOAD_LOW))]
5299 "TARGET_HARD_FLOAT"
5300 {
5301 operands[0] = mips_subword (operands[0], 0);
5302 return mips_output_move (operands[0], operands[1]);
5303 }
5304 [(set_attr "move_type" "mtc,fpload")
5305 (set_attr "mode" "<HALFMODE>")])
5306
5307 ;; Load the high word of operand 0 from operand 1, preserving the value
5308 ;; in the low word.
5309 (define_insn "load_high<mode>"
5310 [(set (match_operand:SPLITF 0 "register_operand" "=f,f")
5311 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "general_operand" "dJ,m")
5312 (match_operand:SPLITF 2 "register_operand" "0,0")]
5313 UNSPEC_LOAD_HIGH))]
5314 "TARGET_HARD_FLOAT"
5315 {
5316 operands[0] = mips_subword (operands[0], 1);
5317 return mips_output_move (operands[0], operands[1]);
5318 }
5319 [(set_attr "move_type" "mtc,fpload")
5320 (set_attr "mode" "<HALFMODE>")])
5321
5322 ;; Store one word of operand 1 in operand 0. Operand 2 is 1 to store the
5323 ;; high word and 0 to store the low word.
5324 (define_insn "store_word<mode>"
5325 [(set (match_operand:<HALFMODE> 0 "nonimmediate_operand" "=d,m")
5326 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f,f")
5327 (match_operand 2 "const_int_operand")]
5328 UNSPEC_STORE_WORD))]
5329 "TARGET_HARD_FLOAT"
5330 {
5331 operands[1] = mips_subword (operands[1], INTVAL (operands[2]));
5332 return mips_output_move (operands[0], operands[1]);
5333 }
5334 [(set_attr "move_type" "mfc,fpstore")
5335 (set_attr "mode" "<HALFMODE>")])
5336
5337 ;; Move operand 1 to the high word of operand 0 using mthc1, preserving the
5338 ;; value in the low word.
5339 (define_insn "mthc1<mode>"
5340 [(set (match_operand:SPLITF 0 "register_operand" "=f")
5341 (unspec:SPLITF [(match_operand:<HALFMODE> 1 "reg_or_0_operand" "dJ")
5342 (match_operand:SPLITF 2 "register_operand" "0")]
5343 UNSPEC_MTHC1))]
5344 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5345 "mthc1\t%z1,%0"
5346 [(set_attr "move_type" "mtc")
5347 (set_attr "mode" "<HALFMODE>")])
5348
5349 ;; Move high word of operand 1 to operand 0 using mfhc1.
5350 (define_insn "mfhc1<mode>"
5351 [(set (match_operand:<HALFMODE> 0 "register_operand" "=d")
5352 (unspec:<HALFMODE> [(match_operand:SPLITF 1 "register_operand" "f")]
5353 UNSPEC_MFHC1))]
5354 "TARGET_HARD_FLOAT && ISA_HAS_MXHC1"
5355 "mfhc1\t%0,%1"
5356 [(set_attr "move_type" "mfc")
5357 (set_attr "mode" "<HALFMODE>")])
5358
5359 ;; Move a constant that satisfies CONST_GP_P into operand 0.
5360 (define_expand "load_const_gp_<mode>"
5361 [(set (match_operand:P 0 "register_operand" "=d")
5362 (const:P (unspec:P [(const_int 0)] UNSPEC_GP)))])
5363
5364 ;; Insn to initialize $gp for n32/n64 abicalls. Operand 0 is the offset
5365 ;; of _gp from the start of this function. Operand 1 is the incoming
5366 ;; function address.
5367 (define_insn_and_split "loadgp_newabi_<mode>"
5368 [(set (match_operand:P 0 "register_operand" "=&d")
5369 (unspec:P [(match_operand:P 1)
5370 (match_operand:P 2 "register_operand" "d")]
5371 UNSPEC_LOADGP))]
5372 "mips_current_loadgp_style () == LOADGP_NEWABI"
5373 { return mips_must_initialize_gp_p () ? "#" : ""; }
5374 "&& mips_must_initialize_gp_p ()"
5375 [(set (match_dup 0) (match_dup 3))
5376 (set (match_dup 0) (match_dup 4))
5377 (set (match_dup 0) (match_dup 5))]
5378 {
5379 operands[3] = gen_rtx_HIGH (Pmode, operands[1]);
5380 operands[4] = gen_rtx_PLUS (Pmode, operands[0], operands[2]);
5381 operands[5] = gen_rtx_LO_SUM (Pmode, operands[0], operands[1]);
5382 }
5383 [(set_attr "type" "ghost")])
5384
5385 ;; Likewise, for -mno-shared code. Operand 0 is the __gnu_local_gp symbol.
5386 (define_insn_and_split "loadgp_absolute_<mode>"
5387 [(set (match_operand:P 0 "register_operand" "=d")
5388 (unspec:P [(match_operand:P 1)] UNSPEC_LOADGP))]
5389 "mips_current_loadgp_style () == LOADGP_ABSOLUTE"
5390 { return mips_must_initialize_gp_p () ? "#" : ""; }
5391 "&& mips_must_initialize_gp_p ()"
5392 [(const_int 0)]
5393 {
5394 mips_emit_move (operands[0], operands[1]);
5395 DONE;
5396 }
5397 [(set_attr "type" "ghost")])
5398
5399 ;; This blockage instruction prevents the gp load from being
5400 ;; scheduled after an implicit use of gp. It also prevents
5401 ;; the load from being deleted as dead.
5402 (define_insn "loadgp_blockage"
5403 [(unspec_volatile [(reg:SI 28)] UNSPEC_BLOCKAGE)]
5404 ""
5405 ""
5406 [(set_attr "type" "ghost")])
5407
5408 ;; Initialize $gp for RTP PIC. Operand 0 is the __GOTT_BASE__ symbol
5409 ;; and operand 1 is the __GOTT_INDEX__ symbol.
5410 (define_insn_and_split "loadgp_rtp_<mode>"
5411 [(set (match_operand:P 0 "register_operand" "=d")
5412 (unspec:P [(match_operand:P 1 "symbol_ref_operand")
5413 (match_operand:P 2 "symbol_ref_operand")]
5414 UNSPEC_LOADGP))]
5415 "mips_current_loadgp_style () == LOADGP_RTP"
5416 { return mips_must_initialize_gp_p () ? "#" : ""; }
5417 "&& mips_must_initialize_gp_p ()"
5418 [(set (match_dup 0) (high:P (match_dup 3)))
5419 (set (match_dup 0) (unspec:P [(match_dup 0)
5420 (match_dup 3)] UNSPEC_LOAD_GOT))
5421 (set (match_dup 0) (unspec:P [(match_dup 0)
5422 (match_dup 4)] UNSPEC_LOAD_GOT))]
5423 {
5424 operands[3] = mips_unspec_address (operands[1], SYMBOL_ABSOLUTE);
5425 operands[4] = mips_unspec_address (operands[2], SYMBOL_HALF);
5426 }
5427 [(set_attr "type" "ghost")])
5428
5429 ;; Initialize the global pointer for MIPS16 code. Operand 0 is the
5430 ;; global pointer and operand 1 is the MIPS16 register that holds
5431 ;; the required value.
5432 (define_insn_and_split "copygp_mips16_<mode>"
5433 [(set (match_operand:P 0 "register_operand" "=y")
5434 (unspec:P [(match_operand:P 1 "register_operand" "d")]
5435 UNSPEC_COPYGP))]
5436 "TARGET_MIPS16"
5437 { return mips_must_initialize_gp_p () ? "#" : ""; }
5438 "&& mips_must_initialize_gp_p ()"
5439 [(set (match_dup 0) (match_dup 1))]
5440 ""
5441 [(set_attr "type" "ghost")])
5442
5443 ;; A placeholder for where the cprestore instruction should go,
5444 ;; if we decide we need one. Operand 0 and operand 1 are as for
5445 ;; "cprestore". Operand 2 is a register that holds the gp value.
5446 ;;
5447 ;; The "cprestore" pattern requires operand 2 to be pic_offset_table_rtx,
5448 ;; otherwise any register that holds the correct value will do.
5449 (define_insn_and_split "potential_cprestore_<mode>"
5450 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5451 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5452 (match_operand:P 2 "register_operand" "d,d")]
5453 UNSPEC_POTENTIAL_CPRESTORE))
5454 (clobber (match_operand:P 3 "scratch_operand" "=X,&d"))]
5455 "!TARGET_CPRESTORE_DIRECTIVE || operands[2] == pic_offset_table_rtx"
5456 { return mips_must_initialize_gp_p () ? "#" : ""; }
5457 "mips_must_initialize_gp_p ()"
5458 [(const_int 0)]
5459 {
5460 mips_save_gp_to_cprestore_slot (operands[0], operands[1],
5461 operands[2], operands[3]);
5462 DONE;
5463 }
5464 [(set_attr "type" "ghost")])
5465
5466 ;; Emit a .cprestore directive, which normally expands to a single store
5467 ;; instruction. Operand 0 is a (possibly illegitimate) sp-based MEM
5468 ;; for the cprestore slot. Operand 1 is the offset of the slot from
5469 ;; the stack pointer. (This is redundant with operand 0, but it makes
5470 ;; things a little simpler.)
5471 (define_insn "cprestore_<mode>"
5472 [(set (match_operand:P 0 "cprestore_save_slot_operand" "=X,X")
5473 (unspec:P [(match_operand:P 1 "const_int_operand" "I,i")
5474 (reg:P 28)]
5475 UNSPEC_CPRESTORE))]
5476 "TARGET_CPRESTORE_DIRECTIVE"
5477 {
5478 if (mips_nomacro.nesting_level > 0 && which_alternative == 1)
5479 return ".set\tmacro\;.cprestore\t%1\;.set\tnomacro";
5480 else
5481 return ".cprestore\t%1";
5482 }
5483 [(set_attr "type" "store")
5484 (set_attr "insn_count" "1,3")])
5485
5486 (define_insn "use_cprestore_<mode>"
5487 [(set (reg:P CPRESTORE_SLOT_REGNUM)
5488 (match_operand:P 0 "cprestore_load_slot_operand"))]
5489 ""
5490 ""
5491 [(set_attr "type" "ghost")])
5492
5493 ;; Expand in-line code to clear the instruction cache between operand[0] and
5494 ;; operand[1].
5495 (define_expand "clear_cache"
5496 [(match_operand 0 "pmode_register_operand")
5497 (match_operand 1 "pmode_register_operand")]
5498 ""
5499 "
5500 {
5501 if (TARGET_SYNCI)
5502 {
5503 mips_expand_synci_loop (operands[0], operands[1]);
5504 emit_insn (gen_sync ());
5505 emit_insn (PMODE_INSN (gen_clear_hazard, ()));
5506 }
5507 else if (mips_cache_flush_func && mips_cache_flush_func[0])
5508 {
5509 rtx len = gen_reg_rtx (Pmode);
5510 emit_insn (gen_sub3_insn (len, operands[1], operands[0]));
5511 MIPS_ICACHE_SYNC (operands[0], len);
5512 }
5513 DONE;
5514 }")
5515
5516 (define_insn "sync"
5517 [(unspec_volatile [(const_int 0)] UNSPEC_SYNC)]
5518 "GENERATE_SYNC"
5519 { return mips_output_sync (); })
5520
5521 (define_insn "synci"
5522 [(unspec_volatile [(match_operand 0 "pmode_register_operand" "d")]
5523 UNSPEC_SYNCI)]
5524 "TARGET_SYNCI"
5525 "synci\t0(%0)")
5526
5527 (define_insn "rdhwr_synci_step_<mode>"
5528 [(set (match_operand:P 0 "register_operand" "=d")
5529 (unspec_volatile [(const_int 1)]
5530 UNSPEC_RDHWR))]
5531 "ISA_HAS_SYNCI"
5532 "rdhwr\t%0,$1")
5533
5534 (define_insn "clear_hazard_<mode>"
5535 [(unspec_volatile [(const_int 0)] UNSPEC_CLEAR_HAZARD)
5536 (clobber (reg:P RETURN_ADDR_REGNUM))]
5537 "ISA_HAS_SYNCI"
5538 {
5539 return "%(%<bal\t1f\n"
5540 "\tnop\n"
5541 "1:\t<d>addiu\t$31,$31,12\n"
5542 "\tjr.hb\t$31\n"
5543 "\tnop%>%)";
5544 }
5545 [(set_attr "insn_count" "5")])
5546
5547 ;; Cache operations for R4000-style caches.
5548 (define_insn "mips_cache"
5549 [(set (mem:BLK (scratch))
5550 (unspec:BLK [(match_operand:SI 0 "const_int_operand")
5551 (match_operand:QI 1 "address_operand" "ZD")]
5552 UNSPEC_MIPS_CACHE))]
5553 "ISA_HAS_CACHE"
5554 "cache\t%X0,%a1")
5555
5556 ;; Similar, but with the operands hard-coded to an R10K cache barrier
5557 ;; operation. We keep the pattern distinct so that we can identify
5558 ;; cache operations inserted by -mr10k-cache-barrier=, and so that
5559 ;; the operation is never inserted into a delay slot.
5560 (define_insn "r10k_cache_barrier"
5561 [(set (mem:BLK (scratch))
5562 (unspec:BLK [(const_int 0)] UNSPEC_R10K_CACHE_BARRIER))]
5563 "ISA_HAS_CACHE"
5564 "cache\t0x14,0(%$)"
5565 [(set_attr "can_delay" "no")])
5566 \f
5567 ;; Block moves, see mips.c for more details.
5568 ;; Argument 0 is the destination
5569 ;; Argument 1 is the source
5570 ;; Argument 2 is the length
5571 ;; Argument 3 is the alignment
5572
5573 (define_expand "movmemsi"
5574 [(parallel [(set (match_operand:BLK 0 "general_operand")
5575 (match_operand:BLK 1 "general_operand"))
5576 (use (match_operand:SI 2 ""))
5577 (use (match_operand:SI 3 "const_int_operand"))])]
5578 "!TARGET_MIPS16 && !TARGET_MEMCPY"
5579 {
5580 if (mips_expand_block_move (operands[0], operands[1], operands[2]))
5581 DONE;
5582 else
5583 FAIL;
5584 })
5585 \f
5586 ;;
5587 ;; ....................
5588 ;;
5589 ;; SHIFTS
5590 ;;
5591 ;; ....................
5592
5593 (define_expand "<optab><mode>3"
5594 [(set (match_operand:GPR 0 "register_operand")
5595 (any_shift:GPR (match_operand:GPR 1 "register_operand")
5596 (match_operand:SI 2 "arith_operand")))]
5597 ""
5598 {
5599 /* On the mips16, a shift of more than 8 is a four byte instruction,
5600 so, for a shift between 8 and 16, it is just as fast to do two
5601 shifts of 8 or less. If there is a lot of shifting going on, we
5602 may win in CSE. Otherwise combine will put the shifts back
5603 together again. This can be called by mips_function_arg, so we must
5604 be careful not to allocate a new register if we've reached the
5605 reload pass. */
5606 if (TARGET_MIPS16
5607 && optimize
5608 && CONST_INT_P (operands[2])
5609 && INTVAL (operands[2]) > 8
5610 && INTVAL (operands[2]) <= 16
5611 && !reload_in_progress
5612 && !reload_completed)
5613 {
5614 rtx temp = gen_reg_rtx (<MODE>mode);
5615
5616 emit_insn (gen_<optab><mode>3 (temp, operands[1], GEN_INT (8)));
5617 emit_insn (gen_<optab><mode>3 (operands[0], temp,
5618 GEN_INT (INTVAL (operands[2]) - 8)));
5619 DONE;
5620 }
5621 })
5622
5623 (define_insn "*<optab><mode>3"
5624 [(set (match_operand:GPR 0 "register_operand" "=!u,d")
5625 (any_shift:GPR (match_operand:GPR 1 "register_operand" "!u,d")
5626 (match_operand:SI 2 "arith_operand" "Uib3,dI")))]
5627 "!TARGET_MIPS16"
5628 {
5629 if (CONST_INT_P (operands[2]))
5630 operands[2] = GEN_INT (INTVAL (operands[2])
5631 & (GET_MODE_BITSIZE (<MODE>mode) - 1));
5632
5633 return "<d><insn>\t%0,%1,%2";
5634 }
5635 [(set_attr "type" "shift")
5636 (set_attr "compression" "<shift_compression>,none")
5637 (set_attr "mode" "<MODE>")])
5638
5639 (define_insn "*<optab>si3_extend"
5640 [(set (match_operand:DI 0 "register_operand" "=d")
5641 (sign_extend:DI
5642 (any_shift:SI (match_operand:SI 1 "register_operand" "d")
5643 (match_operand:SI 2 "arith_operand" "dI"))))]
5644 "TARGET_64BIT && !TARGET_MIPS16"
5645 {
5646 if (CONST_INT_P (operands[2]))
5647 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5648
5649 return "<insn>\t%0,%1,%2";
5650 }
5651 [(set_attr "type" "shift")
5652 (set_attr "mode" "SI")])
5653
5654 (define_insn "*<optab>si3_mips16"
5655 [(set (match_operand:SI 0 "register_operand" "=d,d,d")
5656 (any_shift:SI (match_operand:SI 1 "register_operand" "0,d,d")
5657 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5658 "TARGET_MIPS16"
5659 {
5660 if (which_alternative == 0)
5661 return "<insn>\t%0,%2";
5662
5663 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x1f);
5664 return "<insn>\t%0,%1,%2";
5665 }
5666 [(set_attr "type" "shift")
5667 (set_attr "mode" "SI")
5668 (set_attr "extended_mips16" "no,no,yes")])
5669
5670 (define_insn "<GPR:d>lsa"
5671 [(set (match_operand:GPR 0 "register_operand" "=d")
5672 (plus:GPR (ashift:GPR (match_operand:GPR 1 "register_operand" "d")
5673 (match_operand 2 "const_immlsa_operand" ""))
5674 (match_operand:GPR 3 "register_operand" "d")))]
5675 "ISA_HAS_<GPR:D>LSA"
5676 "<GPR:d>lsa\t%0,%1,%3,%2"
5677 [(set_attr "type" "arith")
5678 (set_attr "mode" "<GPR:MODE>")])
5679
5680 ;; We need separate DImode MIPS16 patterns because of the irregularity
5681 ;; of right shifts.
5682 (define_insn "*ashldi3_mips16"
5683 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5684 (ashift:DI (match_operand:DI 1 "register_operand" "0,d,d")
5685 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5686 "TARGET_64BIT && TARGET_MIPS16"
5687 {
5688 if (which_alternative == 0)
5689 return "dsll\t%0,%2";
5690
5691 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5692 return "dsll\t%0,%1,%2";
5693 }
5694 [(set_attr "type" "shift")
5695 (set_attr "mode" "DI")
5696 (set_attr "extended_mips16" "no,no,yes")])
5697
5698 (define_insn "*ashrdi3_mips16"
5699 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5700 (ashiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5701 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5702 "TARGET_64BIT && TARGET_MIPS16"
5703 {
5704 if (CONST_INT_P (operands[2]))
5705 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5706
5707 return "dsra\t%0,%2";
5708 }
5709 [(set_attr "type" "shift")
5710 (set_attr "mode" "DI")
5711 (set_attr "extended_mips16" "no,no,yes")])
5712
5713 (define_insn "*lshrdi3_mips16"
5714 [(set (match_operand:DI 0 "register_operand" "=d,d,d")
5715 (lshiftrt:DI (match_operand:DI 1 "register_operand" "0,0,0")
5716 (match_operand:SI 2 "arith_operand" "d,Uib3,I")))]
5717 "TARGET_64BIT && TARGET_MIPS16"
5718 {
5719 if (CONST_INT_P (operands[2]))
5720 operands[2] = GEN_INT (INTVAL (operands[2]) & 0x3f);
5721
5722 return "dsrl\t%0,%2";
5723 }
5724 [(set_attr "type" "shift")
5725 (set_attr "mode" "DI")
5726 (set_attr "extended_mips16" "no,no,yes")])
5727
5728 ;; On the mips16, we can split a 4 byte shift into 2 2 byte shifts.
5729
5730 (define_split
5731 [(set (match_operand:GPR 0 "d_operand")
5732 (any_shift:GPR (match_operand:GPR 1 "d_operand")
5733 (match_operand:GPR 2 "const_int_operand")))]
5734 "TARGET_MIPS16 && reload_completed && !TARGET_DEBUG_D_MODE
5735 && INTVAL (operands[2]) > 8
5736 && INTVAL (operands[2]) <= 16"
5737 [(set (match_dup 0) (any_shift:GPR (match_dup 1) (const_int 8)))
5738 (set (match_dup 0) (any_shift:GPR (match_dup 0) (match_dup 2)))]
5739 { operands[2] = GEN_INT (INTVAL (operands[2]) - 8); })
5740
5741 ;; If we load a byte on the mips16 as a bitfield, the resulting
5742 ;; sequence of instructions is too complicated for combine, because it
5743 ;; involves four instructions: a load, a shift, a constant load into a
5744 ;; register, and an and (the key problem here is that the mips16 does
5745 ;; not have and immediate). We recognize a shift of a load in order
5746 ;; to make it simple enough for combine to understand.
5747 ;;
5748 ;; The instruction count here is the worst case.
5749 (define_insn_and_split ""
5750 [(set (match_operand:SI 0 "register_operand" "=d")
5751 (lshiftrt:SI (match_operand:SI 1 "memory_operand" "m")
5752 (match_operand:SI 2 "immediate_operand" "I")))]
5753 "TARGET_MIPS16"
5754 "#"
5755 ""
5756 [(set (match_dup 0) (match_dup 1))
5757 (set (match_dup 0) (lshiftrt:SI (match_dup 0) (match_dup 2)))]
5758 ""
5759 [(set_attr "type" "load")
5760 (set_attr "mode" "SI")
5761 (set (attr "insn_count")
5762 (symbol_ref "mips_load_store_insns (operands[1], insn) + 2"))])
5763
5764 (define_insn "rotr<mode>3"
5765 [(set (match_operand:GPR 0 "register_operand" "=d")
5766 (rotatert:GPR (match_operand:GPR 1 "register_operand" "d")
5767 (match_operand:SI 2 "arith_operand" "dI")))]
5768 "ISA_HAS_ROR"
5769 {
5770 if (CONST_INT_P (operands[2]))
5771 gcc_assert (INTVAL (operands[2]) >= 0
5772 && INTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode));
5773
5774 return "<d>ror\t%0,%1,%2";
5775 }
5776 [(set_attr "type" "shift")
5777 (set_attr "mode" "<MODE>")])
5778
5779 (define_insn "bswaphi2"
5780 [(set (match_operand:HI 0 "register_operand" "=d")
5781 (bswap:HI (match_operand:HI 1 "register_operand" "d")))]
5782 "ISA_HAS_WSBH"
5783 "wsbh\t%0,%1"
5784 [(set_attr "type" "shift")])
5785
5786 (define_insn_and_split "bswapsi2"
5787 [(set (match_operand:SI 0 "register_operand" "=d")
5788 (bswap:SI (match_operand:SI 1 "register_operand" "d")))]
5789 "ISA_HAS_WSBH && ISA_HAS_ROR"
5790 "#"
5791 ""
5792 [(set (match_dup 0) (unspec:SI [(match_dup 1)] UNSPEC_WSBH))
5793 (set (match_dup 0) (rotatert:SI (match_dup 0) (const_int 16)))]
5794 ""
5795 [(set_attr "insn_count" "2")])
5796
5797 (define_insn_and_split "bswapdi2"
5798 [(set (match_operand:DI 0 "register_operand" "=d")
5799 (bswap:DI (match_operand:DI 1 "register_operand" "d")))]
5800 "TARGET_64BIT && ISA_HAS_WSBH"
5801 "#"
5802 ""
5803 [(set (match_dup 0) (unspec:DI [(match_dup 1)] UNSPEC_DSBH))
5804 (set (match_dup 0) (unspec:DI [(match_dup 0)] UNSPEC_DSHD))]
5805 ""
5806 [(set_attr "insn_count" "2")])
5807
5808 (define_insn "wsbh"
5809 [(set (match_operand:SI 0 "register_operand" "=d")
5810 (unspec:SI [(match_operand:SI 1 "register_operand" "d")] UNSPEC_WSBH))]
5811 "ISA_HAS_WSBH"
5812 "wsbh\t%0,%1"
5813 [(set_attr "type" "shift")])
5814
5815 (define_insn "dsbh"
5816 [(set (match_operand:DI 0 "register_operand" "=d")
5817 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSBH))]
5818 "TARGET_64BIT && ISA_HAS_WSBH"
5819 "dsbh\t%0,%1"
5820 [(set_attr "type" "shift")])
5821
5822 (define_insn "dshd"
5823 [(set (match_operand:DI 0 "register_operand" "=d")
5824 (unspec:DI [(match_operand:DI 1 "register_operand" "d")] UNSPEC_DSHD))]
5825 "TARGET_64BIT && ISA_HAS_WSBH"
5826 "dshd\t%0,%1"
5827 [(set_attr "type" "shift")])
5828 \f
5829 ;;
5830 ;; ....................
5831 ;;
5832 ;; CONDITIONAL BRANCHES
5833 ;;
5834 ;; ....................
5835
5836 ;; Conditional branches on floating-point equality tests.
5837
5838 (define_insn "*branch_fp_<mode>"
5839 [(set (pc)
5840 (if_then_else
5841 (match_operator 1 "equality_operator"
5842 [(match_operand:FPCC 2 "register_operand" "<reg>")
5843 (const_int 0)])
5844 (label_ref (match_operand 0 "" ""))
5845 (pc)))]
5846 "TARGET_HARD_FLOAT"
5847 {
5848 return mips_output_conditional_branch (insn, operands,
5849 MIPS_BRANCH ("b%F1", "%Z2%0"),
5850 MIPS_BRANCH ("b%W1", "%Z2%0"));
5851 }
5852 [(set_attr "type" "branch")])
5853
5854 (define_insn "*branch_fp_inverted_<mode>"
5855 [(set (pc)
5856 (if_then_else
5857 (match_operator 1 "equality_operator"
5858 [(match_operand:FPCC 2 "register_operand" "<reg>")
5859 (const_int 0)])
5860 (pc)
5861 (label_ref (match_operand 0 "" ""))))]
5862 "TARGET_HARD_FLOAT"
5863 {
5864 return mips_output_conditional_branch (insn, operands,
5865 MIPS_BRANCH ("b%W1", "%Z2%0"),
5866 MIPS_BRANCH ("b%F1", "%Z2%0"));
5867 }
5868 [(set_attr "type" "branch")])
5869
5870 ;; Conditional branches on ordered comparisons with zero.
5871
5872 (define_insn "*branch_order<mode>"
5873 [(set (pc)
5874 (if_then_else
5875 (match_operator 1 "order_operator"
5876 [(match_operand:GPR 2 "register_operand" "d,d")
5877 (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5878 (label_ref (match_operand 0 "" ""))
5879 (pc)))]
5880 "!TARGET_MIPS16"
5881 { return mips_output_order_conditional_branch (insn, operands, false); }
5882 [(set_attr "type" "branch")
5883 (set_attr "compact_form" "maybe,always")
5884 (set_attr "hazard" "forbidden_slot")])
5885
5886 (define_insn "*branch_order<mode>_inverted"
5887 [(set (pc)
5888 (if_then_else
5889 (match_operator 1 "order_operator"
5890 [(match_operand:GPR 2 "register_operand" "d,d")
5891 (match_operand:GPR 3 "reg_or_0_operand" "J,d")])
5892 (pc)
5893 (label_ref (match_operand 0 "" ""))))]
5894 "!TARGET_MIPS16"
5895 { return mips_output_order_conditional_branch (insn, operands, true); }
5896 [(set_attr "type" "branch")
5897 (set_attr "compact_form" "maybe,always")
5898 (set_attr "hazard" "forbidden_slot")])
5899
5900 ;; Conditional branch on equality comparison.
5901
5902 (define_insn "*branch_equality<mode>"
5903 [(set (pc)
5904 (if_then_else
5905 (match_operator 1 "equality_operator"
5906 [(match_operand:GPR 2 "register_operand" "d")
5907 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5908 (label_ref (match_operand 0 "" ""))
5909 (pc)))]
5910 "!TARGET_MIPS16"
5911 { return mips_output_equal_conditional_branch (insn, operands, false); }
5912 [(set_attr "type" "branch")
5913 (set_attr "compact_form" "maybe")
5914 (set_attr "hazard" "forbidden_slot")])
5915
5916 (define_insn "*branch_equality<mode>_inverted"
5917 [(set (pc)
5918 (if_then_else
5919 (match_operator 1 "equality_operator"
5920 [(match_operand:GPR 2 "register_operand" "d")
5921 (match_operand:GPR 3 "reg_or_0_operand" "dJ")])
5922 (pc)
5923 (label_ref (match_operand 0 "" ""))))]
5924 "!TARGET_MIPS16"
5925 { return mips_output_equal_conditional_branch (insn, operands, true); }
5926 [(set_attr "type" "branch")
5927 (set_attr "compact_form" "maybe")
5928 (set_attr "hazard" "forbidden_slot")])
5929
5930 ;; MIPS16 branches
5931
5932 (define_insn "*branch_equality<mode>_mips16"
5933 [(set (pc)
5934 (if_then_else
5935 (match_operator 1 "equality_operator"
5936 [(match_operand:GPR 2 "register_operand" "d,t")
5937 (const_int 0)])
5938 (label_ref (match_operand 0 "" ""))
5939 (pc)))]
5940 "TARGET_MIPS16"
5941 "@
5942 b%C1z\t%2,%0
5943 bt%C1z\t%0"
5944 [(set_attr "type" "branch")])
5945
5946 (define_insn "*branch_equality<mode>_mips16_inverted"
5947 [(set (pc)
5948 (if_then_else
5949 (match_operator 1 "equality_operator"
5950 [(match_operand:GPR 2 "register_operand" "d,t")
5951 (const_int 0)])
5952 (pc)
5953 (label_ref (match_operand 0 "" ""))))]
5954 "TARGET_MIPS16"
5955 "@
5956 b%N1z\t%2,%0
5957 bt%N1z\t%0"
5958 [(set_attr "type" "branch")])
5959
5960 (define_expand "cbranch<mode>4"
5961 [(set (pc)
5962 (if_then_else (match_operator 0 "comparison_operator"
5963 [(match_operand:GPR 1 "register_operand")
5964 (match_operand:GPR 2 "nonmemory_operand")])
5965 (label_ref (match_operand 3 ""))
5966 (pc)))]
5967 ""
5968 {
5969 mips_expand_conditional_branch (operands);
5970 DONE;
5971 })
5972
5973 (define_expand "cbranch<mode>4"
5974 [(set (pc)
5975 (if_then_else (match_operator 0 "comparison_operator"
5976 [(match_operand:SCALARF 1 "register_operand")
5977 (match_operand:SCALARF 2 "register_operand")])
5978 (label_ref (match_operand 3 ""))
5979 (pc)))]
5980 ""
5981 {
5982 mips_expand_conditional_branch (operands);
5983 DONE;
5984 })
5985
5986 ;; Used to implement built-in functions.
5987 (define_expand "condjump"
5988 [(set (pc)
5989 (if_then_else (match_operand 0)
5990 (label_ref (match_operand 1))
5991 (pc)))])
5992
5993 ;; Branch if bit is set/clear.
5994
5995 (define_insn "*branch_bit<bbv><mode>"
5996 [(set (pc)
5997 (if_then_else
5998 (equality_op (zero_extract:GPR
5999 (match_operand:GPR 1 "register_operand" "d")
6000 (const_int 1)
6001 (match_operand 2 "const_int_operand" ""))
6002 (const_int 0))
6003 (label_ref (match_operand 0 ""))
6004 (pc)))]
6005 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6006 {
6007 return
6008 mips_output_conditional_branch (insn, operands,
6009 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"),
6010 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"));
6011 }
6012 [(set_attr "type" "branch")
6013 (set_attr "branch_likely" "no")])
6014
6015 (define_insn "*branch_bit<bbv><mode>_inverted"
6016 [(set (pc)
6017 (if_then_else
6018 (equality_op (zero_extract:GPR
6019 (match_operand:GPR 1 "register_operand" "d")
6020 (const_int 1)
6021 (match_operand 2 "const_int_operand" ""))
6022 (const_int 0))
6023 (pc)
6024 (label_ref (match_operand 0 ""))))]
6025 "ISA_HAS_BBIT && UINTVAL (operands[2]) < GET_MODE_BITSIZE (<MODE>mode)"
6026 {
6027 return
6028 mips_output_conditional_branch (insn, operands,
6029 MIPS_BRANCH ("bbit<bbinv>", "%1,%2,%0"),
6030 MIPS_BRANCH ("bbit<bbv>", "%1,%2,%0"));
6031 }
6032 [(set_attr "type" "branch")
6033 (set_attr "branch_likely" "no")])
6034 \f
6035 ;;
6036 ;; ....................
6037 ;;
6038 ;; SETTING A REGISTER FROM A COMPARISON
6039 ;;
6040 ;; ....................
6041
6042 ;; Destination is always set in SI mode.
6043
6044 (define_expand "cstore<mode>4"
6045 [(set (match_operand:SI 0 "register_operand")
6046 (match_operator:SI 1 "mips_cstore_operator"
6047 [(match_operand:GPR 2 "register_operand")
6048 (match_operand:GPR 3 "nonmemory_operand")]))]
6049 ""
6050 {
6051 mips_expand_scc (operands);
6052 DONE;
6053 })
6054
6055 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>"
6056 [(set (match_operand:GPR2 0 "register_operand" "=d")
6057 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6058 (const_int 0)))]
6059 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6060 "sltu\t%0,%1,1"
6061 [(set_attr "type" "slt")
6062 (set_attr "mode" "<GPR:MODE>")])
6063
6064 (define_insn "*seq_zero_<GPR:mode><GPR2:mode>_mips16"
6065 [(set (match_operand:GPR2 0 "register_operand" "=t")
6066 (eq:GPR2 (match_operand:GPR 1 "register_operand" "d")
6067 (const_int 0)))]
6068 "TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6069 "sltu\t%1,1"
6070 [(set_attr "type" "slt")
6071 (set_attr "mode" "<GPR:MODE>")])
6072
6073 ;; Generate sltiu unless using seq results in better code.
6074 (define_insn "*seq_<GPR:mode><GPR2:mode>_seq"
6075 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6076 (eq:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6077 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6078 "ISA_HAS_SEQ_SNE"
6079 "@
6080 seq\t%0,%1,%2
6081 sltiu\t%0,%1,1
6082 seqi\t%0,%1,%2"
6083 [(set_attr "type" "slt")
6084 (set_attr "mode" "<GPR:MODE>")])
6085
6086 (define_insn "*sne_zero_<GPR:mode><GPR2:mode>"
6087 [(set (match_operand:GPR2 0 "register_operand" "=d")
6088 (ne:GPR2 (match_operand:GPR 1 "register_operand" "d")
6089 (const_int 0)))]
6090 "!TARGET_MIPS16 && !ISA_HAS_SEQ_SNE"
6091 "sltu\t%0,%.,%1"
6092 [(set_attr "type" "slt")
6093 (set_attr "mode" "<GPR:MODE>")])
6094
6095 ;; Generate sltu unless using sne results in better code.
6096 (define_insn "*sne_<GPR:mode><GPR2:mode>_sne"
6097 [(set (match_operand:GPR2 0 "register_operand" "=d,d,d")
6098 (ne:GPR2 (match_operand:GPR 1 "register_operand" "%d,d,d")
6099 (match_operand:GPR 2 "reg_imm10_operand" "d,J,YB")))]
6100 "ISA_HAS_SEQ_SNE"
6101 "@
6102 sne\t%0,%1,%2
6103 sltu\t%0,%.,%1
6104 snei\t%0,%1,%2"
6105 [(set_attr "type" "slt")
6106 (set_attr "mode" "<GPR:MODE>")])
6107
6108 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>"
6109 [(set (match_operand:GPR2 0 "register_operand" "=d")
6110 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6111 (match_operand:GPR 2 "reg_or_0_operand" "dJ")))]
6112 "!TARGET_MIPS16"
6113 "slt<u>\t%0,%z2,%1"
6114 [(set_attr "type" "slt")
6115 (set_attr "mode" "<GPR:MODE>")])
6116
6117 (define_insn "*sgt<u>_<GPR:mode><GPR2:mode>_mips16"
6118 [(set (match_operand:GPR2 0 "register_operand" "=t")
6119 (any_gt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6120 (match_operand:GPR 2 "register_operand" "d")))]
6121 "TARGET_MIPS16"
6122 "slt<u>\t%2,%1"
6123 [(set_attr "type" "slt")
6124 (set_attr "mode" "<GPR:MODE>")])
6125
6126 (define_insn "*sge<u>_<GPR:mode><GPR2:mode>"
6127 [(set (match_operand:GPR2 0 "register_operand" "=d")
6128 (any_ge:GPR2 (match_operand:GPR 1 "register_operand" "d")
6129 (const_int 1)))]
6130 "!TARGET_MIPS16"
6131 "slt<u>\t%0,%.,%1"
6132 [(set_attr "type" "slt")
6133 (set_attr "mode" "<GPR:MODE>")])
6134
6135 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>"
6136 [(set (match_operand:GPR2 0 "register_operand" "=d")
6137 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d")
6138 (match_operand:GPR 2 "arith_operand" "dI")))]
6139 "!TARGET_MIPS16"
6140 "slt<u>\t%0,%1,%2"
6141 [(set_attr "type" "slt")
6142 (set_attr "mode" "<GPR:MODE>")])
6143
6144 (define_insn "*slt<u>_<GPR:mode><GPR2:mode>_mips16"
6145 [(set (match_operand:GPR2 0 "register_operand" "=t,t,t")
6146 (any_lt:GPR2 (match_operand:GPR 1 "register_operand" "d,d,d")
6147 (match_operand:GPR 2 "arith_operand" "d,Uub8,I")))]
6148 "TARGET_MIPS16"
6149 "slt<u>\t%1,%2"
6150 [(set_attr "type" "slt")
6151 (set_attr "mode" "<GPR:MODE>")
6152 (set_attr "extended_mips16" "no,no,yes")])
6153
6154 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>"
6155 [(set (match_operand:GPR2 0 "register_operand" "=d")
6156 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d")
6157 (match_operand:GPR 2 "sle_operand" "")))]
6158 "!TARGET_MIPS16"
6159 {
6160 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6161 return "slt<u>\t%0,%1,%2";
6162 }
6163 [(set_attr "type" "slt")
6164 (set_attr "mode" "<GPR:MODE>")])
6165
6166 (define_insn "*sle<u>_<GPR:mode><GPR2:mode>_mips16"
6167 [(set (match_operand:GPR2 0 "register_operand" "=t,t")
6168 (any_le:GPR2 (match_operand:GPR 1 "register_operand" "d,d")
6169 (match_operand:GPR 2 "sle_operand" "Udb8,i")))]
6170 "TARGET_MIPS16"
6171 {
6172 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6173 return "slt<u>\t%1,%2";
6174 }
6175 [(set_attr "type" "slt")
6176 (set_attr "mode" "<GPR:MODE>")
6177 (set_attr "extended_mips16" "no,yes")])
6178 \f
6179 ;;
6180 ;; ....................
6181 ;;
6182 ;; FLOATING POINT COMPARISONS
6183 ;;
6184 ;; ....................
6185
6186 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6187 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6188 (fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6189 (match_operand:SCALARF 2 "register_operand" "f")))]
6190 ""
6191 "<fpcmp>.<fcond>.<fmt>\t%Z0%1,%2"
6192 [(set_attr "type" "fcmp")
6193 (set_attr "mode" "FPSW")])
6194
6195 (define_insn "s<code>_<SCALARF:mode>_using_<FPCC:mode>"
6196 [(set (match_operand:FPCC 0 "register_operand" "=<reg>")
6197 (swapped_fcond:FPCC (match_operand:SCALARF 1 "register_operand" "f")
6198 (match_operand:SCALARF 2 "register_operand" "f")))]
6199 ""
6200 "<fpcmp>.<swapped_fcond>.<fmt>\t%Z0%2,%1"
6201 [(set_attr "type" "fcmp")
6202 (set_attr "mode" "FPSW")])
6203 \f
6204 ;;
6205 ;; ....................
6206 ;;
6207 ;; UNCONDITIONAL BRANCHES
6208 ;;
6209 ;; ....................
6210
6211 ;; Unconditional branches.
6212
6213 (define_expand "jump"
6214 [(set (pc)
6215 (label_ref (match_operand 0)))])
6216
6217 (define_insn "*jump_absolute"
6218 [(set (pc)
6219 (label_ref (match_operand 0)))]
6220 "!TARGET_MIPS16 && TARGET_ABSOLUTE_JUMPS"
6221 {
6222 if (get_attr_length (insn) <= 8)
6223 {
6224 if (TARGET_CB_MAYBE)
6225 return MIPS_ABSOLUTE_JUMP ("%*b%:\t%l0");
6226 else
6227 return MIPS_ABSOLUTE_JUMP ("%*b\t%l0%/");
6228 }
6229 else
6230 {
6231 if (TARGET_CB_MAYBE && !final_sequence)
6232 return MIPS_ABSOLUTE_JUMP ("%*bc\t%l0");
6233 else
6234 return MIPS_ABSOLUTE_JUMP ("%*j\t%l0%/");
6235 }
6236 }
6237 [(set_attr "type" "branch")
6238 (set_attr "compact_form" "maybe")])
6239
6240 (define_insn "*jump_pic"
6241 [(set (pc)
6242 (label_ref (match_operand 0)))]
6243 "!TARGET_MIPS16 && !TARGET_ABSOLUTE_JUMPS"
6244 {
6245 if (get_attr_length (insn) <= 8)
6246 {
6247 if (TARGET_CB_MAYBE)
6248 return "%*b%:\t%l0";
6249 else
6250 return "%*b\t%l0%/";
6251 }
6252 else
6253 {
6254 mips_output_load_label (operands[0]);
6255 if (TARGET_CB_MAYBE)
6256 return "%*jr%:\t%@%]";
6257 else
6258 return "%*jr\t%@%/%]";
6259 }
6260 }
6261 [(set_attr "type" "branch")
6262 (set_attr "compact_form" "maybe")])
6263
6264 ;; We need a different insn for the mips16, because a mips16 branch
6265 ;; does not have a delay slot.
6266
6267 (define_insn "*jump_mips16"
6268 [(set (pc)
6269 (label_ref (match_operand 0 "" "")))]
6270 "TARGET_MIPS16"
6271 "b\t%l0"
6272 [(set_attr "type" "branch")
6273 (set (attr "length")
6274 ;; This calculation is like the normal branch one, but the
6275 ;; range of the unextended instruction is [-0x800, 0x7fe] rather
6276 ;; than [-0x100, 0xfe]. This translates to a range of:
6277 ;;
6278 ;; [-(0x800 - sizeof (branch)), 0x7fe]
6279 ;; == [-0x7fe, 0x7fe]
6280 ;;
6281 ;; from the shorten_branches reference address. Long-branch
6282 ;; sequences will replace this one, so the minimum length
6283 ;; is one instruction shorter than for conditional branches.
6284 (cond [(and (le (minus (match_dup 0) (pc)) (const_int 2046))
6285 (le (minus (pc) (match_dup 0)) (const_int 2046)))
6286 (const_int 2)
6287 (and (le (minus (match_dup 0) (pc)) (const_int 65534))
6288 (le (minus (pc) (match_dup 0)) (const_int 65532)))
6289 (const_int 4)
6290 (and (match_test "TARGET_ABICALLS")
6291 (not (match_test "TARGET_ABSOLUTE_ABICALLS")))
6292 (const_int 18)
6293 (match_test "Pmode == SImode")
6294 (const_int 14)
6295 ] (const_int 22)))])
6296
6297 (define_expand "indirect_jump"
6298 [(set (pc) (match_operand 0 "register_operand"))]
6299 ""
6300 {
6301 operands[0] = force_reg (Pmode, operands[0]);
6302 emit_jump_insn (PMODE_INSN (gen_indirect_jump, (operands[0])));
6303 DONE;
6304 })
6305
6306 (define_insn "indirect_jump_<mode>"
6307 [(set (pc) (match_operand:P 0 "register_operand" "d"))]
6308 ""
6309 {
6310 return mips_output_jump (operands, 0, -1, false);
6311 }
6312 [(set_attr "type" "jump")
6313 (set_attr "mode" "none")])
6314
6315 ;; A combined jump-and-move instruction, used for MIPS16 long-branch
6316 ;; sequences. Having a dedicated pattern is more convenient than
6317 ;; creating a SEQUENCE for this special case.
6318 (define_insn "indirect_jump_and_restore_<mode>"
6319 [(set (pc) (match_operand:P 1 "register_operand" "d"))
6320 (set (match_operand:P 0 "register_operand" "=d")
6321 (match_operand:P 2 "register_operand" "y"))]
6322 ""
6323 "%(%<jr\t%1\;move\t%0,%2%>%)"
6324 [(set_attr "type" "multi")
6325 (set_attr "extended_mips16" "yes")])
6326
6327 (define_expand "tablejump"
6328 [(set (pc)
6329 (match_operand 0 "register_operand"))
6330 (use (label_ref (match_operand 1 "")))]
6331 "!TARGET_MIPS16_SHORT_JUMP_TABLES"
6332 {
6333 if (TARGET_GPWORD)
6334 operands[0] = expand_binop (Pmode, add_optab, operands[0],
6335 pic_offset_table_rtx, 0, 0, OPTAB_WIDEN);
6336 else if (TARGET_RTP_PIC)
6337 {
6338 /* When generating RTP PIC, we use case table entries that are relative
6339 to the start of the function. Add the function's address to the
6340 value we loaded. */
6341 rtx start = get_hard_reg_initial_val (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6342 operands[0] = expand_binop (ptr_mode, add_optab, operands[0],
6343 start, 0, 0, OPTAB_WIDEN);
6344 }
6345
6346 emit_jump_insn (PMODE_INSN (gen_tablejump, (operands[0], operands[1])));
6347 DONE;
6348 })
6349
6350 (define_insn "tablejump_<mode>"
6351 [(set (pc)
6352 (match_operand:P 0 "register_operand" "d"))
6353 (use (label_ref (match_operand 1 "" "")))]
6354 ""
6355 {
6356 return mips_output_jump (operands, 0, -1, false);
6357 }
6358 [(set_attr "type" "jump")
6359 (set_attr "mode" "none")])
6360
6361 ;; For MIPS16, we don't know whether a given jump table will use short or
6362 ;; word-sized offsets until late in compilation, when we are able to determine
6363 ;; the sizes of the insns which comprise the containing function. This
6364 ;; necessitates the use of the casesi rather than the tablejump pattern, since
6365 ;; the latter tries to calculate the index of the offset to jump through early
6366 ;; in compilation, i.e. at expand time, when nothing is known about the
6367 ;; eventual function layout.
6368
6369 (define_expand "casesi"
6370 [(match_operand:SI 0 "register_operand" "") ; index to jump on
6371 (match_operand:SI 1 "const_int_operand" "") ; lower bound
6372 (match_operand:SI 2 "const_int_operand" "") ; total range
6373 (match_operand 3 "" "") ; table label
6374 (match_operand 4 "" "")] ; out of range label
6375 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6376 {
6377 if (operands[1] != const0_rtx)
6378 {
6379 rtx reg = gen_reg_rtx (SImode);
6380 rtx offset = gen_int_mode (-INTVAL (operands[1]), SImode);
6381
6382 if (!arith_operand (offset, SImode))
6383 offset = force_reg (SImode, offset);
6384
6385 emit_insn (gen_addsi3 (reg, operands[0], offset));
6386 operands[0] = reg;
6387 }
6388
6389 if (!arith_operand (operands[0], SImode))
6390 operands[0] = force_reg (SImode, operands[0]);
6391
6392 operands[2] = GEN_INT (INTVAL (operands[2]) + 1);
6393
6394 emit_jump_insn (PMODE_INSN (gen_casesi_internal_mips16,
6395 (operands[0], operands[2],
6396 operands[3], operands[4])));
6397
6398 DONE;
6399 })
6400
6401 (define_insn "casesi_internal_mips16_<mode>"
6402 [(set (pc)
6403 (if_then_else
6404 (ltu (match_operand:SI 0 "register_operand" "d")
6405 (match_operand:SI 1 "arith_operand" "dI"))
6406 (unspec:P
6407 [(match_dup 0)
6408 (label_ref (match_operand 2 "" ""))]
6409 UNSPEC_CASESI_DISPATCH)
6410 (label_ref (match_operand 3 "" ""))))
6411 (clobber (match_scratch:P 4 "=d"))
6412 (clobber (match_scratch:P 5 "=d"))
6413 (clobber (reg:SI MIPS16_T_REGNUM))]
6414 "TARGET_MIPS16_SHORT_JUMP_TABLES"
6415 {
6416 rtx diff_vec = PATTERN (NEXT_INSN (as_a <rtx_insn *> (operands[2])));
6417
6418 gcc_assert (GET_CODE (diff_vec) == ADDR_DIFF_VEC);
6419
6420 output_asm_insn ("sltu\t%0, %1", operands);
6421 output_asm_insn ("bteqz\t%3", operands);
6422
6423 switch (GET_MODE (diff_vec))
6424 {
6425 case HImode:
6426 output_asm_insn ("sll\t%5, %0, 1", operands);
6427 output_asm_insn ("<d>la\t%4, %2", operands);
6428 output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6429 output_asm_insn ("lh\t%5, 0(%5)", operands);
6430 break;
6431
6432 case SImode:
6433 output_asm_insn ("sll\t%5, %0, 2", operands);
6434 output_asm_insn ("<d>la\t%4, %2", operands);
6435 output_asm_insn ("<d>addu\t%5, %4, %5", operands);
6436 output_asm_insn ("lw\t%5, 0(%5)", operands);
6437 break;
6438
6439 default:
6440 gcc_unreachable ();
6441 }
6442
6443 output_asm_insn ("<d>addu\t%4, %4, %5", operands);
6444
6445 if (GENERATE_MIPS16E)
6446 return "jrc\t%4";
6447 else
6448 return "jr\t%4";
6449 }
6450 [(set (attr "insn_count")
6451 (if_then_else (match_test "GENERATE_MIPS16E")
6452 (const_string "10")
6453 (const_string "11")))])
6454
6455 ;; For TARGET_USE_GOT, we save the gp in the jmp_buf as well.
6456 ;; While it is possible to either pull it off the stack (in the
6457 ;; o32 case) or recalculate it given t9 and our target label,
6458 ;; it takes 3 or 4 insns to do so.
6459
6460 (define_expand "builtin_setjmp_setup"
6461 [(use (match_operand 0 "register_operand"))]
6462 "TARGET_USE_GOT"
6463 {
6464 rtx addr;
6465
6466 addr = plus_constant (Pmode, operands[0], GET_MODE_SIZE (Pmode) * 3);
6467 mips_emit_move (gen_rtx_MEM (Pmode, addr), pic_offset_table_rtx);
6468 DONE;
6469 })
6470
6471 ;; Restore the gp that we saved above. Despite the earlier comment, it seems
6472 ;; that older code did recalculate the gp from $25. Continue to jump through
6473 ;; $25 for compatibility (we lose nothing by doing so).
6474
6475 (define_expand "builtin_longjmp"
6476 [(use (match_operand 0 "register_operand"))]
6477 "TARGET_USE_GOT"
6478 {
6479 /* The elements of the buffer are, in order: */
6480 int W = GET_MODE_SIZE (Pmode);
6481 rtx fp = gen_rtx_MEM (Pmode, operands[0]);
6482 rtx lab = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 1*W));
6483 rtx stack = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 2*W));
6484 rtx gpv = gen_rtx_MEM (Pmode, plus_constant (Pmode, operands[0], 3*W));
6485 rtx pv = gen_rtx_REG (Pmode, PIC_FUNCTION_ADDR_REGNUM);
6486 /* Use gen_raw_REG to avoid being given pic_offset_table_rtx.
6487 The target is bound to be using $28 as the global pointer
6488 but the current function might not be. */
6489 rtx gp = gen_raw_REG (Pmode, GLOBAL_POINTER_REGNUM);
6490
6491 /* This bit is similar to expand_builtin_longjmp except that it
6492 restores $gp as well. */
6493 mips_emit_move (hard_frame_pointer_rtx, fp);
6494 mips_emit_move (pv, lab);
6495 emit_stack_restore (SAVE_NONLOCAL, stack);
6496 mips_emit_move (gp, gpv);
6497 emit_use (hard_frame_pointer_rtx);
6498 emit_use (stack_pointer_rtx);
6499 emit_use (gp);
6500 emit_indirect_jump (pv);
6501 DONE;
6502 })
6503 \f
6504 ;;
6505 ;; ....................
6506 ;;
6507 ;; Function prologue/epilogue
6508 ;;
6509 ;; ....................
6510 ;;
6511
6512 (define_expand "prologue"
6513 [(const_int 1)]
6514 ""
6515 {
6516 mips_expand_prologue ();
6517 DONE;
6518 })
6519
6520 ;; Block any insns from being moved before this point, since the
6521 ;; profiling call to mcount can use various registers that aren't
6522 ;; saved or used to pass arguments.
6523
6524 (define_insn "blockage"
6525 [(unspec_volatile [(const_int 0)] UNSPEC_BLOCKAGE)]
6526 ""
6527 ""
6528 [(set_attr "type" "ghost")
6529 (set_attr "mode" "none")])
6530
6531 (define_insn "probe_stack_range_<P:mode>"
6532 [(set (match_operand:P 0 "register_operand" "=d")
6533 (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
6534 (match_operand:P 2 "register_operand" "d")]
6535 UNSPEC_PROBE_STACK_RANGE))]
6536 ""
6537 { return mips_output_probe_stack_range (operands[0], operands[2]); }
6538 [(set_attr "type" "unknown")
6539 (set_attr "can_delay" "no")
6540 (set_attr "mode" "<MODE>")])
6541
6542 (define_expand "epilogue"
6543 [(const_int 2)]
6544 ""
6545 {
6546 mips_expand_epilogue (false);
6547 DONE;
6548 })
6549
6550 (define_expand "sibcall_epilogue"
6551 [(const_int 2)]
6552 ""
6553 {
6554 mips_expand_epilogue (true);
6555 DONE;
6556 })
6557
6558 ;; Trivial return. Make it look like a normal return insn as that
6559 ;; allows jump optimizations to work better.
6560
6561 (define_expand "return"
6562 [(simple_return)]
6563 "mips_can_use_return_insn ()"
6564 { mips_expand_before_return (); })
6565
6566 (define_expand "simple_return"
6567 [(simple_return)]
6568 ""
6569 { mips_expand_before_return (); })
6570
6571 (define_insn "*<optab>"
6572 [(any_return)]
6573 ""
6574 {
6575 operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
6576 return mips_output_jump (operands, 0, -1, false);
6577 }
6578 [(set_attr "type" "jump")
6579 (set_attr "mode" "none")])
6580
6581 ;; Normal return.
6582
6583 (define_insn "<optab>_internal"
6584 [(any_return)
6585 (use (match_operand 0 "pmode_register_operand" ""))]
6586 ""
6587 {
6588 operands[0] = gen_rtx_REG (Pmode, RETURN_ADDR_REGNUM);
6589 return mips_output_jump (operands, 0, -1, false);
6590 }
6591 [(set_attr "type" "jump")
6592 (set_attr "mode" "none")])
6593
6594 ;; Exception return.
6595 (define_insn "mips_eret"
6596 [(return)
6597 (unspec_volatile [(const_int 0)] UNSPEC_ERET)]
6598 ""
6599 "eret"
6600 [(set_attr "type" "trap")
6601 (set_attr "mode" "none")])
6602
6603 ;; Debug exception return.
6604 (define_insn "mips_deret"
6605 [(return)
6606 (unspec_volatile [(const_int 0)] UNSPEC_DERET)]
6607 ""
6608 "deret"
6609 [(set_attr "type" "trap")
6610 (set_attr "mode" "none")])
6611
6612 ;; Disable interrupts.
6613 (define_insn "mips_di"
6614 [(unspec_volatile [(const_int 0)] UNSPEC_DI)]
6615 ""
6616 "di"
6617 [(set_attr "type" "trap")
6618 (set_attr "mode" "none")])
6619
6620 ;; Execution hazard barrier.
6621 (define_insn "mips_ehb"
6622 [(unspec_volatile [(const_int 0)] UNSPEC_EHB)]
6623 ""
6624 "ehb"
6625 [(set_attr "type" "trap")
6626 (set_attr "mode" "none")])
6627
6628 ;; Read GPR from previous shadow register set.
6629 (define_insn "mips_rdpgpr_<mode>"
6630 [(set (match_operand:P 0 "register_operand" "=d")
6631 (unspec_volatile:P [(match_operand:P 1 "register_operand" "d")]
6632 UNSPEC_RDPGPR))]
6633 ""
6634 "rdpgpr\t%0,%1"
6635 [(set_attr "type" "move")
6636 (set_attr "mode" "<MODE>")])
6637
6638 ;; Move involving COP0 registers.
6639 (define_insn "cop0_move"
6640 [(set (match_operand:SI 0 "register_operand" "=B,d")
6641 (unspec_volatile:SI [(match_operand:SI 1 "register_operand" "d,B")]
6642 UNSPEC_COP0))]
6643 ""
6644 { return mips_output_move (operands[0], operands[1]); }
6645 [(set_attr "type" "mtc,mfc")
6646 (set_attr "mode" "SI")])
6647
6648 ;; This is used in compiling the unwind routines.
6649 (define_expand "eh_return"
6650 [(use (match_operand 0 "general_operand"))]
6651 ""
6652 {
6653 if (GET_MODE (operands[0]) != word_mode)
6654 operands[0] = convert_to_mode (word_mode, operands[0], 0);
6655 if (TARGET_64BIT)
6656 emit_insn (gen_eh_set_lr_di (operands[0]));
6657 else
6658 emit_insn (gen_eh_set_lr_si (operands[0]));
6659 DONE;
6660 })
6661
6662 ;; Clobber the return address on the stack. We can't expand this
6663 ;; until we know where it will be put in the stack frame.
6664
6665 (define_insn "eh_set_lr_si"
6666 [(unspec [(match_operand:SI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6667 (clobber (match_scratch:SI 1 "=&d"))]
6668 "! TARGET_64BIT"
6669 "#")
6670
6671 (define_insn "eh_set_lr_di"
6672 [(unspec [(match_operand:DI 0 "register_operand" "d")] UNSPEC_EH_RETURN)
6673 (clobber (match_scratch:DI 1 "=&d"))]
6674 "TARGET_64BIT"
6675 "#")
6676
6677 (define_split
6678 [(unspec [(match_operand 0 "register_operand")] UNSPEC_EH_RETURN)
6679 (clobber (match_scratch 1))]
6680 "reload_completed"
6681 [(const_int 0)]
6682 {
6683 mips_set_return_address (operands[0], operands[1]);
6684 DONE;
6685 })
6686
6687 (define_expand "exception_receiver"
6688 [(const_int 0)]
6689 "TARGET_USE_GOT"
6690 {
6691 /* See the comment above load_call<mode> for details. */
6692 emit_insn (gen_set_got_version ());
6693
6694 /* If we have a call-clobbered $gp, restore it from its save slot. */
6695 if (HAVE_restore_gp_si)
6696 emit_insn (gen_restore_gp_si ());
6697 else if (HAVE_restore_gp_di)
6698 emit_insn (gen_restore_gp_di ());
6699 DONE;
6700 })
6701
6702 (define_expand "nonlocal_goto_receiver"
6703 [(const_int 0)]
6704 "TARGET_USE_GOT"
6705 {
6706 /* See the comment above load_call<mode> for details. */
6707 emit_insn (gen_set_got_version ());
6708 DONE;
6709 })
6710
6711 ;; Restore $gp from its .cprestore stack slot. The instruction remains
6712 ;; volatile until all uses of $28 are exposed.
6713 (define_insn_and_split "restore_gp_<mode>"
6714 [(set (reg:P 28)
6715 (unspec_volatile:P [(const_int 0)] UNSPEC_RESTORE_GP))
6716 (clobber (match_scratch:P 0 "=&d"))]
6717 "TARGET_CALL_CLOBBERED_GP"
6718 "#"
6719 "&& epilogue_completed"
6720 [(const_int 0)]
6721 {
6722 mips_restore_gp_from_cprestore_slot (operands[0]);
6723 DONE;
6724 }
6725 [(set_attr "type" "ghost")])
6726
6727 ;; Move between $gp and its register save slot.
6728 (define_insn_and_split "move_gp<mode>"
6729 [(set (match_operand:GPR 0 "nonimmediate_operand" "=d,m")
6730 (unspec:GPR [(match_operand:GPR 1 "move_operand" "m,d")]
6731 UNSPEC_MOVE_GP))]
6732 ""
6733 { return mips_must_initialize_gp_p () ? "#" : ""; }
6734 "mips_must_initialize_gp_p ()"
6735 [(const_int 0)]
6736 {
6737 mips_emit_move (operands[0], operands[1]);
6738 DONE;
6739 }
6740 [(set_attr "type" "ghost")])
6741 \f
6742 ;;
6743 ;; ....................
6744 ;;
6745 ;; FUNCTION CALLS
6746 ;;
6747 ;; ....................
6748
6749 ;; Instructions to load a call address from the GOT. The address might
6750 ;; point to a function or to a lazy binding stub. In the latter case,
6751 ;; the stub will use the dynamic linker to resolve the function, which
6752 ;; in turn will change the GOT entry to point to the function's real
6753 ;; address.
6754 ;;
6755 ;; This means that every call, even pure and constant ones, can
6756 ;; potentially modify the GOT entry. And once a stub has been called,
6757 ;; we must not call it again.
6758 ;;
6759 ;; We represent this restriction using an imaginary, fixed, call-saved
6760 ;; register called GOT_VERSION_REGNUM. The idea is to make the register
6761 ;; live throughout the function and to change its value after every
6762 ;; potential call site. This stops any rtx value that uses the register
6763 ;; from being computed before an earlier call. To do this, we:
6764 ;;
6765 ;; - Ensure that the register is live on entry to the function,
6766 ;; so that it is never thought to be used uninitalized.
6767 ;;
6768 ;; - Ensure that the register is live on exit from the function,
6769 ;; so that it is live throughout.
6770 ;;
6771 ;; - Make each call (lazily-bound or not) use the current value
6772 ;; of GOT_VERSION_REGNUM, so that updates of the register are
6773 ;; not moved across call boundaries.
6774 ;;
6775 ;; - Add "ghost" definitions of the register to the beginning of
6776 ;; blocks reached by EH and ABNORMAL_CALL edges, because those
6777 ;; edges may involve calls that normal paths don't. (E.g. the
6778 ;; unwinding code that handles a non-call exception may change
6779 ;; lazily-bound GOT entries.) We do this by making the
6780 ;; exception_receiver and nonlocal_goto_receiver expanders emit
6781 ;; a set_got_version instruction.
6782 ;;
6783 ;; - After each call (lazily-bound or not), use a "ghost"
6784 ;; update_got_version instruction to change the register's value.
6785 ;; This instruction mimics the _possible_ effect of the dynamic
6786 ;; resolver during the call and it remains live even if the call
6787 ;; itself becomes dead.
6788 ;;
6789 ;; - Leave GOT_VERSION_REGNUM out of all register classes.
6790 ;; The register is therefore not a valid register_operand
6791 ;; and cannot be moved to or from other registers.
6792
6793 (define_insn "load_call<mode>"
6794 [(set (match_operand:P 0 "register_operand" "=d")
6795 (unspec:P [(match_operand:P 1 "register_operand" "d")
6796 (match_operand:P 2 "immediate_operand" "")
6797 (reg:SI GOT_VERSION_REGNUM)] UNSPEC_LOAD_CALL))]
6798 "TARGET_USE_GOT"
6799 "<load>\t%0,%R2(%1)"
6800 [(set_attr "got" "load")
6801 (set_attr "mode" "<MODE>")])
6802
6803 (define_insn "set_got_version"
6804 [(set (reg:SI GOT_VERSION_REGNUM)
6805 (unspec_volatile:SI [(const_int 0)] UNSPEC_SET_GOT_VERSION))]
6806 "TARGET_USE_GOT"
6807 ""
6808 [(set_attr "type" "ghost")])
6809
6810 (define_insn "update_got_version"
6811 [(set (reg:SI GOT_VERSION_REGNUM)
6812 (unspec:SI [(reg:SI GOT_VERSION_REGNUM)] UNSPEC_UPDATE_GOT_VERSION))]
6813 "TARGET_USE_GOT"
6814 ""
6815 [(set_attr "type" "ghost")])
6816
6817 ;; Sibling calls. All these patterns use jump instructions.
6818
6819 ;; If TARGET_SIBCALLS, call_insn_operand will only accept constant
6820 ;; addresses if a direct jump is acceptable. Since the 'S' constraint
6821 ;; is defined in terms of call_insn_operand, the same is true of the
6822 ;; constraints.
6823
6824 ;; When we use an indirect jump, we need a register that will be
6825 ;; preserved by the epilogue. Since TARGET_USE_PIC_FN_ADDR_REG forces
6826 ;; us to use $25 for this purpose -- and $25 is never clobbered by the
6827 ;; epilogue -- we might as well use it for !TARGET_USE_PIC_FN_ADDR_REG
6828 ;; as well.
6829
6830 (define_expand "sibcall"
6831 [(parallel [(call (match_operand 0 "")
6832 (match_operand 1 ""))
6833 (use (match_operand 2 "")) ;; next_arg_reg
6834 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6835 "TARGET_SIBCALLS"
6836 {
6837 mips_expand_call (MIPS_CALL_SIBCALL, NULL_RTX, XEXP (operands[0], 0),
6838 operands[1], operands[2], false);
6839 DONE;
6840 })
6841
6842 (define_insn "sibcall_internal"
6843 [(call (mem:SI (match_operand 0 "call_insn_operand" "j,S"))
6844 (match_operand 1 "" ""))]
6845 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6846 { return mips_output_jump (operands, 0, 1, false); }
6847 [(set_attr "jal" "indirect,direct")
6848 (set_attr "jal_macro" "no")])
6849
6850 (define_expand "sibcall_value"
6851 [(parallel [(set (match_operand 0 "")
6852 (call (match_operand 1 "")
6853 (match_operand 2 "")))
6854 (use (match_operand 3 ""))])] ;; next_arg_reg
6855 "TARGET_SIBCALLS"
6856 {
6857 mips_expand_call (MIPS_CALL_SIBCALL, operands[0], XEXP (operands[1], 0),
6858 operands[2], operands[3], false);
6859 DONE;
6860 })
6861
6862 (define_insn "sibcall_value_internal"
6863 [(set (match_operand 0 "register_operand" "")
6864 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6865 (match_operand 2 "" "")))]
6866 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6867 { return mips_output_jump (operands, 1, 2, false); }
6868 [(set_attr "jal" "indirect,direct")
6869 (set_attr "jal_macro" "no")])
6870
6871 (define_insn "sibcall_value_multiple_internal"
6872 [(set (match_operand 0 "register_operand" "")
6873 (call (mem:SI (match_operand 1 "call_insn_operand" "j,S"))
6874 (match_operand 2 "" "")))
6875 (set (match_operand 3 "register_operand" "")
6876 (call (mem:SI (match_dup 1))
6877 (match_dup 2)))]
6878 "TARGET_SIBCALLS && SIBLING_CALL_P (insn)"
6879 { return mips_output_jump (operands, 1, 2, false); }
6880 [(set_attr "jal" "indirect,direct")
6881 (set_attr "jal_macro" "no")])
6882
6883 (define_expand "call"
6884 [(parallel [(call (match_operand 0 "")
6885 (match_operand 1 ""))
6886 (use (match_operand 2 "")) ;; next_arg_reg
6887 (use (match_operand 3 ""))])] ;; struct_value_size_rtx
6888 ""
6889 {
6890 mips_expand_call (MIPS_CALL_NORMAL, NULL_RTX, XEXP (operands[0], 0),
6891 operands[1], operands[2], false);
6892 DONE;
6893 })
6894
6895 ;; This instruction directly corresponds to an assembly-language "jal".
6896 ;; There are four cases:
6897 ;;
6898 ;; - -mno-abicalls:
6899 ;; Both symbolic and register destinations are OK. The pattern
6900 ;; always expands to a single mips instruction.
6901 ;;
6902 ;; - -mabicalls/-mno-explicit-relocs:
6903 ;; Again, both symbolic and register destinations are OK.
6904 ;; The call is treated as a multi-instruction black box.
6905 ;;
6906 ;; - -mabicalls/-mexplicit-relocs with n32 or n64:
6907 ;; Only "jal $25" is allowed. This expands to a single "jalr $25"
6908 ;; instruction.
6909 ;;
6910 ;; - -mabicalls/-mexplicit-relocs with o32 or o64:
6911 ;; Only "jal $25" is allowed. The call is actually two instructions:
6912 ;; "jalr $25" followed by an insn to reload $gp.
6913 ;;
6914 ;; In the last case, we can generate the individual instructions with
6915 ;; a define_split. There are several things to be wary of:
6916 ;;
6917 ;; - We can't expose the load of $gp before reload. If we did,
6918 ;; it might get removed as dead, but reload can introduce new
6919 ;; uses of $gp by rematerializing constants.
6920 ;;
6921 ;; - We shouldn't restore $gp after calls that never return.
6922 ;; It isn't valid to insert instructions between a noreturn
6923 ;; call and the following barrier.
6924 ;;
6925 ;; - The splitter deliberately changes the liveness of $gp. The unsplit
6926 ;; instruction preserves $gp and so have no effect on its liveness.
6927 ;; But once we generate the separate insns, it becomes obvious that
6928 ;; $gp is not live on entry to the call.
6929 ;;
6930 (define_insn_and_split "call_internal"
6931 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6932 (match_operand 1 "" ""))
6933 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6934 ""
6935 {
6936 return (TARGET_SPLIT_CALLS ? "#"
6937 : mips_output_jump (operands, 0, 1, true));
6938 }
6939 "reload_completed && TARGET_SPLIT_CALLS"
6940 [(const_int 0)]
6941 {
6942 mips_split_call (curr_insn, gen_call_split (operands[0], operands[1]));
6943 DONE;
6944 }
6945 [(set_attr "jal" "indirect,direct")])
6946
6947 (define_insn "call_split"
6948 [(call (mem:SI (match_operand 0 "call_insn_operand" "c,S"))
6949 (match_operand 1 "" ""))
6950 (clobber (reg:SI RETURN_ADDR_REGNUM))
6951 (clobber (reg:SI 28))]
6952 "TARGET_SPLIT_CALLS"
6953 { return mips_output_jump (operands, 0, 1, true); }
6954 [(set_attr "jal" "indirect,direct")
6955 (set_attr "jal_macro" "no")])
6956
6957 ;; A pattern for calls that must be made directly. It is used for
6958 ;; MIPS16 calls that the linker may need to redirect to a hard-float
6959 ;; stub; the linker relies on the call relocation type to detect when
6960 ;; such redirection is needed.
6961 (define_insn_and_split "call_internal_direct"
6962 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6963 (match_operand 1))
6964 (const_int 1)
6965 (clobber (reg:SI RETURN_ADDR_REGNUM))]
6966 ""
6967 {
6968 return (TARGET_SPLIT_CALLS ? "#"
6969 : mips_output_jump (operands, 0, -1, true));
6970 }
6971 "reload_completed && TARGET_SPLIT_CALLS"
6972 [(const_int 0)]
6973 {
6974 mips_split_call (curr_insn,
6975 gen_call_direct_split (operands[0], operands[1]));
6976 DONE;
6977 }
6978 [(set_attr "jal" "direct")])
6979
6980 (define_insn "call_direct_split"
6981 [(call (mem:SI (match_operand 0 "const_call_insn_operand"))
6982 (match_operand 1))
6983 (const_int 1)
6984 (clobber (reg:SI RETURN_ADDR_REGNUM))
6985 (clobber (reg:SI 28))]
6986 "TARGET_SPLIT_CALLS"
6987 { return mips_output_jump (operands, 0, -1, true); }
6988 [(set_attr "jal" "direct")
6989 (set_attr "jal_macro" "no")])
6990
6991 (define_expand "call_value"
6992 [(parallel [(set (match_operand 0 "")
6993 (call (match_operand 1 "")
6994 (match_operand 2 "")))
6995 (use (match_operand 3 ""))])] ;; next_arg_reg
6996 ""
6997 {
6998 mips_expand_call (MIPS_CALL_NORMAL, operands[0], XEXP (operands[1], 0),
6999 operands[2], operands[3], false);
7000 DONE;
7001 })
7002
7003 ;; See comment for call_internal.
7004 (define_insn_and_split "call_value_internal"
7005 [(set (match_operand 0 "register_operand" "")
7006 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7007 (match_operand 2 "" "")))
7008 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7009 ""
7010 {
7011 return (TARGET_SPLIT_CALLS ? "#"
7012 : mips_output_jump (operands, 1, 2, true));
7013 }
7014 "reload_completed && TARGET_SPLIT_CALLS"
7015 [(const_int 0)]
7016 {
7017 mips_split_call (curr_insn,
7018 gen_call_value_split (operands[0], operands[1],
7019 operands[2]));
7020 DONE;
7021 }
7022 [(set_attr "jal" "indirect,direct")])
7023
7024 (define_insn "call_value_split"
7025 [(set (match_operand 0 "register_operand" "")
7026 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7027 (match_operand 2 "" "")))
7028 (clobber (reg:SI RETURN_ADDR_REGNUM))
7029 (clobber (reg:SI 28))]
7030 "TARGET_SPLIT_CALLS"
7031 { return mips_output_jump (operands, 1, 2, true); }
7032 [(set_attr "jal" "indirect,direct")
7033 (set_attr "jal_macro" "no")])
7034
7035 ;; See call_internal_direct.
7036 (define_insn_and_split "call_value_internal_direct"
7037 [(set (match_operand 0 "register_operand")
7038 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7039 (match_operand 2)))
7040 (const_int 1)
7041 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7042 ""
7043 {
7044 return (TARGET_SPLIT_CALLS ? "#"
7045 : mips_output_jump (operands, 1, -1, true));
7046 }
7047 "reload_completed && TARGET_SPLIT_CALLS"
7048 [(const_int 0)]
7049 {
7050 mips_split_call (curr_insn,
7051 gen_call_value_direct_split (operands[0], operands[1],
7052 operands[2]));
7053 DONE;
7054 }
7055 [(set_attr "jal" "direct")])
7056
7057 (define_insn "call_value_direct_split"
7058 [(set (match_operand 0 "register_operand")
7059 (call (mem:SI (match_operand 1 "const_call_insn_operand"))
7060 (match_operand 2)))
7061 (const_int 1)
7062 (clobber (reg:SI RETURN_ADDR_REGNUM))
7063 (clobber (reg:SI 28))]
7064 "TARGET_SPLIT_CALLS"
7065 { return mips_output_jump (operands, 1, -1, true); }
7066 [(set_attr "jal" "direct")
7067 (set_attr "jal_macro" "no")])
7068
7069 ;; See comment for call_internal.
7070 (define_insn_and_split "call_value_multiple_internal"
7071 [(set (match_operand 0 "register_operand" "")
7072 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7073 (match_operand 2 "" "")))
7074 (set (match_operand 3 "register_operand" "")
7075 (call (mem:SI (match_dup 1))
7076 (match_dup 2)))
7077 (clobber (reg:SI RETURN_ADDR_REGNUM))]
7078 ""
7079 {
7080 return (TARGET_SPLIT_CALLS ? "#"
7081 : mips_output_jump (operands, 1, 2, true));
7082 }
7083 "reload_completed && TARGET_SPLIT_CALLS"
7084 [(const_int 0)]
7085 {
7086 mips_split_call (curr_insn,
7087 gen_call_value_multiple_split (operands[0], operands[1],
7088 operands[2], operands[3]));
7089 DONE;
7090 }
7091 [(set_attr "jal" "indirect,direct")])
7092
7093 (define_insn "call_value_multiple_split"
7094 [(set (match_operand 0 "register_operand" "")
7095 (call (mem:SI (match_operand 1 "call_insn_operand" "c,S"))
7096 (match_operand 2 "" "")))
7097 (set (match_operand 3 "register_operand" "")
7098 (call (mem:SI (match_dup 1))
7099 (match_dup 2)))
7100 (clobber (reg:SI RETURN_ADDR_REGNUM))
7101 (clobber (reg:SI 28))]
7102 "TARGET_SPLIT_CALLS"
7103 { return mips_output_jump (operands, 1, 2, true); }
7104 [(set_attr "jal" "indirect,direct")
7105 (set_attr "jal_macro" "no")])
7106
7107 ;; Call subroutine returning any type.
7108
7109 (define_expand "untyped_call"
7110 [(parallel [(call (match_operand 0 "")
7111 (const_int 0))
7112 (match_operand 1 "")
7113 (match_operand 2 "")])]
7114 ""
7115 {
7116 int i;
7117
7118 emit_call_insn (gen_call (operands[0], const0_rtx, NULL, const0_rtx));
7119
7120 for (i = 0; i < XVECLEN (operands[2], 0); i++)
7121 {
7122 rtx set = XVECEXP (operands[2], 0, i);
7123 mips_emit_move (SET_DEST (set), SET_SRC (set));
7124 }
7125
7126 emit_insn (gen_blockage ());
7127 DONE;
7128 })
7129 \f
7130 ;;
7131 ;; ....................
7132 ;;
7133 ;; MISC.
7134 ;;
7135 ;; ....................
7136 ;;
7137
7138
7139 (define_insn "prefetch"
7140 [(prefetch (match_operand:QI 0 "address_operand" "ZD")
7141 (match_operand 1 "const_int_operand" "n")
7142 (match_operand 2 "const_int_operand" "n"))]
7143 "ISA_HAS_PREFETCH && TARGET_EXPLICIT_RELOCS"
7144 {
7145 if (TARGET_LOONGSON_2EF || TARGET_LOONGSON_3A)
7146 {
7147 /* Loongson 2[ef] and Loongson 3a use load to $0 for prefetching. */
7148 if (TARGET_64BIT)
7149 return "ld\t$0,%a0";
7150 else
7151 return "lw\t$0,%a0";
7152 }
7153 operands[1] = mips_prefetch_cookie (operands[1], operands[2]);
7154 return "pref\t%1,%a0";
7155 }
7156 [(set_attr "type" "prefetch")])
7157
7158 (define_insn "*prefetch_indexed_<mode>"
7159 [(prefetch (plus:P (match_operand:P 0 "register_operand" "d")
7160 (match_operand:P 1 "register_operand" "d"))
7161 (match_operand 2 "const_int_operand" "n")
7162 (match_operand 3 "const_int_operand" "n"))]
7163 "ISA_HAS_PREFETCHX && TARGET_HARD_FLOAT && TARGET_DOUBLE_FLOAT"
7164 {
7165 operands[2] = mips_prefetch_cookie (operands[2], operands[3]);
7166 return "prefx\t%2,%1(%0)";
7167 }
7168 [(set_attr "type" "prefetchx")])
7169
7170 (define_insn "nop"
7171 [(const_int 0)]
7172 ""
7173 "%(nop%)"
7174 [(set_attr "type" "nop")
7175 (set_attr "mode" "none")])
7176
7177 ;; Like nop, but commented out when outside a .set noreorder block.
7178 (define_insn "hazard_nop"
7179 [(const_int 1)]
7180 ""
7181 {
7182 if (mips_noreorder.nesting_level > 0)
7183 return "nop";
7184 else
7185 return "#nop";
7186 }
7187 [(set_attr "type" "nop")])
7188
7189 ;; The `.insn' pseudo-op.
7190 (define_insn "insn_pseudo"
7191 [(unspec_volatile [(const_int 0)] UNSPEC_INSN_PSEUDO)]
7192 ""
7193 ".insn"
7194 [(set_attr "mode" "none")
7195 (set_attr "insn_count" "0")])
7196 \f
7197 ;; MIPS4 Conditional move instructions.
7198
7199 (define_insn "*mov<GPR:mode>_on_<MOVECC:mode>"
7200 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7201 (if_then_else:GPR
7202 (match_operator 4 "equality_operator"
7203 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7204 (const_int 0)])
7205 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7206 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7207 "ISA_HAS_CONDMOVE"
7208 "@
7209 mov%T4\t%0,%z2,%1
7210 mov%t4\t%0,%z3,%1"
7211 [(set_attr "type" "condmove")
7212 (set_attr "mode" "<GPR:MODE>")])
7213
7214 (define_insn "*mov<GPR:mode>_on_<GPR2:mode>_ne"
7215 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7216 (if_then_else:GPR
7217 (match_operand:GPR2 1 "register_operand" "<GPR2:reg>,<GPR2:reg>")
7218 (match_operand:GPR 2 "reg_or_0_operand" "dJ,0")
7219 (match_operand:GPR 3 "reg_or_0_operand" "0,dJ")))]
7220 "ISA_HAS_CONDMOVE"
7221 "@
7222 movn\t%0,%z2,%1
7223 movz\t%0,%z3,%1"
7224 [(set_attr "type" "condmove")
7225 (set_attr "mode" "<GPR:MODE>")])
7226
7227 (define_insn "*mov<SCALARF:mode>_on_<MOVECC:mode>"
7228 [(set (match_operand:SCALARF 0 "register_operand" "=f,f")
7229 (if_then_else:SCALARF
7230 (match_operator 4 "equality_operator"
7231 [(match_operand:MOVECC 1 "register_operand" "<MOVECC:reg>,<MOVECC:reg>")
7232 (const_int 0)])
7233 (match_operand:SCALARF 2 "register_operand" "f,0")
7234 (match_operand:SCALARF 3 "register_operand" "0,f")))]
7235 "ISA_HAS_FP_CONDMOVE"
7236 "@
7237 mov%T4.<fmt>\t%0,%2,%1
7238 mov%t4.<fmt>\t%0,%3,%1"
7239 [(set_attr "type" "condmove")
7240 (set_attr "mode" "<SCALARF:MODE>")])
7241
7242 (define_insn "*sel<code><GPR:mode>_using_<GPR2:mode>"
7243 [(set (match_operand:GPR 0 "register_operand" "=d,d")
7244 (if_then_else:GPR
7245 (equality_op:GPR2 (match_operand:GPR2 1 "register_operand" "d,d")
7246 (const_int 0))
7247 (match_operand:GPR 2 "reg_or_0_operand" "d,J")
7248 (match_operand:GPR 3 "reg_or_0_operand" "J,d")))]
7249 "ISA_HAS_SEL
7250 && (register_operand (operands[2], <GPR:MODE>mode)
7251 != register_operand (operands[3], <GPR:MODE>mode))"
7252 "@
7253 <sel>\t%0,%2,%1
7254 <selinv>\t%0,%3,%1"
7255 [(set_attr "type" "condmove")
7256 (set_attr "mode" "<GPR:MODE>")])
7257
7258 ;; sel.fmt copies the 3rd argument when the 1st is non-zero and the 2nd
7259 ;; argument if the 1st is zero. This means operand 2 and 3 are
7260 ;; inverted in the instruction.
7261
7262 (define_insn "*sel<mode>"
7263 [(set (match_operand:SCALARF 0 "register_operand" "=f,f,f")
7264 (if_then_else:SCALARF
7265 (ne:CCF (match_operand:CCF 1 "register_operand" "0,f,f")
7266 (const_int 0))
7267 (match_operand:SCALARF 2 "reg_or_0_operand" "f,G,f")
7268 (match_operand:SCALARF 3 "reg_or_0_operand" "f,f,G")))]
7269 "ISA_HAS_SEL && ISA_HAS_CCF"
7270 "@
7271 sel.<fmt>\t%0,%3,%2
7272 seleqz.<fmt>\t%0,%3,%1
7273 selnez.<fmt>\t%0,%2,%1"
7274 [(set_attr "type" "condmove")
7275 (set_attr "mode" "<SCALARF:MODE>")])
7276
7277 ;; These are the main define_expand's used to make conditional moves.
7278
7279 (define_expand "mov<mode>cc"
7280 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7281 (set (match_operand:GPR 0 "register_operand")
7282 (if_then_else:GPR (match_dup 5)
7283 (match_operand:GPR 2 "reg_or_0_operand")
7284 (match_operand:GPR 3 "reg_or_0_operand")))]
7285 "ISA_HAS_CONDMOVE || ISA_HAS_SEL"
7286 {
7287 if (!ISA_HAS_FP_CONDMOVE
7288 && !INTEGRAL_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7289 FAIL;
7290
7291 mips_expand_conditional_move (operands);
7292 DONE;
7293 })
7294
7295 (define_expand "mov<mode>cc"
7296 [(set (match_dup 4) (match_operand 1 "comparison_operator"))
7297 (set (match_operand:SCALARF 0 "register_operand")
7298 (if_then_else:SCALARF (match_dup 5)
7299 (match_operand:SCALARF 2 "reg_or_0_operand")
7300 (match_operand:SCALARF 3 "reg_or_0_operand")))]
7301 "ISA_HAS_FP_CONDMOVE
7302 || (ISA_HAS_SEL && ISA_HAS_CCF)"
7303 {
7304 if (ISA_HAS_SEL && !FLOAT_MODE_P (GET_MODE (XEXP (operands[1], 0))))
7305 FAIL;
7306
7307 /* Workaround an LRA bug which means that tied operands in the sel.fmt
7308 pattern lead to the double precision destination of sel.d getting
7309 reloaded with the full register file usable and the restrictions on
7310 whether the CCFmode input can be used in odd-numbered single-precision
7311 registers are ignored. For consistency reasons the CCF mode values
7312 must be guaranteed to only exist in the even-registers because of
7313 the unusual duality between single and double precision values. */
7314 if (ISA_HAS_SEL && <MODE>mode == DFmode
7315 && (!TARGET_ODD_SPREG || TARGET_FLOATXX))
7316 FAIL;
7317
7318 mips_expand_conditional_move (operands);
7319 DONE;
7320 })
7321 \f
7322 ;;
7323 ;; ....................
7324 ;;
7325 ;; mips16 inline constant tables
7326 ;;
7327 ;; ....................
7328 ;;
7329
7330 (define_insn "consttable"
7331 [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7332 UNSPEC_CONSTTABLE)]
7333 ""
7334 ""
7335 [(set_attr "mode" "none")
7336 (set_attr "insn_count" "0")])
7337
7338 (define_insn "consttable_end"
7339 [(unspec_volatile [(match_operand 0 "const_int_operand" "")]
7340 UNSPEC_CONSTTABLE_END)]
7341 ""
7342 ""
7343 [(set_attr "mode" "none")
7344 (set_attr "insn_count" "0")])
7345
7346 (define_insn "consttable_tls_reloc"
7347 [(unspec_volatile [(match_operand 0 "tls_reloc_operand" "")
7348 (match_operand 1 "const_int_operand" "")]
7349 UNSPEC_CONSTTABLE_INT)]
7350 "TARGET_MIPS16_PCREL_LOADS"
7351 { return mips_output_tls_reloc_directive (&operands[0]); }
7352 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7353
7354 (define_insn "consttable_int"
7355 [(unspec_volatile [(match_operand 0 "consttable_operand" "")
7356 (match_operand 1 "const_int_operand" "")]
7357 UNSPEC_CONSTTABLE_INT)]
7358 "TARGET_MIPS16"
7359 {
7360 assemble_integer (mips_strip_unspec_address (operands[0]),
7361 INTVAL (operands[1]),
7362 BITS_PER_UNIT * INTVAL (operands[1]), 1);
7363 return "";
7364 }
7365 [(set (attr "length") (symbol_ref "INTVAL (operands[1])"))])
7366
7367 (define_insn "consttable_float"
7368 [(unspec_volatile [(match_operand 0 "consttable_operand" "")]
7369 UNSPEC_CONSTTABLE_FLOAT)]
7370 "TARGET_MIPS16"
7371 {
7372 gcc_assert (GET_CODE (operands[0]) == CONST_DOUBLE);
7373 assemble_real (*CONST_DOUBLE_REAL_VALUE (operands[0]),
7374 GET_MODE (operands[0]),
7375 GET_MODE_BITSIZE (GET_MODE (operands[0])));
7376 return "";
7377 }
7378 [(set (attr "length")
7379 (symbol_ref "GET_MODE_SIZE (GET_MODE (operands[0]))"))])
7380
7381 (define_insn "align"
7382 [(unspec_volatile [(match_operand 0 "const_int_operand" "")] UNSPEC_ALIGN)]
7383 ""
7384 ".align\t%0"
7385 [(set (attr "length") (symbol_ref "(1 << INTVAL (operands[0])) - 1"))])
7386 \f
7387 (define_split
7388 [(match_operand 0 "small_data_pattern")]
7389 "reload_completed"
7390 [(match_dup 0)]
7391 { operands[0] = mips_rewrite_small_data (operands[0]); })
7392
7393 ;;
7394 ;; ....................
7395 ;;
7396 ;; MIPS16e Save/Restore
7397 ;;
7398 ;; ....................
7399 ;;
7400
7401 (define_insn "*mips16e_save_restore"
7402 [(match_parallel 0 ""
7403 [(set (match_operand:SI 1 "register_operand")
7404 (plus:SI (match_dup 1)
7405 (match_operand:SI 2 "const_int_operand")))])]
7406 "operands[1] == stack_pointer_rtx
7407 && mips16e_save_restore_pattern_p (operands[0], INTVAL (operands[2]), NULL)"
7408 { return mips16e_output_save_restore (operands[0], INTVAL (operands[2])); }
7409 [(set_attr "type" "arith")
7410 (set_attr "extended_mips16" "yes")])
7411
7412 ;; Thread-Local Storage
7413
7414 ;; The TLS base pointer is accessed via "rdhwr $3, $29". No current
7415 ;; MIPS architecture defines this register, and no current
7416 ;; implementation provides it; instead, any OS which supports TLS is
7417 ;; expected to trap and emulate this instruction. rdhwr is part of the
7418 ;; MIPS 32r2 specification, but we use it on any architecture because
7419 ;; we expect it to be emulated. Use .set to force the assembler to
7420 ;; accept it.
7421 ;;
7422 ;; We do not use a constraint to force the destination to be $3
7423 ;; because $3 can appear explicitly as a function return value.
7424 ;; If we leave the use of $3 implicit in the constraints until
7425 ;; reload, we may end up making a $3 return value live across
7426 ;; the instruction, leading to a spill failure when reloading it.
7427 (define_insn_and_split "tls_get_tp_<mode>"
7428 [(set (match_operand:P 0 "register_operand" "=d")
7429 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7430 (clobber (reg:P TLS_GET_TP_REGNUM))]
7431 "HAVE_AS_TLS && !TARGET_MIPS16"
7432 "#"
7433 "&& reload_completed"
7434 [(set (reg:P TLS_GET_TP_REGNUM)
7435 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))
7436 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7437 ""
7438 [(set_attr "type" "unknown")
7439 (set_attr "mode" "<MODE>")
7440 (set_attr "insn_count" "2")])
7441
7442 (define_insn "*tls_get_tp_<mode>_split"
7443 [(set (reg:P TLS_GET_TP_REGNUM)
7444 (unspec:P [(const_int 0)] UNSPEC_TLS_GET_TP))]
7445 "HAVE_AS_TLS && !TARGET_MIPS16"
7446 {
7447 if (mips_isa_rev >= 2)
7448 return "rdhwr\t$3,$29";
7449
7450 return ".set\tpush\;.set\tmips32r2\t\;rdhwr\t$3,$29\;.set\tpop";
7451 }
7452 [(set_attr "type" "unknown")
7453 ; Since rdhwr always generates a trap for now, putting it in a delay
7454 ; slot would make the kernel's emulation of it much slower.
7455 (set_attr "can_delay" "no")
7456 (set_attr "mode" "<MODE>")])
7457
7458 ;; In MIPS16 mode, the TLS base pointer is accessed by a
7459 ;; libgcc helper function __mips16_rdhwr(), as 'rdhwr' is not
7460 ;; accessible in MIPS16.
7461 ;;
7462 ;; This is not represented as a call insn, to avoid the
7463 ;; unnecesarry clobbering of caller-save registers by a
7464 ;; function consisting only of: "rdhwr $3,$29; j $31; nop;"
7465 ;;
7466 ;; A $25 clobber is added to cater for a $25 load stub added by the
7467 ;; linker to __mips16_rdhwr when the call is made from non-PIC code.
7468
7469 (define_insn_and_split "tls_get_tp_mips16_<mode>"
7470 [(set (match_operand:P 0 "register_operand" "=d")
7471 (unspec:P [(match_operand:P 1 "call_insn_operand" "dS")]
7472 UNSPEC_TLS_GET_TP))
7473 (clobber (reg:P TLS_GET_TP_REGNUM))
7474 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7475 (clobber (reg:P RETURN_ADDR_REGNUM))]
7476 "HAVE_AS_TLS && TARGET_MIPS16"
7477 "#"
7478 "&& reload_completed"
7479 [(parallel [(set (reg:P TLS_GET_TP_REGNUM)
7480 (unspec:P [(match_dup 1)] UNSPEC_TLS_GET_TP))
7481 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7482 (clobber (reg:P RETURN_ADDR_REGNUM))])
7483 (set (match_dup 0) (reg:P TLS_GET_TP_REGNUM))]
7484 ""
7485 [(set_attr "type" "multi")
7486 (set_attr "insn_count" "4")
7487 (set_attr "mode" "<MODE>")])
7488
7489 (define_insn "*tls_get_tp_mips16_call_<mode>"
7490 [(set (reg:P TLS_GET_TP_REGNUM)
7491 (unspec:P [(match_operand:P 0 "call_insn_operand" "dS")]
7492 UNSPEC_TLS_GET_TP))
7493 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7494 (clobber (reg:P RETURN_ADDR_REGNUM))]
7495 "HAVE_AS_TLS && TARGET_MIPS16"
7496 { return mips_output_jump (operands, 0, -1, true); }
7497 [(set_attr "type" "call")
7498 (set_attr "insn_count" "3")
7499 (set_attr "mode" "<MODE>")])
7500
7501 ;; Named pattern for expanding thread pointer reference.
7502 (define_expand "get_thread_pointer<mode>"
7503 [(match_operand:P 0 "register_operand" "=d")]
7504 "HAVE_AS_TLS"
7505 {
7506 mips_expand_thread_pointer (operands[0]);
7507 DONE;
7508 })
7509
7510 ;; __builtin_mips_get_fcsr: move the FCSR into operand 0.
7511 (define_expand "mips_get_fcsr"
7512 [(set (match_operand:SI 0 "register_operand")
7513 (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7514 "TARGET_HARD_FLOAT_ABI"
7515 {
7516 if (TARGET_MIPS16)
7517 {
7518 mips16_expand_get_fcsr (operands[0]);
7519 DONE;
7520 }
7521 })
7522
7523 (define_insn "*mips_get_fcsr"
7524 [(set (match_operand:SI 0 "register_operand" "=d")
7525 (unspec_volatile [(const_int 0)] UNSPEC_GET_FCSR))]
7526 "TARGET_HARD_FLOAT"
7527 "cfc1\t%0,$31")
7528
7529 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7530 (define_insn "mips_get_fcsr_mips16_<mode>"
7531 [(set (reg:SI GET_FCSR_REGNUM)
7532 (unspec:SI [(match_operand:P 0 "call_insn_operand" "dS")]
7533 UNSPEC_GET_FCSR))
7534 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7535 (clobber (reg:P RETURN_ADDR_REGNUM))]
7536 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7537 { return mips_output_jump (operands, 0, -1, true); }
7538 [(set_attr "type" "call")
7539 (set_attr "insn_count" "3")])
7540
7541 ;; __builtin_mips_set_fcsr: move operand 0 into the FCSR.
7542 (define_expand "mips_set_fcsr"
7543 [(unspec_volatile [(match_operand:SI 0 "register_operand")]
7544 UNSPEC_SET_FCSR)]
7545 "TARGET_HARD_FLOAT_ABI"
7546 {
7547 if (TARGET_MIPS16)
7548 {
7549 mips16_expand_set_fcsr (operands[0]);
7550 DONE;
7551 }
7552 })
7553
7554 (define_insn "*mips_set_fcsr"
7555 [(unspec_volatile [(match_operand:SI 0 "register_operand" "d")]
7556 UNSPEC_SET_FCSR)]
7557 "TARGET_HARD_FLOAT"
7558 "ctc1\t%0,$31")
7559
7560 ;; See tls_get_tp_mips16_<mode> for why this form is used.
7561 (define_insn "mips_set_fcsr_mips16_<mode>"
7562 [(unspec_volatile:SI [(match_operand:P 0 "call_insn_operand" "dS")
7563 (reg:SI SET_FCSR_REGNUM)] UNSPEC_SET_FCSR)
7564 (clobber (reg:P PIC_FUNCTION_ADDR_REGNUM))
7565 (clobber (reg:P RETURN_ADDR_REGNUM))]
7566 "TARGET_HARD_FLOAT_ABI && TARGET_MIPS16"
7567 { return mips_output_jump (operands, 0, -1, true); }
7568 [(set_attr "type" "call")
7569 (set_attr "insn_count" "3")])
7570
7571 ;; Match paired HI/SI/SF/DFmode load/stores.
7572 (define_insn "*join2_load_store<JOIN_MODE:mode>"
7573 [(set (match_operand:JOIN_MODE 0 "nonimmediate_operand" "=d,f,m,m")
7574 (match_operand:JOIN_MODE 1 "nonimmediate_operand" "m,m,d,f"))
7575 (set (match_operand:JOIN_MODE 2 "nonimmediate_operand" "=d,f,m,m")
7576 (match_operand:JOIN_MODE 3 "nonimmediate_operand" "m,m,d,f"))]
7577 "ENABLE_LD_ST_PAIRS && reload_completed"
7578 {
7579 bool load_p = (which_alternative == 0 || which_alternative == 1);
7580 /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7581 Hardware does not bond those loads, even when they are consecutive.
7582 However, order of the loads need to be checked for correctness. */
7583 if (!load_p || !reg_overlap_mentioned_p (operands[0], operands[1]))
7584 {
7585 output_asm_insn (mips_output_move (operands[0], operands[1]),
7586 operands);
7587 output_asm_insn (mips_output_move (operands[2], operands[3]),
7588 &operands[2]);
7589 }
7590 else
7591 {
7592 output_asm_insn (mips_output_move (operands[2], operands[3]),
7593 &operands[2]);
7594 output_asm_insn (mips_output_move (operands[0], operands[1]),
7595 operands);
7596 }
7597 return "";
7598 }
7599 [(set_attr "move_type" "load,fpload,store,fpstore")
7600 (set_attr "insn_count" "2,2,2,2")])
7601
7602 ;; 2 HI/SI/SF/DF loads are joined.
7603 ;; P5600 does not support bonding of two LBs, hence QI mode is not included.
7604 ;; The loads must be non-volatile as they might be reordered at the time of asm
7605 ;; generation.
7606 (define_peephole2
7607 [(set (match_operand:JOIN_MODE 0 "register_operand")
7608 (match_operand:JOIN_MODE 1 "non_volatile_mem_operand"))
7609 (set (match_operand:JOIN_MODE 2 "register_operand")
7610 (match_operand:JOIN_MODE 3 "non_volatile_mem_operand"))]
7611 "ENABLE_LD_ST_PAIRS
7612 && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, true)"
7613 [(parallel [(set (match_dup 0)
7614 (match_dup 1))
7615 (set (match_dup 2)
7616 (match_dup 3))])]
7617 "")
7618
7619 ;; 2 HI/SI/SF/DF stores are joined.
7620 ;; P5600 does not support bonding of two SBs, hence QI mode is not included.
7621 (define_peephole2
7622 [(set (match_operand:JOIN_MODE 0 "memory_operand")
7623 (match_operand:JOIN_MODE 1 "register_operand"))
7624 (set (match_operand:JOIN_MODE 2 "memory_operand")
7625 (match_operand:JOIN_MODE 3 "register_operand"))]
7626 "ENABLE_LD_ST_PAIRS
7627 && mips_load_store_bonding_p (operands, <JOIN_MODE:MODE>mode, false)"
7628 [(parallel [(set (match_dup 0)
7629 (match_dup 1))
7630 (set (match_dup 2)
7631 (match_dup 3))])]
7632 "")
7633
7634 ;; Match paired HImode loads.
7635 (define_insn "*join2_loadhi"
7636 [(set (match_operand:SI 0 "register_operand" "=r")
7637 (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand" "m")))
7638 (set (match_operand:SI 2 "register_operand" "=r")
7639 (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand" "m")))]
7640 "ENABLE_LD_ST_PAIRS && reload_completed"
7641 {
7642 /* Reg-renaming pass reuses base register if it is dead after bonded loads.
7643 Hardware does not bond those loads, even when they are consecutive.
7644 However, order of the loads need to be checked for correctness. */
7645 if (!reg_overlap_mentioned_p (operands[0], operands[1]))
7646 {
7647 output_asm_insn ("lh<u>\t%0,%1", operands);
7648 output_asm_insn ("lh<u>\t%2,%3", operands);
7649 }
7650 else
7651 {
7652 output_asm_insn ("lh<u>\t%2,%3", operands);
7653 output_asm_insn ("lh<u>\t%0,%1", operands);
7654 }
7655
7656 return "";
7657 }
7658 [(set_attr "move_type" "load")
7659 (set_attr "insn_count" "2")])
7660
7661
7662 ;; 2 HI loads are joined.
7663 (define_peephole2
7664 [(set (match_operand:SI 0 "register_operand")
7665 (any_extend:SI (match_operand:HI 1 "non_volatile_mem_operand")))
7666 (set (match_operand:SI 2 "register_operand")
7667 (any_extend:SI (match_operand:HI 3 "non_volatile_mem_operand")))]
7668 "ENABLE_LD_ST_PAIRS
7669 && mips_load_store_bonding_p (operands, HImode, true)"
7670 [(parallel [(set (match_dup 0)
7671 (any_extend:SI (match_dup 1)))
7672 (set (match_dup 2)
7673 (any_extend:SI (match_dup 3)))])]
7674 "")
7675
7676 \f
7677 ;; Synchronization instructions.
7678
7679 (include "sync.md")
7680
7681 ; The MIPS Paired-Single Floating Point and MIPS-3D Instructions.
7682
7683 (include "mips-ps-3d.md")
7684
7685 ; The MIPS DSP Instructions.
7686
7687 (include "mips-dsp.md")
7688
7689 ; The MIPS DSP REV 2 Instructions.
7690
7691 (include "mips-dspr2.md")
7692
7693 ; MIPS fixed-point instructions.
7694 (include "mips-fixed.md")
7695
7696 ; microMIPS patterns.
7697 (include "micromips.md")
7698
7699 ; ST-Microelectronics Loongson-2E/2F-specific patterns.
7700 (include "loongson.md")
7701
7702 ; The MIPS MSA Instructions.
7703 (include "mips-msa.md")
7704
7705 (define_c_enum "unspec" [
7706 UNSPEC_ADDRESS_FIRST
7707 ])