OSDN Git Service

fix typo in nor.
[pf3gnuchains/gcc-fork.git] / gcc / config / rs6000 / rs6000.md
1 ;; Machine description for IBM RISC System 6000 (POWER) for GNU C compiler
2 ;; Copyright (C) 1990, 91, 92, 93, 94, 95, 1996 Free Software Foundation, Inc.
3 ;; Contributed by Richard Kenner (kenner@vlsi1.ultra.nyu.edu)
4
5 ;; This file is part of GNU CC.
6
7 ;; GNU CC is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
12 ;; GNU CC is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU CC; see the file COPYING.  If not, write to
19 ;; the Free Software Foundation, 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
21
22 ;;- See file "rtl.def" for documentation on define_insn, match_*, et. al.
23 \f
24 ;; Define an insn type attribute.  This is used in function unit delay
25 ;; computations.
26 (define_attr "type" "integer,load,fpload,imul,idiv,branch,compare,delayed_compare,fpcompare,mtjmpr,fp,dmul,sdiv,ddiv,ssqrt,dsqrt,jmpreg"
27   (const_string "integer"))
28
29 ;; Length (in bytes).
30 (define_attr "length" ""
31   (if_then_else (eq_attr "type" "branch")
32                 (if_then_else (and (ge (minus (pc) (match_dup 0))
33                                        (const_int -32768))
34                                    (lt (minus (pc) (match_dup 0))
35                                        (const_int 32767)))
36                               (const_int 8)
37                               (const_int 12))
38                 (const_int 4)))
39
40 ;; Processor type -- this attribute must exactly match the processor_type
41 ;; enumeration in rs6000.h.
42
43 (define_attr "cpu" "rios1,rios2,mpccore,ppc403,ppc601,ppc602,ppc603,ppc604,ppc620"
44   (const (symbol_ref "rs6000_cpu_attr")))
45
46 ; (define_function_unit NAME MULTIPLICITY SIMULTANEITY
47 ;                       TEST READY-DELAY ISSUE-DELAY [CONFLICT-LIST])
48
49 ; Load/Store Unit -- POWER/2 and pure PowerPC only
50 ; (POWER and 601 use Integer Unit)
51 (define_function_unit "lsu" 1 0
52   (and (eq_attr "type" "load")
53        (eq_attr "cpu" "mpccore,ppc602,ppc603,ppc604,ppc620"))
54   2 1)
55
56 (define_function_unit "lsu" 1 0
57   (and (eq_attr "type" "fpload")
58        (eq_attr "cpu" "ppc604,ppc620"))
59   3 1)
60
61 (define_function_unit "lsu" 1 0
62   (and (eq_attr "type" "fpload")
63        (eq_attr "cpu" "mpccore,ppc602,ppc603"))
64   2 1)
65
66 (define_function_unit "iu" 1 0
67   (and (eq_attr "type" "load")
68        (eq_attr "cpu" "rios1,ppc601,ppc403"))
69   2 1)
70
71 (define_function_unit "iu" 1 0
72   (and (eq_attr "type" "fpload")
73        (eq_attr "cpu" "rios1,ppc601"))
74   2 0)
75
76 ; Integer Unit (RIOS1, PPC601, PPC603)
77 ; Trivial operations take one cycle which need not be listed here.
78 (define_function_unit "iu" 1 0
79   (and (eq_attr "type" "imul")
80        (eq_attr "cpu" "rios1"))
81   3 3)
82
83 (define_function_unit "iu" 1 0
84   (and (eq_attr "type" "imul")
85        (eq_attr "cpu" "ppc403"))
86   4 4)
87
88 (define_function_unit "iu" 1 0
89   (and (eq_attr "type" "imul")
90        (eq_attr "cpu" "ppc601,ppc602,ppc603"))
91   5 5)
92
93 (define_function_unit "iu" 1 0
94   (and (eq_attr "type" "idiv")
95        (eq_attr "cpu" "rios1"))
96   19 19)
97
98 (define_function_unit "iu" 1 0
99   (and (eq_attr "type" "idiv")
100        (eq_attr "cpu" "ppc601"))
101   36 36)
102
103 (define_function_unit "iu" 1 0
104   (and (eq_attr "type" "idiv")
105        (eq_attr "cpu" "ppc403"))
106   33 33)
107
108 (define_function_unit "iu" 1 0
109   (and (eq_attr "type" "idiv")
110        (eq_attr "cpu" "ppc602,ppc603"))
111   37 36)
112
113 ; RIOS2 has two integer units: a primary one which can perform all
114 ; operations and a secondary one which is fed in lock step with the first
115 ; and can perform "simple" integer operations.  
116 ; To catch this we define a 'dummy' imuldiv-unit that is also needed
117 ; for the complex insns. 
118 (define_function_unit "iu2" 2 0
119   (and (eq_attr "type" "integer")
120        (eq_attr "cpu" "rios2"))
121   1 0)
122
123 (define_function_unit "iu2" 2 0
124   (and (eq_attr "type" "imul")
125        (eq_attr "cpu" "rios2"))
126   2 2)
127
128 (define_function_unit "iu2" 2 0
129   (and (eq_attr "type" "idiv")
130        (eq_attr "cpu" "rios2"))
131   13 13)
132
133 (define_function_unit "imuldiv" 1 0
134   (and (eq_attr "type" "imul")
135        (eq_attr "cpu" "rios2"))
136   2 2)
137
138
139 (define_function_unit "imuldiv" 1 0
140   (and (eq_attr "type" "idiv")
141        (eq_attr "cpu" "rios2"))
142   13 13)
143
144 ; MPCCORE has separate IMUL/IDIV unit for multicycle instructions
145 ; Divide latency varies greatly from 2-11, use 6 as average
146 (define_function_unit "imuldiv" 1 0
147   (and (eq_attr "type" "imul")
148        (eq_attr "cpu" "mpccore"))
149   2 1)
150
151 (define_function_unit "imuldiv" 1 0
152   (and (eq_attr "type" "idiv")
153        (eq_attr "cpu" "mpccore"))
154   6 6)
155
156 ; PPC604 has two units that perform integer operations
157 ; and one unit for divide/multiply operations (and move
158 ; from/to spr).
159 (define_function_unit "iu2" 2 0
160   (and (eq_attr "type" "integer")
161        (eq_attr "cpu" "ppc604,ppc620"))
162   1 1
163   [(eq_attr "type" "imul,idiv")])
164
165 (define_function_unit "imuldiv" 1 0
166   (and (eq_attr "type" "imul")
167        (eq_attr "cpu" "ppc604,ppc620"))
168   4 2
169   [(eq_attr "type" "integer")])
170
171 (define_function_unit "imuldiv" 1 0
172   (and (eq_attr "type" "idiv")
173        (eq_attr "cpu" "ppc604,ppc620"))
174   20 19
175   [(eq_attr "type" "integer")])
176
177 ; compare is done on integer unit, but feeds insns which
178 ; execute on the branch unit.  Ready-delay of the compare 
179 ; on the branch unit is large (3-5 cycles).  On the iu/fpu
180 ; it is 1.  One drawback is that the compare will also be 
181 ; assigned to the bpu, but this inaccuracy is worth for being
182 ; able to fill the compare-branch delay, with insns on iu/fpu.
183 (define_function_unit "iu" 1 0   
184   (and (eq_attr "type" "compare")
185        (eq_attr "cpu" "rios1,mpccore,ppc601"))
186   1 1)
187
188 (define_function_unit "iu2" 2 0   
189   (and (eq_attr "type" "compare")
190        (eq_attr "cpu" "rios2"))
191   1 1)
192
193 (define_function_unit "bpu" 1 0   
194   (and (eq_attr "type" "compare")
195        (eq_attr "cpu" "rios1,rios2,ppc403,mpccore,ppc601,ppc603,ppc604,ppc620"))
196   4 1)
197
198 ; different machines have different compare timings
199 ; in ppc604, compare is done on the one of the two
200 ; main integer units.
201 (define_function_unit "iu2" 2 0
202   (and (eq_attr "type" "compare")
203        (eq_attr "cpu" "ppc604,ppc620"))
204   1 1)
205
206 (define_function_unit "bpu" 1 0
207   (eq_attr "type" "delayed_compare")
208   5 0)
209
210 ; fp compare uses fp unit
211 (define_function_unit "fpu" 1 0
212   (and (eq_attr "type" "fpcompare")
213        (eq_attr "cpu" "rios1"))
214   8 1)
215
216 ; rios1 and rios2 have different fpcompare delays
217 (define_function_unit "fpu2" 2 0
218   (and (eq_attr "type" "fpcompare")
219        (eq_attr "cpu" "rios2"))
220   5 1)
221
222 ; on ppc601 and ppc603, fpcompare takes also 2 cycles from
223 ; the integer unit
224 ; here we do not define delays, just occupy the unit. The dependencies
225 ; will be signed by the fpcompare definition in the fpu.
226 (define_function_unit "iu" 1 0
227   (and (eq_attr "type" "fpcompare")
228        (eq_attr "cpu" "ppc601,ppc602,ppc603"))
229   0 2)
230
231 ; fp compare uses fp unit
232 (define_function_unit "fpu" 1 0
233   (and (eq_attr "type" "fpcompare")
234        (eq_attr "cpu" "ppc601,ppc602,ppc603,ppc604,ppc620"))
235   5 1)
236
237 (define_function_unit "fpu" 1 0
238   (and (eq_attr "type" "fpcompare")
239        (eq_attr "cpu" "mpccore"))
240   1 1)
241
242 (define_function_unit "bpu" 1 0
243   (and (eq_attr "type" "mtjmpr")
244        (eq_attr "cpu" "rios1,rios2"))
245   5 0)
246
247 (define_function_unit "bpu" 1 0
248   (and (eq_attr "type" "mtjmpr")
249        (eq_attr "cpu" "ppc403,mpccore,ppc601,ppc602,ppc603,ppc604,ppc620"))
250   4 0)
251
252 ; all jumps/branches are executing on the bpu, in 1 cycle, for all machines.
253 (define_function_unit "bpu" 1 0
254   (eq_attr "type" "jmpreg")
255   1 0)
256
257 (define_function_unit "bpu" 1 0
258   (eq_attr "type" "branch")
259   1 0)
260
261 ; Floating Point Unit
262 (define_function_unit "fpu" 1 0
263   (and (eq_attr "type" "fp,dmul")
264        (eq_attr "cpu" "rios1"))
265   2 0)
266
267 (define_function_unit "fpu" 1 0
268   (and (eq_attr "type" "fp")
269        (eq_attr "cpu" "mpccore"))
270   4 4)
271
272 (define_function_unit "fpu" 1 0
273   (and (eq_attr "type" "fp")
274        (eq_attr "cpu" "ppc601"))
275   4 0)
276
277 (define_function_unit "fpu" 1 0
278   (and (eq_attr "type" "fp")
279        (eq_attr "cpu" "ppc602,ppc603,ppc604,ppc620"))
280   3 1)
281
282 (define_function_unit "fpu" 1 0
283   (and (eq_attr "type" "dmul")
284        (eq_attr "cpu" "mpccore"))
285   5 5)
286
287 (define_function_unit "fpu" 1 0
288   (and (eq_attr "type" "dmul")
289        (eq_attr "cpu" "ppc601"))
290   5 2)
291
292 ; is this true?
293 (define_function_unit "fpu" 1 0
294   (and (eq_attr "type" "dmul")
295        (eq_attr "cpu" "ppc602,ppc603"))
296   4 2)
297
298 (define_function_unit "fpu" 1 0
299   (and (eq_attr "type" "dmul")
300        (eq_attr "cpu" "ppc604,ppc620"))
301   3 1)
302
303 (define_function_unit "fpu" 1 0
304   (and (eq_attr "type" "sdiv,ddiv")
305        (eq_attr "cpu" "rios1"))
306   19 19)
307
308 (define_function_unit "fpu" 1 0
309   (and (eq_attr "type" "sdiv")
310        (eq_attr "cpu" "ppc601"))
311   17 17)
312
313 (define_function_unit "fpu" 1 0
314   (and (eq_attr "type" "sdiv")
315        (eq_attr "cpu" "mpccore"))
316   10 10)
317
318 (define_function_unit "fpu" 1 0
319   (and (eq_attr "type" "sdiv")
320        (eq_attr "cpu" "ppc602,ppc603,ppc604,ppc620"))
321   18 18)
322
323 (define_function_unit "fpu" 1 0
324   (and (eq_attr "type" "ddiv")
325        (eq_attr "cpu" "mpccore"))
326   17 17)
327
328 (define_function_unit "fpu" 1 0
329   (and (eq_attr "type" "ddiv")
330        (eq_attr "cpu" "ppc601,ppc604,ppc620"))
331   31 31)
332
333 (define_function_unit "fpu" 1 0
334   (and (eq_attr "type" "ddiv")
335        (eq_attr "cpu" "ppc602,ppc603"))
336   33 33)
337
338 (define_function_unit "fpu" 1 0
339   (and (eq_attr "type" "ssqrt")
340        (eq_attr "cpu" "ppc620"))
341   31 31)
342
343 (define_function_unit "fpu" 1 0
344   (and (eq_attr "type" "dsqrt")
345        (eq_attr "cpu" "ppc620"))
346   31 31)
347
348 ; RIOS2 has two symmetric FPUs.
349 (define_function_unit "fpu2" 2 0
350   (and (eq_attr "type" "fp")
351        (eq_attr "cpu" "rios2"))
352   2 0)
353
354 (define_function_unit "fpu2" 2 0
355   (and (eq_attr "type" "dmul")
356        (eq_attr "cpu" "rios2"))
357   2 0)
358
359 (define_function_unit "fpu2" 2 0
360   (and (eq_attr "type" "sdiv,ddiv")
361        (eq_attr "cpu" "rios2"))
362   17 17)
363
364 (define_function_unit "fpu2" 2 0
365   (and (eq_attr "type" "ssqrt,dsqrt")
366        (eq_attr "cpu" "rios2"))
367   26 26)
368
369 \f
370 ;; Start with fixed-point load and store insns.  Here we put only the more
371 ;; complex forms.  Basic data transfer is done later.
372
373 (define_expand "zero_extendqidi2"
374   [(set (match_operand:DI 0 "gpc_reg_operand" "")
375         (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "")))]
376   "TARGET_POWERPC64"
377   "")
378
379 (define_insn ""
380   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
381         (zero_extend:DI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
382   "TARGET_POWERPC64"
383   "@
384    lbz%U1%X1 %0,%1
385    rldicl %0,%1,0,56"
386   [(set_attr "type" "load,*")])
387
388 (define_insn ""
389   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
390         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
391                     (const_int 0)))
392    (clobber (match_scratch:DI 2 "=r"))]
393   "TARGET_POWERPC64"
394   "rldicl. %2,%1,0,56"
395   [(set_attr "type" "compare")])
396
397 (define_insn ""
398   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
399         (compare:CC (zero_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
400                     (const_int 0)))
401    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
402         (zero_extend:DI (match_dup 1)))]
403   "TARGET_POWERPC64"
404   "rldicl. %0,%1,0,56"
405   [(set_attr "type" "compare")])
406
407 (define_insn "extendqidi2"
408   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
409         (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r")))]
410   "TARGET_POWERPC64"
411   "extsb %0,%1")
412
413 (define_insn ""
414   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
415         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
416                     (const_int 0)))
417    (clobber (match_scratch:DI 2 "=r"))]
418   "TARGET_POWERPC64"
419   "extsb. %2,%1"
420   [(set_attr "type" "compare")])
421
422 (define_insn ""
423   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
424         (compare:CC (sign_extend:DI (match_operand:QI 1 "gpc_reg_operand" "r"))
425                     (const_int 0)))
426    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
427         (sign_extend:DI (match_dup 1)))]
428   "TARGET_POWERPC64"
429   "extsb. %0,%1"
430   [(set_attr "type" "compare")])
431
432 (define_expand "zero_extendhidi2"
433   [(set (match_operand:DI 0 "gpc_reg_operand" "")
434         (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
435   "TARGET_POWERPC64"
436   "")
437
438 (define_insn ""
439   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
440         (zero_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
441   "TARGET_POWERPC64"
442   "@
443    lhz%U1%X1 %0,%1
444    rldicl %0,%1,0,48"
445   [(set_attr "type" "load,*")])
446
447 (define_insn ""
448   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
449         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
450                     (const_int 0)))
451    (clobber (match_scratch:DI 2 "=r"))]
452   "TARGET_POWERPC64"
453   "rldicl. %2,%1,0,48"
454   [(set_attr "type" "compare")])
455
456 (define_insn ""
457   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
458         (compare:CC (zero_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
459                     (const_int 0)))
460    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
461         (zero_extend:DI (match_dup 1)))]
462   "TARGET_POWERPC64"
463   "rldicl. %0,%1,0,48"
464   [(set_attr "type" "compare")])
465
466 (define_expand "extendhidi2"
467   [(set (match_operand:DI 0 "gpc_reg_operand" "")
468         (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "")))]
469   "TARGET_POWERPC64"
470   "")
471
472 (define_insn ""
473   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
474         (sign_extend:DI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
475   "TARGET_POWERPC64"
476   "@
477    lha%U1%X1 %0,%1
478    extsh %0,%1"
479   [(set_attr "type" "load,*")])
480
481 (define_insn ""
482   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
483         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
484                     (const_int 0)))
485    (clobber (match_scratch:DI 2 "=r"))]
486   "TARGET_POWERPC64"
487   "extsh. %2,%1"
488   [(set_attr "type" "compare")])
489
490 (define_insn ""
491   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
492         (compare:CC (sign_extend:DI (match_operand:HI 1 "gpc_reg_operand" "r"))
493                     (const_int 0)))
494    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
495         (sign_extend:DI (match_dup 1)))]
496   "TARGET_POWERPC64"
497   "extsh. %0,%1"
498   [(set_attr "type" "compare")])
499
500 (define_expand "zero_extendsidi2"
501   [(set (match_operand:DI 0 "gpc_reg_operand" "")
502         (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
503   "TARGET_POWERPC64"
504   "")
505
506 (define_insn ""
507   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
508         (zero_extend:DI (match_operand:SI 1 "reg_or_mem_operand" "m,r")))]
509   "TARGET_POWERPC64"
510   "@
511    lwz%U1%X1 %0,%1
512    rldicl %0,%1,0,32"
513   [(set_attr "type" "load,*")])
514
515 (define_insn ""
516   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
517         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
518                     (const_int 0)))
519    (clobber (match_scratch:DI 2 "=r"))]
520   "TARGET_POWERPC64"
521   "rldicl. %2,%1,0,32"
522   [(set_attr "type" "compare")])
523
524 (define_insn ""
525   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
526         (compare:CC (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
527                     (const_int 0)))
528    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
529         (zero_extend:DI (match_dup 1)))]
530   "TARGET_POWERPC64"
531   "rldicl. %0,%1,0,32"
532   [(set_attr "type" "compare")])
533
534 (define_expand "extendsidi2"
535   [(set (match_operand:DI 0 "gpc_reg_operand" "")
536         (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "")))]
537   "TARGET_POWERPC64"
538   "")
539
540 (define_insn ""
541   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
542         (sign_extend:DI (match_operand:SI 1 "lwa_operand" "m,r")))]
543   "TARGET_POWERPC64"
544   "@
545    lwa%U1%X1 %0,%1
546    extsw %0,%1"
547   [(set_attr "type" "load,*")])
548
549 (define_insn ""
550   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
551         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
552                     (const_int 0)))
553    (clobber (match_scratch:DI 2 "=r"))]
554   "TARGET_POWERPC64"
555   "extsw. %2,%1"
556   [(set_attr "type" "compare")])
557
558 (define_insn ""
559   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
560         (compare:CC (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
561                     (const_int 0)))
562    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
563         (sign_extend:DI (match_dup 1)))]
564   "TARGET_POWERPC64"
565   "extsw. %0,%1"
566   [(set_attr "type" "compare")])
567
568 (define_expand "zero_extendqisi2"
569   [(set (match_operand:SI 0 "gpc_reg_operand" "")
570         (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "")))]
571   ""
572   "")
573
574 (define_insn ""
575   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
576         (zero_extend:SI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
577   ""
578   "@
579    lbz%U1%X1 %0,%1
580    {rlinm|rlwinm} %0,%1,0,0xff"
581   [(set_attr "type" "load,*")])
582
583 (define_insn ""
584   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
585         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
586                     (const_int 0)))
587    (clobber (match_scratch:SI 2 "=r"))]
588   ""
589   "{andil.|andi.} %2,%1,0xff"
590   [(set_attr "type" "compare")])
591
592 (define_insn ""
593   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
594         (compare:CC (zero_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
595                     (const_int 0)))
596    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
597         (zero_extend:SI (match_dup 1)))]
598   ""
599   "{andil.|andi.} %0,%1,0xff"
600   [(set_attr "type" "compare")])
601
602 (define_expand "extendqisi2"
603   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
604    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
605   ""
606   "
607 {
608   if (TARGET_POWERPC)
609     emit_insn (gen_extendqisi2_ppc (operands[0], operands[1]));
610   else if (TARGET_POWER)
611     emit_insn (gen_extendqisi2_power (operands[0], operands[1]));
612   else
613     emit_insn (gen_extendqisi2_no_power (operands[0], operands[1]));
614   DONE;
615 }")
616
617 (define_insn "extendqisi2_ppc"
618   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
619         (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r")))]
620   "TARGET_POWERPC"
621   "extsb %0,%1")
622
623 (define_insn ""
624   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
625         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
626                     (const_int 0)))
627    (clobber (match_scratch:SI 2 "=r"))]
628   "TARGET_POWERPC"
629   "extsb. %2,%1"
630   [(set_attr "type" "compare")])
631
632 (define_insn ""
633   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
634         (compare:CC (sign_extend:SI (match_operand:QI 1 "gpc_reg_operand" "r"))
635                     (const_int 0)))
636    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
637         (sign_extend:SI (match_dup 1)))]
638   "TARGET_POWERPC"
639   "extsb. %0,%1"
640   [(set_attr "type" "compare")])
641
642 (define_expand "extendqisi2_power"
643   [(parallel [(set (match_dup 2)
644                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
645                               (const_int 24)))
646               (clobber (scratch:SI))])
647    (parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
648                    (ashiftrt:SI (match_dup 2)
649                                 (const_int 24)))
650               (clobber (scratch:SI))])]
651   "TARGET_POWER"
652   "
653 { operands[1] = gen_lowpart (SImode, operands[1]);
654   operands[2] = gen_reg_rtx (SImode); }")
655
656 (define_expand "extendqisi2_no_power"
657   [(set (match_dup 2)
658         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
659                    (const_int 24)))
660    (set (match_operand:SI 0 "gpc_reg_operand" "")
661         (ashiftrt:SI (match_dup 2)
662                      (const_int 24)))]
663   "! TARGET_POWER && ! TARGET_POWERPC"
664   "
665 { operands[1] = gen_lowpart (SImode, operands[1]);
666   operands[2] = gen_reg_rtx (SImode); }")
667
668 (define_expand "zero_extendqihi2"
669   [(set (match_operand:HI 0 "gpc_reg_operand" "")
670         (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "")))]
671   ""
672   "")
673
674 (define_insn ""
675   [(set (match_operand:HI 0 "gpc_reg_operand" "=r,r")
676         (zero_extend:HI (match_operand:QI 1 "reg_or_mem_operand" "m,r")))]
677   ""
678   "@
679    lbz%U1%X1 %0,%1
680    {rlinm|rlwinm} %0,%1,0,0xff"
681   [(set_attr "type" "load,*")])
682
683 (define_insn ""
684   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
685         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
686                     (const_int 0)))
687    (clobber (match_scratch:HI 2 "=r"))]
688   ""
689   "{andil.|andi.} %2,%1,0xff"
690   [(set_attr "type" "compare")])
691
692 (define_insn ""
693   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
694         (compare:CC (zero_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
695                     (const_int 0)))
696    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
697         (zero_extend:HI (match_dup 1)))]
698   ""
699   "{andil.|andi.} %0,%1,0xff"
700   [(set_attr "type" "compare")])
701
702 (define_expand "extendqihi2"
703   [(use (match_operand:HI 0 "gpc_reg_operand" ""))
704    (use (match_operand:QI 1 "gpc_reg_operand" ""))]
705   ""
706   "
707 {
708   if (TARGET_POWERPC)
709     emit_insn (gen_extendqihi2_ppc (operands[0], operands[1]));
710   else if (TARGET_POWER)
711     emit_insn (gen_extendqihi2_power (operands[0], operands[1]));
712   else
713     emit_insn (gen_extendqihi2_no_power (operands[0], operands[1]));
714   DONE;
715 }")
716
717 (define_insn "extendqihi2_ppc"
718   [(set (match_operand:HI 0 "gpc_reg_operand" "=r")
719         (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r")))]
720   "TARGET_POWERPC"
721   "extsb %0,%1")
722
723 (define_insn ""
724   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
725         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
726                     (const_int 0)))
727    (clobber (match_scratch:HI 2 "=r"))]
728   "TARGET_POWERPC"
729   "extsb. %2,%1"
730   [(set_attr "type" "compare")])
731
732 (define_insn ""
733   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
734         (compare:CC (sign_extend:HI (match_operand:QI 1 "gpc_reg_operand" "r"))
735                     (const_int 0)))
736    (set (match_operand:HI 0 "gpc_reg_operand" "=r")
737         (sign_extend:HI (match_dup 1)))]
738   "TARGET_POWERPC"
739   "extsb. %0,%1"
740   [(set_attr "type" "compare")])
741
742 (define_expand "extendqihi2_power"
743   [(parallel [(set (match_dup 2)
744                    (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
745                               (const_int 24)))
746               (clobber (scratch:SI))])
747    (parallel [(set (match_operand:HI 0 "gpc_reg_operand" "")
748                    (ashiftrt:SI (match_dup 2)
749                                 (const_int 24)))
750               (clobber (scratch:SI))])]
751   "TARGET_POWER"
752   "
753 { operands[0] = gen_lowpart (SImode, operands[0]);
754   operands[1] = gen_lowpart (SImode, operands[1]);
755   operands[2] = gen_reg_rtx (SImode); }")
756
757 (define_expand "extendqihi2_no_power"
758   [(set (match_dup 2)
759         (ashift:SI (match_operand:QI 1 "gpc_reg_operand" "")
760                    (const_int 24)))
761    (set (match_operand:HI 0 "gpc_reg_operand" "")
762         (ashiftrt:SI (match_dup 2)
763                      (const_int 24)))]
764   "! TARGET_POWER && ! TARGET_POWERPC"
765   "
766 { operands[0] = gen_lowpart (SImode, operands[0]);
767   operands[1] = gen_lowpart (SImode, operands[1]);
768   operands[2] = gen_reg_rtx (SImode); }")
769
770 (define_expand "zero_extendhisi2"
771   [(set (match_operand:SI 0 "gpc_reg_operand" "")
772         (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
773   ""
774   "")
775
776 (define_insn ""
777   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
778         (zero_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
779   ""
780   "@
781    lhz%U1%X1 %0,%1
782    {rlinm|rlwinm} %0,%1,0,0xffff"
783   [(set_attr "type" "load,*")])
784
785 (define_insn ""
786   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
787         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
788                     (const_int 0)))
789    (clobber (match_scratch:SI 2 "=r"))]
790   ""
791   "{andil.|andi.} %2,%1,0xffff"
792   [(set_attr "type" "compare")])
793
794 (define_insn ""
795   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
796         (compare:CC (zero_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
797                     (const_int 0)))
798    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
799         (zero_extend:SI (match_dup 1)))]
800   ""
801   "{andil.|andi.} %0,%1,0xffff"
802   [(set_attr "type" "compare")])
803
804 (define_expand "extendhisi2"
805   [(set (match_operand:SI 0 "gpc_reg_operand" "")
806         (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "")))]
807   ""
808   "")
809
810 (define_insn ""
811   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
812         (sign_extend:SI (match_operand:HI 1 "reg_or_mem_operand" "m,r")))]
813   ""
814   "@
815    lha%U1%X1 %0,%1
816    {exts|extsh} %0,%1"
817   [(set_attr "type" "load,*")])
818
819 (define_insn ""
820   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
821         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
822                     (const_int 0)))
823    (clobber (match_scratch:SI 2 "=r"))]
824   ""
825   "{exts.|extsh.} %2,%1"
826   [(set_attr "type" "compare")])
827
828 (define_insn ""
829   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
830         (compare:CC (sign_extend:SI (match_operand:HI 1 "gpc_reg_operand" "r"))
831                     (const_int 0)))
832    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
833         (sign_extend:SI (match_dup 1)))]
834   ""
835   "{exts.|extsh.} %0,%1"
836   [(set_attr "type" "compare")])
837 \f
838 ;; Fixed-point arithmetic insns.
839
840 ;; Discourage ai/addic because of carry but provide it in an alternative
841 ;; allowing register zero as source.
842 (define_insn "addsi3"
843   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,?r,r")
844         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,b,r,b")
845                  (match_operand:SI 2 "add_operand" "r,I,I,J")))]
846   ""
847   "@
848    {cax|add} %0,%1,%2
849    {cal %0,%2(%1)|addi %0,%1,%2}
850    {ai|addic} %0,%1,%2
851    {cau|addis} %0,%1,%u2")
852
853 (define_insn ""
854   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
855         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
856                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
857                     (const_int 0)))
858    (clobber (match_scratch:SI 3 "=r,r"))]
859   ""
860   "@
861    {cax.|add.} %3,%1,%2
862    {ai.|addic.} %3,%1,%2"
863   [(set_attr "type" "compare")])
864
865 (define_insn ""
866   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
867         (compare:CC (plus:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
868                              (match_operand:SI 2 "reg_or_short_operand" "r,I"))
869                     (const_int 0)))
870    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
871         (plus:SI (match_dup 1) (match_dup 2)))]
872   ""
873   "@
874    {cax.|add.} %0,%1,%2
875    {ai.|addic.} %0,%1,%2"
876   [(set_attr "type" "compare")])
877
878 ;; Split an add that we can't do in one insn into two insns, each of which
879 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
880 ;; add should be last in case the result gets used in an address.
881
882 (define_split
883   [(set (match_operand:SI 0 "gpc_reg_operand" "")
884         (plus:SI (match_operand:SI 1 "gpc_reg_operand" "")
885                  (match_operand:SI 2 "non_add_cint_operand" "")))]
886   ""
887   [(set (match_dup 0) (plus:SI (match_dup 1) (match_dup 3)))
888    (set (match_dup 0) (plus:SI (match_dup 0) (match_dup 4)))]
889 "
890 {
891   HOST_WIDE_INT low = INTVAL (operands[2]) & 0xffff;
892   HOST_WIDE_INT high = INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff);
893
894   if (low & 0x8000)
895     high += 0x10000, low |= ((HOST_WIDE_INT) -1) << 16;
896
897   operands[3] = GEN_INT (high);
898   operands[4] = GEN_INT (low);
899 }")
900
901 (define_insn "one_cmplsi2"
902   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
903         (not:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
904   ""
905   "nor %0,%1,%1")
906
907 (define_insn ""
908   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
909         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
910                     (const_int 0)))
911    (clobber (match_scratch:SI 2 "=r"))]
912   ""
913   "nor. %2,%1,%1"
914   [(set_attr "type" "compare")])
915
916 (define_insn ""
917   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
918         (compare:CC (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
919                     (const_int 0)))
920    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
921         (not:SI (match_dup 1)))]
922   ""
923   "nor. %0,%1,%1"
924   [(set_attr "type" "compare")])
925
926 (define_insn ""
927   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
928         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "rI")
929                   (match_operand:SI 2 "gpc_reg_operand" "r")))]
930   "! TARGET_POWERPC"
931   "{sf%I1|subf%I1c} %0,%2,%1")
932
933 (define_insn ""
934   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
935         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "r,I")
936                   (match_operand:SI 2 "gpc_reg_operand" "r,r")))]
937   "TARGET_POWERPC"
938   "@
939    subf %0,%2,%1
940    subfic %0,%2,%1")
941
942 (define_insn ""
943   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
944         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
945                               (match_operand:SI 2 "gpc_reg_operand" "r"))
946                     (const_int 0)))
947    (clobber (match_scratch:SI 3 "=r"))]
948   "! TARGET_POWERPC"
949   "{sf.|subfc.} %3,%2,%1"
950   [(set_attr "type" "compare")])
951
952 (define_insn ""
953   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
954         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
955                               (match_operand:SI 2 "gpc_reg_operand" "r"))
956                     (const_int 0)))
957    (clobber (match_scratch:SI 3 "=r"))]
958   "TARGET_POWERPC"
959   "subf. %3,%2,%1"
960   [(set_attr "type" "compare")])
961
962 (define_insn ""
963   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
964         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
965                               (match_operand:SI 2 "gpc_reg_operand" "r"))
966                     (const_int 0)))
967    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
968         (minus:SI (match_dup 1) (match_dup 2)))]
969   "! TARGET_POWERPC"
970   "{sf.|subfc.} %0,%2,%1"
971   [(set_attr "type" "compare")])
972
973 (define_insn ""
974   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
975         (compare:CC (minus:SI (match_operand:SI 1 "gpc_reg_operand" "r")
976                               (match_operand:SI 2 "gpc_reg_operand" "r"))
977                     (const_int 0)))
978    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
979         (minus:SI (match_dup 1) (match_dup 2)))]
980   "TARGET_POWERPC"
981   "subf. %0,%2,%1"
982   [(set_attr "type" "compare")])
983
984 (define_expand "subsi3"
985   [(set (match_operand:SI 0 "gpc_reg_operand" "")
986         (minus:SI (match_operand:SI 1 "reg_or_short_operand" "")
987                   (match_operand:SI 2 "reg_or_cint_operand" "")))]
988   ""
989   "
990 {
991   if (GET_CODE (operands[2]) == CONST_INT)
992     {
993       emit_insn (gen_addsi3 (operands[0], operands[1],
994                              negate_rtx (SImode, operands[2])));
995       DONE;
996     }
997 }")
998
999 ;; For SMIN, SMAX, UMIN, and UMAX, we use DEFINE_EXPAND's that involve a doz[i]
1000 ;; instruction and some auxiliary computations.  Then we just have a single
1001 ;; DEFINE_INSN for doz[i] and the define_splits to make them if made by
1002 ;; combine.
1003
1004 (define_expand "sminsi3"
1005   [(set (match_dup 3)
1006         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1007                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1008                          (const_int 0)
1009                          (minus:SI (match_dup 2) (match_dup 1))))
1010    (set (match_operand:SI 0 "gpc_reg_operand" "")
1011         (minus:SI (match_dup 2) (match_dup 3)))]
1012   "TARGET_POWER"
1013   "
1014 { operands[3] = gen_reg_rtx (SImode); }")
1015
1016 (define_split
1017   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1018         (smin:SI (match_operand:SI 1 "gpc_reg_operand" "")
1019                  (match_operand:SI 2 "reg_or_short_operand" "")))
1020    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1021   "TARGET_POWER"
1022   [(set (match_dup 3)
1023         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1024                          (const_int 0)
1025                          (minus:SI (match_dup 2) (match_dup 1))))
1026    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 3)))]
1027   "")
1028
1029 (define_expand "smaxsi3"
1030   [(set (match_dup 3)
1031         (if_then_else:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "")
1032                                 (match_operand:SI 2 "reg_or_short_operand" ""))
1033                          (const_int 0)
1034                          (minus:SI (match_dup 2) (match_dup 1))))
1035    (set (match_operand:SI 0 "gpc_reg_operand" "")
1036         (plus:SI (match_dup 3) (match_dup 1)))]
1037   "TARGET_POWER"
1038   "
1039 { operands[3] = gen_reg_rtx (SImode); }")
1040
1041 (define_split
1042   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1043         (smax:SI (match_operand:SI 1 "gpc_reg_operand" "")
1044                  (match_operand:SI 2 "reg_or_short_operand" "")))
1045    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
1046   "TARGET_POWER"
1047   [(set (match_dup 3)
1048         (if_then_else:SI (gt:SI (match_dup 1) (match_dup 2))
1049                          (const_int 0)
1050                          (minus:SI (match_dup 2) (match_dup 1))))
1051    (set (match_dup 0) (plus:SI (match_dup 3) (match_dup 1)))]
1052   "")
1053
1054 (define_expand "uminsi3"
1055   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1056                               (match_dup 5)))
1057    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1058                               (match_dup 5)))
1059    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1060                                        (const_int 0)
1061                                        (minus:SI (match_dup 4) (match_dup 3))))
1062    (set (match_operand:SI 0 "gpc_reg_operand" "")
1063         (minus:SI (match_dup 2) (match_dup 3)))]
1064   "TARGET_POWER"
1065   "
1066 {
1067   operands[3] = gen_reg_rtx (SImode);
1068   operands[4] = gen_reg_rtx (SImode);
1069   operands[5] = GEN_INT (-2147483647 - 1);
1070 }")
1071
1072 (define_expand "umaxsi3"
1073   [(set (match_dup 3) (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1074                               (match_dup 5)))
1075    (set (match_dup 4) (xor:SI (match_operand:SI 2 "gpc_reg_operand" "")
1076                               (match_dup 5)))
1077    (set (match_dup 3) (if_then_else:SI (gt (match_dup 3) (match_dup 4))
1078                                        (const_int 0)
1079                                        (minus:SI (match_dup 4) (match_dup 3))))
1080    (set (match_operand:SI 0 "gpc_reg_operand" "")
1081         (plus:SI (match_dup 3) (match_dup 1)))]
1082   "TARGET_POWER"
1083   "
1084 {
1085   operands[3] = gen_reg_rtx (SImode);
1086   operands[4] = gen_reg_rtx (SImode);
1087   operands[5] = GEN_INT (-2147483647 - 1);
1088 }")
1089
1090 (define_insn ""
1091   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1092         (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1093                              (match_operand:SI 2 "reg_or_short_operand" "rI"))
1094                          (const_int 0)
1095                          (minus:SI (match_dup 2) (match_dup 1))))]
1096   "TARGET_POWER"
1097   "doz%I2 %0,%1,%2")
1098
1099 (define_insn ""
1100   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1101         (compare:CC
1102          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1103                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1104                           (const_int 0)
1105                           (minus:SI (match_dup 2) (match_dup 1)))
1106          (const_int 0)))
1107    (clobber (match_scratch:SI 3 "=r"))]
1108   "TARGET_POWER"
1109   "doz%I2. %3,%1,%2"
1110   [(set_attr "type" "delayed_compare")])
1111
1112 (define_insn ""
1113   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1114         (compare:CC
1115          (if_then_else:SI (gt (match_operand:SI 1 "gpc_reg_operand" "r")
1116                               (match_operand:SI 2 "reg_or_short_operand" "rI"))
1117                           (const_int 0)
1118                           (minus:SI (match_dup 2) (match_dup 1)))
1119          (const_int 0)))
1120    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1121         (if_then_else:SI (gt (match_dup 1) (match_dup 2))
1122                          (const_int 0)
1123                          (minus:SI (match_dup 2) (match_dup 1))))]
1124   "TARGET_POWER"
1125   "doz%I2. %0,%1,%2"
1126   [(set_attr "type" "delayed_compare")])
1127
1128 ;; We don't need abs with condition code because such comparisons should
1129 ;; never be done.
1130 (define_expand "abssi2"
1131   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1132         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "")))]
1133   ""
1134   "
1135 {
1136   if (!TARGET_POWER)
1137     {
1138       emit_insn (gen_abssi2_nopower (operands[0], operands[1]));
1139       DONE;
1140     }
1141 }")
1142
1143 (define_insn "abssi2_power"
1144   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1145         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1146   "TARGET_POWER"
1147   "abs %0,%1")
1148
1149 (define_insn "abssi2_nopower"
1150   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1151         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1152    (clobber (match_scratch:SI 2 "=&r,&r"))]
1153   "!TARGET_POWER"
1154   "*
1155 {
1156   return (TARGET_POWERPC)
1157     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0\"
1158     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%2,%0\";
1159 }"
1160   [(set_attr "length" "12")])
1161
1162 (define_split
1163   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1164         (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0")))
1165    (clobber (match_scratch:SI 2 "=&r,&r"))]
1166   "!TARGET_POWER && reload_completed"
1167   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1168    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1169    (set (match_dup 0) (minus:SI (match_dup 2) (match_dup 0)))]
1170   "")
1171
1172 (define_insn ""
1173   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1174         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r"))))]
1175   "TARGET_POWER"
1176   "nabs %0,%1")
1177
1178 (define_insn ""
1179   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1180         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1181    (clobber (match_scratch:SI 2 "=&r,&r"))]
1182   "!TARGET_POWER"
1183   "*
1184 {
1185   return (TARGET_POWERPC)
1186     ? \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2\"
1187     : \"{srai|srawi} %2,%1,31\;xor %0,%2,%1\;{sf|subfc} %0,%0,%2\";
1188 }"
1189   [(set_attr "length" "12")])
1190
1191 (define_split
1192   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r,r")
1193         (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r,0"))))
1194    (clobber (match_scratch:SI 2 "=&r,&r"))]
1195   "!TARGET_POWER && reload_completed"
1196   [(set (match_dup 2) (ashiftrt:SI (match_dup 1) (const_int 31)))
1197    (set (match_dup 0) (xor:SI (match_dup 2) (match_dup 1)))
1198    (set (match_dup 0) (minus:SI (match_dup 0) (match_dup 2)))]
1199   "")
1200
1201 (define_insn "negsi2"
1202   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1203         (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1204   ""
1205   "neg %0,%1")
1206
1207 (define_insn ""
1208   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1209         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1210                     (const_int 0)))
1211    (clobber (match_scratch:SI 2 "=r"))]
1212   ""
1213   "neg. %2,%1"
1214   [(set_attr "type" "compare")])
1215
1216 (define_insn ""
1217   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
1218         (compare:CC (neg:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1219                     (const_int 0)))
1220    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1221         (neg:SI (match_dup 1)))]
1222   ""
1223   "neg. %0,%1"
1224   [(set_attr "type" "compare")])
1225
1226 (define_insn "ffssi2"
1227   [(set (match_operand:SI 0 "gpc_reg_operand" "=&r")
1228         (ffs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))]
1229   ""
1230   "neg %0,%1\;and %0,%0,%1\;{cntlz|cntlzw} %0,%0\;{sfi|subfic} %0,%0,32"
1231   [(set_attr "length" "16")])
1232
1233 (define_expand "mulsi3"
1234   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1235    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1236    (use (match_operand:SI 2 "reg_or_short_operand" ""))]
1237   ""
1238   "
1239 {
1240   if (TARGET_POWER)
1241     emit_insn (gen_mulsi3_mq (operands[0], operands[1], operands[2]));
1242   else
1243     emit_insn (gen_mulsi3_no_mq (operands[0], operands[1], operands[2]));
1244   DONE;
1245 }")
1246
1247 (define_insn "mulsi3_mq"
1248   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1249         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1250                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))
1251    (clobber (match_scratch:SI 3 "=q,q"))]
1252   "TARGET_POWER"
1253   "@
1254    {muls|mullw} %0,%1,%2
1255    {muli|mulli} %0,%1,%2"
1256    [(set_attr "type" "imul")])
1257
1258 (define_insn "mulsi3_no_mq"
1259   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
1260         (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r")
1261                  (match_operand:SI 2 "reg_or_short_operand" "r,I")))]
1262   "! TARGET_POWER"
1263   "@
1264    {muls|mullw} %0,%1,%2
1265    {muli|mulli} %0,%1,%2"
1266    [(set_attr "type" "imul")])
1267
1268 (define_insn ""
1269   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1270         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1271                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1272                     (const_int 0)))
1273    (clobber (match_scratch:SI 3 "=r"))
1274    (clobber (match_scratch:SI 4 "=q"))]
1275   "TARGET_POWER"
1276   "{muls.|mullw.} %3,%1,%2"
1277   [(set_attr "type" "delayed_compare")])
1278
1279 (define_insn ""
1280   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1281         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1282                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1283                     (const_int 0)))
1284    (clobber (match_scratch:SI 3 "=r"))]
1285   "! TARGET_POWER"
1286   "{muls.|mullw.} %3,%1,%2"
1287   [(set_attr "type" "delayed_compare")])
1288
1289 (define_insn ""
1290   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1291         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1292                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1293                     (const_int 0)))
1294    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1295         (mult:SI (match_dup 1) (match_dup 2)))
1296    (clobber (match_scratch:SI 4 "=q"))]
1297   "TARGET_POWER"
1298   "{muls.|mullw.} %0,%1,%2"
1299   [(set_attr "type" "delayed_compare")])
1300
1301 (define_insn ""
1302   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1303         (compare:CC (mult:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1304                              (match_operand:SI 2 "gpc_reg_operand" "r"))
1305                     (const_int 0)))
1306    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1307         (mult:SI (match_dup 1) (match_dup 2)))]
1308   "! TARGET_POWER"
1309   "{muls.|mullw.} %0,%1,%2"
1310   [(set_attr "type" "delayed_compare")])
1311
1312 ;; Operand 1 is divided by operand 2; quotient goes to operand
1313 ;; 0 and remainder to operand 3.
1314 ;; ??? At some point, see what, if anything, we can do about if (x % y == 0).
1315
1316 (define_expand "divmodsi4"
1317   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1318                    (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1319                            (match_operand:SI 2 "gpc_reg_operand" "")))
1320               (set (match_operand:SI 3 "gpc_reg_operand" "")
1321                    (mod:SI (match_dup 1) (match_dup 2)))])]
1322   "TARGET_POWER || (! TARGET_POWER && ! TARGET_POWERPC)"
1323   "
1324 {
1325   if (! TARGET_POWER && ! TARGET_POWERPC)
1326     {
1327       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1328       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1329       emit_insn (gen_divss_call ());
1330       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1331       emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1332       DONE;
1333     }
1334 }")
1335
1336 (define_insn ""
1337   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1338         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1339                 (match_operand:SI 2 "gpc_reg_operand" "r")))
1340    (set (match_operand:SI 3 "gpc_reg_operand" "=q")
1341         (mod:SI (match_dup 1) (match_dup 2)))]
1342   "TARGET_POWER"
1343   "divs %0,%1,%2"
1344   [(set_attr "type" "idiv")])
1345
1346 (define_insn ""
1347   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1348         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1349                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1350   "TARGET_POWERPC"
1351   "divw %0,%1,%2"
1352   [(set_attr "type" "idiv")])
1353
1354 (define_expand "udivsi3"
1355   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1356         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1357                  (match_operand:SI 2 "gpc_reg_operand" "")))]
1358   "TARGET_POWERPC || (! TARGET_POWER && ! TARGET_POWERPC)"
1359   "
1360 {
1361   if (! TARGET_POWER && ! TARGET_POWERPC)
1362     {
1363       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1364       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1365       emit_insn (gen_quous_call ());
1366       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1367       DONE;
1368     }
1369 }")
1370
1371 (define_insn ""
1372   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1373         (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1374                  (match_operand:SI 2 "gpc_reg_operand" "r")))]
1375   "TARGET_POWERPC"
1376   "divwu %0,%1,%2"
1377   [(set_attr "type" "idiv")])
1378
1379 ;; For powers of two we can do srai/aze for divide and then adjust for
1380 ;; modulus.  If it isn't a power of two, FAIL on POWER so divmodsi4 will be
1381 ;; used; for PowerPC, force operands into register and do a normal divide;
1382 ;; for AIX common-mode, use quoss call on register operands.
1383 (define_expand "divsi3"
1384   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1385         (div:SI (match_operand:SI 1 "gpc_reg_operand" "")
1386                 (match_operand:SI 2 "reg_or_cint_operand" "")))]
1387   ""
1388   "
1389 {
1390   if (GET_CODE (operands[2]) == CONST_INT
1391       && exact_log2 (INTVAL (operands[2])) >= 0)
1392     ;
1393   else if (TARGET_POWERPC)
1394     operands[2] = force_reg (SImode, operands[2]);
1395   else if (TARGET_POWER)
1396     FAIL;
1397   else
1398     {
1399       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1400       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1401       emit_insn (gen_quoss_call ());
1402       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1403       DONE;
1404     }
1405 }")
1406
1407 (define_expand "modsi3"
1408   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
1409    (use (match_operand:SI 1 "gpc_reg_operand" ""))
1410    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
1411   ""
1412   "
1413 {
1414   int i = exact_log2 (INTVAL (operands[2]));
1415   rtx temp1;
1416   rtx temp2;
1417
1418   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
1419     FAIL;
1420
1421   temp1 = gen_reg_rtx (SImode);
1422   temp2 = gen_reg_rtx (SImode);
1423
1424   emit_insn (gen_divsi3 (temp1, operands[1], operands[2]));
1425   emit_insn (gen_ashlsi3 (temp2, temp1, GEN_INT (i)));
1426   emit_insn (gen_subsi3 (operands[0], operands[1], temp2));
1427   DONE;
1428 }")
1429
1430 (define_insn ""
1431   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1432         (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1433                 (match_operand:SI 2 "const_int_operand" "N")))]
1434   "exact_log2 (INTVAL (operands[2])) >= 0"
1435   "{srai|srawi} %0,%1,%p2\;{aze|addze} %0,%0"
1436   [(set_attr "length" "8")])
1437
1438 (define_insn ""
1439   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1440         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1441                             (match_operand:SI 2 "const_int_operand" "N"))
1442                     (const_int 0)))
1443    (clobber (match_scratch:SI 3 "=r"))]
1444   "exact_log2 (INTVAL (operands[2])) >= 0"
1445   "{srai|srawi} %3,%1,%p2\;{aze.|addze.} %3,%3"
1446   [(set_attr "type" "compare")
1447    (set_attr "length" "8")])
1448
1449 (define_insn ""
1450   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1451         (compare:CC (div:SI (match_operand:SI 1 "gpc_reg_operand" "r")
1452                             (match_operand:SI 2 "const_int_operand" "N"))
1453                     (const_int 0)))
1454    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1455         (div:SI (match_dup 1) (match_dup 2)))]
1456   "exact_log2 (INTVAL (operands[2])) >= 0"
1457   "{srai|srawi} %0,%1,%p2\;{aze.|addze.} %0,%0"
1458   [(set_attr "type" "compare")
1459    (set_attr "length" "8")])
1460
1461 (define_insn ""
1462   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1463         (udiv:SI
1464          (plus:DI (ashift:DI
1465                    (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "r"))
1466                    (const_int 32))
1467                   (zero_extend:DI (match_operand:SI 4 "register_operand" "2")))
1468          (match_operand:SI 3 "gpc_reg_operand" "r")))
1469    (set (match_operand:SI 2 "register_operand" "=*q")
1470         (umod:SI
1471          (plus:DI (ashift:DI
1472                    (zero_extend:DI (match_dup 1)) (const_int 32))
1473                   (zero_extend:DI (match_dup 4)))
1474          (match_dup 3)))]
1475   "TARGET_POWER"
1476   "div %0,%1,%3"
1477   [(set_attr "type" "idiv")])
1478
1479 ;; To do unsigned divide we handle the cases of the divisor looking like a
1480 ;; negative number.  If it is a constant that is less than 2**31, we don't
1481 ;; have to worry about the branches.  So make a few subroutines here.
1482 ;;
1483 ;; First comes the normal case.
1484 (define_expand "udivmodsi4_normal"
1485   [(set (match_dup 4) (const_int 0))
1486    (parallel [(set (match_operand:SI 0 "" "")
1487                    (udiv:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1488                                                 (const_int 32))
1489                                      (zero_extend:DI (match_operand:SI 1 "" "")))
1490                             (match_operand:SI 2 "" "")))
1491               (set (match_operand:SI 3 "" "")
1492                    (umod:SI (plus:DI (ashift:DI (zero_extend:DI (match_dup 4))
1493                                                 (const_int 32))
1494                                      (zero_extend:DI (match_dup 1)))
1495                             (match_dup 2)))])]
1496   "TARGET_POWER"
1497   "
1498 { operands[4] = gen_reg_rtx (SImode); }")
1499
1500 ;; This handles the branches.
1501 (define_expand "udivmodsi4_tests"
1502   [(set (match_operand:SI 0 "" "") (const_int 0))
1503    (set (match_operand:SI 3 "" "") (match_operand:SI 1 "" ""))
1504    (set (match_dup 5) (compare:CCUNS (match_dup 1) (match_operand:SI 2 "" "")))
1505    (set (pc) (if_then_else (ltu (match_dup 5) (const_int 0))
1506                            (label_ref (match_operand:SI 4 "" "")) (pc)))
1507    (set (match_dup 0) (const_int 1))
1508    (set (match_dup 3) (minus:SI (match_dup 1) (match_dup 2)))
1509    (set (match_dup 6) (compare:CC (match_dup 2) (const_int 0)))
1510    (set (pc) (if_then_else (lt (match_dup 6) (const_int 0))
1511                            (label_ref (match_dup 4)) (pc)))]
1512   "TARGET_POWER"
1513   "
1514 { operands[5] = gen_reg_rtx (CCUNSmode);
1515   operands[6] = gen_reg_rtx (CCmode);
1516 }")
1517
1518 (define_expand "udivmodsi4"
1519   [(parallel [(set (match_operand:SI 0 "gpc_reg_operand" "")
1520                    (udiv:SI (match_operand:SI 1 "gpc_reg_operand" "")
1521                             (match_operand:SI 2 "reg_or_cint_operand" "")))
1522               (set (match_operand:SI 3 "gpc_reg_operand" "")
1523                    (umod:SI (match_dup 1) (match_dup 2)))])]
1524   ""
1525   "
1526 {
1527   rtx label = 0;
1528
1529   if (! TARGET_POWER)
1530     if (! TARGET_POWERPC)
1531       {
1532         emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
1533         emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
1534         emit_insn (gen_divus_call ());
1535         emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
1536         emit_move_insn (operands[3], gen_rtx (REG, SImode, 4));
1537         DONE;
1538       }
1539     else
1540       FAIL;
1541
1542   if (GET_CODE (operands[2]) != CONST_INT || INTVAL (operands[2]) < 0)
1543     {
1544       operands[2] = force_reg (SImode, operands[2]);
1545       label = gen_label_rtx ();
1546       emit (gen_udivmodsi4_tests (operands[0], operands[1], operands[2],
1547                                   operands[3], label));
1548     }
1549   else
1550     operands[2] = force_reg (SImode, operands[2]);
1551
1552   emit (gen_udivmodsi4_normal (operands[0], operands[1], operands[2],
1553                                operands[3]));
1554   if (label)
1555     emit_label (label);
1556
1557   DONE;
1558 }")
1559
1560 ;; AIX architecture-independent common-mode multiply (DImode),
1561 ;; divide/modulus, and quotient subroutine calls.  Input operands in R3 and
1562 ;; R4; results in R3 and sometimes R4; link register always clobbered by bla
1563 ;; instruction; R0 sometimes clobbered; also, MQ sometimes clobbered but
1564 ;; assumed unused if generating common-mode, so ignore.
1565 (define_insn "mulh_call"
1566   [(set (reg:SI 3)
1567         (truncate:SI
1568          (lshiftrt:DI (mult:DI (sign_extend:DI (reg:SI 3))
1569                                (sign_extend:DI (reg:SI 4)))
1570                       (const_int 32))))
1571    (clobber (match_scratch:SI 0 "=l"))]
1572   "! TARGET_POWER && ! TARGET_POWERPC"
1573   "bla __mulh")
1574
1575 (define_insn "mull_call"
1576   [(set (reg:DI 3)
1577         (mult:DI (sign_extend:DI (reg:SI 3))
1578                  (sign_extend:DI (reg:SI 4))))
1579    (clobber (match_scratch:SI 0 "=l"))
1580    (clobber (reg:SI 0))]
1581   "! TARGET_POWER && ! TARGET_POWERPC"
1582   "bla __mull")
1583
1584 (define_insn "divss_call"
1585   [(set (reg:SI 3)
1586         (div:SI (reg:SI 3) (reg:SI 4)))
1587    (set (reg:SI 4)
1588         (mod:SI (reg:SI 3) (reg:SI 4)))
1589    (clobber (match_scratch:SI 0 "=l"))
1590    (clobber (reg:SI 0))]
1591   "! TARGET_POWER && ! TARGET_POWERPC"
1592   "bla __divss")
1593
1594 (define_insn "divus_call"
1595   [(set (reg:SI 3)
1596         (udiv:SI (reg:SI 3) (reg:SI 4)))
1597    (set (reg:SI 4)
1598         (umod:SI (reg:SI 3) (reg:SI 4)))
1599    (clobber (match_scratch:SI 0 "=l"))
1600    (clobber (reg:SI 0))
1601    (clobber (match_scratch:CC 1 "=x"))
1602    (clobber (reg:CC 69))]
1603   "! TARGET_POWER && ! TARGET_POWERPC"
1604   "bla __divus")
1605
1606 (define_insn "quoss_call"
1607   [(set (reg:SI 3)
1608         (div:SI (reg:SI 3) (reg:SI 4)))
1609    (clobber (match_scratch:SI 0 "=l"))]
1610   "! TARGET_POWER && ! TARGET_POWERPC"
1611   "bla __quoss")
1612
1613 (define_insn "quous_call"
1614   [(set (reg:SI 3)
1615         (udiv:SI (reg:SI 3) (reg:SI 4)))
1616    (clobber (match_scratch:SI 0 "=l"))
1617    (clobber (reg:SI 0))
1618    (clobber (match_scratch:CC 1 "=x"))
1619    (clobber (reg:CC 69))]
1620   "! TARGET_POWER && ! TARGET_POWERPC"
1621   "bla __quous")
1622 \f
1623 (define_insn "andsi3"
1624   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1625         (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1626                 (match_operand:SI 2 "and_operand" "?r,L,K,J")))
1627    (clobber (match_scratch:CC 3 "=X,X,x,x"))]
1628   ""
1629   "@
1630    and %0,%1,%2
1631    {rlinm|rlwinm} %0,%1,0,%m2,%M2
1632    {andil.|andi.} %0,%1,%b2
1633    {andiu.|andis.} %0,%1,%u2")
1634
1635 (define_insn ""
1636   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x")
1637         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1638                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1639                     (const_int 0)))
1640    (clobber (match_scratch:SI 3 "=r,r,r,r"))]
1641   ""
1642   "@
1643    and. %3,%1,%2
1644    {andil.|andi.} %3,%1,%b2
1645    {andiu.|andis.} %3,%1,%u2
1646    {rlinm.|rlwinm.} %3,%1,0,%m2,%M2"
1647   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1648
1649 (define_insn ""
1650   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x,x")
1651         (compare:CC (and:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r")
1652                             (match_operand:SI 2 "and_operand" "r,K,J,L"))
1653                     (const_int 0)))
1654    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
1655         (and:SI (match_dup 1) (match_dup 2)))]
1656   ""
1657   "@
1658    and. %0,%1,%2
1659    {andil.|andi.} %0,%1,%b2
1660    {andiu.|andis.} %0,%1,%u2
1661    {rlinm.|rlwinm.} %0,%1,0,%m2,%M2"
1662   [(set_attr "type" "compare,compare,compare,delayed_compare")])
1663
1664 ;; Take a AND with a constant that cannot be done in a single insn and try to
1665 ;; split it into two insns.  This does not verify that the insns are valid
1666 ;; since this need not be done as combine will do it.
1667
1668 (define_split
1669   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1670         (and:SI (match_operand:SI 1 "gpc_reg_operand" "")
1671                 (match_operand:SI 2 "non_and_cint_operand" "")))]
1672   ""
1673   [(set (match_dup 0) (and:SI (match_dup 1) (match_dup 3)))
1674    (set (match_dup 0) (and:SI (match_dup 0) (match_dup 4)))]
1675   "
1676 {
1677   int maskval = INTVAL (operands[2]);
1678   int i, transitions, last_bit_value;
1679   int orig = maskval, first_c = maskval, second_c;
1680
1681   /* We know that MASKVAL must have more than 2 bit-transitions.  Start at
1682      the low-order bit and count for the third transition.  When we get there,
1683      make a first mask that has everything to the left of that position
1684      a one.  Then make the second mask to turn off whatever else is needed.  */
1685
1686   for (i = 1, transitions = 0, last_bit_value = maskval & 1; i < 32; i++)
1687     {
1688       if (((maskval >>= 1) & 1) != last_bit_value)
1689         last_bit_value ^= 1, transitions++;
1690
1691       if (transitions > 2)
1692         {
1693           first_c |= (~0) << i;
1694           break;
1695         }
1696     }
1697
1698   second_c = orig | ~ first_c;
1699
1700   operands[3] = gen_rtx (CONST_INT, VOIDmode, first_c);
1701   operands[4] = gen_rtx (CONST_INT, VOIDmode, second_c);
1702 }")
1703
1704 (define_insn "iorsi3"
1705   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1706         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1707                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1708   ""
1709   "@
1710    or %0,%1,%2
1711    {oril|ori} %0,%1,%b2
1712    {oriu|oris} %0,%1,%u2")
1713
1714 (define_insn ""
1715   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1716         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1717                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1718                     (const_int 0)))
1719    (clobber (match_scratch:SI 3 "=r"))]
1720   ""
1721   "or. %3,%1,%2"
1722   [(set_attr "type" "compare")])
1723
1724 (define_insn ""
1725   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1726         (compare:CC (ior:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1727                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1728                     (const_int 0)))
1729    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1730         (ior:SI (match_dup 1) (match_dup 2)))]
1731   ""
1732   "or. %0,%1,%2"
1733   [(set_attr "type" "compare")])
1734
1735 ;; Split an IOR that we can't do in one insn into two insns, each of which
1736 ;; does one 16-bit part.  This is used by combine.
1737
1738 (define_split
1739   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1740         (ior:SI (match_operand:SI 1 "gpc_reg_operand" "")
1741                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1742   ""
1743   [(set (match_dup 0) (ior:SI (match_dup 1) (match_dup 3)))
1744    (set (match_dup 0) (ior:SI (match_dup 0) (match_dup 4)))]
1745 "
1746 {
1747   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1748                          INTVAL (operands[2]) & 0xffff0000);
1749   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1750 }")
1751
1752 (define_insn "xorsi3"
1753   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
1754         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r")
1755                 (match_operand:SI 2 "logical_operand" "r,K,J")))]
1756   ""
1757   "@
1758    xor %0,%1,%2
1759    {xoril|xori} %0,%1,%b2
1760    {xoriu|xoris} %0,%1,%u2")
1761
1762 (define_insn ""
1763   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1764         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1765                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1766                     (const_int 0)))
1767    (clobber (match_scratch:SI 3 "=r"))]
1768   ""
1769   "xor. %3,%1,%2"
1770   [(set_attr "type" "compare")])
1771
1772 (define_insn ""
1773   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1774         (compare:CC (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1775                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1776                     (const_int 0)))
1777    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1778         (xor:SI (match_dup 1) (match_dup 2)))]
1779   ""
1780   "xor. %0,%1,%2"
1781   [(set_attr "type" "compare")])
1782
1783 ;; Split an XOR that we can't do in one insn into two insns, each of which
1784 ;; does one 16-bit part.  This is used by combine.
1785
1786 (define_split
1787   [(set (match_operand:SI 0 "gpc_reg_operand" "")
1788         (xor:SI (match_operand:SI 1 "gpc_reg_operand" "")
1789                 (match_operand:SI 2 "non_logical_cint_operand" "")))]
1790   ""
1791   [(set (match_dup 0) (xor:SI (match_dup 1) (match_dup 3)))
1792    (set (match_dup 0) (xor:SI (match_dup 0) (match_dup 4)))]
1793 "
1794 {
1795   operands[3] = gen_rtx (CONST_INT, VOIDmode,
1796                          INTVAL (operands[2]) & 0xffff0000);
1797   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
1798 }")
1799
1800 (define_insn ""
1801   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1802         (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1803                         (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1804    ""
1805    "eqv %0,%1,%2")
1806
1807 (define_insn ""
1808   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1809         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1810                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1811                     (const_int 0)))
1812    (clobber (match_scratch:SI 3 "=r"))]
1813    ""
1814    "eqv. %3,%1,%2"
1815    [(set_attr "type" "compare")])
1816
1817 (define_insn ""
1818   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1819         (compare:CC (not:SI (xor:SI (match_operand:SI 1 "gpc_reg_operand" "%r")
1820                                     (match_operand:SI 2 "gpc_reg_operand" "r")))
1821                     (const_int 0)))
1822    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1823         (not:SI (xor:SI (match_dup 1) (match_dup 2))))]
1824    ""
1825    "eqv. %0,%1,%2"
1826    [(set_attr "type" "compare")])
1827
1828 (define_insn ""
1829   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1830         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1831                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1832   ""
1833   "andc %0,%2,%1")
1834
1835 (define_insn ""
1836   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1837         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1838                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1839                     (const_int 0)))
1840    (clobber (match_scratch:SI 3 "=r"))]
1841   ""
1842   "andc. %3,%2,%1"
1843   [(set_attr "type" "compare")])
1844
1845 (define_insn ""
1846   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1847         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1848                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1849                     (const_int 0)))
1850    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1851         (and:SI (not:SI (match_dup 1)) (match_dup 2)))]
1852   ""
1853   "andc. %0,%2,%1"
1854   [(set_attr "type" "compare")])
1855
1856 (define_insn ""
1857   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1858         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1859                 (match_operand:SI 2 "gpc_reg_operand" "r")))]
1860   ""
1861   "orc %0,%2,%1")
1862
1863 (define_insn ""
1864   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1865         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1866                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1867                     (const_int 0)))
1868    (clobber (match_scratch:SI 3 "=r"))]
1869   ""
1870   "orc. %3,%2,%1"
1871   [(set_attr "type" "compare")])
1872
1873 (define_insn ""
1874   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1875         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
1876                             (match_operand:SI 2 "gpc_reg_operand" "r"))
1877                     (const_int 0)))
1878    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1879         (ior:SI (not:SI (match_dup 1)) (match_dup 2)))]
1880   ""
1881   "orc. %0,%2,%1"
1882   [(set_attr "type" "compare")])
1883
1884 (define_insn ""
1885   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1886         (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1887                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1888   ""
1889   "nand %0,%1,%2")
1890
1891 (define_insn ""
1892   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1893         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1894                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1895                     (const_int 0)))
1896    (clobber (match_scratch:SI 3 "=r"))]
1897   ""
1898   "nand. %3,%1,%2"
1899   [(set_attr "type" "compare")])
1900
1901 (define_insn ""
1902   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1903         (compare:CC (ior:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1904                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1905                     (const_int 0)))
1906    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1907         (ior:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1908   ""
1909   "nand. %0,%1,%2"
1910   [(set_attr "type" "compare")])
1911
1912 (define_insn ""
1913   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1914         (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1915                 (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
1916   ""
1917   "nor %0,%1,%2")
1918
1919 (define_insn ""
1920   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
1921         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1922                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1923                     (const_int 0)))
1924    (clobber (match_scratch:SI 3 "=r"))]
1925   ""
1926   "nor. %3,%1,%2"
1927   [(set_attr "type" "compare")])
1928
1929 (define_insn ""
1930   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
1931         (compare:CC (and:SI (not:SI (match_operand:SI 1 "gpc_reg_operand" "%r"))
1932                             (not:SI (match_operand:SI 2 "gpc_reg_operand" "r")))
1933                     (const_int 0)))
1934    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1935         (and:SI (not:SI (match_dup 1)) (not:SI (match_dup 2))))]
1936   ""
1937   "nor. %0,%1,%2"
1938   [(set_attr "type" "compare")])
1939
1940 ;; maskir insn.  We need four forms because things might be in arbitrary
1941 ;; orders.  Don't define forms that only set CR fields because these
1942 ;; would modify an input register.
1943
1944 (define_insn ""
1945   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1946         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1947                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1948                 (and:SI (match_dup 2)
1949                         (match_operand:SI 3 "gpc_reg_operand" "r"))))]
1950   "TARGET_POWER"
1951   "maskir %0,%3,%2")
1952
1953 (define_insn ""
1954   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1955         (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1956                         (match_operand:SI 1 "gpc_reg_operand" "0"))
1957                 (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1958                         (match_dup 2))))]
1959   "TARGET_POWER"
1960   "maskir %0,%3,%2")
1961
1962 (define_insn ""
1963   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1964         (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
1965                         (match_operand:SI 3 "gpc_reg_operand" "r"))
1966                 (and:SI (not:SI (match_dup 2))
1967                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1968   "TARGET_POWER"
1969   "maskir %0,%3,%2")
1970
1971 (define_insn ""
1972   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
1973         (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
1974                         (match_operand:SI 2 "gpc_reg_operand" "r"))
1975                 (and:SI (not:SI (match_dup 2))
1976                         (match_operand:SI 1 "gpc_reg_operand" "0"))))]
1977   "TARGET_POWER"
1978   "maskir %0,%3,%2")
1979
1980 (define_insn ""
1981   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1982         (compare:CC
1983          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1984                          (match_operand:SI 1 "gpc_reg_operand" "0"))
1985                  (and:SI (match_dup 2)
1986                          (match_operand:SI 3 "gpc_reg_operand" "r")))
1987          (const_int 0)))
1988    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
1989         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
1990                 (and:SI (match_dup 2) (match_dup 3))))]
1991   "TARGET_POWER"
1992   "maskir. %0,%3,%2"
1993   [(set_attr "type" "compare")])
1994
1995 (define_insn ""
1996   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
1997         (compare:CC
1998          (ior:SI (and:SI (not:SI (match_operand:SI 2 "gpc_reg_operand" "r"))
1999                          (match_operand:SI 1 "gpc_reg_operand" "0"))
2000                  (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2001                          (match_dup 2)))
2002          (const_int 0)))
2003    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2004         (ior:SI (and:SI (not:SI (match_dup 2)) (match_dup 1))
2005                 (and:SI (match_dup 3) (match_dup 2))))]
2006   "TARGET_POWER"
2007   "maskir. %0,%3,%2"
2008   [(set_attr "type" "compare")])
2009
2010 (define_insn ""
2011   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2012         (compare:CC
2013          (ior:SI (and:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2014                          (match_operand:SI 3 "gpc_reg_operand" "r"))
2015                  (and:SI (not:SI (match_dup 2))
2016                          (match_operand:SI 1 "gpc_reg_operand" "0")))
2017          (const_int 0)))
2018    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2019         (ior:SI (and:SI (match_dup 2) (match_dup 3))
2020                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2021   "TARGET_POWER"
2022   "maskir. %0,%3,%2"
2023   [(set_attr "type" "compare")])
2024
2025 (define_insn ""
2026   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2027         (compare:CC
2028          (ior:SI (and:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2029                          (match_operand:SI 2 "gpc_reg_operand" "r"))
2030                  (and:SI (not:SI (match_dup 2))
2031                          (match_operand:SI 1 "gpc_reg_operand" "0")))
2032          (const_int 0)))
2033    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2034         (ior:SI (and:SI (match_dup 3) (match_dup 2))
2035                 (and:SI (not:SI (match_dup 2)) (match_dup 1))))]
2036   "TARGET_POWER"
2037   "maskir. %0,%3,%2"
2038   [(set_attr "type" "compare")])
2039 \f
2040 ;; Rotate and shift insns, in all their variants.  These support shifts,
2041 ;; field inserts and extracts, and various combinations thereof.
2042 (define_expand "insv"
2043   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2044                          (match_operand:SI 1 "const_int_operand" "i")
2045                          (match_operand:SI 2 "const_int_operand" "i"))
2046         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2047   ""
2048   "
2049 {
2050   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2051      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2052      compiler if the address of the structure is taken later.  */
2053   if (GET_CODE (operands[0]) == SUBREG
2054       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2055     FAIL;
2056 }")
2057
2058 (define_insn ""
2059   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2060                          (match_operand:SI 1 "const_int_operand" "i")
2061                          (match_operand:SI 2 "const_int_operand" "i"))
2062         (match_operand:SI 3 "gpc_reg_operand" "r"))]
2063   ""
2064   "*
2065 {
2066   int start = INTVAL (operands[2]) & 31;
2067   int size = INTVAL (operands[1]) & 31;
2068
2069   operands[4] = gen_rtx (CONST_INT, VOIDmode, 32 - start - size);
2070   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2071   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
2072 }")
2073
2074 (define_insn ""
2075   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2076                          (match_operand:SI 1 "const_int_operand" "i")
2077                          (match_operand:SI 2 "const_int_operand" "i"))
2078         (ashift:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2079                    (match_operand:SI 4 "const_int_operand" "i")))]
2080   ""
2081   "*
2082 {
2083   int shift = INTVAL (operands[4]) & 31;
2084   int start = INTVAL (operands[2]) & 31;
2085   int size = INTVAL (operands[1]) & 31;
2086
2087   operands[4] = gen_rtx (CONST_INT, VOIDmode, (shift - start - size) & 31);
2088   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2089   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
2090 }")
2091
2092 (define_insn ""
2093   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2094                          (match_operand:SI 1 "const_int_operand" "i")
2095                          (match_operand:SI 2 "const_int_operand" "i"))
2096         (ashiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2097                      (match_operand:SI 4 "const_int_operand" "i")))]
2098   ""
2099   "*
2100 {
2101   int shift = INTVAL (operands[4]) & 31;
2102   int start = INTVAL (operands[2]) & 31;
2103   int size = INTVAL (operands[1]) & 31;
2104
2105   operands[4] = gen_rtx (CONST_INT, VOIDmode, (32 - shift - start - size) & 31);
2106   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2107   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
2108 }")
2109
2110 (define_insn ""
2111   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2112                          (match_operand:SI 1 "const_int_operand" "i")
2113                          (match_operand:SI 2 "const_int_operand" "i"))
2114         (lshiftrt:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2115                      (match_operand:SI 4 "const_int_operand" "i")))]
2116   ""
2117   "*
2118 {
2119   int shift = INTVAL (operands[4]) & 31;
2120   int start = INTVAL (operands[2]) & 31;
2121   int size = INTVAL (operands[1]) & 31;
2122
2123   operands[4] = gen_rtx (CONST_INT, VOIDmode, (32 - shift - start - size) & 31);
2124   operands[1] = gen_rtx (CONST_INT, VOIDmode, start + size - 1);
2125   return \"{rlimi|rlwimi} %0,%3,%4,%h2,%h1\";
2126 }")
2127
2128 (define_insn ""
2129   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2130                          (match_operand:SI 1 "const_int_operand" "i")
2131                          (match_operand:SI 2 "const_int_operand" "i"))
2132         (zero_extract:SI (match_operand:SI 3 "gpc_reg_operand" "r")
2133                          (match_operand:SI 4 "const_int_operand" "i")
2134                          (match_operand:SI 5 "const_int_operand" "i")))]
2135   "INTVAL (operands[4]) >= INTVAL (operands[1])"
2136   "*
2137 {
2138   int extract_start = INTVAL (operands[5]) & 31;
2139   int extract_size = INTVAL (operands[4]) & 31;
2140   int insert_start = INTVAL (operands[2]) & 31;
2141   int insert_size = INTVAL (operands[1]) & 31;
2142
2143 /* Align extract field with insert field */
2144   operands[5] = gen_rtx (CONST_INT, VOIDmode,
2145                          (extract_start + extract_size - insert_start - insert_size) & 31);
2146   operands[1] = gen_rtx (CONST_INT, VOIDmode, insert_start + insert_size - 1);
2147   return \"{rlimi|rlwimi} %0,%3,%5,%h2,%h1\";
2148 }")
2149
2150 (define_expand "extzv"
2151   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2152         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2153                          (match_operand:SI 2 "const_int_operand" "i")
2154                          (match_operand:SI 3 "const_int_operand" "i")))]
2155   ""
2156   "
2157 {
2158   /* Do not handle 16/8 bit structures that fit in HI/QI modes directly, since
2159      the (SUBREG:SI (REG:HI xxx)) that is otherwise generated can confuse the
2160      compiler if the address of the structure is taken later.  */
2161   if (GET_CODE (operands[0]) == SUBREG
2162       && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (operands[0]))) < UNITS_PER_WORD))
2163     FAIL;
2164 }")
2165
2166 (define_insn ""
2167   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2168         (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2169                          (match_operand:SI 2 "const_int_operand" "i")
2170                          (match_operand:SI 3 "const_int_operand" "i")))]
2171   ""
2172   "*
2173 {
2174   int start = INTVAL (operands[3]) & 31;
2175   int size = INTVAL (operands[2]) & 31;
2176
2177   if (start + size >= 32)
2178     operands[3] = const0_rtx;
2179   else
2180     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2181   return \"{rlinm|rlwinm} %0,%1,%3,%s2,31\";
2182 }")
2183
2184 (define_insn ""
2185   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2186         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2187                          (match_operand:SI 2 "const_int_operand" "i")
2188                          (match_operand:SI 3 "const_int_operand" "i"))
2189                     (const_int 0)))
2190    (clobber (match_scratch:SI 4 "=r"))]
2191   ""
2192   "*
2193 {
2194   int start = INTVAL (operands[3]) & 31;
2195   int size = INTVAL (operands[2]) & 31;
2196
2197   /* If the bitfield being tested fits in the upper or lower half of a
2198      word, it is possible to use andiu. or andil. to test it.  This is
2199      useful because the condition register set-use delay is smaller for
2200      andi[ul]. than for rlinm.  This doesn't work when the starting bit
2201      position is 0 because the LT and GT bits may be set wrong.  */
2202
2203   if ((start > 0 && start + size <= 16) || start >= 16)
2204     {
2205       operands[3] = gen_rtx (CONST_INT, VOIDmode,
2206                              ((1 << (16 - (start & 15)))
2207                               - (1 << (16 - (start & 15) - size))));
2208       if (start < 16)
2209         return \"{andiu.|andis.} %4,%1,%3\";
2210       else
2211         return \"{andil.|andi.} %4,%1,%3\";
2212     }
2213
2214   if (start + size >= 32)
2215     operands[3] = const0_rtx;
2216   else
2217     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2218   return \"{rlinm.|rlwinm.} %4,%1,%3,%s2,31\";
2219 }"
2220   [(set_attr "type" "compare")])
2221
2222 (define_insn ""
2223   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2224         (compare:CC (zero_extract:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2225                          (match_operand:SI 2 "const_int_operand" "i")
2226                          (match_operand:SI 3 "const_int_operand" "i"))
2227                     (const_int 0)))
2228    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2229         (zero_extract:SI (match_dup 1) (match_dup 2) (match_dup 3)))]
2230   ""
2231   "*
2232 {
2233   int start = INTVAL (operands[3]) & 31;
2234   int size = INTVAL (operands[2]) & 31;
2235
2236   if (start >= 16 && start + size == 32)
2237     {
2238       operands[3] = gen_rtx (CONST_INT, VOIDmode, (1 << (32 - start)) - 1);
2239       return \"{andil.|andi.} %0,%1,%3\";
2240     }
2241
2242   if (start + size >= 32)
2243     operands[3] = const0_rtx;
2244   else
2245     operands[3] = gen_rtx (CONST_INT, VOIDmode, start + size);
2246   return \"{rlinm.|rlwinm.} %0,%1,%3,%s2,31\";
2247 }"
2248   [(set_attr "type" "delayed_compare")])
2249
2250 (define_insn "rotlsi3"
2251   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2252         (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2253                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2254   ""
2255   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffffffff")
2256
2257 (define_insn ""
2258   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2259         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2260                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2261                     (const_int 0)))
2262    (clobber (match_scratch:SI 3 "=r"))]
2263   ""
2264   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffffffff"
2265   [(set_attr "type" "delayed_compare")])
2266
2267 (define_insn ""
2268   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2269         (compare:CC (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2270                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2271                     (const_int 0)))
2272    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2273         (rotate:SI (match_dup 1) (match_dup 2)))]
2274   ""
2275   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffffffff"
2276   [(set_attr "type" "delayed_compare")])
2277
2278 (define_insn ""
2279   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2280         (and:SI (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2281                            (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2282                 (match_operand:SI 3 "mask_operand" "L")))]
2283   ""
2284   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,%m3,%M3")
2285
2286 (define_insn ""
2287   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2288         (compare:CC (and:SI
2289                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2290                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2291                      (match_operand:SI 3 "mask_operand" "L"))
2292                     (const_int 0)))
2293    (clobber (match_scratch:SI 4 "=r"))]
2294   ""
2295   "{rl%I2nm.|rlw%I2nm.} %4,%1,%h2,%m3,%M3"
2296   [(set_attr "type" "delayed_compare")])
2297
2298 (define_insn ""
2299   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2300         (compare:CC (and:SI
2301                      (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2302                                 (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2303                      (match_operand:SI 3 "mask_operand" "L"))
2304                     (const_int 0)))
2305    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2306         (and:SI (rotate:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2307   ""
2308   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,%m3,%M3"
2309   [(set_attr "type" "delayed_compare")])
2310
2311 (define_insn ""
2312   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2313         (zero_extend:SI
2314          (subreg:QI
2315           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2316                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2317   ""
2318   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xff")
2319
2320 (define_insn ""
2321   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2322         (compare:CC (zero_extend:SI
2323                      (subreg:QI
2324                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2325                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2326                     (const_int 0)))
2327    (clobber (match_scratch:SI 3 "=r"))]
2328   ""
2329   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xff"
2330   [(set_attr "type" "delayed_compare")])
2331
2332 (define_insn ""
2333   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2334         (compare:CC (zero_extend:SI
2335                      (subreg:QI
2336                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2337                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2338                     (const_int 0)))
2339    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2340         (zero_extend:SI (subreg:QI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2341   ""
2342   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xff"
2343   [(set_attr "type" "delayed_compare")])
2344
2345 (define_insn ""
2346   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2347         (zero_extend:SI
2348          (subreg:HI
2349           (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2350                      (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0)))]
2351   ""
2352   "{rl%I2nm|rlw%I2nm} %0,%1,%h2,0xffff")
2353
2354 (define_insn ""
2355   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2356         (compare:CC (zero_extend:SI
2357                      (subreg:HI
2358                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2359                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2360                     (const_int 0)))
2361    (clobber (match_scratch:SI 3 "=r"))]
2362   ""
2363   "{rl%I2nm.|rlw%I2nm.} %3,%1,%h2,0xffff"
2364   [(set_attr "type" "delayed_compare")])
2365
2366 (define_insn ""
2367   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2368         (compare:CC (zero_extend:SI
2369                      (subreg:HI
2370                       (rotate:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2371                                  (match_operand:SI 2 "reg_or_cint_operand" "ri")) 0))
2372                     (const_int 0)))
2373    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2374         (zero_extend:SI (subreg:HI (rotate:SI (match_dup 1) (match_dup 2)) 0)))]
2375   ""
2376   "{rl%I2nm.|rlw%I2nm.} %0,%1,%h2,0xffff"
2377   [(set_attr "type" "delayed_compare")])
2378
2379 ;; Note that we use "sle." instead of "sl." so that we can set
2380 ;; SHIFT_COUNT_TRUNCATED.
2381
2382 (define_expand "ashlsi3"
2383   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2384    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2385    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2386   ""
2387   "
2388 {
2389   if (TARGET_POWER)
2390     emit_insn (gen_ashlsi3_power (operands[0], operands[1], operands[2]));
2391   else
2392     emit_insn (gen_ashlsi3_no_power (operands[0], operands[1], operands[2]));
2393   DONE;
2394 }")
2395
2396 (define_insn "ashlsi3_power"
2397   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2398         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2399                    (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2400    (clobber (match_scratch:SI 3 "=q,X"))]
2401   "TARGET_POWER"
2402   "@
2403    sle %0,%1,%2
2404    {sli|slwi} %0,%1,%h2"
2405   [(set_attr "length" "8")])
2406
2407 (define_insn "ashlsi3_no_power"
2408   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2409         (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2410                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2411   "! TARGET_POWER"
2412   "{sl|slw}%I2 %0,%1,%h2"
2413   [(set_attr "length" "8")])
2414
2415 (define_insn ""
2416   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2417         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2418                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2419                     (const_int 0)))
2420    (clobber (match_scratch:SI 3 "=r,r"))
2421    (clobber (match_scratch:SI 4 "=q,X"))]
2422   "TARGET_POWER"
2423   "@
2424    sle. %3,%1,%2
2425    {sli.|slwi.} %3,%1,%h2"
2426   [(set_attr "type" "delayed_compare")])
2427
2428 (define_insn ""
2429   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2430         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2431                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2432                     (const_int 0)))
2433    (clobber (match_scratch:SI 3 "=r"))]
2434   "! TARGET_POWER"
2435   "{sl|slw}%I2. %3,%1,%h2"
2436   [(set_attr "type" "delayed_compare")])
2437
2438 (define_insn ""
2439   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2440         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2441                                (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2442                     (const_int 0)))
2443    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2444         (ashift:SI (match_dup 1) (match_dup 2)))
2445    (clobber (match_scratch:SI 4 "=q,X"))]
2446   "TARGET_POWER"
2447   "@
2448    sle. %0,%1,%2
2449    {sli.|slwi.} %0,%1,%h2"
2450   [(set_attr "type" "delayed_compare")])
2451
2452 (define_insn ""
2453   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2454         (compare:CC (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2455                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2456                     (const_int 0)))
2457    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2458         (ashift:SI (match_dup 1) (match_dup 2)))]
2459   "! TARGET_POWER"
2460   "{sl|slw}%I2. %0,%1,%h2"
2461   [(set_attr "type" "delayed_compare")])
2462
2463 (define_insn ""
2464   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2465         (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2466                            (match_operand:SI 2 "const_int_operand" "i"))
2467                 (match_operand:SI 3 "mask_operand" "L")))]
2468   "includes_lshift_p (operands[2], operands[3])"
2469   "{rlinm|rlwinm} %0,%1,%h2,%m3,%M3")
2470
2471 (define_insn ""
2472   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2473         (compare:CC
2474          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2475                             (match_operand:SI 2 "const_int_operand" "i"))
2476                  (match_operand:SI 3 "mask_operand" "L"))
2477          (const_int 0)))
2478    (clobber (match_scratch:SI 4 "=r"))]
2479   "includes_lshift_p (operands[2], operands[3])"
2480   "{rlinm.|rlwinm.} %4,%1,%h2,%m3,%M3"
2481   [(set_attr "type" "delayed_compare")])
2482
2483 (define_insn ""
2484   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2485         (compare:CC
2486          (and:SI (ashift:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2487                             (match_operand:SI 2 "const_int_operand" "i"))
2488                  (match_operand:SI 3 "mask_operand" "L"))
2489          (const_int 0)))
2490    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2491         (and:SI (ashift:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2492   "includes_lshift_p (operands[2], operands[3])"
2493   "{rlinm.|rlwinm.} %0,%1,%h2,%m3,%M3"
2494   [(set_attr "type" "delayed_compare")])
2495
2496 ;; The AIX assembler mis-handles "sri x,x,0", so write that case as
2497 ;; "sli x,x,0".
2498 (define_expand "lshrsi3"
2499   [(use (match_operand:SI 0 "gpc_reg_operand" ""))
2500    (use (match_operand:SI 1 "gpc_reg_operand" ""))
2501    (use (match_operand:SI 2 "reg_or_cint_operand" ""))]
2502   ""
2503   "
2504 {
2505   if (TARGET_POWER)
2506     emit_insn (gen_lshrsi3_power (operands[0], operands[1], operands[2]));
2507   else
2508     emit_insn (gen_lshrsi3_no_power (operands[0], operands[1], operands[2]));
2509   DONE;
2510 }")
2511
2512 (define_insn "lshrsi3_power"
2513   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2514         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2515                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2516    (clobber (match_scratch:SI 3 "=q,X"))]
2517   "TARGET_POWER"
2518   "@
2519   sre %0,%1,%2
2520   {s%A2i|s%A2wi} %0,%1,%h2")
2521
2522 (define_insn "lshrsi3_no_power"
2523   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2524         (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2525                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2526   "! TARGET_POWER"
2527   "{sr|srw}%I2 %0,%1,%h2")
2528
2529 (define_insn ""
2530   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2531         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2532                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2533                     (const_int 0)))
2534    (clobber (match_scratch:SI 3 "=r,r"))
2535    (clobber (match_scratch:SI 4 "=q,X"))]
2536   "TARGET_POWER"
2537   "@
2538   sre. %3,%1,%2
2539   {s%A2i.|s%A2wi.} %3,%1,%h2"
2540   [(set_attr "type" "delayed_compare")])
2541
2542 (define_insn ""
2543   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2544         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2545                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2546                     (const_int 0)))
2547    (clobber (match_scratch:SI 3 "=r"))]
2548   "! TARGET_POWER"
2549   "{sr|srw}%I2. %3,%1,%h2"
2550   [(set_attr "type" "delayed_compare")])
2551
2552 (define_insn ""
2553   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2554         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2555                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2556                     (const_int 0)))
2557    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2558         (lshiftrt:SI (match_dup 1) (match_dup 2)))
2559    (clobber (match_scratch:SI 4 "=q,X"))]
2560   "TARGET_POWER"
2561   "@
2562   sre. %0,%1,%2
2563   {s%A2i.|s%A2wi.} %0,%1,%h2"
2564   [(set_attr "type" "delayed_compare")])
2565
2566 (define_insn ""
2567   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2568         (compare:CC (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2569                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2570                     (const_int 0)))
2571    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2572         (lshiftrt:SI (match_dup 1) (match_dup 2)))]
2573   "! TARGET_POWER"
2574   "{sr|srw}%I2. %0,%1,%h2"
2575   [(set_attr "type" "delayed_compare")])
2576
2577 (define_insn ""
2578   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2579         (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2580                              (match_operand:SI 2 "const_int_operand" "i"))
2581                 (match_operand:SI 3 "mask_operand" "L")))]
2582   "includes_rshift_p (operands[2], operands[3])"
2583   "{rlinm|rlwinm} %0,%1,%s2,%m3,%M3")
2584
2585 (define_insn ""
2586   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2587         (compare:CC
2588          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2589                               (match_operand:SI 2 "const_int_operand" "i"))
2590                  (match_operand:SI 3 "mask_operand" "L"))
2591          (const_int 0)))
2592    (clobber (match_scratch:SI 4 "=r"))]
2593   "includes_rshift_p (operands[2], operands[3])"
2594   "{rlinm.|rlwinm.} %4,%1,%s2,%m3,%M3"
2595   [(set_attr "type" "delayed_compare")])
2596
2597 (define_insn ""
2598   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
2599         (compare:CC
2600          (and:SI (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2601                               (match_operand:SI 2 "const_int_operand" "i"))
2602                  (match_operand:SI 3 "mask_operand" "L"))
2603          (const_int 0)))
2604    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2605         (and:SI (lshiftrt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))]
2606   "includes_rshift_p (operands[2], operands[3])"
2607   "{rlinm.|rlwinm.} %0,%1,%s2,%m3,%M3"
2608   [(set_attr "type" "delayed_compare")])
2609
2610 (define_insn ""
2611   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2612         (zero_extend:SI
2613          (subreg:QI
2614           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2615                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2616   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2617   "{rlinm|rlwinm} %0,%1,%s2,0xff")
2618
2619 (define_insn ""
2620   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2621         (compare:CC
2622          (zero_extend:SI
2623           (subreg:QI
2624            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2625                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2626          (const_int 0)))
2627    (clobber (match_scratch:SI 3 "=r"))]
2628   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2629   "{rlinm.|rlwinm.} %3,%1,%s2,0xff"
2630   [(set_attr "type" "delayed_compare")])
2631
2632 (define_insn ""
2633   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2634         (compare:CC
2635          (zero_extend:SI
2636           (subreg:QI
2637            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2638                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2639          (const_int 0)))
2640    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2641         (zero_extend:SI (subreg:QI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2642   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 255))"
2643   "{rlinm.|rlwinm.} %0,%1,%s2,0xff"
2644   [(set_attr "type" "delayed_compare")])
2645
2646 (define_insn ""
2647   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2648         (zero_extend:SI
2649          (subreg:HI
2650           (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2651                        (match_operand:SI 2 "const_int_operand" "i")) 0)))]
2652   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2653   "{rlinm|rlwinm} %0,%1,%s2,0xffff")
2654
2655 (define_insn ""
2656   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2657         (compare:CC
2658          (zero_extend:SI
2659           (subreg:HI
2660            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2661                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2662          (const_int 0)))
2663    (clobber (match_scratch:SI 3 "=r"))]
2664   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2665   "{rlinm.|rlwinm.} %3,%1,%s2,0xffff"
2666   [(set_attr "type" "delayed_compare")])
2667
2668 (define_insn ""
2669   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2670         (compare:CC
2671          (zero_extend:SI
2672           (subreg:HI
2673            (lshiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2674                         (match_operand:SI 2 "const_int_operand" "i")) 0))
2675          (const_int 0)))
2676    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2677         (zero_extend:SI (subreg:HI (lshiftrt:SI (match_dup 1) (match_dup 2)) 0)))]
2678   "includes_rshift_p (operands[2], gen_rtx (CONST_INT, VOIDmode, 65535))"
2679   "{rlinm.|rlwinm.} %0,%1,%s2,0xffff"
2680   [(set_attr "type" "delayed_compare")])
2681
2682 (define_insn ""
2683   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2684                          (const_int 1)
2685                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2686         (ashiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2687                      (const_int 31)))]
2688   "TARGET_POWER"
2689   "rrib %0,%1,%2")
2690
2691 (define_insn ""
2692   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2693                          (const_int 1)
2694                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2695         (lshiftrt:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2696                      (const_int 31)))]
2697   "TARGET_POWER"
2698   "rrib %0,%1,%2")
2699
2700 (define_insn ""
2701   [(set (zero_extract:SI (match_operand:SI 0 "gpc_reg_operand" "+r")
2702                          (const_int 1)
2703                          (match_operand:SI 1 "gpc_reg_operand" "r"))
2704         (zero_extract:SI (match_operand:SI 2 "gpc_reg_operand" "r")
2705                          (const_int 1)
2706                          (const_int 0)))]
2707   "TARGET_POWER"
2708   "rrib %0,%1,%2")
2709
2710 (define_expand "ashrsi3"
2711   [(set (match_operand:SI 0 "gpc_reg_operand" "")
2712         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "")
2713                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
2714   ""
2715   "
2716 {
2717   if (TARGET_POWER)
2718     emit_insn (gen_ashrsi3_power (operands[0], operands[1], operands[2]));
2719   else
2720     emit_insn (gen_ashrsi3_no_power (operands[0], operands[1], operands[2]));
2721   DONE;
2722 }")
2723
2724 (define_insn "ashrsi3_power"
2725   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2726         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2727                      (match_operand:SI 2 "reg_or_cint_operand" "r,i")))
2728    (clobber (match_scratch:SI 3 "=q,X"))]
2729   "TARGET_POWER"
2730   "@
2731    srea %0,%1,%2
2732    {srai|srawi} %0,%1,%h2")
2733
2734 (define_insn "ashrsi3_no_power"
2735   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
2736         (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2737                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
2738   "! TARGET_POWER"
2739   "{sra|sraw}%I2 %0,%1,%h2")
2740
2741 (define_insn ""
2742   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
2743         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2744                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2745                     (const_int 0)))
2746    (clobber (match_scratch:SI 3 "=r,r"))
2747    (clobber (match_scratch:SI 4 "=q,X"))]
2748   "TARGET_POWER"
2749   "@
2750    srea. %3,%1,%2
2751    {srai.|srawi.} %3,%1,%h2"
2752   [(set_attr "type" "delayed_compare")])
2753
2754 (define_insn ""
2755   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
2756         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2757                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2758                     (const_int 0)))
2759    (clobber (match_scratch:SI 3 "=r"))]
2760   "! TARGET_POWER"
2761   "{sra|sraw}%I2. %3,%1,%h2"
2762   [(set_attr "type" "delayed_compare")])
2763
2764 (define_insn ""
2765   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
2766         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
2767                                  (match_operand:SI 2 "reg_or_cint_operand" "r,i"))
2768                     (const_int 0)))
2769    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
2770         (ashiftrt:SI (match_dup 1) (match_dup 2)))
2771    (clobber (match_scratch:SI 4 "=q,X"))]
2772   "TARGET_POWER"
2773   "@
2774    srea. %0,%1,%2
2775    {srai.|srawi.} %0,%1,%h2"
2776   [(set_attr "type" "delayed_compare")])
2777
2778 (define_insn ""
2779   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
2780         (compare:CC (ashiftrt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
2781                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
2782                     (const_int 0)))
2783    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
2784         (ashiftrt:SI (match_dup 1) (match_dup 2)))]
2785   "! TARGET_POWER"
2786   "{sra|sraw}%I2. %0,%1,%h2"
2787   [(set_attr "type" "delayed_compare")])
2788 \f
2789 ;; Floating-point insns, excluding normal data motion.
2790 ;;
2791 ;; PowerPC has a full set of single-precision floating point instructions.
2792 ;;
2793 ;; For the POWER architecture, we pretend that we have both SFmode and
2794 ;; DFmode insns, while, in fact, all fp insns are actually done in double.
2795 ;; The only conversions we will do will be when storing to memory.  In that
2796 ;; case, we will use the "frsp" instruction before storing.
2797 ;;
2798 ;; Note that when we store into a single-precision memory location, we need to
2799 ;; use the frsp insn first.  If the register being stored isn't dead, we
2800 ;; need a scratch register for the frsp.  But this is difficult when the store
2801 ;; is done by reload.  It is not incorrect to do the frsp on the register in
2802 ;; this case, we just lose precision that we would have otherwise gotten but
2803 ;; is not guaranteed.  Perhaps this should be tightened up at some point.
2804
2805 (define_insn "extendsfdf2"
2806   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
2807         (float_extend:DF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2808   "TARGET_HARD_FLOAT"
2809   "*
2810 {
2811   if (REGNO (operands[0]) == REGNO (operands[1]))
2812     return \"\";
2813   else
2814     return \"fmr %0,%1\";
2815 }"
2816   [(set_attr "type" "fp")])
2817
2818 (define_insn "truncdfsf2"
2819   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2820         (float_truncate:SF (match_operand:DF 1 "gpc_reg_operand" "f")))]
2821   "TARGET_HARD_FLOAT"
2822   "frsp %0,%1"
2823   [(set_attr "type" "fp")])
2824
2825 (define_insn "aux_truncdfsf2"
2826   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2827         (unspec:SF [(match_operand:SF 1 "gpc_reg_operand" "f")] 0))]
2828   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2829   "frsp %0,%1"
2830   [(set_attr "type" "fp")])
2831
2832 (define_insn "negsf2"
2833   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2834         (neg:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2835   "TARGET_HARD_FLOAT"
2836   "fneg %0,%1"
2837   [(set_attr "type" "fp")])
2838
2839 (define_insn "abssf2"
2840   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2841         (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
2842   "TARGET_HARD_FLOAT"
2843   "fabs %0,%1"
2844   [(set_attr "type" "fp")])
2845
2846 (define_insn ""
2847   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2848         (neg:SF (abs:SF (match_operand:SF 1 "gpc_reg_operand" "f"))))]
2849   "TARGET_HARD_FLOAT"
2850   "fnabs %0,%1"
2851   [(set_attr "type" "fp")])
2852
2853 (define_expand "addsf3"
2854   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2855         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2856                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2857   "TARGET_HARD_FLOAT"
2858   "")
2859
2860 (define_insn ""
2861   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2862         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2863                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2864   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2865   "fadds %0,%1,%2"
2866   [(set_attr "type" "fp")])
2867
2868 (define_insn ""
2869   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2870         (plus:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2871                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2872   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2873   "{fa|fadd} %0,%1,%2"
2874   [(set_attr "type" "fp")])
2875
2876 (define_expand "subsf3"
2877   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2878         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
2879                   (match_operand:SF 2 "gpc_reg_operand" "")))]
2880   "TARGET_HARD_FLOAT"
2881   "")
2882
2883 (define_insn ""
2884   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2885         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2886                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2887   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2888   "fsubs %0,%1,%2"
2889   [(set_attr "type" "fp")])
2890
2891 (define_insn ""
2892   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2893         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2894                   (match_operand:SF 2 "gpc_reg_operand" "f")))]
2895   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2896   "{fs|fsub} %0,%1,%2"
2897   [(set_attr "type" "fp")])
2898
2899 (define_expand "mulsf3"
2900   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2901         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "")
2902                  (match_operand:SF 2 "gpc_reg_operand" "")))]
2903   "TARGET_HARD_FLOAT"
2904   "")
2905
2906 (define_insn ""
2907   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2908         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2909                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2910   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2911   "fmuls %0,%1,%2"
2912   [(set_attr "type" "fp")])
2913
2914 (define_insn ""
2915   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2916         (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2917                  (match_operand:SF 2 "gpc_reg_operand" "f")))]
2918   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2919   "{fm|fmul} %0,%1,%2"
2920   [(set_attr "type" "dmul")])
2921
2922 (define_expand "divsf3"
2923   [(set (match_operand:SF 0 "gpc_reg_operand" "")
2924         (div:SF (match_operand:SF 1 "gpc_reg_operand" "")
2925                 (match_operand:SF 2 "gpc_reg_operand" "")))]
2926   "TARGET_HARD_FLOAT"
2927   "")
2928
2929 (define_insn ""
2930   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2931         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2932                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
2933   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2934   "fdivs %0,%1,%2"
2935   [(set_attr "type" "sdiv")])
2936
2937 (define_insn ""
2938   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2939         (div:SF (match_operand:SF 1 "gpc_reg_operand" "f")
2940                 (match_operand:SF 2 "gpc_reg_operand" "f")))]
2941   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2942   "{fd|fdiv} %0,%1,%2"
2943   [(set_attr "type" "ddiv")])
2944
2945 (define_insn ""
2946   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2947         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2948                           (match_operand:SF 2 "gpc_reg_operand" "f"))
2949                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
2950   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2951   "fmadds %0,%1,%2,%3"
2952   [(set_attr "type" "fp")])
2953
2954 (define_insn ""
2955   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2956         (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2957                           (match_operand:SF 2 "gpc_reg_operand" "f"))
2958                  (match_operand:SF 3 "gpc_reg_operand" "f")))]
2959   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2960   "{fma|fmadd} %0,%1,%2,%3"
2961   [(set_attr "type" "dmul")])
2962
2963 (define_insn ""
2964   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2965         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2966                            (match_operand:SF 2 "gpc_reg_operand" "f"))
2967                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
2968   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2969   "fmsubs %0,%1,%2,%3"
2970   [(set_attr "type" "fp")])
2971
2972 (define_insn ""
2973   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2974         (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2975                            (match_operand:SF 2 "gpc_reg_operand" "f"))
2976                   (match_operand:SF 3 "gpc_reg_operand" "f")))]
2977   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2978   "{fms|fmsub} %0,%1,%2,%3"
2979   [(set_attr "type" "dmul")])
2980
2981 (define_insn ""
2982   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2983         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2984                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
2985                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2986   "TARGET_POWERPC && TARGET_HARD_FLOAT"
2987   "fnmadds %0,%1,%2,%3"
2988   [(set_attr "type" "fp")])
2989
2990 (define_insn ""
2991   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
2992         (neg:SF (plus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
2993                                   (match_operand:SF 2 "gpc_reg_operand" "f"))
2994                          (match_operand:SF 3 "gpc_reg_operand" "f"))))]
2995   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
2996   "{fnma|fnmadd} %0,%1,%2,%3"
2997   [(set_attr "type" "dmul")])
2998
2999 (define_insn ""
3000   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3001         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3002                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
3003                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3004   "TARGET_POWERPC && TARGET_HARD_FLOAT"
3005   "fnmsubs %0,%1,%2,%3"
3006   [(set_attr "type" "fp")])
3007
3008 (define_insn ""
3009   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3010         (neg:SF (minus:SF (mult:SF (match_operand:SF 1 "gpc_reg_operand" "%f")
3011                                    (match_operand:SF 2 "gpc_reg_operand" "f"))
3012                           (match_operand:SF 3 "gpc_reg_operand" "f"))))]
3013   "! TARGET_POWERPC && TARGET_HARD_FLOAT"
3014   "{fnms|fnmsub} %0,%1,%2,%3"
3015   [(set_attr "type" "dmul")])
3016
3017 (define_expand "sqrtsf2"
3018   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3019         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "")))]
3020   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3021   "")
3022
3023 (define_insn ""
3024   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3025         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
3026   "TARGET_PPC_GPOPT && TARGET_HARD_FLOAT"
3027   "fsqrts %0,%1"
3028   [(set_attr "type" "ssqrt")])
3029
3030 (define_insn ""
3031   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3032         (sqrt:SF (match_operand:SF 1 "gpc_reg_operand" "f")))]
3033   "TARGET_POWER2 && TARGET_HARD_FLOAT"
3034   "fsqrt %0,%1"
3035   [(set_attr "type" "dsqrt")])
3036
3037 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3038 ;; fsel instruction and some auxiliary computations.  Then we just have a
3039 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3040 ;; combine.
3041 (define_expand "maxsf3"
3042   [(set (match_dup 3)
3043         (minus:SF (match_operand:SF 1 "gpc_reg_operand" "")
3044                   (match_operand:SF 2 "gpc_reg_operand" "")))
3045    (set (match_operand:SF 0 "gpc_reg_operand" "")
3046         (if_then_else:SF (ge (match_dup 3)
3047                              (const_int 0))
3048                          (match_dup 1)
3049                          (match_dup 2)))]
3050   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3051   "
3052 { operands[3] = gen_reg_rtx (SFmode); }")
3053
3054 (define_split
3055   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3056         (smax:SF (match_operand:SF 1 "gpc_reg_operand" "")
3057                  (match_operand:SF 2 "gpc_reg_operand" "")))
3058    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
3059   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3060   [(set (match_dup 3)
3061         (minus:SF (match_dup 1) (match_dup 2)))
3062    (set (match_dup 0)
3063         (if_then_else:SF (ge (match_dup 3)
3064                              (const_int 0))
3065                          (match_dup 1)
3066                          (match_dup 2)))]
3067   "")
3068
3069 (define_expand "minsf3"
3070   [(set (match_dup 3)
3071         (minus:SF (match_operand:SF 2 "gpc_reg_operand" "")
3072                   (match_operand:SF 1 "gpc_reg_operand" "")))
3073    (set (match_operand:SF 0 "gpc_reg_operand" "")
3074         (if_then_else:SF (ge (match_dup 3)
3075                              (const_int 0))
3076                          (match_dup 1)
3077                          (match_dup 2)))]
3078   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3079   "
3080 { operands[3] = gen_reg_rtx (SFmode); }")
3081
3082 (define_split
3083   [(set (match_operand:SF 0 "gpc_reg_operand" "")
3084         (smin:SF (match_operand:SF 1 "gpc_reg_operand" "")
3085                  (match_operand:SF 2 "gpc_reg_operand" "")))
3086    (clobber (match_operand:SF 3 "gpc_reg_operand" ""))]
3087   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3088   [(set (match_dup 3)
3089         (minus:SF (match_dup 2) (match_dup 1)))
3090    (set (match_dup 0)
3091         (if_then_else:SF (ge (match_dup 3)
3092                              (const_int 0))
3093                          (match_dup 1)
3094                          (match_dup 2)))]
3095   "")
3096
3097 (define_expand "movsfcc"
3098    [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3099          (if_then_else:SF (match_operand 1 "comparison_operator" "")
3100                           (match_operand:SF 2 "gpc_reg_operand" "f")
3101                           (match_operand:SF 3 "gpc_reg_operand" "f")))]
3102   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3103   "
3104 {
3105   rtx temp, op0, op1;
3106   enum rtx_code code = GET_CODE (operands[1]);
3107   if (! rs6000_compare_fp_p)
3108     FAIL;
3109   switch (code)
3110     {
3111     case GE: case EQ: case NE:
3112       op0 = rs6000_compare_op0;
3113       op1 = rs6000_compare_op1;
3114       break;
3115     case GT:
3116       op0 = rs6000_compare_op1;
3117       op1 = rs6000_compare_op0;
3118       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3119       break;
3120     case LE:
3121       op0 = rs6000_compare_op1;
3122       op1 = rs6000_compare_op0;
3123       break;
3124     case LT:
3125       op0 = rs6000_compare_op0;
3126       op1 = rs6000_compare_op1;
3127       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3128       break;
3129     default:
3130       FAIL;
3131     }
3132   if (GET_MODE (rs6000_compare_op0) == DFmode)
3133     {
3134       temp = gen_reg_rtx (DFmode);
3135       emit_insn (gen_subdf3 (temp, op0, op1));
3136       emit_insn (gen_fseldfsf4 (operands[0], temp, operands[2], operands[3]));
3137       if (code == EQ)
3138         {
3139           emit_insn (gen_negdf2 (temp, temp));
3140           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[0], operands[3]));
3141         }
3142       if (code == NE)
3143         {
3144           emit_insn (gen_negdf2 (temp, temp));
3145           emit_insn (gen_fseldfsf4 (operands[0], temp, operands[3], operands[0]));
3146         }
3147     }
3148   else
3149     {
3150       temp = gen_reg_rtx (SFmode);
3151       emit_insn (gen_subsf3 (temp, op0, op1));
3152       emit_insn (gen_fselsfsf4 (operands[0], temp, operands[2], operands[3]));
3153       if (code == EQ)
3154         {
3155           emit_insn (gen_negsf2 (temp, temp));
3156           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[0], operands[3]));
3157         }
3158       if (code == NE)
3159         {
3160           emit_insn (gen_negsf2 (temp, temp));
3161           emit_insn (gen_fselsfsf4 (operands[0], temp, operands[3], operands[0]));
3162         }
3163     }
3164   DONE;
3165 }")
3166
3167 (define_insn "fselsfsf4"
3168   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3169         (if_then_else:SF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3170                              (const_int 0))
3171                          (match_operand:SF 2 "gpc_reg_operand" "f")
3172                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3173   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3174   "fsel %0,%1,%2,%3"
3175   [(set_attr "type" "fp")])
3176
3177 (define_insn "fseldfsf4"
3178   [(set (match_operand:SF 0 "gpc_reg_operand" "=f")
3179         (if_then_else:SF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3180                              (const_int 0))
3181                          (match_operand:SF 2 "gpc_reg_operand" "f")
3182                          (match_operand:SF 3 "gpc_reg_operand" "f")))]
3183   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3184   "fsel %0,%1,%2,%3"
3185   [(set_attr "type" "fp")])
3186
3187 (define_insn "negdf2"
3188   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3189         (neg:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3190   "TARGET_HARD_FLOAT"
3191   "fneg %0,%1"
3192   [(set_attr "type" "fp")])
3193
3194 (define_insn "absdf2"
3195   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3196         (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3197   "TARGET_HARD_FLOAT"
3198   "fabs %0,%1"
3199   [(set_attr "type" "fp")])
3200
3201 (define_insn ""
3202   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3203         (neg:DF (abs:DF (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3204   "TARGET_HARD_FLOAT"
3205   "fnabs %0,%1"
3206   [(set_attr "type" "fp")])
3207
3208 (define_insn "adddf3"
3209   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3210         (plus:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3211                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3212   "TARGET_HARD_FLOAT"
3213   "{fa|fadd} %0,%1,%2"
3214   [(set_attr "type" "fp")])
3215
3216 (define_insn "subdf3"
3217   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3218         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3219                   (match_operand:DF 2 "gpc_reg_operand" "f")))]
3220   "TARGET_HARD_FLOAT"
3221   "{fs|fsub} %0,%1,%2"
3222   [(set_attr "type" "fp")])
3223
3224 (define_insn "muldf3"
3225   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3226         (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3227                  (match_operand:DF 2 "gpc_reg_operand" "f")))]
3228   "TARGET_HARD_FLOAT"
3229   "{fm|fmul} %0,%1,%2"
3230   [(set_attr "type" "dmul")])
3231
3232 (define_insn "divdf3"
3233   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3234         (div:DF (match_operand:DF 1 "gpc_reg_operand" "f")
3235                 (match_operand:DF 2 "gpc_reg_operand" "f")))]
3236   "TARGET_HARD_FLOAT"
3237   "{fd|fdiv} %0,%1,%2"
3238   [(set_attr "type" "ddiv")])
3239
3240 (define_insn ""
3241   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3242         (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3243                           (match_operand:DF 2 "gpc_reg_operand" "f"))
3244                  (match_operand:DF 3 "gpc_reg_operand" "f")))]
3245   "TARGET_HARD_FLOAT"
3246   "{fma|fmadd} %0,%1,%2,%3"
3247   [(set_attr "type" "dmul")])
3248
3249 (define_insn ""
3250   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3251         (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3252                            (match_operand:DF 2 "gpc_reg_operand" "f"))
3253                   (match_operand:DF 3 "gpc_reg_operand" "f")))]
3254   "TARGET_HARD_FLOAT"
3255   "{fms|fmsub} %0,%1,%2,%3"
3256   [(set_attr "type" "dmul")])
3257
3258 (define_insn ""
3259   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3260         (neg:DF (plus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3261                                   (match_operand:DF 2 "gpc_reg_operand" "f"))
3262                          (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3263   "TARGET_HARD_FLOAT"
3264   "{fnma|fnmadd} %0,%1,%2,%3"
3265   [(set_attr "type" "dmul")])
3266
3267 (define_insn ""
3268   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3269         (neg:DF (minus:DF (mult:DF (match_operand:DF 1 "gpc_reg_operand" "%f")
3270                                    (match_operand:DF 2 "gpc_reg_operand" "f"))
3271                           (match_operand:DF 3 "gpc_reg_operand" "f"))))]
3272   "TARGET_HARD_FLOAT"
3273   "{fnms|fnmsub} %0,%1,%2,%3"
3274   [(set_attr "type" "dmul")])
3275
3276 (define_insn "sqrtdf2"
3277   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3278         (sqrt:DF (match_operand:DF 1 "gpc_reg_operand" "f")))]
3279   "(TARGET_PPC_GPOPT || TARGET_POWER2) && TARGET_HARD_FLOAT"
3280   "fsqrt %0,%1"
3281   [(set_attr "type" "dsqrt")])
3282
3283 ;; For MIN, MAX, and conditional move, we use DEFINE_EXPAND's that involve a
3284 ;; fsel instruction and some auxiliary computations.  Then we just have a
3285 ;; single DEFINE_INSN for fsel and the define_splits to make them if made by
3286 ;; combine.
3287
3288 (define_expand "maxdf3"
3289   [(set (match_dup 3)
3290         (minus:DF (match_operand:DF 1 "gpc_reg_operand" "")
3291                   (match_operand:DF 2 "gpc_reg_operand" "")))
3292    (set (match_operand:DF 0 "gpc_reg_operand" "")
3293         (if_then_else:DF (ge (match_dup 3)
3294                              (const_int 0))
3295                          (match_dup 1)
3296                          (match_dup 2)))]
3297   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3298   "
3299 { operands[3] = gen_reg_rtx (DFmode); }")
3300
3301 (define_split
3302   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3303         (smax:DF (match_operand:DF 1 "gpc_reg_operand" "")
3304                  (match_operand:DF 2 "gpc_reg_operand" "")))
3305    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3306   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3307   [(set (match_dup 3)
3308         (minus:DF (match_dup 1) (match_dup 2)))
3309    (set (match_dup 0)
3310         (if_then_else:DF (ge (match_dup 3)
3311                              (const_int 0))
3312                          (match_dup 1)
3313                          (match_dup 2)))]
3314   "")
3315
3316 (define_expand "mindf3"
3317   [(set (match_dup 3)
3318         (minus:DF (match_operand:DF 2 "gpc_reg_operand" "")
3319                   (match_operand:DF 1 "gpc_reg_operand" "")))
3320    (set (match_operand:DF 0 "gpc_reg_operand" "")
3321         (if_then_else:DF (ge (match_dup 3)
3322                              (const_int 0))
3323                          (match_dup 1)
3324                          (match_dup 2)))]
3325   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3326   "
3327 { operands[3] = gen_reg_rtx (DFmode); }")
3328
3329 (define_split
3330   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3331         (smin:DF (match_operand:DF 1 "gpc_reg_operand" "")
3332                  (match_operand:DF 2 "gpc_reg_operand" "")))
3333    (clobber (match_operand:DF 3 "gpc_reg_operand" ""))]
3334   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3335   [(set (match_dup 3)
3336         (minus:DF (match_dup 2) (match_dup 1)))
3337    (set (match_dup 0)
3338         (if_then_else:DF (ge (match_dup 3)
3339                              (const_int 0))
3340                          (match_dup 1)
3341                          (match_dup 2)))]
3342   "")
3343
3344 (define_expand "movdfcc"
3345    [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3346          (if_then_else:DF (match_operand 1 "comparison_operator" "")
3347                           (match_operand:DF 2 "gpc_reg_operand" "f")
3348                           (match_operand:DF 3 "gpc_reg_operand" "f")))]
3349   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3350   "
3351 {
3352   rtx temp, op0, op1;
3353   enum rtx_code code = GET_CODE (operands[1]);
3354   if (! rs6000_compare_fp_p)
3355     FAIL;
3356   switch (code)
3357     {
3358     case GE: case EQ: case NE:
3359       op0 = rs6000_compare_op0;
3360       op1 = rs6000_compare_op1;
3361       break;
3362     case GT:
3363       op0 = rs6000_compare_op1;
3364       op1 = rs6000_compare_op0;
3365       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3366       break;
3367     case LE:
3368       op0 = rs6000_compare_op1;
3369       op1 = rs6000_compare_op0;
3370       break;
3371     case LT:
3372       op0 = rs6000_compare_op0;
3373       op1 = rs6000_compare_op1;
3374       temp = operands[2]; operands[2] = operands[3]; operands[3] = temp;
3375       break;
3376     default:
3377       FAIL;
3378     }
3379   if (GET_MODE (rs6000_compare_op0) == DFmode)
3380     {
3381       temp = gen_reg_rtx (DFmode);
3382       emit_insn (gen_subdf3 (temp, op0, op1));
3383       emit_insn (gen_fseldfdf4 (operands[0], temp, operands[2], operands[3]));
3384       if (code == EQ)
3385         {
3386           emit_insn (gen_negdf2 (temp, temp));
3387           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[0], operands[3]));
3388         }
3389       if (code == NE)
3390         {
3391           emit_insn (gen_negdf2 (temp, temp));
3392           emit_insn (gen_fseldfdf4 (operands[0], temp, operands[3], operands[0]));
3393         }
3394     }
3395   else
3396     {
3397       temp = gen_reg_rtx (SFmode);
3398       emit_insn (gen_subsf3 (temp, op0, op1));
3399       emit_insn (gen_fselsfdf4 (operands[0], temp, operands[2], operands[3]));
3400       if (code == EQ)
3401         {
3402           emit_insn (gen_negsf2 (temp, temp));
3403           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[0], operands[3]));
3404         }
3405       if (code == NE)
3406         {
3407           emit_insn (gen_negsf2 (temp, temp));
3408           emit_insn (gen_fselsfdf4 (operands[0], temp, operands[3], operands[0]));
3409         }
3410     }
3411   DONE;
3412 }")
3413
3414 (define_insn "fseldfdf4"
3415   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3416         (if_then_else:DF (ge (match_operand:DF 1 "gpc_reg_operand" "f")
3417                              (const_int 0))
3418                          (match_operand:DF 2 "gpc_reg_operand" "f")
3419                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3420   "TARGET_PPC_GFXOPT && TARGET_HARD_FLOAT"
3421   "fsel %0,%1,%2,%3"
3422   [(set_attr "type" "fp")])
3423
3424 (define_insn "fselsfdf4"
3425   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3426         (if_then_else:DF (ge (match_operand:SF 1 "gpc_reg_operand" "f")
3427                              (const_int 0))
3428                          (match_operand:DF 2 "gpc_reg_operand" "f")
3429                          (match_operand:DF 3 "gpc_reg_operand" "f")))]
3430   "TARGET_PPC_GFXOPT"
3431   "fsel %0,%1,%2,%3"
3432   [(set_attr "type" "fp")])
3433 \f
3434 ;; Conversions to and from floating-point.
3435 (define_expand "floatsidf2"
3436   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3437         (float:DF (match_operand:SI 1 "gpc_reg_operand" "")))]
3438   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3439   "
3440 {
3441   if (operands[0])
3442     {                           /* prevent unused warning messages */
3443       rtx high   = force_reg (SImode, GEN_INT (0x43300000));
3444       rtx low    = gen_reg_rtx (SImode);
3445       rtx df     = gen_reg_rtx (DFmode);
3446       rtx adjust = force_reg (DFmode, rs6000_float_const (\"4503601774854144\", DFmode));
3447
3448       emit_insn (gen_xorsi3 (low, operands[1], GEN_INT (0x80000000)));
3449       emit_insn (gen_move_to_float (df, low, high));
3450       emit_insn (gen_subdf3 (operands[0], df, adjust));
3451       DONE;
3452     }
3453 }")
3454
3455 (define_expand "floatunssidf2"
3456   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3457         (unsigned_float:DF (match_operand:SI 1 "gpc_reg_operand" "")))]
3458   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3459   "
3460 {
3461   if (operands[0])
3462     {                           /* prevent unused warning messages */
3463       rtx high   = force_reg (SImode, GEN_INT (0x43300000));
3464       rtx df     = gen_reg_rtx (DFmode);
3465       rtx adjust = force_reg (DFmode, rs6000_float_const (\"4503599627370496\", DFmode));
3466
3467       emit_insn (gen_move_to_float (df, operands[1], high));
3468       emit_insn (gen_subdf3 (operands[0], df, adjust));
3469       DONE;
3470     }
3471 }")
3472
3473 (define_expand "move_to_float"
3474   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3475         (unspec [(match_operand:SI 1 "gpc_reg_operand" "")
3476                  (match_operand:SI 2 "gpc_reg_operand" "")
3477                  (match_dup 3)] 2))]
3478   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3479   "
3480 {
3481   operands[3] = XEXP (rs6000_stack_temp (DFmode, 8, 1), 0);
3482 }")
3483
3484 (define_split
3485   [(set (match_operand:DF 0 "gpc_reg_operand" "")
3486         (unspec [(match_operand:SI 1 "gpc_reg_operand" "")
3487                  (match_operand:SI 2 "gpc_reg_operand" "")
3488                  (match_operand:SI 3 "offsettable_addr_operand" "")] 2))]
3489   "reload_completed"
3490   [(set (match_dup 4) (match_dup 1))
3491    (set (match_dup 5) (match_dup 2))
3492    (set (match_dup 0) (mem:DF (match_dup 3)))]
3493   "
3494 {
3495   rtx word1 = gen_rtx (MEM, SImode, operands[3]);
3496   rtx word2 = gen_rtx (MEM, SImode, plus_constant (operands[3], 4));
3497
3498   MEM_IN_STRUCT_P (word1) = 1;
3499   MEM_IN_STRUCT_P (word2) = 1;
3500
3501   if (WORDS_BIG_ENDIAN)
3502     {
3503       operands[4] = word2;
3504       operands[5] = word1;
3505     }
3506   else
3507     {
3508       operands[4] = word1;
3509       operands[5] = word2;
3510     }
3511 }")
3512
3513 (define_insn ""
3514   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3515         (unspec [(match_operand:SI 1 "gpc_reg_operand" "r")
3516                  (match_operand:SI 2 "gpc_reg_operand" "r")
3517                  (match_operand:SI 3 "offsettable_addr_operand" "p")] 2))]
3518   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3519   "#"
3520   [(set_attr "length" "12")])
3521
3522 (define_expand "fix_truncdfsi2"
3523   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3524         (fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3525   "TARGET_HARD_FLOAT"
3526   "
3527 {
3528   if (TARGET_POWER2 || TARGET_POWERPC)
3529     {
3530       rtx stack_slot = rs6000_stack_temp (DImode, 8, 1);
3531       rtx temp = gen_reg_rtx (DImode);
3532
3533       emit_insn (gen_fpcvtsi (temp, operands[1]));
3534       emit_move_insn (stack_slot, temp);
3535       emit_move_insn (operands[0],
3536                       gen_rtx (SUBREG, SImode, stack_slot, WORDS_BIG_ENDIAN));
3537       DONE;
3538     }
3539   else
3540     {
3541       emit_insn (gen_trunc_call (operands[0], operands[1],
3542                                  gen_rtx (SYMBOL_REF, Pmode, RS6000_ITRUNC)));
3543       DONE;
3544     }
3545 }")
3546
3547 (define_insn "fpcvtsi"
3548   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3549         (sign_extend:DI
3550          (fix:SI (match_operand:DF 1 "gpc_reg_operand" "f"))))]
3551   "(TARGET_POWER2 || TARGET_POWERPC) && TARGET_HARD_FLOAT"
3552   "{fcirz|fctiwz} %0,%1"
3553   [(set_attr "type" "fp")])
3554
3555 (define_expand "fixuns_truncdfsi2"
3556   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3557         (unsigned_fix:SI (match_operand:DF 1 "gpc_reg_operand" "")))]
3558   "! TARGET_POWER2 && ! TARGET_POWERPC && TARGET_HARD_FLOAT"
3559   "
3560 {
3561   emit_insn (gen_trunc_call (operands[0], operands[1],
3562                              gen_rtx (SYMBOL_REF, Pmode, RS6000_UITRUNC)));
3563   DONE;
3564 }")
3565
3566 (define_expand "trunc_call"
3567   [(parallel [(set (match_operand:SI 0 "" "")
3568                    (fix:SI (match_operand:DF 1 "" "")))
3569               (use (match_operand:SI 2 "" ""))])]
3570   "TARGET_HARD_FLOAT"
3571   "
3572 {
3573   rtx insns = gen_trunc_call_rtl (operands[0], operands[1], operands[2]);
3574   rtx first = XVECEXP (insns, 0, 0);
3575   rtx last = XVECEXP (insns, 0, XVECLEN (insns, 0) - 1);
3576
3577   REG_NOTES (first) = gen_rtx (INSN_LIST, REG_LIBCALL, last,
3578                                REG_NOTES (first));
3579   REG_NOTES (last) = gen_rtx (INSN_LIST, REG_RETVAL, first, REG_NOTES (last));
3580
3581   emit_insn (insns);
3582   DONE;
3583 }")
3584
3585 (define_expand "trunc_call_rtl"
3586   [(set (reg:DF 33) (match_operand:DF 1 "gpc_reg_operand" ""))
3587    (use (reg:DF 33))
3588    (parallel [(set (reg:SI 3)
3589                    (call (mem:SI (match_operand 2 "" "")) (const_int 0)))
3590               (use (const_int 0))
3591               (clobber (scratch:SI))])
3592    (set (match_operand:SI 0 "gpc_reg_operand" "")
3593         (reg:SI 3))]
3594   "TARGET_HARD_FLOAT"
3595   "
3596 {
3597   rs6000_trunc_used = 1;
3598 }")
3599
3600 (define_insn "floatdidf2"
3601   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
3602         (float:DF (match_operand:DI 1 "gpc_reg_operand" "f")))]
3603   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3604   "fcfid %0,%1"
3605   [(set_attr "type" "fp")])
3606
3607 (define_insn "fix_truncdfdi2"
3608   [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
3609         (fix:DI (match_operand:DF 1 "gpc_reg_operand" "f")))]
3610   "TARGET_POWERPC64 && TARGET_HARD_FLOAT"
3611   "fctidz %0,%1"
3612   [(set_attr "type" "fp")])
3613 \f
3614 ;; Define the DImode operations that can be done in a small number
3615 ;; of instructions.  The & constraints are to prevent the register
3616 ;; allocator from allocating registers that overlap with the inputs
3617 ;; (for example, having an input in 7,8 and an output in 6,7).  We
3618 ;; also allow for the the output being the same as one of the inputs.
3619
3620 (define_insn "*adddi3_noppc64"
3621   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r")
3622         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,0,0")
3623                  (match_operand:DI 2 "reg_or_short_operand" "r,I,r,I")))]
3624   "! TARGET_POWERPC64"
3625   "*
3626 {
3627   if (WORDS_BIG_ENDIAN)
3628     return (GET_CODE (operands[2])) != CONST_INT
3629             ? \"{a|addc} %L0,%L1,%L2\;{ae|adde} %0,%1,%2\"
3630             : \"{ai|addic} %L0,%L1,%2\;{a%G2e|add%G2e} %0,%1\";
3631   else
3632     return (GET_CODE (operands[2])) != CONST_INT
3633             ? \"{a|addc} %0,%1,%2\;{ae|adde} %L0,%L1,%L2\"
3634             : \"{ai|addic} %0,%1,%2\;{a%G2e|add%G2e} %L0,%L1\";
3635 }"
3636   [(set_attr "length" "8")])
3637
3638 (define_insn "*subdi3_noppc64"
3639   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,&r,r,r,r")
3640         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I,0,r,I")
3641                   (match_operand:DI 2 "gpc_reg_operand" "r,r,r,0,0")))]
3642   "! TARGET_POWERPC64"
3643   "*
3644 {
3645   if (WORDS_BIG_ENDIAN)
3646     return (GET_CODE (operands[1]) != CONST_INT)
3647             ? \"{sf|subfc} %L0,%L2,%L1\;{sfe|subfe} %0,%2,%1\"
3648             : \"{sfi|subfic} %L0,%L2,%1\;{sf%G1e|subf%G1e} %0,%2\";
3649   else
3650     return (GET_CODE (operands[1]) != CONST_INT)
3651             ? \"{sf|subfc} %0,%2,%1\;{sfe|subfe} %L0,%L2,%L1\"
3652             : \"{sfi|subfic} %0,%2,%1\;{sf%G1e|subf%G1e} %L0,%L2\";
3653 }"
3654   [(set_attr "length" "8")])
3655
3656 (define_insn "*negdi2_noppc64"
3657   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
3658         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))]
3659   "! TARGET_POWERPC64"
3660   "*
3661 {
3662   return (WORDS_BIG_ENDIAN)
3663     ? \"{sfi|subfic} %L0,%L1,0\;{sfze|subfze} %0,%1\"
3664     : \"{sfi|subfic} %0,%1,0\;{sfze|subfze} %L0,%L1\";
3665 }"
3666   [(set_attr "length" "8")])
3667
3668 (define_expand "mulsidi3"
3669   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3670         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3671                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
3672   ""
3673   "
3674 {
3675   if (! TARGET_POWER && ! TARGET_POWERPC)
3676     {
3677       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3678       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3679       emit_insn (gen_mull_call ());
3680       if (WORDS_BIG_ENDIAN)
3681         emit_move_insn (operands[0], gen_rtx (REG, DImode, 3));
3682       else
3683         {
3684           emit_move_insn (operand_subword (operands[0], 0, 0, DImode),
3685                           gen_rtx (REG, SImode, 3));
3686           emit_move_insn (operand_subword (operands[0], 1, 0, DImode),
3687                           gen_rtx (REG, SImode, 4));
3688         }
3689       DONE;
3690     }
3691   else if (TARGET_POWER)
3692     {
3693       emit_insn (gen_mulsidi3_mq (operands[0], operands[1], operands[2]));
3694       DONE;
3695     }
3696 }")
3697
3698 (define_insn "mulsidi3_mq"
3699   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3700         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3701                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))
3702    (clobber (match_scratch:SI 3 "=q"))]
3703   "TARGET_POWER"
3704   "mul %0,%1,%2\;mfmq %L0"
3705   [(set_attr "type" "imul")
3706    (set_attr "length" "8")])
3707
3708 (define_insn "*mulsidi3_powerpc"
3709   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
3710         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3711                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
3712   "TARGET_POWERPC && ! TARGET_POWERPC64"
3713   "*
3714 {
3715   return (WORDS_BIG_ENDIAN)
3716     ? \"mulhw %0,%1,%2\;mullw %L0,%1,%2\"
3717     : \"mulhw %L0,%1,%2\;mullw %0,%1,%2\";
3718 }"
3719   [(set_attr "type" "imul")
3720    (set_attr "length" "8")])
3721
3722 (define_split
3723   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3724         (mult:DI (sign_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3725                  (sign_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
3726   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
3727   [(set (match_dup 3)
3728         (truncate:SI
3729          (lshiftrt:DI (mult:DI (sign_extend:DI (match_dup 1))
3730                                (sign_extend:DI (match_dup 2)))
3731                       (const_int 32))))
3732    (set (match_dup 4)
3733         (mult:SI (match_dup 1)
3734                  (match_dup 2)))]
3735   "
3736 {
3737   int endian = (WORDS_BIG_ENDIAN == 0);
3738   operands[3] = operand_subword (operands[0], endian, 0, DImode);
3739   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
3740 }")
3741
3742 (define_insn "umulsidi3"
3743   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
3744         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" "%r"))
3745                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" "r"))))]
3746   "TARGET_POWERPC && ! TARGET_POWERPC64"
3747   "*
3748 {
3749   return (WORDS_BIG_ENDIAN)
3750     ? \"mulhwu %0,%1,%2\;mullw %L0,%1,%2\"
3751     : \"mulhwu %L0,%1,%2\;mullw %0,%1,%2\";
3752 }"
3753   [(set_attr "type" "imul")
3754    (set_attr "length" "8")])
3755
3756 (define_split
3757   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3758         (mult:DI (zero_extend:DI (match_operand:SI 1 "gpc_reg_operand" ""))
3759                  (zero_extend:DI (match_operand:SI 2 "gpc_reg_operand" ""))))]
3760   "TARGET_POWERPC && ! TARGET_POWERPC64 && reload_completed"
3761   [(set (match_dup 3)
3762         (truncate:SI
3763          (lshiftrt:DI (mult:DI (zero_extend:DI (match_dup 1))
3764                                (zero_extend:DI (match_dup 2)))
3765                       (const_int 32))))
3766    (set (match_dup 4)
3767         (mult:SI (match_dup 1)
3768                  (match_dup 2)))]
3769   "
3770 {
3771   int endian = (WORDS_BIG_ENDIAN == 0);
3772   operands[3] = operand_subword (operands[0], endian, 0, DImode);
3773   operands[4] = operand_subword (operands[0], 1 - endian, 0, DImode);
3774 }")
3775
3776 (define_expand "smulsi3_highpart"
3777   [(set (match_operand:SI 0 "gpc_reg_operand" "")
3778         (truncate:SI
3779          (lshiftrt:DI (mult:DI (sign_extend:DI
3780                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3781                                (sign_extend:DI
3782                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3783                       (const_int 32))))]
3784   ""
3785   "
3786 {
3787   if (! TARGET_POWER && ! TARGET_POWERPC)
3788     {
3789       emit_move_insn (gen_rtx (REG, SImode, 3), operands[1]);
3790       emit_move_insn (gen_rtx (REG, SImode, 4), operands[2]);
3791       emit_insn (gen_mulh_call ());
3792       emit_move_insn (operands[0], gen_rtx (REG, SImode, 3));
3793       DONE;
3794     }
3795   else if (TARGET_POWER)
3796     {
3797       emit_insn (gen_smulsi3_highpart_mq (operands[0], operands[1], operands[2]));
3798       DONE;
3799     }
3800 }")
3801
3802 (define_insn "smulsi3_highpart_mq"
3803   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3804         (truncate:SI
3805          (lshiftrt:DI (mult:DI (sign_extend:DI
3806                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3807                                (sign_extend:DI
3808                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3809                       (const_int 32))))
3810    (clobber (match_scratch:SI 3 "=q"))]
3811   "TARGET_POWER"
3812   "mul %0,%1,%2"
3813   [(set_attr "type" "imul")])
3814
3815 (define_insn ""
3816   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3817         (truncate:SI
3818          (lshiftrt:DI (mult:DI (sign_extend:DI
3819                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3820                                (sign_extend:DI
3821                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3822                       (const_int 32))))]
3823   "TARGET_POWERPC"
3824   "mulhw %0,%1,%2"
3825   [(set_attr "type" "imul")])
3826
3827 (define_insn "umulsi3_highpart"
3828   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
3829         (truncate:SI
3830          (lshiftrt:DI (mult:DI (zero_extend:DI
3831                                 (match_operand:SI 1 "gpc_reg_operand" "%r"))
3832                                (zero_extend:DI
3833                                 (match_operand:SI 2 "gpc_reg_operand" "r")))
3834                       (const_int 32))))]
3835   "TARGET_POWERPC"
3836   "mulhwu %0,%1,%2"
3837   [(set_attr "type" "imul")])
3838
3839 ;; If operands 0 and 2 are in the same register, we have a problem.  But
3840 ;; operands 0 and 1 (the usual case) can be in the same register.  That's
3841 ;; why we have the strange constraints below.
3842 (define_insn "ashldi3_power"
3843   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r,&r")
3844         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
3845                    (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
3846    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
3847   "TARGET_POWER"
3848   "@
3849    {sli|slwi} %0,%L1,%h2\;{cal %L0,0(0)|li %L0,0}
3850    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
3851    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2
3852    sl%I2q %L0,%L1,%h2\;sll%I2q %0,%1,%h2"
3853   [(set_attr "length" "8")])
3854
3855 (define_insn "lshrdi3_power"
3856   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r,r,&r")
3857         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r,0,r")
3858                      (match_operand:SI 2 "reg_or_cint_operand" "M,i,r,r")))
3859    (clobber (match_scratch:SI 3 "=X,q,q,q"))]
3860   "TARGET_POWER"
3861   "@
3862    {cal %0,0(0)|li %0,0}\;{s%A2i|s%A2wi} %L0,%1,%h2
3863    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
3864    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2
3865    sr%I2q %0,%1,%h2\;srl%I2q %L0,%L1,%h2"
3866   [(set_attr "length" "8")])
3867
3868 ;; Shift by a variable amount is too complex to be worth open-coding.  We
3869 ;; just handle shifts by constants.
3870 (define_insn "ashrdi3_power"
3871   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3872         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r,r")
3873                      (match_operand:SI 2 "const_int_operand" "M,i")))
3874    (clobber (match_scratch:SI 3 "=X,q"))]
3875   "TARGET_POWER"
3876   "@
3877    {srai|srawi} %0,%1,31\;{srai|srawi} %L0,%1,%h2
3878    sraiq %0,%1,%h2\;srliq %L0,%L1,%h2"
3879   [(set_attr "length" "8")])
3880 \f
3881 ;; PowerPC64 DImode operations.
3882
3883 (define_expand "adddi3"
3884   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3885         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
3886                  (match_operand:DI 2 "add_operand" "")))]
3887   ""
3888   "
3889 {
3890   if (! TARGET_POWERPC64 && non_add_cint_operand (operands[2], DImode))
3891     FAIL;
3892 }")
3893
3894 ;; Discourage ai/addic because of carry but provide it in an alternative
3895 ;; allowing register zero as source.
3896
3897 (define_insn ""
3898   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,?r,r")
3899         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,b,r,b")
3900                  (match_operand:DI 2 "add_operand" "r,I,I,J")))]
3901   "TARGET_POWERPC64"
3902   "@
3903    add %0,%1,%2
3904    addi %0,%1,%2
3905    addic %0,%1,%2
3906    addis %0,%1,%u2")
3907
3908 (define_insn ""
3909   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
3910         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
3911                              (match_operand:DI 2 "reg_or_short_operand" "r,I"))
3912                     (const_int 0)))
3913    (clobber (match_scratch:DI 3 "=r,r"))]
3914   "TARGET_POWERPC64"
3915   "@
3916    add. %3,%1,%2
3917    addic. %3,%1,%2"
3918   [(set_attr "type" "compare")])
3919
3920 (define_insn ""
3921   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
3922         (compare:CC (plus:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r")
3923                              (match_operand:DI 2 "reg_or_short_operand" "r,I"))
3924                     (const_int 0)))
3925    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3926         (plus:DI (match_dup 1) (match_dup 2)))]
3927   "TARGET_POWERPC64"
3928   "@
3929    add. %0,%1,%2
3930    addic. %0,%1,%2"
3931   [(set_attr "type" "compare")])
3932
3933 ;; Split an add that we can't do in one insn into two insns, each of which
3934 ;; does one 16-bit part.  This is used by combine.  Note that the low-order
3935 ;; add should be last in case the result gets used in an address.
3936
3937 (define_split
3938   [(set (match_operand:DI 0 "gpc_reg_operand" "")
3939         (plus:DI (match_operand:DI 1 "gpc_reg_operand" "")
3940                  (match_operand:DI 2 "non_add_cint_operand" "")))]
3941   "TARGET_POWERPC64"
3942   [(set (match_dup 0) (plus:DI (match_dup 1) (match_dup 3)))
3943    (set (match_dup 0) (plus:DI (match_dup 0) (match_dup 4)))]
3944 "
3945 {
3946   HOST_WIDE_INT low = INTVAL (operands[2]) & 0xffff;
3947   HOST_WIDE_INT high = INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff);
3948
3949   if (low & 0x8000)
3950     high+=0x10000, low |= ((HOST_WIDE_INT) -1) << 16;
3951
3952   operands[3] = GEN_INT (high);
3953   operands[4] = GEN_INT (low);
3954 }")
3955
3956 (define_insn "one_cmpldi2"
3957   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
3958         (not:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
3959   "TARGET_POWERPC64"
3960   "nor %0,%1,%1")
3961
3962 (define_insn ""
3963   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
3964         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
3965                     (const_int 0)))
3966    (clobber (match_scratch:DI 2 "=r"))]
3967   "TARGET_POWERPC64"
3968   "nor. %2,%1,%1"
3969   [(set_attr "type" "compare")])
3970
3971 (define_insn ""
3972   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
3973         (compare:CC (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
3974                     (const_int 0)))
3975    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
3976         (not:DI (match_dup 1)))]
3977   "TARGET_POWERPC64"
3978   "nor. %0,%1,%1"
3979   [(set_attr "type" "compare")])
3980
3981 (define_insn ""
3982   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r")
3983         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "r,I")
3984                   (match_operand:DI 2 "gpc_reg_operand" "r,r")))]
3985   "TARGET_POWERPC64"
3986   "@
3987    subf %0,%2,%1
3988    subfic %0,%2,%1")
3989
3990 (define_insn ""
3991   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
3992         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
3993                               (match_operand:DI 2 "gpc_reg_operand" "r"))
3994                     (const_int 0)))
3995    (clobber (match_scratch:DI 3 "=r"))]
3996   "TARGET_POWERPC64"
3997   "subf. %3,%2,%1"
3998   [(set_attr "type" "compare")])
3999
4000 (define_insn ""
4001   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4002         (compare:CC (minus:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4003                               (match_operand:DI 2 "gpc_reg_operand" "r"))
4004                     (const_int 0)))
4005    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4006         (minus:DI (match_dup 1) (match_dup 2)))]
4007   "TARGET_POWERPC64"
4008   "subf. %0,%2,%1"
4009   [(set_attr "type" "compare")])
4010
4011 (define_expand "subdi3"
4012   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4013         (minus:DI (match_operand:DI 1 "reg_or_short_operand" "")
4014                   (match_operand:DI 2 "reg_or_cint_operand" "")))]
4015   ""
4016   "
4017 {
4018   if (GET_CODE (operands[2]) == CONST_INT)
4019     {
4020       emit_insn (gen_adddi3 (operands[0], operands[1],
4021                              negate_rtx (DImode, operands[2])));
4022       DONE;
4023     }
4024 }")
4025
4026 (define_insn "absdi2"
4027   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4028         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
4029    (clobber (match_scratch:DI 2 "=&r,&r"))]
4030   "TARGET_POWERPC64"
4031   "sradi %2,%1,31\;xor %0,%2,%1\;subf %0,%2,%0"
4032   [(set_attr "length" "12")])
4033
4034 (define_split
4035   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4036         (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0")))
4037    (clobber (match_scratch:DI 2 "=&r,&r"))]
4038   "TARGET_POWERPC64 && reload_completed"
4039   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 31)))
4040    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
4041    (set (match_dup 0) (minus:DI (match_dup 2) (match_dup 0)))]
4042   "")
4043
4044 (define_insn ""
4045   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4046         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
4047    (clobber (match_scratch:DI 2 "=&r,&r"))]
4048   "TARGET_POWERPC64"
4049   "sradi %2,%1,31\;xor %0,%2,%1\;subf %0,%0,%2"
4050   [(set_attr "length" "12")])
4051
4052 (define_split
4053   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r,r")
4054         (neg:DI (abs:DI (match_operand:DI 1 "gpc_reg_operand" "r,0"))))
4055    (clobber (match_scratch:DI 2 "=&r,&r"))]
4056   "TARGET_POWERPC64 && reload_completed"
4057   [(set (match_dup 2) (ashiftrt:DI (match_dup 1) (const_int 31)))
4058    (set (match_dup 0) (xor:DI (match_dup 2) (match_dup 1)))
4059    (set (match_dup 0) (minus:DI (match_dup 0) (match_dup 2)))]
4060   "")
4061
4062 (define_expand "negdi2"
4063   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4064         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "")))]
4065   ""
4066   "")
4067
4068 (define_insn ""
4069   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4070         (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
4071   "TARGET_POWERPC64"
4072   "neg %0,%1")
4073
4074 (define_insn ""
4075   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4076         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4077                     (const_int 0)))
4078    (clobber (match_scratch:DI 2 "=r"))]
4079   "TARGET_POWERPC64"
4080   "neg. %2,%1"
4081   [(set_attr "type" "compare")])
4082
4083 (define_insn ""
4084   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
4085         (compare:CC (neg:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4086                     (const_int 0)))
4087    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4088         (neg:DI (match_dup 1)))]
4089   "TARGET_POWERPC64"
4090   "neg. %0,%1"
4091   [(set_attr "type" "compare")])
4092
4093 (define_insn "ffsdi2"
4094   [(set (match_operand:DI 0 "gpc_reg_operand" "=&r")
4095         (ffs:DI (match_operand:DI 1 "gpc_reg_operand" "r")))]
4096   "TARGET_POWERPC64"
4097   "neg %0,%1\;and %0,%0,%1\;cntlzd %0,%0\;subfic %0,%0,64"
4098   [(set_attr "length" "16")])
4099
4100 (define_insn "muldi3"
4101   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4102         (mult:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4103                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
4104   "TARGET_POWERPC64"
4105   "mulld %0,%1,%2"
4106    [(set_attr "type" "imul")])
4107
4108 (define_insn "smuldi3_highpart"
4109   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4110         (truncate:DI
4111          (lshiftrt:TI (mult:TI (sign_extend:TI
4112                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
4113                                (sign_extend:TI
4114                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
4115                       (const_int 64))))]
4116   "TARGET_POWERPC64"
4117   "mulhd %0,%1,%2"
4118   [(set_attr "type" "imul")])
4119
4120 (define_insn "umuldi3_highpart"
4121   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4122         (truncate:DI
4123          (lshiftrt:TI (mult:TI (zero_extend:TI
4124                                 (match_operand:DI 1 "gpc_reg_operand" "%r"))
4125                                (zero_extend:TI
4126                                 (match_operand:DI 2 "gpc_reg_operand" "r")))
4127                       (const_int 64))))]
4128   "TARGET_POWERPC64"
4129   "mulhdu %0,%1,%2"
4130   [(set_attr "type" "imul")])
4131
4132 (define_expand "divdi3"
4133   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4134         (div:DI (match_operand:DI 1 "gpc_reg_operand" "")
4135                 (match_operand:DI 2 "reg_or_cint_operand" "")))]
4136   "TARGET_POWERPC64"
4137   "
4138 {
4139   if (GET_CODE (operands[2]) == CONST_INT
4140       && exact_log2 (INTVAL (operands[2])) >= 0)
4141     ;
4142   else
4143     operands[2] = force_reg (DImode, operands[2]);
4144 }")
4145
4146 (define_expand "moddi3"
4147   [(use (match_operand:DI 0 "gpc_reg_operand" ""))
4148    (use (match_operand:DI 1 "gpc_reg_operand" ""))
4149    (use (match_operand:DI 2 "reg_or_cint_operand" ""))]
4150   "TARGET_POWERPC64"
4151   "
4152 {
4153   int i = exact_log2 (INTVAL (operands[2]));
4154   rtx temp1;
4155   rtx temp2;
4156
4157   if (GET_CODE (operands[2]) != CONST_INT || i < 0)
4158     FAIL;
4159
4160   temp1 = gen_reg_rtx (DImode);
4161   temp2 = gen_reg_rtx (DImode);
4162
4163   emit_insn (gen_divdi3 (temp1, operands[1], operands[2]));
4164   emit_insn (gen_ashldi3 (temp2, temp1, GEN_INT (i)));
4165   emit_insn (gen_subdi3 (operands[0], operands[1], temp2));
4166   DONE;
4167 }")
4168
4169 (define_insn ""
4170   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4171         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4172                 (match_operand:DI 2 "const_int_operand" "N")))]
4173   "TARGET_POWERPC64 && exact_log2 (INTVAL (operands[2])) >= 0"
4174   "sradi %0,%1,%p2\;addze %0,%0"
4175   [(set_attr "length" "8")])
4176
4177 (define_insn ""
4178   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4179         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4180                             (match_operand:DI 2 "const_int_operand" "N"))
4181                     (const_int 0)))
4182    (clobber (match_scratch:DI 3 "=r"))]
4183   "TARGET_POWERPC64 && exact_log2 (INTVAL (operands[2])) >= 0"
4184   "sradi %3,%1,%p2\;addze. %3,%3"
4185   [(set_attr "type" "compare")
4186    (set_attr "length" "8")])
4187
4188 (define_insn ""
4189   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4190         (compare:CC (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4191                             (match_operand:DI 2 "const_int_operand" "N"))
4192                     (const_int 0)))
4193    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4194         (div:DI (match_dup 1) (match_dup 2)))]
4195   "TARGET_POWERPC64 && exact_log2 (INTVAL (operands[2])) >= 0"
4196   "sradi %0,%1,%p2\;addze. %0,%0"
4197   [(set_attr "type" "compare")
4198    (set_attr "length" "8")])
4199
4200 (define_insn ""
4201   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4202         (div:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4203                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
4204   "TARGET_POWERPC64"
4205   "divd %0,%1,%2"
4206   [(set_attr "type" "idiv")])
4207
4208 (define_insn "udivdi3"
4209   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4210         (udiv:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4211                  (match_operand:DI 2 "gpc_reg_operand" "r")))]
4212   "TARGET_POWERPC64"
4213   "divdu %0,%1,%2"
4214   [(set_attr "type" "idiv")])
4215
4216 (define_insn "rotldi3"
4217   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4218         (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4219                    (match_operand:DI 2 "reg_or_cint_operand" "ri")))]
4220   "TARGET_POWERPC64"
4221   "rld%I2cl %0,%1,%h2,0")
4222
4223 (define_insn ""
4224   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4225         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4226                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
4227                     (const_int 0)))
4228    (clobber (match_scratch:DI 3 "=r"))]
4229   "TARGET_POWERPC64"
4230   "rld%I2cl. %3,%1,%h2,0"
4231   [(set_attr "type" "delayed_compare")])
4232
4233 (define_insn ""
4234   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4235         (compare:CC (rotate:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4236                                (match_operand:DI 2 "reg_or_cint_operand" "ri"))
4237                     (const_int 0)))
4238    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4239         (rotate:DI (match_dup 1) (match_dup 2)))]
4240   "TARGET_POWERPC64"
4241   "rld%I2cl. %0,%1,%h2,0"
4242   [(set_attr "type" "delayed_compare")])
4243
4244 (define_expand "ashldi3"
4245   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4246         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "")
4247                    (match_operand:SI 2 "reg_or_cint_operand" "")))]
4248   "TARGET_POWERPC64 || TARGET_POWER"
4249   "
4250 {
4251   if (TARGET_POWERPC64)
4252     ;
4253   else if (TARGET_POWER)
4254     {
4255       emit_insn (gen_ashldi3_power (operands[0], operands[1], operands[2]));
4256       DONE;
4257     }
4258   else
4259     FAIL;
4260 }")
4261
4262 (define_insn ""
4263   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4264         (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4265                    (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4266   "TARGET_POWERPC64"
4267   "sld%I2 %0,%1,%2"
4268   [(set_attr "length" "8")])
4269   
4270 (define_insn ""
4271   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4272         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4273                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4274                     (const_int 0)))
4275    (clobber (match_scratch:DI 3 "=r"))]
4276   "TARGET_POWERPC64"
4277   "sld%I2. %3,%1,%2"
4278   [(set_attr "type" "delayed_compare")])
4279   
4280 (define_insn ""
4281   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4282         (compare:CC (ashift:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4283                                (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4284                     (const_int 0)))
4285    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4286         (ashift:DI (match_dup 1) (match_dup 2)))]
4287   "TARGET_POWERPC64"
4288   "sld%I2. %0,%1,%2"
4289   [(set_attr "type" "delayed_compare")])
4290
4291 (define_expand "lshrdi3"
4292   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4293         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
4294                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4295   "TARGET_POWERPC64 || TARGET_POWER"
4296   "
4297 {
4298   if (TARGET_POWERPC64)
4299     ;
4300   else if (TARGET_POWER)
4301     {
4302       emit_insn (gen_lshrdi3_power (operands[0], operands[1], operands[2]));
4303       DONE;
4304     }
4305   else
4306     FAIL;
4307 }")
4308
4309 (define_insn ""
4310   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4311         (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4312                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4313   "TARGET_POWERPC64"
4314   "srd%I2 %0,%1,%2")
4315
4316 (define_insn ""
4317   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4318         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4319                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4320                     (const_int 0)))
4321    (clobber (match_scratch:DI 3 "=r"))]
4322   "TARGET_POWERPC64"
4323   "srd%I2. %3,%1,%2"
4324   [(set_attr "type" "delayed_compare")])
4325
4326 (define_insn ""
4327   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4328         (compare:CC (lshiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4329                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4330                     (const_int 0)))
4331    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4332         (lshiftrt:DI (match_dup 1) (match_dup 2)))]
4333   "TARGET_POWERPC64"
4334   "srd%I2. %0,%1,%2"
4335   [(set_attr "type" "delayed_compare")])
4336
4337 (define_expand "ashrdi3"
4338   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4339         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "")
4340                      (match_operand:SI 2 "reg_or_cint_operand" "")))]
4341   "TARGET_POWERPC64 || TARGET_POWER"
4342   "
4343 {
4344   if (TARGET_POWERPC64)
4345     ;
4346   else if (TARGET_POWER && GET_CODE (operands[2]) == CONST_INT)
4347     {
4348       emit_insn (gen_ashrdi3_power (operands[0], operands[1], operands[2]));
4349       DONE;
4350     }
4351   else
4352     FAIL;
4353 }")
4354
4355 (define_insn ""
4356   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4357         (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4358                      (match_operand:SI 2 "reg_or_cint_operand" "ri")))]
4359   "TARGET_POWERPC64"
4360   "srad%I2 %0,%1,%2")
4361
4362 (define_insn ""
4363   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4364         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4365                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4366                     (const_int 0)))
4367    (clobber (match_scratch:DI 3 "=r"))]
4368   "TARGET_POWERPC64"
4369   "srad%I2. %3,%1,%2"
4370   [(set_attr "type" "delayed_compare")])
4371
4372 (define_insn ""
4373   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4374         (compare:CC (ashiftrt:DI (match_operand:DI 1 "gpc_reg_operand" "r")
4375                                  (match_operand:SI 2 "reg_or_cint_operand" "ri"))
4376                     (const_int 0)))
4377    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4378         (ashiftrt:DI (match_dup 1) (match_dup 2)))]
4379   "TARGET_POWERPC64"
4380   "srad%I2. %0,%1,%2"
4381   [(set_attr "type" "delayed_compare")])
4382
4383 (define_insn "anddi3"
4384   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4385         (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4386                 (match_operand:DI 2 "and_operand" "?r,K,J")))
4387    (clobber (match_scratch:CC 3 "=X,x,x"))]
4388   "TARGET_POWERPC64"
4389   "@
4390    and %0,%1,%2
4391    andi. %0,%1,%b2
4392    andis. %0,%1,%u2")
4393
4394 (define_insn ""
4395   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x")
4396         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4397                             (match_operand:DI 2 "and_operand" "r,K,J"))
4398                     (const_int 0)))
4399    (clobber (match_scratch:DI 3 "=r,r,r"))]
4400   "TARGET_POWERPC64"
4401   "@
4402    and. %3,%1,%2
4403    andi. %3,%1,%b2
4404    andis. %3,%1,%u2"
4405   [(set_attr "type" "compare,compare,compare")])
4406
4407 (define_insn ""
4408   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x,x")
4409         (compare:CC (and:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4410                             (match_operand:DI 2 "and_operand" "r,K,J"))
4411                     (const_int 0)))
4412    (set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4413         (and:DI (match_dup 1) (match_dup 2)))]
4414   "TARGET_POWERPC64"
4415   "@
4416    and. %0,%1,%2
4417    andi. %0,%1,%b2
4418    andis. %0,%1,%u2"
4419   [(set_attr "type" "compare,compare,compare")])
4420
4421 ;; Take a AND with a constant that cannot be done in a single insn and try to
4422 ;; split it into two insns.  This does not verify that the insns are valid
4423 ;; since this need not be done as combine will do it.
4424
4425 (define_split
4426   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4427         (and:DI (match_operand:DI 1 "gpc_reg_operand" "")
4428                 (match_operand:DI 2 "non_and_cint_operand" "")))]
4429   "TARGET_POWERPC64"
4430   [(set (match_dup 0) (and:DI (match_dup 1) (match_dup 3)))
4431    (set (match_dup 0) (and:DI (match_dup 0) (match_dup 4)))]
4432   "
4433 {
4434   int maskval = INTVAL (operands[2]);
4435   int i, transitions, last_bit_value;
4436   int orig = maskval, first_c = maskval, second_c;
4437
4438   /* We know that MASKVAL must have more than 2 bit-transitions.  Start at
4439      the low-order bit and count for the third transition.  When we get there,
4440      make a first mask that has everything to the left of that position
4441      a one.  Then make the second mask to turn off whatever else is needed.  */
4442
4443   for (i = 1, transitions = 0, last_bit_value = maskval & 1; i < 32; i++)
4444     {
4445       if (((maskval >>= 1) & 1) != last_bit_value)
4446         last_bit_value ^= 1, transitions++;
4447
4448       if (transitions > 2)
4449         {
4450           first_c |= (~0) << i;
4451           break;
4452         }
4453     }
4454
4455   second_c = orig | ~ first_c;
4456
4457   operands[3] = gen_rtx (CONST_INT, VOIDmode, first_c);
4458   operands[4] = gen_rtx (CONST_INT, VOIDmode, second_c);
4459 }")
4460
4461 (define_insn "iordi3"
4462   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4463         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4464                 (match_operand:DI 2 "logical_operand" "r,K,J")))]
4465   "TARGET_POWERPC64"
4466   "@
4467    or %0,%1,%2
4468    ori %0,%1,%b2
4469    oris %0,%1,%u2")
4470
4471 (define_insn ""
4472   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4473         (compare:CC (ior:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4474                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4475                     (const_int 0)))
4476    (clobber (match_scratch:DI 3 "=r"))]
4477   "TARGET_POWERPC64"
4478   "or. %3,%1,%2"
4479   [(set_attr "type" "compare")])
4480
4481 (define_insn ""
4482   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4483         (compare:CC (ior:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4484                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4485                     (const_int 0)))
4486    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4487         (ior:DI (match_dup 1) (match_dup 2)))]
4488   "TARGET_POWERPC64"
4489   "or. %0,%1,%2"
4490   [(set_attr "type" "compare")])
4491
4492 ;; Split an IOR that we can't do in one insn into two insns, each of which
4493 ;; does one 16-bit part.  This is used by combine.
4494
4495 (define_split
4496   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4497         (ior:DI (match_operand:DI 1 "gpc_reg_operand" "")
4498                 (match_operand:DI 2 "non_logical_cint_operand" "")))]
4499   "TARGET_POWERPC64"
4500   [(set (match_dup 0) (ior:DI (match_dup 1) (match_dup 3)))
4501    (set (match_dup 0) (ior:DI (match_dup 0) (match_dup 4)))]
4502 "
4503 {
4504   operands[3] = gen_rtx (CONST_INT, VOIDmode,
4505                          INTVAL (operands[2]) & (~ (HOST_WIDE_INT) 0xffff));
4506   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
4507 }")
4508
4509 (define_insn "xordi3"
4510   [(set (match_operand:DI 0 "gpc_reg_operand" "=r,r,r")
4511         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r,r,r")
4512                 (match_operand:DI 2 "logical_operand" "r,K,J")))]
4513   "TARGET_POWERPC64"
4514   "@
4515    xor %0,%1,%2
4516    xori %0,%1,%b2
4517    xoris %0,%1,%u2")
4518
4519 (define_insn ""
4520   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4521         (compare:CC (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4522                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4523                     (const_int 0)))
4524    (clobber (match_scratch:DI 3 "=r"))]
4525   "TARGET_POWERPC64"
4526   "xor. %3,%1,%2"
4527   [(set_attr "type" "compare")])
4528
4529 (define_insn ""
4530   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4531         (compare:CC (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4532                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4533                     (const_int 0)))
4534    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4535         (xor:DI (match_dup 1) (match_dup 2)))]
4536   "TARGET_POWERPC64"
4537   "xor. %0,%1,%2"
4538   [(set_attr "type" "compare")])
4539
4540 ;; Split an XOR that we can't do in one insn into two insns, each of which
4541 ;; does one 16-bit part.  This is used by combine.
4542
4543 (define_split
4544   [(set (match_operand:DI 0 "gpc_reg_operand" "")
4545         (xor:DI (match_operand:DI 1 "gpc_reg_operand" "")
4546                 (match_operand:DI 2 "non_logical_cint_operand" "")))]
4547   "TARGET_POWERPC64"
4548   [(set (match_dup 0) (xor:DI (match_dup 1) (match_dup 3)))
4549    (set (match_dup 0) (xor:DI (match_dup 0) (match_dup 4)))]
4550 "
4551 {
4552   operands[3] = gen_rtx (CONST_INT, VOIDmode,
4553                          INTVAL (operands[2]) & 0xffff0000);
4554   operands[4] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[2]) & 0xffff);
4555 }")
4556
4557 (define_insn ""
4558   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4559         (not:DI (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4560                         (match_operand:DI 2 "gpc_reg_operand" "r"))))]
4561    "TARGET_POWERPC64"
4562    "eqv %0,%1,%2")
4563
4564 (define_insn ""
4565   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4566         (compare:CC (not:DI (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4567                                     (match_operand:DI 2 "gpc_reg_operand" "r")))
4568                     (const_int 0)))
4569    (clobber (match_scratch:DI 3 "=r"))]
4570    "TARGET_POWERPC64"
4571    "eqv. %3,%1,%2"
4572    [(set_attr "type" "compare")])
4573
4574 (define_insn ""
4575   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4576         (compare:CC (not:DI (xor:DI (match_operand:DI 1 "gpc_reg_operand" "%r")
4577                                     (match_operand:DI 2 "gpc_reg_operand" "r")))
4578                     (const_int 0)))
4579    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4580         (not:DI (xor:DI (match_dup 1) (match_dup 2))))]
4581    "TARGET_POWERPC64"
4582    "eqv. %0,%1,%2"
4583    [(set_attr "type" "compare")])
4584
4585 (define_insn ""
4586   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4587         (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4588                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
4589   "TARGET_POWERPC64"
4590   "andc %0,%2,%1")
4591
4592 (define_insn ""
4593   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4594         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4595                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4596                     (const_int 0)))
4597    (clobber (match_scratch:DI 3 "=r"))]
4598   "TARGET_POWERPC64"
4599   "andc. %3,%2,%1"
4600   [(set_attr "type" "compare")])
4601
4602 (define_insn ""
4603   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4604         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4605                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4606                     (const_int 0)))
4607    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4608         (and:DI (not:DI (match_dup 1)) (match_dup 2)))]
4609   "TARGET_POWERPC64"
4610   "andc. %0,%2,%1"
4611   [(set_attr "type" "compare")])
4612
4613 (define_insn ""
4614   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4615         (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4616                 (match_operand:DI 2 "gpc_reg_operand" "r")))]
4617   "TARGET_POWERPC64"
4618   "orc %0,%2,%1")
4619
4620 (define_insn ""
4621   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4622         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4623                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4624                     (const_int 0)))
4625    (clobber (match_scratch:DI 3 "=r"))]
4626   "TARGET_POWERPC64"
4627   "orc. %3,%2,%1"
4628   [(set_attr "type" "compare")])
4629
4630 (define_insn ""
4631   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4632         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "r"))
4633                             (match_operand:DI 2 "gpc_reg_operand" "r"))
4634                     (const_int 0)))
4635    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4636         (ior:DI (not:DI (match_dup 1)) (match_dup 2)))]
4637   "TARGET_POWERPC64"
4638   "orc. %0,%2,%1"
4639   [(set_attr "type" "compare")])
4640
4641 (define_insn ""
4642   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4643         (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4644                 (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))))]
4645   "TARGET_POWERPC64"
4646   "nand %0,%1,%2")
4647
4648 (define_insn ""
4649   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4650         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4651                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4652                     (const_int 0)))
4653    (clobber (match_scratch:DI 3 "=r"))]
4654   "TARGET_POWERPC64"
4655   "nand. %3,%1,%2"
4656   [(set_attr "type" "compare")])
4657
4658 (define_insn ""
4659   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4660         (compare:CC (ior:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4661                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4662                     (const_int 0)))
4663    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4664         (ior:DI (not:DI (match_dup 1)) (not:DI (match_dup 2))))]
4665   "TARGET_POWERPC64"
4666   "nand. %0,%1,%2"
4667   [(set_attr "type" "compare")])
4668
4669 (define_insn ""
4670   [(set (match_operand:DI 0 "gpc_reg_operand" "=r")
4671         (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4672                 (not:DI (match_operand:DI 2 "gpc_reg_operand" "r"))))]
4673   "TARGET_POWERPC64"
4674   "nor %0,%1,%2")
4675
4676 (define_insn ""
4677   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
4678         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4679                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4680                     (const_int 0)))
4681    (clobber (match_scratch:DI 3 "=r"))]
4682   "TARGET_POWERPC64"
4683   "nor. %3,%1,%2"
4684   [(set_attr "type" "compare")])
4685
4686 (define_insn ""
4687   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
4688         (compare:CC (and:DI (not:DI (match_operand:DI 1 "gpc_reg_operand" "%r"))
4689                             (not:DI (match_operand:DI 2 "gpc_reg_operand" "r")))
4690                     (const_int 0)))
4691    (set (match_operand:DI 0 "gpc_reg_operand" "=r")
4692         (and:DI (not:DI (match_dup 1)) (not:DI (match_dup 2))))]
4693   "TARGET_POWERPC64"
4694   "nor. %0,%1,%2"
4695   [(set_attr "type" "compare")])
4696 \f
4697 ;; Now define ways of moving data around.
4698
4699 ;; Elf specific ways of loading addresses for non-PIC code.
4700 ;; The output of this could be r0, but we limit it to base
4701 ;; registers, since almost all uses of this will need it
4702 ;; in a base register shortly.
4703 (define_insn "elf_high"
4704   [(set (match_operand:SI 0 "register_operand" "=b")
4705         (high:SI (match_operand 1 "" "")))]
4706   "TARGET_ELF && !TARGET_64BIT"
4707   "{cau|addis} %0,0,%1@ha")
4708
4709 (define_insn "elf_low"
4710   [(set (match_operand:SI 0 "register_operand" "=r")
4711         (lo_sum:SI (match_operand:SI 1 "register_operand" "b")
4712                    (match_operand 2 "" "")))]
4713    "TARGET_ELF && !TARGET_64BIT"
4714    "{cal %0,%a2@l(%1)|addi %0,%1,%2@l}")
4715
4716 ;; For SI, we special-case integers that can't be loaded in one insn.  We
4717 ;; do the load 16-bits at a time.  We could do this by loading from memory,
4718 ;; and this is even supposed to be faster, but it is simpler not to get
4719 ;; integers in the TOC.
4720 (define_expand "movsi"
4721   [(set (match_operand:SI 0 "general_operand" "")
4722         (match_operand:SI 1 "any_operand" ""))]
4723   ""
4724   "
4725 {
4726   if (GET_CODE (operands[0]) != REG)
4727     operands[1] = force_reg (SImode, operands[1]);
4728
4729   /* Convert a move of a CONST_DOUBLE into a CONST_INT */
4730   if (GET_CODE (operands[1]) == CONST_DOUBLE)
4731     operands[1] = GEN_INT (CONST_DOUBLE_LOW (operands[1]));
4732
4733   /* Use default pattern for address of ELF small data */
4734   if (TARGET_ELF
4735       && DEFAULT_ABI == ABI_V4
4736       && (GET_CODE (operands[1]) == SYMBOL_REF || GET_CODE (operands[1]) == CONST)
4737       && small_data_operand (operands[1], SImode))
4738     {
4739       emit_insn (gen_rtx (SET, VOIDmode, operands[0], operands[1]));
4740       DONE;
4741     }
4742
4743   if (TARGET_ELF && TARGET_NO_TOC && !TARGET_64BIT
4744       && CONSTANT_P (operands[1])
4745       && GET_CODE (operands[1]) != HIGH
4746       && GET_CODE (operands[1]) != CONST_INT)
4747     {
4748       rtx target = (reload_completed || reload_in_progress)
4749                         ? operands[0] : gen_reg_rtx (SImode);
4750
4751       /* If this is a function address on -mcall-aixdesc or -mcall-nt,
4752          convert it to the address of the descriptor.  */
4753       if ((DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT)
4754           && GET_CODE (operands[1]) == SYMBOL_REF
4755           && XSTR (operands[1], 0)[0] == '.')
4756         {
4757           char *name = XSTR (operands[1], 0);
4758           rtx new_ref;
4759           while (*name == '.')
4760             name++;
4761           new_ref = gen_rtx (SYMBOL_REF, Pmode, name);
4762           CONSTANT_POOL_ADDRESS_P (new_ref) = CONSTANT_POOL_ADDRESS_P (operands[1]);
4763           SYMBOL_REF_FLAG (new_ref) = SYMBOL_REF_FLAG (operands[1]);
4764           SYMBOL_REF_USED (new_ref) = SYMBOL_REF_USED (operands[1]);
4765           operands[1] = new_ref;
4766         }
4767
4768       emit_insn (gen_elf_high (target, operands[1]));
4769       emit_insn (gen_elf_low (operands[0], target, operands[1]));
4770       DONE;
4771     }
4772
4773   if (GET_CODE (operands[1]) == CONST
4774       && DEFAULT_ABI == ABI_NT
4775       && !side_effects_p (operands[0]))
4776     {
4777       rtx const_term = const0_rtx;
4778       rtx sym = eliminate_constant_term (XEXP (operands[1], 0), &const_term);
4779       if (sym && GET_CODE (const_term) == CONST_INT
4780           && (GET_CODE (sym) == SYMBOL_REF || GET_CODE (sym) == LABEL_REF))
4781         {
4782           unsigned HOST_WIDE_INT value = INTVAL (const_term);
4783           int new_reg_p = (flag_expensive_optimizations
4784                            && !reload_completed
4785                            && !reload_in_progress);
4786           rtx tmp1 = (new_reg_p && value != 0) ? gen_reg_rtx (SImode) : operands[0];
4787
4788           emit_insn (gen_movsi (tmp1, sym));
4789           if (INTVAL (const_term) != 0)
4790             {
4791               if (value + 0x8000 < 0x10000)
4792                 emit_insn (gen_addsi3 (operands[0], tmp1, GEN_INT (value)));
4793
4794               else
4795                 {
4796                   HOST_WIDE_INT high_int = value & (~ (HOST_WIDE_INT) 0xffff);
4797                   HOST_WIDE_INT low_int = value & 0xffff;
4798                   rtx tmp2 = (!new_reg_p || !low_int) ? operands[0] : gen_reg_rtx (Pmode);
4799
4800                   if (low_int & 0x8000)
4801                     high_int += 0x10000, low_int |= ((HOST_WIDE_INT) -1) << 16;
4802
4803                   emit_insn (gen_addsi3 (tmp2, tmp1, GEN_INT (high_int)));
4804                   if (low_int)
4805                     emit_insn (gen_addsi3 (operands[0], tmp2, GEN_INT (low_int)));
4806                 }
4807             }
4808           DONE;
4809         }
4810       else
4811         fatal_insn (\"bad address\", operands[1]);
4812     }
4813
4814   if ((!TARGET_WINDOWS_NT || DEFAULT_ABI != ABI_NT)
4815       && CONSTANT_P (operands[1])
4816       && GET_CODE (operands[1]) != CONST_INT
4817       && GET_CODE (operands[1]) != HIGH
4818       && ! LEGITIMATE_CONSTANT_POOL_ADDRESS_P (operands[1]))
4819     {
4820       /* If we are to limit the number of things we put in the TOC and
4821          this is a symbol plus a constant we can add in one insn,
4822          just put the symbol in the TOC and add the constant.  Don't do
4823          this if reload is in progress.  */
4824       if (GET_CODE (operands[1]) == CONST
4825           && TARGET_NO_SUM_IN_TOC && ! reload_in_progress
4826           && GET_CODE (XEXP (operands[1], 0)) == PLUS
4827           && add_operand (XEXP (XEXP (operands[1], 0), 1), SImode)
4828           && (GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == LABEL_REF
4829               || GET_CODE (XEXP (XEXP (operands[1], 0), 0)) == SYMBOL_REF)
4830           && ! side_effects_p (operands[0]))
4831         {
4832           rtx sym = force_const_mem (SImode, XEXP (XEXP (operands[1], 0), 0));
4833           rtx other = XEXP (XEXP (operands[1], 0), 1);
4834
4835           emit_insn (gen_addsi3 (operands[0], force_reg (SImode, sym), other));
4836           DONE;
4837         }
4838
4839       operands[1] = force_const_mem (SImode, operands[1]);
4840       if (! memory_address_p (SImode, XEXP (operands[1], 0))
4841           && ! reload_in_progress)
4842         operands[1] = change_address (operands[1], SImode,
4843                                       XEXP (operands[1], 0));
4844     }
4845 }")
4846
4847 (define_insn ""
4848   [(set (match_operand:SI 0 "nonimmediate_operand" "=r,r,r,r,r,m,r,r,r,r,r,*q,*c*l,*h")
4849         (match_operand:SI 1 "input_operand" "r,S,T,U,m,r,I,J,n,R,*h,r,r,0"))]
4850   "gpc_reg_operand (operands[0], SImode)
4851    || gpc_reg_operand (operands[1], SImode)"
4852   "@
4853    mr %0,%1
4854    {l|lwz} %0,[toc]%1(2)
4855    {l|lwz} %0,[toc]%l1(2)
4856    {cal|la} %0,%a1
4857    {l%U1%X1|lwz%U1%X1} %0,%1
4858    {st%U0%X0|stw%U0%X0} %1,%0
4859    {lil|li} %0,%1
4860    {liu|lis} %0,%u1
4861    #
4862    {cal|la} %0,%1(%*)
4863    mf%1 %0
4864    mt%0 %1
4865    mt%0 %1
4866    cror 0,0,0"
4867   [(set_attr "type" "*,load,load,*,load,*,*,*,*,*,*,*,mtjmpr,*")
4868    (set_attr "length" "4,4,4,4,4,4,4,4,8,4,4,4,4,4")])
4869
4870 ;; Split a load of a large constant into the appropriate two-insn
4871 ;; sequence.
4872
4873 (define_split
4874   [(set (match_operand:SI 0 "gpc_reg_operand" "")
4875         (match_operand:SI 1 "const_int_operand" ""))]
4876   "(unsigned) (INTVAL (operands[1]) + 0x8000) >= 0x10000
4877    && (INTVAL (operands[1]) & 0xffff) != 0"
4878   [(set (match_dup 0)
4879         (match_dup 2))
4880    (set (match_dup 0)
4881         (ior:SI (match_dup 0)
4882                 (match_dup 3)))]
4883   "
4884 {
4885   operands[2] = gen_rtx (CONST_INT, VOIDmode,
4886                          INTVAL (operands[1]) & 0xffff0000);
4887   operands[3] = gen_rtx (CONST_INT, VOIDmode, INTVAL (operands[1]) & 0xffff);
4888 }")
4889
4890 (define_insn ""
4891   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
4892         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
4893                     (const_int 0)))
4894    (set (match_operand:SI 0 "gpc_reg_operand" "=r") (match_dup 1))]
4895   ""
4896   "mr. %0,%1"
4897   [(set_attr "type" "compare")])
4898 \f
4899 (define_expand "movhi"
4900   [(set (match_operand:HI 0 "general_operand" "")
4901         (match_operand:HI 1 "any_operand" ""))]
4902   ""
4903   "
4904 {
4905   if (GET_CODE (operands[0]) != REG)
4906     operands[1] = force_reg (HImode, operands[1]);
4907
4908   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
4909     {
4910       operands[1] = force_const_mem (HImode, operands[1]);
4911       if (! memory_address_p (HImode, XEXP (operands[1], 0))
4912           && ! reload_in_progress)
4913         operands[1] = change_address (operands[1], HImode,
4914                                       XEXP (operands[1], 0));
4915     }
4916 }")
4917
4918 (define_insn ""
4919   [(set (match_operand:HI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
4920         (match_operand:HI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
4921   "gpc_reg_operand (operands[0], HImode)
4922    || gpc_reg_operand (operands[1], HImode)"
4923   "@
4924    mr %0,%1
4925    lhz%U1%X1 %0,%1
4926    sth%U0%X0 %1,%0
4927    {lil|li} %0,%w1
4928    mf%1 %0
4929    mt%0 %1
4930    mt%0 %1
4931    cror 0,0,0"
4932   [(set_attr "type" "*,load,*,*,*,*,mtjmpr,*")])
4933
4934 (define_expand "movqi"
4935   [(set (match_operand:QI 0 "general_operand" "")
4936         (match_operand:QI 1 "any_operand" ""))]
4937   ""
4938   "
4939 {
4940   if (GET_CODE (operands[0]) != REG)
4941     operands[1] = force_reg (QImode, operands[1]);
4942
4943   if (CONSTANT_P (operands[1]) && GET_CODE (operands[1]) != CONST_INT)
4944     {
4945       operands[1] = force_const_mem (QImode, operands[1]);
4946       if (! memory_address_p (QImode, XEXP (operands[1], 0))
4947           && ! reload_in_progress)
4948         operands[1] = change_address (operands[1], QImode,
4949                                       XEXP (operands[1], 0));
4950     }
4951 }")
4952
4953 (define_insn ""
4954   [(set (match_operand:QI 0 "nonimmediate_operand" "=r,r,m,r,r,*q,*c*l,*h")
4955         (match_operand:QI 1 "input_operand" "r,m,r,i,*h,r,r,0"))]
4956   "gpc_reg_operand (operands[0], QImode)
4957    || gpc_reg_operand (operands[1], QImode)"
4958   "@
4959    mr %0,%1
4960    lbz%U1%X1 %0,%1
4961    stb%U0%X0 %1,%0
4962    {lil|li} %0,%1
4963    mf%1 %0
4964    mt%0 %1
4965    mt%0 %1
4966    cror 0,0,0"
4967   [(set_attr "type" "*,load,*,*,*,*,mtjmpr,*")])
4968 \f
4969 ;; Here is how to move condition codes around.  When we store CC data in
4970 ;; an integer register or memory, we store just the high-order 4 bits.
4971 ;; This lets us not shift in the most common case of CR0.
4972 (define_expand "movcc"
4973   [(set (match_operand:CC 0 "nonimmediate_operand" "")
4974         (match_operand:CC 1 "nonimmediate_operand" ""))]
4975   ""
4976   "")
4977
4978 (define_insn ""
4979   [(set (match_operand:CC 0 "nonimmediate_operand" "=y,x,y,r,r,r,r,m")
4980         (match_operand:CC 1 "nonimmediate_operand" "y,r,r,x,y,r,m,r"))]
4981   "register_operand (operands[0], CCmode)
4982    || register_operand (operands[1], CCmode)"
4983   "@
4984    mcrf %0,%1
4985    mtcrf 128,%1
4986    {rlinm|rlwinm} %1,%1,%F0,0xffffffff\;mtcrf %R0,%1\;{rlinm|rlwinm} %1,%1,%f0,0xffffffff
4987    mfcr %0
4988    mfcr %0\;{rlinm|rlwinm} %0,%0,%f1,0xf0000000
4989    mr %0,%1
4990    {l%U1%X1|lwz%U1%X1} %0,%1
4991    {st%U0%U1|stw%U0%U1} %1,%0"
4992   [(set_attr "type" "*,*,*,compare,*,*,load,*")
4993    (set_attr "length" "*,*,12,*,8,*,*,*")])
4994 \f
4995 ;; For floating-point, we normally deal with the floating-point registers
4996 ;; unless -msoft-float is used.  The sole exception is that parameter passing
4997 ;; can produce floating-point values in fixed-point registers.  Unless the
4998 ;; value is a simple constant or already in memory, we deal with this by
4999 ;; allocating memory and copying the value explicitly via that memory location.
5000 (define_expand "movsf"
5001   [(set (match_operand:SF 0 "nonimmediate_operand" "")
5002         (match_operand:SF 1 "any_operand" ""))]
5003   ""
5004   "
5005 {
5006   /* If we are called from reload, we might be getting a SUBREG of a hard
5007      reg.  So expand it.  */
5008   if (GET_CODE (operands[0]) == SUBREG
5009       && GET_CODE (SUBREG_REG (operands[0])) == REG
5010       && REGNO (SUBREG_REG (operands[0])) < FIRST_PSEUDO_REGISTER)
5011     operands[0] = alter_subreg (operands[0]);
5012   if (GET_CODE (operands[1]) == SUBREG
5013       && GET_CODE (SUBREG_REG (operands[1])) == REG
5014       && REGNO (SUBREG_REG (operands[1])) < FIRST_PSEUDO_REGISTER)
5015     operands[1] = alter_subreg (operands[1]);
5016
5017   if (TARGET_SOFT_FLOAT && GET_CODE (operands[0]) == MEM)
5018     operands[1] = force_reg (SFmode, operands[1]);
5019
5020   else if (TARGET_HARD_FLOAT)
5021     {
5022       if (GET_CODE (operands[1]) == REG && REGNO (operands[1]) < 32)
5023         {
5024           /* If this is a store to memory or another integer register do the
5025              move directly.  Otherwise store to a temporary stack slot and
5026              load from there into a floating point register.  */
5027
5028           if (GET_CODE (operands[0]) == MEM
5029               || (GET_CODE (operands[0]) == REG
5030                   && (REGNO (operands[0]) < 32
5031                       || (reload_in_progress
5032                           && REGNO (operands[0]) >= FIRST_PSEUDO_REGISTER))))
5033             {
5034               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
5035                               operand_subword (operands[1], 0, 0, SFmode));
5036               DONE;
5037             }
5038           else
5039             {
5040               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
5041
5042               emit_move_insn (stack_slot, operands[1]);
5043               emit_move_insn (operands[0], stack_slot);
5044               DONE;
5045             }
5046         }
5047
5048       if (GET_CODE (operands[0]) == MEM)
5049         {
5050           /* If operands[1] is a register, it may have double-precision data
5051              in it, so truncate it to single precision.  We need not do
5052              this for POWERPC.  */
5053           if (! TARGET_POWERPC && TARGET_HARD_FLOAT
5054               && GET_CODE (operands[1]) == REG)
5055             {
5056               rtx newreg
5057                 = reload_in_progress ? operands[1] : gen_reg_rtx (SFmode);
5058               emit_insn (gen_aux_truncdfsf2 (newreg, operands[1]));
5059               operands[1] = newreg;
5060             }
5061
5062           operands[1] = force_reg (SFmode, operands[1]);
5063         }
5064
5065       if (GET_CODE (operands[0]) == REG && REGNO (operands[0]) < 32)
5066         {
5067           if (GET_CODE (operands[1]) == MEM
5068 #if HOST_FLOAT_FORMAT == TARGET_FLOAT_FORMAT && ! defined(REAL_IS_NOT_DOUBLE)
5069               || GET_CODE (operands[1]) == CONST_DOUBLE
5070 #endif
5071               || (GET_CODE (operands[1]) == REG
5072                   && (REGNO (operands[1]) < 32
5073                       || (reload_in_progress
5074                           && REGNO (operands[1]) >= FIRST_PSEUDO_REGISTER))))
5075             {
5076               emit_move_insn (operand_subword (operands[0], 0, 0, SFmode),
5077                               operand_subword (operands[1], 0, 0, SFmode));
5078               DONE;
5079             }
5080           else
5081             {
5082               rtx stack_slot = assign_stack_temp (SFmode, 4, 0);
5083
5084               emit_move_insn (stack_slot, operands[1]);
5085               emit_move_insn (operands[0], stack_slot);
5086               DONE;
5087             }
5088         }
5089     }
5090
5091   if (CONSTANT_P (operands[1]))
5092     {
5093       operands[1] = force_const_mem (SFmode, operands[1]);
5094       if (! memory_address_p (SFmode, XEXP (operands[1], 0))
5095           && ! reload_in_progress)
5096         operands[1] = change_address (operands[1], SFmode,
5097                                       XEXP (operands[1], 0));
5098     }
5099 }")
5100
5101 (define_split
5102   [(set (match_operand:SF 0 "gpc_reg_operand" "")
5103         (match_operand:SF 1 "easy_fp_constant" ""))]
5104   "reload_completed && REGNO (operands[0]) <= 31"
5105   [(set (match_dup 2) (match_dup 3))]
5106   "
5107 { operands[2] = operand_subword (operands[0], 0, 0, SFmode);
5108   operands[3] = operand_subword (operands[1], 0, 0, SFmode); }")
5109
5110 (define_insn ""
5111   [(set (match_operand:SF 0 "fp_reg_or_mem_operand" "=f,f,m")
5112         (match_operand:SF 1 "input_operand" "f,m,f"))]
5113   "(gpc_reg_operand (operands[0], SFmode)
5114    || gpc_reg_operand (operands[1], SFmode)) && TARGET_HARD_FLOAT"
5115   "@
5116    fmr %0,%1
5117    lfs%U1%X1 %0,%1
5118    stfs%U0%X0 %1,%0"
5119   [(set_attr "type" "fp,fpload,*")])
5120
5121 (define_insn ""
5122   [(set (match_operand:SF 0 "nonimmediate_operand" "=r,r,m,r,r,r")
5123         (match_operand:SF 1 "input_operand" "r,m,r,I,J,R"))]
5124   "(gpc_reg_operand (operands[0], SFmode)
5125    || gpc_reg_operand (operands[1], SFmode)) && TARGET_SOFT_FLOAT"
5126   "@
5127    mr %0,%1
5128    {l%U1%X1|lwz%U1%X1} %0,%1
5129    {st%U0%X0|stw%U0%X0} %1,%0
5130    {lil|li} %0,%1
5131    {liu|lis} %0,%u1
5132    {cal|la} %0,%1(%*)"
5133   [(set_attr "type" "*,load,*,*,*,*")])
5134
5135 \f
5136 (define_expand "movdf"
5137   [(set (match_operand:DF 0 "nonimmediate_operand" "")
5138         (match_operand:DF 1 "any_operand" ""))]
5139   ""
5140   "
5141 {
5142   if (GET_CODE (operands[0]) != REG)
5143     operands[1] = force_reg (DFmode, operands[1]);
5144
5145       /* Stores between FPR and any non-FPR registers must go through a
5146          temporary stack slot.  */
5147
5148   if (TARGET_POWERPC64
5149       && GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
5150       && ((FP_REGNO_P (REGNO (operands[0]))
5151            && ! FP_REGNO_P (REGNO (operands[1])))
5152           || (FP_REGNO_P (REGNO (operands[1]))
5153               && ! FP_REGNO_P (REGNO (operands[0])))))
5154     {
5155       rtx stack_slot = assign_stack_temp (DFmode, 8, 0);
5156
5157       emit_move_insn (stack_slot, operands[1]);
5158       emit_move_insn (operands[0], stack_slot);
5159       DONE;
5160     }
5161
5162   if (CONSTANT_P (operands[1]) && ! easy_fp_constant (operands[1], DFmode))
5163     {
5164       operands[1] = force_const_mem (DFmode, operands[1]);
5165       if (! memory_address_p (DFmode, XEXP (operands[1], 0))
5166           && ! reload_in_progress)
5167         operands[1] = change_address (operands[1], DFmode,
5168                                       XEXP (operands[1], 0));
5169     }
5170 }")
5171
5172 (define_split
5173   [(set (match_operand:DF 0 "gpc_reg_operand" "")
5174         (match_operand:DF 1 "easy_fp_constant" ""))]
5175   "reload_completed && REGNO (operands[0]) <= 31"
5176   [(set (match_dup 2) (match_dup 3))
5177    (set (match_dup 4) (match_dup 5))]
5178   "
5179 { operands[2] = operand_subword (operands[0], 0, 0, DFmode);
5180   operands[3] = operand_subword (operands[1], 0, 0, DFmode);
5181   operands[4] = operand_subword (operands[0], 1, 0, DFmode);
5182   operands[5] = operand_subword (operands[1], 1, 0, DFmode); }")
5183
5184 ;; Don't have reload use general registers to load a constant.  First,
5185 ;; it might not work if the output operand has is the equivalent of
5186 ;; a non-offsettable memref, but also it is less efficient than loading
5187 ;; the constant into an FP register, since it will probably be used there.
5188 ;; The "??" is a kludge until we can figure out a more reasonable way
5189 ;; of handling these non-offsettable values.
5190 (define_insn ""
5191   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,f,f,m")
5192         (match_operand:DF 1 "input_operand" "r,o,r,G,f,m,f"))]
5193   "! TARGET_POWERPC64 && TARGET_HARD_FLOAT
5194    && (register_operand (operands[0], DFmode)
5195        || register_operand (operands[1], DFmode))"
5196   "*
5197 {
5198   switch (which_alternative)
5199     {
5200     case 0:
5201       /* We normally copy the low-numbered register first.  However, if
5202          the first register operand 0 is the same as the second register of
5203          operand 1, we must copy in the opposite order.  */
5204       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5205         return \"mr %L0,%L1\;mr %0,%1\";
5206       else
5207         return \"mr %0,%1\;mr %L0,%L1\";
5208     case 1:
5209       /* If the low-address word is used in the address, we must load it
5210          last.  Otherwise, load it first.  Note that we cannot have
5211          auto-increment in that case since the address register is known to be
5212          dead.  */
5213       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5214                              operands [1], 0))
5215         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
5216       else
5217         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
5218     case 2:
5219       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
5220     case 3:
5221       return \"#\";
5222     case 4:
5223       return \"fmr %0,%1\";
5224     case 5:
5225       return \"lfd%U1%X1 %0,%1\";
5226     case 6:
5227       return \"stfd%U0%X0 %1,%0\";
5228     }
5229 }"
5230   [(set_attr "type" "*,load,*,*,fp,fpload,*")
5231    (set_attr "length" "8,8,8,8,*,*,*")])
5232
5233 (define_insn ""
5234   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r")
5235         (match_operand:DF 1 "input_operand" "r,o,r,G"))]
5236   "! TARGET_POWERPC64 && TARGET_SOFT_FLOAT
5237    && (register_operand (operands[0], DFmode)
5238        || register_operand (operands[1], DFmode))"
5239   "*
5240 {
5241   switch (which_alternative)
5242     {
5243     case 0:
5244       /* We normally copy the low-numbered register first.  However, if
5245          the first register operand 0 is the same as the second register of
5246          operand 1, we must copy in the opposite order.  */
5247       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5248         return \"mr %L0,%L1\;mr %0,%1\";
5249       else
5250         return \"mr %0,%1\;mr %L0,%L1\";
5251     case 1:
5252       /* If the low-address word is used in the address, we must load it
5253          last.  Otherwise, load it first.  Note that we cannot have
5254          auto-increment in that case since the address register is known to be
5255          dead.  */
5256       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5257                              operands [1], 0))
5258         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
5259       else
5260         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
5261     case 2:
5262       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
5263     case 3:
5264       return \"#\";
5265     }
5266 }"
5267   [(set_attr "type" "*,load,*,*")
5268    (set_attr "length" "8,8,8,8")])
5269
5270 (define_insn ""
5271   [(set (match_operand:DF 0 "nonimmediate_operand" "=!r,??r,o,!r,f,f,m")
5272         (match_operand:DF 1 "input_operand" "r,o,r,G,f,m,f"))]
5273   "TARGET_POWERPC64 && TARGET_HARD_FLOAT
5274    && (register_operand (operands[0], DFmode)
5275        || register_operand (operands[1], DFmode))"
5276   "@
5277    mr %0,%1
5278    ld%U1%X1 %0,%1
5279    std%U0%X0 %1,%0
5280    #
5281    fmr %0,%1
5282    lfd%U1%X1 %0,%1
5283    stfd%U0%X0 %1,%0"
5284   [(set_attr "type" "*,load,*,*,fp,fpload,*")])
5285
5286 (define_insn ""
5287   [(set (match_operand:DF 0 "nonimmediate_operand" "=r,r,o,r")
5288         (match_operand:DF 1 "input_operand" "r,o,r,G"))]
5289   "TARGET_POWERPC64 && TARGET_SOFT_FLOAT
5290    && (register_operand (operands[0], DFmode)
5291        || register_operand (operands[1], DFmode))"
5292   "@
5293    mr %0,%1
5294    ld%U1%X1 %0,%1
5295    std%U0%X0 %1,%0
5296    #"
5297   [(set_attr "type" "*,load,*,*")])
5298 \f
5299 ;; Next come the multi-word integer load and store and the load and store
5300 ;; multiple insns.
5301 (define_expand "movdi"
5302   [(set (match_operand:DI 0 "general_operand" "")
5303         (match_operand:DI 1 "any_operand" ""))]
5304   ""
5305   "
5306 {
5307   if (! TARGET_64BIT && ! general_operand (operands[1], DImode))
5308     FAIL;
5309
5310   if (GET_CODE (operands[0]) != REG)
5311     operands[1] = force_reg (DImode, operands[1]);
5312
5313   if (GET_CODE (operands[1]) == CONST_DOUBLE
5314       || GET_CODE (operands[1]) == CONST_INT)
5315     {
5316       HOST_WIDE_INT low;
5317       HOST_WIDE_INT high;
5318
5319       if (GET_CODE (operands[1]) == CONST_DOUBLE)
5320         {
5321           low = CONST_DOUBLE_LOW (operands[1]);
5322           high = CONST_DOUBLE_HIGH (operands[1]);
5323         }
5324       else
5325 #if HOST_BITS_PER_WIDE_INT == 32
5326         {
5327           low = INTVAL (operands[1]);
5328           high = (low < 0) ? ~0 : 0;
5329         }
5330 #else
5331         {
5332           low = INTVAL (operands[1]) & 0xffffffff;
5333           high = (HOST_WIDE_INT) INTVAL (operands[1]) >> 32;
5334         }
5335 #endif
5336
5337       if (! TARGET_POWERPC64)
5338         {
5339           emit_move_insn (gen_rtx (SUBREG, SImode, operands[0],
5340                           WORDS_BIG_ENDIAN), GEN_INT (low));
5341
5342           emit_move_insn (gen_rtx (SUBREG, SImode, operands[0],
5343                           ! WORDS_BIG_ENDIAN), GEN_INT (high));
5344           DONE;
5345         }
5346       else
5347         {
5348           if (high + 0x8000 >= 0x10000)
5349             {
5350               emit_move_insn (gen_rtx (SUBREG, SImode, operands[0], 1),
5351                               GEN_INT (high));
5352               emit_insn (gen_ashldi3 (operands[0], operands[0], GEN_INT(32)));
5353               if (low)
5354                 {
5355                   HOST_WIDE_INT low_low = low & 0xffff;
5356                   HOST_WIDE_INT low_high = low & (~ (HOST_WIDE_INT) 0xffff);
5357                   if (low_high)
5358                     emit_insn (gen_iordi3 (operands[0], operands[0],
5359                                            GEN_INT (low_high)));
5360                   if (low_low)
5361                     emit_insn (gen_iordi3 (operands[0], operands[0],
5362                                            GEN_INT (low_low)));
5363                 }
5364             }
5365           else if (low)
5366             emit_move_insn (gen_rtx (SUBREG, SImode, operands[0], 1),
5367                             GEN_INT (low));
5368           DONE;
5369         }
5370     }
5371
5372       /* Stores between FPR and any non-FPR registers must go through a
5373          temporary stack slot.  */
5374
5375   if (GET_CODE (operands[0]) == REG && GET_CODE (operands[1]) == REG
5376       && ((FP_REGNO_P (REGNO (operands[0]))
5377            && ! FP_REGNO_P (REGNO (operands[1])))
5378           || (FP_REGNO_P (REGNO (operands[1]))
5379               && ! FP_REGNO_P (REGNO (operands[0])))))
5380     {
5381       rtx stack_slot = assign_stack_temp (DImode, 8, 0);
5382
5383       emit_move_insn (stack_slot, operands[1]);
5384       emit_move_insn (operands[0], stack_slot);
5385       DONE;
5386     }
5387 }")
5388
5389 (define_insn ""
5390   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,f,f,m")
5391         (match_operand:DI 1 "input_operand" "r,m,r,f,m,f"))]
5392   "! TARGET_POWERPC64 && (gpc_reg_operand (operands[0], DImode)
5393    || gpc_reg_operand (operands[1], DImode))"
5394   "*
5395 {
5396   switch (which_alternative)
5397     {
5398     case 0:
5399       /* We normally copy the low-numbered register first.  However, if
5400          the first register operand 0 is the same as the second register of
5401          operand 1, we must copy in the opposite order.  */
5402       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5403         return \"mr %L0,%L1\;mr %0,%1\";
5404       else
5405         return \"mr %0,%1\;mr %L0,%L1\";
5406     case 1:
5407       /* If the low-address word is used in the address, we must load it
5408          last.  Otherwise, load it first.  Note that we cannot have
5409          auto-increment in that case since the address register is known to be
5410          dead.  */
5411       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5412                              operands [1], 0))
5413         return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
5414       else
5415         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
5416     case 2:
5417       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
5418     case 3:
5419       return \"fmr %0,%1\";
5420     case 4:
5421       return \"lfd%U1%X1 %0,%1\";
5422     case 5:
5423       return \"stfd%U0%X0 %1,%0\";
5424     }
5425 }"
5426   [(set_attr "type" "*,load,*,fp,fpload,*")
5427    (set_attr "length" "8,8,8,*,*,*")])
5428
5429 (define_insn ""
5430   [(set (match_operand:DI 0 "nonimmediate_operand" "=r,r,m,r,r,r,r,f,f,m,r,*h,*h")
5431         (match_operand:DI 1 "input_operand" "r,m,r,I,J,n,R,f,m,f,*h,r,0"))]
5432   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], DImode)
5433    || gpc_reg_operand (operands[1], DImode))"
5434   "@
5435    mr %0,%1
5436    ld%U1%X1 %0,%1
5437    std%U0%X0 %1,%0
5438    li %0,%1
5439    lis %0,%u1
5440    #
5441    {cal|la} %0,%1(%*)
5442    fmr %0,%1
5443    lfd%U1%X1 %0,%1
5444    stfd%U0%X0 %1,%0
5445    mf%1 %0
5446    mt%0 %1
5447    cror 0,0,0"
5448   [(set_attr "type" "*,load,*,*,*,*,*,fp,fpload,*,*,mtjmpr,*")
5449    (set_attr "length" "4,4,4,4,4,20,4,4,4,4,4,4,4")])
5450
5451 ;; Split a load of a large constant into the appropriate five-instruction
5452 ;; sequence.  The expansion in movdi tries to perform the minimum number of
5453 ;; steps, but here we have to handle anything in a constant number of insns.
5454
5455 (define_split
5456   [(set (match_operand:DI 0 "gpc_reg_operand" "")
5457         (match_operand:DI 1 "const_double_operand" ""))]
5458   "TARGET_POWERPC64"
5459   [(set (match_dup 0)
5460         (match_dup 2))
5461    (set (match_dup 0)
5462         (ior:DI (match_dup 0)
5463                 (match_dup 3)))
5464    (set (match_dup 0)
5465         (ashift:DI (match_dup 0)
5466                    (const_int 32)))
5467    (set (match_dup 0)
5468         (ior:DI (match_dup 0)
5469                 (match_dup 4)))
5470    (set (match_dup 0)
5471         (ior:DI (match_dup 0)
5472                 (match_dup 5)))]
5473   "
5474 {
5475   HOST_WIDE_INT low;
5476   HOST_WIDE_INT high;
5477
5478   if (GET_CODE (operands[1]) == CONST_DOUBLE)
5479     {
5480       low = CONST_DOUBLE_LOW (operands[1]);
5481       high = CONST_DOUBLE_HIGH (operands[1]);
5482     }
5483   else
5484 #if HOST_BITS_PER_WIDE_INT == 32
5485     {
5486       low = INTVAL (operands[1]);
5487       high = (low < 0) ? ~0 : 0;
5488     }
5489 #else
5490     {
5491       low = INTVAL (operands[1]) & 0xffffffff;
5492       high = (HOST_WIDE_INT) INTVAL (operands[1]) >> 32;
5493     }
5494 #endif
5495
5496   if ((high + 0x8000) < 0x10000
5497       && ((low & 0xffff) == 0 || (low & (~ (HOST_WIDE_INT) 0xffff)) == 0))
5498     FAIL;
5499
5500   operands[2] = GEN_INT (high & (~ (HOST_WIDE_INT) 0xffff));
5501   operands[3] = GEN_INT (high & 0xffff);
5502   operands[4] = GEN_INT (low & (~ (HOST_WIDE_INT) 0xffff));
5503   operands[5] = GEN_INT (low & 0xffff);
5504 }")
5505
5506 (define_insn ""
5507   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
5508         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
5509                     (const_int 0)))
5510    (set (match_operand:DI 0 "gpc_reg_operand" "=r") (match_dup 1))]
5511   "TARGET_POWERPC64"
5512   "mr. %0,%1"
5513   [(set_attr "type" "compare")])
5514 \f
5515 ;; TImode is similar, except that we usually want to compute the address into
5516 ;; a register and use lsi/stsi (the exception is during reload).  MQ is also
5517 ;; clobbered in stsi for POWER, so we need a SCRATCH for it.
5518 (define_expand "movti"
5519   [(parallel [(set (match_operand:TI 0 "general_operand" "")
5520                    (match_operand:TI 1 "general_operand" ""))
5521               (clobber (scratch:SI))])]
5522   "TARGET_STRING || TARGET_POWERPC64"
5523   "
5524 {
5525   if (GET_CODE (operands[0]) == MEM)
5526     operands[1] = force_reg (TImode, operands[1]);
5527
5528   if (GET_CODE (operands[0]) == MEM
5529       && GET_CODE (XEXP (operands[0], 0)) != REG
5530       && ! reload_in_progress)
5531     operands[0] = change_address (operands[0], TImode,
5532                                   copy_addr_to_reg (XEXP (operands[0], 0)));
5533
5534   if (GET_CODE (operands[1]) == MEM
5535       && GET_CODE (XEXP (operands[1], 0)) != REG
5536       && ! reload_in_progress)
5537     operands[1] = change_address (operands[1], TImode,
5538                                   copy_addr_to_reg (XEXP (operands[1], 0)));
5539 }")
5540
5541 ;; We say that MQ is clobbered in the last alternative because the first
5542 ;; alternative would never get used otherwise since it would need a reload
5543 ;; while the 2nd alternative would not.  We put memory cases first so they
5544 ;; are preferred.  Otherwise, we'd try to reload the output instead of
5545 ;; giving the SCRATCH mq.
5546 (define_insn ""
5547   [(set (match_operand:TI 0 "reg_or_mem_operand" "=Q,m,????r,????r,????r")
5548         (match_operand:TI 1 "reg_or_mem_operand" "r,r,r,Q,m"))
5549    (clobber (match_scratch:SI 2 "=q,q#X,X,X,X"))]
5550   "TARGET_STRING && TARGET_POWER && ! TARGET_POWERPC64
5551    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
5552   "*
5553 {
5554   switch (which_alternative)
5555     {
5556     default:
5557       abort ();
5558
5559     case 0:
5560       return \"{stsi|stswi} %1,%P0,16\";
5561
5562     case 1:
5563       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
5564
5565     case 2:
5566       /* Normally copy registers with lowest numbered register copied first.
5567          But copy in the other order if the first register of the output
5568          is the second, third, or fourth register in the input.  */
5569       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
5570           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
5571         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
5572       else
5573         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
5574     case 3:
5575       /* If the address is not used in the output, we can use lsi.  Otherwise,
5576          fall through to generating four loads.  */
5577       if (! reg_overlap_mentioned_p (operands[0], operands[1]))
5578         return \"{lsi|lswi} %0,%P1,16\";
5579       /* ... fall through ... */
5580     case 4:
5581       /* If the address register is the same as the register for the lowest-
5582          addressed word, load it last.  Similarly for the next two words.
5583          Otherwise load lowest address to highest.  */
5584       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5585                              operands[1], 0))
5586         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
5587       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
5588                                   REGNO (operands[0]) + 2, operands[1], 0))
5589         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
5590       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
5591                                   REGNO (operands[0]) + 3, operands[1], 0))
5592         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
5593       else
5594         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
5595     }
5596 }"
5597   [(set_attr "type" "*,load,load,*,*")
5598    (set_attr "length" "*,16,16,*,16")])
5599
5600 (define_insn ""
5601   [(set (match_operand:TI 0 "reg_or_mem_operand" "=m,????r,????r")
5602         (match_operand:TI 1 "reg_or_mem_operand" "r,r,m"))
5603    (clobber (match_scratch:SI 2 "=X,X,X"))]
5604   "TARGET_STRING && !TARGET_POWER && ! TARGET_POWERPC64
5605    && (gpc_reg_operand (operands[0], TImode) || gpc_reg_operand (operands[1], TImode))"
5606   "*
5607 {
5608   switch (which_alternative)
5609     {
5610     default:
5611       abort ();
5612
5613     case 0:
5614       return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\;{st|stw} %Y1,%Y0\;{st|stw} %Z1,%Z0\";
5615
5616     case 1:
5617       /* Normally copy registers with lowest numbered register copied first.
5618          But copy in the other order if the first register of the output
5619          is the second, third, or fourth register in the input.  */
5620       if (REGNO (operands[0]) >= REGNO (operands[1]) + 1
5621           && REGNO (operands[0]) <= REGNO (operands[1]) + 3)
5622         return \"mr %Z0,%Z1\;mr %Y0,%Y1\;mr %L0,%L1\;mr %0,%1\";
5623       else
5624         return \"mr %0,%1\;mr %L0,%L1\;mr %Y0,%Y1\;mr %Z0,%Z1\";
5625     case 2:
5626       /* If the address register is the same as the register for the lowest-
5627          addressed word, load it last.  Similarly for the next two words.
5628          Otherwise load lowest address to highest.  */
5629       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5630                              operands[1], 0))
5631         return \"{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %0,%1\";
5632       else if (refers_to_regno_p (REGNO (operands[0]) + 1,
5633                                   REGNO (operands[0]) + 2, operands[1], 0))
5634         return \"{l|lwz} %0,%1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\;{l|lwz} %L0,%L1\";
5635       else if (refers_to_regno_p (REGNO (operands[0]) + 2,
5636                                   REGNO (operands[0]) + 3, operands[1], 0))
5637         return \"{l|lwz} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Z0,%Z1\;{l|lwz} %Y0,%Y1\";
5638       else
5639         return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\;{l|lwz} %Y0,%Y1\;{l|lwz} %Z0,%Z1\";
5640     }
5641 }"
5642   [(set_attr "type" "load,*,*")
5643    (set_attr "length" "16,16,16")])
5644
5645 (define_insn ""
5646   [(set (match_operand:TI 0 "nonimmediate_operand" "=r,r,m")
5647         (match_operand:TI 1 "input_operand" "r,m,r"))]
5648   "TARGET_POWERPC64 && (gpc_reg_operand (operands[0], TImode)
5649    || gpc_reg_operand (operands[1], TImode))"
5650   "*
5651 {
5652   switch (which_alternative)
5653     {
5654     case 0:
5655       /* We normally copy the low-numbered register first.  However, if
5656          the first register operand 0 is the same as the second register of
5657          operand 1, we must copy in the opposite order.  */
5658       if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
5659         return \"mr %L0,%L1\;mr %0,%1\";
5660       else
5661         return \"mr %0,%1\;mr %L0,%L1\";
5662     case 1:
5663       /* If the low-address word is used in the address, we must load it
5664          last.  Otherwise, load it first.  Note that we cannot have
5665          auto-increment in that case since the address register is known to be
5666          dead.  */
5667       if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
5668                              operands [1], 0))
5669         return \"ld %L0,%L1\;ld %0,%1\";
5670       else
5671         return \"ld%U1 %0,%1\;ld %L0,%L1\";
5672     case 2:
5673       return \"std%U0 %1,%0\;std %L1,%L0\";
5674     }
5675 }"
5676   [(set_attr "type" "*,load,*")
5677    (set_attr "length" "8,8,8")])
5678 \f
5679 (define_expand "load_multiple"
5680   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
5681                           (match_operand:SI 1 "" ""))
5682                      (use (match_operand:SI 2 "" ""))])]
5683   "TARGET_STRING"
5684   "
5685 {
5686   int regno;
5687   int count;
5688   rtx from;
5689   int i;
5690
5691   /* Support only loading a constant number of fixed-point registers from
5692      memory and only bother with this if more than two; the machine
5693      doesn't support more than eight.  */
5694   if (GET_CODE (operands[2]) != CONST_INT
5695       || INTVAL (operands[2]) <= 2
5696       || INTVAL (operands[2]) > 8
5697       || GET_CODE (operands[1]) != MEM
5698       || GET_CODE (operands[0]) != REG
5699       || REGNO (operands[0]) >= 32)
5700     FAIL;
5701
5702   count = INTVAL (operands[2]);
5703   regno = REGNO (operands[0]);
5704
5705   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count));
5706   from = force_reg (SImode, XEXP (operands[1], 0));
5707
5708   for (i = 0; i < count; i++)
5709     XVECEXP (operands[3], 0, i)
5710       = gen_rtx (SET, VOIDmode, gen_rtx (REG, SImode, regno + i),
5711                  gen_rtx (MEM, SImode, plus_constant (from, i * 4)));
5712 }")
5713
5714 (define_insn ""
5715   [(match_parallel 0 "load_multiple_operation"
5716                    [(set (match_operand:SI 1 "gpc_reg_operand" "=r")
5717                          (mem:SI (match_operand:SI 2 "register_operand" "b")))])]
5718   "TARGET_STRING"
5719   "*
5720 {
5721   /* We have to handle the case where the pseudo used to contain the address
5722      is assigned to one of the output registers.  */
5723   int i, j;
5724   int words = XVECLEN (operands[0], 0);
5725   rtx xop[10];
5726
5727   if (XVECLEN (operands[0], 0) == 1)
5728     return \"{l|lwz} %1,0(%2)\";
5729
5730   for (i = 0; i < words; i++)
5731     if (refers_to_regno_p (REGNO (operands[1]) + i,
5732                            REGNO (operands[1]) + i + 1, operands[2], 0))
5733       {
5734         if (i == words-1)
5735           {
5736             xop[0] = operands[1];
5737             xop[1] = operands[2];
5738             xop[2] = GEN_INT (4 * (words-1));
5739             output_asm_insn (\"{lsi|lswi} %0,%1,%2\;{l|lwz} %1,%2(%1)\", xop);
5740             return \"\";
5741           }
5742         else if (i == 0)
5743           {
5744             xop[0] = operands[1];
5745             xop[1] = gen_rtx (REG, SImode, REGNO (operands[1]) + 1);
5746             xop[2] = GEN_INT (4 * (words-1));
5747             output_asm_insn (\"{cal %0,4(%0)|addi %0,%0,4}\;{lsi|lswi} %1,%0,%2\;{l|lwz} %0,-4(%0)\", xop);
5748             return \"\";
5749           }
5750         else
5751           {
5752             for (j = 0; j < words; j++)
5753               if (j != i)
5754                 {
5755                   xop[0] = gen_rtx (REG, SImode, REGNO (operands[1]) + j);
5756                   xop[1] = operands[2];
5757                   xop[2] = GEN_INT (j * 4);
5758                   output_asm_insn (\"{l|lwz} %0,%2(%1)\", xop);
5759                 }
5760             xop[0] = operands[2];
5761             xop[1] = GEN_INT (i * 4);
5762             output_asm_insn (\"{l|lwz} %0,%1(%0)\", xop);
5763             return \"\";
5764           }
5765       }
5766
5767   return \"{lsi|lswi} %1,%2,%N0\";
5768 }"
5769   [(set_attr "type" "load")
5770    (set_attr "length" "32")])
5771 \f
5772
5773 (define_expand "store_multiple"
5774   [(match_par_dup 3 [(set (match_operand:SI 0 "" "")
5775                           (match_operand:SI 1 "" ""))
5776                      (clobber (scratch:SI))
5777                      (use (match_operand:SI 2 "" ""))])]
5778   "TARGET_STRING"
5779   "
5780 {
5781   int regno;
5782   int count;
5783   rtx to;
5784   int i;
5785
5786   /* Support only storing a constant number of fixed-point registers to
5787      memory and only bother with this if more than two; the machine
5788      doesn't support more than eight.  */
5789   if (GET_CODE (operands[2]) != CONST_INT
5790       || INTVAL (operands[2]) <= 2
5791       || INTVAL (operands[2]) > 8
5792       || GET_CODE (operands[0]) != MEM
5793       || GET_CODE (operands[1]) != REG
5794       || REGNO (operands[1]) >= 32)
5795     FAIL;
5796
5797   count = INTVAL (operands[2]);
5798   regno = REGNO (operands[1]);
5799
5800   operands[3] = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (count + 1));
5801   to = force_reg (SImode, XEXP (operands[0], 0));
5802
5803   XVECEXP (operands[3], 0, 0)
5804     = gen_rtx (SET, VOIDmode, gen_rtx (MEM, SImode, to), operands[1]);
5805   XVECEXP (operands[3], 0, 1) = gen_rtx (CLOBBER, VOIDmode,
5806                                                   gen_rtx (SCRATCH, SImode));
5807
5808   for (i = 1; i < count; i++)
5809     XVECEXP (operands[3], 0, i + 1)
5810       = gen_rtx (SET, VOIDmode,
5811                  gen_rtx (MEM, SImode, plus_constant (to, i * 4)),
5812                  gen_rtx (REG, SImode, regno + i));
5813 }")
5814
5815 (define_insn ""
5816   [(match_parallel 0 "store_multiple_operation"
5817                    [(set (match_operand:SI 1 "indirect_operand" "=Q")
5818                          (match_operand:SI 2 "gpc_reg_operand" "r"))
5819                     (clobber (match_scratch:SI 3 "=q"))])]
5820   "TARGET_STRING && TARGET_POWER"
5821   "{stsi|stswi} %2,%P1,%O0")
5822
5823 (define_insn ""
5824   [(match_parallel 0 "store_multiple_operation"
5825                    [(set (mem:SI (match_operand:SI 1 "register_operand" "b"))
5826                          (match_operand:SI 2 "gpc_reg_operand" "r"))
5827                     (clobber (match_scratch:SI 3 "X"))])]
5828   "TARGET_STRING && !TARGET_POWER"
5829   "{stsi|stswi} %2,%1,%O0")
5830
5831 \f
5832 ;; String/block move insn.
5833 ;; Argument 0 is the destination
5834 ;; Argument 1 is the source
5835 ;; Argument 2 is the length
5836 ;; Argument 3 is the alignment
5837
5838 (define_expand "movstrsi"
5839   [(parallel [(set (match_operand:BLK 0 "" "")
5840                    (match_operand:BLK 1 "" ""))
5841               (use (match_operand:SI 2 "" ""))
5842               (use (match_operand:SI 3 "" ""))])]
5843   ""
5844   "
5845 {
5846   if (expand_block_move (operands))
5847     DONE;
5848   else
5849     FAIL;
5850 }")
5851
5852 ;; Move up to 32 bytes at a time.  The fixed registers are needed because the
5853 ;; register allocator doesn't have a clue about allocating 8 word registers
5854 (define_expand "movstrsi_8reg"
5855   [(parallel [(set (match_operand 0 "" "")
5856                    (match_operand 1 "" ""))
5857               (use (match_operand 2 "" ""))
5858               (use (match_operand 3 "" ""))
5859               (clobber (reg:SI  5))
5860               (clobber (reg:SI  6))
5861               (clobber (reg:SI  7))
5862               (clobber (reg:SI  8))
5863               (clobber (reg:SI  9))
5864               (clobber (reg:SI 10))
5865               (clobber (reg:SI 11))
5866               (clobber (reg:SI 12))
5867               (clobber (match_scratch:SI 4 ""))])]
5868   "TARGET_STRING"
5869   "")
5870
5871 (define_insn ""
5872   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
5873         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
5874    (use (match_operand:SI 2 "immediate_operand" "i"))
5875    (use (match_operand:SI 3 "immediate_operand" "i"))
5876    (clobber (match_operand:SI 4 "register_operand" "=r"))
5877    (clobber (reg:SI  6))
5878    (clobber (reg:SI  7))
5879    (clobber (reg:SI  8))
5880    (clobber (reg:SI  9))
5881    (clobber (reg:SI 10))
5882    (clobber (reg:SI 11))
5883    (clobber (reg:SI 12))
5884    (clobber (match_scratch:SI 5 "=q"))]
5885   "TARGET_STRING && TARGET_POWER
5886    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32) || INTVAL (operands[2]) == 0)
5887    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
5888    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
5889    && REGNO (operands[4]) == 5"
5890   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
5891   [(set_attr "length" "8")])
5892
5893 (define_insn ""
5894   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
5895         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
5896    (use (match_operand:SI 2 "immediate_operand" "i"))
5897    (use (match_operand:SI 3 "immediate_operand" "i"))
5898    (clobber (match_operand:SI 4 "register_operand" "=r"))
5899    (clobber (reg:SI  6))
5900    (clobber (reg:SI  7))
5901    (clobber (reg:SI  8))
5902    (clobber (reg:SI  9))
5903    (clobber (reg:SI 10))
5904    (clobber (reg:SI 11))
5905    (clobber (reg:SI 12))
5906    (clobber (match_scratch:SI 5 "X"))]
5907   "TARGET_STRING && !TARGET_POWER
5908    && ((INTVAL (operands[2]) > 24 && INTVAL (operands[2]) < 32) || INTVAL (operands[2]) == 0)
5909    && (REGNO (operands[0]) < 5 || REGNO (operands[0]) > 12)
5910    && (REGNO (operands[1]) < 5 || REGNO (operands[1]) > 12)
5911    && REGNO (operands[4]) == 5"
5912   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
5913   [(set_attr "length" "8")])
5914
5915 ;; Move up to 24 bytes at a time.  The fixed registers are needed because the
5916 ;; register allocator doesn't have a clue about allocating 6 word registers
5917 (define_expand "movstrsi_6reg"
5918   [(parallel [(set (match_operand 0 "" "")
5919                    (match_operand 1 "" ""))
5920               (use (match_operand 2 "" ""))
5921               (use (match_operand 3 "" ""))
5922               (clobber (reg:SI  7))
5923               (clobber (reg:SI  8))
5924               (clobber (reg:SI  9))
5925               (clobber (reg:SI 10))
5926               (clobber (reg:SI 11))
5927               (clobber (reg:SI 12))
5928               (clobber (match_scratch:SI 4 ""))])]
5929   "TARGET_STRING"
5930   "")
5931
5932 (define_insn ""
5933   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
5934         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
5935    (use (match_operand:SI 2 "immediate_operand" "i"))
5936    (use (match_operand:SI 3 "immediate_operand" "i"))
5937    (clobber (match_operand:SI 4 "register_operand" "=r"))
5938    (clobber (reg:SI  8))
5939    (clobber (reg:SI  9))
5940    (clobber (reg:SI 10))
5941    (clobber (reg:SI 11))
5942    (clobber (reg:SI 12))
5943    (clobber (match_scratch:SI 5 "=q"))]
5944   "TARGET_STRING && TARGET_POWER
5945    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 24
5946    && (REGNO (operands[0]) < 7 || REGNO (operands[0]) > 12)
5947    && (REGNO (operands[1]) < 7 || REGNO (operands[1]) > 12)
5948    && REGNO (operands[4]) == 7"
5949   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
5950   [(set_attr "length" "8")])
5951
5952 (define_insn ""
5953   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
5954         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
5955    (use (match_operand:SI 2 "immediate_operand" "i"))
5956    (use (match_operand:SI 3 "immediate_operand" "i"))
5957    (clobber (match_operand:SI 4 "register_operand" "=r"))
5958    (clobber (reg:SI  8))
5959    (clobber (reg:SI  9))
5960    (clobber (reg:SI 10))
5961    (clobber (reg:SI 11))
5962    (clobber (reg:SI 12))
5963    (clobber (match_scratch:SI 5 "X"))]
5964   "TARGET_STRING && !TARGET_POWER
5965    && INTVAL (operands[2]) > 16 && INTVAL (operands[2]) <= 32
5966    && (REGNO (operands[0]) < 7 || REGNO (operands[0]) > 12)
5967    && (REGNO (operands[1]) < 7 || REGNO (operands[1]) > 12)
5968    && REGNO (operands[4]) == 7"
5969   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
5970   [(set_attr "length" "8")])
5971
5972 ;; Move up to 16 bytes at a time, using 4 fixed registers to avoid spill problems
5973 ;; with TImode
5974 (define_expand "movstrsi_4reg"
5975   [(parallel [(set (match_operand 0 "" "")
5976                    (match_operand 1 "" ""))
5977               (use (match_operand 2 "" ""))
5978               (use (match_operand 3 "" ""))
5979               (clobber (reg:SI  9))
5980               (clobber (reg:SI 10))
5981               (clobber (reg:SI 11))
5982               (clobber (reg:SI 12))
5983               (clobber (match_scratch:SI 4 ""))])]
5984   "TARGET_STRING"
5985   "")
5986
5987 (define_insn ""
5988   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
5989         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
5990    (use (match_operand:SI 2 "immediate_operand" "i"))
5991    (use (match_operand:SI 3 "immediate_operand" "i"))
5992    (clobber (match_operand:SI 4 "register_operand" "=r"))
5993    (clobber (reg:SI 10))
5994    (clobber (reg:SI 11))
5995    (clobber (reg:SI 12))
5996    (clobber (match_scratch:SI 5 "=q"))]
5997   "TARGET_STRING && TARGET_POWER
5998    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
5999    && (REGNO (operands[0]) < 9 || REGNO (operands[0]) > 12)
6000    && (REGNO (operands[1]) < 9 || REGNO (operands[1]) > 12)
6001    && REGNO (operands[4]) == 9"
6002   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6003   [(set_attr "length" "8")])
6004
6005 (define_insn ""
6006   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6007         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6008    (use (match_operand:SI 2 "immediate_operand" "i"))
6009    (use (match_operand:SI 3 "immediate_operand" "i"))
6010    (clobber (match_operand:SI 4 "register_operand" "=r"))
6011    (clobber (reg:SI 10))
6012    (clobber (reg:SI 11))
6013    (clobber (reg:SI 12))
6014    (clobber (match_scratch:SI 5 "X"))]
6015   "TARGET_STRING && !TARGET_POWER
6016    && INTVAL (operands[2]) > 8 && INTVAL (operands[2]) <= 16
6017    && (REGNO (operands[0]) < 9 || REGNO (operands[0]) > 12)
6018    && (REGNO (operands[1]) < 9 || REGNO (operands[1]) > 12)
6019    && REGNO (operands[4]) == 9"
6020   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6021   [(set_attr "length" "8")])
6022
6023 ;; Move up to 8 bytes at a time.
6024 (define_expand "movstrsi_2reg"
6025   [(parallel [(set (match_operand 0 "" "")
6026                    (match_operand 1 "" ""))
6027               (use (match_operand 2 "" ""))
6028               (use (match_operand 3 "" ""))
6029               (clobber (match_scratch:DI 4 ""))
6030               (clobber (match_scratch:SI 5 ""))])]
6031   "TARGET_STRING && !TARGET_64BIT"
6032   "")
6033
6034 (define_insn ""
6035   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6036         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6037    (use (match_operand:SI 2 "immediate_operand" "i"))
6038    (use (match_operand:SI 3 "immediate_operand" "i"))
6039    (clobber (match_scratch:DI 4 "=&r"))
6040    (clobber (match_scratch:SI 5 "=q"))]
6041   "TARGET_STRING && TARGET_POWER && !TARGET_64BIT
6042    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
6043   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6044   [(set_attr "length" "8")])
6045
6046 (define_insn ""
6047   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6048         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6049    (use (match_operand:SI 2 "immediate_operand" "i"))
6050    (use (match_operand:SI 3 "immediate_operand" "i"))
6051    (clobber (match_scratch:DI 4 "=&r"))
6052    (clobber (match_scratch:SI 5 "X"))]
6053   "TARGET_STRING && !TARGET_POWER && !TARGET_64BIT
6054    && INTVAL (operands[2]) > 4 && INTVAL (operands[2]) <= 8"
6055   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6056   [(set_attr "length" "8")])
6057
6058 ;; Move up to 4 bytes at a time.
6059 (define_expand "movstrsi_1reg"
6060   [(parallel [(set (match_operand 0 "" "")
6061                    (match_operand 1 "" ""))
6062               (use (match_operand 2 "" ""))
6063               (use (match_operand 3 "" ""))
6064               (clobber (match_scratch:SI 4 ""))
6065               (clobber (match_scratch:SI 5 ""))])]
6066   "TARGET_STRING"
6067   "")
6068
6069 (define_insn ""
6070   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6071         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6072    (use (match_operand:SI 2 "immediate_operand" "i"))
6073    (use (match_operand:SI 3 "immediate_operand" "i"))
6074    (clobber (match_scratch:SI 4 "=&r"))
6075    (clobber (match_scratch:SI 5 "=q"))]
6076   "TARGET_STRING && TARGET_POWER
6077    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
6078   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6079   [(set_attr "length" "8")])
6080
6081 (define_insn ""
6082   [(set (mem:BLK (match_operand:SI 0 "register_operand" "b"))
6083         (mem:BLK (match_operand:SI 1 "register_operand" "b")))
6084    (use (match_operand:SI 2 "immediate_operand" "i"))
6085    (use (match_operand:SI 3 "immediate_operand" "i"))
6086    (clobber (match_scratch:SI 4 "=&r"))
6087    (clobber (match_scratch:SI 5 "X"))]
6088   "TARGET_STRING && !TARGET_POWER
6089    && INTVAL (operands[2]) > 0 && INTVAL (operands[2]) <= 4"
6090   "{lsi|lswi} %4,%1,%2\;{stsi|stswi} %4,%0,%2"
6091   [(set_attr "length" "8")])
6092
6093 \f
6094 ;; Define insns that do load or store with update.  Some of these we can
6095 ;; get by using pre-decrement or pre-increment, but the hardware can also
6096 ;; do cases where the increment is not the size of the object.
6097 ;;
6098 ;; In all these cases, we use operands 0 and 1 for the register being
6099 ;; incremented because those are the operands that local-alloc will
6100 ;; tie and these are the pair most likely to be tieable (and the ones
6101 ;; that will benefit the most).
6102
6103 (define_insn ""
6104   [(set (match_operand:DI 3 "gpc_reg_operand" "=r,r")
6105         (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
6106                          (match_operand:DI 2 "reg_or_short_operand" "r,I"))))
6107    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
6108         (plus:DI (match_dup 1) (match_dup 2)))]
6109   "TARGET_POWERPC64"
6110   "@
6111    ldux %3,%0,%2
6112    ldu %3,%2(%0)"
6113   [(set_attr "type" "load")])
6114
6115 (define_insn ""
6116   [(set (match_operand:DI 3 "gpc_reg_operand" "=r")
6117         (sign_extend:DI
6118          (mem:SI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0")
6119                           (match_operand:DI 2 "gpc_reg_operand" "r")))))
6120    (set (match_operand:DI 0 "gpc_reg_operand" "=b")
6121         (plus:DI (match_dup 1) (match_dup 2)))]
6122   "TARGET_POWERPC64"
6123   "lwaux %3,%0,%2"
6124   [(set_attr "type" "load")])
6125
6126 (define_insn "movdi_update"
6127   [(set (mem:DI (plus:DI (match_operand:DI 1 "gpc_reg_operand" "0,0")
6128                          (match_operand:DI 2 "reg_or_short_operand" "r,I")))
6129         (match_operand:DI 3 "gpc_reg_operand" "r,r"))
6130    (set (match_operand:DI 0 "gpc_reg_operand" "=b,b")
6131         (plus:DI (match_dup 1) (match_dup 2)))]
6132   "TARGET_POWERPC64"
6133   "@
6134    stdux %3,%0,%2
6135    stdu %3,%2(%0)")
6136
6137 (define_insn ""
6138   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6139         (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6140                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6141    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6142         (plus:SI (match_dup 1) (match_dup 2)))]
6143   ""
6144   "@
6145    {lux|lwzux} %3,%0,%2
6146    {lu|lwzu} %3,%2(%0)"
6147   [(set_attr "type" "load")])
6148
6149 (define_insn "movsi_update"
6150   [(set (mem:SI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6151                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6152         (match_operand:SI 3 "gpc_reg_operand" "r,r"))
6153    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6154         (plus:SI (match_dup 1) (match_dup 2)))]
6155   ""
6156   "@
6157    {stux|stwux} %3,%0,%2
6158    {stu|stwu} %3,%2(%0)")
6159
6160 (define_insn ""
6161   [(set (match_operand:HI 3 "gpc_reg_operand" "=r,r")
6162         (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6163                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6164    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6165         (plus:SI (match_dup 1) (match_dup 2)))]
6166   ""
6167   "@
6168    lhzux %3,%0,%2
6169    lhzu %3,%2(%0)"
6170   [(set_attr "type" "load")])
6171
6172 (define_insn ""
6173   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6174         (zero_extend:SI
6175          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6176                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
6177    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6178         (plus:SI (match_dup 1) (match_dup 2)))]
6179   ""
6180   "@
6181    lhzux %3,%0,%2
6182    lhzu %3,%2(%0)"
6183   [(set_attr "type" "load")])
6184
6185 (define_insn ""
6186   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6187         (sign_extend:SI
6188          (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6189                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
6190    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6191         (plus:SI (match_dup 1) (match_dup 2)))]
6192   ""
6193   "@
6194    lhaux %3,%0,%2
6195    lhau %3,%2(%0)"
6196   [(set_attr "type" "load")])
6197
6198 (define_insn ""
6199   [(set (mem:HI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6200                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6201         (match_operand:HI 3 "gpc_reg_operand" "r,r"))
6202    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6203         (plus:SI (match_dup 1) (match_dup 2)))]
6204   ""
6205   "@
6206    sthux %3,%0,%2
6207    sthu %3,%2(%0)")
6208
6209 (define_insn ""
6210   [(set (match_operand:QI 3 "gpc_reg_operand" "=r,r")
6211         (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6212                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6213    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6214         (plus:SI (match_dup 1) (match_dup 2)))]
6215   ""
6216   "@
6217    lbzux %3,%0,%2
6218    lbzu %3,%2(%0)"
6219   [(set_attr "type" "load")])
6220
6221 (define_insn ""
6222   [(set (match_operand:SI 3 "gpc_reg_operand" "=r,r")
6223         (zero_extend:SI
6224          (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6225                           (match_operand:SI 2 "reg_or_short_operand" "r,I")))))
6226    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6227         (plus:SI (match_dup 1) (match_dup 2)))]
6228   ""
6229   "@
6230    lbzux %3,%0,%2
6231    lbzu %3,%2(%0)"
6232   [(set_attr "type" "load")])
6233
6234 (define_insn ""
6235   [(set (mem:QI (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6236                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6237         (match_operand:QI 3 "gpc_reg_operand" "r,r"))
6238    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6239         (plus:SI (match_dup 1) (match_dup 2)))]
6240   ""
6241   "@
6242    stbux %3,%0,%2
6243    stbu %3,%2(%0)")
6244
6245 (define_insn ""
6246   [(set (match_operand:SF 3 "gpc_reg_operand" "=f,f")
6247         (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6248                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6249    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6250         (plus:SI (match_dup 1) (match_dup 2)))]
6251   "TARGET_HARD_FLOAT"
6252   "@
6253    lfsux %3,%0,%2
6254    lfsu %3,%2(%0)"
6255   [(set_attr "type" "fpload")])
6256
6257 (define_insn ""
6258   [(set (mem:SF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6259                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6260         (match_operand:SF 3 "gpc_reg_operand" "f,f"))
6261    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6262         (plus:SI (match_dup 1) (match_dup 2)))]
6263   "TARGET_HARD_FLOAT"
6264   "@
6265    stfsux %3,%0,%2
6266    stfsu %3,%2(%0)")
6267
6268 (define_insn ""
6269   [(set (match_operand:DF 3 "gpc_reg_operand" "=f,f")
6270         (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6271                          (match_operand:SI 2 "reg_or_short_operand" "r,I"))))
6272    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6273         (plus:SI (match_dup 1) (match_dup 2)))]
6274   "TARGET_HARD_FLOAT"
6275   "@
6276    lfdux %3,%0,%2
6277    lfdu %3,%2(%0)"
6278   [(set_attr "type" "fpload")])
6279
6280 (define_insn ""
6281   [(set (mem:DF (plus:SI (match_operand:SI 1 "gpc_reg_operand" "0,0")
6282                          (match_operand:SI 2 "reg_or_short_operand" "r,I")))
6283         (match_operand:DF 3 "gpc_reg_operand" "f,f"))
6284    (set (match_operand:SI 0 "gpc_reg_operand" "=b,b")
6285         (plus:SI (match_dup 1) (match_dup 2)))]
6286   "TARGET_HARD_FLOAT"
6287   "@
6288    stfdux %3,%0,%2
6289    stfdu %3,%2(%0)")
6290
6291 ;; Peephole to convert two consecutive FP loads or stores into lfq/stfq.
6292
6293 (define_peephole
6294   [(set (match_operand:DF 0 "gpc_reg_operand" "=f")
6295         (match_operand:DF 1 "memory_operand" ""))
6296    (set (match_operand:DF 2 "gpc_reg_operand" "=f")
6297         (match_operand:DF 3 "memory_operand" ""))]
6298   "TARGET_POWER2
6299    && TARGET_HARD_FLOAT
6300    && registers_ok_for_quad_peep (operands[0], operands[2])
6301    && ! MEM_VOLATILE_P (operands[1]) && ! MEM_VOLATILE_P (operands[3])
6302    && addrs_ok_for_quad_peep (XEXP (operands[1], 0), XEXP (operands[3], 0))"
6303   "lfq%U1%X1 %0,%1")
6304
6305 (define_peephole
6306   [(set (match_operand:DF 0 "memory_operand" "")
6307         (match_operand:DF 1 "gpc_reg_operand" "f"))
6308    (set (match_operand:DF 2 "memory_operand" "")
6309         (match_operand:DF 3 "gpc_reg_operand" "f"))]
6310   "TARGET_POWER2
6311    && TARGET_HARD_FLOAT
6312    && registers_ok_for_quad_peep (operands[1], operands[3])
6313    && ! MEM_VOLATILE_P (operands[0]) && ! MEM_VOLATILE_P (operands[2])
6314    && addrs_ok_for_quad_peep (XEXP (operands[0], 0), XEXP (operands[2], 0))"
6315   "stfq%U0%X0 %1,%0")
6316 \f
6317 ;; Next come insns related to the calling sequence.
6318 ;;
6319 ;; First, an insn to allocate new stack space for dynamic use (e.g., alloca).
6320 ;; We move the back-chain and decrement the stack pointer.
6321
6322 (define_expand "allocate_stack"
6323   [(set (reg:SI 1)
6324         (minus:SI (reg:SI 1) (match_operand:SI 0 "reg_or_short_operand" "")))]
6325   ""
6326   "
6327 { rtx chain = gen_reg_rtx (Pmode);
6328   rtx stack_bot = gen_rtx (MEM, Pmode, stack_pointer_rtx);
6329   rtx neg_op0;
6330
6331   emit_move_insn (chain, stack_bot);
6332
6333   /* Under Windows NT, we need to add stack probes for large/variable allocations,
6334      so do it via a call to the external function alloca, instead of doing it
6335      inline.  */
6336   if (DEFAULT_ABI == ABI_NT
6337       && (GET_CODE (operands[0]) != CONST_INT || INTVAL (operands[0]) > 4096))
6338     {
6339       rtx tmp = gen_reg_rtx (SImode);
6340       emit_library_call_value (gen_rtx (SYMBOL_REF, Pmode, \"__allocate_stack\"),
6341                                tmp, 0, SImode, 1, operands[0], Pmode);
6342       emit_insn (gen_set_sp (tmp));
6343       DONE;
6344     }
6345
6346   if (GET_CODE (operands[0]) != CONST_INT
6347       || INTVAL (operands[0]) < -32767
6348       || INTVAL (operands[0]) > 32768)
6349     {
6350       neg_op0 = gen_reg_rtx (Pmode);
6351       if (TARGET_32BIT)
6352         emit_insn (gen_negsi2 (neg_op0, operands[0]));
6353       else
6354         emit_insn (gen_negdi2 (neg_op0, operands[0]));
6355     }
6356   else
6357     neg_op0 = GEN_INT (- INTVAL (operands[0]));
6358
6359   if (TARGET_32BIT)
6360     emit_insn (gen_movsi_update (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
6361   else
6362     emit_insn (gen_movdi_update (stack_pointer_rtx, stack_pointer_rtx, neg_op0, chain));
6363
6364   DONE;
6365 }")
6366
6367 ;; Marker to indicate that the stack pointer was changed under NT in
6368 ;; ways not known to the compiler
6369
6370 (define_insn "set_sp"
6371   [(set (reg:SI 1)
6372         (unspec [(match_operand:SI 0 "register_operand" "r")] 7))]
6373   ""
6374   ""
6375   [(set_attr "length" "0")])
6376
6377 ;; These patterns say how to save and restore the stack pointer.  We need not
6378 ;; save the stack pointer at function level since we are careful to
6379 ;; preserve the backchain.  At block level, we have to restore the backchain
6380 ;; when we restore the stack pointer.
6381 ;;
6382 ;; For nonlocal gotos, we must save both the stack pointer and its
6383 ;; backchain and restore both.  Note that in the nonlocal case, the
6384 ;; save area is a memory location.
6385
6386 (define_expand "save_stack_function"
6387   [(use (const_int 0))]
6388   ""
6389   "")
6390
6391 (define_expand "restore_stack_function"
6392   [(use (const_int 0))]
6393   ""
6394   "")
6395
6396 (define_expand "restore_stack_block"
6397   [(set (match_dup 2) (mem:SI (match_operand:SI 0 "register_operand" "")))
6398    (set (match_dup 0) (match_operand:SI 1 "register_operand" ""))
6399    (set (mem:SI (match_dup 0)) (match_dup 2))]
6400   ""
6401   "
6402 { operands[2] = gen_reg_rtx (SImode); }")
6403
6404 (define_expand "save_stack_nonlocal"
6405   [(match_operand:DI 0 "memory_operand" "")
6406    (match_operand:SI 1 "register_operand" "")]
6407   ""
6408   "
6409 {
6410   rtx temp = gen_reg_rtx (SImode);
6411
6412   /* Copy the backchain to the first word, sp to the second.  */
6413   emit_move_insn (temp, gen_rtx (MEM, SImode, operands[1]));
6414   emit_move_insn (operand_subword (operands[0], 0, 0, DImode), temp);
6415   emit_move_insn (operand_subword (operands[0], 1, 0, DImode), operands[1]);
6416   DONE;
6417 }")
6418
6419 (define_expand "restore_stack_nonlocal"
6420   [(match_operand:SI 0 "register_operand" "")
6421    (match_operand:DI 1 "memory_operand" "")]
6422   ""
6423   "
6424 {
6425   rtx temp = gen_reg_rtx (SImode);
6426
6427   /* Restore the backchain from the first word, sp from the second.  */
6428   emit_move_insn (temp, operand_subword (operands[1], 0, 0, DImode));
6429   emit_move_insn (operands[0], operand_subword (operands[1], 1, 0, DImode));
6430   emit_move_insn (gen_rtx (MEM, SImode, operands[0]), temp);
6431   DONE;
6432 }")
6433 \f
6434
6435 ;; A function pointer under AIX is a pointer to a data area whose first word
6436 ;; contains the actual address of the function, whose second word contains a
6437 ;; pointer to its TOC, and whose third word contains a value to place in the
6438 ;; static chain register (r11).  Note that if we load the static chain, our
6439 ;; "trampoline" need not have any executable code.
6440 ;;
6441 ;; operands[0] is a register pointing to the 3 word descriptor (aka, the function address)
6442 ;; operands[1] is the stack size to clean up
6443 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument (must be 0 for AIX)
6444 ;; operands[3] is location to store the TOC
6445 ;; operands[4] is the TOC register
6446 ;; operands[5] is the static chain register
6447 ;;
6448 ;; We do not break this into separate insns, so that the scheduler will not try
6449 ;; to move the load of the new TOC before any loads from the TOC.
6450
6451 (define_insn "call_indirect_aix"
6452   [(call (mem:SI (match_operand:SI 0 "register_operand" "b"))
6453          (match_operand 1 "const_int_operand" "n"))
6454    (use (match_operand 2 "const_int_operand" "O"))
6455    (use (match_operand 3 "offsettable_addr_operand" "p"))
6456    (use (match_operand 4 "register_operand" "r"))
6457    (clobber (match_operand 5 "register_operand" "=r"))
6458    (clobber (match_scratch:SI 6 "=&r"))
6459    (clobber (match_scratch:SI 7 "=l"))]
6460   "DEFAULT_ABI == ABI_AIX"
6461   "{st|stw} %4,%a3\;{l|lwz} %6,0(%0)\;{l|lwz} %4,4(%0);\;mt%7 %6\;{l|lwz} %5,8(%0)\;{brl|blrl}\;{l|lwz} %4,%a3"
6462   [(set_attr "length" "28")])
6463
6464 (define_insn "call_value_indirect_aix"
6465   [(set (match_operand 0 "register_operand" "fg")
6466         (call (mem:SI (match_operand:SI 1 "register_operand" "b"))
6467               (match_operand 2 "const_int_operand" "n")))
6468    (use (match_operand 3 "const_int_operand" "O"))
6469    (use (match_operand 4 "offsettable_addr_operand" "p"))
6470    (use (match_operand 5 "register_operand" "r"))
6471    (clobber (match_operand 6 "register_operand" "=r"))
6472    (clobber (match_scratch:SI 7 "=&r"))
6473    (clobber (match_scratch:SI 8 "=l"))]
6474   "DEFAULT_ABI == ABI_AIX"
6475   "{st|stw} %5,%a4\;{l|lwz} %7,0(%1)\;{l|lwz} %5,4(%1);\;mt%8 %7\;{l|lwz} %6,8(%1)\;{brl|blrl}\;{l|lwz} %5,%a4"
6476   [(set_attr "length" "28")])
6477
6478 ;; A function pointer undef NT is a pointer to a data area whose first word
6479 ;; contains the actual address of the function, whose second word contains a
6480 ;; pointer to its TOC.  The static chain is not stored under NT, which means
6481 ;; that we need a trampoline.
6482 ;;
6483 ;; operands[0] is an SImode pseudo in which we place the address of the function.
6484 ;; operands[1] is the stack size to clean up
6485 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument (must be 0 for NT)
6486 ;; operands[3] is location to store the TOC
6487 ;; operands[4] is the TOC register
6488 ;;
6489 ;; We do not break this into separate insns, so that the scheduler will not try
6490 ;; to move the load of the new TOC before any loads from the TOC.
6491
6492 (define_insn "call_indirect_nt"
6493   [(call (mem:SI (match_operand:SI 0 "register_operand" "b"))
6494          (match_operand 1 "const_int_operand" "n"))
6495    (use (match_operand 2 "const_int_operand" "O"))
6496    (use (match_operand 3 "offsettable_addr_operand" "p"))
6497    (use (match_operand 4 "register_operand" "r"))
6498    (clobber (match_scratch:SI 5 "=&r"))
6499    (clobber (match_scratch:SI 6 "=l"))]
6500   "DEFAULT_ABI == ABI_NT"
6501   "{st|stw} %4,%a3\;{l|lwz} %5,0(%0)\;{l|lwz} %4,4(%0)\;mt%6 %5\;{brl|blrl}\;{l|lwz} %4,%a3"
6502   [(set_attr "length" "24")])
6503
6504 (define_insn "call_value_indirect_nt"
6505   [(set (match_operand 0 "register_operand" "fg")
6506         (call (mem:SI (match_operand:SI 1 "register_operand" "b"))
6507               (match_operand 2 "const_int_operand" "n")))
6508    (use (match_operand 3 "const_int_operand" "O"))
6509    (use (match_operand 4 "offsettable_addr_operand" "p"))
6510    (use (match_operand 5 "register_operand" "r"))
6511    (clobber (match_scratch:SI 6 "=&r"))
6512    (clobber (match_scratch:SI 7 "=l"))]
6513   "DEFAULT_ABI == ABI_NT"
6514   "{st|stw} %5,%a4\;{l|lwz} %6,0(%1)\;{l|lwz} %5,4(%1)\;mt%7 %6\;{brl|blrl}\;{l|lwz} %5,%a4"
6515   [(set_attr "length" "24")])
6516
6517 ;; A function pointer under System V is just a normal pointer
6518 ;; operands[0] is the function pointer
6519 ;; operands[1] is the stack size to clean up
6520 ;; operands[2] is the value FUNCTION_ARG returns for the VOID argument which indicates how to set cr1
6521
6522 (define_insn "call_indirect_sysv"
6523   [(call (mem:SI (match_operand:SI 0 "register_operand" "l,l"))
6524          (match_operand 1 "const_int_operand" "n,n"))
6525    (use (match_operand 2 "const_int_operand" "O,n"))
6526    (clobber (match_scratch:SI 3 "=l,l"))]
6527   "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_AIX_NODESC"
6528   "*
6529 {
6530   if (INTVAL (operands[2]) > 0)
6531     return \"creqv 6,6,6\;{brl|blrl}\";
6532
6533   else if (INTVAL (operands[2]) < 0)
6534     return \"crxor 6,6,6\;{brl|blrl}\";
6535
6536   return \"{brl|blrl}\";
6537 }"
6538   [(set_attr "length" "4,8")])
6539
6540 (define_insn "call_value_indirect_sysv"
6541   [(set (match_operand 0 "register_operand" "=fg,fg")
6542         (call (mem:SI (match_operand:SI 1 "register_operand" "l,l"))
6543               (match_operand 2 "const_int_operand" "n,n")))
6544    (use (match_operand 3 "const_int_operand" "O,n"))
6545    (clobber (match_scratch:SI 4 "=l,l"))]
6546   "DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_AIX_NODESC"
6547   "*
6548 {
6549   if (INTVAL (operands[3]) > 0)
6550     return \"creqv 6,6,6\;{brl|blrl}\";
6551
6552   else if (INTVAL (operands[3]) < 0)
6553     return \"crxor 6,6,6\;{brl|blrl}\";
6554
6555   return \"{brl|blrl}\";
6556 }"
6557   [(set_attr "length" "4,8")])
6558
6559 ;; Now the definitions for the call and call_value insns
6560 (define_expand "call"
6561   [(parallel [(call (mem:SI (match_operand:SI 0 "address_operand" ""))
6562                     (match_operand 1 "" ""))
6563               (use (match_operand 2 "" ""))
6564               (clobber (scratch:SI))])]
6565   ""
6566   "
6567 {
6568   if (GET_CODE (operands[0]) != MEM || GET_CODE (operands[1]) != CONST_INT)
6569     abort ();
6570
6571   operands[0] = XEXP (operands[0], 0);
6572
6573   /* Convert NT DLL imports into an indirect call.  */
6574   if (GET_CODE (operands[0]) == SYMBOL_REF
6575       && INTVAL (operands[2]) == (int)CALL_NT_DLLIMPORT)
6576     {
6577       operands[0] = rs6000_dll_import_ref (operands[0]);
6578       operands[2] = GEN_INT ((int)CALL_NORMAL);
6579     }
6580
6581   if (GET_CODE (operands[0]) != SYMBOL_REF)
6582     {
6583       if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_AIX_NODESC)
6584         emit_call_insn (gen_call_indirect_sysv (force_reg (Pmode, operands[0]),
6585                                                 operands[1], operands[2]));
6586       else
6587         {
6588           rtx toc_reg = gen_rtx (REG, Pmode, 2);
6589           rtx toc_addr = RS6000_SAVE_TOC;
6590
6591           if (DEFAULT_ABI == ABI_AIX)
6592             {
6593               /* AIX function pointers are really pointers to a three word area */
6594               rtx static_chain = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
6595               emit_call_insn (gen_call_indirect_aix (force_reg (Pmode, operands[0]),
6596                                                      operands[1], operands[2],
6597                                                      toc_addr, toc_reg, static_chain));
6598             }
6599           else if (DEFAULT_ABI == ABI_NT)
6600             {
6601               /* NT function pointers are really pointers to a two word area */
6602               rs6000_save_toc_p = 1;
6603               emit_call_insn (gen_call_indirect_nt (force_reg (Pmode, operands[0]),
6604                                                     operands[1], operands[2],
6605                                                     toc_addr, toc_reg));
6606             }
6607           else
6608             abort ();
6609         }
6610       DONE;
6611     }
6612 }")
6613
6614 (define_expand "call_value"
6615   [(parallel [(set (match_operand 0 "" "")
6616                    (call (mem:SI (match_operand:SI 1 "address_operand" ""))
6617                          (match_operand 2 "" "")))
6618               (use (match_operand 3 "" ""))
6619               (clobber (scratch:SI))])]
6620   ""
6621   "
6622 {
6623   if (GET_CODE (operands[1]) != MEM || GET_CODE (operands[2]) != CONST_INT)
6624     abort ();
6625
6626   operands[1] = XEXP (operands[1], 0);
6627
6628   /* Convert NT DLL imports into an indirect call.  */
6629   if (GET_CODE (operands[1]) == SYMBOL_REF
6630       && INTVAL (operands[3]) == (int)CALL_NT_DLLIMPORT)
6631     {
6632       operands[1] = rs6000_dll_import_ref (operands[1]);
6633       operands[3] = GEN_INT ((int)CALL_NORMAL);
6634     }
6635
6636   if (GET_CODE (operands[1]) != SYMBOL_REF)
6637     {
6638       if (DEFAULT_ABI == ABI_V4 || DEFAULT_ABI == ABI_AIX_NODESC)
6639         emit_call_insn (gen_call_value_indirect_sysv (operands[0], operands[1],
6640                                                       operands[2], operands[3]));
6641       else
6642         {
6643           rtx toc_reg = gen_rtx (REG, Pmode, 2);
6644           rtx toc_addr = RS6000_SAVE_TOC;
6645
6646           if (DEFAULT_ABI == ABI_AIX)
6647             {
6648               /* AIX function pointers are really pointers to a three word area */
6649               rtx static_chain = gen_rtx (REG, Pmode, STATIC_CHAIN_REGNUM);
6650               emit_call_insn (gen_call_value_indirect_aix (operands[0],
6651                                                            force_reg (Pmode, operands[1]),
6652                                                            operands[2], operands[3],
6653                                                            toc_addr, toc_reg, static_chain));
6654             }
6655           else if (DEFAULT_ABI == ABI_NT)
6656             {
6657               /* NT function pointers are really pointers to a two word area */
6658               rs6000_save_toc_p = 1;
6659               emit_call_insn (gen_call_value_indirect_nt (operands[0],
6660                                                           force_reg (Pmode, operands[1]),
6661                                                           operands[2], operands[3],
6662                                                           toc_addr, toc_reg));
6663             }
6664           else
6665             abort ();
6666         }
6667       DONE;
6668     }
6669 }")
6670
6671 ;; Call to function in current module.  No TOC pointer reload needed.
6672 ;; Operand2 is non-zero if we are using the V.4 calling sequence and
6673 ;; either the function was not prototyped, or it was prototyped as a
6674 ;; variable argument function.  It is > 0 if FP registers were passed
6675 ;; and < 0 if they were not.
6676
6677 (define_insn ""
6678   [(call (mem:SI (match_operand:SI 0 "current_file_function_operand" "s,s"))
6679          (match_operand 1 "" "g,g"))
6680    (use (match_operand:SI 2 "immediate_operand" "O,n"))
6681    (clobber (match_scratch:SI 3 "=l,l"))]
6682   ""
6683   "*
6684 {
6685   switch ((enum rs6000_call_cookie)INTVAL (operands[2]))
6686     {
6687     case CALL_V4_SET_FP_ARGS:   output_asm_insn (\"crxor 6,6,6\", operands); break;
6688     case CALL_V4_CLEAR_FP_ARGS: output_asm_insn (\"creqv 6,6,6\", operands); break;
6689     }
6690
6691   return \"bl %z0\";
6692 }"
6693   [(set_attr "length" "4,8")])
6694
6695 ;; Call to function which may be in another module.  Restore the TOC
6696 ;; pointer (r2) after the call unless this is System V.
6697 ;; Operand2 is non-zero if we are using the V.4 calling sequence and
6698 ;; either the function was not prototyped, or it was prototyped as a
6699 ;; variable argument function.  It is > 0 if FP registers were passed
6700 ;; and < 0 if they were not.
6701
6702 (define_insn ""
6703   [(call (mem:SI (match_operand:SI 0 "call_operand" "s,s"))
6704          (match_operand 1 "" "fg,fg"))
6705    (use (match_operand:SI 2 "immediate_operand" "O,n"))
6706    (clobber (match_scratch:SI 3 "=l,l"))]
6707   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT"
6708   "*
6709 {
6710   /* Indirect calls should go through call_indirect */
6711   if (GET_CODE (operands[0]) == REG)
6712     abort ();
6713
6714   switch ((enum rs6000_call_cookie)INTVAL (operands[2]))
6715     {
6716     case CALL_V4_SET_FP_ARGS:   output_asm_insn (\"crxor 6,6,6\", operands); break;
6717     case CALL_V4_CLEAR_FP_ARGS: output_asm_insn (\"creqv 6,6,6\", operands); break;
6718     }
6719
6720   return (TARGET_WINDOWS_NT) ? \"bl %z0\;.znop %z0\" : \"bl %z0\;%.\";
6721 }"
6722   [(set_attr "length" "8,12")])
6723
6724 (define_insn ""
6725   [(call (mem:SI (match_operand:SI 0 "call_operand" "s,s"))
6726          (match_operand 1 "" "fg,fg"))
6727    (use (match_operand:SI 2 "immediate_operand" "O,n"))
6728    (clobber (match_scratch:SI 3 "=l,l"))]
6729   "DEFAULT_ABI == ABI_AIX_NODESC || DEFAULT_ABI == ABI_V4"
6730   "*
6731 {
6732   /* Indirect calls should go through call_indirect */
6733   if (GET_CODE (operands[0]) == REG)
6734     abort ();
6735
6736   switch ((enum rs6000_call_cookie)INTVAL (operands[2]))
6737     {
6738     case CALL_V4_SET_FP_ARGS:   output_asm_insn (\"crxor 6,6,6\", operands); break;
6739     case CALL_V4_CLEAR_FP_ARGS: output_asm_insn (\"creqv 6,6,6\", operands); break;
6740     }
6741
6742   return \"bl %z0\";
6743 }"
6744   [(set_attr "length" "4,8")])
6745
6746 (define_insn ""
6747   [(set (match_operand 0 "" "=fg,fg")
6748         (call (mem:SI (match_operand:SI 1 "current_file_function_operand" "s,s"))
6749               (match_operand 2 "" "g,g")))
6750    (use (match_operand:SI 3 "immediate_operand" "O,n"))
6751    (clobber (match_scratch:SI 4 "=l,l"))]
6752   ""
6753   "*
6754 {
6755   switch ((enum rs6000_call_cookie)INTVAL (operands[3]))
6756     {
6757     case CALL_V4_SET_FP_ARGS:   output_asm_insn (\"crxor 6,6,6\", operands); break;
6758     case CALL_V4_CLEAR_FP_ARGS: output_asm_insn (\"creqv 6,6,6\", operands); break;
6759     }
6760
6761   return \"bl %z1\";
6762 }"
6763   [(set_attr "length" "4,8")])
6764
6765 (define_insn ""
6766   [(set (match_operand 0 "" "=fg,fg")
6767         (call (mem:SI (match_operand:SI 1 "call_operand" "s,s"))
6768               (match_operand 2 "" "fg,fg")))
6769    (use (match_operand:SI 3 "immediate_operand" "O,n"))
6770    (clobber (match_scratch:SI 4 "=l,l"))]
6771   "DEFAULT_ABI == ABI_AIX || DEFAULT_ABI == ABI_NT"
6772   "*
6773 {
6774   /* This should be handled by call_value_indirect */
6775   if (GET_CODE (operands[1]) == REG)
6776     abort ();
6777
6778   switch ((enum rs6000_call_cookie)INTVAL (operands[3]))
6779     {
6780     case CALL_V4_SET_FP_ARGS:   output_asm_insn (\"crxor 6,6,6\", operands); break;
6781     case CALL_V4_CLEAR_FP_ARGS: output_asm_insn (\"creqv 6,6,6\", operands); break;
6782     }
6783
6784   return (TARGET_WINDOWS_NT) ? \"bl %z1\;.znop %z1\" : \"bl %z1\;%.\";
6785 }"
6786   [(set_attr "length" "8,12")])
6787
6788 (define_insn ""
6789   [(set (match_operand 0 "" "=fg,fg")
6790         (call (mem:SI (match_operand:SI 1 "call_operand" "s,s"))
6791               (match_operand 2 "" "fg,fg")))
6792    (use (match_operand:SI 3 "immediate_operand" "O,n"))
6793    (clobber (match_scratch:SI 4 "=l,l"))]
6794   "DEFAULT_ABI == ABI_AIX_NODESC || DEFAULT_ABI == ABI_V4"
6795   "*
6796 {
6797   /* This should be handled by call_value_indirect */
6798   if (GET_CODE (operands[1]) == REG)
6799     abort ();
6800
6801   switch ((enum rs6000_call_cookie)INTVAL (operands[3]))
6802     {
6803     case CALL_V4_SET_FP_ARGS:   output_asm_insn (\"crxor 6,6,6\", operands); break;
6804     case CALL_V4_CLEAR_FP_ARGS: output_asm_insn (\"creqv 6,6,6\", operands); break;
6805     }
6806
6807   return \"bl %z1\";
6808 }"
6809   [(set_attr "length" "4,8")])
6810
6811
6812 ;; Call subroutine returning any type.
6813
6814 (define_expand "untyped_call"
6815   [(parallel [(call (match_operand 0 "" "")
6816                     (const_int 0))
6817               (match_operand 1 "" "")
6818               (match_operand 2 "" "")])]
6819   ""
6820   "
6821 {
6822   int i;
6823
6824   emit_call_insn (gen_call (operands[0], const0_rtx, const0_rtx, const0_rtx));
6825
6826   for (i = 0; i < XVECLEN (operands[2], 0); i++)
6827     {
6828       rtx set = XVECEXP (operands[2], 0, i);
6829       emit_move_insn (SET_DEST (set), SET_SRC (set));
6830     }
6831
6832   /* The optimizer does not know that the call sets the function value
6833      registers we stored in the result block.  We avoid problems by
6834      claiming that all hard registers are used and clobbered at this
6835      point.  */
6836   emit_insn (gen_blockage ());
6837
6838   DONE;
6839 }")
6840
6841 ;; UNSPEC_VOLATILE is considered to use and clobber all hard registers and
6842 ;; all of memory.  This blocks insns from being moved across this point.
6843
6844 (define_insn "blockage"
6845   [(unspec_volatile [(const_int 0)] 0)]
6846   ""
6847   "")
6848
6849 ;; Synchronize instructions/data caches for V.4 trampolines
6850 ;; The extra memory_operand is to prevent the optimizer from
6851 ;; deleting insns with "no" effect.
6852 (define_insn "icbi"
6853   [(unspec [(match_operand 0 "memory_operand" "=m")
6854             (match_operand 1 "register_operand" "b")
6855             (match_operand 2 "register_operand" "r")] 3)]
6856   "TARGET_POWERPC"
6857   "icbi %1,%2")
6858
6859 (define_insn "dcbst"
6860   [(unspec [(match_operand 0 "memory_operand" "=m")
6861             (match_operand 1 "register_operand" "b")
6862             (match_operand 2 "register_operand" "r")] 4)]
6863   "TARGET_POWERPC"
6864   "dcbst %1,%2")
6865
6866 (define_insn "sync"
6867   [(unspec [(match_operand 0 "memory_operand" "=m")] 5)]
6868   ""
6869   "{dcs|sync}")
6870
6871 (define_insn "isync"
6872   [(unspec [(match_operand 0 "memory_operand" "=m")] 6)]
6873   ""
6874   "{ics|isync}")
6875
6876 \f
6877 ;; Compare insns are next.  Note that the RS/6000 has two types of compares,
6878 ;; signed & unsigned, and one type of branch.
6879 ;;
6880 ;; Start with the DEFINE_EXPANDs to generate the rtl for compares, scc
6881 ;; insns, and branches.  We store the operands of compares until we see
6882 ;; how it is used.
6883 (define_expand "cmpsi"
6884   [(set (cc0)
6885         (compare (match_operand:SI 0 "gpc_reg_operand" "")
6886                  (match_operand:SI 1 "reg_or_short_operand" "")))]
6887   ""
6888   "
6889 {
6890   /* Take care of the possibility that operands[1] might be negative but
6891      this might be a logical operation.  That insn doesn't exist.  */
6892   if (GET_CODE (operands[1]) == CONST_INT
6893       && INTVAL (operands[1]) < 0)
6894     operands[1] = force_reg (SImode, operands[1]);
6895
6896   rs6000_compare_op0 = operands[0];
6897   rs6000_compare_op1 = operands[1];
6898   rs6000_compare_fp_p = 0;
6899   DONE;
6900 }")
6901
6902 (define_expand "cmpdi"
6903   [(set (cc0)
6904         (compare (match_operand:DI 0 "gpc_reg_operand" "")
6905                  (match_operand:DI 1 "reg_or_short_operand" "")))]
6906   "TARGET_POWERPC64"
6907   "
6908 {
6909   /* Take care of the possibility that operands[1] might be negative but
6910      this might be a logical operation.  That insn doesn't exist.  */
6911   if (GET_CODE (operands[1]) == CONST_INT
6912       && INTVAL (operands[1]) < 0)
6913     operands[1] = force_reg (DImode, operands[1]);
6914
6915   rs6000_compare_op0 = operands[0];
6916   rs6000_compare_op1 = operands[1];
6917   rs6000_compare_fp_p = 0;
6918   DONE;
6919 }")
6920
6921 (define_expand "cmpsf"
6922   [(set (cc0) (compare (match_operand:SF 0 "gpc_reg_operand" "")
6923                        (match_operand:SF 1 "gpc_reg_operand" "")))]
6924   "TARGET_HARD_FLOAT"
6925   "
6926 {
6927   rs6000_compare_op0 = operands[0];
6928   rs6000_compare_op1 = operands[1];
6929   rs6000_compare_fp_p = 1;
6930   DONE;
6931 }")
6932
6933 (define_expand "cmpdf"
6934   [(set (cc0) (compare (match_operand:DF 0 "gpc_reg_operand" "")
6935                        (match_operand:DF 1 "gpc_reg_operand" "")))]
6936   "TARGET_HARD_FLOAT"
6937   "
6938 {
6939   rs6000_compare_op0 = operands[0];
6940   rs6000_compare_op1 = operands[1];
6941   rs6000_compare_fp_p = 1;
6942   DONE;
6943 }")
6944
6945 (define_expand "beq"
6946   [(set (match_dup 2) (match_dup 1))
6947    (set (pc)
6948         (if_then_else (eq (match_dup 2)
6949                           (const_int 0))
6950                       (label_ref (match_operand 0 "" ""))
6951                       (pc)))]
6952   ""
6953   "
6954 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
6955   operands[1] = gen_rtx (COMPARE, mode,
6956                          rs6000_compare_op0, rs6000_compare_op1);
6957   operands[2] = gen_reg_rtx (mode);
6958 }")
6959
6960 (define_expand "bne"
6961   [(set (match_dup 2) (match_dup 1))
6962    (set (pc)
6963         (if_then_else (ne (match_dup 2)
6964                           (const_int 0))
6965                       (label_ref (match_operand 0 "" ""))
6966                       (pc)))]
6967   ""
6968   "
6969 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
6970   operands[1] = gen_rtx (COMPARE, mode,
6971                          rs6000_compare_op0, rs6000_compare_op1);
6972   operands[2] = gen_reg_rtx (mode);
6973 }")
6974
6975 (define_expand "blt"
6976   [(set (match_dup 2) (match_dup 1))
6977    (set (pc)
6978         (if_then_else (lt (match_dup 2)
6979                           (const_int 0))
6980                       (label_ref (match_operand 0 "" ""))
6981                       (pc)))]
6982   ""
6983   "
6984 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
6985   operands[1] = gen_rtx (COMPARE, mode,
6986                          rs6000_compare_op0, rs6000_compare_op1);
6987   operands[2] = gen_reg_rtx (mode);
6988 }")
6989
6990 (define_expand "bgt"
6991   [(set (match_dup 2) (match_dup 1))
6992    (set (pc)
6993         (if_then_else (gt (match_dup 2)
6994                           (const_int 0))
6995                       (label_ref (match_operand 0 "" ""))
6996                       (pc)))]
6997   ""
6998   "
6999 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7000   operands[1] = gen_rtx (COMPARE, mode,
7001                          rs6000_compare_op0, rs6000_compare_op1);
7002   operands[2] = gen_reg_rtx (mode);
7003 }")
7004
7005 (define_expand "ble"
7006   [(set (match_dup 2) (match_dup 1))
7007    (set (pc)
7008         (if_then_else (le (match_dup 2)
7009                           (const_int 0))
7010                       (label_ref (match_operand 0 "" ""))
7011                       (pc)))]
7012   ""
7013   "
7014 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7015   operands[1] = gen_rtx (COMPARE, mode,
7016                          rs6000_compare_op0, rs6000_compare_op1);
7017   operands[2] = gen_reg_rtx (mode);
7018 }")
7019
7020 (define_expand "bge"
7021   [(set (match_dup 2) (match_dup 1))
7022    (set (pc)
7023         (if_then_else (ge (match_dup 2)
7024                           (const_int 0))
7025                       (label_ref (match_operand 0 "" ""))
7026                       (pc)))]
7027   ""
7028   "
7029 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7030   operands[1] = gen_rtx (COMPARE, mode,
7031                          rs6000_compare_op0, rs6000_compare_op1);
7032   operands[2] = gen_reg_rtx (mode);
7033 }")
7034
7035 (define_expand "bgtu"
7036   [(set (match_dup 2) (match_dup 1))
7037    (set (pc)
7038         (if_then_else (gtu (match_dup 2)
7039                            (const_int 0))
7040                       (label_ref (match_operand 0 "" ""))
7041                       (pc)))]
7042   ""
7043   "
7044 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7045                          rs6000_compare_op0, rs6000_compare_op1);
7046   operands[2] = gen_reg_rtx (CCUNSmode);
7047 }")
7048
7049 (define_expand "bltu"
7050   [(set (match_dup 2) (match_dup 1))
7051    (set (pc)
7052         (if_then_else (ltu (match_dup 2)
7053                            (const_int 0))
7054                       (label_ref (match_operand 0 "" ""))
7055                       (pc)))]
7056   ""
7057   "
7058 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7059                          rs6000_compare_op0, rs6000_compare_op1);
7060   operands[2] = gen_reg_rtx (CCUNSmode);
7061 }")
7062
7063 (define_expand "bgeu"
7064   [(set (match_dup 2) (match_dup 1))
7065    (set (pc)
7066         (if_then_else (geu (match_dup 2)
7067                            (const_int 0))
7068                       (label_ref (match_operand 0 "" ""))
7069                       (pc)))]
7070   ""
7071   "
7072 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7073                          rs6000_compare_op0, rs6000_compare_op1);
7074   operands[2] = gen_reg_rtx (CCUNSmode);
7075 }")
7076
7077 (define_expand "bleu"
7078   [(set (match_dup 2) (match_dup 1))
7079    (set (pc)
7080         (if_then_else (leu (match_dup 2)
7081                            (const_int 0))
7082                       (label_ref (match_operand 0 "" ""))
7083                       (pc)))]
7084   ""
7085   "
7086 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7087                          rs6000_compare_op0, rs6000_compare_op1);
7088   operands[2] = gen_reg_rtx (CCUNSmode);
7089 }")
7090
7091 ;; For SNE, we would prefer that the xor/abs sequence be used for integers.
7092 ;; For SEQ, likewise, except that comparisons with zero should be done
7093 ;; with an scc insns.  However, due to the order that combine see the
7094 ;; resulting insns, we must, in fact, allow SEQ for integers.  Fail in
7095 ;; the cases we don't want to handle.
7096 (define_expand "seq"
7097   [(set (match_dup 2) (match_dup 1))
7098    (set (match_operand:SI 0 "gpc_reg_operand" "")
7099         (eq:SI (match_dup 2) (const_int 0)))]
7100   ""
7101   "
7102 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7103   operands[1] = gen_rtx (COMPARE, mode,
7104                          rs6000_compare_op0, rs6000_compare_op1);
7105   operands[2] = gen_reg_rtx (mode);
7106 }")
7107
7108 (define_expand "sne"
7109   [(set (match_dup 2) (match_dup 1))
7110    (set (match_operand:SI 0 "gpc_reg_operand" "")
7111         (ne:SI (match_dup 2) (const_int 0)))]
7112   ""
7113   "
7114 { if (! rs6000_compare_fp_p)
7115     FAIL;
7116
7117   operands[1] = gen_rtx (COMPARE, CCFPmode,
7118                          rs6000_compare_op0, rs6000_compare_op1);
7119   operands[2] = gen_reg_rtx (CCFPmode);
7120 }")
7121
7122 ;; A > 0 is best done using the portable sequence, so fail in that case.
7123 (define_expand "sgt"
7124   [(set (match_dup 2) (match_dup 1))
7125    (set (match_operand:SI 0 "gpc_reg_operand" "")
7126         (gt:SI (match_dup 2) (const_int 0)))]
7127   ""
7128   "
7129 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7130
7131   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
7132     FAIL;
7133
7134   operands[1] = gen_rtx (COMPARE, mode,
7135                          rs6000_compare_op0, rs6000_compare_op1);
7136   operands[2] = gen_reg_rtx (mode);
7137 }")
7138
7139 ;; A < 0 is best done in the portable way for A an integer.
7140 (define_expand "slt"
7141   [(set (match_dup 2) (match_dup 1))
7142    (set (match_operand:SI 0 "gpc_reg_operand" "")
7143         (lt:SI (match_dup 2) (const_int 0)))]
7144   ""
7145   "
7146 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7147
7148   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
7149     FAIL;
7150
7151   operands[1] = gen_rtx (COMPARE, mode,
7152                          rs6000_compare_op0, rs6000_compare_op1);
7153   operands[2] = gen_reg_rtx (mode);
7154 }")
7155
7156 (define_expand "sge"
7157   [(set (match_dup 2) (match_dup 1))
7158    (set (match_operand:SI 0 "gpc_reg_operand" "")
7159         (ge:SI (match_dup 2) (const_int 0)))]
7160   ""
7161   "
7162 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7163   operands[1] = gen_rtx (COMPARE, mode,
7164                          rs6000_compare_op0, rs6000_compare_op1);
7165   operands[2] = gen_reg_rtx (mode);
7166 }")
7167
7168 ;; A <= 0 is best done the portable way for A an integer.
7169 (define_expand "sle"
7170   [(set (match_dup 2) (match_dup 1))
7171    (set (match_operand:SI 0 "gpc_reg_operand" "")
7172         (le:SI (match_dup 2) (const_int 0)))]
7173   ""
7174   "
7175 { enum machine_mode mode = rs6000_compare_fp_p ? CCFPmode : CCmode;
7176
7177   if (! rs6000_compare_fp_p && rs6000_compare_op1 == const0_rtx)
7178     FAIL;
7179
7180   operands[1] = gen_rtx (COMPARE, mode,
7181                          rs6000_compare_op0, rs6000_compare_op1);
7182   operands[2] = gen_reg_rtx (mode);
7183 }")
7184
7185 (define_expand "sgtu"
7186   [(set (match_dup 2) (match_dup 1))
7187    (set (match_operand:SI 0 "gpc_reg_operand" "")
7188         (gtu:SI (match_dup 2) (const_int 0)))]
7189   ""
7190   "
7191 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7192                          rs6000_compare_op0, rs6000_compare_op1);
7193   operands[2] = gen_reg_rtx (CCUNSmode);
7194 }")
7195
7196 (define_expand "sltu"
7197   [(set (match_dup 2) (match_dup 1))
7198    (set (match_operand:SI 0 "gpc_reg_operand" "")
7199         (ltu:SI (match_dup 2) (const_int 0)))]
7200   ""
7201   "
7202 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7203                          rs6000_compare_op0, rs6000_compare_op1);
7204   operands[2] = gen_reg_rtx (CCUNSmode);
7205 }")
7206
7207 (define_expand "sgeu"
7208   [(set (match_dup 2) (match_dup 1))
7209    (set (match_operand:SI 0 "gpc_reg_operand" "")
7210         (geu:SI (match_dup 2) (const_int 0)))]
7211   ""
7212   "
7213 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7214                          rs6000_compare_op0, rs6000_compare_op1);
7215   operands[2] = gen_reg_rtx (CCUNSmode);
7216 }")
7217
7218 (define_expand "sleu"
7219   [(set (match_dup 2) (match_dup 1))
7220    (set (match_operand:SI 0 "gpc_reg_operand" "")
7221         (leu:SI (match_dup 2) (const_int 0)))]
7222   ""
7223   "
7224 { operands[1] = gen_rtx (COMPARE, CCUNSmode,
7225                          rs6000_compare_op0, rs6000_compare_op1);
7226   operands[2] = gen_reg_rtx (CCUNSmode);
7227 }")
7228 \f
7229 ;; Here are the actual compare insns.
7230 (define_insn ""
7231   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
7232         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
7233                     (match_operand:SI 2 "reg_or_short_operand" "rI")))]
7234   ""
7235   "{cmp%I2|cmpw%I2} %0,%1,%2"
7236   [(set_attr "type" "compare")])
7237
7238 (define_insn ""
7239   [(set (match_operand:CC 0 "cc_reg_operand" "=y")
7240         (compare:CC (match_operand:DI 1 "gpc_reg_operand" "r")
7241                     (match_operand:DI 2 "reg_or_short_operand" "rI")))]
7242   "TARGET_POWERPC64"
7243   "cmpd%I2 %0,%1,%2"
7244   [(set_attr "type" "compare")])
7245
7246 ;; If we are comparing a register for equality with a large constant,
7247 ;; we can do this with an XOR followed by a compare.  But we need a scratch
7248 ;; register for the result of the XOR.
7249
7250 (define_split
7251   [(set (match_operand:CC 0 "cc_reg_operand" "")
7252         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7253                     (match_operand:SI 2 "non_short_cint_operand" "")))
7254    (clobber (match_operand:SI 3 "gpc_reg_operand" ""))]
7255   "find_single_use (operands[0], insn, 0)
7256    && (GET_CODE (*find_single_use (operands[0], insn, 0)) == EQ
7257        || GET_CODE (*find_single_use (operands[0], insn, 0)) == NE)"
7258   [(set (match_dup 3) (xor:SI (match_dup 1) (match_dup 4)))
7259    (set (match_dup 0) (compare:CC (match_dup 3) (match_dup 5)))]
7260   "
7261 {
7262   /* Get the constant we are comparing against, C,  and see what it looks like
7263      sign-extended to 16 bits.  Then see what constant could be XOR'ed
7264      with C to get the sign-extended value.  */
7265
7266   int c = INTVAL (operands[2]);
7267   int sextc = (c << 16) >> 16;
7268   int xorv = c ^ sextc;
7269
7270   operands[4] = gen_rtx (CONST_INT, VOIDmode, xorv);
7271   operands[5] = gen_rtx (CONST_INT, VOIDmode, sextc);
7272 }")
7273
7274 (define_insn ""
7275   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
7276         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
7277                        (match_operand:SI 2 "reg_or_u_short_operand" "rI")))]
7278   ""
7279   "{cmpl%I2|cmplw%I2} %0,%1,%W2"
7280   [(set_attr "type" "compare")])
7281
7282 (define_insn ""
7283   [(set (match_operand:CCUNS 0 "cc_reg_operand" "=y")
7284         (compare:CCUNS (match_operand:DI 1 "gpc_reg_operand" "r")
7285                        (match_operand:DI 2 "reg_or_u_short_operand" "rI")))]
7286   ""
7287   "cmpld%I2 %0,%1,%W2"
7288   [(set_attr "type" "compare")])
7289
7290 ;; The following two insns don't exist as single insns, but if we provide
7291 ;; them, we can swap an add and compare, which will enable us to overlap more
7292 ;; of the required delay between a compare and branch.  We generate code for
7293 ;; them by splitting.
7294
7295 (define_insn ""
7296   [(set (match_operand:CC 3 "cc_reg_operand" "=y")
7297         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "r")
7298                     (match_operand:SI 2 "short_cint_operand" "i")))
7299    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7300         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
7301   ""
7302   "#"
7303   [(set_attr "length" "8")])
7304
7305 (define_insn ""
7306   [(set (match_operand:CCUNS 3 "cc_reg_operand" "=y")
7307         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "r")
7308                        (match_operand:SI 2 "u_short_cint_operand" "i")))
7309    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7310         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "i")))]
7311   ""
7312   "#"
7313   [(set_attr "length" "8")])
7314
7315 (define_split
7316   [(set (match_operand:CC 3 "cc_reg_operand" "")
7317         (compare:CC (match_operand:SI 1 "gpc_reg_operand" "")
7318                     (match_operand:SI 2 "short_cint_operand" "")))
7319    (set (match_operand:SI 0 "gpc_reg_operand" "")
7320         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
7321   ""
7322   [(set (match_dup 3) (compare:CC (match_dup 1) (match_dup 2)))
7323    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
7324
7325 (define_split
7326   [(set (match_operand:CCUNS 3 "cc_reg_operand" "")
7327         (compare:CCUNS (match_operand:SI 1 "gpc_reg_operand" "")
7328                        (match_operand:SI 2 "u_short_cint_operand" "")))
7329    (set (match_operand:SI 0 "gpc_reg_operand" "")
7330         (plus:SI (match_dup 1) (match_operand:SI 4 "short_cint_operand" "")))]
7331   ""
7332   [(set (match_dup 3) (compare:CCUNS (match_dup 1) (match_dup 2)))
7333    (set (match_dup 0) (plus:SI (match_dup 1) (match_dup 4)))])
7334
7335 (define_insn ""
7336   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
7337         (compare:CCFP (match_operand:SF 1 "gpc_reg_operand" "f")
7338                       (match_operand:SF 2 "gpc_reg_operand" "f")))]
7339   "TARGET_HARD_FLOAT"
7340   "fcmpu %0,%1,%2"
7341   [(set_attr "type" "fpcompare")])
7342
7343 (define_insn ""
7344   [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
7345         (compare:CCFP (match_operand:DF 1 "gpc_reg_operand" "f")
7346                       (match_operand:DF 2 "gpc_reg_operand" "f")))]
7347   "TARGET_HARD_FLOAT"
7348   "fcmpu %0,%1,%2"
7349   [(set_attr "type" "fpcompare")])
7350 \f
7351 ;; Now we have the scc insns.  We can do some combinations because of the
7352 ;; way the machine works.
7353 ;;
7354 ;; Note that this is probably faster if we can put an insn between the
7355 ;; mfcr and rlinm, but this is tricky.  Let's leave it for now.  In most
7356 ;; cases the insns below which don't use an intermediate CR field will
7357 ;; be used instead.
7358 (define_insn ""
7359   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7360         (match_operator:SI 1 "scc_comparison_operator"
7361                            [(match_operand 2 "cc_reg_operand" "y")
7362                             (const_int 0)]))]
7363   ""
7364   "%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%J1,1"
7365   [(set_attr "length" "12")])
7366
7367 (define_insn ""
7368   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
7369         (compare:CC (match_operator:SI 1 "scc_comparison_operator"
7370                                        [(match_operand 2 "cc_reg_operand" "y")
7371                                         (const_int 0)])
7372                     (const_int 0)))
7373    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
7374         (match_op_dup 1 [(match_dup 2) (const_int 0)]))]
7375   ""
7376   "%D1mfcr %3\;{rlinm.|rlwinm.} %3,%3,%J1,1"
7377   [(set_attr "type" "delayed_compare")
7378    (set_attr "length" "12")])
7379
7380 (define_insn ""
7381   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7382         (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
7383                                       [(match_operand 2 "cc_reg_operand" "y")
7384                                        (const_int 0)])
7385                    (match_operand:SI 3 "const_int_operand" "n")))]
7386   ""
7387   "*
7388 {
7389   int is_bit = ccr_bit (operands[1], 1);
7390   int put_bit = 31 - (INTVAL (operands[3]) & 31);
7391   int count;
7392
7393   if (is_bit >= put_bit)
7394     count = is_bit - put_bit;
7395   else
7396     count = 32 - (put_bit - is_bit);
7397
7398   operands[4] = gen_rtx (CONST_INT, VOIDmode, count);
7399   operands[5] = gen_rtx (CONST_INT, VOIDmode, put_bit);
7400
7401   return \"%D1mfcr %0\;{rlinm|rlwinm} %0,%0,%4,%5,%5\";
7402 }"
7403  [(set_attr "length" "12")])
7404
7405 (define_insn ""
7406   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
7407         (compare:CC
7408          (ashift:SI (match_operator:SI 1 "scc_comparison_operator"
7409                                        [(match_operand 2 "cc_reg_operand" "y")
7410                                         (const_int 0)])
7411                     (match_operand:SI 3 "const_int_operand" "n"))
7412          (const_int 0)))
7413    (set (match_operand:SI 4 "gpc_reg_operand" "=r")
7414         (ashift:SI (match_op_dup 1 [(match_dup 2) (const_int 0)])
7415                    (match_dup 3)))]
7416   ""
7417   "*
7418 {
7419   int is_bit = ccr_bit (operands[1], 1);
7420   int put_bit = 31 - (INTVAL (operands[3]) & 31);
7421   int count;
7422
7423   if (is_bit >= put_bit)
7424     count = is_bit - put_bit;
7425   else
7426     count = 32 - (put_bit - is_bit);
7427
7428   operands[5] = gen_rtx (CONST_INT, VOIDmode, count);
7429   operands[6] = gen_rtx (CONST_INT, VOIDmode, put_bit);
7430
7431   return \"%D1mfcr %4\;{rlinm.|rlwinm.} %4,%4,%5,%6,%6\";
7432 }"
7433   [(set_attr "type" "delayed_compare")
7434    (set_attr "length" "12")])
7435
7436 ;; If we are comparing the result of two comparisons, this can be done
7437 ;; using creqv or crxor.
7438
7439 (define_insn ""
7440   [(set (match_operand:CCEQ 0 "cc_reg_operand" "=y")
7441         (compare:CCEQ (match_operator 1 "scc_comparison_operator"
7442                               [(match_operand 2 "cc_reg_operand" "y")
7443                                (const_int 0)])
7444                       (match_operator 3 "scc_comparison_operator"
7445                               [(match_operand 4 "cc_reg_operand" "y")
7446                                (const_int 0)])))]
7447   "REGNO (operands[2]) != REGNO (operands[4])"
7448   "*
7449 {
7450   enum rtx_code code1, code2;
7451
7452   code1 = GET_CODE (operands[1]);
7453   code2 = GET_CODE (operands[3]);
7454
7455   if ((code1 == EQ || code1 == LT || code1 == GT
7456        || code1 == LTU || code1 == GTU
7457        || (code1 != NE && GET_MODE (operands[2]) == CCFPmode))
7458       !=
7459       (code2 == EQ || code2 == LT || code2 == GT
7460        || code2 == LTU || code2 == GTU
7461        || (code2 != NE && GET_MODE (operands[4]) == CCFPmode)))
7462     return \"%C1%C3crxor %E0,%j1,%j3\";
7463   else
7464     return \"%C1%C3creqv %E0,%j1,%j3\";
7465 }"
7466   [(set_attr "length" "12")])
7467
7468 ;; There is a 3 cycle delay between consecutive mfcr instructions
7469 ;; so it is useful to combine 2 scc instructions to use only one mfcr.
7470
7471 (define_peephole
7472   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7473         (match_operator:SI 1 "scc_comparison_operator"
7474                            [(match_operand 2 "cc_reg_operand" "y")
7475                             (const_int 0)]))
7476    (set (match_operand:SI 3 "gpc_reg_operand" "=r")
7477         (match_operator:SI 4 "scc_comparison_operator"
7478                            [(match_operand 5 "cc_reg_operand" "y")
7479                             (const_int 0)]))]
7480    "REGNO (operands[2]) != REGNO (operands[5])"
7481    "%D1%D4mfcr %3\;{rlinm|rlwinm} %0,%3,%J1,1\;{rlinm|rlwinm} %3,%3,%J4,1"
7482    [(set_attr "length" "20")])
7483
7484 ;; There are some scc insns that can be done directly, without a compare.
7485 ;; These are faster because they don't involve the communications between
7486 ;; the FXU and branch units.   In fact, we will be replacing all of the
7487 ;; integer scc insns here or in the portable methods in emit_store_flag.
7488 ;;
7489 ;; Also support (neg (scc ..)) since that construct is used to replace
7490 ;; branches, (plus (scc ..) ..) since that construct is common and
7491 ;; takes no more insns than scc, and (and (neg (scc ..)) ..) in the
7492 ;; cases where it is no more expensive than (neg (scc ..)).
7493
7494 ;; Have reload force a constant into a register for the simple insns that
7495 ;; otherwise won't accept constants.  We do this because it is faster than
7496 ;; the cmp/mfcr sequence we would otherwise generate.
7497
7498 (define_insn ""
7499   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
7500         (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
7501                (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I")))
7502    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
7503   ""
7504   "@
7505    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
7506    {sfi|subfic} %3,%1,0\;{ae|adde} %0,%3,%1
7507    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
7508    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0
7509    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae|adde} %0,%3,%0"
7510   [(set_attr "length" "12,8,12,12,12")])
7511
7512 (define_insn ""
7513   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x,x,x,x")
7514         (compare:CC
7515          (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
7516                 (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
7517          (const_int 0)))
7518    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
7519         (eq:SI (match_dup 1) (match_dup 2)))
7520    (clobber (match_scratch:SI 3 "=r,&r,r,r,r"))]
7521   ""
7522   "@
7523    xor %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
7524    {sfi|subfic} %3,%1,0\;{ae.|adde.} %0,%3,%1
7525    {xoril|xori} %0,%1,%b2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
7526    {xoriu|xoris} %0,%1,%u2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0
7527    {sfi|subfic} %0,%1,%2\;{sfi|subfic} %3,%0,0\;{ae.|adde.} %0,%3,%0"
7528   [(set_attr "type" "compare")
7529    (set_attr "length" "12,8,12,12,12")])
7530
7531 ;; We have insns of the form shown by the first define_insn below.  If
7532 ;; there is something inside the comparison operation, we must split it.
7533 (define_split
7534   [(set (match_operand:SI 0 "gpc_reg_operand" "")
7535         (plus:SI (match_operator 1 "comparison_operator"
7536                                  [(match_operand:SI 2 "" "")
7537                                   (match_operand:SI 3
7538                                                     "reg_or_cint_operand" "")])
7539                  (match_operand:SI 4 "gpc_reg_operand" "")))
7540    (clobber (match_operand:SI 5 "register_operand" ""))]
7541   "! gpc_reg_operand (operands[2], SImode)"
7542   [(set (match_dup 5) (match_dup 2))
7543    (set (match_dup 2) (plus:SI (match_op_dup 1 [(match_dup 2) (match_dup 3)])
7544                                (match_dup 4)))])
7545
7546 (define_insn ""
7547   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
7548         (plus:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
7549                         (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
7550                  (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r")))
7551    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
7552   ""
7553   "@
7554    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
7555    {sfi|subfic} %4,%1,0\;{aze|addze} %0,%3
7556    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
7557    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
7558    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
7559   [(set_attr "length" "12,8,12,12,12")])
7560
7561 (define_insn ""
7562   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x,x,x,x")
7563         (compare:CC
7564          (plus:SI
7565           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
7566                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
7567           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
7568          (const_int 0)))
7569    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
7570   ""
7571   "@
7572    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
7573    {sfi|subfic} %4,%1,0\;{aze.|addze.} %0,%3
7574    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
7575    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
7576    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
7577   [(set_attr "type" "compare")
7578    (set_attr "length" "12,8,12,12,12")])
7579
7580 (define_insn ""
7581   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x,x,x,x")
7582         (compare:CC
7583          (plus:SI
7584           (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
7585                  (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))
7586           (match_operand:SI 3 "gpc_reg_operand" "r,r,r,r,r"))
7587          (const_int 0)))
7588    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
7589         (plus:SI (eq:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
7590    (clobber (match_scratch:SI 4 "=&r,&r,&r,&r,&r"))]
7591   ""
7592   "@
7593    xor %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
7594    {sfi|subfic} %4,%1,0\;{aze.|addze.} %4,%3
7595    {xoril|xori} %4,%1,%b2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
7596    {xoriu|xoris} %4,%1,%u2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
7597    {sfi|subfic} %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
7598   [(set_attr "type" "compare")
7599    (set_attr "length" "12,8,12,12,12")])
7600
7601 (define_insn ""
7602   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r,r")
7603         (neg:SI (eq:SI (match_operand:SI 1 "gpc_reg_operand" "%r,r,r,r,r")
7604                        (match_operand:SI 2 "reg_or_cint_operand" "r,O,K,J,I"))))]
7605   ""
7606   "@
7607    xor %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
7608    {ai|addic} %0,%1,-1\;{sfe|subfe} %0,%0,%0
7609    {xoril|xori} %0,%1,%b2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
7610    {xoriu|xoris} %0,%1,%u2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
7611    {sfi|subfic} %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
7612    [(set_attr "length" "12,8,12,12,12")])
7613
7614 ;; Simplify (ne X (const_int 0)) on the PowerPC.  No need to on the Power,
7615 ;; since it nabs/sr is just as fast.
7616 (define_insn ""
7617   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7618         (lshiftrt:SI (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
7619                      (const_int 31)))
7620    (clobber (match_scratch:SI 2 "=&r"))]
7621   "!TARGET_POWER"
7622   "{ai|addic} %2,%1,-1\;{sfe|subfe} %0,%2,%1"
7623   [(set_attr "length" "8")])
7624
7625 ;; This is what (plus (ne X (const_int 0)) Y) looks like.
7626 (define_insn ""
7627   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7628         (plus:SI (lshiftrt:SI
7629                   (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
7630                   (const_int 31))
7631                  (match_operand:SI 2 "gpc_reg_operand" "r")))
7632    (clobber (match_scratch:SI 3 "=&r"))]
7633   ""
7634   "{ai|addic} %3,%1,-1\;{aze|addze} %0,%2"
7635   [(set_attr "length" "8")])
7636
7637 (define_insn ""
7638   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
7639         (compare:CC
7640          (plus:SI (lshiftrt:SI
7641                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
7642                    (const_int 31))
7643                   (match_operand:SI 2 "gpc_reg_operand" "r"))
7644          (const_int 0)))
7645    (clobber (match_scratch:SI 3 "=&r"))]
7646   ""
7647   "{ai|addic} %3,%1,-1\;{aze.|addze.} %3,%2"
7648   [(set_attr "type" "compare")
7649    (set_attr "length" "8")])
7650
7651 (define_insn ""
7652   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
7653         (compare:CC
7654          (plus:SI (lshiftrt:SI
7655                    (neg:SI (abs:SI (match_operand:SI 1 "gpc_reg_operand" "r")))
7656                    (const_int 31))
7657                   (match_operand:SI 2 "gpc_reg_operand" "r"))
7658          (const_int 0)))
7659    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7660         (plus:SI (lshiftrt:SI (neg:SI (abs:SI (match_dup 1))) (const_int 31))
7661                  (match_dup 2)))
7662    (clobber (match_scratch:SI 3 "=&r"))]
7663   ""
7664   "{ai|addic} %3,%1,-1\;{aze.|addze.} %0,%2"
7665   [(set_attr "type" "compare")
7666    (set_attr "length" "8")])
7667
7668 (define_insn ""
7669   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7670         (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7671                (match_operand:SI 2 "reg_or_short_operand" "r,O")))
7672    (clobber (match_scratch:SI 3 "=r,X"))]
7673   "TARGET_POWER"
7674   "@
7675    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3
7676    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri|srwi} %0,%0,31"
7677   [(set_attr "length" "12")])
7678
7679 (define_insn ""
7680   [(set (match_operand:CC 4 "cc_reg_operand" "=x,x")
7681         (compare:CC
7682          (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7683                 (match_operand:SI 2 "reg_or_short_operand" "r,O"))
7684          (const_int 0)))
7685    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7686         (le:SI (match_dup 1) (match_dup 2)))
7687    (clobber (match_scratch:SI 3 "=r,X"))]
7688   "TARGET_POWER"
7689   "@
7690    doz %3,%2,%1\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3
7691    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{sri.|srwi.} %0,%0,31"
7692   [(set_attr "type" "compare,delayed_compare")
7693    (set_attr "length" "12")])
7694
7695 (define_insn ""
7696   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7697         (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7698                         (match_operand:SI 2 "reg_or_short_operand" "r,O"))
7699                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
7700    (clobber (match_scratch:SI 4 "=&r,&r"))]
7701   "TARGET_POWER"
7702   "@
7703    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3
7704    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze|addze} %0,%3"
7705   [(set_attr "length" "12")])
7706
7707 (define_insn ""
7708   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
7709         (compare:CC
7710          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7711                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
7712                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
7713          (const_int 0)))
7714    (clobber (match_scratch:SI 4 "=&r,&r"))]
7715   "TARGET_POWER"
7716   "@
7717    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3
7718    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %4,%3"
7719   [(set_attr "type" "compare")
7720    (set_attr "length" "12")])
7721
7722 (define_insn ""
7723   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
7724         (compare:CC
7725          (plus:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7726                          (match_operand:SI 2 "reg_or_short_operand" "r,O"))
7727                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
7728          (const_int 0)))
7729    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7730         (plus:SI (le:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
7731    (clobber (match_scratch:SI 4 "=&r,&r"))]
7732   "TARGET_POWER"
7733   "@
7734    doz %4,%2,%1\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3
7735    {srai|srawi} %4,%1,31\;{sf|subfc} %4,%1,%4\;{aze.|addze.} %0,%3"
7736   [(set_attr "type" "compare")
7737    (set_attr "length" "12")])
7738
7739 (define_insn ""
7740   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7741         (neg:SI (le:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7742                        (match_operand:SI 2 "reg_or_short_operand" "r,O"))))]
7743   "TARGET_POWER"
7744   "@
7745    doz %0,%2,%1\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0
7746    {ai|addic} %0,%1,-1\;{aze|addze} %0,%0\;{srai|srawi} %0,%0,31"
7747   [(set_attr "length" "12")])
7748
7749 (define_insn ""
7750   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7751         (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7752                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
7753   ""
7754   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
7755   [(set_attr "length" "12")])
7756
7757 (define_insn ""
7758   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
7759         (compare:CC
7760          (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7761                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
7762          (const_int 0)))
7763    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7764         (leu:SI (match_dup 1) (match_dup 2)))]
7765    ""
7766   "{sf%I2|subf%I2c} %0,%1,%2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
7767   [(set_attr "type" "compare")
7768    (set_attr "length" "12")])
7769
7770 (define_insn ""
7771   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7772         (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7773                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
7774                  (match_operand:SI 3 "gpc_reg_operand" "r")))
7775    (clobber (match_scratch:SI 4 "=&r"))]
7776   ""
7777   "{sf%I2|subf%I2c} %4,%1,%2\;{aze|addze} %0,%3"
7778   [(set_attr "length" "8")])
7779
7780 (define_insn ""
7781   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
7782         (compare:CC
7783          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7784                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
7785                   (match_operand:SI 3 "gpc_reg_operand" "r"))
7786          (const_int 0)))
7787    (clobber (match_scratch:SI 4 "=&r"))]
7788   ""
7789   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %4,%3"
7790   [(set_attr "type" "compare")
7791    (set_attr "length" "8")])
7792
7793 (define_insn ""
7794   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
7795         (compare:CC
7796          (plus:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7797                           (match_operand:SI 2 "reg_or_short_operand" "rI"))
7798                   (match_operand:SI 3 "gpc_reg_operand" "r"))
7799          (const_int 0)))
7800    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7801         (plus:SI (leu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
7802    (clobber (match_scratch:SI 4 "=&r"))]
7803   ""
7804   "{sf%I2|subf%I2c} %4,%1,%2\;{aze.|addze.} %0,%3"
7805   [(set_attr "type" "compare")
7806    (set_attr "length" "8")])
7807
7808 (define_insn ""
7809   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7810         (neg:SI (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7811                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
7812   ""
7813   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0"
7814    [(set_attr "length" "12")])
7815
7816 (define_insn ""
7817   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7818         (and:SI (neg:SI
7819                  (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7820                          (match_operand:SI 2 "reg_or_short_operand" "rI")))
7821                 (match_operand:SI 3 "gpc_reg_operand" "r")))
7822    (clobber (match_scratch:SI 4 "=&r"))]
7823   ""
7824   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
7825   [(set_attr "length" "12")])
7826
7827 (define_insn ""
7828   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
7829         (compare:CC
7830          (and:SI (neg:SI
7831                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7832                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
7833                  (match_operand:SI 3 "gpc_reg_operand" "r"))
7834          (const_int 0)))
7835    (clobber (match_scratch:SI 4 "=&r"))]
7836   ""
7837   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
7838   [(set_attr "type" "compare")
7839    (set_attr "length" "12")])
7840
7841 (define_insn ""
7842   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
7843         (compare:CC
7844          (and:SI (neg:SI
7845                   (leu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7846                           (match_operand:SI 2 "reg_or_short_operand" "rI")))
7847                  (match_operand:SI 3 "gpc_reg_operand" "r"))
7848          (const_int 0)))
7849    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7850         (and:SI (neg:SI (leu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
7851    (clobber (match_scratch:SI 4 "=&r"))]
7852   ""
7853   "{sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
7854   [(set_attr "type" "compare")
7855    (set_attr "length" "12")])
7856
7857 (define_insn ""
7858   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7859         (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7860                (match_operand:SI 2 "reg_or_short_operand" "rI")))]
7861   "TARGET_POWER"
7862   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri|srwi} %0,%0,31"
7863    [(set_attr "length" "12")])
7864
7865 (define_insn ""
7866   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
7867         (compare:CC
7868          (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7869                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
7870          (const_int 0)))
7871    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7872         (lt:SI (match_dup 1) (match_dup 2)))]
7873   "TARGET_POWER"
7874   "doz%I2 %0,%1,%2\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
7875   [(set_attr "type" "delayed_compare")
7876    (set_attr "length" "12")])
7877
7878 (define_insn ""
7879   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7880         (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7881                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
7882                  (match_operand:SI 3 "gpc_reg_operand" "r")))
7883    (clobber (match_scratch:SI 4 "=&r"))]
7884   "TARGET_POWER"
7885   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
7886   [(set_attr "length" "12")])
7887
7888 (define_insn ""
7889   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
7890         (compare:CC
7891          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7892                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
7893                   (match_operand:SI 3 "gpc_reg_operand" "r"))
7894          (const_int 0)))
7895    (clobber (match_scratch:SI 4 "=&r"))]
7896   "TARGET_POWER"
7897   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
7898   [(set_attr "type" "compare")
7899    (set_attr "length" "12")])
7900
7901 (define_insn ""
7902   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
7903         (compare:CC
7904          (plus:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7905                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
7906                   (match_operand:SI 3 "gpc_reg_operand" "r"))
7907          (const_int 0)))
7908    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
7909         (plus:SI (lt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
7910    (clobber (match_scratch:SI 4 "=&r"))]
7911   "TARGET_POWER"
7912   "doz%I2 %4,%1,%2\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
7913   [(set_attr "type" "compare")
7914    (set_attr "length" "12")])
7915
7916 (define_insn ""
7917   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
7918         (neg:SI (lt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
7919                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
7920   "TARGET_POWER"
7921   "doz%I2 %0,%1,%2\;nabs %0,%0\;{srai|srawi} %0,%0,31"
7922   [(set_attr "length" "12")])
7923
7924 (define_insn ""
7925   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7926         (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7927                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
7928   ""
7929   "@
7930    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg %0,%0
7931    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
7932   [(set_attr "length" "12")])
7933
7934 (define_insn ""
7935   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
7936         (compare:CC
7937          (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7938                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
7939          (const_int 0)))
7940    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7941         (ltu:SI (match_dup 1) (match_dup 2)))]
7942   ""
7943   "@
7944    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;neg. %0,%0
7945    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
7946   [(set_attr "type" "compare")
7947    (set_attr "length" "12")])
7948
7949 (define_insn ""
7950   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r,r")
7951         (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r,r")
7952                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,r,P,P"))
7953                  (match_operand:SI 3 "reg_or_short_operand" "r,I,r,I")))
7954    (clobber (match_scratch:SI 4 "=&r,r,&r,r"))]
7955   ""
7956   "@
7957   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
7958   {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
7959   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
7960   {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
7961  [(set_attr "length" "12")])
7962
7963 (define_insn ""
7964   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
7965         (compare:CC
7966          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7967                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
7968                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
7969          (const_int 0)))
7970    (clobber (match_scratch:SI 4 "=&r,&r"))]
7971   ""
7972   "@
7973    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3
7974    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %4,%4,%3"
7975   [(set_attr "type" "compare")
7976    (set_attr "length" "12")])
7977
7978 (define_insn ""
7979   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
7980         (compare:CC
7981          (plus:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7982                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
7983                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
7984          (const_int 0)))
7985    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7986         (plus:SI (ltu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
7987    (clobber (match_scratch:SI 4 "=&r,&r"))]
7988   ""
7989   "@
7990    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3
7991    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
7992   [(set_attr "type" "compare")
7993    (set_attr "length" "12")])
7994
7995 (define_insn ""
7996   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
7997         (neg:SI (ltu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
7998                         (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))))]
7999   ""
8000   "@
8001    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0
8002    {ai|addic} %0,%1,%n2\;{sfe|subfe} %0,%0,%0"
8003   [(set_attr "length" "8")])
8004
8005 (define_insn ""
8006   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8007         (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8008                (match_operand:SI 2 "reg_or_short_operand" "rI")))
8009    (clobber (match_scratch:SI 3 "=r"))]
8010   "TARGET_POWER"
8011   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae|adde} %0,%0,%3"
8012    [(set_attr "length" "12")])
8013
8014 (define_insn ""
8015   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
8016         (compare:CC
8017          (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8018                 (match_operand:SI 2 "reg_or_short_operand" "rI"))
8019          (const_int 0)))
8020    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8021         (ge:SI (match_dup 1) (match_dup 2)))
8022    (clobber (match_scratch:SI 3 "=r"))]
8023   "TARGET_POWER"
8024   "doz%I2 %3,%1,%2\;{sfi|subfic} %0,%3,0\;{ae.|adde.} %0,%0,%3"
8025   [(set_attr "type" "compare")
8026    (set_attr "length" "12")])
8027
8028 (define_insn ""
8029   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8030         (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8031                         (match_operand:SI 2 "reg_or_short_operand" "rI"))
8032                  (match_operand:SI 3 "gpc_reg_operand" "r")))
8033    (clobber (match_scratch:SI 4 "=&r"))]
8034   "TARGET_POWER"
8035   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze|addze} %0,%3"
8036   [(set_attr "length" "12")])
8037
8038 (define_insn ""
8039   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8040         (compare:CC
8041          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8042                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8043                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8044          (const_int 0)))
8045    (clobber (match_scratch:SI 4 "=&r"))]
8046   "TARGET_POWER"
8047   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %4,%3"
8048   [(set_attr "type" "compare")
8049    (set_attr "length" "12")])
8050
8051 (define_insn ""
8052   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
8053         (compare:CC
8054          (plus:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8055                          (match_operand:SI 2 "reg_or_short_operand" "rI"))
8056                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8057          (const_int 0)))
8058    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8059         (plus:SI (ge:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8060    (clobber (match_scratch:SI 4 "=&r"))]
8061   "TARGET_POWER"
8062   "doz%I2 %4,%1,%2\;{sfi|subfic} %4,%4,0\;{aze.|addze.} %0,%3"
8063   [(set_attr "type" "compare")
8064    (set_attr "length" "12")])
8065
8066 (define_insn ""
8067   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8068         (neg:SI (ge:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8069                        (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
8070   "TARGET_POWER"
8071   "doz%I2 %0,%1,%2\;{ai|addic} %0,%0,-1\;{sfe|subfe} %0,%0,%0"
8072   [(set_attr "length" "12")])
8073
8074 ;; This is (and (neg (ge X (const_int 0))) Y).
8075 (define_insn ""
8076   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8077         (and:SI (neg:SI
8078                  (lshiftrt:SI
8079                   (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
8080                   (const_int 31)))
8081                 (match_operand:SI 2 "gpc_reg_operand" "r")))
8082    (clobber (match_scratch:SI 3 "=&r"))]
8083   ""
8084   "{srai|srawi} %3,%1,31\;andc %0,%2,%3"
8085   [(set_attr "length" "8")])
8086
8087 (define_insn ""
8088   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8089         (compare:CC
8090          (and:SI (neg:SI
8091                   (lshiftrt:SI
8092                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
8093                    (const_int 31)))
8094                  (match_operand:SI 2 "gpc_reg_operand" "r"))
8095          (const_int 0)))
8096    (clobber (match_scratch:SI 3 "=&r"))]
8097   ""
8098   "{srai|srawi} %3,%1,31\;andc. %3,%2,%3"
8099   [(set_attr "type" "compare")
8100    (set_attr "length" "8")])
8101
8102 (define_insn ""
8103   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
8104         (compare:CC
8105          (and:SI (neg:SI
8106                   (lshiftrt:SI
8107                    (not:SI (match_operand:SI 1 "gpc_reg_operand" "r"))
8108                    (const_int 31)))
8109                  (match_operand:SI 2 "gpc_reg_operand" "r"))
8110          (const_int 0)))
8111    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8112         (and:SI (neg:SI (lshiftrt:SI (not:SI (match_dup 1))
8113                                      (const_int 31)))
8114                 (match_dup 2)))
8115    (clobber (match_scratch:SI 3 "=&r"))]
8116   ""
8117   "{srai|srawi} %3,%1,31\;andc. %0,%2,%3"
8118   [(set_attr "type" "compare")
8119    (set_attr "length" "8")])
8120
8121 (define_insn ""
8122   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8123         (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8124                 (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))]
8125   ""
8126   "@
8127    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0
8128    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae|adde} %0,%0,%0"
8129   [(set_attr "length" "12")])
8130
8131 (define_insn ""
8132   [(set (match_operand:CC 3 "cc_reg_operand" "=x,x")
8133         (compare:CC
8134          (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8135                  (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8136          (const_int 0)))
8137    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8138         (geu:SI (match_dup 1) (match_dup 2)))]
8139   ""
8140   "@
8141    {sf|subfc} %0,%2,%1\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0
8142    {ai|addic} %0,%1,%n2\;{cal %0,0(0)|li %0,0}\;{ae.|adde.} %0,%0,%0"
8143   [(set_attr "type" "compare")
8144    (set_attr "length" "12")])
8145
8146 (define_insn ""
8147   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8148         (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8149                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8150                  (match_operand:SI 3 "gpc_reg_operand" "r,r")))
8151    (clobber (match_scratch:SI 4 "=&r,&r"))]
8152   ""
8153   "@
8154    {sf|subfc} %4,%2,%1\;{aze|addze} %0,%3
8155    {ai|addic} %4,%1,%n2\;{aze|addze} %0,%3"
8156   [(set_attr "length" "8")])
8157
8158 (define_insn ""
8159   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8160         (compare:CC
8161          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8162                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8163                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8164          (const_int 0)))
8165    (clobber (match_scratch:SI 4 "=&r,&r"))]
8166   ""
8167   "@
8168    {sf|subfc} %4,%2,%1\;{aze.|addze.} %4,%3
8169    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
8170   [(set_attr "type" "compare")
8171    (set_attr "length" "8")])
8172
8173 (define_insn ""
8174   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8175         (compare:CC
8176          (plus:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8177                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P"))
8178                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8179          (const_int 0)))
8180    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8181         (plus:SI (geu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8182    (clobber (match_scratch:SI 4 "=&r,&r"))]
8183   ""
8184   "@
8185    {sf|subfc} %4,%2,%1\;{aze.|addze.} %0,%3
8186    {ai|addic} %4,%1,%n2\;{aze.|addze.} %4,%3"
8187   [(set_attr "type" "compare")
8188    (set_attr "length" "8")])
8189
8190 (define_insn ""
8191   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8192         (neg:SI (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8193                         (match_operand:SI 2 "reg_or_short_operand" "r,I"))))]
8194   ""
8195   "@
8196    {sf|subfc} %0,%2,%1\;{sfe|subfe} %0,%0,%0\;nand %0,%0,%0
8197    {sfi|subfic} %0,%1,-1\;{a%I2|add%I2c} %0,%0,%2\;{sfe|subfe} %0,%0,%0"
8198   [(set_attr "length" "12")])
8199
8200 (define_insn ""
8201   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8202         (and:SI (neg:SI
8203                  (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8204                          (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
8205                 (match_operand:SI 3 "gpc_reg_operand" "r,r")))
8206    (clobber (match_scratch:SI 4 "=&r,&r"))]
8207   ""
8208   "@
8209    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4
8210    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc %0,%3,%4"
8211   [(set_attr "length" "12")])
8212
8213 (define_insn ""
8214   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8215         (compare:CC
8216          (and:SI (neg:SI
8217                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8218                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
8219                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8220          (const_int 0)))
8221    (clobber (match_scratch:SI 4 "=&r,&r"))]
8222   ""
8223   "@
8224    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4
8225    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %4,%3,%4"
8226   [(set_attr "type" "compare")
8227    (set_attr "length" "12")])
8228
8229 (define_insn ""
8230   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8231         (compare:CC
8232          (and:SI (neg:SI
8233                   (geu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8234                           (match_operand:SI 2 "reg_or_neg_short_operand" "r,P")))
8235                  (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8236          (const_int 0)))
8237    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8238         (and:SI (neg:SI (geu:SI (match_dup 1) (match_dup 2))) (match_dup 3)))
8239    (clobber (match_scratch:SI 4 "=&r,&r"))]
8240   ""
8241   "@
8242    {sf|subfc} %4,%2,%1\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4
8243    {ai|addic} %4,%1,%n2\;{sfe|subfe} %4,%4,%4\;andc. %0,%3,%4"
8244   [(set_attr "type" "compare")
8245    (set_attr "length" "12")])
8246
8247 (define_insn ""
8248   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8249         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8250                (const_int 0)))]
8251   ""
8252   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri|srwi} %0,%0,31"
8253   [(set_attr "length" "12")])
8254
8255 (define_insn ""
8256   [(set (match_operand:CC 2 "cc_reg_operand" "=x")
8257         (compare:CC
8258          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8259                 (const_int 0))
8260          (const_int 0)))
8261    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8262         (gt:SI (match_dup 1) (const_int 0)))]
8263   ""
8264   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{sri.|srwi.} %0,%0,31"
8265   [(set_attr "type" "delayed_compare")
8266    (set_attr "length" "12")])
8267
8268 (define_insn ""
8269   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8270         (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8271                (match_operand:SI 2 "reg_or_short_operand" "r")))]
8272   "TARGET_POWER"
8273   "doz %0,%2,%1\;nabs %0,%0\;{sri|srwi} %0,%0,31"
8274   [(set_attr "length" "12")])
8275
8276 (define_insn ""
8277   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
8278         (compare:CC
8279          (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8280                 (match_operand:SI 2 "reg_or_short_operand" "r"))
8281          (const_int 0)))
8282    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8283         (gt:SI (match_dup 1) (match_dup 2)))]
8284   "TARGET_POWER"
8285   "doz %0,%2,%1\;nabs %0,%0\;{sri.|srwi.} %0,%0,31"
8286   [(set_attr "type" "delayed_compare")
8287    (set_attr "length" "12")])
8288
8289 (define_insn ""
8290   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8291         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8292                         (const_int 0))
8293                  (match_operand:SI 2 "gpc_reg_operand" "r")))
8294    (clobber (match_scratch:SI 3 "=&r"))]
8295   ""
8296   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze|addze} %0,%2"
8297   [(set_attr "length" "12")])
8298
8299 (define_insn ""
8300   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8301         (compare:CC
8302          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8303                          (const_int 0))
8304                   (match_operand:SI 2 "gpc_reg_operand" "r"))
8305          (const_int 0)))
8306    (clobber (match_scratch:SI 3 "=&r"))]
8307   ""
8308   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %0,%2"
8309   [(set_attr "type" "compare")
8310    (set_attr "length" "12")])
8311
8312 (define_insn ""
8313   [(set (match_operand:CC 4 "cc_reg_operand" "=x")
8314         (compare:CC
8315          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8316                          (const_int 0))
8317                   (match_operand:SI 2 "gpc_reg_operand" "r"))
8318          (const_int 0)))
8319    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8320         (plus:SI (gt:SI (match_dup 1) (const_int 0)) (match_dup 2)))
8321    (clobber (match_scratch:SI 3 "=&r"))]
8322   ""
8323   "{a|addc} %3,%1,%1\;{sfe|subfe} %3,%1,%3\;{aze.|addze.} %3,%2"
8324   [(set_attr "type" "compare")
8325    (set_attr "length" "12")])
8326
8327 (define_insn ""
8328   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8329         (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8330                         (match_operand:SI 2 "reg_or_short_operand" "r"))
8331                  (match_operand:SI 3 "gpc_reg_operand" "r")))
8332    (clobber (match_scratch:SI 4 "=&r"))]
8333   "TARGET_POWER"
8334   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze|addze} %0,%3"
8335   [(set_attr "length" "12")])
8336
8337 (define_insn ""
8338   [(set (match_operand:CC 0 "cc_reg_operand" "=x")
8339         (compare:CC
8340          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8341                          (match_operand:SI 2 "reg_or_short_operand" "r"))
8342                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8343          (const_int 0)))
8344    (clobber (match_scratch:SI 4 "=&r"))]
8345   "TARGET_POWER"
8346   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %4,%3"
8347   [(set_attr "type" "compare")
8348    (set_attr "length" "12")])
8349
8350 (define_insn ""
8351   [(set (match_operand:CC 5 "cc_reg_operand" "=x")
8352         (compare:CC
8353          (plus:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8354                          (match_operand:SI 2 "reg_or_short_operand" "r"))
8355                   (match_operand:SI 3 "gpc_reg_operand" "r"))
8356          (const_int 0)))
8357    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8358         (plus:SI (gt:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8359    (clobber (match_scratch:SI 4 "=&r"))]
8360   "TARGET_POWER"
8361   "doz %4,%2,%1\;{ai|addic} %4,%4,-1\;{aze.|addze.} %0,%3"
8362   [(set_attr "type" "compare")
8363    (set_attr "length" "12")])
8364
8365 (define_insn ""
8366   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8367         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8368                        (const_int 0))))]
8369   ""
8370   "{sfi|subfic} %0,%1,0\;{ame|addme} %0,%0\;{srai|srawi} %0,%0,31"
8371   [(set_attr "length" "12")])
8372
8373 (define_insn ""
8374   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8375         (neg:SI (gt:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8376                        (match_operand:SI 2 "reg_or_short_operand" "r"))))]
8377   "TARGET_POWER"
8378   "doz %0,%2,%1\;nabs %0,%0\;{srai|srawi} %0,%0,31"
8379   [(set_attr "length" "12")])
8380
8381 (define_insn ""
8382   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8383         (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8384                 (match_operand:SI 2 "reg_or_short_operand" "rI")))]
8385   ""
8386   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg %0,%0"
8387   [(set_attr "length" "12")])
8388
8389 (define_insn ""
8390   [(set (match_operand:CC 3 "cc_reg_operand" "=x")
8391         (compare:CC
8392          (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8393                  (match_operand:SI 2 "reg_or_short_operand" "rI"))
8394          (const_int 0)))
8395    (set (match_operand:SI 0 "gpc_reg_operand" "=r")
8396         (gtu:SI (match_dup 1) (match_dup 2)))]
8397   ""
8398   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0\;neg. %0,%0"
8399   [(set_attr "type" "compare")
8400    (set_attr "length" "12")])
8401
8402 (define_insn ""
8403   [(set (match_operand:SI 0 "gpc_reg_operand" "=r,r,r")
8404         (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r,r")
8405                          (match_operand:SI 2 "reg_or_short_operand" "I,r,rI"))
8406                  (match_operand:SI 3 "reg_or_short_operand" "r,r,I")))
8407    (clobber (match_scratch:SI 4 "=&r,&r,&r"))]
8408   ""
8409   "@
8410    {ai|addic} %4,%1,%k2\;{aze|addze} %0,%3
8411    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3
8412    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf%I3|subf%I3c} %0,%4,%3"
8413   [(set_attr "length" "8,12,12")])
8414
8415 (define_insn ""
8416   [(set (match_operand:CC 0 "cc_reg_operand" "=x,x")
8417         (compare:CC
8418          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8419                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
8420                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8421          (const_int 0)))
8422    (clobber (match_scratch:SI 4 "=&r,&r"))]
8423   ""
8424   "@
8425    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
8426    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
8427   [(set_attr "type" "compare")
8428    (set_attr "length" "8,12")])
8429
8430 (define_insn ""
8431   [(set (match_operand:CC 5 "cc_reg_operand" "=x,x")
8432         (compare:CC
8433          (plus:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r,r")
8434                           (match_operand:SI 2 "reg_or_short_operand" "I,r"))
8435                   (match_operand:SI 3 "gpc_reg_operand" "r,r"))
8436          (const_int 0)))
8437    (set (match_operand:SI 0 "gpc_reg_operand" "=r,r")
8438         (plus:SI (gtu:SI (match_dup 1) (match_dup 2)) (match_dup 3)))
8439    (clobber (match_scratch:SI 4 "=&r,&r"))]
8440   ""
8441   "@
8442    {ai|addic} %4,%1,%k2\;{aze.|addze.} %0,%3
8443    {sf%I2|subf%I2c} %4,%1,%2\;{sfe|subfe} %4,%4,%4\;{sf.|subfc.} %0,%4,%3"
8444   [(set_attr "type" "compare")
8445    (set_attr "length" "8,12")])
8446
8447 (define_insn ""
8448   [(set (match_operand:SI 0 "gpc_reg_operand" "=r")
8449         (neg:SI (gtu:SI (match_operand:SI 1 "gpc_reg_operand" "r")
8450                         (match_operand:SI 2 "reg_or_short_operand" "rI"))))]
8451   ""
8452   "{sf%I2|subf%I2c} %0,%1,%2\;{sfe|subfe} %0,%0,%0"
8453   [(set_attr "length" "8")])
8454 \f
8455 ;; Define both directions of branch and return.  If we need a reload
8456 ;; register, we'd rather use CR0 since it is much easier to copy a
8457 ;; register CC value to there.
8458
8459 (define_insn ""
8460   [(set (pc)
8461         (if_then_else (match_operator 1 "branch_comparison_operator"
8462                                       [(match_operand 2
8463                                                       "cc_reg_operand" "x,?y")
8464                                        (const_int 0)])
8465                       (label_ref (match_operand 0 "" ""))
8466                       (pc)))]
8467   ""
8468   "*
8469 {
8470   if (get_attr_length (insn) == 8)
8471     return \"%C1bc %t1,%j1,%l0\";
8472   else
8473     return \"%C1bc %T1,%j1,$+8\;b %l0\";
8474 }"
8475   [(set_attr "type" "branch")])
8476
8477 (define_insn ""
8478   [(set (pc)
8479         (if_then_else (match_operator 0 "branch_comparison_operator"
8480                                       [(match_operand 1
8481                                                       "cc_reg_operand" "x,?y")
8482                                        (const_int 0)])
8483                       (return)
8484                       (pc)))]
8485   "direct_return ()"
8486   "{%C0bcr|%C0bclr} %t0,%j0"
8487   [(set_attr "length" "8")])
8488
8489 (define_insn ""
8490   [(set (pc)
8491         (if_then_else (match_operator 1 "branch_comparison_operator"
8492                                       [(match_operand 2
8493                                                       "cc_reg_operand" "x,?y")
8494                                        (const_int 0)])
8495                       (pc)
8496                       (label_ref (match_operand 0 "" ""))))]
8497   ""
8498   "*
8499 {
8500   if (get_attr_length (insn) == 8)
8501     return \"%C1bc %T1,%j1,%l0\";
8502   else
8503     return \"%C1bc %t1,%j1,$+8\;b %l0\";
8504 }"
8505   [(set_attr "type" "branch")])
8506
8507 (define_insn ""
8508   [(set (pc)
8509         (if_then_else (match_operator 0 "branch_comparison_operator"
8510                                       [(match_operand 1
8511                                                       "cc_reg_operand" "x,?y")
8512                                        (const_int 0)])
8513                       (pc)
8514                       (return)))]
8515   "direct_return ()"
8516   "{%C0bcr|%C0bclr} %T0,%j0"
8517   [(set_attr "length" "8")])
8518
8519 ;; Unconditional branch and return.
8520
8521 (define_insn "jump"
8522   [(set (pc)
8523         (label_ref (match_operand 0 "" "")))]
8524   ""
8525   "b %l0")
8526
8527 (define_insn "return"
8528   [(return)]
8529   "direct_return ()"
8530   "{br|blr}"
8531   [(set_attr "type" "jmpreg")])
8532
8533 (define_insn "indirect_jump"
8534   [(set (pc) (match_operand:SI 0 "register_operand" "c,l"))]
8535   ""
8536   "@
8537    bctr
8538    {br|blr}"
8539   [(set_attr "type" "jmpreg")])
8540
8541 (define_insn ""
8542   [(set (pc) (match_operand:DI 0 "register_operand" "c,l"))]
8543   "TARGET_POWERPC64"
8544   "@
8545    bctr
8546    {br|blr}"
8547   [(set_attr "type" "jmpreg")])
8548
8549 ;; Table jump for switch statements:
8550 (define_expand "tablejump"
8551   [(use (match_operand 0 "" ""))
8552    (use (label_ref (match_operand 1 "" "")))]
8553   ""
8554   "
8555 {
8556   if (TARGET_32BIT)
8557     emit_jump_insn (gen_tablejumpsi (operands[0], operands[1]));
8558   else
8559     emit_jump_insn (gen_tablejumpdi (operands[0], operands[1]));
8560   DONE;
8561 }")
8562
8563 (define_expand "tablejumpsi"
8564   [(set (match_dup 3)
8565         (plus:SI (match_operand:SI 0 "" "")
8566                  (match_dup 2)))
8567    (parallel [(set (pc) (match_dup 3))
8568               (use (label_ref (match_operand 1 "" "")))])]
8569   ""
8570   "
8571 { operands[0] = force_reg (SImode, operands[0]);
8572   operands[2] = force_reg (SImode, gen_rtx (LABEL_REF, VOIDmode, operands[1]));
8573   operands[3] = gen_reg_rtx (SImode);
8574 }")
8575
8576 (define_expand "tablejumpdi"
8577   [(set (match_dup 3)
8578         (plus:DI (match_operand:DI 0 "" "")
8579                  (match_dup 2)))
8580    (parallel [(set (pc) (match_dup 3))
8581               (use (label_ref (match_operand 1 "" "")))])]
8582   ""
8583   "
8584 { operands[0] = force_reg (DImode, operands[0]);
8585   operands[2] = force_reg (DImode, gen_rtx (LABEL_REF, VOIDmode, operands[1]));
8586   operands[3] = gen_reg_rtx (DImode);
8587 }")
8588
8589 (define_insn ""
8590   [(set (pc)
8591         (match_operand:SI 0 "register_operand" "c,l"))
8592    (use (label_ref (match_operand 1 "" "")))]
8593   ""
8594   "@
8595    bctr
8596    {br|blr}"
8597   [(set_attr "type" "jmpreg")])
8598
8599 (define_insn ""
8600   [(set (pc)
8601         (match_operand:DI 0 "register_operand" "c,l"))
8602    (use (label_ref (match_operand 1 "" "")))]
8603   "TARGET_POWERPC64"
8604   "@
8605    bctr
8606    {br|blr}"
8607   [(set_attr "type" "jmpreg")])
8608
8609 (define_insn "nop"
8610   [(const_int 0)]
8611   ""
8612   "{cror 0,0,0|nop}")
8613 \f
8614 ;; Define the subtract-one-and-jump insns, starting with the template
8615 ;; so loop.c knows what to generate.
8616
8617 (define_expand "decrement_and_branch_on_count"
8618   [(parallel [(set (pc) (if_then_else (ne (match_operand:SI 0 "register_operand" "")
8619                                           (const_int 1))
8620                                       (label_ref (match_operand 1 "" ""))
8621                                       (pc)))
8622               (set (match_dup 0)
8623                    (plus:SI (match_dup 0)
8624                             (const_int -1)))
8625               (clobber (match_scratch:CC 2 ""))
8626               (clobber (match_scratch:SI 3 ""))])]
8627   ""
8628   "")
8629
8630 ;; We need to be able to do this for any operand, including MEM, or we
8631 ;; will cause reload to blow up since we don't allow output reloads on
8632 ;; JUMP_INSNs.
8633 ;; In order that the length attribute is calculated correctly, the
8634 ;; label MUST be operand 0.
8635
8636 (define_insn ""
8637   [(set (pc)
8638         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r")
8639                           (const_int 1))
8640                       (label_ref (match_operand 0 "" ""))
8641                       (pc)))
8642    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
8643         (plus:SI (match_dup 1)
8644                  (const_int -1)))
8645    (clobber (match_scratch:CC 3 "=X,&x,&x"))
8646    (clobber (match_scratch:SI 4 "=X,X,r"))]
8647   ""
8648   "*
8649 {
8650   if (which_alternative != 0)
8651     return \"#\";
8652   else if (get_attr_length (insn) == 8)
8653     return \"{bdn|bdnz} %l0\";
8654   else
8655     return \"bdz $+8\;b %l0\";
8656 }"
8657   [(set_attr "type" "branch")
8658    (set_attr "length" "*,12,16")])
8659
8660 (define_insn ""
8661   [(set (pc)
8662         (if_then_else (ne (match_operand:SI 1 "register_operand" "c,*r,*r")
8663                           (const_int 1))
8664                       (pc)
8665                       (label_ref (match_operand 0 "" ""))))
8666    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
8667         (plus:SI (match_dup 1)
8668                  (const_int -1)))
8669    (clobber (match_scratch:CC 3 "=X,&x,&x"))
8670    (clobber (match_scratch:SI 4 "=X,X,r"))]
8671   ""
8672   "*
8673 {
8674   if (which_alternative != 0)
8675     return \"#\";
8676   else if (get_attr_length (insn) == 8)
8677     return \"bdz %l0\";
8678   else
8679     return \"{bdn|bdnz} $+8\;b %l0\";
8680 }"
8681   [(set_attr "type" "branch")
8682    (set_attr "length" "*,12,16")])
8683
8684 ;; Similar, but we can use GE since we have a REG_NONNEG.
8685 (define_insn ""
8686   [(set (pc)
8687         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r")
8688                           (const_int 0))
8689                       (label_ref (match_operand 0 "" ""))
8690                       (pc)))
8691    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
8692         (plus:SI (match_dup 1)
8693                  (const_int -1)))
8694    (clobber (match_scratch:CC 3 "=X,&x,&X"))
8695    (clobber (match_scratch:SI 4 "=X,X,r"))]
8696   "find_reg_note (insn, REG_NONNEG, 0)"
8697   "*
8698 {
8699   if (which_alternative != 0)
8700     return \"#\";
8701   else if (get_attr_length (insn) == 8)
8702     return \"{bdn|bdnz} %l0\";
8703   else
8704     return \"bdz $+8\;b %l0\";
8705 }"
8706   [(set_attr "type" "branch")
8707    (set_attr "length" "*,12,16")])
8708
8709 (define_insn ""
8710   [(set (pc)
8711         (if_then_else (ge (match_operand:SI 1 "register_operand" "c,*r,*r")
8712                           (const_int 0))
8713                       (pc)
8714                       (label_ref (match_operand 0 "" ""))))
8715    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
8716         (plus:SI (match_dup 1)
8717                  (const_int -1)))
8718    (clobber (match_scratch:CC 3 "=X,&x,&X"))
8719    (clobber (match_scratch:SI 4 "=X,X,r"))]
8720   "find_reg_note (insn, REG_NONNEG, 0)"
8721   "*
8722 {
8723   if (which_alternative != 0)
8724     return \"#\";
8725   else if (get_attr_length (insn) == 8)
8726     return \"bdz %l0\";
8727   else
8728     return \"{bdn|bdnz} $+8\;b %l0\";
8729 }"
8730   [(set_attr "type" "branch")
8731    (set_attr "length" "*,12,16")])
8732
8733 (define_insn ""
8734   [(set (pc)
8735         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r")
8736                           (const_int 1))
8737                       (label_ref (match_operand 0 "" ""))
8738                       (pc)))
8739    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
8740         (plus:SI (match_dup 1)
8741                  (const_int -1)))
8742    (clobber (match_scratch:CC 3 "=X,&x,&x"))
8743    (clobber (match_scratch:SI 4 "=X,X,r"))]
8744   ""
8745   "*
8746 {
8747   if (which_alternative != 0)
8748     return \"#\";
8749   else if (get_attr_length (insn) == 8)
8750     return \"bdz %l0\";
8751   else
8752     return \"{bdn|bdnz} $+8\;b %l0\";
8753 }"
8754   [(set_attr "type" "branch")
8755    (set_attr "length" "*,12,16")])
8756
8757 (define_insn ""
8758   [(set (pc)
8759         (if_then_else (eq (match_operand:SI 1 "register_operand" "c,*r,*r")
8760                           (const_int 1))
8761                       (pc)
8762                       (label_ref (match_operand 0 "" ""))))
8763    (set (match_operand:SI 2 "register_operand" "=1,*r,m*q*c*l")
8764         (plus:SI (match_dup 1)
8765                  (const_int -1)))
8766    (clobber (match_scratch:CC 3 "=X,&x,&x"))
8767    (clobber (match_scratch:SI 4 "=X,X,r"))]
8768   ""
8769   "*
8770 {
8771   if (which_alternative != 0)
8772     return \"#\";
8773   else if (get_attr_length (insn) == 8)
8774     return \"{bdn|bdnz} %l0\";
8775   else
8776     return \"bdz $+8\;b %l0\";
8777 }"
8778   [(set_attr "type" "branch")
8779    (set_attr "length" "*,12,16")])
8780
8781 (define_split
8782   [(set (pc)
8783         (if_then_else (match_operator 2 "comparison_operator"
8784                                       [(match_operand:SI 1 "gpc_reg_operand" "")
8785                                        (const_int 1)])
8786                       (match_operand 5 "" "")
8787                       (match_operand 6 "" "")))
8788    (set (match_operand:SI 0 "gpc_reg_operand" "")
8789         (plus:SI (match_dup 1)
8790                  (const_int -1)))
8791    (clobber (match_scratch:CC 3 ""))
8792    (clobber (match_scratch:SI 4 ""))]
8793   "reload_completed"
8794   [(parallel [(set (match_dup 3)
8795                    (compare:CC (plus:SI (match_dup 1)
8796                                         (const_int -1))
8797                                (const_int 0)))
8798               (set (match_dup 0)
8799                    (plus:SI (match_dup 1)
8800                             (const_int -1)))])
8801    (set (pc) (if_then_else (match_dup 7)
8802                            (match_dup 5)
8803                            (match_dup 6)))]
8804   "
8805 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
8806                          const0_rtx); }")
8807
8808 (define_split
8809   [(set (pc)
8810         (if_then_else (match_operator 2 "comparison_operator"
8811                                       [(match_operand:SI 1 "gpc_reg_operand" "")
8812                                        (const_int 1)])
8813                       (match_operand 5 "" "")
8814                       (match_operand 6 "" "")))
8815    (set (match_operand:SI 0 "general_operand" "")
8816         (plus:SI (match_dup 1) (const_int -1)))
8817    (clobber (match_scratch:CC 3 ""))
8818    (clobber (match_scratch:SI 4 ""))]
8819   "reload_completed && ! gpc_reg_operand (operands[0], SImode)"
8820   [(parallel [(set (match_dup 3)
8821                    (compare:CC (plus:SI (match_dup 1)
8822                                         (const_int -1))
8823                                (const_int 0)))
8824               (set (match_dup 4)
8825                    (plus:SI (match_dup 1)
8826                             (const_int -1)))])
8827    (set (match_dup 0)
8828         (match_dup 4))
8829    (set (pc) (if_then_else (match_dup 7)
8830                            (match_dup 5)
8831                            (match_dup 6)))]
8832   "
8833 { operands[7] = gen_rtx (GET_CODE (operands[2]), VOIDmode, operands[3],
8834                          const0_rtx); }")