Debian Codegraph @

gcc/config/rs6000/rs6000.md

raw
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990-2025 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner ([email protected])
4
5 ;; This file is part of GCC.
6
7 ;; GCC is free software; you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License as published
9 ;; by the Free Software Foundation; either version 3, or (at your
10 ;; option) any later version.
11
12 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
13 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 ;; License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GCC; see the file COPYING3. If not see
19 ;; <http://www.gnu.org/licenses/>.
20
21 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
22
23 ;;
24 ;; REGNOS
25 ;;
26
27 (define_constants
28 [(FIRST_GPR_REGNO 0)
29 (STACK_POINTER_REGNUM 1)
30 (TOC_REGNUM 2)
31 (STATIC_CHAIN_REGNUM 11)
32 (HARD_FRAME_POINTER_REGNUM 31)
33 (LAST_GPR_REGNO 31)
34 (FIRST_FPR_REGNO 32)
35 (LAST_FPR_REGNO 63)
36 (FIRST_ALTIVEC_REGNO 64)
37 (LAST_ALTIVEC_REGNO 95)
38 (LR_REGNO 96)
39 (CTR_REGNO 97)
40 (CA_REGNO 98)
41 (ARG_POINTER_REGNUM 99)
42 (CR0_REGNO 100)
43 (CR1_REGNO 101)
44 (CR2_REGNO 102)
45 (CR3_REGNO 103)
46 (CR4_REGNO 104)
47 (CR5_REGNO 105)
48 (CR6_REGNO 106)
49 (CR7_REGNO 107)
50 (MAX_CR_REGNO 107)
51 (VRSAVE_REGNO 108)
52 (VSCR_REGNO 109)
53 (FRAME_POINTER_REGNUM 110)
54 ])
55
56 ;;
57 ;; Test data class mask bits
58 ;;
59
60 (define_constants
61 [(VSX_TEST_DATA_CLASS_NAN 0x40)
62 (VSX_TEST_DATA_CLASS_POS_INF 0x20)
63 (VSX_TEST_DATA_CLASS_NEG_INF 0x10)
64 (VSX_TEST_DATA_CLASS_POS_ZERO 0x8)
65 (VSX_TEST_DATA_CLASS_NEG_ZERO 0x4)
66 (VSX_TEST_DATA_CLASS_POS_DENORMAL 0x2)
67 (VSX_TEST_DATA_CLASS_NEG_DENORMAL 0x1)
68 ])
69
70 ;;
71 ;; UNSPEC usage
72 ;;
73
74 (define_c_enum "unspec"
75 [UNSPEC_PROBE_STACK ; probe stack memory reference
76 UNSPEC_TOCPTR ; address of a word pointing to the TOC
77 UNSPEC_TOC ; address of the TOC (more-or-less)
78 UNSPEC_TOCSLOT ; offset from r1 of toc pointer save slot
79 UNSPEC_MOVSI_GOT
80 UNSPEC_FCTIWZ
81 UNSPEC_FRIM
82 UNSPEC_FRIN
83 UNSPEC_FRIP
84 UNSPEC_FRIZ
85 UNSPEC_XSRDPI
86 UNSPEC_LD_MPIC ; load_macho_picbase
87 UNSPEC_RELD_MPIC ; re-load_macho_picbase
88 UNSPEC_MPIC_CORRECT ; macho_correct_pic
89 UNSPEC_TLSGD
90 UNSPEC_TLSLD
91 UNSPEC_TLS_GET_ADDR
92 UNSPEC_MOVESI_FROM_CR
93 UNSPEC_MOVESI_TO_CR
94 UNSPEC_XVTLSBB
95 UNSPEC_TLSDTPREL
96 UNSPEC_TLSDTPRELHA
97 UNSPEC_TLSDTPRELLO
98 UNSPEC_TLSGOTDTPREL
99 UNSPEC_TLSTPREL
100 UNSPEC_TLSTPRELHA
101 UNSPEC_TLSTPRELLO
102 UNSPEC_TLSGOTTPREL
103 UNSPEC_TLSTLS
104 UNSPEC_TLSTLS_PCREL
105 UNSPEC_FIX_TRUNC_TF ; fadd, rounding towards zero
106 UNSPEC_STFIWX
107 UNSPEC_POPCNTB
108 UNSPEC_FRES
109 UNSPEC_SP_SET
110 UNSPEC_SP_TEST
111 UNSPEC_SYNC
112 UNSPEC_LWSYNC
113 UNSPEC_SYNC_OP
114 UNSPEC_ATOMIC
115 UNSPEC_CMPXCHG
116 UNSPEC_XCHG
117 UNSPEC_AND
118 UNSPEC_DLMZB
119 UNSPEC_DLMZB_CR
120 UNSPEC_DLMZB_STRLEN
121 UNSPEC_RSQRT
122 UNSPEC_TOCREL
123 UNSPEC_MACHOPIC_OFFSET
124 UNSPEC_BPERM
125 UNSPEC_PARITY
126 UNSPEC_CMPB
127 UNSPEC_FCTIW
128 UNSPEC_FCTID
129 UNSPEC_LFIWAX
130 UNSPEC_LFIWZX
131 UNSPEC_FCTIWUZ
132 UNSPEC_NOP
133 UNSPEC_GRP_END_NOP
134 UNSPEC_P8V_FMRGOW
135 UNSPEC_P8V_MTVSRWZ
136 UNSPEC_P8V_RELOAD_FROM_GPR
137 UNSPEC_P8V_MTVSRD
138 UNSPEC_P8V_XXPERMDI
139 UNSPEC_P8V_RELOAD_FROM_VSX
140 UNSPEC_ADDG6S
141 UNSPEC_CDTBCD
142 UNSPEC_CBCDTD
143 UNSPEC_DIVE
144 UNSPEC_DIVEU
145 UNSPEC_UNPACK_128BIT
146 UNSPEC_PACK_128BIT
147 UNSPEC_LSQ
148 UNSPEC_FUSION_GPR
149 UNSPEC_STACK_CHECK
150 UNSPEC_CMPRB
151 UNSPEC_CMPRB2
152 UNSPEC_CMPEQB
153 UNSPEC_ADD_ROUND_TO_ODD
154 UNSPEC_SUB_ROUND_TO_ODD
155 UNSPEC_MUL_ROUND_TO_ODD
156 UNSPEC_DIV_ROUND_TO_ODD
157 UNSPEC_FMA_ROUND_TO_ODD
158 UNSPEC_SQRT_ROUND_TO_ODD
159 UNSPEC_TRUNC_ROUND_TO_ODD
160 UNSPEC_SIGNBIT
161 UNSPEC_SF_FROM_SI
162 UNSPEC_SI_FROM_SF
163 UNSPEC_PLTSEQ
164 UNSPEC_PLT16_HA
165 UNSPEC_CFUGED
166 UNSPEC_CNTLZDM
167 UNSPEC_CNTTZDM
168 UNSPEC_PDEPD
169 UNSPEC_PEXTD
170 UNSPEC_HASHST
171 UNSPEC_HASHCHK
172 UNSPEC_XXSPLTIDP_CONST
173 UNSPEC_XXSPLTIW_CONST
174 UNSPEC_FMAX
175 UNSPEC_FMIN
176 ])
177
178 ;;
179 ;; UNSPEC_VOLATILE usage
180 ;;
181
182 (define_c_enum "unspecv"
183 [UNSPECV_BLOCK
184 UNSPECV_LL ; load-locked
185 UNSPECV_SC ; store-conditional
186 UNSPECV_PROBE_STACK_RANGE ; probe range of stack addresses
187 UNSPECV_EH_RR ; eh_reg_restore
188 UNSPECV_ISYNC ; isync instruction
189 UNSPECV_MFTB ; move from time base
190 UNSPECV_DARN ; darn (deliver a random number)
191 UNSPECV_NLGR ; non-local goto receiver
192 UNSPECV_MFFS ; Move from FPSCR
193 UNSPECV_MFFSL ; Move from FPSCR light instruction version
194 UNSPECV_MFFSCRN ; Move from FPSCR float rounding mode
195 UNSPECV_MFFSCDRN ; Move from FPSCR decimal float rounding mode
196 UNSPECV_MTFSF ; Move to FPSCR Fields 8 to 15
197 UNSPECV_MTFSF_HI ; Move to FPSCR Fields 0 to 7
198 UNSPECV_MTFSB0 ; Set FPSCR Field bit to 0
199 UNSPECV_MTFSB1 ; Set FPSCR Field bit to 1
200 UNSPECV_SPLIT_STACK_RETURN ; A camouflaged return
201 UNSPECV_SPEC_BARRIER ; Speculation barrier
202 UNSPECV_PLT16_LO
203 UNSPECV_PLT_PCREL
204 ])
205
206 ; The three different kinds of epilogue.
207 (define_enum "epilogue_type" [normal sibcall eh_return])
208
209 ;; Define an insn type attribute. This is used in function unit delay
210 ;; computations.
211 (define_attr "type"
212 "integer,two,three,
213 add,logical,shift,insert,
214 mul,halfmul,div,
215 exts,cntlz,popcnt,isel,
216 load,store,fpload,fpstore,vecload,vecstore,
217 cmp,
218 branch,jmpreg,mfjmpr,mtjmpr,trap,isync,sync,load_l,store_c,
219 cr_logical,mfcr,mfcrf,mtcr,
220 fpcompare,fp,fpsimple,dmul,qmul,sdiv,ddiv,ssqrt,dsqrt,
221 vecsimple,veccomplex,vecdiv,veccmp,veccmpsimple,vecperm,
222 vecfloat,vecfdiv,vecdouble,mtvsr,mfvsr,crypto,
223 veclogical,veccmpfx,vecexts,vecmove,
224 htm,htmsimple,dfp,mma,
225 fused_arith_logical,
226 fused_cmp_isel,
227 fused_carry,
228 fused_load_cmpi,
229 fused_load_load,fused_store_store,
230 fused_addis_load,
231 fused_mtbc,
232 fused_vector"
233 (const_string "integer"))
234 ;; Attr type definitions for fused pairs:
235 ;; fused_arith_logical is used for scalar logical+add/subf and
236 ;; add/subf+logical pairs of instructions.
237 ;; fused_load_cmpi is used for a D-form load fused with
238 ;; a compare immediate.
239 ;; fused_load_load is for a fused pair of loads to adjacent addresses.
240 ;; fused_store_store is for a fused pair of stores to adjacent addresses.
241 ;; fused_addis_load is for addis fused to D-form load for a larger immediate.
242 ;; fused_mtbc is for fused mtlr and bclr[l] pairs.
243 ;; fused_vector is for a fused pair of vector logical instructions.
244
245 ;; What data size does this instruction work on?
246 ;; This is used for insert, mul and others as necessary.
247 (define_attr "size" "8,16,32,64,128,256" (const_string "32"))
248
249 ;; What is the insn_cost for this insn? The target hook can still override
250 ;; this. For optimizing for size the "length" attribute is used instead.
251 (define_attr "cost" "" (const_int 0))
252
253 ;; Is this instruction record form ("dot", signed compare to 0, writing CR0)?
254 ;; This is used for add, logical, shift, exts, mul.
255 (define_attr "dot" "no,yes" (const_string "no"))
256
257 ;; Does this instruction sign-extend its result?
258 ;; This is used for load insns.
259 (define_attr "sign_extend" "no,yes" (const_string "no"))
260
261 ;; Does this cr_logical instruction have three operands? That is, BT != BB.
262 (define_attr "cr_logical_3op" "no,yes" (const_string "no"))
263
264 ;; Does this instruction use indexed (that is, reg+reg) addressing?
265 ;; This is used for load and store insns. If operand 0 or 1 is a MEM
266 ;; it is automatically set based on that. If a load or store instruction
267 ;; has fewer than two operands it needs to set this attribute manually
268 ;; or the compiler will crash.
269 (define_attr "indexed" "no,yes"
270 (if_then_else (ior (match_operand 0 "indexed_address_mem")
271 (match_operand 1 "indexed_address_mem"))
272 (const_string "yes")
273 (const_string "no")))
274
275 ;; Does this instruction use update addressing?
276 ;; This is used for load and store insns. See the comments for "indexed".
277 (define_attr "update" "no,yes"
278 (if_then_else (ior (match_operand 0 "update_address_mem")
279 (match_operand 1 "update_address_mem"))
280 (const_string "yes")
281 (const_string "no")))
282
283 ;; Is this instruction using operands[2] as shift amount, and can that be a
284 ;; register?
285 ;; This is used for shift insns.
286 (define_attr "maybe_var_shift" "no,yes" (const_string "no"))
287
288 ;; Is this instruction using a shift amount from a register?
289 ;; This is used for shift insns.
290 (define_attr "var_shift" "no,yes"
291 (if_then_else (and (eq_attr "type" "shift")
292 (eq_attr "maybe_var_shift" "yes"))
293 (if_then_else (match_operand 2 "gpc_reg_operand")
294 (const_string "yes")
295 (const_string "no"))
296 (const_string "no")))
297
298 ;; Is copying of this instruction disallowed?
299 (define_attr "cannot_copy" "no,yes" (const_string "no"))
300
301
302 ;; Whether this insn has a prefixed form and a non-prefixed form.
303 (define_attr "maybe_prefixed" "no,yes"
304 (if_then_else (eq_attr "type" "load,fpload,vecload,store,fpstore,vecstore,
305 integer,add,fused_load_cmpi")
306 (const_string "yes")
307 (const_string "no")))
308
309 ;; Whether an insn is a prefixed insn. A prefixed instruction has a prefix
310 ;; instruction word that conveys additional information such as a larger
311 ;; immediate, additional operands, etc., in addition to the normal instruction
312 ;; word. The default "length" attribute will also be adjusted by default to
313 ;; be 12 bytes.
314 (define_attr "prefixed" "no,yes"
315 (cond [(ior (match_test "!TARGET_PREFIXED")
316 (match_test "!NONJUMP_INSN_P (insn)")
317 (eq_attr "maybe_prefixed" "no"))
318 (const_string "no")
319
320 (eq_attr "type" "load,fpload,vecload,fused_load_cmpi")
321 (if_then_else (match_test "prefixed_load_p (insn)")
322 (const_string "yes")
323 (const_string "no"))
324
325 (eq_attr "type" "store,fpstore,vecstore")
326 (if_then_else (match_test "prefixed_store_p (insn)")
327 (const_string "yes")
328 (const_string "no"))
329
330 (eq_attr "type" "integer,add")
331 (if_then_else (match_test "prefixed_paddi_p (insn)")
332 (const_string "yes")
333 (const_string "no"))]
334
335 (const_string "no")))
336
337 ;; Whether an insn loads an external address for the PCREL_OPT optimizaton.
338 (define_attr "loads_external_address" "no,yes"
339 (const_string "no"))
340
341 ;; Return the number of real hardware instructions in a combined insn. If it
342 ;; is 0, just use the length / 4.
343 (define_attr "num_insns" "" (const_int 0))
344
345 ;; If an insn is prefixed, return the maximum number of prefixed instructions
346 ;; in the insn. The macro ADJUST_INSN_LENGTH uses this number to adjust the
347 ;; insn length.
348 (define_attr "max_prefixed_insns" "" (const_int 1))
349
350 ;; Length of the instruction (in bytes). This length does not consider the
351 ;; length for prefixed instructions. The macro ADJUST_INSN_LENGTH will adjust
352 ;; the length if there are prefixed instructions.
353 ;;
354 ;; While it might be tempting to use num_insns to calculate the length, it can
355 ;; be problematical unless all insn lengths are adjusted to use num_insns
356 ;; (i.e. if num_insns is 0, it will get the length, which in turn will get
357 ;; num_insns and recurse).
358 (define_attr "length" "" (const_int 4))
359
360 ;; Processor type -- this attribute must exactly match the processor_type
361 ;; enumeration in rs6000-opts.h.
362 (define_attr "cpu"
363 "ppc601,ppc603,ppc604,ppc604e,ppc620,ppc630,
364 ppc750,ppc7400,ppc7450,
365 ppc403,ppc405,ppc440,ppc476,
366 ppc8540,ppc8548,ppce300c2,ppce300c3,ppce500mc,ppce500mc64,ppce5500,ppce6500,
367 power4,power5,power6,power7,power8,power9,power10,power11,
368 rs64a,mpccore,cell,ppca2,titan"
369 (const (symbol_ref "(enum attr_cpu) rs6000_tune")))
370
371 ;; The ISA we implement.
372 (define_attr "isa" "any,p5,p6,p7,p7v,p8,p8v,p9,p9v,p9kf,p9tf,p10"
373 (const_string "any"))
374
375 ;; Is this alternative enabled for the current CPU/ISA/etc.?
376 (define_attr "enabled" ""
377 (cond
378 [(eq_attr "isa" "any")
379 (const_int 1)
380
381 (and (eq_attr "isa" "p5")
382 (match_test "TARGET_POPCNTB"))
383 (const_int 1)
384
385 (and (eq_attr "isa" "p6")
386 (match_test "TARGET_CMPB"))
387 (const_int 1)
388
389 (and (eq_attr "isa" "p7")
390 (match_test "TARGET_POPCNTD"))
391 (const_int 1)
392
393 (and (eq_attr "isa" "p7v")
394 (match_test "TARGET_VSX"))
395 (const_int 1)
396
397 (and (eq_attr "isa" "p8")
398 (match_test "TARGET_POWER8"))
399 (const_int 1)
400
401 (and (eq_attr "isa" "p8v")
402 (match_test "TARGET_P8_VECTOR"))
403 (const_int 1)
404
405 (and (eq_attr "isa" "p9")
406 (match_test "TARGET_MODULO"))
407 (const_int 1)
408
409 (and (eq_attr "isa" "p9v")
410 (match_test "TARGET_P9_VECTOR"))
411 (const_int 1)
412
413 (and (eq_attr "isa" "p9kf")
414 (match_test "TARGET_FLOAT128_TYPE"))
415 (const_int 1)
416
417 (and (eq_attr "isa" "p9tf")
418 (match_test "FLOAT128_VECTOR_P (TFmode)"))
419 (const_int 1)
420
421 (and (eq_attr "isa" "p10")
422 (match_test "TARGET_POWER10"))
423 (const_int 1)
424 ] (const_int 0)))
425
426 ;; If this instruction is microcoded on the CELL processor
427 ; The default for load extended, the recorded instructions and rotate/shifts by a variable is always microcoded
428 (define_attr "cell_micro" "not,conditional,always"
429 (if_then_else (ior (and (eq_attr "type" "shift,exts,mul")
430 (eq_attr "dot" "yes"))
431 (and (eq_attr "type" "load")
432 (eq_attr "sign_extend" "yes"))
433 (and (eq_attr "type" "shift")
434 (eq_attr "var_shift" "yes")))
435 (const_string "always")
436 (const_string "not")))
437
438 (automata_option "ndfa")
439
440 (include "rs64.md")
441 (include "mpc.md")
442 (include "40x.md")
443 (include "440.md")
444 (include "476.md")
445 (include "601.md")
446 (include "603.md")
447 (include "6xx.md")
448 (include "7xx.md")
449 (include "7450.md")
450 (include "8540.md")
451 (include "e300c2c3.md")
452 (include "e500mc.md")
453 (include "e500mc64.md")
454 (include "e5500.md")
455 (include "e6500.md")
456 (include "power4.md")
457 (include "power5.md")
458 (include "power6.md")
459 (include "power7.md")
460 (include "power8.md")
461 (include "power9.md")
462 (include "power10.md")
463 (include "cell.md")
464 (include "a2.md")
465 (include "titan.md")
466
467 (include "predicates.md")
468 (include "constraints.md")
469
470
471 ;; Mode iterators
472
473 ; This mode iterator allows :GPR to be used to indicate the allowable size
474 ; of whole values in GPRs.
475 (define_mode_iterator GPR [SI (DI "TARGET_POWERPC64")])
476
477 ; And again, for patterns that need two (potentially) different integer modes.
478 (define_mode_iterator GPR2 [SI (DI "TARGET_POWERPC64")])
479
480 ; Any supported integer mode.
481 (define_mode_iterator INT [QI HI SI DI TI PTI])
482
483 ; Any supported integer mode that fits in one register.
484 (define_mode_iterator INT1 [QI HI SI (DI "TARGET_POWERPC64")])
485
486 ; Integer modes supported in VSX registers with ISA 3.0 instructions
487 (define_mode_iterator INT_ISA3 [QI HI SI DI])
488
489 ; Everything we can extend QImode to.
490 (define_mode_iterator EXTQI [SI (DI "TARGET_POWERPC64")])
491
492 ; Everything we can extend HImode to.
493 (define_mode_iterator EXTHI [SI (DI "TARGET_POWERPC64")])
494
495 ; Everything we can extend SImode to.
496 (define_mode_iterator EXTSI [(DI "TARGET_POWERPC64")])
497
498 ; QImode or HImode for small integer moves and small atomic ops
499 (define_mode_iterator QHI [QI HI])
500
501 ; QImode, HImode, SImode for fused ops only for GPR loads
502 (define_mode_iterator QHSI [QI HI SI])
503
504 ; HImode or SImode for sign extended fusion ops
505 (define_mode_iterator HSI [HI SI])
506
507 ; SImode or DImode, even if DImode doesn't fit in GPRs.
508 (define_mode_iterator SDI [SI DI])
509
510 ; The size of a pointer. Also, the size of the value that a record-condition
511 ; (one with a '.') will compare; and the size used for arithmetic carries.
512 (define_mode_iterator P [(SI "TARGET_32BIT") (DI "TARGET_64BIT")])
513 (define_mode_iterator WORD [(SI "!TARGET_POWERPC64") (DI "TARGET_POWERPC64")])
514
515 ; Iterator to add PTImode along with TImode (TImode can go in VSX registers,
516 ; PTImode is GPR only)
517 (define_mode_iterator TI2 [TI PTI])
518
519 ; Any hardware-supported floating-point mode
520 (define_mode_iterator FP [
521 (SF "TARGET_HARD_FLOAT")
522 (DF "TARGET_HARD_FLOAT")
523 (TF "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128")
524 (IF "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128")
525 (KF "TARGET_FLOAT128_TYPE")
526 (DD "TARGET_DFP")
527 (TD "TARGET_DFP")])
528
529 ; Any fma capable floating-point mode.
530 (define_mode_iterator FMA_F [
531 (SF "TARGET_HARD_FLOAT")
532 (DF "TARGET_HARD_FLOAT || VECTOR_UNIT_VSX_P (DFmode)")
533 (V4SF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V4SFmode)")
534 (V2DF "VECTOR_UNIT_ALTIVEC_OR_VSX_P (V2DFmode)")
535 (KF "TARGET_FLOAT128_HW && FLOAT128_IEEE_P (KFmode)")
536 (TF "TARGET_FLOAT128_HW && FLOAT128_IEEE_P (TFmode)")
537 ])
538
539 ; Floating point move iterators to combine binary and decimal moves
540 (define_mode_iterator FMOVE32 [SF SD])
541 (define_mode_iterator FMOVE64 [DF DD])
542 (define_mode_iterator FMOVE64X [DI DF DD])
543 (define_mode_iterator FMOVE128 [(TF "TARGET_LONG_DOUBLE_128")
544 (IF "FLOAT128_IBM_P (IFmode)")
545 (TD "TARGET_HARD_FLOAT")])
546
547 (define_mode_iterator FMOVE128_FPR [(TF "FLOAT128_2REG_P (TFmode)")
548 (IF "FLOAT128_2REG_P (IFmode)")
549 (TD "TARGET_HARD_FLOAT")])
550
551 ; Iterators for 128 bit types for direct move
552 (define_mode_iterator FMOVE128_GPR [TI
553 V16QI
554 V8HI
555 V4SI
556 V4SF
557 V2DI
558 V2DF
559 V1TI
560 (KF "FLOAT128_VECTOR_P (KFmode)")
561 (TF "FLOAT128_VECTOR_P (TFmode)")])
562
563 ; Iterator for 128-bit VSX types for pack/unpack
564 (define_mode_iterator FMOVE128_VSX [V1TI KF])
565
566 ; Iterators for converting to/from TFmode
567 (define_mode_iterator IFKF [IF KF])
568
569 ; Constraints for moving IF/KFmode.
570 (define_mode_attr IFKF_reg [(IF "d") (KF "wa")])
571
572 ; Whether a floating point move is ok, don't allow SD without hardware FP
573 (define_mode_attr fmove_ok [(SF "")
574 (DF "")
575 (SD "TARGET_HARD_FLOAT")
576 (DD "")])
577
578 ; Convert REAL_VALUE to the appropriate bits
579 (define_mode_attr real_value_to_target [(SF "REAL_VALUE_TO_TARGET_SINGLE")
580 (DF "REAL_VALUE_TO_TARGET_DOUBLE")
581 (SD "REAL_VALUE_TO_TARGET_DECIMAL32")
582 (DD "REAL_VALUE_TO_TARGET_DECIMAL64")])
583
584 ; Whether 0.0 has an all-zero bit pattern
585 (define_mode_attr zero_fp [(SF "j")
586 (DF "j")
587 (TF "j")
588 (IF "j")
589 (KF "j")
590 (SD "wn")
591 (DD "wn")
592 (TD "wn")])
593
594 ; Definitions for 64-bit VSX
595 (define_mode_attr f64_vsx [(DF "wa") (DD "wn")])
596
597 ; Definitions for 64-bit direct move
598 (define_mode_attr f64_dm [(DF "wa") (DD "d")])
599
600 ; Definitions for 64-bit use of altivec registers
601 (define_mode_attr f64_av [(DF "v") (DD "wn")])
602
603 ; Definitions for 64-bit access to ISA 3.0 (power9) vector
604 (define_mode_attr f64_p9 [(DF "v") (DD "wn")])
605
606 ; These modes do not fit in integer registers in 32-bit mode.
607 (define_mode_iterator DIFD [DI DF DD])
608
609 ; Iterator for reciprocal estimate instructions
610 (define_mode_iterator RECIPF [SF DF V4SF V2DF])
611
612 ; SFmode or DFmode.
613 (define_mode_iterator SFDF [SF DF])
614
615 ; And again, for when we need two FP modes in a pattern.
616 (define_mode_iterator SFDF2 [SF DF])
617
618 ; A generic s/d attribute, for sp/dp for example.
619 (define_mode_attr sd [(SF "s") (DF "d")
620 (V4SF "s") (V2DF "d")])
621
622 ; A generic s/d/q attribute, for sp/dp/qp for example.
623 (define_mode_attr sdq [(SF "s") (DF "d")
624 (TF "q") (KF "q")])
625
626 ; "s" or nothing, for fmuls/fmul for example.
627 (define_mode_attr s [(SF "s") (DF "")])
628
629 ; Iterator for 128-bit floating point that uses the IBM double-double format
630 (define_mode_iterator IBM128 [(IF "FLOAT128_IBM_P (IFmode)")
631 (TF "FLOAT128_IBM_P (TFmode)")])
632
633 ; Iterator for 128-bit floating point that uses IEEE 128-bit float
634 (define_mode_iterator IEEE128 [(KF "FLOAT128_IEEE_P (KFmode)")
635 (TF "FLOAT128_IEEE_P (TFmode)")])
636
637 ; Iterator for IEEE floating point
638 (define_mode_iterator IEEE_FP [SFDF IEEE128])
639
640 ; "vsx/altivec_register_operand", for IEEE_FP predicates
641 (define_mode_attr fp_register_op [(SF "vsx_register_operand")
642 (DF "vsx_register_operand")
643 (TF "altivec_register_operand")
644 (KF "altivec_register_operand")])
645
646 ; "wa" or "v", for IEEE_FP constraints
647 (define_mode_attr wa_v [(SF "wa") (DF "wa")
648 (TF "v") (KF "v")])
649
650 ; "x" or nothing, for IEEE_FP
651 (define_mode_attr x [(SF "x") (DF "x")
652 (TF "") (KF "")])
653
654 ; Iterator for 128-bit floating point
655 (define_mode_iterator FLOAT128 [(KF "TARGET_FLOAT128_TYPE")
656 (IF "TARGET_FLOAT128_TYPE")
657 (TF "TARGET_LONG_DOUBLE_128")])
658
659 ; Iterator for signbit on 64-bit machines with direct move
660 (define_mode_iterator SIGNBIT [(KF "FLOAT128_VECTOR_P (KFmode)")
661 (TF "FLOAT128_VECTOR_P (TFmode)")])
662
663 ; Which isa is needed for those float instructions?
664 (define_mode_attr Fisa [(SF "p8v") (DF "*") (DI "*")])
665
666 ; FRE/FRES support
667 (define_mode_attr FFRE [(SF "FRES") (DF "FRE")])
668
669 ; Conditional returns.
670 (define_code_iterator any_return [return simple_return])
671 (define_code_attr return_pred [(return "direct_return ()")
672 (simple_return "1")])
673 (define_code_attr return_str [(return "") (simple_return "simple_")])
674
675 ; Logical operators.
676 (define_code_iterator iorxor [ior xor])
677 (define_code_iterator and_ior_xor [and ior xor])
678
679 ; Signed/unsigned variants of ops.
680 (define_code_iterator any_extend [sign_extend zero_extend])
681 (define_code_iterator any_fix [fix unsigned_fix])
682 (define_code_iterator any_float [float unsigned_float])
683
684 ; Shift right.
685 (define_code_iterator any_shiftrt [ashiftrt lshiftrt])
686
687 (define_code_attr u [(sign_extend "")
688 (zero_extend "u")
689 (fix "")
690 (unsigned_fix "u")])
691
692 (define_code_attr su [(sign_extend "s")
693 (zero_extend "u")
694 (fix "s")
695 (unsigned_fix "u")
696 (float "s")
697 (unsigned_float "u")])
698
699 (define_code_attr az [(sign_extend "a")
700 (zero_extend "z")
701 (fix "a")
702 (unsigned_fix "z")
703 (float "a")
704 (unsigned_float "z")])
705
706 (define_code_attr uns [(fix "")
707 (unsigned_fix "uns")
708 (float "")
709 (unsigned_float "uns")])
710
711 ; Various instructions that come in SI and DI forms.
712 ; A generic w/d attribute, for things like cmpw/cmpd.
713 (define_mode_attr wd [(QI "b")
714 (HI "h")
715 (SI "w")
716 (DI "d")
717 (V16QI "b")
718 (V8HI "h")
719 (V4SI "w")
720 (V2DI "d")
721 (V1TI "q")
722 (TI "q")])
723
724 ; For double extract from different origin types
725 (define_mode_attr du_or_d [(QI "du")
726 (HI "du")
727 (SI "du")
728 (DI "d")
729 (V16QI "du")
730 (V8HI "du")
731 (V4SI "du")
732 (V2DI "d")])
733
734 ;; How many bits (per element) in this mode?
735 (define_mode_attr bits [(QI "8") (HI "16") (SI "32") (DI "64")
736 (SF "32") (DF "64")
737 (DD "64") (TD "128")
738 (V4SI "32") (V2DI "64")])
739
740 ; DImode bits
741 (define_mode_attr dbits [(QI "56") (HI "48") (SI "32")])
742
743 ;; Bitmask for shift instructions
744 (define_mode_attr hH [(SI "h") (DI "H")])
745
746 ;; A mode twice the size of the given mode
747 (define_mode_attr dmode [(SI "di") (DI "ti")])
748 (define_mode_attr DMODE [(SI "DI") (DI "TI")])
749
750 ;; Suffix for reload patterns
751 (define_mode_attr ptrsize [(SI "32bit")
752 (DI "64bit")])
753
754 (define_mode_attr tptrsize [(SI "TARGET_32BIT")
755 (DI "TARGET_64BIT")])
756
757 (define_mode_attr mptrsize [(SI "si")
758 (DI "di")])
759
760 (define_mode_attr ptrload [(SI "lwz")
761 (DI "ld")])
762
763 (define_mode_attr ptrm [(SI "m")
764 (DI "Y")])
765
766 (define_mode_attr rreg [(SF "f")
767 (DF "wa")])
768
769 (define_mode_attr rreg2 [(SF "f")
770 (DF "d")])
771
772 (define_mode_attr SI_CONVERT_FP [(SF "TARGET_FCFIDS")
773 (DF "TARGET_FCFID")])
774
775 ;; Mode iterator for logical operations on 128-bit types
776 (define_mode_iterator BOOL_128 [TI
777 PTI
778 (V16QI "TARGET_ALTIVEC")
779 (V8HI "TARGET_ALTIVEC")
780 (V4SI "TARGET_ALTIVEC")
781 (V4SF "TARGET_ALTIVEC")
782 (V2DI "TARGET_ALTIVEC")
783 (V2DF "TARGET_ALTIVEC")
784 (V1TI "TARGET_ALTIVEC")])
785
786 ;; For the GPRs we use 3 constraints for register outputs, two that are the
787 ;; same as the output register, and a third where the output register is an
788 ;; early clobber, so we don't have to deal with register overlaps. For the
789 ;; vector types, we prefer to use the vector registers. For TI mode, allow
790 ;; either.
791
792 ;; Mode attribute for boolean operation register constraints for output
793 (define_mode_attr BOOL_REGS_OUTPUT [(TI "&r,r,r,wa,v")
794 (PTI "&r,r,r")
795 (V16QI "wa,v,&?r,?r,?r")
796 (V8HI "wa,v,&?r,?r,?r")
797 (V4SI "wa,v,&?r,?r,?r")
798 (V4SF "wa,v,&?r,?r,?r")
799 (V2DI "wa,v,&?r,?r,?r")
800 (V2DF "wa,v,&?r,?r,?r")
801 (V1TI "wa,v,&?r,?r,?r")])
802
803 ;; Mode attribute for boolean operation register constraints for operand1
804 (define_mode_attr BOOL_REGS_OP1 [(TI "r,0,r,wa,v")
805 (PTI "r,0,r")
806 (V16QI "wa,v,r,0,r")
807 (V8HI "wa,v,r,0,r")
808 (V4SI "wa,v,r,0,r")
809 (V4SF "wa,v,r,0,r")
810 (V2DI "wa,v,r,0,r")
811 (V2DF "wa,v,r,0,r")
812 (V1TI "wa,v,r,0,r")])
813
814 ;; Mode attribute for boolean operation register constraints for operand2
815 (define_mode_attr BOOL_REGS_OP2 [(TI "r,r,0,wa,v")
816 (PTI "r,r,0")
817 (V16QI "wa,v,r,r,0")
818 (V8HI "wa,v,r,r,0")
819 (V4SI "wa,v,r,r,0")
820 (V4SF "wa,v,r,r,0")
821 (V2DI "wa,v,r,r,0")
822 (V2DF "wa,v,r,r,0")
823 (V1TI "wa,v,r,r,0")])
824
825 ;; Mode attribute for boolean operation register constraints for operand1
826 ;; for one_cmpl. To simplify things, we repeat the constraint where 0
827 ;; is used for operand1 or operand2
828 (define_mode_attr BOOL_REGS_UNARY [(TI "r,0,0,wa,v")
829 (PTI "r,0,0")
830 (V16QI "wa,v,r,0,0")
831 (V8HI "wa,v,r,0,0")
832 (V4SI "wa,v,r,0,0")
833 (V4SF "wa,v,r,0,0")
834 (V2DI "wa,v,r,0,0")
835 (V2DF "wa,v,r,0,0")
836 (V1TI "wa,v,r,0,0")])
837
838 ;; Reload iterator for creating the function to allocate a base register to
839 ;; supplement addressing modes.
840 (define_mode_iterator RELOAD [V16QI V8HI V4SI V2DI V4SF V2DF V1TI
841 SF SD SI DF DD DI TI PTI KF IF TF
842 OO XO])
843
844 ;; Iterate over smin, smax
845 (define_code_iterator fp_minmax [smin smax])
846
847 (define_code_attr minmax [(smin "min")
848 (smax "max")])
849
850 (define_code_attr SMINMAX [(smin "SMIN")
851 (smax "SMAX")])
852
853 ;; Iterator to optimize the following cases:
854 ;; D-form load to FPR register & move to Altivec register
855 ;; Move Altivec register to FPR register and store
856 (define_mode_iterator ALTIVEC_DFORM [DF
857 (SF "TARGET_P8_VECTOR")
858 (DI "TARGET_POWERPC64")])
859
860 (include "darwin.md")
861
862 ;; Start with fixed-point load and store insns. Here we put only the more
863 ;; complex forms. Basic data transfer is done later.
864
865 (define_insn "zero_extendqi<mode>2"
866 [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,r,wa,^v")
867 (zero_extend:EXTQI (match_operand:QI 1 "reg_or_mem_operand" "m,r,?Z,v")))]
868 ""
869 "@
870 lbz%U1%X1 %0,%1
871 rlwinm %0,%1,0,0xff
872 lxsibzx %x0,%y1
873 vextractub %0,%1,7"
874 [(set_attr "type" "load,shift,fpload,vecperm")
875 (set_attr "isa" "*,*,p9v,p9v")])
876
877 (define_insn_and_split "*zero_extendqi<mode>2_dot"
878 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
879 (compare:CC (zero_extend:EXTQI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
880 (const_int 0)))
881 (clobber (match_scratch:EXTQI 0 "=r,r"))]
882 ""
883 "@
884 andi. %0,%1,0xff
885 #"
886 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
887 [(set (match_dup 0)
888 (zero_extend:EXTQI (match_dup 1)))
889 (set (match_dup 2)
890 (compare:CC (match_dup 0)
891 (const_int 0)))]
892 ""
893 [(set_attr "type" "logical")
894 (set_attr "dot" "yes")
895 (set_attr "length" "4,8")])
896
897 (define_insn_and_split "*zero_extendqi<mode>2_dot2"
898 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
899 (compare:CC (zero_extend:EXTQI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
900 (const_int 0)))
901 (set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,r")
902 (zero_extend:EXTQI (match_dup 1)))]
903 ""
904 "@
905 andi. %0,%1,0xff
906 #"
907 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
908 [(set (match_dup 0)
909 (zero_extend:EXTQI (match_dup 1)))
910 (set (match_dup 2)
911 (compare:CC (match_dup 0)
912 (const_int 0)))]
913 ""
914 [(set_attr "type" "logical")
915 (set_attr "dot" "yes")
916 (set_attr "length" "4,8")])
917
918
919 (define_insn "zero_extendhi<mode>2"
920 [(set (match_operand:EXTHI 0 "gpc_reg_operand" "=r,r,wa,^v")
921 (zero_extend:EXTHI (match_operand:HI 1 "reg_or_mem_operand" "m,r,?Z,v")))]
922 ""
923 "@
924 lhz%U1%X1 %0,%1
925 rlwinm %0,%1,0,0xffff
926 lxsihzx %x0,%y1
927 vextractuh %0,%1,6"
928 [(set_attr "type" "load,shift,fpload,vecperm")
929 (set_attr "isa" "*,*,p9v,p9v")])
930
931 (define_insn_and_split "*zero_extendhi<mode>2_dot"
932 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
933 (compare:CC (zero_extend:EXTHI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
934 (const_int 0)))
935 (clobber (match_scratch:EXTHI 0 "=r,r"))]
936 ""
937 "@
938 andi. %0,%1,0xffff
939 #"
940 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
941 [(set (match_dup 0)
942 (zero_extend:EXTHI (match_dup 1)))
943 (set (match_dup 2)
944 (compare:CC (match_dup 0)
945 (const_int 0)))]
946 ""
947 [(set_attr "type" "logical")
948 (set_attr "dot" "yes")
949 (set_attr "length" "4,8")])
950
951 (define_insn_and_split "*zero_extendhi<mode>2_dot2"
952 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
953 (compare:CC (zero_extend:EXTHI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
954 (const_int 0)))
955 (set (match_operand:EXTHI 0 "gpc_reg_operand" "=r,r")
956 (zero_extend:EXTHI (match_dup 1)))]
957 ""
958 "@
959 andi. %0,%1,0xffff
960 #"
961 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
962 [(set (match_dup 0)
963 (zero_extend:EXTHI (match_dup 1)))
964 (set (match_dup 2)
965 (compare:CC (match_dup 0)
966 (const_int 0)))]
967 ""
968 [(set_attr "type" "logical")
969 (set_attr "dot" "yes")
970 (set_attr "length" "4,8")])
971
972
973 (define_insn "zero_extendsi<mode>2"
974 [(set (match_operand:EXTSI 0 "gpc_reg_operand" "=r,r,d,wa,wa,r,wa")
975 (zero_extend:EXTSI (match_operand:SI 1 "reg_or_mem_operand" "m,r,?Z,?Z,r,wa,wa")))]
976 ""
977 "@
978 lwz%U1%X1 %0,%1
979 rldicl %0,%1,0,32
980 lfiwzx %0,%y1
981 lxsiwzx %x0,%y1
982 mtvsrwz %x0,%1
983 mfvsrwz %0,%x1
984 xxextractuw %x0,%x1,4"
985 [(set_attr "type" "load,shift,fpload,fpload,mtvsr,mfvsr,vecexts")
986 (set_attr "isa" "*,*,p7,p8v,p8v,p8v,p9v")])
987
988 (define_insn_and_split "*zero_extendsi<mode>2_dot"
989 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
990 (compare:CC (zero_extend:EXTSI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
991 (const_int 0)))
992 (clobber (match_scratch:EXTSI 0 "=r,r"))]
993 ""
994 "@
995 rldicl. %0,%1,0,32
996 #"
997 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
998 [(set (match_dup 0)
999 (zero_extend:DI (match_dup 1)))
1000 (set (match_dup 2)
1001 (compare:CC (match_dup 0)
1002 (const_int 0)))]
1003 ""
1004 [(set_attr "type" "shift")
1005 (set_attr "dot" "yes")
1006 (set_attr "length" "4,8")])
1007
1008 (define_insn_and_split "*zero_extendsi<mode>2_dot2"
1009 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1010 (compare:CC (zero_extend:EXTSI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1011 (const_int 0)))
1012 (set (match_operand:EXTSI 0 "gpc_reg_operand" "=r,r")
1013 (zero_extend:EXTSI (match_dup 1)))]
1014 ""
1015 "@
1016 rldicl. %0,%1,0,32
1017 #"
1018 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1019 [(set (match_dup 0)
1020 (zero_extend:EXTSI (match_dup 1)))
1021 (set (match_dup 2)
1022 (compare:CC (match_dup 0)
1023 (const_int 0)))]
1024 ""
1025 [(set_attr "type" "shift")
1026 (set_attr "dot" "yes")
1027 (set_attr "length" "4,8")])
1028
1029
1030 (define_insn "extendqi<mode>2"
1031 [(set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,?*v")
1032 (sign_extend:EXTQI (match_operand:QI 1 "gpc_reg_operand" "r,?*v")))]
1033 ""
1034 "@
1035 extsb %0,%1
1036 vextsb2d %0,%1"
1037 [(set_attr "type" "exts,vecperm")
1038 (set_attr "isa" "*,p9v")])
1039
1040 (define_insn_and_split "*extendqi<mode>2_dot"
1041 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1042 (compare:CC (sign_extend:EXTQI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1043 (const_int 0)))
1044 (clobber (match_scratch:EXTQI 0 "=r,r"))]
1045 ""
1046 "@
1047 extsb. %0,%1
1048 #"
1049 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1050 [(set (match_dup 0)
1051 (sign_extend:EXTQI (match_dup 1)))
1052 (set (match_dup 2)
1053 (compare:CC (match_dup 0)
1054 (const_int 0)))]
1055 ""
1056 [(set_attr "type" "exts")
1057 (set_attr "dot" "yes")
1058 (set_attr "length" "4,8")])
1059
1060 (define_insn_and_split "*extendqi<mode>2_dot2"
1061 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1062 (compare:CC (sign_extend:EXTQI (match_operand:QI 1 "gpc_reg_operand" "r,r"))
1063 (const_int 0)))
1064 (set (match_operand:EXTQI 0 "gpc_reg_operand" "=r,r")
1065 (sign_extend:EXTQI (match_dup 1)))]
1066 ""
1067 "@
1068 extsb. %0,%1
1069 #"
1070 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1071 [(set (match_dup 0)
1072 (sign_extend:EXTQI (match_dup 1)))
1073 (set (match_dup 2)
1074 (compare:CC (match_dup 0)
1075 (const_int 0)))]
1076 ""
1077 [(set_attr "type" "exts")
1078 (set_attr "dot" "yes")
1079 (set_attr "length" "4,8")])
1080
1081
1082 (define_expand "extendhi<mode>2"
1083 [(set (match_operand:EXTHI 0 "gpc_reg_operand")
1084 (sign_extend:EXTHI (match_operand:HI 1 "gpc_reg_operand")))]
1085 ""
1086 "")
1087
1088 (define_insn "*extendhi<mode>2"
1089 [(set (match_operand:EXTHI 0 "gpc_reg_operand" "=r,r,?*v,?*v")
1090 (sign_extend:EXTHI (match_operand:HI 1 "reg_or_mem_operand" "m,r,Z,v")))]
1091 ""
1092 "@
1093 lha%U1%X1 %0,%1
1094 extsh %0,%1
1095 #
1096 vextsh2d %0,%1"
1097 [(set_attr "type" "load,exts,fpload,vecperm")
1098 (set_attr "sign_extend" "yes")
1099 (set_attr "length" "*,*,8,*")
1100 (set_attr "isa" "*,*,p9v,p9v")])
1101
1102 (define_split
1103 [(set (match_operand:EXTHI 0 "altivec_register_operand")
1104 (sign_extend:EXTHI
1105 (match_operand:HI 1 "indexed_or_indirect_operand")))]
1106 "TARGET_P9_VECTOR && reload_completed"
1107 [(set (match_dup 2)
1108 (match_dup 1))
1109 (set (match_dup 0)
1110 (sign_extend:EXTHI (match_dup 2)))]
1111 {
1112 operands[2] = gen_rtx_REG (HImode, REGNO (operands[0]));
1113 })
1114
1115 (define_insn_and_split "*extendhi<mode>2_dot"
1116 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1117 (compare:CC (sign_extend:EXTHI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1118 (const_int 0)))
1119 (clobber (match_scratch:EXTHI 0 "=r,r"))]
1120 ""
1121 "@
1122 extsh. %0,%1
1123 #"
1124 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1125 [(set (match_dup 0)
1126 (sign_extend:EXTHI (match_dup 1)))
1127 (set (match_dup 2)
1128 (compare:CC (match_dup 0)
1129 (const_int 0)))]
1130 ""
1131 [(set_attr "type" "exts")
1132 (set_attr "dot" "yes")
1133 (set_attr "length" "4,8")])
1134
1135 (define_insn_and_split "*extendhi<mode>2_dot2"
1136 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1137 (compare:CC (sign_extend:EXTHI (match_operand:HI 1 "gpc_reg_operand" "r,r"))
1138 (const_int 0)))
1139 (set (match_operand:EXTHI 0 "gpc_reg_operand" "=r,r")
1140 (sign_extend:EXTHI (match_dup 1)))]
1141 ""
1142 "@
1143 extsh. %0,%1
1144 #"
1145 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1146 [(set (match_dup 0)
1147 (sign_extend:EXTHI (match_dup 1)))
1148 (set (match_dup 2)
1149 (compare:CC (match_dup 0)
1150 (const_int 0)))]
1151 ""
1152 [(set_attr "type" "exts")
1153 (set_attr "dot" "yes")
1154 (set_attr "length" "4,8")])
1155
1156
1157 (define_insn "extendsi<mode>2"
1158 [(set (match_operand:EXTSI 0 "gpc_reg_operand"
1159 "=r, r, d, wa, wa, v, v, wr")
1160 (sign_extend:EXTSI (match_operand:SI 1 "lwa_operand"
1161 "YZ, r, Z, Z, r, v, v, ?wa")))]
1162 ""
1163 "@
1164 lwa%U1%X1 %0,%1
1165 extsw %0,%1
1166 lfiwax %0,%y1
1167 lxsiwax %x0,%y1
1168 mtvsrwa %x0,%1
1169 vextsw2d %0,%1
1170 #
1171 #"
1172 [(set_attr "type" "load,exts,fpload,fpload,mtvsr,vecexts,vecperm,mfvsr")
1173 (set_attr "sign_extend" "yes")
1174 (set_attr "length" "*,*,*,*,*,*,8,8")
1175 (set_attr "isa" "*,*,p6,p8v,p8v,p9v,p8v,p8v")])
1176
1177 (define_split
1178 [(set (match_operand:EXTSI 0 "int_reg_operand")
1179 (sign_extend:EXTSI (match_operand:SI 1 "vsx_register_operand")))]
1180 "TARGET_DIRECT_MOVE_64BIT && reload_completed"
1181 [(set (match_dup 2)
1182 (match_dup 1))
1183 (set (match_dup 0)
1184 (sign_extend:DI (match_dup 2)))]
1185 {
1186 operands[2] = gen_rtx_REG (SImode, reg_or_subregno (operands[0]));
1187 })
1188
1189 (define_split
1190 [(set (match_operand:DI 0 "altivec_register_operand")
1191 (sign_extend:DI (match_operand:SI 1 "altivec_register_operand")))]
1192 "TARGET_P8_VECTOR && !TARGET_P9_VECTOR && reload_completed"
1193 [(const_int 0)]
1194 {
1195 rtx dest = operands[0];
1196 rtx src = operands[1];
1197 int dest_regno = REGNO (dest);
1198 int src_regno = REGNO (src);
1199 rtx dest_v2di = gen_rtx_REG (V2DImode, dest_regno);
1200 rtx src_v4si = gen_rtx_REG (V4SImode, src_regno);
1201
1202 if (BYTES_BIG_ENDIAN)
1203 {
1204 emit_insn (gen_altivec_vupkhsw (dest_v2di, src_v4si));
1205 emit_insn (gen_vsx_xxspltd_v2di (dest_v2di, dest_v2di, const1_rtx));
1206 }
1207 else
1208 {
1209 emit_insn (gen_altivec_vupklsw (dest_v2di, src_v4si));
1210 emit_insn (gen_vsx_xxspltd_v2di (dest_v2di, dest_v2di, const0_rtx));
1211 }
1212 DONE;
1213 })
1214
1215 (define_insn_and_split "*extendsi<mode>2_dot"
1216 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1217 (compare:CC (sign_extend:EXTSI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1218 (const_int 0)))
1219 (clobber (match_scratch:EXTSI 0 "=r,r"))]
1220 ""
1221 "@
1222 extsw. %0,%1
1223 #"
1224 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1225 [(set (match_dup 0)
1226 (sign_extend:EXTSI (match_dup 1)))
1227 (set (match_dup 2)
1228 (compare:CC (match_dup 0)
1229 (const_int 0)))]
1230 ""
1231 [(set_attr "type" "exts")
1232 (set_attr "dot" "yes")
1233 (set_attr "length" "4,8")])
1234
1235 (define_insn_and_split "*extendsi<mode>2_dot2"
1236 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
1237 (compare:CC (sign_extend:EXTSI (match_operand:SI 1 "gpc_reg_operand" "r,r"))
1238 (const_int 0)))
1239 (set (match_operand:EXTSI 0 "gpc_reg_operand" "=r,r")
1240 (sign_extend:EXTSI (match_dup 1)))]
1241 ""
1242 "@
1243 extsw. %0,%1
1244 #"
1245 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
1246 [(set (match_dup 0)
1247 (sign_extend:EXTSI (match_dup 1)))
1248 (set (match_dup 2)
1249 (compare:CC (match_dup 0)
1250 (const_int 0)))]
1251 ""
1252 [(set_attr "type" "exts")
1253 (set_attr "dot" "yes")
1254 (set_attr "length" "4,8")])
1255
1256 ;; IBM 405, 440, 464 and 476 half-word multiplication operations.
1257
1258 (define_insn "*macchwc"
1259 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1260 (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1261 (match_operand:SI 2 "gpc_reg_operand" "r")
1262 (const_int 16))
1263 (sign_extend:SI
1264 (match_operand:HI 1 "gpc_reg_operand" "r")))
1265 (match_operand:SI 4 "gpc_reg_operand" "0"))
1266 (const_int 0)))
1267 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1268 (plus:SI (mult:SI (ashiftrt:SI
1269 (match_dup 2)
1270 (const_int 16))
1271 (sign_extend:SI
1272 (match_dup 1)))
1273 (match_dup 4)))]
1274 "TARGET_MULHW"
1275 "macchw. %0,%1,%2"
1276 [(set_attr "type" "halfmul")])
1277
1278 (define_insn "*macchw"
1279 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1280 (plus:SI (mult:SI (ashiftrt:SI
1281 (match_operand:SI 2 "gpc_reg_operand" "r")
1282 (const_int 16))
1283 (sign_extend:SI
1284 (match_operand:HI 1 "gpc_reg_operand" "r")))
1285 (match_operand:SI 3 "gpc_reg_operand" "0")))]
1286 "TARGET_MULHW"
1287 "macchw %0,%1,%2"
1288 [(set_attr "type" "halfmul")])
1289
1290 (define_insn "*macchwuc"
1291 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1292 (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1293 (match_operand:SI 2 "gpc_reg_operand" "r")
1294 (const_int 16))
1295 (zero_extend:SI
1296 (match_operand:HI 1 "gpc_reg_operand" "r")))
1297 (match_operand:SI 4 "gpc_reg_operand" "0"))
1298 (const_int 0)))
1299 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1300 (plus:SI (mult:SI (lshiftrt:SI
1301 (match_dup 2)
1302 (const_int 16))
1303 (zero_extend:SI
1304 (match_dup 1)))
1305 (match_dup 4)))]
1306 "TARGET_MULHW"
1307 "macchwu. %0,%1,%2"
1308 [(set_attr "type" "halfmul")])
1309
1310 (define_insn "*macchwu"
1311 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1312 (plus:SI (mult:SI (lshiftrt:SI
1313 (match_operand:SI 2 "gpc_reg_operand" "r")
1314 (const_int 16))
1315 (zero_extend:SI
1316 (match_operand:HI 1 "gpc_reg_operand" "r")))
1317 (match_operand:SI 3 "gpc_reg_operand" "0")))]
1318 "TARGET_MULHW"
1319 "macchwu %0,%1,%2"
1320 [(set_attr "type" "halfmul")])
1321
1322 (define_insn "*machhwc"
1323 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1324 (compare:CC (plus:SI (mult:SI (ashiftrt:SI
1325 (match_operand:SI 1 "gpc_reg_operand" "%r")
1326 (const_int 16))
1327 (ashiftrt:SI
1328 (match_operand:SI 2 "gpc_reg_operand" "r")
1329 (const_int 16)))
1330 (match_operand:SI 4 "gpc_reg_operand" "0"))
1331 (const_int 0)))
1332 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1333 (plus:SI (mult:SI (ashiftrt:SI
1334 (match_dup 1)
1335 (const_int 16))
1336 (ashiftrt:SI
1337 (match_dup 2)
1338 (const_int 16)))
1339 (match_dup 4)))]
1340 "TARGET_MULHW"
1341 "machhw. %0,%1,%2"
1342 [(set_attr "type" "halfmul")])
1343
1344 (define_insn "*machhw"
1345 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1346 (plus:SI (mult:SI (ashiftrt:SI
1347 (match_operand:SI 1 "gpc_reg_operand" "%r")
1348 (const_int 16))
1349 (ashiftrt:SI
1350 (match_operand:SI 2 "gpc_reg_operand" "r")
1351 (const_int 16)))
1352 (match_operand:SI 3 "gpc_reg_operand" "0")))]
1353 "TARGET_MULHW"
1354 "machhw %0,%1,%2"
1355 [(set_attr "type" "halfmul")])
1356
1357 (define_insn "*machhwuc"
1358 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1359 (compare:CC (plus:SI (mult:SI (lshiftrt:SI
1360 (match_operand:SI 1 "gpc_reg_operand" "%r")
1361 (const_int 16))
1362 (lshiftrt:SI
1363 (match_operand:SI 2 "gpc_reg_operand" "r")
1364 (const_int 16)))
1365 (match_operand:SI 4 "gpc_reg_operand" "0"))
1366 (const_int 0)))
1367 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1368 (plus:SI (mult:SI (lshiftrt:SI
1369 (match_dup 1)
1370 (const_int 16))
1371 (lshiftrt:SI
1372 (match_dup 2)
1373 (const_int 16)))
1374 (match_dup 4)))]
1375 "TARGET_MULHW"
1376 "machhwu. %0,%1,%2"
1377 [(set_attr "type" "halfmul")])
1378
1379 (define_insn "*machhwu"
1380 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1381 (plus:SI (mult:SI (lshiftrt:SI
1382 (match_operand:SI 1 "gpc_reg_operand" "%r")
1383 (const_int 16))
1384 (lshiftrt:SI
1385 (match_operand:SI 2 "gpc_reg_operand" "r")
1386 (const_int 16)))
1387 (match_operand:SI 3 "gpc_reg_operand" "0")))]
1388 "TARGET_MULHW"
1389 "machhwu %0,%1,%2"
1390 [(set_attr "type" "halfmul")])
1391
1392 (define_insn "*maclhwc"
1393 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1394 (compare:CC (plus:SI (mult:SI (sign_extend:SI
1395 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1396 (sign_extend:SI
1397 (match_operand:HI 2 "gpc_reg_operand" "r")))
1398 (match_operand:SI 4 "gpc_reg_operand" "0"))
1399 (const_int 0)))
1400 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1401 (plus:SI (mult:SI (sign_extend:SI
1402 (match_dup 1))
1403 (sign_extend:SI
1404 (match_dup 2)))
1405 (match_dup 4)))]
1406 "TARGET_MULHW"
1407 "maclhw. %0,%1,%2"
1408 [(set_attr "type" "halfmul")])
1409
1410 (define_insn "*maclhw"
1411 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1412 (plus:SI (mult:SI (sign_extend:SI
1413 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1414 (sign_extend:SI
1415 (match_operand:HI 2 "gpc_reg_operand" "r")))
1416 (match_operand:SI 3 "gpc_reg_operand" "0")))]
1417 "TARGET_MULHW"
1418 "maclhw %0,%1,%2"
1419 [(set_attr "type" "halfmul")])
1420
1421 (define_insn "*maclhwuc"
1422 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1423 (compare:CC (plus:SI (mult:SI (zero_extend:SI
1424 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1425 (zero_extend:SI
1426 (match_operand:HI 2 "gpc_reg_operand" "r")))
1427 (match_operand:SI 4 "gpc_reg_operand" "0"))
1428 (const_int 0)))
1429 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1430 (plus:SI (mult:SI (zero_extend:SI
1431 (match_dup 1))
1432 (zero_extend:SI
1433 (match_dup 2)))
1434 (match_dup 4)))]
1435 "TARGET_MULHW"
1436 "maclhwu. %0,%1,%2"
1437 [(set_attr "type" "halfmul")])
1438
1439 (define_insn "*maclhwu"
1440 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1441 (plus:SI (mult:SI (zero_extend:SI
1442 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1443 (zero_extend:SI
1444 (match_operand:HI 2 "gpc_reg_operand" "r")))
1445 (match_operand:SI 3 "gpc_reg_operand" "0")))]
1446 "TARGET_MULHW"
1447 "maclhwu %0,%1,%2"
1448 [(set_attr "type" "halfmul")])
1449
1450 (define_insn "*nmacchwc"
1451 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1452 (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1453 (mult:SI (ashiftrt:SI
1454 (match_operand:SI 2 "gpc_reg_operand" "r")
1455 (const_int 16))
1456 (sign_extend:SI
1457 (match_operand:HI 1 "gpc_reg_operand" "r"))))
1458 (const_int 0)))
1459 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1460 (minus:SI (match_dup 4)
1461 (mult:SI (ashiftrt:SI
1462 (match_dup 2)
1463 (const_int 16))
1464 (sign_extend:SI
1465 (match_dup 1)))))]
1466 "TARGET_MULHW"
1467 "nmacchw. %0,%1,%2"
1468 [(set_attr "type" "halfmul")])
1469
1470 (define_insn "*nmacchw"
1471 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1472 (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1473 (mult:SI (ashiftrt:SI
1474 (match_operand:SI 2 "gpc_reg_operand" "r")
1475 (const_int 16))
1476 (sign_extend:SI
1477 (match_operand:HI 1 "gpc_reg_operand" "r")))))]
1478 "TARGET_MULHW"
1479 "nmacchw %0,%1,%2"
1480 [(set_attr "type" "halfmul")])
1481
1482 (define_insn "*nmachhwc"
1483 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1484 (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1485 (mult:SI (ashiftrt:SI
1486 (match_operand:SI 1 "gpc_reg_operand" "%r")
1487 (const_int 16))
1488 (ashiftrt:SI
1489 (match_operand:SI 2 "gpc_reg_operand" "r")
1490 (const_int 16))))
1491 (const_int 0)))
1492 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1493 (minus:SI (match_dup 4)
1494 (mult:SI (ashiftrt:SI
1495 (match_dup 1)
1496 (const_int 16))
1497 (ashiftrt:SI
1498 (match_dup 2)
1499 (const_int 16)))))]
1500 "TARGET_MULHW"
1501 "nmachhw. %0,%1,%2"
1502 [(set_attr "type" "halfmul")])
1503
1504 (define_insn "*nmachhw"
1505 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1506 (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1507 (mult:SI (ashiftrt:SI
1508 (match_operand:SI 1 "gpc_reg_operand" "%r")
1509 (const_int 16))
1510 (ashiftrt:SI
1511 (match_operand:SI 2 "gpc_reg_operand" "r")
1512 (const_int 16)))))]
1513 "TARGET_MULHW"
1514 "nmachhw %0,%1,%2"
1515 [(set_attr "type" "halfmul")])
1516
1517 (define_insn "*nmaclhwc"
1518 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1519 (compare:CC (minus:SI (match_operand:SI 4 "gpc_reg_operand" "0")
1520 (mult:SI (sign_extend:SI
1521 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1522 (sign_extend:SI
1523 (match_operand:HI 2 "gpc_reg_operand" "r"))))
1524 (const_int 0)))
1525 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1526 (minus:SI (match_dup 4)
1527 (mult:SI (sign_extend:SI
1528 (match_dup 1))
1529 (sign_extend:SI
1530 (match_dup 2)))))]
1531 "TARGET_MULHW"
1532 "nmaclhw. %0,%1,%2"
1533 [(set_attr "type" "halfmul")])
1534
1535 (define_insn "*nmaclhw"
1536 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1537 (minus:SI (match_operand:SI 3 "gpc_reg_operand" "0")
1538 (mult:SI (sign_extend:SI
1539 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1540 (sign_extend:SI
1541 (match_operand:HI 2 "gpc_reg_operand" "r")))))]
1542 "TARGET_MULHW"
1543 "nmaclhw %0,%1,%2"
1544 [(set_attr "type" "halfmul")])
1545
1546 (define_insn "*mulchwc"
1547 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1548 (compare:CC (mult:SI (ashiftrt:SI
1549 (match_operand:SI 2 "gpc_reg_operand" "r")
1550 (const_int 16))
1551 (sign_extend:SI
1552 (match_operand:HI 1 "gpc_reg_operand" "r")))
1553 (const_int 0)))
1554 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1555 (mult:SI (ashiftrt:SI
1556 (match_dup 2)
1557 (const_int 16))
1558 (sign_extend:SI
1559 (match_dup 1))))]
1560 "TARGET_MULHW"
1561 "mulchw. %0,%1,%2"
1562 [(set_attr "type" "halfmul")])
1563
1564 (define_insn "*mulchw"
1565 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1566 (mult:SI (ashiftrt:SI
1567 (match_operand:SI 2 "gpc_reg_operand" "r")
1568 (const_int 16))
1569 (sign_extend:SI
1570 (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1571 "TARGET_MULHW"
1572 "mulchw %0,%1,%2"
1573 [(set_attr "type" "halfmul")])
1574
1575 (define_insn "*mulchwuc"
1576 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1577 (compare:CC (mult:SI (lshiftrt:SI
1578 (match_operand:SI 2 "gpc_reg_operand" "r")
1579 (const_int 16))
1580 (zero_extend:SI
1581 (match_operand:HI 1 "gpc_reg_operand" "r")))
1582 (const_int 0)))
1583 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1584 (mult:SI (lshiftrt:SI
1585 (match_dup 2)
1586 (const_int 16))
1587 (zero_extend:SI
1588 (match_dup 1))))]
1589 "TARGET_MULHW"
1590 "mulchwu. %0,%1,%2"
1591 [(set_attr "type" "halfmul")])
1592
1593 (define_insn "*mulchwu"
1594 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1595 (mult:SI (lshiftrt:SI
1596 (match_operand:SI 2 "gpc_reg_operand" "r")
1597 (const_int 16))
1598 (zero_extend:SI
1599 (match_operand:HI 1 "gpc_reg_operand" "r"))))]
1600 "TARGET_MULHW"
1601 "mulchwu %0,%1,%2"
1602 [(set_attr "type" "halfmul")])
1603
1604 (define_insn "*mulhhwc"
1605 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1606 (compare:CC (mult:SI (ashiftrt:SI
1607 (match_operand:SI 1 "gpc_reg_operand" "%r")
1608 (const_int 16))
1609 (ashiftrt:SI
1610 (match_operand:SI 2 "gpc_reg_operand" "r")
1611 (const_int 16)))
1612 (const_int 0)))
1613 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1614 (mult:SI (ashiftrt:SI
1615 (match_dup 1)
1616 (const_int 16))
1617 (ashiftrt:SI
1618 (match_dup 2)
1619 (const_int 16))))]
1620 "TARGET_MULHW"
1621 "mulhhw. %0,%1,%2"
1622 [(set_attr "type" "halfmul")])
1623
1624 (define_insn "*mulhhw"
1625 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1626 (mult:SI (ashiftrt:SI
1627 (match_operand:SI 1 "gpc_reg_operand" "%r")
1628 (const_int 16))
1629 (ashiftrt:SI
1630 (match_operand:SI 2 "gpc_reg_operand" "r")
1631 (const_int 16))))]
1632 "TARGET_MULHW"
1633 "mulhhw %0,%1,%2"
1634 [(set_attr "type" "halfmul")])
1635
1636 (define_insn "*mulhhwuc"
1637 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1638 (compare:CC (mult:SI (lshiftrt:SI
1639 (match_operand:SI 1 "gpc_reg_operand" "%r")
1640 (const_int 16))
1641 (lshiftrt:SI
1642 (match_operand:SI 2 "gpc_reg_operand" "r")
1643 (const_int 16)))
1644 (const_int 0)))
1645 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1646 (mult:SI (lshiftrt:SI
1647 (match_dup 1)
1648 (const_int 16))
1649 (lshiftrt:SI
1650 (match_dup 2)
1651 (const_int 16))))]
1652 "TARGET_MULHW"
1653 "mulhhwu. %0,%1,%2"
1654 [(set_attr "type" "halfmul")])
1655
1656 (define_insn "*mulhhwu"
1657 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1658 (mult:SI (lshiftrt:SI
1659 (match_operand:SI 1 "gpc_reg_operand" "%r")
1660 (const_int 16))
1661 (lshiftrt:SI
1662 (match_operand:SI 2 "gpc_reg_operand" "r")
1663 (const_int 16))))]
1664 "TARGET_MULHW"
1665 "mulhhwu %0,%1,%2"
1666 [(set_attr "type" "halfmul")])
1667
1668 (define_insn "*mullhwc"
1669 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1670 (compare:CC (mult:SI (sign_extend:SI
1671 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1672 (sign_extend:SI
1673 (match_operand:HI 2 "gpc_reg_operand" "r")))
1674 (const_int 0)))
1675 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1676 (mult:SI (sign_extend:SI
1677 (match_dup 1))
1678 (sign_extend:SI
1679 (match_dup 2))))]
1680 "TARGET_MULHW"
1681 "mullhw. %0,%1,%2"
1682 [(set_attr "type" "halfmul")])
1683
1684 (define_insn "*mullhw"
1685 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1686 (mult:SI (sign_extend:SI
1687 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1688 (sign_extend:SI
1689 (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1690 "TARGET_MULHW"
1691 "mullhw %0,%1,%2"
1692 [(set_attr "type" "halfmul")])
1693
1694 (define_insn "*mullhwuc"
1695 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1696 (compare:CC (mult:SI (zero_extend:SI
1697 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1698 (zero_extend:SI
1699 (match_operand:HI 2 "gpc_reg_operand" "r")))
1700 (const_int 0)))
1701 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1702 (mult:SI (zero_extend:SI
1703 (match_dup 1))
1704 (zero_extend:SI
1705 (match_dup 2))))]
1706 "TARGET_MULHW"
1707 "mullhwu. %0,%1,%2"
1708 [(set_attr "type" "halfmul")])
1709
1710 (define_insn "*mullhwu"
1711 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1712 (mult:SI (zero_extend:SI
1713 (match_operand:HI 1 "gpc_reg_operand" "%r"))
1714 (zero_extend:SI
1715 (match_operand:HI 2 "gpc_reg_operand" "r"))))]
1716 "TARGET_MULHW"
1717 "mullhwu %0,%1,%2"
1718 [(set_attr "type" "halfmul")])
1719
1720 ;; IBM 405, 440, 464 and 476 string-search dlmzb instruction support.
1721 (define_insn "dlmzb"
1722 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1723 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
1724 (match_operand:SI 2 "gpc_reg_operand" "r")]
1725 UNSPEC_DLMZB_CR))
1726 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1727 (unspec:SI [(match_dup 1)
1728 (match_dup 2)]
1729 UNSPEC_DLMZB))]
1730 "TARGET_DLMZB"
1731 "dlmzb. %0,%1,%2")
1732
1733 (define_expand "strlensi"
1734 [(set (match_operand:SI 0 "gpc_reg_operand")
1735 (unspec:SI [(match_operand:BLK 1 "general_operand")
1736 (match_operand:QI 2 "const_int_operand")
1737 (match_operand 3 "const_int_operand")]
1738 UNSPEC_DLMZB_STRLEN))
1739 (clobber (match_scratch:CC 4))]
1740 "TARGET_DLMZB && WORDS_BIG_ENDIAN && !optimize_size"
1741 {
1742 rtx result = operands[0];
1743 rtx src = operands[1];
1744 rtx search_char = operands[2];
1745 rtx align = operands[3];
1746 rtx addr, scratch_string, word1, word2, scratch_dlmzb;
1747 rtx loop_label, end_label, mem, cr0, cond;
1748 if (search_char != const0_rtx
1749 || !CONST_INT_P (align)
1750 || INTVAL (align) < 8)
1751 FAIL;
1752 word1 = gen_reg_rtx (SImode);
1753 word2 = gen_reg_rtx (SImode);
1754 scratch_dlmzb = gen_reg_rtx (SImode);
1755 scratch_string = gen_reg_rtx (Pmode);
1756 loop_label = gen_label_rtx ();
1757 end_label = gen_label_rtx ();
1758 addr = force_reg (Pmode, XEXP (src, 0));
1759 emit_move_insn (scratch_string, addr);
1760 emit_label (loop_label);
1761 mem = change_address (src, SImode, scratch_string);
1762 emit_move_insn (word1, mem);
1763 emit_move_insn (word2, adjust_address (mem, SImode, 4));
1764 cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
1765 emit_insn (gen_dlmzb (scratch_dlmzb, word1, word2, cr0));
1766 cond = gen_rtx_NE (VOIDmode, cr0, const0_rtx);
1767 emit_jump_insn (gen_rtx_SET (pc_rtx,
1768 gen_rtx_IF_THEN_ELSE (VOIDmode,
1769 cond,
1770 gen_rtx_LABEL_REF
1771 (VOIDmode,
1772 end_label),
1773 pc_rtx)));
1774 emit_insn (gen_addsi3 (scratch_string, scratch_string, GEN_INT (8)));
1775 emit_jump_insn (gen_rtx_SET (pc_rtx,
1776 gen_rtx_LABEL_REF (VOIDmode, loop_label)));
1777 emit_barrier ();
1778 emit_label (end_label);
1779 emit_insn (gen_addsi3 (scratch_string, scratch_string, scratch_dlmzb));
1780 emit_insn (gen_subsi3 (result, scratch_string, addr));
1781 emit_insn (gen_addsi3 (result, result, constm1_rtx));
1782 DONE;
1783 })
1784
1785 ;; Fixed-point arithmetic insns.
1786
1787 (define_expand "add<mode>3"
1788 [(set (match_operand:SDI 0 "gpc_reg_operand")
1789 (plus:SDI (match_operand:SDI 1 "gpc_reg_operand")
1790 (match_operand:SDI 2 "reg_or_add_cint_operand")))]
1791 ""
1792 {
1793 if (<MODE>mode == DImode && !TARGET_POWERPC64)
1794 {
1795 rtx lo0 = gen_lowpart (SImode, operands[0]);
1796 rtx lo1 = gen_lowpart (SImode, operands[1]);
1797 rtx lo2 = gen_lowpart (SImode, operands[2]);
1798 rtx hi0 = gen_highpart (SImode, operands[0]);
1799 rtx hi1 = gen_highpart (SImode, operands[1]);
1800 rtx hi2 = gen_highpart_mode (SImode, DImode, operands[2]);
1801
1802 if (!reg_or_short_operand (lo2, SImode))
1803 lo2 = force_reg (SImode, lo2);
1804 if (!adde_operand (hi2, SImode))
1805 hi2 = force_reg (SImode, hi2);
1806
1807 emit_insn (gen_addsi3_carry (lo0, lo1, lo2));
1808 emit_insn (gen_addsi3_carry_in (hi0, hi1, hi2));
1809 DONE;
1810 }
1811
1812 if (CONST_INT_P (operands[2]) && !add_operand (operands[2], <MODE>mode))
1813 {
1814 rtx tmp = ((!can_create_pseudo_p ()
1815 || rtx_equal_p (operands[0], operands[1]))
1816 ? operands[0] : gen_reg_rtx (<MODE>mode));
1817
1818 /* Adding a constant to r0 is not a valid insn, so use a different
1819 strategy in that case. */
1820 if (reg_or_subregno (operands[1]) == 0 || reg_or_subregno (tmp) == 0)
1821 {
1822 if (operands[0] == operands[1])
1823 FAIL;
1824 rs6000_emit_move (operands[0], operands[2], <MODE>mode);
1825 emit_insn (gen_add<mode>3 (operands[0], operands[1], operands[0]));
1826 DONE;
1827 }
1828
1829 HOST_WIDE_INT val = INTVAL (operands[2]);
1830 HOST_WIDE_INT low = sext_hwi (val, 16);
1831 HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1832
1833 if (<MODE>mode == DImode && !satisfies_constraint_L (GEN_INT (rest)))
1834 FAIL;
1835
1836 /* The ordering here is important for the prolog expander.
1837 When space is allocated from the stack, adding 'low' first may
1838 produce a temporary deallocation (which would be bad). */
1839 emit_insn (gen_add<mode>3 (tmp, operands[1], GEN_INT (rest)));
1840 emit_insn (gen_add<mode>3 (operands[0], tmp, GEN_INT (low)));
1841 DONE;
1842 }
1843 })
1844
1845 (define_insn "*add<mode>3"
1846 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r,r,r")
1847 (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b,b,b")
1848 (match_operand:GPR 2 "add_operand" "r,I,L,eI")))]
1849 ""
1850 "@
1851 add %0,%1,%2
1852 addi %0,%1,%2
1853 addis %0,%1,%v2
1854 addi %0,%1,%2"
1855 [(set_attr "type" "add")
1856 (set_attr "isa" "*,*,*,p10")])
1857
1858 (define_insn "*addsi3_high"
1859 [(set (match_operand:SI 0 "gpc_reg_operand" "=b")
1860 (plus:SI (match_operand:SI 1 "gpc_reg_operand" "b")
1861 (high:SI (match_operand 2 "" ""))))]
1862 "TARGET_MACHO && !TARGET_64BIT"
1863 "addis %0,%1,ha16(%2)"
1864 [(set_attr "type" "add")])
1865
1866 (define_insn_and_split "*add<mode>3_dot"
1867 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1868 (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
1869 (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
1870 (const_int 0)))
1871 (clobber (match_scratch:GPR 0 "=r,r"))]
1872 "<MODE>mode == Pmode"
1873 "@
1874 add. %0,%1,%2
1875 #"
1876 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
1877 [(set (match_dup 0)
1878 (plus:GPR (match_dup 1)
1879 (match_dup 2)))
1880 (set (match_dup 3)
1881 (compare:CC (match_dup 0)
1882 (const_int 0)))]
1883 ""
1884 [(set_attr "type" "add")
1885 (set_attr "dot" "yes")
1886 (set_attr "length" "4,8")])
1887
1888 (define_insn_and_split "*add<mode>3_dot2"
1889 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1890 (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
1891 (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
1892 (const_int 0)))
1893 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1894 (plus:GPR (match_dup 1)
1895 (match_dup 2)))]
1896 "<MODE>mode == Pmode"
1897 "@
1898 add. %0,%1,%2
1899 #"
1900 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
1901 [(set (match_dup 0)
1902 (plus:GPR (match_dup 1)
1903 (match_dup 2)))
1904 (set (match_dup 3)
1905 (compare:CC (match_dup 0)
1906 (const_int 0)))]
1907 ""
1908 [(set_attr "type" "add")
1909 (set_attr "dot" "yes")
1910 (set_attr "length" "4,8")])
1911
1912 (define_insn_and_split "*add<mode>3_imm_dot"
1913 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1914 (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b")
1915 (match_operand:GPR 2 "short_cint_operand" "I,I"))
1916 (const_int 0)))
1917 (clobber (match_scratch:GPR 0 "=r,r"))
1918 (clobber (reg:GPR CA_REGNO))]
1919 "<MODE>mode == Pmode"
1920 "@
1921 addic. %0,%1,%2
1922 #"
1923 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
1924 [(set (match_dup 0)
1925 (plus:GPR (match_dup 1)
1926 (match_dup 2)))
1927 (set (match_dup 3)
1928 (compare:CC (match_dup 0)
1929 (const_int 0)))]
1930 ""
1931 [(set_attr "type" "add")
1932 (set_attr "dot" "yes")
1933 (set_attr "length" "4,8")])
1934
1935 (define_insn_and_split "*add<mode>3_imm_dot2"
1936 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
1937 (compare:CC (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,b")
1938 (match_operand:GPR 2 "short_cint_operand" "I,I"))
1939 (const_int 0)))
1940 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
1941 (plus:GPR (match_dup 1)
1942 (match_dup 2)))
1943 (clobber (reg:GPR CA_REGNO))]
1944 "<MODE>mode == Pmode"
1945 "@
1946 addic. %0,%1,%2
1947 #"
1948 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
1949 [(set (match_dup 0)
1950 (plus:GPR (match_dup 1)
1951 (match_dup 2)))
1952 (set (match_dup 3)
1953 (compare:CC (match_dup 0)
1954 (const_int 0)))]
1955 ""
1956 [(set_attr "type" "add")
1957 (set_attr "dot" "yes")
1958 (set_attr "length" "4,8")])
1959
1960 ;; Split an add that we can't do in one insn into two insns, each of which
1961 ;; does one 16-bit part. This is used by combine. Note that the low-order
1962 ;; add should be last in case the result gets used in an address.
1963
1964 (define_split
1965 [(set (match_operand:GPR 0 "gpc_reg_operand")
1966 (plus:GPR (match_operand:GPR 1 "gpc_reg_operand")
1967 (match_operand:GPR 2 "non_add_cint_operand")))]
1968 ""
1969 [(set (match_dup 0) (plus:GPR (match_dup 1) (match_dup 3)))
1970 (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))]
1971 {
1972 HOST_WIDE_INT val = INTVAL (operands[2]);
1973 HOST_WIDE_INT low = sext_hwi (val, 16);
1974 HOST_WIDE_INT rest = trunc_int_for_mode (val - low, <MODE>mode);
1975
1976 operands[4] = GEN_INT (low);
1977 if (<MODE>mode == SImode || satisfies_constraint_L (GEN_INT (rest)))
1978 operands[3] = GEN_INT (rest);
1979 else if (can_create_pseudo_p ())
1980 {
1981 operands[3] = gen_reg_rtx (DImode);
1982 emit_move_insn (operands[3], operands[2]);
1983 emit_insn (gen_adddi3 (operands[0], operands[1], operands[3]));
1984 DONE;
1985 }
1986 else
1987 FAIL;
1988 })
1989
1990
1991 (define_insn "add<mode>3_carry"
1992 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
1993 (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
1994 (match_operand:P 2 "reg_or_short_operand" "rI")))
1995 (set (reg:P CA_REGNO)
1996 (ltu:P (plus:P (match_dup 1)
1997 (match_dup 2))
1998 (match_dup 1)))]
1999 ""
2000 "add%I2c %0,%1,%2"
2001 [(set_attr "type" "add")])
2002
2003 (define_insn "*add<mode>3_imm_carry_pos"
2004 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2005 (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
2006 (match_operand:P 2 "short_cint_operand" "n")))
2007 (set (reg:P CA_REGNO)
2008 (geu:P (match_dup 1)
2009 (match_operand:P 3 "const_int_operand" "n")))]
2010 "INTVAL (operands[2]) > 0
2011 && INTVAL (operands[2]) + INTVAL (operands[3]) == 0"
2012 "addic %0,%1,%2"
2013 [(set_attr "type" "add")])
2014
2015 (define_insn "*add<mode>3_imm_carry_0"
2016 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2017 (match_operand:P 1 "gpc_reg_operand" "r"))
2018 (set (reg:P CA_REGNO)
2019 (const_int 0))]
2020 ""
2021 "addic %0,%1,0"
2022 [(set_attr "type" "add")])
2023
2024 (define_insn "*add<mode>3_imm_carry_m1"
2025 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2026 (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
2027 (const_int -1)))
2028 (set (reg:P CA_REGNO)
2029 (ne:P (match_dup 1)
2030 (const_int 0)))]
2031 ""
2032 "addic %0,%1,-1"
2033 [(set_attr "type" "add")])
2034
2035 (define_insn "*add<mode>3_imm_carry_neg"
2036 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2037 (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
2038 (match_operand:P 2 "short_cint_operand" "n")))
2039 (set (reg:P CA_REGNO)
2040 (gtu:P (match_dup 1)
2041 (match_operand:P 3 "const_int_operand" "n")))]
2042 "INTVAL (operands[2]) < 0
2043 && INTVAL (operands[2]) + INTVAL (operands[3]) == -1"
2044 "addic %0,%1,%2"
2045 [(set_attr "type" "add")])
2046
2047
2048 (define_expand "add<mode>3_carry_in"
2049 [(parallel [
2050 (set (match_operand:GPR 0 "gpc_reg_operand")
2051 (plus:GPR (plus:GPR (match_operand:GPR 1 "gpc_reg_operand")
2052 (match_operand:GPR 2 "adde_operand"))
2053 (reg:GPR CA_REGNO)))
2054 (clobber (reg:GPR CA_REGNO))])]
2055 ""
2056 {
2057 if (operands[2] == const0_rtx)
2058 {
2059 emit_insn (gen_add<mode>3_carry_in_0 (operands[0], operands[1]));
2060 DONE;
2061 }
2062 if (operands[2] == constm1_rtx)
2063 {
2064 emit_insn (gen_add<mode>3_carry_in_m1 (operands[0], operands[1]));
2065 DONE;
2066 }
2067 })
2068
2069 (define_insn "*add<mode>3_carry_in_internal"
2070 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2071 (plus:GPR (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2072 (match_operand:GPR 2 "gpc_reg_operand" "r"))
2073 (reg:GPR CA_REGNO)))
2074 (clobber (reg:GPR CA_REGNO))]
2075 ""
2076 "adde %0,%1,%2"
2077 [(set_attr "type" "add")])
2078
2079 (define_insn "*add<mode>3_carry_in_internal2"
2080 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2081 (plus:GPR (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2082 (reg:GPR CA_REGNO))
2083 (match_operand:GPR 2 "gpc_reg_operand" "r")))
2084 (clobber (reg:GPR CA_REGNO))]
2085 ""
2086 "adde %0,%1,%2"
2087 [(set_attr "type" "add")])
2088
2089 (define_insn "add<mode>3_carry_in_0"
2090 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2091 (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2092 (reg:GPR CA_REGNO)))
2093 (clobber (reg:GPR CA_REGNO))]
2094 ""
2095 "addze %0,%1"
2096 [(set_attr "type" "add")])
2097
2098 (define_insn "add<mode>3_carry_in_m1"
2099 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2100 (plus:GPR (plus:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
2101 (reg:GPR CA_REGNO))
2102 (const_int -1)))
2103 (clobber (reg:GPR CA_REGNO))]
2104 ""
2105 "addme %0,%1"
2106 [(set_attr "type" "add")])
2107
2108
2109 (define_expand "one_cmpl<mode>2"
2110 [(set (match_operand:SDI 0 "gpc_reg_operand")
2111 (not:SDI (match_operand:SDI 1 "gpc_reg_operand")))]
2112 ""
2113 {
2114 if (<MODE>mode == DImode && !TARGET_POWERPC64)
2115 {
2116 rs6000_split_logical (operands, NOT, false, false, false);
2117 DONE;
2118 }
2119 })
2120
2121 (define_insn "*one_cmpl<mode>2"
2122 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2123 (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2124 ""
2125 "not %0,%1")
2126
2127 (define_insn_and_split "*one_cmpl<mode>2_dot"
2128 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2129 (compare:CC (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
2130 (const_int 0)))
2131 (clobber (match_scratch:GPR 0 "=r,r"))]
2132 "<MODE>mode == Pmode"
2133 "@
2134 not. %0,%1
2135 #"
2136 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
2137 [(set (match_dup 0)
2138 (not:GPR (match_dup 1)))
2139 (set (match_dup 2)
2140 (compare:CC (match_dup 0)
2141 (const_int 0)))]
2142 ""
2143 [(set_attr "type" "logical")
2144 (set_attr "dot" "yes")
2145 (set_attr "length" "4,8")])
2146
2147 (define_insn_and_split "*one_cmpl<mode>2_dot2"
2148 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2149 (compare:CC (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
2150 (const_int 0)))
2151 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
2152 (not:GPR (match_dup 1)))]
2153 "<MODE>mode == Pmode"
2154 "@
2155 not. %0,%1
2156 #"
2157 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
2158 [(set (match_dup 0)
2159 (not:GPR (match_dup 1)))
2160 (set (match_dup 2)
2161 (compare:CC (match_dup 0)
2162 (const_int 0)))]
2163 ""
2164 [(set_attr "type" "logical")
2165 (set_attr "dot" "yes")
2166 (set_attr "length" "4,8")])
2167
2168
2169 (define_expand "sub<mode>3"
2170 [(set (match_operand:SDI 0 "gpc_reg_operand")
2171 (minus:SDI (match_operand:SDI 1 "reg_or_short_operand")
2172 (match_operand:SDI 2 "gpc_reg_operand")))]
2173 ""
2174 {
2175 if (<MODE>mode == DImode && !TARGET_POWERPC64)
2176 {
2177 rtx lo0 = gen_lowpart (SImode, operands[0]);
2178 rtx lo1 = gen_lowpart (SImode, operands[1]);
2179 rtx lo2 = gen_lowpart (SImode, operands[2]);
2180 rtx hi0 = gen_highpart (SImode, operands[0]);
2181 rtx hi1 = gen_highpart_mode (SImode, DImode, operands[1]);
2182 rtx hi2 = gen_highpart (SImode, operands[2]);
2183
2184 if (!reg_or_short_operand (lo1, SImode))
2185 lo1 = force_reg (SImode, lo1);
2186 if (!adde_operand (hi1, SImode))
2187 hi1 = force_reg (SImode, hi1);
2188
2189 emit_insn (gen_subfsi3_carry (lo0, lo2, lo1));
2190 emit_insn (gen_subfsi3_carry_in (hi0, hi2, hi1));
2191 DONE;
2192 }
2193
2194 if (short_cint_operand (operands[1], <MODE>mode))
2195 {
2196 emit_insn (gen_subf<mode>3_imm (operands[0], operands[2], operands[1]));
2197 DONE;
2198 }
2199 })
2200
2201 (define_insn "*subf<mode>3"
2202 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2203 (minus:GPR (match_operand:GPR 2 "gpc_reg_operand" "r")
2204 (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2205 ""
2206 "subf %0,%1,%2"
2207 [(set_attr "type" "add")])
2208
2209 (define_insn_and_split "*subf<mode>3_dot"
2210 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2211 (compare:CC (minus:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r")
2212 (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
2213 (const_int 0)))
2214 (clobber (match_scratch:GPR 0 "=r,r"))]
2215 "<MODE>mode == Pmode"
2216 "@
2217 subf. %0,%1,%2
2218 #"
2219 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
2220 [(set (match_dup 0)
2221 (minus:GPR (match_dup 2)
2222 (match_dup 1)))
2223 (set (match_dup 3)
2224 (compare:CC (match_dup 0)
2225 (const_int 0)))]
2226 ""
2227 [(set_attr "type" "add")
2228 (set_attr "dot" "yes")
2229 (set_attr "length" "4,8")])
2230
2231 (define_insn_and_split "*subf<mode>3_dot2"
2232 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2233 (compare:CC (minus:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r")
2234 (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
2235 (const_int 0)))
2236 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
2237 (minus:GPR (match_dup 2)
2238 (match_dup 1)))]
2239 "<MODE>mode == Pmode"
2240 "@
2241 subf. %0,%1,%2
2242 #"
2243 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
2244 [(set (match_dup 0)
2245 (minus:GPR (match_dup 2)
2246 (match_dup 1)))
2247 (set (match_dup 3)
2248 (compare:CC (match_dup 0)
2249 (const_int 0)))]
2250 ""
2251 [(set_attr "type" "add")
2252 (set_attr "dot" "yes")
2253 (set_attr "length" "4,8")])
2254
2255 (define_insn "subf<mode>3_imm"
2256 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2257 (minus:GPR (match_operand:GPR 2 "short_cint_operand" "I")
2258 (match_operand:GPR 1 "gpc_reg_operand" "r")))
2259 (clobber (reg:GPR CA_REGNO))]
2260 ""
2261 "subfic %0,%1,%2"
2262 [(set_attr "type" "add")])
2263
2264 (define_insn_and_split "subf<mode>3_carry_dot2"
2265 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
2266 (compare:CC (minus:P (match_operand:P 2 "gpc_reg_operand" "r,r")
2267 (match_operand:P 1 "gpc_reg_operand" "r,r"))
2268 (const_int 0)))
2269 (set (match_operand:P 0 "gpc_reg_operand" "=r,r")
2270 (minus:P (match_dup 2)
2271 (match_dup 1)))
2272 (set (reg:P CA_REGNO)
2273 (leu:P (match_dup 1)
2274 (match_dup 2)))]
2275 "<MODE>mode == Pmode"
2276 "@
2277 subfc. %0,%1,%2
2278 #"
2279 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
2280 [(parallel [(set (match_dup 0)
2281 (minus:P (match_dup 2)
2282 (match_dup 1)))
2283 (set (reg:P CA_REGNO)
2284 (leu:P (match_dup 1)
2285 (match_dup 2)))])
2286 (set (match_dup 3)
2287 (compare:CC (match_dup 0)
2288 (const_int 0)))]
2289 ""
2290 [(set_attr "type" "add")
2291 (set_attr "dot" "yes")
2292 (set_attr "length" "4,8")])
2293
2294 (define_insn "subf<mode>3_carry"
2295 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2296 (minus:P (match_operand:P 2 "reg_or_short_operand" "rI")
2297 (match_operand:P 1 "gpc_reg_operand" "r")))
2298 (set (reg:P CA_REGNO)
2299 (leu:P (match_dup 1)
2300 (match_dup 2)))]
2301 ""
2302 "subf%I2c %0,%1,%2"
2303 [(set_attr "type" "add")])
2304
2305 (define_insn "*subf<mode>3_imm_carry_0"
2306 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2307 (neg:P (match_operand:P 1 "gpc_reg_operand" "r")))
2308 (set (reg:P CA_REGNO)
2309 (eq:P (match_dup 1)
2310 (const_int 0)))]
2311 ""
2312 "subfic %0,%1,0"
2313 [(set_attr "type" "add")])
2314
2315 (define_insn "*subf<mode>3_imm_carry_m1"
2316 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
2317 (not:P (match_operand:P 1 "gpc_reg_operand" "r")))
2318 (set (reg:P CA_REGNO)
2319 (const_int 1))]
2320 ""
2321 "subfic %0,%1,-1"
2322 [(set_attr "type" "add")])
2323
2324
2325 (define_expand "subf<mode>3_carry_in"
2326 [(parallel [
2327 (set (match_operand:GPR 0 "gpc_reg_operand")
2328 (plus:GPR (plus:GPR (not:GPR (match_operand:GPR 1 "gpc_reg_operand"))
2329 (reg:GPR CA_REGNO))
2330 (match_operand:GPR 2 "adde_operand")))
2331 (clobber (reg:GPR CA_REGNO))])]
2332 ""
2333 {
2334 if (operands[2] == const0_rtx)
2335 {
2336 emit_insn (gen_subf<mode>3_carry_in_0 (operands[0], operands[1]));
2337 DONE;
2338 }
2339 if (operands[2] == constm1_rtx)
2340 {
2341 emit_insn (gen_subf<mode>3_carry_in_m1 (operands[0], operands[1]));
2342 DONE;
2343 }
2344 })
2345
2346 (define_insn "*subf<mode>3_carry_in_internal"
2347 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2348 (plus:GPR (plus:GPR (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))
2349 (reg:GPR CA_REGNO))
2350 (match_operand:GPR 2 "gpc_reg_operand" "r")))
2351 (clobber (reg:GPR CA_REGNO))]
2352 ""
2353 "subfe %0,%1,%2"
2354 [(set_attr "type" "add")])
2355
2356 (define_insn "subf<mode>3_carry_in_0"
2357 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2358 (plus:GPR (not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))
2359 (reg:GPR CA_REGNO)))
2360 (clobber (reg:GPR CA_REGNO))]
2361 ""
2362 "subfze %0,%1"
2363 [(set_attr "type" "add")])
2364
2365 (define_insn "subf<mode>3_carry_in_m1"
2366 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2367 (plus:GPR (minus:GPR (reg:GPR CA_REGNO)
2368 (match_operand:GPR 1 "gpc_reg_operand" "r"))
2369 (const_int -2)))
2370 (clobber (reg:GPR CA_REGNO))]
2371 ""
2372 "subfme %0,%1"
2373 [(set_attr "type" "add")])
2374
2375 (define_insn "subf<mode>3_carry_in_xx"
2376 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2377 (plus:GPR (reg:GPR CA_REGNO)
2378 (const_int -1)))
2379 (clobber (reg:GPR CA_REGNO))]
2380 ""
2381 "subfe %0,%0,%0"
2382 [(set_attr "type" "add")])
2383
2384 (define_insn_and_split "*subfsi3_carry_in_xx_64"
2385 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2386 (sign_extend:DI (plus:SI (reg:SI CA_REGNO)
2387 (const_int -1))))]
2388 "TARGET_POWERPC64"
2389 "#"
2390 "&&1"
2391 [(parallel [(set (match_dup 0)
2392 (plus:DI (reg:DI CA_REGNO)
2393 (const_int -1)))
2394 (clobber (reg:DI CA_REGNO))])]
2395 ""
2396 )
2397
2398 (define_insn "@neg<mode>2"
2399 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2400 (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2401 ""
2402 "neg %0,%1"
2403 [(set_attr "type" "add")])
2404
2405 (define_insn_and_split "*neg<mode>2_dot"
2406 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2407 (compare:CC (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
2408 (const_int 0)))
2409 (clobber (match_scratch:GPR 0 "=r,r"))]
2410 "<MODE>mode == Pmode"
2411 "@
2412 neg. %0,%1
2413 #"
2414 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
2415 [(set (match_dup 0)
2416 (neg:GPR (match_dup 1)))
2417 (set (match_dup 2)
2418 (compare:CC (match_dup 0)
2419 (const_int 0)))]
2420 ""
2421 [(set_attr "type" "add")
2422 (set_attr "dot" "yes")
2423 (set_attr "length" "4,8")])
2424
2425 (define_insn_and_split "*neg<mode>2_dot2"
2426 [(set (match_operand:CC 2 "cc_reg_operand" "=x,?y")
2427 (compare:CC (neg:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
2428 (const_int 0)))
2429 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
2430 (neg:GPR (match_dup 1)))]
2431 "<MODE>mode == Pmode"
2432 "@
2433 neg. %0,%1
2434 #"
2435 "&& reload_completed && cc_reg_not_cr0_operand (operands[2], CCmode)"
2436 [(set (match_dup 0)
2437 (neg:GPR (match_dup 1)))
2438 (set (match_dup 2)
2439 (compare:CC (match_dup 0)
2440 (const_int 0)))]
2441 ""
2442 [(set_attr "type" "add")
2443 (set_attr "dot" "yes")
2444 (set_attr "length" "4,8")])
2445
2446
2447 (define_insn "clz<mode>2"
2448 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2449 (clz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2450 ""
2451 "cntlz<wd> %0,%1"
2452 [(set_attr "type" "cntlz")])
2453
2454 (define_expand "ctz<mode>2"
2455 [(set (match_operand:GPR 0 "gpc_reg_operand")
2456 (ctz:GPR (match_operand:GPR 1 "gpc_reg_operand")))]
2457 ""
2458 {
2459 if (TARGET_CTZ)
2460 {
2461 emit_insn (gen_ctz<mode>2_hw (operands[0], operands[1]));
2462 DONE;
2463 }
2464
2465 rtx tmp1 = gen_reg_rtx (<MODE>mode);
2466 rtx tmp2 = gen_reg_rtx (<MODE>mode);
2467 rtx tmp3 = gen_reg_rtx (<MODE>mode);
2468
2469 if (TARGET_POPCNTD)
2470 {
2471 emit_insn (gen_add<mode>3 (tmp1, operands[1], constm1_rtx));
2472 emit_insn (gen_one_cmpl<mode>2 (tmp2, operands[1]));
2473 emit_insn (gen_and<mode>3 (tmp3, tmp1, tmp2));
2474 emit_insn (gen_popcntd<mode>2 (operands[0], tmp3));
2475 }
2476 else
2477 {
2478 emit_insn (gen_neg<mode>2 (tmp1, operands[1]));
2479 emit_insn (gen_and<mode>3 (tmp2, operands[1], tmp1));
2480 emit_insn (gen_clz<mode>2 (tmp3, tmp2));
2481 emit_insn (gen_sub<mode>3 (operands[0], GEN_INT (<bits> - 1), tmp3));
2482 }
2483
2484 DONE;
2485 })
2486
2487 (define_insn "ctz<mode>2_hw"
2488 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2489 (ctz:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2490 "TARGET_CTZ"
2491 "cnttz<wd> %0,%1"
2492 [(set_attr "type" "cntlz")])
2493
2494 (define_expand "ffs<mode>2"
2495 [(set (match_operand:GPR 0 "gpc_reg_operand")
2496 (ffs:GPR (match_operand:GPR 1 "gpc_reg_operand")))]
2497 ""
2498 {
2499 rtx tmp1 = gen_reg_rtx (<MODE>mode);
2500 rtx tmp2 = gen_reg_rtx (<MODE>mode);
2501 rtx tmp3 = gen_reg_rtx (<MODE>mode);
2502 emit_insn (gen_neg<mode>2 (tmp1, operands[1]));
2503 emit_insn (gen_and<mode>3 (tmp2, operands[1], tmp1));
2504 emit_insn (gen_clz<mode>2 (tmp3, tmp2));
2505 emit_insn (gen_sub<mode>3 (operands[0], GEN_INT (<bits>), tmp3));
2506 DONE;
2507 })
2508
2509
2510 (define_expand "popcount<mode>2"
2511 [(set (match_operand:GPR 0 "gpc_reg_operand")
2512 (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand")))]
2513 "TARGET_POPCNTB || TARGET_POPCNTD"
2514 {
2515 rs6000_emit_popcount (operands[0], operands[1]);
2516 DONE;
2517 })
2518
2519 (define_insn "popcntb<mode>2"
2520 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2521 (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")]
2522 UNSPEC_POPCNTB))]
2523 "TARGET_POPCNTB"
2524 "popcntb %0,%1"
2525 [(set_attr "type" "popcnt")])
2526
2527 (define_insn "popcntd<mode>2"
2528 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2529 (popcount:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")))]
2530 "TARGET_POPCNTD"
2531 "popcnt<wd> %0,%1"
2532 [(set_attr "type" "popcnt")])
2533
2534
2535 (define_expand "parity<mode>2"
2536 [(set (match_operand:GPR 0 "gpc_reg_operand")
2537 (parity:GPR (match_operand:GPR 1 "gpc_reg_operand")))]
2538 "TARGET_POPCNTB"
2539 {
2540 rs6000_emit_parity (operands[0], operands[1]);
2541 DONE;
2542 })
2543
2544 (define_insn "parity<mode>2_cmpb"
2545 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2546 (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")] UNSPEC_PARITY))]
2547 "TARGET_CMPB && TARGET_POPCNTB"
2548 "prty<wd> %0,%1"
2549 [(set_attr "type" "popcnt")])
2550
2551 (define_insn "cfuged"
2552 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2553 (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
2554 (match_operand:DI 2 "gpc_reg_operand" "r")]
2555 UNSPEC_CFUGED))]
2556 "TARGET_POWER10 && TARGET_64BIT"
2557 "cfuged %0,%1,%2"
2558 [(set_attr "type" "integer")])
2559
2560 (define_insn "cntlzdm"
2561 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2562 (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
2563 (match_operand:DI 2 "gpc_reg_operand" "r")]
2564 UNSPEC_CNTLZDM))]
2565 "TARGET_POWER10 && TARGET_POWERPC64"
2566 "cntlzdm %0,%1,%2"
2567 [(set_attr "type" "integer")])
2568
2569 (define_insn "cnttzdm"
2570 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2571 (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
2572 (match_operand:DI 2 "gpc_reg_operand" "r")]
2573 UNSPEC_CNTTZDM))]
2574 "TARGET_POWER10 && TARGET_POWERPC64"
2575 "cnttzdm %0,%1,%2"
2576 [(set_attr "type" "integer")])
2577
2578 (define_insn "pdepd"
2579 [(set (match_operand:DI 0 "register_operand" "=r")
2580 (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
2581 (match_operand:DI 2 "gpc_reg_operand" "r")]
2582 UNSPEC_PDEPD))]
2583 "TARGET_POWER10 && TARGET_POWERPC64"
2584 "pdepd %0,%1,%2"
2585 [(set_attr "type" "integer")])
2586
2587 (define_insn "pextd"
2588 [(set (match_operand:DI 0 "register_operand" "=r")
2589 (unspec:DI [(match_operand:DI 1 "gpc_reg_operand" "r")
2590 (match_operand:DI 2 "gpc_reg_operand" "r")]
2591 UNSPEC_PEXTD))]
2592 "TARGET_POWER10 && TARGET_POWERPC64"
2593 "pextd %0,%1,%2"
2594 [(set_attr "type" "integer")])
2595
2596 (define_insn "cmpb<mode>3"
2597 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
2598 (unspec:GPR [(match_operand:GPR 1 "gpc_reg_operand" "r")
2599 (match_operand:GPR 2 "gpc_reg_operand" "r")] UNSPEC_CMPB))]
2600 "TARGET_CMPB"
2601 "cmpb %0,%1,%2"
2602 [(set_attr "type" "cmp")])
2603
2604 ;; Since the hardware zeros the upper part of the register, save generating the
2605 ;; AND immediate if we are converting to unsigned
2606 (define_insn "*bswap<mode>2_extenddi"
2607 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2608 (zero_extend:DI
2609 (bswap:HSI (match_operand:HSI 1 "memory_operand" "Z"))))]
2610 "TARGET_POWERPC64"
2611 "l<wd>brx %0,%y1"
2612 [(set_attr "type" "load")])
2613
2614 (define_insn "*bswaphi2_extendsi"
2615 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2616 (zero_extend:SI
2617 (bswap:HI (match_operand:HI 1 "memory_operand" "Z"))))]
2618 ""
2619 "lhbrx %0,%y1"
2620 [(set_attr "type" "load")])
2621
2622 ;; Separate the bswap patterns into load, store, and gpr<-gpr. This prevents
2623 ;; the register allocator from converting a gpr<-gpr swap into a store and then
2624 ;; load with byte swap, which can be slower than doing it in the registers. It
2625 ;; also prevents certain failures with the RELOAD register allocator.
2626
2627 (define_expand "bswap<mode>2"
2628 [(use (match_operand:HSI 0 "reg_or_mem_operand"))
2629 (use (match_operand:HSI 1 "reg_or_mem_operand"))]
2630 ""
2631 {
2632 rtx dest = operands[0];
2633 rtx src = operands[1];
2634
2635 if (!REG_P (dest) && !REG_P (src))
2636 src = force_reg (<MODE>mode, src);
2637
2638 if (MEM_P (src))
2639 {
2640 src = rs6000_force_indexed_or_indirect_mem (src);
2641 emit_insn (gen_bswap<mode>2_load (dest, src));
2642 }
2643 else if (MEM_P (dest))
2644 {
2645 dest = rs6000_force_indexed_or_indirect_mem (dest);
2646 emit_insn (gen_bswap<mode>2_store (dest, src));
2647 }
2648 else
2649 emit_insn (gen_bswap<mode>2_reg (dest, src));
2650 DONE;
2651 })
2652
2653 (define_insn "bswap<mode>2_load"
2654 [(set (match_operand:HSI 0 "gpc_reg_operand" "=r")
2655 (bswap:HSI (match_operand:HSI 1 "memory_operand" "Z")))]
2656 ""
2657 "l<wd>brx %0,%y1"
2658 [(set_attr "type" "load")])
2659
2660 (define_insn "bswap<mode>2_store"
2661 [(set (match_operand:HSI 0 "memory_operand" "=Z")
2662 (bswap:HSI (match_operand:HSI 1 "gpc_reg_operand" "r")))]
2663 ""
2664 "st<wd>brx %1,%y0"
2665 [(set_attr "type" "store")])
2666
2667 (define_insn_and_split "bswaphi2_reg"
2668 [(set (match_operand:HI 0 "gpc_reg_operand" "=r,&r,wa")
2669 (bswap:HI
2670 (match_operand:HI 1 "gpc_reg_operand" "r,r,wa")))
2671 (clobber (match_scratch:SI 2 "=X,&r,X"))]
2672 ""
2673 "@
2674 brh %0,%1
2675 #
2676 xxbrh %x0,%x1"
2677 "reload_completed && !TARGET_POWER10 && int_reg_operand (operands[0], HImode)"
2678 [(set (match_dup 3)
2679 (and:SI (lshiftrt:SI (match_dup 4)
2680 (const_int 8))
2681 (const_int 255)))
2682 (set (match_dup 2)
2683 (and:SI (ashift:SI (match_dup 4)
2684 (const_int 8))
2685 (const_int 65280))) ;; 0xff00
2686 (set (match_dup 3)
2687 (ior:SI (match_dup 3)
2688 (match_dup 2)))]
2689 {
2690 operands[3] = simplify_gen_subreg (SImode, operands[0], HImode, 0);
2691 operands[4] = simplify_gen_subreg (SImode, operands[1], HImode, 0);
2692 }
2693 [(set_attr "length" "*,12,*")
2694 (set_attr "type" "shift,*,vecperm")
2695 (set_attr "isa" "p10,*,p9v")])
2696
2697 ;; We are always BITS_BIG_ENDIAN, so the bit positions below in
2698 ;; zero_extract insns do not change for -mlittle.
2699 (define_insn_and_split "bswapsi2_reg"
2700 [(set (match_operand:SI 0 "gpc_reg_operand" "=r,&r,wa")
2701 (bswap:SI
2702 (match_operand:SI 1 "gpc_reg_operand" "r,r,wa")))]
2703 ""
2704 "@
2705 brw %0,%1
2706 #
2707 xxbrw %x0,%x1"
2708 "reload_completed && !TARGET_POWER10 && int_reg_operand (operands[0], SImode)"
2709 [(set (match_dup 0) ; DABC
2710 (rotate:SI (match_dup 1)
2711 (const_int 24)))
2712 (set (match_dup 0) ; DCBC
2713 (ior:SI (and:SI (ashift:SI (match_dup 1)
2714 (const_int 8))
2715 (const_int 16711680))
2716 (and:SI (match_dup 0)
2717 (const_int -16711681))))
2718 (set (match_dup 0) ; DCBA
2719 (ior:SI (and:SI (lshiftrt:SI (match_dup 1)
2720 (const_int 24))
2721 (const_int 255))
2722 (and:SI (match_dup 0)
2723 (const_int -256))))]
2724 ""
2725 [(set_attr "length" "4,12,4")
2726 (set_attr "type" "shift,*,vecperm")
2727 (set_attr "isa" "p10,*,p9v")])
2728
2729 ;; On systems with LDBRX/STDBRX generate the loads/stores directly, just like
2730 ;; we do for L{H,W}BRX and ST{H,W}BRX above. If not, we have to generate more
2731 ;; complex code.
2732
2733 (define_expand "bswapdi2"
2734 [(parallel [(set (match_operand:DI 0 "reg_or_mem_operand")
2735 (bswap:DI
2736 (match_operand:DI 1 "reg_or_mem_operand")))
2737 (clobber (match_scratch:DI 2))
2738 (clobber (match_scratch:DI 3))])]
2739 ""
2740 {
2741 rtx dest = operands[0];
2742 rtx src = operands[1];
2743
2744 if (!REG_P (dest) && !REG_P (src))
2745 operands[1] = src = force_reg (DImode, src);
2746
2747 if (TARGET_POWERPC64 && TARGET_LDBRX)
2748 {
2749 if (MEM_P (src))
2750 {
2751 src = rs6000_force_indexed_or_indirect_mem (src);
2752 emit_insn (gen_bswapdi2_load (dest, src));
2753 }
2754 else if (MEM_P (dest))
2755 {
2756 dest = rs6000_force_indexed_or_indirect_mem (dest);
2757 emit_insn (gen_bswapdi2_store (dest, src));
2758 }
2759 else if (TARGET_P9_VECTOR)
2760 emit_insn (gen_bswapdi2_brd (dest, src));
2761 else
2762 emit_insn (gen_bswapdi2_reg (dest, src));
2763 DONE;
2764 }
2765
2766 if (!TARGET_POWERPC64)
2767 {
2768 /* 32-bit mode needs fewer scratch registers, but 32-bit addressing mode
2769 that uses 64-bit registers needs the same scratch registers as 64-bit
2770 mode. */
2771 emit_insn (gen_bswapdi2_32bit (dest, src));
2772 DONE;
2773 }
2774 })
2775
2776 ;; Power7/cell has ldbrx/stdbrx, so use it directly
2777 (define_insn "bswapdi2_load"
2778 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
2779 (bswap:DI (match_operand:DI 1 "memory_operand" "Z")))]
2780 "TARGET_POWERPC64 && TARGET_LDBRX"
2781 "ldbrx %0,%y1"
2782 [(set_attr "type" "load")])
2783
2784 (define_insn "bswapdi2_store"
2785 [(set (match_operand:DI 0 "memory_operand" "=Z")
2786 (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
2787 "TARGET_POWERPC64 && TARGET_LDBRX"
2788 "stdbrx %1,%y0"
2789 [(set_attr "type" "store")])
2790
2791 (define_insn "bswapdi2_brd"
2792 [(set (match_operand:DI 0 "gpc_reg_operand" "=r,wa")
2793 (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "r,wa")))]
2794 "TARGET_P9_VECTOR"
2795 "@
2796 brd %0,%1
2797 xxbrd %x0,%x1"
2798 [(set_attr "type" "shift,vecperm")
2799 (set_attr "isa" "p10,p9v")])
2800
2801 (define_insn "bswapdi2_reg"
2802 [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
2803 (bswap:DI (match_operand:DI 1 "gpc_reg_operand" "r")))
2804 (clobber (match_scratch:DI 2 "=&r"))
2805 (clobber (match_scratch:DI 3 "=&r"))]
2806 "TARGET_POWERPC64 && TARGET_LDBRX && !TARGET_P9_VECTOR"
2807 "#"
2808 [(set_attr "length" "36")])
2809
2810 ;; Non-power7/cell, fall back to use lwbrx/stwbrx
2811 (define_insn "*bswapdi2_64bit"
2812 [(set (match_operand:DI 0 "reg_or_mem_operand" "=r,Z,&r")
2813 (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2814 (clobber (match_scratch:DI 2 "=&b,&b,&r"))
2815 (clobber (match_scratch:DI 3 "=&r,&r,&r"))]
2816 "TARGET_POWERPC64 && !TARGET_LDBRX
2817 && (REG_P (operands[0]) || REG_P (operands[1]))
2818 && !(MEM_P (operands[0]) && MEM_VOLATILE_P (operands[0]))
2819 && !(MEM_P (operands[1]) && MEM_VOLATILE_P (operands[1]))"
2820 "#"
2821 [(set_attr "length" "16,12,36")])
2822
2823 (define_split
2824 [(set (match_operand:DI 0 "gpc_reg_operand")
2825 (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand")))
2826 (clobber (match_operand:DI 2 "gpc_reg_operand"))
2827 (clobber (match_operand:DI 3 "gpc_reg_operand"))]
2828 "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2829 [(const_int 0)]
2830 {
2831 rtx dest = operands[0];
2832 rtx src = operands[1];
2833 rtx op2 = operands[2];
2834 rtx op3 = operands[3];
2835 rtx op3_32 = simplify_gen_subreg (SImode, op3, DImode,
2836 BYTES_BIG_ENDIAN ? 4 : 0);
2837 rtx dest_32 = simplify_gen_subreg (SImode, dest, DImode,
2838 BYTES_BIG_ENDIAN ? 4 : 0);
2839 rtx addr1;
2840 rtx addr2;
2841 rtx word1;
2842 rtx word2;
2843
2844 addr1 = XEXP (src, 0);
2845 if (GET_CODE (addr1) == PLUS)
2846 {
2847 emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2848 if (TARGET_AVOID_XFORM)
2849 {
2850 emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2851 addr2 = op2;
2852 }
2853 else
2854 addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2855 }
2856 else if (TARGET_AVOID_XFORM)
2857 {
2858 emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2859 addr2 = op2;
2860 }
2861 else
2862 {
2863 emit_move_insn (op2, GEN_INT (4));
2864 addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2865 }
2866
2867 word1 = change_address (src, SImode, addr1);
2868 word2 = change_address (src, SImode, addr2);
2869
2870 if (BYTES_BIG_ENDIAN)
2871 {
2872 emit_insn (gen_bswapsi2 (op3_32, word2));
2873 emit_insn (gen_bswapsi2 (dest_32, word1));
2874 }
2875 else
2876 {
2877 emit_insn (gen_bswapsi2 (op3_32, word1));
2878 emit_insn (gen_bswapsi2 (dest_32, word2));
2879 }
2880
2881 emit_insn (gen_rotldi3_insert_3 (dest, op3, GEN_INT (32), dest,
2882 GEN_INT (0xffffffff)));
2883 DONE;
2884 })
2885
2886 (define_split
2887 [(set (match_operand:DI 0 "indexed_or_indirect_operand")
2888 (bswap:DI (match_operand:DI 1 "gpc_reg_operand")))
2889 (clobber (match_operand:DI 2 "gpc_reg_operand"))
2890 (clobber (match_operand:DI 3 "gpc_reg_operand"))]
2891 "TARGET_POWERPC64 && !TARGET_LDBRX && reload_completed"
2892 [(const_int 0)]
2893 {
2894 rtx dest = operands[0];
2895 rtx src = operands[1];
2896 rtx op2 = operands[2];
2897 rtx op3 = operands[3];
2898 rtx src_si = simplify_gen_subreg (SImode, src, DImode,
2899 BYTES_BIG_ENDIAN ? 4 : 0);
2900 rtx op3_si = simplify_gen_subreg (SImode, op3, DImode,
2901 BYTES_BIG_ENDIAN ? 4 : 0);
2902 rtx addr1;
2903 rtx addr2;
2904 rtx word1;
2905 rtx word2;
2906
2907 addr1 = XEXP (dest, 0);
2908 if (GET_CODE (addr1) == PLUS)
2909 {
2910 emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
2911 if (TARGET_AVOID_XFORM)
2912 {
2913 emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
2914 addr2 = op2;
2915 }
2916 else
2917 addr2 = gen_rtx_PLUS (Pmode, op2, XEXP (addr1, 1));
2918 }
2919 else if (TARGET_AVOID_XFORM)
2920 {
2921 emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
2922 addr2 = op2;
2923 }
2924 else
2925 {
2926 emit_move_insn (op2, GEN_INT (4));
2927 addr2 = gen_rtx_PLUS (Pmode, op2, addr1);
2928 }
2929
2930 word1 = change_address (dest, SImode, addr1);
2931 word2 = change_address (dest, SImode, addr2);
2932
2933 emit_insn (gen_lshrdi3 (op3, src, GEN_INT (32)));
2934
2935 if (BYTES_BIG_ENDIAN)
2936 {
2937 emit_insn (gen_bswapsi2 (word1, src_si));
2938 emit_insn (gen_bswapsi2 (word2, op3_si));
2939 }
2940 else
2941 {
2942 emit_insn (gen_bswapsi2 (word2, src_si));
2943 emit_insn (gen_bswapsi2 (word1, op3_si));
2944 }
2945 DONE;
2946 })
2947
2948 (define_split
2949 [(set (match_operand:DI 0 "gpc_reg_operand")
2950 (bswap:DI (match_operand:DI 1 "gpc_reg_operand")))
2951 (clobber (match_operand:DI 2 "gpc_reg_operand"))
2952 (clobber (match_operand:DI 3 "gpc_reg_operand"))]
2953 "TARGET_POWERPC64 && !TARGET_P9_VECTOR && reload_completed"
2954 [(const_int 0)]
2955 {
2956 rtx dest = operands[0];
2957 rtx src = operands[1];
2958 rtx op2 = operands[2];
2959 rtx op3 = operands[3];
2960 int lo_off = BYTES_BIG_ENDIAN ? 4 : 0;
2961 rtx dest_si = simplify_gen_subreg (SImode, dest, DImode, lo_off);
2962 rtx src_si = simplify_gen_subreg (SImode, src, DImode, lo_off);
2963 rtx op2_si = simplify_gen_subreg (SImode, op2, DImode, lo_off);
2964 rtx op3_si = simplify_gen_subreg (SImode, op3, DImode, lo_off);
2965
2966 emit_insn (gen_lshrdi3 (op2, src, GEN_INT (32)));
2967 emit_insn (gen_bswapsi2 (op3_si, src_si));
2968 emit_insn (gen_bswapsi2 (dest_si, op2_si));
2969 emit_insn (gen_rotldi3_insert_3 (dest, op3, GEN_INT (32), dest,
2970 GEN_INT (0xffffffff)));
2971 DONE;
2972 })
2973
2974 (define_insn "bswapdi2_32bit"
2975 [(set (match_operand:DI 0 "reg_or_mem_operand" "=r,Z,?&r")
2976 (bswap:DI (match_operand:DI 1 "reg_or_mem_operand" "Z,r,r")))
2977 (clobber (match_scratch:SI 2 "=&b,&b,X"))]
2978 "!TARGET_POWERPC64 && (REG_P (operands[0]) || REG_P (operands[1]))"
2979 "#"
2980 [(set_attr "length" "16,12,36")])
2981
2982 (define_split
2983 [(set (match_operand:DI 0 "gpc_reg_operand")
2984 (bswap:DI (match_operand:DI 1 "indexed_or_indirect_operand")))
2985 (clobber (match_operand:SI 2 "gpc_reg_operand"))]
2986 "!TARGET_POWERPC64 && reload_completed"
2987 [(const_int 0)]
2988 {
2989 rtx dest = operands[0];
2990 rtx src = operands[1];
2991 rtx op2 = operands[2];
2992 rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
2993 rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
2994 rtx addr1;
2995 rtx addr2;
2996 rtx word1;
2997 rtx word2;
2998
2999 addr1 = XEXP (src, 0);
3000 if (GET_CODE (addr1) == PLUS)
3001 {
3002 emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
3003 if (TARGET_AVOID_XFORM
3004 || REGNO (XEXP (addr1, 1)) == REGNO (dest2))
3005 {
3006 emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
3007 addr2 = op2;
3008 }
3009 else
3010 addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
3011 }
3012 else if (TARGET_AVOID_XFORM
3013 || REGNO (addr1) == REGNO (dest2))
3014 {
3015 emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
3016 addr2 = op2;
3017 }
3018 else
3019 {
3020 emit_move_insn (op2, GEN_INT (4));
3021 addr2 = gen_rtx_PLUS (SImode, op2, addr1);
3022 }
3023
3024 word1 = change_address (src, SImode, addr1);
3025 word2 = change_address (src, SImode, addr2);
3026
3027 emit_insn (gen_bswapsi2 (dest2, word1));
3028 /* The REGNO (dest2) tests above ensure that addr2 has not been trashed,
3029 thus allowing us to omit an early clobber on the output. */
3030 emit_insn (gen_bswapsi2 (dest1, word2));
3031 DONE;
3032 })
3033
3034 (define_split
3035 [(set (match_operand:DI 0 "indexed_or_indirect_operand")
3036 (bswap:DI (match_operand:DI 1 "gpc_reg_operand")))
3037 (clobber (match_operand:SI 2 "gpc_reg_operand"))]
3038 "!TARGET_POWERPC64 && reload_completed"
3039 [(const_int 0)]
3040 {
3041 rtx dest = operands[0];
3042 rtx src = operands[1];
3043 rtx op2 = operands[2];
3044 rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
3045 rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
3046 rtx addr1;
3047 rtx addr2;
3048 rtx word1;
3049 rtx word2;
3050
3051 addr1 = XEXP (dest, 0);
3052 if (GET_CODE (addr1) == PLUS)
3053 {
3054 emit_insn (gen_add3_insn (op2, XEXP (addr1, 0), GEN_INT (4)));
3055 if (TARGET_AVOID_XFORM)
3056 {
3057 emit_insn (gen_add3_insn (op2, XEXP (addr1, 1), op2));
3058 addr2 = op2;
3059 }
3060 else
3061 addr2 = gen_rtx_PLUS (SImode, op2, XEXP (addr1, 1));
3062 }
3063 else if (TARGET_AVOID_XFORM)
3064 {
3065 emit_insn (gen_add3_insn (op2, addr1, GEN_INT (4)));
3066 addr2 = op2;
3067 }
3068 else
3069 {
3070 emit_move_insn (op2, GEN_INT (4));
3071 addr2 = gen_rtx_PLUS (SImode, op2, addr1);
3072 }
3073
3074 word1 = change_address (dest, SImode, addr1);
3075 word2 = change_address (dest, SImode, addr2);
3076
3077 emit_insn (gen_bswapsi2 (word2, src1));
3078 emit_insn (gen_bswapsi2 (word1, src2));
3079 DONE;
3080 })
3081
3082 (define_split
3083 [(set (match_operand:DI 0 "gpc_reg_operand")
3084 (bswap:DI (match_operand:DI 1 "gpc_reg_operand")))
3085 (clobber (match_operand:SI 2 ""))]
3086 "!TARGET_POWERPC64 && reload_completed"
3087 [(const_int 0)]
3088 {
3089 rtx dest = operands[0];
3090 rtx src = operands[1];
3091 rtx src1 = simplify_gen_subreg (SImode, src, DImode, 0);
3092 rtx src2 = simplify_gen_subreg (SImode, src, DImode, 4);
3093 rtx dest1 = simplify_gen_subreg (SImode, dest, DImode, 0);
3094 rtx dest2 = simplify_gen_subreg (SImode, dest, DImode, 4);
3095
3096 emit_insn (gen_bswapsi2 (dest1, src2));
3097 emit_insn (gen_bswapsi2 (dest2, src1));
3098 DONE;
3099 })
3100
3101
3102 (define_insn "mul<mode>3"
3103 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3104 (mult:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3105 (match_operand:GPR 2 "reg_or_short_operand" "r,I")))]
3106 ""
3107 "@
3108 mull<wd> %0,%1,%2
3109 mulli %0,%1,%2"
3110 [(set_attr "type" "mul")
3111 (set (attr "size")
3112 (cond [(match_operand:GPR 2 "s8bit_cint_operand")
3113 (const_string "8")
3114 (match_operand:GPR 2 "short_cint_operand")
3115 (const_string "16")]
3116 (const_string "<bits>")))])
3117
3118 (define_insn_and_split "*mul<mode>3_dot"
3119 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3120 (compare:CC (mult:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3121 (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
3122 (const_int 0)))
3123 (clobber (match_scratch:GPR 0 "=r,r"))]
3124 "<MODE>mode == Pmode"
3125 "@
3126 mull<wd>. %0,%1,%2
3127 #"
3128 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3129 [(set (match_dup 0)
3130 (mult:GPR (match_dup 1)
3131 (match_dup 2)))
3132 (set (match_dup 3)
3133 (compare:CC (match_dup 0)
3134 (const_int 0)))]
3135 ""
3136 [(set_attr "type" "mul")
3137 (set_attr "size" "<bits>")
3138 (set_attr "dot" "yes")
3139 (set_attr "length" "4,8")])
3140
3141 (define_insn_and_split "*mul<mode>3_dot2"
3142 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3143 (compare:CC (mult:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3144 (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
3145 (const_int 0)))
3146 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3147 (mult:GPR (match_dup 1)
3148 (match_dup 2)))]
3149 "<MODE>mode == Pmode"
3150 "@
3151 mull<wd>. %0,%1,%2
3152 #"
3153 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3154 [(set (match_dup 0)
3155 (mult:GPR (match_dup 1)
3156 (match_dup 2)))
3157 (set (match_dup 3)
3158 (compare:CC (match_dup 0)
3159 (const_int 0)))]
3160 ""
3161 [(set_attr "type" "mul")
3162 (set_attr "size" "<bits>")
3163 (set_attr "dot" "yes")
3164 (set_attr "length" "4,8")])
3165
3166
3167 (define_expand "<su>mul<mode>3_highpart"
3168 [(set (match_operand:GPR 0 "gpc_reg_operand")
3169 (subreg:GPR
3170 (mult:<DMODE> (any_extend:<DMODE>
3171 (match_operand:GPR 1 "gpc_reg_operand"))
3172 (any_extend:<DMODE>
3173 (match_operand:GPR 2 "gpc_reg_operand")))
3174 0))]
3175 ""
3176 {
3177 if (<MODE>mode == SImode && TARGET_POWERPC64)
3178 {
3179 emit_insn (gen_<su>mulsi3_highpart_64 (operands[0], operands[1],
3180 operands[2]));
3181 DONE;
3182 }
3183
3184 if (!WORDS_BIG_ENDIAN)
3185 {
3186 emit_insn (gen_<su>mul<mode>3_highpart_le (operands[0], operands[1],
3187 operands[2]));
3188 DONE;
3189 }
3190 })
3191
3192 (define_insn "*<su>mul<mode>3_highpart"
3193 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3194 (subreg:GPR
3195 (mult:<DMODE> (any_extend:<DMODE>
3196 (match_operand:GPR 1 "gpc_reg_operand" "r"))
3197 (any_extend:<DMODE>
3198 (match_operand:GPR 2 "gpc_reg_operand" "r")))
3199 0))]
3200 "WORDS_BIG_ENDIAN && !(<MODE>mode == SImode && TARGET_POWERPC64)"
3201 "mulh<wd><u> %0,%1,%2"
3202 [(set_attr "type" "mul")
3203 (set_attr "size" "<bits>")])
3204
3205 (define_insn "<su>mulsi3_highpart_le"
3206 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3207 (subreg:SI
3208 (mult:DI (any_extend:DI
3209 (match_operand:SI 1 "gpc_reg_operand" "r"))
3210 (any_extend:DI
3211 (match_operand:SI 2 "gpc_reg_operand" "r")))
3212 4))]
3213 "!WORDS_BIG_ENDIAN && !TARGET_POWERPC64"
3214 "mulhw<u> %0,%1,%2"
3215 [(set_attr "type" "mul")])
3216
3217 (define_insn "<su>muldi3_highpart_le"
3218 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3219 (subreg:DI
3220 (mult:TI (any_extend:TI
3221 (match_operand:DI 1 "gpc_reg_operand" "r"))
3222 (any_extend:TI
3223 (match_operand:DI 2 "gpc_reg_operand" "r")))
3224 8))]
3225 "!WORDS_BIG_ENDIAN && TARGET_POWERPC64"
3226 "mulhd<u> %0,%1,%2"
3227 [(set_attr "type" "mul")
3228 (set_attr "size" "64")])
3229
3230 (define_insn "<su>mulsi3_highpart_64"
3231 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3232 (truncate:SI
3233 (lshiftrt:DI
3234 (mult:DI (any_extend:DI
3235 (match_operand:SI 1 "gpc_reg_operand" "r"))
3236 (any_extend:DI
3237 (match_operand:SI 2 "gpc_reg_operand" "r")))
3238 (const_int 32))))]
3239 "TARGET_POWERPC64"
3240 "mulhw<u> %0,%1,%2"
3241 [(set_attr "type" "mul")])
3242
3243 (define_expand "<u>mul<mode><dmode>3"
3244 [(set (match_operand:<DMODE> 0 "gpc_reg_operand")
3245 (mult:<DMODE> (any_extend:<DMODE>
3246 (match_operand:GPR 1 "gpc_reg_operand"))
3247 (any_extend:<DMODE>
3248 (match_operand:GPR 2 "gpc_reg_operand"))))]
3249 "!(<MODE>mode == SImode && TARGET_POWERPC64)"
3250 {
3251 rtx l = gen_reg_rtx (<MODE>mode);
3252 rtx h = gen_reg_rtx (<MODE>mode);
3253 emit_insn (gen_mul<mode>3 (l, operands[1], operands[2]));
3254 emit_insn (gen_<su>mul<mode>3_highpart (h, operands[1], operands[2]));
3255 emit_move_insn (gen_lowpart (<MODE>mode, operands[0]), l);
3256 emit_move_insn (gen_highpart (<MODE>mode, operands[0]), h);
3257 DONE;
3258 })
3259
3260 (define_insn "maddld<mode>4"
3261 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3262 (plus:GPR (mult:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3263 (match_operand:GPR 2 "gpc_reg_operand" "r"))
3264 (match_operand:GPR 3 "gpc_reg_operand" "r")))]
3265 "TARGET_MADDLD"
3266 "maddld %0,%1,%2,%3"
3267 [(set_attr "type" "mul")])
3268
3269 ;; umaddditi4 generally needs maddhdu + maddld + add instructions,
3270 ;; unless last operand is zero extended from DImode, then needs
3271 ;; maddhdu + maddld, which is both faster than mulld + mulhdu + addc + adde
3272 ;; resp. mulld + mulhdu + addc + addze.
3273 ;; We don't define maddditi4, as that one needs
3274 ;; maddhd + sradi + maddld + add + sub and for last operand sign extended
3275 ;; from DImode nothing is able to optimize it into maddhd + maddld, while
3276 ;; without maddditi4 mulld + mulhd + addc + adde or
3277 ;; mulld + mulhd + sradi + addc + adde is needed. See PR108787.
3278 (define_expand "umaddditi4"
3279 [(set (match_operand:TI 0 "gpc_reg_operand")
3280 (plus:TI
3281 (mult:TI (zero_extend:TI (match_operand:DI 1 "gpc_reg_operand"))
3282 (zero_extend:TI (match_operand:DI 2 "gpc_reg_operand")))
3283 (match_operand:TI 3 "gpc_reg_operand")))]
3284 "TARGET_MADDLD && TARGET_POWERPC64"
3285 {
3286 rtx op0_lo = gen_rtx_SUBREG (DImode, operands[0], BYTES_BIG_ENDIAN ? 8 : 0);
3287 rtx op0_hi = gen_rtx_SUBREG (DImode, operands[0], BYTES_BIG_ENDIAN ? 0 : 8);
3288 rtx op3_lo = gen_rtx_SUBREG (DImode, operands[3], BYTES_BIG_ENDIAN ? 8 : 0);
3289 rtx op3_hi = gen_rtx_SUBREG (DImode, operands[3], BYTES_BIG_ENDIAN ? 0 : 8);
3290 rtx hi_temp = gen_reg_rtx (DImode);
3291
3292 if (BYTES_BIG_ENDIAN)
3293 emit_insn (gen_umadddi4_highpart (hi_temp, operands[1], operands[2],
3294 op3_lo));
3295 else
3296 emit_insn (gen_umadddi4_highpart_le (hi_temp, operands[1], operands[2],
3297 op3_lo));
3298
3299 emit_insn (gen_maddlddi4 (op0_lo, operands[1], operands[2], op3_lo));
3300
3301 emit_insn (gen_adddi3 (op0_hi, hi_temp, op3_hi));
3302
3303 DONE;
3304 })
3305
3306 (define_insn "<u>madddi4_highpart"
3307 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3308 (subreg:DI
3309 (plus:TI
3310 (mult:TI (any_extend:TI (match_operand:DI 1 "gpc_reg_operand" "r"))
3311 (any_extend:TI (match_operand:DI 2 "gpc_reg_operand" "r")))
3312 (any_extend:TI (match_operand:DI 3 "gpc_reg_operand" "r")))
3313 0))]
3314 "TARGET_MADDLD && BYTES_BIG_ENDIAN && TARGET_POWERPC64"
3315 "maddhd<u> %0,%1,%2,%3"
3316 [(set_attr "type" "mul")])
3317
3318 (define_insn "<u>madddi4_highpart_le"
3319 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3320 (subreg:DI
3321 (plus:TI
3322 (mult:TI (any_extend:TI (match_operand:DI 1 "gpc_reg_operand" "r"))
3323 (any_extend:TI (match_operand:DI 2 "gpc_reg_operand" "r")))
3324 (any_extend:TI (match_operand:DI 3 "gpc_reg_operand" "r")))
3325 8))]
3326 "TARGET_MADDLD && !BYTES_BIG_ENDIAN && TARGET_POWERPC64"
3327 "maddhd<u> %0,%1,%2,%3"
3328 [(set_attr "type" "mul")])
3329
3330 (define_insn "udiv<mode>3"
3331 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3332 (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3333 (match_operand:GPR 2 "gpc_reg_operand" "r")))]
3334 ""
3335 "div<wd>u %0,%1,%2"
3336 [(set_attr "type" "div")
3337 (set_attr "size" "<bits>")])
3338
3339 (define_insn "udivti3"
3340 [(set (match_operand:TI 0 "altivec_register_operand" "=v")
3341 (udiv:TI (match_operand:TI 1 "altivec_register_operand" "v")
3342 (match_operand:TI 2 "altivec_register_operand" "v")))]
3343 "TARGET_POWER10 && TARGET_POWERPC64"
3344 "vdivuq %0,%1,%2"
3345 [(set_attr "type" "vecdiv")
3346 (set_attr "size" "128")])
3347
3348 ;; For powers of two we can do sra[wd]i/addze for divide and then adjust for
3349 ;; modulus. If it isn't a power of two, force operands into register and do
3350 ;; a normal divide.
3351 (define_expand "div<mode>3"
3352 [(set (match_operand:GPR 0 "gpc_reg_operand")
3353 (div:GPR (match_operand:GPR 1 "gpc_reg_operand")
3354 (match_operand:GPR 2 "reg_or_cint_operand")))]
3355 ""
3356 {
3357 if (CONST_INT_P (operands[2])
3358 && INTVAL (operands[2]) > 0
3359 && exact_log2 (INTVAL (operands[2])) >= 0)
3360 {
3361 emit_insn (gen_div<mode>3_sra (operands[0], operands[1], operands[2]));
3362 DONE;
3363 }
3364
3365 operands[2] = force_reg (<MODE>mode, operands[2]);
3366 })
3367
3368 (define_insn "*div<mode>3"
3369 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3370 (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3371 (match_operand:GPR 2 "gpc_reg_operand" "r")))]
3372 ""
3373 "div<wd> %0,%1,%2"
3374 [(set_attr "type" "div")
3375 (set_attr "size" "<bits>")])
3376
3377 (define_insn "div<mode>3_sra"
3378 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3379 (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
3380 (match_operand:GPR 2 "exact_log2_cint_operand" "N")))
3381 (clobber (reg:GPR CA_REGNO))]
3382 ""
3383 "sra<wd>i %0,%1,%p2\;addze %0,%0"
3384 [(set_attr "type" "two")
3385 (set_attr "length" "8")])
3386
3387 (define_insn_and_split "*div<mode>3_sra_dot"
3388 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3389 (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3390 (match_operand:GPR 2 "exact_log2_cint_operand" "N,N"))
3391 (const_int 0)))
3392 (clobber (match_scratch:GPR 0 "=r,r"))
3393 (clobber (reg:GPR CA_REGNO))]
3394 "<MODE>mode == Pmode"
3395 "@
3396 sra<wd>i %0,%1,%p2\;addze. %0,%0
3397 #"
3398 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3399 [(parallel [(set (match_dup 0)
3400 (div:GPR (match_dup 1)
3401 (match_dup 2)))
3402 (clobber (reg:GPR CA_REGNO))])
3403 (set (match_dup 3)
3404 (compare:CC (match_dup 0)
3405 (const_int 0)))]
3406 ""
3407 [(set_attr "type" "two")
3408 (set_attr "length" "8,12")
3409 (set_attr "cell_micro" "not")])
3410
3411 (define_insn_and_split "*div<mode>3_sra_dot2"
3412 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3413 (compare:CC (div:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3414 (match_operand:GPR 2 "exact_log2_cint_operand" "N,N"))
3415 (const_int 0)))
3416 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3417 (div:GPR (match_dup 1)
3418 (match_dup 2)))
3419 (clobber (reg:GPR CA_REGNO))]
3420 "<MODE>mode == Pmode"
3421 "@
3422 sra<wd>i %0,%1,%p2\;addze. %0,%0
3423 #"
3424 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3425 [(parallel [(set (match_dup 0)
3426 (div:GPR (match_dup 1)
3427 (match_dup 2)))
3428 (clobber (reg:GPR CA_REGNO))])
3429 (set (match_dup 3)
3430 (compare:CC (match_dup 0)
3431 (const_int 0)))]
3432 ""
3433 [(set_attr "type" "two")
3434 (set_attr "length" "8,12")
3435 (set_attr "cell_micro" "not")])
3436
3437 (define_insn "divti3"
3438 [(set (match_operand:TI 0 "altivec_register_operand" "=v")
3439 (div:TI (match_operand:TI 1 "altivec_register_operand" "v")
3440 (match_operand:TI 2 "altivec_register_operand" "v")))]
3441 "TARGET_POWER10 && TARGET_POWERPC64"
3442 "vdivsq %0,%1,%2"
3443 [(set_attr "type" "vecdiv")
3444 (set_attr "size" "128")])
3445
3446 (define_expand "mod<mode>3"
3447 [(set (match_operand:GPR 0 "gpc_reg_operand")
3448 (mod:GPR (match_operand:GPR 1 "gpc_reg_operand")
3449 (match_operand:GPR 2 "reg_or_cint_operand")))]
3450 ""
3451 {
3452 int i;
3453 rtx temp1;
3454 rtx temp2;
3455
3456 if (!CONST_INT_P (operands[2])
3457 || INTVAL (operands[2]) <= 0
3458 || (i = exact_log2 (INTVAL (operands[2]))) < 0)
3459 {
3460 if (!TARGET_MODULO)
3461 FAIL;
3462
3463 operands[2] = force_reg (<MODE>mode, operands[2]);
3464
3465 if (RS6000_DISABLE_SCALAR_MODULO)
3466 {
3467 temp1 = gen_reg_rtx (<MODE>mode);
3468 temp2 = gen_reg_rtx (<MODE>mode);
3469
3470 emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
3471 emit_insn (gen_mul<mode>3 (temp2, temp1, operands[2]));
3472 emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3473 DONE;
3474 }
3475 }
3476 else
3477 {
3478 temp1 = gen_reg_rtx (<MODE>mode);
3479 temp2 = gen_reg_rtx (<MODE>mode);
3480
3481 emit_insn (gen_div<mode>3 (temp1, operands[1], operands[2]));
3482 emit_insn (gen_ashl<mode>3 (temp2, temp1, GEN_INT (i)));
3483 emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3484 DONE;
3485 }
3486 })
3487
3488 ;; In order to enable using a peephole2 for combining div/mod to eliminate the
3489 ;; mod, prefer putting the result of mod into a different register
3490 (define_insn "*mod<mode>3"
3491 [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r,r")
3492 (mod:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3493 (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
3494 "TARGET_MODULO && !RS6000_DISABLE_SCALAR_MODULO"
3495 "mods<wd> %0,%1,%2"
3496 [(set_attr "type" "div")
3497 (set_attr "size" "<bits>")])
3498
3499 ;; This define_expand can be removed when RS6000_DISABLE_SCALAR_MODULO is
3500 ;; removed.
3501 (define_expand "umod<mode>3"
3502 [(set (match_operand:GPR 0 "gpc_reg_operand")
3503 (umod:GPR (match_operand:GPR 1 "gpc_reg_operand")
3504 (match_operand:GPR 2 "gpc_reg_operand")))]
3505 "TARGET_MODULO"
3506 {
3507 if (RS6000_DISABLE_SCALAR_MODULO)
3508 {
3509 rtx temp1 = gen_reg_rtx (<MODE>mode);
3510 rtx temp2 = gen_reg_rtx (<MODE>mode);
3511
3512 emit_insn (gen_udiv<mode>3 (temp1, operands[1], operands[2]));
3513 emit_insn (gen_mul<mode>3 (temp2, temp1, operands[2]));
3514 emit_insn (gen_sub<mode>3 (operands[0], operands[1], temp2));
3515 DONE;
3516 }
3517 })
3518
3519 (define_insn "*umod<mode>3"
3520 [(set (match_operand:GPR 0 "gpc_reg_operand" "=&r,r")
3521 (umod:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
3522 (match_operand:GPR 2 "gpc_reg_operand" "r,r")))]
3523 "TARGET_MODULO && !RS6000_DISABLE_SCALAR_MODULO"
3524 "modu<wd> %0,%1,%2"
3525 [(set_attr "type" "div")
3526 (set_attr "size" "<bits>")])
3527
3528 ;; On machines with modulo support, do a combined div/mod the old fashioned
3529 ;; method, since the multiply/subtract is faster than doing the mod instruction
3530 ;; after a divide.
3531
3532 (define_peephole2
3533 [(set (match_operand:GPR 0 "gpc_reg_operand")
3534 (div:GPR (match_operand:GPR 1 "gpc_reg_operand")
3535 (match_operand:GPR 2 "gpc_reg_operand")))
3536 (set (match_operand:GPR 3 "gpc_reg_operand")
3537 (mod:GPR (match_dup 1)
3538 (match_dup 2)))]
3539 "TARGET_MODULO
3540 && ! reg_mentioned_p (operands[0], operands[1])
3541 && ! reg_mentioned_p (operands[0], operands[2])
3542 && ! reg_mentioned_p (operands[3], operands[1])
3543 && ! reg_mentioned_p (operands[3], operands[2])"
3544 [(set (match_dup 0)
3545 (div:GPR (match_dup 1)
3546 (match_dup 2)))
3547 (set (match_dup 3)
3548 (mult:GPR (match_dup 0)
3549 (match_dup 2)))
3550 (set (match_dup 3)
3551 (minus:GPR (match_dup 1)
3552 (match_dup 3)))])
3553
3554 (define_peephole2
3555 [(set (match_operand:GPR 0 "gpc_reg_operand")
3556 (udiv:GPR (match_operand:GPR 1 "gpc_reg_operand")
3557 (match_operand:GPR 2 "gpc_reg_operand")))
3558 (set (match_operand:GPR 3 "gpc_reg_operand")
3559 (umod:GPR (match_dup 1)
3560 (match_dup 2)))]
3561 "TARGET_MODULO
3562 && ! reg_mentioned_p (operands[0], operands[1])
3563 && ! reg_mentioned_p (operands[0], operands[2])
3564 && ! reg_mentioned_p (operands[3], operands[1])
3565 && ! reg_mentioned_p (operands[3], operands[2])"
3566 [(set (match_dup 0)
3567 (udiv:GPR (match_dup 1)
3568 (match_dup 2)))
3569 (set (match_dup 3)
3570 (mult:GPR (match_dup 0)
3571 (match_dup 2)))
3572 (set (match_dup 3)
3573 (minus:GPR (match_dup 1)
3574 (match_dup 3)))])
3575
3576 (define_insn "umodti3"
3577 [(set (match_operand:TI 0 "altivec_register_operand" "=v")
3578 (umod:TI (match_operand:TI 1 "altivec_register_operand" "v")
3579 (match_operand:TI 2 "altivec_register_operand" "v")))]
3580 "TARGET_POWER10 && TARGET_POWERPC64 && !RS6000_DISABLE_SCALAR_MODULO"
3581 "vmoduq %0,%1,%2"
3582 [(set_attr "type" "vecdiv")
3583 (set_attr "size" "128")])
3584
3585 (define_insn "modti3"
3586 [(set (match_operand:TI 0 "altivec_register_operand" "=v")
3587 (mod:TI (match_operand:TI 1 "altivec_register_operand" "v")
3588 (match_operand:TI 2 "altivec_register_operand" "v")))]
3589 "TARGET_POWER10 && TARGET_POWERPC64 && !RS6000_DISABLE_SCALAR_MODULO"
3590 "vmodsq %0,%1,%2"
3591 [(set_attr "type" "vecdiv")
3592 (set_attr "size" "128")])
3593
3594 ;; Logical instructions
3595 ;; The logical instructions are mostly combined by using match_operator,
3596 ;; but the plain AND insns are somewhat different because there is no
3597 ;; plain 'andi' (only 'andi.'), no plain 'andis', and there are all
3598 ;; those rotate-and-mask operations. Thus, the AND insns come first.
3599
3600 (define_expand "and<mode>3"
3601 [(set (match_operand:SDI 0 "gpc_reg_operand")
3602 (and:SDI (match_operand:SDI 1 "gpc_reg_operand")
3603 (match_operand:SDI 2 "reg_or_cint_operand")))]
3604 ""
3605 {
3606 if (<MODE>mode == DImode && !TARGET_POWERPC64)
3607 {
3608 rs6000_split_logical (operands, AND, false, false, false);
3609 DONE;
3610 }
3611
3612 if (CONST_INT_P (operands[2]))
3613 {
3614 if (rs6000_is_valid_and_mask (operands[2], <MODE>mode))
3615 {
3616 emit_insn (gen_and<mode>3_mask (operands[0], operands[1], operands[2]));
3617 DONE;
3618 }
3619
3620 if (logical_const_operand (operands[2], <MODE>mode))
3621 {
3622 emit_insn (gen_and<mode>3_imm (operands[0], operands[1], operands[2]));
3623 DONE;
3624 }
3625
3626 if (rs6000_is_valid_2insn_and (operands[2], <MODE>mode))
3627 {
3628 rs6000_emit_2insn_and (<MODE>mode, operands, true, 0);
3629 DONE;
3630 }
3631
3632 operands[2] = force_reg (<MODE>mode, operands[2]);
3633 }
3634 })
3635
3636
3637 (define_insn "and<mode>3_imm"
3638 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3639 (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r")
3640 (match_operand:GPR 2 "logical_const_operand" "n")))
3641 (clobber (match_scratch:CC 3 "=x"))]
3642 "!rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3643 "andi%e2. %0,%1,%u2"
3644 [(set_attr "type" "logical")
3645 (set_attr "dot" "yes")])
3646
3647 (define_insn_and_split "*and<mode>3_imm_dot"
3648 [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
3649 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3650 (match_operand:GPR 2 "logical_const_operand" "n,n"))
3651 (const_int 0)))
3652 (clobber (match_scratch:GPR 0 "=r,r"))
3653 (clobber (match_scratch:CC 4 "=X,x"))]
3654 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3655 && !rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3656 "@
3657 andi%e2. %0,%1,%u2
3658 #"
3659 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3660 [(parallel [(set (match_dup 0)
3661 (and:GPR (match_dup 1)
3662 (match_dup 2)))
3663 (clobber (match_dup 4))])
3664 (set (match_dup 3)
3665 (compare:CC (match_dup 0)
3666 (const_int 0)))]
3667 ""
3668 [(set_attr "type" "logical")
3669 (set_attr "dot" "yes")
3670 (set_attr "length" "4,8")])
3671
3672 (define_insn_and_split "*and<mode>3_imm_dot2"
3673 [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
3674 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3675 (match_operand:GPR 2 "logical_const_operand" "n,n"))
3676 (const_int 0)))
3677 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3678 (and:GPR (match_dup 1)
3679 (match_dup 2)))
3680 (clobber (match_scratch:CC 4 "=X,x"))]
3681 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3682 && !rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3683 "@
3684 andi%e2. %0,%1,%u2
3685 #"
3686 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3687 [(parallel [(set (match_dup 0)
3688 (and:GPR (match_dup 1)
3689 (match_dup 2)))
3690 (clobber (match_dup 4))])
3691 (set (match_dup 3)
3692 (compare:CC (match_dup 0)
3693 (const_int 0)))]
3694 ""
3695 [(set_attr "type" "logical")
3696 (set_attr "dot" "yes")
3697 (set_attr "length" "4,8")])
3698
3699 (define_insn_and_split "*and<mode>3_imm_mask_dot"
3700 [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
3701 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3702 (match_operand:GPR 2 "logical_const_operand" "n,n"))
3703 (const_int 0)))
3704 (clobber (match_scratch:GPR 0 "=r,r"))]
3705 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3706 && rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3707 "@
3708 andi%e2. %0,%1,%u2
3709 #"
3710 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3711 [(set (match_dup 0)
3712 (and:GPR (match_dup 1)
3713 (match_dup 2)))
3714 (set (match_dup 3)
3715 (compare:CC (match_dup 0)
3716 (const_int 0)))]
3717 ""
3718 [(set_attr "type" "logical")
3719 (set_attr "dot" "yes")
3720 (set_attr "length" "4,8")])
3721
3722 (define_insn_and_split "*and<mode>3_imm_mask_dot2"
3723 [(set (match_operand:CC 3 "cc_reg_operand" "=x,??y")
3724 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3725 (match_operand:GPR 2 "logical_const_operand" "n,n"))
3726 (const_int 0)))
3727 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3728 (and:GPR (match_dup 1)
3729 (match_dup 2)))]
3730 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3731 && rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3732 "@
3733 andi%e2. %0,%1,%u2
3734 #"
3735 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3736 [(set (match_dup 0)
3737 (and:GPR (match_dup 1)
3738 (match_dup 2)))
3739 (set (match_dup 3)
3740 (compare:CC (match_dup 0)
3741 (const_int 0)))]
3742 ""
3743 [(set_attr "type" "logical")
3744 (set_attr "dot" "yes")
3745 (set_attr "length" "4,8")])
3746
3747 (define_insn "*and<mode>3_imm_dot_shifted"
3748 [(set (match_operand:CC 3 "cc_reg_operand" "=x")
3749 (compare:CC
3750 (and:GPR
3751 (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r")
3752 (match_operand:SI 4 "const_int_operand" "n"))
3753 (match_operand:GPR 2 "const_int_operand" "n"))
3754 (const_int 0)))
3755 (clobber (match_scratch:GPR 0 "=r"))]
3756 "logical_const_operand (GEN_INT (UINTVAL (operands[2])
3757 << INTVAL (operands[4])),
3758 DImode)
3759 && (<MODE>mode == Pmode
3760 || (UINTVAL (operands[2]) << INTVAL (operands[4])) <= 0x7fffffff)"
3761 {
3762 operands[2] = GEN_INT (UINTVAL (operands[2]) << INTVAL (operands[4]));
3763 return "andi%e2. %0,%1,%u2";
3764 }
3765 [(set_attr "type" "logical")
3766 (set_attr "dot" "yes")])
3767
3768
3769 (define_insn "and<mode>3_mask"
3770 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3771 (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r")
3772 (match_operand:GPR 2 "const_int_operand" "n")))]
3773 "rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3774 {
3775 return rs6000_insn_for_and_mask (<MODE>mode, operands, false);
3776 }
3777 [(set_attr "type" "shift")])
3778
3779 (define_insn_and_split "*and<mode>3_mask_dot"
3780 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3781 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3782 (match_operand:GPR 2 "const_int_operand" "n,n"))
3783 (const_int 0)))
3784 (clobber (match_scratch:GPR 0 "=r,r"))]
3785 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3786 && !logical_const_operand (operands[2], <MODE>mode)
3787 && rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3788 {
3789 if (which_alternative == 0)
3790 return rs6000_insn_for_and_mask (<MODE>mode, operands, true);
3791 else
3792 return "#";
3793 }
3794 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3795 [(set (match_dup 0)
3796 (and:GPR (match_dup 1)
3797 (match_dup 2)))
3798 (set (match_dup 3)
3799 (compare:CC (match_dup 0)
3800 (const_int 0)))]
3801 ""
3802 [(set_attr "type" "shift")
3803 (set_attr "dot" "yes")
3804 (set_attr "length" "4,8")])
3805
3806 (define_insn_and_split "*and<mode>3_mask_dot2"
3807 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3808 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3809 (match_operand:GPR 2 "const_int_operand" "n,n"))
3810 (const_int 0)))
3811 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3812 (and:GPR (match_dup 1)
3813 (match_dup 2)))]
3814 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3815 && !logical_const_operand (operands[2], <MODE>mode)
3816 && rs6000_is_valid_and_mask (operands[2], <MODE>mode)"
3817 {
3818 if (which_alternative == 0)
3819 return rs6000_insn_for_and_mask (<MODE>mode, operands, true);
3820 else
3821 return "#";
3822 }
3823 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
3824 [(set (match_dup 0)
3825 (and:GPR (match_dup 1)
3826 (match_dup 2)))
3827 (set (match_dup 3)
3828 (compare:CC (match_dup 0)
3829 (const_int 0)))]
3830 ""
3831 [(set_attr "type" "shift")
3832 (set_attr "dot" "yes")
3833 (set_attr "length" "4,8")])
3834
3835
3836 (define_insn_and_split "*and<mode>3_2insn"
3837 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3838 (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r")
3839 (match_operand:GPR 2 "const_int_operand" "n")))]
3840 "rs6000_is_valid_2insn_and (operands[2], <MODE>mode)
3841 && !(rs6000_is_valid_and_mask (operands[2], <MODE>mode)
3842 || logical_const_operand (operands[2], <MODE>mode))"
3843 "#"
3844 "&& 1"
3845 [(pc)]
3846 {
3847 rs6000_emit_2insn_and (<MODE>mode, operands, false, 0);
3848 DONE;
3849 }
3850 [(set_attr "type" "shift")
3851 (set_attr "length" "8")])
3852
3853 (define_insn_and_split "*and<mode>3_2insn_dot"
3854 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3855 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3856 (match_operand:GPR 2 "const_int_operand" "n,n"))
3857 (const_int 0)))
3858 (clobber (match_scratch:GPR 0 "=r,r"))]
3859 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3860 && rs6000_is_valid_2insn_and (operands[2], <MODE>mode)
3861 && !(rs6000_is_valid_and_mask (operands[2], <MODE>mode)
3862 || logical_const_operand (operands[2], <MODE>mode))"
3863 "#"
3864 "&& reload_completed"
3865 [(pc)]
3866 {
3867 rs6000_emit_2insn_and (<MODE>mode, operands, false, 1);
3868 DONE;
3869 }
3870 [(set_attr "type" "shift")
3871 (set_attr "dot" "yes")
3872 (set_attr "length" "8,12")])
3873
3874 (define_insn_and_split "*and<mode>3_2insn_dot2"
3875 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
3876 (compare:CC (and:GPR (match_operand:GPR 1 "gpc_reg_operand" "%r,r")
3877 (match_operand:GPR 2 "const_int_operand" "n,n"))
3878 (const_int 0)))
3879 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
3880 (and:GPR (match_dup 1)
3881 (match_dup 2)))]
3882 "(<MODE>mode == Pmode || UINTVAL (operands[2]) <= 0x7fffffff)
3883 && rs6000_is_valid_2insn_and (operands[2], <MODE>mode)
3884 && !(rs6000_is_valid_and_mask (operands[2], <MODE>mode)
3885 || logical_const_operand (operands[2], <MODE>mode))"
3886 "#"
3887 "&& reload_completed"
3888 [(pc)]
3889 {
3890 rs6000_emit_2insn_and (<MODE>mode, operands, false, 2);
3891 DONE;
3892 }
3893 [(set_attr "type" "shift")
3894 (set_attr "dot" "yes")
3895 (set_attr "length" "8,12")])
3896
3897 (define_insn_and_split "*branch_anddi3_dot"
3898 [(set (pc)
3899 (if_then_else (eq (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
3900 (match_operand:DI 2 "const_int_operand" "n,n"))
3901 (const_int 0))
3902 (label_ref (match_operand 3 ""))
3903 (pc)))
3904 (clobber (match_scratch:DI 0 "=r,r"))
3905 (clobber (reg:CC CR0_REGNO))]
3906 "rs6000_is_valid_rotate_dot_mask (operands[2], DImode)
3907 && TARGET_POWERPC64"
3908 "#"
3909 "&& reload_completed"
3910 [(pc)]
3911 {
3912 int nb, ne;
3913 if (rs6000_is_valid_mask (operands[2], &nb, &ne, DImode)
3914 && nb >= ne
3915 && ne > 0)
3916 {
3917 unsigned HOST_WIDE_INT val = INTVAL (operands[2]);
3918 int shift = 63 - nb;
3919 rtx tmp = gen_rtx_ASHIFT (DImode, operands[1], GEN_INT (shift));
3920 tmp = gen_rtx_AND (DImode, tmp, GEN_INT (val << shift));
3921 rtx cr0 = gen_rtx_REG (CCmode, CR0_REGNO);
3922 rs6000_emit_dot_insn (operands[0], tmp, 1, cr0);
3923 rtx loc_ref = gen_rtx_LABEL_REF (VOIDmode, operands[3]);
3924 rtx cond = gen_rtx_EQ (CCEQmode, cr0, const0_rtx);
3925 rtx ite = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, loc_ref, pc_rtx);
3926 emit_jump_insn (gen_rtx_SET (pc_rtx, ite));
3927 DONE;
3928 }
3929 else
3930 FAIL;
3931 }
3932 [(set_attr "type" "shift")
3933 (set_attr "dot" "yes")
3934 (set_attr "length" "8,12")])
3935
3936 (define_expand "<code><mode>3"
3937 [(set (match_operand:SDI 0 "gpc_reg_operand")
3938 (iorxor:SDI (match_operand:SDI 1 "gpc_reg_operand")
3939 (match_operand:SDI 2 "reg_or_cint_operand")))]
3940 ""
3941 {
3942 if (<MODE>mode == DImode && !TARGET_POWERPC64)
3943 {
3944 rs6000_split_logical (operands, <CODE>, false, false, false);
3945 DONE;
3946 }
3947
3948 if (non_logical_cint_operand (operands[2], <MODE>mode))
3949 {
3950 rtx tmp = ((!can_create_pseudo_p ()
3951 || rtx_equal_p (operands[0], operands[1]))
3952 ? operands[0] : gen_reg_rtx (<MODE>mode));
3953
3954 HOST_WIDE_INT value = INTVAL (operands[2]);
3955 HOST_WIDE_INT lo = value & 0xffff;
3956 HOST_WIDE_INT hi = value - lo;
3957
3958 emit_insn (gen_<code><mode>3 (tmp, operands[1], GEN_INT (hi)));
3959 emit_insn (gen_<code><mode>3 (operands[0], tmp, GEN_INT (lo)));
3960 DONE;
3961 }
3962
3963 if (!reg_or_logical_cint_operand (operands[2], <MODE>mode))
3964 operands[2] = force_reg (<MODE>mode, operands[2]);
3965 })
3966
3967 (define_split
3968 [(set (match_operand:GPR 0 "gpc_reg_operand")
3969 (iorxor:GPR (match_operand:GPR 1 "gpc_reg_operand")
3970 (match_operand:GPR 2 "non_logical_cint_operand")))]
3971 ""
3972 [(set (match_dup 3)
3973 (iorxor:GPR (match_dup 1)
3974 (match_dup 4)))
3975 (set (match_dup 0)
3976 (iorxor:GPR (match_dup 3)
3977 (match_dup 5)))]
3978 {
3979 operands[3] = ((!can_create_pseudo_p ()
3980 || rtx_equal_p (operands[0], operands[1]))
3981 ? operands[0] : gen_reg_rtx (<MODE>mode));
3982
3983 HOST_WIDE_INT value = INTVAL (operands[2]);
3984 HOST_WIDE_INT lo = value & 0xffff;
3985 HOST_WIDE_INT hi = value - lo;
3986
3987 operands[4] = GEN_INT (hi);
3988 operands[5] = GEN_INT (lo);
3989 })
3990
3991 (define_insn "*bool<mode>3_imm"
3992 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
3993 (match_operator:GPR 3 "boolean_or_operator"
3994 [(match_operand:GPR 1 "gpc_reg_operand" "%r")
3995 (match_operand:GPR 2 "logical_const_operand" "n")]))]
3996 ""
3997 "%q3i%e2 %0,%1,%u2"
3998 [(set_attr "type" "logical")])
3999
4000 (define_insn "*bool<mode>3"
4001 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4002 (match_operator:GPR 3 "boolean_operator"
4003 [(match_operand:GPR 1 "gpc_reg_operand" "r")
4004 (match_operand:GPR 2 "gpc_reg_operand" "r")]))]
4005 ""
4006 "%q3 %0,%1,%2"
4007 [(set_attr "type" "logical")])
4008
4009 (define_insn_and_split "*bool<mode>3_dot"
4010 [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4011 (compare:CC (match_operator:GPR 3 "boolean_operator"
4012 [(match_operand:GPR 1 "gpc_reg_operand" "r,r")
4013 (match_operand:GPR 2 "gpc_reg_operand" "r,r")])
4014 (const_int 0)))
4015 (clobber (match_scratch:GPR 0 "=r,r"))]
4016 "<MODE>mode == Pmode"
4017 "@
4018 %q3. %0,%1,%2
4019 #"
4020 "&& reload_completed && cc_reg_not_cr0_operand (operands[4], CCmode)"
4021 [(set (match_dup 0)
4022 (match_dup 3))
4023 (set (match_dup 4)
4024 (compare:CC (match_dup 0)
4025 (const_int 0)))]
4026 ""
4027 [(set_attr "type" "logical")
4028 (set_attr "dot" "yes")
4029 (set_attr "length" "4,8")])
4030
4031 (define_insn_and_split "*bool<mode>3_dot2"
4032 [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4033 (compare:CC (match_operator:GPR 3 "boolean_operator"
4034 [(match_operand:GPR 1 "gpc_reg_operand" "r,r")
4035 (match_operand:GPR 2 "gpc_reg_operand" "r,r")])
4036 (const_int 0)))
4037 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4038 (match_dup 3))]
4039 "<MODE>mode == Pmode"
4040 "@
4041 %q3. %0,%1,%2
4042 #"
4043 "&& reload_completed && cc_reg_not_cr0_operand (operands[4], CCmode)"
4044 [(set (match_dup 0)
4045 (match_dup 3))
4046 (set (match_dup 4)
4047 (compare:CC (match_dup 0)
4048 (const_int 0)))]
4049 ""
4050 [(set_attr "type" "logical")
4051 (set_attr "dot" "yes")
4052 (set_attr "length" "4,8")])
4053
4054
4055 (define_insn "*boolc<mode>3"
4056 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4057 (match_operator:GPR 3 "boolean_operator"
4058 [(not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r"))
4059 (match_operand:GPR 1 "gpc_reg_operand" "r")]))]
4060 ""
4061 "%q3 %0,%1,%2"
4062 [(set_attr "type" "logical")])
4063
4064 (define_insn_and_split "*boolc<mode>3_dot"
4065 [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4066 (compare:CC (match_operator:GPR 3 "boolean_operator"
4067 [(not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
4068 (match_operand:GPR 1 "gpc_reg_operand" "r,r")])
4069 (const_int 0)))
4070 (clobber (match_scratch:GPR 0 "=r,r"))]
4071 "<MODE>mode == Pmode"
4072 "@
4073 %q3. %0,%1,%2
4074 #"
4075 "&& reload_completed && cc_reg_not_cr0_operand (operands[4], CCmode)"
4076 [(set (match_dup 0)
4077 (match_dup 3))
4078 (set (match_dup 4)
4079 (compare:CC (match_dup 0)
4080 (const_int 0)))]
4081 ""
4082 [(set_attr "type" "logical")
4083 (set_attr "dot" "yes")
4084 (set_attr "length" "4,8")])
4085
4086 (define_insn_and_split "*boolc<mode>3_dot2"
4087 [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4088 (compare:CC (match_operator:GPR 3 "boolean_operator"
4089 [(not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r"))
4090 (match_operand:GPR 1 "gpc_reg_operand" "r,r")])
4091 (const_int 0)))
4092 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4093 (match_dup 3))]
4094 "<MODE>mode == Pmode"
4095 "@
4096 %q3. %0,%1,%2
4097 #"
4098 "&& reload_completed && cc_reg_not_cr0_operand (operands[4], CCmode)"
4099 [(set (match_dup 0)
4100 (match_dup 3))
4101 (set (match_dup 4)
4102 (compare:CC (match_dup 0)
4103 (const_int 0)))]
4104 ""
4105 [(set_attr "type" "logical")
4106 (set_attr "dot" "yes")
4107 (set_attr "length" "4,8")])
4108
4109
4110 (define_insn "*boolcc<mode>3"
4111 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4112 (match_operator:GPR 3 "boolean_operator"
4113 [(not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r"))
4114 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r"))]))]
4115 ""
4116 "%q3 %0,%1,%2"
4117 [(set_attr "type" "logical")])
4118
4119 (define_insn_and_split "*boolcc<mode>3_dot"
4120 [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4121 (compare:CC (match_operator:GPR 3 "boolean_operator"
4122 [(not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
4123 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r"))])
4124 (const_int 0)))
4125 (clobber (match_scratch:GPR 0 "=r,r"))]
4126 "<MODE>mode == Pmode"
4127 "@
4128 %q3. %0,%1,%2
4129 #"
4130 "&& reload_completed && cc_reg_not_cr0_operand (operands[4], CCmode)"
4131 [(set (match_dup 0)
4132 (match_dup 3))
4133 (set (match_dup 4)
4134 (compare:CC (match_dup 0)
4135 (const_int 0)))]
4136 ""
4137 [(set_attr "type" "logical")
4138 (set_attr "dot" "yes")
4139 (set_attr "length" "4,8")])
4140
4141 (define_insn_and_split "*boolcc<mode>3_dot2"
4142 [(set (match_operand:CC 4 "cc_reg_operand" "=x,?y")
4143 (compare:CC (match_operator:GPR 3 "boolean_operator"
4144 [(not:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r"))
4145 (not:GPR (match_operand:GPR 2 "gpc_reg_operand" "r,r"))])
4146 (const_int 0)))
4147 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4148 (match_dup 3))]
4149 "<MODE>mode == Pmode"
4150 "@
4151 %q3. %0,%1,%2
4152 #"
4153 "&& reload_completed && cc_reg_not_cr0_operand (operands[4], CCmode)"
4154 [(set (match_dup 0)
4155 (match_dup 3))
4156 (set (match_dup 4)
4157 (compare:CC (match_dup 0)
4158 (const_int 0)))]
4159 ""
4160 [(set_attr "type" "logical")
4161 (set_attr "dot" "yes")
4162 (set_attr "length" "4,8")])
4163
4164
4165 ;; TODO: Should have dots of this as well.
4166 (define_insn "*eqv<mode>3"
4167 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4168 (not:GPR (xor:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4169 (match_operand:GPR 2 "gpc_reg_operand" "r"))))]
4170 ""
4171 "eqv %0,%1,%2"
4172 [(set_attr "type" "logical")])
4173
4174 ;; Rotate-and-mask and insert.
4175
4176 (define_insn "*rotl<mode>3_mask"
4177 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4178 (and:GPR (match_operator:GPR 4 "rotate_mask_operator"
4179 [(match_operand:GPR 1 "gpc_reg_operand" "r")
4180 (match_operand:SI 2 "reg_or_cint_operand" "rn")])
4181 (match_operand:GPR 3 "const_int_operand" "n")))]
4182 "rs6000_is_valid_shift_mask (operands[3], operands[4], <MODE>mode)"
4183 {
4184 return rs6000_insn_for_shift_mask (<MODE>mode, operands, false);
4185 }
4186 [(set_attr "type" "shift")
4187 (set_attr "maybe_var_shift" "yes")])
4188
4189 (define_insn_and_split "*rotl<mode>3_mask_dot"
4190 [(set (match_operand:CC 5 "cc_reg_operand" "=x,?y")
4191 (compare:CC
4192 (and:GPR (match_operator:GPR 4 "rotate_mask_operator"
4193 [(match_operand:GPR 1 "gpc_reg_operand" "r,r")
4194 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn")])
4195 (match_operand:GPR 3 "const_int_operand" "n,n"))
4196 (const_int 0)))
4197 (clobber (match_scratch:GPR 0 "=r,r"))]
4198 "(<MODE>mode == Pmode || UINTVAL (operands[3]) <= 0x7fffffff)
4199 && rs6000_is_valid_shift_mask (operands[3], operands[4], <MODE>mode)"
4200 {
4201 if (which_alternative == 0)
4202 return rs6000_insn_for_shift_mask (<MODE>mode, operands, true);
4203 else
4204 return "#";
4205 }
4206 "&& reload_completed && cc_reg_not_cr0_operand (operands[5], CCmode)"
4207 [(set (match_dup 0)
4208 (and:GPR (match_dup 4)
4209 (match_dup 3)))
4210 (set (match_dup 5)
4211 (compare:CC (match_dup 0)
4212 (const_int 0)))]
4213 ""
4214 [(set_attr "type" "shift")
4215 (set_attr "maybe_var_shift" "yes")
4216 (set_attr "dot" "yes")
4217 (set_attr "length" "4,8")])
4218
4219 (define_insn_and_split "*rotl<mode>3_mask_dot2"
4220 [(set (match_operand:CC 5 "cc_reg_operand" "=x,?y")
4221 (compare:CC
4222 (and:GPR (match_operator:GPR 4 "rotate_mask_operator"
4223 [(match_operand:GPR 1 "gpc_reg_operand" "r,r")
4224 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn")])
4225 (match_operand:GPR 3 "const_int_operand" "n,n"))
4226 (const_int 0)))
4227 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4228 (and:GPR (match_dup 4)
4229 (match_dup 3)))]
4230 "(<MODE>mode == Pmode || UINTVAL (operands[3]) <= 0x7fffffff)
4231 && rs6000_is_valid_shift_mask (operands[3], operands[4], <MODE>mode)"
4232 {
4233 if (which_alternative == 0)
4234 return rs6000_insn_for_shift_mask (<MODE>mode, operands, true);
4235 else
4236 return "#";
4237 }
4238 "&& reload_completed && cc_reg_not_cr0_operand (operands[5], CCmode)"
4239 [(set (match_dup 0)
4240 (and:GPR (match_dup 4)
4241 (match_dup 3)))
4242 (set (match_dup 5)
4243 (compare:CC (match_dup 0)
4244 (const_int 0)))]
4245 ""
4246 [(set_attr "type" "shift")
4247 (set_attr "maybe_var_shift" "yes")
4248 (set_attr "dot" "yes")
4249 (set_attr "length" "4,8")])
4250
4251 ; Special case for less-than-0. We can do it with just one machine
4252 ; instruction, but the generic optimizers do not realise it is cheap.
4253 (define_insn "*lt0_<mode>di"
4254 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4255 (lt:GPR (match_operand:DI 1 "gpc_reg_operand" "r")
4256 (const_int 0)))]
4257 "TARGET_POWERPC64"
4258 "srdi %0,%1,63"
4259 [(set_attr "type" "shift")])
4260
4261 (define_insn "*lt0_<mode>si"
4262 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4263 (lt:GPR (match_operand:SI 1 "gpc_reg_operand" "r")
4264 (const_int 0)))]
4265 ""
4266 "rlwinm %0,%1,1,31,31"
4267 [(set_attr "type" "shift")])
4268
4269
4270
4271 ; Two forms for insert (the two arms of the IOR are not canonicalized,
4272 ; both are an AND so are the same precedence).
4273 (define_insn "*rotl<mode>3_insert"
4274 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4275 (ior:GPR (and:GPR (match_operator:GPR 4 "rotate_mask_operator"
4276 [(match_operand:GPR 1 "gpc_reg_operand" "r")
4277 (match_operand:SI 2 "const_int_operand" "n")])
4278 (match_operand:GPR 3 "const_int_operand" "n"))
4279 (and:GPR (match_operand:GPR 5 "gpc_reg_operand" "0")
4280 (match_operand:GPR 6 "const_int_operand" "n"))))]
4281 "rs6000_is_valid_insert_mask (operands[3], operands[4], <MODE>mode)
4282 && UINTVAL (operands[3]) + UINTVAL (operands[6]) + 1 == 0"
4283 {
4284 return rs6000_insn_for_insert_mask (<MODE>mode, operands, false);
4285 }
4286 [(set_attr "type" "insert")])
4287 ; FIXME: this needs an attr "size", so that the scheduler can see the
4288 ; difference between rlwimi and rldimi. We also might want dot forms,
4289 ; but not for rlwimi on POWER4 and similar processors.
4290
4291 (define_insn "*rotl<mode>3_insert_2"
4292 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4293 (ior:GPR (and:GPR (match_operand:GPR 5 "gpc_reg_operand" "0")
4294 (match_operand:GPR 6 "const_int_operand" "n"))
4295 (and:GPR (match_operator:GPR 4 "rotate_mask_operator"
4296 [(match_operand:GPR 1 "gpc_reg_operand" "r")
4297 (match_operand:SI 2 "const_int_operand" "n")])
4298 (match_operand:GPR 3 "const_int_operand" "n"))))]
4299 "rs6000_is_valid_insert_mask (operands[3], operands[4], <MODE>mode)
4300 && UINTVAL (operands[3]) + UINTVAL (operands[6]) + 1 == 0"
4301 {
4302 return rs6000_insn_for_insert_mask (<MODE>mode, operands, false);
4303 }
4304 [(set_attr "type" "insert")])
4305
4306 ; There are also some forms without one of the ANDs.
4307 (define_insn "rotl<mode>3_insert_3"
4308 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4309 (ior:GPR (and:GPR (match_operand:GPR 3 "gpc_reg_operand" "0")
4310 (match_operand:GPR 4 "const_int_operand" "n"))
4311 (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4312 (match_operand:SI 2 "const_int_operand" "n"))))]
4313 "INTVAL (operands[2]) > 0
4314 && INTVAL (operands[2]) == exact_log2 (UINTVAL (operands[4]) + 1)"
4315 {
4316 if (<MODE>mode == SImode)
4317 return "rlwimi %0,%1,%h2,0,31-%h2";
4318 else
4319 return "rldimi %0,%1,%H2,0";
4320 }
4321 [(set_attr "type" "insert")])
4322
4323 ; Canonicalize the PLUS and XOR forms to IOR for rotl<mode>3_insert_3
4324 (define_code_iterator plus_xor [plus xor])
4325
4326 (define_insn_and_split "*rotl<mode>3_insert_3_<code>"
4327 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4328 (plus_xor:GPR
4329 (and:GPR (match_operand:GPR 3 "gpc_reg_operand" "0")
4330 (match_operand:GPR 4 "const_int_operand" "n"))
4331 (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4332 (match_operand:SI 2 "const_int_operand" "n"))))]
4333 "INTVAL (operands[2]) > 0
4334 && INTVAL (operands[2]) == exact_log2 (UINTVAL (operands[4]) + 1)"
4335 "#"
4336 "&& 1"
4337 [(set (match_dup 0)
4338 (ior:GPR (and:GPR (match_dup 3) (match_dup 4))
4339 (ashift:GPR (match_dup 1) (match_dup 2))))])
4340
4341 (define_code_iterator plus_ior_xor [plus ior xor])
4342
4343 (define_split
4344 [(set (match_operand:GPR 0 "gpc_reg_operand")
4345 (plus_ior_xor:GPR (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand")
4346 (match_operand:SI 2 "const_int_operand"))
4347 (match_operand:GPR 3 "gpc_reg_operand")))]
4348 "nonzero_bits (operands[3], <MODE>mode)
4349 < HOST_WIDE_INT_1U << INTVAL (operands[2])"
4350 [(set (match_dup 0)
4351 (ior:GPR (and:GPR (match_dup 3)
4352 (match_dup 4))
4353 (ashift:GPR (match_dup 1)
4354 (match_dup 2))))]
4355 {
4356 operands[4] = GEN_INT ((HOST_WIDE_INT_1U << INTVAL (operands[2])) - 1);
4357 })
4358
4359 (define_insn "*rotlsi3_insert_4"
4360 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
4361 (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "0")
4362 (match_operand:SI 4 "const_int_operand" "n"))
4363 (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4364 (match_operand:SI 2 "const_int_operand" "n"))))]
4365 "INTVAL (operands[2]) + exact_log2 (-UINTVAL (operands[4])) == 32"
4366 "rlwimi %0,%1,32-%h2,%h2,31"
4367 [(set_attr "type" "insert")])
4368
4369 (define_insn "*rotlsi3_insert_5"
4370 [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
4371 (ior:SI (and:SI (match_operand:SI 1 "gpc_reg_operand" "0,r")
4372 (match_operand:SI 2 "const_int_operand" "n,n"))
4373 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r,0")
4374 (match_operand:SI 4 "const_int_operand" "n,n"))))]
4375 "rs6000_is_valid_mask (operands[2], NULL, NULL, SImode)
4376 && UINTVAL (operands[2]) != 0 && UINTVAL (operands[4]) != 0
4377 && UINTVAL (operands[2]) + UINTVAL (operands[4]) + 1 == 0"
4378 "@
4379 rlwimi %0,%3,0,%4
4380 rlwimi %0,%1,0,%2"
4381 [(set_attr "type" "insert")])
4382
4383 (define_insn "*rotldi3_insert_6"
4384 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4385 (ior:DI (and:DI (match_operand:DI 1 "gpc_reg_operand" "0")
4386 (match_operand:DI 2 "const_int_operand" "n"))
4387 (and:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4388 (match_operand:DI 4 "const_int_operand" "n"))))]
4389 "exact_log2 (-UINTVAL (operands[2])) > 0
4390 && UINTVAL (operands[2]) + UINTVAL (operands[4]) + 1 == 0"
4391 {
4392 operands[5] = GEN_INT (64 - exact_log2 (-UINTVAL (operands[2])));
4393 return "rldimi %0,%3,0,%5";
4394 }
4395 [(set_attr "type" "insert")
4396 (set_attr "size" "64")])
4397
4398 (define_insn "*rotldi3_insert_7"
4399 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4400 (ior:DI (and:DI (match_operand:DI 3 "gpc_reg_operand" "r")
4401 (match_operand:DI 4 "const_int_operand" "n"))
4402 (and:DI (match_operand:DI 1 "gpc_reg_operand" "0")
4403 (match_operand:DI 2 "const_int_operand" "n"))))]
4404 "exact_log2 (-UINTVAL (operands[2])) > 0
4405 && UINTVAL (operands[2]) + UINTVAL (operands[4]) + 1 == 0"
4406 {
4407 operands[5] = GEN_INT (64 - exact_log2 (-UINTVAL (operands[2])));
4408 return "rldimi %0,%3,0,%5";
4409 }
4410 [(set_attr "type" "insert")
4411 (set_attr "size" "64")])
4412
4413
4414 ; This handles the important case of multiple-precision shifts. There is
4415 ; no canonicalization rule for ASHIFT vs. LSHIFTRT, so two patterns.
4416 (define_split
4417 [(set (match_operand:GPR 0 "gpc_reg_operand")
4418 (ior:GPR (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand")
4419 (match_operand:SI 3 "const_int_operand"))
4420 (lshiftrt:GPR (match_operand:GPR 2 "gpc_reg_operand")
4421 (match_operand:SI 4 "const_int_operand"))))]
4422 "can_create_pseudo_p ()
4423 && INTVAL (operands[3]) + INTVAL (operands[4])
4424 >= GET_MODE_PRECISION (<MODE>mode)"
4425 [(set (match_dup 5)
4426 (lshiftrt:GPR (match_dup 2)
4427 (match_dup 4)))
4428 (set (match_dup 0)
4429 (ior:GPR (and:GPR (match_dup 5)
4430 (match_dup 6))
4431 (ashift:GPR (match_dup 1)
4432 (match_dup 3))))]
4433 {
4434 unsigned HOST_WIDE_INT mask = 1;
4435 mask = (mask << INTVAL (operands[3])) - 1;
4436 operands[5] = gen_reg_rtx (<MODE>mode);
4437 operands[6] = GEN_INT (mask);
4438 })
4439
4440 (define_split
4441 [(set (match_operand:GPR 0 "gpc_reg_operand")
4442 (ior:GPR (lshiftrt:GPR (match_operand:GPR 2 "gpc_reg_operand")
4443 (match_operand:SI 4 "const_int_operand"))
4444 (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand")
4445 (match_operand:SI 3 "const_int_operand"))))]
4446 "can_create_pseudo_p ()
4447 && INTVAL (operands[3]) + INTVAL (operands[4])
4448 >= GET_MODE_PRECISION (<MODE>mode)"
4449 [(set (match_dup 5)
4450 (lshiftrt:GPR (match_dup 2)
4451 (match_dup 4)))
4452 (set (match_dup 0)
4453 (ior:GPR (and:GPR (match_dup 5)
4454 (match_dup 6))
4455 (ashift:GPR (match_dup 1)
4456 (match_dup 3))))]
4457 {
4458 unsigned HOST_WIDE_INT mask = 1;
4459 mask = (mask << INTVAL (operands[3])) - 1;
4460 operands[5] = gen_reg_rtx (<MODE>mode);
4461 operands[6] = GEN_INT (mask);
4462 })
4463
4464
4465 ; Another important case is setting some bits to 1; we can do that with
4466 ; an insert instruction, in many cases.
4467 (define_insn_and_split "*ior<mode>_mask"
4468 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4469 (ior:GPR (match_operand:GPR 1 "gpc_reg_operand" "0")
4470 (match_operand:GPR 2 "const_int_operand" "n")))
4471 (clobber (match_scratch:GPR 3 "=r"))]
4472 "!logical_const_operand (operands[2], <MODE>mode)
4473 && rs6000_is_valid_mask (operands[2], NULL, NULL, <MODE>mode)"
4474 "#"
4475 "&& 1"
4476 [(set (match_dup 3)
4477 (const_int -1))
4478 (set (match_dup 0)
4479 (ior:GPR (and:GPR (rotate:GPR (match_dup 3)
4480 (match_dup 4))
4481 (match_dup 2))
4482 (and:GPR (match_dup 1)
4483 (match_dup 5))))]
4484 {
4485 int nb, ne;
4486 rs6000_is_valid_mask (operands[2], &nb, &ne, <MODE>mode);
4487 if (GET_CODE (operands[3]) == SCRATCH)
4488 operands[3] = gen_reg_rtx (<MODE>mode);
4489 operands[4] = GEN_INT (ne);
4490 operands[5] = GEN_INT (~UINTVAL (operands[2]));
4491 }
4492 [(set_attr "type" "two")
4493 (set_attr "length" "8")])
4494
4495
4496 ; Yet another case is an rldimi with the second value coming from memory.
4497 ; The zero_extend that should become part of the rldimi is merged into the
4498 ; load from memory instead. Split things properly again.
4499 (define_split
4500 [(set (match_operand:DI 0 "gpc_reg_operand")
4501 (ior:DI (ashift:DI (match_operand:DI 1 "gpc_reg_operand")
4502 (match_operand:SI 2 "const_int_operand"))
4503 (zero_extend:DI (match_operand:QHSI 3 "memory_operand"))))]
4504 "INTVAL (operands[2]) == <bits>"
4505 [(set (match_dup 4)
4506 (zero_extend:DI (match_dup 3)))
4507 (set (match_dup 0)
4508 (ior:DI (and:DI (match_dup 4)
4509 (match_dup 5))
4510 (ashift:DI (match_dup 1)
4511 (match_dup 2))))]
4512 {
4513 operands[4] = gen_reg_rtx (DImode);
4514 operands[5] = GEN_INT ((HOST_WIDE_INT_1U << <bits>) - 1);
4515 })
4516
4517 ; rldimi with UNSPEC_SI_FROM_SF.
4518 (define_insn_and_split "*rotldi3_insert_sf"
4519 [(set (match_operand:DI 0 "gpc_reg_operand")
4520 (ior:DI
4521 (ashift:DI (match_operand:DI 1 "gpc_reg_operand")
4522 (match_operand:SI 2 "const_int_operand"))
4523 (zero_extend:DI
4524 (unspec:QHSI
4525 [(match_operand:SF 3 "memory_operand")]
4526 UNSPEC_SI_FROM_SF))))
4527 (clobber (match_scratch:V4SF 4))]
4528 "TARGET_POWERPC64 && INTVAL (operands[2]) == <bits>"
4529 "#"
4530 "&& 1"
4531 [(parallel [(set (match_dup 5)
4532 (zero_extend:DI (unspec:QHSI [(match_dup 3)] UNSPEC_SI_FROM_SF)))
4533 (clobber (match_dup 4))])
4534 (set (match_dup 0)
4535 (ior:DI
4536 (and:DI (match_dup 5) (match_dup 6))
4537 (ashift:DI (match_dup 1) (match_dup 2))))]
4538 {
4539 operands[5] = gen_reg_rtx (DImode);
4540 operands[6] = GEN_INT ((HOST_WIDE_INT_1U << <bits>) - 1);
4541 })
4542
4543 ; rlwimi, too.
4544 (define_split
4545 [(set (match_operand:SI 0 "gpc_reg_operand")
4546 (ior:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand")
4547 (match_operand:SI 2 "const_int_operand"))
4548 (zero_extend:SI (match_operand:QHI 3 "memory_operand"))))]
4549 "INTVAL (operands[2]) == <bits>"
4550 [(set (match_dup 4)
4551 (zero_extend:SI (match_dup 3)))
4552 (set (match_dup 0)
4553 (ior:SI (and:SI (match_dup 4)
4554 (match_dup 5))
4555 (ashift:SI (match_dup 1)
4556 (match_dup 2))))]
4557 {
4558 operands[4] = gen_reg_rtx (SImode);
4559 operands[5] = GEN_INT ((HOST_WIDE_INT_1U << <bits>) - 1);
4560 })
4561
4562
4563 ;; Now the simple shifts.
4564
4565 (define_insn "rotl<mode>3"
4566 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4567 (rotate:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4568 (match_operand:SI 2 "reg_or_cint_operand" "rn")))]
4569 ""
4570 "rotl<wd>%I2 %0,%1,%<hH>2"
4571 [(set_attr "type" "shift")
4572 (set_attr "maybe_var_shift" "yes")])
4573
4574 (define_insn "*rotlsi3_64"
4575 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4576 (zero_extend:DI
4577 (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4578 (match_operand:SI 2 "reg_or_cint_operand" "rn"))))]
4579 "TARGET_POWERPC64"
4580 "rotlw%I2 %0,%1,%h2"
4581 [(set_attr "type" "shift")
4582 (set_attr "maybe_var_shift" "yes")])
4583
4584 (define_insn_and_split "*rotl<mode>3_dot"
4585 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4586 (compare:CC (rotate:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4587 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4588 (const_int 0)))
4589 (clobber (match_scratch:GPR 0 "=r,r"))]
4590 "<MODE>mode == Pmode"
4591 "@
4592 rotl<wd>%I2. %0,%1,%<hH>2
4593 #"
4594 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4595 [(set (match_dup 0)
4596 (rotate:GPR (match_dup 1)
4597 (match_dup 2)))
4598 (set (match_dup 3)
4599 (compare:CC (match_dup 0)
4600 (const_int 0)))]
4601 ""
4602 [(set_attr "type" "shift")
4603 (set_attr "maybe_var_shift" "yes")
4604 (set_attr "dot" "yes")
4605 (set_attr "length" "4,8")])
4606
4607 (define_insn_and_split "*rotl<mode>3_dot2"
4608 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4609 (compare:CC (rotate:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4610 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4611 (const_int 0)))
4612 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4613 (rotate:GPR (match_dup 1)
4614 (match_dup 2)))]
4615 "<MODE>mode == Pmode"
4616 "@
4617 rotl<wd>%I2. %0,%1,%<hH>2
4618 #"
4619 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4620 [(set (match_dup 0)
4621 (rotate:GPR (match_dup 1)
4622 (match_dup 2)))
4623 (set (match_dup 3)
4624 (compare:CC (match_dup 0)
4625 (const_int 0)))]
4626 ""
4627 [(set_attr "type" "shift")
4628 (set_attr "maybe_var_shift" "yes")
4629 (set_attr "dot" "yes")
4630 (set_attr "length" "4,8")])
4631
4632
4633 (define_insn "ashl<mode>3"
4634 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4635 (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4636 (match_operand:SI 2 "reg_or_cint_operand" "rn")))]
4637 ""
4638 "sl<wd>%I2 %0,%1,%<hH>2"
4639 [(set_attr "type" "shift")
4640 (set_attr "maybe_var_shift" "yes")])
4641
4642 (define_insn "*ashlsi3_64"
4643 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4644 (zero_extend:DI
4645 (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4646 (match_operand:SI 2 "reg_or_cint_operand" "rn"))))]
4647 "TARGET_POWERPC64"
4648 "slw%I2 %0,%1,%h2"
4649 [(set_attr "type" "shift")
4650 (set_attr "maybe_var_shift" "yes")])
4651
4652 (define_insn_and_split "*ashl<mode>3_dot"
4653 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4654 (compare:CC (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4655 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4656 (const_int 0)))
4657 (clobber (match_scratch:GPR 0 "=r,r"))]
4658 "<MODE>mode == Pmode"
4659 "@
4660 sl<wd>%I2. %0,%1,%<hH>2
4661 #"
4662 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4663 [(set (match_dup 0)
4664 (ashift:GPR (match_dup 1)
4665 (match_dup 2)))
4666 (set (match_dup 3)
4667 (compare:CC (match_dup 0)
4668 (const_int 0)))]
4669 ""
4670 [(set_attr "type" "shift")
4671 (set_attr "maybe_var_shift" "yes")
4672 (set_attr "dot" "yes")
4673 (set_attr "length" "4,8")])
4674
4675 (define_insn_and_split "*ashl<mode>3_dot2"
4676 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4677 (compare:CC (ashift:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4678 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4679 (const_int 0)))
4680 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4681 (ashift:GPR (match_dup 1)
4682 (match_dup 2)))]
4683 "<MODE>mode == Pmode"
4684 "@
4685 sl<wd>%I2. %0,%1,%<hH>2
4686 #"
4687 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4688 [(set (match_dup 0)
4689 (ashift:GPR (match_dup 1)
4690 (match_dup 2)))
4691 (set (match_dup 3)
4692 (compare:CC (match_dup 0)
4693 (const_int 0)))]
4694 ""
4695 [(set_attr "type" "shift")
4696 (set_attr "maybe_var_shift" "yes")
4697 (set_attr "dot" "yes")
4698 (set_attr "length" "4,8")])
4699
4700 ;; Pretend we have a memory form of extswsli until register allocation is done
4701 ;; so that we use LWZ to load the value from memory, instead of LWA.
4702 (define_insn_and_split "ashdi3_extswsli"
4703 [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
4704 (ashift:DI
4705 (sign_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "r,m"))
4706 (match_operand:DI 2 "u6bit_cint_operand" "n,n")))]
4707 "TARGET_EXTSWSLI"
4708 "@
4709 extswsli %0,%1,%2
4710 #"
4711 "&& reload_completed && MEM_P (operands[1])"
4712 [(set (match_dup 3)
4713 (match_dup 1))
4714 (set (match_dup 0)
4715 (ashift:DI (sign_extend:DI (match_dup 3))
4716 (match_dup 2)))]
4717 {
4718 operands[3] = gen_lowpart (SImode, operands[0]);
4719 }
4720 [(set_attr "type" "shift")
4721 (set_attr "maybe_var_shift" "no")])
4722
4723
4724 (define_insn_and_split "ashdi3_extswsli_dot"
4725 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y,?x,??y")
4726 (compare:CC
4727 (ashift:DI
4728 (sign_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "r,r,m,m"))
4729 (match_operand:DI 2 "u6bit_cint_operand" "n,n,n,n"))
4730 (const_int 0)))
4731 (clobber (match_scratch:DI 0 "=r,r,r,r"))]
4732 "TARGET_EXTSWSLI"
4733 "@
4734 extswsli. %0,%1,%2
4735 #
4736 #
4737 #"
4738 "&& reload_completed
4739 && (cc_reg_not_cr0_operand (operands[3], CCmode)
4740 || memory_operand (operands[1], SImode))"
4741 [(pc)]
4742 {
4743 rtx dest = operands[0];
4744 rtx src = operands[1];
4745 rtx shift = operands[2];
4746 rtx cr = operands[3];
4747 rtx src2;
4748
4749 if (!MEM_P (src))
4750 src2 = src;
4751 else
4752 {
4753 src2 = gen_lowpart (SImode, dest);
4754 emit_move_insn (src2, src);
4755 }
4756
4757 if (REGNO (cr) == CR0_REGNO)
4758 {
4759 emit_insn (gen_ashdi3_extswsli_dot2 (dest, src2, shift, cr));
4760 DONE;
4761 }
4762
4763 emit_insn (gen_ashdi3_extswsli (dest, src2, shift));
4764 emit_insn (gen_rtx_SET (cr, gen_rtx_COMPARE (CCmode, dest, const0_rtx)));
4765 DONE;
4766 }
4767 [(set_attr "type" "shift")
4768 (set_attr "maybe_var_shift" "no")
4769 (set_attr "dot" "yes")
4770 (set_attr "length" "4,8,8,12")])
4771
4772 (define_insn_and_split "ashdi3_extswsli_dot2"
4773 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y,?x,??y")
4774 (compare:CC
4775 (ashift:DI
4776 (sign_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "r,r,m,m"))
4777 (match_operand:DI 2 "u6bit_cint_operand" "n,n,n,n"))
4778 (const_int 0)))
4779 (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,r")
4780 (ashift:DI (sign_extend:DI (match_dup 1))
4781 (match_dup 2)))]
4782 "TARGET_EXTSWSLI"
4783 "@
4784 extswsli. %0,%1,%2
4785 #
4786 #
4787 #"
4788 "&& reload_completed
4789 && (cc_reg_not_cr0_operand (operands[3], CCmode)
4790 || memory_operand (operands[1], SImode))"
4791 [(pc)]
4792 {
4793 rtx dest = operands[0];
4794 rtx src = operands[1];
4795 rtx shift = operands[2];
4796 rtx cr = operands[3];
4797 rtx src2;
4798
4799 if (!MEM_P (src))
4800 src2 = src;
4801 else
4802 {
4803 src2 = gen_lowpart (SImode, dest);
4804 emit_move_insn (src2, src);
4805 }
4806
4807 if (REGNO (cr) == CR0_REGNO)
4808 {
4809 emit_insn (gen_ashdi3_extswsli_dot2 (dest, src2, shift, cr));
4810 DONE;
4811 }
4812
4813 emit_insn (gen_ashdi3_extswsli (dest, src2, shift));
4814 emit_insn (gen_rtx_SET (cr, gen_rtx_COMPARE (CCmode, dest, const0_rtx)));
4815 DONE;
4816 }
4817 [(set_attr "type" "shift")
4818 (set_attr "maybe_var_shift" "no")
4819 (set_attr "dot" "yes")
4820 (set_attr "length" "4,8,8,12")])
4821
4822 (define_insn "lshr<mode>3"
4823 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4824 (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4825 (match_operand:SI 2 "reg_or_cint_operand" "rn")))]
4826 ""
4827 "sr<wd>%I2 %0,%1,%<hH>2"
4828 [(set_attr "type" "shift")
4829 (set_attr "maybe_var_shift" "yes")])
4830
4831 (define_insn "*lshrsi3_64"
4832 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4833 (zero_extend:DI
4834 (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4835 (match_operand:SI 2 "reg_or_cint_operand" "rn"))))]
4836 "TARGET_POWERPC64"
4837 "srw%I2 %0,%1,%h2"
4838 [(set_attr "type" "shift")
4839 (set_attr "maybe_var_shift" "yes")])
4840
4841 (define_insn_and_split "*lshr<mode>3_dot"
4842 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4843 (compare:CC (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4844 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4845 (const_int 0)))
4846 (clobber (match_scratch:GPR 0 "=r,r"))]
4847 "<MODE>mode == Pmode"
4848 "@
4849 sr<wd>%I2. %0,%1,%<hH>2
4850 #"
4851 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4852 [(set (match_dup 0)
4853 (lshiftrt:GPR (match_dup 1)
4854 (match_dup 2)))
4855 (set (match_dup 3)
4856 (compare:CC (match_dup 0)
4857 (const_int 0)))]
4858 ""
4859 [(set_attr "type" "shift")
4860 (set_attr "maybe_var_shift" "yes")
4861 (set_attr "dot" "yes")
4862 (set_attr "length" "4,8")])
4863
4864 (define_insn_and_split "*lshr<mode>3_dot2"
4865 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4866 (compare:CC (lshiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4867 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4868 (const_int 0)))
4869 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4870 (lshiftrt:GPR (match_dup 1)
4871 (match_dup 2)))]
4872 "<MODE>mode == Pmode"
4873 "@
4874 sr<wd>%I2. %0,%1,%<hH>2
4875 #"
4876 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4877 [(set (match_dup 0)
4878 (lshiftrt:GPR (match_dup 1)
4879 (match_dup 2)))
4880 (set (match_dup 3)
4881 (compare:CC (match_dup 0)
4882 (const_int 0)))]
4883 ""
4884 [(set_attr "type" "shift")
4885 (set_attr "maybe_var_shift" "yes")
4886 (set_attr "dot" "yes")
4887 (set_attr "length" "4,8")])
4888
4889
4890 (define_insn "ashr<mode>3"
4891 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
4892 (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
4893 (match_operand:SI 2 "reg_or_cint_operand" "rn")))
4894 (clobber (reg:GPR CA_REGNO))]
4895 ""
4896 "sra<wd>%I2 %0,%1,%<hH>2"
4897 [(set_attr "type" "shift")
4898 (set_attr "maybe_var_shift" "yes")])
4899
4900 (define_insn "*ashrsi3_64"
4901 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4902 (sign_extend:DI
4903 (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
4904 (match_operand:SI 2 "reg_or_cint_operand" "rn"))))
4905 (clobber (reg:SI CA_REGNO))]
4906 "TARGET_POWERPC64"
4907 "sraw%I2 %0,%1,%h2"
4908 [(set_attr "type" "shift")
4909 (set_attr "maybe_var_shift" "yes")])
4910
4911 (define_insn_and_split "*ashr<mode>3_dot"
4912 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4913 (compare:CC (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4914 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4915 (const_int 0)))
4916 (clobber (match_scratch:GPR 0 "=r,r"))
4917 (clobber (reg:GPR CA_REGNO))]
4918 "<MODE>mode == Pmode"
4919 "@
4920 sra<wd>%I2. %0,%1,%<hH>2
4921 #"
4922 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4923 [(parallel [(set (match_dup 0)
4924 (ashiftrt:GPR (match_dup 1)
4925 (match_dup 2)))
4926 (clobber (reg:GPR CA_REGNO))])
4927 (set (match_dup 3)
4928 (compare:CC (match_dup 0)
4929 (const_int 0)))]
4930 ""
4931 [(set_attr "type" "shift")
4932 (set_attr "maybe_var_shift" "yes")
4933 (set_attr "dot" "yes")
4934 (set_attr "length" "4,8")])
4935
4936 (define_insn_and_split "*ashr<mode>3_dot2"
4937 [(set (match_operand:CC 3 "cc_reg_operand" "=x,?y")
4938 (compare:CC (ashiftrt:GPR (match_operand:GPR 1 "gpc_reg_operand" "r,r")
4939 (match_operand:SI 2 "reg_or_cint_operand" "rn,rn"))
4940 (const_int 0)))
4941 (set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
4942 (ashiftrt:GPR (match_dup 1)
4943 (match_dup 2)))
4944 (clobber (reg:GPR CA_REGNO))]
4945 "<MODE>mode == Pmode"
4946 "@
4947 sra<wd>%I2. %0,%1,%<hH>2
4948 #"
4949 "&& reload_completed && cc_reg_not_cr0_operand (operands[3], CCmode)"
4950 [(parallel [(set (match_dup 0)
4951 (ashiftrt:GPR (match_dup 1)
4952 (match_dup 2)))
4953 (clobber (reg:GPR CA_REGNO))])
4954 (set (match_dup 3)
4955 (compare:CC (match_dup 0)
4956 (const_int 0)))]
4957 ""
4958 [(set_attr "type" "shift")
4959 (set_attr "maybe_var_shift" "yes")
4960 (set_attr "dot" "yes")
4961 (set_attr "length" "4,8")])
4962
4963 ;; Builtins to replace a division to generate FRE reciprocal estimate
4964 ;; instructions and the necessary fixup instructions
4965 (define_expand "recip<mode>3"
4966 [(match_operand:RECIPF 0 "gpc_reg_operand")
4967 (match_operand:RECIPF 1 "gpc_reg_operand")
4968 (match_operand:RECIPF 2 "gpc_reg_operand")]
4969 "RS6000_RECIP_HAVE_RE_P (<MODE>mode)"
4970 {
4971 rs6000_emit_swdiv (operands[0], operands[1], operands[2], false);
4972 DONE;
4973 })
4974
4975 ;; Split to create division from FRE/FRES/etc. and fixup instead of the normal
4976 ;; hardware division. This is only done before register allocation and with
4977 ;; -ffast-math. This must appear before the divsf3/divdf3 insns.
4978 ;; We used to also check optimize_insn_for_speed_p () but problems with guessed
4979 ;; frequencies (pr68212/pr77536) yields that unreliable so it was removed.
4980 (define_split
4981 [(set (match_operand:RECIPF 0 "gpc_reg_operand")
4982 (div:RECIPF (match_operand 1 "gpc_reg_operand")
4983 (match_operand 2 "gpc_reg_operand")))]
4984 "RS6000_RECIP_AUTO_RE_P (<MODE>mode)
4985 && can_create_pseudo_p () && flag_finite_math_only
4986 && !flag_trapping_math && flag_reciprocal_math"
4987 [(const_int 0)]
4988 {
4989 rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
4990 DONE;
4991 })
4992
4993 ;; Builtins to replace 1/sqrt(x) with instructions using RSQRTE and the
4994 ;; appropriate fixup.
4995 (define_expand "rsqrt<mode>2"
4996 [(match_operand:RECIPF 0 "gpc_reg_operand")
4997 (match_operand:RECIPF 1 "gpc_reg_operand")]
4998 "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
4999 {
5000 rs6000_emit_swsqrt (operands[0], operands[1], 1);
5001 DONE;
5002 })
5003
5004 ;; Floating-point insns, excluding normal data motion. We combine the SF/DF
5005 ;; modes here, and also add in conditional vsx/power8-vector support to access
5006 ;; values in the traditional Altivec registers if the appropriate
5007 ;; -mupper-regs-{df,sf} option is enabled.
5008
5009 (define_expand "abs<mode>2"
5010 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5011 (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand")))]
5012 "TARGET_HARD_FLOAT"
5013 "")
5014
5015 (define_insn "*abs<mode>2_fpr"
5016 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5017 (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")))]
5018 "TARGET_HARD_FLOAT"
5019 "@
5020 fabs %0,%1
5021 xsabsdp %x0,%x1"
5022 [(set_attr "type" "fpsimple")])
5023
5024 (define_insn "*nabs<mode>2_fpr"
5025 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5026 (neg:SFDF
5027 (abs:SFDF
5028 (match_operand:SFDF 1 "gpc_reg_operand" "d,wa"))))]
5029 "TARGET_HARD_FLOAT"
5030 "@
5031 fnabs %0,%1
5032 xsnabsdp %x0,%x1"
5033 [(set_attr "type" "fpsimple")])
5034
5035 (define_expand "neg<mode>2"
5036 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5037 (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand")))]
5038 "TARGET_HARD_FLOAT"
5039 "")
5040
5041 (define_insn "*neg<mode>2_fpr"
5042 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5043 (neg:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")))]
5044 "TARGET_HARD_FLOAT"
5045 "@
5046 fneg %0,%1
5047 xsnegdp %x0,%x1"
5048 [(set_attr "type" "fpsimple")])
5049
5050 (define_expand "add<mode>3"
5051 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5052 (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand")
5053 (match_operand:SFDF 2 "gpc_reg_operand")))]
5054 "TARGET_HARD_FLOAT"
5055 "")
5056
5057 (define_insn "*add<mode>3_fpr"
5058 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5059 (plus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%d,wa")
5060 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa")))]
5061 "TARGET_HARD_FLOAT"
5062 "@
5063 fadd<s> %0,%1,%2
5064 xsadd<sd>p %x0,%x1,%x2"
5065 [(set_attr "type" "fp")
5066 (set_attr "isa" "*,<Fisa>")])
5067
5068 (define_expand "sub<mode>3"
5069 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5070 (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand")
5071 (match_operand:SFDF 2 "gpc_reg_operand")))]
5072 "TARGET_HARD_FLOAT"
5073 "")
5074
5075 (define_insn "*sub<mode>3_fpr"
5076 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5077 (minus:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")
5078 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa")))]
5079 "TARGET_HARD_FLOAT"
5080 "@
5081 fsub<s> %0,%1,%2
5082 xssub<sd>p %x0,%x1,%x2"
5083 [(set_attr "type" "fp")
5084 (set_attr "isa" "*,<Fisa>")])
5085
5086 (define_expand "mul<mode>3"
5087 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5088 (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand")
5089 (match_operand:SFDF 2 "gpc_reg_operand")))]
5090 "TARGET_HARD_FLOAT"
5091 "")
5092
5093 (define_insn "*mul<mode>3_fpr"
5094 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5095 (mult:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "%d,wa")
5096 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa")))]
5097 "TARGET_HARD_FLOAT"
5098 "@
5099 fmul<s> %0,%1,%2
5100 xsmul<sd>p %x0,%x1,%x2"
5101 [(set_attr "type" "dmul")
5102 (set_attr "isa" "*,<Fisa>")])
5103
5104 (define_expand "div<mode>3"
5105 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5106 (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand")
5107 (match_operand:SFDF 2 "gpc_reg_operand")))]
5108 "TARGET_HARD_FLOAT"
5109 {
5110 if (RS6000_RECIP_AUTO_RE_P (<MODE>mode)
5111 && can_create_pseudo_p () && flag_finite_math_only
5112 && !flag_trapping_math && flag_reciprocal_math)
5113 {
5114 rs6000_emit_swdiv (operands[0], operands[1], operands[2], true);
5115 DONE;
5116 }
5117 })
5118
5119 (define_insn "*div<mode>3_fpr"
5120 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5121 (div:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")
5122 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa")))]
5123 "TARGET_HARD_FLOAT"
5124 "@
5125 fdiv<s> %0,%1,%2
5126 xsdiv<sd>p %x0,%x1,%x2"
5127 [(set_attr "type" "<sd>div")
5128 (set_attr "isa" "*,<Fisa>")])
5129
5130 (define_insn "*sqrt<mode>2_internal"
5131 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5132 (sqrt:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")))]
5133 "TARGET_HARD_FLOAT && TARGET_PPC_GPOPT"
5134 "@
5135 fsqrt<s> %0,%1
5136 xssqrt<sd>p %x0,%x1"
5137 [(set_attr "type" "<sd>sqrt")
5138 (set_attr "isa" "*,<Fisa>")])
5139
5140 (define_expand "sqrt<mode>2"
5141 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5142 (sqrt:SFDF (match_operand:SFDF 1 "gpc_reg_operand")))]
5143 "TARGET_HARD_FLOAT && TARGET_PPC_GPOPT"
5144 {
5145 if (<MODE>mode == SFmode
5146 && TARGET_RECIP_PRECISION
5147 && RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)
5148 && !optimize_function_for_size_p (cfun)
5149 && flag_finite_math_only && !flag_trapping_math
5150 && flag_unsafe_math_optimizations)
5151 {
5152 rs6000_emit_swsqrt (operands[0], operands[1], 0);
5153 DONE;
5154 }
5155 })
5156
5157 ;; Floating point reciprocal approximation
5158 (define_insn "fre<sd>"
5159 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5160 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "d,wa")]
5161 UNSPEC_FRES))]
5162 "TARGET_<FFRE>"
5163 "@
5164 fre<s> %0,%1
5165 xsre<sd>p %x0,%x1"
5166 [(set_attr "type" "fp")
5167 (set_attr "isa" "*,<Fisa>")])
5168
5169 (define_expand "fmod<mode>3"
5170 [(use (match_operand:SFDF 0 "gpc_reg_operand"))
5171 (use (match_operand:SFDF 1 "gpc_reg_operand"))
5172 (use (match_operand:SFDF 2 "gpc_reg_operand"))]
5173 "TARGET_HARD_FLOAT
5174 && TARGET_FPRND
5175 && flag_unsafe_math_optimizations"
5176 {
5177 rtx div = gen_reg_rtx (<MODE>mode);
5178 emit_insn (gen_div<mode>3 (div, operands[1], operands[2]));
5179
5180 rtx friz = gen_reg_rtx (<MODE>mode);
5181 emit_insn (gen_btrunc<mode>2 (friz, div));
5182
5183 emit_insn (gen_nfms<mode>4 (operands[0], operands[2], friz, operands[1]));
5184 DONE;
5185 })
5186
5187 (define_expand "remainder<mode>3"
5188 [(use (match_operand:SFDF 0 "gpc_reg_operand"))
5189 (use (match_operand:SFDF 1 "gpc_reg_operand"))
5190 (use (match_operand:SFDF 2 "gpc_reg_operand"))]
5191 "TARGET_HARD_FLOAT
5192 && TARGET_FPRND
5193 && flag_unsafe_math_optimizations"
5194 {
5195 rtx div = gen_reg_rtx (<MODE>mode);
5196 emit_insn (gen_div<mode>3 (div, operands[1], operands[2]));
5197
5198 rtx frin = gen_reg_rtx (<MODE>mode);
5199 emit_insn (gen_round<mode>2 (frin, div));
5200
5201 emit_insn (gen_nfms<mode>4 (operands[0], operands[2], frin, operands[1]));
5202 DONE;
5203 })
5204
5205 (define_insn "*rsqrt<mode>2"
5206 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5207 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "d,wa")]
5208 UNSPEC_RSQRT))]
5209 "RS6000_RECIP_HAVE_RSQRTE_P (<MODE>mode)"
5210 "@
5211 frsqrte<s> %0,%1
5212 xsrsqrte<sd>p %x0,%x1"
5213 [(set_attr "type" "fp")
5214 (set_attr "isa" "*,<Fisa>")])
5215
5216 ;; Floating point comparisons
5217 (define_insn "*cmp<mode>_fpr"
5218 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y,y")
5219 (compare:CCFP (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")
5220 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa")))]
5221 "TARGET_HARD_FLOAT"
5222 "@
5223 fcmpu %0,%1,%2
5224 xscmpudp %0,%x1,%x2"
5225 [(set_attr "type" "fpcompare")
5226 (set_attr "isa" "*,<Fisa>")])
5227
5228 ;; Floating point conversions
5229 (define_expand "extendsfdf2"
5230 [(set (match_operand:DF 0 "gpc_reg_operand")
5231 (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand")))]
5232 "TARGET_HARD_FLOAT"
5233 {
5234 if (HONOR_SNANS (SFmode))
5235 operands[1] = force_reg (SFmode, operands[1]);
5236 })
5237
5238 (define_insn_and_split "*extendsfdf2_fpr"
5239 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d,d,wa,?wa,wa,v")
5240 (float_extend:DF (match_operand:SF 1 "reg_or_mem_operand" "0,f,m,0,wa,Z,wY")))]
5241 "TARGET_HARD_FLOAT && !HONOR_SNANS (SFmode)"
5242 "@
5243 #
5244 fmr %0,%1
5245 lfs%U1%X1 %0,%1
5246 #
5247 xscpsgndp %x0,%x1,%x1
5248 lxsspx %x0,%y1
5249 lxssp %0,%1"
5250 "&& reload_completed && REG_P (operands[1]) && REGNO (operands[0]) == REGNO (operands[1])"
5251 [(const_int 0)]
5252 {
5253 emit_note (NOTE_INSN_DELETED);
5254 DONE;
5255 }
5256 [(set_attr "type" "fp,fpsimple,fpload,fp,fpsimple,fpload,fpload")
5257 (set_attr "isa" "*,*,*,*,p8v,p8v,p9v")])
5258
5259 (define_insn "*extendsfdf2_snan"
5260 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,wa")
5261 (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f,wa")))]
5262 "TARGET_HARD_FLOAT && HONOR_SNANS (SFmode)"
5263 "@
5264 frsp %0,%1
5265 xsrsp %x0,%x1"
5266 [(set_attr "type" "fp")
5267 (set_attr "isa" "*,p8v")])
5268
5269 (define_expand "truncdfsf2"
5270 [(set (match_operand:SF 0 "gpc_reg_operand")
5271 (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand")))]
5272 "TARGET_HARD_FLOAT"
5273 "")
5274
5275 (define_insn "*truncdfsf2_fpr"
5276 [(set (match_operand:SF 0 "gpc_reg_operand" "=f,wa")
5277 (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "d,wa")))]
5278 "TARGET_HARD_FLOAT"
5279 "@
5280 frsp %0,%1
5281 xsrsp %x0,%x1"
5282 [(set_attr "type" "fp")
5283 (set_attr "isa" "*,p8v")])
5284
5285 ;; This expander is here to avoid FLOAT_WORDS_BIGENDIAN tests in
5286 ;; builtins.cc and optabs.cc that are not correct for IBM long double
5287 ;; when little-endian.
5288 (define_expand "signbit<mode>2"
5289 [(set (match_dup 2)
5290 (float_truncate:DF (match_operand:FLOAT128 1 "reg_or_mem_operand")))
5291 (set (match_dup 3)
5292 (subreg:DI (match_dup 2) 0))
5293 (set (match_dup 4)
5294 (match_dup 5))
5295 (set (match_operand:SI 0 "gpc_reg_operand")
5296 (match_dup 6))]
5297 "TARGET_HARD_FLOAT
5298 && (!FLOAT128_IEEE_P (<MODE>mode)
5299 || TARGET_DIRECT_MOVE_64BIT)"
5300 {
5301 if (FLOAT128_IEEE_P (<MODE>mode))
5302 {
5303 rtx dest = operands[0];
5304 rtx src = operands[1];
5305 rtx tmp = gen_reg_rtx (DImode);
5306 /* For P8 LE, we generate memory access with subreg:V1TI which
5307 prevents the related gen_signbitkf2_dm_mem being matched so
5308 directly emit it here and leave the other cases alone. */
5309 if (!BYTES_BIG_ENDIAN
5310 && !TARGET_P9_VECTOR
5311 && memory_operand (src, <MODE>mode))
5312 emit_insn (gen_signbitkf2_dm_mem (tmp, src));
5313 else
5314 {
5315 if (!gpc_reg_operand (src, <MODE>mode))
5316 src = copy_to_mode_reg (<MODE>mode, src);
5317 gcc_assert (gpc_reg_operand (src, <MODE>mode));
5318 emit_insn (gen_signbit2_dm (<MODE>mode, tmp, src));
5319 }
5320 rtx dest_di = gen_lowpart (DImode, dest);
5321 emit_insn (gen_lshrdi3 (dest_di, tmp, GEN_INT (63)));
5322 DONE;
5323 }
5324 if (!gpc_reg_operand (operands[1], <MODE>mode))
5325 operands[1] = copy_to_mode_reg (<MODE>mode, operands[1]);
5326 operands[2] = gen_reg_rtx (DFmode);
5327 operands[3] = gen_reg_rtx (DImode);
5328 if (TARGET_POWERPC64)
5329 {
5330 operands[4] = gen_reg_rtx (DImode);
5331 operands[5] = gen_rtx_LSHIFTRT (DImode, operands[3], GEN_INT (63));
5332 operands[6] = gen_rtx_SUBREG (SImode, operands[4],
5333 WORDS_BIG_ENDIAN ? 4 : 0);
5334 }
5335 else
5336 {
5337 operands[4] = gen_reg_rtx (SImode);
5338 operands[5] = gen_rtx_SUBREG (SImode, operands[3],
5339 WORDS_BIG_ENDIAN ? 0 : 4);
5340 operands[6] = gen_rtx_LSHIFTRT (SImode, operands[4], GEN_INT (31));
5341 }
5342 })
5343
5344 ;; Optimize IEEE 128-bit signbit on 64-bit systems with direct move to avoid
5345 ;; multiple direct moves. If we used a SUBREG:DI of the Floa128 type, the
5346 ;; register allocator would typically move the entire _Float128 item to GPRs (2
5347 ;; instructions on ISA 3.0, 3-4 instructions on ISA 2.07).
5348 ;;
5349 ;; After register allocation, if the _Float128 had originally been in GPRs, the
5350 ;; split allows the post reload phases to eliminate the move, and do the shift
5351 ;; directly with the register that contains the signbit.
5352 (define_insn_and_split "@signbit<mode>2_dm"
5353 [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
5354 (unspec:DI [(match_operand:SIGNBIT 1 "gpc_reg_operand" "wa,r")]
5355 UNSPEC_SIGNBIT))]
5356 "TARGET_DIRECT_MOVE_64BIT"
5357 "@
5358 mfvsrd %0,%x1
5359 #"
5360 "&& reload_completed && int_reg_operand (operands[1], <MODE>mode)"
5361 [(set (match_dup 0)
5362 (match_dup 2))]
5363 {
5364 operands[2] = gen_highpart (DImode, operands[1]);
5365 }
5366 [(set_attr "type" "mfvsr,*")])
5367
5368 ;; Optimize IEEE 128-bit signbit on to avoid loading the value into a vector
5369 ;; register and then doing a direct move if the value comes from memory. On
5370 ;; little endian, we have to load the 2nd double-word to get the sign bit.
5371 (define_insn_and_split "signbit<mode>2_dm_mem"
5372 [(set (match_operand:DI 0 "gpc_reg_operand" "=b")
5373 (unspec:DI [(match_operand:SIGNBIT 1 "memory_operand" "m")]
5374 UNSPEC_SIGNBIT))]
5375 "TARGET_DIRECT_MOVE_64BIT"
5376 "#"
5377 "&& 1"
5378 [(set (match_dup 0)
5379 (match_dup 2))]
5380 {
5381 rtx dest = operands[0];
5382 rtx src = operands[1];
5383 rtx addr = XEXP (src, 0);
5384
5385 if (WORDS_BIG_ENDIAN)
5386 operands[2] = adjust_address (src, DImode, 0);
5387
5388 else if (REG_P (addr) || SUBREG_P (addr))
5389 operands[2] = adjust_address (src, DImode, 8);
5390
5391 else if (GET_CODE (addr) == PLUS && REG_P (XEXP (addr, 0))
5392 && CONST_INT_P (XEXP (addr, 1)) && mem_operand_gpr (src, DImode))
5393 operands[2] = adjust_address (src, DImode, 8);
5394
5395 else
5396 {
5397 rtx tmp = can_create_pseudo_p () ? gen_reg_rtx (DImode) : dest;
5398 emit_insn (gen_rtx_SET (tmp, addr));
5399 operands[2] = change_address (src, DImode,
5400 gen_rtx_PLUS (DImode, tmp, GEN_INT (8)));
5401 }
5402 })
5403
5404 (define_expand "copysign<mode>3"
5405 [(set (match_dup 3)
5406 (abs:SFDF (match_operand:SFDF 1 "gpc_reg_operand")))
5407 (set (match_dup 4)
5408 (neg:SFDF (abs:SFDF (match_dup 1))))
5409 (set (match_operand:SFDF 0 "gpc_reg_operand")
5410 (if_then_else:SFDF (ge (match_operand:SFDF 2 "any_operand")
5411 (match_dup 5))
5412 (match_dup 3)
5413 (match_dup 4)))]
5414 "TARGET_HARD_FLOAT
5415 && ((TARGET_PPC_GFXOPT
5416 && !HONOR_NANS (<MODE>mode)
5417 && !HONOR_SIGNED_ZEROS (<MODE>mode))
5418 || TARGET_CMPB
5419 || VECTOR_UNIT_VSX_P (<MODE>mode))"
5420 {
5421 /* Middle-end canonicalizes -fabs (x) to copysign (x, -1),
5422 but PowerPC prefers -fabs (x). */
5423 if (CONST_DOUBLE_AS_FLOAT_P (operands[2]))
5424 {
5425 if (real_isneg (CONST_DOUBLE_REAL_VALUE (operands[2])))
5426 {
5427 operands[3] = gen_reg_rtx (<MODE>mode);
5428 emit_insn (gen_abs<mode>2 (operands[3], operands[1]));
5429 emit_insn (gen_neg<mode>2 (operands[0], operands[3]));
5430 }
5431 else
5432 emit_insn (gen_abs<mode>2 (operands[0], operands[1]));
5433 DONE;
5434 }
5435
5436 if (!gpc_reg_operand (operands[2], <MODE>mode))
5437 operands[2] = copy_to_mode_reg (<MODE>mode, operands[2]);
5438
5439 if (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))
5440 {
5441 emit_insn (gen_copysign<mode>3_fcpsgn (operands[0], operands[1],
5442 operands[2]));
5443 DONE;
5444 }
5445
5446 operands[3] = gen_reg_rtx (<MODE>mode);
5447 operands[4] = gen_reg_rtx (<MODE>mode);
5448 operands[5] = CONST0_RTX (<MODE>mode);
5449 })
5450
5451 (define_insn "copysign<mode>3_fcpsgn"
5452 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5453 (copysign:SFDF (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")
5454 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa")))]
5455 "TARGET_HARD_FLOAT && (TARGET_CMPB || VECTOR_UNIT_VSX_P (<MODE>mode))"
5456 "@
5457 fcpsgn %0,%2,%1
5458 xscpsgndp %x0,%x2,%x1"
5459 [(set_attr "type" "fpsimple")])
5460
5461 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
5462 ;; fsel instruction and some auxiliary computations. Then we just have a
5463 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
5464 ;; combine.
5465 ;; For MIN, MAX on non-VSX machines, and conditional move all of the time, we
5466 ;; use DEFINE_EXPAND's that involve a fsel instruction and some auxiliary
5467 ;; computations. Then we just have a single DEFINE_INSN for fsel and the
5468 ;; define_splits to make them if made by combine. On VSX machines we have the
5469 ;; min/max instructions.
5470 ;;
5471 ;; On VSX, we only check for TARGET_VSX instead of checking for a vsx/p8 vector
5472 ;; to allow either DF/SF to use only traditional registers.
5473
5474 (define_expand "s<minmax><mode>3"
5475 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5476 (fp_minmax:SFDF (match_operand:SFDF 1 "gpc_reg_operand")
5477 (match_operand:SFDF 2 "gpc_reg_operand")))]
5478 "TARGET_MINMAX"
5479 {
5480 rs6000_emit_minmax (operands[0], <SMINMAX>, operands[1], operands[2]);
5481 DONE;
5482 })
5483
5484 (define_insn "*s<minmax><mode>3_vsx"
5485 [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa")
5486 (fp_minmax:SFDF (match_operand:SFDF 1 "vsx_register_operand" "wa")
5487 (match_operand:SFDF 2 "vsx_register_operand" "wa")))]
5488 "TARGET_VSX && TARGET_HARD_FLOAT"
5489 {
5490 return (TARGET_P9_MINMAX
5491 ? "xs<minmax>cdp %x0,%x1,%x2"
5492 : "xs<minmax>dp %x0,%x1,%x2");
5493 }
5494 [(set_attr "type" "fp")])
5495
5496 ;; Min/max for ISA 3.1 IEEE 128-bit floating point
5497 (define_insn "s<minmax><mode>3"
5498 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
5499 (fp_minmax:IEEE128
5500 (match_operand:IEEE128 1 "altivec_register_operand" "v")
5501 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
5502 "TARGET_POWER10 && TARGET_FLOAT128_HW"
5503 "xs<minmax>cqp %0,%1,%2"
5504 [(set_attr "type" "vecfloat")
5505 (set_attr "size" "128")])
5506
5507 ;; The conditional move instructions allow us to perform max and min operations
5508 ;; even when we don't have the appropriate max/min instruction using the FSEL
5509 ;; instruction.
5510
5511 (define_insn_and_split "*s<minmax><mode>3_fpr"
5512 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5513 (fp_minmax:SFDF (match_operand:SFDF 1 "gpc_reg_operand")
5514 (match_operand:SFDF 2 "gpc_reg_operand")))]
5515 "!TARGET_VSX && TARGET_MINMAX"
5516 "#"
5517 "&& 1"
5518 [(const_int 0)]
5519 {
5520 rs6000_emit_minmax (operands[0], <SMINMAX>, operands[1], operands[2]);
5521 DONE;
5522 })
5523
5524
5525 (define_int_iterator FMINMAX [UNSPEC_FMAX UNSPEC_FMIN])
5526
5527 (define_int_attr minmax_op [(UNSPEC_FMAX "max")
5528 (UNSPEC_FMIN "min")])
5529
5530 (define_insn "f<minmax_op><mode>3"
5531 [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa")
5532 (unspec:SFDF [(match_operand:SFDF 1 "vsx_register_operand" "wa")
5533 (match_operand:SFDF 2 "vsx_register_operand" "wa")]
5534 FMINMAX))]
5535 "TARGET_VSX && !flag_finite_math_only"
5536 "xs<minmax_op>dp %x0,%x1,%x2"
5537 [(set_attr "type" "fp")]
5538 )
5539
5540 (define_expand "mov<mode>cc"
5541 [(set (match_operand:GPR 0 "gpc_reg_operand")
5542 (if_then_else:GPR (match_operand 1 "comparison_operator")
5543 (match_operand:GPR 2 "gpc_reg_operand")
5544 (match_operand:GPR 3 "gpc_reg_operand")))]
5545 "TARGET_ISEL"
5546 {
5547 if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5548 DONE;
5549 else
5550 FAIL;
5551 })
5552
5553 ;; We use the BASE_REGS for the isel input operands because, if rA is
5554 ;; 0, the value of 0 is placed in rD upon truth. Similarly for rB
5555 ;; because we may switch the operands and rB may end up being rA.
5556 ;;
5557 ;; We need 2 patterns: an unsigned and a signed pattern. We could
5558 ;; leave out the mode in operand 4 and use one pattern, but reload can
5559 ;; change the mode underneath our feet and then gets confused trying
5560 ;; to reload the value.
5561 (define_mode_iterator CCANY [CC CCUNS])
5562 (define_insn "isel_<CCANY:mode>_<GPR:mode>"
5563 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5564 (if_then_else:GPR
5565 (match_operator 1 "scc_comparison_operator"
5566 [(match_operand:CCANY 4 "cc_reg_operand" "y,y")
5567 (const_int 0)])
5568 (match_operand:GPR 2 "reg_or_zero_operand" "O,b")
5569 (match_operand:GPR 3 "gpc_reg_operand" "r,r")))]
5570 "TARGET_ISEL"
5571 "isel %0,%2,%3,%j1"
5572 [(set_attr "type" "isel")])
5573
5574 ;; These patterns can be useful for combine; they let combine know that
5575 ;; isel can handle reversed comparisons so long as the operands are
5576 ;; registers.
5577
5578 (define_insn "*isel_reversed_<CCANY:mode>_<GPR:mode>"
5579 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r,r")
5580 (if_then_else:GPR
5581 (match_operator 1 "scc_rev_comparison_operator"
5582 [(match_operand:CCANY 4 "cc_reg_operand" "y,y")
5583 (const_int 0)])
5584 (match_operand:GPR 2 "gpc_reg_operand" "r,r")
5585 (match_operand:GPR 3 "reg_or_zero_operand" "O,b")))]
5586 "TARGET_ISEL"
5587 {
5588 PUT_CODE (operands[1], reverse_condition (GET_CODE (operands[1])));
5589 return "isel %0,%3,%2,%j1";
5590 }
5591 [(set_attr "type" "isel")])
5592
5593 ; Set Boolean Condition (Reverse)
5594 (define_insn "setbc_<CCANY:mode>_<GPR:mode>"
5595 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5596 (match_operator:GPR 1 "scc_comparison_operator"
5597 [(match_operand:CCANY 2 "cc_reg_operand" "y")
5598 (const_int 0)]))]
5599 "TARGET_POWER10"
5600 "setbc %0,%j1"
5601 [(set_attr "type" "isel")])
5602
5603 (define_insn "*setbcr_<CCANY:mode>_<GPR:mode>"
5604 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5605 (match_operator:GPR 1 "scc_rev_comparison_operator"
5606 [(match_operand:CCANY 2 "cc_reg_operand" "y")
5607 (const_int 0)]))]
5608 "TARGET_POWER10"
5609 "setbcr %0,%j1"
5610 [(set_attr "type" "isel")])
5611
5612 ; Set Negative Boolean Condition (Reverse)
5613 (define_insn "*setnbc_<CCANY:mode>_<GPR:mode>"
5614 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5615 (neg:GPR (match_operator:GPR 1 "scc_comparison_operator"
5616 [(match_operand:CCANY 2 "cc_reg_operand" "y")
5617 (const_int 0)])))]
5618 "TARGET_POWER10"
5619 "setnbc %0,%j1"
5620 [(set_attr "type" "isel")])
5621
5622 (define_insn "*setnbcr_<CCANY:mode>_<GPR:mode>"
5623 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
5624 (neg:GPR (match_operator:GPR 1 "scc_rev_comparison_operator"
5625 [(match_operand:CCANY 2 "cc_reg_operand" "y")
5626 (const_int 0)])))]
5627 "TARGET_POWER10"
5628 "setnbcr %0,%j1"
5629 [(set_attr "type" "isel")])
5630
5631 ;; Floating point conditional move
5632 (define_expand "mov<mode>cc"
5633 [(set (match_operand:SFDF 0 "gpc_reg_operand")
5634 (if_then_else:SFDF (match_operand 1 "comparison_operator")
5635 (match_operand:SFDF 2 "gpc_reg_operand")
5636 (match_operand:SFDF 3 "gpc_reg_operand")))]
5637 "TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT"
5638 {
5639 if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5640 DONE;
5641 else
5642 FAIL;
5643 })
5644
5645 (define_insn "*fsel<SFDF:mode><SFDF2:mode>4"
5646 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=&<SFDF:rreg2>")
5647 (if_then_else:SFDF
5648 (ge (match_operand:SFDF2 1 "gpc_reg_operand" "<SFDF2:rreg2>")
5649 (match_operand:SFDF2 4 "zero_fp_constant" "F"))
5650 (match_operand:SFDF 2 "gpc_reg_operand" "<SFDF:rreg2>")
5651 (match_operand:SFDF 3 "gpc_reg_operand" "<SFDF:rreg2>")))]
5652 "TARGET_HARD_FLOAT && TARGET_PPC_GFXOPT"
5653 "fsel %0,%1,%2,%3"
5654 [(set_attr "type" "fp")])
5655
5656 (define_insn_and_split "*mov<SFDF:mode><SFDF2:mode>cc_p9"
5657 [(set (match_operand:SFDF 0 "vsx_register_operand" "=&wa,wa")
5658 (if_then_else:SFDF
5659 (match_operator:CCFP 1 "fpmask_comparison_operator"
5660 [(match_operand:SFDF2 2 "vsx_register_operand" "wa,wa")
5661 (match_operand:SFDF2 3 "vsx_register_operand" "wa,wa")])
5662 (match_operand:SFDF 4 "vsx_register_operand" "wa,wa")
5663 (match_operand:SFDF 5 "vsx_register_operand" "wa,wa")))
5664 (clobber (match_scratch:V2DI 6 "=0,&wa"))]
5665 "TARGET_P9_MINMAX"
5666 "#"
5667 "&& 1"
5668 [(set (match_dup 6)
5669 (if_then_else:V2DI (match_dup 1)
5670 (match_dup 7)
5671 (match_dup 8)))
5672 (set (match_dup 0)
5673 (if_then_else:SFDF (ne (match_dup 6)
5674 (match_dup 8))
5675 (match_dup 4)
5676 (match_dup 5)))]
5677 {
5678 if (GET_CODE (operands[6]) == SCRATCH)
5679 operands[6] = gen_reg_rtx (V2DImode);
5680
5681 operands[7] = CONSTM1_RTX (V2DImode);
5682 operands[8] = CONST0_RTX (V2DImode);
5683 }
5684 [(set_attr "length" "8")
5685 (set_attr "type" "vecperm")])
5686
5687 ;; Handle inverting the fpmask comparisons.
5688 (define_insn_and_split "*mov<SFDF:mode><SFDF2:mode>cc_invert_p9"
5689 [(set (match_operand:SFDF 0 "vsx_register_operand" "=&wa,wa")
5690 (if_then_else:SFDF
5691 (match_operator:CCFP 1 "invert_fpmask_comparison_operator"
5692 [(match_operand:SFDF2 2 "vsx_register_operand" "wa,wa")
5693 (match_operand:SFDF2 3 "vsx_register_operand" "wa,wa")])
5694 (match_operand:SFDF 4 "vsx_register_operand" "wa,wa")
5695 (match_operand:SFDF 5 "vsx_register_operand" "wa,wa")))
5696 (clobber (match_scratch:V2DI 6 "=0,&wa"))]
5697 "TARGET_P9_MINMAX"
5698 "#"
5699 "&& 1"
5700 [(set (match_dup 6)
5701 (if_then_else:V2DI (match_dup 9)
5702 (match_dup 7)
5703 (match_dup 8)))
5704 (set (match_dup 0)
5705 (if_then_else:SFDF (ne (match_dup 6)
5706 (match_dup 8))
5707 (match_dup 5)
5708 (match_dup 4)))]
5709 {
5710 rtx op1 = operands[1];
5711 enum rtx_code cond = reverse_condition_maybe_unordered (GET_CODE (op1));
5712
5713 if (GET_CODE (operands[6]) == SCRATCH)
5714 operands[6] = gen_reg_rtx (V2DImode);
5715
5716 operands[7] = CONSTM1_RTX (V2DImode);
5717 operands[8] = CONST0_RTX (V2DImode);
5718
5719 operands[9] = gen_rtx_fmt_ee (cond, CCFPmode, operands[2], operands[3]);
5720 }
5721 [(set_attr "length" "8")
5722 (set_attr "type" "vecperm")])
5723
5724 (define_insn "*fpmask<mode>"
5725 [(set (match_operand:V2DI 0 "vsx_register_operand" "=wa")
5726 (if_then_else:V2DI
5727 (match_operator:CCFP 1 "fpmask_comparison_operator"
5728 [(match_operand:SFDF 2 "vsx_register_operand" "wa")
5729 (match_operand:SFDF 3 "vsx_register_operand" "wa")])
5730 (match_operand:V2DI 4 "all_ones_constant" "")
5731 (match_operand:V2DI 5 "zero_constant" "")))]
5732 "TARGET_P9_MINMAX"
5733 "xscmp%V1dp %x0,%x2,%x3"
5734 [(set_attr "type" "fpcompare")])
5735
5736 (define_insn "*xxsel<mode>"
5737 [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa")
5738 (if_then_else:SFDF (ne (match_operand:V2DI 1 "vsx_register_operand" "wa")
5739 (match_operand:V2DI 2 "zero_constant" ""))
5740 (match_operand:SFDF 3 "vsx_register_operand" "wa")
5741 (match_operand:SFDF 4 "vsx_register_operand" "wa")))]
5742 "TARGET_P9_MINMAX"
5743 "xxsel %x0,%x4,%x3,%x1"
5744 [(set_attr "type" "vecmove")])
5745
5746 ;; Support for ISA 3.1 IEEE 128-bit conditional move. The mode used in the
5747 ;; comparison must be the same as used in the move.
5748 (define_expand "mov<mode>cc"
5749 [(set (match_operand:IEEE128 0 "gpc_reg_operand")
5750 (if_then_else:IEEE128 (match_operand 1 "comparison_operator")
5751 (match_operand:IEEE128 2 "gpc_reg_operand")
5752 (match_operand:IEEE128 3 "gpc_reg_operand")))]
5753 "TARGET_POWER10 && TARGET_FLOAT128_HW"
5754 {
5755 if (rs6000_emit_cmove (operands[0], operands[1], operands[2], operands[3]))
5756 DONE;
5757 else
5758 FAIL;
5759 })
5760
5761 (define_insn_and_split "*mov<mode>cc_p10"
5762 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=&v,v")
5763 (if_then_else:IEEE128
5764 (match_operator:CCFP 1 "fpmask_comparison_operator"
5765 [(match_operand:IEEE128 2 "altivec_register_operand" "v,v")
5766 (match_operand:IEEE128 3 "altivec_register_operand" "v,v")])
5767 (match_operand:IEEE128 4 "altivec_register_operand" "v,v")
5768 (match_operand:IEEE128 5 "altivec_register_operand" "v,v")))
5769 (clobber (match_scratch:V2DI 6 "=0,&v"))]
5770 "TARGET_POWER10 && TARGET_FLOAT128_HW"
5771 "#"
5772 "&& 1"
5773 [(set (match_dup 6)
5774 (if_then_else:V2DI (match_dup 1)
5775 (match_dup 7)
5776 (match_dup 8)))
5777 (set (match_dup 0)
5778 (if_then_else:IEEE128 (ne (match_dup 6)
5779 (match_dup 8))
5780 (match_dup 4)
5781 (match_dup 5)))]
5782 {
5783 if (GET_CODE (operands[6]) == SCRATCH)
5784 operands[6] = gen_reg_rtx (V2DImode);
5785
5786 operands[7] = CONSTM1_RTX (V2DImode);
5787 operands[8] = CONST0_RTX (V2DImode);
5788 }
5789 [(set_attr "length" "8")
5790 (set_attr "type" "vecperm")])
5791
5792 ;; Handle inverting the fpmask comparisons.
5793 (define_insn_and_split "*mov<mode>cc_invert_p10"
5794 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=&v,v")
5795 (if_then_else:IEEE128
5796 (match_operator:CCFP 1 "invert_fpmask_comparison_operator"
5797 [(match_operand:IEEE128 2 "altivec_register_operand" "v,v")
5798 (match_operand:IEEE128 3 "altivec_register_operand" "v,v")])
5799 (match_operand:IEEE128 4 "altivec_register_operand" "v,v")
5800 (match_operand:IEEE128 5 "altivec_register_operand" "v,v")))
5801 (clobber (match_scratch:V2DI 6 "=0,&v"))]
5802 "TARGET_POWER10 && TARGET_FLOAT128_HW"
5803 "#"
5804 "&& 1"
5805 [(set (match_dup 6)
5806 (if_then_else:V2DI (match_dup 9)
5807 (match_dup 7)
5808 (match_dup 8)))
5809 (set (match_dup 0)
5810 (if_then_else:IEEE128 (ne (match_dup 6)
5811 (match_dup 8))
5812 (match_dup 5)
5813 (match_dup 4)))]
5814 {
5815 rtx op1 = operands[1];
5816 enum rtx_code cond = reverse_condition_maybe_unordered (GET_CODE (op1));
5817
5818 if (GET_CODE (operands[6]) == SCRATCH)
5819 operands[6] = gen_reg_rtx (V2DImode);
5820
5821 operands[7] = CONSTM1_RTX (V2DImode);
5822 operands[8] = CONST0_RTX (V2DImode);
5823
5824 operands[9] = gen_rtx_fmt_ee (cond, CCFPmode, operands[2], operands[3]);
5825 }
5826 [(set_attr "length" "8")
5827 (set_attr "type" "vecperm")])
5828
5829 (define_insn "*fpmask<mode>"
5830 [(set (match_operand:V2DI 0 "altivec_register_operand" "=v")
5831 (if_then_else:V2DI
5832 (match_operator:CCFP 1 "fpmask_comparison_operator"
5833 [(match_operand:IEEE128 2 "altivec_register_operand" "v")
5834 (match_operand:IEEE128 3 "altivec_register_operand" "v")])
5835 (match_operand:V2DI 4 "all_ones_constant" "")
5836 (match_operand:V2DI 5 "zero_constant" "")))]
5837 "TARGET_POWER10 && TARGET_FLOAT128_HW"
5838 "xscmp%V1qp %0,%2,%3"
5839 [(set_attr "type" "fpcompare")])
5840
5841 (define_insn "*xxsel<mode>"
5842 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
5843 (if_then_else:IEEE128
5844 (ne (match_operand:V2DI 1 "altivec_register_operand" "v")
5845 (match_operand:V2DI 2 "zero_constant" ""))
5846 (match_operand:IEEE128 3 "altivec_register_operand" "v")
5847 (match_operand:IEEE128 4 "altivec_register_operand" "v")))]
5848 "TARGET_POWER10 && TARGET_FLOAT128_HW"
5849 "xxsel %x0,%x4,%x3,%x1"
5850 [(set_attr "type" "vecmove")])
5851
5852
5853 ;; Conversions to and from floating-point.
5854
5855 ; We don't define lfiwax/lfiwzx with the normal definition, because we
5856 ; don't want to support putting SImode in FPR registers.
5857 (define_insn "lfiwax"
5858 [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wa,wa,v")
5859 (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r,v")]
5860 UNSPEC_LFIWAX))]
5861 "TARGET_HARD_FLOAT && TARGET_LFIWAX"
5862 "@
5863 lfiwax %0,%y1
5864 lxsiwax %x0,%y1
5865 mtvsrwa %x0,%1
5866 vextsw2d %0,%1"
5867 [(set_attr "type" "fpload,fpload,mtvsr,vecexts")
5868 (set_attr "isa" "*,p8v,p8v,p9v")])
5869
5870 ; This split must be run before register allocation because it allocates the
5871 ; memory slot that is needed to move values to/from the FPR. We don't allocate
5872 ; it earlier to allow for the combiner to merge insns together where it might
5873 ; not be needed and also in case the insns are deleted as dead code.
5874
5875 (define_insn_and_split "floatsi<mode>2_lfiwax"
5876 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5877 (float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r,r")))
5878 (clobber (match_scratch:DI 2 "=d,wa"))]
5879 "TARGET_HARD_FLOAT && TARGET_LFIWAX
5880 && <SI_CONVERT_FP> && can_create_pseudo_p ()"
5881 "#"
5882 "&& 1"
5883 [(pc)]
5884 {
5885 rtx dest = operands[0];
5886 rtx src = operands[1];
5887 rtx tmp;
5888
5889 if (!MEM_P (src) && TARGET_DIRECT_MOVE_64BIT)
5890 tmp = convert_to_mode (DImode, src, false);
5891 else
5892 {
5893 tmp = operands[2];
5894 if (GET_CODE (tmp) == SCRATCH)
5895 tmp = gen_reg_rtx (DImode);
5896 if (MEM_P (src))
5897 {
5898 src = rs6000_force_indexed_or_indirect_mem (src);
5899 emit_insn (gen_lfiwax (tmp, src));
5900 }
5901 else
5902 {
5903 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
5904 emit_move_insn (stack, src);
5905 emit_insn (gen_lfiwax (tmp, stack));
5906 }
5907 }
5908 emit_insn (gen_floatdi<mode>2 (dest, tmp));
5909 DONE;
5910 }
5911 [(set_attr "length" "12")
5912 (set_attr "type" "fpload")])
5913
5914 (define_insn_and_split "floatsi<mode>2_lfiwax_mem"
5915 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5916 (float:SFDF
5917 (sign_extend:DI
5918 (match_operand:SI 1 "indexed_or_indirect_operand" "Z,Z"))))
5919 (clobber (match_scratch:DI 2 "=d,wa"))]
5920 "TARGET_HARD_FLOAT && TARGET_LFIWAX && <SI_CONVERT_FP>"
5921 "#"
5922 "&& 1"
5923 [(pc)]
5924 {
5925 operands[1] = rs6000_force_indexed_or_indirect_mem (operands[1]);
5926 if (GET_CODE (operands[2]) == SCRATCH)
5927 operands[2] = gen_reg_rtx (DImode);
5928 if (TARGET_P8_VECTOR)
5929 emit_insn (gen_extendsidi2 (operands[2], operands[1]));
5930 else
5931 emit_insn (gen_lfiwax (operands[2], operands[1]));
5932 emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
5933 DONE;
5934 }
5935 [(set_attr "length" "8")
5936 (set_attr "type" "fpload")])
5937
5938 (define_insn_and_split "floatsi<SFDF:mode>2_lfiwax_<QHI:mode>_mem_zext"
5939 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5940 (float:SFDF
5941 (zero_extend:SI
5942 (match_operand:QHI 1 "indexed_or_indirect_operand" "Z,Z"))))
5943 (clobber (match_scratch:DI 2 "=d,wa"))]
5944 "TARGET_HARD_FLOAT && <SI_CONVERT_FP> && TARGET_P9_VECTOR
5945 && TARGET_DIRECT_MOVE_64BIT"
5946 "#"
5947 "&& 1"
5948 [(pc)]
5949 {
5950 if (GET_CODE (operands[2]) == SCRATCH)
5951 operands[2] = gen_reg_rtx (DImode);
5952 emit_insn (gen_zero_extendhidi2 (operands[2], operands[1]));
5953 emit_insn (gen_floatdi<SFDF:mode>2 (operands[0], operands[2]));
5954 DONE;
5955 }
5956 [(set_attr "length" "8")
5957 (set_attr "type" "fpload")])
5958
5959 (define_insn "lfiwzx"
5960 [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wa,wa,wa")
5961 (unspec:DI [(match_operand:SI 1 "reg_or_indexed_operand" "Z,Z,r,wa")]
5962 UNSPEC_LFIWZX))]
5963 "TARGET_HARD_FLOAT && TARGET_LFIWZX"
5964 "@
5965 lfiwzx %0,%y1
5966 lxsiwzx %x0,%y1
5967 mtvsrwz %x0,%1
5968 xxextractuw %x0,%x1,4"
5969 [(set_attr "type" "fpload,fpload,mtvsr,vecexts")
5970 (set_attr "isa" "*,p8v,p8v,p9v")])
5971
5972 (define_insn_and_split "floatunssi<mode>2_lfiwzx"
5973 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
5974 (unsigned_float:SFDF (match_operand:SI 1 "nonimmediate_operand" "r,r")))
5975 (clobber (match_scratch:DI 2 "=d,wa"))]
5976 "TARGET_HARD_FLOAT && TARGET_LFIWZX && <SI_CONVERT_FP>"
5977 "#"
5978 "&& 1"
5979 [(pc)]
5980 {
5981 rtx dest = operands[0];
5982 rtx src = operands[1];
5983 rtx tmp;
5984
5985 if (!MEM_P (src) && TARGET_DIRECT_MOVE_64BIT)
5986 tmp = convert_to_mode (DImode, src, true);
5987 else
5988 {
5989 tmp = operands[2];
5990 if (GET_CODE (tmp) == SCRATCH)
5991 tmp = gen_reg_rtx (DImode);
5992 if (MEM_P (src))
5993 {
5994 src = rs6000_force_indexed_or_indirect_mem (src);
5995 emit_insn (gen_lfiwzx (tmp, src));
5996 }
5997 else
5998 {
5999 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6000 emit_move_insn (stack, src);
6001 emit_insn (gen_lfiwzx (tmp, stack));
6002 }
6003 }
6004 emit_insn (gen_floatdi<mode>2 (dest, tmp));
6005 DONE;
6006 }
6007 [(set_attr "length" "12")
6008 (set_attr "type" "fpload")])
6009
6010 (define_insn_and_split "floatunssi<mode>2_lfiwzx_mem"
6011 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
6012 (unsigned_float:SFDF
6013 (zero_extend:DI
6014 (match_operand:SI 1 "indexed_or_indirect_operand" "Z,Z"))))
6015 (clobber (match_scratch:DI 2 "=d,wa"))]
6016 "TARGET_HARD_FLOAT && TARGET_LFIWZX && <SI_CONVERT_FP>"
6017 "#"
6018 "&& 1"
6019 [(pc)]
6020 {
6021 operands[1] = rs6000_force_indexed_or_indirect_mem (operands[1]);
6022 if (GET_CODE (operands[2]) == SCRATCH)
6023 operands[2] = gen_reg_rtx (DImode);
6024 if (TARGET_P8_VECTOR)
6025 emit_insn (gen_zero_extendsidi2 (operands[2], operands[1]));
6026 else
6027 emit_insn (gen_lfiwzx (operands[2], operands[1]));
6028 emit_insn (gen_floatdi<mode>2 (operands[0], operands[2]));
6029 DONE;
6030 }
6031 [(set_attr "length" "8")
6032 (set_attr "type" "fpload")])
6033
6034 ; For each of these conversions, there is a define_expand, a define_insn
6035 ; with a '#' template, and a define_split (with C code). The idea is
6036 ; to allow constant folding with the template of the define_insn,
6037 ; then to have the insns split later (between sched1 and final).
6038
6039 (define_expand "floatsidf2"
6040 [(parallel [(set (match_operand:DF 0 "gpc_reg_operand")
6041 (float:DF (match_operand:SI 1 "nonimmediate_operand")))
6042 (use (match_dup 2))
6043 (use (match_dup 3))
6044 (clobber (match_dup 4))
6045 (clobber (match_dup 5))
6046 (clobber (match_dup 6))])]
6047 "TARGET_HARD_FLOAT"
6048 {
6049 if (TARGET_LFIWAX && TARGET_FCFID)
6050 {
6051 emit_insn (gen_floatsidf2_lfiwax (operands[0], operands[1]));
6052 DONE;
6053 }
6054 else if (TARGET_FCFID)
6055 {
6056 rtx dreg = operands[1];
6057 if (!REG_P (dreg))
6058 dreg = force_reg (SImode, dreg);
6059 dreg = convert_to_mode (DImode, dreg, false);
6060 emit_insn (gen_floatdidf2 (operands[0], dreg));
6061 DONE;
6062 }
6063
6064 if (!REG_P (operands[1]))
6065 operands[1] = force_reg (SImode, operands[1]);
6066 operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6067 operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503601774854144\", DFmode));
6068 operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6069 operands[5] = gen_reg_rtx (DFmode);
6070 operands[6] = gen_reg_rtx (SImode);
6071 })
6072
6073 (define_insn_and_split "*floatsidf2_internal"
6074 [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6075 (float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6076 (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6077 (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6078 (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6079 (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))
6080 (clobber (match_operand:SI 6 "gpc_reg_operand" "=&r"))]
6081 "!TARGET_FCFID && TARGET_HARD_FLOAT"
6082 "#"
6083 "&& 1"
6084 [(pc)]
6085 {
6086 rtx lowword, highword;
6087 gcc_assert (MEM_P (operands[4]));
6088 highword = adjust_address (operands[4], SImode, 0);
6089 lowword = adjust_address (operands[4], SImode, 4);
6090 if (! WORDS_BIG_ENDIAN)
6091 std::swap (lowword, highword);
6092
6093 emit_insn (gen_xorsi3 (operands[6], operands[1],
6094 GEN_INT (~ (HOST_WIDE_INT) 0x7fffffff)));
6095 emit_move_insn (lowword, operands[6]);
6096 emit_move_insn (highword, operands[2]);
6097 emit_move_insn (operands[5], operands[4]);
6098 emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6099 DONE;
6100 }
6101 [(set_attr "length" "24")
6102 (set_attr "type" "fp")])
6103
6104 ;; If we don't have a direct conversion to single precision, don't enable this
6105 ;; conversion for 32-bit without fast math, because we don't have the insn to
6106 ;; generate the fixup swizzle to avoid double rounding problems.
6107 (define_expand "floatunssisf2"
6108 [(set (match_operand:SF 0 "gpc_reg_operand")
6109 (unsigned_float:SF (match_operand:SI 1 "nonimmediate_operand")))]
6110 "TARGET_HARD_FLOAT
6111 && ((TARGET_FCFIDUS && TARGET_LFIWZX)
6112 || (TARGET_FCFID
6113 && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))"
6114 {
6115 if (TARGET_LFIWZX && TARGET_FCFIDUS)
6116 {
6117 emit_insn (gen_floatunssisf2_lfiwzx (operands[0], operands[1]));
6118 DONE;
6119 }
6120 else
6121 {
6122 rtx dreg = operands[1];
6123 if (!REG_P (dreg))
6124 dreg = force_reg (SImode, dreg);
6125 dreg = convert_to_mode (DImode, dreg, true);
6126 emit_insn (gen_floatdisf2 (operands[0], dreg));
6127 DONE;
6128 }
6129 })
6130
6131 (define_expand "floatunssidf2"
6132 [(parallel [(set (match_operand:DF 0 "gpc_reg_operand")
6133 (unsigned_float:DF (match_operand:SI 1 "nonimmediate_operand")))
6134 (use (match_dup 2))
6135 (use (match_dup 3))
6136 (clobber (match_dup 4))
6137 (clobber (match_dup 5))])]
6138 "TARGET_HARD_FLOAT"
6139 {
6140 if (TARGET_LFIWZX && TARGET_FCFID)
6141 {
6142 emit_insn (gen_floatunssidf2_lfiwzx (operands[0], operands[1]));
6143 DONE;
6144 }
6145 else if (TARGET_FCFID)
6146 {
6147 rtx dreg = operands[1];
6148 if (!REG_P (dreg))
6149 dreg = force_reg (SImode, dreg);
6150 dreg = convert_to_mode (DImode, dreg, true);
6151 emit_insn (gen_floatdidf2 (operands[0], dreg));
6152 DONE;
6153 }
6154
6155 if (!REG_P (operands[1]))
6156 operands[1] = force_reg (SImode, operands[1]);
6157 operands[2] = force_reg (SImode, GEN_INT (0x43300000));
6158 operands[3] = force_reg (DFmode, CONST_DOUBLE_ATOF (\"4503599627370496\", DFmode));
6159 operands[4] = rs6000_allocate_stack_temp (DFmode, true, false);
6160 operands[5] = gen_reg_rtx (DFmode);
6161 })
6162
6163 (define_insn_and_split "*floatunssidf2_internal"
6164 [(set (match_operand:DF 0 "gpc_reg_operand" "=&d")
6165 (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "r")))
6166 (use (match_operand:SI 2 "gpc_reg_operand" "r"))
6167 (use (match_operand:DF 3 "gpc_reg_operand" "d"))
6168 (clobber (match_operand:DF 4 "offsettable_mem_operand" "=o"))
6169 (clobber (match_operand:DF 5 "gpc_reg_operand" "=&d"))]
6170 "!TARGET_FCFIDU && TARGET_HARD_FLOAT
6171 && !(TARGET_FCFID && TARGET_POWERPC64)"
6172 "#"
6173 "&& 1"
6174 [(pc)]
6175 {
6176 rtx lowword, highword;
6177 gcc_assert (MEM_P (operands[4]));
6178 highword = adjust_address (operands[4], SImode, 0);
6179 lowword = adjust_address (operands[4], SImode, 4);
6180 if (! WORDS_BIG_ENDIAN)
6181 std::swap (lowword, highword);
6182
6183 emit_move_insn (lowword, operands[1]);
6184 emit_move_insn (highword, operands[2]);
6185 emit_move_insn (operands[5], operands[4]);
6186 emit_insn (gen_subdf3 (operands[0], operands[5], operands[3]));
6187 DONE;
6188 }
6189 [(set_attr "length" "20")
6190 (set_attr "type" "fp")])
6191
6192 ;; ISA 3.0 adds instructions lxsi[bh]zx to directly load QImode and HImode to
6193 ;; vector registers. These insns favor doing the sign/zero extension in
6194 ;; the vector registers, rather then loading up a GPR, doing a sign/zero
6195 ;; extension and then a direct move.
6196
6197 (define_expand "float<QHI:mode><SFDF:mode>2"
6198 [(parallel [(set (match_operand:SFDF 0 "vsx_register_operand")
6199 (float:SFDF
6200 (match_operand:QHI 1 "input_operand")))
6201 (clobber (match_scratch:DI 2))
6202 (clobber (match_scratch:DI 3))
6203 (clobber (match_scratch:<QHI:MODE> 4))])]
6204 "TARGET_P9_VECTOR && TARGET_DIRECT_MOVE_64BIT"
6205 {
6206 if (MEM_P (operands[1]))
6207 operands[1] = rs6000_force_indexed_or_indirect_mem (operands[1]);
6208 })
6209
6210 (define_insn_and_split "*float<QHI:mode><SFDF:mode>2_internal"
6211 [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa,wa,wa")
6212 (float:SFDF
6213 (match_operand:QHI 1 "reg_or_indexed_operand" "v,r,Z")))
6214 (clobber (match_scratch:DI 2 "=v,wa,v"))
6215 (clobber (match_scratch:DI 3 "=X,r,X"))
6216 (clobber (match_scratch:<QHI:MODE> 4 "=X,X,v"))]
6217 "TARGET_P9_VECTOR && TARGET_DIRECT_MOVE_64BIT"
6218 "#"
6219 "&& reload_completed"
6220 [(const_int 0)]
6221 {
6222 rtx result = operands[0];
6223 rtx input = operands[1];
6224 rtx di = operands[2];
6225
6226 if (!MEM_P (input))
6227 {
6228 rtx tmp = operands[3];
6229 if (altivec_register_operand (input, <QHI:MODE>mode))
6230 emit_insn (gen_extend<QHI:mode>di2 (di, input));
6231 else if (GET_CODE (tmp) == SCRATCH)
6232 emit_insn (gen_extend<QHI:mode>di2 (di, input));
6233 else
6234 {
6235 emit_insn (gen_extend<QHI:mode>di2 (tmp, input));
6236 emit_move_insn (di, tmp);
6237 }
6238 }
6239 else
6240 {
6241 rtx tmp = operands[4];
6242 emit_move_insn (tmp, input);
6243 emit_insn (gen_extend<QHI:mode>di2 (di, tmp));
6244 }
6245
6246 emit_insn (gen_floatdi<SFDF:mode>2 (result, di));
6247 DONE;
6248 }
6249 [(set_attr "isa" "p9v,*,p9v")])
6250
6251 (define_expand "floatuns<QHI:mode><SFDF:mode>2"
6252 [(parallel [(set (match_operand:SFDF 0 "vsx_register_operand")
6253 (unsigned_float:SFDF
6254 (match_operand:QHI 1 "input_operand")))
6255 (clobber (match_scratch:DI 2))
6256 (clobber (match_scratch:DI 3))])]
6257 "TARGET_P9_VECTOR && TARGET_DIRECT_MOVE_64BIT"
6258 {
6259 if (MEM_P (operands[1]))
6260 operands[1] = rs6000_force_indexed_or_indirect_mem (operands[1]);
6261 })
6262
6263 (define_insn_and_split "*floatuns<QHI:mode><SFDF:mode>2_internal"
6264 [(set (match_operand:SFDF 0 "vsx_register_operand" "=wa,wa,wa")
6265 (unsigned_float:SFDF
6266 (match_operand:QHI 1 "reg_or_indexed_operand" "v,r,Z")))
6267 (clobber (match_scratch:DI 2 "=v,wa,wa"))
6268 (clobber (match_scratch:DI 3 "=X,r,X"))]
6269 "TARGET_P9_VECTOR && TARGET_DIRECT_MOVE_64BIT"
6270 "#"
6271 "&& reload_completed"
6272 [(const_int 0)]
6273 {
6274 rtx result = operands[0];
6275 rtx input = operands[1];
6276 rtx di = operands[2];
6277
6278 if (MEM_P (input) || altivec_register_operand (input, <QHI:MODE>mode))
6279 emit_insn (gen_zero_extend<QHI:mode>di2 (di, input));
6280 else
6281 {
6282 rtx tmp = operands[3];
6283 if (GET_CODE (tmp) == SCRATCH)
6284 emit_insn (gen_extend<QHI:mode>di2 (di, input));
6285 else
6286 {
6287 emit_insn (gen_zero_extend<QHI:mode>di2 (tmp, input));
6288 emit_move_insn (di, tmp);
6289 }
6290 }
6291
6292 emit_insn (gen_floatdi<SFDF:mode>2 (result, di));
6293 DONE;
6294 }
6295 [(set_attr "isa" "p9v,*,p9v")])
6296
6297 (define_expand "fix_trunc<mode>si2"
6298 [(set (match_operand:SI 0 "gpc_reg_operand")
6299 (fix:SI (match_operand:SFDF 1 "gpc_reg_operand")))]
6300 "TARGET_HARD_FLOAT"
6301 {
6302 if (!TARGET_DIRECT_MOVE)
6303 {
6304 rtx src = force_reg (<MODE>mode, operands[1]);
6305
6306 if (TARGET_STFIWX)
6307 emit_insn (gen_fix_trunc<mode>si2_stfiwx (operands[0], src));
6308 else
6309 {
6310 rtx tmp = gen_reg_rtx (DImode);
6311 rtx stack = rs6000_allocate_stack_temp (DImode, true, false);
6312 emit_insn (gen_fix_trunc<mode>si2_internal (operands[0], src,
6313 tmp, stack));
6314 }
6315 DONE;
6316 }
6317 })
6318
6319 ; Like the convert to float patterns, this insn must be split before
6320 ; register allocation so that it can allocate the memory slot if it
6321 ; needed
6322 (define_insn_and_split "fix_trunc<mode>si2_stfiwx"
6323 [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6324 (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6325 (clobber (match_scratch:DI 2 "=d"))]
6326 "TARGET_HARD_FLOAT && TARGET_STFIWX && can_create_pseudo_p ()
6327 && !TARGET_DIRECT_MOVE"
6328 "#"
6329 "&& 1"
6330 [(pc)]
6331 {
6332 rtx dest = operands[0];
6333 rtx src = operands[1];
6334 rtx tmp = operands[2];
6335
6336 if (GET_CODE (tmp) == SCRATCH)
6337 tmp = gen_reg_rtx (DImode);
6338
6339 emit_insn (gen_fctiwz_<mode> (tmp, src));
6340 if (MEM_P (dest) && (TARGET_MFCRF || MEM_ALIGN (dest) >= 32))
6341 {
6342 dest = rs6000_force_indexed_or_indirect_mem (dest);
6343 emit_insn (gen_stfiwx (dest, tmp));
6344 DONE;
6345 }
6346 else
6347 {
6348 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6349 emit_insn (gen_stfiwx (stack, tmp));
6350 emit_move_insn (dest, stack);
6351 DONE;
6352 }
6353 }
6354 [(set_attr "length" "12")
6355 (set_attr "type" "fp")])
6356
6357 (define_insn_and_split "fix_trunc<mode>si2_internal"
6358 [(set (match_operand:SI 0 "gpc_reg_operand" "=r,?r")
6359 (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,<rreg>")))
6360 (clobber (match_operand:DI 2 "gpc_reg_operand" "=1,d"))
6361 (clobber (match_operand:DI 3 "offsettable_mem_operand" "=o,o"))]
6362 "TARGET_HARD_FLOAT
6363 && !TARGET_DIRECT_MOVE"
6364 "#"
6365 "&& 1"
6366 [(pc)]
6367 {
6368 rtx lowword;
6369 gcc_assert (MEM_P (operands[3]));
6370 lowword = adjust_address (operands[3], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
6371
6372 emit_insn (gen_fctiwz_<mode> (operands[2], operands[1]));
6373 emit_move_insn (operands[3], operands[2]);
6374 emit_move_insn (operands[0], lowword);
6375 DONE;
6376 }
6377 [(set_attr "length" "16")
6378 (set_attr "type" "fp")])
6379
6380 (define_expand "fix_trunc<mode>di2"
6381 [(set (match_operand:DI 0 "gpc_reg_operand")
6382 (fix:DI (match_operand:SFDF 1 "gpc_reg_operand")))]
6383 "TARGET_HARD_FLOAT && TARGET_FCFID"
6384 "")
6385
6386 (define_insn "*fix_trunc<mode>di2_fctidz"
6387 [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wa")
6388 (fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")))]
6389 "TARGET_HARD_FLOAT && TARGET_FCFID"
6390 "@
6391 fctidz %0,%1
6392 xscvdpsxds %x0,%x1"
6393 [(set_attr "type" "fp")])
6394
6395 ;; If we have ISA 3.0, QI/HImode values can go in both VSX registers and GPR
6396 ;; registers. If we have ISA 2.07, we don't allow QI/HImode values in the
6397 ;; vector registers, so we need to do direct moves to the GPRs, but SImode
6398 ;; values can go in VSX registers. Keeping the direct move part through
6399 ;; register allocation prevents the register allocator from doing a direct move
6400 ;; of the SImode value to a GPR, and then a store/load.
6401 (define_insn_and_split "fix<uns>_trunc<SFDF:mode><QHI:mode>2"
6402 [(set (match_operand:<QHI:MODE> 0 "gpc_reg_operand" "=d,wa,r")
6403 (any_fix:QHI (match_operand:SFDF 1 "gpc_reg_operand" "d,wa,wa")))
6404 (clobber (match_scratch:SI 2 "=X,X,wa"))]
6405 "TARGET_DIRECT_MOVE"
6406 "@
6407 fctiw<u>z %0,%1
6408 xscvdp<su>xws %x0,%x1
6409 #"
6410 "&& reload_completed && int_reg_operand (operands[0], <QHI:MODE>mode)"
6411 [(set (match_dup 2)
6412 (any_fix:SI (match_dup 1)))
6413 (set (match_dup 3)
6414 (match_dup 2))]
6415 {
6416 operands[3] = gen_rtx_REG (SImode, REGNO (operands[0]));
6417 }
6418 [(set_attr "type" "fp")
6419 (set_attr "length" "4,4,8")
6420 (set_attr "isa" "p9v,p9v,*")])
6421
6422 (define_insn "*fix<uns>_trunc<SFDF:mode>si2_p8"
6423 [(set (match_operand:SI 0 "gpc_reg_operand" "=d,wa")
6424 (any_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")))]
6425 "TARGET_DIRECT_MOVE"
6426 "@
6427 fctiw<u>z %0,%1
6428 xscvdp<su>xws %x0,%x1"
6429 [(set_attr "type" "fp")])
6430
6431 ;; Keep the convert and store together through register allocation to prevent
6432 ;; the register allocator from getting clever and doing a direct move to a GPR
6433 ;; and then store for reg+offset stores.
6434 (define_insn_and_split "*fix<uns>_trunc<SFDF:mode><QHSI:mode>2_mem"
6435 [(set (match_operand:QHSI 0 "memory_operand" "=Z")
6436 (any_fix:QHSI (match_operand:SFDF 1 "gpc_reg_operand" "wa")))
6437 (clobber (match_scratch:SI 2 "=wa"))]
6438 "(<QHSI:MODE>mode == SImode && TARGET_P8_VECTOR) || TARGET_P9_VECTOR"
6439 "#"
6440 "&& reload_completed"
6441 [(set (match_dup 2)
6442 (any_fix:SI (match_dup 1)))
6443 (set (match_dup 0)
6444 (match_dup 3))]
6445 {
6446 operands[3] = (<QHSI:MODE>mode == SImode
6447 ? operands[2]
6448 : gen_rtx_REG (<QHSI:MODE>mode, REGNO (operands[2])));
6449 })
6450
6451 (define_expand "fixuns_trunc<mode>si2"
6452 [(set (match_operand:SI 0 "gpc_reg_operand")
6453 (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand")))]
6454 "TARGET_HARD_FLOAT && TARGET_FCTIWUZ && TARGET_STFIWX"
6455 {
6456 if (!TARGET_P8_VECTOR)
6457 {
6458 emit_insn (gen_fixuns_trunc<mode>si2_stfiwx (operands[0], operands[1]));
6459 DONE;
6460 }
6461 })
6462
6463 (define_insn_and_split "fixuns_trunc<mode>si2_stfiwx"
6464 [(set (match_operand:SI 0 "nonimmediate_operand" "=rm")
6465 (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d")))
6466 (clobber (match_scratch:DI 2 "=d"))]
6467 "TARGET_HARD_FLOAT && TARGET_FCTIWUZ
6468 && TARGET_STFIWX && can_create_pseudo_p ()
6469 && !TARGET_DIRECT_MOVE"
6470 "#"
6471 "&& 1"
6472 [(pc)]
6473 {
6474 rtx dest = operands[0];
6475 rtx src = operands[1];
6476 rtx tmp = operands[2];
6477
6478 if (GET_CODE (tmp) == SCRATCH)
6479 tmp = gen_reg_rtx (DImode);
6480
6481 emit_insn (gen_fctiwuz_<mode> (tmp, src));
6482 if (MEM_P (dest))
6483 {
6484 dest = rs6000_force_indexed_or_indirect_mem (dest);
6485 emit_insn (gen_stfiwx (dest, tmp));
6486 DONE;
6487 }
6488 else
6489 {
6490 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6491 emit_insn (gen_stfiwx (stack, tmp));
6492 emit_move_insn (dest, stack);
6493 DONE;
6494 }
6495 }
6496 [(set_attr "length" "12")
6497 (set_attr "type" "fp")])
6498
6499 (define_insn "fixuns_trunc<mode>di2"
6500 [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wa")
6501 (unsigned_fix:DI (match_operand:SFDF 1 "gpc_reg_operand" "d,wa")))]
6502 "TARGET_HARD_FLOAT && TARGET_FCTIDUZ"
6503 "@
6504 fctiduz %0,%1
6505 xscvdpuxds %x0,%x1"
6506 [(set_attr "type" "fp")])
6507
6508 (define_insn "rs6000_mtfsb0"
6509 [(unspec_volatile [(match_operand:SI 0 "u5bit_cint_operand" "n")]
6510 UNSPECV_MTFSB0)]
6511 "TARGET_HARD_FLOAT"
6512 "mtfsb0 %0"
6513 [(set_attr "type" "fp")])
6514
6515 (define_insn "rs6000_mtfsb1"
6516 [(unspec_volatile [(match_operand:SI 0 "u5bit_cint_operand" "n")]
6517 UNSPECV_MTFSB1)]
6518 "TARGET_HARD_FLOAT"
6519 "mtfsb1 %0"
6520 [(set_attr "type" "fp")])
6521
6522 (define_insn "rs6000_mffscrn"
6523 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6524 (unspec_volatile:DF [(match_operand:DF 1 "gpc_reg_operand" "d")]
6525 UNSPECV_MFFSCRN))]
6526 "TARGET_P9_MISC"
6527 "mffscrn %0,%1"
6528 [(set_attr "type" "fp")])
6529
6530 (define_insn "rs6000_mffscrni"
6531 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6532 (unspec_volatile:DF [(match_operand:SI 1 "const_0_to_3_operand" "n")]
6533 UNSPECV_MFFSCRN))]
6534 "TARGET_P9_MISC"
6535 "mffscrni %0,%1"
6536 [(set_attr "type" "fp")])
6537
6538 (define_insn "rs6000_mffscdrn"
6539 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
6540 (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFSCDRN))
6541 (use (match_operand:DF 1 "gpc_reg_operand" "d"))]
6542 "TARGET_P9_MISC"
6543 "mffscdrn %0,%1"
6544 [(set_attr "type" "fp")])
6545
6546 (define_expand "rs6000_set_fpscr_rn"
6547 [(use (match_operand:DF 0 "gpc_reg_operand"))
6548 (use (match_operand:SI 1 "reg_or_cint_operand"))]
6549 "TARGET_HARD_FLOAT"
6550 {
6551 rtx tmp_df = gen_reg_rtx (DFmode);
6552
6553 /* The floating point rounding control bits are FPSCR[62:63]. Put the
6554 new rounding mode bits from operands[0][62:63] into FPSCR[62:63]. */
6555 if (TARGET_P9_MISC)
6556 {
6557 if (const_0_to_3_operand (operands[1], VOIDmode))
6558 emit_insn (gen_rs6000_mffscrni (tmp_df, operands[1]));
6559 else
6560 {
6561 rtx op1 = convert_to_mode (DImode, operands[1], false);
6562 rtx src_df = simplify_gen_subreg (DFmode, op1, DImode, 0);
6563 emit_insn (gen_rs6000_mffscrn (tmp_df, src_df));
6564 }
6565 emit_move_insn (operands[0], tmp_df);
6566 DONE;
6567 }
6568
6569 /* Emulate the behavior of the mffscrni, mffscrn instructions for earlier
6570 ISAs. Return bits 29:31 (DRN) and bits 56:63 (VE, OE, UE, ZE, XE, NI,
6571 RN) from the FPSCR. Set the RN field based on the value in operands[1].
6572 */
6573
6574 /* Get the current FPSCR fields, bits 29:31 (DRN) and bits 56:63 (VE, OE, UE,
6575 ZE, XE, NI, RN) from the FPSCR and return them. */
6576
6577 emit_insn (gen_rs6000_mffs (tmp_df));
6578 rtx orig_df_in_di = simplify_gen_subreg (DImode, tmp_df, DFmode, 0);
6579 rtx tmp_di1 = gen_reg_rtx (DImode);
6580 emit_insn (gen_anddi3 (tmp_di1, orig_df_in_di,
6581 GEN_INT (0x00000007000000FFULL)));
6582 rtx tmp_rtn = simplify_gen_subreg (DFmode, tmp_di1, DImode, 0);
6583 emit_move_insn (operands[0], tmp_rtn);
6584
6585 if (CONST_INT_P (operands[1]))
6586 {
6587 if ((INTVAL (operands[1]) & 0x1) == 0x1)
6588 emit_insn (gen_rs6000_mtfsb1 (GEN_INT (31)));
6589 else
6590 emit_insn (gen_rs6000_mtfsb0 (GEN_INT (31)));
6591
6592 if ((INTVAL (operands[1]) & 0x2) == 0x2)
6593 emit_insn (gen_rs6000_mtfsb1 (GEN_INT (30)));
6594 else
6595 emit_insn (gen_rs6000_mtfsb0 (GEN_INT (30)));
6596 }
6597 else
6598 {
6599 /* Extract new RN mode from operand. */
6600 rtx op1 = convert_to_mode (DImode, operands[1], false);
6601 rtx tmp_rn = gen_reg_rtx (DImode);
6602 emit_insn (gen_anddi3 (tmp_rn, op1, GEN_INT (3)));
6603
6604 /* Insert the new RN value from tmp_rn into FPSCR bit [62:63]. */
6605 rtx tmp_di1 = gen_reg_rtx (DImode);
6606 emit_insn (gen_anddi3 (tmp_di1, orig_df_in_di, GEN_INT (-4)));
6607 rtx tmp_di2 = gen_reg_rtx (DImode);
6608 emit_insn (gen_iordi3 (tmp_di2, tmp_di1, tmp_rn));
6609
6610 /* Need to write to field k=15. The fields are [0:15]. Hence with
6611 L=0, W=0, FLM_i must be equal to 8, 16 = i + 8*(1-W). FLM is an
6612 8-bit field[0:7]. Need to set the bit that corresponds to the
6613 value of i that you want [0:7]. */
6614 tmp_df = simplify_gen_subreg (DFmode, tmp_di2, DImode, 0);
6615 emit_insn (gen_rs6000_mtfsf (GEN_INT (0x01), tmp_df));
6616 }
6617 DONE;
6618 })
6619
6620 (define_expand "rs6000_set_fpscr_drn"
6621 [(match_operand:DI 0 "gpc_reg_operand")]
6622 "TARGET_HARD_FLOAT"
6623 {
6624 rtx tmp_df = gen_reg_rtx (DFmode);
6625
6626 /* The decimal floating point rounding control bits are FPSCR[29:31]. Put the
6627 new rounding mode bits from operands[0][61:63] into FPSCR[29:31]. */
6628 if (TARGET_P9_MISC)
6629 {
6630 rtx src_df = gen_reg_rtx (DFmode);
6631
6632 emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT (32)));
6633 src_df = simplify_gen_subreg (DFmode, operands[0], DImode, 0);
6634 emit_insn (gen_rs6000_mffscdrn (tmp_df, src_df));
6635 }
6636 else
6637 {
6638 rtx tmp_rn = gen_reg_rtx (DImode);
6639 rtx tmp_di = gen_reg_rtx (DImode);
6640
6641 /* Extract new DRN mode from operand. */
6642 emit_insn (gen_anddi3 (tmp_rn, operands[0], GEN_INT (0x7)));
6643 emit_insn (gen_ashldi3 (tmp_rn, tmp_rn, GEN_INT (32)));
6644
6645 /* Insert new RN mode into FSCPR. */
6646 emit_insn (gen_rs6000_mffs (tmp_df));
6647 tmp_di = simplify_gen_subreg (DImode, tmp_df, DFmode, 0);
6648 emit_insn (gen_anddi3 (tmp_di, tmp_di, GEN_INT (0xFFFFFFF8FFFFFFFFULL)));
6649 emit_insn (gen_iordi3 (tmp_di, tmp_di, tmp_rn));
6650
6651 /* Need to write to field 7. The fields are [0:15]. The equation to
6652 select the field is i + 8*(1-W). Hence with L=0 and W=1, need to set
6653 i to 0x1 to get field 7 where i selects the field. */
6654 tmp_df = simplify_gen_subreg (DFmode, tmp_di, DImode, 0);
6655 emit_insn (gen_rs6000_mtfsf_hi (GEN_INT (0x01), tmp_df));
6656 }
6657 DONE;
6658 })
6659
6660 ;; Here, we use (set (reg) (unspec:DI [(fix:SI ...)] UNSPEC_FCTIWZ))
6661 ;; rather than (set (subreg:SI (reg)) (fix:SI ...))
6662 ;; because the first makes it clear that operand 0 is not live
6663 ;; before the instruction.
6664 (define_insn "fctiwz_<mode>"
6665 [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wa")
6666 (unspec:DI [(fix:SI
6667 (match_operand:SFDF 1 "gpc_reg_operand" "d,wa"))]
6668 UNSPEC_FCTIWZ))]
6669 "TARGET_HARD_FLOAT"
6670 "@
6671 fctiwz %0,%1
6672 xscvdpsxws %x0,%x1"
6673 [(set_attr "type" "fp")])
6674
6675 (define_insn "fctiwuz_<mode>"
6676 [(set (match_operand:DI 0 "gpc_reg_operand" "=d,wa")
6677 (unspec:DI [(unsigned_fix:SI
6678 (match_operand:SFDF 1 "gpc_reg_operand" "d,wa"))]
6679 UNSPEC_FCTIWUZ))]
6680 "TARGET_HARD_FLOAT && TARGET_FCTIWUZ"
6681 "@
6682 fctiwuz %0,%1
6683 xscvdpuxws %x0,%x1"
6684 [(set_attr "type" "fp")])
6685
6686 ;; Only optimize (float (fix x)) -> frz if we are in fast-math mode, since
6687 ;; since the friz instruction does not truncate the value if the floating
6688 ;; point value is < LONG_MIN or > LONG_MAX.
6689 (define_insn "*friz"
6690 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,wa")
6691 (float:DF (fix:DI (match_operand:DF 1 "gpc_reg_operand" "d,wa"))))]
6692 "TARGET_HARD_FLOAT && TARGET_FPRND
6693 && flag_unsafe_math_optimizations && !flag_trapping_math && TARGET_FRIZ"
6694 "@
6695 friz %0,%1
6696 xsrdpiz %x0,%x1"
6697 [(set_attr "type" "fp")])
6698
6699 ;; Opitmize converting SF/DFmode to signed SImode and back to SF/DFmode. This
6700 ;; optimization prevents on ISA 2.06 systems and earlier having to store the
6701 ;; value from the FPR/vector unit to the stack, load the value into a GPR, sign
6702 ;; extend it, store it back on the stack from the GPR, load it back into the
6703 ;; FP/vector unit to do the rounding. If we have direct move (ISA 2.07),
6704 ;; disable using store and load to sign/zero extend the value.
6705 (define_insn_and_split "*round32<mode>2_fprs"
6706 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6707 (float:SFDF
6708 (fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6709 (clobber (match_scratch:DI 2 "=d"))
6710 (clobber (match_scratch:DI 3 "=d"))]
6711 "TARGET_HARD_FLOAT
6712 && <SI_CONVERT_FP> && TARGET_LFIWAX && TARGET_STFIWX && TARGET_FCFID
6713 && !TARGET_DIRECT_MOVE && can_create_pseudo_p ()"
6714 "#"
6715 "&& 1"
6716 [(pc)]
6717 {
6718 rtx dest = operands[0];
6719 rtx src = operands[1];
6720 rtx tmp1 = operands[2];
6721 rtx tmp2 = operands[3];
6722 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6723
6724 if (GET_CODE (tmp1) == SCRATCH)
6725 tmp1 = gen_reg_rtx (DImode);
6726 if (GET_CODE (tmp2) == SCRATCH)
6727 tmp2 = gen_reg_rtx (DImode);
6728
6729 emit_insn (gen_fctiwz_<mode> (tmp1, src));
6730 emit_insn (gen_stfiwx (stack, tmp1));
6731 emit_insn (gen_lfiwax (tmp2, stack));
6732 emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6733 DONE;
6734 }
6735 [(set_attr "type" "fpload")
6736 (set_attr "length" "16")])
6737
6738 (define_insn_and_split "*roundu32<mode>2_fprs"
6739 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d")
6740 (unsigned_float:SFDF
6741 (unsigned_fix:SI (match_operand:SFDF 1 "gpc_reg_operand" "d"))))
6742 (clobber (match_scratch:DI 2 "=d"))
6743 (clobber (match_scratch:DI 3 "=d"))]
6744 "TARGET_HARD_FLOAT
6745 && TARGET_LFIWZX && TARGET_STFIWX && TARGET_FCFIDU && !TARGET_DIRECT_MOVE
6746 && can_create_pseudo_p ()"
6747 "#"
6748 "&& 1"
6749 [(pc)]
6750 {
6751 rtx dest = operands[0];
6752 rtx src = operands[1];
6753 rtx tmp1 = operands[2];
6754 rtx tmp2 = operands[3];
6755 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6756
6757 if (GET_CODE (tmp1) == SCRATCH)
6758 tmp1 = gen_reg_rtx (DImode);
6759 if (GET_CODE (tmp2) == SCRATCH)
6760 tmp2 = gen_reg_rtx (DImode);
6761
6762 emit_insn (gen_fctiwuz_<mode> (tmp1, src));
6763 emit_insn (gen_stfiwx (stack, tmp1));
6764 emit_insn (gen_lfiwzx (tmp2, stack));
6765 emit_insn (gen_floatdi<mode>2 (dest, tmp2));
6766 DONE;
6767 }
6768 [(set_attr "type" "fpload")
6769 (set_attr "length" "16")])
6770
6771 ;; No VSX equivalent to fctid
6772 (define_insn "lrint<mode>di2"
6773 [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6774 (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6775 UNSPEC_FCTID))]
6776 "TARGET_HARD_FLOAT && TARGET_FCTID"
6777 "fctid %0,%1"
6778 [(set_attr "type" "fp")])
6779
6780 (define_expand "lrint<mode>si2"
6781 [(set (match_operand:SI 0 "gpc_reg_operand" "=d")
6782 (unspec:SI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6783 UNSPEC_FCTIW))]
6784 "TARGET_HARD_FLOAT && TARGET_STFIWX"
6785 {
6786 /* For those old archs in which SImode can't be hold in float registers,
6787 call lrint<mode>si_di to put the result in DImode then convert it via
6788 stack. */
6789 if (!TARGET_POPCNTD)
6790 {
6791 rtx tmp = gen_reg_rtx (DImode);
6792 emit_insn (gen_lrint<mode>si_di (tmp, operands[1]));
6793 rtx stack = rs6000_allocate_stack_temp (SImode, false, true);
6794 emit_insn (gen_stfiwx (stack, tmp));
6795 emit_move_insn (operands[0], stack);
6796 DONE;
6797 }
6798 })
6799
6800 (define_insn "*lrint<mode>si"
6801 [(set (match_operand:SI 0 "gpc_reg_operand" "=d")
6802 (unspec:SI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6803 UNSPEC_FCTIW))]
6804 "TARGET_HARD_FLOAT && TARGET_POPCNTD"
6805 "fctiw %0,%1"
6806 [(set_attr "type" "fp")])
6807
6808 (define_insn "lrint<mode>si_di"
6809 [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
6810 (unspec:DI [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6811 UNSPEC_FCTIW))]
6812 "TARGET_HARD_FLOAT && !TARGET_POPCNTD"
6813 "fctiw %0,%1"
6814 [(set_attr "type" "fp")])
6815
6816 (define_insn "btrunc<mode>2"
6817 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
6818 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "d,wa")]
6819 UNSPEC_FRIZ))]
6820 "TARGET_HARD_FLOAT && TARGET_FPRND"
6821 "@
6822 friz %0,%1
6823 xsrdpiz %x0,%x1"
6824 [(set_attr "type" "fp")])
6825
6826 (define_insn "ceil<mode>2"
6827 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
6828 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "d,wa")]
6829 UNSPEC_FRIP))]
6830 "TARGET_HARD_FLOAT && TARGET_FPRND"
6831 "@
6832 frip %0,%1
6833 xsrdpip %x0,%x1"
6834 [(set_attr "type" "fp")])
6835
6836 (define_insn "floor<mode>2"
6837 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa")
6838 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "d,wa")]
6839 UNSPEC_FRIM))]
6840 "TARGET_HARD_FLOAT && TARGET_FPRND"
6841 "@
6842 frim %0,%1
6843 xsrdpim %x0,%x1"
6844 [(set_attr "type" "fp")])
6845
6846 ;; No VSX equivalent to frin
6847 (define_insn "round<mode>2"
6848 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=<rreg2>")
6849 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "<rreg2>")]
6850 UNSPEC_FRIN))]
6851 "TARGET_HARD_FLOAT && TARGET_FPRND"
6852 "frin %0,%1"
6853 [(set_attr "type" "fp")])
6854
6855 (define_insn "*xsrdpi<mode>2"
6856 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=wa")
6857 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" "wa")]
6858 UNSPEC_XSRDPI))]
6859 "TARGET_HARD_FLOAT && TARGET_VSX"
6860 "xsrdpi %x0,%x1"
6861 [(set_attr "type" "fp")])
6862
6863 (define_expand "lround<mode>di2"
6864 [(set (match_dup 2)
6865 (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand")]
6866 UNSPEC_XSRDPI))
6867 (set (match_operand:DI 0 "gpc_reg_operand")
6868 (unspec:DI [(match_dup 2)]
6869 UNSPEC_FCTID))]
6870 "TARGET_HARD_FLOAT && TARGET_VSX && TARGET_FCTID"
6871 {
6872 operands[2] = gen_reg_rtx (<MODE>mode);
6873 })
6874
6875 ; An UNSPEC is used so we don't have to support SImode in FP registers.
6876 (define_insn "stfiwx"
6877 [(set (match_operand:SI 0 "memory_operand" "=Z,Z")
6878 (unspec:SI [(match_operand:DI 1 "gpc_reg_operand" "d,wa")]
6879 UNSPEC_STFIWX))]
6880 "TARGET_PPC_GFXOPT"
6881 "@
6882 stfiwx %1,%y0
6883 stxsiwx %x1,%y0"
6884 [(set_attr "type" "fpstore")
6885 (set_attr "isa" "*,p8v")])
6886
6887 ;; If we don't have a direct conversion to single precision, don't enable this
6888 ;; conversion for 32-bit without fast math, because we don't have the insn to
6889 ;; generate the fixup swizzle to avoid double rounding problems.
6890 (define_expand "floatsisf2"
6891 [(set (match_operand:SF 0 "gpc_reg_operand")
6892 (float:SF (match_operand:SI 1 "nonimmediate_operand")))]
6893 "TARGET_HARD_FLOAT
6894 && ((TARGET_FCFIDS && TARGET_LFIWAX)
6895 || (TARGET_FCFID
6896 && (TARGET_POWERPC64 || flag_unsafe_math_optimizations)))"
6897 {
6898 if (TARGET_FCFIDS && TARGET_LFIWAX)
6899 {
6900 emit_insn (gen_floatsisf2_lfiwax (operands[0], operands[1]));
6901 DONE;
6902 }
6903 else if (TARGET_FCFID && TARGET_LFIWAX)
6904 {
6905 rtx dfreg = gen_reg_rtx (DFmode);
6906 emit_insn (gen_floatsidf2_lfiwax (dfreg, operands[1]));
6907 emit_insn (gen_truncdfsf2 (operands[0], dfreg));
6908 DONE;
6909 }
6910 else
6911 {
6912 rtx dreg = operands[1];
6913 if (!REG_P (dreg))
6914 dreg = force_reg (SImode, dreg);
6915 dreg = convert_to_mode (DImode, dreg, false);
6916 emit_insn (gen_floatdisf2 (operands[0], dreg));
6917 DONE;
6918 }
6919 })
6920
6921 (define_insn "floatdidf2"
6922 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,wa")
6923 (float:DF (match_operand:DI 1 "gpc_reg_operand" "d,wa")))]
6924 "TARGET_FCFID && TARGET_HARD_FLOAT"
6925 "@
6926 fcfid %0,%1
6927 xscvsxddp %x0,%x1"
6928 [(set_attr "type" "fp")])
6929
6930 (define_insn "floatti<mode>2"
6931 [(set (match_operand:IEEE128 0 "vsx_register_operand" "=v")
6932 (float:IEEE128 (match_operand:TI 1 "vsx_register_operand" "v")))]
6933 "TARGET_POWER10 && TARGET_FLOAT128_HW"
6934 {
6935 return "xscvsqqp %0,%1";
6936 }
6937 [(set_attr "type" "fp")])
6938
6939 (define_insn "floatunsti<mode>2"
6940 [(set (match_operand:IEEE128 0 "vsx_register_operand" "=v")
6941 (unsigned_float:IEEE128 (match_operand:TI 1 "vsx_register_operand" "v")))]
6942 "TARGET_POWER10 && TARGET_FLOAT128_HW"
6943 {
6944 return "xscvuqqp %0,%1";
6945 }
6946 [(set_attr "type" "fp")])
6947
6948 (define_insn "fix_trunc<mode>ti2"
6949 [(set (match_operand:TI 0 "vsx_register_operand" "=v")
6950 (fix:TI (match_operand:IEEE128 1 "vsx_register_operand" "v")))]
6951 "TARGET_POWER10 && TARGET_FLOAT128_HW"
6952 {
6953 return "xscvqpsqz %0,%1";
6954 }
6955 [(set_attr "type" "fp")])
6956
6957 (define_insn "fixuns_trunc<mode>ti2"
6958 [(set (match_operand:TI 0 "vsx_register_operand" "=v")
6959 (unsigned_fix:TI (match_operand:IEEE128 1 "vsx_register_operand" "v")))]
6960 "TARGET_POWER10"
6961 {
6962 return "xscvqpuqz %0,%1";
6963 }
6964 [(set_attr "type" "fp")])
6965
6966 ; Allow the combiner to merge source memory operands to the conversion so that
6967 ; the optimizer/register allocator doesn't try to load the value too early in a
6968 ; GPR and then use store/load to move it to a FPR and suffer from a store-load
6969 ; hit. We will split after reload to avoid the trip through the GPRs
6970
6971 (define_insn_and_split "*floatdidf2_mem"
6972 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,wa")
6973 (float:DF (match_operand:DI 1 "memory_operand" "m,Z")))
6974 (clobber (match_scratch:DI 2 "=d,wa"))]
6975 "TARGET_HARD_FLOAT && TARGET_FCFID"
6976 "#"
6977 "&& reload_completed"
6978 [(set (match_dup 2) (match_dup 1))
6979 (set (match_dup 0) (float:DF (match_dup 2)))]
6980 ""
6981 [(set_attr "length" "8")
6982 (set_attr "type" "fpload")])
6983
6984 (define_expand "floatunsdidf2"
6985 [(set (match_operand:DF 0 "gpc_reg_operand")
6986 (unsigned_float:DF
6987 (match_operand:DI 1 "gpc_reg_operand")))]
6988 "TARGET_HARD_FLOAT && TARGET_FCFIDU"
6989 "")
6990
6991 (define_insn "*floatunsdidf2_fcfidu"
6992 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,wa")
6993 (unsigned_float:DF (match_operand:DI 1 "gpc_reg_operand" "d,wa")))]
6994 "TARGET_HARD_FLOAT && TARGET_FCFIDU"
6995 "@
6996 fcfidu %0,%1
6997 xscvuxddp %x0,%x1"
6998 [(set_attr "type" "fp")])
6999
7000 (define_insn_and_split "*floatunsdidf2_mem"
7001 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,wa")
7002 (unsigned_float:DF (match_operand:DI 1 "memory_operand" "m,Z")))
7003 (clobber (match_scratch:DI 2 "=d,wa"))]
7004 "TARGET_HARD_FLOAT && (TARGET_FCFIDU || VECTOR_UNIT_VSX_P (DFmode))"
7005 "#"
7006 "&& reload_completed"
7007 [(set (match_dup 2) (match_dup 1))
7008 (set (match_dup 0) (unsigned_float:DF (match_dup 2)))]
7009 ""
7010 [(set_attr "length" "8")
7011 (set_attr "type" "fpload")])
7012
7013 (define_expand "floatdisf2"
7014 [(set (match_operand:SF 0 "gpc_reg_operand")
7015 (float:SF (match_operand:DI 1 "gpc_reg_operand")))]
7016 "TARGET_FCFID && TARGET_HARD_FLOAT
7017 && (TARGET_FCFIDS || TARGET_POWERPC64 || flag_unsafe_math_optimizations)"
7018 {
7019 if (!TARGET_FCFIDS)
7020 {
7021 rtx val = operands[1];
7022 if (!flag_unsafe_math_optimizations)
7023 {
7024 rtx label = gen_label_rtx ();
7025 val = gen_reg_rtx (DImode);
7026 emit_insn (gen_floatdisf2_internal2 (val, operands[1], label));
7027 emit_label (label);
7028 }
7029 emit_insn (gen_floatdisf2_internal1 (operands[0], val));
7030 DONE;
7031 }
7032 })
7033
7034 (define_insn "floatdisf2_fcfids"
7035 [(set (match_operand:SF 0 "gpc_reg_operand" "=f,wa")
7036 (float:SF (match_operand:DI 1 "gpc_reg_operand" "d,wa")))]
7037 "TARGET_HARD_FLOAT && TARGET_FCFIDS"
7038 "@
7039 fcfids %0,%1
7040 xscvsxdsp %x0,%x1"
7041 [(set_attr "type" "fp")
7042 (set_attr "isa" "*,p8v")])
7043
7044 (define_insn_and_split "*floatdisf2_mem"
7045 [(set (match_operand:SF 0 "gpc_reg_operand" "=f,wa,wa")
7046 (float:SF (match_operand:DI 1 "memory_operand" "m,m,Z")))
7047 (clobber (match_scratch:DI 2 "=d,d,wa"))]
7048 "TARGET_HARD_FLOAT && TARGET_FCFIDS"
7049 "#"
7050 "&& reload_completed"
7051 [(pc)]
7052 {
7053 emit_move_insn (operands[2], operands[1]);
7054 emit_insn (gen_floatdisf2_fcfids (operands[0], operands[2]));
7055 DONE;
7056 }
7057 [(set_attr "length" "8")
7058 (set_attr "isa" "*,p8v,p8v")])
7059
7060 ;; This is not IEEE compliant if rounding mode is "round to nearest".
7061 ;; If the DI->DF conversion is inexact, then it's possible to suffer
7062 ;; from double rounding.
7063 ;; Instead of creating a new cpu type for two FP operations, just use fp
7064 (define_insn_and_split "floatdisf2_internal1"
7065 [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
7066 (float:SF (match_operand:DI 1 "gpc_reg_operand" "d")))
7067 (clobber (match_scratch:DF 2 "=d"))]
7068 "TARGET_FCFID && TARGET_HARD_FLOAT && !TARGET_FCFIDS"
7069 "#"
7070 "&& reload_completed"
7071 [(set (match_dup 2)
7072 (float:DF (match_dup 1)))
7073 (set (match_dup 0)
7074 (float_truncate:SF (match_dup 2)))]
7075 ""
7076 [(set_attr "length" "8")
7077 (set_attr "type" "fp")])
7078
7079 ;; Twiddles bits to avoid double rounding.
7080 ;; Bits that might be truncated when converting to DFmode are replaced
7081 ;; by a bit that won't be lost at that stage, but is below the SFmode
7082 ;; rounding position.
7083 (define_expand "floatdisf2_internal2"
7084 [(parallel [(set (match_dup 3) (ashiftrt:DI (match_operand:DI 1 "")
7085 (const_int 53)))
7086 (clobber (reg:DI CA_REGNO))])
7087 (set (match_operand:DI 0 "") (and:DI (match_dup 1)
7088 (const_int 2047)))
7089 (set (match_dup 3) (plus:DI (match_dup 3)
7090 (const_int 1)))
7091 (set (match_dup 0) (plus:DI (match_dup 0)
7092 (const_int 2047)))
7093 (set (match_dup 4) (compare:CCUNS (match_dup 3)
7094 (const_int 2)))
7095 (set (match_dup 0) (ior:DI (match_dup 0)
7096 (match_dup 1)))
7097 (set (match_dup 0) (and:DI (match_dup 0)
7098 (const_int -2048)))
7099 (set (pc) (if_then_else (geu (match_dup 4) (const_int 0))
7100 (label_ref (match_operand:DI 2 ""))
7101 (pc)))
7102 (set (match_dup 0) (match_dup 1))]
7103 "TARGET_POWERPC64 && TARGET_HARD_FLOAT && !TARGET_FCFIDS"
7104 {
7105 operands[3] = gen_reg_rtx (DImode);
7106 operands[4] = gen_reg_rtx (CCUNSmode);
7107 })
7108
7109 (define_expand "floatunsdisf2"
7110 [(set (match_operand:SF 0 "gpc_reg_operand")
7111 (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand")))]
7112 "TARGET_HARD_FLOAT && TARGET_FCFIDUS"
7113 "")
7114
7115 (define_insn "floatunsdisf2_fcfidus"
7116 [(set (match_operand:SF 0 "gpc_reg_operand" "=f,wa")
7117 (unsigned_float:SF (match_operand:DI 1 "gpc_reg_operand" "d,wa")))]
7118 "TARGET_HARD_FLOAT && TARGET_FCFIDUS"
7119 "@
7120 fcfidus %0,%1
7121 xscvuxdsp %x0,%x1"
7122 [(set_attr "type" "fp")
7123 (set_attr "isa" "*,p8v")])
7124
7125 (define_insn_and_split "*floatunsdisf2_mem"
7126 [(set (match_operand:SF 0 "gpc_reg_operand" "=f,wa,wa")
7127 (unsigned_float:SF (match_operand:DI 1 "memory_operand" "m,m,Z")))
7128 (clobber (match_scratch:DI 2 "=d,d,wa"))]
7129 "TARGET_HARD_FLOAT && TARGET_FCFIDUS"
7130 "#"
7131 "&& reload_completed"
7132 [(pc)]
7133 {
7134 emit_move_insn (operands[2], operands[1]);
7135 emit_insn (gen_floatunsdisf2_fcfidus (operands[0], operands[2]));
7136 DONE;
7137 }
7138 [(set_attr "type" "fpload")
7139 (set_attr "length" "8")
7140 (set_attr "isa" "*,p8v,p8v")])
7141
7142 ;; int fegetround(void)
7143 ;;
7144 ;; This expansion for the C99 function only expands for compatible
7145 ;; target libcs, because it needs to return one of FE_DOWNWARD,
7146 ;; FE_TONEAREST, FE_TOWARDZERO or FE_UPWARD with the values as defined
7147 ;; by the target libc, and since the libc is free to choose the values
7148 ;; (and they may differ from the hardware) and the expander needs to
7149 ;; know then beforehand, this expanded only expands for target libcs
7150 ;; that it can handle the values is knows.
7151 ;; Because of these restriction, this only expands on the desired
7152 ;; case and fallback to a call to libc otherwise.
7153 (define_expand "fegetroundsi"
7154 [(set (match_operand:SI 0 "gpc_reg_operand")
7155 (unspec_volatile:SI [(const_int 0)] UNSPECV_MFFSL))]
7156 "TARGET_HARD_FLOAT"
7157 {
7158 if (!OPTION_GLIBC)
7159 FAIL;
7160
7161 rtx tmp_df = gen_reg_rtx (DFmode);
7162 emit_insn (gen_rs6000_mffsl (tmp_df));
7163
7164 rtx tmp_di = simplify_gen_subreg (DImode, tmp_df, DFmode, 0);
7165 rtx tmp_di_2 = gen_reg_rtx (DImode);
7166 emit_insn (gen_anddi3 (tmp_di_2, tmp_di, GEN_INT (3)));
7167 rtx tmp_si = gen_reg_rtx (SImode);
7168 tmp_si = gen_lowpart (SImode, tmp_di_2);
7169 emit_move_insn (operands[0], tmp_si);
7170 DONE;
7171 })
7172
7173 ;; int feclearexcept(int excepts)
7174 ;;
7175 ;; This expansion for the C99 function only works when EXCEPTS is a
7176 ;; constant known at compile time and specifies any one of
7177 ;; FE_INEXACT, FE_DIVBYZERO, FE_UNDERFLOW and FE_OVERFLOW flags.
7178 ;; It doesn't handle values out of range, and always returns 0.
7179 ;; Note that FE_INVALID is unsupported because it maps to more than
7180 ;; one bit of the FPSCR register.
7181 ;; The FE_* are defined in the target libc, and since they are free to
7182 ;; choose the values and the expand needs to know them beforehand,
7183 ;; this expander only expands for target libcs that it can handle the
7184 ;; values it knows.
7185 ;; Because of these restrictions, this only expands on the desired
7186 ;; cases and fallback to a call to libc on any other case.
7187 (define_expand "feclearexceptsi"
7188 [(use (match_operand:SI 1 "const_int_operand" "n"))
7189 (set (match_operand:SI 0 "gpc_reg_operand")
7190 (const_int 0))]
7191 "TARGET_HARD_FLOAT"
7192 {
7193 if (!OPTION_GLIBC)
7194 FAIL;
7195
7196 unsigned int fe = INTVAL (operands[1]);
7197 if (fe != (fe & 0x1e000000))
7198 FAIL;
7199
7200 if (fe & 0x02000000) /* FE_INEXACT */
7201 emit_insn (gen_rs6000_mtfsb0 (gen_rtx_CONST_INT (SImode, 6)));
7202 if (fe & 0x04000000) /* FE_DIVBYZERO */
7203 emit_insn (gen_rs6000_mtfsb0 (gen_rtx_CONST_INT (SImode, 5)));
7204 if (fe & 0x08000000) /* FE_UNDERFLOW */
7205 emit_insn (gen_rs6000_mtfsb0 (gen_rtx_CONST_INT (SImode, 4)));
7206 if (fe & 0x10000000) /* FE_OVERFLOW */
7207 emit_insn (gen_rs6000_mtfsb0 (gen_rtx_CONST_INT (SImode, 3)));
7208
7209 emit_move_insn (operands[0], const0_rtx);
7210 DONE;
7211 })
7212
7213 ;; int feraiseexcept(int excepts)
7214 ;;
7215 ;; This expansion for the C99 function only works when excepts is a
7216 ;; constant known at compile time and specifies any one of
7217 ;; FE_INEXACT, FE_DIVBYZERO, FE_UNDERFLOW and FE_OVERFLOW flags.
7218 ;; It doesn't handle values out of range, and always returns 0.
7219 ;; Note that FE_INVALID is unsupported because it maps to more than
7220 ;; one bit of the FPSCR register.
7221 ;; The FE_* are defined in the target libc, and since they are free to
7222 ;; choose the values and the expand needs to know them beforehand,
7223 ;; this expander only expands for target libcs that it can handle the
7224 ;; values it knows.
7225 ;; Because of these restrictions, this only expands on the desired
7226 ;; cases and fallback to a call to libc on any other case.
7227 (define_expand "feraiseexceptsi"
7228 [(use (match_operand:SI 1 "const_int_operand" "n"))
7229 (set (match_operand:SI 0 "gpc_reg_operand")
7230 (const_int 0))]
7231 "TARGET_HARD_FLOAT"
7232 {
7233 if (!OPTION_GLIBC)
7234 FAIL;
7235
7236 unsigned int fe = INTVAL (operands[1]);
7237 if (fe != (fe & 0x1e000000))
7238 FAIL;
7239
7240 if (fe & 0x02000000) /* FE_INEXACT */
7241 emit_insn (gen_rs6000_mtfsb1 (gen_rtx_CONST_INT (SImode, 6)));
7242 if (fe & 0x04000000) /* FE_DIVBYZERO */
7243 emit_insn (gen_rs6000_mtfsb1 (gen_rtx_CONST_INT (SImode, 5)));
7244 if (fe & 0x08000000) /* FE_UNDERFLOW */
7245 emit_insn (gen_rs6000_mtfsb1 (gen_rtx_CONST_INT (SImode, 4)));
7246 if (fe & 0x10000000) /* FE_OVERFLOW */
7247 emit_insn (gen_rs6000_mtfsb1 (gen_rtx_CONST_INT (SImode, 3)));
7248
7249 emit_move_insn (operands[0], const0_rtx);
7250 DONE;
7251 })
7252
7253 ;; Define the TImode operations that can be done in a small number
7254 ;; of instructions. The & constraints are to prevent the register
7255 ;; allocator from allocating registers that overlap with the inputs
7256 ;; (for example, having an input in 7,8 and an output in 6,7). We
7257 ;; also allow for the output being the same as one of the inputs.
7258
7259 (define_expand "addti3"
7260 [(set (match_operand:TI 0 "gpc_reg_operand")
7261 (plus:TI (match_operand:TI 1 "gpc_reg_operand")
7262 (match_operand:TI 2 "reg_or_short_operand")))]
7263 "TARGET_64BIT"
7264 {
7265 rtx lo0 = gen_lowpart (DImode, operands[0]);
7266 rtx lo1 = gen_lowpart (DImode, operands[1]);
7267 rtx lo2 = gen_lowpart (DImode, operands[2]);
7268 rtx hi0 = gen_highpart (DImode, operands[0]);
7269 rtx hi1 = gen_highpart (DImode, operands[1]);
7270 rtx hi2 = gen_highpart_mode (DImode, TImode, operands[2]);
7271
7272 if (!reg_or_short_operand (lo2, DImode))
7273 lo2 = force_reg (DImode, lo2);
7274 if (!adde_operand (hi2, DImode))
7275 hi2 = force_reg (DImode, hi2);
7276
7277 emit_insn (gen_adddi3_carry (lo0, lo1, lo2));
7278 emit_insn (gen_adddi3_carry_in (hi0, hi1, hi2));
7279 DONE;
7280 })
7281
7282 (define_expand "subti3"
7283 [(set (match_operand:TI 0 "gpc_reg_operand")
7284 (minus:TI (match_operand:TI 1 "reg_or_short_operand")
7285 (match_operand:TI 2 "gpc_reg_operand")))]
7286 "TARGET_64BIT"
7287 {
7288 rtx lo0 = gen_lowpart (DImode, operands[0]);
7289 rtx lo1 = gen_lowpart (DImode, operands[1]);
7290 rtx lo2 = gen_lowpart (DImode, operands[2]);
7291 rtx hi0 = gen_highpart (DImode, operands[0]);
7292 rtx hi1 = gen_highpart_mode (DImode, TImode, operands[1]);
7293 rtx hi2 = gen_highpart (DImode, operands[2]);
7294
7295 if (!reg_or_short_operand (lo1, DImode))
7296 lo1 = force_reg (DImode, lo1);
7297 if (!adde_operand (hi1, DImode))
7298 hi1 = force_reg (DImode, hi1);
7299
7300 emit_insn (gen_subfdi3_carry (lo0, lo2, lo1));
7301 emit_insn (gen_subfdi3_carry_in (hi0, hi2, hi1));
7302 DONE;
7303 })
7304
7305 ;; 128-bit logical operations expanders
7306
7307 (define_expand "and<mode>3"
7308 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7309 (and:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand")
7310 (match_operand:BOOL_128 2 "vlogical_operand")))]
7311 ""
7312 "")
7313
7314 (define_expand "ior<mode>3"
7315 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7316 (ior:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand")
7317 (match_operand:BOOL_128 2 "vlogical_operand")))]
7318 ""
7319 "")
7320
7321 (define_expand "xor<mode>3"
7322 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7323 (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand")
7324 (match_operand:BOOL_128 2 "vlogical_operand")))]
7325 ""
7326 "")
7327
7328 (define_expand "nor<mode>3"
7329 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7330 (and:BOOL_128
7331 (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand"))
7332 (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand"))))]
7333 ""
7334 "")
7335
7336 (define_expand "andn<mode>3"
7337 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7338 (and:BOOL_128
7339 (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand"))
7340 (match_operand:BOOL_128 1 "vlogical_operand")))]
7341 ""
7342 "")
7343
7344 ;; Power8 vector logical instructions.
7345 (define_expand "eqv<mode>3"
7346 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7347 (not:BOOL_128
7348 (xor:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand")
7349 (match_operand:BOOL_128 2 "vlogical_operand"))))]
7350 "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
7351 "")
7352
7353 ;; Rewrite nand into canonical form
7354 (define_expand "nand<mode>3"
7355 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7356 (ior:BOOL_128
7357 (not:BOOL_128 (match_operand:BOOL_128 1 "vlogical_operand"))
7358 (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand"))))]
7359 "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
7360 "")
7361
7362 ;; The canonical form is to have the negated element first, so we need to
7363 ;; reverse arguments.
7364 (define_expand "iorn<mode>3"
7365 [(set (match_operand:BOOL_128 0 "vlogical_operand")
7366 (ior:BOOL_128
7367 (not:BOOL_128 (match_operand:BOOL_128 2 "vlogical_operand"))
7368 (match_operand:BOOL_128 1 "vlogical_operand")))]
7369 "<MODE>mode == TImode || <MODE>mode == PTImode || TARGET_P8_VECTOR"
7370 "")
7371
7372 ;; 128-bit logical operations insns and split operations
7373 (define_insn_and_split "*and<mode>3_internal"
7374 [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
7375 (and:BOOL_128
7376 (match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
7377 (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")))]
7378 ""
7379 {
7380 if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
7381 return "xxland %x0,%x1,%x2";
7382
7383 if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
7384 return "vand %0,%1,%2";
7385
7386 return "#";
7387 }
7388 "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
7389 [(const_int 0)]
7390 {
7391 rs6000_split_logical (operands, AND, false, false, false);
7392 DONE;
7393 }
7394 [(set (attr "type")
7395 (if_then_else
7396 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7397 (const_string "veclogical")
7398 (const_string "integer")))
7399 (set (attr "length")
7400 (if_then_else
7401 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7402 (const_string "4")
7403 (if_then_else
7404 (match_test "TARGET_POWERPC64")
7405 (const_string "8")
7406 (const_string "16"))))])
7407
7408 ;; 128-bit IOR/XOR
7409 (define_insn_and_split "*bool<mode>3_internal"
7410 [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
7411 (match_operator:BOOL_128 3 "boolean_or_operator"
7412 [(match_operand:BOOL_128 1 "vlogical_operand" "%<BOOL_REGS_OP1>")
7413 (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>")]))]
7414 ""
7415 {
7416 if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
7417 return "xxl%q3 %x0,%x1,%x2";
7418
7419 if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
7420 return "v%q3 %0,%1,%2";
7421
7422 return "#";
7423 }
7424 "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
7425 [(const_int 0)]
7426 {
7427 rs6000_split_logical (operands, GET_CODE (operands[3]), false, false, false);
7428 DONE;
7429 }
7430 [(set (attr "type")
7431 (if_then_else
7432 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7433 (const_string "veclogical")
7434 (const_string "integer")))
7435 (set (attr "length")
7436 (if_then_else
7437 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7438 (const_string "4")
7439 (if_then_else
7440 (match_test "TARGET_POWERPC64")
7441 (const_string "8")
7442 (const_string "16"))))])
7443
7444 ;; 128-bit ANDC/ORC
7445 (define_insn_and_split "*boolc<mode>3_internal1"
7446 [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
7447 (match_operator:BOOL_128 3 "boolean_operator"
7448 [(not:BOOL_128
7449 (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))
7450 (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>")]))]
7451 "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
7452 {
7453 if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
7454 return "xxl%q3 %x0,%x1,%x2";
7455
7456 if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
7457 return "v%q3 %0,%1,%2";
7458
7459 return "#";
7460 }
7461 "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
7462 && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
7463 [(const_int 0)]
7464 {
7465 rs6000_split_logical (operands, GET_CODE (operands[3]), false, false, true);
7466 DONE;
7467 }
7468 [(set (attr "type")
7469 (if_then_else
7470 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7471 (const_string "veclogical")
7472 (const_string "integer")))
7473 (set (attr "length")
7474 (if_then_else
7475 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7476 (const_string "4")
7477 (if_then_else
7478 (match_test "TARGET_POWERPC64")
7479 (const_string "8")
7480 (const_string "16"))))])
7481
7482 (define_insn_and_split "*boolc<mode>3_internal2"
7483 [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
7484 (match_operator:TI2 3 "boolean_operator"
7485 [(not:TI2
7486 (match_operand:TI2 2 "int_reg_operand" "r,0,r"))
7487 (match_operand:TI2 1 "int_reg_operand" "r,r,0")]))]
7488 "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
7489 "#"
7490 "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
7491 [(const_int 0)]
7492 {
7493 rs6000_split_logical (operands, GET_CODE (operands[3]), false, false, true);
7494 DONE;
7495 }
7496 [(set_attr "type" "integer")
7497 (set (attr "length")
7498 (if_then_else
7499 (match_test "TARGET_POWERPC64")
7500 (const_string "8")
7501 (const_string "16")))])
7502
7503 ;; 128-bit NAND/NOR
7504 (define_insn_and_split "*boolcc<mode>3_internal1"
7505 [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
7506 (match_operator:BOOL_128 3 "boolean_operator"
7507 [(not:BOOL_128
7508 (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>"))
7509 (not:BOOL_128
7510 (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))]))]
7511 "TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND)"
7512 {
7513 if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
7514 return "xxl%q3 %x0,%x1,%x2";
7515
7516 if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
7517 return "v%q3 %0,%1,%2";
7518
7519 return "#";
7520 }
7521 "(TARGET_P8_VECTOR || (GET_CODE (operands[3]) == AND))
7522 && reload_completed && int_reg_operand (operands[0], <MODE>mode)"
7523 [(const_int 0)]
7524 {
7525 rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true);
7526 DONE;
7527 }
7528 [(set (attr "type")
7529 (if_then_else
7530 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7531 (const_string "veclogical")
7532 (const_string "integer")))
7533 (set (attr "length")
7534 (if_then_else
7535 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7536 (const_string "4")
7537 (if_then_else
7538 (match_test "TARGET_POWERPC64")
7539 (const_string "8")
7540 (const_string "16"))))])
7541
7542 (define_insn_and_split "*boolcc<mode>3_internal2"
7543 [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
7544 (match_operator:TI2 3 "boolean_operator"
7545 [(not:TI2
7546 (match_operand:TI2 1 "int_reg_operand" "r,0,r"))
7547 (not:TI2
7548 (match_operand:TI2 2 "int_reg_operand" "r,r,0"))]))]
7549 "!TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
7550 "#"
7551 "reload_completed && !TARGET_P8_VECTOR && (GET_CODE (operands[3]) != AND)"
7552 [(const_int 0)]
7553 {
7554 rs6000_split_logical (operands, GET_CODE (operands[3]), false, true, true);
7555 DONE;
7556 }
7557 [(set_attr "type" "integer")
7558 (set (attr "length")
7559 (if_then_else
7560 (match_test "TARGET_POWERPC64")
7561 (const_string "8")
7562 (const_string "16")))])
7563
7564
7565 ;; 128-bit EQV
7566 (define_insn_and_split "*eqv<mode>3_internal1"
7567 [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
7568 (not:BOOL_128
7569 (xor:BOOL_128
7570 (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_OP1>")
7571 (match_operand:BOOL_128 2 "vlogical_operand" "<BOOL_REGS_OP2>"))))]
7572 "TARGET_P8_VECTOR"
7573 {
7574 if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
7575 return "xxleqv %x0,%x1,%x2";
7576
7577 if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
7578 return "veqv %0,%1,%2";
7579
7580 return "#";
7581 }
7582 "TARGET_P8_VECTOR && reload_completed
7583 && int_reg_operand (operands[0], <MODE>mode)"
7584 [(const_int 0)]
7585 {
7586 rs6000_split_logical (operands, XOR, true, false, false);
7587 DONE;
7588 }
7589 [(set (attr "type")
7590 (if_then_else
7591 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7592 (const_string "veclogical")
7593 (const_string "integer")))
7594 (set (attr "length")
7595 (if_then_else
7596 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7597 (const_string "4")
7598 (if_then_else
7599 (match_test "TARGET_POWERPC64")
7600 (const_string "8")
7601 (const_string "16"))))])
7602
7603 (define_insn_and_split "*eqv<mode>3_internal2"
7604 [(set (match_operand:TI2 0 "int_reg_operand" "=&r,r,r")
7605 (not:TI2
7606 (xor:TI2
7607 (match_operand:TI2 1 "int_reg_operand" "r,0,r")
7608 (match_operand:TI2 2 "int_reg_operand" "r,r,0"))))]
7609 "!TARGET_P8_VECTOR"
7610 "#"
7611 "reload_completed && !TARGET_P8_VECTOR"
7612 [(const_int 0)]
7613 {
7614 rs6000_split_logical (operands, XOR, true, false, false);
7615 DONE;
7616 }
7617 [(set_attr "type" "integer")
7618 (set (attr "length")
7619 (if_then_else
7620 (match_test "TARGET_POWERPC64")
7621 (const_string "8")
7622 (const_string "16")))])
7623
7624 ;; 128-bit one's complement
7625 (define_insn_and_split "one_cmpl<mode>2"
7626 [(set (match_operand:BOOL_128 0 "vlogical_operand" "=<BOOL_REGS_OUTPUT>")
7627 (not:BOOL_128
7628 (match_operand:BOOL_128 1 "vlogical_operand" "<BOOL_REGS_UNARY>")))]
7629 ""
7630 {
7631 if (TARGET_VSX && vsx_register_operand (operands[0], <MODE>mode))
7632 return "xxlnor %x0,%x1,%x1";
7633
7634 if (TARGET_ALTIVEC && altivec_register_operand (operands[0], <MODE>mode))
7635 return "vnor %0,%1,%1";
7636
7637 return "#";
7638 }
7639 "reload_completed && int_reg_operand (operands[0], <MODE>mode)"
7640 [(const_int 0)]
7641 {
7642 rs6000_split_logical (operands, NOT, false, false, false);
7643 DONE;
7644 }
7645 [(set (attr "type")
7646 (if_then_else
7647 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7648 (const_string "veclogical")
7649 (const_string "integer")))
7650 (set (attr "length")
7651 (if_then_else
7652 (match_test "vsx_register_operand (operands[0], <MODE>mode)")
7653 (const_string "4")
7654 (if_then_else
7655 (match_test "TARGET_POWERPC64")
7656 (const_string "8")
7657 (const_string "16"))))])
7658
7659
7660 ;; Now define ways of moving data around.
7661
7662 ;; Set up a register with a value from the GOT table
7663
7664 (define_expand "movsi_got"
7665 [(set (match_operand:SI 0 "gpc_reg_operand")
7666 (unspec:SI [(match_operand:SI 1 "got_operand")
7667 (match_dup 2)] UNSPEC_MOVSI_GOT))]
7668 "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7669 {
7670 if (GET_CODE (operands[1]) == CONST)
7671 {
7672 rtx offset = const0_rtx;
7673 HOST_WIDE_INT value;
7674
7675 operands[1] = eliminate_constant_term (XEXP (operands[1], 0), &offset);
7676 value = INTVAL (offset);
7677 if (value != 0)
7678 {
7679 rtx tmp = (!can_create_pseudo_p ()
7680 ? operands[0]
7681 : gen_reg_rtx (Pmode));
7682 emit_insn (gen_movsi_got (tmp, operands[1]));
7683 emit_insn (gen_addsi3 (operands[0], tmp, offset));
7684 DONE;
7685 }
7686 }
7687
7688 operands[2] = rs6000_got_register (operands[1]);
7689 })
7690
7691 (define_insn "*movsi_got_internal"
7692 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7693 (unspec:SI [(match_operand:SI 1 "got_no_const_operand" "")
7694 (match_operand:SI 2 "gpc_reg_operand" "b")]
7695 UNSPEC_MOVSI_GOT))]
7696 "DEFAULT_ABI == ABI_V4 && flag_pic == 1"
7697 "lwz %0,%a1@got(%2)"
7698 [(set_attr "type" "load")])
7699
7700 ;; Used by sched, shorten_branches and final when the GOT pseudo reg
7701 ;; didn't get allocated to a hard register.
7702 (define_split
7703 [(set (match_operand:SI 0 "gpc_reg_operand")
7704 (unspec:SI [(match_operand:SI 1 "got_no_const_operand")
7705 (match_operand:SI 2 "memory_operand")]
7706 UNSPEC_MOVSI_GOT))]
7707 "DEFAULT_ABI == ABI_V4
7708 && flag_pic == 1
7709 && reload_completed"
7710 [(set (match_dup 0) (match_dup 2))
7711 (set (match_dup 0) (unspec:SI [(match_dup 1)(match_dup 0)]
7712 UNSPEC_MOVSI_GOT))]
7713 "")
7714
7715 ;; MR LA
7716 ;; LWZ LFIWZX LXSIWZX
7717 ;; STW STFIWX STXSIWX
7718 ;; LI LIS PLI #
7719 ;; XXLOR XXSPLTIB 0 XXSPLTIB -1 VSPLTISW
7720 ;; XXLXOR 0 XXLORC -1 P9 const
7721 ;; MTVSRWZ MFVSRWZ
7722 ;; MF%1 MT%0 NOP
7723
7724 (define_insn "*movsi_internal1"
7725 [(set (match_operand:SI 0 "nonimmediate_operand"
7726 "=r, r, d,
7727 r, d, v,
7728 m, ?Z, ?Z,
7729 r, r, r, r,
7730 wa, wa, wa, v,
7731 wa, v, v,
7732 wa, r,
7733 r, *h, *h")
7734 (match_operand:SI 1 "input_operand"
7735 "r, U, d,
7736 m, ?Z, ?Z,
7737 r, d, v,
7738 I, L, eI, n,
7739 wa, O, wM, wB,
7740 O, wM, wS,
7741 r, wa,
7742 *h, r, 0"))]
7743 "gpc_reg_operand (operands[0], SImode)
7744 || gpc_reg_operand (operands[1], SImode)"
7745 "@
7746 mr %0,%1
7747 la %0,%a1
7748 fmr %0,%1
7749 lwz%U1%X1 %0,%1
7750 lfiwzx %0,%y1
7751 lxsiwzx %x0,%y1
7752 stw%U0%X0 %1,%0
7753 stfiwx %1,%y0
7754 stxsiwx %x1,%y0
7755 li %0,%1
7756 lis %0,%v1
7757 li %0,%1
7758 #
7759 xxlor %x0,%x1,%x1
7760 xxspltib %x0,0
7761 xxspltib %x0,255
7762 vspltisw %0,%1
7763 xxlxor %x0,%x0,%x0
7764 xxlorc %x0,%x0,%x0
7765 #
7766 mtvsrwz %x0,%1
7767 mfvsrwz %0,%x1
7768 mf%1 %0
7769 mt%0 %1
7770 nop"
7771 [(set_attr "type"
7772 "*, *, fpsimple,
7773 load, fpload, fpload,
7774 store, fpstore, fpstore,
7775 *, *, *, *,
7776 veclogical, vecsimple, vecsimple, vecsimple,
7777 veclogical, veclogical, vecsimple,
7778 mtvsr, mfvsr,
7779 *, *, *")
7780 (set_attr "length"
7781 "*, *, *,
7782 *, *, *,
7783 *, *, *,
7784 *, *, *, 8,
7785 *, *, *, *,
7786 *, *, 8,
7787 *, *,
7788 *, *, *")
7789 (set_attr "isa"
7790 "*, *, *,
7791 *, p7, p8v,
7792 *, *, p8v,
7793 *, *, p10, *,
7794 p8v, p9v, p9v, p8v,
7795 p9v, p8v, p9v,
7796 p8v, p8v,
7797 *, *, *")])
7798
7799 ;; Like movsi, but adjust a SF value to be used in a SI context, i.e.
7800 ;; (set (reg:SI ...) (subreg:SI (reg:SF ...) 0))
7801 ;;
7802 ;; Because SF values are actually stored as DF values within the vector
7803 ;; registers, we need to convert the value to the vector SF format when
7804 ;; we need to use the bits in a union or similar cases. We only need
7805 ;; to do this transformation when the value is a vector register. Loads,
7806 ;; stores, and transfers within GPRs are assumed to be safe.
7807 ;;
7808 ;; This is a more general case of reload_gpr_from_vsxsf. That insn must have
7809 ;; no alternatives, because the call is created as part of secondary_reload,
7810 ;; and operand #2's register class is used to allocate the temporary register.
7811 ;; This function is called before reload, and it creates the temporary as
7812 ;; needed.
7813
7814 ;; MR LWZ LFIWZX LXSIWZX STW
7815 ;; STFS STXSSP STXSSPX VSX->GPR VSX->VSX
7816 ;; MTVSRWZ
7817
7818 (define_insn_and_split "movsi_from_sf"
7819 [(set (match_operand:SI 0 "nonimmediate_operand"
7820 "=r, r, ?*d, ?*v, m,
7821 m, wY, Z, r, ?*wa,
7822 wa")
7823 (unspec:SI [(match_operand:SF 1 "input_operand"
7824 "r, m, Z, Z, r,
7825 f, v, wa, wa, wa,
7826 r")]
7827 UNSPEC_SI_FROM_SF))
7828 (clobber (match_scratch:V4SF 2
7829 "=X, X, X, X, X,
7830 X, X, X, wa, X,
7831 X"))]
7832 "TARGET_NO_SF_SUBREG
7833 && (register_operand (operands[0], SImode)
7834 || register_operand (operands[1], SFmode))"
7835 "@
7836 mr %0,%1
7837 lwz%U1%X1 %0,%1
7838 lfiwzx %0,%y1
7839 lxsiwzx %x0,%y1
7840 stw%U0%X0 %1,%0
7841 stfs%U0%X0 %1,%0
7842 stxssp %1,%0
7843 stxsspx %x1,%y0
7844 #
7845 xscvdpspn %x0,%x1
7846 mtvsrwz %x0,%1"
7847 "&& reload_completed
7848 && int_reg_operand (operands[0], SImode)
7849 && vsx_reg_sfsubreg_ok (operands[1], SFmode)"
7850 [(const_int 0)]
7851 {
7852 rtx op0 = operands[0];
7853 rtx op1 = operands[1];
7854 rtx op2 = operands[2];
7855 rtx op0_di = gen_rtx_REG (DImode, reg_or_subregno (op0));
7856 rtx op2_si = gen_rtx_REG (SImode, reg_or_subregno (op2));
7857
7858 emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
7859 emit_insn (gen_zero_extendsidi2 (op0_di, op2_si));
7860 DONE;
7861 }
7862 [(set_attr "type"
7863 "*, load, fpload, fpload, store,
7864 fpstore, fpstore, fpstore, mfvsr, fp,
7865 mtvsr")
7866 (set_attr "length"
7867 "*, *, *, *, *,
7868 *, *, *, 8, *,
7869 *")
7870 (set_attr "isa"
7871 "*, *, p8v, p8v, *,
7872 *, p9v, p8v, p8v, p8v,
7873 p8v")])
7874
7875 ;; movsi_from_sf with zero extension
7876 ;;
7877 ;; RLDICL LWZ LFIWZX LXSIWZX VSX->GPR
7878 ;; VSX->VSX MTVSRWZ
7879
7880 (define_insn_and_split "*movdi_from_sf_zero_ext"
7881 [(set (match_operand:DI 0 "gpc_reg_operand"
7882 "=r, r, ?*d, ?*v, r,
7883 ?v, wa")
7884 (zero_extend:DI
7885 (unspec:SI [(match_operand:SF 1 "input_operand"
7886 "r, m, Z, Z, wa,
7887 wa, r")]
7888 UNSPEC_SI_FROM_SF)))
7889 (clobber (match_scratch:V4SF 2
7890 "=X, X, X, X, wa,
7891 wa, X"))]
7892 "TARGET_DIRECT_MOVE_64BIT
7893 && (register_operand (operands[0], DImode)
7894 || register_operand (operands[1], SImode))"
7895 "@
7896 rldicl %0,%1,0,32
7897 lwz%U1%X1 %0,%1
7898 lfiwzx %0,%y1
7899 lxsiwzx %x0,%y1
7900 #
7901 #
7902 mtvsrwz %x0,%1"
7903 "&& reload_completed
7904 && register_operand (operands[0], DImode)
7905 && vsx_reg_sfsubreg_ok (operands[1], SFmode)"
7906 [(const_int 0)]
7907 {
7908 rtx op0 = operands[0];
7909 rtx op1 = operands[1];
7910 rtx op2 = operands[2];
7911 rtx op2_si = gen_rtx_REG (SImode, reg_or_subregno (op2));
7912
7913 emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
7914 emit_insn (gen_zero_extendsidi2 (op0, op2_si));
7915 DONE;
7916 }
7917 [(set_attr "type"
7918 "*, load, fpload, fpload, two,
7919 two, mtvsr")
7920 (set_attr "length"
7921 "*, *, *, *, 8,
7922 8, *")
7923 (set_attr "isa"
7924 "*, *, p8v, p8v, p8v,
7925 p9v, p8v")])
7926
7927 ;; Like movsi_from_sf, but combine a convert from DFmode to SFmode before
7928 ;; moving it to SImode. We cannot do a SFmode store without having to do the
7929 ;; conversion explicitly since that doesn't work in most cases if the input
7930 ;; isn't representable as SF. Use XSCVDPSP instead of XSCVDPSPN, since the
7931 ;; former handles cases where the input will not fit in a SFmode, and the
7932 ;; latter assumes the value has already been rounded.
7933 (define_insn "*movsi_from_df"
7934 [(set (match_operand:SI 0 "gpc_reg_operand" "=wa")
7935 (unspec:SI [(float_truncate:SF
7936 (match_operand:DF 1 "gpc_reg_operand" "wa"))]
7937 UNSPEC_SI_FROM_SF))]
7938 "TARGET_NO_SF_SUBREG"
7939 "xscvdpsp %x0,%x1"
7940 [(set_attr "type" "fp")])
7941
7942
7943 (define_code_iterator eqne [eq ne])
7944
7945 ;; "i == C" ==> "rotl(i,N) == rotl(C,N)"
7946 (define_insn_and_split "*rotate_on_cmpdi"
7947 [(set (pc)
7948 (if_then_else (eqne (match_operand:DI 1 "gpc_reg_operand" "r")
7949 (match_operand:DI 2 "const_int_operand" "n"))
7950 (label_ref (match_operand 0 ""))
7951 (pc)))
7952 (clobber (match_scratch:DI 3 "=r"))
7953 (clobber (match_scratch:CCUNS 4 "=y"))]
7954 "TARGET_POWERPC64 && num_insns_constant (operands[2], DImode) > 1
7955 && (can_be_rotated_to_positive_16bits (INTVAL (operands[2]))
7956 || can_be_rotated_to_negative_15bits (INTVAL (operands[2])))"
7957 "#"
7958 "&& 1"
7959 [(pc)]
7960 {
7961 bool sgn = false;
7962 unsigned HOST_WIDE_INT C = INTVAL (operands[2]);
7963 int rot;
7964
7965 /* cmpldi */
7966 if (!can_be_rotated_to_lowbits (C, 16, &rot))
7967 {
7968 /* cmpdi */
7969 sgn = true;
7970 bool res = can_be_rotated_to_lowbits (~C, 15, &rot);
7971 gcc_assert (res);
7972 }
7973
7974 rtx n = GEN_INT (rot);
7975
7976 /* i' = rotl (i, n) */
7977 rtx op0 = can_create_pseudo_p () ? gen_reg_rtx (DImode) : operands[3];
7978 emit_insn (gen_rtx_SET (op0, gen_rtx_ROTATE (DImode, operands[1], n)));
7979
7980 /* C' = rotl (C, n) */
7981 rtx op1 = GEN_INT ((C << rot) | (C >> (HOST_BITS_PER_WIDE_INT - rot)));
7982
7983 /* i' == C' */
7984 machine_mode comp_mode = sgn ? CCmode : CCUNSmode;
7985 rtx cc = can_create_pseudo_p () ? gen_reg_rtx (comp_mode) : operands[4];
7986 PUT_MODE (cc, comp_mode);
7987 emit_insn (gen_rtx_SET (cc, gen_rtx_COMPARE (comp_mode, op0, op1)));
7988 rtx cmp = gen_rtx_<eqne:CODE> (CCmode, cc, const0_rtx);
7989 rtx loc_ref = gen_rtx_LABEL_REF (VOIDmode, operands[0]);
7990 emit_jump_insn (gen_rtx_SET (pc_rtx,
7991 gen_rtx_IF_THEN_ELSE (VOIDmode, cmp,
7992 loc_ref, pc_rtx)));
7993
7994 /* Keep the probability info for the prediction of the branch insn. */
7995 rtx note = find_reg_note (curr_insn, REG_BR_PROB, 0);
7996 if (note)
7997 {
7998 profile_probability prob
7999 = profile_probability::from_reg_br_prob_note (XINT (note, 0));
8000
8001 add_reg_br_prob_note (get_last_insn (), prob);
8002 }
8003
8004 DONE;
8005 })
8006
8007 ;; Split a load of a large constant into the appropriate two-insn
8008 ;; sequence.
8009
8010 (define_split
8011 [(set (match_operand:SI 0 "gpc_reg_operand")
8012 (match_operand:SI 1 "const_int_operand"))]
8013 "num_insns_constant (operands[1], SImode) > 1"
8014 [(pc)]
8015 {
8016 if (rs6000_emit_set_const (operands[0], operands[1]))
8017 DONE;
8018 else
8019 FAIL;
8020 })
8021
8022 ;; Split loading -128..127 to use XXSPLITB and VEXTSW2D
8023 (define_split
8024 [(set (match_operand:DI 0 "altivec_register_operand")
8025 (match_operand:DI 1 "xxspltib_constant_split"))]
8026 "TARGET_P9_VECTOR && reload_completed"
8027 [(const_int 0)]
8028 {
8029 rtx op0 = operands[0];
8030 rtx op1 = operands[1];
8031 int r = REGNO (op0);
8032 rtx op0_v16qi = gen_rtx_REG (V16QImode, r);
8033
8034 emit_insn (gen_xxspltib_v16qi (op0_v16qi, op1));
8035 emit_insn (gen_vsx_sign_extend_v16qi_si (operands[0], op0_v16qi));
8036 DONE;
8037 })
8038
8039 (define_insn "*mov<mode>_internal2"
8040 [(set (match_operand:CC 2 "cc_reg_operand" "=y,x,?y")
8041 (compare:CC (match_operand:WORD 1 "gpc_reg_operand" "0,r,r")
8042 (const_int 0)))
8043 (set (match_operand:WORD 0 "gpc_reg_operand" "=r,r,r") (match_dup 1))]
8044 ""
8045 "@
8046 cmp<wd>i %2,%0,0
8047 mr. %0,%1
8048 #"
8049 [(set_attr "type" "cmp,logical,cmp")
8050 (set_attr "dot" "yes")
8051 (set_attr "length" "4,4,8")])
8052
8053 (define_peephole2
8054 [(set (match_operand:CC 2 "cc_reg_operand")
8055 (compare:CC (match_operand:WORD 1 "int_reg_operand")
8056 (const_int 0)))
8057 (set (match_operand:WORD 0 "int_reg_operand")
8058 (match_dup 1))]
8059 "!cc_reg_not_cr0_operand (operands[2], CCmode)"
8060 [(parallel [(set (match_operand:CC 2 "cc_reg_operand" "=x")
8061 (compare:CC (match_operand:WORD 1 "int_reg_operand" "r")
8062 (const_int 0)))
8063 (set (match_operand:WORD 0 "int_reg_operand" "=r")
8064 (match_dup 1))])]
8065 ""
8066 )
8067
8068 (define_peephole2
8069 [(set (match_operand:WORD 0 "int_reg_operand")
8070 (match_operand:WORD 1 "int_reg_operand"))
8071 (set (match_operand:CC 2 "cc_reg_operand")
8072 (compare:CC (match_dup 1)
8073 (const_int 0)))]
8074 "!cc_reg_not_cr0_operand (operands[2], CCmode)"
8075 [(parallel [(set (match_operand:CC 2 "cc_reg_operand" "=x")
8076 (compare:CC (match_operand:GPR 1 "int_reg_operand" "r")
8077 (const_int 0)))
8078 (set (match_operand:WORD 0 "int_reg_operand" "=r")
8079 (match_dup 1))])]
8080 ""
8081 )
8082
8083 (define_split
8084 [(set (match_operand:CC 2 "cc_reg_not_cr0_operand")
8085 (compare:CC (match_operand:WORD 1 "gpc_reg_operand")
8086 (const_int 0)))
8087 (set (match_operand:WORD 0 "gpc_reg_operand") (match_dup 1))]
8088 "reload_completed"
8089 [(set (match_dup 0) (match_dup 1))
8090 (set (match_dup 2)
8091 (compare:CC (match_dup 0)
8092 (const_int 0)))]
8093 "")
8094
8095 (define_expand "mov<mode>"
8096 [(set (match_operand:INT 0 "general_operand")
8097 (match_operand:INT 1 "any_operand"))]
8098 ""
8099 {
8100 rs6000_emit_move (operands[0], operands[1], <MODE>mode);
8101 DONE;
8102 })
8103
8104 ;; MR LHZ/LBZ LXSI*ZX STH/STB STXSI*X LI
8105 ;; XXLOR load 0 load -1 VSPLTI* # MFVSRWZ
8106 ;; MTVSRWZ MF%1 MT%1 NOP
8107 (define_insn "*mov<mode>_internal"
8108 [(set (match_operand:QHI 0 "nonimmediate_operand"
8109 "=r, r, wa, m, ?Z, r,
8110 wa, wa, wa, v, ?v, r,
8111 wa, r, *c*l, *h")
8112 (match_operand:QHI 1 "input_operand"
8113 "r, m, ?Z, r, wa, i,
8114 wa, O, wM, wB, wS, wa,
8115 r, *h, r, 0"))]
8116 "gpc_reg_operand (operands[0], <MODE>mode)
8117 || gpc_reg_operand (operands[1], <MODE>mode)"
8118 "@
8119 mr %0,%1
8120 l<wd>z%U1%X1 %0,%1
8121 lxsi<wd>zx %x0,%y1
8122 st<wd>%U0%X0 %1,%0
8123 stxsi<wd>x %x1,%y0
8124 li %0,%1
8125 xxlor %x0,%x1,%x1
8126 xxspltib %x0,0
8127 xxspltib %x0,255
8128 vspltis<wd> %0,%1
8129 #
8130 mfvsrwz %0,%x1
8131 mtvsrwz %x0,%1
8132 mf%1 %0
8133 mt%0 %1
8134 nop"
8135 [(set_attr "type"
8136 "*, load, fpload, store, fpstore, *,
8137 vecsimple, vecperm, vecperm, vecperm, vecperm, mfvsr,
8138 mtvsr, mfjmpr, mtjmpr, *")
8139 (set_attr "length"
8140 "*, *, *, *, *, *,
8141 *, *, *, *, 8, *,
8142 *, *, *, *")
8143 (set_attr "isa"
8144 "*, *, p9v, *, p9v, *,
8145 p9v, p9v, p9v, p9v, p9v, p9v,
8146 p9v, *, *, *")])
8147
8148
8149 ;; Here is how to move condition codes around. When we store CC data in
8150 ;; an integer register or memory, we store just the high-order 4 bits.
8151 ;; This lets us not shift in the most common case of CR0.
8152 (define_expand "movcc"
8153 [(set (match_operand:CC 0 "nonimmediate_operand")
8154 (match_operand:CC 1 "nonimmediate_operand"))]
8155 ""
8156 "")
8157
8158 (define_mode_iterator CC_any [CC CCUNS CCEQ CCFP])
8159
8160 (define_insn "*movcc_<mode>"
8161 [(set (match_operand:CC_any 0 "nonimmediate_operand"
8162 "=y,x,?y,y,r,r,r,r, r,*c*l,r,m")
8163 (match_operand:CC_any 1 "general_operand"
8164 " y,r, r,O,x,y,r,I,*h, r,m,r"))]
8165 "register_operand (operands[0], <MODE>mode)
8166 || register_operand (operands[1], <MODE>mode)"
8167 "@
8168 mcrf %0,%1
8169 mtcrf 128,%1
8170 rlwinm %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;rlwinm %1,%1,%f0,0xffffffff
8171 crxor %0,%0,%0
8172 mfcr %0%Q1
8173 mfcr %0%Q1\;rlwinm %0,%0,%f1,0xf0000000
8174 mr %0,%1
8175 li %0,%1
8176 mf%1 %0
8177 mt%0 %1
8178 lwz%U1%X1 %0,%1
8179 stw%U0%X0 %1,%0"
8180 [(set_attr_alternative "type"
8181 [(const_string "cr_logical")
8182 (const_string "mtcr")
8183 (const_string "mtcr")
8184 (const_string "cr_logical")
8185 (if_then_else (match_test "TARGET_MFCRF")
8186 (const_string "mfcrf") (const_string "mfcr"))
8187 (if_then_else (match_test "TARGET_MFCRF")
8188 (const_string "mfcrf") (const_string "mfcr"))
8189 (const_string "integer")
8190 (const_string "integer")
8191 (const_string "mfjmpr")
8192 (const_string "mtjmpr")
8193 (const_string "load")
8194 (const_string "store")])
8195 (set_attr "length" "*,*,12,*,*,8,*,*,*,*,*,*")])
8196
8197 ;; For floating-point, we normally deal with the floating-point registers
8198 ;; unless -msoft-float is used. The sole exception is that parameter passing
8199 ;; can produce floating-point values in fixed-point registers. Unless the
8200 ;; value is a simple constant or already in memory, we deal with this by
8201 ;; allocating memory and copying the value explicitly via that memory location.
8202
8203 ;; Move 32-bit binary/decimal floating point
8204 (define_expand "mov<mode>"
8205 [(set (match_operand:FMOVE32 0 "nonimmediate_operand")
8206 (match_operand:FMOVE32 1 "any_operand"))]
8207 "<fmove_ok>"
8208 {
8209 rs6000_emit_move (operands[0], operands[1], <MODE>mode);
8210 DONE;
8211 })
8212
8213 (define_split
8214 [(set (match_operand:FMOVE32 0 "gpc_reg_operand")
8215 (match_operand:FMOVE32 1 "const_double_operand"))]
8216 "reload_completed
8217 && ((REG_P (operands[0]) && REGNO (operands[0]) <= 31)
8218 || (SUBREG_P (operands[0])
8219 && REG_P (SUBREG_REG (operands[0]))
8220 && REGNO (SUBREG_REG (operands[0])) <= 31))"
8221 [(set (match_dup 2) (match_dup 3))]
8222 {
8223 long l;
8224
8225 <real_value_to_target> (*CONST_DOUBLE_REAL_VALUE (operands[1]), l);
8226
8227 if (! TARGET_POWERPC64)
8228 operands[2] = operand_subword (operands[0], 0, 0, <MODE>mode);
8229 else
8230 operands[2] = gen_lowpart (SImode, operands[0]);
8231
8232 operands[3] = gen_int_mode (l, SImode);
8233 })
8234
8235 ;; Originally, we tried to keep movsf and movsd common, but the differences
8236 ;; addressing was making it rather difficult to hide with mode attributes. In
8237 ;; particular for SFmode, on ISA 2.07 (power8) systems, having the GPR store
8238 ;; before the VSX stores meant that the register allocator would tend to do a
8239 ;; direct move to the GPR (which involves conversion from scalar to
8240 ;; vector/memory formats) to save values in the traditional Altivec registers,
8241 ;; while SDmode had problems on power6 if the GPR store was not first due to
8242 ;; the power6 not having an integer store operation.
8243 ;;
8244 ;; LWZ LFS LXSSP LXSSPX STFS STXSSP
8245 ;; STXSSPX STW XXLXOR LI FMR XSCPSGNDP
8246 ;; MR MT<x> MF<x> NOP XXSPLTIDP
8247
8248 (define_insn "movsf_hardfloat"
8249 [(set (match_operand:SF 0 "nonimmediate_operand"
8250 "=!r, f, v, wa, m, wY,
8251 Z, m, wa, !r, f, wa,
8252 !r, *c*l, !r, *h, wa")
8253 (match_operand:SF 1 "input_operand"
8254 "m, m, wY, Z, f, v,
8255 wa, r, j, j, f, wa,
8256 r, r, *h, 0, eP"))]
8257 "(register_operand (operands[0], SFmode)
8258 || register_operand (operands[1], SFmode))
8259 && TARGET_HARD_FLOAT
8260 && (TARGET_ALLOW_SF_SUBREG
8261 || valid_sf_si_move (operands[0], operands[1], SFmode))"
8262 "@
8263 lwz%U1%X1 %0,%1
8264 lfs%U1%X1 %0,%1
8265 lxssp %0,%1
8266 lxsspx %x0,%y1
8267 stfs%U0%X0 %1,%0
8268 stxssp %1,%0
8269 stxsspx %x1,%y0
8270 stw%U0%X0 %1,%0
8271 xxlxor %x0,%x0,%x0
8272 li %0,0
8273 fmr %0,%1
8274 xscpsgndp %x0,%x1,%x1
8275 mr %0,%1
8276 mt%0 %1
8277 mf%1 %0
8278 nop
8279 #"
8280 [(set_attr "type"
8281 "load, fpload, fpload, fpload, fpstore, fpstore,
8282 fpstore, store, veclogical, integer, fpsimple, fpsimple,
8283 *, mtjmpr, mfjmpr, *, vecperm")
8284 (set_attr "isa"
8285 "*, *, p9v, p8v, *, p9v,
8286 p8v, *, *, *, *, *,
8287 *, *, *, *, p10")
8288 (set_attr "prefixed"
8289 "*, *, *, *, *, *,
8290 *, *, *, *, *, *,
8291 *, *, *, *, yes")])
8292
8293 ;; LWZ LFIWZX STW STFIWX MTVSRWZ MFVSRWZ
8294 ;; FMR MR MT%0 MF%1 NOP
8295 (define_insn "movsd_hardfloat"
8296 [(set (match_operand:SD 0 "nonimmediate_operand"
8297 "=!r, d, m, ?Z, ?d, ?r,
8298 f, !r, *c*l, !r, *h")
8299 (match_operand:SD 1 "input_operand"
8300 "m, ?Z, r, wx, r, d,
8301 f, r, r, *h, 0"))]
8302 "(register_operand (operands[0], SDmode)
8303 || register_operand (operands[1], SDmode))
8304 && TARGET_HARD_FLOAT"
8305 "@
8306 lwz%U1%X1 %0,%1
8307 lfiwzx %0,%y1
8308 stw%U0%X0 %1,%0
8309 stfiwx %1,%y0
8310 mtvsrwz %x0,%1
8311 mfvsrwz %0,%x1
8312 fmr %0,%1
8313 mr %0,%1
8314 mt%0 %1
8315 mf%1 %0
8316 nop"
8317 [(set_attr "type"
8318 "load, fpload, store, fpstore, mtvsr, mfvsr,
8319 fpsimple, *, mtjmpr, mfjmpr, *")
8320 (set_attr "isa"
8321 "*, p7, *, *, p8v, p8v,
8322 *, *, *, *, *")])
8323
8324 ;; MR MT%0 MF%0 LWZ STW LI
8325 ;; LIS G-const. F/n-const NOP
8326 (define_insn "*mov<mode>_softfloat"
8327 [(set (match_operand:FMOVE32 0 "nonimmediate_operand"
8328 "=r, *c*l, r, r, m, r,
8329 r, r, r, *h")
8330
8331 (match_operand:FMOVE32 1 "input_operand"
8332 "r, r, *h, m, r, I,
8333 L, G, Fn, 0"))]
8334
8335 "(gpc_reg_operand (operands[0], <MODE>mode)
8336 || gpc_reg_operand (operands[1], <MODE>mode))
8337 && TARGET_SOFT_FLOAT"
8338 "@
8339 mr %0,%1
8340 mt%0 %1
8341 mf%1 %0
8342 lwz%U1%X1 %0,%1
8343 stw%U0%X0 %1,%0
8344 li %0,%1
8345 lis %0,%v1
8346 #
8347 #
8348 nop"
8349 [(set_attr "type"
8350 "*, mtjmpr, mfjmpr, load, store, *,
8351 *, *, *, *")
8352
8353 (set_attr "length"
8354 "*, *, *, *, *, *,
8355 *, *, 8, *")])
8356
8357 ;; Like movsf, but adjust a SI value to be used in a SF context, i.e.
8358 ;; (set (reg:SF ...) (subreg:SF (reg:SI ...) 0))
8359 ;;
8360 ;; Because SF values are actually stored as DF values within the vector
8361 ;; registers, we need to convert the value to the vector SF format when
8362 ;; we need to use the bits in a union or similar cases. We only need
8363 ;; to do this transformation when the value is a vector register. Loads,
8364 ;; stores, and transfers within GPRs are assumed to be safe.
8365 ;;
8366 ;; This is a more general case of reload_vsx_from_gprsf. That insn must have
8367 ;; no alternatives, because the call is created as part of secondary_reload,
8368 ;; and operand #2's register class is used to allocate the temporary register.
8369 ;; This function is called before reload, and it creates the temporary as
8370 ;; needed.
8371
8372 ;; LWZ LFS LXSSP LXSSPX STW STFIWX
8373 ;; STXSIWX GPR->VSX VSX->GPR GPR->GPR
8374 (define_insn_and_split "movsf_from_si"
8375 [(set (match_operand:SF 0 "nonimmediate_operand"
8376 "=!r, f, v, wa, m, Z,
8377 Z, wa, ?r, !r")
8378 (unspec:SF [(match_operand:SI 1 "input_operand"
8379 "m, m, wY, Z, r, f,
8380 wa, r, wa, r")]
8381 UNSPEC_SF_FROM_SI))
8382 (clobber (match_scratch:DI 2
8383 "=X, X, X, X, X, X,
8384 X, r, X, X"))]
8385 "TARGET_NO_SF_SUBREG
8386 && (register_operand (operands[0], SFmode)
8387 || register_operand (operands[1], SImode))"
8388 "@
8389 lwz%U1%X1 %0,%1
8390 lfs%U1%X1 %0,%1
8391 lxssp %0,%1
8392 lxsspx %x0,%y1
8393 stw%U0%X0 %1,%0
8394 stfiwx %1,%y0
8395 stxsiwx %x1,%y0
8396 #
8397 mfvsrwz %0,%x1
8398 mr %0,%1"
8399
8400 "&& reload_completed
8401 && vsx_reg_sfsubreg_ok (operands[0], SFmode)
8402 && int_reg_operand_not_pseudo (operands[1], SImode)"
8403 [(const_int 0)]
8404 {
8405 rtx op0 = operands[0];
8406 rtx op1 = operands[1];
8407
8408 /* Move lowpart 32-bits from register for SFmode. */
8409 if (TARGET_P9_VECTOR)
8410 {
8411 /* Using mtvsrws;xscvspdpn. */
8412 rtx op0_v = gen_rtx_REG (V4SImode, REGNO (op0));
8413 emit_insn (gen_vsx_splat_v4si (op0_v, op1));
8414 emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0));
8415 }
8416 else
8417 {
8418 rtx op2 = operands[2];
8419 rtx op1_di = gen_rtx_REG (DImode, REGNO (op1));
8420
8421 /* Using sldi;mtvsrd;xscvspdpn. */
8422 emit_insn (gen_ashldi3 (op2, op1_di, GEN_INT (32)));
8423 emit_insn (gen_p8_mtvsrd_sf (op0, op2));
8424 emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0));
8425 }
8426
8427 DONE;
8428 }
8429 [(set_attr "length"
8430 "*, *, *, *, *, *,
8431 *, 12, *, *")
8432 (set_attr "type"
8433 "load, fpload, fpload, fpload, store, fpstore,
8434 fpstore, vecfloat, mfvsr, *")
8435 (set_attr "isa"
8436 "*, *, p9v, p8v, *, *,
8437 p8v, p8v, p8v, *")])
8438
8439 ;; For extracting high part element from DImode register like:
8440 ;; {%1:SF=unspec[r122:DI>>0x20#0] 86;clobber scratch;}
8441 ;; split it before reload with "and mask" to avoid generating shift right
8442 ;; 32 bit then shift left 32 bit.
8443 (define_insn_and_split "movsf_from_si2_<code>"
8444 [(set (match_operand:SF 0 "gpc_reg_operand" "=wa")
8445 (unspec:SF
8446 [(match_operator:SI 3 "lowpart_subreg_operator"
8447 [(any_shiftrt:DI
8448 (match_operand:DI 1 "input_operand" "r")
8449 (const_int 32))])]
8450 UNSPEC_SF_FROM_SI))
8451 (clobber (match_scratch:DI 2 "=r"))]
8452 "TARGET_NO_SF_SUBREG"
8453 "#"
8454 "&& 1"
8455 [(const_int 0)]
8456 {
8457 if (GET_CODE (operands[2]) == SCRATCH)
8458 operands[2] = gen_reg_rtx (DImode);
8459
8460 rtx mask = GEN_INT (HOST_WIDE_INT_M1U << 32);
8461 emit_insn (gen_anddi3 (operands[2], operands[1], mask));
8462 emit_insn (gen_p8_mtvsrd_sf (operands[0], operands[2]));
8463 emit_insn (gen_vsx_xscvspdpn_directmove (operands[0], operands[0]));
8464 DONE;
8465 }
8466 [(set_attr "length" "12")
8467 (set_attr "type" "vecfloat")
8468 (set_attr "isa" "p8v")])
8469
8470 ;; Move 64-bit binary/decimal floating point
8471 (define_expand "mov<mode>"
8472 [(set (match_operand:FMOVE64 0 "nonimmediate_operand")
8473 (match_operand:FMOVE64 1 "any_operand"))]
8474 ""
8475 {
8476 rs6000_emit_move (operands[0], operands[1], <MODE>mode);
8477 DONE;
8478 })
8479
8480 (define_split
8481 [(set (match_operand:FMOVE64 0 "gpc_reg_operand")
8482 (match_operand:FMOVE64 1 "const_int_operand"))]
8483 "! TARGET_POWERPC64 && reload_completed
8484 && ((REG_P (operands[0]) && REGNO (operands[0]) <= 31)
8485 || (SUBREG_P (operands[0])
8486 && REG_P (SUBREG_REG (operands[0]))
8487 && REGNO (SUBREG_REG (operands[0])) <= 31))"
8488 [(set (match_dup 2) (match_dup 4))
8489 (set (match_dup 3) (match_dup 1))]
8490 {
8491 int endian = (WORDS_BIG_ENDIAN == 0);
8492 HOST_WIDE_INT value = INTVAL (operands[1]);
8493
8494 operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
8495 operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
8496 operands[4] = GEN_INT (value >> 32);
8497 operands[1] = GEN_INT (sext_hwi (value, 32));
8498 })
8499
8500 (define_split
8501 [(set (match_operand:FMOVE64 0 "gpc_reg_operand")
8502 (match_operand:FMOVE64 1 "const_double_operand"))]
8503 "! TARGET_POWERPC64 && reload_completed
8504 && ((REG_P (operands[0]) && REGNO (operands[0]) <= 31)
8505 || (SUBREG_P (operands[0])
8506 && REG_P (SUBREG_REG (operands[0]))
8507 && REGNO (SUBREG_REG (operands[0])) <= 31))"
8508 [(set (match_dup 2) (match_dup 4))
8509 (set (match_dup 3) (match_dup 5))]
8510 {
8511 int endian = (WORDS_BIG_ENDIAN == 0);
8512 long l[2];
8513
8514 <real_value_to_target> (*CONST_DOUBLE_REAL_VALUE (operands[1]), l);
8515
8516 operands[2] = operand_subword (operands[0], endian, 0, <MODE>mode);
8517 operands[3] = operand_subword (operands[0], 1 - endian, 0, <MODE>mode);
8518 operands[4] = gen_int_mode (l[endian], SImode);
8519 operands[5] = gen_int_mode (l[1 - endian], SImode);
8520 })
8521
8522 (define_split
8523 [(set (match_operand:FMOVE64 0 "gpc_reg_operand")
8524 (match_operand:FMOVE64 1 "const_double_operand"))]
8525 "TARGET_POWERPC64 && reload_completed
8526 && ((REG_P (operands[0]) && REGNO (operands[0]) <= 31)
8527 || (SUBREG_P (operands[0])
8528 && REG_P (SUBREG_REG (operands[0]))
8529 && REGNO (SUBREG_REG (operands[0])) <= 31))"
8530 [(set (match_dup 2) (match_dup 3))]
8531 {
8532 int endian = (WORDS_BIG_ENDIAN == 0);
8533 long l[2];
8534 HOST_WIDE_INT val;
8535
8536 <real_value_to_target> (*CONST_DOUBLE_REAL_VALUE (operands[1]), l);
8537
8538 operands[2] = gen_lowpart (DImode, operands[0]);
8539 /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN. */
8540 val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
8541 | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
8542
8543 operands[3] = gen_int_mode (val, DImode);
8544 })
8545
8546 ;; Don't have reload use general registers to load a constant. It is
8547 ;; less efficient than loading the constant into an FP register, since
8548 ;; it will probably be used there.
8549
8550 ;; The move constraints are ordered to prefer floating point registers before
8551 ;; general purpose registers to avoid doing a store and a load to get the value
8552 ;; into a floating point register when it is needed for a floating point
8553 ;; operation. Prefer traditional floating point registers over VSX registers,
8554 ;; since the D-form version of the memory instructions does not need a GPR for
8555 ;; reloading. ISA 3.0 (power9) adds D-form addressing for scalars to Altivec
8556 ;; registers.
8557
8558 ;; If we have FPR registers, rs6000_emit_move has moved all constants to memory,
8559 ;; except for 0.0 which can be created on VSX with an xor instruction.
8560
8561 ;; STFD LFD FMR LXSD STXSD
8562 ;; LXSD STXSD XXLOR XXLXOR GPR<-0
8563 ;; LWZ STW MR XXSPLTIDP
8564
8565
8566 (define_insn "*mov<mode>_hardfloat32"
8567 [(set (match_operand:FMOVE64 0 "nonimmediate_operand"
8568 "=m, d, d, <f64_p9>, wY,
8569 <f64_av>, Z, <f64_vsx>, <f64_vsx>, !r,
8570 Y, r, !r, wa")
8571 (match_operand:FMOVE64 1 "input_operand"
8572 "d, m, d, wY, <f64_p9>,
8573 Z, <f64_av>, <f64_vsx>, <zero_fp>, <zero_fp>,
8574 r, Y, r, eP"))]
8575 "! TARGET_POWERPC64 && TARGET_HARD_FLOAT
8576 && (gpc_reg_operand (operands[0], <MODE>mode)
8577 || gpc_reg_operand (operands[1], <MODE>mode))"
8578 "@
8579 stfd%U0%X0 %1,%0
8580 lfd%U1%X1 %0,%1
8581 fmr %0,%1
8582 lxsd %0,%1
8583 stxsd %1,%0
8584 lxsdx %x0,%y1
8585 stxsdx %x1,%y0
8586 xxlor %x0,%x1,%x1
8587 xxlxor %x0,%x0,%x0
8588 #
8589 #
8590 #
8591 #
8592 #"
8593 [(set_attr "type"
8594 "fpstore, fpload, fpsimple, fpload, fpstore,
8595 fpload, fpstore, veclogical, veclogical, two,
8596 store, load, two, vecperm")
8597 (set_attr "size" "64")
8598 (set_attr "length"
8599 "*, *, *, *, *,
8600 *, *, *, *, 8,
8601 8, 8, 8, *")
8602 (set_attr "isa"
8603 "*, *, *, p9v, p9v,
8604 p7v, p7v, *, *, *,
8605 *, *, *, p10")
8606 (set_attr "prefixed"
8607 "*, *, *, *, *,
8608 *, *, *, *, *,
8609 *, *, *, yes")])
8610
8611 ;; STW LWZ MR G-const H-const F-const
8612
8613 (define_insn "*mov<mode>_softfloat32"
8614 [(set (match_operand:FMOVE64 0 "nonimmediate_operand"
8615 "=Y, r, r, r, r, r")
8616
8617 (match_operand:FMOVE64 1 "input_operand"
8618 "r, Y, r, G, H, F"))]
8619
8620 "!TARGET_POWERPC64
8621 && (gpc_reg_operand (operands[0], <MODE>mode)
8622 || gpc_reg_operand (operands[1], <MODE>mode))"
8623 "#"
8624 [(set_attr "type"
8625 "store, load, two, *, *, *")
8626
8627 (set_attr "length"
8628 "8, 8, 8, 8, 12, 16")])
8629
8630 ; ld/std require word-aligned displacements -> 'Y' constraint.
8631 ; List Y->r and r->Y before r->r for reload.
8632
8633 ;; STFD LFD FMR LXSD STXSD
8634 ;; LXSDX STXSDX XXLOR XXLXOR LI 0
8635 ;; STD LD MR MT{CTR,LR} MF{CTR,LR}
8636 ;; NOP MFVSRD MTVSRD XXSPLTIDP
8637
8638 (define_insn "*mov<mode>_hardfloat64"
8639 [(set (match_operand:FMOVE64 0 "nonimmediate_operand"
8640 "=m, d, d, <f64_p9>, wY,
8641 <f64_av>, Z, <f64_vsx>, <f64_vsx>, !r,
8642 YZ, r, !r, *c*l, !r,
8643 *h, r, <f64_dm>, wa")
8644 (match_operand:FMOVE64 1 "input_operand"
8645 "d, m, d, wY, <f64_p9>,
8646 Z, <f64_av>, <f64_vsx>, <zero_fp>, <zero_fp>,
8647 r, YZ, r, r, *h,
8648 0, <f64_dm>, r, eP"))]
8649 "TARGET_POWERPC64 && TARGET_HARD_FLOAT
8650 && (gpc_reg_operand (operands[0], <MODE>mode)
8651 || gpc_reg_operand (operands[1], <MODE>mode))"
8652 "@
8653 stfd%U0%X0 %1,%0
8654 lfd%U1%X1 %0,%1
8655 fmr %0,%1
8656 lxsd %0,%1
8657 stxsd %1,%0
8658 lxsdx %x0,%y1
8659 stxsdx %x1,%y0
8660 xxlor %x0,%x1,%x1
8661 xxlxor %x0,%x0,%x0
8662 li %0,0
8663 std%U0%X0 %1,%0
8664 ld%U1%X1 %0,%1
8665 mr %0,%1
8666 mt%0 %1
8667 mf%1 %0
8668 nop
8669 mfvsrd %0,%x1
8670 mtvsrd %x0,%1
8671 #"
8672 [(set_attr "type"
8673 "fpstore, fpload, fpsimple, fpload, fpstore,
8674 fpload, fpstore, veclogical, veclogical, integer,
8675 store, load, *, mtjmpr, mfjmpr,
8676 *, mfvsr, mtvsr, vecperm")
8677 (set_attr "size" "64")
8678 (set_attr "isa"
8679 "*, *, *, p9v, p9v,
8680 p7v, p7v, *, *, *,
8681 *, *, *, *, *,
8682 *, p8v, p8v, p10")
8683 (set_attr "prefixed"
8684 "*, *, *, *, *,
8685 *, *, *, *, *,
8686 *, *, *, *, *,
8687 *, *, *, *")])
8688
8689 ;; STD LD MR MT<SPR> MF<SPR> G-const
8690 ;; H-const F-const Special
8691
8692 (define_insn "*mov<mode>_softfloat64"
8693 [(set (match_operand:FMOVE64 0 "nonimmediate_operand"
8694 "=Y, r, r, *c*l, r, r,
8695 r, r, *h")
8696
8697 (match_operand:FMOVE64 1 "input_operand"
8698 "r, Y, r, r, *h, G,
8699 H, F, 0"))]
8700
8701 "TARGET_POWERPC64 && TARGET_SOFT_FLOAT
8702 && (gpc_reg_operand (operands[0], <MODE>mode)
8703 || gpc_reg_operand (operands[1], <MODE>mode))"
8704 "@
8705 std%U0%X0 %1,%0
8706 ld%U1%X1 %0,%1
8707 mr %0,%1
8708 mt%0 %1
8709 mf%1 %0
8710 #
8711 #
8712 #
8713 nop"
8714 [(set_attr "type"
8715 "store, load, *, mtjmpr, mfjmpr, *,
8716 *, *, *")
8717
8718 (set_attr "length"
8719 "*, *, *, *, *, 8,
8720 12, 16, *")])
8721
8722 ;; Split the VSX prefixed instruction to support SFmode and DFmode scalar
8723 ;; constants that look like DFmode floating point values where both elements
8724 ;; are the same. The constant has to be expressible as a SFmode constant that
8725 ;; is not a SFmode denormal value.
8726 ;;
8727 ;; We don't need splitters for the 128-bit types, since the function
8728 ;; rs6000_output_move_128bit handles the generation of XXSPLTIDP.
8729 (define_insn "xxspltidp_<mode>_internal"
8730 [(set (match_operand:SFDF 0 "register_operand" "=wa")
8731 (unspec:SFDF [(match_operand:SI 1 "c32bit_cint_operand" "n")]
8732 UNSPEC_XXSPLTIDP_CONST))]
8733 "TARGET_POWER10"
8734 "xxspltidp %x0,%1"
8735 [(set_attr "type" "vecperm")
8736 (set_attr "prefixed" "yes")])
8737
8738 (define_insn "xxspltiw_<mode>_internal"
8739 [(set (match_operand:SFDF 0 "register_operand" "=wa")
8740 (unspec:SFDF [(match_operand:SI 1 "c32bit_cint_operand" "n")]
8741 UNSPEC_XXSPLTIW_CONST))]
8742 "TARGET_POWER10"
8743 "xxspltiw %x0,%1"
8744 [(set_attr "type" "vecperm")
8745 (set_attr "prefixed" "yes")])
8746
8747 (define_split
8748 [(set (match_operand:SFDF 0 "vsx_register_operand")
8749 (match_operand:SFDF 1 "vsx_prefixed_constant"))]
8750 "TARGET_POWER10"
8751 [(pc)]
8752 {
8753 rtx dest = operands[0];
8754 rtx src = operands[1];
8755 vec_const_128bit_type vsx_const;
8756
8757 if (!vec_const_128bit_to_bytes (src, <MODE>mode, &vsx_const))
8758 gcc_unreachable ();
8759
8760 unsigned imm = constant_generates_xxspltidp (&vsx_const);
8761 if (imm)
8762 {
8763 emit_insn (gen_xxspltidp_<mode>_internal (dest, GEN_INT (imm)));
8764 DONE;
8765 }
8766
8767 imm = constant_generates_xxspltiw (&vsx_const);
8768 if (imm)
8769 {
8770 emit_insn (gen_xxspltiw_<mode>_internal (dest, GEN_INT (imm)));
8771 DONE;
8772 }
8773
8774 else
8775 gcc_unreachable ();
8776 })
8777
8778 (define_expand "mov<mode>"
8779 [(set (match_operand:FMOVE128 0 "general_operand")
8780 (match_operand:FMOVE128 1 "any_operand"))]
8781 ""
8782 {
8783 rs6000_emit_move (operands[0], operands[1], <MODE>mode);
8784 DONE;
8785 })
8786
8787 ;; It's important to list Y->r and r->Y before r->r because otherwise
8788 ;; reload, given m->r, will try to pick r->r and reload it, which
8789 ;; doesn't make progress.
8790
8791 ;; We can't split little endian direct moves of TDmode, because the words are
8792 ;; not swapped like they are for TImode or TFmode. Subregs therefore are
8793 ;; problematical. Don't allow direct move for this case.
8794
8795 ;; FPR load FPR store FPR move FPR zero GPR load
8796 ;; GPR zero GPR store GPR move MFVSRD MTVSRD
8797
8798 (define_insn_and_split "*mov<mode>_64bit_dm"
8799 [(set (match_operand:FMOVE128_FPR 0 "nonimmediate_operand"
8800 "=m, d, d, d, Y,
8801 r, r, r, r, d")
8802
8803 (match_operand:FMOVE128_FPR 1 "input_operand"
8804 "d, m, d, <zero_fp>, r,
8805 <zero_fp>, Y, r, d, r"))]
8806
8807 "TARGET_HARD_FLOAT && TARGET_POWERPC64 && FLOAT128_2REG_P (<MODE>mode)
8808 && (<MODE>mode != TDmode || WORDS_BIG_ENDIAN)
8809 && (gpc_reg_operand (operands[0], <MODE>mode)
8810 || gpc_reg_operand (operands[1], <MODE>mode))"
8811 "#"
8812 "&& reload_completed"
8813 [(pc)]
8814 {
8815 rs6000_split_multireg_move (operands[0], operands[1]);
8816 DONE;
8817 }
8818 [(set_attr "length" "8")
8819 (set_attr "isa" "*,*,*,*,*,*,*,*,p8v,p8v")
8820 (set_attr "max_prefixed_insns" "2")
8821 (set_attr "num_insns" "2")])
8822
8823 (define_insn_and_split "*movtd_64bit_nodm"
8824 [(set (match_operand:TD 0 "nonimmediate_operand" "=m,d,d,Y,r,r")
8825 (match_operand:TD 1 "input_operand" "d,m,d,r,Y,r"))]
8826 "TARGET_HARD_FLOAT && TARGET_POWERPC64 && !WORDS_BIG_ENDIAN
8827 && (gpc_reg_operand (operands[0], TDmode)
8828 || gpc_reg_operand (operands[1], TDmode))"
8829 "#"
8830 "&& reload_completed"
8831 [(pc)]
8832 {
8833 rs6000_split_multireg_move (operands[0], operands[1]);
8834 DONE;
8835 }
8836 [(set_attr "length" "8,8,8,12,12,8")
8837 (set_attr "max_prefixed_insns" "2")
8838 (set_attr "num_insns" "2,2,2,3,3,2")])
8839
8840 (define_insn_and_split "*mov<mode>_32bit"
8841 [(set (match_operand:FMOVE128_FPR 0 "nonimmediate_operand" "=m,d,d,d,Y,r,r")
8842 (match_operand:FMOVE128_FPR 1 "input_operand" "d,m,d,<zero_fp>,r,<zero_fp>Y,r"))]
8843 "TARGET_HARD_FLOAT && !TARGET_POWERPC64
8844 && (FLOAT128_2REG_P (<MODE>mode)
8845 || int_reg_operand_not_pseudo (operands[0], <MODE>mode)
8846 || int_reg_operand_not_pseudo (operands[1], <MODE>mode))
8847 && (gpc_reg_operand (operands[0], <MODE>mode)
8848 || gpc_reg_operand (operands[1], <MODE>mode))"
8849 "#"
8850 "&& reload_completed"
8851 [(pc)]
8852 {
8853 rs6000_split_multireg_move (operands[0], operands[1]);
8854 DONE;
8855 }
8856 [(set_attr "length" "8,8,8,8,20,20,16")])
8857
8858 (define_insn_and_split "*mov<mode>_softfloat"
8859 [(set (match_operand:FMOVE128 0 "nonimmediate_operand" "=Y,r,r,r")
8860 (match_operand:FMOVE128 1 "input_operand" "r,Y,F,r"))]
8861 "TARGET_SOFT_FLOAT
8862 && (gpc_reg_operand (operands[0], <MODE>mode)
8863 || gpc_reg_operand (operands[1], <MODE>mode))"
8864 "#"
8865 "&& reload_completed"
8866 [(pc)]
8867 {
8868 rs6000_split_multireg_move (operands[0], operands[1]);
8869 DONE;
8870 }
8871 [(set_attr_alternative "length"
8872 [(if_then_else (match_test "TARGET_POWERPC64")
8873 (const_string "8")
8874 (const_string "16"))
8875 (if_then_else (match_test "TARGET_POWERPC64")
8876 (const_string "8")
8877 (const_string "16"))
8878 (if_then_else (match_test "TARGET_POWERPC64")
8879 (const_string "16")
8880 (const_string "32"))
8881 (if_then_else (match_test "TARGET_POWERPC64")
8882 (const_string "8")
8883 (const_string "16"))])])
8884
8885 (define_expand "@extenddf<mode>2"
8886 [(set (match_operand:FLOAT128 0 "gpc_reg_operand")
8887 (float_extend:FLOAT128 (match_operand:DF 1 "gpc_reg_operand")))]
8888 "TARGET_HARD_FLOAT
8889 && (TARGET_LONG_DOUBLE_128 || FLOAT128_IEEE_P (<MODE>mode))"
8890 {
8891 if (FLOAT128_IEEE_P (<MODE>mode))
8892 rs6000_expand_float128_convert (operands[0], operands[1], false);
8893 else if (TARGET_VSX)
8894 emit_insn (gen_extenddf2_vsx (<MODE>mode, operands[0], operands[1]));
8895 else
8896 {
8897 rtx zero = gen_reg_rtx (DFmode);
8898 rs6000_emit_move (zero, CONST0_RTX (DFmode), DFmode);
8899
8900 emit_insn (gen_extenddf2_fprs (<MODE>mode,
8901 operands[0], operands[1], zero));
8902 }
8903 DONE;
8904 })
8905
8906 ;; Allow memory operands for the source to be created by the combiner.
8907 (define_insn_and_split "@extenddf<mode>2_fprs"
8908 [(set (match_operand:IBM128 0 "gpc_reg_operand" "=d,d,&d")
8909 (float_extend:IBM128
8910 (match_operand:DF 1 "nonimmediate_operand" "d,m,d")))
8911 (use (match_operand:DF 2 "nonimmediate_operand" "m,m,d"))]
8912 "!TARGET_VSX && TARGET_HARD_FLOAT
8913 && TARGET_LONG_DOUBLE_128"
8914 "#"
8915 "&& reload_completed"
8916 [(set (match_dup 3) (match_dup 1))
8917 (set (match_dup 4) (match_dup 2))]
8918 {
8919 const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
8920 const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
8921
8922 operands[3] = simplify_gen_subreg (DFmode, operands[0], <MODE>mode, hi_word);
8923 operands[4] = simplify_gen_subreg (DFmode, operands[0], <MODE>mode, lo_word);
8924 })
8925
8926 (define_insn_and_split "@extenddf<mode>2_vsx"
8927 [(set (match_operand:IBM128 0 "gpc_reg_operand" "=d,d")
8928 (float_extend:IBM128
8929 (match_operand:DF 1 "nonimmediate_operand" "wa,m")))]
8930 "TARGET_LONG_DOUBLE_128 && TARGET_VSX"
8931 "#"
8932 "&& reload_completed"
8933 [(set (match_dup 2) (match_dup 1))
8934 (set (match_dup 3) (match_dup 4))]
8935 {
8936 const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
8937 const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
8938
8939 operands[2] = simplify_gen_subreg (DFmode, operands[0], <MODE>mode, hi_word);
8940 operands[3] = simplify_gen_subreg (DFmode, operands[0], <MODE>mode, lo_word);
8941 operands[4] = CONST0_RTX (DFmode);
8942 })
8943
8944 (define_expand "extendsf<mode>2"
8945 [(set (match_operand:FLOAT128 0 "gpc_reg_operand")
8946 (float_extend:FLOAT128 (match_operand:SF 1 "gpc_reg_operand")))]
8947 "TARGET_HARD_FLOAT
8948 && (TARGET_LONG_DOUBLE_128 || FLOAT128_IEEE_P (<MODE>mode))"
8949 {
8950 if (FLOAT128_IEEE_P (<MODE>mode))
8951 rs6000_expand_float128_convert (operands[0], operands[1], false);
8952 else
8953 {
8954 rtx tmp = gen_reg_rtx (DFmode);
8955 emit_insn (gen_extendsfdf2 (tmp, operands[1]));
8956 emit_insn (gen_extenddf<mode>2 (operands[0], tmp));
8957 }
8958 DONE;
8959 })
8960
8961 (define_expand "trunc<mode>df2"
8962 [(set (match_operand:DF 0 "gpc_reg_operand")
8963 (float_truncate:DF (match_operand:FLOAT128 1 "gpc_reg_operand")))]
8964 "TARGET_HARD_FLOAT
8965 && (TARGET_LONG_DOUBLE_128 || FLOAT128_IEEE_P (<MODE>mode))"
8966 {
8967 if (FLOAT128_IEEE_P (<MODE>mode))
8968 {
8969 rs6000_expand_float128_convert (operands[0], operands[1], false);
8970 DONE;
8971 }
8972 })
8973
8974 (define_insn_and_split "trunc<mode>df2_internal1"
8975 [(set (match_operand:DF 0 "gpc_reg_operand" "=d,?d")
8976 (float_truncate:DF
8977 (match_operand:IBM128 1 "gpc_reg_operand" "0,d")))]
8978 "!TARGET_XL_COMPAT
8979 && TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128"
8980 "@
8981 #
8982 fmr %0,%1"
8983 "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
8984 [(const_int 0)]
8985 {
8986 emit_note (NOTE_INSN_DELETED);
8987 DONE;
8988 }
8989 [(set_attr "type" "fpsimple")])
8990
8991 (define_insn "trunc<mode>df2_internal2"
8992 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
8993 (float_truncate:DF (match_operand:IBM128 1 "gpc_reg_operand" "d")))]
8994 "TARGET_XL_COMPAT && TARGET_HARD_FLOAT
8995 && TARGET_LONG_DOUBLE_128"
8996 "fadd %0,%1,%L1"
8997 [(set_attr "type" "fp")])
8998
8999 (define_expand "trunc<mode>sf2"
9000 [(set (match_operand:SF 0 "gpc_reg_operand")
9001 (float_truncate:SF (match_operand:FLOAT128 1 "gpc_reg_operand")))]
9002 "TARGET_HARD_FLOAT
9003 && (TARGET_LONG_DOUBLE_128 || FLOAT128_IEEE_P (<MODE>mode))"
9004 {
9005 if (FLOAT128_IEEE_P (<MODE>mode))
9006 rs6000_expand_float128_convert (operands[0], operands[1], false);
9007 else
9008 {
9009 rtx tmp = gen_reg_rtx (DFmode);
9010 emit_insn (gen_trunc<mode>df2 (tmp, operands[1]));
9011 emit_insn (gen_truncdfsf2 (operands[0], tmp));
9012 }
9013 DONE;
9014 })
9015
9016 (define_expand "floatsi<mode>2"
9017 [(parallel [(set (match_operand:FLOAT128 0 "gpc_reg_operand")
9018 (float:FLOAT128 (match_operand:SI 1 "gpc_reg_operand")))
9019 (clobber (match_scratch:DI 2))])]
9020 "TARGET_HARD_FLOAT
9021 && (TARGET_LONG_DOUBLE_128 || FLOAT128_IEEE_P (<MODE>mode))"
9022 {
9023 rtx op0 = operands[0];
9024 rtx op1 = operands[1];
9025
9026 if (TARGET_FLOAT128_HW && FLOAT128_IEEE_P (<MODE>mode))
9027 ;
9028 else if (FLOAT128_IEEE_P (<MODE>mode))
9029 {
9030 rs6000_expand_float128_convert (op0, op1, false);
9031 DONE;
9032 }
9033 else
9034 {
9035 rtx tmp = gen_reg_rtx (DFmode);
9036 expand_float (tmp, op1, false);
9037 emit_insn (gen_extenddf2 (<MODE>mode, op0, tmp));
9038 DONE;
9039 }
9040 })
9041
9042 ; fadd, but rounding towards zero.
9043 ; This is probably not the optimal code sequence.
9044 (define_insn "fix_trunc_helper<mode>"
9045 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
9046 (unspec:DF [(match_operand:IBM128 1 "gpc_reg_operand" "d")]
9047 UNSPEC_FIX_TRUNC_TF))
9048 (clobber (match_operand:DF 2 "gpc_reg_operand" "=&d"))]
9049 "TARGET_HARD_FLOAT"
9050 "mffs %2\n\tmtfsb1 31\n\tmtfsb0 30\n\tfadd %0,%1,%L1\n\tmtfsf 1,%2"
9051 [(set_attr "type" "fp")
9052 (set_attr "length" "20")])
9053
9054 (define_expand "fix_trunc<mode>si2"
9055 [(set (match_operand:SI 0 "gpc_reg_operand")
9056 (fix:SI (match_operand:FLOAT128 1 "gpc_reg_operand")))]
9057 "TARGET_HARD_FLOAT
9058 && (TARGET_LONG_DOUBLE_128 || FLOAT128_IEEE_P (<MODE>mode))"
9059 {
9060 rtx op0 = operands[0];
9061 rtx op1 = operands[1];
9062
9063 if (TARGET_FLOAT128_HW && FLOAT128_IEEE_P (<MODE>mode))
9064 ;
9065 else
9066 {
9067 if (FLOAT128_IEEE_P (<MODE>mode))
9068 rs6000_expand_float128_convert (op0, op1, false);
9069 else
9070 emit_insn (gen_fix_truncsi2_fprs (<MODE>mode, op0, op1));
9071 DONE;
9072 }
9073 })
9074
9075 (define_expand "@fix_trunc<mode>si2_fprs"
9076 [(parallel [(set (match_operand:SI 0 "gpc_reg_operand")
9077 (fix:SI (match_operand:IBM128 1 "gpc_reg_operand")))
9078 (clobber (match_dup 2))
9079 (clobber (match_dup 3))
9080 (clobber (match_dup 4))
9081 (clobber (match_dup 5))])]
9082 "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128"
9083 {
9084 operands[2] = gen_reg_rtx (DFmode);
9085 operands[3] = gen_reg_rtx (DFmode);
9086 operands[4] = gen_reg_rtx (DImode);
9087 operands[5] = assign_stack_temp (DImode, GET_MODE_SIZE (DImode));
9088 })
9089
9090 (define_insn_and_split "*fix_trunc<mode>si2_internal"
9091 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
9092 (fix:SI (match_operand:IBM128 1 "gpc_reg_operand" "d")))
9093 (clobber (match_operand:DF 2 "gpc_reg_operand" "=d"))
9094 (clobber (match_operand:DF 3 "gpc_reg_operand" "=&d"))
9095 (clobber (match_operand:DI 4 "gpc_reg_operand" "=d"))
9096 (clobber (match_operand:DI 5 "offsettable_mem_operand" "=o"))]
9097 "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128"
9098 "#"
9099 "&& 1"
9100 [(pc)]
9101 {
9102 rtx lowword;
9103 emit_insn (gen_fix_trunc_helper<mode> (operands[2], operands[1],
9104 operands[3]));
9105
9106 gcc_assert (MEM_P (operands[5]));
9107 lowword = adjust_address (operands[5], SImode, WORDS_BIG_ENDIAN ? 4 : 0);
9108
9109 emit_insn (gen_fctiwz_df (operands[4], operands[2]));
9110 emit_move_insn (operands[5], operands[4]);
9111 emit_move_insn (operands[0], lowword);
9112 DONE;
9113 })
9114
9115 (define_expand "fix_trunc<mode>di2"
9116 [(set (match_operand:DI 0 "gpc_reg_operand")
9117 (fix:DI (match_operand:IEEE128 1 "gpc_reg_operand")))]
9118 "TARGET_FLOAT128_TYPE"
9119 {
9120 if (!TARGET_FLOAT128_HW)
9121 {
9122 rs6000_expand_float128_convert (operands[0], operands[1], false);
9123 DONE;
9124 }
9125 })
9126
9127 (define_expand "fixuns_trunc<IEEE128:mode><SDI:mode>2"
9128 [(set (match_operand:SDI 0 "gpc_reg_operand")
9129 (unsigned_fix:SDI (match_operand:IEEE128 1 "gpc_reg_operand")))]
9130 "TARGET_FLOAT128_TYPE"
9131 {
9132 rs6000_expand_float128_convert (operands[0], operands[1], true);
9133 DONE;
9134 })
9135
9136 (define_expand "floatdi<mode>2"
9137 [(set (match_operand:IEEE128 0 "gpc_reg_operand")
9138 (float:IEEE128 (match_operand:DI 1 "gpc_reg_operand")))]
9139 "TARGET_FLOAT128_TYPE"
9140 {
9141 if (!TARGET_FLOAT128_HW)
9142 {
9143 rs6000_expand_float128_convert (operands[0], operands[1], false);
9144 DONE;
9145 }
9146 })
9147
9148 (define_expand "floatunsdi<IEEE128:mode>2"
9149 [(set (match_operand:IEEE128 0 "gpc_reg_operand")
9150 (unsigned_float:IEEE128 (match_operand:DI 1 "gpc_reg_operand")))]
9151 "TARGET_FLOAT128_TYPE"
9152 {
9153 if (!TARGET_FLOAT128_HW)
9154 {
9155 rs6000_expand_float128_convert (operands[0], operands[1], true);
9156 DONE;
9157 }
9158 })
9159
9160 (define_expand "floatuns<IEEE128:mode>2"
9161 [(set (match_operand:IEEE128 0 "gpc_reg_operand")
9162 (unsigned_float:IEEE128 (match_operand:SI 1 "gpc_reg_operand")))]
9163 "TARGET_FLOAT128_TYPE"
9164 {
9165 rtx op0 = operands[0];
9166 rtx op1 = operands[1];
9167
9168 if (TARGET_FLOAT128_HW)
9169 emit_insn (gen_floatuns_<IEEE128:mode>si2_hw (op0, op1));
9170 else
9171 rs6000_expand_float128_convert (op0, op1, true);
9172 DONE;
9173 })
9174
9175 (define_expand "neg<mode>2"
9176 [(set (match_operand:FLOAT128 0 "gpc_reg_operand")
9177 (neg:FLOAT128 (match_operand:FLOAT128 1 "gpc_reg_operand")))]
9178 "FLOAT128_IEEE_P (<MODE>mode)
9179 || (FLOAT128_IBM_P (<MODE>mode) && TARGET_HARD_FLOAT)"
9180 {
9181 if (FLOAT128_IEEE_P (<MODE>mode))
9182 {
9183 if (TARGET_FLOAT128_HW)
9184 emit_insn (gen_neg2_hw (<MODE>mode, operands[0], operands[1]));
9185 else if (TARGET_FLOAT128_TYPE)
9186 emit_insn (gen_ieee_128bit_vsx_neg2 (<MODE>mode,
9187 operands[0], operands[1]));
9188 else
9189 {
9190 rtx libfunc = optab_libfunc (neg_optab, <MODE>mode);
9191 rtx target = emit_library_call_value (libfunc, operands[0], LCT_CONST,
9192 <MODE>mode,
9193 operands[1], <MODE>mode);
9194
9195 if (target && !rtx_equal_p (target, operands[0]))
9196 emit_move_insn (operands[0], target);
9197 }
9198 DONE;
9199 }
9200 })
9201
9202 (define_insn "neg<mode>2_internal"
9203 [(set (match_operand:IBM128 0 "gpc_reg_operand" "=d")
9204 (neg:IBM128 (match_operand:IBM128 1 "gpc_reg_operand" "d")))]
9205 "TARGET_HARD_FLOAT"
9206 {
9207 if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
9208 return "fneg %L0,%L1\;fneg %0,%1";
9209 else
9210 return "fneg %0,%1\;fneg %L0,%L1";
9211 }
9212 [(set_attr "type" "fpsimple")
9213 (set_attr "length" "8")])
9214
9215 (define_expand "abs<mode>2"
9216 [(set (match_operand:FLOAT128 0 "gpc_reg_operand")
9217 (abs:FLOAT128 (match_operand:FLOAT128 1 "gpc_reg_operand")))]
9218 "FLOAT128_IEEE_P (<MODE>mode)
9219 || (FLOAT128_IBM_P (<MODE>mode) && TARGET_HARD_FLOAT)"
9220 {
9221 rtx label;
9222
9223 if (FLOAT128_IEEE_P (<MODE>mode))
9224 {
9225 if (TARGET_FLOAT128_HW)
9226 {
9227 emit_insn (gen_abs2_hw (<MODE>mode, operands[0], operands[1]));
9228 DONE;
9229 }
9230 else if (TARGET_FLOAT128_TYPE)
9231 {
9232 emit_insn (gen_ieee_128bit_vsx_abs2 (<MODE>mode,
9233 operands[0], operands[1]));
9234 DONE;
9235 }
9236 else
9237 FAIL;
9238 }
9239
9240 label = gen_label_rtx ();
9241 emit_insn (gen_abs2_internal (<MODE>mode, operands[0], operands[1], label));
9242 emit_label (label);
9243 DONE;
9244 })
9245
9246 (define_expand "@abs<mode>2_internal"
9247 [(set (match_operand:IBM128 0 "gpc_reg_operand")
9248 (match_operand:IBM128 1 "gpc_reg_operand"))
9249 (set (match_dup 3) (match_dup 5))
9250 (set (match_dup 5) (abs:DF (match_dup 5)))
9251 (set (match_dup 4) (compare:CCFP (match_dup 3) (match_dup 5)))
9252 (set (pc) (if_then_else (eq (match_dup 4) (const_int 0))
9253 (label_ref (match_operand 2 ""))
9254 (pc)))
9255 (set (match_dup 6) (neg:DF (match_dup 6)))]
9256 "TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128"
9257 {
9258 const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
9259 const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
9260 operands[3] = gen_reg_rtx (DFmode);
9261 operands[4] = gen_reg_rtx (CCFPmode);
9262 operands[5] = simplify_gen_subreg (DFmode, operands[0], <MODE>mode, hi_word);
9263 operands[6] = simplify_gen_subreg (DFmode, operands[0], <MODE>mode, lo_word);
9264 })
9265
9266
9267 ;; Generate IEEE 128-bit -0.0 (0x80000000000000000000000000000000) in a vector
9268 ;; register
9269
9270 (define_expand "ieee_128bit_negative_zero"
9271 [(set (match_operand:V16QI 0 "register_operand") (match_dup 1))]
9272 "TARGET_FLOAT128_TYPE"
9273 {
9274 rtvec v = rtvec_alloc (16);
9275 int i, high;
9276
9277 for (i = 0; i < 16; i++)
9278 RTVEC_ELT (v, i) = const0_rtx;
9279
9280 high = (BYTES_BIG_ENDIAN) ? 0 : 15;
9281 RTVEC_ELT (v, high) = gen_int_mode (0x80, QImode);
9282
9283 rs6000_expand_vector_init (operands[0], gen_rtx_PARALLEL (V16QImode, v));
9284 DONE;
9285 })
9286
9287 ;; IEEE 128-bit negate
9288
9289 ;; We have 2 insns here for negate and absolute value. The first uses
9290 ;; match_scratch so that phases like combine can recognize neg/abs as generic
9291 ;; insns, and second insn after the first split pass loads up the bit to
9292 ;; twiddle the sign bit. Later GCSE passes can then combine multiple uses of
9293 ;; neg/abs to create the constant just once.
9294
9295 (define_insn_and_split "@ieee_128bit_vsx_neg<mode>2"
9296 [(set (match_operand:IEEE128 0 "register_operand" "=wa")
9297 (neg:IEEE128 (match_operand:IEEE128 1 "register_operand" "wa")))
9298 (clobber (match_scratch:V16QI 2 "=v"))]
9299 "TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_HW"
9300 "#"
9301 "&& 1"
9302 [(parallel [(set (match_dup 0)
9303 (neg:IEEE128 (match_dup 1)))
9304 (use (match_dup 2))])]
9305 {
9306 if (GET_CODE (operands[2]) == SCRATCH)
9307 operands[2] = gen_reg_rtx (V16QImode);
9308
9309 emit_insn (gen_ieee_128bit_negative_zero (operands[2]));
9310 }
9311 [(set_attr "length" "8")
9312 (set_attr "type" "vecsimple")])
9313
9314 (define_insn "*ieee_128bit_vsx_neg<mode>2_internal"
9315 [(set (match_operand:IEEE128 0 "register_operand" "=wa")
9316 (neg:IEEE128 (match_operand:IEEE128 1 "register_operand" "wa")))
9317 (use (match_operand:V16QI 2 "register_operand" "v"))]
9318 "TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_HW"
9319 "xxlxor %x0,%x1,%x2"
9320 [(set_attr "type" "veclogical")])
9321
9322 ;; IEEE 128-bit absolute value
9323 (define_insn_and_split "@ieee_128bit_vsx_abs<mode>2"
9324 [(set (match_operand:IEEE128 0 "register_operand" "=wa")
9325 (abs:IEEE128 (match_operand:IEEE128 1 "register_operand" "wa")))
9326 (clobber (match_scratch:V16QI 2 "=v"))]
9327 "TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_HW"
9328 "#"
9329 "&& 1"
9330 [(parallel [(set (match_dup 0)
9331 (abs:IEEE128 (match_dup 1)))
9332 (use (match_dup 2))])]
9333 {
9334 if (GET_CODE (operands[2]) == SCRATCH)
9335 operands[2] = gen_reg_rtx (V16QImode);
9336
9337 emit_insn (gen_ieee_128bit_negative_zero (operands[2]));
9338 }
9339 [(set_attr "length" "8")
9340 (set_attr "type" "vecsimple")])
9341
9342 (define_insn "*ieee_128bit_vsx_abs<mode>2_internal"
9343 [(set (match_operand:IEEE128 0 "register_operand" "=wa")
9344 (abs:IEEE128 (match_operand:IEEE128 1 "register_operand" "wa")))
9345 (use (match_operand:V16QI 2 "register_operand" "v"))]
9346 "TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_HW"
9347 "xxlandc %x0,%x1,%x2"
9348 [(set_attr "type" "veclogical")])
9349
9350 ;; IEEE 128-bit negative absolute value
9351 (define_insn_and_split "*ieee_128bit_vsx_nabs<mode>2"
9352 [(set (match_operand:IEEE128 0 "register_operand" "=wa")
9353 (neg:IEEE128
9354 (abs:IEEE128
9355 (match_operand:IEEE128 1 "register_operand" "wa"))))
9356 (clobber (match_scratch:V16QI 2 "=v"))]
9357 "TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_HW"
9358 "#"
9359 "&& 1"
9360 [(parallel [(set (match_dup 0)
9361 (neg:IEEE128 (abs:IEEE128 (match_dup 1))))
9362 (use (match_dup 2))])]
9363 {
9364 if (GET_CODE (operands[2]) == SCRATCH)
9365 operands[2] = gen_reg_rtx (V16QImode);
9366
9367 emit_insn (gen_ieee_128bit_negative_zero (operands[2]));
9368 }
9369 [(set_attr "length" "8")
9370 (set_attr "type" "vecsimple")])
9371
9372 (define_insn "*ieee_128bit_vsx_nabs<mode>2_internal"
9373 [(set (match_operand:IEEE128 0 "register_operand" "=wa")
9374 (neg:IEEE128
9375 (abs:IEEE128
9376 (match_operand:IEEE128 1 "register_operand" "wa"))))
9377 (use (match_operand:V16QI 2 "register_operand" "v"))]
9378 "TARGET_FLOAT128_TYPE && !TARGET_FLOAT128_HW"
9379 "xxlor %x0,%x1,%x2"
9380 [(set_attr "type" "veclogical")])
9381
9382 ; Float128 conversion functions.
9383 ; If the conversion happens between IBM double double and
9384 ; IEEE 128-bit, it expands to library function calls.
9385 ; Generic code adopts sext_optab for converting IEEE 128-bit
9386 ; to IBM double double while trunc_optab for converting
9387 ; IBM double double to IEEE 128-bit.
9388 (define_expand "extendtfif2"
9389 [(set (match_operand:IF 0 "gpc_reg_operand")
9390 (float_extend:IF (match_operand:TF 1 "gpc_reg_operand")))]
9391 "TARGET_FLOAT128_TYPE"
9392 {
9393 gcc_assert (TARGET_IEEEQUAD);
9394 rs6000_expand_float128_convert (operands[0], operands[1], false);
9395 DONE;
9396 })
9397
9398 (define_expand "extendkftf2"
9399 [(set (match_operand:TF 0 "gpc_reg_operand")
9400 (float_extend:TF (match_operand:KF 1 "gpc_reg_operand")))]
9401 "TARGET_FLOAT128_TYPE"
9402 {
9403 gcc_assert (!TARGET_IEEEQUAD);
9404 rs6000_expand_float128_convert (operands[0], operands[1], false);
9405 DONE;
9406 })
9407
9408 (define_expand "trunciftf2"
9409 [(set (match_operand:TF 0 "gpc_reg_operand")
9410 (float_truncate:TF (match_operand:IF 1 "gpc_reg_operand")))]
9411 "TARGET_FLOAT128_TYPE"
9412 {
9413 gcc_assert (TARGET_IEEEQUAD);
9414 rs6000_expand_float128_convert (operands[0], operands[1], false);
9415 DONE;
9416 })
9417
9418 (define_expand "trunctfkf2"
9419 [(set (match_operand:KF 0 "gpc_reg_operand")
9420 (float_truncate:KF (match_operand:TF 1 "gpc_reg_operand")))]
9421 "TARGET_FLOAT128_TYPE"
9422 {
9423 gcc_assert (!TARGET_IEEEQUAD);
9424 rs6000_expand_float128_convert (operands[0], operands[1], false);
9425 DONE;
9426 })
9427
9428 (define_expand "truncifkf2"
9429 [(set (match_operand:KF 0 "gpc_reg_operand")
9430 (float_truncate:KF (match_operand:IF 1 "gpc_reg_operand")))]
9431 "TARGET_FLOAT128_TYPE"
9432 {
9433 gcc_unreachable ();
9434 })
9435
9436 (define_expand "extendkfif2"
9437 [(set (match_operand:IF 0 "gpc_reg_operand")
9438 (float_extend:IF (match_operand:KF 1 "gpc_reg_operand")))]
9439 "TARGET_FLOAT128_TYPE"
9440 {
9441 gcc_unreachable ();
9442 })
9443
9444 (define_insn_and_split "*extend<mode>tf2_internal"
9445 [(set (match_operand:TF 0 "gpc_reg_operand" "=<IFKF_reg>")
9446 (float_extend:TF
9447 (match_operand:IFKF 1 "gpc_reg_operand" "<IFKF_reg>")))]
9448 "TARGET_FLOAT128_TYPE
9449 && FLOAT128_IBM_P (TFmode) == FLOAT128_IBM_P (<MODE>mode)"
9450 "#"
9451 "&& reload_completed"
9452 [(set (match_dup 0) (match_dup 2))]
9453 {
9454 operands[2] = gen_rtx_REG (TFmode, REGNO (operands[1]));
9455 })
9456
9457 (define_insn_and_split "*extendtf<mode>2_internal"
9458 [(set (match_operand:IFKF 0 "gpc_reg_operand" "=<IFKF_reg>")
9459 (float_extend:IFKF
9460 (match_operand:TF 1 "gpc_reg_operand" "<IFKF_reg>")))]
9461 "TARGET_FLOAT128_TYPE
9462 && FLOAT128_IBM_P (TFmode) == FLOAT128_IBM_P (<MODE>mode)"
9463 "#"
9464 "&& reload_completed"
9465 [(set (match_dup 0) (match_dup 2))]
9466 {
9467 operands[2] = gen_rtx_REG (<MODE>mode, REGNO (operands[1]));
9468 })
9469
9470
9471 ;; Reload helper functions used by rs6000_secondary_reload. The patterns all
9472 ;; must have 3 arguments, and scratch register constraint must be a single
9473 ;; constraint.
9474
9475 ;; Reload patterns to support gpr load/store with misaligned mem.
9476 ;; and multiple gpr load/store at offset >= 0xfffc
9477 (define_expand "reload_<mode>_store"
9478 [(parallel [(match_operand 0 "memory_operand" "=m")
9479 (match_operand 1 "gpc_reg_operand" "r")
9480 (match_operand:GPR 2 "register_operand" "=&b")])]
9481 ""
9482 {
9483 rs6000_secondary_reload_gpr (operands[1], operands[0], operands[2], true);
9484 DONE;
9485 })
9486
9487 (define_expand "reload_<mode>_load"
9488 [(parallel [(match_operand 0 "gpc_reg_operand" "=r")
9489 (match_operand 1 "memory_operand" "m")
9490 (match_operand:GPR 2 "register_operand" "=b")])]
9491 ""
9492 {
9493 rs6000_secondary_reload_gpr (operands[0], operands[1], operands[2], false);
9494 DONE;
9495 })
9496
9497
9498 ;; Reload patterns for various types using the vector registers. We may need
9499 ;; an additional base register to convert the reg+offset addressing to reg+reg
9500 ;; for vector registers and reg+reg or (reg+reg)&(-16) addressing to just an
9501 ;; index register for gpr registers.
9502 (define_expand "reload_<RELOAD:mode>_<P:mptrsize>_store"
9503 [(parallel [(match_operand:RELOAD 0 "memory_operand" "m")
9504 (match_operand:RELOAD 1 "gpc_reg_operand" "wa")
9505 (match_operand:P 2 "register_operand" "=b")])]
9506 "<P:tptrsize>"
9507 {
9508 rs6000_secondary_reload_inner (operands[1], operands[0], operands[2], true);
9509 DONE;
9510 })
9511
9512 (define_expand "reload_<RELOAD:mode>_<P:mptrsize>_load"
9513 [(parallel [(match_operand:RELOAD 0 "gpc_reg_operand" "wa")
9514 (match_operand:RELOAD 1 "memory_operand" "m")
9515 (match_operand:P 2 "register_operand" "=b")])]
9516 "<P:tptrsize>"
9517 {
9518 rs6000_secondary_reload_inner (operands[0], operands[1], operands[2], false);
9519 DONE;
9520 })
9521
9522
9523 ;; Reload sometimes tries to move the address to a GPR, and can generate
9524 ;; invalid RTL for addresses involving AND -16. Allow addresses involving
9525 ;; reg+reg, reg+small constant, or just reg, all wrapped in an AND -16.
9526
9527 (define_insn_and_split "*vec_reload_and_plus_<mptrsize>"
9528 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
9529 (and:P (plus:P (match_operand:P 1 "gpc_reg_operand" "r")
9530 (match_operand:P 2 "reg_or_cint_operand" "rI"))
9531 (const_int -16)))]
9532 "TARGET_ALTIVEC && reload_completed"
9533 "#"
9534 "&& reload_completed"
9535 [(set (match_dup 0)
9536 (plus:P (match_dup 1)
9537 (match_dup 2)))
9538 (set (match_dup 0)
9539 (and:P (match_dup 0)
9540 (const_int -16)))])
9541
9542 ;; Power8 merge instructions to allow direct move to/from floating point
9543 ;; registers in 32-bit mode. We use TF mode to get two registers to move the
9544 ;; individual 32-bit parts across. Subreg doesn't work too well on the TF
9545 ;; value, since it is allocated in reload and not all of the flow information
9546 ;; is setup for it. We have two patterns to do the two moves between gprs and
9547 ;; fprs. There isn't a dependancy between the two, but we could potentially
9548 ;; schedule other instructions between the two instructions.
9549
9550 (define_insn "p8_fmrgow_<mode>"
9551 [(set (match_operand:FMOVE64X 0 "register_operand" "=d")
9552 (unspec:FMOVE64X [
9553 (match_operand:DF 1 "register_operand" "d")
9554 (match_operand:DF 2 "register_operand" "d")]
9555 UNSPEC_P8V_FMRGOW))]
9556 "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9557 "fmrgow %0,%1,%2"
9558 [(set_attr "type" "fpsimple")])
9559
9560 (define_insn "p8_mtvsrwz"
9561 [(set (match_operand:DF 0 "register_operand" "=d")
9562 (unspec:DF [(match_operand:SI 1 "register_operand" "r")]
9563 UNSPEC_P8V_MTVSRWZ))]
9564 "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9565 "mtvsrwz %x0,%1"
9566 [(set_attr "type" "mtvsr")])
9567
9568 (define_insn "p8_mtvsrwz_v16qisi2"
9569 [(set (match_operand:V16QI 0 "register_operand" "=wa")
9570 (unspec:V16QI [(match_operand:SI 1 "register_operand" "r")]
9571 UNSPEC_P8V_MTVSRWZ))]
9572 "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9573 "mtvsrwz %x0,%1"
9574 [(set_attr "type" "mtvsr")])
9575
9576 (define_insn "p8_mtvsrd_v16qidi2"
9577 [(set (match_operand:V16QI 0 "register_operand" "=wa")
9578 (unspec:V16QI [(match_operand:DI 1 "register_operand" "r")]
9579 UNSPEC_P8V_MTVSRD))]
9580 "TARGET_DIRECT_MOVE_64BIT"
9581 "mtvsrd %x0,%1"
9582 [(set_attr "type" "mtvsr")])
9583
9584 (define_insn_and_split "reload_fpr_from_gpr<mode>"
9585 [(set (match_operand:FMOVE64X 0 "register_operand" "=d")
9586 (unspec:FMOVE64X [(match_operand:FMOVE64X 1 "register_operand" "r")]
9587 UNSPEC_P8V_RELOAD_FROM_GPR))
9588 (clobber (match_operand:IF 2 "register_operand" "=d"))]
9589 "!TARGET_POWERPC64 && TARGET_DIRECT_MOVE"
9590 "#"
9591 "&& reload_completed"
9592 [(const_int 0)]
9593 {
9594 rtx dest = operands[0];
9595 rtx src = operands[1];
9596 rtx tmp_hi = simplify_gen_subreg (DFmode, operands[2], IFmode, 0);
9597 rtx tmp_lo = simplify_gen_subreg (DFmode, operands[2], IFmode, 8);
9598 rtx gpr_hi_reg = gen_highpart (SImode, src);
9599 rtx gpr_lo_reg = gen_lowpart (SImode, src);
9600
9601 emit_insn (gen_p8_mtvsrwz (tmp_hi, gpr_hi_reg));
9602 emit_insn (gen_p8_mtvsrwz (tmp_lo, gpr_lo_reg));
9603 emit_insn (gen_p8_fmrgow_<mode> (dest, tmp_hi, tmp_lo));
9604 DONE;
9605 }
9606 [(set_attr "length" "12")
9607 (set_attr "type" "three")])
9608
9609 ;; Move 128 bit values from GPRs to VSX registers in 64-bit mode
9610 (define_insn "p8_mtvsrd_df"
9611 [(set (match_operand:DF 0 "register_operand" "=wa")
9612 (unspec:DF [(match_operand:DI 1 "register_operand" "r")]
9613 UNSPEC_P8V_MTVSRD))]
9614 "TARGET_DIRECT_MOVE_64BIT"
9615 "mtvsrd %x0,%1"
9616 [(set_attr "type" "mtvsr")])
9617
9618 (define_insn "p8_xxpermdi_<mode>"
9619 [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9620 (unspec:FMOVE128_GPR [
9621 (match_operand:DF 1 "register_operand" "wa")
9622 (match_operand:DF 2 "register_operand" "wa")]
9623 UNSPEC_P8V_XXPERMDI))]
9624 "TARGET_DIRECT_MOVE_64BIT"
9625 "xxpermdi %x0,%x1,%x2,0"
9626 [(set_attr "type" "vecperm")])
9627
9628 (define_insn_and_split "reload_vsx_from_gpr<mode>"
9629 [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=wa")
9630 (unspec:FMOVE128_GPR
9631 [(match_operand:FMOVE128_GPR 1 "register_operand" "r")]
9632 UNSPEC_P8V_RELOAD_FROM_GPR))
9633 (clobber (match_operand:IF 2 "register_operand" "=wa"))]
9634 "TARGET_DIRECT_MOVE_64BIT"
9635 "#"
9636 "&& reload_completed"
9637 [(const_int 0)]
9638 {
9639 rtx dest = operands[0];
9640 rtx src = operands[1];
9641 /* You might think that we could use op0 as one temp and a DF clobber
9642 as op2, but you'd be wrong. Secondary reload move patterns don't
9643 check for overlap of the clobber and the destination. */
9644 rtx tmp_hi = simplify_gen_subreg (DFmode, operands[2], IFmode, 0);
9645 rtx tmp_lo = simplify_gen_subreg (DFmode, operands[2], IFmode, 8);
9646 rtx gpr_hi_reg = gen_highpart (DImode, src);
9647 rtx gpr_lo_reg = gen_lowpart (DImode, src);
9648
9649 emit_insn (gen_p8_mtvsrd_df (tmp_hi, gpr_hi_reg));
9650 emit_insn (gen_p8_mtvsrd_df (tmp_lo, gpr_lo_reg));
9651 emit_insn (gen_p8_xxpermdi_<mode> (dest, tmp_hi, tmp_lo));
9652 DONE;
9653 }
9654 [(set_attr "length" "12")
9655 (set_attr "type" "three")])
9656
9657 (define_split
9658 [(set (match_operand:FMOVE128_GPR 0 "nonimmediate_operand")
9659 (match_operand:FMOVE128_GPR 1 "input_operand"))]
9660 "reload_completed
9661 && (int_reg_operand (operands[0], <MODE>mode)
9662 || int_reg_operand (operands[1], <MODE>mode))
9663 && (!TARGET_DIRECT_MOVE_128
9664 || (!vsx_register_operand (operands[0], <MODE>mode)
9665 && !vsx_register_operand (operands[1], <MODE>mode)))"
9666 [(pc)]
9667 {
9668 rs6000_split_multireg_move (operands[0], operands[1]);
9669 DONE;
9670 })
9671
9672 ;; Move SFmode to a VSX from a GPR register. Because scalar floating point
9673 ;; type is stored internally as double precision in the VSX registers, we have
9674 ;; to convert it from the vector format.
9675 (define_insn "p8_mtvsrd_sf"
9676 [(set (match_operand:SF 0 "register_operand" "=wa")
9677 (unspec:SF [(match_operand:DI 1 "register_operand" "r")]
9678 UNSPEC_P8V_MTVSRD))]
9679 "TARGET_DIRECT_MOVE_64BIT"
9680 "mtvsrd %x0,%1"
9681 [(set_attr "type" "mtvsr")])
9682
9683 (define_insn_and_split "reload_vsx_from_gprsf"
9684 [(set (match_operand:SF 0 "register_operand" "=wa")
9685 (unspec:SF [(match_operand:SF 1 "register_operand" "r")]
9686 UNSPEC_P8V_RELOAD_FROM_GPR))
9687 (clobber (match_operand:DI 2 "register_operand" "=r"))]
9688 "TARGET_DIRECT_MOVE_64BIT"
9689 "#"
9690 "&& reload_completed"
9691 [(const_int 0)]
9692 {
9693 rtx op0 = operands[0];
9694 rtx op1 = operands[1];
9695 rtx op2 = operands[2];
9696 rtx op1_di = simplify_gen_subreg (DImode, op1, SFmode, 0);
9697
9698 /* Move SF value to upper 32-bits for xscvspdpn. */
9699 emit_insn (gen_ashldi3 (op2, op1_di, GEN_INT (32)));
9700 emit_insn (gen_p8_mtvsrd_sf (op0, op2));
9701 emit_insn (gen_vsx_xscvspdpn_directmove (op0, op0));
9702 DONE;
9703 }
9704 [(set_attr "length" "8")
9705 (set_attr "type" "two")])
9706
9707 ;; Move 128 bit values from VSX registers to GPRs in 64-bit mode by doing a
9708 ;; normal 64-bit move, followed by an xxpermdi to get the bottom 64-bit value,
9709 ;; and then doing a move of that.
9710 (define_insn "p8_mfvsrd_3_<mode>"
9711 [(set (match_operand:DF 0 "register_operand" "=r")
9712 (unspec:DF [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9713 UNSPEC_P8V_RELOAD_FROM_VSX))]
9714 "TARGET_DIRECT_MOVE_64BIT"
9715 "mfvsrd %0,%x1"
9716 [(set_attr "type" "mfvsr")])
9717
9718 (define_insn_and_split "reload_gpr_from_vsx<mode>"
9719 [(set (match_operand:FMOVE128_GPR 0 "register_operand" "=r")
9720 (unspec:FMOVE128_GPR
9721 [(match_operand:FMOVE128_GPR 1 "register_operand" "wa")]
9722 UNSPEC_P8V_RELOAD_FROM_VSX))
9723 (clobber (match_operand:FMOVE128_GPR 2 "register_operand" "=wa"))]
9724 "TARGET_DIRECT_MOVE_64BIT"
9725 "#"
9726 "&& reload_completed"
9727 [(const_int 0)]
9728 {
9729 rtx dest = operands[0];
9730 rtx src = operands[1];
9731 rtx tmp = operands[2];
9732 rtx gpr_hi_reg = gen_highpart (DFmode, dest);
9733 rtx gpr_lo_reg = gen_lowpart (DFmode, dest);
9734
9735 emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_hi_reg, src));
9736 emit_insn (gen_vsx_xxpermdi_<mode>_be (tmp, src, src, GEN_INT (3)));
9737 emit_insn (gen_p8_mfvsrd_3_<mode> (gpr_lo_reg, tmp));
9738 DONE;
9739 }
9740 [(set_attr "length" "12")
9741 (set_attr "type" "three")])
9742
9743 ;; Move SFmode to a GPR from a VSX register. Because scalar floating point
9744 ;; type is stored internally as double precision, we have to convert it to the
9745 ;; vector format.
9746
9747 (define_insn_and_split "reload_gpr_from_vsxsf"
9748 [(set (match_operand:SF 0 "register_operand" "=r")
9749 (unspec:SF [(match_operand:SF 1 "register_operand" "wa")]
9750 UNSPEC_P8V_RELOAD_FROM_VSX))
9751 (clobber (match_operand:V4SF 2 "register_operand" "=wa"))]
9752 "TARGET_DIRECT_MOVE_64BIT"
9753 "#"
9754 "&& reload_completed"
9755 [(const_int 0)]
9756 {
9757 rtx op0 = operands[0];
9758 rtx op1 = operands[1];
9759 rtx op2 = operands[2];
9760 rtx op0_di = gen_rtx_REG (DImode, reg_or_subregno (op0));
9761 rtx op2_si = gen_rtx_REG (SImode, reg_or_subregno (op2));
9762
9763 emit_insn (gen_vsx_xscvdpspn_scalar (op2, op1));
9764 emit_insn (gen_zero_extendsidi2 (op0_di, op2_si));
9765 DONE;
9766 }
9767 [(set_attr "length" "8")
9768 (set_attr "type" "two")
9769 (set_attr "isa" "p8v")])
9770
9771 ;; Next come the multi-word integer load and store and the load and store
9772 ;; multiple insns.
9773
9774 ;; List r->r after r->Y, otherwise reload will try to reload a
9775 ;; non-offsettable address by using r->r which won't make progress.
9776 ;; Use of fprs is disparaged slightly otherwise reload prefers to reload
9777 ;; a gpr into a fpr instead of reloading an invalid 'Y' address
9778
9779 ;; GPR store GPR load GPR move FPR store FPR load FPR move
9780 ;; GPR const AVX store AVX store AVX load AVX load VSX move
9781 ;; P9 0 P9 -1 AVX 0/-1 VSX 0 VSX -1 P9 const
9782 ;; AVX const
9783
9784 (define_insn "*movdi_internal32"
9785 [(set (match_operand:DI 0 "nonimmediate_operand"
9786 "=Y, r, r, m, ^d, ^d,
9787 r, wY, Z, ^v, $v, ^wa,
9788 wa, wa, v, wa, *i, v,
9789 v")
9790 (match_operand:DI 1 "input_operand"
9791 "r, Y, r, ^d, m, ^d,
9792 IJKnF, ^v, $v, wY, Z, ^wa,
9793 Oj, wM, OjwM, Oj, wM, wS,
9794 wB"))]
9795 "! TARGET_POWERPC64
9796 && (gpc_reg_operand (operands[0], DImode)
9797 || gpc_reg_operand (operands[1], DImode))"
9798 "@
9799 #
9800 #
9801 #
9802 stfd%U0%X0 %1,%0
9803 lfd%U1%X1 %0,%1
9804 fmr %0,%1
9805 #
9806 stxsd %1,%0
9807 stxsdx %x1,%y0
9808 lxsd %0,%1
9809 lxsdx %x0,%y1
9810 xxlor %x0,%x1,%x1
9811 xxspltib %x0,0
9812 xxspltib %x0,255
9813 vspltisw %0,%1
9814 xxlxor %x0,%x0,%x0
9815 xxlorc %x0,%x0,%x0
9816 #
9817 #"
9818 [(set_attr "type"
9819 "store, load, *, fpstore, fpload, fpsimple,
9820 *, fpstore, fpstore, fpload, fpload, veclogical,
9821 vecsimple, vecsimple, vecsimple, veclogical,veclogical,vecsimple,
9822 vecsimple")
9823 (set_attr "size" "64")
9824 (set_attr "length"
9825 "8, 8, 8, *, *, *,
9826 16, *, *, *, *, *,
9827 *, *, *, *, *, 8,
9828 *")
9829 (set_attr "isa"
9830 "*, *, *, *, *, *,
9831 *, p9v, p7v, p9v, p7v, *,
9832 p9v, p9v, p7v, *, *, p7v,
9833 p7v")])
9834
9835 (define_split
9836 [(set (match_operand:DI 0 "gpc_reg_operand")
9837 (match_operand:DI 1 "const_int_operand"))]
9838 "! TARGET_POWERPC64 && reload_completed
9839 && gpr_or_gpr_p (operands[0], operands[1])
9840 && !direct_move_p (operands[0], operands[1])"
9841 [(set (match_dup 2) (match_dup 4))
9842 (set (match_dup 3) (match_dup 1))]
9843 {
9844 HOST_WIDE_INT value = INTVAL (operands[1]);
9845 operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
9846 DImode);
9847 operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
9848 DImode);
9849 operands[4] = GEN_INT (value >> 32);
9850 operands[1] = GEN_INT (sext_hwi (value, 32));
9851 })
9852
9853 (define_split
9854 [(set (match_operand:DIFD 0 "nonimmediate_operand")
9855 (match_operand:DIFD 1 "input_operand"))]
9856 "reload_completed && !TARGET_POWERPC64
9857 && gpr_or_gpr_p (operands[0], operands[1])
9858 && !direct_move_p (operands[0], operands[1])"
9859 [(pc)]
9860 {
9861 rs6000_split_multireg_move (operands[0], operands[1]);
9862 DONE;
9863 })
9864
9865 ;; GPR store GPR load GPR move
9866 ;; GPR li GPR lis GPR pli GPR #
9867 ;; FPR store FPR load FPR move
9868 ;; AVX store AVX store AVX load AVX load VSX move
9869 ;; P9 0 P9 -1 AVX 0/-1 VSX 0 VSX -1
9870 ;; P9 const AVX const
9871 ;; From SPR To SPR SPR<->SPR
9872 ;; VSX->GPR GPR->VSX
9873 (define_insn "*movdi_internal64"
9874 [(set (match_operand:DI 0 "nonimmediate_operand"
9875 "=YZ, r, r,
9876 r, r, r, r,
9877 m, ^d, ^d,
9878 wY, Z, $v, $v, ^wa,
9879 wa, wa, v, wa, wa,
9880 v, v,
9881 r, *h, *h,
9882 ?r, ?wa")
9883 (match_operand:DI 1 "input_operand"
9884 "r, YZ, r,
9885 I, L, eI, nF,
9886 ^d, m, ^d,
9887 ^v, $v, wY, Z, ^wa,
9888 Oj, wM, OjwM, Oj, wM,
9889 wS, wB,
9890 *h, r, 0,
9891 wa, r"))]
9892 "TARGET_POWERPC64
9893 && (gpc_reg_operand (operands[0], DImode)
9894 || gpc_reg_operand (operands[1], DImode))"
9895 "@
9896 std%U0%X0 %1,%0
9897 ld%U1%X1 %0,%1
9898 mr %0,%1
9899 li %0,%1
9900 lis %0,%v1
9901 li %0,%1
9902 #
9903 stfd%U0%X0 %1,%0
9904 lfd%U1%X1 %0,%1
9905 fmr %0,%1
9906 stxsd %1,%0
9907 stxsdx %x1,%y0
9908 lxsd %0,%1
9909 lxsdx %x0,%y1
9910 xxlor %x0,%x1,%x1
9911 xxspltib %x0,0
9912 xxspltib %x0,255
9913 #
9914 xxlxor %x0,%x0,%x0
9915 xxlorc %x0,%x0,%x0
9916 #
9917 #
9918 mf%1 %0
9919 mt%0 %1
9920 nop
9921 mfvsrd %0,%x1
9922 mtvsrd %x0,%1"
9923 [(set_attr "type"
9924 "store, load, *,
9925 *, *, *, *,
9926 fpstore, fpload, fpsimple,
9927 fpstore, fpstore, fpload, fpload, veclogical,
9928 vecsimple, vecsimple, vecsimple, veclogical, veclogical,
9929 vecsimple, vecsimple,
9930 mfjmpr, mtjmpr, *,
9931 mfvsr, mtvsr")
9932 (set_attr "size" "64")
9933 (set_attr "length"
9934 "*, *, *,
9935 *, *, *, 20,
9936 *, *, *,
9937 *, *, *, *, *,
9938 *, *, *, *, *,
9939 8, *,
9940 *, *, *,
9941 *, *")
9942 (set_attr "isa"
9943 "*, *, *,
9944 *, *, p10, *,
9945 *, *, *,
9946 p9v, p7v, p9v, p7v, *,
9947 p9v, p9v, p7v, *, *,
9948 p7v, p7v,
9949 *, *, *,
9950 p8v, p8v")])
9951
9952 ; Some DImode loads are best done as a load of -1 followed by a mask
9953 ; instruction.
9954 (define_split
9955 [(set (match_operand:DI 0 "int_reg_operand")
9956 (match_operand:DI 1 "const_int_operand"))]
9957 "TARGET_POWERPC64
9958 && num_insns_constant (operands[1], DImode) > 1
9959 && !IN_RANGE (INTVAL (operands[1]), -0x80000000, 0xffffffff)
9960 && rs6000_is_valid_and_mask (operands[1], DImode)"
9961 [(set (match_dup 0)
9962 (const_int -1))
9963 (set (match_dup 0)
9964 (and:DI (match_dup 0)
9965 (match_dup 1)))]
9966 "")
9967
9968 ;; Split a load of a large constant into the appropriate five-instruction
9969 ;; sequence. Handle anything in a constant number of insns.
9970 ;; When non-easy constants can go in the TOC, this should use
9971 ;; easy_fp_constant predicate.
9972 (define_split
9973 [(set (match_operand:DI 0 "int_reg_operand")
9974 (match_operand:DI 1 "const_int_operand"))]
9975 "TARGET_POWERPC64 && num_insns_constant (operands[1], DImode) > 1"
9976 [(pc)]
9977 {
9978 if (rs6000_emit_set_const (operands[0], operands[1]))
9979 DONE;
9980 else
9981 FAIL;
9982 })
9983
9984 (define_split
9985 [(set (match_operand:DI 0 "altivec_register_operand")
9986 (match_operand:DI 1 "s5bit_cint_operand"))]
9987 "TARGET_VSX && reload_completed"
9988 [(const_int 0)]
9989 {
9990 rtx op0 = operands[0];
9991 rtx op1 = operands[1];
9992 int r = REGNO (op0);
9993 rtx op0_v4si = gen_rtx_REG (V4SImode, r);
9994
9995 emit_insn (gen_altivec_vspltisw (op0_v4si, op1));
9996 if (op1 != const0_rtx && op1 != constm1_rtx)
9997 {
9998 rtx op0_v2di = gen_rtx_REG (V2DImode, r);
9999 emit_insn (gen_altivec_vupkhsw (op0_v2di, op0_v4si));
10000 }
10001 DONE;
10002 })
10003
10004 ;; Split integer constants that can be loaded with XXSPLTIB and a
10005 ;; sign extend operation.
10006 (define_split
10007 [(set (match_operand:INT_ISA3 0 "altivec_register_operand")
10008 (match_operand:INT_ISA3 1 "xxspltib_constant_split"))]
10009 "TARGET_P9_VECTOR && reload_completed"
10010 [(const_int 0)]
10011 {
10012 rtx op0 = operands[0];
10013 rtx op1 = operands[1];
10014 int r = REGNO (op0);
10015 rtx op0_v16qi = gen_rtx_REG (V16QImode, r);
10016
10017 emit_insn (gen_xxspltib_v16qi (op0_v16qi, op1));
10018 if (<MODE>mode == DImode)
10019 emit_insn (gen_vsx_sign_extend_v16qi_di (operands[0], op0_v16qi));
10020 else if (<MODE>mode == SImode)
10021 emit_insn (gen_vsx_sign_extend_v16qi_si (operands[0], op0_v16qi));
10022 else if (<MODE>mode == HImode)
10023 {
10024 rtx op0_v8hi = gen_rtx_REG (V8HImode, r);
10025 emit_insn (gen_altivec_vupkhsb (op0_v8hi, op0_v16qi));
10026 }
10027 DONE;
10028 })
10029
10030
10031 ;; TImode/PTImode is similar, except that we usually want to compute the
10032 ;; address into a register and use lsi/stsi (the exception is during reload).
10033
10034 (define_insn "*mov<mode>_string"
10035 [(set (match_operand:TI2 0 "reg_or_mem_operand" "=Q,Y,????r,????r,????r,r")
10036 (match_operand:TI2 1 "input_operand" "r,r,Q,Y,r,n"))]
10037 "! TARGET_POWERPC64
10038 && (<MODE>mode != TImode || VECTOR_MEM_NONE_P (TImode))
10039 && (gpc_reg_operand (operands[0], <MODE>mode)
10040 || gpc_reg_operand (operands[1], <MODE>mode))"
10041 "#"
10042 [(set_attr "type" "store,store,load,load,*,*")
10043 (set_attr "update" "yes")
10044 (set_attr "indexed" "yes")
10045 (set_attr "cell_micro" "conditional")])
10046
10047 (define_insn "*mov<mode>_ppc64"
10048 [(set (match_operand:TI2 0 "nonimmediate_operand" "=wQ,Y,r,r,r,r")
10049 (match_operand:TI2 1 "input_operand" "r,r,wQ,Y,r,n"))]
10050 "(TARGET_POWERPC64 && VECTOR_MEM_NONE_P (<MODE>mode)
10051 && (gpc_reg_operand (operands[0], <MODE>mode)
10052 || gpc_reg_operand (operands[1], <MODE>mode)))"
10053 {
10054 return rs6000_output_move_128bit (operands);
10055 }
10056 [(set_attr "type" "store,store,load,load,*,*")
10057 (set_attr "length" "8")
10058 (set_attr "max_prefixed_insns" "2")])
10059
10060 (define_split
10061 [(set (match_operand:TI2 0 "int_reg_operand")
10062 (match_operand:TI2 1 "const_scalar_int_operand"))]
10063 "TARGET_POWERPC64
10064 && (VECTOR_MEM_NONE_P (<MODE>mode)
10065 || (reload_completed && INT_REGNO_P (REGNO (operands[0]))))"
10066 [(set (match_dup 2) (match_dup 4))
10067 (set (match_dup 3) (match_dup 5))]
10068 {
10069 operands[2] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN == 0,
10070 <MODE>mode);
10071 operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0,
10072 <MODE>mode);
10073 if (CONST_WIDE_INT_P (operands[1]))
10074 {
10075 operands[4] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 1));
10076 operands[5] = GEN_INT (CONST_WIDE_INT_ELT (operands[1], 0));
10077 }
10078 else if (CONST_INT_P (operands[1]))
10079 {
10080 operands[4] = GEN_INT (- (INTVAL (operands[1]) < 0));
10081 operands[5] = operands[1];
10082 }
10083 else
10084 FAIL;
10085 })
10086
10087 (define_split
10088 [(set (match_operand:TI2 0 "nonimmediate_operand")
10089 (match_operand:TI2 1 "input_operand"))]
10090 "reload_completed
10091 && gpr_or_gpr_p (operands[0], operands[1])
10092 && !direct_move_p (operands[0], operands[1])
10093 && !quad_load_store_p (operands[0], operands[1])"
10094 [(pc)]
10095 {
10096 rs6000_split_multireg_move (operands[0], operands[1]);
10097 DONE;
10098 })
10099
10100 (define_expand "setmemsi"
10101 [(parallel [(set (match_operand:BLK 0 "")
10102 (match_operand 2 "const_int_operand"))
10103 (use (match_operand:SI 1 ""))
10104 (use (match_operand:SI 3 ""))])]
10105 ""
10106 {
10107 /* If value to set is not zero, use the library routine. */
10108 if (operands[2] != const0_rtx)
10109 FAIL;
10110
10111 if (expand_block_clear (operands))
10112 DONE;
10113 else
10114 FAIL;
10115 })
10116
10117 ;; String compare N insn.
10118 ;; Argument 0 is the target (result)
10119 ;; Argument 1 is the destination
10120 ;; Argument 2 is the source
10121 ;; Argument 3 is the length
10122 ;; Argument 4 is the alignment
10123
10124 (define_expand "cmpstrnsi"
10125 [(parallel [(set (match_operand:SI 0)
10126 (compare:SI (match_operand:BLK 1)
10127 (match_operand:BLK 2)))
10128 (use (match_operand:SI 3))
10129 (use (match_operand:SI 4))])]
10130 "TARGET_CMPB && (BYTES_BIG_ENDIAN || TARGET_LDBRX)"
10131 {
10132 if (optimize_insn_for_size_p ())
10133 FAIL;
10134
10135 if (expand_strn_compare (operands, 0))
10136 DONE;
10137 else
10138 FAIL;
10139 })
10140
10141 ;; String compare insn.
10142 ;; Argument 0 is the target (result)
10143 ;; Argument 1 is the destination
10144 ;; Argument 2 is the source
10145 ;; Argument 3 is the alignment
10146
10147 (define_expand "cmpstrsi"
10148 [(parallel [(set (match_operand:SI 0)
10149 (compare:SI (match_operand:BLK 1)
10150 (match_operand:BLK 2)))
10151 (use (match_operand:SI 3))])]
10152 "TARGET_CMPB && (BYTES_BIG_ENDIAN || TARGET_LDBRX)"
10153 {
10154 if (optimize_insn_for_size_p ())
10155 FAIL;
10156
10157 if (expand_strn_compare (operands, 1))
10158 DONE;
10159 else
10160 FAIL;
10161 })
10162
10163 ;; Block compare insn.
10164 ;; Argument 0 is the target (result)
10165 ;; Argument 1 is the destination
10166 ;; Argument 2 is the source
10167 ;; Argument 3 is the length
10168 ;; Argument 4 is the alignment
10169
10170 (define_expand "cmpmemsi"
10171 [(parallel [(set (match_operand:SI 0)
10172 (compare:SI (match_operand:BLK 1)
10173 (match_operand:BLK 2)))
10174 (use (match_operand:SI 3))
10175 (use (match_operand:SI 4))])]
10176 "TARGET_POPCNTD"
10177 {
10178 if (optimize_insn_for_size_p ())
10179 FAIL;
10180
10181 if (expand_block_compare (operands))
10182 DONE;
10183 else
10184 FAIL;
10185 })
10186
10187 ;; String/block copy insn (source and destination must not overlap).
10188 ;; Argument 0 is the destination
10189 ;; Argument 1 is the source
10190 ;; Argument 2 is the length
10191 ;; Argument 3 is the alignment
10192
10193 (define_expand "cpymemsi"
10194 [(parallel [(set (match_operand:BLK 0 "")
10195 (match_operand:BLK 1 ""))
10196 (use (match_operand:SI 2 ""))
10197 (use (match_operand:SI 3 ""))])]
10198 ""
10199 {
10200 if (expand_block_move (operands, false))
10201 DONE;
10202 else
10203 FAIL;
10204 })
10205
10206 ;; String/block move insn (source and destination may overlap).
10207 ;; Argument 0 is the destination
10208 ;; Argument 1 is the source
10209 ;; Argument 2 is the length
10210 ;; Argument 3 is the alignment
10211
10212 (define_expand "movmemsi"
10213 [(parallel [(set (match_operand:BLK 0 "")
10214 (match_operand:BLK 1 ""))
10215 (use (match_operand:SI 2 ""))
10216 (use (match_operand:SI 3 ""))])]
10217 ""
10218 {
10219 if (expand_block_move (operands, true))
10220 DONE;
10221 else
10222 FAIL;
10223 })
10224
10225
10226 ;; Define insns that do load or store with update. Some of these we can
10227 ;; get by using pre-decrement or pre-increment, but the hardware can also
10228 ;; do cases where the increment is not the size of the object.
10229 ;;
10230 ;; In all these cases, we use operands 0 and 1 for the register being
10231 ;; incremented because those are the operands that local-alloc will
10232 ;; tie and these are the pair most likely to be tieable (and the ones
10233 ;; that will benefit the most).
10234
10235 (define_insn "*movdi_update1"
10236 [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
10237 (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10238 (match_operand:P 2 "reg_or_aligned_short_operand" "r,I"))))
10239 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10240 (plus:P (match_dup 1) (match_dup 2)))]
10241 "TARGET_POWERPC64 && TARGET_UPDATE
10242 && (!avoiding_indexed_address_p (DImode)
10243 || !gpc_reg_operand (operands[2], Pmode))"
10244 "@
10245 ldux %3,%0,%2
10246 ldu %3,%2(%0)"
10247 [(set_attr "type" "load")
10248 (set_attr "update" "yes")
10249 (set_attr "indexed" "yes,no")])
10250
10251 (define_insn "movdi_<mode>_update"
10252 [(set (mem:DI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10253 (match_operand:P 2 "reg_or_aligned_short_operand" "r,I")))
10254 (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10255 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10256 (plus:P (match_dup 1) (match_dup 2)))]
10257 "TARGET_POWERPC64 && TARGET_UPDATE
10258 && (!avoiding_indexed_address_p (DImode)
10259 || !gpc_reg_operand (operands[2], Pmode)
10260 || (REG_P (operands[0])
10261 && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10262 "@
10263 stdux %3,%0,%2
10264 stdu %3,%2(%0)"
10265 [(set_attr "type" "store")
10266 (set_attr "update" "yes")
10267 (set_attr "indexed" "yes,no")])
10268
10269 ;; This pattern is only conditional on TARGET_64BIT, as it is
10270 ;; needed for stack allocation, even if the user passes -mno-update.
10271 (define_insn "movdi_update_stack"
10272 [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
10273 (match_operand:DI 2 "reg_or_aligned_short_operand" "r,I")))
10274 (match_operand:DI 3 "gpc_reg_operand" "r,r"))
10275 (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
10276 (plus:DI (match_dup 1) (match_dup 2)))]
10277 "TARGET_64BIT"
10278 "@
10279 stdux %3,%0,%2
10280 stdu %3,%2(%0)"
10281 [(set_attr "type" "store")
10282 (set_attr "update" "yes")
10283 (set_attr "indexed" "yes,no")])
10284
10285 (define_insn "*movsi_update1"
10286 [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
10287 (mem:SI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10288 (match_operand:P 2 "reg_or_short_operand" "r,I"))))
10289 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10290 (plus:P (match_dup 1) (match_dup 2)))]
10291 "TARGET_UPDATE
10292 && (!avoiding_indexed_address_p (SImode)
10293 || !gpc_reg_operand (operands[2], Pmode))"
10294 "@
10295 lwzux %3,%0,%2
10296 lwzu %3,%2(%0)"
10297 [(set_attr "type" "load")
10298 (set_attr "update" "yes")
10299 (set_attr "indexed" "yes,no")])
10300
10301 (define_insn "*movsi_update2"
10302 [(set (match_operand:EXTSI 3 "gpc_reg_operand" "=r")
10303 (sign_extend:EXTSI
10304 (mem:SI (plus:P (match_operand:P 1 "gpc_reg_operand" "0")
10305 (match_operand:P 2 "gpc_reg_operand" "r")))))
10306 (set (match_operand:P 0 "gpc_reg_operand" "=b")
10307 (plus:P (match_dup 1) (match_dup 2)))]
10308 "TARGET_POWERPC64 && !avoiding_indexed_address_p (DImode)"
10309 "lwaux %3,%0,%2"
10310 [(set_attr "type" "load")
10311 (set_attr "sign_extend" "yes")
10312 (set_attr "update" "yes")
10313 (set_attr "indexed" "yes")])
10314
10315 (define_insn "movsi_<mode>_update"
10316 [(set (mem:SI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10317 (match_operand:P 2 "reg_or_short_operand" "r,I")))
10318 (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10319 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10320 (plus:P (match_dup 1) (match_dup 2)))]
10321 "TARGET_UPDATE
10322 && (!avoiding_indexed_address_p (SImode)
10323 || !gpc_reg_operand (operands[2], Pmode)
10324 || (REG_P (operands[0])
10325 && REGNO (operands[0]) == STACK_POINTER_REGNUM))"
10326 "@
10327 stwux %3,%0,%2
10328 stwu %3,%2(%0)"
10329 [(set_attr "type" "store")
10330 (set_attr "update" "yes")
10331 (set_attr "indexed" "yes,no")])
10332
10333 ;; This is an unconditional pattern; needed for stack allocation, even
10334 ;; if the user passes -mno-update.
10335 (define_insn "movsi_update_stack"
10336 [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
10337 (match_operand:SI 2 "reg_or_short_operand" "r,I")))
10338 (match_operand:SI 3 "gpc_reg_operand" "r,r"))
10339 (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
10340 (plus:SI (match_dup 1) (match_dup 2)))]
10341 "TARGET_32BIT"
10342 "@
10343 stwux %3,%0,%2
10344 stwu %3,%2(%0)"
10345 [(set_attr "type" "store")
10346 (set_attr "update" "yes")
10347 (set_attr "indexed" "yes,no")])
10348
10349 (define_insn "*movhi_update1"
10350 [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
10351 (mem:HI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10352 (match_operand:P 2 "reg_or_short_operand" "r,I"))))
10353 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10354 (plus:P (match_dup 1) (match_dup 2)))]
10355 "TARGET_UPDATE
10356 && (!avoiding_indexed_address_p (HImode)
10357 || !gpc_reg_operand (operands[2], SImode))"
10358 "@
10359 lhzux %3,%0,%2
10360 lhzu %3,%2(%0)"
10361 [(set_attr "type" "load")
10362 (set_attr "update" "yes")
10363 (set_attr "indexed" "yes,no")])
10364
10365 (define_insn "*movhi_update2"
10366 [(set (match_operand:EXTHI 3 "gpc_reg_operand" "=r,r")
10367 (zero_extend:EXTHI
10368 (mem:HI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10369 (match_operand:P 2 "reg_or_short_operand" "r,I")))))
10370 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10371 (plus:P (match_dup 1) (match_dup 2)))]
10372 "TARGET_UPDATE
10373 && (!avoiding_indexed_address_p (HImode)
10374 || !gpc_reg_operand (operands[2], Pmode))"
10375 "@
10376 lhzux %3,%0,%2
10377 lhzu %3,%2(%0)"
10378 [(set_attr "type" "load")
10379 (set_attr "update" "yes")
10380 (set_attr "indexed" "yes,no")])
10381
10382 (define_insn "*movhi_update3"
10383 [(set (match_operand:EXTHI 3 "gpc_reg_operand" "=r,r")
10384 (sign_extend:EXTHI
10385 (mem:HI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10386 (match_operand:P 2 "reg_or_short_operand" "r,I")))))
10387 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10388 (plus:P (match_dup 1) (match_dup 2)))]
10389 "TARGET_UPDATE
10390 && !(avoiding_indexed_address_p (HImode)
10391 && gpc_reg_operand (operands[2], Pmode))"
10392 "@
10393 lhaux %3,%0,%2
10394 lhau %3,%2(%0)"
10395 [(set_attr "type" "load")
10396 (set_attr "sign_extend" "yes")
10397 (set_attr "update" "yes")
10398 (set_attr "indexed" "yes,no")])
10399
10400 (define_insn "*movhi_update4"
10401 [(set (mem:HI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10402 (match_operand:P 2 "reg_or_short_operand" "r,I")))
10403 (match_operand:HI 3 "gpc_reg_operand" "r,r"))
10404 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10405 (plus:P (match_dup 1) (match_dup 2)))]
10406 "TARGET_UPDATE
10407 && (!avoiding_indexed_address_p (HImode)
10408 || !gpc_reg_operand (operands[2], Pmode))"
10409 "@
10410 sthux %3,%0,%2
10411 sthu %3,%2(%0)"
10412 [(set_attr "type" "store")
10413 (set_attr "update" "yes")
10414 (set_attr "indexed" "yes,no")])
10415
10416 (define_insn "*movqi_update1"
10417 [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
10418 (mem:QI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10419 (match_operand:P 2 "reg_or_short_operand" "r,I"))))
10420 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10421 (plus:P (match_dup 1) (match_dup 2)))]
10422 "TARGET_UPDATE
10423 && (!avoiding_indexed_address_p (QImode)
10424 || !gpc_reg_operand (operands[2], Pmode))"
10425 "@
10426 lbzux %3,%0,%2
10427 lbzu %3,%2(%0)"
10428 [(set_attr "type" "load")
10429 (set_attr "update" "yes")
10430 (set_attr "indexed" "yes,no")])
10431
10432 (define_insn "*movqi_update2"
10433 [(set (match_operand:EXTQI 3 "gpc_reg_operand" "=r,r")
10434 (zero_extend:EXTQI
10435 (mem:QI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10436 (match_operand:P 2 "reg_or_short_operand" "r,I")))))
10437 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10438 (plus:P (match_dup 1) (match_dup 2)))]
10439 "TARGET_UPDATE
10440 && (!avoiding_indexed_address_p (QImode)
10441 || !gpc_reg_operand (operands[2], Pmode))"
10442 "@
10443 lbzux %3,%0,%2
10444 lbzu %3,%2(%0)"
10445 [(set_attr "type" "load")
10446 (set_attr "update" "yes")
10447 (set_attr "indexed" "yes,no")])
10448
10449 (define_insn "*movqi_update3"
10450 [(set (mem:QI (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10451 (match_operand:P 2 "reg_or_short_operand" "r,I")))
10452 (match_operand:QI 3 "gpc_reg_operand" "r,r"))
10453 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10454 (plus:P (match_dup 1) (match_dup 2)))]
10455 "TARGET_UPDATE
10456 && (!avoiding_indexed_address_p (QImode)
10457 || !gpc_reg_operand (operands[2], Pmode))"
10458 "@
10459 stbux %3,%0,%2
10460 stbu %3,%2(%0)"
10461 [(set_attr "type" "store")
10462 (set_attr "update" "yes")
10463 (set_attr "indexed" "yes,no")])
10464
10465 (define_insn "*mov<SFDF:mode>_update1"
10466 [(set (match_operand:SFDF 3 "gpc_reg_operand" "=d,d")
10467 (mem:SFDF (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10468 (match_operand:P 2 "reg_or_short_operand" "r,I"))))
10469 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10470 (plus:P (match_dup 1) (match_dup 2)))]
10471 "TARGET_HARD_FLOAT && TARGET_UPDATE
10472 && (!avoiding_indexed_address_p (<SFDF:MODE>mode)
10473 || !gpc_reg_operand (operands[2], Pmode))"
10474 "@
10475 lf<sd>ux %3,%0,%2
10476 lf<sd>u %3,%2(%0)"
10477 [(set_attr "type" "fpload")
10478 (set_attr "update" "yes")
10479 (set_attr "indexed" "yes,no")
10480 (set_attr "size" "<SFDF:bits>")])
10481
10482 (define_insn "*mov<SFDF:mode>_update2"
10483 [(set (mem:SFDF (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10484 (match_operand:P 2 "reg_or_short_operand" "r,I")))
10485 (match_operand:SFDF 3 "gpc_reg_operand" "d,d"))
10486 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10487 (plus:P (match_dup 1) (match_dup 2)))]
10488 "TARGET_HARD_FLOAT && TARGET_UPDATE
10489 && (!avoiding_indexed_address_p (<SFDF:MODE>mode)
10490 || !gpc_reg_operand (operands[2], Pmode))"
10491 "@
10492 stf<sd>ux %3,%0,%2
10493 stf<sd>u %3,%2(%0)"
10494 [(set_attr "type" "fpstore")
10495 (set_attr "update" "yes")
10496 (set_attr "indexed" "yes,no")
10497 (set_attr "size" "<SFDF:bits>")])
10498
10499 (define_insn "*movsf_update3"
10500 [(set (match_operand:SF 3 "gpc_reg_operand" "=r,r")
10501 (mem:SF (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10502 (match_operand:P 2 "reg_or_short_operand" "r,I"))))
10503 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10504 (plus:P (match_dup 1) (match_dup 2)))]
10505 "TARGET_SOFT_FLOAT && TARGET_UPDATE
10506 && (!avoiding_indexed_address_p (SFmode)
10507 || !gpc_reg_operand (operands[2], Pmode))"
10508 "@
10509 lwzux %3,%0,%2
10510 lwzu %3,%2(%0)"
10511 [(set_attr "type" "load")
10512 (set_attr "update" "yes")
10513 (set_attr "indexed" "yes,no")])
10514
10515 (define_insn "*movsf_update4"
10516 [(set (mem:SF (plus:P (match_operand:P 1 "gpc_reg_operand" "0,0")
10517 (match_operand:P 2 "reg_or_short_operand" "r,I")))
10518 (match_operand:SF 3 "gpc_reg_operand" "r,r"))
10519 (set (match_operand:P 0 "gpc_reg_operand" "=b,b")
10520 (plus:P (match_dup 1) (match_dup 2)))]
10521 "TARGET_SOFT_FLOAT && TARGET_UPDATE
10522 && (!avoiding_indexed_address_p (SFmode)
10523 || !gpc_reg_operand (operands[2], Pmode))"
10524 "@
10525 stwux %3,%0,%2
10526 stwu %3,%2(%0)"
10527 [(set_attr "type" "store")
10528 (set_attr "update" "yes")
10529 (set_attr "indexed" "yes,no")])
10530
10531
10532 ;; After inserting conditional returns we can sometimes have
10533 ;; unnecessary register moves. Unfortunately we cannot have a
10534 ;; modeless peephole here, because some single SImode sets have early
10535 ;; clobber outputs. Although those sets expand to multi-ppc-insn
10536 ;; sequences, using get_attr_length here will smash the operands
10537 ;; array. Neither is there an early_cobbler_p predicate.
10538 ;; Also this optimization interferes with scalars going into
10539 ;; altivec registers (the code does reloading through the FPRs).
10540 (define_peephole2
10541 [(set (match_operand:DF 0 "gpc_reg_operand")
10542 (match_operand:DF 1 "any_operand"))
10543 (set (match_operand:DF 2 "gpc_reg_operand")
10544 (match_dup 0))]
10545 "!TARGET_VSX
10546 && peep2_reg_dead_p (2, operands[0])"
10547 [(set (match_dup 2) (match_dup 1))])
10548
10549 (define_peephole2
10550 [(set (match_operand:SF 0 "gpc_reg_operand")
10551 (match_operand:SF 1 "any_operand"))
10552 (set (match_operand:SF 2 "gpc_reg_operand")
10553 (match_dup 0))]
10554 "!TARGET_P8_VECTOR
10555 && peep2_reg_dead_p (2, operands[0])"
10556 [(set (match_dup 2) (match_dup 1))])
10557
10558
10559 ;; TLS support.
10560
10561 (define_insn "*tls_gd_pcrel<bits>"
10562 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10563 (unspec:P [(match_operand:P 1 "rs6000_tls_symbol_ref" "")
10564 (const_int 0)]
10565 UNSPEC_TLSGD))]
10566 "HAVE_AS_TLS && TARGET_ELF"
10567 "la %0,%1@got@tlsgd@pcrel"
10568 [(set_attr "prefixed" "yes")])
10569
10570 (define_insn_and_split "*tls_gd<bits>"
10571 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10572 (unspec:P [(match_operand:P 1 "rs6000_tls_symbol_ref" "")
10573 (match_operand:P 2 "gpc_reg_operand" "b")]
10574 UNSPEC_TLSGD))]
10575 "HAVE_AS_TLS && TARGET_ELF"
10576 "addi %0,%2,%1@got@tlsgd"
10577 "&& TARGET_CMODEL != CMODEL_SMALL"
10578 [(set (match_dup 3)
10579 (high:P
10580 (unspec:P [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))
10581 (set (match_dup 0)
10582 (lo_sum:P (match_dup 3)
10583 (unspec:P [(match_dup 1) (match_dup 2)] UNSPEC_TLSGD)))]
10584 {
10585 operands[3] = gen_reg_rtx (<MODE>mode);
10586 }
10587 [(set (attr "length")
10588 (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10589 (const_int 8)
10590 (const_int 4)))])
10591
10592 (define_insn "*tls_gd_high<bits>"
10593 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10594 (high:P
10595 (unspec:P [(match_operand:P 1 "rs6000_tls_symbol_ref" "")
10596 (match_operand:P 2 "gpc_reg_operand" "b")]
10597 UNSPEC_TLSGD)))]
10598 "HAVE_AS_TLS && TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10599 "addis %0,%2,%1@got@tlsgd@ha")
10600
10601 (define_insn "*tls_gd_low<bits>"
10602 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10603 (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
10604 (unspec:P [(match_operand:P 2 "rs6000_tls_symbol_ref" "")
10605 (match_operand:P 3 "gpc_reg_operand" "b")]
10606 UNSPEC_TLSGD)))]
10607 "HAVE_AS_TLS && TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10608 "addi %0,%1,%2@got@tlsgd@l")
10609
10610 (define_insn "*tls_ld_pcrel<bits>"
10611 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10612 (unspec:P [(const_int 0)]
10613 UNSPEC_TLSLD))]
10614 "HAVE_AS_TLS && TARGET_ELF"
10615 "la %0,%&@got@tlsld@pcrel"
10616 [(set_attr "prefixed" "yes")])
10617
10618 (define_insn_and_split "*tls_ld<bits>"
10619 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10620 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")]
10621 UNSPEC_TLSLD))]
10622 "HAVE_AS_TLS && TARGET_ELF"
10623 "addi %0,%1,%&@got@tlsld"
10624 "&& TARGET_CMODEL != CMODEL_SMALL"
10625 [(set (match_dup 2)
10626 (high:P
10627 (unspec:P [(match_dup 1)] UNSPEC_TLSLD)))
10628 (set (match_dup 0)
10629 (lo_sum:P (match_dup 2)
10630 (unspec:P [(match_dup 1)] UNSPEC_TLSLD)))]
10631 {
10632 operands[2] = gen_reg_rtx (<MODE>mode);
10633 }
10634 [(set (attr "length")
10635 (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10636 (const_int 8)
10637 (const_int 4)))])
10638
10639 (define_insn "*tls_ld_high<bits>"
10640 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10641 (high:P
10642 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")]
10643 UNSPEC_TLSLD)))]
10644 "HAVE_AS_TLS && TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10645 "addis %0,%1,%&@got@tlsld@ha")
10646
10647 (define_insn "*tls_ld_low<bits>"
10648 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10649 (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
10650 (unspec:P [(match_operand:P 2 "gpc_reg_operand" "b")]
10651 UNSPEC_TLSLD)))]
10652 "HAVE_AS_TLS && TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
10653 "addi %0,%1,%&@got@tlsld@l")
10654
10655 (define_insn "tls_dtprel_<bits>"
10656 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10657 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10658 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10659 UNSPEC_TLSDTPREL))]
10660 "HAVE_AS_TLS"
10661 "addi %0,%1,%2@dtprel"
10662 [(set (attr "prefixed")
10663 (if_then_else (match_test "rs6000_tls_size == 16")
10664 (const_string "no")
10665 (const_string "yes")))])
10666
10667 (define_insn "tls_dtprel_ha_<bits>"
10668 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10669 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10670 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10671 UNSPEC_TLSDTPRELHA))]
10672 "HAVE_AS_TLS"
10673 "addis %0,%1,%2@dtprel@ha")
10674
10675 (define_insn "tls_dtprel_lo_<bits>"
10676 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10677 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10678 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10679 UNSPEC_TLSDTPRELLO))]
10680 "HAVE_AS_TLS"
10681 "addi %0,%1,%2@dtprel@l")
10682
10683 (define_insn_and_split "tls_got_dtprel_<bits>"
10684 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10685 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10686 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10687 UNSPEC_TLSGOTDTPREL))]
10688 "HAVE_AS_TLS"
10689 "<ptrload> %0,%2@got@dtprel(%1)"
10690 "&& TARGET_CMODEL != CMODEL_SMALL"
10691 [(set (match_dup 3)
10692 (high:P
10693 (unspec:P [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))
10694 (set (match_dup 0)
10695 (lo_sum:P (match_dup 3)
10696 (unspec:P [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTDTPREL)))]
10697 {
10698 operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
10699 }
10700 [(set (attr "length")
10701 (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10702 (const_int 8)
10703 (const_int 4)))])
10704
10705 (define_insn "*tls_got_dtprel_high<bits>"
10706 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10707 (high:P
10708 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10709 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10710 UNSPEC_TLSGOTDTPREL)))]
10711 "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10712 "addis %0,%1,%2@got@dtprel@ha")
10713
10714 (define_insn "*tls_got_dtprel_low<bits>"
10715 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10716 (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
10717 (unspec:P [(match_operand:P 3 "gpc_reg_operand" "b")
10718 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10719 UNSPEC_TLSGOTDTPREL)))]
10720 "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10721 "<ptrload> %0,%2@got@dtprel@l(%1)")
10722
10723 (define_insn "tls_tprel_<bits>"
10724 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10725 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10726 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10727 UNSPEC_TLSTPREL))]
10728 "HAVE_AS_TLS"
10729 "addi %0,%1,%2@tprel"
10730 [(set (attr "prefixed")
10731 (if_then_else (match_test "rs6000_tls_size == 16")
10732 (const_string "no")
10733 (const_string "yes")))])
10734
10735 (define_insn "tls_tprel_ha_<bits>"
10736 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10737 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10738 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10739 UNSPEC_TLSTPRELHA))]
10740 "HAVE_AS_TLS"
10741 "addis %0,%1,%2@tprel@ha")
10742
10743 (define_insn "tls_tprel_lo_<bits>"
10744 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10745 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10746 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10747 UNSPEC_TLSTPRELLO))]
10748 "HAVE_AS_TLS"
10749 "addi %0,%1,%2@tprel@l")
10750
10751 (define_insn "*tls_got_tprel_pcrel_<bits>"
10752 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10753 (unspec:P [(const_int 0)
10754 (match_operand:P 1 "rs6000_tls_symbol_ref" "")]
10755 UNSPEC_TLSGOTTPREL))]
10756 "HAVE_AS_TLS"
10757 "<ptrload> %0,%1@got@tprel@pcrel"
10758 [(set_attr "prefixed" "yes")])
10759
10760 ;; "b" output constraint here and on tls_tls input to support linker tls
10761 ;; optimization. The linker may edit the instructions emitted by a
10762 ;; tls_got_tprel/tls_tls pair to addis,addi.
10763 (define_insn_and_split "tls_got_tprel_<bits>"
10764 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10765 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10766 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10767 UNSPEC_TLSGOTTPREL))]
10768 "HAVE_AS_TLS"
10769 "<ptrload> %0,%2@got@tprel(%1)"
10770 "&& TARGET_CMODEL != CMODEL_SMALL"
10771 [(set (match_dup 3)
10772 (high:P
10773 (unspec:P [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))
10774 (set (match_dup 0)
10775 (lo_sum:P (match_dup 3)
10776 (unspec:P [(match_dup 1) (match_dup 2)] UNSPEC_TLSGOTTPREL)))]
10777 {
10778 operands[3] = gen_reg_rtx (TARGET_64BIT ? DImode : SImode);
10779 }
10780 [(set (attr "length")
10781 (if_then_else (ne (symbol_ref "TARGET_CMODEL") (symbol_ref "CMODEL_SMALL"))
10782 (const_int 8)
10783 (const_int 4)))])
10784
10785 (define_insn "*tls_got_tprel_high<bits>"
10786 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
10787 (high:P
10788 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10789 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10790 UNSPEC_TLSGOTTPREL)))]
10791 "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10792 "addis %0,%1,%2@got@tprel@ha")
10793
10794 (define_insn "*tls_got_tprel_low<bits>"
10795 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10796 (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
10797 (unspec:P [(match_operand:P 3 "gpc_reg_operand" "b")
10798 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10799 UNSPEC_TLSGOTTPREL)))]
10800 "HAVE_AS_TLS && TARGET_CMODEL != CMODEL_SMALL"
10801 "<ptrload> %0,%2@got@tprel@l(%1)")
10802
10803 (define_insn "tls_tls_pcrel_<bits>"
10804 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10805 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10806 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10807 UNSPEC_TLSTLS_PCREL))]
10808 "TARGET_ELF && HAVE_AS_TLS"
10809 "add %0,%1,%2@tls@pcrel")
10810
10811 (define_insn "tls_tls_<bits>"
10812 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
10813 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
10814 (match_operand:P 2 "rs6000_tls_symbol_ref" "")]
10815 UNSPEC_TLSTLS))]
10816 "TARGET_ELF && HAVE_AS_TLS"
10817 "add %0,%1,%2@tls")
10818
10819 (define_expand "tls_get_tpointer"
10820 [(set (match_operand:SI 0 "gpc_reg_operand")
10821 (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))]
10822 "TARGET_XCOFF && HAVE_AS_TLS"
10823 {
10824 emit_insn (gen_tls_get_tpointer_internal ());
10825 emit_move_insn (operands[0], gen_rtx_REG (SImode, 3));
10826 DONE;
10827 })
10828
10829 (define_insn "tls_get_tpointer_internal"
10830 [(set (reg:SI 3)
10831 (unspec:SI [(const_int 0)] UNSPEC_TLSTLS))
10832 (clobber (reg:SI LR_REGNO))]
10833 "TARGET_XCOFF && HAVE_AS_TLS"
10834 "bla .__get_tpointer")
10835
10836 (define_expand "tls_get_addr<mode>"
10837 [(set (match_operand:P 0 "gpc_reg_operand")
10838 (unspec:P [(match_operand:P 1 "gpc_reg_operand")
10839 (match_operand:P 2 "gpc_reg_operand")] UNSPEC_TLSTLS))]
10840 "TARGET_XCOFF && HAVE_AS_TLS"
10841 {
10842 emit_move_insn (gen_rtx_REG (Pmode, 3), operands[1]);
10843 emit_move_insn (gen_rtx_REG (Pmode, 4), operands[2]);
10844 emit_insn (gen_tls_get_addr_internal<mode> ());
10845 emit_move_insn (operands[0], gen_rtx_REG (Pmode, 3));
10846 DONE;
10847 })
10848
10849 (define_insn "tls_get_addr_internal<mode>"
10850 [(set (reg:P 3)
10851 (unspec:P [(reg:P 3) (reg:P 4)] UNSPEC_TLSTLS))
10852 (clobber (reg:P 0))
10853 (clobber (reg:P 4))
10854 (clobber (reg:P 5))
10855 (clobber (reg:P 11))
10856 (clobber (reg:CC CR0_REGNO))
10857 (clobber (reg:P LR_REGNO))]
10858 "TARGET_XCOFF && HAVE_AS_TLS"
10859 "bla .__tls_get_addr")
10860
10861 ;; Next come insns related to the calling sequence.
10862 ;;
10863 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
10864 ;; We move the back-chain and decrement the stack pointer.
10865 ;;
10866 ;; Operand1 is more naturally reg_or_short_operand. However, for a large
10867 ;; constant alloca, using that predicate will force the generic code to put
10868 ;; the constant size into a register before calling the expander.
10869 ;;
10870 ;; As a result the expander would not have the constant size information
10871 ;; in those cases and would have to generate less efficient code.
10872 ;;
10873 ;; Thus we allow reg_or_cint_operand instead so that the expander can see
10874 ;; the constant size. The value is forced into a register if necessary.
10875 ;;
10876 (define_expand "allocate_stack"
10877 [(set (match_operand 0 "gpc_reg_operand")
10878 (minus (reg 1) (match_operand 1 "reg_or_cint_operand")))
10879 (set (reg 1)
10880 (minus (reg 1) (match_dup 1)))]
10881 ""
10882 {
10883 rtx chain = gen_reg_rtx (Pmode);
10884 rtx stack_bot = gen_rtx_MEM (Pmode, stack_pointer_rtx);
10885 rtx neg_op0;
10886 rtx insn, par, set, mem;
10887
10888 /* By allowing reg_or_cint_operand as the predicate we can get
10889 better code for stack-clash-protection because we do not lose
10890 size information. But the rest of the code expects the operand
10891 to be reg_or_short_operand. If it isn't, then force it into
10892 a register. */
10893 rtx orig_op1 = operands[1];
10894 if (!reg_or_short_operand (operands[1], Pmode))
10895 operands[1] = force_reg (Pmode, operands[1]);
10896
10897 emit_move_insn (chain, stack_bot);
10898
10899 /* Check stack bounds if necessary. */
10900 if (crtl->limit_stack)
10901 {
10902 rtx available;
10903 available = expand_binop (Pmode, sub_optab,
10904 stack_pointer_rtx, stack_limit_rtx,
10905 NULL_RTX, 1, OPTAB_WIDEN);
10906 emit_insn (gen_cond_trap (LTU, available, operands[1], const0_rtx));
10907 }
10908
10909 /* Allocate and probe if requested.
10910 This may look similar to the loop we use for prologue allocations,
10911 but it is critically different. For the former we know the loop
10912 will iterate, but do not know that generally here. The former
10913 uses that knowledge to rotate the loop. Combining them would be
10914 possible with some performance cost. */
10915 if (flag_stack_clash_protection)
10916 {
10917 rtx rounded_size, last_addr, residual;
10918 HOST_WIDE_INT probe_interval;
10919 compute_stack_clash_protection_loop_data (&rounded_size, &last_addr,
10920 &residual, &probe_interval,
10921 orig_op1);
10922
10923 /* We do occasionally get in here with constant sizes, we might
10924 as well do a reasonable job when we obviously can. */
10925 if (rounded_size != const0_rtx)
10926 {
10927 rtx loop_lab, end_loop;
10928 bool rotated = CONST_INT_P (rounded_size);
10929 rtx update = GEN_INT (-probe_interval);
10930 if (probe_interval > 32768)
10931 update = force_reg (Pmode, update);
10932
10933 emit_stack_clash_protection_probe_loop_start (&loop_lab, &end_loop,
10934 last_addr, rotated);
10935
10936 if (TARGET_32BIT)
10937 emit_insn (gen_movsi_update_stack (stack_pointer_rtx,
10938 stack_pointer_rtx,
10939 update, chain));
10940 else
10941 emit_insn (gen_movdi_update_stack (stack_pointer_rtx,
10942 stack_pointer_rtx,
10943 update, chain));
10944 emit_stack_clash_protection_probe_loop_end (loop_lab, end_loop,
10945 last_addr, rotated);
10946 }
10947
10948 /* Now handle residuals. We just have to set operands[1] correctly
10949 and let the rest of the expander run. */
10950 operands[1] = residual;
10951 }
10952
10953 if (!(CONST_INT_P (operands[1])
10954 && IN_RANGE (INTVAL (operands[1]), -32767, 32768)))
10955 {
10956 operands[1] = force_reg (Pmode, operands[1]);
10957 neg_op0 = gen_reg_rtx (Pmode);
10958 emit_insn (gen_neg2 (Pmode, neg_op0, operands[1]));
10959 }
10960 else
10961 neg_op0 = GEN_INT (-INTVAL (operands[1]));
10962
10963 insn = emit_insn ((* ((TARGET_32BIT) ? gen_movsi_update_stack
10964 : gen_movdi_update_stack))
10965 (stack_pointer_rtx, stack_pointer_rtx, neg_op0,
10966 chain));
10967 /* Since we didn't use gen_frame_mem to generate the MEM, grab
10968 it now and set the alias set/attributes. The above gen_*_update
10969 calls will generate a PARALLEL with the MEM set being the first
10970 operation. */
10971 par = PATTERN (insn);
10972 gcc_assert (GET_CODE (par) == PARALLEL);
10973 set = XVECEXP (par, 0, 0);
10974 gcc_assert (GET_CODE (set) == SET);
10975 mem = SET_DEST (set);
10976 gcc_assert (MEM_P (mem));
10977 MEM_NOTRAP_P (mem) = 1;
10978 set_mem_alias_set (mem, get_frame_alias_set ());
10979
10980 emit_move_insn (operands[0], virtual_stack_dynamic_rtx);
10981 DONE;
10982 })
10983
10984 ;; These patterns say how to save and restore the stack pointer. We need not
10985 ;; save the stack pointer at function level since we are careful to
10986 ;; preserve the backchain. At block level, we have to restore the backchain
10987 ;; when we restore the stack pointer.
10988 ;;
10989 ;; For nonlocal gotos, we must save both the stack pointer and its
10990 ;; backchain and restore both. Note that in the nonlocal case, the
10991 ;; save area is a memory location.
10992
10993 (define_expand "save_stack_function"
10994 [(match_operand 0 "any_operand")
10995 (match_operand 1 "any_operand")]
10996 ""
10997 "DONE;")
10998
10999 (define_expand "restore_stack_function"
11000 [(match_operand 0 "any_operand")
11001 (match_operand 1 "any_operand")]
11002 ""
11003 "DONE;")
11004
11005 ;; Adjust stack pointer (op0) to a new value (op1).
11006 ;; First copy old stack backchain to new location, and ensure that the
11007 ;; scheduler won't reorder the sp assignment before the backchain write.
11008 (define_expand "restore_stack_block"
11009 [(set (match_dup 2) (match_dup 3))
11010 (set (match_dup 4) (match_dup 2))
11011 (match_dup 5)
11012 (set (match_operand 0 "register_operand")
11013 (match_operand 1 "register_operand"))]
11014 ""
11015 {
11016 rtvec p;
11017
11018 operands[1] = force_reg (Pmode, operands[1]);
11019 operands[2] = gen_reg_rtx (Pmode);
11020 operands[3] = gen_frame_mem (Pmode, operands[0]);
11021 operands[4] = gen_frame_mem (Pmode, operands[1]);
11022 p = rtvec_alloc (1);
11023 RTVEC_ELT (p, 0) = gen_rtx_SET (gen_frame_mem (BLKmode, operands[0]),
11024 const0_rtx);
11025 operands[5] = gen_rtx_PARALLEL (VOIDmode, p);
11026 })
11027
11028 (define_expand "save_stack_nonlocal"
11029 [(set (match_dup 3) (match_dup 4))
11030 (set (match_operand 0 "memory_operand") (match_dup 3))
11031 (set (match_dup 2) (match_operand 1 "register_operand"))]
11032 ""
11033 {
11034 int units_per_word = (TARGET_32BIT) ? 4 : 8;
11035
11036 /* Copy the backchain to the first word, sp to the second. */
11037 operands[0] = adjust_address_nv (operands[0], Pmode, 0);
11038 operands[2] = adjust_address_nv (operands[0], Pmode, units_per_word);
11039 operands[3] = gen_reg_rtx (Pmode);
11040 operands[4] = gen_frame_mem (Pmode, operands[1]);
11041 })
11042
11043 (define_expand "restore_stack_nonlocal"
11044 [(set (match_dup 2) (match_operand 1 "memory_operand"))
11045 (set (match_dup 3) (match_dup 4))
11046 (set (match_dup 5) (match_dup 2))
11047 (match_dup 6)
11048 (set (match_operand 0 "register_operand") (match_dup 3))]
11049 ""
11050 {
11051 int units_per_word = (TARGET_32BIT) ? 4 : 8;
11052 rtvec p;
11053
11054 /* Restore the backchain from the first word, sp from the second. */
11055 operands[2] = gen_reg_rtx (Pmode);
11056 operands[3] = gen_reg_rtx (Pmode);
11057 operands[1] = adjust_address_nv (operands[1], Pmode, 0);
11058 operands[4] = adjust_address_nv (operands[1], Pmode, units_per_word);
11059 operands[5] = gen_frame_mem (Pmode, operands[3]);
11060 p = rtvec_alloc (1);
11061 RTVEC_ELT (p, 0) = gen_rtx_SET (gen_frame_mem (BLKmode, operands[0]),
11062 const0_rtx);
11063 operands[6] = gen_rtx_PARALLEL (VOIDmode, p);
11064 })
11065
11066 ;; Load up a PC-relative address. Print_operand_address will append a @pcrel
11067 ;; to the symbol or label.
11068 (define_insn "*pcrel_local_addr"
11069 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11070 (match_operand:DI 1 "pcrel_local_address"))]
11071 "TARGET_PCREL"
11072 "la %0,%a1"
11073 [(set_attr "prefixed" "yes")])
11074
11075 ;; Load up a PC-relative address to an external symbol. If the symbol and the
11076 ;; program are both defined in the main program, the linker will optimize this
11077 ;; to a PADDI. Otherwise, it will create a GOT address that is relocated by
11078 ;; the dynamic linker and loaded up. Print_operand_address will append a
11079 ;; @got@pcrel to the symbol.
11080 (define_insn "*pcrel_extern_addr"
11081 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11082 (match_operand:DI 1 "pcrel_external_address"))]
11083 "TARGET_PCREL"
11084 "ld %0,%a1"
11085 [(set_attr "prefixed" "yes")
11086 (set_attr "type" "load")
11087 (set_attr "loads_external_address" "yes")])
11088
11089 ;; TOC register handling.
11090
11091 ;; Code to initialize the TOC register...
11092
11093 (define_insn "load_toc_aix_si"
11094 [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11095 (unspec:SI [(const_int 0)] UNSPEC_TOC))
11096 (use (reg:SI 2))])]
11097 "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_32BIT"
11098 {
11099 char buf[30];
11100 extern int need_toc_init;
11101 need_toc_init = 1;
11102 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC", 1);
11103 operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11104 operands[2] = gen_rtx_REG (Pmode, 2);
11105 return "lwz %0,%1(%2)";
11106 }
11107 [(set_attr "type" "load")
11108 (set_attr "update" "no")
11109 (set_attr "indexed" "no")])
11110
11111 (define_insn "load_toc_aix_di"
11112 [(parallel [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11113 (unspec:DI [(const_int 0)] UNSPEC_TOC))
11114 (use (reg:DI 2))])]
11115 "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2) && TARGET_64BIT"
11116 {
11117 char buf[30];
11118 extern int need_toc_init;
11119 need_toc_init = 1;
11120 ASM_GENERATE_INTERNAL_LABEL (buf, "LCTOC",
11121 !TARGET_ELF || !TARGET_MINIMAL_TOC);
11122 if (TARGET_ELF)
11123 strcat (buf, "@toc");
11124 operands[1] = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (buf));
11125 operands[2] = gen_rtx_REG (Pmode, 2);
11126 return "ld %0,%1(%2)";
11127 }
11128 [(set_attr "type" "load")
11129 (set_attr "update" "no")
11130 (set_attr "indexed" "no")])
11131
11132 (define_insn "load_toc_v4_pic_si"
11133 [(set (reg:SI LR_REGNO)
11134 (unspec:SI [(const_int 0)] UNSPEC_TOC))]
11135 "DEFAULT_ABI == ABI_V4 && flag_pic == 1 && TARGET_32BIT"
11136 "bl _GLOBAL_OFFSET_TABLE_@local-4"
11137 [(set_attr "type" "branch")])
11138
11139 (define_expand "load_toc_v4_PIC_1"
11140 [(parallel [(set (reg:SI LR_REGNO)
11141 (match_operand:SI 0 "immediate_operand" "s"))
11142 (use (unspec [(match_dup 0)] UNSPEC_TOC))])]
11143 "TARGET_ELF && DEFAULT_ABI == ABI_V4
11144 && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11145 "")
11146
11147 (define_insn "load_toc_v4_PIC_1_normal"
11148 [(set (reg:SI LR_REGNO)
11149 (match_operand:SI 0 "immediate_operand" "s"))
11150 (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11151 "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11152 && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11153 "bcl 20,31,%0\n%0:"
11154 [(set_attr "type" "branch")
11155 (set_attr "cannot_copy" "yes")])
11156
11157 (define_insn "load_toc_v4_PIC_1_476"
11158 [(set (reg:SI LR_REGNO)
11159 (match_operand:SI 0 "immediate_operand" "s"))
11160 (use (unspec [(match_dup 0)] UNSPEC_TOC))]
11161 "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4
11162 && (flag_pic == 2 || (flag_pic && TARGET_SECURE_PLT))"
11163 {
11164 char name[32];
11165 static char templ[32];
11166
11167 get_ppc476_thunk_name (name);
11168 sprintf (templ, "bl %s\n%%0:", name);
11169 return templ;
11170 }
11171 [(set_attr "type" "branch")
11172 (set_attr "cannot_copy" "yes")])
11173
11174 (define_expand "load_toc_v4_PIC_1b"
11175 [(parallel [(set (reg:SI LR_REGNO)
11176 (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11177 (label_ref (match_operand 1 ""))]
11178 UNSPEC_TOCPTR))
11179 (match_dup 1)])]
11180 "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11181 "")
11182
11183 (define_insn "load_toc_v4_PIC_1b_normal"
11184 [(set (reg:SI LR_REGNO)
11185 (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11186 (label_ref (match_operand 1 "" ""))]
11187 UNSPEC_TOCPTR))
11188 (match_dup 1)]
11189 "!TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11190 "bcl 20,31,$+8\;.long %0-$"
11191 [(set_attr "type" "branch")
11192 (set_attr "length" "8")])
11193
11194 (define_insn "load_toc_v4_PIC_1b_476"
11195 [(set (reg:SI LR_REGNO)
11196 (unspec:SI [(match_operand:SI 0 "immediate_operand" "s")
11197 (label_ref (match_operand 1 "" ""))]
11198 UNSPEC_TOCPTR))
11199 (match_dup 1)]
11200 "TARGET_LINK_STACK && TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11201 {
11202 char name[32];
11203 static char templ[32];
11204
11205 get_ppc476_thunk_name (name);
11206 sprintf (templ, "bl %s\;b $+8\;.long %%0-$", name);
11207 return templ;
11208 }
11209 [(set_attr "type" "branch")
11210 (set_attr "length" "16")])
11211
11212 (define_insn "load_toc_v4_PIC_2"
11213 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11214 (mem:SI (plus:SI
11215 (match_operand:SI 1 "gpc_reg_operand" "b")
11216 (const
11217 (minus:SI (match_operand:SI 2 "immediate_operand" "s")
11218 (match_operand:SI 3 "immediate_operand" "s"))))))]
11219 "TARGET_ELF && DEFAULT_ABI == ABI_V4 && flag_pic == 2"
11220 "lwz %0,%2-%3(%1)"
11221 [(set_attr "type" "load")])
11222
11223 (define_insn "load_toc_v4_PIC_3b"
11224 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11225 (plus:SI
11226 (match_operand:SI 1 "gpc_reg_operand" "b")
11227 (high:SI
11228 (const
11229 (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11230 (match_operand:SI 3 "symbol_ref_operand" "s"))))))]
11231 "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11232 "addis %0,%1,%2-%3@ha")
11233
11234 (define_insn "load_toc_v4_PIC_3c"
11235 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11236 (lo_sum:SI
11237 (match_operand:SI 1 "gpc_reg_operand" "b")
11238 (const
11239 (minus:SI (match_operand:SI 2 "symbol_ref_operand" "s")
11240 (match_operand:SI 3 "symbol_ref_operand" "s")))))]
11241 "TARGET_ELF && TARGET_SECURE_PLT && DEFAULT_ABI == ABI_V4 && flag_pic"
11242 "addi %0,%1,%2-%3@l")
11243
11244 ;; If the TOC is shared over a translation unit, as happens with all
11245 ;; the kinds of PIC that we support, we need to restore the TOC
11246 ;; pointer only when jumping over units of translation.
11247 ;; On Darwin, we need to reload the picbase.
11248
11249 (define_expand "builtin_setjmp_receiver"
11250 [(use (label_ref (match_operand 0 "")))]
11251 "(DEFAULT_ABI == ABI_V4 && flag_pic == 1)
11252 || (TARGET_TOC && TARGET_MINIMAL_TOC)
11253 || (DEFAULT_ABI == ABI_DARWIN && flag_pic)"
11254 {
11255 #if TARGET_MACHO
11256 if (DEFAULT_ABI == ABI_DARWIN)
11257 {
11258 rtx picrtx = gen_rtx_SYMBOL_REF (Pmode, MACHOPIC_FUNCTION_BASE_NAME);
11259 rtx picreg = gen_rtx_REG (Pmode, RS6000_PIC_OFFSET_TABLE_REGNUM);
11260 rtx tmplabrtx;
11261 char tmplab[20];
11262
11263 crtl->uses_pic_offset_table = 1;
11264 ASM_GENERATE_INTERNAL_LABEL(tmplab, "LSJR",
11265 CODE_LABEL_NUMBER (operands[0]));
11266 tmplabrtx = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (tmplab));
11267
11268 emit_insn (gen_load_macho_picbase (Pmode, tmplabrtx));
11269 emit_move_insn (picreg, gen_rtx_REG (Pmode, LR_REGNO));
11270 emit_insn (gen_macho_correct_pic (Pmode, picreg, picreg,
11271 picrtx, tmplabrtx));
11272 }
11273 else
11274 #endif
11275 rs6000_emit_load_toc_table (FALSE);
11276 DONE;
11277 })
11278
11279 ;; Largetoc support
11280 (define_insn "*largetoc_high"
11281 [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11282 (high:DI
11283 (unspec [(match_operand:DI 1 "" "")
11284 (match_operand:DI 2 "gpc_reg_operand" "b")]
11285 UNSPEC_TOCREL)))]
11286 "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11287 "addis %0,%2,%1@toc@ha")
11288
11289 (define_insn "*largetoc_high_aix<mode>"
11290 [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11291 (high:P
11292 (unspec [(match_operand:P 1 "" "")
11293 (match_operand:P 2 "gpc_reg_operand" "b")]
11294 UNSPEC_TOCREL)))]
11295 "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11296 "addis %0,%1@u(%2)")
11297
11298 (define_insn "*largetoc_high_plus"
11299 [(set (match_operand:DI 0 "gpc_reg_operand" "=b*r")
11300 (high:DI
11301 (plus:DI
11302 (unspec [(match_operand:DI 1 "" "")
11303 (match_operand:DI 2 "gpc_reg_operand" "b")]
11304 UNSPEC_TOCREL)
11305 (match_operand:DI 3 "add_cint_operand" "n"))))]
11306 "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11307 "addis %0,%2,%1+%3@toc@ha")
11308
11309 (define_insn "*largetoc_high_plus_aix<mode>"
11310 [(set (match_operand:P 0 "gpc_reg_operand" "=b*r")
11311 (high:P
11312 (plus:P
11313 (unspec [(match_operand:P 1 "" "")
11314 (match_operand:P 2 "gpc_reg_operand" "b")]
11315 UNSPEC_TOCREL)
11316 (match_operand:P 3 "add_cint_operand" "n"))))]
11317 "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11318 "addis %0,%1+%3@u(%2)")
11319
11320 (define_insn "*largetoc_low"
11321 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
11322 (lo_sum:DI (match_operand:DI 1 "gpc_reg_operand" "b")
11323 (match_operand:DI 2 "" "")))]
11324 "TARGET_ELF && TARGET_CMODEL != CMODEL_SMALL"
11325 "addi %0,%1,%2@l")
11326
11327 (define_insn "*largetoc_low_aix<mode>"
11328 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11329 (lo_sum:P (match_operand:P 1 "gpc_reg_operand" "b")
11330 (match_operand:P 2 "" "")))]
11331 "TARGET_XCOFF && TARGET_CMODEL != CMODEL_SMALL"
11332 "la %0,%2@l(%1)")
11333
11334 (define_insn_and_split "*tocref<mode>"
11335 [(set (match_operand:P 0 "gpc_reg_operand" "=b")
11336 (match_operand:P 1 "small_toc_ref" "R"))]
11337 "TARGET_TOC
11338 && legitimate_constant_pool_address_p (operands[1], QImode, false)"
11339 "la %0,%a1"
11340 "&& TARGET_CMODEL != CMODEL_SMALL && reload_completed"
11341 [(set (match_dup 0) (high:P (match_dup 1)))
11342 (set (match_dup 0) (lo_sum:P (match_dup 0) (match_dup 1)))])
11343
11344 ;; Elf specific ways of loading addresses for non-PIC code.
11345 ;; The output of this could be r0, but we make a very strong
11346 ;; preference for a base register because it will usually
11347 ;; be needed there.
11348 (define_insn "elf_high"
11349 [(set (match_operand:SI 0 "gpc_reg_operand" "=b*r")
11350 (high:SI (match_operand 1 "" "")))]
11351 "TARGET_ELF && !TARGET_64BIT && !flag_pic"
11352 "lis %0,%1@ha")
11353
11354 (define_insn "elf_low"
11355 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
11356 (lo_sum:SI (match_operand:SI 1 "gpc_reg_operand" "b")
11357 (match_operand 2 "" "")))]
11358 "TARGET_ELF && !TARGET_64BIT && !flag_pic"
11359 "la %0,%2@l(%1)")
11360
11361 (define_insn "*pltseq_tocsave_<mode>"
11362 [(set (match_operand:P 0 "memory_operand" "=m")
11363 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "b")
11364 (match_operand:P 2 "symbol_ref_operand" "s")
11365 (match_operand:P 3 "" "")]
11366 UNSPEC_PLTSEQ))]
11367 "TARGET_PLTSEQ
11368 && DEFAULT_ABI == ABI_ELFv2"
11369 {
11370 return rs6000_pltseq_template (operands, RS6000_PLTSEQ_TOCSAVE);
11371 })
11372
11373 (define_insn "*pltseq_plt16_ha_<mode>"
11374 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11375 (unspec:P [(match_operand:P 1 "" "")
11376 (match_operand:P 2 "symbol_ref_operand" "s")
11377 (match_operand:P 3 "" "")]
11378 UNSPEC_PLT16_HA))]
11379 "TARGET_PLTSEQ"
11380 {
11381 return rs6000_pltseq_template (operands, RS6000_PLTSEQ_PLT16_HA);
11382 })
11383
11384 (define_insn "*pltseq_plt16_lo_<mode>"
11385 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11386 (unspec_volatile:P [(match_operand:P 1 "gpc_reg_operand" "b")
11387 (match_operand:P 2 "symbol_ref_operand" "s")
11388 (match_operand:P 3 "" "")]
11389 UNSPECV_PLT16_LO))]
11390 "TARGET_PLTSEQ"
11391 {
11392 return rs6000_pltseq_template (operands, RS6000_PLTSEQ_PLT16_LO);
11393 }
11394 [(set_attr "type" "load")])
11395
11396 (define_insn "*pltseq_mtctr_<mode>"
11397 [(set (match_operand:P 0 "register_operand" "=c")
11398 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
11399 (match_operand:P 2 "symbol_ref_operand" "s")
11400 (match_operand:P 3 "" "")]
11401 UNSPEC_PLTSEQ))]
11402 "TARGET_PLTSEQ"
11403 {
11404 return rs6000_pltseq_template (operands, RS6000_PLTSEQ_MTCTR);
11405 })
11406
11407 (define_insn "*pltseq_plt_pcrel<mode>"
11408 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
11409 (unspec_volatile:P [(match_operand:P 1 "" "")
11410 (match_operand:P 2 "symbol_ref_operand" "s")
11411 (match_operand:P 3 "" "")]
11412 UNSPECV_PLT_PCREL))]
11413 "HAVE_AS_PLTSEQ && TARGET_ELF
11414 && rs6000_pcrel_p ()"
11415 {
11416 return rs6000_pltseq_template (operands, RS6000_PLTSEQ_PLT_PCREL34);
11417 }
11418 [(set_attr "type" "load")
11419 (set_attr "length" "12")])
11420
11421 ;; Call and call_value insns
11422 ;; For the purposes of expanding calls, Darwin is very similar to SYSV.
11423 (define_expand "call"
11424 [(parallel [(call (mem:SI (match_operand 0 "address_operand"))
11425 (match_operand 1 ""))
11426 (use (match_operand 2 ""))
11427 (clobber (reg:SI LR_REGNO))])]
11428 ""
11429 {
11430 #if TARGET_MACHO
11431 if (MACHOPIC_INDIRECT)
11432 operands[0] = machopic_indirect_call_target (operands[0]);
11433 #endif
11434
11435 gcc_assert (MEM_P (operands[0]));
11436
11437 operands[0] = XEXP (operands[0], 0);
11438
11439 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11440 rs6000_call_aix (NULL_RTX, operands[0], operands[1], operands[2]);
11441 else if (DEFAULT_ABI == ABI_V4)
11442 rs6000_call_sysv (NULL_RTX, operands[0], operands[1], operands[2]);
11443 else if (DEFAULT_ABI == ABI_DARWIN)
11444 rs6000_call_darwin (NULL_RTX, operands[0], operands[1], operands[2]);
11445 else
11446 gcc_unreachable ();
11447
11448 DONE;
11449 })
11450
11451 (define_expand "call_value"
11452 [(parallel [(set (match_operand 0 "")
11453 (call (mem:SI (match_operand 1 "address_operand"))
11454 (match_operand 2 "")))
11455 (use (match_operand 3 ""))
11456 (clobber (reg:SI LR_REGNO))])]
11457 ""
11458 {
11459 #if TARGET_MACHO
11460 if (MACHOPIC_INDIRECT)
11461 operands[1] = machopic_indirect_call_target (operands[1]);
11462 #endif
11463
11464 gcc_assert (MEM_P (operands[1]));
11465
11466 operands[1] = XEXP (operands[1], 0);
11467
11468 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11469 rs6000_call_aix (operands[0], operands[1], operands[2], operands[3]);
11470 else if (DEFAULT_ABI == ABI_V4)
11471 rs6000_call_sysv (operands[0], operands[1], operands[2], operands[3]);
11472 else if (DEFAULT_ABI == ABI_DARWIN)
11473 rs6000_call_darwin (operands[0], operands[1], operands[2], operands[3]);
11474 else
11475 gcc_unreachable ();
11476
11477 DONE;
11478 })
11479
11480 ;; Call to function in current module. No TOC pointer reload needed.
11481 ;; Operand2 is nonzero if we are using the V.4 calling sequence and
11482 ;; either the function was not prototyped, or it was prototyped as a
11483 ;; variable argument function. It is > 0 if FP registers were passed
11484 ;; and < 0 if they were not.
11485
11486 (define_insn "*call_local<mode>"
11487 [(call (mem:SI (match_operand:P 0 "current_file_function_operand" "s,s"))
11488 (match_operand 1))
11489 (use (match_operand:SI 2 "immediate_operand" "O,n"))
11490 (clobber (reg:P LR_REGNO))]
11491 "(INTVAL (operands[2]) & CALL_LONG) == 0"
11492 {
11493 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11494 output_asm_insn ("crxor 6,6,6", operands);
11495
11496 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11497 output_asm_insn ("creqv 6,6,6", operands);
11498
11499 if (rs6000_pcrel_p ())
11500 return "bl %z0@notoc";
11501 return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z0@local" : "bl %z0";
11502 }
11503 [(set_attr "type" "branch")
11504 (set_attr "length" "4,8")])
11505
11506 (define_insn "*call_value_local<mode>"
11507 [(set (match_operand 0 "" "")
11508 (call (mem:SI (match_operand:P 1 "current_file_function_operand" "s,s"))
11509 (match_operand 2)))
11510 (use (match_operand:SI 3 "immediate_operand" "O,n"))
11511 (clobber (reg:P LR_REGNO))]
11512 "(INTVAL (operands[3]) & CALL_LONG) == 0"
11513 {
11514 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11515 output_asm_insn ("crxor 6,6,6", operands);
11516
11517 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11518 output_asm_insn ("creqv 6,6,6", operands);
11519
11520 if (rs6000_pcrel_p ())
11521 return "bl %z1@notoc";
11522 return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "bl %z1@local" : "bl %z1";
11523 }
11524 [(set_attr "type" "branch")
11525 (set_attr "length" "4,8")])
11526
11527
11528 ;; A function pointer under System V is just a normal pointer
11529 ;; operands[0] is the function pointer
11530 ;; operands[1] is the tls call arg
11531 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument
11532 ;; which indicates how to set cr1
11533
11534 (define_insn "*call_indirect_nonlocal_sysv<mode>"
11535 [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
11536 (match_operand 1))
11537 (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
11538 (clobber (reg:P LR_REGNO))]
11539 "DEFAULT_ABI == ABI_V4
11540 || DEFAULT_ABI == ABI_DARWIN"
11541 {
11542 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11543 output_asm_insn ("crxor 6,6,6", operands);
11544
11545 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11546 output_asm_insn ("creqv 6,6,6", operands);
11547
11548 return rs6000_indirect_call_template (operands, 0);
11549 }
11550 [(set_attr "type" "jmpreg")
11551 (set (attr "length")
11552 (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps")
11553 (match_test "which_alternative != 1"))
11554 (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))"))
11555 (const_string "12")
11556 (ior (and (match_test "!rs6000_speculate_indirect_jumps")
11557 (match_test "which_alternative != 1"))
11558 (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))"))
11559 (const_string "8")]
11560 (const_string "4")))])
11561
11562 (define_insn "*call_nonlocal_sysv<mode>"
11563 [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11564 (match_operand 1))
11565 (use (match_operand:SI 2 "immediate_operand" "O,n"))
11566 (clobber (reg:P LR_REGNO))]
11567 "(DEFAULT_ABI == ABI_DARWIN
11568 || (DEFAULT_ABI == ABI_V4
11569 && (INTVAL (operands[2]) & CALL_LONG) == 0))"
11570 {
11571 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11572 output_asm_insn ("crxor 6,6,6", operands);
11573
11574 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11575 output_asm_insn ("creqv 6,6,6", operands);
11576
11577 return rs6000_call_template (operands, 0);
11578 }
11579 [(set_attr "type" "branch,branch")
11580 (set_attr "length" "4,8")])
11581
11582 (define_insn "*call_nonlocal_sysv_secure<mode>"
11583 [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11584 (match_operand 1))
11585 (use (match_operand:SI 2 "immediate_operand" "O,n"))
11586 (use (match_operand:SI 3 "register_operand" "r,r"))
11587 (clobber (reg:P LR_REGNO))]
11588 "(DEFAULT_ABI == ABI_V4
11589 && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[0])
11590 && (INTVAL (operands[2]) & CALL_LONG) == 0)"
11591 {
11592 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11593 output_asm_insn ("crxor 6,6,6", operands);
11594
11595 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11596 output_asm_insn ("creqv 6,6,6", operands);
11597
11598 return rs6000_call_template (operands, 0);
11599 }
11600 [(set_attr "type" "branch,branch")
11601 (set_attr "length" "4,8")])
11602
11603 (define_insn "*call_value_indirect_nonlocal_sysv<mode>"
11604 [(set (match_operand 0 "" "")
11605 (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
11606 (match_operand:P 2 "unspec_tls" "")))
11607 (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
11608 (clobber (reg:P LR_REGNO))]
11609 "DEFAULT_ABI == ABI_V4
11610 || DEFAULT_ABI == ABI_DARWIN"
11611 {
11612 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11613 output_asm_insn ("crxor 6,6,6", operands);
11614
11615 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11616 output_asm_insn ("creqv 6,6,6", operands);
11617
11618 return rs6000_indirect_call_template (operands, 1);
11619 }
11620 [(set_attr "type" "jmpreg")
11621 (set (attr "length")
11622 (plus
11623 (if_then_else (match_test "IS_V4_FP_ARGS (operands[3])")
11624 (const_int 4)
11625 (const_int 0))
11626 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11627 (match_test "which_alternative != 1"))
11628 (const_int 8)
11629 (const_int 4))))])
11630
11631 (define_insn "*call_value_nonlocal_sysv<mode>"
11632 [(set (match_operand 0 "" "")
11633 (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
11634 (match_operand:P 2 "unspec_tls" "")))
11635 (use (match_operand:SI 3 "immediate_operand" "n"))
11636 (clobber (reg:P LR_REGNO))]
11637 "(DEFAULT_ABI == ABI_DARWIN
11638 || (DEFAULT_ABI == ABI_V4
11639 && (INTVAL (operands[3]) & CALL_LONG) == 0))"
11640 {
11641 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11642 output_asm_insn ("crxor 6,6,6", operands);
11643
11644 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11645 output_asm_insn ("creqv 6,6,6", operands);
11646
11647 return rs6000_call_template (operands, 1);
11648 }
11649 [(set_attr "type" "branch")
11650 (set (attr "length")
11651 (if_then_else (match_test "IS_V4_FP_ARGS (operands[3])")
11652 (const_int 8)
11653 (const_int 4)))])
11654
11655 (define_insn "*call_value_nonlocal_sysv_secure<mode>"
11656 [(set (match_operand 0 "" "")
11657 (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
11658 (match_operand:P 2 "unspec_tls" "")))
11659 (use (match_operand:SI 3 "immediate_operand" "n"))
11660 (use (match_operand:SI 4 "register_operand" "r"))
11661 (clobber (reg:P LR_REGNO))]
11662 "(DEFAULT_ABI == ABI_V4
11663 && TARGET_SECURE_PLT && flag_pic && !SYMBOL_REF_LOCAL_P (operands[1])
11664 && (INTVAL (operands[3]) & CALL_LONG) == 0)"
11665 {
11666 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11667 output_asm_insn ("crxor 6,6,6", operands);
11668
11669 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11670 output_asm_insn ("creqv 6,6,6", operands);
11671
11672 return rs6000_call_template (operands, 1);
11673 }
11674 [(set_attr "type" "branch")
11675 (set (attr "length")
11676 (if_then_else (match_test "IS_V4_FP_ARGS (operands[3])")
11677 (const_int 8)
11678 (const_int 4)))])
11679
11680 ;; Call to AIX abi function which may be in another module.
11681 ;; Restore the TOC pointer (r2) after the call.
11682
11683 (define_insn "*call_nonlocal_aix<mode>"
11684 [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s"))
11685 (match_operand 1))
11686 (use (match_operand:SI 2 "immediate_operand" "n"))
11687 (clobber (reg:P LR_REGNO))]
11688 "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11689 && (INTVAL (operands[2]) & CALL_LONG) == 0"
11690 {
11691 return rs6000_call_template (operands, 0);
11692 }
11693 [(set_attr "type" "branch")
11694 (set (attr "length")
11695 (if_then_else (match_test "rs6000_pcrel_p ()")
11696 (const_int 4)
11697 (const_int 8)))])
11698
11699 (define_insn "*call_value_nonlocal_aix<mode>"
11700 [(set (match_operand 0 "" "")
11701 (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s"))
11702 (match_operand:P 2 "unspec_tls" "")))
11703 (use (match_operand:SI 3 "immediate_operand" "n"))
11704 (clobber (reg:P LR_REGNO))]
11705 "(DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11706 && (INTVAL (operands[3]) & CALL_LONG) == 0"
11707 {
11708 return rs6000_call_template (operands, 1);
11709 }
11710 [(set_attr "type" "branch")
11711 (set (attr "length")
11712 (if_then_else (match_test "rs6000_pcrel_p ()")
11713 (const_int 4)
11714 (const_int 8)))])
11715
11716 ;; Call to indirect functions with the AIX abi using a 3 word descriptor.
11717 ;; Operand0 is the addresss of the function to call
11718 ;; Operand3 is the location in the function descriptor to load r2 from
11719 ;; Operand4 is the offset of the stack location holding the current TOC pointer
11720
11721 (define_insn "*call_indirect_aix<mode>"
11722 [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
11723 (match_operand 1))
11724 (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
11725 (use (match_operand:P 3 "memory_operand" "<ptrm>,<ptrm>,<ptrm>"))
11726 (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 4 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT))
11727 (clobber (reg:P LR_REGNO))]
11728 "DEFAULT_ABI == ABI_AIX"
11729 {
11730 return rs6000_indirect_call_template (operands, 0);
11731 }
11732 [(set_attr "type" "jmpreg")
11733 (set (attr "length")
11734 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11735 (match_test "which_alternative != 1"))
11736 (const_string "16")
11737 (const_string "12")))])
11738
11739 (define_insn "*call_value_indirect_aix<mode>"
11740 [(set (match_operand 0 "" "")
11741 (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
11742 (match_operand:P 2 "unspec_tls" "")))
11743 (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
11744 (use (match_operand:P 4 "memory_operand" "<ptrm>,<ptrm>,<ptrm>"))
11745 (set (reg:P TOC_REGNUM)
11746 (unspec:P [(match_operand:P 5 "const_int_operand" "n,n,n")]
11747 UNSPEC_TOCSLOT))
11748 (clobber (reg:P LR_REGNO))]
11749 "DEFAULT_ABI == ABI_AIX"
11750 {
11751 return rs6000_indirect_call_template (operands, 1);
11752 }
11753 [(set_attr "type" "jmpreg")
11754 (set (attr "length")
11755 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11756 (match_test "which_alternative != 1"))
11757 (const_string "16")
11758 (const_string "12")))])
11759
11760 ;; Call to indirect functions with the ELFv2 ABI.
11761 ;; Operand0 is the addresss of the function to call
11762 ;; Operand3 is the offset of the stack location holding the current TOC pointer
11763
11764 (define_insn "*call_indirect_elfv2<mode>"
11765 [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
11766 (match_operand 1))
11767 (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
11768 (set (reg:P TOC_REGNUM) (unspec:P [(match_operand:P 3 "const_int_operand" "n,n,n")] UNSPEC_TOCSLOT))
11769 (clobber (reg:P LR_REGNO))]
11770 "DEFAULT_ABI == ABI_ELFv2"
11771 {
11772 return rs6000_indirect_call_template (operands, 0);
11773 }
11774 [(set_attr "type" "jmpreg")
11775 (set (attr "length")
11776 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11777 (match_test "which_alternative != 1"))
11778 (const_string "12")
11779 (const_string "8")))])
11780
11781 (define_insn "*call_indirect_pcrel<mode>"
11782 [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
11783 (match_operand 1))
11784 (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
11785 (clobber (reg:P LR_REGNO))]
11786 "rs6000_pcrel_p ()"
11787 {
11788 return rs6000_indirect_call_template (operands, 0);
11789 }
11790 [(set_attr "type" "jmpreg")
11791 (set (attr "length")
11792 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11793 (match_test "which_alternative != 1"))
11794 (const_string "8")
11795 (const_string "4")))])
11796
11797 (define_insn "*call_value_indirect_elfv2<mode>"
11798 [(set (match_operand 0 "" "")
11799 (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
11800 (match_operand:P 2 "unspec_tls" "")))
11801 (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
11802 (set (reg:P TOC_REGNUM)
11803 (unspec:P [(match_operand:P 4 "const_int_operand" "n,n,n")]
11804 UNSPEC_TOCSLOT))
11805 (clobber (reg:P LR_REGNO))]
11806 "DEFAULT_ABI == ABI_ELFv2"
11807 {
11808 return rs6000_indirect_call_template (operands, 1);
11809 }
11810 [(set_attr "type" "jmpreg")
11811 (set (attr "length")
11812 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11813 (match_test "which_alternative != 1"))
11814 (const_string "12")
11815 (const_string "8")))])
11816
11817 (define_insn "*call_value_indirect_pcrel<mode>"
11818 [(set (match_operand 0 "" "")
11819 (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
11820 (match_operand:P 2 "unspec_tls" "")))
11821 (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
11822 (clobber (reg:P LR_REGNO))]
11823 "rs6000_pcrel_p ()"
11824 {
11825 return rs6000_indirect_call_template (operands, 1);
11826 }
11827 [(set_attr "type" "jmpreg")
11828 (set (attr "length")
11829 (if_then_else (and (match_test "!rs6000_speculate_indirect_jumps")
11830 (match_test "which_alternative != 1"))
11831 (const_string "8")
11832 (const_string "4")))])
11833
11834 ;; Call subroutine returning any type.
11835 (define_expand "untyped_call"
11836 [(parallel [(call (match_operand 0 "")
11837 (const_int 0))
11838 (match_operand 1 "")
11839 (match_operand 2 "")])]
11840 ""
11841 {
11842 int i;
11843
11844 emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx));
11845
11846 for (int i = 0; i < XVECLEN (operands[2], 0); i++)
11847 emit_clobber (SET_SRC (XVECEXP (operands[2], 0, i)));
11848 emit_insn (gen_blockage ());
11849
11850 for (i = 0; i < XVECLEN (operands[2], 0); i++)
11851 {
11852 rtx set = XVECEXP (operands[2], 0, i);
11853 emit_move_insn (SET_DEST (set), SET_SRC (set));
11854 }
11855
11856 /* The optimizer does not know that the call sets the function value
11857 registers we stored in the result block. We avoid problems by
11858 claiming that all hard registers are used and clobbered at this
11859 point. */
11860 emit_insn (gen_blockage ());
11861
11862 DONE;
11863 })
11864
11865 ;; sibling call patterns
11866 (define_expand "sibcall"
11867 [(parallel [(call (mem:SI (match_operand 0 "address_operand"))
11868 (match_operand 1 ""))
11869 (use (match_operand 2 ""))
11870 (simple_return)])]
11871 ""
11872 {
11873 #if TARGET_MACHO
11874 if (MACHOPIC_INDIRECT)
11875 operands[0] = machopic_indirect_call_target (operands[0]);
11876 #endif
11877
11878 gcc_assert (MEM_P (operands[0]));
11879 gcc_assert (CONST_INT_P (operands[1]));
11880
11881 operands[0] = XEXP (operands[0], 0);
11882
11883 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11884 rs6000_sibcall_aix (NULL_RTX, operands[0], operands[1], operands[2]);
11885 else if (DEFAULT_ABI == ABI_V4)
11886 rs6000_sibcall_sysv (NULL_RTX, operands[0], operands[1], operands[2]);
11887 else if (DEFAULT_ABI == ABI_DARWIN)
11888 rs6000_sibcall_darwin (NULL_RTX, operands[0], operands[1], operands[2]);
11889 else
11890 gcc_unreachable ();
11891
11892 DONE;
11893 })
11894
11895 (define_expand "sibcall_value"
11896 [(parallel [(set (match_operand 0 "register_operand")
11897 (call (mem:SI (match_operand 1 "address_operand"))
11898 (match_operand 2 "")))
11899 (use (match_operand 3 ""))
11900 (simple_return)])]
11901 ""
11902 {
11903 #if TARGET_MACHO
11904 if (MACHOPIC_INDIRECT)
11905 operands[1] = machopic_indirect_call_target (operands[1]);
11906 #endif
11907
11908 gcc_assert (MEM_P (operands[1]));
11909 gcc_assert (CONST_INT_P (operands[2]));
11910
11911 operands[1] = XEXP (operands[1], 0);
11912
11913 if (DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2)
11914 rs6000_sibcall_aix (operands[0], operands[1], operands[2], operands[3]);
11915 else if (DEFAULT_ABI == ABI_V4)
11916 rs6000_sibcall_sysv (operands[0], operands[1], operands[2], operands[3]);
11917 else if (DEFAULT_ABI == ABI_DARWIN)
11918 rs6000_sibcall_darwin (operands[0], operands[1], operands[2], operands[3]);
11919 else
11920 gcc_unreachable ();
11921
11922 DONE;
11923 })
11924
11925 (define_insn "*sibcall_local<mode>"
11926 [(call (mem:SI (match_operand:P 0 "current_file_function_operand" "s,s"))
11927 (match_operand 1))
11928 (use (match_operand:SI 2 "immediate_operand" "O,n"))
11929 (simple_return)]
11930 "(INTVAL (operands[2]) & CALL_LONG) == 0"
11931 {
11932 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11933 output_asm_insn ("crxor 6,6,6", operands);
11934
11935 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11936 output_asm_insn ("creqv 6,6,6", operands);
11937
11938 return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "b %z0@local" : "b %z0";
11939 }
11940 [(set_attr "type" "branch")
11941 (set_attr "length" "4,8")])
11942
11943 (define_insn "*sibcall_value_local<mode>"
11944 [(set (match_operand 0 "" "")
11945 (call (mem:SI (match_operand:P 1 "current_file_function_operand" "s,s"))
11946 (match_operand 2)))
11947 (use (match_operand:SI 3 "immediate_operand" "O,n"))
11948 (simple_return)]
11949 "(INTVAL (operands[3]) & CALL_LONG) == 0"
11950 {
11951 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
11952 output_asm_insn ("crxor 6,6,6", operands);
11953
11954 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
11955 output_asm_insn ("creqv 6,6,6", operands);
11956
11957 return (DEFAULT_ABI == ABI_V4 && flag_pic) ? "b %z1@local" : "b %z1";
11958 }
11959 [(set_attr "type" "branch")
11960 (set_attr "length" "4,8")])
11961
11962 (define_insn "*sibcall_indirect_nonlocal_sysv<mode>"
11963 [(call (mem:SI (match_operand:P 0 "indirect_call_operand" "c,*l,X"))
11964 (match_operand 1))
11965 (use (match_operand:SI 2 "immediate_operand" "n,n,n"))
11966 (simple_return)]
11967 "DEFAULT_ABI == ABI_V4
11968 || DEFAULT_ABI == ABI_DARWIN"
11969 {
11970 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
11971 output_asm_insn ("crxor 6,6,6", operands);
11972
11973 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
11974 output_asm_insn ("creqv 6,6,6", operands);
11975
11976 return rs6000_indirect_sibcall_template (operands, 0);
11977 }
11978 [(set_attr "type" "jmpreg")
11979 (set (attr "length")
11980 (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps")
11981 (match_test "which_alternative != 1"))
11982 (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))"))
11983 (const_string "12")
11984 (ior (and (match_test "!rs6000_speculate_indirect_jumps")
11985 (match_test "which_alternative != 1"))
11986 (match_test "(INTVAL (operands[2]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))"))
11987 (const_string "8")]
11988 (const_string "4")))])
11989
11990 (define_insn "*sibcall_nonlocal_sysv<mode>"
11991 [(call (mem:SI (match_operand:P 0 "symbol_ref_operand" "s,s"))
11992 (match_operand 1))
11993 (use (match_operand 2 "immediate_operand" "O,n"))
11994 (simple_return)]
11995 "(DEFAULT_ABI == ABI_DARWIN
11996 || DEFAULT_ABI == ABI_V4)
11997 && (INTVAL (operands[2]) & CALL_LONG) == 0"
11998 {
11999 if (INTVAL (operands[2]) & CALL_V4_SET_FP_ARGS)
12000 output_asm_insn ("crxor 6,6,6", operands);
12001
12002 else if (INTVAL (operands[2]) & CALL_V4_CLEAR_FP_ARGS)
12003 output_asm_insn ("creqv 6,6,6", operands);
12004
12005 return rs6000_sibcall_template (operands, 0);
12006 }
12007 [(set_attr "type" "branch")
12008 (set_attr "length" "4,8")])
12009
12010 (define_insn "*sibcall_value_indirect_nonlocal_sysv<mode>"
12011 [(set (match_operand 0 "" "")
12012 (call (mem:SI (match_operand:P 1 "indirect_call_operand" "c,*l,X"))
12013 (match_operand 2)))
12014 (use (match_operand:SI 3 "immediate_operand" "n,n,n"))
12015 (simple_return)]
12016 "DEFAULT_ABI == ABI_V4
12017 || DEFAULT_ABI == ABI_DARWIN"
12018 {
12019 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12020 output_asm_insn ("crxor 6,6,6", operands);
12021
12022 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12023 output_asm_insn ("creqv 6,6,6", operands);
12024
12025 return rs6000_indirect_sibcall_template (operands, 1);
12026 }
12027 [(set_attr "type" "jmpreg")
12028 (set (attr "length")
12029 (cond [(and (and (match_test "!rs6000_speculate_indirect_jumps")
12030 (match_test "which_alternative != 1"))
12031 (match_test "(INTVAL (operands[3]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))"))
12032 (const_string "12")
12033 (ior (and (match_test "!rs6000_speculate_indirect_jumps")
12034 (match_test "which_alternative != 1"))
12035 (match_test "(INTVAL (operands[3]) & (CALL_V4_SET_FP_ARGS | CALL_V4_CLEAR_FP_ARGS))"))
12036 (const_string "8")]
12037 (const_string "4")))])
12038
12039 (define_insn "*sibcall_value_nonlocal_sysv<mode>"
12040 [(set (match_operand 0 "" "")
12041 (call (mem:SI (match_operand:P 1 "symbol_ref_operand" "s,s"))
12042 (match_operand 2)))
12043 (use (match_operand:SI 3 "immediate_operand" "O,n"))
12044 (simple_return)]
12045 "(DEFAULT_ABI == ABI_DARWIN
12046 || DEFAULT_ABI == ABI_V4)
12047 && (INTVAL (operands[3]) & CALL_LONG) == 0"
12048 {
12049 if (INTVAL (operands[3]) & CALL_V4_SET_FP_ARGS)
12050 output_asm_insn ("crxor 6,6,6", operands);
12051
12052 else if (INTVAL (operands[3]) & CALL_V4_CLEAR_FP_ARGS)
12053 output_asm_insn ("creqv 6,6,6", operands);
12054
12055 return rs6000_sibcall_template (operands, 1);
12056 }
12057 [(set_attr "type" "branch")
12058 (set_attr "length" "4,8")])
12059
12060 ;; AIX ABI sibling call patterns.
12061
12062 (define_insn "*sibcall_aix<mode>"
12063 [(call (mem:SI (match_operand:P 0 "call_operand" "s,c"))
12064 (match_operand 1))
12065 (simple_return)]
12066 "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12067 {
12068 if (which_alternative == 0)
12069 return rs6000_sibcall_template (operands, 0);
12070 else
12071 return "b%T0";
12072 }
12073 [(set_attr "type" "branch")])
12074
12075 (define_insn "*sibcall_value_aix<mode>"
12076 [(set (match_operand 0 "" "")
12077 (call (mem:SI (match_operand:P 1 "call_operand" "s,c"))
12078 (match_operand 2)))
12079 (simple_return)]
12080 "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_ELFv2"
12081 {
12082 if (which_alternative == 0)
12083 return rs6000_sibcall_template (operands, 1);
12084 else
12085 return "b%T1";
12086 }
12087 [(set_attr "type" "branch")])
12088
12089 (define_expand "sibcall_epilogue"
12090 [(use (const_int 0))]
12091 ""
12092 {
12093 if (!TARGET_SCHED_PROLOG)
12094 emit_insn (gen_blockage ());
12095 rs6000_emit_epilogue (EPILOGUE_TYPE_SIBCALL);
12096 DONE;
12097 })
12098
12099 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
12100 ;; all of memory. This blocks insns from being moved across this point.
12101
12102 (define_insn "blockage"
12103 [(unspec_volatile [(const_int 0)] UNSPECV_BLOCK)]
12104 ""
12105 ""
12106 [(set_attr "length" "0")])
12107
12108 (define_expand "probe_stack_address"
12109 [(use (match_operand 0 "address_operand"))]
12110 ""
12111 {
12112 operands[0] = gen_rtx_MEM (Pmode, operands[0]);
12113 MEM_VOLATILE_P (operands[0]) = 1;
12114
12115 if (TARGET_64BIT)
12116 emit_insn (gen_probe_stack_di (operands[0]));
12117 else
12118 emit_insn (gen_probe_stack_si (operands[0]));
12119 DONE;
12120 })
12121
12122 (define_insn "probe_stack_<mode>"
12123 [(set (match_operand:P 0 "memory_operand" "=m")
12124 (unspec:P [(const_int 0)] UNSPEC_PROBE_STACK))]
12125 ""
12126 {
12127 operands[1] = gen_rtx_REG (Pmode, 0);
12128 return "st<wd>%U0%X0 %1,%0";
12129 }
12130 [(set_attr "type" "store")
12131 (set (attr "update")
12132 (if_then_else (match_operand 0 "update_address_mem")
12133 (const_string "yes")
12134 (const_string "no")))
12135 (set (attr "indexed")
12136 (if_then_else (match_operand 0 "indexed_address_mem")
12137 (const_string "yes")
12138 (const_string "no")))])
12139
12140 (define_insn "probe_stack_range<P:mode>"
12141 [(set (match_operand:P 0 "register_operand" "=&r")
12142 (unspec_volatile:P [(match_operand:P 1 "register_operand" "0")
12143 (match_operand:P 2 "register_operand" "r")
12144 (match_operand:P 3 "register_operand" "r")]
12145 UNSPECV_PROBE_STACK_RANGE))]
12146 ""
12147 "* return output_probe_stack_range (operands[0], operands[2], operands[3]);"
12148 [(set_attr "type" "three")])
12149
12150 ;; Compare insns are next. Note that the RS/6000 has two types of compares,
12151 ;; signed & unsigned, and one type of branch.
12152 ;;
12153 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
12154 ;; insns, and branches.
12155
12156 (define_expand "cbranch<mode>4"
12157 [(use (match_operator 0 "comparison_operator"
12158 [(match_operand:GPR 1 "gpc_reg_operand")
12159 (match_operand:GPR 2 "reg_or_short_operand")]))
12160 (use (match_operand 3))]
12161 ""
12162 {
12163 /* Take care of the possibility that operands[2] might be negative but
12164 this might be a logical operation. That insn doesn't exist. */
12165 if (CONST_INT_P (operands[2])
12166 && INTVAL (operands[2]) < 0)
12167 {
12168 operands[2] = force_reg (<MODE>mode, operands[2]);
12169 operands[0] = gen_rtx_fmt_ee (GET_CODE (operands[0]),
12170 GET_MODE (operands[0]),
12171 operands[1], operands[2]);
12172 }
12173
12174 rs6000_emit_cbranch (<MODE>mode, operands);
12175 DONE;
12176 })
12177
12178 (define_expand "cbranch<mode>4"
12179 [(use (match_operator 0 "comparison_operator"
12180 [(match_operand:FP 1 "gpc_reg_operand")
12181 (match_operand:FP 2 "gpc_reg_operand")]))
12182 (use (match_operand 3))]
12183 ""
12184 {
12185 rs6000_emit_cbranch (<MODE>mode, operands);
12186 DONE;
12187 })
12188
12189 (define_expand "cbranchcc4"
12190 [(set (pc)
12191 (if_then_else (match_operator 0 "branch_comparison_operator"
12192 [(match_operand 1 "cc_reg_operand")
12193 (match_operand 2 "zero_constant")])
12194 (label_ref (match_operand 3))
12195 (pc)))]
12196 ""
12197 "")
12198
12199 (define_expand "cstore<mode>4_signed"
12200 [(use (match_operator 1 "signed_comparison_operator"
12201 [(match_operand:P 2 "gpc_reg_operand")
12202 (match_operand:P 3 "gpc_reg_operand")]))
12203 (clobber (match_operand:P 0 "gpc_reg_operand"))]
12204 ""
12205 {
12206 enum rtx_code cond_code = GET_CODE (operands[1]);
12207
12208 rtx op0 = operands[0];
12209 rtx op1 = operands[2];
12210 rtx op2 = operands[3];
12211
12212 if (cond_code == GE || cond_code == LT)
12213 {
12214 cond_code = swap_condition (cond_code);
12215 std::swap (op1, op2);
12216 }
12217
12218 rtx tmp1 = gen_reg_rtx (<MODE>mode);
12219 rtx tmp2 = gen_reg_rtx (<MODE>mode);
12220 rtx tmp3 = gen_reg_rtx (<MODE>mode);
12221
12222 int sh = GET_MODE_BITSIZE (<MODE>mode) - 1;
12223 emit_insn (gen_lshr<mode>3 (tmp1, op1, GEN_INT (sh)));
12224 emit_insn (gen_ashr<mode>3 (tmp2, op2, GEN_INT (sh)));
12225
12226 emit_insn (gen_subf<mode>3_carry (tmp3, op1, op2));
12227
12228 if (cond_code == LE)
12229 emit_insn (gen_add<mode>3_carry_in (op0, tmp1, tmp2));
12230 else
12231 {
12232 rtx tmp4 = gen_reg_rtx (<MODE>mode);
12233 emit_insn (gen_add<mode>3_carry_in (tmp4, tmp1, tmp2));
12234 emit_insn (gen_xor<mode>3 (op0, tmp4, const1_rtx));
12235 }
12236
12237 DONE;
12238 })
12239
12240 (define_expand "cstore<mode>4_unsigned"
12241 [(use (match_operator 1 "unsigned_comparison_operator"
12242 [(match_operand:P 2 "gpc_reg_operand")
12243 (match_operand:P 3 "reg_or_short_operand")]))
12244 (clobber (match_operand:P 0 "gpc_reg_operand"))]
12245 ""
12246 {
12247 enum rtx_code cond_code = GET_CODE (operands[1]);
12248
12249 rtx op0 = operands[0];
12250 rtx op1 = operands[2];
12251 rtx op2 = operands[3];
12252
12253 if (cond_code == GEU || cond_code == LTU)
12254 {
12255 cond_code = swap_condition (cond_code);
12256 std::swap (op1, op2);
12257 }
12258
12259 if (!gpc_reg_operand (op1, <MODE>mode))
12260 op1 = force_reg (<MODE>mode, op1);
12261 if (!reg_or_short_operand (op2, <MODE>mode))
12262 op2 = force_reg (<MODE>mode, op2);
12263
12264 rtx tmp = gen_reg_rtx (<MODE>mode);
12265 rtx tmp2 = gen_reg_rtx (<MODE>mode);
12266
12267 emit_insn (gen_subf<mode>3_carry (tmp, op1, op2));
12268 emit_insn (gen_subf<mode>3_carry_in_xx (tmp2));
12269
12270 if (cond_code == LEU)
12271 emit_insn (gen_add<mode>3 (op0, tmp2, const1_rtx));
12272 else
12273 emit_insn (gen_neg<mode>2 (op0, tmp2));
12274
12275 DONE;
12276 })
12277
12278 (define_expand "cstore_si_as_di"
12279 [(use (match_operator 1 "unsigned_comparison_operator"
12280 [(match_operand:SI 2 "gpc_reg_operand")
12281 (match_operand:SI 3 "reg_or_short_operand")]))
12282 (clobber (match_operand:SI 0 "gpc_reg_operand"))]
12283 ""
12284 {
12285 int uns_flag = unsigned_comparison_operator (operands[1], VOIDmode) ? 1 : 0;
12286 enum rtx_code cond_code = signed_condition (GET_CODE (operands[1]));
12287
12288 operands[2] = force_reg (SImode, operands[2]);
12289 operands[3] = force_reg (SImode, operands[3]);
12290 rtx op1 = gen_reg_rtx (DImode);
12291 rtx op2 = gen_reg_rtx (DImode);
12292 convert_move (op1, operands[2], uns_flag);
12293 convert_move (op2, operands[3], uns_flag);
12294
12295 if (cond_code == GT || cond_code == LE)
12296 {
12297 cond_code = swap_condition (cond_code);
12298 std::swap (op1, op2);
12299 }
12300
12301 rtx tmp = gen_reg_rtx (DImode);
12302 rtx tmp2 = gen_reg_rtx (DImode);
12303 emit_insn (gen_subdi3 (tmp, op1, op2));
12304 emit_insn (gen_lshrdi3 (tmp2, tmp, GEN_INT (63)));
12305
12306 rtx tmp3;
12307 switch (cond_code)
12308 {
12309 default:
12310 gcc_unreachable ();
12311 case LT:
12312 tmp3 = tmp2;
12313 break;
12314 case GE:
12315 tmp3 = gen_reg_rtx (DImode);
12316 emit_insn (gen_xordi3 (tmp3, tmp2, const1_rtx));
12317 break;
12318 }
12319
12320 convert_move (operands[0], tmp3, 1);
12321
12322 DONE;
12323 })
12324
12325 (define_expand "cstore<mode>4_signed_imm"
12326 [(use (match_operator 1 "signed_comparison_operator"
12327 [(match_operand:GPR 2 "gpc_reg_operand")
12328 (match_operand:GPR 3 "immediate_operand")]))
12329 (clobber (match_operand:GPR 0 "gpc_reg_operand"))]
12330 ""
12331 {
12332 bool invert = false;
12333
12334 enum rtx_code cond_code = GET_CODE (operands[1]);
12335
12336 rtx op0 = operands[0];
12337 rtx op1 = operands[2];
12338 HOST_WIDE_INT val = INTVAL (operands[3]);
12339
12340 if (cond_code == GE || cond_code == GT)
12341 {
12342 cond_code = reverse_condition (cond_code);
12343 invert = true;
12344 }
12345
12346 if (cond_code == LE)
12347 val++;
12348
12349 rtx tmp = gen_reg_rtx (<MODE>mode);
12350 emit_insn (gen_add<mode>3 (tmp, op1, GEN_INT (-val)));
12351 rtx x = gen_reg_rtx (<MODE>mode);
12352 if (val < 0)
12353 emit_insn (gen_and<mode>3 (x, op1, tmp));
12354 else
12355 emit_insn (gen_ior<mode>3 (x, op1, tmp));
12356
12357 if (invert)
12358 {
12359 rtx tmp = gen_reg_rtx (<MODE>mode);
12360 emit_insn (gen_one_cmpl<mode>2 (tmp, x));
12361 x = tmp;
12362 }
12363
12364 int sh = GET_MODE_BITSIZE (<MODE>mode) - 1;
12365 emit_insn (gen_lshr<mode>3 (op0, x, GEN_INT (sh)));
12366
12367 DONE;
12368 })
12369
12370 (define_expand "cstore<mode>4_unsigned_imm"
12371 [(use (match_operator 1 "unsigned_comparison_operator"
12372 [(match_operand:GPR 2 "gpc_reg_operand")
12373 (match_operand:GPR 3 "immediate_operand")]))
12374 (clobber (match_operand:GPR 0 "gpc_reg_operand"))]
12375 ""
12376 {
12377 bool invert = false;
12378
12379 enum rtx_code cond_code = GET_CODE (operands[1]);
12380
12381 rtx op0 = operands[0];
12382 rtx op1 = operands[2];
12383 HOST_WIDE_INT val = INTVAL (operands[3]);
12384
12385 if (cond_code == GEU || cond_code == GTU)
12386 {
12387 cond_code = reverse_condition (cond_code);
12388 invert = true;
12389 }
12390
12391 if (cond_code == LEU)
12392 val++;
12393
12394 rtx tmp = gen_reg_rtx (<MODE>mode);
12395 rtx tmp2 = gen_reg_rtx (<MODE>mode);
12396 emit_insn (gen_add<mode>3 (tmp, op1, GEN_INT (-val)));
12397 emit_insn (gen_one_cmpl<mode>2 (tmp2, op1));
12398 rtx x = gen_reg_rtx (<MODE>mode);
12399 if (val < 0)
12400 emit_insn (gen_ior<mode>3 (x, tmp, tmp2));
12401 else
12402 emit_insn (gen_and<mode>3 (x, tmp, tmp2));
12403
12404 if (invert)
12405 {
12406 rtx tmp = gen_reg_rtx (<MODE>mode);
12407 emit_insn (gen_one_cmpl<mode>2 (tmp, x));
12408 x = tmp;
12409 }
12410
12411 int sh = GET_MODE_BITSIZE (<MODE>mode) - 1;
12412 emit_insn (gen_lshr<mode>3 (op0, x, GEN_INT (sh)));
12413
12414 DONE;
12415 })
12416
12417 (define_expand "cstore<mode>4"
12418 [(use (match_operator 1 "comparison_operator"
12419 [(match_operand:GPR 2 "gpc_reg_operand")
12420 (match_operand:GPR 3 "reg_or_short_operand")]))
12421 (clobber (match_operand:GPR 0 "gpc_reg_operand"))]
12422 ""
12423 {
12424 /* Everything is best done with setbc[r] if available. */
12425 if (TARGET_POWER10 && TARGET_ISEL)
12426 {
12427 rs6000_emit_int_cmove (operands[0], operands[1], const1_rtx, const0_rtx);
12428 DONE;
12429 }
12430
12431 /* Expanding EQ and NE directly to some machine instructions does not help
12432 but does hurt combine. So don't. */
12433 if (GET_CODE (operands[1]) == EQ)
12434 emit_insn (gen_eq<mode>3 (operands[0], operands[2], operands[3]));
12435 else if (<MODE>mode == Pmode
12436 && GET_CODE (operands[1]) == NE)
12437 emit_insn (gen_ne<mode>3 (operands[0], operands[2], operands[3]));
12438 else if (GET_CODE (operands[1]) == NE)
12439 {
12440 rtx tmp = gen_reg_rtx (<MODE>mode);
12441 emit_insn (gen_eq<mode>3 (tmp, operands[2], operands[3]));
12442 emit_insn (gen_xor<mode>3 (operands[0], tmp, const1_rtx));
12443 }
12444
12445 /* If ISEL is fast, expand to it. */
12446 else if (TARGET_ISEL)
12447 rs6000_emit_int_cmove (operands[0], operands[1], const1_rtx, const0_rtx);
12448
12449 /* Expanding the unsigned comparisons helps a lot: all the neg_ltu
12450 etc. combinations magically work out just right. */
12451 else if (<MODE>mode == Pmode
12452 && unsigned_comparison_operator (operands[1], VOIDmode))
12453 emit_insn (gen_cstore<mode>4_unsigned (operands[0], operands[1],
12454 operands[2], operands[3]));
12455
12456 /* For comparisons smaller than Pmode we can cheaply do things in Pmode. */
12457 else if (<MODE>mode == SImode && Pmode == DImode)
12458 emit_insn (gen_cstore_si_as_di (operands[0], operands[1],
12459 operands[2], operands[3]));
12460
12461 /* For signed comparisons against a constant, we can do some simple
12462 bit-twiddling. */
12463 else if (signed_comparison_operator (operands[1], VOIDmode)
12464 && CONST_INT_P (operands[3]))
12465 emit_insn (gen_cstore<mode>4_signed_imm (operands[0], operands[1],
12466 operands[2], operands[3]));
12467
12468 /* And similarly for unsigned comparisons. */
12469 else if (unsigned_comparison_operator (operands[1], VOIDmode)
12470 && CONST_INT_P (operands[3]))
12471 emit_insn (gen_cstore<mode>4_unsigned_imm (operands[0], operands[1],
12472 operands[2], operands[3]));
12473
12474 /* We also do not want to use mfcr for signed comparisons. */
12475 else if (<MODE>mode == Pmode
12476 && signed_comparison_operator (operands[1], VOIDmode))
12477 emit_insn (gen_cstore<mode>4_signed (operands[0], operands[1],
12478 operands[2], operands[3]));
12479
12480 /* Everything else, use the mfcr brute force. */
12481 else
12482 rs6000_emit_sCOND (<MODE>mode, operands);
12483
12484 DONE;
12485 })
12486
12487 (define_expand "cstore<mode>4"
12488 [(use (match_operator 1 "comparison_operator"
12489 [(match_operand:FP 2 "gpc_reg_operand")
12490 (match_operand:FP 3 "gpc_reg_operand")]))
12491 (clobber (match_operand:SI 0 "gpc_reg_operand"))]
12492 ""
12493 {
12494 rs6000_emit_sCOND (<MODE>mode, operands);
12495 DONE;
12496 })
12497
12498
12499 (define_expand "stack_protect_set"
12500 [(match_operand 0 "memory_operand")
12501 (match_operand 1 "memory_operand")]
12502 ""
12503 {
12504 if (rs6000_stack_protector_guard == SSP_TLS)
12505 {
12506 rtx reg = gen_rtx_REG (Pmode, rs6000_stack_protector_guard_reg);
12507 rtx offset = GEN_INT (rs6000_stack_protector_guard_offset);
12508 rtx addr = gen_rtx_PLUS (Pmode, reg, offset);
12509 operands[1] = gen_rtx_MEM (Pmode, addr);
12510 }
12511
12512 if (TARGET_64BIT)
12513 emit_insn (gen_stack_protect_setdi (operands[0], operands[1]));
12514 else
12515 emit_insn (gen_stack_protect_setsi (operands[0], operands[1]));
12516
12517 DONE;
12518 })
12519
12520 ;; We can't use the prefixed attribute here because there are two memory
12521 ;; instructions. We can't split the insn due to the fact that this operation
12522 ;; needs to be done in one piece.
12523 (define_insn "stack_protect_set<mode>"
12524 [(set (match_operand:P 0 "memory_operand" "=YZ")
12525 (unspec:P [(match_operand:P 1 "memory_operand" "YZ")] UNSPEC_SP_SET))
12526 (set (match_scratch:P 2 "=&r") (const_int 0))]
12527 ""
12528 {
12529 if (prefixed_memory (operands[1], <MODE>mode))
12530 /* Prefixed load only supports D-form but no update and X-form. */
12531 output_asm_insn ("p<ptrload> %2,%1", operands);
12532 else
12533 output_asm_insn ("<ptrload>%U1%X1 %2,%1", operands);
12534
12535 if (prefixed_memory (operands[0], <MODE>mode))
12536 /* Prefixed store only supports D-form but no update and X-form. */
12537 output_asm_insn ("pst<wd> %2,%0", operands);
12538 else
12539 output_asm_insn ("st<wd>%U0%X0 %2,%0", operands);
12540
12541 return "li %2,0";
12542 }
12543 [(set_attr "type" "three")
12544
12545 ;; Back to back prefixed memory instructions take 20 bytes (8 bytes for each
12546 ;; prefixed instruction + 4 bytes for the possible NOP). Add in 4 bytes for
12547 ;; the LI 0 at the end.
12548 (set_attr "prefixed" "no")
12549 (set_attr "num_insns" "3")
12550 (set (attr "length")
12551 (cond [(and (match_operand 0 "prefixed_memory")
12552 (match_operand 1 "prefixed_memory"))
12553 (const_int 24)
12554
12555 (ior (match_operand 0 "prefixed_memory")
12556 (match_operand 1 "prefixed_memory"))
12557 (const_int 20)]
12558
12559 (const_int 12)))])
12560
12561 (define_expand "stack_protect_test"
12562 [(match_operand 0 "memory_operand")
12563 (match_operand 1 "memory_operand")
12564 (match_operand 2 "")]
12565 ""
12566 {
12567 rtx guard = operands[1];
12568
12569 if (rs6000_stack_protector_guard == SSP_TLS)
12570 {
12571 rtx reg = gen_rtx_REG (Pmode, rs6000_stack_protector_guard_reg);
12572 rtx offset = GEN_INT (rs6000_stack_protector_guard_offset);
12573 rtx addr = gen_rtx_PLUS (Pmode, reg, offset);
12574 guard = gen_rtx_MEM (Pmode, addr);
12575 }
12576
12577 operands[1] = gen_rtx_UNSPEC (Pmode, gen_rtvec (1, guard), UNSPEC_SP_TEST);
12578 rtx test = gen_rtx_EQ (VOIDmode, operands[0], operands[1]);
12579 rtx jump = gen_cbranchsi4 (test, operands[0], operands[1], operands[2]);
12580 emit_jump_insn (jump);
12581
12582 DONE;
12583 })
12584
12585 ;; We can't use the prefixed attribute here because there are two memory
12586 ;; instructions. We can't split the insn due to the fact that this operation
12587 ;; needs to be done in one piece.
12588 (define_insn "stack_protect_test<mode>"
12589 [(set (match_operand:CCEQ 0 "cc_reg_operand" "=x,?y")
12590 (unspec:CCEQ [(match_operand:P 1 "memory_operand" "YZ,YZ")
12591 (match_operand:P 2 "memory_operand" "YZ,YZ")]
12592 UNSPEC_SP_TEST))
12593 (set (match_scratch:P 4 "=r,r") (const_int 0))
12594 (clobber (match_scratch:P 3 "=&r,&r"))]
12595 ""
12596 {
12597 if (prefixed_memory (operands[1], <MODE>mode))
12598 /* Prefixed load only supports D-form but no update and X-form. */
12599 output_asm_insn ("p<ptrload> %3,%1", operands);
12600 else
12601 output_asm_insn ("<ptrload>%U1%X1 %3,%1", operands);
12602
12603 if (prefixed_memory (operands[2], <MODE>mode))
12604 output_asm_insn ("p<ptrload> %4,%2", operands);
12605 else
12606 output_asm_insn ("<ptrload>%U2%X2 %4,%2", operands);
12607
12608 if (which_alternative == 0)
12609 output_asm_insn ("xor. %3,%3,%4", operands);
12610 else
12611 output_asm_insn ("cmpl<wd> %0,%3,%4\;li %3,0", operands);
12612
12613 return "li %4,0";
12614 }
12615 ;; Back to back prefixed memory instructions take 20 bytes (8 bytes for each
12616 ;; prefixed instruction + 4 bytes for the possible NOP). Add in either 4 or
12617 ;; 8 bytes to do the test.
12618 [(set_attr "prefixed" "no")
12619 (set_attr "num_insns" "4,5")
12620 (set (attr "length")
12621 (cond [(and (match_operand 1 "prefixed_memory")
12622 (match_operand 2 "prefixed_memory"))
12623 (if_then_else (eq_attr "alternative" "0")
12624 (const_int 28)
12625 (const_int 32))
12626
12627 (ior (match_operand 1 "prefixed_memory")
12628 (match_operand 2 "prefixed_memory"))
12629 (if_then_else (eq_attr "alternative" "0")
12630 (const_int 20)
12631 (const_int 24))]
12632
12633 (if_then_else (eq_attr "alternative" "0")
12634 (const_int 16)
12635 (const_int 20))))])
12636
12637
12638 ;; Here are the actual compare insns.
12639 (define_insn "*cmp<mode>_signed"
12640 [(set (match_operand:CC 0 "cc_reg_operand" "=y")
12641 (compare:CC (match_operand:GPR 1 "gpc_reg_operand" "r")
12642 (match_operand:GPR 2 "reg_or_short_operand" "rI")))]
12643 ""
12644 "cmp<wd>%I2 %0,%1,%2"
12645 [(set_attr "type" "cmp")])
12646
12647 (define_insn "*cmp<mode>_unsigned"
12648 [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
12649 (compare:CCUNS (match_operand:GPR 1 "gpc_reg_operand" "r")
12650 (match_operand:GPR 2 "reg_or_u_short_operand" "rK")))]
12651 ""
12652 "cmpl<wd>%I2 %0,%1,%2"
12653 [(set_attr "type" "cmp")])
12654
12655 ;; If we are comparing a register for equality with a large constant,
12656 ;; we can do this with an XOR followed by a compare. But this is profitable
12657 ;; only if the large constant is only used for the comparison (and in this
12658 ;; case we already have a register to reuse as scratch).
12659 ;;
12660 ;; For 64-bit registers, we could only do so if the constant's bit 15 is clear:
12661 ;; otherwise we'd need to XOR with FFFFFFFF????0000 which is not available.
12662
12663 (define_peephole2
12664 [(set (match_operand:SI 0 "register_operand")
12665 (match_operand:SI 1 "logical_const_operand"))
12666 (set (match_dup 0) (match_operator:SI 3 "boolean_or_operator"
12667 [(match_dup 0)
12668 (match_operand:SI 2 "logical_const_operand")]))
12669 (set (match_operand:CC 4 "cc_reg_operand")
12670 (compare:CC (match_operand:SI 5 "gpc_reg_operand")
12671 (match_dup 0)))
12672 (set (pc)
12673 (if_then_else (match_operator 6 "equality_operator"
12674 [(match_dup 4) (const_int 0)])
12675 (match_operand 7 "")
12676 (match_operand 8 "")))]
12677 "peep2_reg_dead_p (3, operands[0])
12678 && peep2_reg_dead_p (4, operands[4])
12679 && REGNO (operands[0]) != REGNO (operands[5])"
12680 [(set (match_dup 0) (xor:SI (match_dup 5) (match_dup 9)))
12681 (set (match_dup 4) (compare:CC (match_dup 0) (match_dup 10)))
12682 (set (pc) (if_then_else (match_dup 6) (match_dup 7) (match_dup 8)))]
12683
12684 {
12685 /* Get the constant we are comparing against, and see what it looks like
12686 when sign-extended from 16 to 32 bits. Then see what constant we could
12687 XOR with SEXTC to get the sign-extended value. */
12688 rtx cnst = simplify_const_binary_operation (GET_CODE (operands[3]),
12689 SImode,
12690 operands[1], operands[2]);
12691 HOST_WIDE_INT c = INTVAL (cnst);
12692 HOST_WIDE_INT sextc = sext_hwi (c, 16);
12693 HOST_WIDE_INT xorv = c ^ sextc;
12694
12695 operands[9] = GEN_INT (xorv);
12696 operands[10] = GEN_INT (sextc);
12697 })
12698
12699 ;; Only need to compare second words if first words equal
12700 (define_insn "*cmp<mode>_internal1"
12701 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12702 (compare:CCFP (match_operand:IBM128 1 "gpc_reg_operand" "d")
12703 (match_operand:IBM128 2 "gpc_reg_operand" "d")))]
12704 "!TARGET_XL_COMPAT
12705 && TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128"
12706 "fcmpu %0,%1,%2\;bne %0,$+8\;fcmpu %0,%L1,%L2"
12707 [(set_attr "type" "fpcompare")
12708 (set_attr "length" "12")])
12709
12710 (define_insn_and_split "*cmp<IBM128:mode>_internal2"
12711 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
12712 (compare:CCFP (match_operand:IBM128 1 "gpc_reg_operand" "d")
12713 (match_operand:IBM128 2 "gpc_reg_operand" "d")))
12714 (clobber (match_scratch:DF 3 "=d"))
12715 (clobber (match_scratch:DF 4 "=d"))
12716 (clobber (match_scratch:DF 5 "=d"))
12717 (clobber (match_scratch:DF 6 "=d"))
12718 (clobber (match_scratch:DF 7 "=d"))
12719 (clobber (match_scratch:DF 8 "=d"))
12720 (clobber (match_scratch:DF 9 "=d"))
12721 (clobber (match_scratch:DF 10 "=d"))
12722 (clobber (match_scratch:GPR 11 "=b"))]
12723 "TARGET_XL_COMPAT
12724 && TARGET_HARD_FLOAT && TARGET_LONG_DOUBLE_128"
12725 "#"
12726 "&& reload_completed"
12727 [(set (match_dup 3) (match_dup 14))
12728 (set (match_dup 4) (match_dup 15))
12729 (set (match_dup 9) (abs:DF (match_dup 5)))
12730 (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 3)))
12731 (set (pc) (if_then_else (ne (match_dup 0) (const_int 0))
12732 (label_ref (match_dup 12))
12733 (pc)))
12734 (set (match_dup 0) (compare:CCFP (match_dup 5) (match_dup 7)))
12735 (set (pc) (label_ref (match_dup 13)))
12736 (match_dup 12)
12737 (set (match_dup 10) (minus:DF (match_dup 5) (match_dup 7)))
12738 (set (match_dup 9) (minus:DF (match_dup 6) (match_dup 8)))
12739 (set (match_dup 9) (plus:DF (match_dup 10) (match_dup 9)))
12740 (set (match_dup 0) (compare:CCFP (match_dup 9) (match_dup 4)))
12741 (match_dup 13)]
12742 {
12743 REAL_VALUE_TYPE rv;
12744 const int lo_word = LONG_DOUBLE_LARGE_FIRST ? GET_MODE_SIZE (DFmode) : 0;
12745 const int hi_word = LONG_DOUBLE_LARGE_FIRST ? 0 : GET_MODE_SIZE (DFmode);
12746
12747 operands[5] = simplify_gen_subreg (DFmode, operands[1],
12748 <IBM128:MODE>mode, hi_word);
12749 operands[6] = simplify_gen_subreg (DFmode, operands[1],
12750 <IBM128:MODE>mode, lo_word);
12751 operands[7] = simplify_gen_subreg (DFmode, operands[2],
12752 <IBM128:MODE>mode, hi_word);
12753 operands[8] = simplify_gen_subreg (DFmode, operands[2],
12754 <IBM128:MODE>mode, lo_word);
12755 operands[12] = gen_label_rtx ();
12756 operands[13] = gen_label_rtx ();
12757 real_inf (&rv);
12758 operands[14] = force_const_mem (DFmode,
12759 const_double_from_real_value (rv, DFmode));
12760 operands[15] = force_const_mem (DFmode,
12761 const_double_from_real_value (dconst0,
12762 DFmode));
12763 if (TARGET_TOC)
12764 {
12765 rtx tocref;
12766 tocref = create_TOC_reference (XEXP (operands[14], 0), operands[11]);
12767 operands[14] = gen_const_mem (DFmode, tocref);
12768 tocref = create_TOC_reference (XEXP (operands[15], 0), operands[11]);
12769 operands[15] = gen_const_mem (DFmode, tocref);
12770 set_mem_alias_set (operands[14], get_TOC_alias_set ());
12771 set_mem_alias_set (operands[15], get_TOC_alias_set ());
12772 }
12773 })
12774
12775 ;; Now we have the scc insns. We can do some combinations because of the
12776 ;; way the machine works.
12777 ;;
12778 ;; Note that this is probably faster if we can put an insn between the
12779 ;; mfcr and rlinm, but this is tricky. Let's leave it for now. In most
12780 ;; cases the insns below which don't use an intermediate CR field will
12781 ;; be used instead.
12782 (define_insn "set<mode>_cc"
12783 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12784 (match_operator:GPR 1 "scc_comparison_operator"
12785 [(match_operand 2 "cc_reg_operand" "y")
12786 (const_int 0)]))]
12787 ""
12788 "mfcr %0%Q2\;rlwinm %0,%0,%J1,1"
12789 [(set (attr "type")
12790 (cond [(match_test "TARGET_MFCRF")
12791 (const_string "mfcrf")
12792 ]
12793 (const_string "mfcr")))
12794 (set_attr "length" "8")])
12795
12796
12797 (define_code_iterator cmp [eq ne lt ltu gt gtu le leu ge geu])
12798 (define_code_attr UNS [(eq "CC")
12799 (ne "CC")
12800 (lt "CC") (ltu "CCUNS")
12801 (gt "CC") (gtu "CCUNS")
12802 (le "CC") (leu "CCUNS")
12803 (ge "CC") (geu "CCUNS")])
12804 (define_code_attr UNSu_ [(eq "")
12805 (ne "")
12806 (lt "") (ltu "u_")
12807 (gt "") (gtu "u_")
12808 (le "") (leu "u_")
12809 (ge "") (geu "u_")])
12810 (define_code_attr UNSIK [(eq "I")
12811 (ne "I")
12812 (lt "I") (ltu "K")
12813 (gt "I") (gtu "K")
12814 (le "I") (leu "K")
12815 (ge "I") (geu "K")])
12816
12817 (define_insn_and_split "<code><GPR:mode><GPR2:mode>2_isel"
12818 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12819 (cmp:GPR (match_operand:GPR2 1 "gpc_reg_operand" "r")
12820 (match_operand:GPR2 2 "reg_or_<cmp:UNSu_>short_operand" "r<cmp:UNSIK>")))
12821 (clobber (match_scratch:GPR 3 "=r"))
12822 (clobber (match_scratch:GPR 4 "=r"))
12823 (clobber (match_scratch:<UNS> 5 "=y"))]
12824 "!TARGET_POWER10 && TARGET_ISEL
12825 && !(<CODE> == EQ && operands[2] == const0_rtx)
12826 && !(<CODE> == NE && operands[2] == const0_rtx
12827 && <GPR:MODE>mode == Pmode && <GPR2:MODE>mode == Pmode)"
12828 "#"
12829 "&& 1"
12830 [(pc)]
12831 {
12832 rtx_code code = <CODE>;
12833 if (CONST_INT_P (operands[2]) && code != EQ && code != NE)
12834 {
12835 HOST_WIDE_INT val = INTVAL (operands[2]);
12836 if (code == LT && val != -0x8000)
12837 {
12838 code = LE;
12839 val--;
12840 }
12841 if (code == GT && val != 0x7fff)
12842 {
12843 code = GE;
12844 val++;
12845 }
12846 if (code == LTU && val != 0)
12847 {
12848 code = LEU;
12849 val--;
12850 }
12851 if (code == GTU && val != 0xffff)
12852 {
12853 code = GEU;
12854 val++;
12855 }
12856 operands[2] = GEN_INT (val);
12857 }
12858
12859 if (code == NE || code == LE || code == GE || code == LEU || code == GEU)
12860 operands[3] = const0_rtx;
12861 else
12862 {
12863 if (GET_CODE (operands[3]) == SCRATCH)
12864 operands[3] = gen_reg_rtx (<GPR:MODE>mode);
12865 emit_move_insn (operands[3], const0_rtx);
12866 }
12867
12868 if (GET_CODE (operands[4]) == SCRATCH)
12869 operands[4] = gen_reg_rtx (<GPR:MODE>mode);
12870 emit_move_insn (operands[4], const1_rtx);
12871
12872 if (GET_CODE (operands[5]) == SCRATCH)
12873 operands[5] = gen_reg_rtx (<UNS>mode);
12874
12875 rtx c1 = gen_rtx_COMPARE (<UNS>mode, operands[1], operands[2]);
12876 emit_insn (gen_rtx_SET (operands[5], c1));
12877
12878 rtx c2 = gen_rtx_fmt_ee (code, <GPR:MODE>mode, operands[5], const0_rtx);
12879 rtx x = gen_rtx_IF_THEN_ELSE (<GPR:MODE>mode, c2, operands[4], operands[3]);
12880 emit_move_insn (operands[0], x);
12881
12882 DONE;
12883 }
12884 [(set (attr "cost")
12885 (if_then_else (match_test "(CONST_INT_P (operands[2]) && <CODE> != EQ)
12886 || <CODE> == NE
12887 || <CODE> == LE || <CODE> == GE
12888 || <CODE> == LEU || <CODE> == GEU")
12889 (const_string "9")
12890 (const_string "10")))])
12891
12892 (define_mode_attr scc_eq_op2 [(SI "rKLI")
12893 (DI "rKJI")])
12894
12895 (define_expand "eq<mode>3"
12896 [(parallel [
12897 (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12898 (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
12899 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))
12900 (clobber (match_scratch:GPR 3 "=r"))
12901 (clobber (match_scratch:GPR 4 "=r"))])]
12902 ""
12903 {
12904 if (TARGET_POWER10)
12905 {
12906 rtx cc = gen_reg_rtx (CCmode);
12907 rtx compare = gen_rtx_COMPARE (CCmode, operands[1], operands[2]);
12908 emit_insn (gen_rtx_SET (cc, compare));
12909 rtx eq = gen_rtx_fmt_ee (EQ, <MODE>mode, cc, const0_rtx);
12910 emit_insn (gen_setbc_cc_<mode> (operands[0], eq, cc));
12911 DONE;
12912 }
12913
12914 if (TARGET_ISEL && operands[2] != const0_rtx)
12915 {
12916 emit_insn (gen_eq<mode><mode>2_isel (operands[0], operands[1],
12917 operands[2]));
12918 DONE;
12919 }
12920 })
12921
12922 (define_insn_and_split "*eq<mode>3"
12923 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12924 (eq:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
12925 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))
12926 (clobber (match_scratch:GPR 3 "=r"))
12927 (clobber (match_scratch:GPR 4 "=r"))]
12928 "!TARGET_POWER10 && !(TARGET_ISEL && operands[2] != const0_rtx)"
12929 "#"
12930 "&& 1"
12931 [(set (match_dup 4)
12932 (clz:GPR (match_dup 3)))
12933 (set (match_dup 0)
12934 (lshiftrt:GPR (match_dup 4)
12935 (match_dup 5)))]
12936 {
12937 operands[3] = rs6000_emit_eqne (<MODE>mode,
12938 operands[1], operands[2], operands[3]);
12939
12940 if (GET_CODE (operands[4]) == SCRATCH)
12941 operands[4] = gen_reg_rtx (<MODE>mode);
12942
12943 operands[5] = GEN_INT (exact_log2 (GET_MODE_BITSIZE (<MODE>mode)));
12944 }
12945 [(set (attr "length")
12946 (if_then_else (match_test "operands[2] == const0_rtx")
12947 (const_string "8")
12948 (const_string "12")))])
12949
12950 (define_expand "ne<mode>3"
12951 [(parallel [
12952 (set (match_operand:GPR 0 "gpc_reg_operand" "=r")
12953 (ne:GPR (match_operand:GPR 1 "gpc_reg_operand" "r")
12954 (match_operand:GPR 2 "scc_eq_operand" "<scc_eq_op2>")))
12955 (clobber (match_scratch:GPR 3 "=r"))
12956 (clobber (match_scratch:GPR 4 "=r"))
12957 (clobber (reg:GPR CA_REGNO))])]
12958 ""
12959 {
12960 if (TARGET_POWER10)
12961 {
12962 rtx cc = gen_reg_rtx (CCmode);
12963 rtx compare = gen_rtx_COMPARE (CCmode, operands[1], operands[2]);
12964 emit_insn (gen_rtx_SET (cc, compare));
12965 rtx ne = gen_rtx_fmt_ee (NE, <MODE>mode, cc, const0_rtx);
12966 emit_insn (gen_setbc_cc_<mode> (operands[0], ne, cc));
12967 DONE;
12968 }
12969
12970 if (<MODE>mode != Pmode)
12971 {
12972 rtx x = gen_reg_rtx (<MODE>mode);
12973 emit_insn (gen_eq<mode>3 (x, operands[1], operands[2]));
12974 emit_insn (gen_xor<mode>3 (operands[0], x, const1_rtx));
12975 DONE;
12976 }
12977
12978 if (TARGET_ISEL && operands[2] != const0_rtx)
12979 {
12980 emit_insn (gen_ne<mode><mode>2_isel (operands[0], operands[1],
12981 operands[2]));
12982 DONE;
12983 }
12984 })
12985
12986 (define_insn_and_split "*ne<mode>3"
12987 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
12988 (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
12989 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>")))
12990 (clobber (match_scratch:P 3 "=r"))
12991 (clobber (match_scratch:P 4 "=r"))
12992 (clobber (reg:P CA_REGNO))]
12993 "!TARGET_POWER10 && !(TARGET_ISEL && operands[2] != const0_rtx)"
12994 "#"
12995 "&& 1"
12996 [(parallel [(set (match_dup 4)
12997 (plus:P (match_dup 3)
12998 (const_int -1)))
12999 (set (reg:P CA_REGNO)
13000 (ne:P (match_dup 3)
13001 (const_int 0)))])
13002 (parallel [(set (match_dup 0)
13003 (plus:P (plus:P (not:P (match_dup 4))
13004 (reg:P CA_REGNO))
13005 (match_dup 3)))
13006 (clobber (reg:P CA_REGNO))])]
13007 {
13008 operands[3] = rs6000_emit_eqne (<MODE>mode,
13009 operands[1], operands[2], operands[3]);
13010
13011 if (GET_CODE (operands[4]) == SCRATCH)
13012 operands[4] = gen_reg_rtx (<MODE>mode);
13013 }
13014 [(set (attr "length")
13015 (if_then_else (match_test "operands[2] == const0_rtx")
13016 (const_string "8")
13017 (const_string "12")))])
13018
13019 (define_insn_and_split "*neg_eq_<mode>"
13020 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13021 (neg:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13022 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))
13023 (clobber (match_scratch:P 3 "=r"))
13024 (clobber (match_scratch:P 4 "=r"))
13025 (clobber (reg:P CA_REGNO))]
13026 "!TARGET_POWER10"
13027 "#"
13028 "&& 1"
13029 [(parallel [(set (match_dup 4)
13030 (plus:P (match_dup 3)
13031 (const_int -1)))
13032 (set (reg:P CA_REGNO)
13033 (ne:P (match_dup 3)
13034 (const_int 0)))])
13035 (parallel [(set (match_dup 0)
13036 (plus:P (reg:P CA_REGNO)
13037 (const_int -1)))
13038 (clobber (reg:P CA_REGNO))])]
13039 {
13040 operands[3] = rs6000_emit_eqne (<MODE>mode,
13041 operands[1], operands[2], operands[3]);
13042
13043 if (GET_CODE (operands[4]) == SCRATCH)
13044 operands[4] = gen_reg_rtx (<MODE>mode);
13045 }
13046 [(set (attr "length")
13047 (if_then_else (match_test "operands[2] == const0_rtx")
13048 (const_string "8")
13049 (const_string "12")))])
13050
13051 (define_insn_and_split "*neg_ne_<mode>"
13052 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13053 (neg:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13054 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))
13055 (clobber (match_scratch:P 3 "=r"))
13056 (clobber (match_scratch:P 4 "=r"))
13057 (clobber (reg:P CA_REGNO))]
13058 "!TARGET_POWER10"
13059 "#"
13060 "&& 1"
13061 [(parallel [(set (match_dup 4)
13062 (neg:P (match_dup 3)))
13063 (set (reg:P CA_REGNO)
13064 (eq:P (match_dup 3)
13065 (const_int 0)))])
13066 (parallel [(set (match_dup 0)
13067 (plus:P (reg:P CA_REGNO)
13068 (const_int -1)))
13069 (clobber (reg:P CA_REGNO))])]
13070 {
13071 operands[3] = rs6000_emit_eqne (<MODE>mode,
13072 operands[1], operands[2], operands[3]);
13073
13074 if (GET_CODE (operands[4]) == SCRATCH)
13075 operands[4] = gen_reg_rtx (<MODE>mode);
13076 }
13077 [(set (attr "length")
13078 (if_then_else (match_test "operands[2] == const0_rtx")
13079 (const_string "8")
13080 (const_string "12")))])
13081
13082 (define_insn_and_split "*plus_eq_<mode>"
13083 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13084 (plus:P (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13085 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13086 (match_operand:P 3 "gpc_reg_operand" "r")))
13087 (clobber (match_scratch:P 4 "=r"))
13088 (clobber (match_scratch:P 5 "=r"))
13089 (clobber (reg:P CA_REGNO))]
13090 ""
13091 "#"
13092 ""
13093 [(parallel [(set (match_dup 5)
13094 (neg:P (match_dup 4)))
13095 (set (reg:P CA_REGNO)
13096 (eq:P (match_dup 4)
13097 (const_int 0)))])
13098 (parallel [(set (match_dup 0)
13099 (plus:P (match_dup 3)
13100 (reg:P CA_REGNO)))
13101 (clobber (reg:P CA_REGNO))])]
13102 {
13103 operands[4] = rs6000_emit_eqne (<MODE>mode,
13104 operands[1], operands[2], operands[4]);
13105
13106 if (GET_CODE (operands[5]) == SCRATCH)
13107 operands[5] = gen_reg_rtx (<MODE>mode);
13108 }
13109 [(set (attr "length")
13110 (if_then_else (match_test "operands[2] == const0_rtx")
13111 (const_string "8")
13112 (const_string "12")))])
13113
13114 (define_insn_and_split "*plus_ne_<mode>"
13115 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13116 (plus:P (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13117 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))
13118 (match_operand:P 3 "gpc_reg_operand" "r")))
13119 (clobber (match_scratch:P 4 "=r"))
13120 (clobber (match_scratch:P 5 "=r"))
13121 (clobber (reg:P CA_REGNO))]
13122 ""
13123 "#"
13124 ""
13125 [(parallel [(set (match_dup 5)
13126 (plus:P (match_dup 4)
13127 (const_int -1)))
13128 (set (reg:P CA_REGNO)
13129 (ne:P (match_dup 4)
13130 (const_int 0)))])
13131 (parallel [(set (match_dup 0)
13132 (plus:P (match_dup 3)
13133 (reg:P CA_REGNO)))
13134 (clobber (reg:P CA_REGNO))])]
13135 {
13136 operands[4] = rs6000_emit_eqne (<MODE>mode,
13137 operands[1], operands[2], operands[4]);
13138
13139 if (GET_CODE (operands[5]) == SCRATCH)
13140 operands[5] = gen_reg_rtx (<MODE>mode);
13141 }
13142 [(set (attr "length")
13143 (if_then_else (match_test "operands[2] == const0_rtx")
13144 (const_string "8")
13145 (const_string "12")))])
13146
13147 (define_insn_and_split "*minus_eq_<mode>"
13148 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13149 (minus:P (match_operand:P 3 "gpc_reg_operand" "r")
13150 (eq:P (match_operand:P 1 "gpc_reg_operand" "r")
13151 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))
13152 (clobber (match_scratch:P 4 "=r"))
13153 (clobber (match_scratch:P 5 "=r"))
13154 (clobber (reg:P CA_REGNO))]
13155 ""
13156 "#"
13157 ""
13158 [(parallel [(set (match_dup 5)
13159 (plus:P (match_dup 4)
13160 (const_int -1)))
13161 (set (reg:P CA_REGNO)
13162 (ne:P (match_dup 4)
13163 (const_int 0)))])
13164 (parallel [(set (match_dup 0)
13165 (plus:P (plus:P (match_dup 3)
13166 (reg:P CA_REGNO))
13167 (const_int -1)))
13168 (clobber (reg:P CA_REGNO))])]
13169 {
13170 operands[4] = rs6000_emit_eqne (<MODE>mode,
13171 operands[1], operands[2], operands[4]);
13172
13173 if (GET_CODE (operands[5]) == SCRATCH)
13174 operands[5] = gen_reg_rtx (<MODE>mode);
13175 }
13176 [(set (attr "length")
13177 (if_then_else (match_test "operands[2] == const0_rtx")
13178 (const_string "8")
13179 (const_string "12")))])
13180
13181 (define_insn_and_split "*minus_ne_<mode>"
13182 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
13183 (minus:P (match_operand:P 3 "gpc_reg_operand" "r")
13184 (ne:P (match_operand:P 1 "gpc_reg_operand" "r")
13185 (match_operand:P 2 "scc_eq_operand" "<scc_eq_op2>"))))
13186 (clobber (match_scratch:P 4 "=r"))
13187 (clobber (match_scratch:P 5 "=r"))
13188 (clobber (reg:P CA_REGNO))]
13189 ""
13190 "#"
13191 ""
13192 [(parallel [(set (match_dup 5)
13193 (neg:P (match_dup 4)))
13194 (set (reg:P CA_REGNO)
13195 (eq:P (match_dup 4)
13196 (const_int 0)))])
13197 (parallel [(set (match_dup 0)
13198 (plus:P (plus:P (match_dup 3)
13199 (reg:P CA_REGNO))
13200 (const_int -1)))
13201 (clobber (reg:P CA_REGNO))])]
13202 {
13203 operands[4] = rs6000_emit_eqne (<MODE>mode,
13204 operands[1], operands[2], operands[4]);
13205
13206 if (GET_CODE (operands[5]) == SCRATCH)
13207 operands[5] = gen_reg_rtx (<MODE>mode);
13208 }
13209 [(set (attr "length")
13210 (if_then_else (match_test "operands[2] == const0_rtx")
13211 (const_string "8")
13212 (const_string "12")))])
13213
13214 (define_insn_and_split "*eqsi3_ext<mode>"
13215 [(set (match_operand:EXTSI 0 "gpc_reg_operand" "=r")
13216 (eq:EXTSI (match_operand:SI 1 "gpc_reg_operand" "r")
13217 (match_operand:SI 2 "scc_eq_operand" "rKLI")))
13218 (clobber (match_scratch:SI 3 "=r"))
13219 (clobber (match_scratch:SI 4 "=r"))]
13220 "!TARGET_POWER10"
13221 "#"
13222 "&& 1"
13223 [(set (match_dup 4)
13224 (clz:SI (match_dup 3)))
13225 (set (match_dup 0)
13226 (zero_extend:EXTSI
13227 (lshiftrt:SI (match_dup 4)
13228 (const_int 5))))]
13229 {
13230 operands[3] = rs6000_emit_eqne (SImode,
13231 operands[1], operands[2], operands[3]);
13232
13233 if (GET_CODE (operands[4]) == SCRATCH)
13234 operands[4] = gen_reg_rtx (SImode);
13235 }
13236 [(set (attr "length")
13237 (if_then_else (match_test "operands[2] == const0_rtx")
13238 (const_string "8")
13239 (const_string "12")))])
13240
13241 (define_insn_and_split "*nesi3_ext<mode>"
13242 [(set (match_operand:EXTSI 0 "gpc_reg_operand" "=r")
13243 (ne:EXTSI (match_operand:SI 1 "gpc_reg_operand" "r")
13244 (match_operand:SI 2 "scc_eq_operand" "rKLI")))
13245 (clobber (match_scratch:SI 3 "=r"))
13246 (clobber (match_scratch:SI 4 "=r"))
13247 (clobber (match_scratch:EXTSI 5 "=r"))]
13248 "!TARGET_ISEL"
13249 "#"
13250 "&& 1"
13251 [(set (match_dup 4)
13252 (clz:SI (match_dup 3)))
13253 (set (match_dup 5)
13254 (zero_extend:EXTSI
13255 (lshiftrt:SI (match_dup 4)
13256 (const_int 5))))
13257 (set (match_dup 0)
13258 (xor:EXTSI (match_dup 5)
13259 (const_int 1)))]
13260 {
13261 operands[3] = rs6000_emit_eqne (SImode,
13262 operands[1], operands[2], operands[3]);
13263
13264 if (GET_CODE (operands[4]) == SCRATCH)
13265 operands[4] = gen_reg_rtx (SImode);
13266 if (GET_CODE (operands[5]) == SCRATCH)
13267 operands[5] = gen_reg_rtx (<MODE>mode);
13268 }
13269 [(set (attr "length")
13270 (if_then_else (match_test "operands[2] == const0_rtx")
13271 (const_string "12")
13272 (const_string "16")))])
13273
13274
13275 (define_code_iterator fp_rev [ordered ne unle unge])
13276 (define_code_iterator fp_two [ltgt le ge unlt ungt uneq])
13277
13278 (define_insn_and_split "*<code><mode>_cc"
13279 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13280 (fp_rev:GPR (match_operand:CCFP 1 "cc_reg_operand" "y")
13281 (const_int 0)))]
13282 "!flag_finite_math_only"
13283 "#"
13284 "&& 1"
13285 [(pc)]
13286 {
13287 rtx_code revcode = reverse_condition_maybe_unordered (<CODE>);
13288 rtx eq = gen_rtx_fmt_ee (revcode, <MODE>mode, operands[1], const0_rtx);
13289 rtx tmp = gen_reg_rtx (<MODE>mode);
13290 emit_move_insn (tmp, eq);
13291 emit_insn (gen_xor<mode>3 (operands[0], tmp, const1_rtx));
13292 DONE;
13293 }
13294 [(set_attr "length" "12")])
13295
13296 (define_insn_and_split "*<code><mode>_cc"
13297 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
13298 (fp_two:GPR (match_operand:CCFP 1 "cc_reg_operand" "y")
13299 (const_int 0)))]
13300 "!flag_finite_math_only"
13301 "#"
13302 "&& 1"
13303 [(pc)]
13304 {
13305 rtx cc = rs6000_emit_fp_cror (<CODE>, <MODE>mode, operands[1]);
13306
13307 emit_move_insn (operands[0], gen_rtx_EQ (<MODE>mode, cc, const0_rtx));
13308 DONE;
13309 }
13310 [(set_attr "length" "12")])
13311
13312 ;; Conditional branches.
13313 ;; These either are a single bc insn, or a bc around a b.
13314
13315 (define_insn "*cbranch"
13316 [(set (pc)
13317 (if_then_else (match_operator 1 "branch_comparison_operator"
13318 [(match_operand 2 "cc_reg_operand" "y")
13319 (const_int 0)])
13320 (label_ref (match_operand 0))
13321 (pc)))]
13322 ""
13323 {
13324 return output_cbranch (operands[1], "%l0", 0, insn);
13325 }
13326 [(set_attr "type" "branch")
13327 (set (attr "length")
13328 (if_then_else (and (ge (minus (match_dup 0) (pc))
13329 (const_int -32768))
13330 (lt (minus (match_dup 0) (pc))
13331 (const_int 32764)))
13332 (const_int 4)
13333 (const_int 8)))])
13334
13335 (define_insn_and_split "*cbranch_2insn"
13336 [(set (pc)
13337 (if_then_else (match_operator 1 "extra_insn_branch_comparison_operator"
13338 [(match_operand 2 "cc_reg_operand" "y")
13339 (const_int 0)])
13340 (label_ref (match_operand 0))
13341 (pc)))]
13342 "!flag_finite_math_only"
13343 "#"
13344 "&& 1"
13345 [(pc)]
13346 {
13347 rtx cc = rs6000_emit_fp_cror (GET_CODE (operands[1]), SImode, operands[2]);
13348
13349 rtx note = find_reg_note (curr_insn, REG_BR_PROB, 0);
13350
13351 rtx loc_ref = gen_rtx_LABEL_REF (VOIDmode, operands[0]);
13352 rtx cond = gen_rtx_EQ (CCEQmode, cc, const0_rtx);
13353 rtx ite = gen_rtx_IF_THEN_ELSE (VOIDmode, cond, loc_ref, pc_rtx);
13354 emit_jump_insn (gen_rtx_SET (pc_rtx, ite));
13355
13356 if (note)
13357 {
13358 profile_probability prob
13359 = profile_probability::from_reg_br_prob_note (XINT (note, 0));
13360
13361 add_reg_br_prob_note (get_last_insn (), prob);
13362 }
13363
13364 DONE;
13365 }
13366 [(set_attr "type" "branch")
13367 (set (attr "length")
13368 (if_then_else (and (ge (minus (match_dup 0) (pc))
13369 (const_int -32764))
13370 (lt (minus (match_dup 0) (pc))
13371 (const_int 32760)))
13372 (const_int 8)
13373 (const_int 16)))])
13374
13375 ;; Conditional return.
13376 (define_insn "*creturn"
13377 [(set (pc)
13378 (if_then_else (match_operator 0 "branch_comparison_operator"
13379 [(match_operand 1 "cc_reg_operand" "y")
13380 (const_int 0)])
13381 (any_return)
13382 (pc)))]
13383 "<return_pred>"
13384 {
13385 return output_cbranch (operands[0], NULL, 0, insn);
13386 }
13387 [(set_attr "type" "jmpreg")])
13388
13389 ;; Logic on condition register values.
13390
13391 ; This pattern matches things like
13392 ; (set (reg:CCEQ 68) (compare:CCEQ (ior:SI (gt:SI (reg:CCFP 68) (const_int 0))
13393 ; (eq:SI (reg:CCFP 68) (const_int 0)))
13394 ; (const_int 1)))
13395 ; which are generated by the branch logic.
13396 ; Prefer destructive operations where BT = BB (for crXX BT,BA,BB)
13397
13398 (define_insn "@cceq_ior_compare_<mode>"
13399 [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13400 (compare:CCEQ (match_operator:GPR 1 "boolean_operator"
13401 [(match_operator:GPR 2
13402 "branch_positive_comparison_operator"
13403 [(match_operand 3
13404 "cc_reg_operand" "y,y")
13405 (const_int 0)])
13406 (match_operator:GPR 4
13407 "branch_positive_comparison_operator"
13408 [(match_operand 5
13409 "cc_reg_operand" "0,y")
13410 (const_int 0)])])
13411 (const_int 1)))]
13412 ""
13413 "cr%q1 %E0,%j2,%j4"
13414 [(set_attr "type" "cr_logical")
13415 (set_attr "cr_logical_3op" "no,yes")])
13416
13417 ; Why is the constant -1 here, but 1 in the previous pattern?
13418 ; Because ~1 has all but the low bit set.
13419 (define_insn "cceq_ior_compare_complement"
13420 [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13421 (compare:CCEQ (match_operator:SI 1 "boolean_operator"
13422 [(not:SI (match_operator:SI 2
13423 "branch_positive_comparison_operator"
13424 [(match_operand 3
13425 "cc_reg_operand" "y,y")
13426 (const_int 0)]))
13427 (match_operator:SI 4
13428 "branch_positive_comparison_operator"
13429 [(match_operand 5
13430 "cc_reg_operand" "0,y")
13431 (const_int 0)])])
13432 (const_int -1)))]
13433 ""
13434 "cr%q1 %E0,%j2,%j4"
13435 [(set_attr "type" "cr_logical")
13436 (set_attr "cr_logical_3op" "no,yes")])
13437
13438 (define_insn "@cceq_rev_compare_<mode>"
13439 [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y,?y")
13440 (compare:CCEQ (match_operator:GPR 1
13441 "branch_positive_comparison_operator"
13442 [(match_operand 2
13443 "cc_reg_operand" "0,y")
13444 (const_int 0)])
13445 (const_int 0)))]
13446 ""
13447 "crnot %E0,%j1"
13448 [(set_attr "type" "cr_logical")
13449 (set_attr "cr_logical_3op" "no,yes")])
13450
13451 ;; If we are comparing the result of two comparisons, this can be done
13452 ;; using creqv or crxor.
13453
13454 (define_insn_and_split ""
13455 [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
13456 (compare:CCEQ (match_operator 1 "branch_comparison_operator"
13457 [(match_operand 2 "cc_reg_operand" "y")
13458 (const_int 0)])
13459 (match_operator 3 "branch_comparison_operator"
13460 [(match_operand 4 "cc_reg_operand" "y")
13461 (const_int 0)])))]
13462 ""
13463 "#"
13464 ""
13465 [(set (match_dup 0) (compare:CCEQ (xor:SI (match_dup 1) (match_dup 3))
13466 (match_dup 5)))]
13467 {
13468 int positive_1, positive_2;
13469
13470 positive_1 = branch_positive_comparison_operator (operands[1],
13471 GET_MODE (operands[1]));
13472 positive_2 = branch_positive_comparison_operator (operands[3],
13473 GET_MODE (operands[3]));
13474
13475 if (! positive_1)
13476 operands[1] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[2]),
13477 GET_CODE (operands[1])),
13478 SImode,
13479 operands[2], const0_rtx);
13480 else if (GET_MODE (operands[1]) != SImode)
13481 operands[1] = gen_rtx_fmt_ee (GET_CODE (operands[1]), SImode,
13482 operands[2], const0_rtx);
13483
13484 if (! positive_2)
13485 operands[3] = gen_rtx_fmt_ee (rs6000_reverse_condition (GET_MODE (operands[4]),
13486 GET_CODE (operands[3])),
13487 SImode,
13488 operands[4], const0_rtx);
13489 else if (GET_MODE (operands[3]) != SImode)
13490 operands[3] = gen_rtx_fmt_ee (GET_CODE (operands[3]), SImode,
13491 operands[4], const0_rtx);
13492
13493 if (positive_1 == positive_2)
13494 {
13495 operands[1] = gen_rtx_NOT (SImode, operands[1]);
13496 operands[5] = constm1_rtx;
13497 }
13498 else
13499 {
13500 operands[5] = const1_rtx;
13501 }
13502 })
13503
13504 ;; Unconditional branch and return.
13505
13506 (define_insn "jump"
13507 [(set (pc)
13508 (label_ref (match_operand 0)))]
13509 ""
13510 "b %l0"
13511 [(set_attr "type" "branch")])
13512
13513 (define_insn "<return_str>return"
13514 [(any_return)]
13515 "<return_pred>"
13516 "blr"
13517 [(set_attr "type" "jmpreg")])
13518
13519 (define_expand "indirect_jump"
13520 [(set (pc) (match_operand 0 "register_operand"))]
13521 ""
13522 {
13523 if (!rs6000_speculate_indirect_jumps) {
13524 rtx ccreg = gen_reg_rtx (CCmode);
13525 emit_jump_insn (gen_indirect_jump_nospec (Pmode, operands[0], ccreg));
13526 DONE;
13527 }
13528 })
13529
13530 (define_insn "*indirect_jump<mode>"
13531 [(set (pc)
13532 (match_operand:P 0 "register_operand" "c,*l"))]
13533 "rs6000_speculate_indirect_jumps"
13534 "b%T0"
13535 [(set_attr "type" "jmpreg")])
13536
13537 (define_insn "@indirect_jump<mode>_nospec"
13538 [(set (pc) (match_operand:P 0 "register_operand" "c,*l"))
13539 (clobber (match_operand:CC 1 "cc_reg_operand" "=y,y"))]
13540 "!rs6000_speculate_indirect_jumps"
13541 "crset %E1\;beq%T0- %1\;b $"
13542 [(set_attr "type" "jmpreg")
13543 (set_attr "length" "12")])
13544
13545 ;; Table jump for switch statements:
13546 (define_expand "tablejump"
13547 [(use (match_operand 0))
13548 (use (label_ref (match_operand 1)))]
13549 ""
13550 {
13551 if (rs6000_speculate_indirect_jumps)
13552 {
13553 if (rs6000_relative_jumptables)
13554 emit_jump_insn (gen_tablejump_normal (Pmode, operands[0], operands[1]));
13555 else
13556 emit_jump_insn (gen_tablejump_absolute (Pmode, operands[0],
13557 operands[1]));
13558 }
13559 else
13560 {
13561 rtx ccreg = gen_reg_rtx (CCmode);
13562 rtx jump;
13563 if (rs6000_relative_jumptables)
13564 jump = gen_tablejump_nospec (Pmode, operands[0], operands[1], ccreg);
13565 else
13566 jump = gen_tablejump_absolute_nospec (Pmode, operands[0], operands[1],
13567 ccreg);
13568 emit_jump_insn (jump);
13569 }
13570 DONE;
13571 })
13572
13573 (define_expand "@tablejump<mode>_normal"
13574 [(use (match_operand:SI 0))
13575 (use (match_operand:P 1))]
13576 "rs6000_speculate_indirect_jumps && rs6000_relative_jumptables"
13577 {
13578 rtx off = force_reg (SImode, operands[0]);
13579 if (<MODE>mode != SImode)
13580 {
13581 rtx src = gen_rtx_fmt_e (SIGN_EXTEND, Pmode, off);
13582 off = gen_reg_rtx (Pmode);
13583 emit_move_insn (off, src);
13584 }
13585
13586 rtx lab = force_reg (Pmode, gen_rtx_LABEL_REF (Pmode, operands[1]));
13587 rtx addr = gen_reg_rtx (Pmode);
13588
13589 emit_insn (gen_add<mode>3 (addr, off, lab));
13590 emit_jump_insn (gen_tablejump_insn_normal (Pmode, addr, operands[1]));
13591 DONE;
13592 })
13593
13594 (define_expand "@tablejump<mode>_absolute"
13595 [(use (match_operand:P 0))
13596 (use (match_operand:P 1))]
13597 "rs6000_speculate_indirect_jumps && !rs6000_relative_jumptables"
13598 {
13599 rtx addr = gen_reg_rtx (Pmode);
13600 emit_move_insn (addr, operands[0]);
13601
13602 emit_jump_insn (gen_tablejump_insn_normal (Pmode, addr, operands[1]));
13603 DONE;
13604 })
13605
13606 (define_expand "@tablejump<mode>_nospec"
13607 [(use (match_operand:SI 0))
13608 (use (match_operand:P 1))
13609 (use (match_operand:CC 2))]
13610 "!rs6000_speculate_indirect_jumps && rs6000_relative_jumptables"
13611 {
13612 rtx off = force_reg (SImode, operands[0]);
13613 if (<MODE>mode != SImode)
13614 {
13615 rtx src = gen_rtx_fmt_e (SIGN_EXTEND, Pmode, off);
13616 off = gen_reg_rtx (Pmode);
13617 emit_move_insn (off, src);
13618 }
13619
13620 rtx lab = force_reg (Pmode, gen_rtx_LABEL_REF (Pmode, operands[1]));
13621 rtx addr = gen_reg_rtx (Pmode);
13622
13623 emit_insn (gen_add<mode>3 (addr, off, lab));
13624 emit_jump_insn (gen_tablejump_insn_nospec (Pmode, addr, operands[1],
13625 operands[2]));
13626 DONE;
13627 })
13628
13629 (define_expand "@tablejump<mode>_absolute_nospec"
13630 [(use (match_operand:P 0))
13631 (use (match_operand:P 1))
13632 (use (match_operand:CC 2))]
13633 "!rs6000_speculate_indirect_jumps && !rs6000_relative_jumptables"
13634 {
13635 rtx addr = gen_reg_rtx (Pmode);
13636 emit_move_insn (addr, operands[0]);
13637
13638 emit_jump_insn (gen_tablejump_insn_nospec (Pmode, addr, operands[1],
13639 operands[2]));
13640 DONE;
13641 })
13642
13643 (define_insn "@tablejump<mode>_insn_normal"
13644 [(set (pc)
13645 (match_operand:P 0 "register_operand" "c,*l"))
13646 (use (label_ref (match_operand 1)))]
13647 "rs6000_speculate_indirect_jumps"
13648 "b%T0"
13649 [(set_attr "type" "jmpreg")])
13650
13651 (define_insn "@tablejump<mode>_insn_nospec"
13652 [(set (pc)
13653 (match_operand:P 0 "register_operand" "c,*l"))
13654 (use (label_ref (match_operand 1)))
13655 (clobber (match_operand:CC 2 "cc_reg_operand" "=y,y"))]
13656 "!rs6000_speculate_indirect_jumps"
13657 "crset %E2\;beq%T0- %2\;b $"
13658 [(set_attr "type" "jmpreg")
13659 (set_attr "length" "12")])
13660
13661 (define_insn "nop"
13662 [(unspec [(const_int 0)] UNSPEC_NOP)]
13663 ""
13664 "nop")
13665
13666 (define_insn "group_ending_nop"
13667 [(unspec [(const_int 0)] UNSPEC_GRP_END_NOP)]
13668 ""
13669 {
13670 operands[0] = gen_rtx_REG (Pmode,
13671 rs6000_tune == PROCESSOR_POWER6 ? 1 : 2);
13672 return "ori %0,%0,0";
13673 })
13674
13675 (define_insn "speculation_barrier"
13676 [(unspec_volatile:BLK [(const_int 0)] UNSPECV_SPEC_BARRIER)]
13677 ""
13678 {
13679 operands[0] = gen_rtx_REG (Pmode, 31);
13680 return "ori %0,%0,0";
13681 })
13682
13683 ;; Define the subtract-one-and-jump insns, starting with the template
13684 ;; so loop.c knows what to generate.
13685
13686 (define_expand "doloop_end"
13687 [(use (match_operand 0)) ; loop pseudo
13688 (use (match_operand 1))] ; label
13689 ""
13690 {
13691 if (GET_MODE (operands[0]) != Pmode)
13692 FAIL;
13693
13694 emit_jump_insn (gen_ctr (Pmode, operands[0], operands[1]));
13695 DONE;
13696 })
13697
13698 (define_expand "@ctr<mode>"
13699 [(parallel [(set (pc)
13700 (if_then_else (ne (match_operand:P 0 "register_operand")
13701 (const_int 1))
13702 (label_ref (match_operand 1))
13703 (pc)))
13704 (set (match_dup 0)
13705 (plus:P (match_dup 0)
13706 (const_int -1)))
13707 (clobber (match_scratch:CC 2))
13708 (clobber (match_scratch:P 3))])]
13709 ""
13710 "")
13711
13712 ;; We need to be able to do this for any operand, including MEM, or we
13713 ;; will cause reload to blow up since we don't allow output reloads on
13714 ;; JUMP_INSNs.
13715 ;; For the length attribute to be calculated correctly, the
13716 ;; label MUST be operand 0.
13717 ;; rs6000_legitimate_combined_insn prevents combine creating any of
13718 ;; the ctr<mode> insns.
13719
13720 (define_code_attr bd [(eq "bdz") (ne "bdnz")])
13721 (define_code_attr bd_neg [(eq "bdnz") (ne "bdz")])
13722
13723 (define_insn "<bd>_<mode>"
13724 [(set (pc)
13725 (if_then_else (eqne (match_operand:P 1 "register_operand" "c,*b,*b,*b")
13726 (const_int 1))
13727 (label_ref (match_operand 0))
13728 (pc)))
13729 (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*d*wa*c*l")
13730 (plus:P (match_dup 1)
13731 (const_int -1)))
13732 (clobber (match_scratch:CC 3 "=X,&x,&x,&x"))
13733 (clobber (match_scratch:P 4 "=X,X,&r,r"))]
13734 ""
13735 {
13736 if (which_alternative != 0)
13737 return "#";
13738 else if (get_attr_length (insn) == 4)
13739 return "<bd> %l0";
13740 else
13741 return "<bd_neg> $+8\;b %l0";
13742 }
13743 [(set_attr "type" "branch")
13744 (set_attr_alternative "length"
13745 [(if_then_else (and (ge (minus (match_dup 0) (pc))
13746 (const_int -32768))
13747 (lt (minus (match_dup 0) (pc))
13748 (const_int 32764)))
13749 (const_int 4)
13750 (const_int 8))
13751 (const_string "16")
13752 (const_string "20")
13753 (const_string "20")])])
13754
13755 ;; Now the splitter if we could not allocate the CTR register
13756 (define_split
13757 [(set (pc)
13758 (if_then_else (match_operator 2 "comparison_operator"
13759 [(match_operand:P 1 "gpc_reg_operand")
13760 (const_int 1)])
13761 (match_operand 5)
13762 (match_operand 6)))
13763 (set (match_operand:P 0 "nonimmediate_operand")
13764 (plus:P (match_dup 1)
13765 (const_int -1)))
13766 (clobber (match_scratch:CC 3))
13767 (clobber (match_scratch:P 4))]
13768 "reload_completed"
13769 [(set (pc)
13770 (if_then_else (match_dup 7)
13771 (match_dup 5)
13772 (match_dup 6)))]
13773 {
13774 operands[7] = gen_rtx_fmt_ee (GET_CODE (operands[2]), VOIDmode, operands[3],
13775 const0_rtx);
13776 emit_insn (gen_rtx_SET (operands[3],
13777 gen_rtx_COMPARE (CCmode, operands[1], const1_rtx)));
13778 if (int_reg_operand (operands[0], <MODE>mode))
13779 emit_insn (gen_add<mode>3 (operands[0], operands[1], constm1_rtx));
13780 else
13781 {
13782 emit_insn (gen_add<mode>3 (operands[4], operands[1], constm1_rtx));
13783 emit_move_insn (operands[0], operands[4]);
13784 }
13785 /* No DONE so branch comes from the pattern. */
13786 })
13787
13788 ;; patterns for bdnzt/bdnzf/bdzt/bdzf
13789 ;; Note that in the case of long branches we have to decompose this into
13790 ;; bdnz+bc. This is because bdnzt has an implied AND between the ctr condition
13791 ;; and the CR bit, which means there is no way to conveniently invert the
13792 ;; comparison as is done with plain bdnz/bdz.
13793
13794 (define_insn "<bd>tf_<mode>"
13795 [(set (pc)
13796 (if_then_else
13797 (and
13798 (eqne (match_operand:P 1 "register_operand" "c,*b,*b,*b")
13799 (const_int 1))
13800 (match_operator 3 "branch_comparison_operator"
13801 [(match_operand 4 "cc_reg_operand" "y,y,y,y")
13802 (const_int 0)]))
13803 (label_ref (match_operand 0))
13804 (pc)))
13805 (set (match_operand:P 2 "nonimmediate_operand" "=1,*r,m,*d*wa*c*l")
13806 (plus:P (match_dup 1)
13807 (const_int -1)))
13808 (clobber (match_scratch:P 5 "=X,X,&r,r"))
13809 (clobber (match_scratch:CC 6 "=X,&y,&y,&y"))
13810 (clobber (match_scratch:CCEQ 7 "=X,&y,&y,&y"))]
13811 ""
13812 {
13813 if (which_alternative != 0)
13814 return "#";
13815 else if (get_attr_length (insn) == 4)
13816 {
13817 if (branch_positive_comparison_operator (operands[3],
13818 GET_MODE (operands[3])))
13819 return "<bd>t %j3,%l0";
13820 else
13821 return "<bd>f %j3,%l0";
13822 }
13823 else
13824 {
13825 static char seq[96];
13826 char *bcs = output_cbranch (operands[3], ".Lshort%=", 1, insn);
13827 sprintf(seq, "<bd_neg> .Lshort%%=\;%s\;b %%l0\;.Lshort%%=:", bcs);
13828 return seq;
13829 }
13830 }
13831 [(set_attr "type" "branch")
13832 (set_attr_alternative "length"
13833 [(if_then_else (and (ge (minus (match_dup 0) (pc))
13834 (const_int -32768))
13835 (lt (minus (match_dup 0) (pc))
13836 (const_int 32764)))
13837 (const_int 4)
13838 (const_int 8))
13839 (const_string "16")
13840 (const_string "20")
13841 (const_string "20")])])
13842
13843 ;; Now the splitter if we could not allocate the CTR register
13844 (define_split
13845 [(set (pc)
13846 (if_then_else
13847 (and
13848 (match_operator 1 "comparison_operator"
13849 [(match_operand:P 0 "gpc_reg_operand")
13850 (const_int 1)])
13851 (match_operator 3 "branch_comparison_operator"
13852 [(match_operand 2 "cc_reg_operand")
13853 (const_int 0)]))
13854 (match_operand 4)
13855 (match_operand 5)))
13856 (set (match_operand:P 6 "nonimmediate_operand")
13857 (plus:P (match_dup 0)
13858 (const_int -1)))
13859 (clobber (match_scratch:P 7))
13860 (clobber (match_scratch:CC 8))
13861 (clobber (match_scratch:CCEQ 9))]
13862 "reload_completed"
13863 [(pc)]
13864 {
13865 rtx ctr = operands[0];
13866 rtx ctrcmp = operands[1];
13867 rtx ccin = operands[2];
13868 rtx cccmp = operands[3];
13869 rtx dst1 = operands[4];
13870 rtx dst2 = operands[5];
13871 rtx ctrout = operands[6];
13872 rtx ctrtmp = operands[7];
13873 enum rtx_code cmpcode = GET_CODE (ctrcmp);
13874 bool ispos = branch_positive_comparison_operator (ctrcmp, GET_MODE (ctrcmp));
13875 if (!ispos)
13876 cmpcode = reverse_condition (cmpcode);
13877 /* Generate crand/crandc here. */
13878 emit_insn (gen_rtx_SET (operands[8],
13879 gen_rtx_COMPARE (CCmode, ctr, const1_rtx)));
13880 rtx ctrcmpcc = gen_rtx_fmt_ee (cmpcode, SImode, operands[8], const0_rtx);
13881
13882 rtx andexpr = gen_rtx_AND (SImode, ctrcmpcc, cccmp);
13883 if (ispos)
13884 emit_insn (gen_cceq_ior_compare (SImode, operands[9], andexpr, ctrcmpcc,
13885 operands[8], cccmp, ccin));
13886 else
13887 emit_insn (gen_cceq_ior_compare_complement (operands[9], andexpr, ctrcmpcc,
13888 operands[8], cccmp, ccin));
13889 if (int_reg_operand (ctrout, <MODE>mode))
13890 emit_insn (gen_add<mode>3 (ctrout, ctr, constm1_rtx));
13891 else
13892 {
13893 emit_insn (gen_add<mode>3 (ctrtmp, ctr, constm1_rtx));
13894 emit_move_insn (ctrout, ctrtmp);
13895 }
13896 rtx cmp = gen_rtx_EQ (CCEQmode, operands[9], const0_rtx);
13897 emit_jump_insn (gen_rtx_SET (pc_rtx,
13898 gen_rtx_IF_THEN_ELSE (VOIDmode, cmp,
13899 dst1, dst2)));
13900 DONE;
13901 })
13902
13903
13904 (define_insn "trap"
13905 [(trap_if (const_int 1) (const_int 0))]
13906 ""
13907 "trap"
13908 [(set_attr "type" "trap")])
13909
13910 (define_expand "ctrap<mode>4"
13911 [(trap_if (match_operator 0 "ordered_comparison_operator"
13912 [(match_operand:GPR 1 "register_operand")
13913 (match_operand:GPR 2 "reg_or_short_operand")])
13914 (match_operand 3 "zero_constant" ""))]
13915 ""
13916 "")
13917
13918 (define_insn ""
13919 [(trap_if (match_operator 0 "ordered_comparison_operator"
13920 [(match_operand:GPR 1 "register_operand" "r")
13921 (match_operand:GPR 2 "reg_or_short_operand" "rI")])
13922 (const_int 0))]
13923 ""
13924 "t<wd>%V0%I2 %1,%2"
13925 [(set_attr "type" "trap")])
13926
13927 ;; Insns related to generating the function prologue and epilogue.
13928
13929 (define_expand "prologue"
13930 [(use (const_int 0))]
13931 ""
13932 {
13933 rs6000_emit_prologue ();
13934 if (!TARGET_SCHED_PROLOG)
13935 emit_insn (gen_blockage ());
13936 DONE;
13937 })
13938
13939 (define_insn "*movesi_from_cr_one"
13940 [(match_parallel 0 "mfcr_operation"
13941 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
13942 (unspec:SI [(match_operand:CC 2 "cc_reg_operand" "y")
13943 (match_operand 3 "immediate_operand" "n")]
13944 UNSPEC_MOVESI_FROM_CR))])]
13945 "TARGET_MFCRF"
13946 {
13947 int mask = 0;
13948 int i;
13949 for (i = 0; i < XVECLEN (operands[0], 0); i++)
13950 {
13951 mask = INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
13952 operands[4] = GEN_INT (mask);
13953 output_asm_insn ("mfcr %1,%4", operands);
13954 }
13955 return "";
13956 }
13957 [(set_attr "type" "mfcrf")])
13958
13959 ;; Don't include the volatile CRs since their values are not used wrt CR save
13960 ;; in the prologue and doing so prevents shrink-wrapping because we can't move the
13961 ;; prologue past an insn (early exit test) that defines a register used in the
13962 ;; prologue.
13963 (define_insn "prologue_movesi_from_cr"
13964 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
13965 (unspec:SI [(reg:CC CR2_REGNO) (reg:CC CR3_REGNO)
13966 (reg:CC CR4_REGNO)]
13967 UNSPEC_MOVESI_FROM_CR))]
13968 ""
13969 "mfcr %0"
13970 [(set_attr "type" "mfcr")])
13971
13972 (define_insn "*crsave"
13973 [(match_parallel 0 "crsave_operation"
13974 [(set (match_operand:SI 1 "memory_operand" "=m")
13975 (match_operand:SI 2 "gpc_reg_operand" "r"))])]
13976 ""
13977 "stw %2,%1"
13978 [(set_attr "type" "store")])
13979
13980 (define_insn "*stmw"
13981 [(match_parallel 0 "stmw_operation"
13982 [(set (match_operand:SI 1 "memory_operand" "=m")
13983 (match_operand:SI 2 "gpc_reg_operand" "r"))])]
13984 "TARGET_MULTIPLE"
13985 "stmw %2,%1"
13986 [(set_attr "type" "store")
13987 (set_attr "update" "yes")
13988 (set_attr "indexed" "yes")])
13989
13990 ; The following comment applies to:
13991 ; save_gpregs_*
13992 ; save_fpregs_*
13993 ; restore_gpregs*
13994 ; return_and_restore_gpregs*
13995 ; return_and_restore_fpregs*
13996 ; return_and_restore_fpregs_aix*
13997 ;
13998 ; The out-of-line save / restore functions expects one input argument.
13999 ; Since those are not standard call_insn's, we must avoid using
14000 ; MATCH_OPERAND for that argument. That way the register rename
14001 ; optimization will not try to rename this register.
14002 ; Each pattern is repeated for each possible register number used in
14003 ; various ABIs (r11, r1, and for some functions r12)
14004
14005 (define_insn "*save_gpregs_<mode>_r11"
14006 [(match_parallel 0 "any_parallel_operand"
14007 [(clobber (reg:P LR_REGNO))
14008 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14009 (use (reg:P 11))
14010 (set (match_operand:P 2 "memory_operand" "=m")
14011 (match_operand:P 3 "gpc_reg_operand" "r"))])]
14012 ""
14013 "bl %1"
14014 [(set_attr "type" "branch")])
14015
14016 (define_insn "*save_gpregs_<mode>_r12"
14017 [(match_parallel 0 "any_parallel_operand"
14018 [(clobber (reg:P LR_REGNO))
14019 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14020 (use (reg:P 12))
14021 (set (match_operand:P 2 "memory_operand" "=m")
14022 (match_operand:P 3 "gpc_reg_operand" "r"))])]
14023 ""
14024 "bl %1"
14025 [(set_attr "type" "branch")])
14026
14027 (define_insn "*save_gpregs_<mode>_r1"
14028 [(match_parallel 0 "any_parallel_operand"
14029 [(clobber (reg:P LR_REGNO))
14030 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14031 (use (reg:P 1))
14032 (set (match_operand:P 2 "memory_operand" "=m")
14033 (match_operand:P 3 "gpc_reg_operand" "r"))])]
14034 ""
14035 "bl %1"
14036 [(set_attr "type" "branch")])
14037
14038 (define_insn "*save_fpregs_<mode>_r11"
14039 [(match_parallel 0 "any_parallel_operand"
14040 [(clobber (reg:P LR_REGNO))
14041 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14042 (use (reg:P 11))
14043 (set (match_operand:DF 2 "memory_operand" "=m")
14044 (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14045 ""
14046 "bl %1"
14047 [(set_attr "type" "branch")])
14048
14049 (define_insn "*save_fpregs_<mode>_r12"
14050 [(match_parallel 0 "any_parallel_operand"
14051 [(clobber (reg:P LR_REGNO))
14052 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14053 (use (reg:P 12))
14054 (set (match_operand:DF 2 "memory_operand" "=m")
14055 (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14056 ""
14057 "bl %1"
14058 [(set_attr "type" "branch")])
14059
14060 (define_insn "*save_fpregs_<mode>_r1"
14061 [(match_parallel 0 "any_parallel_operand"
14062 [(clobber (reg:P LR_REGNO))
14063 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14064 (use (reg:P 1))
14065 (set (match_operand:DF 2 "memory_operand" "=m")
14066 (match_operand:DF 3 "gpc_reg_operand" "d"))])]
14067 ""
14068 "bl %1"
14069 [(set_attr "type" "branch")])
14070
14071 ; This is to explain that changes to the stack pointer should
14072 ; not be moved over loads from or stores to stack memory.
14073 (define_insn "stack_tie"
14074 [(match_parallel 0 "tie_operand"
14075 [(set (mem:BLK (reg 1)) (const_int 0))])]
14076 ""
14077 ""
14078 [(set_attr "length" "0")])
14079
14080 ; Some 32-bit ABIs do not have a red zone, so the stack deallocation has to
14081 ; stay behind all restores from the stack, it cannot be reordered to before
14082 ; one. See PR77687. This insn is an add or mr, and a memory clobber.
14083 (define_insn "stack_restore_tie"
14084 [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
14085 (plus:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
14086 (match_operand:SI 2 "reg_or_cint_operand" "O,rI")))
14087 (set (mem:BLK (scratch)) (const_int 0))]
14088 "TARGET_32BIT"
14089 "@
14090 mr %0,%1
14091 add%I2 %0,%1,%2"
14092 [(set_attr "type" "*,add")])
14093
14094 (define_expand "epilogue"
14095 [(use (const_int 0))]
14096 ""
14097 {
14098 if (!TARGET_SCHED_PROLOG)
14099 emit_insn (gen_blockage ());
14100 rs6000_emit_epilogue (EPILOGUE_TYPE_NORMAL);
14101 DONE;
14102 })
14103
14104 ; On some processors, doing the mtcrf one CC register at a time is
14105 ; faster (like on the 604e). On others, doing them all at once is
14106 ; faster; for instance, on the 601 and 750.
14107
14108 (define_expand "movsi_to_cr_one"
14109 [(set (match_operand:CC 0 "cc_reg_operand")
14110 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand")
14111 (match_dup 2)] UNSPEC_MOVESI_TO_CR))]
14112 ""
14113 "operands[2] = GEN_INT (1 << (7 - (REGNO (operands[0]) - CR0_REGNO)));")
14114
14115 (define_insn "*movsi_to_cr"
14116 [(match_parallel 0 "mtcrf_operation"
14117 [(set (match_operand:CC 1 "cc_reg_operand" "=y")
14118 (unspec:CC [(match_operand:SI 2 "gpc_reg_operand" "r")
14119 (match_operand 3 "immediate_operand" "n")]
14120 UNSPEC_MOVESI_TO_CR))])]
14121 ""
14122 {
14123 int mask = 0;
14124 int i;
14125 for (i = 0; i < XVECLEN (operands[0], 0); i++)
14126 mask |= INTVAL (XVECEXP (SET_SRC (XVECEXP (operands[0], 0, i)), 0, 1));
14127 operands[4] = GEN_INT (mask);
14128 return "mtcrf %4,%2";
14129 }
14130 [(set_attr "type" "mtcr")])
14131
14132 (define_insn "*mtcrfsi"
14133 [(set (match_operand:CC 0 "cc_reg_operand" "=y")
14134 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
14135 (match_operand 2 "immediate_operand" "n")]
14136 UNSPEC_MOVESI_TO_CR))]
14137 "REG_P (operands[0])
14138 && CR_REGNO_P (REGNO (operands[0]))
14139 && CONST_INT_P (operands[2])
14140 && INTVAL (operands[2]) == 1 << (7 - (REGNO (operands[0]) - CR0_REGNO))"
14141 "mtcrf %R0,%1"
14142 [(set_attr "type" "mtcr")])
14143
14144 ; The load-multiple instructions have similar properties.
14145 ; Note that "load_multiple" is a name known to the machine-independent
14146 ; code that actually corresponds to the PowerPC load-string.
14147
14148 (define_insn "*lmw"
14149 [(match_parallel 0 "lmw_operation"
14150 [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
14151 (match_operand:SI 2 "memory_operand" "m"))])]
14152 "TARGET_MULTIPLE"
14153 "lmw %1,%2"
14154 [(set_attr "type" "load")
14155 (set_attr "update" "yes")
14156 (set_attr "indexed" "yes")
14157 (set_attr "cell_micro" "always")])
14158
14159 ; FIXME: "any_parallel_operand" is a bit flexible...
14160
14161 ; The following comment applies to:
14162 ; save_gpregs_*
14163 ; save_fpregs_*
14164 ; restore_gpregs*
14165 ; return_and_restore_gpregs*
14166 ; return_and_restore_fpregs*
14167 ; return_and_restore_fpregs_aix*
14168 ;
14169 ; The out-of-line save / restore functions expects one input argument.
14170 ; Since those are not standard call_insn's, we must avoid using
14171 ; MATCH_OPERAND for that argument. That way the register rename
14172 ; optimization will not try to rename this register.
14173 ; Each pattern is repeated for each possible register number used in
14174 ; various ABIs (r11, r1, and for some functions r12)
14175
14176 (define_insn "*restore_gpregs_<mode>_r11"
14177 [(match_parallel 0 "any_parallel_operand"
14178 [(clobber (reg:P LR_REGNO))
14179 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14180 (use (reg:P 11))
14181 (set (match_operand:P 2 "gpc_reg_operand" "=r")
14182 (match_operand:P 3 "memory_operand" "m"))])]
14183 ""
14184 "bl %1"
14185 [(set_attr "type" "branch")])
14186
14187 (define_insn "*restore_gpregs_<mode>_r12"
14188 [(match_parallel 0 "any_parallel_operand"
14189 [(clobber (reg:P LR_REGNO))
14190 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14191 (use (reg:P 12))
14192 (set (match_operand:P 2 "gpc_reg_operand" "=r")
14193 (match_operand:P 3 "memory_operand" "m"))])]
14194 ""
14195 "bl %1"
14196 [(set_attr "type" "branch")])
14197
14198 (define_insn "*restore_gpregs_<mode>_r1"
14199 [(match_parallel 0 "any_parallel_operand"
14200 [(clobber (reg:P LR_REGNO))
14201 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14202 (use (reg:P 1))
14203 (set (match_operand:P 2 "gpc_reg_operand" "=r")
14204 (match_operand:P 3 "memory_operand" "m"))])]
14205 ""
14206 "bl %1"
14207 [(set_attr "type" "branch")])
14208
14209 (define_insn "*return_and_restore_gpregs_<mode>_r11"
14210 [(match_parallel 0 "any_parallel_operand"
14211 [(return)
14212 (clobber (reg:P LR_REGNO))
14213 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14214 (use (reg:P 11))
14215 (set (match_operand:P 2 "gpc_reg_operand" "=r")
14216 (match_operand:P 3 "memory_operand" "m"))])]
14217 ""
14218 "b %1"
14219 [(set_attr "type" "branch")])
14220
14221 (define_insn "*return_and_restore_gpregs_<mode>_r12"
14222 [(match_parallel 0 "any_parallel_operand"
14223 [(return)
14224 (clobber (reg:P LR_REGNO))
14225 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14226 (use (reg:P 12))
14227 (set (match_operand:P 2 "gpc_reg_operand" "=r")
14228 (match_operand:P 3 "memory_operand" "m"))])]
14229 ""
14230 "b %1"
14231 [(set_attr "type" "branch")])
14232
14233 (define_insn "*return_and_restore_gpregs_<mode>_r1"
14234 [(match_parallel 0 "any_parallel_operand"
14235 [(return)
14236 (clobber (reg:P LR_REGNO))
14237 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14238 (use (reg:P 1))
14239 (set (match_operand:P 2 "gpc_reg_operand" "=r")
14240 (match_operand:P 3 "memory_operand" "m"))])]
14241 ""
14242 "b %1"
14243 [(set_attr "type" "branch")])
14244
14245 (define_insn "*return_and_restore_fpregs_<mode>_r11"
14246 [(match_parallel 0 "any_parallel_operand"
14247 [(return)
14248 (clobber (reg:P LR_REGNO))
14249 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14250 (use (reg:P 11))
14251 (set (match_operand:DF 2 "gpc_reg_operand" "=d")
14252 (match_operand:DF 3 "memory_operand" "m"))])]
14253 ""
14254 "b %1"
14255 [(set_attr "type" "branch")])
14256
14257 (define_insn "*return_and_restore_fpregs_<mode>_r12"
14258 [(match_parallel 0 "any_parallel_operand"
14259 [(return)
14260 (clobber (reg:P LR_REGNO))
14261 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14262 (use (reg:P 12))
14263 (set (match_operand:DF 2 "gpc_reg_operand" "=d")
14264 (match_operand:DF 3 "memory_operand" "m"))])]
14265 ""
14266 "b %1"
14267 [(set_attr "type" "branch")])
14268
14269 (define_insn "*return_and_restore_fpregs_<mode>_r1"
14270 [(match_parallel 0 "any_parallel_operand"
14271 [(return)
14272 (clobber (reg:P LR_REGNO))
14273 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14274 (use (reg:P 1))
14275 (set (match_operand:DF 2 "gpc_reg_operand" "=d")
14276 (match_operand:DF 3 "memory_operand" "m"))])]
14277 ""
14278 "b %1"
14279 [(set_attr "type" "branch")])
14280
14281 (define_insn "*return_and_restore_fpregs_aix_<mode>_r11"
14282 [(match_parallel 0 "any_parallel_operand"
14283 [(return)
14284 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14285 (use (reg:P 11))
14286 (set (match_operand:DF 2 "gpc_reg_operand" "=d")
14287 (match_operand:DF 3 "memory_operand" "m"))])]
14288 ""
14289 "b %1"
14290 [(set_attr "type" "branch")])
14291
14292 (define_insn "*return_and_restore_fpregs_aix_<mode>_r1"
14293 [(match_parallel 0 "any_parallel_operand"
14294 [(return)
14295 (use (match_operand:P 1 "symbol_ref_operand" "s"))
14296 (use (reg:P 1))
14297 (set (match_operand:DF 2 "gpc_reg_operand" "=d")
14298 (match_operand:DF 3 "memory_operand" "m"))])]
14299 ""
14300 "b %1"
14301 [(set_attr "type" "branch")])
14302
14303 ; This is used in compiling the unwind routines.
14304 (define_expand "eh_return"
14305 [(use (match_operand 0 "general_operand"))]
14306 ""
14307 {
14308 emit_insn (gen_eh_set_lr (Pmode, operands[0]));
14309 emit_jump_insn (gen_eh_return_internal ());
14310 emit_barrier ();
14311 DONE;
14312 })
14313
14314 ; We can't expand this before we know where the link register is stored.
14315 (define_insn_and_split "@eh_set_lr_<mode>"
14316 [(unspec_volatile [(match_operand:P 0 "register_operand" "r")] UNSPECV_EH_RR)
14317 (clobber (match_scratch:P 1 "=&b"))]
14318 ""
14319 "#"
14320 "reload_completed"
14321 [(const_int 0)]
14322 {
14323 rs6000_emit_eh_reg_restore (operands[0], operands[1]);
14324 DONE;
14325 })
14326
14327 (define_insn_and_split "eh_return_internal"
14328 [(eh_return)]
14329 ""
14330 "#"
14331 "epilogue_completed"
14332 [(const_int 0)]
14333 {
14334 if (!TARGET_SCHED_PROLOG)
14335 emit_insn (gen_blockage ());
14336 rs6000_emit_epilogue (EPILOGUE_TYPE_EH_RETURN);
14337 DONE;
14338 })
14339
14340 (define_insn "prefetch"
14341 [(prefetch (match_operand 0 "indexed_or_indirect_address" "a")
14342 (match_operand:SI 1 "const_int_operand" "n")
14343 (match_operand:SI 2 "const_int_operand" "n"))]
14344 ""
14345 {
14346
14347
14348 /* dcbtstt, dcbtt and TH=0b10000 support starts with ISA 2.06 (Power7).
14349 AIX does not support the dcbtstt and dcbtt extended mnemonics.
14350 The AIX assembler does not support the three operand form of dcbt
14351 and dcbtst on Power 7 (-mpwr7). */
14352 int inst_select = INTVAL (operands[2]) || !TARGET_POWER8;
14353
14354 if (REG_P (operands[0]))
14355 {
14356 if (INTVAL (operands[1]) != 1)
14357 return inst_select ? "dcbt 0,%0" : "dcbt 0,%0,16";
14358 else
14359 return inst_select ? "dcbtst 0,%0" : "dcbtst 0,%0,16";
14360 }
14361 else
14362 {
14363 if (INTVAL (operands[1]) != 1)
14364 return inst_select ? "dcbt %a0" : "dcbt %a0,16";
14365 else
14366 return inst_select ? "dcbtst %a0" : "dcbtst %a0,16";
14367 }
14368 }
14369 [(set_attr "type" "load")])
14370
14371 ;; Handle -fsplit-stack.
14372
14373 (define_expand "split_stack_prologue"
14374 [(const_int 0)]
14375 ""
14376 {
14377 rs6000_expand_split_stack_prologue ();
14378 DONE;
14379 })
14380
14381 (define_expand "load_split_stack_limit"
14382 [(set (match_operand 0)
14383 (unspec [(const_int 0)] UNSPEC_STACK_CHECK))]
14384 ""
14385 {
14386 emit_insn (gen_rtx_SET (operands[0],
14387 gen_rtx_UNSPEC (Pmode,
14388 gen_rtvec (1, const0_rtx),
14389 UNSPEC_STACK_CHECK)));
14390 DONE;
14391 })
14392
14393 (define_insn "load_split_stack_limit_di"
14394 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
14395 (unspec:DI [(const_int 0)] UNSPEC_STACK_CHECK))]
14396 "TARGET_64BIT"
14397 "ld %0,-0x7040(13)"
14398 [(set_attr "type" "load")
14399 (set_attr "update" "no")
14400 (set_attr "indexed" "no")])
14401
14402 (define_insn "load_split_stack_limit_si"
14403 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
14404 (unspec:SI [(const_int 0)] UNSPEC_STACK_CHECK))]
14405 "!TARGET_64BIT"
14406 "lwz %0,-0x7020(2)"
14407 [(set_attr "type" "load")
14408 (set_attr "update" "no")
14409 (set_attr "indexed" "no")])
14410
14411 ;; A return instruction which the middle-end doesn't see.
14412 ;; Use r0 to stop regrename twiddling with lr restore insns emitted
14413 ;; after the call to __morestack.
14414 (define_insn "split_stack_return"
14415 [(unspec_volatile [(reg:SI 0) (reg:SI LR_REGNO)] UNSPECV_SPLIT_STACK_RETURN)]
14416 ""
14417 "blr"
14418 [(set_attr "type" "jmpreg")])
14419
14420 ;; If there are operand 0 bytes available on the stack, jump to
14421 ;; operand 1.
14422 (define_expand "split_stack_space_check"
14423 [(set (match_dup 2)
14424 (unspec [(const_int 0)] UNSPEC_STACK_CHECK))
14425 (set (match_dup 3)
14426 (minus (reg STACK_POINTER_REGNUM)
14427 (match_operand 0)))
14428 (set (match_dup 4) (compare:CCUNS (match_dup 3) (match_dup 2)))
14429 (set (pc) (if_then_else
14430 (geu (match_dup 4) (const_int 0))
14431 (label_ref (match_operand 1))
14432 (pc)))]
14433 ""
14434 {
14435 rs6000_split_stack_space_check (operands[0], operands[1]);
14436 DONE;
14437 })
14438
14439 (define_insn "bpermd_<mode>"
14440 [(set (match_operand:P 0 "gpc_reg_operand" "=r")
14441 (unspec:P [(match_operand:P 1 "gpc_reg_operand" "r")
14442 (match_operand:P 2 "gpc_reg_operand" "r")] UNSPEC_BPERM))]
14443 "TARGET_POPCNTD"
14444 "bpermd %0,%1,%2"
14445 [(set_attr "type" "popcnt")])
14446
14447
14448 ;; Builtin fma support. Handle
14449 ;; Note that the conditions for expansion are in the FMA_F iterator.
14450
14451 (define_expand "fma<mode>4"
14452 [(set (match_operand:FMA_F 0 "gpc_reg_operand")
14453 (fma:FMA_F
14454 (match_operand:FMA_F 1 "gpc_reg_operand")
14455 (match_operand:FMA_F 2 "gpc_reg_operand")
14456 (match_operand:FMA_F 3 "gpc_reg_operand")))]
14457 ""
14458 "")
14459
14460 (define_insn "*fma<mode>4_fpr"
14461 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa,wa")
14462 (fma:SFDF
14463 (match_operand:SFDF 1 "gpc_reg_operand" "%d,wa,wa")
14464 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa,0")
14465 (match_operand:SFDF 3 "gpc_reg_operand" "d,0,wa")))]
14466 "TARGET_HARD_FLOAT"
14467 "@
14468 fmadd<s> %0,%1,%2,%3
14469 xsmadda<sd>p %x0,%x1,%x2
14470 xsmaddm<sd>p %x0,%x1,%x3"
14471 [(set_attr "type" "fp")
14472 (set_attr "isa" "*,<Fisa>,<Fisa>")])
14473
14474 ; Altivec only has fma and nfms.
14475 (define_expand "fms<mode>4"
14476 [(set (match_operand:FMA_F 0 "gpc_reg_operand")
14477 (fma:FMA_F
14478 (match_operand:FMA_F 1 "gpc_reg_operand")
14479 (match_operand:FMA_F 2 "gpc_reg_operand")
14480 (neg:FMA_F (match_operand:FMA_F 3 "gpc_reg_operand"))))]
14481 "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
14482 "")
14483
14484 (define_insn "*fms<mode>4_fpr"
14485 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa,wa")
14486 (fma:SFDF
14487 (match_operand:SFDF 1 "gpc_reg_operand" "d,wa,wa")
14488 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa,0")
14489 (neg:SFDF (match_operand:SFDF 3 "gpc_reg_operand" "d,0,wa"))))]
14490 "TARGET_HARD_FLOAT"
14491 "@
14492 fmsub<s> %0,%1,%2,%3
14493 xsmsuba<sd>p %x0,%x1,%x2
14494 xsmsubm<sd>p %x0,%x1,%x3"
14495 [(set_attr "type" "fp")
14496 (set_attr "isa" "*,<Fisa>,<Fisa>")])
14497
14498 ;; If signed zeros are ignored, -(a * b - c) = -a * b + c.
14499 (define_expand "fnma<mode>4"
14500 [(set (match_operand:FMA_F 0 "gpc_reg_operand")
14501 (neg:FMA_F
14502 (fma:FMA_F
14503 (match_operand:FMA_F 1 "gpc_reg_operand")
14504 (match_operand:FMA_F 2 "gpc_reg_operand")
14505 (neg:FMA_F (match_operand:FMA_F 3 "gpc_reg_operand")))))]
14506 "!HONOR_SIGNED_ZEROS (<MODE>mode)"
14507 "")
14508
14509 ;; If signed zeros are ignored, -(a * b + c) = -a * b - c.
14510 (define_expand "fnms<mode>4"
14511 [(set (match_operand:FMA_F 0 "gpc_reg_operand")
14512 (neg:FMA_F
14513 (fma:FMA_F
14514 (match_operand:FMA_F 1 "gpc_reg_operand")
14515 (match_operand:FMA_F 2 "gpc_reg_operand")
14516 (match_operand:FMA_F 3 "gpc_reg_operand"))))]
14517 "!HONOR_SIGNED_ZEROS (<MODE>mode) && !VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
14518 "")
14519
14520 ; Not an official optab name, but used from builtins.
14521 (define_expand "nfma<mode>4"
14522 [(set (match_operand:FMA_F 0 "gpc_reg_operand")
14523 (neg:FMA_F
14524 (fma:FMA_F
14525 (match_operand:FMA_F 1 "gpc_reg_operand")
14526 (match_operand:FMA_F 2 "gpc_reg_operand")
14527 (match_operand:FMA_F 3 "gpc_reg_operand"))))]
14528 "!VECTOR_UNIT_ALTIVEC_P (<MODE>mode)"
14529 "")
14530
14531 (define_insn "*nfma<mode>4_fpr"
14532 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa,wa")
14533 (neg:SFDF
14534 (fma:SFDF
14535 (match_operand:SFDF 1 "gpc_reg_operand" "d,wa,wa")
14536 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa,0")
14537 (match_operand:SFDF 3 "gpc_reg_operand" "d,0,wa"))))]
14538 "TARGET_HARD_FLOAT"
14539 "@
14540 fnmadd<s> %0,%1,%2,%3
14541 xsnmadda<sd>p %x0,%x1,%x2
14542 xsnmaddm<sd>p %x0,%x1,%x3"
14543 [(set_attr "type" "fp")
14544 (set_attr "isa" "*,<Fisa>,<Fisa>")])
14545
14546 ; Not an official optab name, but used from builtins.
14547 (define_expand "nfms<mode>4"
14548 [(set (match_operand:FMA_F 0 "gpc_reg_operand")
14549 (neg:FMA_F
14550 (fma:FMA_F
14551 (match_operand:FMA_F 1 "gpc_reg_operand")
14552 (match_operand:FMA_F 2 "gpc_reg_operand")
14553 (neg:FMA_F (match_operand:FMA_F 3 "gpc_reg_operand")))))]
14554 ""
14555 "")
14556
14557 (define_insn "*nfmssf4_fpr"
14558 [(set (match_operand:SFDF 0 "gpc_reg_operand" "=d,wa,wa")
14559 (neg:SFDF
14560 (fma:SFDF
14561 (match_operand:SFDF 1 "gpc_reg_operand" "d,wa,wa")
14562 (match_operand:SFDF 2 "gpc_reg_operand" "d,wa,0")
14563 (neg:SFDF
14564 (match_operand:SFDF 3 "gpc_reg_operand" "d,0,wa")))))]
14565 "TARGET_HARD_FLOAT"
14566 "@
14567 fnmsub<s> %0,%1,%2,%3
14568 xsnmsuba<sd>p %x0,%x1,%x2
14569 xsnmsubm<sd>p %x0,%x1,%x3"
14570 [(set_attr "type" "fp")
14571 (set_attr "isa" "*,<Fisa>,<Fisa>")])
14572
14573 (define_expand "rs6000_get_timebase"
14574 [(use (match_operand:DI 0 "gpc_reg_operand"))]
14575 ""
14576 {
14577 if (TARGET_POWERPC64)
14578 emit_insn (gen_rs6000_mftb_di (operands[0]));
14579 else
14580 emit_insn (gen_rs6000_get_timebase_ppc32 (operands[0]));
14581 DONE;
14582 })
14583
14584 (define_insn "rs6000_get_timebase_ppc32"
14585 [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
14586 (unspec_volatile:DI [(const_int 0)] UNSPECV_MFTB))
14587 (clobber (match_scratch:SI 1 "=r"))
14588 (clobber (match_scratch:CC 2 "=y"))]
14589 "!TARGET_POWERPC64"
14590 {
14591 if (WORDS_BIG_ENDIAN)
14592 if (TARGET_MFCRF)
14593 {
14594 return "mfspr %0,269\;"
14595 "mfspr %L0,268\;"
14596 "mfspr %1,269\;"
14597 "cmpw %2,%0,%1\;"
14598 "bne- %2,$-16";
14599 }
14600 else
14601 {
14602 return "mftbu %0\;"
14603 "mftb %L0\;"
14604 "mftbu %1\;"
14605 "cmpw %2,%0,%1\;"
14606 "bne- %2,$-16";
14607 }
14608 else
14609 if (TARGET_MFCRF)
14610 {
14611 return "mfspr %L0,269\;"
14612 "mfspr %0,268\;"
14613 "mfspr %1,269\;"
14614 "cmpw %2,%L0,%1\;"
14615 "bne- %2,$-16";
14616 }
14617 else
14618 {
14619 return "mftbu %L0\;"
14620 "mftb %0\;"
14621 "mftbu %1\;"
14622 "cmpw %2,%L0,%1\;"
14623 "bne- %2,$-16";
14624 }
14625 }
14626 [(set_attr "length" "20")])
14627
14628 (define_insn "rs6000_mftb_<mode>"
14629 [(set (match_operand:GPR 0 "gpc_reg_operand" "=r")
14630 (unspec_volatile:GPR [(const_int 0)] UNSPECV_MFTB))]
14631 ""
14632 {
14633 if (TARGET_MFCRF)
14634 return "mfspr %0,268";
14635 else
14636 return "mftb %0";
14637 })
14638
14639
14640 ;; The ISA 3.0 mffsl instruction is a lower latency instruction
14641 ;; for reading bits [29:31], [45:51] and [56:63] of the FPSCR.
14642 (define_insn "rs6000_mffsl_hw"
14643 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
14644 (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFSL))]
14645 "TARGET_HARD_FLOAT"
14646 "mffsl %0")
14647
14648 (define_expand "rs6000_mffsl"
14649 [(set (match_operand:DF 0 "gpc_reg_operand")
14650 (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFSL))]
14651 "TARGET_HARD_FLOAT"
14652 {
14653 /* If the low latency mffsl instruction (ISA 3.0) is available use it,
14654 otherwise fall back to the older mffs instruction to emulate the mffsl
14655 instruction. */
14656
14657 if (!TARGET_P9_MISC)
14658 {
14659 rtx tmp1 = gen_reg_rtx (DFmode);
14660
14661 /* The mffs instruction reads the entire FPSCR. Emulate the mffsl
14662 instruction using the mffs instruction and masking the result. */
14663 emit_insn (gen_rs6000_mffs (tmp1));
14664
14665 rtx tmp1di = simplify_gen_subreg (DImode, tmp1, DFmode, 0);
14666 rtx tmp2 = gen_reg_rtx (DImode);
14667 emit_insn (gen_anddi3 (tmp2, tmp1di, GEN_INT (0x70007f0ffLL)));
14668
14669 rtx tmp2df = simplify_gen_subreg (DFmode, tmp2, DImode, 0);
14670 emit_move_insn (operands[0], tmp2df);
14671 DONE;
14672 }
14673
14674 emit_insn (gen_rs6000_mffsl_hw (operands[0]));
14675 DONE;
14676 })
14677
14678 (define_insn "rs6000_mffs"
14679 [(set (match_operand:DF 0 "gpc_reg_operand" "=d")
14680 (unspec_volatile:DF [(const_int 0)] UNSPECV_MFFS))]
14681 "TARGET_HARD_FLOAT"
14682 "mffs %0")
14683
14684 (define_insn "rs6000_mtfsf"
14685 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "i")
14686 (match_operand:DF 1 "gpc_reg_operand" "d")]
14687 UNSPECV_MTFSF)]
14688 "TARGET_HARD_FLOAT"
14689 "mtfsf %0,%1")
14690
14691 (define_insn "rs6000_mtfsf_hi"
14692 [(unspec_volatile [(match_operand:SI 0 "const_int_operand" "n")
14693 (match_operand:DF 1 "gpc_reg_operand" "d")]
14694 UNSPECV_MTFSF_HI)]
14695 "TARGET_HARD_FLOAT"
14696 "mtfsf %0,%1,0,1")
14697
14698
14699 ;; Power8 fusion support for fusing an addis instruction with a D-form load of
14700 ;; a GPR. The addis instruction must be adjacent to the load, and use the same
14701 ;; register that is being loaded. The fused ops must be physically adjacent.
14702
14703 ;; On Power8 GPR loads, we try to use the register that is being load. The
14704 ;; peephole2 then gathers any other fused possibilities that it can find after
14705 ;; register allocation. If power9 fusion is selected, we also fuse floating
14706 ;; point loads/stores.
14707
14708 ;; Find cases where the addis that feeds into a load instruction is either used
14709 ;; once or is the same as the target register, and replace it with the fusion
14710 ;; insn
14711
14712 (define_peephole2
14713 [(set (match_operand:P 0 "base_reg_operand")
14714 (match_operand:P 1 "fusion_gpr_addis"))
14715 (set (match_operand:INT1 2 "base_reg_operand")
14716 (match_operand:INT1 3 "fusion_gpr_mem_load"))]
14717 "TARGET_P8_FUSION
14718 && fusion_gpr_load_p (operands[0], operands[1], operands[2],
14719 operands[3])"
14720 [(const_int 0)]
14721 {
14722 expand_fusion_gpr_load (operands);
14723 DONE;
14724 })
14725
14726 ;; Fusion insn, created by the define_peephole2 above (and eventually by
14727 ;; reload)
14728
14729 (define_insn "*fusion_gpr_load_<mode>"
14730 [(set (match_operand:INT1 0 "base_reg_operand" "=b")
14731 (unspec:INT1 [(match_operand:INT1 1 "fusion_addis_mem_combo_load" "wF")]
14732 UNSPEC_FUSION_GPR))]
14733 "TARGET_P8_FUSION"
14734 {
14735 return emit_fusion_gpr_load (operands[0], operands[1]);
14736 }
14737 [(set_attr "type" "load")
14738 (set_attr "length" "8")])
14739
14740
14741 ;; Optimize cases where we want to do a D-form load (register+offset) on
14742 ;; ISA 2.06/2.07 to an Altivec register, and the register allocator
14743 ;; has generated:
14744 ;; LFD 0,32(3)
14745 ;; XXLOR 32,0,0
14746 ;;
14747 ;; and we change this to:
14748 ;; LI 0,32
14749 ;; LXSDX 32,3,9
14750
14751 (define_peephole2
14752 [(match_scratch:P 0 "b")
14753 (set (match_operand:ALTIVEC_DFORM 1 "fpr_reg_operand")
14754 (match_operand:ALTIVEC_DFORM 2 "simple_offsettable_mem_operand"))
14755 (set (match_operand:ALTIVEC_DFORM 3 "altivec_register_operand")
14756 (match_dup 1))]
14757 "TARGET_VSX && !TARGET_P9_VECTOR && peep2_reg_dead_p (2, operands[1])"
14758 [(set (match_dup 0)
14759 (match_dup 4))
14760 (set (match_dup 3)
14761 (match_dup 5))]
14762 {
14763 rtx tmp_reg = operands[0];
14764 rtx mem = operands[2];
14765 rtx addr = XEXP (mem, 0);
14766 rtx add_op0, add_op1, new_addr;
14767
14768 gcc_assert (GET_CODE (addr) == PLUS || GET_CODE (addr) == LO_SUM);
14769 add_op0 = XEXP (addr, 0);
14770 add_op1 = XEXP (addr, 1);
14771 gcc_assert (REG_P (add_op0));
14772 new_addr = gen_rtx_PLUS (Pmode, add_op0, tmp_reg);
14773
14774 operands[4] = add_op1;
14775 operands[5] = change_address (mem, <ALTIVEC_DFORM:MODE>mode, new_addr);
14776 })
14777
14778 ;; Optimize cases were want to do a D-form store on ISA 2.06/2.07 from an
14779 ;; Altivec register, and the register allocator has generated:
14780 ;; XXLOR 0,32,32
14781 ;; STFD 0,32(3)
14782 ;;
14783 ;; and we change this to:
14784 ;; LI 0,32
14785 ;; STXSDX 32,3,9
14786
14787 (define_peephole2
14788 [(match_scratch:P 0 "b")
14789 (set (match_operand:ALTIVEC_DFORM 1 "fpr_reg_operand")
14790 (match_operand:ALTIVEC_DFORM 2 "altivec_register_operand"))
14791 (set (match_operand:ALTIVEC_DFORM 3 "simple_offsettable_mem_operand")
14792 (match_dup 1))]
14793 "TARGET_VSX && !TARGET_P9_VECTOR && peep2_reg_dead_p (2, operands[1])"
14794 [(set (match_dup 0)
14795 (match_dup 4))
14796 (set (match_dup 5)
14797 (match_dup 2))]
14798 {
14799 rtx tmp_reg = operands[0];
14800 rtx mem = operands[3];
14801 rtx addr = XEXP (mem, 0);
14802 rtx add_op0, add_op1, new_addr;
14803
14804 gcc_assert (GET_CODE (addr) == PLUS || GET_CODE (addr) == LO_SUM);
14805 add_op0 = XEXP (addr, 0);
14806 add_op1 = XEXP (addr, 1);
14807 gcc_assert (REG_P (add_op0));
14808 new_addr = gen_rtx_PLUS (Pmode, add_op0, tmp_reg);
14809
14810 operands[4] = add_op1;
14811 operands[5] = change_address (mem, <ALTIVEC_DFORM:MODE>mode, new_addr);
14812 })
14813
14814
14815 ;; Miscellaneous ISA 2.06 (power7) instructions
14816 (define_insn "addg6s"
14817 [(set (match_operand:SI 0 "register_operand" "=r")
14818 (unspec:SI [(match_operand:SI 1 "register_operand" "r")
14819 (match_operand:SI 2 "register_operand" "r")]
14820 UNSPEC_ADDG6S))]
14821 "TARGET_POPCNTD"
14822 "addg6s %0,%1,%2"
14823 [(set_attr "type" "integer")])
14824
14825 (define_insn "cdtbcd"
14826 [(set (match_operand:SI 0 "register_operand" "=r")
14827 (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
14828 UNSPEC_CDTBCD))]
14829 "TARGET_POPCNTD"
14830 "cdtbcd %0,%1"
14831 [(set_attr "type" "integer")])
14832
14833 (define_insn "cbcdtd"
14834 [(set (match_operand:SI 0 "register_operand" "=r")
14835 (unspec:SI [(match_operand:SI 1 "register_operand" "r")]
14836 UNSPEC_CBCDTD))]
14837 "TARGET_POPCNTD"
14838 "cbcdtd %0,%1"
14839 [(set_attr "type" "integer")])
14840
14841 (define_int_iterator UNSPEC_DIV_EXTEND [UNSPEC_DIVE
14842 UNSPEC_DIVEU])
14843
14844 (define_int_attr div_extend [(UNSPEC_DIVE "e")
14845 (UNSPEC_DIVEU "eu")])
14846
14847 (define_insn "div<div_extend>_<mode>"
14848 [(set (match_operand:GPR 0 "register_operand" "=r")
14849 (unspec:GPR [(match_operand:GPR 1 "register_operand" "r")
14850 (match_operand:GPR 2 "register_operand" "r")]
14851 UNSPEC_DIV_EXTEND))]
14852 "TARGET_POPCNTD"
14853 "div<wd><div_extend> %0,%1,%2"
14854 [(set_attr "type" "div")
14855 (set_attr "size" "<bits>")])
14856
14857
14858 ;; Pack/unpack 128-bit floating point types that take 2 scalar registers
14859
14860 ; Type of the 64-bit part when packing/unpacking 128-bit floating point types
14861 (define_mode_attr FP128_64 [(TF "DF")
14862 (IF "DF")
14863 (TD "DI")
14864 (KF "DI")])
14865
14866 (define_expand "unpack<mode>"
14867 [(set (match_operand:<FP128_64> 0 "nonimmediate_operand")
14868 (unspec:<FP128_64>
14869 [(match_operand:FMOVE128 1 "register_operand")
14870 (match_operand:QI 2 "const_0_to_1_operand")]
14871 UNSPEC_UNPACK_128BIT))]
14872 "FLOAT128_2REG_P (<MODE>mode)"
14873 "")
14874
14875 (define_insn_and_split "unpack<mode>_dm"
14876 [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m,d,r,m")
14877 (unspec:<FP128_64>
14878 [(match_operand:FMOVE128 1 "register_operand" "d,d,r,d,r")
14879 (match_operand:QI 2 "const_0_to_1_operand" "i,i,i,i,i")]
14880 UNSPEC_UNPACK_128BIT))]
14881 "TARGET_DIRECT_MOVE_64BIT && FLOAT128_2REG_P (<MODE>mode)"
14882 "#"
14883 "&& reload_completed"
14884 [(set (match_dup 0) (match_dup 3))]
14885 {
14886 unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
14887
14888 if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
14889 {
14890 emit_note (NOTE_INSN_DELETED);
14891 DONE;
14892 }
14893
14894 operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
14895 }
14896 [(set_attr "type" "fp,fpstore,mtvsr,mfvsr,store")])
14897
14898 (define_insn_and_split "unpack<mode>_nodm"
14899 [(set (match_operand:<FP128_64> 0 "nonimmediate_operand" "=d,m,m")
14900 (unspec:<FP128_64>
14901 [(match_operand:FMOVE128 1 "register_operand" "d,d,r")
14902 (match_operand:QI 2 "const_0_to_1_operand" "i,i,i")]
14903 UNSPEC_UNPACK_128BIT))]
14904 "!TARGET_DIRECT_MOVE_64BIT && FLOAT128_2REG_P (<MODE>mode)"
14905 "#"
14906 "&& reload_completed"
14907 [(set (match_dup 0) (match_dup 3))]
14908 {
14909 unsigned fp_regno = REGNO (operands[1]) + UINTVAL (operands[2]);
14910
14911 if (REG_P (operands[0]) && REGNO (operands[0]) == fp_regno)
14912 {
14913 emit_note (NOTE_INSN_DELETED);
14914 DONE;
14915 }
14916
14917 operands[3] = gen_rtx_REG (<FP128_64>mode, fp_regno);
14918 }
14919 [(set_attr "type" "fp,fpstore,store")])
14920
14921 (define_expand "pack<mode>"
14922 [(use (match_operand:FMOVE128 0 "register_operand"))
14923 (use (match_operand:<FP128_64> 1 "register_operand"))
14924 (use (match_operand:<FP128_64> 2 "register_operand"))]
14925 "FLOAT128_2REG_P (<MODE>mode)"
14926 {
14927 if (TARGET_HARD_FLOAT)
14928 emit_insn (gen_pack<mode>_hard (operands[0], operands[1], operands[2]));
14929 else
14930 emit_insn (gen_pack<mode>_soft (operands[0], operands[1], operands[2]));
14931 DONE;
14932 })
14933
14934 (define_insn_and_split "pack<mode>_hard"
14935 [(set (match_operand:FMOVE128 0 "register_operand" "=&d")
14936 (unspec:FMOVE128
14937 [(match_operand:<FP128_64> 1 "register_operand" "d")
14938 (match_operand:<FP128_64> 2 "register_operand" "d")]
14939 UNSPEC_PACK_128BIT))]
14940 "FLOAT128_2REG_P (<MODE>mode) && TARGET_HARD_FLOAT"
14941 "#"
14942 "&& reload_completed"
14943 [(set (match_dup 3) (match_dup 1))
14944 (set (match_dup 4) (match_dup 2))]
14945 {
14946 unsigned dest_hi = REGNO (operands[0]);
14947 unsigned dest_lo = dest_hi + 1;
14948
14949 gcc_assert (!IN_RANGE (REGNO (operands[1]), dest_hi, dest_lo));
14950 gcc_assert (!IN_RANGE (REGNO (operands[2]), dest_hi, dest_lo));
14951
14952 operands[3] = gen_rtx_REG (<FP128_64>mode, dest_hi);
14953 operands[4] = gen_rtx_REG (<FP128_64>mode, dest_lo);
14954 }
14955 [(set_attr "type" "fp")
14956 (set_attr "length" "8")])
14957
14958 (define_insn_and_split "pack<mode>_soft"
14959 [(set (match_operand:FMOVE128 0 "register_operand" "=&r")
14960 (unspec:FMOVE128
14961 [(match_operand:<FP128_64> 1 "register_operand" "r")
14962 (match_operand:<FP128_64> 2 "register_operand" "r")]
14963 UNSPEC_PACK_128BIT))]
14964 "FLOAT128_2REG_P (<MODE>mode) && TARGET_SOFT_FLOAT"
14965 "#"
14966 "&& reload_completed"
14967 [(set (match_dup 3) (match_dup 1))
14968 (set (match_dup 4) (match_dup 2))]
14969 {
14970 unsigned dest_hi = REGNO (operands[0]);
14971 unsigned dest_lo = dest_hi + (TARGET_POWERPC64 ? 1 : 2);
14972
14973 gcc_assert (!IN_RANGE (REGNO (operands[1]), dest_hi, dest_lo));
14974 gcc_assert (!IN_RANGE (REGNO (operands[2]), dest_hi, dest_lo));
14975
14976 operands[3] = gen_rtx_REG (<FP128_64>mode, dest_hi);
14977 operands[4] = gen_rtx_REG (<FP128_64>mode, dest_lo);
14978 }
14979 [(set_attr "type" "integer")
14980 (set (attr "length")
14981 (if_then_else
14982 (match_test "TARGET_POWERPC64")
14983 (const_string "8")
14984 (const_string "16")))])
14985
14986 (define_insn "unpack<mode>"
14987 [(set (match_operand:DI 0 "register_operand" "=wa,wa")
14988 (unspec:DI [(match_operand:FMOVE128_VSX 1 "register_operand" "0,wa")
14989 (match_operand:QI 2 "const_0_to_1_operand" "O,i")]
14990 UNSPEC_UNPACK_128BIT))]
14991 "VECTOR_MEM_ALTIVEC_OR_VSX_P (<MODE>mode)"
14992 {
14993 if (REGNO (operands[0]) == REGNO (operands[1]) && INTVAL (operands[2]) == 0)
14994 return ASM_COMMENT_START " xxpermdi to same register";
14995
14996 operands[3] = GEN_INT (INTVAL (operands[2]) == 0 ? 0 : 3);
14997 return "xxpermdi %x0,%x1,%x1,%3";
14998 }
14999 [(set_attr "type" "vecperm")])
15000
15001 (define_insn "pack<mode>"
15002 [(set (match_operand:FMOVE128_VSX 0 "register_operand" "=wa")
15003 (unspec:FMOVE128_VSX
15004 [(match_operand:DI 1 "register_operand" "wa")
15005 (match_operand:DI 2 "register_operand" "wa")]
15006 UNSPEC_PACK_128BIT))]
15007 "TARGET_VSX"
15008 "xxpermdi %x0,%x1,%x2,0"
15009 [(set_attr "type" "vecperm")])
15010
15011
15012
15013 ;; ISA 2.08 IEEE 128-bit floating point support.
15014
15015 (define_insn "add<mode>3"
15016 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15017 (plus:IEEE128
15018 (match_operand:IEEE128 1 "altivec_register_operand" "v")
15019 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
15020 "TARGET_FLOAT128_HW"
15021 "xsaddqp %0,%1,%2"
15022 [(set_attr "type" "vecfloat")
15023 (set_attr "size" "128")])
15024
15025 (define_insn "sub<mode>3"
15026 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15027 (minus:IEEE128
15028 (match_operand:IEEE128 1 "altivec_register_operand" "v")
15029 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
15030 "TARGET_FLOAT128_HW"
15031 "xssubqp %0,%1,%2"
15032 [(set_attr "type" "vecfloat")
15033 (set_attr "size" "128")])
15034
15035 (define_insn "mul<mode>3"
15036 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15037 (mult:IEEE128
15038 (match_operand:IEEE128 1 "altivec_register_operand" "v")
15039 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
15040 "TARGET_FLOAT128_HW"
15041 "xsmulqp %0,%1,%2"
15042 [(set_attr "type" "qmul")
15043 (set_attr "size" "128")])
15044
15045 (define_insn "div<mode>3"
15046 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15047 (div:IEEE128
15048 (match_operand:IEEE128 1 "altivec_register_operand" "v")
15049 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
15050 "TARGET_FLOAT128_HW"
15051 "xsdivqp %0,%1,%2"
15052 [(set_attr "type" "vecdiv")
15053 (set_attr "size" "128")])
15054
15055 (define_insn "sqrt<mode>2"
15056 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15057 (sqrt:IEEE128
15058 (match_operand:IEEE128 1 "altivec_register_operand" "v")))]
15059 "TARGET_FLOAT128_HW"
15060 "xssqrtqp %0,%1"
15061 [(set_attr "type" "vecdiv")
15062 (set_attr "size" "128")])
15063
15064 (define_expand "copysign<mode>3"
15065 [(use (match_operand:IEEE128 0 "altivec_register_operand"))
15066 (use (match_operand:IEEE128 1 "altivec_register_operand"))
15067 (use (match_operand:IEEE128 2 "any_operand"))]
15068 ""
15069 {
15070 /* Middle-end canonicalizes -fabs (x) to copysign (x, -1),
15071 but PowerPC prefers -fabs (x). */
15072 if (CONST_DOUBLE_AS_FLOAT_P (operands[2]))
15073 {
15074 if (real_isneg (CONST_DOUBLE_REAL_VALUE (operands[2])))
15075 {
15076 rtx abs_res = gen_reg_rtx (<MODE>mode);
15077 emit_insn (gen_abs<mode>2 (abs_res, operands[1]));
15078 emit_insn (gen_neg<mode>2 (operands[0], abs_res));
15079 }
15080 else
15081 emit_insn (gen_abs<mode>2 (operands[0], operands[1]));
15082 DONE;
15083 }
15084
15085 if (!altivec_register_operand (operands[2], <MODE>mode))
15086 operands[2] = copy_to_mode_reg (<MODE>mode, operands[2]);
15087
15088 if (TARGET_FLOAT128_HW)
15089 emit_insn (gen_copysign<mode>3_hard (operands[0], operands[1],
15090 operands[2]));
15091 else
15092 emit_insn (gen_copysign<mode>3_soft (operands[0], operands[1],
15093 operands[2]));
15094 DONE;
15095 })
15096
15097 (define_insn "copysign<mode>3_hard"
15098 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15099 (copysign:IEEE128
15100 (match_operand:IEEE128 1 "altivec_register_operand" "v")
15101 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
15102 "TARGET_FLOAT128_HW"
15103 "xscpsgnqp %0,%2,%1"
15104 [(set_attr "type" "vecmove")
15105 (set_attr "size" "128")])
15106
15107 (define_insn "copysign<mode>3_soft"
15108 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15109 (copysign:IEEE128
15110 (match_operand:IEEE128 1 "altivec_register_operand" "v")
15111 (match_operand:IEEE128 2 "altivec_register_operand" "v")))
15112 (clobber (match_scratch:IEEE128 3 "=&v"))]
15113 "!TARGET_FLOAT128_HW"
15114 "xscpsgndp %x3,%x2,%x1\;xxpermdi %x0,%x3,%x1,1"
15115 [(set_attr "type" "veccomplex")
15116 (set_attr "length" "8")])
15117
15118 (define_insn "@neg<mode>2_hw"
15119 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15120 (neg:IEEE128
15121 (match_operand:IEEE128 1 "altivec_register_operand" "v")))]
15122 "TARGET_FLOAT128_HW"
15123 "xsnegqp %0,%1"
15124 [(set_attr "type" "vecmove")
15125 (set_attr "size" "128")])
15126
15127
15128 (define_insn "@abs<mode>2_hw"
15129 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15130 (abs:IEEE128
15131 (match_operand:IEEE128 1 "altivec_register_operand" "v")))]
15132 "TARGET_FLOAT128_HW"
15133 "xsabsqp %0,%1"
15134 [(set_attr "type" "vecmove")
15135 (set_attr "size" "128")])
15136
15137
15138 (define_insn "*nabs<mode>2_hw"
15139 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15140 (neg:IEEE128
15141 (abs:IEEE128
15142 (match_operand:IEEE128 1 "altivec_register_operand" "v"))))]
15143 "TARGET_FLOAT128_HW"
15144 "xsnabsqp %0,%1"
15145 [(set_attr "type" "vecmove")
15146 (set_attr "size" "128")])
15147
15148 ;; Initially don't worry about doing fusion
15149 (define_insn "fma<mode>4_hw"
15150 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15151 (fma:IEEE128
15152 (match_operand:IEEE128 1 "altivec_register_operand" "%v")
15153 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15154 (match_operand:IEEE128 3 "altivec_register_operand" "0")))]
15155 "TARGET_FLOAT128_HW"
15156 "xsmaddqp %0,%1,%2"
15157 [(set_attr "type" "qmul")
15158 (set_attr "size" "128")])
15159
15160 (define_insn "*fms<mode>4_hw"
15161 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15162 (fma:IEEE128
15163 (match_operand:IEEE128 1 "altivec_register_operand" "%v")
15164 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15165 (neg:IEEE128
15166 (match_operand:IEEE128 3 "altivec_register_operand" "0"))))]
15167 "TARGET_FLOAT128_HW"
15168 "xsmsubqp %0,%1,%2"
15169 [(set_attr "type" "qmul")
15170 (set_attr "size" "128")])
15171
15172 (define_insn "*nfma<mode>4_hw"
15173 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15174 (neg:IEEE128
15175 (fma:IEEE128
15176 (match_operand:IEEE128 1 "altivec_register_operand" "%v")
15177 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15178 (match_operand:IEEE128 3 "altivec_register_operand" "0"))))]
15179 "TARGET_FLOAT128_HW"
15180 "xsnmaddqp %0,%1,%2"
15181 [(set_attr "type" "qmul")
15182 (set_attr "size" "128")])
15183
15184 (define_insn "*nfms<mode>4_hw"
15185 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15186 (neg:IEEE128
15187 (fma:IEEE128
15188 (match_operand:IEEE128 1 "altivec_register_operand" "%v")
15189 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15190 (neg:IEEE128
15191 (match_operand:IEEE128 3 "altivec_register_operand" "0")))))]
15192 "TARGET_FLOAT128_HW"
15193 "xsnmsubqp %0,%1,%2"
15194 [(set_attr "type" "qmul")
15195 (set_attr "size" "128")])
15196
15197 (define_insn "extend<SFDF:mode><IEEE128:mode>2_hw"
15198 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15199 (float_extend:IEEE128
15200 (match_operand:SFDF 1 "altivec_register_operand" "v")))]
15201 "TARGET_FLOAT128_HW"
15202 "xscvdpqp %0,%1"
15203 [(set_attr "type" "vecfloat")
15204 (set_attr "size" "128")])
15205
15206 ;; Conversion between KFmode and TFmode if TFmode is ieee 128-bit floating
15207 ;; point is a simple copy.
15208 (define_insn_and_split "*extendkftf2"
15209 [(set (match_operand:TF 0 "vsx_register_operand" "=wa,?wa")
15210 (float_extend:TF (match_operand:KF 1 "vsx_register_operand" "0,wa")))]
15211 "TARGET_FLOAT128_TYPE && TARGET_IEEEQUAD"
15212 "@
15213 #
15214 xxlor %x0,%x1,%x1"
15215 "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
15216 [(const_int 0)]
15217 {
15218 emit_note (NOTE_INSN_DELETED);
15219 DONE;
15220 }
15221 [(set_attr "type" "*,veclogical")
15222 (set_attr "length" "0,4")])
15223
15224 (define_insn_and_split "*extendtfkf2"
15225 [(set (match_operand:KF 0 "vsx_register_operand" "=wa,?wa")
15226 (float_extend:KF (match_operand:TF 1 "vsx_register_operand" "0,wa")))]
15227 "TARGET_FLOAT128_TYPE && TARGET_IEEEQUAD"
15228 "@
15229 #
15230 xxlor %x0,%x1,%x1"
15231 "&& reload_completed && REGNO (operands[0]) == REGNO (operands[1])"
15232 [(const_int 0)]
15233 {
15234 emit_note (NOTE_INSN_DELETED);
15235 DONE;
15236 }
15237 [(set_attr "type" "*,veclogical")
15238 (set_attr "length" "0,4")])
15239
15240 (define_insn "trunc<mode>df2_hw"
15241 [(set (match_operand:DF 0 "altivec_register_operand" "=v")
15242 (float_truncate:DF
15243 (match_operand:IEEE128 1 "altivec_register_operand" "v")))]
15244 "TARGET_FLOAT128_HW"
15245 "xscvqpdp %0,%1"
15246 [(set_attr "type" "vecfloat")
15247 (set_attr "size" "128")])
15248
15249 ;; There is no KFmode -> SFmode instruction. Preserve the accuracy by doing
15250 ;; the KFmode -> DFmode conversion using round to odd rather than the normal
15251 ;; conversion
15252 (define_insn_and_split "trunc<mode>sf2_hw"
15253 [(set (match_operand:SF 0 "vsx_register_operand" "=wa")
15254 (float_truncate:SF
15255 (match_operand:IEEE128 1 "altivec_register_operand" "v")))
15256 (clobber (match_scratch:DF 2 "=v"))]
15257 "TARGET_FLOAT128_HW"
15258 "#"
15259 "&& 1"
15260 [(set (match_dup 2)
15261 (unspec:DF [(match_dup 1)]
15262 UNSPEC_TRUNC_ROUND_TO_ODD))
15263 (set (match_dup 0)
15264 (float_truncate:SF (match_dup 2)))]
15265 {
15266 if (GET_CODE (operands[2]) == SCRATCH)
15267 operands[2] = gen_reg_rtx (DFmode);
15268 }
15269 [(set_attr "type" "vecfloat")
15270 (set_attr "length" "8")
15271 (set_attr "isa" "p8v")])
15272
15273 ;; Conversion between IEEE 128-bit and integer types
15274
15275 ;; The fix function for DImode and SImode was declared earlier as a
15276 ;; define_expand. It calls into rs6000_expand_float128_convert if we don't
15277 ;; have IEEE 128-bit hardware support. QImode and HImode are not provided
15278 ;; unless we have the IEEE 128-bit hardware.
15279 ;;
15280 ;; Unlike the code for converting SFmode/DFmode to QImode/HImode, we don't have
15281 ;; to provide a GPR target that used direct move and a conversion in the GPR
15282 ;; which works around QImode/HImode not being allowed in vector registers in
15283 ;; ISA 2.07 (power8).
15284 (define_insn "fix<uns>_<IEEE128:mode><SDI:mode>2_hw"
15285 [(set (match_operand:SDI 0 "altivec_register_operand" "=v")
15286 (any_fix:SDI (match_operand:IEEE128 1 "altivec_register_operand" "v")))]
15287 "TARGET_FLOAT128_HW"
15288 "xscvqp<su><wd>z %0,%1"
15289 [(set_attr "type" "vecfloat")
15290 (set_attr "size" "128")])
15291
15292 (define_insn "fix<uns>_trunc<IEEE128:mode><QHI:mode>2"
15293 [(set (match_operand:QHI 0 "altivec_register_operand" "=v")
15294 (any_fix:QHI
15295 (match_operand:IEEE128 1 "altivec_register_operand" "v")))]
15296 "TARGET_FLOAT128_HW"
15297 "xscvqp<su>wz %0,%1"
15298 [(set_attr "type" "vecfloat")
15299 (set_attr "size" "128")])
15300
15301 ;; Combiner patterns to prevent moving the result of converting an IEEE 128-bit
15302 ;; floating point value to 8/16/32-bit integer to GPR in order to save it.
15303 (define_insn_and_split "*fix<uns>_trunc<IEEE128:mode><QHSI:mode>2_mem"
15304 [(set (match_operand:QHSI 0 "memory_operand" "=Z")
15305 (any_fix:QHSI
15306 (match_operand:IEEE128 1 "altivec_register_operand" "v")))
15307 (clobber (match_scratch:QHSI 2 "=v"))]
15308 "TARGET_FLOAT128_HW"
15309 "#"
15310 "&& reload_completed"
15311 [(set (match_dup 2)
15312 (any_fix:QHSI (match_dup 1)))
15313 (set (match_dup 0)
15314 (match_dup 2))])
15315
15316 (define_insn "float_<mode>di2_hw"
15317 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15318 (float:IEEE128 (match_operand:DI 1 "altivec_register_operand" "v")))]
15319 "TARGET_FLOAT128_HW"
15320 "xscvsdqp %0,%1"
15321 [(set_attr "type" "vecfloat")
15322 (set_attr "size" "128")])
15323
15324 (define_insn_and_split "float_<mode>si2_hw"
15325 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15326 (float:IEEE128 (match_operand:SI 1 "nonimmediate_operand" "vrZ")))
15327 (clobber (match_scratch:DI 2 "=v"))]
15328 "TARGET_FLOAT128_HW"
15329 "#"
15330 "&& 1"
15331 [(set (match_dup 2)
15332 (sign_extend:DI (match_dup 1)))
15333 (set (match_dup 0)
15334 (float:IEEE128 (match_dup 2)))]
15335 {
15336 if (GET_CODE (operands[2]) == SCRATCH)
15337 operands[2] = gen_reg_rtx (DImode);
15338
15339 if (MEM_P (operands[1]))
15340 operands[1] = rs6000_force_indexed_or_indirect_mem (operands[1]);
15341 })
15342
15343 (define_insn_and_split "float<QHI:mode><IEEE128:mode>2"
15344 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v,v,v")
15345 (float:IEEE128 (match_operand:QHI 1 "nonimmediate_operand" "v,r,Z")))
15346 (clobber (match_scratch:DI 2 "=X,r,X"))]
15347 "TARGET_FLOAT128_HW"
15348 "#"
15349 "&& reload_completed"
15350 [(const_int 0)]
15351 {
15352 rtx dest = operands[0];
15353 rtx src = operands[1];
15354 rtx dest_di = gen_rtx_REG (DImode, REGNO (dest));
15355
15356 if (altivec_register_operand (src, <QHI:MODE>mode))
15357 emit_insn (gen_extend<QHI:mode>di2 (dest_di, src));
15358 else if (int_reg_operand (src, <QHI:MODE>mode))
15359 {
15360 rtx ext_di = operands[2];
15361 emit_insn (gen_extend<QHI:mode>di2 (ext_di, src));
15362 emit_move_insn (dest_di, ext_di);
15363 }
15364 else if (MEM_P (src))
15365 {
15366 rtx dest_qhi = gen_rtx_REG (<QHI:MODE>mode, REGNO (dest));
15367 emit_move_insn (dest_qhi, src);
15368 emit_insn (gen_extend<QHI:mode>di2 (dest_di, dest_qhi));
15369 }
15370 else
15371 gcc_unreachable ();
15372
15373 emit_insn (gen_float_<IEEE128:mode>di2_hw (dest, dest_di));
15374 DONE;
15375 }
15376 [(set_attr "length" "8,12,12")
15377 (set_attr "type" "vecfloat")
15378 (set_attr "size" "128")])
15379
15380 (define_insn "floatuns_<mode>di2_hw"
15381 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15382 (unsigned_float:IEEE128
15383 (match_operand:DI 1 "altivec_register_operand" "v")))]
15384 "TARGET_FLOAT128_HW"
15385 "xscvudqp %0,%1"
15386 [(set_attr "type" "vecfloat")
15387 (set_attr "size" "128")])
15388
15389 (define_insn_and_split "floatuns_<mode>si2_hw"
15390 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15391 (unsigned_float:IEEE128
15392 (match_operand:SI 1 "nonimmediate_operand" "vrZ")))
15393 (clobber (match_scratch:DI 2 "=v"))]
15394 "TARGET_FLOAT128_HW"
15395 "#"
15396 "&& 1"
15397 [(set (match_dup 2)
15398 (zero_extend:DI (match_dup 1)))
15399 (set (match_dup 0)
15400 (float:IEEE128 (match_dup 2)))]
15401 {
15402 if (GET_CODE (operands[2]) == SCRATCH)
15403 operands[2] = gen_reg_rtx (DImode);
15404
15405 if (MEM_P (operands[1]))
15406 operands[1] = rs6000_force_indexed_or_indirect_mem (operands[1]);
15407 })
15408
15409 (define_insn_and_split "floatuns<QHI:mode><IEEE128:mode>2"
15410 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v,v,v")
15411 (unsigned_float:IEEE128
15412 (match_operand:QHI 1 "nonimmediate_operand" "v,r,Z")))
15413 (clobber (match_scratch:DI 2 "=X,r,X"))]
15414 "TARGET_FLOAT128_HW"
15415 "#"
15416 "&& reload_completed"
15417 [(const_int 0)]
15418 {
15419 rtx dest = operands[0];
15420 rtx src = operands[1];
15421 rtx dest_di = gen_rtx_REG (DImode, REGNO (dest));
15422
15423 if (altivec_register_operand (src, <QHI:MODE>mode) || MEM_P (src))
15424 emit_insn (gen_zero_extend<QHI:mode>di2 (dest_di, src));
15425 else if (int_reg_operand (src, <QHI:MODE>mode))
15426 {
15427 rtx ext_di = operands[2];
15428 emit_insn (gen_zero_extend<QHI:mode>di2 (ext_di, src));
15429 emit_move_insn (dest_di, ext_di);
15430 }
15431 else
15432 gcc_unreachable ();
15433
15434 emit_insn (gen_floatuns_<IEEE128:mode>di2_hw (dest, dest_di));
15435 DONE;
15436 }
15437 [(set_attr "length" "8,12,8")
15438 (set_attr "type" "vecfloat")
15439 (set_attr "size" "128")])
15440
15441 ;; IEEE 128-bit round to integer built-in functions
15442 (define_insn "floor<mode>2"
15443 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15444 (unspec:IEEE128
15445 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
15446 UNSPEC_FRIM))]
15447 "TARGET_FLOAT128_HW"
15448 "xsrqpi 1,%0,%1,3"
15449 [(set_attr "type" "vecfloat")
15450 (set_attr "size" "128")])
15451
15452 (define_insn "ceil<mode>2"
15453 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15454 (unspec:IEEE128
15455 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
15456 UNSPEC_FRIP))]
15457 "TARGET_FLOAT128_HW"
15458 "xsrqpi 1,%0,%1,2"
15459 [(set_attr "type" "vecfloat")
15460 (set_attr "size" "128")])
15461
15462 (define_insn "btrunc<mode>2"
15463 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15464 (unspec:IEEE128
15465 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
15466 UNSPEC_FRIZ))]
15467 "TARGET_FLOAT128_HW"
15468 "xsrqpi 1,%0,%1,1"
15469 [(set_attr "type" "vecfloat")
15470 (set_attr "size" "128")])
15471
15472 (define_insn "round<mode>2"
15473 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15474 (unspec:IEEE128
15475 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
15476 UNSPEC_FRIN))]
15477 "TARGET_FLOAT128_HW"
15478 "xsrqpi 0,%0,%1,0"
15479 [(set_attr "type" "vecfloat")
15480 (set_attr "size" "128")])
15481
15482 ;; IEEE 128-bit instructions with round to odd semantics
15483 (define_insn "add<mode>3_odd"
15484 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15485 (unspec:IEEE128
15486 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
15487 (match_operand:IEEE128 2 "altivec_register_operand" "v")]
15488 UNSPEC_ADD_ROUND_TO_ODD))]
15489 "TARGET_FLOAT128_HW"
15490 "xsaddqpo %0,%1,%2"
15491 [(set_attr "type" "vecfloat")
15492 (set_attr "size" "128")])
15493
15494 (define_insn "sub<mode>3_odd"
15495 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15496 (unspec:IEEE128
15497 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
15498 (match_operand:IEEE128 2 "altivec_register_operand" "v")]
15499 UNSPEC_SUB_ROUND_TO_ODD))]
15500 "TARGET_FLOAT128_HW"
15501 "xssubqpo %0,%1,%2"
15502 [(set_attr "type" "vecfloat")
15503 (set_attr "size" "128")])
15504
15505 (define_insn "mul<mode>3_odd"
15506 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15507 (unspec:IEEE128
15508 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
15509 (match_operand:IEEE128 2 "altivec_register_operand" "v")]
15510 UNSPEC_MUL_ROUND_TO_ODD))]
15511 "TARGET_FLOAT128_HW"
15512 "xsmulqpo %0,%1,%2"
15513 [(set_attr "type" "qmul")
15514 (set_attr "size" "128")])
15515
15516 (define_insn "div<mode>3_odd"
15517 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15518 (unspec:IEEE128
15519 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
15520 (match_operand:IEEE128 2 "altivec_register_operand" "v")]
15521 UNSPEC_DIV_ROUND_TO_ODD))]
15522 "TARGET_FLOAT128_HW"
15523 "xsdivqpo %0,%1,%2"
15524 [(set_attr "type" "vecdiv")
15525 (set_attr "size" "128")])
15526
15527 (define_insn "sqrt<mode>2_odd"
15528 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15529 (unspec:IEEE128
15530 [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
15531 UNSPEC_SQRT_ROUND_TO_ODD))]
15532 "TARGET_FLOAT128_HW"
15533 "xssqrtqpo %0,%1"
15534 [(set_attr "type" "vecdiv")
15535 (set_attr "size" "128")])
15536
15537 (define_insn "fma<mode>4_odd"
15538 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15539 (unspec:IEEE128
15540 [(match_operand:IEEE128 1 "altivec_register_operand" "v")
15541 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15542 (match_operand:IEEE128 3 "altivec_register_operand" "0")]
15543 UNSPEC_FMA_ROUND_TO_ODD))]
15544 "TARGET_FLOAT128_HW"
15545 "xsmaddqpo %0,%1,%2"
15546 [(set_attr "type" "qmul")
15547 (set_attr "size" "128")])
15548
15549 (define_insn "*fms<mode>4_odd"
15550 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15551 (unspec:IEEE128
15552 [(match_operand:IEEE128 1 "altivec_register_operand" "%v")
15553 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15554 (neg:IEEE128
15555 (match_operand:IEEE128 3 "altivec_register_operand" "0"))]
15556 UNSPEC_FMA_ROUND_TO_ODD))]
15557 "TARGET_FLOAT128_HW"
15558 "xsmsubqpo %0,%1,%2"
15559 [(set_attr "type" "qmul")
15560 (set_attr "size" "128")])
15561
15562 (define_insn "*nfma<mode>4_odd"
15563 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15564 (neg:IEEE128
15565 (unspec:IEEE128
15566 [(match_operand:IEEE128 1 "altivec_register_operand" "%v")
15567 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15568 (match_operand:IEEE128 3 "altivec_register_operand" "0")]
15569 UNSPEC_FMA_ROUND_TO_ODD)))]
15570 "TARGET_FLOAT128_HW"
15571 "xsnmaddqpo %0,%1,%2"
15572 [(set_attr "type" "qmul")
15573 (set_attr "size" "128")])
15574
15575 (define_insn "*nfms<mode>4_odd"
15576 [(set (match_operand:IEEE128 0 "altivec_register_operand" "=v")
15577 (neg:IEEE128
15578 (unspec:IEEE128
15579 [(match_operand:IEEE128 1 "altivec_register_operand" "%v")
15580 (match_operand:IEEE128 2 "altivec_register_operand" "v")
15581 (neg:IEEE128
15582 (match_operand:IEEE128 3 "altivec_register_operand" "0"))]
15583 UNSPEC_FMA_ROUND_TO_ODD)))]
15584 "TARGET_FLOAT128_HW"
15585 "xsnmsubqpo %0,%1,%2"
15586 [(set_attr "type" "qmul")
15587 (set_attr "size" "128")])
15588
15589 (define_insn "trunc<mode>df2_odd"
15590 [(set (match_operand:DF 0 "vsx_register_operand" "=v")
15591 (unspec:DF [(match_operand:IEEE128 1 "altivec_register_operand" "v")]
15592 UNSPEC_TRUNC_ROUND_TO_ODD))]
15593 "TARGET_FLOAT128_HW"
15594 "xscvqpdpo %0,%1"
15595 [(set_attr "type" "vecfloat")
15596 (set_attr "size" "128")])
15597
15598 ;; IEEE 128-bit comparisons
15599 (define_insn "*cmp<mode>_hw"
15600 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
15601 (compare:CCFP (match_operand:IEEE128 1 "altivec_register_operand" "v")
15602 (match_operand:IEEE128 2 "altivec_register_operand" "v")))]
15603 "TARGET_FLOAT128_HW"
15604 "xscmpuqp %0,%1,%2"
15605 [(set_attr "type" "veccmp")
15606 (set_attr "size" "128")])
15607
15608 ;; Miscellaneous ISA 3.0 (power9) instructions
15609
15610 (define_expand "darn_32_<mode>"
15611 [(use (match_operand:GPR 0 "register_operand"))]
15612 "TARGET_P9_MISC"
15613 {
15614 emit_insn (gen_darn (<MODE>mode, operands[0], const0_rtx));
15615 DONE;
15616 })
15617
15618 (define_expand "darn_64_<mode>"
15619 [(use (match_operand:GPR 0 "register_operand"))]
15620 "TARGET_P9_MISC"
15621 {
15622 emit_insn (gen_darn (<MODE>mode, operands[0], const1_rtx));
15623 DONE;
15624 })
15625
15626 (define_expand "darn_raw_<mode>"
15627 [(use (match_operand:GPR 0 "register_operand"))]
15628 "TARGET_P9_MISC"
15629 {
15630 emit_insn (gen_darn (<MODE>mode, operands[0], const2_rtx));
15631 DONE;
15632 })
15633
15634 (define_insn "@darn<mode>"
15635 [(set (match_operand:GPR 0 "register_operand" "=r")
15636 (unspec_volatile:GPR [(match_operand 1 "const_int_operand" "n")]
15637 UNSPECV_DARN))]
15638 "TARGET_P9_MISC"
15639 "darn %0,%1"
15640 [(set_attr "type" "integer")])
15641
15642 ;; Test byte within range.
15643 ;;
15644 ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx
15645 ;; represents a byte whose value is ignored in this context and
15646 ;; vv, the least significant byte, holds the byte value that is to
15647 ;; be tested for membership within the range specified by operand 2.
15648 ;; The bytes of operand 2 are organized as xx:xx:hi:lo.
15649 ;;
15650 ;; Return in target register operand 0 a value of 1 if lo <= vv and
15651 ;; vv <= hi. Otherwise, set register operand 0 to 0.
15652 ;;
15653 ;; Though the instructions to which this expansion maps operate on
15654 ;; 64-bit registers, the current implementation only operates on
15655 ;; SI-mode operands as the high-order bits provide no information
15656 ;; that is not already available in the low-order bits. To avoid the
15657 ;; costs of data widening operations, future enhancements might allow
15658 ;; DI mode for operand 0 and/or might allow operand 1 to be QI mode.
15659 (define_expand "cmprb"
15660 [(set (match_dup 3)
15661 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15662 (match_operand:SI 2 "gpc_reg_operand" "r")]
15663 UNSPEC_CMPRB))
15664 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
15665 (if_then_else:SI (lt (match_dup 3)
15666 (const_int 0))
15667 (const_int -1)
15668 (if_then_else (gt (match_dup 3)
15669 (const_int 0))
15670 (const_int 1)
15671 (const_int 0))))]
15672 "TARGET_P9_MISC"
15673 {
15674 operands[3] = gen_reg_rtx (CCmode);
15675 })
15676
15677 ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx
15678 ;; represents a byte whose value is ignored in this context and
15679 ;; vv, the least significant byte, holds the byte value that is to
15680 ;; be tested for membership within the range specified by operand 2.
15681 ;; The bytes of operand 2 are organized as xx:xx:hi:lo.
15682 ;;
15683 ;; Set bit 1 (the GT bit, 0x4) of CR register operand 0 to 1 if
15684 ;; lo <= vv and vv <= hi. Otherwise, set the GT bit to 0. The other
15685 ;; 3 bits of the target CR register are all set to 0.
15686 (define_insn "*cmprb_internal"
15687 [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15688 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15689 (match_operand:SI 2 "gpc_reg_operand" "r")]
15690 UNSPEC_CMPRB))]
15691 "TARGET_P9_MISC"
15692 "cmprb %0,0,%1,%2"
15693 [(set_attr "type" "logical")])
15694
15695 ;; Set operand 0 register to -1 if the LT bit (0x8) of condition
15696 ;; register operand 1 is on. Otherwise, set operand 0 register to 1
15697 ;; if the GT bit (0x4) of condition register operand 1 is on.
15698 ;; Otherwise, set operand 0 to 0. Note that the result stored into
15699 ;; register operand 0 is non-zero iff either the LT or GT bits are on
15700 ;; within condition register operand 1.
15701 (define_insn "setb_signed"
15702 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15703 (if_then_else:SI (lt (match_operand:CC 1 "cc_reg_operand" "y")
15704 (const_int 0))
15705 (const_int -1)
15706 (if_then_else (gt (match_dup 1)
15707 (const_int 0))
15708 (const_int 1)
15709 (const_int 0))))]
15710 "TARGET_P9_MISC"
15711 "setb %0,%1"
15712 [(set_attr "type" "logical")])
15713
15714 (define_insn "setb_unsigned"
15715 [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
15716 (if_then_else:SI (ltu (match_operand:CCUNS 1 "cc_reg_operand" "y")
15717 (const_int 0))
15718 (const_int -1)
15719 (if_then_else (gtu (match_dup 1)
15720 (const_int 0))
15721 (const_int 1)
15722 (const_int 0))))]
15723 "TARGET_P9_MISC"
15724 "setb %0,%1"
15725 [(set_attr "type" "logical")])
15726
15727 ;; Test byte within two ranges.
15728 ;;
15729 ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx
15730 ;; represents a byte whose value is ignored in this context and
15731 ;; vv, the least significant byte, holds the byte value that is to
15732 ;; be tested for membership within the range specified by operand 2.
15733 ;; The bytes of operand 2 are organized as hi_1:lo_1:hi_2:lo_2.
15734 ;;
15735 ;; Return in target register operand 0 a value of 1 if (lo_1 <= vv and
15736 ;; vv <= hi_1) or if (lo_2 <= vv and vv <= hi_2). Otherwise, set register
15737 ;; operand 0 to 0.
15738 ;;
15739 ;; Though the instructions to which this expansion maps operate on
15740 ;; 64-bit registers, the current implementation only operates on
15741 ;; SI-mode operands as the high-order bits provide no information
15742 ;; that is not already available in the low-order bits. To avoid the
15743 ;; costs of data widening operations, future enhancements might allow
15744 ;; DI mode for operand 0 and/or might allow operand 1 to be QI mode.
15745 (define_expand "cmprb2"
15746 [(set (match_dup 3)
15747 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15748 (match_operand:SI 2 "gpc_reg_operand" "r")]
15749 UNSPEC_CMPRB2))
15750 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
15751 (if_then_else:SI (lt (match_dup 3)
15752 (const_int 0))
15753 (const_int -1)
15754 (if_then_else (gt (match_dup 3)
15755 (const_int 0))
15756 (const_int 1)
15757 (const_int 0))))]
15758 "TARGET_P9_MISC"
15759 {
15760 operands[3] = gen_reg_rtx (CCmode);
15761 })
15762
15763 ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx
15764 ;; represents a byte whose value is ignored in this context and
15765 ;; vv, the least significant byte, holds the byte value that is to
15766 ;; be tested for membership within the ranges specified by operand 2.
15767 ;; The bytes of operand 2 are organized as hi_1:lo_1:hi_2:lo_2.
15768 ;;
15769 ;; Set bit 1 (the GT bit, 0x4) of CR register operand 0 to 1 if
15770 ;; (lo_1 <= vv and vv <= hi_1) or if (lo_2 <= vv and vv <= hi_2).
15771 ;; Otherwise, set the GT bit to 0. The other 3 bits of the target
15772 ;; CR register are all set to 0.
15773 (define_insn "*cmprb2_internal"
15774 [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15775 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15776 (match_operand:SI 2 "gpc_reg_operand" "r")]
15777 UNSPEC_CMPRB2))]
15778 "TARGET_P9_MISC"
15779 "cmprb %0,1,%1,%2"
15780 [(set_attr "type" "logical")])
15781
15782 ;; Test byte membership within set of 8 bytes.
15783 ;;
15784 ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx
15785 ;; represents a byte whose value is ignored in this context and
15786 ;; vv, the least significant byte, holds the byte value that is to
15787 ;; be tested for membership within the set specified by operand 2.
15788 ;; The bytes of operand 2 are organized as e0:e1:e2:e3:e4:e5:e6:e7.
15789 ;;
15790 ;; Return in target register operand 0 a value of 1 if vv equals one
15791 ;; of the values e0, e1, e2, e3, e4, e5, e6, or e7. Otherwise, set
15792 ;; register operand 0 to 0. Note that the 8 byte values held within
15793 ;; operand 2 need not be unique.
15794 ;;
15795 ;; Though the instructions to which this expansion maps operate on
15796 ;; 64-bit registers, the current implementation requires that operands
15797 ;; 0 and 1 have mode SI as the high-order bits provide no information
15798 ;; that is not already available in the low-order bits. To avoid the
15799 ;; costs of data widening operations, future enhancements might allow
15800 ;; DI mode for operand 0 and/or might allow operand 1 to be QI mode.
15801 (define_expand "cmpeqb"
15802 [(set (match_dup 3)
15803 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15804 (match_operand:DI 2 "gpc_reg_operand" "r")]
15805 UNSPEC_CMPEQB))
15806 (set (match_operand:SI 0 "gpc_reg_operand" "=r")
15807 (if_then_else:SI (lt (match_dup 3)
15808 (const_int 0))
15809 (const_int -1)
15810 (if_then_else (gt (match_dup 3)
15811 (const_int 0))
15812 (const_int 1)
15813 (const_int 0))))]
15814 "TARGET_P9_MISC && TARGET_64BIT"
15815 {
15816 operands[3] = gen_reg_rtx (CCmode);
15817 })
15818
15819 ;; The bytes of operand 1 are organized as xx:xx:xx:vv, where xx
15820 ;; represents a byte whose value is ignored in this context and
15821 ;; vv, the least significant byte, holds the byte value that is to
15822 ;; be tested for membership within the set specified by operand 2.
15823 ;; The bytes of operand 2 are organized as e0:e1:e2:e3:e4:e5:e6:e7.
15824 ;;
15825 ;; Set bit 1 (the GT bit, 0x4) of CR register operand 0 to 1 if vv
15826 ;; equals one of the values e0, e1, e2, e3, e4, e5, e6, or e7. Otherwise,
15827 ;; set the GT bit to zero. The other 3 bits of the target CR register
15828 ;; are all set to 0.
15829 (define_insn "*cmpeqb_internal"
15830 [(set (match_operand:CC 0 "cc_reg_operand" "=y")
15831 (unspec:CC [(match_operand:SI 1 "gpc_reg_operand" "r")
15832 (match_operand:DI 2 "gpc_reg_operand" "r")]
15833 UNSPEC_CMPEQB))]
15834 "TARGET_P9_MISC && TARGET_64BIT"
15835 "cmpeqb %0,%1,%2"
15836 [(set_attr "type" "logical")])
15837
15838
15839 ;; ROP mitigation instructions.
15840
15841 (define_insn "hashst"
15842 [(set (match_operand:DI 0 "simple_offsettable_mem_operand" "=m")
15843 (unspec_volatile:DI [(match_operand:DI 1 "int_reg_operand" "r")]
15844 UNSPEC_HASHST))]
15845 "rs6000_rop_protect"
15846 {
15847 static char templ[32];
15848 const char *p = rs6000_privileged ? "p" : "";
15849 sprintf (templ, "hashst%s %%1,%%0", p);
15850 return templ;
15851 }
15852 [(set_attr "type" "store")])
15853
15854 (define_insn "hashchk"
15855 [(unspec_volatile [(match_operand:DI 0 "int_reg_operand" "r")
15856 (match_operand:DI 1 "simple_offsettable_mem_operand" "m")]
15857 UNSPEC_HASHCHK)]
15858 "rs6000_rop_protect"
15859 {
15860 static char templ[32];
15861 const char *p = rs6000_privileged ? "p" : "";
15862 sprintf (templ, "hashchk%s %%0,%%1", p);
15863 return templ;
15864 }
15865 [(set_attr "type" "load")])
15866
15867
15868 (include "sync.md")
15869 (include "vector.md")
15870 (include "vsx.md")
15871 (include "altivec.md")
15872 (include "mma.md")
15873 (include "dfp.md")
15874 (include "crypto.md")
15875 (include "htm.md")
15876 (include "fusion.md")
15877 (include "pcrel-opt.md")